Skip to content

Commit

Permalink
custom min deposit and vanity create3 address
Browse files Browse the repository at this point in the history
  • Loading branch information
Filipp Makarov authored and Filipp Makarov committed Dec 11, 2024
1 parent 1b4cf38 commit 405301f
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 27 deletions.
3 changes: 0 additions & 3 deletions contracts/base/BasePaymaster.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import { IPaymaster } from "account-abstraction/interfaces/IPaymaster.sol";
import { IEntryPoint } from "account-abstraction/interfaces/IEntryPoint.sol";
import "account-abstraction/core/UserOperationLib.sol";

Check warning on line 10 in contracts/base/BasePaymaster.sol

View workflow job for this annotation

GitHub Actions / Lint sources

global import of path account-abstraction/core/UserOperationLib.sol is not allowed. Specify names to import individually or bind all exports of the module into a name (import "path" as Name)

import {console} from "forge-std/console.sol";

/**
* Helper class for creating a paymaster.
* provides helper methods for staking.
Expand All @@ -25,7 +23,6 @@ abstract contract BasePaymaster is IPaymaster, SoladyOwnable {
uint256 internal constant _PAYMASTER_DATA_OFFSET = UserOperationLib.PAYMASTER_DATA_OFFSET;

constructor(address owner, IEntryPoint entryPointArg) SoladyOwnable(owner) {
console.log("0-0");
_validateEntryPointInterface(entryPointArg);
entryPoint = entryPointArg;
}
Expand Down
8 changes: 0 additions & 8 deletions contracts/sponsorship/BiconomySponsorshipPaymaster.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { SafeTransferLib } from "solady/utils/SafeTransferLib.sol";
import { IBiconomySponsorshipPaymaster } from "../interfaces/IBiconomySponsorshipPaymaster.sol";

import {console} from "forge-std/console.sol";

/**
* @title BiconomySponsorshipPaymaster
* @author livingrockrises<[email protected]>
Expand Down Expand Up @@ -67,19 +65,13 @@ contract BiconomySponsorshipPaymaster is
)
BasePaymaster(owner, entryPointArg)
{
console.log("0");
_checkConstructorArgs(verifyingSignerArg, feeCollectorArg, unaccountedGasArg);
console.log("1");
assembly ("memory-safe") {
sstore(verifyingSigner.slot, verifyingSignerArg)
}
console.log("2");
feeCollector = feeCollectorArg;
console.log("3");
unaccountedGas = unaccountedGasArg;
console.log("4");
paymasterIdWithdrawalDelay = paymasterIdWithdrawalDelayArg;
console.log("5");
minDeposit = minDepositArg;
}

Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

24 changes: 22 additions & 2 deletions scripts/bash-deploy/deploy-gasdaddy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,29 @@ else
printf "Using precompiled artifacts\n"
fi

### Get custom min deposit
read -r -p "Do you want to specify a custom min deposit? (y/n): " proceed
if [ $proceed = "y" ]; then
printf "Choose a custom min deposit: \n 1. 0.001 native token \n 2. 0.01 native token \n 3. 0.1 native token \n 4. 1 native token \n 5. 10 native tokens \n"
read -r -a MIN_DEPOSIT_CHOICE
if [ $MIN_DEPOSIT_CHOICE = "1" ]; then
MIN_DEPOSIT=1000000000000000
elif [ $MIN_DEPOSIT_CHOICE = "2" ]; then
MIN_DEPOSIT=10000000000000000
elif [ $MIN_DEPOSIT_CHOICE = "3" ]; then
MIN_DEPOSIT=100000000000000000
elif [ $MIN_DEPOSIT_CHOICE = "4" ]; then
MIN_DEPOSIT=1000000000000000000
elif [ $MIN_DEPOSIT_CHOICE = "5" ]; then
MIN_DEPOSIT=10000000000000000000
fi
else
MIN_DEPOSIT=1000000000000000
fi

### DEPLOY GASDADDY SCs ###
printf "Addresses for Paymaster SCs:\n"
forge script DeployGasdaddy true --sig "run(bool)" --rpc-url $CHAIN_NAME -vv | grep -e "address" -e "already deployed"
forge script DeployGasdaddy true $MIN_DEPOSIT --sig "run(bool,uint256)" --rpc-url $CHAIN_NAME -vv | grep -e "address" -e "already deployed"
printf "Do you want to proceed with the addresses above? (y/n): "
read -r proceed
if [ $proceed = "y" ]; then
Expand All @@ -104,7 +124,7 @@ if [ $proceed = "y" ]; then
{
printf "Proceeding with deployment \n"
mkdir -p ./logs/$CHAIN_NAME
forge script DeployGasdaddy false --sig "run(bool)" --rpc-url $CHAIN_NAME --etherscan-api-key $CHAIN_NAME --private-key $PRIVATE_KEY $VERIFY -vv --broadcast --slow $GAS_SUFFIX # 1> ./logs/$CHAIN_NAME/$CHAIN_NAME-deploy-gasdaddy.log 2> ./logs/$CHAIN_NAME/$CHAIN_NAME-deploy-gasdaddy-errors.log
forge script DeployGasdaddy false $MIN_DEPOSIT --sig "run(bool,uint256)" --rpc-url $CHAIN_NAME --etherscan-api-key $CHAIN_NAME --private-key $PRIVATE_KEY $VERIFY -vv --broadcast --slow $GAS_SUFFIX 1> ./logs/$CHAIN_NAME/$CHAIN_NAME-deploy-gasdaddy.log 2> ./logs/$CHAIN_NAME/$CHAIN_NAME-deploy-gasdaddy-errors.log
} || {
printf "Deployment failed\n See logs for more details\n"
exit 1
Expand Down
56 changes: 44 additions & 12 deletions scripts/foundry/DeployGasdaddy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface Create3Deployer {

contract DeployGasdaddy is Script {
// SALTS
bytes32 constant SPONSORSHIP_PAYMASTER_DEPLOYMENT_SALT = 0x0000000cc000000000000000000000000000000048da08a98903870005d16743;
bytes32 constant SPONSORSHIP_PAYMASTER_DEPLOYMENT_SALT = 0xe37d270a4b697fd49a738e7a7027fe45ab32da92f60226a4fb719794c954eab3; // PM Address => 0x0000a35bb5246c53457a8a28b05b1f0b79348ce1

// CREATE3 DEPLOYER ADDRESS
address constant CREATE3_DEPLOYER_ADDRESS = 0x000000aFCC4940A247A53bEa5f3f4602433fe815;
Expand All @@ -23,25 +23,34 @@ contract DeployGasdaddy is Script {
address constant FEE_COLLECTOR = 0x2cf491602ad22944D9047282aBC00D3e52F56B37;
uint256 constant UNACCOUNTED_GAS = 50_000;
uint256 constant PAYMASTER_ID_WITHDRAWAL_DELAY = 3600; // 1 hour
uint256 constant MIN_DEPOSIT = 1e15;
address constant ENTRY_POINT_V07 = 0x0000000071727De22E5E9d8BAf0edAc6f37da032;

mapping (uint256 => bytes) public signaturesForMinDeposits;

Create3Deployer create3Deployer;


function setUp() public {
create3Deployer = Create3Deployer(CREATE3_DEPLOYER_ADDRESS);
signaturesForMinDeposits[1e15] = hex'f799f0e37b89b42d667d6cf6ca461bb4e1d9818a5568a640ad89dbe74a16b18b105a3ecbe06828faaf91153bf2238bd5bf9f52cda834eb2ddc81c5665b77901f1b'; //0.001 native token
signaturesForMinDeposits[1e16] = hex'3d4fc4d9a447fb205cc50dce4b74230f0e0baea776bbce2cced39e1b82f612bc5de05607fdeaf3734f8577a8b829b0dd05bb0fe760e4fe9dda28b729d45c95d21c'; //0.01 native token
signaturesForMinDeposits[1e17] = hex'f121c54fabc0f95a2baa1cc296135d125f636532d489a9850a0ea3fe7f52694a2954b6f5cd42aca1e2203e7e39108a878477bfe2f90ed6a38ec578199e5586111c'; //0.1 native token
signaturesForMinDeposits[1e18] = hex'0e2f4921b34b8a2a6ceab67bd7db9655c0e272a725cbb5da84acaad1d023237817a1cb754fd65dd45bebc43312dafb9b53c8e58619da7da5acc9ea96294534141b'; //1 native token
signaturesForMinDeposits[1e19] = hex'6e559e01580bc8cd18fabef2d0aa018f35dc5cb1aa0c26e8cb8b9c45478382cf0fcc208ad2564d693418957e417a90b9081716fa1c01cba65e8442edaed584541c'; //10 native tokens

}

function run(bool check) public {
function run(bool check, uint256 minDeposit) public {
if (check) {
checkGasDaddyAddresses();
checkGasDaddyAddresses(minDeposit);
} else {
deployGasDaddy();
vm.startBroadcast();
deployGasDaddy(minDeposit);
vm.stopBroadcast();
}
}

function checkGasDaddyAddresses() public {
function checkGasDaddyAddresses(uint256 minDeposit) public {
bytes memory bytecode = vm.getCode("scripts/bash-deploy/artifacts/BiconomySponsorshipPaymaster/BiconomySponsorshipPaymaster.json");
bytes memory args = abi.encode(
VERIFYING_PAYMASTER_OWNER,
Expand All @@ -50,7 +59,7 @@ contract DeployGasdaddy is Script {
FEE_COLLECTOR,
UNACCOUNTED_GAS,
PAYMASTER_ID_WITHDRAWAL_DELAY,
MIN_DEPOSIT
minDeposit
);
address sponsorshipPM = create3Deployer.addressOf(SPONSORSHIP_PAYMASTER_DEPLOYMENT_SALT);

Expand All @@ -61,11 +70,34 @@ contract DeployGasdaddy is Script {

console.log("Sponsorship Paymaster address: ", sponsorshipPM, " || >> Code Size: ", codeSize);

//initcode hash to look for the salt
//console.logBytes32(keccak256(abi.encodePacked(bytecode, args)));
// Use this block to get initcode hashes to sign
/*
uint256[] memory minDeposits = new uint256[](5);
minDeposits[0] = 1e15;
minDeposits[1] = 1e16;
minDeposits[2] = 1e17;
minDeposits[3] = 1e18;
minDeposits[4] = 1e19;
for (uint256 i = 0; i < minDeposits.length; i++) {
minDeposit = minDeposits[i];
args = abi.encode(
VERIFYING_PAYMASTER_OWNER,
ENTRY_POINT_V07,
VERIFYING_SIGNER,
FEE_COLLECTOR,
UNACCOUNTED_GAS,
PAYMASTER_ID_WITHDRAWAL_DELAY,
minDeposit
);
console.log("min deposit: ", (minDeposit));
console.logBytes32(keccak256(abi.encodePacked(bytecode, args)));
}
*/

}

function deployGasDaddy() public {
function deployGasDaddy(uint256 minDeposit) public {

//
// SPONSORSHIP PAYMASTER
Expand All @@ -78,7 +110,7 @@ contract DeployGasdaddy is Script {
FEE_COLLECTOR,
UNACCOUNTED_GAS,
PAYMASTER_ID_WITHDRAWAL_DELAY,
MIN_DEPOSIT
minDeposit
);
address sponsorshipPM = create3Deployer.addressOf(SPONSORSHIP_PAYMASTER_DEPLOYMENT_SALT);
uint256 codeSize;
Expand All @@ -89,7 +121,7 @@ contract DeployGasdaddy is Script {
console.log("Sponsorship Paymaster already deployed at", sponsorshipPM);
} else {
bytes memory initcode = abi.encodePacked(bytecode, args);
bytes memory signature = hex'f799f0e37b89b42d667d6cf6ca461bb4e1d9818a5568a640ad89dbe74a16b18b105a3ecbe06828faaf91153bf2238bd5bf9f52cda834eb2ddc81c5665b77901f1b'; //pre-computed signature
bytes memory signature = signaturesForMinDeposits[minDeposit];
sponsorshipPM = create3Deployer.deploy(SPONSORSHIP_PAYMASTER_DEPLOYMENT_SALT, initcode, signature);
console.log("Sponsorship Paymaster deployed at", sponsorshipPM);
}
Expand Down

0 comments on commit 405301f

Please sign in to comment.