@layerzerolabs/lz-aptos-sdk-v1 2.0.14 → 2.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +72 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +15 -1
- package/dist/index.d.ts +15 -1
- package/dist/index.mjs +72 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -1972,10 +1972,60 @@ var Executor = class {
|
|
|
1972
1972
|
);
|
|
1973
1973
|
return typeInfos;
|
|
1974
1974
|
}
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1975
|
+
/**
|
|
1976
|
+
* get lz_receive_types arguments by view function (tagged with #[view])
|
|
1977
|
+
* 1. try UA::${module}::lz_receive_types, if failed, then
|
|
1978
|
+
* 2. try UA::lz_receive::lz_receive_types by convention
|
|
1979
|
+
* @param packet
|
|
1980
|
+
* @param ledger_version
|
|
1981
|
+
*/
|
|
1982
|
+
async getLzReceiveTypeArgumentsView(packet, ledger_version) {
|
|
1983
|
+
const dstAddressHex = Buffer.from(packet.dst_address).toString("hex");
|
|
1984
|
+
const uaAddress = aptos2__namespace.HexString.ensure(dstAddressHex);
|
|
1985
|
+
const uaTypeInfo = await this.sdk.LayerzeroModule.Endpoint.getUATypeInfo(uaAddress);
|
|
1986
|
+
const potentialModules = [uaTypeInfo.module_name, "lz_receive"];
|
|
1987
|
+
for (const module of potentialModules) {
|
|
1988
|
+
const payload = {
|
|
1989
|
+
function: `${uaTypeInfo.account_address}::${module}::lz_receive_types`,
|
|
1990
|
+
type_arguments: [],
|
|
1991
|
+
arguments: [
|
|
1992
|
+
`${packet.src_chain_id}`,
|
|
1993
|
+
Buffer.from(packet.src_address).toString("hex"),
|
|
1994
|
+
Buffer.from(packet.payload).toString("hex")
|
|
1995
|
+
]
|
|
1996
|
+
};
|
|
1997
|
+
try {
|
|
1998
|
+
const ret = await this.sdk.client.view(payload, ledger_version);
|
|
1999
|
+
const types = ret[0];
|
|
2000
|
+
return [
|
|
2001
|
+
types.map((t) => {
|
|
2002
|
+
const account_address = fullAddress(t.account_address).toString();
|
|
2003
|
+
const module_name = hexToAscii(t.module_name);
|
|
2004
|
+
const struct_name = hexToAscii(t.struct_name);
|
|
2005
|
+
return `${account_address}::${module_name}::${struct_name}`;
|
|
2006
|
+
}),
|
|
2007
|
+
{
|
|
2008
|
+
account_address: uaTypeInfo.account_address,
|
|
2009
|
+
module_name: module,
|
|
2010
|
+
struct_name: uaTypeInfo.struct_name,
|
|
2011
|
+
type: uaTypeInfo.type
|
|
2012
|
+
}
|
|
2013
|
+
];
|
|
2014
|
+
} catch (e) {
|
|
2015
|
+
if (isErrorOfApiError(e, 400)) {
|
|
2016
|
+
continue;
|
|
2017
|
+
}
|
|
2018
|
+
throw e;
|
|
2019
|
+
}
|
|
2020
|
+
}
|
|
2021
|
+
throw new Error(`failed to get lz_receive_types arguments for ${uaAddress}`);
|
|
2022
|
+
}
|
|
2023
|
+
async getLzReceivePayload(type_arguments, packet, uaTypeInfo) {
|
|
2024
|
+
if (!uaTypeInfo) {
|
|
2025
|
+
uaTypeInfo = await this.sdk.LayerzeroModule.Endpoint.getUATypeInfo(
|
|
2026
|
+
aptos2__namespace.HexString.fromBuffer(packet.dst_address)
|
|
2027
|
+
);
|
|
2028
|
+
}
|
|
1979
2029
|
const transaction = {
|
|
1980
2030
|
function: `${uaTypeInfo.account_address}::${uaTypeInfo.module_name}::lz_receive`,
|
|
1981
2031
|
type_arguments,
|
|
@@ -1991,6 +2041,24 @@ var Executor = class {
|
|
|
1991
2041
|
const transaction = await this.getLzReceivePayload(type_arguments, packet);
|
|
1992
2042
|
return this.sdk.sendAndConfirmTransaction(signer, transaction);
|
|
1993
2043
|
}
|
|
2044
|
+
/**
|
|
2045
|
+
* auto-detect lz_receive_types and call lz_receive
|
|
2046
|
+
* @param signer
|
|
2047
|
+
* @param packet
|
|
2048
|
+
*/
|
|
2049
|
+
async lzReceiveNew(signer, packet) {
|
|
2050
|
+
let transaction;
|
|
2051
|
+
try {
|
|
2052
|
+
const [typeArgs, uaTypeInfo] = await this.getLzReceiveTypeArgumentsView(packet);
|
|
2053
|
+
transaction = await this.getLzReceivePayload(typeArgs, packet, uaTypeInfo);
|
|
2054
|
+
} catch (e) {
|
|
2055
|
+
}
|
|
2056
|
+
if (!transaction) {
|
|
2057
|
+
const typeArgs = await this.getLzReceiveTypeArguments(packet);
|
|
2058
|
+
transaction = await this.getLzReceivePayload(typeArgs, packet);
|
|
2059
|
+
}
|
|
2060
|
+
return this.sdk.sendAndConfirmTransaction(signer, transaction);
|
|
2061
|
+
}
|
|
1994
2062
|
getShortRequestEventType() {
|
|
1995
2063
|
return `${this.module}::RequestEvent`.replace(/^(0x)0*/i, "$1");
|
|
1996
2064
|
}
|