@scallop-io/sui-scallop-sdk 0.46.42 → 0.46.44

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.
@@ -2,7 +2,7 @@ import type { SuiTxBlock as SuiKitTxBlock, SuiAddressArg, SuiObjectArg, SuiTxArg
2
2
  import type { TransactionArgument, TransactionResult } from '@mysten/sui.js/transactions';
3
3
  import type { ScallopBuilder } from '../../models';
4
4
  import type { SupportCollateralCoins, SupportPoolCoins, SupportAssetCoins } from '../constant';
5
- import { ScallopTxBlockWithoutCoreTxBlock } from '.';
5
+ import { SuiTxBlockWithSpool } from '.';
6
6
  export type CoreIds = {
7
7
  protocolPkg: string;
8
8
  market: string;
@@ -43,7 +43,7 @@ export type CoreQuickMethods = {
43
43
  repayQuick: (amount: number, poolCoinName: SupportPoolCoins, obligationId?: SuiAddressArg) => Promise<void>;
44
44
  updateAssetPricesQuick: (assetCoinNames?: SupportAssetCoins[]) => Promise<void>;
45
45
  };
46
- export type SuiTxBlockWithCoreNormalMethods = SuiKitTxBlock & ScallopTxBlockWithoutCoreTxBlock & CoreNormalMethods;
46
+ export type SuiTxBlockWithCoreNormalMethods = SuiKitTxBlock & SuiTxBlockWithSpool & CoreNormalMethods;
47
47
  export type CoreTxBlock = SuiTxBlockWithCoreNormalMethods & CoreQuickMethods;
48
48
  export type GenerateCoreNormalMethod = (params: {
49
49
  builder: ScallopBuilder;
@@ -12,6 +12,6 @@ export type * from './vesca';
12
12
  export type * from './loyaltyProgram';
13
13
  export type * from './sCoin';
14
14
  export type BaseScallopTxBlock = ReferralTxBlock & LoyaltyProgramTxBlock & BorrowIncentiveTxBlock & VeScaTxBlock;
15
- export type ScallopTxBlockWithoutSCoinTxBlock = SpoolTxBlock & BaseScallopTxBlock;
16
- export type ScallopTxBlockWithoutCoreTxBlock = SCoinTxBlock & ScallopTxBlockWithoutSCoinTxBlock;
17
- export type ScallopTxBlock = CoreTxBlock & ScallopTxBlockWithoutCoreTxBlock;
15
+ export type SuiTxBlockWithSCoin = BaseScallopTxBlock & SCoinTxBlock;
16
+ export type SuiTxBlockWithSpool = SuiTxBlockWithSCoin & SpoolTxBlock;
17
+ export type ScallopTxBlock = SuiTxBlockWithSpool & CoreTxBlock;
@@ -1,7 +1,7 @@
1
1
  import { SuiObjectArg, SuiTxBlock as SuiKitTxBlock, TransactionResult } from '@scallop-io/sui-kit';
2
2
  import { SupportSCoin } from '../constant';
3
3
  import { ScallopBuilder } from 'src/models';
4
- import { ScallopTxBlockWithoutSCoinTxBlock } from '.';
4
+ import { BaseScallopTxBlock } from '.';
5
5
  export type sCoinPkgIds = {
6
6
  pkgId: string;
7
7
  };
@@ -25,7 +25,7 @@ export type sCoinQuickMethods = {
25
25
  mintSCoinQuick: (marketCoinName: SupportSCoin, amount: number) => Promise<TransactionResult>;
26
26
  burnSCoinQuick: (sCoinName: SupportSCoin, amount: number) => Promise<TransactionResult>;
27
27
  };
28
- export type SuiTxBlockWithSCoinNormalMethods = SuiKitTxBlock & ScallopTxBlockWithoutSCoinTxBlock & sCoinNormalMethods;
28
+ export type SuiTxBlockWithSCoinNormalMethods = SuiKitTxBlock & BaseScallopTxBlock & sCoinNormalMethods;
29
29
  export type SCoinTxBlock = SuiTxBlockWithSCoinNormalMethods & sCoinQuickMethods;
30
30
  export type GenerateSCoinNormalMethod = (params: {
31
31
  builder: ScallopBuilder;
@@ -2,7 +2,7 @@ import type { SuiTxBlock as SuiKitTxBlock, SuiAddressArg, SuiObjectArg, SuiTxArg
2
2
  import type { TransactionResult } from '@mysten/sui.js/transactions';
3
3
  import type { ScallopBuilder } from '../../models';
4
4
  import type { SupportStakeMarketCoins } from '../constant';
5
- import { BaseScallopTxBlock } from '.';
5
+ import { SuiTxBlockWithSCoin } from '.';
6
6
  export type SpoolIds = {
7
7
  spoolPkg: string;
8
8
  };
@@ -14,10 +14,10 @@ export type SpoolNormalMethods = {
14
14
  };
15
15
  export type SpoolQuickMethods = {
16
16
  stakeQuick(amountOrMarketCoin: SuiObjectArg | number, stakeMarketCoinName: SupportStakeMarketCoins, stakeAccountId?: SuiAddressArg): Promise<void>;
17
- unstakeQuick(amount: number, stakeMarketCoinName: SupportStakeMarketCoins, stakeAccountId?: SuiAddressArg): Promise<TransactionResult[]>;
17
+ unstakeQuick(amount: number, stakeMarketCoinName: SupportStakeMarketCoins, stakeAccountId?: SuiAddressArg): Promise<TransactionResult>;
18
18
  claimQuick(stakeMarketCoinName: SupportStakeMarketCoins, stakeAccountId?: SuiAddressArg): Promise<TransactionResult[]>;
19
19
  };
20
- export type SuiTxBlockWithSpoolNormalMethods = SuiKitTxBlock & BaseScallopTxBlock & SpoolNormalMethods;
20
+ export type SuiTxBlockWithSpoolNormalMethods = SuiKitTxBlock & SuiTxBlockWithSCoin & SpoolNormalMethods;
21
21
  export type SpoolTxBlock = SuiTxBlockWithSpoolNormalMethods & SpoolQuickMethods;
22
22
  export type GenerateSpoolNormalMethod = (params: {
23
23
  builder: ScallopBuilder;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scallop-io/sui-scallop-sdk",
3
- "version": "0.46.42",
3
+ "version": "0.46.44",
4
4
  "description": "Typescript sdk for interacting with Scallop contract on SUI",
5
5
  "keywords": [
6
6
  "sui",
@@ -14,6 +14,7 @@ import type {
14
14
  CoreTxBlock,
15
15
  ScallopTxBlock,
16
16
  NestedResult,
17
+ SuiTxBlockWithSpool,
17
18
  } from '../types';
18
19
 
19
20
  /**
@@ -473,7 +474,11 @@ const generateCoreQuickMethod: GenerateCoreQuickMethod = ({
473
474
  */
474
475
  export const newCoreTxBlock = (
475
476
  builder: ScallopBuilder,
476
- initTxBlock?: ScallopTxBlock | SuiKitTxBlock | TransactionBlock
477
+ initTxBlock?:
478
+ | ScallopTxBlock
479
+ | SuiKitTxBlock
480
+ | TransactionBlock
481
+ | SuiTxBlockWithSpool
477
482
  ) => {
478
483
  const txBlock =
479
484
  initTxBlock instanceof TransactionBlock
@@ -28,9 +28,9 @@ export const newScallopTxBlock = (
28
28
  loyaltyTxBlock
29
29
  );
30
30
  const referralTxBlock = newReferralTxBlock(builder, borrowIncentiveTxBlock);
31
- const spoolTxBlock = newSpoolTxBlock(builder, referralTxBlock);
32
- const sCoinTxBlock = newSCoinTxBlock(builder, spoolTxBlock);
33
- const coreTxBlock = newCoreTxBlock(builder, sCoinTxBlock);
31
+ const sCoinTxBlock = newSCoinTxBlock(builder, referralTxBlock);
32
+ const spoolTxBlock = newSpoolTxBlock(builder, sCoinTxBlock);
33
+ const coreTxBlock = newCoreTxBlock(builder, spoolTxBlock);
34
34
 
35
35
  return new Proxy(coreTxBlock, {
36
36
  get: (target, prop) => {
@@ -4,6 +4,7 @@ import {
4
4
  } from '@scallop-io/sui-kit';
5
5
  import { ScallopBuilder } from 'src/models';
6
6
  import {
7
+ BaseScallopTxBlock,
7
8
  GenerateSCoinNormalMethod,
8
9
  GenerateSCoinQuickMethod,
9
10
  SCoinTxBlock,
@@ -79,7 +80,11 @@ const generateSCoinQuickMethod: GenerateSCoinQuickMethod = ({
79
80
 
80
81
  export const newSCoinTxBlock = (
81
82
  builder: ScallopBuilder,
82
- initTxBlock?: ScallopTxBlock | SuiKitTxBlock | TransactionBlock
83
+ initTxBlock?:
84
+ | ScallopTxBlock
85
+ | SuiKitTxBlock
86
+ | TransactionBlock
87
+ | BaseScallopTxBlock
83
88
  ) => {
84
89
  const txBlock =
85
90
  initTxBlock instanceof TransactionBlock
@@ -15,6 +15,7 @@ import type {
15
15
  SpoolTxBlock,
16
16
  SupportStakeMarketCoins,
17
17
  ScallopTxBlock,
18
+ SuiTxBlockWithSCoin,
18
19
  } from '../types';
19
20
 
20
21
  /**
@@ -85,6 +86,32 @@ const requireStakeAccounts = async (
85
86
  return specificStakeAccounts;
86
87
  };
87
88
 
89
+ const stakeHelper = async (
90
+ builder: ScallopBuilder,
91
+ txBlock: SuiTxBlockWithSpoolNormalMethods,
92
+ stakeAccount: SuiAddressArg,
93
+ coinType: string,
94
+ coinName: SupportStakeMarketCoins,
95
+ amount: number,
96
+ sender: string,
97
+ isSCoin: boolean = false
98
+ ) => {
99
+ try {
100
+ const coins = await builder.utils.selectCoins(amount, coinType, sender);
101
+ const [takeCoin, leftCoin] = txBlock.takeAmountFromCoins(coins, amount);
102
+ if (isSCoin) {
103
+ const marketCoin = txBlock.burnSCoin(coinName, takeCoin);
104
+ txBlock.stake(stakeAccount, marketCoin, coinName);
105
+ } else {
106
+ txBlock.stake(stakeAccount, takeCoin, coinName);
107
+ }
108
+ txBlock.transferObjects([leftCoin], sender);
109
+ return true;
110
+ } catch (e) {
111
+ return false;
112
+ }
113
+ };
114
+
88
115
  /**
89
116
  * Generate spool normal methods.
90
117
  *
@@ -188,18 +215,32 @@ const generateSpoolQuickMethod: GenerateSpoolQuickMethod = ({
188
215
 
189
216
  const marketCoinType =
190
217
  builder.utils.parseMarketCoinType(stakeMarketCoinName);
218
+ const sCoinType = builder.utils.parseSCoinType(stakeMarketCoinName);
191
219
  if (typeof amountOrMarketCoin === 'number') {
192
- const coins = await builder.utils.selectCoins(
193
- amountOrMarketCoin,
220
+ // try stake market coin
221
+ const stakeMarketCoinRes = await stakeHelper(
222
+ builder,
223
+ txBlock,
224
+ stakeAccountIds[0],
194
225
  marketCoinType,
226
+ stakeMarketCoinName,
227
+ amountOrMarketCoin,
195
228
  sender
196
229
  );
197
- const [takeCoin, leftCoin] = txBlock.takeAmountFromCoins(
198
- coins,
199
- amountOrMarketCoin
200
- );
201
- txBlock.stake(stakeAccountIds[0], takeCoin, stakeMarketCoinName);
202
- txBlock.transferObjects([leftCoin], sender);
230
+
231
+ // no market coin, try sCoin
232
+ if (!stakeMarketCoinRes) {
233
+ await stakeHelper(
234
+ builder,
235
+ txBlock,
236
+ stakeAccountIds[0],
237
+ sCoinType,
238
+ stakeMarketCoinName,
239
+ amountOrMarketCoin,
240
+ sender,
241
+ true
242
+ );
243
+ }
203
244
  } else {
204
245
  txBlock.stake(
205
246
  stakeAccountIds[0],
@@ -215,7 +256,7 @@ const generateSpoolQuickMethod: GenerateSpoolQuickMethod = ({
215
256
  stakeMarketCoinName,
216
257
  stakeAccountId
217
258
  );
218
- const stakeMarketCoins: TransactionResult[] = [];
259
+ const sCoins: TransactionResult[] = [];
219
260
  for (const account of stakeAccounts) {
220
261
  if (account.staked === 0) continue;
221
262
  const amountToUnstake = Math.min(amount, account.staked);
@@ -224,11 +265,34 @@ const generateSpoolQuickMethod: GenerateSpoolQuickMethod = ({
224
265
  amountToUnstake,
225
266
  stakeMarketCoinName
226
267
  );
227
- stakeMarketCoins.push(marketCoin);
268
+
269
+ // convert to new sCoin
270
+ const sCoin = txBlock.mintSCoin(stakeMarketCoinName, marketCoin);
271
+ sCoins.push(sCoin);
228
272
  amount -= amountToUnstake;
229
273
  if (amount === 0) break;
230
274
  }
231
- return stakeMarketCoins;
275
+
276
+ const mergedSCoin = sCoins[0];
277
+ if (sCoins.length > 1) {
278
+ txBlock.mergeCoins(mergedSCoin, sCoins.slice(1));
279
+ }
280
+
281
+ // check for existing sCoins
282
+ try {
283
+ const existingCoins = await builder.utils.selectCoins(
284
+ Number.MAX_SAFE_INTEGER,
285
+ builder.utils.parseSCoinType(stakeMarketCoinName),
286
+ requireSender(txBlock)
287
+ );
288
+
289
+ if (existingCoins.length > 0) {
290
+ txBlock.mergeCoins(mergedSCoin, existingCoins);
291
+ }
292
+ } catch (e) {
293
+ // ignore
294
+ }
295
+ return mergedSCoin;
232
296
  },
233
297
  claimQuick: async (stakeMarketCoinName, stakeAccountId) => {
234
298
  const stakeAccountIds = await requireStakeAccountIds(
@@ -256,7 +320,11 @@ const generateSpoolQuickMethod: GenerateSpoolQuickMethod = ({
256
320
  */
257
321
  export const newSpoolTxBlock = (
258
322
  builder: ScallopBuilder,
259
- initTxBlock?: ScallopTxBlock | SuiKitTxBlock | TransactionBlock
323
+ initTxBlock?:
324
+ | ScallopTxBlock
325
+ | SuiKitTxBlock
326
+ | TransactionBlock
327
+ | SuiTxBlockWithSCoin
260
328
  ) => {
261
329
  const txBlock =
262
330
  initTxBlock instanceof TransactionBlock
@@ -364,8 +364,8 @@ export class ScallopClient {
364
364
  const sender = walletAddress || this.walletAddress;
365
365
  txBlock.setSender(sender);
366
366
 
367
- const marketCoin = await txBlock.depositQuick(amount, poolCoinName);
368
- txBlock.transferObjects([marketCoin], sender);
367
+ const sCoin = await txBlock.depositQuick(amount, poolCoinName);
368
+ txBlock.transferObjects([sCoin], sender);
369
369
 
370
370
  if (sign) {
371
371
  return (await this.suiKit.signAndSendTxn(
@@ -414,7 +414,7 @@ export class ScallopClient {
414
414
  await this.query.getStakeAccounts(stakeMarketCoinName);
415
415
  const targetStakeAccount = stakeAccountId || stakeAccounts[0].id;
416
416
 
417
- const marketCoin = await txBlock.depositQuick(amount, stakeCoinName);
417
+ const marketCoin = await txBlock.depositQuick(amount, stakeCoinName, false);
418
418
  if (targetStakeAccount) {
419
419
  await txBlock.stakeQuick(
420
420
  marketCoin,
@@ -219,7 +219,9 @@ export const getLending = async (
219
219
  const marketCoinPrice = BigNumber(coinPrice ?? 0).multipliedBy(
220
220
  marketPool?.conversionRate ?? 1
221
221
  );
222
- const unstakedMarketAmount = BigNumber(marketCoinAmount);
222
+ const unstakedMarketAmount = BigNumber(marketCoinAmount).plus(
223
+ BigNumber(sCoinAmount)
224
+ );
223
225
  const unstakedMarketCoin = unstakedMarketAmount.shiftedBy(-1 * coinDecimal);
224
226
 
225
227
  const availableSupplyAmount = BigNumber(coinAmount);
@@ -14,7 +14,7 @@ import type {
14
14
  SupportPoolCoins,
15
15
  SupportAssetCoins,
16
16
  } from '../constant';
17
- import { ScallopTxBlockWithoutCoreTxBlock } from '.';
17
+ import { SuiTxBlockWithSpool } from '.';
18
18
 
19
19
  export type CoreIds = {
20
20
  protocolPkg: string;
@@ -143,7 +143,7 @@ export type CoreQuickMethods = {
143
143
  };
144
144
 
145
145
  export type SuiTxBlockWithCoreNormalMethods = SuiKitTxBlock &
146
- ScallopTxBlockWithoutCoreTxBlock &
146
+ SuiTxBlockWithSpool &
147
147
  CoreNormalMethods;
148
148
 
149
149
  export type CoreTxBlock = SuiTxBlockWithCoreNormalMethods & CoreQuickMethods;
@@ -18,10 +18,6 @@ export type BaseScallopTxBlock = ReferralTxBlock &
18
18
  BorrowIncentiveTxBlock &
19
19
  VeScaTxBlock;
20
20
 
21
- export type ScallopTxBlockWithoutSCoinTxBlock = SpoolTxBlock &
22
- BaseScallopTxBlock;
23
-
24
- export type ScallopTxBlockWithoutCoreTxBlock = SCoinTxBlock &
25
- ScallopTxBlockWithoutSCoinTxBlock;
26
-
27
- export type ScallopTxBlock = CoreTxBlock & ScallopTxBlockWithoutCoreTxBlock;
21
+ export type SuiTxBlockWithSCoin = BaseScallopTxBlock & SCoinTxBlock;
22
+ export type SuiTxBlockWithSpool = SuiTxBlockWithSCoin & SpoolTxBlock;
23
+ export type ScallopTxBlock = SuiTxBlockWithSpool & CoreTxBlock;
@@ -5,7 +5,7 @@ import {
5
5
  } from '@scallop-io/sui-kit';
6
6
  import { SupportSCoin } from '../constant';
7
7
  import { ScallopBuilder } from 'src/models';
8
- import { ScallopTxBlockWithoutSCoinTxBlock } from '.';
8
+ import { BaseScallopTxBlock } from '.';
9
9
 
10
10
  export type sCoinPkgIds = {
11
11
  pkgId: string;
@@ -46,7 +46,7 @@ export type sCoinQuickMethods = {
46
46
  };
47
47
 
48
48
  export type SuiTxBlockWithSCoinNormalMethods = SuiKitTxBlock &
49
- ScallopTxBlockWithoutSCoinTxBlock &
49
+ BaseScallopTxBlock &
50
50
  sCoinNormalMethods;
51
51
  export type SCoinTxBlock = SuiTxBlockWithSCoinNormalMethods & sCoinQuickMethods;
52
52
 
@@ -7,7 +7,7 @@ import type {
7
7
  import type { TransactionResult } from '@mysten/sui.js/transactions';
8
8
  import type { ScallopBuilder } from '../../models';
9
9
  import type { SupportStakeMarketCoins } from '../constant';
10
- import { BaseScallopTxBlock } from '.';
10
+ import { SuiTxBlockWithSCoin } from '.';
11
11
 
12
12
  export type SpoolIds = {
13
13
  spoolPkg: string;
@@ -43,7 +43,7 @@ export type SpoolQuickMethods = {
43
43
  amount: number,
44
44
  stakeMarketCoinName: SupportStakeMarketCoins,
45
45
  stakeAccountId?: SuiAddressArg
46
- ): Promise<TransactionResult[]>;
46
+ ): Promise<TransactionResult>;
47
47
  claimQuick(
48
48
  stakeMarketCoinName: SupportStakeMarketCoins,
49
49
  stakeAccountId?: SuiAddressArg
@@ -51,7 +51,7 @@ export type SpoolQuickMethods = {
51
51
  };
52
52
 
53
53
  export type SuiTxBlockWithSpoolNormalMethods = SuiKitTxBlock &
54
- BaseScallopTxBlock &
54
+ SuiTxBlockWithSCoin &
55
55
  SpoolNormalMethods;
56
56
 
57
57
  export type SpoolTxBlock = SuiTxBlockWithSpoolNormalMethods & SpoolQuickMethods;