clients/js: Add support for AttestMeta
commit-id:67ad91cc
This commit is contained in:
parent
1b4c97cd67
commit
465916c3f8
|
@ -247,6 +247,10 @@ export async function execute_evm(
|
|||
console.log("Completing transfer")
|
||||
console.log("Hash: " + (await tb.completeTransfer(vaa, overrides)).hash)
|
||||
break
|
||||
case "AttestMeta":
|
||||
console.log("Creating wrapped token")
|
||||
console.log("Hash: " + (await tb.createWrapped(vaa, overrides)).hash)
|
||||
break
|
||||
case "TransferWithPayload":
|
||||
console.log("Completing transfer with payload")
|
||||
console.log("Hash: " + (await tb.completeTransferWithPayload(vaa, overrides)).hash)
|
||||
|
|
|
@ -144,7 +144,7 @@ yargs(hideBin(process.argv))
|
|||
| "Core"
|
||||
| "NFTBridge"
|
||||
| "TokenBridge";
|
||||
let payload: Payload = {
|
||||
let payload: vaa.ContractUpgrade = {
|
||||
module,
|
||||
type: "ContractUpgrade",
|
||||
chain: toChainId(argv["chain"]),
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
{
|
||||
version: 1,
|
||||
guardianSetIndex: 0,
|
||||
signatures: [
|
||||
{
|
||||
guardianSetIndex: 0,
|
||||
signature: '6cd3cdd701bbd878eb403f6505b5b797544eb9c486dadf79f0c445e9b8fa5cd474de1683e3a80f7e22dbfacd53b0ddc7b040ff6f974aafe7a6571c9355b8129b00'
|
||||
}
|
||||
],
|
||||
timestamp: 0,
|
||||
nonce: 2095245887,
|
||||
emitterChain: 1,
|
||||
emitterAddress: '0x95f83a27e90c622a98c037353f271fd8f5f57b4dc18ebf5ff75a934724bd0491',
|
||||
sequence: 11833801757748136510n,
|
||||
consistencyLevel: 32,
|
||||
payload: {
|
||||
module: 'TokenBridge',
|
||||
chain: 0,
|
||||
type: 'AttestMeta',
|
||||
tokenAddress: '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
||||
tokenChain: 2,
|
||||
decimals: 18,
|
||||
symbol: 'WETH',
|
||||
name: 'Wrapped ether'
|
||||
},
|
||||
digest: '0x4bb52b9a44ff6062ba5db1c47afc40c186f7485c8972b1c6261eb070ce0b1c6e'
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
010000000001006cd3cdd701bbd878eb403f6505b5b797544eb9c486dadf79f0c445e9b8fa5cd474de1683e3a80f7e22dbfacd53b0ddc7b040ff6f974aafe7a6571c9355b8129b00000000007ce2ea3f000195f83a27e90c622a98c037353f271fd8f5f57b4dc18ebf5ff75a934724bd0491a43a1c0020f88a3e2002000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200021200000000000000000000000000000000000000000000000000000000574554480000000000000000000000000000000000000057726170706564206574686572
|
|
@ -71,6 +71,10 @@ export async function execute_solana(
|
|||
ix = token_bridge.complete_transfer_wrapped_ix(token_bridge_id.toString(), bridge_id.toString(), from.publicKey.toString(), vaa)
|
||||
}
|
||||
break
|
||||
case "AttestMeta":
|
||||
console.log("Creating wrapped token")
|
||||
ix = token_bridge.create_wrapped_ix(token_bridge_id.toString(), bridge_id.toString(), from.publicKey.toString(), vaa)
|
||||
break
|
||||
case "TransferWithPayload":
|
||||
throw Error("Can't complete payload 3 transfer from CLI")
|
||||
default:
|
||||
|
|
|
@ -93,9 +93,11 @@ export async function execute_terra(
|
|||
case "Transfer":
|
||||
console.log("Completing transfer");
|
||||
break;
|
||||
case "TransferWithPayload":
|
||||
console.log("Completing transfer");
|
||||
case "AttestMeta":
|
||||
console.log("Creating wrapped token");
|
||||
break;
|
||||
case "TransferWithPayload":
|
||||
throw Error("Can't complete payload 3 transfer from CLI")
|
||||
default:
|
||||
impossible(payload)
|
||||
break
|
||||
|
|
|
@ -62,8 +62,14 @@ export type Payload =
|
|||
| PortalRegisterChain<"NFTBridge">
|
||||
| TokenBridgeTransfer
|
||||
| TokenBridgeTransferWithPayload
|
||||
| TokenBridgeAttestMeta
|
||||
// TODO: add other types of payloads
|
||||
|
||||
export type ContractUpgrade =
|
||||
CoreContractUpgrade
|
||||
| PortalContractUpgrade<"TokenBridge">
|
||||
| PortalContractUpgrade<"NFTBridge">
|
||||
|
||||
export function parse(buffer: Buffer): VAA<Payload | null> {
|
||||
const vaa = parseEnvelope(buffer)
|
||||
const parser = guardianSetUpgradeParser
|
||||
|
@ -74,6 +80,7 @@ export function parse(buffer: Buffer): VAA<Payload | null> {
|
|||
.or(portalRegisterChainParser("NFTBridge"))
|
||||
.or(tokenBridgeTransferParser())
|
||||
.or(tokenBridgeTransferWithPayloadParser())
|
||||
.or(tokenBridgeAttestMetaParser())
|
||||
const payload = parser.parse(vaa.payload)
|
||||
var myVAA = { ...vaa, payload }
|
||||
|
||||
|
@ -200,6 +207,9 @@ function vaaBody(vaa: VAA<Payload>) {
|
|||
case "TransferWithPayload":
|
||||
payload_str = serialiseTokenBridgeTransferWithPayload(payload)
|
||||
break
|
||||
case "AttestMeta":
|
||||
payload_str = serialiseTokenBridgeAttestMeta(payload)
|
||||
break
|
||||
default:
|
||||
impossible(payload)
|
||||
break
|
||||
|
@ -440,6 +450,7 @@ function serialisePortalRegisterChain<Module extends "NFTBridge" | "TokenBridge"
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Token bridge
|
||||
|
||||
// payload 1
|
||||
export interface TokenBridgeTransfer {
|
||||
module: "TokenBridge"
|
||||
type: "Transfer"
|
||||
|
@ -504,6 +515,70 @@ function serialiseTokenBridgeTransfer(payload: TokenBridgeTransfer): string {
|
|||
return body.join("")
|
||||
}
|
||||
|
||||
// payload 2
|
||||
export interface TokenBridgeAttestMeta {
|
||||
module: "TokenBridge"
|
||||
type: "AttestMeta"
|
||||
chain: 0,
|
||||
tokenAddress: string
|
||||
tokenChain: number
|
||||
decimals: number
|
||||
symbol: string
|
||||
name: string
|
||||
}
|
||||
|
||||
function tokenBridgeAttestMetaParser(): P<TokenBridgeAttestMeta> {
|
||||
return new P(new Parser()
|
||||
.endianess("big")
|
||||
.string("module", {
|
||||
length: (_) => 0,
|
||||
formatter: (_) => "TokenBridge"
|
||||
})
|
||||
.string("chain", {
|
||||
length: (_) => 0,
|
||||
formatter: (_) => 0
|
||||
})
|
||||
.uint8("type", {
|
||||
assert: 2,
|
||||
formatter: (_action) => "AttestMeta"
|
||||
})
|
||||
.array("tokenAddress", {
|
||||
type: "uint8",
|
||||
lengthInBytes: 32,
|
||||
formatter: (arr) => "0x" + Buffer.from(arr).toString("hex")
|
||||
})
|
||||
.uint16("tokenChain")
|
||||
.uint8("decimals")
|
||||
.array("symbol", {
|
||||
type: "uint8",
|
||||
lengthInBytes: 32,
|
||||
formatter: (arr: Uint8Array) => Buffer.from(arr).toString("utf8", arr.findIndex((val) => val != 0))
|
||||
})
|
||||
.array("name", {
|
||||
type: "uint8",
|
||||
lengthInBytes: 32,
|
||||
formatter: (arr: Uint8Array) => Buffer.from(arr).toString("utf8", arr.findIndex((val) => val != 0))
|
||||
})
|
||||
.string("end", {
|
||||
greedy: true,
|
||||
assert: str => str === ""
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
function serialiseTokenBridgeAttestMeta(payload: TokenBridgeAttestMeta): string {
|
||||
const body = [
|
||||
encode("uint8", 2),
|
||||
encode("bytes32", hex(payload.tokenAddress)),
|
||||
encode("uint16", payload.tokenChain),
|
||||
encode("uint8", payload.decimals),
|
||||
encode("bytes32", encodeString(payload.symbol)),
|
||||
encode("bytes32", encodeString(payload.name)),
|
||||
]
|
||||
return body.join("")
|
||||
}
|
||||
|
||||
// payload 3
|
||||
export interface TokenBridgeTransferWithPayload {
|
||||
module: "TokenBridge"
|
||||
type: "TransferWithPayload"
|
||||
|
|
Loading…
Reference in New Issue