@scallop-io/sui-scallop-sdk 0.44.16 → 0.44.18
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 +119 -44
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +119 -44
- 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/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 +25 -1
- package/src/types/model.ts +4 -1
- package/src/utils/query.ts +6 -1
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: ""
|
|
@@ -922,7 +936,10 @@ var calculateSpoolRewardPoolData = (parsedSpoolData, parsedSpoolRewardPoolData,
|
|
|
922
936
|
);
|
|
923
937
|
const claimedRewardValue = claimedRewardCoin.multipliedBy(rewardCoinPrice);
|
|
924
938
|
const rewardValueForYear = BigNumber(rewardPerSec).shiftedBy(-1 * rewardCoinDecimal).multipliedBy(rateYearFactor).multipliedBy(rewardCoinPrice);
|
|
925
|
-
|
|
939
|
+
let rewardRate = rewardValueForYear.dividedBy(calculatedSpoolData.stakedValue).isFinite() ? rewardValueForYear.dividedBy(calculatedSpoolData.stakedValue).toNumber() : Infinity;
|
|
940
|
+
if (parsedSpoolData.maxPoint === parsedSpoolData.distributedPoint) {
|
|
941
|
+
rewardRate = Infinity;
|
|
942
|
+
}
|
|
926
943
|
return {
|
|
927
944
|
rewardApr: rewardRate,
|
|
928
945
|
totalRewardAmount: totalRewardAmount.toNumber(),
|
|
@@ -1944,9 +1961,11 @@ var getStakeAccounts = async (query, ownerAddress) => {
|
|
|
1944
1961
|
}
|
|
1945
1962
|
} while (hasNextPage);
|
|
1946
1963
|
const stakeAccounts = {
|
|
1964
|
+
seth: [],
|
|
1947
1965
|
ssui: [],
|
|
1948
1966
|
susdc: [],
|
|
1949
1967
|
susdt: [],
|
|
1968
|
+
scetus: [],
|
|
1950
1969
|
safsui: [],
|
|
1951
1970
|
shasui: [],
|
|
1952
1971
|
svsui: []
|
|
@@ -1973,7 +1992,18 @@ var getStakeAccounts = async (query, ownerAddress) => {
|
|
|
1973
1992
|
const index = Number(fields.index);
|
|
1974
1993
|
const points = Number(fields.points);
|
|
1975
1994
|
const totalPoints = Number(fields.total_points);
|
|
1976
|
-
if (normalizeStructTag3(type) === stakeMarketCoinTypes.
|
|
1995
|
+
if (normalizeStructTag3(type) === stakeMarketCoinTypes.seth) {
|
|
1996
|
+
stakeAccounts.seth.push({
|
|
1997
|
+
id,
|
|
1998
|
+
type: normalizeStructTag3(type),
|
|
1999
|
+
stakePoolId,
|
|
2000
|
+
stakeType: normalizeStructTag3(stakeType),
|
|
2001
|
+
staked,
|
|
2002
|
+
index,
|
|
2003
|
+
points,
|
|
2004
|
+
totalPoints
|
|
2005
|
+
});
|
|
2006
|
+
} else if (normalizeStructTag3(type) === stakeMarketCoinTypes.ssui) {
|
|
1977
2007
|
stakeAccounts.ssui.push({
|
|
1978
2008
|
id,
|
|
1979
2009
|
type: normalizeStructTag3(type),
|
|
@@ -2006,6 +2036,17 @@ var getStakeAccounts = async (query, ownerAddress) => {
|
|
|
2006
2036
|
points,
|
|
2007
2037
|
totalPoints
|
|
2008
2038
|
});
|
|
2039
|
+
} else if (normalizeStructTag3(type) === stakeMarketCoinTypes.scetus) {
|
|
2040
|
+
stakeAccounts.scetus.push({
|
|
2041
|
+
id,
|
|
2042
|
+
type: normalizeStructTag3(type),
|
|
2043
|
+
stakePoolId,
|
|
2044
|
+
stakeType: normalizeStructTag3(stakeType),
|
|
2045
|
+
staked,
|
|
2046
|
+
index,
|
|
2047
|
+
points,
|
|
2048
|
+
totalPoints
|
|
2049
|
+
});
|
|
2009
2050
|
} else if (normalizeStructTag3(type) === stakeMarketCoinTypes.safsui) {
|
|
2010
2051
|
stakeAccounts.safsui.push({
|
|
2011
2052
|
id,
|
|
@@ -2946,13 +2987,16 @@ var ScallopQuery = class {
|
|
|
2946
2987
|
/**
|
|
2947
2988
|
* Request the scallop API to initialize data.
|
|
2948
2989
|
*
|
|
2949
|
-
* @param
|
|
2990
|
+
* @param force - Whether to force initialization.
|
|
2991
|
+
* @param address - ScallopAddress instance.
|
|
2950
2992
|
*/
|
|
2951
|
-
async init(
|
|
2952
|
-
if (
|
|
2993
|
+
async init(force = false, address) {
|
|
2994
|
+
if (force || !this.address.getAddresses() || !address?.getAddresses()) {
|
|
2953
2995
|
await this.address.read();
|
|
2996
|
+
} else {
|
|
2997
|
+
this.address = address;
|
|
2954
2998
|
}
|
|
2955
|
-
await this.utils.init(
|
|
2999
|
+
await this.utils.init(force, this.address);
|
|
2956
3000
|
}
|
|
2957
3001
|
/* ==================== Core Query Methods ==================== */
|
|
2958
3002
|
/**
|
|
@@ -3278,6 +3322,12 @@ var ScallopQuery = class {
|
|
|
3278
3322
|
}
|
|
3279
3323
|
};
|
|
3280
3324
|
|
|
3325
|
+
// src/constants/pyth.ts
|
|
3326
|
+
var PYTH_ENDPOINTS = {
|
|
3327
|
+
testnet: ["https://hermes-beta.pyth.network"],
|
|
3328
|
+
mainnet: ["https://hermes.pyth.network", "https://scallop.rpc.p2p.world"]
|
|
3329
|
+
};
|
|
3330
|
+
|
|
3281
3331
|
// src/models/scallopUtils.ts
|
|
3282
3332
|
var ScallopUtils = class {
|
|
3283
3333
|
constructor(params, instance) {
|
|
@@ -3315,13 +3365,18 @@ var ScallopUtils = class {
|
|
|
3315
3365
|
/**
|
|
3316
3366
|
* Request the scallop API to initialize data.
|
|
3317
3367
|
*
|
|
3318
|
-
* @param
|
|
3368
|
+
* @param force - Whether to force initialization.
|
|
3369
|
+
* @param address - ScallopAddress instance.
|
|
3319
3370
|
*/
|
|
3320
|
-
async init(
|
|
3321
|
-
if (
|
|
3371
|
+
async init(force = false, address) {
|
|
3372
|
+
if (force || !this._address.getAddresses() || !address?.getAddresses()) {
|
|
3322
3373
|
await this._address.read();
|
|
3374
|
+
} else {
|
|
3375
|
+
this._address = address;
|
|
3376
|
+
}
|
|
3377
|
+
if (!this._query.address.getAddresses()) {
|
|
3378
|
+
await this._query.init(force, this._address);
|
|
3323
3379
|
}
|
|
3324
|
-
await this._query.init(forece);
|
|
3325
3380
|
}
|
|
3326
3381
|
/**
|
|
3327
3382
|
* Convert coin name to symbol.
|
|
@@ -3519,22 +3574,31 @@ var ScallopUtils = class {
|
|
|
3519
3574
|
}
|
|
3520
3575
|
}
|
|
3521
3576
|
if (lackPricesCoinNames.length > 0) {
|
|
3522
|
-
const
|
|
3523
|
-
this.isTestnet ? "https://hermes-beta.pyth.network" : "https://hermes.pyth.network"
|
|
3524
|
-
);
|
|
3525
|
-
const priceIds = lackPricesCoinNames.map(
|
|
3526
|
-
(coinName) => this._address.get(`core.coins.${coinName}.oracle.pyth.feed`)
|
|
3527
|
-
);
|
|
3577
|
+
const endpoints = this.params.pythEndpoints ?? PYTH_ENDPOINTS[this.isTestnet ? "testnet" : "mainnet"];
|
|
3528
3578
|
try {
|
|
3529
|
-
const
|
|
3530
|
-
|
|
3531
|
-
|
|
3532
|
-
|
|
3533
|
-
|
|
3534
|
-
|
|
3535
|
-
|
|
3536
|
-
|
|
3537
|
-
|
|
3579
|
+
for (const endpoint of endpoints) {
|
|
3580
|
+
try {
|
|
3581
|
+
const pythConnection = new SuiPriceServiceConnection(endpoint);
|
|
3582
|
+
const priceIds = lackPricesCoinNames.map(
|
|
3583
|
+
(coinName) => this._address.get(`core.coins.${coinName}.oracle.pyth.feed`)
|
|
3584
|
+
);
|
|
3585
|
+
const priceFeeds = await pythConnection.getLatestPriceFeeds(priceIds) || [];
|
|
3586
|
+
for (const [index, feed] of priceFeeds.entries()) {
|
|
3587
|
+
const data = parseDataFromPythPriceFeed(feed, this._address);
|
|
3588
|
+
const coinName = lackPricesCoinNames[index];
|
|
3589
|
+
this._priceMap.set(coinName, {
|
|
3590
|
+
price: data.price,
|
|
3591
|
+
publishTime: data.publishTime
|
|
3592
|
+
});
|
|
3593
|
+
coinPrices[coinName] = data.price;
|
|
3594
|
+
}
|
|
3595
|
+
break;
|
|
3596
|
+
} catch (e) {
|
|
3597
|
+
console.warn(
|
|
3598
|
+
`Failed to update price feeds with endpoint ${endpoint}: ${e}`
|
|
3599
|
+
);
|
|
3600
|
+
}
|
|
3601
|
+
throw new Error("Failed to update price feeds with all endpoins");
|
|
3538
3602
|
}
|
|
3539
3603
|
} catch (_e) {
|
|
3540
3604
|
for (const coinName of lackPricesCoinNames) {
|
|
@@ -3600,15 +3664,23 @@ var updateOracles = async (builder, txBlock, assetCoinNames) => {
|
|
|
3600
3664
|
const priceIds = assetCoinNames.map(
|
|
3601
3665
|
(assetCoinName) => builder.address.get(`core.coins.${assetCoinName}.oracle.pyth.feed`)
|
|
3602
3666
|
);
|
|
3603
|
-
const
|
|
3604
|
-
|
|
3605
|
-
|
|
3606
|
-
|
|
3607
|
-
|
|
3608
|
-
|
|
3609
|
-
|
|
3610
|
-
|
|
3611
|
-
|
|
3667
|
+
const endpoints = builder.params.pythEndpoints ?? PYTH_ENDPOINTS[builder.isTestnet ? "testnet" : "mainnet"];
|
|
3668
|
+
for (const endpoint of endpoints) {
|
|
3669
|
+
try {
|
|
3670
|
+
const pythConnection = new SuiPriceServiceConnection2(endpoint);
|
|
3671
|
+
const priceUpdateData = await pythConnection.getPriceFeedsUpdateData(priceIds);
|
|
3672
|
+
await pythClient.updatePriceFeeds(
|
|
3673
|
+
txBlock.txBlock,
|
|
3674
|
+
priceUpdateData,
|
|
3675
|
+
priceIds
|
|
3676
|
+
);
|
|
3677
|
+
break;
|
|
3678
|
+
} catch (e) {
|
|
3679
|
+
console.warn(
|
|
3680
|
+
`Failed to update price feeds with endpoint ${endpoint}: ${e}`
|
|
3681
|
+
);
|
|
3682
|
+
}
|
|
3683
|
+
}
|
|
3612
3684
|
}
|
|
3613
3685
|
const updateAssetCoinNames = [...new Set(assetCoinNames)];
|
|
3614
3686
|
for (const assetCoinName of updateAssetCoinNames) {
|
|
@@ -4431,13 +4503,16 @@ var ScallopBuilder = class {
|
|
|
4431
4503
|
* Request the scallop API to initialize data.
|
|
4432
4504
|
*
|
|
4433
4505
|
* @param force - Whether to force initialization.
|
|
4506
|
+
* @param address - ScallopAddress instance.
|
|
4434
4507
|
*/
|
|
4435
|
-
async init(force = false) {
|
|
4436
|
-
if (force || !this.address.getAddresses()) {
|
|
4508
|
+
async init(force = false, address) {
|
|
4509
|
+
if (force || !this.address.getAddresses() || !address?.getAddresses()) {
|
|
4437
4510
|
await this.address.read();
|
|
4511
|
+
} else {
|
|
4512
|
+
this.address = address;
|
|
4438
4513
|
}
|
|
4439
|
-
await this.query.init(force);
|
|
4440
|
-
await this.utils.init(force);
|
|
4514
|
+
await this.query.init(force, this.address);
|
|
4515
|
+
await this.utils.init(force, this.address);
|
|
4441
4516
|
}
|
|
4442
4517
|
/**
|
|
4443
4518
|
* Create a scallop txBlock instance that enhances transaction block.
|
|
@@ -4525,15 +4600,15 @@ var ScallopClient = class {
|
|
|
4525
4600
|
/**
|
|
4526
4601
|
* Request the scallop API to initialize data.
|
|
4527
4602
|
*
|
|
4528
|
-
* @param
|
|
4603
|
+
* @param force - Whether to force initialization.
|
|
4529
4604
|
*/
|
|
4530
|
-
async init(
|
|
4531
|
-
if (
|
|
4605
|
+
async init(force = false) {
|
|
4606
|
+
if (force || !this.address.getAddresses()) {
|
|
4532
4607
|
await this.address.read();
|
|
4533
4608
|
}
|
|
4534
|
-
await this.
|
|
4535
|
-
await this.
|
|
4536
|
-
await this.
|
|
4609
|
+
await this.builder.init(force, this.address);
|
|
4610
|
+
await this.query.init(force, this.address);
|
|
4611
|
+
await this.utils.init(force, this.address);
|
|
4537
4612
|
}
|
|
4538
4613
|
/* ==================== Query Method ==================== */
|
|
4539
4614
|
/**
|