@scallop-io/sui-scallop-sdk 0.46.43 → 0.46.45
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/builders/coreBuilder.d.ts +2 -2
- package/dist/builders/sCoinBuilder.d.ts +2 -2
- package/dist/builders/spoolBuilder.d.ts +2 -2
- package/dist/index.js +65 -33
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +65 -33
- package/dist/index.mjs.map +1 -1
- package/dist/types/builder/core.d.ts +2 -2
- package/dist/types/builder/index.d.ts +3 -3
- package/dist/types/builder/sCoin.d.ts +2 -2
- package/dist/types/builder/spool.d.ts +3 -3
- package/package.json +1 -1
- package/src/builders/coreBuilder.ts +6 -1
- package/src/builders/index.ts +3 -3
- package/src/builders/sCoinBuilder.ts +6 -1
- package/src/builders/spoolBuilder.ts +80 -12
- package/src/models/scallopClient.ts +9 -20
- package/src/types/builder/core.ts +2 -2
- package/src/types/builder/index.ts +3 -7
- package/src/types/builder/sCoin.ts +2 -2
- package/src/types/builder/spool.ts +3 -3
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { TransactionBlock } from '@mysten/sui.js/transactions';
|
|
2
2
|
import { SuiTxBlock as SuiKitTxBlock } from '@scallop-io/sui-kit';
|
|
3
3
|
import type { ScallopBuilder } from '../models';
|
|
4
|
-
import type { CoreTxBlock, ScallopTxBlock } from '../types';
|
|
4
|
+
import type { CoreTxBlock, ScallopTxBlock, SuiTxBlockWithSpool } from '../types';
|
|
5
5
|
/**
|
|
6
6
|
* Create an enhanced transaction block instance for interaction with core modules of the Scallop contract.
|
|
7
7
|
*
|
|
@@ -9,4 +9,4 @@ import type { CoreTxBlock, ScallopTxBlock } from '../types';
|
|
|
9
9
|
* @param initTxBlock - Scallop txBlock, txBlock created by SuiKit, or original transaction block.
|
|
10
10
|
* @return Scallop core txBlock.
|
|
11
11
|
*/
|
|
12
|
-
export declare const newCoreTxBlock: (builder: ScallopBuilder, initTxBlock?: ScallopTxBlock | SuiKitTxBlock | TransactionBlock) => CoreTxBlock;
|
|
12
|
+
export declare const newCoreTxBlock: (builder: ScallopBuilder, initTxBlock?: ScallopTxBlock | SuiKitTxBlock | TransactionBlock | SuiTxBlockWithSpool) => CoreTxBlock;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { TransactionBlock, SuiTxBlock as SuiKitTxBlock } from '@scallop-io/sui-kit';
|
|
2
2
|
import { ScallopBuilder } from 'src/models';
|
|
3
|
-
import { SCoinTxBlock, ScallopTxBlock } from 'src/types';
|
|
4
|
-
export declare const newSCoinTxBlock: (builder: ScallopBuilder, initTxBlock?: ScallopTxBlock | SuiKitTxBlock | TransactionBlock) => SCoinTxBlock;
|
|
3
|
+
import { BaseScallopTxBlock, SCoinTxBlock, ScallopTxBlock } from 'src/types';
|
|
4
|
+
export declare const newSCoinTxBlock: (builder: ScallopBuilder, initTxBlock?: ScallopTxBlock | SuiKitTxBlock | TransactionBlock | BaseScallopTxBlock) => SCoinTxBlock;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { TransactionBlock } from '@mysten/sui.js/transactions';
|
|
2
2
|
import { SuiTxBlock as SuiKitTxBlock } from '@scallop-io/sui-kit';
|
|
3
3
|
import type { ScallopBuilder } from '../models';
|
|
4
|
-
import type { SpoolTxBlock, ScallopTxBlock } from '../types';
|
|
4
|
+
import type { SpoolTxBlock, ScallopTxBlock, SuiTxBlockWithSCoin } from '../types';
|
|
5
5
|
/**
|
|
6
6
|
* Create an enhanced transaction block instance for interaction with spool modules of the Scallop contract.
|
|
7
7
|
*
|
|
@@ -9,4 +9,4 @@ import type { SpoolTxBlock, ScallopTxBlock } from '../types';
|
|
|
9
9
|
* @param initTxBlock - Scallop txBlock, txBlock created by SuiKit, or original transaction block.
|
|
10
10
|
* @return Scallop spool txBlock.
|
|
11
11
|
*/
|
|
12
|
-
export declare const newSpoolTxBlock: (builder: ScallopBuilder, initTxBlock?: ScallopTxBlock | SuiKitTxBlock | TransactionBlock) => SpoolTxBlock;
|
|
12
|
+
export declare const newSpoolTxBlock: (builder: ScallopBuilder, initTxBlock?: ScallopTxBlock | SuiKitTxBlock | TransactionBlock | SuiTxBlockWithSCoin) => SpoolTxBlock;
|
package/dist/index.js
CHANGED
|
@@ -5749,6 +5749,22 @@ var requireStakeAccounts = async (...params) => {
|
|
|
5749
5749
|
}) : stakeAccounts[stakeMarketCoinName];
|
|
5750
5750
|
return specificStakeAccounts;
|
|
5751
5751
|
};
|
|
5752
|
+
var stakeHelper = async (builder, txBlock, stakeAccount, coinType, coinName, amount, sender, isSCoin = false) => {
|
|
5753
|
+
try {
|
|
5754
|
+
const coins = await builder.utils.selectCoins(amount, coinType, sender);
|
|
5755
|
+
const [takeCoin, leftCoin] = txBlock.takeAmountFromCoins(coins, amount);
|
|
5756
|
+
if (isSCoin) {
|
|
5757
|
+
const marketCoin = txBlock.burnSCoin(coinName, takeCoin);
|
|
5758
|
+
txBlock.stake(stakeAccount, marketCoin, coinName);
|
|
5759
|
+
} else {
|
|
5760
|
+
txBlock.stake(stakeAccount, takeCoin, coinName);
|
|
5761
|
+
}
|
|
5762
|
+
txBlock.transferObjects([leftCoin], sender);
|
|
5763
|
+
return true;
|
|
5764
|
+
} catch (e) {
|
|
5765
|
+
return false;
|
|
5766
|
+
}
|
|
5767
|
+
};
|
|
5752
5768
|
var generateSpoolNormalMethod = ({
|
|
5753
5769
|
builder,
|
|
5754
5770
|
txBlock
|
|
@@ -5822,18 +5838,29 @@ var generateSpoolQuickMethod = ({
|
|
|
5822
5838
|
stakeAccountId
|
|
5823
5839
|
);
|
|
5824
5840
|
const marketCoinType = builder.utils.parseMarketCoinType(stakeMarketCoinName);
|
|
5841
|
+
const sCoinType = builder.utils.parseSCoinType(stakeMarketCoinName);
|
|
5825
5842
|
if (typeof amountOrMarketCoin === "number") {
|
|
5826
|
-
const
|
|
5827
|
-
|
|
5843
|
+
const stakeMarketCoinRes = await stakeHelper(
|
|
5844
|
+
builder,
|
|
5845
|
+
txBlock,
|
|
5846
|
+
stakeAccountIds[0],
|
|
5828
5847
|
marketCoinType,
|
|
5848
|
+
stakeMarketCoinName,
|
|
5849
|
+
amountOrMarketCoin,
|
|
5829
5850
|
sender
|
|
5830
5851
|
);
|
|
5831
|
-
|
|
5832
|
-
|
|
5833
|
-
|
|
5834
|
-
|
|
5835
|
-
|
|
5836
|
-
|
|
5852
|
+
if (!stakeMarketCoinRes) {
|
|
5853
|
+
await stakeHelper(
|
|
5854
|
+
builder,
|
|
5855
|
+
txBlock,
|
|
5856
|
+
stakeAccountIds[0],
|
|
5857
|
+
sCoinType,
|
|
5858
|
+
stakeMarketCoinName,
|
|
5859
|
+
amountOrMarketCoin,
|
|
5860
|
+
sender,
|
|
5861
|
+
true
|
|
5862
|
+
);
|
|
5863
|
+
}
|
|
5837
5864
|
} else {
|
|
5838
5865
|
txBlock.stake(
|
|
5839
5866
|
stakeAccountIds[0],
|
|
@@ -5849,7 +5876,7 @@ var generateSpoolQuickMethod = ({
|
|
|
5849
5876
|
stakeMarketCoinName,
|
|
5850
5877
|
stakeAccountId
|
|
5851
5878
|
);
|
|
5852
|
-
const
|
|
5879
|
+
const sCoins2 = [];
|
|
5853
5880
|
for (const account of stakeAccounts) {
|
|
5854
5881
|
if (account.staked === 0)
|
|
5855
5882
|
continue;
|
|
@@ -5859,12 +5886,28 @@ var generateSpoolQuickMethod = ({
|
|
|
5859
5886
|
amountToUnstake,
|
|
5860
5887
|
stakeMarketCoinName
|
|
5861
5888
|
);
|
|
5862
|
-
|
|
5889
|
+
const sCoin = txBlock.mintSCoin(stakeMarketCoinName, marketCoin);
|
|
5890
|
+
sCoins2.push(sCoin);
|
|
5863
5891
|
amount -= amountToUnstake;
|
|
5864
5892
|
if (amount === 0)
|
|
5865
5893
|
break;
|
|
5866
5894
|
}
|
|
5867
|
-
|
|
5895
|
+
const mergedSCoin = sCoins2[0];
|
|
5896
|
+
if (sCoins2.length > 1) {
|
|
5897
|
+
txBlock.mergeCoins(mergedSCoin, sCoins2.slice(1));
|
|
5898
|
+
}
|
|
5899
|
+
try {
|
|
5900
|
+
const existingCoins = await builder.utils.selectCoins(
|
|
5901
|
+
Number.MAX_SAFE_INTEGER,
|
|
5902
|
+
builder.utils.parseSCoinType(stakeMarketCoinName),
|
|
5903
|
+
requireSender(txBlock)
|
|
5904
|
+
);
|
|
5905
|
+
if (existingCoins.length > 0) {
|
|
5906
|
+
txBlock.mergeCoins(mergedSCoin, existingCoins);
|
|
5907
|
+
}
|
|
5908
|
+
} catch (e) {
|
|
5909
|
+
}
|
|
5910
|
+
return mergedSCoin;
|
|
5868
5911
|
},
|
|
5869
5912
|
claimQuick: async (stakeMarketCoinName, stakeAccountId) => {
|
|
5870
5913
|
const stakeAccountIds = await requireStakeAccountIds(
|
|
@@ -6734,9 +6777,9 @@ var newScallopTxBlock = (builder, initTxBlock) => {
|
|
|
6734
6777
|
loyaltyTxBlock
|
|
6735
6778
|
);
|
|
6736
6779
|
const referralTxBlock = newReferralTxBlock(builder, borrowIncentiveTxBlock);
|
|
6737
|
-
const
|
|
6738
|
-
const
|
|
6739
|
-
const coreTxBlock = newCoreTxBlock(builder,
|
|
6780
|
+
const sCoinTxBlock = newSCoinTxBlock(builder, referralTxBlock);
|
|
6781
|
+
const spoolTxBlock = newSpoolTxBlock(builder, sCoinTxBlock);
|
|
6782
|
+
const coreTxBlock = newCoreTxBlock(builder, spoolTxBlock);
|
|
6740
6783
|
return new Proxy(coreTxBlock, {
|
|
6741
6784
|
get: (target, prop) => {
|
|
6742
6785
|
if (prop in vescaTxBlock) {
|
|
@@ -7092,8 +7135,8 @@ var ScallopClient = class {
|
|
|
7092
7135
|
const txBlock = this.builder.createTxBlock();
|
|
7093
7136
|
const sender = walletAddress || this.walletAddress;
|
|
7094
7137
|
txBlock.setSender(sender);
|
|
7095
|
-
const
|
|
7096
|
-
txBlock.transferObjects([
|
|
7138
|
+
const sCoin = await txBlock.depositQuick(amount, poolCoinName);
|
|
7139
|
+
txBlock.transferObjects([sCoin], sender);
|
|
7097
7140
|
if (sign) {
|
|
7098
7141
|
return await this.suiKit.signAndSendTxn(
|
|
7099
7142
|
txBlock
|
|
@@ -7109,7 +7152,7 @@ var ScallopClient = class {
|
|
|
7109
7152
|
const stakeMarketCoinName = this.utils.parseMarketCoinName(stakeCoinName);
|
|
7110
7153
|
const stakeAccounts = await this.query.getStakeAccounts(stakeMarketCoinName);
|
|
7111
7154
|
const targetStakeAccount = stakeAccountId || stakeAccounts[0].id;
|
|
7112
|
-
const marketCoin = await txBlock.depositQuick(amount, stakeCoinName);
|
|
7155
|
+
const marketCoin = await txBlock.depositQuick(amount, stakeCoinName, false);
|
|
7113
7156
|
if (targetStakeAccount) {
|
|
7114
7157
|
await txBlock.stakeQuick(
|
|
7115
7158
|
marketCoin,
|
|
@@ -7426,25 +7469,14 @@ var ScallopClient = class {
|
|
|
7426
7469
|
}
|
|
7427
7470
|
if (SUPPORT_SPOOLS.includes(sCoinName)) {
|
|
7428
7471
|
try {
|
|
7429
|
-
const
|
|
7472
|
+
const stakedMarketCoin = await txBlock.unstakeQuick(
|
|
7430
7473
|
Number.MAX_SAFE_INTEGER,
|
|
7431
7474
|
sCoinName
|
|
7432
7475
|
);
|
|
7433
|
-
if (
|
|
7434
|
-
|
|
7435
|
-
|
|
7436
|
-
|
|
7437
|
-
mergedStakedMarketCoin,
|
|
7438
|
-
stakedMarketCoins.slice(1)
|
|
7439
|
-
);
|
|
7440
|
-
}
|
|
7441
|
-
if (toDestroyMarketCoin) {
|
|
7442
|
-
txBlock.mergeCoins(toDestroyMarketCoin, [
|
|
7443
|
-
mergedStakedMarketCoin
|
|
7444
|
-
]);
|
|
7445
|
-
} else {
|
|
7446
|
-
toDestroyMarketCoin = mergedStakedMarketCoin;
|
|
7447
|
-
}
|
|
7476
|
+
if (toDestroyMarketCoin) {
|
|
7477
|
+
txBlock.mergeCoins(toDestroyMarketCoin, [stakedMarketCoin]);
|
|
7478
|
+
} else {
|
|
7479
|
+
toDestroyMarketCoin = stakedMarketCoin;
|
|
7448
7480
|
}
|
|
7449
7481
|
} catch (e) {
|
|
7450
7482
|
const errMsg = e.toString();
|