Skip to content

Commit 43bd05f

Browse files
authored
Sean/curve tests (#128)
* just updating some tests, and the createAndStake script * update test args for curves * Fix unit tests that somehow broke from auto merge? * update ethmultivault 1.5 test address in createAndStake script
1 parent fe44a1d commit 43bd05f

8 files changed

+185
-32
lines changed

Diff for: script/CreateAndStake.s.sol

+58-21
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,17 @@ import {EthMultiVault} from "src/EthMultiVault.sol";
1313
*/
1414
contract CreateAndStake is Script {
1515
// Address of the EthMultiVault contract
16-
address payable public constant ETH_MULTI_VAULT = payable(0x71Ea9FEb2C8341897188B409c83bc9a64ECdDdFC);
16+
address payable public constant ETH_MULTI_VAULT = payable(0x63B90A9c109fF8f137916026876171ffeEdEe714);
17+
18+
bytes[] public ATOM_URIS = [
19+
bytes("intuition.systems"),
20+
bytes("is"),
21+
bytes("bullish"),
22+
bytes("cat"),
23+
bytes("internet")
24+
];
25+
26+
uint256[] public ATOM_IDS;
1727

1828
// Bonding curve IDs
1929
uint256 public constant CURVE_ID_2 = 2;
@@ -31,38 +41,65 @@ contract CreateAndStake is Script {
3141

3242
// Get the atom cost
3343
uint256 atomCost = ethMultiVault.getAtomCost();
34-
console.log("Atom creation cost: %s wei", atomCost);
44+
console.log("Atom creation cost: %d wei", atomCost);
45+
uint256 tripleCost = ethMultiVault.getTripleCost();
46+
console.log("Triple creation cost: %d wei", tripleCost);
3547

3648
// Create the atom with the raw URI "intuition.systems"
37-
bytes memory atomUri = bytes("intuition.systems");
38-
uint256 atomId = ethMultiVault.createAtom{value: atomCost}(atomUri);
39-
console.log("Created atom with ID: %s", atomId);
49+
for (uint256 i = 0; i < ATOM_URIS.length; i++) {
50+
uint256 atomId = ethMultiVault.createAtom{value: atomCost}(ATOM_URIS[i]);
51+
console.log("Created atom with ID: %s", atomId);
52+
ATOM_IDS.push(atomId);
53+
}
4054

4155
// Stake in bonding curve 2
42-
console.log("Staking %s wei in bonding curve 2", STAKE_AMOUNT);
43-
uint256 shares2 = ethMultiVault.depositAtomCurve{value: STAKE_AMOUNT}(
56+
for (uint256 i = 0; i < ATOM_IDS.length; i++) {
57+
console.log("Staking %d wei in %s bonding curve 2", STAKE_AMOUNT, string(ATOM_URIS[i]));
58+
uint256 shares2 = ethMultiVault.depositAtomCurve{value: STAKE_AMOUNT}(
59+
msg.sender, // receiver is the sender of this transaction
60+
ATOM_IDS[i],
61+
CURVE_ID_2
62+
);
63+
console.log("Received %d shares in bonding curve 2", shares2);
64+
65+
// Stake in bonding curve 3
66+
console.log("Staking %d wei in %s bonding curve 3", STAKE_AMOUNT, string(ATOM_URIS[i]));
67+
uint256 shares3 = ethMultiVault.depositAtomCurve{value: STAKE_AMOUNT}(
68+
msg.sender, // receiver is the sender of this transaction
69+
ATOM_IDS[i],
70+
CURVE_ID_3
71+
);
72+
console.log("Received %d shares in bonding curve 3", shares3);
73+
}
74+
75+
// Create a triple
76+
uint256 tripleId = ethMultiVault.createTriple{value: tripleCost}(ATOM_IDS[0], ATOM_IDS[1], ATOM_IDS[2]);
77+
console.log("Created triple with ID: %s", tripleId);
78+
79+
// Stake in the triple
80+
console.log("Staking %d wei in triple", STAKE_AMOUNT);
81+
uint256 shares4 = ethMultiVault.depositTripleCurve{value: STAKE_AMOUNT}(
4482
msg.sender, // receiver is the sender of this transaction
45-
atomId,
46-
CURVE_ID_2
83+
tripleId,
84+
CURVE_ID_3
4785
);
48-
console.log("Received %s shares in bonding curve 2", shares2);
86+
console.log("Received %d shares in triple", shares4);
4987

50-
// Stake in bonding curve 3
51-
console.log("Staking %s wei in bonding curve 3", STAKE_AMOUNT);
52-
uint256 shares3 = ethMultiVault.depositAtomCurve{value: STAKE_AMOUNT}(
88+
// Create another triple
89+
uint256 tripleId2 = ethMultiVault.createTriple{value: tripleCost}(ATOM_IDS[3], ATOM_IDS[1], ATOM_IDS[4]);
90+
console.log("Created triple with ID: %s", tripleId2);
91+
92+
// Stake in the second counter-triple
93+
console.log("Staking %s wei in second triple", STAKE_AMOUNT);
94+
uint256 counterTripleId = ethMultiVault.getCounterIdFromTriple(tripleId2);
95+
uint256 shares5 = ethMultiVault.depositTripleCurve{value: STAKE_AMOUNT}(
5396
msg.sender, // receiver is the sender of this transaction
54-
atomId,
97+
counterTripleId,
5598
CURVE_ID_3
5699
);
57-
console.log("Received %s shares in bonding curve 3", shares3);
100+
console.log("Received %s shares in counter second triple", shares5);
58101

59102
// Stop broadcasting transactions
60103
vm.stopBroadcast();
61-
62-
// Print summary
63-
console.log("Summary:");
64-
console.log("- Created atom 'intuition.systems' with ID: %s", atomId);
65-
console.log("- Staked %s wei in bonding curve 2, received %s shares", STAKE_AMOUNT, shares2);
66-
console.log("- Staked %s wei in bonding curve 3, received %s shares", STAKE_AMOUNT, shares3);
67104
}
68105
}

Diff for: script/DeployCurve.s.sol

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ contract DeployCurve is Script {
1616
// Deploy OffsetProgressiveCurve
1717
OffsetProgressiveCurve offsetProgressiveCurve = new OffsetProgressiveCurve(
1818
"Offset Progressive Curve",
19-
2, // slope
20-
1e17 // offset
19+
1e16, // slope
20+
1e28 // offset
2121
);
2222
console.logString("deployed OffsetProgressiveCurve.");
2323

Diff for: script/DeployForTesting.s.sol

+2-2
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,11 @@ contract DeployEthMultiVault is Script {
129129
console.logString("deployed LinearCurve.");
130130

131131
// Deploy ProgressiveCurve
132-
progressiveCurve = new ProgressiveCurve("Progressive Curve", 2);
132+
progressiveCurve = new ProgressiveCurve("Progressive Curve", 1e16);
133133
console.logString("deployed ProgressiveCurve.");
134134

135135
// Deploy OffsetProgressiveCurve
136-
offsetProgressiveCurve = new OffsetProgressiveCurve("Offset Progressive Curve", 2, 1e17);
136+
offsetProgressiveCurve = new OffsetProgressiveCurve("Offset Progressive Curve", 1e16, 1e28);
137137
console.logString("deployed OffsetProgressiveCurve.");
138138

139139
// Add curves to BondingCurveRegistry

Diff for: test/BaseTest.sol

+4-3
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,6 @@ contract BaseTest is Test {
134134
// Testing for offset curve:
135135
// - 7e13 - 0 - 36%
136136
// - 7e13 - 10 - 36% initial dropoff
137-
address offsetCurve = address(new OffsetProgressiveCurve("Offset Curve", 2, 1e17));
138-
BondingCurveRegistry(c.bondingCurve.registry).addBondingCurve(offsetCurve);
139137

140138
// address progressiveCurve = address(
141139
// new ProgressiveCurve("Progressive Curve", 0.00007054e18);
@@ -163,8 +161,11 @@ contract BaseTest is Test {
163161
// Bob Shares: 4.14132267880182129e17
164162
// Charlie Shares: 3.17781355457602312e17
165163

166-
address progressiveCurve = address(new ProgressiveCurve("Progressive Curve", 0.0001e18)); // Because minDeposit is 0.0003 ether
164+
address progressiveCurve = address(new ProgressiveCurve("Progressive Curve", 1e16));
167165
BondingCurveRegistry(c.bondingCurve.registry).addBondingCurve(progressiveCurve);
166+
167+
address offsetCurve = address(new OffsetProgressiveCurve("Offset Curve", 1e16, 1e28));
168+
BondingCurveRegistry(c.bondingCurve.registry).addBondingCurve(offsetCurve);
168169
vm.stopPrank();
169170

170171
return c;

Diff for: test/EthMultiVaultBase.sol

+4-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {IPermit2} from "src/interfaces/IPermit2.sol";
1414
import {BondingCurveRegistry} from "src/BondingCurveRegistry.sol";
1515
import {ProgressiveCurve} from "src/ProgressiveCurve.sol";
1616
import {LinearCurve} from "src/LinearCurve.sol";
17-
17+
import {OffsetProgressiveCurve} from "src/OffsetProgressiveCurve.sol";
1818
contract EthMultiVaultBase is Test {
1919
// msg.value - atomCreationProtocolFee - protocolFee
2020

@@ -85,8 +85,10 @@ contract EthMultiVaultBase is Test {
8585

8686
address linearCurve = address(new LinearCurve("Linear Curve"));
8787
BondingCurveRegistry(bondingCurveRegistry).addBondingCurve(linearCurve);
88-
address progressiveCurve = address(new ProgressiveCurve("Progressive Curve", 2));
88+
address progressiveCurve = address(new ProgressiveCurve("Progressive Curve", 1e16));
8989
BondingCurveRegistry(bondingCurveRegistry).addBondingCurve(progressiveCurve);
90+
address offsetProgressiveCurve = address(new OffsetProgressiveCurve("Offset Progressive Curve", 1e16, 1e28));
91+
BondingCurveRegistry(bondingCurveRegistry).addBondingCurve(offsetProgressiveCurve);
9092

9193
IEthMultiVault.BondingCurveConfig memory bondingCurveConfig =
9294
IEthMultiVault.BondingCurveConfig({registry: bondingCurveRegistry, defaultCurveId: 1});

Diff for: test/unit/EthMultiVault/BatchRedeem.t.sol

+6-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {EthMultiVaultBase} from "test/EthMultiVaultBase.sol";
88
import {EthMultiVaultHelpers} from "test/helpers/EthMultiVaultHelpers.sol";
99

1010
contract BatchRedeemTest is EthMultiVaultBase, EthMultiVaultHelpers {
11-
uint256 constant CURVE_ID = 2;
11+
uint256 constant CURVE_ID = 3;
1212

1313
function setUp() external {
1414
_setUp();
@@ -41,8 +41,11 @@ contract BatchRedeemTest is EthMultiVaultBase, EthMultiVaultHelpers {
4141
amounts[1] = testDepositAmount;
4242
amounts[2] = testDepositAmount;
4343

44+
ethMultiVault.batchDeposit{value: testDepositAmount * 3}(alice, termIds, amounts);
45+
4446
// Get initial state
4547
uint256 aliceInitialBalance = address(alice).balance;
48+
console.log("aliceInitialBalance: ", aliceInitialBalance);
4649

4750
// Redeem 100% of shares from all vaults
4851
uint256[] memory assets = ethMultiVault.batchRedeem(10000, alice, termIds);
@@ -95,6 +98,8 @@ contract BatchRedeemTest is EthMultiVaultBase, EthMultiVaultHelpers {
9598
amounts[1] = testDepositAmount;
9699
amounts[2] = testDepositAmount;
97100

101+
ethMultiVault.batchDepositCurve{value: testDepositAmount * 3}(alice, termIds, curveIds, amounts);
102+
98103
// Get initial state
99104
uint256 aliceInitialBalance = address(alice).balance;
100105

Diff for: test/unit/EthMultiVault/CurveComparison.t.sol

+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
// SPDX-License-Identifier: BUSL-1.1
2+
pragma solidity ^0.8.21;
3+
4+
import "forge-std/Test.sol";
5+
import "forge-std/console2.sol";
6+
import {EthMultiVaultBase} from "test/EthMultiVaultBase.sol";
7+
import {EthMultiVaultHelpers} from "test/helpers/EthMultiVaultHelpers.sol";
8+
import {StringUtils} from "./StringUtils.sol";
9+
import {BondingCurveRegistry} from "src/BondingCurveRegistry.sol";
10+
import {ProgressiveCurve} from "src/ProgressiveCurve.sol";
11+
import {OffsetProgressiveCurve} from "src/OffsetProgressiveCurve.sol";
12+
import {IEthMultiVault} from "src/interfaces/IEthMultiVault.sol";
13+
14+
contract CurveComparisonTest is EthMultiVaultBase, EthMultiVaultHelpers {
15+
using StringUtils for uint256;
16+
17+
uint256 constant PROGRESSIVE_CURVE_ID = 2;
18+
uint256 constant OFFSET_PROGRESSIVE_CURVE_ID = 3;
19+
address internal charlie = makeAddr("charlie");
20+
21+
function setUp() external {
22+
_setUp();
23+
vm.deal(charlie, 100 ether);
24+
}
25+
26+
function testCompareCurves(uint256 depositAmount) internal {
27+
// Log curve addresses and parameters
28+
(address registry,) = ethMultiVault.bondingCurveConfig();
29+
address progressiveCurve = BondingCurveRegistry(registry).curveAddresses(PROGRESSIVE_CURVE_ID);
30+
address offsetProgressiveCurve = BondingCurveRegistry(registry).curveAddresses(OFFSET_PROGRESSIVE_CURVE_ID);
31+
32+
console2.log("Progressive Curve slope: ", ProgressiveCurve(progressiveCurve).SLOPE().unwrap().toString());
33+
console2.log("Offset Progressive Curve slope: ", OffsetProgressiveCurve(offsetProgressiveCurve).SLOPE().unwrap().toString());
34+
console2.log("Offset Progressive Curve offset: ", OffsetProgressiveCurve(offsetProgressiveCurve).OFFSET().unwrap().toString());
35+
36+
// Alice creates an atom
37+
vm.startPrank(alice, alice);
38+
uint256 atomId;
39+
try ethMultiVault.createAtom{value: getAtomCost()}("") returns (uint256 id) {
40+
atomId = id;
41+
} catch Error(string memory reason) {
42+
console2.log("Failed to create atom: ", reason);
43+
revert(reason);
44+
}
45+
vm.stopPrank();
46+
47+
uint256 progressiveShares;
48+
uint256 offsetProgressiveShares;
49+
50+
// Deposit into Curve 2 (Progressive)
51+
vm.startPrank(bob, bob);
52+
try ethMultiVault.depositAtomCurve{value: depositAmount}(bob, atomId, PROGRESSIVE_CURVE_ID) {
53+
(progressiveShares,) = ethMultiVault.getVaultStateForUserCurve(atomId, PROGRESSIVE_CURVE_ID, bob);
54+
console2.log("%s Assets into Progressive Curve yields %s shares", depositAmount.toString(), progressiveShares.toString());
55+
} catch Error(string memory reason) {
56+
console2.log("Failed to deposit into progressive curve: ", reason);
57+
revert(reason);
58+
}
59+
vm.stopPrank();
60+
61+
// Deposit into Curve 3 (Offset Progressive)
62+
vm.startPrank(charlie, charlie);
63+
try ethMultiVault.depositAtomCurve{value: depositAmount}(charlie, atomId, OFFSET_PROGRESSIVE_CURVE_ID) {
64+
(offsetProgressiveShares,) = ethMultiVault.getVaultStateForUserCurve(atomId, OFFSET_PROGRESSIVE_CURVE_ID, charlie);
65+
console2.log("%s Assets into Offset Progressive Curve yields %s shares", depositAmount.toString(), offsetProgressiveShares.toString());
66+
} catch Error(string memory reason) {
67+
console2.log("Failed to deposit into offset curve: ", reason);
68+
revert(reason);
69+
}
70+
vm.stopPrank();
71+
72+
// Calculate and log differences
73+
uint256 shareDifference;
74+
if (progressiveShares > offsetProgressiveShares) {
75+
shareDifference = progressiveShares - offsetProgressiveShares;
76+
console2.log("Progressive curve produced more shares by: ", shareDifference);
77+
console2.log("Percentage difference: ", shareDifference.toPercentage(progressiveShares));
78+
} else {
79+
shareDifference = offsetProgressiveShares - progressiveShares;
80+
console2.log("Offset curve produced more shares by: ", shareDifference);
81+
console2.log("Percentage difference: ", shareDifference.toPercentage(offsetProgressiveShares));
82+
}
83+
}
84+
85+
function testCompareCurvesSmallAmount() external {
86+
testCompareCurves(0.001 ether);
87+
}
88+
89+
function testCompareCurvesMediumAmount() external {
90+
testCompareCurves(1 ether);
91+
}
92+
93+
function testCompareCurvesLargeAmount() external {
94+
testCompareCurves(10 ether);
95+
}
96+
97+
function testCompareCurvesVerySmallAmount() external {
98+
testCompareCurves(0.0003 ether);
99+
}
100+
101+
function testCompareCurvesTinyAmount() external {
102+
testCompareCurves(0.003 ether);
103+
}
104+
105+
function testCompareCurvesMicroAmount() external {
106+
testCompareCurves(0.03 ether);
107+
}
108+
}

Diff for: test/unit/EthMultiVault/Profit.t.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {StringUtils} from "./StringUtils.sol";
1111
contract ProfitTest is EthMultiVaultBase, EthMultiVaultHelpers {
1212
using StringUtils for uint256;
1313

14-
uint256 constant CURVE_ID = 2;
14+
uint256 constant CURVE_ID = 3;
1515
address internal charlie = makeAddr("charlie");
1616

1717
function setUp() external {

0 commit comments

Comments
 (0)