@scallop-io/sui-scallop-sdk 2.0.0 → 2.0.2-switchboard-alpha.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.
@@ -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
  *
@@ -443,7 +443,7 @@ export class ScallopAddress {
443
443
  instance?: ScallopAddressInstanceParams
444
444
  ) {
445
445
  const { addressId, auth, network, forceAddressesInterface } = params;
446
- this.cache = instance?.cache ?? new ScallopCache({});
446
+ this.cache = instance?.cache ?? new ScallopCache(params);
447
447
 
448
448
  this._requestClient = axios.create({
449
449
  baseURL: API_BASE_URL,
@@ -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
  }
@@ -246,7 +246,7 @@ export class ScallopCache {
246
246
  return query;
247
247
  }
248
248
 
249
- public async queryGetNormalizedMoveFunction(target: string) {
249
+ private async queryGetNormalizedMoveFunction(target: string) {
250
250
  const { address, module, name } = parseStructTag(target);
251
251
  return this.queryClient.fetchQuery({
252
252
  queryKey: queryKeys.rpc.getNormalizedMoveFunction(target),
@@ -460,11 +460,7 @@ export class ScallopCache {
460
460
  input: GetBalanceParams
461
461
  ): Promise<CoinBalance | null> {
462
462
  if (!input.coinType) return null;
463
-
464
- return (
465
- ((await this.queryGetAllCoinBalances(input.owner)) ?? {})[
466
- normalizeStructTag(input.coinType)
467
- ] ?? '0'
468
- );
463
+ const coinBalances = await this.queryGetAllCoinBalances(input.owner);
464
+ return coinBalances[normalizeStructTag(input.coinType)] ?? null;
469
465
  }
470
466
  }
@@ -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
  /**
@@ -1,11 +1,26 @@
1
1
  import { SuiKit, SuiKitParams } from '@scallop-io/sui-kit';
2
2
  import { RPC_PROVIDERS } from 'src/constants/rpc';
3
3
 
4
- export const newSuiKit = (params: SuiKitParams) => {
4
+ export const newSuiKit = (params: Partial<SuiKitParams>) => {
5
+ let initParams;
6
+ if (
7
+ 'suiClients' in params &&
8
+ params.suiClients &&
9
+ params.suiClients?.length > 0
10
+ ) {
11
+ initParams = {
12
+ suiClients: params.suiClients,
13
+ };
14
+ } else {
15
+ initParams = {
16
+ fullnodeUrls:
17
+ 'fullnodeUrls' in params
18
+ ? (params?.fullnodeUrls ?? RPC_PROVIDERS)
19
+ : RPC_PROVIDERS,
20
+ };
21
+ }
5
22
  return new SuiKit({
6
23
  ...params,
7
- fullnodeUrls: Array.from(
8
- new Set([...(params.fullnodeUrls ?? []), ...RPC_PROVIDERS])
9
- ),
24
+ ...initParams,
10
25
  });
11
26
  };
@@ -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
 
@@ -74,7 +74,7 @@ export type ScallopCacheParams = {
74
74
  walletAddress?: string;
75
75
  cacheOptions?: QueryClientConfig;
76
76
  config?: ScallopCacheConfig;
77
- } & SuiKitParams;
77
+ } & Partial<SuiKitParams>;
78
78
 
79
79
  export type ScallopIndexerParams = ScallopCacheParams & {
80
80
  indexerApiUrl?: string;
@@ -99,6 +99,7 @@ export type ScallopConstantsParams = ScallopAddressParams & {
99
99
  export type ScallopUtilsParams = ScallopAddressParams &
100
100
  ScallopConstantsParams & {
101
101
  pythEndpoints?: string[];
102
+ switchboardSolanaRpc?: string;
102
103
  };
103
104
 
104
105
  export type ScallopQueryParams = ScallopUtilsParams & ScallopIndexerParams;
@@ -109,7 +110,7 @@ export type ScallopBuilderParams = ScallopQueryParams & {
109
110
  };
110
111
 
111
112
  export type ScallopClientParams = ScallopBuilderParams;
112
- export type ScallopParams = SuiKitParams &
113
+ export type ScallopParams = Partial<SuiKitParams> &
113
114
  ScallopAddressParams &
114
115
  ScallopConstantsParams & {
115
116
  walletAddress?: string;
@@ -1,25 +0,0 @@
1
- // export const PYTH_FEED_IDS: Record<string, string> = {
2
- // usdc: 'eaa020c61cc479712813461ce153894a96a6c00b21ed0cfc2798d1f9a9e9c94a',
3
- // sbeth: 'ff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace',
4
- // sbusdt: '2b89b9dc8fdf9f34709a5b106b472f0f39bb6ca9ce04b0fd7f2e971688e2e53b',
5
- // sbwbtc: 'e62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43',
6
- // weth: 'ff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace',
7
- // wbtc: 'e62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43',
8
- // wusdc: 'eaa020c61cc479712813461ce153894a96a6c00b21ed0cfc2798d1f9a9e9c94a',
9
- // wusdt: '2b89b9dc8fdf9f34709a5b106b472f0f39bb6ca9ce04b0fd7f2e971688e2e53b',
10
- // sui: '23d7315113f5b1d3ba7a83604c44b94d79f4fd69af77f804fc7f920a6dc65744',
11
- // wapt: '03ae4db29ed4ae33d323568895aa00337e658e348b37509f5372ae51f0af00d5',
12
- // wsol: 'ef0d8b6fda2ceba41da15d4095d1da392a0d2f8ed0c6c7bc0f4cfac8c280b56d',
13
- // cetus: 'e5b274b2611143df055d6e7cd8d93fe1961716bcd4dca1cad87a83bc1e78c1ef',
14
- // afsui: '23d7315113f5b1d3ba7a83604c44b94d79f4fd69af77f804fc7f920a6dc65744',
15
- // hasui: '23d7315113f5b1d3ba7a83604c44b94d79f4fd69af77f804fc7f920a6dc65744',
16
- // vsui: '23d7315113f5b1d3ba7a83604c44b94d79f4fd69af77f804fc7f920a6dc65744',
17
- // sca: '7e17f0ac105abe9214deb9944c30264f5986bf292869c6bd8e8da3ccd92d79bc',
18
- // fdusd: 'ccdc1a08923e2e4f4b1e6ea89de6acbc5fe1948e9706f5604b8cb50bc1ed3979',
19
- // deep: '29bdd5248234e33bd93d3b81100b5fa32eaa5997843847e2c2cb16d7c6d9f7ff',
20
- // fud: '6a4090703da959247727f2b490eb21aea95c8684ecfac675f432008830890c75',
21
- // blub: '5fc11ffe4975b624be495be038da30e30bee2004d8ae6282b5364577ef4ca92c',
22
- // musd: '2ee09cdb656959379b9262f89de5ff3d4dfed0dd34c072b3e22518496a65249c',
23
- // ns: 'bb5ff26e47a3a6cc7ec2fce1db996c2a145300edc5acaabe43bf9ff7c5dd5d32',
24
- // usdy: 'e3d1723999820435ebab53003a542ff26847720692af92523eea613a9a28d500',
25
- // };