-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add script file * feat: script can be run successfully * script: some basic setting up * git: add /broadcast to gitignore * script: create one more pair * docs: add README section for instructions to use script * refactor: rename functions * fix: add assertion to script * refactor: function names * script: use private key for broadcast * lib: update v3-core commit * script: deploy our dummy tokens * enable stable pair deploy * ci: disable coverage step * script: use create2 to deploy router and quoter for stable addresses * fix: change tokens to those we control * fix: comment out wrapping AVAX as we might not have enough * script: split into reliable txs and problematic ones * fix: use more secure method of reading private key from env * refactor: make pair address a member variable * lib: update v3-core version * feat: creating a StablePair now works * feat: approve router for spending * feat: deploy second pair with WAVAX * feat: use AVAX mainnet WAVAX address * test: add test for case where attempting to remove liq for a pair that doesn't exist * script: update deployed contract addresses * test: update gas snapshot * test: update gas snapshot --------- Co-authored-by: OliverNChalk <[email protected]>
- Loading branch information
Showing
10 changed files
with
285 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
/cache | ||
/out | ||
/node_modules | ||
/broadcast | ||
|
||
# slither | ||
/slither-report.md | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule v3-core
updated
from de1cc4 to b89900
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.0; | ||
|
||
import "v3-core/scripts/BaseScript.sol"; | ||
|
||
import { FactoryStoreLib } from "v3-core/src/libraries/FactoryStore.sol"; | ||
import { ConstantsLib } from "v3-core/src/libraries/Constants.sol"; | ||
import { StablePair } from "v3-core/src/curve/stable/StablePair.sol"; | ||
import { StableMintBurn } from "v3-core/src/curve/stable/StableMintBurn.sol"; | ||
import { MintableERC20 } from "v3-core/test/__fixtures/MintableERC20.sol"; | ||
|
||
uint256 constant DEFAULT_SWAP_FEE_SP = 100; // 0.01% | ||
uint256 constant DEFAULT_AMP_COEFF = 1000; | ||
|
||
contract DeployStablePair is BaseScript { | ||
using FactoryStoreLib for GenericFactory; | ||
|
||
// default private key from anvil | ||
uint256 private _defaultPrivateKey = vm.envUint("PRIVATE_KEY"); | ||
address private _walletAddress; | ||
|
||
address private _deployedUSDC = 0x5D60473C5Cb323032d6fdFf42380B50E2AE4d245; | ||
address private _deployedUSDT = 0x6e9FDaE1Fe20b0A5a605C879Ae14030a0aE99cF9; | ||
address private _router = 0x7F05c63dC7CA3F99f2d3409f0017C28058C42B27; | ||
|
||
StablePair internal _sp1; | ||
|
||
function _createStablePair() private { | ||
vm.startBroadcast(_defaultPrivateKey); | ||
// add stable curve | ||
_factory.addCurve(type(StablePair).creationCode); | ||
_factory.write("SP::swapFee", DEFAULT_SWAP_FEE_SP); | ||
_factory.write("SP::amplificationCoefficient", DEFAULT_AMP_COEFF); | ||
|
||
_factory.addBytecode(type(StableMintBurn).creationCode); | ||
address lStableMintBurn = _factory.deploySharedContract(ConstantsLib.MINT_BURN_KEY, _deployedUSDC, _deployedUSDT); | ||
_factory.write("SP::STABLE_MINT_BURN", lStableMintBurn); | ||
|
||
_sp1 = StablePair(_factory.createPair(_deployedUSDC, _deployedUSDT, 1)); | ||
MintableERC20(_deployedUSDC).mint(address(_sp1), 948_192_492_581); | ||
MintableERC20(_deployedUSDT).mint(address(_sp1), 1_140_591_501_001); | ||
_sp1.mint(_walletAddress); | ||
require(_sp1.balanceOf(_walletAddress) > 0, "INSUFFICIENT LIQ"); | ||
|
||
_sp1.approve(_router, type(uint256).max); | ||
|
||
// _factory.createPair(WAVAX_AVAX_MAINNET, USDC_AVAX_MAINNET, 1); | ||
vm.stopBroadcast(); | ||
} | ||
|
||
function run() external { | ||
_walletAddress = vm.rememberKey(_defaultPrivateKey); | ||
_setup(_defaultPrivateKey); | ||
_createStablePair(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0xfca7c68f711102d77ab0a2765cee66cea90b7f07334352820e7ebf31c0ef3acf | ||
0xf629f8de34ecb99dffcf69ea812ed1fdbba96bee14757da972c41f5b986fc74d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.0; | ||
|
||
import { WETH } from "solmate/tokens/WETH.sol"; | ||
|
||
import "v3-core/scripts/BaseScript.sol"; | ||
import { ConstantProductPair } from "v3-core/src/curve/constant-product/ConstantProductPair.sol"; | ||
import { FactoryStoreLib } from "v3-core/src/libraries/FactoryStore.sol"; | ||
import { MintableERC20 } from "v3-core/test/__fixtures/MintableERC20.sol"; | ||
|
||
import { ReservoirRouter } from "src/ReservoirRouter.sol"; | ||
import { Quoter } from "src/Quoter.sol"; | ||
|
||
uint256 constant INITIAL_MINT_AMOUNT = 100e18; | ||
uint256 constant DEFAULT_SWAP_FEE_CP = 3000; // 0.3% | ||
uint256 constant DEFAULT_PLATFORM_FEE = 250_000; // 25% | ||
uint256 constant DEFAULT_MAX_CHANGE_RATE = 0.0005e18; | ||
|
||
contract SetupScaffold is BaseScript { | ||
using FactoryStoreLib for GenericFactory; | ||
|
||
address payable private constant AVAX_MAINNET_WAVAX = payable(0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7); | ||
|
||
ReservoirRouter private _router; | ||
Quoter private _quoter; | ||
|
||
MintableERC20 internal _usdc; | ||
MintableERC20 internal _usdt; | ||
WETH internal _wavax = WETH(AVAX_MAINNET_WAVAX); | ||
ConstantProductPair internal _cp1; | ||
ConstantProductPair internal _cp2; | ||
|
||
// default private key from anvil | ||
uint256 private _defaultPrivateKey = vm.envUint("PRIVATE_KEY"); | ||
address private _walletAddress; | ||
|
||
function _deployInfra() private { | ||
vm.startBroadcast(_defaultPrivateKey); | ||
_usdc = new MintableERC20("USD Circle", "USDC", 6); | ||
_usdt = new MintableERC20("USD Tether", "USDT", 6); | ||
// _wavax = new WETH(); | ||
vm.stopBroadcast(); | ||
} | ||
|
||
function _deployCore() private { | ||
_setup(_defaultPrivateKey); | ||
|
||
vm.startBroadcast(_defaultPrivateKey); | ||
// set shared variables | ||
_factory.write("Shared::platformFee", DEFAULT_PLATFORM_FEE); | ||
// _factory.write("Shared::platformFeeTo", _platformFeeTo); | ||
// _factory.write("Shared::defaultRecoverer", _recoverer); | ||
_factory.write("Shared::maxChangeRate", DEFAULT_MAX_CHANGE_RATE); | ||
|
||
// add constant product curve | ||
_factory.addCurve(type(ConstantProductPair).creationCode); | ||
_factory.write("CP::swapFee", DEFAULT_SWAP_FEE_CP); | ||
|
||
vm.stopBroadcast(); | ||
} | ||
|
||
function _deployPeriphery() private { | ||
|
||
_router = ReservoirRouter( | ||
payable( | ||
Create2Lib.computeAddress( | ||
CREATE2_FACTORY, | ||
abi.encodePacked(type(ReservoirRouter).creationCode, abi.encode(address(_factory), address(_wavax))), | ||
bytes32(uint256(0)) | ||
) | ||
) | ||
); | ||
if (address(_router).code.length == 0) { | ||
vm.broadcast(_defaultPrivateKey); | ||
ReservoirRouter lRouter = new ReservoirRouter{salt: bytes32(uint256(0))}(address(_factory), address(_wavax)); | ||
|
||
require(lRouter == _router, "Create2 Address Mismatch for ReservoirRouter"); | ||
} | ||
|
||
_quoter = Quoter( | ||
Create2Lib.computeAddress( | ||
CREATE2_FACTORY, | ||
abi.encodePacked(type(Quoter).creationCode, abi.encode(address(_factory), address(_wavax))), | ||
bytes32(uint256(0)) | ||
) | ||
); | ||
if (address(_quoter).code.length == 0) { | ||
vm.broadcast(_defaultPrivateKey); | ||
Quoter lQuoter = new Quoter{salt: bytes32(uint256(0))}(address(_factory), address(_wavax)); | ||
|
||
require(lQuoter == _quoter, "Create2 Address mismatch for Quoter"); | ||
} | ||
} | ||
|
||
function _getRich() private { | ||
uint256 lAmtToWrap = 1 ether; | ||
vm.startBroadcast(_defaultPrivateKey); | ||
_usdc.mint(_walletAddress, 1_000_000e6); | ||
_usdt.mint(_walletAddress, 1_000_000e6); | ||
_wavax.deposit{value: lAmtToWrap}(); | ||
require(_wavax.balanceOf(_walletAddress) == lAmtToWrap, "WAVAX AMT WRONG"); | ||
vm.stopBroadcast(); | ||
} | ||
|
||
function _deployPairs() private { | ||
vm.startBroadcast(_defaultPrivateKey); | ||
_cp1 = ConstantProductPair(_factory.createPair(address(_usdt), address(_usdc), 0)); | ||
_usdc.mint(address(_cp1), 1_000_000e6); | ||
_usdt.mint(address(_cp1), 950_000e6); | ||
_cp1.mint(_walletAddress); | ||
|
||
_cp2 = ConstantProductPair(_factory.createPair(address(_wavax), address(_usdc), 0)); | ||
_usdc.mint(address(_cp2), 103_392_049_192); | ||
_wavax.transfer(address(_cp2), 302_291_291_321_201_392); | ||
_cp2.mint(_walletAddress); | ||
|
||
require(_cp1.balanceOf(_walletAddress) > 0, "INSUFFICIENT LIQ"); | ||
require(_cp2.balanceOf(_walletAddress) > 0, "INSUFFICIENT LIQ"); | ||
vm.stopBroadcast(); | ||
} | ||
|
||
function _approveRouter() private { | ||
vm.startBroadcast(_defaultPrivateKey); | ||
_usdc.approve(address(_router), type(uint256).max); | ||
_usdt.approve(address(_router), type(uint256).max); | ||
_wavax.approve(address(_router), type(uint256).max); | ||
_cp1.approve(address(_router), type(uint256).max); | ||
_cp2.approve(address(_router), type(uint256).max); | ||
vm.stopBroadcast(); | ||
} | ||
|
||
function run() external { | ||
_walletAddress = vm.rememberKey(_defaultPrivateKey); | ||
_deployInfra(); | ||
_deployCore(); | ||
_deployPeriphery(); | ||
_getRich(); | ||
_deployPairs(); | ||
_approveRouter(); | ||
} | ||
} |
Oops, something went wrong.