Skip to content

Commit

Permalink
Integrated new auctions and liquidator
Browse files Browse the repository at this point in the history
  • Loading branch information
asselstine committed Aug 4, 2023
1 parent e3b42f5 commit faa54d2
Show file tree
Hide file tree
Showing 37 changed files with 1,765 additions and 194 deletions.
11 changes: 7 additions & 4 deletions .envrc.example
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
# Mnemonic phrase
export MNEMONIC=""
# Wallet address for remote RPC calls
export SENDER=""

# Private key
export PRIVATE_KEY=""

# Wallet address sending the transactions
export SENDER=""
# Wallet address for local (below is default anvil settings)
export LOCAL_SENDER="0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"
export LOCAL_PRIVATE_KEY="0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"

export LOCAL_CODE_SIZE_LIMIT_BYTES=30000

# Mainnet RPC URLs
export MAINNET_RPC_URL=""
Expand Down
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v16.14.2
2 changes: 1 addition & 1 deletion .solhint.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"plugins": ["prettier"],
"rules": {
"avoid-low-level-calls": "off",
"compiler-version": ["error", "0.8.17"],
"compiler-version": ["error", "0.8.19"],
"func-visibility": "off",
"no-empty-blocks": "off",
"no-inline-assembly": "off"
Expand Down
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,20 @@ For the coverage to work, you will need to setup the `MAINNET_RPC_URL` repositor

## Deployment

First setup npm:

```
nvm use
yarn
```

### Local

Start `anvil` with the following command: `anvil -m $MNEMONIC`
Start anvil:

```
anvil --code-size-limit $LOCAL_CODE_SIZE_LIMIT_BYTES
```

In another terminal window, run the following command: `npm run deploy:contracts:local`

Expand Down
2 changes: 1 addition & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ src = 'src'
out = 'out'
test = 'test'
libs = ['lib']
solc = "0.8.17"
solc = "0.8.19"
fs_permissions = [{ access = "read", path = "./broadcast"}]
gas_reports = ["*"]

Expand Down
31 changes: 15 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,19 @@
"clean": "forge clean",
"compile": "forge compile",
"coverage": "forge coverage --report lcov && lcov --extract lcov.info -o lcov.info 'src/*' && genhtml lcov.info -o coverage",

"----------LOCAL-DEPLOYMENT-SCRIPTS----------": "",
"deploy:pool:local": "forge script script/deploy/DeployPool.s.sol:DeployPool --ffi --rpc-url http://localhost:8545 --sender $SENDER --broadcast",
"deploy:stable-token:local": "forge script script/deploy/DeployStableToken.s.sol:DeployStableToken --ffi --rpc-url http://localhost:8545 --sender $SENDER --broadcast",
"deploy:token:local": "forge script script/deploy/DeployToken.s.sol:DeployToken --ffi --rpc-url http://localhost:8545 --sender $SENDER --broadcast",
"deploy:set-token-price:local": "forge script script/deploy/SetTokenPrice.s.sol:SetTokenPrice --ffi --rpc-url http://localhost:8545 --sender $SENDER --broadcast",
"deploy:set-stable-token-role:local": "forge script script/deploy/SetStableTokenRole.s.sol:SetStableTokenRole --ffi --rpc-url http://localhost:8545 --sender $SENDER --broadcast",
"deploy:set-token-role:local": "forge script script/deploy/SetTokenRole.s.sol:SetTokenRole --ffi --rpc-url http://localhost:8545 --sender $SENDER --broadcast",
"deploy:yield-vault:local": "forge script script/deploy/DeployYieldVault.s.sol:DeployYieldVault --ffi --rpc-url http://localhost:8545 --sender $SENDER --broadcast",
"deploy:set-vault-role:local": "forge script script/deploy/SetVaultRole.s.sol:SetVaultRole --ffi --rpc-url http://localhost:8545 --sender $SENDER --broadcast",
"deploy:set-yield-vault-role:local": "forge script script/deploy/SetYieldVaultRole.s.sol:SetYieldVaultRole --ffi --rpc-url http://localhost:8545 --sender $SENDER --broadcast",
"deploy:vault:local": "forge script script/deploy/DeployVault.s.sol:DeployVault --ffi --rpc-url http://localhost:8545 --sender $SENDER --broadcast",
"deploy:pool:local": "forge script script/deploy/DeployPool.s.sol:DeployPool --code-size-limit $LOCAL_CODE_SIZE_LIMIT_BYTES --ffi --rpc-url http://localhost:8545 --private-key $LOCAL_PRIVATE_KEY --sender $LOCAL_SENDER --broadcast",
"deploy:stable-token:local": "forge script script/deploy/DeployStableToken.s.sol:DeployStableToken --code-size-limit $LOCAL_CODE_SIZE_LIMIT_BYTES --ffi --rpc-url http://localhost:8545 --private-key $LOCAL_PRIVATE_KEY --sender $LOCAL_SENDER --broadcast",
"deploy:token:local": "forge script script/deploy/DeployToken.s.sol:DeployToken --code-size-limit $LOCAL_CODE_SIZE_LIMIT_BYTES --ffi --rpc-url http://localhost:8545 --private-key $LOCAL_PRIVATE_KEY --sender $LOCAL_SENDER --broadcast",
"deploy:set-token-price:local": "forge script script/deploy/SetTokenPrice.s.sol:SetTokenPrice --code-size-limit $LOCAL_CODE_SIZE_LIMIT_BYTES --ffi --rpc-url http://localhost:8545 --private-key $LOCAL_PRIVATE_KEY --sender $LOCAL_SENDER --broadcast",
"deploy:set-stable-token-role:local": "forge script script/deploy/SetStableTokenRole.s.sol:SetStableTokenRole --code-size-limit $LOCAL_CODE_SIZE_LIMIT_BYTES --ffi --rpc-url http://localhost:8545 --private-key $LOCAL_PRIVATE_KEY --sender $LOCAL_SENDER --broadcast",
"deploy:set-token-role:local": "forge script script/deploy/SetTokenRole.s.sol:SetTokenRole --code-size-limit $LOCAL_CODE_SIZE_LIMIT_BYTES --ffi --rpc-url http://localhost:8545 --private-key $LOCAL_PRIVATE_KEY --sender $LOCAL_SENDER --broadcast",
"deploy:yield-vault:local": "forge script script/deploy/DeployYieldVault.s.sol:DeployYieldVault --code-size-limit $LOCAL_CODE_SIZE_LIMIT_BYTES --ffi --rpc-url http://localhost:8545 --private-key $LOCAL_PRIVATE_KEY --sender $LOCAL_SENDER --broadcast",
"deploy:set-vault-role:local": "forge script script/deploy/SetVaultRole.s.sol:SetVaultRole --code-size-limit $LOCAL_CODE_SIZE_LIMIT_BYTES --ffi --rpc-url http://localhost:8545 --private-key $LOCAL_PRIVATE_KEY --sender $LOCAL_SENDER --broadcast",
"deploy:set-yield-vault-role:local": "forge script script/deploy/SetYieldVaultRole.s.sol:SetYieldVaultRole --code-size-limit $LOCAL_CODE_SIZE_LIMIT_BYTES --ffi --rpc-url http://localhost:8545 --private-key $LOCAL_PRIVATE_KEY --sender $LOCAL_SENDER --broadcast",
"deploy:vault:local": "forge script script/deploy/DeployVault.s.sol:DeployVault --code-size-limit $LOCAL_CODE_SIZE_LIMIT_BYTES --ffi --rpc-url http://localhost:8545 --private-key $LOCAL_PRIVATE_KEY --sender $LOCAL_SENDER --broadcast",
"deploy:contracts:local": "npm run deploy:stable-token:local && npm run deploy:token:local && npm run deploy:pool:local && npm run deploy:yield-vault:local && npm run deploy:vault:local",
"deploy:config-contracts:local": "npm run deploy:set-token-price:local && npm run deploy:set-stable-token-role:local && npm run deploy:set-token-role:local && npm run deploy:set-vault-role:local && npm run deploy:set-yield-vault-role:local",

"----------ETH-GOERLI-DEPLOYMENT-SCRIPTS----------": "",
"deploy:pool:ethGoerli": "forge script script/deploy/DeployPool.s.sol:DeployPool --ffi --rpc-url $GOERLI_RPC_URL --sender $SENDER --broadcast --verify --etherscan-api-key $ETHERSCAN_API_KEY",
"deploy:stable-token:ethGoerli": "forge script script/deploy/DeployStableToken.s.sol:DeployStableToken --ffi --rpc-url $GOERLI_RPC_URL --sender $SENDER --broadcast --verify --etherscan-api-key $ETHERSCAN_API_KEY",
Expand All @@ -42,7 +40,6 @@
"deploy:vault:ethGoerli": "forge script script/deploy/DeployVault.s.sol:DeployVault --ffi --rpc-url $GOERLI_RPC_URL --sender $SENDER --broadcast --verify --etherscan-api-key $ETHERSCAN_API_KEY",
"deploy:contracts:ethGoerli": "npm run deploy:stable-token:ethGoerli && npm run deploy:token:ethGoerli && npm run deploy:pool:ethGoerli && npm run deploy:yield-vault:ethGoerli && npm run deploy:vault:ethGoerli",
"deploy:config-contracts:ethGoerli": "npm run deploy:set-token-price:ethGoerli && npm run deploy:set-stable-token-role:ethGoerli && npm run deploy:set-token-role:ethGoerli && npm run deploy:set-vault-role:ethGoerli && npm run deploy:set-yield-vault-role:ethGoerli",

"----------ETH-SEPOLIA-DEPLOYMENT-SCRIPTS----------": "",
"deploy:pool:ethSepolia": "forge script script/deploy/DeployPool.s.sol:DeployPool --ffi --rpc-url $SEPOLIA_RPC_URL --sender $SENDER --broadcast --verify --etherscan-api-key $ETHERSCAN_API_KEY",
"deploy:stable-token:ethSepolia": "forge script script/deploy/DeployStableToken.s.sol:DeployStableToken --ffi --rpc-url $SEPOLIA_RPC_URL --sender $SENDER --broadcast --verify --etherscan-api-key $ETHERSCAN_API_KEY",
Expand All @@ -56,7 +53,6 @@
"deploy:vault:ethSepolia": "forge script script/deploy/DeployVault.s.sol:DeployVault --ffi --rpc-url $SEPOLIA_RPC_URL --sender $SENDER --broadcast --verify --etherscan-api-key $ETHERSCAN_API_KEY",
"deploy:contracts:ethSepolia": "npm run deploy:stable-token:ethSepolia && npm run deploy:token:ethSepolia && npm run deploy:pool:ethSepolia && npm run deploy:yield-vault:ethSepolia && npm run deploy:vault:ethSepolia",
"deploy:config-contracts:ethSepolia": "npm run deploy:set-token-price:ethSepolia && npm run deploy:set-stable-token-role:ethSepolia && npm run deploy:set-token-role:ethSepolia && npm run deploy:set-vault-role:ethSepolia && npm run deploy:set-yield-vault-role:ethSepolia",

"----------MUMBAI-DEPLOYMENT-SCRIPTS----------": "",
"deploy:pool:mumbai": "forge script script/deploy/DeployPool.s.sol:DeployPool --ffi --rpc-url $POLYGON_MUMBAI_RPC_URL --sender $SENDER --broadcast --verify --etherscan-api-key $POLYGONSCAN_API_KEY",
"deploy:stable-token:mumbai": "forge script script/deploy/DeployStableToken.s.sol:DeployStableToken --ffi --rpc-url $POLYGON_MUMBAI_RPC_URL --sender $SENDER --broadcast --verify --etherscan-api-key $POLYGONSCAN_API_KEY",
Expand All @@ -70,7 +66,6 @@
"deploy:vault:mumbai": "forge script script/deploy/DeployVault.s.sol:DeployVault --ffi --rpc-url $POLYGON_MUMBAI_RPC_URL --sender $SENDER --broadcast --verify --etherscan-api-key $POLYGONSCAN_API_KEY",
"deploy:contracts:mumbai": "npm run deploy:stable-token:mumbai && npm run deploy:token:mumbai && npm run deploy:pool:mumbai && npm run deploy:yield-vault:mumbai && npm run deploy:vault:mumbai",
"deploy:config-contracts:mumbai": "npm run deploy:set-token-price:mumbai && npm run deploy:set-stable-token-role:mumbai && npm run deploy:set-token-role:mumbai && npm run deploy:set-vault-role:mumbai && npm run deploy:set-yield-vault-role:mumbai",

"format": "prettier --config .prettierrc --write \"**/*.{json,md,ts,sol,yml}\"",
"format:file": "prettier --config .prettierrc --write",
"gen:local": "ts-node ./script/utils/generateLocalList.ts",
Expand All @@ -93,5 +88,9 @@
"files": [
"src/**",
"out/**"
]
],
"dependencies": {
"@types/node": "^20.4.7",
"typescript": "^5.1.6"
}
}
5 changes: 3 additions & 2 deletions remappings.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
ds-test/=lib/forge-std/lib/ds-test/src/
forge-std/=lib/forge-std/src/
openzeppelin/=lib/openzeppelin-contracts/contracts/
prb-math/=lib/prb-math/src/
prb-math/=lib/pt-v5-cgda-liquidator/lib/prb-math/src/
solidity-stringutils/=lib/solidity-stringutils/src/

pt-v5-draw-auction/=lib/pt-v5-draw-auction/src/
pt-v5-cgda-liquidator/=lib/pt-v5-cgda-liquidator/src/
pt-v5-liquidator-interfaces/=lib/pt-v5-vault/lib/pt-v5-liquidator-interfaces/src/interfaces/
pt-v5-liquidator-interfaces/=lib/pt-v5-cgda-liquidator/lib/pt-v5-liquidator-interfaces/src/interfaces/
pt-v5-prize-pool/=lib/pt-v5-prize-pool/src/
pt-v5-twab-controller/=lib/pt-v5-prize-pool/lib/pt-v5-twab-controller/src/
pt-v5-vault/=lib/pt-v5-vault/src/
pt-v5-vault-mock/=lib/pt-v5-vault/test/contracts/mock/
pt-v5-claimer/=lib/pt-v5-claimer/src/
rng=lib/pt-v5-draw-auction/lib/pt-v5-rng-contracts/contracts/
53 changes: 40 additions & 13 deletions script/deploy/DeployPool.s.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.17;
pragma solidity 0.8.19;

import "forge-std/console2.sol";

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

Expand All @@ -14,6 +16,12 @@ import { LiquidationPairFactory } from "pt-v5-cgda-liquidator/LiquidationPairFac
import { LiquidationRouter } from "pt-v5-cgda-liquidator/LiquidationRouter.sol";
import { VaultFactory } from "pt-v5-vault/VaultFactory.sol";

import { RNGBlockhash } from "rng/RNGBlockhash.sol";
import { RNGInterface } from "rng/RNGInterface.sol";
import { RngAuction } from "pt-v5-draw-auction/RngAuction.sol";
import { RngAuctionRelayerDirect } from "pt-v5-draw-auction/RngAuctionRelayerDirect.sol";
import { RngRelayAuction } from "pt-v5-draw-auction/RngRelayAuction.sol";

import { ERC20Mintable } from "../../src/ERC20Mintable.sol";
import { VaultMintRate } from "../../src/VaultMintRate.sol";
import { ERC20, YieldVaultMintRate } from "../../src/YieldVaultMintRate.sol";
Expand All @@ -24,19 +32,39 @@ contract DeployPool is Helpers {
uint32 internal constant DRAW_PERIOD_SECONDS = 2 hours;

function run() public {
vm.startBroadcast(vm.envUint("PRIVATE_KEY"));
vm.startBroadcast();

ERC20Mintable prizeToken = _getToken("POOL", _tokenDeployPath);
TwabController twabController = new TwabController(1 days, uint32(block.timestamp));

uint64 firstDrawStartsAt = uint64(block.timestamp);
uint64 auctionDuration = DRAW_PERIOD_SECONDS / 4;
uint64 auctionTargetSaleTime = auctionDuration / 2;

console2.log("constructing rng stuff....");

RNGBlockhash rng = new RNGBlockhash();

RngAuction rngAuction = new RngAuction(
rng,
address(this),
DRAW_PERIOD_SECONDS,
firstDrawStartsAt,
auctionDuration,
auctionTargetSaleTime
);

RngAuctionRelayerDirect rngAuctionRelayerDirect = new RngAuctionRelayerDirect(rngAuction);

console2.log("constructing prize pool....");

PrizePool prizePool = new PrizePool(
ConstructorParams(
prizeToken,
twabController,
address(0),
uint16(7), // grand prize should occur every 3.5 days
DRAW_PERIOD_SECONDS,
uint64(block.timestamp), // drawStartedAt
firstDrawStartsAt, // drawStartedAt
uint8(3), // minimum number of tiers
100,
10,
Expand All @@ -46,17 +74,16 @@ contract DeployPool is Helpers {
)
);

if (block.chainid == 5) {
prizePool.setDrawManager(GOERLI_DEFENDER_ADDRESS);
}
console2.log("constructing auction....");

if (block.chainid == 11155111) {
prizePool.setDrawManager(SEPOLIA_DEFENDER_ADDRESS);
}
RngRelayAuction rngRelayAuction = new RngRelayAuction(
prizePool,
address(rngAuctionRelayerDirect),
auctionDuration,
auctionTargetSaleTime
);

if (block.chainid == 80001) {
prizePool.setDrawManager(MUMBAI_DEFENDER_ADDRESS);
}
prizePool.setDrawManager(address(rngRelayAuction));

new Claimer(prizePool, 0.0001e18, 1000e18, DRAW_PERIOD_SECONDS, ud2x18(0.5e18));

Expand Down
4 changes: 2 additions & 2 deletions script/deploy/DeployStableToken.s.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.17;
pragma solidity 0.8.19;

import { ERC20Mintable } from "../../src/ERC20Mintable.sol";
import { MarketRate } from "../../src/MarketRate.sol";
Expand Down Expand Up @@ -36,7 +36,7 @@ contract DeployStableToken is Helpers {
}

function run() public {
vm.startBroadcast(vm.envUint("PRIVATE_KEY"));
vm.startBroadcast();
_deployTokens();
vm.stopBroadcast();
}
Expand Down
4 changes: 2 additions & 2 deletions script/deploy/DeployToken.s.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.17;
pragma solidity 0.8.19;

import { ERC20Mintable } from "../../src/ERC20Mintable.sol";
import { TokenFaucet } from "../../src/TokenFaucet.sol";
Expand Down Expand Up @@ -36,7 +36,7 @@ contract DeployToken is Helpers {
}

function run() public {
vm.startBroadcast(vm.envUint("PRIVATE_KEY"));
vm.startBroadcast();
_deployTokens();
vm.stopBroadcast();
}
Expand Down
Loading

0 comments on commit faa54d2

Please sign in to comment.