@scallop-io/sui-scallop-sdk 2.1.7 → 2.1.9
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 +9 -4
- package/dist/index.d.ts +9 -4
- package/dist/index.js +29 -29
- package/dist/index.mjs +4 -4
- package/package.json +1 -1
- package/src/builders/vescaBuilder.ts +22 -0
- package/src/models/scallopAddress.ts +27 -16
- package/src/models/scallopConstants.ts +35 -22
- package/src/models/scallopSuiKit.ts +7 -1
- package/src/utils/util.ts +7 -0
package/package.json
CHANGED
|
@@ -490,6 +490,28 @@ const generateQuickVeScaMethod: GenerateVeScaQuickMethod = ({
|
|
|
490
490
|
);
|
|
491
491
|
}
|
|
492
492
|
|
|
493
|
+
const [sourceVesca, targetVesca] = await Promise.all([
|
|
494
|
+
getVeSca(builder.utils, sourceKey),
|
|
495
|
+
getVeSca(builder.utils, targetKey),
|
|
496
|
+
]);
|
|
497
|
+
|
|
498
|
+
if (!sourceVesca || !targetVesca) {
|
|
499
|
+
throw new Error('Source or target veSCA not found');
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
// Extend lock period to the max of both veSca
|
|
503
|
+
if (sourceVesca.unlockAt < targetVesca.unlockAt) {
|
|
504
|
+
txBlock.extendLockPeriod(
|
|
505
|
+
sourceVesca.keyId,
|
|
506
|
+
targetVesca.unlockAt / 1000
|
|
507
|
+
);
|
|
508
|
+
} else if (sourceVesca.unlockAt > targetVesca.unlockAt) {
|
|
509
|
+
txBlock.extendLockPeriod(
|
|
510
|
+
targetVesca.keyId,
|
|
511
|
+
sourceVesca.unlockAt / 1000
|
|
512
|
+
);
|
|
513
|
+
}
|
|
514
|
+
|
|
493
515
|
return txBlock.mergeVeSca(targetKey, sourceKey);
|
|
494
516
|
},
|
|
495
517
|
};
|
|
@@ -3,10 +3,14 @@ import { API_BASE_URL, queryKeys } from 'src/constants';
|
|
|
3
3
|
import { AddressesInterface, AddressStringPath } from 'src/types';
|
|
4
4
|
import ScallopAxios, { ScallopAxiosParams } from './scallopAxios';
|
|
5
5
|
import { QueryKey } from '@tanstack/query-core';
|
|
6
|
+
import { AxiosRequestConfig } from 'axios';
|
|
7
|
+
import { parseUrl } from 'src/utils';
|
|
6
8
|
|
|
7
9
|
export type ScallopAddressParams = {
|
|
8
10
|
addressId?: string;
|
|
9
|
-
|
|
11
|
+
urls?: {
|
|
12
|
+
addresses?: string[];
|
|
13
|
+
};
|
|
10
14
|
auth?: string;
|
|
11
15
|
network?: NetworkType;
|
|
12
16
|
forceAddressesInterface?: Partial<Record<NetworkType, AddressesInterface>>;
|
|
@@ -445,7 +449,6 @@ class ScallopAddress {
|
|
|
445
449
|
constructor(public readonly params: ScallopAddressParams = {}) {
|
|
446
450
|
this.scallopAxios = new ScallopAxios({
|
|
447
451
|
...this.defaultParamValues,
|
|
448
|
-
baseUrl: params.addressApiUrl || API_BASE_URL,
|
|
449
452
|
...params,
|
|
450
453
|
});
|
|
451
454
|
|
|
@@ -662,11 +665,13 @@ class ScallopAddress {
|
|
|
662
665
|
protected async readApi<T>({
|
|
663
666
|
url,
|
|
664
667
|
queryKey,
|
|
668
|
+
config,
|
|
665
669
|
}: {
|
|
666
670
|
url: string;
|
|
667
671
|
queryKey: QueryKey;
|
|
672
|
+
config?: AxiosRequestConfig;
|
|
668
673
|
}) {
|
|
669
|
-
const resp = await this.axiosClient.get<T>(url, queryKey);
|
|
674
|
+
const resp = await this.axiosClient.get<T>(url, queryKey, config);
|
|
670
675
|
if (resp.status === 200) {
|
|
671
676
|
return resp.data as T;
|
|
672
677
|
} else {
|
|
@@ -686,20 +691,26 @@ class ScallopAddress {
|
|
|
686
691
|
const addressId = id || this.addressId || undefined;
|
|
687
692
|
if (addressId !== undefined) {
|
|
688
693
|
const response = await (async () => {
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
694
|
+
const urls = (this.params.urls?.addresses ?? [API_BASE_URL]).map(
|
|
695
|
+
(url) => `${parseUrl(url)}/addresses/${addressId}`
|
|
696
|
+
);
|
|
697
|
+
for (const url of urls) {
|
|
698
|
+
try {
|
|
699
|
+
return await this.readApi<
|
|
700
|
+
Record<NetworkType, AddressesInterface> & { id?: string }
|
|
701
|
+
>({
|
|
702
|
+
url,
|
|
703
|
+
queryKey: queryKeys.api.getAddresses({ addressId }) as string[],
|
|
704
|
+
});
|
|
705
|
+
} catch (e) {
|
|
706
|
+
console.error(`${e}`); // Trying next url in the list
|
|
707
|
+
}
|
|
702
708
|
}
|
|
709
|
+
|
|
710
|
+
return {
|
|
711
|
+
id: '',
|
|
712
|
+
mainnet: this.defaultValues?.addresses?.mainnet ?? EMPTY_ADDRESSES,
|
|
713
|
+
};
|
|
703
714
|
})();
|
|
704
715
|
|
|
705
716
|
const isNetworkValid = (network: string): network is NetworkType =>
|
|
@@ -2,6 +2,7 @@ import { PoolAddress, Whitelist } from 'src/types';
|
|
|
2
2
|
import ScallopAddress, { ScallopAddressParams } from './scallopAddress';
|
|
3
3
|
import { NetworkType, parseStructTag } from '@scallop-io/sui-kit';
|
|
4
4
|
import { queryKeys } from 'src/constants';
|
|
5
|
+
import { parseUrl } from 'src/utils';
|
|
5
6
|
|
|
6
7
|
const isEmptyObject = (obj: object) => {
|
|
7
8
|
return Object.keys(obj).length === 0;
|
|
@@ -23,8 +24,10 @@ type SCoinRawName = string;
|
|
|
23
24
|
type SCoinName = string;
|
|
24
25
|
|
|
25
26
|
export type ScallopConstantsParams = {
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
urls?: {
|
|
28
|
+
poolAddresses?: string[];
|
|
29
|
+
whitelist?: string[];
|
|
30
|
+
};
|
|
28
31
|
forcePoolAddressInterface?: Record<string, PoolAddress>;
|
|
29
32
|
forceWhitelistInterface?: Whitelist | Record<string, any>;
|
|
30
33
|
defaultValues?: {
|
|
@@ -325,17 +328,22 @@ class ScallopConstants extends ScallopAddress {
|
|
|
325
328
|
|
|
326
329
|
async readWhiteList() {
|
|
327
330
|
const response = await (async () => {
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
331
|
+
const urls = (
|
|
332
|
+
this.params.urls?.whitelist ?? [
|
|
333
|
+
`https://sui.apis.scallop.io/pool/whitelist`,
|
|
334
|
+
]
|
|
335
|
+
).map(parseUrl);
|
|
336
|
+
for (const url of urls) {
|
|
337
|
+
try {
|
|
338
|
+
return await this.readApi<Record<keyof Whitelist, string[]>>({
|
|
339
|
+
url,
|
|
340
|
+
queryKey: queryKeys.api.getWhiteList(),
|
|
341
|
+
});
|
|
342
|
+
} catch (e) {
|
|
343
|
+
console.error(`${e}`); // Trying next url in the list
|
|
344
|
+
}
|
|
338
345
|
}
|
|
346
|
+
return this.defaultValues?.whitelist ?? DEFAULT_WHITELIST;
|
|
339
347
|
})();
|
|
340
348
|
|
|
341
349
|
return Object.fromEntries(
|
|
@@ -349,17 +357,22 @@ class ScallopConstants extends ScallopAddress {
|
|
|
349
357
|
}
|
|
350
358
|
|
|
351
359
|
async readPoolAddresses() {
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
360
|
+
const urls = (
|
|
361
|
+
this.params.urls?.poolAddresses ?? [
|
|
362
|
+
`https://sui.apis.scallop.io/pool/addresses`,
|
|
363
|
+
]
|
|
364
|
+
).map(parseUrl);
|
|
365
|
+
for (const url of urls) {
|
|
366
|
+
try {
|
|
367
|
+
return await this.readApi<Record<string, PoolAddress>>({
|
|
368
|
+
url,
|
|
369
|
+
queryKey: queryKeys.api.getPoolAddresses(),
|
|
370
|
+
});
|
|
371
|
+
} catch (e) {
|
|
372
|
+
console.error(`${e}`); // Trying next url in the list
|
|
373
|
+
}
|
|
362
374
|
}
|
|
375
|
+
return this.defaultValues?.poolAddresses ?? {};
|
|
363
376
|
}
|
|
364
377
|
}
|
|
365
378
|
|
|
@@ -163,7 +163,13 @@ class ScallopSuiKit extends ScallopQueryClient {
|
|
|
163
163
|
}
|
|
164
164
|
|
|
165
165
|
get currentFullNode() {
|
|
166
|
-
|
|
166
|
+
try {
|
|
167
|
+
// return current fullnode from SuiKit
|
|
168
|
+
return this.suiKit.suiInteractor.currentFullNode;
|
|
169
|
+
} catch (_) {
|
|
170
|
+
// SuiKit is initialized with custom sui clients, so no fullnodes can be read
|
|
171
|
+
return '';
|
|
172
|
+
}
|
|
167
173
|
}
|
|
168
174
|
|
|
169
175
|
signAndSendTxn(
|
package/src/utils/util.ts
CHANGED