@aptos-labs/cross-chain-core 5.4.16 → 5.6.0-alpha.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.
@@ -78,19 +78,15 @@ export const mainnetChains: ChainsConfig = {
78
78
  symbol: "MATIC",
79
79
  defaultRpc: "https://polygon-bor-rpc.publicnode.com",
80
80
  },
81
- // Sui: {
82
- // key: "Sui",
83
- // id: 21,
84
- // context: Context.SUI,
85
- // finalityThreshold: 0,
86
- // displayName: "Sui",
87
- // sdkName: "Sui",
88
- // explorerUrl: "https://suiscan.xyz/",
89
- // explorerName: "Suiscan",
90
- // gasToken: "SUI",
91
- // chainId: 0,
92
- // icon: "Sui",
93
- // maxBlockSearch: 0,
94
- // symbol: "SUI",
95
- // },
81
+ Sui: {
82
+ key: "Sui",
83
+ context: Context.SUI,
84
+ displayName: "Sui",
85
+ explorerUrl: "https://suiscan.xyz/",
86
+ explorerName: "Suiscan",
87
+ chainId: 0,
88
+ icon: "Sui",
89
+ symbol: "SUI",
90
+ defaultRpc: "https://fullnode.mainnet.sui.io:443",
91
+ },
96
92
  };
@@ -65,14 +65,14 @@ export const mainnetTokens: Record<string, TokenConfig> = {
65
65
  address: "0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359",
66
66
  },
67
67
  },
68
- // Sui: {
69
- // symbol: "USDC",
70
- // decimals: 6,
71
- // tokenId: {
72
- // chain: "Sui",
73
- // address:
74
- // "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC",
75
- // },
76
- // icon: "USDC",
77
- // },
68
+ Sui: {
69
+ symbol: "USDC",
70
+ decimals: 6,
71
+ tokenId: {
72
+ chain: "Sui",
73
+ address:
74
+ "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC",
75
+ },
76
+ icon: "USDC",
77
+ },
78
78
  };
@@ -79,19 +79,15 @@ export const testnetChains: ChainsConfig = {
79
79
  symbol: "APT",
80
80
  defaultRpc: "https://fullnode.testnet.aptos.dev",
81
81
  },
82
- // Sui: {
83
- // key: "Sui",
84
- // id: 21,
85
- // context: Context.SUI,
86
- // finalityThreshold: 0,
87
- // displayName: "Sui",
88
- // explorerUrl: "https://suiscan.xyz/testnet/",
89
- // explorerName: "Suiscan",
90
- // gasToken: "SUI",
91
- // chainId: 0,
92
- // icon: "Sui",
93
- // maxBlockSearch: 0,
94
- // symbol: "SUI",
95
- // sdkName: "Sui",
96
- // },
82
+ Sui: {
83
+ key: "Sui",
84
+ context: Context.SUI,
85
+ displayName: "Sui",
86
+ explorerUrl: "https://suiscan.xyz/testnet",
87
+ explorerName: "Suiscan",
88
+ chainId: 0,
89
+ icon: "Sui",
90
+ symbol: "SUI",
91
+ defaultRpc: "https://fullnode.testnet.sui.io:443",
92
+ },
97
93
  };
@@ -65,14 +65,14 @@ export const testnetTokens: Record<string, TokenConfig> = {
65
65
  address: "0x41E94Eb019C0762f9Bfcf9Fb1E58725BfB0e7582",
66
66
  },
67
67
  },
68
- // Sui: {
69
- // symbol: "USDC",
70
- // tokenId: {
71
- // chain: "Sui",
72
- // address:
73
- // "0xa1ec7fc00a6f40db9693ad1415d0c193ad3906494428cf252621037bd7117e29::usdc::USDC",
74
- // },
75
- // icon: "USDC",
76
- // decimals: 6,
77
- // },
68
+ Sui: {
69
+ symbol: "USDC",
70
+ tokenId: {
71
+ chain: "Sui",
72
+ address:
73
+ "0xa1ec7fc00a6f40db9693ad1415d0c193ad3906494428cf252621037bd7117e29::usdc::USDC",
74
+ },
75
+ icon: "USDC",
76
+ decimals: 6,
77
+ },
78
78
  };
@@ -4,6 +4,7 @@ export enum Context {
4
4
  ETH = "Ethereum",
5
5
  SOLANA = "Solana",
6
6
  APTOS = "Aptos",
7
+ SUI = "Sui",
7
8
  }
8
9
 
9
10
  export type BaseChainConfig = {
@@ -11,15 +11,15 @@ import {
11
11
  EvmUnsignedTransaction,
12
12
  EvmChains,
13
13
  } from "@wormhole-foundation/sdk-evm";
14
+ import {
15
+ SuiChains,
16
+ SuiUnsignedTransaction,
17
+ } from "@wormhole-foundation/sdk-sui";
14
18
 
15
19
  import * as solanaSigner from "./SolanaSigner";
16
20
  import * as ethereumSigner from "./EthereumSigner";
17
21
  import * as aptosSigner from "./AptosSigner";
18
- // import {
19
- // SuiChains,
20
- // SuiUnsignedTransaction,
21
- // } from "@wormhole-foundation/sdk-sui";
22
- // import * as suiSigner from "./SuiSigner";
22
+ import * as suiSigner from "./SuiSigner";
23
23
 
24
24
  import { ChainConfig } from "../../../config";
25
25
  import { CrossChainCore } from "../../../CrossChainCore";
@@ -114,6 +114,12 @@ export const signAndSendTransaction = async (
114
114
  options,
115
115
  );
116
116
  return tx;
117
+ } else if (chain.context === "Sui") {
118
+ const tx = await suiSigner.signAndSendTransaction(
119
+ request as SuiUnsignedTransaction<Network, SuiChains>,
120
+ wallet,
121
+ );
122
+ return tx;
117
123
  } else if (chain.context === "Aptos") {
118
124
  const tx = await aptosSigner.signAndSendTransaction(
119
125
  request as AptosUnsignedTransaction<Network, AptosChains>,
@@ -0,0 +1,42 @@
1
+ import { AdapterWallet } from "@aptos-labs/wallet-adapter-core";
2
+ import { Network } from "@wormhole-foundation/sdk";
3
+ import {
4
+ SuiChains,
5
+ SuiUnsignedTransaction,
6
+ } from "@wormhole-foundation/sdk-sui";
7
+ import { SuiDerivedWallet } from "@aptos-labs/derived-wallet-sui";
8
+ import {
9
+ SuiSignAndExecuteTransactionInput,
10
+ SuiSignAndExecuteTransactionOutput,
11
+ } from "@mysten/wallet-standard";
12
+
13
+ export async function signAndSendTransaction(
14
+ request: SuiUnsignedTransaction<Network, SuiChains>,
15
+ wallet: AdapterWallet,
16
+ ): Promise<string> {
17
+ if (!wallet) {
18
+ throw new Error("wallet is undefined");
19
+ }
20
+ const suiDerivedWallet = wallet as SuiDerivedWallet;
21
+
22
+ const signAndExecuteTransactionFeature = suiDerivedWallet.suiWallet.features[
23
+ "sui:signAndExecuteTransaction"
24
+ ] as {
25
+ signAndExecuteTransaction: (
26
+ input: SuiSignAndExecuteTransactionInput,
27
+ ) => Promise<SuiSignAndExecuteTransactionOutput>;
28
+ };
29
+
30
+ if (!signAndExecuteTransactionFeature) {
31
+ throw new Error("wallet does not support signAndExecuteTransaction");
32
+ }
33
+
34
+ const { digest } =
35
+ await signAndExecuteTransactionFeature.signAndExecuteTransaction({
36
+ transaction: request.transaction,
37
+ account: suiDerivedWallet.suiWallet.accounts[0],
38
+ chain: `sui:${request.network.toLocaleLowerCase()}`,
39
+ });
40
+
41
+ return digest;
42
+ }
@@ -11,6 +11,7 @@ import { Network, sleep } from "@aptos-labs/ts-sdk";
11
11
  import aptos from "@wormhole-foundation/sdk/aptos";
12
12
  import solana from "@wormhole-foundation/sdk/solana";
13
13
  import evm from "@wormhole-foundation/sdk/evm";
14
+ import sui from "@wormhole-foundation/sdk/sui";
14
15
 
15
16
  import {
16
17
  Chain,
@@ -36,6 +37,7 @@ import {
36
37
  } from "./types";
37
38
  import { SolanaDerivedWallet } from "@aptos-labs/derived-wallet-solana";
38
39
  import { EIP1193DerivedWallet } from "@aptos-labs/derived-wallet-ethereum";
40
+ import { SuiDerivedWallet } from "@aptos-labs/derived-wallet-sui";
39
41
 
40
42
  export class WormholeProvider implements CrossChainProvider<
41
43
  WormholeQuoteRequest,
@@ -70,7 +72,7 @@ export class WormholeProvider implements CrossChainProvider<
70
72
  throw new Error("Origin chain not selected");
71
73
  }
72
74
  const isMainnet = dappNetwork === Network.MAINNET;
73
- const platforms: PlatformLoader<any>[] = [aptos, solana, evm];
75
+ const platforms: PlatformLoader<any>[] = [aptos, solana, evm, sui];
74
76
  const wh = await wormhole(isMainnet ? "Mainnet" : "Testnet", platforms);
75
77
  this._wormholeContext = wh;
76
78
  }
@@ -187,13 +189,18 @@ export class WormholeProvider implements CrossChainProvider<
187
189
  signerAddress =
188
190
  (wallet as SolanaDerivedWallet).solanaWallet.publicKey?.toBase58() ||
189
191
  "";
190
- } else {
192
+ } else if (chainContext === "Ethereum") {
191
193
  // is Ethereum
192
194
  [signerAddress] = await (
193
195
  wallet as EIP1193DerivedWallet
194
196
  ).eip1193Provider.request({
195
197
  method: "eth_requestAccounts",
196
198
  });
199
+ } else if (chainContext === "Sui") {
200
+ signerAddress =
201
+ (wallet as SuiDerivedWallet).suiWallet.accounts[0].address || "";
202
+ } else {
203
+ throw new Error("Unsupported chain context: " + chainContext);
197
204
  }
198
205
  logger.log("signerAddress", signerAddress);
199
206
 
@@ -3,6 +3,7 @@ import { Connection, PublicKey } from "@solana/web3.js";
3
3
  import { mainnetTokens, testnetTokens } from "../config";
4
4
  import { ethers, JsonRpcProvider } from "ethers";
5
5
  import { Chain } from "../CrossChainCore";
6
+ import { SuiClient } from "@mysten/sui/client";
6
7
 
7
8
  export const getSolanaWalletUSDCBalance = async (
8
9
  walletAddress: string,
@@ -29,7 +30,7 @@ export const getSolanaWalletUSDCBalance = async (
29
30
 
30
31
  return (
31
32
  balance.value.uiAmountString ??
32
- (Number(balance.value.amount) / 10 ** balance.value.decimals).toString()
33
+ ethers.formatUnits(BigInt(balance.value.amount), balance.value.decimals)
33
34
  );
34
35
  };
35
36
 
@@ -74,9 +75,26 @@ export const getAptosWalletUSDCBalance = async (
74
75
  if (response.length === 0) {
75
76
  return "0";
76
77
  }
77
- const balance = (
78
- Number(response[0].amount) /
79
- 10 ** token.decimals
80
- ).toString();
81
- return balance;
78
+ return ethers.formatUnits(BigInt(response[0].amount), token.decimals);
79
+ };
80
+
81
+ export const getSuiWalletUSDCBalance = async (
82
+ walletAddress: string,
83
+ aptosNetwork: Network,
84
+ rpc: string,
85
+ ): Promise<string> => {
86
+ const token =
87
+ aptosNetwork === Network.MAINNET
88
+ ? mainnetTokens["Sui"]
89
+ : testnetTokens["Sui"];
90
+
91
+ const client = new SuiClient({
92
+ url: rpc,
93
+ });
94
+ const balance = await client.getBalance({
95
+ owner: walletAddress,
96
+ coinType: token.tokenId.address,
97
+ });
98
+ // Reuse ethers' formatter for precise decimal formatting of large integers.
99
+ return ethers.formatUnits(BigInt(balance.totalBalance), token.decimals);
82
100
  };
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const CROSS_CHAIN_CORE_VERSION = "5.4.16";
1
+ export const CROSS_CHAIN_CORE_VERSION = "5.6.0-alpha.0";