@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
@@ -51,13 +51,13 @@ const requireObligationInfo = async (
51
51
  typeof obligationId === 'string'
52
52
  ) {
53
53
  const obligationLocked = await getObligationLocked(
54
- builder.query,
54
+ builder.cache,
55
55
  obligationId
56
56
  );
57
57
  return { obligationId, obligationKey, obligationLocked };
58
58
  }
59
59
  const sender = requireSender(txBlock);
60
- const obligations = await getObligations(builder.query, sender);
60
+ const obligations = await getObligations(builder, sender);
61
61
  if (obligations.length === 0) {
62
62
  throw new Error(`No obligation found for sender ${sender}`);
63
63
  }
@@ -207,7 +207,7 @@ const generateBorrowIncentiveQuickMethod: GenerateBorrowIncentiveQuickMethod =
207
207
  stakeObligationQuick: async (obligation, obligationKey) => {
208
208
  const {
209
209
  obligationId: obligationArg,
210
- obligationKey: obligationtKeyArg,
210
+ obligationKey: obligationKeyArg,
211
211
  obligationLocked: obligationLocked,
212
212
  } = await requireObligationInfo(
213
213
  builder,
@@ -227,7 +227,7 @@ const generateBorrowIncentiveQuickMethod: GenerateBorrowIncentiveQuickMethod =
227
227
  );
228
228
 
229
229
  if (!obligationLocked || unstakeObligationBeforeStake) {
230
- txBlock.stakeObligation(obligationArg, obligationtKeyArg);
230
+ txBlock.stakeObligation(obligationArg, obligationKeyArg);
231
231
  }
232
232
  },
233
233
  stakeObligationWithVeScaQuick: async (
@@ -237,7 +237,7 @@ const generateBorrowIncentiveQuickMethod: GenerateBorrowIncentiveQuickMethod =
237
237
  ) => {
238
238
  const {
239
239
  obligationId: obligationArg,
240
- obligationKey: obligationtKeyArg,
240
+ obligationKey: obligationKeyArg,
241
241
  obligationLocked: obligationLocked,
242
242
  } = await requireObligationInfo(
243
243
  builder,
@@ -260,7 +260,7 @@ const generateBorrowIncentiveQuickMethod: GenerateBorrowIncentiveQuickMethod =
260
260
  const veSca = await requireVeSca(builder, txBlock, veScaKey);
261
261
  if (veSca) {
262
262
  const bindedObligationId = await getBindedObligationId(
263
- builder.query,
263
+ builder,
264
264
  veSca.keyId
265
265
  );
266
266
 
@@ -271,21 +271,21 @@ const generateBorrowIncentiveQuickMethod: GenerateBorrowIncentiveQuickMethod =
271
271
  ) {
272
272
  txBlock.stakeObligationWithVesca(
273
273
  obligationArg,
274
- obligationtKeyArg,
274
+ obligationKeyArg,
275
275
  veSca.keyId
276
276
  );
277
277
  } else {
278
- txBlock.stakeObligation(obligationArg, obligationtKeyArg);
278
+ txBlock.stakeObligation(obligationArg, obligationKeyArg);
279
279
  }
280
280
  } else {
281
- txBlock.stakeObligation(obligationArg, obligationtKeyArg);
281
+ txBlock.stakeObligation(obligationArg, obligationKeyArg);
282
282
  }
283
283
  }
284
284
  },
285
285
  unstakeObligationQuick: async (obligation, obligationKey) => {
286
286
  const {
287
287
  obligationId: obligationArg,
288
- obligationKey: obligationtKeyArg,
288
+ obligationKey: obligationKeyArg,
289
289
  obligationLocked: obligationLocked,
290
290
  } = await requireObligationInfo(
291
291
  builder,
@@ -295,7 +295,7 @@ const generateBorrowIncentiveQuickMethod: GenerateBorrowIncentiveQuickMethod =
295
295
  );
296
296
 
297
297
  if (obligationLocked) {
298
- txBlock.unstakeObligation(obligationArg, obligationtKeyArg);
298
+ txBlock.unstakeObligation(obligationArg, obligationKeyArg);
299
299
  }
300
300
  },
301
301
  claimBorrowIncentiveQuick: async (
@@ -304,19 +304,17 @@ const generateBorrowIncentiveQuickMethod: GenerateBorrowIncentiveQuickMethod =
304
304
  obligation,
305
305
  obligationKey
306
306
  ) => {
307
- const {
308
- obligationId: obligationArg,
309
- obligationKey: obligationtKeyArg,
310
- } = await requireObligationInfo(
311
- builder,
312
- txBlock,
313
- obligation,
314
- obligationKey
315
- );
307
+ const { obligationId: obligationArg, obligationKey: obligationKeyArg } =
308
+ await requireObligationInfo(
309
+ builder,
310
+ txBlock,
311
+ obligation,
312
+ obligationKey
313
+ );
316
314
 
317
315
  return txBlock.claimBorrowIncentive(
318
316
  obligationArg,
319
- obligationtKeyArg,
317
+ obligationKeyArg,
320
318
  coinName,
321
319
  rewardCoinName
322
320
  );
@@ -44,7 +44,7 @@ const requireObligationInfo = async (
44
44
  if (params.length === 4 && obligationId && obligationKey)
45
45
  return { obligationId, obligationKey };
46
46
  const sender = requireSender(txBlock);
47
- const obligations = await getObligations(builder.query, sender);
47
+ const obligations = await getObligations(builder, sender);
48
48
  if (obligations.length === 0) {
49
49
  throw new Error(`No obligation found for sender ${sender}`);
50
50
  }
@@ -391,10 +391,11 @@ const generateCoreQuickMethod: GenerateCoreQuickMethod = ({
391
391
  obligationId,
392
392
  obligationKey
393
393
  );
394
- const obligationCoinNames = await builder.utils.getObligationCoinNames(
395
- obligationInfo.obligationId
396
- );
397
- const updateCoinNames = [...obligationCoinNames, poolCoinName];
394
+ const obligationCoinNames =
395
+ (await builder.utils.getObligationCoinNames(
396
+ obligationInfo.obligationId
397
+ )) ?? [];
398
+ const updateCoinNames = [...(obligationCoinNames ?? []), poolCoinName];
398
399
  await updateOracles(builder, txBlock, updateCoinNames);
399
400
  return txBlock.borrow(
400
401
  obligationInfo.obligationId,
@@ -416,9 +417,10 @@ const generateCoreQuickMethod: GenerateCoreQuickMethod = ({
416
417
  obligationId,
417
418
  obligationKey
418
419
  );
419
- const obligationCoinNames = await builder.utils.getObligationCoinNames(
420
- obligationInfo.obligationId
421
- );
420
+ const obligationCoinNames =
421
+ (await builder.utils.getObligationCoinNames(
422
+ obligationInfo.obligationId
423
+ )) ?? [];
422
424
  const updateCoinNames = [...obligationCoinNames, poolCoinName];
423
425
  await updateOracles(builder, txBlock, updateCoinNames);
424
426
  return txBlock.borrowWithReferral(
@@ -42,7 +42,7 @@ const requireStakeAccountIds = async (
42
42
  const [builder, txBlock, stakeMarketCoinName, stakeAccountId] = params;
43
43
  if (params.length === 4 && stakeAccountId) return [stakeAccountId];
44
44
  const sender = requireSender(txBlock);
45
- const stakeAccounts = await getStakeAccounts(builder.query, sender);
45
+ const stakeAccounts = await getStakeAccounts(builder, sender);
46
46
  if (stakeAccounts[stakeMarketCoinName].length === 0) {
47
47
  throw new Error(`No stake account id found for sender ${sender}`);
48
48
  }
@@ -72,7 +72,7 @@ const requireStakeAccounts = async (
72
72
  ) => {
73
73
  const [builder, txBlock, stakeMarketCoinName, stakeAccountId] = params;
74
74
  const sender = requireSender(txBlock);
75
- const stakeAccounts = await getStakeAccounts(builder.query, sender);
75
+ const stakeAccounts = await getStakeAccounts(builder, sender);
76
76
  if (stakeAccounts[stakeMarketCoinName].length === 0) {
77
77
  throw new Error(`No stake account found for sender ${sender}`);
78
78
  }
@@ -22,6 +22,7 @@ import type {
22
22
  import type {
23
23
  GenerateVeScaNormalMethod,
24
24
  GenerateVeScaQuickMethod,
25
+ RedeemScaQuickReturnType,
25
26
  ScallopTxBlock,
26
27
  SuiTxBlockWithVeScaNormalMethods,
27
28
  VeScaTxBlock,
@@ -50,7 +51,7 @@ export const requireVeSca = async (
50
51
  ) => {
51
52
  const [builder, txBlock, veScaKey] = params;
52
53
  if (params.length === 3 && veScaKey && typeof veScaKey === 'string') {
53
- const veSca = await getVeSca(builder.query, veScaKey);
54
+ const veSca = await getVeSca(builder.utils, veScaKey);
54
55
 
55
56
  if (!veSca) {
56
57
  return undefined;
@@ -60,7 +61,7 @@ export const requireVeSca = async (
60
61
  }
61
62
 
62
63
  const sender = requireSender(txBlock);
63
- const veScas = await getVeScas(builder.query, sender);
64
+ const veScas = await getVeScas(builder, sender);
64
65
  if (veScas.length === 0) {
65
66
  return undefined;
66
67
  }
@@ -334,7 +335,10 @@ const generateQuickVeScaMethod: GenerateVeScaQuickMethod = ({
334
335
  txBlock.transferObjects(transferObjects, sender);
335
336
  }
336
337
  },
337
- redeemScaQuick: async (veScaKey?: SuiObjectArg) => {
338
+ redeemScaQuick: async <S extends boolean>(
339
+ veScaKey?: SuiObjectArg,
340
+ transferSca: S = true as S
341
+ ) => {
338
342
  const sender = requireSender(txBlock);
339
343
  const veSca = await requireVeSca(builder, txBlock, veScaKey);
340
344
 
@@ -342,7 +346,11 @@ const generateQuickVeScaMethod: GenerateVeScaQuickMethod = ({
342
346
 
343
347
  if (veSca) {
344
348
  const sca = txBlock.redeemSca(veSca.keyId);
345
- txBlock.transferObjects([sca], sender);
349
+ if (transferSca) {
350
+ txBlock.transferObjects([sca], sender);
351
+ return;
352
+ }
353
+ return sca as RedeemScaQuickReturnType<S>;
346
354
  }
347
355
  },
348
356
  };
@@ -83,6 +83,8 @@ export const SUPPORT_SCOIN = [
83
83
  'seth',
84
84
  'ssca',
85
85
  'scetus',
86
+ 'ssol',
87
+ 'sbtc',
86
88
  ] as const;
87
89
 
88
90
  export const SUPPORT_SPOOLS_REWARDS = ['sui'] as const;
@@ -68,6 +68,8 @@ export const sCoins: types.SCoins = {
68
68
  shasui: 'shasui',
69
69
  svsui: 'svsui',
70
70
  ssca: 'ssca',
71
+ ssol: 'ssol',
72
+ sbtc: 'sbtc',
71
73
  };
72
74
 
73
75
  export const stakeMarketCoins: types.StakeMarketCoins = {
@@ -150,6 +152,8 @@ export const sCoinIds: types.SCoinIds = {
150
152
  '0x9a2376943f7d22f88087c259c5889925f332ca4347e669dc37d54c2bf651af3c::scallop_ha_sui::SCALLOP_HA_SUI',
151
153
  svsui:
152
154
  '0xe1a1cc6bcf0001a015eab84bcc6713393ce20535f55b8b6f35c142e057a25fbe::scallop_v_sui::SCALLOP_V_SUI',
155
+ ssol: '0x1392650f2eca9e3f6ffae3ff89e42a3590d7102b80e2b430f674730bc30d3259::scallop_wormhole_sol::SCALLOP_WORMHOLE_SOL',
156
+ sbtc: '0x2cf76a9cf5d3337961d1154283234f94da2dcff18544dfe5cbdef65f319591b5::scallop_wormhole_btc::SCALLOP_WORMHOLE_BTC',
153
157
  } as const;
154
158
 
155
159
  // TEST VERSION
@@ -1,6 +1,6 @@
1
1
  export const PYTH_ENDPOINTS: {
2
- [k in 'mainnet' | 'testnet']: Readonly<string[]>;
2
+ [k in 'mainnet' | 'testnet']: string[];
3
3
  } = {
4
4
  testnet: ['https://hermes-beta.pyth.network'],
5
5
  mainnet: ['https://hermes.pyth.network', 'https://scallop.rpc.p2p.world'],
6
- } as const;
6
+ };
@@ -38,7 +38,7 @@ export class Scallop {
38
38
  public suiKit: SuiKit;
39
39
  public cache: ScallopCache;
40
40
 
41
- private _address: ScallopAddress;
41
+ private address: ScallopAddress;
42
42
 
43
43
  public constructor(
44
44
  params: ScallopParams,
@@ -48,17 +48,17 @@ export class Scallop {
48
48
  this.params = params;
49
49
  this.suiKit = new SuiKit(params);
50
50
  this.cache = new ScallopCache(
51
- cacheOptions ?? DEFAULT_CACHE_OPTIONS,
52
51
  this.suiKit,
52
+ cacheOptions ?? DEFAULT_CACHE_OPTIONS,
53
53
  tokenBucket ??
54
54
  new TokenBucket(DEFAULT_TOKENS_PER_INTERVAL, DEFAULT_INTERVAL_IN_MS)
55
55
  );
56
- this._address = new ScallopAddress(
56
+ this.address = new ScallopAddress(
57
57
  {
58
58
  id: params?.addressesId || ADDRESSES_ID,
59
59
  network: params?.networkType,
60
60
  },
61
- this.cache
61
+ { cache: this.cache }
62
62
  );
63
63
  }
64
64
 
@@ -69,9 +69,9 @@ export class Scallop {
69
69
  * @return Scallop Address.
70
70
  */
71
71
  public async getScallopAddress(id?: string) {
72
- await this._address.read(id);
72
+ await this.address.read(id);
73
73
 
74
- return this._address;
74
+ return this.address;
75
75
  }
76
76
 
77
77
  /**
@@ -80,11 +80,9 @@ export class Scallop {
80
80
  * @return Scallop Builder.
81
81
  */
82
82
  public async createScallopBuilder() {
83
- if (!this._address.getAddresses()) await this._address.read();
83
+ if (!this.address.getAddresses()) await this.address.read();
84
84
  const scallopBuilder = new ScallopBuilder(this.params, {
85
- suiKit: this.suiKit,
86
- address: this._address,
87
- cache: this.cache,
85
+ query: await this.createScallopQuery(),
88
86
  });
89
87
 
90
88
  return scallopBuilder;
@@ -97,10 +95,10 @@ export class Scallop {
97
95
  * @return Scallop Client.
98
96
  */
99
97
  public async createScallopClient(walletAddress?: string) {
100
- if (!this._address.getAddresses()) await this._address.read();
98
+ if (!this.address.getAddresses()) await this.address.read();
101
99
  const scallopClient = new ScallopClient(
102
100
  { ...this.params, walletAddress },
103
- { suiKit: this.suiKit, address: this._address, cache: this.cache }
101
+ { builder: await this.createScallopBuilder() }
104
102
  );
105
103
 
106
104
  return scallopClient;
@@ -112,11 +110,9 @@ export class Scallop {
112
110
  * @return Scallop Query.
113
111
  */
114
112
  public async createScallopQuery() {
115
- if (!this._address.getAddresses()) await this._address.read();
113
+ if (!this.address.getAddresses()) await this.address.read();
116
114
  const scallopQuery = new ScallopQuery(this.params, {
117
- suiKit: this.suiKit,
118
- address: this._address,
119
- cache: this.cache,
115
+ utils: await this.createScallopUtils(),
120
116
  });
121
117
 
122
118
  return scallopQuery;
@@ -141,11 +137,9 @@ export class Scallop {
141
137
  * @return Scallop Utils.
142
138
  */
143
139
  public async createScallopUtils() {
144
- if (!this._address.getAddresses()) await this._address.read();
140
+ if (!this.address.getAddresses()) await this.address.read();
145
141
  const scallopUtils = new ScallopUtils(this.params, {
146
- suiKit: this.suiKit,
147
- address: this._address,
148
- cache: this.cache,
142
+ address: this.address,
149
143
  });
150
144
 
151
145
  return scallopUtils;
@@ -1,9 +1,10 @@
1
1
  import { API_BASE_URL, USE_TEST_ADDRESS } from '../constants';
2
- import type { NetworkType } from '@scallop-io/sui-kit';
2
+ import { SuiKit, type NetworkType } from '@scallop-io/sui-kit';
3
3
  import type {
4
4
  ScallopAddressParams,
5
5
  AddressesInterface,
6
6
  AddressStringPath,
7
+ ScallopAddressInstanceParams,
7
8
  } from '../types';
8
9
  import { ScallopCache } from './scallopCache';
9
10
  import { DEFAULT_CACHE_OPTIONS } from 'src/constants/cache';
@@ -370,11 +371,20 @@ export class ScallopAddress {
370
371
  private _network: NetworkType;
371
372
  private _currentAddresses?: AddressesInterface;
372
373
  private _addressesMap: Map<NetworkType, AddressesInterface>;
373
- private _cache: ScallopCache;
374
+ public cache: ScallopCache;
374
375
 
375
- public constructor(params: ScallopAddressParams, cache?: ScallopCache) {
376
+ public constructor(
377
+ params: ScallopAddressParams,
378
+ instance?: ScallopAddressInstanceParams
379
+ ) {
376
380
  const { id, auth, network } = params;
377
- this._cache = cache ?? new ScallopCache(DEFAULT_CACHE_OPTIONS);
381
+ this.cache =
382
+ instance?.cache ??
383
+ new ScallopCache(
384
+ instance?.suiKit ?? new SuiKit({}),
385
+ DEFAULT_CACHE_OPTIONS
386
+ );
387
+
378
388
  this._requestClient = axios.create({
379
389
  baseURL: API_BASE_URL,
380
390
  headers: {
@@ -573,7 +583,7 @@ export class ScallopAddress {
573
583
  public async read(id?: string) {
574
584
  const addressesId = id || this._id || undefined;
575
585
  if (addressesId !== undefined) {
576
- const response = await this._cache.queryClient.fetchQuery({
586
+ const response = await this.cache.queryClient.fetchQuery({
577
587
  queryKey: ['api-getAddresses', addressesId],
578
588
  queryFn: async () => {
579
589
  return await this._requestClient.get(`/addresses/${addressesId}`, {
@@ -9,12 +9,13 @@ import type { SuiTransactionBlockResponse } from '@mysten/sui.js/client';
9
9
  import type { TransactionBlock } from '@mysten/sui.js/transactions';
10
10
  import type { SuiTxBlock as SuiKitTxBlock } from '@scallop-io/sui-kit';
11
11
  import type {
12
- ScallopInstanceParams,
13
12
  ScallopBuilderParams,
14
13
  ScallopTxBlock,
15
14
  SupportMarketCoins,
16
15
  SupportAssetCoins,
17
16
  SupportSCoin,
17
+ ScallopBuilderInstanceParams,
18
+ SelectCoinReturnType,
18
19
  } from '../types';
19
20
  import { ScallopCache } from './scallopCache';
20
21
  import { DEFAULT_CACHE_OPTIONS } from 'src/constants/cache';
@@ -43,39 +44,43 @@ export class ScallopBuilder {
43
44
 
44
45
  public constructor(
45
46
  params: ScallopBuilderParams,
46
- instance?: ScallopInstanceParams
47
+ instance?: ScallopBuilderInstanceParams
47
48
  ) {
48
- this.params = params;
49
49
  this.suiKit = instance?.suiKit ?? new SuiKit(params);
50
- this.cache =
51
- instance?.cache ?? new ScallopCache(DEFAULT_CACHE_OPTIONS, this.suiKit);
52
- this.address =
53
- instance?.address ??
54
- new ScallopAddress(
50
+
51
+ this.params = params;
52
+ this.walletAddress = normalizeSuiAddress(
53
+ params?.walletAddress || this.suiKit.currentAddress()
54
+ );
55
+
56
+ if (instance?.query) {
57
+ this.query = instance.query;
58
+ this.utils = this.query.utils;
59
+ this.address = this.utils.address;
60
+ this.cache = this.address.cache;
61
+ } else {
62
+ this.cache = new ScallopCache(this.suiKit, DEFAULT_CACHE_OPTIONS);
63
+ this.address = new ScallopAddress(
55
64
  {
56
65
  id: params?.addressesId || ADDRESSES_ID,
57
66
  network: params?.networkType,
58
67
  },
59
- this.cache
68
+ {
69
+ cache: this.cache,
70
+ }
60
71
  );
61
- this.query =
62
- instance?.query ??
63
- new ScallopQuery(params, {
64
- suiKit: this.suiKit,
65
- address: this.address,
66
- cache: this.cache,
67
- });
68
- this.utils =
69
- instance?.utils ??
70
- new ScallopUtils(this.params, {
71
- suiKit: this.suiKit,
72
+ this.utils = new ScallopUtils(this.params, {
72
73
  address: this.address,
73
- query: this.query,
74
- cache: this.cache,
75
74
  });
76
- this.walletAddress = normalizeSuiAddress(
77
- params?.walletAddress || this.suiKit.currentAddress()
78
- );
75
+ this.query = new ScallopQuery(
76
+ {
77
+ walletAddress: this.walletAddress,
78
+ },
79
+ {
80
+ utils: this.utils,
81
+ }
82
+ );
83
+ }
79
84
  this.isTestnet = params.networkType
80
85
  ? params.networkType === 'testnet'
81
86
  : false;
@@ -118,16 +123,21 @@ export class ScallopBuilder {
118
123
  * @param sender - Sender address.
119
124
  * @return Take coin and left coin.
120
125
  */
121
- public async selectCoin(
126
+ public async selectCoin<T extends SupportAssetCoins>(
122
127
  txBlock: ScallopTxBlock | SuiKitTxBlock,
123
- assetCoinName: SupportAssetCoins,
128
+ assetCoinName: T,
124
129
  amount: number,
125
130
  sender: string = this.walletAddress
126
- ) {
127
- const coinType = this.utils.parseCoinType(assetCoinName);
128
- const coins = await this.utils.selectCoins(amount, coinType, sender);
129
- const [takeCoin, leftCoin] = txBlock.takeAmountFromCoins(coins, amount);
130
- return { takeCoin, leftCoin };
131
+ ): Promise<SelectCoinReturnType<T>> {
132
+ if (assetCoinName === 'sui') {
133
+ const [takeCoin] = txBlock.splitSUIFromGas([amount]);
134
+ return { takeCoin } as SelectCoinReturnType<T>;
135
+ } else {
136
+ const coinType = this.utils.parseCoinType(assetCoinName);
137
+ const coins = await this.utils.selectCoins(amount, coinType, sender);
138
+ const [takeCoin, leftCoin] = txBlock.takeAmountFromCoins(coins, amount);
139
+ return { takeCoin, leftCoin } as SelectCoinReturnType<T>;
140
+ }
131
141
  }
132
142
 
133
143
  /**
@@ -46,12 +46,12 @@ type QueryInspectTxnParams = {
46
46
 
47
47
  export class ScallopCache {
48
48
  public readonly queryClient: QueryClient;
49
- public readonly _suiKit?: SuiKit;
49
+ public readonly _suiKit: SuiKit;
50
50
  private tokenBucket: TokenBucket;
51
51
 
52
52
  public constructor(
53
+ suiKit: SuiKit,
53
54
  cacheOptions?: QueryClientConfig,
54
- suiKit?: SuiKit,
55
55
  tokenBucket?: TokenBucket
56
56
  ) {
57
57
  this.queryClient = new QueryClient(cacheOptions ?? DEFAULT_CACHE_OPTIONS);