@scallop-io/sui-scallop-sdk 0.47.2 → 1.3.0-alpha.1
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/borrowIncentiveBuilder.d.ts +2 -2
- package/dist/builders/coreBuilder.d.ts +2 -2
- package/dist/builders/index.d.ts +2 -2
- package/dist/builders/loyaltyProgramBuilder.d.ts +2 -2
- package/dist/builders/oracle.d.ts +4 -1
- package/dist/builders/referralBuilder.d.ts +2 -2
- package/dist/builders/sCoinBuilder.d.ts +2 -2
- package/dist/builders/spoolBuilder.d.ts +2 -2
- package/dist/builders/vescaBuilder.d.ts +2 -2
- package/dist/constants/common.d.ts +4 -4
- package/dist/constants/index.d.ts +1 -1
- package/dist/constants/vesca.d.ts +3 -3
- package/dist/index.js +125 -96
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +128 -102
- package/dist/index.mjs.map +1 -1
- package/dist/models/scallop.d.ts +5 -5
- package/dist/models/scallopBuilder.d.ts +10 -8
- package/dist/models/scallopCache.d.ts +5 -9
- package/dist/models/scallopClient.d.ts +2 -2
- package/dist/models/scallopQuery.d.ts +1 -1
- package/dist/models/scallopUtils.d.ts +2 -2
- package/dist/queries/coreQuery.d.ts +3 -3
- package/dist/queries/loyaltyProgramQuery.d.ts +1 -1
- package/dist/queries/priceQuery.d.ts +1 -1
- package/dist/queries/vescaQuery.d.ts +1 -1
- package/dist/test.d.ts +1 -0
- package/dist/types/builder/borrowIncentive.d.ts +1 -1
- package/dist/types/builder/core.d.ts +16 -16
- package/dist/types/builder/spool.d.ts +3 -3
- package/dist/types/builder/vesca.d.ts +5 -5
- package/dist/types/model.d.ts +8 -7
- package/dist/types/query/vesca.d.ts +1 -1
- package/dist/utils/query.d.ts +1 -1
- package/dist/utils/util.d.ts +1 -0
- package/package.json +13 -9
- package/src/builders/borrowIncentiveBuilder.ts +9 -14
- package/src/builders/coreBuilder.ts +15 -15
- package/src/builders/index.ts +2 -2
- package/src/builders/loyaltyProgramBuilder.ts +5 -5
- package/src/builders/oracle.ts +13 -6
- package/src/builders/referralBuilder.ts +6 -6
- package/src/builders/sCoinBuilder.ts +5 -8
- package/src/builders/spoolBuilder.ts +9 -9
- package/src/builders/vescaBuilder.ts +5 -5
- package/src/constants/common.ts +4 -4
- package/src/constants/index.ts +1 -1
- package/src/constants/vesca.ts +5 -6
- package/src/models/scallop.ts +39 -16
- package/src/models/scallopBuilder.ts +14 -7
- package/src/models/scallopCache.ts +43 -34
- package/src/models/scallopClient.ts +8 -6
- package/src/models/scallopQuery.ts +2 -2
- package/src/models/scallopUtils.ts +3 -3
- package/src/queries/borrowIncentiveQuery.ts +1 -1
- package/src/queries/coreQuery.ts +4 -4
- package/src/queries/loyaltyProgramQuery.ts +1 -1
- package/src/queries/priceQuery.ts +1 -1
- package/src/queries/sCoinQuery.ts +2 -2
- package/src/queries/spoolQuery.ts +4 -5
- package/src/queries/vescaQuery.ts +6 -3
- package/src/test.ts +26 -0
- package/src/types/address.ts +26 -26
- package/src/types/builder/borrowIncentive.ts +1 -1
- package/src/types/builder/core.ts +26 -28
- package/src/types/builder/spool.ts +2 -3
- package/src/types/builder/vesca.ts +5 -9
- package/src/types/model.ts +11 -10
- package/src/types/query/vesca.ts +1 -1
- package/src/utils/query.ts +1 -1
package/src/builders/oracle.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import { SUI_CLOCK_OBJECT_ID } from '@mysten/sui
|
|
1
|
+
import { SUI_CLOCK_OBJECT_ID } from '@mysten/sui/utils';
|
|
2
2
|
import {
|
|
3
3
|
SuiPythClient,
|
|
4
4
|
SuiPriceServiceConnection,
|
|
5
5
|
} from '@pythnetwork/pyth-sui-js';
|
|
6
6
|
import { SUPPORT_COLLATERALS, SUPPORT_POOLS } from '../constants';
|
|
7
|
-
import type { TransactionArgument } from '@mysten/sui
|
|
7
|
+
import type { TransactionArgument } from '@mysten/sui/transactions';
|
|
8
8
|
import type { SuiTxBlock as SuiKitTxBlock } from '@scallop-io/sui-kit';
|
|
9
9
|
import type { ScallopBuilder } from '../models';
|
|
10
10
|
import type { SupportAssetCoins, SupportOracleType } from '../types';
|
|
11
11
|
import { PYTH_ENDPOINTS } from 'src/constants/pyth';
|
|
12
|
+
import { TransactionBlock } from '@mysten/sui.js/transactions';
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
15
|
* Update the price of the oracle for multiple coin.
|
|
@@ -16,19 +17,25 @@ import { PYTH_ENDPOINTS } from 'src/constants/pyth';
|
|
|
16
17
|
* @param builder - The scallop builder.
|
|
17
18
|
* @param txBlock - TxBlock created by SuiKit.
|
|
18
19
|
* @param assetCoinNames - Specific an array of support asset coin name.
|
|
20
|
+
* @param options - The options for update oracles.
|
|
19
21
|
*/
|
|
20
22
|
export const updateOracles = async (
|
|
21
23
|
builder: ScallopBuilder,
|
|
22
24
|
txBlock: SuiKitTxBlock,
|
|
23
|
-
assetCoinNames?: SupportAssetCoins[]
|
|
25
|
+
assetCoinNames?: SupportAssetCoins[],
|
|
26
|
+
options: {
|
|
27
|
+
usePythPullModel: boolean;
|
|
28
|
+
} = { usePythPullModel: true }
|
|
24
29
|
) => {
|
|
30
|
+
const usePythPullModel =
|
|
31
|
+
builder.params.usePythPullModel ?? options.usePythPullModel;
|
|
25
32
|
assetCoinNames = assetCoinNames ?? [
|
|
26
33
|
...new Set([...SUPPORT_POOLS, ...SUPPORT_COLLATERALS]),
|
|
27
34
|
];
|
|
28
35
|
const rules: SupportOracleType[] = builder.isTestnet ? ['pyth'] : ['pyth'];
|
|
29
|
-
if (rules.includes('pyth')) {
|
|
36
|
+
if (usePythPullModel && rules.includes('pyth')) {
|
|
30
37
|
const pythClient = new SuiPythClient(
|
|
31
|
-
builder.
|
|
38
|
+
builder.oldSuiClient,
|
|
32
39
|
builder.address.get('core.oracles.pyth.state'),
|
|
33
40
|
builder.address.get('core.oracles.pyth.wormholeState')
|
|
34
41
|
);
|
|
@@ -46,7 +53,7 @@ export const updateOracles = async (
|
|
|
46
53
|
const priceUpdateData =
|
|
47
54
|
await pythConnection.getPriceFeedsUpdateData(priceIds);
|
|
48
55
|
await pythClient.updatePriceFeeds(
|
|
49
|
-
txBlock.txBlock
|
|
56
|
+
TransactionBlock.from(txBlock.serialize()), // convert txBlock to TransactionBlock because pyth sdk not support new @mysten/sui yet
|
|
50
57
|
priceUpdateData,
|
|
51
58
|
priceIds
|
|
52
59
|
);
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
SUI_CLOCK_OBJECT_ID,
|
|
5
5
|
SuiTxBlock as SuiKitTxBlock,
|
|
6
6
|
SuiObjectArg,
|
|
7
|
-
|
|
7
|
+
Transaction,
|
|
8
8
|
} from '@scallop-io/sui-kit';
|
|
9
9
|
import {
|
|
10
10
|
GenerateReferralNormalMethod,
|
|
@@ -39,7 +39,7 @@ const generateReferralNormalMethod: GenerateReferralNormalMethod = ({
|
|
|
39
39
|
`${referralIds.referralPgkId}::referral_bindings::bind_ve_sca_referrer`,
|
|
40
40
|
[
|
|
41
41
|
referralIds.referralBindings,
|
|
42
|
-
txBlock.pure(veScaKeyId),
|
|
42
|
+
txBlock.pure.id(veScaKeyId),
|
|
43
43
|
veScaTable,
|
|
44
44
|
SUI_CLOCK_OBJECT_ID,
|
|
45
45
|
],
|
|
@@ -141,14 +141,14 @@ const generateReferralQuickMethod: GenerateReferralQuickMethod = ({
|
|
|
141
141
|
*/
|
|
142
142
|
export const newReferralTxBlock = (
|
|
143
143
|
builder: ScallopBuilder,
|
|
144
|
-
initTxBlock?: ScallopTxBlock | SuiKitTxBlock |
|
|
144
|
+
initTxBlock?: ScallopTxBlock | SuiKitTxBlock | Transaction
|
|
145
145
|
) => {
|
|
146
146
|
const txBlock =
|
|
147
|
-
initTxBlock instanceof
|
|
147
|
+
initTxBlock instanceof Transaction
|
|
148
148
|
? new SuiKitTxBlock(initTxBlock)
|
|
149
149
|
: initTxBlock
|
|
150
|
-
|
|
151
|
-
|
|
150
|
+
? initTxBlock
|
|
151
|
+
: new SuiKitTxBlock();
|
|
152
152
|
|
|
153
153
|
const normalMethod = generateReferralNormalMethod({
|
|
154
154
|
builder,
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
TransactionBlock,
|
|
3
|
-
SuiTxBlock as SuiKitTxBlock,
|
|
4
|
-
} from '@scallop-io/sui-kit';
|
|
1
|
+
import { Transaction, SuiTxBlock as SuiKitTxBlock } from '@scallop-io/sui-kit';
|
|
5
2
|
import { ScallopBuilder } from 'src/models';
|
|
6
3
|
import {
|
|
7
4
|
BaseScallopTxBlock,
|
|
@@ -83,15 +80,15 @@ export const newSCoinTxBlock = (
|
|
|
83
80
|
initTxBlock?:
|
|
84
81
|
| ScallopTxBlock
|
|
85
82
|
| SuiKitTxBlock
|
|
86
|
-
|
|
|
83
|
+
| Transaction
|
|
87
84
|
| BaseScallopTxBlock
|
|
88
85
|
) => {
|
|
89
86
|
const txBlock =
|
|
90
|
-
initTxBlock instanceof
|
|
87
|
+
initTxBlock instanceof Transaction
|
|
91
88
|
? new SuiKitTxBlock(initTxBlock)
|
|
92
89
|
: initTxBlock
|
|
93
|
-
|
|
94
|
-
|
|
90
|
+
? initTxBlock
|
|
91
|
+
: new SuiKitTxBlock();
|
|
95
92
|
|
|
96
93
|
const normalMethod = generateSCoinNormalMethod({
|
|
97
94
|
builder,
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { SUI_CLOCK_OBJECT_ID } from '@mysten/sui
|
|
1
|
+
import { Transaction } from '@mysten/sui/transactions';
|
|
2
|
+
import { SUI_CLOCK_OBJECT_ID } from '@mysten/sui/utils';
|
|
3
3
|
import { SuiTxBlock as SuiKitTxBlock } from '@scallop-io/sui-kit';
|
|
4
4
|
import { spoolRewardCoins } from '../constants/enum';
|
|
5
5
|
import { getStakeAccounts } from '../queries/spoolQuery';
|
|
6
6
|
import { requireSender } from '../utils';
|
|
7
7
|
import type { SuiAddressArg } from '@scallop-io/sui-kit';
|
|
8
|
-
import type { TransactionResult } from '@mysten/sui
|
|
8
|
+
import type { TransactionResult } from '@mysten/sui/transactions';
|
|
9
9
|
import type { ScallopBuilder } from '../models';
|
|
10
10
|
import type {
|
|
11
11
|
SpoolIds,
|
|
@@ -166,10 +166,10 @@ const generateSpoolNormalMethod: GenerateSpoolNormalMethod = ({
|
|
|
166
166
|
claim: (stakeAccount, stakeMarketCoinName) => {
|
|
167
167
|
const stakePoolId = builder.address.get(
|
|
168
168
|
`spool.pools.${stakeMarketCoinName}.id`
|
|
169
|
-
);
|
|
169
|
+
) as string;
|
|
170
170
|
const rewardPoolId = builder.address.get(
|
|
171
171
|
`spool.pools.${stakeMarketCoinName}.rewardPoolId`
|
|
172
|
-
);
|
|
172
|
+
) as string;
|
|
173
173
|
const marketCoinType =
|
|
174
174
|
builder.utils.parseMarketCoinType(stakeMarketCoinName);
|
|
175
175
|
const rewardCoinName = spoolRewardCoins[stakeMarketCoinName];
|
|
@@ -317,15 +317,15 @@ export const newSpoolTxBlock = (
|
|
|
317
317
|
initTxBlock?:
|
|
318
318
|
| ScallopTxBlock
|
|
319
319
|
| SuiKitTxBlock
|
|
320
|
-
|
|
|
320
|
+
| Transaction
|
|
321
321
|
| SuiTxBlockWithSCoin
|
|
322
322
|
) => {
|
|
323
323
|
const txBlock =
|
|
324
|
-
initTxBlock instanceof
|
|
324
|
+
initTxBlock instanceof Transaction
|
|
325
325
|
? new SuiKitTxBlock(initTxBlock)
|
|
326
326
|
: initTxBlock
|
|
327
|
-
|
|
328
|
-
|
|
327
|
+
? initTxBlock
|
|
328
|
+
: new SuiKitTxBlock();
|
|
329
329
|
|
|
330
330
|
const normalMethod = generateSpoolNormalMethod({
|
|
331
331
|
builder,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
SUI_CLOCK_OBJECT_ID,
|
|
3
3
|
SuiTxBlock,
|
|
4
|
-
|
|
4
|
+
Transaction,
|
|
5
5
|
SuiTxBlock as SuiKitTxBlock,
|
|
6
6
|
} from '@scallop-io/sui-kit';
|
|
7
7
|
import { SCA_COIN_TYPE } from 'src/constants';
|
|
@@ -366,14 +366,14 @@ const generateQuickVeScaMethod: GenerateVeScaQuickMethod = ({
|
|
|
366
366
|
*/
|
|
367
367
|
export const newVeScaTxBlock = (
|
|
368
368
|
builder: ScallopBuilder,
|
|
369
|
-
initTxBlock?: ScallopTxBlock | SuiKitTxBlock |
|
|
369
|
+
initTxBlock?: ScallopTxBlock | SuiKitTxBlock | Transaction
|
|
370
370
|
) => {
|
|
371
371
|
const txBlock =
|
|
372
|
-
initTxBlock instanceof
|
|
372
|
+
initTxBlock instanceof Transaction
|
|
373
373
|
? new SuiKitTxBlock(initTxBlock)
|
|
374
374
|
: initTxBlock
|
|
375
|
-
|
|
376
|
-
|
|
375
|
+
? initTxBlock
|
|
376
|
+
: new SuiKitTxBlock();
|
|
377
377
|
|
|
378
378
|
const normalMethod = generateNormalVeScaMethod({
|
|
379
379
|
builder,
|
package/src/constants/common.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// export const API_BASE_URL = 'https://sui.api.scallop.io';
|
|
2
|
-
export const API_BASE_URL = 'https://sui.apis.scallop.io';
|
|
3
|
-
export const SDK_API_BASE_URL = 'https://sdk.api.scallop.io';
|
|
2
|
+
export const API_BASE_URL = 'https://sui.apis.scallop.io' as const;
|
|
3
|
+
export const SDK_API_BASE_URL = 'https://sdk.api.scallop.io' as const;
|
|
4
4
|
|
|
5
|
-
export const IS_VE_SCA_TEST = false;
|
|
6
|
-
export const USE_TEST_ADDRESS = false;
|
|
5
|
+
export const IS_VE_SCA_TEST: boolean = false;
|
|
6
|
+
export const USE_TEST_ADDRESS: boolean = false;
|
|
7
7
|
|
|
8
8
|
export const ADDRESSES_ID =
|
|
9
9
|
IS_VE_SCA_TEST || USE_TEST_ADDRESS
|
package/src/constants/index.ts
CHANGED
package/src/constants/vesca.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
export const UNLOCK_ROUND_DURATION = 60 * 60 * 24; // 1
|
|
2
|
-
export const MAX_LOCK_ROUNDS
|
|
3
|
-
export const MAX_LOCK_DURATION
|
|
4
|
-
MAX_LOCK_ROUNDS * UNLOCK_ROUND_DURATION; // 4 years in seconds
|
|
1
|
+
export const UNLOCK_ROUND_DURATION = 60 * 60 * 24; // 1 day in seconds
|
|
2
|
+
export const MAX_LOCK_ROUNDS = 1460 as const; // 4 years in days (or 9 days for testing)
|
|
3
|
+
export const MAX_LOCK_DURATION = MAX_LOCK_ROUNDS * UNLOCK_ROUND_DURATION; // 4 years in seconds
|
|
5
4
|
|
|
6
|
-
export const MIN_INITIAL_LOCK_AMOUNT
|
|
7
|
-
export const MIN_TOP_UP_AMOUNT
|
|
5
|
+
export const MIN_INITIAL_LOCK_AMOUNT = 10_000_000_000 as const;
|
|
6
|
+
export const MIN_TOP_UP_AMOUNT = 1_000_000_000 as const;
|
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
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { normalizeSuiAddress } from '@mysten/sui
|
|
1
|
+
import { normalizeSuiAddress } from '@mysten/sui/utils';
|
|
2
2
|
import { SuiKit } from '@scallop-io/sui-kit';
|
|
3
3
|
import { ADDRESSES_ID } from '../constants';
|
|
4
4
|
import { newScallopTxBlock } from '../builders';
|
|
5
5
|
import { ScallopAddress } from './scallopAddress';
|
|
6
6
|
import { ScallopQuery } from './scallopQuery';
|
|
7
7
|
import { ScallopUtils } from './scallopUtils';
|
|
8
|
-
import type { SuiTransactionBlockResponse } from '@mysten/sui
|
|
9
|
-
import type {
|
|
8
|
+
import type { SuiTransactionBlockResponse } from '@mysten/sui/client';
|
|
9
|
+
import type { Transaction } from '@mysten/sui/transactions';
|
|
10
10
|
import type { SuiTxBlock as SuiKitTxBlock } from '@scallop-io/sui-kit';
|
|
11
11
|
import type {
|
|
12
12
|
ScallopBuilderParams,
|
|
@@ -19,6 +19,7 @@ import type {
|
|
|
19
19
|
} from '../types';
|
|
20
20
|
import { ScallopCache } from './scallopCache';
|
|
21
21
|
import { DEFAULT_CACHE_OPTIONS } from 'src/constants/cache';
|
|
22
|
+
import { SuiClient as SuiClientV0 } from '@mysten/sui.js/client';
|
|
22
23
|
|
|
23
24
|
/**
|
|
24
25
|
* @description
|
|
@@ -42,6 +43,9 @@ export class ScallopBuilder {
|
|
|
42
43
|
public walletAddress: string;
|
|
43
44
|
public cache: ScallopCache;
|
|
44
45
|
|
|
46
|
+
// For compatibility with pyth sdk
|
|
47
|
+
public oldSuiClient: SuiClientV0;
|
|
48
|
+
|
|
45
49
|
public constructor(
|
|
46
50
|
params: ScallopBuilderParams,
|
|
47
51
|
instance?: ScallopBuilderInstanceParams
|
|
@@ -88,6 +92,11 @@ export class ScallopBuilder {
|
|
|
88
92
|
this.isTestnet = params.networkType
|
|
89
93
|
? params.networkType === 'testnet'
|
|
90
94
|
: false;
|
|
95
|
+
|
|
96
|
+
// intitialize old Sui Client version
|
|
97
|
+
this.oldSuiClient = new SuiClientV0({
|
|
98
|
+
url: this.suiKit.suiInteractor.currentFullNode,
|
|
99
|
+
});
|
|
91
100
|
}
|
|
92
101
|
|
|
93
102
|
/**
|
|
@@ -112,9 +121,7 @@ export class ScallopBuilder {
|
|
|
112
121
|
* @param txBlock - Scallop txBlock, txBlock created by SuiKit, or original transaction block.
|
|
113
122
|
* @return Scallop txBlock.
|
|
114
123
|
*/
|
|
115
|
-
public createTxBlock(
|
|
116
|
-
txBlock?: ScallopTxBlock | SuiKitTxBlock | TransactionBlock
|
|
117
|
-
) {
|
|
124
|
+
public createTxBlock(txBlock?: ScallopTxBlock | SuiKitTxBlock | Transaction) {
|
|
118
125
|
return newScallopTxBlock(this, txBlock);
|
|
119
126
|
}
|
|
120
127
|
|
|
@@ -210,7 +217,7 @@ export class ScallopBuilder {
|
|
|
210
217
|
* @param txBlock - Scallop txBlock, txBlock created by SuiKit, or original transaction block.
|
|
211
218
|
*/
|
|
212
219
|
public async signAndSendTxBlock(
|
|
213
|
-
txBlock: ScallopTxBlock | SuiKitTxBlock |
|
|
220
|
+
txBlock: ScallopTxBlock | SuiKitTxBlock | Transaction
|
|
214
221
|
) {
|
|
215
222
|
return (await this.suiKit.signAndSendTxn(
|
|
216
223
|
txBlock
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { QueryClient, QueryClientConfig } from '@tanstack/query-core';
|
|
2
2
|
import {
|
|
3
|
-
|
|
3
|
+
SuiObjectArg,
|
|
4
4
|
SuiTxBlock,
|
|
5
5
|
normalizeStructTag,
|
|
6
6
|
normalizeSuiAddress,
|
|
@@ -17,7 +17,7 @@ import type {
|
|
|
17
17
|
GetDynamicFieldObjectParams,
|
|
18
18
|
GetBalanceParams,
|
|
19
19
|
SuiClient,
|
|
20
|
-
} from '@mysten/sui
|
|
20
|
+
} from '@mysten/sui/client';
|
|
21
21
|
import { DEFAULT_CACHE_OPTIONS } from 'src/constants/cache';
|
|
22
22
|
import { callWithRateLimit, TokenBucket } from 'src/utils';
|
|
23
23
|
import {
|
|
@@ -27,7 +27,7 @@ import {
|
|
|
27
27
|
|
|
28
28
|
type QueryInspectTxnParams = {
|
|
29
29
|
queryTarget: string;
|
|
30
|
-
args:
|
|
30
|
+
args: SuiObjectArg[];
|
|
31
31
|
typeArgs?: any[];
|
|
32
32
|
};
|
|
33
33
|
|
|
@@ -92,20 +92,43 @@ export class ScallopCache {
|
|
|
92
92
|
});
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
95
|
+
public async resolveArgs(
|
|
96
|
+
txb: SuiTxBlock,
|
|
97
|
+
args: SuiObjectArg[]
|
|
98
|
+
): Promise<SuiObjectArg[]> {
|
|
99
|
+
return await Promise.all(
|
|
100
|
+
args.map(async (arg) => {
|
|
101
|
+
if (typeof arg === 'string') {
|
|
102
|
+
const objData = (await this.queryGetObject(arg, { showOwner: true }))
|
|
103
|
+
?.data;
|
|
104
|
+
if (!objData) return arg;
|
|
105
|
+
const owner = objData?.owner as any;
|
|
106
|
+
if (!owner) return arg;
|
|
107
|
+
|
|
108
|
+
if ('Shared' in owner) {
|
|
109
|
+
return txb.sharedObjectRef({
|
|
110
|
+
objectId: objData.objectId,
|
|
111
|
+
initialSharedVersion: owner.Shared.initial_shared_version,
|
|
112
|
+
mutable: true,
|
|
113
|
+
});
|
|
114
|
+
} else {
|
|
115
|
+
return txb.objectRef({
|
|
116
|
+
objectId: objData.objectId,
|
|
117
|
+
version: objData.version,
|
|
118
|
+
digest: objData.digest,
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
} else if ('objectId' in arg && 'version' in arg && 'digest' in arg) {
|
|
122
|
+
return txb.objectRef({
|
|
123
|
+
objectId: arg.objectId,
|
|
124
|
+
version: arg.version as string,
|
|
125
|
+
digest: arg.digest,
|
|
126
|
+
});
|
|
127
|
+
} else {
|
|
128
|
+
return arg;
|
|
129
|
+
}
|
|
130
|
+
})
|
|
131
|
+
);
|
|
109
132
|
}
|
|
110
133
|
|
|
111
134
|
/**
|
|
@@ -121,23 +144,9 @@ export class ScallopCache {
|
|
|
121
144
|
}: QueryInspectTxnParams): Promise<DevInspectResults | null> {
|
|
122
145
|
const txBlock = new SuiTxBlock();
|
|
123
146
|
|
|
124
|
-
|
|
125
|
-
const resolvedArgs = await Promise.all(
|
|
126
|
-
args.map(async (arg) => {
|
|
127
|
-
if (typeof arg === 'string') {
|
|
128
|
-
return (await this.queryGetObject(arg, { showContent: true }))?.data;
|
|
129
|
-
}
|
|
130
|
-
return arg;
|
|
131
|
-
})
|
|
132
|
-
);
|
|
133
|
-
txBlock.moveCall(queryTarget, resolvedArgs, typeArgs);
|
|
147
|
+
const resolvedArgs = await this.resolveArgs(txBlock, args);
|
|
134
148
|
|
|
135
|
-
|
|
136
|
-
const txBytes = await txBlock.txBlock.build({
|
|
137
|
-
client: this.client,
|
|
138
|
-
onlyTransactionKind: true,
|
|
139
|
-
protocolConfig: (await this.getProtocolConfig()) ?? undefined,
|
|
140
|
-
});
|
|
149
|
+
txBlock.moveCall(queryTarget, resolvedArgs, typeArgs);
|
|
141
150
|
|
|
142
151
|
const query = await this.queryClient.fetchQuery({
|
|
143
152
|
queryKey: typeArgs
|
|
@@ -150,7 +159,7 @@ export class ScallopCache {
|
|
|
150
159
|
],
|
|
151
160
|
queryFn: async () => {
|
|
152
161
|
return await callWithRateLimit(this.tokenBucket, () =>
|
|
153
|
-
this.suiKit.inspectTxn(
|
|
162
|
+
this.suiKit.inspectTxn(txBlock)
|
|
154
163
|
);
|
|
155
164
|
},
|
|
156
165
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { normalizeSuiAddress } from '@mysten/sui
|
|
1
|
+
import { normalizeSuiAddress } from '@mysten/sui/utils';
|
|
2
2
|
import { SuiKit } from '@scallop-io/sui-kit';
|
|
3
3
|
import { DEFAULT_CACHE_OPTIONS } from 'src/constants/cache';
|
|
4
4
|
import {
|
|
@@ -12,13 +12,13 @@ import { ScallopAddress } from './scallopAddress';
|
|
|
12
12
|
import { ScallopUtils } from './scallopUtils';
|
|
13
13
|
import { ScallopBuilder } from './scallopBuilder';
|
|
14
14
|
import { ScallopQuery } from './scallopQuery';
|
|
15
|
-
import {
|
|
16
|
-
import { requireSender } from 'src/utils';
|
|
17
|
-
import type { SuiTransactionBlockResponse } from '@mysten/sui.js/client';
|
|
15
|
+
import type { SuiTransactionBlockResponse } from '@mysten/sui/client';
|
|
18
16
|
import type {
|
|
19
17
|
TransactionObjectArgument,
|
|
20
18
|
TransactionResult,
|
|
21
|
-
} from '@mysten/sui
|
|
19
|
+
} from '@mysten/sui/transactions';
|
|
20
|
+
import { ScallopCache } from './scallopCache';
|
|
21
|
+
import { requireSender } from 'src/utils';
|
|
22
22
|
import type { SuiObjectArg } from '@scallop-io/sui-kit';
|
|
23
23
|
import type {
|
|
24
24
|
ScallopClientFnReturnType,
|
|
@@ -604,7 +604,7 @@ export class ScallopClient {
|
|
|
604
604
|
callback: (
|
|
605
605
|
txBlock: ScallopTxBlock,
|
|
606
606
|
coin: TransactionObjectArgument | string
|
|
607
|
-
) => SuiObjectArg
|
|
607
|
+
) => SuiObjectArg | Promise<SuiObjectArg>,
|
|
608
608
|
sign: S = true as S,
|
|
609
609
|
walletAddress?: string
|
|
610
610
|
): Promise<ScallopClientFnReturnType<S>> {
|
|
@@ -812,6 +812,8 @@ export class ScallopClient {
|
|
|
812
812
|
);
|
|
813
813
|
const stakeCoinName =
|
|
814
814
|
this.utils.parseCoinName<SupportStakeCoins>(stakeMarketCoinName);
|
|
815
|
+
|
|
816
|
+
console.log(stakeMarketCoin, stakeCoinName);
|
|
815
817
|
if (stakeMarketCoin) {
|
|
816
818
|
const coin = txBlock.withdraw(stakeMarketCoin, stakeCoinName);
|
|
817
819
|
await this.utils.mergeSimilarCoins(
|
|
@@ -53,14 +53,14 @@ import { ScallopUtils } from './scallopUtils';
|
|
|
53
53
|
import { ScallopIndexer } from './scallopIndexer';
|
|
54
54
|
import { ScallopCache } from './scallopCache';
|
|
55
55
|
import { DEFAULT_CACHE_OPTIONS } from 'src/constants/cache';
|
|
56
|
-
import { SuiObjectData } from '@mysten/sui
|
|
56
|
+
import { SuiObjectData } from '@mysten/sui/src/client';
|
|
57
57
|
import {
|
|
58
58
|
getSCoinAmount,
|
|
59
59
|
getSCoinAmounts,
|
|
60
60
|
getSCoinSwapRate,
|
|
61
61
|
getSCoinTotalSupply,
|
|
62
62
|
} from 'src/queries/sCoinQuery';
|
|
63
|
-
import { normalizeSuiAddress } from '@mysten/sui
|
|
63
|
+
import { normalizeSuiAddress } from '@mysten/sui/utils';
|
|
64
64
|
import { getSupplyLimit } from 'src/queries/supplyLimit';
|
|
65
65
|
|
|
66
66
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SUI_TYPE_ARG, normalizeStructTag } from '@mysten/sui
|
|
1
|
+
import { SUI_TYPE_ARG, normalizeStructTag } from '@mysten/sui/utils';
|
|
2
2
|
import { SuiKit } from '@scallop-io/sui-kit';
|
|
3
3
|
import { SuiPriceServiceConnection } from '@pythnetwork/pyth-sui-js';
|
|
4
4
|
import { ScallopAddress } from './scallopAddress';
|
|
@@ -41,7 +41,7 @@ import type {
|
|
|
41
41
|
SupportSCoin,
|
|
42
42
|
ScallopUtilsInstanceParams,
|
|
43
43
|
} from '../types';
|
|
44
|
-
import type {
|
|
44
|
+
import type { SuiObjectArg, SuiTxArg, SuiTxBlock } from '@scallop-io/sui-kit';
|
|
45
45
|
|
|
46
46
|
/**
|
|
47
47
|
* @description
|
|
@@ -444,7 +444,7 @@ export class ScallopUtils {
|
|
|
444
444
|
* @param obligationId - The obligation id.
|
|
445
445
|
* @return Asset coin Names.
|
|
446
446
|
*/
|
|
447
|
-
public async getObligationCoinNames(obligationId:
|
|
447
|
+
public async getObligationCoinNames(obligationId: SuiObjectArg) {
|
|
448
448
|
const obligation = await queryObligation(this, obligationId);
|
|
449
449
|
if (!obligation) return undefined;
|
|
450
450
|
|
package/src/queries/coreQuery.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { normalizeStructTag } from '@mysten/sui
|
|
1
|
+
import { normalizeStructTag } from '@mysten/sui/utils';
|
|
2
2
|
import {
|
|
3
3
|
SUPPORT_POOLS,
|
|
4
4
|
PROTOCOL_OBJECT_ID,
|
|
@@ -13,8 +13,8 @@ import {
|
|
|
13
13
|
parseOriginMarketCollateralData,
|
|
14
14
|
calculateMarketCollateralData,
|
|
15
15
|
} from '../utils';
|
|
16
|
-
import type { SuiObjectResponse, SuiObjectData } from '@mysten/sui
|
|
17
|
-
import type {
|
|
16
|
+
import type { SuiObjectResponse, SuiObjectData } from '@mysten/sui/client';
|
|
17
|
+
import type { SuiObjectArg } from '@scallop-io/sui-kit';
|
|
18
18
|
import type { ScallopAddress, ScallopCache, ScallopQuery } from '../models';
|
|
19
19
|
import {
|
|
20
20
|
Market,
|
|
@@ -819,7 +819,7 @@ export const queryObligation = async (
|
|
|
819
819
|
}: {
|
|
820
820
|
address: ScallopAddress;
|
|
821
821
|
},
|
|
822
|
-
obligationId:
|
|
822
|
+
obligationId: SuiObjectArg
|
|
823
823
|
) => {
|
|
824
824
|
const packageId = address.get('core.packages.query.id');
|
|
825
825
|
const queryTarget = `${packageId}::obligation_query::obligation_data`;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { bcs } from '@mysten/sui
|
|
1
|
+
import { bcs } from '@mysten/sui/bcs';
|
|
2
2
|
import assert from 'assert';
|
|
3
3
|
import BigNumber from 'bignumber.js';
|
|
4
4
|
import { SUPPORT_SCOIN } from 'src/constants';
|
|
@@ -38,7 +38,7 @@ export const getSCoinTotalSupply = async (
|
|
|
38
38
|
const type = results[0].returnValues[0][1]; // should be u64
|
|
39
39
|
assert(type === 'u64', 'Result type is not u64');
|
|
40
40
|
|
|
41
|
-
return BigNumber(bcs.
|
|
41
|
+
return BigNumber(bcs.u64().parse(value))
|
|
42
42
|
.shiftedBy(utils.getCoinDecimal(utils.parseCoinName(sCoinName)))
|
|
43
43
|
.toNumber();
|
|
44
44
|
}
|