Skip to content

Commit

Permalink
update tranche init
Browse files Browse the repository at this point in the history
  • Loading branch information
Siddharth2207 committed Aug 3, 2024
1 parent 0d95323 commit c976e69
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 25 deletions.
2 changes: 1 addition & 1 deletion lib/h20.test-std
12 changes: 11 additions & 1 deletion strategies/wlth-tranche-init.rain
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,17 @@ scenarios:
# Uniswap v3 factory contract address and corresponding init code hash.
# If the factory address and the init code aren't available as a literals
# then non-literal address and hash value can be given as bindings.
uniswap-v3-factory: '[uniswap-v3-factory]'
uniswap-v3-factory: 0x33128a8fC17869897dcE68Ed026d694621f6FDfD
uniswap-v3-init-code: '[uniswap-v3-init-code]'

# Uniswap v3 fee tier and twap duration
twap-fee: '[uniswap-v3-fee-medium]'
twap-duration: 0

# Reference token addresses
reference-token: 0x99b2B1A2aDB02B38222ADcD057783D7e5D1FCC7D
reference-stable: 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913

orderbook-subparser: 0x8D96ea3EF24D7123882c51CE4325b89bc0d63f9e

# How far we move through tranche space in a second.
Expand Down Expand Up @@ -218,6 +226,7 @@ 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'
scenarios:
prod:
bindings:
Expand Down Expand Up @@ -400,6 +409,7 @@ deployments:
#io-ratio-base !The base IO ratio, as a decimal 18 fixed point number. This is the IO ratio at tranche space 0 and grows according to the growth factor per tranche.
#io-ratio-growth !The exponential growth factor of the IO ratio. E.g. 0.01 is 1% io-ratio growth per tranche.

#reference-token !Strategy token for which the budget is written.
#reference-stable !The stable token that is used as a reference for the TWAP to offer dollar equivalent conversions.
#reference-stable-decimals !The number of decimals of the reference stable token.
#reference-reserve !The token that will be used to compare against the reference stable token to calculate the TWAP for dollar equivalent conversions.
Expand Down
10 changes: 6 additions & 4 deletions test/StopLimitTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ contract StopLimitTest is StrategyTests {
IO[] memory outputVaults = new IO[](1);
outputVaults[0] = baseWlthIo();

LibStrategyDeployment.StrategyDeployment memory strategy = LibStrategyDeployment.StrategyDeployment(
LibStrategyDeployment.StrategyDeploymentV3 memory strategy = LibStrategyDeployment.StrategyDeploymentV3(
getEncodedBuyWlthRoute(),
getEncodedSellWlthRoute(),
0,
Expand All @@ -96,7 +96,8 @@ contract StopLimitTest is StrategyTests {
"./lib/h20.test-std/lib/rain.orderbook",
"./lib/h20.test-std/lib/rain.orderbook/Cargo.toml",
inputVaults,
outputVaults
outputVaults,
new ActionV1[](0)
);

OrderV3 memory order = addOrderDepositOutputTokens(strategy);
Expand Down Expand Up @@ -140,7 +141,7 @@ contract StopLimitTest is StrategyTests {
IO[] memory outputVaults = new IO[](1);
outputVaults[0] = baseUsdcIo();

LibStrategyDeployment.StrategyDeployment memory strategy = LibStrategyDeployment.StrategyDeployment(
LibStrategyDeployment.StrategyDeploymentV3 memory strategy = LibStrategyDeployment.StrategyDeploymentV3(
getEncodedSellWlthRoute(),
getEncodedBuyWlthRoute(),
0,
Expand All @@ -154,7 +155,8 @@ contract StopLimitTest is StrategyTests {
"./lib/h20.test-std/lib/rain.orderbook",
"./lib/h20.test-std/lib/rain.orderbook/Cargo.toml",
inputVaults,
outputVaults
outputVaults,
new ActionV1[](0)
);

OrderV3 memory order = addOrderDepositOutputTokens(strategy);
Expand Down
20 changes: 12 additions & 8 deletions test/Trireme/DcaUniV2Test.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ contract DcaUniV2Test is StrategyTests {
uint256 expectedRatio = 7.546679062155744054e18;
uint256 expectedAmount = 1.448940071037488020e18;

LibStrategyDeployment.StrategyDeployment memory strategy = LibStrategyDeployment.StrategyDeployment(
LibStrategyDeployment.StrategyDeploymentV3 memory strategy = LibStrategyDeployment.StrategyDeploymentV3(
getEncodedSellZercRoute(),
getEncodedBuyZercRoute(),
0,
Expand All @@ -93,7 +93,8 @@ contract DcaUniV2Test is StrategyTests {
"./lib/h20.test-std/lib/rain.orderbook",
"./lib/h20.test-std/lib/rain.orderbook/Cargo.toml",
inputVaults,
outputVaults
outputVaults,
new ActionV1[](0)
);

OrderV3 memory order = addOrderDepositOutputTokens(strategy);
Expand Down Expand Up @@ -123,7 +124,7 @@ contract DcaUniV2Test is StrategyTests {
uint256 expectedRatio = 0.107731681330498142e18;
uint256 expectedAmount = 11.591520568299904160e18;

LibStrategyDeployment.StrategyDeployment memory strategy = LibStrategyDeployment.StrategyDeployment(
LibStrategyDeployment.StrategyDeploymentV3 memory strategy = LibStrategyDeployment.StrategyDeploymentV3(
getEncodedBuyZercRoute(),
getEncodedSellZercRoute(),
0,
Expand All @@ -137,7 +138,8 @@ contract DcaUniV2Test is StrategyTests {
"./lib/h20.test-std/lib/rain.orderbook",
"./lib/h20.test-std/lib/rain.orderbook/Cargo.toml",
inputVaults,
outputVaults
outputVaults,
new ActionV1[](0)
);

OrderV3 memory order = addOrderDepositOutputTokens(strategy);
Expand All @@ -163,7 +165,7 @@ contract DcaUniV2Test is StrategyTests {
IO[] memory outputVaults = new IO[](1);
outputVaults[0] = polygonUsdcIo();

LibStrategyDeployment.StrategyDeployment memory strategy = LibStrategyDeployment.StrategyDeployment(
LibStrategyDeployment.StrategyDeploymentV3 memory strategy = LibStrategyDeployment.StrategyDeploymentV3(
getEncodedSellZercRoute(),
getEncodedBuyZercRoute(),
0,
Expand All @@ -177,7 +179,8 @@ contract DcaUniV2Test is StrategyTests {
"./lib/h20.test-std/lib/rain.orderbook",
"./lib/h20.test-std/lib/rain.orderbook/Cargo.toml",
inputVaults,
outputVaults
outputVaults,
new ActionV1[](0)
);

OrderV3 memory order = addOrderDepositOutputTokens(strategy);
Expand Down Expand Up @@ -211,7 +214,7 @@ contract DcaUniV2Test is StrategyTests {
IO[] memory outputVaults = new IO[](1);
outputVaults[0] = polygonUsdcIo();

LibStrategyDeployment.StrategyDeployment memory strategy = LibStrategyDeployment.StrategyDeployment(
LibStrategyDeployment.StrategyDeploymentV3 memory strategy = LibStrategyDeployment.StrategyDeploymentV3(
getEncodedSellZercRoute(),
getEncodedBuyZercRoute(),
0,
Expand All @@ -225,7 +228,8 @@ contract DcaUniV2Test is StrategyTests {
"./lib/h20.test-std/lib/rain.orderbook",
"./lib/h20.test-std/lib/rain.orderbook/Cargo.toml",
inputVaults,
outputVaults
outputVaults,
new ActionV1[](0)
);

OrderV3 memory order = addOrderDepositOutputTokens(strategy);
Expand Down
51 changes: 40 additions & 11 deletions test/WlthTrancheInitTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,13 @@ import {
OrderConfigV3,
TakeOrderConfigV3,
TakeOrdersConfigV3,
ActionV1
} from "rain.orderbook.interface/interface/unstable/IOrderBookV4.sol";

ActionV1,
EvaluableV3,
SignedContextV1
} from "rain.orderbook.interface/interface/unstable/IOrderBookV4.sol";
import {IParserV2} from "rain.interpreter.interface/interface/unstable/IParserV2.sol";
import {IOrderBookV4ArbOrderTaker} from "rain.orderbook.interface/interface/unstable/IOrderBookV4ArbOrderTaker.sol";

// import {IOrderBookV3ArbOrderTaker} from "rain.orderbook.interface/interface/IOrderBookV3ArbOrderTaker.sol";
// import {IParserV1} from "rain.interpreter.interface/interface/IParserV1.sol";
import {IExpressionDeployerV3} from "rain.interpreter.interface/interface/IExpressionDeployerV3.sol";
// import {IInterpreterV2} from "rain.interpreter.interface/interface/IInterpreterV2.sol";
import {IInterpreterV3} from "rain.interpreter.interface/interface/unstable/IInterpreterV3.sol";
import {IInterpreterStoreV2} from "rain.interpreter.interface/interface/IInterpreterStoreV2.sol";
import {StrategyTests, IRouteProcessor, LibStrategyDeployment, LibComposeOrders,IInterpreterV3} from "h20.test-std/StrategyTests.sol";
Expand Down Expand Up @@ -82,7 +79,9 @@ contract StopLimitTest is StrategyTests {
IO[] memory outputVaults = new IO[](1);
outputVaults[0] = baseUsdcIo();

LibStrategyDeployment.StrategyDeployment memory strategy = LibStrategyDeployment.StrategyDeployment(


LibStrategyDeployment.StrategyDeploymentV3 memory strategy = LibStrategyDeployment.StrategyDeploymentV3(
getEncodedSellWlthRoute(),
getEncodedBuyWlthRoute(),
0,
Expand All @@ -96,13 +95,43 @@ contract StopLimitTest is StrategyTests {
"./lib/h20.test-std/lib/rain.orderbook",
"./lib/h20.test-std/lib/rain.orderbook/Cargo.toml",
inputVaults,
outputVaults
outputVaults,
new ActionV1[](0)
);

OrderV3 memory order = addOrderDepositOutputTokens(strategy);
ActionV1[] memory postOrderActions;
{
bytes memory postOrderCompose = iParser.parse2(
LibComposeOrders.getComposedPostAddOrder(
vm, strategy.strategyFile, strategy.strategyScenario, strategy.buildPath, strategy.manifestPath
)
)
;
EvaluableV3 memory postOrderEvaluable = EvaluableV3(iInterpreter, iStore, postOrderCompose);

ActionV1 memory postOrderAction = ActionV1(postOrderEvaluable,new SignedContextV1[](0));
postOrderActions = new ActionV1[](1);
postOrderActions[0] = postOrderAction;
}
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);
}

}



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

0 comments on commit c976e69

Please sign in to comment.