@scallop-io/sui-scallop-sdk 2.3.0-lst-x-oracle-alpha.9 → 2.3.0
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/index.d.mts +1811 -1783
- package/dist/index.d.ts +1811 -1783
- package/dist/index.js +49 -2
- package/dist/index.mjs +15 -2
- package/package.json +8 -7
- package/src/builders/borrowIncentiveBuilder.ts +4 -4
- package/src/builders/coreBuilder.ts +86 -59
- package/src/builders/index.ts +2 -2
- package/src/builders/loyaltyProgramBuilder.ts +2 -2
- package/src/builders/oracles/index.ts +365 -114
- package/src/builders/oracles/pyth.ts +135 -0
- package/src/builders/referralBuilder.ts +4 -10
- package/src/builders/sCoinBuilder.ts +2 -2
- package/src/builders/spoolBuilder.ts +2 -2
- package/src/builders/vescaBuilder.ts +5 -5
- package/src/constants/common.ts +3 -0
- package/src/constants/index.ts +1 -1
- package/src/constants/queryKeys.ts +1 -1
- package/src/constants/testAddress.ts +99 -271
- package/src/constants/xoracle.ts +2 -8
- package/src/index.ts +1 -1
- package/src/models/index.ts +1 -2
- package/src/models/interface.ts +6 -6
- package/src/models/rateLimiter.ts +55 -0
- package/src/models/scallop.ts +1 -1
- package/src/models/scallopAddress.ts +5 -33
- package/src/models/scallopBuilder.ts +14 -11
- package/src/models/scallopClient.ts +31 -14
- package/src/models/scallopConstants.ts +3 -3
- package/src/models/scallopIndexer.ts +3 -4
- package/src/models/scallopQuery.ts +112 -56
- package/src/models/scallopQueryClient.ts +1 -1
- package/src/models/scallopSuiKit.ts +1 -1
- package/src/models/scallopUtils.ts +12 -7
- package/src/queries/borrowIncentiveQuery.ts +4 -3
- package/src/queries/coreQuery.ts +114 -186
- package/src/queries/index.ts +3 -4
- package/src/queries/loyaltyProgramQuery.ts +2 -2
- package/src/queries/ownerQuery.ts +32 -0
- package/src/queries/poolAddressesQuery.ts +1 -3
- package/src/queries/portfolioQuery.ts +68 -16
- package/src/queries/priceQuery.ts +2 -3
- package/src/queries/sCoinQuery.ts +2 -2
- package/src/queries/spoolQuery.ts +57 -74
- package/src/queries/vescaQuery.ts +3 -3
- package/src/queries/xOracleQuery.ts +4 -21
- package/src/types/address.ts +47 -98
- package/src/types/builder/core.ts +40 -15
- package/src/types/builder/index.ts +17 -1
- package/src/types/constant/enum.ts +64 -0
- package/src/types/constant/index.ts +1 -2
- package/src/types/constant/xOracle.ts +7 -10
- package/src/types/index.ts +1 -1
- package/src/types/query/core.ts +3 -0
- package/src/types/query/index.ts +1 -0
- package/src/types/query/sCoin.ts +1 -0
- package/src/{builders/utils.ts → utils/builder.ts} +1 -1
- package/src/utils/core.ts +18 -0
- package/src/utils/index.ts +5 -0
- package/src/utils/indexer.ts +47 -0
- package/src/{queries/utils.ts → utils/query.ts} +7 -25
- package/src/utils/util.ts +42 -0
- package/src/builders/oracles/error.ts +0 -18
- package/src/builders/oracles/oraclePackageRegistry.ts +0 -336
- package/src/builders/oracles/priceFeedUpdater.ts +0 -112
- package/src/builders/oracles/priceUpdateRequester.ts +0 -50
- package/src/builders/oracles/xOracleUpdateStrategy.ts +0 -214
- package/src/builders/oracles/xOracleUpdater.ts +0 -153
- package/src/constants/api.ts +0 -2
- package/src/models/utils.ts +0 -97
- package/src/types/builder/type.ts +0 -25
- package/src/types/constant/package.ts +0 -16
- /package/src/types/{util.ts → utils.ts} +0 -0
package/src/index.ts
CHANGED
package/src/models/index.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// export type * from './interface';
|
|
2
1
|
export { default as Scallop } from './scallop';
|
|
3
2
|
export { default as ScallopClient } from './scallopClient';
|
|
4
3
|
export { default as ScallopBuilder } from './scallopBuilder';
|
|
@@ -7,6 +6,6 @@ export { default as ScallopAxios } from './scallopAxios';
|
|
|
7
6
|
export { default as ScallopConstants } from './scallopConstants';
|
|
8
7
|
export { default as ScallopIndexer } from './scallopIndexer';
|
|
9
8
|
export { default as ScallopQuery } from './scallopQuery';
|
|
10
|
-
export { default as ScallopQueryClient } from '
|
|
9
|
+
export { default as ScallopQueryClient } from '../models/scallopQueryClient';
|
|
11
10
|
export { default as ScallopUtils } from './scallopUtils';
|
|
12
11
|
export { default as ScallopSuiKit } from './scallopSuiKit';
|
package/src/models/interface.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
1
|
+
import ScallopAddress from './scallopAddress';
|
|
2
|
+
import ScallopBuilder from './scallopBuilder';
|
|
3
|
+
import ScallopConstants from './scallopConstants';
|
|
4
|
+
import ScallopQuery from './scallopQuery';
|
|
5
|
+
import ScallopSuiKit from './scallopSuiKit';
|
|
6
|
+
import ScallopUtils from './scallopUtils';
|
|
7
7
|
|
|
8
8
|
interface ScallopBaseInterface {
|
|
9
9
|
scallopSuiKit: ScallopSuiKit;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
export class RateLimiter {
|
|
2
|
+
private tokens: number;
|
|
3
|
+
private lastRefillTime: number;
|
|
4
|
+
private readonly refillRate: number; // tokens per millisecond
|
|
5
|
+
|
|
6
|
+
constructor(private readonly capacity: number = 10) {
|
|
7
|
+
this.refillRate = this.capacity / 1000; // 10 tokens per second = 0.01 tokens/ms
|
|
8
|
+
this.tokens = this.capacity;
|
|
9
|
+
this.lastRefillTime = Date.now();
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
private refill() {
|
|
13
|
+
const now = Date.now();
|
|
14
|
+
const elapsed = now - this.lastRefillTime;
|
|
15
|
+
const newTokens = elapsed * this.refillRate;
|
|
16
|
+
|
|
17
|
+
this.tokens = Math.min(this.capacity, this.tokens + newTokens);
|
|
18
|
+
this.lastRefillTime = now;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
private getTimeToNextToken(): number {
|
|
22
|
+
this.refill();
|
|
23
|
+
|
|
24
|
+
if (this.tokens >= 1) {
|
|
25
|
+
return 0;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Calculate exact milliseconds needed for 1 full token
|
|
29
|
+
const deficit = 1 - this.tokens;
|
|
30
|
+
return Math.ceil(deficit / this.refillRate);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async acquireToken(): Promise<void> {
|
|
34
|
+
// eslint-disable-next-line no-constant-condition
|
|
35
|
+
while (true) {
|
|
36
|
+
const waitTime = this.getTimeToNextToken();
|
|
37
|
+
|
|
38
|
+
if (waitTime === 0) {
|
|
39
|
+
if (this.tokens >= 1) {
|
|
40
|
+
this.tokens -= 1;
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
await new Promise((resolve) => setTimeout(resolve, waitTime));
|
|
47
|
+
this.refill();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async execute<T>(fn: () => Promise<T>): Promise<T> {
|
|
52
|
+
await this.acquireToken();
|
|
53
|
+
return await fn();
|
|
54
|
+
}
|
|
55
|
+
}
|
package/src/models/scallop.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { NetworkType } from '@scallop-io/sui-kit';
|
|
2
|
-
import { API_BASE_URL } from 'src/constants
|
|
3
|
-
import {
|
|
4
|
-
import { AddressesInterface, AddressStringPath } from 'src/types/address';
|
|
2
|
+
import { API_BASE_URL, queryKeys } from 'src/constants';
|
|
3
|
+
import { AddressesInterface, AddressStringPath } from 'src/types';
|
|
5
4
|
import ScallopAxios, { ScallopAxiosParams } from './scallopAxios';
|
|
6
5
|
import { QueryKey } from '@tanstack/query-core';
|
|
7
6
|
import { AxiosRequestConfig } from 'axios';
|
|
8
|
-
import { parseUrl } from '
|
|
7
|
+
import { parseUrl } from 'src/utils';
|
|
9
8
|
|
|
10
9
|
export type ScallopAddressParams = {
|
|
11
10
|
addressId?: string;
|
|
@@ -243,17 +242,6 @@ const EMPTY_ADDRESSES: AddressesInterface = {
|
|
|
243
242
|
state: '',
|
|
244
243
|
wormhole: '',
|
|
245
244
|
wormholeState: '',
|
|
246
|
-
lst: {
|
|
247
|
-
afsui: {
|
|
248
|
-
safeId: '',
|
|
249
|
-
stakedSuiVaultId: '',
|
|
250
|
-
configId: '',
|
|
251
|
-
},
|
|
252
|
-
hasui: {
|
|
253
|
-
configId: '',
|
|
254
|
-
staking: '',
|
|
255
|
-
},
|
|
256
|
-
},
|
|
257
245
|
},
|
|
258
246
|
},
|
|
259
247
|
packages: {
|
|
@@ -285,28 +273,12 @@ const EMPTY_ADDRESSES: AddressesInterface = {
|
|
|
285
273
|
id: '',
|
|
286
274
|
upgradeCap: '',
|
|
287
275
|
},
|
|
288
|
-
supra: {
|
|
289
|
-
id: '',
|
|
290
|
-
upgradeCap: '',
|
|
291
|
-
},
|
|
276
|
+
supra: { id: '', upgradeCap: '' },
|
|
292
277
|
pyth: {
|
|
293
278
|
id: '',
|
|
294
279
|
upgradeCap: '',
|
|
295
|
-
lst: {
|
|
296
|
-
afsui: {
|
|
297
|
-
id: '',
|
|
298
|
-
object: '',
|
|
299
|
-
},
|
|
300
|
-
hasui: {
|
|
301
|
-
id: '',
|
|
302
|
-
object: '',
|
|
303
|
-
},
|
|
304
|
-
},
|
|
305
|
-
},
|
|
306
|
-
switchboard: {
|
|
307
|
-
id: '',
|
|
308
|
-
upgradeCap: '',
|
|
309
280
|
},
|
|
281
|
+
switchboard: { id: '', upgradeCap: '' },
|
|
310
282
|
xOracle: {
|
|
311
283
|
id: '',
|
|
312
284
|
upgradeCap: '',
|
|
@@ -12,13 +12,13 @@ import type {
|
|
|
12
12
|
SuiTxArg,
|
|
13
13
|
SuiVecTxArg,
|
|
14
14
|
} from '@scallop-io/sui-kit';
|
|
15
|
-
import type { ScallopTxBlock
|
|
15
|
+
import type { ScallopTxBlock } from '../types';
|
|
16
16
|
import { ScallopBuilderInterface } from './interface';
|
|
17
17
|
|
|
18
18
|
export type ScallopBuilderParams = {
|
|
19
19
|
query?: ScallopQuery;
|
|
20
20
|
usePythPullModel?: boolean;
|
|
21
|
-
|
|
21
|
+
sponsoredFeeds?: string[];
|
|
22
22
|
useOnChainXOracleList?: boolean;
|
|
23
23
|
} & ScallopQueryParams;
|
|
24
24
|
|
|
@@ -37,13 +37,13 @@ class ScallopBuilder implements ScallopBuilderInterface {
|
|
|
37
37
|
public readonly query: ScallopQuery;
|
|
38
38
|
public readonly usePythPullModel: boolean;
|
|
39
39
|
public readonly useOnChainXOracleList: boolean;
|
|
40
|
-
public readonly
|
|
40
|
+
public readonly sponsoredFeeds: string[];
|
|
41
41
|
|
|
42
42
|
public constructor(params: ScallopBuilderParams) {
|
|
43
43
|
this.query = params.query ?? new ScallopQuery(params);
|
|
44
44
|
this.usePythPullModel = params.usePythPullModel ?? true;
|
|
45
45
|
this.useOnChainXOracleList = params.useOnChainXOracleList ?? true;
|
|
46
|
-
this.
|
|
46
|
+
this.sponsoredFeeds = params.sponsoredFeeds ?? [];
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
get utils() {
|
|
@@ -96,22 +96,25 @@ class ScallopBuilder implements ScallopBuilderInterface {
|
|
|
96
96
|
* @param assetCoinName - Specific support asset coin name.
|
|
97
97
|
* @param amount - Amount of coins to be selected.
|
|
98
98
|
* @param sender - Sender address.
|
|
99
|
+
* @param isSponsored - Whether the transaction is a sponsored transaction.
|
|
99
100
|
* @return Take coin and left coin.
|
|
100
101
|
*/
|
|
101
|
-
async selectCoin
|
|
102
|
+
async selectCoin(
|
|
102
103
|
txBlock: ScallopTxBlock | SuiKitTxBlock,
|
|
103
|
-
assetCoinName:
|
|
104
|
+
assetCoinName: string,
|
|
104
105
|
amount: number,
|
|
105
|
-
sender: string = this.walletAddress
|
|
106
|
-
|
|
107
|
-
|
|
106
|
+
sender: string = this.walletAddress,
|
|
107
|
+
isSponsored: boolean = false
|
|
108
|
+
) {
|
|
109
|
+
if (assetCoinName === 'sui' && !isSponsored) {
|
|
108
110
|
const [takeCoin] = txBlock.splitSUIFromGas([amount]);
|
|
109
|
-
return { takeCoin }
|
|
111
|
+
return { takeCoin };
|
|
110
112
|
} else {
|
|
111
113
|
const coinType = this.utils.parseCoinType(assetCoinName);
|
|
112
114
|
const coins = await this.utils.selectCoins(amount, coinType, sender);
|
|
113
115
|
const [takeCoin, leftCoin] = txBlock.takeAmountFromCoins(coins, amount);
|
|
114
|
-
|
|
116
|
+
|
|
117
|
+
return { takeCoin, leftCoin };
|
|
115
118
|
}
|
|
116
119
|
}
|
|
117
120
|
|
|
@@ -5,10 +5,10 @@ import type {
|
|
|
5
5
|
TransactionObjectArgument,
|
|
6
6
|
TransactionResult,
|
|
7
7
|
} from '@mysten/sui/transactions';
|
|
8
|
-
import { requireSender } from '
|
|
8
|
+
import { requireSender } from 'src/utils';
|
|
9
9
|
import type { NetworkType, SuiObjectArg } from '@scallop-io/sui-kit';
|
|
10
|
+
import type { ScallopTxBlock } from '../types';
|
|
10
11
|
import { ScallopClientInterface } from './interface';
|
|
11
|
-
import { ScallopTxBlock } from 'src/types/builder';
|
|
12
12
|
|
|
13
13
|
export type ScallopClientParams = {
|
|
14
14
|
networkType?: NetworkType;
|
|
@@ -210,6 +210,7 @@ class ScallopClient implements ScallopClientInterface {
|
|
|
210
210
|
* @param sign - Decide to directly sign the transaction or return the transaction block.
|
|
211
211
|
* @param obligationId - The obligation object.
|
|
212
212
|
* @param walletAddress - The wallet address of the owner.
|
|
213
|
+
* @param isSponsoredTx - Whether the transaction is sponsored.
|
|
213
214
|
* @return Transaction block response or transaction block.
|
|
214
215
|
*/
|
|
215
216
|
async depositCollateral(
|
|
@@ -221,30 +222,38 @@ class ScallopClient implements ScallopClientInterface {
|
|
|
221
222
|
amount: number,
|
|
222
223
|
sign?: S,
|
|
223
224
|
obligationId?: string,
|
|
224
|
-
walletAddress?: string
|
|
225
|
+
walletAddress?: string,
|
|
226
|
+
isSponsoredTx?: boolean
|
|
225
227
|
): Promise<ScallopClientFnReturnType<S>>;
|
|
226
228
|
async depositCollateral<S extends boolean>(
|
|
227
229
|
collateralCoinName: string,
|
|
228
230
|
amount: number,
|
|
229
231
|
sign: S = true as S,
|
|
230
232
|
obligationId?: string,
|
|
231
|
-
walletAddress?: string
|
|
233
|
+
walletAddress?: string,
|
|
234
|
+
isSponsoredTx?: boolean
|
|
232
235
|
): Promise<ScallopClientFnReturnType<S>> {
|
|
233
236
|
const txBlock = this.builder.createTxBlock();
|
|
234
237
|
const sender = walletAddress ?? this.walletAddress;
|
|
235
238
|
txBlock.setSender(sender);
|
|
236
239
|
|
|
237
|
-
const
|
|
238
|
-
|
|
240
|
+
const specificObligationId =
|
|
241
|
+
obligationId ?? (await this.query.getObligations(sender))[0]?.id;
|
|
239
242
|
if (specificObligationId) {
|
|
240
243
|
await txBlock.addCollateralQuick(
|
|
241
244
|
amount,
|
|
242
245
|
collateralCoinName,
|
|
243
|
-
specificObligationId
|
|
246
|
+
specificObligationId,
|
|
247
|
+
isSponsoredTx
|
|
244
248
|
);
|
|
245
249
|
} else {
|
|
246
250
|
const [obligation, obligationKey, hotPotato] = txBlock.openObligation();
|
|
247
|
-
await txBlock.addCollateralQuick(
|
|
251
|
+
await txBlock.addCollateralQuick(
|
|
252
|
+
amount,
|
|
253
|
+
collateralCoinName,
|
|
254
|
+
obligation,
|
|
255
|
+
isSponsoredTx
|
|
256
|
+
);
|
|
248
257
|
txBlock.returnObligation(obligation, hotPotato);
|
|
249
258
|
txBlock.transferObjects([obligationKey], sender);
|
|
250
259
|
}
|
|
@@ -267,6 +276,7 @@ class ScallopClient implements ScallopClientInterface {
|
|
|
267
276
|
* @param obligationId - The obligation object.
|
|
268
277
|
* @param obligationKey - The obligation key object to verifying obligation authority.
|
|
269
278
|
* @param walletAddress - The wallet address of the owner.
|
|
279
|
+
* @param isSponsoredTx - Whether the transaction is sponsored.
|
|
270
280
|
* @return Transaction block response or transaction block.
|
|
271
281
|
*/
|
|
272
282
|
async withdrawCollateral<S extends boolean>(
|
|
@@ -275,7 +285,8 @@ class ScallopClient implements ScallopClientInterface {
|
|
|
275
285
|
sign: S = true as S,
|
|
276
286
|
obligationId: string,
|
|
277
287
|
obligationKey: string,
|
|
278
|
-
walletAddress?: string
|
|
288
|
+
walletAddress?: string,
|
|
289
|
+
isSponsoredTx?: boolean
|
|
279
290
|
): Promise<ScallopClientFnReturnType<S>> {
|
|
280
291
|
const txBlock = this.builder.createTxBlock();
|
|
281
292
|
const sender = walletAddress ?? this.walletAddress;
|
|
@@ -285,7 +296,8 @@ class ScallopClient implements ScallopClientInterface {
|
|
|
285
296
|
amount,
|
|
286
297
|
collateralCoinName,
|
|
287
298
|
obligationId,
|
|
288
|
-
obligationKey
|
|
299
|
+
obligationKey,
|
|
300
|
+
{ isSponsoredTx }
|
|
289
301
|
);
|
|
290
302
|
txBlock.transferObjects([collateralCoin], sender);
|
|
291
303
|
|
|
@@ -449,6 +461,7 @@ class ScallopClient implements ScallopClientInterface {
|
|
|
449
461
|
* @param obligationId - The obligation object.
|
|
450
462
|
* @param obligationKey - The obligation key object to verifying obligation authority.
|
|
451
463
|
* @param walletAddress - The wallet address of the owner.
|
|
464
|
+
* @param isSponsoredTx - Whether the transaction is sponsored.
|
|
452
465
|
* @return Transaction block response or transaction block.
|
|
453
466
|
*/
|
|
454
467
|
async borrow<S extends boolean>(
|
|
@@ -457,7 +470,8 @@ class ScallopClient implements ScallopClientInterface {
|
|
|
457
470
|
sign: S = true as S,
|
|
458
471
|
obligationId: string,
|
|
459
472
|
obligationKey: string,
|
|
460
|
-
walletAddress?: string
|
|
473
|
+
walletAddress?: string,
|
|
474
|
+
isSponsoredTx?: boolean
|
|
461
475
|
): Promise<ScallopClientFnReturnType<S>> {
|
|
462
476
|
const txBlock = this.builder.createTxBlock();
|
|
463
477
|
const sender = walletAddress ?? this.walletAddress;
|
|
@@ -471,7 +485,8 @@ class ScallopClient implements ScallopClientInterface {
|
|
|
471
485
|
amount,
|
|
472
486
|
poolCoinName,
|
|
473
487
|
obligationId,
|
|
474
|
-
obligationKey
|
|
488
|
+
obligationKey,
|
|
489
|
+
{ isSponsoredTx }
|
|
475
490
|
);
|
|
476
491
|
txBlock.transferObjects([coin], sender);
|
|
477
492
|
if (sign && availableStake) {
|
|
@@ -495,6 +510,7 @@ class ScallopClient implements ScallopClientInterface {
|
|
|
495
510
|
* @param sign - Decide to directly sign the transaction or return the transaction block.
|
|
496
511
|
* @param obligationId - The obligation object.
|
|
497
512
|
* @param walletAddress - The wallet address of the owner.
|
|
513
|
+
* @param isSponsoredTx - Whether the transaction is sponsored.
|
|
498
514
|
* @return Transaction block response or transaction block.
|
|
499
515
|
*/
|
|
500
516
|
async repay<S extends boolean>(
|
|
@@ -503,7 +519,8 @@ class ScallopClient implements ScallopClientInterface {
|
|
|
503
519
|
sign: S = true as S,
|
|
504
520
|
obligationId: string,
|
|
505
521
|
obligationKey: string,
|
|
506
|
-
walletAddress?: string
|
|
522
|
+
walletAddress?: string,
|
|
523
|
+
isSponsoredTx?: boolean
|
|
507
524
|
): Promise<ScallopClientFnReturnType<S>> {
|
|
508
525
|
const txBlock = this.builder.createTxBlock();
|
|
509
526
|
const sender = walletAddress ?? this.walletAddress;
|
|
@@ -513,7 +530,7 @@ class ScallopClient implements ScallopClientInterface {
|
|
|
513
530
|
if (sign && availableStake) {
|
|
514
531
|
await txBlock.unstakeObligationQuick(obligationId, obligationKey);
|
|
515
532
|
}
|
|
516
|
-
await txBlock.repayQuick(amount, poolCoinName, obligationId);
|
|
533
|
+
await txBlock.repayQuick(amount, poolCoinName, obligationId, isSponsoredTx);
|
|
517
534
|
if (sign && availableStake) {
|
|
518
535
|
await txBlock.stakeObligationWithVeScaQuick(obligationId, obligationKey);
|
|
519
536
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { PoolAddress, Whitelist } from 'src/types
|
|
1
|
+
import { PoolAddress, Whitelist } from 'src/types';
|
|
2
2
|
import ScallopAddress, { ScallopAddressParams } from './scallopAddress';
|
|
3
3
|
import { NetworkType, parseStructTag } from '@scallop-io/sui-kit';
|
|
4
|
-
import { queryKeys } from 'src/constants
|
|
5
|
-
import { parseUrl } from '
|
|
4
|
+
import { queryKeys } from 'src/constants';
|
|
5
|
+
import { parseUrl } from 'src/utils';
|
|
6
6
|
|
|
7
7
|
const isEmptyObject = (obj: object) => {
|
|
8
8
|
return Object.keys(obj).length === 0;
|
|
@@ -10,10 +10,9 @@ import {
|
|
|
10
10
|
Spool,
|
|
11
11
|
Spools,
|
|
12
12
|
TotalValueLocked,
|
|
13
|
-
} from 'src/types
|
|
13
|
+
} from 'src/types';
|
|
14
14
|
import ScallopAxios, { ScallopAxiosParams } from './scallopAxios';
|
|
15
|
-
import { SDK_API_BASE_URL } from 'src/constants
|
|
16
|
-
import { queryKeys } from 'src/constants/queryKeys';
|
|
15
|
+
import { queryKeys, SDK_API_BASE_URL } from 'src/constants';
|
|
17
16
|
|
|
18
17
|
export type ScallopIndexerParams = {
|
|
19
18
|
indexerApiUrl?: string;
|
|
@@ -135,7 +134,7 @@ class ScallopIndexer extends ScallopAxios {
|
|
|
135
134
|
borrowIncentivePools: BorrowIncentivePool[];
|
|
136
135
|
}>(
|
|
137
136
|
'/api/borrowIncentivePools/migrate',
|
|
138
|
-
queryKeys.api.
|
|
137
|
+
queryKeys.api.getBorrowIncentivePools()
|
|
139
138
|
);
|
|
140
139
|
|
|
141
140
|
if (response.status === 200) {
|
|
@@ -1,83 +1,68 @@
|
|
|
1
1
|
import ScallopUtils, { ScallopUtilsParams } from './scallopUtils';
|
|
2
2
|
import ScallopIndexer, { ScallopIndexerParams } from './scallopIndexer';
|
|
3
|
-
import { withIndexerFallback } from '
|
|
3
|
+
import { withIndexerFallback } from 'src/utils';
|
|
4
4
|
import {
|
|
5
|
+
CoinPrices,
|
|
5
6
|
MarketCollaterals,
|
|
6
7
|
MarketPool,
|
|
7
8
|
MarketPools,
|
|
8
9
|
StakePools,
|
|
9
10
|
StakeRewardPools,
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
import { ScallopQueryInterface } from './interface';
|
|
11
|
+
SupportOracleType,
|
|
12
|
+
xOracleRules,
|
|
13
|
+
} from 'src/types';
|
|
14
14
|
import {
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
getAllCoinPrices,
|
|
16
|
+
getAssetOracles,
|
|
17
17
|
getBindedObligationId,
|
|
18
18
|
getBindedVeScaKey,
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
import {
|
|
22
|
-
queryMarket,
|
|
23
|
-
getMarketPools,
|
|
24
|
-
getMarketCollaterals,
|
|
25
|
-
getMarketCollateral,
|
|
26
|
-
getObligations,
|
|
27
|
-
queryObligation,
|
|
28
|
-
getCoinAmounts,
|
|
19
|
+
getBorrowIncentivePools,
|
|
20
|
+
getBorrowLimit,
|
|
29
21
|
getCoinAmount,
|
|
30
|
-
|
|
31
|
-
getMarketCoinAmount,
|
|
22
|
+
getCoinAmounts,
|
|
32
23
|
getFlashLoanFees,
|
|
33
|
-
} from 'src/queries/coreQuery';
|
|
34
|
-
import {
|
|
35
24
|
getIsolatedAssets,
|
|
36
|
-
isIsolatedAsset,
|
|
37
|
-
} from 'src/queries/isolatedAssetQuery';
|
|
38
|
-
import {
|
|
39
|
-
getLoyaltyProgramInformations,
|
|
40
|
-
getVeScaLoyaltyProgramInformations,
|
|
41
|
-
} from 'src/queries/loyaltyProgramQuery';
|
|
42
|
-
import { getPoolAddresses } from 'src/queries/poolAddressesQuery';
|
|
43
|
-
import {
|
|
44
|
-
getLendings,
|
|
45
25
|
getLending,
|
|
26
|
+
getLendings,
|
|
27
|
+
getLoyaltyProgramInformations,
|
|
28
|
+
getMarketCoinAmount,
|
|
29
|
+
getMarketCoinAmounts,
|
|
30
|
+
getMarketCollateral,
|
|
31
|
+
getMarketCollaterals,
|
|
32
|
+
getMarketPools,
|
|
33
|
+
getObligationAccount,
|
|
46
34
|
getObligationAccounts,
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
35
|
+
getObligationAccountsByIds,
|
|
36
|
+
getObligations,
|
|
37
|
+
getOnDemandAggObjectIds,
|
|
38
|
+
getPoolAddresses,
|
|
39
|
+
getPriceUpdatePolicies,
|
|
51
40
|
getPythPrice,
|
|
52
41
|
getPythPrices,
|
|
53
|
-
getAllCoinPrices,
|
|
54
|
-
} from 'src/queries/priceQuery';
|
|
55
|
-
import { queryVeScaKeyIdFromReferralBindings } from 'src/queries/referralQuery';
|
|
56
|
-
import {
|
|
57
|
-
getSCoinTotalSupply,
|
|
58
|
-
getSCoinAmounts,
|
|
59
42
|
getSCoinAmount,
|
|
43
|
+
getSCoinAmounts,
|
|
60
44
|
getSCoinSwapRate,
|
|
61
|
-
|
|
62
|
-
import {
|
|
45
|
+
getSCoinTotalSupply,
|
|
63
46
|
getSpools,
|
|
64
47
|
getStakeAccounts,
|
|
65
48
|
getStakePool,
|
|
66
49
|
getStakeRewardPool,
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
import {
|
|
50
|
+
getSupplyLimit,
|
|
51
|
+
getTotalValueLocked,
|
|
52
|
+
getUserPortfolio,
|
|
71
53
|
getVeSca,
|
|
54
|
+
getVeScaLoyaltyProgramInformations,
|
|
72
55
|
getVeScas,
|
|
73
56
|
getVeScaTreasuryInfo,
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
import {
|
|
57
|
+
isIsolatedAsset,
|
|
58
|
+
queryBorrowIncentiveAccounts,
|
|
59
|
+
queryMarket,
|
|
60
|
+
queryObligation,
|
|
61
|
+
queryVeScaKeyIdFromReferralBindings,
|
|
62
|
+
} from 'src/queries';
|
|
63
|
+
import { SuiObjectRef, SuiObjectData } from '@mysten/sui/dist/cjs/client';
|
|
64
|
+
import { SuiObjectArg } from '@scallop-io/sui-kit';
|
|
65
|
+
import { ScallopQueryInterface } from './interface';
|
|
81
66
|
|
|
82
67
|
export type ScallopQueryParams = {
|
|
83
68
|
indexer?: ScallopIndexer;
|
|
@@ -125,6 +110,14 @@ class ScallopQuery implements ScallopQueryInterface {
|
|
|
125
110
|
this,
|
|
126
111
|
this.getObligationAccounts
|
|
127
112
|
);
|
|
113
|
+
this.getObligationAccountsByIds = withIndexerFallback.call(
|
|
114
|
+
this,
|
|
115
|
+
this.getObligationAccountsByIds
|
|
116
|
+
);
|
|
117
|
+
this.getObligationAccountById = withIndexerFallback.call(
|
|
118
|
+
this,
|
|
119
|
+
this.getObligationAccountById
|
|
120
|
+
);
|
|
128
121
|
this.getObligationAccount = withIndexerFallback.call(
|
|
129
122
|
this,
|
|
130
123
|
this.getObligationAccount
|
|
@@ -575,13 +568,13 @@ class ScallopQuery implements ScallopQueryInterface {
|
|
|
575
568
|
}
|
|
576
569
|
|
|
577
570
|
/**
|
|
578
|
-
* Get user all obligation accounts information.
|
|
571
|
+
* Get user all obligation accounts information from ownerAddress.
|
|
579
572
|
*
|
|
580
573
|
* @description
|
|
581
574
|
* All collateral and borrowing information in all obligation accounts owned by the user.
|
|
582
575
|
*
|
|
583
576
|
* @param ownerAddress - The owner address.
|
|
584
|
-
* @param
|
|
577
|
+
* @param args - Additional arguments.
|
|
585
578
|
* @return All obligation accounts information.
|
|
586
579
|
*/
|
|
587
580
|
async getObligationAccounts(
|
|
@@ -604,6 +597,68 @@ class ScallopQuery implements ScallopQueryInterface {
|
|
|
604
597
|
);
|
|
605
598
|
}
|
|
606
599
|
|
|
600
|
+
/**
|
|
601
|
+
* Get user all obligation accounts information from obligationIds.
|
|
602
|
+
*
|
|
603
|
+
* @description
|
|
604
|
+
* All collateral and borrowing information in all obligation accounts.
|
|
605
|
+
*
|
|
606
|
+
* @param obligationIds - Obligation IDs.
|
|
607
|
+
* @param args - Additional arguments.
|
|
608
|
+
* @return All obligation accounts information.
|
|
609
|
+
*/
|
|
610
|
+
async getObligationAccountsByIds(
|
|
611
|
+
obligationIds: string[],
|
|
612
|
+
args?: {
|
|
613
|
+
market?: {
|
|
614
|
+
collaterals: MarketCollaterals;
|
|
615
|
+
pools: MarketPools;
|
|
616
|
+
};
|
|
617
|
+
coinPrices?: CoinPrices;
|
|
618
|
+
indexer?: boolean;
|
|
619
|
+
}
|
|
620
|
+
) {
|
|
621
|
+
return await getObligationAccountsByIds(
|
|
622
|
+
this,
|
|
623
|
+
obligationIds,
|
|
624
|
+
args?.market,
|
|
625
|
+
args?.coinPrices,
|
|
626
|
+
args?.indexer
|
|
627
|
+
);
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
/**
|
|
631
|
+
* Get obligation account by id
|
|
632
|
+
*
|
|
633
|
+
* @description
|
|
634
|
+
* All collateral and borrowing information in obligation account.
|
|
635
|
+
*
|
|
636
|
+
* @param obligationId - Obligation ID.
|
|
637
|
+
* @param args - Additional arguments.
|
|
638
|
+
* @return All obligation accounts information.
|
|
639
|
+
*/
|
|
640
|
+
async getObligationAccountById(
|
|
641
|
+
obligationId: string,
|
|
642
|
+
args?: {
|
|
643
|
+
market?: {
|
|
644
|
+
collaterals: MarketCollaterals;
|
|
645
|
+
pools: MarketPools;
|
|
646
|
+
};
|
|
647
|
+
coinPrices?: CoinPrices;
|
|
648
|
+
indexer?: boolean;
|
|
649
|
+
}
|
|
650
|
+
) {
|
|
651
|
+
return await getObligationAccount(
|
|
652
|
+
this,
|
|
653
|
+
obligationId,
|
|
654
|
+
'',
|
|
655
|
+
args?.indexer,
|
|
656
|
+
args?.market,
|
|
657
|
+
args?.coinPrices,
|
|
658
|
+
{}
|
|
659
|
+
);
|
|
660
|
+
}
|
|
661
|
+
|
|
607
662
|
/**
|
|
608
663
|
* Get obligation account information for specific id.
|
|
609
664
|
*
|
|
@@ -612,7 +667,7 @@ class ScallopQuery implements ScallopQueryInterface {
|
|
|
612
667
|
*
|
|
613
668
|
* @param obligationId - The obligation id.
|
|
614
669
|
* @param ownerAddress - The owner address.
|
|
615
|
-
* @param
|
|
670
|
+
* @param args - Additional arguments.
|
|
616
671
|
* @return Borrowing and collateral information.
|
|
617
672
|
*/
|
|
618
673
|
async getObligationAccount(
|
|
@@ -868,6 +923,7 @@ class ScallopQuery implements ScallopQueryInterface {
|
|
|
868
923
|
|
|
869
924
|
/**
|
|
870
925
|
* Return the supported primary and secondary oracles for all supported pool assets
|
|
926
|
+
* @returns
|
|
871
927
|
*/
|
|
872
928
|
async getAssetOracles() {
|
|
873
929
|
const [primary, secondary] = await Promise.all([
|