@ensuro/account-abstraction 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/build-info.json +236 -1
- package/build/contracts/AccessControlAccount.sol/AccessControlAccount.json +85 -5
- package/build/contracts/AccessControlAccount.sol/artifacts.d.ts +27 -0
- package/build/contracts/AccessManagerAccount.sol/AccessManagerAccount.json +81 -5
- package/build/contracts/AccessManagerAccount.sol/artifacts.d.ts +27 -0
- package/build/contracts/ERC2771ForwarderAccount.sol/ERC2771ForwarderAccount.json +239 -204
- package/build/contracts/ERC2771ForwarderAccount.sol/artifacts.d.ts +27 -0
- package/build/contracts/dependencies/AccessManager.sol/AccessManager.json +8 -5
- package/build/contracts/dependencies/AccessManager.sol/artifacts.d.ts +27 -0
- package/build/contracts/dependencies/FrozenTime.sol/FrozenTime.json +8 -5
- package/build/contracts/dependencies/FrozenTime.sol/artifacts.d.ts +27 -0
- package/build/contracts/mock/ERC20With2771.sol/ERC20With2771.json +29 -5
- package/build/contracts/mock/ERC20With2771.sol/artifacts.d.ts +27 -0
- package/contracts/AccessControlAccount.sol +1 -1
- package/contracts/AccessManagerAccount.sol +1 -1
- package/contracts/ERC2771ForwarderAccount.sol +117 -88
- package/js/userOp.js +17 -36
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"_format": "
|
|
2
|
+
"_format": "hh3-artifact-1",
|
|
3
3
|
"contractName": "ERC20With2771",
|
|
4
4
|
"sourceName": "contracts/mock/ERC20With2771.sol",
|
|
5
5
|
"abi": [
|
|
@@ -375,8 +375,32 @@
|
|
|
375
375
|
"type": "function"
|
|
376
376
|
}
|
|
377
377
|
],
|
|
378
|
-
"bytecode": "
|
|
379
|
-
"deployedBytecode": "
|
|
378
|
+
"bytecode": "0x60c060405234801561000f575f5ffd5b50604051610d48380380610d4883398101604081905261002e91610274565b808585600361003d838261039d565b50600461004a828261039d565b5050506001600160a01b031660805260ff821660a05261006a3384610074565b505050505061047c565b6001600160a01b0382166100a25760405163ec442f0560e01b81525f60048201526024015b60405180910390fd5b6100ad5f83836100b1565b5050565b6001600160a01b0383166100db578060025f8282546100d09190610457565b9091555061014b9050565b6001600160a01b0383165f908152602081905260409020548181101561012d5760405163391434e360e21b81526001600160a01b03851660048201526024810182905260448101839052606401610099565b6001600160a01b0384165f9081526020819052604090209082900390555b6001600160a01b03821661016757600280548290039055610185565b6001600160a01b0382165f9081526020819052604090208054820190555b816001600160a01b0316836001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040516101ca91815260200190565b60405180910390a3505050565b634e487b7160e01b5f52604160045260245ffd5b5f82601f8301126101fa575f5ffd5b81516001600160401b03811115610213576102136101d7565b604051601f8201601f19908116603f011681016001600160401b0381118282101715610241576102416101d7565b604052818152838201602001851015610258575f5ffd5b8160208501602083015e5f918101602001919091529392505050565b5f5f5f5f5f60a08688031215610288575f5ffd5b85516001600160401b0381111561029d575f5ffd5b6102a9888289016101eb565b602088015190965090506001600160401b038111156102c6575f5ffd5b6102d2888289016101eb565b94505060408601519250606086015160ff811681146102ef575f5ffd5b60808701519092506001600160a01b038116811461030b575f5ffd5b809150509295509295909350565b600181811c9082168061032d57607f821691505b60208210810361034b57634e487b7160e01b5f52602260045260245ffd5b50919050565b601f82111561039857805f5260205f20601f840160051c810160208510156103765750805b601f840160051c820191505b81811015610395575f8155600101610382565b50505b505050565b81516001600160401b038111156103b6576103b66101d7565b6103ca816103c48454610319565b84610351565b6020601f8211600181146103fc575f83156103e55750848201515b5f19600385901b1c1916600184901b178455610395565b5f84815260208120601f198516915b8281101561042b578785015182556020948501946001909201910161040b565b508482101561044857868401515f19600387901b60f8161c191681555b50505050600190811b01905550565b8082018082111561047657634e487b7160e01b5f52601160045260245ffd5b92915050565b60805160a05161089d6104ab5f395f61011701525f8181610151015281816101b60152610448015261089d5ff3fe608060405234801561000f575f5ffd5b50600436106100a6575f3560e01c8063572b6c051161006e578063572b6c051461014157806370a08231146101815780637da0a877146101a957806395d89b41146101e0578063a9059cbb146101e8578063dd62ed3e146101fb575f5ffd5b806306fdde03146100aa578063095ea7b3146100c857806318160ddd146100eb57806323b872dd146100fd578063313ce56714610110575b5f5ffd5b6100b2610233565b6040516100bf9190610699565b60405180910390f35b6100db6100d63660046106e9565b6102c3565b60405190151581526020016100bf565b6002545b6040519081526020016100bf565b6100db61010b366004610711565b6102e6565b60405160ff7f00000000000000000000000000000000000000000000000000000000000000001681526020016100bf565b6100db61014f36600461074b565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0390811691161490565b6100ef61018f36600461074b565b6001600160a01b03165f9081526020819052604090205490565b6040516001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001681526020016100bf565b6100b2610313565b6100db6101f63660046106e9565b610322565b6100ef61020936600461076b565b6001600160a01b039182165f90815260016020908152604080832093909416825291909152205490565b6060600380546102429061079c565b80601f016020809104026020016040519081016040528092919081815260200182805461026e9061079c565b80156102b95780601f10610290576101008083540402835291602001916102b9565b820191905f5260205f20905b81548152906001019060200180831161029c57829003601f168201915b5050505050905090565b5f5f6102cd610339565b90506102da818585610347565b60019150505b92915050565b5f5f6102f0610339565b90506102fd858285610359565b6103088585856103da565b506001949350505050565b6060600480546102429061079c565b5f5f61032c610339565b90506102da8185856103da565b5f610342610437565b905090565b61035483838360016104a1565b505050565b6001600160a01b038381165f908152600160209081526040808320938616835292905220545f198110156103d457818110156103c657604051637dc7a0d960e11b81526001600160a01b038416600482015260248101829052604481018390526064015b60405180910390fd5b6103d484848484035f6104a1565b50505050565b6001600160a01b03831661040357604051634b637e8f60e11b81525f60048201526024016103bd565b6001600160a01b03821661042c5760405163ec442f0560e01b81525f60048201526024016103bd565b610354838383610573565b5f36601480821080159061047357507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031633145b156104995761048636828403815f6107d4565b61048f916107fb565b60601c9250505090565b339250505090565b6001600160a01b0384166104ca5760405163e602df0560e01b81525f60048201526024016103bd565b6001600160a01b0383166104f357604051634a1406b160e11b81525f60048201526024016103bd565b6001600160a01b038085165f90815260016020908152604080832093871683529290522082905580156103d457826001600160a01b0316846001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9258460405161056591815260200190565b60405180910390a350505050565b6001600160a01b03831661059d578060025f8282546105929190610848565b9091555061060d9050565b6001600160a01b0383165f90815260208190526040902054818110156105ef5760405163391434e360e21b81526001600160a01b038516600482015260248101829052604481018390526064016103bd565b6001600160a01b0384165f9081526020819052604090209082900390555b6001600160a01b03821661062957600280548290039055610647565b6001600160a01b0382165f9081526020819052604090208054820190555b816001600160a01b0316836001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8360405161068c91815260200190565b60405180910390a3505050565b602081525f82518060208401528060208501604085015e5f604082850101526040601f19601f83011684010191505092915050565b80356001600160a01b03811681146106e4575f5ffd5b919050565b5f5f604083850312156106fa575f5ffd5b610703836106ce565b946020939093013593505050565b5f5f5f60608486031215610723575f5ffd5b61072c846106ce565b925061073a602085016106ce565b929592945050506040919091013590565b5f6020828403121561075b575f5ffd5b610764826106ce565b9392505050565b5f5f6040838503121561077c575f5ffd5b610785836106ce565b9150610793602084016106ce565b90509250929050565b600181811c908216806107b057607f821691505b6020821081036107ce57634e487b7160e01b5f52602260045260245ffd5b50919050565b5f5f858511156107e2575f5ffd5b838611156107ee575f5ffd5b5050820193919092039150565b80356bffffffffffffffffffffffff198116906014841015610841576bffffffffffffffffffffffff196bffffffffffffffffffffffff198560140360031b1b82161691505b5092915050565b808201808211156102e057634e487b7160e01b5f52601160045260245ffdfea26469706673582212209052ca3b7d16208877574fb8688288b972afaa142be43385402a72663c099d9564736f6c634300081e0033",
|
|
379
|
+
"deployedBytecode": "0x608060405234801561000f575f5ffd5b50600436106100a6575f3560e01c8063572b6c051161006e578063572b6c051461014157806370a08231146101815780637da0a877146101a957806395d89b41146101e0578063a9059cbb146101e8578063dd62ed3e146101fb575f5ffd5b806306fdde03146100aa578063095ea7b3146100c857806318160ddd146100eb57806323b872dd146100fd578063313ce56714610110575b5f5ffd5b6100b2610233565b6040516100bf9190610699565b60405180910390f35b6100db6100d63660046106e9565b6102c3565b60405190151581526020016100bf565b6002545b6040519081526020016100bf565b6100db61010b366004610711565b6102e6565b60405160ff7f00000000000000000000000000000000000000000000000000000000000000001681526020016100bf565b6100db61014f36600461074b565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0390811691161490565b6100ef61018f36600461074b565b6001600160a01b03165f9081526020819052604090205490565b6040516001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001681526020016100bf565b6100b2610313565b6100db6101f63660046106e9565b610322565b6100ef61020936600461076b565b6001600160a01b039182165f90815260016020908152604080832093909416825291909152205490565b6060600380546102429061079c565b80601f016020809104026020016040519081016040528092919081815260200182805461026e9061079c565b80156102b95780601f10610290576101008083540402835291602001916102b9565b820191905f5260205f20905b81548152906001019060200180831161029c57829003601f168201915b5050505050905090565b5f5f6102cd610339565b90506102da818585610347565b60019150505b92915050565b5f5f6102f0610339565b90506102fd858285610359565b6103088585856103da565b506001949350505050565b6060600480546102429061079c565b5f5f61032c610339565b90506102da8185856103da565b5f610342610437565b905090565b61035483838360016104a1565b505050565b6001600160a01b038381165f908152600160209081526040808320938616835292905220545f198110156103d457818110156103c657604051637dc7a0d960e11b81526001600160a01b038416600482015260248101829052604481018390526064015b60405180910390fd5b6103d484848484035f6104a1565b50505050565b6001600160a01b03831661040357604051634b637e8f60e11b81525f60048201526024016103bd565b6001600160a01b03821661042c5760405163ec442f0560e01b81525f60048201526024016103bd565b610354838383610573565b5f36601480821080159061047357507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031633145b156104995761048636828403815f6107d4565b61048f916107fb565b60601c9250505090565b339250505090565b6001600160a01b0384166104ca5760405163e602df0560e01b81525f60048201526024016103bd565b6001600160a01b0383166104f357604051634a1406b160e11b81525f60048201526024016103bd565b6001600160a01b038085165f90815260016020908152604080832093871683529290522082905580156103d457826001600160a01b0316846001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9258460405161056591815260200190565b60405180910390a350505050565b6001600160a01b03831661059d578060025f8282546105929190610848565b9091555061060d9050565b6001600160a01b0383165f90815260208190526040902054818110156105ef5760405163391434e360e21b81526001600160a01b038516600482015260248101829052604481018390526064016103bd565b6001600160a01b0384165f9081526020819052604090209082900390555b6001600160a01b03821661062957600280548290039055610647565b6001600160a01b0382165f9081526020819052604090208054820190555b816001600160a01b0316836001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8360405161068c91815260200190565b60405180910390a3505050565b602081525f82518060208401528060208501604085015e5f604082850101526040601f19601f83011684010191505092915050565b80356001600160a01b03811681146106e4575f5ffd5b919050565b5f5f604083850312156106fa575f5ffd5b610703836106ce565b946020939093013593505050565b5f5f5f60608486031215610723575f5ffd5b61072c846106ce565b925061073a602085016106ce565b929592945050506040919091013590565b5f6020828403121561075b575f5ffd5b610764826106ce565b9392505050565b5f5f6040838503121561077c575f5ffd5b610785836106ce565b9150610793602084016106ce565b90509250929050565b600181811c908216806107b057607f821691505b6020821081036107ce57634e487b7160e01b5f52602260045260245ffd5b50919050565b5f5f858511156107e2575f5ffd5b838611156107ee575f5ffd5b5050820193919092039150565b80356bffffffffffffffffffffffff198116906014841015610841576bffffffffffffffffffffffff196bffffffffffffffffffffffff198560140360031b1b82161691505b5092915050565b808201808211156102e057634e487b7160e01b5f52601160045260245ffdfea26469706673582212209052ca3b7d16208877574fb8688288b972afaa142be43385402a72663c099d9564736f6c634300081e0033",
|
|
380
380
|
"linkReferences": {},
|
|
381
|
-
"deployedLinkReferences": {}
|
|
382
|
-
|
|
381
|
+
"deployedLinkReferences": {},
|
|
382
|
+
"immutableReferences": {
|
|
383
|
+
"2301": [
|
|
384
|
+
{
|
|
385
|
+
"length": 32,
|
|
386
|
+
"start": 337
|
|
387
|
+
},
|
|
388
|
+
{
|
|
389
|
+
"length": 32,
|
|
390
|
+
"start": 438
|
|
391
|
+
},
|
|
392
|
+
{
|
|
393
|
+
"length": 32,
|
|
394
|
+
"start": 1096
|
|
395
|
+
}
|
|
396
|
+
],
|
|
397
|
+
"14972": [
|
|
398
|
+
{
|
|
399
|
+
"length": 32,
|
|
400
|
+
"start": 279
|
|
401
|
+
}
|
|
402
|
+
]
|
|
403
|
+
},
|
|
404
|
+
"inputSourceName": "project/contracts/mock/ERC20With2771.sol",
|
|
405
|
+
"buildInfoId": "solc-0_8_30-3f701667cdad33af53ac1f684f455bb9e01a58ac"
|
|
406
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// This file was autogenerated by Hardhat, do not edit it.
|
|
2
|
+
// prettier-ignore
|
|
3
|
+
// tslint:disable
|
|
4
|
+
// eslint-disable
|
|
5
|
+
// biome-ignore format: see above
|
|
6
|
+
|
|
7
|
+
export interface ERC20With2771$Type {
|
|
8
|
+
readonly _format: "hh3-artifact-1";
|
|
9
|
+
readonly contractName: "ERC20With2771";
|
|
10
|
+
readonly sourceName: "contracts/mock/ERC20With2771.sol";
|
|
11
|
+
readonly abi: [{"inputs":[{"internalType":"string","name":"name_","type":"string"},{"internalType":"string","name":"symbol_","type":"string"},{"internalType":"uint256","name":"initialSupply","type":"uint256"},{"internalType":"uint8","name":"decimals_","type":"uint8"},{"internalType":"address","name":"trustedForwarder","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"allowance","type":"uint256"},{"internalType":"uint256","name":"needed","type":"uint256"}],"name":"ERC20InsufficientAllowance","type":"error"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"uint256","name":"balance","type":"uint256"},{"internalType":"uint256","name":"needed","type":"uint256"}],"name":"ERC20InsufficientBalance","type":"error"},{"inputs":[{"internalType":"address","name":"approver","type":"address"}],"name":"ERC20InvalidApprover","type":"error"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"}],"name":"ERC20InvalidReceiver","type":"error"},{"inputs":[{"internalType":"address","name":"sender","type":"address"}],"name":"ERC20InvalidSender","type":"error"},{"inputs":[{"internalType":"address","name":"spender","type":"address"}],"name":"ERC20InvalidSpender","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"forwarder","type":"address"}],"name":"isTrustedForwarder","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"trustedForwarder","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"}];
|
|
12
|
+
readonly bytecode: "0x60c060405234801561000f575f5ffd5b50604051610d48380380610d4883398101604081905261002e91610274565b808585600361003d838261039d565b50600461004a828261039d565b5050506001600160a01b031660805260ff821660a05261006a3384610074565b505050505061047c565b6001600160a01b0382166100a25760405163ec442f0560e01b81525f60048201526024015b60405180910390fd5b6100ad5f83836100b1565b5050565b6001600160a01b0383166100db578060025f8282546100d09190610457565b9091555061014b9050565b6001600160a01b0383165f908152602081905260409020548181101561012d5760405163391434e360e21b81526001600160a01b03851660048201526024810182905260448101839052606401610099565b6001600160a01b0384165f9081526020819052604090209082900390555b6001600160a01b03821661016757600280548290039055610185565b6001600160a01b0382165f9081526020819052604090208054820190555b816001600160a01b0316836001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040516101ca91815260200190565b60405180910390a3505050565b634e487b7160e01b5f52604160045260245ffd5b5f82601f8301126101fa575f5ffd5b81516001600160401b03811115610213576102136101d7565b604051601f8201601f19908116603f011681016001600160401b0381118282101715610241576102416101d7565b604052818152838201602001851015610258575f5ffd5b8160208501602083015e5f918101602001919091529392505050565b5f5f5f5f5f60a08688031215610288575f5ffd5b85516001600160401b0381111561029d575f5ffd5b6102a9888289016101eb565b602088015190965090506001600160401b038111156102c6575f5ffd5b6102d2888289016101eb565b94505060408601519250606086015160ff811681146102ef575f5ffd5b60808701519092506001600160a01b038116811461030b575f5ffd5b809150509295509295909350565b600181811c9082168061032d57607f821691505b60208210810361034b57634e487b7160e01b5f52602260045260245ffd5b50919050565b601f82111561039857805f5260205f20601f840160051c810160208510156103765750805b601f840160051c820191505b81811015610395575f8155600101610382565b50505b505050565b81516001600160401b038111156103b6576103b66101d7565b6103ca816103c48454610319565b84610351565b6020601f8211600181146103fc575f83156103e55750848201515b5f19600385901b1c1916600184901b178455610395565b5f84815260208120601f198516915b8281101561042b578785015182556020948501946001909201910161040b565b508482101561044857868401515f19600387901b60f8161c191681555b50505050600190811b01905550565b8082018082111561047657634e487b7160e01b5f52601160045260245ffd5b92915050565b60805160a05161089d6104ab5f395f61011701525f8181610151015281816101b60152610448015261089d5ff3fe608060405234801561000f575f5ffd5b50600436106100a6575f3560e01c8063572b6c051161006e578063572b6c051461014157806370a08231146101815780637da0a877146101a957806395d89b41146101e0578063a9059cbb146101e8578063dd62ed3e146101fb575f5ffd5b806306fdde03146100aa578063095ea7b3146100c857806318160ddd146100eb57806323b872dd146100fd578063313ce56714610110575b5f5ffd5b6100b2610233565b6040516100bf9190610699565b60405180910390f35b6100db6100d63660046106e9565b6102c3565b60405190151581526020016100bf565b6002545b6040519081526020016100bf565b6100db61010b366004610711565b6102e6565b60405160ff7f00000000000000000000000000000000000000000000000000000000000000001681526020016100bf565b6100db61014f36600461074b565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0390811691161490565b6100ef61018f36600461074b565b6001600160a01b03165f9081526020819052604090205490565b6040516001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001681526020016100bf565b6100b2610313565b6100db6101f63660046106e9565b610322565b6100ef61020936600461076b565b6001600160a01b039182165f90815260016020908152604080832093909416825291909152205490565b6060600380546102429061079c565b80601f016020809104026020016040519081016040528092919081815260200182805461026e9061079c565b80156102b95780601f10610290576101008083540402835291602001916102b9565b820191905f5260205f20905b81548152906001019060200180831161029c57829003601f168201915b5050505050905090565b5f5f6102cd610339565b90506102da818585610347565b60019150505b92915050565b5f5f6102f0610339565b90506102fd858285610359565b6103088585856103da565b506001949350505050565b6060600480546102429061079c565b5f5f61032c610339565b90506102da8185856103da565b5f610342610437565b905090565b61035483838360016104a1565b505050565b6001600160a01b038381165f908152600160209081526040808320938616835292905220545f198110156103d457818110156103c657604051637dc7a0d960e11b81526001600160a01b038416600482015260248101829052604481018390526064015b60405180910390fd5b6103d484848484035f6104a1565b50505050565b6001600160a01b03831661040357604051634b637e8f60e11b81525f60048201526024016103bd565b6001600160a01b03821661042c5760405163ec442f0560e01b81525f60048201526024016103bd565b610354838383610573565b5f36601480821080159061047357507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031633145b156104995761048636828403815f6107d4565b61048f916107fb565b60601c9250505090565b339250505090565b6001600160a01b0384166104ca5760405163e602df0560e01b81525f60048201526024016103bd565b6001600160a01b0383166104f357604051634a1406b160e11b81525f60048201526024016103bd565b6001600160a01b038085165f90815260016020908152604080832093871683529290522082905580156103d457826001600160a01b0316846001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9258460405161056591815260200190565b60405180910390a350505050565b6001600160a01b03831661059d578060025f8282546105929190610848565b9091555061060d9050565b6001600160a01b0383165f90815260208190526040902054818110156105ef5760405163391434e360e21b81526001600160a01b038516600482015260248101829052604481018390526064016103bd565b6001600160a01b0384165f9081526020819052604090209082900390555b6001600160a01b03821661062957600280548290039055610647565b6001600160a01b0382165f9081526020819052604090208054820190555b816001600160a01b0316836001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8360405161068c91815260200190565b60405180910390a3505050565b602081525f82518060208401528060208501604085015e5f604082850101526040601f19601f83011684010191505092915050565b80356001600160a01b03811681146106e4575f5ffd5b919050565b5f5f604083850312156106fa575f5ffd5b610703836106ce565b946020939093013593505050565b5f5f5f60608486031215610723575f5ffd5b61072c846106ce565b925061073a602085016106ce565b929592945050506040919091013590565b5f6020828403121561075b575f5ffd5b610764826106ce565b9392505050565b5f5f6040838503121561077c575f5ffd5b610785836106ce565b9150610793602084016106ce565b90509250929050565b600181811c908216806107b057607f821691505b6020821081036107ce57634e487b7160e01b5f52602260045260245ffd5b50919050565b5f5f858511156107e2575f5ffd5b838611156107ee575f5ffd5b5050820193919092039150565b80356bffffffffffffffffffffffff198116906014841015610841576bffffffffffffffffffffffff196bffffffffffffffffffffffff198560140360031b1b82161691505b5092915050565b808201808211156102e057634e487b7160e01b5f52601160045260245ffdfea26469706673582212209052ca3b7d16208877574fb8688288b972afaa142be43385402a72663c099d9564736f6c634300081e0033";
|
|
13
|
+
readonly deployedBytecode: "0x608060405234801561000f575f5ffd5b50600436106100a6575f3560e01c8063572b6c051161006e578063572b6c051461014157806370a08231146101815780637da0a877146101a957806395d89b41146101e0578063a9059cbb146101e8578063dd62ed3e146101fb575f5ffd5b806306fdde03146100aa578063095ea7b3146100c857806318160ddd146100eb57806323b872dd146100fd578063313ce56714610110575b5f5ffd5b6100b2610233565b6040516100bf9190610699565b60405180910390f35b6100db6100d63660046106e9565b6102c3565b60405190151581526020016100bf565b6002545b6040519081526020016100bf565b6100db61010b366004610711565b6102e6565b60405160ff7f00000000000000000000000000000000000000000000000000000000000000001681526020016100bf565b6100db61014f36600461074b565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0390811691161490565b6100ef61018f36600461074b565b6001600160a01b03165f9081526020819052604090205490565b6040516001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001681526020016100bf565b6100b2610313565b6100db6101f63660046106e9565b610322565b6100ef61020936600461076b565b6001600160a01b039182165f90815260016020908152604080832093909416825291909152205490565b6060600380546102429061079c565b80601f016020809104026020016040519081016040528092919081815260200182805461026e9061079c565b80156102b95780601f10610290576101008083540402835291602001916102b9565b820191905f5260205f20905b81548152906001019060200180831161029c57829003601f168201915b5050505050905090565b5f5f6102cd610339565b90506102da818585610347565b60019150505b92915050565b5f5f6102f0610339565b90506102fd858285610359565b6103088585856103da565b506001949350505050565b6060600480546102429061079c565b5f5f61032c610339565b90506102da8185856103da565b5f610342610437565b905090565b61035483838360016104a1565b505050565b6001600160a01b038381165f908152600160209081526040808320938616835292905220545f198110156103d457818110156103c657604051637dc7a0d960e11b81526001600160a01b038416600482015260248101829052604481018390526064015b60405180910390fd5b6103d484848484035f6104a1565b50505050565b6001600160a01b03831661040357604051634b637e8f60e11b81525f60048201526024016103bd565b6001600160a01b03821661042c5760405163ec442f0560e01b81525f60048201526024016103bd565b610354838383610573565b5f36601480821080159061047357507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031633145b156104995761048636828403815f6107d4565b61048f916107fb565b60601c9250505090565b339250505090565b6001600160a01b0384166104ca5760405163e602df0560e01b81525f60048201526024016103bd565b6001600160a01b0383166104f357604051634a1406b160e11b81525f60048201526024016103bd565b6001600160a01b038085165f90815260016020908152604080832093871683529290522082905580156103d457826001600160a01b0316846001600160a01b03167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9258460405161056591815260200190565b60405180910390a350505050565b6001600160a01b03831661059d578060025f8282546105929190610848565b9091555061060d9050565b6001600160a01b0383165f90815260208190526040902054818110156105ef5760405163391434e360e21b81526001600160a01b038516600482015260248101829052604481018390526064016103bd565b6001600160a01b0384165f9081526020819052604090209082900390555b6001600160a01b03821661062957600280548290039055610647565b6001600160a01b0382165f9081526020819052604090208054820190555b816001600160a01b0316836001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8360405161068c91815260200190565b60405180910390a3505050565b602081525f82518060208401528060208501604085015e5f604082850101526040601f19601f83011684010191505092915050565b80356001600160a01b03811681146106e4575f5ffd5b919050565b5f5f604083850312156106fa575f5ffd5b610703836106ce565b946020939093013593505050565b5f5f5f60608486031215610723575f5ffd5b61072c846106ce565b925061073a602085016106ce565b929592945050506040919091013590565b5f6020828403121561075b575f5ffd5b610764826106ce565b9392505050565b5f5f6040838503121561077c575f5ffd5b610785836106ce565b9150610793602084016106ce565b90509250929050565b600181811c908216806107b057607f821691505b6020821081036107ce57634e487b7160e01b5f52602260045260245ffd5b50919050565b5f5f858511156107e2575f5ffd5b838611156107ee575f5ffd5b5050820193919092039150565b80356bffffffffffffffffffffffff198116906014841015610841576bffffffffffffffffffffffff196bffffffffffffffffffffffff198560140360031b1b82161691505b5092915050565b808201808211156102e057634e487b7160e01b5f52601160045260245ffdfea26469706673582212209052ca3b7d16208877574fb8688288b972afaa142be43385402a72663c099d9564736f6c634300081e0033";
|
|
14
|
+
readonly linkReferences: {};
|
|
15
|
+
readonly deployedLinkReferences: {};
|
|
16
|
+
readonly immutableReferences: {"2301":[{"length":32,"start":337},{"length":32,"start":438},{"length":32,"start":1096}],"14972":[{"length":32,"start":279}]};
|
|
17
|
+
readonly inputSourceName: "project/contracts/mock/ERC20With2771.sol";
|
|
18
|
+
readonly buildInfoId: "solc-0_8_30-3f701667cdad33af53ac1f684f455bb9e01a58ac";
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
import "hardhat/types/artifacts";
|
|
22
|
+
declare module "hardhat/types/artifacts" {
|
|
23
|
+
interface ArtifactMap {
|
|
24
|
+
["ERC20With2771"]: ERC20With2771$Type;
|
|
25
|
+
["contracts/mock/ERC20With2771.sol:ERC20With2771"]: ERC20With2771$Type;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -47,7 +47,7 @@ contract AccessControlAccount is AccessControl, BaseAccount {
|
|
|
47
47
|
* @param value the value to pass in this call
|
|
48
48
|
* @param func the calldata to pass in this call
|
|
49
49
|
*/
|
|
50
|
-
function execute(address dest, uint256 value, bytes calldata func) external {
|
|
50
|
+
function execute(address dest, uint256 value, bytes calldata func) external override {
|
|
51
51
|
_requireFromEntryPointOrExecutor();
|
|
52
52
|
Address.functionCallWithValue(dest, func, value);
|
|
53
53
|
}
|
|
@@ -40,7 +40,7 @@ contract AccessManagerAccount is AccessManager, BaseAccount {
|
|
|
40
40
|
* @param value the value to pass in this call
|
|
41
41
|
* @param func the calldata to pass in this call
|
|
42
42
|
*/
|
|
43
|
-
function execute(address dest, uint256 value, bytes calldata func) external {
|
|
43
|
+
function execute(address dest, uint256 value, bytes calldata func) external override {
|
|
44
44
|
_requireFromEntryPoint();
|
|
45
45
|
Address.functionCallWithValue(dest, func, value);
|
|
46
46
|
}
|
|
@@ -1,98 +1,131 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
2
|
pragma solidity ^0.8.23;
|
|
3
3
|
|
|
4
|
-
import {AccessControl} from "@openzeppelin/contracts/access/AccessControl.sol";
|
|
5
4
|
import {Address} from "@openzeppelin/contracts/utils/Address.sol";
|
|
6
|
-
import {ERC2771Context} from "@openzeppelin/contracts/metatx/ERC2771Context.sol";
|
|
7
|
-
import {MessageHashUtils} from "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol";
|
|
8
5
|
import {BaseAccount} from "@account-abstraction/contracts/core/BaseAccount.sol";
|
|
9
|
-
import {
|
|
6
|
+
import {ECDSA} from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
|
|
7
|
+
import {ERC2771Context} from "@openzeppelin/contracts/metatx/ERC2771Context.sol";
|
|
8
|
+
import {IAccountExecute} from "@account-abstraction/contracts/interfaces/IAccountExecute.sol";
|
|
10
9
|
import {IEntryPoint} from "@account-abstraction/contracts/interfaces/IEntryPoint.sol";
|
|
10
|
+
import {MessageHashUtils} from "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol";
|
|
11
11
|
import {PackedUserOperation} from "@account-abstraction/contracts/interfaces/PackedUserOperation.sol";
|
|
12
|
-
import {
|
|
12
|
+
import {SIG_VALIDATION_SUCCESS, SIG_VALIDATION_FAILED} from "@account-abstraction/contracts/core/Helpers.sol";
|
|
13
|
+
import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* @title ERC2771ForwarderAccount
|
|
16
17
|
*
|
|
17
|
-
* @dev Smart Account that acts as an ERC2771 Trusted Forwarder, forwarding calls to
|
|
18
|
-
*
|
|
18
|
+
* @dev Smart Account that acts as an ERC2771 Trusted Forwarder, forwarding calls to a pre-defined contract
|
|
19
|
+
* on behalf of the signer of the userOp.
|
|
20
|
+
*
|
|
21
|
+
* Assumes the target contract is designed to work with ERC2771Context and trusts this account as a forwarder.
|
|
22
|
+
*
|
|
23
|
+
* This contract is designed to be used with an AccessManagedProxy for runtime access control management.
|
|
19
24
|
*
|
|
20
25
|
* @custom:security-contact security@ensuro.co
|
|
21
26
|
* @author Ensuro
|
|
22
27
|
*/
|
|
23
|
-
contract ERC2771ForwarderAccount is
|
|
24
|
-
bytes32 public constant WITHDRAW_ROLE = keccak256("WITHDRAW_ROLE");
|
|
25
|
-
bytes32 public constant EXECUTOR_ROLE = keccak256("EXECUTOR_ROLE");
|
|
26
|
-
|
|
28
|
+
contract ERC2771ForwarderAccount is UUPSUpgradeable, BaseAccount, IAccountExecute {
|
|
27
29
|
IEntryPoint private immutable _entryPoint;
|
|
28
|
-
|
|
30
|
+
|
|
31
|
+
/// @custom:storage-location erc7201:ensuro.storage.ERC2771ForwarderAccount
|
|
32
|
+
struct ERC2771ForwarderAccountStorage {
|
|
33
|
+
mapping(address => ERC2771Context) targets;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// keccak256(abi.encode(uint256(keccak256("ensuro.storage.ERC2771ForwarderAccount")) - 1)) & ~bytes32(uint256(0xff))
|
|
37
|
+
// solhint-disable-next-line const-name-snakecase
|
|
38
|
+
bytes32 internal constant ERC2771ForwarderAccountStorageLocation =
|
|
39
|
+
0x32800a8a254400b8b55434a22b827759dcb96a572133b419f26b7155e3843000;
|
|
40
|
+
|
|
41
|
+
function _getAccountStorage() internal pure returns (ERC2771ForwarderAccountStorage storage $) {
|
|
42
|
+
// solhint-disable-next-line no-inline-assembly
|
|
43
|
+
assembly {
|
|
44
|
+
$.slot := ERC2771ForwarderAccountStorageLocation
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
event ExecutorAdded(address indexed executor, ERC2771Context indexed target);
|
|
49
|
+
event ExecutorRemoved(address indexed executor);
|
|
29
50
|
|
|
30
51
|
error RequiredEntryPointOrExecutor(address sender);
|
|
31
|
-
error
|
|
32
|
-
error
|
|
33
|
-
error
|
|
52
|
+
error InvalidTarget(ERC2771Context target, address signer);
|
|
53
|
+
error OnlyExecuteUserOpAllowed();
|
|
54
|
+
error InvalidCall();
|
|
34
55
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
return _entryPoint;
|
|
56
|
+
constructor(IEntryPoint anEntryPoint) {
|
|
57
|
+
_entryPoint = anEntryPoint;
|
|
38
58
|
}
|
|
39
59
|
|
|
60
|
+
// solhint-disable-next-line no-empty-blocks
|
|
61
|
+
function _authorizeUpgrade(address newImpl) internal view override {}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* @dev This is a noop, for deployment convenience where an initializer is expected.
|
|
65
|
+
*/
|
|
66
|
+
//solhint-disable-next-line no-empty-blocks
|
|
67
|
+
function initialize() external {}
|
|
68
|
+
|
|
40
69
|
// solhint-disable-next-line no-empty-blocks
|
|
41
70
|
receive() external payable {}
|
|
42
71
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
_grantRole(DEFAULT_ADMIN_ROLE, admin);
|
|
46
|
-
for (uint256 i; i < executors.length; i++) {
|
|
47
|
-
_grantRole(EXECUTOR_ROLE, executors[i]);
|
|
48
|
-
}
|
|
72
|
+
function executeBatch(Call[] calldata) external virtual override {
|
|
73
|
+
revert OnlyExecuteUserOpAllowed();
|
|
49
74
|
}
|
|
50
75
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
76
|
+
function execute(address, uint256, bytes calldata) external virtual override {
|
|
77
|
+
revert OnlyExecuteUserOpAllowed();
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function _getSigner(PackedUserOperation calldata userop, bytes32 userOpHash) internal pure returns (address) {
|
|
81
|
+
bytes32 hash = MessageHashUtils.toEthSignedMessageHash(userOpHash);
|
|
82
|
+
return ECDSA.recover(hash, userop.signature);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* @dev Validates that the user operation is well formed and that the destination is correct. Does not validate signature.
|
|
87
|
+
* @return expectedSigner The address included in the call data, expected to be the signer of the userOp
|
|
88
|
+
* @return call A Call struct containing the call to be made
|
|
89
|
+
*/
|
|
90
|
+
function _validateAndDecodeCall(
|
|
91
|
+
PackedUserOperation calldata userOp,
|
|
92
|
+
bytes32 userOpHash
|
|
93
|
+
) internal pure returns (address expectedSigner, Call memory call) {
|
|
94
|
+
require(userOp.callData.length >= 80 && bytes4(userOp.callData[0:4]) == this.executeUserOp.selector, InvalidCall());
|
|
95
|
+
(expectedSigner, call.target, call.value, call.data) = abi.decode(
|
|
96
|
+
userOp.callData[4:],
|
|
97
|
+
(address, address, uint256, bytes)
|
|
98
|
+
);
|
|
99
|
+
if (call.target == address(0)) {
|
|
100
|
+
// This is an if and not a require to avoid evaluating the _getSigner call in the happy path
|
|
101
|
+
revert InvalidTarget(ERC2771Context(call.target), _getSigner(userOp, userOpHash));
|
|
62
102
|
}
|
|
63
|
-
|
|
64
|
-
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function _isAuthorized(address signer, address expectedSigner, address target) internal view returns (bool) {
|
|
106
|
+
ERC2771ForwarderAccountStorage storage $ = _getAccountStorage();
|
|
107
|
+
return signer == expectedSigner && $.targets[signer] == ERC2771Context(target);
|
|
65
108
|
}
|
|
66
109
|
|
|
67
110
|
/**
|
|
68
|
-
*
|
|
69
|
-
* @param
|
|
70
|
-
* @param
|
|
71
|
-
* @param func the calldata to pass in this call
|
|
111
|
+
* @notice Add an executor and its corresponding target contract.
|
|
112
|
+
* @param executor The executor address to add
|
|
113
|
+
* @param target The ERC2771Context target contract for this executor
|
|
72
114
|
*/
|
|
73
|
-
function
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
115
|
+
function addExecutor(address executor, ERC2771Context target) external {
|
|
116
|
+
ERC2771ForwarderAccountStorage storage $ = _getAccountStorage();
|
|
117
|
+
$.targets[executor] = target;
|
|
118
|
+
emit ExecutorAdded(executor, target);
|
|
77
119
|
}
|
|
78
120
|
|
|
79
121
|
/**
|
|
80
|
-
*
|
|
81
|
-
* @
|
|
82
|
-
* @param dest an array of destination addresses
|
|
83
|
-
* @param value an array of values to pass to each call. can be zero-length for no-value calls
|
|
84
|
-
* @param func an array of calldata to pass to each call
|
|
122
|
+
* @notice Remove an executor by setting its target to the zero address.
|
|
123
|
+
* @param executor The executor address to remove
|
|
85
124
|
*/
|
|
86
|
-
function
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
require(
|
|
91
|
-
i == 0 ? _isTrustedByTarget(dest[0]) : (dest[i - 1] == dest[i] || _isTrustedByTarget(dest[i])),
|
|
92
|
-
CanCallOnlyIfTrustedForwarder(dest[i])
|
|
93
|
-
);
|
|
94
|
-
Address.functionCallWithValue(dest[i], abi.encodePacked(func[i], sender), value.length == 0 ? 0 : value[i]);
|
|
95
|
-
}
|
|
125
|
+
function removeExecutor(address executor) external {
|
|
126
|
+
ERC2771ForwarderAccountStorage storage $ = _getAccountStorage();
|
|
127
|
+
$.targets[executor] = ERC2771Context(address(0));
|
|
128
|
+
emit ExecutorRemoved(executor);
|
|
96
129
|
}
|
|
97
130
|
|
|
98
131
|
/// implement template method of BaseAccount
|
|
@@ -100,41 +133,32 @@ contract ERC2771ForwarderAccount is AccessControl, BaseAccount {
|
|
|
100
133
|
PackedUserOperation calldata userOp,
|
|
101
134
|
bytes32 userOpHash
|
|
102
135
|
) internal virtual override returns (uint256 validationData) {
|
|
103
|
-
|
|
104
|
-
address
|
|
105
|
-
if (!
|
|
106
|
-
|
|
107
|
-
|
|
136
|
+
(address expectedSigner, Call memory call) = _validateAndDecodeCall(userOp, userOpHash);
|
|
137
|
+
address signer = _getSigner(userOp, userOpHash);
|
|
138
|
+
if (!_isAuthorized(signer, expectedSigner, call.target)) {
|
|
139
|
+
return SIG_VALIDATION_FAILED;
|
|
140
|
+
}
|
|
108
141
|
return SIG_VALIDATION_SUCCESS;
|
|
109
142
|
}
|
|
110
143
|
|
|
111
144
|
/**
|
|
112
|
-
* @dev
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
*
|
|
145
|
+
* @dev Executes a user operation by forwarding the call to the target contract with the signer as the msgSender.
|
|
146
|
+
* The calldata is expected to contain this function's selector followed by the signer and the ABI-encoded call:
|
|
147
|
+
* - signer (address): the signer of the userop, must match the signature
|
|
148
|
+
* - dest (address): the target contract address (must be the same as _target)
|
|
149
|
+
* - value (uint256): the amount of ETH to send with the call
|
|
150
|
+
* - func (bytes): the calldata for the target function
|
|
116
151
|
*
|
|
117
|
-
*
|
|
152
|
+
* @param userOp The packed user operation containing the call data and signature.
|
|
153
|
+
* @param userOpHash The hash of the user operation, used for signature verification.
|
|
118
154
|
*/
|
|
119
|
-
function
|
|
120
|
-
|
|
155
|
+
function executeUserOp(PackedUserOperation calldata userOp, bytes32 userOpHash) external override {
|
|
156
|
+
_requireFromEntryPoint();
|
|
121
157
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
uint256 returnValue;
|
|
125
|
-
// solhint-disable-next-line no-inline-assembly
|
|
126
|
-
assembly ("memory-safe") {
|
|
127
|
-
// Perform the staticcall and save the result in the scratch space.
|
|
128
|
-
// | Location | Content | Content (Hex) |
|
|
129
|
-
// |-----------|----------|--------------------------------------------------------------------|
|
|
130
|
-
// | | | result ↓ |
|
|
131
|
-
// | 0x00:0x1F | selector | 0x0000000000000000000000000000000000000000000000000000000000000001 |
|
|
132
|
-
success := staticcall(gas(), target, add(encodedParams, 0x20), mload(encodedParams), 0, 0x20)
|
|
133
|
-
returnSize := returndatasize()
|
|
134
|
-
returnValue := mload(0)
|
|
135
|
-
}
|
|
158
|
+
// We can trust that expectedSigner is the userop signer because it was checked in validateSignature
|
|
159
|
+
(address expectedSigner, Call memory call) = _validateAndDecodeCall(userOp, userOpHash);
|
|
136
160
|
|
|
137
|
-
|
|
161
|
+
Address.functionCallWithValue(call.target, abi.encodePacked(call.data, expectedSigner), call.value);
|
|
138
162
|
}
|
|
139
163
|
|
|
140
164
|
/**
|
|
@@ -156,7 +180,12 @@ contract ERC2771ForwarderAccount is AccessControl, BaseAccount {
|
|
|
156
180
|
* @param withdrawAddress target to send to
|
|
157
181
|
* @param amount to withdraw
|
|
158
182
|
*/
|
|
159
|
-
function withdrawDepositTo(address payable withdrawAddress, uint256 amount) public
|
|
183
|
+
function withdrawDepositTo(address payable withdrawAddress, uint256 amount) public {
|
|
160
184
|
entryPoint().withdrawTo(withdrawAddress, amount);
|
|
161
185
|
}
|
|
186
|
+
|
|
187
|
+
/// @inheritdoc BaseAccount
|
|
188
|
+
function entryPoint() public view virtual override returns (IEntryPoint) {
|
|
189
|
+
return _entryPoint;
|
|
190
|
+
}
|
|
162
191
|
}
|
package/js/userOp.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
import * as ethers from "ethers";
|
|
2
2
|
const { ZeroAddress } = ethers;
|
|
3
3
|
|
|
4
4
|
const defaultAbiCoder = ethers.AbiCoder.defaultAbiCoder();
|
|
5
5
|
|
|
6
|
-
function packAccountGasLimits(verificationGasLimit, callGasLimit) {
|
|
6
|
+
export function packAccountGasLimits(verificationGasLimit, callGasLimit) {
|
|
7
7
|
return ethers.toBeHex(verificationGasLimit, 16) + ethers.toBeHex(callGasLimit, 16).slice(2);
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
function packUserOp(userOp) {
|
|
10
|
+
export function packUserOp(userOp) {
|
|
11
11
|
const accountGasLimits = packAccountGasLimits(userOp.verificationGasLimit, userOp.callGasLimit);
|
|
12
12
|
const gasFees = packAccountGasLimits(userOp.maxPriorityFeePerGas, userOp.maxFeePerGas);
|
|
13
13
|
let paymasterAndData = "0x";
|
|
@@ -32,7 +32,7 @@ function packUserOp(userOp) {
|
|
|
32
32
|
};
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
function packedUserOpAsArray(packedUserOp, includeSignature = true) {
|
|
35
|
+
export function packedUserOpAsArray(packedUserOp, includeSignature = true) {
|
|
36
36
|
if (includeSignature) {
|
|
37
37
|
return [
|
|
38
38
|
packedUserOp.sender,
|
|
@@ -59,7 +59,7 @@ function packedUserOpAsArray(packedUserOp, includeSignature = true) {
|
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
function encodeUserOp(userOp, forSignature = true) {
|
|
62
|
+
export function encodeUserOp(userOp, forSignature = true) {
|
|
63
63
|
const packedUserOp = packUserOp(userOp);
|
|
64
64
|
if (forSignature) {
|
|
65
65
|
return defaultAbiCoder.encode(
|
|
@@ -94,47 +94,39 @@ function encodeUserOp(userOp, forSignature = true) {
|
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
-
function getUserOpHash(op, entryPoint, chainId) {
|
|
97
|
+
export function getUserOpHash(op, entryPoint, chainId) {
|
|
98
98
|
const userOpHash = ethers.keccak256(encodeUserOp(op, true));
|
|
99
99
|
const enc = defaultAbiCoder.encode(["bytes32", "address", "uint256"], [userOpHash, entryPoint, chainId]);
|
|
100
100
|
return ethers.keccak256(enc);
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
-
const DefaultsForUserOp = {
|
|
103
|
+
export const DefaultsForUserOp = {
|
|
104
104
|
sender: ZeroAddress,
|
|
105
105
|
nonce: 0,
|
|
106
106
|
initCode: "0x",
|
|
107
107
|
callData: "0x",
|
|
108
|
-
callGasLimit:
|
|
109
|
-
verificationGasLimit:
|
|
110
|
-
preVerificationGas:
|
|
111
|
-
maxFeePerGas:
|
|
108
|
+
callGasLimit: 0n,
|
|
109
|
+
verificationGasLimit: 150000n, // default verification gas. will add create2 cost (3200+200*length) if initCode exists
|
|
110
|
+
preVerificationGas: 21000n, // should also cover calldata cost.
|
|
111
|
+
maxFeePerGas: 0n,
|
|
112
112
|
maxPriorityFeePerGas: 1e9,
|
|
113
113
|
paymaster: ZeroAddress,
|
|
114
114
|
paymasterData: "0x",
|
|
115
|
-
paymasterVerificationGasLimit:
|
|
115
|
+
paymasterVerificationGasLimit: 300000n,
|
|
116
116
|
paymasterPostOpGasLimit: 0,
|
|
117
117
|
signature: "0x",
|
|
118
118
|
};
|
|
119
119
|
|
|
120
|
-
function signUserOp(op, signer, entryPoint, chainId) {
|
|
121
|
-
const
|
|
122
|
-
const
|
|
123
|
-
Buffer.from("\x19Ethereum Signed Message:\n32", "ascii"),
|
|
124
|
-
Buffer.from(arrayify(message)),
|
|
125
|
-
]);
|
|
126
|
-
|
|
127
|
-
const sig = ecsign(keccak256_buffer(msg1), Buffer.from(arrayify(signer.privateKey)));
|
|
128
|
-
// that's equivalent of: await signer.signMessage(message);
|
|
129
|
-
// (but without "async"
|
|
130
|
-
const signedMessage1 = toRpcSig(sig.v, sig.r, sig.s);
|
|
120
|
+
export async function signUserOp(op, signer, entryPoint, chainId) {
|
|
121
|
+
const userOpHash = getUserOpHash(op, entryPoint, chainId);
|
|
122
|
+
const signature = await signer.signMessage(ethers.getBytes(userOpHash));
|
|
131
123
|
return {
|
|
132
124
|
...op,
|
|
133
|
-
signature
|
|
125
|
+
signature,
|
|
134
126
|
};
|
|
135
127
|
}
|
|
136
128
|
|
|
137
|
-
function fillUserOpDefaults(op, defaults = DefaultsForUserOp) {
|
|
129
|
+
export function fillUserOpDefaults(op, defaults = DefaultsForUserOp) {
|
|
138
130
|
const partial = { ...op };
|
|
139
131
|
// we want "item:undefined" to be used from defaults, and not override defaults, so we must explicitly
|
|
140
132
|
// remove those so "merge" will succeed.
|
|
@@ -147,14 +139,3 @@ function fillUserOpDefaults(op, defaults = DefaultsForUserOp) {
|
|
|
147
139
|
const filled = { ...defaults, ...partial };
|
|
148
140
|
return filled;
|
|
149
141
|
}
|
|
150
|
-
|
|
151
|
-
module.exports = {
|
|
152
|
-
packAccountGasLimits,
|
|
153
|
-
packUserOp,
|
|
154
|
-
packedUserOpAsArray,
|
|
155
|
-
encodeUserOp,
|
|
156
|
-
getUserOpHash,
|
|
157
|
-
DefaultsForUserOp,
|
|
158
|
-
signUserOp,
|
|
159
|
-
fillUserOpDefaults,
|
|
160
|
-
};
|