Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 10 additions & 19 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
.PHONY: install build tests clean format deploy-router deploy-hook deploy-tokens-and-pool deploy-contracts
.PHONY: install build tests clean format deploy-router deploy-hook create-pool-and-mint-liquidity deploy-auto-wrapper swap-usdc-for-usdl-exact-in swap-usdl-for-usdc-exact-in swap-usdl-for-usdc-exact-out

DEPLOYER_ECDSA_PRIV_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
# public key - 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266

PREDICATE_HOOK_ADDRESS=0x452e2E2CfcaC437d4E321226A3255d2cFc5c68A0
SWAP_ROUTER_ADDRESS=0x8F2c925603c4ba055779475F14241E3c9ee7c1be
AUTO_WRAPPER_HOOK_ADDRESS=0x75202124c8B7FAFBD66AB67F39CE01f69C0128c8
POSM_ADDRESS=0xbD216513d74C8cf14cf4747E6AaA6420FF64ee9e
POSM_ADDRESS=0xbD216513d74C8cf14cf4747E6AaA6420FF64ee9e # mainnet POSM
# POLICY_ID=x-aleo-6a52de9724a6e8f2 // mainnet
POLICY_ID=local-test-policy
# POLICY_ID=x-sanctions-example-policy

# Network configuration
NETWORK=LOCAL
NETWORK=MAINNET
RPC_URL=http://localhost:8545

COMMIT_HASH=$(shell git rev-parse --short HEAD)
Expand All @@ -34,7 +33,7 @@ format:
build:
forge build --via-ir

#_______________________________________LOCAL ENV SETUP_______________________________________#
#______________________________________ENV SETUP_______________________________________#
deploy-pool-manager:
forge script script/common/DeployPoolManager.s.sol \
--via-ir \
Expand All @@ -61,26 +60,27 @@ deploy-predicate-hook:
--private-key ${DEPLOYER_ECDSA_PRIV_KEY} \
--broadcast -vvvv

deploy-tokens-and-liquidity-pool:
create-pool-and-mint-liquidity:
export NETWORK=${NETWORK} && \
export HOOK_ADDRESS=${PREDICATE_HOOK_ADDRESS} && \
export SWAP_ROUTER_ADDRESS=${SWAP_ROUTER_ADDRESS} && \
forge script script/common/DeployTokensAndPool.s.sol \
forge script script/common/CreatePoolandMintLiquidity.s.sol \
--via-ir \
--rpc-url ${RPC_URL} \
--private-key ${DEPLOYER_ECDSA_PRIV_KEY} \
--broadcast -vvvv

create-pool-and-mint-liquidity:
deploy-auto-wrapper:
export NETWORK=${NETWORK} && \
export HOOK_ADDRESS=${PREDICATE_HOOK_ADDRESS} && \
export SWAP_ROUTER_ADDRESS=${SWAP_ROUTER_ADDRESS} && \
forge script script/common/CreatePoolandMintLiquidity.s.sol \
forge script script/common/DeployAutoWrapperAndInitPool.s.sol \
--via-ir \
--rpc-url ${RPC_URL} \
--private-key ${DEPLOYER_ECDSA_PRIV_KEY} \
--broadcast -vvvv

#______________________________________SWAP SCRIPT_______________________________________#
swap-usdc-for-usdl-exact-in:
export NETWORK=${NETWORK} && \
export CASE=SWAP_USDC_FOR_USDL_EXACT_IN && \
Expand Down Expand Up @@ -114,13 +114,4 @@ swap-usdl-for-usdc-exact-out:
--private-key ${DEPLOYER_ECDSA_PRIV_KEY} \
--broadcast -vvvv

deploy-auto-wrapper:
export NETWORK=${NETWORK} && \
export HOOK_ADDRESS=${PREDICATE_HOOK_ADDRESS} && \
export SWAP_ROUTER_ADDRESS=${SWAP_ROUTER_ADDRESS} && \
forge script script/common/DeployAutoWrapperAndInitPool.s.sol \
--via-ir \
--rpc-url ${RPC_URL} \
--private-key ${DEPLOYER_ECDSA_PRIV_KEY} \
--broadcast -vvvv
deploy-contracts: deploy-pool-manager deploy-router deploy-predicate-hook deploy-tokens-and-liquidity-pool deploy-auto-wrapper

30 changes: 16 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Policy docs [here](https://docs.predicate.io/essentials/introduction).
### Prerequisites
- Foundry
- An Ethereum node provider (e.g. Alchemy, Infura, etc.)
- An account with 50 USDL, 50 wUSDL, 50 USDC on Ethereum is required for local development against an Ethereum Mainnet fork

### Setup

Expand All @@ -57,29 +58,30 @@ make tests
```

## Local Development
For local development, it is recommended to run an anvil fork for mainnet. Alternatively, there's scripts in `Makefile` to deploy
PoolManager, PositionManager etc
For local development, it is recommended to run an anvil fork for mainnet. Alternatively, there's `DeployTokensAndPool.s.sol` to deploy PoolManager, PositionManager etc.

To run a local anvil fork:
To run a mainnet anvil fork:
```
anvil --fork-url <MAINNET_URL> --fork-block-number 22197233
```

For testing with mainnet anvil fork:

**Makefile Updates**
- Update ENV variable as `NETWORK=MAINNET`. This enables our network selector in script to use mainnet addresses for tokens, poolmanager etc.
- Update ENV variable for `DEPLOYER_ECDSA_PRIV_KEY` to a key that has USDL, wUSDL and USDC (this is not consumed in testing as we are running local fork but is required)
- Update ENV varialbe as `POLICY_ID=x-test-policy`
**Makefile updates**
- Verify `NETWORK=MAINNET` in Makefile. This enables our network selector in script to use mainnet addresses for tokens, poolmanager etc.
- Update ENV variable for `DEPLOYER_ECDSA_PRIV_KEY` to the key that has USDL, wUSDL and USDC on mainnet (this is not consumed in testing as we are running local fork but is required)

**Steps**
1. Run `make deploy-router` to deploy V4 router. Update `SWAP_ROUTER_ADDRESS` env variable in Makefile
2. Run `make deploy-predicate-hook` to deploy standalone predicate hook contract. Update `PREDICATE_HOOK_ADDRESS` env variable in Makefile
3. Run `make create-pool-and-mint-liquidity`. This deploys a V4 pool and mints necessary liquidity as well
4. Run `make deploy-auto-wrapper` to deploy auto wrapper and create ghost pool. Update `AUTO_WRAPPER_HOOK_ADDRESS` env variable in Makefile.
5. Run `make swap-usdc-for-usdl-exact-in`. This will swap USDC for USDL on the ghost + liquidity pools that we just configured. (there's some more options available in the script that can be used).

*Note: Predicate signature validation is skipped as the predicate hook owner is added to an authorized owner allow-list during hook creation.*
1. Run `make deploy-router` to deploy V4 router.
2. Update `SWAP_ROUTER_ADDRESS` env variable in Makefile from this deployment
3. Run `make deploy-predicate-hook` to deploy standalone predicate hook contract.
4. Update `PREDICATE_HOOK_ADDRESS` env variable in Makefile from this deployment
5. Run `make create-pool-and-mint-liquidity`. This deploys a V4 pool and mints necessary liquidity as well
6. Run `make deploy-auto-wrapper` to deploy auto wrapper and create ghost pool.
7. Update `AUTO_WRAPPER_HOOK_ADDRESS` env variable in Makefile from this deployment
8. Run `make swap-usdc-for-usdl-exact-in`. This will swap USDC for USDL on the ghost + liquidity pools that we just configured. (there's some more options available in the script that can be used).

*Note: Predicate signature validation is skipped for local testing as the predicate hook owner is added to an authorized owner allow-list during hook creation.*

## Testing

Expand Down