@scallop-io/sui-scallop-sdk 2.2.3 → 2.2.4
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 +8 -4
- package/dist/index.d.ts +8 -4
- 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 +27 -11
- 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(
|
|
@@ -228,23 +229,30 @@ class ScallopClient implements ScallopClientInterface {
|
|
|
228
229
|
amount: number,
|
|
229
230
|
sign: S = true as S,
|
|
230
231
|
obligationId?: string,
|
|
231
|
-
walletAddress?: string
|
|
232
|
+
walletAddress?: string,
|
|
233
|
+
isSponsoredTx?: boolean
|
|
232
234
|
): Promise<ScallopClientFnReturnType<S>> {
|
|
233
235
|
const txBlock = this.builder.createTxBlock();
|
|
234
236
|
const sender = walletAddress ?? this.walletAddress;
|
|
235
237
|
txBlock.setSender(sender);
|
|
236
238
|
|
|
237
|
-
const
|
|
238
|
-
|
|
239
|
+
const specificObligationId =
|
|
240
|
+
obligationId ?? (await this.query.getObligations(sender))[0]?.id;
|
|
239
241
|
if (specificObligationId) {
|
|
240
242
|
await txBlock.addCollateralQuick(
|
|
241
243
|
amount,
|
|
242
244
|
collateralCoinName,
|
|
243
|
-
specificObligationId
|
|
245
|
+
specificObligationId,
|
|
246
|
+
isSponsoredTx
|
|
244
247
|
);
|
|
245
248
|
} else {
|
|
246
249
|
const [obligation, obligationKey, hotPotato] = txBlock.openObligation();
|
|
247
|
-
await txBlock.addCollateralQuick(
|
|
250
|
+
await txBlock.addCollateralQuick(
|
|
251
|
+
amount,
|
|
252
|
+
collateralCoinName,
|
|
253
|
+
obligation,
|
|
254
|
+
isSponsoredTx
|
|
255
|
+
);
|
|
248
256
|
txBlock.returnObligation(obligation, hotPotato);
|
|
249
257
|
txBlock.transferObjects([obligationKey], sender);
|
|
250
258
|
}
|
|
@@ -267,6 +275,7 @@ class ScallopClient implements ScallopClientInterface {
|
|
|
267
275
|
* @param obligationId - The obligation object.
|
|
268
276
|
* @param obligationKey - The obligation key object to verifying obligation authority.
|
|
269
277
|
* @param walletAddress - The wallet address of the owner.
|
|
278
|
+
* @param isSponsoredTx - Whether the transaction is sponsored.
|
|
270
279
|
* @return Transaction block response or transaction block.
|
|
271
280
|
*/
|
|
272
281
|
async withdrawCollateral<S extends boolean>(
|
|
@@ -275,7 +284,8 @@ class ScallopClient implements ScallopClientInterface {
|
|
|
275
284
|
sign: S = true as S,
|
|
276
285
|
obligationId: string,
|
|
277
286
|
obligationKey: string,
|
|
278
|
-
walletAddress?: string
|
|
287
|
+
walletAddress?: string,
|
|
288
|
+
isSponsoredTx?: boolean
|
|
279
289
|
): Promise<ScallopClientFnReturnType<S>> {
|
|
280
290
|
const txBlock = this.builder.createTxBlock();
|
|
281
291
|
const sender = walletAddress ?? this.walletAddress;
|
|
@@ -285,7 +295,8 @@ class ScallopClient implements ScallopClientInterface {
|
|
|
285
295
|
amount,
|
|
286
296
|
collateralCoinName,
|
|
287
297
|
obligationId,
|
|
288
|
-
obligationKey
|
|
298
|
+
obligationKey,
|
|
299
|
+
{ isSponsoredTx }
|
|
289
300
|
);
|
|
290
301
|
txBlock.transferObjects([collateralCoin], sender);
|
|
291
302
|
|
|
@@ -449,6 +460,7 @@ class ScallopClient implements ScallopClientInterface {
|
|
|
449
460
|
* @param obligationId - The obligation object.
|
|
450
461
|
* @param obligationKey - The obligation key object to verifying obligation authority.
|
|
451
462
|
* @param walletAddress - The wallet address of the owner.
|
|
463
|
+
* @param isSponsoredTx - Whether the transaction is sponsored.
|
|
452
464
|
* @return Transaction block response or transaction block.
|
|
453
465
|
*/
|
|
454
466
|
async borrow<S extends boolean>(
|
|
@@ -457,7 +469,8 @@ class ScallopClient implements ScallopClientInterface {
|
|
|
457
469
|
sign: S = true as S,
|
|
458
470
|
obligationId: string,
|
|
459
471
|
obligationKey: string,
|
|
460
|
-
walletAddress?: string
|
|
472
|
+
walletAddress?: string,
|
|
473
|
+
isSponsoredTx?: boolean
|
|
461
474
|
): Promise<ScallopClientFnReturnType<S>> {
|
|
462
475
|
const txBlock = this.builder.createTxBlock();
|
|
463
476
|
const sender = walletAddress ?? this.walletAddress;
|
|
@@ -471,7 +484,8 @@ class ScallopClient implements ScallopClientInterface {
|
|
|
471
484
|
amount,
|
|
472
485
|
poolCoinName,
|
|
473
486
|
obligationId,
|
|
474
|
-
obligationKey
|
|
487
|
+
obligationKey,
|
|
488
|
+
{ isSponsoredTx }
|
|
475
489
|
);
|
|
476
490
|
txBlock.transferObjects([coin], sender);
|
|
477
491
|
if (sign && availableStake) {
|
|
@@ -495,6 +509,7 @@ class ScallopClient implements ScallopClientInterface {
|
|
|
495
509
|
* @param sign - Decide to directly sign the transaction or return the transaction block.
|
|
496
510
|
* @param obligationId - The obligation object.
|
|
497
511
|
* @param walletAddress - The wallet address of the owner.
|
|
512
|
+
* @param isSponsoredTx - Whether the transaction is sponsored.
|
|
498
513
|
* @return Transaction block response or transaction block.
|
|
499
514
|
*/
|
|
500
515
|
async repay<S extends boolean>(
|
|
@@ -503,7 +518,8 @@ class ScallopClient implements ScallopClientInterface {
|
|
|
503
518
|
sign: S = true as S,
|
|
504
519
|
obligationId: string,
|
|
505
520
|
obligationKey: string,
|
|
506
|
-
walletAddress?: string
|
|
521
|
+
walletAddress?: string,
|
|
522
|
+
isSponsoredTx?: boolean
|
|
507
523
|
): Promise<ScallopClientFnReturnType<S>> {
|
|
508
524
|
const txBlock = this.builder.createTxBlock();
|
|
509
525
|
const sender = walletAddress ?? this.walletAddress;
|
|
@@ -513,7 +529,7 @@ class ScallopClient implements ScallopClientInterface {
|
|
|
513
529
|
if (sign && availableStake) {
|
|
514
530
|
await txBlock.unstakeObligationQuick(obligationId, obligationKey);
|
|
515
531
|
}
|
|
516
|
-
await txBlock.repayQuick(amount, poolCoinName, obligationId);
|
|
532
|
+
await txBlock.repayQuick(amount, poolCoinName, obligationId, isSponsoredTx);
|
|
517
533
|
if (sign && availableStake) {
|
|
518
534
|
await txBlock.stakeObligationWithVeScaQuick(obligationId, obligationKey);
|
|
519
535
|
}
|
|
@@ -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,
|