@scallop-io/sui-scallop-sdk 2.2.3-pyth-sponsored-transaction-alpha.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 +33 -8
- package/dist/index.d.ts +33 -8
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
- package/src/builders/coreBuilder.ts +53 -35
- package/src/builders/oracles/pyth.ts +1 -2
- package/src/builders/referralBuilder.ts +2 -8
- package/src/models/scallopBuilder.ts +1 -0
- package/src/models/scallopClient.ts +27 -11
- package/src/types/builder/core.ts +29 -5
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,26 +300,25 @@ 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,
|
|
314
318
|
collateralCoinName,
|
|
315
319
|
obligationId,
|
|
316
320
|
obligationKey,
|
|
317
|
-
|
|
321
|
+
updateOracleOptions
|
|
318
322
|
) => {
|
|
319
323
|
const obligationInfo = await requireObligationInfo(
|
|
320
324
|
builder,
|
|
@@ -325,7 +329,12 @@ const generateCoreQuickMethod: GenerateCoreQuickMethod = ({
|
|
|
325
329
|
const updateCoinNames = await builder.utils.getObligationCoinNames(
|
|
326
330
|
obligationInfo.obligationId
|
|
327
331
|
);
|
|
328
|
-
await updateOracles(
|
|
332
|
+
await updateOracles(
|
|
333
|
+
builder,
|
|
334
|
+
txBlock,
|
|
335
|
+
updateCoinNames,
|
|
336
|
+
updateOracleOptions
|
|
337
|
+
);
|
|
329
338
|
return txBlock.takeCollateral(
|
|
330
339
|
obligationInfo.obligationId,
|
|
331
340
|
obligationInfo.obligationKey as SuiObjectArg,
|
|
@@ -335,20 +344,16 @@ const generateCoreQuickMethod: GenerateCoreQuickMethod = ({
|
|
|
335
344
|
},
|
|
336
345
|
depositQuick: async (amount, poolCoinName, returnSCoin = true) => {
|
|
337
346
|
const sender = requireSender(txBlock);
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
poolCoinName,
|
|
346
|
-
amount,
|
|
347
|
-
sender
|
|
348
|
-
);
|
|
347
|
+
const { leftCoin, takeCoin } = await builder.selectCoin(
|
|
348
|
+
txBlock,
|
|
349
|
+
poolCoinName,
|
|
350
|
+
amount,
|
|
351
|
+
sender
|
|
352
|
+
);
|
|
353
|
+
if (leftCoin) {
|
|
349
354
|
txBlock.transferObjects([leftCoin], sender);
|
|
350
|
-
marketCoinDeposit = txBlock.deposit(takeCoin, poolCoinName);
|
|
351
355
|
}
|
|
356
|
+
const marketCoinDeposit = txBlock.deposit(takeCoin, poolCoinName);
|
|
352
357
|
|
|
353
358
|
// convert to sCoin
|
|
354
359
|
return returnSCoin
|
|
@@ -388,7 +393,7 @@ const generateCoreQuickMethod: GenerateCoreQuickMethod = ({
|
|
|
388
393
|
poolCoinName,
|
|
389
394
|
obligationId,
|
|
390
395
|
obligationKey,
|
|
391
|
-
|
|
396
|
+
updateOracleOptions
|
|
392
397
|
) => {
|
|
393
398
|
const obligationInfo = await requireObligationInfo(
|
|
394
399
|
builder,
|
|
@@ -401,7 +406,12 @@ const generateCoreQuickMethod: GenerateCoreQuickMethod = ({
|
|
|
401
406
|
obligationInfo.obligationId
|
|
402
407
|
)) ?? [];
|
|
403
408
|
const updateCoinNames = [...obligationCoinNames, poolCoinName];
|
|
404
|
-
await updateOracles(
|
|
409
|
+
await updateOracles(
|
|
410
|
+
builder,
|
|
411
|
+
txBlock,
|
|
412
|
+
updateCoinNames,
|
|
413
|
+
updateOracleOptions
|
|
414
|
+
);
|
|
405
415
|
return txBlock.borrow(
|
|
406
416
|
obligationInfo.obligationId,
|
|
407
417
|
obligationInfo.obligationKey as SuiObjectArg,
|
|
@@ -415,7 +425,7 @@ const generateCoreQuickMethod: GenerateCoreQuickMethod = ({
|
|
|
415
425
|
borrowReferral,
|
|
416
426
|
obligationId,
|
|
417
427
|
obligationKey,
|
|
418
|
-
|
|
428
|
+
updateOracleOptions
|
|
419
429
|
) => {
|
|
420
430
|
const obligationInfo = await requireObligationInfo(
|
|
421
431
|
builder,
|
|
@@ -428,9 +438,12 @@ const generateCoreQuickMethod: GenerateCoreQuickMethod = ({
|
|
|
428
438
|
obligationInfo.obligationId
|
|
429
439
|
)) ?? [];
|
|
430
440
|
const updateCoinNames = [...obligationCoinNames, poolCoinName];
|
|
431
|
-
await updateOracles(
|
|
432
|
-
|
|
433
|
-
|
|
441
|
+
await updateOracles(
|
|
442
|
+
builder,
|
|
443
|
+
txBlock,
|
|
444
|
+
updateCoinNames,
|
|
445
|
+
updateOracleOptions
|
|
446
|
+
);
|
|
434
447
|
return txBlock.borrowWithReferral(
|
|
435
448
|
obligationInfo.obligationId,
|
|
436
449
|
obligationInfo.obligationKey as SuiObjectArg,
|
|
@@ -462,8 +475,13 @@ const generateCoreQuickMethod: GenerateCoreQuickMethod = ({
|
|
|
462
475
|
if (leftCoin) txBlock.transferObjects([leftCoin], sender);
|
|
463
476
|
return txBlock.repay(obligationInfo.obligationId, takeCoin, poolCoinName);
|
|
464
477
|
},
|
|
465
|
-
updateAssetPricesQuick: async (assetCoinNames) => {
|
|
466
|
-
return await updateOracles(
|
|
478
|
+
updateAssetPricesQuick: async (assetCoinNames, updateOracleOptions) => {
|
|
479
|
+
return await updateOracles(
|
|
480
|
+
builder,
|
|
481
|
+
txBlock,
|
|
482
|
+
assetCoinNames,
|
|
483
|
+
updateOracleOptions
|
|
484
|
+
);
|
|
467
485
|
},
|
|
468
486
|
};
|
|
469
487
|
};
|
|
@@ -99,12 +99,11 @@ export const updatePythPriceFeeds = async (
|
|
|
99
99
|
builder.address.get(`core.coins.${assetCoinName}.oracle.pyth.feed`)
|
|
100
100
|
);
|
|
101
101
|
|
|
102
|
-
// iterate through the endpoints
|
|
103
102
|
const endpoints = builder.utils.pythEndpoints ?? [
|
|
104
103
|
...builder.constants.whitelist.pythEndpoints,
|
|
105
104
|
];
|
|
106
105
|
|
|
107
|
-
//
|
|
106
|
+
// iterate through the endpoints
|
|
108
107
|
for (const endpoint of endpoints) {
|
|
109
108
|
try {
|
|
110
109
|
const pythConnection = new SuiPriceServiceConnection(endpoint);
|
|
@@ -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(
|
|
@@ -96,6 +96,7 @@ class ScallopBuilder implements ScallopBuilderInterface {
|
|
|
96
96
|
* @param assetCoinName - Specific support asset coin name.
|
|
97
97
|
* @param amount - Amount of coins to be selected.
|
|
98
98
|
* @param sender - Sender address.
|
|
99
|
+
* @param isSponsored - Whether the transaction is a sponsored transaction.
|
|
99
100
|
* @return Take coin and left coin.
|
|
100
101
|
*/
|
|
101
102
|
async selectCoin(
|
|
@@ -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,21 +87,32 @@ 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,
|
|
94
95
|
collateralCoinName: string,
|
|
95
96
|
obligationId?: SuiObjectArg,
|
|
96
97
|
obligationKey?: SuiObjectArg,
|
|
97
|
-
|
|
98
|
+
updateOracleOptions?: {
|
|
99
|
+
usePythPullModel?: boolean;
|
|
100
|
+
useOnChainXOracleList?: boolean;
|
|
101
|
+
sponsoredFeeds?: string[];
|
|
102
|
+
isSponsoredTx?: boolean;
|
|
103
|
+
}
|
|
98
104
|
) => Promise<TransactionResult>;
|
|
99
105
|
borrowQuick: (
|
|
100
106
|
amount: number,
|
|
101
107
|
poolCoinName: string,
|
|
102
108
|
obligationId?: SuiObjectArg,
|
|
103
109
|
obligationKey?: SuiObjectArg,
|
|
104
|
-
|
|
110
|
+
updateOracleOptions?: {
|
|
111
|
+
usePythPullModel?: boolean;
|
|
112
|
+
useOnChainXOracleList?: boolean;
|
|
113
|
+
sponsoredFeeds?: string[];
|
|
114
|
+
isSponsoredTx?: boolean;
|
|
115
|
+
}
|
|
105
116
|
) => Promise<TransactionResult>;
|
|
106
117
|
borrowWithReferralQuick: (
|
|
107
118
|
amount: number,
|
|
@@ -109,7 +120,12 @@ export type CoreQuickMethods = {
|
|
|
109
120
|
borrowReferral: SuiObjectArg,
|
|
110
121
|
obligationId?: SuiObjectArg,
|
|
111
122
|
obligationKey?: SuiObjectArg,
|
|
112
|
-
|
|
123
|
+
updateOracleOptions?: {
|
|
124
|
+
usePythPullModel?: boolean;
|
|
125
|
+
useOnChainXOracleList?: boolean;
|
|
126
|
+
sponsoredFeeds?: string[];
|
|
127
|
+
isSponsoredTx?: boolean;
|
|
128
|
+
}
|
|
113
129
|
) => Promise<TransactionResult>;
|
|
114
130
|
depositQuick: (
|
|
115
131
|
amount: number,
|
|
@@ -126,7 +142,15 @@ export type CoreQuickMethods = {
|
|
|
126
142
|
obligationId?: SuiObjectArg,
|
|
127
143
|
isSponsoredTx?: boolean
|
|
128
144
|
) => Promise<void>;
|
|
129
|
-
updateAssetPricesQuick: (
|
|
145
|
+
updateAssetPricesQuick: (
|
|
146
|
+
assetCoinNames?: string[],
|
|
147
|
+
updateOracleOptions?: {
|
|
148
|
+
usePythPullModel?: boolean;
|
|
149
|
+
useOnChainXOracleList?: boolean;
|
|
150
|
+
sponsoredFeeds?: string[];
|
|
151
|
+
isSponsoredTx?: boolean;
|
|
152
|
+
}
|
|
153
|
+
) => Promise<void>;
|
|
130
154
|
};
|
|
131
155
|
|
|
132
156
|
export type SuiTxBlockWithCoreNormalMethods = SuiKitTxBlock &
|