@scallop-io/sui-scallop-sdk 1.5.3 → 2.0.0-alpha.10
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.
- package/dist/index.d.mts +509 -602
- package/dist/index.d.ts +509 -602
- package/dist/index.js +28 -59
- package/dist/index.mjs +7 -7
- package/package.json +1 -1
- package/src/builders/coreBuilder.ts +33 -33
- package/src/builders/loyaltyProgramBuilder.ts +5 -3
- package/src/builders/{oracle.ts → oracles/index.ts} +48 -60
- package/src/builders/oracles/pyth.ts +44 -0
- package/src/builders/oracles/switchboard.ts +270 -0
- package/src/builders/referralBuilder.ts +5 -9
- package/src/builders/sCoinBuilder.ts +9 -8
- package/src/builders/spoolBuilder.ts +4 -6
- package/src/constants/common.ts +114 -126
- package/src/constants/index.ts +0 -5
- package/src/constants/pyth.ts +25 -34
- package/src/constants/queryKeys.ts +2 -0
- package/src/constants/testAddress.ts +36 -487
- package/src/models/index.ts +1 -0
- package/src/models/scallop.ts +23 -19
- package/src/models/scallopAddress.ts +17 -5
- package/src/models/scallopBuilder.ts +36 -41
- package/src/models/scallopCache.ts +3 -3
- package/src/models/scallopClient.ts +93 -98
- package/src/models/scallopConstants.ts +399 -0
- package/src/models/scallopIndexer.ts +11 -24
- package/src/models/scallopQuery.ts +76 -79
- package/src/models/scallopUtils.ts +126 -250
- package/src/queries/borrowIncentiveQuery.ts +25 -58
- package/src/queries/borrowLimitQuery.ts +3 -6
- package/src/queries/coreQuery.ts +98 -114
- package/src/queries/flashloanFeeQuery.ts +86 -0
- package/src/queries/index.ts +1 -0
- package/src/queries/isolatedAssetQuery.ts +12 -11
- package/src/queries/poolAddressesQuery.ts +211 -117
- package/src/queries/portfolioQuery.ts +60 -70
- package/src/queries/priceQuery.ts +16 -22
- package/src/queries/sCoinQuery.ts +15 -16
- package/src/queries/spoolQuery.ts +49 -59
- package/src/queries/supplyLimitQuery.ts +2 -6
- package/src/queries/switchboardQuery.ts +64 -0
- package/src/queries/xOracleQuery.ts +29 -32
- package/src/types/address.ts +21 -19
- package/src/types/builder/borrowIncentive.ts +2 -3
- package/src/types/builder/core.ts +20 -27
- package/src/types/builder/index.ts +1 -2
- package/src/types/builder/referral.ts +4 -8
- package/src/types/builder/sCoin.ts +4 -8
- package/src/types/builder/spool.ts +7 -10
- package/src/types/constant/common.ts +44 -49
- package/src/types/constant/enum.ts +15 -27
- package/src/types/constant/xOracle.ts +3 -2
- package/src/types/model.ts +49 -28
- package/src/types/query/borrowIncentive.ts +7 -24
- package/src/types/query/core.ts +8 -18
- package/src/types/query/portfolio.ts +9 -17
- package/src/types/query/spool.ts +5 -11
- package/src/types/utils.ts +1 -21
- package/src/utils/core.ts +1 -1
- package/src/utils/query.ts +15 -23
- package/src/utils/util.ts +6 -84
- package/src/constants/coinGecko.ts +0 -34
- package/src/constants/enum.ts +0 -268
- package/src/constants/flashloan.ts +0 -18
- package/src/constants/poolAddress.ts +0 -898
- package/src/models/scallopPrice.ts +0 -0
package/src/models/scallop.ts
CHANGED
|
@@ -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
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
169
|
+
constants: this.constants,
|
|
166
170
|
suiKit: this.suiKit,
|
|
167
171
|
}
|
|
168
172
|
);
|
|
@@ -217,8 +217,17 @@ const EMPTY_ADDRESSES: AddressesInterface = {
|
|
|
217
217
|
oracles: {
|
|
218
218
|
xOracle: '',
|
|
219
219
|
xOracleCap: '',
|
|
220
|
+
primaryPriceUpdatePolicyObject: '',
|
|
221
|
+
secondaryPriceUpdatePolicyObject: '',
|
|
222
|
+
primaryPriceUpdatePolicyVecsetId: '',
|
|
223
|
+
secondaryPriceUpdatePolicyVecsetId: '',
|
|
220
224
|
supra: { registry: '', registryCap: '', holder: '' },
|
|
221
|
-
switchboard: {
|
|
225
|
+
switchboard: {
|
|
226
|
+
registry: '',
|
|
227
|
+
registryCap: '',
|
|
228
|
+
registryTableId: '',
|
|
229
|
+
state: '',
|
|
230
|
+
},
|
|
222
231
|
pyth: {
|
|
223
232
|
registry: '',
|
|
224
233
|
registryCap: '',
|
|
@@ -406,6 +415,7 @@ const EMPTY_ADDRESSES: AddressesInterface = {
|
|
|
406
415
|
},
|
|
407
416
|
},
|
|
408
417
|
};
|
|
418
|
+
|
|
409
419
|
/**
|
|
410
420
|
* @description
|
|
411
421
|
* It provides methods for managing addresses.
|
|
@@ -417,6 +427,7 @@ const EMPTY_ADDRESSES: AddressesInterface = {
|
|
|
417
427
|
* await scallopAddress.<address async functions>();
|
|
418
428
|
* ```
|
|
419
429
|
*/
|
|
430
|
+
|
|
420
431
|
export class ScallopAddress {
|
|
421
432
|
private readonly _auth?: string;
|
|
422
433
|
private readonly _requestClient: AxiosInstance;
|
|
@@ -431,7 +442,7 @@ export class ScallopAddress {
|
|
|
431
442
|
params: ScallopAddressParams,
|
|
432
443
|
instance?: ScallopAddressInstanceParams
|
|
433
444
|
) {
|
|
434
|
-
const {
|
|
445
|
+
const { addressId, auth, network, forceAddressesInterface } = params;
|
|
435
446
|
this.cache = instance?.cache ?? new ScallopCache({});
|
|
436
447
|
|
|
437
448
|
this._requestClient = axios.create({
|
|
@@ -443,7 +454,8 @@ export class ScallopAddress {
|
|
|
443
454
|
timeout: 8000,
|
|
444
455
|
});
|
|
445
456
|
if (auth) this._auth = auth;
|
|
446
|
-
|
|
457
|
+
|
|
458
|
+
this._id = addressId;
|
|
447
459
|
this._network = network ?? 'mainnet';
|
|
448
460
|
this._addressesMap = USE_TEST_ADDRESS
|
|
449
461
|
? new Map([['mainnet', TEST_ADDRESSES]])
|
|
@@ -451,9 +463,9 @@ export class ScallopAddress {
|
|
|
451
463
|
if (USE_TEST_ADDRESS) this._currentAddresses = TEST_ADDRESSES;
|
|
452
464
|
|
|
453
465
|
// Set the addresses from the forceInterface if it is provided.
|
|
454
|
-
if (
|
|
466
|
+
if (forceAddressesInterface) {
|
|
455
467
|
for (const [network, addresses] of Object.entries<AddressesInterface>(
|
|
456
|
-
|
|
468
|
+
forceAddressesInterface
|
|
457
469
|
)) {
|
|
458
470
|
if (['localnet', 'devnet', 'testnet', 'mainnet'].includes(network)) {
|
|
459
471
|
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
|
-
|
|
63
|
-
|
|
64
|
-
this.
|
|
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
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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
|
|
105
|
-
if (
|
|
106
|
-
|
|
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
|
|
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
|
|
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:
|
|
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:
|
|
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
|
}
|
|
@@ -351,8 +351,8 @@ export class ScallopCache {
|
|
|
351
351
|
retryDelay: 1000,
|
|
352
352
|
queryKey: queryKeys.rpc.getOwnedObjects(input),
|
|
353
353
|
queryFn: async () => {
|
|
354
|
-
const results = await this.callWithRateLimit(
|
|
355
|
-
|
|
354
|
+
const results = await this.callWithRateLimit(() =>
|
|
355
|
+
this.client.getOwnedObjects(input)
|
|
356
356
|
);
|
|
357
357
|
if (results && results.data.length > 0) {
|
|
358
358
|
results.data
|