@scallop-io/sui-scallop-sdk 2.0.13-merge-split-ve-sca-alpha.4 → 2.1.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +622 -697
- package/dist/index.d.ts +622 -697
- package/dist/index.js +32 -33
- package/dist/index.mjs +10 -10
- package/package.json +8 -18
- package/src/builders/borrowIncentiveBuilder.ts +8 -18
- package/src/builders/coreBuilder.ts +2 -2
- package/src/builders/index.ts +2 -2
- package/src/builders/oracles/index.ts +2 -3
- package/src/builders/oracles/pyth.ts +2 -2
- package/src/builders/spoolBuilder.ts +2 -2
- package/src/builders/vescaBuilder.ts +14 -132
- package/src/constants/queryKeys.ts +29 -54
- package/src/constants/testAddress.ts +6 -12
- package/src/index.ts +11 -1
- package/src/models/index.ts +11 -9
- package/src/models/interface.ts +36 -0
- package/src/models/scallop.ts +38 -133
- package/src/models/scallopAddress.ts +127 -142
- package/src/models/scallopAxios.ts +185 -0
- package/src/models/scallopBuilder.ts +45 -75
- package/src/models/scallopClient.ts +124 -154
- package/src/models/scallopConstants.ts +248 -323
- package/src/models/scallopIndexer.ts +54 -98
- package/src/models/scallopQuery.ts +145 -190
- package/src/models/scallopQueryClient.ts +29 -0
- package/src/models/scallopSuiKit.ts +432 -0
- package/src/models/scallopUtils.ts +260 -164
- package/src/queries/borrowIncentiveQuery.ts +28 -16
- package/src/queries/borrowLimitQuery.ts +1 -1
- package/src/queries/coreQuery.ts +148 -107
- package/src/queries/flashloanFeeQuery.ts +12 -6
- package/src/queries/index.ts +0 -1
- package/src/queries/isolatedAssetQuery.ts +3 -3
- package/src/queries/loyaltyProgramQuery.ts +10 -8
- package/src/queries/ownerQuery.ts +32 -0
- package/src/queries/portfolioQuery.ts +4 -5
- package/src/queries/priceQuery.ts +14 -8
- package/src/queries/referralQuery.ts +9 -3
- package/src/queries/sCoinQuery.ts +4 -4
- package/src/queries/spoolQuery.ts +11 -11
- package/src/queries/supplyLimitQuery.ts +1 -1
- package/src/queries/switchboardQuery.ts +1 -1
- package/src/queries/vescaQuery.ts +31 -27
- package/src/queries/xOracleQuery.ts +13 -8
- package/src/types/address.ts +0 -3
- package/src/types/builder/core.ts +1 -1
- package/src/types/builder/vesca.ts +10 -20
- package/src/types/constant/queryKeys.ts +48 -0
- package/src/types/index.ts +0 -1
- package/src/utils/builder.ts +1 -1
- package/src/utils/util.ts +1 -33
- package/src/models/scallopCache.ts +0 -428
- package/src/queries/objectsQuery.ts +0 -18
- package/src/types/model.ts +0 -117
|
@@ -36,7 +36,7 @@ export const getLoyaltyProgramInformations = async (
|
|
|
36
36
|
const rewardPool = query.address.get('loyaltyProgram.rewardPool');
|
|
37
37
|
|
|
38
38
|
// get fields from rewardPool object
|
|
39
|
-
const rewardPoolObject = await query.
|
|
39
|
+
const rewardPoolObject = await query.scallopSuiKit.queryGetObject(rewardPool);
|
|
40
40
|
|
|
41
41
|
if (rewardPoolObject?.data?.content?.dataType !== 'moveObject') return null;
|
|
42
42
|
const rewardPoolFields = rewardPoolObject.data.content.fields;
|
|
@@ -58,13 +58,15 @@ export const getLoyaltyProgramInformations = async (
|
|
|
58
58
|
'loyaltyProgram.userRewardTableId'
|
|
59
59
|
);
|
|
60
60
|
|
|
61
|
-
const userRewardObject = await query.
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
61
|
+
const userRewardObject = await query.scallopSuiKit.queryGetDynamicFieldObject(
|
|
62
|
+
{
|
|
63
|
+
parentId: userRewardTableId,
|
|
64
|
+
name: {
|
|
65
|
+
type: '0x2::object::ID',
|
|
66
|
+
value: typeof veScaKey === 'string' ? veScaKey : veScaKey.objectId,
|
|
67
|
+
},
|
|
68
|
+
}
|
|
69
|
+
);
|
|
68
70
|
|
|
69
71
|
if (userRewardObject?.data?.content?.dataType !== 'moveObject') return result;
|
|
70
72
|
const userRewardFields = userRewardObject.data.content.fields;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// import { ObjectOwner, SuiObjectData } from '@mysten/sui/client';
|
|
2
|
+
|
|
3
|
+
// const parseOwnerAddress = (owner: ObjectOwner | null | undefined): string => {
|
|
4
|
+
// const notSupportedOwner =
|
|
5
|
+
// !owner ||
|
|
6
|
+
// typeof owner === 'string' ||
|
|
7
|
+
// (typeof owner === 'object' &&
|
|
8
|
+
// ('Shared' in owner || 'ConsensusV2' in owner));
|
|
9
|
+
// if (notSupportedOwner)
|
|
10
|
+
// throw new Error('Owner not supported (ConsensusV2 or Shared or Immutable)');
|
|
11
|
+
|
|
12
|
+
// if ('AddressOwner' in owner) {
|
|
13
|
+
// return owner.AddressOwner;
|
|
14
|
+
// } else {
|
|
15
|
+
// return owner.ObjectOwner;
|
|
16
|
+
// }
|
|
17
|
+
// };
|
|
18
|
+
|
|
19
|
+
// export const getObjectOwner = async (
|
|
20
|
+
// cache: ScallopCache,
|
|
21
|
+
// object: string | SuiObjectData
|
|
22
|
+
// ) => {
|
|
23
|
+
// if (typeof object === 'object') {
|
|
24
|
+
// return parseOwnerAddress(object.owner);
|
|
25
|
+
// }
|
|
26
|
+
|
|
27
|
+
// const objResponse = await cache.queryGetObject(object, {
|
|
28
|
+
// showOwner: true,
|
|
29
|
+
// });
|
|
30
|
+
|
|
31
|
+
// return parseOwnerAddress(objResponse.data?.owner);
|
|
32
|
+
// };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import BigNumber from 'bignumber.js';
|
|
2
2
|
import { minBigNumber, estimatedFactor } from 'src/utils';
|
|
3
|
-
import type { ScallopQuery } from '
|
|
3
|
+
import type { ScallopQuery } from '../models';
|
|
4
4
|
import type {
|
|
5
5
|
Market,
|
|
6
6
|
MarketPool,
|
|
@@ -16,9 +16,8 @@ import type {
|
|
|
16
16
|
ObligationBorrowIncentiveReward,
|
|
17
17
|
MarketPools,
|
|
18
18
|
MarketCollaterals,
|
|
19
|
-
} from '
|
|
19
|
+
} from '../types';
|
|
20
20
|
import { SuiObjectRef } from '@mysten/sui/client';
|
|
21
|
-
import { queryMultipleObjects } from './objectsQuery';
|
|
22
21
|
import { normalizeStructTag, SUI_TYPE_ARG } from '@scallop-io/sui-kit';
|
|
23
22
|
|
|
24
23
|
/**
|
|
@@ -67,6 +66,7 @@ export const getLendings = async (
|
|
|
67
66
|
]);
|
|
68
67
|
|
|
69
68
|
const lendings: Lendings = {};
|
|
69
|
+
|
|
70
70
|
await Promise.allSettled(
|
|
71
71
|
poolCoinNames.map(async (poolCoinName) => {
|
|
72
72
|
const stakeMarketCoinName = stakeMarketCoinNames.find(
|
|
@@ -317,8 +317,7 @@ export const getObligationAccounts = async (
|
|
|
317
317
|
query.getObligations(ownerAddress),
|
|
318
318
|
]);
|
|
319
319
|
|
|
320
|
-
const obligationObjects = await
|
|
321
|
-
query.cache,
|
|
320
|
+
const obligationObjects = await query.scallopSuiKit.queryGetObjects(
|
|
322
321
|
obligations.map((obligation) => obligation.id)
|
|
323
322
|
);
|
|
324
323
|
const obligationAccounts: ObligationAccounts = {};
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { SuiObjectData } from '@mysten/sui/client';
|
|
2
|
-
import type { ScallopAddress, ScallopQuery } from '
|
|
2
|
+
import type { ScallopAddress, ScallopQuery, ScallopSuiKit } from 'src/models';
|
|
3
3
|
import type { CoinPrices, MarketPools, OptionalKeys } from '../types';
|
|
4
4
|
import BigNumber from 'bignumber.js';
|
|
5
|
-
import { ScallopConstants } from 'src/models/scallopConstants';
|
|
6
5
|
|
|
7
6
|
/**
|
|
8
7
|
* Get price from pyth fee object.
|
|
@@ -14,8 +13,10 @@ import { ScallopConstants } from 'src/models/scallopConstants';
|
|
|
14
13
|
export const getPythPrice = async (
|
|
15
14
|
{
|
|
16
15
|
address,
|
|
16
|
+
scallopSuiKit,
|
|
17
17
|
}: {
|
|
18
18
|
address: ScallopAddress;
|
|
19
|
+
scallopSuiKit: ScallopSuiKit;
|
|
19
20
|
},
|
|
20
21
|
assetCoinName: string,
|
|
21
22
|
priceFeedObject?: SuiObjectData | null
|
|
@@ -25,7 +26,7 @@ export const getPythPrice = async (
|
|
|
25
26
|
);
|
|
26
27
|
priceFeedObject =
|
|
27
28
|
priceFeedObject ||
|
|
28
|
-
(await
|
|
29
|
+
(await scallopSuiKit.queryGetObject(pythFeedObjectId))?.data;
|
|
29
30
|
|
|
30
31
|
if (priceFeedObject) {
|
|
31
32
|
const priceFeedPoolObject = priceFeedObject;
|
|
@@ -64,15 +65,17 @@ export const getPythPrice = async (
|
|
|
64
65
|
|
|
65
66
|
export const getPythPrices = async (
|
|
66
67
|
{
|
|
67
|
-
|
|
68
|
+
address,
|
|
69
|
+
scallopSuiKit,
|
|
68
70
|
}: {
|
|
69
|
-
|
|
71
|
+
address: ScallopAddress;
|
|
72
|
+
scallopSuiKit: ScallopSuiKit;
|
|
70
73
|
},
|
|
71
74
|
assetCoinNames: string[]
|
|
72
75
|
) => {
|
|
73
76
|
const pythPriceFeedIds = assetCoinNames.reduce(
|
|
74
77
|
(prev, assetCoinName) => {
|
|
75
|
-
const pythPriceFeed =
|
|
78
|
+
const pythPriceFeed = address.get(
|
|
76
79
|
`core.coins.${assetCoinName}.oracle.pyth.feedObject`
|
|
77
80
|
);
|
|
78
81
|
if (pythPriceFeed) {
|
|
@@ -88,7 +91,7 @@ export const getPythPrices = async (
|
|
|
88
91
|
);
|
|
89
92
|
|
|
90
93
|
// Fetch multiple objects at once to save rpc calls
|
|
91
|
-
const priceFeedObjects = await
|
|
94
|
+
const priceFeedObjects = await scallopSuiKit.queryGetObjects(
|
|
92
95
|
Object.keys(pythPriceFeedIds)
|
|
93
96
|
);
|
|
94
97
|
|
|
@@ -108,7 +111,10 @@ export const getPythPrices = async (
|
|
|
108
111
|
async ([assetCoinName, priceFeedObject]) => ({
|
|
109
112
|
coinName: assetCoinName,
|
|
110
113
|
price: await getPythPrice(
|
|
111
|
-
|
|
114
|
+
{
|
|
115
|
+
address,
|
|
116
|
+
scallopSuiKit,
|
|
117
|
+
},
|
|
112
118
|
assetCoinName as string,
|
|
113
119
|
priceFeedObject
|
|
114
120
|
),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ScallopAddress } from 'src/models';
|
|
1
|
+
import type { ScallopAddress, ScallopSuiKit } from 'src/models';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Query the veScaKeyId from the referral bindings table using the borrower address
|
|
@@ -6,11 +6,17 @@ import { ScallopAddress } from 'src/models';
|
|
|
6
6
|
* @returns
|
|
7
7
|
*/
|
|
8
8
|
export const queryVeScaKeyIdFromReferralBindings = async (
|
|
9
|
-
|
|
9
|
+
{
|
|
10
|
+
address,
|
|
11
|
+
scallopSuiKit,
|
|
12
|
+
}: {
|
|
13
|
+
address: ScallopAddress;
|
|
14
|
+
scallopSuiKit: ScallopSuiKit;
|
|
15
|
+
},
|
|
10
16
|
refereeAddress: string
|
|
11
17
|
): Promise<string | null> => {
|
|
12
18
|
const referralBindingTableId = address.get('referral.bindingTableId');
|
|
13
|
-
const referralBindResponse = await
|
|
19
|
+
const referralBindResponse = await scallopSuiKit.queryGetDynamicFieldObject({
|
|
14
20
|
parentId: referralBindingTableId,
|
|
15
21
|
name: {
|
|
16
22
|
type: 'address',
|
|
@@ -26,7 +26,7 @@ export const getSCoinTotalSupply = async (
|
|
|
26
26
|
utils.parseUnderlyingSCoinType(sCoinName),
|
|
27
27
|
];
|
|
28
28
|
const queryTarget = `${sCoinPkgId}::s_coin_converter::total_supply`;
|
|
29
|
-
const queryResults = await utils.
|
|
29
|
+
const queryResults = await utils.scallopSuiKit.queryInspectTxn({
|
|
30
30
|
queryTarget,
|
|
31
31
|
args,
|
|
32
32
|
typeArgs,
|
|
@@ -62,7 +62,7 @@ export const getSCoinAmounts = async (
|
|
|
62
62
|
sCoinNames: string[] = [...utils.constants.whitelist.scoin],
|
|
63
63
|
ownerAddress?: string
|
|
64
64
|
) => {
|
|
65
|
-
const owner = ownerAddress || utils.suiKit.currentAddress
|
|
65
|
+
const owner = ownerAddress || utils.suiKit.currentAddress;
|
|
66
66
|
const sCoins = {} as OptionalKeys<Record<string, number>>;
|
|
67
67
|
|
|
68
68
|
await Promise.allSettled(
|
|
@@ -92,9 +92,9 @@ export const getSCoinAmount = async (
|
|
|
92
92
|
sCoinName: string,
|
|
93
93
|
ownerAddress?: string
|
|
94
94
|
) => {
|
|
95
|
-
const owner = ownerAddress || utils.suiKit.currentAddress
|
|
95
|
+
const owner = ownerAddress || utils.suiKit.currentAddress;
|
|
96
96
|
const sCoinType = utils.parseSCoinType(sCoinName);
|
|
97
|
-
const coinBalance = await utils.
|
|
97
|
+
const coinBalance = await utils.scallopSuiKit.queryGetCoinBalance({
|
|
98
98
|
owner,
|
|
99
99
|
coinType: sCoinType,
|
|
100
100
|
});
|
|
@@ -5,9 +5,9 @@ import {
|
|
|
5
5
|
parseOriginSpoolRewardPoolData,
|
|
6
6
|
calculateSpoolRewardPoolData,
|
|
7
7
|
parseObjectAs,
|
|
8
|
-
} from '
|
|
8
|
+
} from '../utils';
|
|
9
9
|
import type { SuiObjectData, SuiObjectResponse } from '@mysten/sui/client';
|
|
10
|
-
import type { ScallopQuery, ScallopUtils } from '
|
|
10
|
+
import type { ScallopQuery, ScallopUtils } from '../models';
|
|
11
11
|
import type {
|
|
12
12
|
Spools,
|
|
13
13
|
Spool,
|
|
@@ -19,8 +19,7 @@ import type {
|
|
|
19
19
|
OriginSpoolRewardPoolData,
|
|
20
20
|
SpoolData,
|
|
21
21
|
OriginSpoolData,
|
|
22
|
-
} from '
|
|
23
|
-
import { queryMultipleObjects } from './objectsQuery';
|
|
22
|
+
} from '../types';
|
|
24
23
|
|
|
25
24
|
const queryRequiredSpoolObjects = async (
|
|
26
25
|
query: ScallopQuery,
|
|
@@ -63,9 +62,9 @@ const queryRequiredSpoolObjects = async (
|
|
|
63
62
|
// Phase 2: Parallel queries with pre-collected keys
|
|
64
63
|
const [spoolObjects, spoolRewardObjects, sCoinTreasuryObjects] =
|
|
65
64
|
await Promise.all([
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
65
|
+
query.scallopSuiKit.queryGetObjects(keyCollections.spool),
|
|
66
|
+
query.scallopSuiKit.queryGetObjects(keyCollections.spoolReward),
|
|
67
|
+
query.scallopSuiKit.queryGetObjects(keyCollections.sCoinTreasury),
|
|
69
68
|
]);
|
|
70
69
|
|
|
71
70
|
// Phase 3: Create lookup maps
|
|
@@ -315,7 +314,7 @@ export const getStakeAccounts = async (
|
|
|
315
314
|
},
|
|
316
315
|
ownerAddress?: string
|
|
317
316
|
) => {
|
|
318
|
-
const owner = ownerAddress || utils.suiKit.currentAddress
|
|
317
|
+
const owner = ownerAddress || utils.suiKit.currentAddress;
|
|
319
318
|
const spoolObjectId = utils.address.get('spool.object');
|
|
320
319
|
const stakeAccountType = `${spoolObjectId}::spool_account::SpoolAccount`;
|
|
321
320
|
const stakeObjectsResponse: SuiObjectResponse[] = [];
|
|
@@ -323,7 +322,7 @@ export const getStakeAccounts = async (
|
|
|
323
322
|
let nextCursor: string | null | undefined = null;
|
|
324
323
|
do {
|
|
325
324
|
const paginatedStakeObjectsResponse =
|
|
326
|
-
await utils.
|
|
325
|
+
await utils.scallopSuiKit.queryGetOwnedObjects({
|
|
327
326
|
owner,
|
|
328
327
|
filter: { StructType: stakeAccountType },
|
|
329
328
|
options: {
|
|
@@ -445,7 +444,8 @@ export const getStakePool = async (
|
|
|
445
444
|
) => {
|
|
446
445
|
const poolId = utils.address.get(`spool.pools.${marketCoinName}.id`);
|
|
447
446
|
let stakePool: StakePool | undefined = undefined;
|
|
448
|
-
const stakePoolObjectResponse =
|
|
447
|
+
const stakePoolObjectResponse =
|
|
448
|
+
await utils.scallopSuiKit.queryGetObject(poolId);
|
|
449
449
|
if (stakePoolObjectResponse?.data) {
|
|
450
450
|
const stakePoolObject = stakePoolObjectResponse.data;
|
|
451
451
|
const id = stakePoolObject.objectId;
|
|
@@ -505,7 +505,7 @@ export const getStakeRewardPool = async (
|
|
|
505
505
|
);
|
|
506
506
|
let stakeRewardPool: StakeRewardPool | undefined = undefined;
|
|
507
507
|
const stakeRewardPoolObjectResponse =
|
|
508
|
-
await utils.
|
|
508
|
+
await utils.scallopSuiKit.queryGetObject(poolId);
|
|
509
509
|
|
|
510
510
|
if (stakeRewardPoolObjectResponse?.data) {
|
|
511
511
|
const stakeRewardPoolObject = stakeRewardPoolObjectResponse.data;
|
|
@@ -30,7 +30,7 @@ export const getSupplyLimit = async (utils: ScallopUtils, poolName: string) => {
|
|
|
30
30
|
const marketObject = utils.address.get('core.market');
|
|
31
31
|
if (!marketObject) return null;
|
|
32
32
|
|
|
33
|
-
const object = await utils.
|
|
33
|
+
const object = await utils.scallopSuiKit.queryGetDynamicFieldObject({
|
|
34
34
|
parentId: marketObject,
|
|
35
35
|
name: {
|
|
36
36
|
type: supplyLimitKeyType,
|
|
@@ -47,7 +47,7 @@ export const getOnDemandAggObjectIds = async (
|
|
|
47
47
|
},
|
|
48
48
|
};
|
|
49
49
|
|
|
50
|
-
const resp = await query.
|
|
50
|
+
const resp = await query.scallopSuiKit.queryGetDynamicFieldObject({
|
|
51
51
|
parentId: switchboardRegistryTableId,
|
|
52
52
|
name: dfName,
|
|
53
53
|
});
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import BigNumber from 'bignumber.js';
|
|
2
|
-
import { VeScaTreasuryFields, VeScaTreasuryInfo, Vesca } from '
|
|
2
|
+
import { VeScaTreasuryFields, VeScaTreasuryInfo, Vesca } from '../types';
|
|
3
3
|
import {
|
|
4
4
|
type SuiObjectResponse,
|
|
5
5
|
type SuiObjectData,
|
|
6
6
|
DevInspectResults,
|
|
7
7
|
} from '@mysten/sui/client';
|
|
8
|
-
import type { ScallopUtils } from '
|
|
8
|
+
import type { ScallopUtils } from '../models';
|
|
9
9
|
import { MAX_LOCK_DURATION } from 'src/constants';
|
|
10
10
|
import { SUI_CLOCK_OBJECT_ID, SuiTxBlock } from '@scallop-io/sui-kit';
|
|
11
11
|
import { bcs } from '@mysten/sui/bcs';
|
|
@@ -23,21 +23,22 @@ export const getVescaKeys = async (
|
|
|
23
23
|
utils: ScallopUtils,
|
|
24
24
|
ownerAddress?: string
|
|
25
25
|
) => {
|
|
26
|
-
const owner = ownerAddress || utils.suiKit.currentAddress
|
|
26
|
+
const owner = ownerAddress || utils.suiKit.currentAddress;
|
|
27
27
|
const veScaObjId = utils.address.get('vesca.object');
|
|
28
28
|
const veScaKeyType = `${veScaObjId}::ve_sca::VeScaKey`;
|
|
29
29
|
const keyObjectsResponse: SuiObjectResponse[] = [];
|
|
30
30
|
let hasNextPage = false;
|
|
31
31
|
let nextCursor: string | null | undefined = null;
|
|
32
32
|
do {
|
|
33
|
-
const paginatedKeyObjectsResponse =
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
33
|
+
const paginatedKeyObjectsResponse =
|
|
34
|
+
await utils.scallopSuiKit.queryGetOwnedObjects({
|
|
35
|
+
owner,
|
|
36
|
+
filter: {
|
|
37
|
+
StructType: veScaKeyType,
|
|
38
|
+
},
|
|
39
|
+
cursor: nextCursor,
|
|
40
|
+
limit: 10,
|
|
41
|
+
});
|
|
41
42
|
if (!paginatedKeyObjectsResponse) continue;
|
|
42
43
|
|
|
43
44
|
keyObjectsResponse.push(...paginatedKeyObjectsResponse.data);
|
|
@@ -125,7 +126,7 @@ export const getVeSca = async (
|
|
|
125
126
|
let vesca: Vesca | undefined = undefined;
|
|
126
127
|
|
|
127
128
|
const veScaDynamicFieldObjectResponse =
|
|
128
|
-
await utils.
|
|
129
|
+
await utils.scallopSuiKit.queryGetDynamicFieldObject({
|
|
129
130
|
parentId: tableId,
|
|
130
131
|
name: {
|
|
131
132
|
type: '0x2::object::ID',
|
|
@@ -196,22 +197,22 @@ const getTotalVeScaTreasuryAmount = async (
|
|
|
196
197
|
|
|
197
198
|
// query total veSca amount
|
|
198
199
|
const veScaAmountQueryTarget = `${veScaPkgId}::treasury::total_ve_sca_amount`;
|
|
199
|
-
const
|
|
200
|
+
const vescaAmountArgs = [veScaTreasury, clockObjectRef];
|
|
200
201
|
|
|
201
202
|
// resolve each args
|
|
202
203
|
const resolvedRefreshArgs = await Promise.all(
|
|
203
204
|
refreshArgs.map(async (arg) => {
|
|
204
205
|
if (typeof arg === 'string') {
|
|
205
|
-
return (await utils.
|
|
206
|
+
return (await utils.scallopSuiKit.queryGetObject(arg))?.data;
|
|
206
207
|
}
|
|
207
208
|
return arg;
|
|
208
209
|
})
|
|
209
210
|
);
|
|
210
211
|
|
|
211
212
|
const resolvedVeScaAmountArgs = await Promise.all(
|
|
212
|
-
|
|
213
|
+
vescaAmountArgs.map(async (arg) => {
|
|
213
214
|
if (typeof arg === 'string') {
|
|
214
|
-
return (await utils.
|
|
215
|
+
return (await utils.scallopSuiKit.queryGetObject(arg))?.data;
|
|
215
216
|
}
|
|
216
217
|
return arg;
|
|
217
218
|
})
|
|
@@ -222,20 +223,22 @@ const getTotalVeScaTreasuryAmount = async (
|
|
|
222
223
|
txb.moveCall(veScaAmountQueryTarget, resolvedVeScaAmountArgs);
|
|
223
224
|
|
|
224
225
|
const txBytes = await txb.txBlock.build({
|
|
225
|
-
client: utils.suiKit.client
|
|
226
|
+
client: utils.suiKit.client,
|
|
226
227
|
onlyTransactionKind: true,
|
|
227
228
|
});
|
|
228
229
|
|
|
229
230
|
// return result
|
|
230
|
-
const res =
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
231
|
+
const res =
|
|
232
|
+
await utils.scallopSuiKit.queryClient.fetchQuery<DevInspectResults>({
|
|
233
|
+
queryKey: queryKeys.rpc.getTotalVeScaTreasuryAmount({
|
|
234
|
+
refreshArgs,
|
|
235
|
+
vescaAmountArgs,
|
|
236
|
+
node: utils.scallopSuiKit.currentFullNode,
|
|
237
|
+
}),
|
|
238
|
+
queryFn: async () => {
|
|
239
|
+
return await utils.suiKit.inspectTxn(txBytes);
|
|
240
|
+
},
|
|
241
|
+
});
|
|
239
242
|
|
|
240
243
|
const results = res.results;
|
|
241
244
|
if (results && results[1]?.returnValues) {
|
|
@@ -257,7 +260,8 @@ export const getVeScaTreasuryInfo = async (
|
|
|
257
260
|
utils: ScallopUtils
|
|
258
261
|
): Promise<VeScaTreasuryInfo | null> => {
|
|
259
262
|
const veScaTreasuryId = utils.address.get('vesca.treasury');
|
|
260
|
-
const veScaTreasury =
|
|
263
|
+
const veScaTreasury =
|
|
264
|
+
await utils.scallopSuiKit.queryGetObject(veScaTreasuryId);
|
|
261
265
|
|
|
262
266
|
if (!veScaTreasury || veScaTreasury.data?.content?.dataType !== 'moveObject')
|
|
263
267
|
return null;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SuiObjectResponse } from '@mysten/sui/client';
|
|
2
|
-
import { ScallopAddress, ScallopUtils } from 'src/models';
|
|
2
|
+
import { ScallopAddress, ScallopSuiKit, ScallopUtils } from 'src/models';
|
|
3
3
|
import { SupportOracleType, xOracleRuleType } from 'src/types';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -7,23 +7,27 @@ import { SupportOracleType, xOracleRuleType } from 'src/types';
|
|
|
7
7
|
* @param query
|
|
8
8
|
* @returns Primary and Secondary price update policy table object
|
|
9
9
|
*/
|
|
10
|
-
export const getPriceUpdatePolicies = async (
|
|
11
|
-
address
|
|
12
|
-
|
|
10
|
+
export const getPriceUpdatePolicies = async ({
|
|
11
|
+
address,
|
|
12
|
+
scallopSuiKit,
|
|
13
|
+
}: {
|
|
14
|
+
address: ScallopAddress;
|
|
15
|
+
scallopSuiKit: ScallopSuiKit;
|
|
16
|
+
}): Promise<{
|
|
13
17
|
primary: SuiObjectResponse | null;
|
|
14
18
|
secondary: SuiObjectResponse | null;
|
|
15
19
|
}> => {
|
|
16
20
|
const priceUpdatePolicyRulesKeyType = `${address.get('core.packages.xOracle.object')}::price_update_policy::PriceUpdatePolicyRulesKey`;
|
|
17
21
|
const [primaryPriceUpdatePolicyTable, secondaryPriceUpdatePolicyTable] =
|
|
18
22
|
await Promise.all([
|
|
19
|
-
|
|
23
|
+
scallopSuiKit.queryGetDynamicFieldObject({
|
|
20
24
|
parentId: address.get('core.oracles.primaryPriceUpdatePolicyObject'),
|
|
21
25
|
name: {
|
|
22
26
|
type: priceUpdatePolicyRulesKeyType,
|
|
23
27
|
value: { dummy_field: false },
|
|
24
28
|
},
|
|
25
29
|
}),
|
|
26
|
-
|
|
30
|
+
scallopSuiKit.queryGetDynamicFieldObject({
|
|
27
31
|
parentId: address.get('core.oracles.secondaryPriceUpdatePolicyObject'),
|
|
28
32
|
name: {
|
|
29
33
|
type: priceUpdatePolicyRulesKeyType,
|
|
@@ -67,7 +71,7 @@ export const getAssetOracles = async (
|
|
|
67
71
|
const assetOracles = {} as Record<string, SupportOracleType[]>;
|
|
68
72
|
let cursor = null;
|
|
69
73
|
do {
|
|
70
|
-
const response = await utils.
|
|
74
|
+
const response = await utils.scallopSuiKit.queryGetDynamicFields({
|
|
71
75
|
parentId:
|
|
72
76
|
ruleType === 'primary'
|
|
73
77
|
? utils.address.get('core.oracles.primaryPriceUpdatePolicyVecsetId')
|
|
@@ -85,7 +89,8 @@ export const getAssetOracles = async (
|
|
|
85
89
|
const objectIds = data.map((dynamicField) => dynamicField.objectId);
|
|
86
90
|
|
|
87
91
|
// batch fetch object responses
|
|
88
|
-
const objectResponses =
|
|
92
|
+
const objectResponses =
|
|
93
|
+
await utils.scallopSuiKit.queryGetObjects(objectIds);
|
|
89
94
|
objectResponses.forEach((object) => {
|
|
90
95
|
if (!object.content || object.content.dataType !== 'moveObject') return;
|
|
91
96
|
const fields = object.content.fields as any;
|
package/src/types/address.ts
CHANGED
|
@@ -4,8 +4,8 @@ import type {
|
|
|
4
4
|
SuiTxArg,
|
|
5
5
|
} from '@scallop-io/sui-kit';
|
|
6
6
|
import type { Argument, TransactionResult } from '@mysten/sui/transactions';
|
|
7
|
-
import type { ScallopBuilder } from '../../models';
|
|
8
7
|
import { SuiTxBlockWithSpool } from '.';
|
|
8
|
+
import { ScallopBuilder } from 'src/models';
|
|
9
9
|
|
|
10
10
|
export type CoreIds = {
|
|
11
11
|
protocolPkg: string;
|
|
@@ -2,6 +2,13 @@ import { SuiTxBlock as SuiKitTxBlock, SuiObjectArg } from '@scallop-io/sui-kit';
|
|
|
2
2
|
import type { TransactionResult } from '@mysten/sui/transactions';
|
|
3
3
|
import { ScallopBuilder } from 'src/models';
|
|
4
4
|
|
|
5
|
+
export type VescaIds = {
|
|
6
|
+
pkgId: string;
|
|
7
|
+
table: string;
|
|
8
|
+
treasury: string;
|
|
9
|
+
config: string;
|
|
10
|
+
};
|
|
11
|
+
|
|
5
12
|
export type VeScaNormalMethods = {
|
|
6
13
|
lockSca: (
|
|
7
14
|
scaCoin: SuiObjectArg,
|
|
@@ -19,17 +26,9 @@ export type VeScaNormalMethods = {
|
|
|
19
26
|
) => void;
|
|
20
27
|
redeemSca: (veScaKey: SuiObjectArg) => TransactionResult;
|
|
21
28
|
mintEmptyVeSca: () => TransactionResult;
|
|
22
|
-
splitVeSca: (
|
|
23
|
-
veScaKey: SuiObjectArg,
|
|
24
|
-
splitAmount: string
|
|
25
|
-
) => TransactionResult;
|
|
26
|
-
mergeVeSca: (
|
|
27
|
-
targetVeScaKey: SuiObjectArg,
|
|
28
|
-
sourceVeScaKey: SuiObjectArg
|
|
29
|
-
) => void;
|
|
30
29
|
};
|
|
31
30
|
|
|
32
|
-
export type
|
|
31
|
+
export type RedeemScaQuickReturnType<T extends boolean> = T extends true
|
|
33
32
|
? void
|
|
34
33
|
: TransactionResult | undefined;
|
|
35
34
|
|
|
@@ -72,18 +71,9 @@ export type VeScaQuickMethods = {
|
|
|
72
71
|
autoCheck?: boolean
|
|
73
72
|
) => Promise<void>;
|
|
74
73
|
redeemScaQuick: <T extends boolean>(
|
|
75
|
-
|
|
74
|
+
veSCaKey?: SuiObjectArg,
|
|
76
75
|
transferSca?: T
|
|
77
|
-
) => Promise<
|
|
78
|
-
splitVeScaQuick: <T extends boolean>(
|
|
79
|
-
splitAmount: string,
|
|
80
|
-
veScaKey: string,
|
|
81
|
-
transferVeScaKey?: T
|
|
82
|
-
) => Promise<QuickMethodReturnType<T>>;
|
|
83
|
-
mergeVeScaQuick: (
|
|
84
|
-
targetVeScaKey: string,
|
|
85
|
-
sourceVeScaKey: string
|
|
86
|
-
) => Promise<void>;
|
|
76
|
+
) => Promise<RedeemScaQuickReturnType<T>>;
|
|
87
77
|
};
|
|
88
78
|
|
|
89
79
|
export type SuiTxBlockWithVeScaNormalMethods = SuiKitTxBlock &
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
GetDynamicFieldObjectParams,
|
|
3
|
+
GetDynamicFieldsParams,
|
|
4
|
+
GetOwnedObjectsParams,
|
|
5
|
+
SuiObjectData,
|
|
6
|
+
SuiObjectDataOptions,
|
|
7
|
+
} from '@mysten/sui/dist/cjs/client';
|
|
8
|
+
import type { SuiObjectArg, SuiTxArg } from '@scallop-io/sui-kit';
|
|
9
|
+
|
|
10
|
+
export namespace QueryKeys {
|
|
11
|
+
export namespace API {
|
|
12
|
+
export type GetAddresses = {
|
|
13
|
+
addressId?: string;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export namespace RPC {
|
|
17
|
+
type BaseType = {
|
|
18
|
+
node?: string;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export type GetInspectTxn = BaseType & {
|
|
22
|
+
queryTarget?: string;
|
|
23
|
+
args?: SuiObjectArg[];
|
|
24
|
+
typeArgs?: any[];
|
|
25
|
+
};
|
|
26
|
+
export type GetObject = BaseType & {
|
|
27
|
+
objectId?: string;
|
|
28
|
+
options?: SuiObjectDataOptions;
|
|
29
|
+
};
|
|
30
|
+
export type GetObjects = BaseType & {
|
|
31
|
+
objectIds?: string[];
|
|
32
|
+
};
|
|
33
|
+
export type GetOwnedObjects = BaseType & Partial<GetOwnedObjectsParams>;
|
|
34
|
+
export type GetDynamicFields = BaseType & Partial<GetDynamicFieldsParams>;
|
|
35
|
+
export type GetDynamicFieldObject = BaseType &
|
|
36
|
+
Partial<GetDynamicFieldObjectParams>;
|
|
37
|
+
export type getTotalVeScaTreasuryAmount = BaseType & {
|
|
38
|
+
refreshArgs?: any[];
|
|
39
|
+
vescaAmountArgs?: (string | SuiObjectData | SuiTxArg)[];
|
|
40
|
+
};
|
|
41
|
+
export type GetAllCoinBalances = BaseType & {
|
|
42
|
+
activeAddress?: string;
|
|
43
|
+
};
|
|
44
|
+
export type GetNormalizedMoveFunction = BaseType & {
|
|
45
|
+
target?: string;
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
}
|
package/src/types/index.ts
CHANGED