Skip to content

Commit

Permalink
update init tranche
Browse files Browse the repository at this point in the history
  • Loading branch information
Siddharth2207 committed Aug 16, 2024
1 parent b308427 commit b1f65a2
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 15 deletions.
12 changes: 7 additions & 5 deletions strategies/wlth-tranche-init.rain
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ scenarios:
# buying WLTH with it, then the amount is the OUTPUT.
amount-is-output: 1
io-ratio-expr: '''linear-growth'
io-ratio-base: 19
io-ratio-base: 15
io-ratio-growth: 0.5
tranche-size-expr: '''linear-growth'
tranche-size-base: 5
Expand All @@ -175,8 +175,9 @@ scenarios:
# tranche that won't immediately dump into the market.
# If the market is outside the chart then set this to 0.
initial-tranche-space: 0
post-action: '''post-action-buy'
post-action: '''post-action-constant'
post-action-tranche: '''post-action-tranche-linear'
io-ratio-current: 20
scenarios:
prod:
bindings:
Expand Down Expand Up @@ -213,7 +214,7 @@ scenarios:
# selling WLTH for it, then the amount is the INPUT.
amount-is-output: 0
io-ratio-expr: '''linear-growth'
io-ratio-base: 0.015
io-ratio-base: 0.040
io-ratio-growth: 0.001
tranche-size-expr: '''linear-growth'
tranche-size-base: 5
Expand All @@ -227,8 +228,9 @@ scenarios:
# tranche that won't immediately dump into the market.
# If the market is outside the chart then set this to 0.
initial-tranche-space: 0
post-action: '''post-action-sell'
post-action: '''post-action-constant'
post-action-tranche: '''post-action-tranche-linear'
io-ratio-current: 0.042
scenarios:
prod:
bindings:
Expand Down Expand Up @@ -539,7 +541,7 @@ deployments:
tranche-io-ratio: call<'io-ratio-expr>(io-ratio-base io-ratio-growth floor(tranche-space-now)),
final-io-ratio: mul(tranche-io-ratio call<'io-ratio-multiplier>()),
amount-available: mul(tranche-total-size tranche-space-available),
amount: if(amount-is-output amount-available div(amount-available final-io-ratio)),
amount: if(amount-is-output amount-available div(amount-available final-io-ratio)),
io-ratio: final-io-ratio,
:call<'plottables>(amount io-ratio);

Expand Down
54 changes: 44 additions & 10 deletions test/WlthTrancheInitTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ contract StopLimitTest is StrategyTests {
using SafeERC20 for IERC20;
using Strings for address;

uint256 constant FORK_BLOCK_NUMBER = 18376923;
uint256 constant FORK_BLOCK_NUMBER = 18463466;

function selectFork() internal {
uint256 fork = vm.createFork(vm.envString("RPC_URL_BASE"));
Expand Down Expand Up @@ -79,16 +79,16 @@ contract StopLimitTest is StrategyTests {
IO[] memory outputVaults = new IO[](1);
outputVaults[0] = baseUsdcIo();

uint256 expectedRatio = 22.5e18;
uint256 expectedOrderAmount = 1.676309165235004558e18;
uint256 expectedRatio = 20e18;
uint256 expectedOrderAmount = 6000000000000000000;


LibStrategyDeployment.StrategyDeploymentV4 memory strategy = LibStrategyDeployment.StrategyDeploymentV4(
getEncodedSellWlthRoute(),
getEncodedBuyWlthRoute(),
0,
0,
100000e18,
1e18,
10000e6,
expectedRatio,
expectedOrderAmount,
Expand All @@ -103,6 +103,40 @@ contract StopLimitTest is StrategyTests {

checkStrategyCalculationsArbOrder(strategy);

}

function testWlthTrancheInitSell() public {

IO[] memory inputVaults = new IO[](1);
inputVaults[0] = baseUsdcIo();

IO[] memory outputVaults = new IO[](1);
outputVaults[0] = baseWlthIo();

uint256 expectedRatio = 42000000000000000;
uint256 expectedOrderAmount = 123809523809523809523;


LibStrategyDeployment.StrategyDeploymentV4 memory strategy = LibStrategyDeployment.StrategyDeploymentV4(
getEncodedBuyWlthRoute(),
getEncodedSellWlthRoute(),
0,
0,
1e6,
1000000e18,
expectedRatio,
expectedOrderAmount,
"strategies/wlth-tranche-init.rain",
"wlth-tranches.sell.initialized.prod",
"./lib/h20.test-std/lib/rain.orderbook",
"./lib/h20.test-std/lib/rain.orderbook/Cargo.toml",
inputVaults,
outputVaults,
new SignedContextV1[](0)
);

checkStrategyCalculationsArbOrder(strategy);

}

function testSuccessiveTranches() public {
Expand Down Expand Up @@ -142,8 +176,8 @@ contract StopLimitTest is StrategyTests {
Vm.Log[] memory entries = vm.getRecordedLogs();
(uint256 strategyAmount, uint256 strategyRatio) = getCalculationContext(entries);

uint256 expectedTrancheAmount = 1.676309165235004558e18;
uint256 expectedTrancheRatio = 22.5e18;
uint256 expectedTrancheAmount = 6000000000000000000;
uint256 expectedTrancheRatio = 20e18;

assertEq(strategyAmount, expectedTrancheAmount);
assertEq(strategyRatio, expectedTrancheRatio);
Expand All @@ -157,8 +191,8 @@ contract StopLimitTest is StrategyTests {
Vm.Log[] memory entries = vm.getRecordedLogs();
(uint256 strategyAmount, uint256 strategyRatio) = getCalculationContext(entries);

uint256 expectedTrancheAmount = 5.8e18;
uint256 expectedTrancheRatio = 23e18;
uint256 expectedTrancheAmount = 6100000000000000000;
uint256 expectedTrancheRatio = 20500000000000000000;

assertEq(strategyAmount, expectedTrancheAmount);
assertEq(strategyRatio, expectedTrancheRatio);
Expand All @@ -172,8 +206,8 @@ contract StopLimitTest is StrategyTests {
Vm.Log[] memory entries = vm.getRecordedLogs();
(uint256 strategyAmount, uint256 strategyRatio) = getCalculationContext(entries);

uint256 expectedTrancheAmount = 5.9e18;
uint256 expectedTrancheRatio = 23.5e18;
uint256 expectedTrancheAmount = 6200000000000000000;
uint256 expectedTrancheRatio = 21000000000000000000;

assertEq(strategyAmount, expectedTrancheAmount);
assertEq(strategyRatio, expectedTrancheRatio);
Expand Down

0 comments on commit b1f65a2

Please sign in to comment.