@scallop-io/sui-scallop-sdk 0.46.60 → 0.46.62

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.
@@ -367,6 +367,12 @@ export declare class ScallopQuery {
367
367
  * @return Total value locked.
368
368
  */
369
369
  getTvl(indexer?: boolean): Promise<import("../types").TotalValueLocked>;
370
+ /**
371
+ * Get veSca data.
372
+ * @param veScaKey
373
+ * @returns veSca
374
+ */
375
+ getVeSca(veScaKey: string | SuiObjectData): Promise<import("../types").Vesca | undefined>;
370
376
  /**
371
377
  * Get all veSca from walletAdddress
372
378
  * @param walletAddress
@@ -431,4 +437,8 @@ export declare class ScallopQuery {
431
437
  */
432
438
  getSCoinSwapRate(fromSCoin: SupportSCoin, toSCoin: SupportSCoin): Promise<number>;
433
439
  getFlashLoanFees(assetCoinNames?: SupportAssetCoins[]): Promise<Record<"eth" | "btc" | "usdc" | "usdt" | "sui" | "apt" | "sol" | "cetus" | "afsui" | "hasui" | "vsui" | "sca", number>>;
440
+ /**
441
+ * Get supply limit of supply pool
442
+ */
443
+ getPoolSupplyLimit(poolName: SupportPoolCoins): Promise<string | null>;
434
444
  }
@@ -191,7 +191,7 @@ export declare class ScallopUtils {
191
191
  */
192
192
  parseAprToApy(apr: number, compoundFrequency?: number): number;
193
193
  /**
194
- * Convert apr to apy.
194
+ * Convert apy to apr.
195
195
  *
196
196
  * @param apr The equivalent annual percentage yield (APY).
197
197
  * @param compoundFrequency How often interest is compounded per year. Default is daily (365 times a year).
@@ -0,0 +1,9 @@
1
+ import { ScallopUtils } from 'src/models';
2
+ import { SupportPoolCoins } from 'src/types';
3
+ /**
4
+ * Return supply limit of a pool (including the decimals)
5
+ * @param utils
6
+ * @param poolName
7
+ * @returns supply limit (decimals included)
8
+ */
9
+ export declare const getSupplyLimit: (utils: ScallopUtils, poolName: SupportPoolCoins) => Promise<string | null>;
@@ -122,6 +122,7 @@ export type MarketPool = {
122
122
  coinWrappedType: CoinWrappedType;
123
123
  coinDecimal: number;
124
124
  coinPrice: number;
125
+ maxSupplyCoin: number;
125
126
  } & Required<Pick<ParsedMarketPoolData, 'highKink' | 'midKink' | 'reserveFactor' | 'borrowWeight' | 'borrowFee' | 'marketCoinSupplyAmount' | 'minBorrowAmount'>> & CalculatedMarketPoolData;
126
127
  export type MarketCollateral = {
127
128
  coinName: SupportCollateralCoins;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scallop-io/sui-scallop-sdk",
3
- "version": "0.46.60",
3
+ "version": "0.46.62",
4
4
  "description": "Typescript sdk for interacting with Scallop contract on SUI",
5
5
  "keywords": [
6
6
  "sui",
@@ -33,6 +33,7 @@ import {
33
33
  getVeScaTreasuryInfo,
34
34
  getLoyaltyProgramInformations,
35
35
  getFlashLoanFees,
36
+ getVeSca,
36
37
  } from '../queries';
37
38
  import {
38
39
  ScallopQueryParams,
@@ -60,6 +61,7 @@ import {
60
61
  getSCoinTotalSupply,
61
62
  } from 'src/queries/sCoinQuery';
62
63
  import { normalizeSuiAddress } from '@mysten/sui.js/utils';
64
+ import { getSupplyLimit } from 'src/queries/supplyLimit';
63
65
 
64
66
  /**
65
67
  * @description
@@ -563,6 +565,15 @@ export class ScallopQuery {
563
565
  return await getTotalValueLocked(this, indexer);
564
566
  }
565
567
 
568
+ /**
569
+ * Get veSca data.
570
+ * @param veScaKey
571
+ * @returns veSca
572
+ */
573
+ public async getVeSca(veScaKey: string | SuiObjectData) {
574
+ return await getVeSca(this.utils, veScaKey);
575
+ }
576
+
566
577
  /**
567
578
  * Get all veSca from walletAdddress
568
579
  * @param walletAddress
@@ -681,4 +692,11 @@ export class ScallopQuery {
681
692
  ) {
682
693
  return await getFlashLoanFees(this, assetCoinNames);
683
694
  }
695
+
696
+ /**
697
+ * Get supply limit of supply pool
698
+ */
699
+ public async getPoolSupplyLimit(poolName: SupportPoolCoins) {
700
+ return await getSupplyLimit(this.utils, poolName);
701
+ }
684
702
  }
@@ -582,7 +582,7 @@ export class ScallopUtils {
582
582
  }
583
583
 
584
584
  /**
585
- * Convert apr to apy.
585
+ * Convert apy to apr.
586
586
  *
587
587
  * @param apr The equivalent annual percentage yield (APY).
588
588
  * @param compoundFrequency How often interest is compounded per year. Default is daily (365 times a year).
@@ -37,6 +37,7 @@ import {
37
37
  OptionalKeys,
38
38
  } from '../types';
39
39
  import BigNumber from 'bignumber.js';
40
+ import { getSupplyLimit } from './supplyLimit';
40
41
 
41
42
  /**
42
43
  * Query market data.
@@ -124,6 +125,13 @@ export const queryMarket = async (
124
125
  parsedMarketPoolData
125
126
  );
126
127
 
128
+ const coinDecimal = query.utils.getCoinDecimal(poolCoinName);
129
+ const maxSupplyCoin = BigNumber(
130
+ (await getSupplyLimit(query.utils, poolCoinName)) ?? '0'
131
+ )
132
+ .shiftedBy(-coinDecimal)
133
+ .toNumber();
134
+
127
135
  pools[poolCoinName] = {
128
136
  coinName: poolCoinName,
129
137
  symbol: query.utils.parseSymbol(poolCoinName),
@@ -133,7 +141,7 @@ export const queryMarket = async (
133
141
  query.utils.parseMarketCoinName(poolCoinName)
134
142
  ),
135
143
  coinWrappedType: query.utils.getCoinWrappedType(poolCoinName),
136
- coinDecimal: query.utils.getCoinDecimal(poolCoinName),
144
+ coinDecimal,
137
145
  coinPrice: coinPrice,
138
146
  highKink: parsedMarketPoolData.highKink,
139
147
  midKink: parsedMarketPoolData.midKink,
@@ -142,6 +150,7 @@ export const queryMarket = async (
142
150
  borrowFee: parsedMarketPoolData.borrowFee,
143
151
  marketCoinSupplyAmount: parsedMarketPoolData.marketCoinSupplyAmount,
144
152
  minBorrowAmount: parsedMarketPoolData.minBorrowAmount,
153
+ maxSupplyCoin,
145
154
  ...calculatedMarketPoolData,
146
155
  };
147
156
  }
@@ -451,6 +460,13 @@ export const getMarketPool = async (
451
460
  parsedMarketPoolData
452
461
  );
453
462
 
463
+ const coinDecimal = query.utils.getCoinDecimal(poolCoinName);
464
+ const maxSupplyCoin = BigNumber(
465
+ (await getSupplyLimit(query.utils, poolCoinName)) ?? '0'
466
+ )
467
+ .shiftedBy(-coinDecimal)
468
+ .toNumber();
469
+
454
470
  marketPool = {
455
471
  coinName: poolCoinName,
456
472
  symbol: query.utils.parseSymbol(poolCoinName),
@@ -460,7 +476,7 @@ export const getMarketPool = async (
460
476
  query.utils.parseMarketCoinName(poolCoinName)
461
477
  ),
462
478
  coinWrappedType: query.utils.getCoinWrappedType(poolCoinName),
463
- coinDecimal: query.utils.getCoinDecimal(poolCoinName),
479
+ coinDecimal,
464
480
  coinPrice: coinPrice ?? 0,
465
481
  highKink: parsedMarketPoolData.highKink,
466
482
  midKink: parsedMarketPoolData.midKink,
@@ -469,6 +485,7 @@ export const getMarketPool = async (
469
485
  borrowFee: parsedMarketPoolData.borrowFee,
470
486
  marketCoinSupplyAmount: parsedMarketPoolData.marketCoinSupplyAmount,
471
487
  minBorrowAmount: parsedMarketPoolData.minBorrowAmount,
488
+ maxSupplyCoin,
472
489
  ...calculatedMarketPoolData,
473
490
  };
474
491
  }
@@ -0,0 +1,48 @@
1
+ import { ScallopUtils } from 'src/models';
2
+ import { SupportPoolCoins } from 'src/types';
3
+ import { z as zod } from 'zod';
4
+
5
+ const supplyLimitZod = zod.object({
6
+ dataType: zod.string(),
7
+ type: zod.string(),
8
+ hasPublicTransfer: zod.boolean(),
9
+ fields: zod.object({
10
+ id: zod.object({
11
+ id: zod.string(),
12
+ }),
13
+ name: zod.object({
14
+ type: zod.string(),
15
+ }),
16
+ value: zod.string(),
17
+ }),
18
+ });
19
+
20
+ const SUPPLY_LIMIT_TYPE =
21
+ '0x6e641f0dca8aedab3101d047e96439178f16301bf0b57fe8745086ff1195eb3e::market_dynamic_keys::SupplyLimitKey';
22
+
23
+ /**
24
+ * Return supply limit of a pool (including the decimals)
25
+ * @param utils
26
+ * @param poolName
27
+ * @returns supply limit (decimals included)
28
+ */
29
+ export const getSupplyLimit = async (
30
+ utils: ScallopUtils,
31
+ poolName: SupportPoolCoins
32
+ ) => {
33
+ const poolCoinType = utils.parseCoinType(poolName).slice(2);
34
+ const marketObject = utils.address.get('core.market');
35
+ if (!marketObject) return null;
36
+
37
+ const object = await utils.cache.queryGetDynamicFieldObject({
38
+ parentId: marketObject,
39
+ name: {
40
+ type: SUPPLY_LIMIT_TYPE,
41
+ value: poolCoinType,
42
+ },
43
+ });
44
+
45
+ const parsedData = supplyLimitZod.safeParse(object?.data?.content);
46
+ if (!parsedData.success) return null;
47
+ return parsedData.data.fields.value;
48
+ };
@@ -129,6 +129,7 @@ export type MarketPool = {
129
129
  coinWrappedType: CoinWrappedType;
130
130
  coinDecimal: number;
131
131
  coinPrice: number;
132
+ maxSupplyCoin: number;
132
133
  } & Required<
133
134
  Pick<
134
135
  ParsedMarketPoolData,