diff --git a/bin/mock b/bin/mock index a9db798..0ae6735 100755 --- a/bin/mock +++ b/bin/mock @@ -33,15 +33,7 @@ while ! check_string "Listening on" "log/anvil.txt"; do fi done -# Extract bytecode using jq -BYTECODE=$(jq -r '.bytecode.object' out/PartyPool.sol/PartyPool.json) -if [ $? -ne 0 ] || [ -z "$BYTECODE" ]; then - echo "Failed to extract bytecode from PartyPool.json" - exit 1 -fi - -export BYTECODE -forge script DeployMock --broadcast +forge script DeployMock --broadcast "$@" echo "Press Ctrl+C to exit..." while true; do diff --git a/script/DeployMock.sol b/script/DeployMock.sol index 53c7c31..4bf98bf 100644 --- a/script/DeployMock.sol +++ b/script/DeployMock.sol @@ -28,23 +28,20 @@ contract DeployMock is Script { tokens[1] = address(fusd); tokens[2] = address(dive); uint256[] memory _bases = new uint256[](3); - _bases[0] = 6; - _bases[1] = 6; - _bases[2] = 18; + _bases[0] = 10**6; + _bases[1] = 10**6; + _bases[2] = 10**18; int128 _tradeFrac = ABDKMath64x64.divu(1, 10); int128 _targetSlippage = ABDKMath64x64.divu(1,10000); uint256 _feePpm = 100; - IPartyPool pool = new PartyPool(); - bytes memory args = abi.encode(name, symbol, tokens, _bases, _tradeFrac, _targetSlippage, _feePpm); - bytes memory deployCode = abi.encodePacked(bytecode,args); - vm.etch(pool, deployCode); + IPartyPool pool = new PartyPool(name, symbol, tokens, _bases, _tradeFrac, _targetSlippage, _feePpm, _feePpm); - console2.log('PartyPool', pool); + console2.log('PartyPool', address(pool)); // initial mint - mintAll(pool, 10_000); - IPartyPool(pool).mint(deployer, deployer, 0, 0); + mintAll(address(pool), 10_000); + pool.mint(deployer, deployer, 0, 0); console2.log('USXD', address(usxd)); console2.log('FUSD', address(fusd)); diff --git a/src/PartyPool.sol b/src/PartyPool.sol index 3e02668..2930284 100644 --- a/src/PartyPool.sol +++ b/src/PartyPool.sol @@ -1,6 +1,7 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.30; +import "forge-std/console2.sol"; import "@abdk/ABDKMath64x64.sol"; import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; @@ -174,6 +175,7 @@ contract PartyPool is IPartyPool, ERC20, ReentrancyGuard { bool isInitialDeposit = totalSupply() == 0 || lmsr.nAssets == 0; require(lpTokenAmount > 0 || isInitialDeposit, "mint: zero LP amount"); + console2.log('mint is init?', isInitialDeposit); // Capture old pool size metric (scaled) by computing from current balances uint256 oldScaled = 0; @@ -199,22 +201,31 @@ contract PartyPool is IPartyPool, ERC20, ReentrancyGuard { } // Update cached balances for all assets + console2.log('updating balances'); int128[] memory newQInternal = new int128[](n); for (uint i = 0; i < n; ) { + console2.log(i); uint256 bal = IERC20(tokens[i]).balanceOf(address(this)); cachedUintBalances[i] = bal; + console2.log('floor'); + console2.log(bal); + console2.log(bases[i]); newQInternal[i] = _uintToInternalFloor(bal, bases[i]); + console2.log('internal'); // For initial deposit, record the actual deposited amounts if (isInitialDeposit) { depositAmounts[i] = bal; } + console2.log('inc'); unchecked { i++; } } + console2.log('balances updated'); // If first time, call init, otherwise update proportional change. if (isInitialDeposit) { + console2.log('init lmsr'); // Initialize the stabilized LMSR state lmsr.init(newQInternal, tradeFrac, targetSlippage); } else { @@ -231,6 +242,7 @@ contract PartyPool is IPartyPool, ERC20, ReentrancyGuard { if (isInitialDeposit) { // Initial provisioning: mint newScaled (as LP units) actualLpToMint = newScaled; + console2.log('initial mint', actualLpToMint); } else { require(oldScaled > 0, "mint: oldScaled zero"); uint256 delta = (newScaled > oldScaled) ? (newScaled - oldScaled) : 0; diff --git a/test/Counter.t.sol b/test/Counter.t.sol deleted file mode 100644 index 4831910..0000000 --- a/test/Counter.t.sol +++ /dev/null @@ -1,24 +0,0 @@ -// SPDX-License-Identifier: UNLICENSED -pragma solidity ^0.8.13; - -import {Test} from "forge-std/Test.sol"; -import {Counter} from "../src/Counter.sol"; - -contract CounterTest is Test { - Counter public counter; - - function setUp() public { - counter = new Counter(); - counter.setNumber(0); - } - - function test_Increment() public { - counter.increment(); - assertEq(counter.number(), 1); - } - - function testFuzz_SetNumber(uint256 x) public { - counter.setNumber(x); - assertEq(counter.number(), x); - } -}