@scallop-io/sui-scallop-sdk 1.3.4-alpha.7 → 1.3.4-hotfix
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/constants/common.d.ts +1 -1
- package/dist/constants/enum.d.ts +0 -1
- package/dist/constants/index.d.ts +0 -7
- package/dist/constants/pyth.d.ts +0 -2
- package/dist/constants/queryKeys.d.ts +3 -1
- package/dist/constants/tokenBucket.d.ts +1 -1
- package/dist/index.js +2317 -2481
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2316 -2470
- package/dist/index.mjs.map +1 -1
- package/dist/models/scallopPrice.d.ts +0 -0
- package/dist/models/scallopQuery.d.ts +25 -40
- package/dist/models/scallopUtils.d.ts +3 -13
- package/dist/queries/borrowIncentiveQuery.d.ts +2 -2
- package/dist/queries/coreQuery.d.ts +3 -3
- package/dist/queries/index.d.ts +5 -8
- package/dist/queries/{isolatedAssetQuery.d.ts → isolatedAsset.d.ts} +2 -2
- package/dist/queries/sCoinQuery.d.ts +1 -1
- package/dist/queries/spoolQuery.d.ts +3 -3
- package/dist/queries/{supplyLimitQuery.d.ts → supplyLimit.d.ts} +2 -2
- package/dist/types/query/index.d.ts +4 -4
- package/dist/types/utils.d.ts +0 -12
- package/dist/utils/util.d.ts +2 -2
- package/package.json +1 -1
- package/src/builders/loyaltyProgramBuilder.ts +1 -1
- package/src/constants/common.ts +2 -1
- package/src/constants/enum.ts +0 -8
- package/src/constants/index.ts +0 -7
- package/src/constants/pyth.ts +0 -19
- package/src/constants/queryKeys.ts +5 -1
- package/src/constants/tokenBucket.ts +1 -1
- package/src/models/scallop.ts +2 -3
- package/src/models/scallopAddress.ts +2 -2
- package/src/models/scallopBuilder.ts +3 -4
- package/src/models/scallopCache.ts +1 -1
- package/src/models/scallopClient.ts +26 -27
- package/src/models/scallopPrice.ts +0 -0
- package/src/models/scallopQuery.ts +17 -63
- package/src/models/scallopUtils.ts +96 -96
- package/src/queries/borrowIncentiveQuery.ts +13 -6
- package/src/queries/coreQuery.ts +23 -38
- package/src/queries/index.ts +5 -8
- package/src/queries/{isolatedAssetQuery.ts → isolatedAsset.ts} +2 -2
- package/src/queries/loyaltyProgramQuery.ts +1 -1
- package/src/queries/portfolioQuery.ts +34 -55
- package/src/queries/spoolQuery.ts +17 -17
- package/src/queries/{supplyLimitQuery.ts → supplyLimit.ts} +2 -2
- package/src/types/query/index.ts +4 -4
- package/src/types/utils.ts +0 -13
- package/src/utils/tokenBucket.ts +1 -2
- package/src/utils/util.ts +1 -2
- package/dist/constants/coinGecko.d.ts +0 -2
- package/dist/constants/poolAddress.d.ts +0 -5
- package/dist/constants/rpc.d.ts +0 -1
- package/dist/models/suiKit.d.ts +0 -2
- package/src/constants/coinGecko.ts +0 -18
- package/src/constants/poolAddress.ts +0 -94
- package/src/constants/rpc.ts +0 -16
- package/src/models/suiKit.ts +0 -11
|
@@ -34,7 +34,6 @@ import type {
|
|
|
34
34
|
ScallopClientVeScaReturnType,
|
|
35
35
|
ScallopClientInstanceParams,
|
|
36
36
|
} from '../types';
|
|
37
|
-
import { newSuiKit } from './suiKit';
|
|
38
37
|
|
|
39
38
|
/**
|
|
40
39
|
* @description
|
|
@@ -65,9 +64,9 @@ export class ScallopClient {
|
|
|
65
64
|
) {
|
|
66
65
|
this.params = params;
|
|
67
66
|
this.suiKit =
|
|
68
|
-
instance?.suiKit ?? instance?.builder?.suiKit ??
|
|
67
|
+
instance?.suiKit ?? instance?.builder?.suiKit ?? new SuiKit(params);
|
|
69
68
|
this.walletAddress = normalizeSuiAddress(
|
|
70
|
-
params?.walletAddress
|
|
69
|
+
params?.walletAddress || this.suiKit.currentAddress()
|
|
71
70
|
);
|
|
72
71
|
|
|
73
72
|
if (instance?.builder) {
|
|
@@ -84,7 +83,7 @@ export class ScallopClient {
|
|
|
84
83
|
);
|
|
85
84
|
this.address = new ScallopAddress(
|
|
86
85
|
{
|
|
87
|
-
id: params?.addressesId
|
|
86
|
+
id: params?.addressesId || ADDRESSES_ID,
|
|
88
87
|
network: params?.networkType,
|
|
89
88
|
forceInterface: params?.forceAddressesInterface,
|
|
90
89
|
},
|
|
@@ -143,7 +142,7 @@ export class ScallopClient {
|
|
|
143
142
|
* @return Obligations data.
|
|
144
143
|
*/
|
|
145
144
|
public async getObligations(ownerAddress?: string) {
|
|
146
|
-
const owner = ownerAddress
|
|
145
|
+
const owner = ownerAddress || this.walletAddress;
|
|
147
146
|
return await this.query.getObligations(owner);
|
|
148
147
|
}
|
|
149
148
|
|
|
@@ -170,7 +169,7 @@ export class ScallopClient {
|
|
|
170
169
|
* @return All stake accounts data.
|
|
171
170
|
*/
|
|
172
171
|
async getAllStakeAccounts(ownerAddress?: string) {
|
|
173
|
-
const owner = ownerAddress
|
|
172
|
+
const owner = ownerAddress || this.walletAddress;
|
|
174
173
|
return await this.query.getAllStakeAccounts(owner);
|
|
175
174
|
}
|
|
176
175
|
|
|
@@ -188,7 +187,7 @@ export class ScallopClient {
|
|
|
188
187
|
stakeMarketCoinName: SupportStakeMarketCoins,
|
|
189
188
|
ownerAddress?: string
|
|
190
189
|
) {
|
|
191
|
-
const owner = ownerAddress
|
|
190
|
+
const owner = ownerAddress || this.walletAddress;
|
|
192
191
|
return await this.query.getStakeAccounts(stakeMarketCoinName, owner);
|
|
193
192
|
}
|
|
194
193
|
|
|
@@ -273,11 +272,11 @@ export class ScallopClient {
|
|
|
273
272
|
walletAddress?: string
|
|
274
273
|
): Promise<ScallopClientFnReturnType<S>> {
|
|
275
274
|
const txBlock = this.builder.createTxBlock();
|
|
276
|
-
const sender = walletAddress
|
|
275
|
+
const sender = walletAddress || this.walletAddress;
|
|
277
276
|
txBlock.setSender(sender);
|
|
278
277
|
|
|
279
278
|
const obligations = await this.query.getObligations(sender);
|
|
280
|
-
const specificObligationId = obligationId
|
|
279
|
+
const specificObligationId = obligationId || obligations[0]?.id;
|
|
281
280
|
if (specificObligationId) {
|
|
282
281
|
await txBlock.addCollateralQuick(
|
|
283
282
|
amount,
|
|
@@ -320,7 +319,7 @@ export class ScallopClient {
|
|
|
320
319
|
walletAddress?: string
|
|
321
320
|
): Promise<ScallopClientFnReturnType<S>> {
|
|
322
321
|
const txBlock = this.builder.createTxBlock();
|
|
323
|
-
const sender = walletAddress
|
|
322
|
+
const sender = walletAddress || this.walletAddress;
|
|
324
323
|
txBlock.setSender(sender);
|
|
325
324
|
|
|
326
325
|
const collateralCoin = await txBlock.takeCollateralQuick(
|
|
@@ -366,7 +365,7 @@ export class ScallopClient {
|
|
|
366
365
|
walletAddress?: string
|
|
367
366
|
): Promise<ScallopClientFnReturnType<S>> {
|
|
368
367
|
const txBlock = this.builder.createTxBlock();
|
|
369
|
-
const sender = walletAddress
|
|
368
|
+
const sender = walletAddress || this.walletAddress;
|
|
370
369
|
txBlock.setSender(sender);
|
|
371
370
|
|
|
372
371
|
const sCoin = await txBlock.depositQuick(amount, poolCoinName);
|
|
@@ -410,14 +409,14 @@ export class ScallopClient {
|
|
|
410
409
|
walletAddress?: string
|
|
411
410
|
): Promise<ScallopClientFnReturnType<S>> {
|
|
412
411
|
const txBlock = this.builder.createTxBlock();
|
|
413
|
-
const sender = walletAddress
|
|
412
|
+
const sender = walletAddress || this.walletAddress;
|
|
414
413
|
txBlock.setSender(sender);
|
|
415
414
|
|
|
416
415
|
const stakeMarketCoinName =
|
|
417
416
|
this.utils.parseMarketCoinName<SupportStakeMarketCoins>(stakeCoinName);
|
|
418
417
|
const stakeAccounts =
|
|
419
418
|
await this.query.getStakeAccounts(stakeMarketCoinName);
|
|
420
|
-
const targetStakeAccount = stakeAccountId
|
|
419
|
+
const targetStakeAccount = stakeAccountId || stakeAccounts[0]?.id;
|
|
421
420
|
|
|
422
421
|
const marketCoin = await txBlock.depositQuick(amount, stakeCoinName, false);
|
|
423
422
|
if (targetStakeAccount) {
|
|
@@ -467,7 +466,7 @@ export class ScallopClient {
|
|
|
467
466
|
walletAddress?: string
|
|
468
467
|
): Promise<ScallopClientFnReturnType<S>> {
|
|
469
468
|
const txBlock = this.builder.createTxBlock();
|
|
470
|
-
const sender = walletAddress
|
|
469
|
+
const sender = walletAddress || this.walletAddress;
|
|
471
470
|
txBlock.setSender(sender);
|
|
472
471
|
|
|
473
472
|
const coin = await txBlock.withdrawQuick(amount, poolCoinName);
|
|
@@ -502,7 +501,7 @@ export class ScallopClient {
|
|
|
502
501
|
walletAddress?: string
|
|
503
502
|
): Promise<ScallopClientFnReturnType<S>> {
|
|
504
503
|
const txBlock = this.builder.createTxBlock();
|
|
505
|
-
const sender = walletAddress
|
|
504
|
+
const sender = walletAddress || this.walletAddress;
|
|
506
505
|
txBlock.setSender(sender);
|
|
507
506
|
|
|
508
507
|
const availableStake = (
|
|
@@ -550,7 +549,7 @@ export class ScallopClient {
|
|
|
550
549
|
walletAddress?: string
|
|
551
550
|
): Promise<ScallopClientFnReturnType<S>> {
|
|
552
551
|
const txBlock = this.builder.createTxBlock();
|
|
553
|
-
const sender = walletAddress
|
|
552
|
+
const sender = walletAddress || this.walletAddress;
|
|
554
553
|
txBlock.setSender(sender);
|
|
555
554
|
|
|
556
555
|
const availableStake = (
|
|
@@ -611,7 +610,7 @@ export class ScallopClient {
|
|
|
611
610
|
walletAddress?: string
|
|
612
611
|
): Promise<ScallopClientFnReturnType<S>> {
|
|
613
612
|
const txBlock = this.builder.createTxBlock();
|
|
614
|
-
const sender = walletAddress
|
|
613
|
+
const sender = walletAddress || this.walletAddress;
|
|
615
614
|
txBlock.setSender(sender);
|
|
616
615
|
const [coin, loan] = txBlock.borrowFlashLoan(amount, poolCoinName);
|
|
617
616
|
txBlock.repayFlashLoan(await callback(txBlock, coin), loan, poolCoinName);
|
|
@@ -648,7 +647,7 @@ export class ScallopClient {
|
|
|
648
647
|
walletAddress?: string
|
|
649
648
|
): Promise<ScallopClientFnReturnType<S>> {
|
|
650
649
|
const txBlock = this.builder.createTxBlock();
|
|
651
|
-
const sender = walletAddress
|
|
650
|
+
const sender = walletAddress || this.walletAddress;
|
|
652
651
|
txBlock.setSender(sender);
|
|
653
652
|
|
|
654
653
|
const stakeAccount = txBlock.createStakeAccount(marketCoinName);
|
|
@@ -692,12 +691,12 @@ export class ScallopClient {
|
|
|
692
691
|
walletAddress?: string
|
|
693
692
|
): Promise<ScallopClientFnReturnType<S>> {
|
|
694
693
|
const txBlock = this.builder.createTxBlock();
|
|
695
|
-
const sender = walletAddress
|
|
694
|
+
const sender = walletAddress || this.walletAddress;
|
|
696
695
|
txBlock.setSender(sender);
|
|
697
696
|
|
|
698
697
|
const stakeAccounts =
|
|
699
698
|
await this.query.getStakeAccounts(stakeMarketCoinName);
|
|
700
|
-
const targetStakeAccount = stakeAccountId
|
|
699
|
+
const targetStakeAccount = stakeAccountId || stakeAccounts[0]?.id;
|
|
701
700
|
if (targetStakeAccount) {
|
|
702
701
|
await txBlock.stakeQuick(amount, stakeMarketCoinName, targetStakeAccount);
|
|
703
702
|
} else {
|
|
@@ -744,7 +743,7 @@ export class ScallopClient {
|
|
|
744
743
|
walletAddress?: string
|
|
745
744
|
): Promise<ScallopClientFnReturnType<S>> {
|
|
746
745
|
const txBlock = this.builder.createTxBlock();
|
|
747
|
-
const sender = walletAddress
|
|
746
|
+
const sender = walletAddress || this.walletAddress;
|
|
748
747
|
txBlock.setSender(sender);
|
|
749
748
|
|
|
750
749
|
const sCoin = await txBlock.unstakeQuick(
|
|
@@ -803,7 +802,7 @@ export class ScallopClient {
|
|
|
803
802
|
walletAddress?: string
|
|
804
803
|
): Promise<ScallopClientFnReturnType<S>> {
|
|
805
804
|
const txBlock = this.builder.createTxBlock();
|
|
806
|
-
const sender = walletAddress
|
|
805
|
+
const sender = walletAddress || this.walletAddress;
|
|
807
806
|
txBlock.setSender(sender);
|
|
808
807
|
|
|
809
808
|
const stakeMarketCoin = await txBlock.unstakeQuick(
|
|
@@ -864,7 +863,7 @@ export class ScallopClient {
|
|
|
864
863
|
walletAddress?: string
|
|
865
864
|
): Promise<ScallopClientFnReturnType<S>> {
|
|
866
865
|
const txBlock = this.builder.createTxBlock();
|
|
867
|
-
const sender = walletAddress
|
|
866
|
+
const sender = walletAddress || this.walletAddress;
|
|
868
867
|
txBlock.setSender(sender);
|
|
869
868
|
|
|
870
869
|
const rewardCoins = await txBlock.claimQuick(
|
|
@@ -900,7 +899,7 @@ export class ScallopClient {
|
|
|
900
899
|
walletAddress?: string
|
|
901
900
|
): Promise<ScallopClientFnReturnType<S>> {
|
|
902
901
|
const txBlock = this.builder.createTxBlock();
|
|
903
|
-
const sender = walletAddress
|
|
902
|
+
const sender = walletAddress || this.walletAddress;
|
|
904
903
|
txBlock.setSender(sender);
|
|
905
904
|
|
|
906
905
|
await txBlock.stakeObligationWithVeScaQuick(obligationId, obligationKeyId);
|
|
@@ -930,7 +929,7 @@ export class ScallopClient {
|
|
|
930
929
|
walletAddress?: string
|
|
931
930
|
): Promise<ScallopClientFnReturnType<S>> {
|
|
932
931
|
const txBlock = this.builder.createTxBlock();
|
|
933
|
-
const sender = walletAddress
|
|
932
|
+
const sender = walletAddress || this.walletAddress;
|
|
934
933
|
txBlock.setSender(sender);
|
|
935
934
|
|
|
936
935
|
await txBlock.unstakeObligationQuick(obligationId, obligationKeyId);
|
|
@@ -962,7 +961,7 @@ export class ScallopClient {
|
|
|
962
961
|
walletAddress?: string
|
|
963
962
|
): Promise<ScallopClientFnReturnType<S>> {
|
|
964
963
|
const txBlock = this.builder.createTxBlock();
|
|
965
|
-
const sender = walletAddress
|
|
964
|
+
const sender = walletAddress || this.walletAddress;
|
|
966
965
|
txBlock.setSender(sender);
|
|
967
966
|
|
|
968
967
|
const rewardCoins = [];
|
|
@@ -1187,7 +1186,7 @@ export class ScallopClient {
|
|
|
1187
1186
|
}
|
|
1188
1187
|
|
|
1189
1188
|
const txBlock = this.builder.createTxBlock();
|
|
1190
|
-
const recipient = receiveAddress
|
|
1189
|
+
const recipient = receiveAddress || this.walletAddress;
|
|
1191
1190
|
const packageId = this.address.get('core.packages.testCoin.id');
|
|
1192
1191
|
const treasuryId = this.address.get(`core.coins.${assetCoinName}.treasury`);
|
|
1193
1192
|
const target = `${packageId}::${assetCoinName}::mint`;
|
|
File without changes
|
|
@@ -47,9 +47,6 @@ import {
|
|
|
47
47
|
SupportBorrowIncentiveCoins,
|
|
48
48
|
SupportSCoin,
|
|
49
49
|
ScallopQueryInstanceParams,
|
|
50
|
-
MarketPool,
|
|
51
|
-
CoinPrices,
|
|
52
|
-
MarketPools,
|
|
53
50
|
} from '../types';
|
|
54
51
|
import { ScallopAddress } from './scallopAddress';
|
|
55
52
|
import { ScallopUtils } from './scallopUtils';
|
|
@@ -64,13 +61,9 @@ import {
|
|
|
64
61
|
getSCoinTotalSupply,
|
|
65
62
|
} from 'src/queries/sCoinQuery';
|
|
66
63
|
import { normalizeSuiAddress } from '@mysten/sui/utils';
|
|
67
|
-
import {
|
|
68
|
-
getSupplyLimit,
|
|
69
|
-
getIsolatedAssets,
|
|
70
|
-
isIsolatedAsset,
|
|
71
|
-
} from 'src/queries';
|
|
64
|
+
import { getSupplyLimit } from 'src/queries/supplyLimit';
|
|
72
65
|
import { withIndexerFallback } from 'src/utils/indexer';
|
|
73
|
-
import {
|
|
66
|
+
import { getIsolatedAssets, isIsolatedAsset } from 'src/queries/isolatedAsset';
|
|
74
67
|
|
|
75
68
|
/**
|
|
76
69
|
* @description
|
|
@@ -100,10 +93,10 @@ export class ScallopQuery {
|
|
|
100
93
|
) {
|
|
101
94
|
this.params = params;
|
|
102
95
|
this.suiKit =
|
|
103
|
-
instance?.suiKit ?? instance?.utils?.suiKit ??
|
|
96
|
+
instance?.suiKit ?? instance?.utils?.suiKit ?? new SuiKit(params);
|
|
104
97
|
|
|
105
98
|
this.walletAddress = normalizeSuiAddress(
|
|
106
|
-
params.walletAddress
|
|
99
|
+
params.walletAddress || this.suiKit.currentAddress()
|
|
107
100
|
);
|
|
108
101
|
|
|
109
102
|
if (instance?.utils) {
|
|
@@ -118,7 +111,7 @@ export class ScallopQuery {
|
|
|
118
111
|
);
|
|
119
112
|
this.address = new ScallopAddress(
|
|
120
113
|
{
|
|
121
|
-
id: params?.addressesId
|
|
114
|
+
id: params?.addressesId || ADDRESSES_ID,
|
|
122
115
|
network: params?.networkType,
|
|
123
116
|
forceInterface: params?.forceAddressesInterface,
|
|
124
117
|
},
|
|
@@ -190,11 +183,8 @@ export class ScallopQuery {
|
|
|
190
183
|
* @param indexer - Whether to use indexer.
|
|
191
184
|
* @return Market data.
|
|
192
185
|
*/
|
|
193
|
-
public async queryMarket(
|
|
194
|
-
|
|
195
|
-
args?: { coinPrices: CoinPrices }
|
|
196
|
-
) {
|
|
197
|
-
return await queryMarket(this, indexer, args?.coinPrices);
|
|
186
|
+
public async queryMarket(indexer: boolean = false) {
|
|
187
|
+
return await queryMarket(this, indexer);
|
|
198
188
|
}
|
|
199
189
|
|
|
200
190
|
/**
|
|
@@ -210,12 +200,9 @@ export class ScallopQuery {
|
|
|
210
200
|
*/
|
|
211
201
|
public async getMarketPools(
|
|
212
202
|
poolCoinNames?: SupportPoolCoins[],
|
|
213
|
-
indexer: boolean = false
|
|
214
|
-
args?: {
|
|
215
|
-
coinPrices?: CoinPrices;
|
|
216
|
-
}
|
|
203
|
+
indexer: boolean = false
|
|
217
204
|
) {
|
|
218
|
-
return await getMarketPools(this, poolCoinNames, indexer
|
|
205
|
+
return await getMarketPools(this, poolCoinNames, indexer);
|
|
219
206
|
}
|
|
220
207
|
|
|
221
208
|
/**
|
|
@@ -227,19 +214,9 @@ export class ScallopQuery {
|
|
|
227
214
|
*/
|
|
228
215
|
public async getMarketPool(
|
|
229
216
|
poolCoinName: SupportPoolCoins,
|
|
230
|
-
indexer: boolean = false
|
|
231
|
-
args?: {
|
|
232
|
-
marketObject?: SuiObjectData | null;
|
|
233
|
-
coinPrice?: number;
|
|
234
|
-
}
|
|
217
|
+
indexer: boolean = false
|
|
235
218
|
) {
|
|
236
|
-
return await getMarketPool(
|
|
237
|
-
this,
|
|
238
|
-
poolCoinName,
|
|
239
|
-
indexer,
|
|
240
|
-
args?.marketObject,
|
|
241
|
-
args?.coinPrice
|
|
242
|
-
);
|
|
219
|
+
return await getMarketPool(this, poolCoinName, indexer);
|
|
243
220
|
}
|
|
244
221
|
|
|
245
222
|
/**
|
|
@@ -381,19 +358,9 @@ export class ScallopQuery {
|
|
|
381
358
|
*/
|
|
382
359
|
public async getSpools(
|
|
383
360
|
stakeMarketCoinNames?: SupportStakeMarketCoins[],
|
|
384
|
-
indexer: boolean = false
|
|
385
|
-
args?: {
|
|
386
|
-
marketPools?: MarketPools;
|
|
387
|
-
coinPrices?: CoinPrices;
|
|
388
|
-
}
|
|
361
|
+
indexer: boolean = false
|
|
389
362
|
) {
|
|
390
|
-
return await getSpools(
|
|
391
|
-
this,
|
|
392
|
-
stakeMarketCoinNames,
|
|
393
|
-
indexer,
|
|
394
|
-
args?.marketPools,
|
|
395
|
-
args?.coinPrices
|
|
396
|
-
);
|
|
363
|
+
return await getSpools(this, stakeMarketCoinNames, indexer);
|
|
397
364
|
}
|
|
398
365
|
|
|
399
366
|
/**
|
|
@@ -405,16 +372,9 @@ export class ScallopQuery {
|
|
|
405
372
|
*/
|
|
406
373
|
public async getSpool(
|
|
407
374
|
stakeMarketCoinName: SupportStakeMarketCoins,
|
|
408
|
-
indexer: boolean = false
|
|
409
|
-
args?: { marketPool?: MarketPool; coinPrices?: CoinPrices }
|
|
375
|
+
indexer: boolean = false
|
|
410
376
|
) {
|
|
411
|
-
return await getSpool(
|
|
412
|
-
this,
|
|
413
|
-
stakeMarketCoinName,
|
|
414
|
-
indexer,
|
|
415
|
-
args?.marketPool,
|
|
416
|
-
args?.coinPrices
|
|
417
|
-
);
|
|
377
|
+
return await getSpool(this, stakeMarketCoinName, indexer);
|
|
418
378
|
}
|
|
419
379
|
|
|
420
380
|
/**
|
|
@@ -535,15 +495,9 @@ export class ScallopQuery {
|
|
|
535
495
|
*/
|
|
536
496
|
public async getBorrowIncentivePools(
|
|
537
497
|
coinNames?: SupportBorrowIncentiveCoins[],
|
|
538
|
-
indexer: boolean = false
|
|
539
|
-
args?: { coinPrices: CoinPrices }
|
|
498
|
+
indexer: boolean = false
|
|
540
499
|
) {
|
|
541
|
-
return await getBorrowIncentivePools(
|
|
542
|
-
this,
|
|
543
|
-
coinNames,
|
|
544
|
-
indexer,
|
|
545
|
-
args?.coinPrices
|
|
546
|
-
);
|
|
500
|
+
return await getBorrowIncentivePools(this, coinNames, indexer);
|
|
547
501
|
}
|
|
548
502
|
|
|
549
503
|
/**
|
|
@@ -18,11 +18,8 @@ import {
|
|
|
18
18
|
SUPPORT_SCOIN,
|
|
19
19
|
sCoinIds,
|
|
20
20
|
suiBridgeCoins,
|
|
21
|
-
COIN_GECKGO_IDS,
|
|
22
|
-
POOL_ADDRESSES,
|
|
23
|
-
sCoinTypeToName,
|
|
24
21
|
} from '../constants';
|
|
25
|
-
import {
|
|
22
|
+
import { getPythPrice, queryObligation } from '../queries';
|
|
26
23
|
import {
|
|
27
24
|
parseDataFromPythPriceFeed,
|
|
28
25
|
isMarketCoin,
|
|
@@ -31,7 +28,7 @@ import {
|
|
|
31
28
|
isSuiBridgeAsset,
|
|
32
29
|
isWormholeAsset,
|
|
33
30
|
} from '../utils';
|
|
34
|
-
import { PYTH_ENDPOINTS
|
|
31
|
+
import { PYTH_ENDPOINTS } from 'src/constants/pyth';
|
|
35
32
|
import { ScallopCache } from './scallopCache';
|
|
36
33
|
import { DEFAULT_CACHE_OPTIONS } from 'src/constants/cache';
|
|
37
34
|
import type {
|
|
@@ -42,16 +39,15 @@ import type {
|
|
|
42
39
|
SupportStakeMarketCoins,
|
|
43
40
|
SupportBorrowIncentiveCoins,
|
|
44
41
|
CoinPrices,
|
|
42
|
+
PriceMap,
|
|
45
43
|
CoinWrappedType,
|
|
46
44
|
SupportSCoin,
|
|
47
45
|
ScallopUtilsInstanceParams,
|
|
48
46
|
SupportSuiBridgeCoins,
|
|
49
47
|
SupportWormholeCoins,
|
|
50
|
-
PoolAddressInfo,
|
|
51
48
|
} from '../types';
|
|
52
49
|
import { queryKeys } from 'src/constants';
|
|
53
50
|
import type { SuiObjectArg, SuiTxArg, SuiTxBlock } from '@scallop-io/sui-kit';
|
|
54
|
-
import { newSuiKit } from './suiKit';
|
|
55
51
|
|
|
56
52
|
/**
|
|
57
53
|
* @description
|
|
@@ -73,6 +69,7 @@ export class ScallopUtils {
|
|
|
73
69
|
public address: ScallopAddress;
|
|
74
70
|
public cache: ScallopCache;
|
|
75
71
|
public walletAddress: string;
|
|
72
|
+
private _priceMap: PriceMap = new Map();
|
|
76
73
|
|
|
77
74
|
public constructor(
|
|
78
75
|
params: ScallopUtilsParams,
|
|
@@ -83,7 +80,9 @@ export class ScallopUtils {
|
|
|
83
80
|
...params,
|
|
84
81
|
};
|
|
85
82
|
this.suiKit =
|
|
86
|
-
instance?.suiKit ??
|
|
83
|
+
instance?.suiKit ??
|
|
84
|
+
instance?.address?.cache._suiKit ??
|
|
85
|
+
new SuiKit(params);
|
|
87
86
|
|
|
88
87
|
this.walletAddress = params.walletAddress ?? this.suiKit.currentAddress();
|
|
89
88
|
|
|
@@ -101,7 +100,7 @@ export class ScallopUtils {
|
|
|
101
100
|
instance?.address ??
|
|
102
101
|
new ScallopAddress(
|
|
103
102
|
{
|
|
104
|
-
id: params?.addressesId
|
|
103
|
+
id: params?.addressesId || ADDRESSES_ID,
|
|
105
104
|
network: params?.networkType,
|
|
106
105
|
forceInterface: params?.forceAddressesInterface,
|
|
107
106
|
},
|
|
@@ -225,7 +224,6 @@ export class ScallopUtils {
|
|
|
225
224
|
return undefined;
|
|
226
225
|
}
|
|
227
226
|
}
|
|
228
|
-
|
|
229
227
|
/**
|
|
230
228
|
* Convert sCoin name into sCoin type
|
|
231
229
|
* @param sCoinName
|
|
@@ -235,15 +233,6 @@ export class ScallopUtils {
|
|
|
235
233
|
return sCoinIds[sCoinName];
|
|
236
234
|
}
|
|
237
235
|
|
|
238
|
-
/**
|
|
239
|
-
* Convert sCoinType into sCoin name
|
|
240
|
-
* @param sCoinType
|
|
241
|
-
* @returns sCoin name
|
|
242
|
-
*/
|
|
243
|
-
public parseSCoinNameFromType(sCoinType: string) {
|
|
244
|
-
return sCoinTypeToName[sCoinType];
|
|
245
|
-
}
|
|
246
|
-
|
|
247
236
|
/**
|
|
248
237
|
* Convert sCoin name into its underlying coin type
|
|
249
238
|
* @param sCoinName
|
|
@@ -272,7 +261,7 @@ export class ScallopUtils {
|
|
|
272
261
|
*/
|
|
273
262
|
public parseMarketCoinType(coinName: SupportCoins) {
|
|
274
263
|
const protocolObjectId =
|
|
275
|
-
this.address.get('core.object')
|
|
264
|
+
this.address.get('core.object') || PROTOCOL_OBJECT_ID;
|
|
276
265
|
const coinType = this.parseCoinType(coinName);
|
|
277
266
|
return `${protocolObjectId}::reserve::MarketCoin<${coinType}>`;
|
|
278
267
|
}
|
|
@@ -301,7 +290,7 @@ export class ScallopUtils {
|
|
|
301
290
|
const coinTypeRegex = new RegExp(`((0x[^:]+::[^:]+::[^<>]+))(?![^<>]*<)`);
|
|
302
291
|
const coinTypeMatch = coinType.match(coinTypeRegex);
|
|
303
292
|
const isMarketCoinType = coinType.includes('reserve::MarketCoin');
|
|
304
|
-
coinType = coinTypeMatch?.[1]
|
|
293
|
+
coinType = coinTypeMatch?.[1] || coinType;
|
|
305
294
|
|
|
306
295
|
const wormHoleCoinTypeMap: Record<string, SupportAssetCoins> = {
|
|
307
296
|
[`${
|
|
@@ -439,7 +428,7 @@ export class ScallopUtils {
|
|
|
439
428
|
coinType: string = SUI_TYPE_ARG,
|
|
440
429
|
ownerAddress?: string
|
|
441
430
|
) {
|
|
442
|
-
ownerAddress = ownerAddress
|
|
431
|
+
ownerAddress = ownerAddress || this.suiKit.currentAddress();
|
|
443
432
|
const coins = await this.suiKit.suiInteractor.selectCoins(
|
|
444
433
|
ownerAddress,
|
|
445
434
|
amount,
|
|
@@ -519,68 +508,100 @@ export class ScallopUtils {
|
|
|
519
508
|
* @return Asset coin price.
|
|
520
509
|
*/
|
|
521
510
|
public async getCoinPrices(
|
|
522
|
-
|
|
511
|
+
assetCoinNames: SupportAssetCoins[] = [
|
|
523
512
|
...new Set([...SUPPORT_POOLS, ...SUPPORT_COLLATERALS]),
|
|
524
513
|
] as SupportAssetCoins[]
|
|
525
514
|
) {
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
const
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
},
|
|
546
|
-
[] as [string, string][]
|
|
547
|
-
);
|
|
515
|
+
const coinPrices: CoinPrices = {};
|
|
516
|
+
const existPricesCoinNames: SupportAssetCoins[] = [];
|
|
517
|
+
const lackPricesCoinNames: SupportAssetCoins[] = [];
|
|
518
|
+
|
|
519
|
+
assetCoinNames.forEach((assetCoinName) => {
|
|
520
|
+
if (
|
|
521
|
+
this._priceMap.has(assetCoinName) &&
|
|
522
|
+
Date.now() - this._priceMap.get(assetCoinName)!.publishTime < 1000 * 60
|
|
523
|
+
) {
|
|
524
|
+
existPricesCoinNames.push(assetCoinName);
|
|
525
|
+
} else {
|
|
526
|
+
lackPricesCoinNames.push(assetCoinName);
|
|
527
|
+
this.cache.queryClient.invalidateQueries({
|
|
528
|
+
queryKey: queryKeys.oracle.getPythLatestPriceFeed(
|
|
529
|
+
this.address.get(`core.coins.${assetCoinName}.oracle.pyth.feed`)
|
|
530
|
+
),
|
|
531
|
+
});
|
|
532
|
+
}
|
|
533
|
+
});
|
|
548
534
|
|
|
549
|
-
|
|
535
|
+
if (existPricesCoinNames.length > 0) {
|
|
536
|
+
for (const coinName of existPricesCoinNames) {
|
|
537
|
+
coinPrices[coinName] = this._priceMap.get(coinName)!.price;
|
|
538
|
+
}
|
|
539
|
+
}
|
|
550
540
|
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
541
|
+
if (lackPricesCoinNames.length > 0) {
|
|
542
|
+
const endpoints =
|
|
543
|
+
this.params.pythEndpoints ??
|
|
544
|
+
PYTH_ENDPOINTS[this.isTestnet ? 'testnet' : 'mainnet'];
|
|
554
545
|
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
546
|
+
const failedRequests: Set<SupportAssetCoins> = new Set(
|
|
547
|
+
lackPricesCoinNames
|
|
548
|
+
);
|
|
549
|
+
|
|
550
|
+
for (const endpoint of endpoints) {
|
|
551
|
+
const priceIds = Array.from(failedRequests.values()).reduce(
|
|
552
|
+
(acc, coinName) => {
|
|
553
|
+
const priceId = this.address.get(
|
|
554
|
+
`core.coins.${coinName}.oracle.pyth.feed`
|
|
555
|
+
);
|
|
556
|
+
acc[coinName] = priceId;
|
|
557
|
+
return acc;
|
|
560
558
|
},
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
const
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
559
|
+
{} as Record<SupportAssetCoins, string>
|
|
560
|
+
);
|
|
561
|
+
|
|
562
|
+
await Promise.allSettled(
|
|
563
|
+
Object.entries(priceIds).map(async ([coinName, priceId]) => {
|
|
564
|
+
const pythConnection = new SuiPriceServiceConnection(endpoint);
|
|
565
|
+
try {
|
|
566
|
+
const feed = await this.cache.queryClient.fetchQuery({
|
|
567
|
+
queryKey: queryKeys.oracle.getPythLatestPriceFeed(priceId),
|
|
568
|
+
queryFn: async () => {
|
|
569
|
+
return (
|
|
570
|
+
(await pythConnection.getLatestPriceFeeds([priceId])) ?? []
|
|
571
|
+
);
|
|
572
|
+
},
|
|
573
|
+
});
|
|
574
|
+
if (feed[0]) {
|
|
575
|
+
const data = parseDataFromPythPriceFeed(feed[0], this.address);
|
|
576
|
+
this._priceMap.set(coinName as SupportAssetCoins, {
|
|
577
|
+
price: data.price,
|
|
578
|
+
publishTime: data.publishTime,
|
|
579
|
+
});
|
|
580
|
+
coinPrices[coinName as SupportAssetCoins] = data.price;
|
|
581
|
+
}
|
|
582
|
+
failedRequests.delete(coinName as SupportAssetCoins); // remove success price feed to prevent duplicate request on the next endpoint
|
|
583
|
+
} catch (e) {
|
|
584
|
+
console.warn(
|
|
585
|
+
`Failed to get price ${coinName} feeds with endpoint ${endpoint}: ${e}`
|
|
586
|
+
);
|
|
587
|
+
}
|
|
588
|
+
})
|
|
589
|
+
);
|
|
590
|
+
if (failedRequests.size === 0) break;
|
|
574
591
|
}
|
|
575
|
-
if (failedRequests.size === 0) break;
|
|
576
|
-
}
|
|
577
592
|
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
593
|
+
if (failedRequests.size > 0) {
|
|
594
|
+
await Promise.allSettled(
|
|
595
|
+
Array.from(failedRequests.values()).map(async (coinName) => {
|
|
596
|
+
const price = await getPythPrice(this, coinName);
|
|
597
|
+
this._priceMap.set(coinName, {
|
|
598
|
+
price: price,
|
|
599
|
+
publishTime: Date.now(),
|
|
600
|
+
});
|
|
601
|
+
coinPrices[coinName] = price;
|
|
602
|
+
})
|
|
603
|
+
);
|
|
604
|
+
}
|
|
584
605
|
}
|
|
585
606
|
|
|
586
607
|
return coinPrices;
|
|
@@ -649,25 +670,4 @@ export class ScallopUtils {
|
|
|
649
670
|
}
|
|
650
671
|
return findClosestUnlockRound(newUnlockAtInSecondTimestamp);
|
|
651
672
|
}
|
|
652
|
-
|
|
653
|
-
/**
|
|
654
|
-
* Get detailed contract address and price id information for supported pool in Scallop
|
|
655
|
-
* @returns Supported pool informations
|
|
656
|
-
*/
|
|
657
|
-
public getSupportedPoolAddresses(): PoolAddressInfo[] {
|
|
658
|
-
return SUPPORT_POOLS.map((poolName) => {
|
|
659
|
-
const sCoinName = this.parseSCoinName(poolName)!;
|
|
660
|
-
return {
|
|
661
|
-
name: this.parseSymbol(poolName),
|
|
662
|
-
coingeckoId: COIN_GECKGO_IDS[poolName],
|
|
663
|
-
decimal: coinDecimals[poolName],
|
|
664
|
-
pythFeedId: PYTH_FEED_IDS[poolName],
|
|
665
|
-
...POOL_ADDRESSES[poolName],
|
|
666
|
-
sCoinAddress: sCoinIds[sCoinName],
|
|
667
|
-
marketCoinAddress: this.parseMarketCoinType(poolName),
|
|
668
|
-
coinAddress: this.parseCoinType(poolName),
|
|
669
|
-
sCoinName: sCoinName ? this.parseSymbol(sCoinName) : undefined,
|
|
670
|
-
};
|
|
671
|
-
});
|
|
672
|
-
}
|
|
673
673
|
}
|