22pragma solidity ^ 0.8.28 ;
33
44import "forge-std/Test.sol " ;
5- import "../src/libraries/Formula .sol " ;
5+ import "../src/libraries/BondingCurve .sol " ;
66
7- contract FormulaTest is Test {
8- // Constants from the Formula library
7+ contract BondingCurveTest is Test {
8+ // Constants from the BondingCurve library
99 uint256 constant BASE_PRICE = 30_677_636_300 ;
1010 uint256 constant EXP_FACTOR = 4_000_000 ;
1111 uint256 constant SCALING_FACTOR = 1e18 ;
@@ -15,12 +15,12 @@ contract FormulaTest is Test {
1515 function testPurchaseBaseCases () public pure {
1616 // Test purchase with 0 ETH supply and 1 ETH input
1717 // Should return some tokens
18- uint256 tokensOut = Formula .calculatePurchaseReturn (0 , 1 ether);
18+ uint256 tokensOut = BondingCurve .calculatePurchaseReturn (0 , 1 ether);
1919 assert (tokensOut > 0 );
2020
2121 // Test purchase with 0 ETH input
2222 // Should return 0
23- uint256 zeroOut = Formula .calculatePurchaseReturn (1 ether, 0 );
23+ uint256 zeroOut = BondingCurve .calculatePurchaseReturn (1 ether, 0 );
2424 assert (zeroOut == 0 );
2525 }
2626
@@ -30,8 +30,8 @@ contract FormulaTest is Test {
3030 uint256 supply1 = 10 ether ;
3131 uint256 supply2 = 20 ether ;
3232
33- uint256 tokens1 = Formula .calculatePurchaseReturn (supply1, ethIn);
34- uint256 tokens2 = Formula .calculatePurchaseReturn (supply2, ethIn);
33+ uint256 tokens1 = BondingCurve .calculatePurchaseReturn (supply1, ethIn);
34+ uint256 tokens2 = BondingCurve .calculatePurchaseReturn (supply2, ethIn);
3535
3636 assertTrue (tokens2 < tokens1, "Price should increase with supply " );
3737
@@ -43,7 +43,7 @@ contract FormulaTest is Test {
4343
4444 function testSellBaseCases () public {
4545 // Test sell with 0 token input
46- uint256 ethOut = Formula .calculateSellReturn (1 ether, 0 );
46+ uint256 ethOut = BondingCurve .calculateSellReturn (1 ether, 0 );
4747 assertEq (ethOut, 0 , "Should return 0 ETH for 0 tokens " );
4848 }
4949
@@ -54,8 +54,8 @@ contract FormulaTest is Test {
5454 // Test selling different amounts
5555 uint256 sellAmount1 = 1000 ether ;
5656
57- uint256 ethOut1 = Formula .calculateSellReturn (initialEthSupply, sellAmount1);
58- uint256 ethOut2 = Formula .calculateSellReturn (initialEthSupply - ethOut1, sellAmount1);
57+ uint256 ethOut1 = BondingCurve .calculateSellReturn (initialEthSupply, sellAmount1);
58+ uint256 ethOut2 = BondingCurve .calculateSellReturn (initialEthSupply - ethOut1, sellAmount1);
5959
6060 assertTrue (ethOut2 < ethOut1, "Price should decrease after selling " );
6161 }
@@ -65,10 +65,10 @@ contract FormulaTest is Test {
6565 uint256 ethIn = 1 ether ;
6666
6767 // Buy tokens
68- uint256 tokensReceived = Formula .calculatePurchaseReturn (ethSupply, ethIn);
68+ uint256 tokensReceived = BondingCurve .calculatePurchaseReturn (ethSupply, ethIn);
6969
7070 // Sell the same amount of tokens
71- uint256 ethOut = Formula .calculateSellReturn (ethSupply + ethIn, tokensReceived);
71+ uint256 ethOut = BondingCurve .calculateSellReturn (ethSupply + ethIn, tokensReceived);
7272
7373 // Should get slightly less ETH due to the curve mechanics
7474 assertTrue (ethOut < ethIn, "Should have some slippage " );
@@ -78,18 +78,18 @@ contract FormulaTest is Test {
7878 function testExtremeValues () public {
7979 // Test with very small amounts
8080 uint256 tinyEth = 1 wei ;
81- uint256 tokensForTiny = Formula .calculatePurchaseReturn (0 , tinyEth);
81+ uint256 tokensForTiny = BondingCurve .calculatePurchaseReturn (0 , tinyEth);
8282 // Due to precision limitations with fixed-point math, very small amounts might return 0
8383 assertEq (tokensForTiny, 0 , "Tiny amounts should return 0 due to precision limits " );
8484
8585 // Test with more reasonable minimum amount (0.0001 ether)
8686 uint256 smallEth = 1e14 ; // 0.0001 ether
87- uint256 tokensForSmall = Formula .calculatePurchaseReturn (0 , smallEth);
87+ uint256 tokensForSmall = BondingCurve .calculatePurchaseReturn (0 , smallEth);
8888 assertTrue (tokensForSmall > 0 , "Should handle small amounts " );
8989
9090 // Test with large amounts
9191 uint256 largeEth = 1000000 ether ;
92- uint256 tokensForLarge = Formula .calculatePurchaseReturn (0 , largeEth);
92+ uint256 tokensForLarge = BondingCurve .calculatePurchaseReturn (0 , largeEth);
9393 assertTrue (tokensForLarge > 0 , "Should handle large amounts " );
9494
9595 // Test progression of amounts
@@ -100,9 +100,9 @@ contract FormulaTest is Test {
100100 uint256 ethSupply = 10 ether ;
101101
102102 // Try to sell more tokens than possible
103- uint256 maxTokens = Formula .calculatePurchaseReturn (0 , ethSupply);
104- vm.expectRevert (abi.encodeWithSignature ( " FormulaInvalidTokenAmount() " ) );
105- Formula .calculateSellReturn (ethSupply, maxTokens * 2 );
103+ uint256 maxTokens = BondingCurve .calculatePurchaseReturn (0 , ethSupply);
104+ vm.expectRevert ();
105+ BondingCurve .calculateSellReturn (ethSupply, maxTokens * 2 );
106106 }
107107
108108 function testPriceProgression () public {
@@ -112,7 +112,7 @@ contract FormulaTest is Test {
112112
113113 // Test price progression over multiple purchases
114114 for (uint256 i = 0 ; i < 10 ; i++ ) {
115- uint256 tokenAmount = Formula .calculatePurchaseReturn (ethSupply, ethIncrement);
115+ uint256 tokenAmount = BondingCurve .calculatePurchaseReturn (ethSupply, ethIncrement);
116116 assertTrue (tokenAmount < lastTokenAmount, "Price must increase monotonically " );
117117 assertTrue (tokenAmount > 0 , "Should always return some tokens " );
118118
@@ -123,7 +123,7 @@ contract FormulaTest is Test {
123123
124124 function testCurveParameters () public {
125125 // Test that the curve parameters produce expected behavior
126- uint256 initialPurchase = Formula .calculatePurchaseReturn (0 , 1 ether);
126+ uint256 initialPurchase = BondingCurve .calculatePurchaseReturn (0 , 1 ether);
127127
128128 // Log values for analysis
129129 console.log ("Initial purchase tokens: " , initialPurchase);
@@ -135,13 +135,13 @@ contract FormulaTest is Test {
135135 assertTrue (initialPurchase > 0 , "Should return tokens " );
136136
137137 // 2. Verify curve steepness
138- uint256 laterPurchase = Formula .calculatePurchaseReturn (50 ether, 1 ether);
138+ uint256 laterPurchase = BondingCurve .calculatePurchaseReturn (50 ether, 1 ether);
139139 assertTrue (laterPurchase < initialPurchase / 2 , "Curve should be sufficiently steep " );
140140
141141 // 3. Verify the exponential nature
142- uint256 purchase1 = Formula .calculatePurchaseReturn (0 , 1 ether);
143- uint256 purchase2 = Formula .calculatePurchaseReturn (1 ether, 1 ether);
144- uint256 purchase3 = Formula .calculatePurchaseReturn (2 ether, 1 ether);
142+ uint256 purchase1 = BondingCurve .calculatePurchaseReturn (0 , 1 ether);
143+ uint256 purchase2 = BondingCurve .calculatePurchaseReturn (1 ether, 1 ether);
144+ uint256 purchase3 = BondingCurve .calculatePurchaseReturn (2 ether, 1 ether);
145145
146146 assertTrue (purchase1 > purchase2, "Price should increase " );
147147 assertTrue (purchase2 > purchase3, "Price should increase " );
0 commit comments