@scallop-io/sui-scallop-sdk 1.4.15-rc.1 → 1.4.15-rc.2
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/poolAddress.d.ts +1 -0
- package/dist/constants/tokenBucket.d.ts +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +161 -116
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +159 -116
- package/dist/index.mjs.map +1 -1
- package/dist/models/scallopQuery.d.ts +1 -0
- package/dist/queries/poolAddressesQuery.d.ts +1 -0
- package/dist/queries/spoolQuery.d.ts +6 -2
- package/dist/test.d.ts +1 -0
- package/dist/types/query/spool.d.ts +20 -0
- package/dist/utils/index.d.ts +1 -0
- package/package.json +1 -1
- package/src/constants/poolAddress.ts +1 -0
- package/src/constants/tokenBucket.ts +1 -1
- package/src/index.ts +1 -0
- package/src/models/scallopQuery.ts +2 -9
- package/src/queries/poolAddressesQuery.ts +8 -2
- package/src/queries/spoolQuery.ts +186 -121
- package/src/test.ts +17 -0
- package/src/types/query/spool.ts +21 -0
- package/src/utils/core.ts +11 -4
- package/src/utils/index.ts +1 -0
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const DEFAULT_TOKENS_PER_INTERVAL =
|
|
1
|
+
export declare const DEFAULT_TOKENS_PER_INTERVAL = 10;
|
|
2
2
|
export declare const DEFAULT_INTERVAL_IN_MS = 250;
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -71,9 +71,11 @@ __export(src_exports, {
|
|
|
71
71
|
ScallopQuery: () => ScallopQuery,
|
|
72
72
|
ScallopUtils: () => ScallopUtils,
|
|
73
73
|
TEST_ADDRESSES: () => TEST_ADDRESSES,
|
|
74
|
+
TokenBucket: () => TokenBucket,
|
|
74
75
|
UNLOCK_ROUND_DURATION: () => UNLOCK_ROUND_DURATION,
|
|
75
76
|
USE_TEST_ADDRESS: () => USE_TEST_ADDRESS,
|
|
76
77
|
assetCoins: () => assetCoins,
|
|
78
|
+
callWithRateLimit: () => callWithRateLimit,
|
|
77
79
|
coinDecimals: () => coinDecimals,
|
|
78
80
|
coinIds: () => coinIds,
|
|
79
81
|
marketCoins: () => marketCoins,
|
|
@@ -1214,7 +1216,7 @@ var TEST_ADDRESSES = {
|
|
|
1214
1216
|
};
|
|
1215
1217
|
|
|
1216
1218
|
// src/constants/tokenBucket.ts
|
|
1217
|
-
var DEFAULT_TOKENS_PER_INTERVAL =
|
|
1219
|
+
var DEFAULT_TOKENS_PER_INTERVAL = 10;
|
|
1218
1220
|
var DEFAULT_INTERVAL_IN_MS = 250;
|
|
1219
1221
|
|
|
1220
1222
|
// src/constants/vesca.ts
|
|
@@ -1881,10 +1883,16 @@ function withIndexerFallback(method) {
|
|
|
1881
1883
|
var parseObjectAs = (object) => {
|
|
1882
1884
|
if (!(object && object.content && "fields" in object.content))
|
|
1883
1885
|
throw new Error(`Failed to parse object`);
|
|
1884
|
-
const
|
|
1885
|
-
if (typeof
|
|
1886
|
-
|
|
1887
|
-
|
|
1886
|
+
const fields = object.content.fields;
|
|
1887
|
+
if (typeof fields === "object" && "value" in fields) {
|
|
1888
|
+
const value = fields.value;
|
|
1889
|
+
if (typeof value === "object" && "fields" in value)
|
|
1890
|
+
return value.fields;
|
|
1891
|
+
return value;
|
|
1892
|
+
} else if (typeof fields === "object") {
|
|
1893
|
+
return fields;
|
|
1894
|
+
}
|
|
1895
|
+
return fields;
|
|
1888
1896
|
};
|
|
1889
1897
|
|
|
1890
1898
|
// src/models/scallopCache.ts
|
|
@@ -4649,12 +4657,80 @@ var getSCoinSwapRate = async (query, fromSCoin, toSCoin, underlyingCoinPrice) =>
|
|
|
4649
4657
|
|
|
4650
4658
|
// src/queries/spoolQuery.ts
|
|
4651
4659
|
var import_utils9 = require("@mysten/sui/utils");
|
|
4660
|
+
var queryRequiredSpoolObjects = async (query, stakePoolCoinNames) => {
|
|
4661
|
+
const tasks = stakePoolCoinNames.map((t, idx) => ({
|
|
4662
|
+
poolCoinName: stakePoolCoinNames[idx],
|
|
4663
|
+
spool: POOL_ADDRESSES[t]?.spool,
|
|
4664
|
+
spoolReward: POOL_ADDRESSES[t]?.spoolReward,
|
|
4665
|
+
sCoinTreasury: POOL_ADDRESSES[t]?.sCoinTreasury
|
|
4666
|
+
}));
|
|
4667
|
+
const [spoolObjects, spoolRewardObjects, sCoinTreasuryObjects] = await Promise.all([
|
|
4668
|
+
queryMultipleObjects(
|
|
4669
|
+
query.cache,
|
|
4670
|
+
tasks.map((task) => task.spool).filter((t) => !!t)
|
|
4671
|
+
),
|
|
4672
|
+
queryMultipleObjects(
|
|
4673
|
+
query.cache,
|
|
4674
|
+
tasks.map((task) => task.spoolReward).filter((t) => !!t)
|
|
4675
|
+
),
|
|
4676
|
+
queryMultipleObjects(
|
|
4677
|
+
query.cache,
|
|
4678
|
+
tasks.map((task) => task.sCoinTreasury).filter((t) => !!t)
|
|
4679
|
+
)
|
|
4680
|
+
]);
|
|
4681
|
+
const mapObjects = (tasks2, fetchedObjects) => {
|
|
4682
|
+
const resultMap = {};
|
|
4683
|
+
let fetchedIndex = 0;
|
|
4684
|
+
for (const task of tasks2) {
|
|
4685
|
+
const key = task[Object.keys(task)[1]];
|
|
4686
|
+
if (key) {
|
|
4687
|
+
resultMap[task.poolCoinName] = fetchedObjects[fetchedIndex];
|
|
4688
|
+
fetchedIndex++;
|
|
4689
|
+
}
|
|
4690
|
+
}
|
|
4691
|
+
return resultMap;
|
|
4692
|
+
};
|
|
4693
|
+
const spoolMap = mapObjects(tasks, spoolObjects);
|
|
4694
|
+
const spoolRewardMap = mapObjects(tasks, spoolRewardObjects);
|
|
4695
|
+
const sCoinTreasuryMap = mapObjects(tasks, sCoinTreasuryObjects);
|
|
4696
|
+
return stakePoolCoinNames.reduce(
|
|
4697
|
+
(acc, name) => {
|
|
4698
|
+
acc[name] = {
|
|
4699
|
+
spool: spoolMap[name],
|
|
4700
|
+
spoolReward: spoolRewardMap[name],
|
|
4701
|
+
sCoinTreasury: sCoinTreasuryMap[name]
|
|
4702
|
+
};
|
|
4703
|
+
return acc;
|
|
4704
|
+
},
|
|
4705
|
+
{}
|
|
4706
|
+
);
|
|
4707
|
+
};
|
|
4708
|
+
var parseSpoolObjects = ({
|
|
4709
|
+
spool,
|
|
4710
|
+
spoolReward
|
|
4711
|
+
}) => {
|
|
4712
|
+
const _spool = parseObjectAs(spool);
|
|
4713
|
+
const _spoolReward = parseObjectAs(spoolReward);
|
|
4714
|
+
return {
|
|
4715
|
+
stakeType: _spool.stake_type,
|
|
4716
|
+
maxDistributedPoint: _spool.max_distributed_point,
|
|
4717
|
+
distributedPoint: _spool.distributed_point,
|
|
4718
|
+
distributedPointPerPeriod: _spool.distributed_point_per_period,
|
|
4719
|
+
pointDistributionTime: _spool.point_distribution_time,
|
|
4720
|
+
maxStake: _spool.max_stakes,
|
|
4721
|
+
stakes: _spool.stakes,
|
|
4722
|
+
index: _spool.index,
|
|
4723
|
+
createdAt: _spool.created_at,
|
|
4724
|
+
lastUpdate: _spool.last_update,
|
|
4725
|
+
..._spoolReward
|
|
4726
|
+
};
|
|
4727
|
+
};
|
|
4652
4728
|
var getSpools = async (query, stakeMarketCoinNames = [...SUPPORT_SPOOLS], indexer = false, marketPools, coinPrices) => {
|
|
4653
4729
|
const stakeCoinNames = stakeMarketCoinNames.map(
|
|
4654
4730
|
(stakeMarketCoinName) => query.utils.parseCoinName(stakeMarketCoinName)
|
|
4655
4731
|
);
|
|
4656
|
-
coinPrices = coinPrices ?? await query.utils.getCoinPrices() ?? {};
|
|
4657
4732
|
marketPools = marketPools ?? (await query.getMarketPools(stakeCoinNames, { indexer })).pools;
|
|
4733
|
+
coinPrices = coinPrices ?? await query.getAllCoinPrices({ marketPools }) ?? {};
|
|
4658
4734
|
if (!marketPools)
|
|
4659
4735
|
throw new Error(`Fail to fetch marketPools for ${stakeCoinNames}`);
|
|
4660
4736
|
const spools = {};
|
|
@@ -4669,126 +4745,93 @@ var getSpools = async (query, stakeMarketCoinNames = [...SUPPORT_SPOOLS], indexe
|
|
|
4669
4745
|
const rewardCoinName = query.utils.getSpoolRewardCoinName(
|
|
4670
4746
|
spool.marketCoinName
|
|
4671
4747
|
);
|
|
4672
|
-
const marketPool = marketPools[coinName];
|
|
4673
4748
|
spool.coinPrice = coinPrices[coinName] ?? spool.coinPrice;
|
|
4674
|
-
spool.marketCoinPrice = coinPrices[
|
|
4749
|
+
spool.marketCoinPrice = coinPrices[spool.marketCoinName] ?? spool.marketCoinPrice;
|
|
4675
4750
|
spool.rewardCoinPrice = coinPrices[rewardCoinName] ?? spool.rewardCoinPrice;
|
|
4676
4751
|
spools[spool.marketCoinName] = spool;
|
|
4677
4752
|
};
|
|
4678
4753
|
Object.values(spoolsIndexer).forEach(updateSpools);
|
|
4679
4754
|
return spools;
|
|
4680
4755
|
}
|
|
4681
|
-
|
|
4682
|
-
|
|
4683
|
-
|
|
4684
|
-
|
|
4685
|
-
|
|
4686
|
-
|
|
4687
|
-
|
|
4688
|
-
|
|
4689
|
-
|
|
4690
|
-
|
|
4691
|
-
|
|
4692
|
-
|
|
4693
|
-
|
|
4756
|
+
const requiredObjects = await queryRequiredSpoolObjects(
|
|
4757
|
+
query,
|
|
4758
|
+
stakeCoinNames
|
|
4759
|
+
);
|
|
4760
|
+
await Promise.allSettled(
|
|
4761
|
+
stakeMarketCoinNames.map(async (stakeMarketCoinName, idx) => {
|
|
4762
|
+
try {
|
|
4763
|
+
const stakeCoinName = stakeCoinNames[idx];
|
|
4764
|
+
const spool = await getSpool(
|
|
4765
|
+
query,
|
|
4766
|
+
stakeMarketCoinName,
|
|
4767
|
+
indexer,
|
|
4768
|
+
coinPrices,
|
|
4769
|
+
requiredObjects[stakeCoinName]
|
|
4770
|
+
);
|
|
4771
|
+
if (spool) {
|
|
4772
|
+
spools[stakeMarketCoinName] = spool;
|
|
4773
|
+
}
|
|
4774
|
+
} catch (e) {
|
|
4775
|
+
console.error(e);
|
|
4776
|
+
}
|
|
4777
|
+
})
|
|
4778
|
+
);
|
|
4694
4779
|
return spools;
|
|
4695
4780
|
};
|
|
4696
|
-
var getSpool = async (query, marketCoinName, indexer = false,
|
|
4781
|
+
var getSpool = async (query, marketCoinName, indexer = false, coinPrices, requiredObjects) => {
|
|
4697
4782
|
const coinName = query.utils.parseCoinName(marketCoinName);
|
|
4698
|
-
|
|
4699
|
-
if (!marketPool) {
|
|
4700
|
-
throw new Error(`Failed to fetch marketPool for ${marketCoinName}`);
|
|
4701
|
-
}
|
|
4702
|
-
const poolId = query.address.get(`spool.pools.${marketCoinName}.id`);
|
|
4703
|
-
const rewardPoolId = query.address.get(
|
|
4704
|
-
`spool.pools.${marketCoinName}.rewardPoolId`
|
|
4705
|
-
);
|
|
4706
|
-
let spool = void 0;
|
|
4707
|
-
coinPrices = coinPrices || await query.utils.getCoinPrices();
|
|
4783
|
+
coinPrices = coinPrices || await query.getAllCoinPrices();
|
|
4708
4784
|
if (indexer) {
|
|
4709
4785
|
const spoolIndexer = await query.indexer.getSpool(marketCoinName);
|
|
4710
4786
|
const coinName2 = query.utils.parseCoinName(marketCoinName);
|
|
4711
4787
|
const rewardCoinName2 = query.utils.getSpoolRewardCoinName(marketCoinName);
|
|
4712
|
-
spoolIndexer.coinPrice = coinPrices?.[coinName2]
|
|
4713
|
-
spoolIndexer.marketCoinPrice =
|
|
4714
|
-
spoolIndexer.rewardCoinPrice = coinPrices?.[rewardCoinName2]
|
|
4788
|
+
spoolIndexer.coinPrice = coinPrices?.[coinName2] ?? spoolIndexer.coinPrice;
|
|
4789
|
+
spoolIndexer.marketCoinPrice = coinPrices?.[marketCoinName] ?? spoolIndexer.marketCoinPrice;
|
|
4790
|
+
spoolIndexer.rewardCoinPrice = coinPrices?.[rewardCoinName2] ?? spoolIndexer.rewardCoinPrice;
|
|
4715
4791
|
return spoolIndexer;
|
|
4716
4792
|
}
|
|
4717
|
-
|
|
4718
|
-
[poolId, rewardPoolId],
|
|
4719
|
-
{
|
|
4720
|
-
showContent: true
|
|
4721
|
-
}
|
|
4722
|
-
);
|
|
4723
|
-
if (!(spoolObjectResponse[0] && spoolObjectResponse[1])) {
|
|
4724
|
-
throw new Error("Fail to fetch spoolObjectResponse!");
|
|
4725
|
-
}
|
|
4793
|
+
requiredObjects ?? (requiredObjects = (await queryRequiredSpoolObjects(query, [coinName]))[coinName]);
|
|
4726
4794
|
const rewardCoinName = query.utils.getSpoolRewardCoinName(marketCoinName);
|
|
4727
4795
|
coinPrices = coinPrices || await query.utils.getCoinPrices();
|
|
4728
|
-
const
|
|
4729
|
-
const
|
|
4730
|
-
|
|
4731
|
-
|
|
4732
|
-
|
|
4733
|
-
|
|
4734
|
-
|
|
4735
|
-
|
|
4736
|
-
|
|
4737
|
-
|
|
4738
|
-
|
|
4739
|
-
|
|
4740
|
-
|
|
4741
|
-
|
|
4742
|
-
|
|
4743
|
-
|
|
4744
|
-
|
|
4745
|
-
|
|
4746
|
-
|
|
4747
|
-
|
|
4748
|
-
|
|
4749
|
-
|
|
4750
|
-
)
|
|
4751
|
-
|
|
4752
|
-
|
|
4753
|
-
|
|
4754
|
-
|
|
4755
|
-
|
|
4756
|
-
|
|
4757
|
-
|
|
4758
|
-
|
|
4759
|
-
|
|
4760
|
-
|
|
4761
|
-
|
|
4762
|
-
|
|
4763
|
-
|
|
4764
|
-
|
|
4765
|
-
|
|
4766
|
-
|
|
4767
|
-
rewardCoinDecimal
|
|
4768
|
-
);
|
|
4769
|
-
spool = {
|
|
4770
|
-
marketCoinName,
|
|
4771
|
-
symbol: query.utils.parseSymbol(marketCoinName),
|
|
4772
|
-
coinType: query.utils.parseCoinType(coinName),
|
|
4773
|
-
marketCoinType: query.utils.parseMarketCoinType(coinName),
|
|
4774
|
-
rewardCoinType: isMarketCoin(rewardCoinName) ? query.utils.parseMarketCoinType(rewardCoinName) : query.utils.parseCoinType(rewardCoinName),
|
|
4775
|
-
sCoinType: marketPool.sCoinType,
|
|
4776
|
-
coinDecimal: query.utils.getCoinDecimal(coinName),
|
|
4777
|
-
rewardCoinDecimal: query.utils.getCoinDecimal(rewardCoinName),
|
|
4778
|
-
coinPrice: coinPrices?.[coinName] ?? 0,
|
|
4779
|
-
marketCoinPrice,
|
|
4780
|
-
rewardCoinPrice,
|
|
4781
|
-
maxPoint: parsedSpoolData.maxPoint,
|
|
4782
|
-
distributedPoint: parsedSpoolData.distributedPoint,
|
|
4783
|
-
maxStake: parsedSpoolData.maxStake,
|
|
4784
|
-
...calculatedSpoolData,
|
|
4785
|
-
exchangeRateNumerator: parsedSpoolRewardPoolData.exchangeRateNumerator,
|
|
4786
|
-
exchangeRateDenominator: parsedSpoolRewardPoolData.exchangeRateDenominator,
|
|
4787
|
-
...calculatedRewardPoolData
|
|
4788
|
-
};
|
|
4789
|
-
}
|
|
4790
|
-
}
|
|
4791
|
-
return spool;
|
|
4796
|
+
const parsedSpoolObjects = parseSpoolObjects(requiredObjects);
|
|
4797
|
+
const parsedSpoolData = parseOriginSpoolData(parsedSpoolObjects);
|
|
4798
|
+
const marketCoinPrice = coinPrices?.[marketCoinName] ?? 0;
|
|
4799
|
+
const marketCoinDecimal = query.utils.getCoinDecimal(marketCoinName);
|
|
4800
|
+
const calculatedSpoolData = calculateSpoolData(
|
|
4801
|
+
parsedSpoolData,
|
|
4802
|
+
marketCoinPrice,
|
|
4803
|
+
marketCoinDecimal
|
|
4804
|
+
);
|
|
4805
|
+
const parsedSpoolRewardPoolData = parseOriginSpoolRewardPoolData(parsedSpoolObjects);
|
|
4806
|
+
const rewardCoinPrice = coinPrices?.[rewardCoinName] ?? 0;
|
|
4807
|
+
const rewardCoinDecimal = query.utils.getCoinDecimal(rewardCoinName);
|
|
4808
|
+
const calculatedRewardPoolData = calculateSpoolRewardPoolData(
|
|
4809
|
+
parsedSpoolData,
|
|
4810
|
+
parsedSpoolRewardPoolData,
|
|
4811
|
+
calculatedSpoolData,
|
|
4812
|
+
rewardCoinPrice,
|
|
4813
|
+
rewardCoinDecimal
|
|
4814
|
+
);
|
|
4815
|
+
return {
|
|
4816
|
+
marketCoinName,
|
|
4817
|
+
symbol: query.utils.parseSymbol(marketCoinName),
|
|
4818
|
+
coinType: query.utils.parseCoinType(coinName),
|
|
4819
|
+
marketCoinType: query.utils.parseMarketCoinType(coinName),
|
|
4820
|
+
rewardCoinType: isMarketCoin(rewardCoinName) ? query.utils.parseMarketCoinType(rewardCoinName) : query.utils.parseCoinType(rewardCoinName),
|
|
4821
|
+
sCoinType: query.utils.parseSCoinType(marketCoinName),
|
|
4822
|
+
coinDecimal: query.utils.getCoinDecimal(coinName),
|
|
4823
|
+
rewardCoinDecimal: query.utils.getCoinDecimal(rewardCoinName),
|
|
4824
|
+
coinPrice: coinPrices?.[coinName] ?? 0,
|
|
4825
|
+
marketCoinPrice,
|
|
4826
|
+
rewardCoinPrice,
|
|
4827
|
+
maxPoint: parsedSpoolData.maxPoint,
|
|
4828
|
+
distributedPoint: parsedSpoolData.distributedPoint,
|
|
4829
|
+
maxStake: parsedSpoolData.maxStake,
|
|
4830
|
+
...calculatedSpoolData,
|
|
4831
|
+
exchangeRateNumerator: parsedSpoolRewardPoolData.exchangeRateNumerator,
|
|
4832
|
+
exchangeRateDenominator: parsedSpoolRewardPoolData.exchangeRateDenominator,
|
|
4833
|
+
...calculatedRewardPoolData
|
|
4834
|
+
};
|
|
4792
4835
|
};
|
|
4793
4836
|
var getStakeAccounts = async ({
|
|
4794
4837
|
utils
|
|
@@ -5209,6 +5252,10 @@ var getAllAddresses = async (query) => {
|
|
|
5209
5252
|
// @ts-ignore
|
|
5210
5253
|
`spool.pools.s${coinName}.rewardPoolId`
|
|
5211
5254
|
);
|
|
5255
|
+
const sCoinTreasury = query.address.get(
|
|
5256
|
+
// @ts-ignore
|
|
5257
|
+
`scoin.coins.s${coinName}.treasury`
|
|
5258
|
+
);
|
|
5212
5259
|
results[coinName] = {
|
|
5213
5260
|
lendingPoolAddress: addresses[0],
|
|
5214
5261
|
collateralPoolAddress: addresses[1],
|
|
@@ -5220,7 +5267,8 @@ var getAllAddresses = async (query) => {
|
|
|
5220
5267
|
borrowLimitKey: addresses[7],
|
|
5221
5268
|
isolatedAssetKey: addresses[8],
|
|
5222
5269
|
spool,
|
|
5223
|
-
spoolReward: rewardPool
|
|
5270
|
+
spoolReward: rewardPool,
|
|
5271
|
+
sCoinTreasury
|
|
5224
5272
|
};
|
|
5225
5273
|
await new Promise((resolve) => setTimeout(resolve, 200));
|
|
5226
5274
|
})
|
|
@@ -7730,13 +7778,8 @@ var ScallopQuery = class {
|
|
|
7730
7778
|
* @return Spool data.
|
|
7731
7779
|
*/
|
|
7732
7780
|
async getSpool(stakeMarketCoinName, args) {
|
|
7733
|
-
|
|
7734
|
-
|
|
7735
|
-
stakeMarketCoinName,
|
|
7736
|
-
args?.indexer,
|
|
7737
|
-
args?.marketPool,
|
|
7738
|
-
args?.coinPrices
|
|
7739
|
-
);
|
|
7781
|
+
const spools = await this.getSpools(void 0, args);
|
|
7782
|
+
return spools[stakeMarketCoinName];
|
|
7740
7783
|
}
|
|
7741
7784
|
/**
|
|
7742
7785
|
* Get stake accounts data for all stake pools (spools).
|
|
@@ -9066,9 +9109,11 @@ var Scallop = class {
|
|
|
9066
9109
|
ScallopQuery,
|
|
9067
9110
|
ScallopUtils,
|
|
9068
9111
|
TEST_ADDRESSES,
|
|
9112
|
+
TokenBucket,
|
|
9069
9113
|
UNLOCK_ROUND_DURATION,
|
|
9070
9114
|
USE_TEST_ADDRESS,
|
|
9071
9115
|
assetCoins,
|
|
9116
|
+
callWithRateLimit,
|
|
9072
9117
|
coinDecimals,
|
|
9073
9118
|
coinIds,
|
|
9074
9119
|
marketCoins,
|