diff --git a/src/a3a/3a-0003-tranche-recharge.rain b/src/a3a/3a-0003-tranche-recharge.rain deleted file mode 100644 index 956deab..0000000 --- a/src/a3a/3a-0003-tranche-recharge.rain +++ /dev/null @@ -1,405 +0,0 @@ -# Strat: Recharging tranches -# -# High level idea is that the strategy offers a firm price for batches of tokens. -# Each batch is called a "tranche". -# -# Target Network: Polygon -# Quote (Input): USDC -# Base (Output): FXA3A -# Token contract: 0x58c7b2828e7f2b2caa0cc7feef242fa3196d03df -# Token github: NA -# Liquidity protocol: Quickswap V3 -# Liquidity pool address: https://www.dextools.io/app/en/polygon/pair-explorer/0xdcf937e79c4f730111143b2345c6028c5051f304?t=1719266575032 -# Liquidity pool fee: tbc -# Stable used https://polygonscan.com/token/0x2791bca1f2de4661ed88a30c99a7a9449aa84174?a=0xdcf937e79c4f730111143b2345c6028c5051f304 -# Stable used 0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174 - -networks: - polygon-h20liquidity: - rpc: https://polygon-mainnet.g.alchemy.com/v2/y3BXawVv5uuP_g8BaDlKbKoTBGHo9zD9 - chain-id: 137 - network-id: 137 - currency: MATIC - -subgraphs: - polygon-h20liquidity: https://api.thegraph.com/subgraphs/name/h20liquidity/polygon-0xc95a5f8e - -orderbooks: - polygon-h20liquidity: - address: 0xc95A5f8eFe14d7a20BD2E5BAFEC4E71f8Ce0B9A6 - network: polygon-h20liquidity - subgraph: polygon-h20liquidity - -deployers: - polygon-h20liquidity: - address: 0xB3aC858bEAf7814892d3946A8C109A7D701DF8E7 - network: polygon-h20liquidity - -tokens: - tkn-fxa3a: - network: polygon-h20liquidity - address: 0x58c7b2828e7f2b2caa0cc7feef242fa3196d03df - tkn-usdc: - network: polygon-h20liquidity - address: 0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174 - -orders: - # vault-id generated with `openssl rand -hex 32` - polygon-a3a-buy: - orderbook: polygon-h20liquidity - inputs: - - token: tkn-usdc - vault-id: - outputs: - - token: tkn-fxa3a - vault-id: - -scenarios: - polygon-a3a-tranches: - network: polygon-h20liquidity - deployer: polygon-h20liquidity - orderbook: polygon-h20liquidity - bindings: - # The uniswap words are only requiA3A 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: 0x7692BA8446Bb8B3140A2c02df073080BeD0a7F8E - - orderbook-subparser: 0x77991674ca8887D4ee1b583DB7324B41d5f894c4 - - # How far we move through tranche space in a second. - # 1e18 is a whole tranche, so we divide 1 by the number of seconds - # per recharge to calculate the per-second rate. - # Examples: - # 172800 seconds in 2 days, 48 hours = 1 / 172800 = 0.000005787037037037 - # 86400 seconds in 1 day, 24 hours = 1 / 86400 = 0.000011574074074074 - # 43200 seconds in 12 hours, 12 hours = 1 / 43200 = 0.000023148148148148 - # 3600 seconds in 1 hour, 1 hour = 1 / 3600 = 0.000277777777777777 - tranche-space-per-second: 0.000011574074074074 - - # After any trade happens we pause before recharging. - # Delay is to observe market feedback to the previous trade, e.g. to - # potentially offer the next tranche at a different price for some time - # before recharging back to the previous price. - # Too long and people could grief to stop recharging. - # Too quick and it will be difficult to move between tranches. - # The default here is 5 minutes (units are seconds) and probably never - # needs to be changed. - tranche-space-recharge-delay: 300 - - # When a tranche is completely cleaA3A , the next tranche MAY be jumped - # into partially. For example, if tranches are 90% shy (i.e. 0.9) then - # if a tranche is cleaA3A completely then the next tranche will be - # started at 10% of its maximum size. This means that the capital - # requirements for the strategy to reprice itself as the market moves - # are A3A uced. - # This MUST be set to a value less than 1e18, else it will entirely - # skip tranches. - # Shyness MAY be set to 0, in which case every tranche will be fully - # available as it is enteA3A . - # tranche-space-shyness: 0 - - # Minimum trade size, if you put in a trade for less than x% of a - # tranche it wont clear. - # Mitigates people pinging strat for dust orders to stop recharging. - min-tranche-space-diff: 0.1 - - # Snap to the nearest tranche to avoid dust issues at the edges, either - # due to rounding in the evm or potentially malicious trades. - # 0.01 is 1% - tranche-space-snap-threshold: 0.01 - - # This is only relevant if the tranche size/ratio is denominated in - # some token other than the input/output tokens. For example, if the - # TKN was being traded for WETH but the tranche size was denominated in - # USD then the reference-stable would be USD and the reference-reserve - # would be WETH, and the identity multiplier needs to be swapped out - # for e.g. a TWAP USDT based multiplier. - # Typically this is NOT needed as the tranche size and ratio ARE - # denominated in the input/output tokens. - io-ratio-multiplier: '''io-ratio-multiplier-identity' - - scenarios: - buy: - bindings: - # If we want to denominate the amount in USD when we're - # buying A3A with it, then the amount is the OUTPUT. - amount-is-output: 1 - io-ratio-expr: '''linear-growth' - io-ratio-base: 333.333333333333333 - io-ratio-growth: 30 - tranche-size-expr: '''exponential-growth' - tranche-size-base: 10 - tranche-size-growth: 0.1 - scenarios: - initialized: - bindings: - # This needs to be set upon going live. - # Generate a chart and compare to current market prices, if - # the market is within the chart then set this to the closest - # 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 - scenarios: - prod: - bindings: - get-last-tranche: '''get-last-tranche-prod' - set-last-tranche: '''set-last-tranche-prod' - plottables: '''plottables-prod' - tranche-space-shyness: 0 - test: - 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-shy-tranche: - bindings: - get-last-tranche: '''get-last-tranche-prod' - set-last-tranche: '''set-last-tranche-prod' - plottables: '''plottables-prod' - tranche-space-shyness: 0.9 - 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: - buy-initial-deployment: - scenario: polygon-a3a-tranches.buy.initialized.test - metrics: - - label: Initial USD sold - value: 0.6 - description: 'Amount of USD sold to buy A3A in the first tranche (stack item 0.6)' - - label: Initial A3A bought - value: 0.5.2 - description: 'Amount of A3A purchased in the first tranche (stack item 0.5.2)' - - label: Initial io-ratio - value: 0.7 - description: '# A3A purchased per USD 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: " BLUE" - description: 'Price you pay for 1 A3A in BLUE, visible on dextools (stack item 0.5.3)' - plots: - - buy-simulation: - scenario: polygon-a3a-tranches.buy.test - plots: - USDT sold per tranche: - x: - label: 'Tranche space' - y: - label: 'USDT spent' - marks: - - type: line - options: - x: 0.0 - y: 0.6 - A3A bought per tranche: - x: - label: 'Tranche space' - y: - label: 'A3A bought' - marks: - - type: line - options: - x: 0.0 - y: 0.5.2 - 'io-ratio per tranche': - subtitle: 'Ratio of A3A bought per 1 USDT sold per tranche' - x: - label: 'Tranche space' - y: - label: 'A3A bought per 1 USDT' - marks: - - type: line - options: - x: 0.0 - y: 0.7 - buy price by tranche: - subtitle: 'Price paid for 1 A3A in USDT, visible on dextools as A3A /USDT pair' - x: - label: 'Tranche space' - y: - label: '1 A3A priced in USDT' - marks: - - type: line - options: - x: 0.0 - y: 0.5.3 - - -deployments: - polygon-a3a-buy: - scenario: polygon-a3a-tranches.buy.initialized.prod - order: polygon-a3a-buy - ---- -#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 -#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)) - block-timestamp() - ), - now: block-timestamp(); - -#tranche-space-shyness !The shyness of the liquidity in tranches. E.g. 0.9 is 90% shy. -#set-last-tranche-prod - tranche-space now:, - 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) now); - -/* 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, - now: test-now; -#get-last-tranche-test-init - tranche-space-before: initial-tranche-space, - last-update-time: test-last-update-time, - now: test-now; -/* There's nothing to set if we're just rebinding in tests. */ -#set-last-tranche-test - tranche-space now:; - -#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 - now: call<'get-last-tranche>(), - recharge-duration: saturating-sub(now add(last-update-time tranche-space-recharge-delay)), - recharged-tranche-space: mul(recharge-duration tranche-space-per-second), - /* repeat now for easy access by callers */ - _: now, - 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-stable-decimals reference-reserve reference-reserve-decimals twap-duration 0 twap-fee); - -#io-ratio-multiplier-buy - multiplier: uniswap-v3-twap-output-ratio(reference-reserve reference-reserve-decimals reference-stable reference-stable-decimals twap-duration 0 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 - now - 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 now); diff --git a/src/a3a/3a-polygon-oracle-dca-usdc.rain b/src/a3a/3a-polygon-oracle-dca-usdc.rain deleted file mode 100644 index 89be306..0000000 --- a/src/a3a/3a-polygon-oracle-dca-usdc.rain +++ /dev/null @@ -1,544 +0,0 @@ -# Strategy: Oracle based DCA -# -# High level, this strategy buys USDC denominated FXA3A tokens at the end of every cooldown period -# provided that current calculated USDC denominated price of FXA3A falls within the price gird. -# -# - Amount of FXA3A bought per trade within the price band is randomized and centered around a mean, -# value for which can be set within the bindings. -# - Range for the grid can also be provided within the bindings. -# - Strategy provides a guard against orcale manipulation by enforcing that the ratio of the current price offered -# by the order to the 30 min average price is within the threshold, which can be provided as a binding in the strategy. -# - Strategy implements a bounty auction for gas management -# -# Target Network: Polygon -# Quote (Input): USDC -# Base (Output): FXA3A -# Token contract: 0x58c7b2828e7f2b2caa0cc7feef242fa3196d03df -# Token github: NA -# Liquidity protocol: Quickswap V3 -# Liquidity pool address: https://www.dextools.io/app/en/polygon/pair-explorer/0xdcf937e79c4f730111143b2345c6028c5051f304?t=1719266575032 -# Liquidity pool fee: tbc -# Stable used https://polygonscan.com/token/0x2791bca1f2de4661ed88a30c99a7a9449aa84174?a=0xdcf937e79c4f730111143b2345c6028c5051f304 -# Stable used 0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174 - -networks: - polygon-h20liquidity: - rpc: https://polygon-mainnet.g.alchemy.com/v2/y3BXawVv5uuP_g8BaDlKbKoTBGHo9zD9 - chain-id: 137 - network-id: 137 - currency: MATIC - -subgraphs: - polygon-h20liquidity: https://api.thegraph.com/subgraphs/name/h20liquidity/polygon-0xc95a5f8e - -orderbooks: - polygon-h20liquidity: - address: 0xc95A5f8eFe14d7a20BD2E5BAFEC4E71f8Ce0B9A6 - network: polygon-h20liquidity - subgraph: polygon-h20liquidity - -deployers: - polygon-h20liquidity: - address: 0xB3aC858bEAf7814892d3946A8C109A7D701DF8E7 - network: polygon-h20liquidity - -tokens: - tkn-fxa3a: - network: polygon-h20liquidity - address: 0x58c7b2828e7f2b2caa0cc7feef242fa3196d03df - tkn-usdc: - network: polygon-h20liquidity - address: 0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174 - -orders: - # vault-id generated with `openssl rand -hex 32` - polygon-h20liquidity-sell: - orderbook: polygon-h20liquidity - inputs: - - token: tkn-usdc - vault-id: - outputs: - - token: tkn-fxa3a - vault-id: - -scenarios: - polygon-h20liquidity-oracle-dca: - network: polygon-h20liquidity - deployer: polygon-h20liquidity - orderbook: polygon-h20liquidity - bindings: - # Ask for now, registry in future. - uniswap-words: 0x80DE00e3cA96AE0569426A1bb1Ae22CD4181dE6F - orderbook-subparser: 0x59401c9302e79eb8ac6aea659b8b3ae475715e86 - - # Distribution token, i.e token that is bought or sold, for and against the stable token. - distribution-token: 0xAD86d0E9764ba90DDD68747D64BFfBd79879a238 - # Stable token, token with price pegged to one dollar. - stable-token: 0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d - - # If the distribution token is paired with a stable token in a univ3 pool, - # then address for this binding is same as the stable token address. - # Eg: If the uniswap-v3 pair is PAID-USDC, then reserve token address is same as USDC address. - # - # If the distribution token is paired with native wrapped token in a univ3 pool, - # then address for this binding is the address of the native wrapped token. - # Eg: If the uniswap-v3 pair is PAID-WETH, then reserve token address is same as WETH address. - # This reserve token will be compared against stable token to calculate the dollar - # equivalent twap. - reserve-token: 0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174 - - # Twap fee for tokens - # `twap-io-fee`: Uniswap-v3 pool fee for token pair. - # If distribution token is paired with a stable token, the binding value is the fee - # for the PAID-USDC pool. - # - # If distribution token is paired with native wrapped token, for eg WETH, then the - # binding value is the fee for PAID-WETH pool. - twap-io-fee: '[uniswap-v3-fee-high]' - - # `twap-multiplier-feee`: Uniswap-v3 pool fee for stable-reserve pair. - # If distribution token is paired with a stable token then binding value is irrelevant. - # - # If distribution token is paired with native wrapped token, for eg WETH, then the - # binding value is the fee for WETH-USDC pool - twap-multiplier-fee: '[uniswap-v3-fee-lowest]' - - # IO multiplier binding - # Binding used to calculate multiplier for distribution token to get its dollor equivalent. - # - # If distribution token is paired with a stable token, the binding value is the stable multiplier. - # io-multiplier: '''io-multiplier-stable' - # - # If distribution token is paired with a reserve token, the binding value is the reserve multiplier - # io-multiplier: '''io-multiplier-reserve' - io-multiplier: '''io-multiplier-reserve' - - #Jittery binomial bits - jittery-binomial-bits: 10 - - # Bounty amount offered for trade in dollar. - # - # Minimum amount of bounty offered for the trade, depending upon the network this value might change. - bounty-min: 0.01 - - # Maximum amount of bounty offered for the trade, this will also the amount offered for the first trade, - # as well as to calculate the twap deviation for the first trade which is visible in the metrics. - bounty-max: 1 - - # Bounty unit increase, amount by which to increase the bounty amount. - bounty-unit-increase: 0.001 - - # Bounty unit time in seconds, time in which bounty increased by `bounty-unit-increase` - # Eg: If `bounty-unit-increase` is 0.01 and `bounty-unit-time` is 60, then the bounty will increase linearly - # by `0.01` every 60 seconds. - bounty-unit-time: 30 - - scenarios: - buy: - bindings: - # Cooldown between two trades in seconds. - cooldown-time: 1200 - - # Mean amount of USDC offered per trade. - # For gas expensive networks mean amount needs to be higher to compensate - # for gas fee and bounty. - mean-usd-amount: 3 - - # Grid minimum price - grid-min: 0.000001 - - # Grid maximum price - grid-max: 0.003 - - calculate-exact-quote: '''calculate-exact-buy-quote' - calculate-io-ratio: '''calculate-io-ratio-buy' - scenarios: - deviation: - bindings: - # Percentage acceptable twap deviation - # Acceptable deviation from the 30min average price. - # Binding value is dependent upon the network, token pair and the mean amount of - # tokens traded per trade. If the mean amount of tokens traded is low, or if - # the network gas fee is high, then deviation needs to be a higher value. - # - For 1% deviation, binding value is 0.01 - # - For 5% deviation, binding value is 0.05 - # - For 10% deviation, binding value is 0.1 - twap-deviation: 0.1 - scenarios: - prod: - bindings: - calculate-twap-ratio: '''calculate-twap-ratio-buy' - enforce-twap-check: '''enforce-twap-check-prod' - ensure-grid-band: '''ensure-grid-band-prod' - ensure-cooldown: '''ensure-cooldown-prod' - plottables: '''plottables-prod' - chart: - runs: 1000 - bindings: - calculate-twap-ratio: '''calculate-twap-ratio-buy' - enforce-twap-check: '''enforce-twap-check-chart' - ensure-grid-band: '''ensure-grid-band-chart' - ensure-cooldown: '''ensure-cooldown-chart' - plottables: '''plottables-chart' - metric: - runs: 1 - bindings: - calculate-twap-ratio: '''calculate-twap-ratio-buy' - enforce-twap-check: '''enforce-twap-check-chart' - ensure-grid-band: '''ensure-grid-band-chart' - ensure-cooldown: '''ensure-cooldown-metric' - plottables: '''plottables-chart' - test: - bindings: - twap-deviation: 0.12 - calculate-twap-ratio: '''calculate-twap-ratio-buy' - enforce-twap-check: '''enforce-twap-check-prod' - ensure-grid-band: '''ensure-grid-band-chart' - ensure-cooldown: '''ensure-cooldown-chart' - plottables: '''plottables-prod' - -charts: - a3a-buy-oracle-dca: - scenario: polygon-h20liquidity-oracle-dca.buy.deviation.metric - metrics: - - label: Current FXA3A price. - value: 0.3.3 - unit-prefix: $ - description: Price of FXA3A at current block. - - label: Minimum FXA3A buy price. - value: 0.3.0 - unit-prefix: $ - description: Grid minimum USDC/PAID ratio. - - label: Maximum FXA3A buy price. - value: 0.3.1 - unit-prefix: $ - description: Grid maximum USDC/PAID ratio. - - label: Amount of USDC offered for first trade. - value: 0.4 - description: Amount of USDC offered for the current block. - - label: Amount of FXA3A received for frist trade. - value: 0.5 - description: Amount of FXA3A received for USDC offered. - - label: io-ratio PAID/USDC - value: 0.8 - description: Ratio offered by the order for the current block accounting for bounty. - - label: Minimum Bounty amount - value: 0.8.5 - unit-prefix: $ - description: Minimum bounty offered - - label: Maximum Bounty amount - value: 0.8.6 - unit-prefix: $ - description: Maximum bounty offered - - label: Bounty increase per minute - value: 0.8.10 - unit-prefix: $ - description: Amount by which bounty increases every minute after cooldown. - - label: Max Bounty ratio - value: 0.8.9 - unit-suffix: '%' - description: Ratio of max bounty amount to order amount - - label: Mean amount - value: 0.8.4 - unit-prefix: $ - description: Mean amount of USDC sold - - label: Cooldown in minutes - value: 0.8.11 - description: Number of minutes between strategy running - - label: Trades per hour - value: 0.8.12 - description: Number of trades per hour - - label: Strategy twap buy deviation - value: 0.8.7 - unit-suffix: '%' - description: Twap deviation percentage acceptable - - label: Current twap buy deviation - value: 0.8.8 - unit-suffix: '%' - description: Twap deviation occuring at current block with maximum bounty on the buy side to prevent higher than deviations buys. - - label: Cummulative amount traded daily - value: 0.8.13 - unit-prefix: $ - description: Cummulative dollar equivalent amount of FXA3A tokens sold in a day. - - label: Cummulative amount traded weekly - value: 0.8.14 - unit-prefix: $ - description: Cummulative dollar equivalent amount of FXA3A tokens sold in a week. - - label: Cummulative amount traded montly - value: 0.8.15 - unit-prefix: $ - description: Cummulative dollar equivalent amount of FXA3A tokens sold in a month. - - label: Twap-ratio - value: 0.8.2 - - plots: - - buy-a3a-simulation: - scenario: polygon-h20liquidity-oracle-dca.buy.deviation.chart - plots: - Mean amount of USDC offered: - marks: - - type: recty - options: - transform: - type: binx - content: - outputs: - y: "count" - options: - x: "0.4" - thresholds: 25 - - Mean amount of FXA3A received: - marks: - - type: recty - options: - transform: - type: binx - content: - outputs: - y: "count" - options: - x: "0.5" - thresholds: 25 - -deployments: - polygon-h20liquidity-buy: - scenario: polygon-h20liquidity-oracle-dca.buy.deviation.prod - order: polygon-h20liquidity-buy - ---- -#cooldown-time !The minimum amount of seconds that must elapse between trades. -#bounty-min !Minimum bounty to offer for each trade in USD. -#bounty-unit-increase !Amount to increase bounty per unit time. -#bounty-unit-time !Unit of time to increase the bounty. -#bounty-max !Maximum bounty that can be offered. - -#distribution-token !The distribution token, the token that is bought and sold against the stable token. -#stable-token !The stable token that is used as a reference for the TWAP to offer dollar equivalent conversions. -#reserve-token !The token that will be used to compare against the stable token to calculate the TWAP for dollar equivalent conversions. - -#grid-min !Minimum dollar denominated price to trade distribution token for and against stable token. -#grid-max !Maximum dollar denominated price to trade distribution token for and against stable token. -#mean-usd-amount !Mean dollar denominated amount of stable tokens traded. -#jittery-binomial-bits !Number of bits for jittery binomial to calculate random amount of stable token traded per trade. - -#twap-io-fee !Twap fee for the distribution token pool, paired with either stable or reserve token. -#twap-multiplier-fee !Twap fee for reserve token paired with stable token. -#twap-deviation !Acceptable percentage twap deviation to guard against the 30min price change. - -#test-current-time !Test current time for plotting. -#test-last-time !Test last time for plotting. - -#ensure-cooldown !Binding to enforce cooldown check. -#ensure-grid-band !Binding to enforce price remains between minimum and maximum price set. -#calculate-exact-quote !Binding to calculate exact amount of distribution tokens required for buys and sells. -#calculate-io-ratio !Binding to calculate io-ratio for the order. -#calculate-twap-ratio !Binding to calculate order to 30min twap ratio. -#enforce-twap-check !Binding to enforce oracle manipulation protection guard. -#io-multiplier !Binding to get the ratio multiplier for distribution token. -#plottables !The binding for additional things we want to plot during testing. - -#uniswap-words !The subparser for the Uniswap words -#orderbook-subparser !The subparser for the Orderbook words -#cooldown-key "cooldown-key" - -#enforce-twap-check-chart - _: ; - -#enforce-twap-check-prod - twap-ratio: , - :ensure( - less-than( - twap-ratio - add(1 twap-deviation) - ) - "twap check" - ); - -#calculate-twap-ratio-buy - io-ratio ratio-multiplier: , - twap-30: mul( - uniswap-v3-twap-output-ratio(reserve-token distribution-token 1800 0 [pancake-v3-factory] [pancake-v3-init-code] twap-io-fee) - ratio-multiplier - ), - twap-ratio: div(twap-30 io-ratio), - :call<'enforce-twap-check>(twap-ratio); - -#calculate-twap-ratio-sell - io-ratio ratio-multiplier: , - twap-30: mul( - uniswap-v3-twap-output-ratio(distribution-token reserve-token 1800 0 [pancake-v3-factory] [pancake-v3-init-code] twap-io-fee) - ratio-multiplier - ), - twap-ratio: div(twap-30 io-ratio), - :call<'enforce-twap-check>(twap-ratio); - -#jittery-binomial - seed:, - binomial18-10: - bitwise-count-ones(bitwise-decode<0 jittery-binomial-bits>(hash(seed))), - noise18-1: - mod(hash(seed 0) 1), - jittery-combined: - add(binomial18-10 noise18-1), - jittery-combined-normalized: - div(jittery-combined add(1 jittery-binomial-bits)); - -#bounty-auction - time-since-cooldown: , - bounty: min( - linear-growth( - bounty-min - div(bounty-unit-increase bounty-unit-time) - time-since-cooldown - ) - bounty-max - ); - -#ensure-cooldown-metric - _ _: block-timestamp() 0; - -#ensure-cooldown-chart - _ _: test-current-time test-last-time; - -#ensure-cooldown-prod - current-time: block-timestamp(), - last-time: get(hash(order-hash() cooldown-key)), - :ensure( - greater-than-or-equal-to( - current-time - add(last-time cooldown-time) - ) - "cooldown" - ), - :set(hash(order-hash() cooldown-key) current-time); - -#ensure-grid-band-chart - _ _ ratio-multiplier: , - current-price: mul( - uniswap-v3-twap-output-ratio( - distribution-token - reserve-token - 0 0 - [pancake-v3-factory] [pancake-v3-init-code] - twap-io-fee - ) - ratio-multiplier - ); - - -#ensure-grid-band-prod - grid-min-price grid-max-price ratio-multiplier: , - current-price: mul( - uniswap-v3-twap-output-ratio( - distribution-token - reserve-token - 0 0 - [pancake-v3-factory] [pancake-v3-init-code] - twap-io-fee - ) - ratio-multiplier - ), - :ensure( - every( - greater-than-or-equal-to(current-price grid-min-price) - less-than-or-equal-to(current-price grid-max-price) - ) - "grid band" - ); - -#calculate-io-ratio-buy - usd-amount18 - token-amount18 - ratio-multiplier - time-since-cooldown: , - io-ratio: div(token-amount18 add(usd-amount18 call<'bounty-auction>(time-since-cooldown))), - _ :call<'calculate-twap-ratio>(io-ratio ratio-multiplier), - /* Add io-ratio and max-op on stack*/ - _: usd-amount18, - _: io-ratio; - -#calculate-io-ratio-sell - usd-amount18 - token-amount18 - ratio-multiplier - time-since-cooldown: , - io-ratio: div(saturating-sub(usd-amount18 call<'bounty-auction>(time-since-cooldown)) token-amount18), - _ :call<'calculate-twap-ratio>(io-ratio inv(ratio-multiplier)), - /* Add io-ratio and max-op on stack*/ - _: token-amount18, - _: io-ratio; - -#calculate-exact-buy-quote - amount-usd18 ratio-multiplier: , - _: uniswap-v3-quote-exact-input(reserve-token distribution-token mul(amount-usd18 ratio-multiplier) [pancake-v3-factory] [pancake-v3-init-code] twap-io-fee); - -#calculate-exact-sell-quote - amount-usd18 ratio-multiplier: , - _: uniswap-v3-quote-exact-output(distribution-token reserve-token mul(amount-usd18 ratio-multiplier) [pancake-v3-factory] [pancake-v3-init-code] twap-io-fee); - -#io-multiplier-reserve - _: uniswap-v3-twap-output-ratio( - stable-token - reserve-token - 0 0 - [pancake-v3-factory] [pancake-v3-init-code] - twap-multiplier-fee - ); - -#io-multiplier-stable - _: 1; - -#plottables-chart - max-output-amount io-ratio twap-ratio: , - _: cooldown-time, - _: mean-usd-amount, - _: bounty-min, - _: bounty-max, - _: mul(twap-deviation 100), - current-twap-deviation: if( - greater-than(1 twap-ratio) - mul(saturating-sub(1 twap-ratio) 100) - mul(saturating-sub(twap-ratio 1) 100) - ), - max-bounty-ratio: mul(div(bounty-max mean-usd-amount) 100), - bounty-increase-per-minute: mul(div(bounty-unit-increase bounty-unit-time) 60), - cooldown-in-minutes: div(cooldown-time 60), - cooldown-in-hours: div(60 cooldown-in-minutes), - total-amount-daily: mul(cooldown-in-hours mean-usd-amount 24), - total-amount-weekly: mul(total-amount-daily 7), - total-amount-montly: mul(total-amount-daily 30); - - -#plottables-prod - _ _ _: ; - -#calculate-io - using-words-from uniswap-words orderbook-subparser - - io-ratio-multiplier: call<'io-multiplier>(), - :call<'ensure-grid-band>(grid-min grid-max inv(io-ratio-multiplier)), - current-time last-time: call<'ensure-cooldown>(), - random-multiplier18: call<'jittery-binomial>(last-time), - jittered-amount-usd18: mul( - mul(mean-usd-amount 2) - random-multiplier18 - ), - token-amount-output18: call<'calculate-exact-quote>(jittered-amount-usd18 io-ratio-multiplier), - twap-ratio max-output final-io-ratio: call<'calculate-io-ratio>( - jittered-amount-usd18 - token-amount-output18 - io-ratio-multiplier - saturating-sub(current-time add(last-time cooldown-time)) - ), - :call<'plottables>(max-output final-io-ratio twap-ratio); - -#handle-io - :ensure( - greater-than-or-equal-to( - uint256-output-vault-decrease() - scale-n-dynamic(output-token-decimals() calculated-max-output()) - ) - "Partial trade" - );