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

update tranche charting #58

Merged
merged 4 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 31 additions & 23 deletions src/tranche/tranche-space.rain
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ orderbooks:

deployers:
flare-pubstrats:
address: 0x8ceC9e3Ec2F8838000b91CfB97403A6Bb0F4036A
address: 0xEBe394cff4980992B826Ec70ef0a9ec8b5D4C640
network: flare-pubstrats

tokens:
Expand Down 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 @@ -318,10 +324,10 @@ charts:
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.5.3
value: 0.7
precision: 4
unit-suffix: " BLUE"
description: 'Price you pay for 1 BLUE in RED, visible on dextools (stack item 0.5.3)'
unit-suffix: "BLUE"
description: 'Price you pay for 1 RED in BLUE, visible on dextools (stack item 0.7)'
plots:

sell-simulation:
Expand Down Expand Up @@ -359,16 +365,16 @@ charts:
x: 0.0
y: 0.7
sell price by tranche:
subtitle: 'Price paid for 1 BLUE in RED, visible on dextools as RED/BLUE pair'
subtitle: 'Price paid for 1 RED in BLUE, visible on dextools as RED/BLUE pair'
x:
label: 'Tranche space'
y:
label: '1 BLUE priced in RED'
label: '1 RED priced in BLUE'
marks:
- type: line
options:
x: 0.0
y: 0.5.3
y: 0.7

deployments:
flare-buy:
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);
6 changes: 3 additions & 3 deletions test/TrancheSpaceTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ contract TrancheSpaceTest is StrategyTests {
using LibFixedPointDecimalArithmeticOpenZeppelin for uint256;
using LibFixedPointDecimalScale for uint256;

uint256 constant FORK_BLOCK_NUMBER = 24517782;
uint256 constant FORK_BLOCK_NUMBER = 26478013;
uint256 constant VAULT_ID = uint256(keccak256("vault"));

string constant TRANCHE_SPACE_FILE_PATH = "src/tranche/tranche-space.rain";
Expand All @@ -51,10 +51,10 @@ contract TrancheSpaceTest is StrategyTests {
function setUp() public {
selectFlareFork();

PARSER = IParserV1(0x001B302095D66b777C04cd4d64b86CCe16de55A1);
PARSER = IParserV1(0xA073E75E39C402d2AFFb48E5e8EC18169daeC31D);
ORDERBOOK = IOrderBookV3(0x07701e3BcE4248EFDFc7D31392a43c8b82a7A260);
ARB_INSTANCE = IOrderBookV3ArbOrderTaker(0xF9323B7d23c655122Fb0272D989b83E105cBcf9d);
EXPRESSION_DEPLOYER = IExpressionDeployerV3(0x8ceC9e3Ec2F8838000b91CfB97403A6Bb0F4036A);
EXPRESSION_DEPLOYER = IExpressionDeployerV3(0xEBe394cff4980992B826Ec70ef0a9ec8b5D4C640);
ROUTE_PROCESSOR = IRouteProcessor(address(0x0bB72B4C7c0d47b2CaED07c804D9243C1B8a0728));
EXTERNAL_EOA = address(0x654FEf5Fb8A1C91ad47Ba192F7AA81dd3C821427);
APPROVED_EOA = address(0x669845c29D9B1A64FFF66a55aA13EB4adB889a88);
Expand Down
Loading