Skip to content

Commit e1ec9cb

Browse files
authored
Merge pull request #260 from sprintertech/feat/add-cctpv2-hardhat-task
feat: add cctpv2 hardhat task for processing
2 parents 6a19494 + 09ec00b commit e1ec9cb

1 file changed

Lines changed: 54 additions & 0 deletions

File tree

hardhat.config.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -991,6 +991,60 @@ task("cctp-get-process-data", "Get burn attestation from CCTP Api to mint USDC o
991991
console.log(extraDatas);
992992
});
993993

994+
interface CCTPV2Message {
995+
attestation: string,
996+
message: string,
997+
eventNonce: string,
998+
status: string,
999+
};
1000+
1001+
interface CCTPV2ResponseSuccess {
1002+
messages: CCTPV2Message[],
1003+
};
1004+
1005+
task("cctpv2-get-process-data", "Get burn attestation from CCTP V2 Api to mint USDC on destination")
1006+
.addParam("txhash", "Hash of the initiate transaction")
1007+
.addOptionalParam("adapter", "Rebalancer or Repayer address", "0xA85Cf46c150db2600b1D03E437bedD5513869888")
1008+
.setAction(async ({txhash, adapter}: {txhash: string, adapter: string}, hre) => {
1009+
const {resolveProxyXAddress} = await loadTestHelpers();
1010+
assert(txhash.length > 0, "Valid txhash should be provided.");
1011+
1012+
const cctpAdapter = await hre.ethers.getContractAt("CCTPV2Adapter", await resolveProxyXAddress(adapter));
1013+
const cctpDomain = await cctpAdapter.domainCCTP(DomainSolidity[hre.network.name as Network]);
1014+
1015+
const url = `https://iris-api.circle.com/v2/messages/${cctpDomain}?transactionHash=${txhash}`;
1016+
const options = {method: "GET", headers: {"Content-Type": "application/json"}};
1017+
const result = await (await fetch(url, options)).json();
1018+
1019+
if (result.error) {
1020+
console.error(result.error);
1021+
return;
1022+
}
1023+
1024+
const success = result as CCTPV2ResponseSuccess;
1025+
1026+
assert(success.messages, `Messages are missing in CCTP response: ${success}`);
1027+
1028+
if (success.messages[0].status !== "complete" || !success.messages[0].attestation.startsWith("0x")) {
1029+
console.error("Attestation is not ready:", success.messages[0].status, success.messages[0].attestation);
1030+
return;
1031+
}
1032+
1033+
const extraDatas = success.messages.map(el => {
1034+
const destinationCCTP = toNumber(dataSlice(el.message, 8, 12));
1035+
const destination = CCTPDomain[destinationCCTP];
1036+
assert(destination, `Unknown CCTP domain ${destinationCCTP}`);
1037+
return {
1038+
destination,
1039+
extraData: AbiCoder.defaultAbiCoder().encode(["bytes", "bytes"], [el.message, el.attestation]),
1040+
};
1041+
});
1042+
1043+
const count = extraDatas.length;
1044+
console.log(count, `message${count > 1 ? "s" : ""} found.`);
1045+
console.log(extraDatas);
1046+
});
1047+
9941048
task("push-native-token", "Push native currency through a selfdestruct")
9951049
.addParam("receiver", "Address of the receiver")
9961050
.addOptionalParam("amount", "Human readable amount of native token to send", "0.0011")

0 commit comments

Comments
 (0)