@scallop-io/sui-scallop-sdk 1.3.41 → 1.4.1-alpha.1
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 +3 -3
- package/dist/constants/enum.d.ts +2 -2
- package/dist/constants/tokenBucket.d.ts +1 -1
- package/dist/index.js +412 -334
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +411 -333
- package/dist/index.mjs.map +1 -1
- package/dist/models/scallopClient.d.ts +4 -4
- package/dist/models/scallopQuery.d.ts +74 -20
- package/dist/models/scallopUtils.d.ts +11 -11
- package/dist/queries/borrowIncentiveQuery.d.ts +2 -2
- package/dist/queries/coreQuery.d.ts +0 -2
- package/dist/queries/portfolioQuery.d.ts +0 -2
- package/dist/queries/priceQuery.d.ts +32 -2
- package/dist/queries/sCoinQuery.d.ts +1 -1
- package/dist/test.d.ts +0 -0
- package/dist/types/builder/borrowIncentive.d.ts +6 -6
- package/dist/types/constant/common.d.ts +1 -1
- package/dist/types/utils.d.ts +2 -6
- package/package.json +1 -1
- package/src/builders/borrowIncentiveBuilder.ts +2 -13
- package/src/constants/coinGecko.ts +3 -2
- package/src/constants/common.ts +10 -5
- package/src/constants/enum.ts +44 -34
- package/src/constants/poolAddress.ts +9 -8
- package/src/constants/pyth.ts +3 -2
- package/src/constants/tokenBucket.ts +1 -1
- package/src/models/scallopClient.ts +27 -10
- package/src/models/scallopQuery.ts +55 -31
- package/src/models/scallopUtils.ts +23 -18
- package/src/queries/borrowIncentiveQuery.ts +29 -12
- package/src/queries/borrowLimitQuery.ts +3 -2
- package/src/queries/coreQuery.ts +185 -196
- package/src/queries/isolatedAssetQuery.ts +3 -2
- package/src/queries/portfolioQuery.ts +81 -77
- package/src/queries/priceQuery.ts +35 -2
- package/src/queries/sCoinQuery.ts +3 -3
- package/src/queries/spoolQuery.ts +4 -6
- package/src/queries/supplyLimitQuery.ts +3 -2
- package/src/test.ts +20 -0
- package/src/types/builder/borrowIncentive.ts +10 -15
- package/src/types/constant/common.ts +1 -2
- package/src/types/utils.ts +2 -10
- package/src/utils/indexer.ts +9 -3
- package/src/utils/query.ts +0 -87
- package/src/utils/tokenBucket.ts +2 -2
package/src/constants/enum.ts
CHANGED
|
@@ -16,8 +16,9 @@ export const coinDecimals: types.SupportCoinDecimals = {
|
|
|
16
16
|
hasui: 9,
|
|
17
17
|
vsui: 9,
|
|
18
18
|
sca: 9,
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
// TODO: enable for production
|
|
20
|
+
// deep: 6,
|
|
21
|
+
// fud: 5,
|
|
21
22
|
susdc: 6,
|
|
22
23
|
sweth: 8,
|
|
23
24
|
ssbeth: 8,
|
|
@@ -32,8 +33,9 @@ export const coinDecimals: types.SupportCoinDecimals = {
|
|
|
32
33
|
shasui: 9,
|
|
33
34
|
svsui: 9,
|
|
34
35
|
ssca: 9,
|
|
35
|
-
|
|
36
|
-
|
|
36
|
+
// TODO: enable for production
|
|
37
|
+
// sdeep: 6,
|
|
38
|
+
// sfud: 5,
|
|
37
39
|
};
|
|
38
40
|
|
|
39
41
|
export const assetCoins: types.AssetCoins = {
|
|
@@ -51,8 +53,9 @@ export const assetCoins: types.AssetCoins = {
|
|
|
51
53
|
hasui: 'hasui',
|
|
52
54
|
vsui: 'vsui',
|
|
53
55
|
sca: 'sca',
|
|
54
|
-
|
|
55
|
-
|
|
56
|
+
// TODO: enable for production
|
|
57
|
+
// deep: 'deep',
|
|
58
|
+
// fud: 'fud',
|
|
56
59
|
};
|
|
57
60
|
|
|
58
61
|
export const marketCoins: types.MarketCoins = {
|
|
@@ -70,8 +73,9 @@ export const marketCoins: types.MarketCoins = {
|
|
|
70
73
|
shasui: 'shasui',
|
|
71
74
|
svsui: 'svsui',
|
|
72
75
|
ssca: 'ssca',
|
|
73
|
-
|
|
74
|
-
|
|
76
|
+
// TODO: enable for production
|
|
77
|
+
// sdeep: 'sdeep',
|
|
78
|
+
// sfud: 'sfud',
|
|
75
79
|
};
|
|
76
80
|
|
|
77
81
|
export const sCoins: types.SCoins = {
|
|
@@ -88,8 +92,9 @@ export const sCoins: types.SCoins = {
|
|
|
88
92
|
ssca: 'ssca',
|
|
89
93
|
swsol: 'swsol',
|
|
90
94
|
swbtc: 'swbtc',
|
|
91
|
-
|
|
92
|
-
|
|
95
|
+
// TODO: enable for production
|
|
96
|
+
// sfud: 'sfud',
|
|
97
|
+
// sdeep: 'sdeep',
|
|
93
98
|
};
|
|
94
99
|
|
|
95
100
|
export const stakeMarketCoins: types.StakeMarketCoins = {
|
|
@@ -120,19 +125,6 @@ export const suiBridgeCoins: types.SuiBridgeCoins = {
|
|
|
120
125
|
sbeth: 'sbeth',
|
|
121
126
|
};
|
|
122
127
|
|
|
123
|
-
export const borrowIncentiveRewardCoins: types.BorrowIncentiveRewardCoins = {
|
|
124
|
-
usdc: ['sui', 'sca'],
|
|
125
|
-
sui: ['sui', 'sca'],
|
|
126
|
-
wusdc: ['sui', 'sca'],
|
|
127
|
-
wusdt: ['sui', 'sca'],
|
|
128
|
-
sca: ['sui', 'sca'],
|
|
129
|
-
afsui: ['sui'],
|
|
130
|
-
hasui: ['sui'],
|
|
131
|
-
vsui: ['sui'],
|
|
132
|
-
weth: ['sui'],
|
|
133
|
-
sbeth: ['sui'],
|
|
134
|
-
};
|
|
135
|
-
|
|
136
128
|
export const coinIds: types.AssetCoinIds = {
|
|
137
129
|
usdc: '0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7',
|
|
138
130
|
sui: '0x0000000000000000000000000000000000000000000000000000000000000002',
|
|
@@ -151,8 +143,8 @@ export const coinIds: types.AssetCoinIds = {
|
|
|
151
143
|
? '0x6cd813061a3adf3602b76545f076205f0c8e7ec1d3b1eab9a1da7992c18c0524'
|
|
152
144
|
: '0x7016aae72cfc67f2fadf55769c0a7dd54291a583b63051a5ed71081cce836ac6',
|
|
153
145
|
// isolated assets
|
|
154
|
-
deep: '0xdeeb7a4662eec9f2f3def03fb937a663dddaa2e215b8078a284d026b7946c270',
|
|
155
|
-
fud: '0x76cb819b01abed502bee8a702b4c2d547532c12f25001c9dea795a5e631c26f1',
|
|
146
|
+
// deep: '0xdeeb7a4662eec9f2f3def03fb937a663dddaa2e215b8078a284d026b7946c270',
|
|
147
|
+
// fud: '0x76cb819b01abed502bee8a702b4c2d547532c12f25001c9dea795a5e631c26f1',
|
|
156
148
|
};
|
|
157
149
|
|
|
158
150
|
export const wormholeCoinIds: types.WormholeCoinIds = {
|
|
@@ -174,14 +166,24 @@ export const sCoinIds: types.SCoinIds = {
|
|
|
174
166
|
'0x854950aa624b1df59fe64e630b2ba7c550642e9342267a33061d59fb31582da5::scallop_usdc::SCALLOP_USDC',
|
|
175
167
|
ssbeth:
|
|
176
168
|
'0xb14f82d8506d139eacef109688d1b71e7236bcce9b2c0ad526abcd6aa5be7de0::scallop_sb_eth::SCALLOP_SB_ETH',
|
|
177
|
-
|
|
169
|
+
// prod values
|
|
170
|
+
// ssui: '0xaafc4f740de0dd0dde642a31148fb94517087052f19afb0f7bed1dc41a50c77b::scallop_sui::SCALLOP_SUI',
|
|
171
|
+
// swusdc:
|
|
172
|
+
// '0xad4d71551d31092230db1fd482008ea42867dbf27b286e9c70a79d2a6191d58d::scallop_wormhole_usdc::SCALLOP_WORMHOLE_USDC',
|
|
173
|
+
// swusdt:
|
|
174
|
+
// '0xe6e5a012ec20a49a3d1d57bd2b67140b96cd4d3400b9d79e541f7bdbab661f95::scallop_wormhole_usdt::SCALLOP_WORMHOLE_USDT',
|
|
175
|
+
// ssca: '0x5ca17430c1d046fae9edeaa8fd76c7b4193a00d764a0ecfa9418d733ad27bc1e::scallop_sca::SCALLOP_SCA',
|
|
176
|
+
|
|
177
|
+
// test values
|
|
178
|
+
ssui: '0xf569919046f19a0c40b519ecfbb6ca0319698cd5908716c29b62ef56541f298b::scallop_sui::SCALLOP_SUI',
|
|
179
|
+
swusdt:
|
|
180
|
+
'0xac781d9f73058ff5e69f9bf8dde32f2e8c71c66d7fe8497fc83b2d9182254b22::scallop_wormhole_usdt::SCALLOP_WORMHOLE_USDT',
|
|
181
|
+
swusdc:
|
|
182
|
+
'0xf5447c4305a486d8c8557559887c2c39449ddb5e748f15d33946d02a1663c158::scallop_wormhole_usdc::SCALLOP_WORMHOLE_USDC',
|
|
183
|
+
ssca: '0x958428555e778e55918a59eb1c92c77f32b5c554fa3a5e56cd0815086b5072e7::scallop_sca::SCALLOP_SCA',
|
|
184
|
+
|
|
178
185
|
scetus:
|
|
179
186
|
'0xea346ce428f91ab007210443efcea5f5cdbbb3aae7e9affc0ca93f9203c31f0c::scallop_cetus::SCALLOP_CETUS',
|
|
180
|
-
ssca: '0x5ca17430c1d046fae9edeaa8fd76c7b4193a00d764a0ecfa9418d733ad27bc1e::scallop_sca::SCALLOP_SCA',
|
|
181
|
-
swusdc:
|
|
182
|
-
'0xad4d71551d31092230db1fd482008ea42867dbf27b286e9c70a79d2a6191d58d::scallop_wormhole_usdc::SCALLOP_WORMHOLE_USDC',
|
|
183
|
-
swusdt:
|
|
184
|
-
'0xe6e5a012ec20a49a3d1d57bd2b67140b96cd4d3400b9d79e541f7bdbab661f95::scallop_wormhole_usdt::SCALLOP_WORMHOLE_USDT',
|
|
185
187
|
sweth:
|
|
186
188
|
'0x67540ceb850d418679e69f1fb6b2093d6df78a2a699ffc733f7646096d552e9b::scallop_wormhole_eth::SCALLOP_WORMHOLE_ETH',
|
|
187
189
|
safsui:
|
|
@@ -194,9 +196,9 @@ export const sCoinIds: types.SCoinIds = {
|
|
|
194
196
|
'0x1392650f2eca9e3f6ffae3ff89e42a3590d7102b80e2b430f674730bc30d3259::scallop_wormhole_sol::SCALLOP_WORMHOLE_SOL',
|
|
195
197
|
swbtc:
|
|
196
198
|
'0x2cf76a9cf5d3337961d1154283234f94da2dcff18544dfe5cbdef65f319591b5::scallop_wormhole_btc::SCALLOP_WORMHOLE_BTC',
|
|
197
|
-
sdeep:
|
|
198
|
-
|
|
199
|
-
sfud: '0xe56d5167f427cbe597da9e8150ef5c337839aaf46891d62468dcf80bdd8e10d1::scallop_fud::SCALLOP_FUD',
|
|
199
|
+
// sdeep:
|
|
200
|
+
// '0xeb7a05a3224837c5e5503575aed0be73c091d1ce5e43aa3c3e716e0ae614608f::scallop_deep::SCALLOP_DEEP',
|
|
201
|
+
// sfud: '0xe56d5167f427cbe597da9e8150ef5c337839aaf46891d62468dcf80bdd8e10d1::scallop_fud::SCALLOP_FUD',
|
|
200
202
|
} as const;
|
|
201
203
|
|
|
202
204
|
export const sCoinTypeToName = Object.entries(sCoinIds).reduce(
|
|
@@ -207,6 +209,14 @@ export const sCoinTypeToName = Object.entries(sCoinIds).reduce(
|
|
|
207
209
|
{} as Record<string, types.SupportSCoin>
|
|
208
210
|
);
|
|
209
211
|
|
|
212
|
+
export const sCoinRawNameToName = Object.entries(sCoinIds).reduce(
|
|
213
|
+
(acc, [coinName, coinType]) => {
|
|
214
|
+
acc[coinType.split('::')[2].toLowerCase()] = coinName as types.SupportSCoin;
|
|
215
|
+
return acc;
|
|
216
|
+
},
|
|
217
|
+
{} as Record<string, types.SupportSCoin>
|
|
218
|
+
);
|
|
219
|
+
|
|
210
220
|
// TEST VERSION
|
|
211
221
|
// export const sCoinIds: types.SCoinIds = {
|
|
212
222
|
// ssui: '0xf569919046f19a0c40b519ecfbb6ca0319698cd5908716c29b62ef56541f298b::scallop_sui::SCALLOP_SUI',
|
|
@@ -91,12 +91,13 @@ export const POOL_ADDRESSES: Record<
|
|
|
91
91
|
collateralPoolAddress:
|
|
92
92
|
'0xff677a5d9e9dc8f08f0a8681ebfc7481d1c7d57bc441f2881974adcdd7b13c31',
|
|
93
93
|
},
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
94
|
+
// TODO: enable for production
|
|
95
|
+
// fud: {
|
|
96
|
+
// lendingPoolAddress:
|
|
97
|
+
// '0x14367ddca30e2860cb89ed4eaca20c7ece260c5d59dd9990d2c85a8321326acb',
|
|
98
|
+
// },
|
|
99
|
+
// deep: {
|
|
100
|
+
// lendingPoolAddress:
|
|
101
|
+
// '0xf4a67ffb43da1e1c61c049f188f19463ea8dbbf2d5ef4722d6df854ff1b1cc03',
|
|
102
|
+
// },
|
|
102
103
|
};
|
package/src/constants/pyth.ts
CHANGED
|
@@ -22,6 +22,7 @@ export const PYTH_FEED_IDS: Record<SupportPoolCoins, string> = {
|
|
|
22
22
|
hasui: '23d7315113f5b1d3ba7a83604c44b94d79f4fd69af77f804fc7f920a6dc65744',
|
|
23
23
|
vsui: '23d7315113f5b1d3ba7a83604c44b94d79f4fd69af77f804fc7f920a6dc65744',
|
|
24
24
|
sca: '7e17f0ac105abe9214deb9944c30264f5986bf292869c6bd8e8da3ccd92d79bc',
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
// TODO: enable for production
|
|
26
|
+
// deep: '29bdd5248234e33bd93d3b81100b5fa32eaa5997843847e2c2cb16d7c6d9f7ff',
|
|
27
|
+
// fud: '6a4090703da959247727f2b490eb21aea95c8684ecfac675f432008830890c75',
|
|
27
28
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export const DEFAULT_TOKENS_PER_INTERVAL = 50;
|
|
2
|
-
export const DEFAULT_INTERVAL_IN_MS =
|
|
2
|
+
export const DEFAULT_INTERVAL_IN_MS = 100;
|
|
@@ -4,7 +4,6 @@ import { DEFAULT_CACHE_OPTIONS } from 'src/constants/cache';
|
|
|
4
4
|
import {
|
|
5
5
|
ADDRESSES_ID,
|
|
6
6
|
SUPPORT_BORROW_INCENTIVE_POOLS,
|
|
7
|
-
SUPPORT_BORROW_INCENTIVE_REWARDS,
|
|
8
7
|
SUPPORT_SCOIN,
|
|
9
8
|
SUPPORT_SPOOLS,
|
|
10
9
|
} from '../constants';
|
|
@@ -28,7 +27,6 @@ import type {
|
|
|
28
27
|
SupportAssetCoins,
|
|
29
28
|
SupportStakeCoins,
|
|
30
29
|
SupportStakeMarketCoins,
|
|
31
|
-
SupportBorrowIncentiveCoins,
|
|
32
30
|
ScallopTxBlock,
|
|
33
31
|
SupportSCoin,
|
|
34
32
|
ScallopClientVeScaReturnType,
|
|
@@ -945,9 +943,9 @@ export class ScallopClient {
|
|
|
945
943
|
}
|
|
946
944
|
|
|
947
945
|
/**
|
|
948
|
-
*
|
|
946
|
+
* Claim borrow incentive reward.
|
|
949
947
|
*
|
|
950
|
-
* @param
|
|
948
|
+
* @param poolName
|
|
951
949
|
* @param amount - The amount of coins would deposit.
|
|
952
950
|
* @param sign - Decide to directly sign the transaction or return the transaction block.
|
|
953
951
|
* @param accountId - The stake account object.
|
|
@@ -955,7 +953,6 @@ export class ScallopClient {
|
|
|
955
953
|
* @return Transaction block response or transaction block
|
|
956
954
|
*/
|
|
957
955
|
public async claimBorrowIncentive<S extends boolean>(
|
|
958
|
-
coinName: SupportBorrowIncentiveCoins,
|
|
959
956
|
obligationId: string,
|
|
960
957
|
obligationKeyId: string,
|
|
961
958
|
sign: S = true as S,
|
|
@@ -965,17 +962,37 @@ export class ScallopClient {
|
|
|
965
962
|
const sender = walletAddress ?? this.walletAddress;
|
|
966
963
|
txBlock.setSender(sender);
|
|
967
964
|
|
|
968
|
-
const
|
|
969
|
-
|
|
965
|
+
const rewardCoinsCollection: Record<string, TransactionResult[]> = {};
|
|
966
|
+
const obligationAccount =
|
|
967
|
+
await this.query.getObligationAccount(obligationId);
|
|
968
|
+
const rewardCoinNames = Object.values(obligationAccount.borrowIncentives)
|
|
969
|
+
.flatMap(({ rewards }) =>
|
|
970
|
+
rewards.filter(({ availableClaimAmount }) => availableClaimAmount > 0)
|
|
971
|
+
)
|
|
972
|
+
.flatMap(({ coinName }) => coinName);
|
|
973
|
+
for (const rewardCoinName of rewardCoinNames) {
|
|
970
974
|
const rewardCoin = await txBlock.claimBorrowIncentiveQuick(
|
|
971
|
-
coinName,
|
|
972
975
|
rewardCoinName,
|
|
973
976
|
obligationId,
|
|
974
977
|
obligationKeyId
|
|
975
978
|
);
|
|
976
|
-
|
|
979
|
+
if (!rewardCoinsCollection[rewardCoinName]) {
|
|
980
|
+
rewardCoinsCollection[rewardCoinName] = [rewardCoin];
|
|
981
|
+
} else {
|
|
982
|
+
rewardCoinsCollection[rewardCoinName].push(rewardCoin);
|
|
983
|
+
}
|
|
977
984
|
}
|
|
978
|
-
|
|
985
|
+
|
|
986
|
+
txBlock.transferObjects(
|
|
987
|
+
Object.values(rewardCoinsCollection).map((rewardCoins) => {
|
|
988
|
+
const mergeDest = rewardCoins[0];
|
|
989
|
+
if (rewardCoins.length > 1) {
|
|
990
|
+
txBlock.mergeCoins(mergeDest, rewardCoins.slice(1));
|
|
991
|
+
}
|
|
992
|
+
return mergeDest;
|
|
993
|
+
}),
|
|
994
|
+
sender
|
|
995
|
+
);
|
|
979
996
|
|
|
980
997
|
if (sign) {
|
|
981
998
|
return (await this.suiKit.signAndSendTxn(
|
|
@@ -47,6 +47,7 @@ import {
|
|
|
47
47
|
getSCoinAmounts,
|
|
48
48
|
getSCoinSwapRate,
|
|
49
49
|
getSCoinTotalSupply,
|
|
50
|
+
getAllCoinPrices,
|
|
50
51
|
} from '../queries';
|
|
51
52
|
import {
|
|
52
53
|
ScallopQueryParams,
|
|
@@ -191,11 +192,11 @@ export class ScallopQuery {
|
|
|
191
192
|
* @param indexer - Whether to use indexer.
|
|
192
193
|
* @return Market data.
|
|
193
194
|
*/
|
|
194
|
-
public async queryMarket(
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
) {
|
|
198
|
-
return await queryMarket(this, indexer, args?.coinPrices);
|
|
195
|
+
public async queryMarket(args?: {
|
|
196
|
+
coinPrices?: CoinPrices;
|
|
197
|
+
indexer?: boolean;
|
|
198
|
+
}) {
|
|
199
|
+
return await queryMarket(this, args?.indexer, args?.coinPrices);
|
|
199
200
|
}
|
|
200
201
|
|
|
201
202
|
/**
|
|
@@ -211,12 +212,17 @@ export class ScallopQuery {
|
|
|
211
212
|
*/
|
|
212
213
|
public async getMarketPools(
|
|
213
214
|
poolCoinNames?: SupportPoolCoins[],
|
|
214
|
-
indexer: boolean = false,
|
|
215
215
|
args?: {
|
|
216
216
|
coinPrices?: CoinPrices;
|
|
217
|
+
indexer?: boolean;
|
|
217
218
|
}
|
|
218
219
|
) {
|
|
219
|
-
return await getMarketPools(
|
|
220
|
+
return await getMarketPools(
|
|
221
|
+
this,
|
|
222
|
+
poolCoinNames,
|
|
223
|
+
args?.indexer,
|
|
224
|
+
args?.coinPrices
|
|
225
|
+
);
|
|
220
226
|
}
|
|
221
227
|
|
|
222
228
|
/**
|
|
@@ -228,16 +234,16 @@ export class ScallopQuery {
|
|
|
228
234
|
*/
|
|
229
235
|
public async getMarketPool(
|
|
230
236
|
poolCoinName: SupportPoolCoins,
|
|
231
|
-
indexer: boolean = false,
|
|
232
237
|
args?: {
|
|
233
238
|
marketObject?: SuiObjectData | null;
|
|
234
239
|
coinPrice?: number;
|
|
240
|
+
indexer?: boolean;
|
|
235
241
|
}
|
|
236
242
|
) {
|
|
237
243
|
return await getMarketPool(
|
|
238
244
|
this,
|
|
239
245
|
poolCoinName,
|
|
240
|
-
indexer,
|
|
246
|
+
args?.indexer,
|
|
241
247
|
args?.marketObject,
|
|
242
248
|
args?.coinPrice
|
|
243
249
|
);
|
|
@@ -256,9 +262,9 @@ export class ScallopQuery {
|
|
|
256
262
|
*/
|
|
257
263
|
public async getMarketCollaterals(
|
|
258
264
|
collateralCoinNames?: SupportCollateralCoins[],
|
|
259
|
-
indexer
|
|
265
|
+
args?: { indexer?: boolean }
|
|
260
266
|
) {
|
|
261
|
-
return await getMarketCollaterals(this, collateralCoinNames, indexer);
|
|
267
|
+
return await getMarketCollaterals(this, collateralCoinNames, args?.indexer);
|
|
262
268
|
}
|
|
263
269
|
|
|
264
270
|
/**
|
|
@@ -270,9 +276,9 @@ export class ScallopQuery {
|
|
|
270
276
|
*/
|
|
271
277
|
public async getMarketCollateral(
|
|
272
278
|
collateralCoinName: SupportCollateralCoins,
|
|
273
|
-
indexer
|
|
279
|
+
args?: { indexer?: boolean }
|
|
274
280
|
) {
|
|
275
|
-
return await getMarketCollateral(this, collateralCoinName, indexer);
|
|
281
|
+
return await getMarketCollateral(this, collateralCoinName, args?.indexer);
|
|
276
282
|
}
|
|
277
283
|
|
|
278
284
|
/**
|
|
@@ -382,16 +388,16 @@ export class ScallopQuery {
|
|
|
382
388
|
*/
|
|
383
389
|
public async getSpools(
|
|
384
390
|
stakeMarketCoinNames?: SupportStakeMarketCoins[],
|
|
385
|
-
indexer: boolean = false,
|
|
386
391
|
args?: {
|
|
387
392
|
marketPools?: MarketPools;
|
|
388
393
|
coinPrices?: CoinPrices;
|
|
394
|
+
indexer?: boolean;
|
|
389
395
|
}
|
|
390
396
|
) {
|
|
391
397
|
return await getSpools(
|
|
392
398
|
this,
|
|
393
399
|
stakeMarketCoinNames,
|
|
394
|
-
indexer,
|
|
400
|
+
args?.indexer,
|
|
395
401
|
args?.marketPools,
|
|
396
402
|
args?.coinPrices
|
|
397
403
|
);
|
|
@@ -406,13 +412,16 @@ export class ScallopQuery {
|
|
|
406
412
|
*/
|
|
407
413
|
public async getSpool(
|
|
408
414
|
stakeMarketCoinName: SupportStakeMarketCoins,
|
|
409
|
-
|
|
410
|
-
|
|
415
|
+
args?: {
|
|
416
|
+
marketPool?: MarketPool;
|
|
417
|
+
coinPrices?: CoinPrices;
|
|
418
|
+
indexer?: boolean;
|
|
419
|
+
}
|
|
411
420
|
) {
|
|
412
421
|
return await getSpool(
|
|
413
422
|
this,
|
|
414
423
|
stakeMarketCoinName,
|
|
415
|
-
indexer,
|
|
424
|
+
args?.indexer,
|
|
416
425
|
args?.marketPool,
|
|
417
426
|
args?.coinPrices
|
|
418
427
|
);
|
|
@@ -536,13 +545,17 @@ export class ScallopQuery {
|
|
|
536
545
|
*/
|
|
537
546
|
public async getBorrowIncentivePools(
|
|
538
547
|
coinNames?: SupportBorrowIncentiveCoins[],
|
|
539
|
-
|
|
540
|
-
|
|
548
|
+
args?: {
|
|
549
|
+
coinPrices: CoinPrices;
|
|
550
|
+
indexer?: boolean;
|
|
551
|
+
marketPools?: MarketPools;
|
|
552
|
+
}
|
|
541
553
|
) {
|
|
542
554
|
return await getBorrowIncentivePools(
|
|
543
555
|
this,
|
|
544
556
|
coinNames,
|
|
545
|
-
indexer,
|
|
557
|
+
args?.indexer,
|
|
558
|
+
args?.marketPools,
|
|
546
559
|
args?.coinPrices
|
|
547
560
|
);
|
|
548
561
|
}
|
|
@@ -572,9 +585,9 @@ export class ScallopQuery {
|
|
|
572
585
|
public async getLendings(
|
|
573
586
|
poolCoinNames?: SupportPoolCoins[],
|
|
574
587
|
ownerAddress: string = this.walletAddress,
|
|
575
|
-
indexer
|
|
588
|
+
args?: { indexer?: boolean }
|
|
576
589
|
) {
|
|
577
|
-
return await getLendings(this, poolCoinNames, ownerAddress, indexer);
|
|
590
|
+
return await getLendings(this, poolCoinNames, ownerAddress, args?.indexer);
|
|
578
591
|
}
|
|
579
592
|
|
|
580
593
|
/**
|
|
@@ -588,9 +601,9 @@ export class ScallopQuery {
|
|
|
588
601
|
public async getLending(
|
|
589
602
|
poolCoinName: SupportPoolCoins,
|
|
590
603
|
ownerAddress: string = this.walletAddress,
|
|
591
|
-
indexer
|
|
604
|
+
args?: { indexer?: boolean }
|
|
592
605
|
) {
|
|
593
|
-
return await getLending(this, poolCoinName, ownerAddress, indexer);
|
|
606
|
+
return await getLending(this, poolCoinName, ownerAddress, args?.indexer);
|
|
594
607
|
}
|
|
595
608
|
|
|
596
609
|
/**
|
|
@@ -605,9 +618,9 @@ export class ScallopQuery {
|
|
|
605
618
|
*/
|
|
606
619
|
public async getObligationAccounts(
|
|
607
620
|
ownerAddress: string = this.walletAddress,
|
|
608
|
-
indexer: boolean
|
|
621
|
+
args?: { indexer: boolean }
|
|
609
622
|
) {
|
|
610
|
-
return await getObligationAccounts(this, ownerAddress, indexer);
|
|
623
|
+
return await getObligationAccounts(this, ownerAddress, args?.indexer);
|
|
611
624
|
}
|
|
612
625
|
|
|
613
626
|
/**
|
|
@@ -624,13 +637,13 @@ export class ScallopQuery {
|
|
|
624
637
|
public async getObligationAccount(
|
|
625
638
|
obligationId: string,
|
|
626
639
|
ownerAddress: string = this.walletAddress,
|
|
627
|
-
indexer
|
|
640
|
+
args?: { indexer?: boolean }
|
|
628
641
|
) {
|
|
629
642
|
return await getObligationAccount(
|
|
630
643
|
this,
|
|
631
644
|
obligationId,
|
|
632
645
|
ownerAddress,
|
|
633
|
-
indexer
|
|
646
|
+
args?.indexer
|
|
634
647
|
);
|
|
635
648
|
}
|
|
636
649
|
|
|
@@ -643,8 +656,8 @@ export class ScallopQuery {
|
|
|
643
656
|
*
|
|
644
657
|
* @return Total value locked.
|
|
645
658
|
*/
|
|
646
|
-
public async getTvl(indexer
|
|
647
|
-
return await getTotalValueLocked(this, indexer);
|
|
659
|
+
public async getTvl(args?: { indexer?: boolean }) {
|
|
660
|
+
return await getTotalValueLocked(this, args?.indexer);
|
|
648
661
|
}
|
|
649
662
|
|
|
650
663
|
/**
|
|
@@ -817,4 +830,15 @@ export class ScallopQuery {
|
|
|
817
830
|
public async getCoinPriceByIndexer(poolName: SupportPoolCoins) {
|
|
818
831
|
return this.indexer.getCoinPrice(poolName);
|
|
819
832
|
}
|
|
833
|
+
|
|
834
|
+
/**
|
|
835
|
+
* Get all coin prices, including sCoin
|
|
836
|
+
* @returns prices data
|
|
837
|
+
*/
|
|
838
|
+
public async getAllCoinPrices(args?: {
|
|
839
|
+
marketPools?: MarketPools;
|
|
840
|
+
coinPrices?: CoinPrices;
|
|
841
|
+
}) {
|
|
842
|
+
return getAllCoinPrices(this, args?.marketPools, args?.coinPrices);
|
|
843
|
+
}
|
|
820
844
|
}
|
|
@@ -8,7 +8,6 @@ import {
|
|
|
8
8
|
SUPPORT_POOLS,
|
|
9
9
|
SUPPORT_COLLATERALS,
|
|
10
10
|
spoolRewardCoins,
|
|
11
|
-
borrowIncentiveRewardCoins,
|
|
12
11
|
coinDecimals,
|
|
13
12
|
wormholeCoinIds,
|
|
14
13
|
voloCoinIds,
|
|
@@ -21,6 +20,7 @@ import {
|
|
|
21
20
|
COIN_GECKGO_IDS,
|
|
22
21
|
POOL_ADDRESSES,
|
|
23
22
|
sCoinTypeToName,
|
|
23
|
+
sCoinRawNameToName,
|
|
24
24
|
} from '../constants';
|
|
25
25
|
import { getPythPrices, queryObligation } from '../queries';
|
|
26
26
|
import {
|
|
@@ -40,7 +40,6 @@ import type {
|
|
|
40
40
|
SupportAssetCoins,
|
|
41
41
|
SupportMarketCoins,
|
|
42
42
|
SupportStakeMarketCoins,
|
|
43
|
-
SupportBorrowIncentiveCoins,
|
|
44
43
|
CoinPrices,
|
|
45
44
|
CoinWrappedType,
|
|
46
45
|
SupportSCoin,
|
|
@@ -157,7 +156,14 @@ export class ScallopUtils {
|
|
|
157
156
|
* @param coinName - Specific support coin name.
|
|
158
157
|
* @return Coin type.
|
|
159
158
|
*/
|
|
160
|
-
public parseCoinType(
|
|
159
|
+
public parseCoinType(
|
|
160
|
+
coinName: SupportCoins,
|
|
161
|
+
useOldMarketCoin: boolean = false
|
|
162
|
+
) {
|
|
163
|
+
// try parse scoin first
|
|
164
|
+
if (sCoinIds[coinName as SupportSCoin] && !useOldMarketCoin) {
|
|
165
|
+
return sCoinIds[coinName as SupportSCoin];
|
|
166
|
+
}
|
|
161
167
|
coinName = isMarketCoin(coinName) ? this.parseCoinName(coinName) : coinName;
|
|
162
168
|
const coinPackageId =
|
|
163
169
|
this.address.get(`core.coins.${coinName}.id`) ||
|
|
@@ -225,6 +231,16 @@ export class ScallopUtils {
|
|
|
225
231
|
}
|
|
226
232
|
}
|
|
227
233
|
|
|
234
|
+
/**
|
|
235
|
+
* Convert sCoin name to coin name.
|
|
236
|
+
* This function will parse new sCoin name `scallop_...` to its old market coin name which is shorter
|
|
237
|
+
* e.g: `scallop_sui -> ssui
|
|
238
|
+
* @return sCoin name
|
|
239
|
+
*/
|
|
240
|
+
public parseCoinNameFromSCoinName(coinName: string) {
|
|
241
|
+
return sCoinRawNameToName[coinName];
|
|
242
|
+
}
|
|
243
|
+
|
|
228
244
|
/**
|
|
229
245
|
* Convert sCoin name into sCoin type
|
|
230
246
|
* @param sCoinName
|
|
@@ -272,7 +288,7 @@ export class ScallopUtils {
|
|
|
272
288
|
public parseMarketCoinType(coinName: SupportCoins) {
|
|
273
289
|
const protocolObjectId =
|
|
274
290
|
this.address.get('core.object') ?? PROTOCOL_OBJECT_ID;
|
|
275
|
-
const coinType = this.parseCoinType(coinName);
|
|
291
|
+
const coinType = this.parseCoinType(coinName, true);
|
|
276
292
|
return `${protocolObjectId}::reserve::MarketCoin<${coinType}>`;
|
|
277
293
|
}
|
|
278
294
|
|
|
@@ -297,12 +313,13 @@ export class ScallopUtils {
|
|
|
297
313
|
): T extends SupportCoins ? T : SupportCoins;
|
|
298
314
|
public parseCoinNameFromType(coinType: string) {
|
|
299
315
|
coinType = normalizeStructTag(coinType);
|
|
316
|
+
|
|
300
317
|
const coinTypeRegex = new RegExp(`((0x[^:]+::[^:]+::[^<>]+))(?![^<>]*<)`);
|
|
301
318
|
const coinTypeMatch = coinType.match(coinTypeRegex);
|
|
302
319
|
const isMarketCoinType = coinType.includes('reserve::MarketCoin');
|
|
303
320
|
coinType = coinTypeMatch?.[1] ?? coinType;
|
|
304
321
|
|
|
305
|
-
const
|
|
322
|
+
const wormholeCoinTypeMap: Record<string, SupportAssetCoins> = {
|
|
306
323
|
[`${
|
|
307
324
|
this.address.get('core.coins.wusdc.id') ?? wormholeCoinIds.wusdc
|
|
308
325
|
}::coin::COIN`]: 'wusdc',
|
|
@@ -339,7 +356,7 @@ export class ScallopUtils {
|
|
|
339
356
|
);
|
|
340
357
|
|
|
341
358
|
const assetCoinName =
|
|
342
|
-
|
|
359
|
+
wormholeCoinTypeMap[coinType] ||
|
|
343
360
|
voloCoinTypeMap[coinType] ||
|
|
344
361
|
suiBridgeTypeMap[coinType] ||
|
|
345
362
|
(coinType.split('::')[2].toLowerCase() as SupportAssetCoins);
|
|
@@ -383,18 +400,6 @@ export class ScallopUtils {
|
|
|
383
400
|
return spoolRewardCoins[stakeMarketCoinName];
|
|
384
401
|
};
|
|
385
402
|
|
|
386
|
-
/**
|
|
387
|
-
* Get reward type of borrow incentive pool.
|
|
388
|
-
*
|
|
389
|
-
* @param borrowIncentiveCoinName - Support borrow incentive coin.
|
|
390
|
-
* @return Borrow incentive reward coin name.
|
|
391
|
-
*/
|
|
392
|
-
public getBorrowIncentiveRewardCoinName = (
|
|
393
|
-
borrowIncentiveCoinName: SupportBorrowIncentiveCoins
|
|
394
|
-
) => {
|
|
395
|
-
return borrowIncentiveRewardCoins[borrowIncentiveCoinName];
|
|
396
|
-
};
|
|
397
|
-
|
|
398
403
|
/**
|
|
399
404
|
* Get coin decimal.
|
|
400
405
|
*
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { normalizeStructTag } from '@mysten/sui/utils';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
sCoinRawNameToName,
|
|
4
|
+
SUPPORT_BORROW_INCENTIVE_POOLS,
|
|
5
|
+
SUPPORT_BORROW_INCENTIVE_REWARDS,
|
|
6
|
+
} from '../constants';
|
|
3
7
|
import {
|
|
4
8
|
parseOriginBorrowIncentivePoolData,
|
|
5
9
|
parseOriginBorrowIncentiveAccountData,
|
|
@@ -17,6 +21,7 @@ import type {
|
|
|
17
21
|
OptionalKeys,
|
|
18
22
|
BorrowIncentivePool,
|
|
19
23
|
CoinPrices,
|
|
24
|
+
MarketPools,
|
|
20
25
|
} from '../types';
|
|
21
26
|
import BigNumber from 'bignumber.js';
|
|
22
27
|
|
|
@@ -55,11 +60,14 @@ export const getBorrowIncentivePools = async (
|
|
|
55
60
|
...SUPPORT_BORROW_INCENTIVE_POOLS,
|
|
56
61
|
],
|
|
57
62
|
indexer: boolean = false,
|
|
63
|
+
marketPools?: MarketPools,
|
|
58
64
|
coinPrices?: CoinPrices
|
|
59
65
|
) => {
|
|
60
66
|
const borrowIncentivePools: BorrowIncentivePools = {};
|
|
61
|
-
|
|
62
|
-
|
|
67
|
+
marketPools =
|
|
68
|
+
marketPools ??
|
|
69
|
+
(await query.getMarketPools(undefined, { indexer, coinPrices }));
|
|
70
|
+
coinPrices = coinPrices ?? (await query.getAllCoinPrices({ marketPools }));
|
|
63
71
|
|
|
64
72
|
if (indexer) {
|
|
65
73
|
const borrowIncentivePoolsIndexer =
|
|
@@ -67,7 +75,13 @@ export const getBorrowIncentivePools = async (
|
|
|
67
75
|
|
|
68
76
|
const updateBorrowIncentivePool = (pool: BorrowIncentivePool) => {
|
|
69
77
|
if (!borrowIncentiveCoinNames.includes(pool.coinName)) return;
|
|
70
|
-
pool.coinPrice = coinPrices[pool.coinName]
|
|
78
|
+
pool.coinPrice = coinPrices[pool.coinName] || pool.coinPrice;
|
|
79
|
+
for (const sCoinName of SUPPORT_BORROW_INCENTIVE_REWARDS) {
|
|
80
|
+
if (pool.points[sCoinName]) {
|
|
81
|
+
pool.points[sCoinName].coinPrice =
|
|
82
|
+
coinPrices[sCoinName] ?? pool.points[sCoinName].coinPrice;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
71
85
|
borrowIncentivePools[pool.coinName] = pool;
|
|
72
86
|
};
|
|
73
87
|
|
|
@@ -94,7 +108,6 @@ export const getBorrowIncentivePools = async (
|
|
|
94
108
|
query.utils.parseCoinNameFromType<SupportBorrowIncentiveCoins>(
|
|
95
109
|
poolCoinType
|
|
96
110
|
);
|
|
97
|
-
|
|
98
111
|
const poolCoinPrice = coinPrices?.[poolCoinName] ?? 0;
|
|
99
112
|
const poolCoinDecimal = query.utils.getCoinDecimal(poolCoinName);
|
|
100
113
|
|
|
@@ -102,17 +115,21 @@ export const getBorrowIncentivePools = async (
|
|
|
102
115
|
if (!borrowIncentiveCoinNames.includes(poolCoinName)) {
|
|
103
116
|
continue;
|
|
104
117
|
}
|
|
105
|
-
|
|
118
|
+
|
|
119
|
+
// pool points for borrow incentive reward
|
|
106
120
|
for (const [coinName, poolPoint] of Object.entries(
|
|
107
121
|
parsedBorrowIncentivePoolData.poolPoints
|
|
108
122
|
)) {
|
|
109
|
-
const rewardCoinType =
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
123
|
+
const rewardCoinType = poolPoint.pointType;
|
|
124
|
+
let rewardCoinName = query.utils.parseCoinNameFromType(
|
|
125
|
+
rewardCoinType
|
|
126
|
+
) as SupportBorrowIncentiveRewardCoins;
|
|
127
|
+
// handle for scoin name
|
|
128
|
+
if (sCoinRawNameToName[rewardCoinName]) {
|
|
129
|
+
rewardCoinName = sCoinRawNameToName[rewardCoinName];
|
|
130
|
+
}
|
|
115
131
|
const rewardCoinDecimal = query.utils.getCoinDecimal(rewardCoinName);
|
|
132
|
+
const rewardCoinPrice = coinPrices?.[rewardCoinName] ?? 0;
|
|
116
133
|
|
|
117
134
|
const symbol = query.utils.parseSymbol(rewardCoinName);
|
|
118
135
|
const coinDecimal = query.utils.getCoinDecimal(rewardCoinName);
|