@scallop-io/sui-scallop-sdk 1.5.3 → 2.0.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 (60) hide show
  1. package/dist/index.d.mts +451 -602
  2. package/dist/index.d.ts +451 -602
  3. package/dist/index.js +29 -60
  4. package/dist/index.mjs +6 -6
  5. package/package.json +1 -1
  6. package/src/builders/loyaltyProgramBuilder.ts +5 -3
  7. package/src/builders/oracle.ts +10 -24
  8. package/src/builders/referralBuilder.ts +5 -9
  9. package/src/builders/sCoinBuilder.ts +9 -8
  10. package/src/builders/spoolBuilder.ts +4 -6
  11. package/src/constants/common.ts +114 -126
  12. package/src/constants/index.ts +0 -5
  13. package/src/constants/pyth.ts +25 -34
  14. package/src/constants/queryKeys.ts +2 -0
  15. package/src/models/index.ts +1 -0
  16. package/src/models/scallop.ts +23 -19
  17. package/src/models/scallopAddress.ts +7 -4
  18. package/src/models/scallopBuilder.ts +36 -41
  19. package/src/models/scallopCache.ts +1 -1
  20. package/src/models/scallopClient.ts +93 -94
  21. package/src/models/scallopConstants.ts +342 -0
  22. package/src/models/scallopIndexer.ts +11 -24
  23. package/src/models/scallopQuery.ts +70 -77
  24. package/src/models/scallopUtils.ts +122 -249
  25. package/src/queries/borrowIncentiveQuery.ts +21 -56
  26. package/src/queries/borrowLimitQuery.ts +3 -6
  27. package/src/queries/coreQuery.ts +94 -112
  28. package/src/queries/flashloanFeeQuery.ts +86 -0
  29. package/src/queries/isolatedAssetQuery.ts +12 -11
  30. package/src/queries/poolAddressesQuery.ts +187 -112
  31. package/src/queries/portfolioQuery.ts +65 -67
  32. package/src/queries/priceQuery.ts +16 -22
  33. package/src/queries/sCoinQuery.ts +15 -16
  34. package/src/queries/spoolQuery.ts +49 -59
  35. package/src/queries/supplyLimitQuery.ts +2 -6
  36. package/src/queries/xOracleQuery.ts +4 -15
  37. package/src/types/address.ts +12 -18
  38. package/src/types/builder/borrowIncentive.ts +2 -3
  39. package/src/types/builder/core.ts +20 -27
  40. package/src/types/builder/index.ts +1 -2
  41. package/src/types/builder/referral.ts +4 -8
  42. package/src/types/builder/sCoin.ts +4 -8
  43. package/src/types/builder/spool.ts +7 -10
  44. package/src/types/constant/common.ts +43 -49
  45. package/src/types/constant/enum.ts +15 -27
  46. package/src/types/constant/xOracle.ts +3 -5
  47. package/src/types/model.ts +49 -28
  48. package/src/types/query/borrowIncentive.ts +7 -24
  49. package/src/types/query/core.ts +8 -18
  50. package/src/types/query/portfolio.ts +8 -17
  51. package/src/types/query/spool.ts +5 -11
  52. package/src/types/utils.ts +1 -21
  53. package/src/utils/core.ts +1 -1
  54. package/src/utils/query.ts +13 -20
  55. package/src/utils/util.ts +6 -84
  56. package/src/constants/coinGecko.ts +0 -34
  57. package/src/constants/enum.ts +0 -268
  58. package/src/constants/flashloan.ts +0 -18
  59. package/src/constants/poolAddress.ts +0 -898
  60. package/src/models/scallopPrice.ts +0 -0
@@ -4,10 +4,10 @@ import { ScallopClient } from './scallopClient';
4
4
  import { ScallopBuilder } from './scallopBuilder';
5
5
  import { ScallopQuery } from './scallopQuery';
6
6
  import { ScallopUtils } from './scallopUtils';
7
- import { ADDRESS_ID } from '../constants';
8
7
  import type {
9
8
  ScallopBuilderParams,
10
9
  ScallopClientParams,
10
+ ScallopConstantsParams,
11
11
  ScallopParams,
12
12
  ScallopQueryParams,
13
13
  ScallopUtilsParams,
@@ -15,8 +15,9 @@ import type {
15
15
  import { ScallopIndexer } from './scallopIndexer';
16
16
  import { ScallopCache } from './scallopCache';
17
17
  import { QueryClientConfig } from '@tanstack/query-core';
18
- import type { QueryClient } from '@tanstack/query-core';
19
18
  import { newSuiKit } from './suiKit';
19
+ import { ScallopConstants } from './scallopConstants';
20
+ import type { QueryClient } from '@tanstack/query-core';
20
21
 
21
22
  /**
22
23
  * @argument params - The parameters for the Scallop instance.
@@ -41,6 +42,7 @@ export class Scallop {
41
42
  public cache: ScallopCache;
42
43
 
43
44
  private address: ScallopAddress;
45
+ private constants: ScallopConstants;
44
46
 
45
47
  public constructor(
46
48
  params: ScallopParams,
@@ -59,14 +61,15 @@ export class Scallop {
59
61
  queryClient,
60
62
  }
61
63
  );
62
- this.address = new ScallopAddress(
63
- {
64
- id: params?.addressId ?? ADDRESS_ID,
65
- network: params?.networkType,
66
- forceInterface: params?.forceAddressesInterface,
67
- },
68
- { cache: this.cache }
69
- );
64
+
65
+ this.address = new ScallopAddress(params, {
66
+ cache: this.cache,
67
+ });
68
+ this.constants = new ScallopConstants(params, { address: this.address });
69
+ }
70
+
71
+ private async initConstants(params?: Partial<ScallopConstantsParams>) {
72
+ if (!this.constants.isInitialized) await this.constants.init(params);
70
73
  }
71
74
 
72
75
  /**
@@ -86,8 +89,8 @@ export class Scallop {
86
89
  *
87
90
  * @return Scallop Builder.
88
91
  */
89
- public async createScallopBuilder(params?: ScallopBuilderParams) {
90
- if (!this.address.getAddresses()) await this.address.read();
92
+ public async createScallopBuilder(params?: Partial<ScallopBuilderParams>) {
93
+ await this.initConstants(params);
91
94
  const builderParams = {
92
95
  ...this.params,
93
96
  ...params,
@@ -105,8 +108,8 @@ export class Scallop {
105
108
  * @param walletAddress - When user cannot provide a secret key or mnemonic, the scallop client cannot directly derive the address of the transaction the user wants to sign. This argument specifies the wallet address for signing the transaction.
106
109
  * @return Scallop Client.
107
110
  */
108
- public async createScallopClient(params?: ScallopClientParams) {
109
- if (!this.address.getAddresses()) await this.address.read();
111
+ public async createScallopClient(params?: Partial<ScallopClientParams>) {
112
+ await this.initConstants(params);
110
113
  const clientParams = {
111
114
  ...this.params,
112
115
  ...params,
@@ -123,12 +126,13 @@ export class Scallop {
123
126
  *
124
127
  * @return Scallop Query.
125
128
  */
126
- public async createScallopQuery(params?: ScallopQueryParams) {
127
- if (!this.address.getAddresses()) await this.address.read();
129
+ public async createScallopQuery(params?: Partial<ScallopQueryParams>) {
130
+ await this.initConstants(params);
128
131
  const queryParams = {
129
132
  ...this.params,
130
133
  ...params,
131
134
  };
135
+
132
136
  const scallopQuery = new ScallopQuery(queryParams, {
133
137
  utils: await this.createScallopUtils(queryParams),
134
138
  });
@@ -154,15 +158,15 @@ export class Scallop {
154
158
  *
155
159
  * @return Scallop Utils.
156
160
  */
157
- public async createScallopUtils(params?: ScallopUtilsParams) {
158
- if (!this.address.getAddresses()) await this.address.read();
161
+ public async createScallopUtils(params?: Partial<ScallopUtilsParams>) {
162
+ await this.initConstants(params);
159
163
  const scallopUtils = new ScallopUtils(
160
164
  {
161
165
  ...this.params,
162
166
  ...params,
163
167
  },
164
168
  {
165
- address: this.address,
169
+ constants: this.constants,
166
170
  suiKit: this.suiKit,
167
171
  }
168
172
  );
@@ -406,6 +406,7 @@ const EMPTY_ADDRESSES: AddressesInterface = {
406
406
  },
407
407
  },
408
408
  };
409
+
409
410
  /**
410
411
  * @description
411
412
  * It provides methods for managing addresses.
@@ -417,6 +418,7 @@ const EMPTY_ADDRESSES: AddressesInterface = {
417
418
  * await scallopAddress.<address async functions>();
418
419
  * ```
419
420
  */
421
+
420
422
  export class ScallopAddress {
421
423
  private readonly _auth?: string;
422
424
  private readonly _requestClient: AxiosInstance;
@@ -431,7 +433,7 @@ export class ScallopAddress {
431
433
  params: ScallopAddressParams,
432
434
  instance?: ScallopAddressInstanceParams
433
435
  ) {
434
- const { id, auth, network, forceInterface } = params;
436
+ const { addressId, auth, network, forceAddressesInterface } = params;
435
437
  this.cache = instance?.cache ?? new ScallopCache({});
436
438
 
437
439
  this._requestClient = axios.create({
@@ -443,7 +445,8 @@ export class ScallopAddress {
443
445
  timeout: 8000,
444
446
  });
445
447
  if (auth) this._auth = auth;
446
- this._id = id;
448
+
449
+ this._id = addressId;
447
450
  this._network = network ?? 'mainnet';
448
451
  this._addressesMap = USE_TEST_ADDRESS
449
452
  ? new Map([['mainnet', TEST_ADDRESSES]])
@@ -451,9 +454,9 @@ export class ScallopAddress {
451
454
  if (USE_TEST_ADDRESS) this._currentAddresses = TEST_ADDRESSES;
452
455
 
453
456
  // Set the addresses from the forceInterface if it is provided.
454
- if (forceInterface) {
457
+ if (forceAddressesInterface) {
455
458
  for (const [network, addresses] of Object.entries<AddressesInterface>(
456
- forceInterface
459
+ forceAddressesInterface
457
460
  )) {
458
461
  if (['localnet', 'devnet', 'testnet', 'mainnet'].includes(network)) {
459
462
  if (network === this._network) this._currentAddresses = addresses;
@@ -1,6 +1,5 @@
1
1
  import { normalizeSuiAddress } from '@mysten/sui/utils';
2
2
  import { SuiKit } from '@scallop-io/sui-kit';
3
- import { ADDRESS_ID } from '../constants';
4
3
  import { newScallopTxBlock } from '../builders';
5
4
  import { ScallopAddress } from './scallopAddress';
6
5
  import { ScallopQuery } from './scallopQuery';
@@ -17,14 +16,12 @@ import type {
17
16
  import type {
18
17
  ScallopBuilderParams,
19
18
  ScallopTxBlock,
20
- SupportMarketCoins,
21
- SupportAssetCoins,
22
- SupportSCoin,
23
19
  ScallopBuilderInstanceParams,
24
20
  SelectCoinReturnType,
25
21
  } from '../types';
26
22
  import { ScallopCache } from './scallopCache';
27
23
  import { newSuiKit } from './suiKit';
24
+ import { ScallopConstants } from './scallopConstants';
28
25
 
29
26
  /**
30
27
  * @description
@@ -43,13 +40,14 @@ export class ScallopBuilder {
43
40
 
44
41
  public suiKit: SuiKit;
45
42
  public address: ScallopAddress;
43
+ public constants: ScallopConstants;
46
44
  public query: ScallopQuery;
47
45
  public utils: ScallopUtils;
48
46
  public walletAddress: string;
49
47
  public cache: ScallopCache;
50
48
 
51
49
  public constructor(
52
- params: ScallopBuilderParams = {},
50
+ params: ScallopBuilderParams,
53
51
  instance?: ScallopBuilderInstanceParams
54
52
  ) {
55
53
  this.suiKit = instance?.suiKit ?? newSuiKit(params);
@@ -59,37 +57,36 @@ export class ScallopBuilder {
59
57
  params?.walletAddress ?? this.suiKit.currentAddress()
60
58
  );
61
59
 
62
- if (instance?.query) {
63
- this.query = instance.query;
64
- this.utils = this.query.utils;
65
- this.address = this.utils.address;
66
- this.cache = this.address.cache;
67
- } else {
68
- this.cache = new ScallopCache(this.params, {
60
+ this.cache =
61
+ instance?.query?.cache ??
62
+ new ScallopCache(this.params, {
69
63
  suiKit: this.suiKit,
70
64
  });
71
- this.address = new ScallopAddress(
72
- {
73
- id: params?.addressId ?? ADDRESS_ID,
74
- network: params?.networkType,
75
- forceInterface: params?.forceAddressesInterface,
76
- },
77
- {
78
- cache: this.cache,
79
- }
80
- );
81
- this.utils = new ScallopUtils(this.params, {
65
+
66
+ this.address =
67
+ instance?.query?.address ??
68
+ new ScallopAddress(this.params, {
69
+ cache: this.cache,
70
+ });
71
+
72
+ this.constants =
73
+ instance?.query?.constants ??
74
+ new ScallopConstants(this.params, {
82
75
  address: this.address,
83
76
  });
84
- this.query = new ScallopQuery(
85
- {
86
- walletAddress: this.walletAddress,
87
- },
88
- {
89
- utils: this.utils,
90
- }
91
- );
92
- }
77
+
78
+ this.utils =
79
+ instance?.query?.utils ??
80
+ new ScallopUtils(this.params, {
81
+ constants: this.constants,
82
+ });
83
+
84
+ this.query =
85
+ instance?.query ??
86
+ new ScallopQuery(this.params, {
87
+ utils: this.utils,
88
+ });
89
+
93
90
  this.isTestnet = params.networkType
94
91
  ? params.networkType === 'testnet'
95
92
  : false;
@@ -101,13 +98,11 @@ export class ScallopBuilder {
101
98
  * @param force - Whether to force initialization.
102
99
  * @param address - ScallopAddress instance.
103
100
  */
104
- public async init(force: boolean = false, address?: ScallopAddress) {
105
- if (address && !this.address) this.address = address;
106
- if (force || !this.address.getAddresses()) {
107
- await this.address.read();
101
+ public async init(force: boolean = false) {
102
+ if (force || !this.constants.isInitialized) {
103
+ await this.constants.init();
108
104
  }
109
- await this.query.init(force, this.address);
110
- // await this.utils.init(force, this.address);
105
+ await this.query.init(force);
111
106
  }
112
107
 
113
108
  /**
@@ -129,7 +124,7 @@ export class ScallopBuilder {
129
124
  * @param sender - Sender address.
130
125
  * @return Take coin and left coin.
131
126
  */
132
- public async selectCoin<T extends SupportAssetCoins>(
127
+ public async selectCoin<T extends string>(
133
128
  txBlock: ScallopTxBlock | SuiKitTxBlock,
134
129
  assetCoinName: T,
135
130
  amount: number,
@@ -157,7 +152,7 @@ export class ScallopBuilder {
157
152
  */
158
153
  public async selectMarketCoin(
159
154
  txBlock: ScallopTxBlock | SuiKitTxBlock,
160
- marketCoinName: SupportMarketCoins,
155
+ marketCoinName: string,
161
156
  amount: number,
162
157
  sender: string = this.walletAddress
163
158
  ) {
@@ -185,7 +180,7 @@ export class ScallopBuilder {
185
180
  */
186
181
  public async selectSCoin(
187
182
  txBlock: ScallopTxBlock | SuiKitTxBlock,
188
- sCoinName: SupportSCoin,
183
+ sCoinName: string,
189
184
  amount: number,
190
185
  sender: string = this.walletAddress
191
186
  ) {
@@ -101,7 +101,7 @@ export class ScallopCache {
101
101
  // // if(cacheOptions.mutations)this.queryClient.setMutationDefaults(cacheOptions.mutations);
102
102
  // }
103
103
 
104
- this.tokens = this.tokensPerInterval;
104
+ this.tokens = this.tokensPerInterval; // Initial tokens value
105
105
  this.lastRefill = Date.now();
106
106
  this.walletAddress = params.walletAddress ?? this.suiKit.currentAddress();
107
107
  }