@scallop-io/sui-scallop-sdk 2.0.13-merge-split-ve-sca-alpha.5 → 2.1.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 (55) hide show
  1. package/dist/index.d.mts +622 -697
  2. package/dist/index.d.ts +622 -697
  3. package/dist/index.js +32 -33
  4. package/dist/index.mjs +10 -10
  5. package/package.json +8 -18
  6. package/src/builders/borrowIncentiveBuilder.ts +9 -21
  7. package/src/builders/coreBuilder.ts +2 -2
  8. package/src/builders/index.ts +2 -2
  9. package/src/builders/oracles/index.ts +2 -3
  10. package/src/builders/oracles/pyth.ts +2 -2
  11. package/src/builders/spoolBuilder.ts +2 -2
  12. package/src/builders/vescaBuilder.ts +14 -132
  13. package/src/constants/queryKeys.ts +29 -54
  14. package/src/constants/testAddress.ts +6 -12
  15. package/src/index.ts +11 -1
  16. package/src/models/index.ts +11 -9
  17. package/src/models/interface.ts +36 -0
  18. package/src/models/scallop.ts +38 -133
  19. package/src/models/scallopAddress.ts +127 -142
  20. package/src/models/scallopAxios.ts +185 -0
  21. package/src/models/scallopBuilder.ts +45 -75
  22. package/src/models/scallopClient.ts +124 -154
  23. package/src/models/scallopConstants.ts +248 -323
  24. package/src/models/scallopIndexer.ts +54 -98
  25. package/src/models/scallopQuery.ts +145 -190
  26. package/src/models/scallopQueryClient.ts +29 -0
  27. package/src/models/scallopSuiKit.ts +432 -0
  28. package/src/models/scallopUtils.ts +260 -164
  29. package/src/queries/borrowIncentiveQuery.ts +28 -16
  30. package/src/queries/borrowLimitQuery.ts +1 -1
  31. package/src/queries/coreQuery.ts +148 -107
  32. package/src/queries/flashloanFeeQuery.ts +12 -6
  33. package/src/queries/index.ts +0 -1
  34. package/src/queries/isolatedAssetQuery.ts +3 -3
  35. package/src/queries/loyaltyProgramQuery.ts +10 -8
  36. package/src/queries/ownerQuery.ts +32 -0
  37. package/src/queries/portfolioQuery.ts +4 -5
  38. package/src/queries/priceQuery.ts +14 -8
  39. package/src/queries/referralQuery.ts +9 -3
  40. package/src/queries/sCoinQuery.ts +4 -4
  41. package/src/queries/spoolQuery.ts +11 -11
  42. package/src/queries/supplyLimitQuery.ts +1 -1
  43. package/src/queries/switchboardQuery.ts +1 -1
  44. package/src/queries/vescaQuery.ts +31 -27
  45. package/src/queries/xOracleQuery.ts +13 -8
  46. package/src/types/address.ts +0 -3
  47. package/src/types/builder/core.ts +1 -1
  48. package/src/types/builder/vesca.ts +10 -20
  49. package/src/types/constant/queryKeys.ts +48 -0
  50. package/src/types/index.ts +0 -1
  51. package/src/utils/builder.ts +1 -1
  52. package/src/utils/util.ts +1 -33
  53. package/src/models/scallopCache.ts +0 -428
  54. package/src/queries/objectsQuery.ts +0 -18
  55. package/src/types/model.ts +0 -117
@@ -1,9 +1,5 @@
1
- import { normalizeSuiAddress } from '@mysten/sui/utils';
2
- import { SuiKit } from '@scallop-io/sui-kit';
3
1
  import { newScallopTxBlock } from '../builders';
4
- import { ScallopAddress } from './scallopAddress';
5
- import { ScallopQuery } from './scallopQuery';
6
- import { ScallopUtils } from './scallopUtils';
2
+ import ScallopQuery, { ScallopQueryParams } from './scallopQuery';
7
3
  import type { SuiTransactionBlockResponse } from '@mysten/sui/client';
8
4
  import type {
9
5
  Transaction,
@@ -16,15 +12,14 @@ import type {
16
12
  SuiTxArg,
17
13
  SuiVecTxArg,
18
14
  } from '@scallop-io/sui-kit';
19
- import type {
20
- ScallopBuilderParams,
21
- ScallopTxBlock,
22
- ScallopBuilderInstanceParams,
23
- SelectCoinReturnType,
24
- } from 'src/types';
25
- import { ScallopCache } from './scallopCache';
26
- import { newSuiKit } from './suiKit';
27
- import { ScallopConstants } from './scallopConstants';
15
+ import type { ScallopTxBlock, SelectCoinReturnType } from '../types';
16
+ import { ScallopBuilderInterface } from './interface';
17
+
18
+ export type ScallopBuilderParams = {
19
+ query?: ScallopQuery;
20
+ usePythPullModel?: boolean;
21
+ useOnChainXOracleList?: boolean;
22
+ } & ScallopQueryParams;
28
23
 
29
24
  /**
30
25
  * @description
@@ -37,74 +32,47 @@ import { ScallopConstants } from './scallopConstants';
37
32
  * const txBlock = scallopBuilder.<builder functions>();
38
33
  * ```
39
34
  */
40
- export class ScallopBuilder {
41
- public readonly params: ScallopBuilderParams;
42
- public readonly isTestnet: boolean;
35
+ class ScallopBuilder implements ScallopBuilderInterface {
36
+ public readonly query: ScallopQuery;
37
+ public readonly usePythPullModel: boolean;
38
+ public readonly useOnChainXOracleList: boolean;
43
39
 
44
- public suiKit: SuiKit;
45
- public address: ScallopAddress;
46
- public constants: ScallopConstants;
47
- public query: ScallopQuery;
48
- public utils: ScallopUtils;
49
- public walletAddress: string;
50
- public cache: ScallopCache;
51
-
52
- public constructor(
53
- params: ScallopBuilderParams,
54
- instance?: ScallopBuilderInstanceParams
55
- ) {
56
- this.suiKit = instance?.suiKit ?? newSuiKit(params);
57
-
58
- this.params = params;
59
- this.walletAddress = normalizeSuiAddress(
60
- params?.walletAddress ?? this.suiKit.currentAddress()
61
- );
40
+ public constructor(params: ScallopBuilderParams) {
41
+ this.query = params.query ?? new ScallopQuery(params);
42
+ this.usePythPullModel = params.usePythPullModel ?? true;
43
+ this.useOnChainXOracleList = params.useOnChainXOracleList ?? true;
44
+ }
62
45
 
63
- this.cache =
64
- instance?.query?.cache ??
65
- new ScallopCache(this.params, {
66
- suiKit: this.suiKit,
67
- });
46
+ get utils() {
47
+ return this.query.utils;
48
+ }
68
49
 
69
- this.address =
70
- instance?.query?.address ??
71
- new ScallopAddress(this.params, {
72
- cache: this.cache,
73
- });
50
+ get constants() {
51
+ return this.utils.constants;
52
+ }
74
53
 
75
- this.constants =
76
- instance?.query?.constants ??
77
- new ScallopConstants(this.params, {
78
- address: this.address,
79
- });
54
+ get walletAddress() {
55
+ return this.utils.walletAddress;
56
+ }
80
57
 
81
- this.utils =
82
- instance?.query?.utils ??
83
- new ScallopUtils(this.params, {
84
- constants: this.constants,
85
- });
58
+ get scallopSuiKit() {
59
+ return this.utils.scallopSuiKit;
60
+ }
86
61
 
87
- this.query =
88
- instance?.query ??
89
- new ScallopQuery(this.params, {
90
- utils: this.utils,
91
- });
62
+ get suiKit() {
63
+ return this.scallopSuiKit.suiKit;
64
+ }
92
65
 
93
- this.isTestnet = params.networkType
94
- ? params.networkType === 'testnet'
95
- : false;
66
+ get address() {
67
+ return this.utils.address;
96
68
  }
97
69
 
98
70
  /**
99
71
  * Request the scallop API to initialize data.
100
72
  *
101
73
  * @param force - Whether to force initialization.
102
- * @param address - ScallopAddress instance.
103
74
  */
104
- public async init(force: boolean = false) {
105
- if (force || !this.constants.isInitialized) {
106
- await this.constants.init();
107
- }
75
+ async init(force: boolean = false) {
108
76
  await this.query.init(force);
109
77
  }
110
78
 
@@ -114,7 +82,7 @@ export class ScallopBuilder {
114
82
  * @param txBlock - Scallop txBlock, txBlock created by SuiKit, or original transaction block.
115
83
  * @return Scallop txBlock.
116
84
  */
117
- public createTxBlock(txBlock?: ScallopTxBlock | SuiKitTxBlock | Transaction) {
85
+ createTxBlock(txBlock?: ScallopTxBlock | SuiKitTxBlock | Transaction) {
118
86
  return newScallopTxBlock(this, txBlock);
119
87
  }
120
88
 
@@ -127,7 +95,7 @@ export class ScallopBuilder {
127
95
  * @param sender - Sender address.
128
96
  * @return Take coin and left coin.
129
97
  */
130
- public async selectCoin<T extends string>(
98
+ async selectCoin<T extends string>(
131
99
  txBlock: ScallopTxBlock | SuiKitTxBlock,
132
100
  assetCoinName: T,
133
101
  amount: number,
@@ -153,7 +121,7 @@ export class ScallopBuilder {
153
121
  * @param sender - Sender address.
154
122
  * @return Take coin and left coin.
155
123
  */
156
- public async selectMarketCoin(
124
+ async selectMarketCoin(
157
125
  txBlock: ScallopTxBlock | SuiKitTxBlock,
158
126
  marketCoinName: string,
159
127
  amount: number,
@@ -181,7 +149,7 @@ export class ScallopBuilder {
181
149
  * @param sender - Sender address.
182
150
  * @return Take coin and left coin.
183
151
  */
184
- public async selectSCoin(
152
+ async selectSCoin(
185
153
  txBlock: ScallopTxBlock | SuiKitTxBlock,
186
154
  sCoinName: string,
187
155
  amount: number,
@@ -207,7 +175,7 @@ export class ScallopBuilder {
207
175
  /**
208
176
  * Select sCoin or market coin automatically. Prioritize sCoin first
209
177
  */
210
- public async selectSCoinOrMarketCoin(
178
+ async selectSCoinOrMarketCoin(
211
179
  txBlock: ScallopTxBlock | SuiKitTxBlock,
212
180
  sCoinName: string,
213
181
  amount: number,
@@ -282,10 +250,10 @@ export class ScallopBuilder {
282
250
  *
283
251
  * @param txBlock - Scallop txBlock, txBlock created by SuiKit, or original transaction block.
284
252
  */
285
- public async signAndSendTxBlock(
253
+ async signAndSendTxBlock(
286
254
  txBlock: ScallopTxBlock | SuiKitTxBlock | Transaction
287
255
  ) {
288
- return (await this.suiKit.signAndSendTxn(
256
+ return (await this.scallopSuiKit.suiKit.signAndSendTxn(
289
257
  txBlock
290
258
  )) as SuiTransactionBlockResponse;
291
259
  }
@@ -299,3 +267,5 @@ export class ScallopBuilder {
299
267
  return txb.moveCall(target, args, typeArgs);
300
268
  }
301
269
  }
270
+
271
+ export default ScallopBuilder;