sepolia redeploy
This commit is contained in:
@@ -1,14 +1,26 @@
|
||||
// SPDX-License-Identifier: UNLICENSED
|
||||
pragma solidity ^0.8.30;
|
||||
|
||||
import "../test/Deploy.sol";
|
||||
import "../src/IPartyPool.sol";
|
||||
import "../src/PartyPlanner.sol";
|
||||
import "../src/PartyPool.sol";
|
||||
import "../test/MockERC20.sol";
|
||||
import "@abdk/ABDKMath64x64.sol";
|
||||
import "forge-std/Script.sol";
|
||||
import "forge-std/console2.sol";
|
||||
import {ABDKMath64x64} from "../lib/abdk-libraries-solidity/ABDKMath64x64.sol";
|
||||
import {CommonBase} from "../lib/forge-std/src/Base.sol";
|
||||
import {Script} from "../lib/forge-std/src/Script.sol";
|
||||
import {StdChains} from "../lib/forge-std/src/StdChains.sol";
|
||||
import {StdCheatsSafe} from "../lib/forge-std/src/StdCheats.sol";
|
||||
import {StdUtils} from "../lib/forge-std/src/StdUtils.sol";
|
||||
import {IERC3156FlashBorrower} from "../lib/openzeppelin-contracts/contracts/interfaces/IERC3156FlashBorrower.sol";
|
||||
import {IERC20} from "../lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol";
|
||||
import {IPartyPool} from "../src/IPartyPool.sol";
|
||||
import {IPartyPoolViewer} from "../src/IPartyPoolViewer.sol";
|
||||
import {LMSRStabilized} from "../src/LMSRStabilized.sol";
|
||||
import {NativeWrapper} from "../src/NativeWrapper.sol";
|
||||
import {PartyPlanner} from "../src/PartyPlanner.sol";
|
||||
import {PartyPoolDeployer, PartyPoolBalancedPairDeployer} from "../src/PartyPoolDeployer.sol";
|
||||
import {PartyPoolMintImpl} from "../src/PartyPoolMintImpl.sol";
|
||||
import {PartyPoolSwapImpl} from "../src/PartyPoolSwapImpl.sol";
|
||||
import {PartyPoolViewer} from "../src/PartyPoolViewer.sol";
|
||||
import {MockERC20} from "../test/MockERC20.sol";
|
||||
import {MockFlashBorrower} from "../test/MockFlashBorrower.sol";
|
||||
|
||||
contract DeploySepolia is Script {
|
||||
|
||||
@@ -32,6 +44,14 @@ contract DeploySepolia is Script {
|
||||
dive = MockERC20(0x7ba123e4e7395A361284d069bD0D545F3f820641);
|
||||
butc = MockERC20(0x88125947BBF1A6dd0FeD4B257BB3f9E1FBdCb3Cc);
|
||||
wteth = MockERC20(0xC8dB65C0B9f4cf59097d4C5Bcb9e8E92B9e4e15F);
|
||||
vm.label(address(usxd), 'USXD');
|
||||
vm.label(address(fusd), 'FUSD');
|
||||
vm.label(address(dive), 'DIVE');
|
||||
vm.label(address(butc), 'BUTC');
|
||||
vm.label(address(wteth), 'WTETH');
|
||||
|
||||
// give tokens to msg.sender for later use
|
||||
mintAll(msg.sender, 1_000_000);
|
||||
|
||||
PartyPoolSwapImpl swapImpl = new PartyPoolSwapImpl(WETH);
|
||||
PartyPoolMintImpl mintImpl = new PartyPoolMintImpl(WETH);
|
||||
@@ -50,6 +70,8 @@ contract DeploySepolia is Script {
|
||||
PROTOCOL_FEE_ADDRESS
|
||||
);
|
||||
|
||||
approveAll(address(planner) );
|
||||
|
||||
//
|
||||
// Deploy 3-asset pool
|
||||
//
|
||||
@@ -63,27 +85,29 @@ contract DeploySepolia is Script {
|
||||
_bases[0] = 10**6;
|
||||
_bases[1] = 10**8;
|
||||
_bases[2] = 10**18;
|
||||
uint256[] memory _feesPpm = new uint256[](3);
|
||||
_feesPpm[0] = 50;
|
||||
_feesPpm[1] = 250;
|
||||
_feesPpm[2] = 350;
|
||||
uint256[] memory _prices = new uint256[](3);
|
||||
_prices[0] = 1;
|
||||
_prices[1] = 100000;
|
||||
_prices[2] = 4000;
|
||||
|
||||
// mint _tokens to the deployer so it can fund the initial deposits and approve the factory
|
||||
// mintAll(msg.sender, 10_000);
|
||||
// prepare initial deposits (10_000 units of each token, scaled by _bases)
|
||||
uint256[] memory initialDeposits = new uint256[](3);
|
||||
initialDeposits[0] = _bases[0] * 10_000;
|
||||
initialDeposits[1] = _bases[1] * 10_000;
|
||||
initialDeposits[2] = _bases[2] * 10_000;
|
||||
// approve factory to move initial deposits
|
||||
for (uint i = 0; i < tokens.length; i++) {
|
||||
IERC20(tokens[i]).approve(address(planner), initialDeposits[i]);
|
||||
}
|
||||
initialDeposits[0] = 10_000 * _bases[0] / _prices[0];
|
||||
initialDeposits[1] = 10_000 * _bases[1] / _prices[1];
|
||||
initialDeposits[2] = 10_000 * _bases[2] / _prices[2];
|
||||
int128 kappa = LMSRStabilized.computeKappaFromSlippage(3, ABDKMath64x64.divu(1, 10), ABDKMath64x64.divu(50,10000));
|
||||
|
||||
// call full newPool signature on factory which will take the deposits and mint initial LP
|
||||
planner.newPool(
|
||||
(IPartyPool exercisePool,) = planner.newPool(
|
||||
'Token Pool',
|
||||
'TP',
|
||||
tokens,
|
||||
ABDKMath64x64.divu(1, 10),
|
||||
ABDKMath64x64.divu(1,10000),
|
||||
_feePpm,
|
||||
kappa,
|
||||
_feesPpm,
|
||||
_feePpm,
|
||||
false,
|
||||
msg.sender, // payer: this script
|
||||
@@ -108,17 +132,11 @@ contract DeploySepolia is Script {
|
||||
_bases[1] = 10**6;
|
||||
_bases[2] = 10**18;
|
||||
|
||||
// mint _tokens to the deployer so it can fund the initial deposits and approve the factory
|
||||
// mintAll(msg.sender, 10_000);
|
||||
// prepare initial deposits (10_000 units of each token, scaled by _bases)
|
||||
initialDeposits = new uint256[](3);
|
||||
initialDeposits[0] = _bases[0] * 10_000;
|
||||
initialDeposits[1] = _bases[1] * 10_000;
|
||||
initialDeposits[2] = _bases[2] * 10_000;
|
||||
// approve factory to move initial deposits
|
||||
for (uint i = 0; i < tokens.length; i++) {
|
||||
IERC20(tokens[i]).approve(address(planner), initialDeposits[i]);
|
||||
}
|
||||
|
||||
// call full newPool signature on factory which will take the deposits and mint initial LP
|
||||
planner.newPool(
|
||||
@@ -150,16 +168,10 @@ contract DeploySepolia is Script {
|
||||
_bases[0] = 10**6;
|
||||
_bases[1] = 10**18;
|
||||
|
||||
// mint _tokens to the deployer so it can fund the initial deposits and approve the factory
|
||||
// mintAll(msg.sender, 10_000);
|
||||
// prepare initial deposits (10_000 units of each token, scaled by _bases)
|
||||
initialDeposits = new uint256[](2);
|
||||
initialDeposits[0] = _bases[0] * 10_000;
|
||||
initialDeposits[1] = _bases[1] * 10_000;
|
||||
// approve factory to move initial deposits
|
||||
for (uint i = 0; i < tokens.length; i++) {
|
||||
IERC20(tokens[i]).approve(address(planner), initialDeposits[i]);
|
||||
}
|
||||
|
||||
// call full newPool signature on factory which will take the deposits and mint initial LP
|
||||
planner.newPool(
|
||||
@@ -179,8 +191,7 @@ contract DeploySepolia is Script {
|
||||
|
||||
PartyPoolViewer viewer = new PartyPoolViewer(swapImpl, mintImpl);
|
||||
|
||||
// give tokens to msg.sender for later use
|
||||
// mintAll(msg.sender, 1_000_000);
|
||||
exercise(exercisePool, viewer);
|
||||
|
||||
vm.stopBroadcast();
|
||||
|
||||
@@ -224,4 +235,59 @@ contract DeploySepolia is Script {
|
||||
wteth.mint(who, amount * 1e18);
|
||||
}
|
||||
|
||||
function approveAll(address spender) internal {
|
||||
usxd.approve(spender, type(uint256).max);
|
||||
fusd.approve(spender, type(uint256).max);
|
||||
dive.approve(spender, type(uint256).max);
|
||||
butc.approve(spender, type(uint256).max);
|
||||
wteth.approve(spender, type(uint256).max);
|
||||
}
|
||||
|
||||
function exercise( IPartyPool pool, IPartyPoolViewer viewer ) internal {
|
||||
// gather tokens and denominators
|
||||
IERC20[] memory tokens = pool.allTokens();
|
||||
uint256 n = tokens.length;
|
||||
|
||||
approveAll(address(pool));
|
||||
|
||||
// 1) Proportional mint (request some LP)
|
||||
uint256 lpToMint = 1_234; // arbitrary non-even amount
|
||||
// payer = this contract, receiver = this contract
|
||||
pool.mint(msg.sender, msg.sender, lpToMint, 0);
|
||||
|
||||
// 2) Proportional burn (withdraw a small, non-even amount of LP)
|
||||
uint256 lpToBurn = 7;
|
||||
pool.burn(msg.sender, msg.sender, lpToBurn, 0, false);
|
||||
|
||||
// 3) Flash loan: borrow token 0 and immediately repay in callback
|
||||
// deploy a temporary borrower that repays amount + fee back to the pool
|
||||
MockFlashBorrower borrower = new MockFlashBorrower();
|
||||
uint256 flashAmt = 53 * 10**6; // arbitrary non-even amount
|
||||
uint256 flashFee = viewer.flashFee(pool, address(tokens[0]), flashAmt);
|
||||
// Mint enough to cover the flash fee
|
||||
MockERC20(address(tokens[0])).mint(address(borrower), flashFee);
|
||||
// pass the pool address in data so borrower can repay back to this pool
|
||||
bytes memory data = abi.encode(address(pool));
|
||||
// call flashLoan (ignore success boolean/revert)
|
||||
pool.flashLoan(IERC3156FlashBorrower(address(borrower)), address(tokens[0]), flashAmt, data);
|
||||
|
||||
// 4) swapMint (single-token mint -> LP)
|
||||
uint256 swapMintAmt = 321 * 10**6; // not even
|
||||
pool.swapMint(msg.sender, msg.sender, 0, swapMintAmt, 0);
|
||||
|
||||
// 5) regular swap (token 0 -> last token)
|
||||
uint256 inputIndex = 0;
|
||||
uint256 outputIndex = n > 1 ? n - 1 : 0;
|
||||
uint256 maxIn = 89 * 10**6; // varied
|
||||
pool.swap(msg.sender, msg.sender, inputIndex, outputIndex, maxIn, int128(0), 0, false);
|
||||
|
||||
// 6) Collect protocol fees now (after some swaps) so some will have been moved out
|
||||
pool.collectProtocolFees();
|
||||
|
||||
// 7) Final swap-style operation: burnSwap (burn LP then swap to single asset)
|
||||
// ensure we have some LP allowance
|
||||
uint256 lpForBurnSwap = 3; // non-even small amount
|
||||
uint256 burnToIndex = (n > 1) ? 1 : 0;
|
||||
pool.burnSwap(msg.sender, msg.sender, lpForBurnSwap, burnToIndex, 0, false);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user