@scallop-io/sui-scallop-sdk 1.4.6 → 1.4.8

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 (37) hide show
  1. package/dist/constants/index.d.ts +0 -1
  2. package/dist/constants/poolAddress.d.ts +1 -0
  3. package/dist/index.d.ts +0 -1
  4. package/dist/index.js +1657 -1472
  5. package/dist/index.js.map +1 -1
  6. package/dist/index.mjs +1866 -1677
  7. package/dist/index.mjs.map +1 -1
  8. package/dist/models/scallop.d.ts +1 -2
  9. package/dist/models/scallopCache.d.ts +16 -10
  10. package/dist/models/scallopQuery.d.ts +75 -3
  11. package/dist/queries/poolAddressesQuery.d.ts +2 -0
  12. package/dist/queries/portfolioQuery.d.ts +66 -3
  13. package/dist/types/model.d.ts +8 -2
  14. package/dist/utils/index.d.ts +0 -2
  15. package/package.json +1 -1
  16. package/src/constants/index.ts +0 -1
  17. package/src/constants/poolAddress.ts +93 -25
  18. package/src/index.ts +0 -1
  19. package/src/models/scallop.ts +8 -13
  20. package/src/models/scallopAddress.ts +2 -9
  21. package/src/models/scallopBuilder.ts +3 -6
  22. package/src/models/scallopCache.ts +88 -47
  23. package/src/models/scallopClient.ts +3 -6
  24. package/src/models/scallopIndexer.ts +1 -5
  25. package/src/models/scallopQuery.ts +49 -16
  26. package/src/models/scallopUtils.ts +7 -11
  27. package/src/queries/coreQuery.ts +4 -4
  28. package/src/queries/poolAddressesQuery.ts +6 -0
  29. package/src/queries/portfolioQuery.ts +238 -12
  30. package/src/queries/sCoinQuery.ts +2 -2
  31. package/src/types/model.ts +13 -2
  32. package/src/utils/index.ts +0 -2
  33. package/src/utils/indexer.ts +3 -1
  34. package/dist/constants/tokenBucket.d.ts +0 -2
  35. package/dist/utils/tokenBucket.d.ts +0 -11
  36. package/src/constants/tokenBucket.ts +0 -2
  37. package/src/utils/tokenBucket.ts +0 -68
@@ -1,5 +1,5 @@
1
1
  import { API_BASE_URL, USE_TEST_ADDRESS } from '../constants';
2
- import { SuiKit, type NetworkType } from '@scallop-io/sui-kit';
2
+ import { type NetworkType } from '@scallop-io/sui-kit';
3
3
  import type {
4
4
  ScallopAddressParams,
5
5
  AddressesInterface,
@@ -7,7 +7,6 @@ import type {
7
7
  ScallopAddressInstanceParams,
8
8
  } from '../types';
9
9
  import { ScallopCache } from './scallopCache';
10
- import { DEFAULT_CACHE_OPTIONS } from 'src/constants/cache';
11
10
  import axios, { AxiosInstance } from 'axios';
12
11
  import { TEST_ADDRESSES } from 'src/constants/testAddress';
13
12
  import { queryKeys } from 'src/constants';
@@ -379,13 +378,7 @@ export class ScallopAddress {
379
378
  instance?: ScallopAddressInstanceParams
380
379
  ) {
381
380
  const { id, auth, network, forceInterface } = params;
382
- this.cache =
383
- instance?.cache ??
384
- new ScallopCache(
385
- instance?.suiKit ?? new SuiKit({}),
386
- undefined,
387
- DEFAULT_CACHE_OPTIONS
388
- );
381
+ this.cache = instance?.cache ?? new ScallopCache({});
389
382
 
390
383
  this._requestClient = axios.create({
391
384
  baseURL: API_BASE_URL,
@@ -24,7 +24,6 @@ import type {
24
24
  SelectCoinReturnType,
25
25
  } from '../types';
26
26
  import { ScallopCache } from './scallopCache';
27
- import { DEFAULT_CACHE_OPTIONS } from 'src/constants/cache';
28
27
  import { newSuiKit } from './suiKit';
29
28
 
30
29
  /**
@@ -66,11 +65,9 @@ export class ScallopBuilder {
66
65
  this.address = this.utils.address;
67
66
  this.cache = this.address.cache;
68
67
  } else {
69
- this.cache = new ScallopCache(
70
- this.suiKit,
71
- this.walletAddress,
72
- DEFAULT_CACHE_OPTIONS
73
- );
68
+ this.cache = new ScallopCache(this.params, {
69
+ suiKit: this.suiKit,
70
+ });
74
71
  this.address = new ScallopAddress(
75
72
  {
76
73
  id: params?.addressesId ?? ADDRESSES_ID,
@@ -1,4 +1,4 @@
1
- import { QueryClient, QueryClientConfig } from '@tanstack/query-core';
1
+ import { QueryClient } from '@tanstack/query-core';
2
2
  import {
3
3
  SuiObjectArg,
4
4
  SuiTxBlock,
@@ -17,14 +17,12 @@ import type {
17
17
  GetDynamicFieldObjectParams,
18
18
  GetBalanceParams,
19
19
  SuiClient,
20
+ CoinBalance,
20
21
  } from '@mysten/sui/client';
21
22
  import { DEFAULT_CACHE_OPTIONS } from 'src/constants/cache';
22
- import { callWithRateLimit, TokenBucket } from 'src/utils';
23
- import {
24
- DEFAULT_INTERVAL_IN_MS,
25
- DEFAULT_TOKENS_PER_INTERVAL,
26
- } from 'src/constants/tokenBucket';
27
23
  import { queryKeys } from 'src/constants';
24
+ import { ScallopCacheInstanceParams, ScallopCacheParams } from 'src/types';
25
+ import { newSuiKit } from './suiKit';
28
26
 
29
27
  type QueryInspectTxnParams = {
30
28
  queryTarget: string;
@@ -32,6 +30,9 @@ type QueryInspectTxnParams = {
32
30
  typeArgs?: any[];
33
31
  };
34
32
 
33
+ const DEFAULT_TOKENS_PER_INTERVAL = 10;
34
+ const DEFAULT_INTERVAL_IN_MS = 250;
35
+
35
36
  /**
36
37
  * @description
37
38
  * It provides caching for moveCall, RPC Request, and API Request.
@@ -46,20 +47,26 @@ type QueryInspectTxnParams = {
46
47
  */
47
48
 
48
49
  export class ScallopCache {
49
- public readonly queryClient: QueryClient;
50
- public readonly _suiKit: SuiKit;
51
- private tokenBucket: TokenBucket;
50
+ public readonly params: ScallopCacheParams;
51
+
52
+ public queryClient: QueryClient;
53
+ public suiKit: SuiKit;
54
+ // private tokenBucket: TokenBucket;
52
55
  public walletAddress: string;
56
+ private tokensPerInterval: number = DEFAULT_TOKENS_PER_INTERVAL;
57
+ private interval: number = DEFAULT_INTERVAL_IN_MS;
58
+ private tokens: number;
59
+ private lastRefill: number;
53
60
 
54
61
  public constructor(
55
- suiKit: SuiKit,
56
- walletAddress?: string,
57
- cacheOptions?: QueryClientConfig,
58
- tokenBucket?: TokenBucket,
59
- queryClient?: QueryClient
62
+ params: ScallopCacheParams,
63
+ instance?: ScallopCacheInstanceParams
60
64
  ) {
65
+ this.params = params;
66
+ this.suiKit = instance?.suiKit ?? newSuiKit(params);
61
67
  this.queryClient =
62
- queryClient ?? new QueryClient(cacheOptions ?? DEFAULT_CACHE_OPTIONS);
68
+ instance?.queryClient ??
69
+ new QueryClient(params?.cacheOptions ?? DEFAULT_CACHE_OPTIONS);
63
70
 
64
71
  // handle case where there's existing queryClient and cacheOptions is also passed
65
72
  // if (queryClient && cacheOptions) {
@@ -71,22 +78,62 @@ export class ScallopCache {
71
78
  // // if(cacheOptions.mutations)this.queryClient.setMutationDefaults(cacheOptions.mutations);
72
79
  // }
73
80
 
74
- this._suiKit = suiKit;
75
- this.tokenBucket =
76
- tokenBucket ??
77
- new TokenBucket(DEFAULT_TOKENS_PER_INTERVAL, DEFAULT_INTERVAL_IN_MS);
78
- this.walletAddress = walletAddress ?? suiKit.currentAddress();
81
+ this.tokens = this.tokensPerInterval;
82
+ this.lastRefill = Date.now();
83
+ this.walletAddress = params.walletAddress ?? this.suiKit.currentAddress();
84
+ }
85
+
86
+ private get client(): SuiClient {
87
+ return this.suiKit.client();
79
88
  }
80
89
 
81
- private get suiKit(): SuiKit {
82
- if (!this._suiKit) {
83
- throw new Error('SuiKit instance is not initialized');
90
+ private refill() {
91
+ const now = Date.now();
92
+ const elapsed = now - this.lastRefill;
93
+
94
+ if (elapsed >= this.interval) {
95
+ const tokensToAdd =
96
+ Math.floor(elapsed / this.interval) * this.tokensPerInterval;
97
+ this.tokens = Math.min(this.tokens + tokensToAdd, this.tokensPerInterval);
98
+
99
+ // Update lastRefill to reflect the exact time of the last "refill"
100
+ this.lastRefill += Math.floor(elapsed / this.interval) * this.interval;
84
101
  }
85
- return this._suiKit;
86
102
  }
87
103
 
88
- private get client(): SuiClient {
89
- return this.suiKit.client();
104
+ private removeTokens(count: number) {
105
+ this.refill();
106
+ if (this.tokens >= count) {
107
+ this.tokens -= count;
108
+ return true;
109
+ }
110
+ return false;
111
+ }
112
+
113
+ private async callWithRateLimit<T>(
114
+ fn: () => Promise<T>,
115
+ maxRetries = 15,
116
+ backoffFactor = 1.25 // The factor by which to increase the delay
117
+ ): Promise<T | null> {
118
+ let retries = 0;
119
+
120
+ const tryRequest = async (): Promise<T | null> => {
121
+ if (this.removeTokens(1)) {
122
+ const result = await fn();
123
+ return result;
124
+ } else if (retries < maxRetries) {
125
+ retries++;
126
+ const delay = this.interval * Math.pow(backoffFactor, retries);
127
+ // console.error(`Rate limit exceeded, retrying in ${delay} ms`);
128
+ await new Promise((resolve) => setTimeout(resolve, delay));
129
+ return tryRequest();
130
+ } else {
131
+ console.error('Maximum retries reached');
132
+ return null;
133
+ }
134
+ };
135
+
136
+ return tryRequest();
90
137
  }
91
138
 
92
139
  /**
@@ -168,8 +215,7 @@ export class ScallopCache {
168
215
  retryDelay: 1000,
169
216
  queryKey: queryKeys.rpc.getInspectTxn(queryTarget, args, typeArgs),
170
217
  queryFn: async () => {
171
- return await callWithRateLimit(
172
- this.tokenBucket,
218
+ return await this.callWithRateLimit(
173
219
  async () => await this.suiKit.inspectTxn(txBlock)
174
220
  );
175
221
  },
@@ -182,8 +228,7 @@ export class ScallopCache {
182
228
  return this.queryClient.fetchQuery({
183
229
  queryKey: queryKeys.rpc.getNormalizedMoveFunction(target),
184
230
  queryFn: async () => {
185
- return await callWithRateLimit(
186
- this.tokenBucket,
231
+ return await this.callWithRateLimit(
187
232
  async () =>
188
233
  await this.suiKit.client().getNormalizedMoveFunction({
189
234
  package: address,
@@ -215,8 +260,7 @@ export class ScallopCache {
215
260
  retryDelay: 1000,
216
261
  queryKey: queryKeys.rpc.getObject(objectId, options),
217
262
  queryFn: async () => {
218
- return await callWithRateLimit(
219
- this.tokenBucket,
263
+ return await this.callWithRateLimit(
220
264
  async () =>
221
265
  await this.client.getObject({
222
266
  id: objectId,
@@ -250,8 +294,7 @@ export class ScallopCache {
250
294
  options
251
295
  ),
252
296
  queryFn: async () => {
253
- const results = await callWithRateLimit(
254
- this.tokenBucket,
297
+ const results = await this.callWithRateLimit(
255
298
  async () => await this.suiKit.getObjects(objectIds, options)
256
299
  );
257
300
  if (results) {
@@ -288,8 +331,7 @@ export class ScallopCache {
288
331
  retryDelay: 1000,
289
332
  queryKey: queryKeys.rpc.getOwnedObjects(input),
290
333
  queryFn: async () => {
291
- const results = await callWithRateLimit(
292
- this.tokenBucket,
334
+ const results = await this.callWithRateLimit(
293
335
  async () => await this.client.getOwnedObjects(input)
294
336
  );
295
337
  if (results && results.data.length > 0) {
@@ -332,8 +374,7 @@ export class ScallopCache {
332
374
  retryDelay: 1000,
333
375
  queryKey: queryKeys.rpc.getDynamicFields(input),
334
376
  queryFn: async () => {
335
- return await callWithRateLimit(
336
- this.tokenBucket,
377
+ return await this.callWithRateLimit(
337
378
  async () => await this.client.getDynamicFields(input)
338
379
  );
339
380
  },
@@ -348,7 +389,7 @@ export class ScallopCache {
348
389
  retryDelay: (attemptIndex) => Math.min(1000 * attemptIndex, 8000),
349
390
  queryKey: queryKeys.rpc.getDynamicFieldObject(input),
350
391
  queryFn: async () => {
351
- const result = await callWithRateLimit(this.tokenBucket, () =>
392
+ const result = await this.callWithRateLimit(() =>
352
393
  this.client.getDynamicFieldObject(input)
353
394
  );
354
395
  if (result?.data) {
@@ -376,26 +417,24 @@ export class ScallopCache {
376
417
 
377
418
  public async queryGetAllCoinBalances(
378
419
  owner: string
379
- ): Promise<{ [k: string]: string }> {
420
+ ): Promise<{ [k: string]: CoinBalance }> {
380
421
  return this.queryClient.fetchQuery({
381
422
  retry: this.retryFn,
382
423
  retryDelay: 1000,
383
424
  queryKey: queryKeys.rpc.getAllCoinBalances(owner),
384
425
  queryFn: async () => {
385
- const allBalances = await callWithRateLimit(
386
- this.tokenBucket,
426
+ const allBalances = await this.callWithRateLimit(
387
427
  async () => await this.client.getAllBalances({ owner })
388
428
  );
389
429
  if (!allBalances) return {};
390
430
  const balances = allBalances.reduce(
391
431
  (acc, coinBalance) => {
392
432
  if (coinBalance.totalBalance !== '0') {
393
- acc[normalizeStructTag(coinBalance.coinType)] =
394
- coinBalance.totalBalance;
433
+ acc[normalizeStructTag(coinBalance.coinType)] = coinBalance;
395
434
  }
396
435
  return acc;
397
436
  },
398
- {} as { [k: string]: string }
437
+ {} as { [k: string]: CoinBalance }
399
438
  );
400
439
 
401
440
  return balances;
@@ -403,8 +442,10 @@ export class ScallopCache {
403
442
  });
404
443
  }
405
444
 
406
- public async queryGetCoinBalance(input: GetBalanceParams): Promise<string> {
407
- if (!input.coinType) return '0';
445
+ public async queryGetCoinBalance(
446
+ input: GetBalanceParams
447
+ ): Promise<CoinBalance | null> {
448
+ if (!input.coinType) return null;
408
449
 
409
450
  return (
410
451
  ((await this.queryGetAllCoinBalances(input.owner)) ?? {})[
@@ -1,6 +1,5 @@
1
1
  import { normalizeSuiAddress } from '@mysten/sui/utils';
2
2
  import { SuiKit } from '@scallop-io/sui-kit';
3
- import { DEFAULT_CACHE_OPTIONS } from 'src/constants/cache';
4
3
  import {
5
4
  ADDRESSES_ID,
6
5
  SUPPORT_BORROW_INCENTIVE_POOLS,
@@ -75,11 +74,9 @@ export class ScallopClient {
75
74
  this.address = this.utils.address;
76
75
  this.cache = this.address.cache;
77
76
  } else {
78
- this.cache = new ScallopCache(
79
- this.suiKit,
80
- this.walletAddress,
81
- DEFAULT_CACHE_OPTIONS
82
- );
77
+ this.cache = new ScallopCache(this.params, {
78
+ suiKit: this.suiKit,
79
+ });
83
80
  this.address = new ScallopAddress(
84
81
  {
85
82
  id: params?.addressesId ?? ADDRESSES_ID,
@@ -22,8 +22,6 @@ import type {
22
22
  ScallopIndexerInstanceParams,
23
23
  } from '../types';
24
24
  import { ScallopCache } from './scallopCache';
25
- import { DEFAULT_CACHE_OPTIONS } from 'src/constants/cache';
26
- import { SuiKit } from '@scallop-io/sui-kit';
27
25
  import { queryKeys } from 'src/constants';
28
26
 
29
27
  /**
@@ -48,9 +46,7 @@ export class ScallopIndexer {
48
46
  instance?: ScallopIndexerInstanceParams
49
47
  ) {
50
48
  this.params = params;
51
- this.cache =
52
- instance?.cache ??
53
- new ScallopCache(new SuiKit({}), undefined, DEFAULT_CACHE_OPTIONS);
49
+ this.cache = instance?.cache ?? new ScallopCache(this.params);
54
50
  this._requestClient = axios.create({
55
51
  baseURL: SDK_API_BASE_URL,
56
52
  headers: {
@@ -1,10 +1,5 @@
1
1
  import { SuiKit, SuiObjectArg } from '@scallop-io/sui-kit';
2
- import {
3
- ADDRESSES_ID,
4
- SUPPORT_POOLS,
5
- SUPPORT_SPOOLS,
6
- DEFAULT_CACHE_OPTIONS,
7
- } from '../constants';
2
+ import { ADDRESSES_ID, SUPPORT_POOLS, SUPPORT_SPOOLS } from '../constants';
8
3
  import {
9
4
  queryMarket,
10
5
  getObligations,
@@ -47,6 +42,7 @@ import {
47
42
  getAllCoinPrices,
48
43
  getAllAddresses,
49
44
  isIsolatedAsset,
45
+ getUserPortfolio,
50
46
  } from '../queries';
51
47
  import {
52
48
  ScallopQueryParams,
@@ -63,6 +59,7 @@ import {
63
59
  MarketPool,
64
60
  CoinPrices,
65
61
  MarketPools,
62
+ MarketCollaterals,
66
63
  } from '../types';
67
64
  import { ScallopAddress } from './scallopAddress';
68
65
  import { ScallopUtils } from './scallopUtils';
@@ -112,11 +109,9 @@ export class ScallopQuery {
112
109
  this.address = instance.utils.address;
113
110
  this.cache = this.address.cache;
114
111
  } else {
115
- this.cache = new ScallopCache(
116
- this.suiKit,
117
- this.walletAddress,
118
- DEFAULT_CACHE_OPTIONS
119
- );
112
+ this.cache = new ScallopCache(this.params, {
113
+ suiKit: this.suiKit,
114
+ });
120
115
  this.address = new ScallopAddress(
121
116
  {
122
117
  id: params?.addressesId ?? ADDRESSES_ID,
@@ -582,9 +577,20 @@ export class ScallopQuery {
582
577
  public async getLendings(
583
578
  poolCoinNames?: SupportPoolCoins[],
584
579
  ownerAddress: string = this.walletAddress,
585
- args?: { indexer?: boolean }
580
+ args?: {
581
+ indexer?: boolean;
582
+ marketPools?: MarketPools;
583
+ coinPrices?: CoinPrices;
584
+ }
586
585
  ) {
587
- return await getLendings(this, poolCoinNames, ownerAddress, args?.indexer);
586
+ return await getLendings(
587
+ this,
588
+ poolCoinNames,
589
+ ownerAddress,
590
+ args?.marketPools,
591
+ args?.coinPrices,
592
+ args?.indexer
593
+ );
588
594
  }
589
595
 
590
596
  /**
@@ -615,9 +621,22 @@ export class ScallopQuery {
615
621
  */
616
622
  public async getObligationAccounts(
617
623
  ownerAddress: string = this.walletAddress,
618
- args?: { indexer?: boolean }
624
+ args?: {
625
+ indexer?: boolean;
626
+ market?: {
627
+ collaterals: MarketCollaterals;
628
+ pools: MarketPools;
629
+ };
630
+ coinPrices?: CoinPrices;
631
+ }
619
632
  ) {
620
- return await getObligationAccounts(this, ownerAddress, args?.indexer);
633
+ return await getObligationAccounts(
634
+ this,
635
+ ownerAddress,
636
+ args?.market,
637
+ args?.coinPrices,
638
+ args?.indexer
639
+ );
621
640
  }
622
641
 
623
642
  /**
@@ -844,10 +863,24 @@ export class ScallopQuery {
844
863
  }
845
864
 
846
865
  /**
847
- * Query all address (lending pool, collateral pool, borrow dynamics, interest models) of all pool
866
+ * Query all address (lending pool, collateral pool, borrow dynamics, interest models, etc.) of all pool
848
867
  * @returns
849
868
  */
850
869
  public async getPoolAddresses() {
851
870
  return getAllAddresses(this);
852
871
  }
872
+
873
+ /**
874
+ * Get user portfolio
875
+ */
876
+ public async getUserPortfolio(args?: {
877
+ walletAddress?: string;
878
+ indexer?: boolean;
879
+ }) {
880
+ return getUserPortfolio(
881
+ this,
882
+ args?.walletAddress ?? this.walletAddress,
883
+ args?.indexer ?? false
884
+ );
885
+ }
853
886
  }
@@ -33,7 +33,6 @@ import {
33
33
  } from '../utils';
34
34
  import { PYTH_ENDPOINTS, PYTH_FEED_IDS } from 'src/constants/pyth';
35
35
  import { ScallopCache } from './scallopCache';
36
- import { DEFAULT_CACHE_OPTIONS } from 'src/constants/cache';
37
36
  import type {
38
37
  ScallopUtilsParams,
39
38
  SupportCoins,
@@ -81,21 +80,18 @@ export class ScallopUtils {
81
80
  pythEndpoints: params.pythEndpoints ?? PYTH_ENDPOINTS['mainnet'],
82
81
  ...params,
83
82
  };
83
+ this.walletAddress =
84
+ params.walletAddress ?? instance?.suiKit?.currentAddress() ?? '';
84
85
  this.suiKit =
85
- instance?.suiKit ?? instance?.address?.cache._suiKit ?? newSuiKit(params);
86
-
87
- this.walletAddress = params.walletAddress ?? this.suiKit.currentAddress();
86
+ instance?.suiKit ?? instance?.address?.cache.suiKit ?? newSuiKit(params);
88
87
 
89
88
  if (instance?.address) {
90
89
  this.address = instance.address;
91
90
  this.cache = this.address.cache;
92
- this.suiKit = this.address.cache._suiKit;
93
91
  } else {
94
- this.cache = new ScallopCache(
95
- this.suiKit,
96
- this.walletAddress,
97
- DEFAULT_CACHE_OPTIONS
98
- );
92
+ this.cache = new ScallopCache(this.params, {
93
+ suiKit: this.suiKit,
94
+ });
99
95
  this.address =
100
96
  instance?.address ??
101
97
  new ScallopAddress(
@@ -450,7 +446,7 @@ export class ScallopUtils {
450
446
  coinType: string = SUI_TYPE_ARG,
451
447
  ownerAddress?: string
452
448
  ) {
453
- ownerAddress = ownerAddress ?? this.suiKit.currentAddress();
449
+ ownerAddress = ownerAddress ?? this.walletAddress;
454
450
  const coins = await this.suiKit.suiInteractor.selectCoins(
455
451
  ownerAddress,
456
452
  amount,
@@ -1079,11 +1079,11 @@ export const getCoinAmount = async (
1079
1079
  ) => {
1080
1080
  const owner = ownerAddress ?? query.suiKit.currentAddress();
1081
1081
  const coinType = query.utils.parseCoinType(assetCoinName);
1082
- const amount = await query.cache.queryGetCoinBalance({
1082
+ const coinBalance = await query.cache.queryGetCoinBalance({
1083
1083
  owner,
1084
1084
  coinType: coinType,
1085
1085
  });
1086
- return BigNumber(amount).toNumber();
1086
+ return BigNumber(coinBalance?.totalBalance ?? '0').toNumber();
1087
1087
  };
1088
1088
 
1089
1089
  /**
@@ -1136,11 +1136,11 @@ export const getMarketCoinAmount = async (
1136
1136
  ) => {
1137
1137
  const owner = ownerAddress ?? query.suiKit.currentAddress();
1138
1138
  const marketCoinType = query.utils.parseMarketCoinType(marketCoinName);
1139
- const amount = await query.cache.queryGetCoinBalance({
1139
+ const coinBalance = await query.cache.queryGetCoinBalance({
1140
1140
  owner,
1141
1141
  coinType: marketCoinType,
1142
1142
  });
1143
- return BigNumber(amount).toNumber();
1143
+ return BigNumber(coinBalance?.totalBalance ?? '0').toNumber();
1144
1144
  };
1145
1145
 
1146
1146
  /**
@@ -12,6 +12,7 @@ export const getAllAddresses = async (query: ScallopQuery) => {
12
12
  borrowDynamic?: string;
13
13
  spoolReward?: string;
14
14
  spool?: string;
15
+ sCoinType?: string;
15
16
  sCoinTreasury?: string;
16
17
  interestModel?: string;
17
18
  riskModel?: string;
@@ -21,6 +22,7 @@ export const getAllAddresses = async (query: ScallopQuery) => {
21
22
  isolatedAssetKey?: string;
22
23
  coinDecimalId?: string;
23
24
  borrowIncentivePoolId?: string;
25
+ coinType?: string;
24
26
  }
25
27
  >
26
28
  > = {};
@@ -115,6 +117,8 @@ export const getAllAddresses = async (query: ScallopQuery) => {
115
117
  // @ts-ignore
116
118
  `spool.pools.s${coinName}.rewardPoolId`
117
119
  );
120
+ // @ts-ignore
121
+ const sCoinType = query.address.get(`scoin.coins.s${coinName}.coinType`);
118
122
  const sCoinTreasury = query.address.get(
119
123
  // @ts-ignore
120
124
  `scoin.coins.s${coinName}.treasury`
@@ -135,7 +139,9 @@ export const getAllAddresses = async (query: ScallopQuery) => {
135
139
  spool,
136
140
  spoolReward: rewardPool,
137
141
  sCoinTreasury,
142
+ sCoinType,
138
143
  coinDecimalId,
144
+ coinType: `0x${coinType}`,
139
145
  };
140
146
 
141
147
  await new Promise((resolve) => setTimeout(resolve, 200));