Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: deploy script #4

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
15 changes: 5 additions & 10 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
## NODE URLS
MAINNET_URL=https://eth-mainnet.alchemyapi.io/v2/API_KEY
MAINNET_KEY=API_KEY
POLYGON_MAINNET_URL=https://polygon-mainnet.g.alchemy.com/v2/API_KEY
RINKEBY_URL=
DEFAULT_FORK_BLOCK=15001901

## Always consider these compromised
MNEMONIC=
PRIVATE_KEY=
RPC_URL=
PRIVATE_KEY=
FRAXLEND_CIRCUIT_BREAKER=
FRAXLEND_COMPTROLLER=
FRAXLEND_TIMELOCK=
33 changes: 15 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,32 @@
## [Fraxlend Documentation](https://docs.frax.finance/fraxlend/fraxlend-overview)
<br>
# Fraxlend

# Introduction to Fraxlend
## Overview

Fraxlend is a lending platform that allows anyone to create a market between a pair of ERC-20 tokens. Any token part of a Chainlink data feed can be lent to borrowers or used as collateral. Each pair is an isolated, permission-less market which allows anyone to create and participate in lending and borrowing activities.
Fraxlend adheres to the EIP-4626: Tokenized Vault Standard, lenders are able to deposit ERC-20 assets into the pair and receive yield-bearing fTokens.
Fraxlend is a lending platform that allows anyone to create a market between a pair of ERC-20 tokens. Any token part of a Chainlink data feed can be lent to borrowers or used as collateral. Each pair is an isolated, permission-less market which allows anyone to create and participate in lending and borrowing activities.

## Overview
Fraxlend adheres to the EIP-4626: Tokenized Vault Standard, lenders are able to deposit ERC-20 assets into the pair and receive yield-bearing fTokens.

![https://github.com/FraxFinance/fraxlend/raw/main/documentation/_images/PairOverview.png](https://github.com/FraxFinance/fraxlend/raw/main/documentation/_images/PairOverview.png)

<br>
<br>

# Building and Testing
## Usage

- First copy `.env.example` to `.env` and fill in archival node URLs as well as a mnemonic (hardhat only)
- To download needed modules run `npm install`
- This repository contains scripts to compile using both Hardhat and Foundry
- You will need to [install foundry](https://book.getfoundry.sh/getting-started/installation)
- Install foundry submodules `git submodule init && git submodule update`
```bash
# Compile
forge build

Compilation
# Test
forge test

- `forge build`
- `npx hardhat compile`
# Deploy
source .env
forge script DeployFraxlend --private-key $PRIVATE_KEY --rpc-url $RPC_URL
```

<br>
<br>

# License
## License
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
27 changes: 9 additions & 18 deletions foundry.toml
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
[profile.default]
src = 'src/contracts'
test = 'src/test'
out = 'out'
libs = ['node_modules', 'lib']
#block number
block_number = 100
# The block timestamp in tests
block_timestamp = 1500
# allow ffi
ffi = true
# gas limit in tests
gas_limit = 30000000
# optimizer
optimizer = true
# optimizer runs
optimizer_runs = 200
# use via-ir optimizer
# via_ir = true
src = 'src/contracts'
test = 'test'
out = 'out'
libs = ['node_modules', 'lib']

solc = "0.8.19"
ffi = true
optimizer = false
optimizer_runs = 200

# See more config options https://github.com/gakonst/foundry/tree/master/config
49 changes: 49 additions & 0 deletions script/Deploy.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// SPDX-License-Identifier: The Unlicense
pragma solidity ^0.8.0;

import {Script, console2} from "forge-std/Script.sol";

import {FraxlendPair} from "../src/contracts/FraxlendPair.sol";
import {FraxlendWhitelist} from "../src/contracts/FraxlendWhitelist.sol";
import {FraxlendPairRegistry} from "../src/contracts/FraxlendPairRegistry.sol";
import {FraxlendPairDeployer, ConstructorParams} from "../src/contracts/FraxlendPairDeployer.sol";

contract DeployFraxlend is Script {
FraxlendWhitelist whitelist;
FraxlendPairRegistry registry;
FraxlendPairDeployer pairDeployer;

function run() public virtual {
vm.startBroadcast();

console2.log("Deploying `FraxlendWhitelist`...\n");
whitelist = new FraxlendWhitelist();
console2.log("`FraxlendWhitelist`: ", address(whitelist), "\n");

console2.log("Deploying `FraxlendPairRegistry`...\n");
registry = new FraxlendPairRegistry(msg.sender, new address[](0));
console2.log("`FraxlendPairRegistry`: ", address(registry), "\n");

console2.log("Deploying `FraxlendPairDeployer`...\n");
pairDeployer = new FraxlendPairDeployer(
ConstructorParams(
vm.envAddress("FRAXLEND_CIRCUIT_BREAKER"),
vm.envAddress("FRAXLEND_COMPTROLLER"),
vm.envAddress("FRAXLEND_TIMELOCK"),
address(whitelist),
address(registry)
)
);
console2.log("`FraxlendPairDeployer`: ", address(pairDeployer), "\n");

pairDeployer.setCreationCode(type(FraxlendPair).creationCode);

address[] memory deployers = new address[](1);
deployers[0] = msg.sender;

registry.setDeployers(deployers, true);
whitelist.setFraxlendDeployerWhitelist(deployers, true);

vm.stopBroadcast();
}
}