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

Commit

Permalink
update tranche-space
Browse files Browse the repository at this point in the history
  • Loading branch information
Siddharth2207 committed Jul 6, 2024
1 parent b57bb7a commit cac17b4
Showing 1 changed file with 25 additions and 17 deletions.
42 changes: 25 additions & 17 deletions src/tranche/tranche-space.rain
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,13 @@ 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: 0x7692BA8446Bb8B3140A2c02df073080BeD0a7F8E
uniswap-words: 0xAFF83Dd453f9EE510d6F623d09322A68E8ee29A3

# Uniswap v3 factory contract address and corresponding init code hash.
# If the factory address and the init code aren't available as a literals
# then non-literal address and hash value can be given as bindings.
uniswap-v3-factory: '[uniswap-v3-factory]'
uniswap-v3-init-code: '[uniswap-v3-init-code]'

orderbook-subparser: 0x77991674ca8887D4ee1b583DB7324B41d5f894c4

Expand Down Expand Up @@ -317,7 +323,7 @@ charts:
- label: Starting tranche
value: 0.2.0
description: 'This strategy starts executing sells at the initial tranche (stack item 0.2.0)'
- label: Initial effective sell price
- label: Initial sell price
value: 0.7
precision: 4
unit-suffix: "BLUE"
Expand Down Expand Up @@ -419,6 +425,8 @@ deployments:
#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
Expand All @@ -441,34 +449,34 @@ deployments:
last-update-time: if(
is-initialized
get(hash(order-hash() update-time-key))
block-timestamp()
now()
),
now: block-timestamp();
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 now:,
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) now);
: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,
now: test-now;
current-time: test-now;
#get-last-tranche-test-init
tranche-space-before: initial-tranche-space,
last-update-time: test-last-update-time,
now: test-now;
current-time: test-now;
/* There's nothing to set if we're just rebinding in tests. */
#set-last-tranche-test
tranche-space now:;
tranche-space current-time:;

#exponential-growth
base rate t:,
Expand All @@ -485,20 +493,20 @@ deployments:
#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)),
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 now for easy access by callers */
_: now,
/* 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-stable-decimals reference-reserve reference-reserve-decimals twap-duration 0 twap-fee);
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-reserve-decimals reference-stable reference-stable-decimals twap-duration 0 twap-fee);
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;
Expand All @@ -516,7 +524,7 @@ deployments:
:call<'plottables>(amount io-ratio);

#handle-io
now
current-time
tranche-space-before
_
tranche-total-size: call<'calculate-tranche>(),
Expand All @@ -532,4 +540,4 @@ deployments:
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);
:call<'set-last-tranche>(tranche-space-after-snapped current-time);

0 comments on commit cac17b4

Please sign in to comment.