@scallop-io/sui-scallop-sdk 0.46.55 → 0.46.57

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 (57) hide show
  1. package/dist/constants/common.d.ts +1 -1
  2. package/dist/constants/pyth.d.ts +1 -1
  3. package/dist/index.js +1533 -1378
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.mjs +1499 -1344
  6. package/dist/index.mjs.map +1 -1
  7. package/dist/models/scallop.d.ts +1 -1
  8. package/dist/models/scallopAddress.d.ts +4 -4
  9. package/dist/models/scallopBuilder.d.ts +3 -6
  10. package/dist/models/scallopCache.d.ts +2 -2
  11. package/dist/models/scallopClient.d.ts +7 -2
  12. package/dist/models/scallopIndexer.d.ts +3 -3
  13. package/dist/models/scallopPrice.d.ts +0 -0
  14. package/dist/models/scallopQuery.d.ts +10 -4
  15. package/dist/models/scallopUtils.d.ts +8 -7
  16. package/dist/queries/borrowIncentiveQuery.d.ts +10 -4
  17. package/dist/queries/coreQuery.d.ts +8 -4
  18. package/dist/queries/priceQuery.d.ts +7 -3
  19. package/dist/queries/referralQuery.d.ts +2 -2
  20. package/dist/queries/sCoinQuery.d.ts +18 -4
  21. package/dist/queries/spoolQuery.d.ts +10 -4
  22. package/dist/queries/vescaQuery.d.ts +7 -5
  23. package/dist/types/builder/index.d.ts +8 -1
  24. package/dist/types/builder/vesca.d.ts +2 -1
  25. package/dist/types/model.d.ts +27 -12
  26. package/dist/types/query/core.d.ts +1 -0
  27. package/dist/utils/query.d.ts +1 -1
  28. package/package.json +1 -1
  29. package/src/builders/borrowIncentiveBuilder.ts +19 -21
  30. package/src/builders/coreBuilder.ts +10 -8
  31. package/src/builders/spoolBuilder.ts +2 -2
  32. package/src/builders/vescaBuilder.ts +12 -4
  33. package/src/constants/common.ts +2 -0
  34. package/src/constants/enum.ts +4 -0
  35. package/src/constants/pyth.ts +2 -2
  36. package/src/models/scallop.ts +14 -20
  37. package/src/models/scallopAddress.ts +15 -5
  38. package/src/models/scallopBuilder.ts +42 -32
  39. package/src/models/scallopCache.ts +2 -2
  40. package/src/models/scallopClient.ts +91 -32
  41. package/src/models/scallopIndexer.ts +15 -8
  42. package/src/models/scallopPrice.ts +0 -0
  43. package/src/models/scallopQuery.ts +47 -25
  44. package/src/models/scallopUtils.ts +75 -74
  45. package/src/queries/borrowIncentiveQuery.ts +40 -29
  46. package/src/queries/coreQuery.ts +40 -26
  47. package/src/queries/portfolioQuery.ts +1 -2
  48. package/src/queries/priceQuery.ts +20 -9
  49. package/src/queries/referralQuery.ts +4 -4
  50. package/src/queries/sCoinQuery.ts +95 -17
  51. package/src/queries/spoolQuery.ts +26 -14
  52. package/src/queries/vescaQuery.ts +32 -26
  53. package/src/types/builder/index.ts +11 -1
  54. package/src/types/builder/vesca.ts +8 -1
  55. package/src/types/model.ts +40 -11
  56. package/src/types/query/core.ts +1 -0
  57. package/src/utils/query.ts +1 -1
@@ -5,7 +5,7 @@ import {
5
5
  type SuiObjectData,
6
6
  DevInspectResults,
7
7
  } from '@mysten/sui.js/client';
8
- import type { ScallopQuery } from '../models';
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
11
  import { bcs } from '@mysten/sui.js/bcs';
@@ -18,17 +18,17 @@ import { z as zod } from 'zod';
18
18
  * @return Owned veSca key.
19
19
  */
20
20
  export const getVescaKeys = async (
21
- query: ScallopQuery,
21
+ utils: ScallopUtils,
22
22
  ownerAddress?: string
23
23
  ) => {
24
- const owner = ownerAddress || query.suiKit.currentAddress();
25
- const veScaObjId = query.address.get('vesca.object');
24
+ const owner = ownerAddress || utils.suiKit.currentAddress();
25
+ const veScaObjId = utils.address.get('vesca.object');
26
26
  const veScaKeyType = `${veScaObjId}::ve_sca::VeScaKey`;
27
27
  const keyObjectsResponse: SuiObjectResponse[] = [];
28
28
  let hasNextPage = false;
29
29
  let nextCursor: string | null | undefined = null;
30
30
  do {
31
- const paginatedKeyObjectsResponse = await query.cache.queryGetOwnedObjects({
31
+ const paginatedKeyObjectsResponse = await utils.cache.queryGetOwnedObjects({
32
32
  owner,
33
33
  filter: {
34
34
  StructType: veScaKeyType,
@@ -63,12 +63,19 @@ export const getVescaKeys = async (
63
63
  * @param ownerAddress - The owner address.
64
64
  * @return Owned veScas.
65
65
  */
66
- export const getVeScas = async (query: ScallopQuery, ownerAddress?: string) => {
67
- const keyObjectDatas = await getVescaKeys(query, ownerAddress);
66
+ export const getVeScas = async (
67
+ {
68
+ utils,
69
+ }: {
70
+ utils: ScallopUtils;
71
+ },
72
+ ownerAddress?: string
73
+ ) => {
74
+ const keyObjectDatas = await getVescaKeys(utils, ownerAddress);
68
75
 
69
76
  const veScas: Vesca[] = Array(keyObjectDatas.length).fill(null);
70
77
  const tasks = keyObjectDatas.map(async (veScaKey, idx) => {
71
- const veSca = await getVeSca(query, veScaKey);
78
+ const veSca = await getVeSca(utils, veScaKey);
72
79
  if (veSca) {
73
80
  veScas[idx] = veSca;
74
81
  }
@@ -96,12 +103,12 @@ type SuiObjectRefType = zod.infer<typeof SuiObjectRefZod>;
96
103
  * @returns Vesca data.
97
104
  */
98
105
  export const getVeSca = async (
99
- query: ScallopQuery,
106
+ utils: ScallopUtils,
100
107
  veScaKey?: string | SuiObjectData,
101
108
  ownerAddress?: string
102
109
  ) => {
103
- const tableId = query.address.get(`vesca.tableId`);
104
- veScaKey = veScaKey || (await getVescaKeys(query, ownerAddress))[0];
110
+ const tableId = utils.address.get(`vesca.tableId`);
111
+ veScaKey = veScaKey || (await getVescaKeys(utils, ownerAddress))[0];
105
112
 
106
113
  if (!veScaKey) return undefined;
107
114
  if (typeof veScaKey === 'object') {
@@ -111,7 +118,7 @@ export const getVeSca = async (
111
118
  let vesca: Vesca | undefined = undefined;
112
119
 
113
120
  const veScaDynamicFieldObjectResponse =
114
- await query.cache.queryGetDynamicFieldObject({
121
+ await utils.cache.queryGetDynamicFieldObject({
115
122
  parentId: tableId,
116
123
  name: {
117
124
  type: '0x2::object::ID',
@@ -162,12 +169,12 @@ export const getVeSca = async (
162
169
  * Get current total veSca treasury amount.
163
170
  */
164
171
  const getTotalVeScaTreasuryAmount = async (
165
- query: ScallopQuery,
172
+ utils: ScallopUtils,
166
173
  veScaTreasury: SuiObjectData
167
174
  ): Promise<string> => {
168
- const veScaPkgId = query.address.get('vesca.id');
169
- const veScaConfig = query.address.get('vesca.config');
170
- veScaTreasury = veScaTreasury ?? query.address.get('vesca.treasury');
175
+ const veScaPkgId = utils.address.get('vesca.id');
176
+ const veScaConfig = utils.address.get('vesca.config');
177
+ veScaTreasury = veScaTreasury ?? utils.address.get('vesca.treasury');
171
178
 
172
179
  // refresh query
173
180
  const refreshQueryTarget = `${veScaPkgId}::treasury::refresh`;
@@ -181,7 +188,7 @@ const getTotalVeScaTreasuryAmount = async (
181
188
  const resolvedRefreshArgs = await Promise.all(
182
189
  refreshArgs.map(async (arg) => {
183
190
  if (typeof arg === 'string') {
184
- return (await query.cache.queryGetObject(arg, { showContent: true }))
191
+ return (await utils.cache.queryGetObject(arg, { showContent: true }))
185
192
  ?.data;
186
193
  }
187
194
  return arg;
@@ -191,7 +198,7 @@ const getTotalVeScaTreasuryAmount = async (
191
198
  const resolvedVeScaAmountArgs = await Promise.all(
192
199
  veScaAmountArgs.map(async (arg) => {
193
200
  if (typeof arg === 'string') {
194
- return (await query.cache.queryGetObject(arg, { showContent: true }))
201
+ return (await utils.cache.queryGetObject(arg, { showContent: true }))
195
202
  ?.data;
196
203
  }
197
204
  return arg;
@@ -204,19 +211,18 @@ const getTotalVeScaTreasuryAmount = async (
204
211
  txb.moveCall(veScaAmountQueryTarget, resolvedVeScaAmountArgs);
205
212
 
206
213
  const txBytes = await txb.txBlock.build({
207
- client: query.suiKit.client(),
214
+ client: utils.suiKit.client(),
208
215
  onlyTransactionKind: true,
209
- protocolConfig: (await query.cache.getProtocolConfig()) ?? undefined,
210
216
  });
211
217
 
212
218
  // return result
213
- const res = await query.cache.queryClient.fetchQuery<DevInspectResults>({
219
+ const res = await utils.cache.queryClient.fetchQuery<DevInspectResults>({
214
220
  queryKey: [
215
221
  'getTotalVeScaTreasuryAmount',
216
222
  JSON.stringify([...refreshArgs, ...veScaAmountArgs]),
217
223
  ],
218
224
  queryFn: async () => {
219
- return await query.suiKit.inspectTxn(txBytes);
225
+ return await utils.suiKit.inspectTxn(txBytes);
220
226
  },
221
227
  });
222
228
 
@@ -236,10 +242,10 @@ const getTotalVeScaTreasuryAmount = async (
236
242
  * @returns VeScaTreasuryInfo
237
243
  */
238
244
  export const getVeScaTreasuryInfo = async (
239
- query: ScallopQuery
245
+ utils: ScallopUtils
240
246
  ): Promise<VeScaTreasuryInfo | null> => {
241
- const veScaTreasuryId = query.address.get('vesca.treasury');
242
- const veScaTreasury = await query.cache.queryGetObject(veScaTreasuryId, {
247
+ const veScaTreasuryId = utils.address.get('vesca.treasury');
248
+ const veScaTreasury = await utils.cache.queryGetObject(veScaTreasuryId, {
243
249
  showContent: true,
244
250
  });
245
251
 
@@ -255,7 +261,7 @@ export const getVeScaTreasuryInfo = async (
255
261
  .shiftedBy(-9)
256
262
  .toNumber();
257
263
  const totalVeSca = BigNumber(
258
- (await getTotalVeScaTreasuryAmount(query, veScaTreasury.data)) ?? 0
264
+ (await getTotalVeScaTreasuryAmount(utils, veScaTreasury.data)) ?? 0
259
265
  )
260
266
  .shiftedBy(-9)
261
267
  .toNumber();
@@ -1,10 +1,11 @@
1
- import type { CoreTxBlock } from './core';
1
+ import type { CoreTxBlock, NestedResult } from './core';
2
2
  import type { SpoolTxBlock } from './spool';
3
3
  import type { BorrowIncentiveTxBlock } from './borrowIncentive';
4
4
  import type { VeScaTxBlock } from './vesca';
5
5
  import type { ReferralTxBlock } from './referral';
6
6
  import { LoyaltyProgramTxBlock } from './loyaltyProgram';
7
7
  import { SCoinTxBlock } from './sCoin';
8
+ import { SupportAssetCoins } from '../constant';
8
9
 
9
10
  export type * from './core';
10
11
  export type * from './spool';
@@ -21,3 +22,12 @@ export type BaseScallopTxBlock = ReferralTxBlock &
21
22
  export type SuiTxBlockWithSCoin = BaseScallopTxBlock & SCoinTxBlock;
22
23
  export type SuiTxBlockWithSpool = SuiTxBlockWithSCoin & SpoolTxBlock;
23
24
  export type ScallopTxBlock = SuiTxBlockWithSpool & CoreTxBlock;
25
+
26
+ export type SelectCoinReturnType<T extends SupportAssetCoins> = T extends 'sui'
27
+ ? {
28
+ takeCoin: NestedResult;
29
+ }
30
+ : {
31
+ takeCoin: NestedResult;
32
+ leftCoin: NestedResult;
33
+ };
@@ -32,6 +32,10 @@ export type VeScaNormalMethods = {
32
32
  mintEmptyVeSca: () => TransactionResult;
33
33
  };
34
34
 
35
+ export type RedeemScaQuickReturnType<T extends boolean> = T extends true
36
+ ? void
37
+ : TransactionResult | undefined;
38
+
35
39
  export type VeScaQuickMethods = {
36
40
  /**
37
41
  * Quick methods to automate
@@ -70,7 +74,10 @@ export type VeScaQuickMethods = {
70
74
  veScaKey?: SuiObjectArg,
71
75
  autoCheck?: boolean
72
76
  ) => Promise<void>;
73
- redeemScaQuick: (veScaKey?: SuiObjectArg) => Promise<void>;
77
+ redeemScaQuick: <T extends boolean>(
78
+ veSCaKey?: SuiObjectArg,
79
+ transferSca?: T
80
+ ) => Promise<RedeemScaQuickReturnType<T>>;
74
81
  };
75
82
 
76
83
  export type SuiTxBlockWithVeScaNormalMethods = SuiKitTxBlock &
@@ -1,11 +1,15 @@
1
1
  import type { SuiTransactionBlockResponse } from '@mysten/sui.js/client';
2
- import type { TransactionBlock } from '@mysten/sui.js/transactions';
2
+ import type {
3
+ TransactionBlock,
4
+ TransactionResult,
5
+ } from '@mysten/sui.js/transactions';
3
6
  import type { SuiKit, SuiKitParams, NetworkType } from '@scallop-io/sui-kit';
4
7
  import type {
5
8
  ScallopAddress,
6
9
  ScallopQuery,
7
10
  ScallopUtils,
8
11
  ScallopBuilder,
12
+ ScallopIndexer,
9
13
  } from '../models';
10
14
  import { ScallopCache } from 'src/models/scallopCache';
11
15
 
@@ -13,13 +17,42 @@ export type ScallopClientFnReturnType<T extends boolean> = T extends true
13
17
  ? SuiTransactionBlockResponse
14
18
  : TransactionBlock;
15
19
 
16
- export type ScallopInstanceParams = {
20
+ export type ScallopClientVeScaReturnType<T extends boolean> = T extends true
21
+ ? SuiTransactionBlockResponse
22
+ : {
23
+ tx: TransactionBlock;
24
+ scaCoin: TransactionResult;
25
+ };
26
+
27
+ export type ScallopBaseInstanceParams = {
17
28
  suiKit?: SuiKit;
29
+ };
30
+
31
+ export type ScallopCacheInstanceParams = ScallopBaseInstanceParams;
32
+
33
+ export type ScallopAddressInstanceParams = ScallopBaseInstanceParams & {
34
+ cache?: ScallopCache;
35
+ };
36
+
37
+ export type ScallopIndexerInstanceParams = {
38
+ cache?: ScallopCache;
39
+ };
40
+
41
+ export type ScallopUtilsInstanceParams = ScallopBaseInstanceParams & {
18
42
  address?: ScallopAddress;
19
- query?: ScallopQuery;
43
+ };
44
+
45
+ export type ScallopQueryInstanceParams = ScallopBaseInstanceParams & {
20
46
  utils?: ScallopUtils;
47
+ indexer?: ScallopIndexer;
48
+ };
49
+
50
+ export type ScallopBuilderInstanceParams = ScallopBaseInstanceParams & {
51
+ query?: ScallopQuery;
52
+ };
53
+
54
+ export type ScallopClientInstanceParams = ScallopBaseInstanceParams & {
21
55
  builder?: ScallopBuilder;
22
- cache: ScallopCache;
23
56
  };
24
57
 
25
58
  export type ScallopAddressParams = {
@@ -30,20 +63,16 @@ export type ScallopAddressParams = {
30
63
 
31
64
  export type ScallopParams = {
32
65
  addressesId?: string;
66
+ walletAddress?: string;
33
67
  } & SuiKitParams;
34
68
 
35
- export type ScallopClientParams = ScallopParams & {
36
- walletAddress?: string;
37
- };
69
+ export type ScallopClientParams = ScallopParams;
38
70
 
39
71
  export type ScallopBuilderParams = ScallopParams & {
40
- walletAddress?: string;
41
72
  pythEndpoints?: string[];
42
73
  };
43
74
 
44
- export type ScallopQueryParams = ScallopParams & {
45
- walletAddress?: string;
46
- };
75
+ export type ScallopQueryParams = ScallopParams;
47
76
 
48
77
  export type ScallopUtilsParams = ScallopParams & {
49
78
  pythEndpoints?: string[];
@@ -125,6 +125,7 @@ export type MarketPool = {
125
125
  symbol: string;
126
126
  coinType: string;
127
127
  marketCoinType: string;
128
+ sCoinType: string;
128
129
  coinWrappedType: CoinWrappedType;
129
130
  coinDecimal: number;
130
131
  coinPrice: number;
@@ -697,7 +697,7 @@ export const maxBigNumber = (...args: BigNumber.Value[]) => {
697
697
  };
698
698
 
699
699
  /**
700
- * Dynamically adjust the decrease or increase ratio according to the amout
700
+ * Dynamically adjust the decrease or increase ratio according to the amount
701
701
  * @param amount - The amount required to calculate factor.
702
702
  * @param scaleStep - The scale step required to determine the factor..
703
703
  * @param type - The type of the calculation.