Skip to content

Commit

Permalink
[Blockchain Watcher] (MCTP) Feature 1652/map mctp events (#1692)
Browse files Browse the repository at this point in the history
* Map CMTP events like CCTP

* Rename mapVaaFromFunction

* Run MCTP by contract and topic

* Improve abi format

* Rename standarRelayer in contract mapper

---------

Co-authored-by: julian merlo <julianmerlo@julians-MacBook-Air.local>
  • Loading branch information
julianmerlo95 and julian merlo committed Sep 17, 2024
1 parent 9ce04c7 commit a96572e
Show file tree
Hide file tree
Showing 4 changed files with 271 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@
},
{
"addresses": ["0x27428dd2d3dd32a4d7f7c497eaaa23130d894911"],
"type": "StandardRelayer",
"type": "Standard Relayer",
"methods": [
{
"methodId": "0xa60eb4c8",
Expand Down Expand Up @@ -228,6 +228,16 @@
"method": "MethodFulfillOrder"
}
]
},
{
"addresses": [],
"type": "MCTP",
"methods": [
{
"methodId": "0x958c0937",
"method": "MethodRedeemWithFee"
}
]
}
]
},
Expand Down Expand Up @@ -285,7 +295,7 @@
},
{
"addresses": ["0x7b1bd7a6b4e61c2a123ac6bc2cbfc614437d0470"],
"type": "StandardRelayer",
"type": "Standard Relayer",
"methods": [
{
"methodId": "0xa60eb4c8",
Expand Down Expand Up @@ -411,7 +421,7 @@
"0x0591c25ebd0580e0d4f27a82fc2e24e7489cb5e0",
"0x27428dd2d3dd32a4d7f7c497eaaa23130d894911"
],
"type": "StandardRelayer",
"type": "Standard Relayer",
"methods": [
{
"methodId": "0xa60eb4c8",
Expand Down Expand Up @@ -446,6 +456,16 @@
"method": "MethodFulfillOrder"
}
]
},
{
"addresses": [],
"type": "MCTP",
"methods": [
{
"methodId": "0x958c0937",
"method": "MethodRedeemWithFee"
}
]
}
]
},
Expand Down Expand Up @@ -533,7 +553,7 @@
"0x80ac94316391752a193c1c47e27d382b507c93f3",
"0x27428dd2d3dd32a4d7f7c497eaaa23130d894911"
],
"type": "StandardRelayer",
"type": "Standard Relayer",
"methods": [
{
"methodId": "0xa60eb4c8",
Expand Down Expand Up @@ -619,7 +639,7 @@
},
{
"addresses": ["0x27428dd2d3dd32a4d7f7c497eaaa23130d894911"],
"type": "StandardRelayer",
"type": "Standard Relayer",
"methods": [
{
"methodId": "0xa60eb4c8",
Expand Down Expand Up @@ -762,7 +782,7 @@
"0xa3cf45939bd6260bcfe3d66bc73d60f19e49a8bb",
"0x27428dd2d3dd32a4d7f7c497eaaa23130d894911"
],
"type": "StandardRelayer",
"type": "Standard Relayer",
"methods": [
{
"methodId": "0xa60eb4c8",
Expand Down Expand Up @@ -802,6 +822,16 @@
"method": "MethodFulfillOrder"
}
]
},
{
"addresses": [],
"type": "MCTP",
"methods": [
{
"methodId": "0x958c0937",
"method": "MethodRedeemWithFee"
}
]
}
]
},
Expand Down Expand Up @@ -894,7 +924,7 @@
"0x0591c25ebd0580e0d4f27a82fc2e24e7489cb5e0",
"0x27428dd2d3dd32a4d7f7c497eaaa23130d894911"
],
"type": "StandardRelayer",
"type": "Standard Relayer",
"methods": [
{
"methodId": "0xa60eb4c8",
Expand Down Expand Up @@ -963,7 +993,7 @@
"0x306b68267deb7c5dfcda3619e22e9ca39c374f84",
"0x27428dd2d3dd32a4d7f7c497eaaa23130d894911"
],
"type": "StandardRelayer",
"type": "Standard Relayer",
"methods": [
{
"methodId": "0xa60eb4c8",
Expand Down Expand Up @@ -1077,7 +1107,7 @@
},
{
"addresses": ["0x27428dd2d3dd32a4d7f7c497eaaa23130d894911"],
"type": "StandardRelayer",
"type": "Standard Relayer",
"methods": [
{
"methodId": "0xa60eb4c8",
Expand Down Expand Up @@ -1130,6 +1160,16 @@
"method": "FillRedeemed"
}
]
},
{
"addresses": [],
"type": "MCTP",
"methods": [
{
"methodId": "0x958c0937",
"method": "MethodRedeemWithFee"
}
]
}
]
},
Expand Down Expand Up @@ -1187,7 +1227,7 @@
},
{
"addresses": ["0x7b1bd7a6b4e61c2a123ac6bc2cbfc614437d0470"],
"type": "StandardRelayer",
"type": "Standard Relayer",
"methods": [
{
"methodId": "0xa60eb4c8",
Expand Down Expand Up @@ -1284,7 +1324,7 @@
},
{
"addresses": ["0x27428dd2d3dd32a4d7f7c497eaaa23130d894911"],
"type": "StandardRelayer",
"type": "Standard Relayer",
"methods": [
{
"methodId": "0xa60eb4c8",
Expand Down Expand Up @@ -1324,6 +1364,16 @@
"method": "MethodFulfillOrder"
}
]
},
{
"addresses": [],
"type": "MCTP",
"methods": [
{
"methodId": "0x958c0937",
"method": "MethodRedeemWithFee"
}
]
}
]
},
Expand Down Expand Up @@ -1371,7 +1421,7 @@
},
{
"addresses": ["0x93bad53ddfb6132b0ac8e37f6029163e63372cee"],
"type": "StandardRelayer",
"type": "Standard Relayer",
"methods": [
{
"methodId": "0xa60eb4c8",
Expand Down Expand Up @@ -1519,6 +1569,16 @@
"method": "MethodFulfillOrder"
}
]
},
{
"addresses": [],
"type": "MCTP",
"methods": [
{
"methodId": "0x958c0937",
"method": "MethodRedeemWithFee"
}
]
}
]
},
Expand Down Expand Up @@ -1571,7 +1631,7 @@
},
{
"addresses": ["0x93bad53ddfb6132b0ac8e37f6029163e63372cee"],
"type": "StandardRelayer",
"type": "Standard Relayer",
"methods": [
{
"methodId": "0xa60eb4c8",
Expand Down Expand Up @@ -1746,7 +1806,7 @@
},
{
"addresses": ["0x27428dd2d3dd32a4d7f7c497eaaa23130d894911"],
"type": "StandardRelayer",
"type": "Standard Relayer",
"methods": [
{
"methodId": "0xa60eb4c8",
Expand Down Expand Up @@ -1786,7 +1846,7 @@
},
{
"addresses": ["0x27428dd2d3dd32a4d7f7c497eaaa23130d894911"],
"type": "StandardRelayer",
"type": "Standard Relayer",
"methods": [
{
"methodId": "0xa60eb4c8",
Expand Down Expand Up @@ -1886,7 +1946,7 @@
},
{
"addresses": [],
"type": "StandardRelayer",
"type": "Standard Relayer",
"methods": [
{
"methodId": "0xa60eb4c8",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,27 +189,32 @@ const mapVaaFromInput: LogToVaaMapper = (_, input: string) => {
}
};

const mapVaaFromMayanWithSwiftDelivery: LogToVaaMapper = (
const mapVaaFromFunction: LogToVaaMapper = (
log: EvmTransactionLog,
input: string,
cfg: HandleEvmConfig
) => {
const abi = cfg.abis?.find((abi) => abi.topic === log.topics[0]);
if (!abi) return undefined;
try {
const abi = cfg.abis?.find((abi) => abi.topic === log.topics[0]);
if (!abi) return undefined;

const iface = new ethers.utils.Interface([`function ${abi.abi}`]);
const decodedFulfillOrderFunction = iface.decodeFunctionData(abi.abi, input);
if (!decodedFulfillOrderFunction || !decodedFulfillOrderFunction.encodedVm) return undefined;
const iface = new ethers.utils.Interface([`function ${abi.abi}`]);
const decodedFulfillOrderFunction = iface.decodeFunctionData(abi.abi, input);
if (!decodedFulfillOrderFunction || !decodedFulfillOrderFunction.encodedVm) return undefined;

const payload = decodedFulfillOrderFunction.encodedVm;
const vaaBuffer = Buffer.from(payload.substring(2), "hex"); // Remove 0x
const vaa = parseVaa(vaaBuffer);
const payload = decodedFulfillOrderFunction.encodedVm;
const vaaBuffer = Buffer.from(payload.substring(2), "hex"); // Remove 0x
const vaa = parseVaa(vaaBuffer);

return {
emitterChain: Number(vaa.emitterChain),
emitterAddress: vaa.emitterAddress.toString("hex"),
sequence: Number(vaa.sequence),
};
return {
emitterChain: Number(vaa.emitterChain),
emitterAddress: vaa.emitterAddress.toString("hex"),
sequence: Number(vaa.sequence),
};
} catch (e) {
// If we cant parse the VAA we ignore it and then try to use other mapper
return undefined;
}
};

type VaaInformation = {
Expand All @@ -230,8 +235,8 @@ const REDEEM_TOPICS: Record<string, LogToVaaMapper> = {
"0xf6fc529540981400dc64edf649eb5e2e0eb5812a27f8c81bac2c1d317e71a5f0": mapVaaFromDataBuilder(1), // NTT manual
"0xf02867db6908ee5f81fd178573ae9385837f0a0a72553f8c08306759a7e0f00e": mapVaaFromTopics, // CCTP
"0x67cc74e969bff447b6e0f32eea34930545a732749bdcaaf3530c70e311900b06": mapVaaFromTopics, // Fast Transfer
"0xcc5626df3b699006387b64eca775dbdfecd5ae542e2d6ab22923082e1320dfcb":
mapVaaFromMayanWithSwiftDelivery, // Mayan with Swift
"0x58200b4c34ae05ee816d710053fff3fb75af4395915d3d2a771b24aa10e3cc5d": mapVaaFromFunction, // MCTP
"0xcc5626df3b699006387b64eca775dbdfecd5ae542e2d6ab22923082e1320dfcb": mapVaaFromFunction, // Mayan with Swift
"0xbccc00b713f54173962e7de6098f643d8ebf53d488d71f4b2a5171496d038f9e":
mapVaaFromStandardRelayerDelivery, // Standard Relayer
};
Loading

0 comments on commit a96572e

Please sign in to comment.