@scallop-io/sui-scallop-sdk 0.46.54 → 0.46.56
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/pyth.d.ts +1 -1
- package/dist/index.js +1752 -1605
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1711 -1564
- package/dist/index.mjs.map +1 -1
- package/dist/models/scallop.d.ts +1 -1
- package/dist/models/scallopAddress.d.ts +4 -4
- package/dist/models/scallopBuilder.d.ts +2 -2
- package/dist/models/scallopCache.d.ts +2 -2
- package/dist/models/scallopClient.d.ts +7 -2
- package/dist/models/scallopIndexer.d.ts +3 -3
- package/dist/models/scallopPrice.d.ts +0 -0
- package/dist/models/scallopQuery.d.ts +10 -4
- package/dist/models/scallopUtils.d.ts +8 -7
- package/dist/queries/borrowIncentiveQuery.d.ts +10 -4
- package/dist/queries/coreQuery.d.ts +8 -4
- package/dist/queries/priceQuery.d.ts +7 -3
- package/dist/queries/referralQuery.d.ts +2 -2
- package/dist/queries/sCoinQuery.d.ts +18 -4
- package/dist/queries/spoolQuery.d.ts +10 -4
- package/dist/queries/vescaQuery.d.ts +7 -5
- package/dist/types/builder/vesca.d.ts +2 -1
- package/dist/types/model.d.ts +27 -12
- package/dist/types/query/core.d.ts +1 -0
- package/package.json +1 -1
- package/src/builders/borrowIncentiveBuilder.ts +19 -21
- package/src/builders/coreBuilder.ts +10 -8
- package/src/builders/loyaltyProgramBuilder.ts +2 -6
- package/src/builders/spoolBuilder.ts +2 -2
- package/src/builders/vescaBuilder.ts +12 -4
- package/src/constants/common.ts +2 -0
- package/src/constants/enum.ts +4 -0
- package/src/constants/pyth.ts +2 -2
- package/src/models/scallop.ts +14 -20
- package/src/models/scallopAddress.ts +15 -5
- package/src/models/scallopBuilder.ts +29 -25
- package/src/models/scallopCache.ts +2 -2
- package/src/models/scallopClient.ts +91 -32
- package/src/models/scallopIndexer.ts +15 -8
- package/src/models/scallopPrice.ts +0 -0
- package/src/models/scallopQuery.ts +47 -25
- package/src/models/scallopUtils.ts +75 -74
- package/src/queries/borrowIncentiveQuery.ts +40 -29
- package/src/queries/coreQuery.ts +38 -24
- package/src/queries/portfolioQuery.ts +1 -2
- package/src/queries/priceQuery.ts +20 -9
- package/src/queries/referralQuery.ts +4 -4
- package/src/queries/sCoinQuery.ts +95 -17
- package/src/queries/spoolQuery.ts +26 -14
- package/src/queries/vescaQuery.ts +32 -26
- package/src/types/builder/vesca.ts +8 -1
- package/src/types/model.ts +40 -11
- package/src/types/query/core.ts +1 -0
|
@@ -36,7 +36,6 @@ import {
|
|
|
36
36
|
} from '../queries';
|
|
37
37
|
import {
|
|
38
38
|
ScallopQueryParams,
|
|
39
|
-
ScallopInstanceParams,
|
|
40
39
|
SupportStakeMarketCoins,
|
|
41
40
|
SupportAssetCoins,
|
|
42
41
|
SupportPoolCoins,
|
|
@@ -46,6 +45,7 @@ import {
|
|
|
46
45
|
StakeRewardPools,
|
|
47
46
|
SupportBorrowIncentiveCoins,
|
|
48
47
|
SupportSCoin,
|
|
48
|
+
ScallopQueryInstanceParams,
|
|
49
49
|
} from '../types';
|
|
50
50
|
import { ScallopAddress } from './scallopAddress';
|
|
51
51
|
import { ScallopUtils } from './scallopUtils';
|
|
@@ -56,6 +56,7 @@ import { SuiObjectData } from '@mysten/sui.js/client';
|
|
|
56
56
|
import {
|
|
57
57
|
getSCoinAmount,
|
|
58
58
|
getSCoinAmounts,
|
|
59
|
+
getSCoinSwapRate,
|
|
59
60
|
getSCoinTotalSupply,
|
|
60
61
|
} from 'src/queries/sCoinQuery';
|
|
61
62
|
import { normalizeSuiAddress } from '@mysten/sui.js/utils';
|
|
@@ -84,32 +85,36 @@ export class ScallopQuery {
|
|
|
84
85
|
|
|
85
86
|
public constructor(
|
|
86
87
|
params: ScallopQueryParams,
|
|
87
|
-
instance?:
|
|
88
|
+
instance?: ScallopQueryInstanceParams
|
|
88
89
|
) {
|
|
89
90
|
this.params = params;
|
|
90
|
-
this.suiKit =
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
instance
|
|
95
|
-
|
|
91
|
+
this.suiKit =
|
|
92
|
+
instance?.suiKit ?? instance?.utils?.suiKit ?? new SuiKit(params);
|
|
93
|
+
if (instance?.utils) {
|
|
94
|
+
this.utils = instance.utils;
|
|
95
|
+
this.address = instance.utils.address;
|
|
96
|
+
this.cache = this.address.cache;
|
|
97
|
+
} else {
|
|
98
|
+
this.cache = new ScallopCache(this.suiKit, DEFAULT_CACHE_OPTIONS);
|
|
99
|
+
this.address = new ScallopAddress(
|
|
96
100
|
{
|
|
97
101
|
id: params?.addressesId || ADDRESSES_ID,
|
|
98
102
|
network: params?.networkType,
|
|
99
103
|
},
|
|
100
|
-
|
|
104
|
+
{
|
|
105
|
+
cache: this.cache,
|
|
106
|
+
}
|
|
101
107
|
);
|
|
102
|
-
|
|
103
|
-
instance?.utils ??
|
|
104
|
-
new ScallopUtils(this.params, {
|
|
105
|
-
suiKit: this.suiKit,
|
|
108
|
+
this.utils = new ScallopUtils(this.params, {
|
|
106
109
|
address: this.address,
|
|
107
|
-
cache: this.cache,
|
|
108
|
-
query: this,
|
|
109
110
|
});
|
|
110
|
-
|
|
111
|
+
}
|
|
112
|
+
this.indexer =
|
|
113
|
+
instance?.indexer ??
|
|
114
|
+
new ScallopIndexer(this.params, { cache: this.cache });
|
|
115
|
+
|
|
111
116
|
this.walletAddress = normalizeSuiAddress(
|
|
112
|
-
params
|
|
117
|
+
params.walletAddress || this.suiKit.currentAddress()
|
|
113
118
|
);
|
|
114
119
|
}
|
|
115
120
|
|
|
@@ -365,8 +370,9 @@ export class ScallopQuery {
|
|
|
365
370
|
* @param stakeMarketCoinNames - Specific an array of support stake market coin name.
|
|
366
371
|
* @return Stake pools data.
|
|
367
372
|
*/
|
|
368
|
-
public async getStakePools(
|
|
369
|
-
stakeMarketCoinNames =
|
|
373
|
+
public async getStakePools(
|
|
374
|
+
stakeMarketCoinNames: SupportStakeMarketCoins[] = [...SUPPORT_SPOOLS]
|
|
375
|
+
) {
|
|
370
376
|
const stakePools: StakePools = {};
|
|
371
377
|
for (const stakeMarketCoinName of stakeMarketCoinNames) {
|
|
372
378
|
const stakePool = await getStakePool(this, stakeMarketCoinName);
|
|
@@ -404,9 +410,8 @@ export class ScallopQuery {
|
|
|
404
410
|
* @return Stake reward pools data.
|
|
405
411
|
*/
|
|
406
412
|
public async getStakeRewardPools(
|
|
407
|
-
stakeMarketCoinNames
|
|
413
|
+
stakeMarketCoinNames: SupportStakeMarketCoins[] = [...SUPPORT_SPOOLS]
|
|
408
414
|
) {
|
|
409
|
-
stakeMarketCoinNames = stakeMarketCoinNames ?? [...SUPPORT_SPOOLS];
|
|
410
415
|
const stakeRewardPools: StakeRewardPools = {};
|
|
411
416
|
await Promise.allSettled(
|
|
412
417
|
stakeMarketCoinNames.map(async (stakeMarketCoinName) => {
|
|
@@ -558,7 +563,7 @@ export class ScallopQuery {
|
|
|
558
563
|
* @param walletAddress
|
|
559
564
|
* @returns array of veSca
|
|
560
565
|
*/
|
|
561
|
-
public async getVeScas(walletAddress
|
|
566
|
+
public async getVeScas(walletAddress: string = this.walletAddress) {
|
|
562
567
|
return await getVeScas(this, walletAddress);
|
|
563
568
|
}
|
|
564
569
|
|
|
@@ -567,7 +572,7 @@ export class ScallopQuery {
|
|
|
567
572
|
* @returns Promise<string | undefined>
|
|
568
573
|
*/
|
|
569
574
|
public async getVeScaTreasuryInfo() {
|
|
570
|
-
return await getVeScaTreasuryInfo(this);
|
|
575
|
+
return await getVeScaTreasuryInfo(this.utils);
|
|
571
576
|
}
|
|
572
577
|
|
|
573
578
|
/**
|
|
@@ -575,8 +580,13 @@ export class ScallopQuery {
|
|
|
575
580
|
* @param walletAddress
|
|
576
581
|
* @returns veScaKeyId
|
|
577
582
|
*/
|
|
578
|
-
public async getVeScaKeyIdFromReferralBindings(
|
|
579
|
-
|
|
583
|
+
public async getVeScaKeyIdFromReferralBindings(
|
|
584
|
+
walletAddress: string = this.walletAddress
|
|
585
|
+
) {
|
|
586
|
+
return await queryVeScaKeyIdFromReferralBindings(
|
|
587
|
+
this.address,
|
|
588
|
+
walletAddress
|
|
589
|
+
);
|
|
580
590
|
}
|
|
581
591
|
|
|
582
592
|
/**
|
|
@@ -646,6 +656,18 @@ export class ScallopQuery {
|
|
|
646
656
|
: 0;
|
|
647
657
|
}
|
|
648
658
|
|
|
659
|
+
/**
|
|
660
|
+
* Get swap rate from sCoin A to sCoin B
|
|
661
|
+
* @param assetCoinNames
|
|
662
|
+
* @returns
|
|
663
|
+
*/
|
|
664
|
+
public async getSCoinSwapRate(
|
|
665
|
+
fromSCoin: SupportSCoin,
|
|
666
|
+
toSCoin: SupportSCoin
|
|
667
|
+
) {
|
|
668
|
+
return await getSCoinSwapRate(this, fromSCoin, toSCoin);
|
|
669
|
+
}
|
|
670
|
+
|
|
649
671
|
/*
|
|
650
672
|
* Get flashloan fee for specified assets
|
|
651
673
|
*/
|
|
@@ -2,7 +2,6 @@ import { SUI_TYPE_ARG, normalizeStructTag } from '@mysten/sui.js/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';
|
|
5
|
-
import { ScallopQuery } from './scallopQuery';
|
|
6
5
|
import {
|
|
7
6
|
ADDRESSES_ID,
|
|
8
7
|
PROTOCOL_OBJECT_ID,
|
|
@@ -19,7 +18,7 @@ import {
|
|
|
19
18
|
SUPPORT_SCOIN,
|
|
20
19
|
sCoinIds,
|
|
21
20
|
} from '../constants';
|
|
22
|
-
import { queryObligation } from '../queries';
|
|
21
|
+
import { getPythPrice, queryObligation } from '../queries';
|
|
23
22
|
import {
|
|
24
23
|
parseDataFromPythPriceFeed,
|
|
25
24
|
isMarketCoin,
|
|
@@ -31,7 +30,6 @@ import { ScallopCache } from './scallopCache';
|
|
|
31
30
|
import { DEFAULT_CACHE_OPTIONS } from 'src/constants/cache';
|
|
32
31
|
import type {
|
|
33
32
|
ScallopUtilsParams,
|
|
34
|
-
ScallopInstanceParams,
|
|
35
33
|
SupportCoins,
|
|
36
34
|
SupportAssetCoins,
|
|
37
35
|
SupportMarketCoins,
|
|
@@ -41,6 +39,7 @@ import type {
|
|
|
41
39
|
PriceMap,
|
|
42
40
|
CoinWrappedType,
|
|
43
41
|
SupportSCoin,
|
|
42
|
+
ScallopUtilsInstanceParams,
|
|
44
43
|
} from '../types';
|
|
45
44
|
import type { SuiAddressArg, SuiTxArg, SuiTxBlock } from '@scallop-io/sui-kit';
|
|
46
45
|
|
|
@@ -60,36 +59,42 @@ export class ScallopUtils {
|
|
|
60
59
|
public readonly params: ScallopUtilsParams;
|
|
61
60
|
public readonly isTestnet: boolean;
|
|
62
61
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
62
|
+
public suiKit: SuiKit;
|
|
63
|
+
public address: ScallopAddress;
|
|
64
|
+
public cache: ScallopCache;
|
|
66
65
|
private _priceMap: PriceMap = new Map();
|
|
67
|
-
private _cache: ScallopCache;
|
|
68
66
|
|
|
69
67
|
public constructor(
|
|
70
68
|
params: ScallopUtilsParams,
|
|
71
|
-
instance?:
|
|
69
|
+
instance?: ScallopUtilsInstanceParams
|
|
72
70
|
) {
|
|
73
|
-
this.params =
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
this.
|
|
78
|
-
instance?.
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
71
|
+
this.params = {
|
|
72
|
+
pythEndpoints: params.pythEndpoints ?? PYTH_ENDPOINTS['mainnet'],
|
|
73
|
+
...params,
|
|
74
|
+
};
|
|
75
|
+
this.suiKit =
|
|
76
|
+
instance?.suiKit ??
|
|
77
|
+
instance?.address?.cache._suiKit ??
|
|
78
|
+
new SuiKit(params);
|
|
79
|
+
|
|
80
|
+
if (instance?.address) {
|
|
81
|
+
this.address = instance.address;
|
|
82
|
+
this.cache = this.address.cache;
|
|
83
|
+
this.suiKit = this.address.cache._suiKit;
|
|
84
|
+
} else {
|
|
85
|
+
this.cache = new ScallopCache(this.suiKit, DEFAULT_CACHE_OPTIONS);
|
|
86
|
+
this.address =
|
|
87
|
+
instance?.address ??
|
|
88
|
+
new ScallopAddress(
|
|
89
|
+
{
|
|
90
|
+
id: params?.addressesId || ADDRESSES_ID,
|
|
91
|
+
network: params?.networkType,
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
cache: this.cache,
|
|
95
|
+
}
|
|
96
|
+
);
|
|
97
|
+
}
|
|
93
98
|
this.isTestnet = params.networkType
|
|
94
99
|
? params.networkType === 'testnet'
|
|
95
100
|
: false;
|
|
@@ -102,14 +107,10 @@ export class ScallopUtils {
|
|
|
102
107
|
* @param address - ScallopAddress instance.
|
|
103
108
|
*/
|
|
104
109
|
public async init(force: boolean = false, address?: ScallopAddress) {
|
|
105
|
-
if (force || !this.
|
|
106
|
-
await this.
|
|
110
|
+
if (force || !this.address.getAddresses() || !address?.getAddresses()) {
|
|
111
|
+
await this.address.read();
|
|
107
112
|
} else {
|
|
108
|
-
this.
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
if (!this._query.address.getAddresses()) {
|
|
112
|
-
await this._query.init(force, this._address);
|
|
113
|
+
this.address = address;
|
|
113
114
|
}
|
|
114
115
|
}
|
|
115
116
|
|
|
@@ -146,7 +147,7 @@ export class ScallopUtils {
|
|
|
146
147
|
public parseCoinType(coinName: SupportCoins) {
|
|
147
148
|
coinName = isMarketCoin(coinName) ? this.parseCoinName(coinName) : coinName;
|
|
148
149
|
const coinPackageId =
|
|
149
|
-
this.
|
|
150
|
+
this.address.get(`core.coins.${coinName}.id`) ||
|
|
150
151
|
coinIds[coinName] ||
|
|
151
152
|
undefined;
|
|
152
153
|
if (!coinPackageId) {
|
|
@@ -154,20 +155,20 @@ export class ScallopUtils {
|
|
|
154
155
|
}
|
|
155
156
|
if (coinName === 'sui')
|
|
156
157
|
return normalizeStructTag(`${coinPackageId}::sui::SUI`);
|
|
157
|
-
const
|
|
158
|
-
this.
|
|
159
|
-
this.
|
|
160
|
-
this.
|
|
161
|
-
this.
|
|
162
|
-
this.
|
|
163
|
-
this.
|
|
158
|
+
const wormHolePackageIds = [
|
|
159
|
+
this.address.get('core.coins.usdc.id') ?? wormholeCoinIds.usdc,
|
|
160
|
+
this.address.get('core.coins.usdt.id') ?? wormholeCoinIds.usdt,
|
|
161
|
+
this.address.get('core.coins.eth.id') ?? wormholeCoinIds.eth,
|
|
162
|
+
this.address.get('core.coins.btc.id') ?? wormholeCoinIds.btc,
|
|
163
|
+
this.address.get('core.coins.sol.id') ?? wormholeCoinIds.sol,
|
|
164
|
+
this.address.get('core.coins.apt.id') ?? wormholeCoinIds.apt,
|
|
164
165
|
];
|
|
165
|
-
const
|
|
166
|
-
this.
|
|
166
|
+
const voloPackageIds = [
|
|
167
|
+
this.address.get('core.coins.vsui.id') ?? voloCoinIds.vsui,
|
|
167
168
|
];
|
|
168
|
-
if (
|
|
169
|
+
if (wormHolePackageIds.includes(coinPackageId)) {
|
|
169
170
|
return `${coinPackageId}::coin::COIN`;
|
|
170
|
-
} else if (
|
|
171
|
+
} else if (voloPackageIds.includes(coinPackageId)) {
|
|
171
172
|
return `${coinPackageId}::cert::CERT`;
|
|
172
173
|
} else {
|
|
173
174
|
return `${coinPackageId}::${coinName}::${coinName.toUpperCase()}`;
|
|
@@ -222,7 +223,7 @@ export class ScallopUtils {
|
|
|
222
223
|
* @returns sCoin treasury id
|
|
223
224
|
*/
|
|
224
225
|
public getSCoinTreasury(sCoinName: SupportSCoin) {
|
|
225
|
-
return this.
|
|
226
|
+
return this.address.get(`scoin.coins.${sCoinName}.treasury`);
|
|
226
227
|
}
|
|
227
228
|
|
|
228
229
|
/**
|
|
@@ -234,7 +235,7 @@ export class ScallopUtils {
|
|
|
234
235
|
*/
|
|
235
236
|
public parseMarketCoinType(coinName: SupportCoins) {
|
|
236
237
|
const protocolObjectId =
|
|
237
|
-
this.
|
|
238
|
+
this.address.get('core.object') || PROTOCOL_OBJECT_ID;
|
|
238
239
|
const coinType = this.parseCoinType(coinName);
|
|
239
240
|
return `${protocolObjectId}::reserve::MarketCoin<${coinType}>`;
|
|
240
241
|
}
|
|
@@ -267,27 +268,27 @@ export class ScallopUtils {
|
|
|
267
268
|
|
|
268
269
|
const wormHoleCoinTypeMap: Record<string, SupportAssetCoins> = {
|
|
269
270
|
[`${
|
|
270
|
-
this.
|
|
271
|
+
this.address.get('core.coins.usdc.id') ?? wormholeCoinIds.usdc
|
|
271
272
|
}::coin::COIN`]: 'usdc',
|
|
272
273
|
[`${
|
|
273
|
-
this.
|
|
274
|
+
this.address.get('core.coins.usdt.id') ?? wormholeCoinIds.usdt
|
|
274
275
|
}::coin::COIN`]: 'usdt',
|
|
275
276
|
[`${
|
|
276
|
-
this.
|
|
277
|
+
this.address.get('core.coins.eth.id') ?? wormholeCoinIds.eth
|
|
277
278
|
}::coin::COIN`]: 'eth',
|
|
278
279
|
[`${
|
|
279
|
-
this.
|
|
280
|
+
this.address.get('core.coins.btc.id') ?? wormholeCoinIds.btc
|
|
280
281
|
}::coin::COIN`]: 'btc',
|
|
281
282
|
[`${
|
|
282
|
-
this.
|
|
283
|
+
this.address.get('core.coins.sol.id') ?? wormholeCoinIds.sol
|
|
283
284
|
}::coin::COIN`]: 'sol',
|
|
284
285
|
[`${
|
|
285
|
-
this.
|
|
286
|
+
this.address.get('core.coins.apt.id') ?? wormholeCoinIds.apt
|
|
286
287
|
}::coin::COIN`]: 'apt',
|
|
287
288
|
};
|
|
288
289
|
const voloCoinTypeMap: Record<string, SupportAssetCoins> = {
|
|
289
290
|
[`${
|
|
290
|
-
this.
|
|
291
|
+
this.address.get('core.coins.vsui.id') ?? voloCoinIds.vsui
|
|
291
292
|
}::cert::CERT`]: 'vsui',
|
|
292
293
|
};
|
|
293
294
|
|
|
@@ -388,8 +389,8 @@ export class ScallopUtils {
|
|
|
388
389
|
coinType: string = SUI_TYPE_ARG,
|
|
389
390
|
ownerAddress?: string
|
|
390
391
|
) {
|
|
391
|
-
ownerAddress = ownerAddress || this.
|
|
392
|
-
const coins = await this.
|
|
392
|
+
ownerAddress = ownerAddress || this.suiKit.currentAddress();
|
|
393
|
+
const coins = await this.suiKit.suiInteractor.selectCoins(
|
|
393
394
|
ownerAddress,
|
|
394
395
|
amount,
|
|
395
396
|
coinType
|
|
@@ -412,14 +413,14 @@ export class ScallopUtils {
|
|
|
412
413
|
): Promise<void> {
|
|
413
414
|
// merge to existing coins if exist
|
|
414
415
|
try {
|
|
415
|
-
const
|
|
416
|
+
const existingCoins = await this.selectCoins(
|
|
416
417
|
Number.MAX_SAFE_INTEGER,
|
|
417
418
|
coinType,
|
|
418
419
|
sender
|
|
419
420
|
);
|
|
420
421
|
|
|
421
|
-
if (
|
|
422
|
-
txBlock.mergeCoins(dest,
|
|
422
|
+
if (existingCoins.length > 0) {
|
|
423
|
+
txBlock.mergeCoins(dest, existingCoins.slice(0, 500));
|
|
423
424
|
}
|
|
424
425
|
} catch (e) {
|
|
425
426
|
// ignore
|
|
@@ -437,15 +438,15 @@ export class ScallopUtils {
|
|
|
437
438
|
* @return Asset coin Names.
|
|
438
439
|
*/
|
|
439
440
|
public async getObligationCoinNames(obligationId: SuiAddressArg) {
|
|
440
|
-
const obligation = await queryObligation(this
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
441
|
+
const obligation = await queryObligation(this, obligationId);
|
|
442
|
+
if (!obligation) return undefined;
|
|
443
|
+
|
|
444
|
+
const collateralCoinTypes = obligation.collaterals.map((collateral) => {
|
|
445
|
+
return `0x${collateral.type.name}`;
|
|
446
|
+
});
|
|
447
|
+
const debtCoinTypes = obligation.debts.map((debt) => {
|
|
448
|
+
return `0x${debt.type.name}`;
|
|
449
|
+
});
|
|
449
450
|
const obligationCoinTypes = [
|
|
450
451
|
...new Set([...collateralCoinTypes, ...debtCoinTypes]),
|
|
451
452
|
];
|
|
@@ -507,7 +508,7 @@ export class ScallopUtils {
|
|
|
507
508
|
for (const endpoint of endpoints) {
|
|
508
509
|
const priceIds = Array.from(failedRequests.values()).reduce(
|
|
509
510
|
(acc, coinName) => {
|
|
510
|
-
const priceId = this.
|
|
511
|
+
const priceId = this.address.get(
|
|
511
512
|
`core.coins.${coinName}.oracle.pyth.feed`
|
|
512
513
|
);
|
|
513
514
|
acc[coinName] = priceId;
|
|
@@ -520,14 +521,14 @@ export class ScallopUtils {
|
|
|
520
521
|
Object.entries(priceIds).map(async ([coinName, priceId]) => {
|
|
521
522
|
const pythConnection = new SuiPriceServiceConnection(endpoint);
|
|
522
523
|
try {
|
|
523
|
-
const feed = await this.
|
|
524
|
+
const feed = await this.address.cache.queryClient.fetchQuery({
|
|
524
525
|
queryKey: [priceId],
|
|
525
526
|
queryFn: async () => {
|
|
526
527
|
return await pythConnection.getLatestPriceFeeds([priceId]);
|
|
527
528
|
},
|
|
528
529
|
});
|
|
529
530
|
if (feed) {
|
|
530
|
-
const data = parseDataFromPythPriceFeed(feed[0], this.
|
|
531
|
+
const data = parseDataFromPythPriceFeed(feed[0], this.address);
|
|
531
532
|
this._priceMap.set(coinName as SupportAssetCoins, {
|
|
532
533
|
price: data.price,
|
|
533
534
|
publishTime: data.publishTime,
|
|
@@ -548,7 +549,7 @@ export class ScallopUtils {
|
|
|
548
549
|
if (failedRequests.size > 0) {
|
|
549
550
|
await Promise.allSettled(
|
|
550
551
|
Array.from(failedRequests.values()).map(async (coinName) => {
|
|
551
|
-
const price = await this
|
|
552
|
+
const price = await getPythPrice(this, coinName);
|
|
552
553
|
this._priceMap.set(coinName, {
|
|
553
554
|
price: price,
|
|
554
555
|
publishTime: Date.now(),
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
parseOriginBorrowIncentiveAccountData,
|
|
9
9
|
calculateBorrowIncentivePoolPointData,
|
|
10
10
|
} from '../utils';
|
|
11
|
-
import type { ScallopQuery } from '../models';
|
|
11
|
+
import type { ScallopAddress, ScallopQuery, ScallopUtils } from '../models';
|
|
12
12
|
import type {
|
|
13
13
|
BorrowIncentivePoolsQueryInterface,
|
|
14
14
|
BorrowIncentivePools,
|
|
@@ -163,24 +163,27 @@ export const queryBorrowIncentivePools = async (
|
|
|
163
163
|
* @return Borrow incentive accounts data.
|
|
164
164
|
*/
|
|
165
165
|
export const queryBorrowIncentiveAccounts = async (
|
|
166
|
-
|
|
166
|
+
{
|
|
167
|
+
utils,
|
|
168
|
+
}: {
|
|
169
|
+
utils: ScallopUtils;
|
|
170
|
+
},
|
|
167
171
|
obligationId: string,
|
|
168
172
|
borrowIncentiveCoinNames?: SupportBorrowIncentiveCoins[]
|
|
169
173
|
) => {
|
|
170
174
|
borrowIncentiveCoinNames = borrowIncentiveCoinNames || [
|
|
171
175
|
...SUPPORT_BORROW_INCENTIVE_POOLS,
|
|
172
176
|
];
|
|
173
|
-
const queryPkgId =
|
|
174
|
-
const incentiveAccountsId =
|
|
177
|
+
const queryPkgId = utils.address.get('borrowIncentive.query');
|
|
178
|
+
const incentiveAccountsId = utils.address.get(
|
|
175
179
|
'borrowIncentive.incentiveAccounts'
|
|
176
180
|
);
|
|
177
181
|
const queryTarget = `${queryPkgId}::incentive_account_query::incentive_account_data`;
|
|
178
182
|
const args = [incentiveAccountsId, obligationId];
|
|
179
183
|
|
|
180
|
-
const queryResult = await
|
|
181
|
-
const borrowIncentiveAccountsQueryData = queryResult?.events[0]
|
|
182
|
-
|
|
183
|
-
| undefined;
|
|
184
|
+
const queryResult = await utils.cache.queryInspectTxn({ queryTarget, args });
|
|
185
|
+
const borrowIncentiveAccountsQueryData = queryResult?.events[0]
|
|
186
|
+
.parsedJson as BorrowIncentiveAccountsQueryInterface;
|
|
184
187
|
|
|
185
188
|
const borrowIncentiveAccounts: BorrowIncentiveAccounts = Object.values(
|
|
186
189
|
borrowIncentiveAccountsQueryData?.pool_records ?? []
|
|
@@ -189,7 +192,7 @@ export const queryBorrowIncentiveAccounts = async (
|
|
|
189
192
|
parseOriginBorrowIncentiveAccountData(accountData);
|
|
190
193
|
const poolType = parsedBorrowIncentiveAccount.poolType;
|
|
191
194
|
const coinName =
|
|
192
|
-
|
|
195
|
+
utils.parseCoinNameFromType<SupportBorrowIncentiveCoins>(poolType);
|
|
193
196
|
|
|
194
197
|
if (
|
|
195
198
|
borrowIncentiveCoinNames &&
|
|
@@ -211,15 +214,19 @@ export const queryBorrowIncentiveAccounts = async (
|
|
|
211
214
|
* @returns
|
|
212
215
|
*/
|
|
213
216
|
export const getBindedObligationId = async (
|
|
214
|
-
|
|
217
|
+
{
|
|
218
|
+
address,
|
|
219
|
+
}: {
|
|
220
|
+
address: ScallopAddress;
|
|
221
|
+
},
|
|
215
222
|
veScaKeyId: string
|
|
216
223
|
): Promise<string | null> => {
|
|
217
|
-
const borrowIncentiveObjectId =
|
|
218
|
-
const incentivePoolsId =
|
|
219
|
-
const veScaObjId =
|
|
224
|
+
const borrowIncentiveObjectId = address.get('borrowIncentive.object');
|
|
225
|
+
const incentivePoolsId = address.get('borrowIncentive.incentivePools');
|
|
226
|
+
const veScaObjId = address.get('vesca.object');
|
|
220
227
|
|
|
221
228
|
// get incentive pools
|
|
222
|
-
const incentivePoolsResponse = await
|
|
229
|
+
const incentivePoolsResponse = await address.cache.queryGetObject(
|
|
223
230
|
incentivePoolsId,
|
|
224
231
|
{
|
|
225
232
|
showContent: true,
|
|
@@ -234,13 +241,15 @@ export const getBindedObligationId = async (
|
|
|
234
241
|
|
|
235
242
|
// check if veSca is inside the bind table
|
|
236
243
|
const keyType = `${borrowIncentiveObjectId}::typed_id::TypedID<${veScaObjId}::ve_sca::VeScaKey>`;
|
|
237
|
-
const veScaBindTableResponse = await
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
+
const veScaBindTableResponse = await address.cache.queryGetDynamicFieldObject(
|
|
245
|
+
{
|
|
246
|
+
parentId: veScaBindTableId,
|
|
247
|
+
name: {
|
|
248
|
+
type: keyType,
|
|
249
|
+
value: veScaKeyId,
|
|
250
|
+
},
|
|
251
|
+
}
|
|
252
|
+
);
|
|
244
253
|
|
|
245
254
|
if (veScaBindTableResponse?.data?.content?.dataType !== 'moveObject')
|
|
246
255
|
return null;
|
|
@@ -253,17 +262,19 @@ export const getBindedObligationId = async (
|
|
|
253
262
|
};
|
|
254
263
|
|
|
255
264
|
export const getBindedVeScaKey = async (
|
|
256
|
-
|
|
265
|
+
{
|
|
266
|
+
address,
|
|
267
|
+
}: {
|
|
268
|
+
address: ScallopAddress;
|
|
269
|
+
},
|
|
257
270
|
obliationId: string
|
|
258
271
|
): Promise<string | null> => {
|
|
259
|
-
const borrowIncentiveObjectId =
|
|
260
|
-
const incentiveAccountsId =
|
|
261
|
-
|
|
262
|
-
);
|
|
263
|
-
const corePkg = query.address.get('core.object');
|
|
272
|
+
const borrowIncentiveObjectId = address.get('borrowIncentive.object');
|
|
273
|
+
const incentiveAccountsId = address.get('borrowIncentive.incentiveAccounts');
|
|
274
|
+
const corePkg = address.get('core.object');
|
|
264
275
|
|
|
265
276
|
// get IncentiveAccounts object
|
|
266
|
-
const incentiveAccountsObject = await
|
|
277
|
+
const incentiveAccountsObject = await address.cache.queryGetObject(
|
|
267
278
|
incentiveAccountsId,
|
|
268
279
|
{
|
|
269
280
|
showContent: true,
|
|
@@ -276,7 +287,7 @@ export const getBindedVeScaKey = async (
|
|
|
276
287
|
).accounts.fields.id.id;
|
|
277
288
|
|
|
278
289
|
// Search in the table
|
|
279
|
-
const bindedIncentiveAcc = await
|
|
290
|
+
const bindedIncentiveAcc = await address.cache.queryGetDynamicFieldObject({
|
|
280
291
|
parentId: incentiveAccountsTableId,
|
|
281
292
|
name: {
|
|
282
293
|
type: `${borrowIncentiveObjectId}::typed_id::TypedID<${corePkg}::obligation::Obligation>`,
|