@scallop-io/sui-scallop-sdk 0.44.14 → 0.44.16
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/index.js +84 -54
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +84 -54
- package/dist/index.mjs.map +1 -1
- package/dist/models/scallopBuilder.d.ts +2 -2
- package/dist/models/scallopQuery.d.ts +12 -3
- package/dist/queries/coreQuery.d.ts +3 -3
- package/dist/queries/spoolQuery.d.ts +3 -0
- package/dist/types/query/borrowIncentive.d.ts +0 -5
- package/dist/types/query/portfolio.d.ts +2 -1
- package/dist/types/query/spool.d.ts +0 -7
- package/package.json +1 -1
- package/src/builders/spoolBuilder.ts +2 -2
- package/src/constants/common.ts +8 -1
- package/src/constants/enum.ts +6 -0
- package/src/models/scallopAddress.ts +16 -0
- package/src/models/scallopBuilder.ts +5 -5
- package/src/queries/portfolioQuery.ts +5 -0
- package/src/queries/spoolQuery.ts +39 -47
- package/src/types/query/borrowIncentive.ts +0 -5
- package/src/types/query/portfolio.ts +4 -1
- 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"];
|
|
8
|
+
export declare const SUPPORT_SPOOLS: readonly ["ssui", "susdc", "susdt", "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
|
@@ -94,7 +94,14 @@ var SUPPORT_COLLATERALS = [
|
|
|
94
94
|
"hasui",
|
|
95
95
|
"vsui"
|
|
96
96
|
];
|
|
97
|
-
var SUPPORT_SPOOLS = [
|
|
97
|
+
var SUPPORT_SPOOLS = [
|
|
98
|
+
"ssui",
|
|
99
|
+
"susdc",
|
|
100
|
+
"susdt",
|
|
101
|
+
"safsui",
|
|
102
|
+
"shasui",
|
|
103
|
+
"svsui"
|
|
104
|
+
];
|
|
98
105
|
var SUPPORT_SPOOLS_REWARDS = ["sui"];
|
|
99
106
|
var SUPPORT_BORROW_INCENTIVE_POOLS = ["sui", "usdc", "usdt"];
|
|
100
107
|
var SUPPORT_BORROW_INCENTIVE_REWARDS = ["sui"];
|
|
@@ -168,12 +175,18 @@ var marketCoins = {
|
|
|
168
175
|
var stakeMarketCoins = {
|
|
169
176
|
ssui: "ssui",
|
|
170
177
|
susdc: "susdc",
|
|
171
|
-
susdt: "susdt"
|
|
178
|
+
susdt: "susdt",
|
|
179
|
+
safsui: "safsui",
|
|
180
|
+
shasui: "shasui",
|
|
181
|
+
svsui: "svsui"
|
|
172
182
|
};
|
|
173
183
|
var spoolRewardCoins = {
|
|
174
184
|
ssui: "sui",
|
|
175
185
|
susdc: "sui",
|
|
176
|
-
susdt: "sui"
|
|
186
|
+
susdt: "sui",
|
|
187
|
+
safsui: "sui",
|
|
188
|
+
shasui: "sui",
|
|
189
|
+
svsui: "sui"
|
|
177
190
|
};
|
|
178
191
|
var borrowIncentiveRewardCoins = {
|
|
179
192
|
sui: "sui",
|
|
@@ -401,6 +414,22 @@ var EMPTY_ADDRESSES = {
|
|
|
401
414
|
susdc: {
|
|
402
415
|
id: "",
|
|
403
416
|
rewardPoolId: ""
|
|
417
|
+
},
|
|
418
|
+
susdt: {
|
|
419
|
+
id: "",
|
|
420
|
+
rewardPoolId: ""
|
|
421
|
+
},
|
|
422
|
+
safsui: {
|
|
423
|
+
id: "",
|
|
424
|
+
rewardPoolId: ""
|
|
425
|
+
},
|
|
426
|
+
shasui: {
|
|
427
|
+
id: "",
|
|
428
|
+
rewardPoolId: ""
|
|
429
|
+
},
|
|
430
|
+
svsui: {
|
|
431
|
+
id: "",
|
|
432
|
+
rewardPoolId: ""
|
|
404
433
|
}
|
|
405
434
|
}
|
|
406
435
|
},
|
|
@@ -934,8 +963,6 @@ var parseOriginSpoolRewardPoolData = (originSpoolRewardPoolData) => {
|
|
|
934
963
|
exchangeRateNumerator: Number(
|
|
935
964
|
originSpoolRewardPoolData.exchange_rate_numerator
|
|
936
965
|
),
|
|
937
|
-
feeRateDenominator: Number(originSpoolRewardPoolData.fee_rate_denominator),
|
|
938
|
-
feeRateNumerator: Number(originSpoolRewardPoolData.fee_rate_numerator),
|
|
939
966
|
rewards: Number(originSpoolRewardPoolData.rewards),
|
|
940
967
|
spoolId: String(originSpoolRewardPoolData.spool_id)
|
|
941
968
|
};
|
|
@@ -960,7 +987,6 @@ var calculateSpoolRewardPoolData = (parsedSpoolData, parsedSpoolRewardPoolData,
|
|
|
960
987
|
const claimedRewardValue = claimedRewardCoin.multipliedBy(rewardCoinPrice);
|
|
961
988
|
const rewardValueForYear = (0, import_bignumber.default)(rewardPerSec).shiftedBy(-1 * rewardCoinDecimal).multipliedBy(rateYearFactor).multipliedBy(rewardCoinPrice);
|
|
962
989
|
const rewardRate = rewardValueForYear.dividedBy(calculatedSpoolData.stakedValue).isFinite() ? rewardValueForYear.dividedBy(calculatedSpoolData.stakedValue).toNumber() : Infinity;
|
|
963
|
-
const rewardFeeRate = (0, import_bignumber.default)(parsedSpoolRewardPoolData.feeRateNumerator).dividedBy(parsedSpoolRewardPoolData.feeRateDenominator).toNumber();
|
|
964
990
|
return {
|
|
965
991
|
rewardApr: rewardRate,
|
|
966
992
|
totalRewardAmount: totalRewardAmount.toNumber(),
|
|
@@ -972,8 +998,7 @@ var calculateSpoolRewardPoolData = (parsedSpoolData, parsedSpoolRewardPoolData,
|
|
|
972
998
|
claimedRewardAmount: claimedRewardAmount.toNumber(),
|
|
973
999
|
claimedRewardCoin: claimedRewardCoin.toNumber(),
|
|
974
1000
|
claimedRewardValue: claimedRewardValue.toNumber(),
|
|
975
|
-
rewardPerSec: rewardPerSec.toNumber()
|
|
976
|
-
rewardFee: rewardFeeRate
|
|
1001
|
+
rewardPerSec: rewardPerSec.toNumber()
|
|
977
1002
|
};
|
|
978
1003
|
};
|
|
979
1004
|
var parseOriginBorrowIncentivePoolData = (originBorrowIncentivePoolData) => {
|
|
@@ -1048,12 +1073,6 @@ var parseOriginBorrowIncentiveRewardPoolData = (originBorrowIncentiveRewardPoolD
|
|
|
1048
1073
|
exchangeRateDenominator: Number(
|
|
1049
1074
|
originBorrowIncentiveRewardPoolData.exchange_rate_denominator
|
|
1050
1075
|
),
|
|
1051
|
-
rewardsFeeRateNumerator: Number(
|
|
1052
|
-
originBorrowIncentiveRewardPoolData.rewards_fee_rate_numerator
|
|
1053
|
-
),
|
|
1054
|
-
rewardsFeeRateDenominator: Number(
|
|
1055
|
-
originBorrowIncentiveRewardPoolData.rewards_fee_rate_denominator
|
|
1056
|
-
),
|
|
1057
1076
|
remainingRewards: Number(
|
|
1058
1077
|
originBorrowIncentiveRewardPoolData.remaining_reward
|
|
1059
1078
|
)
|
|
@@ -1083,9 +1102,6 @@ var calculateBorrowIncentiveRewardPoolData = (parsedBorrowIncentivePoolData, par
|
|
|
1083
1102
|
const claimedRewardValue = claimedRewardCoin.multipliedBy(rewardCoinPrice);
|
|
1084
1103
|
const rewardValueForYear = (0, import_bignumber.default)(rewardPerSec).shiftedBy(-1 * rewardCoinDecimal).multipliedBy(rateYearFactor).multipliedBy(rewardCoinPrice);
|
|
1085
1104
|
const rewardRate = rewardValueForYear.dividedBy(calculatedBorrowIncentivePoolData.stakedValue).isFinite() ? rewardValueForYear.dividedBy(calculatedBorrowIncentivePoolData.stakedValue).toNumber() : Infinity;
|
|
1086
|
-
const rewardFeeRate = (0, import_bignumber.default)(
|
|
1087
|
-
parsedBorrowIncentiveRewardPoolData.rewardsFeeRateNumerator
|
|
1088
|
-
).dividedBy(parsedBorrowIncentiveRewardPoolData.rewardsFeeRateDenominator).toNumber();
|
|
1089
1105
|
return {
|
|
1090
1106
|
rewardApr: rewardRate,
|
|
1091
1107
|
totalRewardAmount: totalRewardAmount.toNumber(),
|
|
@@ -1097,8 +1113,7 @@ var calculateBorrowIncentiveRewardPoolData = (parsedBorrowIncentivePoolData, par
|
|
|
1097
1113
|
claimedRewardAmount: claimedRewardAmount.toNumber(),
|
|
1098
1114
|
claimedRewardCoin: claimedRewardCoin.toNumber(),
|
|
1099
1115
|
claimedRewardValue: claimedRewardValue.toNumber(),
|
|
1100
|
-
rewardPerSec: rewardPerSec.toNumber()
|
|
1101
|
-
rewardFee: rewardFeeRate
|
|
1116
|
+
rewardPerSec: rewardPerSec.toNumber()
|
|
1102
1117
|
};
|
|
1103
1118
|
};
|
|
1104
1119
|
var parseOriginBorrowIncentiveAccountData = (originBorrowIncentiveAccountData) => {
|
|
@@ -1879,7 +1894,6 @@ var getSpools = async (query, stakeMarketCoinNames, indexer = false) => {
|
|
|
1879
1894
|
var getSpool = async (query, marketCoinName, indexer = false, marketPool, coinPrices) => {
|
|
1880
1895
|
const coinName = query.utils.parseCoinName(marketCoinName);
|
|
1881
1896
|
marketPool = marketPool || await query.getMarketPool(coinName, indexer);
|
|
1882
|
-
const spoolPkgId = query.address.get(`spool.id`);
|
|
1883
1897
|
const poolId = query.address.get(`spool.pools.${marketCoinName}.id`);
|
|
1884
1898
|
const rewardPoolId = query.address.get(
|
|
1885
1899
|
`spool.pools.${marketCoinName}.rewardPoolId`
|
|
@@ -1900,19 +1914,11 @@ var getSpool = async (query, marketCoinName, indexer = false, marketPool, coinPr
|
|
|
1900
1914
|
showContent: true
|
|
1901
1915
|
}
|
|
1902
1916
|
});
|
|
1903
|
-
const spoolRewardFeeDynamicFieldsResponse = await query.suiKit.client().getDynamicFieldObject({
|
|
1904
|
-
parentId: rewardPoolId,
|
|
1905
|
-
name: {
|
|
1906
|
-
type: `${spoolPkgId}::rewards_pool::RewardsPoolFeeKey`,
|
|
1907
|
-
value: { dummy_field: false }
|
|
1908
|
-
}
|
|
1909
|
-
});
|
|
1910
1917
|
if (marketPool && spoolObjectResponse[0].data && spoolObjectResponse[1].data) {
|
|
1911
1918
|
const rewardCoinName = query.utils.getSpoolRewardCoinName(marketCoinName);
|
|
1912
1919
|
coinPrices = coinPrices || await query.utils.getCoinPrices([coinName, rewardCoinName]);
|
|
1913
1920
|
const spoolObject = spoolObjectResponse[0].data;
|
|
1914
1921
|
const rewardPoolObject = spoolObjectResponse[1].data;
|
|
1915
|
-
const rewardFeeObject = spoolRewardFeeDynamicFieldsResponse.data;
|
|
1916
1922
|
if (spoolObject.content && "fields" in spoolObject.content) {
|
|
1917
1923
|
const spoolFields = spoolObject.content.fields;
|
|
1918
1924
|
const parsedSpoolData = parseOriginSpoolData({
|
|
@@ -1934,15 +1940,12 @@ var getSpool = async (query, marketCoinName, indexer = false, marketPool, coinPr
|
|
|
1934
1940
|
marketCoinPrice,
|
|
1935
1941
|
marketCoinDecimal
|
|
1936
1942
|
);
|
|
1937
|
-
if (rewardPoolObject.content &&
|
|
1943
|
+
if (rewardPoolObject.content && "fields" in rewardPoolObject.content) {
|
|
1938
1944
|
const rewardPoolFields = rewardPoolObject.content.fields;
|
|
1939
|
-
const rewardFeeFields = rewardFeeObject.content.fields.value.fields;
|
|
1940
1945
|
const parsedSpoolRewardPoolData = parseOriginSpoolRewardPoolData({
|
|
1941
1946
|
claimed_rewards: rewardPoolFields.claimed_rewards,
|
|
1942
1947
|
exchange_rate_numerator: rewardPoolFields.exchange_rate_numerator,
|
|
1943
1948
|
exchange_rate_denominator: rewardPoolFields.exchange_rate_denominator,
|
|
1944
|
-
fee_rate_numerator: rewardFeeFields.fee_rate_numerator,
|
|
1945
|
-
fee_rate_denominator: rewardFeeFields.fee_rate_denominator,
|
|
1946
1949
|
rewards: rewardPoolFields.rewards,
|
|
1947
1950
|
spool_id: rewardPoolFields.spool_id
|
|
1948
1951
|
});
|
|
@@ -2007,7 +2010,10 @@ var getStakeAccounts = async (query, ownerAddress) => {
|
|
|
2007
2010
|
const stakeAccounts = {
|
|
2008
2011
|
ssui: [],
|
|
2009
2012
|
susdc: [],
|
|
2010
|
-
susdt: []
|
|
2013
|
+
susdt: [],
|
|
2014
|
+
safsui: [],
|
|
2015
|
+
shasui: [],
|
|
2016
|
+
svsui: []
|
|
2011
2017
|
};
|
|
2012
2018
|
const stakeMarketCoinTypes = Object.keys(stakeAccounts).reduce(
|
|
2013
2019
|
(types, stakeMarketCoinName) => {
|
|
@@ -2064,6 +2070,39 @@ var getStakeAccounts = async (query, ownerAddress) => {
|
|
|
2064
2070
|
points,
|
|
2065
2071
|
totalPoints
|
|
2066
2072
|
});
|
|
2073
|
+
} else if ((0, import_utils4.normalizeStructTag)(type) === stakeMarketCoinTypes.safsui) {
|
|
2074
|
+
stakeAccounts.safsui.push({
|
|
2075
|
+
id,
|
|
2076
|
+
type: (0, import_utils4.normalizeStructTag)(type),
|
|
2077
|
+
stakePoolId,
|
|
2078
|
+
stakeType: (0, import_utils4.normalizeStructTag)(stakeType),
|
|
2079
|
+
staked,
|
|
2080
|
+
index,
|
|
2081
|
+
points,
|
|
2082
|
+
totalPoints
|
|
2083
|
+
});
|
|
2084
|
+
} else if ((0, import_utils4.normalizeStructTag)(type) === stakeMarketCoinTypes.shasui) {
|
|
2085
|
+
stakeAccounts.shasui.push({
|
|
2086
|
+
id,
|
|
2087
|
+
type: (0, import_utils4.normalizeStructTag)(type),
|
|
2088
|
+
stakePoolId,
|
|
2089
|
+
stakeType: (0, import_utils4.normalizeStructTag)(stakeType),
|
|
2090
|
+
staked,
|
|
2091
|
+
index,
|
|
2092
|
+
points,
|
|
2093
|
+
totalPoints
|
|
2094
|
+
});
|
|
2095
|
+
} else if ((0, import_utils4.normalizeStructTag)(type) === stakeMarketCoinTypes.svsui) {
|
|
2096
|
+
stakeAccounts.svsui.push({
|
|
2097
|
+
id,
|
|
2098
|
+
type: (0, import_utils4.normalizeStructTag)(type),
|
|
2099
|
+
stakePoolId,
|
|
2100
|
+
stakeType: (0, import_utils4.normalizeStructTag)(stakeType),
|
|
2101
|
+
staked,
|
|
2102
|
+
index,
|
|
2103
|
+
points,
|
|
2104
|
+
totalPoints
|
|
2105
|
+
});
|
|
2067
2106
|
}
|
|
2068
2107
|
}
|
|
2069
2108
|
}
|
|
@@ -2114,7 +2153,6 @@ var getStakePool = async (query, marketCoinName) => {
|
|
|
2114
2153
|
return stakePool;
|
|
2115
2154
|
};
|
|
2116
2155
|
var getStakeRewardPool = async (query, marketCoinName) => {
|
|
2117
|
-
const spoolPkgId = query.address.get("spool.id");
|
|
2118
2156
|
const poolId = query.address.get(
|
|
2119
2157
|
`spool.pools.${marketCoinName}.rewardPoolId`
|
|
2120
2158
|
);
|
|
@@ -2126,21 +2164,12 @@ var getStakeRewardPool = async (query, marketCoinName) => {
|
|
|
2126
2164
|
showType: true
|
|
2127
2165
|
}
|
|
2128
2166
|
});
|
|
2129
|
-
|
|
2130
|
-
parentId: poolId,
|
|
2131
|
-
name: {
|
|
2132
|
-
type: `${spoolPkgId}::rewards_pool::RewardsPoolFeeKey`,
|
|
2133
|
-
value: { dummy_field: false }
|
|
2134
|
-
}
|
|
2135
|
-
});
|
|
2136
|
-
if (stakeRewardPoolObjectResponse.data && stakeRewardFeeDynamicFieldsResponse.data) {
|
|
2167
|
+
if (stakeRewardPoolObjectResponse.data) {
|
|
2137
2168
|
const stakeRewardPoolObject = stakeRewardPoolObjectResponse.data;
|
|
2138
|
-
const stakeRewardFeeDynamicFieldObject = stakeRewardFeeDynamicFieldsResponse.data;
|
|
2139
2169
|
const id = stakeRewardPoolObject.objectId;
|
|
2140
2170
|
const type = stakeRewardPoolObject.type;
|
|
2141
|
-
if (stakeRewardPoolObject.content &&
|
|
2171
|
+
if (stakeRewardPoolObject.content && "fields" in stakeRewardPoolObject.content) {
|
|
2142
2172
|
const rewardPoolFields = stakeRewardPoolObject.content.fields;
|
|
2143
|
-
const rewardFeeFields = stakeRewardFeeDynamicFieldObject.content.fields.value.fields;
|
|
2144
2173
|
const stakePoolId = String(rewardPoolFields.spool_id);
|
|
2145
2174
|
const ratioNumerator = Number(rewardPoolFields.exchange_rate_numerator);
|
|
2146
2175
|
const ratioDenominator = Number(
|
|
@@ -2148,16 +2177,12 @@ var getStakeRewardPool = async (query, marketCoinName) => {
|
|
|
2148
2177
|
);
|
|
2149
2178
|
const rewards = Number(rewardPoolFields.rewards);
|
|
2150
2179
|
const claimedRewards = Number(rewardPoolFields.claimed_rewards);
|
|
2151
|
-
const feeRateNumerator = Number(rewardFeeFields.fee_rate_numerator);
|
|
2152
|
-
const feeRateDenominator = Number(rewardFeeFields.fee_rate_denominator);
|
|
2153
2180
|
stakeRewardPool = {
|
|
2154
2181
|
id,
|
|
2155
2182
|
type: (0, import_utils4.normalizeStructTag)(type),
|
|
2156
2183
|
stakePoolId,
|
|
2157
2184
|
ratioNumerator,
|
|
2158
2185
|
ratioDenominator,
|
|
2159
|
-
feeRateNumerator,
|
|
2160
|
-
feeRateDenominator,
|
|
2161
2186
|
rewards,
|
|
2162
2187
|
claimedRewards
|
|
2163
2188
|
};
|
|
@@ -2418,6 +2443,9 @@ var getLending = async (query, poolCoinName, ownerAddress, indexer = false, mark
|
|
|
2418
2443
|
);
|
|
2419
2444
|
const suppliedCoin = suppliedAmount.shiftedBy(-1 * coinDecimal);
|
|
2420
2445
|
const suppliedValue = suppliedCoin.multipliedBy(coinPrice ?? 0);
|
|
2446
|
+
const marketCoinPrice = (0, import_bignumber3.default)(coinPrice ?? 0).multipliedBy(
|
|
2447
|
+
marketPool?.conversionRate ?? 1
|
|
2448
|
+
);
|
|
2421
2449
|
const unstakedMarketAmount = (0, import_bignumber3.default)(marketCoinAmount);
|
|
2422
2450
|
const unstakedMarketCoin = unstakedMarketAmount.shiftedBy(-1 * coinDecimal);
|
|
2423
2451
|
const availableSupplyAmount = (0, import_bignumber3.default)(coinAmount);
|
|
@@ -2437,6 +2465,8 @@ var getLending = async (query, poolCoinName, ownerAddress, indexer = false, mark
|
|
|
2437
2465
|
marketCoinType: query.utils.parseMarketCoinType(poolCoinName),
|
|
2438
2466
|
coinDecimal,
|
|
2439
2467
|
coinPrice: coinPrice ?? 0,
|
|
2468
|
+
conversionRate: marketPool?.conversionRate ?? 1,
|
|
2469
|
+
marketCoinPrice: marketCoinPrice.toNumber(),
|
|
2440
2470
|
supplyApr: marketPool?.supplyApr ?? 0,
|
|
2441
2471
|
supplyApy: marketPool?.supplyApy ?? 0,
|
|
2442
2472
|
rewardApr: spool?.rewardApr ?? 0,
|
|
@@ -4461,14 +4491,14 @@ var ScallopBuilder = class {
|
|
|
4461
4491
|
/**
|
|
4462
4492
|
* Request the scallop API to initialize data.
|
|
4463
4493
|
*
|
|
4464
|
-
* @param
|
|
4494
|
+
* @param force - Whether to force initialization.
|
|
4465
4495
|
*/
|
|
4466
|
-
async init(
|
|
4467
|
-
if (
|
|
4496
|
+
async init(force = false) {
|
|
4497
|
+
if (force || !this.address.getAddresses()) {
|
|
4468
4498
|
await this.address.read();
|
|
4469
4499
|
}
|
|
4470
|
-
await this.query.init(
|
|
4471
|
-
await this.utils.init(
|
|
4500
|
+
await this.query.init(force);
|
|
4501
|
+
await this.utils.init(force);
|
|
4472
4502
|
}
|
|
4473
4503
|
/**
|
|
4474
4504
|
* Create a scallop txBlock instance that enhances transaction block.
|