@scallop-io/sui-scallop-sdk 2.2.3-pyth-sponsored-transaction-alpha.1 → 2.2.3-pyth-sponsored-transaction-alpha.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scallop-io/sui-scallop-sdk",
3
- "version": "2.2.3-pyth-sponsored-transaction-alpha.1",
3
+ "version": "2.2.3-pyth-sponsored-transaction-alpha.2",
4
4
  "description": "Typescript sdk for interacting with Scallop contract on SUI",
5
5
  "keywords": [
6
6
  "sui",
@@ -438,7 +438,12 @@ const generateCoreQuickMethod: GenerateCoreQuickMethod = ({
438
438
  poolCoinName
439
439
  );
440
440
  },
441
- repayQuick: async (amount, poolCoinName, obligationId) => {
441
+ repayQuick: async (
442
+ amount,
443
+ poolCoinName,
444
+ obligationId,
445
+ isSponsoredTx = false
446
+ ) => {
442
447
  const sender = requireSender(txBlock);
443
448
  const obligationInfo = await requireObligationInfo(
444
449
  builder,
@@ -446,27 +451,15 @@ const generateCoreQuickMethod: GenerateCoreQuickMethod = ({
446
451
  obligationId
447
452
  );
448
453
 
449
- if (poolCoinName === 'sui') {
450
- const [suiCoin] = txBlock.splitSUIFromGas([amount]);
451
- return txBlock.repay(
452
- obligationInfo.obligationId,
453
- suiCoin,
454
- poolCoinName
455
- );
456
- } else {
457
- const { leftCoin, takeCoin } = await builder.selectCoin(
458
- txBlock,
459
- poolCoinName,
460
- amount,
461
- sender
462
- );
463
- txBlock.transferObjects([leftCoin], sender);
464
- return txBlock.repay(
465
- obligationInfo.obligationId,
466
- takeCoin,
467
- poolCoinName
468
- );
469
- }
454
+ const { leftCoin, takeCoin } = await builder.selectCoin(
455
+ txBlock,
456
+ poolCoinName,
457
+ amount,
458
+ sender,
459
+ isSponsoredTx
460
+ );
461
+ if (leftCoin) txBlock.transferObjects([leftCoin], sender);
462
+ return txBlock.repay(obligationInfo.obligationId, takeCoin, poolCoinName);
470
463
  },
471
464
  updateAssetPricesQuick: async (assetCoinNames) => {
472
465
  return await updateOracles(builder, txBlock, assetCoinNames);
@@ -12,7 +12,7 @@ import type {
12
12
  SuiTxArg,
13
13
  SuiVecTxArg,
14
14
  } from '@scallop-io/sui-kit';
15
- import type { ScallopTxBlock, SelectCoinReturnType } from '../types';
15
+ import type { ScallopTxBlock } from '../types';
16
16
  import { ScallopBuilderInterface } from './interface';
17
17
 
18
18
  export type ScallopBuilderParams = {
@@ -98,20 +98,22 @@ class ScallopBuilder implements ScallopBuilderInterface {
98
98
  * @param sender - Sender address.
99
99
  * @return Take coin and left coin.
100
100
  */
101
- async selectCoin<T extends string>(
101
+ async selectCoin(
102
102
  txBlock: ScallopTxBlock | SuiKitTxBlock,
103
- assetCoinName: T,
103
+ assetCoinName: string,
104
104
  amount: number,
105
- sender: string = this.walletAddress
106
- ): Promise<SelectCoinReturnType<T>> {
107
- if (assetCoinName === 'sui') {
105
+ sender: string = this.walletAddress,
106
+ isSponsored: boolean = false
107
+ ) {
108
+ if (assetCoinName === 'sui' && !isSponsored) {
108
109
  const [takeCoin] = txBlock.splitSUIFromGas([amount]);
109
- return { takeCoin } as SelectCoinReturnType<T>;
110
+ return { takeCoin };
110
111
  } else {
111
112
  const coinType = this.utils.parseCoinType(assetCoinName);
112
113
  const coins = await this.utils.selectCoins(amount, coinType, sender);
113
114
  const [takeCoin, leftCoin] = txBlock.takeAmountFromCoins(coins, amount);
114
- return { takeCoin, leftCoin } as SelectCoinReturnType<T>;
115
+
116
+ return { takeCoin, leftCoin };
115
117
  }
116
118
  }
117
119
 
@@ -122,7 +122,8 @@ export type CoreQuickMethods = {
122
122
  repayQuick: (
123
123
  amount: number,
124
124
  poolCoinName: string,
125
- obligationId?: SuiObjectArg
125
+ obligationId?: SuiObjectArg,
126
+ isSponsoredTx?: boolean
126
127
  ) => Promise<void>;
127
128
  updateAssetPricesQuick: (assetCoinNames?: string[]) => Promise<void>;
128
129
  };
@@ -1,4 +1,4 @@
1
- import type { CoreTxBlock, NestedResult } from './core';
1
+ import type { CoreTxBlock } from './core';
2
2
  import type { SpoolTxBlock } from './spool';
3
3
  import type { BorrowIncentiveTxBlock } from './borrowIncentive';
4
4
  import type { VeScaTxBlock } from './vesca';
@@ -21,12 +21,3 @@ export type BaseScallopTxBlock = ReferralTxBlock &
21
21
  export type SuiTxBlockWithSCoin = BaseScallopTxBlock & SCoinTxBlock;
22
22
  export type SuiTxBlockWithSpool = SuiTxBlockWithSCoin & SpoolTxBlock;
23
23
  export type ScallopTxBlock = SuiTxBlockWithSpool & CoreTxBlock;
24
-
25
- export type SelectCoinReturnType<T extends string> = T extends 'sui'
26
- ? {
27
- takeCoin: NestedResult;
28
- }
29
- : {
30
- takeCoin: NestedResult;
31
- leftCoin: NestedResult;
32
- };