@scallop-io/sui-scallop-sdk 1.4.1 → 1.4.2-rc.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 +1 -1
- package/dist/constants/poolAddress.d.ts +16 -4
- package/dist/constants/queryKeys.d.ts +2 -2
- package/dist/constants/tokenBucket.d.ts +2 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1270 -588
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1225 -544
- package/dist/index.mjs.map +1 -1
- package/dist/models/scallopBuilder.d.ts +2 -1
- package/dist/models/scallopCache.d.ts +2 -0
- package/dist/models/scallopQuery.d.ts +38 -20
- package/dist/models/scallopUtils.d.ts +4 -2
- package/dist/queries/borrowIncentiveQuery.d.ts +12 -0
- package/dist/queries/coreQuery.d.ts +18 -19
- package/dist/queries/index.d.ts +2 -0
- package/dist/queries/isolatedAssetQuery.d.ts +2 -2
- package/dist/queries/objectsQuery.d.ts +3 -0
- package/dist/queries/poolAddressesQuery.d.ts +18 -0
- package/dist/queries/spoolQuery.d.ts +6 -2
- package/dist/test.d.ts +1 -0
- package/dist/types/builder/borrowIncentive.d.ts +5 -5
- package/dist/types/builder/core.d.ts +20 -16
- package/dist/types/builder/loyaltyProgram.d.ts +1 -1
- package/dist/types/builder/referral.d.ts +4 -4
- package/dist/types/builder/sCoin.d.ts +2 -2
- package/dist/types/builder/spool.d.ts +4 -4
- package/dist/types/builder/vesca.d.ts +6 -6
- package/dist/types/query/core.d.ts +22 -5
- package/dist/types/query/spool.d.ts +20 -0
- package/dist/types/utils.d.ts +7 -2
- package/dist/utils/core.d.ts +2 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/query.d.ts +1 -1
- package/dist/utils/util.d.ts +1 -0
- package/package.json +7 -7
- package/src/builders/borrowIncentiveBuilder.ts +28 -15
- package/src/builders/coreBuilder.ts +76 -49
- package/src/builders/loyaltyProgramBuilder.ts +4 -3
- package/src/builders/referralBuilder.ts +23 -10
- package/src/builders/sCoinBuilder.ts +8 -6
- package/src/builders/spoolBuilder.ts +21 -14
- package/src/builders/vescaBuilder.ts +23 -13
- package/src/constants/common.ts +1 -12
- package/src/constants/poolAddress.ts +336 -10
- package/src/constants/queryKeys.ts +9 -5
- package/src/constants/testAddress.ts +42 -0
- package/src/constants/tokenBucket.ts +2 -2
- package/src/index.ts +1 -0
- package/src/models/scallopBuilder.ts +59 -2
- package/src/models/scallopCache.ts +171 -19
- package/src/models/scallopClient.ts +16 -10
- package/src/models/scallopQuery.ts +36 -28
- package/src/models/scallopUtils.ts +11 -4
- package/src/queries/borrowIncentiveQuery.ts +6 -8
- package/src/queries/borrowLimitQuery.ts +1 -0
- package/src/queries/coreQuery.ts +408 -258
- package/src/queries/index.ts +2 -0
- package/src/queries/isolatedAssetQuery.ts +37 -31
- package/src/queries/objectsQuery.ts +20 -0
- package/src/queries/poolAddressesQuery.ts +146 -0
- package/src/queries/portfolioQuery.ts +31 -13
- package/src/queries/priceQuery.ts +3 -1
- package/src/queries/spoolQuery.ts +189 -122
- package/src/test.ts +17 -0
- package/src/types/builder/borrowIncentive.ts +8 -5
- package/src/types/builder/core.ts +23 -17
- package/src/types/builder/loyaltyProgram.ts +1 -1
- package/src/types/builder/referral.ts +6 -4
- package/src/types/builder/sCoin.ts +2 -2
- package/src/types/builder/spool.ts +4 -4
- package/src/types/builder/vesca.ts +9 -6
- package/src/types/query/core.ts +21 -5
- package/src/types/query/spool.ts +21 -0
- package/src/types/utils.ts +8 -3
- package/src/utils/core.ts +18 -0
- package/src/utils/index.ts +2 -0
- package/src/utils/query.ts +21 -5
- package/src/utils/tokenBucket.ts +9 -29
- package/src/utils/util.ts +8 -0
|
@@ -236,6 +236,36 @@ export const TEST_ADDRESSES: AddressesInterface = {
|
|
|
236
236
|
},
|
|
237
237
|
},
|
|
238
238
|
},
|
|
239
|
+
deep: {
|
|
240
|
+
id: '0xdeeb7a4662eec9f2f3def03fb937a663dddaa2e215b8078a284d026b7946c270',
|
|
241
|
+
metaData:
|
|
242
|
+
'0x6e60b051a08fa836f5a7acd7c464c8d9825bc29c44657fe170fe9b8e1e4770c0',
|
|
243
|
+
treasury: '',
|
|
244
|
+
oracle: {
|
|
245
|
+
supra: '',
|
|
246
|
+
switchboard: '',
|
|
247
|
+
pyth: {
|
|
248
|
+
feed: '29bdd5248234e33bd93d3b81100b5fa32eaa5997843847e2c2cb16d7c6d9f7ff',
|
|
249
|
+
feedObject:
|
|
250
|
+
'0x8c7f3a322b94cc69db2a2ac575cbd94bf5766113324c3a3eceac91e3e88a51ed',
|
|
251
|
+
},
|
|
252
|
+
},
|
|
253
|
+
},
|
|
254
|
+
fud: {
|
|
255
|
+
id: '0x76cb819b01abed502bee8a702b4c2d547532c12f25001c9dea795a5e631c26f1',
|
|
256
|
+
metaData:
|
|
257
|
+
'0x01087411ef48aaac1eb6e24803213e3a60a03b147dac930e5e341f17a85e524e',
|
|
258
|
+
treasury: '',
|
|
259
|
+
oracle: {
|
|
260
|
+
supra: '',
|
|
261
|
+
switchboard: '',
|
|
262
|
+
pyth: {
|
|
263
|
+
feed: '6a4090703da959247727f2b490eb21aea95c8684ecfac675f432008830890c75',
|
|
264
|
+
feedObject:
|
|
265
|
+
'0x4531c3ed0d22f21f5fce882905372006c9aafa30f01db03b789e95a6c50de7b2',
|
|
266
|
+
},
|
|
267
|
+
},
|
|
268
|
+
},
|
|
239
269
|
},
|
|
240
270
|
oracles: {
|
|
241
271
|
xOracle:
|
|
@@ -513,6 +543,18 @@ export const TEST_ADDRESSES: AddressesInterface = {
|
|
|
513
543
|
treasury:
|
|
514
544
|
'0xfd0f02def6358a1f266acfa1493d4707ee8387460d434fb667d63d755ff907ed',
|
|
515
545
|
},
|
|
546
|
+
sdeep: {
|
|
547
|
+
coinType:
|
|
548
|
+
'0xeb7a05a3224837c5e5503575aed0be73c091d1ce5e43aa3c3e716e0ae614608f::scallop_deep::SCALLOP_DEEP',
|
|
549
|
+
treasury:
|
|
550
|
+
'0xc63838fabe37b25ad897392d89876d920f5e0c6a406bf3abcb84753d2829bc88',
|
|
551
|
+
},
|
|
552
|
+
sfud: {
|
|
553
|
+
coinType:
|
|
554
|
+
'0xe56d5167f427cbe597da9e8150ef5c337839aaf46891d62468dcf80bdd8e10d1::scallop_fud::SCALLOP_FUD',
|
|
555
|
+
treasury:
|
|
556
|
+
'0xf25212f11d182decff7a86165699a73e3d5787aced203ca539f43cfbc10db867',
|
|
557
|
+
},
|
|
516
558
|
},
|
|
517
559
|
},
|
|
518
560
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const DEFAULT_TOKENS_PER_INTERVAL =
|
|
2
|
-
export const DEFAULT_INTERVAL_IN_MS =
|
|
1
|
+
export const DEFAULT_TOKENS_PER_INTERVAL = 10;
|
|
2
|
+
export const DEFAULT_INTERVAL_IN_MS = 250;
|
package/src/index.ts
CHANGED
|
@@ -7,7 +7,13 @@ import { ScallopQuery } from './scallopQuery';
|
|
|
7
7
|
import { ScallopUtils } from './scallopUtils';
|
|
8
8
|
import type { SuiTransactionBlockResponse } from '@mysten/sui/client';
|
|
9
9
|
import type { Transaction } from '@mysten/sui/transactions';
|
|
10
|
-
import type {
|
|
10
|
+
import type {
|
|
11
|
+
SuiAmountsArg,
|
|
12
|
+
SuiTxBlock as SuiKitTxBlock,
|
|
13
|
+
SuiObjectArg,
|
|
14
|
+
SuiTxArg,
|
|
15
|
+
SuiVecTxArg,
|
|
16
|
+
} from '@scallop-io/sui-kit';
|
|
11
17
|
import type {
|
|
12
18
|
ScallopBuilderParams,
|
|
13
19
|
ScallopTxBlock,
|
|
@@ -104,7 +110,7 @@ export class ScallopBuilder {
|
|
|
104
110
|
await this.address.read();
|
|
105
111
|
}
|
|
106
112
|
await this.query.init(force, this.address);
|
|
107
|
-
await this.utils.init(force, this.address);
|
|
113
|
+
// await this.utils.init(force, this.address);
|
|
108
114
|
}
|
|
109
115
|
|
|
110
116
|
/**
|
|
@@ -215,4 +221,55 @@ export class ScallopBuilder {
|
|
|
215
221
|
txBlock
|
|
216
222
|
)) as SuiTransactionBlockResponse;
|
|
217
223
|
}
|
|
224
|
+
|
|
225
|
+
public moveCall(
|
|
226
|
+
txb: ScallopTxBlock | SuiKitTxBlock,
|
|
227
|
+
target: string,
|
|
228
|
+
args?: (SuiTxArg | SuiVecTxArg | SuiObjectArg | SuiAmountsArg)[],
|
|
229
|
+
typeArgs?: string[]
|
|
230
|
+
) {
|
|
231
|
+
// Disable for now
|
|
232
|
+
// const resolvedQueryTarget =
|
|
233
|
+
// await this.cache.queryGetNormalizedMoveFunction(target);
|
|
234
|
+
// if (!resolvedQueryTarget) throw new Error('Invalid query target');
|
|
235
|
+
|
|
236
|
+
// const { parameters } = resolvedQueryTarget;
|
|
237
|
+
// try {
|
|
238
|
+
// // we can try resolve the args first
|
|
239
|
+
// const resolvedArgs = await Promise.all(
|
|
240
|
+
// (args ?? []).map(async (arg, idx) => {
|
|
241
|
+
// if (typeof arg !== 'string') return arg;
|
|
242
|
+
|
|
243
|
+
// const cachedData = (await this.cache.queryGetObject(arg))?.data;
|
|
244
|
+
// if (!cachedData) return arg;
|
|
245
|
+
|
|
246
|
+
// const owner = cachedData.owner;
|
|
247
|
+
// if (!owner || typeof owner !== 'object' || !('Shared' in owner))
|
|
248
|
+
// return {
|
|
249
|
+
// objectId: cachedData.objectId,
|
|
250
|
+
// version: cachedData.version,
|
|
251
|
+
// digest: cachedData.digest,
|
|
252
|
+
// };
|
|
253
|
+
|
|
254
|
+
// const parameter = parameters[idx];
|
|
255
|
+
// if (
|
|
256
|
+
// typeof parameter !== 'object' ||
|
|
257
|
+
// !('MutableReference' in parameter || 'Reference' in parameter)
|
|
258
|
+
// )
|
|
259
|
+
// return arg;
|
|
260
|
+
|
|
261
|
+
// return {
|
|
262
|
+
// objectId: cachedData.objectId,
|
|
263
|
+
// initialSharedVersion: owner.Shared.initial_shared_version,
|
|
264
|
+
// mutable: 'MutableReference' in parameter,
|
|
265
|
+
// };
|
|
266
|
+
// })
|
|
267
|
+
// );
|
|
268
|
+
// return txb.moveCall(target, resolvedArgs, typeArgs);
|
|
269
|
+
// } catch (e: any) {
|
|
270
|
+
// console.error(e.message);
|
|
271
|
+
// return txb.moveCall(target, args, typeArgs);
|
|
272
|
+
// }
|
|
273
|
+
return txb.moveCall(target, args, typeArgs);
|
|
274
|
+
}
|
|
218
275
|
}
|
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
SuiObjectArg,
|
|
4
4
|
SuiTxBlock,
|
|
5
5
|
normalizeStructTag,
|
|
6
|
+
parseStructTag,
|
|
6
7
|
} from '@scallop-io/sui-kit';
|
|
7
8
|
import { SuiKit } from '@scallop-io/sui-kit';
|
|
8
9
|
import type {
|
|
@@ -106,6 +107,12 @@ export class ScallopCache {
|
|
|
106
107
|
);
|
|
107
108
|
}
|
|
108
109
|
|
|
110
|
+
private retryFn(errCount: number, e: any) {
|
|
111
|
+
if (errCount === 5) return false;
|
|
112
|
+
if (e.status === 429) return true;
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
|
|
109
116
|
/**
|
|
110
117
|
* @description Provides cache for inspectTxn of the SuiKit.
|
|
111
118
|
* @param QueryInspectTxnParams
|
|
@@ -119,19 +126,75 @@ export class ScallopCache {
|
|
|
119
126
|
}: QueryInspectTxnParams): Promise<DevInspectResults | null> {
|
|
120
127
|
const txBlock = new SuiTxBlock();
|
|
121
128
|
|
|
122
|
-
|
|
129
|
+
const resolvedQueryTarget =
|
|
130
|
+
await this.queryGetNormalizedMoveFunction(queryTarget);
|
|
131
|
+
if (!resolvedQueryTarget) throw new Error('Invalid query target');
|
|
132
|
+
|
|
133
|
+
const { parameters } = resolvedQueryTarget;
|
|
134
|
+
|
|
135
|
+
const resolvedArgs = await Promise.all(
|
|
136
|
+
(args ?? []).map(async (arg, idx) => {
|
|
137
|
+
if (typeof arg !== 'string') return arg;
|
|
138
|
+
|
|
139
|
+
const cachedData = (await this.queryGetObject(arg))?.data;
|
|
140
|
+
if (!cachedData) return arg;
|
|
141
|
+
|
|
142
|
+
const owner = cachedData.owner;
|
|
143
|
+
if (!owner || typeof owner !== 'object' || !('Shared' in owner))
|
|
144
|
+
return {
|
|
145
|
+
objectId: cachedData.objectId,
|
|
146
|
+
version: cachedData.version,
|
|
147
|
+
digest: cachedData.digest,
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
const parameter = parameters[idx];
|
|
151
|
+
if (
|
|
152
|
+
typeof parameter !== 'object' ||
|
|
153
|
+
!('MutableReference' in parameter || 'Reference' in parameter)
|
|
154
|
+
)
|
|
155
|
+
return arg;
|
|
156
|
+
|
|
157
|
+
return {
|
|
158
|
+
objectId: cachedData.objectId,
|
|
159
|
+
initialSharedVersion: owner.Shared.initial_shared_version,
|
|
160
|
+
mutable: 'MutableReference' in parameter,
|
|
161
|
+
};
|
|
162
|
+
})
|
|
163
|
+
);
|
|
164
|
+
txBlock.moveCall(queryTarget, resolvedArgs, typeArgs);
|
|
123
165
|
|
|
124
166
|
const query = await this.queryClient.fetchQuery({
|
|
167
|
+
retry: this.retryFn,
|
|
168
|
+
retryDelay: 1000,
|
|
125
169
|
queryKey: queryKeys.rpc.getInspectTxn(queryTarget, args, typeArgs),
|
|
126
170
|
queryFn: async () => {
|
|
127
|
-
return await callWithRateLimit(
|
|
128
|
-
this.
|
|
171
|
+
return await callWithRateLimit(
|
|
172
|
+
this.tokenBucket,
|
|
173
|
+
async () => await this.suiKit.inspectTxn(txBlock)
|
|
129
174
|
);
|
|
130
175
|
},
|
|
131
176
|
});
|
|
132
177
|
return query;
|
|
133
178
|
}
|
|
134
179
|
|
|
180
|
+
public async queryGetNormalizedMoveFunction(target: string) {
|
|
181
|
+
const { address, module, name } = parseStructTag(target);
|
|
182
|
+
return this.queryClient.fetchQuery({
|
|
183
|
+
queryKey: queryKeys.rpc.getNormalizedMoveFunction(target),
|
|
184
|
+
queryFn: async () => {
|
|
185
|
+
return await callWithRateLimit(
|
|
186
|
+
this.tokenBucket,
|
|
187
|
+
async () =>
|
|
188
|
+
await this.suiKit.client().getNormalizedMoveFunction({
|
|
189
|
+
package: address,
|
|
190
|
+
module,
|
|
191
|
+
function: name,
|
|
192
|
+
})
|
|
193
|
+
);
|
|
194
|
+
},
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
|
|
135
198
|
/**
|
|
136
199
|
* @description Provides cache for getObject of the SuiKit.
|
|
137
200
|
* @param objectId
|
|
@@ -141,15 +204,24 @@ export class ScallopCache {
|
|
|
141
204
|
public async queryGetObject(
|
|
142
205
|
objectId: string,
|
|
143
206
|
options?: SuiObjectDataOptions
|
|
144
|
-
)
|
|
207
|
+
) {
|
|
208
|
+
options = {
|
|
209
|
+
...options,
|
|
210
|
+
showOwner: true,
|
|
211
|
+
showContent: true,
|
|
212
|
+
};
|
|
145
213
|
return this.queryClient.fetchQuery({
|
|
146
|
-
|
|
214
|
+
retry: this.retryFn,
|
|
215
|
+
retryDelay: 1000,
|
|
216
|
+
queryKey: queryKeys.rpc.getObject(objectId, options),
|
|
147
217
|
queryFn: async () => {
|
|
148
|
-
return await callWithRateLimit(
|
|
149
|
-
this.
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
218
|
+
return await callWithRateLimit(
|
|
219
|
+
this.tokenBucket,
|
|
220
|
+
async () =>
|
|
221
|
+
await this.client.getObject({
|
|
222
|
+
id: objectId,
|
|
223
|
+
options,
|
|
224
|
+
})
|
|
153
225
|
);
|
|
154
226
|
},
|
|
155
227
|
});
|
|
@@ -170,15 +242,36 @@ export class ScallopCache {
|
|
|
170
242
|
// objectIds.sort();
|
|
171
243
|
|
|
172
244
|
return this.queryClient.fetchQuery({
|
|
245
|
+
retry: this.retryFn,
|
|
246
|
+
retryDelay: 1000,
|
|
173
247
|
queryKey: queryKeys.rpc.getObjects(
|
|
174
248
|
objectIds,
|
|
175
249
|
this.walletAddress,
|
|
176
250
|
options
|
|
177
251
|
),
|
|
178
252
|
queryFn: async () => {
|
|
179
|
-
|
|
180
|
-
this.
|
|
253
|
+
const results = await callWithRateLimit(
|
|
254
|
+
this.tokenBucket,
|
|
255
|
+
async () => await this.suiKit.getObjects(objectIds, options)
|
|
181
256
|
);
|
|
257
|
+
if (results) {
|
|
258
|
+
results.forEach((result) => {
|
|
259
|
+
this.queryClient.setQueriesData(
|
|
260
|
+
{
|
|
261
|
+
exact: false,
|
|
262
|
+
queryKey: queryKeys.rpc.getObject(result.objectId, options),
|
|
263
|
+
},
|
|
264
|
+
{
|
|
265
|
+
data: result,
|
|
266
|
+
error: null,
|
|
267
|
+
},
|
|
268
|
+
{
|
|
269
|
+
updatedAt: Date.now(),
|
|
270
|
+
}
|
|
271
|
+
);
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
return results;
|
|
182
275
|
},
|
|
183
276
|
});
|
|
184
277
|
}
|
|
@@ -189,12 +282,44 @@ export class ScallopCache {
|
|
|
189
282
|
* @returns Promise<PaginatedObjectsResponse>
|
|
190
283
|
*/
|
|
191
284
|
public async queryGetOwnedObjects(input: GetOwnedObjectsParams) {
|
|
285
|
+
// TODO: This query need its own separate rate limiter (as owned objects can theoretically be infinite), need a better way to handle this
|
|
192
286
|
return this.queryClient.fetchQuery({
|
|
287
|
+
retry: this.retryFn,
|
|
288
|
+
retryDelay: 1000,
|
|
193
289
|
queryKey: queryKeys.rpc.getOwnedObjects(input),
|
|
194
290
|
queryFn: async () => {
|
|
195
|
-
|
|
196
|
-
this.
|
|
291
|
+
const results = await callWithRateLimit(
|
|
292
|
+
this.tokenBucket,
|
|
293
|
+
async () => await this.client.getOwnedObjects(input)
|
|
197
294
|
);
|
|
295
|
+
if (results && results.data.length > 0) {
|
|
296
|
+
results.data
|
|
297
|
+
.filter(
|
|
298
|
+
(
|
|
299
|
+
result
|
|
300
|
+
): result is typeof result &
|
|
301
|
+
NonNullable<{ data: SuiObjectData }> => !!result.data
|
|
302
|
+
)
|
|
303
|
+
.forEach((result) => {
|
|
304
|
+
this.queryClient.setQueriesData(
|
|
305
|
+
{
|
|
306
|
+
exact: false,
|
|
307
|
+
queryKey: queryKeys.rpc.getObject(
|
|
308
|
+
result.data.objectId,
|
|
309
|
+
input.options ?? {}
|
|
310
|
+
),
|
|
311
|
+
},
|
|
312
|
+
{
|
|
313
|
+
data: result.data,
|
|
314
|
+
error: null,
|
|
315
|
+
},
|
|
316
|
+
{
|
|
317
|
+
updatedAt: Date.now(),
|
|
318
|
+
}
|
|
319
|
+
);
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
return results;
|
|
198
323
|
},
|
|
199
324
|
});
|
|
200
325
|
}
|
|
@@ -203,10 +328,13 @@ export class ScallopCache {
|
|
|
203
328
|
input: GetDynamicFieldsParams
|
|
204
329
|
): Promise<DynamicFieldPage | null> {
|
|
205
330
|
return this.queryClient.fetchQuery({
|
|
331
|
+
retry: this.retryFn,
|
|
332
|
+
retryDelay: 1000,
|
|
206
333
|
queryKey: queryKeys.rpc.getDynamicFields(input),
|
|
207
334
|
queryFn: async () => {
|
|
208
|
-
return await callWithRateLimit(
|
|
209
|
-
this.
|
|
335
|
+
return await callWithRateLimit(
|
|
336
|
+
this.tokenBucket,
|
|
337
|
+
async () => await this.client.getDynamicFields(input)
|
|
210
338
|
);
|
|
211
339
|
},
|
|
212
340
|
});
|
|
@@ -216,11 +344,32 @@ export class ScallopCache {
|
|
|
216
344
|
input: GetDynamicFieldObjectParams
|
|
217
345
|
): Promise<SuiObjectResponse | null> {
|
|
218
346
|
return this.queryClient.fetchQuery({
|
|
347
|
+
retry: this.retryFn,
|
|
348
|
+
retryDelay: (attemptIndex) => Math.min(1000 * attemptIndex, 8000),
|
|
219
349
|
queryKey: queryKeys.rpc.getDynamicFieldObject(input),
|
|
220
350
|
queryFn: async () => {
|
|
221
|
-
|
|
351
|
+
const result = await callWithRateLimit(this.tokenBucket, () =>
|
|
222
352
|
this.client.getDynamicFieldObject(input)
|
|
223
353
|
);
|
|
354
|
+
if (result?.data) {
|
|
355
|
+
this.queryClient.setQueriesData(
|
|
356
|
+
{
|
|
357
|
+
exact: false,
|
|
358
|
+
queryKey: queryKeys.rpc.getObject(result?.data.objectId, {
|
|
359
|
+
showContent: true,
|
|
360
|
+
showOwner: true,
|
|
361
|
+
}),
|
|
362
|
+
},
|
|
363
|
+
{
|
|
364
|
+
data: result.data,
|
|
365
|
+
error: null,
|
|
366
|
+
},
|
|
367
|
+
{
|
|
368
|
+
updatedAt: Date.now(),
|
|
369
|
+
}
|
|
370
|
+
);
|
|
371
|
+
}
|
|
372
|
+
return result;
|
|
224
373
|
},
|
|
225
374
|
});
|
|
226
375
|
}
|
|
@@ -229,10 +378,13 @@ export class ScallopCache {
|
|
|
229
378
|
owner: string
|
|
230
379
|
): Promise<{ [k: string]: string }> {
|
|
231
380
|
return this.queryClient.fetchQuery({
|
|
381
|
+
retry: this.retryFn,
|
|
382
|
+
retryDelay: 1000,
|
|
232
383
|
queryKey: queryKeys.rpc.getAllCoinBalances(owner),
|
|
233
384
|
queryFn: async () => {
|
|
234
|
-
const allBalances = await callWithRateLimit(
|
|
235
|
-
this.
|
|
385
|
+
const allBalances = await callWithRateLimit(
|
|
386
|
+
this.tokenBucket,
|
|
387
|
+
async () => await this.client.getAllBalances({ owner })
|
|
236
388
|
);
|
|
237
389
|
if (!allBalances) return {};
|
|
238
390
|
const balances = allBalances.reduce(
|
|
@@ -232,7 +232,7 @@ export class ScallopClient {
|
|
|
232
232
|
sign: S = true as S
|
|
233
233
|
): Promise<ScallopClientFnReturnType<S>> {
|
|
234
234
|
const txBlock = this.builder.createTxBlock();
|
|
235
|
-
txBlock.openObligationEntry();
|
|
235
|
+
await txBlock.openObligationEntry();
|
|
236
236
|
if (sign) {
|
|
237
237
|
return (await this.suiKit.signAndSendTxn(
|
|
238
238
|
txBlock
|
|
@@ -283,9 +283,10 @@ export class ScallopClient {
|
|
|
283
283
|
specificObligationId
|
|
284
284
|
);
|
|
285
285
|
} else {
|
|
286
|
-
const [obligation, obligationKey, hotPotato] =
|
|
286
|
+
const [obligation, obligationKey, hotPotato] =
|
|
287
|
+
await txBlock.openObligation();
|
|
287
288
|
await txBlock.addCollateralQuick(amount, collateralCoinName, obligation);
|
|
288
|
-
txBlock.returnObligation(obligation, hotPotato);
|
|
289
|
+
await txBlock.returnObligation(obligation, hotPotato);
|
|
289
290
|
txBlock.transferObjects([obligationKey], sender);
|
|
290
291
|
}
|
|
291
292
|
|
|
@@ -425,7 +426,7 @@ export class ScallopClient {
|
|
|
425
426
|
targetStakeAccount
|
|
426
427
|
);
|
|
427
428
|
} else {
|
|
428
|
-
const account = txBlock.createStakeAccount(stakeMarketCoinName);
|
|
429
|
+
const account = await txBlock.createStakeAccount(stakeMarketCoinName);
|
|
429
430
|
await txBlock.stakeQuick(marketCoin, stakeMarketCoinName, account);
|
|
430
431
|
txBlock.transferObjects([account], sender);
|
|
431
432
|
}
|
|
@@ -611,8 +612,12 @@ export class ScallopClient {
|
|
|
611
612
|
const txBlock = this.builder.createTxBlock();
|
|
612
613
|
const sender = walletAddress ?? this.walletAddress;
|
|
613
614
|
txBlock.setSender(sender);
|
|
614
|
-
const [coin, loan] = txBlock.borrowFlashLoan(amount, poolCoinName);
|
|
615
|
-
txBlock.repayFlashLoan(
|
|
615
|
+
const [coin, loan] = await txBlock.borrowFlashLoan(amount, poolCoinName);
|
|
616
|
+
await txBlock.repayFlashLoan(
|
|
617
|
+
await callback(txBlock, coin),
|
|
618
|
+
loan,
|
|
619
|
+
poolCoinName
|
|
620
|
+
);
|
|
616
621
|
|
|
617
622
|
if (sign) {
|
|
618
623
|
return (await this.suiKit.signAndSendTxn(
|
|
@@ -649,7 +654,7 @@ export class ScallopClient {
|
|
|
649
654
|
const sender = walletAddress ?? this.walletAddress;
|
|
650
655
|
txBlock.setSender(sender);
|
|
651
656
|
|
|
652
|
-
const stakeAccount = txBlock.createStakeAccount(marketCoinName);
|
|
657
|
+
const stakeAccount = await txBlock.createStakeAccount(marketCoinName);
|
|
653
658
|
txBlock.transferObjects([stakeAccount], sender);
|
|
654
659
|
|
|
655
660
|
if (sign) {
|
|
@@ -699,7 +704,7 @@ export class ScallopClient {
|
|
|
699
704
|
if (targetStakeAccount) {
|
|
700
705
|
await txBlock.stakeQuick(amount, stakeMarketCoinName, targetStakeAccount);
|
|
701
706
|
} else {
|
|
702
|
-
const account = txBlock.createStakeAccount(stakeMarketCoinName);
|
|
707
|
+
const account = await txBlock.createStakeAccount(stakeMarketCoinName);
|
|
703
708
|
await txBlock.stakeQuick(amount, stakeMarketCoinName, account);
|
|
704
709
|
txBlock.transferObjects([account], sender);
|
|
705
710
|
}
|
|
@@ -814,7 +819,7 @@ export class ScallopClient {
|
|
|
814
819
|
this.utils.parseCoinName<SupportStakeCoins>(stakeMarketCoinName);
|
|
815
820
|
|
|
816
821
|
if (stakeMarketCoin) {
|
|
817
|
-
const coin = txBlock.withdraw(stakeMarketCoin, stakeCoinName);
|
|
822
|
+
const coin = await txBlock.withdraw(stakeMarketCoin, stakeCoinName);
|
|
818
823
|
await this.utils.mergeSimilarCoins(
|
|
819
824
|
txBlock,
|
|
820
825
|
coin,
|
|
@@ -965,6 +970,7 @@ export class ScallopClient {
|
|
|
965
970
|
const rewardCoinsCollection: Record<string, TransactionResult[]> = {};
|
|
966
971
|
const obligationAccount =
|
|
967
972
|
await this.query.getObligationAccount(obligationId);
|
|
973
|
+
if (!obligationAccount) throw new Error('Obligation not found');
|
|
968
974
|
const rewardCoinNames = Object.values(obligationAccount.borrowIncentives)
|
|
969
975
|
.flatMap(({ rewards }) =>
|
|
970
976
|
rewards.filter(({ availableClaimAmount }) => availableClaimAmount > 0)
|
|
@@ -1047,7 +1053,7 @@ export class ScallopClient {
|
|
|
1047
1053
|
// if market coin found, mint sCoin
|
|
1048
1054
|
if (toDestroyMarketCoin) {
|
|
1049
1055
|
// mint new sCoin
|
|
1050
|
-
const sCoin = txBlock.mintSCoin(
|
|
1056
|
+
const sCoin = await txBlock.mintSCoin(
|
|
1051
1057
|
sCoinName as SupportSCoin,
|
|
1052
1058
|
toDestroyMarketCoin
|
|
1053
1059
|
);
|
|
@@ -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,
|
|
@@ -27,7 +25,6 @@ import {
|
|
|
27
25
|
getLendings,
|
|
28
26
|
getLending,
|
|
29
27
|
getObligationAccounts,
|
|
30
|
-
getObligationAccount,
|
|
31
28
|
getTotalValueLocked,
|
|
32
29
|
queryVeScaKeyIdFromReferralBindings,
|
|
33
30
|
getBindedObligationId,
|
|
@@ -41,13 +38,15 @@ import {
|
|
|
41
38
|
getBorrowIncentivePools,
|
|
42
39
|
getBorrowLimit,
|
|
43
40
|
getIsolatedAssets,
|
|
44
|
-
isIsolatedAsset,
|
|
41
|
+
// isIsolatedAsset,
|
|
45
42
|
getSupplyLimit,
|
|
46
43
|
getSCoinAmount,
|
|
47
44
|
getSCoinAmounts,
|
|
48
45
|
getSCoinSwapRate,
|
|
49
46
|
getSCoinTotalSupply,
|
|
50
47
|
getAllCoinPrices,
|
|
48
|
+
getAllAddresses,
|
|
49
|
+
isIsolatedAsset,
|
|
51
50
|
} from '../queries';
|
|
52
51
|
import {
|
|
53
52
|
ScallopQueryParams,
|
|
@@ -188,6 +187,7 @@ export class ScallopQuery {
|
|
|
188
187
|
/* ==================== Core Query Methods ==================== */
|
|
189
188
|
|
|
190
189
|
/**
|
|
190
|
+
* @deprecated use getMarketPools
|
|
191
191
|
* Query market data.
|
|
192
192
|
* @param indexer - Whether to use indexer.
|
|
193
193
|
* @return Market data.
|
|
@@ -211,7 +211,7 @@ export class ScallopQuery {
|
|
|
211
211
|
* @return Market pools data.
|
|
212
212
|
*/
|
|
213
213
|
public async getMarketPools(
|
|
214
|
-
poolCoinNames
|
|
214
|
+
poolCoinNames: SupportPoolCoins[] = [...SUPPORT_POOLS],
|
|
215
215
|
args?: {
|
|
216
216
|
coinPrices?: CoinPrices;
|
|
217
217
|
indexer?: boolean;
|
|
@@ -235,18 +235,19 @@ export class ScallopQuery {
|
|
|
235
235
|
public async getMarketPool(
|
|
236
236
|
poolCoinName: SupportPoolCoins,
|
|
237
237
|
args?: {
|
|
238
|
-
marketObject?: SuiObjectData | null;
|
|
239
238
|
coinPrice?: number;
|
|
240
239
|
indexer?: boolean;
|
|
241
240
|
}
|
|
242
241
|
) {
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
242
|
+
const marketPools = await this.getMarketPools(undefined, args);
|
|
243
|
+
return marketPools.pools[poolCoinName];
|
|
244
|
+
// return await getMarketPool(
|
|
245
|
+
// this,
|
|
246
|
+
// poolCoinName,
|
|
247
|
+
// args?.indexer,
|
|
248
|
+
// args?.marketObject,
|
|
249
|
+
// args?.coinPrice
|
|
250
|
+
// );
|
|
250
251
|
}
|
|
251
252
|
|
|
252
253
|
/**
|
|
@@ -418,13 +419,8 @@ export class ScallopQuery {
|
|
|
418
419
|
indexer?: boolean;
|
|
419
420
|
}
|
|
420
421
|
) {
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
stakeMarketCoinName,
|
|
424
|
-
args?.indexer,
|
|
425
|
-
args?.marketPool,
|
|
426
|
-
args?.coinPrices
|
|
427
|
-
);
|
|
422
|
+
const spools = await this.getSpools(undefined, args);
|
|
423
|
+
return spools[stakeMarketCoinName];
|
|
428
424
|
}
|
|
429
425
|
|
|
430
426
|
/**
|
|
@@ -546,7 +542,7 @@ export class ScallopQuery {
|
|
|
546
542
|
public async getBorrowIncentivePools(
|
|
547
543
|
coinNames?: SupportBorrowIncentiveCoins[],
|
|
548
544
|
args?: {
|
|
549
|
-
coinPrices
|
|
545
|
+
coinPrices?: CoinPrices;
|
|
550
546
|
indexer?: boolean;
|
|
551
547
|
marketPools?: MarketPools;
|
|
552
548
|
}
|
|
@@ -618,7 +614,7 @@ export class ScallopQuery {
|
|
|
618
614
|
*/
|
|
619
615
|
public async getObligationAccounts(
|
|
620
616
|
ownerAddress: string = this.walletAddress,
|
|
621
|
-
args?: { indexer
|
|
617
|
+
args?: { indexer?: boolean }
|
|
622
618
|
) {
|
|
623
619
|
return await getObligationAccounts(this, ownerAddress, args?.indexer);
|
|
624
620
|
}
|
|
@@ -639,12 +635,16 @@ export class ScallopQuery {
|
|
|
639
635
|
ownerAddress: string = this.walletAddress,
|
|
640
636
|
args?: { indexer?: boolean }
|
|
641
637
|
) {
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
obligationId
|
|
645
|
-
ownerAddress,
|
|
646
|
-
args?.indexer
|
|
638
|
+
const results = await this.getObligationAccounts(ownerAddress, args);
|
|
639
|
+
return Object.values(results).find(
|
|
640
|
+
(obligation) => obligation?.obligationId === obligationId
|
|
647
641
|
);
|
|
642
|
+
// return await getObligationAccount(
|
|
643
|
+
// this,
|
|
644
|
+
// obligationId,
|
|
645
|
+
// ownerAddress,
|
|
646
|
+
// args?.indexer
|
|
647
|
+
// );
|
|
648
648
|
}
|
|
649
649
|
|
|
650
650
|
/**
|
|
@@ -812,7 +812,7 @@ export class ScallopQuery {
|
|
|
812
812
|
* Get list of isolated assets
|
|
813
813
|
*/
|
|
814
814
|
public async getIsolatedAssets() {
|
|
815
|
-
return await getIsolatedAssets(this
|
|
815
|
+
return await getIsolatedAssets(this);
|
|
816
816
|
}
|
|
817
817
|
|
|
818
818
|
/**
|
|
@@ -841,4 +841,12 @@ export class ScallopQuery {
|
|
|
841
841
|
}) {
|
|
842
842
|
return getAllCoinPrices(this, args?.marketPools, args?.coinPrices);
|
|
843
843
|
}
|
|
844
|
+
|
|
845
|
+
/**
|
|
846
|
+
* Query all address (lending pool, collateral pool, borrow dynamics, interest models) of all pool
|
|
847
|
+
* @returns
|
|
848
|
+
*/
|
|
849
|
+
public async getPoolAddresses() {
|
|
850
|
+
return getAllAddresses(this);
|
|
851
|
+
}
|
|
844
852
|
}
|