Skip to content

Commit

Permalink
🔨 script to withdraw as operator
Browse files Browse the repository at this point in the history
  • Loading branch information
qd-qd committed Mar 31, 2024
1 parent 91d63e1 commit e68d474
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ pragma solidity >=0.8.19 <0.9.0;
import { Paymaster } from "src/v1/Paymaster.sol";
import { BaseScript } from "../Base.s.sol";

/// @title PaymasterWithdraw
/// @title PaymasterWithdrawAsOwner
/// @notice Withdraw funds to an arbitrary address
/// @dev Can only be called by the owner of the paymaster
contract PaymasterWithdraw is BaseScript {
contract PaymasterWithdrawAsOwner is BaseScript {
function run() public payable broadcast {
address paymasterAddress = vm.envAddress("PAYMASTER");
address payable recipient = payable(vm.envAddress("RECIPIENT"));
Expand All @@ -28,19 +28,3 @@ contract PaymasterWithdraw is BaseScript {
require(paymaster.getDeposit() == initialBalance - amount, "Withdraw failed");
}
}

/*
ℹ️ HOW TO USE THIS SCRIPT USING A LEDGER:
ADMIN=<ADMIN_ADDRESS> forge script PaymasterDeposit --rpc-url <RPC_URL> --ledger \
--sender <ACCOUNT_ADDRESS> [--broadcast]
ℹ️ HOW TO USE THIS SCRIPT WITH AN ARBITRARY PRIVATE KEY (NOT RECOMMENDED):
PRIVATE_KEY=<PRIVATE_KEY> ADMIN=<ADMIN_ADDRESS> forge script PaymasterDeposit \
--rpc-url <RPC_URL>[--broadcast]
ℹ️ HOW TO USE THIS SCRIPT ON ANVIL IN DEFAULT MODE:
ADMIN=<ADMIN_ADDRESS> forge script PaymasterDeposit --rpc-url http://127.0.0.1:8545 --broadcast --sender \
0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --mnemonics "test test test test test test test test test test test junk"
*/
29 changes: 29 additions & 0 deletions script/Paymaster/04_PaymasterWithdrawAsOperator.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// SPDX-License-Identifier: APACHE-2.0
pragma solidity >=0.8.19 <0.9.0;

import { Paymaster } from "src/v1/Paymaster.sol";
import { BaseScript } from "../Base.s.sol";

/// @title PaymasterWithdrawAsOperator
/// @notice Withdraw funds to an arbitrary address
/// @dev Can only be called by the owner of the paymaster
contract PaymasterWithdrawAsOperator is BaseScript {
function run() public payable broadcast {
address paymasterAddress = vm.envAddress("PAYMASTER");

Paymaster paymaster = Paymaster(paymasterAddress);

// get the initial balance of the paymaster
uint256 initialBalance = paymaster.getDeposit();
uint256 amount = vm.envOr("AMOUNT", initialBalance);

// ensure we don't withdraw more than the paymaster has
require(initialBalance >= amount, "Insufficient deposited funds");

// withdraw some funds to the recipient
paymaster.withdrawTo(amount);

// check that the withdraw was successful
require(paymaster.getDeposit() == initialBalance - amount, "Withdraw failed");
}
}

0 comments on commit e68d474

Please sign in to comment.