@scallop-io/sui-scallop-sdk 2.2.3 → 2.2.5
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 -5
- package/dist/index.d.ts +9 -5
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
- package/src/builders/coreBuilder.ts +25 -25
- package/src/builders/referralBuilder.ts +2 -8
- package/src/models/scallopClient.ts +29 -12
- package/src/types/builder/core.ts +2 -1
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@ import { SuiTxBlock as SuiKitTxBlock } from '@scallop-io/sui-kit';
|
|
|
4
4
|
import { getObligations } from '../queries';
|
|
5
5
|
import { updateOracles } from './oracles';
|
|
6
6
|
import { requireSender } from '../utils';
|
|
7
|
-
import type { SuiObjectArg
|
|
7
|
+
import type { SuiObjectArg } from '@scallop-io/sui-kit';
|
|
8
8
|
import type { ScallopBuilder } from 'src/models';
|
|
9
9
|
import type {
|
|
10
10
|
CoreIds,
|
|
@@ -287,7 +287,12 @@ const generateCoreQuickMethod: GenerateCoreQuickMethod = ({
|
|
|
287
287
|
txBlock,
|
|
288
288
|
}) => {
|
|
289
289
|
return {
|
|
290
|
-
addCollateralQuick: async (
|
|
290
|
+
addCollateralQuick: async (
|
|
291
|
+
amount,
|
|
292
|
+
collateralCoinName,
|
|
293
|
+
obligationId,
|
|
294
|
+
isSponsoredTx = false
|
|
295
|
+
) => {
|
|
291
296
|
const sender = requireSender(txBlock);
|
|
292
297
|
const { obligationId: obligationArg } = await requireObligationInfo(
|
|
293
298
|
builder,
|
|
@@ -295,19 +300,18 @@ const generateCoreQuickMethod: GenerateCoreQuickMethod = ({
|
|
|
295
300
|
obligationId
|
|
296
301
|
);
|
|
297
302
|
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
);
|
|
308
|
-
txBlock.addCollateral(obligationArg, takeCoin, collateralCoinName);
|
|
303
|
+
const { takeCoin, leftCoin } = await builder.selectCoin(
|
|
304
|
+
txBlock,
|
|
305
|
+
collateralCoinName,
|
|
306
|
+
amount,
|
|
307
|
+
sender,
|
|
308
|
+
isSponsoredTx
|
|
309
|
+
);
|
|
310
|
+
|
|
311
|
+
if (leftCoin) {
|
|
309
312
|
txBlock.transferObjects([leftCoin], sender);
|
|
310
313
|
}
|
|
314
|
+
txBlock.addCollateral(obligationArg, takeCoin, collateralCoinName);
|
|
311
315
|
},
|
|
312
316
|
takeCollateralQuick: async (
|
|
313
317
|
amount,
|
|
@@ -340,20 +344,16 @@ const generateCoreQuickMethod: GenerateCoreQuickMethod = ({
|
|
|
340
344
|
},
|
|
341
345
|
depositQuick: async (amount, poolCoinName, returnSCoin = true) => {
|
|
342
346
|
const sender = requireSender(txBlock);
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
poolCoinName,
|
|
351
|
-
amount,
|
|
352
|
-
sender
|
|
353
|
-
);
|
|
347
|
+
const { leftCoin, takeCoin } = await builder.selectCoin(
|
|
348
|
+
txBlock,
|
|
349
|
+
poolCoinName,
|
|
350
|
+
amount,
|
|
351
|
+
sender
|
|
352
|
+
);
|
|
353
|
+
if (leftCoin) {
|
|
354
354
|
txBlock.transferObjects([leftCoin], sender);
|
|
355
|
-
marketCoinDeposit = txBlock.deposit(takeCoin, poolCoinName);
|
|
356
355
|
}
|
|
356
|
+
const marketCoinDeposit = txBlock.deposit(takeCoin, poolCoinName);
|
|
357
357
|
|
|
358
358
|
// convert to sCoin
|
|
359
359
|
return returnSCoin
|
|
@@ -111,16 +111,10 @@ const generateReferralQuickMethod: GenerateReferralQuickMethod = ({
|
|
|
111
111
|
const objToTransfer: SuiObjectArg[] = [];
|
|
112
112
|
for (const coinName of coinNames) {
|
|
113
113
|
if (coinName === 'sui') {
|
|
114
|
-
const rewardCoin =
|
|
115
|
-
veScaKey,
|
|
116
|
-
coinName
|
|
117
|
-
);
|
|
114
|
+
const rewardCoin = txBlock.claimReferralRevenue(veScaKey, coinName);
|
|
118
115
|
objToTransfer.push(rewardCoin);
|
|
119
116
|
} else {
|
|
120
|
-
const rewardCoin =
|
|
121
|
-
veScaKey,
|
|
122
|
-
coinName
|
|
123
|
-
);
|
|
117
|
+
const rewardCoin = txBlock.claimReferralRevenue(veScaKey, coinName);
|
|
124
118
|
try {
|
|
125
119
|
// get the matching user coin if exists
|
|
126
120
|
const coins = await builder.suiKit.suiInteractor.selectCoins(
|
|
@@ -210,6 +210,7 @@ class ScallopClient implements ScallopClientInterface {
|
|
|
210
210
|
* @param sign - Decide to directly sign the transaction or return the transaction block.
|
|
211
211
|
* @param obligationId - The obligation object.
|
|
212
212
|
* @param walletAddress - The wallet address of the owner.
|
|
213
|
+
* @param isSponsoredTx - Whether the transaction is sponsored.
|
|
213
214
|
* @return Transaction block response or transaction block.
|
|
214
215
|
*/
|
|
215
216
|
async depositCollateral(
|
|
@@ -221,30 +222,38 @@ class ScallopClient implements ScallopClientInterface {
|
|
|
221
222
|
amount: number,
|
|
222
223
|
sign?: S,
|
|
223
224
|
obligationId?: string,
|
|
224
|
-
walletAddress?: string
|
|
225
|
+
walletAddress?: string,
|
|
226
|
+
isSponsoredTx?: boolean
|
|
225
227
|
): Promise<ScallopClientFnReturnType<S>>;
|
|
226
228
|
async depositCollateral<S extends boolean>(
|
|
227
229
|
collateralCoinName: string,
|
|
228
230
|
amount: number,
|
|
229
231
|
sign: S = true as S,
|
|
230
232
|
obligationId?: string,
|
|
231
|
-
walletAddress?: string
|
|
233
|
+
walletAddress?: string,
|
|
234
|
+
isSponsoredTx?: boolean
|
|
232
235
|
): Promise<ScallopClientFnReturnType<S>> {
|
|
233
236
|
const txBlock = this.builder.createTxBlock();
|
|
234
237
|
const sender = walletAddress ?? this.walletAddress;
|
|
235
238
|
txBlock.setSender(sender);
|
|
236
239
|
|
|
237
|
-
const
|
|
238
|
-
|
|
240
|
+
const specificObligationId =
|
|
241
|
+
obligationId ?? (await this.query.getObligations(sender))[0]?.id;
|
|
239
242
|
if (specificObligationId) {
|
|
240
243
|
await txBlock.addCollateralQuick(
|
|
241
244
|
amount,
|
|
242
245
|
collateralCoinName,
|
|
243
|
-
specificObligationId
|
|
246
|
+
specificObligationId,
|
|
247
|
+
isSponsoredTx
|
|
244
248
|
);
|
|
245
249
|
} else {
|
|
246
250
|
const [obligation, obligationKey, hotPotato] = txBlock.openObligation();
|
|
247
|
-
await txBlock.addCollateralQuick(
|
|
251
|
+
await txBlock.addCollateralQuick(
|
|
252
|
+
amount,
|
|
253
|
+
collateralCoinName,
|
|
254
|
+
obligation,
|
|
255
|
+
isSponsoredTx
|
|
256
|
+
);
|
|
248
257
|
txBlock.returnObligation(obligation, hotPotato);
|
|
249
258
|
txBlock.transferObjects([obligationKey], sender);
|
|
250
259
|
}
|
|
@@ -267,6 +276,7 @@ class ScallopClient implements ScallopClientInterface {
|
|
|
267
276
|
* @param obligationId - The obligation object.
|
|
268
277
|
* @param obligationKey - The obligation key object to verifying obligation authority.
|
|
269
278
|
* @param walletAddress - The wallet address of the owner.
|
|
279
|
+
* @param isSponsoredTx - Whether the transaction is sponsored.
|
|
270
280
|
* @return Transaction block response or transaction block.
|
|
271
281
|
*/
|
|
272
282
|
async withdrawCollateral<S extends boolean>(
|
|
@@ -275,7 +285,8 @@ class ScallopClient implements ScallopClientInterface {
|
|
|
275
285
|
sign: S = true as S,
|
|
276
286
|
obligationId: string,
|
|
277
287
|
obligationKey: string,
|
|
278
|
-
walletAddress?: string
|
|
288
|
+
walletAddress?: string,
|
|
289
|
+
isSponsoredTx?: boolean
|
|
279
290
|
): Promise<ScallopClientFnReturnType<S>> {
|
|
280
291
|
const txBlock = this.builder.createTxBlock();
|
|
281
292
|
const sender = walletAddress ?? this.walletAddress;
|
|
@@ -285,7 +296,8 @@ class ScallopClient implements ScallopClientInterface {
|
|
|
285
296
|
amount,
|
|
286
297
|
collateralCoinName,
|
|
287
298
|
obligationId,
|
|
288
|
-
obligationKey
|
|
299
|
+
obligationKey,
|
|
300
|
+
{ isSponsoredTx }
|
|
289
301
|
);
|
|
290
302
|
txBlock.transferObjects([collateralCoin], sender);
|
|
291
303
|
|
|
@@ -449,6 +461,7 @@ class ScallopClient implements ScallopClientInterface {
|
|
|
449
461
|
* @param obligationId - The obligation object.
|
|
450
462
|
* @param obligationKey - The obligation key object to verifying obligation authority.
|
|
451
463
|
* @param walletAddress - The wallet address of the owner.
|
|
464
|
+
* @param isSponsoredTx - Whether the transaction is sponsored.
|
|
452
465
|
* @return Transaction block response or transaction block.
|
|
453
466
|
*/
|
|
454
467
|
async borrow<S extends boolean>(
|
|
@@ -457,7 +470,8 @@ class ScallopClient implements ScallopClientInterface {
|
|
|
457
470
|
sign: S = true as S,
|
|
458
471
|
obligationId: string,
|
|
459
472
|
obligationKey: string,
|
|
460
|
-
walletAddress?: string
|
|
473
|
+
walletAddress?: string,
|
|
474
|
+
isSponsoredTx?: boolean
|
|
461
475
|
): Promise<ScallopClientFnReturnType<S>> {
|
|
462
476
|
const txBlock = this.builder.createTxBlock();
|
|
463
477
|
const sender = walletAddress ?? this.walletAddress;
|
|
@@ -471,7 +485,8 @@ class ScallopClient implements ScallopClientInterface {
|
|
|
471
485
|
amount,
|
|
472
486
|
poolCoinName,
|
|
473
487
|
obligationId,
|
|
474
|
-
obligationKey
|
|
488
|
+
obligationKey,
|
|
489
|
+
{ isSponsoredTx }
|
|
475
490
|
);
|
|
476
491
|
txBlock.transferObjects([coin], sender);
|
|
477
492
|
if (sign && availableStake) {
|
|
@@ -495,6 +510,7 @@ class ScallopClient implements ScallopClientInterface {
|
|
|
495
510
|
* @param sign - Decide to directly sign the transaction or return the transaction block.
|
|
496
511
|
* @param obligationId - The obligation object.
|
|
497
512
|
* @param walletAddress - The wallet address of the owner.
|
|
513
|
+
* @param isSponsoredTx - Whether the transaction is sponsored.
|
|
498
514
|
* @return Transaction block response or transaction block.
|
|
499
515
|
*/
|
|
500
516
|
async repay<S extends boolean>(
|
|
@@ -503,7 +519,8 @@ class ScallopClient implements ScallopClientInterface {
|
|
|
503
519
|
sign: S = true as S,
|
|
504
520
|
obligationId: string,
|
|
505
521
|
obligationKey: string,
|
|
506
|
-
walletAddress?: string
|
|
522
|
+
walletAddress?: string,
|
|
523
|
+
isSponsoredTx?: boolean
|
|
507
524
|
): Promise<ScallopClientFnReturnType<S>> {
|
|
508
525
|
const txBlock = this.builder.createTxBlock();
|
|
509
526
|
const sender = walletAddress ?? this.walletAddress;
|
|
@@ -513,7 +530,7 @@ class ScallopClient implements ScallopClientInterface {
|
|
|
513
530
|
if (sign && availableStake) {
|
|
514
531
|
await txBlock.unstakeObligationQuick(obligationId, obligationKey);
|
|
515
532
|
}
|
|
516
|
-
await txBlock.repayQuick(amount, poolCoinName, obligationId);
|
|
533
|
+
await txBlock.repayQuick(amount, poolCoinName, obligationId, isSponsoredTx);
|
|
517
534
|
if (sign && availableStake) {
|
|
518
535
|
await txBlock.stakeObligationWithVeScaQuick(obligationId, obligationKey);
|
|
519
536
|
}
|
|
@@ -87,7 +87,8 @@ export type CoreQuickMethods = {
|
|
|
87
87
|
addCollateralQuick: (
|
|
88
88
|
amount: number,
|
|
89
89
|
collateralCoinName: string,
|
|
90
|
-
obligationId?: SuiObjectArg
|
|
90
|
+
obligationId?: SuiObjectArg,
|
|
91
|
+
isSponsoredTx?: boolean
|
|
91
92
|
) => Promise<void>;
|
|
92
93
|
takeCollateralQuick: (
|
|
93
94
|
amount: number,
|