@scallop-io/sui-scallop-sdk 0.47.2 → 0.47.4
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/builders/oracle.d.ts +4 -1
- package/dist/index.js +52 -30
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +52 -30
- package/dist/index.mjs.map +1 -1
- package/dist/models/scallop.d.ts +5 -5
- package/dist/models/scallopQuery.d.ts +4 -1
- package/dist/queries/vescaQuery.d.ts +1 -1
- package/dist/types/model.d.ts +4 -3
- package/package.json +1 -1
- package/src/builders/borrowIncentiveBuilder.ts +3 -8
- package/src/builders/oracle.ts +8 -2
- package/src/models/scallop.ts +39 -16
- package/src/models/scallopClient.ts +3 -1
- package/src/models/scallopQuery.ts +8 -2
- package/src/queries/vescaQuery.ts +8 -2
- package/src/types/model.ts +7 -3
package/dist/models/scallop.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { ScallopClient } from './scallopClient';
|
|
|
4
4
|
import { ScallopBuilder } from './scallopBuilder';
|
|
5
5
|
import { ScallopQuery } from './scallopQuery';
|
|
6
6
|
import { ScallopUtils } from './scallopUtils';
|
|
7
|
-
import type { ScallopParams } from '../types/';
|
|
7
|
+
import type { ScallopBuilderParams, ScallopClientParams, ScallopParams, ScallopQueryParams, ScallopUtilsParams } from '../types/';
|
|
8
8
|
import { ScallopIndexer } from './scallopIndexer';
|
|
9
9
|
import { ScallopCache } from './scallopCache';
|
|
10
10
|
import { QueryClientConfig } from '@tanstack/query-core';
|
|
@@ -44,20 +44,20 @@ export declare class Scallop {
|
|
|
44
44
|
*
|
|
45
45
|
* @return Scallop Builder.
|
|
46
46
|
*/
|
|
47
|
-
createScallopBuilder(): Promise<ScallopBuilder>;
|
|
47
|
+
createScallopBuilder(params?: ScallopBuilderParams): Promise<ScallopBuilder>;
|
|
48
48
|
/**
|
|
49
49
|
* Create a scallop client instance that already has initial data.
|
|
50
50
|
*
|
|
51
51
|
* @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.
|
|
52
52
|
* @return Scallop Client.
|
|
53
53
|
*/
|
|
54
|
-
createScallopClient(
|
|
54
|
+
createScallopClient(params?: ScallopClientParams): Promise<ScallopClient>;
|
|
55
55
|
/**
|
|
56
56
|
* Create a scallop query instance.
|
|
57
57
|
*
|
|
58
58
|
* @return Scallop Query.
|
|
59
59
|
*/
|
|
60
|
-
createScallopQuery(): Promise<ScallopQuery>;
|
|
60
|
+
createScallopQuery(params?: ScallopQueryParams): Promise<ScallopQuery>;
|
|
61
61
|
/**
|
|
62
62
|
* Create a scallop indexer instance.
|
|
63
63
|
*
|
|
@@ -69,5 +69,5 @@ export declare class Scallop {
|
|
|
69
69
|
*
|
|
70
70
|
* @return Scallop Utils.
|
|
71
71
|
*/
|
|
72
|
-
createScallopUtils(): Promise<ScallopUtils>;
|
|
72
|
+
createScallopUtils(params?: ScallopUtilsParams): Promise<ScallopUtils>;
|
|
73
73
|
}
|
|
@@ -386,7 +386,10 @@ export declare class ScallopQuery {
|
|
|
386
386
|
* @param walletAddress
|
|
387
387
|
* @returns array of veSca
|
|
388
388
|
*/
|
|
389
|
-
getVeScas(walletAddress?:
|
|
389
|
+
getVeScas({ walletAddress, excludeEmpty, }?: {
|
|
390
|
+
walletAddress?: string;
|
|
391
|
+
excludeEmpty?: boolean;
|
|
392
|
+
}): Promise<import("../types").Vesca[]>;
|
|
390
393
|
/**
|
|
391
394
|
* Get total vesca treasury with movecall
|
|
392
395
|
* @returns Promise<string | undefined>
|
|
@@ -18,7 +18,7 @@ export declare const getVescaKeys: (utils: ScallopUtils, ownerAddress?: string)
|
|
|
18
18
|
*/
|
|
19
19
|
export declare const getVeScas: ({ utils, }: {
|
|
20
20
|
utils: ScallopUtils;
|
|
21
|
-
}, ownerAddress?: string) => Promise<Vesca[]>;
|
|
21
|
+
}, ownerAddress?: string, excludeEmpty?: boolean) => Promise<Vesca[]>;
|
|
22
22
|
/**
|
|
23
23
|
* Get veSca data.
|
|
24
24
|
*
|
package/dist/types/model.d.ts
CHANGED
|
@@ -40,11 +40,12 @@ export type ScallopParams = {
|
|
|
40
40
|
addressesId?: string;
|
|
41
41
|
walletAddress?: string;
|
|
42
42
|
} & SuiKitParams;
|
|
43
|
-
export type ScallopClientParams = ScallopParams;
|
|
43
|
+
export type ScallopClientParams = ScallopParams & ScallopBuilderParams & ScallopQueryParams & ScallopUtilsParams;
|
|
44
44
|
export type ScallopBuilderParams = ScallopParams & {
|
|
45
45
|
pythEndpoints?: string[];
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
usePythPullModel?: boolean;
|
|
47
|
+
} & ScallopQueryParams;
|
|
48
|
+
export type ScallopQueryParams = ScallopParams & ScallopUtilsParams;
|
|
48
49
|
export type ScallopUtilsParams = ScallopParams & {
|
|
49
50
|
pythEndpoints?: string[];
|
|
50
51
|
};
|
package/package.json
CHANGED
|
@@ -255,19 +255,14 @@ const generateBorrowIncentiveQuickMethod: GenerateBorrowIncentiveQuickMethod =
|
|
|
255
255
|
const bindedVeScaKey =
|
|
256
256
|
await builder.query.getBindedVeScaKey(obligationArg);
|
|
257
257
|
|
|
258
|
-
if (veScaKey && veScaKey !== bindedVeScaKey) {
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
);
|
|
262
|
-
}
|
|
263
|
-
if (bindedVeScaKey) {
|
|
258
|
+
if ((veScaKey && veScaKey !== bindedVeScaKey) || !bindedVeScaKey) {
|
|
259
|
+
txBlock.stakeObligation(obligationArg, obligationKeyArg);
|
|
260
|
+
} else {
|
|
264
261
|
txBlock.stakeObligationWithVesca(
|
|
265
262
|
obligationArg,
|
|
266
263
|
obligationKeyArg,
|
|
267
264
|
bindedVeScaKey
|
|
268
265
|
);
|
|
269
|
-
} else {
|
|
270
|
-
txBlock.stakeObligation(obligationArg, obligationKeyArg);
|
|
271
266
|
}
|
|
272
267
|
}
|
|
273
268
|
},
|
package/src/builders/oracle.ts
CHANGED
|
@@ -16,17 +16,23 @@ import { PYTH_ENDPOINTS } from 'src/constants/pyth';
|
|
|
16
16
|
* @param builder - The scallop builder.
|
|
17
17
|
* @param txBlock - TxBlock created by SuiKit.
|
|
18
18
|
* @param assetCoinNames - Specific an array of support asset coin name.
|
|
19
|
+
* @param options - The options for update oracles.
|
|
19
20
|
*/
|
|
20
21
|
export const updateOracles = async (
|
|
21
22
|
builder: ScallopBuilder,
|
|
22
23
|
txBlock: SuiKitTxBlock,
|
|
23
|
-
assetCoinNames?: SupportAssetCoins[]
|
|
24
|
+
assetCoinNames?: SupportAssetCoins[],
|
|
25
|
+
options: {
|
|
26
|
+
usePythPullModel: boolean;
|
|
27
|
+
} = { usePythPullModel: true }
|
|
24
28
|
) => {
|
|
29
|
+
const usePythPullModel =
|
|
30
|
+
builder.params.usePythPullModel ?? options.usePythPullModel;
|
|
25
31
|
assetCoinNames = assetCoinNames ?? [
|
|
26
32
|
...new Set([...SUPPORT_POOLS, ...SUPPORT_COLLATERALS]),
|
|
27
33
|
];
|
|
28
34
|
const rules: SupportOracleType[] = builder.isTestnet ? ['pyth'] : ['pyth'];
|
|
29
|
-
if (rules.includes('pyth')) {
|
|
35
|
+
if (usePythPullModel && rules.includes('pyth')) {
|
|
30
36
|
const pythClient = new SuiPythClient(
|
|
31
37
|
builder.suiKit.client(),
|
|
32
38
|
builder.address.get('core.oracles.pyth.state'),
|
package/src/models/scallop.ts
CHANGED
|
@@ -5,7 +5,13 @@ import { ScallopBuilder } from './scallopBuilder';
|
|
|
5
5
|
import { ScallopQuery } from './scallopQuery';
|
|
6
6
|
import { ScallopUtils } from './scallopUtils';
|
|
7
7
|
import { ADDRESSES_ID } from '../constants';
|
|
8
|
-
import type {
|
|
8
|
+
import type {
|
|
9
|
+
ScallopBuilderParams,
|
|
10
|
+
ScallopClientParams,
|
|
11
|
+
ScallopParams,
|
|
12
|
+
ScallopQueryParams,
|
|
13
|
+
ScallopUtilsParams,
|
|
14
|
+
} from '../types/';
|
|
9
15
|
import { ScallopIndexer } from './scallopIndexer';
|
|
10
16
|
import { ScallopCache } from './scallopCache';
|
|
11
17
|
import { QueryClientConfig } from '@tanstack/query-core';
|
|
@@ -80,10 +86,14 @@ export class Scallop {
|
|
|
80
86
|
*
|
|
81
87
|
* @return Scallop Builder.
|
|
82
88
|
*/
|
|
83
|
-
public async createScallopBuilder() {
|
|
89
|
+
public async createScallopBuilder(params?: ScallopBuilderParams) {
|
|
84
90
|
if (!this.address.getAddresses()) await this.address.read();
|
|
85
|
-
const
|
|
86
|
-
|
|
91
|
+
const builderParams = {
|
|
92
|
+
...this.params,
|
|
93
|
+
...params,
|
|
94
|
+
};
|
|
95
|
+
const scallopBuilder = new ScallopBuilder(builderParams, {
|
|
96
|
+
query: await this.createScallopQuery(builderParams),
|
|
87
97
|
});
|
|
88
98
|
|
|
89
99
|
return scallopBuilder;
|
|
@@ -95,12 +105,15 @@ export class Scallop {
|
|
|
95
105
|
* @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.
|
|
96
106
|
* @return Scallop Client.
|
|
97
107
|
*/
|
|
98
|
-
public async createScallopClient(
|
|
108
|
+
public async createScallopClient(params?: ScallopClientParams) {
|
|
99
109
|
if (!this.address.getAddresses()) await this.address.read();
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
110
|
+
const clientParams = {
|
|
111
|
+
...this.params,
|
|
112
|
+
...params,
|
|
113
|
+
};
|
|
114
|
+
const scallopClient = new ScallopClient(clientParams, {
|
|
115
|
+
builder: await this.createScallopBuilder(clientParams),
|
|
116
|
+
});
|
|
104
117
|
|
|
105
118
|
return scallopClient;
|
|
106
119
|
}
|
|
@@ -110,10 +123,14 @@ export class Scallop {
|
|
|
110
123
|
*
|
|
111
124
|
* @return Scallop Query.
|
|
112
125
|
*/
|
|
113
|
-
public async createScallopQuery() {
|
|
126
|
+
public async createScallopQuery(params?: ScallopQueryParams) {
|
|
114
127
|
if (!this.address.getAddresses()) await this.address.read();
|
|
115
|
-
const
|
|
116
|
-
|
|
128
|
+
const queryParams = {
|
|
129
|
+
...this.params,
|
|
130
|
+
...params,
|
|
131
|
+
};
|
|
132
|
+
const scallopQuery = new ScallopQuery(queryParams, {
|
|
133
|
+
utils: await this.createScallopUtils(queryParams),
|
|
117
134
|
});
|
|
118
135
|
|
|
119
136
|
return scallopQuery;
|
|
@@ -137,11 +154,17 @@ export class Scallop {
|
|
|
137
154
|
*
|
|
138
155
|
* @return Scallop Utils.
|
|
139
156
|
*/
|
|
140
|
-
public async createScallopUtils() {
|
|
157
|
+
public async createScallopUtils(params?: ScallopUtilsParams) {
|
|
141
158
|
if (!this.address.getAddresses()) await this.address.read();
|
|
142
|
-
const scallopUtils = new ScallopUtils(
|
|
143
|
-
|
|
144
|
-
|
|
159
|
+
const scallopUtils = new ScallopUtils(
|
|
160
|
+
{
|
|
161
|
+
...this.params,
|
|
162
|
+
...params,
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
address: this.address,
|
|
166
|
+
}
|
|
167
|
+
);
|
|
145
168
|
|
|
146
169
|
return scallopUtils;
|
|
147
170
|
}
|
|
@@ -1095,7 +1095,9 @@ export class ScallopClient {
|
|
|
1095
1095
|
): Promise<ScallopClientVeScaReturnType<S>> {
|
|
1096
1096
|
// get all veSca keys
|
|
1097
1097
|
const veScaKeys = (
|
|
1098
|
-
(await this.query.getVeScas(
|
|
1098
|
+
(await this.query.getVeScas({
|
|
1099
|
+
walletAddress: this.walletAddress,
|
|
1100
|
+
})) ?? []
|
|
1099
1101
|
).map(({ keyObject }) => keyObject);
|
|
1100
1102
|
if (veScaKeys.length === 0) {
|
|
1101
1103
|
throw new Error('No veSCA found in the wallet');
|
|
@@ -579,8 +579,14 @@ export class ScallopQuery {
|
|
|
579
579
|
* @param walletAddress
|
|
580
580
|
* @returns array of veSca
|
|
581
581
|
*/
|
|
582
|
-
public async getVeScas(
|
|
583
|
-
|
|
582
|
+
public async getVeScas({
|
|
583
|
+
walletAddress = this.walletAddress,
|
|
584
|
+
excludeEmpty = false,
|
|
585
|
+
}: {
|
|
586
|
+
walletAddress?: string;
|
|
587
|
+
excludeEmpty?: boolean;
|
|
588
|
+
} = {}) {
|
|
589
|
+
return await getVeScas(this, walletAddress, excludeEmpty);
|
|
584
590
|
}
|
|
585
591
|
|
|
586
592
|
/**
|
|
@@ -70,7 +70,8 @@ export const getVeScas = async (
|
|
|
70
70
|
}: {
|
|
71
71
|
utils: ScallopUtils;
|
|
72
72
|
},
|
|
73
|
-
ownerAddress?: string
|
|
73
|
+
ownerAddress?: string,
|
|
74
|
+
excludeEmpty?: boolean
|
|
74
75
|
) => {
|
|
75
76
|
const keyObjectDatas = await getVescaKeys(utils, ownerAddress);
|
|
76
77
|
|
|
@@ -83,9 +84,14 @@ export const getVeScas = async (
|
|
|
83
84
|
});
|
|
84
85
|
await Promise.allSettled(tasks);
|
|
85
86
|
|
|
86
|
-
|
|
87
|
+
const result = veScas
|
|
87
88
|
.filter(Boolean)
|
|
88
89
|
.sort((a, b) => b!.currentVeScaBalance - a!.currentVeScaBalance);
|
|
90
|
+
|
|
91
|
+
if (excludeEmpty) {
|
|
92
|
+
return result.filter((v) => v.lockedScaAmount !== '0');
|
|
93
|
+
}
|
|
94
|
+
return result;
|
|
89
95
|
};
|
|
90
96
|
|
|
91
97
|
const SuiObjectRefZod = zod.object({
|
package/src/types/model.ts
CHANGED
|
@@ -66,13 +66,17 @@ export type ScallopParams = {
|
|
|
66
66
|
walletAddress?: string;
|
|
67
67
|
} & SuiKitParams;
|
|
68
68
|
|
|
69
|
-
export type ScallopClientParams = ScallopParams
|
|
69
|
+
export type ScallopClientParams = ScallopParams &
|
|
70
|
+
ScallopBuilderParams &
|
|
71
|
+
ScallopQueryParams &
|
|
72
|
+
ScallopUtilsParams;
|
|
70
73
|
|
|
71
74
|
export type ScallopBuilderParams = ScallopParams & {
|
|
72
75
|
pythEndpoints?: string[];
|
|
73
|
-
|
|
76
|
+
usePythPullModel?: boolean;
|
|
77
|
+
} & ScallopQueryParams;
|
|
74
78
|
|
|
75
|
-
export type ScallopQueryParams = ScallopParams;
|
|
79
|
+
export type ScallopQueryParams = ScallopParams & ScallopUtilsParams;
|
|
76
80
|
|
|
77
81
|
export type ScallopUtilsParams = ScallopParams & {
|
|
78
82
|
pythEndpoints?: string[];
|