@scallop-io/sui-scallop-sdk 1.4.15-rc.1 → 1.4.15-rc.3
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 +2 -0
- package/dist/constants/tokenBucket.d.ts +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +327 -194
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +325 -194
- package/dist/index.mjs.map +1 -1
- package/dist/models/scallopQuery.d.ts +5 -2
- package/dist/queries/poolAddressesQuery.d.ts +3 -0
- package/dist/queries/spoolQuery.d.ts +6 -2
- package/dist/test.d.ts +1 -0
- package/dist/types/builder/core.d.ts +3 -3
- package/dist/types/query/spool.d.ts +20 -0
- package/dist/utils/index.d.ts +1 -0
- package/package.json +1 -1
- package/src/builders/coreBuilder.ts +1 -1
- package/src/constants/poolAddress.ts +136 -71
- package/src/constants/tokenBucket.ts +1 -1
- package/src/index.ts +1 -0
- package/src/models/scallopCache.ts +50 -2
- package/src/models/scallopClient.ts +1 -0
- package/src/models/scallopQuery.ts +12 -16
- package/src/queries/coreQuery.ts +30 -10
- package/src/queries/poolAddressesQuery.ts +14 -2
- package/src/queries/portfolioQuery.ts +1 -1
- package/src/queries/spoolQuery.ts +186 -121
- package/src/test.ts +17 -0
- package/src/types/builder/core.ts +3 -2
- package/src/types/query/spool.ts +21 -0
- package/src/utils/core.ts +11 -4
- package/src/utils/index.ts +1 -0
package/src/queries/coreQuery.ts
CHANGED
|
@@ -13,7 +13,11 @@ import {
|
|
|
13
13
|
calculateMarketCollateralData,
|
|
14
14
|
parseObjectAs,
|
|
15
15
|
} from '../utils';
|
|
16
|
-
import type {
|
|
16
|
+
import type {
|
|
17
|
+
SuiObjectResponse,
|
|
18
|
+
SuiObjectData,
|
|
19
|
+
SuiParsedData,
|
|
20
|
+
} from '@mysten/sui/client';
|
|
17
21
|
import type { SuiObjectArg } from '@scallop-io/sui-kit';
|
|
18
22
|
import type { ScallopAddress, ScallopCache, ScallopQuery } from '../models';
|
|
19
23
|
import {
|
|
@@ -902,14 +906,32 @@ export const getObligations = async (
|
|
|
902
906
|
const keyObjects = keyObjectsResponse.filter((ref) => !!ref.data);
|
|
903
907
|
|
|
904
908
|
const obligations: Obligation[] = [];
|
|
909
|
+
// fetch all obligations with multi get objects
|
|
910
|
+
const obligationsObjects = await queryMultipleObjects(
|
|
911
|
+
address.cache,
|
|
912
|
+
keyObjects
|
|
913
|
+
.map((ref) => ref.data?.content)
|
|
914
|
+
.filter(
|
|
915
|
+
(content): content is SuiParsedData & { dataType: 'moveObject' } =>
|
|
916
|
+
content?.dataType === 'moveObject'
|
|
917
|
+
)
|
|
918
|
+
.map((content) => (content.fields as any).ownership.fields.of),
|
|
919
|
+
{
|
|
920
|
+
showContent: true,
|
|
921
|
+
}
|
|
922
|
+
);
|
|
923
|
+
|
|
905
924
|
await Promise.allSettled(
|
|
906
|
-
keyObjects.map(async ({ data }) => {
|
|
925
|
+
keyObjects.map(async ({ data }, idx) => {
|
|
907
926
|
const keyId = data?.objectId;
|
|
908
927
|
const content = data?.content;
|
|
909
928
|
if (keyId && content && 'fields' in content) {
|
|
910
929
|
const fields = content.fields as any;
|
|
911
930
|
const obligationId = String(fields.ownership.fields.of);
|
|
912
|
-
const locked = await getObligationLocked(
|
|
931
|
+
const locked = await getObligationLocked(
|
|
932
|
+
address.cache,
|
|
933
|
+
obligationsObjects[idx]
|
|
934
|
+
);
|
|
913
935
|
obligations.push({ id: obligationId, keyId, locked });
|
|
914
936
|
}
|
|
915
937
|
})
|
|
@@ -929,7 +951,7 @@ export const getObligationLocked = async (
|
|
|
929
951
|
cache: ScallopCache,
|
|
930
952
|
obligation: string | SuiObjectData
|
|
931
953
|
) => {
|
|
932
|
-
const
|
|
954
|
+
const obligationObjectData =
|
|
933
955
|
typeof obligation === 'string'
|
|
934
956
|
? (
|
|
935
957
|
await cache.queryGetObject(obligation, {
|
|
@@ -939,13 +961,11 @@ export const getObligationLocked = async (
|
|
|
939
961
|
: obligation;
|
|
940
962
|
let obligationLocked = false;
|
|
941
963
|
if (
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
'lock_key' in
|
|
964
|
+
obligationObjectData &&
|
|
965
|
+
obligationObjectData?.content?.dataType === 'moveObject' &&
|
|
966
|
+
'lock_key' in obligationObjectData.content.fields
|
|
945
967
|
) {
|
|
946
|
-
obligationLocked = Boolean(
|
|
947
|
-
obligationObjectResponse.content.fields.lock_key
|
|
948
|
-
);
|
|
968
|
+
obligationLocked = Boolean(obligationObjectData.content.fields.lock_key);
|
|
949
969
|
}
|
|
950
970
|
|
|
951
971
|
return obligationLocked;
|
|
@@ -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,12 +12,15 @@ 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;
|
|
18
19
|
supplyLimitKey?: string;
|
|
19
20
|
borrowLimitKey?: string;
|
|
20
21
|
isolatedAssetKey?: string;
|
|
22
|
+
coinDecimalId?: string;
|
|
23
|
+
borrowIncentivePoolId?: string;
|
|
21
24
|
}
|
|
22
25
|
>
|
|
23
26
|
> = {};
|
|
@@ -106,12 +109,19 @@ export const getAllAddresses = async (query: ScallopQuery) => {
|
|
|
106
109
|
|
|
107
110
|
const spool = query.address.get(
|
|
108
111
|
// @ts-ignore
|
|
109
|
-
`spool.pools.s${coinName
|
|
112
|
+
`spool.pools.s${coinName}.id`
|
|
110
113
|
);
|
|
111
114
|
const rewardPool = query.address.get(
|
|
112
115
|
// @ts-ignore
|
|
113
116
|
`spool.pools.s${coinName}.rewardPoolId`
|
|
114
117
|
);
|
|
118
|
+
const sCoinTreasury = query.address.get(
|
|
119
|
+
// @ts-ignore
|
|
120
|
+
`scoin.coins.s${coinName}.treasury`
|
|
121
|
+
);
|
|
122
|
+
const coinDecimalId = query.address.get(
|
|
123
|
+
`core.coins.${coinName}.metaData`
|
|
124
|
+
);
|
|
115
125
|
results[coinName as SupportPoolCoins] = {
|
|
116
126
|
lendingPoolAddress: addresses[0],
|
|
117
127
|
collateralPoolAddress: addresses[1],
|
|
@@ -124,6 +134,8 @@ export const getAllAddresses = async (query: ScallopQuery) => {
|
|
|
124
134
|
isolatedAssetKey: addresses[8],
|
|
125
135
|
spool,
|
|
126
136
|
spoolReward: rewardPool,
|
|
137
|
+
sCoinTreasury,
|
|
138
|
+
coinDecimalId,
|
|
127
139
|
};
|
|
128
140
|
|
|
129
141
|
await new Promise((resolve) => setTimeout(resolve, 200));
|
|
@@ -366,7 +366,7 @@ export const getObligationAccount = async (
|
|
|
366
366
|
coinPrices =
|
|
367
367
|
coinPrices ?? (await query.getAllCoinPrices({ marketPools: market.pools }));
|
|
368
368
|
coinAmounts =
|
|
369
|
-
coinAmounts
|
|
369
|
+
coinAmounts ?? (await query.getCoinAmounts(coinNames, ownerAddress));
|
|
370
370
|
|
|
371
371
|
const [obligationQuery, borrowIncentivePools, borrowIncentiveAccounts] =
|
|
372
372
|
await Promise.all([
|
|
@@ -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();
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
SuiTxBlock as SuiKitTxBlock,
|
|
3
3
|
SuiObjectArg,
|
|
4
|
+
SuiTxArg,
|
|
4
5
|
} from '@scallop-io/sui-kit';
|
|
5
6
|
import type { Argument, TransactionResult } from '@mysten/sui/transactions';
|
|
6
7
|
import type { ScallopBuilder } from '../../models';
|
|
@@ -65,7 +66,7 @@ export type CoreNormalMethods = {
|
|
|
65
66
|
obligation: SuiObjectArg,
|
|
66
67
|
obligationKey: SuiObjectArg,
|
|
67
68
|
borrowReferral: SuiObjectArg,
|
|
68
|
-
amount: number,
|
|
69
|
+
amount: number | SuiTxArg,
|
|
69
70
|
poolCoinName: SupportPoolCoins
|
|
70
71
|
) => TransactionResult;
|
|
71
72
|
borrowEntry: (
|
|
@@ -80,7 +81,7 @@ export type CoreNormalMethods = {
|
|
|
80
81
|
poolCoinName: SupportPoolCoins
|
|
81
82
|
) => void;
|
|
82
83
|
borrowFlashLoan: (
|
|
83
|
-
amount: number,
|
|
84
|
+
amount: number | SuiTxArg,
|
|
84
85
|
poolCoinName: SupportPoolCoins
|
|
85
86
|
) => TransactionResult;
|
|
86
87
|
repayFlashLoan: (
|
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