@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
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const DEFAULT_TOKENS_PER_INTERVAL =
|
|
2
|
-
export declare const DEFAULT_INTERVAL_IN_MS =
|
|
1
|
+
export declare const DEFAULT_TOKENS_PER_INTERVAL = 10;
|
|
2
|
+
export declare const DEFAULT_INTERVAL_IN_MS = 50;
|
package/dist/index.js
CHANGED
|
@@ -816,6 +816,32 @@ var TEST_ADDRESSES = {
|
|
|
816
816
|
feedObject: "0x9193fd47f9a0ab99b6e365a464c8a9ae30e6150fc37ed2a89c1586631f6fc4ab"
|
|
817
817
|
}
|
|
818
818
|
}
|
|
819
|
+
},
|
|
820
|
+
deep: {
|
|
821
|
+
id: "0xdeeb7a4662eec9f2f3def03fb937a663dddaa2e215b8078a284d026b7946c270",
|
|
822
|
+
metaData: "0x6e60b051a08fa836f5a7acd7c464c8d9825bc29c44657fe170fe9b8e1e4770c0",
|
|
823
|
+
treasury: "",
|
|
824
|
+
oracle: {
|
|
825
|
+
supra: "",
|
|
826
|
+
switchboard: "",
|
|
827
|
+
pyth: {
|
|
828
|
+
feed: "29bdd5248234e33bd93d3b81100b5fa32eaa5997843847e2c2cb16d7c6d9f7ff",
|
|
829
|
+
feedObject: "0x8c7f3a322b94cc69db2a2ac575cbd94bf5766113324c3a3eceac91e3e88a51ed"
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
},
|
|
833
|
+
fud: {
|
|
834
|
+
id: "0x76cb819b01abed502bee8a702b4c2d547532c12f25001c9dea795a5e631c26f1",
|
|
835
|
+
metaData: "0x01087411ef48aaac1eb6e24803213e3a60a03b147dac930e5e341f17a85e524e",
|
|
836
|
+
treasury: "",
|
|
837
|
+
oracle: {
|
|
838
|
+
supra: "",
|
|
839
|
+
switchboard: "",
|
|
840
|
+
pyth: {
|
|
841
|
+
feed: "6a4090703da959247727f2b490eb21aea95c8684ecfac675f432008830890c75",
|
|
842
|
+
feedObject: "0x4531c3ed0d22f21f5fce882905372006c9aafa30f01db03b789e95a6c50de7b2"
|
|
843
|
+
}
|
|
844
|
+
}
|
|
819
845
|
}
|
|
820
846
|
},
|
|
821
847
|
oracles: {
|
|
@@ -1035,14 +1061,22 @@ var TEST_ADDRESSES = {
|
|
|
1035
1061
|
ssbeth: {
|
|
1036
1062
|
coinType: "0xb14f82d8506d139eacef109688d1b71e7236bcce9b2c0ad526abcd6aa5be7de0::scallop_sb_eth::SCALLOP_SB_ETH",
|
|
1037
1063
|
treasury: "0xfd0f02def6358a1f266acfa1493d4707ee8387460d434fb667d63d755ff907ed"
|
|
1064
|
+
},
|
|
1065
|
+
sdeep: {
|
|
1066
|
+
coinType: "0xeb7a05a3224837c5e5503575aed0be73c091d1ce5e43aa3c3e716e0ae614608f::scallop_deep::SCALLOP_DEEP",
|
|
1067
|
+
treasury: "0xc63838fabe37b25ad897392d89876d920f5e0c6a406bf3abcb84753d2829bc88"
|
|
1068
|
+
},
|
|
1069
|
+
sfud: {
|
|
1070
|
+
coinType: "0xe56d5167f427cbe597da9e8150ef5c337839aaf46891d62468dcf80bdd8e10d1::scallop_fud::SCALLOP_FUD",
|
|
1071
|
+
treasury: "0xf25212f11d182decff7a86165699a73e3d5787aced203ca539f43cfbc10db867"
|
|
1038
1072
|
}
|
|
1039
1073
|
}
|
|
1040
1074
|
}
|
|
1041
1075
|
};
|
|
1042
1076
|
|
|
1043
1077
|
// src/constants/tokenBucket.ts
|
|
1044
|
-
var DEFAULT_TOKENS_PER_INTERVAL =
|
|
1045
|
-
var DEFAULT_INTERVAL_IN_MS =
|
|
1078
|
+
var DEFAULT_TOKENS_PER_INTERVAL = 10;
|
|
1079
|
+
var DEFAULT_INTERVAL_IN_MS = 50;
|
|
1046
1080
|
|
|
1047
1081
|
// src/constants/vesca.ts
|
|
1048
1082
|
var UNLOCK_ROUND_DURATION = 60 * 60 * 24;
|
|
@@ -1427,9 +1461,12 @@ var parseOriginBorrowIncentivePoolData = (originBorrowIncentivePoolData) => {
|
|
|
1427
1461
|
poolPoints: originBorrowIncentivePoolData.points.reduce(
|
|
1428
1462
|
(acc, point) => {
|
|
1429
1463
|
const parsed = parseOriginBorrowIncentivesPoolPointData(point);
|
|
1430
|
-
|
|
1464
|
+
let name = (0, import_utils.parseStructTag)(
|
|
1431
1465
|
parsed.pointType
|
|
1432
1466
|
).name.toLowerCase();
|
|
1467
|
+
if (sCoinRawNameToName[name]) {
|
|
1468
|
+
name = sCoinRawNameToName[name];
|
|
1469
|
+
}
|
|
1433
1470
|
acc[name] = parsed;
|
|
1434
1471
|
return acc;
|
|
1435
1472
|
},
|
|
@@ -1628,10 +1665,10 @@ var TokenBucket = class {
|
|
|
1628
1665
|
refill() {
|
|
1629
1666
|
const now = Date.now();
|
|
1630
1667
|
const elapsed = now - this.lastRefill;
|
|
1631
|
-
if (elapsed
|
|
1668
|
+
if (elapsed >= this.interval) {
|
|
1632
1669
|
const tokensToAdd = Math.floor(elapsed / this.interval) * this.tokensPerInterval;
|
|
1633
1670
|
this.tokens = Math.min(this.tokens + tokensToAdd, this.tokensPerInterval);
|
|
1634
|
-
this.lastRefill
|
|
1671
|
+
this.lastRefill += Math.floor(elapsed / this.interval) * this.interval;
|
|
1635
1672
|
}
|
|
1636
1673
|
}
|
|
1637
1674
|
removeTokens(count) {
|
|
@@ -1647,26 +1684,12 @@ var callWithRateLimit = async (tokenBucket, fn, retryDelayInMs = DEFAULT_INTERVA
|
|
|
1647
1684
|
let retries = 0;
|
|
1648
1685
|
const tryRequest = async () => {
|
|
1649
1686
|
if (tokenBucket.removeTokens(1)) {
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
if (result && result.status === 429) {
|
|
1653
|
-
throw new Error("Unexpected status code: 429");
|
|
1654
|
-
}
|
|
1655
|
-
return result;
|
|
1656
|
-
} catch (error) {
|
|
1657
|
-
if (error.message === "Unexpected status code: 429" && retries < maxRetries) {
|
|
1658
|
-
retries++;
|
|
1659
|
-
const delay = retryDelayInMs * Math.pow(backoffFactor, retries);
|
|
1660
|
-
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
1661
|
-
return tryRequest();
|
|
1662
|
-
} else {
|
|
1663
|
-
console.error("An error occurred:", error.message);
|
|
1664
|
-
return null;
|
|
1665
|
-
}
|
|
1666
|
-
}
|
|
1687
|
+
const result = await fn();
|
|
1688
|
+
return result;
|
|
1667
1689
|
} else if (retries < maxRetries) {
|
|
1668
1690
|
retries++;
|
|
1669
1691
|
const delay = retryDelayInMs * Math.pow(backoffFactor, retries);
|
|
1692
|
+
console.error(`Rate limit exceeded, retrying in ${delay} ms`);
|
|
1670
1693
|
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
1671
1694
|
return tryRequest();
|
|
1672
1695
|
} else {
|
|
@@ -1750,11 +1773,13 @@ var ScallopCache = class {
|
|
|
1750
1773
|
const txBlock = new import_sui_kit.SuiTxBlock();
|
|
1751
1774
|
txBlock.moveCall(queryTarget, args, typeArgs);
|
|
1752
1775
|
const query = await this.queryClient.fetchQuery({
|
|
1776
|
+
retry: 5,
|
|
1777
|
+
retryDelay: 1e3,
|
|
1753
1778
|
queryKey: queryKeys.rpc.getInspectTxn(queryTarget, args, typeArgs),
|
|
1754
1779
|
queryFn: async () => {
|
|
1755
1780
|
return await callWithRateLimit(
|
|
1756
1781
|
this.tokenBucket,
|
|
1757
|
-
() => this.suiKit.inspectTxn(txBlock)
|
|
1782
|
+
async () => await this.suiKit.inspectTxn(txBlock)
|
|
1758
1783
|
);
|
|
1759
1784
|
}
|
|
1760
1785
|
});
|
|
@@ -1768,11 +1793,13 @@ var ScallopCache = class {
|
|
|
1768
1793
|
*/
|
|
1769
1794
|
async queryGetObject(objectId, options) {
|
|
1770
1795
|
return this.queryClient.fetchQuery({
|
|
1796
|
+
retry: 5,
|
|
1797
|
+
retryDelay: 1e3,
|
|
1771
1798
|
queryKey: queryKeys.rpc.getObject(objectId, this.walletAddress, options),
|
|
1772
1799
|
queryFn: async () => {
|
|
1773
1800
|
return await callWithRateLimit(
|
|
1774
1801
|
this.tokenBucket,
|
|
1775
|
-
() => this.client.getObject({
|
|
1802
|
+
async () => await this.client.getObject({
|
|
1776
1803
|
id: objectId,
|
|
1777
1804
|
options
|
|
1778
1805
|
})
|
|
@@ -1791,6 +1818,8 @@ var ScallopCache = class {
|
|
|
1791
1818
|
if (objectIds.length === 0)
|
|
1792
1819
|
return [];
|
|
1793
1820
|
return this.queryClient.fetchQuery({
|
|
1821
|
+
retry: 5,
|
|
1822
|
+
retryDelay: 1e3,
|
|
1794
1823
|
queryKey: queryKeys.rpc.getObjects(
|
|
1795
1824
|
objectIds,
|
|
1796
1825
|
this.walletAddress,
|
|
@@ -1799,7 +1828,7 @@ var ScallopCache = class {
|
|
|
1799
1828
|
queryFn: async () => {
|
|
1800
1829
|
return await callWithRateLimit(
|
|
1801
1830
|
this.tokenBucket,
|
|
1802
|
-
() => this.suiKit.getObjects(objectIds, options)
|
|
1831
|
+
async () => await this.suiKit.getObjects(objectIds, options)
|
|
1803
1832
|
);
|
|
1804
1833
|
}
|
|
1805
1834
|
});
|
|
@@ -1811,28 +1840,34 @@ var ScallopCache = class {
|
|
|
1811
1840
|
*/
|
|
1812
1841
|
async queryGetOwnedObjects(input) {
|
|
1813
1842
|
return this.queryClient.fetchQuery({
|
|
1843
|
+
retry: 5,
|
|
1844
|
+
retryDelay: 1e3,
|
|
1814
1845
|
queryKey: queryKeys.rpc.getOwnedObjects(input),
|
|
1815
1846
|
queryFn: async () => {
|
|
1816
1847
|
return await callWithRateLimit(
|
|
1817
1848
|
this.tokenBucket,
|
|
1818
|
-
() => this.client.getOwnedObjects(input)
|
|
1849
|
+
async () => await this.client.getOwnedObjects(input)
|
|
1819
1850
|
);
|
|
1820
1851
|
}
|
|
1821
1852
|
});
|
|
1822
1853
|
}
|
|
1823
1854
|
async queryGetDynamicFields(input) {
|
|
1824
1855
|
return this.queryClient.fetchQuery({
|
|
1856
|
+
retry: 5,
|
|
1857
|
+
retryDelay: 1e3,
|
|
1825
1858
|
queryKey: queryKeys.rpc.getDynamicFields(input),
|
|
1826
1859
|
queryFn: async () => {
|
|
1827
1860
|
return await callWithRateLimit(
|
|
1828
1861
|
this.tokenBucket,
|
|
1829
|
-
() => this.client.getDynamicFields(input)
|
|
1862
|
+
async () => await this.client.getDynamicFields(input)
|
|
1830
1863
|
);
|
|
1831
1864
|
}
|
|
1832
1865
|
});
|
|
1833
1866
|
}
|
|
1834
1867
|
async queryGetDynamicFieldObject(input) {
|
|
1835
1868
|
return this.queryClient.fetchQuery({
|
|
1869
|
+
retry: 5,
|
|
1870
|
+
retryDelay: (attemptIndex) => Math.min(1e3 * attemptIndex, 8e3),
|
|
1836
1871
|
queryKey: queryKeys.rpc.getDynamicFieldObject(input),
|
|
1837
1872
|
queryFn: async () => {
|
|
1838
1873
|
return await callWithRateLimit(
|
|
@@ -1844,11 +1879,13 @@ var ScallopCache = class {
|
|
|
1844
1879
|
}
|
|
1845
1880
|
async queryGetAllCoinBalances(owner) {
|
|
1846
1881
|
return this.queryClient.fetchQuery({
|
|
1882
|
+
retry: 5,
|
|
1883
|
+
retryDelay: 1e3,
|
|
1847
1884
|
queryKey: queryKeys.rpc.getAllCoinBalances(owner),
|
|
1848
1885
|
queryFn: async () => {
|
|
1849
1886
|
const allBalances = await callWithRateLimit(
|
|
1850
1887
|
this.tokenBucket,
|
|
1851
|
-
() => this.client.getAllBalances({ owner })
|
|
1888
|
+
async () => await this.client.getAllBalances({ owner })
|
|
1852
1889
|
);
|
|
1853
1890
|
if (!allBalances)
|
|
1854
1891
|
return {};
|
|
@@ -3763,17 +3800,21 @@ var getObligationAccounts = async (query, ownerAddress, indexer = false) => {
|
|
|
3763
3800
|
return obligationAccounts;
|
|
3764
3801
|
};
|
|
3765
3802
|
var getObligationAccount = async (query, obligationId, ownerAddress, indexer = false, market, coinPrices, coinAmounts) => {
|
|
3803
|
+
const coinNames = Array.from(
|
|
3804
|
+
/* @__PURE__ */ new Set([...SUPPORT_POOLS, ...SUPPORT_COLLATERALS])
|
|
3805
|
+
);
|
|
3766
3806
|
const collateralAssetCoinNames = [
|
|
3767
3807
|
...SUPPORT_COLLATERALS
|
|
3768
3808
|
];
|
|
3769
3809
|
market = market ?? await query.queryMarket({ indexer });
|
|
3770
3810
|
coinPrices = coinPrices ?? await query.getAllCoinPrices({ marketPools: market.pools });
|
|
3771
|
-
coinAmounts = coinAmounts || await query.getCoinAmounts(
|
|
3811
|
+
coinAmounts = coinAmounts || await query.getCoinAmounts(coinNames, ownerAddress);
|
|
3772
3812
|
const [obligationQuery, borrowIncentivePools, borrowIncentiveAccounts] = await Promise.all([
|
|
3773
3813
|
query.queryObligation(obligationId),
|
|
3774
3814
|
query.getBorrowIncentivePools(void 0, {
|
|
3775
3815
|
coinPrices,
|
|
3776
|
-
indexer
|
|
3816
|
+
indexer,
|
|
3817
|
+
marketPools: market.pools
|
|
3777
3818
|
}),
|
|
3778
3819
|
query.getBorrowIncentiveAccounts(obligationId)
|
|
3779
3820
|
]);
|
|
@@ -5167,7 +5208,7 @@ var ScallopUtils = class {
|
|
|
5167
5208
|
);
|
|
5168
5209
|
const priceIds = priceIdPairs.map(([_2, priceId]) => priceId);
|
|
5169
5210
|
const pythConnection = new import_pyth_sui_js.SuiPriceServiceConnection(endpoint, {
|
|
5170
|
-
timeout:
|
|
5211
|
+
timeout: 4e3
|
|
5171
5212
|
});
|
|
5172
5213
|
try {
|
|
5173
5214
|
const feeds = await this.cache.queryClient.fetchQuery({
|