@scallop-io/sui-scallop-sdk 0.46.56 → 0.46.57

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,7 +5,7 @@ import { ScallopUtils } from './scallopUtils';
5
5
  import type { SuiTransactionBlockResponse } from '@mysten/sui.js/client';
6
6
  import type { TransactionBlock } from '@mysten/sui.js/transactions';
7
7
  import type { SuiTxBlock as SuiKitTxBlock } from '@scallop-io/sui-kit';
8
- import type { ScallopBuilderParams, ScallopTxBlock, SupportMarketCoins, SupportAssetCoins, SupportSCoin, ScallopBuilderInstanceParams } from '../types';
8
+ import type { ScallopBuilderParams, ScallopTxBlock, SupportMarketCoins, SupportAssetCoins, SupportSCoin, ScallopBuilderInstanceParams, SelectCoinReturnType } from '../types';
9
9
  import { ScallopCache } from './scallopCache';
10
10
  /**
11
11
  * @description
@@ -51,10 +51,7 @@ export declare class ScallopBuilder {
51
51
  * @param sender - Sender address.
52
52
  * @return Take coin and left coin.
53
53
  */
54
- selectCoin(txBlock: ScallopTxBlock | SuiKitTxBlock, assetCoinName: SupportAssetCoins, amount: number, sender?: string): Promise<{
55
- takeCoin: import("@scallop-io/sui-kit").TransactionObjectArgument;
56
- leftCoin: import("@scallop-io/sui-kit").TransactionObjectArgument;
57
- }>;
54
+ selectCoin<T extends SupportAssetCoins>(txBlock: ScallopTxBlock | SuiKitTxBlock, assetCoinName: T, amount: number, sender?: string): Promise<SelectCoinReturnType<T>>;
58
55
  /**
59
56
  * Specifying the sender's amount of market coins to get coins args from transaction result.
60
57
  *
@@ -1,10 +1,11 @@
1
- import type { CoreTxBlock } from './core';
1
+ import type { CoreTxBlock, NestedResult } from './core';
2
2
  import type { SpoolTxBlock } from './spool';
3
3
  import type { BorrowIncentiveTxBlock } from './borrowIncentive';
4
4
  import type { VeScaTxBlock } from './vesca';
5
5
  import type { ReferralTxBlock } from './referral';
6
6
  import { LoyaltyProgramTxBlock } from './loyaltyProgram';
7
7
  import { SCoinTxBlock } from './sCoin';
8
+ import { SupportAssetCoins } from '../constant';
8
9
  export type * from './core';
9
10
  export type * from './spool';
10
11
  export type * from './borrowIncentive';
@@ -15,3 +16,9 @@ export type BaseScallopTxBlock = ReferralTxBlock & LoyaltyProgramTxBlock & Borro
15
16
  export type SuiTxBlockWithSCoin = BaseScallopTxBlock & SCoinTxBlock;
16
17
  export type SuiTxBlockWithSpool = SuiTxBlockWithSCoin & SpoolTxBlock;
17
18
  export type ScallopTxBlock = SuiTxBlockWithSpool & CoreTxBlock;
19
+ export type SelectCoinReturnType<T extends SupportAssetCoins> = T extends 'sui' ? {
20
+ takeCoin: NestedResult;
21
+ } : {
22
+ takeCoin: NestedResult;
23
+ leftCoin: NestedResult;
24
+ };
@@ -53,7 +53,7 @@ export declare const parseOriginBorrowIncentiveAccountData: (originBorrowIncenti
53
53
  export declare const minBigNumber: (...args: BigNumber.Value[]) => BigNumber;
54
54
  export declare const maxBigNumber: (...args: BigNumber.Value[]) => BigNumber;
55
55
  /**
56
- * Dynamically adjust the decrease or increase ratio according to the amout
56
+ * Dynamically adjust the decrease or increase ratio according to the amount
57
57
  * @param amount - The amount required to calculate factor.
58
58
  * @param scaleStep - The scale step required to determine the factor..
59
59
  * @param type - The type of the calculation.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scallop-io/sui-scallop-sdk",
3
- "version": "0.46.56",
3
+ "version": "0.46.57",
4
4
  "description": "Typescript sdk for interacting with Scallop contract on SUI",
5
5
  "keywords": [
6
6
  "sui",
@@ -15,6 +15,7 @@ import type {
15
15
  SupportAssetCoins,
16
16
  SupportSCoin,
17
17
  ScallopBuilderInstanceParams,
18
+ SelectCoinReturnType,
18
19
  } from '../types';
19
20
  import { ScallopCache } from './scallopCache';
20
21
  import { DEFAULT_CACHE_OPTIONS } from 'src/constants/cache';
@@ -122,16 +123,21 @@ export class ScallopBuilder {
122
123
  * @param sender - Sender address.
123
124
  * @return Take coin and left coin.
124
125
  */
125
- public async selectCoin(
126
+ public async selectCoin<T extends SupportAssetCoins>(
126
127
  txBlock: ScallopTxBlock | SuiKitTxBlock,
127
- assetCoinName: SupportAssetCoins,
128
+ assetCoinName: T,
128
129
  amount: number,
129
130
  sender: string = this.walletAddress
130
- ) {
131
- const coinType = this.utils.parseCoinType(assetCoinName);
132
- const coins = await this.utils.selectCoins(amount, coinType, sender);
133
- const [takeCoin, leftCoin] = txBlock.takeAmountFromCoins(coins, amount);
134
- return { takeCoin, leftCoin };
131
+ ): Promise<SelectCoinReturnType<T>> {
132
+ if (assetCoinName === 'sui') {
133
+ const [takeCoin] = txBlock.splitSUIFromGas([amount]);
134
+ return { takeCoin } as SelectCoinReturnType<T>;
135
+ } else {
136
+ const coinType = this.utils.parseCoinType(assetCoinName);
137
+ const coins = await this.utils.selectCoins(amount, coinType, sender);
138
+ const [takeCoin, leftCoin] = txBlock.takeAmountFromCoins(coins, amount);
139
+ return { takeCoin, leftCoin } as SelectCoinReturnType<T>;
140
+ }
135
141
  }
136
142
 
137
143
  /**
@@ -183,7 +183,7 @@ export const queryBorrowIncentiveAccounts = async (
183
183
 
184
184
  const queryResult = await utils.cache.queryInspectTxn({ queryTarget, args });
185
185
  const borrowIncentiveAccountsQueryData = queryResult?.events[0]
186
- .parsedJson as BorrowIncentiveAccountsQueryInterface;
186
+ ?.parsedJson as BorrowIncentiveAccountsQueryInterface | undefined;
187
187
 
188
188
  const borrowIncentiveAccounts: BorrowIncentiveAccounts = Object.values(
189
189
  borrowIncentiveAccountsQueryData?.pool_records ?? []
@@ -802,7 +802,7 @@ export const queryObligation = async (
802
802
  { queryTarget, args }
803
803
  // txBlock
804
804
  );
805
- return queryResult?.events[0].parsedJson as
805
+ return queryResult?.events[0]?.parsedJson as
806
806
  | ObligationQueryInterface
807
807
  | undefined;
808
808
  };
@@ -972,7 +972,7 @@ export const getFlashLoanFees = async (
972
972
  // the balance sheet is a VecSet<0x1::type_name::TypeName
973
973
  const balanceSheetDynamicFields = await query.cache.queryGetDynamicFields({
974
974
  parentId: flashloanFeesTableId,
975
- limit: 50,
975
+ limit: 10,
976
976
  });
977
977
 
978
978
  // get the dynamic object ids
@@ -1,10 +1,11 @@
1
- import type { CoreTxBlock } from './core';
1
+ import type { CoreTxBlock, NestedResult } from './core';
2
2
  import type { SpoolTxBlock } from './spool';
3
3
  import type { BorrowIncentiveTxBlock } from './borrowIncentive';
4
4
  import type { VeScaTxBlock } from './vesca';
5
5
  import type { ReferralTxBlock } from './referral';
6
6
  import { LoyaltyProgramTxBlock } from './loyaltyProgram';
7
7
  import { SCoinTxBlock } from './sCoin';
8
+ import { SupportAssetCoins } from '../constant';
8
9
 
9
10
  export type * from './core';
10
11
  export type * from './spool';
@@ -21,3 +22,12 @@ export type BaseScallopTxBlock = ReferralTxBlock &
21
22
  export type SuiTxBlockWithSCoin = BaseScallopTxBlock & SCoinTxBlock;
22
23
  export type SuiTxBlockWithSpool = SuiTxBlockWithSCoin & SpoolTxBlock;
23
24
  export type ScallopTxBlock = SuiTxBlockWithSpool & CoreTxBlock;
25
+
26
+ export type SelectCoinReturnType<T extends SupportAssetCoins> = T extends 'sui'
27
+ ? {
28
+ takeCoin: NestedResult;
29
+ }
30
+ : {
31
+ takeCoin: NestedResult;
32
+ leftCoin: NestedResult;
33
+ };
@@ -697,7 +697,7 @@ export const maxBigNumber = (...args: BigNumber.Value[]) => {
697
697
  };
698
698
 
699
699
  /**
700
- * Dynamically adjust the decrease or increase ratio according to the amout
700
+ * Dynamically adjust the decrease or increase ratio according to the amount
701
701
  * @param amount - The amount required to calculate factor.
702
702
  * @param scaleStep - The scale step required to determine the factor..
703
703
  * @param type - The type of the calculation.