Skip to content

Commit 419624a

Browse files
amateimaalexandrumatei36melisaguevaranicholaspai
authored
feat: update finalizer to handle quote deadline with emergencyReceive (#3026)
* feat: update finalizer to handle quote deadline with emergencyReceive * Fix * add emergencyReceive ABI --------- Co-authored-by: Alexandru Matei <alexandrumatei3693@gmail.com> Co-authored-by: Melisa Guevara <melisaguevarav@gmail.com> Co-authored-by: nicholaspai <9457025+nicholaspai@users.noreply.github.com>
1 parent dd714b7 commit 419624a

File tree

4 files changed

+37
-6
lines changed

4 files changed

+37
-6
lines changed

src/cctp-finalizer/services/cctpService.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export class CCTPService {
5050
attestation: cctpAttestationUnion,
5151
destinationChainId: providedDestinationChainIdUnion,
5252
signature: signatureUnion,
53+
quoteDeadline: quoteDeadlineUnion,
5354
} = message;
5455

5556
this.evmPrivateKey = await this.getPrivateKey("evm");
@@ -59,6 +60,7 @@ export class CCTPService {
5960
const cctpAttestation = cctpAttestationUnion?.string;
6061
const providedDestinationChainId = providedDestinationChainIdUnion?.long;
6162
const signature = signatureUnion?.string;
63+
const quoteDeadline = quoteDeadlineUnion?.long;
6264

6365
this.logger.info({
6466
at: "CCTPService#processBurnTransaction",
@@ -168,7 +170,7 @@ export class CCTPService {
168170
}
169171

170172
// Process the mint
171-
return await this.processMint(destinationChainId, sourceChainId, attestation, signature);
173+
return await this.processMint(destinationChainId, sourceChainId, attestation, signature, quoteDeadline);
172174
} catch (error) {
173175
if (isCCTPError(error)) {
174176
if (error instanceof AlreadyProcessedError) {
@@ -250,7 +252,8 @@ export class CCTPService {
250252
destinationChainId: number,
251253
originChainId: number,
252254
attestation: any,
253-
signature?: string
255+
signature?: string,
256+
quoteDeadline?: number
254257
): Promise<ProcessBurnTransactionResponse> {
255258
const chainName = PUBLIC_NETWORKS[destinationChainId]?.name || `Chain ${destinationChainId}`;
256259
this.logger.info({
@@ -290,7 +293,8 @@ export class CCTPService {
290293
provider,
291294
this.evmPrivateKey,
292295
this.logger,
293-
signature
296+
signature,
297+
quoteDeadline
294298
);
295299
return {
296300
success: true,

src/cctp-finalizer/types/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export interface PubSubMessage {
2323
attestation?: StringUnion | null;
2424
destinationChainId?: LongUnion | null;
2525
signature?: StringUnion | null;
26+
quoteDeadline?: LongUnion | null;
2627
}
2728

2829
export interface ChainConfig {

src/cctp-finalizer/utils/evmUtils.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ export async function processMintEvm(
135135
provider: ethers.providers.JsonRpcProvider,
136136
privateKey: string,
137137
logger: winston.Logger,
138-
signature?: string
138+
signature?: string,
139+
quoteDeadline?: number
139140
): Promise<{ txHash: string }> {
140141
const signer = new ethers.Wallet(privateKey, provider);
141142

@@ -147,10 +148,17 @@ export async function processMintEvm(
147148

148149
const contract = new ethers.Contract(destination.address, destination.abi, signer);
149150

150-
const receiveMessageArgs = destination.requiresSignature
151+
let receiveMessageArgs = destination.requiresSignature
151152
? [attestation.message, attestation.attestation, signature]
152153
: [attestation.message, attestation.attestation];
153154

155+
// if the quote deadline has expired, we don't need to pass the signature
156+
let method = "receiveMessage";
157+
if (destination.requiresSignature && quoteDeadline < Date.now() / 1000) {
158+
receiveMessageArgs = [attestation.message, attestation.attestation];
159+
method = "emergencyReceiveMessage";
160+
}
161+
154162
logger.info({
155163
at: "evmUtils#processMintEvm",
156164
message: `Using ${destination.type} destination contract`,
@@ -163,7 +171,7 @@ export async function processMintEvm(
163171
const mintTx = await submitTransaction(
164172
{
165173
contract: contract,
166-
method: "receiveMessage",
174+
method,
167175
args: receiveMessageArgs,
168176
chainId,
169177
},

src/common/abi/SponsoredCCTPDstPeriphery.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,23 @@
2121
"outputs": [],
2222
"stateMutability": "nonpayable",
2323
"type": "function"
24+
},
25+
{
26+
"inputs": [
27+
{
28+
"internalType": "bytes",
29+
"name": "message",
30+
"type": "bytes"
31+
},
32+
{
33+
"internalType": "bytes",
34+
"name": "attestation",
35+
"type": "bytes"
36+
}
37+
],
38+
"name": "emergencyReceiveMessage",
39+
"outputs": [],
40+
"stateMutability": "nonpayable",
41+
"type": "function"
2442
}
2543
]

0 commit comments

Comments
 (0)