@scallop-io/sui-scallop-sdk 0.46.47 → 0.46.49
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.js +45 -40
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +45 -40
- package/dist/index.mjs.map +1 -1
- package/dist/types/builder/spool.d.ts +1 -1
- package/package.json +1 -1
- package/src/builders/spoolBuilder.ts +48 -20
- package/src/models/scallopClient.ts +6 -3
- package/src/queries/priceQuery.ts +3 -22
- package/src/types/builder/spool.ts +2 -1
- package/dist/test.d.ts +0 -1
- package/src/test.ts +0 -19
|
@@ -14,7 +14,7 @@ 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 | undefined>;
|
|
17
|
+
unstakeQuick(amount: number, stakeMarketCoinName: SupportStakeMarketCoins, stakeAccountId?: SuiAddressArg, returnSCoin?: boolean): Promise<TransactionResult | undefined>;
|
|
18
18
|
claimQuick(stakeMarketCoinName: SupportStakeMarketCoins, stakeAccountId?: SuiAddressArg): Promise<TransactionResult[]>;
|
|
19
19
|
};
|
|
20
20
|
export type SuiTxBlockWithSpoolNormalMethods = SuiKitTxBlock & SuiTxBlockWithSCoin & SpoolNormalMethods;
|
package/package.json
CHANGED
|
@@ -249,14 +249,19 @@ const generateSpoolQuickMethod: GenerateSpoolQuickMethod = ({
|
|
|
249
249
|
);
|
|
250
250
|
}
|
|
251
251
|
},
|
|
252
|
-
unstakeQuick: async (
|
|
252
|
+
unstakeQuick: async (
|
|
253
|
+
amount,
|
|
254
|
+
stakeMarketCoinName,
|
|
255
|
+
stakeAccountId,
|
|
256
|
+
returnSCoin = true
|
|
257
|
+
) => {
|
|
253
258
|
const stakeAccounts = await requireStakeAccounts(
|
|
254
259
|
builder,
|
|
255
260
|
txBlock,
|
|
256
261
|
stakeMarketCoinName,
|
|
257
262
|
stakeAccountId
|
|
258
263
|
);
|
|
259
|
-
const
|
|
264
|
+
const toTransfer: TransactionResult[] = [];
|
|
260
265
|
for (const account of stakeAccounts) {
|
|
261
266
|
if (account.staked === 0) continue;
|
|
262
267
|
const amountToUnstake = Math.min(amount, account.staked);
|
|
@@ -267,33 +272,56 @@ const generateSpoolQuickMethod: GenerateSpoolQuickMethod = ({
|
|
|
267
272
|
);
|
|
268
273
|
|
|
269
274
|
// convert to new sCoin
|
|
270
|
-
|
|
271
|
-
|
|
275
|
+
if (returnSCoin) {
|
|
276
|
+
const sCoin = txBlock.mintSCoin(stakeMarketCoinName, marketCoin);
|
|
277
|
+
toTransfer.push(sCoin);
|
|
278
|
+
} else {
|
|
279
|
+
toTransfer.push(marketCoin);
|
|
280
|
+
}
|
|
281
|
+
|
|
272
282
|
amount -= amountToUnstake;
|
|
273
283
|
if (amount === 0) break;
|
|
274
284
|
}
|
|
275
285
|
|
|
276
|
-
if (
|
|
277
|
-
const
|
|
286
|
+
if (toTransfer.length > 0) {
|
|
287
|
+
const mergedCoin = toTransfer[0];
|
|
278
288
|
|
|
279
|
-
if (
|
|
280
|
-
txBlock.mergeCoins(
|
|
289
|
+
if (toTransfer.length > 1) {
|
|
290
|
+
txBlock.mergeCoins(mergedCoin, toTransfer.slice(1));
|
|
281
291
|
}
|
|
282
|
-
// check for existing sCoins
|
|
283
|
-
try {
|
|
284
|
-
const existingCoins = await builder.utils.selectCoins(
|
|
285
|
-
Number.MAX_SAFE_INTEGER,
|
|
286
|
-
builder.utils.parseSCoinType(stakeMarketCoinName),
|
|
287
|
-
requireSender(txBlock)
|
|
288
|
-
);
|
|
289
292
|
|
|
290
|
-
|
|
291
|
-
|
|
293
|
+
if (returnSCoin) {
|
|
294
|
+
// check for existing sCoins
|
|
295
|
+
try {
|
|
296
|
+
const existingCoins = await builder.utils.selectCoins(
|
|
297
|
+
Number.MAX_SAFE_INTEGER,
|
|
298
|
+
builder.utils.parseSCoinType(stakeMarketCoinName),
|
|
299
|
+
requireSender(txBlock)
|
|
300
|
+
);
|
|
301
|
+
|
|
302
|
+
if (existingCoins.length > 0) {
|
|
303
|
+
txBlock.mergeCoins(mergedCoin, existingCoins);
|
|
304
|
+
}
|
|
305
|
+
} catch (e) {
|
|
306
|
+
// ignore
|
|
307
|
+
}
|
|
308
|
+
} else {
|
|
309
|
+
// check for existing market coins
|
|
310
|
+
try {
|
|
311
|
+
const existingCoins = await builder.utils.selectCoins(
|
|
312
|
+
Number.MAX_SAFE_INTEGER,
|
|
313
|
+
builder.utils.parseMarketCoinType(stakeMarketCoinName),
|
|
314
|
+
requireSender(txBlock)
|
|
315
|
+
);
|
|
316
|
+
|
|
317
|
+
if (existingCoins.length > 0) {
|
|
318
|
+
txBlock.mergeCoins(mergedCoin, existingCoins);
|
|
319
|
+
}
|
|
320
|
+
} catch (e) {
|
|
321
|
+
// ignore
|
|
292
322
|
}
|
|
293
|
-
} catch (e) {
|
|
294
|
-
// ignore
|
|
295
323
|
}
|
|
296
|
-
return
|
|
324
|
+
return mergedCoin;
|
|
297
325
|
}
|
|
298
326
|
},
|
|
299
327
|
claimQuick: async (stakeMarketCoinName, stakeAccountId) => {
|
|
@@ -742,12 +742,12 @@ export class ScallopClient {
|
|
|
742
742
|
const sender = walletAddress || this.walletAddress;
|
|
743
743
|
txBlock.setSender(sender);
|
|
744
744
|
|
|
745
|
-
const
|
|
745
|
+
const sCoin = await txBlock.unstakeQuick(
|
|
746
746
|
amount,
|
|
747
747
|
stakeMarketCoinName,
|
|
748
748
|
stakeAccountId
|
|
749
749
|
);
|
|
750
|
-
txBlock.transferObjects([
|
|
750
|
+
txBlock.transferObjects([sCoin], sender);
|
|
751
751
|
|
|
752
752
|
if (sign) {
|
|
753
753
|
return (await this.suiKit.signAndSendTxn(
|
|
@@ -793,13 +793,16 @@ export class ScallopClient {
|
|
|
793
793
|
const stakeMarketCoin = await txBlock.unstakeQuick(
|
|
794
794
|
amount,
|
|
795
795
|
stakeMarketCoinName,
|
|
796
|
-
stakeAccountId
|
|
796
|
+
stakeAccountId,
|
|
797
|
+
false
|
|
797
798
|
);
|
|
798
799
|
const stakeCoinName =
|
|
799
800
|
this.utils.parseCoinName<SupportStakeCoins>(stakeMarketCoinName);
|
|
800
801
|
if (stakeMarketCoin) {
|
|
801
802
|
const coin = txBlock.withdraw(stakeMarketCoin, stakeCoinName);
|
|
802
803
|
txBlock.transferObjects([coin], sender);
|
|
804
|
+
} else {
|
|
805
|
+
throw new Error(`No stake found for ${stakeMarketCoinName}`);
|
|
803
806
|
}
|
|
804
807
|
|
|
805
808
|
if (sign) {
|
|
@@ -61,30 +61,11 @@ export const getPythPrices = async (
|
|
|
61
61
|
query: ScallopQuery,
|
|
62
62
|
assetCoinNames: SupportAssetCoins[]
|
|
63
63
|
) => {
|
|
64
|
-
const seen: Record<string, boolean> = {};
|
|
65
|
-
const pythFeedObjectIds = assetCoinNames
|
|
66
|
-
.map((assetCoinName) => {
|
|
67
|
-
const pythFeedObjectId = query.address.get(
|
|
68
|
-
`core.coins.${assetCoinName}.oracle.pyth.feedObject`
|
|
69
|
-
);
|
|
70
|
-
if (seen[pythFeedObjectId]) return null;
|
|
71
|
-
|
|
72
|
-
seen[pythFeedObjectId] = true;
|
|
73
|
-
return pythFeedObjectId;
|
|
74
|
-
})
|
|
75
|
-
.filter((item) => !!item) as string[];
|
|
76
|
-
const priceFeedObjects = await query.cache.queryGetObjects(
|
|
77
|
-
pythFeedObjectIds,
|
|
78
|
-
{
|
|
79
|
-
showContent: true,
|
|
80
|
-
}
|
|
81
|
-
);
|
|
82
|
-
|
|
83
64
|
return (
|
|
84
65
|
await Promise.all(
|
|
85
|
-
|
|
86
|
-
coinName:
|
|
87
|
-
price: await getPythPrice(query,
|
|
66
|
+
assetCoinNames.map(async (assetCoinName) => ({
|
|
67
|
+
coinName: assetCoinName,
|
|
68
|
+
price: await getPythPrice(query, assetCoinName),
|
|
88
69
|
}))
|
|
89
70
|
)
|
|
90
71
|
).reduce(
|
|
@@ -42,7 +42,8 @@ export type SpoolQuickMethods = {
|
|
|
42
42
|
unstakeQuick(
|
|
43
43
|
amount: number,
|
|
44
44
|
stakeMarketCoinName: SupportStakeMarketCoins,
|
|
45
|
-
stakeAccountId?: SuiAddressArg
|
|
45
|
+
stakeAccountId?: SuiAddressArg,
|
|
46
|
+
returnSCoin?: boolean
|
|
46
47
|
): Promise<TransactionResult | undefined>;
|
|
47
48
|
claimQuick(
|
|
48
49
|
stakeMarketCoinName: SupportStakeMarketCoins,
|
package/dist/test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/src/test.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { Scallop } from './models';
|
|
2
|
-
import * as dotenv from 'dotenv';
|
|
3
|
-
dotenv.config();
|
|
4
|
-
const scallop = new Scallop({
|
|
5
|
-
secretKey: process.env.SECRET_KEY as string,
|
|
6
|
-
});
|
|
7
|
-
|
|
8
|
-
const main = async () => {
|
|
9
|
-
const query = await scallop.createScallopQuery();
|
|
10
|
-
|
|
11
|
-
const res = await query.getVeScas(
|
|
12
|
-
'0xd1a70cfe7332e994a950b9c570e93def4b6d2ec53b34ff5c0cc9946226a7cf3d'
|
|
13
|
-
);
|
|
14
|
-
console.dir(res, { depth: null });
|
|
15
|
-
};
|
|
16
|
-
main()
|
|
17
|
-
.then()
|
|
18
|
-
.catch(console.error)
|
|
19
|
-
.finally(() => process.exit(0));
|