@scallop-io/sui-scallop-sdk 2.0.0 → 2.0.1

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scallop-io/sui-scallop-sdk",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "description": "Typescript sdk for interacting with Scallop contract on SUI",
5
5
  "keywords": [
6
6
  "sui",
@@ -9,7 +9,6 @@ import type {
9
9
  } from 'src/types';
10
10
  import { xOracleList as X_ORACLE_LIST } from 'src/constants';
11
11
  import { updatePythPriceFeeds } from './pyth';
12
- // import { updateSwitchboardAggregators } from './switchboard';
13
12
 
14
13
  /**
15
14
  * Update the price of the oracle for multiple coin.
@@ -66,20 +65,6 @@ export const updateOracles = async (
66
65
  await updatePythPriceFeeds(builder, assetCoinNames, txBlock);
67
66
  }
68
67
 
69
- // Handle Switchboard on-demand aggregator
70
- // if (flattenedRules.has('switchboard')) {
71
- // const switchboardAssetCoinNames = assetCoinNames.filter((assetCoinName) =>
72
- // filterAssetCoinNames(assetCoinName, 'switchboard')
73
- // );
74
- // if (switchboardAssetCoinNames.length > 0) {
75
- // await updateSwitchboardAggregators(
76
- // builder,
77
- // switchboardAssetCoinNames,
78
- // txBlock
79
- // );
80
- // }
81
- // }
82
-
83
68
  // Remove duplicate coin names.
84
69
  const updateAssetCoinNames = [...new Set(assetCoinNames)];
85
70
  for (const assetCoinName of updateAssetCoinNames) {
@@ -4,134 +4,9 @@ export const SDK_API_BASE_URL = 'https://sdk.api.scallop.io' as const;
4
4
  export const IS_VE_SCA_TEST: boolean = false;
5
5
  export const USE_TEST_ADDRESS: boolean = false;
6
6
 
7
- // export const ADDRESS_ID =
8
- // IS_VE_SCA_TEST || USE_TEST_ADDRESS
9
- // ? ('65fb07c39c845425d71d7b18' as const)
10
- // : ('67c44a103fe1b8c454eb9699' as const);
11
- // : ('66f8e7ed9bb9e07fdfb86bbb' as const);
12
-
13
7
  export const SCA_COIN_TYPE = IS_VE_SCA_TEST
14
8
  ? (`0x6cd813061a3adf3602b76545f076205f0c8e7ec1d3b1eab9a1da7992c18c0524::sca::SCA` as const)
15
9
  : ('0x7016aae72cfc67f2fadf55769c0a7dd54291a583b63051a5ed71081cce836ac6::sca::SCA' as const);
16
10
 
17
11
  export const OLD_BORROW_INCENTIVE_PROTOCOL_ID =
18
12
  '0xc63072e7f5f4983a2efaf5bdba1480d5e7d74d57948e1c7cc436f8e22cbeb410' as const;
19
-
20
- // export const SUPPORT_POOLS = [
21
- // 'usdc', // native USDC
22
- // 'sbeth', // sui bridge ETH
23
- // 'sbusdt', // sui bridge USDT
24
- // 'sbwbtc', // sui bridge WBTC
25
- // 'weth',
26
- // 'wbtc',
27
- // 'wusdc',
28
- // 'wusdt',
29
- // 'sui',
30
- // 'wapt',
31
- // 'wsol',
32
- // 'cetus',
33
- // 'afsui',
34
- // 'hasui',
35
- // 'vsui',
36
- // 'sca',
37
- // 'fud',
38
- // 'deep',
39
- // 'fdusd',
40
- // 'blub',
41
- // 'musd',
42
- // 'ns',
43
- // 'usdy',
44
- // ] as const;
45
-
46
- // export const SUPPORT_COLLATERALS = [
47
- // 'usdc', // native USDC
48
- // 'sbeth', // sui bridge ETH
49
- // 'sbusdt', // sui bridge USDT
50
- // 'sbwbtc', // sui bridge WBTC
51
- // 'weth',
52
- // 'wbtc',
53
- // 'wusdc',
54
- // 'wusdt',
55
- // 'sui',
56
- // 'wapt',
57
- // 'wsol',
58
- // 'cetus',
59
- // 'afsui',
60
- // 'hasui',
61
- // 'vsui',
62
- // 'sca',
63
- // 'fdusd',
64
- // 'usdy',
65
- // ] as const;
66
-
67
- // export const SUPPORT_SPOOLS = [
68
- // 'susdc',
69
- // 'sweth',
70
- // 'ssui',
71
- // 'swusdc',
72
- // 'swusdt',
73
- // 'scetus',
74
- // 'safsui',
75
- // 'shasui',
76
- // 'svsui',
77
- // ] as const;
78
-
79
- // export const SUPPORT_SCOIN = [
80
- // 'susdc',
81
- // 'ssbeth',
82
- // 'ssbusdt',
83
- // 'ssbwbtc',
84
- // 'ssui',
85
- // 'swusdc',
86
- // 'swusdt',
87
- // 'safsui',
88
- // 'shasui',
89
- // 'svsui',
90
- // 'sweth',
91
- // 'ssca',
92
- // 'scetus',
93
- // 'swsol',
94
- // 'swbtc',
95
- // 'sdeep',
96
- // 'sfud',
97
- // 'sfdusd',
98
- // 'sblub',
99
- // 'smusd',
100
- // 'sns',
101
- // 'susdy',
102
- // ] as const;
103
-
104
- // export const SUPPORT_SUI_BRIDGE = ['sbeth', 'sbusdt', 'sbwbtc'] as const;
105
- // export const SUPPORT_WORMHOLE = [
106
- // 'wusdc',
107
- // 'wusdt',
108
- // 'weth',
109
- // 'wbtc',
110
- // 'wapt',
111
- // 'wsol',
112
- // ] as const;
113
-
114
- // export const SUPPORT_SPOOLS_REWARDS = ['sui'] as const;
115
-
116
- // export const SUPPORT_BORROW_INCENTIVE_POOLS = [...SUPPORT_POOLS] as const;
117
-
118
- // export const SUPPORT_BORROW_INCENTIVE_REWARDS = [
119
- // ...SUPPORT_POOLS,
120
- // ...SUPPORT_SCOIN,
121
- // ] as const;
122
- // export const SUPPORT_ORACLES = ['supra', 'switchboard', 'pyth'] as const;
123
-
124
- // export const SUPPORT_PACKAGES = [
125
- // 'coinDecimalsRegistry',
126
- // 'math',
127
- // 'whitelist',
128
- // 'x',
129
- // 'protocol',
130
- // 'protocolWhitelist',
131
- // 'query',
132
- // 'supra',
133
- // 'pyth',
134
- // 'switchboard',
135
- // 'xOracle',
136
- // 'testCoin',
137
- // ] as const;
@@ -78,12 +78,25 @@ export class Scallop {
78
78
  * @param id - The API id of the addresses.
79
79
  * @return Scallop Address.
80
80
  */
81
- public async getScallopAddress(id?: string) {
81
+ public async getScallopAddress(id: string = this.params.addressId) {
82
82
  await this.address.read(id);
83
83
 
84
84
  return this.address;
85
85
  }
86
86
 
87
+ /**
88
+ * Get a scallop constants instance that already has initial data.
89
+ * @returns Scallop Constants
90
+ */
91
+ public async getScallopConstants(params?: Partial<ScallopConstantsParams>) {
92
+ await this.initConstants({
93
+ ...this.params,
94
+ ...params,
95
+ });
96
+
97
+ return this.constants;
98
+ }
99
+
87
100
  /**
88
101
  * Create a scallop builder instance that already has initial data.
89
102
  *
@@ -220,48 +220,6 @@ export class ScallopBuilder {
220
220
  args?: (SuiTxArg | SuiVecTxArg | SuiObjectArg | SuiAmountsArg)[],
221
221
  typeArgs?: string[]
222
222
  ) {
223
- // Disable for now
224
- // const resolvedQueryTarget =
225
- // await this.cache.queryGetNormalizedMoveFunction(target);
226
- // if (!resolvedQueryTarget) throw new Error('Invalid query target');
227
-
228
- // const { parameters } = resolvedQueryTarget;
229
- // try {
230
- // // we can try resolve the args first
231
- // const resolvedArgs = await Promise.all(
232
- // (args ?? []).map(async (arg, idx) => {
233
- // if (typeof arg !== 'string') return arg;
234
-
235
- // const cachedData = (await this.cache.queryGetObject(arg))?.data;
236
- // if (!cachedData) return arg;
237
-
238
- // const owner = cachedData.owner;
239
- // if (!owner || typeof owner !== 'object' || !('Shared' in owner))
240
- // return {
241
- // objectId: cachedData.objectId,
242
- // version: cachedData.version,
243
- // digest: cachedData.digest,
244
- // };
245
-
246
- // const parameter = parameters[idx];
247
- // if (
248
- // typeof parameter !== 'object' ||
249
- // !('MutableReference' in parameter || 'Reference' in parameter)
250
- // )
251
- // return arg;
252
-
253
- // return {
254
- // objectId: cachedData.objectId,
255
- // initialSharedVersion: owner.Shared.initial_shared_version,
256
- // mutable: 'MutableReference' in parameter,
257
- // };
258
- // })
259
- // );
260
- // return txb.moveCall(target, resolvedArgs, typeArgs);
261
- // } catch (e: any) {
262
- // console.error(e.message);
263
- // return txb.moveCall(target, args, typeArgs);
264
- // }
265
223
  return txb.moveCall(target, args, typeArgs);
266
224
  }
267
225
  }
@@ -112,7 +112,9 @@ export class ScallopConstants {
112
112
  return (
113
113
  this.isAddressInitialized && // address is initialized
114
114
  !this.isEmptyObject(this._poolAddresses) && // poolAddresses is initialized
115
- REQUIRED_WHITELIST_KEYS.every((t) => this.whitelist[t].size > 0) // whitelist is initialized
115
+ REQUIRED_WHITELIST_KEYS.every(
116
+ (t) => this.whitelist[t] && this.whitelist[t].size > 0
117
+ ) // whitelist is initialized
116
118
  );
117
119
  }
118
120
 
@@ -234,13 +234,6 @@ export class ScallopQuery {
234
234
  ) {
235
235
  const marketPools = await this.getMarketPools(undefined, args);
236
236
  return marketPools.pools[poolCoinName];
237
- // return await getMarketPool(
238
- // this,
239
- // poolCoinName,
240
- // args?.indexer,
241
- // args?.marketObject,
242
- // args?.coinPrice
243
- // );
244
237
  }
245
238
 
246
239
  /**
@@ -405,21 +405,6 @@ export const getMarketPools = async (
405
405
  const collaterals: MarketCollaterals = {};
406
406
 
407
407
  if (indexer) {
408
- // const marketPoolsIndexer = await query.indexer.getMarketPools();
409
-
410
- // const updateMarketPool = (marketPool: MarketPool) => {
411
- // if (!poolCoinNames.includes(marketPool.coinName)) return;
412
- // marketPool.coinPrice =
413
- // coinPrices[marketPool.coinName] ?? marketPool.coinPrice;
414
- // marketPool.coinWrappedType = query.utils.getCoinWrappedType(
415
- // marketPool.coinName
416
- // );
417
- // pools[marketPool.coinName] = marketPool;
418
- // };
419
-
420
- // Object.values(marketPoolsIndexer).forEach(updateMarketPool);
421
-
422
- // return pools;
423
408
  const marketIndexer = await query.indexer.getMarket();
424
409
 
425
410
  const updatePools = (item: MarketPool) => {
@@ -193,9 +193,7 @@ export const getPoolAddresses = async (
193
193
  spoolReward: '',
194
194
  };
195
195
  const _spoolData = addressApiResponse.spool.pools[`s${coinName}`];
196
- // @ts-ignore
197
196
  if (_spoolData) {
198
- // @ts-ignore
199
197
  const { id: spool, rewardPoolId: spoolReward } = _spoolData;
200
198
  spoolData = {
201
199
  spool,
@@ -146,8 +146,6 @@ export const getLending = async (
146
146
  },
147
147
  })
148
148
  : undefined;
149
- // some pool does not have spool
150
- // if (!spool) throw new Error(`Failed to fetch spool for ${poolCoinName}`);
151
149
 
152
150
  stakeAccounts =
153
151
  stakeAccounts || query.constants.whitelist.spool.has(marketCoinName)
@@ -2,11 +2,6 @@ import { SuiObjectResponse } from '@mysten/sui/client';
2
2
  import { ScallopAddress, ScallopUtils } from 'src/models';
3
3
  import { SupportOracleType, xOracleRuleType } from 'src/types';
4
4
 
5
- // const PRIMARY_PRICE_UPDATE_POLICY =
6
- // '0x56e48a141f20a3a6a6d3fc43e58b01fc63f756c08224870e7890c80ec9d2afee';
7
- // const SECONDARY_PRICE_UPDDATE_POLICY =
8
- // '0xef4d9430ae42c1b24199ac55e87ddd7262622447ee3c7de8868efe839b3d8705';
9
-
10
5
  /**
11
6
  * Query the price update policy table ids. Usually the value for these table will be constant.
12
7
  * @param query
@@ -43,11 +38,6 @@ export const getPriceUpdatePolicies = async (
43
38
  };
44
39
  };
45
40
 
46
- // const PRIMARY_PRICE_UPDATE_POLICY_VECSET_ID =
47
- // '0xc22c9d691ee4c780de09db91d8b487d863211ebf08720772144bcf716318826c';
48
- // const SECONDARY_PRICE_UPDATE_POLICY_VECSET_ID =
49
- // '0x3b184ff859f5de30eeaf186898e5224925be6bb6d2baa74347ef471a8cd1c0d3';
50
-
51
41
  export const getAssetOracles = async (
52
42
  utils: ScallopUtils,
53
43
  ruleType: xOracleRuleType
@@ -21,54 +21,38 @@ type ObligationKey = NestedResult;
21
21
  type ObligationHotPotato = NestedResult;
22
22
 
23
23
  export type CoreNormalMethods = {
24
- // openObligation: () => Promise<
25
24
  openObligation: () => [Obligation, ObligationKey, ObligationHotPotato];
26
25
  returnObligation: (
27
26
  obligation: SuiObjectArg,
28
27
  obligationHotPotato: SuiObjectArg
29
- // ) => Promise<void>;
30
28
  ) => void;
31
- // openObligationEntry: () => Promise<void>;
32
29
  openObligationEntry: () => void;
33
30
  addCollateral: (
34
31
  obligation: SuiObjectArg,
35
32
  coin: SuiObjectArg,
36
33
  collateralCoinName: string
37
- // ) => Promise<void>;
38
34
  ) => void;
39
35
  takeCollateral: (
40
36
  obligation: SuiObjectArg,
41
37
  obligationKey: SuiObjectArg,
42
38
  amount: number,
43
39
  collateralCoinName: string
44
- // ) => Promise<TransactionResult>;
45
- ) => TransactionResult;
46
- deposit: (
47
- coin: SuiObjectArg,
48
- poolCoinName: string
49
- // ) => Promise<TransactionResult>;
50
- ) => TransactionResult;
51
- depositEntry: (
52
- coin: SuiObjectArg,
53
- poolCoinName: string
54
- // ) => Promise<TransactionResult>;
55
40
  ) => TransactionResult;
41
+ deposit: (coin: SuiObjectArg, poolCoinName: string) => TransactionResult;
42
+ depositEntry: (coin: SuiObjectArg, poolCoinName: string) => TransactionResult;
56
43
  withdraw: (
57
44
  marketCoin: SuiObjectArg,
58
45
  poolCoinName: string
59
- // ) => Promise<TransactionResult>;
60
46
  ) => TransactionResult;
61
47
  withdrawEntry: (
62
48
  marketCoin: SuiObjectArg,
63
49
  poolCoinName: string
64
- // ) => Promise<TransactionResult>;
65
50
  ) => TransactionResult;
66
51
  borrow: (
67
52
  obligation: SuiObjectArg,
68
53
  obligationKey: SuiObjectArg,
69
54
  amount: number,
70
55
  poolCoinName: string
71
- // ) => Promise<TransactionResult>;
72
56
  ) => TransactionResult;
73
57
  borrowWithReferral: (
74
58
  obligation: SuiObjectArg,
@@ -76,31 +60,26 @@ export type CoreNormalMethods = {
76
60
  borrowReferral: SuiObjectArg,
77
61
  amount: number | SuiTxArg,
78
62
  poolCoinName: string
79
- // ) => Promise<TransactionResult>;
80
63
  ) => TransactionResult;
81
64
  borrowEntry: (
82
65
  obligation: SuiObjectArg,
83
66
  obligationKey: SuiObjectArg,
84
67
  amount: number,
85
68
  poolCoinName: string
86
- // ) => Promise<TransactionResult>;
87
69
  ) => TransactionResult;
88
70
  repay: (
89
71
  obligation: SuiObjectArg,
90
72
  coin: SuiObjectArg,
91
73
  poolCoinName: string
92
- // ) => Promise<void>;
93
74
  ) => void;
94
75
  borrowFlashLoan: (
95
76
  amount: number | SuiTxArg,
96
77
  poolCoinName: string
97
- // ) => Promise<TransactionResult>;
98
78
  ) => TransactionResult;
99
79
  repayFlashLoan: (
100
80
  coin: SuiObjectArg,
101
81
  loan: SuiObjectArg,
102
82
  poolCoinName: string
103
- // ) => Promise<void>;
104
83
  ) => void;
105
84
  };
106
85