UNPKG

@lucoadam/zebec-wormhole-sdk

Version:

This sdk can be use to transfer assets across chains and to interact with the Zebec's xchain bridge smart contracts for passing message from EVM chain to solana specially to utilize the features of Zebec Streaming and Zebec Multisig Streaming protocol.

653 lines (634 loc) 30.7 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ZebecBridgeTransactions = void 0; var _wormholeSdk = require("@certusone/wormhole-sdk"); var anchor = _interopRequireWildcard(require("@project-serum/anchor")); var _splToken = require("@solana/spl-token"); var _web = require("@solana/web3.js"); var _utils = require("../../../utils"); function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } class ZebecBridgeTransactions { constructor(bridgeProgram, provider) { this.bridgeProgram = bridgeProgram; this.provider = provider; } async makeStoreMsg(processed_vaa_account, emitter_account, core_bridge_account, dataStorageAccKey, countAccKey, currentCount, senderHash) { const senderArray = Array.from(senderHash); const transaction = await this.bridgeProgram.methods.storeMsg(currentCount, senderArray).accounts({ payer: this.provider.wallet.publicKey, systemProgram: anchor.web3.SystemProgram.programId, processedVaa: processed_vaa_account, emitterAcc: emitter_account, coreBridgeVaa: core_bridge_account, dataStorage: dataStorageAccKey, txnCount: countAccKey }).transaction(); const { blockhash, lastValidBlockHeight } = await this.provider.connection.getLatestBlockhash(); transaction.recentBlockhash = blockhash; transaction.lastValidBlockHeight = lastValidBlockHeight; transaction.feePayer = this.provider.wallet.publicKey; await this.provider.wallet.signTransaction(transaction); console.log("store msg transaction:::"); // logTransaction(transaction); return { transaction, blockhash, lastValidBlockHeight }; } async makeExecuteTransaction(transactionKeypair, proxyPda, cpiInstruction, proxyPdaHash, chainIdBuf) { const proxyPdaArray = Array.from(proxyPdaHash); const remainingAccounts = cpiInstruction.keys.map(acc => { if (acc.pubkey.equals(proxyPda)) { return { ...acc, isSigner: false }; } return acc; }).concat({ pubkey: cpiInstruction.programId, isWritable: false, isSigner: false }); const transaction = await this.bridgeProgram.methods.executeTransaction(proxyPdaArray, chainIdBuf).accounts({ pdaSigner: proxyPda, transaction: transactionKeypair.publicKey }).remainingAccounts(remainingAccounts).transaction(); const { blockhash, lastValidBlockHeight } = await this.provider.connection.getLatestBlockhash(); transaction.recentBlockhash = blockhash; transaction.lastValidBlockHeight = lastValidBlockHeight; transaction.feePayer = this.provider.wallet.publicKey; await this.provider.wallet.signTransaction(transaction); return { transaction: transaction, blockhash: blockhash, lastValidBlockHeight: lastValidBlockHeight }; } async makeCreateAndExecDepositTransaction(transactionKeypair, dataStorageAccKey, countAccKey, sender, cpiInstruction, senderHash, chainIdBuf) { const txSize = 450; const senderArray = Array.from(senderHash); const remainingAccounts = cpiInstruction.keys.map(acc => { if (acc.pubkey.equals(sender)) { return { ...acc, isSigner: false }; } return acc; }).concat({ pubkey: cpiInstruction.programId, isWritable: false, isSigner: false }); const transaction = await this.bridgeProgram.methods.transactionDeposit(cpiInstruction.programId, cpiInstruction.keys, cpiInstruction.data, chainIdBuf, senderArray).accounts({ dataStorage: dataStorageAccKey, pdaSigner: sender, transaction: transactionKeypair.publicKey, txnCount: countAccKey, zebecEoa: this.provider.wallet.publicKey, systemProgram: _web.SystemProgram.programId }).preInstructions([await this.bridgeProgram.account.transaction.createInstruction(transactionKeypair, txSize)]).remainingAccounts(remainingAccounts).transaction(); const { blockhash, lastValidBlockHeight } = await this.provider.connection.getLatestBlockhash(); transaction.recentBlockhash = blockhash; transaction.lastValidBlockHeight = lastValidBlockHeight; transaction.feePayer = this.provider.wallet.publicKey; transaction.partialSign(transactionKeypair); await this.provider.wallet.signTransaction(transaction); return { transaction, blockhash, lastValidBlockHeight }; } async makeCreateWithdrawTransaction(transactionKeypair, dataStorageAccKey, countAccKey, cpiInstruction, senderHash) { const txSize = 450; const senderArray = Array.from(senderHash); const transaction = await this.bridgeProgram.methods.createTransactionSenderWithdraw(cpiInstruction.programId, cpiInstruction.keys, cpiInstruction.data, senderArray).accounts({ dataStorage: dataStorageAccKey, systemProgram: _web.SystemProgram.programId, transaction: transactionKeypair.publicKey, txnCount: countAccKey, zebecEoa: this.provider.wallet.publicKey }).preInstructions([await this.bridgeProgram.account.transaction.createInstruction(transactionKeypair, txSize)]).transaction(); const { blockhash, lastValidBlockHeight } = await this.provider.connection.getLatestBlockhash(); transaction.recentBlockhash = blockhash; transaction.lastValidBlockHeight = lastValidBlockHeight; transaction.feePayer = this.provider.wallet.publicKey; transaction.partialSign(transactionKeypair); await this.provider.wallet.signTransaction(transaction); return { transaction, blockhash, lastValidBlockHeight }; } async makeCreateInitializeStreamTransaction(transactionKeypair, dataAccountKeypair, dataStorageAccKey, countAccKey, cpiInstruction, cpiPreInstruction, senderHash) { const txSize = 1232; const senderArray = Array.from(senderHash); const transaction = await this.bridgeProgram.methods.createTransactionStream(cpiInstruction.programId, cpiInstruction.keys, cpiInstruction.data, senderArray).accounts({ dataStorage: dataStorageAccKey, systemProgram: _web.SystemProgram.programId, transaction: transactionKeypair.publicKey, txnCount: countAccKey, zebecEoa: this.provider.wallet.publicKey }).preInstructions([await this.bridgeProgram.account.transaction.createInstruction(transactionKeypair, txSize), cpiPreInstruction]).transaction(); const { blockhash, lastValidBlockHeight } = await this.provider.connection.getLatestBlockhash(); transaction.recentBlockhash = blockhash; transaction.lastValidBlockHeight = lastValidBlockHeight; transaction.feePayer = this.provider.wallet.publicKey; transaction.partialSign(transactionKeypair, dataAccountKeypair); await this.provider.wallet.signTransaction(transaction); return { transaction, blockhash, lastValidBlockHeight }; } async makeCreateWithrawStreamTransaction(transactionKeypair, dataStorageAccKey, countAccKey, cpiInstruction, receiverHash) { const txSize = 1232; const receiverArray = Array.from(receiverHash); const transaction = await this.bridgeProgram.methods.createTransactionReceiverWithdraw(cpiInstruction.programId, cpiInstruction.keys, cpiInstruction.data, receiverArray).accounts({ transaction: transactionKeypair.publicKey, zebecEoa: this.provider.wallet.publicKey, systemProgram: anchor.web3.SystemProgram.programId, dataStorage: dataStorageAccKey, txnCount: countAccKey }).preInstructions([await this.bridgeProgram.account.transaction.createInstruction(transactionKeypair, txSize)]).transaction(); const { blockhash, lastValidBlockHeight } = await this.provider.connection.getLatestBlockhash(); transaction.recentBlockhash = blockhash; transaction.lastValidBlockHeight = lastValidBlockHeight; transaction.feePayer = this.provider.wallet.publicKey; transaction.partialSign(transactionKeypair); await this.provider.wallet.signTransaction(transaction); return { transaction, blockhash, lastValidBlockHeight }; } async makeUpdateStreamTransaction(transactionKeypair, dataStorageAccKey, countAccKey, sender, cpiInstruction, senderHash, chainIdBuf) { const txSize = 1232; const senderArray = Array.from(senderHash); const remainingAccounts = cpiInstruction.keys.map(acc => { if (acc.pubkey.equals(sender)) { return { ...acc, isSigner: false }; } return acc; }).concat({ pubkey: cpiInstruction.programId, isWritable: false, isSigner: false }); const transaction = await this.bridgeProgram.methods.transactionStreamUpdate(cpiInstruction.programId, cpiInstruction.keys, cpiInstruction.data, chainIdBuf, senderArray).accounts({ transaction: transactionKeypair.publicKey, zebecEoa: this.provider.wallet.publicKey, systemProgram: anchor.web3.SystemProgram.programId, dataStorage: dataStorageAccKey, txnCount: countAccKey, pdaSigner: sender }).preInstructions([await this.bridgeProgram.account.transaction.createInstruction(transactionKeypair, txSize)]).remainingAccounts(remainingAccounts).transaction(); const { blockhash, lastValidBlockHeight } = await this.provider.connection.getLatestBlockhash(); transaction.recentBlockhash = blockhash; transaction.lastValidBlockHeight = lastValidBlockHeight; transaction.feePayer = this.provider.wallet.publicKey; transaction.partialSign(transactionKeypair); await this.provider.wallet.signTransaction(transaction); return { transaction, blockhash, lastValidBlockHeight }; } async makeCreateCancelStreamTransaction(transactionKeypair, dataStorageAccKey, countAccKey, cpiInstruction, senderHash) { const txSize = 1200; const senderArray = Array.from(senderHash); const transaction = await this.bridgeProgram.methods.createTransactionCancel(cpiInstruction.programId, cpiInstruction.keys, cpiInstruction.data, senderArray).accounts({ transaction: transactionKeypair.publicKey, zebecEoa: this.provider.wallet.publicKey, systemProgram: anchor.web3.SystemProgram.programId, dataStorage: dataStorageAccKey, txnCount: countAccKey }).preInstructions([await this.bridgeProgram.account.transaction.createInstruction(transactionKeypair, txSize)]).transaction(); const { blockhash, lastValidBlockHeight } = await this.provider.connection.getLatestBlockhash(); transaction.recentBlockhash = blockhash; transaction.lastValidBlockHeight = lastValidBlockHeight; transaction.feePayer = this.provider.wallet.publicKey; transaction.partialSign(transactionKeypair); await this.provider.wallet.signTransaction(transaction); return { transaction, blockhash, lastValidBlockHeight }; } async makePauseResumeStreamTransaction(transactionKeypair, dataStorageAccKey, countAccKey, sender, cpiInstruction, senderHash, chainIdBuf) { const txSize = 1200; const senderArray = Array.from(senderHash); const remainingAccounts = cpiInstruction.keys.map(acc => { if (acc.pubkey.equals(sender)) { return { ...acc, isSigner: false }; } return acc; }).concat({ pubkey: cpiInstruction.programId, isWritable: false, isSigner: false }); const transaction = await this.bridgeProgram.methods.transactionPauseResume(cpiInstruction.programId, cpiInstruction.keys, cpiInstruction.data, chainIdBuf, senderArray).accounts({ transaction: transactionKeypair.publicKey, zebecEoa: this.provider.wallet.publicKey, systemProgram: anchor.web3.SystemProgram.programId, dataStorage: dataStorageAccKey, txnCount: countAccKey, pdaSigner: sender }).preInstructions([await this.bridgeProgram.account.transaction.createInstruction(transactionKeypair, txSize)]).remainingAccounts(remainingAccounts).transaction(); const { blockhash, lastValidBlockHeight } = await this.provider.connection.getLatestBlockhash(); transaction.recentBlockhash = blockhash; transaction.lastValidBlockHeight = lastValidBlockHeight; transaction.feePayer = this.provider.wallet.publicKey; transaction.partialSign(transactionKeypair); await this.provider.wallet.signTransaction(transaction); return { transaction, blockhash, lastValidBlockHeight }; } async makeInstantTokenTransferTransaction(transactionKeypair, dataStorageAccKey, countAccKey, cpiInstruction, senderHash) { const senderArray = Array.from(senderHash); const txSize = 1200; const transaction = await this.bridgeProgram.methods.createTransactionInstantTransfer(cpiInstruction.programId, cpiInstruction.keys, cpiInstruction.data, senderArray).accounts({ transaction: transactionKeypair.publicKey, zebecEoa: this.provider.wallet.publicKey, systemProgram: anchor.web3.SystemProgram.programId, dataStorage: dataStorageAccKey, txnCount: countAccKey }).preInstructions([await this.bridgeProgram.account.transaction.createInstruction(transactionKeypair, txSize)]).transaction(); const { blockhash, lastValidBlockHeight } = await this.provider.connection.getLatestBlockhash(); transaction.recentBlockhash = blockhash; transaction.lastValidBlockHeight = lastValidBlockHeight; transaction.feePayer = this.provider.wallet.publicKey; transaction.partialSign(transactionKeypair); await this.provider.wallet.signTransaction(transaction); return { transaction, blockhash, lastValidBlockHeight }; } // async makeTransferNativeTransaction( // fromOwner: PublicKey, // mint: PublicKey, // senderHash: Buffer, // sourceChain: Buffer, // targetChain: number, // amount: anchor.BN, // fee: anchor.BN, // ) { // const from = getAssociatedTokenAddressSync(mint, fromOwner, true); // const [config] = PublicKey.findProgramAddressSync([Buffer.from("config")], this.bridgeProgram.programId); // const coreBridgeProgram = new PublicKey(SOL_BRIDGE_ADDRESS); // const portalBridgeProgram = new PublicKey(SOL_TOKEN_BRIDGE_ADDRESS); // const [bridgeConfig] = PublicKey.findProgramAddressSync([Buffer.from("Bridge")], coreBridgeProgram); // const [bridgeFeeCollector] = PublicKey.findProgramAddressSync([Buffer.from("fee_collector")], coreBridgeProgram); // const [portalAuthoritySigner] = PublicKey.findProgramAddressSync( // [Buffer.from("authority_signer")], // portalBridgeProgram, // ); // const [portalConfig] = PublicKey.findProgramAddressSync([Buffer.from("config")], portalBridgeProgram); // const [portalCustody] = PublicKey.findProgramAddressSync([mint.toBuffer()], portalBridgeProgram); // const [portalCustodySigner] = PublicKey.findProgramAddressSync( // [Buffer.from("custody_signer")], // portalBridgeProgram, // ); // const [portalEmitter] = PublicKey.findProgramAddressSync([Buffer.from("emitter")], portalBridgeProgram); // const messageKeypair = Keypair.generate(); // const portalMessage = messageKeypair.publicKey; // const [portalSequence] = PublicKey.findProgramAddressSync( // [Buffer.from("Sequence"), portalEmitter.toBuffer()], // coreBridgeProgram, // ); // console.log("config:", config.toString()); // console.log("coreBridgeProgram:", coreBridgeProgram.toString()); // console.log("portalBridgeProgram", portalBridgeProgram.toString()); // console.log("bridgeConfig", bridgeConfig.toString()); // console.log("bridgeFeeCollector", bridgeFeeCollector.toString()); // console.log("portalAuthoritySigner", portalAuthoritySigner.toString()); // console.log("portalConfig", portalConfig.toString()); // console.log("portalCustody", portalCustody.toString()); // console.log("portalCustodySigner", portalCustodySigner.toString()); // console.log("portalEmitter", portalEmitter.toString()); // console.log("portalMessage", portalMessage.toString()); // console.log("portalSequence", portalSequence.toString()); // const transaction = new Transaction(); // setDefaultWasm("node"); // // fee to core bridge // const transferFeeIxn = await getBridgeFeeIx( // this.provider.connection, // SOL_BRIDGE_ADDRESS, // this.provider.wallet.publicKey.toString(), // ); // const transferIxn = await this.bridgeProgram.methods // .transferNative(senderHash, sourceChain, targetChain, amount, fee) // .accounts({ // bridgeConfig, // bridgeFeeCollector, // clock: SYSVAR_CLOCK_PUBKEY, // config, // coreBridgeProgram, // from, // fromOwner, // mint, // payer: this.provider.wallet.publicKey, // portalAuthoritySigner, // portalBridgeProgram, // portalConfig, // portalCustody, // portalCustodySigner, // portalEmitter, // portalMessage, // portalSequence, // rent: SYSVAR_RENT_PUBKEY, // systemProgram: SystemProgram.programId, // tokenProgram: TOKEN_PROGRAM_ID, // }) // .instruction(); // transaction.add(transferFeeIxn, transferIxn); // const { blockhash, lastValidBlockHeight } = await this.provider.connection.getLatestBlockhash(); // transaction.recentBlockhash = blockhash; // transaction.lastValidBlockHeight = lastValidBlockHeight; // transaction.feePayer = this.provider.wallet.publicKey; // transaction.partialSign(messageKeypair); // await this.provider.wallet.signTransaction(transaction); // return { transaction, blockhash, lastValidBlockHeight }; // } // async makeTransferWrappedTransaction( // fromOwner: PublicKey, // wrappedMint: PublicKey, // tokenOriginAddress: Buffer, // tokenOriginChain: number, // senderHash: Buffer, // sourceChain: Buffer, // targetChain: number, // amount: anchor.BN, // fee: anchor.BN, // ) { // const from = getAssociatedTokenAddressSync(wrappedMint, fromOwner, true); // const [config] = PublicKey.findProgramAddressSync([Buffer.from("config")], this.bridgeProgram.programId); // const coreBridgeProgram = new PublicKey(SOL_BRIDGE_ADDRESS); // const portalBridgeProgram = new PublicKey(SOL_TOKEN_BRIDGE_ADDRESS); // const [bridgeConfig] = PublicKey.findProgramAddressSync([Buffer.from("Bridge")], coreBridgeProgram); // const [bridgeFeeCollector] = PublicKey.findProgramAddressSync([Buffer.from("fee_collector")], coreBridgeProgram); // const [portalAuthoritySigner] = PublicKey.findProgramAddressSync( // [Buffer.from("authority_signer")], // portalBridgeProgram, // ); // const [portalConfig] = PublicKey.findProgramAddressSync([Buffer.from("config")], portalBridgeProgram); // const [wrappedMeta] = PublicKey.findProgramAddressSync( // [Buffer.from("meta"), wrappedMint.toBuffer()], // portalBridgeProgram, // ); // const [portalEmitter] = PublicKey.findProgramAddressSync([Buffer.from("emitter")], portalBridgeProgram); // const messageKeypair = Keypair.generate(); // const portalMessage = messageKeypair.publicKey; // const [portalSequence] = PublicKey.findProgramAddressSync( // [Buffer.from("Sequence"), portalEmitter.toBuffer()], // coreBridgeProgram, // ); // console.log("config:", config.toString()); // console.log("coreBridgeProgram:", coreBridgeProgram.toString()); // console.log("portalBridgeProgram", portalBridgeProgram.toString()); // console.log("bridgeConfig", bridgeConfig.toString()); // console.log("bridgeFeeCollector", bridgeFeeCollector.toString()); // console.log("portalAuthoritySigner", portalAuthoritySigner.toString()); // console.log("portalConfig", portalConfig.toString()); // console.log("wrappedMint", wrappedMint.toString()); // console.log("wrappedMeta", wrappedMeta.toString()); // console.log("portalEmitter", portalEmitter.toString()); // console.log("portalMessage", portalMessage.toString()); // console.log("portalSequence", portalSequence.toString()); // const transaction = new Transaction(); // setDefaultWasm("node"); // // fee to core bridge // const transferFeeIxn = await getBridgeFeeIx( // this.provider.connection, // SOL_BRIDGE_ADDRESS, // this.provider.wallet.publicKey.toString(), // ); // const transferIxn = await this.bridgeProgram.methods // .transferWrapped(senderHash, sourceChain, tokenOriginAddress, tokenOriginChain, targetChain, amount, fee) // .accounts({ // payer: this.provider.wallet.publicKey, // config, // from, // fromOwner, // portalConfig, // wrappedMint, // wrappedMeta, // portalAuthoritySigner, // bridgeConfig, // portalMessage, // portalEmitter, // portalSequence, // bridgeFeeCollector, // clock: SYSVAR_CLOCK_PUBKEY, // rent: SYSVAR_RENT_PUBKEY, // systemProgram: SystemProgram.programId, // portalBridgeProgram, // coreBridgeProgram, // tokenProgram: TOKEN_PROGRAM_ID, // }) // .instruction(); // transaction.add(transferFeeIxn, transferIxn); // const { blockhash, lastValidBlockHeight } = await this.provider.connection.getLatestBlockhash(); // transaction.recentBlockhash = blockhash; // transaction.lastValidBlockHeight = lastValidBlockHeight; // transaction.feePayer = this.provider.wallet.publicKey; // transaction.partialSign(messageKeypair); // await this.provider.wallet.signTransaction(transaction); // return { transaction, blockhash, lastValidBlockHeight }; // } async makeDirectTokenTransferTransaction(dataStorageAccKey, countAccKey, fromOwner, mint, senderHash, sourceChain, targetChain, fee) { const senderArray = Array.from(senderHash); const from = (0, _splToken.getAssociatedTokenAddressSync)(mint, fromOwner, true); const [config] = _web.PublicKey.findProgramAddressSync([Buffer.from("config")], this.bridgeProgram.programId); const coreBridgeProgram = new _web.PublicKey(_utils.SOL_BRIDGE_ADDRESS); const portalBridgeProgram = new _web.PublicKey(_utils.SOL_TOKEN_BRIDGE_ADDRESS); const [bridgeConfig] = _web.PublicKey.findProgramAddressSync([Buffer.from("Bridge")], coreBridgeProgram); const [bridgeFeeCollector] = _web.PublicKey.findProgramAddressSync([Buffer.from("fee_collector")], coreBridgeProgram); const [portalAuthoritySigner] = _web.PublicKey.findProgramAddressSync([Buffer.from("authority_signer")], portalBridgeProgram); const [portalConfig] = _web.PublicKey.findProgramAddressSync([Buffer.from("config")], portalBridgeProgram); const [portalCustody] = _web.PublicKey.findProgramAddressSync([mint.toBuffer()], portalBridgeProgram); const [portalCustodySigner] = _web.PublicKey.findProgramAddressSync([Buffer.from("custody_signer")], portalBridgeProgram); const [portalEmitter] = _web.PublicKey.findProgramAddressSync([Buffer.from("emitter")], portalBridgeProgram); const messageKeypair = _web.Keypair.generate(); const portalMessage = messageKeypair.publicKey; const [portalSequence] = _web.PublicKey.findProgramAddressSync([Buffer.from("Sequence"), portalEmitter.toBuffer()], coreBridgeProgram); console.log("config:", config.toString()); console.log("coreBridgeProgram:", coreBridgeProgram.toString()); console.log("portalBridgeProgram", portalBridgeProgram.toString()); console.log("bridgeConfig", bridgeConfig.toString()); console.log("bridgeFeeCollector", bridgeFeeCollector.toString()); console.log("portalAuthoritySigner", portalAuthoritySigner.toString()); console.log("portalConfig", portalConfig.toString()); console.log("portalCustody", portalCustody.toString()); console.log("portalCustodySigner", portalCustodySigner.toString()); console.log("portalEmitter", portalEmitter.toString()); console.log("portalMessage", portalMessage.toString()); console.log("portalSequence", portalSequence.toString()); const transaction = new _web.Transaction(); (0, _wormholeSdk.setDefaultWasm)("node"); // fee to core bridge const transferFeeIxn = await (0, _wormholeSdk.getBridgeFeeIx)(this.provider.connection, _utils.SOL_BRIDGE_ADDRESS, this.provider.wallet.publicKey.toString()); const transferIxn = await this.bridgeProgram.methods.transactionDirectTransferNative(senderArray, sourceChain, targetChain, fee).accounts({ zebecEoa: this.provider.wallet.publicKey, dataStorage: dataStorageAccKey, txnCount: countAccKey, pdaSigner: fromOwner, config, bridgeConfig, bridgeFeeCollector, clock: _web.SYSVAR_CLOCK_PUBKEY, coreBridgeProgram, from, mint, portalAuthoritySigner, portalBridgeProgram, portalConfig, portalCustody, portalCustodySigner, portalEmitter, portalMessage, portalSequence, rent: _web.SYSVAR_RENT_PUBKEY, systemProgram: _web.SystemProgram.programId, tokenProgram: _splToken.TOKEN_PROGRAM_ID }).instruction(); transaction.add(transferFeeIxn, transferIxn); const { blockhash, lastValidBlockHeight } = await this.provider.connection.getLatestBlockhash(); transaction.recentBlockhash = blockhash; transaction.lastValidBlockHeight = lastValidBlockHeight; transaction.feePayer = this.provider.wallet.publicKey; transaction.partialSign(messageKeypair); await this.provider.wallet.signTransaction(transaction); return { transaction, blockhash, lastValidBlockHeight }; } async makeDirectTokenTransferWrappedTransaction(dataStorageAccKey, countAccKey, fromOwner, wrappedMint, senderHash, sourceChain, targetChain, currentCount, fee, tokenOriginAddress, tokenOriginChain) { const senderArray = Array.from(senderHash); const from = (0, _splToken.getAssociatedTokenAddressSync)(wrappedMint, fromOwner, true); const [config] = _web.PublicKey.findProgramAddressSync([Buffer.from("config")], this.bridgeProgram.programId); const coreBridgeProgram = new _web.PublicKey(_utils.SOL_BRIDGE_ADDRESS); const portalBridgeProgram = new _web.PublicKey(_utils.SOL_TOKEN_BRIDGE_ADDRESS); const [bridgeConfig] = _web.PublicKey.findProgramAddressSync([Buffer.from("Bridge")], coreBridgeProgram); const [bridgeFeeCollector] = _web.PublicKey.findProgramAddressSync([Buffer.from("fee_collector")], coreBridgeProgram); const [portalAuthoritySigner] = _web.PublicKey.findProgramAddressSync([Buffer.from("authority_signer")], portalBridgeProgram); const [portalConfig] = _web.PublicKey.findProgramAddressSync([Buffer.from("config")], portalBridgeProgram); const [wrappedMeta] = _web.PublicKey.findProgramAddressSync([Buffer.from("meta"), wrappedMint.toBuffer()], portalBridgeProgram); const [portalEmitter] = _web.PublicKey.findProgramAddressSync([Buffer.from("emitter")], portalBridgeProgram); const messageKeypair = _web.Keypair.generate(); const portalMessage = messageKeypair.publicKey; const [portalSequence] = _web.PublicKey.findProgramAddressSync([Buffer.from("Sequence"), portalEmitter.toBuffer()], coreBridgeProgram); console.log("config:", config.toString()); console.log("coreBridgeProgram:", coreBridgeProgram.toString()); console.log("portalBridgeProgram", portalBridgeProgram.toString()); console.log("bridgeConfig", bridgeConfig.toString()); console.log("bridgeFeeCollector", bridgeFeeCollector.toString()); console.log("portalAuthoritySigner", portalAuthoritySigner.toString()); console.log("portalConfig", portalConfig.toString()); console.log("portalEmitter", portalEmitter.toString()); console.log("portalMessage", portalMessage.toString()); console.log("portalSequence", portalSequence.toString()); const transaction = new _web.Transaction(); (0, _wormholeSdk.setDefaultWasm)("node"); // fee to core bridge const transferFeeIxn = await (0, _wormholeSdk.getBridgeFeeIx)(this.provider.connection, _utils.SOL_BRIDGE_ADDRESS, this.provider.wallet.publicKey.toString()); const transferIxn = await this.bridgeProgram.methods.transactionDirectTransferWrapped(senderArray, sourceChain, tokenOriginAddress, tokenOriginChain, currentCount, targetChain, fee).accounts({ zebecEoa: this.provider.wallet.publicKey, dataStorage: dataStorageAccKey, txnCount: countAccKey, pdaSigner: fromOwner, config, bridgeConfig, bridgeFeeCollector, clock: _web.SYSVAR_CLOCK_PUBKEY, coreBridgeProgram, from, wrappedMint, portalAuthoritySigner, portalBridgeProgram, portalConfig, portalEmitter, portalMessage, portalSequence, rent: _web.SYSVAR_RENT_PUBKEY, systemProgram: _web.SystemProgram.programId, tokenProgram: _splToken.TOKEN_PROGRAM_ID, wrappedMeta }).instruction(); transaction.add(transferFeeIxn, transferIxn); const { blockhash, lastValidBlockHeight } = await this.provider.connection.getLatestBlockhash(); transaction.recentBlockhash = blockhash; transaction.lastValidBlockHeight = lastValidBlockHeight; transaction.feePayer = this.provider.wallet.publicKey; transaction.partialSign(messageKeypair); await this.provider.wallet.signTransaction(transaction); return { transaction, blockhash, lastValidBlockHeight }; } } exports.ZebecBridgeTransactions = ZebecBridgeTransactions; //# sourceMappingURL=transactions.js.map