@minswap/noodles-sdk 0.0.9 → 0.0.11

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 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
- getSplitCoinForTx: ()=>getSplitCoinForTx,
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,104 @@ 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
+ GAS_FEE_BUFFER_PERCENTAGE: 0.1
1508
+ };
1509
+ class DraftTransferTx {
1510
+ suiClient;
1511
+ constructor(suiClient){
1512
+ this.suiClient = suiClient;
1513
+ }
1514
+ validatePrivateKey(privateKey, expectedSender) {
1515
+ tiny_invariant_default()(privateKey?.trim(), "Private key is required");
1516
+ const keypair = ed25519_namespaceObject.Ed25519Keypair.fromSecretKey(privateKey);
1517
+ const derivedAddress = keypair.getPublicKey().toSuiAddress();
1518
+ if (derivedAddress !== expectedSender) throw new Error(`Private key mismatch. Expected: ${expectedSender}, Got: ${derivedAddress}`);
1519
+ return keypair;
1520
+ }
1521
+ async createDraft(sender, recipient, amountMIST) {
1522
+ tiny_invariant_default()(sender?.trim(), "Sender address is required");
1523
+ tiny_invariant_default()(recipient?.trim(), "Recipient address is required");
1524
+ tiny_invariant_default()(sender !== recipient, "Sender and recipient cannot be the same");
1525
+ tiny_invariant_default()(amountMIST > 0n, "Transfer amount must be at least 1 MIST");
1526
+ try {
1527
+ let transaction = new transactions_namespaceObject.Transaction();
1528
+ const [coin] = transaction.splitCoins(transaction.gas, [
1529
+ amountMIST
1530
+ ]);
1531
+ transaction.transferObjects([
1532
+ coin
1533
+ ], recipient);
1534
+ transaction.setSender(sender);
1535
+ const referenceGasPrice = await this.suiClient.getReferenceGasPrice();
1536
+ transaction.setGasPrice(referenceGasPrice);
1537
+ const feeAmount = await getNeededGasFee(transaction, sender, CONSTANTS.GAS_FEE_BUFFER_PERCENTAGE);
1538
+ transaction = await addGasFee({
1539
+ inheritTx: transaction,
1540
+ sender,
1541
+ feeAmount,
1542
+ suiInputAmount: amountMIST
1543
+ });
1544
+ const txBytes = await transaction.build({
1545
+ client: this.suiClient
1546
+ });
1547
+ const txDraftBase64 = Buffer.from(txBytes).toString("base64");
1548
+ const txDigest = await transaction.getDigest();
1549
+ return {
1550
+ sender,
1551
+ recipient,
1552
+ amountMIST,
1553
+ txDraftBase64,
1554
+ txDigest
1555
+ };
1556
+ } catch (error) {
1557
+ throw new Error(`Failed to create draft transaction: ${error instanceof Error ? error.message : "Unknown error"}`);
1558
+ }
1559
+ }
1560
+ async execute(draftTx, privateKey) {
1561
+ try {
1562
+ tiny_invariant_default()(draftTx, "Draft transaction is required");
1563
+ tiny_invariant_default()(draftTx.txDraftBase64?.trim(), "Transaction data is required");
1564
+ const keypair = this.validatePrivateKey(privateKey, draftTx.sender);
1565
+ const txBytes = (0, utils_namespaceObject.fromBase64)(draftTx.txDraftBase64);
1566
+ const { signature } = await keypair.signTransaction(txBytes);
1567
+ const result = await this.suiClient.executeTransactionBlock({
1568
+ transactionBlock: txBytes,
1569
+ signature
1570
+ });
1571
+ return {
1572
+ success: true,
1573
+ txDigest: result.digest,
1574
+ effects: result.effects
1575
+ };
1576
+ } catch (error) {
1577
+ const errorMessage = error instanceof Error ? error.message : "Unknown error occurred";
1578
+ return {
1579
+ success: false,
1580
+ error: errorMessage
1581
+ };
1582
+ }
1583
+ }
1584
+ async getTransactionStatus(txDigest) {
1585
+ tiny_invariant_default()(txDigest?.trim(), "Transaction digest is required");
1586
+ try {
1587
+ const txResponse = await this.suiClient.getTransactionBlock({
1588
+ digest: txDigest,
1589
+ options: {
1590
+ showEffects: true
1591
+ }
1592
+ });
1593
+ if (!txResponse?.effects?.status) return "pending";
1594
+ return "success" === txResponse.effects.status.status ? "success" : "failure";
1595
+ } catch (error) {
1596
+ if (error instanceof Error) {
1597
+ if (error.message.includes("not found") || error.message.includes("Could not find")) return "pending";
1598
+ }
1599
+ return "failure";
1600
+ }
1601
+ }
1602
+ }
1504
1603
  exports.AftermathAggregator = __webpack_exports__.AftermathAggregator;
1505
1604
  exports.AstrosAggregator = __webpack_exports__.AstrosAggregator;
1506
1605
  exports.BASE_BPS = __webpack_exports__.BASE_BPS;
@@ -1515,6 +1614,7 @@ exports.BluefinTx = __webpack_exports__.BluefinTx;
1515
1614
  exports.Bps = __webpack_exports__.Bps;
1516
1615
  exports.CLOCK_OBJECT_ID = __webpack_exports__.CLOCK_OBJECT_ID;
1517
1616
  exports.CetusAggregator = __webpack_exports__.CetusAggregator;
1617
+ exports.DraftTransferTx = __webpack_exports__.DraftTransferTx;
1518
1618
  exports.FlowXAggregator = __webpack_exports__.FlowXAggregator;
1519
1619
  exports.MathUtils = __webpack_exports__.MathUtils;
1520
1620
  exports.MoonbagsCalculation = __webpack_exports__.MoonbagsCalculation;
@@ -1560,6 +1660,7 @@ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
1560
1660
  "Bps",
1561
1661
  "CLOCK_OBJECT_ID",
1562
1662
  "CetusAggregator",
1663
+ "DraftTransferTx",
1563
1664
  "FlowXAggregator",
1564
1665
  "MathUtils",
1565
1666
  "MoonbagsCalculation",
package/dist/index.d.ts CHANGED
@@ -435,6 +435,51 @@ 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 amountMIST: bigint;
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
+ * Validates private key against expected sender address
451
+ * @private
452
+ */
453
+ private validatePrivateKey;
454
+ /**
455
+ * Creates a draft transaction for SUI transfer
456
+ * @param params - Transfer parameters
457
+ * @returns Draft transaction object with encoded transaction data
458
+ * @throws {Error} If validation fails or transaction building fails
459
+ */
460
+ createDraft(sender: string, recipient: string, amountMIST: bigint): Promise<DraftTransaction>;
461
+ /**
462
+ * Executes a draft transaction on the Sui network
463
+ * @param draftTx - Draft transaction to execute
464
+ * @param privateKey - Sender's private key
465
+ * @returns Execution result with success status and transaction details
466
+ */
467
+ execute(draftTx: DraftTransaction, privateKey: string): Promise<ExecutionResult>;
468
+ /**
469
+ * Verifies the status of a transaction on the Sui network
470
+ * @param txDigest - Transaction digest to check
471
+ * @returns Transaction status: 'success', 'failure', or 'pending'
472
+ */
473
+ getTransactionStatus(txDigest: string): Promise<TransactionStatus>;
474
+ }
475
+
476
+ export declare interface ExecutionResult {
477
+ readonly success: boolean;
478
+ readonly txDigest?: string;
479
+ readonly effects?: any;
480
+ readonly error?: string;
481
+ }
482
+
438
483
  export declare type FinalTradeRoute = {
439
484
  coinIn: string;
440
485
  coinOut: string;
@@ -903,6 +948,8 @@ export declare type TradeRoute = {
903
948
  paths: TradePath[];
904
949
  };
905
950
 
951
+ export declare type TransactionStatus = "success" | "failure" | "pending";
952
+
906
953
  export declare const USDC_TOKEN_TYPE = "0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf::coin::COIN";
907
954
 
908
955
  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,101 @@ var calculation_MoonbagsCalculation;
1418
1419
  MoonbagsTransaction.getSellTransaction = getSellTransaction;
1419
1420
  })(transaction_MoonbagsTransaction || (transaction_MoonbagsTransaction = {}));
1420
1421
  var transaction_MoonbagsTransaction;
1421
- 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, 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 };
1422
+ const CONSTANTS = {
1423
+ GAS_FEE_BUFFER_PERCENTAGE: 0.1
1424
+ };
1425
+ class DraftTransferTx {
1426
+ suiClient;
1427
+ constructor(suiClient){
1428
+ this.suiClient = suiClient;
1429
+ }
1430
+ validatePrivateKey(privateKey, expectedSender) {
1431
+ tiny_invariant(privateKey?.trim(), "Private key is required");
1432
+ const keypair = Ed25519Keypair.fromSecretKey(privateKey);
1433
+ const derivedAddress = keypair.getPublicKey().toSuiAddress();
1434
+ if (derivedAddress !== expectedSender) throw new Error(`Private key mismatch. Expected: ${expectedSender}, Got: ${derivedAddress}`);
1435
+ return keypair;
1436
+ }
1437
+ async createDraft(sender, recipient, amountMIST) {
1438
+ tiny_invariant(sender?.trim(), "Sender address is required");
1439
+ tiny_invariant(recipient?.trim(), "Recipient address is required");
1440
+ tiny_invariant(sender !== recipient, "Sender and recipient cannot be the same");
1441
+ tiny_invariant(amountMIST > 0n, "Transfer amount must be at least 1 MIST");
1442
+ try {
1443
+ let transaction = new Transaction();
1444
+ const [coin] = transaction.splitCoins(transaction.gas, [
1445
+ amountMIST
1446
+ ]);
1447
+ transaction.transferObjects([
1448
+ coin
1449
+ ], recipient);
1450
+ transaction.setSender(sender);
1451
+ const referenceGasPrice = await this.suiClient.getReferenceGasPrice();
1452
+ transaction.setGasPrice(referenceGasPrice);
1453
+ const feeAmount = await getNeededGasFee(transaction, sender, CONSTANTS.GAS_FEE_BUFFER_PERCENTAGE);
1454
+ transaction = await addGasFee({
1455
+ inheritTx: transaction,
1456
+ sender,
1457
+ feeAmount,
1458
+ suiInputAmount: amountMIST
1459
+ });
1460
+ const txBytes = await transaction.build({
1461
+ client: this.suiClient
1462
+ });
1463
+ const txDraftBase64 = Buffer.from(txBytes).toString("base64");
1464
+ const txDigest = await transaction.getDigest();
1465
+ return {
1466
+ sender,
1467
+ recipient,
1468
+ amountMIST,
1469
+ txDraftBase64,
1470
+ txDigest
1471
+ };
1472
+ } catch (error) {
1473
+ throw new Error(`Failed to create draft transaction: ${error instanceof Error ? error.message : "Unknown error"}`);
1474
+ }
1475
+ }
1476
+ async execute(draftTx, privateKey) {
1477
+ try {
1478
+ tiny_invariant(draftTx, "Draft transaction is required");
1479
+ tiny_invariant(draftTx.txDraftBase64?.trim(), "Transaction data is required");
1480
+ const keypair = this.validatePrivateKey(privateKey, draftTx.sender);
1481
+ const txBytes = fromBase64(draftTx.txDraftBase64);
1482
+ const { signature } = await keypair.signTransaction(txBytes);
1483
+ const result = await this.suiClient.executeTransactionBlock({
1484
+ transactionBlock: txBytes,
1485
+ signature
1486
+ });
1487
+ return {
1488
+ success: true,
1489
+ txDigest: result.digest,
1490
+ effects: result.effects
1491
+ };
1492
+ } catch (error) {
1493
+ const errorMessage = error instanceof Error ? error.message : "Unknown error occurred";
1494
+ return {
1495
+ success: false,
1496
+ error: errorMessage
1497
+ };
1498
+ }
1499
+ }
1500
+ async getTransactionStatus(txDigest) {
1501
+ tiny_invariant(txDigest?.trim(), "Transaction digest is required");
1502
+ try {
1503
+ const txResponse = await this.suiClient.getTransactionBlock({
1504
+ digest: txDigest,
1505
+ options: {
1506
+ showEffects: true
1507
+ }
1508
+ });
1509
+ if (!txResponse?.effects?.status) return "pending";
1510
+ return "success" === txResponse.effects.status.status ? "success" : "failure";
1511
+ } catch (error) {
1512
+ if (error instanceof Error) {
1513
+ if (error.message.includes("not found") || error.message.includes("Could not find")) return "pending";
1514
+ }
1515
+ return "failure";
1516
+ }
1517
+ }
1518
+ }
1519
+ 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.9",
3
+ "version": "0.0.11",
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-aggregator.git"
19
+ "url": "git@github.com:minswap/noodles-sdk.git"
20
20
  },
21
21
  "devDependencies": {
22
22
  "@biomejs/biome": "2.2.4",
@@ -46,10 +46,14 @@
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",
52
55
  "dev": "rslib build --watch",
53
- "format": "biome format --write"
56
+ "format": "biome check --write",
57
+ "typecheck": "tsc --noEmit"
54
58
  }
55
59
  }