From bb42280484791fc5648c74f828bdf885fcd2b1c5 Mon Sep 17 00:00:00 2001 From: dcatki <42241987+dcatki@users.noreply.github.com> Date: Fri, 5 Jul 2024 18:24:15 +0100 Subject: [PATCH 1/5] Create limit-order-single.rain --- strategies/limit-order-single.rain | 1 + 1 file changed, 1 insertion(+) create mode 100644 strategies/limit-order-single.rain diff --git a/strategies/limit-order-single.rain b/strategies/limit-order-single.rain new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/strategies/limit-order-single.rain @@ -0,0 +1 @@ + From f755f2bccf601ec800692ffda5c278288035c069 Mon Sep 17 00:00:00 2001 From: dcatki <42241987+dcatki@users.noreply.github.com> Date: Fri, 5 Jul 2024 18:29:53 +0100 Subject: [PATCH 2/5] Update limit-order-single.rain Needs buy and sell Not sure about the final check order number part --- strategies/limit-order-single.rain | 136 +++++++++++++++++++++++++++++ 1 file changed, 136 insertions(+) diff --git a/strategies/limit-order-single.rain b/strategies/limit-order-single.rain index 8b13789..1512310 100644 --- a/strategies/limit-order-single.rain +++ b/strategies/limit-order-single.rain @@ -1 +1,137 @@ +# A single limit order trade +# Place an order to buy or sell a specific quantity of an asset at a predetermined price or better +# Decide the maximum price you are willing to pay to buy an asset (buy limit order) +# Or the minimum price you are willing to accept to sell an asset (sell limit order). +# Specify the asset, quantity, and limit price +# Polygon +# DOLZ +networks: + polygon-dolz: + rpc: https://polygon-mainnet.g.alchemy.com/v2/y3BXawVv5uuP_g8BaDlKbKoTBGHo9zD9 + chain-id: 137 + network-id: 137 + currency: MATIC + +subgraphs: + polygon-dolz: https://api.thegraph.com/subgraphs/name/h20liquidity/polygon-0xc95a5f8e + +orderbooks: + polygon-dolz: + address: 0xc95A5f8eFe14d7a20BD2E5BAFEC4E71f8Ce0B9A6 + network: polygon-dolz + subgraph: polygon-dolz + +deployers: + polygon-dolz: + address: 0xB3aC858bEAf7814892d3946A8C109A7D701DF8E7 + network: polygon-dolz + +tokens: + polygon-dolz: + network: polygon-dolz + address: 0x6ab4E20f36ca48B61ECd66c0450fDf665Fa130be + polygon-usdt: + network: polygon-dolz + address: 0xc2132D05D31c914a87C6611C10748AEb04B58e8F + +orders: + # vault-id generated with `openssl rand -hex 32` + polygon-dolz-sell: + orderbook: polygon-dolz + inputs: + - token: polygon-usdt + vault-id: 0x6049f8ee79b82dd5bc82b368114bb0a69f34d539b04b43208241e1f68da134a8 + outputs: + - token: polygon-dolz + vault-id: 0x6049f8ee79b82dd5bc82b368114bb0a69f34d539b04b43208241e1f68da134a8 + +scenarios: + limit-orders: + network: polygon-dolz + deployer: polygon-dolz + orderbook: polygon-dolz + bindings: + # Ask for now, registry in future. + uniswap-words: 0xbc609623F5020f6Fc7481024862cD5EE3FFf52D7 + orderbook-subparser: 0x8f037f2a3fF2dee510486D9C63A47A245991a4C1 + # io-ratio and amount for first order. + io-ratio-1: 0.0080 + ouptut-amount-1: 100 + + scenarios: + prod: + bindings: + plottables: '''plottables-prod' + chart: + runs: 1 + bindings: + plottables: '''plottables-plot' + + +charts: + limit-orders: + scenario: limit-orders.chart + metrics: + - label: io-ratio-1 + value: 0.3.0 + - label: amount-1 + value: 0.3.1 + +deployments: + dolz-sell: + scenario: limit-orders.prod + order: polygon-dolz-sell +--- +#uniswap-words !The subparser for the Uniswap words +#orderbook-subparser !The subparser for the Orderbook words + +#io-ratio-1 !IO ratio for first order. +#ouptut-amount-1 !Output amount for first order. + +#count-key "count-key" +#plottables !Binding to plot values. + +#plottables-prod + :; + +#plottables-plot + _: io-ratio-1, + _: ouptut-amount-1, + +#calculate-io + using-words-from uniswap-words orderbook-subparser + + trade-count-key: hash(order-hash() count-key), + trade-count: get(trade-count-key), + _ _:call<'get-ratio-amount>(trade-count), + :call<'plottables>(); + +#handle-io + trade-count-key: hash(order-hash() count-key), + trade-count: get(trade-count-key), + :set(trade-count-key add(trade-count 1)); + +#get-ratio-amount + trade-count: , + output-amount: if(equal-to(trade-count 0) + ouptut-amount-1 + if(equal-to(trade-count 1) + ouptut-amount-2 + if(equal-to(trade-count 2) + ouptut-amount-3 + 1 + ) + ) + ), + io-ratio: if(equal-to(trade-count 0) + io-ratio-1 + if(equal-to(trade-count 1) + io-ratio-2 + if(equal-to(trade-count 2) + io-ratio-3 + max-value() + ) + ) + ); + From 72ffcdfe062390bc2ce6af0e2549d9a7fea58e0d Mon Sep 17 00:00:00 2001 From: dcatki <42241987+dcatki@users.noreply.github.com> Date: Sun, 7 Jul 2024 21:08:50 +0100 Subject: [PATCH 3/5] Update and rename strategies/limit-order-single.rain to strategies/wlth/limit-order-single.rain Hopefully @Siddharth2207 ive got the buys and sells right, updated for BASE/WLTH --- strategies/limit-order-single.rain | 137 ------------------ strategies/wlth/limit-order-single.rain | 183 ++++++++++++++++++++++++ 2 files changed, 183 insertions(+), 137 deletions(-) delete mode 100644 strategies/limit-order-single.rain create mode 100644 strategies/wlth/limit-order-single.rain diff --git a/strategies/limit-order-single.rain b/strategies/limit-order-single.rain deleted file mode 100644 index 1512310..0000000 --- a/strategies/limit-order-single.rain +++ /dev/null @@ -1,137 +0,0 @@ -# A single limit order trade -# Place an order to buy or sell a specific quantity of an asset at a predetermined price or better -# Decide the maximum price you are willing to pay to buy an asset (buy limit order) -# Or the minimum price you are willing to accept to sell an asset (sell limit order). -# Specify the asset, quantity, and limit price -# Polygon -# DOLZ - -networks: - polygon-dolz: - rpc: https://polygon-mainnet.g.alchemy.com/v2/y3BXawVv5uuP_g8BaDlKbKoTBGHo9zD9 - chain-id: 137 - network-id: 137 - currency: MATIC - -subgraphs: - polygon-dolz: https://api.thegraph.com/subgraphs/name/h20liquidity/polygon-0xc95a5f8e - -orderbooks: - polygon-dolz: - address: 0xc95A5f8eFe14d7a20BD2E5BAFEC4E71f8Ce0B9A6 - network: polygon-dolz - subgraph: polygon-dolz - -deployers: - polygon-dolz: - address: 0xB3aC858bEAf7814892d3946A8C109A7D701DF8E7 - network: polygon-dolz - -tokens: - polygon-dolz: - network: polygon-dolz - address: 0x6ab4E20f36ca48B61ECd66c0450fDf665Fa130be - polygon-usdt: - network: polygon-dolz - address: 0xc2132D05D31c914a87C6611C10748AEb04B58e8F - -orders: - # vault-id generated with `openssl rand -hex 32` - polygon-dolz-sell: - orderbook: polygon-dolz - inputs: - - token: polygon-usdt - vault-id: 0x6049f8ee79b82dd5bc82b368114bb0a69f34d539b04b43208241e1f68da134a8 - outputs: - - token: polygon-dolz - vault-id: 0x6049f8ee79b82dd5bc82b368114bb0a69f34d539b04b43208241e1f68da134a8 - -scenarios: - limit-orders: - network: polygon-dolz - deployer: polygon-dolz - orderbook: polygon-dolz - bindings: - # Ask for now, registry in future. - uniswap-words: 0xbc609623F5020f6Fc7481024862cD5EE3FFf52D7 - orderbook-subparser: 0x8f037f2a3fF2dee510486D9C63A47A245991a4C1 - # io-ratio and amount for first order. - io-ratio-1: 0.0080 - ouptut-amount-1: 100 - - scenarios: - prod: - bindings: - plottables: '''plottables-prod' - chart: - runs: 1 - bindings: - plottables: '''plottables-plot' - - -charts: - limit-orders: - scenario: limit-orders.chart - metrics: - - label: io-ratio-1 - value: 0.3.0 - - label: amount-1 - value: 0.3.1 - -deployments: - dolz-sell: - scenario: limit-orders.prod - order: polygon-dolz-sell ---- -#uniswap-words !The subparser for the Uniswap words -#orderbook-subparser !The subparser for the Orderbook words - -#io-ratio-1 !IO ratio for first order. -#ouptut-amount-1 !Output amount for first order. - -#count-key "count-key" -#plottables !Binding to plot values. - -#plottables-prod - :; - -#plottables-plot - _: io-ratio-1, - _: ouptut-amount-1, - -#calculate-io - using-words-from uniswap-words orderbook-subparser - - trade-count-key: hash(order-hash() count-key), - trade-count: get(trade-count-key), - _ _:call<'get-ratio-amount>(trade-count), - :call<'plottables>(); - -#handle-io - trade-count-key: hash(order-hash() count-key), - trade-count: get(trade-count-key), - :set(trade-count-key add(trade-count 1)); - -#get-ratio-amount - trade-count: , - output-amount: if(equal-to(trade-count 0) - ouptut-amount-1 - if(equal-to(trade-count 1) - ouptut-amount-2 - if(equal-to(trade-count 2) - ouptut-amount-3 - 1 - ) - ) - ), - io-ratio: if(equal-to(trade-count 0) - io-ratio-1 - if(equal-to(trade-count 1) - io-ratio-2 - if(equal-to(trade-count 2) - io-ratio-3 - max-value() - ) - ) - ); - diff --git a/strategies/wlth/limit-order-single.rain b/strategies/wlth/limit-order-single.rain new file mode 100644 index 0000000..ed3a963 --- /dev/null +++ b/strategies/wlth/limit-order-single.rain @@ -0,0 +1,183 @@ +# Limit Order Strategy +# 1 buy and sell target +# Set buy price and amount and sell price and amount +# Target Network: Base +# Quote (Input / Incoming): USDC or WLTH +# Base (Output / Outgoing): WLTH 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: + base: + rpc: https://mainnet.base.org + chain-id: 8453 + network-id: 8453 + currency: ETH + +subgraphs: + base: https://api.thegraph.com/subgraphs/name/h20liquidity/base-0x2aee87 + +orderbooks: + base: + address: 0x2AeE87D75CD000583DAEC7A28db103B1c0c18b76 + network: base + subgraph: base + +deployers: + base: + address: 0xfca89cD12Ba1346b1ac570ed988AB43b812733fe + network: base + +tokens: + base-wlth: + network: base + address: 0x99b2B1A2aDB02B38222ADcD057783D7e5D1FCC7D + base-usdc: + network: base + address: 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913 + +orders: + base-wlth-sell: + orderbook: base + inputs: + - token: base-usdc + vault-id: + outputs: + - token: base-wlth + vault-id: + base-wlth-buy: + orderbook: base + inputs: + - token: base-wlth + vault-id: + outputs: + - token: base-usdc + vault-id: + +scenarios: + limit-order: + network: base + deployer: base + orderbook: base + bindings: + # Ask for now, registry in future. + uniswap-words: 0xbc609623F5020f6Fc7481024862cD5EE3FFf52D7 + orderbook-subparser: 0x8f037f2a3fF2dee510486D9C63A47A245991a4C1 + + scenarios: + buy: + bindings: + # io-ratio is calculated as 1 divided by the token price + # So 1/(WLTH priced in USDC) + io-ratio-1: 100 + + # amount is the trade size + ouptut-amount-1: 100 + + scenarios: + prod: + bindings: + plottables: '''plottables-prod' + chart: + runs: 1 + bindings: + plottables: '''plottables-plot' + sell: + bindings: + # io-ratio is calculated as 1 divided by the token price + # So USDC priced in WLTH + io-ratio-1: 100 + + # amount is the trade size + ouptut-amount-1: 100 + + scenarios: + prod: + bindings: + plottables: '''plottables-prod' + chart: + runs: 1 + bindings: + plottables: '''plottables-plot' + +charts: + base-wlth-buy-metrics: + scenario: limit-order.buy.metric + metrics: + - label: io-ratio-1 + value: 0.3.0 + - label: amount-1 + value: 0.3.1 + + base-wlth-sell-metrics: + scenario: limit-order.sell.metric + metrics: + - label: io-ratio-1 + value: 0.3.0 + - label: amount-1 + value: 0.3.1 + +deployments: + base-wlth-buy: + scenario: limit-order.buy.prod + order: base-wlth-buy + base-wlth-sell: + scenario: limit-order.sell.prod + order: base-wlth-sell + +--- +#uniswap-words !The subparser for the Uniswap words +#orderbook-subparser !The subparser for the Orderbook words + +#io-ratio-1 !IO ratio for first order. +#ouptut-amount-1 !Output amount for first order. + +#count-key "count-key" +#plottables !Binding to plot values. + +#plottables-prod + :; + +#plottables-plot + _: io-ratio-1, + _: ouptut-amount-1, + +#calculate-io + using-words-from uniswap-words orderbook-subparser + + trade-count-key: hash(order-hash() count-key), + trade-count: get(trade-count-key), + _ _:call<'get-ratio-amount>(trade-count), + :call<'plottables>(); + +#handle-io + trade-count-key: hash(order-hash() count-key), + trade-count: get(trade-count-key), + :set(trade-count-key add(trade-count 1)); + +#get-ratio-amount + trade-count: , + output-amount: if(equal-to(trade-count 0) + ouptut-amount-1 + if(equal-to(trade-count 1) + ouptut-amount-2 + if(equal-to(trade-count 2) + ouptut-amount-3 + 1 + ) + ) + ), + io-ratio: if(equal-to(trade-count 0) + io-ratio-1 + if(equal-to(trade-count 1) + io-ratio-2 + if(equal-to(trade-count 2) + io-ratio-3 + max-value() + ) + ) + ); + From a0733288e1a72404da3475983af3af6822d63100 Mon Sep 17 00:00:00 2001 From: Siddharth2207 Date: Mon, 8 Jul 2024 13:14:03 +0530 Subject: [PATCH 4/5] update strat --- strategies/wlth/limit-order-single.rain | 183 ------------------ strategies/wlth/wlth-limit-order-single.rain | 185 +++++++++++++++++++ 2 files changed, 185 insertions(+), 183 deletions(-) delete mode 100644 strategies/wlth/limit-order-single.rain create mode 100644 strategies/wlth/wlth-limit-order-single.rain diff --git a/strategies/wlth/limit-order-single.rain b/strategies/wlth/limit-order-single.rain deleted file mode 100644 index ed3a963..0000000 --- a/strategies/wlth/limit-order-single.rain +++ /dev/null @@ -1,183 +0,0 @@ -# Limit Order Strategy -# 1 buy and sell target -# Set buy price and amount and sell price and amount -# Target Network: Base -# Quote (Input / Incoming): USDC or WLTH -# Base (Output / Outgoing): WLTH 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: - base: - rpc: https://mainnet.base.org - chain-id: 8453 - network-id: 8453 - currency: ETH - -subgraphs: - base: https://api.thegraph.com/subgraphs/name/h20liquidity/base-0x2aee87 - -orderbooks: - base: - address: 0x2AeE87D75CD000583DAEC7A28db103B1c0c18b76 - network: base - subgraph: base - -deployers: - base: - address: 0xfca89cD12Ba1346b1ac570ed988AB43b812733fe - network: base - -tokens: - base-wlth: - network: base - address: 0x99b2B1A2aDB02B38222ADcD057783D7e5D1FCC7D - base-usdc: - network: base - address: 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913 - -orders: - base-wlth-sell: - orderbook: base - inputs: - - token: base-usdc - vault-id: - outputs: - - token: base-wlth - vault-id: - base-wlth-buy: - orderbook: base - inputs: - - token: base-wlth - vault-id: - outputs: - - token: base-usdc - vault-id: - -scenarios: - limit-order: - network: base - deployer: base - orderbook: base - bindings: - # Ask for now, registry in future. - uniswap-words: 0xbc609623F5020f6Fc7481024862cD5EE3FFf52D7 - orderbook-subparser: 0x8f037f2a3fF2dee510486D9C63A47A245991a4C1 - - scenarios: - buy: - bindings: - # io-ratio is calculated as 1 divided by the token price - # So 1/(WLTH priced in USDC) - io-ratio-1: 100 - - # amount is the trade size - ouptut-amount-1: 100 - - scenarios: - prod: - bindings: - plottables: '''plottables-prod' - chart: - runs: 1 - bindings: - plottables: '''plottables-plot' - sell: - bindings: - # io-ratio is calculated as 1 divided by the token price - # So USDC priced in WLTH - io-ratio-1: 100 - - # amount is the trade size - ouptut-amount-1: 100 - - scenarios: - prod: - bindings: - plottables: '''plottables-prod' - chart: - runs: 1 - bindings: - plottables: '''plottables-plot' - -charts: - base-wlth-buy-metrics: - scenario: limit-order.buy.metric - metrics: - - label: io-ratio-1 - value: 0.3.0 - - label: amount-1 - value: 0.3.1 - - base-wlth-sell-metrics: - scenario: limit-order.sell.metric - metrics: - - label: io-ratio-1 - value: 0.3.0 - - label: amount-1 - value: 0.3.1 - -deployments: - base-wlth-buy: - scenario: limit-order.buy.prod - order: base-wlth-buy - base-wlth-sell: - scenario: limit-order.sell.prod - order: base-wlth-sell - ---- -#uniswap-words !The subparser for the Uniswap words -#orderbook-subparser !The subparser for the Orderbook words - -#io-ratio-1 !IO ratio for first order. -#ouptut-amount-1 !Output amount for first order. - -#count-key "count-key" -#plottables !Binding to plot values. - -#plottables-prod - :; - -#plottables-plot - _: io-ratio-1, - _: ouptut-amount-1, - -#calculate-io - using-words-from uniswap-words orderbook-subparser - - trade-count-key: hash(order-hash() count-key), - trade-count: get(trade-count-key), - _ _:call<'get-ratio-amount>(trade-count), - :call<'plottables>(); - -#handle-io - trade-count-key: hash(order-hash() count-key), - trade-count: get(trade-count-key), - :set(trade-count-key add(trade-count 1)); - -#get-ratio-amount - trade-count: , - output-amount: if(equal-to(trade-count 0) - ouptut-amount-1 - if(equal-to(trade-count 1) - ouptut-amount-2 - if(equal-to(trade-count 2) - ouptut-amount-3 - 1 - ) - ) - ), - io-ratio: if(equal-to(trade-count 0) - io-ratio-1 - if(equal-to(trade-count 1) - io-ratio-2 - if(equal-to(trade-count 2) - io-ratio-3 - max-value() - ) - ) - ); - diff --git a/strategies/wlth/wlth-limit-order-single.rain b/strategies/wlth/wlth-limit-order-single.rain new file mode 100644 index 0000000..fe54a0a --- /dev/null +++ b/strategies/wlth/wlth-limit-order-single.rain @@ -0,0 +1,185 @@ +# Limit Order Strategy +# 5 buy and sell targets +# Each target you set buy price and amount and sell price and amount +# Target Network: Base +# Quote (Input / Incoming): USDC or WLTH +# Base (Output / Outgoing): WLTH 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: + base-community: + rpc: https://rpc.ankr.com/base/8e4cac5728d95471ae55724953c7ae6f19a227ac05146276f09717692b732dae + chain-id: 8453 + network-id: 8453 + currency: ETH + +subgraphs: + base-community: https://api.thegraph.com/subgraphs/name/h20liquidity/base-0x2aee87 + +orderbooks: + base-community: + address: 0x2AeE87D75CD000583DAEC7A28db103B1c0c18b76 + network: base-community + subgraph: base-community + +deployers: + base-community: + address: 0x56394785a22b3BE25470a0e03eD9E0a939C47b9b + network: base-community + +tokens: + base-wlth: + network: base-community + address: 0x99b2B1A2aDB02B38222ADcD057783D7e5D1FCC7D + base-usdc: + network: base-community + address: 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913 + +orders: + # vault-id generated with `openssl rand -hex 32` + base-wlth-sell: + orderbook: base-community + inputs: + - token: base-usdc + vault-id: 0xbc203ee43d814ca260b6400b46f2a3362e6bb0306291ced89ba06856626cc548 + outputs: + - token: base-wlth + vault-id: 0xbc203ee43d814ca260b6400b46f2a3362e6bb0306291ced89ba06856626cc548 + base-wlth-buy: + orderbook: base-community + inputs: + - token: base-wlth + vault-id: 0xaa376e00ebecd7042fccde4feb69390a78001ecea37352f1dab8b3d9023f54f7 + outputs: + - token: base-usdc + vault-id: 0xaa376e00ebecd7042fccde4feb69390a78001ecea37352f1dab8b3d9023f54f7 + +scenarios: + limit-orders: + network: base-community + deployer: base-community + orderbook: base-community + bindings: + # Ask for now, registry in future. + uniswap-words: 0xD6B34F97d4A8Cb38D0544dB241CB3f335866f490 + orderbook-subparser: 0x8D96ea3EF24D7123882c51CE4325b89bc0d63f9e + scenarios: + buy: + bindings: + # io-ratio and amount for first order. + io-ratio-1: 35 + ouptut-amount-1: 1 + scenarios: + prod: + bindings: + plottables: '''plottables-prod' + get-trade-count: '''get-trade-count-prod' + metric: + runs: 1 + bindings: + plottables: '''plottables-metric' + get-trade-count: '''get-trade-count-prod' + sell: + bindings: + # io-ratio and amount for first order. + io-ratio-1: 0.02 + ouptut-amount-1: 50 + scenarios: + prod: + bindings: + plottables: '''plottables-prod' + get-trade-count: '''get-trade-count-prod' + metric: + runs: 1 + bindings: + plottables: '''plottables-metric' + get-trade-count: '''get-trade-count-prod' + + +charts: + base-wlth-buy-metrics: + scenario: limit-orders.buy.metric + metrics: + - label: io-ratio-1 + value: 0.3.2 + - label: amount-1 + value: 0.3.3 + + base-wlth-sell-metrics: + scenario: limit-orders.sell.metric + metrics: + - label: io-ratio-1 + value: 0.3.2 + - label: amount-1 + value: 0.3.3 + +deployments: + base-wlth-buy: + scenario: limit-orders.buy.prod + order: base-wlth-buy + base-wlth-sell: + scenario: limit-orders.sell.prod + order: base-wlth-sell +--- +#uniswap-words !The subparser for the Uniswap words +#orderbook-subparser !The subparser for the Orderbook words + +#io-ratio-1 !IO ratio for first order. +#ouptut-amount-1 !Output amount for first order. + +#io-ratio-2 !IO ratio for second order. +#ouptut-amount-2 !Output amount for second order. + +#io-ratio-3 !IO ratio for third order. +#ouptut-amount-3 !Output amount for third order. + +#io-ratio-4 !IO ratio for fourth order. +#ouptut-amount-4 !Output amount for fourth order. + +#io-ratio-5 !IO ratio for fifth order. +#ouptut-amount-5 !Output amount for fifth order. + +#count-key "count-key" +#plottables !Binding to plot values. +#get-trade-count !Binding to get trade count. +#test-trade-count !Test trade count for plotting. + +#plottables-prod + _ _: ; + +#plottables-metric + amount io-ratio: , + _: io-ratio-1, + _: ouptut-amount-1; + +#get-trade-count-prod + trade-count-key: hash(order-hash() count-key), + trade-count: get(trade-count-key); + +#get-ratio-amount + trade-count: call<'get-trade-count>(), + ouput-amount: conditions( + equal-to(trade-count 0) ouptut-amount-1 + "Max order count" + ), + io-ratio: conditions( + equal-to(trade-count 0) io-ratio-1 + "Max order count" + ); + +#calculate-io + using-words-from uniswap-words orderbook-subparser + + trade-count + final-amount + final-ratio: call<'get-ratio-amount>(), + :call<'plottables>(final-amount final-ratio); + +#handle-io + trade-count-key: hash(order-hash() count-key), + trade-count: get(trade-count-key), + :set(trade-count-key add(trade-count 1)); \ No newline at end of file From 26356f4fdb777edfa66ee4d0f23bfb8006783e12 Mon Sep 17 00:00:00 2001 From: Siddharth2207 Date: Mon, 8 Jul 2024 13:19:41 +0530 Subject: [PATCH 5/5] test --- test/wlth/WlthLimitOrderSingleTest.t.sol | 190 +++++++++++++++++++++++ 1 file changed, 190 insertions(+) create mode 100644 test/wlth/WlthLimitOrderSingleTest.t.sol diff --git a/test/wlth/WlthLimitOrderSingleTest.t.sol b/test/wlth/WlthLimitOrderSingleTest.t.sol new file mode 100644 index 0000000..4c26576 --- /dev/null +++ b/test/wlth/WlthLimitOrderSingleTest.t.sol @@ -0,0 +1,190 @@ +// SPDX-License-Identifier: CAL +pragma solidity =0.8.25; +import {console2, Test} from "forge-std/Test.sol"; + +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://basescan.org/address/0x99b2B1A2aDB02B38222ADcD057783D7e5D1FCC7D +IERC20 constant BASE_WLTH= IERC20(0x99b2B1A2aDB02B38222ADcD057783D7e5D1FCC7D); + +/// @dev https://basescan.org/address/0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913 +IERC20 constant BASE_USDC = IERC20(0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913); + +function baseWlthIo() pure returns (IO memory) { + return IO(address(BASE_WLTH), 18, VAULT_ID); +} + +function baseUsdcIo() pure returns (IO memory) { + return IO(address(BASE_USDC), 6, VAULT_ID); +} + +contract WlthLimitOrderSingleTest is StrategyTests { + + using SafeERC20 for IERC20; + using Strings for address; + + uint256 constant FORK_BLOCK_NUMBER = 16817764; + + function selectFork() internal { + uint256 fork = vm.createFork(vm.envString("RPC_URL_BASE")); + 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(); + + PARSER = IParserV1(0xF836f2746B407136a5bCB515495949B1edB75184); + STORE = IInterpreterStoreV2(0x6E4b01603edBDa617002A077420E98C86595748E); + INTERPRETER = IInterpreterV2(0x379b966DC6B117dD47b5Fc5308534256a4Ab1BCC); + EXPRESSION_DEPLOYER = IExpressionDeployerV3(0x56394785a22b3BE25470a0e03eD9E0a939C47b9b); + ORDERBOOK = IOrderBookV3(0x2AeE87D75CD000583DAEC7A28db103B1c0c18b76); + ARB_INSTANCE = IOrderBookV3ArbOrderTaker(0x199b22ce0c9fD88476cCaA2d2aB253Af38BAE3Ae); + ROUTE_PROCESSOR = IRouteProcessor(address(0x83eC81Ae54dD8dca17C3Dd4703141599090751D1)); + EXTERNAL_EOA = address(0x654FEf5Fb8A1C91ad47Ba192F7AA81dd3C821427); + APPROVED_EOA = address(0x669845c29D9B1A64FFF66a55aA13EB4adB889a88); + ORDER_OWNER = address(0x19f95a84aa1C48A2c6a7B2d5de164331c86D030C); + + EXTERNAL_EOA = address(0x654FEf5Fb8A1C91ad47Ba192F7AA81dd3C821427); + APPROVED_EOA = address(0x669845c29D9B1A64FFF66a55aA13EB4adB889a88); + ORDER_OWNER = address(0x19f95a84aa1C48A2c6a7B2d5de164331c86D030C); + } + + function testWlthLimitOrdersSell() public { + IO[] memory inputVaults = new IO[](1); + inputVaults[0] = baseUsdcIo(); + + IO[] memory outputVaults = new IO[](1); + outputVaults[0] = baseWlthIo(); + + LibStrategyDeployment.StrategyDeployment memory strategy = LibStrategyDeployment.StrategyDeployment( + getEncodedBuyWlthRoute(address(ARB_INSTANCE)), + getEncodedSellWlthRoute(address(ARB_INSTANCE)), + 0, + 0, + 1e6, + 10000e18, + 0, + 0, + "strategies/wlth/wlth-limit-order-single.rain", + "limit-orders.sell.prod", + "./lib/h20.test-std/lib/rain.orderbook", + "./lib/h20.test-std/lib/rain.orderbook/Cargo.toml", + inputVaults, + outputVaults + ); + + OrderV2 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); + + assertEq(strategyRatio, 0.02e18); + assertEq(strategyAmount, 50e18); + } + { + vm.expectRevert("Max order count"); + takeArbOrder(order, strategy.takerRoute, strategy.inputTokenIndex, strategy.outputTokenIndex); + } + + } + + function testWlthLimitOrdersBuy() public { + IO[] memory inputVaults = new IO[](1); + inputVaults[0] = baseWlthIo(); + + IO[] memory outputVaults = new IO[](1); + outputVaults[0] = baseUsdcIo(); + + LibStrategyDeployment.StrategyDeployment memory strategy = LibStrategyDeployment.StrategyDeployment( + getEncodedSellWlthRoute(address(ARB_INSTANCE)), + getEncodedBuyWlthRoute(address(ARB_INSTANCE)), + 0, + 0, + 100000e18, + 10000e6, + 0, + 0, + "strategies/wlth/wlth-limit-order-single.rain", + "limit-orders.buy.prod", + "./lib/h20.test-std/lib/rain.orderbook", + "./lib/h20.test-std/lib/rain.orderbook/Cargo.toml", + inputVaults, + outputVaults + ); + + OrderV2 memory order = addOrderDepositOutputTokens(strategy); + + { + moveExternalPrice( + strategy.inputVaults[strategy.inputTokenIndex].token, + strategy.outputVaults[strategy.outputTokenIndex].token, + strategy.makerAmount, + strategy.makerRoute + ); + } + { + vm.recordLogs(); + // `arb()` called + takeArbOrder(order, strategy.takerRoute, strategy.inputTokenIndex, strategy.outputTokenIndex); + + Vm.Log[] memory entries = vm.getRecordedLogs(); + (uint256 strategyAmount, uint256 strategyRatio) = getCalculationContext(entries); + + assertEq(strategyRatio, 35e18); + assertEq(strategyAmount, 1e18); + } + { + vm.expectRevert("Max order count"); + takeArbOrder(order, strategy.takerRoute, strategy.inputTokenIndex, strategy.outputTokenIndex); + } + } + + function getEncodedBuyWlthRoute(address toAddress) internal pure returns (bytes memory) { + bytes memory ROUTE_PRELUDE = + hex"02833589fCD6eDb6E08f4c7C32D4f71b54bdA0291301ffff011536EE1506e24e5A36Be99C73136cD82907A902E01"; + + return abi.encode(bytes.concat(ROUTE_PRELUDE, abi.encodePacked(address(toAddress)))); + } + + function getEncodedSellWlthRoute(address toAddress) internal pure returns (bytes memory) { + bytes memory ROUTE_PRELUDE = + hex"0299b2B1A2aDB02B38222ADcD057783D7e5D1FCC7D01ffff011536EE1506e24e5A36Be99C73136cD82907A902E00"; + + return abi.encode(bytes.concat(ROUTE_PRELUDE, abi.encodePacked(address(toAddress)))); + } + +} + +