Skip to content

Commit 532bd38

Browse files
committed
feat(compactX): extract nonce check
1 parent 398970f commit 532bd38

File tree

4 files changed

+28
-18
lines changed

4 files changed

+28
-18
lines changed

typescript/solver/solvers/compactX/config/metadata.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ const metadata: CompactXMetadata = {
150150
{
151151
name: "validateArbiterAndTribunal",
152152
},
153+
{
154+
name: "verifyNonce",
155+
},
153156
],
154157
},
155158
};

typescript/solver/solvers/compactX/filler.ts

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -70,24 +70,6 @@ export class CompactXFiller extends BaseFiller<
7070
intent: `${this.metadata.protocolName}-${request.compact.id}`,
7171
});
7272

73-
const chainId = +request.chainId;
74-
75-
// Check if nonce has already been consumed
76-
const theCompactService = new TheCompactService(
77-
this.multiProvider,
78-
this.log,
79-
);
80-
81-
const nonceConsumed = await theCompactService.hasConsumedAllocatorNonce(
82-
chainId,
83-
BigInt(request.compact.nonce),
84-
request.compact.arbiter,
85-
);
86-
87-
if (nonceConsumed) {
88-
throw new Error("Nonce has already been consumed");
89-
}
90-
9173
// Process the broadcast transaction
9274
const mandateChainId = request.compact.mandate.chainId;
9375

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export { checkExpirations } from "./checkExpirations.js";
22
export { validateArbiterAndTribunal } from "./validateArbiterAndTribunal.js";
33
export { validateChainsAndTokens } from "./validateChainsAndTokens.js";
4+
export { verifyNonce } from "./verifyNonce.js";
45
export { verifySignatures } from "./verifySignatures.js";
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import type { CompactXRule } from "../filler.js";
2+
import { TheCompactService } from "../services/TheCompactService.js";
3+
import { log } from "../utils.js";
4+
5+
export function verifyNonce(): CompactXRule {
6+
return async (parsedArgs, context) => {
7+
const theCompactService = new TheCompactService(context.multiProvider, log);
8+
9+
const nonceConsumed = await theCompactService.hasConsumedAllocatorNonce(
10+
+parsedArgs.context.chainId,
11+
BigInt(parsedArgs.context.compact.nonce),
12+
parsedArgs.context.compact.arbiter,
13+
);
14+
15+
if (nonceConsumed) {
16+
return {
17+
error: "Nonce has already been consumed",
18+
success: false,
19+
};
20+
}
21+
22+
return { data: "Signatures are Ok", success: true };
23+
};
24+
}

0 commit comments

Comments
 (0)