@scallop-io/sui-scallop-sdk 2.3.7 → 2.3.8
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 +9 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.js +29 -29
- package/dist/index.mjs +4 -4
- package/package.json +1 -1
- package/src/builders/coreBuilder.ts +68 -0
- package/src/models/scallopSuiKit.ts +2 -2
- package/src/queries/borrowIncentiveQuery.ts +24 -2
- package/src/queries/coreQuery.ts +27 -6
- package/src/queries/sCoinQuery.ts +10 -1
- package/src/types/builder/core.ts +18 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/object.ts +40 -0
package/package.json
CHANGED
|
@@ -267,6 +267,27 @@ const generateCoreNormalMethod: GenerateCoreNormalMethod = ({
|
|
|
267
267
|
[coinType]
|
|
268
268
|
);
|
|
269
269
|
},
|
|
270
|
+
liquidate: (obligation, coin, debtCoinName, collateralCoinName) => {
|
|
271
|
+
const debtCoinType = builder.utils.parseCoinType(debtCoinName);
|
|
272
|
+
const collateralCoinType =
|
|
273
|
+
builder.utils.parseCoinType(collateralCoinName);
|
|
274
|
+
const [debtCoin, collateralCoin] = builder.moveCall(
|
|
275
|
+
txBlock,
|
|
276
|
+
`${coreIds.protocolPkg}::liquidate::liquidate`,
|
|
277
|
+
[
|
|
278
|
+
coreIds.version,
|
|
279
|
+
obligation,
|
|
280
|
+
coreIds.market,
|
|
281
|
+
coin,
|
|
282
|
+
coreIds.coinDecimalsRegistry,
|
|
283
|
+
coreIds.xOracle,
|
|
284
|
+
clockObjectRef,
|
|
285
|
+
],
|
|
286
|
+
[debtCoinType, collateralCoinType]
|
|
287
|
+
);
|
|
288
|
+
|
|
289
|
+
return [debtCoin, collateralCoin] as [NestedResult, NestedResult];
|
|
290
|
+
},
|
|
270
291
|
};
|
|
271
292
|
};
|
|
272
293
|
|
|
@@ -489,6 +510,53 @@ const generateCoreQuickMethod: GenerateCoreQuickMethod = ({
|
|
|
489
510
|
updateOracleOptions
|
|
490
511
|
);
|
|
491
512
|
},
|
|
513
|
+
liquidateQuick: async (
|
|
514
|
+
amount,
|
|
515
|
+
debtCoinName,
|
|
516
|
+
collateralCoinName,
|
|
517
|
+
obligationId,
|
|
518
|
+
updateOracleOptions
|
|
519
|
+
) => {
|
|
520
|
+
const sender = requireSender(txBlock);
|
|
521
|
+
|
|
522
|
+
// Update oracle prices for debt and collateral coins
|
|
523
|
+
const updateCoinNames =
|
|
524
|
+
await builder.utils.getObligationCoinNames(obligationId);
|
|
525
|
+
|
|
526
|
+
await updateOracles(
|
|
527
|
+
builder,
|
|
528
|
+
txBlock,
|
|
529
|
+
updateCoinNames,
|
|
530
|
+
updateOracleOptions
|
|
531
|
+
);
|
|
532
|
+
|
|
533
|
+
// Select coins for liquidation
|
|
534
|
+
const { takeCoin, leftCoin } = await builder.selectCoin(
|
|
535
|
+
txBlock,
|
|
536
|
+
debtCoinName,
|
|
537
|
+
amount,
|
|
538
|
+
sender,
|
|
539
|
+
updateOracleOptions?.isSponsoredTx ?? false
|
|
540
|
+
);
|
|
541
|
+
|
|
542
|
+
if (leftCoin) {
|
|
543
|
+
txBlock.transferObjects([leftCoin], sender);
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
// Convert obligation to SharedObjectRef format
|
|
547
|
+
const obligationSharedObject =
|
|
548
|
+
typeof obligationId === 'string'
|
|
549
|
+
? txBlock.object(obligationId)
|
|
550
|
+
: obligationId;
|
|
551
|
+
|
|
552
|
+
// Execute liquidation
|
|
553
|
+
return txBlock.liquidate(
|
|
554
|
+
obligationSharedObject,
|
|
555
|
+
takeCoin,
|
|
556
|
+
debtCoinName,
|
|
557
|
+
collateralCoinName
|
|
558
|
+
);
|
|
559
|
+
},
|
|
492
560
|
};
|
|
493
561
|
};
|
|
494
562
|
|
|
@@ -32,6 +32,7 @@ type QueryInspectTxnParams = {
|
|
|
32
32
|
queryTarget: string;
|
|
33
33
|
args: SuiObjectArg[];
|
|
34
34
|
typeArgs?: any[];
|
|
35
|
+
txBlock?: SuiTxBlock;
|
|
35
36
|
};
|
|
36
37
|
|
|
37
38
|
export type ScallopSuiKitParams = {
|
|
@@ -352,9 +353,8 @@ class ScallopSuiKit extends ScallopQueryClient {
|
|
|
352
353
|
queryTarget,
|
|
353
354
|
args,
|
|
354
355
|
typeArgs,
|
|
356
|
+
txBlock = new SuiTxBlock(),
|
|
355
357
|
}: QueryInspectTxnParams): Promise<DevInspectResults | null> {
|
|
356
|
-
const txBlock = new SuiTxBlock();
|
|
357
|
-
|
|
358
358
|
const resolvedQueryTarget =
|
|
359
359
|
await this.queryGetNormalizedMoveFunction(queryTarget);
|
|
360
360
|
if (!resolvedQueryTarget) throw new Error('Invalid query target');
|
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
parseOriginBorrowIncentivePoolData,
|
|
4
4
|
parseOriginBorrowIncentiveAccountData,
|
|
5
5
|
calculateBorrowIncentivePoolPointData,
|
|
6
|
+
getSharedObjectData,
|
|
6
7
|
} from 'src/utils';
|
|
7
8
|
import type {
|
|
8
9
|
ScallopAddress,
|
|
@@ -22,6 +23,7 @@ import type {
|
|
|
22
23
|
} from 'src/types';
|
|
23
24
|
import BigNumber from 'bignumber.js';
|
|
24
25
|
import { SuiObjectRef } from '@mysten/sui/client';
|
|
26
|
+
import { SuiTxBlock } from '@scallop-io/sui-kit';
|
|
25
27
|
|
|
26
28
|
/**
|
|
27
29
|
* Query borrow incentive pools data using moveCall
|
|
@@ -38,11 +40,19 @@ export const queryBorrowIncentivePools = async ({
|
|
|
38
40
|
const queryPkgId = address.get('borrowIncentive.query');
|
|
39
41
|
const incentivePoolsId = address.get('borrowIncentive.incentivePools');
|
|
40
42
|
|
|
43
|
+
const txBlock = new SuiTxBlock();
|
|
41
44
|
const queryTarget = `${queryPkgId}::incentive_pools_query::incentive_pools_data`;
|
|
42
|
-
const args = [
|
|
45
|
+
const args = [
|
|
46
|
+
txBlock.sharedObjectRef({
|
|
47
|
+
objectId: incentivePoolsId,
|
|
48
|
+
initialSharedVersion: '81234462',
|
|
49
|
+
mutable: true,
|
|
50
|
+
}),
|
|
51
|
+
];
|
|
43
52
|
const queryResult = await scallopSuiKit.queryInspectTxn({
|
|
44
53
|
queryTarget,
|
|
45
54
|
args,
|
|
55
|
+
txBlock,
|
|
46
56
|
});
|
|
47
57
|
const borrowIncentivePoolsQueryData = queryResult?.events[0].parsedJson as
|
|
48
58
|
| BorrowIncentivePoolsQueryInterface
|
|
@@ -165,16 +175,28 @@ export const queryBorrowIncentiveAccounts = async (
|
|
|
165
175
|
obligationId: string | SuiObjectRef,
|
|
166
176
|
borrowIncentiveCoinNames: string[] = [...utils.constants.whitelist.lending]
|
|
167
177
|
) => {
|
|
178
|
+
const txBlock = new SuiTxBlock();
|
|
168
179
|
const queryPkgId = utils.address.get('borrowIncentive.query');
|
|
169
180
|
const incentiveAccountsId = utils.address.get(
|
|
170
181
|
'borrowIncentive.incentiveAccounts'
|
|
171
182
|
);
|
|
172
183
|
const queryTarget = `${queryPkgId}::incentive_account_query::incentive_account_data`;
|
|
173
|
-
const args = [
|
|
184
|
+
const args = [
|
|
185
|
+
txBlock.sharedObjectRef({
|
|
186
|
+
objectId: incentiveAccountsId,
|
|
187
|
+
initialSharedVersion: '81234462',
|
|
188
|
+
mutable: true,
|
|
189
|
+
}),
|
|
190
|
+
txBlock.sharedObjectRef({
|
|
191
|
+
...(await getSharedObjectData(obligationId)),
|
|
192
|
+
mutable: true,
|
|
193
|
+
}),
|
|
194
|
+
];
|
|
174
195
|
|
|
175
196
|
const queryResult = await utils.scallopSuiKit.queryInspectTxn({
|
|
176
197
|
queryTarget,
|
|
177
198
|
args,
|
|
199
|
+
txBlock,
|
|
178
200
|
});
|
|
179
201
|
const borrowIncentiveAccountsQueryData = queryResult?.events[0]
|
|
180
202
|
?.parsedJson as BorrowIncentiveAccountsQueryInterface | undefined;
|
package/src/queries/coreQuery.ts
CHANGED
|
@@ -12,7 +12,7 @@ import type {
|
|
|
12
12
|
SuiObjectData,
|
|
13
13
|
SuiParsedData,
|
|
14
14
|
} from '@mysten/sui/client';
|
|
15
|
-
import type
|
|
15
|
+
import { SuiTxBlock, type SuiObjectArg } from '@scallop-io/sui-kit';
|
|
16
16
|
// import type { ScallopAddress, ScallopCache, ScallopQuery } from '../models';
|
|
17
17
|
import {
|
|
18
18
|
Market,
|
|
@@ -46,6 +46,7 @@ import {
|
|
|
46
46
|
ScallopIndexer,
|
|
47
47
|
ScallopAddress,
|
|
48
48
|
} from 'src/models';
|
|
49
|
+
import { getSharedObjectData } from 'src/utils/object';
|
|
49
50
|
|
|
50
51
|
/**
|
|
51
52
|
* Query market data.
|
|
@@ -103,14 +104,22 @@ export const queryMarket = async (
|
|
|
103
104
|
};
|
|
104
105
|
}
|
|
105
106
|
|
|
107
|
+
const txBlock = new SuiTxBlock();
|
|
106
108
|
const packageId = utils.address.get('core.packages.query.id');
|
|
107
109
|
const marketId = utils.address.get('core.market');
|
|
108
110
|
const queryTarget = `${packageId}::market_query::market_data`;
|
|
109
|
-
const args = [
|
|
111
|
+
const args = [
|
|
112
|
+
txBlock.sharedObjectRef({
|
|
113
|
+
objectId: marketId,
|
|
114
|
+
initialSharedVersion: '7765848',
|
|
115
|
+
mutable: true,
|
|
116
|
+
}),
|
|
117
|
+
];
|
|
110
118
|
|
|
111
119
|
const queryResult = await utils.scallopSuiKit.queryInspectTxn({
|
|
112
120
|
queryTarget,
|
|
113
121
|
args,
|
|
122
|
+
txBlock,
|
|
114
123
|
});
|
|
115
124
|
const marketData = queryResult?.events[0]?.parsedJson as
|
|
116
125
|
| MarketQueryInterface
|
|
@@ -936,15 +945,27 @@ export const queryObligation = async (
|
|
|
936
945
|
},
|
|
937
946
|
obligationId: SuiObjectArg
|
|
938
947
|
) => {
|
|
948
|
+
const txBlock = new SuiTxBlock();
|
|
939
949
|
const packageId = address.get('core.packages.query.id');
|
|
940
950
|
const version = address.get('core.version');
|
|
941
951
|
const market = address.get('core.market');
|
|
942
952
|
const queryTarget = `${packageId}::obligation_query::obligation_data`;
|
|
943
953
|
|
|
944
954
|
const args = [
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
955
|
+
txBlock.sharedObjectRef({
|
|
956
|
+
objectId: version,
|
|
957
|
+
initialSharedVersion: '7765848',
|
|
958
|
+
mutable: false,
|
|
959
|
+
}),
|
|
960
|
+
txBlock.sharedObjectRef({
|
|
961
|
+
objectId: market,
|
|
962
|
+
initialSharedVersion: '7765848',
|
|
963
|
+
mutable: true,
|
|
964
|
+
}),
|
|
965
|
+
txBlock.sharedObjectRef({
|
|
966
|
+
...(await getSharedObjectData(obligationId)),
|
|
967
|
+
mutable: true,
|
|
968
|
+
}),
|
|
948
969
|
{
|
|
949
970
|
objectId: SUI_CLOCK_OBJECT_ID,
|
|
950
971
|
mutable: false,
|
|
@@ -953,7 +974,7 @@ export const queryObligation = async (
|
|
|
953
974
|
];
|
|
954
975
|
|
|
955
976
|
const queryResult = await scallopSuiKit.queryInspectTxn(
|
|
956
|
-
{ queryTarget, args }
|
|
977
|
+
{ queryTarget, args, txBlock }
|
|
957
978
|
// txBlock
|
|
958
979
|
);
|
|
959
980
|
return queryResult?.events[0]?.parsedJson as
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { bcs } from '@mysten/sui/bcs';
|
|
2
|
+
import { SuiTxBlock } from '@scallop-io/sui-kit';
|
|
2
3
|
import assert from 'assert';
|
|
3
4
|
import BigNumber from 'bignumber.js';
|
|
4
5
|
import { ScallopQuery, ScallopUtils } from 'src/models';
|
|
5
6
|
import { OptionalKeys, sCoinBalance } from 'src/types';
|
|
7
|
+
import { getSharedObjectData } from 'src/utils';
|
|
6
8
|
|
|
7
9
|
/**
|
|
8
10
|
* Get total supply of sCoin
|
|
@@ -18,9 +20,15 @@ export const getSCoinTotalSupply = async (
|
|
|
18
20
|
},
|
|
19
21
|
sCoinName: string
|
|
20
22
|
): Promise<sCoinBalance> => {
|
|
23
|
+
const txBlock = new SuiTxBlock();
|
|
21
24
|
const sCoinPkgId = utils.address.get('scoin.id');
|
|
22
25
|
// get treasury
|
|
23
|
-
const args = [
|
|
26
|
+
const args = [
|
|
27
|
+
txBlock.sharedObjectRef({
|
|
28
|
+
...(await getSharedObjectData(utils.getSCoinTreasury(sCoinName))),
|
|
29
|
+
mutable: false,
|
|
30
|
+
}),
|
|
31
|
+
];
|
|
24
32
|
const typeArgs = [
|
|
25
33
|
utils.parseSCoinType(sCoinName),
|
|
26
34
|
utils.parseUnderlyingSCoinType(sCoinName),
|
|
@@ -30,6 +38,7 @@ export const getSCoinTotalSupply = async (
|
|
|
30
38
|
queryTarget,
|
|
31
39
|
args,
|
|
32
40
|
typeArgs,
|
|
41
|
+
txBlock,
|
|
33
42
|
});
|
|
34
43
|
const results = queryResults?.results;
|
|
35
44
|
if (results && results[0]?.returnValues) {
|
|
@@ -81,6 +81,12 @@ export type CoreNormalMethods = {
|
|
|
81
81
|
loan: SuiObjectArg,
|
|
82
82
|
poolCoinName: string
|
|
83
83
|
) => void;
|
|
84
|
+
liquidate: (
|
|
85
|
+
obligation: SuiObjectArg,
|
|
86
|
+
coin: SuiObjectArg,
|
|
87
|
+
debtCoinName: string,
|
|
88
|
+
collateralCoinName: string
|
|
89
|
+
) => [NestedResult, NestedResult];
|
|
84
90
|
};
|
|
85
91
|
|
|
86
92
|
export type CoreQuickMethods = {
|
|
@@ -152,6 +158,18 @@ export type CoreQuickMethods = {
|
|
|
152
158
|
isSponsoredTx?: boolean;
|
|
153
159
|
}
|
|
154
160
|
) => Promise<void>;
|
|
161
|
+
liquidateQuick: (
|
|
162
|
+
amount: number,
|
|
163
|
+
debtCoinName: string,
|
|
164
|
+
collateralCoinName: string,
|
|
165
|
+
obligationId: SuiObjectArg,
|
|
166
|
+
updateOracleOptions?: {
|
|
167
|
+
usePythPullModel?: boolean;
|
|
168
|
+
useOnChainXOracleList?: boolean;
|
|
169
|
+
sponsoredFeeds?: string[];
|
|
170
|
+
isSponsoredTx?: boolean;
|
|
171
|
+
}
|
|
172
|
+
) => Promise<[NestedResult, NestedResult]>;
|
|
155
173
|
};
|
|
156
174
|
|
|
157
175
|
export type SuiTxBlockWithCoreNormalMethods = SuiKitTxBlock &
|
package/src/utils/index.ts
CHANGED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { getFullnodeUrl, SuiClient, SuiObjectData } from '@mysten/sui/client';
|
|
2
|
+
|
|
3
|
+
const parseObjectData = (data: SuiObjectData) => {
|
|
4
|
+
if (
|
|
5
|
+
typeof data === 'object' &&
|
|
6
|
+
'objectId' in data &&
|
|
7
|
+
'owner' in data &&
|
|
8
|
+
data.owner &&
|
|
9
|
+
typeof data.owner === 'object' &&
|
|
10
|
+
'Shared' in data.owner &&
|
|
11
|
+
'initial_shared_version' in data.owner.Shared
|
|
12
|
+
) {
|
|
13
|
+
return {
|
|
14
|
+
objectId: data.objectId,
|
|
15
|
+
initialSharedVersion: data.owner.Shared.initial_shared_version.toString(),
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
throw new Error('Invalid shared object data');
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export const getSharedObjectData = async (
|
|
23
|
+
object: any,
|
|
24
|
+
client: SuiClient = new SuiClient({
|
|
25
|
+
url: getFullnodeUrl('mainnet'),
|
|
26
|
+
})
|
|
27
|
+
) => {
|
|
28
|
+
if (typeof object === 'string') {
|
|
29
|
+
const objectData = await client.getObject({
|
|
30
|
+
id: object,
|
|
31
|
+
options: {
|
|
32
|
+
showOwner: true,
|
|
33
|
+
showContent: false,
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
return parseObjectData(objectData.data!);
|
|
37
|
+
} else {
|
|
38
|
+
return parseObjectData(object);
|
|
39
|
+
}
|
|
40
|
+
};
|