@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
|
@@ -5,7 +5,7 @@ export declare const PROTOCOL_OBJECT_ID = "0xefe8b36d5b2e43728cc323298626b831778
|
|
|
5
5
|
export declare const BORROW_FEE_PROTOCOL_ID = "0xc38f849e81cfe46d4e4320f508ea7dda42934a329d5a6571bb4c3cb6ea63f5da";
|
|
6
6
|
export declare const SUPPORT_POOLS: readonly ["eth", "btc", "usdc", "usdt", "sui", "apt", "sol", "cetus", "afsui", "hasui", "vsui"];
|
|
7
7
|
export declare const SUPPORT_COLLATERALS: readonly ["eth", "btc", "usdc", "usdt", "sui", "apt", "sol", "cetus", "afsui", "hasui", "vsui"];
|
|
8
|
-
export declare const SUPPORT_SPOOLS: readonly ["ssui", "susdc", "susdt", "safsui", "shasui", "svsui"];
|
|
8
|
+
export declare const SUPPORT_SPOOLS: readonly ["seth", "ssui", "susdc", "susdt", "scetus", "safsui", "shasui", "svsui"];
|
|
9
9
|
export declare const SUPPORT_SPOOLS_REWARDS: readonly ["sui"];
|
|
10
10
|
export declare const SUPPORT_BORROW_INCENTIVE_POOLS: readonly ["sui", "usdc", "usdt"];
|
|
11
11
|
export declare const SUPPORT_BORROW_INCENTIVE_REWARDS: readonly ["sui"];
|
package/dist/index.js
CHANGED
|
@@ -95,9 +95,11 @@ var SUPPORT_COLLATERALS = [
|
|
|
95
95
|
"vsui"
|
|
96
96
|
];
|
|
97
97
|
var SUPPORT_SPOOLS = [
|
|
98
|
+
"seth",
|
|
98
99
|
"ssui",
|
|
99
100
|
"susdc",
|
|
100
101
|
"susdt",
|
|
102
|
+
"scetus",
|
|
101
103
|
"safsui",
|
|
102
104
|
"shasui",
|
|
103
105
|
"svsui"
|
|
@@ -173,17 +175,21 @@ var marketCoins = {
|
|
|
173
175
|
svsui: "svsui"
|
|
174
176
|
};
|
|
175
177
|
var stakeMarketCoins = {
|
|
178
|
+
seth: "seth",
|
|
176
179
|
ssui: "ssui",
|
|
177
180
|
susdc: "susdc",
|
|
178
181
|
susdt: "susdt",
|
|
182
|
+
scetus: "scetus",
|
|
179
183
|
safsui: "safsui",
|
|
180
184
|
shasui: "shasui",
|
|
181
185
|
svsui: "svsui"
|
|
182
186
|
};
|
|
183
187
|
var spoolRewardCoins = {
|
|
188
|
+
seth: "sui",
|
|
184
189
|
ssui: "sui",
|
|
185
190
|
susdc: "sui",
|
|
186
191
|
susdt: "sui",
|
|
192
|
+
scetus: "sui",
|
|
187
193
|
safsui: "sui",
|
|
188
194
|
shasui: "sui",
|
|
189
195
|
svsui: "sui"
|
|
@@ -407,6 +413,10 @@ var EMPTY_ADDRESSES = {
|
|
|
407
413
|
adminCap: "",
|
|
408
414
|
object: "",
|
|
409
415
|
pools: {
|
|
416
|
+
seth: {
|
|
417
|
+
id: "",
|
|
418
|
+
rewardPoolId: ""
|
|
419
|
+
},
|
|
410
420
|
ssui: {
|
|
411
421
|
id: "",
|
|
412
422
|
rewardPoolId: ""
|
|
@@ -419,6 +429,10 @@ var EMPTY_ADDRESSES = {
|
|
|
419
429
|
id: "",
|
|
420
430
|
rewardPoolId: ""
|
|
421
431
|
},
|
|
432
|
+
scetus: {
|
|
433
|
+
id: "",
|
|
434
|
+
rewardPoolId: ""
|
|
435
|
+
},
|
|
422
436
|
safsui: {
|
|
423
437
|
id: "",
|
|
424
438
|
rewardPoolId: ""
|
|
@@ -963,8 +977,6 @@ var parseOriginSpoolRewardPoolData = (originSpoolRewardPoolData) => {
|
|
|
963
977
|
exchangeRateNumerator: Number(
|
|
964
978
|
originSpoolRewardPoolData.exchange_rate_numerator
|
|
965
979
|
),
|
|
966
|
-
feeRateDenominator: Number(originSpoolRewardPoolData.fee_rate_denominator),
|
|
967
|
-
feeRateNumerator: Number(originSpoolRewardPoolData.fee_rate_numerator),
|
|
968
980
|
rewards: Number(originSpoolRewardPoolData.rewards),
|
|
969
981
|
spoolId: String(originSpoolRewardPoolData.spool_id)
|
|
970
982
|
};
|
|
@@ -989,7 +1001,6 @@ var calculateSpoolRewardPoolData = (parsedSpoolData, parsedSpoolRewardPoolData,
|
|
|
989
1001
|
const claimedRewardValue = claimedRewardCoin.multipliedBy(rewardCoinPrice);
|
|
990
1002
|
const rewardValueForYear = (0, import_bignumber.default)(rewardPerSec).shiftedBy(-1 * rewardCoinDecimal).multipliedBy(rateYearFactor).multipliedBy(rewardCoinPrice);
|
|
991
1003
|
const rewardRate = rewardValueForYear.dividedBy(calculatedSpoolData.stakedValue).isFinite() ? rewardValueForYear.dividedBy(calculatedSpoolData.stakedValue).toNumber() : Infinity;
|
|
992
|
-
const rewardFeeRate = (0, import_bignumber.default)(parsedSpoolRewardPoolData.feeRateNumerator).dividedBy(parsedSpoolRewardPoolData.feeRateDenominator).toNumber();
|
|
993
1004
|
return {
|
|
994
1005
|
rewardApr: rewardRate,
|
|
995
1006
|
totalRewardAmount: totalRewardAmount.toNumber(),
|
|
@@ -1001,8 +1012,7 @@ var calculateSpoolRewardPoolData = (parsedSpoolData, parsedSpoolRewardPoolData,
|
|
|
1001
1012
|
claimedRewardAmount: claimedRewardAmount.toNumber(),
|
|
1002
1013
|
claimedRewardCoin: claimedRewardCoin.toNumber(),
|
|
1003
1014
|
claimedRewardValue: claimedRewardValue.toNumber(),
|
|
1004
|
-
rewardPerSec: rewardPerSec.toNumber()
|
|
1005
|
-
rewardFee: rewardFeeRate
|
|
1015
|
+
rewardPerSec: rewardPerSec.toNumber()
|
|
1006
1016
|
};
|
|
1007
1017
|
};
|
|
1008
1018
|
var parseOriginBorrowIncentivePoolData = (originBorrowIncentivePoolData) => {
|
|
@@ -1077,12 +1087,6 @@ var parseOriginBorrowIncentiveRewardPoolData = (originBorrowIncentiveRewardPoolD
|
|
|
1077
1087
|
exchangeRateDenominator: Number(
|
|
1078
1088
|
originBorrowIncentiveRewardPoolData.exchange_rate_denominator
|
|
1079
1089
|
),
|
|
1080
|
-
rewardsFeeRateNumerator: Number(
|
|
1081
|
-
originBorrowIncentiveRewardPoolData.rewards_fee_rate_numerator
|
|
1082
|
-
),
|
|
1083
|
-
rewardsFeeRateDenominator: Number(
|
|
1084
|
-
originBorrowIncentiveRewardPoolData.rewards_fee_rate_denominator
|
|
1085
|
-
),
|
|
1086
1090
|
remainingRewards: Number(
|
|
1087
1091
|
originBorrowIncentiveRewardPoolData.remaining_reward
|
|
1088
1092
|
)
|
|
@@ -1112,9 +1116,6 @@ var calculateBorrowIncentiveRewardPoolData = (parsedBorrowIncentivePoolData, par
|
|
|
1112
1116
|
const claimedRewardValue = claimedRewardCoin.multipliedBy(rewardCoinPrice);
|
|
1113
1117
|
const rewardValueForYear = (0, import_bignumber.default)(rewardPerSec).shiftedBy(-1 * rewardCoinDecimal).multipliedBy(rateYearFactor).multipliedBy(rewardCoinPrice);
|
|
1114
1118
|
const rewardRate = rewardValueForYear.dividedBy(calculatedBorrowIncentivePoolData.stakedValue).isFinite() ? rewardValueForYear.dividedBy(calculatedBorrowIncentivePoolData.stakedValue).toNumber() : Infinity;
|
|
1115
|
-
const rewardFeeRate = (0, import_bignumber.default)(
|
|
1116
|
-
parsedBorrowIncentiveRewardPoolData.rewardsFeeRateNumerator
|
|
1117
|
-
).dividedBy(parsedBorrowIncentiveRewardPoolData.rewardsFeeRateDenominator).toNumber();
|
|
1118
1119
|
return {
|
|
1119
1120
|
rewardApr: rewardRate,
|
|
1120
1121
|
totalRewardAmount: totalRewardAmount.toNumber(),
|
|
@@ -1126,8 +1127,7 @@ var calculateBorrowIncentiveRewardPoolData = (parsedBorrowIncentivePoolData, par
|
|
|
1126
1127
|
claimedRewardAmount: claimedRewardAmount.toNumber(),
|
|
1127
1128
|
claimedRewardCoin: claimedRewardCoin.toNumber(),
|
|
1128
1129
|
claimedRewardValue: claimedRewardValue.toNumber(),
|
|
1129
|
-
rewardPerSec: rewardPerSec.toNumber()
|
|
1130
|
-
rewardFee: rewardFeeRate
|
|
1130
|
+
rewardPerSec: rewardPerSec.toNumber()
|
|
1131
1131
|
};
|
|
1132
1132
|
};
|
|
1133
1133
|
var parseOriginBorrowIncentiveAccountData = (originBorrowIncentiveAccountData) => {
|
|
@@ -1908,7 +1908,6 @@ var getSpools = async (query, stakeMarketCoinNames, indexer = false) => {
|
|
|
1908
1908
|
var getSpool = async (query, marketCoinName, indexer = false, marketPool, coinPrices) => {
|
|
1909
1909
|
const coinName = query.utils.parseCoinName(marketCoinName);
|
|
1910
1910
|
marketPool = marketPool || await query.getMarketPool(coinName, indexer);
|
|
1911
|
-
const spoolPkgId = query.address.get(`spool.id`);
|
|
1912
1911
|
const poolId = query.address.get(`spool.pools.${marketCoinName}.id`);
|
|
1913
1912
|
const rewardPoolId = query.address.get(
|
|
1914
1913
|
`spool.pools.${marketCoinName}.rewardPoolId`
|
|
@@ -1929,19 +1928,11 @@ var getSpool = async (query, marketCoinName, indexer = false, marketPool, coinPr
|
|
|
1929
1928
|
showContent: true
|
|
1930
1929
|
}
|
|
1931
1930
|
});
|
|
1932
|
-
const spoolRewardFeeDynamicFieldsResponse = await query.suiKit.client().getDynamicFieldObject({
|
|
1933
|
-
parentId: rewardPoolId,
|
|
1934
|
-
name: {
|
|
1935
|
-
type: `${spoolPkgId}::rewards_pool::RewardsPoolFeeKey`,
|
|
1936
|
-
value: { dummy_field: false }
|
|
1937
|
-
}
|
|
1938
|
-
});
|
|
1939
1931
|
if (marketPool && spoolObjectResponse[0].data && spoolObjectResponse[1].data) {
|
|
1940
1932
|
const rewardCoinName = query.utils.getSpoolRewardCoinName(marketCoinName);
|
|
1941
1933
|
coinPrices = coinPrices || await query.utils.getCoinPrices([coinName, rewardCoinName]);
|
|
1942
1934
|
const spoolObject = spoolObjectResponse[0].data;
|
|
1943
1935
|
const rewardPoolObject = spoolObjectResponse[1].data;
|
|
1944
|
-
const rewardFeeObject = spoolRewardFeeDynamicFieldsResponse.data;
|
|
1945
1936
|
if (spoolObject.content && "fields" in spoolObject.content) {
|
|
1946
1937
|
const spoolFields = spoolObject.content.fields;
|
|
1947
1938
|
const parsedSpoolData = parseOriginSpoolData({
|
|
@@ -1963,15 +1954,12 @@ var getSpool = async (query, marketCoinName, indexer = false, marketPool, coinPr
|
|
|
1963
1954
|
marketCoinPrice,
|
|
1964
1955
|
marketCoinDecimal
|
|
1965
1956
|
);
|
|
1966
|
-
if (rewardPoolObject.content &&
|
|
1957
|
+
if (rewardPoolObject.content && "fields" in rewardPoolObject.content) {
|
|
1967
1958
|
const rewardPoolFields = rewardPoolObject.content.fields;
|
|
1968
|
-
const rewardFeeFields = rewardFeeObject.content.fields.value.fields;
|
|
1969
1959
|
const parsedSpoolRewardPoolData = parseOriginSpoolRewardPoolData({
|
|
1970
1960
|
claimed_rewards: rewardPoolFields.claimed_rewards,
|
|
1971
1961
|
exchange_rate_numerator: rewardPoolFields.exchange_rate_numerator,
|
|
1972
1962
|
exchange_rate_denominator: rewardPoolFields.exchange_rate_denominator,
|
|
1973
|
-
fee_rate_numerator: rewardFeeFields.fee_rate_numerator,
|
|
1974
|
-
fee_rate_denominator: rewardFeeFields.fee_rate_denominator,
|
|
1975
1963
|
rewards: rewardPoolFields.rewards,
|
|
1976
1964
|
spool_id: rewardPoolFields.spool_id
|
|
1977
1965
|
});
|
|
@@ -2034,9 +2022,11 @@ var getStakeAccounts = async (query, ownerAddress) => {
|
|
|
2034
2022
|
}
|
|
2035
2023
|
} while (hasNextPage);
|
|
2036
2024
|
const stakeAccounts = {
|
|
2025
|
+
seth: [],
|
|
2037
2026
|
ssui: [],
|
|
2038
2027
|
susdc: [],
|
|
2039
2028
|
susdt: [],
|
|
2029
|
+
scetus: [],
|
|
2040
2030
|
safsui: [],
|
|
2041
2031
|
shasui: [],
|
|
2042
2032
|
svsui: []
|
|
@@ -2063,7 +2053,18 @@ var getStakeAccounts = async (query, ownerAddress) => {
|
|
|
2063
2053
|
const index = Number(fields.index);
|
|
2064
2054
|
const points = Number(fields.points);
|
|
2065
2055
|
const totalPoints = Number(fields.total_points);
|
|
2066
|
-
if ((0, import_utils4.normalizeStructTag)(type) === stakeMarketCoinTypes.
|
|
2056
|
+
if ((0, import_utils4.normalizeStructTag)(type) === stakeMarketCoinTypes.seth) {
|
|
2057
|
+
stakeAccounts.seth.push({
|
|
2058
|
+
id,
|
|
2059
|
+
type: (0, import_utils4.normalizeStructTag)(type),
|
|
2060
|
+
stakePoolId,
|
|
2061
|
+
stakeType: (0, import_utils4.normalizeStructTag)(stakeType),
|
|
2062
|
+
staked,
|
|
2063
|
+
index,
|
|
2064
|
+
points,
|
|
2065
|
+
totalPoints
|
|
2066
|
+
});
|
|
2067
|
+
} else if ((0, import_utils4.normalizeStructTag)(type) === stakeMarketCoinTypes.ssui) {
|
|
2067
2068
|
stakeAccounts.ssui.push({
|
|
2068
2069
|
id,
|
|
2069
2070
|
type: (0, import_utils4.normalizeStructTag)(type),
|
|
@@ -2096,6 +2097,17 @@ var getStakeAccounts = async (query, ownerAddress) => {
|
|
|
2096
2097
|
points,
|
|
2097
2098
|
totalPoints
|
|
2098
2099
|
});
|
|
2100
|
+
} else if ((0, import_utils4.normalizeStructTag)(type) === stakeMarketCoinTypes.scetus) {
|
|
2101
|
+
stakeAccounts.scetus.push({
|
|
2102
|
+
id,
|
|
2103
|
+
type: (0, import_utils4.normalizeStructTag)(type),
|
|
2104
|
+
stakePoolId,
|
|
2105
|
+
stakeType: (0, import_utils4.normalizeStructTag)(stakeType),
|
|
2106
|
+
staked,
|
|
2107
|
+
index,
|
|
2108
|
+
points,
|
|
2109
|
+
totalPoints
|
|
2110
|
+
});
|
|
2099
2111
|
} else if ((0, import_utils4.normalizeStructTag)(type) === stakeMarketCoinTypes.safsui) {
|
|
2100
2112
|
stakeAccounts.safsui.push({
|
|
2101
2113
|
id,
|
|
@@ -2179,7 +2191,6 @@ var getStakePool = async (query, marketCoinName) => {
|
|
|
2179
2191
|
return stakePool;
|
|
2180
2192
|
};
|
|
2181
2193
|
var getStakeRewardPool = async (query, marketCoinName) => {
|
|
2182
|
-
const spoolPkgId = query.address.get("spool.id");
|
|
2183
2194
|
const poolId = query.address.get(
|
|
2184
2195
|
`spool.pools.${marketCoinName}.rewardPoolId`
|
|
2185
2196
|
);
|
|
@@ -2191,21 +2202,12 @@ var getStakeRewardPool = async (query, marketCoinName) => {
|
|
|
2191
2202
|
showType: true
|
|
2192
2203
|
}
|
|
2193
2204
|
});
|
|
2194
|
-
|
|
2195
|
-
parentId: poolId,
|
|
2196
|
-
name: {
|
|
2197
|
-
type: `${spoolPkgId}::rewards_pool::RewardsPoolFeeKey`,
|
|
2198
|
-
value: { dummy_field: false }
|
|
2199
|
-
}
|
|
2200
|
-
});
|
|
2201
|
-
if (stakeRewardPoolObjectResponse.data && stakeRewardFeeDynamicFieldsResponse.data) {
|
|
2205
|
+
if (stakeRewardPoolObjectResponse.data) {
|
|
2202
2206
|
const stakeRewardPoolObject = stakeRewardPoolObjectResponse.data;
|
|
2203
|
-
const stakeRewardFeeDynamicFieldObject = stakeRewardFeeDynamicFieldsResponse.data;
|
|
2204
2207
|
const id = stakeRewardPoolObject.objectId;
|
|
2205
2208
|
const type = stakeRewardPoolObject.type;
|
|
2206
|
-
if (stakeRewardPoolObject.content &&
|
|
2209
|
+
if (stakeRewardPoolObject.content && "fields" in stakeRewardPoolObject.content) {
|
|
2207
2210
|
const rewardPoolFields = stakeRewardPoolObject.content.fields;
|
|
2208
|
-
const rewardFeeFields = stakeRewardFeeDynamicFieldObject.content.fields.value.fields;
|
|
2209
2211
|
const stakePoolId = String(rewardPoolFields.spool_id);
|
|
2210
2212
|
const ratioNumerator = Number(rewardPoolFields.exchange_rate_numerator);
|
|
2211
2213
|
const ratioDenominator = Number(
|
|
@@ -2213,16 +2215,12 @@ var getStakeRewardPool = async (query, marketCoinName) => {
|
|
|
2213
2215
|
);
|
|
2214
2216
|
const rewards = Number(rewardPoolFields.rewards);
|
|
2215
2217
|
const claimedRewards = Number(rewardPoolFields.claimed_rewards);
|
|
2216
|
-
const feeRateNumerator = Number(rewardFeeFields.fee_rate_numerator);
|
|
2217
|
-
const feeRateDenominator = Number(rewardFeeFields.fee_rate_denominator);
|
|
2218
2218
|
stakeRewardPool = {
|
|
2219
2219
|
id,
|
|
2220
2220
|
type: (0, import_utils4.normalizeStructTag)(type),
|
|
2221
2221
|
stakePoolId,
|
|
2222
2222
|
ratioNumerator,
|
|
2223
2223
|
ratioDenominator,
|
|
2224
|
-
feeRateNumerator,
|
|
2225
|
-
feeRateDenominator,
|
|
2226
2224
|
rewards,
|
|
2227
2225
|
claimedRewards
|
|
2228
2226
|
};
|
|
@@ -3050,13 +3048,16 @@ var ScallopQuery = class {
|
|
|
3050
3048
|
/**
|
|
3051
3049
|
* Request the scallop API to initialize data.
|
|
3052
3050
|
*
|
|
3053
|
-
* @param
|
|
3051
|
+
* @param force - Whether to force initialization.
|
|
3052
|
+
* @param address - ScallopAddress instance.
|
|
3054
3053
|
*/
|
|
3055
|
-
async init(
|
|
3056
|
-
if (
|
|
3054
|
+
async init(force = false, address) {
|
|
3055
|
+
if (force || !this.address.getAddresses() || !address?.getAddresses()) {
|
|
3057
3056
|
await this.address.read();
|
|
3057
|
+
} else {
|
|
3058
|
+
this.address = address;
|
|
3058
3059
|
}
|
|
3059
|
-
await this.utils.init(
|
|
3060
|
+
await this.utils.init(force, this.address);
|
|
3060
3061
|
}
|
|
3061
3062
|
/* ==================== Core Query Methods ==================== */
|
|
3062
3063
|
/**
|
|
@@ -3382,6 +3383,12 @@ var ScallopQuery = class {
|
|
|
3382
3383
|
}
|
|
3383
3384
|
};
|
|
3384
3385
|
|
|
3386
|
+
// src/constants/pyth.ts
|
|
3387
|
+
var PYTH_ENDPOINTS = {
|
|
3388
|
+
testnet: ["https://hermes-beta.pyth.network"],
|
|
3389
|
+
mainnet: ["https://hermes.pyth.network", "https://scallop.rpc.p2p.world"]
|
|
3390
|
+
};
|
|
3391
|
+
|
|
3385
3392
|
// src/models/scallopUtils.ts
|
|
3386
3393
|
var ScallopUtils = class {
|
|
3387
3394
|
constructor(params, instance) {
|
|
@@ -3419,13 +3426,18 @@ var ScallopUtils = class {
|
|
|
3419
3426
|
/**
|
|
3420
3427
|
* Request the scallop API to initialize data.
|
|
3421
3428
|
*
|
|
3422
|
-
* @param
|
|
3429
|
+
* @param force - Whether to force initialization.
|
|
3430
|
+
* @param address - ScallopAddress instance.
|
|
3423
3431
|
*/
|
|
3424
|
-
async init(
|
|
3425
|
-
if (
|
|
3432
|
+
async init(force = false, address) {
|
|
3433
|
+
if (force || !this._address.getAddresses() || !address?.getAddresses()) {
|
|
3426
3434
|
await this._address.read();
|
|
3435
|
+
} else {
|
|
3436
|
+
this._address = address;
|
|
3437
|
+
}
|
|
3438
|
+
if (!this._query.address.getAddresses()) {
|
|
3439
|
+
await this._query.init(force, this._address);
|
|
3427
3440
|
}
|
|
3428
|
-
await this._query.init(forece);
|
|
3429
3441
|
}
|
|
3430
3442
|
/**
|
|
3431
3443
|
* Convert coin name to symbol.
|
|
@@ -3623,22 +3635,31 @@ var ScallopUtils = class {
|
|
|
3623
3635
|
}
|
|
3624
3636
|
}
|
|
3625
3637
|
if (lackPricesCoinNames.length > 0) {
|
|
3626
|
-
const
|
|
3627
|
-
this.isTestnet ? "https://hermes-beta.pyth.network" : "https://hermes.pyth.network"
|
|
3628
|
-
);
|
|
3629
|
-
const priceIds = lackPricesCoinNames.map(
|
|
3630
|
-
(coinName) => this._address.get(`core.coins.${coinName}.oracle.pyth.feed`)
|
|
3631
|
-
);
|
|
3638
|
+
const endpoints = this.params.pythEndpoints ?? PYTH_ENDPOINTS[this.isTestnet ? "testnet" : "mainnet"];
|
|
3632
3639
|
try {
|
|
3633
|
-
const
|
|
3634
|
-
|
|
3635
|
-
|
|
3636
|
-
|
|
3637
|
-
|
|
3638
|
-
|
|
3639
|
-
|
|
3640
|
-
|
|
3641
|
-
|
|
3640
|
+
for (const endpoint of endpoints) {
|
|
3641
|
+
try {
|
|
3642
|
+
const pythConnection = new import_pyth_sui_js.SuiPriceServiceConnection(endpoint);
|
|
3643
|
+
const priceIds = lackPricesCoinNames.map(
|
|
3644
|
+
(coinName) => this._address.get(`core.coins.${coinName}.oracle.pyth.feed`)
|
|
3645
|
+
);
|
|
3646
|
+
const priceFeeds = await pythConnection.getLatestPriceFeeds(priceIds) || [];
|
|
3647
|
+
for (const [index, feed] of priceFeeds.entries()) {
|
|
3648
|
+
const data = parseDataFromPythPriceFeed(feed, this._address);
|
|
3649
|
+
const coinName = lackPricesCoinNames[index];
|
|
3650
|
+
this._priceMap.set(coinName, {
|
|
3651
|
+
price: data.price,
|
|
3652
|
+
publishTime: data.publishTime
|
|
3653
|
+
});
|
|
3654
|
+
coinPrices[coinName] = data.price;
|
|
3655
|
+
}
|
|
3656
|
+
break;
|
|
3657
|
+
} catch (e) {
|
|
3658
|
+
console.warn(
|
|
3659
|
+
`Failed to update price feeds with endpoint ${endpoint}: ${e}`
|
|
3660
|
+
);
|
|
3661
|
+
}
|
|
3662
|
+
throw new Error("Failed to update price feeds with all endpoins");
|
|
3642
3663
|
}
|
|
3643
3664
|
} catch (_e) {
|
|
3644
3665
|
for (const coinName of lackPricesCoinNames) {
|
|
@@ -3701,15 +3722,23 @@ var updateOracles = async (builder, txBlock, assetCoinNames) => {
|
|
|
3701
3722
|
const priceIds = assetCoinNames.map(
|
|
3702
3723
|
(assetCoinName) => builder.address.get(`core.coins.${assetCoinName}.oracle.pyth.feed`)
|
|
3703
3724
|
);
|
|
3704
|
-
const
|
|
3705
|
-
|
|
3706
|
-
|
|
3707
|
-
|
|
3708
|
-
|
|
3709
|
-
|
|
3710
|
-
|
|
3711
|
-
|
|
3712
|
-
|
|
3725
|
+
const endpoints = builder.params.pythEndpoints ?? PYTH_ENDPOINTS[builder.isTestnet ? "testnet" : "mainnet"];
|
|
3726
|
+
for (const endpoint of endpoints) {
|
|
3727
|
+
try {
|
|
3728
|
+
const pythConnection = new import_pyth_sui_js2.SuiPriceServiceConnection(endpoint);
|
|
3729
|
+
const priceUpdateData = await pythConnection.getPriceFeedsUpdateData(priceIds);
|
|
3730
|
+
await pythClient.updatePriceFeeds(
|
|
3731
|
+
txBlock.txBlock,
|
|
3732
|
+
priceUpdateData,
|
|
3733
|
+
priceIds
|
|
3734
|
+
);
|
|
3735
|
+
break;
|
|
3736
|
+
} catch (e) {
|
|
3737
|
+
console.warn(
|
|
3738
|
+
`Failed to update price feeds with endpoint ${endpoint}: ${e}`
|
|
3739
|
+
);
|
|
3740
|
+
}
|
|
3741
|
+
}
|
|
3713
3742
|
}
|
|
3714
3743
|
const updateAssetCoinNames = [...new Set(assetCoinNames)];
|
|
3715
3744
|
for (const assetCoinName of updateAssetCoinNames) {
|
|
@@ -4532,13 +4561,16 @@ var ScallopBuilder = class {
|
|
|
4532
4561
|
* Request the scallop API to initialize data.
|
|
4533
4562
|
*
|
|
4534
4563
|
* @param force - Whether to force initialization.
|
|
4564
|
+
* @param address - ScallopAddress instance.
|
|
4535
4565
|
*/
|
|
4536
|
-
async init(force = false) {
|
|
4537
|
-
if (force || !this.address.getAddresses()) {
|
|
4566
|
+
async init(force = false, address) {
|
|
4567
|
+
if (force || !this.address.getAddresses() || !address?.getAddresses()) {
|
|
4538
4568
|
await this.address.read();
|
|
4569
|
+
} else {
|
|
4570
|
+
this.address = address;
|
|
4539
4571
|
}
|
|
4540
|
-
await this.query.init(force);
|
|
4541
|
-
await this.utils.init(force);
|
|
4572
|
+
await this.query.init(force, this.address);
|
|
4573
|
+
await this.utils.init(force, this.address);
|
|
4542
4574
|
}
|
|
4543
4575
|
/**
|
|
4544
4576
|
* Create a scallop txBlock instance that enhances transaction block.
|
|
@@ -4626,15 +4658,15 @@ var ScallopClient = class {
|
|
|
4626
4658
|
/**
|
|
4627
4659
|
* Request the scallop API to initialize data.
|
|
4628
4660
|
*
|
|
4629
|
-
* @param
|
|
4661
|
+
* @param force - Whether to force initialization.
|
|
4630
4662
|
*/
|
|
4631
|
-
async init(
|
|
4632
|
-
if (
|
|
4663
|
+
async init(force = false) {
|
|
4664
|
+
if (force || !this.address.getAddresses()) {
|
|
4633
4665
|
await this.address.read();
|
|
4634
4666
|
}
|
|
4635
|
-
await this.
|
|
4636
|
-
await this.
|
|
4637
|
-
await this.
|
|
4667
|
+
await this.builder.init(force, this.address);
|
|
4668
|
+
await this.query.init(force, this.address);
|
|
4669
|
+
await this.utils.init(force, this.address);
|
|
4638
4670
|
}
|
|
4639
4671
|
/* ==================== Query Method ==================== */
|
|
4640
4672
|
/**
|