@scallop-io/sui-scallop-sdk 0.47.6 → 1.3.0-alpha.2
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/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 +149 -83
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +152 -89
- package/dist/index.mjs.map +1 -1
- package/dist/models/scallopBuilder.d.ts +6 -4
- 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 +6 -6
- package/dist/types/query/vesca.d.ts +1 -1
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/indexer.d.ts +17 -0
- package/dist/utils/query.d.ts +1 -1
- package/dist/utils/util.d.ts +4 -3
- package/package.json +15 -11
- package/src/builders/borrowIncentiveBuilder.ts +6 -6
- package/src/builders/coreBuilder.ts +17 -17
- package/src/builders/index.ts +2 -2
- package/src/builders/loyaltyProgramBuilder.ts +5 -5
- package/src/builders/oracle.ts +5 -4
- package/src/builders/referralBuilder.ts +7 -7
- package/src/builders/sCoinBuilder.ts +5 -8
- package/src/builders/spoolBuilder.ts +10 -10
- 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/scallopBuilder.ts +15 -7
- package/src/models/scallopCache.ts +43 -34
- package/src/models/scallopClient.ts +10 -9
- package/src/models/scallopQuery.ts +36 -2
- package/src/models/scallopUtils.ts +5 -4
- 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 +6 -9
- package/src/types/query/vesca.ts +1 -1
- package/src/utils/index.ts +1 -0
- package/src/utils/indexer.ts +39 -0
- 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.
|
|
@@ -34,7 +35,7 @@ export const updateOracles = async (
|
|
|
34
35
|
const rules: SupportOracleType[] = builder.isTestnet ? ['pyth'] : ['pyth'];
|
|
35
36
|
if (usePythPullModel && rules.includes('pyth')) {
|
|
36
37
|
const pythClient = new SuiPythClient(
|
|
37
|
-
builder.
|
|
38
|
+
builder.oldSuiClient,
|
|
38
39
|
builder.address.get('core.oracles.pyth.state'),
|
|
39
40
|
builder.address.get('core.oracles.pyth.wormholeState')
|
|
40
41
|
);
|
|
@@ -52,7 +53,7 @@ export const updateOracles = async (
|
|
|
52
53
|
const priceUpdateData =
|
|
53
54
|
await pythConnection.getPriceFeedsUpdateData(priceIds);
|
|
54
55
|
await pythClient.updatePriceFeeds(
|
|
55
|
-
txBlock.txBlock
|
|
56
|
+
TransactionBlock.from(txBlock.serialize()), // convert txBlock to TransactionBlock because pyth sdk not support new @mysten/sui yet
|
|
56
57
|
priceUpdateData,
|
|
57
58
|
priceIds
|
|
58
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
|
],
|
|
@@ -118,7 +118,7 @@ const generateReferralQuickMethod: GenerateReferralQuickMethod = ({
|
|
|
118
118
|
builder.utils.parseCoinType(coinName)
|
|
119
119
|
);
|
|
120
120
|
txBlock.mergeCoins(rewardCoin, coins.slice(0, 500));
|
|
121
|
-
} catch (
|
|
121
|
+
} catch (_e) {
|
|
122
122
|
// ignore
|
|
123
123
|
} finally {
|
|
124
124
|
objToTransfer.push(rewardCoin);
|
|
@@ -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,
|
|
@@ -107,7 +107,7 @@ const stakeHelper = async (
|
|
|
107
107
|
}
|
|
108
108
|
txBlock.transferObjects([leftCoin], sender);
|
|
109
109
|
return totalAmount;
|
|
110
|
-
} catch (
|
|
110
|
+
} catch (_e) {
|
|
111
111
|
return 0;
|
|
112
112
|
}
|
|
113
113
|
};
|
|
@@ -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;
|
|
@@ -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
|
|
@@ -68,6 +72,7 @@ export class ScallopBuilder {
|
|
|
68
72
|
{
|
|
69
73
|
id: params?.addressesId || ADDRESSES_ID,
|
|
70
74
|
network: params?.networkType,
|
|
75
|
+
forceInterface: params?.forceAddressesInterface,
|
|
71
76
|
},
|
|
72
77
|
{
|
|
73
78
|
cache: this.cache,
|
|
@@ -88,6 +93,11 @@ export class ScallopBuilder {
|
|
|
88
93
|
this.isTestnet = params.networkType
|
|
89
94
|
? params.networkType === 'testnet'
|
|
90
95
|
: false;
|
|
96
|
+
|
|
97
|
+
// intitialize old Sui Client version
|
|
98
|
+
this.oldSuiClient = new SuiClientV0({
|
|
99
|
+
url: this.suiKit.suiInteractor.currentFullNode,
|
|
100
|
+
});
|
|
91
101
|
}
|
|
92
102
|
|
|
93
103
|
/**
|
|
@@ -112,9 +122,7 @@ export class ScallopBuilder {
|
|
|
112
122
|
* @param txBlock - Scallop txBlock, txBlock created by SuiKit, or original transaction block.
|
|
113
123
|
* @return Scallop txBlock.
|
|
114
124
|
*/
|
|
115
|
-
public createTxBlock(
|
|
116
|
-
txBlock?: ScallopTxBlock | SuiKitTxBlock | TransactionBlock
|
|
117
|
-
) {
|
|
125
|
+
public createTxBlock(txBlock?: ScallopTxBlock | SuiKitTxBlock | Transaction) {
|
|
118
126
|
return newScallopTxBlock(this, txBlock);
|
|
119
127
|
}
|
|
120
128
|
|
|
@@ -210,7 +218,7 @@ export class ScallopBuilder {
|
|
|
210
218
|
* @param txBlock - Scallop txBlock, txBlock created by SuiKit, or original transaction block.
|
|
211
219
|
*/
|
|
212
220
|
public async signAndSendTxBlock(
|
|
213
|
-
txBlock: ScallopTxBlock | SuiKitTxBlock |
|
|
221
|
+
txBlock: ScallopTxBlock | SuiKitTxBlock | Transaction
|
|
214
222
|
) {
|
|
215
223
|
return (await this.suiKit.signAndSendTxn(
|
|
216
224
|
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,
|
|
@@ -84,8 +84,8 @@ export class ScallopClient {
|
|
|
84
84
|
this.address = new ScallopAddress(
|
|
85
85
|
{
|
|
86
86
|
id: params?.addressesId || ADDRESSES_ID,
|
|
87
|
-
forceInterface: params?.forceAddressesInterface,
|
|
88
87
|
network: params?.networkType,
|
|
88
|
+
forceInterface: params?.forceAddressesInterface,
|
|
89
89
|
},
|
|
90
90
|
{
|
|
91
91
|
cache: this.cache,
|
|
@@ -605,7 +605,7 @@ export class ScallopClient {
|
|
|
605
605
|
callback: (
|
|
606
606
|
txBlock: ScallopTxBlock,
|
|
607
607
|
coin: TransactionObjectArgument | string
|
|
608
|
-
) => SuiObjectArg
|
|
608
|
+
) => SuiObjectArg | Promise<SuiObjectArg>,
|
|
609
609
|
sign: S = true as S,
|
|
610
610
|
walletAddress?: string
|
|
611
611
|
): Promise<ScallopClientFnReturnType<S>> {
|
|
@@ -813,6 +813,7 @@ export class ScallopClient {
|
|
|
813
813
|
);
|
|
814
814
|
const stakeCoinName =
|
|
815
815
|
this.utils.parseCoinName<SupportStakeCoins>(stakeMarketCoinName);
|
|
816
|
+
|
|
816
817
|
if (stakeMarketCoin) {
|
|
817
818
|
const coin = txBlock.withdraw(stakeMarketCoin, stakeCoinName);
|
|
818
819
|
await this.utils.mergeSimilarCoins(
|
|
@@ -1053,7 +1054,7 @@ export class ScallopClient {
|
|
|
1053
1054
|
if (sCoin) {
|
|
1054
1055
|
sCoins.push(sCoin);
|
|
1055
1056
|
}
|
|
1056
|
-
} catch (
|
|
1057
|
+
} catch (_e: any) {
|
|
1057
1058
|
// ignore
|
|
1058
1059
|
}
|
|
1059
1060
|
}
|
|
@@ -1114,7 +1115,7 @@ export class ScallopClient {
|
|
|
1114
1115
|
const scaCoin = await tx.redeemScaQuick(key, false);
|
|
1115
1116
|
if (!scaCoin) return;
|
|
1116
1117
|
scaCoins.push(scaCoin);
|
|
1117
|
-
} catch (
|
|
1118
|
+
} catch (_e) {
|
|
1118
1119
|
// ignore
|
|
1119
1120
|
}
|
|
1120
1121
|
})
|
|
@@ -53,15 +53,16 @@ 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
|
+
import { withIndexerFallback } from 'src/utils/indexer';
|
|
65
66
|
|
|
66
67
|
/**
|
|
67
68
|
* @description
|
|
@@ -111,6 +112,7 @@ export class ScallopQuery {
|
|
|
111
112
|
{
|
|
112
113
|
id: params?.addressesId || ADDRESSES_ID,
|
|
113
114
|
network: params?.networkType,
|
|
115
|
+
forceInterface: params?.forceAddressesInterface,
|
|
114
116
|
},
|
|
115
117
|
{
|
|
116
118
|
cache: this.cache,
|
|
@@ -123,8 +125,40 @@ export class ScallopQuery {
|
|
|
123
125
|
this.indexer =
|
|
124
126
|
instance?.indexer ??
|
|
125
127
|
new ScallopIndexer(this.params, { cache: this.cache });
|
|
128
|
+
|
|
129
|
+
// Wrap any method that has an indexer parameter as the last parameter
|
|
130
|
+
this.queryMarket = withIndexerFallback.call(this, this.queryMarket);
|
|
131
|
+
this.getMarketPools = withIndexerFallback.call(this, this.getMarketPools);
|
|
132
|
+
this.getMarketPool = withIndexerFallback.call(this, this.getMarketPool);
|
|
133
|
+
this.getMarketCollaterals = withIndexerFallback.call(
|
|
134
|
+
this,
|
|
135
|
+
this.getMarketCollaterals
|
|
136
|
+
);
|
|
137
|
+
this.getMarketCollateral = withIndexerFallback.call(
|
|
138
|
+
this,
|
|
139
|
+
this.getMarketCollateral
|
|
140
|
+
);
|
|
141
|
+
this.getSpools = withIndexerFallback.call(this, this.getSpools);
|
|
142
|
+
this.getSpool = withIndexerFallback.call(this, this.getSpool);
|
|
143
|
+
this.getBorrowIncentivePools = withIndexerFallback.call(
|
|
144
|
+
this,
|
|
145
|
+
this.getBorrowIncentivePools
|
|
146
|
+
);
|
|
147
|
+
this.getLendings = withIndexerFallback.call(this, this.getLendings);
|
|
148
|
+
this.getLending = withIndexerFallback.call(this, this.getLending);
|
|
149
|
+
this.getObligationAccounts = withIndexerFallback.call(
|
|
150
|
+
this,
|
|
151
|
+
this.getObligationAccounts
|
|
152
|
+
);
|
|
153
|
+
this.getObligationAccount = withIndexerFallback.call(
|
|
154
|
+
this,
|
|
155
|
+
this.getObligationAccount
|
|
156
|
+
);
|
|
157
|
+
this.getTvl = withIndexerFallback.call(this, this.getTvl);
|
|
126
158
|
}
|
|
127
159
|
|
|
160
|
+
/* ========================================================== */
|
|
161
|
+
|
|
128
162
|
/**
|
|
129
163
|
* Request the scallop API to initialize data.
|
|
130
164
|
*
|
|
@@ -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';
|
|
@@ -46,7 +46,7 @@ import type {
|
|
|
46
46
|
SupportSuiBridgeCoins,
|
|
47
47
|
SupportWormholeCoins,
|
|
48
48
|
} from '../types';
|
|
49
|
-
import type {
|
|
49
|
+
import type { SuiObjectArg, SuiTxArg, SuiTxBlock } from '@scallop-io/sui-kit';
|
|
50
50
|
|
|
51
51
|
/**
|
|
52
52
|
* @description
|
|
@@ -101,6 +101,7 @@ export class ScallopUtils {
|
|
|
101
101
|
{
|
|
102
102
|
id: params?.addressesId || ADDRESSES_ID,
|
|
103
103
|
network: params?.networkType,
|
|
104
|
+
forceInterface: params?.forceAddressesInterface,
|
|
104
105
|
},
|
|
105
106
|
{
|
|
106
107
|
cache: this.cache,
|
|
@@ -459,7 +460,7 @@ export class ScallopUtils {
|
|
|
459
460
|
if (existingCoins.length > 0) {
|
|
460
461
|
txBlock.mergeCoins(dest, existingCoins.slice(0, 500));
|
|
461
462
|
}
|
|
462
|
-
} catch (
|
|
463
|
+
} catch (_e) {
|
|
463
464
|
// ignore
|
|
464
465
|
}
|
|
465
466
|
}
|
|
@@ -474,7 +475,7 @@ export class ScallopUtils {
|
|
|
474
475
|
* @param obligationId - The obligation id.
|
|
475
476
|
* @return Asset coin Names.
|
|
476
477
|
*/
|
|
477
|
-
public async getObligationCoinNames(obligationId:
|
|
478
|
+
public async getObligationCoinNames(obligationId: SuiObjectArg) {
|
|
478
479
|
const obligation = await queryObligation(this, obligationId);
|
|
479
480
|
if (!obligation) return undefined;
|
|
480
481
|
|
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,
|
|
@@ -818,7 +818,7 @@ export const queryObligation = async (
|
|
|
818
818
|
}: {
|
|
819
819
|
address: ScallopAddress;
|
|
820
820
|
},
|
|
821
|
-
obligationId:
|
|
821
|
+
obligationId: SuiObjectArg
|
|
822
822
|
) => {
|
|
823
823
|
const packageId = address.get('core.packages.query.id');
|
|
824
824
|
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
|
}
|