@scallop-io/sui-scallop-sdk 0.46.40 → 0.46.42

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.
Files changed (61) hide show
  1. package/dist/builders/loyaltyProgramBuilder.d.ts +1 -1
  2. package/dist/builders/sCoinBuilder.d.ts +4 -0
  3. package/dist/constants/common.d.ts +3 -1
  4. package/dist/constants/enum.d.ts +12 -10
  5. package/dist/index.js +660 -97
  6. package/dist/index.js.map +1 -1
  7. package/dist/index.mjs +658 -92
  8. package/dist/index.mjs.map +1 -1
  9. package/dist/models/scallopBuilder.d.ts +16 -1
  10. package/dist/models/scallopClient.d.ts +5 -0
  11. package/dist/models/scallopQuery.d.ts +21 -2
  12. package/dist/models/scallopUtils.d.ts +32 -2
  13. package/dist/queries/portfolioQuery.d.ts +1 -1
  14. package/dist/queries/sCoinQuery.d.ts +27 -0
  15. package/dist/test.d.ts +1 -0
  16. package/dist/types/address.d.ts +8 -1
  17. package/dist/types/builder/core.d.ts +12 -4
  18. package/dist/types/builder/index.d.ts +6 -1
  19. package/dist/types/builder/sCoin.d.ts +37 -0
  20. package/dist/types/builder/spool.d.ts +2 -1
  21. package/dist/types/constant/common.d.ts +3 -2
  22. package/dist/types/constant/enum.d.ts +13 -1
  23. package/dist/types/query/core.d.ts +2 -1
  24. package/dist/types/query/index.d.ts +1 -0
  25. package/dist/types/query/portfolio.d.ts +1 -0
  26. package/dist/types/query/sCoin.d.ts +1 -0
  27. package/package.json +3 -3
  28. package/src/builders/coreBuilder.ts +72 -17
  29. package/src/builders/index.ts +5 -1
  30. package/src/builders/loyaltyProgramBuilder.ts +1 -1
  31. package/src/builders/referralBuilder.ts +1 -1
  32. package/src/builders/sCoinBuilder.ts +119 -0
  33. package/src/builders/spoolBuilder.ts +1 -1
  34. package/src/builders/vescaBuilder.ts +3 -3
  35. package/src/constants/common.ts +19 -5
  36. package/src/constants/enum.ts +98 -20
  37. package/src/constants/testAddress.ts +115 -21
  38. package/src/models/scallopAddress.ts +44 -3
  39. package/src/models/scallopBuilder.ts +43 -7
  40. package/src/models/scallopCache.ts +32 -4
  41. package/src/models/scallopClient.ts +121 -0
  42. package/src/models/scallopQuery.ts +46 -0
  43. package/src/models/scallopUtils.ts +56 -2
  44. package/src/queries/coreQuery.ts +10 -4
  45. package/src/queries/portfolioQuery.ts +26 -4
  46. package/src/queries/sCoinQuery.ts +94 -0
  47. package/src/queries/vescaQuery.ts +0 -1
  48. package/src/test.ts +19 -0
  49. package/src/types/address.ts +13 -0
  50. package/src/types/builder/core.ts +19 -4
  51. package/src/types/builder/index.ts +11 -3
  52. package/src/types/builder/sCoin.ts +61 -0
  53. package/src/types/builder/spool.ts +2 -0
  54. package/src/types/constant/common.ts +4 -1
  55. package/src/types/constant/enum.ts +17 -0
  56. package/src/types/query/core.ts +3 -0
  57. package/src/types/query/index.ts +1 -0
  58. package/src/types/query/portfolio.ts +1 -0
  59. package/src/types/query/sCoin.ts +1 -0
  60. package/src/utils/builder.ts +1 -1
  61. package/src/utils/util.ts +13 -17
@@ -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 { ScallopInstanceParams, ScallopBuilderParams, ScallopTxBlock, SupportMarketCoins, SupportAssetCoins } from '../types';
8
+ import type { ScallopInstanceParams, ScallopBuilderParams, ScallopTxBlock, SupportMarketCoins, SupportAssetCoins, SupportSCoin } from '../types';
9
9
  import { ScallopCache } from './scallopCache';
10
10
  /**
11
11
  * @description
@@ -67,6 +67,21 @@ export declare class ScallopBuilder {
67
67
  selectMarketCoin(txBlock: ScallopTxBlock | SuiKitTxBlock, marketCoinName: SupportMarketCoins, amount: number, sender: string): Promise<{
68
68
  takeCoin: import("@scallop-io/sui-kit").TransactionObjectArgument;
69
69
  leftCoin: import("@scallop-io/sui-kit").TransactionObjectArgument;
70
+ totalAmount: number;
71
+ }>;
72
+ /**
73
+ * Specifying the sender's amount of sCoins to get coins args from transaction result.
74
+ *
75
+ * @param txBlock - Scallop txBlock or txBlock created by SuiKit .
76
+ * @param marketCoinName - Specific support sCoin name.
77
+ * @param amount - Amount of coins to be selected.
78
+ * @param sender - Sender address.
79
+ * @return Take coin and left coin.
80
+ */
81
+ selectSCoin(txBlock: ScallopTxBlock | SuiKitTxBlock, sCoinName: SupportSCoin, amount: number, sender: string): Promise<{
82
+ takeCoin: import("@scallop-io/sui-kit").TransactionObjectArgument;
83
+ leftCoin: import("@scallop-io/sui-kit").TransactionObjectArgument;
84
+ totalAmount: number;
70
85
  }>;
71
86
  /**
72
87
  * Execute Scallop txBlock using the `signAndSendTxn` methods in suikit.
@@ -294,6 +294,11 @@ export declare class ScallopClient {
294
294
  * @return Transaction block response or transaction block
295
295
  */
296
296
  claimBorrowIncentive<S extends boolean>(coinName: SupportBorrowIncentiveCoins, obligationId: string, obligationKeyId: string, sign?: S, walletAddress?: string): Promise<ScallopClientFnReturnType<S>>;
297
+ /**
298
+ * Function to migrate all market coin in user wallet into sCoin
299
+ * @returns Transaction response
300
+ */
301
+ migrateAllMarketCoin<S extends boolean>(sign?: S): Promise<ScallopClientFnReturnType<S>>;
297
302
  /**
298
303
  * Mint and get test coin.
299
304
  *
@@ -1,5 +1,5 @@
1
1
  import { SuiKit } from '@scallop-io/sui-kit';
2
- import { ScallopQueryParams, ScallopInstanceParams, SupportStakeMarketCoins, SupportAssetCoins, SupportPoolCoins, SupportCollateralCoins, SupportMarketCoins, SupportBorrowIncentiveCoins } from '../types';
2
+ import { ScallopQueryParams, ScallopInstanceParams, SupportStakeMarketCoins, SupportAssetCoins, SupportPoolCoins, SupportCollateralCoins, SupportMarketCoins, SupportBorrowIncentiveCoins, SupportSCoin } from '../types';
3
3
  import { ScallopAddress } from './scallopAddress';
4
4
  import { ScallopUtils } from './scallopUtils';
5
5
  import { ScallopIndexer } from './scallopIndexer';
@@ -402,7 +402,26 @@ export declare class ScallopQuery {
402
402
  */
403
403
  getLoyaltyProgramInfos(veScaKey?: string | SuiObjectData): Promise<import("../types").LoyaltyProgramInfo | null>;
404
404
  /**
405
- * Get flashloan fee for specified assets
405
+ * Get total supply of sCoin
406
+ * @param sCoinName - Supported sCoin name
407
+ * @returns Total Supply
406
408
  */
409
+ getSCoinTotalSupply(sCoinName: SupportSCoin): Promise<number>;
410
+ /**
411
+ * Get all sCoin amounts.
412
+ *
413
+ * @param sCoinNames - Specific an array of support sCoin name.
414
+ * @param ownerAddress - The owner address.
415
+ * @return All market sCoin amounts.
416
+ */
417
+ getSCoinAmounts(sCoinNames?: SupportSCoin[], ownerAddress?: string): Promise<import("../types").OptionalKeys<Record<"seth" | "ssui" | "susdc" | "susdt" | "scetus" | "safsui" | "shasui" | "svsui" | "ssca", number>>>;
418
+ /**
419
+ * Get sCoin amount.
420
+ *
421
+ * @param coinNames - Specific support sCoin name.
422
+ * @param ownerAddress - The owner address.
423
+ * @return sCoin amount.
424
+ */
425
+ getSCoinAmount(sCoinName: SupportSCoin | SupportMarketCoins, ownerAddress?: string): Promise<number>;
407
426
  getFlashLoanFees(assetCoinNames?: SupportAssetCoins[]): Promise<Record<"eth" | "btc" | "usdc" | "usdt" | "sui" | "apt" | "sol" | "cetus" | "afsui" | "hasui" | "vsui" | "sca", number>>;
408
427
  }
@@ -1,6 +1,6 @@
1
1
  import { SuiAddressArg } from '@scallop-io/sui-kit';
2
2
  import { ScallopAddress } from './scallopAddress';
3
- import type { ScallopUtilsParams, ScallopInstanceParams, SupportCoins, SupportAssetCoins, SupportMarketCoins, SupportStakeMarketCoins, SupportBorrowIncentiveCoins, CoinWrappedType } from '../types';
3
+ import type { ScallopUtilsParams, ScallopInstanceParams, SupportCoins, SupportAssetCoins, SupportMarketCoins, SupportStakeMarketCoins, SupportBorrowIncentiveCoins, CoinWrappedType, SupportSCoin } from '../types';
4
4
  /**
5
5
  * @description
6
6
  * Integrates some helper functions frequently used in interactions with the Scallop contract.
@@ -48,6 +48,31 @@ export declare class ScallopUtils {
48
48
  * @return Coin type.
49
49
  */
50
50
  parseCoinType(coinName: SupportCoins): string;
51
+ /**
52
+ * Convert coin name to sCoin name.
53
+ *
54
+ * @param coinName - Specific support coin name.
55
+ * @return sCoin name.
56
+ */
57
+ parseSCoinName<T extends SupportSCoin>(coinName: SupportCoins | SupportMarketCoins): T | undefined;
58
+ /**
59
+ * Convert sCoin name into sCoin type
60
+ * @param sCoinName
61
+ * @returns sCoin type
62
+ */
63
+ parseSCoinType(sCoinName: SupportSCoin): string;
64
+ /**
65
+ * Convert sCoin name into its underlying coin type
66
+ * @param sCoinName
67
+ * @returns coin type
68
+ */
69
+ parseUnderlyingSCoinType(sCoinName: SupportSCoin): string;
70
+ /**
71
+ * Get sCoin treasury id from sCoin name
72
+ * @param sCoinName
73
+ * @returns sCoin treasury id
74
+ */
75
+ getSCoinTreasury(sCoinName: SupportSCoin): any;
51
76
  /**
52
77
  * Convert coin name to market coin type.
53
78
  *
@@ -117,7 +142,12 @@ export declare class ScallopUtils {
117
142
  * @param coinType - The coin type, default is 0x2::SUI::SUI.
118
143
  * @return The selected transaction coin arguments.
119
144
  */
120
- selectCoinIds(amount: number, coinType?: string, ownerAddress?: string): Promise<string[]>;
145
+ selectCoins(amount: number, coinType?: string, ownerAddress?: string): Promise<{
146
+ objectId: string;
147
+ digest: string;
148
+ version: string;
149
+ balance: string;
150
+ }[]>;
121
151
  /**
122
152
  * Get all asset coin names in the obligation record by obligation id.
123
153
  *
@@ -40,7 +40,7 @@ export declare const getLendings: (query: ScallopQuery, poolCoinNames?: SupportP
40
40
  * @param marketCoinAmount - The market coin amount.
41
41
  * @return User lending infomation for specific pool.
42
42
  */
43
- export declare const getLending: (query: ScallopQuery, poolCoinName: SupportPoolCoins, ownerAddress?: string, indexer?: boolean, marketPool?: MarketPool, spool?: Spool, stakeAccounts?: StakeAccount[], coinAmount?: number, marketCoinAmount?: number, coinPrice?: number) => Promise<Lending>;
43
+ export declare const getLending: (query: ScallopQuery, poolCoinName: SupportPoolCoins, ownerAddress?: string, indexer?: boolean, marketPool?: MarketPool, spool?: Spool, stakeAccounts?: StakeAccount[], coinAmount?: number, marketCoinAmount?: number, coinPrice?: number, sCoinAmount?: number) => Promise<Lending>;
44
44
  /**
45
45
  * Get all obligation accounts data.
46
46
  *
@@ -0,0 +1,27 @@
1
+ import { ScallopQuery } from 'src/models';
2
+ import { OptionalKeys, SupportSCoin, sCoinBalance } from 'src/types';
3
+ /**
4
+ * Get total supply of sCoin
5
+ * @param query
6
+ * @param sCoinName
7
+ * @returns `number`
8
+ */
9
+ export declare const getSCoinTotalSupply: (query: ScallopQuery, sCoinName: SupportSCoin) => Promise<sCoinBalance>;
10
+ /**
11
+ * Query all owned sCoin amount.
12
+ *
13
+ * @param query - The Scallop query instance.
14
+ * @param sCoinNames - Specific an array of support sCoin name.
15
+ * @param ownerAddress - The owner address.
16
+ * @return All owned sCoins amount.
17
+ */
18
+ export declare const getSCoinAmounts: (query: ScallopQuery, sCoinNames?: SupportSCoin[], ownerAddress?: string) => Promise<OptionalKeys<Record<"seth" | "ssui" | "susdc" | "susdt" | "scetus" | "safsui" | "shasui" | "svsui" | "ssca", number>>>;
19
+ /**
20
+ * Query owned sCoin amount.
21
+ *
22
+ * @param query - The Scallop query instance.
23
+ * @param sCoinNames - Specific support sCoin name.
24
+ * @param ownerAddress - The owner address.
25
+ * @return Owned sCoin amount.
26
+ */
27
+ export declare const getSCoinAmount: (query: ScallopQuery, sCoinName: SupportSCoin, ownerAddress?: string) => Promise<number>;
package/dist/test.d.ts ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -1,5 +1,5 @@
1
1
  import { SUPPORT_ORACLES } from '../constants';
2
- import type { SupportAssetCoins, SupportOracleType, SupportPackageType, SupportStakeMarketCoins } from './constant';
2
+ import type { SupportAssetCoins, SupportOracleType, SupportPackageType, SupportSCoin, SupportStakeMarketCoins } from './constant';
3
3
  export interface AddressesInterface {
4
4
  core: {
5
5
  version: string;
@@ -91,6 +91,13 @@ export interface AddressesInterface {
91
91
  rewardPool: string;
92
92
  userRewardTableId: string;
93
93
  };
94
+ scoin: {
95
+ id: string;
96
+ coins: Partial<Record<SupportSCoin, {
97
+ coinType: string;
98
+ treasury: string;
99
+ }>>;
100
+ };
94
101
  }
95
102
  type AddressPathsProps<T> = T extends string ? [] : {
96
103
  [K in Extract<keyof T, string>]: [K, ...AddressPathsProps<T[K]>];
@@ -1,7 +1,8 @@
1
1
  import type { SuiTxBlock as SuiKitTxBlock, SuiAddressArg, SuiObjectArg, SuiTxArg } from '@scallop-io/sui-kit';
2
- import type { TransactionResult } from '@mysten/sui.js/transactions';
2
+ import type { TransactionArgument, TransactionResult } from '@mysten/sui.js/transactions';
3
3
  import type { ScallopBuilder } from '../../models';
4
4
  import type { SupportCollateralCoins, SupportPoolCoins, SupportAssetCoins } from '../constant';
5
+ import { ScallopTxBlockWithoutCoreTxBlock } from '.';
5
6
  export type CoreIds = {
6
7
  protocolPkg: string;
7
8
  market: string;
@@ -9,8 +10,14 @@ export type CoreIds = {
9
10
  coinDecimalsRegistry: string;
10
11
  xOracle: string;
11
12
  };
13
+ export type NestedResult = Extract<TransactionArgument, {
14
+ kind: 'NestedResult';
15
+ }>;
16
+ type Obligation = NestedResult;
17
+ type ObligationKey = NestedResult;
18
+ type ObligationHotPotato = NestedResult;
12
19
  export type CoreNormalMethods = {
13
- openObligation: () => TransactionResult;
20
+ openObligation: () => [Obligation, ObligationKey, ObligationHotPotato];
14
21
  returnObligation: (obligation: SuiAddressArg, obligationHotPotato: SuiObjectArg) => void;
15
22
  openObligationEntry: () => void;
16
23
  addCollateral: (obligation: SuiAddressArg, coin: SuiObjectArg, collateralCoinName: SupportCollateralCoins) => void;
@@ -31,12 +38,12 @@ export type CoreQuickMethods = {
31
38
  takeCollateralQuick: (amount: number, collateralCoinName: SupportCollateralCoins, obligationId?: SuiAddressArg, obligationKey?: SuiAddressArg) => Promise<TransactionResult>;
32
39
  borrowQuick: (amount: number, poolCoinName: SupportPoolCoins, obligationId?: SuiAddressArg, obligationKey?: SuiAddressArg) => Promise<TransactionResult>;
33
40
  borrowWithReferralQuick: (amount: number, poolCoinName: SupportPoolCoins, borrowReferral: SuiObjectArg, obligationId?: SuiAddressArg, obligationKey?: SuiAddressArg) => Promise<TransactionResult>;
34
- depositQuick: (amount: number, poolCoinName: SupportPoolCoins) => Promise<TransactionResult>;
41
+ depositQuick: (amount: number, poolCoinName: SupportPoolCoins, returnSCoin?: boolean) => Promise<TransactionResult>;
35
42
  withdrawQuick: (amount: number, poolCoinName: SupportPoolCoins) => Promise<TransactionResult>;
36
43
  repayQuick: (amount: number, poolCoinName: SupportPoolCoins, obligationId?: SuiAddressArg) => Promise<void>;
37
44
  updateAssetPricesQuick: (assetCoinNames?: SupportAssetCoins[]) => Promise<void>;
38
45
  };
39
- export type SuiTxBlockWithCoreNormalMethods = SuiKitTxBlock & CoreNormalMethods;
46
+ export type SuiTxBlockWithCoreNormalMethods = SuiKitTxBlock & ScallopTxBlockWithoutCoreTxBlock & CoreNormalMethods;
40
47
  export type CoreTxBlock = SuiTxBlockWithCoreNormalMethods & CoreQuickMethods;
41
48
  export type GenerateCoreNormalMethod = (params: {
42
49
  builder: ScallopBuilder;
@@ -46,3 +53,4 @@ export type GenerateCoreQuickMethod = (params: {
46
53
  builder: ScallopBuilder;
47
54
  txBlock: SuiTxBlockWithCoreNormalMethods;
48
55
  }) => CoreQuickMethods;
56
+ export {};
@@ -4,9 +4,14 @@ 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
+ import { SCoinTxBlock } from './sCoin';
7
8
  export type * from './core';
8
9
  export type * from './spool';
9
10
  export type * from './borrowIncentive';
10
11
  export type * from './vesca';
11
12
  export type * from './loyaltyProgram';
12
- export type ScallopTxBlock = CoreTxBlock & SpoolTxBlock & ReferralTxBlock & LoyaltyProgramTxBlock & BorrowIncentiveTxBlock & VeScaTxBlock;
13
+ export type * from './sCoin';
14
+ export type BaseScallopTxBlock = ReferralTxBlock & LoyaltyProgramTxBlock & BorrowIncentiveTxBlock & VeScaTxBlock;
15
+ export type ScallopTxBlockWithoutSCoinTxBlock = SpoolTxBlock & BaseScallopTxBlock;
16
+ export type ScallopTxBlockWithoutCoreTxBlock = SCoinTxBlock & ScallopTxBlockWithoutSCoinTxBlock;
17
+ export type ScallopTxBlock = CoreTxBlock & ScallopTxBlockWithoutCoreTxBlock;
@@ -0,0 +1,37 @@
1
+ import { SuiObjectArg, SuiTxBlock as SuiKitTxBlock, TransactionResult } from '@scallop-io/sui-kit';
2
+ import { SupportSCoin } from '../constant';
3
+ import { ScallopBuilder } from 'src/models';
4
+ import { ScallopTxBlockWithoutSCoinTxBlock } from '.';
5
+ export type sCoinPkgIds = {
6
+ pkgId: string;
7
+ };
8
+ export type sCoinNormalMethods = {
9
+ /**
10
+ * Lock marketCoin and return sCoin
11
+ * @param marketCoinName
12
+ * @param marketCoin
13
+ * @returns
14
+ */
15
+ mintSCoin: (marketCoinName: SupportSCoin, marketCoin: SuiObjectArg) => TransactionResult;
16
+ /**
17
+ * Burn sCoin and return marketCoin
18
+ * @param sCoinName
19
+ * @param sCoin
20
+ * @returns
21
+ */
22
+ burnSCoin: (sCoinName: SupportSCoin, sCoin: SuiObjectArg) => TransactionResult;
23
+ };
24
+ export type sCoinQuickMethods = {
25
+ mintSCoinQuick: (marketCoinName: SupportSCoin, amount: number) => Promise<TransactionResult>;
26
+ burnSCoinQuick: (sCoinName: SupportSCoin, amount: number) => Promise<TransactionResult>;
27
+ };
28
+ export type SuiTxBlockWithSCoinNormalMethods = SuiKitTxBlock & ScallopTxBlockWithoutSCoinTxBlock & sCoinNormalMethods;
29
+ export type SCoinTxBlock = SuiTxBlockWithSCoinNormalMethods & sCoinQuickMethods;
30
+ export type GenerateSCoinNormalMethod = (params: {
31
+ builder: ScallopBuilder;
32
+ txBlock: SuiKitTxBlock;
33
+ }) => sCoinNormalMethods;
34
+ export type GenerateSCoinQuickMethod = (params: {
35
+ builder: ScallopBuilder;
36
+ txBlock: SuiTxBlockWithSCoinNormalMethods;
37
+ }) => sCoinQuickMethods;
@@ -2,6 +2,7 @@ import type { SuiTxBlock as SuiKitTxBlock, SuiAddressArg, SuiObjectArg, SuiTxArg
2
2
  import type { TransactionResult } from '@mysten/sui.js/transactions';
3
3
  import type { ScallopBuilder } from '../../models';
4
4
  import type { SupportStakeMarketCoins } from '../constant';
5
+ import { BaseScallopTxBlock } from '.';
5
6
  export type SpoolIds = {
6
7
  spoolPkg: string;
7
8
  };
@@ -16,7 +17,7 @@ export type SpoolQuickMethods = {
16
17
  unstakeQuick(amount: number, stakeMarketCoinName: SupportStakeMarketCoins, stakeAccountId?: SuiAddressArg): Promise<TransactionResult[]>;
17
18
  claimQuick(stakeMarketCoinName: SupportStakeMarketCoins, stakeAccountId?: SuiAddressArg): Promise<TransactionResult[]>;
18
19
  };
19
- export type SuiTxBlockWithSpoolNormalMethods = SuiKitTxBlock & SpoolNormalMethods;
20
+ export type SuiTxBlockWithSpoolNormalMethods = SuiKitTxBlock & BaseScallopTxBlock & SpoolNormalMethods;
20
21
  export type SpoolTxBlock = SuiTxBlockWithSpoolNormalMethods & SpoolQuickMethods;
21
22
  export type GenerateSpoolNormalMethod = (params: {
22
23
  builder: ScallopBuilder;
@@ -1,7 +1,7 @@
1
- import { SUPPORT_POOLS, SUPPORT_COLLATERALS, SUPPORT_ORACLES, SUPPORT_PACKAGES, SUPPORT_SPOOLS, SUPPORT_SPOOLS_REWARDS, SUPPORT_BORROW_INCENTIVE_POOLS, SUPPORT_BORROW_INCENTIVE_REWARDS } from '../../constants';
1
+ import { SUPPORT_POOLS, SUPPORT_COLLATERALS, SUPPORT_ORACLES, SUPPORT_PACKAGES, SUPPORT_SPOOLS, SUPPORT_SPOOLS_REWARDS, SUPPORT_BORROW_INCENTIVE_POOLS, SUPPORT_BORROW_INCENTIVE_REWARDS, SUPPORT_SCOIN } from '../../constants';
2
2
  type ParseMarketCoins<T extends string> = `s${T}`;
3
3
  type ParseCoins<T extends string> = T extends `s${infer R}` ? R : never;
4
- export type SupportCoins = SupportAssetCoins | SupportMarketCoins | SupportStakeMarketCoins;
4
+ export type SupportCoins = SupportAssetCoins | SupportMarketCoins | SupportStakeMarketCoins | SupportSCoin;
5
5
  export type SupportAssetCoins = SupportPoolCoins | SupportCollateralCoins | SupportStakeRewardCoins | SupportBorrowIncentiveRewardCoins;
6
6
  export type SupportPoolCoins = (typeof SUPPORT_POOLS)[number];
7
7
  export type SupportCollateralCoins = (typeof SUPPORT_COLLATERALS)[number];
@@ -11,6 +11,7 @@ export type SupportStakeCoins = Extract<SupportPoolCoins, ParseCoins<SupportStak
11
11
  export type SupportStakeRewardCoins = (typeof SUPPORT_SPOOLS_REWARDS)[number];
12
12
  export type SupportBorrowIncentiveCoins = (typeof SUPPORT_BORROW_INCENTIVE_POOLS)[number];
13
13
  export type SupportBorrowIncentiveRewardCoins = (typeof SUPPORT_BORROW_INCENTIVE_REWARDS)[number];
14
+ export type SupportSCoin = (typeof SUPPORT_SCOIN)[number];
14
15
  export type SupportOracleType = (typeof SUPPORT_ORACLES)[number];
15
16
  export type SupportPackageType = (typeof SUPPORT_PACKAGES)[number];
16
17
  export type SupportCoinDecimals = Record<SupportCoins, number>;
@@ -1,4 +1,4 @@
1
- import { SupportCoins, SupportAssetCoins, SupportMarketCoins, SupportStakeMarketCoins, SupportStakeRewardCoins, SupportBorrowIncentiveCoins, SupportBorrowIncentiveRewardCoins } from './common';
1
+ import { SupportCoins, SupportAssetCoins, SupportMarketCoins, SupportStakeMarketCoins, SupportStakeRewardCoins, SupportBorrowIncentiveCoins, SupportBorrowIncentiveRewardCoins, SupportSCoin } from './common';
2
2
  export type Coins = {
3
3
  [K in SupportCoins]: K;
4
4
  };
@@ -8,6 +8,9 @@ export type AssetCoins = {
8
8
  export type MarketCoins = {
9
9
  [K in SupportMarketCoins]: K;
10
10
  };
11
+ export type SCoins = {
12
+ [K in SupportSCoin]: K;
13
+ };
11
14
  export type StakeMarketCoins = {
12
15
  [K in SupportStakeMarketCoins]: K;
13
16
  };
@@ -20,6 +23,15 @@ export type BorrowIncentiveRewardCoins = {
20
23
  export type AssetCoinIds = {
21
24
  [key in SupportAssetCoins]: string;
22
25
  };
26
+ export type SCoinIds = {
27
+ [key in SupportSCoin]: string;
28
+ };
29
+ export type SCoinTreasuryCaps = {
30
+ [key in SupportSCoin]: string;
31
+ };
32
+ export type SCoinConverterTreasury = {
33
+ [key in SupportSCoin]: string;
34
+ };
23
35
  type PickFromUnion<T, K extends string> = K extends T ? K : never;
24
36
  export type WormholeCoinIds = {
25
37
  [key in PickFromUnion<SupportAssetCoins, 'eth' | 'btc' | 'usdc' | 'usdt' | 'apt' | 'sol'>]: string;
@@ -1,4 +1,4 @@
1
- import type { SupportPoolCoins, SupportCollateralCoins, SupportMarketCoins, CoinWrappedType } from '../constant';
1
+ import type { SupportPoolCoins, SupportCollateralCoins, SupportMarketCoins, CoinWrappedType, SupportSCoin } from '../constant';
2
2
  type OptionalKeys<T> = {
3
3
  [K in keyof T]?: T[K];
4
4
  };
@@ -6,6 +6,7 @@ export type MarketPools = OptionalKeys<Record<SupportPoolCoins, MarketPool>>;
6
6
  export type MarketCollaterals = OptionalKeys<Record<SupportCollateralCoins, MarketCollateral>>;
7
7
  export type CoinAmounts = OptionalKeys<Record<SupportPoolCoins, number>>;
8
8
  export type MarketCoinAmounts = OptionalKeys<Record<SupportMarketCoins, number>>;
9
+ export type SCoinAmounts = OptionalKeys<Record<SupportSCoin, number>>;
9
10
  export type BalanceSheet = {
10
11
  cash: string;
11
12
  debt: string;
@@ -4,3 +4,4 @@ export type * from './borrowIncentive';
4
4
  export type * from './portfolio';
5
5
  export type * from './vesca';
6
6
  export type * from './loyaltyProgram';
7
+ export type * from './sCoin';
@@ -47,6 +47,7 @@ export type ObligationAccount = {
47
47
  totalRiskLevel: number;
48
48
  totalDepositedPools: number;
49
49
  totalBorrowedPools: number;
50
+ totalRewardedPools: number;
50
51
  collaterals: OptionalKeys<Record<SupportCollateralCoins, ObligationCollateral>>;
51
52
  debts: OptionalKeys<Record<SupportPoolCoins, ObligationDebt>>;
52
53
  borrowIncentives: OptionalKeys<Record<SupportPoolCoins, ObligationBorrowIncentive>>;
@@ -0,0 +1 @@
1
+ export type sCoinBalance = number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scallop-io/sui-scallop-sdk",
3
- "version": "0.46.40",
3
+ "version": "0.46.42",
4
4
  "description": "Typescript sdk for interacting with Scallop contract on SUI",
5
5
  "keywords": [
6
6
  "sui",
@@ -44,7 +44,7 @@
44
44
  "@noble/hashes": "^1.3.2",
45
45
  "@pythnetwork/price-service-client": "^1.8.2",
46
46
  "@pythnetwork/pyth-sui-js": "2.0.0",
47
- "@scallop-io/sui-kit": "^0.45.0",
47
+ "@scallop-io/sui-kit": "0.52.0",
48
48
  "@scure/bip39": "^1.2.1",
49
49
  "@tanstack/query-core": "^5.28.0",
50
50
  "axios": "^1.6.0",
@@ -77,7 +77,7 @@
77
77
  },
78
78
  "peerDependencies": {
79
79
  "@mysten/sui.js": "0.52.0",
80
- "@scallop-io/sui-kit": "^0.45.0",
80
+ "@scallop-io/sui-kit": "0.52.0",
81
81
  "bn.js": "^5.2.1"
82
82
  },
83
83
  "lint-staged": {
@@ -4,7 +4,7 @@ import { SuiTxBlock as SuiKitTxBlock } from '@scallop-io/sui-kit';
4
4
  import { getObligations } from '../queries';
5
5
  import { updateOracles } from './oracle';
6
6
  import { requireSender } from '../utils';
7
- import type { SuiAddressArg } from '@scallop-io/sui-kit';
7
+ import type { SuiAddressArg, TransactionResult } from '@scallop-io/sui-kit';
8
8
  import type { ScallopBuilder } from '../models';
9
9
  import type {
10
10
  CoreIds,
@@ -13,14 +13,15 @@ import type {
13
13
  SuiTxBlockWithCoreNormalMethods,
14
14
  CoreTxBlock,
15
15
  ScallopTxBlock,
16
+ NestedResult,
16
17
  } from '../types';
17
18
 
18
19
  /**
19
20
  * Check and get Obligation information from transaction block.
20
21
  *
21
22
  * @description
22
- * If the obligation id is provided, direactly return it.
23
- * If both obligation id and key is provided, direactly return them.
23
+ * If the obligation id is provided, directly return it.
24
+ * If both obligation id and key is provided, directly return them.
24
25
  * Otherwise, automatically get obligation id and key from the sender.
25
26
  *
26
27
  * @param builder - Scallop builder instance.
@@ -75,11 +76,17 @@ const generateCoreNormalMethod: GenerateCoreNormalMethod = ({
75
76
  const referralWitnessType = `${referralPkgId}::scallop_referral_program::REFERRAL_WITNESS`;
76
77
 
77
78
  return {
78
- openObligation: () =>
79
- txBlock.moveCall(
79
+ openObligation: () => {
80
+ const [obligation, obligationKey, obligationHotPotato] = txBlock.moveCall(
80
81
  `${coreIds.protocolPkg}::open_obligation::open_obligation`,
81
82
  [coreIds.version]
82
- ),
83
+ );
84
+ return [obligation, obligationKey, obligationHotPotato] as [
85
+ NestedResult,
86
+ NestedResult,
87
+ NestedResult,
88
+ ];
89
+ },
83
90
  returnObligation: (obligation, obligationHotPotato) =>
84
91
  txBlock.moveCall(
85
92
  `${coreIds.protocolPkg}::open_obligation::return_obligation`,
@@ -300,11 +307,12 @@ const generateCoreQuickMethod: GenerateCoreQuickMethod = ({
300
307
  collateralCoinName
301
308
  );
302
309
  },
303
- depositQuick: async (amount, poolCoinName) => {
310
+ depositQuick: async (amount, poolCoinName, returnSCoin = true) => {
304
311
  const sender = requireSender(txBlock);
312
+ let marketCoinDeposit: TransactionResult | undefined;
305
313
  if (poolCoinName === 'sui') {
306
314
  const [suiCoin] = txBlock.splitSUIFromGas([amount]);
307
- return txBlock.deposit(suiCoin, poolCoinName);
315
+ marketCoinDeposit = txBlock.deposit(suiCoin, poolCoinName);
308
316
  } else {
309
317
  const { leftCoin, takeCoin } = await builder.selectCoin(
310
318
  txBlock,
@@ -313,20 +321,67 @@ const generateCoreQuickMethod: GenerateCoreQuickMethod = ({
313
321
  sender
314
322
  );
315
323
  txBlock.transferObjects([leftCoin], sender);
316
- return txBlock.deposit(takeCoin, poolCoinName);
324
+ marketCoinDeposit = txBlock.deposit(takeCoin, poolCoinName);
317
325
  }
326
+
327
+ // convert to sCoin
328
+ return returnSCoin
329
+ ? txBlock.mintSCoin(
330
+ builder.utils.parseMarketCoinName(poolCoinName),
331
+ marketCoinDeposit
332
+ )
333
+ : marketCoinDeposit;
318
334
  },
319
335
  withdrawQuick: async (amount, poolCoinName) => {
320
336
  const sender = requireSender(txBlock);
321
337
  const marketCoinName = builder.utils.parseMarketCoinName(poolCoinName);
322
- const { leftCoin, takeCoin } = await builder.selectMarketCoin(
323
- txBlock,
324
- marketCoinName,
325
- amount,
326
- sender
327
- );
328
- txBlock.transferObjects([leftCoin], sender);
329
- return txBlock.withdraw(takeCoin, poolCoinName);
338
+
339
+ // check if user has sCoin instead of marketCoin
340
+ try {
341
+ const sCoinName = builder.utils.parseSCoinName(poolCoinName);
342
+ if (!sCoinName) throw new Error(`No sCoin for ${poolCoinName}`);
343
+ const { leftCoin, takeCoin, totalAmount } = await builder.selectSCoin(
344
+ txBlock,
345
+ sCoinName,
346
+ amount,
347
+ sender
348
+ );
349
+ txBlock.transferObjects([leftCoin], sender);
350
+ const marketCoin = txBlock.burnSCoin(sCoinName, takeCoin);
351
+
352
+ const txResult = txBlock.withdraw(marketCoin, poolCoinName);
353
+
354
+ // check amount
355
+ amount -= totalAmount;
356
+ try {
357
+ if (amount > 0) {
358
+ // sCoin is not enough, try market coin
359
+ const { leftCoin, takeCoin } = await builder.selectMarketCoin(
360
+ txBlock,
361
+ marketCoinName,
362
+ amount,
363
+ sender
364
+ );
365
+ txBlock.transferObjects([leftCoin], sender);
366
+ txBlock.mergeCoins(txResult, [
367
+ txBlock.withdraw(takeCoin, poolCoinName),
368
+ ]);
369
+ }
370
+ } catch (e) {
371
+ // ignore
372
+ }
373
+ return txResult;
374
+ } catch (e) {
375
+ // no sCoin found
376
+ const { leftCoin, takeCoin } = await builder.selectMarketCoin(
377
+ txBlock,
378
+ marketCoinName,
379
+ amount,
380
+ sender
381
+ );
382
+ txBlock.transferObjects([leftCoin], sender);
383
+ return txBlock.withdraw(takeCoin, poolCoinName);
384
+ }
330
385
  },
331
386
  borrowQuick: async (amount, poolCoinName, obligationId, obligationKey) => {
332
387
  const obligationInfo = await requireObligationInfo(
@@ -8,6 +8,7 @@ import type { ScallopBuilder } from '../models';
8
8
  import type { ScallopTxBlock } from '../types';
9
9
  import { newReferralTxBlock } from './referralBuilder';
10
10
  import { newLoyaltyProgramTxBlock } from './loyaltyProgramBuilder';
11
+ import { newSCoinTxBlock } from './sCoinBuilder';
11
12
 
12
13
  /**
13
14
  * Create a new ScallopTxBlock instance.
@@ -28,7 +29,8 @@ export const newScallopTxBlock = (
28
29
  );
29
30
  const referralTxBlock = newReferralTxBlock(builder, borrowIncentiveTxBlock);
30
31
  const spoolTxBlock = newSpoolTxBlock(builder, referralTxBlock);
31
- const coreTxBlock = newCoreTxBlock(builder, spoolTxBlock);
32
+ const sCoinTxBlock = newSCoinTxBlock(builder, spoolTxBlock);
33
+ const coreTxBlock = newCoreTxBlock(builder, sCoinTxBlock);
32
34
 
33
35
  return new Proxy(coreTxBlock, {
34
36
  get: (target, prop) => {
@@ -42,6 +44,8 @@ export const newScallopTxBlock = (
42
44
  return Reflect.get(spoolTxBlock, prop);
43
45
  } else if (prop in loyaltyTxBlock) {
44
46
  return Reflect.get(loyaltyTxBlock, prop);
47
+ } else if (prop in sCoinTxBlock) {
48
+ return Reflect.get(sCoinTxBlock, prop);
45
49
  }
46
50
  return Reflect.get(target, prop);
47
51
  },
@@ -68,7 +68,7 @@ const generateLoyaltyProgramQuickMethod: GenerateLoyaltyProgramQuickMethod = ({
68
68
  };
69
69
 
70
70
  /**
71
- * Create an enhanced transaction block instance for interaction with borrow incentive modules of the Scallop contract.
71
+ * Create an enhanced transaction block instance for interaction with loyalty program modules of the Scallop contract.
72
72
  *
73
73
  * @param builder - Scallop builder instance.
74
74
  * @param initTxBlock - Scallop txBlock, txBlock created by SuiKit, or original transaction block.
@@ -117,7 +117,7 @@ const generateReferralQuickMethod: GenerateReferralQuickMethod = ({
117
117
  Infinity,
118
118
  builder.utils.parseCoinType(coinName)
119
119
  );
120
- txBlock.mergeCoins(rewardCoin, coins);
120
+ txBlock.mergeCoins(rewardCoin, coins.slice(0, 500));
121
121
  } catch (e) {
122
122
  // ignore
123
123
  } finally {