@scallop-io/sui-scallop-sdk 1.5.3 → 2.0.0-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/index.d.mts +446 -599
- package/dist/index.d.ts +446 -599
- package/dist/index.js +29 -60
- package/dist/index.mjs +6 -6
- package/package.json +1 -1
- package/src/builders/loyaltyProgramBuilder.ts +5 -3
- package/src/builders/oracle.ts +10 -24
- package/src/builders/referralBuilder.ts +5 -9
- package/src/builders/sCoinBuilder.ts +9 -8
- package/src/builders/spoolBuilder.ts +4 -6
- package/src/constants/common.ts +114 -126
- package/src/constants/index.ts +0 -5
- package/src/constants/pyth.ts +25 -34
- package/src/constants/queryKeys.ts +2 -0
- package/src/models/index.ts +1 -0
- package/src/models/scallop.ts +23 -19
- package/src/models/scallopAddress.ts +7 -4
- package/src/models/scallopBuilder.ts +32 -35
- package/src/models/scallopCache.ts +1 -1
- package/src/models/scallopClient.ts +87 -89
- package/src/models/scallopConstants.ts +341 -0
- package/src/models/scallopIndexer.ts +11 -24
- package/src/models/scallopQuery.ts +65 -70
- package/src/models/scallopUtils.ts +114 -244
- package/src/queries/borrowIncentiveQuery.ts +21 -56
- package/src/queries/borrowLimitQuery.ts +3 -6
- package/src/queries/coreQuery.ts +94 -112
- package/src/queries/flashloanFeeQuery.ts +86 -0
- package/src/queries/isolatedAssetQuery.ts +12 -11
- package/src/queries/poolAddressesQuery.ts +187 -112
- package/src/queries/portfolioQuery.ts +65 -67
- package/src/queries/priceQuery.ts +16 -22
- package/src/queries/sCoinQuery.ts +15 -16
- package/src/queries/spoolQuery.ts +49 -59
- package/src/queries/supplyLimitQuery.ts +2 -6
- package/src/queries/xOracleQuery.ts +4 -15
- package/src/types/address.ts +12 -18
- package/src/types/builder/borrowIncentive.ts +2 -3
- package/src/types/builder/core.ts +20 -27
- package/src/types/builder/index.ts +1 -2
- package/src/types/builder/referral.ts +4 -8
- package/src/types/builder/sCoin.ts +4 -8
- package/src/types/builder/spool.ts +7 -10
- package/src/types/constant/common.ts +43 -49
- package/src/types/constant/enum.ts +15 -27
- package/src/types/constant/xOracle.ts +3 -5
- package/src/types/model.ts +47 -28
- package/src/types/query/borrowIncentive.ts +7 -24
- package/src/types/query/core.ts +8 -18
- package/src/types/query/portfolio.ts +8 -17
- package/src/types/query/spool.ts +5 -11
- package/src/types/utils.ts +1 -21
- package/src/utils/core.ts +1 -1
- package/src/utils/query.ts +13 -20
- package/src/utils/util.ts +6 -84
- package/src/constants/coinGecko.ts +0 -34
- package/src/constants/enum.ts +0 -268
- package/src/constants/flashloan.ts +0 -18
- package/src/constants/poolAddress.ts +0 -898
|
@@ -1,14 +1,8 @@
|
|
|
1
1
|
import { SuiObjectData } from '@mysten/sui/client';
|
|
2
2
|
import type { ScallopAddress, ScallopQuery } from '../models';
|
|
3
|
-
import type {
|
|
4
|
-
CoinPrices,
|
|
5
|
-
MarketPools,
|
|
6
|
-
OptionalKeys,
|
|
7
|
-
SupportAssetCoins,
|
|
8
|
-
SupportSCoin,
|
|
9
|
-
} from '../types';
|
|
10
|
-
import { SUPPORT_SCOIN } from 'src/constants/common';
|
|
3
|
+
import type { CoinPrices, MarketPools, OptionalKeys } from '../types';
|
|
11
4
|
import BigNumber from 'bignumber.js';
|
|
5
|
+
import { ScallopConstants } from 'src/models/scallopConstants';
|
|
12
6
|
|
|
13
7
|
/**
|
|
14
8
|
* Get price from pyth fee object.
|
|
@@ -23,7 +17,7 @@ export const getPythPrice = async (
|
|
|
23
17
|
}: {
|
|
24
18
|
address: ScallopAddress;
|
|
25
19
|
},
|
|
26
|
-
assetCoinName:
|
|
20
|
+
assetCoinName: string,
|
|
27
21
|
priceFeedObject?: SuiObjectData | null
|
|
28
22
|
) => {
|
|
29
23
|
const pythFeedObjectId = address.get(
|
|
@@ -70,15 +64,15 @@ export const getPythPrice = async (
|
|
|
70
64
|
|
|
71
65
|
export const getPythPrices = async (
|
|
72
66
|
{
|
|
73
|
-
|
|
67
|
+
constants,
|
|
74
68
|
}: {
|
|
75
|
-
|
|
69
|
+
constants: ScallopConstants;
|
|
76
70
|
},
|
|
77
|
-
assetCoinNames:
|
|
71
|
+
assetCoinNames: string[]
|
|
78
72
|
) => {
|
|
79
73
|
const pythPriceFeedIds = assetCoinNames.reduce(
|
|
80
74
|
(prev, assetCoinName) => {
|
|
81
|
-
const pythPriceFeed = address.get(
|
|
75
|
+
const pythPriceFeed = constants.address.get(
|
|
82
76
|
`core.coins.${assetCoinName}.oracle.pyth.feedObject`
|
|
83
77
|
);
|
|
84
78
|
if (pythPriceFeed) {
|
|
@@ -90,11 +84,11 @@ export const getPythPrices = async (
|
|
|
90
84
|
}
|
|
91
85
|
return prev;
|
|
92
86
|
},
|
|
93
|
-
{} as Record<string,
|
|
87
|
+
{} as Record<string, string[]>
|
|
94
88
|
);
|
|
95
89
|
|
|
96
90
|
// Fetch multiple objects at once to save rpc calls
|
|
97
|
-
const priceFeedObjects = await address.cache.queryGetObjects(
|
|
91
|
+
const priceFeedObjects = await constants.address.cache.queryGetObjects(
|
|
98
92
|
Object.keys(pythPriceFeedIds)
|
|
99
93
|
);
|
|
100
94
|
|
|
@@ -105,7 +99,7 @@ export const getPythPrices = async (
|
|
|
105
99
|
});
|
|
106
100
|
return prev;
|
|
107
101
|
},
|
|
108
|
-
{} as Record<
|
|
102
|
+
{} as Record<string, SuiObjectData>
|
|
109
103
|
);
|
|
110
104
|
|
|
111
105
|
return (
|
|
@@ -114,8 +108,8 @@ export const getPythPrices = async (
|
|
|
114
108
|
async ([assetCoinName, priceFeedObject]) => ({
|
|
115
109
|
coinName: assetCoinName,
|
|
116
110
|
price: await getPythPrice(
|
|
117
|
-
|
|
118
|
-
assetCoinName as
|
|
111
|
+
constants,
|
|
112
|
+
assetCoinName as string,
|
|
119
113
|
priceFeedObject
|
|
120
114
|
),
|
|
121
115
|
})
|
|
@@ -123,10 +117,10 @@ export const getPythPrices = async (
|
|
|
123
117
|
)
|
|
124
118
|
).reduce(
|
|
125
119
|
(prev, curr) => {
|
|
126
|
-
prev[curr.coinName as
|
|
120
|
+
prev[curr.coinName as string] = curr.price;
|
|
127
121
|
return prev;
|
|
128
122
|
},
|
|
129
|
-
{} as Record<
|
|
123
|
+
{} as Record<string, number>
|
|
130
124
|
);
|
|
131
125
|
};
|
|
132
126
|
|
|
@@ -150,8 +144,8 @@ export const getAllCoinPrices = async (
|
|
|
150
144
|
throw new Error(`Failed to fetch market pool for getAllCoinPrices`);
|
|
151
145
|
}
|
|
152
146
|
|
|
153
|
-
const sCoinPrices: OptionalKeys<Record<
|
|
154
|
-
|
|
147
|
+
const sCoinPrices: OptionalKeys<Record<string, number>> = {};
|
|
148
|
+
query.constants.whitelist.scoin.forEach((sCoinName) => {
|
|
155
149
|
const coinName = query.utils.parseCoinName(sCoinName);
|
|
156
150
|
sCoinPrices[sCoinName] = BigNumber(coinPrices[coinName] ?? 0)
|
|
157
151
|
.multipliedBy(marketPools[coinName]?.conversionRate ?? 1)
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { bcs } from '@mysten/sui/bcs';
|
|
2
2
|
import assert from 'assert';
|
|
3
3
|
import BigNumber from 'bignumber.js';
|
|
4
|
-
import { SUPPORT_SCOIN } from 'src/constants';
|
|
5
4
|
import { ScallopQuery, ScallopUtils } from 'src/models';
|
|
6
|
-
import { OptionalKeys,
|
|
5
|
+
import { OptionalKeys, sCoinBalance } from 'src/types';
|
|
7
6
|
|
|
8
7
|
/**
|
|
9
8
|
* Get total supply of sCoin
|
|
@@ -17,7 +16,7 @@ export const getSCoinTotalSupply = async (
|
|
|
17
16
|
}: {
|
|
18
17
|
utils: ScallopUtils;
|
|
19
18
|
},
|
|
20
|
-
sCoinName:
|
|
19
|
+
sCoinName: string
|
|
21
20
|
): Promise<sCoinBalance> => {
|
|
22
21
|
const sCoinPkgId = utils.address.get('scoin.id');
|
|
23
22
|
// get treasury
|
|
@@ -60,11 +59,11 @@ export const getSCoinAmounts = async (
|
|
|
60
59
|
}: {
|
|
61
60
|
utils: ScallopUtils;
|
|
62
61
|
},
|
|
63
|
-
sCoinNames:
|
|
62
|
+
sCoinNames: string[] = [...utils.constants.whitelist.scoin],
|
|
64
63
|
ownerAddress?: string
|
|
65
64
|
) => {
|
|
66
65
|
const owner = ownerAddress || utils.suiKit.currentAddress();
|
|
67
|
-
const sCoins = {} as OptionalKeys<Record<
|
|
66
|
+
const sCoins = {} as OptionalKeys<Record<string, number>>;
|
|
68
67
|
|
|
69
68
|
await Promise.allSettled(
|
|
70
69
|
sCoinNames.map(async (sCoinName) => {
|
|
@@ -90,7 +89,7 @@ export const getSCoinAmount = async (
|
|
|
90
89
|
}: {
|
|
91
90
|
utils: ScallopUtils;
|
|
92
91
|
},
|
|
93
|
-
sCoinName:
|
|
92
|
+
sCoinName: string,
|
|
94
93
|
ownerAddress?: string
|
|
95
94
|
) => {
|
|
96
95
|
const owner = ownerAddress || utils.suiKit.currentAddress();
|
|
@@ -102,18 +101,18 @@ export const getSCoinAmount = async (
|
|
|
102
101
|
return BigNumber(coinBalance?.totalBalance ?? '0').toNumber();
|
|
103
102
|
};
|
|
104
103
|
|
|
105
|
-
const
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
104
|
+
const checkAssetParams = (
|
|
105
|
+
utils: ScallopUtils,
|
|
106
|
+
fromSCoin: string,
|
|
107
|
+
toSCoin: string
|
|
108
|
+
) => {
|
|
110
109
|
if (fromSCoin === toSCoin)
|
|
111
110
|
throw new Error('fromAsset and toAsset must be different');
|
|
112
111
|
|
|
113
|
-
if (!
|
|
112
|
+
if (!utils.constants.whitelist.scoin.has(fromSCoin))
|
|
114
113
|
throw new Error('fromAsset is not supported');
|
|
115
114
|
|
|
116
|
-
if (!
|
|
115
|
+
if (!utils.constants.whitelist.scoin.has(toSCoin)) {
|
|
117
116
|
throw new Error('toAsset is not supported');
|
|
118
117
|
}
|
|
119
118
|
};
|
|
@@ -129,11 +128,11 @@ const checkAssetParams = (fromSCoin: SupportSCoin, toSCoin: SupportSCoin) => {
|
|
|
129
128
|
*/
|
|
130
129
|
export const getSCoinSwapRate = async (
|
|
131
130
|
query: ScallopQuery,
|
|
132
|
-
fromSCoin:
|
|
133
|
-
toSCoin:
|
|
131
|
+
fromSCoin: string,
|
|
132
|
+
toSCoin: string,
|
|
134
133
|
underlyingCoinPrice?: number
|
|
135
134
|
) => {
|
|
136
|
-
checkAssetParams(fromSCoin, toSCoin);
|
|
135
|
+
checkAssetParams(query.utils, fromSCoin, toSCoin);
|
|
137
136
|
const fromCoinName = query.utils.parseCoinName(fromSCoin);
|
|
138
137
|
const toCoinName = query.utils.parseCoinName(toSCoin);
|
|
139
138
|
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { normalizeStructTag } from '@mysten/sui/utils';
|
|
2
|
-
import { POOL_ADDRESSES, SUPPORT_SPOOLS } from '../constants';
|
|
3
2
|
import {
|
|
4
3
|
parseOriginSpoolData,
|
|
5
4
|
calculateSpoolData,
|
|
6
5
|
parseOriginSpoolRewardPoolData,
|
|
7
6
|
calculateSpoolRewardPoolData,
|
|
8
|
-
isMarketCoin,
|
|
9
7
|
parseObjectAs,
|
|
10
8
|
} from '../utils';
|
|
11
9
|
import type { SuiObjectData, SuiObjectResponse } from '@mysten/sui/client';
|
|
@@ -16,8 +14,6 @@ import type {
|
|
|
16
14
|
StakePool,
|
|
17
15
|
StakeRewardPool,
|
|
18
16
|
StakeAccounts,
|
|
19
|
-
SupportStakeMarketCoins,
|
|
20
|
-
SupportStakeCoins,
|
|
21
17
|
CoinPrices,
|
|
22
18
|
MarketPools,
|
|
23
19
|
OriginSpoolRewardPoolData,
|
|
@@ -28,14 +24,14 @@ import { queryMultipleObjects } from './objectsQuery';
|
|
|
28
24
|
|
|
29
25
|
const queryRequiredSpoolObjects = async (
|
|
30
26
|
query: ScallopQuery,
|
|
31
|
-
stakePoolCoinNames:
|
|
27
|
+
stakePoolCoinNames: string[]
|
|
32
28
|
) => {
|
|
33
29
|
// Prepare all tasks for querying each object type
|
|
34
30
|
const tasks = stakePoolCoinNames.map((t, idx) => ({
|
|
35
31
|
poolCoinName: stakePoolCoinNames[idx],
|
|
36
|
-
spool:
|
|
37
|
-
spoolReward:
|
|
38
|
-
sCoinTreasury:
|
|
32
|
+
spool: query.constants.poolAddresses[t]?.spool,
|
|
33
|
+
spoolReward: query.constants.poolAddresses[t]?.spoolReward,
|
|
34
|
+
sCoinTreasury: query.constants.poolAddresses[t]?.sCoinTreasury,
|
|
39
35
|
}));
|
|
40
36
|
|
|
41
37
|
// Query all objects for each key in parallel
|
|
@@ -97,7 +93,7 @@ const queryRequiredSpoolObjects = async (
|
|
|
97
93
|
return acc;
|
|
98
94
|
},
|
|
99
95
|
{} as Record<
|
|
100
|
-
|
|
96
|
+
string,
|
|
101
97
|
{
|
|
102
98
|
spool: SuiObjectData;
|
|
103
99
|
spoolReward: SuiObjectData;
|
|
@@ -141,13 +137,13 @@ const parseSpoolObjects = ({
|
|
|
141
137
|
*/
|
|
142
138
|
export const getSpools = async (
|
|
143
139
|
query: ScallopQuery,
|
|
144
|
-
stakeMarketCoinNames:
|
|
140
|
+
stakeMarketCoinNames: string[] = [...query.constants.whitelist.spool],
|
|
145
141
|
indexer: boolean = false,
|
|
146
142
|
marketPools?: MarketPools,
|
|
147
143
|
coinPrices?: CoinPrices
|
|
148
144
|
) => {
|
|
149
145
|
const stakeCoinNames = stakeMarketCoinNames.map((stakeMarketCoinName) =>
|
|
150
|
-
query.utils.parseCoinName
|
|
146
|
+
query.utils.parseCoinName(stakeMarketCoinName)
|
|
151
147
|
);
|
|
152
148
|
marketPools =
|
|
153
149
|
marketPools ??
|
|
@@ -165,12 +161,8 @@ export const getSpools = async (
|
|
|
165
161
|
const spoolsIndexer = await query.indexer.getSpools();
|
|
166
162
|
const updateSpools = (spool: Spool) => {
|
|
167
163
|
if (!stakeMarketCoinNames.includes(spool.marketCoinName)) return;
|
|
168
|
-
const coinName = query.utils.parseCoinName
|
|
169
|
-
|
|
170
|
-
);
|
|
171
|
-
const rewardCoinName = query.utils.getSpoolRewardCoinName(
|
|
172
|
-
spool.marketCoinName
|
|
173
|
-
);
|
|
164
|
+
const coinName = query.utils.parseCoinName(spool.marketCoinName);
|
|
165
|
+
const rewardCoinName = query.utils.getSpoolRewardCoinName();
|
|
174
166
|
spool.coinPrice = coinPrices[coinName] ?? spool.coinPrice;
|
|
175
167
|
spool.marketCoinPrice =
|
|
176
168
|
coinPrices[spool.marketCoinName] ?? spool.marketCoinPrice;
|
|
@@ -178,7 +170,9 @@ export const getSpools = async (
|
|
|
178
170
|
coinPrices[rewardCoinName] ?? spool.rewardCoinPrice;
|
|
179
171
|
spools[spool.marketCoinName] = spool;
|
|
180
172
|
};
|
|
181
|
-
Object.values(spoolsIndexer)
|
|
173
|
+
Object.values(spoolsIndexer)
|
|
174
|
+
.filter((t) => !!t)
|
|
175
|
+
.forEach(updateSpools);
|
|
182
176
|
|
|
183
177
|
return spools;
|
|
184
178
|
}
|
|
@@ -224,7 +218,7 @@ export const getSpools = async (
|
|
|
224
218
|
*/
|
|
225
219
|
export const getSpool = async (
|
|
226
220
|
query: ScallopQuery,
|
|
227
|
-
marketCoinName:
|
|
221
|
+
marketCoinName: string,
|
|
228
222
|
indexer: boolean = false,
|
|
229
223
|
coinPrices?: CoinPrices,
|
|
230
224
|
requiredObjects?: {
|
|
@@ -232,14 +226,13 @@ export const getSpool = async (
|
|
|
232
226
|
spoolReward: SuiObjectData;
|
|
233
227
|
}
|
|
234
228
|
) => {
|
|
235
|
-
const coinName = query.utils.parseCoinName<
|
|
229
|
+
const coinName = query.utils.parseCoinName<string>(marketCoinName);
|
|
236
230
|
coinPrices = coinPrices || (await query.getAllCoinPrices());
|
|
237
231
|
|
|
238
232
|
if (indexer) {
|
|
239
233
|
const spoolIndexer = await query.indexer.getSpool(marketCoinName);
|
|
240
|
-
const coinName =
|
|
241
|
-
|
|
242
|
-
const rewardCoinName = query.utils.getSpoolRewardCoinName(marketCoinName);
|
|
234
|
+
const coinName = query.utils.parseCoinName<string>(marketCoinName);
|
|
235
|
+
const rewardCoinName = query.utils.getSpoolRewardCoinName();
|
|
243
236
|
spoolIndexer.coinPrice = coinPrices?.[coinName] ?? spoolIndexer.coinPrice;
|
|
244
237
|
spoolIndexer.marketCoinPrice =
|
|
245
238
|
coinPrices?.[marketCoinName] ?? spoolIndexer.marketCoinPrice;
|
|
@@ -253,7 +246,7 @@ export const getSpool = async (
|
|
|
253
246
|
coinName
|
|
254
247
|
];
|
|
255
248
|
|
|
256
|
-
const rewardCoinName = query.utils.getSpoolRewardCoinName(
|
|
249
|
+
const rewardCoinName = query.utils.getSpoolRewardCoinName();
|
|
257
250
|
coinPrices = coinPrices || (await query.utils.getCoinPrices());
|
|
258
251
|
|
|
259
252
|
const parsedSpoolObjects = parseSpoolObjects(requiredObjects);
|
|
@@ -286,10 +279,10 @@ export const getSpool = async (
|
|
|
286
279
|
symbol: query.utils.parseSymbol(marketCoinName),
|
|
287
280
|
coinType: query.utils.parseCoinType(coinName),
|
|
288
281
|
marketCoinType: query.utils.parseMarketCoinType(coinName),
|
|
289
|
-
rewardCoinType: isMarketCoin(rewardCoinName)
|
|
282
|
+
rewardCoinType: query.utils.isMarketCoin(rewardCoinName)
|
|
290
283
|
? query.utils.parseMarketCoinType(rewardCoinName)
|
|
291
284
|
: query.utils.parseCoinType(rewardCoinName),
|
|
292
|
-
sCoinType: query.utils.parseSCoinType(marketCoinName),
|
|
285
|
+
sCoinType: query.utils.parseSCoinType(marketCoinName) ?? '',
|
|
293
286
|
coinDecimal: query.utils.getCoinDecimal(coinName),
|
|
294
287
|
rewardCoinDecimal: query.utils.getCoinDecimal(rewardCoinName),
|
|
295
288
|
coinPrice: coinPrices?.[coinName] ?? 0,
|
|
@@ -352,37 +345,37 @@ export const getStakeAccounts = async (
|
|
|
352
345
|
}
|
|
353
346
|
} while (hasNextPage);
|
|
354
347
|
|
|
355
|
-
const stakeAccounts: StakeAccounts =
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
348
|
+
const stakeAccounts: StakeAccounts = [
|
|
349
|
+
...utils.constants.whitelist.spool,
|
|
350
|
+
].reduce((acc, stakeName) => {
|
|
351
|
+
acc[stakeName] = [];
|
|
352
|
+
return acc;
|
|
353
|
+
}, {} as StakeAccounts);
|
|
354
|
+
|
|
355
|
+
const stakeMarketCoinTypes: Record<string, string> = Object.keys(
|
|
356
|
+
stakeAccounts
|
|
357
|
+
).reduce(
|
|
358
|
+
(types, stakeMarketCoinName) => {
|
|
359
|
+
const stakeCoinName = utils.parseCoinName<string>(stakeMarketCoinName);
|
|
360
|
+
const marketCoinType = utils.parseMarketCoinType(stakeCoinName);
|
|
361
|
+
|
|
362
|
+
types[stakeMarketCoinName as string] =
|
|
363
|
+
`${spoolObjectId}::spool_account::SpoolAccount<${marketCoinType}>`;
|
|
364
|
+
return types;
|
|
359
365
|
},
|
|
360
|
-
{} as
|
|
366
|
+
{} as Record<string, string>
|
|
361
367
|
);
|
|
362
368
|
|
|
363
|
-
const stakeMarketCoinTypes: Record<SupportStakeMarketCoins, string> =
|
|
364
|
-
Object.keys(stakeAccounts).reduce(
|
|
365
|
-
(types, stakeMarketCoinName) => {
|
|
366
|
-
const stakeCoinName =
|
|
367
|
-
utils.parseCoinName<SupportStakeCoins>(stakeMarketCoinName);
|
|
368
|
-
const marketCoinType = utils.parseMarketCoinType(stakeCoinName);
|
|
369
|
-
|
|
370
|
-
types[stakeMarketCoinName as SupportStakeMarketCoins] =
|
|
371
|
-
`${spoolObjectId}::spool_account::SpoolAccount<${marketCoinType}>`;
|
|
372
|
-
return types;
|
|
373
|
-
},
|
|
374
|
-
{} as Record<SupportStakeMarketCoins, string>
|
|
375
|
-
);
|
|
376
|
-
|
|
377
369
|
// Reverse the mapping
|
|
378
|
-
const reversedStakeMarketCoinTypes: Record<string,
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
370
|
+
const reversedStakeMarketCoinTypes: Record<string, string> = Object.entries(
|
|
371
|
+
stakeMarketCoinTypes
|
|
372
|
+
).reduce(
|
|
373
|
+
(reversedTypes, [key, value]) => {
|
|
374
|
+
reversedTypes[value] = key as string;
|
|
375
|
+
return reversedTypes;
|
|
376
|
+
},
|
|
377
|
+
{} as Record<string, string>
|
|
378
|
+
);
|
|
386
379
|
|
|
387
380
|
for (const stakeObject of stakeObjectsResponse.map((ref) => ref.data)) {
|
|
388
381
|
const id = stakeObject?.objectId;
|
|
@@ -396,10 +389,7 @@ export const getStakeAccounts = async (
|
|
|
396
389
|
const points = Number(fields.points);
|
|
397
390
|
const totalPoints = Number(fields.total_points);
|
|
398
391
|
|
|
399
|
-
const stakeMarketCoinTypeMap: Record<
|
|
400
|
-
SupportStakeMarketCoins,
|
|
401
|
-
StakeAccounts[SupportStakeMarketCoins]
|
|
402
|
-
> = {
|
|
392
|
+
const stakeMarketCoinTypeMap: Record<string, StakeAccounts[string]> = {
|
|
403
393
|
sweth: stakeAccounts.sweth,
|
|
404
394
|
ssui: stakeAccounts.ssui,
|
|
405
395
|
swusdc: stakeAccounts.swusdc,
|
|
@@ -449,7 +439,7 @@ export const getStakePool = async (
|
|
|
449
439
|
}: {
|
|
450
440
|
utils: ScallopUtils;
|
|
451
441
|
},
|
|
452
|
-
marketCoinName:
|
|
442
|
+
marketCoinName: string
|
|
453
443
|
) => {
|
|
454
444
|
const poolId = utils.address.get(`spool.pools.${marketCoinName}.id`);
|
|
455
445
|
let stakePool: StakePool | undefined = undefined;
|
|
@@ -506,7 +496,7 @@ export const getStakeRewardPool = async (
|
|
|
506
496
|
}: {
|
|
507
497
|
utils: ScallopUtils;
|
|
508
498
|
},
|
|
509
|
-
marketCoinName:
|
|
499
|
+
marketCoinName: string
|
|
510
500
|
) => {
|
|
511
501
|
const poolId = utils.address.get(
|
|
512
502
|
`spool.pools.${marketCoinName}.rewardPoolId`
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { ScallopUtils } from 'src/models';
|
|
2
|
-
import { SupportPoolCoins } from 'src/types';
|
|
3
2
|
import { z as zod } from 'zod';
|
|
4
3
|
|
|
5
4
|
const supplyLimitZod = zod.object({
|
|
@@ -25,10 +24,7 @@ const supplyLimitKeyType = `0x6e641f0dca8aedab3101d047e96439178f16301bf0b57fe874
|
|
|
25
24
|
* @param poolName
|
|
26
25
|
* @returns supply limit (decimals included)
|
|
27
26
|
*/
|
|
28
|
-
export const getSupplyLimit = async (
|
|
29
|
-
utils: ScallopUtils,
|
|
30
|
-
poolName: SupportPoolCoins
|
|
31
|
-
) => {
|
|
27
|
+
export const getSupplyLimit = async (utils: ScallopUtils, poolName: string) => {
|
|
32
28
|
try {
|
|
33
29
|
const poolCoinType = utils.parseCoinType(poolName).slice(2);
|
|
34
30
|
const marketObject = utils.address.get('core.market');
|
|
@@ -43,7 +39,7 @@ export const getSupplyLimit = async (
|
|
|
43
39
|
});
|
|
44
40
|
|
|
45
41
|
const parsedData = supplyLimitZod.safeParse(object?.data?.content);
|
|
46
|
-
if (!parsedData.success) return
|
|
42
|
+
if (!parsedData.success) return '0';
|
|
47
43
|
return parsedData.data.fields.value;
|
|
48
44
|
} catch (e: any) {
|
|
49
45
|
console.error(`Error in getSupplyLimit for ${poolName}: ${e.message}`);
|
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
import { SuiObjectResponse } from '@mysten/sui/client';
|
|
2
2
|
import { ScallopAddress, ScallopUtils } from 'src/models';
|
|
3
|
-
import {
|
|
4
|
-
SupportAssetCoins,
|
|
5
|
-
SupportOracleType,
|
|
6
|
-
xOracleRuleType,
|
|
7
|
-
} from 'src/types';
|
|
3
|
+
import { xOracleRuleType } from 'src/types';
|
|
8
4
|
|
|
9
5
|
const PRIMARY_PRICE_UPDATE_POLICY =
|
|
10
6
|
'0x56e48a141f20a3a6a6d3fc43e58b01fc63f756c08224870e7890c80ec9d2afee';
|
|
@@ -47,10 +43,6 @@ export const getPriceUpdatePolicies = async (
|
|
|
47
43
|
};
|
|
48
44
|
};
|
|
49
45
|
|
|
50
|
-
// const PRIMARY_PRICE_UPDATE_POLICY_KEY =
|
|
51
|
-
// '0x856d0930acc36780eda9ea47019c979ca6ad34fd36f158b181eb7350195acc00';
|
|
52
|
-
// const SECONDARY_PRICE_UPDATE_POLICY_KEY =
|
|
53
|
-
// '0x304d226734fa5e376423c9ff0f1d49aeb1e2572d4b617d31e11e2f69865b73ed';
|
|
54
46
|
const PRIMARY_PRICE_UPDATE_POLICY_VECSET_ID =
|
|
55
47
|
'0xc22c9d691ee4c780de09db91d8b487d863211ebf08720772144bcf716318826c';
|
|
56
48
|
const SECONDARY_PRICE_UPDATE_POLICY_VECSET_ID =
|
|
@@ -59,7 +51,7 @@ const SECONDARY_PRICE_UPDATE_POLICY_VECSET_ID =
|
|
|
59
51
|
export const getAssetOracles = async (
|
|
60
52
|
utils: ScallopUtils,
|
|
61
53
|
ruleType: xOracleRuleType
|
|
62
|
-
): Promise<Record<
|
|
54
|
+
): Promise<Record<string, string[]> | null> => {
|
|
63
55
|
if (ruleType === 'primary' && !PRIMARY_PRICE_UPDATE_POLICY_VECSET_ID) {
|
|
64
56
|
console.error('Primary price update policy vecset id is not set');
|
|
65
57
|
return null;
|
|
@@ -69,17 +61,14 @@ export const getAssetOracles = async (
|
|
|
69
61
|
return null;
|
|
70
62
|
}
|
|
71
63
|
|
|
72
|
-
const ruleTypeNameToOracleType: Record<string,
|
|
64
|
+
const ruleTypeNameToOracleType: Record<string, string> = {
|
|
73
65
|
[`${utils.address.get('core.packages.pyth.object')}::rule::Rule`]: 'pyth',
|
|
74
66
|
[`${utils.address.get('core.packages.supra.object')}::rule::Rule`]: 'supra',
|
|
75
67
|
[`${utils.address.get('core.packages.switchboard.object')}::rule::Rule`]:
|
|
76
68
|
'switchboard',
|
|
77
69
|
};
|
|
78
70
|
|
|
79
|
-
const assetPrimaryOracles = {} as Record<
|
|
80
|
-
SupportAssetCoins,
|
|
81
|
-
SupportOracleType[]
|
|
82
|
-
>;
|
|
71
|
+
const assetPrimaryOracles = {} as Record<string, string[]>;
|
|
83
72
|
let cursor = null;
|
|
84
73
|
do {
|
|
85
74
|
const response = await utils.cache.queryGetDynamicFields({
|
package/src/types/address.ts
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
SupportAssetCoins,
|
|
4
|
-
SupportOracleType,
|
|
5
|
-
SupportPackageType,
|
|
6
|
-
SupportSCoin,
|
|
7
|
-
SupportStakeMarketCoins,
|
|
8
|
-
} from './constant';
|
|
1
|
+
const _SUPPORT_ORACLES = ['supra', 'switchboard', 'pyth'] as const;
|
|
2
|
+
type SupportOracleType = (typeof _SUPPORT_ORACLES)[number];
|
|
9
3
|
|
|
10
4
|
export interface AddressesInterface {
|
|
11
5
|
core: {
|
|
@@ -18,7 +12,7 @@ export interface AddressesInterface {
|
|
|
18
12
|
obligationAccessStore: string;
|
|
19
13
|
coins: Partial<
|
|
20
14
|
Record<
|
|
21
|
-
|
|
15
|
+
string,
|
|
22
16
|
{
|
|
23
17
|
id: string;
|
|
24
18
|
treasury: string;
|
|
@@ -27,11 +21,11 @@ export interface AddressesInterface {
|
|
|
27
21
|
symbol: string;
|
|
28
22
|
decimals: number;
|
|
29
23
|
oracle: {
|
|
30
|
-
[K in SupportOracleType]: K extends (typeof
|
|
24
|
+
[K in SupportOracleType]: K extends (typeof _SUPPORT_ORACLES)[0]
|
|
31
25
|
? string
|
|
32
|
-
: K extends (typeof
|
|
26
|
+
: K extends (typeof _SUPPORT_ORACLES)[1]
|
|
33
27
|
? string
|
|
34
|
-
: K extends (typeof
|
|
28
|
+
: K extends (typeof _SUPPORT_ORACLES)[2]
|
|
35
29
|
? {
|
|
36
30
|
feed: string;
|
|
37
31
|
feedObject: string;
|
|
@@ -42,18 +36,18 @@ export interface AddressesInterface {
|
|
|
42
36
|
>
|
|
43
37
|
>;
|
|
44
38
|
oracles: {
|
|
45
|
-
[K in SupportOracleType]: K extends (typeof
|
|
39
|
+
[K in SupportOracleType]: K extends (typeof _SUPPORT_ORACLES)[0]
|
|
46
40
|
? {
|
|
47
41
|
registry: string;
|
|
48
42
|
registryCap: string;
|
|
49
43
|
holder: string;
|
|
50
44
|
}
|
|
51
|
-
: K extends (typeof
|
|
45
|
+
: K extends (typeof _SUPPORT_ORACLES)[1]
|
|
52
46
|
? {
|
|
53
47
|
registry: string;
|
|
54
48
|
registryCap: string;
|
|
55
49
|
}
|
|
56
|
-
: K extends (typeof
|
|
50
|
+
: K extends (typeof _SUPPORT_ORACLES)[2]
|
|
57
51
|
? {
|
|
58
52
|
registry: string;
|
|
59
53
|
registryCap: string;
|
|
@@ -65,7 +59,7 @@ export interface AddressesInterface {
|
|
|
65
59
|
} & { xOracle: string; xOracleCap: string };
|
|
66
60
|
packages: Partial<
|
|
67
61
|
Record<
|
|
68
|
-
|
|
62
|
+
string,
|
|
69
63
|
{
|
|
70
64
|
id: string;
|
|
71
65
|
object?: string;
|
|
@@ -81,7 +75,7 @@ export interface AddressesInterface {
|
|
|
81
75
|
config: string;
|
|
82
76
|
pools: Partial<
|
|
83
77
|
Record<
|
|
84
|
-
|
|
78
|
+
string,
|
|
85
79
|
{
|
|
86
80
|
id: string;
|
|
87
81
|
rewardPoolId: string;
|
|
@@ -130,7 +124,7 @@ export interface AddressesInterface {
|
|
|
130
124
|
id: string;
|
|
131
125
|
coins: Partial<
|
|
132
126
|
Record<
|
|
133
|
-
|
|
127
|
+
string,
|
|
134
128
|
{
|
|
135
129
|
coinType: string;
|
|
136
130
|
symbol: string;
|
|
@@ -4,7 +4,6 @@ import type {
|
|
|
4
4
|
} from '@scallop-io/sui-kit';
|
|
5
5
|
import type { TransactionResult } from '@mysten/sui/transactions';
|
|
6
6
|
import type { ScallopBuilder } from '../../models';
|
|
7
|
-
import type { SupportBorrowIncentiveRewardCoins } from '../constant';
|
|
8
7
|
|
|
9
8
|
export type BorrowIncentiveIds = {
|
|
10
9
|
borrowIncentivePkg: string;
|
|
@@ -32,7 +31,7 @@ export type BorrowIncentiveNormalMethods = {
|
|
|
32
31
|
claimBorrowIncentive: (
|
|
33
32
|
obligation: SuiObjectArg,
|
|
34
33
|
obligationKey: SuiObjectArg,
|
|
35
|
-
rewardType:
|
|
34
|
+
rewardType: string
|
|
36
35
|
) => TransactionResult;
|
|
37
36
|
deactivateBoost: (obligation: SuiObjectArg, veScaKey: SuiObjectArg) => void;
|
|
38
37
|
};
|
|
@@ -52,7 +51,7 @@ export type BorrowIncentiveQuickMethods = {
|
|
|
52
51
|
obligationKey?: string
|
|
53
52
|
): Promise<void>;
|
|
54
53
|
claimBorrowIncentiveQuick(
|
|
55
|
-
rewardType:
|
|
54
|
+
rewardType: string,
|
|
56
55
|
obligation?: string,
|
|
57
56
|
obligationKey?: string
|
|
58
57
|
): Promise<TransactionResult>;
|