@minswap/noodles-sdk 0.0.8 → 0.0.10
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.cjs +108 -1
- package/dist/index.d.ts +52 -0
- package/dist/index.js +106 -2
- package/package.json +5 -2
package/dist/index.cjs
CHANGED
|
@@ -46,8 +46,9 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
46
46
|
BASE_BPS: ()=>BASE_BPS,
|
|
47
47
|
MoonbagsConstants: ()=>constants_MoonbagsConstants,
|
|
48
48
|
getSuiClient: ()=>getSuiClient,
|
|
49
|
-
|
|
49
|
+
DraftTransferTx: ()=>DraftTransferTx,
|
|
50
50
|
SUI_FULL_TYPE: ()=>SUI_FULL_TYPE,
|
|
51
|
+
getSplitCoinForTx: ()=>getSplitCoinForTx,
|
|
51
52
|
splitSuiCoinAfterFeeFromBuyTx: ()=>splitSuiCoinAfterFeeFromBuyTx,
|
|
52
53
|
BlastFunSDKTransaction: ()=>sdk_transaction_BlastFunSDKTransaction,
|
|
53
54
|
AstrosAggregator: ()=>astros_AstrosAggregator,
|
|
@@ -1501,6 +1502,110 @@ var calculation_MoonbagsCalculation;
|
|
|
1501
1502
|
MoonbagsTransaction.getSellTransaction = getSellTransaction;
|
|
1502
1503
|
})(transaction_MoonbagsTransaction || (transaction_MoonbagsTransaction = {}));
|
|
1503
1504
|
var transaction_MoonbagsTransaction;
|
|
1505
|
+
const ed25519_namespaceObject = require("@mysten/sui/keypairs/ed25519");
|
|
1506
|
+
const CONSTANTS = {
|
|
1507
|
+
SUI_DECIMALS: 9,
|
|
1508
|
+
GAS_FEE_BUFFER_PERCENTAGE: 0.1,
|
|
1509
|
+
MIN_TRANSFER_AMOUNT: 0.000000001
|
|
1510
|
+
};
|
|
1511
|
+
class DraftTransferTx {
|
|
1512
|
+
suiClient;
|
|
1513
|
+
constructor(suiClient){
|
|
1514
|
+
this.suiClient = suiClient;
|
|
1515
|
+
}
|
|
1516
|
+
suiToMist(suiAmount) {
|
|
1517
|
+
return BigInt(Math.floor(suiAmount * 10 ** CONSTANTS.SUI_DECIMALS));
|
|
1518
|
+
}
|
|
1519
|
+
validatePrivateKey(privateKey, expectedSender) {
|
|
1520
|
+
tiny_invariant_default()(privateKey?.trim(), "Private key is required");
|
|
1521
|
+
const keypair = ed25519_namespaceObject.Ed25519Keypair.fromSecretKey(privateKey);
|
|
1522
|
+
const derivedAddress = keypair.getPublicKey().toSuiAddress();
|
|
1523
|
+
if (derivedAddress !== expectedSender) throw new Error(`Private key mismatch. Expected: ${expectedSender}, Got: ${derivedAddress}`);
|
|
1524
|
+
return keypair;
|
|
1525
|
+
}
|
|
1526
|
+
async createDraft(sender, recipient, suiAmount) {
|
|
1527
|
+
tiny_invariant_default()(sender?.trim(), "Sender address is required");
|
|
1528
|
+
tiny_invariant_default()(recipient?.trim(), "Recipient address is required");
|
|
1529
|
+
tiny_invariant_default()(sender !== recipient, "Sender and recipient cannot be the same");
|
|
1530
|
+
tiny_invariant_default()(suiAmount > CONSTANTS.MIN_TRANSFER_AMOUNT, `Transfer amount must be greater than ${CONSTANTS.MIN_TRANSFER_AMOUNT} SUI`);
|
|
1531
|
+
const suiAmountMist = this.suiToMist(suiAmount);
|
|
1532
|
+
try {
|
|
1533
|
+
let transaction = new transactions_namespaceObject.Transaction();
|
|
1534
|
+
const [coin] = transaction.splitCoins(transaction.gas, [
|
|
1535
|
+
suiAmountMist
|
|
1536
|
+
]);
|
|
1537
|
+
transaction.transferObjects([
|
|
1538
|
+
coin
|
|
1539
|
+
], recipient);
|
|
1540
|
+
transaction.setSender(sender);
|
|
1541
|
+
const referenceGasPrice = await this.suiClient.getReferenceGasPrice();
|
|
1542
|
+
transaction.setGasPrice(referenceGasPrice);
|
|
1543
|
+
const feeAmount = await getNeededGasFee(transaction, sender, CONSTANTS.GAS_FEE_BUFFER_PERCENTAGE);
|
|
1544
|
+
transaction = await addGasFee({
|
|
1545
|
+
inheritTx: transaction,
|
|
1546
|
+
sender,
|
|
1547
|
+
feeAmount,
|
|
1548
|
+
suiInputAmount: suiAmountMist
|
|
1549
|
+
});
|
|
1550
|
+
const txBytes = await transaction.build({
|
|
1551
|
+
client: this.suiClient
|
|
1552
|
+
});
|
|
1553
|
+
const txDraftBase64 = Buffer.from(txBytes).toString("base64");
|
|
1554
|
+
const txDigest = await transaction.getDigest();
|
|
1555
|
+
return {
|
|
1556
|
+
sender,
|
|
1557
|
+
recipient,
|
|
1558
|
+
suiAmount,
|
|
1559
|
+
txDraftBase64,
|
|
1560
|
+
txDigest
|
|
1561
|
+
};
|
|
1562
|
+
} catch (error) {
|
|
1563
|
+
throw new Error(`Failed to create draft transaction: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
1564
|
+
}
|
|
1565
|
+
}
|
|
1566
|
+
async execute(draftTx, privateKey) {
|
|
1567
|
+
try {
|
|
1568
|
+
tiny_invariant_default()(draftTx, "Draft transaction is required");
|
|
1569
|
+
tiny_invariant_default()(draftTx.txDraftBase64?.trim(), "Transaction data is required");
|
|
1570
|
+
const keypair = this.validatePrivateKey(privateKey, draftTx.sender);
|
|
1571
|
+
const txBytes = (0, utils_namespaceObject.fromBase64)(draftTx.txDraftBase64);
|
|
1572
|
+
const { signature } = await keypair.signTransaction(txBytes);
|
|
1573
|
+
const result = await this.suiClient.executeTransactionBlock({
|
|
1574
|
+
transactionBlock: txBytes,
|
|
1575
|
+
signature
|
|
1576
|
+
});
|
|
1577
|
+
return {
|
|
1578
|
+
success: true,
|
|
1579
|
+
txDigest: result.digest,
|
|
1580
|
+
effects: result.effects
|
|
1581
|
+
};
|
|
1582
|
+
} catch (error) {
|
|
1583
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error occurred";
|
|
1584
|
+
return {
|
|
1585
|
+
success: false,
|
|
1586
|
+
error: errorMessage
|
|
1587
|
+
};
|
|
1588
|
+
}
|
|
1589
|
+
}
|
|
1590
|
+
async getTransactionStatus(txDigest) {
|
|
1591
|
+
tiny_invariant_default()(txDigest?.trim(), "Transaction digest is required");
|
|
1592
|
+
try {
|
|
1593
|
+
const txResponse = await this.suiClient.getTransactionBlock({
|
|
1594
|
+
digest: txDigest,
|
|
1595
|
+
options: {
|
|
1596
|
+
showEffects: true
|
|
1597
|
+
}
|
|
1598
|
+
});
|
|
1599
|
+
if (!txResponse?.effects?.status) return "pending";
|
|
1600
|
+
return "success" === txResponse.effects.status.status ? "success" : "failure";
|
|
1601
|
+
} catch (error) {
|
|
1602
|
+
if (error instanceof Error) {
|
|
1603
|
+
if (error.message.includes("not found") || error.message.includes("Could not find")) return "pending";
|
|
1604
|
+
}
|
|
1605
|
+
return "failure";
|
|
1606
|
+
}
|
|
1607
|
+
}
|
|
1608
|
+
}
|
|
1504
1609
|
exports.AftermathAggregator = __webpack_exports__.AftermathAggregator;
|
|
1505
1610
|
exports.AstrosAggregator = __webpack_exports__.AstrosAggregator;
|
|
1506
1611
|
exports.BASE_BPS = __webpack_exports__.BASE_BPS;
|
|
@@ -1515,6 +1620,7 @@ exports.BluefinTx = __webpack_exports__.BluefinTx;
|
|
|
1515
1620
|
exports.Bps = __webpack_exports__.Bps;
|
|
1516
1621
|
exports.CLOCK_OBJECT_ID = __webpack_exports__.CLOCK_OBJECT_ID;
|
|
1517
1622
|
exports.CetusAggregator = __webpack_exports__.CetusAggregator;
|
|
1623
|
+
exports.DraftTransferTx = __webpack_exports__.DraftTransferTx;
|
|
1518
1624
|
exports.FlowXAggregator = __webpack_exports__.FlowXAggregator;
|
|
1519
1625
|
exports.MathUtils = __webpack_exports__.MathUtils;
|
|
1520
1626
|
exports.MoonbagsCalculation = __webpack_exports__.MoonbagsCalculation;
|
|
@@ -1560,6 +1666,7 @@ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
|
1560
1666
|
"Bps",
|
|
1561
1667
|
"CLOCK_OBJECT_ID",
|
|
1562
1668
|
"CetusAggregator",
|
|
1669
|
+
"DraftTransferTx",
|
|
1563
1670
|
"FlowXAggregator",
|
|
1564
1671
|
"MathUtils",
|
|
1565
1672
|
"MoonbagsCalculation",
|
package/dist/index.d.ts
CHANGED
|
@@ -435,6 +435,56 @@ export declare interface CommonTxParams {
|
|
|
435
435
|
*/
|
|
436
436
|
export declare function createCompatibleSuiClient(client: SuiClient): LegacySuiClient;
|
|
437
437
|
|
|
438
|
+
export declare type DraftTransaction = {
|
|
439
|
+
readonly sender: string;
|
|
440
|
+
readonly recipient: string;
|
|
441
|
+
readonly suiAmount: number;
|
|
442
|
+
readonly txDigest: string;
|
|
443
|
+
readonly txDraftBase64: string;
|
|
444
|
+
};
|
|
445
|
+
|
|
446
|
+
export declare class DraftTransferTx {
|
|
447
|
+
private readonly suiClient;
|
|
448
|
+
constructor(suiClient: SuiClient);
|
|
449
|
+
/**
|
|
450
|
+
* Converts SUI amount to MIST (smallest unit)
|
|
451
|
+
* @private
|
|
452
|
+
*/
|
|
453
|
+
private suiToMist;
|
|
454
|
+
/**
|
|
455
|
+
* Validates private key against expected sender address
|
|
456
|
+
* @private
|
|
457
|
+
*/
|
|
458
|
+
private validatePrivateKey;
|
|
459
|
+
/**
|
|
460
|
+
* Creates a draft transaction for SUI transfer
|
|
461
|
+
* @param params - Transfer parameters
|
|
462
|
+
* @returns Draft transaction object with encoded transaction data
|
|
463
|
+
* @throws {Error} If validation fails or transaction building fails
|
|
464
|
+
*/
|
|
465
|
+
createDraft(sender: string, recipient: string, suiAmount: number): Promise<DraftTransaction>;
|
|
466
|
+
/**
|
|
467
|
+
* Executes a draft transaction on the Sui network
|
|
468
|
+
* @param draftTx - Draft transaction to execute
|
|
469
|
+
* @param privateKey - Sender's private key
|
|
470
|
+
* @returns Execution result with success status and transaction details
|
|
471
|
+
*/
|
|
472
|
+
execute(draftTx: DraftTransaction, privateKey: string): Promise<ExecutionResult>;
|
|
473
|
+
/**
|
|
474
|
+
* Verifies the status of a transaction on the Sui network
|
|
475
|
+
* @param txDigest - Transaction digest to check
|
|
476
|
+
* @returns Transaction status: 'success', 'failure', or 'pending'
|
|
477
|
+
*/
|
|
478
|
+
getTransactionStatus(txDigest: string): Promise<TransactionStatus>;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
export declare interface ExecutionResult {
|
|
482
|
+
readonly success: boolean;
|
|
483
|
+
readonly txDigest?: string;
|
|
484
|
+
readonly effects?: any;
|
|
485
|
+
readonly error?: string;
|
|
486
|
+
}
|
|
487
|
+
|
|
438
488
|
export declare type FinalTradeRoute = {
|
|
439
489
|
coinIn: string;
|
|
440
490
|
coinOut: string;
|
|
@@ -903,6 +953,8 @@ export declare type TradeRoute = {
|
|
|
903
953
|
paths: TradePath[];
|
|
904
954
|
};
|
|
905
955
|
|
|
956
|
+
export declare type TransactionStatus = "success" | "failure" | "pending";
|
|
957
|
+
|
|
906
958
|
export declare const USDC_TOKEN_TYPE = "0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf::coin::COIN";
|
|
907
959
|
|
|
908
960
|
export { }
|
package/dist/index.js
CHANGED
|
@@ -7,10 +7,11 @@ import { AggregatorClient, Env } from "@cetusprotocol/aggregator-sdk";
|
|
|
7
7
|
import bn from "bn.js";
|
|
8
8
|
import { AggregatorQuoter, Coin, Commission, CommissionType, TradeBuilder } from "@flowx-finance/sdk";
|
|
9
9
|
import { SuiClient, getFullnodeUrl } from "@mysten/sui/client";
|
|
10
|
-
import { normalizeStructTag } from "@mysten/sui/utils";
|
|
10
|
+
import { fromBase64, normalizeStructTag } from "@mysten/sui/utils";
|
|
11
11
|
import tiny_invariant from "@minswap/tiny-invariant";
|
|
12
12
|
import { MemezPumpSDK } from "@interest-protocol/memez-fun-sdk";
|
|
13
13
|
import { Network } from "@interest-protocol/sui-core-sdk";
|
|
14
|
+
import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519";
|
|
14
15
|
class _7k_SevenKAggregator {
|
|
15
16
|
_config;
|
|
16
17
|
_suiClient;
|
|
@@ -1418,4 +1419,107 @@ var calculation_MoonbagsCalculation;
|
|
|
1418
1419
|
MoonbagsTransaction.getSellTransaction = getSellTransaction;
|
|
1419
1420
|
})(transaction_MoonbagsTransaction || (transaction_MoonbagsTransaction = {}));
|
|
1420
1421
|
var transaction_MoonbagsTransaction;
|
|
1421
|
-
|
|
1422
|
+
const CONSTANTS = {
|
|
1423
|
+
SUI_DECIMALS: 9,
|
|
1424
|
+
GAS_FEE_BUFFER_PERCENTAGE: 0.1,
|
|
1425
|
+
MIN_TRANSFER_AMOUNT: 0.000000001
|
|
1426
|
+
};
|
|
1427
|
+
class DraftTransferTx {
|
|
1428
|
+
suiClient;
|
|
1429
|
+
constructor(suiClient){
|
|
1430
|
+
this.suiClient = suiClient;
|
|
1431
|
+
}
|
|
1432
|
+
suiToMist(suiAmount) {
|
|
1433
|
+
return BigInt(Math.floor(suiAmount * 10 ** CONSTANTS.SUI_DECIMALS));
|
|
1434
|
+
}
|
|
1435
|
+
validatePrivateKey(privateKey, expectedSender) {
|
|
1436
|
+
tiny_invariant(privateKey?.trim(), "Private key is required");
|
|
1437
|
+
const keypair = Ed25519Keypair.fromSecretKey(privateKey);
|
|
1438
|
+
const derivedAddress = keypair.getPublicKey().toSuiAddress();
|
|
1439
|
+
if (derivedAddress !== expectedSender) throw new Error(`Private key mismatch. Expected: ${expectedSender}, Got: ${derivedAddress}`);
|
|
1440
|
+
return keypair;
|
|
1441
|
+
}
|
|
1442
|
+
async createDraft(sender, recipient, suiAmount) {
|
|
1443
|
+
tiny_invariant(sender?.trim(), "Sender address is required");
|
|
1444
|
+
tiny_invariant(recipient?.trim(), "Recipient address is required");
|
|
1445
|
+
tiny_invariant(sender !== recipient, "Sender and recipient cannot be the same");
|
|
1446
|
+
tiny_invariant(suiAmount > CONSTANTS.MIN_TRANSFER_AMOUNT, `Transfer amount must be greater than ${CONSTANTS.MIN_TRANSFER_AMOUNT} SUI`);
|
|
1447
|
+
const suiAmountMist = this.suiToMist(suiAmount);
|
|
1448
|
+
try {
|
|
1449
|
+
let transaction = new Transaction();
|
|
1450
|
+
const [coin] = transaction.splitCoins(transaction.gas, [
|
|
1451
|
+
suiAmountMist
|
|
1452
|
+
]);
|
|
1453
|
+
transaction.transferObjects([
|
|
1454
|
+
coin
|
|
1455
|
+
], recipient);
|
|
1456
|
+
transaction.setSender(sender);
|
|
1457
|
+
const referenceGasPrice = await this.suiClient.getReferenceGasPrice();
|
|
1458
|
+
transaction.setGasPrice(referenceGasPrice);
|
|
1459
|
+
const feeAmount = await getNeededGasFee(transaction, sender, CONSTANTS.GAS_FEE_BUFFER_PERCENTAGE);
|
|
1460
|
+
transaction = await addGasFee({
|
|
1461
|
+
inheritTx: transaction,
|
|
1462
|
+
sender,
|
|
1463
|
+
feeAmount,
|
|
1464
|
+
suiInputAmount: suiAmountMist
|
|
1465
|
+
});
|
|
1466
|
+
const txBytes = await transaction.build({
|
|
1467
|
+
client: this.suiClient
|
|
1468
|
+
});
|
|
1469
|
+
const txDraftBase64 = Buffer.from(txBytes).toString("base64");
|
|
1470
|
+
const txDigest = await transaction.getDigest();
|
|
1471
|
+
return {
|
|
1472
|
+
sender,
|
|
1473
|
+
recipient,
|
|
1474
|
+
suiAmount,
|
|
1475
|
+
txDraftBase64,
|
|
1476
|
+
txDigest
|
|
1477
|
+
};
|
|
1478
|
+
} catch (error) {
|
|
1479
|
+
throw new Error(`Failed to create draft transaction: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
1480
|
+
}
|
|
1481
|
+
}
|
|
1482
|
+
async execute(draftTx, privateKey) {
|
|
1483
|
+
try {
|
|
1484
|
+
tiny_invariant(draftTx, "Draft transaction is required");
|
|
1485
|
+
tiny_invariant(draftTx.txDraftBase64?.trim(), "Transaction data is required");
|
|
1486
|
+
const keypair = this.validatePrivateKey(privateKey, draftTx.sender);
|
|
1487
|
+
const txBytes = fromBase64(draftTx.txDraftBase64);
|
|
1488
|
+
const { signature } = await keypair.signTransaction(txBytes);
|
|
1489
|
+
const result = await this.suiClient.executeTransactionBlock({
|
|
1490
|
+
transactionBlock: txBytes,
|
|
1491
|
+
signature
|
|
1492
|
+
});
|
|
1493
|
+
return {
|
|
1494
|
+
success: true,
|
|
1495
|
+
txDigest: result.digest,
|
|
1496
|
+
effects: result.effects
|
|
1497
|
+
};
|
|
1498
|
+
} catch (error) {
|
|
1499
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error occurred";
|
|
1500
|
+
return {
|
|
1501
|
+
success: false,
|
|
1502
|
+
error: errorMessage
|
|
1503
|
+
};
|
|
1504
|
+
}
|
|
1505
|
+
}
|
|
1506
|
+
async getTransactionStatus(txDigest) {
|
|
1507
|
+
tiny_invariant(txDigest?.trim(), "Transaction digest is required");
|
|
1508
|
+
try {
|
|
1509
|
+
const txResponse = await this.suiClient.getTransactionBlock({
|
|
1510
|
+
digest: txDigest,
|
|
1511
|
+
options: {
|
|
1512
|
+
showEffects: true
|
|
1513
|
+
}
|
|
1514
|
+
});
|
|
1515
|
+
if (!txResponse?.effects?.status) return "pending";
|
|
1516
|
+
return "success" === txResponse.effects.status.status ? "success" : "failure";
|
|
1517
|
+
} catch (error) {
|
|
1518
|
+
if (error instanceof Error) {
|
|
1519
|
+
if (error.message.includes("not found") || error.message.includes("Could not find")) return "pending";
|
|
1520
|
+
}
|
|
1521
|
+
return "failure";
|
|
1522
|
+
}
|
|
1523
|
+
}
|
|
1524
|
+
}
|
|
1525
|
+
export { aftermath_AftermathAggregator as AftermathAggregator, astros_AstrosAggregator as AstrosAggregator, BASE_BPS, BLUEFIN_PACKAGE_ID, constants_BlastFunConstants as BlastFunConstants, custom_calculation_BlastFunCustomCalculation as BlastFunCustomCalculation, custom_transaction_BlastFunCustomTransaction as BlastFunCustomTransaction, package_BlastFunPackage as BlastFunPackage, sdk_calculation_BlastFunSDKCalculation as BlastFunSDKCalculation, sdk_transaction_BlastFunSDKTransaction as BlastFunSDKTransaction, bluefin_BluefinTx as BluefinTx, package_Bps as Bps, CLOCK_OBJECT_ID, cetus_CetusAggregator as CetusAggregator, DraftTransferTx, flowx_FlowXAggregator as FlowXAggregator, package_MathUtils as MathUtils, calculation_MoonbagsCalculation as MoonbagsCalculation, constants_MoonbagsConstants as MoonbagsConstants, package_MoonbagsPackage as MoonbagsPackage, transaction_MoonbagsTransaction as MoonbagsTransaction, NATIVE_USDC_TOKEN_TYPE, SUI_FULL_TYPE, SUI_METADATA_OBJECT_ID, SUI_TYPE, _7k_SevenKAggregator as SevenKAggregator, common_SupportedAggregator as SupportedAggregator, types_SupportedBondingCurve as SupportedBondingCurve, types_TradeFeeOptions as TradeFeeOptions, USDC_TOKEN_TYPE, adaptSuiClient, adaptTransaction, addGasFee, createCompatibleSuiClient, getAmountAfterFee, getCoinObjectIdsByAmount, getMemezPumpSDK, getMoveObject, getMoveObjectContent, getNeededGasFee, getSplitCoinForTx, getSplitCoinsAfterFee, getSuiClient, splitSuiCoinAfterFeeFromBuyTx, splitSuiCoinAfterFeeFromSellTx };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@minswap/noodles-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.10",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
],
|
|
17
17
|
"repository": {
|
|
18
18
|
"type": "git",
|
|
19
|
-
"url": "git@github.com:minswap/noodles-
|
|
19
|
+
"url": "git@github.com:minswap/noodles-sdk.git"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"@biomejs/biome": "2.2.4",
|
|
@@ -46,6 +46,9 @@
|
|
|
46
46
|
"bn.js": "^5.2.2",
|
|
47
47
|
"navi-sdk": "^1.6.22"
|
|
48
48
|
},
|
|
49
|
+
"publishConfig": {
|
|
50
|
+
"access": "public"
|
|
51
|
+
},
|
|
49
52
|
"scripts": {
|
|
50
53
|
"build": "rslib build",
|
|
51
54
|
"lint": "biome check --write",
|