@scallop-io/sui-scallop-sdk 1.4.1 → 1.4.12
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 +2 -2
- package/dist/index.js +72 -31
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +72 -31
- package/dist/index.mjs.map +1 -1
- package/dist/models/scallopQuery.d.ts +1 -1
- package/package.json +1 -1
- package/src/constants/testAddress.ts +42 -0
- package/src/constants/tokenBucket.ts +2 -2
- package/src/models/scallopCache.ts +36 -15
- package/src/models/scallopQuery.ts +1 -1
- package/src/models/scallopUtils.ts +1 -1
- package/src/queries/borrowLimitQuery.ts +1 -0
- package/src/queries/portfolioQuery.ts +9 -4
- package/src/utils/query.ts +5 -1
- package/src/utils/tokenBucket.ts +8 -28
package/dist/index.mjs
CHANGED
|
@@ -724,6 +724,32 @@ var TEST_ADDRESSES = {
|
|
|
724
724
|
feedObject: "0x9193fd47f9a0ab99b6e365a464c8a9ae30e6150fc37ed2a89c1586631f6fc4ab"
|
|
725
725
|
}
|
|
726
726
|
}
|
|
727
|
+
},
|
|
728
|
+
deep: {
|
|
729
|
+
id: "0xdeeb7a4662eec9f2f3def03fb937a663dddaa2e215b8078a284d026b7946c270",
|
|
730
|
+
metaData: "0x6e60b051a08fa836f5a7acd7c464c8d9825bc29c44657fe170fe9b8e1e4770c0",
|
|
731
|
+
treasury: "",
|
|
732
|
+
oracle: {
|
|
733
|
+
supra: "",
|
|
734
|
+
switchboard: "",
|
|
735
|
+
pyth: {
|
|
736
|
+
feed: "29bdd5248234e33bd93d3b81100b5fa32eaa5997843847e2c2cb16d7c6d9f7ff",
|
|
737
|
+
feedObject: "0x8c7f3a322b94cc69db2a2ac575cbd94bf5766113324c3a3eceac91e3e88a51ed"
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
},
|
|
741
|
+
fud: {
|
|
742
|
+
id: "0x76cb819b01abed502bee8a702b4c2d547532c12f25001c9dea795a5e631c26f1",
|
|
743
|
+
metaData: "0x01087411ef48aaac1eb6e24803213e3a60a03b147dac930e5e341f17a85e524e",
|
|
744
|
+
treasury: "",
|
|
745
|
+
oracle: {
|
|
746
|
+
supra: "",
|
|
747
|
+
switchboard: "",
|
|
748
|
+
pyth: {
|
|
749
|
+
feed: "6a4090703da959247727f2b490eb21aea95c8684ecfac675f432008830890c75",
|
|
750
|
+
feedObject: "0x4531c3ed0d22f21f5fce882905372006c9aafa30f01db03b789e95a6c50de7b2"
|
|
751
|
+
}
|
|
752
|
+
}
|
|
727
753
|
}
|
|
728
754
|
},
|
|
729
755
|
oracles: {
|
|
@@ -943,14 +969,22 @@ var TEST_ADDRESSES = {
|
|
|
943
969
|
ssbeth: {
|
|
944
970
|
coinType: "0xb14f82d8506d139eacef109688d1b71e7236bcce9b2c0ad526abcd6aa5be7de0::scallop_sb_eth::SCALLOP_SB_ETH",
|
|
945
971
|
treasury: "0xfd0f02def6358a1f266acfa1493d4707ee8387460d434fb667d63d755ff907ed"
|
|
972
|
+
},
|
|
973
|
+
sdeep: {
|
|
974
|
+
coinType: "0xeb7a05a3224837c5e5503575aed0be73c091d1ce5e43aa3c3e716e0ae614608f::scallop_deep::SCALLOP_DEEP",
|
|
975
|
+
treasury: "0xc63838fabe37b25ad897392d89876d920f5e0c6a406bf3abcb84753d2829bc88"
|
|
976
|
+
},
|
|
977
|
+
sfud: {
|
|
978
|
+
coinType: "0xe56d5167f427cbe597da9e8150ef5c337839aaf46891d62468dcf80bdd8e10d1::scallop_fud::SCALLOP_FUD",
|
|
979
|
+
treasury: "0xf25212f11d182decff7a86165699a73e3d5787aced203ca539f43cfbc10db867"
|
|
946
980
|
}
|
|
947
981
|
}
|
|
948
982
|
}
|
|
949
983
|
};
|
|
950
984
|
|
|
951
985
|
// src/constants/tokenBucket.ts
|
|
952
|
-
var DEFAULT_TOKENS_PER_INTERVAL =
|
|
953
|
-
var DEFAULT_INTERVAL_IN_MS =
|
|
986
|
+
var DEFAULT_TOKENS_PER_INTERVAL = 10;
|
|
987
|
+
var DEFAULT_INTERVAL_IN_MS = 50;
|
|
954
988
|
|
|
955
989
|
// src/constants/vesca.ts
|
|
956
990
|
var UNLOCK_ROUND_DURATION = 60 * 60 * 24;
|
|
@@ -1338,9 +1372,12 @@ var parseOriginBorrowIncentivePoolData = (originBorrowIncentivePoolData) => {
|
|
|
1338
1372
|
poolPoints: originBorrowIncentivePoolData.points.reduce(
|
|
1339
1373
|
(acc, point) => {
|
|
1340
1374
|
const parsed = parseOriginBorrowIncentivesPoolPointData(point);
|
|
1341
|
-
|
|
1375
|
+
let name = parseStructTag(
|
|
1342
1376
|
parsed.pointType
|
|
1343
1377
|
).name.toLowerCase();
|
|
1378
|
+
if (sCoinRawNameToName[name]) {
|
|
1379
|
+
name = sCoinRawNameToName[name];
|
|
1380
|
+
}
|
|
1344
1381
|
acc[name] = parsed;
|
|
1345
1382
|
return acc;
|
|
1346
1383
|
},
|
|
@@ -1539,10 +1576,10 @@ var TokenBucket = class {
|
|
|
1539
1576
|
refill() {
|
|
1540
1577
|
const now = Date.now();
|
|
1541
1578
|
const elapsed = now - this.lastRefill;
|
|
1542
|
-
if (elapsed
|
|
1579
|
+
if (elapsed >= this.interval) {
|
|
1543
1580
|
const tokensToAdd = Math.floor(elapsed / this.interval) * this.tokensPerInterval;
|
|
1544
1581
|
this.tokens = Math.min(this.tokens + tokensToAdd, this.tokensPerInterval);
|
|
1545
|
-
this.lastRefill
|
|
1582
|
+
this.lastRefill += Math.floor(elapsed / this.interval) * this.interval;
|
|
1546
1583
|
}
|
|
1547
1584
|
}
|
|
1548
1585
|
removeTokens(count) {
|
|
@@ -1558,26 +1595,12 @@ var callWithRateLimit = async (tokenBucket, fn, retryDelayInMs = DEFAULT_INTERVA
|
|
|
1558
1595
|
let retries = 0;
|
|
1559
1596
|
const tryRequest = async () => {
|
|
1560
1597
|
if (tokenBucket.removeTokens(1)) {
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
if (result && result.status === 429) {
|
|
1564
|
-
throw new Error("Unexpected status code: 429");
|
|
1565
|
-
}
|
|
1566
|
-
return result;
|
|
1567
|
-
} catch (error) {
|
|
1568
|
-
if (error.message === "Unexpected status code: 429" && retries < maxRetries) {
|
|
1569
|
-
retries++;
|
|
1570
|
-
const delay = retryDelayInMs * Math.pow(backoffFactor, retries);
|
|
1571
|
-
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
1572
|
-
return tryRequest();
|
|
1573
|
-
} else {
|
|
1574
|
-
console.error("An error occurred:", error.message);
|
|
1575
|
-
return null;
|
|
1576
|
-
}
|
|
1577
|
-
}
|
|
1598
|
+
const result = await fn();
|
|
1599
|
+
return result;
|
|
1578
1600
|
} else if (retries < maxRetries) {
|
|
1579
1601
|
retries++;
|
|
1580
1602
|
const delay = retryDelayInMs * Math.pow(backoffFactor, retries);
|
|
1603
|
+
console.error(`Rate limit exceeded, retrying in ${delay} ms`);
|
|
1581
1604
|
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
1582
1605
|
return tryRequest();
|
|
1583
1606
|
} else {
|
|
@@ -1661,11 +1684,13 @@ var ScallopCache = class {
|
|
|
1661
1684
|
const txBlock = new SuiTxBlock();
|
|
1662
1685
|
txBlock.moveCall(queryTarget, args, typeArgs);
|
|
1663
1686
|
const query = await this.queryClient.fetchQuery({
|
|
1687
|
+
retry: 5,
|
|
1688
|
+
retryDelay: 1e3,
|
|
1664
1689
|
queryKey: queryKeys.rpc.getInspectTxn(queryTarget, args, typeArgs),
|
|
1665
1690
|
queryFn: async () => {
|
|
1666
1691
|
return await callWithRateLimit(
|
|
1667
1692
|
this.tokenBucket,
|
|
1668
|
-
() => this.suiKit.inspectTxn(txBlock)
|
|
1693
|
+
async () => await this.suiKit.inspectTxn(txBlock)
|
|
1669
1694
|
);
|
|
1670
1695
|
}
|
|
1671
1696
|
});
|
|
@@ -1679,11 +1704,13 @@ var ScallopCache = class {
|
|
|
1679
1704
|
*/
|
|
1680
1705
|
async queryGetObject(objectId, options) {
|
|
1681
1706
|
return this.queryClient.fetchQuery({
|
|
1707
|
+
retry: 5,
|
|
1708
|
+
retryDelay: 1e3,
|
|
1682
1709
|
queryKey: queryKeys.rpc.getObject(objectId, this.walletAddress, options),
|
|
1683
1710
|
queryFn: async () => {
|
|
1684
1711
|
return await callWithRateLimit(
|
|
1685
1712
|
this.tokenBucket,
|
|
1686
|
-
() => this.client.getObject({
|
|
1713
|
+
async () => await this.client.getObject({
|
|
1687
1714
|
id: objectId,
|
|
1688
1715
|
options
|
|
1689
1716
|
})
|
|
@@ -1702,6 +1729,8 @@ var ScallopCache = class {
|
|
|
1702
1729
|
if (objectIds.length === 0)
|
|
1703
1730
|
return [];
|
|
1704
1731
|
return this.queryClient.fetchQuery({
|
|
1732
|
+
retry: 5,
|
|
1733
|
+
retryDelay: 1e3,
|
|
1705
1734
|
queryKey: queryKeys.rpc.getObjects(
|
|
1706
1735
|
objectIds,
|
|
1707
1736
|
this.walletAddress,
|
|
@@ -1710,7 +1739,7 @@ var ScallopCache = class {
|
|
|
1710
1739
|
queryFn: async () => {
|
|
1711
1740
|
return await callWithRateLimit(
|
|
1712
1741
|
this.tokenBucket,
|
|
1713
|
-
() => this.suiKit.getObjects(objectIds, options)
|
|
1742
|
+
async () => await this.suiKit.getObjects(objectIds, options)
|
|
1714
1743
|
);
|
|
1715
1744
|
}
|
|
1716
1745
|
});
|
|
@@ -1722,28 +1751,34 @@ var ScallopCache = class {
|
|
|
1722
1751
|
*/
|
|
1723
1752
|
async queryGetOwnedObjects(input) {
|
|
1724
1753
|
return this.queryClient.fetchQuery({
|
|
1754
|
+
retry: 5,
|
|
1755
|
+
retryDelay: 1e3,
|
|
1725
1756
|
queryKey: queryKeys.rpc.getOwnedObjects(input),
|
|
1726
1757
|
queryFn: async () => {
|
|
1727
1758
|
return await callWithRateLimit(
|
|
1728
1759
|
this.tokenBucket,
|
|
1729
|
-
() => this.client.getOwnedObjects(input)
|
|
1760
|
+
async () => await this.client.getOwnedObjects(input)
|
|
1730
1761
|
);
|
|
1731
1762
|
}
|
|
1732
1763
|
});
|
|
1733
1764
|
}
|
|
1734
1765
|
async queryGetDynamicFields(input) {
|
|
1735
1766
|
return this.queryClient.fetchQuery({
|
|
1767
|
+
retry: 5,
|
|
1768
|
+
retryDelay: 1e3,
|
|
1736
1769
|
queryKey: queryKeys.rpc.getDynamicFields(input),
|
|
1737
1770
|
queryFn: async () => {
|
|
1738
1771
|
return await callWithRateLimit(
|
|
1739
1772
|
this.tokenBucket,
|
|
1740
|
-
() => this.client.getDynamicFields(input)
|
|
1773
|
+
async () => await this.client.getDynamicFields(input)
|
|
1741
1774
|
);
|
|
1742
1775
|
}
|
|
1743
1776
|
});
|
|
1744
1777
|
}
|
|
1745
1778
|
async queryGetDynamicFieldObject(input) {
|
|
1746
1779
|
return this.queryClient.fetchQuery({
|
|
1780
|
+
retry: 5,
|
|
1781
|
+
retryDelay: (attemptIndex) => Math.min(1e3 * attemptIndex, 8e3),
|
|
1747
1782
|
queryKey: queryKeys.rpc.getDynamicFieldObject(input),
|
|
1748
1783
|
queryFn: async () => {
|
|
1749
1784
|
return await callWithRateLimit(
|
|
@@ -1755,11 +1790,13 @@ var ScallopCache = class {
|
|
|
1755
1790
|
}
|
|
1756
1791
|
async queryGetAllCoinBalances(owner) {
|
|
1757
1792
|
return this.queryClient.fetchQuery({
|
|
1793
|
+
retry: 5,
|
|
1794
|
+
retryDelay: 1e3,
|
|
1758
1795
|
queryKey: queryKeys.rpc.getAllCoinBalances(owner),
|
|
1759
1796
|
queryFn: async () => {
|
|
1760
1797
|
const allBalances = await callWithRateLimit(
|
|
1761
1798
|
this.tokenBucket,
|
|
1762
|
-
() => this.client.getAllBalances({ owner })
|
|
1799
|
+
async () => await this.client.getAllBalances({ owner })
|
|
1763
1800
|
);
|
|
1764
1801
|
if (!allBalances)
|
|
1765
1802
|
return {};
|
|
@@ -3674,17 +3711,21 @@ var getObligationAccounts = async (query, ownerAddress, indexer = false) => {
|
|
|
3674
3711
|
return obligationAccounts;
|
|
3675
3712
|
};
|
|
3676
3713
|
var getObligationAccount = async (query, obligationId, ownerAddress, indexer = false, market, coinPrices, coinAmounts) => {
|
|
3714
|
+
const coinNames = Array.from(
|
|
3715
|
+
/* @__PURE__ */ new Set([...SUPPORT_POOLS, ...SUPPORT_COLLATERALS])
|
|
3716
|
+
);
|
|
3677
3717
|
const collateralAssetCoinNames = [
|
|
3678
3718
|
...SUPPORT_COLLATERALS
|
|
3679
3719
|
];
|
|
3680
3720
|
market = market ?? await query.queryMarket({ indexer });
|
|
3681
3721
|
coinPrices = coinPrices ?? await query.getAllCoinPrices({ marketPools: market.pools });
|
|
3682
|
-
coinAmounts = coinAmounts || await query.getCoinAmounts(
|
|
3722
|
+
coinAmounts = coinAmounts || await query.getCoinAmounts(coinNames, ownerAddress);
|
|
3683
3723
|
const [obligationQuery, borrowIncentivePools, borrowIncentiveAccounts] = await Promise.all([
|
|
3684
3724
|
query.queryObligation(obligationId),
|
|
3685
3725
|
query.getBorrowIncentivePools(void 0, {
|
|
3686
3726
|
coinPrices,
|
|
3687
|
-
indexer
|
|
3727
|
+
indexer,
|
|
3728
|
+
marketPools: market.pools
|
|
3688
3729
|
}),
|
|
3689
3730
|
query.getBorrowIncentiveAccounts(obligationId)
|
|
3690
3731
|
]);
|
|
@@ -5078,7 +5119,7 @@ var ScallopUtils = class {
|
|
|
5078
5119
|
);
|
|
5079
5120
|
const priceIds = priceIdPairs.map(([_2, priceId]) => priceId);
|
|
5080
5121
|
const pythConnection = new SuiPriceServiceConnection(endpoint, {
|
|
5081
|
-
timeout:
|
|
5122
|
+
timeout: 4e3
|
|
5082
5123
|
});
|
|
5083
5124
|
try {
|
|
5084
5125
|
const feeds = await this.cache.queryClient.fetchQuery({
|