sepolia redeploy
This commit is contained in:
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -1,17 +1,17 @@
|
||||
{
|
||||
"11155111": {
|
||||
"v1": {
|
||||
"PartyPlanner": "0x894611f1B772047DAF6d1F2d3B177b4b0d6b38b2",
|
||||
"PartyPoolViewer": "0xB5Fd1f912394a5C94bA2F9e30687e9c58a9d1e5b",
|
||||
"PartyPoolMintImpl": "0x6614909225Cd897220b64E7257030f74c35Bf8Da",
|
||||
"PartyPoolSwapImpl": "0x84F774D2203725720b22Df458a18e776394dAAff",
|
||||
"PartyPoolDeployer": "0x960226748e9447e5Cd0f42cc2BB3a996AaDA9a86",
|
||||
"PartyPoolBalancedPairDeployer": "0x3768e3333C6232e5186Bf9686E7cd02eefEf0f2e",
|
||||
"USXD": "",
|
||||
"FUSD": "",
|
||||
"DIVE": "",
|
||||
"BUTC": "",
|
||||
"WTETH": ""
|
||||
"PartyPlanner": "0x2954911231c44E49938b2FBd1e0cD2787FdF69AD",
|
||||
"PartyPoolViewer": "0x71b04a353a77405a3217EAF3A24BA619B86cD5E9",
|
||||
"PartyPoolMintImpl": "0x705272c50F905204187B3126701BeDEd82Dc2F9a",
|
||||
"PartyPoolSwapImpl": "0xC9608aAaF772c1cAce83C863e88EC4FF54017CeB",
|
||||
"PartyPoolDeployer": "0x6811C56804321F811eAFa3f7694b026d738Ba7a1",
|
||||
"PartyPoolBalancedPairDeployer": "0xc321406Fc8e174Bb0D006C145D515b858b1b883d",
|
||||
"USXD": "0x8E4D16886b8946dfE463fA172129eaBf4825fb09",
|
||||
"FUSD": "0xdc225280216822CA956738390f589c794129bd53",
|
||||
"DIVE": "0x7ba123e4e7395A361284d069bD0D545F3f820641",
|
||||
"BUTC": "0x88125947BBF1A6dd0FeD4B257BB3f9E1FBdCb3Cc",
|
||||
"WTETH": "0xC8dB65C0B9f4cf59097d4C5Bcb9e8E92B9e4e15F"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,12 +56,6 @@ interface IPartyPoolViewer {
|
||||
function burnSwapAmounts(IPartyPool pool, uint256 lpAmount, uint256 outputTokenIndex) external view
|
||||
returns (uint256 amountOut, uint256 outFee);
|
||||
|
||||
/// @notice Compute repayment amounts (principal + flash fee) for a proposed flash loan.
|
||||
/// @param loanAmounts array of per-token loan amounts; must match the pool's token ordering.
|
||||
/// @return repaymentAmounts array where repaymentAmounts[i] = loanAmounts[i] + ceil(loanAmounts[i] * flashFeePpm)
|
||||
function flashRepaymentAmounts(IPartyPool pool, uint256[] memory loanAmounts) external view
|
||||
returns (uint256[] memory repaymentAmounts);
|
||||
|
||||
/**
|
||||
* @dev The amount of currency available to be lent.
|
||||
* @param token The loan currency.
|
||||
|
||||
@@ -459,7 +459,7 @@ contract PartyPool is PartyPoolBase, OwnableExternal, ERC20External, IPartyPool
|
||||
|
||||
/// @notice Transfer all protocol fees to the configured protocolFeeAddress and zero the ledger.
|
||||
/// @dev Anyone can call; must have protocolFeeAddress != address(0) to be operational.
|
||||
function collectProtocolFees() external nonReentrant {
|
||||
function collectProtocolFees() external {
|
||||
bytes memory data = abi.encodeWithSelector(
|
||||
PartyPoolSwapImpl.collectProtocolFees.selector,
|
||||
protocolFeeAddress
|
||||
|
||||
@@ -132,23 +132,6 @@ contract PartyPoolViewer is PartyPoolHelpers, IPartyPoolViewer {
|
||||
}
|
||||
|
||||
|
||||
/// @notice Compute repayment amounts (principal + flash fee) for a proposed flash loan.
|
||||
/// @param loanAmounts array of per-token loan amounts; must match the pool's token ordering.
|
||||
/// @return repaymentAmounts array where repaymentAmounts[i] = loanAmounts[i] + ceil(loanAmounts[i] * flashFeePpm)
|
||||
function flashRepaymentAmounts(IPartyPool pool, uint256[] memory loanAmounts) external view
|
||||
returns (uint256[] memory repaymentAmounts) {
|
||||
LMSRStabilized.State memory lmsr = pool.LMSR();
|
||||
uint256 nAssets = lmsr.qInternal.length;
|
||||
repaymentAmounts = new uint256[](nAssets);
|
||||
for (uint256 i = 0; i < nAssets; i++) {
|
||||
uint256 amount = loanAmounts[i];
|
||||
if (amount > 0) {
|
||||
repaymentAmounts[i] = amount + _ceilFee(amount, pool.flashFeePpm());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @dev The amount of currency available to be lent.
|
||||
* @param token The loan currency.
|
||||
|
||||
21
test/MockFlashBorrower.sol
Normal file
21
test/MockFlashBorrower.sol
Normal file
@@ -0,0 +1,21 @@
|
||||
// SPDX-License-Identifier: UNLICENSED
|
||||
pragma solidity ^0.8.30;
|
||||
|
||||
import {IERC3156FlashBorrower} from "../lib/openzeppelin-contracts/contracts/interfaces/IERC3156FlashBorrower.sol";
|
||||
import {IERC20} from "../lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol";
|
||||
|
||||
// Minimal flash borrower that repays amount + fee back to the pool passed via data
|
||||
contract MockFlashBorrower is IERC3156FlashBorrower {
|
||||
// IERC3156FlashBorrower callback
|
||||
function onFlashLoan(
|
||||
address /*initiator*/,
|
||||
address token,
|
||||
uint256 amount,
|
||||
uint256 fee,
|
||||
bytes calldata data
|
||||
) external returns (bytes32) {
|
||||
address poolAddr = abi.decode(data, (address));
|
||||
IERC20(token).approve(poolAddr, amount + fee);
|
||||
return keccak256("ERC3156FlashBorrower.onFlashLoan");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user