@scallop-io/sui-scallop-sdk 2.2.2 → 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.2",
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",
@@ -382,7 +382,13 @@ const generateCoreQuickMethod: GenerateCoreQuickMethod = ({
382
382
  if (!marketCoin) throw new Error(`No market coin for ${poolCoinName}`);
383
383
  return txBlock.withdraw(marketCoin, poolCoinName);
384
384
  },
385
- borrowQuick: async (amount, poolCoinName, obligationId, obligationKey) => {
385
+ borrowQuick: async (
386
+ amount,
387
+ poolCoinName,
388
+ obligationId,
389
+ obligationKey,
390
+ isSponsoredTx = false
391
+ ) => {
386
392
  const obligationInfo = await requireObligationInfo(
387
393
  builder,
388
394
  txBlock,
@@ -394,7 +400,7 @@ const generateCoreQuickMethod: GenerateCoreQuickMethod = ({
394
400
  obligationInfo.obligationId
395
401
  )) ?? [];
396
402
  const updateCoinNames = [...obligationCoinNames, poolCoinName];
397
- await updateOracles(builder, txBlock, updateCoinNames);
403
+ await updateOracles(builder, txBlock, updateCoinNames, { isSponsoredTx });
398
404
  return txBlock.borrow(
399
405
  obligationInfo.obligationId,
400
406
  obligationInfo.obligationKey as SuiObjectArg,
@@ -407,7 +413,8 @@ const generateCoreQuickMethod: GenerateCoreQuickMethod = ({
407
413
  poolCoinName,
408
414
  borrowReferral,
409
415
  obligationId,
410
- obligationKey
416
+ obligationKey,
417
+ isSponsoredTx = false
411
418
  ) => {
412
419
  const obligationInfo = await requireObligationInfo(
413
420
  builder,
@@ -420,7 +427,9 @@ const generateCoreQuickMethod: GenerateCoreQuickMethod = ({
420
427
  obligationInfo.obligationId
421
428
  )) ?? [];
422
429
  const updateCoinNames = [...obligationCoinNames, poolCoinName];
423
- await updateOracles(builder, txBlock, updateCoinNames);
430
+ await updateOracles(builder, txBlock, updateCoinNames, {
431
+ isSponsoredTx,
432
+ });
424
433
  return txBlock.borrowWithReferral(
425
434
  obligationInfo.obligationId,
426
435
  obligationInfo.obligationKey as SuiObjectArg,
@@ -429,7 +438,12 @@ const generateCoreQuickMethod: GenerateCoreQuickMethod = ({
429
438
  poolCoinName
430
439
  );
431
440
  },
432
- repayQuick: async (amount, poolCoinName, obligationId) => {
441
+ repayQuick: async (
442
+ amount,
443
+ poolCoinName,
444
+ obligationId,
445
+ isSponsoredTx = false
446
+ ) => {
433
447
  const sender = requireSender(txBlock);
434
448
  const obligationInfo = await requireObligationInfo(
435
449
  builder,
@@ -437,27 +451,15 @@ const generateCoreQuickMethod: GenerateCoreQuickMethod = ({
437
451
  obligationId
438
452
  );
439
453
 
440
- if (poolCoinName === 'sui') {
441
- const [suiCoin] = txBlock.splitSUIFromGas([amount]);
442
- return txBlock.repay(
443
- obligationInfo.obligationId,
444
- suiCoin,
445
- poolCoinName
446
- );
447
- } else {
448
- const { leftCoin, takeCoin } = await builder.selectCoin(
449
- txBlock,
450
- poolCoinName,
451
- amount,
452
- sender
453
- );
454
- txBlock.transferObjects([leftCoin], sender);
455
- return txBlock.repay(
456
- obligationInfo.obligationId,
457
- takeCoin,
458
- poolCoinName
459
- );
460
- }
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);
461
463
  },
462
464
  updateAssetPricesQuick: async (assetCoinNames) => {
463
465
  return await updateOracles(builder, txBlock, assetCoinNames);
@@ -22,19 +22,21 @@ export const updateOracles = async (
22
22
  builder: ScallopBuilder,
23
23
  txBlock: SuiKitTxBlock,
24
24
  assetCoinNames: string[] = [...builder.constants.whitelist.lending],
25
- options: {
26
- usePythPullModel: boolean;
27
- useOnChainXOracleList: boolean;
28
- sponsoredFeeds: string[];
29
- } = {
30
- usePythPullModel: true,
31
- useOnChainXOracleList: true,
32
- sponsoredFeeds: [],
25
+ options?: {
26
+ usePythPullModel?: boolean;
27
+ useOnChainXOracleList?: boolean;
28
+ sponsoredFeeds?: string[];
29
+ isSponsoredTx?: boolean;
33
30
  }
34
31
  ) => {
32
+ const usePythPullModel =
33
+ options?.usePythPullModel ?? builder.usePythPullModel;
34
+ const useOnChainXOracleList =
35
+ options?.useOnChainXOracleList ?? builder.useOnChainXOracleList;
35
36
  const sponsoredFeeds = new Set(
36
- builder.sponsoredFeeds ?? options.sponsoredFeeds
37
+ options?.sponsoredFeeds ?? builder.sponsoredFeeds
37
38
  );
39
+ const isSponsoredTx = options?.isSponsoredTx ?? false;
38
40
 
39
41
  // Validate the sponsoredFeeds content.
40
42
  sponsoredFeeds.forEach((feed) => {
@@ -43,10 +45,6 @@ export const updateOracles = async (
43
45
  }
44
46
  });
45
47
 
46
- const usePythPullModel = builder.usePythPullModel ?? options.usePythPullModel;
47
- const useOnChainXOracleList =
48
- builder.useOnChainXOracleList ?? options.useOnChainXOracleList;
49
-
50
48
  const xOracleList = useOnChainXOracleList
51
49
  ? await builder.query.getAssetOracles()
52
50
  : X_ORACLE_LIST;
@@ -92,7 +90,12 @@ export const updateOracles = async (
92
90
  }
93
91
 
94
92
  if (needToUpdatePythPriceFeeds.length > 0) {
95
- await updatePythPriceFeeds(builder, needToUpdatePythPriceFeeds, txBlock);
93
+ await updatePythPriceFeeds(
94
+ builder,
95
+ needToUpdatePythPriceFeeds,
96
+ txBlock,
97
+ isSponsoredTx
98
+ );
96
99
  }
97
100
  }
98
101
 
@@ -8,12 +8,19 @@ import type { SuiTxBlock as SuiKitTxBlock } from '@scallop-io/sui-kit';
8
8
  export const updatePythPriceFeeds = async (
9
9
  builder: ScallopBuilder,
10
10
  assetCoinNames: string[],
11
- txBlock: SuiKitTxBlock
11
+ txBlock: SuiKitTxBlock,
12
+ isSponsoredTx: boolean = false
12
13
  ) => {
13
14
  const pythClient = new SuiPythClient(
14
15
  builder.suiKit.client,
15
16
  builder.address.get('core.oracles.pyth.state'),
16
- builder.address.get('core.oracles.pyth.wormholeState')
17
+ builder.address.get('core.oracles.pyth.wormholeState'),
18
+ {
19
+ defaultPackageId:
20
+ '0xa6f9bec2f9748656b6af8aafb5d7bc1a0d5faf25ac9645fc7f447822cd509325',
21
+ gasStationId:
22
+ '0xa8b8dcc9880166edb57b53e05f8df7364d31b5d9b7d107fd27f0b69cf338b687',
23
+ }
17
24
  );
18
25
  const priceIds = assetCoinNames.map((assetCoinName) =>
19
26
  builder.address.get(`core.coins.${assetCoinName}.oracle.pyth.feed`)
@@ -29,9 +36,10 @@ export const updatePythPriceFeeds = async (
29
36
  const priceUpdateData =
30
37
  await pythConnection.getPriceFeedsUpdateData(priceIds);
31
38
  await pythClient.updatePriceFeeds(
32
- txBlock.txBlock, // convert txBlock to TransactionBlock because pyth sdk not support new @mysten/sui yet
39
+ txBlock.txBlock,
33
40
  priceUpdateData,
34
- priceIds
41
+ priceIds,
42
+ isSponsoredTx
35
43
  );
36
44
 
37
45
  break;
@@ -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
 
@@ -99,14 +99,16 @@ export type CoreQuickMethods = {
99
99
  amount: number,
100
100
  poolCoinName: string,
101
101
  obligationId?: SuiObjectArg,
102
- obligationKey?: SuiObjectArg
102
+ obligationKey?: SuiObjectArg,
103
+ isSponsoredTx?: boolean
103
104
  ) => Promise<TransactionResult>;
104
105
  borrowWithReferralQuick: (
105
106
  amount: number,
106
107
  poolCoinName: string,
107
108
  borrowReferral: SuiObjectArg,
108
109
  obligationId?: SuiObjectArg,
109
- obligationKey?: SuiObjectArg
110
+ obligationKey?: SuiObjectArg,
111
+ isSponsoredTx?: boolean
110
112
  ) => Promise<TransactionResult>;
111
113
  depositQuick: (
112
114
  amount: number,
@@ -120,7 +122,8 @@ export type CoreQuickMethods = {
120
122
  repayQuick: (
121
123
  amount: number,
122
124
  poolCoinName: string,
123
- obligationId?: SuiObjectArg
125
+ obligationId?: SuiObjectArg,
126
+ isSponsoredTx?: boolean
124
127
  ) => Promise<void>;
125
128
  updateAssetPricesQuick: (assetCoinNames?: string[]) => Promise<void>;
126
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
- };