@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.
- package/dist/constants/common.d.ts +1 -1
- package/dist/constants/pyth.d.ts +1 -1
- package/dist/index.js +1533 -1378
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1499 -1344
- package/dist/index.mjs.map +1 -1
- package/dist/models/scallop.d.ts +1 -1
- package/dist/models/scallopAddress.d.ts +4 -4
- package/dist/models/scallopBuilder.d.ts +3 -6
- package/dist/models/scallopCache.d.ts +2 -2
- package/dist/models/scallopClient.d.ts +7 -2
- package/dist/models/scallopIndexer.d.ts +3 -3
- package/dist/models/scallopPrice.d.ts +0 -0
- package/dist/models/scallopQuery.d.ts +10 -4
- package/dist/models/scallopUtils.d.ts +8 -7
- package/dist/queries/borrowIncentiveQuery.d.ts +10 -4
- package/dist/queries/coreQuery.d.ts +8 -4
- package/dist/queries/priceQuery.d.ts +7 -3
- package/dist/queries/referralQuery.d.ts +2 -2
- package/dist/queries/sCoinQuery.d.ts +18 -4
- package/dist/queries/spoolQuery.d.ts +10 -4
- package/dist/queries/vescaQuery.d.ts +7 -5
- package/dist/types/builder/index.d.ts +8 -1
- package/dist/types/builder/vesca.d.ts +2 -1
- package/dist/types/model.d.ts +27 -12
- package/dist/types/query/core.d.ts +1 -0
- package/dist/utils/query.d.ts +1 -1
- package/package.json +1 -1
- package/src/builders/borrowIncentiveBuilder.ts +19 -21
- package/src/builders/coreBuilder.ts +10 -8
- package/src/builders/spoolBuilder.ts +2 -2
- package/src/builders/vescaBuilder.ts +12 -4
- package/src/constants/common.ts +2 -0
- package/src/constants/enum.ts +4 -0
- package/src/constants/pyth.ts +2 -2
- package/src/models/scallop.ts +14 -20
- package/src/models/scallopAddress.ts +15 -5
- package/src/models/scallopBuilder.ts +42 -32
- package/src/models/scallopCache.ts +2 -2
- package/src/models/scallopClient.ts +91 -32
- package/src/models/scallopIndexer.ts +15 -8
- package/src/models/scallopPrice.ts +0 -0
- package/src/models/scallopQuery.ts +47 -25
- package/src/models/scallopUtils.ts +75 -74
- package/src/queries/borrowIncentiveQuery.ts +40 -29
- package/src/queries/coreQuery.ts +40 -26
- package/src/queries/portfolioQuery.ts +1 -2
- package/src/queries/priceQuery.ts +20 -9
- package/src/queries/referralQuery.ts +4 -4
- package/src/queries/sCoinQuery.ts +95 -17
- package/src/queries/spoolQuery.ts +26 -14
- package/src/queries/vescaQuery.ts +32 -26
- package/src/types/builder/index.ts +11 -1
- package/src/types/builder/vesca.ts +8 -1
- package/src/types/model.ts +40 -11
- package/src/types/query/core.ts +1 -0
- 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.
|
|
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
|
|
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:
|
|
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,
|
|
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:
|
|
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
|
|
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
|
-
|
|
274
|
+
obligationKeyArg,
|
|
275
275
|
veSca.keyId
|
|
276
276
|
);
|
|
277
277
|
} else {
|
|
278
|
-
txBlock.stakeObligation(obligationArg,
|
|
278
|
+
txBlock.stakeObligation(obligationArg, obligationKeyArg);
|
|
279
279
|
}
|
|
280
280
|
} else {
|
|
281
|
-
txBlock.stakeObligation(obligationArg,
|
|
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:
|
|
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,
|
|
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
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
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
|
-
|
|
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
|
|
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 =
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
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 =
|
|
420
|
-
|
|
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
|
|
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
|
|
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.
|
|
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
|
|
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
|
|
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
|
-
|
|
349
|
+
if (transferSca) {
|
|
350
|
+
txBlock.transferObjects([sca], sender);
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
353
|
+
return sca as RedeemScaQuickReturnType<S>;
|
|
346
354
|
}
|
|
347
355
|
},
|
|
348
356
|
};
|
package/src/constants/common.ts
CHANGED
package/src/constants/enum.ts
CHANGED
|
@@ -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
|
package/src/constants/pyth.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export const PYTH_ENDPOINTS: {
|
|
2
|
-
[k in 'mainnet' | 'testnet']:
|
|
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
|
-
}
|
|
6
|
+
};
|
package/src/models/scallop.ts
CHANGED
|
@@ -38,7 +38,7 @@ export class Scallop {
|
|
|
38
38
|
public suiKit: SuiKit;
|
|
39
39
|
public cache: ScallopCache;
|
|
40
40
|
|
|
41
|
-
private
|
|
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.
|
|
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.
|
|
72
|
+
await this.address.read(id);
|
|
73
73
|
|
|
74
|
-
return this.
|
|
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.
|
|
83
|
+
if (!this.address.getAddresses()) await this.address.read();
|
|
84
84
|
const scallopBuilder = new ScallopBuilder(this.params, {
|
|
85
|
-
|
|
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.
|
|
98
|
+
if (!this.address.getAddresses()) await this.address.read();
|
|
101
99
|
const scallopClient = new ScallopClient(
|
|
102
100
|
{ ...this.params, walletAddress },
|
|
103
|
-
{
|
|
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.
|
|
113
|
+
if (!this.address.getAddresses()) await this.address.read();
|
|
116
114
|
const scallopQuery = new ScallopQuery(this.params, {
|
|
117
|
-
|
|
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.
|
|
140
|
+
if (!this.address.getAddresses()) await this.address.read();
|
|
145
141
|
const scallopUtils = new ScallopUtils(this.params, {
|
|
146
|
-
|
|
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
|
|
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
|
-
|
|
374
|
+
public cache: ScallopCache;
|
|
374
375
|
|
|
375
|
-
public constructor(
|
|
376
|
+
public constructor(
|
|
377
|
+
params: ScallopAddressParams,
|
|
378
|
+
instance?: ScallopAddressInstanceParams
|
|
379
|
+
) {
|
|
376
380
|
const { id, auth, network } = params;
|
|
377
|
-
this.
|
|
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.
|
|
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?:
|
|
47
|
+
instance?: ScallopBuilderInstanceParams
|
|
47
48
|
) {
|
|
48
|
-
this.params = params;
|
|
49
49
|
this.suiKit = instance?.suiKit ?? new SuiKit(params);
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
this.
|
|
53
|
-
|
|
54
|
-
|
|
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
|
-
|
|
68
|
+
{
|
|
69
|
+
cache: this.cache,
|
|
70
|
+
}
|
|
60
71
|
);
|
|
61
|
-
|
|
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
|
-
|
|
77
|
-
|
|
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:
|
|
128
|
+
assetCoinName: T,
|
|
124
129
|
amount: number,
|
|
125
130
|
sender: string = this.walletAddress
|
|
126
|
-
) {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
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
|
|
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);
|