From 9f2ad1005fa47d289e69f5e003443b6c5684a68c Mon Sep 17 00:00:00 2001 From: "Jason Ridgway-Taylor (~misfur-mondut)" <57174310+glottologist@users.noreply.github.com> Date: Thu, 31 Aug 2023 16:52:11 +0300 Subject: [PATCH] Current mainnet contract (#393) * Added enforcement of correct side when depositing tokens (#390) * Added enforcement of correct side when depositing tokens * Built contract * Enforce side (#391) * Added enforcement of correct side when depositing tokens * Built contract * :/:Dockerfile.tick.ghostnet * Enforce side (#392) * Added enforcement of correct side when depositing tokens * Built contract * :/:Dockerfile.tick.ghostnet * Added correct tokens for ghostnet contract * Switched UI to new ghostnet contract --- Dockerfile.tick.ghostnet | 3 +- batcher-ui/config/config.ghostnet.ts | 3 +- batcher/Makefile | 2 + batcher/batcher-ghostnet.tz | 47 +++++++++++++++---- batcher/batcher.mligo | 17 ++++++- .../storage/initial_storage_ghostnet.mligo | 34 ++++++++++++-- 6 files changed, 91 insertions(+), 15 deletions(-) diff --git a/Dockerfile.tick.ghostnet b/Dockerfile.tick.ghostnet index 6313e66b..8f9c841f 100644 --- a/Dockerfile.tick.ghostnet +++ b/Dockerfile.tick.ghostnet @@ -12,4 +12,5 @@ WORKDIR /etc/run COPY ./tick.sh /etc/run/ -CMD [ "/etc/run/tick.sh", "-b", "KT1VbeN9etQe5c2b6EAFfCZVaSTpiieHj5u1", "-f", "150" ] \ No newline at end of file +CMD [ "/etc/run/tick.sh", "-b", "KT1Txkbx4sDc3qXQubG48vL3ojoTK4HH8Ci8", "-f", "150" ] + diff --git a/batcher-ui/config/config.ghostnet.ts b/batcher-ui/config/config.ghostnet.ts index 875d7f2e..a2026c66 100644 --- a/batcher-ui/config/config.ghostnet.ts +++ b/batcher-ui/config/config.ghostnet.ts @@ -54,8 +54,9 @@ export default defineConfig({ REACT_APP_PATH_TO_BATCHER_LOGO: BATCHER_LOGO, REACT_APP_TEZOS_NODE_URI: 'https://ghostnet.tezos.marigold.dev', REACT_APP_TZKT_URI_API: 'https://api.ghostnet.tzkt.io', - REACT_APP_BATCHER_CONTRACT_HASH: 'KT1VsdkeG3PZZ5yraiBJTdKWhT9C8nNiLGu1', + REACT_APP_BATCHER_CONTRACT_HASH: 'KT1UPMR3WkoFRJYmBBbvv4Z9bBhKYuhCx7Cq', GA_TRACKING_ID: 'G-2K59PEELC8', + }, metas: [ { diff --git a/batcher/Makefile b/batcher/Makefile index 7c5478eb..c0844e03 100644 --- a/batcher/Makefile +++ b/batcher/Makefile @@ -1,7 +1,9 @@ .PHONY: test + LIGO_COMPILER_VERSION:=0.66.0 TEZOS_PROTOCOL:=mumbai + LIGO_DOCKER := docker run --rm -v $(PWD):$(PWD) -w $(PWD) ligolang/ligo:$(LIGO_COMPILER_VERSION) define test_ligo diff --git a/batcher/batcher-ghostnet.tz b/batcher/batcher-ghostnet.tz index 90d3b8b1..197a24d2 100644 --- a/batcher/batcher-ghostnet.tz +++ b/batcher/batcher-ghostnet.tz @@ -1044,9 +1044,40 @@ { PUSH string "/" ; CONCAT ; SWAP ; CONCAT } ; GET ; IF_NONE { PUSH nat 117 ; FAILWITH } {} ; + DUP ; GET 8 ; - IF { DROP 4 ; PUSH nat 125 ; FAILWITH } + IF { DROP 5 ; PUSH nat 125 ; FAILWITH } { DUP 4 ; + CAR ; + PUSH nat 0 ; + DUP 6 ; + GET 5 ; + COMPARE ; + EQ ; + IF { SWAP ; + CAR ; + CAR ; + CAR ; + CAR ; + SWAP ; + CAR ; + CAR ; + CAR ; + COMPARE ; + EQ ; + IF {} { PUSH nat 138 ; FAILWITH } } + { SWAP ; + CAR ; + CDR ; + CAR ; + SWAP ; + CAR ; + CAR ; + CAR ; + COMPARE ; + EQ ; + IF {} { PUSH nat 138 ; FAILWITH } } ; + DUP 4 ; CAR ; CAR ; CDR ; @@ -2617,17 +2648,12 @@ DIG 2 ; CAR ; DUP ; - CDR ; - GET 3 ; - SWAP ; CAR ; CAR ; - GET 3 ; - PAIR ; - DUP ; CAR ; DUP 2 ; CDR ; + CAR ; DIG 4 ; DUP 3 ; DUP 3 ; @@ -2635,7 +2661,12 @@ GT ; IF { DIG 2 ; PUSH string "/" ; CONCAT ; DIG 2 ; CONCAT } { SWAP ; PUSH string "/" ; CONCAT ; DIG 2 ; CONCAT } ; - NONE (pair (pair string string) address string nat bool) ; + NONE (pair (pair (pair (pair string (option address) nat (option string)) nat) + (pair string (option address) nat (option string))) + address + string + nat + bool) ; SWAP ; UPDATE ; DUP 3 ; diff --git a/batcher/batcher.mligo b/batcher/batcher.mligo index 4e7102a6..0f23fb82 100644 --- a/batcher/batcher.mligo +++ b/batcher/batcher.mligo @@ -39,7 +39,9 @@ [@inline] let cannot_update_scale_factor_to_less_than_the_minimum : nat = 135n [@inline] let cannot_update_scale_factor_to_more_than_the_maximum : nat = 136n [@inline] let cannot_remove_swap_pair_that_is_not_disabled : nat = 137n -[@inline] let token_name_not_in_list_of_valid_tokens : nat = 138n +[@inline] let incorrect_side_specified: nat = 138n +[@inline] let token_name_not_in_list_of_valid_tokens : nat = 139n + (* Constants *) @@ -1699,6 +1701,18 @@ let confirm_swap_pair_is_disabled_prior_to_removal (valid_swap:valid_swap) : unit = if valid_swap.is_disabled_for_deposits then () else failwith cannot_remove_swap_pair_that_is_not_disabled + +[@inline] +let enforce_correct_side + (order:external_swap_order) + (valid_swap:valid_swap) : unit = + let swap = order.swap in + if order.side = 0n then + if swap.from.token.name = valid_swap.swap.from.token.name then () else failwith incorrect_side_specified + else + if swap.from.token.name = valid_swap.swap.to.name then () else failwith incorrect_side_specified + + (* Register a deposit during a valid (Open) deposit time; fails otherwise. Updates the current_batch if the time is valid but the new batch was not initialized. *) [@inline] @@ -1708,6 +1722,7 @@ let deposit (external_order: external_swap_order) (storage : storage) : result = let pair_name = Utils.get_rate_name_from_pair pair in let valid_swap = get_valid_swap_reduced pair_name storage in if valid_swap.is_disabled_for_deposits then failwith swap_is_disabled_for_deposits else + let () = enforce_correct_side external_order valid_swap in let fee_amount_in_mutez = storage.fee_in_mutez in let fee_provided = Tezos.get_amount () in if fee_provided < fee_amount_in_mutez then failwith insufficient_swap_fee else diff --git a/batcher/storage/initial_storage_ghostnet.mligo b/batcher/storage/initial_storage_ghostnet.mligo index 28e33428..2a642f93 100644 --- a/batcher/storage/initial_storage_ghostnet.mligo +++ b/batcher/storage/initial_storage_ghostnet.mligo @@ -28,8 +28,21 @@ let f(_:unit) : Batcher.Storage.t = { valid_swaps = Map.literal [ ("tzBTC/USDT", { swap = { - from = "tzBTC"; - to = "USDT"; + from = { + amount = 1n; + token = { + name = "tzBTC"; + address = Some(("KT1P8RdJ5MfHMK5phKJ5JsfNfask5v2b2NQS" : address)); + decimals = 8n; + standard = Some "FA1.2 token" + } + }; + to = { + name = "USDT"; + address = Some(("KT1WNrZ7pEbpmYBGPib1e7UVCeC6GA6TkJYR" : address)); + decimals = 6n; + standard = Some "FA2 token"; + } }; oracle_address = ("KT1DG2g5DPYWqyHKGpRL579YkYZwJxibwaAZ": address); oracle_asset_name = "BTC-USDT"; @@ -39,8 +52,21 @@ let f(_:unit) : Batcher.Storage.t = { ); ("tzBTC/EURL", { swap = { - from = "tzBTC"; - to = "EURL"; + from = { + amount = 1n; + token = { + name = "tzBTC"; + address = Some(("KT1P8RdJ5MfHMK5phKJ5JsfNfask5v2b2NQS" : address)); + decimals = 8n; + standard = Some "FA1.2 token"; + } + }; + to = { + name = "EURL"; + address = Some(("KT1RcHjqDWWycYQGrz4KBYoGZSMmMuVpkmuS" : address)); + decimals = 6n; + standard = Some "FA2 token"; + } }; oracle_address = ("KT1DG2g5DPYWqyHKGpRL579YkYZwJxibwaAZ": address); oracle_asset_name = "BTC-EUR";