Skip to content
This repository has been archived by the owner on Nov 29, 2024. It is now read-only.

Commit

Permalink
wip tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Siddharth2207 committed Mar 11, 2024
1 parent 965558f commit 7e9db54
Show file tree
Hide file tree
Showing 3 changed files with 375 additions and 398 deletions.
19 changes: 9 additions & 10 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

167 changes: 65 additions & 102 deletions src/lib/LibTrendTrade.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,170 +10,133 @@ library LibTrendTrade {
using Strings for uint256;

struct TrendTradeTest {
address orderBookSubparser;
address uniswapSubparser;
uint256 testMeanReserveAmount18;
address reserveToken;
uint256 reserveDecimals;
uint256 testLastTime;
uint256 testNow;
uint256 testTrendNumerator;
uint256 testTrendDenominator;
uint256 testTrendUpFactor;
uint256 testTrendDownFactor;
uint256 cooldown;
uint256 jitteryBinomialBits;
uint256 meanCooldown;
uint256 twapTrendRatioLongTime;
uint256 twapTrendRatioShortTime;
uint256 twapTrendRatioFee;
uint256 meanReserveAmount18;
uint256 trendUpFactor;
uint256 trendDownFactor;
uint256 bounty;
}

struct TrendTrade {
address orderBookSubparser;
address uniswapSubparser;
address tokenAddress;
uint256 tokenDecimals;
address reserveToken;
uint256 reserveDecimals;
uint256 meanAmount;
uint256 cooldown;
uint256 bounty;
uint256 jitteryBinomialBits;
uint256 twapLongTime;
uint256 twapShortTime;
uint256 meanCooldown;
uint256 twapTrendRatioLongTime;
uint256 twapTrendRatioShortTime;
uint256 twapTrendRatioFee;
uint256 meanReserveAmount18;
uint256 trendUpFactor;
uint256 trendDownFactor;
uint256 bounty;
}

function getTestTrendOrder(
Vm vm,
TrendTradeTest memory tradeTest
TrendTradeTest memory tradeTestConifg,
address orderBookSubparser,
address uniswapSubparser
) internal returns (bytes memory testTrend){

string[] memory ffi = new string[](35);
string[] memory ffi = new string[](39);
ffi[0] = "rain";
ffi[1] = "dotrain";
ffi[2] = "compose";
ffi[3] = "-i";
ffi[4] = "src/trend-trader.rain";
ffi[4] = "src/trend-trader.rain";
ffi[5] = "--entrypoint";
ffi[6] = "test-calculate-io";
ffi[6] = "calculate-io";
ffi[7] = "--entrypoint";
ffi[8] = "test-handle-io";
ffi[8] = "handle-io";
ffi[9] = "--bind";
ffi[10] = string.concat("tkn-address=0x692AC1e363ae34b6B489148152b12e2785a3d8d6");
ffi[10] = string.concat("reserve-address=",tradeTestConifg.reserveToken.toHexString());
ffi[11] = "--bind";
ffi[12] = string.concat("tkn-decimals=18");
ffi[12] = string.concat("reserve-decimals=",tradeTestConifg.reserveDecimals.toString());
ffi[13] = "--bind";
ffi[14] = string.concat("reserve-address=0xc2132D05D31c914a87C6611C10748AEb04B58e8F");
ffi[14] = string.concat("times='test-times");
ffi[15] = "--bind";
ffi[16] = string.concat("reserve-decimals=6");
ffi[16] = string.concat("jittery-binomial-bits=", tradeTestConifg.jitteryBinomialBits.toString());
ffi[17] = "--bind";
ffi[18] = string.concat("test-mean-reserve-amount18=", tradeTest.testMeanReserveAmount18.toString());
ffi[18] = string.concat("mean-cooldown=", tradeTestConifg.meanCooldown.toString());
ffi[19] = "--bind";
ffi[20] = string.concat("test-last-time=", tradeTest.testLastTime.toString());
ffi[20] = string.concat("trend-ratio-exp='uni-v3-twap-trend-ratio");
ffi[21] = "--bind";
ffi[22] = string.concat("test-now=", tradeTest.testNow.toHexString());
ffi[22] = string.concat("twap-trend-ratio-long-time=", tradeTestConifg.twapTrendRatioLongTime.toString());
ffi[23] = "--bind";
ffi[24] = string.concat("test-trend-numerator=", tradeTest.testTrendNumerator.toString());
ffi[24] = string.concat("twap-trend-ratio-short-time=", tradeTestConifg.twapTrendRatioShortTime.toString());
ffi[25] = "--bind";
ffi[26] = string.concat("test-trend-denominator=", tradeTest.testTrendDenominator.toString());
ffi[26] = string.concat("twap-trend-ratio-fee=", tradeTestConifg.twapTrendRatioFee.toString());
ffi[27] = "--bind";
ffi[28] = string.concat("test-trend-up-factor=", tradeTest.testTrendUpFactor.toString());
ffi[28] = string.concat("mean-reserve-amount18=", tradeTestConifg.meanReserveAmount18.toString());
ffi[29] = "--bind";
ffi[30] = string.concat("test-trend-down-factor=", tradeTest.testTrendDownFactor.toString());
ffi[30] = string.concat("trend-up-factor=", tradeTestConifg.trendUpFactor.toString());
ffi[31] = "--bind";
ffi[32] = string.concat("mean-cooldown=", tradeTest.cooldown.toString());
ffi[32] = string.concat("trend-down-factor=", tradeTestConifg.trendDownFactor.toString());
ffi[33] = "--bind";
ffi[34] = string.concat("jittery-binomial-bits=", tradeTest.jitteryBinomialBits.toString());

testTrend = bytes.concat(getSubparserPrelude(tradeTest.orderBookSubparser,tradeTest.uniswapSubparser), vm.ffi(ffi));

}

function getTrendBuyOrder(
Vm vm,
TrendTrade memory buyTrend
)
internal
returns (bytes memory buyOrder)
{
string[] memory ffi = new string[](33);
ffi[0] = "rain";
ffi[1] = "dotrain";
ffi[2] = "compose";
ffi[3] = "-i";
ffi[4] = "src/trend-trader.rain";
ffi[5] = "--entrypoint";
ffi[6] = "buy-calculate-io";
ffi[7] = "--entrypoint";
ffi[8] = "buy-handle-io";
ffi[9] = "--bind";
ffi[10] = string.concat("tkn-address=",buyTrend.tokenAddress.toHexString());
ffi[11] = "--bind";
ffi[12] = string.concat("tkn-decimals=",buyTrend.tokenDecimals.toString());
ffi[13] = "--bind";
ffi[14] = string.concat("reserve-address=",buyTrend.reserveToken.toHexString());
ffi[15] = "--bind";
ffi[16] = string.concat("reserve-decimals=",buyTrend.reserveDecimals.toString());
ffi[17] = "--bind";
ffi[18] = string.concat("buy-mean-reserve-amount18=", buyTrend.meanAmount.toString());
ffi[19] = "--bind";
ffi[20] = string.concat("mean-cooldown=", buyTrend.cooldown.toString());
ffi[21] = "--bind";
ffi[22] = string.concat("bounty=", buyTrend.bounty.toString());
ffi[23] = "--bind";
ffi[24] = string.concat("jittery-binomial-bits=", buyTrend.jitteryBinomialBits.toString());
ffi[25] = "--bind";
ffi[26] = string.concat("twap-long-time=", buyTrend.twapLongTime.toString());
ffi[27] = "--bind";
ffi[28] = string.concat("twap-short-time=", buyTrend.twapShortTime.toString());
ffi[29] = "--bind";
ffi[30] = string.concat("buy-trend-up-factor=", buyTrend.trendUpFactor.toString());
ffi[31] = "--bind";
ffi[32] = string.concat("buy-trend-down-factor=", buyTrend.trendDownFactor.toString());
ffi[34] = string.concat("bounty=", tradeTestConifg.bounty.toString());
ffi[35] = "--bind";
ffi[36] = string.concat("test-last-time=", tradeTestConifg.testLastTime.toString());
ffi[37] = "--bind";
ffi[38] = string.concat("test-now=", tradeTestConifg.testNow.toString());

buyOrder = bytes.concat(getSubparserPrelude(buyTrend.orderBookSubparser,buyTrend.uniswapSubparser), vm.ffi(ffi));
testTrend = bytes.concat(getSubparserPrelude(orderBookSubparser,uniswapSubparser), vm.ffi(ffi));
}

function getTrendSellOrder(
function getTrendOrder(
Vm vm,
TrendTrade memory sellTrend
TrendTrade memory trendOrderConfig,
address orderBookSubparser,
address uniswapSubparser
)
internal
returns (bytes memory sellOrder)
returns (bytes memory trendOrder)
{
string[] memory ffi = new string[](33);
string[] memory ffi = new string[](35);
ffi[0] = "rain";
ffi[1] = "dotrain";
ffi[2] = "compose";
ffi[3] = "-i";
ffi[4] = "src/trend-trader.rain";
ffi[4] = "src/trend-trader.rain";
ffi[5] = "--entrypoint";
ffi[6] = "sell-calculate-io";
ffi[6] = "calculate-io";
ffi[7] = "--entrypoint";
ffi[8] = "sell-handle-io";
ffi[8] = "handle-io";
ffi[9] = "--bind";
ffi[10] = string.concat("tkn-address=",sellTrend.tokenAddress.toHexString());
ffi[10] = string.concat("reserve-address=",trendOrderConfig.reserveToken.toHexString());
ffi[11] = "--bind";
ffi[12] = string.concat("tkn-decimals=",sellTrend.tokenDecimals.toString());
ffi[12] = string.concat("reserve-decimals=",trendOrderConfig.reserveDecimals.toString());
ffi[13] = "--bind";
ffi[14] = string.concat("reserve-address=",sellTrend.reserveToken.toHexString());
ffi[14] = string.concat("times='real-times");
ffi[15] = "--bind";
ffi[16] = string.concat("reserve-decimals=",sellTrend.reserveDecimals.toString());
ffi[16] = string.concat("jittery-binomial-bits=", trendOrderConfig.jitteryBinomialBits.toString());
ffi[17] = "--bind";
ffi[18] = string.concat("sell-mean-reserve-amount18=", sellTrend.meanAmount.toString());
ffi[18] = string.concat("mean-cooldown=", trendOrderConfig.meanCooldown.toString());
ffi[19] = "--bind";
ffi[20] = string.concat("mean-cooldown=", sellTrend.cooldown.toString());
ffi[20] = string.concat("trend-ratio-exp='uni-v3-twap-trend-ratio");
ffi[21] = "--bind";
ffi[22] = string.concat("bounty=", sellTrend.bounty.toString());
ffi[22] = string.concat("twap-trend-ratio-long-time=", trendOrderConfig.twapTrendRatioLongTime.toString());
ffi[23] = "--bind";
ffi[24] = string.concat("jittery-binomial-bits=", sellTrend.jitteryBinomialBits.toString());
ffi[24] = string.concat("twap-trend-ratio-short-time=", trendOrderConfig.twapTrendRatioShortTime.toString());
ffi[25] = "--bind";
ffi[26] = string.concat("twap-long-time=", sellTrend.twapLongTime.toString());
ffi[26] = string.concat("twap-trend-ratio-fee=", trendOrderConfig.twapTrendRatioFee.toString());
ffi[27] = "--bind";
ffi[28] = string.concat("twap-short-time=", sellTrend.twapShortTime.toString());
ffi[28] = string.concat("mean-reserve-amount18=", trendOrderConfig.meanReserveAmount18.toString());
ffi[29] = "--bind";
ffi[30] = string.concat("sell-trend-up-factor=", sellTrend.trendUpFactor.toString());
ffi[30] = string.concat("trend-up-factor=", trendOrderConfig.trendUpFactor.toString());
ffi[31] = "--bind";
ffi[32] = string.concat("sell-trend-down-factor=", sellTrend.trendDownFactor.toString());
ffi[32] = string.concat("trend-down-factor=", trendOrderConfig.trendDownFactor.toString());
ffi[33] = "--bind";
ffi[34] = string.concat("bounty=", trendOrderConfig.bounty.toString());

sellOrder = bytes.concat(getSubparserPrelude(sellTrend.orderBookSubparser,sellTrend.uniswapSubparser), vm.ffi(ffi));
trendOrder = bytes.concat(getSubparserPrelude(orderBookSubparser,uniswapSubparser), vm.ffi(ffi));
}

function getSubparserPrelude(address obSubparser, address uniswapWords) internal pure returns (bytes memory) {
Expand Down
Loading

0 comments on commit 7e9db54

Please sign in to comment.