Verified contractExactMIT
PolynomialFeeCalculator
Address0x24e170f9bcdfb4bbc532b341c069cd094b6ff5ce
- Balance
0 ETH
- Transactions
1
- Compiler
solc 0.8.26
- Same code
Only this contract
Details
- Compiler
- solc 0.8.26+commit.8a97fa7a
- Language
- solidity
- Optimization
- Yes, 200 runs
- EVM version
- cancun
- Via IR
- yes
- License
- MIT
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 23,797,396
- Creation transaction
- 0x4074c6f099…62b929c95a
2 files
- src/PolynomialFeeCalculator.solmain2.49 KB
- src/interface/IFeeCalculator.sol167 B
src/PolynomialFeeCalculator.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import "./interface/IFeeCalculator.sol";
contract PolynomialFeeCalculator is IFeeCalculator {
int256 public constant COEFFICIENT_SCALE = 1e18;
struct PolynomialCoefficients {
int256 a; // R⁵
int256 b; // R⁴
int256 c; // R³
int256 d; // R²
int256 e; // R¹
}
PolynomialCoefficients public declineCoefficients;
PolynomialCoefficients public pumpCoefficients;
error InvalidRValue();
constructor() {
// R < 0
declineCoefficients = PolynomialCoefficients({
a: -4167 * COEFFICIENT_SCALE / 100, // -41.67
b: -5833 * COEFFICIENT_SCALE / 100, // -58.33
c: -3792 * COEFFICIENT_SCALE / 100, // -37.92
d: -6417 * COEFFICIENT_SCALE / 1000, // -6.417
e: -4167 * COEFFICIENT_SCALE / 10000 // -0.4167
});
// R > 0
pumpCoefficients = PolynomialCoefficients({
a: 4167 * COEFFICIENT_SCALE / 100, // 41.67
b: -5833 * COEFFICIENT_SCALE / 100, // -58.33
c: 3792 * COEFFICIENT_SCALE / 100, // 37.92
d: -6417 * COEFFICIENT_SCALE / 1000, // -6.417
e: 4167 * COEFFICIENT_SCALE / 10000 // 0.4167
});
}
function calculateFee(int256 R, bool flow) external view override returns (uint256 feeRateBps) {
if (R == 0) return 0;
PolynomialCoefficients memory coeffs;
if (flow) {
// F(Rd) = -41.67Rd^5 - 58.33Rd^4 - 37.92Rd^3 - 6.417Rd^2 - 0.4167Rd
coeffs = declineCoefficients;
} else {
// F(Rp) = 41.67Rp^5 - 58.33Rp^4 + 37.92Rp^3 - 6.417Rp^2 + 0.4167Rp
coeffs = pumpCoefficients;
}
// Price decline: Calculated using a polynomial curve
int256 R2 = (R * R) / COEFFICIENT_SCALE;
int256 R3 = (R2 * R) / COEFFICIENT_SCALE;
int256 R4 = (R3 * R) / COEFFICIENT_SCALE;
int256 R5 = (R4 * R) / COEFFICIENT_SCALE;
int256 F_raw = 0;
F_raw += (coeffs.a * R5) / COEFFICIENT_SCALE;
F_raw += (coeffs.b * R4) / COEFFICIENT_SCALE;
F_raw += (coeffs.c * R3) / COEFFICIENT_SCALE;
F_raw += (coeffs.d * R2) / COEFFICIENT_SCALE;
F_raw += (coeffs.e * R) / COEFFICIENT_SCALE;
F_raw = (F_raw * 10000) / COEFFICIENT_SCALE;
if (F_raw < 0) F_raw = -F_raw;
feeRateBps = uint256(F_raw);
}
}
src/interface/IFeeCalculator.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
interface IFeeCalculator {
function calculateFee(int256 R, bool flow) external view returns (uint256);
}
Compiler settingsShow
{
"viaIR": true,
"metadata": {
"appendCBOR": true,
"bytecodeHash": "ipfs",
"useLiteralContent": false
},
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "cancun",
"remappings": [
"@ensdomains/=lib/v4-core/node_modules/@ensdomains/",
"@openzeppelin/=lib/v4-core/lib/openzeppelin-contracts/",
"@uniswap/v4-core/=lib/v4-periphery/lib/v4-core/",
"ds-test/=lib/solmate/lib/ds-test/src/",
"erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
"forge-gas-snapshot/=lib/permit2/lib/forge-gas-snapshot/src/",
"forge-std/=lib/forge-std/src/",
"halmos-cheatcodes/=lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
"hardhat/=lib/v4-core/node_modules/hardhat/",
"openzeppelin-contracts/=lib/openzeppelin-contracts/",
"permit2/=lib/permit2/",
"solmate/=lib/solmate/",
"@uniswap/v2-core/=lib/v2-core/",
"@uniswap/v3-core/=lib/v3-core/",
"v4-core/=lib/v4-core/src/",
"@uniswap/v4-periphery/=lib/v4-periphery/",
"universal-router/=lib/universal-router/",
"v2-core/=lib/v2-core/contracts/",
"v3-core/=lib/v3-core/",
"@uniswap/v3-periphery/=lib/universal-router/lib/v3-periphery/",
"v3-periphery/=lib/universal-router/lib/v3-periphery/contracts/",
"v4-periphery/=lib/v4-periphery/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.