@scallop-io/sui-scallop-sdk 0.46.53 → 0.46.54
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/tokenBucket.d.ts +2 -0
- package/dist/index.js +1981 -1884
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1932 -1835
- package/dist/index.mjs.map +1 -1
- package/dist/models/scallop.d.ts +2 -1
- package/dist/models/scallopCache.d.ts +11 -8
- package/dist/models/scallopClient.d.ts +2 -2
- package/dist/models/scallopQuery.d.ts +1 -1
- package/dist/models/scallopUtils.d.ts +9 -1
- package/dist/queries/coreQuery.d.ts +1 -1
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/tokenBucket.d.ts +11 -0
- package/package.json +1 -1
- package/src/builders/loyaltyProgramBuilder.ts +6 -12
- package/src/builders/spoolBuilder.ts +1 -33
- package/src/constants/tokenBucket.ts +2 -0
- package/src/models/scallop.ts +13 -2
- package/src/models/scallopCache.ts +55 -25
- package/src/models/scallopClient.ts +28 -13
- package/src/models/scallopUtils.ts +42 -10
- package/src/queries/borrowIncentiveQuery.ts +12 -10
- package/src/queries/coreQuery.ts +33 -16
- package/src/queries/loyaltyProgramQuery.ts +2 -2
- package/src/queries/portfolioQuery.ts +2 -2
- package/src/queries/priceQuery.ts +1 -1
- package/src/queries/referralQuery.ts +1 -1
- package/src/queries/sCoinQuery.ts +1 -1
- package/src/queries/spoolQuery.ts +4 -2
- package/src/queries/vescaQuery.ts +8 -3
- package/src/utils/index.ts +1 -0
- package/src/utils/tokenBucket.ts +63 -0
package/dist/index.mjs
CHANGED
|
@@ -248,7 +248,7 @@ import { SuiKit as SuiKit5 } from "@scallop-io/sui-kit";
|
|
|
248
248
|
import { QueryClient } from "@tanstack/query-core";
|
|
249
249
|
import {
|
|
250
250
|
SuiTxBlock,
|
|
251
|
-
normalizeStructTag,
|
|
251
|
+
normalizeStructTag as normalizeStructTag2,
|
|
252
252
|
normalizeSuiAddress
|
|
253
253
|
} from "@scallop-io/sui-kit";
|
|
254
254
|
|
|
@@ -261,1831 +261,1906 @@ var DEFAULT_CACHE_OPTIONS = {
|
|
|
261
261
|
}
|
|
262
262
|
};
|
|
263
263
|
|
|
264
|
-
// src/
|
|
265
|
-
var
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
264
|
+
// src/utils/builder.ts
|
|
265
|
+
var requireSender = (txBlock) => {
|
|
266
|
+
const sender = txBlock.blockData.sender;
|
|
267
|
+
if (!sender) {
|
|
268
|
+
throw new Error("Sender is required");
|
|
269
269
|
}
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
270
|
+
return sender;
|
|
271
|
+
};
|
|
272
|
+
var checkVesca = (prevUnlockAtInMillisTimestamp) => {
|
|
273
|
+
if (prevUnlockAtInMillisTimestamp === void 0) {
|
|
274
|
+
throw new Error("veSca not found");
|
|
275
275
|
}
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
* - `active`: Only queries that match the refetch predicate and are actively being rendered via useQuery and related functions will be refetched in the background.
|
|
281
|
-
* - `inactive`: Only queries that match the refetch predicate and are NOT actively being rendered via useQuery and related functions will be refetched in the background.
|
|
282
|
-
* - `all`: All queries that match the refetch predicate will be refetched in the background.
|
|
283
|
-
* - `none`: No queries will be refetched. Queries that match the refetch predicate will only be marked as invalid.
|
|
284
|
-
*/
|
|
285
|
-
invalidateAndRefetchAllCache(refetchType) {
|
|
286
|
-
return this.queryClient.invalidateQueries({
|
|
287
|
-
refetchType
|
|
288
|
-
});
|
|
276
|
+
};
|
|
277
|
+
var checkVescaExpired = (prevUnlockAtInMillisTimestamp) => {
|
|
278
|
+
if (prevUnlockAtInMillisTimestamp <= (/* @__PURE__ */ new Date()).getTime()) {
|
|
279
|
+
throw new Error("veSca is expired, use renewExpiredVeScaQuick instead");
|
|
289
280
|
}
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
},
|
|
300
|
-
staleTime: 3e4
|
|
301
|
-
});
|
|
281
|
+
};
|
|
282
|
+
var checkExtendLockPeriod = (lockPeriodInDays, newUnlockAtInSecondTimestamp, prevUnlockAtInMillisTimestamp) => {
|
|
283
|
+
checkVesca(prevUnlockAtInMillisTimestamp);
|
|
284
|
+
checkVescaExpired(prevUnlockAtInMillisTimestamp);
|
|
285
|
+
const prevUnlockAtInSecondTimestamp = Math.floor(
|
|
286
|
+
prevUnlockAtInMillisTimestamp / 1e3
|
|
287
|
+
);
|
|
288
|
+
if (lockPeriodInDays < 1) {
|
|
289
|
+
throw new Error("Minimum lock period is 1 day");
|
|
302
290
|
}
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
async queryInspectTxn({
|
|
310
|
-
queryTarget,
|
|
311
|
-
args,
|
|
312
|
-
typeArgs
|
|
313
|
-
}) {
|
|
314
|
-
const txBlock = new SuiTxBlock();
|
|
315
|
-
const resolvedArgs = await Promise.all(
|
|
316
|
-
args.map(async (arg) => {
|
|
317
|
-
if (typeof arg === "string") {
|
|
318
|
-
return (await this.queryGetObject(arg, { showContent: true })).data;
|
|
319
|
-
}
|
|
320
|
-
return arg;
|
|
321
|
-
})
|
|
291
|
+
const availableLockPeriodInDays = Math.floor(
|
|
292
|
+
(newUnlockAtInSecondTimestamp - prevUnlockAtInSecondTimestamp) / UNLOCK_ROUND_DURATION
|
|
293
|
+
);
|
|
294
|
+
if (lockPeriodInDays > availableLockPeriodInDays) {
|
|
295
|
+
throw new Error(
|
|
296
|
+
`Cannot extend lock period by ${lockPeriodInDays} days, maximum lock period is ~4 years (${MAX_LOCK_ROUNDS} days), remaining lock period is ${MAX_LOCK_ROUNDS - availableLockPeriodInDays}`
|
|
322
297
|
);
|
|
323
|
-
txBlock.moveCall(queryTarget, resolvedArgs, typeArgs);
|
|
324
|
-
const txBytes = await txBlock.txBlock.build({
|
|
325
|
-
client: this.suiKit.client(),
|
|
326
|
-
onlyTransactionKind: true,
|
|
327
|
-
protocolConfig: await this.getProtocolConfig()
|
|
328
|
-
});
|
|
329
|
-
const query = await this.queryClient.fetchQuery({
|
|
330
|
-
queryKey: typeArgs ? ["inspectTxn", queryTarget, JSON.stringify(args)] : [
|
|
331
|
-
"inspectTxn",
|
|
332
|
-
queryTarget,
|
|
333
|
-
JSON.stringify(args),
|
|
334
|
-
JSON.stringify(typeArgs)
|
|
335
|
-
],
|
|
336
|
-
queryFn: async () => {
|
|
337
|
-
return await this.suiKit.inspectTxn(txBytes);
|
|
338
|
-
}
|
|
339
|
-
});
|
|
340
|
-
return query;
|
|
341
298
|
}
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
queryKey.push(JSON.stringify(options));
|
|
352
|
-
}
|
|
353
|
-
return this.queryClient.fetchQuery({
|
|
354
|
-
queryKey,
|
|
355
|
-
queryFn: async () => {
|
|
356
|
-
return await this.suiKit.client().getObject({
|
|
357
|
-
id: objectId,
|
|
358
|
-
options
|
|
359
|
-
});
|
|
299
|
+
};
|
|
300
|
+
var checkLockSca = (scaAmountOrCoin, lockPeriodInDays, newUnlockAtInSecondTimestamp, prevUnlockAtInMillisTimestamp) => {
|
|
301
|
+
const prevUnlockAtInSecondTimestamp = prevUnlockAtInMillisTimestamp ? Math.floor(prevUnlockAtInMillisTimestamp / 1e3) : void 0;
|
|
302
|
+
const isInitialLock = !prevUnlockAtInSecondTimestamp;
|
|
303
|
+
const isLockExpired = !isInitialLock && prevUnlockAtInSecondTimestamp * 1e3 <= (/* @__PURE__ */ new Date()).getTime();
|
|
304
|
+
if (isInitialLock || isLockExpired) {
|
|
305
|
+
if (scaAmountOrCoin !== void 0 && lockPeriodInDays !== void 0) {
|
|
306
|
+
if (lockPeriodInDays <= 0) {
|
|
307
|
+
throw new Error("Lock period must be greater than 0");
|
|
360
308
|
}
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
* @param objectIds
|
|
366
|
-
* @returns Promise<SuiObjectData[]>
|
|
367
|
-
*/
|
|
368
|
-
async queryGetObjects(objectIds, options) {
|
|
369
|
-
if (objectIds.length === 0)
|
|
370
|
-
return [];
|
|
371
|
-
const queryKey = [
|
|
372
|
-
"getObjects",
|
|
373
|
-
JSON.stringify(objectIds),
|
|
374
|
-
this.suiKit.currentAddress()
|
|
375
|
-
];
|
|
376
|
-
if (options) {
|
|
377
|
-
queryKey.push(JSON.stringify(options));
|
|
378
|
-
}
|
|
379
|
-
return this.queryClient.fetchQuery({
|
|
380
|
-
queryKey,
|
|
381
|
-
queryFn: async () => {
|
|
382
|
-
return await this.suiKit.getObjects(objectIds, options);
|
|
309
|
+
if (typeof scaAmountOrCoin === "number" && scaAmountOrCoin < MIN_INITIAL_LOCK_AMOUNT) {
|
|
310
|
+
throw new Error(
|
|
311
|
+
`Minimum lock amount for ${isLockExpired ? "renewing expired veSca" : "initial lock"} is 10 SCA`
|
|
312
|
+
);
|
|
383
313
|
}
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
queryKey.push(JSON.stringify(input.cursor));
|
|
395
|
-
}
|
|
396
|
-
if (input.options) {
|
|
397
|
-
queryKey.push(JSON.stringify(input.options));
|
|
314
|
+
const extendLockPeriodInSecond = lockPeriodInDays * UNLOCK_ROUND_DURATION;
|
|
315
|
+
if (extendLockPeriodInSecond > MAX_LOCK_DURATION) {
|
|
316
|
+
throw new Error(
|
|
317
|
+
`Maximum lock period is ~4 years (${MAX_LOCK_ROUNDS} days)`
|
|
318
|
+
);
|
|
319
|
+
}
|
|
320
|
+
} else {
|
|
321
|
+
throw new Error(
|
|
322
|
+
`SCA amount and lock period is required for ${isLockExpired ? "renewing expired veSca" : "initial lock"}`
|
|
323
|
+
);
|
|
398
324
|
}
|
|
399
|
-
|
|
400
|
-
|
|
325
|
+
} else {
|
|
326
|
+
checkVesca(prevUnlockAtInMillisTimestamp);
|
|
327
|
+
checkVescaExpired(prevUnlockAtInMillisTimestamp);
|
|
328
|
+
if (typeof scaAmountOrCoin === "number" && scaAmountOrCoin < MIN_TOP_UP_AMOUNT) {
|
|
329
|
+
throw new Error("Minimum top up amount is 1 SCA");
|
|
401
330
|
}
|
|
402
|
-
if (
|
|
403
|
-
|
|
331
|
+
if (newUnlockAtInSecondTimestamp && lockPeriodInDays) {
|
|
332
|
+
checkExtendLockPeriod(
|
|
333
|
+
lockPeriodInDays,
|
|
334
|
+
newUnlockAtInSecondTimestamp,
|
|
335
|
+
prevUnlockAtInMillisTimestamp
|
|
336
|
+
);
|
|
404
337
|
}
|
|
405
|
-
return this.queryClient.fetchQuery({
|
|
406
|
-
queryKey,
|
|
407
|
-
queryFn: async () => {
|
|
408
|
-
return await this.suiKit.client().getOwnedObjects(input);
|
|
409
|
-
}
|
|
410
|
-
});
|
|
411
338
|
}
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
queryKey.push(JSON.stringify(input.limit));
|
|
419
|
-
}
|
|
420
|
-
return this.queryClient.fetchQuery({
|
|
421
|
-
queryKey,
|
|
422
|
-
queryFn: async () => {
|
|
423
|
-
return await this.suiKit.client().getDynamicFields(input);
|
|
424
|
-
}
|
|
425
|
-
});
|
|
339
|
+
};
|
|
340
|
+
var checkExtendLockAmount = (scaAmount, prevUnlockAtInMillisTimestamp) => {
|
|
341
|
+
checkVesca(prevUnlockAtInMillisTimestamp);
|
|
342
|
+
checkVescaExpired(prevUnlockAtInMillisTimestamp);
|
|
343
|
+
if (scaAmount < MIN_TOP_UP_AMOUNT) {
|
|
344
|
+
throw new Error("Minimum top up amount is 1 SCA");
|
|
426
345
|
}
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
input.name.type,
|
|
432
|
-
input.name.value
|
|
433
|
-
];
|
|
434
|
-
return this.queryClient.fetchQuery({
|
|
435
|
-
queryKey,
|
|
436
|
-
queryFn: async () => {
|
|
437
|
-
return await this.suiKit.client().getDynamicFieldObject(input);
|
|
438
|
-
}
|
|
439
|
-
});
|
|
346
|
+
const isInitialLock = !prevUnlockAtInMillisTimestamp;
|
|
347
|
+
const isLockExpired = !isInitialLock && prevUnlockAtInMillisTimestamp <= (/* @__PURE__ */ new Date()).getTime();
|
|
348
|
+
if (isLockExpired) {
|
|
349
|
+
throw new Error("veSca is expired, use renewExpiredVeScaQuick instead");
|
|
440
350
|
}
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
queryFn: async () => {
|
|
446
|
-
const allBalances = await this.suiKit.client().getAllBalances({ owner });
|
|
447
|
-
const balances = allBalances.reduce(
|
|
448
|
-
(acc, coinBalance) => {
|
|
449
|
-
if (coinBalance.totalBalance !== "0") {
|
|
450
|
-
acc[normalizeStructTag(coinBalance.coinType)] = coinBalance.totalBalance;
|
|
451
|
-
}
|
|
452
|
-
return acc;
|
|
453
|
-
},
|
|
454
|
-
{}
|
|
455
|
-
);
|
|
456
|
-
for (const coinType in balances) {
|
|
457
|
-
const coinBalanceQueryKey = [
|
|
458
|
-
"getCoinBalance",
|
|
459
|
-
normalizeSuiAddress(owner),
|
|
460
|
-
normalizeStructTag(coinType)
|
|
461
|
-
];
|
|
462
|
-
this.queryClient.setQueryData(
|
|
463
|
-
coinBalanceQueryKey,
|
|
464
|
-
balances[coinType]
|
|
465
|
-
);
|
|
466
|
-
}
|
|
467
|
-
return balances;
|
|
468
|
-
}
|
|
469
|
-
});
|
|
351
|
+
};
|
|
352
|
+
var checkRenewExpiredVeSca = (scaAmount, lockPeriodInDays, prevUnlockAtInMillisTimestamp) => {
|
|
353
|
+
if (!prevUnlockAtInMillisTimestamp || prevUnlockAtInMillisTimestamp > (/* @__PURE__ */ new Date()).getTime()) {
|
|
354
|
+
throw new Error("Renew method can only be used for expired veSca");
|
|
470
355
|
}
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
return this.queryClient.fetchQuery({
|
|
480
|
-
queryKey,
|
|
481
|
-
queryFn: async () => {
|
|
482
|
-
if (!input.coinType)
|
|
483
|
-
return "0";
|
|
484
|
-
return (await this.queryGetAllCoinBalances(input.owner))[normalizeStructTag(input.coinType)] ?? "0";
|
|
485
|
-
}
|
|
486
|
-
});
|
|
356
|
+
if (scaAmount < MIN_INITIAL_LOCK_AMOUNT) {
|
|
357
|
+
throw new Error("Minimum lock amount for renewing expired vesca 10 SCA");
|
|
358
|
+
}
|
|
359
|
+
const extendLockPeriodInSecond = lockPeriodInDays * UNLOCK_ROUND_DURATION;
|
|
360
|
+
if (extendLockPeriodInSecond >= MAX_LOCK_DURATION - UNLOCK_ROUND_DURATION) {
|
|
361
|
+
throw new Error(
|
|
362
|
+
`Maximum lock period is ~4 years (${MAX_LOCK_ROUNDS - 1} days)`
|
|
363
|
+
);
|
|
487
364
|
}
|
|
488
365
|
};
|
|
489
366
|
|
|
490
|
-
// src/
|
|
491
|
-
import
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
//
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
//
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
supra: "",
|
|
518
|
-
switchboard: "",
|
|
519
|
-
pyth: {
|
|
520
|
-
feed: "e5b274b2611143df055d6e7cd8d93fe1961716bcd4dca1cad87a83bc1e78c1ef",
|
|
521
|
-
feedObject: "0x24c0247fb22457a719efac7f670cdc79be321b521460bd6bd2ccfa9f80713b14"
|
|
522
|
-
}
|
|
523
|
-
}
|
|
524
|
-
},
|
|
525
|
-
apt: {
|
|
526
|
-
id: "0x3a5143bb1196e3bcdfab6203d1683ae29edd26294fc8bfeafe4aaa9d2704df37",
|
|
527
|
-
metaData: "0xc969c5251f372c0f34c32759f1d315cf1ea0ee5e4454b52aea08778eacfdd0a8",
|
|
528
|
-
treasury: "",
|
|
529
|
-
oracle: {
|
|
530
|
-
supra: "",
|
|
531
|
-
switchboard: "",
|
|
532
|
-
pyth: {
|
|
533
|
-
feed: "03ae4db29ed4ae33d323568895aa00337e658e348b37509f5372ae51f0af00d5",
|
|
534
|
-
feedObject: "0x7c5b7837c44a69b469325463ac0673ac1aa8435ff44ddb4191c9ae380463647f"
|
|
535
|
-
}
|
|
536
|
-
}
|
|
537
|
-
},
|
|
538
|
-
sol: {
|
|
539
|
-
id: "0xb7844e289a8410e50fb3ca48d69eb9cf29e27d223ef90353fe1bd8e27ff8f3f8",
|
|
540
|
-
metaData: "0x4d2c39082b4477e3e79dc4562d939147ab90c42fc5f3e4acf03b94383cd69b6e",
|
|
541
|
-
treasury: "",
|
|
542
|
-
oracle: {
|
|
543
|
-
supra: "",
|
|
544
|
-
switchboard: "",
|
|
545
|
-
pyth: {
|
|
546
|
-
feed: "ef0d8b6fda2ceba41da15d4095d1da392a0d2f8ed0c6c7bc0f4cfac8c280b56d",
|
|
547
|
-
feedObject: "0x9d0d275efbd37d8a8855f6f2c761fa5983293dd8ce202ee5196626de8fcd4469"
|
|
548
|
-
}
|
|
549
|
-
}
|
|
550
|
-
},
|
|
551
|
-
btc: {
|
|
552
|
-
id: "0x027792d9fed7f9844eb4839566001bb6f6cb4804f66aa2da6fe1ee242d896881",
|
|
553
|
-
metaData: "0x5d3c6e60eeff8a05b693b481539e7847dfe33013e7070cdcb387f5c0cac05dfd",
|
|
554
|
-
treasury: "",
|
|
555
|
-
oracle: {
|
|
556
|
-
supra: "",
|
|
557
|
-
switchboard: "",
|
|
558
|
-
pyth: {
|
|
559
|
-
feed: "e62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43",
|
|
560
|
-
feedObject: "0x9a62b4863bdeaabdc9500fce769cf7e72d5585eeb28a6d26e4cafadc13f76ab2"
|
|
561
|
-
}
|
|
562
|
-
}
|
|
563
|
-
},
|
|
564
|
-
eth: {
|
|
565
|
-
id: "0xaf8cd5edc19c4512f4259f0bee101a40d41ebed738ade5874359610ef8eeced5",
|
|
566
|
-
metaData: "0x8900e4ceede3363bef086d6b50ca89d816d0e90bf6bc46efefe1f8455e08f50f",
|
|
567
|
-
treasury: "",
|
|
568
|
-
oracle: {
|
|
569
|
-
supra: "",
|
|
570
|
-
switchboard: "",
|
|
571
|
-
pyth: {
|
|
572
|
-
feed: "ff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace",
|
|
573
|
-
feedObject: "0x9193fd47f9a0ab99b6e365a464c8a9ae30e6150fc37ed2a89c1586631f6fc4ab"
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
},
|
|
577
|
-
usdc: {
|
|
578
|
-
id: "0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf",
|
|
579
|
-
metaData: "0x4fbf84f3029bd0c0b77164b587963be957f853eccf834a67bb9ecba6ec80f189",
|
|
580
|
-
treasury: "",
|
|
581
|
-
oracle: {
|
|
582
|
-
supra: "",
|
|
583
|
-
switchboard: "",
|
|
584
|
-
pyth: {
|
|
585
|
-
feed: "eaa020c61cc479712813461ce153894a96a6c00b21ed0cfc2798d1f9a9e9c94a",
|
|
586
|
-
feedObject: "0x5dec622733a204ca27f5a90d8c2fad453cc6665186fd5dff13a83d0b6c9027ab"
|
|
587
|
-
}
|
|
588
|
-
}
|
|
589
|
-
},
|
|
590
|
-
usdt: {
|
|
591
|
-
id: "0xc060006111016b8a020ad5b33834984a437aaa7d3c74c18e09a95d48aceab08c",
|
|
592
|
-
metaData: "0xfb0e3eb97dd158a5ae979dddfa24348063843c5b20eb8381dd5fa7c93699e45c",
|
|
593
|
-
treasury: "",
|
|
594
|
-
oracle: {
|
|
595
|
-
supra: "",
|
|
596
|
-
switchboard: "",
|
|
597
|
-
pyth: {
|
|
598
|
-
feed: "2b89b9dc8fdf9f34709a5b106b472f0f39bb6ca9ce04b0fd7f2e971688e2e53b",
|
|
599
|
-
feedObject: "0x985e3db9f93f76ee8bace7c3dd5cc676a096accd5d9e09e9ae0fb6e492b14572"
|
|
600
|
-
}
|
|
601
|
-
}
|
|
602
|
-
},
|
|
603
|
-
sui: {
|
|
604
|
-
id: "0x0000000000000000000000000000000000000000000000000000000000000002",
|
|
605
|
-
metaData: "0x9258181f5ceac8dbffb7030890243caed69a9599d2886d957a9cb7656af3bdb3",
|
|
606
|
-
treasury: "",
|
|
607
|
-
oracle: {
|
|
608
|
-
supra: "",
|
|
609
|
-
switchboard: "0xbca474133638352ba83ccf7b5c931d50f764b09550e16612c9f70f1e21f3f594",
|
|
610
|
-
pyth: {
|
|
611
|
-
feed: "23d7315113f5b1d3ba7a83604c44b94d79f4fd69af77f804fc7f920a6dc65744",
|
|
612
|
-
feedObject: "0x801dbc2f0053d34734814b2d6df491ce7807a725fe9a01ad74a07e9c51396c37"
|
|
613
|
-
}
|
|
614
|
-
}
|
|
615
|
-
},
|
|
616
|
-
afsui: {
|
|
617
|
-
id: "0xf325ce1300e8dac124071d3152c5c5ee6174914f8bc2161e88329cf579246efc",
|
|
618
|
-
metaData: "0x2f9217f533e51334873a39b8026a4aa6919497b47f49d0986a4f1aec66f8a34d",
|
|
619
|
-
treasury: "",
|
|
620
|
-
oracle: {
|
|
621
|
-
supra: "",
|
|
622
|
-
switchboard: "",
|
|
623
|
-
pyth: {
|
|
624
|
-
feed: "23d7315113f5b1d3ba7a83604c44b94d79f4fd69af77f804fc7f920a6dc65744",
|
|
625
|
-
feedObject: "0x801dbc2f0053d34734814b2d6df491ce7807a725fe9a01ad74a07e9c51396c37"
|
|
626
|
-
}
|
|
627
|
-
}
|
|
628
|
-
},
|
|
629
|
-
hasui: {
|
|
630
|
-
id: "0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d",
|
|
631
|
-
metaData: "0x2c5f33af93f6511df699aaaa5822d823aac6ed99d4a0de2a4a50b3afa0172e24",
|
|
632
|
-
treasury: "",
|
|
633
|
-
oracle: {
|
|
634
|
-
supra: "",
|
|
635
|
-
switchboard: "",
|
|
636
|
-
pyth: {
|
|
637
|
-
feed: "23d7315113f5b1d3ba7a83604c44b94d79f4fd69af77f804fc7f920a6dc65744",
|
|
638
|
-
feedObject: "0x801dbc2f0053d34734814b2d6df491ce7807a725fe9a01ad74a07e9c51396c37"
|
|
639
|
-
}
|
|
640
|
-
}
|
|
641
|
-
},
|
|
642
|
-
vsui: {
|
|
643
|
-
id: "0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55",
|
|
644
|
-
metaData: "0xabd84a23467b33854ab25cf862006fd97479f8f6f53e50fe732c43a274d939bd",
|
|
645
|
-
treasury: "",
|
|
646
|
-
oracle: {
|
|
647
|
-
supra: "",
|
|
648
|
-
switchboard: "",
|
|
649
|
-
pyth: {
|
|
650
|
-
feed: "23d7315113f5b1d3ba7a83604c44b94d79f4fd69af77f804fc7f920a6dc65744",
|
|
651
|
-
feedObject: "0x801dbc2f0053d34734814b2d6df491ce7807a725fe9a01ad74a07e9c51396c37"
|
|
652
|
-
}
|
|
653
|
-
}
|
|
654
|
-
},
|
|
655
|
-
sca: {
|
|
656
|
-
id: "0x7016aae72cfc67f2fadf55769c0a7dd54291a583b63051a5ed71081cce836ac6",
|
|
657
|
-
metaData: "0x5d26a1e9a55c88147ac870bfa31b729d7f49f8804b8b3adfdf3582d301cca844",
|
|
658
|
-
treasury: "",
|
|
659
|
-
oracle: {
|
|
660
|
-
supra: "",
|
|
661
|
-
switchboard: "",
|
|
662
|
-
pyth: {
|
|
663
|
-
feed: "7e17f0ac105abe9214deb9944c30264f5986bf292869c6bd8e8da3ccd92d79bc",
|
|
664
|
-
feedObject: "0xf6de1d3279a269a597d813cbaca59aa906543ab9a8c64e84a4722f1a20863985"
|
|
665
|
-
}
|
|
666
|
-
}
|
|
667
|
-
}
|
|
668
|
-
},
|
|
669
|
-
oracles: {
|
|
670
|
-
xOracle: "0x93d5bf0936b71eb27255941e532fac33b5a5c7759e377b4923af0a1359ad494f",
|
|
671
|
-
xOracleCap: "0x1edeae568fde99e090dbdec4bcdbd33a15f53a1ce1f87aeef1a560dedf4b4a90",
|
|
672
|
-
supra: { registry: "", registryCap: "", holder: "" },
|
|
673
|
-
switchboard: { registry: "", registryCap: "" },
|
|
674
|
-
pyth: {
|
|
675
|
-
registry: "0xedc293f9413a5a7a5d53bdba1fd889d0a4030894469228f0acdae4aa3c55a213",
|
|
676
|
-
registryCap: "0xbcb07141eb1f7e01fbda4130ecf5f5adaeabb77f5d9c32158b7532bcd2197acd",
|
|
677
|
-
state: "0x1f9310238ee9298fb703c3419030b35b22bb1cc37113e3bb5007c99aec79e5b8",
|
|
678
|
-
wormhole: "0x5306f64e312b581766351c07af79c72fcb1cd25147157fdc2f8ad76de9a3fb6a",
|
|
679
|
-
wormholeState: "0xaeab97f96cf9877fee2883315d459552b2b921edc16d7ceac6eab944dd88919c"
|
|
680
|
-
}
|
|
681
|
-
},
|
|
682
|
-
packages: {
|
|
683
|
-
coinDecimalsRegistry: {
|
|
684
|
-
id: "0xca5a5a62f01c79a104bf4d31669e29daa387f325c241de4edbe30986a9bc8b0d",
|
|
685
|
-
upgradeCap: "0x34e76a945d29f195bc53ca704fa70877d1cf3a5d7bbfdda1b13e633fff13c0f6"
|
|
686
|
-
},
|
|
687
|
-
math: {
|
|
688
|
-
id: "0xad013d5fde39e15eabda32b3dbdafd67dac32b798ce63237c27a8f73339b9b6f",
|
|
689
|
-
upgradeCap: "0x3a329598231de02e6135c62284b66005b41cad1d9ab7ca2dc79c08293aba2ec6"
|
|
690
|
-
},
|
|
691
|
-
whitelist: {
|
|
692
|
-
id: "0x1318fdc90319ec9c24df1456d960a447521b0a658316155895014a6e39b5482f",
|
|
693
|
-
upgradeCap: "0xf5a22aea23db664f7b69855b6a546747f17c1ec4230319cfc17225e462b05761"
|
|
694
|
-
},
|
|
695
|
-
x: {
|
|
696
|
-
id: "0x779b5c547976899f5474f3a5bc0db36ddf4697ad7e5a901db0415c2281d28162",
|
|
697
|
-
upgradeCap: "0x3f203f6fff6a69d151e4f1cd931f22b68c489ef2759765662fc7baf673943c9e"
|
|
698
|
-
},
|
|
699
|
-
protocol: {
|
|
700
|
-
id: "0x87ddec2984645dbbe2403a509cc6edf393a43acdba9b77d45da2bcbefcf733c1",
|
|
701
|
-
upgradeCap: "0x38527d154618d1fd5a644b90717fe07cf0e9f26b46b63e9568e611a3f86d5c1a"
|
|
702
|
-
},
|
|
703
|
-
// protocol: {
|
|
704
|
-
// id: '0x6e641f0dca8aedab3101d047e96439178f16301bf0b57fe8745086ff1195eb3e',
|
|
705
|
-
// upgradeCap:
|
|
706
|
-
// '0x38527d154618d1fd5a644b90717fe07cf0e9f26b46b63e9568e611a3f86d5c1a',
|
|
707
|
-
// },
|
|
708
|
-
protocolWhitelist: {
|
|
709
|
-
id: "0x4c262d9343dac53ecb28f482a2a3f62c73d0ebac5b5f03d57383d56ff219acdf",
|
|
710
|
-
upgradeCap: "0x4a5e88a75039b00988f633f811f58117f31b8627a46bf822aa114d9010049449"
|
|
711
|
-
},
|
|
712
|
-
// query: {
|
|
713
|
-
// id: '0xb8d603a39114a5efef3dd0bf84df0bed1be1fbd39b78b7dd6e8a61ccc5e6006f',
|
|
714
|
-
// upgradeCap:
|
|
715
|
-
// '0x0d535c35f608b9b01b7ccce11acf43b1dd80c1b72bf8b541744a6e28e8d2745f',
|
|
716
|
-
// },
|
|
717
|
-
query: {
|
|
718
|
-
id: "0xe4f9d62d17746d5b9dbf0d5557747430021a71575780b515161210cdba0a4c1c",
|
|
719
|
-
upgradeCap: "0x0d535c35f608b9b01b7ccce11acf43b1dd80c1b72bf8b541744a6e28e8d2745f"
|
|
720
|
-
},
|
|
721
|
-
supra: { id: "", upgradeCap: "" },
|
|
722
|
-
pyth: {
|
|
723
|
-
id: "0x910f30cbc7f601f75a5141a01265cd47c62d468707c5e1aecb32a18f448cb25a",
|
|
724
|
-
upgradeCap: "0xdf0ffbae1ea5bb25fbca5efba433dcf00c7cced65679af2f04728901275c6157"
|
|
725
|
-
},
|
|
726
|
-
switchboard: { id: "", upgradeCap: "" },
|
|
727
|
-
xOracle: {
|
|
728
|
-
id: "0x1478a432123e4b3d61878b629f2c692969fdb375644f1251cd278a4b1e7d7cd6",
|
|
729
|
-
upgradeCap: "0x0f928a6b2e26b73330fecaf9b44acfc9800a4a9794d6415c2a3153bc70e3c1f0"
|
|
730
|
-
},
|
|
731
|
-
testCoin: { id: "", upgradeCap: "" }
|
|
732
|
-
}
|
|
733
|
-
},
|
|
734
|
-
spool: {
|
|
735
|
-
// id: '0x7c4fdabe81c31b19a45d1e572a52a539997a90903fbb5bfab71480abe0fa62c3',
|
|
736
|
-
id: "0x1742655fe5872dfa6456673f9e38612a4965e6979e6cd7696a7f1225f28bae21",
|
|
737
|
-
adminCap: "0xdd8a047cbbf802bfcde5288b8ef1910965d789cc614da11d39af05fca0bd020a",
|
|
738
|
-
// object:
|
|
739
|
-
// '0xe87f1b2d498106a2c61421cec75b7b5c5e348512b0dc263949a0e7a3c256571a',
|
|
740
|
-
object: "0x1742655fe5872dfa6456673f9e38612a4965e6979e6cd7696a7f1225f28bae21",
|
|
741
|
-
pools: {
|
|
742
|
-
seth: {
|
|
743
|
-
id: "0xeec40beccb07c575bebd842eeaabb835f77cd3dab73add433477e57f583a6787",
|
|
744
|
-
rewardPoolId: "0x957de68a18d87817de8309b30c1ec269a4d87ae513abbeed86b5619cb9ce1077"
|
|
745
|
-
},
|
|
746
|
-
ssui: {
|
|
747
|
-
// id: '0x4f0ba970d3c11db05c8f40c64a15b6a33322db3702d634ced6536960ab6f3ee4',
|
|
748
|
-
id: "0xb9617f83c06ebdeac0a8834782b1015e1cc7ea23739e30c132c4bfb95c37a579",
|
|
749
|
-
rewardPoolId: (
|
|
750
|
-
// '0x162250ef72393a4ad3d46294c4e1bdfcb03f04c869d390e7efbfc995353a7ee9',
|
|
751
|
-
"0xc3206071a8d43212efb6e3b5504f2321f8df97ab122b466c0bc7cfdf398dc13a"
|
|
752
|
-
)
|
|
753
|
-
},
|
|
754
|
-
susdc: {
|
|
755
|
-
// id: '0x4ace6648ddc64e646ba47a957c562c32c9599b3bba8f5ac1aadb2ae23a2f8ca0',
|
|
756
|
-
id: "0xf1b383b9cf2e9f515fc69567df1053098f273849d09cd84b0278a773429bd2b2",
|
|
757
|
-
rewardPoolId: (
|
|
758
|
-
// '0xf4268cc9b9413b9bfe09e8966b8de650494c9e5784bf0930759cfef4904daff8',
|
|
759
|
-
"0xc71c53ee6505d928ba15bea4fe4f45d98c9c31eced94b72d00a7827d4b7ba3ff"
|
|
760
|
-
)
|
|
761
|
-
},
|
|
762
|
-
susdt: {
|
|
763
|
-
// id: '0xcb328f7ffa7f9342ed85af3fdb2f22919e1a06dfb2f713c04c73543870d7548f',
|
|
764
|
-
id: "0xb5567dfa5c7fc17a249e959732664c50713dd8c23db1a11376b27df800c17418",
|
|
765
|
-
rewardPoolId: (
|
|
766
|
-
// '0x2c9f934d67a5baa586ceec2cc24163a2f049a6af3d5ba36b84d8ac40f25c4080',
|
|
767
|
-
"0x60768b0687ff0235e376a039709a683e4c436098785e473b67b32dbab47b69ab"
|
|
768
|
-
)
|
|
769
|
-
},
|
|
770
|
-
scetus: {
|
|
771
|
-
id: "0xac1bb13bf4472a637c18c2415fb0e3c1227ea2bcf35242e50563c98215bd298e",
|
|
772
|
-
rewardPoolId: "0x6835c1224126a45086fc6406adc249e3f30df18d779ca4f4e570e38716a17f3f"
|
|
773
|
-
},
|
|
774
|
-
safsui: {
|
|
775
|
-
// id: '0xeedf438abcaa6ce4d9625ffca110920592d5867e4c5637d84ad9f466c4feb800',
|
|
776
|
-
id: "0xc568bb4c991258e839aa54802ecda04fcd9838c826bc3b42b40af81b23c458c8",
|
|
777
|
-
rewardPoolId: (
|
|
778
|
-
// '0x89255a2f86ed7fbfef35ab8b7be48cc7667015975be2685dd9a55a9a64baf76e',
|
|
779
|
-
"0x389a3cbeda742b918941bb24fd00e077bad3367484394d6234f8209b9a6aa03d"
|
|
780
|
-
)
|
|
781
|
-
},
|
|
782
|
-
shasui: {
|
|
783
|
-
// id: '0xa6148bc1b623e936d39a952ceb5bea79e8b37228a8f595067bf1852efd3c34aa',
|
|
784
|
-
id: "0x93f3f4499bf89f2d05ddc1f8b15f51701a7c6c4d0ac0b9c3bc99462cbbd8e321",
|
|
785
|
-
rewardPoolId: (
|
|
786
|
-
// '0x6f3563644d3e2ef13176dbf9d865bd93479df60ccbe07b7e66db57f6309f5a66',
|
|
787
|
-
"0x94cee1be7f5ff34193f3aabef0b14142cb28af4d905fe487a9a7d85a15edb6aa"
|
|
788
|
-
)
|
|
789
|
-
},
|
|
790
|
-
svsui: {
|
|
791
|
-
// id: '0x69ce8e537e750a95381e6040794afa5ab1758353a1a2e1de7760391b01f91670',
|
|
792
|
-
id: "0xa970e9087f80cb59e9299b8e7af7175d977ad6c9af0322aa4440e138fbd7ae00",
|
|
793
|
-
rewardPoolId: (
|
|
794
|
-
// '0xbca914adce058ad0902c7f3cfcd698392a475f00dcfdc3f76001d0370b98777a',
|
|
795
|
-
"0x38eee9699c4fc132a6623e54b865f047df4fc6eb83af807300f44e8f4b235ff0"
|
|
796
|
-
)
|
|
797
|
-
}
|
|
798
|
-
},
|
|
799
|
-
config: ""
|
|
800
|
-
},
|
|
801
|
-
borrowIncentive: {
|
|
802
|
-
id: "0x6152f696fc3a658f33c4b891764731a59153125ffedfa8bff7167c42823f58a9",
|
|
803
|
-
adminCap: "0xc486afa253646f4d381e81d7f1df8aa4723b845a6bb356f69bad635ffefffe2c",
|
|
804
|
-
object: "0x002875153e09f8145ab63527bc85c00f2bd102e12f9573c47f8cdf1a1cb62934",
|
|
805
|
-
query: "0x529edc54a3dce2207703ceebbccb0ac14133f7825c1f528775ba0d85a4063489",
|
|
806
|
-
incentivePools: "0x6547e143d406b5ccd5f46aae482497de279cc1a68c406f701df70a05f9212ab4",
|
|
807
|
-
incentiveAccounts: "0xc4701fdbc1c92f9a636d334d66012b3027659e9fb8aff27279a82edfb6b77d02",
|
|
808
|
-
config: "0xdf5d04b4691cc67e82fd4db8394d89ff44823a9de29716c924f74bb4f11cc1f7"
|
|
809
|
-
},
|
|
810
|
-
referral: {
|
|
811
|
-
id: "0xa3654ebb63eb06c0f4ff52f8aa6512df9f164f7772bdf15dac3709bd3798dda9",
|
|
812
|
-
object: "0x5658d4bf5ddcba27e4337b4262108b3ad1716643cac8c2054ac341538adc72ec",
|
|
813
|
-
adminCap: "0xc5dc06b9074291259f2cac460c940012c781c4430e42125c541cc43101c3bcbd",
|
|
814
|
-
referralBindings: "0xf63299d58789d99de94092b9011323466e55ca0c1ea1a7a3786a589af46e1c09",
|
|
815
|
-
bindingTableId: "0x1c8202b17267ec8d6cf97ca013615354181a04f179570e42601ff2dae19294b1",
|
|
816
|
-
referralRevenuePool: "0x6abd852caf90769c1b185cdf636d841673fa95528f0550f018b8a138bd283c07",
|
|
817
|
-
revenueTableId: "0x595baa3654c297bff84ab7786a2d250f019cefc66e8df8e89fd9d41e02bd30dd",
|
|
818
|
-
referralTiers: "0x962cb903d8d7346190c5204785ccbb91b61086aa764f674c8145df82335cf83e",
|
|
819
|
-
tiersTableId: "0xeac755a7a8b7798530905ac79e8c114f19d0f130f6eab012954f08faac29c75d",
|
|
820
|
-
// authorizedWitnessList:
|
|
821
|
-
// '0xf21b0ed043c9bb70842c0129159f4943dbcc3c9ef2f2f808af65f8be25cfd20e',
|
|
822
|
-
authorizedWitnessList: "0x9d6223dc52015b8a3986a573590ef2af8f1b8f3e4685513888c052f001b87e7f",
|
|
823
|
-
version: "0x1bd4b7285f72e11c316b828c7c47b3f4da18dcec9f9b3dba6d8629cbb6f93e5e"
|
|
824
|
-
},
|
|
825
|
-
vesca: {
|
|
826
|
-
id: "0xb15b6e0cdd85afb5028bea851dd249405e734d800a259147bbc24980629723a4",
|
|
827
|
-
object: "0xb15b6e0cdd85afb5028bea851dd249405e734d800a259147bbc24980629723a4",
|
|
828
|
-
adminCap: "0x8ffa76135c5b85c5fbd73a6448a4a733d826cb63a267ab817656acb77c72d4a5",
|
|
829
|
-
tableId: "0xe3153b2bf124be0b86cb8bd468346a861efd0da52fc42197b54d2f616488a311",
|
|
830
|
-
table: "0x611cb8d9d4d90867467b5ebdf4cc447a0047ed5b01334a28a29fcfe733e3d609",
|
|
831
|
-
treasury: "0xe8c112c09b88158dc6c8e23d1fbae5b3c7136cdee54b7dafc08e65db28c4a5bc",
|
|
832
|
-
config: "0xe0a2ff281e73c1d53cfa85807080f87e833e4f1a7f93dcf8800b3865269a76b9"
|
|
833
|
-
},
|
|
834
|
-
loyaltyProgram: {
|
|
835
|
-
id: "0xd17bcf8b5a59652c36225d478564a8593ae0ed7d650bcacdda1d6fe179127907",
|
|
836
|
-
object: "0xd17bcf8b5a59652c36225d478564a8593ae0ed7d650bcacdda1d6fe179127907",
|
|
837
|
-
rewardPool: "0xf9c090492ef476bd542109d0913ffe871cbfa28578b7114eca2a8c0e5671786f",
|
|
838
|
-
userRewardTableId: "0x748a80395849ed37db1b0e14f2ab5d1d96458d2359ab3a84eb079d0f4ac7cf2e"
|
|
839
|
-
},
|
|
840
|
-
scoin: {
|
|
841
|
-
id: "0xad2ca2aa5089df94bb2d444d5eb3520378c2f2dfb3a0bd2a2c994145ac4b0a53",
|
|
842
|
-
coins: {
|
|
843
|
-
ssui: {
|
|
844
|
-
coinType: "0xfac769100bccc0caebcf4f4e2d00ac2f8883f07f724be28940df90605f5e7e9a::scallop_sui::SCALLOP_SUI",
|
|
845
|
-
treasury: "0x9cb4551b36c17d37e19d700147fa819ea1c487ff8bcf18374de2cceb2e9d4845"
|
|
846
|
-
},
|
|
847
|
-
scetus: {
|
|
848
|
-
coinType: "0x8b71e6d323ed78515af2bead13bf3d0da1562ba4a99234eb7c4f14fd39ef0427::scallop_cetus::SCALLOP_CETUS",
|
|
849
|
-
treasury: "0xd786f4b2d26278cc7911a3445b1b085eab60f269ef9dbb6b87e803d52f155003"
|
|
850
|
-
},
|
|
851
|
-
ssca: {
|
|
852
|
-
coinType: "0x0a9d3c6c9af9f6e8def82921541bcbd17f73ed31bed3adcb684f2a4c267e42f0::scallop_sca::SCALLOP_SCA",
|
|
853
|
-
treasury: "0xe818636d1d6c46d6ea1a2dce9d94696d7cbc18ce27451b603eeaa47aba8d75e0"
|
|
854
|
-
},
|
|
855
|
-
susdc: {
|
|
856
|
-
coinType: "0xaedc3ab75db8680b81a755015fa90124d217be93457b893c05bac033817defaf::scallop_wormhole_usdc::SCALLOP_WORMHOLE_USDC",
|
|
857
|
-
treasury: "0xfc6971648f867f7fd6928d1b873af71577e2eaf2c7543ef8bc82c431d833ae78"
|
|
858
|
-
},
|
|
859
|
-
susdt: {
|
|
860
|
-
coinType: "0xbf02fc87ddc104b342ad8414c85ceadf5b0c823c055a06fb0ed776272c01a52a::scallop_wormhole_usdt::SCALLOP_WORMHOLE_USDT",
|
|
861
|
-
treasury: "0xb9593e2c3a0ba796ee815012b75ae46468ea78cda0188b9ac6816efe65503521"
|
|
862
|
-
},
|
|
863
|
-
seth: {
|
|
864
|
-
coinType: "0x27d54f43e3eda701be56b82e5756e41c84467cd202f5cf713d5f9e45a9f1b6bc::scallop_wormhole_eth::SCALLOP_WORMHOLE_ETH",
|
|
865
|
-
treasury: "0x032b4c8fac94c038dbe986f7587e9b1e4ef580b5ee06d2ef249d85459b7ef05d"
|
|
866
|
-
},
|
|
867
|
-
safsui: {
|
|
868
|
-
coinType: "0xb75b46d975d8d80670b53a6bee90baaa8ce2e0b7d397f079447d641eef6b44ad::scallop_af_sui::SCALLOP_AF_SUI",
|
|
869
|
-
treasury: "0x21450ef0570ef3d224ffa3b873ab802e439ece7b93cc7efad10ae0c1e3b3fcfe"
|
|
870
|
-
},
|
|
871
|
-
shasui: {
|
|
872
|
-
coinType: "0xd973a723874e2c7cde196602a79155a1343a933f8cf87d9b1bb7408bc1acbc58::scallop_ha_sui::SCALLOP_HA_SUI",
|
|
873
|
-
treasury: "0xf822fc1402207e47d2e3ba8ff6e1e594bf1de777dc5ebd2744619cd2726e3b0d"
|
|
874
|
-
},
|
|
875
|
-
svsui: {
|
|
876
|
-
coinType: "0x97023a317320c4498cc4cd239dd02fd30c28246e5e8f81325d63f2bd8d70f6b3::scallop_v_sui::SCALLOP_V_SUI",
|
|
877
|
-
treasury: "0x327114f0bf3559d7e2de10282147ed76a236c7c6775029165c4db09a6062ead6\u0192"
|
|
878
|
-
}
|
|
879
|
-
}
|
|
880
|
-
}
|
|
367
|
+
// src/utils/query.ts
|
|
368
|
+
import BigNumber from "bignumber.js";
|
|
369
|
+
import { normalizeStructTag, parseStructTag } from "@mysten/sui.js/utils";
|
|
370
|
+
var parseOriginMarketPoolData = (originMarketPoolData) => {
|
|
371
|
+
return {
|
|
372
|
+
coinType: normalizeStructTag(originMarketPoolData.type.name),
|
|
373
|
+
// Parse origin data required for basic calculations.
|
|
374
|
+
maxBorrowRate: Number(originMarketPoolData.maxBorrowRate.value) / 2 ** 32,
|
|
375
|
+
borrowRate: Number(originMarketPoolData.interestRate.value) / 2 ** 32,
|
|
376
|
+
borrowRateScale: Number(originMarketPoolData.interestRateScale),
|
|
377
|
+
borrowIndex: Number(originMarketPoolData.borrowIndex),
|
|
378
|
+
lastUpdated: Number(originMarketPoolData.lastUpdated),
|
|
379
|
+
cashAmount: Number(originMarketPoolData.cash),
|
|
380
|
+
debtAmount: Number(originMarketPoolData.debt),
|
|
381
|
+
marketCoinSupplyAmount: Number(originMarketPoolData.marketCoinSupply),
|
|
382
|
+
reserveAmount: Number(originMarketPoolData.reserve),
|
|
383
|
+
reserveFactor: Number(originMarketPoolData.reserveFactor.value) / 2 ** 32,
|
|
384
|
+
borrowWeight: Number(originMarketPoolData.borrowWeight.value) / 2 ** 32,
|
|
385
|
+
borrowFee: Number(originMarketPoolData.borrowFeeRate.value) / 2 ** 32,
|
|
386
|
+
// Parse origin data required for additional display.
|
|
387
|
+
baseBorrowRate: Number(originMarketPoolData.baseBorrowRatePerSec.value) / 2 ** 32,
|
|
388
|
+
borrowRateOnHighKink: Number(originMarketPoolData.borrowRateOnHighKink.value) / 2 ** 32,
|
|
389
|
+
borrowRateOnMidKink: Number(originMarketPoolData.borrowRateOnMidKink.value) / 2 ** 32,
|
|
390
|
+
highKink: Number(originMarketPoolData.highKink.value) / 2 ** 32,
|
|
391
|
+
midKink: Number(originMarketPoolData.midKink.value) / 2 ** 32,
|
|
392
|
+
minBorrowAmount: Number(originMarketPoolData.minBorrowAmount)
|
|
393
|
+
};
|
|
881
394
|
};
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
395
|
+
var calculateMarketPoolData = (utils, parsedMarketPoolData) => {
|
|
396
|
+
const poolCoinName = utils.parseCoinNameFromType(
|
|
397
|
+
parsedMarketPoolData.coinType
|
|
398
|
+
);
|
|
399
|
+
const coinDecimal = utils.getCoinDecimal(poolCoinName);
|
|
400
|
+
const borrowYearFactor = 24 * 365 * 3600;
|
|
401
|
+
const baseBorrowApr = parsedMarketPoolData.baseBorrowRate * borrowYearFactor / parsedMarketPoolData.borrowRateScale;
|
|
402
|
+
const borrowAprOnHighKink = parsedMarketPoolData.borrowRateOnHighKink * borrowYearFactor / parsedMarketPoolData.borrowRateScale;
|
|
403
|
+
const borrowAprOnMidKink = parsedMarketPoolData.borrowRateOnMidKink * borrowYearFactor / parsedMarketPoolData.borrowRateScale;
|
|
404
|
+
const maxBorrowApr = parsedMarketPoolData.maxBorrowRate * borrowYearFactor / parsedMarketPoolData.borrowRateScale;
|
|
405
|
+
const borrowApr = parsedMarketPoolData.borrowRate * borrowYearFactor / parsedMarketPoolData.borrowRateScale;
|
|
406
|
+
const timeDelta = Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3) - parsedMarketPoolData.lastUpdated;
|
|
407
|
+
const borrowIndexDelta = BigNumber(parsedMarketPoolData.borrowIndex).multipliedBy(
|
|
408
|
+
BigNumber(timeDelta).multipliedBy(parsedMarketPoolData.borrowRate)
|
|
409
|
+
).dividedBy(parsedMarketPoolData.borrowRateScale);
|
|
410
|
+
const currentBorrowIndex = BigNumber(parsedMarketPoolData.borrowIndex).plus(
|
|
411
|
+
borrowIndexDelta
|
|
412
|
+
);
|
|
413
|
+
const growthInterest = BigNumber(currentBorrowIndex).dividedBy(parsedMarketPoolData.borrowIndex).minus(1);
|
|
414
|
+
const increasedDebtAmount = BigNumber(
|
|
415
|
+
parsedMarketPoolData.debtAmount
|
|
416
|
+
).multipliedBy(growthInterest);
|
|
417
|
+
const borrowAmount = increasedDebtAmount.plus(
|
|
418
|
+
parsedMarketPoolData.debtAmount
|
|
419
|
+
);
|
|
420
|
+
const borrowCoin = borrowAmount.shiftedBy(-1 * coinDecimal);
|
|
421
|
+
const reserveAmount = BigNumber(parsedMarketPoolData.reserveAmount).plus(
|
|
422
|
+
increasedDebtAmount.multipliedBy(parsedMarketPoolData.reserveFactor)
|
|
423
|
+
);
|
|
424
|
+
const reserveCoin = reserveAmount.shiftedBy(-1 * coinDecimal);
|
|
425
|
+
const supplyAmount = BigNumber(borrowAmount).plus(
|
|
426
|
+
Math.max(parsedMarketPoolData.cashAmount - reserveAmount.toNumber(), 0)
|
|
427
|
+
);
|
|
428
|
+
const supplyCoin = supplyAmount.shiftedBy(-1 * coinDecimal);
|
|
429
|
+
let utilizationRate = BigNumber(borrowAmount).dividedBy(supplyAmount);
|
|
430
|
+
utilizationRate = utilizationRate.isFinite() ? utilizationRate : BigNumber(0);
|
|
431
|
+
let supplyApr = BigNumber(borrowApr).multipliedBy(utilizationRate).multipliedBy(1 - parsedMarketPoolData.reserveFactor);
|
|
432
|
+
supplyApr = supplyApr.isFinite() ? supplyApr : BigNumber(0);
|
|
433
|
+
let conversionRate = supplyAmount.dividedBy(
|
|
434
|
+
parsedMarketPoolData.marketCoinSupplyAmount
|
|
435
|
+
);
|
|
436
|
+
conversionRate = conversionRate.isFinite() && !conversionRate.isNaN() ? conversionRate : BigNumber(1);
|
|
437
|
+
return {
|
|
438
|
+
baseBorrowApr,
|
|
439
|
+
baseBorrowApy: utils.parseAprToApy(baseBorrowApr),
|
|
440
|
+
borrowAprOnHighKink,
|
|
441
|
+
borrowApyOnHighKink: utils.parseAprToApy(borrowAprOnHighKink),
|
|
442
|
+
borrowAprOnMidKink,
|
|
443
|
+
borrowApyOnMidKink: utils.parseAprToApy(borrowAprOnMidKink),
|
|
444
|
+
maxBorrowApr,
|
|
445
|
+
maxBorrowApy: utils.parseAprToApy(maxBorrowApr),
|
|
446
|
+
borrowApr: Math.min(borrowApr, maxBorrowApr),
|
|
447
|
+
borrowApy: Math.min(
|
|
448
|
+
utils.parseAprToApy(borrowApr),
|
|
449
|
+
utils.parseAprToApy(maxBorrowApr)
|
|
450
|
+
),
|
|
451
|
+
borrowIndex: currentBorrowIndex.toNumber(),
|
|
452
|
+
growthInterest: growthInterest.toNumber(),
|
|
453
|
+
supplyAmount: supplyAmount.toNumber(),
|
|
454
|
+
supplyCoin: supplyCoin.toNumber(),
|
|
455
|
+
borrowAmount: borrowAmount.toNumber(),
|
|
456
|
+
borrowCoin: borrowCoin.toNumber(),
|
|
457
|
+
reserveAmount: reserveAmount.toNumber(),
|
|
458
|
+
reserveCoin: reserveCoin.toNumber(),
|
|
459
|
+
utilizationRate: utilizationRate.toNumber(),
|
|
460
|
+
supplyApr: supplyApr.toNumber(),
|
|
461
|
+
supplyApy: utils.parseAprToApy(supplyApr.toNumber()),
|
|
462
|
+
conversionRate: conversionRate.toNumber()
|
|
463
|
+
};
|
|
464
|
+
};
|
|
465
|
+
var parseOriginMarketCollateralData = (originMarketCollateralData) => {
|
|
466
|
+
const divisor = 2 ** 32;
|
|
467
|
+
return {
|
|
468
|
+
coinType: normalizeStructTag(originMarketCollateralData.type.name),
|
|
469
|
+
collateralFactor: Number(originMarketCollateralData.collateralFactor.value) / divisor,
|
|
470
|
+
liquidationFactor: Number(originMarketCollateralData.liquidationFactor.value) / divisor,
|
|
471
|
+
liquidationDiscount: Number(originMarketCollateralData.liquidationDiscount.value) / divisor,
|
|
472
|
+
liquidationPanelty: Number(originMarketCollateralData.liquidationPanelty.value) / divisor,
|
|
473
|
+
liquidationReserveFactor: Number(originMarketCollateralData.liquidationReserveFactor.value) / divisor,
|
|
474
|
+
maxCollateralAmount: Number(originMarketCollateralData.maxCollateralAmount),
|
|
475
|
+
totalCollateralAmount: Number(
|
|
476
|
+
originMarketCollateralData.totalCollateralAmount
|
|
477
|
+
)
|
|
478
|
+
};
|
|
479
|
+
};
|
|
480
|
+
var calculateMarketCollateralData = (utils, parsedMarketCollateralData) => {
|
|
481
|
+
const collateralCoinName = utils.parseCoinNameFromType(
|
|
482
|
+
parsedMarketCollateralData.coinType
|
|
483
|
+
);
|
|
484
|
+
const coinDecimal = utils.getCoinDecimal(collateralCoinName);
|
|
485
|
+
const maxCollateralCoin = BigNumber(
|
|
486
|
+
parsedMarketCollateralData.maxCollateralAmount
|
|
487
|
+
).shiftedBy(-1 * coinDecimal);
|
|
488
|
+
const depositCoin = BigNumber(
|
|
489
|
+
parsedMarketCollateralData.totalCollateralAmount
|
|
490
|
+
).shiftedBy(-1 * coinDecimal);
|
|
491
|
+
return {
|
|
492
|
+
maxDepositAmount: parsedMarketCollateralData.maxCollateralAmount,
|
|
493
|
+
maxDepositCoin: maxCollateralCoin.toNumber(),
|
|
494
|
+
depositAmount: parsedMarketCollateralData.totalCollateralAmount,
|
|
495
|
+
depositCoin: depositCoin.toNumber()
|
|
496
|
+
};
|
|
497
|
+
};
|
|
498
|
+
var parseOriginSpoolData = (originSpoolData) => {
|
|
499
|
+
return {
|
|
500
|
+
stakeType: normalizeStructTag(originSpoolData.stakeType.fields.name),
|
|
501
|
+
maxPoint: Number(originSpoolData.maxDistributedPoint),
|
|
502
|
+
distributedPoint: Number(originSpoolData.distributedPoint),
|
|
503
|
+
pointPerPeriod: Number(originSpoolData.distributedPointPerPeriod),
|
|
504
|
+
period: Number(originSpoolData.pointDistributionTime),
|
|
505
|
+
maxStake: Number(originSpoolData.maxStake),
|
|
506
|
+
staked: Number(originSpoolData.stakes),
|
|
507
|
+
index: Number(originSpoolData.index),
|
|
508
|
+
createdAt: Number(originSpoolData.createdAt),
|
|
509
|
+
lastUpdate: Number(originSpoolData.lastUpdate)
|
|
510
|
+
};
|
|
511
|
+
};
|
|
512
|
+
var calculateSpoolData = (parsedSpoolData, stakeMarketCoinPrice, stakeMarketCoinDecimal) => {
|
|
513
|
+
const baseIndexRate = 1e9;
|
|
514
|
+
const distributedPointPerSec = BigNumber(
|
|
515
|
+
parsedSpoolData.pointPerPeriod
|
|
516
|
+
).dividedBy(parsedSpoolData.period);
|
|
517
|
+
const pointPerSec = BigNumber(parsedSpoolData.pointPerPeriod).dividedBy(
|
|
518
|
+
parsedSpoolData.period
|
|
519
|
+
);
|
|
520
|
+
const remainingPeriod = pointPerSec.gt(0) ? BigNumber(parsedSpoolData.maxPoint).minus(parsedSpoolData.distributedPoint).dividedBy(pointPerSec) : BigNumber(0);
|
|
521
|
+
const startDate = parsedSpoolData.createdAt;
|
|
522
|
+
const endDate = remainingPeriod.plus(parsedSpoolData.lastUpdate).integerValue().toNumber();
|
|
523
|
+
const timeDelta = BigNumber(
|
|
524
|
+
Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3) - parsedSpoolData.lastUpdate
|
|
525
|
+
).dividedBy(parsedSpoolData.period).toFixed(0);
|
|
526
|
+
const remainingPoints = BigNumber(parsedSpoolData.maxPoint).minus(
|
|
527
|
+
parsedSpoolData.distributedPoint
|
|
528
|
+
);
|
|
529
|
+
const accumulatedPoints = BigNumber.minimum(
|
|
530
|
+
BigNumber(timeDelta).multipliedBy(parsedSpoolData.pointPerPeriod),
|
|
531
|
+
remainingPoints
|
|
532
|
+
);
|
|
533
|
+
const currentPointIndex = BigNumber(parsedSpoolData.index).plus(
|
|
534
|
+
accumulatedPoints.dividedBy(parsedSpoolData.staked).isFinite() ? BigNumber(baseIndexRate).multipliedBy(accumulatedPoints).dividedBy(parsedSpoolData.staked) : 0
|
|
535
|
+
);
|
|
536
|
+
const currentTotalDistributedPoint = BigNumber(
|
|
537
|
+
parsedSpoolData.distributedPoint
|
|
538
|
+
).plus(accumulatedPoints);
|
|
539
|
+
const stakedAmount = BigNumber(parsedSpoolData.staked);
|
|
540
|
+
const stakedCoin = stakedAmount.shiftedBy(-1 * stakeMarketCoinDecimal);
|
|
541
|
+
const stakedValue = stakedCoin.multipliedBy(stakeMarketCoinPrice);
|
|
542
|
+
return {
|
|
543
|
+
distributedPointPerSec: distributedPointPerSec.toNumber(),
|
|
544
|
+
accumulatedPoints: accumulatedPoints.toNumber(),
|
|
545
|
+
currentPointIndex: currentPointIndex.toNumber(),
|
|
546
|
+
currentTotalDistributedPoint: currentTotalDistributedPoint.toNumber(),
|
|
547
|
+
startDate: new Date(startDate * 1e3),
|
|
548
|
+
endDate: new Date(endDate * 1e3),
|
|
549
|
+
stakedAmount: stakedAmount.toNumber(),
|
|
550
|
+
stakedCoin: stakedCoin.toNumber(),
|
|
551
|
+
stakedValue: stakedValue.toNumber()
|
|
552
|
+
};
|
|
553
|
+
};
|
|
554
|
+
var parseOriginSpoolRewardPoolData = (originSpoolRewardPoolData) => {
|
|
555
|
+
return {
|
|
556
|
+
claimedRewards: Number(originSpoolRewardPoolData.claimed_rewards),
|
|
557
|
+
exchangeRateDenominator: Number(
|
|
558
|
+
originSpoolRewardPoolData.exchange_rate_denominator
|
|
559
|
+
),
|
|
560
|
+
exchangeRateNumerator: Number(
|
|
561
|
+
originSpoolRewardPoolData.exchange_rate_numerator
|
|
562
|
+
),
|
|
563
|
+
rewards: Number(originSpoolRewardPoolData.rewards),
|
|
564
|
+
spoolId: String(originSpoolRewardPoolData.spool_id)
|
|
565
|
+
};
|
|
566
|
+
};
|
|
567
|
+
var calculateSpoolRewardPoolData = (parsedSpoolData, parsedSpoolRewardPoolData, calculatedSpoolData, rewardCoinPrice, rewardCoinDecimal) => {
|
|
568
|
+
const rateYearFactor = 365 * 24 * 60 * 60;
|
|
569
|
+
const rewardPerSec = BigNumber(calculatedSpoolData.distributedPointPerSec).multipliedBy(parsedSpoolRewardPoolData.exchangeRateNumerator).dividedBy(parsedSpoolRewardPoolData.exchangeRateDenominator);
|
|
570
|
+
const totalRewardAmount = BigNumber(parsedSpoolData.maxPoint).multipliedBy(parsedSpoolRewardPoolData.exchangeRateNumerator).dividedBy(parsedSpoolRewardPoolData.exchangeRateDenominator);
|
|
571
|
+
const totalRewardCoin = totalRewardAmount.shiftedBy(-1 * rewardCoinDecimal);
|
|
572
|
+
const totalRewardValue = totalRewardCoin.multipliedBy(rewardCoinPrice);
|
|
573
|
+
const remaindRewardAmount = BigNumber(parsedSpoolRewardPoolData.rewards);
|
|
574
|
+
const remaindRewardCoin = remaindRewardAmount.shiftedBy(
|
|
575
|
+
-1 * rewardCoinDecimal
|
|
576
|
+
);
|
|
577
|
+
const remaindRewardValue = remaindRewardCoin.multipliedBy(rewardCoinPrice);
|
|
578
|
+
const claimedRewardAmount = BigNumber(
|
|
579
|
+
parsedSpoolRewardPoolData.claimedRewards
|
|
580
|
+
);
|
|
581
|
+
const claimedRewardCoin = claimedRewardAmount.shiftedBy(
|
|
582
|
+
-1 * rewardCoinDecimal
|
|
583
|
+
);
|
|
584
|
+
const claimedRewardValue = claimedRewardCoin.multipliedBy(rewardCoinPrice);
|
|
585
|
+
const rewardValueForYear = BigNumber(rewardPerSec).shiftedBy(-1 * rewardCoinDecimal).multipliedBy(rateYearFactor).multipliedBy(rewardCoinPrice);
|
|
586
|
+
let rewardRate = rewardValueForYear.dividedBy(calculatedSpoolData.stakedValue).isFinite() ? rewardValueForYear.dividedBy(calculatedSpoolData.stakedValue).toNumber() : Infinity;
|
|
587
|
+
if (parsedSpoolData.maxPoint <= parsedSpoolData.distributedPoint || parsedSpoolData.pointPerPeriod === 0) {
|
|
588
|
+
rewardRate = Infinity;
|
|
589
|
+
}
|
|
590
|
+
return {
|
|
591
|
+
rewardApr: rewardRate,
|
|
592
|
+
totalRewardAmount: totalRewardAmount.toNumber(),
|
|
593
|
+
totalRewardCoin: totalRewardCoin.toNumber(),
|
|
594
|
+
totalRewardValue: totalRewardValue.toNumber(),
|
|
595
|
+
remaindRewardAmount: remaindRewardAmount.toNumber(),
|
|
596
|
+
remaindRewardCoin: remaindRewardCoin.toNumber(),
|
|
597
|
+
remaindRewardValue: remaindRewardValue.toNumber(),
|
|
598
|
+
claimedRewardAmount: claimedRewardAmount.toNumber(),
|
|
599
|
+
claimedRewardCoin: claimedRewardCoin.toNumber(),
|
|
600
|
+
claimedRewardValue: claimedRewardValue.toNumber(),
|
|
601
|
+
rewardPerSec: rewardPerSec.toNumber()
|
|
602
|
+
};
|
|
603
|
+
};
|
|
604
|
+
var parseOriginBorrowIncentivesPoolPointData = (originBorrowIncentivePoolPointData) => {
|
|
605
|
+
return {
|
|
606
|
+
pointType: normalizeStructTag(
|
|
607
|
+
originBorrowIncentivePoolPointData.point_type.name
|
|
608
|
+
),
|
|
609
|
+
distributedPointPerPeriod: Number(
|
|
610
|
+
originBorrowIncentivePoolPointData.distributed_point_per_period
|
|
611
|
+
),
|
|
612
|
+
period: Number(originBorrowIncentivePoolPointData.point_distribution_time),
|
|
613
|
+
distributedPoint: Number(
|
|
614
|
+
originBorrowIncentivePoolPointData.distributed_point
|
|
615
|
+
),
|
|
616
|
+
points: Number(originBorrowIncentivePoolPointData.points),
|
|
617
|
+
index: Number(originBorrowIncentivePoolPointData.index),
|
|
618
|
+
baseWeight: Number(originBorrowIncentivePoolPointData.base_weight),
|
|
619
|
+
weightedAmount: Number(originBorrowIncentivePoolPointData.weighted_amount),
|
|
620
|
+
lastUpdate: Number(originBorrowIncentivePoolPointData.last_update)
|
|
621
|
+
};
|
|
622
|
+
};
|
|
623
|
+
var parseOriginBorrowIncentivePoolData = (originBorrowIncentivePoolData) => {
|
|
624
|
+
return {
|
|
625
|
+
poolType: normalizeStructTag(originBorrowIncentivePoolData.pool_type.name),
|
|
626
|
+
minStakes: Number(originBorrowIncentivePoolData.min_stakes),
|
|
627
|
+
maxStakes: Number(originBorrowIncentivePoolData.max_stakes),
|
|
628
|
+
staked: Number(originBorrowIncentivePoolData.stakes),
|
|
629
|
+
createdAt: Number(originBorrowIncentivePoolData.created_at),
|
|
630
|
+
poolPoints: originBorrowIncentivePoolData.points.reduce(
|
|
631
|
+
(acc, point) => {
|
|
632
|
+
const parsed = parseOriginBorrowIncentivesPoolPointData(point);
|
|
633
|
+
const name = parseStructTag(
|
|
634
|
+
parsed.pointType
|
|
635
|
+
).name.toLowerCase();
|
|
636
|
+
acc[name] = parsed;
|
|
637
|
+
return acc;
|
|
971
638
|
},
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
639
|
+
{}
|
|
640
|
+
)
|
|
641
|
+
};
|
|
642
|
+
};
|
|
643
|
+
var calculateBorrowIncentivePoolPointData = (parsedBorrowIncentivePoolData, parsedBorrowIncentivePoolPointData, rewardCoinPrice, rewardCoinDecimal, poolCoinPrice, poolCoinDecimal) => {
|
|
644
|
+
const baseIndexRate = 1e9;
|
|
645
|
+
const distributedPointPerSec = BigNumber(
|
|
646
|
+
parsedBorrowIncentivePoolPointData.distributedPointPerPeriod
|
|
647
|
+
).dividedBy(parsedBorrowIncentivePoolPointData.period);
|
|
648
|
+
const timeDelta = BigNumber(
|
|
649
|
+
Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3) - parsedBorrowIncentivePoolPointData.lastUpdate
|
|
650
|
+
).dividedBy(parsedBorrowIncentivePoolPointData.period).toFixed(0);
|
|
651
|
+
const accumulatedPoints = BigNumber.minimum(
|
|
652
|
+
BigNumber(timeDelta).multipliedBy(
|
|
653
|
+
parsedBorrowIncentivePoolPointData.distributedPointPerPeriod
|
|
654
|
+
),
|
|
655
|
+
BigNumber(parsedBorrowIncentivePoolPointData.points)
|
|
656
|
+
);
|
|
657
|
+
const currentPointIndex = BigNumber(
|
|
658
|
+
parsedBorrowIncentivePoolPointData.index
|
|
659
|
+
).plus(
|
|
660
|
+
accumulatedPoints.dividedBy(parsedBorrowIncentivePoolPointData.weightedAmount).isFinite() ? BigNumber(baseIndexRate).multipliedBy(accumulatedPoints).dividedBy(parsedBorrowIncentivePoolPointData.weightedAmount) : 0
|
|
661
|
+
);
|
|
662
|
+
const currentTotalDistributedPoint = BigNumber(
|
|
663
|
+
parsedBorrowIncentivePoolPointData.distributedPoint
|
|
664
|
+
).plus(accumulatedPoints);
|
|
665
|
+
const baseWeight = BigNumber(parsedBorrowIncentivePoolPointData.baseWeight);
|
|
666
|
+
const weightedStakedAmount = BigNumber(
|
|
667
|
+
parsedBorrowIncentivePoolPointData.weightedAmount
|
|
668
|
+
);
|
|
669
|
+
const weightedStakedCoin = weightedStakedAmount.shiftedBy(
|
|
670
|
+
-1 * poolCoinDecimal
|
|
671
|
+
);
|
|
672
|
+
const weightedStakedValue = weightedStakedCoin.multipliedBy(poolCoinPrice);
|
|
673
|
+
const rateYearFactor = 365 * 24 * 60 * 60;
|
|
674
|
+
const rewardPerSec = BigNumber(distributedPointPerSec).shiftedBy(
|
|
675
|
+
-1 * rewardCoinDecimal
|
|
676
|
+
);
|
|
677
|
+
const rewardValueForYear = BigNumber(rewardPerSec).multipliedBy(rateYearFactor).multipliedBy(rewardCoinPrice);
|
|
678
|
+
const weightScale = BigNumber(1e12);
|
|
679
|
+
const rewardRate = rewardValueForYear.multipliedBy(
|
|
680
|
+
BigNumber(parsedBorrowIncentivePoolPointData.baseWeight).dividedBy(
|
|
681
|
+
weightScale
|
|
682
|
+
)
|
|
683
|
+
).dividedBy(weightedStakedValue).isFinite() && parsedBorrowIncentivePoolPointData.points > 0 ? rewardValueForYear.multipliedBy(
|
|
684
|
+
BigNumber(parsedBorrowIncentivePoolPointData.baseWeight).dividedBy(
|
|
685
|
+
weightScale
|
|
686
|
+
)
|
|
687
|
+
).dividedBy(weightedStakedValue).toNumber() : Infinity;
|
|
688
|
+
return {
|
|
689
|
+
distributedPointPerSec: distributedPointPerSec.toNumber(),
|
|
690
|
+
accumulatedPoints: accumulatedPoints.toNumber(),
|
|
691
|
+
currentPointIndex: currentPointIndex.toNumber(),
|
|
692
|
+
currentTotalDistributedPoint: currentTotalDistributedPoint.toNumber(),
|
|
693
|
+
baseWeight: baseWeight.toNumber(),
|
|
694
|
+
weightedStakedAmount: weightedStakedAmount.toNumber(),
|
|
695
|
+
weightedStakedCoin: weightedStakedCoin.toNumber(),
|
|
696
|
+
weightedStakedValue: weightedStakedValue.toNumber(),
|
|
697
|
+
rewardApr: rewardRate,
|
|
698
|
+
rewardPerSec: rewardPerSec.toNumber()
|
|
699
|
+
};
|
|
700
|
+
};
|
|
701
|
+
var parseOriginBorrowIncentiveAccountPoolPointData = (originBorrowIncentiveAccountPoolPointData) => {
|
|
702
|
+
return {
|
|
703
|
+
pointType: normalizeStructTag(
|
|
704
|
+
originBorrowIncentiveAccountPoolPointData.point_type.name
|
|
705
|
+
),
|
|
706
|
+
weightedAmount: Number(
|
|
707
|
+
originBorrowIncentiveAccountPoolPointData.weighted_amount
|
|
708
|
+
),
|
|
709
|
+
points: Number(originBorrowIncentiveAccountPoolPointData.points),
|
|
710
|
+
totalPoints: Number(originBorrowIncentiveAccountPoolPointData.total_points),
|
|
711
|
+
index: Number(originBorrowIncentiveAccountPoolPointData.index)
|
|
712
|
+
};
|
|
713
|
+
};
|
|
714
|
+
var parseOriginBorrowIncentiveAccountData = (originBorrowIncentiveAccountData) => {
|
|
715
|
+
return {
|
|
716
|
+
poolType: normalizeStructTag(
|
|
717
|
+
originBorrowIncentiveAccountData.pool_type.name
|
|
718
|
+
),
|
|
719
|
+
debtAmount: Number(originBorrowIncentiveAccountData.debt_amount),
|
|
720
|
+
pointList: originBorrowIncentiveAccountData.points_list.reduce(
|
|
721
|
+
(acc, point) => {
|
|
722
|
+
const parsed = parseOriginBorrowIncentiveAccountPoolPointData(point);
|
|
723
|
+
const name = parseStructTag(
|
|
724
|
+
parsed.pointType
|
|
725
|
+
).name.toLowerCase();
|
|
726
|
+
acc[name] = parsed;
|
|
727
|
+
return acc;
|
|
1010
728
|
},
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
729
|
+
{}
|
|
730
|
+
)
|
|
731
|
+
};
|
|
732
|
+
};
|
|
733
|
+
var minBigNumber = (...args) => {
|
|
734
|
+
return BigNumber(
|
|
735
|
+
args.reduce(
|
|
736
|
+
(min, current) => new BigNumber(current).lt(min) ? current : min
|
|
737
|
+
)
|
|
738
|
+
);
|
|
739
|
+
};
|
|
740
|
+
var estimatedFactor = (amount, scaleStep, type) => {
|
|
741
|
+
const amountOfDigits = Math.max(
|
|
742
|
+
1,
|
|
743
|
+
Math.floor(Math.log10(Math.abs(amount)) + 1)
|
|
744
|
+
);
|
|
745
|
+
const adjustScale = Math.max(Math.floor((amountOfDigits - 1) / scaleStep), 1) + 1;
|
|
746
|
+
let adjustFactor = Math.pow(10, -adjustScale);
|
|
747
|
+
adjustFactor = type === "increase" ? 1 - adjustFactor : 1 + adjustFactor;
|
|
748
|
+
return adjustFactor;
|
|
749
|
+
};
|
|
750
|
+
|
|
751
|
+
// src/utils/util.ts
|
|
752
|
+
var COIN_SET = Array.from(
|
|
753
|
+
/* @__PURE__ */ new Set([
|
|
754
|
+
...SUPPORT_POOLS,
|
|
755
|
+
...SUPPORT_COLLATERALS,
|
|
756
|
+
...SUPPORT_SPOOLS_REWARDS,
|
|
757
|
+
...SUPPORT_BORROW_INCENTIVE_REWARDS,
|
|
758
|
+
...SUPPORT_SCOIN
|
|
759
|
+
])
|
|
760
|
+
);
|
|
761
|
+
var isMarketCoin = (coinName) => {
|
|
762
|
+
const assetCoinName = coinName.slice(1).toLowerCase();
|
|
763
|
+
return coinName.charAt(0).toLowerCase() === "s" && COIN_SET.includes(assetCoinName);
|
|
764
|
+
};
|
|
765
|
+
var parseAssetSymbol = (coinName) => {
|
|
766
|
+
switch (coinName) {
|
|
767
|
+
case "afsui":
|
|
768
|
+
return "afSUI";
|
|
769
|
+
case "hasui":
|
|
770
|
+
return "haSUI";
|
|
771
|
+
case "vsui":
|
|
772
|
+
return "vSUI";
|
|
773
|
+
default:
|
|
774
|
+
return coinName.toUpperCase();
|
|
775
|
+
}
|
|
776
|
+
};
|
|
777
|
+
var parseDataFromPythPriceFeed = (feed, address) => {
|
|
778
|
+
const assetCoinNames = COIN_SET;
|
|
779
|
+
const assetCoinName = assetCoinNames.find((assetCoinName2) => {
|
|
780
|
+
return address.get(`core.coins.${assetCoinName2}.oracle.pyth.feed`) === feed.id;
|
|
781
|
+
});
|
|
782
|
+
if (assetCoinName) {
|
|
783
|
+
const price = feed.price.price * 10 ** feed.price.expo;
|
|
784
|
+
return {
|
|
785
|
+
coinName: assetCoinName,
|
|
786
|
+
price,
|
|
787
|
+
publishTime: Number(feed.price.publishTime) * 10 ** 3
|
|
788
|
+
};
|
|
789
|
+
} else {
|
|
790
|
+
throw new Error("Invalid feed id");
|
|
791
|
+
}
|
|
792
|
+
};
|
|
793
|
+
var findClosestUnlockRound = (unlockAtInSecondTimestamp) => {
|
|
794
|
+
const unlockDate = new Date(unlockAtInSecondTimestamp * 1e3);
|
|
795
|
+
const closestTwelveAM = new Date(unlockAtInSecondTimestamp * 1e3);
|
|
796
|
+
closestTwelveAM.setUTCHours(0, 0, 0, 0);
|
|
797
|
+
if (unlockDate.getUTCHours() >= 0) {
|
|
798
|
+
closestTwelveAM.setUTCDate(closestTwelveAM.getUTCDate() + 1);
|
|
799
|
+
}
|
|
800
|
+
const now = (/* @__PURE__ */ new Date()).getTime();
|
|
801
|
+
if (closestTwelveAM.getTime() - now > MAX_LOCK_DURATION * 1e3) {
|
|
802
|
+
closestTwelveAM.setUTCDate(closestTwelveAM.getUTCDate() - 1);
|
|
803
|
+
}
|
|
804
|
+
return Math.floor(closestTwelveAM.getTime() / 1e3);
|
|
805
|
+
};
|
|
806
|
+
|
|
807
|
+
// src/constants/tokenBucket.ts
|
|
808
|
+
var DEFAULT_TOKENS_PER_INTERVAL = 10;
|
|
809
|
+
var DEFAULT_INTERVAL_IN_MS = 1e3;
|
|
810
|
+
|
|
811
|
+
// src/utils/tokenBucket.ts
|
|
812
|
+
var TokenBucket = class {
|
|
813
|
+
constructor(tokensPerInterval, intervalInMs) {
|
|
814
|
+
this.tokensPerInterval = tokensPerInterval;
|
|
815
|
+
this.interval = intervalInMs;
|
|
816
|
+
this.tokens = tokensPerInterval;
|
|
817
|
+
this.lastRefill = Date.now();
|
|
818
|
+
}
|
|
819
|
+
refill() {
|
|
820
|
+
const now = Date.now();
|
|
821
|
+
const elapsed = now - this.lastRefill;
|
|
822
|
+
if (elapsed > this.interval) {
|
|
823
|
+
const tokensToAdd = Math.floor(elapsed / this.interval) * this.tokensPerInterval;
|
|
824
|
+
this.tokens = Math.min(this.tokens + tokensToAdd, this.tokensPerInterval);
|
|
825
|
+
this.lastRefill = now;
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
removeTokens(count) {
|
|
829
|
+
this.refill();
|
|
830
|
+
if (this.tokens >= count) {
|
|
831
|
+
this.tokens -= count;
|
|
832
|
+
return true;
|
|
833
|
+
}
|
|
834
|
+
return false;
|
|
835
|
+
}
|
|
836
|
+
};
|
|
837
|
+
var callWithRateLimit = async (tokenBucket, fn, retryDelayInMs = DEFAULT_INTERVAL_IN_MS, maxRetries = 5) => {
|
|
838
|
+
let retries = 0;
|
|
839
|
+
const tryRequest = async () => {
|
|
840
|
+
if (tokenBucket.removeTokens(1)) {
|
|
841
|
+
return await fn();
|
|
842
|
+
} else if (retries < maxRetries) {
|
|
843
|
+
retries++;
|
|
844
|
+
await new Promise((resolve) => setTimeout(resolve, retryDelayInMs));
|
|
845
|
+
return tryRequest();
|
|
846
|
+
} else {
|
|
847
|
+
console.error("Maximum retries reached");
|
|
848
|
+
return null;
|
|
849
|
+
}
|
|
850
|
+
};
|
|
851
|
+
return tryRequest();
|
|
852
|
+
};
|
|
853
|
+
|
|
854
|
+
// src/models/scallopCache.ts
|
|
855
|
+
var ScallopCache = class {
|
|
856
|
+
constructor(cacheOptions, suiKit, tokenBucket) {
|
|
857
|
+
this.queryClient = new QueryClient(cacheOptions ?? DEFAULT_CACHE_OPTIONS);
|
|
858
|
+
this._suiKit = suiKit;
|
|
859
|
+
this.tokenBucket = tokenBucket ?? new TokenBucket(DEFAULT_TOKENS_PER_INTERVAL, DEFAULT_INTERVAL_IN_MS);
|
|
860
|
+
}
|
|
861
|
+
get suiKit() {
|
|
862
|
+
if (!this._suiKit) {
|
|
863
|
+
throw new Error("SuiKit instance is not initialized");
|
|
864
|
+
}
|
|
865
|
+
return this._suiKit;
|
|
866
|
+
}
|
|
867
|
+
get client() {
|
|
868
|
+
return this.suiKit.client();
|
|
869
|
+
}
|
|
870
|
+
/**
|
|
871
|
+
* @description Invalidate cache based on the refetchType parameter
|
|
872
|
+
* @param refetchType Determines the type of queries to be refetched. Defaults to `active`.
|
|
873
|
+
*
|
|
874
|
+
* - `active`: Only queries that match the refetch predicate and are actively being rendered via useQuery and related functions will be refetched in the background.
|
|
875
|
+
* - `inactive`: Only queries that match the refetch predicate and are NOT actively being rendered via useQuery and related functions will be refetched in the background.
|
|
876
|
+
* - `all`: All queries that match the refetch predicate will be refetched in the background.
|
|
877
|
+
* - `none`: No queries will be refetched. Queries that match the refetch predicate will only be marked as invalid.
|
|
878
|
+
*/
|
|
879
|
+
invalidateAndRefetchAllCache(refetchType) {
|
|
880
|
+
return this.queryClient.invalidateQueries({
|
|
881
|
+
refetchType
|
|
882
|
+
});
|
|
883
|
+
}
|
|
884
|
+
/**
|
|
885
|
+
* @description Cache protocol config call for 60 seconds.
|
|
886
|
+
* @returns Promise<ProtocolConfig>
|
|
887
|
+
*/
|
|
888
|
+
async getProtocolConfig() {
|
|
889
|
+
return await this.queryClient.fetchQuery({
|
|
890
|
+
queryKey: ["getProtocolConfig"],
|
|
891
|
+
queryFn: async () => {
|
|
892
|
+
return await callWithRateLimit(
|
|
893
|
+
this.tokenBucket,
|
|
894
|
+
() => this.client.getProtocolConfig()
|
|
895
|
+
);
|
|
1023
896
|
},
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
897
|
+
staleTime: 3e4
|
|
898
|
+
});
|
|
899
|
+
}
|
|
900
|
+
/**
|
|
901
|
+
* @description Provides cache for inspectTxn of the SuiKit.
|
|
902
|
+
* @param QueryInspectTxnParams
|
|
903
|
+
* @param txBlock
|
|
904
|
+
* @returns Promise<DevInspectResults>
|
|
905
|
+
*/
|
|
906
|
+
async queryInspectTxn({
|
|
907
|
+
queryTarget,
|
|
908
|
+
args,
|
|
909
|
+
typeArgs
|
|
910
|
+
}) {
|
|
911
|
+
const txBlock = new SuiTxBlock();
|
|
912
|
+
const resolvedArgs = await Promise.all(
|
|
913
|
+
args.map(async (arg) => {
|
|
914
|
+
if (typeof arg === "string") {
|
|
915
|
+
return (await this.queryGetObject(arg, { showContent: true }))?.data;
|
|
916
|
+
}
|
|
917
|
+
return arg;
|
|
918
|
+
})
|
|
919
|
+
);
|
|
920
|
+
txBlock.moveCall(queryTarget, resolvedArgs, typeArgs);
|
|
921
|
+
const txBytes = await txBlock.txBlock.build({
|
|
922
|
+
client: this.client,
|
|
923
|
+
onlyTransactionKind: true,
|
|
924
|
+
protocolConfig: await this.getProtocolConfig() ?? void 0
|
|
925
|
+
});
|
|
926
|
+
const query = await this.queryClient.fetchQuery({
|
|
927
|
+
queryKey: typeArgs ? ["inspectTxn", queryTarget, JSON.stringify(args)] : [
|
|
928
|
+
"inspectTxn",
|
|
929
|
+
queryTarget,
|
|
930
|
+
JSON.stringify(args),
|
|
931
|
+
JSON.stringify(typeArgs)
|
|
932
|
+
],
|
|
933
|
+
queryFn: async () => {
|
|
934
|
+
return await callWithRateLimit(
|
|
935
|
+
this.tokenBucket,
|
|
936
|
+
() => this.suiKit.inspectTxn(txBytes)
|
|
937
|
+
);
|
|
938
|
+
}
|
|
939
|
+
});
|
|
940
|
+
return query;
|
|
941
|
+
}
|
|
942
|
+
/**
|
|
943
|
+
* @description Provides cache for getObject of the SuiKit.
|
|
944
|
+
* @param objectId
|
|
945
|
+
* @param QueryObjectParams
|
|
946
|
+
* @returns Promise<SuiObjectResponse>
|
|
947
|
+
*/
|
|
948
|
+
async queryGetObject(objectId, options) {
|
|
949
|
+
const queryKey = ["getObject", objectId, this.suiKit.currentAddress()];
|
|
950
|
+
if (options) {
|
|
951
|
+
queryKey.push(JSON.stringify(options));
|
|
952
|
+
}
|
|
953
|
+
return this.queryClient.fetchQuery({
|
|
954
|
+
queryKey,
|
|
955
|
+
queryFn: async () => {
|
|
956
|
+
return await callWithRateLimit(
|
|
957
|
+
this.tokenBucket,
|
|
958
|
+
() => this.client.getObject({
|
|
959
|
+
id: objectId,
|
|
960
|
+
options
|
|
961
|
+
})
|
|
962
|
+
);
|
|
963
|
+
}
|
|
964
|
+
});
|
|
965
|
+
}
|
|
966
|
+
/**
|
|
967
|
+
* @description Provides cache for getObjects of the SuiKit.
|
|
968
|
+
* @param objectIds
|
|
969
|
+
* @returns Promise<SuiObjectData[]>
|
|
970
|
+
*/
|
|
971
|
+
async queryGetObjects(objectIds, options) {
|
|
972
|
+
if (objectIds.length === 0)
|
|
973
|
+
return [];
|
|
974
|
+
const queryKey = [
|
|
975
|
+
"getObjects",
|
|
976
|
+
JSON.stringify(objectIds),
|
|
977
|
+
this.suiKit.currentAddress()
|
|
978
|
+
];
|
|
979
|
+
if (options) {
|
|
980
|
+
queryKey.push(JSON.stringify(options));
|
|
981
|
+
}
|
|
982
|
+
return this.queryClient.fetchQuery({
|
|
983
|
+
queryKey,
|
|
984
|
+
queryFn: async () => {
|
|
985
|
+
return await callWithRateLimit(
|
|
986
|
+
this.tokenBucket,
|
|
987
|
+
() => this.suiKit.getObjects(objectIds, options)
|
|
988
|
+
);
|
|
989
|
+
}
|
|
990
|
+
});
|
|
991
|
+
}
|
|
992
|
+
/**
|
|
993
|
+
* @description Provides cache for getOwnedObjects of the SuiKit.
|
|
994
|
+
* @param input
|
|
995
|
+
* @returns Promise<PaginatedObjectsResponse>
|
|
996
|
+
*/
|
|
997
|
+
async queryGetOwnedObjects(input) {
|
|
998
|
+
const queryKey = ["getOwnedObjects", input.owner];
|
|
999
|
+
if (input.cursor) {
|
|
1000
|
+
queryKey.push(JSON.stringify(input.cursor));
|
|
1001
|
+
}
|
|
1002
|
+
if (input.options) {
|
|
1003
|
+
queryKey.push(JSON.stringify(input.options));
|
|
1004
|
+
}
|
|
1005
|
+
if (input.filter) {
|
|
1006
|
+
queryKey.push(JSON.stringify(input.filter));
|
|
1007
|
+
}
|
|
1008
|
+
if (input.limit) {
|
|
1009
|
+
queryKey.push(JSON.stringify(input.limit));
|
|
1010
|
+
}
|
|
1011
|
+
return this.queryClient.fetchQuery({
|
|
1012
|
+
queryKey,
|
|
1013
|
+
queryFn: async () => {
|
|
1014
|
+
return await callWithRateLimit(
|
|
1015
|
+
this.tokenBucket,
|
|
1016
|
+
() => this.client.getOwnedObjects(input)
|
|
1017
|
+
);
|
|
1018
|
+
}
|
|
1019
|
+
});
|
|
1020
|
+
}
|
|
1021
|
+
async queryGetDynamicFields(input) {
|
|
1022
|
+
const queryKey = ["getDynamicFields", input.parentId];
|
|
1023
|
+
if (input.cursor) {
|
|
1024
|
+
queryKey.push(JSON.stringify(input.cursor));
|
|
1025
|
+
}
|
|
1026
|
+
if (input.limit) {
|
|
1027
|
+
queryKey.push(JSON.stringify(input.limit));
|
|
1028
|
+
}
|
|
1029
|
+
return this.queryClient.fetchQuery({
|
|
1030
|
+
queryKey,
|
|
1031
|
+
queryFn: async () => {
|
|
1032
|
+
return await callWithRateLimit(
|
|
1033
|
+
this.tokenBucket,
|
|
1034
|
+
() => this.client.getDynamicFields(input)
|
|
1035
|
+
);
|
|
1036
|
+
}
|
|
1037
|
+
});
|
|
1038
|
+
}
|
|
1039
|
+
async queryGetDynamicFieldObject(input) {
|
|
1040
|
+
const queryKey = [
|
|
1041
|
+
"getDynamicFieldObject",
|
|
1042
|
+
input.parentId,
|
|
1043
|
+
input.name.type,
|
|
1044
|
+
input.name.value
|
|
1045
|
+
];
|
|
1046
|
+
return this.queryClient.fetchQuery({
|
|
1047
|
+
queryKey,
|
|
1048
|
+
queryFn: async () => {
|
|
1049
|
+
return await callWithRateLimit(
|
|
1050
|
+
this.tokenBucket,
|
|
1051
|
+
() => this.client.getDynamicFieldObject(input)
|
|
1052
|
+
);
|
|
1053
|
+
}
|
|
1054
|
+
});
|
|
1055
|
+
}
|
|
1056
|
+
async queryGetAllCoinBalances(owner) {
|
|
1057
|
+
const queryKey = ["getAllCoinBalances", owner];
|
|
1058
|
+
return this.queryClient.fetchQuery({
|
|
1059
|
+
queryKey,
|
|
1060
|
+
queryFn: async () => {
|
|
1061
|
+
const allBalances = await callWithRateLimit(
|
|
1062
|
+
this.tokenBucket,
|
|
1063
|
+
() => this.client.getAllBalances({ owner })
|
|
1064
|
+
);
|
|
1065
|
+
if (!allBalances)
|
|
1066
|
+
return {};
|
|
1067
|
+
const balances = allBalances.reduce(
|
|
1068
|
+
(acc, coinBalance) => {
|
|
1069
|
+
if (coinBalance.totalBalance !== "0") {
|
|
1070
|
+
acc[normalizeStructTag2(coinBalance.coinType)] = coinBalance.totalBalance;
|
|
1071
|
+
}
|
|
1072
|
+
return acc;
|
|
1073
|
+
},
|
|
1074
|
+
{}
|
|
1075
|
+
);
|
|
1076
|
+
for (const coinType in balances) {
|
|
1077
|
+
const coinBalanceQueryKey = [
|
|
1078
|
+
"getCoinBalance",
|
|
1079
|
+
normalizeSuiAddress(owner),
|
|
1080
|
+
normalizeStructTag2(coinType)
|
|
1081
|
+
];
|
|
1082
|
+
this.queryClient.setQueryData(
|
|
1083
|
+
coinBalanceQueryKey,
|
|
1084
|
+
balances[coinType]
|
|
1085
|
+
);
|
|
1086
|
+
}
|
|
1087
|
+
return balances;
|
|
1088
|
+
}
|
|
1089
|
+
});
|
|
1090
|
+
}
|
|
1091
|
+
async queryGetCoinBalance(input) {
|
|
1092
|
+
if (!input.coinType)
|
|
1093
|
+
return "0";
|
|
1094
|
+
const queryKey = [
|
|
1095
|
+
"getCoinBalance",
|
|
1096
|
+
normalizeSuiAddress(input.owner),
|
|
1097
|
+
normalizeStructTag2(input.coinType)
|
|
1098
|
+
];
|
|
1099
|
+
return this.queryClient.fetchQuery({
|
|
1100
|
+
queryKey,
|
|
1101
|
+
queryFn: async () => {
|
|
1102
|
+
if (!input.coinType)
|
|
1103
|
+
return "0";
|
|
1104
|
+
return (await this.queryGetAllCoinBalances(input.owner))[normalizeStructTag2(input.coinType)] ?? "0";
|
|
1105
|
+
}
|
|
1106
|
+
});
|
|
1107
|
+
}
|
|
1108
|
+
};
|
|
1109
|
+
|
|
1110
|
+
// src/models/scallopAddress.ts
|
|
1111
|
+
import axios from "axios";
|
|
1112
|
+
|
|
1113
|
+
// src/constants/testAddress.ts
|
|
1114
|
+
var TEST_ADDRESSES = {
|
|
1115
|
+
core: {
|
|
1116
|
+
// version:
|
|
1117
|
+
// '0x07871c4b3c847a0f674510d4978d5cf6f960452795e8ff6f189fd2088a3f6ac7',
|
|
1118
|
+
version: "0x6156d5cd1538bec8a167a40fe1209a4ec9cf8137921fe0a697f191ac561f0b09",
|
|
1119
|
+
versionCap: "0x590a4011cb649b3878f3ea14b3a78674642a9548d79b7e091ef679574b158a07",
|
|
1120
|
+
// object:
|
|
1121
|
+
// '0xefe8b36d5b2e43728cc323298626b83177803521d195cfb11e15b910e892fddf',
|
|
1122
|
+
object: "0x87ddec2984645dbbe2403a509cc6edf393a43acdba9b77d45da2bcbefcf733c1",
|
|
1123
|
+
// market:
|
|
1124
|
+
// '0xa757975255146dc9686aa823b7838b507f315d704f428cbadad2f4ea061939d9',
|
|
1125
|
+
market: "0x8606ed145cc887985b8ed793f7753ff5dc762a42c379dac035f568e1bac58490",
|
|
1126
|
+
adminCap: "0x09689d018e71c337d9db6d67cbca06b74ed92196103624028ccc3ecea411777c",
|
|
1127
|
+
coinDecimalsRegistry: "0x200abe9bf19751cc566ae35aa58e2b7e4ff688fc1130f8d8909ea09bc137d668",
|
|
1128
|
+
// obligationAccessStore:
|
|
1129
|
+
// '0x733e30b7c94d619d78cb8f5bc4bfbb759ced9a531239028caabb2474e5be59c9',
|
|
1130
|
+
obligationAccessStore: "0x48b472d68ca910c45f7f3b6c26836b6aa6d2569810d94b1b939023da05ae0a23",
|
|
1131
|
+
coins: {
|
|
1132
|
+
cetus: {
|
|
1133
|
+
id: "0x06864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b",
|
|
1134
|
+
metaData: "0x4c0dce55eff2db5419bbd2d239d1aa22b4a400c01bbb648b058a9883989025da",
|
|
1027
1135
|
treasury: "",
|
|
1028
1136
|
oracle: {
|
|
1029
1137
|
supra: "",
|
|
1030
1138
|
switchboard: "",
|
|
1031
1139
|
pyth: {
|
|
1032
|
-
feed: "",
|
|
1033
|
-
feedObject: ""
|
|
1140
|
+
feed: "e5b274b2611143df055d6e7cd8d93fe1961716bcd4dca1cad87a83bc1e78c1ef",
|
|
1141
|
+
feedObject: "0x24c0247fb22457a719efac7f670cdc79be321b521460bd6bd2ccfa9f80713b14"
|
|
1034
1142
|
}
|
|
1035
1143
|
}
|
|
1036
1144
|
},
|
|
1037
|
-
|
|
1038
|
-
id: "",
|
|
1039
|
-
metaData: "",
|
|
1145
|
+
apt: {
|
|
1146
|
+
id: "0x3a5143bb1196e3bcdfab6203d1683ae29edd26294fc8bfeafe4aaa9d2704df37",
|
|
1147
|
+
metaData: "0xc969c5251f372c0f34c32759f1d315cf1ea0ee5e4454b52aea08778eacfdd0a8",
|
|
1040
1148
|
treasury: "",
|
|
1041
1149
|
oracle: {
|
|
1042
1150
|
supra: "",
|
|
1043
1151
|
switchboard: "",
|
|
1044
1152
|
pyth: {
|
|
1045
|
-
feed: "",
|
|
1046
|
-
feedObject: ""
|
|
1153
|
+
feed: "03ae4db29ed4ae33d323568895aa00337e658e348b37509f5372ae51f0af00d5",
|
|
1154
|
+
feedObject: "0x7c5b7837c44a69b469325463ac0673ac1aa8435ff44ddb4191c9ae380463647f"
|
|
1047
1155
|
}
|
|
1048
1156
|
}
|
|
1049
|
-
}
|
|
1050
|
-
},
|
|
1051
|
-
oracles: {
|
|
1052
|
-
xOracle: "",
|
|
1053
|
-
xOracleCap: "",
|
|
1054
|
-
supra: { registry: "", registryCap: "", holder: "" },
|
|
1055
|
-
switchboard: { registry: "", registryCap: "" },
|
|
1056
|
-
pyth: {
|
|
1057
|
-
registry: "",
|
|
1058
|
-
registryCap: "",
|
|
1059
|
-
state: "",
|
|
1060
|
-
wormhole: "",
|
|
1061
|
-
wormholeState: ""
|
|
1062
|
-
}
|
|
1063
|
-
},
|
|
1064
|
-
packages: {
|
|
1065
|
-
coinDecimalsRegistry: {
|
|
1066
|
-
id: "",
|
|
1067
|
-
upgradeCap: ""
|
|
1068
1157
|
},
|
|
1069
|
-
|
|
1070
|
-
id: "",
|
|
1071
|
-
|
|
1158
|
+
sol: {
|
|
1159
|
+
id: "0xb7844e289a8410e50fb3ca48d69eb9cf29e27d223ef90353fe1bd8e27ff8f3f8",
|
|
1160
|
+
metaData: "0x4d2c39082b4477e3e79dc4562d939147ab90c42fc5f3e4acf03b94383cd69b6e",
|
|
1161
|
+
treasury: "",
|
|
1162
|
+
oracle: {
|
|
1163
|
+
supra: "",
|
|
1164
|
+
switchboard: "",
|
|
1165
|
+
pyth: {
|
|
1166
|
+
feed: "ef0d8b6fda2ceba41da15d4095d1da392a0d2f8ed0c6c7bc0f4cfac8c280b56d",
|
|
1167
|
+
feedObject: "0x9d0d275efbd37d8a8855f6f2c761fa5983293dd8ce202ee5196626de8fcd4469"
|
|
1168
|
+
}
|
|
1169
|
+
}
|
|
1072
1170
|
},
|
|
1073
|
-
|
|
1074
|
-
id: "",
|
|
1075
|
-
|
|
1171
|
+
btc: {
|
|
1172
|
+
id: "0x027792d9fed7f9844eb4839566001bb6f6cb4804f66aa2da6fe1ee242d896881",
|
|
1173
|
+
metaData: "0x5d3c6e60eeff8a05b693b481539e7847dfe33013e7070cdcb387f5c0cac05dfd",
|
|
1174
|
+
treasury: "",
|
|
1175
|
+
oracle: {
|
|
1176
|
+
supra: "",
|
|
1177
|
+
switchboard: "",
|
|
1178
|
+
pyth: {
|
|
1179
|
+
feed: "e62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43",
|
|
1180
|
+
feedObject: "0x9a62b4863bdeaabdc9500fce769cf7e72d5585eeb28a6d26e4cafadc13f76ab2"
|
|
1181
|
+
}
|
|
1182
|
+
}
|
|
1183
|
+
},
|
|
1184
|
+
eth: {
|
|
1185
|
+
id: "0xaf8cd5edc19c4512f4259f0bee101a40d41ebed738ade5874359610ef8eeced5",
|
|
1186
|
+
metaData: "0x8900e4ceede3363bef086d6b50ca89d816d0e90bf6bc46efefe1f8455e08f50f",
|
|
1187
|
+
treasury: "",
|
|
1188
|
+
oracle: {
|
|
1189
|
+
supra: "",
|
|
1190
|
+
switchboard: "",
|
|
1191
|
+
pyth: {
|
|
1192
|
+
feed: "ff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace",
|
|
1193
|
+
feedObject: "0x9193fd47f9a0ab99b6e365a464c8a9ae30e6150fc37ed2a89c1586631f6fc4ab"
|
|
1194
|
+
}
|
|
1195
|
+
}
|
|
1196
|
+
},
|
|
1197
|
+
usdc: {
|
|
1198
|
+
id: "0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf",
|
|
1199
|
+
metaData: "0x4fbf84f3029bd0c0b77164b587963be957f853eccf834a67bb9ecba6ec80f189",
|
|
1200
|
+
treasury: "",
|
|
1201
|
+
oracle: {
|
|
1202
|
+
supra: "",
|
|
1203
|
+
switchboard: "",
|
|
1204
|
+
pyth: {
|
|
1205
|
+
feed: "eaa020c61cc479712813461ce153894a96a6c00b21ed0cfc2798d1f9a9e9c94a",
|
|
1206
|
+
feedObject: "0x5dec622733a204ca27f5a90d8c2fad453cc6665186fd5dff13a83d0b6c9027ab"
|
|
1207
|
+
}
|
|
1208
|
+
}
|
|
1209
|
+
},
|
|
1210
|
+
usdt: {
|
|
1211
|
+
id: "0xc060006111016b8a020ad5b33834984a437aaa7d3c74c18e09a95d48aceab08c",
|
|
1212
|
+
metaData: "0xfb0e3eb97dd158a5ae979dddfa24348063843c5b20eb8381dd5fa7c93699e45c",
|
|
1213
|
+
treasury: "",
|
|
1214
|
+
oracle: {
|
|
1215
|
+
supra: "",
|
|
1216
|
+
switchboard: "",
|
|
1217
|
+
pyth: {
|
|
1218
|
+
feed: "2b89b9dc8fdf9f34709a5b106b472f0f39bb6ca9ce04b0fd7f2e971688e2e53b",
|
|
1219
|
+
feedObject: "0x985e3db9f93f76ee8bace7c3dd5cc676a096accd5d9e09e9ae0fb6e492b14572"
|
|
1220
|
+
}
|
|
1221
|
+
}
|
|
1222
|
+
},
|
|
1223
|
+
sui: {
|
|
1224
|
+
id: "0x0000000000000000000000000000000000000000000000000000000000000002",
|
|
1225
|
+
metaData: "0x9258181f5ceac8dbffb7030890243caed69a9599d2886d957a9cb7656af3bdb3",
|
|
1226
|
+
treasury: "",
|
|
1227
|
+
oracle: {
|
|
1228
|
+
supra: "",
|
|
1229
|
+
switchboard: "0xbca474133638352ba83ccf7b5c931d50f764b09550e16612c9f70f1e21f3f594",
|
|
1230
|
+
pyth: {
|
|
1231
|
+
feed: "23d7315113f5b1d3ba7a83604c44b94d79f4fd69af77f804fc7f920a6dc65744",
|
|
1232
|
+
feedObject: "0x801dbc2f0053d34734814b2d6df491ce7807a725fe9a01ad74a07e9c51396c37"
|
|
1233
|
+
}
|
|
1234
|
+
}
|
|
1235
|
+
},
|
|
1236
|
+
afsui: {
|
|
1237
|
+
id: "0xf325ce1300e8dac124071d3152c5c5ee6174914f8bc2161e88329cf579246efc",
|
|
1238
|
+
metaData: "0x2f9217f533e51334873a39b8026a4aa6919497b47f49d0986a4f1aec66f8a34d",
|
|
1239
|
+
treasury: "",
|
|
1240
|
+
oracle: {
|
|
1241
|
+
supra: "",
|
|
1242
|
+
switchboard: "",
|
|
1243
|
+
pyth: {
|
|
1244
|
+
feed: "23d7315113f5b1d3ba7a83604c44b94d79f4fd69af77f804fc7f920a6dc65744",
|
|
1245
|
+
feedObject: "0x801dbc2f0053d34734814b2d6df491ce7807a725fe9a01ad74a07e9c51396c37"
|
|
1246
|
+
}
|
|
1247
|
+
}
|
|
1248
|
+
},
|
|
1249
|
+
hasui: {
|
|
1250
|
+
id: "0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d",
|
|
1251
|
+
metaData: "0x2c5f33af93f6511df699aaaa5822d823aac6ed99d4a0de2a4a50b3afa0172e24",
|
|
1252
|
+
treasury: "",
|
|
1253
|
+
oracle: {
|
|
1254
|
+
supra: "",
|
|
1255
|
+
switchboard: "",
|
|
1256
|
+
pyth: {
|
|
1257
|
+
feed: "23d7315113f5b1d3ba7a83604c44b94d79f4fd69af77f804fc7f920a6dc65744",
|
|
1258
|
+
feedObject: "0x801dbc2f0053d34734814b2d6df491ce7807a725fe9a01ad74a07e9c51396c37"
|
|
1259
|
+
}
|
|
1260
|
+
}
|
|
1261
|
+
},
|
|
1262
|
+
vsui: {
|
|
1263
|
+
id: "0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55",
|
|
1264
|
+
metaData: "0xabd84a23467b33854ab25cf862006fd97479f8f6f53e50fe732c43a274d939bd",
|
|
1265
|
+
treasury: "",
|
|
1266
|
+
oracle: {
|
|
1267
|
+
supra: "",
|
|
1268
|
+
switchboard: "",
|
|
1269
|
+
pyth: {
|
|
1270
|
+
feed: "23d7315113f5b1d3ba7a83604c44b94d79f4fd69af77f804fc7f920a6dc65744",
|
|
1271
|
+
feedObject: "0x801dbc2f0053d34734814b2d6df491ce7807a725fe9a01ad74a07e9c51396c37"
|
|
1272
|
+
}
|
|
1273
|
+
}
|
|
1274
|
+
},
|
|
1275
|
+
sca: {
|
|
1276
|
+
id: "0x7016aae72cfc67f2fadf55769c0a7dd54291a583b63051a5ed71081cce836ac6",
|
|
1277
|
+
metaData: "0x5d26a1e9a55c88147ac870bfa31b729d7f49f8804b8b3adfdf3582d301cca844",
|
|
1278
|
+
treasury: "",
|
|
1279
|
+
oracle: {
|
|
1280
|
+
supra: "",
|
|
1281
|
+
switchboard: "",
|
|
1282
|
+
pyth: {
|
|
1283
|
+
feed: "7e17f0ac105abe9214deb9944c30264f5986bf292869c6bd8e8da3ccd92d79bc",
|
|
1284
|
+
feedObject: "0xf6de1d3279a269a597d813cbaca59aa906543ab9a8c64e84a4722f1a20863985"
|
|
1285
|
+
}
|
|
1286
|
+
}
|
|
1287
|
+
}
|
|
1288
|
+
},
|
|
1289
|
+
oracles: {
|
|
1290
|
+
xOracle: "0x93d5bf0936b71eb27255941e532fac33b5a5c7759e377b4923af0a1359ad494f",
|
|
1291
|
+
xOracleCap: "0x1edeae568fde99e090dbdec4bcdbd33a15f53a1ce1f87aeef1a560dedf4b4a90",
|
|
1292
|
+
supra: { registry: "", registryCap: "", holder: "" },
|
|
1293
|
+
switchboard: { registry: "", registryCap: "" },
|
|
1294
|
+
pyth: {
|
|
1295
|
+
registry: "0xedc293f9413a5a7a5d53bdba1fd889d0a4030894469228f0acdae4aa3c55a213",
|
|
1296
|
+
registryCap: "0xbcb07141eb1f7e01fbda4130ecf5f5adaeabb77f5d9c32158b7532bcd2197acd",
|
|
1297
|
+
state: "0x1f9310238ee9298fb703c3419030b35b22bb1cc37113e3bb5007c99aec79e5b8",
|
|
1298
|
+
wormhole: "0x5306f64e312b581766351c07af79c72fcb1cd25147157fdc2f8ad76de9a3fb6a",
|
|
1299
|
+
wormholeState: "0xaeab97f96cf9877fee2883315d459552b2b921edc16d7ceac6eab944dd88919c"
|
|
1300
|
+
}
|
|
1301
|
+
},
|
|
1302
|
+
packages: {
|
|
1303
|
+
coinDecimalsRegistry: {
|
|
1304
|
+
id: "0xca5a5a62f01c79a104bf4d31669e29daa387f325c241de4edbe30986a9bc8b0d",
|
|
1305
|
+
upgradeCap: "0x34e76a945d29f195bc53ca704fa70877d1cf3a5d7bbfdda1b13e633fff13c0f6"
|
|
1306
|
+
},
|
|
1307
|
+
math: {
|
|
1308
|
+
id: "0xad013d5fde39e15eabda32b3dbdafd67dac32b798ce63237c27a8f73339b9b6f",
|
|
1309
|
+
upgradeCap: "0x3a329598231de02e6135c62284b66005b41cad1d9ab7ca2dc79c08293aba2ec6"
|
|
1310
|
+
},
|
|
1311
|
+
whitelist: {
|
|
1312
|
+
id: "0x1318fdc90319ec9c24df1456d960a447521b0a658316155895014a6e39b5482f",
|
|
1313
|
+
upgradeCap: "0xf5a22aea23db664f7b69855b6a546747f17c1ec4230319cfc17225e462b05761"
|
|
1076
1314
|
},
|
|
1077
1315
|
x: {
|
|
1078
|
-
id: "",
|
|
1079
|
-
upgradeCap: ""
|
|
1316
|
+
id: "0x779b5c547976899f5474f3a5bc0db36ddf4697ad7e5a901db0415c2281d28162",
|
|
1317
|
+
upgradeCap: "0x3f203f6fff6a69d151e4f1cd931f22b68c489ef2759765662fc7baf673943c9e"
|
|
1080
1318
|
},
|
|
1081
1319
|
protocol: {
|
|
1082
|
-
id: "",
|
|
1083
|
-
upgradeCap: ""
|
|
1320
|
+
id: "0x87ddec2984645dbbe2403a509cc6edf393a43acdba9b77d45da2bcbefcf733c1",
|
|
1321
|
+
upgradeCap: "0x38527d154618d1fd5a644b90717fe07cf0e9f26b46b63e9568e611a3f86d5c1a"
|
|
1084
1322
|
},
|
|
1323
|
+
// protocol: {
|
|
1324
|
+
// id: '0x6e641f0dca8aedab3101d047e96439178f16301bf0b57fe8745086ff1195eb3e',
|
|
1325
|
+
// upgradeCap:
|
|
1326
|
+
// '0x38527d154618d1fd5a644b90717fe07cf0e9f26b46b63e9568e611a3f86d5c1a',
|
|
1327
|
+
// },
|
|
1085
1328
|
protocolWhitelist: {
|
|
1086
|
-
id: "",
|
|
1087
|
-
upgradeCap: ""
|
|
1329
|
+
id: "0x4c262d9343dac53ecb28f482a2a3f62c73d0ebac5b5f03d57383d56ff219acdf",
|
|
1330
|
+
upgradeCap: "0x4a5e88a75039b00988f633f811f58117f31b8627a46bf822aa114d9010049449"
|
|
1088
1331
|
},
|
|
1332
|
+
// query: {
|
|
1333
|
+
// id: '0xb8d603a39114a5efef3dd0bf84df0bed1be1fbd39b78b7dd6e8a61ccc5e6006f',
|
|
1334
|
+
// upgradeCap:
|
|
1335
|
+
// '0x0d535c35f608b9b01b7ccce11acf43b1dd80c1b72bf8b541744a6e28e8d2745f',
|
|
1336
|
+
// },
|
|
1089
1337
|
query: {
|
|
1090
|
-
id: "",
|
|
1091
|
-
upgradeCap: ""
|
|
1338
|
+
id: "0xe4f9d62d17746d5b9dbf0d5557747430021a71575780b515161210cdba0a4c1c",
|
|
1339
|
+
upgradeCap: "0x0d535c35f608b9b01b7ccce11acf43b1dd80c1b72bf8b541744a6e28e8d2745f"
|
|
1092
1340
|
},
|
|
1093
1341
|
supra: { id: "", upgradeCap: "" },
|
|
1094
1342
|
pyth: {
|
|
1095
|
-
id: "",
|
|
1096
|
-
upgradeCap: ""
|
|
1343
|
+
id: "0x910f30cbc7f601f75a5141a01265cd47c62d468707c5e1aecb32a18f448cb25a",
|
|
1344
|
+
upgradeCap: "0xdf0ffbae1ea5bb25fbca5efba433dcf00c7cced65679af2f04728901275c6157"
|
|
1097
1345
|
},
|
|
1098
1346
|
switchboard: { id: "", upgradeCap: "" },
|
|
1099
1347
|
xOracle: {
|
|
1100
|
-
id: "",
|
|
1101
|
-
upgradeCap: ""
|
|
1348
|
+
id: "0x1478a432123e4b3d61878b629f2c692969fdb375644f1251cd278a4b1e7d7cd6",
|
|
1349
|
+
upgradeCap: "0x0f928a6b2e26b73330fecaf9b44acfc9800a4a9794d6415c2a3153bc70e3c1f0"
|
|
1102
1350
|
},
|
|
1103
1351
|
testCoin: { id: "", upgradeCap: "" }
|
|
1104
1352
|
}
|
|
1105
1353
|
},
|
|
1106
1354
|
spool: {
|
|
1107
|
-
id:
|
|
1108
|
-
|
|
1109
|
-
|
|
1355
|
+
// id: '0x7c4fdabe81c31b19a45d1e572a52a539997a90903fbb5bfab71480abe0fa62c3',
|
|
1356
|
+
id: "0x1742655fe5872dfa6456673f9e38612a4965e6979e6cd7696a7f1225f28bae21",
|
|
1357
|
+
adminCap: "0xdd8a047cbbf802bfcde5288b8ef1910965d789cc614da11d39af05fca0bd020a",
|
|
1358
|
+
// object:
|
|
1359
|
+
// '0xe87f1b2d498106a2c61421cec75b7b5c5e348512b0dc263949a0e7a3c256571a',
|
|
1360
|
+
object: "0x1742655fe5872dfa6456673f9e38612a4965e6979e6cd7696a7f1225f28bae21",
|
|
1110
1361
|
pools: {
|
|
1111
1362
|
seth: {
|
|
1112
|
-
id: "",
|
|
1113
|
-
rewardPoolId: ""
|
|
1363
|
+
id: "0xeec40beccb07c575bebd842eeaabb835f77cd3dab73add433477e57f583a6787",
|
|
1364
|
+
rewardPoolId: "0x957de68a18d87817de8309b30c1ec269a4d87ae513abbeed86b5619cb9ce1077"
|
|
1114
1365
|
},
|
|
1115
1366
|
ssui: {
|
|
1116
|
-
id:
|
|
1117
|
-
|
|
1367
|
+
// id: '0x4f0ba970d3c11db05c8f40c64a15b6a33322db3702d634ced6536960ab6f3ee4',
|
|
1368
|
+
id: "0xb9617f83c06ebdeac0a8834782b1015e1cc7ea23739e30c132c4bfb95c37a579",
|
|
1369
|
+
rewardPoolId: (
|
|
1370
|
+
// '0x162250ef72393a4ad3d46294c4e1bdfcb03f04c869d390e7efbfc995353a7ee9',
|
|
1371
|
+
"0xc3206071a8d43212efb6e3b5504f2321f8df97ab122b466c0bc7cfdf398dc13a"
|
|
1372
|
+
)
|
|
1118
1373
|
},
|
|
1119
1374
|
susdc: {
|
|
1120
|
-
id:
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
},
|
|
1127
|
-
|
|
1128
|
-
id:
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
},
|
|
1135
|
-
|
|
1136
|
-
id: "",
|
|
1137
|
-
rewardPoolId: ""
|
|
1138
|
-
},
|
|
1139
|
-
|
|
1140
|
-
id:
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
adminCap: "",
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
/**
|
|
1246
|
-
* Get addresses API id.
|
|
1247
|
-
*
|
|
1248
|
-
* @return The addresses API id.
|
|
1249
|
-
*/
|
|
1250
|
-
getId() {
|
|
1251
|
-
return this._id || void 0;
|
|
1252
|
-
}
|
|
1253
|
-
/**
|
|
1254
|
-
* Get the address at the provided path.
|
|
1255
|
-
*
|
|
1256
|
-
* @param path - The path of the address to get.
|
|
1257
|
-
* @return The address at the provided path.
|
|
1258
|
-
*/
|
|
1259
|
-
get(path) {
|
|
1260
|
-
if (this._currentAddresses) {
|
|
1261
|
-
const value = path.split(".").reduce(
|
|
1262
|
-
(nestedAddressObj, key) => typeof nestedAddressObj === "object" ? nestedAddressObj[key] : nestedAddressObj,
|
|
1263
|
-
this._currentAddresses
|
|
1264
|
-
);
|
|
1265
|
-
return value || void 0;
|
|
1266
|
-
} else {
|
|
1267
|
-
return void 0;
|
|
1268
|
-
}
|
|
1269
|
-
}
|
|
1270
|
-
/**
|
|
1271
|
-
* Sets the address for the specified path, it does not interact with the API.
|
|
1272
|
-
*
|
|
1273
|
-
* @param path - The path of the address to set.
|
|
1274
|
-
* @param address - The address be setted to the tartget path.
|
|
1275
|
-
* @return The addresses.
|
|
1276
|
-
*/
|
|
1277
|
-
set(path, address) {
|
|
1278
|
-
if (this._currentAddresses) {
|
|
1279
|
-
const keys = path.split(".");
|
|
1280
|
-
keys.reduce((nestedAddressObj, key, index) => {
|
|
1281
|
-
if (index === keys.length - 1) {
|
|
1282
|
-
nestedAddressObj[key] = address;
|
|
1283
|
-
} else {
|
|
1284
|
-
return nestedAddressObj[key];
|
|
1285
|
-
}
|
|
1286
|
-
}, this._currentAddresses);
|
|
1287
|
-
}
|
|
1288
|
-
return this._currentAddresses;
|
|
1289
|
-
}
|
|
1290
|
-
/**
|
|
1291
|
-
* Synchronize the specified network addresses from the addresses map to the
|
|
1292
|
-
* current addresses and change the default network to specified network.
|
|
1293
|
-
*
|
|
1294
|
-
* @param network - Specifies which network's addresses you want to get.
|
|
1295
|
-
* @return Current addresses.
|
|
1296
|
-
*/
|
|
1297
|
-
switchCurrentAddresses(network) {
|
|
1298
|
-
if (this._addressesMap.has(network)) {
|
|
1299
|
-
this._currentAddresses = this._addressesMap.get(network);
|
|
1300
|
-
this._network = network;
|
|
1301
|
-
}
|
|
1302
|
-
return this._currentAddresses;
|
|
1303
|
-
}
|
|
1304
|
-
/**
|
|
1305
|
-
* Get the addresses, If `network` is not provided, returns the current
|
|
1306
|
-
* addresses or the default network addresses in the addresses map.
|
|
1307
|
-
*
|
|
1308
|
-
* @param network - Specifies which network's addresses you want to get.
|
|
1309
|
-
*/
|
|
1310
|
-
getAddresses(network) {
|
|
1311
|
-
if (network) {
|
|
1312
|
-
return this._addressesMap.get(network);
|
|
1313
|
-
} else {
|
|
1314
|
-
return this._currentAddresses ?? this._addressesMap.get(this._network);
|
|
1315
|
-
}
|
|
1316
|
-
}
|
|
1317
|
-
/**
|
|
1318
|
-
* Set the addresses into addresses map. If the specified network is the same
|
|
1319
|
-
* as the current network, the current addresses will be updated at the same time.
|
|
1320
|
-
*
|
|
1321
|
-
* @param addresses - The addresses be setted to the tartget network.
|
|
1322
|
-
* @param network - Specifies which network's addresses you want to set.
|
|
1323
|
-
* @return The addresses.
|
|
1324
|
-
*/
|
|
1325
|
-
setAddresses(addresses, network) {
|
|
1326
|
-
const targetNetwork = network || this._network;
|
|
1327
|
-
if (targetNetwork === this._network)
|
|
1328
|
-
this._currentAddresses = addresses;
|
|
1329
|
-
this._addressesMap.set(targetNetwork, addresses);
|
|
1330
|
-
}
|
|
1331
|
-
/**
|
|
1332
|
-
* Get all addresses.
|
|
1333
|
-
*
|
|
1334
|
-
* @return All addresses.
|
|
1335
|
-
*/
|
|
1336
|
-
getAllAddresses() {
|
|
1337
|
-
return Object.fromEntries(this._addressesMap);
|
|
1338
|
-
}
|
|
1339
|
-
/**
|
|
1340
|
-
* Create a new addresses through the API and synchronize it back to the
|
|
1341
|
-
* instance.
|
|
1342
|
-
*
|
|
1343
|
-
* @description
|
|
1344
|
-
* If the `network` is not specified, the mainnet is used by default.
|
|
1345
|
-
* If no `addresses` from instance or parameter is provided, an addresses with
|
|
1346
|
-
* all empty strings is created by default.
|
|
1347
|
-
*
|
|
1348
|
-
* This function only allows for one addresses to be input into a specific network
|
|
1349
|
-
* at a time, and does not provide an addresses map for setting addresses
|
|
1350
|
-
* across all networks at once.
|
|
1351
|
-
*
|
|
1352
|
-
* @param params.addresses - The addresses be setted to the tartget network.
|
|
1353
|
-
* @param params.network - Specifies which network's addresses you want to set.
|
|
1354
|
-
* @param params.auth - The authentication API key.
|
|
1355
|
-
* @param params.memo - Add memo to the addresses created in the API.
|
|
1356
|
-
* @return All addresses.
|
|
1357
|
-
*/
|
|
1358
|
-
async create(params) {
|
|
1359
|
-
const { addresses, network, auth, memo } = params ?? {};
|
|
1360
|
-
const apiKey = auth || this._auth || void 0;
|
|
1361
|
-
const targetNetwork = network || this._network;
|
|
1362
|
-
const targetAddresses = addresses || this._currentAddresses || this._addressesMap.get(targetNetwork) || EMPTY_ADDRESSES;
|
|
1363
|
-
if (apiKey !== void 0) {
|
|
1364
|
-
this._addressesMap.clear();
|
|
1365
|
-
this.setAddresses(targetAddresses, targetNetwork);
|
|
1366
|
-
const response = await this._requestClient.post(
|
|
1367
|
-
`/addresses`,
|
|
1368
|
-
JSON.stringify({ ...Object.fromEntries(this._addressesMap), memo }),
|
|
1369
|
-
{
|
|
1370
|
-
headers: {
|
|
1371
|
-
"Content-Type": "application/json",
|
|
1372
|
-
"api-key": auth || this._auth
|
|
1373
|
-
}
|
|
1374
|
-
}
|
|
1375
|
-
);
|
|
1376
|
-
if (response.status === 201) {
|
|
1377
|
-
for (const [network2, addresses2] of Object.entries(
|
|
1378
|
-
response.data
|
|
1379
|
-
)) {
|
|
1380
|
-
if (["localnet", "devnet", "testnet", "mainnet"].includes(network2)) {
|
|
1381
|
-
if (network2 === this._network)
|
|
1382
|
-
this._currentAddresses = addresses2;
|
|
1383
|
-
this._addressesMap.set(network2, addresses2);
|
|
1384
|
-
}
|
|
1385
|
-
}
|
|
1386
|
-
this._id = response.data.id;
|
|
1387
|
-
return this.getAllAddresses();
|
|
1388
|
-
} else {
|
|
1389
|
-
throw Error("Failed to create addresses.");
|
|
1390
|
-
}
|
|
1391
|
-
} else {
|
|
1392
|
-
throw Error("You don't have permission to access this request.");
|
|
1393
|
-
}
|
|
1394
|
-
}
|
|
1395
|
-
/**
|
|
1396
|
-
* Read and synchronizes all addresses from the API into instance.
|
|
1397
|
-
*
|
|
1398
|
-
* @param id - The id of the addresses to get.
|
|
1399
|
-
* @return All addresses.
|
|
1400
|
-
*/
|
|
1401
|
-
async read(id) {
|
|
1402
|
-
const addressesId = id || this._id || void 0;
|
|
1403
|
-
if (addressesId !== void 0) {
|
|
1404
|
-
const response = await this._cache.queryClient.fetchQuery({
|
|
1405
|
-
queryKey: ["api-getAddresses", addressesId],
|
|
1406
|
-
queryFn: async () => {
|
|
1407
|
-
return await this._requestClient.get(`/addresses/${addressesId}`, {
|
|
1408
|
-
headers: {
|
|
1409
|
-
"Content-Type": "application/json"
|
|
1410
|
-
}
|
|
1411
|
-
});
|
|
1412
|
-
}
|
|
1413
|
-
});
|
|
1414
|
-
if (response.status === 200) {
|
|
1415
|
-
for (const [network, addresses] of Object.entries(
|
|
1416
|
-
response.data
|
|
1417
|
-
)) {
|
|
1418
|
-
if (["localnet", "devnet", "testnet", "mainnet"].includes(network)) {
|
|
1419
|
-
if (network === this._network)
|
|
1420
|
-
this._currentAddresses = addresses;
|
|
1421
|
-
this._addressesMap.set(network, addresses);
|
|
1422
|
-
}
|
|
1423
|
-
}
|
|
1424
|
-
this._id = response.data.id;
|
|
1425
|
-
return this.getAllAddresses();
|
|
1426
|
-
} else {
|
|
1427
|
-
throw Error("Failed to create addresses.");
|
|
1428
|
-
}
|
|
1429
|
-
} else {
|
|
1430
|
-
throw Error("Please provide API addresses id.");
|
|
1431
|
-
}
|
|
1432
|
-
}
|
|
1433
|
-
/**
|
|
1434
|
-
* Update the addresses through the API and synchronize it back to the
|
|
1435
|
-
* instance.
|
|
1436
|
-
*
|
|
1437
|
-
* @description
|
|
1438
|
-
* If the `network` is not specified, the mainnet is used by default.
|
|
1439
|
-
* If no `addresses` from instance or parameter is provided, an addresses with
|
|
1440
|
-
* all empty strings is created by default.
|
|
1441
|
-
*
|
|
1442
|
-
* This function only allows for one addresses to be input into a specific network
|
|
1443
|
-
* at a time, and does not provide an addresses map for setting addresses
|
|
1444
|
-
* across all networks at once.
|
|
1445
|
-
*
|
|
1446
|
-
* @param params.id - The id of the addresses to update.
|
|
1447
|
-
* @param params.addresses - The addresses be setted to the tartget network.
|
|
1448
|
-
* @param params.network - Specifies which network's addresses you want to set.
|
|
1449
|
-
* @param params.auth - The authentication api key.
|
|
1450
|
-
* @param params.memo - Add memo to the addresses created in the API.
|
|
1451
|
-
* @return All addresses.
|
|
1452
|
-
*/
|
|
1453
|
-
async update(params) {
|
|
1454
|
-
const { id, addresses, network, auth, memo } = params ?? {};
|
|
1455
|
-
const apiKey = auth || this._auth || void 0;
|
|
1456
|
-
const targetId = id || this._id || void 0;
|
|
1457
|
-
const targetNetwork = network || this._network;
|
|
1458
|
-
const targetAddresses = addresses || this._currentAddresses || this._addressesMap.get(targetNetwork) || EMPTY_ADDRESSES;
|
|
1459
|
-
if (targetId === void 0)
|
|
1460
|
-
throw Error("Require specific addresses id to be updated.");
|
|
1461
|
-
if (apiKey !== void 0) {
|
|
1462
|
-
if (id !== this._id) {
|
|
1463
|
-
this._addressesMap.clear();
|
|
1464
|
-
}
|
|
1465
|
-
this.setAddresses(targetAddresses, targetNetwork);
|
|
1466
|
-
const response = await this._requestClient.put(
|
|
1467
|
-
`/addresses/${targetId}`,
|
|
1468
|
-
JSON.stringify({ ...Object.fromEntries(this._addressesMap), memo }),
|
|
1469
|
-
{
|
|
1470
|
-
headers: {
|
|
1471
|
-
"Content-Type": "application/json",
|
|
1472
|
-
"api-key": auth || this._auth
|
|
1473
|
-
}
|
|
1474
|
-
}
|
|
1475
|
-
);
|
|
1476
|
-
if (response.status === 200) {
|
|
1477
|
-
for (const [network2, addresses2] of Object.entries(
|
|
1478
|
-
response.data
|
|
1479
|
-
)) {
|
|
1480
|
-
if (["localnet", "devnet", "testnet", "mainnet"].includes(network2)) {
|
|
1481
|
-
if (network2 === this._network)
|
|
1482
|
-
this._currentAddresses = addresses2;
|
|
1483
|
-
this._addressesMap.set(network2, addresses2);
|
|
1484
|
-
}
|
|
1485
|
-
}
|
|
1486
|
-
this._id = response.data.id;
|
|
1487
|
-
return this.getAllAddresses();
|
|
1488
|
-
} else {
|
|
1489
|
-
throw Error("Failed to update addresses.");
|
|
1490
|
-
}
|
|
1491
|
-
} else {
|
|
1492
|
-
throw Error("You don't have permission to access this request.");
|
|
1493
|
-
}
|
|
1494
|
-
}
|
|
1495
|
-
/**
|
|
1496
|
-
* Deletes all addresses of a specified id through the API and clear all
|
|
1497
|
-
* addresses in the instance.
|
|
1498
|
-
*
|
|
1499
|
-
* @param id - The id of the addresses to delete.
|
|
1500
|
-
* @param auth - The authentication API key.
|
|
1501
|
-
*/
|
|
1502
|
-
async delete(id, auth) {
|
|
1503
|
-
const apiKey = auth || this._auth || void 0;
|
|
1504
|
-
const targetId = id || this._id || void 0;
|
|
1505
|
-
if (targetId === void 0)
|
|
1506
|
-
throw Error("Require specific addresses id to be deleted.");
|
|
1507
|
-
if (apiKey !== void 0) {
|
|
1508
|
-
const response = await this._requestClient.delete(
|
|
1509
|
-
`/addresses/${targetId}`,
|
|
1510
|
-
{
|
|
1511
|
-
headers: {
|
|
1512
|
-
"Content-Type": "application/json",
|
|
1513
|
-
"api-key": auth || this._auth
|
|
1514
|
-
}
|
|
1515
|
-
}
|
|
1516
|
-
);
|
|
1517
|
-
if (response.status === 200) {
|
|
1518
|
-
this._id = void 0;
|
|
1519
|
-
this._currentAddresses = void 0;
|
|
1520
|
-
this._addressesMap.clear();
|
|
1521
|
-
} else {
|
|
1522
|
-
throw Error("Failed to delete addresses.");
|
|
1523
|
-
}
|
|
1524
|
-
} else {
|
|
1525
|
-
throw Error("You don't have permission to access this request.");
|
|
1526
|
-
}
|
|
1527
|
-
}
|
|
1528
|
-
};
|
|
1529
|
-
|
|
1530
|
-
// src/models/scallopClient.ts
|
|
1531
|
-
import { normalizeSuiAddress as normalizeSuiAddress4 } from "@mysten/sui.js/utils";
|
|
1532
|
-
import { SuiKit as SuiKit4 } from "@scallop-io/sui-kit";
|
|
1533
|
-
|
|
1534
|
-
// src/models/scallopUtils.ts
|
|
1535
|
-
import { SUI_TYPE_ARG, normalizeStructTag as normalizeStructTag6 } from "@mysten/sui.js/utils";
|
|
1536
|
-
import { SuiKit as SuiKit2 } from "@scallop-io/sui-kit";
|
|
1537
|
-
import { SuiPriceServiceConnection } from "@pythnetwork/pyth-sui-js";
|
|
1538
|
-
|
|
1539
|
-
// src/models/scallopQuery.ts
|
|
1540
|
-
import { SuiKit } from "@scallop-io/sui-kit";
|
|
1541
|
-
|
|
1542
|
-
// src/queries/coreQuery.ts
|
|
1543
|
-
import { normalizeStructTag as normalizeStructTag3 } from "@mysten/sui.js/utils";
|
|
1544
|
-
|
|
1545
|
-
// src/utils/builder.ts
|
|
1546
|
-
var requireSender = (txBlock) => {
|
|
1547
|
-
const sender = txBlock.blockData.sender;
|
|
1548
|
-
if (!sender) {
|
|
1549
|
-
throw new Error("Sender is required");
|
|
1550
|
-
}
|
|
1551
|
-
return sender;
|
|
1552
|
-
};
|
|
1553
|
-
var checkVesca = (prevUnlockAtInMillisTimestamp) => {
|
|
1554
|
-
if (prevUnlockAtInMillisTimestamp === void 0) {
|
|
1555
|
-
throw new Error("veSca not found");
|
|
1556
|
-
}
|
|
1557
|
-
};
|
|
1558
|
-
var checkVescaExpired = (prevUnlockAtInMillisTimestamp) => {
|
|
1559
|
-
if (prevUnlockAtInMillisTimestamp <= (/* @__PURE__ */ new Date()).getTime()) {
|
|
1560
|
-
throw new Error("veSca is expired, use renewExpiredVeScaQuick instead");
|
|
1561
|
-
}
|
|
1562
|
-
};
|
|
1563
|
-
var checkExtendLockPeriod = (lockPeriodInDays, newUnlockAtInSecondTimestamp, prevUnlockAtInMillisTimestamp) => {
|
|
1564
|
-
checkVesca(prevUnlockAtInMillisTimestamp);
|
|
1565
|
-
checkVescaExpired(prevUnlockAtInMillisTimestamp);
|
|
1566
|
-
const prevUnlockAtInSecondTimestamp = Math.floor(
|
|
1567
|
-
prevUnlockAtInMillisTimestamp / 1e3
|
|
1568
|
-
);
|
|
1569
|
-
if (lockPeriodInDays < 1) {
|
|
1570
|
-
throw new Error("Minimum lock period is 1 day");
|
|
1571
|
-
}
|
|
1572
|
-
const availableLockPeriodInDays = Math.floor(
|
|
1573
|
-
(newUnlockAtInSecondTimestamp - prevUnlockAtInSecondTimestamp) / UNLOCK_ROUND_DURATION
|
|
1574
|
-
);
|
|
1575
|
-
if (lockPeriodInDays > availableLockPeriodInDays) {
|
|
1576
|
-
throw new Error(
|
|
1577
|
-
`Cannot extend lock period by ${lockPeriodInDays} days, maximum lock period is ~4 years (${MAX_LOCK_ROUNDS} days), remaining lock period is ${MAX_LOCK_ROUNDS - availableLockPeriodInDays}`
|
|
1578
|
-
);
|
|
1579
|
-
}
|
|
1580
|
-
};
|
|
1581
|
-
var checkLockSca = (scaAmountOrCoin, lockPeriodInDays, newUnlockAtInSecondTimestamp, prevUnlockAtInMillisTimestamp) => {
|
|
1582
|
-
const prevUnlockAtInSecondTimestamp = prevUnlockAtInMillisTimestamp ? Math.floor(prevUnlockAtInMillisTimestamp / 1e3) : void 0;
|
|
1583
|
-
const isInitialLock = !prevUnlockAtInSecondTimestamp;
|
|
1584
|
-
const isLockExpired = !isInitialLock && prevUnlockAtInSecondTimestamp * 1e3 <= (/* @__PURE__ */ new Date()).getTime();
|
|
1585
|
-
if (isInitialLock || isLockExpired) {
|
|
1586
|
-
if (scaAmountOrCoin !== void 0 && lockPeriodInDays !== void 0) {
|
|
1587
|
-
if (lockPeriodInDays <= 0) {
|
|
1588
|
-
throw new Error("Lock period must be greater than 0");
|
|
1589
|
-
}
|
|
1590
|
-
if (typeof scaAmountOrCoin === "number" && scaAmountOrCoin < MIN_INITIAL_LOCK_AMOUNT) {
|
|
1591
|
-
throw new Error(
|
|
1592
|
-
`Minimum lock amount for ${isLockExpired ? "renewing expired veSca" : "initial lock"} is 10 SCA`
|
|
1593
|
-
);
|
|
1594
|
-
}
|
|
1595
|
-
const extendLockPeriodInSecond = lockPeriodInDays * UNLOCK_ROUND_DURATION;
|
|
1596
|
-
if (extendLockPeriodInSecond > MAX_LOCK_DURATION) {
|
|
1597
|
-
throw new Error(
|
|
1598
|
-
`Maximum lock period is ~4 years (${MAX_LOCK_ROUNDS} days)`
|
|
1599
|
-
);
|
|
1600
|
-
}
|
|
1601
|
-
} else {
|
|
1602
|
-
throw new Error(
|
|
1603
|
-
`SCA amount and lock period is required for ${isLockExpired ? "renewing expired veSca" : "initial lock"}`
|
|
1604
|
-
);
|
|
1605
|
-
}
|
|
1606
|
-
} else {
|
|
1607
|
-
checkVesca(prevUnlockAtInMillisTimestamp);
|
|
1608
|
-
checkVescaExpired(prevUnlockAtInMillisTimestamp);
|
|
1609
|
-
if (typeof scaAmountOrCoin === "number" && scaAmountOrCoin < MIN_TOP_UP_AMOUNT) {
|
|
1610
|
-
throw new Error("Minimum top up amount is 1 SCA");
|
|
1611
|
-
}
|
|
1612
|
-
if (newUnlockAtInSecondTimestamp && lockPeriodInDays) {
|
|
1613
|
-
checkExtendLockPeriod(
|
|
1614
|
-
lockPeriodInDays,
|
|
1615
|
-
newUnlockAtInSecondTimestamp,
|
|
1616
|
-
prevUnlockAtInMillisTimestamp
|
|
1617
|
-
);
|
|
1618
|
-
}
|
|
1619
|
-
}
|
|
1620
|
-
};
|
|
1621
|
-
var checkExtendLockAmount = (scaAmount, prevUnlockAtInMillisTimestamp) => {
|
|
1622
|
-
checkVesca(prevUnlockAtInMillisTimestamp);
|
|
1623
|
-
checkVescaExpired(prevUnlockAtInMillisTimestamp);
|
|
1624
|
-
if (scaAmount < MIN_TOP_UP_AMOUNT) {
|
|
1625
|
-
throw new Error("Minimum top up amount is 1 SCA");
|
|
1626
|
-
}
|
|
1627
|
-
const isInitialLock = !prevUnlockAtInMillisTimestamp;
|
|
1628
|
-
const isLockExpired = !isInitialLock && prevUnlockAtInMillisTimestamp <= (/* @__PURE__ */ new Date()).getTime();
|
|
1629
|
-
if (isLockExpired) {
|
|
1630
|
-
throw new Error("veSca is expired, use renewExpiredVeScaQuick instead");
|
|
1631
|
-
}
|
|
1632
|
-
};
|
|
1633
|
-
var checkRenewExpiredVeSca = (scaAmount, lockPeriodInDays, prevUnlockAtInMillisTimestamp) => {
|
|
1634
|
-
if (!prevUnlockAtInMillisTimestamp || prevUnlockAtInMillisTimestamp > (/* @__PURE__ */ new Date()).getTime()) {
|
|
1635
|
-
throw new Error("Renew method can only be used for expired veSca");
|
|
1636
|
-
}
|
|
1637
|
-
if (scaAmount < MIN_INITIAL_LOCK_AMOUNT) {
|
|
1638
|
-
throw new Error("Minimum lock amount for renewing expired vesca 10 SCA");
|
|
1639
|
-
}
|
|
1640
|
-
const extendLockPeriodInSecond = lockPeriodInDays * UNLOCK_ROUND_DURATION;
|
|
1641
|
-
if (extendLockPeriodInSecond >= MAX_LOCK_DURATION - UNLOCK_ROUND_DURATION) {
|
|
1642
|
-
throw new Error(
|
|
1643
|
-
`Maximum lock period is ~4 years (${MAX_LOCK_ROUNDS - 1} days)`
|
|
1644
|
-
);
|
|
1645
|
-
}
|
|
1646
|
-
};
|
|
1647
|
-
|
|
1648
|
-
// src/utils/query.ts
|
|
1649
|
-
import BigNumber from "bignumber.js";
|
|
1650
|
-
import { normalizeStructTag as normalizeStructTag2, parseStructTag } from "@mysten/sui.js/utils";
|
|
1651
|
-
var parseOriginMarketPoolData = (originMarketPoolData) => {
|
|
1652
|
-
return {
|
|
1653
|
-
coinType: normalizeStructTag2(originMarketPoolData.type.name),
|
|
1654
|
-
// Parse origin data required for basic calculations.
|
|
1655
|
-
maxBorrowRate: Number(originMarketPoolData.maxBorrowRate.value) / 2 ** 32,
|
|
1656
|
-
borrowRate: Number(originMarketPoolData.interestRate.value) / 2 ** 32,
|
|
1657
|
-
borrowRateScale: Number(originMarketPoolData.interestRateScale),
|
|
1658
|
-
borrowIndex: Number(originMarketPoolData.borrowIndex),
|
|
1659
|
-
lastUpdated: Number(originMarketPoolData.lastUpdated),
|
|
1660
|
-
cashAmount: Number(originMarketPoolData.cash),
|
|
1661
|
-
debtAmount: Number(originMarketPoolData.debt),
|
|
1662
|
-
marketCoinSupplyAmount: Number(originMarketPoolData.marketCoinSupply),
|
|
1663
|
-
reserveAmount: Number(originMarketPoolData.reserve),
|
|
1664
|
-
reserveFactor: Number(originMarketPoolData.reserveFactor.value) / 2 ** 32,
|
|
1665
|
-
borrowWeight: Number(originMarketPoolData.borrowWeight.value) / 2 ** 32,
|
|
1666
|
-
borrowFee: Number(originMarketPoolData.borrowFeeRate.value) / 2 ** 32,
|
|
1667
|
-
// Parse origin data required for additional display.
|
|
1668
|
-
baseBorrowRate: Number(originMarketPoolData.baseBorrowRatePerSec.value) / 2 ** 32,
|
|
1669
|
-
borrowRateOnHighKink: Number(originMarketPoolData.borrowRateOnHighKink.value) / 2 ** 32,
|
|
1670
|
-
borrowRateOnMidKink: Number(originMarketPoolData.borrowRateOnMidKink.value) / 2 ** 32,
|
|
1671
|
-
highKink: Number(originMarketPoolData.highKink.value) / 2 ** 32,
|
|
1672
|
-
midKink: Number(originMarketPoolData.midKink.value) / 2 ** 32,
|
|
1673
|
-
minBorrowAmount: Number(originMarketPoolData.minBorrowAmount)
|
|
1674
|
-
};
|
|
1675
|
-
};
|
|
1676
|
-
var calculateMarketPoolData = (utils, parsedMarketPoolData) => {
|
|
1677
|
-
const poolCoinName = utils.parseCoinNameFromType(
|
|
1678
|
-
parsedMarketPoolData.coinType
|
|
1679
|
-
);
|
|
1680
|
-
const coinDecimal = utils.getCoinDecimal(poolCoinName);
|
|
1681
|
-
const borrowYearFactor = 24 * 365 * 3600;
|
|
1682
|
-
const baseBorrowApr = parsedMarketPoolData.baseBorrowRate * borrowYearFactor / parsedMarketPoolData.borrowRateScale;
|
|
1683
|
-
const borrowAprOnHighKink = parsedMarketPoolData.borrowRateOnHighKink * borrowYearFactor / parsedMarketPoolData.borrowRateScale;
|
|
1684
|
-
const borrowAprOnMidKink = parsedMarketPoolData.borrowRateOnMidKink * borrowYearFactor / parsedMarketPoolData.borrowRateScale;
|
|
1685
|
-
const maxBorrowApr = parsedMarketPoolData.maxBorrowRate * borrowYearFactor / parsedMarketPoolData.borrowRateScale;
|
|
1686
|
-
const borrowApr = parsedMarketPoolData.borrowRate * borrowYearFactor / parsedMarketPoolData.borrowRateScale;
|
|
1687
|
-
const timeDelta = Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3) - parsedMarketPoolData.lastUpdated;
|
|
1688
|
-
const borrowIndexDelta = BigNumber(parsedMarketPoolData.borrowIndex).multipliedBy(
|
|
1689
|
-
BigNumber(timeDelta).multipliedBy(parsedMarketPoolData.borrowRate)
|
|
1690
|
-
).dividedBy(parsedMarketPoolData.borrowRateScale);
|
|
1691
|
-
const currentBorrowIndex = BigNumber(parsedMarketPoolData.borrowIndex).plus(
|
|
1692
|
-
borrowIndexDelta
|
|
1693
|
-
);
|
|
1694
|
-
const growthInterest = BigNumber(currentBorrowIndex).dividedBy(parsedMarketPoolData.borrowIndex).minus(1);
|
|
1695
|
-
const increasedDebtAmount = BigNumber(
|
|
1696
|
-
parsedMarketPoolData.debtAmount
|
|
1697
|
-
).multipliedBy(growthInterest);
|
|
1698
|
-
const borrowAmount = increasedDebtAmount.plus(
|
|
1699
|
-
parsedMarketPoolData.debtAmount
|
|
1700
|
-
);
|
|
1701
|
-
const borrowCoin = borrowAmount.shiftedBy(-1 * coinDecimal);
|
|
1702
|
-
const reserveAmount = BigNumber(parsedMarketPoolData.reserveAmount).plus(
|
|
1703
|
-
increasedDebtAmount.multipliedBy(parsedMarketPoolData.reserveFactor)
|
|
1704
|
-
);
|
|
1705
|
-
const reserveCoin = reserveAmount.shiftedBy(-1 * coinDecimal);
|
|
1706
|
-
const supplyAmount = BigNumber(borrowAmount).plus(
|
|
1707
|
-
Math.max(parsedMarketPoolData.cashAmount - reserveAmount.toNumber(), 0)
|
|
1708
|
-
);
|
|
1709
|
-
const supplyCoin = supplyAmount.shiftedBy(-1 * coinDecimal);
|
|
1710
|
-
let utilizationRate = BigNumber(borrowAmount).dividedBy(supplyAmount);
|
|
1711
|
-
utilizationRate = utilizationRate.isFinite() ? utilizationRate : BigNumber(0);
|
|
1712
|
-
let supplyApr = BigNumber(borrowApr).multipliedBy(utilizationRate).multipliedBy(1 - parsedMarketPoolData.reserveFactor);
|
|
1713
|
-
supplyApr = supplyApr.isFinite() ? supplyApr : BigNumber(0);
|
|
1714
|
-
let conversionRate = supplyAmount.dividedBy(
|
|
1715
|
-
parsedMarketPoolData.marketCoinSupplyAmount
|
|
1716
|
-
);
|
|
1717
|
-
conversionRate = conversionRate.isFinite() && !conversionRate.isNaN() ? conversionRate : BigNumber(1);
|
|
1718
|
-
return {
|
|
1719
|
-
baseBorrowApr,
|
|
1720
|
-
baseBorrowApy: utils.parseAprToApy(baseBorrowApr),
|
|
1721
|
-
borrowAprOnHighKink,
|
|
1722
|
-
borrowApyOnHighKink: utils.parseAprToApy(borrowAprOnHighKink),
|
|
1723
|
-
borrowAprOnMidKink,
|
|
1724
|
-
borrowApyOnMidKink: utils.parseAprToApy(borrowAprOnMidKink),
|
|
1725
|
-
maxBorrowApr,
|
|
1726
|
-
maxBorrowApy: utils.parseAprToApy(maxBorrowApr),
|
|
1727
|
-
borrowApr: Math.min(borrowApr, maxBorrowApr),
|
|
1728
|
-
borrowApy: Math.min(
|
|
1729
|
-
utils.parseAprToApy(borrowApr),
|
|
1730
|
-
utils.parseAprToApy(maxBorrowApr)
|
|
1731
|
-
),
|
|
1732
|
-
borrowIndex: currentBorrowIndex.toNumber(),
|
|
1733
|
-
growthInterest: growthInterest.toNumber(),
|
|
1734
|
-
supplyAmount: supplyAmount.toNumber(),
|
|
1735
|
-
supplyCoin: supplyCoin.toNumber(),
|
|
1736
|
-
borrowAmount: borrowAmount.toNumber(),
|
|
1737
|
-
borrowCoin: borrowCoin.toNumber(),
|
|
1738
|
-
reserveAmount: reserveAmount.toNumber(),
|
|
1739
|
-
reserveCoin: reserveCoin.toNumber(),
|
|
1740
|
-
utilizationRate: utilizationRate.toNumber(),
|
|
1741
|
-
supplyApr: supplyApr.toNumber(),
|
|
1742
|
-
supplyApy: utils.parseAprToApy(supplyApr.toNumber()),
|
|
1743
|
-
conversionRate: conversionRate.toNumber()
|
|
1744
|
-
};
|
|
1745
|
-
};
|
|
1746
|
-
var parseOriginMarketCollateralData = (originMarketCollateralData) => {
|
|
1747
|
-
const divisor = 2 ** 32;
|
|
1748
|
-
return {
|
|
1749
|
-
coinType: normalizeStructTag2(originMarketCollateralData.type.name),
|
|
1750
|
-
collateralFactor: Number(originMarketCollateralData.collateralFactor.value) / divisor,
|
|
1751
|
-
liquidationFactor: Number(originMarketCollateralData.liquidationFactor.value) / divisor,
|
|
1752
|
-
liquidationDiscount: Number(originMarketCollateralData.liquidationDiscount.value) / divisor,
|
|
1753
|
-
liquidationPanelty: Number(originMarketCollateralData.liquidationPanelty.value) / divisor,
|
|
1754
|
-
liquidationReserveFactor: Number(originMarketCollateralData.liquidationReserveFactor.value) / divisor,
|
|
1755
|
-
maxCollateralAmount: Number(originMarketCollateralData.maxCollateralAmount),
|
|
1756
|
-
totalCollateralAmount: Number(
|
|
1757
|
-
originMarketCollateralData.totalCollateralAmount
|
|
1758
|
-
)
|
|
1759
|
-
};
|
|
1760
|
-
};
|
|
1761
|
-
var calculateMarketCollateralData = (utils, parsedMarketCollateralData) => {
|
|
1762
|
-
const collateralCoinName = utils.parseCoinNameFromType(
|
|
1763
|
-
parsedMarketCollateralData.coinType
|
|
1764
|
-
);
|
|
1765
|
-
const coinDecimal = utils.getCoinDecimal(collateralCoinName);
|
|
1766
|
-
const maxCollateralCoin = BigNumber(
|
|
1767
|
-
parsedMarketCollateralData.maxCollateralAmount
|
|
1768
|
-
).shiftedBy(-1 * coinDecimal);
|
|
1769
|
-
const depositCoin = BigNumber(
|
|
1770
|
-
parsedMarketCollateralData.totalCollateralAmount
|
|
1771
|
-
).shiftedBy(-1 * coinDecimal);
|
|
1772
|
-
return {
|
|
1773
|
-
maxDepositAmount: parsedMarketCollateralData.maxCollateralAmount,
|
|
1774
|
-
maxDepositCoin: maxCollateralCoin.toNumber(),
|
|
1775
|
-
depositAmount: parsedMarketCollateralData.totalCollateralAmount,
|
|
1776
|
-
depositCoin: depositCoin.toNumber()
|
|
1777
|
-
};
|
|
1778
|
-
};
|
|
1779
|
-
var parseOriginSpoolData = (originSpoolData) => {
|
|
1780
|
-
return {
|
|
1781
|
-
stakeType: normalizeStructTag2(originSpoolData.stakeType.fields.name),
|
|
1782
|
-
maxPoint: Number(originSpoolData.maxDistributedPoint),
|
|
1783
|
-
distributedPoint: Number(originSpoolData.distributedPoint),
|
|
1784
|
-
pointPerPeriod: Number(originSpoolData.distributedPointPerPeriod),
|
|
1785
|
-
period: Number(originSpoolData.pointDistributionTime),
|
|
1786
|
-
maxStake: Number(originSpoolData.maxStake),
|
|
1787
|
-
staked: Number(originSpoolData.stakes),
|
|
1788
|
-
index: Number(originSpoolData.index),
|
|
1789
|
-
createdAt: Number(originSpoolData.createdAt),
|
|
1790
|
-
lastUpdate: Number(originSpoolData.lastUpdate)
|
|
1791
|
-
};
|
|
1792
|
-
};
|
|
1793
|
-
var calculateSpoolData = (parsedSpoolData, stakeMarketCoinPrice, stakeMarketCoinDecimal) => {
|
|
1794
|
-
const baseIndexRate = 1e9;
|
|
1795
|
-
const distributedPointPerSec = BigNumber(
|
|
1796
|
-
parsedSpoolData.pointPerPeriod
|
|
1797
|
-
).dividedBy(parsedSpoolData.period);
|
|
1798
|
-
const pointPerSec = BigNumber(parsedSpoolData.pointPerPeriod).dividedBy(
|
|
1799
|
-
parsedSpoolData.period
|
|
1800
|
-
);
|
|
1801
|
-
const remainingPeriod = pointPerSec.gt(0) ? BigNumber(parsedSpoolData.maxPoint).minus(parsedSpoolData.distributedPoint).dividedBy(pointPerSec) : BigNumber(0);
|
|
1802
|
-
const startDate = parsedSpoolData.createdAt;
|
|
1803
|
-
const endDate = remainingPeriod.plus(parsedSpoolData.lastUpdate).integerValue().toNumber();
|
|
1804
|
-
const timeDelta = BigNumber(
|
|
1805
|
-
Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3) - parsedSpoolData.lastUpdate
|
|
1806
|
-
).dividedBy(parsedSpoolData.period).toFixed(0);
|
|
1807
|
-
const remainingPoints = BigNumber(parsedSpoolData.maxPoint).minus(
|
|
1808
|
-
parsedSpoolData.distributedPoint
|
|
1809
|
-
);
|
|
1810
|
-
const accumulatedPoints = BigNumber.minimum(
|
|
1811
|
-
BigNumber(timeDelta).multipliedBy(parsedSpoolData.pointPerPeriod),
|
|
1812
|
-
remainingPoints
|
|
1813
|
-
);
|
|
1814
|
-
const currentPointIndex = BigNumber(parsedSpoolData.index).plus(
|
|
1815
|
-
accumulatedPoints.dividedBy(parsedSpoolData.staked).isFinite() ? BigNumber(baseIndexRate).multipliedBy(accumulatedPoints).dividedBy(parsedSpoolData.staked) : 0
|
|
1816
|
-
);
|
|
1817
|
-
const currentTotalDistributedPoint = BigNumber(
|
|
1818
|
-
parsedSpoolData.distributedPoint
|
|
1819
|
-
).plus(accumulatedPoints);
|
|
1820
|
-
const stakedAmount = BigNumber(parsedSpoolData.staked);
|
|
1821
|
-
const stakedCoin = stakedAmount.shiftedBy(-1 * stakeMarketCoinDecimal);
|
|
1822
|
-
const stakedValue = stakedCoin.multipliedBy(stakeMarketCoinPrice);
|
|
1823
|
-
return {
|
|
1824
|
-
distributedPointPerSec: distributedPointPerSec.toNumber(),
|
|
1825
|
-
accumulatedPoints: accumulatedPoints.toNumber(),
|
|
1826
|
-
currentPointIndex: currentPointIndex.toNumber(),
|
|
1827
|
-
currentTotalDistributedPoint: currentTotalDistributedPoint.toNumber(),
|
|
1828
|
-
startDate: new Date(startDate * 1e3),
|
|
1829
|
-
endDate: new Date(endDate * 1e3),
|
|
1830
|
-
stakedAmount: stakedAmount.toNumber(),
|
|
1831
|
-
stakedCoin: stakedCoin.toNumber(),
|
|
1832
|
-
stakedValue: stakedValue.toNumber()
|
|
1833
|
-
};
|
|
1834
|
-
};
|
|
1835
|
-
var parseOriginSpoolRewardPoolData = (originSpoolRewardPoolData) => {
|
|
1836
|
-
return {
|
|
1837
|
-
claimedRewards: Number(originSpoolRewardPoolData.claimed_rewards),
|
|
1838
|
-
exchangeRateDenominator: Number(
|
|
1839
|
-
originSpoolRewardPoolData.exchange_rate_denominator
|
|
1840
|
-
),
|
|
1841
|
-
exchangeRateNumerator: Number(
|
|
1842
|
-
originSpoolRewardPoolData.exchange_rate_numerator
|
|
1843
|
-
),
|
|
1844
|
-
rewards: Number(originSpoolRewardPoolData.rewards),
|
|
1845
|
-
spoolId: String(originSpoolRewardPoolData.spool_id)
|
|
1846
|
-
};
|
|
1847
|
-
};
|
|
1848
|
-
var calculateSpoolRewardPoolData = (parsedSpoolData, parsedSpoolRewardPoolData, calculatedSpoolData, rewardCoinPrice, rewardCoinDecimal) => {
|
|
1849
|
-
const rateYearFactor = 365 * 24 * 60 * 60;
|
|
1850
|
-
const rewardPerSec = BigNumber(calculatedSpoolData.distributedPointPerSec).multipliedBy(parsedSpoolRewardPoolData.exchangeRateNumerator).dividedBy(parsedSpoolRewardPoolData.exchangeRateDenominator);
|
|
1851
|
-
const totalRewardAmount = BigNumber(parsedSpoolData.maxPoint).multipliedBy(parsedSpoolRewardPoolData.exchangeRateNumerator).dividedBy(parsedSpoolRewardPoolData.exchangeRateDenominator);
|
|
1852
|
-
const totalRewardCoin = totalRewardAmount.shiftedBy(-1 * rewardCoinDecimal);
|
|
1853
|
-
const totalRewardValue = totalRewardCoin.multipliedBy(rewardCoinPrice);
|
|
1854
|
-
const remaindRewardAmount = BigNumber(parsedSpoolRewardPoolData.rewards);
|
|
1855
|
-
const remaindRewardCoin = remaindRewardAmount.shiftedBy(
|
|
1856
|
-
-1 * rewardCoinDecimal
|
|
1857
|
-
);
|
|
1858
|
-
const remaindRewardValue = remaindRewardCoin.multipliedBy(rewardCoinPrice);
|
|
1859
|
-
const claimedRewardAmount = BigNumber(
|
|
1860
|
-
parsedSpoolRewardPoolData.claimedRewards
|
|
1861
|
-
);
|
|
1862
|
-
const claimedRewardCoin = claimedRewardAmount.shiftedBy(
|
|
1863
|
-
-1 * rewardCoinDecimal
|
|
1864
|
-
);
|
|
1865
|
-
const claimedRewardValue = claimedRewardCoin.multipliedBy(rewardCoinPrice);
|
|
1866
|
-
const rewardValueForYear = BigNumber(rewardPerSec).shiftedBy(-1 * rewardCoinDecimal).multipliedBy(rateYearFactor).multipliedBy(rewardCoinPrice);
|
|
1867
|
-
let rewardRate = rewardValueForYear.dividedBy(calculatedSpoolData.stakedValue).isFinite() ? rewardValueForYear.dividedBy(calculatedSpoolData.stakedValue).toNumber() : Infinity;
|
|
1868
|
-
if (parsedSpoolData.maxPoint <= parsedSpoolData.distributedPoint || parsedSpoolData.pointPerPeriod === 0) {
|
|
1869
|
-
rewardRate = Infinity;
|
|
1375
|
+
// id: '0x4ace6648ddc64e646ba47a957c562c32c9599b3bba8f5ac1aadb2ae23a2f8ca0',
|
|
1376
|
+
id: "0xf1b383b9cf2e9f515fc69567df1053098f273849d09cd84b0278a773429bd2b2",
|
|
1377
|
+
rewardPoolId: (
|
|
1378
|
+
// '0xf4268cc9b9413b9bfe09e8966b8de650494c9e5784bf0930759cfef4904daff8',
|
|
1379
|
+
"0xc71c53ee6505d928ba15bea4fe4f45d98c9c31eced94b72d00a7827d4b7ba3ff"
|
|
1380
|
+
)
|
|
1381
|
+
},
|
|
1382
|
+
susdt: {
|
|
1383
|
+
// id: '0xcb328f7ffa7f9342ed85af3fdb2f22919e1a06dfb2f713c04c73543870d7548f',
|
|
1384
|
+
id: "0xb5567dfa5c7fc17a249e959732664c50713dd8c23db1a11376b27df800c17418",
|
|
1385
|
+
rewardPoolId: (
|
|
1386
|
+
// '0x2c9f934d67a5baa586ceec2cc24163a2f049a6af3d5ba36b84d8ac40f25c4080',
|
|
1387
|
+
"0x60768b0687ff0235e376a039709a683e4c436098785e473b67b32dbab47b69ab"
|
|
1388
|
+
)
|
|
1389
|
+
},
|
|
1390
|
+
scetus: {
|
|
1391
|
+
id: "0xac1bb13bf4472a637c18c2415fb0e3c1227ea2bcf35242e50563c98215bd298e",
|
|
1392
|
+
rewardPoolId: "0x6835c1224126a45086fc6406adc249e3f30df18d779ca4f4e570e38716a17f3f"
|
|
1393
|
+
},
|
|
1394
|
+
safsui: {
|
|
1395
|
+
// id: '0xeedf438abcaa6ce4d9625ffca110920592d5867e4c5637d84ad9f466c4feb800',
|
|
1396
|
+
id: "0xc568bb4c991258e839aa54802ecda04fcd9838c826bc3b42b40af81b23c458c8",
|
|
1397
|
+
rewardPoolId: (
|
|
1398
|
+
// '0x89255a2f86ed7fbfef35ab8b7be48cc7667015975be2685dd9a55a9a64baf76e',
|
|
1399
|
+
"0x389a3cbeda742b918941bb24fd00e077bad3367484394d6234f8209b9a6aa03d"
|
|
1400
|
+
)
|
|
1401
|
+
},
|
|
1402
|
+
shasui: {
|
|
1403
|
+
// id: '0xa6148bc1b623e936d39a952ceb5bea79e8b37228a8f595067bf1852efd3c34aa',
|
|
1404
|
+
id: "0x93f3f4499bf89f2d05ddc1f8b15f51701a7c6c4d0ac0b9c3bc99462cbbd8e321",
|
|
1405
|
+
rewardPoolId: (
|
|
1406
|
+
// '0x6f3563644d3e2ef13176dbf9d865bd93479df60ccbe07b7e66db57f6309f5a66',
|
|
1407
|
+
"0x94cee1be7f5ff34193f3aabef0b14142cb28af4d905fe487a9a7d85a15edb6aa"
|
|
1408
|
+
)
|
|
1409
|
+
},
|
|
1410
|
+
svsui: {
|
|
1411
|
+
// id: '0x69ce8e537e750a95381e6040794afa5ab1758353a1a2e1de7760391b01f91670',
|
|
1412
|
+
id: "0xa970e9087f80cb59e9299b8e7af7175d977ad6c9af0322aa4440e138fbd7ae00",
|
|
1413
|
+
rewardPoolId: (
|
|
1414
|
+
// '0xbca914adce058ad0902c7f3cfcd698392a475f00dcfdc3f76001d0370b98777a',
|
|
1415
|
+
"0x38eee9699c4fc132a6623e54b865f047df4fc6eb83af807300f44e8f4b235ff0"
|
|
1416
|
+
)
|
|
1417
|
+
}
|
|
1418
|
+
},
|
|
1419
|
+
config: ""
|
|
1420
|
+
},
|
|
1421
|
+
borrowIncentive: {
|
|
1422
|
+
id: "0x6152f696fc3a658f33c4b891764731a59153125ffedfa8bff7167c42823f58a9",
|
|
1423
|
+
adminCap: "0xc486afa253646f4d381e81d7f1df8aa4723b845a6bb356f69bad635ffefffe2c",
|
|
1424
|
+
object: "0x002875153e09f8145ab63527bc85c00f2bd102e12f9573c47f8cdf1a1cb62934",
|
|
1425
|
+
query: "0x529edc54a3dce2207703ceebbccb0ac14133f7825c1f528775ba0d85a4063489",
|
|
1426
|
+
incentivePools: "0x6547e143d406b5ccd5f46aae482497de279cc1a68c406f701df70a05f9212ab4",
|
|
1427
|
+
incentiveAccounts: "0xc4701fdbc1c92f9a636d334d66012b3027659e9fb8aff27279a82edfb6b77d02",
|
|
1428
|
+
config: "0xdf5d04b4691cc67e82fd4db8394d89ff44823a9de29716c924f74bb4f11cc1f7"
|
|
1429
|
+
},
|
|
1430
|
+
referral: {
|
|
1431
|
+
id: "0xa3654ebb63eb06c0f4ff52f8aa6512df9f164f7772bdf15dac3709bd3798dda9",
|
|
1432
|
+
object: "0x5658d4bf5ddcba27e4337b4262108b3ad1716643cac8c2054ac341538adc72ec",
|
|
1433
|
+
adminCap: "0xc5dc06b9074291259f2cac460c940012c781c4430e42125c541cc43101c3bcbd",
|
|
1434
|
+
referralBindings: "0xf63299d58789d99de94092b9011323466e55ca0c1ea1a7a3786a589af46e1c09",
|
|
1435
|
+
bindingTableId: "0x1c8202b17267ec8d6cf97ca013615354181a04f179570e42601ff2dae19294b1",
|
|
1436
|
+
referralRevenuePool: "0x6abd852caf90769c1b185cdf636d841673fa95528f0550f018b8a138bd283c07",
|
|
1437
|
+
revenueTableId: "0x595baa3654c297bff84ab7786a2d250f019cefc66e8df8e89fd9d41e02bd30dd",
|
|
1438
|
+
referralTiers: "0x962cb903d8d7346190c5204785ccbb91b61086aa764f674c8145df82335cf83e",
|
|
1439
|
+
tiersTableId: "0xeac755a7a8b7798530905ac79e8c114f19d0f130f6eab012954f08faac29c75d",
|
|
1440
|
+
// authorizedWitnessList:
|
|
1441
|
+
// '0xf21b0ed043c9bb70842c0129159f4943dbcc3c9ef2f2f808af65f8be25cfd20e',
|
|
1442
|
+
authorizedWitnessList: "0x9d6223dc52015b8a3986a573590ef2af8f1b8f3e4685513888c052f001b87e7f",
|
|
1443
|
+
version: "0x1bd4b7285f72e11c316b828c7c47b3f4da18dcec9f9b3dba6d8629cbb6f93e5e"
|
|
1444
|
+
},
|
|
1445
|
+
vesca: {
|
|
1446
|
+
id: "0xb15b6e0cdd85afb5028bea851dd249405e734d800a259147bbc24980629723a4",
|
|
1447
|
+
object: "0xb15b6e0cdd85afb5028bea851dd249405e734d800a259147bbc24980629723a4",
|
|
1448
|
+
adminCap: "0x8ffa76135c5b85c5fbd73a6448a4a733d826cb63a267ab817656acb77c72d4a5",
|
|
1449
|
+
tableId: "0xe3153b2bf124be0b86cb8bd468346a861efd0da52fc42197b54d2f616488a311",
|
|
1450
|
+
table: "0x611cb8d9d4d90867467b5ebdf4cc447a0047ed5b01334a28a29fcfe733e3d609",
|
|
1451
|
+
treasury: "0xe8c112c09b88158dc6c8e23d1fbae5b3c7136cdee54b7dafc08e65db28c4a5bc",
|
|
1452
|
+
config: "0xe0a2ff281e73c1d53cfa85807080f87e833e4f1a7f93dcf8800b3865269a76b9"
|
|
1453
|
+
},
|
|
1454
|
+
loyaltyProgram: {
|
|
1455
|
+
id: "0xd17bcf8b5a59652c36225d478564a8593ae0ed7d650bcacdda1d6fe179127907",
|
|
1456
|
+
object: "0xd17bcf8b5a59652c36225d478564a8593ae0ed7d650bcacdda1d6fe179127907",
|
|
1457
|
+
rewardPool: "0xf9c090492ef476bd542109d0913ffe871cbfa28578b7114eca2a8c0e5671786f",
|
|
1458
|
+
userRewardTableId: "0x748a80395849ed37db1b0e14f2ab5d1d96458d2359ab3a84eb079d0f4ac7cf2e"
|
|
1459
|
+
},
|
|
1460
|
+
scoin: {
|
|
1461
|
+
id: "0xad2ca2aa5089df94bb2d444d5eb3520378c2f2dfb3a0bd2a2c994145ac4b0a53",
|
|
1462
|
+
coins: {
|
|
1463
|
+
ssui: {
|
|
1464
|
+
coinType: "0xfac769100bccc0caebcf4f4e2d00ac2f8883f07f724be28940df90605f5e7e9a::scallop_sui::SCALLOP_SUI",
|
|
1465
|
+
treasury: "0x9cb4551b36c17d37e19d700147fa819ea1c487ff8bcf18374de2cceb2e9d4845"
|
|
1466
|
+
},
|
|
1467
|
+
scetus: {
|
|
1468
|
+
coinType: "0x8b71e6d323ed78515af2bead13bf3d0da1562ba4a99234eb7c4f14fd39ef0427::scallop_cetus::SCALLOP_CETUS",
|
|
1469
|
+
treasury: "0xd786f4b2d26278cc7911a3445b1b085eab60f269ef9dbb6b87e803d52f155003"
|
|
1470
|
+
},
|
|
1471
|
+
ssca: {
|
|
1472
|
+
coinType: "0x0a9d3c6c9af9f6e8def82921541bcbd17f73ed31bed3adcb684f2a4c267e42f0::scallop_sca::SCALLOP_SCA",
|
|
1473
|
+
treasury: "0xe818636d1d6c46d6ea1a2dce9d94696d7cbc18ce27451b603eeaa47aba8d75e0"
|
|
1474
|
+
},
|
|
1475
|
+
susdc: {
|
|
1476
|
+
coinType: "0xaedc3ab75db8680b81a755015fa90124d217be93457b893c05bac033817defaf::scallop_wormhole_usdc::SCALLOP_WORMHOLE_USDC",
|
|
1477
|
+
treasury: "0xfc6971648f867f7fd6928d1b873af71577e2eaf2c7543ef8bc82c431d833ae78"
|
|
1478
|
+
},
|
|
1479
|
+
susdt: {
|
|
1480
|
+
coinType: "0xbf02fc87ddc104b342ad8414c85ceadf5b0c823c055a06fb0ed776272c01a52a::scallop_wormhole_usdt::SCALLOP_WORMHOLE_USDT",
|
|
1481
|
+
treasury: "0xb9593e2c3a0ba796ee815012b75ae46468ea78cda0188b9ac6816efe65503521"
|
|
1482
|
+
},
|
|
1483
|
+
seth: {
|
|
1484
|
+
coinType: "0x27d54f43e3eda701be56b82e5756e41c84467cd202f5cf713d5f9e45a9f1b6bc::scallop_wormhole_eth::SCALLOP_WORMHOLE_ETH",
|
|
1485
|
+
treasury: "0x032b4c8fac94c038dbe986f7587e9b1e4ef580b5ee06d2ef249d85459b7ef05d"
|
|
1486
|
+
},
|
|
1487
|
+
safsui: {
|
|
1488
|
+
coinType: "0xb75b46d975d8d80670b53a6bee90baaa8ce2e0b7d397f079447d641eef6b44ad::scallop_af_sui::SCALLOP_AF_SUI",
|
|
1489
|
+
treasury: "0x21450ef0570ef3d224ffa3b873ab802e439ece7b93cc7efad10ae0c1e3b3fcfe"
|
|
1490
|
+
},
|
|
1491
|
+
shasui: {
|
|
1492
|
+
coinType: "0xd973a723874e2c7cde196602a79155a1343a933f8cf87d9b1bb7408bc1acbc58::scallop_ha_sui::SCALLOP_HA_SUI",
|
|
1493
|
+
treasury: "0xf822fc1402207e47d2e3ba8ff6e1e594bf1de777dc5ebd2744619cd2726e3b0d"
|
|
1494
|
+
},
|
|
1495
|
+
svsui: {
|
|
1496
|
+
coinType: "0x97023a317320c4498cc4cd239dd02fd30c28246e5e8f81325d63f2bd8d70f6b3::scallop_v_sui::SCALLOP_V_SUI",
|
|
1497
|
+
treasury: "0x327114f0bf3559d7e2de10282147ed76a236c7c6775029165c4db09a6062ead6\u0192"
|
|
1498
|
+
}
|
|
1499
|
+
}
|
|
1870
1500
|
}
|
|
1871
|
-
return {
|
|
1872
|
-
rewardApr: rewardRate,
|
|
1873
|
-
totalRewardAmount: totalRewardAmount.toNumber(),
|
|
1874
|
-
totalRewardCoin: totalRewardCoin.toNumber(),
|
|
1875
|
-
totalRewardValue: totalRewardValue.toNumber(),
|
|
1876
|
-
remaindRewardAmount: remaindRewardAmount.toNumber(),
|
|
1877
|
-
remaindRewardCoin: remaindRewardCoin.toNumber(),
|
|
1878
|
-
remaindRewardValue: remaindRewardValue.toNumber(),
|
|
1879
|
-
claimedRewardAmount: claimedRewardAmount.toNumber(),
|
|
1880
|
-
claimedRewardCoin: claimedRewardCoin.toNumber(),
|
|
1881
|
-
claimedRewardValue: claimedRewardValue.toNumber(),
|
|
1882
|
-
rewardPerSec: rewardPerSec.toNumber()
|
|
1883
|
-
};
|
|
1884
|
-
};
|
|
1885
|
-
var parseOriginBorrowIncentivesPoolPointData = (originBorrowIncentivePoolPointData) => {
|
|
1886
|
-
return {
|
|
1887
|
-
pointType: normalizeStructTag2(
|
|
1888
|
-
originBorrowIncentivePoolPointData.point_type.name
|
|
1889
|
-
),
|
|
1890
|
-
distributedPointPerPeriod: Number(
|
|
1891
|
-
originBorrowIncentivePoolPointData.distributed_point_per_period
|
|
1892
|
-
),
|
|
1893
|
-
period: Number(originBorrowIncentivePoolPointData.point_distribution_time),
|
|
1894
|
-
distributedPoint: Number(
|
|
1895
|
-
originBorrowIncentivePoolPointData.distributed_point
|
|
1896
|
-
),
|
|
1897
|
-
points: Number(originBorrowIncentivePoolPointData.points),
|
|
1898
|
-
index: Number(originBorrowIncentivePoolPointData.index),
|
|
1899
|
-
baseWeight: Number(originBorrowIncentivePoolPointData.base_weight),
|
|
1900
|
-
weightedAmount: Number(originBorrowIncentivePoolPointData.weighted_amount),
|
|
1901
|
-
lastUpdate: Number(originBorrowIncentivePoolPointData.last_update)
|
|
1902
|
-
};
|
|
1903
1501
|
};
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1502
|
+
|
|
1503
|
+
// src/models/scallopAddress.ts
|
|
1504
|
+
var EMPTY_ADDRESSES = {
|
|
1505
|
+
core: {
|
|
1506
|
+
version: "",
|
|
1507
|
+
versionCap: "",
|
|
1508
|
+
object: "",
|
|
1509
|
+
market: "",
|
|
1510
|
+
adminCap: "",
|
|
1511
|
+
coinDecimalsRegistry: "",
|
|
1512
|
+
obligationAccessStore: "",
|
|
1513
|
+
coins: {
|
|
1514
|
+
cetus: {
|
|
1515
|
+
id: "",
|
|
1516
|
+
metaData: "",
|
|
1517
|
+
treasury: "",
|
|
1518
|
+
oracle: {
|
|
1519
|
+
supra: "",
|
|
1520
|
+
switchboard: "",
|
|
1521
|
+
pyth: {
|
|
1522
|
+
feed: "",
|
|
1523
|
+
feedObject: ""
|
|
1524
|
+
}
|
|
1525
|
+
}
|
|
1526
|
+
},
|
|
1527
|
+
apt: {
|
|
1528
|
+
id: "",
|
|
1529
|
+
metaData: "",
|
|
1530
|
+
treasury: "",
|
|
1531
|
+
oracle: {
|
|
1532
|
+
supra: "",
|
|
1533
|
+
switchboard: "",
|
|
1534
|
+
pyth: {
|
|
1535
|
+
feed: "",
|
|
1536
|
+
feedObject: ""
|
|
1537
|
+
}
|
|
1538
|
+
}
|
|
1539
|
+
},
|
|
1540
|
+
sol: {
|
|
1541
|
+
id: "",
|
|
1542
|
+
metaData: "",
|
|
1543
|
+
treasury: "",
|
|
1544
|
+
oracle: {
|
|
1545
|
+
supra: "",
|
|
1546
|
+
switchboard: "",
|
|
1547
|
+
pyth: {
|
|
1548
|
+
feed: "",
|
|
1549
|
+
feedObject: ""
|
|
1550
|
+
}
|
|
1551
|
+
}
|
|
1552
|
+
},
|
|
1553
|
+
btc: {
|
|
1554
|
+
id: "",
|
|
1555
|
+
metaData: "",
|
|
1556
|
+
treasury: "",
|
|
1557
|
+
oracle: {
|
|
1558
|
+
supra: "",
|
|
1559
|
+
switchboard: "",
|
|
1560
|
+
pyth: {
|
|
1561
|
+
feed: "",
|
|
1562
|
+
feedObject: ""
|
|
1563
|
+
}
|
|
1564
|
+
}
|
|
1565
|
+
},
|
|
1566
|
+
eth: {
|
|
1567
|
+
id: "",
|
|
1568
|
+
metaData: "",
|
|
1569
|
+
treasury: "",
|
|
1570
|
+
oracle: {
|
|
1571
|
+
supra: "",
|
|
1572
|
+
switchboard: "",
|
|
1573
|
+
pyth: {
|
|
1574
|
+
feed: "",
|
|
1575
|
+
feedObject: ""
|
|
1576
|
+
}
|
|
1577
|
+
}
|
|
1578
|
+
},
|
|
1579
|
+
usdc: {
|
|
1580
|
+
id: "",
|
|
1581
|
+
metaData: "",
|
|
1582
|
+
treasury: "",
|
|
1583
|
+
oracle: {
|
|
1584
|
+
supra: "",
|
|
1585
|
+
switchboard: "",
|
|
1586
|
+
pyth: {
|
|
1587
|
+
feed: "",
|
|
1588
|
+
feedObject: ""
|
|
1589
|
+
}
|
|
1590
|
+
}
|
|
1591
|
+
},
|
|
1592
|
+
usdt: {
|
|
1593
|
+
id: "",
|
|
1594
|
+
metaData: "",
|
|
1595
|
+
treasury: "",
|
|
1596
|
+
oracle: {
|
|
1597
|
+
supra: "",
|
|
1598
|
+
switchboard: "",
|
|
1599
|
+
pyth: {
|
|
1600
|
+
feed: "",
|
|
1601
|
+
feedObject: ""
|
|
1602
|
+
}
|
|
1603
|
+
}
|
|
1919
1604
|
},
|
|
1920
|
-
{
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
1605
|
+
sui: {
|
|
1606
|
+
id: "",
|
|
1607
|
+
metaData: "",
|
|
1608
|
+
treasury: "",
|
|
1609
|
+
oracle: {
|
|
1610
|
+
supra: "",
|
|
1611
|
+
switchboard: "",
|
|
1612
|
+
pyth: {
|
|
1613
|
+
feed: "",
|
|
1614
|
+
feedObject: ""
|
|
1615
|
+
}
|
|
1616
|
+
}
|
|
1617
|
+
},
|
|
1618
|
+
afsui: {
|
|
1619
|
+
id: "",
|
|
1620
|
+
metaData: "",
|
|
1621
|
+
treasury: "",
|
|
1622
|
+
oracle: {
|
|
1623
|
+
supra: "",
|
|
1624
|
+
switchboard: "",
|
|
1625
|
+
pyth: {
|
|
1626
|
+
feed: "",
|
|
1627
|
+
feedObject: ""
|
|
1628
|
+
}
|
|
1629
|
+
}
|
|
1630
|
+
},
|
|
1631
|
+
hasui: {
|
|
1632
|
+
id: "",
|
|
1633
|
+
metaData: "",
|
|
1634
|
+
treasury: "",
|
|
1635
|
+
oracle: {
|
|
1636
|
+
supra: "",
|
|
1637
|
+
switchboard: "",
|
|
1638
|
+
pyth: {
|
|
1639
|
+
feed: "",
|
|
1640
|
+
feedObject: ""
|
|
1641
|
+
}
|
|
1642
|
+
}
|
|
1643
|
+
},
|
|
1644
|
+
vsui: {
|
|
1645
|
+
id: "",
|
|
1646
|
+
metaData: "",
|
|
1647
|
+
treasury: "",
|
|
1648
|
+
oracle: {
|
|
1649
|
+
supra: "",
|
|
1650
|
+
switchboard: "",
|
|
1651
|
+
pyth: {
|
|
1652
|
+
feed: "",
|
|
1653
|
+
feedObject: ""
|
|
1654
|
+
}
|
|
1655
|
+
}
|
|
1656
|
+
},
|
|
1657
|
+
sca: {
|
|
1658
|
+
id: "",
|
|
1659
|
+
metaData: "",
|
|
1660
|
+
treasury: "",
|
|
1661
|
+
oracle: {
|
|
1662
|
+
supra: "",
|
|
1663
|
+
switchboard: "",
|
|
1664
|
+
pyth: {
|
|
1665
|
+
feed: "",
|
|
1666
|
+
feedObject: ""
|
|
1667
|
+
}
|
|
1668
|
+
}
|
|
1669
|
+
}
|
|
1670
|
+
},
|
|
1671
|
+
oracles: {
|
|
1672
|
+
xOracle: "",
|
|
1673
|
+
xOracleCap: "",
|
|
1674
|
+
supra: { registry: "", registryCap: "", holder: "" },
|
|
1675
|
+
switchboard: { registry: "", registryCap: "" },
|
|
1676
|
+
pyth: {
|
|
1677
|
+
registry: "",
|
|
1678
|
+
registryCap: "",
|
|
1679
|
+
state: "",
|
|
1680
|
+
wormhole: "",
|
|
1681
|
+
wormholeState: ""
|
|
1682
|
+
}
|
|
1683
|
+
},
|
|
1684
|
+
packages: {
|
|
1685
|
+
coinDecimalsRegistry: {
|
|
1686
|
+
id: "",
|
|
1687
|
+
upgradeCap: ""
|
|
1688
|
+
},
|
|
1689
|
+
math: {
|
|
1690
|
+
id: "",
|
|
1691
|
+
upgradeCap: ""
|
|
1692
|
+
},
|
|
1693
|
+
whitelist: {
|
|
1694
|
+
id: "",
|
|
1695
|
+
upgradeCap: ""
|
|
1696
|
+
},
|
|
1697
|
+
x: {
|
|
1698
|
+
id: "",
|
|
1699
|
+
upgradeCap: ""
|
|
1700
|
+
},
|
|
1701
|
+
protocol: {
|
|
1702
|
+
id: "",
|
|
1703
|
+
upgradeCap: ""
|
|
1704
|
+
},
|
|
1705
|
+
protocolWhitelist: {
|
|
1706
|
+
id: "",
|
|
1707
|
+
upgradeCap: ""
|
|
1708
|
+
},
|
|
1709
|
+
query: {
|
|
1710
|
+
id: "",
|
|
1711
|
+
upgradeCap: ""
|
|
1712
|
+
},
|
|
1713
|
+
supra: { id: "", upgradeCap: "" },
|
|
1714
|
+
pyth: {
|
|
1715
|
+
id: "",
|
|
1716
|
+
upgradeCap: ""
|
|
1717
|
+
},
|
|
1718
|
+
switchboard: { id: "", upgradeCap: "" },
|
|
1719
|
+
xOracle: {
|
|
1720
|
+
id: "",
|
|
1721
|
+
upgradeCap: ""
|
|
1722
|
+
},
|
|
1723
|
+
testCoin: { id: "", upgradeCap: "" }
|
|
1724
|
+
}
|
|
1725
|
+
},
|
|
1726
|
+
spool: {
|
|
1727
|
+
id: "",
|
|
1728
|
+
adminCap: "",
|
|
1729
|
+
object: "",
|
|
1730
|
+
pools: {
|
|
1731
|
+
seth: {
|
|
1732
|
+
id: "",
|
|
1733
|
+
rewardPoolId: ""
|
|
1734
|
+
},
|
|
1735
|
+
ssui: {
|
|
1736
|
+
id: "",
|
|
1737
|
+
rewardPoolId: ""
|
|
1738
|
+
},
|
|
1739
|
+
susdc: {
|
|
1740
|
+
id: "",
|
|
1741
|
+
rewardPoolId: ""
|
|
1742
|
+
},
|
|
1743
|
+
susdt: {
|
|
1744
|
+
id: "",
|
|
1745
|
+
rewardPoolId: ""
|
|
1746
|
+
},
|
|
1747
|
+
scetus: {
|
|
1748
|
+
id: "",
|
|
1749
|
+
rewardPoolId: ""
|
|
1750
|
+
},
|
|
1751
|
+
safsui: {
|
|
1752
|
+
id: "",
|
|
1753
|
+
rewardPoolId: ""
|
|
1754
|
+
},
|
|
1755
|
+
shasui: {
|
|
1756
|
+
id: "",
|
|
1757
|
+
rewardPoolId: ""
|
|
1758
|
+
},
|
|
1759
|
+
svsui: {
|
|
1760
|
+
id: "",
|
|
1761
|
+
rewardPoolId: ""
|
|
1762
|
+
}
|
|
1763
|
+
},
|
|
1764
|
+
config: ""
|
|
1765
|
+
},
|
|
1766
|
+
borrowIncentive: {
|
|
1767
|
+
id: "",
|
|
1768
|
+
adminCap: "",
|
|
1769
|
+
object: "",
|
|
1770
|
+
query: "",
|
|
1771
|
+
incentivePools: "",
|
|
1772
|
+
incentiveAccounts: "",
|
|
1773
|
+
config: ""
|
|
1774
|
+
},
|
|
1775
|
+
vesca: {
|
|
1776
|
+
id: "",
|
|
1777
|
+
object: "",
|
|
1778
|
+
adminCap: "",
|
|
1779
|
+
tableId: "",
|
|
1780
|
+
table: "",
|
|
1781
|
+
treasury: "",
|
|
1782
|
+
config: ""
|
|
1783
|
+
},
|
|
1784
|
+
referral: {
|
|
1785
|
+
id: "",
|
|
1786
|
+
version: "",
|
|
1787
|
+
object: "",
|
|
1788
|
+
adminCap: "",
|
|
1789
|
+
referralBindings: "",
|
|
1790
|
+
bindingTableId: "",
|
|
1791
|
+
referralRevenuePool: "",
|
|
1792
|
+
revenueTableId: "",
|
|
1793
|
+
referralTiers: "",
|
|
1794
|
+
tiersTableId: "",
|
|
1795
|
+
authorizedWitnessList: ""
|
|
1796
|
+
},
|
|
1797
|
+
loyaltyProgram: {
|
|
1798
|
+
id: "",
|
|
1799
|
+
object: "",
|
|
1800
|
+
rewardPool: "",
|
|
1801
|
+
userRewardTableId: ""
|
|
1802
|
+
},
|
|
1803
|
+
scoin: {
|
|
1804
|
+
id: "",
|
|
1805
|
+
coins: {
|
|
1806
|
+
ssui: {
|
|
1807
|
+
coinType: "",
|
|
1808
|
+
treasury: ""
|
|
2009
1809
|
},
|
|
2010
|
-
{
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
}
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
return coinName.charAt(0).toLowerCase() === "s" && COIN_SET.includes(assetCoinName);
|
|
1810
|
+
scetus: {
|
|
1811
|
+
coinType: "",
|
|
1812
|
+
treasury: ""
|
|
1813
|
+
},
|
|
1814
|
+
ssca: {
|
|
1815
|
+
coinType: "",
|
|
1816
|
+
treasury: ""
|
|
1817
|
+
},
|
|
1818
|
+
susdc: {
|
|
1819
|
+
coinType: "",
|
|
1820
|
+
treasury: ""
|
|
1821
|
+
},
|
|
1822
|
+
susdt: {
|
|
1823
|
+
coinType: "",
|
|
1824
|
+
treasury: ""
|
|
1825
|
+
},
|
|
1826
|
+
seth: {
|
|
1827
|
+
coinType: "",
|
|
1828
|
+
treasury: ""
|
|
1829
|
+
},
|
|
1830
|
+
safsui: {
|
|
1831
|
+
coinType: "",
|
|
1832
|
+
treasury: ""
|
|
1833
|
+
},
|
|
1834
|
+
shasui: {
|
|
1835
|
+
coinType: "",
|
|
1836
|
+
treasury: ""
|
|
1837
|
+
},
|
|
1838
|
+
svsui: {
|
|
1839
|
+
coinType: "",
|
|
1840
|
+
treasury: ""
|
|
1841
|
+
}
|
|
1842
|
+
}
|
|
1843
|
+
}
|
|
2045
1844
|
};
|
|
2046
|
-
var
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
1845
|
+
var ScallopAddress = class {
|
|
1846
|
+
constructor(params, cache) {
|
|
1847
|
+
const { id, auth, network } = params;
|
|
1848
|
+
this._cache = cache ?? new ScallopCache(DEFAULT_CACHE_OPTIONS);
|
|
1849
|
+
this._requestClient = axios.create({
|
|
1850
|
+
baseURL: API_BASE_URL,
|
|
1851
|
+
headers: {
|
|
1852
|
+
"Content-Type": "application/json",
|
|
1853
|
+
Accept: "application/json"
|
|
1854
|
+
},
|
|
1855
|
+
timeout: 3e4
|
|
1856
|
+
});
|
|
1857
|
+
if (auth)
|
|
1858
|
+
this._auth = auth;
|
|
1859
|
+
this._id = id;
|
|
1860
|
+
this._network = network || "mainnet";
|
|
1861
|
+
this._addressesMap = USE_TEST_ADDRESS ? /* @__PURE__ */ new Map([["mainnet", TEST_ADDRESSES]]) : /* @__PURE__ */ new Map();
|
|
1862
|
+
if (USE_TEST_ADDRESS)
|
|
1863
|
+
this._currentAddresses = TEST_ADDRESSES;
|
|
1864
|
+
}
|
|
1865
|
+
/**
|
|
1866
|
+
* Get addresses API id.
|
|
1867
|
+
*
|
|
1868
|
+
* @return The addresses API id.
|
|
1869
|
+
*/
|
|
1870
|
+
getId() {
|
|
1871
|
+
return this._id || void 0;
|
|
1872
|
+
}
|
|
1873
|
+
/**
|
|
1874
|
+
* Get the address at the provided path.
|
|
1875
|
+
*
|
|
1876
|
+
* @param path - The path of the address to get.
|
|
1877
|
+
* @return The address at the provided path.
|
|
1878
|
+
*/
|
|
1879
|
+
get(path) {
|
|
1880
|
+
if (this._currentAddresses) {
|
|
1881
|
+
const value = path.split(".").reduce(
|
|
1882
|
+
(nestedAddressObj, key) => typeof nestedAddressObj === "object" ? nestedAddressObj[key] : nestedAddressObj,
|
|
1883
|
+
this._currentAddresses
|
|
1884
|
+
);
|
|
1885
|
+
return value || void 0;
|
|
1886
|
+
} else {
|
|
1887
|
+
return void 0;
|
|
1888
|
+
}
|
|
1889
|
+
}
|
|
1890
|
+
/**
|
|
1891
|
+
* Sets the address for the specified path, it does not interact with the API.
|
|
1892
|
+
*
|
|
1893
|
+
* @param path - The path of the address to set.
|
|
1894
|
+
* @param address - The address be setted to the tartget path.
|
|
1895
|
+
* @return The addresses.
|
|
1896
|
+
*/
|
|
1897
|
+
set(path, address) {
|
|
1898
|
+
if (this._currentAddresses) {
|
|
1899
|
+
const keys = path.split(".");
|
|
1900
|
+
keys.reduce((nestedAddressObj, key, index) => {
|
|
1901
|
+
if (index === keys.length - 1) {
|
|
1902
|
+
nestedAddressObj[key] = address;
|
|
1903
|
+
} else {
|
|
1904
|
+
return nestedAddressObj[key];
|
|
1905
|
+
}
|
|
1906
|
+
}, this._currentAddresses);
|
|
1907
|
+
}
|
|
1908
|
+
return this._currentAddresses;
|
|
1909
|
+
}
|
|
1910
|
+
/**
|
|
1911
|
+
* Synchronize the specified network addresses from the addresses map to the
|
|
1912
|
+
* current addresses and change the default network to specified network.
|
|
1913
|
+
*
|
|
1914
|
+
* @param network - Specifies which network's addresses you want to get.
|
|
1915
|
+
* @return Current addresses.
|
|
1916
|
+
*/
|
|
1917
|
+
switchCurrentAddresses(network) {
|
|
1918
|
+
if (this._addressesMap.has(network)) {
|
|
1919
|
+
this._currentAddresses = this._addressesMap.get(network);
|
|
1920
|
+
this._network = network;
|
|
1921
|
+
}
|
|
1922
|
+
return this._currentAddresses;
|
|
1923
|
+
}
|
|
1924
|
+
/**
|
|
1925
|
+
* Get the addresses, If `network` is not provided, returns the current
|
|
1926
|
+
* addresses or the default network addresses in the addresses map.
|
|
1927
|
+
*
|
|
1928
|
+
* @param network - Specifies which network's addresses you want to get.
|
|
1929
|
+
*/
|
|
1930
|
+
getAddresses(network) {
|
|
1931
|
+
if (network) {
|
|
1932
|
+
return this._addressesMap.get(network);
|
|
1933
|
+
} else {
|
|
1934
|
+
return this._currentAddresses ?? this._addressesMap.get(this._network);
|
|
1935
|
+
}
|
|
1936
|
+
}
|
|
1937
|
+
/**
|
|
1938
|
+
* Set the addresses into addresses map. If the specified network is the same
|
|
1939
|
+
* as the current network, the current addresses will be updated at the same time.
|
|
1940
|
+
*
|
|
1941
|
+
* @param addresses - The addresses be setted to the tartget network.
|
|
1942
|
+
* @param network - Specifies which network's addresses you want to set.
|
|
1943
|
+
* @return The addresses.
|
|
1944
|
+
*/
|
|
1945
|
+
setAddresses(addresses, network) {
|
|
1946
|
+
const targetNetwork = network || this._network;
|
|
1947
|
+
if (targetNetwork === this._network)
|
|
1948
|
+
this._currentAddresses = addresses;
|
|
1949
|
+
this._addressesMap.set(targetNetwork, addresses);
|
|
1950
|
+
}
|
|
1951
|
+
/**
|
|
1952
|
+
* Get all addresses.
|
|
1953
|
+
*
|
|
1954
|
+
* @return All addresses.
|
|
1955
|
+
*/
|
|
1956
|
+
getAllAddresses() {
|
|
1957
|
+
return Object.fromEntries(this._addressesMap);
|
|
1958
|
+
}
|
|
1959
|
+
/**
|
|
1960
|
+
* Create a new addresses through the API and synchronize it back to the
|
|
1961
|
+
* instance.
|
|
1962
|
+
*
|
|
1963
|
+
* @description
|
|
1964
|
+
* If the `network` is not specified, the mainnet is used by default.
|
|
1965
|
+
* If no `addresses` from instance or parameter is provided, an addresses with
|
|
1966
|
+
* all empty strings is created by default.
|
|
1967
|
+
*
|
|
1968
|
+
* This function only allows for one addresses to be input into a specific network
|
|
1969
|
+
* at a time, and does not provide an addresses map for setting addresses
|
|
1970
|
+
* across all networks at once.
|
|
1971
|
+
*
|
|
1972
|
+
* @param params.addresses - The addresses be setted to the tartget network.
|
|
1973
|
+
* @param params.network - Specifies which network's addresses you want to set.
|
|
1974
|
+
* @param params.auth - The authentication API key.
|
|
1975
|
+
* @param params.memo - Add memo to the addresses created in the API.
|
|
1976
|
+
* @return All addresses.
|
|
1977
|
+
*/
|
|
1978
|
+
async create(params) {
|
|
1979
|
+
const { addresses, network, auth, memo } = params ?? {};
|
|
1980
|
+
const apiKey = auth || this._auth || void 0;
|
|
1981
|
+
const targetNetwork = network || this._network;
|
|
1982
|
+
const targetAddresses = addresses || this._currentAddresses || this._addressesMap.get(targetNetwork) || EMPTY_ADDRESSES;
|
|
1983
|
+
if (apiKey !== void 0) {
|
|
1984
|
+
this._addressesMap.clear();
|
|
1985
|
+
this.setAddresses(targetAddresses, targetNetwork);
|
|
1986
|
+
const response = await this._requestClient.post(
|
|
1987
|
+
`/addresses`,
|
|
1988
|
+
JSON.stringify({ ...Object.fromEntries(this._addressesMap), memo }),
|
|
1989
|
+
{
|
|
1990
|
+
headers: {
|
|
1991
|
+
"Content-Type": "application/json",
|
|
1992
|
+
"api-key": auth || this._auth
|
|
1993
|
+
}
|
|
1994
|
+
}
|
|
1995
|
+
);
|
|
1996
|
+
if (response.status === 201) {
|
|
1997
|
+
for (const [network2, addresses2] of Object.entries(
|
|
1998
|
+
response.data
|
|
1999
|
+
)) {
|
|
2000
|
+
if (["localnet", "devnet", "testnet", "mainnet"].includes(network2)) {
|
|
2001
|
+
if (network2 === this._network)
|
|
2002
|
+
this._currentAddresses = addresses2;
|
|
2003
|
+
this._addressesMap.set(network2, addresses2);
|
|
2004
|
+
}
|
|
2005
|
+
}
|
|
2006
|
+
this._id = response.data.id;
|
|
2007
|
+
return this.getAllAddresses();
|
|
2008
|
+
} else {
|
|
2009
|
+
throw Error("Failed to create addresses.");
|
|
2010
|
+
}
|
|
2011
|
+
} else {
|
|
2012
|
+
throw Error("You don't have permission to access this request.");
|
|
2013
|
+
}
|
|
2056
2014
|
}
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
const
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2015
|
+
/**
|
|
2016
|
+
* Read and synchronizes all addresses from the API into instance.
|
|
2017
|
+
*
|
|
2018
|
+
* @param id - The id of the addresses to get.
|
|
2019
|
+
* @return All addresses.
|
|
2020
|
+
*/
|
|
2021
|
+
async read(id) {
|
|
2022
|
+
const addressesId = id || this._id || void 0;
|
|
2023
|
+
if (addressesId !== void 0) {
|
|
2024
|
+
const response = await this._cache.queryClient.fetchQuery({
|
|
2025
|
+
queryKey: ["api-getAddresses", addressesId],
|
|
2026
|
+
queryFn: async () => {
|
|
2027
|
+
return await this._requestClient.get(`/addresses/${addressesId}`, {
|
|
2028
|
+
headers: {
|
|
2029
|
+
"Content-Type": "application/json"
|
|
2030
|
+
}
|
|
2031
|
+
});
|
|
2032
|
+
}
|
|
2033
|
+
});
|
|
2034
|
+
if (response.status === 200) {
|
|
2035
|
+
for (const [network, addresses] of Object.entries(
|
|
2036
|
+
response.data
|
|
2037
|
+
)) {
|
|
2038
|
+
if (["localnet", "devnet", "testnet", "mainnet"].includes(network)) {
|
|
2039
|
+
if (network === this._network)
|
|
2040
|
+
this._currentAddresses = addresses;
|
|
2041
|
+
this._addressesMap.set(network, addresses);
|
|
2042
|
+
}
|
|
2043
|
+
}
|
|
2044
|
+
this._id = response.data.id;
|
|
2045
|
+
return this.getAllAddresses();
|
|
2046
|
+
} else {
|
|
2047
|
+
throw Error("Failed to create addresses.");
|
|
2048
|
+
}
|
|
2049
|
+
} else {
|
|
2050
|
+
throw Error("Please provide API addresses id.");
|
|
2051
|
+
}
|
|
2072
2052
|
}
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2053
|
+
/**
|
|
2054
|
+
* Update the addresses through the API and synchronize it back to the
|
|
2055
|
+
* instance.
|
|
2056
|
+
*
|
|
2057
|
+
* @description
|
|
2058
|
+
* If the `network` is not specified, the mainnet is used by default.
|
|
2059
|
+
* If no `addresses` from instance or parameter is provided, an addresses with
|
|
2060
|
+
* all empty strings is created by default.
|
|
2061
|
+
*
|
|
2062
|
+
* This function only allows for one addresses to be input into a specific network
|
|
2063
|
+
* at a time, and does not provide an addresses map for setting addresses
|
|
2064
|
+
* across all networks at once.
|
|
2065
|
+
*
|
|
2066
|
+
* @param params.id - The id of the addresses to update.
|
|
2067
|
+
* @param params.addresses - The addresses be setted to the tartget network.
|
|
2068
|
+
* @param params.network - Specifies which network's addresses you want to set.
|
|
2069
|
+
* @param params.auth - The authentication api key.
|
|
2070
|
+
* @param params.memo - Add memo to the addresses created in the API.
|
|
2071
|
+
* @return All addresses.
|
|
2072
|
+
*/
|
|
2073
|
+
async update(params) {
|
|
2074
|
+
const { id, addresses, network, auth, memo } = params ?? {};
|
|
2075
|
+
const apiKey = auth || this._auth || void 0;
|
|
2076
|
+
const targetId = id || this._id || void 0;
|
|
2077
|
+
const targetNetwork = network || this._network;
|
|
2078
|
+
const targetAddresses = addresses || this._currentAddresses || this._addressesMap.get(targetNetwork) || EMPTY_ADDRESSES;
|
|
2079
|
+
if (targetId === void 0)
|
|
2080
|
+
throw Error("Require specific addresses id to be updated.");
|
|
2081
|
+
if (apiKey !== void 0) {
|
|
2082
|
+
if (id !== this._id) {
|
|
2083
|
+
this._addressesMap.clear();
|
|
2084
|
+
}
|
|
2085
|
+
this.setAddresses(targetAddresses, targetNetwork);
|
|
2086
|
+
const response = await this._requestClient.put(
|
|
2087
|
+
`/addresses/${targetId}`,
|
|
2088
|
+
JSON.stringify({ ...Object.fromEntries(this._addressesMap), memo }),
|
|
2089
|
+
{
|
|
2090
|
+
headers: {
|
|
2091
|
+
"Content-Type": "application/json",
|
|
2092
|
+
"api-key": auth || this._auth
|
|
2093
|
+
}
|
|
2094
|
+
}
|
|
2095
|
+
);
|
|
2096
|
+
if (response.status === 200) {
|
|
2097
|
+
for (const [network2, addresses2] of Object.entries(
|
|
2098
|
+
response.data
|
|
2099
|
+
)) {
|
|
2100
|
+
if (["localnet", "devnet", "testnet", "mainnet"].includes(network2)) {
|
|
2101
|
+
if (network2 === this._network)
|
|
2102
|
+
this._currentAddresses = addresses2;
|
|
2103
|
+
this._addressesMap.set(network2, addresses2);
|
|
2104
|
+
}
|
|
2105
|
+
}
|
|
2106
|
+
this._id = response.data.id;
|
|
2107
|
+
return this.getAllAddresses();
|
|
2108
|
+
} else {
|
|
2109
|
+
throw Error("Failed to update addresses.");
|
|
2110
|
+
}
|
|
2111
|
+
} else {
|
|
2112
|
+
throw Error("You don't have permission to access this request.");
|
|
2113
|
+
}
|
|
2080
2114
|
}
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2115
|
+
/**
|
|
2116
|
+
* Deletes all addresses of a specified id through the API and clear all
|
|
2117
|
+
* addresses in the instance.
|
|
2118
|
+
*
|
|
2119
|
+
* @param id - The id of the addresses to delete.
|
|
2120
|
+
* @param auth - The authentication API key.
|
|
2121
|
+
*/
|
|
2122
|
+
async delete(id, auth) {
|
|
2123
|
+
const apiKey = auth || this._auth || void 0;
|
|
2124
|
+
const targetId = id || this._id || void 0;
|
|
2125
|
+
if (targetId === void 0)
|
|
2126
|
+
throw Error("Require specific addresses id to be deleted.");
|
|
2127
|
+
if (apiKey !== void 0) {
|
|
2128
|
+
const response = await this._requestClient.delete(
|
|
2129
|
+
`/addresses/${targetId}`,
|
|
2130
|
+
{
|
|
2131
|
+
headers: {
|
|
2132
|
+
"Content-Type": "application/json",
|
|
2133
|
+
"api-key": auth || this._auth
|
|
2134
|
+
}
|
|
2135
|
+
}
|
|
2136
|
+
);
|
|
2137
|
+
if (response.status === 200) {
|
|
2138
|
+
this._id = void 0;
|
|
2139
|
+
this._currentAddresses = void 0;
|
|
2140
|
+
this._addressesMap.clear();
|
|
2141
|
+
} else {
|
|
2142
|
+
throw Error("Failed to delete addresses.");
|
|
2143
|
+
}
|
|
2144
|
+
} else {
|
|
2145
|
+
throw Error("You don't have permission to access this request.");
|
|
2146
|
+
}
|
|
2084
2147
|
}
|
|
2085
|
-
return Math.floor(closestTwelveAM.getTime() / 1e3);
|
|
2086
2148
|
};
|
|
2087
2149
|
|
|
2150
|
+
// src/models/scallopClient.ts
|
|
2151
|
+
import { normalizeSuiAddress as normalizeSuiAddress4 } from "@mysten/sui.js/utils";
|
|
2152
|
+
import { SuiKit as SuiKit4 } from "@scallop-io/sui-kit";
|
|
2153
|
+
|
|
2154
|
+
// src/models/scallopUtils.ts
|
|
2155
|
+
import { SUI_TYPE_ARG, normalizeStructTag as normalizeStructTag6 } from "@mysten/sui.js/utils";
|
|
2156
|
+
import { SuiKit as SuiKit2 } from "@scallop-io/sui-kit";
|
|
2157
|
+
import { SuiPriceServiceConnection } from "@pythnetwork/pyth-sui-js";
|
|
2158
|
+
|
|
2159
|
+
// src/models/scallopQuery.ts
|
|
2160
|
+
import { SuiKit } from "@scallop-io/sui-kit";
|
|
2161
|
+
|
|
2088
2162
|
// src/queries/coreQuery.ts
|
|
2163
|
+
import { normalizeStructTag as normalizeStructTag3 } from "@mysten/sui.js/utils";
|
|
2089
2164
|
import BigNumber2 from "bignumber.js";
|
|
2090
2165
|
var queryMarket = async (query, indexer = false) => {
|
|
2091
2166
|
const coinPrices = await query.utils.getCoinPrices();
|
|
@@ -2113,8 +2188,8 @@ var queryMarket = async (query, indexer = false) => {
|
|
|
2113
2188
|
const queryTarget = `${packageId}::market_query::market_data`;
|
|
2114
2189
|
const args = [marketId];
|
|
2115
2190
|
const queryResult = await query.cache.queryInspectTxn({ queryTarget, args });
|
|
2116
|
-
const marketData = queryResult
|
|
2117
|
-
for (const pool of marketData
|
|
2191
|
+
const marketData = queryResult?.events[0].parsedJson;
|
|
2192
|
+
for (const pool of marketData?.pools ?? []) {
|
|
2118
2193
|
const coinType = normalizeStructTag3(pool.type.name);
|
|
2119
2194
|
const poolCoinName = query.utils.parseCoinNameFromType(coinType);
|
|
2120
2195
|
const coinPrice = coinPrices[poolCoinName] ?? 0;
|
|
@@ -2164,7 +2239,7 @@ var queryMarket = async (query, indexer = false) => {
|
|
|
2164
2239
|
...calculatedMarketPoolData
|
|
2165
2240
|
};
|
|
2166
2241
|
}
|
|
2167
|
-
for (const collateral of marketData
|
|
2242
|
+
for (const collateral of marketData?.collaterals ?? []) {
|
|
2168
2243
|
const coinType = normalizeStructTag3(collateral.type.name);
|
|
2169
2244
|
const collateralCoinName = query.utils.parseCoinNameFromType(coinType);
|
|
2170
2245
|
const coinPrice = coinPrices[collateralCoinName] ?? 0;
|
|
@@ -2234,7 +2309,7 @@ var getMarketPools = async (query, poolCoinNames, indexer = false) => {
|
|
|
2234
2309
|
query,
|
|
2235
2310
|
poolCoinName,
|
|
2236
2311
|
indexer,
|
|
2237
|
-
marketObjectResponse
|
|
2312
|
+
marketObjectResponse?.data,
|
|
2238
2313
|
coinPrices?.[poolCoinName]
|
|
2239
2314
|
);
|
|
2240
2315
|
if (marketPool) {
|
|
@@ -2261,7 +2336,7 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
|
|
|
2261
2336
|
const marketId = query.address.get("core.market");
|
|
2262
2337
|
marketObject = marketObject || (await query.cache.queryGetObject(marketId, {
|
|
2263
2338
|
showContent: true
|
|
2264
|
-
}))
|
|
2339
|
+
}))?.data;
|
|
2265
2340
|
coinPrice = coinPrice || (await query.utils.getCoinPrices([poolCoinName]))?.[poolCoinName];
|
|
2266
2341
|
if (marketObject) {
|
|
2267
2342
|
if (marketObject.content && "fields" in marketObject.content) {
|
|
@@ -2277,6 +2352,8 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
|
|
|
2277
2352
|
}
|
|
2278
2353
|
}
|
|
2279
2354
|
});
|
|
2355
|
+
if (!balanceSheetDynamicFieldObjectResponse)
|
|
2356
|
+
return void 0;
|
|
2280
2357
|
const balanceSheetDynamicFieldObject = balanceSheetDynamicFieldObjectResponse.data;
|
|
2281
2358
|
if (balanceSheetDynamicFieldObject && balanceSheetDynamicFieldObject.content && "fields" in balanceSheetDynamicFieldObject.content) {
|
|
2282
2359
|
const dynamicFields = balanceSheetDynamicFieldObject.content.fields;
|
|
@@ -2292,6 +2369,8 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
|
|
|
2292
2369
|
}
|
|
2293
2370
|
}
|
|
2294
2371
|
});
|
|
2372
|
+
if (!borrowIndexDynamicFieldObjectResponse)
|
|
2373
|
+
return void 0;
|
|
2295
2374
|
const borrowIndexDynamicFieldObject = borrowIndexDynamicFieldObjectResponse.data;
|
|
2296
2375
|
if (borrowIndexDynamicFieldObject && borrowIndexDynamicFieldObject.content && "fields" in borrowIndexDynamicFieldObject.content) {
|
|
2297
2376
|
const dynamicFields = borrowIndexDynamicFieldObject.content.fields;
|
|
@@ -2307,6 +2386,8 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
|
|
|
2307
2386
|
}
|
|
2308
2387
|
}
|
|
2309
2388
|
});
|
|
2389
|
+
if (!interestModelDynamicFieldObjectResponse)
|
|
2390
|
+
return void 0;
|
|
2310
2391
|
const interestModelDynamicFieldObject = interestModelDynamicFieldObjectResponse.data;
|
|
2311
2392
|
if (interestModelDynamicFieldObject && interestModelDynamicFieldObject.content && "fields" in interestModelDynamicFieldObject.content) {
|
|
2312
2393
|
const dynamicFields = interestModelDynamicFieldObject.content.fields;
|
|
@@ -2323,6 +2404,8 @@ var getMarketPool = async (query, poolCoinName, indexer = false, marketObject, c
|
|
|
2323
2404
|
}
|
|
2324
2405
|
}
|
|
2325
2406
|
});
|
|
2407
|
+
if (!borrowFeeDynamicFieldObjectResponse)
|
|
2408
|
+
return void 0;
|
|
2326
2409
|
const borrowFeeDynamicFieldObject = borrowFeeDynamicFieldObjectResponse.data;
|
|
2327
2410
|
if (borrowFeeDynamicFieldObject && borrowFeeDynamicFieldObject.content && "fields" in borrowFeeDynamicFieldObject.content) {
|
|
2328
2411
|
const dynamicFields = borrowFeeDynamicFieldObject.content.fields;
|
|
@@ -2405,7 +2488,7 @@ var getMarketCollaterals = async (query, collateralCoinNames, indexer = false) =
|
|
|
2405
2488
|
query,
|
|
2406
2489
|
collateralCoinName,
|
|
2407
2490
|
indexer,
|
|
2408
|
-
marketObjectResponse
|
|
2491
|
+
marketObjectResponse?.data,
|
|
2409
2492
|
coinPrices?.[collateralCoinName]
|
|
2410
2493
|
);
|
|
2411
2494
|
if (marketCollateral) {
|
|
@@ -2430,7 +2513,7 @@ var getMarketCollateral = async (query, collateralCoinName, indexer = false, mar
|
|
|
2430
2513
|
const marketId = query.address.get("core.market");
|
|
2431
2514
|
marketObject = marketObject || (await query.cache.queryGetObject(marketId, {
|
|
2432
2515
|
showContent: true
|
|
2433
|
-
}))
|
|
2516
|
+
}))?.data;
|
|
2434
2517
|
coinPrice = coinPrice || (await query.utils.getCoinPrices([collateralCoinName]))?.[collateralCoinName];
|
|
2435
2518
|
if (marketObject) {
|
|
2436
2519
|
if (marketObject.content && "fields" in marketObject.content) {
|
|
@@ -2446,6 +2529,8 @@ var getMarketCollateral = async (query, collateralCoinName, indexer = false, mar
|
|
|
2446
2529
|
}
|
|
2447
2530
|
}
|
|
2448
2531
|
});
|
|
2532
|
+
if (!riskModelDynamicFieldObjectResponse)
|
|
2533
|
+
return void 0;
|
|
2449
2534
|
const riskModelDynamicFieldObject = riskModelDynamicFieldObjectResponse.data;
|
|
2450
2535
|
if (riskModelDynamicFieldObject && riskModelDynamicFieldObject.content && "fields" in riskModelDynamicFieldObject.content) {
|
|
2451
2536
|
const dynamicFields = riskModelDynamicFieldObject.content.fields;
|
|
@@ -2461,6 +2546,8 @@ var getMarketCollateral = async (query, collateralCoinName, indexer = false, mar
|
|
|
2461
2546
|
}
|
|
2462
2547
|
}
|
|
2463
2548
|
});
|
|
2549
|
+
if (!collateralStatDynamicFieldObjectResponse)
|
|
2550
|
+
return void 0;
|
|
2464
2551
|
const collateralStatDynamicFieldObject = collateralStatDynamicFieldObjectResponse.data;
|
|
2465
2552
|
if (collateralStatDynamicFieldObject && collateralStatDynamicFieldObject.content && "fields" in collateralStatDynamicFieldObject.content) {
|
|
2466
2553
|
const dynamicFields = collateralStatDynamicFieldObject.content.fields;
|
|
@@ -2515,6 +2602,8 @@ var getObligations = async (query, ownerAddress) => {
|
|
|
2515
2602
|
},
|
|
2516
2603
|
cursor: nextCursor
|
|
2517
2604
|
});
|
|
2605
|
+
if (!paginatedKeyObjectsResponse)
|
|
2606
|
+
continue;
|
|
2518
2607
|
keyObjectsResponse.push(...paginatedKeyObjectsResponse.data);
|
|
2519
2608
|
if (paginatedKeyObjectsResponse.hasNextPage && paginatedKeyObjectsResponse.nextCursor) {
|
|
2520
2609
|
hasNextPage = true;
|
|
@@ -2545,7 +2634,7 @@ var getObligationLocked = async (query, obligationId) => {
|
|
|
2545
2634
|
{ showContent: true }
|
|
2546
2635
|
);
|
|
2547
2636
|
let obligationLocked = false;
|
|
2548
|
-
if (obligationObjectResponse
|
|
2637
|
+
if (obligationObjectResponse?.data && obligationObjectResponse?.data?.content?.dataType === "moveObject" && "lock_key" in obligationObjectResponse.data.content.fields) {
|
|
2549
2638
|
obligationLocked = Boolean(
|
|
2550
2639
|
obligationObjectResponse.data.content.fields.lock_key
|
|
2551
2640
|
);
|
|
@@ -2560,7 +2649,7 @@ var queryObligation = async (query, obligationId) => {
|
|
|
2560
2649
|
{ queryTarget, args }
|
|
2561
2650
|
// txBlock
|
|
2562
2651
|
);
|
|
2563
|
-
return queryResult
|
|
2652
|
+
return queryResult?.events[0].parsedJson;
|
|
2564
2653
|
};
|
|
2565
2654
|
var getCoinAmounts = async (query, assetCoinNames, ownerAddress) => {
|
|
2566
2655
|
assetCoinNames = assetCoinNames || [...SUPPORT_POOLS];
|
|
@@ -2637,7 +2726,7 @@ var getFlashLoanFees = async (query, assetNames) => {
|
|
|
2637
2726
|
const marketObjectRes = await query.cache.queryGetObject(marketObjectId, {
|
|
2638
2727
|
showContent: true
|
|
2639
2728
|
});
|
|
2640
|
-
if (marketObjectRes
|
|
2729
|
+
if (marketObjectRes?.data?.content?.dataType !== "moveObject")
|
|
2641
2730
|
throw new Error("Failed to get market object");
|
|
2642
2731
|
const vault = marketObjectRes.data.content.fields.vault;
|
|
2643
2732
|
const flashloanFeesTableId = vault.fields.flash_loan_fees.fields.table.fields.id.id;
|
|
@@ -2645,10 +2734,10 @@ var getFlashLoanFees = async (query, assetNames) => {
|
|
|
2645
2734
|
parentId: flashloanFeesTableId,
|
|
2646
2735
|
limit: 50
|
|
2647
2736
|
});
|
|
2648
|
-
const dynamicFieldObjectIds = balanceSheetDynamicFields
|
|
2737
|
+
const dynamicFieldObjectIds = balanceSheetDynamicFields?.data.filter((field) => {
|
|
2649
2738
|
const assetType = field.name.value.name;
|
|
2650
2739
|
return !!assetTypeMap[assetType];
|
|
2651
|
-
}).map((field) => field.objectId);
|
|
2740
|
+
}).map((field) => field.objectId) ?? [];
|
|
2652
2741
|
flashloanFeeObjects.push(
|
|
2653
2742
|
...await query.cache.queryGetObjects(dynamicFieldObjectIds, {
|
|
2654
2743
|
showContent: true
|
|
@@ -2827,6 +2916,8 @@ var getStakeAccounts = async (query, ownerAddress) => {
|
|
|
2827
2916
|
},
|
|
2828
2917
|
cursor: nextCursor
|
|
2829
2918
|
});
|
|
2919
|
+
if (!paginatedStakeObjectsResponse)
|
|
2920
|
+
continue;
|
|
2830
2921
|
stakeObjectsResponse.push(...paginatedStakeObjectsResponse.data);
|
|
2831
2922
|
if (paginatedStakeObjectsResponse.hasNextPage && paginatedStakeObjectsResponse.nextCursor) {
|
|
2832
2923
|
hasNextPage = true;
|
|
@@ -2968,7 +3059,7 @@ var getStakePool = async (query, marketCoinName) => {
|
|
|
2968
3059
|
showContent: true,
|
|
2969
3060
|
showType: true
|
|
2970
3061
|
});
|
|
2971
|
-
if (stakePoolObjectResponse
|
|
3062
|
+
if (stakePoolObjectResponse?.data) {
|
|
2972
3063
|
const stakePoolObject = stakePoolObjectResponse.data;
|
|
2973
3064
|
const id = stakePoolObject.objectId;
|
|
2974
3065
|
const type = stakePoolObject.type;
|
|
@@ -3014,7 +3105,7 @@ var getStakeRewardPool = async (query, marketCoinName) => {
|
|
|
3014
3105
|
showType: true
|
|
3015
3106
|
}
|
|
3016
3107
|
);
|
|
3017
|
-
if (stakeRewardPoolObjectResponse
|
|
3108
|
+
if (stakeRewardPoolObjectResponse?.data) {
|
|
3018
3109
|
const stakeRewardPoolObject = stakeRewardPoolObjectResponse.data;
|
|
3019
3110
|
const id = stakeRewardPoolObject.objectId;
|
|
3020
3111
|
const type = stakeRewardPoolObject.type;
|
|
@@ -3074,8 +3165,8 @@ var queryBorrowIncentivePools = async (query, borrowIncentiveCoinNames, indexer
|
|
|
3074
3165
|
const queryTarget = `${queryPkgId}::incentive_pools_query::incentive_pools_data`;
|
|
3075
3166
|
const args = [incentivePoolsId];
|
|
3076
3167
|
const queryResult = await query.cache.queryInspectTxn({ queryTarget, args });
|
|
3077
|
-
const borrowIncentivePoolsQueryData = queryResult
|
|
3078
|
-
for (const pool of borrowIncentivePoolsQueryData
|
|
3168
|
+
const borrowIncentivePoolsQueryData = queryResult?.events[0].parsedJson;
|
|
3169
|
+
for (const pool of borrowIncentivePoolsQueryData?.incentive_pools ?? []) {
|
|
3079
3170
|
const borrowIncentivePoolPoints = {};
|
|
3080
3171
|
const parsedBorrowIncentivePoolData = parseOriginBorrowIncentivePoolData(pool);
|
|
3081
3172
|
const poolCoinType = normalizeStructTag5(pool.pool_type.name);
|
|
@@ -3146,9 +3237,9 @@ var queryBorrowIncentiveAccounts = async (query, obligationId, borrowIncentiveCo
|
|
|
3146
3237
|
const queryTarget = `${queryPkgId}::incentive_account_query::incentive_account_data`;
|
|
3147
3238
|
const args = [incentiveAccountsId, obligationId];
|
|
3148
3239
|
const queryResult = await query.cache.queryInspectTxn({ queryTarget, args });
|
|
3149
|
-
const borrowIncentiveAccountsQueryData = queryResult
|
|
3240
|
+
const borrowIncentiveAccountsQueryData = queryResult?.events[0].parsedJson;
|
|
3150
3241
|
const borrowIncentiveAccounts = Object.values(
|
|
3151
|
-
borrowIncentiveAccountsQueryData
|
|
3242
|
+
borrowIncentiveAccountsQueryData?.pool_records ?? []
|
|
3152
3243
|
).reduce((accounts, accountData) => {
|
|
3153
3244
|
const parsedBorrowIncentiveAccount = parseOriginBorrowIncentiveAccountData(accountData);
|
|
3154
3245
|
const poolType = parsedBorrowIncentiveAccount.poolType;
|
|
@@ -3170,7 +3261,7 @@ var getBindedObligationId = async (query, veScaKeyId) => {
|
|
|
3170
3261
|
showContent: true
|
|
3171
3262
|
}
|
|
3172
3263
|
);
|
|
3173
|
-
if (incentivePoolsResponse
|
|
3264
|
+
if (incentivePoolsResponse?.data?.content?.dataType !== "moveObject")
|
|
3174
3265
|
return null;
|
|
3175
3266
|
const incentivePoolFields = incentivePoolsResponse.data.content.fields;
|
|
3176
3267
|
const veScaBindTableId = incentivePoolFields.ve_sca_bind.fields.id.id;
|
|
@@ -3182,7 +3273,7 @@ var getBindedObligationId = async (query, veScaKeyId) => {
|
|
|
3182
3273
|
value: veScaKeyId
|
|
3183
3274
|
}
|
|
3184
3275
|
});
|
|
3185
|
-
if (veScaBindTableResponse
|
|
3276
|
+
if (veScaBindTableResponse?.data?.content?.dataType !== "moveObject")
|
|
3186
3277
|
return null;
|
|
3187
3278
|
const veScaBindTableFields = veScaBindTableResponse.data.content.fields;
|
|
3188
3279
|
const obligationId = veScaBindTableFields.value.fields.id;
|
|
@@ -3200,7 +3291,7 @@ var getBindedVeScaKey = async (query, obliationId) => {
|
|
|
3200
3291
|
showContent: true
|
|
3201
3292
|
}
|
|
3202
3293
|
);
|
|
3203
|
-
if (incentiveAccountsObject
|
|
3294
|
+
if (incentiveAccountsObject?.data?.content?.dataType !== "moveObject")
|
|
3204
3295
|
return null;
|
|
3205
3296
|
const incentiveAccountsTableId = incentiveAccountsObject.data.content.fields.accounts.fields.id.id;
|
|
3206
3297
|
const bindedIncentiveAcc = await query.cache.queryGetDynamicFieldObject({
|
|
@@ -3210,7 +3301,7 @@ var getBindedVeScaKey = async (query, obliationId) => {
|
|
|
3210
3301
|
value: obliationId
|
|
3211
3302
|
}
|
|
3212
3303
|
});
|
|
3213
|
-
if (bindedIncentiveAcc
|
|
3304
|
+
if (bindedIncentiveAcc?.data?.content?.dataType !== "moveObject")
|
|
3214
3305
|
return null;
|
|
3215
3306
|
const bindedIncentiveAccFields = bindedIncentiveAcc.data.content.fields;
|
|
3216
3307
|
return bindedIncentiveAccFields.value.fields.binded_ve_sca_key?.fields.id ?? null;
|
|
@@ -3221,7 +3312,7 @@ var getPythPrice = async (query, assetCoinName, priceFeedObject) => {
|
|
|
3221
3312
|
const pythFeedObjectId = query.address.get(
|
|
3222
3313
|
`core.coins.${assetCoinName}.oracle.pyth.feedObject`
|
|
3223
3314
|
);
|
|
3224
|
-
priceFeedObject = priceFeedObject || (await query.cache.queryGetObject(pythFeedObjectId, { showContent: true }))
|
|
3315
|
+
priceFeedObject = priceFeedObject || (await query.cache.queryGetObject(pythFeedObjectId, { showContent: true }))?.data;
|
|
3225
3316
|
if (priceFeedObject) {
|
|
3226
3317
|
const priceFeedPoolObject = priceFeedObject;
|
|
3227
3318
|
if (priceFeedPoolObject.content && "fields" in priceFeedPoolObject.content) {
|
|
@@ -3509,7 +3600,7 @@ var getObligationAccount = async (query, obligationId, ownerAddress, indexer = f
|
|
|
3509
3600
|
let totalBorrowedValue = BigNumber4(0);
|
|
3510
3601
|
let totalBorrowedValueWithWeight = BigNumber4(0);
|
|
3511
3602
|
for (const assetCoinName of collateralAssetCoinNames) {
|
|
3512
|
-
const collateral = obligationQuery
|
|
3603
|
+
const collateral = obligationQuery?.collaterals.find((collateral2) => {
|
|
3513
3604
|
const collateralCoinName = query.utils.parseCoinNameFromType(
|
|
3514
3605
|
collateral2.type.name
|
|
3515
3606
|
);
|
|
@@ -3569,7 +3660,7 @@ var getObligationAccount = async (query, obligationId, ownerAddress, indexer = f
|
|
|
3569
3660
|
.../* @__PURE__ */ new Set([...Object.values(market.pools).map((pool) => pool.coinName)])
|
|
3570
3661
|
];
|
|
3571
3662
|
for (const assetCoinName of borrowAssetCoinNames) {
|
|
3572
|
-
const debt = obligationQuery
|
|
3663
|
+
const debt = obligationQuery?.debts.find((debt2) => {
|
|
3573
3664
|
const poolCoinName = query.utils.parseCoinNameFromType(
|
|
3574
3665
|
debt2.type.name
|
|
3575
3666
|
);
|
|
@@ -3829,8 +3920,10 @@ var getVescaKeys = async (query, ownerAddress) => {
|
|
|
3829
3920
|
},
|
|
3830
3921
|
cursor: nextCursor
|
|
3831
3922
|
});
|
|
3923
|
+
if (!paginatedKeyObjectsResponse)
|
|
3924
|
+
continue;
|
|
3832
3925
|
keyObjectsResponse.push(...paginatedKeyObjectsResponse.data);
|
|
3833
|
-
if (paginatedKeyObjectsResponse.hasNextPage && paginatedKeyObjectsResponse.nextCursor) {
|
|
3926
|
+
if (paginatedKeyObjectsResponse && paginatedKeyObjectsResponse.hasNextPage && paginatedKeyObjectsResponse.nextCursor) {
|
|
3834
3927
|
hasNextPage = true;
|
|
3835
3928
|
nextCursor = paginatedKeyObjectsResponse.nextCursor;
|
|
3836
3929
|
} else {
|
|
@@ -3873,6 +3966,8 @@ var getVeSca = async (query, veScaKey, ownerAddress) => {
|
|
|
3873
3966
|
value: typeof veScaKey === "string" ? veScaKey : veScaKey.objectId
|
|
3874
3967
|
}
|
|
3875
3968
|
});
|
|
3969
|
+
if (!veScaDynamicFieldObjectResponse)
|
|
3970
|
+
return void 0;
|
|
3876
3971
|
const veScaDynamicFieldObject = veScaDynamicFieldObjectResponse.data;
|
|
3877
3972
|
if (veScaDynamicFieldObject && veScaDynamicFieldObject.content && veScaDynamicFieldObject.content.dataType === "moveObject" && "fields" in veScaDynamicFieldObject.content) {
|
|
3878
3973
|
const dynamicFields = veScaDynamicFieldObject.content.fields.value.fields;
|
|
@@ -3907,7 +4002,7 @@ var getTotalVeScaTreasuryAmount = async (query, veScaTreasury) => {
|
|
|
3907
4002
|
const resolvedRefreshArgs = await Promise.all(
|
|
3908
4003
|
refreshArgs.map(async (arg) => {
|
|
3909
4004
|
if (typeof arg === "string") {
|
|
3910
|
-
return (await query.cache.queryGetObject(arg, { showContent: true }))
|
|
4005
|
+
return (await query.cache.queryGetObject(arg, { showContent: true }))?.data;
|
|
3911
4006
|
}
|
|
3912
4007
|
return arg;
|
|
3913
4008
|
})
|
|
@@ -3915,7 +4010,7 @@ var getTotalVeScaTreasuryAmount = async (query, veScaTreasury) => {
|
|
|
3915
4010
|
const resolvedVeScaAmountArgs = await Promise.all(
|
|
3916
4011
|
veScaAmountArgs.map(async (arg) => {
|
|
3917
4012
|
if (typeof arg === "string") {
|
|
3918
|
-
return (await query.cache.queryGetObject(arg, { showContent: true }))
|
|
4013
|
+
return (await query.cache.queryGetObject(arg, { showContent: true }))?.data;
|
|
3919
4014
|
}
|
|
3920
4015
|
return arg;
|
|
3921
4016
|
})
|
|
@@ -3926,7 +4021,7 @@ var getTotalVeScaTreasuryAmount = async (query, veScaTreasury) => {
|
|
|
3926
4021
|
const txBytes = await txb.txBlock.build({
|
|
3927
4022
|
client: query.suiKit.client(),
|
|
3928
4023
|
onlyTransactionKind: true,
|
|
3929
|
-
protocolConfig: await query.cache.getProtocolConfig()
|
|
4024
|
+
protocolConfig: await query.cache.getProtocolConfig() ?? void 0
|
|
3930
4025
|
});
|
|
3931
4026
|
const res = await query.cache.queryClient.fetchQuery({
|
|
3932
4027
|
queryKey: [
|
|
@@ -3979,7 +4074,7 @@ var queryVeScaKeyIdFromReferralBindings = async (query, refereeAddress) => {
|
|
|
3979
4074
|
value: refereeAddress
|
|
3980
4075
|
}
|
|
3981
4076
|
});
|
|
3982
|
-
if (referralBindResponse
|
|
4077
|
+
if (referralBindResponse?.data?.content?.dataType !== "moveObject")
|
|
3983
4078
|
return null;
|
|
3984
4079
|
const fields = referralBindResponse.data.content.fields;
|
|
3985
4080
|
return fields.value;
|
|
@@ -4003,7 +4098,7 @@ var getLoyaltyProgramInformations = async (query, veScaKey) => {
|
|
|
4003
4098
|
const rewardPoolObject = await query.cache.queryGetObject(rewardPool, {
|
|
4004
4099
|
showContent: true
|
|
4005
4100
|
});
|
|
4006
|
-
if (rewardPoolObject
|
|
4101
|
+
if (rewardPoolObject?.data?.content?.dataType !== "moveObject")
|
|
4007
4102
|
return null;
|
|
4008
4103
|
const rewardPoolFields = rewardPoolObject.data.content.fields;
|
|
4009
4104
|
const { isClaimEnabled, totalPoolReward } = rewardPoolFieldsZod.parse(
|
|
@@ -4027,7 +4122,7 @@ var getLoyaltyProgramInformations = async (query, veScaKey) => {
|
|
|
4027
4122
|
value: typeof veScaKey === "string" ? veScaKey : veScaKey.objectId
|
|
4028
4123
|
}
|
|
4029
4124
|
});
|
|
4030
|
-
if (userRewardObject
|
|
4125
|
+
if (userRewardObject?.data?.content?.dataType !== "moveObject")
|
|
4031
4126
|
return result;
|
|
4032
4127
|
const userRewardFields = userRewardObject.data.content.fields;
|
|
4033
4128
|
result.pendingReward = userRewardFieldsZod.parse(
|
|
@@ -4221,7 +4316,7 @@ var getSCoinTotalSupply = async (query, sCoinName) => {
|
|
|
4221
4316
|
args,
|
|
4222
4317
|
typeArgs
|
|
4223
4318
|
});
|
|
4224
|
-
const results = queryResults
|
|
4319
|
+
const results = queryResults?.results;
|
|
4225
4320
|
if (results && results[0].returnValues) {
|
|
4226
4321
|
const value = Uint8Array.from(results[0].returnValues[0][0]);
|
|
4227
4322
|
const type = results[0].returnValues[0][1];
|
|
@@ -4951,6 +5046,26 @@ var ScallopUtils = class {
|
|
|
4951
5046
|
);
|
|
4952
5047
|
return coins;
|
|
4953
5048
|
}
|
|
5049
|
+
/**
|
|
5050
|
+
* Merge coins with type `coinType` to dest
|
|
5051
|
+
* @param txBlock
|
|
5052
|
+
* @param dest
|
|
5053
|
+
* @param coinType
|
|
5054
|
+
* @param sender
|
|
5055
|
+
*/
|
|
5056
|
+
async mergeSimilarCoins(txBlock, dest, coinType, sender) {
|
|
5057
|
+
try {
|
|
5058
|
+
const existingSCoin = await this.selectCoins(
|
|
5059
|
+
Number.MAX_SAFE_INTEGER,
|
|
5060
|
+
coinType,
|
|
5061
|
+
sender
|
|
5062
|
+
);
|
|
5063
|
+
if (existingSCoin.length > 0) {
|
|
5064
|
+
txBlock.mergeCoins(dest, existingSCoin);
|
|
5065
|
+
}
|
|
5066
|
+
} catch (e) {
|
|
5067
|
+
}
|
|
5068
|
+
}
|
|
4954
5069
|
/**
|
|
4955
5070
|
* Get all asset coin names in the obligation record by obligation id.
|
|
4956
5071
|
*
|
|
@@ -4963,12 +5078,12 @@ var ScallopUtils = class {
|
|
|
4963
5078
|
*/
|
|
4964
5079
|
async getObligationCoinNames(obligationId) {
|
|
4965
5080
|
const obligation = await queryObligation(this._query, obligationId);
|
|
4966
|
-
const collateralCoinTypes = obligation
|
|
5081
|
+
const collateralCoinTypes = obligation?.collaterals.map((collateral) => {
|
|
4967
5082
|
return `0x${collateral.type.name}`;
|
|
4968
|
-
});
|
|
4969
|
-
const debtCoinTypes = obligation
|
|
5083
|
+
}) ?? [];
|
|
5084
|
+
const debtCoinTypes = obligation?.debts.map((debt) => {
|
|
4970
5085
|
return `0x${debt.type.name}`;
|
|
4971
|
-
});
|
|
5086
|
+
}) ?? [];
|
|
4972
5087
|
const obligationCoinTypes = [
|
|
4973
5088
|
.../* @__PURE__ */ new Set([...collateralCoinTypes, ...debtCoinTypes])
|
|
4974
5089
|
];
|
|
@@ -5838,7 +5953,7 @@ var generateSpoolQuickMethod = ({
|
|
|
5838
5953
|
toTransfer.push(marketCoin);
|
|
5839
5954
|
}
|
|
5840
5955
|
amount -= amountToUnstake;
|
|
5841
|
-
if (amount
|
|
5956
|
+
if (amount <= 0)
|
|
5842
5957
|
break;
|
|
5843
5958
|
}
|
|
5844
5959
|
if (toTransfer.length > 0) {
|
|
@@ -5846,31 +5961,6 @@ var generateSpoolQuickMethod = ({
|
|
|
5846
5961
|
if (toTransfer.length > 1) {
|
|
5847
5962
|
txBlock.mergeCoins(mergedCoin, toTransfer.slice(1));
|
|
5848
5963
|
}
|
|
5849
|
-
if (returnSCoin) {
|
|
5850
|
-
try {
|
|
5851
|
-
const existingCoins = await builder.utils.selectCoins(
|
|
5852
|
-
Number.MAX_SAFE_INTEGER,
|
|
5853
|
-
builder.utils.parseSCoinType(stakeMarketCoinName),
|
|
5854
|
-
requireSender(txBlock)
|
|
5855
|
-
);
|
|
5856
|
-
if (existingCoins.length > 0) {
|
|
5857
|
-
txBlock.mergeCoins(mergedCoin, existingCoins);
|
|
5858
|
-
}
|
|
5859
|
-
} catch (e) {
|
|
5860
|
-
}
|
|
5861
|
-
} else {
|
|
5862
|
-
try {
|
|
5863
|
-
const existingCoins = await builder.utils.selectCoins(
|
|
5864
|
-
Number.MAX_SAFE_INTEGER,
|
|
5865
|
-
builder.utils.parseMarketCoinType(stakeMarketCoinName),
|
|
5866
|
-
requireSender(txBlock)
|
|
5867
|
-
);
|
|
5868
|
-
if (existingCoins.length > 0) {
|
|
5869
|
-
txBlock.mergeCoins(mergedCoin, existingCoins);
|
|
5870
|
-
}
|
|
5871
|
-
} catch (e) {
|
|
5872
|
-
}
|
|
5873
|
-
}
|
|
5874
5964
|
return mergedCoin;
|
|
5875
5965
|
}
|
|
5876
5966
|
},
|
|
@@ -6607,17 +6697,12 @@ var generateLoyaltyProgramQuickMethod = ({
|
|
|
6607
6697
|
throw new Error(`No veScaKey found for user ${sender}`);
|
|
6608
6698
|
const toTransferObject = [];
|
|
6609
6699
|
const rewardCoin = txBlock.claimLoyaltyRevenue(veScaKey);
|
|
6610
|
-
|
|
6611
|
-
|
|
6612
|
-
|
|
6613
|
-
|
|
6614
|
-
|
|
6615
|
-
|
|
6616
|
-
txBlock.mergeCoins(rewardCoin, existingScaCoin);
|
|
6617
|
-
} catch (e) {
|
|
6618
|
-
} finally {
|
|
6619
|
-
toTransferObject.push(rewardCoin);
|
|
6620
|
-
}
|
|
6700
|
+
await builder.utils.mergeSimilarCoins(
|
|
6701
|
+
txBlock,
|
|
6702
|
+
rewardCoin,
|
|
6703
|
+
coinIds.sca,
|
|
6704
|
+
requireSender(txBlock)
|
|
6705
|
+
);
|
|
6621
6706
|
if (toTransferObject.length > 0) {
|
|
6622
6707
|
txBlock.transferObjects(toTransferObject, sender);
|
|
6623
6708
|
}
|
|
@@ -7287,6 +7372,14 @@ var ScallopClient = class {
|
|
|
7287
7372
|
stakeMarketCoinName,
|
|
7288
7373
|
stakeAccountId
|
|
7289
7374
|
);
|
|
7375
|
+
if (sCoin) {
|
|
7376
|
+
await this.utils.mergeSimilarCoins(
|
|
7377
|
+
txBlock,
|
|
7378
|
+
sCoin,
|
|
7379
|
+
this.utils.parseSCoinType(stakeMarketCoinName),
|
|
7380
|
+
requireSender(txBlock)
|
|
7381
|
+
);
|
|
7382
|
+
}
|
|
7290
7383
|
txBlock.transferObjects([sCoin], sender);
|
|
7291
7384
|
if (sign) {
|
|
7292
7385
|
return await this.suiKit.signAndSendTxn(
|
|
@@ -7309,6 +7402,12 @@ var ScallopClient = class {
|
|
|
7309
7402
|
const stakeCoinName = this.utils.parseCoinName(stakeMarketCoinName);
|
|
7310
7403
|
if (stakeMarketCoin) {
|
|
7311
7404
|
const coin = txBlock.withdraw(stakeMarketCoin, stakeCoinName);
|
|
7405
|
+
await this.utils.mergeSimilarCoins(
|
|
7406
|
+
txBlock,
|
|
7407
|
+
coin,
|
|
7408
|
+
this.utils.parseCoinType(this.utils.parseCoinName(stakeCoinName)),
|
|
7409
|
+
requireSender(txBlock)
|
|
7410
|
+
);
|
|
7312
7411
|
txBlock.transferObjects([coin], sender);
|
|
7313
7412
|
} else {
|
|
7314
7413
|
throw new Error(`No stake found for ${stakeMarketCoinName}`);
|
|
@@ -7449,15 +7548,12 @@ var ScallopClient = class {
|
|
|
7449
7548
|
sCoinName,
|
|
7450
7549
|
toDestroyMarketCoin
|
|
7451
7550
|
);
|
|
7452
|
-
|
|
7453
|
-
|
|
7454
|
-
|
|
7455
|
-
|
|
7456
|
-
|
|
7457
|
-
|
|
7458
|
-
txBlock.mergeCoins(sCoin, existSCoins);
|
|
7459
|
-
} catch (e) {
|
|
7460
|
-
}
|
|
7551
|
+
await this.utils.mergeSimilarCoins(
|
|
7552
|
+
txBlock,
|
|
7553
|
+
sCoin,
|
|
7554
|
+
this.utils.parseSCoinType(sCoinName),
|
|
7555
|
+
requireSender(txBlock)
|
|
7556
|
+
);
|
|
7461
7557
|
sCoins2.push(sCoin);
|
|
7462
7558
|
}
|
|
7463
7559
|
if (SUPPORT_SPOOLS.includes(sCoinName)) {
|
|
@@ -7516,12 +7612,13 @@ var ScallopClient = class {
|
|
|
7516
7612
|
|
|
7517
7613
|
// src/models/scallop.ts
|
|
7518
7614
|
var Scallop = class {
|
|
7519
|
-
constructor(params, cacheOptions) {
|
|
7615
|
+
constructor(params, cacheOptions, tokenBucket) {
|
|
7520
7616
|
this.params = params;
|
|
7521
7617
|
this.suiKit = new SuiKit5(params);
|
|
7522
7618
|
this.cache = new ScallopCache(
|
|
7523
7619
|
cacheOptions ?? DEFAULT_CACHE_OPTIONS,
|
|
7524
|
-
this.suiKit
|
|
7620
|
+
this.suiKit,
|
|
7621
|
+
tokenBucket ?? new TokenBucket(DEFAULT_TOKENS_PER_INTERVAL, DEFAULT_INTERVAL_IN_MS)
|
|
7525
7622
|
);
|
|
7526
7623
|
this._address = new ScallopAddress(
|
|
7527
7624
|
{
|