@scallop-io/sui-scallop-sdk 0.44.15 → 0.44.17
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/common.d.ts +1 -1
- package/dist/constants/pyth.d.ts +3 -0
- package/dist/index.js +120 -88
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +120 -88
- package/dist/index.mjs.map +1 -1
- package/dist/models/scallopBuilder.d.ts +2 -1
- package/dist/models/scallopClient.d.ts +2 -2
- package/dist/models/scallopQuery.d.ts +11 -4
- package/dist/models/scallopUtils.d.ts +4 -2
- package/dist/queries/coreQuery.d.ts +2 -2
- package/dist/queries/spoolQuery.d.ts +2 -0
- package/dist/types/model.d.ts +4 -1
- package/dist/types/query/borrowIncentive.d.ts +0 -5
- package/dist/types/query/spool.d.ts +0 -7
- package/package.json +1 -1
- package/src/builders/oracle.ts +24 -12
- package/src/constants/common.ts +2 -0
- package/src/constants/enum.ts +4 -0
- package/src/constants/pyth.ts +6 -0
- package/src/models/scallopAddress.ts +8 -0
- package/src/models/scallopBuilder.ts +7 -4
- package/src/models/scallopClient.ts +7 -6
- package/src/models/scallopQuery.ts +8 -4
- package/src/models/scallopUtils.ts +40 -22
- package/src/queries/spoolQuery.ts +28 -48
- package/src/types/model.ts +4 -1
- package/src/types/query/borrowIncentive.ts +0 -5
- package/src/types/query/spool.ts +0 -7
- package/src/utils/query.ts +0 -18
package/dist/index.mjs
CHANGED
|
@@ -31,9 +31,11 @@ var SUPPORT_COLLATERALS = [
|
|
|
31
31
|
"vsui"
|
|
32
32
|
];
|
|
33
33
|
var SUPPORT_SPOOLS = [
|
|
34
|
+
"seth",
|
|
34
35
|
"ssui",
|
|
35
36
|
"susdc",
|
|
36
37
|
"susdt",
|
|
38
|
+
"scetus",
|
|
37
39
|
"safsui",
|
|
38
40
|
"shasui",
|
|
39
41
|
"svsui"
|
|
@@ -109,17 +111,21 @@ var marketCoins = {
|
|
|
109
111
|
svsui: "svsui"
|
|
110
112
|
};
|
|
111
113
|
var stakeMarketCoins = {
|
|
114
|
+
seth: "seth",
|
|
112
115
|
ssui: "ssui",
|
|
113
116
|
susdc: "susdc",
|
|
114
117
|
susdt: "susdt",
|
|
118
|
+
scetus: "scetus",
|
|
115
119
|
safsui: "safsui",
|
|
116
120
|
shasui: "shasui",
|
|
117
121
|
svsui: "svsui"
|
|
118
122
|
};
|
|
119
123
|
var spoolRewardCoins = {
|
|
124
|
+
seth: "sui",
|
|
120
125
|
ssui: "sui",
|
|
121
126
|
susdc: "sui",
|
|
122
127
|
susdt: "sui",
|
|
128
|
+
scetus: "sui",
|
|
123
129
|
safsui: "sui",
|
|
124
130
|
shasui: "sui",
|
|
125
131
|
svsui: "sui"
|
|
@@ -343,6 +349,10 @@ var EMPTY_ADDRESSES = {
|
|
|
343
349
|
adminCap: "",
|
|
344
350
|
object: "",
|
|
345
351
|
pools: {
|
|
352
|
+
seth: {
|
|
353
|
+
id: "",
|
|
354
|
+
rewardPoolId: ""
|
|
355
|
+
},
|
|
346
356
|
ssui: {
|
|
347
357
|
id: "",
|
|
348
358
|
rewardPoolId: ""
|
|
@@ -355,6 +365,10 @@ var EMPTY_ADDRESSES = {
|
|
|
355
365
|
id: "",
|
|
356
366
|
rewardPoolId: ""
|
|
357
367
|
},
|
|
368
|
+
scetus: {
|
|
369
|
+
id: "",
|
|
370
|
+
rewardPoolId: ""
|
|
371
|
+
},
|
|
358
372
|
safsui: {
|
|
359
373
|
id: "",
|
|
360
374
|
rewardPoolId: ""
|
|
@@ -899,8 +913,6 @@ var parseOriginSpoolRewardPoolData = (originSpoolRewardPoolData) => {
|
|
|
899
913
|
exchangeRateNumerator: Number(
|
|
900
914
|
originSpoolRewardPoolData.exchange_rate_numerator
|
|
901
915
|
),
|
|
902
|
-
feeRateDenominator: Number(originSpoolRewardPoolData.fee_rate_denominator),
|
|
903
|
-
feeRateNumerator: Number(originSpoolRewardPoolData.fee_rate_numerator),
|
|
904
916
|
rewards: Number(originSpoolRewardPoolData.rewards),
|
|
905
917
|
spoolId: String(originSpoolRewardPoolData.spool_id)
|
|
906
918
|
};
|
|
@@ -925,7 +937,6 @@ var calculateSpoolRewardPoolData = (parsedSpoolData, parsedSpoolRewardPoolData,
|
|
|
925
937
|
const claimedRewardValue = claimedRewardCoin.multipliedBy(rewardCoinPrice);
|
|
926
938
|
const rewardValueForYear = BigNumber(rewardPerSec).shiftedBy(-1 * rewardCoinDecimal).multipliedBy(rateYearFactor).multipliedBy(rewardCoinPrice);
|
|
927
939
|
const rewardRate = rewardValueForYear.dividedBy(calculatedSpoolData.stakedValue).isFinite() ? rewardValueForYear.dividedBy(calculatedSpoolData.stakedValue).toNumber() : Infinity;
|
|
928
|
-
const rewardFeeRate = BigNumber(parsedSpoolRewardPoolData.feeRateNumerator).dividedBy(parsedSpoolRewardPoolData.feeRateDenominator).toNumber();
|
|
929
940
|
return {
|
|
930
941
|
rewardApr: rewardRate,
|
|
931
942
|
totalRewardAmount: totalRewardAmount.toNumber(),
|
|
@@ -937,8 +948,7 @@ var calculateSpoolRewardPoolData = (parsedSpoolData, parsedSpoolRewardPoolData,
|
|
|
937
948
|
claimedRewardAmount: claimedRewardAmount.toNumber(),
|
|
938
949
|
claimedRewardCoin: claimedRewardCoin.toNumber(),
|
|
939
950
|
claimedRewardValue: claimedRewardValue.toNumber(),
|
|
940
|
-
rewardPerSec: rewardPerSec.toNumber()
|
|
941
|
-
rewardFee: rewardFeeRate
|
|
951
|
+
rewardPerSec: rewardPerSec.toNumber()
|
|
942
952
|
};
|
|
943
953
|
};
|
|
944
954
|
var parseOriginBorrowIncentivePoolData = (originBorrowIncentivePoolData) => {
|
|
@@ -1013,12 +1023,6 @@ var parseOriginBorrowIncentiveRewardPoolData = (originBorrowIncentiveRewardPoolD
|
|
|
1013
1023
|
exchangeRateDenominator: Number(
|
|
1014
1024
|
originBorrowIncentiveRewardPoolData.exchange_rate_denominator
|
|
1015
1025
|
),
|
|
1016
|
-
rewardsFeeRateNumerator: Number(
|
|
1017
|
-
originBorrowIncentiveRewardPoolData.rewards_fee_rate_numerator
|
|
1018
|
-
),
|
|
1019
|
-
rewardsFeeRateDenominator: Number(
|
|
1020
|
-
originBorrowIncentiveRewardPoolData.rewards_fee_rate_denominator
|
|
1021
|
-
),
|
|
1022
1026
|
remainingRewards: Number(
|
|
1023
1027
|
originBorrowIncentiveRewardPoolData.remaining_reward
|
|
1024
1028
|
)
|
|
@@ -1048,9 +1052,6 @@ var calculateBorrowIncentiveRewardPoolData = (parsedBorrowIncentivePoolData, par
|
|
|
1048
1052
|
const claimedRewardValue = claimedRewardCoin.multipliedBy(rewardCoinPrice);
|
|
1049
1053
|
const rewardValueForYear = BigNumber(rewardPerSec).shiftedBy(-1 * rewardCoinDecimal).multipliedBy(rateYearFactor).multipliedBy(rewardCoinPrice);
|
|
1050
1054
|
const rewardRate = rewardValueForYear.dividedBy(calculatedBorrowIncentivePoolData.stakedValue).isFinite() ? rewardValueForYear.dividedBy(calculatedBorrowIncentivePoolData.stakedValue).toNumber() : Infinity;
|
|
1051
|
-
const rewardFeeRate = BigNumber(
|
|
1052
|
-
parsedBorrowIncentiveRewardPoolData.rewardsFeeRateNumerator
|
|
1053
|
-
).dividedBy(parsedBorrowIncentiveRewardPoolData.rewardsFeeRateDenominator).toNumber();
|
|
1054
1055
|
return {
|
|
1055
1056
|
rewardApr: rewardRate,
|
|
1056
1057
|
totalRewardAmount: totalRewardAmount.toNumber(),
|
|
@@ -1062,8 +1063,7 @@ var calculateBorrowIncentiveRewardPoolData = (parsedBorrowIncentivePoolData, par
|
|
|
1062
1063
|
claimedRewardAmount: claimedRewardAmount.toNumber(),
|
|
1063
1064
|
claimedRewardCoin: claimedRewardCoin.toNumber(),
|
|
1064
1065
|
claimedRewardValue: claimedRewardValue.toNumber(),
|
|
1065
|
-
rewardPerSec: rewardPerSec.toNumber()
|
|
1066
|
-
rewardFee: rewardFeeRate
|
|
1066
|
+
rewardPerSec: rewardPerSec.toNumber()
|
|
1067
1067
|
};
|
|
1068
1068
|
};
|
|
1069
1069
|
var parseOriginBorrowIncentiveAccountData = (originBorrowIncentiveAccountData) => {
|
|
@@ -1844,7 +1844,6 @@ var getSpools = async (query, stakeMarketCoinNames, indexer = false) => {
|
|
|
1844
1844
|
var getSpool = async (query, marketCoinName, indexer = false, marketPool, coinPrices) => {
|
|
1845
1845
|
const coinName = query.utils.parseCoinName(marketCoinName);
|
|
1846
1846
|
marketPool = marketPool || await query.getMarketPool(coinName, indexer);
|
|
1847
|
-
const spoolPkgId = query.address.get(`spool.id`);
|
|
1848
1847
|
const poolId = query.address.get(`spool.pools.${marketCoinName}.id`);
|
|
1849
1848
|
const rewardPoolId = query.address.get(
|
|
1850
1849
|
`spool.pools.${marketCoinName}.rewardPoolId`
|
|
@@ -1865,19 +1864,11 @@ var getSpool = async (query, marketCoinName, indexer = false, marketPool, coinPr
|
|
|
1865
1864
|
showContent: true
|
|
1866
1865
|
}
|
|
1867
1866
|
});
|
|
1868
|
-
const spoolRewardFeeDynamicFieldsResponse = await query.suiKit.client().getDynamicFieldObject({
|
|
1869
|
-
parentId: rewardPoolId,
|
|
1870
|
-
name: {
|
|
1871
|
-
type: `${spoolPkgId}::rewards_pool::RewardsPoolFeeKey`,
|
|
1872
|
-
value: { dummy_field: false }
|
|
1873
|
-
}
|
|
1874
|
-
});
|
|
1875
1867
|
if (marketPool && spoolObjectResponse[0].data && spoolObjectResponse[1].data) {
|
|
1876
1868
|
const rewardCoinName = query.utils.getSpoolRewardCoinName(marketCoinName);
|
|
1877
1869
|
coinPrices = coinPrices || await query.utils.getCoinPrices([coinName, rewardCoinName]);
|
|
1878
1870
|
const spoolObject = spoolObjectResponse[0].data;
|
|
1879
1871
|
const rewardPoolObject = spoolObjectResponse[1].data;
|
|
1880
|
-
const rewardFeeObject = spoolRewardFeeDynamicFieldsResponse.data;
|
|
1881
1872
|
if (spoolObject.content && "fields" in spoolObject.content) {
|
|
1882
1873
|
const spoolFields = spoolObject.content.fields;
|
|
1883
1874
|
const parsedSpoolData = parseOriginSpoolData({
|
|
@@ -1899,15 +1890,12 @@ var getSpool = async (query, marketCoinName, indexer = false, marketPool, coinPr
|
|
|
1899
1890
|
marketCoinPrice,
|
|
1900
1891
|
marketCoinDecimal
|
|
1901
1892
|
);
|
|
1902
|
-
if (rewardPoolObject.content &&
|
|
1893
|
+
if (rewardPoolObject.content && "fields" in rewardPoolObject.content) {
|
|
1903
1894
|
const rewardPoolFields = rewardPoolObject.content.fields;
|
|
1904
|
-
const rewardFeeFields = rewardFeeObject.content.fields.value.fields;
|
|
1905
1895
|
const parsedSpoolRewardPoolData = parseOriginSpoolRewardPoolData({
|
|
1906
1896
|
claimed_rewards: rewardPoolFields.claimed_rewards,
|
|
1907
1897
|
exchange_rate_numerator: rewardPoolFields.exchange_rate_numerator,
|
|
1908
1898
|
exchange_rate_denominator: rewardPoolFields.exchange_rate_denominator,
|
|
1909
|
-
fee_rate_numerator: rewardFeeFields.fee_rate_numerator,
|
|
1910
|
-
fee_rate_denominator: rewardFeeFields.fee_rate_denominator,
|
|
1911
1899
|
rewards: rewardPoolFields.rewards,
|
|
1912
1900
|
spool_id: rewardPoolFields.spool_id
|
|
1913
1901
|
});
|
|
@@ -1970,9 +1958,11 @@ var getStakeAccounts = async (query, ownerAddress) => {
|
|
|
1970
1958
|
}
|
|
1971
1959
|
} while (hasNextPage);
|
|
1972
1960
|
const stakeAccounts = {
|
|
1961
|
+
seth: [],
|
|
1973
1962
|
ssui: [],
|
|
1974
1963
|
susdc: [],
|
|
1975
1964
|
susdt: [],
|
|
1965
|
+
scetus: [],
|
|
1976
1966
|
safsui: [],
|
|
1977
1967
|
shasui: [],
|
|
1978
1968
|
svsui: []
|
|
@@ -1999,7 +1989,18 @@ var getStakeAccounts = async (query, ownerAddress) => {
|
|
|
1999
1989
|
const index = Number(fields.index);
|
|
2000
1990
|
const points = Number(fields.points);
|
|
2001
1991
|
const totalPoints = Number(fields.total_points);
|
|
2002
|
-
if (normalizeStructTag3(type) === stakeMarketCoinTypes.
|
|
1992
|
+
if (normalizeStructTag3(type) === stakeMarketCoinTypes.seth) {
|
|
1993
|
+
stakeAccounts.seth.push({
|
|
1994
|
+
id,
|
|
1995
|
+
type: normalizeStructTag3(type),
|
|
1996
|
+
stakePoolId,
|
|
1997
|
+
stakeType: normalizeStructTag3(stakeType),
|
|
1998
|
+
staked,
|
|
1999
|
+
index,
|
|
2000
|
+
points,
|
|
2001
|
+
totalPoints
|
|
2002
|
+
});
|
|
2003
|
+
} else if (normalizeStructTag3(type) === stakeMarketCoinTypes.ssui) {
|
|
2003
2004
|
stakeAccounts.ssui.push({
|
|
2004
2005
|
id,
|
|
2005
2006
|
type: normalizeStructTag3(type),
|
|
@@ -2032,6 +2033,17 @@ var getStakeAccounts = async (query, ownerAddress) => {
|
|
|
2032
2033
|
points,
|
|
2033
2034
|
totalPoints
|
|
2034
2035
|
});
|
|
2036
|
+
} else if (normalizeStructTag3(type) === stakeMarketCoinTypes.scetus) {
|
|
2037
|
+
stakeAccounts.scetus.push({
|
|
2038
|
+
id,
|
|
2039
|
+
type: normalizeStructTag3(type),
|
|
2040
|
+
stakePoolId,
|
|
2041
|
+
stakeType: normalizeStructTag3(stakeType),
|
|
2042
|
+
staked,
|
|
2043
|
+
index,
|
|
2044
|
+
points,
|
|
2045
|
+
totalPoints
|
|
2046
|
+
});
|
|
2035
2047
|
} else if (normalizeStructTag3(type) === stakeMarketCoinTypes.safsui) {
|
|
2036
2048
|
stakeAccounts.safsui.push({
|
|
2037
2049
|
id,
|
|
@@ -2115,7 +2127,6 @@ var getStakePool = async (query, marketCoinName) => {
|
|
|
2115
2127
|
return stakePool;
|
|
2116
2128
|
};
|
|
2117
2129
|
var getStakeRewardPool = async (query, marketCoinName) => {
|
|
2118
|
-
const spoolPkgId = query.address.get("spool.id");
|
|
2119
2130
|
const poolId = query.address.get(
|
|
2120
2131
|
`spool.pools.${marketCoinName}.rewardPoolId`
|
|
2121
2132
|
);
|
|
@@ -2127,21 +2138,12 @@ var getStakeRewardPool = async (query, marketCoinName) => {
|
|
|
2127
2138
|
showType: true
|
|
2128
2139
|
}
|
|
2129
2140
|
});
|
|
2130
|
-
|
|
2131
|
-
parentId: poolId,
|
|
2132
|
-
name: {
|
|
2133
|
-
type: `${spoolPkgId}::rewards_pool::RewardsPoolFeeKey`,
|
|
2134
|
-
value: { dummy_field: false }
|
|
2135
|
-
}
|
|
2136
|
-
});
|
|
2137
|
-
if (stakeRewardPoolObjectResponse.data && stakeRewardFeeDynamicFieldsResponse.data) {
|
|
2141
|
+
if (stakeRewardPoolObjectResponse.data) {
|
|
2138
2142
|
const stakeRewardPoolObject = stakeRewardPoolObjectResponse.data;
|
|
2139
|
-
const stakeRewardFeeDynamicFieldObject = stakeRewardFeeDynamicFieldsResponse.data;
|
|
2140
2143
|
const id = stakeRewardPoolObject.objectId;
|
|
2141
2144
|
const type = stakeRewardPoolObject.type;
|
|
2142
|
-
if (stakeRewardPoolObject.content &&
|
|
2145
|
+
if (stakeRewardPoolObject.content && "fields" in stakeRewardPoolObject.content) {
|
|
2143
2146
|
const rewardPoolFields = stakeRewardPoolObject.content.fields;
|
|
2144
|
-
const rewardFeeFields = stakeRewardFeeDynamicFieldObject.content.fields.value.fields;
|
|
2145
2147
|
const stakePoolId = String(rewardPoolFields.spool_id);
|
|
2146
2148
|
const ratioNumerator = Number(rewardPoolFields.exchange_rate_numerator);
|
|
2147
2149
|
const ratioDenominator = Number(
|
|
@@ -2149,16 +2151,12 @@ var getStakeRewardPool = async (query, marketCoinName) => {
|
|
|
2149
2151
|
);
|
|
2150
2152
|
const rewards = Number(rewardPoolFields.rewards);
|
|
2151
2153
|
const claimedRewards = Number(rewardPoolFields.claimed_rewards);
|
|
2152
|
-
const feeRateNumerator = Number(rewardFeeFields.fee_rate_numerator);
|
|
2153
|
-
const feeRateDenominator = Number(rewardFeeFields.fee_rate_denominator);
|
|
2154
2154
|
stakeRewardPool = {
|
|
2155
2155
|
id,
|
|
2156
2156
|
type: normalizeStructTag3(type),
|
|
2157
2157
|
stakePoolId,
|
|
2158
2158
|
ratioNumerator,
|
|
2159
2159
|
ratioDenominator,
|
|
2160
|
-
feeRateNumerator,
|
|
2161
|
-
feeRateDenominator,
|
|
2162
2160
|
rewards,
|
|
2163
2161
|
claimedRewards
|
|
2164
2162
|
};
|
|
@@ -2986,13 +2984,16 @@ var ScallopQuery = class {
|
|
|
2986
2984
|
/**
|
|
2987
2985
|
* Request the scallop API to initialize data.
|
|
2988
2986
|
*
|
|
2989
|
-
* @param
|
|
2987
|
+
* @param force - Whether to force initialization.
|
|
2988
|
+
* @param address - ScallopAddress instance.
|
|
2990
2989
|
*/
|
|
2991
|
-
async init(
|
|
2992
|
-
if (
|
|
2990
|
+
async init(force = false, address) {
|
|
2991
|
+
if (force || !this.address.getAddresses() || !address?.getAddresses()) {
|
|
2993
2992
|
await this.address.read();
|
|
2993
|
+
} else {
|
|
2994
|
+
this.address = address;
|
|
2994
2995
|
}
|
|
2995
|
-
await this.utils.init(
|
|
2996
|
+
await this.utils.init(force, this.address);
|
|
2996
2997
|
}
|
|
2997
2998
|
/* ==================== Core Query Methods ==================== */
|
|
2998
2999
|
/**
|
|
@@ -3318,6 +3319,12 @@ var ScallopQuery = class {
|
|
|
3318
3319
|
}
|
|
3319
3320
|
};
|
|
3320
3321
|
|
|
3322
|
+
// src/constants/pyth.ts
|
|
3323
|
+
var PYTH_ENDPOINTS = {
|
|
3324
|
+
testnet: ["https://hermes-beta.pyth.network"],
|
|
3325
|
+
mainnet: ["https://hermes.pyth.network", "https://scallop.rpc.p2p.world"]
|
|
3326
|
+
};
|
|
3327
|
+
|
|
3321
3328
|
// src/models/scallopUtils.ts
|
|
3322
3329
|
var ScallopUtils = class {
|
|
3323
3330
|
constructor(params, instance) {
|
|
@@ -3355,13 +3362,18 @@ var ScallopUtils = class {
|
|
|
3355
3362
|
/**
|
|
3356
3363
|
* Request the scallop API to initialize data.
|
|
3357
3364
|
*
|
|
3358
|
-
* @param
|
|
3365
|
+
* @param force - Whether to force initialization.
|
|
3366
|
+
* @param address - ScallopAddress instance.
|
|
3359
3367
|
*/
|
|
3360
|
-
async init(
|
|
3361
|
-
if (
|
|
3368
|
+
async init(force = false, address) {
|
|
3369
|
+
if (force || !this._address.getAddresses() || !address?.getAddresses()) {
|
|
3362
3370
|
await this._address.read();
|
|
3371
|
+
} else {
|
|
3372
|
+
this._address = address;
|
|
3373
|
+
}
|
|
3374
|
+
if (!this._query.address.getAddresses()) {
|
|
3375
|
+
await this._query.init(force, this._address);
|
|
3363
3376
|
}
|
|
3364
|
-
await this._query.init(forece);
|
|
3365
3377
|
}
|
|
3366
3378
|
/**
|
|
3367
3379
|
* Convert coin name to symbol.
|
|
@@ -3559,22 +3571,31 @@ var ScallopUtils = class {
|
|
|
3559
3571
|
}
|
|
3560
3572
|
}
|
|
3561
3573
|
if (lackPricesCoinNames.length > 0) {
|
|
3562
|
-
const
|
|
3563
|
-
this.isTestnet ? "https://hermes-beta.pyth.network" : "https://hermes.pyth.network"
|
|
3564
|
-
);
|
|
3565
|
-
const priceIds = lackPricesCoinNames.map(
|
|
3566
|
-
(coinName) => this._address.get(`core.coins.${coinName}.oracle.pyth.feed`)
|
|
3567
|
-
);
|
|
3574
|
+
const endpoints = this.params.pythEndpoints ?? PYTH_ENDPOINTS[this.isTestnet ? "testnet" : "mainnet"];
|
|
3568
3575
|
try {
|
|
3569
|
-
const
|
|
3570
|
-
|
|
3571
|
-
|
|
3572
|
-
|
|
3573
|
-
|
|
3574
|
-
|
|
3575
|
-
|
|
3576
|
-
|
|
3577
|
-
|
|
3576
|
+
for (const endpoint of endpoints) {
|
|
3577
|
+
try {
|
|
3578
|
+
const pythConnection = new SuiPriceServiceConnection(endpoint);
|
|
3579
|
+
const priceIds = lackPricesCoinNames.map(
|
|
3580
|
+
(coinName) => this._address.get(`core.coins.${coinName}.oracle.pyth.feed`)
|
|
3581
|
+
);
|
|
3582
|
+
const priceFeeds = await pythConnection.getLatestPriceFeeds(priceIds) || [];
|
|
3583
|
+
for (const [index, feed] of priceFeeds.entries()) {
|
|
3584
|
+
const data = parseDataFromPythPriceFeed(feed, this._address);
|
|
3585
|
+
const coinName = lackPricesCoinNames[index];
|
|
3586
|
+
this._priceMap.set(coinName, {
|
|
3587
|
+
price: data.price,
|
|
3588
|
+
publishTime: data.publishTime
|
|
3589
|
+
});
|
|
3590
|
+
coinPrices[coinName] = data.price;
|
|
3591
|
+
}
|
|
3592
|
+
break;
|
|
3593
|
+
} catch (e) {
|
|
3594
|
+
console.warn(
|
|
3595
|
+
`Failed to update price feeds with endpoint ${endpoint}: ${e}`
|
|
3596
|
+
);
|
|
3597
|
+
}
|
|
3598
|
+
throw new Error("Failed to update price feeds with all endpoins");
|
|
3578
3599
|
}
|
|
3579
3600
|
} catch (_e) {
|
|
3580
3601
|
for (const coinName of lackPricesCoinNames) {
|
|
@@ -3640,15 +3661,23 @@ var updateOracles = async (builder, txBlock, assetCoinNames) => {
|
|
|
3640
3661
|
const priceIds = assetCoinNames.map(
|
|
3641
3662
|
(assetCoinName) => builder.address.get(`core.coins.${assetCoinName}.oracle.pyth.feed`)
|
|
3642
3663
|
);
|
|
3643
|
-
const
|
|
3644
|
-
|
|
3645
|
-
|
|
3646
|
-
|
|
3647
|
-
|
|
3648
|
-
|
|
3649
|
-
|
|
3650
|
-
|
|
3651
|
-
|
|
3664
|
+
const endpoints = builder.params.pythEndpoints ?? PYTH_ENDPOINTS[builder.isTestnet ? "testnet" : "mainnet"];
|
|
3665
|
+
for (const endpoint of endpoints) {
|
|
3666
|
+
try {
|
|
3667
|
+
const pythConnection = new SuiPriceServiceConnection2(endpoint);
|
|
3668
|
+
const priceUpdateData = await pythConnection.getPriceFeedsUpdateData(priceIds);
|
|
3669
|
+
await pythClient.updatePriceFeeds(
|
|
3670
|
+
txBlock.txBlock,
|
|
3671
|
+
priceUpdateData,
|
|
3672
|
+
priceIds
|
|
3673
|
+
);
|
|
3674
|
+
break;
|
|
3675
|
+
} catch (e) {
|
|
3676
|
+
console.warn(
|
|
3677
|
+
`Failed to update price feeds with endpoint ${endpoint}: ${e}`
|
|
3678
|
+
);
|
|
3679
|
+
}
|
|
3680
|
+
}
|
|
3652
3681
|
}
|
|
3653
3682
|
const updateAssetCoinNames = [...new Set(assetCoinNames)];
|
|
3654
3683
|
for (const assetCoinName of updateAssetCoinNames) {
|
|
@@ -4471,13 +4500,16 @@ var ScallopBuilder = class {
|
|
|
4471
4500
|
* Request the scallop API to initialize data.
|
|
4472
4501
|
*
|
|
4473
4502
|
* @param force - Whether to force initialization.
|
|
4503
|
+
* @param address - ScallopAddress instance.
|
|
4474
4504
|
*/
|
|
4475
|
-
async init(force = false) {
|
|
4476
|
-
if (force || !this.address.getAddresses()) {
|
|
4505
|
+
async init(force = false, address) {
|
|
4506
|
+
if (force || !this.address.getAddresses() || !address?.getAddresses()) {
|
|
4477
4507
|
await this.address.read();
|
|
4508
|
+
} else {
|
|
4509
|
+
this.address = address;
|
|
4478
4510
|
}
|
|
4479
|
-
await this.query.init(force);
|
|
4480
|
-
await this.utils.init(force);
|
|
4511
|
+
await this.query.init(force, this.address);
|
|
4512
|
+
await this.utils.init(force, this.address);
|
|
4481
4513
|
}
|
|
4482
4514
|
/**
|
|
4483
4515
|
* Create a scallop txBlock instance that enhances transaction block.
|
|
@@ -4565,15 +4597,15 @@ var ScallopClient = class {
|
|
|
4565
4597
|
/**
|
|
4566
4598
|
* Request the scallop API to initialize data.
|
|
4567
4599
|
*
|
|
4568
|
-
* @param
|
|
4600
|
+
* @param force - Whether to force initialization.
|
|
4569
4601
|
*/
|
|
4570
|
-
async init(
|
|
4571
|
-
if (
|
|
4602
|
+
async init(force = false) {
|
|
4603
|
+
if (force || !this.address.getAddresses()) {
|
|
4572
4604
|
await this.address.read();
|
|
4573
4605
|
}
|
|
4574
|
-
await this.
|
|
4575
|
-
await this.
|
|
4576
|
-
await this.
|
|
4606
|
+
await this.builder.init(force, this.address);
|
|
4607
|
+
await this.query.init(force, this.address);
|
|
4608
|
+
await this.utils.init(force, this.address);
|
|
4577
4609
|
}
|
|
4578
4610
|
/* ==================== Query Method ==================== */
|
|
4579
4611
|
/**
|