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 12, 2024
1 parent 34c9f60 commit 90043dd
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 38 deletions.
12 changes: 4 additions & 8 deletions strategies/trireme/dca-oracle-univ2.rain
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,8 @@ scenarios:
backtest:
runs: 1
blocks:
type: RangeWithInterval
value:
range: [59857426..]
interval: 1000
range: [59857426..]
interval: 1000
bindings:
plottables: '''plottables-backtest'
ensure-min-ratio: '''ensure-min-ratio-chart'
Expand Down Expand Up @@ -242,10 +240,8 @@ scenarios:
backtest:
runs: 1
blocks:
type: RangeWithInterval
value:
range: [59857426..]
interval: 1000
range: [59857426..]
interval: 1000
bindings:
plottables: '''plottables-backtest'
ensure-min-ratio: '''ensure-min-ratio-chart'
Expand Down
11 changes: 7 additions & 4 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: 15
io-ratio-base: 19
io-ratio-growth: 0.5
tranche-size-expr: '''linear-growth'
tranche-size-base: 5
Expand Down Expand Up @@ -547,8 +547,9 @@ deployments:
tranche-total-size: call<'calculate-tranche>(),
tranche-amount-diff: if(
amount-is-output
scale-18-dynamic(output-token-decimals() uint256-output-vault-decrease())
scale-18-dynamic(input-token-decimals() uint256-input-vault-increase())),
output-vault-decrease()
input-vault-increase()
),
tranche-space-diff: div(tranche-amount-diff tranche-total-size),
tranche-space-after: add(tranche-space-before tranche-space-diff),
/* Snap tranche space to the nearest tranche to avoid dust issues at the edges */
Expand Down Expand Up @@ -577,6 +578,7 @@ deployments:
_: io-ratio-current;

#post-add-order
using-words-from uniswap-words orderbook-subparser
current-ratio: call<'post-action>(),
tranche-0-ratio: call<'io-ratio-expr>(io-ratio-base io-ratio-growth 0),
tranche-1-ratio: call<'io-ratio-expr>(io-ratio-base io-ratio-growth 1),
Expand All @@ -595,4 +597,5 @@ deployments:
"default" initial-tranche-space
),
:set(hash(order-hash() init-key) 1),
:set(hash(order-hash() tranche-space-key) init-tranche);
:set(hash(order-hash() tranche-space-key) init-tranche),
:set(hash(order-hash() update-time-key) now());
2 changes: 1 addition & 1 deletion test/Trireme/DcaUniV2Test.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ contract DcaUniV2Test is StrategyTests {
APPROVED_EOA = address(0x669845c29D9B1A64FFF66a55aA13EB4adB889a88);
ORDER_OWNER = address(0x5e01e44aE1969e16B9160d903B6F2aa991a37B21);
}

function testDcaBuyUniV2() public {

IO[] memory inputVaults = new IO[](1);
Expand Down
39 changes: 14 additions & 25 deletions test/WlthTrancheInitTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {IOrderBookV4ArbOrderTaker} from "rain.orderbook.interface/interface/IOrd
import {IExpressionDeployerV3} from "rain.interpreter.interface/interface/deprecated/IExpressionDeployerV3.sol";
import {IInterpreterV3} from "rain.interpreter.interface/interface/IInterpreterV3.sol";
import {IInterpreterStoreV2} from "rain.interpreter.interface/interface/IInterpreterStoreV2.sol";
import {StrategyTests, IRouteProcessor, LibStrategyDeployment, LibComposeOrders,IInterpreterV3} from "h20.test-std/StrategyTests.sol";
import {StrategyTests, IRouteProcessor, LibStrategyDeployment, LibComposeOrders,IInterpreterV3,FullyQualifiedNamespace,LibNamespace,StateNamespace} from "h20.test-std/StrategyTests.sol";
import {Strings} from "openzeppelin-contracts/contracts/utils/Strings.sol";
import {SafeERC20, IERC20} from "openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol";
import "h20.test-std/lib/LibProcessStream.sol";
Expand All @@ -48,7 +48,7 @@ contract StopLimitTest is StrategyTests {
using SafeERC20 for IERC20;
using Strings for address;

uint256 constant FORK_BLOCK_NUMBER = 17914079;
uint256 constant FORK_BLOCK_NUMBER = 18339410;

function selectFork() internal {
uint256 fork = vm.createFork(vm.envString("RPC_URL_BASE"));
Expand All @@ -63,8 +63,8 @@ contract StopLimitTest is StrategyTests {
iStore = IInterpreterStoreV2(0x6E4b01603edBDa617002A077420E98C86595748E);
iInterpreter = IInterpreterV3(0x379b966DC6B117dD47b5Fc5308534256a4Ab1BCC);
iExpressionDeployer = IExpressionDeployerV3(0x56394785a22b3BE25470a0e03eD9E0a939C47b9b);
iOrderBook = IOrderBookV4(0xA2f56F8F74B7d04d61f281BE6576b6155581dcBA);
iArbInstance = IOrderBookV4ArbOrderTaker(0xF97A86C2Cb3e42f89AC5f5AA020E5c3505015a88);
iOrderBook = IOrderBookV4(0x7A44459893F99b9d9a92d488eb5d16E4090f0545);
iArbInstance = IOrderBookV4ArbOrderTaker(0x03B6A05D487e760edb383754dA58C801D860D1d0);
iRouteProcessor = IRouteProcessor(address(0x0389879e0156033202C44BF784ac18fC02edeE4f));
EXTERNAL_EOA = address(0x654FEf5Fb8A1C91ad47Ba192F7AA81dd3C821427);
APPROVED_EOA = address(0x669845c29D9B1A64FFF66a55aA13EB4adB889a88);
Expand All @@ -79,17 +79,19 @@ contract StopLimitTest is StrategyTests {
IO[] memory outputVaults = new IO[](1);
outputVaults[0] = baseUsdcIo();


uint256 expectedRatio = 20.5e18;
uint256 expectedOrderAmount = 5.3e18;


LibStrategyDeployment.StrategyDeploymentV3 memory strategy = LibStrategyDeployment.StrategyDeploymentV3(
getEncodedSellWlthRoute(),
getEncodedBuyWlthRoute(),
0,
0,
1000000e18,
100000e18,
10000e6,
0,
0,
expectedRatio,
expectedOrderAmount,
"strategies/wlth-tranche-init.rain",
"wlth-tranches.buy.initialized.prod",
"./lib/h20.test-std/lib/rain.orderbook",
Expand All @@ -99,6 +101,7 @@ contract StopLimitTest is StrategyTests {
new ActionV1[](0)
);
ActionV1[] memory postOrderActions;

{
bytes memory postOrderCompose = iParser.parse2(
LibComposeOrders.getComposedPostAddOrder(
Expand All @@ -114,34 +117,20 @@ contract StopLimitTest is StrategyTests {
}
strategy.postActions = postOrderActions;

OrderV3 memory order = addOrderDepositOutputTokens(strategy);

{
vm.recordLogs();
// `arb()` called
takeArbOrder(order, strategy.takerRoute, strategy.inputTokenIndex, strategy.outputTokenIndex);

Vm.Log[] memory entries = vm.getRecordedLogs();
(uint256 strategyAmount, uint256 strategyRatio) = getCalculationContext(entries);

console2.log("strategyAmount : ",strategyAmount);
console2.log("strategyRatio : ",strategyRatio);
}
checkStrategyCalculationsArbOrder(strategy);

}



function getEncodedBuyWlthRoute() internal pure returns (bytes memory) {
bytes memory BUY_WLTH_ROUTE =
hex"02833589fCD6eDb6E08f4c7C32D4f71b54bdA0291301ffff011536EE1506e24e5A36Be99C73136cD82907A902E01F97A86C2Cb3e42f89AC5f5AA020E5c3505015a88";
hex"02833589fCD6eDb6E08f4c7C32D4f71b54bdA0291301ffff011536EE1506e24e5A36Be99C73136cD82907A902E0103B6A05D487e760edb383754dA58C801D860D1d0";

return abi.encode(BUY_WLTH_ROUTE);
}

function getEncodedSellWlthRoute() internal pure returns (bytes memory) {
bytes memory SELL_WLTH_ROUTE =
hex"0299b2B1A2aDB02B38222ADcD057783D7e5D1FCC7D01ffff011536EE1506e24e5A36Be99C73136cD82907A902E00F97A86C2Cb3e42f89AC5f5AA020E5c3505015a88";
hex"0299b2B1A2aDB02B38222ADcD057783D7e5D1FCC7D01ffff011536EE1506e24e5A36Be99C73136cD82907A902E0003B6A05D487e760edb383754dA58C801D860D1d0";

return abi.encode(SELL_WLTH_ROUTE);
}
Expand Down

0 comments on commit 90043dd

Please sign in to comment.