@scallop-io/sui-scallop-sdk 0.47.6 → 1.3.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/dist/builders/borrowIncentiveBuilder.d.ts +2 -2
  2. package/dist/builders/coreBuilder.d.ts +2 -2
  3. package/dist/builders/index.d.ts +2 -2
  4. package/dist/builders/loyaltyProgramBuilder.d.ts +2 -2
  5. package/dist/builders/referralBuilder.d.ts +2 -2
  6. package/dist/builders/sCoinBuilder.d.ts +2 -2
  7. package/dist/builders/spoolBuilder.d.ts +2 -2
  8. package/dist/builders/vescaBuilder.d.ts +2 -2
  9. package/dist/constants/common.d.ts +4 -4
  10. package/dist/constants/index.d.ts +1 -1
  11. package/dist/constants/vesca.d.ts +3 -3
  12. package/dist/index.js +149 -83
  13. package/dist/index.js.map +1 -1
  14. package/dist/index.mjs +152 -89
  15. package/dist/index.mjs.map +1 -1
  16. package/dist/models/scallopBuilder.d.ts +6 -4
  17. package/dist/models/scallopCache.d.ts +5 -9
  18. package/dist/models/scallopClient.d.ts +2 -2
  19. package/dist/models/scallopQuery.d.ts +1 -1
  20. package/dist/models/scallopUtils.d.ts +2 -2
  21. package/dist/queries/coreQuery.d.ts +3 -3
  22. package/dist/queries/loyaltyProgramQuery.d.ts +1 -1
  23. package/dist/queries/priceQuery.d.ts +1 -1
  24. package/dist/queries/vescaQuery.d.ts +1 -1
  25. package/dist/test.d.ts +1 -0
  26. package/dist/types/builder/borrowIncentive.d.ts +1 -1
  27. package/dist/types/builder/core.d.ts +16 -16
  28. package/dist/types/builder/spool.d.ts +3 -3
  29. package/dist/types/builder/vesca.d.ts +5 -5
  30. package/dist/types/model.d.ts +6 -6
  31. package/dist/types/query/vesca.d.ts +1 -1
  32. package/dist/utils/index.d.ts +1 -0
  33. package/dist/utils/indexer.d.ts +17 -0
  34. package/dist/utils/query.d.ts +1 -1
  35. package/dist/utils/util.d.ts +4 -3
  36. package/package.json +15 -11
  37. package/src/builders/borrowIncentiveBuilder.ts +6 -6
  38. package/src/builders/coreBuilder.ts +17 -17
  39. package/src/builders/index.ts +2 -2
  40. package/src/builders/loyaltyProgramBuilder.ts +5 -5
  41. package/src/builders/oracle.ts +5 -4
  42. package/src/builders/referralBuilder.ts +7 -7
  43. package/src/builders/sCoinBuilder.ts +5 -8
  44. package/src/builders/spoolBuilder.ts +10 -10
  45. package/src/builders/vescaBuilder.ts +5 -5
  46. package/src/constants/common.ts +4 -4
  47. package/src/constants/index.ts +1 -1
  48. package/src/constants/vesca.ts +5 -6
  49. package/src/models/scallopBuilder.ts +15 -7
  50. package/src/models/scallopCache.ts +43 -34
  51. package/src/models/scallopClient.ts +10 -9
  52. package/src/models/scallopQuery.ts +36 -2
  53. package/src/models/scallopUtils.ts +5 -4
  54. package/src/queries/borrowIncentiveQuery.ts +1 -1
  55. package/src/queries/coreQuery.ts +4 -4
  56. package/src/queries/loyaltyProgramQuery.ts +1 -1
  57. package/src/queries/priceQuery.ts +1 -1
  58. package/src/queries/sCoinQuery.ts +2 -2
  59. package/src/queries/spoolQuery.ts +4 -5
  60. package/src/queries/vescaQuery.ts +6 -3
  61. package/src/test.ts +26 -0
  62. package/src/types/address.ts +26 -26
  63. package/src/types/builder/borrowIncentive.ts +1 -1
  64. package/src/types/builder/core.ts +26 -28
  65. package/src/types/builder/spool.ts +2 -3
  66. package/src/types/builder/vesca.ts +5 -9
  67. package/src/types/model.ts +6 -9
  68. package/src/types/query/vesca.ts +1 -1
  69. package/src/utils/index.ts +1 -0
  70. package/src/utils/indexer.ts +39 -0
  71. package/src/utils/query.ts +1 -1
@@ -1,4 +1,4 @@
1
- import { normalizeStructTag } from '@mysten/sui.js/utils';
1
+ import { normalizeStructTag } from '@mysten/sui/utils';
2
2
  import { SUPPORT_SPOOLS } from '../constants';
3
3
  import {
4
4
  parseOriginSpoolData,
@@ -7,7 +7,7 @@ import {
7
7
  calculateSpoolRewardPoolData,
8
8
  isMarketCoin,
9
9
  } from '../utils';
10
- import type { SuiObjectResponse } from '@mysten/sui.js/client';
10
+ import type { SuiObjectResponse } from '@mysten/sui/client';
11
11
  import type { ScallopQuery, ScallopUtils } from '../models';
12
12
  import type {
13
13
  MarketPool,
@@ -287,9 +287,8 @@ export const getStakeAccounts = async (
287
287
  utils.parseCoinName<SupportStakeCoins>(stakeMarketCoinName);
288
288
  const marketCoinType = utils.parseMarketCoinType(stakeCoinName);
289
289
 
290
- types[
291
- stakeMarketCoinName as SupportStakeMarketCoins
292
- ] = `${spoolObjectId}::spool_account::SpoolAccount<${marketCoinType}>`;
290
+ types[stakeMarketCoinName as SupportStakeMarketCoins] =
291
+ `${spoolObjectId}::spool_account::SpoolAccount<${marketCoinType}>`;
293
292
  return types;
294
293
  },
295
294
  {} as Record<SupportStakeMarketCoins, string>
@@ -4,12 +4,13 @@ import {
4
4
  type SuiObjectResponse,
5
5
  type SuiObjectData,
6
6
  DevInspectResults,
7
- } from '@mysten/sui.js/client';
7
+ } from '@mysten/sui/client';
8
8
  import type { ScallopUtils } from '../models';
9
9
  import { MAX_LOCK_DURATION } from 'src/constants';
10
10
  import { SUI_CLOCK_OBJECT_ID, SuiTxBlock } from '@scallop-io/sui-kit';
11
- import { bcs } from '@mysten/sui.js/bcs';
11
+ import { bcs } from '@mysten/sui/bcs';
12
12
  import { z as zod } from 'zod';
13
+ import assert from 'assert';
13
14
  /**
14
15
  * Query all owned veSca key.
15
16
  *
@@ -213,6 +214,7 @@ const getTotalVeScaTreasuryAmount = async (
213
214
  );
214
215
 
215
216
  const txb = new SuiTxBlock();
217
+
216
218
  // refresh first
217
219
  txb.moveCall(refreshQueryTarget, resolvedRefreshArgs);
218
220
  txb.moveCall(veScaAmountQueryTarget, resolvedVeScaAmountArgs);
@@ -237,7 +239,8 @@ const getTotalVeScaTreasuryAmount = async (
237
239
  if (results && results[1].returnValues) {
238
240
  const value = Uint8Array.from(results[1].returnValues[0][0]);
239
241
  const type = results[1].returnValues[0][1];
240
- return bcs.de(type, value);
242
+ assert(type === 'u64', 'Result type is not u64');
243
+ return bcs.u64().parse(value);
241
244
  }
242
245
 
243
246
  return '0';
package/src/test.ts ADDED
@@ -0,0 +1,26 @@
1
+ import { ScallopQuery } from './models';
2
+
3
+ const query = new ScallopQuery({
4
+ walletAddress:
5
+ '0xe78704e7c188b1902dbb630dc4c3ef7f46740c8cf121e38b3438ac1daea09f2d',
6
+ });
7
+
8
+ const main = async () => {
9
+ try {
10
+ await query.init();
11
+ const result = await query.suiKit.client().getObject({
12
+ id: '0xaa72bd551b25715b8f9d72f226fa02526bdf2e085a86faec7184230c5209bb6e',
13
+ options: {
14
+ showContent: true,
15
+ showType: true,
16
+ },
17
+ });
18
+ console.dir(result.data, { depth: null });
19
+ } catch (e) {
20
+ console.error(e);
21
+ } finally {
22
+ process.exit(0);
23
+ }
24
+ };
25
+
26
+ main();
@@ -27,13 +27,13 @@ export interface AddressesInterface {
27
27
  [K in SupportOracleType]: K extends (typeof SUPPORT_ORACLES)[0]
28
28
  ? string
29
29
  : K extends (typeof SUPPORT_ORACLES)[1]
30
- ? string
31
- : K extends (typeof SUPPORT_ORACLES)[2]
32
- ? {
33
- feed: string;
34
- feedObject: string;
35
- }
36
- : never;
30
+ ? string
31
+ : K extends (typeof SUPPORT_ORACLES)[2]
32
+ ? {
33
+ feed: string;
34
+ feedObject: string;
35
+ }
36
+ : never;
37
37
  };
38
38
  }
39
39
  >
@@ -46,19 +46,19 @@ export interface AddressesInterface {
46
46
  holder: string;
47
47
  }
48
48
  : K extends (typeof SUPPORT_ORACLES)[1]
49
- ? {
50
- registry: string;
51
- registryCap: string;
52
- }
53
- : K extends (typeof SUPPORT_ORACLES)[2]
54
- ? {
55
- registry: string;
56
- registryCap: string;
57
- state: string;
58
- wormhole: string;
59
- wormholeState: string;
60
- }
61
- : never;
49
+ ? {
50
+ registry: string;
51
+ registryCap: string;
52
+ }
53
+ : K extends (typeof SUPPORT_ORACLES)[2]
54
+ ? {
55
+ registry: string;
56
+ registryCap: string;
57
+ state: string;
58
+ wormhole: string;
59
+ wormholeState: string;
60
+ }
61
+ : never;
62
62
  } & { xOracle: string; xOracleCap: string };
63
63
  packages: Partial<
64
64
  Record<
@@ -145,12 +145,12 @@ type AddressPathsProps<T> = T extends string
145
145
  type Join<T extends string[], D extends string> = T extends []
146
146
  ? never
147
147
  : T extends [infer F]
148
- ? F
149
- : T extends [infer F, ...infer R]
150
- ? F extends string
151
- ? `${F}${D}${Join<Extract<R, string[]>, D>}`
152
- : never
153
- : string;
148
+ ? F
149
+ : T extends [infer F, ...infer R]
150
+ ? F extends string
151
+ ? `${F}${D}${Join<Extract<R, string[]>, D>}`
152
+ : never
153
+ : string;
154
154
 
155
155
  export type AddressStringPath = Join<
156
156
  AddressPathsProps<AddressesInterface>,
@@ -2,7 +2,7 @@ import type {
2
2
  SuiTxBlock as SuiKitTxBlock,
3
3
  SuiObjectArg,
4
4
  } from '@scallop-io/sui-kit';
5
- import type { TransactionResult } from '@mysten/sui.js/transactions';
5
+ import type { TransactionResult } from '@mysten/sui/transactions';
6
6
  import type { ScallopBuilder } from '../../models';
7
7
  import type {
8
8
  SupportBorrowIncentiveCoins,
@@ -1,13 +1,11 @@
1
1
  import type {
2
2
  SuiTxBlock as SuiKitTxBlock,
3
- SuiAddressArg,
4
3
  SuiObjectArg,
5
- SuiTxArg,
6
4
  } from '@scallop-io/sui-kit';
7
5
  import type {
8
6
  TransactionArgument,
9
7
  TransactionResult,
10
- } from '@mysten/sui.js/transactions';
8
+ } from '@mysten/sui/transactions';
11
9
  import type { ScallopBuilder } from '../../models';
12
10
  import type {
13
11
  SupportCollateralCoins,
@@ -35,19 +33,19 @@ type ObligationHotPotato = NestedResult;
35
33
  export type CoreNormalMethods = {
36
34
  openObligation: () => [Obligation, ObligationKey, ObligationHotPotato];
37
35
  returnObligation: (
38
- obligation: SuiAddressArg,
36
+ obligation: SuiObjectArg,
39
37
  obligationHotPotato: SuiObjectArg
40
38
  ) => void;
41
39
  openObligationEntry: () => void;
42
40
  addCollateral: (
43
- obligation: SuiAddressArg,
41
+ obligation: SuiObjectArg,
44
42
  coin: SuiObjectArg,
45
43
  collateralCoinName: SupportCollateralCoins
46
44
  ) => void;
47
45
  takeCollateral: (
48
- obligation: SuiAddressArg,
49
- obligationKey: SuiAddressArg,
50
- amount: SuiTxArg,
46
+ obligation: SuiObjectArg,
47
+ obligationKey: SuiObjectArg,
48
+ amount: number,
51
49
  collateralCoinName: SupportCollateralCoins
52
50
  ) => TransactionResult;
53
51
  deposit: (
@@ -64,36 +62,36 @@ export type CoreNormalMethods = {
64
62
  poolCoinName: SupportPoolCoins
65
63
  ) => void;
66
64
  borrow: (
67
- obligation: SuiAddressArg,
68
- obligationKey: SuiAddressArg,
69
- amount: SuiTxArg,
65
+ obligation: SuiObjectArg,
66
+ obligationKey: SuiObjectArg,
67
+ amount: number,
70
68
  poolCoinName: SupportPoolCoins
71
69
  ) => TransactionResult;
72
70
  borrowWithReferral: (
73
- obligation: SuiAddressArg,
74
- obligationKey: SuiAddressArg,
71
+ obligation: SuiObjectArg,
72
+ obligationKey: SuiObjectArg,
75
73
  borrowReferral: SuiObjectArg,
76
- amount: SuiTxArg,
74
+ amount: number,
77
75
  poolCoinName: SupportPoolCoins
78
76
  ) => TransactionResult;
79
77
  borrowEntry: (
80
- obligation: SuiAddressArg,
81
- obligationKey: SuiAddressArg,
82
- amount: SuiTxArg,
78
+ obligation: SuiObjectArg,
79
+ obligationKey: SuiObjectArg,
80
+ amount: number,
83
81
  poolCoinName: SupportPoolCoins
84
82
  ) => void;
85
83
  repay: (
86
- obligation: SuiAddressArg,
84
+ obligation: SuiObjectArg,
87
85
  coin: SuiObjectArg,
88
86
  poolCoinName: SupportPoolCoins
89
87
  ) => void;
90
88
  borrowFlashLoan: (
91
- amount: SuiTxArg,
89
+ amount: number,
92
90
  poolCoinName: SupportPoolCoins
93
91
  ) => TransactionResult;
94
92
  repayFlashLoan: (
95
93
  coin: SuiObjectArg,
96
- loan: SuiAddressArg,
94
+ loan: SuiObjectArg,
97
95
  poolCoinName: SupportPoolCoins
98
96
  ) => void;
99
97
  };
@@ -102,26 +100,26 @@ export type CoreQuickMethods = {
102
100
  addCollateralQuick: (
103
101
  amount: number,
104
102
  collateralCoinName: SupportCollateralCoins,
105
- obligationId?: SuiAddressArg
103
+ obligationId?: SuiObjectArg
106
104
  ) => Promise<void>;
107
105
  takeCollateralQuick: (
108
106
  amount: number,
109
107
  collateralCoinName: SupportCollateralCoins,
110
- obligationId?: SuiAddressArg,
111
- obligationKey?: SuiAddressArg
108
+ obligationId?: SuiObjectArg,
109
+ obligationKey?: SuiObjectArg
112
110
  ) => Promise<TransactionResult>;
113
111
  borrowQuick: (
114
112
  amount: number,
115
113
  poolCoinName: SupportPoolCoins,
116
- obligationId?: SuiAddressArg,
117
- obligationKey?: SuiAddressArg
114
+ obligationId?: SuiObjectArg,
115
+ obligationKey?: SuiObjectArg
118
116
  ) => Promise<TransactionResult>;
119
117
  borrowWithReferralQuick: (
120
118
  amount: number,
121
119
  poolCoinName: SupportPoolCoins,
122
120
  borrowReferral: SuiObjectArg,
123
- obligationId?: SuiAddressArg,
124
- obligationKey?: SuiAddressArg
121
+ obligationId?: SuiObjectArg,
122
+ obligationKey?: SuiObjectArg
125
123
  ) => Promise<TransactionResult>;
126
124
  depositQuick: (
127
125
  amount: number,
@@ -135,7 +133,7 @@ export type CoreQuickMethods = {
135
133
  repayQuick: (
136
134
  amount: number,
137
135
  poolCoinName: SupportPoolCoins,
138
- obligationId?: SuiAddressArg
136
+ obligationId?: SuiObjectArg
139
137
  ) => Promise<void>;
140
138
  updateAssetPricesQuick: (
141
139
  assetCoinNames?: SupportAssetCoins[]
@@ -2,9 +2,8 @@ import type {
2
2
  SuiTxBlock as SuiKitTxBlock,
3
3
  SuiAddressArg,
4
4
  SuiObjectArg,
5
- SuiTxArg,
6
5
  } from '@scallop-io/sui-kit';
7
- import type { TransactionResult } from '@mysten/sui.js/transactions';
6
+ import type { TransactionResult } from '@mysten/sui/transactions';
8
7
  import type { ScallopBuilder } from '../../models';
9
8
  import type { SupportStakeMarketCoins } from '../constant';
10
9
  import { SuiTxBlockWithSCoin } from '.';
@@ -24,7 +23,7 @@ export type SpoolNormalMethods = {
24
23
  ) => void;
25
24
  unstake: (
26
25
  stakeAccount: SuiAddressArg,
27
- amount: SuiTxArg,
26
+ amount: number,
28
27
  stakeMarketCoinName: SupportStakeMarketCoins
29
28
  ) => TransactionResult;
30
29
  claim: (
@@ -1,9 +1,5 @@
1
- import {
2
- SuiTxBlock as SuiKitTxBlock,
3
- SuiObjectArg,
4
- SuiTxArg,
5
- } from '@scallop-io/sui-kit';
6
- import type { TransactionResult } from '@mysten/sui.js/transactions';
1
+ import { SuiTxBlock as SuiKitTxBlock, SuiObjectArg } from '@scallop-io/sui-kit';
2
+ import type { TransactionResult } from '@mysten/sui/transactions';
7
3
  import { ScallopBuilder } from 'src/models';
8
4
 
9
5
  export type VescaIds = {
@@ -16,17 +12,17 @@ export type VescaIds = {
16
12
  export type VeScaNormalMethods = {
17
13
  lockSca: (
18
14
  scaCoin: SuiObjectArg,
19
- unlockAtInSecondTimestamp: SuiTxArg
15
+ unlockAtInSecondTimestamp: number
20
16
  ) => TransactionResult;
21
17
  extendLockPeriod: (
22
18
  veScaKey: SuiObjectArg,
23
- newUnlockAtInSecondTimestamp: SuiTxArg
19
+ newUnlockAtInSecondTimestamp: number
24
20
  ) => void;
25
21
  extendLockAmount: (veScaKey: SuiObjectArg, scaCoin: SuiObjectArg) => void;
26
22
  renewExpiredVeSca: (
27
23
  veScaKey: SuiObjectArg,
28
24
  scaCoin: SuiObjectArg,
29
- newUnlockAtInSecondTimestamp: SuiTxArg
25
+ newUnlockAtInSecondTimestamp: number
30
26
  ) => void;
31
27
  redeemSca: (veScaKey: SuiObjectArg) => TransactionResult;
32
28
  mintEmptyVeSca: () => TransactionResult;
@@ -1,8 +1,5 @@
1
- import type { SuiTransactionBlockResponse } from '@mysten/sui.js/client';
2
- import type {
3
- TransactionBlock,
4
- TransactionResult,
5
- } from '@mysten/sui.js/transactions';
1
+ import type { SuiTransactionBlockResponse } from '@mysten/sui/client';
2
+ import type { Transaction, TransactionResult } from '@mysten/sui/transactions';
6
3
  import type { SuiKit, SuiKitParams, NetworkType } from '@scallop-io/sui-kit';
7
4
  import type {
8
5
  ScallopAddress,
@@ -16,12 +13,12 @@ import { AddressesInterface } from './address';
16
13
 
17
14
  export type ScallopClientFnReturnType<T extends boolean> = T extends true
18
15
  ? SuiTransactionBlockResponse
19
- : TransactionBlock;
16
+ : Transaction;
20
17
 
21
18
  export type ScallopClientVeScaReturnType<T extends boolean> = T extends true
22
19
  ? SuiTransactionBlockResponse
23
20
  : {
24
- tx: TransactionBlock;
21
+ tx: Transaction;
25
22
  scaCoin: TransactionResult;
26
23
  };
27
24
 
@@ -60,12 +57,12 @@ export type ScallopAddressParams = {
60
57
  id: string;
61
58
  auth?: string;
62
59
  network?: NetworkType;
63
- forceInterface?: Record<NetworkType, AddressesInterface>;
60
+ forceInterface?: Partial<Record<NetworkType, AddressesInterface>>;
64
61
  };
65
62
 
66
63
  export type ScallopParams = {
67
64
  addressesId?: string;
68
- forceAddressesInterface?: Record<NetworkType, AddressesInterface>;
65
+ forceAddressesInterface?: Partial<Record<NetworkType, AddressesInterface>>;
69
66
  walletAddress?: string;
70
67
  } & SuiKitParams;
71
68
 
@@ -1,4 +1,4 @@
1
- import type { SuiObjectRef } from '@mysten/sui.js/client';
1
+ import type { SuiObjectRef } from '@mysten/sui/client';
2
2
 
3
3
  export type Vesca = {
4
4
  id: string;
@@ -2,3 +2,4 @@ export * from './builder';
2
2
  export * from './query';
3
3
  export * from './util';
4
4
  export * from './tokenBucket';
5
+ export * from './indexer';
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Generic wrapper for methods with indexer fallback.
3
+ *
4
+ * @param method - The method to call with fallback behavior.
5
+ * @param context - The context (`this`) of the class instance.
6
+ * @param args - The arguments to pass to the method.
7
+ * @returns The result of the method call.
8
+ */
9
+ export async function callMethodWithIndexerFallback(
10
+ method: Function,
11
+ context: any,
12
+ ...args: any[]
13
+ ) {
14
+ const indexer = args[args.length - 1]; // Assume last argument is always `indexer`
15
+
16
+ if (indexer) {
17
+ try {
18
+ return await method.apply(context, args);
19
+ } catch (_e) {
20
+ console.warn('Indexer requests failed. Retrying without indexer..');
21
+ return await method.apply(context, [...args.slice(0, -1), false]);
22
+ }
23
+ }
24
+ return await method.apply(context, args);
25
+ }
26
+
27
+ /**
28
+ * This function creates a wrapper for methods that have an indexer parameter.
29
+ * It ensures fallback behavior if indexer fails.
30
+ *
31
+ * @param method - The method to wrap.
32
+ * @returns A function that applies indexer fallback.
33
+ */
34
+ export function withIndexerFallback(method: Function) {
35
+ return (...args: any[]) => {
36
+ // @ts-ignore
37
+ return callMethodWithIndexerFallback(method, this, ...args); // Preserve `this` with arrow function
38
+ };
39
+ }
@@ -1,5 +1,5 @@
1
1
  import BigNumber from 'bignumber.js';
2
- import { normalizeStructTag, parseStructTag } from '@mysten/sui.js/utils';
2
+ import { normalizeStructTag, parseStructTag } from '@mysten/sui/utils';
3
3
  import type { ScallopUtils } from '../models';
4
4
  import type {
5
5
  OriginMarketPoolData,