@scallop-io/sui-scallop-sdk 0.44.16 → 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 +115 -43
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +115 -43
- 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
|
@@ -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: ""
|
|
@@ -2008,9 +2022,11 @@ var getStakeAccounts = async (query, ownerAddress) => {
|
|
|
2008
2022
|
}
|
|
2009
2023
|
} while (hasNextPage);
|
|
2010
2024
|
const stakeAccounts = {
|
|
2025
|
+
seth: [],
|
|
2011
2026
|
ssui: [],
|
|
2012
2027
|
susdc: [],
|
|
2013
2028
|
susdt: [],
|
|
2029
|
+
scetus: [],
|
|
2014
2030
|
safsui: [],
|
|
2015
2031
|
shasui: [],
|
|
2016
2032
|
svsui: []
|
|
@@ -2037,7 +2053,18 @@ var getStakeAccounts = async (query, ownerAddress) => {
|
|
|
2037
2053
|
const index = Number(fields.index);
|
|
2038
2054
|
const points = Number(fields.points);
|
|
2039
2055
|
const totalPoints = Number(fields.total_points);
|
|
2040
|
-
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) {
|
|
2041
2068
|
stakeAccounts.ssui.push({
|
|
2042
2069
|
id,
|
|
2043
2070
|
type: (0, import_utils4.normalizeStructTag)(type),
|
|
@@ -2070,6 +2097,17 @@ var getStakeAccounts = async (query, ownerAddress) => {
|
|
|
2070
2097
|
points,
|
|
2071
2098
|
totalPoints
|
|
2072
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
|
+
});
|
|
2073
2111
|
} else if ((0, import_utils4.normalizeStructTag)(type) === stakeMarketCoinTypes.safsui) {
|
|
2074
2112
|
stakeAccounts.safsui.push({
|
|
2075
2113
|
id,
|
|
@@ -3010,13 +3048,16 @@ var ScallopQuery = class {
|
|
|
3010
3048
|
/**
|
|
3011
3049
|
* Request the scallop API to initialize data.
|
|
3012
3050
|
*
|
|
3013
|
-
* @param
|
|
3051
|
+
* @param force - Whether to force initialization.
|
|
3052
|
+
* @param address - ScallopAddress instance.
|
|
3014
3053
|
*/
|
|
3015
|
-
async init(
|
|
3016
|
-
if (
|
|
3054
|
+
async init(force = false, address) {
|
|
3055
|
+
if (force || !this.address.getAddresses() || !address?.getAddresses()) {
|
|
3017
3056
|
await this.address.read();
|
|
3057
|
+
} else {
|
|
3058
|
+
this.address = address;
|
|
3018
3059
|
}
|
|
3019
|
-
await this.utils.init(
|
|
3060
|
+
await this.utils.init(force, this.address);
|
|
3020
3061
|
}
|
|
3021
3062
|
/* ==================== Core Query Methods ==================== */
|
|
3022
3063
|
/**
|
|
@@ -3342,6 +3383,12 @@ var ScallopQuery = class {
|
|
|
3342
3383
|
}
|
|
3343
3384
|
};
|
|
3344
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
|
+
|
|
3345
3392
|
// src/models/scallopUtils.ts
|
|
3346
3393
|
var ScallopUtils = class {
|
|
3347
3394
|
constructor(params, instance) {
|
|
@@ -3379,13 +3426,18 @@ var ScallopUtils = class {
|
|
|
3379
3426
|
/**
|
|
3380
3427
|
* Request the scallop API to initialize data.
|
|
3381
3428
|
*
|
|
3382
|
-
* @param
|
|
3429
|
+
* @param force - Whether to force initialization.
|
|
3430
|
+
* @param address - ScallopAddress instance.
|
|
3383
3431
|
*/
|
|
3384
|
-
async init(
|
|
3385
|
-
if (
|
|
3432
|
+
async init(force = false, address) {
|
|
3433
|
+
if (force || !this._address.getAddresses() || !address?.getAddresses()) {
|
|
3386
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);
|
|
3387
3440
|
}
|
|
3388
|
-
await this._query.init(forece);
|
|
3389
3441
|
}
|
|
3390
3442
|
/**
|
|
3391
3443
|
* Convert coin name to symbol.
|
|
@@ -3583,22 +3635,31 @@ var ScallopUtils = class {
|
|
|
3583
3635
|
}
|
|
3584
3636
|
}
|
|
3585
3637
|
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
|
-
);
|
|
3638
|
+
const endpoints = this.params.pythEndpoints ?? PYTH_ENDPOINTS[this.isTestnet ? "testnet" : "mainnet"];
|
|
3592
3639
|
try {
|
|
3593
|
-
const
|
|
3594
|
-
|
|
3595
|
-
|
|
3596
|
-
|
|
3597
|
-
|
|
3598
|
-
|
|
3599
|
-
|
|
3600
|
-
|
|
3601
|
-
|
|
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");
|
|
3602
3663
|
}
|
|
3603
3664
|
} catch (_e) {
|
|
3604
3665
|
for (const coinName of lackPricesCoinNames) {
|
|
@@ -3661,15 +3722,23 @@ var updateOracles = async (builder, txBlock, assetCoinNames) => {
|
|
|
3661
3722
|
const priceIds = assetCoinNames.map(
|
|
3662
3723
|
(assetCoinName) => builder.address.get(`core.coins.${assetCoinName}.oracle.pyth.feed`)
|
|
3663
3724
|
);
|
|
3664
|
-
const
|
|
3665
|
-
|
|
3666
|
-
|
|
3667
|
-
|
|
3668
|
-
|
|
3669
|
-
|
|
3670
|
-
|
|
3671
|
-
|
|
3672
|
-
|
|
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
|
+
}
|
|
3673
3742
|
}
|
|
3674
3743
|
const updateAssetCoinNames = [...new Set(assetCoinNames)];
|
|
3675
3744
|
for (const assetCoinName of updateAssetCoinNames) {
|
|
@@ -4492,13 +4561,16 @@ var ScallopBuilder = class {
|
|
|
4492
4561
|
* Request the scallop API to initialize data.
|
|
4493
4562
|
*
|
|
4494
4563
|
* @param force - Whether to force initialization.
|
|
4564
|
+
* @param address - ScallopAddress instance.
|
|
4495
4565
|
*/
|
|
4496
|
-
async init(force = false) {
|
|
4497
|
-
if (force || !this.address.getAddresses()) {
|
|
4566
|
+
async init(force = false, address) {
|
|
4567
|
+
if (force || !this.address.getAddresses() || !address?.getAddresses()) {
|
|
4498
4568
|
await this.address.read();
|
|
4569
|
+
} else {
|
|
4570
|
+
this.address = address;
|
|
4499
4571
|
}
|
|
4500
|
-
await this.query.init(force);
|
|
4501
|
-
await this.utils.init(force);
|
|
4572
|
+
await this.query.init(force, this.address);
|
|
4573
|
+
await this.utils.init(force, this.address);
|
|
4502
4574
|
}
|
|
4503
4575
|
/**
|
|
4504
4576
|
* Create a scallop txBlock instance that enhances transaction block.
|
|
@@ -4586,15 +4658,15 @@ var ScallopClient = class {
|
|
|
4586
4658
|
/**
|
|
4587
4659
|
* Request the scallop API to initialize data.
|
|
4588
4660
|
*
|
|
4589
|
-
* @param
|
|
4661
|
+
* @param force - Whether to force initialization.
|
|
4590
4662
|
*/
|
|
4591
|
-
async init(
|
|
4592
|
-
if (
|
|
4663
|
+
async init(force = false) {
|
|
4664
|
+
if (force || !this.address.getAddresses()) {
|
|
4593
4665
|
await this.address.read();
|
|
4594
4666
|
}
|
|
4595
|
-
await this.
|
|
4596
|
-
await this.
|
|
4597
|
-
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);
|
|
4598
4670
|
}
|
|
4599
4671
|
/* ==================== Query Method ==================== */
|
|
4600
4672
|
/**
|