Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test/more #28

Merged
merged 118 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
118 commits
Select commit Hold shift + click to select a range
bc54a6e
test: add test_swapExactSyForYt_AdjustsReserves
clemlak Jun 24, 2024
126616f
test: add test_swapExactSyForYt_RevertsWhenExcessInput
clemlak Jun 24, 2024
e1c4813
test: add test_swapExactSyForYt_RevertsWhenInsufficientOutput
clemlak Jun 24, 2024
473714e
feat: turn reentrancy lock private
clemlak Jun 24, 2024
932d04c
test: add reserves update in swapExactPtForSy handler
clemlak Jun 24, 2024
f8871b5
chore: reduce invariant tests depth
clemlak Jun 24, 2024
4038412
test: add test_swapExactSyForYt_EmitsEvent
clemlak Jun 24, 2024
5544fd2
test: fix reserves tracking in swapExactPtForSy handler
clemlak Jun 25, 2024
f0a9787
test: add reserves update to swapExactSyForYt handler
clemlak Jun 25, 2024
7c37833
test: add weth to RMMHandler, improve reserves tracking, fix some stuff
clemlak Jun 25, 2024
9e8a878
test: add swapExactSyForPt handler, update config
clemlak Jun 25, 2024
47d8d17
test: track reserves in swapExactYtForSy handler
clemlak Jun 25, 2024
9d54ddc
test: add swapExactYtForSy handler to invariant testing
clemlak Jun 25, 2024
b6e025a
test: add swapExactTokenForYt to invariant testing targets
clemlak Jun 25, 2024
f234d46
test: add random amount for swapExactSyForYt handler
clemlak Jun 25, 2024
34bc281
test: add random amounts to target functions
clemlak Jun 25, 2024
ec7f877
test: revert to hardcoded amounts
clemlak Jun 25, 2024
c1b4fb0
fix initialization status, reverting with insuficient allowance?
kinrezC Jun 25, 2024
d4c87e8
fix: allocate returns sy dxWad instead of asset units
kinrezC Jun 25, 2024
598ccca
rm console logs
kinrezC Jun 25, 2024
25ce6a2
fmt
kinrezC Jun 25, 2024
e0c38a9
test: add newIndex utils function to SetUp, update SY minting
clemlak Jun 26, 2024
bd8d365
add _updateReserves internal function and remove redundant trading fu…
kinrezC Jun 26, 2024
cb52fbf
fix allocate
kinrezC Jun 26, 2024
e5c929e
fix allocate related tests
kinrezC Jun 26, 2024
d6d0db3
assert strike >= 1e18 instead of simply > 1e18
kinrezC Jun 26, 2024
bf237b8
pass amountX instead of totalAsset to prepareInit
kinrezC Jun 26, 2024
58cb7d1
fix init tests
kinrezC Jun 26, 2024
ff74153
fix invariant init failure
kinrezC Jun 26, 2024
bf41f48
fiddling with invariant tests
kinrezC Jun 26, 2024
353c574
wip rY invariant tests
kinrezC Jun 27, 2024
2d3346b
fix sy for pt ghost reserves
kinrezC Jun 27, 2024
f3ff06c
change tokenForYt upper bound approximation
kinrezC Jun 27, 2024
6ee1a20
test: add test_swapExactPtForSy_EmitsEvent
clemlak Jun 28, 2024
8d31296
test: update test_swapExactPtForSy_RevertsIfInsufficientOutput
clemlak Jun 28, 2024
11f9370
test: add trading function and price checks to swapExactPtForSy tests
clemlak Jun 28, 2024
1fdb2d3
test: add test_swapExactSyForPt_EmitsEvent
clemlak Jun 28, 2024
0e69fcb
test: improve test_swapExactSyForPt_RevertsIfInsufficientOutput
clemlak Jun 28, 2024
15b7e5b
test: add syToAsset to SetUp base test file
clemlak Jun 28, 2024
8044428
test: use syToAsset
clemlak Jun 28, 2024
f889eb9
test: add trading function and price checks to SwapExactSyForPtTest
clemlak Jun 28, 2024
39ae334
test: fix test_swapExactSyForPt_MaintainsPrice
clemlak Jun 28, 2024
008c2e7
test: add setLastTimestamp to MockRMM
clemlak Jun 28, 2024
9ae6636
test: use MockRMM instead of RMM for testing
clemlak Jun 28, 2024
ec4670d
test: add test_approxSpotPrice_IncreasesOverTime
clemlak Jun 28, 2024
08062f7
test: delete old RMM test file
clemlak Jun 28, 2024
e872190
chore: rename ApproxSpotPriceTest contract
clemlak Jun 28, 2024
9e3798c
chore: clean up unused or duplicate tests
clemlak Jun 28, 2024
2dec962
test: add test_mintSY_MintsSYUsingETH
clemlak Jun 28, 2024
47a2b57
fix: wrong receiver param using ETH in _mintSYFromNativeAndToken
clemlak Jun 28, 2024
1bb3819
test: add test_mintSY_MintsSYUsingWETH
clemlak Jun 28, 2024
7d4405f
test: add test_approxSpotPrice_OneAtMaturity
clemlak Jun 28, 2024
d20849c
test: add test_strike_OneAtMaturity_IncreasesOverTime
clemlak Jun 28, 2024
1dffe19
chore: remove unused import
clemlak Jun 28, 2024
67d0c8b
test: remove old test file
clemlak Jun 28, 2024
018ff00
chore: add dev comment to MockRMM
clemlak Jun 28, 2024
5fa7efc
test: add assetToSyUp to SetUp base test file
clemlak Jun 28, 2024
c6b7d19
test: use newIndex
clemlak Jun 28, 2024
2dcc8d2
chore: remove logs
clemlak Jun 28, 2024
8b2f31b
test: add RMM label
clemlak Jun 28, 2024
0dfe4f7
test: add DEFAULT_NOW parameter, warp to NOW, update default expiry
clemlak Jun 28, 2024
87087a4
approxEq on strike
kinrezC Jun 28, 2024
d37d733
feat: add SY and PT scalars as storage variables
clemlak Jul 1, 2024
08831a2
test: add increaseTime to invariant handler
clemlak Jul 2, 2024
1118f08
feat: remove init in favor of constructor
clemlak Jul 2, 2024
d2c11eb
test: add new constructor params to MockRMM
clemlak Jul 2, 2024
0dac70d
test: update test base setup with new RMM constructor
clemlak Jul 2, 2024
7c74860
test: add RMM default name and symbol
clemlak Jul 2, 2024
babf2e9
test: update test_constructor_InitializesParameters
clemlak Jul 2, 2024
e6233b5
test: add more assertions to test_constructor_InitializesParameters
clemlak Jul 2, 2024
a9019cf
feat: add prepareInit to RMM Factory
clemlak Jul 3, 2024
04a5e7b
feat: change prepareInit parameters (remove PT, add PYIndex)
clemlak Jul 3, 2024
1656172
test: add real WstETH contract
clemlak Jul 3, 2024
9d8edab
feat: add immutable vars, init them in constructor, remove unused var…
clemlak Jul 3, 2024
d34cc16
feat: clean up factory, add new RMM constructor params
clemlak Jul 3, 2024
e45f849
feat: remove curator from Init event
clemlak Jul 3, 2024
6df39da
test: update MockRMM constructor params
clemlak Jul 3, 2024
13108e7
test: update init tests
clemlak Jul 3, 2024
42823a6
test: update constructor tests
clemlak Jul 3, 2024
93bbb03
chore: update scripts
clemlak Jul 3, 2024
d470f28
test: add WstETH to test SetUp, add setUpRMM, initRMM functions
clemlak Jul 3, 2024
54fc632
test: update Debit tests
clemlak Jul 3, 2024
62ae5dd
test: use newIndex() in InitTest
clemlak Jul 3, 2024
9e37591
test: update init in RMMHandler
clemlak Jul 3, 2024
2a9ba05
test: use setUpRMM in invariant test file
clemlak Jul 3, 2024
7b27936
test: add test_credit_TransfersTokens
clemlak Jul 4, 2024
60cf368
Merge pull request #29 from primitivefinance/feat/remove-init
clemlak Jul 5, 2024
d19dfb2
test: add test_adjust_UpdatesReservesAndPrices
clemlak Jul 5, 2024
94787ce
test: add test_credit_DownscalesAmount
clemlak Jul 8, 2024
293273f
feat: add MaturityReached
clemlak Jul 8, 2024
fbc9aa6
feat: add MaturityReached error, use updateReserves in deallocate, fi…
clemlak Jul 8, 2024
72a1b66
feat: remove computeYTToPT
clemlak Jul 8, 2024
dd7d73e
wip calcSlope
kinrezC Jul 8, 2024
7a307e9
test: fix test_swapExactSyForYt_AdjustsReserves
clemlak Jul 10, 2024
f0c42a3
wip
kinrezC Jul 8, 2024
8269983
working upperbound for sy -> yt
kinrezC Jul 10, 2024
7aaae18
wip invariant tests almost there
kinrezC Jul 10, 2024
63865ed
fix initialization of ghost reserves
kinrezC Jul 10, 2024
f368afe
fix invariant test runs
kinrezC Jul 10, 2024
c75f2a7
invariant tests working except for yt->sy and token->yt
kinrezC Jul 10, 2024
8f72ce3
increase initial reserves so that call depth can go higher
kinrezC Jul 10, 2024
58f94ee
fix yt -> sy invariant tests
kinrezC Jul 11, 2024
f2ff3df
use custom `fund` instead of `deal`
kinrezC Jul 11, 2024
8babed3
fix invariant tests
kinrezC Jul 11, 2024
a5e38a5
increase depth to tolerable amount
kinrezC Jul 11, 2024
2eeb0e4
Merge branch 'main' into test/more
clemlak Jul 12, 2024
044641a
test: update mint SY and PY functions and modifiers (got rid of deal)
clemlak Jul 12, 2024
d2a6d12
test: add missing ETH deal in WETH modifier
clemlak Jul 12, 2024
57ae968
test: add missing ETH deal in test_swapExactTokenForYt_SwapsETH
clemlak Jul 12, 2024
1266326
test: fix test_mintSY_MintsSYUsingWETH
clemlak Jul 12, 2024
a17d30a
test: add missing ETH deal in test_mintSY_MintsSYUsingETH
clemlak Jul 12, 2024
4ad1b0a
feat: LiquidityManager update
clemlak Jul 12, 2024
6f0b802
test: update LiquidityManager setup
clemlak Jul 12, 2024
c5984f7
wip lower contract size
kinrezC Jul 15, 2024
bd45fa0
revert balanceNative impl
kinrezC Jul 15, 2024
9e6b556
rm unused currentTau fn
kinrezC Jul 15, 2024
a41bbac
19 bytes off
kinrezC Jul 15, 2024
52aba25
remove custom error selector for allocate
kinrezC Jul 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion script/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ contract Deploy is Script {

address sender = vm.addr(pk);
console2.log("Deploying RMM from", sender);
RMM rmm = FACTORY.createRMM("RMM", "RMM");
// RMM rmm = FACTORY.createRMM("RMM", "RMM");

vm.stopBroadcast();
}
Expand Down
12 changes: 2 additions & 10 deletions script/DeployPool.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ contract DeployPool is Script {
uint256 pk = vm.envUint(ENV_PRIVATE_KEY);
vm.startBroadcast(pk);
sender = vm.addr(pk);
rmm = FACTORY.createRMM("Lido Staked ETH 24 Dec 2025", "stETH-24DEC25");
rmm = FACTORY.createRMM("Lido Staked ETH 24 Dec 2025", "stETH-24DEC25", address(PT), 0.02 ether, fee);
console2.log("rmm address: ", address(rmm));

mintSY(10_000 ether);
Expand All @@ -107,15 +107,7 @@ contract DeployPool is Script {
PYIndex index = YT.newIndex();
(MarketState memory ms, MarketPreCompute memory mp) = getPendleMarketData(index);
uint256 price = uint256(getPtExchangeRate(index));
rmm.init({
PT_: address(PT),
priceX: price,
amountX: uint256(ms.totalSy),
strike_: uint256(mp.rateAnchor),
sigma_: 0.02 ether,
fee_: fee,
curator_: address(0x55)
});
rmm.init({priceX: price, amountX: uint256(ms.totalSy), strike_: uint256(mp.rateAnchor)});

vm.stopBroadcast();
}
Expand Down
7 changes: 5 additions & 2 deletions src/Factory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ contract Factory {
WETH = weth_;
}

function createRMM(string memory poolName, string memory poolSymbol) external returns (RMM) {
RMM rmm = new RMM(WETH, poolName, poolSymbol);
function createRMM(string memory poolName, string memory poolSymbol, address PT, uint256 sigma, uint256 fee)
external
returns (RMM)
{
RMM rmm = new RMM(poolName, poolSymbol, PT, sigma, fee);
emit NewPool(msg.sender, address(rmm), poolName, poolSymbol);
pools.push(address(rmm));
return rmm;
Expand Down
31 changes: 24 additions & 7 deletions src/LiquidityManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {PYIndexLib, PYIndex} from "pendle/core/StandardizedYield/PYIndex.sol";
import {FixedPointMathLib} from "solmate/utils/FixedPointMathLib.sol";
import {SafeTransferLib, ERC20} from "solmate/utils/SafeTransferLib.sol";

import {RMM, IPYieldToken} from "./RMM.sol";
import {RMM, IPYieldToken, Gaussian, computeTradingFunction} from "./RMM.sol";
import {InvalidTokenIn, InsufficientSYMinted} from "./lib/RmmErrors.sol";

contract LiquidityManager {
Expand Down Expand Up @@ -78,10 +78,11 @@ contract LiquidityManager {
// swap syToSwap for pt
rmm.swapExactSyForPt(syToSwap, args.minOut, address(this));
uint256 syBal = sy.balanceOf(address(this));
sy.approve(address(args.rmm), syBal);
uint256 ptBal = pt.balanceOf(address(this));

pt.approve(address(args.rmm), ptBal);
liquidity = rmm.allocate(syBal, ptBal, args.minLiquidityDelta, msg.sender);
liquidity = rmm.allocate(true, syBal, args.minLiquidityDelta, msg.sender);
}

function allocateFromPt(AllocateArgs calldata args) external returns (uint256 liquidity) {
Expand Down Expand Up @@ -112,12 +113,10 @@ contract LiquidityManager {
pt.approve(address(rmm), args.amountIn);

// swap ptToSwap for sy
rmm.swapExactPtForSy(ptToSwap, args.minOut, address(this));
uint256 syBal = sy.balanceOf(address(this));
uint256 ptBal = pt.balanceOf(address(this));
(uint256 syOut,) = rmm.swapExactPtForSy(ptToSwap, args.minOut, address(this));

sy.approve(address(rmm), syBal);
liquidity = rmm.allocate(syBal, ptBal, args.minLiquidityDelta, msg.sender);
sy.approve(address(rmm), type(uint256).max);
liquidity = rmm.allocate(false, pt.balanceOf(address(this)), args.minLiquidityDelta, msg.sender);
}

struct ComputeArgs {
Expand Down Expand Up @@ -179,4 +178,22 @@ contract LiquidityManager {
function isAApproxB(uint256 a, uint256 b, uint256 eps) internal pure returns (bool) {
return b.mulWadDown(1 ether - eps) <= a && a <= b.mulWadDown(1 ether + eps);
}

function calcMaxPtOut(
uint256 reserveX_,
uint256 reserveY_,
uint256 totalLiquidity_,
uint256 strike_,
uint256 sigma_,
uint256 tau_
) internal pure returns (uint256) {
int256 currentTF = computeTradingFunction(reserveX_, reserveY_, totalLiquidity_, strike_, sigma_, tau_);

uint256 maxProportion = uint256(int256(1e18) - currentTF) * 1e18 / (2 * 1e18);

uint256 maxPtOut = reserveY_ * maxProportion / 1e18;

return (maxPtOut * 999) / 1000;
}

}
Loading
Loading