Skip to content

Commit

Permalink
Adding a refund target
Browse files Browse the repository at this point in the history
  • Loading branch information
brickpop committed Oct 30, 2024
1 parent 7d28eb7 commit 6b9f13d
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
5 changes: 3 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# NETWORK AND DEPLOYMENT WALLET
DEPLOYMENT_PRIVATE_KEY="..."
# NETWORK AND ACCOUNT(s)
DEPLOYMENT_PRIVATE_KEY="0x..."
REFUND_ADDRESS="0x..."

# The name of the networks to use for test/production
TESTNET_NETWORK="holesky"
Expand Down
30 changes: 30 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ E2E_TEST_NAME=TestE2EV2
DEPLOY_SCRIPT=script/DeployGauges.s.sol:DeployGauges
VERBOSITY=-vvv
DEPLOYMENT_LOG_FILE=$(shell echo "./deployment-$(shell date +"%y-%m-%d-%H-%M").log")
DEPLOYMENT_ADDRESS=$(shell cast wallet address --private-key $(DEPLOYMENT_PRIVATE_KEY))
SHELL:=/bin/bash

# TARGETS

Expand Down Expand Up @@ -143,3 +145,31 @@ deploy: test
$(VERIFIER_URL_PARAM) \
$(ETHERSCAN_API_KEY_PARAM) \
$(VERBOSITY) | tee $(DEPLOYMENT_LOG_FILE)

: ##

.PHONY: refund
refund: ## Refund the remaining balance left on the deployment account
@echo "Refunding the remaining balance on $(DEPLOYMENT_ADDRESS)"
@if [ -z $(REFUND_ADDRESS) -o $(REFUND_ADDRESS) = "0x0000000000000000000000000000000000000000" ]; then \
echo "- The refund address is empty" ; \
exit 1; \
fi
@BALANCE=$(shell cast balance $(DEPLOYMENT_ADDRESS) --rpc-url $(PRODNET_RPC_URL)) && \
GAS_PRICE=$(shell cast gas-price --rpc-url $(PRODNET_RPC_URL)) && \
REMAINING=$$(echo "$$BALANCE - $$GAS_PRICE * 21000" | bc) && \
\
ENOUGH_BALANCE=$$(echo "$$REMAINING > 0" | bc) && \
if [ "$$ENOUGH_BALANCE" = "0" ]; then \
echo -e "- No balance can be refunded: $$BALANCE wei\n- Minimum balance: $${REMAINING:1} wei" ; \
exit 1; \
fi ; \
echo -n -e "Summary:\n- Refunding: $$REMAINING (wei)\n- Recipient: $(REFUND_ADDRESS)\n\nContinue? (y/N) " && \
\
read CONFIRM && \
if [ "$$CONFIRM" != "y" ]; then echo "Aborting" ; exit 1; fi ; \
\
cast send --private-key $(DEPLOYMENT_PRIVATE_KEY) \
--rpc-url $(PRODNET_RPC_URL) \
--value $$REMAINING \
$(REFUND_ADDRESS)
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,16 @@ Check the available make targets to simulate and deploy the smart contracts:

### Deployment Checklist

- [ ] I am running on a docker container running Alpine Linux
- [ ] I have cloned the official repository on my computer and I have checked out the corresponding branch
- [ ] I am running on a docker container running Debian Linux (stable)
- [ ] I have run `docker run --rm -it -v .:/deployment debian:bookworm-slim`
- [ ] I have run `apt update && apt install make curl git`
- [ ] I have run `apt update && apt install -y make curl git vim neovim bc`
- [ ] I have run `curl -L https://foundry.paradigm.xyz | bash`
- [ ] I have run `source /root/.bashrc && foundryup`
- [ ] I have run `cd /deployment`
- [ ] I have run `make init`
- [ ] I have printed the contents of `.env` and `.env.test` on the screen
- [ ] I am opening an editor on the `/deployment` folder, within Docker
- [ ] The `.env` file contains the correct parameters for the deployment
- [ ] I have created a brand new burner wallet and copied the private key to `DEPLOYMENT_PRIVATE_KEY`
- [ ] I have reviewed the target network and RPC URL
Expand Down

0 comments on commit 6b9f13d

Please sign in to comment.