diff --git a/batcher/marketmaker.mligo b/batcher/marketmaker.mligo index a03f6937..9b37a879 100644 --- a/batcher/marketmaker.mligo +++ b/batcher/marketmaker.mligo @@ -22,7 +22,7 @@ let no_op (s : storage) : result = (([] : operation list), s) let change_admin_address (new_admin_address: address) (storage: storage) : operation list * storage = - let () = is_administrator storage.administrator in + let () = is_known_sender storage.administrator sender_not_administrator in let () = reject_if_tez_supplied () in let storage = { storage with administrator = new_admin_address; } in no_op storage @@ -32,7 +32,7 @@ let change_admin_address let change_batcher_address (new_batcher_address: address) (storage: storage) : operation list * storage = - let () = is_administrator storage.administrator in + let () = is_known_sender storage.administrator sender_not_administrator in let () = reject_if_tez_supplied () in let storage = { storage with batcher = new_batcher_address; } in no_op storage @@ -42,7 +42,7 @@ let change_batcher_address let change_tokenmanager_address (new_tm_address: address) (storage: storage) : operation list * storage = - let () = is_administrator storage.administrator in + let () = is_known_sender storage.administrator sender_not_administrator in let () = reject_if_tez_supplied () in let storage = { storage with tokenmanager = new_tm_address; } in no_op storage @@ -79,6 +79,50 @@ let remove_vault +[@inline] +let get_volume + (rate:exchange_rate) + (opposing_volume: nat) : nat = + let rat_opposing_volume = Rational.new (int opposing_volume) in + let rat_vol_required = Rational.mul rat_opposing_volume rate.rate in + get_rounded_number_lower_bound rat_vol_required + +[@inline] +let get_inverse_volume + (rate:exchange_rate) + (opposing_volume: nat) : nat = + let rat_opposing_volume = Rational.new (int opposing_volume) in + let rat_vol_required = Rational.div rat_opposing_volume rate.rate in + get_rounded_number_lower_bound rat_vol_required + +[@inline] +let execute_liquidity_request + (lt:token) + (ot:token) + (opposing_volume: nat) + (vault_address:address) + (valid_tokens:ValidTokens.t_map) + (valid_swaps:ValidSwaps.t_map) : operation = + let pair_name = find_lexicographical_pair_name lt.name ot.name in + match Map.find_opt pair_name valid_swaps with + | None -> failwith swap_does_not_exist + | Some vs -> let (lastupdated, price) = OracleUtils.get_oracle_price unable_to_get_price_from_oracle vs in + let swap:swap = swap_reduced_to_swap vs.swap 1n valid_tokens in + let oracle_rate = OracleUtils.convert_oracle_price vs.oracle_precision swap lastupdated price valid_tokens in + let (side,vol_req) = if lt.name = vs.swap.to then + (Sell,get_inverse_volume oracle_rate opposing_volume) + else + (Buy,get_volume oracle_rate opposing_volume) + in + let req = { + side = side; + from_token = lt; + to_token = ot; + amount = vol_req; + } in + send_liquidity_injection_request req vault_address + + [@inline] let make_liquidity_request (liq_token: string) @@ -87,41 +131,15 @@ let make_liquidity_request (ops: operation list) (valid_tokens:ValidTokens.t_map) (valid_swaps:ValidSwaps.t_map) - (vaults: Vaults.t) : operation list + (vaults: Vaults.t) : operation list = let liq_token_opt = Map.find_opt liq_token valid_tokens in - let opposing_token_opt = Map.find_opt sell_token valid_tokens in + let opposing_token_opt = Map.find_opt opposing_token valid_tokens in + if not (Vaults.mem liq_token vaults) then ops else + let vault_address = Option.unopt (Vaults.find_opt liq_token vaults) in match (liq_token_opt,opposing_token_opt) with - | Some lt, Some ot -> (let pair_name = find_lexicographical_pair_name lt.name ot.name in - match Map.find_opt pair_name valid_swaps with - | None -> failwith swap_does_not_exist - | Some vs -> let (lastupdated, price) = OracleUtils.get_oracle_price unable_to_get_price_from_oracle vs in - let oracle_rate = OracleUtils.convert_oracle_price valid_swap.oracle_precision valid_swap.swap lastupdated price valid_tokens in - let rat_opposing_volume = Rational.new (int opposing_volume) in - if lt.token.name = valid_swap.swap.to then - let rat_vol_required = Rational.div rat_opposing_volume oracle_rate.rate in - let vol_required = get_rounded_number_lower_bound rat_vol_required in - - else - - - - (* Create a Rational version of the native token in the opposing vault i.e a rational version of the tzBTC held in the USDT vault *) - let rat_opposing_vault_native_amount = Rational.new (int opposing_vault_native_token_amount.amount) in - (* Use the rate to create a foreign equivalent of the native token in the opposing vault this is the tzBTC held in the USDT vault but converted into its USDT value for comparison *) - let opposite_native_equivalent = Rational.mul rate.rate rat_opposing_vault_native_amount in - (* Create a Rational version of the foreign token amount in the native vault i.e a rational version of the USDT held in the tzBTC vault *) - let rat_foreign_token_amount = Rational.new (int foreign_token_amount.amount) in - (* We are comparing USDT equivalent of the tzBTC in the USDT vault with the USDT held in the tzBTC vault as a foreign token *) - let rat_foreign_amount_to_move = if opposite_native_equivalent > rat_foreign_token_amount then rat_foreign_token_amount else opposite_native_equivalent in - let rat_native_amount_to_move = Rational.div rat_foreign_amount_to_move rate.rate in - let int_native_amount_to_move = Utils.get_rounded_number_lower_bound rat_native_amount_to_move in - let int_foreign_amount_to_move = Utils.get_rounded_number_lower_bound rat_foreign_amount_to_move in - let native_amount_to_move = { native_token_amount with amount = int_native_amount_to_move; } in - let foreign_amount_to_move = { foreign_token_amount with amount = int_foreign_amount_to_move; } in - exchange_amount native_amount_to_move foreign_amount_to_move native_token_amount foreign_token_amount opposing_vault_foreign_token_amount opposing_vault_native_token_amount - - - | _, _ -> failwith token_name_not_in_list_of_valid_tokens + | Some lt, Some ot -> execute_liquidity_request lt ot opposing_volume vault_address valid_tokens valid_swaps :: ops + | _,_ -> failwith token_name_not_in_list_of_valid_tokens + [@inline] let tick @@ -130,17 +148,18 @@ let tick let vaults = storage.vaults in let valid_tokens = TokenManagerUtils.get_valid_tokens storage.tokenmanager in let valid_swaps = TokenManagerUtils.get_valid_swaps storage.tokenmanager in - let request_liquidity (liq_ops,batch):(operation list * batch) : operation list = + let request_liquidity ((liq_ops,batch):(operation list * batch)) : operation list = let (bt,st) = batch.pair in let buy_vol_opt = if batch.volumes.sell_total_volume = 0n then None else Some batch.volumes.sell_total_volume in let sell_vol_opt = if batch.volumes.buy_total_volume = 0n then None else Some batch.volumes.buy_total_volume in match (buy_vol_opt, sell_vol_opt) with | Some _,Some _ -> liq_ops - | Some bv, None -> make_liquidity_request st bt bv liq_ops vaults - | None, Some sv -> make_liquidity_request bt st sv liq_ops vaults + | Some bv, None -> make_liquidity_request st bt bv liq_ops valid_tokens valid_swaps vaults + | None, Some sv -> make_liquidity_request bt st sv liq_ops valid_tokens valid_swaps vaults | None, None -> liq_ops - - no_op storage + in + let ops = List.fold_left request_liquidity ([]:operation list) batches_needing_liquidity in + ops, storage end diff --git a/batcher/michelson/marketmaker-ghostnet.tz b/batcher/michelson/marketmaker-ghostnet.tz new file mode 100644 index 00000000..e2f067ca --- /dev/null +++ b/batcher/michelson/marketmaker-ghostnet.tz @@ -0,0 +1,955 @@ +{ parameter + (or (or (or (pair %addVault string address) (address %change_admin_address)) + (or (address %change_batcher_address) (address %change_tokenmanager_address))) + (or (string %removeVault) (unit %tick))) ; + storage + (pair (pair (address %administrator) (address %batcher)) + (address %tokenmanager) + (pair %vaults (set %keys string) (big_map %values string address))) ; + code { LAMBDA + (pair nat nat nat) + nat + { UNPAIR 3 ; + PAIR ; + PAIR ; + LEFT nat ; + LOOP_LEFT + { UNPAIR ; + UNPAIR ; + PUSH nat 0 ; + DUP 3 ; + COMPARE ; + EQ ; + IF { DROP 2 ; RIGHT (pair (pair nat nat) nat) } + { PUSH nat 1 ; + PUSH nat 1 ; + DUP 4 ; + AND ; + COMPARE ; + EQ ; + IF { DUP ; DIG 3 ; MUL } { DIG 2 } ; + PUSH nat 1 ; + DIG 3 ; + LSR ; + DUP 3 ; + DIG 3 ; + MUL ; + PAIR ; + PAIR ; + LEFT nat } } } ; + LAMBDA + (pair int int) + int + { UNPAIR ; + SWAP ; + PUSH int 1 ; + PAIR ; + LEFT int ; + LOOP_LEFT + { UNPAIR ; + PUSH int 0 ; + DUP 3 ; + COMPARE ; + EQ ; + IF { SWAP ; DROP ; RIGHT (pair int int) } + { PUSH int 1 ; DIG 2 ; SUB ; DUP 3 ; DIG 2 ; MUL ; PAIR ; LEFT int } } ; + SWAP ; + DROP } ; + DIG 2 ; + UNPAIR ; + IF_LEFT + { DIG 2 ; + DIG 3 ; + DROP 2 ; + IF_LEFT + { IF_LEFT + { UNPAIR ; + DUP 3 ; + CAR ; + CAR ; + SENDER ; + COMPARE ; + EQ ; + IF {} { PUSH nat 114 ; FAILWITH } ; + PUSH mutez 1 ; + AMOUNT ; + COMPARE ; + LT ; + IF {} { PUSH nat 118 ; FAILWITH } ; + DUP 2 ; + UNIT ; + VIEW "get_native_token_from_vault" + (pair (nat %token_id) + (string %name) + (option %address address) + (nat %decimals) + (option %standard string)) ; + IF_NONE { PUSH nat 164 ; FAILWITH } {} ; + DUP 2 ; + SWAP ; + GET 3 ; + COMPARE ; + EQ ; + NOT ; + IF { DROP 3 ; PUSH nat 163 ; FAILWITH } + { DUP 3 ; + DUP 4 ; + CDR ; + DIG 4 ; + CDR ; + CDR ; + DUP ; + CAR ; + DUP 5 ; + MEM ; + IF { DUP ; CDR ; DIG 5 ; SOME ; DIG 5 ; UPDATE ; UPDATE 2 } + { DUP ; CDR ; DIG 5 ; DIG 5 ; SWAP ; SOME ; SWAP ; UPDATE ; UPDATE 2 } ; + UPDATE 2 ; + UPDATE 2 ; + NIL operation ; + PAIR } } + { DUP 2 ; + CAR ; + CAR ; + SENDER ; + COMPARE ; + EQ ; + IF {} { PUSH nat 114 ; FAILWITH } ; + PUSH mutez 1 ; + AMOUNT ; + COMPARE ; + LT ; + IF {} { PUSH nat 118 ; FAILWITH } ; + DUP 2 ; + DIG 2 ; + CAR ; + DIG 2 ; + UPDATE 1 ; + UPDATE 1 ; + NIL operation ; + PAIR } } + { IF_LEFT + { DUP 2 ; + CAR ; + CAR ; + SENDER ; + COMPARE ; + EQ ; + IF {} { PUSH nat 114 ; FAILWITH } ; + PUSH mutez 1 ; + AMOUNT ; + COMPARE ; + LT ; + IF {} { PUSH nat 118 ; FAILWITH } ; + DUP 2 ; + DIG 2 ; + CAR ; + DIG 2 ; + UPDATE 2 ; + UPDATE 1 } + { DUP 2 ; + CAR ; + CAR ; + SENDER ; + COMPARE ; + EQ ; + IF {} { PUSH nat 114 ; FAILWITH } ; + PUSH mutez 1 ; + AMOUNT ; + COMPARE ; + LT ; + IF {} { PUSH nat 118 ; FAILWITH } ; + DUP 2 ; + DIG 2 ; + CDR ; + DIG 2 ; + UPDATE 1 ; + UPDATE 2 } ; + NIL operation ; + PAIR } } + { IF_LEFT + { DIG 2 ; + DIG 3 ; + DROP 2 ; + DUP 2 ; + CAR ; + CAR ; + SENDER ; + COMPARE ; + EQ ; + IF {} { PUSH nat 114 ; FAILWITH } ; + PUSH mutez 1 ; + AMOUNT ; + COMPARE ; + LT ; + IF {} { PUSH nat 118 ; FAILWITH } ; + DUP 2 ; + CDR ; + CDR ; + DUP ; + CAR ; + DUP 3 ; + MEM ; + IF { CDR ; DUP 2 ; GET ; IF_NONE { NONE address } { SOME } } + { DROP ; NONE address } ; + IF_NONE + { DROP 2 ; PUSH nat 163 ; FAILWITH } + { UNIT ; + VIEW "get_native_token_from_vault" + (pair (nat %token_id) + (string %name) + (option %address address) + (nat %decimals) + (option %standard string)) ; + IF_NONE { PUSH nat 164 ; FAILWITH } {} ; + DUP 2 ; + SWAP ; + GET 3 ; + COMPARE ; + EQ ; + NOT ; + IF { DROP 2 ; PUSH nat 163 ; FAILWITH } + { DUP 2 ; + DUP 3 ; + CDR ; + DIG 3 ; + CDR ; + CDR ; + DUP ; + CAR ; + DUP 5 ; + MEM ; + IF { DUP ; CDR ; DIG 4 ; NONE address ; SWAP ; UPDATE ; UPDATE 2 } + { DIG 3 ; DROP } ; + UPDATE 2 ; + UPDATE 2 ; + NIL operation ; + PAIR } } } + { DROP ; + DUP ; + CAR ; + CDR ; + UNIT ; + VIEW "get_current_batches" + (list (pair (nat %batch_number) + (or %status + (or (pair %cleared + (pair (timestamp %at) + (pair %clearing + (pair %clearing_volumes (nat %minus) (nat %exact) (nat %plus)) + (or %clearing_tolerance (or (unit %exact) (unit %minus)) (unit %plus)) + (pair %total_cleared_volumes + (nat %buy_side_total_cleared_volume) + (nat %buy_side_volume_subject_to_clearing) + (nat %sell_side_total_cleared_volume) + (nat %sell_side_volume_subject_to_clearing)) + (pair %clearing_rate + (pair %swap (string %from) (string %to)) + (pair %rate (int %p) (int %q)) + (timestamp %when)))) + (pair %rate + (pair %swap (string %from) (string %to)) + (pair %rate (int %p) (int %q)) + (timestamp %when))) + (pair %closed (timestamp %closing_time) (timestamp %start_time))) + (timestamp %open)) + (pair %volumes + (nat %buy_minus_volume) + (nat %buy_exact_volume) + (nat %buy_plus_volume) + (nat %buy_total_volume) + (nat %sell_minus_volume) + (nat %sell_exact_volume) + (nat %sell_plus_volume) + (nat %sell_total_volume)) + (pair %pair string string) + (nat %holdings) + (option %market_vault_used address))) ; + IF_NONE { PUSH nat 167 ; FAILWITH } {} ; + DUP 2 ; + CDR ; + CDR ; + DUP 3 ; + CDR ; + CAR ; + UNIT ; + VIEW "get_valid_tokens" + (map string + (pair (nat %token_id) + (string %name) + (option %address address) + (nat %decimals) + (option %standard string))) ; + IF_NONE { PUSH nat 162 ; FAILWITH } {} ; + DUP 4 ; + CDR ; + CAR ; + UNIT ; + VIEW "get_valid_swaps" + (map string + (pair (pair %swap (string %from) (string %to)) + (address %oracle_address) + (string %oracle_asset_name) + (nat %oracle_precision) + (bool %is_disabled_for_deposits))) ; + IF_NONE { PUSH nat 165 ; FAILWITH } {} ; + NIL operation ; + DIG 4 ; + ITER { SWAP ; + DUP 2 ; + GET 7 ; + UNPAIR ; + PUSH nat 0 ; + DUP 5 ; + GET 5 ; + GET 7 ; + COMPARE ; + EQ ; + IF { NONE nat } { DUP 4 ; GET 5 ; GET 7 ; SOME } ; + PUSH nat 0 ; + DUP 6 ; + GET 5 ; + GET 14 ; + COMPARE ; + EQ ; + IF { DIG 4 ; DROP ; NONE nat } { DIG 4 ; GET 5 ; GET 14 ; SOME } ; + IF_NONE + { IF_NONE + { DROP 2 } + { DUP 7 ; + CAR ; + DUP 3 ; + MEM ; + NOT ; + IF { DROP 3 } + { DUP 7 ; + CAR ; + DUP 3 ; + MEM ; + IF { DUP 7 ; CDR ; DUP 3 ; GET ; IF_NONE { NONE address } { SOME } } + { NONE address } ; + IF_NONE { PUSH string "option is None" ; FAILWITH } {} ; + DUP 7 ; + DIG 3 ; + GET ; + IF_NONE + { DROP 4 ; PUSH nat 138 ; FAILWITH } + { DUP 7 ; + DIG 4 ; + GET ; + IF_NONE + { DROP 4 ; PUSH nat 138 ; FAILWITH } + { DIG 4 ; + DUP 2 ; + GET 3 ; + DUP 4 ; + GET 3 ; + DUP 8 ; + DUP 3 ; + DUP 3 ; + COMPARE ; + GT ; + IF { DIG 2 ; PUSH string "/" ; CONCAT ; DIG 2 ; CONCAT } + { SWAP ; PUSH string "/" ; CONCAT ; DIG 2 ; CONCAT } ; + GET ; + IF_NONE + { SWAP ; DIG 2 ; DIG 3 ; DIG 4 ; DROP 4 ; PUSH nat 117 ; FAILWITH } + { DUP ; + GET 3 ; + DUP 2 ; + GET 5 ; + VIEW "getPrice" (pair timestamp nat) ; + IF_NONE { PUSH nat 122 ; FAILWITH } {} ; + UNPAIR ; + DUP 3 ; + CAR ; + DUP 11 ; + DUP 2 ; + CAR ; + GET ; + IF_NONE { PUSH nat 111 ; FAILWITH } {} ; + DUP 12 ; + DIG 2 ; + CDR ; + GET ; + IF_NONE { PUSH nat 111 ; FAILWITH } {} ; + PUSH nat 1 ; + DIG 2 ; + PAIR ; + PAIR ; + DUP 4 ; + GET 7 ; + DUP ; + DUP 3 ; + CAR ; + CAR ; + GET 7 ; + COMPARE ; + GT ; + IF { DUP 2 ; + CAR ; + CAR ; + GET 7 ; + SUB ; + PUSH int 10 ; + PAIR ; + DUP 15 ; + SWAP ; + EXEC ; + DIG 3 ; + MUL ; + ISNAT ; + IF_NONE { PUSH nat 119 ; FAILWITH } {} ; + DUP 2 ; + CAR ; + CAR ; + GET 7 ; + INT ; + PUSH int 10 ; + PAIR ; + DUP 15 ; + SWAP ; + EXEC ; + SWAP } + { INT ; PUSH int 10 ; PAIR ; DUP 15 ; SWAP ; EXEC ; DIG 3 } ; + INT ; + PUSH int 1 ; + DIG 2 ; + PAIR ; + PUSH int 1 ; + DIG 2 ; + PAIR ; + DUP 2 ; + CAR ; + DUP 2 ; + CDR ; + MUL ; + DIG 2 ; + CDR ; + DIG 2 ; + CAR ; + MUL ; + PAIR ; + DIG 2 ; + SWAP ; + DUP 3 ; + CDR ; + GET 3 ; + DIG 3 ; + CAR ; + CAR ; + GET 3 ; + PAIR ; + PAIR 3 ; + DUP ; + CAR ; + DUP 10 ; + DUP 2 ; + CAR ; + GET ; + IF_NONE { PUSH nat 111 ; FAILWITH } {} ; + DUP 11 ; + DIG 2 ; + CDR ; + GET ; + IF_NONE { PUSH nat 111 ; FAILWITH } {} ; + SWAP ; + GET 7 ; + SWAP ; + GET 7 ; + SUB ; + DUP ; + ABS ; + INT ; + PUSH int 10 ; + PAIR ; + DUP 14 ; + SWAP ; + EXEC ; + PUSH int 0 ; + DUP 3 ; + COMPARE ; + EQ ; + IF { DROP 2 ; PUSH int 1 ; PUSH int 1 } + { PUSH int 0 ; + DIG 2 ; + COMPARE ; + LT ; + IF { PUSH int 1 ; + SWAP ; + PAIR ; + PUSH int 1 ; + PUSH int 1 ; + PAIR ; + DUP 2 ; + CAR ; + DUP 2 ; + CDR ; + MUL ; + DIG 2 ; + CDR ; + DIG 2 ; + CAR ; + MUL } + { PUSH int 1 ; SWAP } } ; + PAIR ; + DUP 2 ; + GET 3 ; + DUP 2 ; + CDR ; + DUP 2 ; + CDR ; + MUL ; + DIG 2 ; + CAR ; + DIG 2 ; + CAR ; + MUL ; + PAIR ; + UPDATE 3 ; + SWAP ; + CAR ; + CDR ; + DUP 5 ; + GET 3 ; + COMPARE ; + EQ ; + IF { DIG 5 ; + INT ; + SWAP ; + GET 3 ; + PUSH int 1 ; + DIG 2 ; + PAIR ; + DUP 2 ; + CAR ; + DUP 2 ; + CDR ; + MUL ; + DIG 2 ; + CDR ; + DIG 2 ; + CAR ; + MUL ; + PAIR ; + PUSH int 0 ; + DUP 2 ; + CAR ; + COMPARE ; + LT ; + IF { PUSH int -1 ; DUP 2 ; CDR ; MUL ; PUSH int -1 ; DIG 2 ; CAR ; MUL ; PAIR } + {} ; + DUP ; + CDR ; + PUSH nat 1 ; + PUSH nat 0 ; + PUSH nat 10 ; + PAIR 3 ; + DUP 13 ; + SWAP ; + EXEC ; + DIG 2 ; + CAR ; + MUL ; + EDIV ; + IF_NONE { PUSH string "DIV by 0" ; FAILWITH } {} ; + CAR ; + ISNAT ; + IF_NONE { PUSH nat 119 ; FAILWITH } {} ; + UNIT ; + RIGHT unit } + { DIG 5 ; + INT ; + PUSH int 1 ; + SWAP ; + PAIR ; + SWAP ; + GET 3 ; + DUP ; + CDR ; + DUP 3 ; + CDR ; + MUL ; + SWAP ; + CAR ; + DIG 2 ; + CAR ; + MUL ; + PAIR ; + PUSH int 0 ; + DUP 2 ; + CAR ; + COMPARE ; + LT ; + IF { PUSH int -1 ; DUP 2 ; CDR ; MUL ; PUSH int -1 ; DIG 2 ; CAR ; MUL ; PAIR } + {} ; + DUP ; + CDR ; + PUSH nat 1 ; + PUSH nat 0 ; + PUSH nat 10 ; + PAIR 3 ; + DUP 13 ; + SWAP ; + EXEC ; + DIG 2 ; + CAR ; + MUL ; + EDIV ; + IF_NONE { PUSH string "DIV by 0" ; FAILWITH } {} ; + CAR ; + ISNAT ; + IF_NONE { PUSH nat 119 ; FAILWITH } {} ; + UNIT ; + LEFT unit } ; + DIG 5 ; + CONTRACT %injectliquidity + (pair (pair (nat %amount) + (pair %from_token + (nat %token_id) + (string %name) + (option %address address) + (nat %decimals) + (option %standard string))) + (or %side (unit %buy) (unit %sell)) + (pair %to_token + (nat %token_id) + (string %name) + (option %address address) + (nat %decimals) + (option %standard string))) ; + IF_NONE { PUSH nat 157 ; FAILWITH } {} ; + PUSH mutez 0 ; + DIG 5 ; + DIG 3 ; + PAIR ; + DIG 5 ; + DIG 4 ; + PAIR ; + PAIR ; + TRANSFER_TOKENS } ; + CONS } } } } } + { SWAP ; + IF_NONE + { DUP 7 ; + CAR ; + DUP 4 ; + MEM ; + NOT ; + IF { DROP 3 } + { DUP 7 ; + CAR ; + DUP 4 ; + MEM ; + IF { DUP 7 ; CDR ; DUP 4 ; GET ; IF_NONE { NONE address } { SOME } } + { NONE address } ; + IF_NONE { PUSH string "option is None" ; FAILWITH } {} ; + DUP 7 ; + DIG 4 ; + GET ; + IF_NONE + { DROP 4 ; PUSH nat 138 ; FAILWITH } + { DUP 7 ; + DIG 4 ; + GET ; + IF_NONE + { DROP 4 ; PUSH nat 138 ; FAILWITH } + { DIG 4 ; + DUP 2 ; + GET 3 ; + DUP 4 ; + GET 3 ; + DUP 8 ; + DUP 3 ; + DUP 3 ; + COMPARE ; + GT ; + IF { DIG 2 ; PUSH string "/" ; CONCAT ; DIG 2 ; CONCAT } + { SWAP ; PUSH string "/" ; CONCAT ; DIG 2 ; CONCAT } ; + GET ; + IF_NONE + { SWAP ; DIG 2 ; DIG 3 ; DIG 4 ; DROP 4 ; PUSH nat 117 ; FAILWITH } + { DUP ; + GET 3 ; + DUP 2 ; + GET 5 ; + VIEW "getPrice" (pair timestamp nat) ; + IF_NONE { PUSH nat 122 ; FAILWITH } {} ; + UNPAIR ; + DUP 3 ; + CAR ; + DUP 11 ; + DUP 2 ; + CAR ; + GET ; + IF_NONE { PUSH nat 111 ; FAILWITH } {} ; + DUP 12 ; + DIG 2 ; + CDR ; + GET ; + IF_NONE { PUSH nat 111 ; FAILWITH } {} ; + PUSH nat 1 ; + DIG 2 ; + PAIR ; + PAIR ; + DUP 4 ; + GET 7 ; + DUP ; + DUP 3 ; + CAR ; + CAR ; + GET 7 ; + COMPARE ; + GT ; + IF { DUP 2 ; + CAR ; + CAR ; + GET 7 ; + SUB ; + PUSH int 10 ; + PAIR ; + DUP 15 ; + SWAP ; + EXEC ; + DIG 3 ; + MUL ; + ISNAT ; + IF_NONE { PUSH nat 119 ; FAILWITH } {} ; + DUP 2 ; + CAR ; + CAR ; + GET 7 ; + INT ; + PUSH int 10 ; + PAIR ; + DUP 15 ; + SWAP ; + EXEC ; + SWAP } + { INT ; PUSH int 10 ; PAIR ; DUP 15 ; SWAP ; EXEC ; DIG 3 } ; + INT ; + PUSH int 1 ; + DIG 2 ; + PAIR ; + PUSH int 1 ; + DIG 2 ; + PAIR ; + DUP 2 ; + CAR ; + DUP 2 ; + CDR ; + MUL ; + DIG 2 ; + CDR ; + DIG 2 ; + CAR ; + MUL ; + PAIR ; + DIG 2 ; + SWAP ; + DUP 3 ; + CDR ; + GET 3 ; + DIG 3 ; + CAR ; + CAR ; + GET 3 ; + PAIR ; + PAIR 3 ; + DUP ; + CAR ; + DUP 10 ; + DUP 2 ; + CAR ; + GET ; + IF_NONE { PUSH nat 111 ; FAILWITH } {} ; + DUP 11 ; + DIG 2 ; + CDR ; + GET ; + IF_NONE { PUSH nat 111 ; FAILWITH } {} ; + SWAP ; + GET 7 ; + SWAP ; + GET 7 ; + SUB ; + DUP ; + ABS ; + INT ; + PUSH int 10 ; + PAIR ; + DUP 14 ; + SWAP ; + EXEC ; + PUSH int 0 ; + DUP 3 ; + COMPARE ; + EQ ; + IF { DROP 2 ; PUSH int 1 ; PUSH int 1 } + { PUSH int 0 ; + DIG 2 ; + COMPARE ; + LT ; + IF { PUSH int 1 ; + SWAP ; + PAIR ; + PUSH int 1 ; + PUSH int 1 ; + PAIR ; + DUP 2 ; + CAR ; + DUP 2 ; + CDR ; + MUL ; + DIG 2 ; + CDR ; + DIG 2 ; + CAR ; + MUL } + { PUSH int 1 ; SWAP } } ; + PAIR ; + DUP 2 ; + GET 3 ; + DUP 2 ; + CDR ; + DUP 2 ; + CDR ; + MUL ; + DIG 2 ; + CAR ; + DIG 2 ; + CAR ; + MUL ; + PAIR ; + UPDATE 3 ; + SWAP ; + CAR ; + CDR ; + DUP 5 ; + GET 3 ; + COMPARE ; + EQ ; + IF { DIG 5 ; + INT ; + SWAP ; + GET 3 ; + PUSH int 1 ; + DIG 2 ; + PAIR ; + DUP 2 ; + CAR ; + DUP 2 ; + CDR ; + MUL ; + DIG 2 ; + CDR ; + DIG 2 ; + CAR ; + MUL ; + PAIR ; + PUSH int 0 ; + DUP 2 ; + CAR ; + COMPARE ; + LT ; + IF { PUSH int -1 ; DUP 2 ; CDR ; MUL ; PUSH int -1 ; DIG 2 ; CAR ; MUL ; PAIR } + {} ; + DUP ; + CDR ; + PUSH nat 1 ; + PUSH nat 0 ; + PUSH nat 10 ; + PAIR 3 ; + DUP 13 ; + SWAP ; + EXEC ; + DIG 2 ; + CAR ; + MUL ; + EDIV ; + IF_NONE { PUSH string "DIV by 0" ; FAILWITH } {} ; + CAR ; + ISNAT ; + IF_NONE { PUSH nat 119 ; FAILWITH } {} ; + UNIT ; + RIGHT unit } + { DIG 5 ; + INT ; + PUSH int 1 ; + SWAP ; + PAIR ; + SWAP ; + GET 3 ; + DUP ; + CDR ; + DUP 3 ; + CDR ; + MUL ; + SWAP ; + CAR ; + DIG 2 ; + CAR ; + MUL ; + PAIR ; + PUSH int 0 ; + DUP 2 ; + CAR ; + COMPARE ; + LT ; + IF { PUSH int -1 ; DUP 2 ; CDR ; MUL ; PUSH int -1 ; DIG 2 ; CAR ; MUL ; PAIR } + {} ; + DUP ; + CDR ; + PUSH nat 1 ; + PUSH nat 0 ; + PUSH nat 10 ; + PAIR 3 ; + DUP 13 ; + SWAP ; + EXEC ; + DIG 2 ; + CAR ; + MUL ; + EDIV ; + IF_NONE { PUSH string "DIV by 0" ; FAILWITH } {} ; + CAR ; + ISNAT ; + IF_NONE { PUSH nat 119 ; FAILWITH } {} ; + UNIT ; + LEFT unit } ; + DIG 5 ; + CONTRACT %injectliquidity + (pair (pair (nat %amount) + (pair %from_token + (nat %token_id) + (string %name) + (option %address address) + (nat %decimals) + (option %standard string))) + (or %side (unit %buy) (unit %sell)) + (pair %to_token + (nat %token_id) + (string %name) + (option %address address) + (nat %decimals) + (option %standard string))) ; + IF_NONE { PUSH nat 157 ; FAILWITH } {} ; + PUSH mutez 0 ; + DIG 5 ; + DIG 3 ; + PAIR ; + DIG 5 ; + DIG 4 ; + PAIR ; + PAIR ; + TRANSFER_TOKENS } ; + CONS } } } } + { DROP 4 } } } ; + SWAP ; + DIG 2 ; + DIG 3 ; + DIG 5 ; + DIG 6 ; + DROP 5 ; + PAIR } } } } + diff --git a/batcher/michelson/marketmaker-storage-ghostnet.tz b/batcher/michelson/marketmaker-storage-ghostnet.tz new file mode 100644 index 00000000..9fd22888 --- /dev/null +++ b/batcher/michelson/marketmaker-storage-ghostnet.tz @@ -0,0 +1,5 @@ +(Pair (Pair "tz1ca4batAsNxMYab3mUK5H4QRjY8drV4ViL" "KT1LhTpwSGcFAUUM3JYjW8XW74UHP82YzERy") + "tz1ca4batAsNxMYab3mUK5H4QRjY8drV4ViL" + {} + {}) + diff --git a/batcher/michelson/tzbtc-vault-storage-ghostnet.tz b/batcher/michelson/tzbtc-vault-storage-ghostnet.tz index f57f6c99..e69de29b 100644 --- a/batcher/michelson/tzbtc-vault-storage-ghostnet.tz +++ b/batcher/michelson/tzbtc-vault-storage-ghostnet.tz @@ -1,10 +0,0 @@ -(Pair (Pair (Pair "tz1ca4batAsNxMYab3mUK5H4QRjY8drV4ViL" "tz1ca4batAsNxMYab3mUK5H4QRjY8drV4ViL") - {} - "tz1ca4batAsNxMYab3mUK5H4QRjY8drV4ViL") - (Pair (Pair (Pair 0 "tzBTC" (Some "KT1P8RdJ5MfHMK5phKJ5JsfNfask5v2b2NQS") 8 (Some "FA1.2 token")) - 0) - "tz1ca4batAsNxMYab3mUK5H4QRjY8drV4ViL") - 0 - {} - {}) - diff --git a/batcher/storage/batcher_storage_ghostnet.mligo b/batcher/storage/batcher_storage_ghostnet.mligo index 3e900cf9..34dd7dbd 100644 --- a/batcher/storage/batcher_storage_ghostnet.mligo +++ b/batcher/storage/batcher_storage_ghostnet.mligo @@ -15,7 +15,7 @@ let f(_:unit) : Batcher.Storage.t = { fee_recipient = ("tz1burnburnburnburnburnburnburjAYjjX" : address); administrator = ("tz1ca4batAsNxMYab3mUK5H4QRjY8drV4ViL" : address); marketmaker = ("KT1XKvKiTTj8N6WKv3MhnZhFjZopFGQGBTdT" : address); - tokenmanager = ("KT19JLvQdDGUnssfL5n6rBozZpnaej3Xfvjy" : address); + tokenmanager = ("KT1SG9z3pU1cNh8dSranm5C5HXWphWi2pLwx" : address); limit_on_tokens_or_pairs = 10n; deposit_time_window_in_seconds = 600n; } diff --git a/batcher/storage/btctz_vault_storage_ghostnet.mligo b/batcher/storage/btctz_vault_storage_ghostnet.mligo index 540b4f8c..99bb9e49 100644 --- a/batcher/storage/btctz_vault_storage_ghostnet.mligo +++ b/batcher/storage/btctz_vault_storage_ghostnet.mligo @@ -4,7 +4,7 @@ let f(_:unit) : Vault.Vault.storage = { administrator = ("tz1ca4batAsNxMYab3mUK5H4QRjY8drV4ViL" : address); batcher = ("tz1ca4batAsNxMYab3mUK5H4QRjY8drV4ViL" : address); marketmaker = ("tz1ca4batAsNxMYab3mUK5H4QRjY8drV4ViL" : address); - tokenmanager = ("tz1ca4batAsNxMYab3mUK5H4QRjY8drV4ViL" : address); + tokenmanager = ("KT1SG9z3pU1cNh8dSranm5C5HXWphWi2pLwx" : address); total_shares = 0n; native_token = { token = { diff --git a/batcher/storage/eurl_vault_storage_ghostnet.mligo b/batcher/storage/eurl_vault_storage_ghostnet.mligo index e055177a..02b86fd0 100644 --- a/batcher/storage/eurl_vault_storage_ghostnet.mligo +++ b/batcher/storage/eurl_vault_storage_ghostnet.mligo @@ -4,7 +4,7 @@ let f(_:unit) : Vault.Vault.storage = { administrator = ("tz1ca4batAsNxMYab3mUK5H4QRjY8drV4ViL" : address); batcher = ("tz1ca4batAsNxMYab3mUK5H4QRjY8drV4ViL" : address); marketmaker = ("tz1ca4batAsNxMYab3mUK5H4QRjY8drV4ViL" : address); - tokenmanager = ("tz1ca4batAsNxMYab3mUK5H4QRjY8drV4ViL" : address); + tokenmanager = ("KT1SG9z3pU1cNh8dSranm5C5HXWphWi2pLwx" : address); total_shares = 0n; native_token = { token = { diff --git a/batcher/storage/tzbtc_vault_storage_ghostnet.mligo b/batcher/storage/tzbtc_vault_storage_ghostnet.mligo index 0669b8e2..6f6489ab 100644 --- a/batcher/storage/tzbtc_vault_storage_ghostnet.mligo +++ b/batcher/storage/tzbtc_vault_storage_ghostnet.mligo @@ -2,9 +2,9 @@ #import "../types.mligo" "Types" let f(_:unit) : Vault.Vault.storage = { administrator = ("tz1ca4batAsNxMYab3mUK5H4QRjY8drV4ViL" : address); - batcher = ("tz1ca4batAsNxMYab3mUK5H4QRjY8drV4ViL" : address); + batcher = ("" : address); marketmaker = ("tz1ca4batAsNxMYab3mUK5H4QRjY8drV4ViL" : address); - tokenmanager = ("tz1ca4batAsNxMYab3mUK5H4QRjY8drV4ViL" : address); + tokenmanager = ("KT1SG9z3pU1cNh8dSranm5C5HXWphWi2pLwx" : address); total_shares = 0n; native_token = { token = { diff --git a/batcher/storage/usdt_vault_storage_ghostnet.mligo b/batcher/storage/usdt_vault_storage_ghostnet.mligo index 53064cbc..cfd09ca2 100644 --- a/batcher/storage/usdt_vault_storage_ghostnet.mligo +++ b/batcher/storage/usdt_vault_storage_ghostnet.mligo @@ -4,7 +4,7 @@ let f(_:unit) : Vault.Vault.storage = { administrator = ("tz1ca4batAsNxMYab3mUK5H4QRjY8drV4ViL" : address); batcher = ("tz1ca4batAsNxMYab3mUK5H4QRjY8drV4ViL" : address); marketmaker = ("tz1ca4batAsNxMYab3mUK5H4QRjY8drV4ViL" : address); - tokenmanager = ("tz1ca4batAsNxMYab3mUK5H4QRjY8drV4ViL" : address); + tokenmanager = ("KT1SG9z3pU1cNh8dSranm5C5HXWphWi2pLwx" : address); total_shares = 0n; native_token = { token = { diff --git a/batcher/storage/usdtz_vault_storage_ghostnet.mligo b/batcher/storage/usdtz_vault_storage_ghostnet.mligo index 625e4739..e614c263 100644 --- a/batcher/storage/usdtz_vault_storage_ghostnet.mligo +++ b/batcher/storage/usdtz_vault_storage_ghostnet.mligo @@ -4,7 +4,7 @@ let f(_:unit) : Vault.Vault.storage = { administrator = ("tz1ca4batAsNxMYab3mUK5H4QRjY8drV4ViL" : address); batcher = ("tz1ca4batAsNxMYab3mUK5H4QRjY8drV4ViL" : address); marketmaker = ("tz1ca4batAsNxMYab3mUK5H4QRjY8drV4ViL" : address); - tokenmanager = ("tz1ca4batAsNxMYab3mUK5H4QRjY8drV4ViL" : address); + tokenmanager = ("KT1SG9z3pU1cNh8dSranm5C5HXWphWi2pLwx" : address); total_shares = 0n; native_token = { token = { diff --git a/batcher/utils.mligo b/batcher/utils.mligo index e6afa80f..34c2bc5a 100644 --- a/batcher/utils.mligo +++ b/batcher/utils.mligo @@ -1034,3 +1034,14 @@ let is_known_sender (addr : address) (error: nat): unit = if Tezos.get_sender () = addr then () else failwith error + +[@inline] +let send_liquidity_injection_request + (liq_request: liquidity_injection_request) + (vault:address) : operation = + let liq_req_ent = match Tezos.get_entrypoint_opt "%injectliquidity" vault with + | Some ep -> ep + | None -> failwith entrypoint_does_not_exist + in + Tezos.transaction liq_request 0mutez liq_req_ent +