@scallop-io/sui-scallop-sdk 1.4.1-alpha.1 → 1.4.2-rc.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/constants/common.d.ts +4 -4
- package/dist/constants/enum.d.ts +2 -2
- package/dist/constants/poolAddress.d.ts +16 -4
- package/dist/constants/queryKeys.d.ts +2 -2
- package/dist/constants/tokenBucket.d.ts +2 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1314 -653
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1269 -609
- package/dist/index.mjs.map +1 -1
- package/dist/models/scallopBuilder.d.ts +2 -1
- package/dist/models/scallopCache.d.ts +2 -0
- package/dist/models/scallopQuery.d.ts +46 -20
- package/dist/models/scallopUtils.d.ts +5 -3
- package/dist/queries/borrowIncentiveQuery.d.ts +12 -0
- package/dist/queries/coreQuery.d.ts +18 -17
- package/dist/queries/index.d.ts +2 -0
- package/dist/queries/isolatedAssetQuery.d.ts +2 -2
- package/dist/queries/objectsQuery.d.ts +3 -0
- package/dist/queries/poolAddressesQuery.d.ts +18 -0
- package/dist/queries/portfolioQuery.d.ts +2 -0
- package/dist/queries/priceQuery.d.ts +4 -0
- package/dist/queries/sCoinQuery.d.ts +1 -1
- package/dist/queries/spoolQuery.d.ts +6 -2
- package/dist/test.d.ts +1 -0
- package/dist/types/builder/borrowIncentive.d.ts +5 -5
- package/dist/types/builder/core.d.ts +20 -16
- package/dist/types/builder/loyaltyProgram.d.ts +1 -1
- package/dist/types/builder/referral.d.ts +4 -4
- package/dist/types/builder/sCoin.d.ts +2 -2
- package/dist/types/builder/spool.d.ts +4 -4
- package/dist/types/builder/vesca.d.ts +6 -6
- package/dist/types/query/core.d.ts +22 -5
- package/dist/types/query/spool.d.ts +20 -0
- package/dist/types/utils.d.ts +7 -2
- package/dist/utils/core.d.ts +2 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/query.d.ts +1 -1
- package/dist/utils/util.d.ts +1 -0
- package/package.json +7 -7
- package/src/builders/borrowIncentiveBuilder.ts +28 -15
- package/src/builders/coreBuilder.ts +76 -49
- package/src/builders/loyaltyProgramBuilder.ts +4 -3
- package/src/builders/referralBuilder.ts +23 -10
- package/src/builders/sCoinBuilder.ts +8 -6
- package/src/builders/spoolBuilder.ts +21 -14
- package/src/builders/vescaBuilder.ts +23 -13
- package/src/constants/coinGecko.ts +2 -3
- package/src/constants/common.ts +5 -19
- package/src/constants/enum.ts +20 -35
- package/src/constants/poolAddress.ts +344 -19
- package/src/constants/pyth.ts +2 -3
- package/src/constants/queryKeys.ts +9 -5
- package/src/constants/testAddress.ts +42 -0
- package/src/constants/tokenBucket.ts +2 -2
- package/src/index.ts +1 -0
- package/src/models/scallopBuilder.ts +59 -2
- package/src/models/scallopCache.ts +171 -19
- package/src/models/scallopClient.ts +16 -10
- package/src/models/scallopQuery.ts +36 -28
- package/src/models/scallopUtils.ts +11 -4
- package/src/queries/borrowIncentiveQuery.ts +6 -8
- package/src/queries/borrowLimitQuery.ts +3 -3
- package/src/queries/coreQuery.ts +408 -258
- package/src/queries/index.ts +2 -0
- package/src/queries/isolatedAssetQuery.ts +39 -34
- package/src/queries/objectsQuery.ts +20 -0
- package/src/queries/poolAddressesQuery.ts +146 -0
- package/src/queries/portfolioQuery.ts +31 -13
- package/src/queries/priceQuery.ts +3 -1
- package/src/queries/spoolQuery.ts +189 -122
- package/src/queries/supplyLimitQuery.ts +2 -3
- package/src/test.ts +14 -17
- package/src/types/builder/borrowIncentive.ts +8 -5
- package/src/types/builder/core.ts +23 -17
- package/src/types/builder/loyaltyProgram.ts +1 -1
- package/src/types/builder/referral.ts +6 -4
- package/src/types/builder/sCoin.ts +2 -2
- package/src/types/builder/spool.ts +4 -4
- package/src/types/builder/vesca.ts +9 -6
- package/src/types/query/core.ts +21 -5
- package/src/types/query/spool.ts +21 -0
- package/src/types/utils.ts +8 -3
- package/src/utils/core.ts +18 -0
- package/src/utils/index.ts +2 -0
- package/src/utils/query.ts +21 -5
- package/src/utils/tokenBucket.ts +9 -29
- package/src/utils/util.ts +8 -0
|
@@ -13,7 +13,7 @@ export type BalanceSheet = {
|
|
|
13
13
|
market_coin_supply: string;
|
|
14
14
|
revenue: string;
|
|
15
15
|
};
|
|
16
|
-
export type
|
|
16
|
+
export type BorrowDynamic = {
|
|
17
17
|
borrow_index: string;
|
|
18
18
|
interest_rate: {
|
|
19
19
|
fields: {
|
|
@@ -23,6 +23,9 @@ export type BorrowIndex = {
|
|
|
23
23
|
interest_rate_scale: string;
|
|
24
24
|
last_updated: string;
|
|
25
25
|
};
|
|
26
|
+
export type BorrowFee = {
|
|
27
|
+
value: string;
|
|
28
|
+
};
|
|
26
29
|
export type InterestModel = {
|
|
27
30
|
base_borrow_rate_per_sec: {
|
|
28
31
|
fields: {
|
|
@@ -135,7 +138,7 @@ export type MarketCollateral = {
|
|
|
135
138
|
coinDecimal: number;
|
|
136
139
|
coinPrice: number;
|
|
137
140
|
isIsolated: boolean;
|
|
138
|
-
} & Required<Pick<ParsedMarketCollateralData, 'collateralFactor' | 'liquidationFactor' | 'liquidationDiscount' | '
|
|
141
|
+
} & Required<Pick<ParsedMarketCollateralData, 'collateralFactor' | 'liquidationFactor' | 'liquidationDiscount' | 'liquidationPenalty' | 'liquidationReserveFactor'>> & CalculatedMarketCollateralData;
|
|
139
142
|
export type OriginMarketPoolData = {
|
|
140
143
|
type: {
|
|
141
144
|
name: string;
|
|
@@ -178,6 +181,9 @@ export type OriginMarketPoolData = {
|
|
|
178
181
|
value: string;
|
|
179
182
|
};
|
|
180
183
|
minBorrowAmount: string;
|
|
184
|
+
isIsolated: boolean;
|
|
185
|
+
supplyLimit: string;
|
|
186
|
+
borrowLimit: string;
|
|
181
187
|
};
|
|
182
188
|
export type ParsedMarketPoolData = {
|
|
183
189
|
coinType: string;
|
|
@@ -199,6 +205,9 @@ export type ParsedMarketPoolData = {
|
|
|
199
205
|
highKink: number;
|
|
200
206
|
midKink: number;
|
|
201
207
|
minBorrowAmount: number;
|
|
208
|
+
isIsolated: boolean;
|
|
209
|
+
supplyLimit: number;
|
|
210
|
+
borrowLimit: number;
|
|
202
211
|
};
|
|
203
212
|
export type CalculatedMarketPoolData = {
|
|
204
213
|
baseBorrowApr: number;
|
|
@@ -207,6 +216,8 @@ export type CalculatedMarketPoolData = {
|
|
|
207
216
|
borrowApyOnHighKink: number;
|
|
208
217
|
borrowAprOnMidKink: number;
|
|
209
218
|
borrowApyOnMidKink: number;
|
|
219
|
+
coinDecimal: number;
|
|
220
|
+
conversionRate: number;
|
|
210
221
|
maxBorrowApr: number;
|
|
211
222
|
maxBorrowApy: number;
|
|
212
223
|
borrowApr: number;
|
|
@@ -222,12 +233,15 @@ export type CalculatedMarketPoolData = {
|
|
|
222
233
|
utilizationRate: number;
|
|
223
234
|
supplyApr: number;
|
|
224
235
|
supplyApy: number;
|
|
225
|
-
|
|
236
|
+
isIsolated: boolean;
|
|
237
|
+
maxSupplyCoin: number;
|
|
238
|
+
maxBorrowCoin: number;
|
|
226
239
|
};
|
|
227
240
|
export type OriginMarketCollateralData = {
|
|
228
241
|
type: {
|
|
229
242
|
name: string;
|
|
230
243
|
};
|
|
244
|
+
isIsolated: boolean;
|
|
231
245
|
collateralFactor: {
|
|
232
246
|
value: string;
|
|
233
247
|
};
|
|
@@ -237,7 +251,7 @@ export type OriginMarketCollateralData = {
|
|
|
237
251
|
liquidationDiscount: {
|
|
238
252
|
value: string;
|
|
239
253
|
};
|
|
240
|
-
|
|
254
|
+
liquidationPenalty: {
|
|
241
255
|
value: string;
|
|
242
256
|
};
|
|
243
257
|
liquidationReserveFactor: {
|
|
@@ -251,12 +265,15 @@ export type ParsedMarketCollateralData = {
|
|
|
251
265
|
collateralFactor: number;
|
|
252
266
|
liquidationFactor: number;
|
|
253
267
|
liquidationDiscount: number;
|
|
254
|
-
|
|
268
|
+
liquidationPenalty: number;
|
|
255
269
|
liquidationReserveFactor: number;
|
|
256
270
|
maxCollateralAmount: number;
|
|
257
271
|
totalCollateralAmount: number;
|
|
272
|
+
isIsolated: boolean;
|
|
258
273
|
};
|
|
259
274
|
export type CalculatedMarketCollateralData = {
|
|
275
|
+
coinDecimal: number;
|
|
276
|
+
isIsolated: boolean;
|
|
260
277
|
maxDepositAmount: number;
|
|
261
278
|
maxDepositCoin: number;
|
|
262
279
|
depositAmount: number;
|
|
@@ -32,6 +32,26 @@ export type OriginSpoolData = {
|
|
|
32
32
|
createdAt: string;
|
|
33
33
|
lastUpdate: string;
|
|
34
34
|
};
|
|
35
|
+
export type SpoolData = {
|
|
36
|
+
created_at: string;
|
|
37
|
+
distributed_point: string;
|
|
38
|
+
distributed_point_per_period: string;
|
|
39
|
+
id: {
|
|
40
|
+
id: string;
|
|
41
|
+
};
|
|
42
|
+
index: string;
|
|
43
|
+
last_update: string;
|
|
44
|
+
max_distributed_point: string;
|
|
45
|
+
max_stakes: string;
|
|
46
|
+
point_distribution_time: string;
|
|
47
|
+
stake_type: {
|
|
48
|
+
type: string;
|
|
49
|
+
fields: {
|
|
50
|
+
name: string;
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
stakes: string;
|
|
54
|
+
};
|
|
35
55
|
export type ParsedSpoolData = {
|
|
36
56
|
stakeType: string;
|
|
37
57
|
maxPoint: number;
|
package/dist/types/utils.d.ts
CHANGED
|
@@ -8,10 +8,15 @@ export type PoolAddressInfo = {
|
|
|
8
8
|
coingeckoId: string;
|
|
9
9
|
decimal: number;
|
|
10
10
|
pythFeedId: string;
|
|
11
|
-
lendingPoolAddress
|
|
11
|
+
lendingPoolAddress?: string;
|
|
12
12
|
collateralPoolAddress?: string;
|
|
13
|
+
borrowDynamic?: string;
|
|
14
|
+
interestModelId?: string;
|
|
15
|
+
borrowFeeKey?: string;
|
|
16
|
+
supplyLimitKey?: string;
|
|
17
|
+
borrowLimitKey?: string;
|
|
18
|
+
isolatedAssetKey?: string;
|
|
13
19
|
sCoinAddress: string | undefined;
|
|
14
20
|
marketCoinAddress: string;
|
|
15
|
-
coinAddress: string;
|
|
16
21
|
sCoinName: string | undefined;
|
|
17
22
|
};
|
package/dist/utils/index.d.ts
CHANGED
package/dist/utils/query.d.ts
CHANGED
|
@@ -40,7 +40,7 @@ export declare const parseOriginBorrowIncentivesPoolPointData: (originBorrowInce
|
|
|
40
40
|
* @param originBorrowIncentivePoolData - Origin borrow incentive pool data
|
|
41
41
|
* @return Parsed borrow incentive pool data
|
|
42
42
|
*/
|
|
43
|
-
export declare const parseOriginBorrowIncentivePoolData: (originBorrowIncentivePoolData: OriginBorrowIncentivePoolData) => ParsedBorrowIncentivePoolData;
|
|
43
|
+
export declare const parseOriginBorrowIncentivePoolData: (utils: ScallopUtils, originBorrowIncentivePoolData: OriginBorrowIncentivePoolData) => ParsedBorrowIncentivePoolData;
|
|
44
44
|
export declare const calculateBorrowIncentivePoolPointData: (parsedBorrowIncentivePoolPointData: ParsedBorrowIncentivePoolPointData, rewardCoinPrice: number, rewardCoinDecimal: number, poolCoinPrice: number, poolCoinDecimal: number) => CalculatedBorrowIncentivePoolPointData;
|
|
45
45
|
export declare const parseOriginBorrowIncentiveAccountPoolPointData: (originBorrowIncentiveAccountPoolPointData: OriginBorrowIncentiveAccountPoolData) => ParsedBorrowIncentiveAccountPoolData;
|
|
46
46
|
/**
|
package/dist/utils/util.d.ts
CHANGED
|
@@ -24,3 +24,4 @@ export declare const parseDataFromPythPriceFeed: (feed: PriceFeed, address: Scal
|
|
|
24
24
|
* @returns Closest round (12AM) in seconds timestamp.
|
|
25
25
|
*/
|
|
26
26
|
export declare const findClosestUnlockRound: (unlockAtInSecondTimestamp: number) => number;
|
|
27
|
+
export declare const partitionArray: <T>(array: T[], chunkSize: number) => T[][];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scallop-io/sui-scallop-sdk",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.2-rc.1",
|
|
4
4
|
"description": "Typescript sdk for interacting with Scallop contract on SUI",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sui",
|
|
@@ -39,13 +39,12 @@
|
|
|
39
39
|
],
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"@graphql-typed-document-node/core": "3.2.0",
|
|
42
|
-
"@mysten/
|
|
43
|
-
"@mysten/sui": "^1.3.0",
|
|
42
|
+
"@mysten/sui": "1.3.1",
|
|
44
43
|
"@noble/curves": "^1.2.0",
|
|
45
44
|
"@noble/hashes": "^1.3.2",
|
|
46
45
|
"@pythnetwork/price-service-client": "^1.8.2",
|
|
47
46
|
"@pythnetwork/pyth-sui-js": "2.1.0",
|
|
48
|
-
"@scallop-io/sui-kit": "1.3.1
|
|
47
|
+
"@scallop-io/sui-kit": "1.3.1",
|
|
49
48
|
"@scure/bip39": "^1.2.1",
|
|
50
49
|
"@tanstack/query-core": "5.51.15",
|
|
51
50
|
"axios": "^1.6.0",
|
|
@@ -81,9 +80,10 @@
|
|
|
81
80
|
"vitest": "^0.34.6"
|
|
82
81
|
},
|
|
83
82
|
"peerDependencies": {
|
|
84
|
-
"@mysten/sui": "1.3.
|
|
85
|
-
"@scallop-io/sui-kit": "1.3.1
|
|
86
|
-
"bn.js": "^5.2.1"
|
|
83
|
+
"@mysten/sui": "1.3.1",
|
|
84
|
+
"@scallop-io/sui-kit": "1.3.1",
|
|
85
|
+
"bn.js": "^5.2.1",
|
|
86
|
+
"@mysten/bcs": "^1.2.0"
|
|
87
87
|
},
|
|
88
88
|
"lint-staged": {
|
|
89
89
|
"**/*.ts": [
|
|
@@ -97,8 +97,9 @@ const generateBorrowIncentiveNormalMethod: GenerateBorrowIncentiveNormalMethod =
|
|
|
97
97
|
};
|
|
98
98
|
|
|
99
99
|
return {
|
|
100
|
-
stakeObligation: (obligationId, obligationKey) => {
|
|
101
|
-
|
|
100
|
+
stakeObligation: async (obligationId, obligationKey) => {
|
|
101
|
+
await builder.moveCall(
|
|
102
|
+
txBlock,
|
|
102
103
|
`${borrowIncentiveIds.borrowIncentivePkg}::user::stake`,
|
|
103
104
|
[
|
|
104
105
|
borrowIncentiveIds.config,
|
|
@@ -111,8 +112,13 @@ const generateBorrowIncentiveNormalMethod: GenerateBorrowIncentiveNormalMethod =
|
|
|
111
112
|
]
|
|
112
113
|
);
|
|
113
114
|
},
|
|
114
|
-
stakeObligationWithVesca: (
|
|
115
|
-
|
|
115
|
+
stakeObligationWithVesca: async (
|
|
116
|
+
obligationId,
|
|
117
|
+
obligationKey,
|
|
118
|
+
veScaKey
|
|
119
|
+
) => {
|
|
120
|
+
await builder.moveCall(
|
|
121
|
+
txBlock,
|
|
116
122
|
`${borrowIncentiveIds.borrowIncentivePkg}::user::stake_with_ve_sca`,
|
|
117
123
|
[
|
|
118
124
|
borrowIncentiveIds.config,
|
|
@@ -130,8 +136,9 @@ const generateBorrowIncentiveNormalMethod: GenerateBorrowIncentiveNormalMethod =
|
|
|
130
136
|
[]
|
|
131
137
|
);
|
|
132
138
|
},
|
|
133
|
-
unstakeObligation: (obligationId, obligationKey) => {
|
|
134
|
-
|
|
139
|
+
unstakeObligation: async (obligationId, obligationKey) => {
|
|
140
|
+
await builder.moveCall(
|
|
141
|
+
txBlock,
|
|
135
142
|
`${borrowIncentiveIds.borrowIncentivePkg}::user::unstake`,
|
|
136
143
|
[
|
|
137
144
|
borrowIncentiveIds.config,
|
|
@@ -143,9 +150,14 @@ const generateBorrowIncentiveNormalMethod: GenerateBorrowIncentiveNormalMethod =
|
|
|
143
150
|
]
|
|
144
151
|
);
|
|
145
152
|
},
|
|
146
|
-
claimBorrowIncentive: (
|
|
153
|
+
claimBorrowIncentive: async (
|
|
154
|
+
obligationId,
|
|
155
|
+
obligationKey,
|
|
156
|
+
rewardCoinName
|
|
157
|
+
) => {
|
|
147
158
|
const rewardType = builder.utils.parseCoinType(rewardCoinName);
|
|
148
|
-
return
|
|
159
|
+
return await builder.moveCall(
|
|
160
|
+
txBlock,
|
|
149
161
|
`${borrowIncentiveIds.borrowIncentivePkg}::user::redeem_rewards`,
|
|
150
162
|
[
|
|
151
163
|
borrowIncentiveIds.config,
|
|
@@ -158,8 +170,9 @@ const generateBorrowIncentiveNormalMethod: GenerateBorrowIncentiveNormalMethod =
|
|
|
158
170
|
[rewardType]
|
|
159
171
|
);
|
|
160
172
|
},
|
|
161
|
-
deactivateBoost: (obligation, veScaKey) => {
|
|
162
|
-
|
|
173
|
+
deactivateBoost: async (obligation, veScaKey) => {
|
|
174
|
+
await builder.moveCall(
|
|
175
|
+
txBlock,
|
|
163
176
|
`${borrowIncentiveIds.borrowIncentivePkg}::user::deactivate_boost`,
|
|
164
177
|
[
|
|
165
178
|
borrowIncentiveIds.config,
|
|
@@ -212,7 +225,7 @@ const generateBorrowIncentiveQuickMethod: GenerateBorrowIncentiveQuickMethod =
|
|
|
212
225
|
);
|
|
213
226
|
|
|
214
227
|
if (!obligationLocked || unstakeObligationBeforeStake) {
|
|
215
|
-
txBlock.stakeObligation(obligationArg, obligationKeyArg);
|
|
228
|
+
await txBlock.stakeObligation(obligationArg, obligationKeyArg);
|
|
216
229
|
}
|
|
217
230
|
},
|
|
218
231
|
stakeObligationWithVeScaQuick: async (
|
|
@@ -247,9 +260,9 @@ const generateBorrowIncentiveQuickMethod: GenerateBorrowIncentiveQuickMethod =
|
|
|
247
260
|
|
|
248
261
|
const _veScaKey = bindedVeScaKey ?? veScaKey;
|
|
249
262
|
if (!_veScaKey) {
|
|
250
|
-
txBlock.stakeObligation(obligationArg, obligationKeyArg);
|
|
263
|
+
await txBlock.stakeObligation(obligationArg, obligationKeyArg);
|
|
251
264
|
} else {
|
|
252
|
-
txBlock.stakeObligationWithVesca(
|
|
265
|
+
await txBlock.stakeObligationWithVesca(
|
|
253
266
|
obligationArg,
|
|
254
267
|
obligationKeyArg,
|
|
255
268
|
_veScaKey
|
|
@@ -270,7 +283,7 @@ const generateBorrowIncentiveQuickMethod: GenerateBorrowIncentiveQuickMethod =
|
|
|
270
283
|
);
|
|
271
284
|
|
|
272
285
|
if (obligationLocked) {
|
|
273
|
-
txBlock.unstakeObligation(obligationArg, obligationKeyArg);
|
|
286
|
+
await txBlock.unstakeObligation(obligationArg, obligationKeyArg);
|
|
274
287
|
}
|
|
275
288
|
},
|
|
276
289
|
claimBorrowIncentiveQuick: async (
|
|
@@ -287,7 +300,7 @@ const generateBorrowIncentiveQuickMethod: GenerateBorrowIncentiveQuickMethod =
|
|
|
287
300
|
obligationKey
|
|
288
301
|
);
|
|
289
302
|
|
|
290
|
-
return txBlock.claimBorrowIncentive(
|
|
303
|
+
return await txBlock.claimBorrowIncentive(
|
|
291
304
|
obligationArg,
|
|
292
305
|
obligationKeyArg,
|
|
293
306
|
rewardCoinName
|
|
@@ -77,38 +77,51 @@ const generateCoreNormalMethod: GenerateCoreNormalMethod = ({
|
|
|
77
77
|
const referralWitnessType = `${referralPkgId}::scallop_referral_program::REFERRAL_WITNESS`;
|
|
78
78
|
|
|
79
79
|
return {
|
|
80
|
-
openObligation: () => {
|
|
81
|
-
const [obligation, obligationKey, obligationHotPotato] =
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
80
|
+
openObligation: async () => {
|
|
81
|
+
const [obligation, obligationKey, obligationHotPotato] =
|
|
82
|
+
await builder.moveCall(
|
|
83
|
+
txBlock,
|
|
84
|
+
`${coreIds.protocolPkg}::open_obligation::open_obligation`,
|
|
85
|
+
[coreIds.version]
|
|
86
|
+
);
|
|
85
87
|
return [obligation, obligationKey, obligationHotPotato] as [
|
|
86
88
|
NestedResult,
|
|
87
89
|
NestedResult,
|
|
88
90
|
NestedResult,
|
|
89
91
|
];
|
|
90
92
|
},
|
|
91
|
-
returnObligation: (obligation, obligationHotPotato) =>
|
|
92
|
-
|
|
93
|
+
returnObligation: async (obligation, obligationHotPotato) => {
|
|
94
|
+
await builder.moveCall(
|
|
95
|
+
txBlock,
|
|
93
96
|
`${coreIds.protocolPkg}::open_obligation::return_obligation`,
|
|
94
97
|
[coreIds.version, obligation, obligationHotPotato]
|
|
95
|
-
)
|
|
96
|
-
|
|
97
|
-
|
|
98
|
+
);
|
|
99
|
+
},
|
|
100
|
+
openObligationEntry: async () => {
|
|
101
|
+
await builder.moveCall(
|
|
102
|
+
txBlock,
|
|
98
103
|
`${coreIds.protocolPkg}::open_obligation::open_obligation_entry`,
|
|
99
104
|
[coreIds.version]
|
|
100
|
-
)
|
|
101
|
-
|
|
105
|
+
);
|
|
106
|
+
},
|
|
107
|
+
addCollateral: async (obligation, coin, collateralCoinName) => {
|
|
102
108
|
const coinType = builder.utils.parseCoinType(collateralCoinName);
|
|
103
|
-
|
|
109
|
+
await builder.moveCall(
|
|
110
|
+
txBlock,
|
|
104
111
|
`${coreIds.protocolPkg}::deposit_collateral::deposit_collateral`,
|
|
105
112
|
[coreIds.version, obligation, coreIds.market, coin],
|
|
106
113
|
[coinType]
|
|
107
114
|
);
|
|
108
115
|
},
|
|
109
|
-
takeCollateral: (
|
|
116
|
+
takeCollateral: async (
|
|
117
|
+
obligation,
|
|
118
|
+
obligationKey,
|
|
119
|
+
amount,
|
|
120
|
+
collateralCoinName
|
|
121
|
+
) => {
|
|
110
122
|
const coinType = builder.utils.parseCoinType(collateralCoinName);
|
|
111
|
-
return
|
|
123
|
+
return await builder.moveCall(
|
|
124
|
+
txBlock,
|
|
112
125
|
`${coreIds.protocolPkg}::withdraw_collateral::withdraw_collateral`,
|
|
113
126
|
[
|
|
114
127
|
coreIds.version,
|
|
@@ -123,41 +136,46 @@ const generateCoreNormalMethod: GenerateCoreNormalMethod = ({
|
|
|
123
136
|
[coinType]
|
|
124
137
|
);
|
|
125
138
|
},
|
|
126
|
-
deposit: (coin, poolCoinName) => {
|
|
139
|
+
deposit: async (coin, poolCoinName) => {
|
|
127
140
|
const coinType = builder.utils.parseCoinType(poolCoinName);
|
|
128
|
-
return
|
|
141
|
+
return await builder.moveCall(
|
|
142
|
+
txBlock,
|
|
129
143
|
`${coreIds.protocolPkg}::mint::mint`,
|
|
130
144
|
[coreIds.version, coreIds.market, coin, SUI_CLOCK_OBJECT_ID],
|
|
131
145
|
[coinType]
|
|
132
146
|
);
|
|
133
147
|
},
|
|
134
|
-
depositEntry: (coin, poolCoinName) => {
|
|
148
|
+
depositEntry: async (coin, poolCoinName) => {
|
|
135
149
|
const coinType = builder.utils.parseCoinType(poolCoinName);
|
|
136
|
-
return
|
|
150
|
+
return await builder.moveCall(
|
|
151
|
+
txBlock,
|
|
137
152
|
`${coreIds.protocolPkg}::mint::mint_entry`,
|
|
138
153
|
[coreIds.version, coreIds.market, coin, SUI_CLOCK_OBJECT_ID],
|
|
139
154
|
[coinType]
|
|
140
155
|
);
|
|
141
156
|
},
|
|
142
|
-
withdraw: (marketCoin, poolCoinName) => {
|
|
157
|
+
withdraw: async (marketCoin, poolCoinName) => {
|
|
143
158
|
const coinType = builder.utils.parseCoinType(poolCoinName);
|
|
144
|
-
return
|
|
159
|
+
return await builder.moveCall(
|
|
160
|
+
txBlock,
|
|
145
161
|
`${coreIds.protocolPkg}::redeem::redeem`,
|
|
146
162
|
[coreIds.version, coreIds.market, marketCoin, SUI_CLOCK_OBJECT_ID],
|
|
147
163
|
[coinType]
|
|
148
164
|
);
|
|
149
165
|
},
|
|
150
|
-
withdrawEntry: (marketCoin, poolCoinName) => {
|
|
166
|
+
withdrawEntry: async (marketCoin, poolCoinName) => {
|
|
151
167
|
const coinType = builder.utils.parseCoinType(poolCoinName);
|
|
152
|
-
return
|
|
168
|
+
return await builder.moveCall(
|
|
169
|
+
txBlock,
|
|
153
170
|
`${coreIds.protocolPkg}::redeem::redeem_entry`,
|
|
154
171
|
[coreIds.version, coreIds.market, marketCoin, SUI_CLOCK_OBJECT_ID],
|
|
155
172
|
[coinType]
|
|
156
173
|
);
|
|
157
174
|
},
|
|
158
|
-
borrow: (obligation, obligationKey, amount, poolCoinName) => {
|
|
175
|
+
borrow: async (obligation, obligationKey, amount, poolCoinName) => {
|
|
159
176
|
const coinType = builder.utils.parseCoinType(poolCoinName);
|
|
160
|
-
return
|
|
177
|
+
return await builder.moveCall(
|
|
178
|
+
txBlock,
|
|
161
179
|
`${coreIds.protocolPkg}::borrow::borrow`,
|
|
162
180
|
[
|
|
163
181
|
coreIds.version,
|
|
@@ -172,7 +190,7 @@ const generateCoreNormalMethod: GenerateCoreNormalMethod = ({
|
|
|
172
190
|
[coinType]
|
|
173
191
|
);
|
|
174
192
|
},
|
|
175
|
-
borrowWithReferral: (
|
|
193
|
+
borrowWithReferral: async (
|
|
176
194
|
obligation,
|
|
177
195
|
obligationKey,
|
|
178
196
|
borrowReferral,
|
|
@@ -180,7 +198,8 @@ const generateCoreNormalMethod: GenerateCoreNormalMethod = ({
|
|
|
180
198
|
poolCoinName
|
|
181
199
|
) => {
|
|
182
200
|
const coinType = builder.utils.parseCoinType(poolCoinName);
|
|
183
|
-
return
|
|
201
|
+
return await builder.moveCall(
|
|
202
|
+
txBlock,
|
|
184
203
|
`${coreIds.protocolPkg}::borrow::borrow_with_referral`,
|
|
185
204
|
[
|
|
186
205
|
coreIds.version,
|
|
@@ -189,16 +208,17 @@ const generateCoreNormalMethod: GenerateCoreNormalMethod = ({
|
|
|
189
208
|
coreIds.market,
|
|
190
209
|
coreIds.coinDecimalsRegistry,
|
|
191
210
|
borrowReferral,
|
|
192
|
-
txBlock.pure.u64(amount),
|
|
211
|
+
typeof amount === 'number' ? txBlock.pure.u64(amount) : amount,
|
|
193
212
|
coreIds.xOracle,
|
|
194
213
|
SUI_CLOCK_OBJECT_ID,
|
|
195
214
|
],
|
|
196
215
|
[coinType, referralWitnessType]
|
|
197
216
|
);
|
|
198
217
|
},
|
|
199
|
-
borrowEntry: (obligation, obligationKey, amount, poolCoinName) => {
|
|
218
|
+
borrowEntry: async (obligation, obligationKey, amount, poolCoinName) => {
|
|
200
219
|
const coinType = builder.utils.parseCoinType(poolCoinName);
|
|
201
|
-
return
|
|
220
|
+
return await builder.moveCall(
|
|
221
|
+
txBlock,
|
|
202
222
|
`${coreIds.protocolPkg}::borrow::borrow_entry`,
|
|
203
223
|
[
|
|
204
224
|
coreIds.version,
|
|
@@ -213,9 +233,10 @@ const generateCoreNormalMethod: GenerateCoreNormalMethod = ({
|
|
|
213
233
|
[coinType]
|
|
214
234
|
);
|
|
215
235
|
},
|
|
216
|
-
repay: (obligation, coin, poolCoinName) => {
|
|
236
|
+
repay: async (obligation, coin, poolCoinName) => {
|
|
217
237
|
const coinType = builder.utils.parseCoinType(poolCoinName);
|
|
218
|
-
|
|
238
|
+
await builder.moveCall(
|
|
239
|
+
txBlock,
|
|
219
240
|
`${coreIds.protocolPkg}::repay::repay`,
|
|
220
241
|
[
|
|
221
242
|
coreIds.version,
|
|
@@ -227,17 +248,19 @@ const generateCoreNormalMethod: GenerateCoreNormalMethod = ({
|
|
|
227
248
|
[coinType]
|
|
228
249
|
);
|
|
229
250
|
},
|
|
230
|
-
borrowFlashLoan: (amount, poolCoinName) => {
|
|
251
|
+
borrowFlashLoan: async (amount, poolCoinName) => {
|
|
231
252
|
const coinType = builder.utils.parseCoinType(poolCoinName);
|
|
232
|
-
return
|
|
253
|
+
return await builder.moveCall(
|
|
254
|
+
txBlock,
|
|
233
255
|
`${coreIds.protocolPkg}::flash_loan::borrow_flash_loan`,
|
|
234
256
|
[coreIds.version, coreIds.market, amount],
|
|
235
257
|
[coinType]
|
|
236
258
|
);
|
|
237
259
|
},
|
|
238
|
-
repayFlashLoan: (coin, loan, poolCoinName) => {
|
|
260
|
+
repayFlashLoan: async (coin, loan, poolCoinName) => {
|
|
239
261
|
const coinType = builder.utils.parseCoinType(poolCoinName);
|
|
240
|
-
|
|
262
|
+
await builder.moveCall(
|
|
263
|
+
txBlock,
|
|
241
264
|
`${coreIds.protocolPkg}::flash_loan::repay_flash_loan`,
|
|
242
265
|
[coreIds.version, coreIds.market, coin, loan],
|
|
243
266
|
[coinType]
|
|
@@ -273,7 +296,7 @@ const generateCoreQuickMethod: GenerateCoreQuickMethod = ({
|
|
|
273
296
|
|
|
274
297
|
if (collateralCoinName === 'sui') {
|
|
275
298
|
const [suiCoin] = txBlock.splitSUIFromGas([amount]);
|
|
276
|
-
txBlock.addCollateral(obligationArg, suiCoin, collateralCoinName);
|
|
299
|
+
await txBlock.addCollateral(obligationArg, suiCoin, collateralCoinName);
|
|
277
300
|
} else {
|
|
278
301
|
const { leftCoin, takeCoin } = await builder.selectCoin(
|
|
279
302
|
txBlock,
|
|
@@ -281,7 +304,11 @@ const generateCoreQuickMethod: GenerateCoreQuickMethod = ({
|
|
|
281
304
|
amount,
|
|
282
305
|
sender
|
|
283
306
|
);
|
|
284
|
-
txBlock.addCollateral(
|
|
307
|
+
await txBlock.addCollateral(
|
|
308
|
+
obligationArg,
|
|
309
|
+
takeCoin,
|
|
310
|
+
collateralCoinName
|
|
311
|
+
);
|
|
285
312
|
txBlock.transferObjects([leftCoin], sender);
|
|
286
313
|
}
|
|
287
314
|
},
|
|
@@ -301,7 +328,7 @@ const generateCoreQuickMethod: GenerateCoreQuickMethod = ({
|
|
|
301
328
|
obligationInfo.obligationId
|
|
302
329
|
);
|
|
303
330
|
await updateOracles(builder, txBlock, updateCoinNames);
|
|
304
|
-
return txBlock.takeCollateral(
|
|
331
|
+
return await txBlock.takeCollateral(
|
|
305
332
|
obligationInfo.obligationId,
|
|
306
333
|
obligationInfo.obligationKey as SuiObjectArg,
|
|
307
334
|
amount,
|
|
@@ -313,7 +340,7 @@ const generateCoreQuickMethod: GenerateCoreQuickMethod = ({
|
|
|
313
340
|
let marketCoinDeposit: TransactionResult | undefined;
|
|
314
341
|
if (poolCoinName === 'sui') {
|
|
315
342
|
const [suiCoin] = txBlock.splitSUIFromGas([amount]);
|
|
316
|
-
marketCoinDeposit = txBlock.deposit(suiCoin, poolCoinName);
|
|
343
|
+
marketCoinDeposit = await txBlock.deposit(suiCoin, poolCoinName);
|
|
317
344
|
} else {
|
|
318
345
|
const { leftCoin, takeCoin } = await builder.selectCoin(
|
|
319
346
|
txBlock,
|
|
@@ -322,12 +349,12 @@ const generateCoreQuickMethod: GenerateCoreQuickMethod = ({
|
|
|
322
349
|
sender
|
|
323
350
|
);
|
|
324
351
|
txBlock.transferObjects([leftCoin], sender);
|
|
325
|
-
marketCoinDeposit = txBlock.deposit(takeCoin, poolCoinName);
|
|
352
|
+
marketCoinDeposit = await txBlock.deposit(takeCoin, poolCoinName);
|
|
326
353
|
}
|
|
327
354
|
|
|
328
355
|
// convert to sCoin
|
|
329
356
|
return returnSCoin
|
|
330
|
-
? txBlock.mintSCoin(
|
|
357
|
+
? await txBlock.mintSCoin(
|
|
331
358
|
builder.utils.parseMarketCoinName(poolCoinName),
|
|
332
359
|
marketCoinDeposit
|
|
333
360
|
)
|
|
@@ -347,7 +374,7 @@ const generateCoreQuickMethod: GenerateCoreQuickMethod = ({
|
|
|
347
374
|
totalAmount,
|
|
348
375
|
} = await builder.selectSCoin(txBlock, sCoinName, amount, sender);
|
|
349
376
|
txBlock.transferObjects([leftCoin], sender);
|
|
350
|
-
const marketCoins = txBlock.burnSCoin(sCoinName, sCoins);
|
|
377
|
+
const marketCoins = await txBlock.burnSCoin(sCoinName, sCoins);
|
|
351
378
|
|
|
352
379
|
// check amount
|
|
353
380
|
amount -= totalAmount;
|
|
@@ -378,7 +405,7 @@ const generateCoreQuickMethod: GenerateCoreQuickMethod = ({
|
|
|
378
405
|
sender
|
|
379
406
|
);
|
|
380
407
|
txBlock.transferObjects([leftCoin], sender);
|
|
381
|
-
return txBlock.withdraw(walletMarketCoins, poolCoinName);
|
|
408
|
+
return await txBlock.withdraw(walletMarketCoins, poolCoinName);
|
|
382
409
|
}
|
|
383
410
|
},
|
|
384
411
|
borrowQuick: async (amount, poolCoinName, obligationId, obligationKey) => {
|
|
@@ -394,7 +421,7 @@ const generateCoreQuickMethod: GenerateCoreQuickMethod = ({
|
|
|
394
421
|
)) ?? [];
|
|
395
422
|
const updateCoinNames = [...obligationCoinNames, poolCoinName];
|
|
396
423
|
await updateOracles(builder, txBlock, updateCoinNames);
|
|
397
|
-
return txBlock.borrow(
|
|
424
|
+
return await txBlock.borrow(
|
|
398
425
|
obligationInfo.obligationId,
|
|
399
426
|
obligationInfo.obligationKey as SuiObjectArg,
|
|
400
427
|
amount,
|
|
@@ -420,7 +447,7 @@ const generateCoreQuickMethod: GenerateCoreQuickMethod = ({
|
|
|
420
447
|
)) ?? [];
|
|
421
448
|
const updateCoinNames = [...obligationCoinNames, poolCoinName];
|
|
422
449
|
await updateOracles(builder, txBlock, updateCoinNames);
|
|
423
|
-
return txBlock.borrowWithReferral(
|
|
450
|
+
return await txBlock.borrowWithReferral(
|
|
424
451
|
obligationInfo.obligationId,
|
|
425
452
|
obligationInfo.obligationKey as SuiObjectArg,
|
|
426
453
|
borrowReferral,
|
|
@@ -438,7 +465,7 @@ const generateCoreQuickMethod: GenerateCoreQuickMethod = ({
|
|
|
438
465
|
|
|
439
466
|
if (poolCoinName === 'sui') {
|
|
440
467
|
const [suiCoin] = txBlock.splitSUIFromGas([amount]);
|
|
441
|
-
return txBlock.repay(
|
|
468
|
+
return await txBlock.repay(
|
|
442
469
|
obligationInfo.obligationId,
|
|
443
470
|
suiCoin,
|
|
444
471
|
poolCoinName
|
|
@@ -451,7 +478,7 @@ const generateCoreQuickMethod: GenerateCoreQuickMethod = ({
|
|
|
451
478
|
sender
|
|
452
479
|
);
|
|
453
480
|
txBlock.transferObjects([leftCoin], sender);
|
|
454
|
-
return txBlock.repay(
|
|
481
|
+
return await txBlock.repay(
|
|
455
482
|
obligationInfo.obligationId,
|
|
456
483
|
takeCoin,
|
|
457
484
|
poolCoinName
|
|
@@ -459,7 +486,7 @@ const generateCoreQuickMethod: GenerateCoreQuickMethod = ({
|
|
|
459
486
|
}
|
|
460
487
|
},
|
|
461
488
|
updateAssetPricesQuick: async (assetCoinNames) => {
|
|
462
|
-
return updateOracles(builder, txBlock, assetCoinNames);
|
|
489
|
+
return await updateOracles(builder, txBlock, assetCoinNames);
|
|
463
490
|
},
|
|
464
491
|
};
|
|
465
492
|
};
|
|
@@ -23,8 +23,9 @@ const generateLoyaltyProgramNormalMethod: GenerateLoyaltyProgramNormalMethod =
|
|
|
23
23
|
};
|
|
24
24
|
|
|
25
25
|
return {
|
|
26
|
-
claimLoyaltyRevenue: (veScaKey) => {
|
|
27
|
-
return
|
|
26
|
+
claimLoyaltyRevenue: async (veScaKey) => {
|
|
27
|
+
return await builder.moveCall(
|
|
28
|
+
txBlock,
|
|
28
29
|
`${loyaltyProgramIds.loyaltyProgramPkgId}::reward_pool::redeem_reward`,
|
|
29
30
|
[loyaltyProgramIds.rewardPool, veScaKey]
|
|
30
31
|
);
|
|
@@ -43,7 +44,7 @@ const generateLoyaltyProgramQuickMethod: GenerateLoyaltyProgramQuickMethod = ({
|
|
|
43
44
|
if (!veScaKey) throw new Error(`No veScaKey found for user ${sender}`);
|
|
44
45
|
|
|
45
46
|
// claim the pending reward
|
|
46
|
-
const rewardCoin = txBlock.claimLoyaltyRevenue(veScaKey);
|
|
47
|
+
const rewardCoin = await txBlock.claimLoyaltyRevenue(veScaKey);
|
|
47
48
|
|
|
48
49
|
// get existing sca coin to merge with
|
|
49
50
|
await builder.utils.mergeSimilarCoins(
|