@scallop-io/sui-scallop-sdk 2.3.0-lst-x-oracle-alpha.8 → 2.3.0

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.
Files changed (73) hide show
  1. package/dist/index.d.mts +1811 -1750
  2. package/dist/index.d.ts +1811 -1750
  3. package/dist/index.js +49 -2
  4. package/dist/index.mjs +15 -2
  5. package/package.json +8 -5
  6. package/src/builders/borrowIncentiveBuilder.ts +4 -4
  7. package/src/builders/coreBuilder.ts +86 -59
  8. package/src/builders/index.ts +2 -2
  9. package/src/builders/loyaltyProgramBuilder.ts +2 -2
  10. package/src/builders/oracles/index.ts +365 -114
  11. package/src/builders/oracles/pyth.ts +135 -0
  12. package/src/builders/referralBuilder.ts +4 -10
  13. package/src/builders/sCoinBuilder.ts +2 -6
  14. package/src/builders/spoolBuilder.ts +2 -2
  15. package/src/builders/vescaBuilder.ts +5 -5
  16. package/src/constants/common.ts +3 -0
  17. package/src/constants/index.ts +1 -1
  18. package/src/constants/queryKeys.ts +1 -1
  19. package/src/constants/testAddress.ts +95 -183
  20. package/src/constants/xoracle.ts +2 -8
  21. package/src/index.ts +1 -1
  22. package/src/models/index.ts +1 -2
  23. package/src/models/interface.ts +6 -6
  24. package/src/models/rateLimiter.ts +55 -0
  25. package/src/models/scallop.ts +1 -1
  26. package/src/models/scallopAddress.ts +5 -25
  27. package/src/models/scallopBuilder.ts +14 -11
  28. package/src/models/scallopClient.ts +31 -14
  29. package/src/models/scallopConstants.ts +3 -3
  30. package/src/models/scallopIndexer.ts +3 -4
  31. package/src/models/scallopQuery.ts +112 -56
  32. package/src/models/scallopQueryClient.ts +1 -1
  33. package/src/models/scallopSuiKit.ts +1 -1
  34. package/src/models/scallopUtils.ts +12 -7
  35. package/src/queries/borrowIncentiveQuery.ts +4 -3
  36. package/src/queries/coreQuery.ts +114 -186
  37. package/src/queries/index.ts +3 -4
  38. package/src/queries/loyaltyProgramQuery.ts +2 -2
  39. package/src/queries/ownerQuery.ts +32 -0
  40. package/src/queries/poolAddressesQuery.ts +1 -3
  41. package/src/queries/portfolioQuery.ts +68 -16
  42. package/src/queries/priceQuery.ts +2 -3
  43. package/src/queries/sCoinQuery.ts +2 -2
  44. package/src/queries/spoolQuery.ts +57 -74
  45. package/src/queries/vescaQuery.ts +3 -3
  46. package/src/queries/xOracleQuery.ts +4 -21
  47. package/src/types/address.ts +47 -85
  48. package/src/types/builder/core.ts +40 -15
  49. package/src/types/builder/index.ts +17 -1
  50. package/src/types/constant/enum.ts +64 -0
  51. package/src/types/constant/index.ts +1 -2
  52. package/src/types/constant/xOracle.ts +7 -10
  53. package/src/types/index.ts +1 -1
  54. package/src/types/query/core.ts +3 -0
  55. package/src/types/query/index.ts +1 -0
  56. package/src/types/query/sCoin.ts +1 -0
  57. package/src/{builders/utils.ts → utils/builder.ts} +1 -1
  58. package/src/utils/core.ts +18 -0
  59. package/src/utils/index.ts +5 -0
  60. package/src/utils/indexer.ts +47 -0
  61. package/src/{queries/utils.ts → utils/query.ts} +7 -25
  62. package/src/utils/util.ts +42 -0
  63. package/src/builders/oracles/error.ts +0 -29
  64. package/src/builders/oracles/oraclePackageRegistry.ts +0 -322
  65. package/src/builders/oracles/priceFeedUpdater.ts +0 -112
  66. package/src/builders/oracles/priceUpdateRequester.ts +0 -50
  67. package/src/builders/oracles/xOracleUpdateStrategy.ts +0 -178
  68. package/src/builders/oracles/xOracleUpdater.ts +0 -160
  69. package/src/constants/api.ts +0 -2
  70. package/src/models/utils.ts +0 -97
  71. package/src/types/builder/type.ts +0 -25
  72. package/src/types/constant/package.ts +0 -16
  73. /package/src/types/{util.ts → utils.ts} +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scallop-io/sui-scallop-sdk",
3
- "version": "2.3.0-lst-x-oracle-alpha.8",
3
+ "version": "2.3.0",
4
4
  "description": "Typescript sdk for interacting with Scallop contract on SUI",
5
5
  "keywords": [
6
6
  "sui",
@@ -39,7 +39,7 @@
39
39
  ],
40
40
  "dependencies": {
41
41
  "@mysten/sui": "1.28.2",
42
- "@pythnetwork/pyth-sui-js": "2.1.0",
42
+ "@pythnetwork/pyth-sui-js": "2.2.0",
43
43
  "@scallop-io/sui-kit": "1.4.1",
44
44
  "@tanstack/query-core": "5.59.16",
45
45
  "axios": "^1.9.0",
@@ -70,7 +70,7 @@
70
70
  "prettier": "^3.0.3",
71
71
  "standard-version": "^9.5.0",
72
72
  "tsconfig-paths": "^4.2.0",
73
- "tsup": "^8.5.0",
73
+ "tsup": "^7.2.0",
74
74
  "typedoc": "^0.26.3",
75
75
  "typescript": "5.5.4",
76
76
  "valibot": "^1.1.0",
@@ -145,8 +145,11 @@
145
145
  },
146
146
  "scripts": {
147
147
  "clean": "rm -rf tsconfig.tsbuildinfo ./dist",
148
- "build": "pnpm run clean && pnpm run build:tsup",
149
- "build:tsup": "tsup ./src/index.ts --format esm,cjs --dts --splitting --minify --treeshake",
148
+ "build": "pnpm run build:tsup",
149
+ "build:sourcemap": "tsup ./src/index.ts --format esm,cjs --sourcemap --dts",
150
+ "build:tsup": "tsup ./src/index.ts --format esm,cjs --splitting --minify --treeshake --dts",
151
+ "watch:tsup": "tsup ./src/index.ts --format esm,cjs --clean --splitting --watch",
152
+ "watch:types": "tsc --watch",
150
153
  "watch": "pnpm run clean & pnpm run watch:types & pnpm run watch:tsup",
151
154
  "test": "pnpm test:typecheck && pnpm test:unit",
152
155
  "test:typecheck": "tsc -p ./test",
@@ -3,7 +3,8 @@ import {
3
3
  SuiTxBlock as SuiKitTxBlock,
4
4
  SUI_CLOCK_OBJECT_ID,
5
5
  } from '@scallop-io/sui-kit';
6
- import { requireSender } from './utils';
6
+ import { getObligations, getObligationLocked } from 'src/queries';
7
+ import { requireSender } from 'src/utils';
7
8
  import type { SuiObjectArg } from '@scallop-io/sui-kit';
8
9
  import type { ScallopBuilder } from 'src/models';
9
10
  import type {
@@ -13,9 +14,8 @@ import type {
13
14
  SuiTxBlockWithBorrowIncentiveNormalMethods,
14
15
  BorrowIncentiveTxBlock,
15
16
  ScallopTxBlock,
16
- } from 'src/types/builder';
17
- import { OLD_BORROW_INCENTIVE_PROTOCOL_ID } from 'src/constants/common';
18
- import { getObligationLocked, getObligations } from 'src/queries/coreQuery';
17
+ } from 'src/types';
18
+ import { OLD_BORROW_INCENTIVE_PROTOCOL_ID } from 'src/constants';
19
19
 
20
20
  /**
21
21
  * Check and get Obligation information from transaction block.
@@ -1,10 +1,10 @@
1
1
  import { Transaction } from '@mysten/sui/transactions';
2
2
  import { SUI_CLOCK_OBJECT_ID } from '@mysten/sui/utils';
3
3
  import { SuiTxBlock as SuiKitTxBlock } from '@scallop-io/sui-kit';
4
- import { getObligations } from 'src/queries/coreQuery';
4
+ import { getObligations } from '../queries';
5
5
  import { updateOracles } from './oracles';
6
- import { requireSender } from './utils';
7
- import type { SuiObjectArg, TransactionResult } from '@scallop-io/sui-kit';
6
+ import { requireSender } from '../utils';
7
+ import type { SuiObjectArg } from '@scallop-io/sui-kit';
8
8
  import type { ScallopBuilder } from 'src/models';
9
9
  import type {
10
10
  CoreIds,
@@ -15,7 +15,7 @@ import type {
15
15
  ScallopTxBlock,
16
16
  NestedResult,
17
17
  SuiTxBlockWithSpool,
18
- } from 'src/types/builder';
18
+ } from 'src/types';
19
19
 
20
20
  /**
21
21
  * Check and get Obligation information from transaction block.
@@ -287,7 +287,12 @@ const generateCoreQuickMethod: GenerateCoreQuickMethod = ({
287
287
  txBlock,
288
288
  }) => {
289
289
  return {
290
- addCollateralQuick: async (amount, collateralCoinName, obligationId) => {
290
+ addCollateralQuick: async (
291
+ amount,
292
+ collateralCoinName,
293
+ obligationId,
294
+ isSponsoredTx = false
295
+ ) => {
291
296
  const sender = requireSender(txBlock);
292
297
  const { obligationId: obligationArg } = await requireObligationInfo(
293
298
  builder,
@@ -295,25 +300,25 @@ const generateCoreQuickMethod: GenerateCoreQuickMethod = ({
295
300
  obligationId
296
301
  );
297
302
 
298
- if (collateralCoinName === 'sui') {
299
- const [suiCoin] = txBlock.splitSUIFromGas([amount]);
300
- txBlock.addCollateral(obligationArg, suiCoin, collateralCoinName);
301
- } else {
302
- const { leftCoin, takeCoin } = await builder.selectCoin(
303
- txBlock,
304
- collateralCoinName,
305
- amount,
306
- sender
307
- );
308
- txBlock.addCollateral(obligationArg, takeCoin, collateralCoinName);
303
+ const { takeCoin, leftCoin } = await builder.selectCoin(
304
+ txBlock,
305
+ collateralCoinName,
306
+ amount,
307
+ sender,
308
+ isSponsoredTx
309
+ );
310
+
311
+ if (leftCoin) {
309
312
  txBlock.transferObjects([leftCoin], sender);
310
313
  }
314
+ txBlock.addCollateral(obligationArg, takeCoin, collateralCoinName);
311
315
  },
312
316
  takeCollateralQuick: async (
313
317
  amount,
314
318
  collateralCoinName,
315
319
  obligationId,
316
- obligationKey
320
+ obligationKey,
321
+ updateOracleOptions
317
322
  ) => {
318
323
  const obligationInfo = await requireObligationInfo(
319
324
  builder,
@@ -324,7 +329,12 @@ const generateCoreQuickMethod: GenerateCoreQuickMethod = ({
324
329
  const updateCoinNames = await builder.utils.getObligationCoinNames(
325
330
  obligationInfo.obligationId
326
331
  );
327
- await updateOracles(builder, txBlock, updateCoinNames);
332
+ await updateOracles(
333
+ builder,
334
+ txBlock,
335
+ updateCoinNames,
336
+ updateOracleOptions
337
+ );
328
338
  return txBlock.takeCollateral(
329
339
  obligationInfo.obligationId,
330
340
  obligationInfo.obligationKey as SuiObjectArg,
@@ -332,22 +342,24 @@ const generateCoreQuickMethod: GenerateCoreQuickMethod = ({
332
342
  collateralCoinName
333
343
  );
334
344
  },
335
- depositQuick: async (amount, poolCoinName, returnSCoin = true) => {
345
+ depositQuick: async (
346
+ amount,
347
+ poolCoinName,
348
+ returnSCoin = true,
349
+ isSponsoredTx = false
350
+ ) => {
336
351
  const sender = requireSender(txBlock);
337
- let marketCoinDeposit: TransactionResult | undefined;
338
- if (poolCoinName === 'sui') {
339
- const [suiCoin] = txBlock.splitSUIFromGas([amount]);
340
- marketCoinDeposit = txBlock.deposit(suiCoin, poolCoinName);
341
- } else {
342
- const { leftCoin, takeCoin } = await builder.selectCoin(
343
- txBlock,
344
- poolCoinName,
345
- amount,
346
- sender
347
- );
352
+ const { leftCoin, takeCoin } = await builder.selectCoin(
353
+ txBlock,
354
+ poolCoinName,
355
+ amount,
356
+ sender,
357
+ isSponsoredTx
358
+ );
359
+ if (leftCoin) {
348
360
  txBlock.transferObjects([leftCoin], sender);
349
- marketCoinDeposit = txBlock.deposit(takeCoin, poolCoinName);
350
361
  }
362
+ const marketCoinDeposit = txBlock.deposit(takeCoin, poolCoinName);
351
363
 
352
364
  // convert to sCoin
353
365
  return returnSCoin
@@ -382,7 +394,13 @@ const generateCoreQuickMethod: GenerateCoreQuickMethod = ({
382
394
  if (!marketCoin) throw new Error(`No market coin for ${poolCoinName}`);
383
395
  return txBlock.withdraw(marketCoin, poolCoinName);
384
396
  },
385
- borrowQuick: async (amount, poolCoinName, obligationId, obligationKey) => {
397
+ borrowQuick: async (
398
+ amount,
399
+ poolCoinName,
400
+ obligationId,
401
+ obligationKey,
402
+ updateOracleOptions
403
+ ) => {
386
404
  const obligationInfo = await requireObligationInfo(
387
405
  builder,
388
406
  txBlock,
@@ -394,7 +412,12 @@ const generateCoreQuickMethod: GenerateCoreQuickMethod = ({
394
412
  obligationInfo.obligationId
395
413
  )) ?? [];
396
414
  const updateCoinNames = [...obligationCoinNames, poolCoinName];
397
- await updateOracles(builder, txBlock, updateCoinNames);
415
+ await updateOracles(
416
+ builder,
417
+ txBlock,
418
+ updateCoinNames,
419
+ updateOracleOptions
420
+ );
398
421
  return txBlock.borrow(
399
422
  obligationInfo.obligationId,
400
423
  obligationInfo.obligationKey as SuiObjectArg,
@@ -407,7 +430,8 @@ const generateCoreQuickMethod: GenerateCoreQuickMethod = ({
407
430
  poolCoinName,
408
431
  borrowReferral,
409
432
  obligationId,
410
- obligationKey
433
+ obligationKey,
434
+ updateOracleOptions
411
435
  ) => {
412
436
  const obligationInfo = await requireObligationInfo(
413
437
  builder,
@@ -420,7 +444,12 @@ const generateCoreQuickMethod: GenerateCoreQuickMethod = ({
420
444
  obligationInfo.obligationId
421
445
  )) ?? [];
422
446
  const updateCoinNames = [...obligationCoinNames, poolCoinName];
423
- await updateOracles(builder, txBlock, updateCoinNames);
447
+ await updateOracles(
448
+ builder,
449
+ txBlock,
450
+ updateCoinNames,
451
+ updateOracleOptions
452
+ );
424
453
  return txBlock.borrowWithReferral(
425
454
  obligationInfo.obligationId,
426
455
  obligationInfo.obligationKey as SuiObjectArg,
@@ -429,7 +458,12 @@ const generateCoreQuickMethod: GenerateCoreQuickMethod = ({
429
458
  poolCoinName
430
459
  );
431
460
  },
432
- repayQuick: async (amount, poolCoinName, obligationId) => {
461
+ repayQuick: async (
462
+ amount,
463
+ poolCoinName,
464
+ obligationId,
465
+ isSponsoredTx = false
466
+ ) => {
433
467
  const sender = requireSender(txBlock);
434
468
  const obligationInfo = await requireObligationInfo(
435
469
  builder,
@@ -437,30 +471,23 @@ const generateCoreQuickMethod: GenerateCoreQuickMethod = ({
437
471
  obligationId
438
472
  );
439
473
 
440
- if (poolCoinName === 'sui') {
441
- const [suiCoin] = txBlock.splitSUIFromGas([amount]);
442
- return txBlock.repay(
443
- obligationInfo.obligationId,
444
- suiCoin,
445
- poolCoinName
446
- );
447
- } else {
448
- const { leftCoin, takeCoin } = await builder.selectCoin(
449
- txBlock,
450
- poolCoinName,
451
- amount,
452
- sender
453
- );
454
- txBlock.transferObjects([leftCoin], sender);
455
- return txBlock.repay(
456
- obligationInfo.obligationId,
457
- takeCoin,
458
- poolCoinName
459
- );
460
- }
474
+ const { leftCoin, takeCoin } = await builder.selectCoin(
475
+ txBlock,
476
+ poolCoinName,
477
+ amount,
478
+ sender,
479
+ isSponsoredTx
480
+ );
481
+ if (leftCoin) txBlock.transferObjects([leftCoin], sender);
482
+ return txBlock.repay(obligationInfo.obligationId, takeCoin, poolCoinName);
461
483
  },
462
- updateAssetPricesQuick: async (assetCoinNames) => {
463
- return await updateOracles(builder, txBlock, assetCoinNames);
484
+ updateAssetPricesQuick: async (assetCoinNames, updateOracleOptions) => {
485
+ return await updateOracles(
486
+ builder,
487
+ txBlock,
488
+ assetCoinNames,
489
+ updateOracleOptions
490
+ );
464
491
  },
465
492
  };
466
493
  };
@@ -4,11 +4,11 @@ import { newCoreTxBlock } from './coreBuilder';
4
4
  import { newSpoolTxBlock } from './spoolBuilder';
5
5
  import { newBorrowIncentiveTxBlock } from './borrowIncentiveBuilder';
6
6
  import { newVeScaTxBlock } from './vescaBuilder';
7
+ import type { ScallopBuilder } from 'src/models';
8
+ import type { ScallopTxBlock } from 'src/types';
7
9
  import { newReferralTxBlock } from './referralBuilder';
8
10
  import { newLoyaltyProgramTxBlock } from './loyaltyProgramBuilder';
9
11
  import { newSCoinTxBlock } from './sCoinBuilder';
10
- import { ScallopTxBlock } from 'src/types/builder';
11
- import type { ScallopBuilder } from 'src/models';
12
12
 
13
13
  /**
14
14
  * Create a new ScallopTxBlock instance.
@@ -7,8 +7,8 @@ import {
7
7
  LoyaltyProgramTxBlock,
8
8
  ScallopTxBlock,
9
9
  SuiTxBlockWithLoyaltyProgramNormalMethods,
10
- } from 'src/types/builder';
11
- import { requireSender } from './utils';
10
+ } from 'src/types';
11
+ import { requireSender } from 'src/utils';
12
12
 
13
13
  const generateLoyaltyProgramNormalMethod: GenerateLoyaltyProgramNormalMethod =
14
14
  ({ builder, txBlock }) => {