@scallop-io/sui-scallop-sdk 0.47.1 → 0.47.3
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 +272 -264
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +275 -267
- package/dist/index.mjs.map +1 -1
- package/dist/models/scallop.d.ts +5 -5
- package/dist/queries/borrowIncentiveQuery.d.ts +1 -1
- package/dist/types/model.d.ts +4 -3
- package/package.json +1 -1
- package/src/builders/borrowIncentiveBuilder.ts +10 -26
- package/src/builders/oracle.ts +8 -2
- package/src/builders/vescaBuilder.ts +2 -1
- package/src/models/scallop.ts +39 -16
- package/src/queries/borrowIncentiveQuery.ts +2 -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
|
}
|
|
@@ -56,4 +56,4 @@ export declare const getBindedObligationId: ({ address, }: {
|
|
|
56
56
|
}, veScaKeyId: string) => Promise<string | null>;
|
|
57
57
|
export declare const getBindedVeScaKey: ({ address, }: {
|
|
58
58
|
address: ScallopAddress;
|
|
59
|
-
},
|
|
59
|
+
}, obligationId: string) => Promise<string | null>;
|
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
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
import { TransactionBlock } from '@mysten/sui.js/transactions';
|
|
2
2
|
import { SUI_CLOCK_OBJECT_ID } from '@mysten/sui.js/utils';
|
|
3
3
|
import { SuiTxBlock as SuiKitTxBlock } from '@scallop-io/sui-kit';
|
|
4
|
-
import {
|
|
5
|
-
getObligations,
|
|
6
|
-
getObligationLocked,
|
|
7
|
-
getBindedObligationId,
|
|
8
|
-
} from '../queries';
|
|
4
|
+
import { getObligations, getObligationLocked } from '../queries';
|
|
9
5
|
import { requireSender } from '../utils';
|
|
10
6
|
import type { SuiObjectArg } from '@scallop-io/sui-kit';
|
|
11
7
|
import type { ScallopBuilder } from 'src/models';
|
|
@@ -18,7 +14,6 @@ import type {
|
|
|
18
14
|
ScallopTxBlock,
|
|
19
15
|
VescaIds,
|
|
20
16
|
} from '../types';
|
|
21
|
-
import { requireVeSca } from './vescaBuilder';
|
|
22
17
|
import { OLD_BORROW_INCENTIVE_PROTOCOL_ID } from 'src/constants';
|
|
23
18
|
|
|
24
19
|
/**
|
|
@@ -257,28 +252,17 @@ const generateBorrowIncentiveQuickMethod: GenerateBorrowIncentiveQuickMethod =
|
|
|
257
252
|
);
|
|
258
253
|
|
|
259
254
|
if (!obligationLocked || unstakeObligationBeforeStake) {
|
|
260
|
-
const
|
|
261
|
-
|
|
262
|
-
const bindedObligationId = await getBindedObligationId(
|
|
263
|
-
builder,
|
|
264
|
-
veSca.keyId
|
|
265
|
-
);
|
|
255
|
+
const bindedVeScaKey =
|
|
256
|
+
await builder.query.getBindedVeScaKey(obligationArg);
|
|
266
257
|
|
|
267
|
-
|
|
268
|
-
if (
|
|
269
|
-
(!bindedObligationId || bindedObligationId === obligationArg) &&
|
|
270
|
-
veSca.currentVeScaBalance > 0
|
|
271
|
-
) {
|
|
272
|
-
txBlock.stakeObligationWithVesca(
|
|
273
|
-
obligationArg,
|
|
274
|
-
obligationKeyArg,
|
|
275
|
-
veSca.keyId
|
|
276
|
-
);
|
|
277
|
-
} else {
|
|
278
|
-
txBlock.stakeObligation(obligationArg, obligationKeyArg);
|
|
279
|
-
}
|
|
280
|
-
} else {
|
|
258
|
+
if ((veScaKey && veScaKey !== bindedVeScaKey) || !bindedVeScaKey) {
|
|
281
259
|
txBlock.stakeObligation(obligationArg, obligationKeyArg);
|
|
260
|
+
} else {
|
|
261
|
+
txBlock.stakeObligationWithVesca(
|
|
262
|
+
obligationArg,
|
|
263
|
+
obligationKeyArg,
|
|
264
|
+
bindedVeScaKey
|
|
265
|
+
);
|
|
282
266
|
}
|
|
283
267
|
}
|
|
284
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'),
|
|
@@ -66,7 +66,8 @@ export const requireVeSca = async (
|
|
|
66
66
|
return undefined;
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
|
|
69
|
+
// return veSCA with the same veScaKey or the highest veSCA balance
|
|
70
|
+
return veScaKey ? veScas.find(({ keyId }) => veScaKey === keyId) : veScas[0];
|
|
70
71
|
};
|
|
71
72
|
|
|
72
73
|
/**
|
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
|
}
|
|
@@ -278,7 +278,7 @@ export const getBindedVeScaKey = async (
|
|
|
278
278
|
}: {
|
|
279
279
|
address: ScallopAddress;
|
|
280
280
|
},
|
|
281
|
-
|
|
281
|
+
obligationId: string
|
|
282
282
|
): Promise<string | null> => {
|
|
283
283
|
const borrowIncentiveObjectId = address.get('borrowIncentive.object');
|
|
284
284
|
const incentiveAccountsId = address.get('borrowIncentive.incentiveAccounts');
|
|
@@ -302,7 +302,7 @@ export const getBindedVeScaKey = async (
|
|
|
302
302
|
parentId: incentiveAccountsTableId,
|
|
303
303
|
name: {
|
|
304
304
|
type: `${borrowIncentiveObjectId}::typed_id::TypedID<${corePkg}::obligation::Obligation>`,
|
|
305
|
-
value:
|
|
305
|
+
value: obligationId,
|
|
306
306
|
},
|
|
307
307
|
});
|
|
308
308
|
|
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[];
|