@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
@@ -3,6 +3,7 @@ import type {
3
3
  SupportAssetCoins,
4
4
  SupportOracleType,
5
5
  SupportPackageType,
6
+ SupportSCoin,
6
7
  SupportStakeMarketCoins,
7
8
  } from './constant';
8
9
 
@@ -121,6 +122,18 @@ export interface AddressesInterface {
121
122
  rewardPool: string;
122
123
  userRewardTableId: string;
123
124
  };
125
+ scoin: {
126
+ id: string;
127
+ coins: Partial<
128
+ Record<
129
+ SupportSCoin,
130
+ {
131
+ coinType: string;
132
+ treasury: string;
133
+ }
134
+ >
135
+ >;
136
+ };
124
137
  }
125
138
 
126
139
  type AddressPathsProps<T> = T extends string
@@ -4,13 +4,17 @@ import type {
4
4
  SuiObjectArg,
5
5
  SuiTxArg,
6
6
  } from '@scallop-io/sui-kit';
7
- import type { TransactionResult } from '@mysten/sui.js/transactions';
7
+ import type {
8
+ TransactionArgument,
9
+ TransactionResult,
10
+ } from '@mysten/sui.js/transactions';
8
11
  import type { ScallopBuilder } from '../../models';
9
12
  import type {
10
13
  SupportCollateralCoins,
11
14
  SupportPoolCoins,
12
15
  SupportAssetCoins,
13
16
  } from '../constant';
17
+ import { ScallopTxBlockWithoutCoreTxBlock } from '.';
14
18
 
15
19
  export type CoreIds = {
16
20
  protocolPkg: string;
@@ -20,8 +24,16 @@ export type CoreIds = {
20
24
  xOracle: string;
21
25
  };
22
26
 
27
+ export type NestedResult = Extract<
28
+ TransactionArgument,
29
+ { kind: 'NestedResult' }
30
+ >;
31
+ type Obligation = NestedResult;
32
+ type ObligationKey = NestedResult;
33
+ type ObligationHotPotato = NestedResult;
34
+
23
35
  export type CoreNormalMethods = {
24
- openObligation: () => TransactionResult;
36
+ openObligation: () => [Obligation, ObligationKey, ObligationHotPotato];
25
37
  returnObligation: (
26
38
  obligation: SuiAddressArg,
27
39
  obligationHotPotato: SuiObjectArg
@@ -113,7 +125,8 @@ export type CoreQuickMethods = {
113
125
  ) => Promise<TransactionResult>;
114
126
  depositQuick: (
115
127
  amount: number,
116
- poolCoinName: SupportPoolCoins
128
+ poolCoinName: SupportPoolCoins,
129
+ returnSCoin?: boolean
117
130
  ) => Promise<TransactionResult>;
118
131
  withdrawQuick: (
119
132
  amount: number,
@@ -129,7 +142,9 @@ export type CoreQuickMethods = {
129
142
  ) => Promise<void>;
130
143
  };
131
144
 
132
- export type SuiTxBlockWithCoreNormalMethods = SuiKitTxBlock & CoreNormalMethods;
145
+ export type SuiTxBlockWithCoreNormalMethods = SuiKitTxBlock &
146
+ ScallopTxBlockWithoutCoreTxBlock &
147
+ CoreNormalMethods;
133
148
 
134
149
  export type CoreTxBlock = SuiTxBlockWithCoreNormalMethods & CoreQuickMethods;
135
150
 
@@ -4,16 +4,24 @@ 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
 
8
9
  export type * from './core';
9
10
  export type * from './spool';
10
11
  export type * from './borrowIncentive';
11
12
  export type * from './vesca';
12
13
  export type * from './loyaltyProgram';
14
+ export type * from './sCoin';
13
15
 
14
- export type ScallopTxBlock = CoreTxBlock &
15
- SpoolTxBlock &
16
- ReferralTxBlock &
16
+ export type BaseScallopTxBlock = ReferralTxBlock &
17
17
  LoyaltyProgramTxBlock &
18
18
  BorrowIncentiveTxBlock &
19
19
  VeScaTxBlock;
20
+
21
+ export type ScallopTxBlockWithoutSCoinTxBlock = SpoolTxBlock &
22
+ BaseScallopTxBlock;
23
+
24
+ export type ScallopTxBlockWithoutCoreTxBlock = SCoinTxBlock &
25
+ ScallopTxBlockWithoutSCoinTxBlock;
26
+
27
+ export type ScallopTxBlock = CoreTxBlock & ScallopTxBlockWithoutCoreTxBlock;
@@ -0,0 +1,61 @@
1
+ import {
2
+ SuiObjectArg,
3
+ SuiTxBlock as SuiKitTxBlock,
4
+ TransactionResult,
5
+ } from '@scallop-io/sui-kit';
6
+ import { SupportSCoin } from '../constant';
7
+ import { ScallopBuilder } from 'src/models';
8
+ import { ScallopTxBlockWithoutSCoinTxBlock } from '.';
9
+
10
+ export type sCoinPkgIds = {
11
+ pkgId: string;
12
+ };
13
+
14
+ export type sCoinNormalMethods = {
15
+ /**
16
+ * Lock marketCoin and return sCoin
17
+ * @param marketCoinName
18
+ * @param marketCoin
19
+ * @returns
20
+ */
21
+ mintSCoin: (
22
+ marketCoinName: SupportSCoin,
23
+ marketCoin: SuiObjectArg
24
+ ) => TransactionResult;
25
+ /**
26
+ * Burn sCoin and return marketCoin
27
+ * @param sCoinName
28
+ * @param sCoin
29
+ * @returns
30
+ */
31
+ burnSCoin: (
32
+ sCoinName: SupportSCoin,
33
+ sCoin: SuiObjectArg
34
+ ) => TransactionResult; // returns marketCoin
35
+ };
36
+
37
+ export type sCoinQuickMethods = {
38
+ mintSCoinQuick: (
39
+ marketCoinName: SupportSCoin,
40
+ amount: number
41
+ ) => Promise<TransactionResult>;
42
+ burnSCoinQuick: (
43
+ sCoinName: SupportSCoin,
44
+ amount: number
45
+ ) => Promise<TransactionResult>;
46
+ };
47
+
48
+ export type SuiTxBlockWithSCoinNormalMethods = SuiKitTxBlock &
49
+ ScallopTxBlockWithoutSCoinTxBlock &
50
+ sCoinNormalMethods;
51
+ export type SCoinTxBlock = SuiTxBlockWithSCoinNormalMethods & sCoinQuickMethods;
52
+
53
+ export type GenerateSCoinNormalMethod = (params: {
54
+ builder: ScallopBuilder;
55
+ txBlock: SuiKitTxBlock;
56
+ }) => sCoinNormalMethods;
57
+
58
+ export type GenerateSCoinQuickMethod = (params: {
59
+ builder: ScallopBuilder;
60
+ txBlock: SuiTxBlockWithSCoinNormalMethods;
61
+ }) => sCoinQuickMethods;
@@ -7,6 +7,7 @@ import type {
7
7
  import type { TransactionResult } from '@mysten/sui.js/transactions';
8
8
  import type { ScallopBuilder } from '../../models';
9
9
  import type { SupportStakeMarketCoins } from '../constant';
10
+ import { BaseScallopTxBlock } from '.';
10
11
 
11
12
  export type SpoolIds = {
12
13
  spoolPkg: string;
@@ -50,6 +51,7 @@ export type SpoolQuickMethods = {
50
51
  };
51
52
 
52
53
  export type SuiTxBlockWithSpoolNormalMethods = SuiKitTxBlock &
54
+ BaseScallopTxBlock &
53
55
  SpoolNormalMethods;
54
56
 
55
57
  export type SpoolTxBlock = SuiTxBlockWithSpoolNormalMethods & SpoolQuickMethods;
@@ -7,6 +7,7 @@ import {
7
7
  SUPPORT_SPOOLS_REWARDS,
8
8
  SUPPORT_BORROW_INCENTIVE_POOLS,
9
9
  SUPPORT_BORROW_INCENTIVE_REWARDS,
10
+ SUPPORT_SCOIN,
10
11
  } from '../../constants';
11
12
 
12
13
  type ParseMarketCoins<T extends string> = `s${T}`;
@@ -15,7 +16,8 @@ type ParseCoins<T extends string> = T extends `s${infer R}` ? R : never;
15
16
  export type SupportCoins =
16
17
  | SupportAssetCoins
17
18
  | SupportMarketCoins
18
- | SupportStakeMarketCoins;
19
+ | SupportStakeMarketCoins
20
+ | SupportSCoin;
19
21
  export type SupportAssetCoins =
20
22
  | SupportPoolCoins
21
23
  | SupportCollateralCoins
@@ -36,6 +38,7 @@ export type SupportBorrowIncentiveCoins =
36
38
  (typeof SUPPORT_BORROW_INCENTIVE_POOLS)[number];
37
39
  export type SupportBorrowIncentiveRewardCoins =
38
40
  (typeof SUPPORT_BORROW_INCENTIVE_REWARDS)[number];
41
+ export type SupportSCoin = (typeof SUPPORT_SCOIN)[number];
39
42
 
40
43
  export type SupportOracleType = (typeof SUPPORT_ORACLES)[number];
41
44
 
@@ -6,6 +6,7 @@ import {
6
6
  SupportStakeRewardCoins,
7
7
  SupportBorrowIncentiveCoins,
8
8
  SupportBorrowIncentiveRewardCoins,
9
+ SupportSCoin,
9
10
  } from './common';
10
11
 
11
12
  export type Coins = {
@@ -20,6 +21,10 @@ export type MarketCoins = {
20
21
  [K in SupportMarketCoins]: K;
21
22
  };
22
23
 
24
+ export type SCoins = {
25
+ [K in SupportSCoin]: K;
26
+ };
27
+
23
28
  export type StakeMarketCoins = {
24
29
  [K in SupportStakeMarketCoins]: K;
25
30
  };
@@ -36,6 +41,18 @@ export type AssetCoinIds = {
36
41
  [key in SupportAssetCoins]: string;
37
42
  };
38
43
 
44
+ export type SCoinIds = {
45
+ [key in SupportSCoin]: string;
46
+ };
47
+
48
+ export type SCoinTreasuryCaps = {
49
+ [key in SupportSCoin]: string;
50
+ };
51
+
52
+ export type SCoinConverterTreasury = {
53
+ [key in SupportSCoin]: string;
54
+ };
55
+
39
56
  type PickFromUnion<T, K extends string> = K extends T ? K : never;
40
57
 
41
58
  export type WormholeCoinIds = {
@@ -3,6 +3,7 @@ import type {
3
3
  SupportCollateralCoins,
4
4
  SupportMarketCoins,
5
5
  CoinWrappedType,
6
+ SupportSCoin,
6
7
  } from '../constant';
7
8
 
8
9
  type OptionalKeys<T> = {
@@ -18,6 +19,8 @@ export type MarketCoinAmounts = OptionalKeys<
18
19
  Record<SupportMarketCoins, number>
19
20
  >;
20
21
 
22
+ export type SCoinAmounts = OptionalKeys<Record<SupportSCoin, number>>;
23
+
21
24
  export type BalanceSheet = {
22
25
  cash: string;
23
26
  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';
@@ -69,6 +69,7 @@ export type ObligationAccount = {
69
69
  totalRiskLevel: number;
70
70
  totalDepositedPools: number;
71
71
  totalBorrowedPools: number;
72
+ totalRewardedPools: number;
72
73
  collaterals: OptionalKeys<
73
74
  Record<SupportCollateralCoins, ObligationCollateral>
74
75
  >;
@@ -0,0 +1 @@
1
+ export type sCoinBalance = number;
@@ -52,7 +52,7 @@ export const checkExtendLockPeriod = (
52
52
  (newUnlockAtInSecondTimestamp - prevUnlockAtInSecondTimestamp) /
53
53
  UNLOCK_ROUND_DURATION
54
54
  );
55
- console.log('availableLockPeriodInDays', availableLockPeriodInDays);
55
+
56
56
  if (lockPeriodInDays > availableLockPeriodInDays) {
57
57
  throw new Error(
58
58
  `Cannot extend lock period by ${lockPeriodInDays} days, maximum lock period is ~4 years (${MAX_LOCK_ROUNDS} days), remaining lock period is ${
package/src/utils/util.ts CHANGED
@@ -5,6 +5,7 @@ import {
5
5
  SUPPORT_SPOOLS_REWARDS,
6
6
  MAX_LOCK_DURATION,
7
7
  SUPPORT_BORROW_INCENTIVE_REWARDS,
8
+ SUPPORT_SCOIN,
8
9
  } from '../constants';
9
10
  import type { ScallopAddress } from '../models';
10
11
  import type {
@@ -13,20 +14,22 @@ import type {
13
14
  SupportMarketCoins,
14
15
  } from '../types';
15
16
 
17
+ const COIN_SET = Array.from(
18
+ new Set([
19
+ ...SUPPORT_POOLS,
20
+ ...SUPPORT_COLLATERALS,
21
+ ...SUPPORT_SPOOLS_REWARDS,
22
+ ...SUPPORT_BORROW_INCENTIVE_REWARDS,
23
+ ...SUPPORT_SCOIN,
24
+ ])
25
+ );
26
+
16
27
  export const isMarketCoin = (
17
28
  coinName: SupportCoins
18
29
  ): coinName is SupportMarketCoins => {
19
30
  const assetCoinName = coinName.slice(1).toLowerCase() as SupportAssetCoins;
20
31
  return (
21
- coinName.charAt(0).toLowerCase() === 's' &&
22
- [
23
- ...new Set([
24
- ...SUPPORT_POOLS,
25
- ...SUPPORT_COLLATERALS,
26
- ...SUPPORT_SPOOLS_REWARDS,
27
- ...SUPPORT_BORROW_INCENTIVE_REWARDS,
28
- ]),
29
- ].includes(assetCoinName)
32
+ coinName.charAt(0).toLowerCase() === 's' && COIN_SET.includes(assetCoinName)
30
33
  );
31
34
  };
32
35
 
@@ -54,14 +57,7 @@ export const parseDataFromPythPriceFeed = (
54
57
  feed: PriceFeed,
55
58
  address: ScallopAddress
56
59
  ) => {
57
- const assetCoinNames = [
58
- ...new Set([
59
- ...SUPPORT_POOLS,
60
- ...SUPPORT_COLLATERALS,
61
- ...SUPPORT_SPOOLS_REWARDS,
62
- ...SUPPORT_BORROW_INCENTIVE_REWARDS,
63
- ]),
64
- ] as SupportAssetCoins[];
60
+ const assetCoinNames = COIN_SET as SupportAssetCoins[];
65
61
  const assetCoinName = assetCoinNames.find((assetCoinName) => {
66
62
  return (
67
63
  address.get(`core.coins.${assetCoinName}.oracle.pyth.feed`) === feed.id