@scallop-io/sui-scallop-sdk 1.4.13 → 1.4.14-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.
- package/dist/constants/tokenBucket.d.ts +1 -1
- package/dist/index.js +47 -32
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +47 -32
- package/dist/index.mjs.map +1 -1
- package/dist/models/scallopCache.d.ts +1 -0
- package/dist/models/scallopUtils.d.ts +4 -2
- package/dist/utils/query.d.ts +1 -1
- package/package.json +1 -1
- package/src/constants/enum.ts +14 -6
- package/src/constants/tokenBucket.ts +1 -1
- package/src/models/scallopCache.ts +12 -7
- package/src/models/scallopUtils.ts +10 -3
- package/src/queries/borrowIncentiveQuery.ts +5 -7
- package/src/queries/borrowLimitQuery.ts +2 -2
- package/src/queries/isolatedAssetQuery.ts +2 -2
- package/src/queries/portfolioQuery.ts +6 -1
- package/src/queries/supplyLimitQuery.ts +2 -2
- package/src/utils/query.ts +5 -7
- package/src/utils/tokenBucket.ts +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export declare const DEFAULT_TOKENS_PER_INTERVAL = 10;
|
|
2
|
-
export declare const DEFAULT_INTERVAL_IN_MS =
|
|
2
|
+
export declare const DEFAULT_INTERVAL_IN_MS = 250;
|
package/dist/index.js
CHANGED
|
@@ -371,12 +371,19 @@ var voloCoinIds = {
|
|
|
371
371
|
vsui: "0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55"
|
|
372
372
|
};
|
|
373
373
|
var sCoinIds = {
|
|
374
|
+
// prod values
|
|
375
|
+
// ssui: '0xaafc4f740de0dd0dde642a31148fb94517087052f19afb0f7bed1dc41a50c77b::scallop_sui::SCALLOP_SUI',
|
|
376
|
+
// swusdc:
|
|
377
|
+
// '0xad4d71551d31092230db1fd482008ea42867dbf27b286e9c70a79d2a6191d58d::scallop_wormhole_usdc::SCALLOP_WORMHOLE_USDC',
|
|
378
|
+
// swusdt:
|
|
379
|
+
// '0xe6e5a012ec20a49a3d1d57bd2b67140b96cd4d3400b9d79e541f7bdbab661f95::scallop_wormhole_usdt::SCALLOP_WORMHOLE_USDT',
|
|
380
|
+
// ssca: '0x5ca17430c1d046fae9edeaa8fd76c7b4193a00d764a0ecfa9418d733ad27bc1e::scallop_sca::SCALLOP_SCA',
|
|
381
|
+
ssui: "0xf569919046f19a0c40b519ecfbb6ca0319698cd5908716c29b62ef56541f298b::scallop_sui::SCALLOP_SUI",
|
|
382
|
+
swusdt: "0xac781d9f73058ff5e69f9bf8dde32f2e8c71c66d7fe8497fc83b2d9182254b22::scallop_wormhole_usdt::SCALLOP_WORMHOLE_USDT",
|
|
383
|
+
swusdc: "0xf5447c4305a486d8c8557559887c2c39449ddb5e748f15d33946d02a1663c158::scallop_wormhole_usdc::SCALLOP_WORMHOLE_USDC",
|
|
384
|
+
ssca: "0x958428555e778e55918a59eb1c92c77f32b5c554fa3a5e56cd0815086b5072e7::scallop_sca::SCALLOP_SCA",
|
|
374
385
|
susdc: "0x854950aa624b1df59fe64e630b2ba7c550642e9342267a33061d59fb31582da5::scallop_usdc::SCALLOP_USDC",
|
|
375
386
|
ssbeth: "0xb14f82d8506d139eacef109688d1b71e7236bcce9b2c0ad526abcd6aa5be7de0::scallop_sb_eth::SCALLOP_SB_ETH",
|
|
376
|
-
ssui: "0xaafc4f740de0dd0dde642a31148fb94517087052f19afb0f7bed1dc41a50c77b::scallop_sui::SCALLOP_SUI",
|
|
377
|
-
swusdc: "0xad4d71551d31092230db1fd482008ea42867dbf27b286e9c70a79d2a6191d58d::scallop_wormhole_usdc::SCALLOP_WORMHOLE_USDC",
|
|
378
|
-
swusdt: "0xe6e5a012ec20a49a3d1d57bd2b67140b96cd4d3400b9d79e541f7bdbab661f95::scallop_wormhole_usdt::SCALLOP_WORMHOLE_USDT",
|
|
379
|
-
ssca: "0x5ca17430c1d046fae9edeaa8fd76c7b4193a00d764a0ecfa9418d733ad27bc1e::scallop_sca::SCALLOP_SCA",
|
|
380
387
|
scetus: "0xea346ce428f91ab007210443efcea5f5cdbbb3aae7e9affc0ca93f9203c31f0c::scallop_cetus::SCALLOP_CETUS",
|
|
381
388
|
sweth: "0x67540ceb850d418679e69f1fb6b2093d6df78a2a699ffc733f7646096d552e9b::scallop_wormhole_eth::SCALLOP_WORMHOLE_ETH",
|
|
382
389
|
safsui: "0x00671b1fa2a124f5be8bdae8b91ee711462c5d9e31bda232e70fd9607b523c88::scallop_af_sui::SCALLOP_AF_SUI",
|
|
@@ -1065,7 +1072,7 @@ var TEST_ADDRESSES = {
|
|
|
1065
1072
|
|
|
1066
1073
|
// src/constants/tokenBucket.ts
|
|
1067
1074
|
var DEFAULT_TOKENS_PER_INTERVAL = 10;
|
|
1068
|
-
var DEFAULT_INTERVAL_IN_MS =
|
|
1075
|
+
var DEFAULT_INTERVAL_IN_MS = 250;
|
|
1069
1076
|
|
|
1070
1077
|
// src/constants/vesca.ts
|
|
1071
1078
|
var UNLOCK_ROUND_DURATION = 60 * 60 * 24;
|
|
@@ -1441,7 +1448,7 @@ var parseOriginBorrowIncentivesPoolPointData = (originBorrowIncentivePoolPointDa
|
|
|
1441
1448
|
createdAt: Number(originBorrowIncentivePoolPointData.created_at)
|
|
1442
1449
|
};
|
|
1443
1450
|
};
|
|
1444
|
-
var parseOriginBorrowIncentivePoolData = (originBorrowIncentivePoolData) => {
|
|
1451
|
+
var parseOriginBorrowIncentivePoolData = (utils, originBorrowIncentivePoolData) => {
|
|
1445
1452
|
return {
|
|
1446
1453
|
poolType: (0, import_utils.normalizeStructTag)(originBorrowIncentivePoolData.pool_type.name),
|
|
1447
1454
|
minStakes: Number(originBorrowIncentivePoolData.min_stakes),
|
|
@@ -1450,12 +1457,9 @@ var parseOriginBorrowIncentivePoolData = (originBorrowIncentivePoolData) => {
|
|
|
1450
1457
|
poolPoints: originBorrowIncentivePoolData.points.reduce(
|
|
1451
1458
|
(acc, point) => {
|
|
1452
1459
|
const parsed = parseOriginBorrowIncentivesPoolPointData(point);
|
|
1453
|
-
|
|
1454
|
-
parsed.pointType
|
|
1455
|
-
)
|
|
1456
|
-
if (sCoinRawNameToName[name]) {
|
|
1457
|
-
name = sCoinRawNameToName[name];
|
|
1458
|
-
}
|
|
1460
|
+
const name = utils.parseSCoinTypeNameToMarketCoinName(
|
|
1461
|
+
(0, import_utils.parseStructTag)(parsed.pointType).name.toLowerCase()
|
|
1462
|
+
);
|
|
1459
1463
|
acc[name] = parsed;
|
|
1460
1464
|
return acc;
|
|
1461
1465
|
},
|
|
@@ -1669,7 +1673,7 @@ var TokenBucket = class {
|
|
|
1669
1673
|
return false;
|
|
1670
1674
|
}
|
|
1671
1675
|
};
|
|
1672
|
-
var callWithRateLimit = async (tokenBucket, fn, retryDelayInMs = DEFAULT_INTERVAL_IN_MS, maxRetries = 15, backoffFactor =
|
|
1676
|
+
var callWithRateLimit = async (tokenBucket, fn, retryDelayInMs = DEFAULT_INTERVAL_IN_MS, maxRetries = 15, backoffFactor = 1.25) => {
|
|
1673
1677
|
let retries = 0;
|
|
1674
1678
|
const tryRequest = async () => {
|
|
1675
1679
|
if (tokenBucket.removeTokens(1)) {
|
|
@@ -1748,6 +1752,13 @@ var ScallopCache = class {
|
|
|
1748
1752
|
})
|
|
1749
1753
|
);
|
|
1750
1754
|
}
|
|
1755
|
+
retryFn(errCount, err) {
|
|
1756
|
+
if (err.status === 429)
|
|
1757
|
+
return true;
|
|
1758
|
+
if (errCount >= 5)
|
|
1759
|
+
return false;
|
|
1760
|
+
return false;
|
|
1761
|
+
}
|
|
1751
1762
|
/**
|
|
1752
1763
|
* @description Provides cache for inspectTxn of the SuiKit.
|
|
1753
1764
|
* @param QueryInspectTxnParams
|
|
@@ -1762,7 +1773,7 @@ var ScallopCache = class {
|
|
|
1762
1773
|
const txBlock = new import_sui_kit.SuiTxBlock();
|
|
1763
1774
|
txBlock.moveCall(queryTarget, args, typeArgs);
|
|
1764
1775
|
const query = await this.queryClient.fetchQuery({
|
|
1765
|
-
retry:
|
|
1776
|
+
retry: this.retryFn,
|
|
1766
1777
|
retryDelay: 1e3,
|
|
1767
1778
|
queryKey: queryKeys.rpc.getInspectTxn(queryTarget, args, typeArgs),
|
|
1768
1779
|
queryFn: async () => {
|
|
@@ -1782,7 +1793,7 @@ var ScallopCache = class {
|
|
|
1782
1793
|
*/
|
|
1783
1794
|
async queryGetObject(objectId, options) {
|
|
1784
1795
|
return this.queryClient.fetchQuery({
|
|
1785
|
-
retry:
|
|
1796
|
+
retry: this.retryFn,
|
|
1786
1797
|
retryDelay: 1e3,
|
|
1787
1798
|
queryKey: queryKeys.rpc.getObject(objectId, this.walletAddress, options),
|
|
1788
1799
|
queryFn: async () => {
|
|
@@ -1807,7 +1818,7 @@ var ScallopCache = class {
|
|
|
1807
1818
|
if (objectIds.length === 0)
|
|
1808
1819
|
return [];
|
|
1809
1820
|
return this.queryClient.fetchQuery({
|
|
1810
|
-
retry:
|
|
1821
|
+
retry: this.retryFn,
|
|
1811
1822
|
retryDelay: 1e3,
|
|
1812
1823
|
queryKey: queryKeys.rpc.getObjects(
|
|
1813
1824
|
objectIds,
|
|
@@ -1829,7 +1840,7 @@ var ScallopCache = class {
|
|
|
1829
1840
|
*/
|
|
1830
1841
|
async queryGetOwnedObjects(input) {
|
|
1831
1842
|
return this.queryClient.fetchQuery({
|
|
1832
|
-
retry:
|
|
1843
|
+
retry: this.retryFn,
|
|
1833
1844
|
retryDelay: 1e3,
|
|
1834
1845
|
queryKey: queryKeys.rpc.getOwnedObjects(input),
|
|
1835
1846
|
queryFn: async () => {
|
|
@@ -1842,7 +1853,7 @@ var ScallopCache = class {
|
|
|
1842
1853
|
}
|
|
1843
1854
|
async queryGetDynamicFields(input) {
|
|
1844
1855
|
return this.queryClient.fetchQuery({
|
|
1845
|
-
retry:
|
|
1856
|
+
retry: this.retryFn,
|
|
1846
1857
|
retryDelay: 1e3,
|
|
1847
1858
|
queryKey: queryKeys.rpc.getDynamicFields(input),
|
|
1848
1859
|
queryFn: async () => {
|
|
@@ -1855,7 +1866,7 @@ var ScallopCache = class {
|
|
|
1855
1866
|
}
|
|
1856
1867
|
async queryGetDynamicFieldObject(input) {
|
|
1857
1868
|
return this.queryClient.fetchQuery({
|
|
1858
|
-
retry:
|
|
1869
|
+
retry: this.retryFn,
|
|
1859
1870
|
retryDelay: (attemptIndex) => Math.min(1e3 * attemptIndex, 8e3),
|
|
1860
1871
|
queryKey: queryKeys.rpc.getDynamicFieldObject(input),
|
|
1861
1872
|
queryFn: async () => {
|
|
@@ -1868,7 +1879,7 @@ var ScallopCache = class {
|
|
|
1868
1879
|
}
|
|
1869
1880
|
async queryGetAllCoinBalances(owner) {
|
|
1870
1881
|
return this.queryClient.fetchQuery({
|
|
1871
|
-
retry:
|
|
1882
|
+
retry: this.retryFn,
|
|
1872
1883
|
retryDelay: 1e3,
|
|
1873
1884
|
queryKey: queryKeys.rpc.getAllCoinBalances(owner),
|
|
1874
1885
|
queryFn: async () => {
|
|
@@ -2612,7 +2623,10 @@ var getBorrowIncentivePools = async (query, borrowIncentiveCoinNames = [
|
|
|
2612
2623
|
);
|
|
2613
2624
|
for (const pool of borrowIncentivePoolsQueryData?.incentive_pools ?? []) {
|
|
2614
2625
|
const borrowIncentivePoolPoints = {};
|
|
2615
|
-
const parsedBorrowIncentivePoolData = parseOriginBorrowIncentivePoolData(
|
|
2626
|
+
const parsedBorrowIncentivePoolData = parseOriginBorrowIncentivePoolData(
|
|
2627
|
+
query.utils,
|
|
2628
|
+
pool
|
|
2629
|
+
);
|
|
2616
2630
|
const poolCoinType = (0, import_utils3.normalizeStructTag)(pool.pool_type.name);
|
|
2617
2631
|
const poolCoinName = query.utils.parseCoinNameFromType(
|
|
2618
2632
|
poolCoinType
|
|
@@ -2626,12 +2640,9 @@ var getBorrowIncentivePools = async (query, borrowIncentiveCoinNames = [
|
|
|
2626
2640
|
parsedBorrowIncentivePoolData.poolPoints
|
|
2627
2641
|
)) {
|
|
2628
2642
|
const rewardCoinType = poolPoint.pointType;
|
|
2629
|
-
|
|
2643
|
+
const rewardCoinName = query.utils.parseCoinNameFromType(
|
|
2630
2644
|
rewardCoinType
|
|
2631
2645
|
);
|
|
2632
|
-
if (sCoinRawNameToName[rewardCoinName]) {
|
|
2633
|
-
rewardCoinName = sCoinRawNameToName[rewardCoinName];
|
|
2634
|
-
}
|
|
2635
2646
|
const rewardCoinDecimal = query.utils.getCoinDecimal(rewardCoinName);
|
|
2636
2647
|
const rewardCoinPrice = coinPrices?.[rewardCoinName] ?? 0;
|
|
2637
2648
|
const symbol = query.utils.parseSymbol(rewardCoinName);
|
|
@@ -2779,7 +2790,7 @@ var supplyLimitZod = import_zod.z.object({
|
|
|
2779
2790
|
value: import_zod.z.string()
|
|
2780
2791
|
})
|
|
2781
2792
|
});
|
|
2782
|
-
var supplyLimitKeyType = `
|
|
2793
|
+
var supplyLimitKeyType = `0x6c23585e940a989588432509107e98bae06dbca4e333f26d0635d401b3c7c76d::market_dynamic_keys::SupplyLimitKey`;
|
|
2783
2794
|
var getSupplyLimit = async (utils, poolName) => {
|
|
2784
2795
|
try {
|
|
2785
2796
|
const poolCoinType = utils.parseCoinType(poolName).slice(2);
|
|
@@ -2819,7 +2830,7 @@ var isolatedAssetZod = import_zod2.z.object({
|
|
|
2819
2830
|
value: import_zod2.z.boolean()
|
|
2820
2831
|
})
|
|
2821
2832
|
});
|
|
2822
|
-
var isolatedAssetKeyType = `
|
|
2833
|
+
var isolatedAssetKeyType = `0x6c23585e940a989588432509107e98bae06dbca4e333f26d0635d401b3c7c76d::market_dynamic_keys::IsolatedAssetKey`;
|
|
2823
2834
|
var getIsolatedAssets = async (address) => {
|
|
2824
2835
|
try {
|
|
2825
2836
|
const marketObject = address.get("core.market");
|
|
@@ -2899,7 +2910,7 @@ var borrowLimitZod = import_zod3.z.object({
|
|
|
2899
2910
|
value: import_zod3.z.string()
|
|
2900
2911
|
})
|
|
2901
2912
|
});
|
|
2902
|
-
var borrowLimitKeyType = `
|
|
2913
|
+
var borrowLimitKeyType = `0xb784ea287d944e478a3ceaa071f8885072cce6b7224cf245914dc2f9963f460e::market_dynamic_keys::BorrowLimitKey`;
|
|
2903
2914
|
var getBorrowLimit = async (utils, poolName) => {
|
|
2904
2915
|
try {
|
|
2905
2916
|
const poolCoinType = utils.parseCoinType(poolName).slice(2);
|
|
@@ -3941,7 +3952,7 @@ var getObligationAccount = async (query, obligationId, ownerAddress, indexer = f
|
|
|
3941
3952
|
const rewards = [];
|
|
3942
3953
|
Object.entries(borrowIncentiveAccount.pointList).forEach(
|
|
3943
3954
|
([key, accountPoint]) => {
|
|
3944
|
-
const poolPoint = borrowIncentivePool.points[key];
|
|
3955
|
+
const poolPoint = borrowIncentivePool.points[query.utils.parseSCoinTypeNameToMarketCoinName(key)];
|
|
3945
3956
|
if (accountPoint && poolPoint) {
|
|
3946
3957
|
let availableClaimAmount = (0, import_bignumber5.default)(0);
|
|
3947
3958
|
let availableClaimCoin = (0, import_bignumber5.default)(0);
|
|
@@ -4973,13 +4984,14 @@ var ScallopUtils = class {
|
|
|
4973
4984
|
}
|
|
4974
4985
|
}
|
|
4975
4986
|
/**
|
|
4976
|
-
* Convert sCoin name to coin name.
|
|
4987
|
+
* Convert sCoin name to market coin name.
|
|
4977
4988
|
* This function will parse new sCoin name `scallop_...` to its old market coin name which is shorter
|
|
4978
4989
|
* e.g: `scallop_sui -> ssui
|
|
4990
|
+
* if no `scallop_...` is encountered, return coinName
|
|
4979
4991
|
* @return sCoin name
|
|
4980
4992
|
*/
|
|
4981
|
-
|
|
4982
|
-
return sCoinRawNameToName[coinName];
|
|
4993
|
+
parseSCoinTypeNameToMarketCoinName(coinName) {
|
|
4994
|
+
return sCoinRawNameToName[coinName] ?? coinName;
|
|
4983
4995
|
}
|
|
4984
4996
|
/**
|
|
4985
4997
|
* Convert sCoin name into sCoin type
|
|
@@ -5028,6 +5040,9 @@ var ScallopUtils = class {
|
|
|
5028
5040
|
}
|
|
5029
5041
|
parseCoinNameFromType(coinType) {
|
|
5030
5042
|
coinType = (0, import_utils10.normalizeStructTag)(coinType);
|
|
5043
|
+
if (sCoinTypeToName[coinType]) {
|
|
5044
|
+
return sCoinTypeToName[coinType];
|
|
5045
|
+
}
|
|
5031
5046
|
const coinTypeRegex = new RegExp(`((0x[^:]+::[^:]+::[^<>]+))(?![^<>]*<)`);
|
|
5032
5047
|
const coinTypeMatch = coinType.match(coinTypeRegex);
|
|
5033
5048
|
const isMarketCoinType = coinType.includes("reserve::MarketCoin");
|