Skip to content

Commit bde0467

Browse files
eip-712 signer sdk (#344)
* Add yarn lock * sdk: add support for EIP712 signing * tests: add eip712 encoder tests * remove eslint from tests * Add test setup for full integration test * Fix SignTypedMessageLib tests * add a chai failing test * fix integration test hardhat setup * scopeSignTypedMessage tests * format files * use renamed AbiType * Add MockEIP712Encoder test contract to expose EIP712Encoder functions * fix: replace ParameterType with AbiType in app components * docs: replace ParameterType with AbiType in examples and components --------- Co-authored-by: Jan-Felix <jfschwarz@users.noreply.github.com> Co-authored-by: Cristóvão <cristovaoth@users.noreply.github.com>
1 parent 030621c commit bde0467

File tree

84 files changed

+4214
-899
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+4214
-899
lines changed

packages/app/components/permissions/ConditionView/ConditionHeader.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Condition, Operator, ParameterType } from "zodiac-roles-sdk"
1+
import { AbiType, Condition, Operator } from "zodiac-roles-sdk"
22
import { AbiFunction, AbiParameter } from "viem"
33
import { ReactNode } from "react"
44
import { BsLightningCharge } from "react-icons/bs"
@@ -28,16 +28,15 @@ const ConditionHeader: React.FC<Props> = ({
2828
const paramName =
2929
paramIndex !== undefined ? abi?.name || `[${paramIndex}]` : "" // e.g.: array elements don't have a param name
3030

31-
const paramTypeLabel =
32-
!abi || "inputs" in abi ? ParameterType[paramType] : abi.type
31+
const paramTypeLabel = !abi || "inputs" in abi ? AbiType[paramType] : abi.type
3332

3433
const abiMismatch = abi && condition && !matchesAbi(condition, abi)
3534

3635
const operatorLabel = OperatorLabels[operator] || Operator[operator]
3736

3837
// only conditions that aren't used are collapsible
3938
const isCollapsible =
40-
paramType >= ParameterType.Tuple &&
39+
paramType >= AbiType.Tuple &&
4140
!(
4241
condition.operator >= Operator.Matches &&
4342
condition.operator <= Operator.ArraySubset
@@ -74,7 +73,7 @@ const ConditionHeader: React.FC<Props> = ({
7473
>
7574
{paramTypeLabel}
7675
<BsLightningCharge />
77-
{ParameterType[paramType]}
76+
{AbiType[paramType]}
7877
</Flex>
7978
) : (
8079
paramTypeLabel

packages/app/components/permissions/ConditionView/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Condition, Operator, ParameterType } from "zodiac-roles-sdk"
1+
import { AbiType, Condition, Operator } from "zodiac-roles-sdk"
22
import { Fragment, ReactNode } from "react"
33
import { AbiFunction, AbiParameter, decodeAbiParameters, toHex } from "viem"
44

@@ -21,7 +21,7 @@ export interface Props {
2121
}
2222

2323
const ConditionView: React.FC<Props> = ({ condition, paramIndex, abi }) => {
24-
if (condition.paramType === ParameterType.Calldata) {
24+
if (condition.paramType === AbiType.Calldata) {
2525
return (
2626
<CalldataConditionView
2727
condition={condition}
@@ -186,7 +186,7 @@ export const ChildConditions: React.FC<
186186
> = ({ condition, paramIndex, abi, separator }) => {
187187
const { children, operator } = condition
188188
const childrenLength = children?.length || 0
189-
const isCalldataCondition = condition.paramType === ParameterType.Calldata
189+
const isCalldataCondition = condition.paramType === AbiType.Calldata
190190
const isLogicalCondition =
191191
operator >= Operator.And && operator <= Operator.Nor
192192

packages/app/components/permissions/ConditionView/utils.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
import { arrayElementType, isStaticType } from "@/utils/abi"
22
import { AbiFunction, AbiParameter } from "viem"
3-
import { Condition, Operator, ParameterType } from "zodiac-roles-sdk"
3+
import { AbiType, Condition, Operator } from "zodiac-roles-sdk"
44

55
/** Validates if the given ABI fragments matches the condition node's paramType */
66
export const matchesAbi = (
77
condition: Condition,
88
abi: AbiFunction | AbiParameter
99
): boolean => {
1010
switch (condition.paramType) {
11-
case ParameterType.None:
11+
case AbiType.None:
1212
return true
13-
case ParameterType.Static:
13+
case AbiType.Static:
1414
return abi.type !== "function" && isStaticType(abi)
15-
case ParameterType.Dynamic:
15+
case AbiType.Dynamic:
1616
return abi.type === "function" || !isStaticType(abi)
17-
case ParameterType.Tuple:
17+
case AbiType.Tuple:
1818
return "components" in abi && !!abi.components && !arrayElementType(abi)
19-
case ParameterType.Array:
19+
case AbiType.Array:
2020
const elementType = arrayElementType(abi)
2121
return !!elementType
22-
case ParameterType.Calldata:
22+
case AbiType.Calldata:
2323
abi.type === "bytes" || abi.type === "function"
24-
case ParameterType.AbiEncoded:
24+
case AbiType.AbiEncoded:
2525
return abi.type === "bytes"
2626
}
2727
}

packages/app/components/permissions/schema.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import z from "zod"
33
import {
44
Condition,
55
Operator,
6-
ParameterType,
6+
AbiType,
77
Clearance,
88
ExecutionOptions,
99
} from "zodiac-roles-sdk"
@@ -26,7 +26,7 @@ export const zHex = z
2626
.transform((value) => value.toLowerCase() as `0x${string}`)
2727

2828
const zCondition = z.object({
29-
paramType: z.nativeEnum(ParameterType),
29+
paramType: z.nativeEnum(AbiType),
3030
operator: z.nativeEnum(Operator),
3131
compValue: zHex.optional(),
3232
children: z.lazy(() => z.array(zCondition)).optional(),

packages/deployments/src/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export enum Clearance {
1515
Function = 2,
1616
}
1717

18-
export enum ParameterType {
18+
export enum AbiType {
1919
None = 0,
2020
Static = 1,
2121
Dynamic = 2,
@@ -132,7 +132,7 @@ export interface Function {
132132
}
133133

134134
export interface Condition {
135-
paramType: ParameterType
135+
paramType: AbiType
136136
operator: Operator
137137
compValue?: `0x${string}`
138138
children?: readonly Condition[]

packages/docs/components/conditionsExamples/index.tsx

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"use client";
2-
import { Condition, Operator, ParameterType } from "zodiac-roles-sdk";
2+
import { AbiType, Condition, Operator } from "zodiac-roles-sdk";
33
import AbiTree from "@/components/tree/AbiTree";
44
import ConditionTree, { gatherNodeIds } from "@/components/tree/ConditionTree";
55
import clsx from "clsx";
@@ -144,93 +144,93 @@ const balancerSwapInputs = [
144144
];
145145

146146
const balancerSwapCondition: Condition = {
147-
paramType: ParameterType.Calldata,
147+
paramType: AbiType.Calldata,
148148
operator: Operator.Matches,
149149
children: [
150150
{
151-
paramType: ParameterType.Tuple,
151+
paramType: AbiType.Tuple,
152152
operator: Operator.Matches,
153153
children: [
154154
{
155155
// poolId
156-
paramType: ParameterType.Static,
156+
paramType: AbiType.Static,
157157
operator: Operator.EqualTo,
158158
compValue:
159159
"0x0b09dea16768f0799065c475be02919503cb2a3500020000000000000000001a",
160160
},
161161
{
162162
// kind
163-
paramType: ParameterType.Static,
163+
paramType: AbiType.Static,
164164
operator: Operator.Pass,
165165
},
166166
{
167167
// assetIn
168-
paramType: ParameterType.None,
168+
paramType: AbiType.None,
169169
operator: Operator.Or,
170170
children: [
171171
{
172-
paramType: ParameterType.Static,
172+
paramType: AbiType.Static,
173173
operator: Operator.EqualTo,
174174
compValue: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
175175
}, // WETH
176176
{
177-
paramType: ParameterType.Static,
177+
paramType: AbiType.Static,
178178
operator: Operator.EqualTo,
179179
compValue: "0x6b175474e89094c44da98b954eedeac495271d0f",
180180
}, // DAI
181181
],
182182
},
183183
{
184184
// assetOut
185-
paramType: ParameterType.None,
185+
paramType: AbiType.None,
186186
operator: Operator.Or,
187187
children: [
188188
{
189-
paramType: ParameterType.Static,
189+
paramType: AbiType.Static,
190190
operator: Operator.EqualTo,
191191
compValue: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
192192
}, // WETH
193193
{
194-
paramType: ParameterType.Static,
194+
paramType: AbiType.Static,
195195
operator: Operator.EqualTo,
196196
compValue: "0x6b175474e89094c44da98b954eedeac495271d0f",
197197
}, // DAI
198198
],
199199
},
200200
{
201201
// amount
202-
paramType: ParameterType.Static,
202+
paramType: AbiType.Static,
203203
operator: Operator.Pass,
204204
},
205205
{
206206
// userDatq
207-
paramType: ParameterType.Dynamic,
207+
paramType: AbiType.Dynamic,
208208
operator: Operator.Pass,
209209
},
210210
],
211211
},
212212
{
213-
paramType: ParameterType.Tuple,
213+
paramType: AbiType.Tuple,
214214
operator: Operator.Matches,
215215
children: [
216216
{
217217
// sender
218-
paramType: ParameterType.Static,
218+
paramType: AbiType.Static,
219219
operator: Operator.EqualToAvatar,
220220
},
221221
{
222222
// fromInternalBalance
223-
paramType: ParameterType.Static,
223+
paramType: AbiType.Static,
224224
operator: Operator.Pass,
225225
},
226226
{
227227
// recipient
228-
paramType: ParameterType.Static,
228+
paramType: AbiType.Static,
229229
operator: Operator.EqualToAvatar,
230230
},
231231
{
232232
// toInternalBalance
233-
paramType: ParameterType.Static,
233+
paramType: AbiType.Static,
234234
operator: Operator.Pass,
235235
},
236236
],

packages/docs/components/tree/ConditionTree/index.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from "react";
2-
import { Condition, Operator, ParameterType } from "zodiac-roles-sdk";
2+
import { AbiType, Condition, Operator } from "zodiac-roles-sdk";
33
import styles from "./styles.module.css";
44
import Tree, { TreeProps } from "../Tree";
55
import Node from "../Node/index";
@@ -16,7 +16,7 @@ const ConditionTree: React.FC<Props & TreeProps> = ({ condition, ...rest }) => {
1616
path = "0",
1717
abiPath = "0"
1818
) => {
19-
const isNotPlucking = condition.paramType === ParameterType.None;
19+
const isNotPlucking = condition.paramType === AbiType.None;
2020
return (
2121
<Node
2222
key={path}
@@ -47,7 +47,7 @@ const ConditionHead: React.FC<{ condition: Condition }> = ({ condition }) => (
4747
{hexEllipsis(condition.compValue)}
4848
</code>
4949
)}
50-
<code className={styles.type}>{ParameterType[condition.paramType]}</code>
50+
<code className={styles.type}>{AbiType[condition.paramType]}</code>
5151
</div>
5252
);
5353

@@ -56,7 +56,7 @@ export const gatherNodeIds = (
5656
path = "0",
5757
abiPath = "0"
5858
): string[] => {
59-
const isNotPlucking = condition.paramType === ParameterType.None;
59+
const isNotPlucking = condition.paramType === AbiType.None;
6060
return [
6161
abiPath,
6262
...(condition.children?.flatMap((child, index) =>

packages/docs/content/sdk/architecture.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ This layer has diffing & patching functions on role configurations, operating on
1616
{
1717
selector: "0x84e9bd7e",
1818
condition: {
19-
paramType: ParameterType.Calldata,
19+
paramType: AbiType.Calldata,
2020
operator: Operator.Matches,
2121
children: [
2222
{
23-
paramType: ParameterType.Static,
23+
paramType: AbiType.Static,
2424
operator: Operator.EqualTo,
2525
compValue: defaultAbiCoder.encode(["address"], ["0x4F2083f5fBede34C2714aFfb3105539775f7FE64"]),
2626
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// SPDX-License-Identifier: LGPL-3.0-only
2+
pragma solidity >=0.8.21 <0.9.0;
3+
4+
import "../periphery/EIP712Encoder.sol";
5+
6+
/**
7+
* @title MockEIP712Encoder - Test wrapper for EIP712Encoder
8+
* @dev Exposes internal EIP712Encoder functions for integration testing
9+
*/
10+
contract MockEIP712Encoder {
11+
function hashTypedMessage(
12+
bytes calldata domain,
13+
bytes calldata message,
14+
EIP712Encoder.Types calldata types
15+
) external pure returns (bytes32) {
16+
return EIP712Encoder.hashTypedMessage(domain, message, types);
17+
}
18+
19+
function hashTypedDomain(
20+
bytes calldata data,
21+
EIP712Encoder.Types calldata types
22+
) external pure returns (bytes32) {
23+
return EIP712Encoder.hashTypedDomain(data, types);
24+
}
25+
}

packages/evm/contracts/test/MultiSend.sol

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
// SPDX-License-Identifier: LGPL-3.0-only
22
pragma solidity >=0.8.17 <0.9.0;
33

4-
/// @title Multi Send - Allows to batch multiple transactions into one.
5-
/// @author Nick Dodson - <nick.dodson@consensys.net>
6-
/// @author Gonçalo Sá - <goncalo.sa@consensys.net>
7-
/// @author Stefan George - <stefan@gnosis.io>
8-
/// @author Richard Meissner - <richard@gnosis.io>
94
contract MultiSend {
105
address private immutable multisendSingleton;
116

0 commit comments

Comments
 (0)