@scallop-io/sui-scallop-sdk 1.4.15-rc.1 → 1.4.15-rc.2
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/poolAddress.d.ts +1 -0
- package/dist/constants/tokenBucket.d.ts +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +161 -116
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +159 -116
- package/dist/index.mjs.map +1 -1
- package/dist/models/scallopQuery.d.ts +1 -0
- package/dist/queries/poolAddressesQuery.d.ts +1 -0
- package/dist/queries/spoolQuery.d.ts +6 -2
- package/dist/test.d.ts +1 -0
- package/dist/types/query/spool.d.ts +20 -0
- package/dist/utils/index.d.ts +1 -0
- package/package.json +1 -1
- package/src/constants/poolAddress.ts +1 -0
- package/src/constants/tokenBucket.ts +1 -1
- package/src/index.ts +1 -0
- package/src/models/scallopQuery.ts +2 -9
- package/src/queries/poolAddressesQuery.ts +8 -2
- package/src/queries/spoolQuery.ts +186 -121
- package/src/test.ts +17 -0
- package/src/types/query/spool.ts +21 -0
- package/src/utils/core.ts +11 -4
- package/src/utils/index.ts +1 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import type { SuiObjectData } from '@mysten/sui/client';
|
|
1
2
|
import type { ScallopQuery, ScallopUtils } from '../models';
|
|
2
|
-
import type {
|
|
3
|
+
import type { Spool, StakePool, StakeRewardPool, StakeAccounts, SupportStakeMarketCoins, CoinPrices, MarketPools } from '../types';
|
|
3
4
|
/**
|
|
4
5
|
* Get spools data.
|
|
5
6
|
*
|
|
@@ -29,7 +30,10 @@ export declare const getSpools: (query: ScallopQuery, stakeMarketCoinNames?: Sup
|
|
|
29
30
|
* @param coinPrices - The coin prices.
|
|
30
31
|
* @return Spool data.
|
|
31
32
|
*/
|
|
32
|
-
export declare const getSpool: (query: ScallopQuery, marketCoinName: SupportStakeMarketCoins, indexer?: boolean,
|
|
33
|
+
export declare const getSpool: (query: ScallopQuery, marketCoinName: SupportStakeMarketCoins, indexer?: boolean, coinPrices?: CoinPrices, requiredObjects?: {
|
|
34
|
+
spool: SuiObjectData;
|
|
35
|
+
spoolReward: SuiObjectData;
|
|
36
|
+
}) => Promise<Spool>;
|
|
33
37
|
/**
|
|
34
38
|
* Get all stake accounts of the owner.
|
|
35
39
|
*
|
package/dist/test.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -32,6 +32,26 @@ export type OriginSpoolData = {
|
|
|
32
32
|
createdAt: string;
|
|
33
33
|
lastUpdate: string;
|
|
34
34
|
};
|
|
35
|
+
export type SpoolData = {
|
|
36
|
+
created_at: string;
|
|
37
|
+
distributed_point: string;
|
|
38
|
+
distributed_point_per_period: string;
|
|
39
|
+
id: {
|
|
40
|
+
id: string;
|
|
41
|
+
};
|
|
42
|
+
index: string;
|
|
43
|
+
last_update: string;
|
|
44
|
+
max_distributed_point: string;
|
|
45
|
+
max_stakes: string;
|
|
46
|
+
point_distribution_time: string;
|
|
47
|
+
stake_type: {
|
|
48
|
+
type: string;
|
|
49
|
+
fields: {
|
|
50
|
+
name: string;
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
stakes: string;
|
|
54
|
+
};
|
|
35
55
|
export type ParsedSpoolData = {
|
|
36
56
|
stakeType: string;
|
|
37
57
|
maxPoint: number;
|
package/dist/utils/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const DEFAULT_TOKENS_PER_INTERVAL =
|
|
1
|
+
export const DEFAULT_TOKENS_PER_INTERVAL = 10;
|
|
2
2
|
export const DEFAULT_INTERVAL_IN_MS = 250;
|
package/src/index.ts
CHANGED
|
@@ -14,11 +14,9 @@ import {
|
|
|
14
14
|
getStakeRewardPool,
|
|
15
15
|
getPythPrice,
|
|
16
16
|
getMarketPools,
|
|
17
|
-
// getMarketPool,
|
|
18
17
|
getMarketCollaterals,
|
|
19
18
|
getMarketCollateral,
|
|
20
19
|
getSpools,
|
|
21
|
-
getSpool,
|
|
22
20
|
queryBorrowIncentiveAccounts,
|
|
23
21
|
getCoinAmounts,
|
|
24
22
|
getCoinAmount,
|
|
@@ -422,13 +420,8 @@ export class ScallopQuery {
|
|
|
422
420
|
indexer?: boolean;
|
|
423
421
|
}
|
|
424
422
|
) {
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
stakeMarketCoinName,
|
|
428
|
-
args?.indexer,
|
|
429
|
-
args?.marketPool,
|
|
430
|
-
args?.coinPrices
|
|
431
|
-
);
|
|
423
|
+
const spools = await this.getSpools(undefined, args);
|
|
424
|
+
return spools[stakeMarketCoinName];
|
|
432
425
|
}
|
|
433
426
|
|
|
434
427
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SUPPORT_POOLS } from 'src/constants';
|
|
2
2
|
import { ScallopQuery } from 'src/models';
|
|
3
|
-
import { OptionalKeys, SupportPoolCoins
|
|
3
|
+
import { OptionalKeys, SupportPoolCoins } from 'src/types';
|
|
4
4
|
|
|
5
5
|
export const getAllAddresses = async (query: ScallopQuery) => {
|
|
6
6
|
const results: OptionalKeys<
|
|
@@ -12,6 +12,7 @@ export const getAllAddresses = async (query: ScallopQuery) => {
|
|
|
12
12
|
borrowDynamic?: string;
|
|
13
13
|
spoolReward?: string;
|
|
14
14
|
spool?: string;
|
|
15
|
+
sCoinTreasury?: string;
|
|
15
16
|
interestModel?: string;
|
|
16
17
|
riskModel?: string;
|
|
17
18
|
borrowFeeKey?: string;
|
|
@@ -106,12 +107,16 @@ export const getAllAddresses = async (query: ScallopQuery) => {
|
|
|
106
107
|
|
|
107
108
|
const spool = query.address.get(
|
|
108
109
|
// @ts-ignore
|
|
109
|
-
`spool.pools.s${coinName
|
|
110
|
+
`spool.pools.s${coinName}.id`
|
|
110
111
|
);
|
|
111
112
|
const rewardPool = query.address.get(
|
|
112
113
|
// @ts-ignore
|
|
113
114
|
`spool.pools.s${coinName}.rewardPoolId`
|
|
114
115
|
);
|
|
116
|
+
const sCoinTreasury = query.address.get(
|
|
117
|
+
// @ts-ignore
|
|
118
|
+
`scoin.coins.s${coinName}.treasury`
|
|
119
|
+
);
|
|
115
120
|
results[coinName as SupportPoolCoins] = {
|
|
116
121
|
lendingPoolAddress: addresses[0],
|
|
117
122
|
collateralPoolAddress: addresses[1],
|
|
@@ -124,6 +129,7 @@ export const getAllAddresses = async (query: ScallopQuery) => {
|
|
|
124
129
|
isolatedAssetKey: addresses[8],
|
|
125
130
|
spool,
|
|
126
131
|
spoolReward: rewardPool,
|
|
132
|
+
sCoinTreasury,
|
|
127
133
|
};
|
|
128
134
|
|
|
129
135
|
await new Promise((resolve) => setTimeout(resolve, 200));
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { normalizeStructTag } from '@mysten/sui/utils';
|
|
2
|
-
import { SUPPORT_SPOOLS } from '../constants';
|
|
2
|
+
import { POOL_ADDRESSES, SUPPORT_SPOOLS } from '../constants';
|
|
3
3
|
import {
|
|
4
4
|
parseOriginSpoolData,
|
|
5
5
|
calculateSpoolData,
|
|
6
6
|
parseOriginSpoolRewardPoolData,
|
|
7
7
|
calculateSpoolRewardPoolData,
|
|
8
8
|
isMarketCoin,
|
|
9
|
+
parseObjectAs,
|
|
9
10
|
} from '../utils';
|
|
10
|
-
import type { SuiObjectResponse } from '@mysten/sui/client';
|
|
11
|
+
import type { SuiObjectData, SuiObjectResponse } from '@mysten/sui/client';
|
|
11
12
|
import type { ScallopQuery, ScallopUtils } from '../models';
|
|
12
13
|
import type {
|
|
13
|
-
MarketPool,
|
|
14
14
|
Spools,
|
|
15
15
|
Spool,
|
|
16
16
|
StakePool,
|
|
@@ -20,7 +20,107 @@ import type {
|
|
|
20
20
|
SupportStakeCoins,
|
|
21
21
|
CoinPrices,
|
|
22
22
|
MarketPools,
|
|
23
|
+
OriginSpoolRewardPoolData,
|
|
24
|
+
SpoolData,
|
|
25
|
+
OriginSpoolData,
|
|
23
26
|
} from '../types';
|
|
27
|
+
import { queryMultipleObjects } from './objectsQuery';
|
|
28
|
+
|
|
29
|
+
const queryRequiredSpoolObjects = async (
|
|
30
|
+
query: ScallopQuery,
|
|
31
|
+
stakePoolCoinNames: SupportStakeCoins[]
|
|
32
|
+
) => {
|
|
33
|
+
// Prepare all tasks for querying each object type
|
|
34
|
+
const tasks = stakePoolCoinNames.map((t, idx) => ({
|
|
35
|
+
poolCoinName: stakePoolCoinNames[idx],
|
|
36
|
+
spool: POOL_ADDRESSES[t]?.spool,
|
|
37
|
+
spoolReward: POOL_ADDRESSES[t]?.spoolReward,
|
|
38
|
+
sCoinTreasury: POOL_ADDRESSES[t]?.sCoinTreasury,
|
|
39
|
+
}));
|
|
40
|
+
|
|
41
|
+
// Query all objects for each key in parallel
|
|
42
|
+
const [spoolObjects, spoolRewardObjects, sCoinTreasuryObjects] =
|
|
43
|
+
await Promise.all([
|
|
44
|
+
queryMultipleObjects(
|
|
45
|
+
query.cache,
|
|
46
|
+
tasks.map((task) => task.spool).filter((t): t is string => !!t)
|
|
47
|
+
),
|
|
48
|
+
queryMultipleObjects(
|
|
49
|
+
query.cache,
|
|
50
|
+
tasks.map((task) => task.spoolReward).filter((t): t is string => !!t)
|
|
51
|
+
),
|
|
52
|
+
queryMultipleObjects(
|
|
53
|
+
query.cache,
|
|
54
|
+
tasks.map((task) => task.sCoinTreasury).filter((t): t is string => !!t)
|
|
55
|
+
),
|
|
56
|
+
]);
|
|
57
|
+
|
|
58
|
+
// Map the results back to poolCoinNames
|
|
59
|
+
const mapObjects = (
|
|
60
|
+
tasks: { poolCoinName: string; [key: string]: string | undefined }[],
|
|
61
|
+
fetchedObjects: SuiObjectData[]
|
|
62
|
+
) => {
|
|
63
|
+
const resultMap: Record<string, SuiObjectData> = {};
|
|
64
|
+
let fetchedIndex = 0;
|
|
65
|
+
|
|
66
|
+
for (const task of tasks) {
|
|
67
|
+
const key = task[Object.keys(task)[1]]; // current object key being queried
|
|
68
|
+
if (key) {
|
|
69
|
+
resultMap[task.poolCoinName] = fetchedObjects[fetchedIndex];
|
|
70
|
+
fetchedIndex++;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return resultMap;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const spoolMap = mapObjects(tasks, spoolObjects);
|
|
77
|
+
const spoolRewardMap = mapObjects(tasks, spoolRewardObjects);
|
|
78
|
+
const sCoinTreasuryMap = mapObjects(tasks, sCoinTreasuryObjects);
|
|
79
|
+
|
|
80
|
+
// Construct the final requiredObjects result
|
|
81
|
+
return stakePoolCoinNames.reduce(
|
|
82
|
+
(acc, name) => {
|
|
83
|
+
acc[name] = {
|
|
84
|
+
spool: spoolMap[name],
|
|
85
|
+
spoolReward: spoolRewardMap[name],
|
|
86
|
+
sCoinTreasury: sCoinTreasuryMap[name],
|
|
87
|
+
};
|
|
88
|
+
return acc;
|
|
89
|
+
},
|
|
90
|
+
{} as Record<
|
|
91
|
+
SupportStakeCoins,
|
|
92
|
+
{
|
|
93
|
+
spool: SuiObjectData;
|
|
94
|
+
spoolReward: SuiObjectData;
|
|
95
|
+
sCoinTreasury: SuiObjectData;
|
|
96
|
+
}
|
|
97
|
+
>
|
|
98
|
+
);
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
const parseSpoolObjects = ({
|
|
102
|
+
spool,
|
|
103
|
+
spoolReward,
|
|
104
|
+
}: {
|
|
105
|
+
spool: SuiObjectData;
|
|
106
|
+
spoolReward: SuiObjectData;
|
|
107
|
+
}): OriginSpoolData & OriginSpoolRewardPoolData => {
|
|
108
|
+
const _spool = parseObjectAs<SpoolData>(spool);
|
|
109
|
+
const _spoolReward = parseObjectAs<OriginSpoolRewardPoolData>(spoolReward);
|
|
110
|
+
return {
|
|
111
|
+
stakeType: _spool.stake_type,
|
|
112
|
+
maxDistributedPoint: _spool.max_distributed_point,
|
|
113
|
+
distributedPoint: _spool.distributed_point,
|
|
114
|
+
distributedPointPerPeriod: _spool.distributed_point_per_period,
|
|
115
|
+
pointDistributionTime: _spool.point_distribution_time,
|
|
116
|
+
maxStake: _spool.max_stakes,
|
|
117
|
+
stakes: _spool.stakes,
|
|
118
|
+
index: _spool.index,
|
|
119
|
+
createdAt: _spool.created_at,
|
|
120
|
+
lastUpdate: _spool.last_update,
|
|
121
|
+
..._spoolReward,
|
|
122
|
+
};
|
|
123
|
+
};
|
|
24
124
|
|
|
25
125
|
/**
|
|
26
126
|
* Get spools data.
|
|
@@ -40,12 +140,13 @@ export const getSpools = async (
|
|
|
40
140
|
const stakeCoinNames = stakeMarketCoinNames.map((stakeMarketCoinName) =>
|
|
41
141
|
query.utils.parseCoinName<SupportStakeCoins>(stakeMarketCoinName)
|
|
42
142
|
);
|
|
43
|
-
coinPrices = coinPrices ?? (await query.utils.getCoinPrices()) ?? {};
|
|
44
|
-
|
|
45
143
|
marketPools =
|
|
46
144
|
marketPools ??
|
|
47
145
|
(await query.getMarketPools(stakeCoinNames, { indexer })).pools;
|
|
48
146
|
|
|
147
|
+
coinPrices =
|
|
148
|
+
coinPrices ?? (await query.getAllCoinPrices({ marketPools })) ?? {};
|
|
149
|
+
|
|
49
150
|
if (!marketPools)
|
|
50
151
|
throw new Error(`Fail to fetch marketPools for ${stakeCoinNames}`);
|
|
51
152
|
|
|
@@ -61,12 +162,9 @@ export const getSpools = async (
|
|
|
61
162
|
const rewardCoinName = query.utils.getSpoolRewardCoinName(
|
|
62
163
|
spool.marketCoinName
|
|
63
164
|
);
|
|
64
|
-
const marketPool = marketPools[coinName];
|
|
65
165
|
spool.coinPrice = coinPrices[coinName] ?? spool.coinPrice;
|
|
66
|
-
spool.marketCoinPrice =
|
|
67
|
-
|
|
68
|
-
(marketPool ? marketPool.conversionRate : 0)
|
|
69
|
-
: spool.marketCoinPrice;
|
|
166
|
+
spool.marketCoinPrice =
|
|
167
|
+
coinPrices[spool.marketCoinName] ?? spool.marketCoinPrice;
|
|
70
168
|
spool.rewardCoinPrice =
|
|
71
169
|
coinPrices[rewardCoinName] ?? spool.rewardCoinPrice;
|
|
72
170
|
spools[spool.marketCoinName] = spool;
|
|
@@ -76,21 +174,31 @@ export const getSpools = async (
|
|
|
76
174
|
return spools;
|
|
77
175
|
}
|
|
78
176
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
query,
|
|
84
|
-
stakeMarketCoinName,
|
|
85
|
-
indexer,
|
|
86
|
-
marketPools[stakeCoinName],
|
|
87
|
-
coinPrices
|
|
88
|
-
);
|
|
177
|
+
const requiredObjects = await queryRequiredSpoolObjects(
|
|
178
|
+
query,
|
|
179
|
+
stakeCoinNames
|
|
180
|
+
);
|
|
89
181
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
182
|
+
await Promise.allSettled(
|
|
183
|
+
stakeMarketCoinNames.map(async (stakeMarketCoinName, idx) => {
|
|
184
|
+
try {
|
|
185
|
+
const stakeCoinName = stakeCoinNames[idx];
|
|
186
|
+
const spool = await getSpool(
|
|
187
|
+
query,
|
|
188
|
+
stakeMarketCoinName,
|
|
189
|
+
indexer,
|
|
190
|
+
coinPrices,
|
|
191
|
+
requiredObjects[stakeCoinName]
|
|
192
|
+
);
|
|
193
|
+
|
|
194
|
+
if (spool) {
|
|
195
|
+
spools[stakeMarketCoinName] = spool;
|
|
196
|
+
}
|
|
197
|
+
} catch (e) {
|
|
198
|
+
console.error(e);
|
|
199
|
+
}
|
|
200
|
+
})
|
|
201
|
+
);
|
|
94
202
|
|
|
95
203
|
return spools;
|
|
96
204
|
};
|
|
@@ -109,126 +217,83 @@ export const getSpool = async (
|
|
|
109
217
|
query: ScallopQuery,
|
|
110
218
|
marketCoinName: SupportStakeMarketCoins,
|
|
111
219
|
indexer: boolean = false,
|
|
112
|
-
|
|
113
|
-
|
|
220
|
+
coinPrices?: CoinPrices,
|
|
221
|
+
requiredObjects?: {
|
|
222
|
+
spool: SuiObjectData;
|
|
223
|
+
spoolReward: SuiObjectData;
|
|
224
|
+
}
|
|
114
225
|
) => {
|
|
115
226
|
const coinName = query.utils.parseCoinName<SupportStakeCoins>(marketCoinName);
|
|
116
|
-
|
|
117
|
-
if (!marketPool) {
|
|
118
|
-
throw new Error(`Failed to fetch marketPool for ${marketCoinName}`);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
const poolId = query.address.get(`spool.pools.${marketCoinName}.id`);
|
|
122
|
-
const rewardPoolId = query.address.get(
|
|
123
|
-
`spool.pools.${marketCoinName}.rewardPoolId`
|
|
124
|
-
);
|
|
125
|
-
let spool: Spool | undefined = undefined;
|
|
126
|
-
coinPrices = coinPrices || (await query.utils.getCoinPrices());
|
|
227
|
+
coinPrices = coinPrices || (await query.getAllCoinPrices());
|
|
127
228
|
|
|
128
229
|
if (indexer) {
|
|
129
230
|
const spoolIndexer = await query.indexer.getSpool(marketCoinName);
|
|
130
231
|
const coinName =
|
|
131
232
|
query.utils.parseCoinName<SupportStakeCoins>(marketCoinName);
|
|
132
233
|
const rewardCoinName = query.utils.getSpoolRewardCoinName(marketCoinName);
|
|
133
|
-
spoolIndexer.coinPrice = coinPrices?.[coinName]
|
|
234
|
+
spoolIndexer.coinPrice = coinPrices?.[coinName] ?? spoolIndexer.coinPrice;
|
|
134
235
|
spoolIndexer.marketCoinPrice =
|
|
135
|
-
|
|
136
|
-
(marketPool ? marketPool.conversionRate : 0) ||
|
|
137
|
-
spoolIndexer.marketCoinPrice;
|
|
236
|
+
coinPrices?.[marketCoinName] ?? spoolIndexer.marketCoinPrice;
|
|
138
237
|
spoolIndexer.rewardCoinPrice =
|
|
139
|
-
coinPrices?.[rewardCoinName]
|
|
238
|
+
coinPrices?.[rewardCoinName] ?? spoolIndexer.rewardCoinPrice;
|
|
140
239
|
|
|
141
240
|
return spoolIndexer;
|
|
142
241
|
}
|
|
143
242
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
showContent: true,
|
|
148
|
-
}
|
|
149
|
-
);
|
|
150
|
-
|
|
151
|
-
if (!(spoolObjectResponse[0] && spoolObjectResponse[1])) {
|
|
152
|
-
throw new Error('Fail to fetch spoolObjectResponse!');
|
|
153
|
-
}
|
|
243
|
+
requiredObjects ??= (await queryRequiredSpoolObjects(query, [coinName]))[
|
|
244
|
+
coinName
|
|
245
|
+
];
|
|
154
246
|
|
|
155
247
|
const rewardCoinName = query.utils.getSpoolRewardCoinName(marketCoinName);
|
|
156
248
|
coinPrices = coinPrices || (await query.utils.getCoinPrices());
|
|
157
249
|
|
|
158
|
-
const
|
|
159
|
-
const
|
|
160
|
-
if (spoolObject.content && 'fields' in spoolObject.content) {
|
|
161
|
-
const spoolFields = spoolObject.content.fields as any;
|
|
162
|
-
const parsedSpoolData = parseOriginSpoolData({
|
|
163
|
-
stakeType: spoolFields.stake_type,
|
|
164
|
-
maxDistributedPoint: spoolFields.max_distributed_point,
|
|
165
|
-
distributedPoint: spoolFields.distributed_point,
|
|
166
|
-
distributedPointPerPeriod: spoolFields.distributed_point_per_period,
|
|
167
|
-
pointDistributionTime: spoolFields.point_distribution_time,
|
|
168
|
-
maxStake: spoolFields.max_stakes,
|
|
169
|
-
stakes: spoolFields.stakes,
|
|
170
|
-
index: spoolFields.index,
|
|
171
|
-
createdAt: spoolFields.created_at,
|
|
172
|
-
lastUpdate: spoolFields.last_update,
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
const marketCoinPrice =
|
|
176
|
-
(coinPrices?.[coinName] ?? 0) * marketPool.conversionRate;
|
|
177
|
-
const marketCoinDecimal = query.utils.getCoinDecimal(marketCoinName);
|
|
178
|
-
const calculatedSpoolData = calculateSpoolData(
|
|
179
|
-
parsedSpoolData,
|
|
180
|
-
marketCoinPrice,
|
|
181
|
-
marketCoinDecimal
|
|
182
|
-
);
|
|
250
|
+
const parsedSpoolObjects = parseSpoolObjects(requiredObjects);
|
|
251
|
+
const parsedSpoolData = parseOriginSpoolData(parsedSpoolObjects);
|
|
183
252
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
spool_id: rewardPoolFields.spool_id,
|
|
192
|
-
});
|
|
253
|
+
const marketCoinPrice = coinPrices?.[marketCoinName] ?? 0;
|
|
254
|
+
const marketCoinDecimal = query.utils.getCoinDecimal(marketCoinName);
|
|
255
|
+
const calculatedSpoolData = calculateSpoolData(
|
|
256
|
+
parsedSpoolData,
|
|
257
|
+
marketCoinPrice,
|
|
258
|
+
marketCoinDecimal
|
|
259
|
+
);
|
|
193
260
|
|
|
194
|
-
|
|
195
|
-
|
|
261
|
+
const parsedSpoolRewardPoolData =
|
|
262
|
+
parseOriginSpoolRewardPoolData(parsedSpoolObjects);
|
|
196
263
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
parsedSpoolRewardPoolData,
|
|
200
|
-
calculatedSpoolData,
|
|
201
|
-
rewardCoinPrice,
|
|
202
|
-
rewardCoinDecimal
|
|
203
|
-
);
|
|
264
|
+
const rewardCoinPrice = coinPrices?.[rewardCoinName] ?? 0;
|
|
265
|
+
const rewardCoinDecimal = query.utils.getCoinDecimal(rewardCoinName);
|
|
204
266
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
: query.utils.parseCoinType(rewardCoinName),
|
|
213
|
-
sCoinType: marketPool.sCoinType,
|
|
214
|
-
coinDecimal: query.utils.getCoinDecimal(coinName),
|
|
215
|
-
rewardCoinDecimal: query.utils.getCoinDecimal(rewardCoinName),
|
|
216
|
-
coinPrice: coinPrices?.[coinName] ?? 0,
|
|
217
|
-
marketCoinPrice: marketCoinPrice,
|
|
218
|
-
rewardCoinPrice: rewardCoinPrice,
|
|
219
|
-
maxPoint: parsedSpoolData.maxPoint,
|
|
220
|
-
distributedPoint: parsedSpoolData.distributedPoint,
|
|
221
|
-
maxStake: parsedSpoolData.maxStake,
|
|
222
|
-
...calculatedSpoolData,
|
|
223
|
-
exchangeRateNumerator: parsedSpoolRewardPoolData.exchangeRateNumerator,
|
|
224
|
-
exchangeRateDenominator:
|
|
225
|
-
parsedSpoolRewardPoolData.exchangeRateDenominator,
|
|
226
|
-
...calculatedRewardPoolData,
|
|
227
|
-
};
|
|
228
|
-
}
|
|
229
|
-
}
|
|
267
|
+
const calculatedRewardPoolData = calculateSpoolRewardPoolData(
|
|
268
|
+
parsedSpoolData,
|
|
269
|
+
parsedSpoolRewardPoolData,
|
|
270
|
+
calculatedSpoolData,
|
|
271
|
+
rewardCoinPrice,
|
|
272
|
+
rewardCoinDecimal
|
|
273
|
+
);
|
|
230
274
|
|
|
231
|
-
return
|
|
275
|
+
return {
|
|
276
|
+
marketCoinName: marketCoinName,
|
|
277
|
+
symbol: query.utils.parseSymbol(marketCoinName),
|
|
278
|
+
coinType: query.utils.parseCoinType(coinName),
|
|
279
|
+
marketCoinType: query.utils.parseMarketCoinType(coinName),
|
|
280
|
+
rewardCoinType: isMarketCoin(rewardCoinName)
|
|
281
|
+
? query.utils.parseMarketCoinType(rewardCoinName)
|
|
282
|
+
: query.utils.parseCoinType(rewardCoinName),
|
|
283
|
+
sCoinType: query.utils.parseSCoinType(marketCoinName),
|
|
284
|
+
coinDecimal: query.utils.getCoinDecimal(coinName),
|
|
285
|
+
rewardCoinDecimal: query.utils.getCoinDecimal(rewardCoinName),
|
|
286
|
+
coinPrice: coinPrices?.[coinName] ?? 0,
|
|
287
|
+
marketCoinPrice: marketCoinPrice,
|
|
288
|
+
rewardCoinPrice: rewardCoinPrice,
|
|
289
|
+
maxPoint: parsedSpoolData.maxPoint,
|
|
290
|
+
distributedPoint: parsedSpoolData.distributedPoint,
|
|
291
|
+
maxStake: parsedSpoolData.maxStake,
|
|
292
|
+
...calculatedSpoolData,
|
|
293
|
+
exchangeRateNumerator: parsedSpoolRewardPoolData.exchangeRateNumerator,
|
|
294
|
+
exchangeRateDenominator: parsedSpoolRewardPoolData.exchangeRateDenominator,
|
|
295
|
+
...calculatedRewardPoolData,
|
|
296
|
+
};
|
|
232
297
|
};
|
|
233
298
|
|
|
234
299
|
/**
|
package/src/test.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ScallopQuery } from './models';
|
|
2
|
+
|
|
3
|
+
const main = async () => {
|
|
4
|
+
try {
|
|
5
|
+
const query = new ScallopQuery({});
|
|
6
|
+
await query.init();
|
|
7
|
+
|
|
8
|
+
const res = await query.getSpool('ssui');
|
|
9
|
+
console.dir(res, { depth: null });
|
|
10
|
+
} catch (e) {
|
|
11
|
+
console.error(e);
|
|
12
|
+
} finally {
|
|
13
|
+
process.exit(0);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
main();
|
package/src/types/query/spool.ts
CHANGED
|
@@ -37,6 +37,27 @@ export type OriginSpoolData = {
|
|
|
37
37
|
lastUpdate: string;
|
|
38
38
|
};
|
|
39
39
|
|
|
40
|
+
export type SpoolData = {
|
|
41
|
+
created_at: string;
|
|
42
|
+
distributed_point: string;
|
|
43
|
+
distributed_point_per_period: string;
|
|
44
|
+
id: {
|
|
45
|
+
id: string;
|
|
46
|
+
};
|
|
47
|
+
index: string;
|
|
48
|
+
last_update: string;
|
|
49
|
+
max_distributed_point: string;
|
|
50
|
+
max_stakes: string;
|
|
51
|
+
point_distribution_time: string;
|
|
52
|
+
stake_type: {
|
|
53
|
+
type: string;
|
|
54
|
+
fields: {
|
|
55
|
+
name: string;
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
stakes: string;
|
|
59
|
+
};
|
|
60
|
+
|
|
40
61
|
export type ParsedSpoolData = {
|
|
41
62
|
stakeType: string;
|
|
42
63
|
maxPoint: number;
|
package/src/utils/core.ts
CHANGED
|
@@ -4,8 +4,15 @@ export const parseObjectAs = <T>(object: SuiObjectData): T => {
|
|
|
4
4
|
if (!(object && object.content && 'fields' in object.content))
|
|
5
5
|
throw new Error(`Failed to parse object`);
|
|
6
6
|
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
const fields = object.content.fields as any;
|
|
8
|
+
|
|
9
|
+
if (typeof fields === 'object' && 'value' in fields) {
|
|
10
|
+
const value = fields.value;
|
|
11
|
+
if (typeof value === 'object' && 'fields' in value)
|
|
12
|
+
return value.fields as T;
|
|
13
|
+
return value as T;
|
|
14
|
+
} else if (typeof fields === 'object') {
|
|
15
|
+
return fields as T;
|
|
16
|
+
}
|
|
17
|
+
return fields as T;
|
|
11
18
|
};
|
package/src/utils/index.ts
CHANGED