@coin-voyage/crypto 3.0.0-beta.1 → 3.0.0

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.
@@ -19,7 +19,7 @@ export function createCoinVoyageDAppKit(config) {
19
19
  },
20
20
  autoConnect: walletConfiguration?.autoConnect ?? false,
21
21
  enableBurnerWallet: walletConfiguration?.enableBurnerWallet,
22
- slushWalletConfig: walletConfiguration?.slushWalletConfig,
22
+ slushWalletConfig: walletConfiguration?.slushWalletConfig ?? null,
23
23
  storage: walletConfiguration?.storage,
24
24
  storageKey: walletConfiguration?.storageKey ?? DEFAULT_STORAGE_KEY,
25
25
  walletInitializers: walletConfiguration?.walletInitializers,
@@ -2,6 +2,48 @@ import { useCurrentClient, useDAppKit } from "@mysten/dapp-kit-react";
2
2
  import { Transaction } from "@mysten/sui/transactions";
3
3
  import { fromBase64 } from "@mysten/sui/utils";
4
4
  import { SUI_PACKAGE_IDS } from "./constants";
5
+ async function buildSuiTransferTransaction({ client, owner, to, amount, token, }) {
6
+ const tokenAddress = token?.address;
7
+ const isNative = !tokenAddress || tokenAddress.toLowerCase() === SUI_PACKAGE_IDS["sui"].toLowerCase();
8
+ const tx = new Transaction();
9
+ const value = BigInt(amount);
10
+ if (isNative) {
11
+ const balanceResponse = await client.core.getBalance({
12
+ owner,
13
+ coinType: SUI_PACKAGE_IDS["sui"],
14
+ });
15
+ if (BigInt(balanceResponse.balance.balance) < value) {
16
+ throw new Error(`[CHECKOUT] Insufficient balance: ${balanceResponse.balance.balance}`);
17
+ }
18
+ const [coin] = tx.splitCoins(tx.gas, [value]);
19
+ tx.transferObjects([coin], to);
20
+ }
21
+ else {
22
+ const coins = await client.core.listCoins({
23
+ owner,
24
+ coinType: tokenAddress,
25
+ });
26
+ let total = BigInt(0);
27
+ const coinInputs = [];
28
+ for (const c of coins.objects) {
29
+ coinInputs.push(tx.object(c.objectId));
30
+ total += BigInt(c.balance);
31
+ if (total >= value)
32
+ break;
33
+ }
34
+ if (total < value)
35
+ throw new Error("Insufficient balance");
36
+ const coinInput = coinInputs[0];
37
+ if (!coinInput)
38
+ throw new Error("Insufficient balance");
39
+ if (coinInputs.length > 1) {
40
+ tx.mergeCoins(coinInput, coinInputs.slice(1));
41
+ }
42
+ const [paymentCoin] = tx.splitCoins(coinInput, [value]);
43
+ tx.transferObjects([paymentCoin], to);
44
+ }
45
+ return tx;
46
+ }
5
47
  export function useSUITransaction() {
6
48
  const client = useCurrentClient();
7
49
  const { signTransaction } = useDAppKit();
@@ -29,45 +71,13 @@ export function useSUITransaction() {
29
71
  if (!to || amount == undefined) {
30
72
  throw new Error("Missing Sui transfer target or amount");
31
73
  }
32
- const tokenAddress = token?.address;
33
- const isNative = !tokenAddress || tokenAddress.toLowerCase() === SUI_PACKAGE_IDS["sui"].toLowerCase();
34
- const tx = new Transaction();
35
- const value = BigInt(amount);
36
- if (isNative) {
37
- const balanceResponse = await client.core.getBalance({
38
- owner,
39
- coinType: SUI_PACKAGE_IDS["sui"],
40
- });
41
- if (BigInt(balanceResponse.balance.balance) < value) {
42
- throw new Error(`[CHECKOUT] Insufficient balance: ${balanceResponse.balance.balance}`);
43
- }
44
- const [coin] = tx.splitCoins(tx.gas, [value]);
45
- tx.transferObjects([coin], to);
46
- }
47
- else {
48
- const coins = await client.core.listCoins({
49
- owner,
50
- coinType: tokenAddress,
51
- });
52
- let total = BigInt(0);
53
- const coinInputs = [];
54
- for (const c of coins.objects) {
55
- coinInputs.push(tx.object(c.objectId));
56
- total += BigInt(c.balance);
57
- if (total >= value)
58
- break;
59
- }
60
- if (total < value)
61
- throw new Error("Insufficient balance");
62
- const coinInput = coinInputs[0];
63
- if (!coinInput)
64
- throw new Error("Insufficient balance");
65
- if (coinInputs.length > 1) {
66
- tx.mergeCoins(coinInput, coinInputs.slice(1));
67
- }
68
- const [paymentCoin] = tx.splitCoins(coinInput, [value]);
69
- tx.transferObjects([paymentCoin], to);
70
- }
74
+ const tx = await buildSuiTransferTransaction({
75
+ client,
76
+ owner,
77
+ to,
78
+ amount,
79
+ token,
80
+ });
71
81
  const gasPrice = await client.core.getReferenceGasPrice();
72
82
  tx.setGasPrice(gasPrice.referenceGasPrice);
73
83
  const signedTransaction = await signTransaction({
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@coin-voyage/crypto",
3
3
  "description": "Crypto utilities for Coin Voyage",
4
- "version": "3.0.0-beta.1",
4
+ "version": "3.0.0",
5
5
  "private": false,
6
6
  "sideEffects": false,
7
7
  "author": "Lars <lars@coinvoyage.io>",
@@ -104,7 +104,7 @@
104
104
  "bitcoinjs-lib": "6.1.7",
105
105
  "bitcoinjs-message": "2.2.0",
106
106
  "bitcoin-address-validation": "3.0.0",
107
- "@mysten/sui": "2.16.2",
107
+ "@mysten/sui": "2.20.0",
108
108
  "@solana/web3.js": "1.98.4",
109
109
  "@solana/spl-token": "0.4.14",
110
110
  "@solana/wallet-standard-features": "1.3.0",
@@ -112,14 +112,14 @@
112
112
  "@solana/wallet-adapter-walletconnect": "0.1.21",
113
113
  "@solana/wallet-adapter-base": "0.9.27",
114
114
  "@solana/wallet-adapter-coinbase": "0.1.23",
115
- "@coin-voyage/shared": "3.0.0-beta.1"
115
+ "@coin-voyage/shared": "3.0.0"
116
116
  },
117
117
  "devDependencies": {
118
118
  "@types/elliptic": "6.4.18"
119
119
  },
120
120
  "peerDependencies": {
121
121
  "@bigmi/react": "^0.8.0",
122
- "@mysten/dapp-kit-react": "^2.0.3",
122
+ "@mysten/dapp-kit-react": "^2.1.4",
123
123
  "@solana/wallet-adapter-react": "^0.15.39",
124
124
  "@tanstack/react-query": "^5.90.6",
125
125
  "react": "^18 || ^19",