fixed-b
This commit is contained in:
@@ -114,6 +114,22 @@ contract GasTest is Test {
|
||||
uint256 constant internal INIT_BAL = 1_000_000; // initial token units for each token (internal==amount when base==1)
|
||||
uint256 constant internal BASE = 1; // use base=1 so internal amounts correspond to raw integers (Q64.64 units)
|
||||
|
||||
// Compute fixed b from a target slippage profile for a pool that will be initialized
|
||||
// with numTokens tokens each deposited with INIT_BAL and BASE==1.
|
||||
function _computeFixedB(uint256 numTokens) internal view returns (int128) {
|
||||
// Size metric S = sum q_i (in 64.64) with q_i = INIT_BAL for each token (BASE == 1)
|
||||
int128 S = ABDKMath64x64.fromUInt(numTokens * INIT_BAL);
|
||||
// E = (1 - s*(n-1)) / (1 + s)
|
||||
int128 one = ABDKMath64x64.fromInt(1);
|
||||
int128 nMinus1 = ABDKMath64x64.fromUInt(numTokens - 1);
|
||||
int128 numerator = one.sub(targetSlippage.mul(nMinus1));
|
||||
int128 denominator = one.add(targetSlippage);
|
||||
int128 E = numerator.div(denominator);
|
||||
// y = -ln(E) / f, b = S / y
|
||||
int128 y = ABDKMath64x64.ln(E).neg().div(tradeFrac);
|
||||
return S.div(y);
|
||||
}
|
||||
|
||||
/// @notice Helper function to create a pool with the specified number of _tokens
|
||||
function createPool(uint256 numTokens) internal returns (PartyPool) {
|
||||
// Deploy _tokens dynamically
|
||||
@@ -139,9 +155,9 @@ contract GasTest is Test {
|
||||
for (uint i = 0; i < tokens.length; i++) {
|
||||
ierc20Tokens[i] = IERC20(tokens[i]);
|
||||
}
|
||||
// Compute kappa from slippage params and number of _tokens, then construct pool with kappa
|
||||
int128 computedKappa = LMSRStabilized.computeKappaFromSlippage(ierc20Tokens.length, tradeFrac, targetSlippage);
|
||||
PartyPool newPool = Deploy.newPartyPool(address(this), poolName, poolName, ierc20Tokens, bases, computedKappa, feePpm, feePpm, false);
|
||||
// Compute fixed b from slippage and expected initial S, then construct pool with fixed b
|
||||
int128 bFixed = _computeFixedB(ierc20Tokens.length);
|
||||
PartyPool newPool = Deploy.newPartyPool(address(this), poolName, poolName, ierc20Tokens, bases, bFixed, feePpm, feePpm, false);
|
||||
|
||||
// Transfer initial deposit amounts into pool before initial mint
|
||||
for (uint256 i = 0; i < numTokens; i++) {
|
||||
@@ -180,8 +196,8 @@ contract GasTest is Test {
|
||||
for (uint i = 0; i < tokens.length; i++) {
|
||||
ierc20Tokens[i] = IERC20(tokens[i]);
|
||||
}
|
||||
int128 computedKappa = LMSRStabilized.computeKappaFromSlippage(ierc20Tokens.length, tradeFrac, targetSlippage);
|
||||
PartyPool newPool = Deploy.newPartyPool(address(this), poolName, poolName, ierc20Tokens, bases, computedKappa, feePpm, feePpm, true);
|
||||
int128 bFixed = _computeFixedB(ierc20Tokens.length);
|
||||
PartyPool newPool = Deploy.newPartyPool(address(this), poolName, poolName, ierc20Tokens, bases, bFixed, feePpm, feePpm, true);
|
||||
|
||||
// Transfer initial deposit amounts into pool before initial mint
|
||||
for (uint256 i = 0; i < numTokens; i++) {
|
||||
|
||||
Reference in New Issue
Block a user