Skip to content

Commit 45214b2

Browse files
authored
add support for chainless domain relayer (#386)
1 parent 2746071 commit 45214b2

File tree

2 files changed

+68
-1
lines changed

2 files changed

+68
-1
lines changed

src/constants/relayer.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,66 @@ export const ForwarderAbi = [
5656
},
5757
];
5858

59+
export const ForwarderAbiEIP712ChainlessDomain = [
60+
{ inputs: [], stateMutability: "nonpayable", type: "constructor" },
61+
{
62+
inputs: [
63+
{
64+
components: [
65+
{ internalType: "address", name: "from", type: "address" },
66+
{ internalType: "address", name: "to", type: "address" },
67+
{ internalType: "uint256", name: "value", type: "uint256" },
68+
{ internalType: "uint256", name: "gas", type: "uint256" },
69+
{ internalType: "uint256", name: "nonce", type: "uint256" },
70+
{ internalType: "bytes", name: "data", type: "bytes" },
71+
{ internalType: "uint256", name: "chainid", type: "uint256" },
72+
],
73+
internalType: "struct ForwarderChainlessDomain.ForwardRequest",
74+
name: "req",
75+
type: "tuple",
76+
},
77+
{ internalType: "bytes", name: "signature", type: "bytes" },
78+
],
79+
name: "execute",
80+
outputs: [
81+
{ internalType: "bool", name: "", type: "bool" },
82+
{ internalType: "bytes", name: "", type: "bytes" },
83+
],
84+
stateMutability: "payable",
85+
type: "function",
86+
},
87+
{
88+
inputs: [{ internalType: "address", name: "from", type: "address" }],
89+
name: "getNonce",
90+
outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
91+
stateMutability: "view",
92+
type: "function",
93+
},
94+
{
95+
inputs: [
96+
{
97+
components: [
98+
{ internalType: "address", name: "from", type: "address" },
99+
{ internalType: "address", name: "to", type: "address" },
100+
{ internalType: "uint256", name: "value", type: "uint256" },
101+
{ internalType: "uint256", name: "gas", type: "uint256" },
102+
{ internalType: "uint256", name: "nonce", type: "uint256" },
103+
{ internalType: "bytes", name: "data", type: "bytes" },
104+
{ internalType: "uint256", name: "chainid", type: "uint256" },
105+
],
106+
internalType: "struct ForwarderChainlessDomain.ForwardRequest",
107+
name: "req",
108+
type: "tuple",
109+
},
110+
{ internalType: "bytes", name: "signature", type: "bytes" },
111+
],
112+
name: "verify",
113+
outputs: [{ internalType: "bool", name: "", type: "bool" }],
114+
stateMutability: "view",
115+
type: "function",
116+
},
117+
];
118+
59119
export const ERC2771ContextAbi = [
60120
{
61121
inputs: [

src/server/routes/relayer/index.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
ERC20PermitAbi,
77
ERC2771ContextAbi,
88
ForwarderAbi,
9+
ForwarderAbiEIP712ChainlessDomain,
910
NativeMetaTransaction,
1011
} from "../../../constants/relayer";
1112
import { getRelayerById } from "../../../db/relayer/getRelayerById";
@@ -30,6 +31,7 @@ const BodySchema = Type.Union([
3031
gas: Type.String(),
3132
nonce: Type.String(),
3233
data: Type.String(),
34+
chainid: Type.Optional(Type.String()),
3335
}),
3436
signature: Type.String(),
3537
forwarderAddress: Type.String(),
@@ -252,9 +254,14 @@ export async function relayTransaction(fastify: FastifyInstance) {
252254
return;
253255
}
254256

257+
const isForwarderEIP712ChainlessDomain = !!request.chainid;
258+
const forwarderAbi = isForwarderEIP712ChainlessDomain
259+
? ForwarderAbiEIP712ChainlessDomain
260+
: ForwarderAbi;
261+
255262
const forwarder = await sdk.getContractFromAbi(
256263
forwarderAddress,
257-
ForwarderAbi,
264+
forwarderAbi,
258265
);
259266

260267
const valid = await forwarder.call("verify", [

0 commit comments

Comments
 (0)