@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
|
@@ -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: ""
|
|
@@ -986,7 +1000,10 @@ var calculateSpoolRewardPoolData = (parsedSpoolData, parsedSpoolRewardPoolData,
|
|
|
986
1000
|
);
|
|
987
1001
|
const claimedRewardValue = claimedRewardCoin.multipliedBy(rewardCoinPrice);
|
|
988
1002
|
const rewardValueForYear = (0, import_bignumber.default)(rewardPerSec).shiftedBy(-1 * rewardCoinDecimal).multipliedBy(rateYearFactor).multipliedBy(rewardCoinPrice);
|
|
989
|
-
|
|
1003
|
+
let rewardRate = rewardValueForYear.dividedBy(calculatedSpoolData.stakedValue).isFinite() ? rewardValueForYear.dividedBy(calculatedSpoolData.stakedValue).toNumber() : Infinity;
|
|
1004
|
+
if (parsedSpoolData.maxPoint === parsedSpoolData.distributedPoint) {
|
|
1005
|
+
rewardRate = Infinity;
|
|
1006
|
+
}
|
|
990
1007
|
return {
|
|
991
1008
|
rewardApr: rewardRate,
|
|
992
1009
|
totalRewardAmount: totalRewardAmount.toNumber(),
|
|
@@ -2008,9 +2025,11 @@ var getStakeAccounts = async (query, ownerAddress) => {
|
|
|
2008
2025
|
}
|
|
2009
2026
|
} while (hasNextPage);
|
|
2010
2027
|
const stakeAccounts = {
|
|
2028
|
+
seth: [],
|
|
2011
2029
|
ssui: [],
|
|
2012
2030
|
susdc: [],
|
|
2013
2031
|
susdt: [],
|
|
2032
|
+
scetus: [],
|
|
2014
2033
|
safsui: [],
|
|
2015
2034
|
shasui: [],
|
|
2016
2035
|
svsui: []
|
|
@@ -2037,7 +2056,18 @@ var getStakeAccounts = async (query, ownerAddress) => {
|
|
|
2037
2056
|
const index = Number(fields.index);
|
|
2038
2057
|
const points = Number(fields.points);
|
|
2039
2058
|
const totalPoints = Number(fields.total_points);
|
|
2040
|
-
if ((0, import_utils4.normalizeStructTag)(type) === stakeMarketCoinTypes.
|
|
2059
|
+
if ((0, import_utils4.normalizeStructTag)(type) === stakeMarketCoinTypes.seth) {
|
|
2060
|
+
stakeAccounts.seth.push({
|
|
2061
|
+
id,
|
|
2062
|
+
type: (0, import_utils4.normalizeStructTag)(type),
|
|
2063
|
+
stakePoolId,
|
|
2064
|
+
stakeType: (0, import_utils4.normalizeStructTag)(stakeType),
|
|
2065
|
+
staked,
|
|
2066
|
+
index,
|
|
2067
|
+
points,
|
|
2068
|
+
totalPoints
|
|
2069
|
+
});
|
|
2070
|
+
} else if ((0, import_utils4.normalizeStructTag)(type) === stakeMarketCoinTypes.ssui) {
|
|
2041
2071
|
stakeAccounts.ssui.push({
|
|
2042
2072
|
id,
|
|
2043
2073
|
type: (0, import_utils4.normalizeStructTag)(type),
|
|
@@ -2070,6 +2100,17 @@ var getStakeAccounts = async (query, ownerAddress) => {
|
|
|
2070
2100
|
points,
|
|
2071
2101
|
totalPoints
|
|
2072
2102
|
});
|
|
2103
|
+
} else if ((0, import_utils4.normalizeStructTag)(type) === stakeMarketCoinTypes.scetus) {
|
|
2104
|
+
stakeAccounts.scetus.push({
|
|
2105
|
+
id,
|
|
2106
|
+
type: (0, import_utils4.normalizeStructTag)(type),
|
|
2107
|
+
stakePoolId,
|
|
2108
|
+
stakeType: (0, import_utils4.normalizeStructTag)(stakeType),
|
|
2109
|
+
staked,
|
|
2110
|
+
index,
|
|
2111
|
+
points,
|
|
2112
|
+
totalPoints
|
|
2113
|
+
});
|
|
2073
2114
|
} else if ((0, import_utils4.normalizeStructTag)(type) === stakeMarketCoinTypes.safsui) {
|
|
2074
2115
|
stakeAccounts.safsui.push({
|
|
2075
2116
|
id,
|
|
@@ -3010,13 +3051,16 @@ var ScallopQuery = class {
|
|
|
3010
3051
|
/**
|
|
3011
3052
|
* Request the scallop API to initialize data.
|
|
3012
3053
|
*
|
|
3013
|
-
* @param
|
|
3054
|
+
* @param force - Whether to force initialization.
|
|
3055
|
+
* @param address - ScallopAddress instance.
|
|
3014
3056
|
*/
|
|
3015
|
-
async init(
|
|
3016
|
-
if (
|
|
3057
|
+
async init(force = false, address) {
|
|
3058
|
+
if (force || !this.address.getAddresses() || !address?.getAddresses()) {
|
|
3017
3059
|
await this.address.read();
|
|
3060
|
+
} else {
|
|
3061
|
+
this.address = address;
|
|
3018
3062
|
}
|
|
3019
|
-
await this.utils.init(
|
|
3063
|
+
await this.utils.init(force, this.address);
|
|
3020
3064
|
}
|
|
3021
3065
|
/* ==================== Core Query Methods ==================== */
|
|
3022
3066
|
/**
|
|
@@ -3342,6 +3386,12 @@ var ScallopQuery = class {
|
|
|
3342
3386
|
}
|
|
3343
3387
|
};
|
|
3344
3388
|
|
|
3389
|
+
// src/constants/pyth.ts
|
|
3390
|
+
var PYTH_ENDPOINTS = {
|
|
3391
|
+
testnet: ["https://hermes-beta.pyth.network"],
|
|
3392
|
+
mainnet: ["https://hermes.pyth.network", "https://scallop.rpc.p2p.world"]
|
|
3393
|
+
};
|
|
3394
|
+
|
|
3345
3395
|
// src/models/scallopUtils.ts
|
|
3346
3396
|
var ScallopUtils = class {
|
|
3347
3397
|
constructor(params, instance) {
|
|
@@ -3379,13 +3429,18 @@ var ScallopUtils = class {
|
|
|
3379
3429
|
/**
|
|
3380
3430
|
* Request the scallop API to initialize data.
|
|
3381
3431
|
*
|
|
3382
|
-
* @param
|
|
3432
|
+
* @param force - Whether to force initialization.
|
|
3433
|
+
* @param address - ScallopAddress instance.
|
|
3383
3434
|
*/
|
|
3384
|
-
async init(
|
|
3385
|
-
if (
|
|
3435
|
+
async init(force = false, address) {
|
|
3436
|
+
if (force || !this._address.getAddresses() || !address?.getAddresses()) {
|
|
3386
3437
|
await this._address.read();
|
|
3438
|
+
} else {
|
|
3439
|
+
this._address = address;
|
|
3440
|
+
}
|
|
3441
|
+
if (!this._query.address.getAddresses()) {
|
|
3442
|
+
await this._query.init(force, this._address);
|
|
3387
3443
|
}
|
|
3388
|
-
await this._query.init(forece);
|
|
3389
3444
|
}
|
|
3390
3445
|
/**
|
|
3391
3446
|
* Convert coin name to symbol.
|
|
@@ -3583,22 +3638,31 @@ var ScallopUtils = class {
|
|
|
3583
3638
|
}
|
|
3584
3639
|
}
|
|
3585
3640
|
if (lackPricesCoinNames.length > 0) {
|
|
3586
|
-
const
|
|
3587
|
-
this.isTestnet ? "https://hermes-beta.pyth.network" : "https://hermes.pyth.network"
|
|
3588
|
-
);
|
|
3589
|
-
const priceIds = lackPricesCoinNames.map(
|
|
3590
|
-
(coinName) => this._address.get(`core.coins.${coinName}.oracle.pyth.feed`)
|
|
3591
|
-
);
|
|
3641
|
+
const endpoints = this.params.pythEndpoints ?? PYTH_ENDPOINTS[this.isTestnet ? "testnet" : "mainnet"];
|
|
3592
3642
|
try {
|
|
3593
|
-
const
|
|
3594
|
-
|
|
3595
|
-
|
|
3596
|
-
|
|
3597
|
-
|
|
3598
|
-
|
|
3599
|
-
|
|
3600
|
-
|
|
3601
|
-
|
|
3643
|
+
for (const endpoint of endpoints) {
|
|
3644
|
+
try {
|
|
3645
|
+
const pythConnection = new import_pyth_sui_js.SuiPriceServiceConnection(endpoint);
|
|
3646
|
+
const priceIds = lackPricesCoinNames.map(
|
|
3647
|
+
(coinName) => this._address.get(`core.coins.${coinName}.oracle.pyth.feed`)
|
|
3648
|
+
);
|
|
3649
|
+
const priceFeeds = await pythConnection.getLatestPriceFeeds(priceIds) || [];
|
|
3650
|
+
for (const [index, feed] of priceFeeds.entries()) {
|
|
3651
|
+
const data = parseDataFromPythPriceFeed(feed, this._address);
|
|
3652
|
+
const coinName = lackPricesCoinNames[index];
|
|
3653
|
+
this._priceMap.set(coinName, {
|
|
3654
|
+
price: data.price,
|
|
3655
|
+
publishTime: data.publishTime
|
|
3656
|
+
});
|
|
3657
|
+
coinPrices[coinName] = data.price;
|
|
3658
|
+
}
|
|
3659
|
+
break;
|
|
3660
|
+
} catch (e) {
|
|
3661
|
+
console.warn(
|
|
3662
|
+
`Failed to update price feeds with endpoint ${endpoint}: ${e}`
|
|
3663
|
+
);
|
|
3664
|
+
}
|
|
3665
|
+
throw new Error("Failed to update price feeds with all endpoins");
|
|
3602
3666
|
}
|
|
3603
3667
|
} catch (_e) {
|
|
3604
3668
|
for (const coinName of lackPricesCoinNames) {
|
|
@@ -3661,15 +3725,23 @@ var updateOracles = async (builder, txBlock, assetCoinNames) => {
|
|
|
3661
3725
|
const priceIds = assetCoinNames.map(
|
|
3662
3726
|
(assetCoinName) => builder.address.get(`core.coins.${assetCoinName}.oracle.pyth.feed`)
|
|
3663
3727
|
);
|
|
3664
|
-
const
|
|
3665
|
-
|
|
3666
|
-
|
|
3667
|
-
|
|
3668
|
-
|
|
3669
|
-
|
|
3670
|
-
|
|
3671
|
-
|
|
3672
|
-
|
|
3728
|
+
const endpoints = builder.params.pythEndpoints ?? PYTH_ENDPOINTS[builder.isTestnet ? "testnet" : "mainnet"];
|
|
3729
|
+
for (const endpoint of endpoints) {
|
|
3730
|
+
try {
|
|
3731
|
+
const pythConnection = new import_pyth_sui_js2.SuiPriceServiceConnection(endpoint);
|
|
3732
|
+
const priceUpdateData = await pythConnection.getPriceFeedsUpdateData(priceIds);
|
|
3733
|
+
await pythClient.updatePriceFeeds(
|
|
3734
|
+
txBlock.txBlock,
|
|
3735
|
+
priceUpdateData,
|
|
3736
|
+
priceIds
|
|
3737
|
+
);
|
|
3738
|
+
break;
|
|
3739
|
+
} catch (e) {
|
|
3740
|
+
console.warn(
|
|
3741
|
+
`Failed to update price feeds with endpoint ${endpoint}: ${e}`
|
|
3742
|
+
);
|
|
3743
|
+
}
|
|
3744
|
+
}
|
|
3673
3745
|
}
|
|
3674
3746
|
const updateAssetCoinNames = [...new Set(assetCoinNames)];
|
|
3675
3747
|
for (const assetCoinName of updateAssetCoinNames) {
|
|
@@ -4492,13 +4564,16 @@ var ScallopBuilder = class {
|
|
|
4492
4564
|
* Request the scallop API to initialize data.
|
|
4493
4565
|
*
|
|
4494
4566
|
* @param force - Whether to force initialization.
|
|
4567
|
+
* @param address - ScallopAddress instance.
|
|
4495
4568
|
*/
|
|
4496
|
-
async init(force = false) {
|
|
4497
|
-
if (force || !this.address.getAddresses()) {
|
|
4569
|
+
async init(force = false, address) {
|
|
4570
|
+
if (force || !this.address.getAddresses() || !address?.getAddresses()) {
|
|
4498
4571
|
await this.address.read();
|
|
4572
|
+
} else {
|
|
4573
|
+
this.address = address;
|
|
4499
4574
|
}
|
|
4500
|
-
await this.query.init(force);
|
|
4501
|
-
await this.utils.init(force);
|
|
4575
|
+
await this.query.init(force, this.address);
|
|
4576
|
+
await this.utils.init(force, this.address);
|
|
4502
4577
|
}
|
|
4503
4578
|
/**
|
|
4504
4579
|
* Create a scallop txBlock instance that enhances transaction block.
|
|
@@ -4586,15 +4661,15 @@ var ScallopClient = class {
|
|
|
4586
4661
|
/**
|
|
4587
4662
|
* Request the scallop API to initialize data.
|
|
4588
4663
|
*
|
|
4589
|
-
* @param
|
|
4664
|
+
* @param force - Whether to force initialization.
|
|
4590
4665
|
*/
|
|
4591
|
-
async init(
|
|
4592
|
-
if (
|
|
4666
|
+
async init(force = false) {
|
|
4667
|
+
if (force || !this.address.getAddresses()) {
|
|
4593
4668
|
await this.address.read();
|
|
4594
4669
|
}
|
|
4595
|
-
await this.
|
|
4596
|
-
await this.
|
|
4597
|
-
await this.
|
|
4670
|
+
await this.builder.init(force, this.address);
|
|
4671
|
+
await this.query.init(force, this.address);
|
|
4672
|
+
await this.utils.init(force, this.address);
|
|
4598
4673
|
}
|
|
4599
4674
|
/* ==================== Query Method ==================== */
|
|
4600
4675
|
/**
|