From af516e0e2761bfaad7c71ce145811da08fe983f5 Mon Sep 17 00:00:00 2001 From: dcatki <42241987+dcatki@users.noreply.github.com> Date: Wed, 10 Jul 2024 15:49:32 +0100 Subject: [PATCH 1/4] TFT community - grid-trading.rain --- strategies/tft/grid-trading.rain | 486 +++++++++++++++++++++++++++++++ 1 file changed, 486 insertions(+) create mode 100644 strategies/tft/grid-trading.rain diff --git a/strategies/tft/grid-trading.rain b/strategies/tft/grid-trading.rain new file mode 100644 index 0000000..a19ce3b --- /dev/null +++ b/strategies/tft/grid-trading.rain @@ -0,0 +1,486 @@ +# Strat: Grid trading +# Grid trading is a strategy that involves placing buy and sell +# orders at pTFTetermined intervals above and below a set price +# level to profit from market volatility. It creates a grid of orders, +# aiming to capture profits from the regular price fluctuations without +# pTFTicting market direction. This method is particularly effective in +# sideways or ranging markets, where prices oscillate within a defined +# range, allowing traders to systematically buy low and sell high. +# +# Target Network: Base +# Quote (Input / Incoming): USDC or TFT +# Base (Output / Outgoing): TFT or USDC +# Token contract: https://basescan.org/address/0x99b2B1A2aDB02B38222ADcD057783D7e5D1FCC7D +# Token github: NA +# Liquidity protocol: Uniswap V3 +# Liquidity pool address: https://www.dextools.io/app/en/base/pair-explorer/0x1536ee1506e24e5a36be99c73136cd82907a902e?t=1717921711270 +# Liquidity pool fee: 0.3% + +networks: + bsc-community: + rpc: https://bsc-rpc.publicnode.com + chain-id: 56 + network-id: 56 + currency: BNB + +subgraphs: + bsc-community: https://api.thegraph.com/subgraphs/name/h20liquidity/binance-0xb1d6d105 + +orderbooks: + bsc-community: + address: 0xb1d6D10561D4e1792A7c6B336b0529e4bFb5Ea8F + network: bsc-community + subgraph: bsc-community + +deployers: + bsc-community: + address: 0x1eFd85E6C384fAD9B80C6D508E9098Eb91C4eD30 + network: bsc-community + +tokens: + tft-wlth: + network: bsc-community + address: 0x8f0FB159380176D324542b3a7933F0C2Fd0c2bbf + tft-busd: + bsc-binance-peg: + network: bsc-community + address: 0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56 + +orders: + # vault-id generated with `openssl rand -hex 32` + bsc-tft-sell: + orderbook: bsc-community + inputs: + - token: tft-busd + vault-id: + outputs: + - token: tft-wlth + vault-id: + bsc-tft-buy: + orderbook: bsc-community + inputs: + - token: tft-wlth + vault-id: + outputs: + - token: tft-busd + vault-id: + +scenarios: + grid-trading: + network: bsc-community + deployer: bsc-community + orderbook: bsc-community + bindings: + # The uniswap words are only requiTFT if there is a conversion between + # the input/output token and some external price. Typically this is + # not the case as the io-ratio is defined in terms of the input/output + # token and the io-ratio-multiplier is set to the identity function. + uniswap-words: 0xee873E21F8a6A256cb9f53BE491E569eA6cdd63E + + # 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: 0x33128a8fC17869897dcE68Ed026d694621f6FDfD + uniswap-v3-init-code: '[uniswap-v3-init-code]' + + # Orderbook subparser for orderbook words. + orderbook-subparser: 0x90CAF23eA7E507BB722647B0674e50D8d6468234 + scenarios: + buy: + bindings: + # TFT/USDC base ratio and increment. + io-ratio-base: 40 + io-ratio-growth: 2.5 + + # Base amount of USDC tokens to offer and increment. + tranche-size-base: 5 + tranche-size-growth: 1 + + scenarios: + grid: + bindings: + tranche-space-per-second: 0 + tranche-space-recharge-delay: 300 + min-tranche-space-diff: 0.1 + tranche-space-snap-threshold: 0.01 + io-ratio-multiplier: '''io-ratio-multiplier-identity' + amount-is-output: 1 + tranche-space-shyness: 0 + initial-tranche-space: 0 + io-ratio-expr: '''linear-growth' + tranche-size-expr: '''linear-growth' + scenarios: + prod: + bindings: + get-last-tranche: '''get-last-tranche-prod' + set-last-tranche: '''set-last-tranche-prod' + plottables: '''plottables-prod' + tranche-space-shyness: 0 + initial-tranche-space: 0 + init: + runs: 100 + bindings: + get-last-tranche: '''get-last-tranche-test-init' + set-last-tranche: '''set-last-tranche-test' + plottables: '''plottables-test' + test-last-update-time: 0 + test-now: 0 + test: + runs: 10000 + bindings: + get-last-tranche: '''get-last-tranche-test' + set-last-tranche: '''set-last-tranche-test' + plottables: '''plottables-test' + max-test-tranche-space: 20 + test-last-update-time: 0 + test-now: 0 + sell: + bindings: + # USDC/TFT base ratio and increment. + io-ratio-base: 0.020 + io-ratio-growth: 0.002 + + # Base amount of USDC tokens to received and increment. + tranche-size-base: 5 + tranche-size-growth: 1 + + scenarios: + grid: + bindings: + tranche-space-per-second: 0 + tranche-space-recharge-delay: 300 + min-tranche-space-diff: 0.1 + tranche-space-snap-threshold: 0.01 + io-ratio-multiplier: '''io-ratio-multiplier-identity' + amount-is-output: 0 + tranche-space-shyness: 0 + initial-tranche-space: 0 + io-ratio-expr: '''linear-growth' + tranche-size-expr: '''linear-growth' + scenarios: + prod: + bindings: + get-last-tranche: '''get-last-tranche-prod' + set-last-tranche: '''set-last-tranche-prod' + plottables: '''plottables-prod' + tranche-space-shyness: 0 + initial-tranche-space: 0 + init: + runs: 100 + bindings: + get-last-tranche: '''get-last-tranche-test-init' + set-last-tranche: '''set-last-tranche-test' + plottables: '''plottables-test' + test-last-update-time: 0 + test-now: 0 + test: + runs: 10000 + bindings: + get-last-tranche: '''get-last-tranche-test' + set-last-tranche: '''set-last-tranche-test' + plottables: '''plottables-test' + max-test-tranche-space: 20 + test-last-update-time: 0 + test-now: 0 + +charts: + bsc-tft-buy-deployment: + scenario: grid-trading.buy.grid.init + metrics: + - label: Initial USDC sold + value: 0.6 + description: 'Amount of USDC sold to buy TFT in the first tranche (stack item 0.6)' + - label: Initial TFT bought + value: 0.5.2 + description: 'Amount of TFT purchased in the first tranche (stack item 0.5.2)' + - label: Initial io-ratio + value: 0.7 + description: '# TFT purchased per USDC spent (stack item 0.7)' + - label: Starting tranche + value: 0.2.0 + description: 'This strategy starts executing buys at the initial tranche (stack item 0.2.0)' + - label: Initial buy price + value: 0.5.3 + precision: 4 + unit-suffix: " USDC" + description: 'Price you pay for 1 TFT in USDC, visible on dextools (stack item 0.5.3)' + plots: + + buy-simulation: + scenario: grid-trading.buy.grid.test + plots: + USDT sold per tranche: + x: + label: 'Tranche space' + y: + label: 'USDT spent' + marks: + - type: line + options: + x: 0.0 + y: 0.6 + TFT bought per tranche: + x: + label: 'Tranche space' + y: + label: 'TFT bought' + marks: + - type: line + options: + x: 0.0 + y: 0.5.2 + 'io-ratio per tranche': + subtitle: 'Ratio of TFT bought per 1 USDT sold per tranche' + x: + label: 'Tranche space' + y: + label: 'TFT bought per 1 USDT' + marks: + - type: line + options: + x: 0.0 + y: 0.7 + buy price by tranche: + subtitle: 'Price paid for 1 TFT in USDT, visible on dextools as TFT/USDT pair' + x: + label: 'Tranche space' + y: + label: '1 TFT priced in USDT' + marks: + - type: line + options: + x: 0.0 + y: 0.5.3 + + bsc-tft-sell-deployment: + scenario: grid-trading.sell.grid.init + metrics: + - label: Initial TFT sold + value: 0.6 + description: 'Amount of TFT sold for USDC in the first tranche (stack item 0.6)' + - label: Initial USDC bought + value: 0.5.2 + description: 'Amount of USDC purchased by selling TFT in the first tranche (stack item 0.5.2)' + - label: Initial io-ratio + value: 0.7 + description: '# USDC purchased per TFT spent (stack item 0.7)' + - label: Starting tranche + value: 0.2.0 + description: 'This strategy starts executing sells at the initial tranche (stack item 0.2.0)' + - label: Initial sell price + value: 0.7 + precision: 4 + unit-suffix: "USDC" + description: 'Price you pay for 1 TFT in USDC, visible on dextools (stack item 0.7)' + plots: + + sell-simulation: + scenario: grid-trading.sell.grid.test + plots: + TFT sold per tranche: + x: + label: 'Tranche space' + y: + label: 'TFT spent' + marks: + - type: line + options: + x: 0.0 + y: 0.6 + USDC bought per tranche: + x: + label: 'Tranche space' + y: + label: 'USDC bought' + marks: + - type: line + options: + x: 0.0 + y: 0.5.2 + 'io-ratio per tranche': + subtitle: 'Ratio of USDC bought per 1 TFT sold per tranche' + x: + label: 'Tranche space' + y: + label: 'TFT bought per 1 USDC' + marks: + - type: line + options: + x: 0.0 + y: 0.7 + sell price by tranche: + subtitle: 'Price paid for 1 TFT in USDC, visible on dextools as TFT/USDC pair' + x: + label: 'Tranche space' + y: + label: '1 TFT priced in USDC' + marks: + - type: line + options: + x: 0.0 + y: 0.7 + +deployments: + bsc-tft-buy: + scenario: grid-trading.buy.grid.prod + order: bsc-tft-buy + bsc-tft-sell: + scenario: grid-trading.sell.grid.prod + order: bsc-tft-sell +--- +#tranche-space-per-second !The amount of tranche space that is recharged per second. +#tranche-space-recharge-delay !The duration in seconds that no recharging occurs after a trade occurs. + +#tranche-size-expr !The binding to get the tranche size for the current tranche space. +#tranche-size-base !Base tranche size is the size of the smallest tranche, denominated in output token. +#tranche-size-growth !The exponential growth factor of the size of each tranche. E.g. 0.01 is 1% output amount growth per tranche. + +#io-ratio-expr !The binding to get the IO ratio for the current tranche space. +#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-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. +#reference-reserve-decimals !The number of decimals of the reserve token. +#twap-duration !The duration in seconds of the TWAP window for dollar equivalence conversions. +#twap-fee !The uniswap fee tier to use for the TWAP. + +#min-tranche-space-diff !The minimum tranche space difference that is allowed per trade. Prevents dusting the strat to stop it recharging. +#tranche-space-snap-threshold !The threshold in tranche space to snap to the nearest tranche to avoid dust issues at the edges. + +#initial-tranche-space !The initial tranche space when the order is first deployed. +#get-last-tranche !The binding to get the last tranche space and update time. +#set-last-tranche !The binding to set the last tranche space and update time. + +#test-tranche-space-before !Returned by get-test-last-tranche to allow the tranche space before to be bound for testing. +#test-last-update-time !Returned by get-test-last-tranche to allow the last update time to be bound for testing. +#test-now !Returned by get-test-last-tranche to allow the current time to be bound for testing. + +#io-ratio-multiplier !The binding to get the IO ratio multiplier. + +#amount-is-output !Whether the amount is an output or input amount. Non-zero means output (i.e. normal orderbook behaviour), zero means input. + +#init-key "init" +#tranche-space-key "tranche-space" +#update-time-key "update-time" + +#plottables !The binding for additional things we want to plot during testing. + +#uniswap-words !The subparser for the Uniswap words +#uniswap-v3-factory !Uniswap v3 factory address. +#uniswap-v3-init-code !Uniswap v3 init code hash. +#orderbook-subparser !The subparser for the Orderbook + +#plottables-test + amount + io-ratio:, + input-amount: mul(amount io-ratio), + effective-price: inv(io-ratio); + +#plottables-prod + amount + io-ratio:; + +#get-last-tranche-prod + is-initialized: get(hash(order-hash() init-key)), + tranche-space-before: if( + is-initialized + get(hash(order-hash() tranche-space-key)) + initial-tranche-space + ), + last-update-time: if( + is-initialized + get(hash(order-hash() update-time-key)) + now() + ), + current-time: now(); + +#tranche-space-shyness !The shyness of the liquidity in tranches. E.g. 0.9 is 90% shy. +#set-last-tranche-prod + tranche-space current-time:, + shy-tranche-space: if( + is-zero(frac(tranche-space)) + add(tranche-space tranche-space-shyness) + tranche-space), + :set(hash(order-hash() init-key) 1), + :set(hash(order-hash() tranche-space-key) shy-tranche-space), + :set(hash(order-hash() update-time-key) current-time); + +/* Forward the bindings through as is to the caller. */ +#max-test-tranche-space !The maximum tranche space that will appear on the test chart. +#get-last-tranche-test + tranche-space-before: mod(test-tranche-space-before max-test-tranche-space), + last-update-time: test-last-update-time, + current-time: test-now; +#get-last-tranche-test-init + tranche-space-before: initial-tranche-space, + last-update-time: test-last-update-time, + current-time: test-now; +/* There's nothing to set if we're just rebinding in tests. */ +#set-last-tranche-test + tranche-space current-time:; + +#exponential-growth + base rate t:, + _: exponential-growth(base rate t); + +#linear-growth + base rate t:, + _: linear-growth(base rate t); + +#constant-growth + base _ _:, + _: base; + +#calculate-tranche + tranche-space-before + last-update-time + current-time: call<'get-last-tranche>(), + recharge-duration: saturating-sub(current-time add(last-update-time tranche-space-recharge-delay)), + recharged-tranche-space: mul(recharge-duration tranche-space-per-second), + /* repeat current-time for easy access by callers */ + _: current-time, + tranche-space-now: saturating-sub(tranche-space-before recharged-tranche-space), + tranche-space-available: headroom(tranche-space-now), + tranche-total-size: call<'tranche-size-expr>(tranche-size-base tranche-size-growth floor(tranche-space-now)); + +#io-ratio-multiplier-sell + multiplier: uniswap-v3-twap-output-ratio(reference-stable reference-reserve twap-duration 0 uniswap-v3-factory uniswap-v3-init-code twap-fee); + +#io-ratio-multiplier-buy + multiplier: uniswap-v3-twap-output-ratio(reference-reserve reference-stable twap-duration 0 uniswap-v3-factory uniswap-v3-init-code twap-fee); + +#io-ratio-multiplier-identity + multiplier: 1; + +#calculate-io + using-words-from uniswap-words orderbook-subparser + tranche-space-now + tranche-space-available + tranche-total-size: call<'calculate-tranche>(), + 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)), + io-ratio: final-io-ratio, + :call<'plottables>(amount io-ratio); + +#handle-io + current-time + tranche-space-before + _ + 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())), + 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 */ + tranche-space-after-snapped: snap-to-unit(tranche-space-snap-threshold tranche-space-after), + :ensure( + greater-than-or-equal-to(tranche-space-after-snapped add(tranche-space-before min-tranche-space-diff)) + "Minimum trade size not met." + ), + :call<'set-last-tranche>(tranche-space-after-snapped current-time); From 6ecf4b77e344b95bd0809b3d96c20dbd7871c144 Mon Sep 17 00:00:00 2001 From: Siddharth2207 Date: Wed, 10 Jul 2024 23:06:13 +0530 Subject: [PATCH 2/4] tft grid --- strategies/tft/grid-trading.rain | 23 +++-- test/tft/TftGridTrading.t.sol | 165 +++++++++++++++++++++++++++++++ 2 files changed, 176 insertions(+), 12 deletions(-) create mode 100644 test/tft/TftGridTrading.t.sol diff --git a/strategies/tft/grid-trading.rain b/strategies/tft/grid-trading.rain index a19ce3b..8d1785d 100644 --- a/strategies/tft/grid-trading.rain +++ b/strategies/tft/grid-trading.rain @@ -34,7 +34,7 @@ orderbooks: deployers: bsc-community: - address: 0x1eFd85E6C384fAD9B80C6D508E9098Eb91C4eD30 + address: 0x379b966DC6B117dD47b5Fc5308534256a4Ab1BCC network: bsc-community tokens: @@ -42,7 +42,6 @@ tokens: network: bsc-community address: 0x8f0FB159380176D324542b3a7933F0C2Fd0c2bbf tft-busd: - bsc-binance-peg: network: bsc-community address: 0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56 @@ -52,18 +51,18 @@ orders: orderbook: bsc-community inputs: - token: tft-busd - vault-id: + vault-id: 0x90879c42e70872f7bee992d25fc49c953f0b895ce5f7917fae32d2069bc2fc02 outputs: - token: tft-wlth - vault-id: + vault-id: 0x90879c42e70872f7bee992d25fc49c953f0b895ce5f7917fae32d2069bc2fc02 bsc-tft-buy: orderbook: bsc-community inputs: - token: tft-wlth - vault-id: + vault-id: 0x90879c42e70872f7bee992d25fc49c953f0b895ce5f7917fae32d2069bc2fc02 outputs: - token: tft-busd - vault-id: + vault-id: 0x90879c42e70872f7bee992d25fc49c953f0b895ce5f7917fae32d2069bc2fc02 scenarios: grid-trading: @@ -75,21 +74,21 @@ scenarios: # the input/output token and some external price. Typically this is # not the case as the io-ratio is defined in terms of the input/output # token and the io-ratio-multiplier is set to the identity function. - uniswap-words: 0xee873E21F8a6A256cb9f53BE491E569eA6cdd63E + uniswap-words: 0x80DE00e3cA96AE0569426A1bb1Ae22CD4181dE6F # 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: 0x33128a8fC17869897dcE68Ed026d694621f6FDfD - uniswap-v3-init-code: '[uniswap-v3-init-code]' + uniswap-v3-factory: '[pancake-v3-factory]' + uniswap-v3-init-code: '[pancake-v3-init-code]' # Orderbook subparser for orderbook words. - orderbook-subparser: 0x90CAF23eA7E507BB722647B0674e50D8d6468234 + orderbook-subparser: 0x59401c9302e79eb8ac6aea659b8b3ae475715e86 scenarios: buy: bindings: # TFT/USDC base ratio and increment. - io-ratio-base: 40 + io-ratio-base: 75 io-ratio-growth: 2.5 # Base amount of USDC tokens to offer and increment. @@ -137,7 +136,7 @@ scenarios: sell: bindings: # USDC/TFT base ratio and increment. - io-ratio-base: 0.020 + io-ratio-base: 0.010 io-ratio-growth: 0.002 # Base amount of USDC tokens to received and increment. diff --git a/test/tft/TftGridTrading.t.sol b/test/tft/TftGridTrading.t.sol new file mode 100644 index 0000000..ff740d4 --- /dev/null +++ b/test/tft/TftGridTrading.t.sol @@ -0,0 +1,165 @@ +// SPDX-License-Identifier: CAL +pragma solidity =0.8.25; +import { + IOrderBookV3, + IO, + OrderV2, + OrderConfigV2, + TakeOrderConfigV2, + TakeOrdersConfigV2 +} from "rain.orderbook.interface/interface/IOrderBookV3.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 { EvaluableConfigV3, SignedContextV1} from "rain.interpreter.interface/interface/IInterpreterCallerV2.sol"; +import {IInterpreterV2,SourceIndexV2} from "rain.interpreter.interface/interface/IInterpreterV2.sol"; +import {IInterpreterStoreV2} from "rain.interpreter.interface/interface/IInterpreterStoreV2.sol"; +import {StrategyTests, IRouteProcessor, LibStrategyDeployment, LibComposeOrders} from "h20.test-std/StrategyTests.sol"; +import {LibEncodedDispatch} from "rain.interpreter.interface/lib/caller/LibEncodedDispatch.sol"; +import {StateNamespace, LibNamespace, FullyQualifiedNamespace} from "rain.interpreter.interface/lib/ns/LibNamespace.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"; + +uint256 constant VAULT_ID = uint256(keccak256("vault")); + +/// @dev https://bscscan.com/address/0x8f0FB159380176D324542b3a7933F0C2Fd0c2bbf +IERC20 constant TFT_TOKEN = IERC20(0x8f0FB159380176D324542b3a7933F0C2Fd0c2bbf); + +/// @dev https://bscscan.com/address/0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56 +IERC20 constant BUSD_TOKEN = IERC20(0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56); + +function bscTftIo() pure returns (IO memory) { + return IO(address(TFT_TOKEN), 7, VAULT_ID); +} + +function bscBusdIo() pure returns (IO memory) { + return IO(address(BUSD_TOKEN), 18, VAULT_ID); +} + +contract ThreefoldStabiliseTest is StrategyTests { + + using SafeERC20 for IERC20; + using Strings for address; + + uint256 constant FORK_BLOCK_NUMBER = 40355587; + + function selectFork() internal { + uint256 fork = vm.createFork(vm.envString("RPC_URL_BSC")); + vm.selectFork(fork); + vm.rollFork(FORK_BLOCK_NUMBER); + } + + function getNamespace() public view returns (FullyQualifiedNamespace) { + return LibNamespace.qualifyNamespace(StateNamespace.wrap(0), address(this)); + } + + function setUp() public { + selectFork(); + INTERPRETER = IInterpreterV2(0x6E4b01603edBDa617002A077420E98C86595748E); + STORE = IInterpreterStoreV2(0xF836f2746B407136a5bCB515495949B1edB75184); + PARSER = IParserV1(0xb06202aA3Fe7d85171fB7aA5f17011d17E63f382); + EXPRESSION_DEPLOYER = IExpressionDeployerV3(0x379b966DC6B117dD47b5Fc5308534256a4Ab1BCC); + + ORDERBOOK = IOrderBookV3(0xb1d6D10561D4e1792A7c6B336b0529e4bFb5Ea8F); + ARB_INSTANCE = IOrderBookV3ArbOrderTaker(0xaCD99A1BE78926b05De19237E2C35B2eDa0292B8); + ROUTE_PROCESSOR = IRouteProcessor(address(0xd36990D74b947eC4Ad9f52Fe3D49d14AdDB51E44)); + + EXTERNAL_EOA = address(0x654FEf5Fb8A1C91ad47Ba192F7AA81dd3C821427); + APPROVED_EOA = address(0x669845c29D9B1A64FFF66a55aA13EB4adB889a88); + ORDER_OWNER = address(0x19f95a84aa1C48A2c6a7B2d5de164331c86D030C); + } + + function testTftGridTradingBuy() public { + + IO[] memory inputVaults = new IO[](1); + inputVaults[0] = bscTftIo(); + + IO[] memory outputVaults = new IO[](1); + outputVaults[0] = bscBusdIo(); + + uint256 expectedRatio = 75e18; + uint256 expectedMaxOutput = 5e18; + + + LibStrategyDeployment.StrategyDeployment memory strategy = LibStrategyDeployment.StrategyDeployment( + getEncodedSellTftRoute(address(ARB_INSTANCE)), + getEncodedBuyTftRoute(address(ARB_INSTANCE)), + 0, + 0, + 1e7, + 100000e18, + expectedRatio, + expectedMaxOutput, + "strategies/tft/grid-trading.rain", + "grid-trading.buy.grid.prod", + "./lib/h20.test-std/lib/rain.orderbook", + "./lib/h20.test-std/lib/rain.orderbook/Cargo.toml", + inputVaults, + outputVaults + ); + + // OrderV2 memory order = addOrderDepositOutputTokens(strategy); + checkStrategyCalculationsArbOrder(strategy); + + } + + function testTftGridTradingSell() public { + + IO[] memory inputVaults = new IO[](1); + inputVaults[0] = bscBusdIo(); + + IO[] memory outputVaults = new IO[](1); + outputVaults[0] = bscTftIo(); + + uint256 expectedRatio = 0.01e18; + uint256 expectedMaxOutput = 500e18; + + LibStrategyDeployment.StrategyDeployment memory strategy = LibStrategyDeployment.StrategyDeployment( + getEncodedBuyTftRoute(address(ARB_INSTANCE)), + getEncodedSellTftRoute(address(ARB_INSTANCE)), + 0, + 0, + 1e18, + 10000000e7, + expectedRatio, + expectedMaxOutput, + "strategies/tft/grid-trading.rain", + "grid-trading.sell.grid.prod", + "./lib/h20.test-std/lib/rain.orderbook", + "./lib/h20.test-std/lib/rain.orderbook/Cargo.toml", + inputVaults, + outputVaults + ); + + // OrderV2 memory order = addOrderDepositOutputTokens(strategy); + checkStrategyCalculationsArbOrder(strategy); + + } + + function getEncodedBuyTftRoute(address toAddress) internal pure returns (bytes memory) { + bytes memory ROUTE_PRELUDE = + hex"02" + hex"e9e7CEA3DedcA5984780Bafc599bD69ADd087D56" + hex"01" + hex"ffff" + hex"00" + hex"4A2Dbaa979A3F4Cfb8004eA5743fAF159DD2665A" + hex"00"; + return abi.encode(bytes.concat(ROUTE_PRELUDE, abi.encodePacked(address(toAddress)))); + } + + function getEncodedSellTftRoute(address toAddress) internal pure returns (bytes memory) { + bytes memory ROUTE_PRELUDE = + hex"02" + hex"8f0FB159380176D324542b3a7933F0C2Fd0c2bbf" + hex"01" + hex"ffff" + hex"00" + hex"4A2Dbaa979A3F4Cfb8004eA5743fAF159DD2665A" + hex"01"; + return abi.encode(bytes.concat(ROUTE_PRELUDE, abi.encodePacked(address(toAddress)))); + } + + +} \ No newline at end of file From c6da7313b42f3d5ae22e9534c817b7adfd530703 Mon Sep 17 00:00:00 2001 From: Siddharth2207 Date: Wed, 10 Jul 2024 23:06:30 +0530 Subject: [PATCH 3/4] debug ci --- .github/workflows/test.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0c4c924..ba43fdd 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,9 +13,12 @@ jobs: CI_SEPOLIA_METABOARD_URL: ${{ vars.CI_SEPOLIA_METABOARD_URL }} CI_DEPLOY_POLYGON_RPC_URL: ${{ secrets.CI_DEPLOY_POLYGON_RPC_URL }} RPC_URL_ETHEREUM_FORK: ${{ secrets.RPC_URL_ETHEREUM_FORK }} - RPC_URL_POLYGON: ${{ secrets.CI_DEPLOY_POLYGON_RPC_URL || vars.CI_DEPLOY_POLYGON_RPC_URL }} + RPC_URL_ARBITRUM: ${{ secrets.CI_DEPLOY_ARBITRUM_RPC_URL || vars.CI_DEPLOY_ARBITRUM_RPC_URL }} RPC_URL_BASE: ${{ secrets.CI_DEPLOY_BASE_RPC_URL || vars.CI_DEPLOY_BASE_RPC_URL }} RPC_URL_FLARE: ${{ secrets.CI_DEPLOY_FLARE_RPC_URL || vars.CI_DEPLOY_FLARE_RPC_URL }} + RPC_URL_POLYGON: ${{ secrets.CI_DEPLOY_POLYGON_RPC_URL || vars.CI_DEPLOY_POLYGON_RPC_URL }} + RPC_URL_ETH: ${{ secrets.CI_DEPLOY_ETH_RPC_URL || vars.CI_DEPLOY_ETH_RPC_URL }} + RPC_URL_BSC: ${{ secrets.CI_DEPLOY_BSC_RPC_URL || vars.CI_DEPLOY_BSC_RPC_URL }} steps: From a862b1155af79ce6ea3142b2eba70f21d1b7bd30 Mon Sep 17 00:00:00 2001 From: Siddharth2207 Date: Thu, 11 Jul 2024 00:32:05 +0530 Subject: [PATCH 4/4] debug ci --- test/tft/TftGridTrading.t.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/tft/TftGridTrading.t.sol b/test/tft/TftGridTrading.t.sol index ff740d4..fcabe98 100644 --- a/test/tft/TftGridTrading.t.sol +++ b/test/tft/TftGridTrading.t.sol @@ -45,7 +45,7 @@ contract ThreefoldStabiliseTest is StrategyTests { uint256 constant FORK_BLOCK_NUMBER = 40355587; function selectFork() internal { - uint256 fork = vm.createFork(vm.envString("RPC_URL_BSC")); + uint256 fork = vm.createFork("https://1rpc.io/bnb"); vm.selectFork(fork); vm.rollFork(FORK_BLOCK_NUMBER); }