@aptos-labs/cross-chain-core 5.5.0 → 5.6.0-alpha.1
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/CrossChainCore.d.ts +1 -1
- package/dist/CrossChainCore.d.ts.map +1 -1
- package/dist/config/mainnet/chains.d.ts.map +1 -1
- package/dist/config/testnet/chains.d.ts.map +1 -1
- package/dist/config/types.d.ts +2 -1
- package/dist/config/types.d.ts.map +1 -1
- package/dist/index.d.mts +3 -2
- package/dist/index.js +94 -57
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +94 -57
- package/dist/index.mjs.map +1 -1
- package/dist/providers/wormhole/signers/AptosLocalSigner.d.ts.map +1 -1
- package/dist/providers/wormhole/signers/Signer.d.ts.map +1 -1
- package/dist/providers/wormhole/signers/SuiSigner.d.ts.map +1 -1
- package/dist/providers/wormhole/wormhole.d.ts.map +1 -1
- package/dist/utils/getUsdcBalance.d.ts +1 -0
- package/dist/utils/getUsdcBalance.d.ts.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.d.ts.map +1 -1
- package/package.json +13 -12
- package/src/CrossChainCore.ts +10 -1
- package/src/config/mainnet/chains.ts +11 -15
- package/src/config/mainnet/tokens.ts +10 -10
- package/src/config/testnet/chains.ts +11 -15
- package/src/config/testnet/tokens.ts +10 -10
- package/src/config/types.ts +1 -0
- package/src/providers/wormhole/signers/AptosLocalSigner.ts +4 -3
- package/src/providers/wormhole/signers/Signer.ts +15 -8
- package/src/providers/wormhole/signers/SuiSigner.ts +42 -0
- package/src/providers/wormhole/wormhole.ts +17 -13
- package/src/utils/getUsdcBalance.ts +24 -6
- package/src/version.ts +1 -1
package/dist/index.mjs
CHANGED
|
@@ -13,6 +13,7 @@ import { Network, sleep as sleep2 } from "@aptos-labs/ts-sdk";
|
|
|
13
13
|
import aptos from "@wormhole-foundation/sdk/aptos";
|
|
14
14
|
import solana from "@wormhole-foundation/sdk/solana";
|
|
15
15
|
import evm from "@wormhole-foundation/sdk/evm";
|
|
16
|
+
import sui from "@wormhole-foundation/sdk/sui";
|
|
16
17
|
|
|
17
18
|
// src/utils/logger.ts
|
|
18
19
|
var logger = {
|
|
@@ -492,6 +493,24 @@ function extractFunctionArguments(functionArguments) {
|
|
|
492
493
|
return [amount, destination_domain, mint_recipient, burn_token];
|
|
493
494
|
}
|
|
494
495
|
|
|
496
|
+
// src/providers/wormhole/signers/SuiSigner.ts
|
|
497
|
+
async function signAndSendTransaction5(request, wallet) {
|
|
498
|
+
if (!wallet) {
|
|
499
|
+
throw new Error("wallet is undefined");
|
|
500
|
+
}
|
|
501
|
+
const suiDerivedWallet = wallet;
|
|
502
|
+
const signAndExecuteTransactionFeature = suiDerivedWallet.suiWallet.features["sui:signAndExecuteTransaction"];
|
|
503
|
+
if (!signAndExecuteTransactionFeature) {
|
|
504
|
+
throw new Error("wallet does not support signAndExecuteTransaction");
|
|
505
|
+
}
|
|
506
|
+
const { digest } = await signAndExecuteTransactionFeature.signAndExecuteTransaction({
|
|
507
|
+
transaction: request.transaction,
|
|
508
|
+
account: suiDerivedWallet.suiWallet.accounts[0],
|
|
509
|
+
chain: `sui:${request.network.toLocaleLowerCase()}`
|
|
510
|
+
});
|
|
511
|
+
return digest;
|
|
512
|
+
}
|
|
513
|
+
|
|
495
514
|
// src/providers/wormhole/signers/Signer.ts
|
|
496
515
|
var Signer = class {
|
|
497
516
|
constructor(chain, address, options, wallet, crossChainCore, sponsorAccount) {
|
|
@@ -515,7 +534,7 @@ var Signer = class {
|
|
|
515
534
|
async signAndSend(txs) {
|
|
516
535
|
const txHashes = [];
|
|
517
536
|
for (const tx of txs) {
|
|
518
|
-
const txId = await
|
|
537
|
+
const txId = await signAndSendTransaction6(
|
|
519
538
|
this._chain,
|
|
520
539
|
tx,
|
|
521
540
|
this._wallet,
|
|
@@ -529,7 +548,7 @@ var Signer = class {
|
|
|
529
548
|
return txHashes;
|
|
530
549
|
}
|
|
531
550
|
};
|
|
532
|
-
var
|
|
551
|
+
var signAndSendTransaction6 = async (chain, request, wallet, options = {}, crossChainCore, sponsorAccount) => {
|
|
533
552
|
if (!wallet) {
|
|
534
553
|
throw new Error("wallet is undefined");
|
|
535
554
|
}
|
|
@@ -549,6 +568,12 @@ var signAndSendTransaction5 = async (chain, request, wallet, options = {}, cross
|
|
|
549
568
|
options
|
|
550
569
|
);
|
|
551
570
|
return tx;
|
|
571
|
+
} else if (chain.context === "Sui") {
|
|
572
|
+
const tx = await signAndSendTransaction5(
|
|
573
|
+
request,
|
|
574
|
+
wallet
|
|
575
|
+
);
|
|
576
|
+
return tx;
|
|
552
577
|
} else if (chain.context === "Aptos") {
|
|
553
578
|
const tx = await signAndSendTransaction4(
|
|
554
579
|
request,
|
|
@@ -578,7 +603,7 @@ var WormholeProvider = class {
|
|
|
578
603
|
throw new Error("Origin chain not selected");
|
|
579
604
|
}
|
|
580
605
|
const isMainnet = dappNetwork === Network.MAINNET;
|
|
581
|
-
const platforms = [aptos, solana, evm];
|
|
606
|
+
const platforms = [aptos, solana, evm, sui];
|
|
582
607
|
const wh = await wormhole(isMainnet ? "Mainnet" : "Testnet", platforms);
|
|
583
608
|
this._wormholeContext = wh;
|
|
584
609
|
}
|
|
@@ -657,10 +682,14 @@ var WormholeProvider = class {
|
|
|
657
682
|
const chainContext = this.getChainConfig(sourceChain).context;
|
|
658
683
|
if (chainContext === "Solana") {
|
|
659
684
|
signerAddress = wallet.solanaWallet.publicKey?.toBase58() || "";
|
|
660
|
-
} else {
|
|
685
|
+
} else if (chainContext === "Ethereum") {
|
|
661
686
|
[signerAddress] = await wallet.eip1193Provider.request({
|
|
662
687
|
method: "eth_requestAccounts"
|
|
663
688
|
});
|
|
689
|
+
} else if (chainContext === "Sui") {
|
|
690
|
+
signerAddress = wallet.suiWallet.accounts[0].address || "";
|
|
691
|
+
} else {
|
|
692
|
+
throw new Error("Unsupported chain context: " + chainContext);
|
|
664
693
|
}
|
|
665
694
|
logger.log("signerAddress", signerAddress);
|
|
666
695
|
const signer = new Signer(
|
|
@@ -870,6 +899,7 @@ var Context = /* @__PURE__ */ ((Context2) => {
|
|
|
870
899
|
Context2["ETH"] = "Ethereum";
|
|
871
900
|
Context2["SOLANA"] = "Solana";
|
|
872
901
|
Context2["APTOS"] = "Aptos";
|
|
902
|
+
Context2["SUI"] = "Sui";
|
|
873
903
|
return Context2;
|
|
874
904
|
})(Context || {});
|
|
875
905
|
|
|
@@ -951,22 +981,18 @@ var testnetChains = {
|
|
|
951
981
|
icon: "Aptos",
|
|
952
982
|
symbol: "APT",
|
|
953
983
|
defaultRpc: "https://fullnode.testnet.aptos.dev"
|
|
984
|
+
},
|
|
985
|
+
Sui: {
|
|
986
|
+
key: "Sui",
|
|
987
|
+
context: "Sui" /* SUI */,
|
|
988
|
+
displayName: "Sui",
|
|
989
|
+
explorerUrl: "https://suiscan.xyz/testnet",
|
|
990
|
+
explorerName: "Suiscan",
|
|
991
|
+
chainId: 0,
|
|
992
|
+
icon: "Sui",
|
|
993
|
+
symbol: "SUI",
|
|
994
|
+
defaultRpc: "https://fullnode.testnet.sui.io:443"
|
|
954
995
|
}
|
|
955
|
-
// Sui: {
|
|
956
|
-
// key: "Sui",
|
|
957
|
-
// id: 21,
|
|
958
|
-
// context: Context.SUI,
|
|
959
|
-
// finalityThreshold: 0,
|
|
960
|
-
// displayName: "Sui",
|
|
961
|
-
// explorerUrl: "https://suiscan.xyz/testnet/",
|
|
962
|
-
// explorerName: "Suiscan",
|
|
963
|
-
// gasToken: "SUI",
|
|
964
|
-
// chainId: 0,
|
|
965
|
-
// icon: "Sui",
|
|
966
|
-
// maxBlockSearch: 0,
|
|
967
|
-
// symbol: "SUI",
|
|
968
|
-
// sdkName: "Sui",
|
|
969
|
-
// },
|
|
970
996
|
};
|
|
971
997
|
|
|
972
998
|
// src/config/testnet/tokens.ts
|
|
@@ -1033,17 +1059,16 @@ var testnetTokens = {
|
|
|
1033
1059
|
chain: "PolygonSepolia",
|
|
1034
1060
|
address: "0x41E94Eb019C0762f9Bfcf9Fb1E58725BfB0e7582"
|
|
1035
1061
|
}
|
|
1062
|
+
},
|
|
1063
|
+
Sui: {
|
|
1064
|
+
symbol: "USDC",
|
|
1065
|
+
tokenId: {
|
|
1066
|
+
chain: "Sui",
|
|
1067
|
+
address: "0xa1ec7fc00a6f40db9693ad1415d0c193ad3906494428cf252621037bd7117e29::usdc::USDC"
|
|
1068
|
+
},
|
|
1069
|
+
icon: "USDC",
|
|
1070
|
+
decimals: 6
|
|
1036
1071
|
}
|
|
1037
|
-
// Sui: {
|
|
1038
|
-
// symbol: "USDC",
|
|
1039
|
-
// tokenId: {
|
|
1040
|
-
// chain: "Sui",
|
|
1041
|
-
// address:
|
|
1042
|
-
// "0xa1ec7fc00a6f40db9693ad1415d0c193ad3906494428cf252621037bd7117e29::usdc::USDC",
|
|
1043
|
-
// },
|
|
1044
|
-
// icon: "USDC",
|
|
1045
|
-
// decimals: 6,
|
|
1046
|
-
// },
|
|
1047
1072
|
};
|
|
1048
1073
|
|
|
1049
1074
|
// src/config/mainnet/chains.ts
|
|
@@ -1124,22 +1149,18 @@ var mainnetChains = {
|
|
|
1124
1149
|
icon: "Polygon",
|
|
1125
1150
|
symbol: "MATIC",
|
|
1126
1151
|
defaultRpc: "https://polygon-bor-rpc.publicnode.com"
|
|
1152
|
+
},
|
|
1153
|
+
Sui: {
|
|
1154
|
+
key: "Sui",
|
|
1155
|
+
context: "Sui" /* SUI */,
|
|
1156
|
+
displayName: "Sui",
|
|
1157
|
+
explorerUrl: "https://suiscan.xyz/",
|
|
1158
|
+
explorerName: "Suiscan",
|
|
1159
|
+
chainId: 0,
|
|
1160
|
+
icon: "Sui",
|
|
1161
|
+
symbol: "SUI",
|
|
1162
|
+
defaultRpc: "https://fullnode.mainnet.sui.io:443"
|
|
1127
1163
|
}
|
|
1128
|
-
// Sui: {
|
|
1129
|
-
// key: "Sui",
|
|
1130
|
-
// id: 21,
|
|
1131
|
-
// context: Context.SUI,
|
|
1132
|
-
// finalityThreshold: 0,
|
|
1133
|
-
// displayName: "Sui",
|
|
1134
|
-
// sdkName: "Sui",
|
|
1135
|
-
// explorerUrl: "https://suiscan.xyz/",
|
|
1136
|
-
// explorerName: "Suiscan",
|
|
1137
|
-
// gasToken: "SUI",
|
|
1138
|
-
// chainId: 0,
|
|
1139
|
-
// icon: "Sui",
|
|
1140
|
-
// maxBlockSearch: 0,
|
|
1141
|
-
// symbol: "SUI",
|
|
1142
|
-
// },
|
|
1143
1164
|
};
|
|
1144
1165
|
|
|
1145
1166
|
// src/config/mainnet/tokens.ts
|
|
@@ -1206,23 +1227,23 @@ var mainnetTokens = {
|
|
|
1206
1227
|
chain: "Polygon",
|
|
1207
1228
|
address: "0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359"
|
|
1208
1229
|
}
|
|
1230
|
+
},
|
|
1231
|
+
Sui: {
|
|
1232
|
+
symbol: "USDC",
|
|
1233
|
+
decimals: 6,
|
|
1234
|
+
tokenId: {
|
|
1235
|
+
chain: "Sui",
|
|
1236
|
+
address: "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC"
|
|
1237
|
+
},
|
|
1238
|
+
icon: "USDC"
|
|
1209
1239
|
}
|
|
1210
|
-
// Sui: {
|
|
1211
|
-
// symbol: "USDC",
|
|
1212
|
-
// decimals: 6,
|
|
1213
|
-
// tokenId: {
|
|
1214
|
-
// chain: "Sui",
|
|
1215
|
-
// address:
|
|
1216
|
-
// "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC",
|
|
1217
|
-
// },
|
|
1218
|
-
// icon: "USDC",
|
|
1219
|
-
// },
|
|
1220
1240
|
};
|
|
1221
1241
|
|
|
1222
1242
|
// src/utils/getUsdcBalance.ts
|
|
1223
1243
|
import { Aptos as Aptos3, AptosConfig as AptosConfig3, Network as Network2 } from "@aptos-labs/ts-sdk";
|
|
1224
1244
|
import { Connection as Connection2, PublicKey } from "@solana/web3.js";
|
|
1225
1245
|
import { ethers as ethers2, JsonRpcProvider } from "ethers";
|
|
1246
|
+
import { SuiClient } from "@mysten/sui/client";
|
|
1226
1247
|
var getSolanaWalletUSDCBalance = async (walletAddress, aptosNetwork, rpc) => {
|
|
1227
1248
|
const address = new PublicKey(walletAddress);
|
|
1228
1249
|
const tokenAddress = aptosNetwork === Network2.MAINNET ? mainnetTokens["Solana"].tokenId.address : testnetTokens["Solana"].tokenId.address;
|
|
@@ -1232,7 +1253,7 @@ var getSolanaWalletUSDCBalance = async (walletAddress, aptosNetwork, rpc) => {
|
|
|
1232
1253
|
});
|
|
1233
1254
|
const checkAddress = splToken.value.length > 0 ? splToken.value[0].pubkey : address;
|
|
1234
1255
|
const balance = await connection.getTokenAccountBalance(checkAddress);
|
|
1235
|
-
return balance.value.uiAmountString ?? (
|
|
1256
|
+
return balance.value.uiAmountString ?? ethers2.formatUnits(BigInt(balance.value.amount), balance.value.decimals);
|
|
1236
1257
|
};
|
|
1237
1258
|
var getEthereumWalletUSDCBalance = async (walletAddress, aptosNetwork, chain, rpc) => {
|
|
1238
1259
|
const token = aptosNetwork === Network2.MAINNET ? mainnetTokens[chain] : testnetTokens[chain];
|
|
@@ -1259,8 +1280,18 @@ var getAptosWalletUSDCBalance = async (walletAddress, aptosNetwork) => {
|
|
|
1259
1280
|
if (response.length === 0) {
|
|
1260
1281
|
return "0";
|
|
1261
1282
|
}
|
|
1262
|
-
|
|
1263
|
-
|
|
1283
|
+
return ethers2.formatUnits(BigInt(response[0].amount), token.decimals);
|
|
1284
|
+
};
|
|
1285
|
+
var getSuiWalletUSDCBalance = async (walletAddress, aptosNetwork, rpc) => {
|
|
1286
|
+
const token = aptosNetwork === Network2.MAINNET ? mainnetTokens["Sui"] : testnetTokens["Sui"];
|
|
1287
|
+
const client = new SuiClient({
|
|
1288
|
+
url: rpc
|
|
1289
|
+
});
|
|
1290
|
+
const balance = await client.getBalance({
|
|
1291
|
+
owner: walletAddress,
|
|
1292
|
+
coinType: token.tokenId.address
|
|
1293
|
+
});
|
|
1294
|
+
return ethers2.formatUnits(BigInt(balance.totalBalance), token.decimals);
|
|
1264
1295
|
};
|
|
1265
1296
|
|
|
1266
1297
|
// src/CrossChainCore.ts
|
|
@@ -1336,6 +1367,12 @@ var CrossChainCore = class {
|
|
|
1336
1367
|
// TODO: maybe let the user config it
|
|
1337
1368
|
this.CHAINS[sourceChain].defaultRpc
|
|
1338
1369
|
);
|
|
1370
|
+
case "Sui":
|
|
1371
|
+
return await getSuiWalletUSDCBalance(
|
|
1372
|
+
walletAddress,
|
|
1373
|
+
this._dappConfig.aptosNetwork,
|
|
1374
|
+
this.CHAINS[sourceChain].defaultRpc
|
|
1375
|
+
);
|
|
1339
1376
|
default:
|
|
1340
1377
|
throw new Error(`Unsupported chain: ${sourceChain}`);
|
|
1341
1378
|
}
|