forked from eth-infinitism/account-abstraction
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial contract created from Yoav's pseudocode
- Loading branch information
0 parents
commit 894034e
Showing
8 changed files
with
27,938 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
node_modules | ||
|
||
#Hardhat files | ||
cache | ||
artifacts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# account-abstraction | ||
|
||
https://notes.ethereum.org/@vbuterin/alt_abstraction |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// SPDX-License-Identifier: GPL-3.0 | ||
pragma solidity >=0.7.0 <0.9.0; | ||
|
||
contract Singleton { | ||
|
||
uint256 MAX_CHECK_GAS = 100_000; | ||
uint256 POST_CALL_GAS_OVERHEAD = 50_000; | ||
|
||
struct UserOperation { | ||
bytes20 target; | ||
uint64 callGas; | ||
uint64 postCallGas; | ||
uint256 gasPrice; | ||
bytes callData; | ||
bytes signature; | ||
} | ||
|
||
function handleOps(UserOperation[] calldata ops, uint256 minimumGasPrice) public { | ||
//require(msg.sender == block.coinbase); | ||
uint256 savedBalance = address(this).balance; | ||
for(uint i=0;i<ops.length;i++){ | ||
UserOperation calldata op = ops[i]; | ||
if (gasleft() <= op.callGas + op.postCallGas + MAX_CHECK_GAS + POST_CALL_GAS_OVERHEAD){ | ||
break; | ||
} | ||
handleOp(op, minimumGasPrice); | ||
} | ||
payable(address(msg.sender)).transfer(address(this).balance-savedBalance); | ||
} | ||
|
||
function handleOp(UserOperation calldata op, uint256 minimumGasPrice) public { | ||
uint256 savedGas = gasleft(); | ||
|
||
require(op.gasPrice >= minimumGasPrice); | ||
require(gasleft()-op.callGas+op.postCallGas >= POST_CALL_GAS_OVERHEAD); | ||
|
||
ISmartContractWallet smartContractWallet = ISmartContractWallet(address(op.target)); | ||
smartContractWallet.payForOp{gas:MAX_CHECK_GAS}(op.callGas, op.postCallGas, op.callData, op.signature); | ||
|
||
require(address(this).balance >= op.gasPrice*(op.callGas+op.postCallGas)); | ||
(bool success,) = address(smartContractWallet).call{gas:op.callGas}(op.callData); | ||
require(success); | ||
smartContractWallet.handleRefundGas{gas:op.postCallGas,value:(savedGas-gasleft()-op.postCallGas)*tx.gasprice}; | ||
} | ||
} | ||
|
||
interface ISmartContractWallet { | ||
|
||
// callGas, postCallGas, callData, signature | ||
function payForOp(uint64, uint64, bytes calldata, bytes calldata) external; | ||
|
||
function handleRefundGas() payable external; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
require("@nomiclabs/hardhat-waffle"); | ||
|
||
// This is a sample Hardhat task. To learn how to create your own go to | ||
// https://hardhat.org/guides/create-task.html | ||
task("accounts", "Prints the list of accounts", async (taskArgs, hre) => { | ||
const accounts = await hre.ethers.getSigners(); | ||
|
||
for (const account of accounts) { | ||
console.log(account.address); | ||
} | ||
}); | ||
|
||
// You need to export an object to set up your config | ||
// Go to https://hardhat.org/config/ to learn more | ||
|
||
/** | ||
* @type import('hardhat/config').HardhatUserConfig | ||
*/ | ||
module.exports = { | ||
solidity: "0.8.4", | ||
}; |
Oops, something went wrong.