UNPKG

@layerzerolabs/lz-aptos-sdk-v1

Version:

Aptos SDK for LayerZero

1,324 lines (1,314 loc) 298 kB
'use strict'; var aptos2 = require('aptos'); var invariant2 = require('tiny-invariant'); var lzDefinitions = require('@layerzerolabs/lz-definitions'); var crypto = require('crypto'); var sha3 = require('@noble/hashes/sha3'); var utils = require('@noble/hashes/utils'); var bip39 = require('bip39'); var BN = require('bn.js'); var extendedBuffer = require('extended-buffer'); var lzMovevmSdkV2 = require('@layerzerolabs/lz-movevm-sdk-v2'); function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; } function _interopNamespace(e) { if (e && e.__esModule) return e; var n = Object.create(null); if (e) { Object.keys(e).forEach(function (k) { if (k !== 'default') { var d = Object.getOwnPropertyDescriptor(e, k); Object.defineProperty(n, k, d.get ? d : { enumerable: true, get: function () { return e[k]; } }); } }); } n.default = e; return Object.freeze(n); } var aptos2__namespace = /*#__PURE__*/_interopNamespace(aptos2); var invariant2__default = /*#__PURE__*/_interopDefault(invariant2); var crypto__default = /*#__PURE__*/_interopDefault(crypto); var bip39__namespace = /*#__PURE__*/_interopNamespace(bip39); var BN__default = /*#__PURE__*/_interopDefault(BN); var __defProp = Object.defineProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; // src/constants.ts var constants_exports = {}; __export(constants_exports, { AIRDROP_WRAPPER_ADDRESS: () => AIRDROP_WRAPPER_ADDRESS, BRIDGE_ADDRESS: () => BRIDGE_ADDRESS, BRIDGE_PRECRIME_ADDRESS: () => BRIDGE_PRECRIME_ADDRESS, COUNTER_ADDRESS: () => COUNTER_ADDRESS, EXECUTOR_ADDRESS: () => EXECUTOR_ADDRESS, EXECUTOR_EXT_ADDRESS: () => EXECUTOR_EXT_ADDRESS, EXECUTOR_FEE_LIB_V1_ADDRESS: () => EXECUTOR_FEE_LIB_V1_ADDRESS, EXECUTOR_V2_ADDRESS: () => EXECUTOR_V2_ADDRESS, FAUCET_URL: () => FAUCET_URL, LAYERZERO_ADDRESS: () => LAYERZERO_ADDRESS, LAYERZERO_APPS_ADDRESS: () => LAYERZERO_APPS_ADDRESS, LAYERZERO_APPS_PUBKEY: () => LAYERZERO_APPS_PUBKEY, LAYERZERO_VIEW_ADDRESS: () => LAYERZERO_VIEW_ADDRESS, LAYERZERO_VIEW_ULN301_ADDRESS: () => LAYERZERO_VIEW_ULN301_ADDRESS, MSGLIB_ROUTING_HELPER_ADDRESS: () => MSGLIB_ROUTING_HELPER_ADDRESS, NODE_URL: () => NODE_URL, OFT_PRECRIME_ADDRESS: () => OFT_PRECRIME_ADDRESS, ORACLE_ADDRESS: () => ORACLE_ADDRESS, ORACLE_SIGNER_ADDRESS: () => ORACLE_SIGNER_ADDRESS, RELAYER_SIGNER_ADDRESS: () => RELAYER_SIGNER_ADDRESS, ULN_301_ADDRESS: () => ULN_301_ADDRESS, ULN_301_RECEIVE_HELPER_ADDRESS: () => ULN_301_RECEIVE_HELPER_ADDRESS }); var NODE_URL = { [lzDefinitions.Environment.MAINNET]: "https://mainnet.aptoslabs.com/v1", [lzDefinitions.Environment.TESTNET]: "https://fullnode.testnet.aptoslabs.com/v1", [lzDefinitions.Environment.DEVNET]: "https://fullnode.devnet.aptoslabs.com/v1", [lzDefinitions.Environment.LOCAL]: "http://127.0.0.1:8080/v1" // 'http://192.168.0.169:8080/v1 }; var FAUCET_URL = { [lzDefinitions.Environment.MAINNET]: "", [lzDefinitions.Environment.TESTNET]: "https://faucet.testnet.aptoslabs.com", [lzDefinitions.Environment.DEVNET]: "https://faucet.devnet.aptoslabs.com", [lzDefinitions.Environment.LOCAL]: "http://127.0.0.1:8081" // 'http://192.168.0.169:8081 }; var LAYERZERO_ADDRESS = { [lzDefinitions.Stage.MAINNET]: "0x54ad3d30af77b60d939ae356e6606de9a4da67583f02b962d2d3f2e481484e90", // MAINNET [lzDefinitions.Stage.TESTNET]: "0x1759cc0d3161f1eb79f65847d4feb9d1f74fb79014698a23b16b28b9cd4c37e3", [lzDefinitions.Stage.SANDBOX]: "0xf2e1e034475dc0439487dd09dfc3950c462f731599e53a6b015dd85502352e68" //TODO(Ethan) double check }; var ULN_301_ADDRESS = { [lzDefinitions.Stage.MAINNET]: "0x844bec096472b9ca651bfce5e639f8ef92dafb7b4e5a54461dd8c8f5c5231812", [lzDefinitions.Stage.TESTNET]: "0x9b4f328857baf5471ffe873471459a75da3aa3db0629f4c1b0ede4d48cf9fac1", [lzDefinitions.Stage.SANDBOX]: "0x1050fe8b6900532a0fc312c1635f3e0bfb1153cc9ef55bc190ce48f0db471514" }; var ULN_301_RECEIVE_HELPER_ADDRESS = { [lzDefinitions.Stage.MAINNET]: "0x7060cc3af37451b4fb3804400b98942b074384dc3de634c2559830210c6ad1de", [lzDefinitions.Stage.TESTNET]: "0x9f09756d37b4103e3e94bbe3ef8f161a3b957a394af48a5bee1e8de4d2e7b1b8", [lzDefinitions.Stage.SANDBOX]: "0x4198b568d9044d0165f8c357e88a7b12dd76fecd3016e7726e5512f668164be9" }; var MSGLIB_ROUTING_HELPER_ADDRESS = { [lzDefinitions.Stage.MAINNET]: "0xf423abcbbc65f5e11d0027c51c1287765e8fe8b145d5a477690989e7adc9d714", [lzDefinitions.Stage.TESTNET]: "0xff6c2de369bdff3481d7d19e17967686d65e8585d97de45bfd2fe1debbcb0a4f", [lzDefinitions.Stage.SANDBOX]: "0xda0ee3324a739cf664fedfba5174fbc6a11ffbb669b6ead9dc366415b9a37114" }; var LAYERZERO_APPS_ADDRESS = { [lzDefinitions.Stage.MAINNET]: "0x43d8cad89263e6936921a0adb8d5d49f0e236c229460f01b14dca073114df2b9", [lzDefinitions.Stage.TESTNET]: "0x2f972c173927006c83277b6e6ae38f83482eba560f343d022f145979020d3621", [lzDefinitions.Stage.SANDBOX]: "0x9b2bac312330430f5e7287a18065e24b55a5e3834459a92be0784177441959bf" //TODO(Ethan) double check }; var ORACLE_ADDRESS = { [lzDefinitions.Stage.MAINNET]: "0xc2846ea05319c339b3b52186ceae40b43d4e9cf6c7350336c3eb0b351d9394eb", // MAINNET [lzDefinitions.Stage.TESTNET]: "0x8ab85d94bf34808386b3ce0f9516db74d2b6d2f1166aa48f75ca641f3adb6c63", [lzDefinitions.Stage.SANDBOX]: "0x86052d5722c3222a88de346aad92a02ace56839487165c6b1bad844e85297d5e" //TODO(Ethan) double check }; var ORACLE_SIGNER_ADDRESS = { [lzDefinitions.Stage.MAINNET]: "0x12e12de0af996d9611b0b78928cd9f4cbf50d94d972043cdd829baa77a78929b", // MAINNET [lzDefinitions.Stage.TESTNET]: "0x47a30bcdb5b5bdbf6af883c7325827f3e40b3f52c3538e9e677e68cf0c0db060", [lzDefinitions.Stage.SANDBOX]: "0x81f5957aa36d8d1515ba5eb95df187fed85185610e7b14fbb0f281b12397f807" //TODO(Ethan) double check }; var RELAYER_SIGNER_ADDRESS = { [lzDefinitions.Stage.MAINNET]: "0x1d8727df513fa2a8785d0834e40b34223daff1affc079574082baadb74b66ee4", // MAINNET [lzDefinitions.Stage.TESTNET]: "0xc192864c4215741051321d44f89c3b7a54840a0b1b7ef5bec6149a07f9df4641", [lzDefinitions.Stage.SANDBOX]: "0x34fb23a3db82f39629506b507fdf886202c7935f74ddc8ecef9dac0bb849b07f" //TODO(Ethan) double check }; var EXECUTOR_ADDRESS = { [lzDefinitions.Stage.MAINNET]: "0x1d8727df513fa2a8785d0834e40b34223daff1affc079574082baadb74b66ee4", // MAINNET [lzDefinitions.Stage.TESTNET]: "0xc192864c4215741051321d44f89c3b7a54840a0b1b7ef5bec6149a07f9df4641", [lzDefinitions.Stage.SANDBOX]: "0xce28babbf0e389e9f153d6e80af4e5dd5f24a3d7a9c3697864ef862752df1032" // switch to executorAdmin wallet, requested by Alvin. }; var EXECUTOR_EXT_ADDRESS = { [lzDefinitions.Stage.MAINNET]: "0xd122ac52d43736e0f524a334fc37b6750884559da7ddf1aee0b11b6ae62643d7", // MAINNET [lzDefinitions.Stage.TESTNET]: "0x39942f4bd78e899f162644b5ec5998a19cb6de1ff8b7321070cb75cf96e5cf6c", [lzDefinitions.Stage.SANDBOX]: "0xd8f318cab62a1142e1cd60f3f090331becc9a462a1a85180de8a99e2a27eadc0" //TODO(Ethan) double check }; var EXECUTOR_V2_ADDRESS = { [lzDefinitions.Stage.MAINNET]: "0x54ad3d30af77b60d939ae356e6606de9a4da67583f02b962d2d3f2e481484e90", // MAINNET [lzDefinitions.Stage.TESTNET]: "0x1759cc0d3161f1eb79f65847d4feb9d1f74fb79014698a23b16b28b9cd4c37e3", [lzDefinitions.Stage.SANDBOX]: "0xf2e1e034475dc0439487dd09dfc3950c462f731599e53a6b015dd85502352e68" }; var EXECUTOR_FEE_LIB_V1_ADDRESS = { [lzDefinitions.Stage.MAINNET]: "0xf3cea996f573055d29acdf0a5b4c342437a1d51ea49add7b16eecf82f0fca314", // MAINNET [lzDefinitions.Stage.TESTNET]: "0xe957adc7b93c61c3fb0ad1cba6f302451e81e9e107d0335ec0a6fc44694a418d", [lzDefinitions.Stage.SANDBOX]: "0x53268a3c075dbe2518b60b5e6f9f8a4df7433f48cd350375538c5f5205d7b6b3" }; var LAYERZERO_APPS_PUBKEY = { [lzDefinitions.Stage.MAINNET]: "0xf57e5a95ae0e2b5f999ac14abd0ff73daf64e6e7e2a1fad024f2e44422e88d76", // MAINNET [lzDefinitions.Stage.TESTNET]: "0xa6d39a1f522da0298a387032952393b1dd2f88ea75423de05c26792930c60ac0", [lzDefinitions.Stage.SANDBOX]: "0x116a5d69ece688512eaf0c0849ca587c6386c36a474d21504a4b6f6ae3a3a487" }; var BRIDGE_ADDRESS = { [lzDefinitions.Stage.MAINNET]: "0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa", // MAINNET [lzDefinitions.Stage.TESTNET]: "0xec84c05cc40950c86d8a8bed19552f1e8ebb783196bb021c916161d22dc179f7", [lzDefinitions.Stage.SANDBOX]: "0xf52132c1ce7922eb0ac4f5342e8d7d0f817a5af9fb8da23793b058ad8ad38e19" //TODO(Ethan) double check }; var BRIDGE_PRECRIME_ADDRESS = { [lzDefinitions.Stage.MAINNET]: "0x16c7d29eea08ac77dfc4e4665bb56da0ded4e7b82c4c25d535b3d5a5fd6071ad", [lzDefinitions.Stage.TESTNET]: "0x3ed30825c327d8ee51e079c48b12981053fe2bfe07f74a6572726abf4d5c9afc", [lzDefinitions.Stage.SANDBOX]: "0x93b4711e61b1339868ab29f109b2204b452d6997bb5b58cf9d2160addfb71724" // TODO TESTNET_SANDBOX }; var OFT_PRECRIME_ADDRESS = { [lzDefinitions.Stage.MAINNET]: "0x273f3e39593a6723adcecd5aa112158c07239043f79609a0380473157c841e19", [lzDefinitions.Stage.TESTNET]: "0x9fea38276544542be16c4592d1b10cf08d4d9dee33b51eca8a88f17921d985d2", [lzDefinitions.Stage.SANDBOX]: "0xa721bd722a3eff335044536af6e048afcfaae03043da920639f773154f20afd6" // TODO TESTNET_SANDBOX }; var COUNTER_ADDRESS = { [lzDefinitions.Stage.MAINNET]: "0xb17cebee4f9a1db3c1777a7339358a1355f546739d97995e86d3841e65d09e16", // MAINNET [lzDefinitions.Stage.TESTNET]: "0x3ded83bd990eb694e2f3970bb7f8dedb106b0e696a635574da9bffc1efe864b4", // [Stage.SANDBOX]: '0x9584ff2b8ec928fc82889c979a0d443ebccde12a0c65840bd302f6254e14c004', [lzDefinitions.Stage.SANDBOX]: "0x2b249feeed4e30deb84f92c0960baf68652757ce2d7d672d566fdb9a34f8720e" }; var LAYERZERO_VIEW_ADDRESS = { [lzDefinitions.Stage.MAINNET]: "0xe6f6eb32853cb7a43f6ead4bea489b5bb0705b40c41dc13fffd9147c91adfbbf", [lzDefinitions.Stage.TESTNET]: "0x2eed41cf51a714f968d2ee4a3fa1483bc7e2ce7fb22192fd55c0df96a2aad45f", [lzDefinitions.Stage.SANDBOX]: "0xaebc3f4f27559ea378f21d75b43236ea0f8038a2c171224eb01be7a7dfe918ab" }; var LAYERZERO_VIEW_ULN301_ADDRESS = { [lzDefinitions.Stage.MAINNET]: "0x49bbf8d8214fb2b158f50ecf3d75a73da133440776bff0db6005c1175138e7c0", [lzDefinitions.Stage.TESTNET]: "0xa37316bc18fa9b5b5e976b9bc9b103565443cc72b85981d61c72324bf50ede1f", [lzDefinitions.Stage.SANDBOX]: "0x5df37117d3fa3d577908d8741a70122cfb04718e94e768a130d2133363c505c8" }; var AIRDROP_WRAPPER_ADDRESS = { [lzDefinitions.Stage.MAINNET]: "0xe5e98365149e3c4dc4bf0116f8c7a1ae89dd57d27530032bb733a3c3d774fc5d", [lzDefinitions.Stage.TESTNET]: "0x8b4deb76c00a75ec75722ca0aa6608a76fae0d86176f7e96ed5fcf012c863c99", [lzDefinitions.Stage.SANDBOX]: "0xc81f7a4f09fa14c425c3a94ee147c8a4200cf5b047dceb3429288877b3bf11b7" }; // src/utils.ts var utils_exports = {}; __export(utils_exports, { GAS_LIMIT_SAFETY_BPS: () => GAS_LIMIT_SAFETY_BPS, ZERO_ADDRESS_BYTES: () => ZERO_ADDRESS_BYTES, ZERO_ADDRESS_HEX: () => ZERO_ADDRESS_HEX, applyGasLimitSafety: () => applyGasLimitSafety, buildStructTagFromTypeInfo: () => buildStructTagFromTypeInfo, bytesToUint8Array: () => bytesToUint8Array, computeGuid: () => computeGuid, convertBytesToUint64: () => convertBytesToUint64, convertToPaddedUint8Array: () => convertToPaddedUint8Array, convertUint64ToBytes: () => convertUint64ToBytes, decodePacket: () => decodePacket, decodePacketString: () => decodePacketString, decodePayload: () => decodePayload, encodePacket: () => encodePacket, fullAddress: () => fullAddress, generateMultisig: () => generateMultisig, getAccountFromMnemonic: () => getAccountFromMnemonic, getAccountFromPrivateKey: () => getAccountFromPrivateKey, getAddressFromPublicKey: () => getAddressFromPublicKey, getLzReceiveTypeArguments: () => getLzReceiveTypeArguments, getResourceAddress: () => getResourceAddress, getSignedTransactionHash: () => getSignedTransactionHash, hashBuffer: () => hashBuffer, hashPacket: () => hashPacket, hexToAscii: () => hexToAscii, isErrorOfApiError: () => isErrorOfApiError, isSameAddress: () => isSameAddress, isTypeInfo: () => isTypeInfo, isZeroAddress: () => isZeroAddress, makeSignFuncWithMultipleSigners: () => makeSignFuncWithMultipleSigners, multiSigSignedBCSTxn: () => multiSigSignedBCSTxn, normalizeTypeInfo: () => normalizeTypeInfo, paddingUint8Array: () => paddingUint8Array, rebuildPacketFromEvent: () => rebuildPacketFromEvent, stringToPaddedUint8Array: () => stringToPaddedUint8Array, stringToUint8Array: () => stringToUint8Array }); var TypeArgumentABI = class _TypeArgumentABI { /** * Constructs a TypeArgumentABI instance. * * @param {string} name - The name of the type argument. */ constructor(name) { this.name = name; } /** * Serializes the TypeArgumentABI instance. * * @param {aptos.BCS.Serializer} serializer - The serializer. */ serialize(serializer) { serializer.serializeStr(this.name); } /** * Deserializes a TypeArgumentABI instance. * * @param {aptos.BCS.Deserializer} deserializer - The deserializer. * @returns {TypeArgumentABI} The deserialized TypeArgumentABI instance. */ static deserialize(deserializer) { const name = deserializer.deserializeStr(); return new _TypeArgumentABI(name); } }; var ArgumentABI = class _ArgumentABI { /** * Constructs an ArgumentABI instance. * * @param {string} name - The name of the argument. * @param {aptos.TxnBuilderTypes.TypeTag} type_tag - The type tag of the argument. */ constructor(name, type_tag) { this.name = name; this.type_tag = type_tag; } /** * Serializes the ArgumentABI instance. * * @param {aptos.BCS.Serializer} serializer - The serializer. */ serialize(serializer) { serializer.serializeStr(this.name); this.type_tag.serialize(serializer); } /** * Deserializes an ArgumentABI instance. * * @param {aptos.BCS.Deserializer} deserializer - The deserializer. * @returns {ArgumentABI} The deserialized ArgumentABI instance. */ static deserialize(deserializer) { const name = deserializer.deserializeStr(); const typeTag = aptos2__namespace.TxnBuilderTypes.TypeTag.deserialize(deserializer); return new _ArgumentABI(name, typeTag); } }; var ScriptABI = class { /** * Deserializes a ScriptABI instance. * * @param {aptos.BCS.Deserializer} deserializer - The deserializer. * @returns {ScriptABI} The deserialized ScriptABI instance. */ static deserialize(deserializer) { const index = deserializer.deserializeUleb128AsU32(); switch (index) { case 0: return TransactionScriptABI.load(deserializer); case 1: return EntryFunctionABI.load(deserializer); default: throw new Error(`Unknown variant index for TransactionPayload: ${index}`); } } }; var TransactionScriptABI = class _TransactionScriptABI extends ScriptABI { /** * Constructs a TransactionScriptABI instance. * * @param {string} name - The entry function name. * @param {string} doc - The documentation. * @param {aptos.BCS.Bytes} code - The code. * @param {aptos.BCS.Seq<TypeArgumentABI>} ty_args - The type arguments. * @param {aptos.BCS.Seq<ArgumentABI>} args - The arguments. */ constructor(name, doc, code, ty_args, args) { super(); this.name = name; this.doc = doc; this.code = code; this.ty_args = ty_args; this.args = args; } /** * Serializes the TransactionScriptABI instance. * * @param {aptos.BCS.Serializer} serializer - The serializer. */ serialize(serializer) { serializer.serializeU32AsUleb128(0); serializer.serializeStr(this.name); serializer.serializeStr(this.doc); serializer.serializeBytes(this.code); aptos2__namespace.BCS.serializeVector(this.ty_args, serializer); aptos2__namespace.BCS.serializeVector(this.args, serializer); } /** * Loads a TransactionScriptABI instance from a deserializer. * * @param {aptos.BCS.Deserializer} deserializer - The deserializer. * @returns {TransactionScriptABI} The loaded TransactionScriptABI instance. */ static load(deserializer) { const name = deserializer.deserializeStr(); const doc = deserializer.deserializeStr(); const code = deserializer.deserializeBytes(); const tyArgs = aptos2__namespace.BCS.deserializeVector(deserializer, TypeArgumentABI); const args = aptos2__namespace.BCS.deserializeVector(deserializer, ArgumentABI); return new _TransactionScriptABI(name, doc, code, tyArgs, args); } }; var EntryFunctionABI = class _EntryFunctionABI extends ScriptABI { /** * Constructs an EntryFunctionABI instance. * * @param {string} name - The name of the entry function. * @param {aptos.TxnBuilderTypes.ModuleId} module_name - The fully qualified module ID. * @param {string} doc - The documentation. * @param {aptos.BCS.Seq<TypeArgumentABI>} ty_args - The type arguments. * @param {aptos.BCS.Seq<ArgumentABI>} args - The arguments. */ constructor(name, module_name, doc, ty_args, args) { super(); this.name = name; this.module_name = module_name; this.doc = doc; this.ty_args = ty_args; this.args = args; } /** * Serializes the EntryFunctionABI instance. * * @param {aptos.BCS.Serializer} serializer - The serializer. */ serialize(serializer) { serializer.serializeU32AsUleb128(1); serializer.serializeStr(this.name); this.module_name.serialize(serializer); serializer.serializeStr(this.doc); aptos2__namespace.BCS.serializeVector(this.ty_args, serializer); aptos2__namespace.BCS.serializeVector(this.args, serializer); } /** * Loads an EntryFunctionABI instance from a deserializer. * * @param {aptos.BCS.Deserializer} deserializer - The deserializer. * @returns {EntryFunctionABI} The loaded EntryFunctionABI instance. */ static load(deserializer) { const name = deserializer.deserializeStr(); const moduleName = aptos2__namespace.TxnBuilderTypes.ModuleId.deserialize(deserializer); const doc = deserializer.deserializeStr(); const tyArgs = aptos2__namespace.BCS.deserializeVector(deserializer, TypeArgumentABI); const args = aptos2__namespace.BCS.deserializeVector(deserializer, ArgumentABI); return new _EntryFunctionABI(name, moduleName, doc, tyArgs, args); } }; // src/utils.ts var ZERO_ADDRESS_HEX = fullAddress("0x0").toString(); var ZERO_ADDRESS_BYTES = fullAddress("0x0").toUint8Array(); var GAS_LIMIT_SAFETY_BPS = 2e3; function encodePacket(packet) { const encoded_packet = new extendedBuffer.ExtendedBuffer(); encoded_packet.writeBuffer(new BN__default.default(packet.nonce.toString()).toArrayLike(Buffer, "be", 8)); encoded_packet.writeUInt16BE(new BN__default.default(packet.src_chain_id).toNumber()); encoded_packet.writeBuffer(packet.src_address); encoded_packet.writeUInt16BE(new BN__default.default(packet.dst_chain_id).toNumber()); encoded_packet.writeBuffer(packet.dst_address); encoded_packet.writeBuffer(packet.payload); return encoded_packet.buffer; } function computeGuid(packet) { const encoded_packet = new extendedBuffer.ExtendedBuffer(); encoded_packet.writeBuffer(new BN__default.default(packet.nonce.toString()).toArrayLike(Buffer, "be", 8)); encoded_packet.writeUInt16BE(new BN__default.default(packet.src_chain_id).toNumber()); encoded_packet.writeBuffer(packet.src_address); encoded_packet.writeUInt16BE(new BN__default.default(packet.dst_chain_id).toNumber()); encoded_packet.writeBuffer(packet.dst_address); return hashBuffer(encoded_packet.buffer); } async function decodePacket(buf, getAddressSizeOfChain) { const extendedBuffer$1 = new extendedBuffer.ExtendedBuffer(); extendedBuffer$1.writeBuffer(buf); const nonce = BigInt(new BN__default.default(Uint8Array.from(extendedBuffer$1.readBuffer(8, true)), "be").toString()); const src_chain_id = extendedBuffer$1.readUInt16BE(); const src_address = extendedBuffer$1.readBuffer(32, true); const dst_chain_id = extendedBuffer$1.readUInt16BE(); let addressSize = 0; if (typeof getAddressSizeOfChain === "number") { addressSize = getAddressSizeOfChain; } else if (typeof getAddressSizeOfChain === "function") { addressSize = await getAddressSizeOfChain(dst_chain_id); } const dst_address = extendedBuffer$1.readBuffer(addressSize, true); const payload = extendedBuffer$1.readBuffer(extendedBuffer$1.getReadableSize(), true); return { nonce, src_chain_id, src_address, dst_chain_id, dst_address, payload }; } async function decodePacketString(encodedPacket, dstAddressSize) { return decodePacket(Buffer.from(aptos2__namespace.HexString.ensure(encodedPacket).toUint8Array()), dstAddressSize); } function hashBuffer(buf) { return crypto__default.default.createHash("sha3-256").update(buf).digest("hex"); } function hashPacket(packet) { return hashBuffer(encodePacket(packet)); } async function rebuildPacketFromEvent(event, getAddressSizeOfChain) { const hexValue = event.data.encoded_packet.replace(/^0x/, ""); const input = Buffer.from(hexValue, "hex"); return decodePacket(input, getAddressSizeOfChain); } async function generateMultisig(publicKeys, threshold) { const multiSigPublicKey = new aptos2__namespace.TxnBuilderTypes.MultiEd25519PublicKey( publicKeys.map((publicKey) => new aptos2__namespace.TxnBuilderTypes.Ed25519PublicKey(publicKey)), threshold ); const authKey = aptos2__namespace.TxnBuilderTypes.AuthenticationKey.fromMultiEd25519PublicKey(multiSigPublicKey); return [multiSigPublicKey, authKey.derivedAddress().toString()]; } function multiSigSignedBCSTxn(pubkey, rawTx, signatures, bitmap) { const txBuilder = new aptos2__namespace.TransactionBuilderMultiEd25519(() => { return new aptos2__namespace.TxnBuilderTypes.MultiEd25519Signature( signatures.map((signature) => new aptos2__namespace.TxnBuilderTypes.Ed25519Signature(signature.toUint8Array())), aptos2__namespace.TxnBuilderTypes.MultiEd25519Signature.createBitmap(bitmap) ); }, pubkey); return txBuilder.sign(rawTx); } function fullAddress(address) { const rawValue = aptos2__namespace.HexString.ensure(address).noPrefix(); return aptos2__namespace.HexString.ensure( Buffer.concat([Buffer.alloc(64 - rawValue.length, "0"), Buffer.from(rawValue)]).toString() ); } function isHexStrict(hex) { return /^(-)?0x[0-9a-f]*$/i.test(hex); } function hexToAscii(hex) { invariant2__default.default(isHexStrict(hex), `Invalid hex string ${hex}`); let str = ""; let i = 0; const l = hex.length; if (hex.startsWith("0x")) { i = 2; } for (; i < l; i += 2) { const code = parseInt(hex.slice(i, i + 2), 16); str += String.fromCharCode(code); } return str; } function isSameAddress(a, b) { return fullAddress(a).toString() == fullAddress(b).toString(); } function isZeroAddress(a) { return isSameAddress(a, ZERO_ADDRESS_HEX); } function convertUint64ToBytes(number) { return aptos2__namespace.BCS.bcsSerializeUint64(number).reverse(); } function convertBytesToUint64(bytes) { return BigInt(new BN__default.default(bytes, "be").toString()); } function isErrorOfApiError(e, status) { if (e instanceof aptos2__namespace.ApiError) { return e.status === status; } else if (e instanceof Error && e.constructor.name.match(/ApiError[0-9]*/)) { if (Object.prototype.hasOwnProperty.call(e, "vmErrorCode")) { const err = e; return err.status === status; } else if (Object.prototype.hasOwnProperty.call(e, "request")) { const err = e; return err.status === status; } } else if (e instanceof Error) { if (Object.prototype.hasOwnProperty.call(e, "status")) { return e.status === status; } } return false; } function bytesToUint8Array(data, length) { return paddingUint8Array(data, length); } function convertToPaddedUint8Array(str, length) { return stringToPaddedUint8Array(str, length); } function stringToPaddedUint8Array(str, length) { const value = stringToUint8Array(str); return paddingUint8Array(value, length); } function paddingUint8Array(bytes, length) { if (bytes.length >= length) { return bytes; } return Uint8Array.from([...new Array(length - bytes.length), ...Array.from(bytes)]); } function stringToUint8Array(str) { const value = str.replace(/^0x/i, ""); const len = value.length + 1 - (value.length + 1) % 2; return Uint8Array.from(Buffer.from(value.padStart(len, "0"), "hex")); } function makeSignFuncWithMultipleSigners(...signers) { return async function(data) { const retval = signers.map((s, index) => { return { signature: s.signBuffer(data), bitmap: index }; }); return Promise.resolve(retval); }; } function applyGasLimitSafety(gasUsed) { return BigInt(gasUsed) * BigInt(1e4 + GAS_LIMIT_SAFETY_BPS) / BigInt(1e4); } function decodePayload(payload) { const extendedBuffer$1 = new extendedBuffer.ExtendedBuffer(); extendedBuffer$1.writeBuffer(payload); const packetType = extendedBuffer$1.readUInt8(); const remoteCoinAddr = extendedBuffer$1.readBuffer(32, true); const receiverBytes = extendedBuffer$1.readBuffer(32, true); const amount = new BN__default.default(extendedBuffer$1.readBuffer(8, true)); return { packetType, remoteCoinAddr, receiverBytes, amount }; } function getSignedTransactionHash(signedTransaction) { const deserializer = new aptos2__namespace.BCS.Deserializer(signedTransaction); const userTxn = aptos2__namespace.TxnBuilderTypes.UserTransaction.load(deserializer); const txnHash = aptos2__namespace.HexString.fromUint8Array(userTxn.hash()).toString(); return txnHash; } function getAddressFromPublicKey(publicKey) { const hash = sha3.sha3_256.create(); hash.update(publicKey.toBytes()); hash.update("\0"); return aptos2__namespace.HexString.fromUint8Array(hash.digest()); } async function getLzReceiveTypeArguments(bytecode, sdk, publicKey, dstAddress, srcChainId, srcAddress, payload) { const uaAddress = aptos2__namespace.HexString.ensure(Buffer.from(dstAddress).toString("hex")); await sdk.LayerzeroModule.Endpoint.getUATypeInfo(uaAddress); const ABIS = [ new TransactionScriptABI( "main", "", bytecode, [], [ new ArgumentABI("src_chain_id", new aptos2__namespace.TypeTagParser("u64").parseTypeTag()), new ArgumentABI("src_address", new aptos2__namespace.TypeTagParser("vector<u8>").parseTypeTag()), new ArgumentABI("payload", new aptos2__namespace.TypeTagParser("vector<u8>").parseTypeTag()) ] ) ]; const abis = ABIS.map((abi) => { const serializer = new aptos2__namespace.BCS.Serializer(); abi.serialize(serializer); return serializer.getBytes(); }); const builder = new aptos2__namespace.TransactionBuilderABI(abis); const transaction = builder.buildTransactionPayload( "main", [], [srcChainId, Uint8Array.from(srcAddress), Uint8Array.from(payload)] ); const address = getAddressFromPublicKey(publicKey); const rawTransaction = await sdk.client.generateRawTransaction(address, transaction, {}); const txns = await sdk.client.simulateTransaction(publicKey, rawTransaction); if (!txns[0].success) { throw new Error(txns[0].vm_status); } const result = txns.flatMap((txn) => txn.changes).filter( (change) => change.type === "write_resource" && change.data.type.match(/::executor_ext::TypeArguments$/) ).map((change) => change.data.data).flatMap((r) => { return r.types; }).map((t) => { const account_address = fullAddress(t.account_address).toString(); const module_name = hexToAscii(t.module_name); const struct_name = hexToAscii(t.struct_name); return `${account_address}::${module_name}::${struct_name}`; }); return result; } var DERIVE_RESOURCE_ACCOUNT_SCHEME = 255; function getResourceAddress(source, seed) { const bytes = [...aptos2__namespace.HexString.ensure(source).toUint8Array(), ...seed, DERIVE_RESOURCE_ACCOUNT_SCHEME]; const hash = crypto__default.default.createHash("sha3-256").update(Buffer.from(bytes)).digest("hex"); return aptos2__namespace.HexString.ensure(hash); } function getAccountFromPrivateKey(key) { const privateKeyBytes = Uint8Array.from(Buffer.from(aptos2__namespace.HexString.ensure(key).noPrefix(), "hex")); return new aptos2__namespace.AptosAccount(privateKeyBytes); } function getAccountFromMnemonic(mnemonic, path = "m/44'/637'/0'/0'/0'") { if (!aptos2__namespace.AptosAccount.isValidPath(path)) { throw new Error(`Invalid derivation path: ${path}`); } const normalizeMnemonics = mnemonic.trim().split(/\s+/).map((part) => part.toLowerCase()).join(" "); { const { key } = aptos2__namespace.derivePath(path, utils.bytesToHex(bip39__namespace.mnemonicToSeedSync(normalizeMnemonics))); return new aptos2__namespace.AptosAccount(new Uint8Array(key)); } } function normalizeTypeInfo(typeInfo) { const account_address = aptos2__namespace.HexString.ensure(typeInfo.account_address).toString(); const module_name = hexToAscii(typeInfo.module_name); const struct_name = hexToAscii(typeInfo.struct_name); return { account_address, module_name, struct_name }; } function buildStructTagFromTypeInfo(typeInfo) { let info = typeInfo; if (typeInfo.module_name.match("/^0x.*/i") && typeInfo.struct_name.match(/^0x.*/i)) { info = normalizeTypeInfo(typeInfo); } return `${info.account_address}::${info.module_name}::${info.struct_name}`; } function isTypeInfo(value) { const hasProperty = Object.prototype.hasOwnProperty; return hasProperty.call(value, "account_address") && hasProperty.call(value, "module_name") && hasProperty.call(value, "struct_name"); } // src/modules/channel.ts var Channel = class { /** * Creates an instance of the Channel class. * * @param {SDK} sdk - The SDK instance. */ constructor(sdk) { this.sdk = sdk; this.module = `${sdk.accounts.layerzero}::channel`; } /** * The module name. */ module; /** * Gets outbound events. * * @param {bigint} start - The start index. * @param {number} limit - The limit of events to retrieve. * @returns {Promise<aptos.Types.Event[]>} A promise that resolves to an array of events. */ async getOutboundEvents(start, limit) { return this.sdk.client.getEventsByEventHandle( this.sdk.accounts.layerzero, `${this.module}::EventStore`, "outbound_events", { start, limit } ); } /** * Gets inbound events. * * @param {bigint} start - The start index. * @param {number} limit - The limit of events to retrieve. * @returns {Promise<aptos.Types.Event[]>} A promise that resolves to an array of events. */ async getInboundEvents(start, limit) { return this.sdk.client.getEventsByEventHandle( this.sdk.accounts.layerzero, `${this.module}::EventStore`, "inbound_events", { start, limit } ); } /** * Gets receive events. * * @param {bigint} start - The start index. * @param {number} limit - The limit of events to retrieve. * @returns {Promise<aptos.Types.Event[]>} A promise that resolves to an array of events. */ async getReceiveEvents(start, limit) { return this.sdk.client.getEventsByEventHandle( this.sdk.accounts.layerzero, `${this.module}::EventStore`, "receive_events", { start, limit } ); } /** * Gets the channel state. * * @param {aptos.MaybeHexString} uaAddress - The user address. * @param {aptos.BCS.Uint16} remoteChainId - The remote chain ID. * @param {aptos.BCS.Bytes} remoteAddress - The remote address. * @param {Object} [query] - The query parameters. * @param {bigint | number} [query.ledgerVersion] - The ledger version. * @returns {Promise<ChannelType>} A promise that resolves to the channel state. */ async getChannelState(uaAddress, remoteChainId, remoteAddress, query) { const resource = await this.sdk.client.getAccountResource(uaAddress, `${this.module}::Channels`, query); const { states } = resource.data; const pathsHandle = states.handle; return this.sdk.client.getTableItem( pathsHandle, { key_type: `${this.module}::Remote`, value_type: `${this.module}::Channel`, key: { chain_id: remoteChainId.toString(), addr: Buffer.from(remoteAddress).toString("hex") } }, query ); } /** * Gets the outbound nonce. * * @param {aptos.MaybeHexString} uaAddress - The user address. * @param {aptos.BCS.Uint16} remoteChainId - The remote chain ID. * @param {aptos.BCS.Bytes} remoteAddress - The remote address. * @param {Object} [query] - The query parameters. * @param {bigint | number} [query.ledgerVersion] - The ledger version. * @returns {Promise<aptos.BCS.Uint64>} A promise that resolves to the outbound nonce. */ async getOutboundNonce(uaAddress, remoteChainId, remoteAddress, query) { try { const pathInfo = await this.getChannelState(uaAddress, remoteChainId, remoteAddress, query); const outboundNonce = pathInfo.outbound_nonce; return BigInt(outboundNonce); } catch (e) { if (isErrorOfApiError(e, 404)) { return BigInt(0); } throw e; } } /** * Gets the inbound nonce. * * @param {aptos.MaybeHexString} uaAddress - The user address. * @param {aptos.BCS.Uint16} remoteChainId - The remote chain ID. * @param {aptos.BCS.Bytes} remoteAddress - The remote address. * @param {Object} [query] - The query parameters. * @param {bigint | number} [query.ledgerVersion] - The ledger version. * @returns {Promise<aptos.BCS.Uint64>} A promise that resolves to the inbound nonce. */ async getInboundNonce(uaAddress, remoteChainId, remoteAddress, query) { try { const pathInfo = await this.getChannelState(uaAddress, remoteChainId, remoteAddress, query); const inboundNonce = pathInfo.inbound_nonce; return BigInt(inboundNonce); } catch (e) { if (isErrorOfApiError(e, 404)) { return BigInt(0); } throw e; } } /** * Gets the payload hash. * * @param {aptos.MaybeHexString} uaAddress - The user address. * @param {aptos.BCS.Uint16} remoteChainId - The remote chain ID. * @param {aptos.BCS.Bytes} remoteAddress - The remote address. * @param {aptos.BCS.Uint64} nonce - The nonce. * @param {Object} [query] - The query parameters. * @param {bigint | number} [query.ledgerVersion] - The ledger version. * @returns {Promise<string>} A promise that resolves to the payload hash. */ async getPayloadHash(uaAddress, remoteChainId, remoteAddress, nonce, query) { try { const pathInfo = await this.getChannelState(uaAddress, remoteChainId, remoteAddress, query); const resource = pathInfo.payload_hashs; return await this.sdk.client.getTableItem( resource.handle, { key_type: "u64", value_type: "vector<u8>", key: nonce.toString() }, query ); } catch (e) { if (isErrorOfApiError(e, 404)) { return ""; } throw e; } } /** * Checks if the proof is delivered. * * @param {aptos.MaybeHexString} uaAddress - The user address. * @param {aptos.BCS.Uint16} remoteChainId - The remote chain ID. * @param {aptos.BCS.Bytes} remoteAddress - The remote address. * @param {aptos.BCS.Uint64} nonce - The nonce. * @param {Object} [query] - The query parameters. * @param {bigint | number} [query.ledgerVersion] - The ledger version. * @returns {Promise<boolean>} A promise that resolves to true if the proof is delivered, false otherwise. */ async isProofDelivered(uaAddress, remoteChainId, remoteAddress, nonce, query) { const inboundNonce = await this.getInboundNonce(uaAddress, remoteChainId, remoteAddress, query); console.log(`inboundNonce: ${inboundNonce}`); console.log(`nonce: ${nonce}`); if (nonce <= inboundNonce) { return true; } const payloadHash = await this.getPayloadHash(uaAddress, remoteChainId, remoteAddress, nonce, query); return payloadHash !== ""; } }; var Endpoint = class { /** * Creates an instance of the Endpoint class. * * @param {SDK} sdk - The SDK instance. */ constructor(sdk) { this.sdk = sdk; this.module = `${sdk.accounts.layerzero}::endpoint`; this.moduleName = "layerzero::endpoint"; this.viewModule = `${sdk.accounts.view}::endpoint_view`; this.viewUln301Module = `${sdk.accounts.view_uln301}::uln_301`; } /** * The module name. */ module; /** * The module name with namespace. */ moduleName; /** * The view module name. */ viewModule; /** * The view module name for uln301. */ viewUln301Module; /** * Initializes the endpoint. * * @param {aptos.AptosAccount} signer - The signer account. * @param {aptos.BCS.Uint16} localChainId - The local chain ID. * @returns {Promise<aptos.Types.Transaction>} A promise that resolves to the transaction. */ async initialize(signer, localChainId) { const transaction = { function: `${this.module}::init`, type_arguments: [], arguments: [localChainId] }; return this.sdk.sendAndConfirmTransaction(signer, transaction); } /** * Gets the local chain ID. * * @returns {Promise<aptos.BCS.Uint64 | undefined>} A promise that resolves to the local chain ID or undefined if not found. */ async getLocalChainId() { try { const resource = await this.sdk.client.getAccountResource( this.sdk.accounts.layerzero, `${this.module}::ChainConfig` ); const { local_chain_id } = resource.data; return local_chain_id; } catch (err) { if (err instanceof aptos2.ApiError && err.errorCode === "resource_not_found") { return void 0; } throw err; } } /** * Gets the UA type information. * * @param {aptos.MaybeHexString} uaAddress - The UA address. * @returns {Promise<TypeInfoEx>} A promise that resolves to the type information. */ async getUATypeInfo(uaAddress) { const resource = await this.sdk.client.getAccountResource( this.sdk.accounts.layerzero, `${this.module}::UaRegistry` ); const { ua_infos } = resource.data; const typesHandle = ua_infos.handle; const typeInfo = await this.sdk.client.getTableItem(typesHandle, { key_type: "address", value_type: `0x1::type_info::TypeInfo`, key: aptos2__namespace.HexString.ensure(uaAddress).toString() }); const account_address = fullAddress(typeInfo.account_address).toString(); const module_name = hexToAscii(typeInfo.module_name); const struct_name = hexToAscii(typeInfo.struct_name); return { account_address, module_name, struct_name, type: `${account_address}::${module_name}::${struct_name}` }; } /** * Gets the oracle fee. * * @param {aptos.MaybeHexString} oracleAddr - The oracle address. * @param {aptos.BCS.Uint16} dstChainId - The destination chain ID. * @returns {Promise<aptos.BCS.Uint64>} A promise that resolves to the oracle fee. */ async getOracleFee(oracleAddr, dstChainId) { if (this.sdk.accounts.layerzero === void 0) { throw new Error("endpoint sdk accounts layerzero is undefined when invoke getOracleFee"); } const resource = await this.sdk.client.getAccountResource( this.sdk.accounts.layerzero, `${this.module}::FeeStore` ); const { oracle_fees } = resource.data; const response = await this.sdk.client.getTableItem(oracle_fees.handle, { key_type: `${this.module}::QuoteKey`, value_type: "u64", key: { agent: aptos2__namespace.HexString.ensure(oracleAddr).toString(), chain_id: dstChainId.toString() } }); return BigInt(response); } /** * Gets the register events. * * @param {bigint} start - The start index. * @param {number} limit - The limit of events to fetch. * @returns {Promise<aptos.Types.Event[]>} A promise that resolves to an array of events. */ async getRegisterEvents(start, limit) { if (this.sdk.accounts.layerzero === void 0) { throw new Error("endpoint sdk accounts layerzero is undefined when invoke getRegisterEvents"); } return this.sdk.client.getEventsByEventHandle( this.sdk.accounts.layerzero, `${this.module}::UaRegistry`, "register_events", { start, limit } ); } /** * Quotes the fee. * * @param {aptos.MaybeHexString} uaAddress - The UA address. * @param {aptos.BCS.Uint16} dstChainId - The destination chain ID. * @param {aptos.BCS.Bytes} adapterParams - The adapter parameters. * @param {number} payloadSize - The payload size. * @param {Object} [query] - The query parameters. * @param {bigint | number} [query.ledgerVersion] - The ledger version. * @param {aptos.BCS.Bytes} [msglibParams] - The msglib parameters. * @returns {Promise<{ nativeFee: aptos.BCS.Uint64; zroFee: aptos.BCS.Uint64 }>} A promise that resolves to the quoted fee. */ async quoteFee(uaAddress, dstChainId, adapterParams, payloadSize, msglibParams, payInZro = false, query) { const payload = { function: `${this.viewModule}::quote_fee`, type_arguments: [], arguments: [ uaAddress, dstChainId.toString(), payloadSize.toString(), payInZro, Buffer.from(adapterParams).toString("hex"), Buffer.from(msglibParams ?? new Uint8Array([])).toString("hex") ] }; const view = await this.sdk.viewFunction(payload); const [nativeFee, zroFee] = view[0]; return { nativeFee, zroFee }; } /** * Checks if a message is verifiable. * * @param {string} packetHeaderBytes - The packet header bytes. * @param {string} payloadHash - The payload hash. * @returns {Promise<aptos.BCS.Uint8>} A promise that resolves to the verifiable state. */ async verifiable(packetHeaderBytes, payloadHash) { const payload = { function: `${this.viewUln301Module}::verifiable`, type_arguments: [], arguments: [packetHeaderBytes, payloadHash] }; const view = await this.sdk.viewFunction(payload); return view[0]; } /** * Checks if a message is executable. * * @param {aptos.BCS.Uint32} srcEid - The source endpoint ID. * @param {aptos.BCS.Bytes} sender - The sender. * @param {aptos.BCS.Uint64} nonce - The nonce. * @param {aptos.MaybeHexString} receiver - The receiver. * @returns {Promise<aptos.BCS.Uint8>} A promise that resolves to the executable state. */ async executable(srcEid, sender, nonce, receiver) { const payload = { function: `${this.viewModule}::executable`, type_arguments: [], arguments: [srcEid, Buffer.from(sender).toString("hex"), nonce.toString(), receiver] }; const view = await this.sdk.viewFunction(payload); return view[0]; } /** * Gets the send msglib. * * @param {aptos.MaybeHexString} uaAddress - The UA address. * @param {aptos.BCS.Uint16} chainId - The chain ID. * @returns {Promise<[aptos.BCS.Uint64, aptos.BCS.Uint8]>} A promise that resolves to the send msglib. */ async getSendMsglib(uaAddress, chainId) { const payload = { function: `${this.viewModule}::get_send_msglib`, type_arguments: [], arguments: [uaAddress, chainId.toString()] }; try { const view = await this.sdk.viewFunction(payload); return view[0]; } catch (err) { if (isErrorOfApiError(err, 400)) { return [BigInt(0), 0]; } throw err; } } /** * Gets the receive msglib. * * @param {aptos.MaybeHexString} uaAddress - The UA address. * @param {aptos.BCS.Uint16} chainId - The chain ID. * @returns {Promise<[aptos.BCS.Uint64, aptos.BCS.Uint8]>} A promise that resolves to the receive msglib. */ async getReceiveMsglib(uaAddress, chainId) { const payload = { function: `${this.viewModule}::get_receive_msglib`, type_arguments: [], arguments: [uaAddress, chainId.toString()] }; try { const view = await this.sdk.viewFunction(payload); return view[0]; } catch (err) { if (isErrorOfApiError(err, 400)) { return [BigInt(0), 0]; } throw err; } } /** * Creates a payload for registering an executor. * * @param {string} executorType - The executor type. * @returns {aptos.Types.EntryFunctionPayload} The payload. */ registerExecutorPayload(executorType) { return { function: `${this.module}::register_executor`, type_arguments: [executorType], arguments: [] }; } /** * Registers an executor. * * @param {aptos.AptosAccount} signer - The signer account. * @param {string} executorType - The executor type. * @returns {Promise<aptos.Types.Transaction>} A promise that resolves to the transaction. */ async registerExecutor(signer, executorType) { const transaction = this.registerExecutorPayload(executorType); return this.sdk.sendAndConfirmTransaction(signer, transaction); } /** * Gets the executor capability. * * @param {string} [version='1'] - The version. * @returns {Promise<string | undefined>} A promise that resolves to the executor capability or undefined if not found. */ async getExecutorCap(version = "1") { try { const resource = await this.sdk.client.getAccountResource( this.sdk.accounts.layerzero, `${this.module}::Capabilities` ); const { executor_caps } = resource.data; const { handle } = executor_caps; const executorCap = await this.sdk.client.getTableItem(handle, { key_type: "u64", value_type: `${this.sdk.accounts.executor_auth}::executor_cap::ExecutorCapability`, key: version }); return executorCap.version; } catch (err) { if (err instanceof aptos2.ApiError && (err.errorCode === "resource_not_found" || err.errorCode === "table_item_not_found")) { return void 0; } throw err; } } }; // src/format/bytecode.ts var Bytecode = class { /** * Deserializes the bytecode. * @param {BCS.Deserializer} deserializer - The deserializer. * @returns {Bytecode} The deserialized bytecode. * @throws {Error} If the method is not implemented. */ static deserialize(deserializer) { throw new Error("Not implemented"); } }; var UnaryBytecode = class _UnaryBytecode extends Bytecode { /** * Creates an instance of UnaryBytecode. * @param {Opcodes} opcode - The opcode. */ constructor(opcode) { super(); this.opcode = opcode; } /** * Serializes the unary bytecode. * @param {BCS.Serializer} serializer - The serializer. */ serialize(serializer) { serializer.serializeU8(this.opcode); } /** * Deserializes the unary bytecode. * @param {BCS.Deserializer} deserializer - The deserializer. * @returns {Bytecode} The deserialized unary bytecode. */ static deserialize(deserializer) { const opcode = deserializer.deserializeU8(); return new _UnaryBytecode(opcode); } }; var BinaryBytecode = class _BinaryBytecode extends Bytecode { /** * Creates an instance of BinaryBytecode. * @param {Opcodes} opcode - The opcode. * @param {Index} operand - The operand. */ constructor(opcode, operand) { super(); this.opcode = opcode; this.operand = operand; } /** * Serializes the binary bytecode. * @param {BCS.Serializer} serializer - The serializer. */ serialize(serializer) { serializer.serializeU8(this.opcode); this.operand.serialize(serializer); } /** * Deserializes the binary bytecode. * @param {BCS.Deserializer} deserializer - The deserializer. * @returns {Bytecode} The deserialized binary bytecode. */ static deserialize(deserializer) { const opcode = deserializer.deserializeU8(); const index = Index.deserialize(deserializer); return new _BinaryBytecode(opcode, index); } }; var ROP = class extends UnaryBytecode { }; var RET = class extends UnaryBytecode { }; var BR_TRUE = class extends BinaryBytecode { }; var BR_FALSE = class extends BinaryBytecode { }; var BRANCH = class extends BinaryBytecode { }; var LD_U8 = class _LD_U8 extends Bytecode { /** * Creates an instance of LD_U8. * @param {Opcodes} opcode - The opcode. * @param {BCS.Uint8} value - The value. */ constructor(opcode, value) { super(); this.opcode = opcode; this.value = value; } /** * Serializes the LD_U8 bytecode. * @param {BCS.Serializer} serializer - The serializer. */ serialize(serializer) { serializer.serializeU8(this.opcode); serializer.serializeU8(this.value); } /** * Deserializes the LD_U8 bytecode. * @param {BCS.Deserializer} deserializer - The deserializer. * @returns {Bytecode} The deserialized LD_U8 bytecode. */ static deserialize(deserializer) { const opcode = deserializer.deserializeU8(); const value = deserializer.deserializeU8(); return new _LD_U8(opcode, value); } }; var LD_U64 = class _LD_U64 extends Bytecode { /** * Creates an instance of LD_U64. * @param {Opcodes} opcode - The opcode. * @param {BCS.Uint64} value - The value. */ constructor(opcode, value) { super(); this.opcode = opcode; this.value = value; } /** * Serializes the LD_U64 bytecode. * @param {BCS.Serializer} serializer - The serializer. */ serialize(serializer) { serializer.serializeU8(this.opcode); serializer.serializeU64(this.value); } /** * Deserializes the LD_U64 bytecode. * @param {BCS.Deserializer} deserializer - The deserializer. * @returns {Bytecode} The deserialized LD_U64 bytecode. */ static deserialize(deserializer) { con