@aptos-labs/cross-chain-core 4.25.0 → 5.0.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/README.md +11 -0
- package/dist/CrossChainCore.d.ts +3 -3
- package/dist/CrossChainCore.d.ts.map +1 -1
- package/dist/config/mainnet/chains.d.ts +0 -14
- package/dist/config/mainnet/chains.d.ts.map +1 -1
- package/dist/config/mainnet/tokens.d.ts +0 -1
- package/dist/config/mainnet/tokens.d.ts.map +1 -1
- package/dist/config/testnet/chains.d.ts +0 -16
- package/dist/config/testnet/chains.d.ts.map +1 -1
- package/dist/config/testnet/tokens.d.ts +0 -1
- package/dist/config/testnet/tokens.d.ts.map +1 -1
- package/dist/index.js +272 -92
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +263 -73
- package/dist/index.mjs.map +1 -1
- package/dist/providers/wormhole/signers/AptosLocalSigner.d.ts.map +1 -1
- package/dist/providers/wormhole/signers/AptosSigner.d.ts +7 -0
- package/dist/providers/wormhole/signers/AptosSigner.d.ts.map +1 -0
- package/dist/providers/wormhole/signers/Signer.d.ts +7 -2
- package/dist/providers/wormhole/signers/Signer.d.ts.map +1 -1
- package/dist/providers/wormhole/types.d.ts +14 -3
- package/dist/providers/wormhole/types.d.ts.map +1 -1
- package/dist/providers/wormhole/wormhole.d.ts +7 -9
- package/dist/providers/wormhole/wormhole.d.ts.map +1 -1
- 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 +9 -9
- package/src/CrossChainCore.ts +18 -19
- package/src/config/mainnet/chains.ts +15 -15
- package/src/config/mainnet/tokens.ts +10 -11
- package/src/config/testnet/chains.ts +15 -16
- package/src/config/testnet/tokens.ts +10 -11
- package/src/providers/wormhole/signers/AptosLocalSigner.ts +4 -3
- package/src/providers/wormhole/signers/AptosSigner.ts +139 -0
- package/src/providers/wormhole/signers/Signer.ts +26 -2
- package/src/providers/wormhole/types.ts +16 -3
- package/src/providers/wormhole/wormhole.ts +165 -29
- package/src/utils/getUsdcBalance.ts +9 -11
- package/src/version.ts +1 -1
package/dist/index.mjs
CHANGED
|
@@ -416,14 +416,92 @@ async function signAndSendTransaction3(request, wallet, chainName, options) {
|
|
|
416
416
|
return receipt?.hash || "";
|
|
417
417
|
}
|
|
418
418
|
|
|
419
|
+
// src/providers/wormhole/signers/AptosSigner.ts
|
|
420
|
+
import {
|
|
421
|
+
AccountAddress,
|
|
422
|
+
Aptos as Aptos2,
|
|
423
|
+
AptosConfig as AptosConfig2,
|
|
424
|
+
Network as AptosNetwork2,
|
|
425
|
+
Deserializer
|
|
426
|
+
} from "@aptos-labs/ts-sdk";
|
|
427
|
+
import { UserResponseStatus } from "@aptos-labs/wallet-standard";
|
|
428
|
+
async function signAndSendTransaction4(request, wallet, sponsorAccount) {
|
|
429
|
+
if (!wallet) {
|
|
430
|
+
throw new Error("wallet.sendTransaction is undefined").message;
|
|
431
|
+
}
|
|
432
|
+
const payload = request.transaction;
|
|
433
|
+
payload.functionArguments = payload.functionArguments.map((a) => {
|
|
434
|
+
if (a instanceof Uint8Array) {
|
|
435
|
+
return Array.from(a);
|
|
436
|
+
} else if (typeof a === "bigint") {
|
|
437
|
+
return a.toString();
|
|
438
|
+
} else {
|
|
439
|
+
return a;
|
|
440
|
+
}
|
|
441
|
+
});
|
|
442
|
+
const aptosConfig = new AptosConfig2({
|
|
443
|
+
network: AptosNetwork2.TESTNET
|
|
444
|
+
});
|
|
445
|
+
const aptos2 = new Aptos2(aptosConfig);
|
|
446
|
+
const contractAddress = AptosNetwork2.TESTNET ? "0x5e2d961f06cd27aa07554a39d55f5ce1e58dff35d803c3529b1cd5c4fa3ab584" : "0x1";
|
|
447
|
+
const functionArguments = extractFunctionArguments(
|
|
448
|
+
payload.functionArguments
|
|
449
|
+
);
|
|
450
|
+
const transactionData = {
|
|
451
|
+
// a custom function to withdraw tokens from the aptos chain, published here on testnet:
|
|
452
|
+
// https://explorer.aptoslabs.com/account/0x5e2d961f06cd27aa07554a39d55f5ce1e58dff35d803c3529b1cd5c4fa3ab584/modules/code/withdraw?network=testnet
|
|
453
|
+
function: `${contractAddress}::withdraw::deposit_for_burn`,
|
|
454
|
+
functionArguments
|
|
455
|
+
};
|
|
456
|
+
const txnToSign = await aptos2.transaction.build.simple({
|
|
457
|
+
data: transactionData,
|
|
458
|
+
sender: (await wallet.features["aptos:account"]?.account()).address.toString(),
|
|
459
|
+
withFeePayer: sponsorAccount ? true : false
|
|
460
|
+
});
|
|
461
|
+
const response = await wallet.features["aptos:signTransaction"]?.signTransaction(txnToSign);
|
|
462
|
+
if (response?.status === UserResponseStatus.REJECTED) {
|
|
463
|
+
throw new Error("User has rejected the request");
|
|
464
|
+
}
|
|
465
|
+
const txnToSubmit = {
|
|
466
|
+
transaction: txnToSign,
|
|
467
|
+
senderAuthenticator: response.args
|
|
468
|
+
};
|
|
469
|
+
if (sponsorAccount) {
|
|
470
|
+
if (typeof sponsorAccount === "string") {
|
|
471
|
+
} else {
|
|
472
|
+
const feePayerSignerAuthenticator = aptos2.transaction.signAsFeePayer({
|
|
473
|
+
signer: sponsorAccount,
|
|
474
|
+
transaction: txnToSign
|
|
475
|
+
});
|
|
476
|
+
txnToSubmit.feePayerAuthenticator = feePayerSignerAuthenticator;
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
const txnSubmitted = await aptos2.transaction.submit.simple(txnToSubmit);
|
|
480
|
+
const tx = await aptos2.waitForTransaction({
|
|
481
|
+
transactionHash: txnSubmitted.hash
|
|
482
|
+
});
|
|
483
|
+
return tx.hash;
|
|
484
|
+
}
|
|
485
|
+
function extractFunctionArguments(functionArguments) {
|
|
486
|
+
const deserializer1 = new Deserializer(functionArguments[0].bcsToBytes());
|
|
487
|
+
const amount = deserializer1.deserializeU64();
|
|
488
|
+
const deserializer2 = new Deserializer(functionArguments[1].bcsToBytes());
|
|
489
|
+
const destination_domain = deserializer2.deserializeU32();
|
|
490
|
+
const mint_recipient = new AccountAddress(functionArguments[2].bcsToBytes());
|
|
491
|
+
const burn_token = new AccountAddress(functionArguments[3].bcsToBytes());
|
|
492
|
+
return [amount, destination_domain, mint_recipient, burn_token];
|
|
493
|
+
}
|
|
494
|
+
|
|
419
495
|
// src/providers/wormhole/signers/Signer.ts
|
|
420
496
|
var Signer = class {
|
|
421
|
-
constructor(chain, address, options, wallet, crossChainCore) {
|
|
497
|
+
constructor(chain, address, options, wallet, crossChainCore, sponsorAccount) {
|
|
422
498
|
this._chain = chain;
|
|
423
499
|
this._address = address;
|
|
424
500
|
this._options = options;
|
|
425
501
|
this._wallet = wallet;
|
|
426
502
|
this._crossChainCore = crossChainCore;
|
|
503
|
+
this._sponsorAccount = sponsorAccount;
|
|
504
|
+
this._claimedTransactionHashes = "";
|
|
427
505
|
}
|
|
428
506
|
chain() {
|
|
429
507
|
return this._chain.displayName;
|
|
@@ -431,22 +509,27 @@ var Signer = class {
|
|
|
431
509
|
address() {
|
|
432
510
|
return this._address;
|
|
433
511
|
}
|
|
512
|
+
claimedTransactionHashes() {
|
|
513
|
+
return this._claimedTransactionHashes;
|
|
514
|
+
}
|
|
434
515
|
async signAndSend(txs) {
|
|
435
516
|
const txHashes = [];
|
|
436
517
|
for (const tx of txs) {
|
|
437
|
-
const txId = await
|
|
518
|
+
const txId = await signAndSendTransaction5(
|
|
438
519
|
this._chain,
|
|
439
520
|
tx,
|
|
440
521
|
this._wallet,
|
|
441
522
|
this._options,
|
|
442
|
-
this._crossChainCore
|
|
523
|
+
this._crossChainCore,
|
|
524
|
+
this._sponsorAccount
|
|
443
525
|
);
|
|
444
526
|
txHashes.push(txId);
|
|
527
|
+
this._claimedTransactionHashes = txId;
|
|
445
528
|
}
|
|
446
529
|
return txHashes;
|
|
447
530
|
}
|
|
448
531
|
};
|
|
449
|
-
var
|
|
532
|
+
var signAndSendTransaction5 = async (chain, request, wallet, options = {}, crossChainCore, sponsorAccount) => {
|
|
450
533
|
if (!wallet) {
|
|
451
534
|
throw new Error("wallet is undefined");
|
|
452
535
|
}
|
|
@@ -466,6 +549,13 @@ var signAndSendTransaction4 = async (chain, request, wallet, options = {}, cross
|
|
|
466
549
|
options
|
|
467
550
|
);
|
|
468
551
|
return tx;
|
|
552
|
+
} else if (chain.context === "Aptos") {
|
|
553
|
+
const tx = await signAndSendTransaction4(
|
|
554
|
+
request,
|
|
555
|
+
wallet,
|
|
556
|
+
sponsorAccount
|
|
557
|
+
);
|
|
558
|
+
return tx;
|
|
469
559
|
} else {
|
|
470
560
|
throw new Error(`Unsupported chain: ${chain}`);
|
|
471
561
|
}
|
|
@@ -492,15 +582,20 @@ var WormholeProvider = class {
|
|
|
492
582
|
const wh = await wormhole(isMainnet ? "Mainnet" : "Testnet", platforms);
|
|
493
583
|
this._wormholeContext = wh;
|
|
494
584
|
}
|
|
495
|
-
async getRoute(sourceChain) {
|
|
585
|
+
async getRoute(sourceChain, destinationChain) {
|
|
496
586
|
if (!this._wormholeContext) {
|
|
497
587
|
throw new Error("Wormhole context not initialized");
|
|
498
588
|
}
|
|
499
|
-
const { sourceToken, destToken } = this.getTokenInfo(
|
|
589
|
+
const { sourceToken, destToken } = this.getTokenInfo(
|
|
590
|
+
sourceChain,
|
|
591
|
+
destinationChain
|
|
592
|
+
);
|
|
593
|
+
const destContext = this._wormholeContext.getPlatform(chainToPlatform(destinationChain)).getChain(destinationChain);
|
|
500
594
|
const sourceContext = this._wormholeContext.getPlatform(chainToPlatform(sourceChain)).getChain(sourceChain);
|
|
501
595
|
logger.log("sourceContext", sourceContext);
|
|
502
|
-
|
|
596
|
+
logger.log("sourceToken", sourceToken);
|
|
503
597
|
logger.log("destContext", destContext);
|
|
598
|
+
logger.log("destToken", destToken);
|
|
504
599
|
const request = await routes.RouteTransferRequest.create(
|
|
505
600
|
this._wormholeContext,
|
|
506
601
|
{
|
|
@@ -521,11 +616,17 @@ var WormholeProvider = class {
|
|
|
521
616
|
return { route: cctpRoute, request };
|
|
522
617
|
}
|
|
523
618
|
async getQuote(input) {
|
|
524
|
-
const { amount,
|
|
619
|
+
const { amount, originChain, type } = input;
|
|
525
620
|
if (!this._wormholeContext) {
|
|
526
|
-
await this.setWormholeContext(
|
|
621
|
+
await this.setWormholeContext(originChain);
|
|
527
622
|
}
|
|
528
|
-
|
|
623
|
+
logger.log("type", type);
|
|
624
|
+
const sourceChain = type === "transfer" ? originChain : "Aptos";
|
|
625
|
+
const destinationChain = type === "transfer" ? "Aptos" : originChain;
|
|
626
|
+
const { route, request } = await this.getRoute(
|
|
627
|
+
sourceChain,
|
|
628
|
+
destinationChain
|
|
629
|
+
);
|
|
529
630
|
const transferParams = {
|
|
530
631
|
amount,
|
|
531
632
|
options: { nativeGas: 0 }
|
|
@@ -631,14 +732,15 @@ var WormholeProvider = class {
|
|
|
631
732
|
* @param args
|
|
632
733
|
* @returns
|
|
633
734
|
*/
|
|
634
|
-
async
|
|
735
|
+
async transfer(input) {
|
|
635
736
|
if (this.crossChainCore._dappConfig?.aptosNetwork === Network.DEVNET) {
|
|
636
737
|
throw new Error("Devnet is not supported on Wormhole");
|
|
637
738
|
}
|
|
638
739
|
if (input.amount) {
|
|
639
740
|
await this.getQuote({
|
|
640
741
|
amount: input.amount,
|
|
641
|
-
|
|
742
|
+
originChain: input.sourceChain,
|
|
743
|
+
type: "transfer"
|
|
642
744
|
});
|
|
643
745
|
}
|
|
644
746
|
let { originChainTxnId, receipt } = await this.submitCCTPTransfer(input);
|
|
@@ -649,6 +751,97 @@ var WormholeProvider = class {
|
|
|
649
751
|
});
|
|
650
752
|
return { originChainTxnId, destinationChainTxnId };
|
|
651
753
|
}
|
|
754
|
+
async withdraw(input) {
|
|
755
|
+
const { sourceChain, wallet, destinationAddress, sponsorAccount } = input;
|
|
756
|
+
logger.log("sourceChain", sourceChain);
|
|
757
|
+
logger.log("wallet", wallet);
|
|
758
|
+
logger.log("destinationAddress", destinationAddress);
|
|
759
|
+
logger.log("sponsorAccount", sponsorAccount);
|
|
760
|
+
if (!this._wormholeContext) {
|
|
761
|
+
await this.setWormholeContext(sourceChain);
|
|
762
|
+
}
|
|
763
|
+
if (!this._wormholeContext) {
|
|
764
|
+
throw new Error("Wormhole context not initialized");
|
|
765
|
+
}
|
|
766
|
+
if (!this.wormholeRoute || !this.wormholeRequest || !this.wormholeQuote) {
|
|
767
|
+
throw new Error("Wormhole route, request, or quote not initialized");
|
|
768
|
+
}
|
|
769
|
+
const signer = new Signer(
|
|
770
|
+
this.getChainConfig("Aptos"),
|
|
771
|
+
(await input.wallet.features["aptos:account"].account()).address.toString(),
|
|
772
|
+
{},
|
|
773
|
+
input.wallet,
|
|
774
|
+
void 0,
|
|
775
|
+
sponsorAccount
|
|
776
|
+
);
|
|
777
|
+
logger.log("signer", signer);
|
|
778
|
+
logger.log("wormholeRequest", this.wormholeRequest);
|
|
779
|
+
logger.log("wormholeQuote", this.wormholeQuote);
|
|
780
|
+
logger.log(
|
|
781
|
+
"Wormhole.chainAddress",
|
|
782
|
+
Wormhole.chainAddress(sourceChain, input.destinationAddress.toString())
|
|
783
|
+
);
|
|
784
|
+
let receipt = await this.wormholeRoute.initiate(
|
|
785
|
+
this.wormholeRequest,
|
|
786
|
+
signer,
|
|
787
|
+
this.wormholeQuote,
|
|
788
|
+
Wormhole.chainAddress(sourceChain, input.destinationAddress.toString())
|
|
789
|
+
);
|
|
790
|
+
logger.log("receipt", receipt);
|
|
791
|
+
const originChainTxnId = "originTxs" in receipt ? receipt.originTxs[receipt.originTxs.length - 1].txid : void 0;
|
|
792
|
+
let retries = 0;
|
|
793
|
+
const maxRetries = 5;
|
|
794
|
+
const baseDelay = 1e3;
|
|
795
|
+
while (retries < maxRetries) {
|
|
796
|
+
try {
|
|
797
|
+
for await (receipt of this.wormholeRoute.track(receipt, 120 * 1e3)) {
|
|
798
|
+
if (receipt.state >= TransferState.SourceInitiated) {
|
|
799
|
+
logger.log("Receipt is on track ", receipt);
|
|
800
|
+
try {
|
|
801
|
+
const signer2 = new Signer(
|
|
802
|
+
this.getChainConfig(sourceChain),
|
|
803
|
+
destinationAddress.toString(),
|
|
804
|
+
{},
|
|
805
|
+
wallet
|
|
806
|
+
);
|
|
807
|
+
if (routes.isManual(this.wormholeRoute)) {
|
|
808
|
+
const circleAttestationReceipt = await this.wormholeRoute.complete(signer2, receipt);
|
|
809
|
+
logger.log("Claim receipt: ", circleAttestationReceipt);
|
|
810
|
+
const destinationChainTxnId = signer2.claimedTransactionHashes();
|
|
811
|
+
return {
|
|
812
|
+
originChainTxnId: originChainTxnId || "",
|
|
813
|
+
destinationChainTxnId
|
|
814
|
+
};
|
|
815
|
+
} else {
|
|
816
|
+
return {
|
|
817
|
+
originChainTxnId: originChainTxnId || "",
|
|
818
|
+
destinationChainTxnId: ""
|
|
819
|
+
};
|
|
820
|
+
}
|
|
821
|
+
} catch (e) {
|
|
822
|
+
console.error("Failed to claim", e);
|
|
823
|
+
return {
|
|
824
|
+
originChainTxnId: originChainTxnId || "",
|
|
825
|
+
destinationChainTxnId: ""
|
|
826
|
+
};
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
} catch (e) {
|
|
831
|
+
console.error(
|
|
832
|
+
`Error tracking transfer (attempt ${retries + 1} / ${maxRetries}):`,
|
|
833
|
+
e
|
|
834
|
+
);
|
|
835
|
+
const delay = baseDelay * Math.pow(2, retries);
|
|
836
|
+
await sleep2(delay);
|
|
837
|
+
retries++;
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
return {
|
|
841
|
+
originChainTxnId: originChainTxnId || "",
|
|
842
|
+
destinationChainTxnId: ""
|
|
843
|
+
};
|
|
844
|
+
}
|
|
652
845
|
getChainConfig(chain) {
|
|
653
846
|
const chainConfig = this.crossChainCore.CHAINS[chain];
|
|
654
847
|
if (!chainConfig) {
|
|
@@ -656,14 +849,14 @@ var WormholeProvider = class {
|
|
|
656
849
|
}
|
|
657
850
|
return chainConfig;
|
|
658
851
|
}
|
|
659
|
-
getTokenInfo(sourceChain) {
|
|
852
|
+
getTokenInfo(sourceChain, destinationChain) {
|
|
660
853
|
const sourceToken = Wormhole.tokenId(
|
|
661
854
|
this.crossChainCore.TOKENS[sourceChain].tokenId.chain,
|
|
662
855
|
this.crossChainCore.TOKENS[sourceChain].tokenId.address
|
|
663
856
|
);
|
|
664
857
|
const destToken = Wormhole.tokenId(
|
|
665
|
-
this.crossChainCore.
|
|
666
|
-
this.crossChainCore.
|
|
858
|
+
this.crossChainCore.TOKENS[destinationChain].tokenId.chain,
|
|
859
|
+
this.crossChainCore.TOKENS[destinationChain].tokenId.address
|
|
667
860
|
);
|
|
668
861
|
return { sourceToken, destToken };
|
|
669
862
|
}
|
|
@@ -710,6 +903,21 @@ var testnetChains = {
|
|
|
710
903
|
symbol: "SOL",
|
|
711
904
|
defaultRpc: "https://api.devnet.solana.com",
|
|
712
905
|
wrappedGasToken: "So11111111111111111111111111111111111111112"
|
|
906
|
+
},
|
|
907
|
+
Aptos: {
|
|
908
|
+
key: "Aptos",
|
|
909
|
+
id: 22,
|
|
910
|
+
context: "Aptos" /* APTOS */,
|
|
911
|
+
finalityThreshold: 0,
|
|
912
|
+
displayName: "Aptos",
|
|
913
|
+
explorerUrl: "https://explorer.aptoslabs.com?network=testnet",
|
|
914
|
+
explorerName: "Aptos Explorer",
|
|
915
|
+
gasToken: "APT",
|
|
916
|
+
chainId: 0,
|
|
917
|
+
icon: "Aptos",
|
|
918
|
+
maxBlockSearch: 0,
|
|
919
|
+
symbol: "APT",
|
|
920
|
+
defaultRpc: "https://fullnode.testnet.aptos.dev"
|
|
713
921
|
}
|
|
714
922
|
// Sui: {
|
|
715
923
|
// key: "Sui",
|
|
@@ -727,21 +935,6 @@ var testnetChains = {
|
|
|
727
935
|
// sdkName: "Sui",
|
|
728
936
|
// },
|
|
729
937
|
};
|
|
730
|
-
var AptosTestnetChain = {
|
|
731
|
-
key: "Aptos",
|
|
732
|
-
id: 22,
|
|
733
|
-
context: "Aptos" /* APTOS */,
|
|
734
|
-
finalityThreshold: 0,
|
|
735
|
-
displayName: "Aptos",
|
|
736
|
-
explorerUrl: "https://explorer.aptoslabs.com?network=testnet",
|
|
737
|
-
explorerName: "Aptos Explorer",
|
|
738
|
-
gasToken: "APT",
|
|
739
|
-
chainId: 0,
|
|
740
|
-
icon: "Aptos",
|
|
741
|
-
maxBlockSearch: 0,
|
|
742
|
-
symbol: "APT",
|
|
743
|
-
sdkName: "Aptos"
|
|
744
|
-
};
|
|
745
938
|
|
|
746
939
|
// src/config/testnet/tokens.ts
|
|
747
940
|
var testnetTokens = {
|
|
@@ -762,6 +955,15 @@ var testnetTokens = {
|
|
|
762
955
|
},
|
|
763
956
|
icon: "USDC",
|
|
764
957
|
decimals: 6
|
|
958
|
+
},
|
|
959
|
+
Aptos: {
|
|
960
|
+
symbol: "USDC",
|
|
961
|
+
decimals: 6,
|
|
962
|
+
tokenId: {
|
|
963
|
+
chain: "Aptos",
|
|
964
|
+
address: "0x69091fbab5f7d635ee7ac5098cf0c1efbe31d68fec0f2cd565e8d168daf52832"
|
|
965
|
+
},
|
|
966
|
+
icon: "USDC"
|
|
765
967
|
}
|
|
766
968
|
// Sui: {
|
|
767
969
|
// symbol: "USDC",
|
|
@@ -774,15 +976,6 @@ var testnetTokens = {
|
|
|
774
976
|
// decimals: 6,
|
|
775
977
|
// },
|
|
776
978
|
};
|
|
777
|
-
var AptosTestnetUSDCToken = {
|
|
778
|
-
symbol: "USDC",
|
|
779
|
-
decimals: 6,
|
|
780
|
-
tokenId: {
|
|
781
|
-
chain: "Aptos",
|
|
782
|
-
address: "0x69091fbab5f7d635ee7ac5098cf0c1efbe31d68fec0f2cd565e8d168daf52832"
|
|
783
|
-
},
|
|
784
|
-
icon: "USDC"
|
|
785
|
-
};
|
|
786
979
|
|
|
787
980
|
// src/config/mainnet/chains.ts
|
|
788
981
|
var mainnetChains = {
|
|
@@ -815,6 +1008,21 @@ var mainnetChains = {
|
|
|
815
1008
|
maxBlockSearch: 2e3,
|
|
816
1009
|
symbol: "SOL",
|
|
817
1010
|
defaultRpc: "https://solana-mainnet.rpc.extrnode.com"
|
|
1011
|
+
},
|
|
1012
|
+
Aptos: {
|
|
1013
|
+
key: "Aptos",
|
|
1014
|
+
id: 22,
|
|
1015
|
+
context: "Aptos" /* APTOS */,
|
|
1016
|
+
finalityThreshold: 0,
|
|
1017
|
+
displayName: "Aptos",
|
|
1018
|
+
explorerUrl: "https://explorer.aptoslabs.com/",
|
|
1019
|
+
explorerName: "Aptos Explorer",
|
|
1020
|
+
gasToken: "APT",
|
|
1021
|
+
chainId: 0,
|
|
1022
|
+
icon: "Aptos",
|
|
1023
|
+
maxBlockSearch: 0,
|
|
1024
|
+
symbol: "APT",
|
|
1025
|
+
defaultRpc: "https://fullnode.mainnet.aptos.dev"
|
|
818
1026
|
}
|
|
819
1027
|
// Sui: {
|
|
820
1028
|
// key: "Sui",
|
|
@@ -832,20 +1040,6 @@ var mainnetChains = {
|
|
|
832
1040
|
// symbol: "SUI",
|
|
833
1041
|
// },
|
|
834
1042
|
};
|
|
835
|
-
var AptosMainnetChain = {
|
|
836
|
-
key: "Aptos",
|
|
837
|
-
id: 22,
|
|
838
|
-
context: "Aptos",
|
|
839
|
-
finalityThreshold: 0,
|
|
840
|
-
displayName: "Aptos",
|
|
841
|
-
explorerUrl: "https://explorer.aptoslabs.com/",
|
|
842
|
-
explorerName: "Aptos Explorer",
|
|
843
|
-
gasToken: "APT",
|
|
844
|
-
chainId: 0,
|
|
845
|
-
icon: "Aptos",
|
|
846
|
-
maxBlockSearch: 0,
|
|
847
|
-
symbol: "APT"
|
|
848
|
-
};
|
|
849
1043
|
|
|
850
1044
|
// src/config/mainnet/tokens.ts
|
|
851
1045
|
var mainnetTokens = {
|
|
@@ -866,6 +1060,15 @@ var mainnetTokens = {
|
|
|
866
1060
|
},
|
|
867
1061
|
icon: "USDC",
|
|
868
1062
|
decimals: 6
|
|
1063
|
+
},
|
|
1064
|
+
Aptos: {
|
|
1065
|
+
symbol: "USDC",
|
|
1066
|
+
decimals: 6,
|
|
1067
|
+
tokenId: {
|
|
1068
|
+
chain: "Aptos",
|
|
1069
|
+
address: "0xbae207659db88bea0cbead6da0ed00aac12edcdda169e591cd41c94180b46f3b"
|
|
1070
|
+
},
|
|
1071
|
+
icon: "USDC"
|
|
869
1072
|
}
|
|
870
1073
|
// Sui: {
|
|
871
1074
|
// symbol: "USDC",
|
|
@@ -878,18 +1081,9 @@ var mainnetTokens = {
|
|
|
878
1081
|
// icon: "USDC",
|
|
879
1082
|
// },
|
|
880
1083
|
};
|
|
881
|
-
var AptosMainnetUSDCToken = {
|
|
882
|
-
symbol: "USDC",
|
|
883
|
-
tokenId: {
|
|
884
|
-
chain: "Aptos",
|
|
885
|
-
address: "0xbae207659db88bea0cbead6da0ed00aac12edcdda169e591cd41c94180b46f3b"
|
|
886
|
-
},
|
|
887
|
-
icon: "USDC",
|
|
888
|
-
decimals: 6
|
|
889
|
-
};
|
|
890
1084
|
|
|
891
1085
|
// src/utils/getUsdcBalance.ts
|
|
892
|
-
import { Aptos as
|
|
1086
|
+
import { Aptos as Aptos3, AptosConfig as AptosConfig3, Network as Network2 } from "@aptos-labs/ts-sdk";
|
|
893
1087
|
import { Connection as Connection2, PublicKey } from "@solana/web3.js";
|
|
894
1088
|
import { ethers as ethers2, JsonRpcProvider } from "ethers";
|
|
895
1089
|
var getSolanaWalletUSDCBalance = async (walletAddress, aptosNetwork, rpc) => {
|
|
@@ -913,10 +1107,10 @@ var getEthereumWalletUSDCBalance = async (walletAddress, aptosNetwork, rpc) => {
|
|
|
913
1107
|
return ethers2.formatUnits(balance, token.decimals).toString();
|
|
914
1108
|
};
|
|
915
1109
|
var getAptosWalletUSDCBalance = async (walletAddress, aptosNetwork) => {
|
|
916
|
-
const token = aptosNetwork === Network2.MAINNET ?
|
|
1110
|
+
const token = aptosNetwork === Network2.MAINNET ? mainnetTokens["Aptos"] : testnetTokens["Aptos"];
|
|
917
1111
|
const tokenAddress = token.tokenId.address;
|
|
918
|
-
const aptosConfig = new
|
|
919
|
-
const connection = new
|
|
1112
|
+
const aptosConfig = new AptosConfig3({ network: aptosNetwork });
|
|
1113
|
+
const connection = new Aptos3(aptosConfig);
|
|
920
1114
|
const response = await connection.getCurrentFungibleAssetBalances({
|
|
921
1115
|
options: {
|
|
922
1116
|
where: {
|
|
@@ -925,6 +1119,9 @@ var getAptosWalletUSDCBalance = async (walletAddress, aptosNetwork) => {
|
|
|
925
1119
|
}
|
|
926
1120
|
}
|
|
927
1121
|
});
|
|
1122
|
+
if (response.length === 0) {
|
|
1123
|
+
return "0";
|
|
1124
|
+
}
|
|
928
1125
|
const balance = (Number(response[0].amount) / 10 ** token.decimals).toString();
|
|
929
1126
|
return balance;
|
|
930
1127
|
};
|
|
@@ -938,16 +1135,13 @@ var CrossChainCore = class {
|
|
|
938
1135
|
};
|
|
939
1136
|
this.CHAINS = testnetChains;
|
|
940
1137
|
this.TOKENS = testnetTokens;
|
|
941
|
-
this.APTOS_TOKEN = AptosTestnetUSDCToken;
|
|
942
1138
|
this._dappConfig = args.dappConfig;
|
|
943
1139
|
if (args.dappConfig?.aptosNetwork === Network3.MAINNET) {
|
|
944
1140
|
this.CHAINS = mainnetChains;
|
|
945
1141
|
this.TOKENS = mainnetTokens;
|
|
946
|
-
this.APTOS_TOKEN = AptosMainnetUSDCToken;
|
|
947
1142
|
} else {
|
|
948
1143
|
this.CHAINS = testnetChains;
|
|
949
1144
|
this.TOKENS = testnetTokens;
|
|
950
|
-
this.APTOS_TOKEN = AptosTestnetUSDCToken;
|
|
951
1145
|
}
|
|
952
1146
|
}
|
|
953
1147
|
getProvider(providerType) {
|
|
@@ -993,10 +1187,6 @@ var CrossChainCore = class {
|
|
|
993
1187
|
import { Network as Network4 } from "@aptos-labs/ts-sdk";
|
|
994
1188
|
export {
|
|
995
1189
|
AptosLocalSigner,
|
|
996
|
-
AptosMainnetChain,
|
|
997
|
-
AptosMainnetUSDCToken,
|
|
998
|
-
AptosTestnetChain,
|
|
999
|
-
AptosTestnetUSDCToken,
|
|
1000
1190
|
Context,
|
|
1001
1191
|
CrossChainCore,
|
|
1002
1192
|
Network4 as Network,
|