Skip to content

Commit

Permalink
Update wlth-tranche-init.rain
Browse files Browse the repository at this point in the history
- added spread binding and put downstairs
- added the refernces for memory 
- added cost basis function 
- add sets for post trade (needs to be called)

Needs the spread and cost basis applied to be the new moving base. Needs the sets called.
  • Loading branch information
TobyMeller authored Aug 16, 2024
1 parent b1f65a2 commit 168c8d1
Showing 1 changed file with 54 additions and 1 deletion.
55 changes: 54 additions & 1 deletion strategies/wlth-tranche-init.rain
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ scenarios:
amount-is-output: 1
io-ratio-expr: '''linear-growth'
io-ratio-base: 15
io-ratio-spread: 0.025 #this is in %
io-ratio-growth: 0.5
tranche-size-expr: '''linear-growth'
tranche-size-base: 5
Expand Down Expand Up @@ -215,6 +216,7 @@ scenarios:
amount-is-output: 0
io-ratio-expr: '''linear-growth'
io-ratio-base: 0.040
io-ratio-spread: 0.025 #this is in %
io-ratio-growth: 0.001
tranche-size-expr: '''linear-growth'
tranche-size-base: 5
Expand Down Expand Up @@ -407,6 +409,7 @@ deployments:

#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.
#io-ratio-spread !The distance the tranche starts from away from the cost basis.
#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.
Expand Down Expand Up @@ -439,6 +442,10 @@ deployments:
#init-key "init"
#tranche-space-key "tranche-space"
#update-time-key "update-time"
#cumulative-sale-volume "cumulative-sale-volume"
#cumulative-sale-cost "cumulative-sale-cost"
#cumulative-buy-volume "cumulative-buy-volume"
#cumulative-buy-cost "cumulative-buy-cost"

#plottables !The binding for additional things we want to plot during testing.

Expand Down Expand Up @@ -533,6 +540,21 @@ deployments:
#io-ratio-multiplier-identity
multiplier: 1;

#calculate-midpoint
cumulative-sale-volumeb: get(hash(order-hash() cumulative-sale-volume)),
cumulative-sale-costb: get(hash(order-hash() cumulative-sale-cost)),
cumulative-buy-volumeb: get(hash(order-hash() cumulative-buy-volume)),
cumulative-buy-costb: get(hash(order-hash() cumulative-buy-cost)),

total-volume: add(cumulative-sale-volumeb cumulative-buy-volumeb),

sale-cost-basis: div(cumulative-sale-costb cumulative-sale-volumeb),
buy-cost-basis: div(cumulative-buy-costb cumulative-buy-volumeb),

/* ADD : if initized hasnt change then intiilised */

current-cost-basis: div(add(mul(sale-cost-basis cumulative-sale-volumeb) mul(buy-cost-basis cumulative-buy-volumeb)) total-volume);

#calculate-io
using-words-from uniswap-words orderbook-subparser
tranche-space-now
Expand Down Expand Up @@ -602,4 +624,35 @@ deployments:
init-tranche: call<'post-action-tranche>(current-ratio),
:set(hash(order-hash() init-key) 1),
:set(hash(order-hash() tranche-space-key) init-tranche),
:set(hash(order-hash() update-time-key) now());
:set(hash(order-hash() update-time-key) now());

#post-update-cost-basis
/* will this just run or do i need to call it in handle io?

sudo code of what i want to achieve below, deonminated in USDC
if side == 'sell':
cumulative_sale_volume += volume
cumulative_sale_cost += volume * price
elif side == 'buy':
cumulative_buy_volume += volume
cumulative_buy_cost += volume * price
*/
:set(hash(order-hash() cumulative-buy-volume)
if(amount-is-output
add(get(hash(order-hash()cumulative-buy-volume)) output-vault-increase())
get(hash(order-hash()cumulative-buy-volume)))),

:set(hash(order-hash() cumulative-buy-cost)
if(is-zero(amount-is-output)
add(get(hash(order-hash() cumulative-buy-cost)) mul(output-vault-increase() inv(calculated-io-ratio())))
get(hash(order-hash() cumulative-buy-cost))),

:set(hash(order-hash()cumulative-sale-volume)
if(is-zero(amount-is-output)
add(get(hash(order-hash()cumulative-sale-volume)) input-vault-increase())
get(hash(order-hash() cumulative-sale-volume)))),

:set(hash(order-hash()cumulative-sale-cost)
if(is-zero(amount-is-output)
add(get(hash(order-hash() cumulative-sale-cost)) mul(input-vault-increase() calculated-io-ratio()))
get(hash(order-hash() cumulative-sale-cost))));

0 comments on commit 168c8d1

Please sign in to comment.