Skip to content

Commit

Permalink
Merge pull request #97 from traderjoe-xyz/v2.1
Browse files Browse the repository at this point in the history
LB v2.1
  • Loading branch information
0xmurloc authored Apr 4, 2023
2 parents 07f1021 + adbe21c commit 8eeb42d
Show file tree
Hide file tree
Showing 126 changed files with 15,125 additions and 10,351 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.env
.vscode
cache
out
broadcast
broadcast
slither-results.json
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"solidity.formatter": "forge",
"slither.solcPath": "",
"slither.hiddenDetectors": [],
"coverage-gutters.showLineCoverage": true
}
8 changes: 8 additions & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,19 @@ libs = ['lib']
optimizer = true
optimizer_runs = 800

fs_permissions = [{ access = "read", path = "./"}]

[fuzz]
runs = 1024

[rpc_endpoints]
avalanche = "https://api.avax.network/ext/bc/C/rpc"
fuji = "https://api.avax-test.network/ext/bc/C/rpc"

[etherscan]
arbitrum = { key = "${ARBISCAN_API_KEY}", chain = 42161 }
avalanche = { key = "${SNOWTRACE_API_KEY}", chain = 43114 }
arbitrum_goerli = { key = "${ARBISCAN_API_KEY}", chain = 421613 }
fuji = { key = "${SNOWTRACE_API_KEY}", chain = 43113 }

# See more config options https://github.com/foundry-rs/foundry/tree/master/config
2 changes: 1 addition & 1 deletion lib/openzeppelin-contracts
2 changes: 1 addition & 1 deletion remappings.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
ds-test/=lib/forge-std/lib/ds-test/src/
forge-std/=lib/forge-std/src/
openzeppelin/=lib/openzeppelin-contracts/contracts
openzeppelin/=lib/openzeppelin-contracts/contracts/
8 changes: 8 additions & 0 deletions script/config/bips-config.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ library BipsConfig {
uint16 protocolShare;
uint24 maxVolatilityAccumulated;
uint16 sampleLifetime;
bool isOpen;
}

function getPreset(uint256 _bp) internal pure returns (FactoryPreset memory preset) {
Expand All @@ -26,6 +27,7 @@ library BipsConfig {
preset.protocolShare = 0;
preset.maxVolatilityAccumulated = 100_000;
preset.sampleLifetime = 120;
preset.isOpen = false;
} else if (_bp == 2) {
preset.binStep = 2;
preset.baseFactor = 15_000;
Expand All @@ -36,6 +38,7 @@ library BipsConfig {
preset.protocolShare = 0;
preset.maxVolatilityAccumulated = 250_000;
preset.sampleLifetime = 120;
preset.isOpen = false;
} else if (_bp == 5) {
preset.binStep = 5;
preset.baseFactor = 8_000;
Expand All @@ -46,6 +49,7 @@ library BipsConfig {
preset.protocolShare = 0;
preset.maxVolatilityAccumulated = 300_000;
preset.sampleLifetime = 120;
preset.isOpen = false;
} else if (_bp == 10) {
preset.binStep = 10;
preset.baseFactor = 10_000;
Expand All @@ -56,6 +60,7 @@ library BipsConfig {
preset.protocolShare = 0;
preset.maxVolatilityAccumulated = 350_000;
preset.sampleLifetime = 120;
preset.isOpen = false;
} else if (_bp == 15) {
preset.binStep = 15;
preset.baseFactor = 10_000;
Expand All @@ -66,6 +71,7 @@ library BipsConfig {
preset.protocolShare = 0;
preset.maxVolatilityAccumulated = 350_000;
preset.sampleLifetime = 120;
preset.isOpen = false;
} else if (_bp == 20) {
preset.binStep = 20;
preset.baseFactor = 10_000;
Expand All @@ -76,6 +82,7 @@ library BipsConfig {
preset.protocolShare = 0;
preset.maxVolatilityAccumulated = 350_000;
preset.sampleLifetime = 120;
preset.isOpen = false;
} else if (_bp == 25) {
preset.binStep = 25;
preset.baseFactor = 10_000;
Expand All @@ -86,6 +93,7 @@ library BipsConfig {
preset.protocolShare = 0;
preset.maxVolatilityAccumulated = 350_000;
preset.sampleLifetime = 120;
preset.isOpen = false;
}
}

Expand Down
18 changes: 18 additions & 0 deletions script/config/deployments.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"avalanche_fuji": {
"factory_v1": "0xF5c7d9733e5f53abCC1695820c4818C59B457C2C",
"factory_v2": "0x6B8E020098cd1B3Ec9f811024bc24e51C660F768",
"multisig": "0xFFC08538077a0455E0F4077823b1A0E3e18Faf0b",
"router_v1": "0xd7f655E3376cE2D7A2b08fF01Eb3B1023191A901",
"router_v2": "0x7b50046cEC8252ca835b148b1eDD997319120a12",
"w_native": "0xd00ae08403B9bbb9124bB305C09058E32C39A48c"
},
"arbitrum_one_goerli": {
"factory_v1": "0x1886D09C9Ade0c5DB822D85D21678Db67B6c2982",
"factory_v2": "0xC8Af41e49e2C03eA14706C7aa9cEE60454bc5c03",
"multisig": "0xbeE5c10Cf6E4F68f831E11C1D9E59B43560B3642",
"router_v1": "0x454206AD825cAfaE03c9581014AF6b74f7D53713",
"router_v2": "0x6E9603f925FB5A74f7321f51499d9633c1252893",
"w_native": "0xaE4EC9901c3076D0DdBe76A520F9E90a6227aCB7"
}
}
152 changes: 94 additions & 58 deletions script/deploy-core.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,73 +4,109 @@ pragma solidity 0.8.10;

import "forge-std/Script.sol";

import "src/LBFactory.sol";
import "src/LBRouter.sol";
import "src/LBPair.sol";
import "src/LBQuoter.sol";
import {ILBFactory, LBFactory} from "src/LBFactory.sol";
import {ILBRouter, IJoeFactory, ILBLegacyFactory, ILBLegacyRouter, IWNATIVE, LBRouter} from "src/LBRouter.sol";
import {IERC20, LBPair} from "src/LBPair.sol";
import {LBQuoter} from "src/LBQuoter.sol";

import "./config/bips-config.sol";
import {BipsConfig} from "./config/bips-config.sol";

contract CoreDeployer is Script {
address private constant WAVAX_AVALANCHE = 0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7;
address private constant WAVAX_FUJI = 0xd00ae08403B9bbb9124bB305C09058E32C39A48c;
using stdJson for string;

address private constant FACTORY_V1_AVALANCHE = 0x9Ad6C38BE94206cA50bb0d90783181662f0Cfa10;
address private constant FACTORY_V1_FUJI = 0xF5c7d9733e5f53abCC1695820c4818C59B457C2C;
uint256 private constant FLASHLOAN_FEE = 5e12;

address private wavax;
address private factoryV1;
struct Deployment {
address factoryV1;
address factoryV2;
address multisig;
address routerV1;
address routerV2;
address wNative;
}

uint256 private constant FLASHLOAN_FEE = 5e12;
string[] chains = ["avalanche_fuji", "arbitrum_one_goerli"];

function run() external {
if (block.chainid == 43114) {
wavax = WAVAX_AVALANCHE;
factoryV1 = FACTORY_V1_AVALANCHE;
} else {
wavax = WAVAX_FUJI;
factoryV1 = FACTORY_V1_FUJI;
}
function setUp() public {
_overwriteDefaultArbitrumRPC();
}

function run() public {
string memory json = vm.readFile("script/config/deployments.json");
address deployer = vm.rememberKey(vm.envUint("DEPLOYER_PRIVATE_KEY"));

console.log("Deployer address: %s", deployer);

vm.broadcast();
LBFactory factory = new LBFactory(msg.sender, FLASHLOAN_FEE);
console.log("LBFactory deployed -->", address(factory));

vm.broadcast();
LBPair pairImplementation = new LBPair(factory);
console.log("LBPair implementation deployed -->", address(pairImplementation));

vm.broadcast();
LBRouter router = new LBRouter(factory, IJoeFactory(factoryV1), IWAVAX(wavax));
console.log("LBRouter deployed -->", address(router));

vm.startBroadcast();
LBQuoter quoter = new LBQuoter(address(router), address(factoryV1), address(factory));
console.log("LBQuoter deployed -->", address(quoter));

factory.setLBPairImplementation(address(pairImplementation));
console.log("LBPair implementation set on factory");

factory.addQuoteAsset(IERC20(wavax));
console.log("Wavax whitelisted as quote asset");
vm.stopBroadcast();

vm.startBroadcast();
uint256[] memory presetList = BipsConfig.getPresetList();
for (uint256 i; i < presetList.length; i++) {
BipsConfig.FactoryPreset memory preset = BipsConfig.getPreset(presetList[i]);
factory.setPreset(
preset.binStep,
preset.baseFactor,
preset.filterPeriod,
preset.decayPeriod,
preset.reductionFactor,
preset.variableFeeControl,
preset.protocolShare,
preset.maxVolatilityAccumulated,
preset.sampleLifetime
for (uint256 i = 0; i < chains.length; i++) {
bytes memory rawDeploymentData = json.parseRaw(string(abi.encodePacked(".", chains[i])));
Deployment memory deployment = abi.decode(rawDeploymentData, (Deployment));

console.log("\nDeploying V2.1 on %s", chains[i]);

vm.createSelectFork(StdChains.getChain(chains[i]).rpcUrl);

vm.broadcast(deployer);
LBFactory factory = new LBFactory(deployer, FLASHLOAN_FEE);
console.log("LBFactory deployed -->", address(factory));

vm.broadcast(deployer);
LBPair pairImplementation = new LBPair(factory);
console.log("LBPair implementation deployed -->", address(pairImplementation));

vm.broadcast(deployer);
LBRouter router = new LBRouter(
factory,
IJoeFactory(deployment.factoryV1),
ILBLegacyFactory(deployment.factoryV2),
ILBLegacyRouter(deployment.routerV2),
IWNATIVE(deployment.wNative)
);
console.log("LBRouter deployed -->", address(router));

vm.startBroadcast(deployer);
LBQuoter quoter =
new LBQuoter(deployment.factoryV1, deployment.factoryV2, address(factory),deployment.routerV2, address(router));
console.log("LBQuoter deployed -->", address(quoter));

factory.setLBPairImplementation(address(pairImplementation));
console.log("LBPair implementation set on factory\n");

uint256 quoteAssets = ILBLegacyFactory(deployment.factoryV2).getNumberOfQuoteAssets();
for (uint256 j = 0; j < quoteAssets; j++) {
IERC20 quoteAsset = ILBLegacyFactory(deployment.factoryV2).getQuoteAsset(j);
factory.addQuoteAsset(quoteAsset);
console.log("Quote asset whitelisted -->", address(quoteAsset));
}

uint256[] memory presetList = BipsConfig.getPresetList();
for (uint256 j; j < presetList.length; j++) {
BipsConfig.FactoryPreset memory preset = BipsConfig.getPreset(presetList[j]);
factory.setPreset(
preset.binStep,
preset.baseFactor,
preset.filterPeriod,
preset.decayPeriod,
preset.reductionFactor,
preset.variableFeeControl,
preset.protocolShare,
preset.maxVolatilityAccumulated,
preset.isOpen
);
}

factory.setPendingOwner(deployment.multisig);
vm.stopBroadcast();
}
vm.stopBroadcast();
}

function _overwriteDefaultArbitrumRPC() private {
StdChains.setChain(
"arbitrum_one_goerli",
StdChains.ChainData({
name: "Arbitrum One Goerli",
chainId: 421613,
rpcUrl: vm.envString("ARBITRUM_TESTNET_RPC_URL")
})
);
}
}
8 changes: 8 additions & 0 deletions slither.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"filter_paths": "(lib/|test/|script/)",
"solc_remaps": [
"ds-test/=lib/ds-test/src/",
"forge-std/=lib/forge-std/src/",
"openzeppelin/=lib/openzeppelin-contracts/contracts/"
]
}
Loading

0 comments on commit 8eeb42d

Please sign in to comment.