This commit is contained in:
tim
2025-09-15 14:44:40 -04:00
parent 5fb2b17b2e
commit 77784644ad
4 changed files with 20 additions and 43 deletions

View File

@@ -33,15 +33,7 @@ while ! check_string "Listening on" "log/anvil.txt"; do
fi fi
done done
# Extract bytecode using jq forge script DeployMock --broadcast "$@"
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
echo "Press Ctrl+C to exit..." echo "Press Ctrl+C to exit..."
while true; do while true; do

View File

@@ -28,23 +28,20 @@ contract DeployMock is Script {
tokens[1] = address(fusd); tokens[1] = address(fusd);
tokens[2] = address(dive); tokens[2] = address(dive);
uint256[] memory _bases = new uint256[](3); uint256[] memory _bases = new uint256[](3);
_bases[0] = 6; _bases[0] = 10**6;
_bases[1] = 6; _bases[1] = 10**6;
_bases[2] = 18; _bases[2] = 10**18;
int128 _tradeFrac = ABDKMath64x64.divu(1, 10); int128 _tradeFrac = ABDKMath64x64.divu(1, 10);
int128 _targetSlippage = ABDKMath64x64.divu(1,10000); int128 _targetSlippage = ABDKMath64x64.divu(1,10000);
uint256 _feePpm = 100; uint256 _feePpm = 100;
IPartyPool pool = new PartyPool(); IPartyPool pool = new PartyPool(name, symbol, tokens, _bases, _tradeFrac, _targetSlippage, _feePpm, _feePpm);
bytes memory args = abi.encode(name, symbol, tokens, _bases, _tradeFrac, _targetSlippage, _feePpm);
bytes memory deployCode = abi.encodePacked(bytecode,args);
vm.etch(pool, deployCode);
console2.log('PartyPool', pool); console2.log('PartyPool', address(pool));
// initial mint // initial mint
mintAll(pool, 10_000); mintAll(address(pool), 10_000);
IPartyPool(pool).mint(deployer, deployer, 0, 0); pool.mint(deployer, deployer, 0, 0);
console2.log('USXD', address(usxd)); console2.log('USXD', address(usxd));
console2.log('FUSD', address(fusd)); console2.log('FUSD', address(fusd));

View File

@@ -1,6 +1,7 @@
// SPDX-License-Identifier: UNLICENSED // SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.30; pragma solidity ^0.8.30;
import "forge-std/console2.sol";
import "@abdk/ABDKMath64x64.sol"; import "@abdk/ABDKMath64x64.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.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; bool isInitialDeposit = totalSupply() == 0 || lmsr.nAssets == 0;
require(lpTokenAmount > 0 || isInitialDeposit, "mint: zero LP amount"); 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 // Capture old pool size metric (scaled) by computing from current balances
uint256 oldScaled = 0; uint256 oldScaled = 0;
@@ -199,22 +201,31 @@ contract PartyPool is IPartyPool, ERC20, ReentrancyGuard {
} }
// Update cached balances for all assets // Update cached balances for all assets
console2.log('updating balances');
int128[] memory newQInternal = new int128[](n); int128[] memory newQInternal = new int128[](n);
for (uint i = 0; i < n; ) { for (uint i = 0; i < n; ) {
console2.log(i);
uint256 bal = IERC20(tokens[i]).balanceOf(address(this)); uint256 bal = IERC20(tokens[i]).balanceOf(address(this));
cachedUintBalances[i] = bal; cachedUintBalances[i] = bal;
console2.log('floor');
console2.log(bal);
console2.log(bases[i]);
newQInternal[i] = _uintToInternalFloor(bal, bases[i]); newQInternal[i] = _uintToInternalFloor(bal, bases[i]);
console2.log('internal');
// For initial deposit, record the actual deposited amounts // For initial deposit, record the actual deposited amounts
if (isInitialDeposit) { if (isInitialDeposit) {
depositAmounts[i] = bal; depositAmounts[i] = bal;
} }
console2.log('inc');
unchecked { i++; } unchecked { i++; }
} }
console2.log('balances updated');
// If first time, call init, otherwise update proportional change. // If first time, call init, otherwise update proportional change.
if (isInitialDeposit) { if (isInitialDeposit) {
console2.log('init lmsr');
// Initialize the stabilized LMSR state // Initialize the stabilized LMSR state
lmsr.init(newQInternal, tradeFrac, targetSlippage); lmsr.init(newQInternal, tradeFrac, targetSlippage);
} else { } else {
@@ -231,6 +242,7 @@ contract PartyPool is IPartyPool, ERC20, ReentrancyGuard {
if (isInitialDeposit) { if (isInitialDeposit) {
// Initial provisioning: mint newScaled (as LP units) // Initial provisioning: mint newScaled (as LP units)
actualLpToMint = newScaled; actualLpToMint = newScaled;
console2.log('initial mint', actualLpToMint);
} else { } else {
require(oldScaled > 0, "mint: oldScaled zero"); require(oldScaled > 0, "mint: oldScaled zero");
uint256 delta = (newScaled > oldScaled) ? (newScaled - oldScaled) : 0; uint256 delta = (newScaled > oldScaled) ? (newScaled - oldScaled) : 0;

View File

@@ -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);
}
}