-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdeploy.sh
executable file
·200 lines (180 loc) · 11.9 KB
/
deploy.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#!/bin/bash
# DEPLOYER_PRIVATE_KEY=0x...
# DEPLOYER_PUBLIC_KEY=0x...
# ETHERSCAN_API_KEY=...
if [ -z "$DEPLOYER_PRIVATE_KEY" ]; then
echo "Error: DEPLOYER_PRIVATE_KEY is not set."
exit 1
fi
if [ -z "$DEPLOYER_PUBLIC_KEY" ]; then
echo "Error: DEPLOYER_PUBLIC_KEY is not set."
exit 1
fi
# Config
RPC_URL="http://localhost:8545" # "https://arb-mainnet..."
CHAIN_NAME="sepolia" # "arbitrum" "mainnet"...
VERIFY=true
AAVE_DEADLINE=2592000
FRAX_DEADLINE=1296000
GMX_DEADLINE=1296000
FIXEDYIELD_DEADLINE=2592000
FIXEDYIELD_YELD=0
if [ "$VERIFY" = true ] && [ -z "$ETHERSCAN_API_KEY" ]; then
echo "Error: ETHERSCAN_API_KEY is not set."
exit 1
fi
# Tokens
USDC=0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8
USDT=0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9
DAI=0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1
FRAX=0x17FC002b466eEc40DaE837Fc4bE5c67993ddBd6F
WETH=0x82aF49447D8a07e3bd95BD0d56f35241523fBab1
WBTC=0x2f2a2543B76A4166549F7aaB2e75Bef0aefC5B0f
tokens=($USDC $USDT $DAI $FRAX $WETH $WBTC)
# Params
AAVE=0x794a61358D6845594F94dc1DB02A252b5b4814aD
FRAXLEND=0x2D0483FefAbA4325c7521539a3DFaCf94A19C472
GMXROUTER1=0xA906F338CB21815cBc4Bc87ace9e68c87eF8d8F1
GMXROUTER2=0xB95DB5B167D75e6d04227CfFFA61069348d271F5
# Deploy Manager
echo "Deploying Manager contract..."
MANAGER=$(forge create src/Manager.sol:Manager --rpc-url=$RPC_URL --private-key=$DEPLOYER_PRIVATE_KEY --optimize)
export MANAGER_ADDRESS=$(echo "$MANAGER" | grep "Deployed to:" | awk '{print $3}')
if [ -z "$MANAGER_ADDRESS" ]; then
echo "Error: Manager contract deployment failed"
exit 1
fi
if [ "$VERIFY" = true ]; then
echo "Verifying..."
forge verify-contract $MANAGER_ADDRESS src/Manager.sol:Manager --chain $CHAIN_NAME --watch
echo "OK!"
fi
# Create vaults
declare -A VAULTS
echo "Creating vaults..."
for token in "${tokens[@]}"; do
cast send --rpc-url=$RPC_URL --private-key=$DEPLOYER_PRIVATE_KEY $token "approve(address,uint256)" $MANAGER_ADDRESS 1000
cast send --rpc-url=$RPC_URL --private-key=$DEPLOYER_PRIVATE_KEY $MANAGER_ADDRESS "create(address)" $token
VAULT_BYTES=$(cast call --rpc-url=$RPC_URL $MANAGER_ADDRESS "vaults(address)" $token)
VAULT_ADDRESS="0x${VAULT_BYTES: -40}"
if [ "$VAULT_ADDRESS" = "0x0000000000000000000000000000000000000000" ]; then
echo "Error: Vault creation failed for token $token"
exit 1
fi
echo "Vault for $token created at $VAULT_ADDRESS"
if [ "$VERIFY" = true ]; then
echo "Verifying Vault..."
VAULTS[$token]=$VAULT_ADDRESS
ENCODED_ARGS=$(cast abi-encode "constructor(address)" $token)
forge verify-contract ${VAULTS[$token]} src/Vault.sol:Vault --constructor-args $ENCODED_ARGS --chain $CHAIN_NAME --watch --etherscan-api-key $ETHERSCAN_API_KEY
echo "OK!"
fi
done
# Deploy AaveService
echo "Deploying AaveService contract..."
AAVESERVICE=$(forge create src/services/debit/AaveService.sol:AaveService --rpc-url=$RPC_URL --private-key=$DEPLOYER_PRIVATE_KEY --optimize --constructor-args $MANAGER_ADDRESS $AAVE $AAVE_DEADLINE)
AAVESERVICE_ADDRESS=$(echo "$AAVESERVICE" | grep "Deployed to:" | awk '{print $3}')
if [ -z "$AAVESERVICE_ADDRESS" ]; then
echo "Error: AaveService contract deployment failed"
exit 1
fi
if [ "$VERIFY" = true ]; then
echo "Verifying..."
ENCODED_ARGS=$(cast abi-encode "constructor(address,address,uint256)" $MANAGER_ADDRESS $AAVE $AAVE_DEADLINE)
forge verify-contract $AAVESERVICE_ADDRESS src/services/debit/AaveService.sol:AaveService --constructor-args $ENCODED_ARGS --chain $CHAIN_NAME --watch --etherscan-api-key $ETHERSCAN_API_KEY
echo "OK!"
fi
cast send --rpc-url=$RPC_URL --private-key=$DEPLOYER_PRIVATE_KEY $AAVESERVICE_ADDRESS "setMinMargin(address,uint256)" $USDC 10000000
cast send --rpc-url=$RPC_URL --private-key=$DEPLOYER_PRIVATE_KEY $AAVESERVICE_ADDRESS "setMinMargin(address,uint256)" $USDT 10000000
cast send --rpc-url=$RPC_URL --private-key=$DEPLOYER_PRIVATE_KEY $AAVESERVICE_ADDRESS "setMinMargin(address,uint256)" $DAI 10000000000000000000
cast send --rpc-url=$RPC_URL --private-key=$DEPLOYER_PRIVATE_KEY $AAVESERVICE_ADDRESS "setMinMargin(address,uint256)" $WETH 4000000000000000
cast send --rpc-url=$RPC_URL --private-key=$DEPLOYER_PRIVATE_KEY $AAVESERVICE_ADDRESS "setMinMargin(address,uint256)" $WBTC 20000
cast send --rpc-url=$RPC_URL --private-key=$DEPLOYER_PRIVATE_KEY $AAVESERVICE_ADDRESS "setMinMargin(address,uint256)" $FRAX 10000000000000000000
# Deploy FraxlendService
echo "Deploying FraxlendService contract..."
FRAXSERVICE=$(forge create src/services/debit/FraxlendService.sol:FraxlendService --rpc-url=$RPC_URL --private-key=$DEPLOYER_PRIVATE_KEY --optimize --constructor-args $MANAGER_ADDRESS $FRAXLEND $FRAX_DEADLINE)
FRAXSERVICE_ADDRESS=$(echo "$FRAXSERVICE" | grep "Deployed to:" | awk '{print $3}')
if [ -z "$FRAXSERVICE_ADDRESS" ]; then
echo "Error: FraxlendService contract deployment failed"
exit 1
fi
if [ "$VERIFY" = true ]; then
echo "Verifying..."
ENCODED_ARGS=$(cast abi-encode "constructor(address,address,uint256)" $MANAGER_ADDRESS $FRAXLEND $FRAX_DEADLINE)
forge verify-contract $FRAXSERVICE_ADDRESS src/services/debit/FraxlendService.sol:FraxlendService --constructor-args $ENCODED_ARGS --chain $CHAIN_NAME --watch --etherscan-api-key $ETHERSCAN_API_KEY
echo "OK!"
fi
cast send --rpc-url=$RPC_URL --private-key=$DEPLOYER_PRIVATE_KEY $FRAXSERVICE_ADDRESS "setMinMargin(address,uint256)" $FRAX 10000000000000000000
# Deploy GmxService
echo "Deploying GmxService contract..."
GMXSERVICE=$(forge create src/services/debit/GmxService.sol:GmxService --rpc-url=$RPC_URL --private-key=$DEPLOYER_PRIVATE_KEY --optimize --constructor-args $MANAGER_ADDRESS $GMXROUTER1 $GMXROUTER2 $GMX_DEADLINE)
GMXSERVICE_ADDRESS=$(echo "$GMXSERVICE" | grep "Deployed to:" | awk '{print $3}')
if [ -z "$GMXSERVICE_ADDRESS" ]; then
echo "Error: GmxService contract deployment failed"
exit 1
fi
if [ "$VERIFY" = true ]; then
echo "Verifying..."
ENCODED_ARGS=$(cast abi-encode "constructor(address,address,address,uint256)" $MANAGER_ADDRESS $GMXROUTER1 $GMXROUTER2 $GMX_DEADLINE)
forge verify-contract $GMXSERVICE_ADDRESS src/services/debit/GmxService.sol:GmxService --constructor-args $ENCODED_ARGS --chain $CHAIN_NAME --watch --etherscan-api-key $ETHERSCAN_API_KEY
echo "OK!"
fi
cast send --rpc-url=$RPC_URL --private-key=$DEPLOYER_PRIVATE_KEY $GMXSERVICE_ADDRESS "setMinMargin(address,uint256)" $USDC 10000000
cast send --rpc-url=$RPC_URL --private-key=$DEPLOYER_PRIVATE_KEY $GMXSERVICE_ADDRESS "setMinMargin(address,uint256)" $USDT 10000000
cast send --rpc-url=$RPC_URL --private-key=$DEPLOYER_PRIVATE_KEY $GMXSERVICE_ADDRESS "setMinMargin(address,uint256)" $DAI 10000000000000000000
cast send --rpc-url=$RPC_URL --private-key=$DEPLOYER_PRIVATE_KEY $GMXSERVICE_ADDRESS "setMinMargin(address,uint256)" $WETH 4000000000000000
cast send --rpc-url=$RPC_URL --private-key=$DEPLOYER_PRIVATE_KEY $GMXSERVICE_ADDRESS "setMinMargin(address,uint256)" $WBTC 20000
cast send --rpc-url=$RPC_URL --private-key=$DEPLOYER_PRIVATE_KEY $GMXSERVICE_ADDRESS "setMinMargin(address,uint256)" $FRAX 10000000000000000000
# Deploy FixedYieldService
echo "Deploying FixedYieldService contract..."
FIXEDYIELD=$(forge create src/services/credit/FixedYieldService.sol:FixedYieldService --rpc-url=$RPC_URL --private-key=$DEPLOYER_PRIVATE_KEY --optimize --constructor-args $MANAGER_ADDRESS $FIXEDYIELD_YELD $FIXEDYIELD_DEADLINE)
FIXEDYIELD_ADDRESS=$(echo "$FIXEDYIELD" | grep "Deployed to:" | awk '{print $3}')
if [ -z "$FIXEDYIELD_ADDRESS" ]; then
echo "Error: FixedYieldService contract deployment failed"
exit 1
fi
if [ "$VERIFY" = true ]; then
echo "Verifying..."
ENCODED_ARGS=$(cast abi-encode "constructor(address,uint256,uint256)" $MANAGER_ADDRESS $FIXEDYIELD_YELD $FIXEDYIELD_DEADLINE)
forge verify-contract $FIXEDYIELD_ADDRESS src/services/credit/FixedYieldService.sol:FixedYieldService --constructor-args $ENCODED_ARGS --chain $CHAIN_NAME --watch --etherscan-api-key $ETHERSCAN_API_KEY
echo "OK!"
fi
cast send --rpc-url=$RPC_URL --private-key=$DEPLOYER_PRIVATE_KEY $FIXEDYIELD_ADDRESS "setMinLoan(address,uint256)" $USDC 10000000
cast send --rpc-url=$RPC_URL --private-key=$DEPLOYER_PRIVATE_KEY $FIXEDYIELD_ADDRESS "setMinLoan(address,uint256)" $USDT 10000000
cast send --rpc-url=$RPC_URL --private-key=$DEPLOYER_PRIVATE_KEY $FIXEDYIELD_ADDRESS "setMinLoan(address,uint256)" $DAI 10000000000000000000
cast send --rpc-url=$RPC_URL --private-key=$DEPLOYER_PRIVATE_KEY $FIXEDYIELD_ADDRESS "setMinLoan(address,uint256)" $WETH 4000000000000000
cast send --rpc-url=$RPC_URL --private-key=$DEPLOYER_PRIVATE_KEY $FIXEDYIELD_ADDRESS "setMinLoan(address,uint256)" $WBTC 20000
cast send --rpc-url=$RPC_URL --private-key=$DEPLOYER_PRIVATE_KEY $FIXEDYIELD_ADDRESS "setMinLoan(address,uint256)" $FRAX 10000000000000000000
# Set caps
## AaveService
cast send --rpc-url=$RPC_URL --private-key=$DEPLOYER_PRIVATE_KEY $MANAGER_ADDRESS "setCap(address,address,uint256,uint256)" $AAVESERVICE_ADDRESS $USDC 800000000000000000 10000000000
cast send --rpc-url=$RPC_URL --private-key=$DEPLOYER_PRIVATE_KEY $MANAGER_ADDRESS "setCap(address,address,uint256,uint256)" $AAVESERVICE_ADDRESS $USDT 800000000000000000 10000000000
cast send --rpc-url=$RPC_URL --private-key=$DEPLOYER_PRIVATE_KEY $MANAGER_ADDRESS "setCap(address,address,uint256,uint256)" $AAVESERVICE_ADDRESS $DAI 800000000000000000 10000000000000000000000
cast send --rpc-url=$RPC_URL --private-key=$DEPLOYER_PRIVATE_KEY $MANAGER_ADDRESS "setCap(address,address,uint256,uint256)" $AAVESERVICE_ADDRESS $WETH 800000000000000000 4000000000000000000
cast send --rpc-url=$RPC_URL --private-key=$DEPLOYER_PRIVATE_KEY $MANAGER_ADDRESS "setCap(address,address,uint256,uint256)" $AAVESERVICE_ADDRESS $WBTC 800000000000000000 20000000
cast send --rpc-url=$RPC_URL --private-key=$DEPLOYER_PRIVATE_KEY $MANAGER_ADDRESS "setCap(address,address,uint256,uint256)" $AAVESERVICE_ADDRESS $FRAX 800000000000000000 10000000000000000000000
## GmxService
cast send --rpc-url=$RPC_URL --private-key=$DEPLOYER_PRIVATE_KEY $MANAGER_ADDRESS "setCap(address,address,uint256,uint256)" $GMXSERVICE_ADDRESS $USDC 500000000000000000 10000000000
cast send --rpc-url=$RPC_URL --private-key=$DEPLOYER_PRIVATE_KEY $MANAGER_ADDRESS "setCap(address,address,uint256,uint256)" $GMXSERVICE_ADDRESS $USDT 500000000000000000 10000000000
cast send --rpc-url=$RPC_URL --private-key=$DEPLOYER_PRIVATE_KEY $MANAGER_ADDRESS "setCap(address,address,uint256,uint256)" $GMXSERVICE_ADDRESS $DAI 500000000000000000 10000000000000000000000
cast send --rpc-url=$RPC_URL --private-key=$DEPLOYER_PRIVATE_KEY $MANAGER_ADDRESS "setCap(address,address,uint256,uint256)" $GMXSERVICE_ADDRESS $WETH 500000000000000000 4000000000000000000
cast send --rpc-url=$RPC_URL --private-key=$DEPLOYER_PRIVATE_KEY $MANAGER_ADDRESS "setCap(address,address,uint256,uint256)" $GMXSERVICE_ADDRESS $WBTC 500000000000000000 20000000
cast send --rpc-url=$RPC_URL --private-key=$DEPLOYER_PRIVATE_KEY $MANAGER_ADDRESS "setCap(address,address,uint256,uint256)" $GMXSERVICE_ADDRESS $FRAX 500000000000000000 10000000000000000000000
## FraxlendService
cast send --rpc-url=$RPC_URL --private-key=$DEPLOYER_PRIVATE_KEY $MANAGER_ADDRESS "setCap(address,address,uint256,uint256)" $FRAXSERVICE_ADDRESS $FRAX 500000000000000000 10000000000000000000000
## FixedYieldService
for token in "${tokens[@]}"; do
cast send --rpc-url=$RPC_URL --private-key=$DEPLOYER_PRIVATE_KEY $MANAGER_ADDRESS "setCap(address,address,uint256,uint256)" $FIXEDYIELD_ADDRESS $token 1 0
done
# Print out address
echo " "
echo "---------------------------------------------------------------------------"
echo "Manager contract deployed to $MANAGER_ADDRESS"
for token in "${tokens[@]}"; do
echo "Vault for $token deployed to $VAULTS[$token]"
done
echo "AaveService contract deployed to $AAVESERVICE_ADDRESS"
echo "FraxlendService contract deployed to $FRAXSERVICE_ADDRESS"
echo "GmxService contract deployed to $GMXSERVICE_ADDRESS"
echo "FixedYieldService contract deployed to $FIXEDYIELD_ADDRESS"
echo "---------------------------------------------------------------------------"