Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EIP-6551 compat #27

Merged
merged 43 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
23c3a86
upgrade to latest account-abstraction contracts
jfschwarz Apr 26, 2023
f76da22
fix package json
jfschwarz May 10, 2023
4170293
adjust tests
jfschwarz May 10, 2023
4e7cf06
trial to fix vercel routes
jfschwarz May 10, 2023
217223d
fix deploy script for gnosis chain
jfschwarz May 11, 2023
6e53bb0
implement IERC6551Account
jfschwarz May 30, 2023
3d6d79d
restructure contract inheritance hierarchy
jfschwarz Jun 7, 2023
203d1d2
add mech factory
jfschwarz Jun 7, 2023
1f67b0c
refactor contracts
jfschwarz Jun 12, 2023
de98dec
add erc20 threshold mech
jfschwarz Jun 12, 2023
c749149
cleanup
jfschwarz Jun 12, 2023
e264243
update docs
jfschwarz Jun 12, 2023
06d0971
adjust all deploy functions and migrate them to viem
jfschwarz Jun 14, 2023
b608faa
add hierarchy graph
jfschwarz Jun 20, 2023
139d356
adding exports
jfschwarz Jul 13, 2023
f8436f9
Merge branch 'main' into erc-6551
jfschwarz Aug 18, 2023
52484d9
fixes after merge
jfschwarz Aug 18, 2023
cdab142
upgrade deps
jfschwarz Aug 18, 2023
98c79c1
6551 updates and prevent ownership cycles
jfschwarz Aug 21, 2023
eb19c39
fine-tune execution interface
jfschwarz Aug 21, 2023
81dbd52
upgrade tooling
jfschwarz Aug 21, 2023
00304e4
ethers v5 -> v6 migration
jfschwarz Aug 21, 2023
8d249e6
erc165
jfschwarz Aug 21, 2023
a5a32fe
tokenbound deterministic deployment test green
jfschwarz Aug 25, 2023
cd7e95d
update 4337 entrypoint address
jfschwarz Aug 25, 2023
4167db5
fix 4337 tests
jfschwarz Aug 25, 2023
f399e1d
fix missing onlyOperator annotation
jfschwarz Aug 25, 2023
ee82d3f
improve test coverage
jfschwarz Aug 25, 2023
c2f8e3c
test fixes
jfschwarz Aug 28, 2023
a39dc16
front-end updates
jfschwarz Aug 28, 2023
5186a9c
fix deploy scripts
jfschwarz Aug 28, 2023
9fe7e05
migrate from n.xyz to sequencer
jfschwarz Sep 1, 2023
9f371eb
Merge pull request #28 from gnosis/sequencer
jfschwarz Sep 1, 2023
c57769b
deploy 6551 factory
jfschwarz Sep 4, 2023
3198123
more solid deploy script
jfschwarz Sep 4, 2023
1381bd4
fix wallet connect
jfschwarz Sep 4, 2023
63edc04
fix a JS error when switching chains
jfschwarz Oct 12, 2023
7354c08
work around issue of tokenID not being set by sequence api
jfschwarz Oct 12, 2023
0c7cc8c
fix walletconnect v2 issues
jfschwarz Oct 12, 2023
3ca7ec0
fix a ux issue
jfschwarz Oct 12, 2023
bf94f2e
upgrade to latest 6551 contract and adjust accordingly
jfschwarz Oct 13, 2023
11e9b4d
fix tests
jfschwarz Oct 13, 2023
39ef6c7
update eip6551 registry address
jfschwarz Oct 13, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
tokenbound deterministic deployment test green
  • Loading branch information
jfschwarz committed Aug 25, 2023
commit a5a32feb96c84706b2c6137402e74b8dff435454
1 change: 1 addition & 0 deletions contracts/base/Mech.sol
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ abstract contract Mech is IMech, Account, Receiver {
bytes4 interfaceId
) public pure virtual returns (bool) {
return
interfaceId == type(IMech).interfaceId ||
interfaceId == type(IERC165).interfaceId ||
interfaceId == type(IAccount).interfaceId ||
interfaceId == type(IERC1271).interfaceId ||
Expand Down
8 changes: 2 additions & 6 deletions contracts/base/TokenboundMech.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
pragma solidity ^0.8.12;

import "@erc6551/reference/src/interfaces/IERC6551Account.sol";
import "@erc6551/reference/src/lib/ERC6551AccountLib.sol";

import "./Mech.sol";
import "../libraries/MinimalProxyStore.sol";

/**
* @dev A Mech that is operated by the holder of a designated token, implements the ERC6551 standard and is deployed through the ERC6551 registry
Expand All @@ -22,11 +22,7 @@ abstract contract TokenboundMech is Mech, IERC6551Account {
view
returns (uint256 chainId, address tokenContract, uint256 tokenId)
{
return
abi.decode(
MinimalProxyStore.getContext(address(this)),
(uint256, address, uint256)
);
return ERC6551AccountLib.token();
}

receive() external payable override(Receiver, IERC6551Account) {}
Expand Down
4 changes: 4 additions & 0 deletions contracts/test/ERC6551Registry.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
//SPDX-License-Identifier: LGPL-3.0
pragma solidity ^0.8.12;

import "@erc6551/reference/src/ERC6551Registry.sol";
63 changes: 62 additions & 1 deletion sdk/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,67 @@ export const DEFAULT_SALT =
export const SENTINEL_MODULES =
"0x0000000000000000000000000000000000000001" as const

export const ERC2470_SINGLETON_FACTORY_ABI = [
{
type: "function",
name: "deploy",
constant: false,
payable: false,
inputs: [
{
type: "bytes",
name: "_initCode",
},
{
type: "bytes32",
name: "_salt",
},
],
outputs: [
{
type: "address",
name: "createdContract",
},
],
},
]

export const ERC6551_REGISTRY_ABI = [
"createAccount(address implementation, uint256 chainId, address tokenContract, uint256 tokenId, uint256 salt, bytes initData) returns (address)",
{
type: "function",
name: "createAccount",
constant: false,
payable: false,
inputs: [
{
type: "address",
name: "implementation",
},
{
type: "uint256",
name: "chainId",
},
{
type: "address",
name: "tokenContract",
},
{
type: "uint256",
name: "tokenId",
},
{
type: "uint256",
name: "salt",
},
{
type: "bytes",
name: "initData",
},
],
outputs: [
{
type: "address",
},
],
},
]
6 changes: 3 additions & 3 deletions sdk/src/deploy/deployERC1155ThresholdMech.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const calculateERC1155ThresholdMechAddress = ({
minBalances: bigint[]
/** minimum total balance over all tokens */
minTotalBalance: bigint
salt: `0x${string}`
salt?: `0x${string}`
}) => {
const context = encodeAbiParameters(
[
Expand Down Expand Up @@ -77,7 +77,7 @@ export const makeERC1155ThresholdMechDeployTransaction = ({
minBalances: bigint[]
/** minimum total balance over all tokens */
minTotalBalance: bigint
salt: `0x${string}`
salt?: `0x${string}`
}) => {
const context = encodeAbiParameters(
[
Expand Down Expand Up @@ -121,7 +121,7 @@ export const deployERC1155ThresholdMech = async (
minBalances: bigint[]
/** minimum total balance over all tokens */
minTotalBalance: bigint
salt: `0x${string}`
salt?: `0x${string}`
}
) => {
const { chain, account } = walletClient
Expand Down
35 changes: 16 additions & 19 deletions sdk/src/deploy/deployERC1155TokenboundMech.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,25 @@ import {
ERC6551_REGISTRY_ADDRESS,
} from "../constants"

import { deployMastercopy, mechProxyBytecode } from "./factory"
import { deployMastercopy, erc6551ProxyBytecode } from "./factory"

export const calculateERC1155TokenboundMechAddress = ({
chainId,
token,
tokenId,
salt = DEFAULT_SALT,
}: {
export const calculateERC1155TokenboundMechAddress = (context: {
/** Address of the ERC1155 token contract */
chainId: number
/** Address of the ERC1155 token contract */
token: `0x${string}`
/** ID of the ERC1155 token */
tokenId: bigint
salt: `0x${string}`
salt?: `0x${string}`
from?: `0x${string}`
}) => {
const context = encodeAbiParameters(
[{ type: "uint256" }, { type: "address" }, { type: "uint256" }],
[BigInt(chainId), token, tokenId]
)

return getCreate2Address({
bytecode: mechProxyBytecode(
bytecode: erc6551ProxyBytecode(
calculateERC1155TokenboundMechMastercopyAddress(),
context
),
from: ERC6551_REGISTRY_ADDRESS,
salt,
from: context.from || ERC6551_REGISTRY_ADDRESS,
salt: context.salt || DEFAULT_SALT,
})
}

Expand All @@ -57,17 +48,19 @@ export const makeERC1155TokenboundMechDeployTransaction = ({
token,
tokenId,
salt = DEFAULT_SALT,
from = ERC6551_REGISTRY_ADDRESS,
}: {
/** ID of the chain the token lives on */
chainId: number
/** Address of the ERC1155 token contract */
token: `0x${string}`
/** ID of the ERC1155 token */
tokenId: bigint
salt: string
salt?: string
from?: `0x${string}`
}) => {
return {
to: ERC6551_REGISTRY_ADDRESS,
to: from,
data: encodeFunctionData({
abi: ERC6551_REGISTRY_ABI,
functionName: "createAccount",
Expand All @@ -77,6 +70,7 @@ export const makeERC1155TokenboundMechDeployTransaction = ({
token,
tokenId,
salt,
"0x",
],
}),
}
Expand All @@ -89,14 +83,16 @@ export const deployERC1155TokenboundMech = async (
token,
tokenId,
salt = DEFAULT_SALT,
from = ERC6551_REGISTRY_ADDRESS,
}: {
/** ID of the chain the token lives on, default to the current chain of walletClient */
chainId?: number
/** Address of the ERC1155 token contract */
token: `0x${string}`
/** ID of the ERC1155 token */
tokenId: bigint
salt: `0x${string}`
salt?: `0x${string}`
from?: `0x${string}`
}
) => {
const { chain, account } = walletClient
Expand All @@ -110,6 +106,7 @@ export const deployERC1155TokenboundMech = async (
token,
tokenId,
salt,
from,
})

return walletClient.sendTransaction({
Expand Down
35 changes: 16 additions & 19 deletions sdk/src/deploy/deployERC721TokenboundMech.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,25 @@ import {
ERC6551_REGISTRY_ADDRESS,
} from "../constants"

import { deployMastercopy, mechProxyBytecode } from "./factory"
import { deployMastercopy, erc6551ProxyBytecode } from "./factory"

export const calculateERC721TokenboundMechAddress = ({
chainId,
token,
tokenId,
salt = DEFAULT_SALT,
}: {
export const calculateERC721TokenboundMechAddress = (context: {
/** Address of the ERC721 token contract */
chainId: number
/** Address of the ERC721 token contract */
token: `0x${string}`
/** ID of the ERC721 token */
tokenId: bigint
salt: `0x${string}`
salt?: `0x${string}`
from?: `0x${string}`
}) => {
const context = encodeAbiParameters(
[{ type: "uint256" }, { type: "address" }, { type: "uint256" }],
[BigInt(chainId), token, tokenId]
)

return getCreate2Address({
bytecode: mechProxyBytecode(
bytecode: erc6551ProxyBytecode(
calculateERC721TokenboundMechMastercopyAddress(),
context
),
from: ERC6551_REGISTRY_ADDRESS,
salt,
from: context.from || ERC6551_REGISTRY_ADDRESS,
salt: context.salt || DEFAULT_SALT,
})
}

Expand All @@ -57,17 +48,19 @@ export const makeERC721TokenboundMechDeployTransaction = ({
token,
tokenId,
salt = DEFAULT_SALT,
from = ERC6551_REGISTRY_ADDRESS,
}: {
/** ID of the chain the token lives on */
chainId: number
/** Address of the ERC721 token contract */
token: `0x${string}`
/** ID of the ERC721 token */
tokenId: bigint
salt: string
salt?: string
from?: `0x${string}`
}) => {
return {
to: ERC6551_REGISTRY_ADDRESS,
to: from,
data: encodeFunctionData({
abi: ERC6551_REGISTRY_ABI,
functionName: "createAccount",
Expand All @@ -77,6 +70,7 @@ export const makeERC721TokenboundMechDeployTransaction = ({
token,
tokenId,
salt,
"0x",
],
}),
}
Expand All @@ -89,14 +83,16 @@ export const deployERC721TokenboundMech = async (
token,
tokenId,
salt = DEFAULT_SALT,
from = ERC6551_REGISTRY_ADDRESS,
}: {
/** ID of the chain the token lives on, default to the current chain of walletClient */
chainId?: number
/** Address of the ERC721 token contract */
token: `0x${string}`
/** ID of the ERC721 token */
tokenId: bigint
salt: `0x${string}`
salt?: `0x${string}`
from?: `0x${string}`
}
) => {
const { chain, account } = walletClient
Expand All @@ -110,6 +106,7 @@ export const deployERC721TokenboundMech = async (
token,
tokenId,
salt,
from,
})

return walletClient.sendTransaction({
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/deploy/deployZodiacMech.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const makeZodiacMechDeployTransaction = ({
}: {
/** Addresses of the Zodiac modules */
modules: `0x${string}`[]
salt: `0x${string}`
salt?: `0x${string}`
}) => {
const initCall = encodeFunctionData({
abi: ZodiacMech__factory.abi,
Expand Down
Loading