Skip to content

Commit 10608be

Browse files
scripts
1 parent 449beb4 commit 10608be

File tree

10 files changed

+147
-0
lines changed

10 files changed

+147
-0
lines changed

.env.example

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Private key to interact with contracts using scripts inside /script
2+
WALLET_PRIVATE_KEY=0xa26..
3+
# RPC
4+
MAINNET_RPC_URL="https://"
5+
ARBITRUM_RPC_URL="https://"
6+
BASE_RPC_URL="https://"
7+
8+
# Explorer API Key
9+
ETHERSCAN_MAINNET_API_KEY=adada
10+
ETHERSCAN_ARBITRUM_API_KEY=adada
11+
ETHERSCAN_BASE_API_KEY=adada

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ out/
66
!/broadcast
77
/broadcast/*/31337/
88
/broadcast/**/dry-run/
9+
broadcast/
910

1011
# Dotenv file
1112
.env

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ forge test
4444
forge coverage
4545
```
4646

47+
## Private Deployment
48+
49+
- EulerSwapFactory: 0xB6cFe9b23d18A034cE925Ee84b97D20a52Db1940
50+
- EulerSwapPeriphery: 0x7fc1edF54d86DfAA90F1069E81D4B520A2A44d2B
51+
4752
## Safety
4853

4954
This software is experimental and is provided "as is" and "as available".

foundry.toml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,18 @@ solc = "0.8.27"
66
optimizer = true
77
optimizer_runs = 10000
88
gas_reports = ["*"]
9+
fs_permissions = [{ access = "read", path = "./"}]
10+
11+
[doc]
12+
out = "foundry-docs/"
13+
title = "EulerSwap Contracts Documentation"
14+
15+
[rpc_endpoints]
16+
mainnet = "${MAINNET_RPC_URL}"
17+
base = "${BASE_RPC_URL}"
18+
19+
[etherscan]
20+
mainnet = { key = "${ETHERSCAN_MAINNET_API_KEY}" }
21+
base = { key = "${ETHERSCAN_BASE_API_KEY}" }
922

1023
# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options

script/DeployPool.s.sol

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// SPDX-License-Identifier: GPL-2.0-or-later
2+
pragma solidity ^0.8.0;
3+
4+
import {ScriptUtil} from "./ScriptUtil.s.sol";
5+
import {IEulerSwapFactory, EulerSwapFactory} from "../src/EulerSwapFactory.sol";
6+
7+
/// @title Script to deploy EulerSwapFactory & EulerSwapPeriphery.
8+
contract DeployPool is ScriptUtil {
9+
function run() public {
10+
// load wallet
11+
uint256 deployerKey = vm.envUint("WALLET_PRIVATE_KEY");
12+
address deployerAddress = vm.rememberKey(deployerKey);
13+
14+
// load JSON file
15+
string memory inputScriptFileName = "DeployPool_input.json";
16+
string memory json = _getJsonFile(inputScriptFileName);
17+
18+
EulerSwapFactory factory = EulerSwapFactory(vm.parseJsonAddress(json, ".factory"));
19+
IEulerSwapFactory.DeployParams memory params = IEulerSwapFactory.DeployParams({
20+
vault0: vm.parseJsonAddress(json, ".vault0"),
21+
vault1: vm.parseJsonAddress(json, ".vault1"),
22+
swapAccount: vm.parseJsonAddress(json, ".swapAccount"),
23+
fee: vm.parseJsonUint(json, ".fee"),
24+
priceX: vm.parseJsonUint(json, ".priceX"),
25+
priceY: vm.parseJsonUint(json, ".priceY"),
26+
concentrationX: vm.parseJsonUint(json, ".concentrationX"),
27+
concentrationY: vm.parseJsonUint(json, ".concentrationY"),
28+
debtLimit0: uint112(vm.parseJsonUint(json, ".debtLimit0")),
29+
debtLimit1: uint112(vm.parseJsonUint(json, ".debtLimit1"))
30+
});
31+
32+
vm.startBroadcast(deployerAddress);
33+
34+
address pool = factory.deployPool(params);
35+
36+
string memory outputScriptFileName = "DeployPool_output.json";
37+
38+
string memory object;
39+
object = vm.serializeAddress("factory", "deployedPool", pool);
40+
41+
vm.writeJson(object, string.concat(vm.projectRoot(), "/script/", outputScriptFileName));
42+
43+
vm.stopBroadcast();
44+
}
45+
}

script/DeployProtocol.s.sol

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// SPDX-License-Identifier: GPL-2.0-or-later
2+
pragma solidity ^0.8.0;
3+
4+
import {ScriptUtil} from "./ScriptUtil.s.sol";
5+
import {EulerSwapFactory} from "../src/EulerSwapFactory.sol";
6+
import {EulerSwapPeriphery} from "../src/EulerSwapPeriphery.sol";
7+
8+
/// @title Script to deploy EulerSwapFactory & EulerSwapPeriphery.
9+
contract DeployProtocol is ScriptUtil {
10+
function run() public {
11+
// load wallet
12+
uint256 deployerKey = vm.envUint("WALLET_PRIVATE_KEY");
13+
address deployerAddress = vm.rememberKey(deployerKey);
14+
15+
// load JSON file
16+
string memory inputScriptFileName = "DeployProtocol_input.json";
17+
string memory json = _getJsonFile(inputScriptFileName);
18+
19+
address evc = vm.parseJsonAddress(json, ".evc");
20+
21+
vm.startBroadcast(deployerAddress);
22+
23+
new EulerSwapFactory();
24+
new EulerSwapPeriphery(evc);
25+
26+
vm.stopBroadcast();
27+
}
28+
}

script/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Forge scripts
2+
3+
Every script takes inputs via a `ScriptName_input.json` file inside the json directory.
4+
5+
Before running the scripts, please make sure to fill the `.env` file following the `.env.example`. The main env variables for the script to succefully run, are `WALLET_PRIVATE_KEY` and the `NETWORK_RPC_URL`.
6+
7+
After filling the `.env` file, make sure to run: `source .env` in your terminal.
8+
9+
## Deploy protocol
10+
11+
- Fill the `DeployProtocol_input.json` file with the needed inputs.
12+
- Run `forge script ./script/DeployProtocol.s.sol --rpc-url network_name --broadcast --slow`
13+

script/ScriptUtil.s.sol

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// SPDX-License-Identifier: GPL-2.0-or-later
2+
pragma solidity ^0.8.0;
3+
4+
import "forge-std/Script.sol";
5+
6+
contract ScriptUtil is Script {
7+
function _getJsonFile(string memory _jsonFile) internal view returns (string memory) {
8+
return vm.readFile(_getJsonFilePath(_jsonFile));
9+
}
10+
11+
function _getJsonFilePath(string memory _jsonFile) private view returns (string memory) {
12+
string memory root = vm.projectRoot();
13+
return string.concat(root, "/script/json/", _jsonFile);
14+
}
15+
}

script/json/DeployPool_input.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"factory": "0xB6cFe9b23d18A034cE925Ee84b97D20a52Db1940",
3+
"vault0": "0xa66957e58b60d6b92b850c8773a9ff9b0ba96a65",
4+
"vault1": "0x4212e01c7c8e1c21dea6030c74ae2084f5337bd1",
5+
"swapAccount": "0x0C9a3dd6b8F28529d72d7f9cE918D493519EE383",
6+
"fee": 0,
7+
"priceX": 1e18,
8+
"priceY": 1e18,
9+
"concentrationX": 0.4e18,
10+
"concentrationY": 0.85e18,
11+
"debtLimit0": "1000000000",
12+
"debtLimit1": "1000000000"
13+
}

script/json/DeployProtocol_input.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"evc": "0x0C9a3dd6b8F28529d72d7f9cE918D493519EE383"
3+
}

0 commit comments

Comments
 (0)