From 2b73699aa033f999457044ae21734fa6559f2d2b Mon Sep 17 00:00:00 2001 From: Jason Ridgway-Taylor Date: Tue, 7 Nov 2023 13:47:34 +0530 Subject: [PATCH] Updated batcher contracts to newest version --- batcher/Makefile | 101 +- batcher/batcher-ghostnet.tz | 6747 ----------------- batcher/batcher-mainnet.tz | 4039 ---------- batcher/batcher-storage-mainnet.tz | 16 - batcher/batcher.mligo | 731 +- batcher/errors.mligo | 13 +- batcher/ligo.json | 10 + batcher/marketmaker.mligo | 766 +- batcher/michelson/batcher-ghostnet.tz | 4808 ++++++++++++ batcher/michelson/batcher-storage-ghostnet.tz | 9 + batcher/michelson/btctz-vault-ghostnet.tz | 1650 ++++ .../michelson/btctz-vault-storage-ghostnet.tz | 9 + batcher/michelson/eurl-vault-ghostnet.tz | 1650 ++++ .../michelson/eurl-vault-storage-ghostnet.tz | 9 + batcher/michelson/marketmaker-ghostnet.tz | 1029 +++ .../michelson/marketmaker-storage-ghostnet.tz | 5 + batcher/michelson/tokenmanager-ghostnet.tz | 1365 ++++ .../tokenmanager-storage-ghostnet.tz} | 9 +- batcher/michelson/tzbtc-vault-ghostnet.tz | 1650 ++++ .../michelson/tzbtc-vault-storage-ghostnet.tz | 10 + batcher/michelson/usdt-vault-ghostnet.tz | 1650 ++++ .../michelson/usdt-vault-storage-ghostnet.tz | 9 + batcher/michelson/usdtz-vault-ghostnet.tz | 1650 ++++ .../michelson/usdtz-vault-storage-ghostnet.tz | 10 + .../storage/batcher_storage_ghostnet.mligo | 23 + ...et.mligo => batcher_storage_mainnet.mligo} | 1 + .../btctz_vault_storage_ghostnet.mligo | 22 + .../storage/eurl_vault_storage_ghostnet.mligo | 22 + .../marketmaker_storage_ghostnet.mligo | 183 +- .../storage/marketmaker_storage_mainnet.mligo | 59 - ...go => tokenmanager_storage_ghostnet.mligo} | 27 +- .../tzbtc_vault_storage_ghostnet.mligo | 22 + .../storage/usdt_vault_storage_ghostnet.mligo | 22 + .../usdtz_vault_storage_ghostnet.mligo | 22 + batcher/test/common/helpers.mligo | 157 +- batcher/test/common/storage.mligo | 112 +- batcher/test/common/utils.mligo | 45 +- batcher/test/mocks/oracle.mligo | 18 +- batcher/test/test-tokenmanager.mligo | 44 + batcher/test/test-vault.mligo | 0 .../test_add_remove_token_swap_pair.mligo | 9 +- .../admin/test_amend_token_pair_limit.mligo | 0 .../admin/test_change_admin_address.mligo | 87 + .../test_change_marketmaker_address.mligo | 87 + .../test_change_oracle_source_of_pair.mligo | 0 ...enable_disable_swap_pair_for_deposit.mligo | 0 .../admin/test_change_admin_address.mligo | 87 + .../admin/test_change_batcher_address.mligo | 87 + .../user}/test_add_update_liquidity.mligo | 0 .../endpoints/user}/test_claim_rewards.mligo | 0 .../user}/test_remove_liquidity.mligo | 0 batcher/tokenmanager.mligo | 136 + batcher/types.mligo | 434 +- batcher/utils.mligo | 577 +- batcher/vault.mligo | 407 + 55 files changed, 18182 insertions(+), 12453 deletions(-) delete mode 100644 batcher/batcher-ghostnet.tz delete mode 100644 batcher/batcher-mainnet.tz delete mode 100644 batcher/batcher-storage-mainnet.tz create mode 100644 batcher/ligo.json create mode 100644 batcher/michelson/batcher-ghostnet.tz create mode 100644 batcher/michelson/batcher-storage-ghostnet.tz create mode 100644 batcher/michelson/btctz-vault-ghostnet.tz create mode 100644 batcher/michelson/btctz-vault-storage-ghostnet.tz create mode 100644 batcher/michelson/eurl-vault-ghostnet.tz create mode 100644 batcher/michelson/eurl-vault-storage-ghostnet.tz create mode 100644 batcher/michelson/marketmaker-ghostnet.tz create mode 100644 batcher/michelson/marketmaker-storage-ghostnet.tz create mode 100644 batcher/michelson/tokenmanager-ghostnet.tz rename batcher/{batcher-storage-ghostnet.tz => michelson/tokenmanager-storage-ghostnet.tz} (83%) create mode 100644 batcher/michelson/tzbtc-vault-ghostnet.tz create mode 100644 batcher/michelson/tzbtc-vault-storage-ghostnet.tz create mode 100644 batcher/michelson/usdt-vault-ghostnet.tz create mode 100644 batcher/michelson/usdt-vault-storage-ghostnet.tz create mode 100644 batcher/michelson/usdtz-vault-ghostnet.tz create mode 100644 batcher/michelson/usdtz-vault-storage-ghostnet.tz create mode 100644 batcher/storage/batcher_storage_ghostnet.mligo rename batcher/storage/{initial_storage_mainnet.mligo => batcher_storage_mainnet.mligo} (98%) create mode 100644 batcher/storage/btctz_vault_storage_ghostnet.mligo create mode 100644 batcher/storage/eurl_vault_storage_ghostnet.mligo delete mode 100644 batcher/storage/marketmaker_storage_mainnet.mligo rename batcher/storage/{initial_storage_ghostnet.mligo => tokenmanager_storage_ghostnet.mligo} (75%) create mode 100644 batcher/storage/tzbtc_vault_storage_ghostnet.mligo create mode 100644 batcher/storage/usdt_vault_storage_ghostnet.mligo create mode 100644 batcher/storage/usdtz_vault_storage_ghostnet.mligo create mode 100644 batcher/test/test-tokenmanager.mligo create mode 100644 batcher/test/test-vault.mligo rename batcher/test/{batcher => tokenmanager}/endpoints/admin/test_add_remove_token_swap_pair.mligo (96%) rename batcher/test/{batcher => tokenmanager}/endpoints/admin/test_amend_token_pair_limit.mligo (100%) create mode 100644 batcher/test/tokenmanager/endpoints/admin/test_change_admin_address.mligo create mode 100644 batcher/test/tokenmanager/endpoints/admin/test_change_marketmaker_address.mligo rename batcher/test/{batcher => tokenmanager}/endpoints/admin/test_change_oracle_source_of_pair.mligo (100%) rename batcher/test/{batcher => tokenmanager}/endpoints/admin/test_enable_disable_swap_pair_for_deposit.mligo (100%) create mode 100644 batcher/test/vault/endpoints/admin/test_change_admin_address.mligo create mode 100644 batcher/test/vault/endpoints/admin/test_change_batcher_address.mligo rename batcher/test/{market_maker => vault/endpoints/user}/test_add_update_liquidity.mligo (100%) rename batcher/test/{market_maker => vault/endpoints/user}/test_claim_rewards.mligo (100%) rename batcher/test/{market_maker => vault/endpoints/user}/test_remove_liquidity.mligo (100%) create mode 100644 batcher/tokenmanager.mligo create mode 100644 batcher/vault.mligo diff --git a/batcher/Makefile b/batcher/Makefile index 6102106b..d03a58de 100644 --- a/batcher/Makefile +++ b/batcher/Makefile @@ -6,6 +6,7 @@ LIGO_DOCKER := docker run --rm -v $(PWD):$(PWD) -w $(PWD) ligolang/ligo:$(LIGO_ TEST_DIRECTORY:=test STORAGE_DIRECTORY:=storage +MICHELSON_DIRECTORY:=michelson TOKENS_DIRECTORY:=$(BATCHER_TEST_DIRECTORY)/tokens FA12_DIRECTORY:=$(TOKENS_DIRECTORY)/fa12 FA12_STORAGE_DIRECTORY:=$(FA12_DIRECTORY)/storage @@ -24,6 +25,11 @@ define compile_storage $(LIGO_DOCKER) compile expression cameligo -p $(TEZOS_PROTOCOL) --michelson-format text --werror --init-file $(1) 'f()' > $(2) endef +define build_vault + $(call compile_contract,vault.mligo, $(MICHELSON_DIRECTORY)/'$(1)-vault-$(2).tz') + $(call compile_storage,$(STORAGE_DIRECTORY)/$(1)_vault_storage_$(2).mligo, $(MICHELSON_DIRECTORY)/$(1)-vault-storage-$(2).tz) +endef + define measure_contract $(LIGO_DOCKER) info measure-contract -p $(TEZOS_PROTOCOL) $(1) endef @@ -33,58 +39,82 @@ define install_deps endef define clean_mainnet_files - rm -rf *mainnet.tz + rm -rf $(MICHELSON_DIRECTORY)/*mainnet.tz endef define clean_ghostnet_files - rm -rf *ghostnet.tz + rm -rf $(MICHELSON_DIRECTORY)/*ghostnet.tz endef -clean: +clean-mainnet: $(call clean_mainnet_files) +clean-ghostnet: $(call clean_ghostnet_files) -build-mainnet: +clean: $(call clean_mainnet_files) - $(call compile_contract,batcher.mligo, batcher-mainnet.tz) - $(call compile_storage,$(STORAGE_DIRECTORY)/initial_storage_mainnet.mligo, batcher-storage-mainnet.tz) -build-ghostnet: $(call clean_ghostnet_files) - $(call compile_contract,batcher.mligo, batcher-ghostnet.tz) - $(call compile_storage,$(STORAGE_DIRECTORY)/initial_storage_ghostnet.mligo, batcher-storage-ghostnet.tz) +build-batcher-mainnet: + $(call compile_contract,batcher.mligo, $(MICHELSON_DIRECTORY)/batcher-mainnet.tz) + $(call compile_storage,$(STORAGE_DIRECTORY)/batcher_storage_mainnet.mligo, $(MICHELSON_DIRECTORY)/batcher-storage-mainnet.tz) +build-batcher-ghostnet: + $(call compile_contract,batcher.mligo, $(MICHELSON_DIRECTORY)/batcher-ghostnet.tz) + $(call compile_storage,$(STORAGE_DIRECTORY)/batcher_storage_ghostnet.mligo, $(MICHELSON_DIRECTORY)/batcher-storage-ghostnet.tz) build-mm-mainnet: - $(call clean_mainnet_files) - $(call compile_contract,marketmaker.mligo, marketmaker-mainnet.tz) - $(call compile_storage,$(STORAGE_DIRECTORY)/marketmaker_storage_mainnet.mligo, marketmaker-storage-mainnet.tz) + $(call compile_contract,marketmaker.mligo, $(MICHELSON_DIRECTORY)/marketmaker-mainnet.tz) + $(call compile_storage,$(STORAGE_DIRECTORY)/marketmaker_storage_mainnet.mligo, $(MICHELSON_DIRECTORY)/marketmaker-storage-mainnet.tz) build-mm-ghostnet: - $(call clean_ghostnet_files) - $(call compile_contract,marketmaker.mligo, marketmaker-ghostnet.tz) - $(call compile_storage,$(STORAGE_DIRECTORY)/marketmaker_storage_ghostnet.mligo, marketmaker-storage-ghostnet.tz) + $(call compile_contract,marketmaker.mligo, $(MICHELSON_DIRECTORY)/marketmaker-ghostnet.tz) + $(call compile_storage,$(STORAGE_DIRECTORY)/marketmaker_storage_ghostnet.mligo, $(MICHELSON_DIRECTORY)/marketmaker-storage-ghostnet.tz) +build-tm-mainnet: + $(call compile_contract,tokenmanager.mligo, $(MICHELSON_DIRECTORY)/tokenmanager-mainnet.tz) + $(call compile_storage,$(STORAGE_DIRECTORY)/tokenmanager_storage_mainnet.mligo, $(MICHELSON_DIRECTORY)/tokenmanager-storage-mainnet.tz) +build-tm-ghostnet: + $(call compile_contract,tokenmanager.mligo, $(MICHELSON_DIRECTORY)/tokenmanager-ghostnet.tz) + $(call compile_storage,$(STORAGE_DIRECTORY)/tokenmanager_storage_ghostnet.mligo, $(MICHELSON_DIRECTORY)/tokenmanager-storage-ghostnet.tz) +build-tzbtc-vault-mainnet: + $(call build_vault,tzbtc,mainnet) +build-tzbtc-vault-ghostnet: + $(call build_vault,tzbtc,ghostnet) +build-btctz-vault-mainnet: + $(call build_vault,btctz,mainnet) +build-btctz-vault-ghostnet: + $(call build_vault,btctz,ghostnet) +build-eurl-vault-mainnet: + $(call build_vault,eurl,mainnet) +build-eurl-vault-ghostnet: + $(call build_vault,eurl,ghostnet) +build-usdt-vault-mainnet: + $(call build_vault,usdt,mainnet) +build-usdt-vault-ghostnet: + $(call build_vault,usdt,ghostnet) +build-usdtz-vault-mainnet: + $(call build_vault,usdtz,mainnet) +build-usdtz-vault-ghostnet: + $(call build_vault,usdtz,ghostnet) build-tzBTC: - $(call clean_files) - $(call compile_contract,$(FA12_DIRECTORY)/main.mligo, tzBTC_token.tz) - $(call compile_storage,$(FA12_STORAGE_DIRECTORY)/tzBTC_storage.mligo, tzBTC_token_storage.tz) + $(call compile_contract,$(FA12_DIRECTORY)/main.mligo, $(MICHELSON_DIRECTORY)/tzBTC_token.tz) + $(call compile_storage,$(FA12_STORAGE_DIRECTORY)/tzBTC_storage.mligo, $(MICHELSON_DIRECTORY)/tzBTC_token_storage.tz) build-USDT: - $(call clean_files) - $(call compile_contract,$(FA2_DIRECTORY)/main.mligo, USDT_token.tz) - $(call compile_storage,$(FA2_STORAGE_DIRECTORY)/USDT_storage.mligo, USDT_token_storage.tz) + $(call compile_contract,$(FA2_DIRECTORY)/main.mligo, $(MICHELSON_DIRECTORY)/USDT_token.tz) + $(call compile_storage,$(FA2_STORAGE_DIRECTORY)/USDT_storage.mligo, $(MICHELSON_DIRECTORY)/USDT_token_storage.tz) build-CTEZ: - $(call clean_files) - $(call compile_contract,$(FA12_DIRECTORY)/main.mligo, CTEZ_token.tz) - $(call compile_storage,$(FA12_STORAGE_DIRECTORY)/CTEZ_storage.mligo, CTEZ_token_storage.tz) + $(call compile_contract,$(FA12_DIRECTORY)/main.mligo, $(MICHELSON_DIRECTORY)/CTEZ_token.tz) + $(call compile_storage,$(FA12_STORAGE_DIRECTORY)/CTEZ_storage.mligo, $(MICHELSON_DIRECTORY)/CTEZ_token_storage.tz) build-KUSD: - $(call clean_files) - $(call compile_contract,$(FA12_DIRECTORY)/main.mligo, KUSD_token.tz) - $(call compile_storage,$(FA12_STORAGE_DIRECTORY)/KUSD_storage.mligo, KUSD_token_storage.tz) + $(call compile_contract,$(FA12_DIRECTORY)/main.mligo, $(MICHELSON_DIRECTORY)/KUSD_token.tz) + $(call compile_storage,$(FA12_STORAGE_DIRECTORY)/KUSD_storage.mligo, $(MICHELSON_DIRECTORY)/KUSD_token_storage.tz) build-EURL: - $(call clean_files) - $(call compile_contract, $(FA2_DIRECTORY)/main.mligo, EURL_token.tz) - $(call compile_storage, $(FA2_STORAGE_DIRECTORY)/EURL_storage.mligo, EURL_token_storage.tz) + $(call compile_contract, $(FA2_DIRECTORY)/main.mligo, $(MICHELSON_DIRECTORY)/EURL_token.tz) + $(call compile_storage, $(FA2_STORAGE_DIRECTORY)/EURL_storage.mligo, $(MICHELSON_DIRECTORY)/EURL_token_storage.tz) build-fa12-tzBTC: - $(call clean_files) - $(call compile_contract,$(FA12_DIRECTORY)/main.mligo, tzBTC_fa12_token.tz) - $(call compile_storage,$(FA12_STORAGE_DIRECTORY)/tzBTC_storage.mligo, tzBTC_fa12_token_storage.tz) + $(call compile_contract,$(FA12_DIRECTORY)/main.mligo, $(MICHELSON_DIRECTORY)/tzBTC_fa12_token.tz) + $(call compile_storage,$(FA12_STORAGE_DIRECTORY)/tzBTC_storage.mligo, $(MICHELSON_DIRECTORY)/tzBTC_fa12_token_storage.tz) +build-all-ghostnet: build-tm-ghostnet build-tzbtc-vault-ghostnet build-eurl-vault-ghostnet build-usdt-vault-ghostnet build-btctz-vault-ghostnet build-usdtz-vault-ghostnet build-mm-ghostnet build-batcher-ghostnet +build-all-mainnet: build-tm-mainnet build-tzbtc-vault-mainnet build-eurl-vault-mainnet build-usdt-vault-mainnet build-btctz-vault-mainnet build-usdtz-vault-mainnet build-mm-mainnet build-batcher-mainnet test-mm: $(call test_ligo,$(TEST_DIRECTORY)/test-market-maker.mligo) +test-tm: + $(call test_ligo,$(TEST_DIRECTORY)/test-tokenmanager.mligo) test-batcher: $(call test_ligo,$(TEST_DIRECTORY)/test-batcher.mligo) test-all: @@ -92,5 +122,10 @@ test-all: $(call test_ligo,$(TEST_DIRECTORY)/test-market-maker.mligo) measure: $(call measure_contract,batcher.mligo) +measure-mm: + $(call measure_contract,marketmaker.mligo) +measure-tm: + $(call measure_contract,tokenmanager.mligo) install: $(call install_deps) + diff --git a/batcher/batcher-ghostnet.tz b/batcher/batcher-ghostnet.tz deleted file mode 100644 index 7a9117c9..00000000 --- a/batcher/batcher-ghostnet.tz +++ /dev/null @@ -1,6747 +0,0 @@ -{ parameter - (or (or (or (or (or (pair %add_or_update_metadata (string %key) (bytes %value)) - (pair %add_token_swap_pair - (pair %swap - (pair %from - (pair %token - (nat %token_id) - (string %name) - (option %address address) - (nat %decimals) - (option %standard string)) - (nat %amount)) - (pair %to - (nat %token_id) - (string %name) - (option %address address) - (nat %decimals) - (option %standard string))) - (address %oracle_address) - (string %oracle_asset_name) - (nat %oracle_precision) - (bool %is_disabled_for_deposits))) - (or (nat %amend_token_and_pair_limit) (pair %cancel string string))) - (or (or (address %change_admin_address) (nat %change_deposit_time_window)) - (or (mutez %change_fee) (address %change_fee_recipient_address)))) - (or (or (or (address %change_marketmaker_address) - (pair %change_oracle_source_of_pair - (string %pair_name) - (address %oracle_address) - (string %oracle_asset_name) - (nat %oracle_precision))) - (or (pair %deposit - (pair %swap - (pair %from - (pair %token - (nat %token_id) - (string %name) - (option %address address) - (nat %decimals) - (option %standard string)) - (nat %amount)) - (pair %to - (nat %token_id) - (string %name) - (option %address address) - (nat %decimals) - (option %standard string))) - (timestamp %created_at) - (nat %side) - (nat %tolerance)) - (string %disable_swap_pair_for_deposit))) - (or (or (string %enable_swap_pair_for_deposit) (unit %redeem)) - (or (nat %redeemByBatch) (string %remove_metadata))))) - (or (pair %remove_token_swap_pair - (pair %swap - (pair %from - (pair %token - (nat %token_id) - (string %name) - (option %address address) - (nat %decimals) - (option %standard string)) - (nat %amount)) - (pair %to - (nat %token_id) - (string %name) - (option %address address) - (nat %decimals) - (option %standard string))) - (address %oracle_address) - (string %oracle_asset_name) - (nat %oracle_precision) - (bool %is_disabled_for_deposits)) - (string %tick))) ; - storage - (pair (pair (pair (pair (address %administrator) - (pair %batch_set - (map %current_batch_indices string nat) - (big_map %batches - nat - (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) - (bool %market_vault_used))))) - (nat %deposit_time_window_in_seconds) - (mutez %fee_in_mutez)) - (pair (address %fee_recipient) (nat %last_order_number)) - (nat %limit_on_tokens_or_pairs) - (address %marketmaker)) - (pair (pair (big_map %metadata string bytes) - (big_map %rates_current - string - (pair (pair %swap (string %from) (string %to)) - (pair %rate (int %p) (int %q)) - (timestamp %when)))) - (big_map %user_batch_ordertypes - address - (map nat - (map (pair (or %side (unit %buy) (unit %sell)) - (or %tolerance (or (unit %exact) (unit %minus)) (unit %plus))) - nat))) - (map %valid_swaps - string - (pair (pair %swap (string %from) (string %to)) - (address %oracle_address) - (string %oracle_asset_name) - (nat %oracle_precision) - (bool %is_disabled_for_deposits)))) - (map %valid_tokens - string - (pair (nat %token_id) - (string %name) - (option %address address) - (nat %decimals) - (option %standard string)))) ; - code { LAMBDA - (pair nat nat) - nat - { UNPAIR ; - PUSH nat 1 ; - DUG 2 ; - 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 } } } ; - PUSH int 1 ; - PUSH int 10000 ; - PAIR ; - PUSH int 1 ; - PUSH int 10001 ; - PAIR ; - DUP 2 ; - CAR ; - DUP 2 ; - CDR ; - MUL ; - DIG 2 ; - CDR ; - DIG 2 ; - CAR ; - MUL ; - PAIR ; - 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 } ; - LAMBDA - (pair (pair (pair nat string (option address) nat (option string)) nat) - (map string (pair (pair nat string (option address) nat (option string)) nat))) - (map string (pair (pair nat string (option address) nat (option string)) nat)) - { UNPAIR ; - SWAP ; - UNIT ; - RIGHT unit ; - DIG 2 ; - DUP ; - CAR ; - GET 3 ; - DUP 4 ; - DUP 2 ; - GET ; - IF_NONE - { DIG 2 ; DROP ; SWAP ; SOME ; SWAP ; UPDATE } - { DIG 3 ; - IF_LEFT - { DROP ; - DUP ; - CDR ; - DUP 4 ; - CDR ; - COMPARE ; - GT ; - IF { DROP ; PUSH nat 111 ; FAILWITH } - { DUP 3 ; CDR ; SWAP ; CDR ; SUB ; ABS } } - { DROP ; CDR ; DUP 3 ; CDR ; ADD } ; - DIG 3 ; - DIG 3 ; - DIG 2 ; - UPDATE 2 ; - SOME ; - DIG 2 ; - UPDATE } } ; - DIG 4 ; - UNPAIR ; - IF_LEFT - { DIG 3 ; - DIG 4 ; - DROP 2 ; - IF_LEFT - { DIG 3 ; - DROP ; - IF_LEFT - { IF_LEFT - { DIG 2 ; - DROP ; - IF_LEFT - { DUP 2 ; - CAR ; - CAR ; - CAR ; - CAR ; - SENDER ; - COMPARE ; - EQ ; - IF {} { PUSH nat 114 ; FAILWITH } ; - PUSH mutez 1 ; - AMOUNT ; - COMPARE ; - LT ; - IF {} { PUSH nat 118 ; FAILWITH } ; - DUP 2 ; - DUP 3 ; - CDR ; - DUP ; - CAR ; - DUP ; - CAR ; - DUP 6 ; - CDR ; - CAR ; - CAR ; - CAR ; - DUP 6 ; - CAR ; - GET ; - IF_NONE - { DIG 5 ; - CDR ; - CAR ; - CAR ; - CAR ; - DUP 6 ; - CDR ; - DIG 6 ; - CAR ; - SWAP ; - SOME ; - SWAP ; - UPDATE } - { DROP ; - DIG 5 ; - CDR ; - CAR ; - CAR ; - CAR ; - DUP 6 ; - CDR ; - SOME ; - DIG 6 ; - CAR ; - UPDATE } ; - UPDATE 1 ; - UPDATE 1 ; - UPDATE 1 ; - UPDATE 2 ; - NIL operation ; - PAIR } - { DUP 2 ; - CAR ; - CAR ; - CAR ; - CAR ; - SENDER ; - COMPARE ; - EQ ; - IF {} { PUSH nat 114 ; FAILWITH } ; - PUSH mutez 1 ; - AMOUNT ; - COMPARE ; - LT ; - IF {} { PUSH nat 118 ; FAILWITH } ; - PUSH nat 6 ; - DUP 2 ; - CAR ; - CAR ; - CAR ; - GET 7 ; - COMPARE ; - LT ; - IF { DROP 2 ; PUSH nat 134 ; FAILWITH } - { PUSH nat 6 ; - DUP 2 ; - CAR ; - CDR ; - GET 7 ; - COMPARE ; - LT ; - IF { DROP 2 ; PUSH nat 134 ; FAILWITH } - { PUSH nat 6 ; - DUP 2 ; - GET 7 ; - COMPARE ; - NEQ ; - IF { DROP 2 ; PUSH nat 133 ; FAILWITH } - { DUP 2 ; - CDR ; - CDR ; - DUP 3 ; - CDR ; - CAR ; - CDR ; - CDR ; - DUP 4 ; - CAR ; - CDR ; - CDR ; - CAR ; - DUP 4 ; - CAR ; - DUP ; - CAR ; - CAR ; - DUP 2 ; - CDR ; - DUP 4 ; - PUSH nat 1 ; - DUP 7 ; - SIZE ; - ADD ; - COMPARE ; - GT ; - IF { DIG 3 ; DROP ; PUSH nat 127 ; FAILWITH } - { PUSH bool False ; - DUP 7 ; - ITER { CDR ; - SWAP ; - DUP 2 ; - GET 8 ; - DUP 5 ; - GET 8 ; - COMPARE ; - EQ ; - DUP 3 ; - GET 7 ; - DUP 6 ; - GET 7 ; - COMPARE ; - EQ ; - DUP 4 ; - GET 5 ; - DUP 7 ; - GET 5 ; - COMPARE ; - EQ ; - DUP 5 ; - GET 3 ; - DUP 8 ; - GET 3 ; - COMPARE ; - EQ ; - DIG 5 ; - CAR ; - DUP 8 ; - CAR ; - COMPARE ; - EQ ; - AND ; - AND ; - AND ; - AND ; - OR } ; - PUSH bool False ; - DUP 8 ; - ITER { CDR ; - SWAP ; - DUP 2 ; - GET 8 ; - DUP 5 ; - GET 8 ; - COMPARE ; - EQ ; - DUP 3 ; - GET 7 ; - DUP 6 ; - GET 7 ; - COMPARE ; - EQ ; - DUP 4 ; - GET 5 ; - DUP 7 ; - GET 5 ; - COMPARE ; - EQ ; - DUP 5 ; - GET 3 ; - DUP 8 ; - GET 3 ; - COMPARE ; - EQ ; - DIG 5 ; - CAR ; - DUP 8 ; - CAR ; - COMPARE ; - EQ ; - AND ; - AND ; - AND ; - AND ; - OR } ; - AND ; - IF { PUSH nat 0 } - { PUSH bool False ; - DUP 7 ; - ITER { CDR ; - SWAP ; - DUP 2 ; - GET 8 ; - DUP 5 ; - GET 8 ; - COMPARE ; - EQ ; - DUP 3 ; - GET 7 ; - DUP 6 ; - GET 7 ; - COMPARE ; - EQ ; - DUP 4 ; - GET 5 ; - DUP 7 ; - GET 5 ; - COMPARE ; - EQ ; - DUP 5 ; - GET 3 ; - DUP 8 ; - GET 3 ; - COMPARE ; - EQ ; - DIG 5 ; - CAR ; - DUP 8 ; - CAR ; - COMPARE ; - EQ ; - AND ; - AND ; - AND ; - AND ; - OR } ; - PUSH bool False ; - DUP 8 ; - ITER { CDR ; - SWAP ; - DUP 2 ; - GET 8 ; - DUP 5 ; - GET 8 ; - COMPARE ; - EQ ; - DUP 3 ; - GET 7 ; - DUP 6 ; - GET 7 ; - COMPARE ; - EQ ; - DUP 4 ; - GET 5 ; - DUP 7 ; - GET 5 ; - COMPARE ; - EQ ; - DUP 5 ; - GET 3 ; - DUP 8 ; - GET 3 ; - COMPARE ; - EQ ; - DIG 5 ; - CAR ; - DUP 8 ; - CAR ; - COMPARE ; - EQ ; - AND ; - AND ; - AND ; - AND ; - OR } ; - OR ; - IF { PUSH nat 1 } { PUSH nat 2 } } ; - DIG 4 ; - SWAP ; - DUP 7 ; - SIZE ; - ADD ; - COMPARE ; - GT ; - IF { PUSH nat 126 ; FAILWITH } {} } ; - DUP 3 ; - CDR ; - GET 3 ; - DIG 3 ; - CAR ; - CAR ; - GET 3 ; - PAIR ; - DUP 4 ; - DUP 2 ; - CAR ; - DIG 2 ; - CDR ; - DUP 2 ; - DUP 2 ; - COMPARE ; - GT ; - IF { SWAP ; PUSH string "/" ; CONCAT ; SWAP ; CONCAT } - { PUSH string "/" ; CONCAT ; SWAP ; CONCAT } ; - GET ; - IF_NONE - { DUP 4 ; - DUP 3 ; - GET 3 ; - GET ; - IF_NONE - { DIG 3 ; DUP 3 ; DIG 3 ; GET 3 ; SWAP ; SOME ; SWAP ; UPDATE } - { DUP 3 ; - GET 8 ; - DUP 2 ; - GET 8 ; - COMPARE ; - EQ ; - DUP 4 ; - GET 7 ; - DUP 3 ; - GET 7 ; - COMPARE ; - EQ ; - DUP 5 ; - GET 5 ; - DUP 4 ; - GET 5 ; - COMPARE ; - EQ ; - DUP 6 ; - GET 3 ; - DUP 5 ; - GET 3 ; - COMPARE ; - EQ ; - DIG 6 ; - CAR ; - DIG 5 ; - CAR ; - COMPARE ; - EQ ; - AND ; - AND ; - AND ; - AND ; - IF { DIG 2 } { DIG 2 ; DROP ; PUSH nat 115 ; FAILWITH } } ; - DUP ; - DUP 3 ; - GET 3 ; - GET ; - IF_NONE - { DUP 2 ; DIG 2 ; GET 3 ; SWAP ; SOME ; SWAP ; UPDATE } - { DUP 3 ; - GET 8 ; - DUP 2 ; - GET 8 ; - COMPARE ; - EQ ; - DUP 4 ; - GET 7 ; - DUP 3 ; - GET 7 ; - COMPARE ; - EQ ; - DUP 5 ; - GET 5 ; - DUP 4 ; - GET 5 ; - COMPARE ; - EQ ; - DUP 6 ; - GET 3 ; - DUP 5 ; - GET 3 ; - COMPARE ; - EQ ; - DIG 6 ; - CAR ; - DIG 5 ; - CAR ; - COMPARE ; - EQ ; - AND ; - AND ; - AND ; - AND ; - IF {} { DROP ; PUSH nat 115 ; FAILWITH } } ; - DUP 3 ; - CAR ; - DUP ; - CDR ; - GET 3 ; - SWAP ; - CAR ; - CAR ; - GET 3 ; - PAIR ; - SWAP ; - DUP 2 ; - CAR ; - DIG 2 ; - CDR ; - DIG 3 ; - DUP 5 ; - GET 8 ; - DUP 6 ; - GET 7 ; - DUP 7 ; - GET 5 ; - DUP 8 ; - GET 3 ; - DIG 8 ; - CAR ; - DUP ; - CDR ; - GET 3 ; - SWAP ; - CAR ; - CAR ; - GET 3 ; - PAIR ; - PAIR 5 ; - DUP 4 ; - DUP 4 ; - COMPARE ; - GT ; - IF { DIG 3 ; PUSH string "/" ; CONCAT ; DIG 3 ; CONCAT } - { DIG 2 ; PUSH string "/" ; CONCAT ; DIG 3 ; CONCAT } ; - SWAP ; - SOME ; - SWAP ; - UPDATE ; - PAIR } - { DROP 6 ; PUSH nat 116 ; FAILWITH } ; - UNPAIR ; - DUP 3 ; - DIG 3 ; - CDR ; - DUP ; - CDR ; - GET 3 ; - SWAP ; - CAR ; - DUP ; - CDR ; - DIG 4 ; - UPDATE 2 ; - UPDATE 2 ; - UPDATE 1 ; - UPDATE 2 ; - DUP ; - CDR ; - DIG 2 ; - UPDATE 2 ; - UPDATE 2 ; - NIL operation ; - PAIR } } } } } - { IF_LEFT - { DIG 2 ; - DROP ; - DUP 2 ; - CAR ; - CAR ; - 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 ; - SIZE ; - DUP 2 ; - COMPARE ; - LT ; - IF { DROP 2 ; PUSH nat 128 ; FAILWITH } - { DUP 2 ; - CDR ; - CAR ; - CDR ; - CDR ; - SIZE ; - DUP 2 ; - COMPARE ; - LT ; - IF { DROP 2 ; PUSH nat 129 ; FAILWITH } - { DUP 2 ; - DIG 2 ; - CAR ; - DUP ; - CDR ; - DUP ; - CDR ; - DIG 4 ; - UPDATE 1 ; - UPDATE 2 ; - UPDATE 2 ; - UPDATE 1 ; - NIL operation ; - PAIR } } } - { PUSH mutez 1 ; - AMOUNT ; - COMPARE ; - LT ; - IF {} { PUSH nat 118 ; FAILWITH } ; - SENDER ; - DUP 2 ; - UNPAIR ; - DUP 5 ; - CDR ; - CAR ; - CDR ; - CDR ; - 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 - { DROP 4 ; PUSH nat 117 ; FAILWITH } - { DUP 4 ; - CDR ; - CDR ; - DUP 2 ; - CAR ; - DUP 2 ; - DUP 2 ; - CAR ; - GET ; - IF_NONE { PUSH nat 111 ; FAILWITH } {} ; - DUG 2 ; - CDR ; - GET ; - IF_NONE { PUSH nat 111 ; FAILWITH } {} ; - NOW ; - DUP 7 ; - CAR ; - CAR ; - CAR ; - CDR ; - DUP ; - CDR ; - DUP 2 ; - CAR ; - DUP 9 ; - UNPAIR ; - DUP ; - DUP 3 ; - COMPARE ; - GT ; - IF { PUSH string "/" ; CONCAT ; SWAP ; CONCAT } - { SWAP ; PUSH string "/" ; CONCAT ; SWAP ; CONCAT } ; - GET ; - IF_NONE { PUSH nat 0 } {} ; - GET ; - IF_NONE - { PUSH nat 0 ; - DUP 2 ; - CAR ; - ITER { CDR ; DUP 2 ; DUP 2 ; COMPARE ; GT ; IF { SWAP ; DROP } { DROP } } ; - PUSH nat 1 ; - ADD ; - PUSH bool False ; - PUSH nat 0 ; - DIG 9 ; - PUSH nat 0 ; - PUSH nat 0 ; - PUSH nat 0 ; - PUSH nat 0 ; - PUSH nat 0 ; - PUSH nat 0 ; - PUSH nat 0 ; - PUSH nat 0 ; - PAIR 8 ; - DIG 6 ; - RIGHT - (or (pair (pair timestamp - (pair (pair nat nat nat) - (or (or unit unit) unit) - (pair nat nat nat nat) - (pair (pair string string) (pair int int) timestamp))) - (pair (pair string string) (pair int int) timestamp)) - (pair timestamp timestamp)) ; - DIG 5 ; - PAIR 6 ; - DUP 7 ; - DUP 3 ; - DUP 4 ; - CDR ; - DUP 4 ; - SOME ; - DUP 5 ; - CAR ; - UPDATE ; - UPDATE 2 ; - DIG 3 ; - CAR ; - DUP 4 ; - CAR ; - SOME ; - DUP 5 ; - GET 7 ; - UNPAIR ; - DUP ; - DUP 3 ; - COMPARE ; - GT ; - IF { PUSH string "/" ; CONCAT ; SWAP ; CONCAT } - { SWAP ; PUSH string "/" ; CONCAT ; SWAP ; CONCAT } ; - UPDATE ; - UPDATE 1 } - { DUP 9 ; - CAR ; - CAR ; - CDR ; - CAR ; - DUP 2 ; - GET 3 ; - IF_LEFT - { SWAP ; - DROP ; - IF_LEFT - { DROP 2 ; - PUSH nat 0 ; - DUP 2 ; - CAR ; - ITER { CDR ; DUP 2 ; DUP 2 ; COMPARE ; GT ; IF { SWAP ; DROP } { DROP } } ; - PUSH nat 1 ; - ADD ; - PUSH bool False ; - PUSH nat 0 ; - DIG 9 ; - PUSH nat 0 ; - PUSH nat 0 ; - PUSH nat 0 ; - PUSH nat 0 ; - PUSH nat 0 ; - PUSH nat 0 ; - PUSH nat 0 ; - PUSH nat 0 ; - PAIR 8 ; - DIG 6 ; - RIGHT - (or (pair (pair timestamp - (pair (pair nat nat nat) - (or (or unit unit) unit) - (pair nat nat nat nat) - (pair (pair string string) (pair int int) timestamp))) - (pair (pair string string) (pair int int) timestamp)) - (pair timestamp timestamp)) ; - DIG 5 ; - PAIR 6 ; - DUP 7 ; - DUP 3 ; - DUP 4 ; - CDR ; - DUP 4 ; - SOME ; - DUP 5 ; - CAR ; - UPDATE ; - UPDATE 2 ; - DIG 3 ; - CAR ; - DUP 4 ; - CAR ; - SOME ; - DUP 5 ; - GET 7 ; - UNPAIR ; - DUP ; - DUP 3 ; - COMPARE ; - GT ; - IF { PUSH string "/" ; CONCAT ; SWAP ; CONCAT } - { SWAP ; PUSH string "/" ; CONCAT ; SWAP ; CONCAT } ; - UPDATE ; - UPDATE 1 } - { DIG 3 ; DIG 8 ; DROP 3 ; DUP 7 ; DIG 2 } } - { DIG 9 ; - DROP ; - DUP 2 ; - INT ; - ADD ; - DIG 4 ; - COMPARE ; - GE ; - IF { DUP 2 ; - GET 3 ; - IF_LEFT - { SWAP ; - DIG 2 ; - DROP 2 ; - IF_LEFT - { DROP ; PUSH nat 105 ; FAILWITH } - { DROP ; PUSH nat 105 ; FAILWITH } } - { SWAP ; - INT ; - DUP 2 ; - ADD ; - PAIR ; - RIGHT - (pair (pair timestamp - (pair (pair nat nat nat) - (or (or unit unit) unit) - (pair nat nat nat nat) - (pair (pair string string) (pair int int) timestamp))) - (pair (pair string string) (pair int int) timestamp)) ; - LEFT timestamp ; - UPDATE 3 ; - DUP 7 ; - PAIR } ; - UNPAIR ; - DUP 3 ; - DUP 4 ; - CDR ; - DUP 4 ; - SOME ; - DUP 5 ; - CAR ; - UPDATE ; - UPDATE 2 ; - DIG 3 ; - CAR ; - DUP 4 ; - CAR ; - SOME ; - DUP 5 ; - GET 7 ; - UNPAIR ; - DUP ; - DUP 3 ; - COMPARE ; - GT ; - IF { PUSH string "/" ; CONCAT ; SWAP ; CONCAT } - { SWAP ; PUSH string "/" ; CONCAT ; SWAP ; CONCAT } ; - UPDATE ; - UPDATE 1 } - { DROP ; DUP 7 ; DIG 2 } } } ; - DIG 2 ; - DUP ; - GET 3 ; - IF_LEFT - { IF_LEFT { DROP ; PUSH bool False } { DROP ; PUSH bool False } } - { DROP ; PUSH bool True } ; - NOT ; - IF { PUSH nat 140 ; FAILWITH } {} ; - DIG 7 ; - CDR ; - CAR ; - CDR ; - CAR ; - DUP 8 ; - GET ; - IF_NONE - { DROP 8 ; PUSH nat 139 ; FAILWITH } - { DUP 2 ; - CAR ; - DUP 2 ; - DUP 2 ; - GET ; - IF_NONE - { SWAP ; DIG 4 ; DROP 3 ; PUSH nat 139 ; FAILWITH } - { DUP 6 ; - DUP 7 ; - CDR ; - DUP ; - CAR ; - DUP ; - CDR ; - DIG 9 ; - CDR ; - CAR ; - CDR ; - CAR ; - DIG 7 ; - DIG 7 ; - NONE (map (pair (or unit unit) (or (or unit unit) unit)) nat) ; - SWAP ; - UPDATE ; - SOME ; - DUP 13 ; - UPDATE ; - UPDATE 1 ; - UPDATE 2 ; - UPDATE 1 ; - UPDATE 2 ; - SWAP ; - PAIR } ; - UNPAIR ; - DUP 3 ; - GET 5 ; - DUP 2 ; - ITER { UNPAIR ; - UNPAIR ; - IF_LEFT - { DROP ; - DUP 2 ; - DUP 4 ; - GET 7 ; - SUB ; - ABS ; - SWAP ; - IF_LEFT - { IF_LEFT - { DROP ; - DUP 3 ; - DIG 2 ; - DIG 3 ; - GET 3 ; - SUB ; - ABS ; - UPDATE 3 ; - SWAP ; - UPDATE 7 } - { DROP ; - DUP 3 ; - DIG 2 ; - DIG 3 ; - CAR ; - SUB ; - ABS ; - UPDATE 1 ; - SWAP ; - UPDATE 7 } } - { DROP ; - DUP 3 ; - DIG 2 ; - DIG 3 ; - GET 5 ; - SUB ; - ABS ; - UPDATE 5 ; - SWAP ; - UPDATE 7 } } - { DROP ; - DUP 2 ; - DUP 4 ; - GET 14 ; - SUB ; - ABS ; - SWAP ; - IF_LEFT - { IF_LEFT - { DROP ; - DUP 3 ; - DIG 2 ; - DIG 3 ; - GET 11 ; - SUB ; - ABS ; - UPDATE 11 ; - SWAP ; - UPDATE 14 } - { DROP ; - DUP 3 ; - DIG 2 ; - DIG 3 ; - GET 9 ; - SUB ; - ABS ; - UPDATE 9 ; - SWAP ; - UPDATE 14 } } - { DROP ; - DUP 3 ; - DIG 2 ; - DIG 3 ; - GET 13 ; - SUB ; - ABS ; - UPDATE 13 ; - SWAP ; - UPDATE 14 } } } ; - PUSH nat 1 ; - DUP 5 ; - GET 9 ; - SUB ; - ABS ; - DIG 4 ; - DIG 2 ; - UPDATE 5 ; - SWAP ; - UPDATE 9 ; - DUP 3 ; - DIG 3 ; - CAR ; - DUP ; - CAR ; - DUP ; - CAR ; - DUP 7 ; - DIG 7 ; - CDR ; - DUP 7 ; - SOME ; - DIG 7 ; - CAR ; - UPDATE ; - UPDATE 2 ; - UPDATE 2 ; - UPDATE 1 ; - UPDATE 1 ; - UPDATE 1 ; - DUP 5 ; - GET 8 ; - DUP 6 ; - GET 7 ; - DUP 7 ; - GET 5 ; - DIG 7 ; - GET 3 ; - DIG 6 ; - PUSH nat 1 ; - DIG 8 ; - PAIR ; - PAIR ; - PAIR 5 ; - PUSH mutez 0 ; - EMPTY_MAP string (pair (pair nat string (option address) nat (option string)) nat) ; - PAIR ; - DIG 3 ; - ITER { UNPAIR ; - DIG 2 ; - UNPAIR ; - DIG 3 ; - DIG 3 ; - CAR ; - IF_LEFT { DROP ; DUP 4 ; CAR ; CAR ; CAR } { DROP ; DUP 4 ; CAR ; CDR } ; - PAIR ; - PAIR ; - DUP 6 ; - SWAP ; - EXEC ; - DUP 4 ; - CAR ; - CAR ; - CDR ; - CDR ; - DIG 2 ; - ADD ; - SWAP ; - PAIR } ; - SWAP ; - DIG 4 ; - DROP 2 ; - UNPAIR ; - SELF_ADDRESS ; - NIL operation ; - DIG 2 ; - ITER { CDR ; - DUP ; - CAR ; - GET 5 ; - IF_NONE - { DROP ; PUSH nat 109 ; FAILWITH } - { DUP 2 ; - CAR ; - GET 8 ; - IF_NONE - { DROP 2 ; PUSH nat 108 ; FAILWITH } - { PUSH string "FA1.2 token" ; - DUP 2 ; - COMPARE ; - EQ ; - IF { DROP ; - CONTRACT %transfer (pair (address %from) (address %to) (nat %value)) ; - IF_NONE { PUSH nat 101 ; FAILWITH } {} ; - PUSH mutez 0 ; - DIG 2 ; - CDR ; - DUP 8 ; - DUP 6 ; - PAIR 3 ; - TRANSFER_TOKENS } - { PUSH string "FA2 token" ; - SWAP ; - COMPARE ; - EQ ; - IF { CONTRACT %transfer - (list (pair (address %from_) (list %tx (pair (address %to_) (nat %token_id) (nat %amount))))) ; - IF_NONE { PUSH nat 101 ; FAILWITH } {} ; - PUSH mutez 0 ; - NIL (pair address (list (pair address nat nat))) ; - NIL (pair address nat nat) ; DUP 5 ; - CDR ; - DIG 5 ; - CAR ; - CAR ; - DUP 11 ; - PAIR 3 ; - CONS ; - DUP 6 ; - PAIR ; - CONS ; - TRANSFER_TOKENS } - { DROP 2 ; PUSH nat 108 ; FAILWITH } } } } ; - CONS } ; - SWAP ; - DIG 4 ; - DROP 2 ; - PUSH mutez 0 ; - DUP 3 ; - COMPARE ; - GT ; - IF { DUP 3 ; - CAR ; - CDR ; - CAR ; - CAR ; - CONTRACT unit ; - IF_NONE - { SWAP ; DROP ; PUSH nat 102 ; FAILWITH } - { DIG 2 ; UNIT ; TRANSFER_TOKENS } ; - CONS } - { SWAP ; DROP } ; - PAIR } } } } } - { DIG 2 ; - DROP ; - IF_LEFT - { IF_LEFT - { DUP 2 ; - CAR ; - CAR ; - CAR ; - CAR ; - SENDER ; - COMPARE ; - EQ ; - IF {} { PUSH nat 114 ; FAILWITH } ; - PUSH mutez 1 ; - AMOUNT ; - COMPARE ; - LT ; - IF {} { PUSH nat 118 ; FAILWITH } ; - DUP 2 ; - CAR ; - CDR ; - CAR ; - CAR ; - DUP 2 ; - COMPARE ; - EQ ; - IF { PUSH nat 144 ; FAILWITH } {} ; - DUP 2 ; - DIG 2 ; - CAR ; - DUP ; - CAR ; - DUP ; - CAR ; - DIG 4 ; - UPDATE 1 ; - UPDATE 1 ; - UPDATE 1 ; - UPDATE 1 ; - NIL operation ; - PAIR } - { DUP 2 ; - CAR ; - CAR ; - CAR ; - CAR ; - SENDER ; - COMPARE ; - EQ ; - IF {} { PUSH nat 114 ; FAILWITH } ; - PUSH mutez 1 ; - AMOUNT ; - COMPARE ; - LT ; - IF {} { PUSH nat 118 ; FAILWITH } ; - PUSH nat 600 ; - DUP 2 ; - COMPARE ; - LT ; - IF { DROP 2 ; PUSH nat 131 ; FAILWITH } - { PUSH nat 3600 ; - DUP 2 ; - COMPARE ; - GT ; - IF { DROP 2 ; PUSH nat 132 ; FAILWITH } - { DUP 2 ; - DIG 2 ; - CAR ; - DUP ; - CAR ; - DUP ; - CDR ; - DIG 4 ; - UPDATE 1 ; - UPDATE 2 ; - UPDATE 1 ; - UPDATE 1 ; - NIL operation ; - PAIR } } } } - { IF_LEFT - { DUP 2 ; - CAR ; - CAR ; - 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 ; - DUP ; - CAR ; - DUP ; - CDR ; - DIG 4 ; - UPDATE 2 ; - UPDATE 2 ; - UPDATE 1 ; - UPDATE 1 } - { DUP 2 ; - CAR ; - CAR ; - CAR ; - CAR ; - SENDER ; - COMPARE ; - EQ ; - IF {} { PUSH nat 114 ; FAILWITH } ; - PUSH mutez 1 ; - AMOUNT ; - COMPARE ; - LT ; - IF {} { PUSH nat 118 ; FAILWITH } ; - DUP 2 ; - CAR ; - CAR ; - CAR ; - CAR ; - DUP 2 ; - COMPARE ; - EQ ; - IF { PUSH nat 144 ; FAILWITH } {} ; - DUP 2 ; - DIG 2 ; - CAR ; - DUP ; - CDR ; - DUP ; - CAR ; - DIG 4 ; - UPDATE 1 ; - UPDATE 1 ; - UPDATE 2 ; - UPDATE 1 } ; - NIL operation ; - PAIR } } } - { IF_LEFT - { DIG 2 ; - DIG 3 ; - DROP 2 ; - IF_LEFT - { IF_LEFT - { DUP 2 ; - CAR ; CAR ; - CAR ; - CAR ; - SENDER ; - COMPARE ; - EQ ; - IF {} { PUSH nat 114 ; FAILWITH } ; - PUSH mutez 1 ; - AMOUNT ; - COMPARE ; - LT ; - IF {} { PUSH nat 118 ; FAILWITH } ; - DUP 2 ; - CAR ; - CDR ; - CAR ; - CAR ; - DUP 2 ; - COMPARE ; - EQ ; - IF { PUSH nat 144 ; FAILWITH } {} ; - DUP 2 ; - DIG 2 ; - CAR ; - DUP ; CDR ; - DUP ; - CDR ; - DIG 4 ; - UPDATE 2 ; - UPDATE 2 ; - UPDATE 2 ; - UPDATE 1 } - { DUP 2 ; - CAR ; - CAR ; - CAR ; - CAR ; - SENDER ; - COMPARE ; - EQ ; - IF {} { PUSH nat 114 ; FAILWITH } ; - PUSH mutez 1 ; - AMOUNT ; - COMPARE ; - LT ; - IF {} { PUSH nat 118 ; FAILWITH } ; - DUP 2 ; - CDR ; - CAR ; - CDR ; - CDR ; - DUP 2 ; - CAR ; - GET ; - IF_NONE { PUSH nat 117 ; FAILWITH } {} ; - DUP ; - GET 3 ; - DUP 2 ; - GET 5 ; - VIEW "getPrice" (pair timestamp nat) ; - IF_NONE { PUSH nat 123 ; FAILWITH } { DROP } ; - DUP 3 ; - DUP 4 ; - CDR ; - DUP ; - CAR ; - DUP ; - CDR ; - DIG 6 ; - CDR ; - CAR ; - CDR ; - CDR ; - DIG 5 ; - DUP 7 ; - GET 3 ; - UPDATE 3 ; - DUP 7 ; - GET 5 ; - UPDATE 5 ; - DUP 7 ; - GET 6 ; - UPDATE 7 ; - SOME ; - DIG 6 ; - CAR ; - UPDATE ; - UPDATE 2 ; - UPDATE 2 ; - UPDATE 1 ; - UPDATE 2 } ; - NIL operation ; - PAIR } - { IF_LEFT - { DUP ; - GET 5 ; - PUSH nat 0 ; - DUP 2 ; - CDR ; - CAR ; - DIG 4 ; - DUP 3 ; - DUP 3 ; - COMPARE ; - EQ ; - IF { DROP ; UNIT ; LEFT unit } - { PUSH nat 1 ; - SWAP ; - COMPARE ; - EQ ; - IF { UNIT ; RIGHT unit } { PUSH nat 106 ; FAILWITH } } ; - DUP 2 ; - CAR ; - DUP ; - CDR ; - GET 3 ; - SWAP ; - CAR ; - CAR ; - GET 3 ; - PAIR ; - SWAP ; - IF_LEFT { DROP } { DROP ; DUP ; CAR ; SWAP ; CDR ; PAIR } ; - NOW ; - DUP 4 ; - CDR ; - CAR ; - CDR ; - CDR ; - DUP 3 ; - UNPAIR ; - DUP ; - DUP 3 ; - COMPARE ; - GT ; - IF { PUSH string "/" ; CONCAT ; SWAP ; CONCAT } - { SWAP ; PUSH string "/" ; CONCAT ; SWAP ; CONCAT } ; - GET ; - IF_NONE { PUSH nat 117 ; FAILWITH } {} ; - DUP ; - GET 8 ; - IF { DROP 5 ; PUSH nat 125 ; FAILWITH } - { DUP 4 ; - CAR ; - DUP 5 ; - GET 5 ; - PUSH nat 0 ; - DUP 2 ; - COMPARE ; - EQ ; - IF { DROP ; UNIT ; LEFT unit } - { PUSH nat 1 ; - SWAP ; - COMPARE ; - EQ ; - IF { UNIT ; RIGHT unit } { PUSH nat 106 ; FAILWITH } } ; - IF_LEFT - { DROP ; - SWAP ; - CAR ; - CAR ; - SWAP ; CAR ; - CAR ; GET 3 ; - COMPARE ; - EQ ; - IF {} { PUSH nat 156 ; FAILWITH } } - { DROP ; - SWAP ; - CAR ; - CDR ; - SWAP ; - CAR ; - CAR ; - GET 3 ; - COMPARE ; - EQ ; - IF {} { PUSH nat 156 ; FAILWITH } } ; DUP 4 ; - CAR ; - CAR ; - CDR ; - CDR ; - AMOUNT ; - DUP 2 ; - DUP 2 ; - COMPARE ; - LT ; - IF { DROP 6 ; PUSH nat 113 ; FAILWITH } - { COMPARE ; - GT ; - IF { DROP 4 ; PUSH nat 130 ; FAILWITH } - { DUP 4 ; - CAR ; - CAR ; - CAR ; - CDR ; - DUP ; - CDR ; - DUP 2 ; - CAR ; - DUP 5 ; - UNPAIR ; - DUP ; - DUP 3 ; - COMPARE ; - GT ; - IF { PUSH string "/" ; CONCAT ; SWAP ; CONCAT } - { SWAP ; PUSH string "/" ; CONCAT ; SWAP ; CONCAT } ; - GET ; - IF_NONE { PUSH nat 0 } {} ; - GET ; - IF_NONE - { PUSH nat 0 ; - DUP 2 ; - CAR ; - ITER { CDR ; DUP 2 ; DUP 2 ; COMPARE ; GT ; IF { SWAP ; DROP } { DROP } } ; - PUSH nat 1 ; - ADD ; - PUSH bool False ; - PUSH nat 0 ; - DUP 6 ; - PUSH nat 0 ; - PUSH nat 0 ; - PUSH nat 0 ; - PUSH nat 0 ; - PUSH nat 0 ; - PUSH nat 0 ; - PUSH nat 0 ; - PUSH nat 0 ; - PAIR 8 ; - DIG 6 ; - RIGHT - (or (pair (pair timestamp - (pair (pair nat nat nat) - (or (or unit unit) unit) - (pair nat nat nat nat) - (pair (pair string string) (pair int int) timestamp))) - (pair (pair string string) (pair int int) timestamp)) - (pair timestamp timestamp)) ; - DIG 5 ; - PAIR 6 ; - DIG 4 ; - DUP 3 ; - DUP 4 ; - CDR ; - DUP 4 ; - SOME ; - DUP 5 ; - CAR ; - UPDATE ; - UPDATE 2 ; - DIG 3 ; - CAR ; - DUP 4 ; - CAR ; - SOME ; - DUP 5 ; - GET 7 ; - UNPAIR ; - DUP ; - DUP 3 ; - COMPARE ; - GT ; - IF { PUSH string "/" ; CONCAT ; SWAP ; CONCAT } - { SWAP ; PUSH string "/" ; CONCAT ; SWAP ; CONCAT } ; - UPDATE ; - UPDATE 1 } - { DUP 6 ; - CAR ; - CAR ; - CDR ; - CAR ; - DUP 2 ; - GET 3 ; - IF_LEFT - { SWAP ; - DROP ; - IF_LEFT - { DROP 2 ; - PUSH nat 0 ; - DUP 2 ; - CAR ; - ITER { CDR ; DUP 2 ; DUP 2 ; COMPARE ; GT ; IF { SWAP ; DROP } { DROP } } ; - PUSH nat 1 ; - ADD ; - PUSH bool False ; - PUSH nat 0 ; - DUP 6 ; - PUSH nat 0 ; - PUSH nat 0 ; - PUSH nat 0 ; - PUSH nat 0 ; - PUSH nat 0 ; - PUSH nat 0 ; - PUSH nat 0 ; - PUSH nat 0 ; - PAIR 8 ; - DIG 6 ; - RIGHT - (or (pair (pair timestamp - (pair (pair nat nat nat) - (or (or unit unit) unit) - (pair nat nat nat nat) - (pair (pair string string) (pair int int) timestamp))) - (pair (pair string string) (pair int int) timestamp)) - (pair timestamp timestamp)) ; - DIG 5 ; - PAIR 6 ; - DIG 4 ; - DUP 3 ; - DUP 4 ; - CDR ; - DUP 4 ; - SOME ; - DUP 5 ; - CAR ; - UPDATE ; - UPDATE 2 ; - DIG 3 ; - CAR ; - DUP 4 ; - CAR ; - SOME ; - DUP 5 ; - GET 7 ; - UNPAIR ; - DUP ; - DUP 3 ; - COMPARE ; - GT ; - IF { PUSH string "/" ; CONCAT ; SWAP ; CONCAT } - { SWAP ; PUSH string "/" ; CONCAT ; SWAP ; CONCAT } ; - UPDATE ; - UPDATE 1 } - { DIG 3 ; DROP 2 ; DIG 4 ; DIG 2 } } - { DUP 2 ; - INT ; - ADD ; - DIG 4 ; - COMPARE ; - GE ; - IF { DUP 2 ; - GET 3 ; - IF_LEFT - { SWAP ; - DIG 2 ; - DIG 6 ; - DROP 3 ; - IF_LEFT - { DROP ; PUSH nat 105 ; FAILWITH } - { DROP ; PUSH nat 105 ; FAILWITH } } - { SWAP ; - INT ; - DUP 2 ; - ADD ; - PAIR ; - RIGHT - (pair (pair timestamp - (pair (pair nat nat nat) - (or (or unit unit) unit) - (pair nat nat nat nat) - (pair (pair string string) (pair int int) timestamp))) - (pair (pair string string) (pair int int) timestamp)) ; - LEFT timestamp ; - UPDATE 3 ; - DIG 4 ; - PAIR } ; - UNPAIR ; - DUP 3 ; - DUP 4 ; - CDR ; - DUP 4 ; - SOME ; - DUP 5 ; - CAR ; - UPDATE ; - UPDATE 2 ; - DIG 3 ; - CAR ; - DUP 4 ; - CAR ; - SOME ; - DUP 5 ; - GET 7 ; - UNPAIR ; - DUP ; - DUP 3 ; - COMPARE ; - GT ; - IF { PUSH string "/" ; CONCAT ; SWAP ; CONCAT } - { SWAP ; PUSH string "/" ; CONCAT ; SWAP ; CONCAT } ; - UPDATE ; - UPDATE 1 } - { DROP ; DIG 4 ; DIG 2 } } } ; - DIG 2 ; - DUP ; - GET 3 ; - IF_LEFT - { IF_LEFT { DROP ; PUSH bool False } { DROP ; PUSH bool False } } - { DROP ; PUSH bool True } ; - IF { DUP ; - GET 3 ; - IF_LEFT - { IF_LEFT { DROP ; PUSH bool False } { DROP ; PUSH bool False } } - { DROP ; PUSH bool True } ; - IF { DIG 3 ; DROP } - { DUP 3 ; - CDR ; - CAR ; - CDR ; - CDR ; - DIG 4 ; - UNPAIR ; - DUP ; - DUP 3 ; - COMPARE ; - GT ; - IF { PUSH string "/" ; CONCAT ; SWAP ; CONCAT } - { SWAP ; PUSH string "/" ; CONCAT ; SWAP ; CONCAT } ; - GET ; - IF_NONE { PUSH nat 117 ; FAILWITH } {} ; - DUP ; - GET 3 ; - SWAP ; - GET 5 ; - VIEW "getPrice" (pair timestamp nat) ; - IF_NONE { PUSH nat 124 ; FAILWITH } {} ; - CAR ; - DUP 4 ; - CAR ; - CAR ; - CDR ; - CAR ; - INT ; - NOW ; - SUB ; - COMPARE ; - LT ; - IF {} { PUSH nat 120 ; FAILWITH } } ; - DUP 3 ; - DIG 3 ; - CAR ; - DUP ; - CAR ; - DUP ; - CAR ; - DUP 6 ; - UPDATE 2 ; - UPDATE 1 ; - UPDATE 1 ; - UPDATE 1 ; - DUP 2 ; - CAR ; - SENDER ; - PUSH nat 1 ; - DUP 4 ; - CAR ; - CDR ; - CAR ; - CDR ; - ADD ; - DUP 7 ; - GET 5 ; - PUSH nat 0 ; - DUP 2 ; - COMPARE ; - EQ ; - IF { DROP ; UNIT ; LEFT unit } - { PUSH nat 1 ; - SWAP ; - COMPARE ; - EQ ; - IF { UNIT ; RIGHT unit } { PUSH nat 106 ; FAILWITH } } ; - DUP 8 ; - GET 6 ; - PUSH nat 0 ; - DUP 2 ; - COMPARE ; - EQ ; - IF { DROP ; UNIT ; RIGHT unit ; LEFT unit } - { PUSH nat 1 ; - DUP 2 ; - COMPARE ; - EQ ; - IF { DROP ; UNIT ; LEFT unit ; LEFT unit } - { PUSH nat 2 ; - SWAP ; - COMPARE ; - EQ ; - IF { UNIT ; RIGHT (or unit unit) } { PUSH nat 107 ; FAILWITH } } } ; - SENDER ; - DUP 7 ; - CDR ; - CDR ; - DUP 11 ; - CAR ; - DUP ; - CAR ; - CAR ; - DUP 2 ; - CDR ; - DUP 4 ; - DUP 3 ; - GET 3 ; - GET ; - IF_NONE - { DROP 4 ; PUSH nat 110 ; FAILWITH } - { DIG 4 ; - DUP 3 ; - GET 3 ; - GET ; - IF_NONE - { DROP 4 ; PUSH nat 110 ; FAILWITH } - { DUP ; - GET 8 ; - DUP 4 ; - GET 8 ; - COMPARE ; - EQ ; - DUP 2 ; - GET 7 ; - DUP 5 ; - GET 7 ; - COMPARE ; - EQ ; - DUP 3 ; - GET 5 ; - DUP 6 ; - GET 5 ; - COMPARE ; - EQ ; - DUP 4 ; - GET 3 ; - DUP 7 ; - GET 3 ; - COMPARE ; - EQ ; - DIG 4 ; - CAR ; - DIG 6 ; - CAR ; - COMPARE ; - EQ ; - AND ; - AND ; - AND ; - AND ; - DUP 2 ; - GET 8 ; - DUP 4 ; - GET 8 ; - COMPARE ; - EQ ; - DUP 3 ; - GET 7 ; - DUP 5 ; - GET 7 ; - COMPARE ; - EQ ; - DUP 4 ; - GET 5 ; - DUP 6 ; - GET 5 ; - COMPARE ; - EQ ; - DUP 5 ; - GET 3 ; - DUP 7 ; - GET 3 ; - COMPARE ; - EQ ; - DIG 5 ; - CAR ; - DIG 6 ; - CAR ; - COMPARE ; - EQ ; - AND ; - AND ; - AND ; - AND ; - AND ; - IF { DUP ; - CDR ; - GET 3 ; - SWAP ; - CAR ; - CAR ; - GET 3 ; - PAIR ; - DUP 8 ; - CDR ; - CAR ; - CDR ; - CDR ; - DUP 5 ; - IF_LEFT { DROP ; SWAP } { DROP ; DUP 2 ; CAR ; DIG 2 ; CDR ; PAIR } ; - UNPAIR ; - DUP ; - DUP 3 ; - COMPARE ; - GT ; - IF { PUSH string "/" ; CONCAT ; SWAP ; CONCAT } - { SWAP ; PUSH string "/" ; CONCAT ; SWAP ; CONCAT } ; - MEM ; - IF {} { PUSH nat 110 ; FAILWITH } } - { DROP ; PUSH nat 110 ; FAILWITH } } } ; - PUSH bool False ; - DIG 2 ; - DIG 3 ; - DIG 10 ; - CAR ; - DIG 4 ; - DUP 8 ; - DUP 7 ; - PAIR 7 ; - DUP 5 ; - CDR ; - CAR ; - CDR ; - CAR ; - DUP 2 ; - GET 5 ; - GET ; - IF_NONE - { PUSH bool True } - { PUSH nat 0 ; - SWAP ; - ITER { CDR ; SIZE ; ADD } ; - PUSH nat 10 ; - SWAP ; - COMPARE ; - LE } ; - IF { DUP 5 ; - CAR ; - CDR ; - CDR ; - CDR ; - DIG 3 ; - COMPARE ; - EQ ; - IF { DIG 4 ; PUSH bool True ; UPDATE 10 } { DIG 4 } ; - DUP ; - GET 5 ; - DUP 3 ; - GET 9 ; - IF_LEFT - { DROP ; - DUP 3 ; - GET 7 ; - CAR ; - CDR ; - DUP 2 ; - GET 7 ; - ADD ; - DUP 4 ; - GET 11 ; - IF_LEFT - { IF_LEFT - { DROP ; - DUP 2 ; - DUP 5 ; - GET 7 ; - CAR ; - CDR ; - DIG 3 ; - GET 3 ; - ADD ; - UPDATE 3 ; - SWAP ; - UPDATE 7 } - { DROP ; - DUP 2 ; - DUP 5 ; - GET 7 ; - CAR ; - CDR ; - DIG 3 ; - CAR ; - ADD ; - UPDATE 1 ; - SWAP ; - UPDATE 7 } } - { DROP ; - DUP 2 ; - DUP 5 ; - GET 7 ; - CAR ; - CDR ; - DIG 3 ; - GET 5 ; - ADD ; - UPDATE 5 ; - SWAP ; - UPDATE 7 } } - { DROP ; - DUP 3 ; - GET 7 ; - CAR ; - CDR ; - DUP 2 ; - GET 14 ; - ADD ; - DUP 4 ; - GET 11 ; - IF_LEFT - { IF_LEFT - { DROP ; - DUP 2 ; - DUP 5 ; - GET 7 ; - CAR ; - CDR ; - DIG 3 ; - GET 11 ; - ADD ; - UPDATE 11 ; - SWAP ; - UPDATE 14 } - { DROP ; - DUP 2 ; - DUP 5 ; - GET 7 ; - CAR ; - CDR ; - DIG 3 ; - GET 9 ; - ADD ; - UPDATE 9 ; - SWAP ; - UPDATE 14 } } - { DROP ; - DUP 2 ; - DUP 5 ; - GET 7 ; - CAR ; - CDR ; - DIG 3 ; - GET 13 ; - ADD ; - UPDATE 13 ; - SWAP ; - UPDATE 14 } } ; - DUP 7 ; - CDR ; - DUG 2 ; - UPDATE 5 ; - SOME ; - DUP 5 ; - UPDATE ; - DUP 5 ; - CDR ; - CAR ; - CDR ; - CAR ; - DUP 3 ; - GET 5 ; - GET ; - IF_NONE - { DUP ; - DUP 5 ; - GET ; - IF_NONE - { DROP ; PUSH nat 142 ; FAILWITH } - { PUSH nat 1 ; DUP 2 ; GET 9 ; ADD ; UPDATE 9 ; SOME ; DUP 5 ; UPDATE } } - { DUP 5 ; - GET ; - IF_NONE - { DUP ; - DUP 5 ; - GET ; - IF_NONE - { DROP ; PUSH nat 142 ; FAILWITH } - { PUSH nat 1 ; DUP 2 ; GET 9 ; ADD ; UPDATE 9 ; SOME ; DUP 5 ; UPDATE } } - { DROP } } ; - DUP 5 ; - CDR ; - CAR ; - CDR ; - CAR ; - DUP 3 ; - GET 5 ; - DUP 2 ; - DUP 2 ; - GET ; - IF_NONE - { SWAP ; - EMPTY_MAP nat (map (pair (or unit unit) (or (or unit unit) unit)) nat) ; - EMPTY_MAP (pair (or unit unit) (or (or unit unit) unit)) nat ; - DUP 6 ; - GET 7 ; - CAR ; - CDR ; - DUP 7 ; - GET 11 ; - DUP 8 ; - GET 9 ; - PAIR ; - SWAP ; - SOME ; - SWAP ; - UPDATE ; - DIG 7 ; - SWAP ; - SOME ; - SWAP ; - UPDATE ; - DIG 2 ; - SWAP ; - SOME ; - SWAP ; - UPDATE } - { DUP ; - DUP 8 ; - GET ; - IF_NONE - { EMPTY_MAP (pair (or unit unit) (or (or unit unit) unit)) nat ; - DUP 6 ; - GET 7 ; - CAR ; - CDR ; - DUP 7 ; - GET 11 ; - DUP 8 ; - GET 9 ; - PAIR ; - SWAP ; - SOME ; - SWAP ; - UPDATE ; - DIG 7 ; - SWAP ; - SOME ; - SWAP ; - UPDATE } - { DUP 6 ; - GET 11 ; - DUP 7 ; - GET 9 ; - PAIR ; - DUP 2 ; - DUP 2 ; - GET ; - IF_NONE - { SWAP ; DUP 7 ; GET 7 ; CAR ; CDR ; DIG 2 ; SWAP ; SOME ; SWAP ; UPDATE } - { DUP 8 ; GET 7 ; CAR ; CDR ; ADD ; DIG 2 ; SWAP ; SOME ; DIG 2 ; UPDATE } ; - SOME ; - DIG 7 ; - UPDATE } ; - DIG 2 ; - SWAP ; - SOME ; - DIG 2 ; - UPDATE } ; - DUP 5 ; - DIG 5 ; - CAR ; - DUP ; - CAR ; - DUP ; - CAR ; - DIG 8 ; - DIG 6 ; - UPDATE 2 ; - UPDATE 2 ; - UPDATE 1 ; - UPDATE 1 ; - UPDATE 1 ; - DUP ; - CAR ; - DUP ; - CDR ; - DUP ; - CAR ; - DIG 6 ; - UPDATE 2 ; - UPDATE 1 ; - UPDATE 2 ; - UPDATE 1 ; - DUP 3 ; - GET 7 ; - CAR ; - SELF_ADDRESS ; - DUP 2 ; - CAR ; - GET 5 ; - IF_NONE - { SWAP ; DIG 4 ; DROP 3 ; PUSH nat 109 ; FAILWITH } - { DIG 5 ; - GET 5 ; - DUP 4 ; - CAR ; - GET 8 ; - IF_NONE - { DROP 4 ; PUSH nat 108 ; FAILWITH } - { PUSH string "FA1.2 token" ; - DUP 2 ; - COMPARE ; - EQ ; - IF { DROP ; - SWAP ; - CONTRACT %transfer (pair (address %from) (address %to) (nat %value)) ; - IF_NONE { PUSH nat 101 ; FAILWITH } {} ; - PUSH mutez 0 ; - DIG 4 ; - CDR ; - DIG 4 ; - DIG 4 ; - PAIR 3 ; - TRANSFER_TOKENS } - { PUSH string "FA2 token" ; - SWAP ; - COMPARE ; - EQ ; - IF { SWAP ; - CONTRACT %transfer - (list (pair (address %from_) (list %tx (pair (address %to_) (nat %token_id) (nat %amount))))) ; - IF_NONE { PUSH nat 101 ; FAILWITH } {} ; - PUSH mutez 0 ; - NIL (pair address (list (pair address nat nat))) ; - NIL (pair address nat nat) ; - DUP 7 ; - CDR ; - DIG 7 ; - CAR ; - CAR ; - DIG 7 ; - PAIR 3 ; - CONS ; - DIG 4 ; - PAIR ; - CONS ; - TRANSFER_TOKENS } - { DROP 4 ; PUSH nat 108 ; FAILWITH } } } } ; - DUP 2 ; - DIG 2 ; - CDR ; - DUP ; - CAR ; - DUP ; - CDR ; - DIG 5 ; - UPDATE 1 ; - UPDATE 2 ; - UPDATE 1 ; - UPDATE 2 ; - NIL operation ; - DIG 2 ; - CONS ; - PAIR } - { DROP 7 ; PUSH nat 112 ; FAILWITH } } - { DROP 5 ; PUSH nat 103 ; FAILWITH } } } } } - { DUP 2 ; - CAR ; - CAR ; - CAR ; - CAR ; - SENDER ; - COMPARE ; - EQ ; - IF {} { PUSH nat 114 ; FAILWITH } ; - PUSH mutez 1 ; - AMOUNT ; - COMPARE ; - LT ; - IF {} { PUSH nat 118 ; FAILWITH } ; - DUP 2 ; - CDR ; - CAR ; - CDR ; - CDR ; - DUP 2 ; - GET ; - IF_NONE { PUSH nat 117 ; FAILWITH } {} ; - DUP 3 ; - DUP 4 ; - CDR ; - DUP ; - CAR ; - DUP ; - CDR ; - DIG 6 ; - CDR ; - CAR ; - CDR ; - CDR ; - DIG 5 ; - PUSH bool True ; - UPDATE 8 ; - SOME ; - DIG 6 ; - UPDATE ; - UPDATE 2 ; - UPDATE 2 ; - UPDATE 1 ; - UPDATE 2 ; - NIL operation ; - PAIR } } } - { IF_LEFT - { IF_LEFT - { DIG 2 ; - DIG 3 ; - DROP 2 ; - DUP 2 ; - CAR ; - CAR ; - CAR ; - CAR ; - SENDER ; - COMPARE ; - EQ ; - IF {} { PUSH nat 114 ; FAILWITH } ; - PUSH mutez 1 ; - AMOUNT ; - COMPARE ; - LT ; - IF {} { PUSH nat 118 ; FAILWITH } ; - DUP 2 ; - CDR ; - CAR ; - CDR ; - CDR ; - DUP 2 ; - GET ; - IF_NONE { PUSH nat 117 ; FAILWITH } {} ; - DUP 3 ; - DUP 4 ; - CDR ; - DUP ; - CAR ; - DUP ; - CDR ; - DIG 6 ; - CDR ; - CAR ; - CDR ; - CDR ; - DIG 5 ; - PUSH bool False ; - UPDATE 8 ; - SOME ; - DIG 6 ; - UPDATE ; - UPDATE 2 ; - UPDATE 2 ; - UPDATE 1 ; - UPDATE 2 ; - NIL operation } - { DROP ; - SENDER ; - PUSH mutez 1 ; - AMOUNT ; - COMPARE ; - LT ; - IF {} { PUSH nat 118 ; FAILWITH } ; - SELF_ADDRESS ; - PUSH mutez 0 ; - PUSH mutez 0 ; - PAIR ; - PUSH mutez 0 ; - DUP 5 ; - CAR ; - CDR ; - CAR ; - CAR ; - PAIR ; - DUP 4 ; - DUP 6 ; - CAR ; - CDR ; - CDR ; - CDR ; - PAIR ; - PAIR ; - PAIR ; - DUP 4 ; - CAR ; - CAR ; - CDR ; - CDR ; - DUP 5 ; - CAR ; - CAR ; - CAR ; - CDR ; - DUP 6 ; - CDR ; - CAR ; - CDR ; - CAR ; - DUP 7 ; - CDR ; - CDR ; - EMPTY_MAP string (pair (pair nat string (option address) nat (option string)) nat) ; - DUP 3 ; - DUP 9 ; - GET ; - IF_NONE - { SWAP ; DIG 4 ; DIG 9 ; DIG 10 ; DROP 4 ; DIG 2 ; PAIR ; SWAP } - { NONE nat ; - IF_NONE - { DIG 5 ; - DIG 6 ; - PAIR ; - DIG 3 ; - DIG 5 ; - PAIR ; - DIG 3 ; - DUP 4 ; - PAIR ; - PAIR ; - PAIR ; - SWAP ; - ITER { UNPAIR ; - DIG 2 ; - UNPAIR ; - UNPAIR ; - UNPAIR ; - DIG 2 ; - UNPAIR ; - DIG 4 ; - UNPAIR ; - DUP 3 ; - CDR ; - DUP ; - DUP 9 ; - GET ; - IF_NONE - { DIG 7 ; DIG 8 ; DROP 3 ; PAIR ; DUG 2 ; PAIR ; DIG 3 ; DIG 3 } - { DUP ; - GET 3 ; - IF_LEFT - { IF_LEFT - { CAR ; CDR ; SOME } - { DROP ; - NONE (pair (pair nat nat nat) - (or (or unit unit) unit) - (pair nat nat nat nat) - (pair (pair string string) (pair int int) timestamp)) } } - { DROP ; - NONE (pair (pair nat nat nat) - (or (or unit unit) unit) - (pair nat nat nat nat) - (pair (pair string string) (pair int int) timestamp)) } ; - IF_NONE - { SWAP ; DIG 8 ; DIG 9 ; DROP 4 ; PAIR ; DUG 2 ; PAIR ; DIG 3 ; DIG 3 } - { DUP 2 ; - GET 10 ; - DUP 6 ; - DIG 5 ; - PAIR ; - PAIR ; - DUP 7 ; - DUP 4 ; - GET 5 ; - PAIR ; - DIG 9 ; - DIG 3 ; - PAIR ; - PAIR ; - PAIR ; - DIG 8 ; - ITER { UNPAIR ; - DIG 2 ; - UNPAIR ; - UNPAIR ; - UNPAIR ; - DIG 2 ; - UNPAIR ; - DIG 4 ; - UNPAIR ; - UNPAIR ; - PUSH nat 0 ; - DUP 5 ; - GET 7 ; - COMPARE ; - EQ ; - IF { PUSH bool False } - { PUSH nat 0 ; - DUP 5 ; - GET 14 ; - COMPARE ; - EQ ; - IF { PUSH bool False } - { DUP 8 ; - CDR ; - DUP 7 ; - GET 3 ; - DUP 10 ; - CAR ; - IF_LEFT - { DROP ; - SWAP ; - IF_LEFT - { IF_LEFT - { DROP ; - IF_LEFT - { IF_LEFT { DROP ; PUSH bool True } { DROP ; PUSH bool False } } - { DROP ; PUSH bool True } } - { DROP ; - IF_LEFT - { IF_LEFT { DROP ; PUSH bool True } { DROP ; PUSH bool True } } - { DROP ; PUSH bool True } } } - { DROP ; - IF_LEFT - { IF_LEFT { DROP ; PUSH bool False } { DROP ; PUSH bool False } } - { DROP ; PUSH bool True } } } - { DROP ; - SWAP ; - IF_LEFT - { IF_LEFT - { DROP ; - IF_LEFT - { IF_LEFT { DROP ; PUSH bool True } { DROP ; PUSH bool True } } - { DROP ; PUSH bool False } } - { DROP ; - IF_LEFT - { IF_LEFT { DROP ; PUSH bool False } { DROP ; PUSH bool True } } - { DROP ; PUSH bool False } } } - { DROP ; - IF_LEFT - { IF_LEFT { DROP ; PUSH bool True } { DROP ; PUSH bool True } } - { DROP ; PUSH bool True } } } } } ; - IF { DUP 6 ; - GET 6 ; - CAR ; - DUP 6 ; - DUP 2 ; - CAR ; - GET ; - IF_NONE { PUSH nat 111 ; FAILWITH } {} ; - DUP 7 ; - DIG 2 ; - CDR ; - GET ; - IF_NONE { PUSH nat 111 ; FAILWITH } {} ; - DIG 9 ; - CAR ; - IF_LEFT - { DROP ; - DUP 8 ; - GET 5 ; - DUP ; - GET 5 ; - INT ; - SWAP ; - GET 3 ; - INT ; - DIG 11 ; - INT ; - PUSH int 1 ; - SWAP ; - PAIR ; - PUSH int 1 ; - DIG 2 ; - PAIR ; - DUP ; - CAR ; - DUP 3 ; - CDR ; - MUL ; - SWAP ; - CDR ; - DUP 3 ; - CAR ; - MUL ; - PAIR ; - PUSH int 1 ; - DIG 3 ; - PAIR ; - DUP ; - CDR ; - DUP 3 ; - CDR ; - MUL ; - SWAP ; - CAR ; - DIG 2 ; - CAR ; - MUL ; - PAIR ; - DUP 10 ; - GET 6 ; - GET 3 ; - DUP ; - CAR ; - DUP 3 ; - CDR ; - MUL ; - SWAP ; - CDR ; - DUP 3 ; - CAR ; - MUL ; - PAIR ; - DUP ; - CDR ; - DUP 4 ; - CDR ; - MUL ; - DUP 4 ; - CDR ; - DUP 3 ; - CAR ; - MUL ; - DIG 2 ; - CDR ; - DIG 4 ; - CAR ; - MUL ; - SUB ; - PAIR ; - PUSH int 0 ; - DUP 3 ; - CAR ; - COMPARE ; - LT ; - IF { PUSH int -1 ; DUP 3 ; CDR ; MUL ; PUSH int -1 ; DIG 3 ; CAR ; MUL ; PAIR } - { SWAP } ; - DUP ; - CDR ; - PUSH nat 0 ; - PUSH nat 10 ; - PAIR ; - DUP 26 ; - SWAP ; - EXEC ; - DIG 2 ; - CAR ; - MUL ; - EDIV ; - IF_NONE { PUSH string "DIV by 0" ; FAILWITH } {} ; - CAR ; - ISNAT ; - IF_NONE { PUSH nat 119 ; FAILWITH } {} ; - DIG 2 ; - PAIR ; - PUSH nat 0 ; - DUP 2 ; - CDR ; - COMPARE ; - GT ; - IF { DIG 9 ; SWAP ; PAIR ; DUP 21 ; SWAP ; EXEC } { DROP ; DIG 8 } ; - PUSH int 1 ; - PUSH int 0 ; - PAIR ; - DUP ; - CAR ; - DUP 4 ; - CDR ; - MUL ; - SWAP ; - CDR ; - DUP 4 ; - CAR ; - MUL ; - COMPARE ; - LE ; - NOT ; - IF { PUSH int 0 ; - DUP 3 ; - CAR ; - COMPARE ; - LT ; - IF { PUSH int -1 ; DUP 3 ; CDR ; MUL ; PUSH int -1 ; DIG 3 ; CAR ; MUL ; PAIR } - { SWAP } ; - DUP ; - CDR ; - PUSH nat 0 ; - PUSH nat 10 ; - PAIR ; - DUP 24 ; - SWAP ; - EXEC ; - DIG 2 ; - CAR ; - MUL ; - EDIV ; - IF_NONE { PUSH string "DIV by 0" ; FAILWITH } {} ; - CAR ; - ISNAT ; - IF_NONE { PUSH nat 119 ; FAILWITH } {} ; - DIG 2 ; - PAIR ; - PAIR ; - DUP 19 ; - SWAP ; - EXEC } - { SWAP ; DIG 2 ; DROP 2 } } - { DROP ; - DUP 8 ; - GET 5 ; - DUP ; - CAR ; - INT ; - SWAP ; - GET 6 ; - INT ; - DIG 11 ; - INT ; - PUSH int 1 ; - SWAP ; - PAIR ; - PUSH int 1 ; - DIG 2 ; - PAIR ; - DUP ; - CAR ; - DUP 3 ; - CDR ; - MUL ; - SWAP ; - CDR ; - DUP 3 ; - CAR ; - MUL ; - PAIR ; - PUSH int 1 ; - DIG 3 ; - PAIR ; - DUP ; - CDR ; - DUP 3 ; - CDR ; - MUL ; - SWAP ; - CAR ; - DIG 2 ; - CAR ; - MUL ; - PAIR ; - DUP 10 ; - GET 6 ; - GET 3 ; - DUP ; - CDR ; - DUP 3 ; - CDR ; - MUL ; - SWAP ; - CAR ; - DUP 3 ; - CAR ; - MUL ; - PAIR ; - DUP ; - CDR ; - DUP 4 ; - CDR ; - MUL ; - DUP 4 ; - CDR ; - DUP 3 ; - CAR ; - MUL ; - DIG 2 ; - CDR ; - DIG 4 ; - CAR ; - MUL ; - SUB ; - PAIR ; - PUSH int 0 ; - DUP 3 ; - CAR ; - COMPARE ; - LT ; - IF { PUSH int -1 ; DUP 3 ; CDR ; MUL ; PUSH int -1 ; DIG 3 ; CAR ; MUL ; PAIR } - { SWAP } ; - DUP ; - CDR ; - PUSH nat 0 ; - PUSH nat 10 ; - PAIR ; - DUP 26 ; - SWAP ; - EXEC ; - DIG 2 ; - CAR ; - MUL ; - EDIV ; - IF_NONE { PUSH string "DIV by 0" ; FAILWITH } {} ; - CAR ; - ISNAT ; - IF_NONE { PUSH nat 119 ; FAILWITH } {} ; - DIG 3 ; - PAIR ; - PUSH nat 0 ; - DUP 2 ; - CDR ; - COMPARE ; - GT ; - IF { DIG 9 ; SWAP ; PAIR ; DUP 21 ; SWAP ; EXEC } { DROP ; DIG 8 } ; - PUSH int 1 ; - PUSH int 0 ; - PAIR ; - DUP ; - CAR ; - DUP 4 ; - CDR ; - MUL ; - SWAP ; - CDR ; - DUP 4 ; - CAR ; - MUL ; - COMPARE ; - LE ; - NOT ; - IF { PUSH int 0 ; - DUP 3 ; - CAR ; - COMPARE ; - LT ; - IF { PUSH int -1 ; DUP 3 ; CDR ; MUL ; PUSH int -1 ; DIG 3 ; CAR ; MUL ; PAIR } - { SWAP } ; - DUP ; - CDR ; - PUSH nat 0 ; - PUSH nat 10 ; - PAIR ; - DUP 24 ; - SWAP ; - EXEC ; - DIG 2 ; - CAR ; - MUL ; - EDIV ; - IF_NONE { PUSH string "DIV by 0" ; FAILWITH } {} ; - CAR ; - ISNAT ; - IF_NONE { PUSH nat 119 ; FAILWITH } {} ; - DIG 2 ; - PAIR ; - PAIR ; - DUP 19 ; - SWAP ; - EXEC } - { SWAP ; DIG 2 ; DROP 2 } } ; - DUP 4 ; - IF { DUP 3 ; - DUP 3 ; - CAR ; - CDR ; - CDR ; - ADD ; - DUP 3 ; - DIG 3 ; - CAR ; - DUP ; - CDR ; - DIG 3 ; - UPDATE 2 ; - UPDATE 2 ; - UPDATE 1 } - { DUP 3 ; - DUP 3 ; - CDR ; - CDR ; - ADD ; - DUP 3 ; - DIG 3 ; - CDR ; - DIG 2 ; - UPDATE 2 ; - UPDATE 2 } ; - SWAP } - { DUP 6 ; - GET 6 ; - CAR ; - DIG 8 ; - CAR ; - IF_LEFT - { DROP ; - DUP 6 ; - SWAP ; - CAR ; - GET ; - IF_NONE { PUSH nat 111 ; FAILWITH } {} } - { DROP ; - DUP 6 ; - SWAP ; - CDR ; - GET ; - IF_NONE { PUSH nat 111 ; FAILWITH } {} } ; - DUP 3 ; - DUP 3 ; - CDR ; - CAR ; - ADD ; - DUP 3 ; - DIG 3 ; - CDR ; - DIG 2 ; - UPDATE 1 ; - UPDATE 2 ; - DIG 7 ; - DIG 8 ; - DIG 3 ; - PAIR ; - PAIR ; - DUP 19 ; - SWAP ; - EXEC } ; - DUG 3 ; - PAIR ; - PAIR ; - DIG 3 ; - DIG 3 ; - PAIR ; - DIG 2 ; - DIG 3 ; - PAIR ; - PAIR ; - PAIR } ; - UNPAIR ; - CAR ; - CDR ; - SWAP ; - CAR ; - CAR ; - DUP 3 ; - CAR ; - DUP 5 ; - DUP 2 ; - GET ; - IF_NONE - { DIG 4 ; DROP 2 ; PUSH nat 141 ; FAILWITH } - { PUSH nat 1 ; - DUP 2 ; - GET 9 ; - SUB ; - ABS ; - DIG 6 ; - DUG 2 ; - UPDATE 9 ; - SOME ; - DIG 2 ; - UPDATE } ; - DUP ; - DUP 5 ; - CAR ; - GET ; - IF_NONE - { PUSH nat 141 ; FAILWITH } - { PUSH nat 0 ; SWAP ; GET 9 ; COMPARE ; LE } ; - DIG 5 ; - DIG 3 ; - PAIR ; - DIG 6 ; - DIG 2 ; - IF { DIG 2 ; - DROP ; - DUP 5 ; - DIG 5 ; - CDR ; - DIG 5 ; - CAR ; - NONE (pair nat - (or (or (pair (pair timestamp - (pair (pair nat nat nat) - (or (or unit unit) unit) - (pair nat nat nat nat) - (pair (pair string string) (pair int int) timestamp))) - (pair (pair string string) (pair int int) timestamp)) - (pair timestamp timestamp)) - timestamp) - (pair nat nat nat nat nat nat nat nat) - (pair string string) - nat - bool) ; - SWAP ; - UPDATE ; - UPDATE 2 } - { DIG 4 ; DROP ; DIG 4 ; DIG 3 ; UPDATE 2 } ; - PAIR ; - DIG 2 ; - DIG 3 ; - DIG 4 ; - NONE (map (pair (or unit unit) (or (or unit unit) unit)) nat) ; - SWAP ; - UPDATE } } ; - PAIR ; - PAIR ; - PAIR } ; - DIG 5 ; - DIG 6 ; - DROP 2 } - { DUP 2 ; - DUP 2 ; - GET ; - IF_NONE - { DIG 11 ; - DIG 12 ; - DROP 3 ; - DIG 5 ; - DIG 6 ; - PAIR ; - DIG 3 ; - DIG 5 ; - PAIR ; - DIG 3 ; - DIG 3 } - { DUP 7 ; - CDR ; - DUP ; - DUP 4 ; - GET ; - IF_NONE - { SWAP ; - DIG 2 ; - DIG 13 ; - DIG 14 ; - DROP 5 ; - DIG 5 ; - DIG 6 ; - PAIR ; - DIG 3 ; - DIG 5 ; - PAIR ; - DIG 3 ; - DIG 3 } - { DUP ; - GET 3 ; - IF_LEFT - { IF_LEFT - { CAR ; CDR ; SOME } - { DROP ; - NONE (pair (pair nat nat nat) - (or (or unit unit) unit) - (pair nat nat nat nat) - (pair (pair string string) (pair int int) timestamp)) } } - { DROP ; - NONE (pair (pair nat nat nat) - (or (or unit unit) unit) - (pair nat nat nat nat) - (pair (pair string string) (pair int int) timestamp)) } ; - IF_NONE - { SWAP ; - DIG 2 ; - DIG 3 ; - DIG 14 ; - DIG 15 ; - DROP 6 ; - DIG 5 ; - DIG 6 ; - PAIR ; - DIG 3 ; - DIG 5 ; - PAIR ; - DIG 3 ; - DIG 3 } - { DUP 2 ; - GET 10 ; - DUP 12 ; - DIG 13 ; - PAIR ; - PAIR ; - DUP 9 ; - DUP 4 ; - GET 5 ; - PAIR ; - DIG 8 ; - DIG 3 ; - PAIR ; - PAIR ; - PAIR ; - DIG 3 ; - ITER { UNPAIR ; - DIG 2 ; - UNPAIR ; - UNPAIR ; - UNPAIR ; - DIG 2 ; - UNPAIR ; - DIG 4 ; - UNPAIR ; - UNPAIR ; - PUSH nat 0 ; - DUP 5 ; - GET 7 ; - COMPARE ; - EQ ; - IF { PUSH bool False } - { PUSH nat 0 ; - DUP 5 ; - GET 14 ; - COMPARE ; - EQ ; - IF { PUSH bool False } - { DUP 8 ; - CDR ; - DUP 7 ; - GET 3 ; - DUP 10 ; - CAR ; - IF_LEFT - { DROP ; - SWAP ; - IF_LEFT - { IF_LEFT - { DROP ; - IF_LEFT - { IF_LEFT { DROP ; PUSH bool True } { DROP ; PUSH bool False } } - { DROP ; PUSH bool True } } - { DROP ; - IF_LEFT - { IF_LEFT { DROP ; PUSH bool True } { DROP ; PUSH bool True } } - { DROP ; PUSH bool True } } } - { DROP ; - IF_LEFT - { IF_LEFT { DROP ; PUSH bool False } { DROP ; PUSH bool False } } - { DROP ; PUSH bool True } } } - { DROP ; - SWAP ; - IF_LEFT - { IF_LEFT - { DROP ; - IF_LEFT - { IF_LEFT { DROP ; PUSH bool True } { DROP ; PUSH bool True } } - { DROP ; PUSH bool False } } - { DROP ; - IF_LEFT - { IF_LEFT { DROP ; PUSH bool False } { DROP ; PUSH bool True } } - { DROP ; PUSH bool False } } } - { DROP ; - IF_LEFT - { IF_LEFT { DROP ; PUSH bool True } { DROP ; PUSH bool True } } - { DROP ; PUSH bool True } } } } } ; - IF { DUP 6 ; - GET 6 ; - CAR ; - DUP 6 ; - DUP 2 ; - CAR ; - GET ; - IF_NONE { PUSH nat 111 ; FAILWITH } {} ; - DUP 7 ; - DIG 2 ; - CDR ; - GET ; - IF_NONE { PUSH nat 111 ; FAILWITH } {} ; - DIG 9 ; - CAR ; - IF_LEFT - { DROP ; - DUP 8 ; - GET 5 ; - DUP ; - GET 5 ; - INT ; - SWAP ; - GET 3 ; - INT ; - DIG 11 ; - INT ; - PUSH int 1 ; - SWAP ; - PAIR ; - PUSH int 1 ; - DIG 2 ; - PAIR ; - DUP ; - CAR ; - DUP 3 ; - CDR ; - MUL ; - SWAP ; - CDR ; - DUP 3 ; - CAR ; - MUL ; - PAIR ; - PUSH int 1 ; - DIG 3 ; - PAIR ; - DUP ; - CDR ; - DUP 3 ; - CDR ; - MUL ; - SWAP ; - CAR ; - DIG 2 ; - CAR ; - MUL ; - PAIR ; - DUP 10 ; - GET 6 ; - GET 3 ; - DUP ; - CAR ; - DUP 3 ; - CDR ; - MUL ; - SWAP ; - CDR ; - DUP 3 ; - CAR ; - MUL ; - PAIR ; - DUP ; - CDR ; - DUP 4 ; - CDR ; - MUL ; - DUP 4 ; - CDR ; - DUP 3 ; - CAR ; - MUL ; - DIG 2 ; - CDR ; - DIG 4 ; - CAR ; - MUL ; - SUB ; - PAIR ; - PUSH int 0 ; - DUP 3 ; - CAR ; - COMPARE ; - LT ; - IF { PUSH int -1 ; DUP 3 ; CDR ; MUL ; PUSH int -1 ; DIG 3 ; CAR ; MUL ; PAIR } - { SWAP } ; - DUP ; - CDR ; - PUSH nat 0 ; - PUSH nat 10 ; - PAIR ; - DUP 26 ; - SWAP ; - EXEC ; - DIG 2 ; - CAR ; - MUL ; - EDIV ; - IF_NONE { PUSH string "DIV by 0" ; FAILWITH } {} ; - CAR ; - ISNAT ; - IF_NONE { PUSH nat 119 ; FAILWITH } {} ; - DIG 2 ; - PAIR ; - PUSH nat 0 ; - DUP 2 ; - CDR ; - COMPARE ; - GT ; - IF { DIG 9 ; SWAP ; PAIR ; DUP 21 ; SWAP ; EXEC } { DROP ; DIG 8 } ; - PUSH int 1 ; - PUSH int 0 ; - PAIR ; - DUP ; - CAR ; - DUP 4 ; - CDR ; - MUL ; - SWAP ; - CDR ; - DUP 4 ; - CAR ; - MUL ; - COMPARE ; - LE ; - NOT ; - IF { PUSH int 0 ; - DUP 3 ; - CAR ; - COMPARE ; - LT ; - IF { PUSH int -1 ; DUP 3 ; CDR ; MUL ; PUSH int -1 ; DIG 3 ; CAR ; MUL ; PAIR } - { SWAP } ; - DUP ; - CDR ; - PUSH nat 0 ; - PUSH nat 10 ; - PAIR ; - DUP 24 ; - SWAP ; - EXEC ; - DIG 2 ; - CAR ; - MUL ; - EDIV ; - IF_NONE { PUSH string "DIV by 0" ; FAILWITH } {} ; - CAR ; - ISNAT ; - IF_NONE { PUSH nat 119 ; FAILWITH } {} ; - DIG 2 ; - PAIR ; - PAIR ; - DUP 19 ; - SWAP ; - EXEC } - { SWAP ; DIG 2 ; DROP 2 } } - { DROP ; - DUP 8 ; - GET 5 ; - DUP ; - CAR ; - INT ; - SWAP ; - GET 6 ; - INT ; - DIG 11 ; - INT ; - PUSH int 1 ; - SWAP ; - PAIR ; - PUSH int 1 ; - DIG 2 ; - PAIR ; - DUP ; - CAR ; - DUP 3 ; - CDR ; - MUL ; - SWAP ; - CDR ; - DUP 3 ; - CAR ; - MUL ; - PAIR ; - PUSH int 1 ; - DIG 3 ; - PAIR ; - DUP ; - CDR ; - DUP 3 ; - CDR ; - MUL ; - SWAP ; - CAR ; - DIG 2 ; - CAR ; - MUL ; - PAIR ; - DUP 10 ; - GET 6 ; - GET 3 ; - DUP ; - CDR ; - DUP 3 ; - CDR ; - MUL ; - SWAP ; - CAR ; - DUP 3 ; - CAR ; - MUL ; - PAIR ; - DUP ; - CDR ; - DUP 4 ; - CDR ; - MUL ; - DUP 4 ; - CDR ; - DUP 3 ; - CAR ; - MUL ; - DIG 2 ; - CDR ; - DIG 4 ; - CAR ; - MUL ; - SUB ; - PAIR ; - PUSH int 0 ; - DUP 3 ; - CAR ; - COMPARE ; - LT ; - IF { PUSH int -1 ; DUP 3 ; CDR ; MUL ; PUSH int -1 ; DIG 3 ; CAR ; MUL ; PAIR } - { SWAP } ; - DUP ; - CDR ; - PUSH nat 0 ; - PUSH nat 10 ; - PAIR ; - DUP 26 ; - SWAP ; - EXEC ; - DIG 2 ; - CAR ; - MUL ; - EDIV ; - IF_NONE { PUSH string "DIV by 0" ; FAILWITH } {} ; - CAR ; - ISNAT ; - IF_NONE { PUSH nat 119 ; FAILWITH } {} ; - DIG 3 ; - PAIR ; - PUSH nat 0 ; - DUP 2 ; - CDR ; - COMPARE ; - GT ; - IF { DIG 9 ; SWAP ; PAIR ; DUP 21 ; SWAP ; EXEC } { DROP ; DIG 8 } ; - PUSH int 1 ; - PUSH int 0 ; - PAIR ; - DUP ; - CAR ; - DUP 4 ; - CDR ; - MUL ; - SWAP ; - CDR ; - DUP 4 ; - CAR ; - MUL ; - COMPARE ; - LE ; - NOT ; - IF { PUSH int 0 ; - DUP 3 ; - CAR ; - COMPARE ; - LT ; - IF { PUSH int -1 ; DUP 3 ; CDR ; MUL ; PUSH int -1 ; DIG 3 ; CAR ; MUL ; PAIR } - { SWAP } ; - DUP ; - CDR ; - PUSH nat 0 ; - PUSH nat 10 ; - PAIR ; - DUP 24 ; - SWAP ; - EXEC ; - DIG 2 ; - CAR ; - MUL ; - EDIV ; - IF_NONE { PUSH string "DIV by 0" ; FAILWITH } {} ; - CAR ; - ISNAT ; - IF_NONE { PUSH nat 119 ; FAILWITH } {} ; - DIG 2 ; - PAIR ; - PAIR ; - DUP 19 ; - SWAP ; - EXEC } - { SWAP ; DIG 2 ; DROP 2 } } ; - DUP 4 ; - IF { DUP 3 ; - DUP 3 ; - CAR ; - CDR ; - CDR ; - ADD ; - DUP 3 ; - DIG 3 ; - CAR ; - DUP ; - CDR ; - DIG 3 ; - UPDATE 2 ; - UPDATE 2 ; - UPDATE 1 } - { DUP 3 ; - DUP 3 ; - CDR ; - CDR ; - ADD ; - DUP 3 ; - DIG 3 ; - CDR ; - DIG 2 ; - UPDATE 2 ; - UPDATE 2 } ; - SWAP } - { DUP 6 ; - GET 6 ; - CAR ; - DIG 8 ; - CAR ; - IF_LEFT - { DROP ; - DUP 6 ; - SWAP ; - CAR ; - GET ; - IF_NONE { PUSH nat 111 ; FAILWITH } {} } - { DROP ; - DUP 6 ; - SWAP ; - CDR ; - GET ; - IF_NONE { PUSH nat 111 ; FAILWITH } {} } ; - DUP 3 ; - DUP 3 ; - CDR ; - CAR ; - ADD ; - DUP 3 ; - DIG 3 ; - CDR ; - DIG 2 ; - UPDATE 1 ; - UPDATE 2 ; - DIG 7 ; - DIG 8 ; - DIG 3 ; - PAIR ; - PAIR ; - DUP 19 ; - SWAP ; - EXEC } ; - DUG 3 ; - PAIR ; - PAIR ; - DIG 3 ; - DIG 3 ; - PAIR ; - DIG 2 ; - DIG 3 ; - PAIR ; - PAIR ; - PAIR } ; - DIG 12 ; - DIG 13 ; - DROP 2 ; - UNPAIR ; - CAR ; - CDR ; - SWAP ; - CAR ; - CAR ; - DUP 3 ; - CAR ; - DUP 5 ; - DUP 2 ; - GET ; - IF_NONE - { DIG 4 ; DROP 2 ; PUSH nat 141 ; FAILWITH } - { PUSH nat 1 ; - DUP 2 ; - GET 9 ; - SUB ; - ABS ; - DIG 6 ; - DUG 2 ; - UPDATE 9 ; - SOME ; - DIG 2 ; - UPDATE } ; - DUP ; - DUP 5 ; - CAR ; - GET ; - IF_NONE - { PUSH nat 141 ; FAILWITH } - { PUSH nat 0 ; SWAP ; GET 9 ; COMPARE ; LE } ; - DIG 10 ; - DIG 3 ; - PAIR ; - DIG 7 ; - DIG 2 ; - IF { DIG 2 ; - DROP ; - DUP 8 ; - DIG 8 ; - CDR ; - DIG 5 ; - CAR ; - NONE (pair nat - (or (or (pair (pair timestamp - (pair (pair nat nat nat) - (or (or unit unit) unit) - (pair nat nat nat nat) - (pair (pair string string) (pair int int) timestamp))) - (pair (pair string string) (pair int int) timestamp)) - (pair timestamp timestamp)) - timestamp) - (pair nat nat nat nat nat nat nat nat) - (pair string string) - nat - bool) ; - SWAP ; - UPDATE ; - UPDATE 2 } - { DIG 4 ; DROP ; DIG 7 ; DIG 3 ; UPDATE 2 } ; - PAIR ; - DIG 2 ; - DIG 4 ; - DIG 4 ; - NONE (map (pair (or unit unit) (or (or unit unit) unit)) nat) ; - SWAP ; - UPDATE } } } ; - PAIR ; - PAIR ; - PAIR } ; - UNPAIR ; - UNPAIR ; - UNPAIR ; - DIG 2 ; - CAR ; - DIG 3 ; - CAR ; - DIG 3 ; - DIG 2 ; - PAIR ; - DIG 3 ; - DIG 3 ; - SOME ; - DUP 6 ; - UPDATE } ; - DUG 2 ; - UNPAIR ; - NIL operation ; - DIG 2 ; - ITER { CDR ; - DUP ; - CAR ; - GET 5 ; - IF_NONE - { DROP ; PUSH nat 109 ; FAILWITH } - { DUP 2 ; - CAR ; - GET 8 ; - IF_NONE - { DROP 2 ; PUSH nat 108 ; FAILWITH } - { PUSH string "FA1.2 token" ; - DUP 2 ; - COMPARE ; - EQ ; - IF { DROP ; - CONTRACT %transfer (pair (address %from) (address %to) (nat %value)) ; - IF_NONE { PUSH nat 101 ; FAILWITH } {} ; - PUSH mutez 0 ; - DIG 2 ; - CDR ; - DUP 9 ; - DUP 9 ; - PAIR 3 ; - TRANSFER_TOKENS } - { PUSH string "FA2 token" ; - SWAP ; - COMPARE ; - EQ ; - IF { CONTRACT %transfer - (list (pair (address %from_) (list %tx (pair (address %to_) (nat %token_id) (nat %amount))))) ; - IF_NONE { PUSH nat 101 ; FAILWITH } {} ; - PUSH mutez 0 ; - NIL (pair address (list (pair address nat nat))) ; - NIL (pair address nat nat) ; - DUP 5 ; - CDR ; - DIG 5 ; - CAR ; - CAR ; - DUP 12 ; - PAIR 3 ; - CONS ; - DUP 9 ; - PAIR ; - CONS ; - TRANSFER_TOKENS } - { DROP 2 ; PUSH nat 108 ; FAILWITH } } } } ; - CONS } ; - DIG 4 ; - DIG 5 ; - DROP 2 ; - PUSH mutez 0 ; - DUP 4 ; - CDR ; - CAR ; - COMPARE ; - GT ; - IF { DUP 3 ; - CAR ; - CAR ; - CDR ; - CONTRACT unit ; - IF_NONE - { PUSH nat 102 ; FAILWITH } - { DUP 4 ; CDR ; CAR ; UNIT ; TRANSFER_TOKENS } ; - CONS } - {} ; - PUSH mutez 0 ; - DUP 4 ; - CAR ; - CDR ; - CDR ; - COMPARE ; - GT ; - IF { DUP 3 ; - CAR ; - CAR ; - CAR ; - CONTRACT unit ; - IF_NONE - { PUSH nat 102 ; FAILWITH } - { DUP 4 ; CAR ; CDR ; CDR ; UNIT ; TRANSFER_TOKENS } ; - CONS } - {} ; - PUSH mutez 0 ; - DUP 4 ; - CDR ; - CDR ; - COMPARE ; - GT ; - IF { DUP 3 ; - CAR ; - CDR ; - CAR ; - CONTRACT unit ; - IF_NONE - { DIG 2 ; DROP ; PUSH nat 102 ; FAILWITH } - { DIG 3 ; CDR ; CDR ; UNIT ; TRANSFER_TOKENS } ; - CONS } - { DIG 2 ; DROP } ; - DUP 4 ; - DIG 4 ; - CDR ; - DUP ; - CAR ; - DUP ; - CDR ; - DIG 6 ; - UPDATE 1 ; - UPDATE 2 ; - UPDATE 1 ; - UPDATE 2 ; - DUP ; - CAR ; - DUP ; - CAR ; - DUP ; - CAR ; - DIG 5 ; - UPDATE 2 ; - UPDATE 1 ; - UPDATE 1 ; - UPDATE 1 ; - SWAP } } - { IF_LEFT - { SENDER ; - PUSH mutez 1 ; - AMOUNT ; - COMPARE ; - LT ; - IF {} { PUSH nat 118 ; FAILWITH } ; - SELF_ADDRESS ; - PUSH mutez 0 ; - PUSH mutez 0 ; - PAIR ; - PUSH mutez 0 ; - DUP 6 ; - CAR ; - CDR ; - CAR ; - CAR ; - PAIR ; - DUP 4 ; - DUP 7 ; - CAR ; - CDR ; - CDR ; - CDR ; - PAIR ; - PAIR ; - PAIR ; - DUP 5 ; - CAR ; - CAR ; - CDR ; - CDR ; - DUP 6 ; - CAR ; - CAR ; - CAR ; - CDR ; - DUP 7 ; - CDR ; - CAR ; - CDR ; - CAR ; - DUP 8 ; - CDR ; - CDR ; - EMPTY_MAP string (pair (pair nat string (option address) nat (option string)) nat) ; - DUP 3 ; - DUP 9 ; - GET ; - IF_NONE - { SWAP ; DIG 4 ; DIG 8 ; DIG 10 ; DIG 11 ; DROP 5 ; DIG 2 ; PAIR ; SWAP } - { DIG 9 ; - SOME ; - IF_NONE - { DIG 5 ; - DIG 6 ; - PAIR ; - DIG 3 ; - DIG 5 ; - PAIR ; - DIG 3 ; - DUP 4 ; - PAIR ; - PAIR ; - PAIR ; - SWAP ; - ITER { UNPAIR ; - DIG 2 ; - UNPAIR ; - UNPAIR ; - UNPAIR ; - DIG 2 ; - UNPAIR ; - DIG 4 ; - UNPAIR ; - DUP 3 ; - CDR ; - DUP ; - DUP 9 ; - GET ; - IF_NONE - { DIG 7 ; DIG 8 ; DROP 3 ; PAIR ; DUG 2 ; PAIR ; DIG 3 ; DIG 3 } - { DUP ; - GET 3 ; - IF_LEFT - { IF_LEFT - { CAR ; CDR ; SOME } - { DROP ; - NONE (pair (pair nat nat nat) - (or (or unit unit) unit) - (pair nat nat nat nat) - (pair (pair string string) (pair int int) timestamp)) } } - { DROP ; - NONE (pair (pair nat nat nat) - (or (or unit unit) unit) - (pair nat nat nat nat) - (pair (pair string string) (pair int int) timestamp)) } ; - IF_NONE - { SWAP ; DIG 8 ; DIG 9 ; DROP 4 ; PAIR ; DUG 2 ; PAIR ; DIG 3 ; DIG 3 } - { DUP 2 ; - GET 10 ; - DUP 6 ; - DIG 5 ; - PAIR ; - PAIR ; - DUP 7 ; - DUP 4 ; - GET 5 ; - PAIR ; - DIG 9 ; - DIG 3 ; - PAIR ; - PAIR ; - PAIR ; - DIG 8 ; - ITER { UNPAIR ; - DIG 2 ; - UNPAIR ; - UNPAIR ; - UNPAIR ; - DIG 2 ; - UNPAIR ; - DIG 4 ; - UNPAIR ; - UNPAIR ; - PUSH nat 0 ; - DUP 5 ; - GET 7 ; - COMPARE ; - EQ ; - IF { PUSH bool False } - { PUSH nat 0 ; - DUP 5 ; - GET 14 ; - COMPARE ; - EQ ; - IF { PUSH bool False } - { DUP 8 ; - CDR ; - DUP 7 ; - GET 3 ; - DUP 10 ; - CAR ; - IF_LEFT - { DROP ; - SWAP ; - IF_LEFT - { IF_LEFT - { DROP ; - IF_LEFT - { IF_LEFT { DROP ; PUSH bool True } { DROP ; PUSH bool False } } - { DROP ; PUSH bool True } } - { DROP ; - IF_LEFT - { IF_LEFT { DROP ; PUSH bool True } { DROP ; PUSH bool True } } - { DROP ; PUSH bool True } } } - { DROP ; - IF_LEFT - { IF_LEFT { DROP ; PUSH bool False } { DROP ; PUSH bool False } } - { DROP ; PUSH bool True } } } - { DROP ; - SWAP ; - IF_LEFT - { IF_LEFT - { DROP ; - IF_LEFT - { IF_LEFT { DROP ; PUSH bool True } { DROP ; PUSH bool True } } - { DROP ; PUSH bool False } } - { DROP ; - IF_LEFT - { IF_LEFT { DROP ; PUSH bool False } { DROP ; PUSH bool True } } - { DROP ; PUSH bool False } } } - { DROP ; - IF_LEFT - { IF_LEFT { DROP ; PUSH bool True } { DROP ; PUSH bool True } } - { DROP ; PUSH bool True } } } } } ; - IF { DUP 6 ; - GET 6 ; - CAR ; - DUP 6 ; - DUP 2 ; - CAR ; - GET ; - IF_NONE { PUSH nat 111 ; FAILWITH } {} ; - DUP 7 ; - DIG 2 ; - CDR ; - GET ; - IF_NONE { PUSH nat 111 ; FAILWITH } {} ; - DIG 9 ; - CAR ; - IF_LEFT - { DROP ; - DUP 8 ; - GET 5 ; - DUP ; - GET 5 ; - INT ; - SWAP ; - GET 3 ; - INT ; - DIG 11 ; - INT ; - PUSH int 1 ; - SWAP ; - PAIR ; - PUSH int 1 ; - DIG 2 ; - PAIR ; - DUP ; - CAR ; - DUP 3 ; - CDR ; - MUL ; - SWAP ; - CDR ; - DUP 3 ; - CAR ; - MUL ; - PAIR ; - PUSH int 1 ; - DIG 3 ; - PAIR ; - DUP ; - CDR ; - DUP 3 ; - CDR ; - MUL ; - SWAP ; - CAR ; - DIG 2 ; - CAR ; - MUL ; - PAIR ; - DUP 10 ; - GET 6 ; - GET 3 ; - DUP ; - CAR ; - DUP 3 ; - CDR ; - MUL ; - SWAP ; - CDR ; - DUP 3 ; - CAR ; - MUL ; - PAIR ; - DUP ; - CDR ; - DUP 4 ; - CDR ; - MUL ; - DUP 4 ; - CDR ; - DUP 3 ; - CAR ; - MUL ; - DIG 2 ; - CDR ; - DIG 4 ; - CAR ; - MUL ; - SUB ; - PAIR ; - PUSH int 0 ; - DUP 3 ; - CAR ; - COMPARE ; - LT ; - IF { PUSH int -1 ; DUP 3 ; CDR ; MUL ; PUSH int -1 ; DIG 3 ; CAR ; MUL ; PAIR } - { SWAP } ; - DUP ; - CDR ; - PUSH nat 0 ; - PUSH nat 10 ; - PAIR ; - DUP 26 ; - SWAP ; - EXEC ; - DIG 2 ; - CAR ; - MUL ; - EDIV ; - IF_NONE { PUSH string "DIV by 0" ; FAILWITH } {} ; - CAR ; - ISNAT ; - IF_NONE { PUSH nat 119 ; FAILWITH } {} ; - DIG 2 ; - PAIR ; - PUSH nat 0 ; - DUP 2 ; - CDR ; - COMPARE ; - GT ; - IF { DIG 9 ; SWAP ; PAIR ; DUP 21 ; SWAP ; EXEC } { DROP ; DIG 8 } ; - PUSH int 1 ; - PUSH int 0 ; - PAIR ; - DUP ; - CAR ; - DUP 4 ; - CDR ; - MUL ; - SWAP ; - CDR ; - DUP 4 ; - CAR ; - MUL ; - COMPARE ; - LE ; - NOT ; - IF { PUSH int 0 ; - DUP 3 ; - CAR ; - COMPARE ; - LT ; - IF { PUSH int -1 ; DUP 3 ; CDR ; MUL ; PUSH int -1 ; DIG 3 ; CAR ; MUL ; PAIR } - { SWAP } ; - DUP ; - CDR ; - PUSH nat 0 ; - PUSH nat 10 ; - PAIR ; - DUP 24 ; - SWAP ; - EXEC ; - DIG 2 ; - CAR ; - MUL ; - EDIV ; - IF_NONE { PUSH string "DIV by 0" ; FAILWITH } {} ; - CAR ; - ISNAT ; - IF_NONE { PUSH nat 119 ; FAILWITH } {} ; - DIG 2 ; - PAIR ; - PAIR ; - DUP 19 ; - SWAP ; - EXEC } - { SWAP ; DIG 2 ; DROP 2 } } - { DROP ; - DUP 8 ; - GET 5 ; - DUP ; - CAR ; - INT ; - SWAP ; - GET 6 ; - INT ; - DIG 11 ; - INT ; - PUSH int 1 ; - SWAP ; - PAIR ; - PUSH int 1 ; - DIG 2 ; - PAIR ; - DUP ; - CAR ; - DUP 3 ; - CDR ; - MUL ; - SWAP ; - CDR ; - DUP 3 ; - CAR ; - MUL ; - PAIR ; - PUSH int 1 ; - DIG 3 ; - PAIR ; - DUP ; - CDR ; - DUP 3 ; - CDR ; - MUL ; - SWAP ; - CAR ; - DIG 2 ; - CAR ; - MUL ; - PAIR ; - DUP 10 ; - GET 6 ; - GET 3 ; - DUP ; - CDR ; - DUP 3 ; - CDR ; - MUL ; - SWAP ; - CAR ; - DUP 3 ; - CAR ; - MUL ; - PAIR ; - DUP ; - CDR ; - DUP 4 ; - CDR ; - MUL ; - DUP 4 ; - CDR ; - DUP 3 ; - CAR ; - MUL ; - DIG 2 ; - CDR ; - DIG 4 ; - CAR ; - MUL ; - SUB ; - PAIR ; - PUSH int 0 ; - DUP 3 ; - CAR ; - COMPARE ; - LT ; - IF { PUSH int -1 ; DUP 3 ; CDR ; MUL ; PUSH int -1 ; DIG 3 ; CAR ; MUL ; PAIR } - { SWAP } ; - DUP ; - CDR ; - PUSH nat 0 ; - PUSH nat 10 ; - PAIR ; - DUP 26 ; - SWAP ; - EXEC ; - DIG 2 ; - CAR ; - MUL ; - EDIV ; - IF_NONE { PUSH string "DIV by 0" ; FAILWITH } {} ; - CAR ; - ISNAT ; - IF_NONE { PUSH nat 119 ; FAILWITH } {} ; - DIG 3 ; - PAIR ; - PUSH nat 0 ; - DUP 2 ; - CDR ; - COMPARE ; - GT ; - IF { DIG 9 ; SWAP ; PAIR ; DUP 21 ; SWAP ; EXEC } { DROP ; DIG 8 } ; - PUSH int 1 ; - PUSH int 0 ; - PAIR ; - DUP ; - CAR ; - DUP 4 ; - CDR ; - MUL ; - SWAP ; - CDR ; - DUP 4 ; - CAR ; - MUL ; - COMPARE ; - LE ; - NOT ; - IF { PUSH int 0 ; - DUP 3 ; - CAR ; - COMPARE ; - LT ; - IF { PUSH int -1 ; DUP 3 ; CDR ; MUL ; PUSH int -1 ; DIG 3 ; CAR ; MUL ; PAIR } - { SWAP } ; - DUP ; - CDR ; - PUSH nat 0 ; - PUSH nat 10 ; - PAIR ; - DUP 24 ; - SWAP ; - EXEC ; - DIG 2 ; - CAR ; - MUL ; - EDIV ; - IF_NONE { PUSH string "DIV by 0" ; FAILWITH } {} ; - CAR ; - ISNAT ; - IF_NONE { PUSH nat 119 ; FAILWITH } {} ; - DIG 2 ; - PAIR ; - PAIR ; - DUP 19 ; - SWAP ; - EXEC } - { SWAP ; DIG 2 ; DROP 2 } } ; - DUP 4 ; - IF { DUP 3 ; - DUP 3 ; - CAR ; - CDR ; - CDR ; - ADD ; - DUP 3 ; - DIG 3 ; - CAR ; - DUP ; - CDR ; - DIG 3 ; - UPDATE 2 ; - UPDATE 2 ; - UPDATE 1 } - { DUP 3 ; - DUP 3 ; - CDR ; - CDR ; - ADD ; - DUP 3 ; - DIG 3 ; - CDR ; - DIG 2 ; - UPDATE 2 ; - UPDATE 2 } ; - SWAP } - { DUP 6 ; - GET 6 ; - CAR ; - DIG 8 ; - CAR ; - IF_LEFT - { DROP ; - DUP 6 ; - SWAP ; - CAR ; - GET ; - IF_NONE { PUSH nat 111 ; FAILWITH } {} } - { DROP ; - DUP 6 ; - SWAP ; - CDR ; - GET ; - IF_NONE { PUSH nat 111 ; FAILWITH } {} } ; - DUP 3 ; - DUP 3 ; - CDR ; - CAR ; - ADD ; - DUP 3 ; - DIG 3 ; - CDR ; - DIG 2 ; - UPDATE 1 ; - UPDATE 2 ; - DIG 7 ; - DIG 8 ; - DIG 3 ; - PAIR ; - PAIR ; - DUP 19 ; - SWAP ; - EXEC } ; - DUG 3 ; - PAIR ; - PAIR ; - DIG 3 ; - DIG 3 ; - PAIR ; - DIG 2 ; - DIG 3 ; - PAIR ; - PAIR ; - PAIR } ; - UNPAIR ; - CAR ; - CDR ; - SWAP ; - CAR ; - CAR ; - DUP 3 ; - CAR ; - DUP 5 ; - DUP 2 ; - GET ; - IF_NONE - { DIG 4 ; DROP 2 ; PUSH nat 141 ; FAILWITH } - { PUSH nat 1 ; - DUP 2 ; - GET 9 ; - SUB ; - ABS ; - DIG 6 ; - DUG 2 ; - UPDATE 9 ; - SOME ; - DIG 2 ; - UPDATE } ; - DUP ; - DUP 5 ; - CAR ; - GET ; - IF_NONE - { PUSH nat 141 ; FAILWITH } - { PUSH nat 0 ; SWAP ; GET 9 ; COMPARE ; LE } ; - DIG 5 ; - DIG 3 ; - PAIR ; - DIG 6 ; - DIG 2 ; - IF { DIG 2 ; - DROP ; - DUP 5 ; - DIG 5 ; - CDR ; - DIG 5 ; - CAR ; - NONE (pair nat - (or (or (pair (pair timestamp - (pair (pair nat nat nat) - (or (or unit unit) unit) - (pair nat nat nat nat) - (pair (pair string string) (pair int int) timestamp))) - (pair (pair string string) (pair int int) timestamp)) - (pair timestamp timestamp)) - timestamp) - (pair nat nat nat nat nat nat nat nat) - (pair string string) - nat - bool) ; - SWAP ; - UPDATE ; - UPDATE 2 } - { DIG 4 ; DROP ; DIG 4 ; DIG 3 ; UPDATE 2 } ; - PAIR ; - DIG 2 ; - DIG 3 ; - DIG 4 ; - NONE (map (pair (or unit unit) (or (or unit unit) unit)) nat) ; - SWAP ; - UPDATE } } ; - PAIR ; - PAIR ; - PAIR } ; - DIG 5 ; - DIG 6 ; - DROP 2 } - { DUP 2 ; - DUP 2 ; - GET ; - IF_NONE - { DIG 11 ; - DIG 12 ; - DROP 3 ; - DIG 5 ; - DIG 6 ; - PAIR ; - DIG 3 ; - DIG 5 ; - PAIR ; - DIG 3 ; - DIG 3 } - { DUP 7 ; - CDR ; - DUP ; - DUP 4 ; - GET ; - IF_NONE - { SWAP ; - DIG 2 ; - DIG 13 ; - DIG 14 ; - DROP 5 ; - DIG 5 ; - DIG 6 ; - PAIR ; - DIG 3 ; - DIG 5 ; - PAIR ; - DIG 3 ; - DIG 3 } - { DUP ; - GET 3 ; - IF_LEFT - { IF_LEFT - { CAR ; CDR ; SOME } - { DROP ; - NONE (pair (pair nat nat nat) - (or (or unit unit) unit) - (pair nat nat nat nat) - (pair (pair string string) (pair int int) timestamp)) } } - { DROP ; - NONE (pair (pair nat nat nat) - (or (or unit unit) unit) - (pair nat nat nat nat) - (pair (pair string string) (pair int int) timestamp)) } ; - IF_NONE - { SWAP ; - DIG 2 ; - DIG 3 ; - DIG 14 ; - DIG 15 ; - DROP 6 ; - DIG 5 ; - DIG 6 ; - PAIR ; - DIG 3 ; - DIG 5 ; - PAIR ; - DIG 3 ; - DIG 3 } - { DUP 2 ; - GET 10 ; - DUP 12 ; - DIG 13 ; - PAIR ; - PAIR ; - DUP 9 ; - DUP 4 ; - GET 5 ; - PAIR ; - DIG 8 ; - DIG 3 ; - PAIR ; - PAIR ; - PAIR ; - DIG 3 ; - ITER { UNPAIR ; - DIG 2 ; - UNPAIR ; - UNPAIR ; - UNPAIR ; - DIG 2 ; - UNPAIR ; - DIG 4 ; - UNPAIR ; - UNPAIR ; - PUSH nat 0 ; - DUP 5 ; - GET 7 ; - COMPARE ; - EQ ; - IF { PUSH bool False } - { PUSH nat 0 ; - DUP 5 ; - GET 14 ; - COMPARE ; - EQ ; - IF { PUSH bool False } - { DUP 8 ; - CDR ; - DUP 7 ; - GET 3 ; - DUP 10 ; - CAR ; - IF_LEFT - { DROP ; - SWAP ; - IF_LEFT - { IF_LEFT - { DROP ; - IF_LEFT - { IF_LEFT { DROP ; PUSH bool True } { DROP ; PUSH bool False } } - { DROP ; PUSH bool True } } - { DROP ; - IF_LEFT - { IF_LEFT { DROP ; PUSH bool True } { DROP ; PUSH bool True } } - { DROP ; PUSH bool True } } } - { DROP ; - IF_LEFT - { IF_LEFT { DROP ; PUSH bool False } { DROP ; PUSH bool False } } - { DROP ; PUSH bool True } } } - { DROP ; - SWAP ; - IF_LEFT - { IF_LEFT - { DROP ; - IF_LEFT - { IF_LEFT { DROP ; PUSH bool True } { DROP ; PUSH bool True } } - { DROP ; PUSH bool False } } - { DROP ; - IF_LEFT - { IF_LEFT { DROP ; PUSH bool False } { DROP ; PUSH bool True } } - { DROP ; PUSH bool False } } } - { DROP ; - IF_LEFT - { IF_LEFT { DROP ; PUSH bool True } { DROP ; PUSH bool True } } - { DROP ; PUSH bool True } } } } } ; - IF { DUP 6 ; - GET 6 ; - CAR ; - DUP 6 ; - DUP 2 ; - CAR ; - GET ; - IF_NONE { PUSH nat 111 ; FAILWITH } {} ; - DUP 7 ; - DIG 2 ; - CDR ; - GET ; - IF_NONE { PUSH nat 111 ; FAILWITH } {} ; - DIG 9 ; - CAR ; - IF_LEFT - { DROP ; - DUP 8 ; - GET 5 ; - DUP ; - GET 5 ; - INT ; - SWAP ; - GET 3 ; - INT ; - DIG 11 ; - INT ; - PUSH int 1 ; - SWAP ; - PAIR ; - PUSH int 1 ; - DIG 2 ; - PAIR ; - DUP ; - CAR ; - DUP 3 ; - CDR ; - MUL ; - SWAP ; - CDR ; - DUP 3 ; - CAR ; - MUL ; - PAIR ; - PUSH int 1 ; - DIG 3 ; - PAIR ; - DUP ; - CDR ; - DUP 3 ; - CDR ; - MUL ; - SWAP ; - CAR ; - DIG 2 ; - CAR ; - MUL ; - PAIR ; - DUP 10 ; - GET 6 ; - GET 3 ; - DUP ; - CAR ; - DUP 3 ; - CDR ; - MUL ; - SWAP ; - CDR ; - DUP 3 ; - CAR ; - MUL ; - PAIR ; - DUP ; - CDR ; - DUP 4 ; - CDR ; - MUL ; - DUP 4 ; - CDR ; - DUP 3 ; - CAR ; - MUL ; - DIG 2 ; - CDR ; - DIG 4 ; - CAR ; - MUL ; - SUB ; - PAIR ; - PUSH int 0 ; - DUP 3 ; - CAR ; - COMPARE ; - LT ; - IF { PUSH int -1 ; DUP 3 ; CDR ; MUL ; PUSH int -1 ; DIG 3 ; CAR ; MUL ; PAIR } - { SWAP } ; - DUP ; - CDR ; - PUSH nat 0 ; - PUSH nat 10 ; - PAIR ; - DUP 26 ; - SWAP ; - EXEC ; - DIG 2 ; - CAR ; - MUL ; - EDIV ; - IF_NONE { PUSH string "DIV by 0" ; FAILWITH } {} ; - CAR ; - ISNAT ; - IF_NONE { PUSH nat 119 ; FAILWITH } {} ; - DIG 2 ; - PAIR ; - PUSH nat 0 ; - DUP 2 ; - CDR ; - COMPARE ; - GT ; - IF { DIG 9 ; SWAP ; PAIR ; DUP 21 ; SWAP ; EXEC } { DROP ; DIG 8 } ; - PUSH int 1 ; - PUSH int 0 ; - PAIR ; - DUP ; - CAR ; - DUP 4 ; - CDR ; - MUL ; - SWAP ; - CDR ; - DUP 4 ; - CAR ; - MUL ; - COMPARE ; - LE ; - NOT ; - IF { PUSH int 0 ; - DUP 3 ; - CAR ; - COMPARE ; - LT ; - IF { PUSH int -1 ; DUP 3 ; CDR ; MUL ; PUSH int -1 ; DIG 3 ; CAR ; MUL ; PAIR } - { SWAP } ; - DUP ; - CDR ; - PUSH nat 0 ; - PUSH nat 10 ; - PAIR ; - DUP 24 ; - SWAP ; - EXEC ; - DIG 2 ; - CAR ; - MUL ; - EDIV ; - IF_NONE { PUSH string "DIV by 0" ; FAILWITH } {} ; - CAR ; - ISNAT ; - IF_NONE { PUSH nat 119 ; FAILWITH } {} ; - DIG 2 ; - PAIR ; - PAIR ; - DUP 19 ; - SWAP ; - EXEC } - { SWAP ; DIG 2 ; DROP 2 } } - { DROP ; - DUP 8 ; - GET 5 ; - DUP ; - CAR ; - INT ; - SWAP ; - GET 6 ; - INT ; - DIG 11 ; - INT ; - PUSH int 1 ; - SWAP ; - PAIR ; - PUSH int 1 ; - DIG 2 ; - PAIR ; - DUP ; - CAR ; - DUP 3 ; - CDR ; - MUL ; - SWAP ; - CDR ; - DUP 3 ; - CAR ; - MUL ; - PAIR ; - PUSH int 1 ; - DIG 3 ; - PAIR ; - DUP ; - CDR ; - DUP 3 ; - CDR ; - MUL ; - SWAP ; - CAR ; - DIG 2 ; - CAR ; - MUL ; - PAIR ; - DUP 10 ; - GET 6 ; - GET 3 ; - DUP ; - CDR ; - DUP 3 ; - CDR ; - MUL ; - SWAP ; - CAR ; - DUP 3 ; - CAR ; - MUL ; - PAIR ; - DUP ; - CDR ; - DUP 4 ; - CDR ; - MUL ; - DUP 4 ; - CDR ; - DUP 3 ; - CAR ; - MUL ; - DIG 2 ; - CDR ; - DIG 4 ; - CAR ; - MUL ; - SUB ; - PAIR ; - PUSH int 0 ; - DUP 3 ; - CAR ; - COMPARE ; - LT ; - IF { PUSH int -1 ; DUP 3 ; CDR ; MUL ; PUSH int -1 ; DIG 3 ; CAR ; MUL ; PAIR } - { SWAP } ; - DUP ; - CDR ; - PUSH nat 0 ; - PUSH nat 10 ; - PAIR ; - DUP 26 ; - SWAP ; - EXEC ; - DIG 2 ; - CAR ; - MUL ; - EDIV ; - IF_NONE { PUSH string "DIV by 0" ; FAILWITH } {} ; - CAR ; - ISNAT ; - IF_NONE { PUSH nat 119 ; FAILWITH } {} ; - DIG 3 ; - PAIR ; - PUSH nat 0 ; - DUP 2 ; - CDR ; - COMPARE ; - GT ; - IF { DIG 9 ; SWAP ; PAIR ; DUP 21 ; SWAP ; EXEC } { DROP ; DIG 8 } ; - PUSH int 1 ; - PUSH int 0 ; - PAIR ; - DUP ; - CAR ; - DUP 4 ; - CDR ; - MUL ; - SWAP ; - CDR ; - DUP 4 ; - CAR ; - MUL ; - COMPARE ; - LE ; - NOT ; - IF { PUSH int 0 ; - DUP 3 ; - CAR ; - COMPARE ; - LT ; - IF { PUSH int -1 ; DUP 3 ; CDR ; MUL ; PUSH int -1 ; DIG 3 ; CAR ; MUL ; PAIR } - { SWAP } ; - DUP ; - CDR ; - PUSH nat 0 ; - PUSH nat 10 ; - PAIR ; - DUP 24 ; - SWAP ; - EXEC ; - DIG 2 ; - CAR ; - MUL ; - EDIV ; - IF_NONE { PUSH string "DIV by 0" ; FAILWITH } {} ; - CAR ; - ISNAT ; - IF_NONE { PUSH nat 119 ; FAILWITH } {} ; - DIG 2 ; - PAIR ; - PAIR ; - DUP 19 ; - SWAP ; - EXEC } - { SWAP ; DIG 2 ; DROP 2 } } ; - DUP 4 ; - IF { DUP 3 ; - DUP 3 ; - CAR ; - CDR ; - CDR ; - ADD ; - DUP 3 ; - DIG 3 ; - CAR ; - DUP ; - CDR ; - DIG 3 ; - UPDATE 2 ; - UPDATE 2 ; - UPDATE 1 } - { DUP 3 ; - DUP 3 ; - CDR ; - CDR ; - ADD ; - DUP 3 ; - DIG 3 ; - CDR ; - DIG 2 ; - UPDATE 2 ; - UPDATE 2 } ; - SWAP } - { DUP 6 ; - GET 6 ; - CAR ; - DIG 8 ; - CAR ; - IF_LEFT - { DROP ; - DUP 6 ; - SWAP ; - CAR ; - GET ; - IF_NONE { PUSH nat 111 ; FAILWITH } {} } - { DROP ; - DUP 6 ; - SWAP ; - CDR ; - GET ; - IF_NONE { PUSH nat 111 ; FAILWITH } {} } ; - DUP 3 ; - DUP 3 ; - CDR ; - CAR ; - ADD ; - DUP 3 ; - DIG 3 ; - CDR ; - DIG 2 ; - UPDATE 1 ; - UPDATE 2 ; - DIG 7 ; - DIG 8 ; - DIG 3 ; - PAIR ; - PAIR ; - DUP 19 ; - SWAP ; - EXEC } ; - DUG 3 ; - PAIR ; - PAIR ; - DIG 3 ; - DIG 3 ; - PAIR ; - DIG 2 ; - DIG 3 ; - PAIR ; - PAIR ; - PAIR } ; - DIG 12 ; - DIG 13 ; - DROP 2 ; - UNPAIR ; - CAR ; - CDR ; - SWAP ; - CAR ; - CAR ; - DUP 3 ; - CAR ; - DUP 5 ; - DUP 2 ; - GET ; - IF_NONE - { DIG 4 ; DROP 2 ; PUSH nat 141 ; FAILWITH } - { PUSH nat 1 ; - DUP 2 ; - GET 9 ; - SUB ; - ABS ; - DIG 6 ; - DUG 2 ; - UPDATE 9 ; - SOME ; - DIG 2 ; - UPDATE } ; - DUP ; - DUP 5 ; - CAR ; - GET ; - IF_NONE - { PUSH nat 141 ; FAILWITH } - { PUSH nat 0 ; SWAP ; GET 9 ; COMPARE ; LE } ; - DIG 10 ; - DIG 3 ; - PAIR ; - DIG 7 ; - DIG 2 ; - IF { DIG 2 ; - DROP ; - DUP 8 ; - DIG 8 ; - CDR ; - DIG 5 ; - CAR ; - NONE (pair nat - (or (or (pair (pair timestamp - (pair (pair nat nat nat) - (or (or unit unit) unit) - (pair nat nat nat nat) - (pair (pair string string) (pair int int) timestamp))) - (pair (pair string string) (pair int int) timestamp)) - (pair timestamp timestamp)) - timestamp) - (pair nat nat nat nat nat nat nat nat) - (pair string string) - nat - bool) ; - SWAP ; - UPDATE ; - UPDATE 2 } - { DIG 4 ; DROP ; DIG 7 ; DIG 3 ; UPDATE 2 } ; - PAIR ; - DIG 2 ; - DIG 4 ; - DIG 4 ; - NONE (map (pair (or unit unit) (or (or unit unit) unit)) nat) ; - SWAP ; - UPDATE } } } ; - PAIR ; - PAIR ; - PAIR } ; - UNPAIR ; - UNPAIR ; - UNPAIR ; - DIG 2 ; - CAR ; - DIG 3 ; - CAR ; - DIG 3 ; - DIG 2 ; - PAIR ; - DIG 3 ; - DIG 3 ; - SOME ; - DUP 6 ; - UPDATE } ; - DUG 2 ; - UNPAIR ; - NIL operation ; - DIG 2 ; - ITER { CDR ; - DUP ; - CAR ; - GET 5 ; - IF_NONE - { DROP ; PUSH nat 109 ; FAILWITH } - { DUP 2 ; - CAR ; - GET 8 ; - IF_NONE - { DROP 2 ; PUSH nat 108 ; FAILWITH } - { PUSH string "FA1.2 token" ; - DUP 2 ; - COMPARE ; - EQ ; - IF { DROP ; - CONTRACT %transfer (pair (address %from) (address %to) (nat %value)) ; - IF_NONE { PUSH nat 101 ; FAILWITH } {} ; - PUSH mutez 0 ; - DIG 2 ; - CDR ; - DUP 9 ; - DUP 9 ; - PAIR 3 ; - TRANSFER_TOKENS } - { PUSH string "FA2 token" ; - SWAP ; - COMPARE ; - EQ ; - IF { CONTRACT %transfer - (list (pair (address %from_) (list %tx (pair (address %to_) (nat %token_id) (nat %amount))))) ; - IF_NONE { PUSH nat 101 ; FAILWITH } {} ; - PUSH mutez 0 ; - NIL (pair address (list (pair address nat nat))) ; - NIL (pair address nat nat) ; - DUP 5 ; - CDR ; - DIG 5 ; - CAR ; - CAR ; - DUP 12 ; - PAIR 3 ; - CONS ; - DUP 9 ; - PAIR ; - CONS ; - TRANSFER_TOKENS } - { DROP 2 ; PUSH nat 108 ; FAILWITH } } } } ; - CONS } ; - DIG 4 ; - DIG 5 ; - DROP 2 ; - PUSH mutez 0 ; - DUP 4 ; - CDR ; - CAR ; - COMPARE ; - GT ; - IF { DUP 3 ; - CAR ; - CAR ; - CDR ; - CONTRACT unit ; - IF_NONE - { PUSH nat 102 ; FAILWITH } - { DUP 4 ; CDR ; CAR ; UNIT ; TRANSFER_TOKENS } ; - CONS } - {} ; - PUSH mutez 0 ; - DUP 4 ; - CAR ; - CDR ; - CDR ; - COMPARE ; - GT ; - IF { DUP 3 ; - CAR ; - CAR ; - CAR ; - CONTRACT unit ; - IF_NONE - { PUSH nat 102 ; FAILWITH } - { DUP 4 ; CAR ; CDR ; CDR ; UNIT ; TRANSFER_TOKENS } ; - CONS } - {} ; - PUSH mutez 0 ; - DUP 4 ; - CDR ; - CDR ; - COMPARE ; - GT ; - IF { DUP 3 ; - CAR ; - CDR ; - CAR ; - CONTRACT unit ; - IF_NONE - { DIG 2 ; DROP ; PUSH nat 102 ; FAILWITH } - { DIG 3 ; CDR ; CDR ; UNIT ; TRANSFER_TOKENS } ; - CONS } - { DIG 2 ; DROP } ; - DUP 4 ; - DIG 4 ; - CDR ; - DUP ; - CAR ; - DUP ; - CDR ; - DIG 6 ; - UPDATE 1 ; - UPDATE 2 ; - UPDATE 1 ; - UPDATE 2 ; - DUP ; - CAR ; - DUP ; - CAR ; - DUP ; - CAR ; - DIG 5 ; - UPDATE 2 ; - UPDATE 1 ; - UPDATE 1 ; - UPDATE 1 ; - SWAP } - { DIG 2 ; - DIG 3 ; - DROP 2 ; - DUP 2 ; - CAR ; - CAR ; - CAR ; - CAR ; - SENDER ; - COMPARE ; - EQ ; - IF {} { PUSH nat 114 ; FAILWITH } ; - PUSH mutez 1 ; - AMOUNT ; - COMPARE ; - LT ; - IF {} { PUSH nat 118 ; FAILWITH } ; - DUP 2 ; - DUP 3 ; - CDR ; - DUP ; - CAR ; - DUP ; - CAR ; - DIG 5 ; - CDR ; - CAR ; - CAR ; - CAR ; - DIG 5 ; - NONE bytes ; - SWAP ; - UPDATE ; - UPDATE 1 ; - UPDATE 1 ; - UPDATE 1 ; - UPDATE 2 ; - NIL operation } } ; - PAIR } } } - { DIG 2 ; - DROP ; - IF_LEFT - { DIG 2 ; - DIG 3 ; - DIG 4 ; - DROP 3 ; - DUP 2 ; - CAR ; - CAR ; - CAR ; - CAR ; - SENDER ; - COMPARE ; - EQ ; - IF {} { PUSH nat 114 ; FAILWITH } ; - PUSH mutez 1 ; - AMOUNT ; - COMPARE ; - LT ; - IF {} { PUSH nat 118 ; FAILWITH } ; - DUP ; - GET 8 ; - IF {} { PUSH nat 137 ; FAILWITH } ; - DUP 2 ; - CDR ; - CAR ; - CDR ; - CDR ; - DUP 2 ; - CAR ; - DUP ; - CDR ; - GET 3 ; - SWAP ; - CAR ; - CAR ; - GET 3 ; - SWAP ; - DUP 3 ; - 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 - { DROP 2 ; PUSH nat 117 ; FAILWITH } - { DROP ; - DUP 3 ; - CDR ; - CDR ; - DIG 2 ; - CAR ; - DUP ; - CDR ; - GET 3 ; - SWAP ; - CAR ; - CAR ; - GET 3 ; - PAIR ; - DUP ; - CAR ; - DUP 2 ; - CDR ; - DIG 4 ; - DUP 3 ; - DUP 3 ; - COMPARE ; - 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) ; - SWAP ; - UPDATE ; - DUP 3 ; - DUP 3 ; - CAR ; - GET ; - IF_NONE { PUSH nat 111 ; FAILWITH } {} ; - DUP 4 ; - DIG 3 ; - CDR ; - GET ; - IF_NONE { PUSH nat 111 ; FAILWITH } {} ; - PUSH bool False ; - DUP 4 ; - ITER { CDR ; - CAR ; - DUP 6 ; - DUP 2 ; - CDR ; - GET ; - IF_NONE { PUSH nat 111 ; FAILWITH } {} ; - DUP 7 ; - DIG 2 ; - CAR ; - GET ; - IF_NONE { PUSH nat 111 ; FAILWITH } {} ; - DIG 2 ; - DUP 2 ; - GET 8 ; - DUP 6 ; - GET 8 ; - COMPARE ; - EQ ; - DUP 3 ; - GET 7 ; - DUP 7 ; - GET 7 ; - COMPARE ; - EQ ; - DUP 4 ; - GET 5 ; - DUP 8 ; - GET 5 ; - COMPARE ; - EQ ; - DUP 5 ; - GET 3 ; - DUP 9 ; - GET 3 ; - COMPARE ; - EQ ; - DIG 5 ; - CAR ; - DUP 9 ; - CAR ; - COMPARE ; - EQ ; - AND ; - AND ; - AND ; - AND ; - DUP 3 ; - GET 8 ; - DUP 6 ; - GET 8 ; - COMPARE ; - EQ ; - DUP 4 ; - GET 7 ; - DUP 7 ; - GET 7 ; - COMPARE ; - EQ ; - DUP 5 ; - GET 5 ; - DUP 8 ; - GET 5 ; - COMPARE ; - EQ ; - DUP 6 ; - GET 3 ; - DUP 9 ; - GET 3 ; - COMPARE ; - EQ ; - DIG 6 ; - CAR ; - DUP 9 ; - CAR ; - COMPARE ; - EQ ; - AND ; - AND ; - AND ; - AND ; - OR ; - OR } ; - IF { SWAP ; DROP ; DIG 2 } - { DUP 4 ; - DUP 3 ; - GET 3 ; - GET ; - IF_NONE - { SWAP ; DROP ; DIG 2 } - { DUP 3 ; - GET 8 ; - DUP 2 ; - GET 8 ; - COMPARE ; - EQ ; - DUP 4 ; - GET 7 ; - DUP 3 ; - GET 7 ; - COMPARE ; - EQ ; - DUP 5 ; - GET 5 ; - DUP 4 ; - GET 5 ; - COMPARE ; - EQ ; - DUP 6 ; - GET 3 ; - DUP 5 ; - GET 3 ; - COMPARE ; - EQ ; - DUP 7 ; - CAR ; - DIG 5 ; - CAR ; - COMPARE ; - EQ ; - AND ; - AND ; - AND ; - AND ; - IF { DIG 3 ; - DIG 2 ; - GET 3 ; - NONE (pair nat string (option address) nat (option string)) ; - SWAP ; - UPDATE } - { SWAP ; DIG 3 ; DROP 2 ; PUSH nat 115 ; FAILWITH } } } ; - PUSH bool False ; - DUP 4 ; - ITER { CDR ; - CAR ; - DUP 3 ; - DUP 2 ; - CDR ; - GET ; - IF_NONE { PUSH nat 111 ; FAILWITH } {} ; - DUP 4 ; - DIG 2 ; - CAR ; - GET ; - IF_NONE { PUSH nat 111 ; FAILWITH } {} ; - DIG 2 ; - DUP 2 ; - GET 8 ; - DUP 6 ; - GET 8 ; - COMPARE ; - EQ ; - DUP 3 ; - GET 7 ; - DUP 7 ; - GET 7 ; - COMPARE ; - EQ ; - DUP 4 ; - GET 5 ; - DUP 8 ; - GET 5 ; - COMPARE ; - EQ ; - DUP 5 ; - GET 3 ; - DUP 9 ; - GET 3 ; - COMPARE ; - EQ ; - DIG 5 ; - CAR ; - DUP 9 ; - CAR ; - COMPARE ; - EQ ; - AND ; - AND ; - AND ; - AND ; - DUP 3 ; - GET 8 ; - DUP 6 ; - GET 8 ; - COMPARE ; - EQ ; - DUP 4 ; - GET 7 ; - DUP 7 ; - GET 7 ; - COMPARE ; - EQ ; - DUP 5 ; - GET 5 ; - DUP 8 ; - GET 5 ; - COMPARE ; - EQ ; - DUP 6 ; - GET 3 ; - DUP 9 ; - GET 3 ; - COMPARE ; - EQ ; - DIG 6 ; - CAR ; - DUP 9 ; - CAR ; - COMPARE ; - EQ ; - AND ; - AND ; - AND ; - AND ; - OR ; - OR } ; - IF { SWAP ; DROP } - { DUP ; - DUP 3 ; - GET 3 ; - GET ; - IF_NONE - { SWAP ; DROP } - { DUP 3 ; - GET 8 ; - DUP 2 ; - GET 8 ; - COMPARE ; - EQ ; - DUP 4 ; - GET 7 ; - DUP 3 ; - GET 7 ; - COMPARE ; - EQ ; - DUP 5 ; - GET 5 ; - DUP 4 ; - GET 5 ; - COMPARE ; - EQ ; - DUP 6 ; - GET 3 ; - DUP 5 ; - GET 3 ; - COMPARE ; - EQ ; - DUP 7 ; - CAR ; - DIG 5 ; - CAR ; - COMPARE ; - EQ ; - AND ; - AND ; - AND ; - AND ; - IF { SWAP ; - GET 3 ; - NONE (pair nat string (option address) nat (option string)) ; - SWAP ; - UPDATE } - { DROP 2 ; PUSH nat 115 ; FAILWITH } } } ; - SWAP ; - PAIR } ; - UNPAIR ; - DUP 3 ; - DIG 3 ; - CDR ; - DUP ; - CAR ; - DUP ; - CDR ; - DIG 4 ; - UPDATE 2 ; - UPDATE 2 ; - UPDATE 1 ; - UPDATE 2 ; - DUP ; - CDR ; - DIG 2 ; - UPDATE 2 ; - UPDATE 2 ; - NIL operation ; - PAIR } - { PUSH mutez 1 ; - AMOUNT ; - COMPARE ; - LT ; - IF {} { PUSH nat 118 ; FAILWITH } ; - DUP 2 ; - CDR ; - CAR ; - CDR ; - CDR ; - DUP 2 ; - GET ; - IF_NONE - { DROP 5 ; PUSH nat 117 ; FAILWITH } - { DUP 3 ; - CDR ; - CDR ; - DUP 2 ; - CAR ; - DUP 2 ; - DUP 2 ; - CAR ; - GET ; - IF_NONE { PUSH nat 111 ; FAILWITH } {} ; - DUG 2 ; - CDR ; - GET ; - IF_NONE { PUSH nat 111 ; FAILWITH } {} ; - DUP 3 ; - GET 8 ; - DUP 4 ; - GET 7 ; - DUP 5 ; - GET 5 ; - DIG 5 ; - GET 3 ; - DIG 4 ; - PUSH nat 1 ; - DIG 6 ; - PAIR ; - PAIR ; - PAIR 5 ; - DUP ; - GET 8 ; - DUP 2 ; - GET 7 ; - DUP 3 ; - GET 5 ; - DUP 4 ; - GET 3 ; - DUP 5 ; - CAR ; - DUP ; - CDR ; - GET 3 ; - SWAP ; - CAR ; - CAR ; - GET 3 ; - PAIR ; - PAIR 5 ; - DUP ; - GET 3 ; - SWAP ; - GET 5 ; - VIEW "getPrice" (pair timestamp nat) ; - IF_NONE { PUSH nat 122 ; FAILWITH } {} ; - UNPAIR ; - DUP 5 ; - CDR ; - CAR ; - CAR ; - CDR ; - DUP 5 ; - GET ; - IF_NONE - {} - { DUP 2 ; - SWAP ; - GET 4 ; - COMPARE ; - GE ; - IF { PUSH nat 121 ; FAILWITH } {} } ; - DUP 5 ; - CAR ; - CAR ; - CDR ; - CAR ; - INT ; - DUP 2 ; - SWAP ; - NOW ; - SUB ; - COMPARE ; - LT ; - IF {} { PUSH nat 120 ; FAILWITH } ; - DUP 5 ; - CDR ; - CDR ; - DUP 4 ; - CAR ; - DIG 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 8 ; - SWAP ; - EXEC ; - DIG 4 ; - MUL ; - ISNAT ; - IF_NONE { PUSH nat 119 ; FAILWITH } {} ; - DUP 2 ; - CAR ; - CAR ; - GET 7 ; - INT ; - PUSH int 10 ; - PAIR ; - DUP 8 ; - SWAP ; - EXEC ; - SWAP } - { INT ; PUSH int 10 ; PAIR ; DUP 8 ; SWAP ; EXEC ; DIG 4 } ; - 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 3 ; - SWAP ; - DUP 3 ; - CDR ; - GET 3 ; - DIG 3 ; - CAR ; - CAR ; - GET 3 ; - PAIR ; - PAIR 3 ; - DUP ; - CAR ; - DUP 3 ; - DUP 2 ; - CAR ; - GET ; - IF_NONE { PUSH nat 111 ; FAILWITH } {} ; - DIG 3 ; - DIG 2 ; - CDR ; - GET ; - IF_NONE { PUSH nat 111 ; FAILWITH } {} ; - SWAP ; - GET 7 ; - SWAP ; - GET 7 ; - SUB ; - DUP ; - ABS ; - INT ; - PUSH int 10 ; - PAIR ; - DIG 5 ; - 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 ; - DUP 3 ; - DUP 4 ; - CDR ; - DUP ; - CAR ; - DUP ; - CAR ; - DIG 6 ; - CDR ; - CAR ; - CAR ; - CDR ; - DUP ; - DUP 8 ; - GET ; - IF_NONE - { DUP 6 ; DIG 7 ; SWAP ; SOME ; SWAP ; UPDATE } - { GET 4 ; - DUP 7 ; - GET 4 ; - COMPARE ; - GT ; - IF { DUP 6 ; SOME ; DIG 7 ; UPDATE } { DIG 6 ; DROP } } ; - UPDATE 2 ; - UPDATE 1 ; - UPDATE 1 ; - UPDATE 2 ; - DUP 2 ; - CAR ; - UNIT ; - LEFT unit ; - PAIR ; - NOW ; - DUP 3 ; - CAR ; - CAR ; - CAR ; - CDR ; - DIG 2 ; - UNPAIR ; - IF_LEFT { DROP } { DROP ; DUP ; CAR ; SWAP ; CDR ; PAIR } ; - DUP 4 ; - CAR ; - CAR ; - CDR ; - CAR ; - DUP 3 ; - CDR ; - DUP 4 ; - CAR ; - DUP 4 ; - UNPAIR ; - DUP ; - DUP 3 ; - COMPARE ; - GT ; - IF { PUSH string "/" ; CONCAT ; SWAP ; CONCAT } - { SWAP ; PUSH string "/" ; CONCAT ; SWAP ; CONCAT } ; - GET ; - IF_NONE { PUSH nat 0 } {} ; - GET ; - IF_NONE - { DROP 2 ; - DIG 2 ; - SWAP ; - NONE (pair nat - (or (or (pair (pair timestamp - (pair (pair nat nat nat) - (or (or unit unit) unit) - (pair nat nat nat nat) - (pair (pair string string) (pair int int) timestamp))) - (pair (pair string string) (pair int int) timestamp)) - (pair timestamp timestamp)) - timestamp) - (pair nat nat nat nat nat nat nat nat) - (pair string string) - nat - bool) } - { DUP ; - GET 3 ; - IF_LEFT - { IF_LEFT { DROP ; PUSH bool True } { DROP ; PUSH bool False } } - { DROP ; PUSH bool False } ; - IF { SWAP ; DIG 2 ; DROP 2 ; DIG 3 } - { DUP ; - GET 3 ; - IF_LEFT - { DIG 2 ; - DROP ; - IF_LEFT - { DROP 2 ; - PUSH nat 0 ; - DUP 3 ; - CAR ; - ITER { CDR ; DUP 2 ; DUP 2 ; COMPARE ; GT ; IF { SWAP ; DROP } { DROP } } ; - PUSH nat 1 ; - ADD ; - PUSH bool False ; - PUSH nat 0 ; - DIG 3 ; - PUSH nat 0 ; - PUSH nat 0 ; - PUSH nat 0 ; - PUSH nat 0 ; - PUSH nat 0 ; - PUSH nat 0 ; - PUSH nat 0 ; - PUSH nat 0 ; - PAIR 8 ; - DUP 7 ; - RIGHT - (or (pair (pair timestamp - (pair (pair nat nat nat) - (or (or unit unit) unit) - (pair nat nat nat nat) - (pair (pair string string) (pair int int) timestamp))) - (pair (pair string string) (pair int int) timestamp)) - (pair timestamp timestamp)) ; - DIG 5 ; - PAIR 6 ; - DIG 3 ; - DUP 3 ; - DUP 4 ; - CDR ; - DUP 4 ; - SOME ; - DUP 5 ; - CAR ; - UPDATE ; - UPDATE 2 ; - DIG 3 ; - CAR ; - DUP 4 ; - CAR ; - SOME ; - DUP 5 ; - GET 7 ; - UNPAIR ; - DUP ; - DUP 3 ; - COMPARE ; - GT ; - IF { PUSH string "/" ; CONCAT ; SWAP ; CONCAT } - { SWAP ; PUSH string "/" ; CONCAT ; SWAP ; CONCAT } ; - UPDATE ; - UPDATE 1 } - { DIG 2 ; DROP 2 ; DIG 3 ; DIG 2 } } - { DIG 3 ; - DROP ; - DUP 3 ; - INT ; - ADD ; - DUP 5 ; - COMPARE ; - GE ; - IF { DUP ; - GET 3 ; - IF_LEFT - { SWAP ; - DIG 2 ; - DIG 5 ; - DROP 3 ; - IF_LEFT - { DROP ; PUSH nat 105 ; FAILWITH } - { DROP ; PUSH nat 105 ; FAILWITH } } - { DIG 2 ; - INT ; - DUP 2 ; - ADD ; - PAIR ; - RIGHT - (pair (pair timestamp - (pair (pair nat nat nat) - (or (or unit unit) unit) - (pair nat nat nat nat) - (pair (pair string string) (pair int int) timestamp))) - (pair (pair string string) (pair int int) timestamp)) ; - LEFT timestamp ; - UPDATE 3 ; - DIG 3 ; - PAIR } ; - UNPAIR ; - DUP 3 ; - DUP 4 ; - CDR ; - DUP 4 ; - SOME ; - DUP 5 ; - CAR ; - UPDATE ; - UPDATE 2 ; - DIG 3 ; - CAR ; - DUP 4 ; - CAR ; - SOME ; - DUP 5 ; - GET 7 ; - UNPAIR ; - DUP ; - DUP 3 ; - COMPARE ; - GT ; - IF { PUSH string "/" ; CONCAT ; SWAP ; CONCAT } - { SWAP ; PUSH string "/" ; CONCAT ; SWAP ; CONCAT } ; - UPDATE ; - UPDATE 1 } - { SWAP ; DROP ; DIG 3 ; DIG 2 } } ; - DUG 2 } ; - DUG 2 ; - SOME } ; - IF_NONE - { DIG 2 ; DIG 3 ; DIG 4 ; DIG 5 ; DROP 5 } - { DUP ; - GET 3 ; - IF_LEFT - { IF_LEFT - { DIG 4 ; DROP 2 ; PUSH bool False } - { CAR ; PUSH int 120 ; ADD ; DIG 4 ; COMPARE ; GT } } - { DIG 4 ; DROP 2 ; PUSH bool False } ; - IF { NOW ; - DUP 2 ; - GET 5 ; - DUP ; - GET 9 ; - INT ; - DUP 2 ; - GET 11 ; - INT ; - DUP 3 ; - GET 13 ; - INT ; - DUP 4 ; - CAR ; - INT ; - DUP 5 ; - GET 3 ; - INT ; - DUP 6 ; - GET 5 ; - INT ; - DIG 3 ; - DIG 4 ; - DIG 5 ; - PAIR ; - PAIR ; - SWAP ; - DIG 2 ; - DIG 3 ; - PAIR ; - PAIR ; - DUP 8 ; - GET 3 ; - DUP 2 ; - CAR ; - CAR ; - DUP 4 ; - UNPAIR ; - UNPAIR ; - DUP 5 ; - DUP 15 ; - DIG 4 ; - DIG 4 ; - DIG 4 ; - ADD ; - ADD ; - PUSH int 1 ; - SWAP ; - PAIR ; - DUP 2 ; - CDR ; - DUP 2 ; - CDR ; - MUL ; - DIG 2 ; - CAR ; - DIG 2 ; - CAR ; - MUL ; - PAIR ; - DUP 2 ; - CAR ; - DUP 2 ; - CDR ; - MUL ; - DIG 2 ; - CDR ; - DIG 2 ; - CAR ; - MUL ; - PAIR ; - PUSH int 1 ; - DIG 2 ; - PAIR ; - DUP 2 ; - CAR ; - DUP 2 ; - CDR ; - MUL ; - DUP 3 ; - CDR ; - DUP 3 ; - CAR ; - MUL ; - COMPARE ; - LE ; - IF { SWAP ; DROP } { DROP } ; - DUP 3 ; - CAR ; - UNPAIR ; - DUP 6 ; - UNPAIR ; - CDR ; - DIG 3 ; - DIG 3 ; - ADD ; - DUP 5 ; - DIG 3 ; - DIG 3 ; - ADD ; - PUSH int 1 ; - SWAP ; - PAIR ; - DUP 2 ; - CAR ; - DUP 2 ; - CDR ; - MUL ; - DIG 2 ; - CDR ; - DIG 2 ; - CAR ; - MUL ; - PAIR ; - PUSH int 1 ; - DIG 2 ; - PAIR ; - DUP 2 ; - CAR ; - DUP 2 ; - CDR ; - MUL ; - DUP 3 ; - CDR ; - DUP 3 ; - CAR ; - MUL ; - COMPARE ; - LE ; - IF { SWAP ; DROP } { DROP } ; - DIG 3 ; - UNPAIR ; - UNPAIR ; - DIG 6 ; - CDR ; - DUG 3 ; - ADD ; - ADD ; - DUP 5 ; - CDR ; - DUP 13 ; - CDR ; - MUL ; - DIG 5 ; - CAR ; - DUP 13 ; - CAR ; - MUL ; - PAIR ; - PUSH int 1 ; - DIG 3 ; - PAIR ; - DUP 2 ; - CAR ; - DUP 2 ; - CDR ; - MUL ; - DIG 2 ; - CDR ; - DIG 2 ; - CAR ; - MUL ; - PAIR ; - PUSH int 1 ; - DIG 2 ; - PAIR ; - DUP 2 ; - CAR ; - DUP 2 ; - CDR ; - MUL ; - DUP 3 ; - CDR ; - DUP 3 ; - CAR ; - MUL ; - COMPARE ; - LE ; - IF { SWAP ; DROP } { DROP } ; - PUSH int 0 ; - DUP 4 ; - CAR ; - COMPARE ; - LT ; - IF { PUSH int -1 ; DUP 4 ; CDR ; MUL ; PUSH int -1 ; DUP 5 ; CAR ; MUL ; PAIR } - { DUP 3 } ; - DUP ; - CDR ; - PUSH nat 0 ; - PUSH nat 10 ; - PAIR ; - DUP 14 ; - SWAP ; - EXEC ; - DIG 2 ; - CAR ; - MUL ; - EDIV ; - IF_NONE { PUSH string "DIV by 0" ; FAILWITH } {} ; - CAR ; - ISNAT ; - IF_NONE { PUSH nat 119 ; FAILWITH } {} ; - PUSH int 0 ; - DUP 4 ; - CAR ; - COMPARE ; - LT ; - IF { PUSH int -1 ; DUP 4 ; CDR ; MUL ; PUSH int -1 ; DUP 5 ; CAR ; MUL ; PAIR } - { DUP 3 } ; - DUP ; - CDR ; - PUSH nat 0 ; - PUSH nat 10 ; - PAIR ; - DUP 15 ; - SWAP ; - EXEC ; - DIG 2 ; - CAR ; - MUL ; - EDIV ; - IF_NONE { PUSH string "DIV by 0" ; FAILWITH } {} ; - CAR ; - ISNAT ; - IF_NONE { PUSH nat 119 ; FAILWITH } {} ; - PUSH int 0 ; - DUP 4 ; - CAR ; - COMPARE ; - LT ; - IF { PUSH int -1 ; DUP 4 ; CDR ; MUL ; PUSH int -1 ; DUP 5 ; CAR ; MUL ; PAIR } - { DUP 3 } ; - DUP ; - CDR ; - PUSH nat 0 ; - PUSH nat 10 ; - PAIR ; - DUP 16 ; - SWAP ; - EXEC ; - DIG 2 ; - CAR ; - MUL ; - EDIV ; - IF_NONE { PUSH string "DIV by 0" ; FAILWITH } {} ; - CAR ; - ISNAT ; - IF_NONE { PUSH nat 119 ; FAILWITH } {} ; - DUP 4 ; - CAR ; - DUP 7 ; - CDR ; - MUL ; - DUP 5 ; - CDR ; - DUP 8 ; - CAR ; - MUL ; - COMPARE ; - LT ; - NOT ; - DUP 6 ; - CAR ; - DUP 8 ; - CDR ; - MUL ; - DUP 7 ; - CDR ; - DUP 9 ; - CAR ; - MUL ; - COMPARE ; - LT ; - NOT ; - AND ; - IF { DIG 3 ; DIG 4 ; DIG 5 ; DROP 3 ; UNIT ; RIGHT unit ; LEFT unit } - { DUP 4 ; - CAR ; - DUP 6 ; - CDR ; - MUL ; - DIG 4 ; - CDR ; - DUP 6 ; - CAR ; - MUL ; - COMPARE ; - LT ; - NOT ; - DUP 6 ; - CAR ; - DUP 6 ; - CDR ; - MUL ; - DIG 6 ; - CDR ; - DIG 6 ; - CAR ; - MUL ; - COMPARE ; - LT ; - NOT ; - AND ; - IF { UNIT ; LEFT unit ; LEFT unit } { UNIT ; RIGHT (or unit unit) } } ; - DUP 10 ; - PUSH nat 0 ; - PUSH nat 0 ; - PUSH nat 0 ; - PUSH nat 0 ; - PAIR 4 ; - DIG 2 ; - DIG 3 ; - DIG 4 ; - DIG 5 ; - PAIR 3 ; - PAIR 4 ; - DUP ; - GET 3 ; - IF_LEFT - { IF_LEFT - { DROP ; - DUP 2 ; - GET 3 ; - DUP 3 ; - CAR ; - ADD ; - DUP 3 ; - GET 13 ; - DIG 3 ; - GET 11 ; - ADD ; - SWAP } - { DROP ; - DUP 2 ; - GET 13 ; - DUP 3 ; - GET 11 ; - DUP 4 ; - GET 9 ; - ADD ; - ADD ; - DIG 2 ; - CAR } } - { DROP ; - DUP 2 ; - GET 5 ; - DUP 3 ; - GET 3 ; - DUP 4 ; - CAR ; - ADD ; - ADD ; - DIG 2 ; - GET 13 ; - SWAP } ; - DUP 3 ; - GET 3 ; - IF_LEFT - { IF_LEFT - { DIG 9 ; DROP 2 ; DUP 8 } - { DROP ; - DUP 8 ; - GET 3 ; - DUP 10 ; - CAR ; - DUP 2 ; - CDR ; - MUL ; - DIG 10 ; - CDR ; - DIG 2 ; - CAR ; - MUL ; - PAIR ; - DUP 9 ; - SWAP ; - UPDATE 3 } } - { DROP ; - DUP 8 ; - GET 3 ; - DUP 10 ; - CDR ; - DUP 2 ; - CDR ; - MUL ; - DIG 10 ; - CAR ; - DIG 2 ; - CAR ; - MUL ; - PAIR ; - DUP 9 ; - SWAP ; - UPDATE 3 } ; - DUP 4 ; - GET 3 ; - IF_LEFT - { IF_LEFT { DROP ; DUP 4 ; CAR ; GET 3 } { DROP ; DUP 4 ; CAR ; CAR } } - { DROP ; DUP 4 ; CAR ; GET 4 } ; - DUP 2 ; - GET 3 ; - DUP 2 ; - INT ; - PUSH int 1 ; - SWAP ; - PAIR ; - DUP 2 ; - CDR ; - DUP 2 ; - CDR ; - MUL ; - DIG 2 ; - 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 0 ; - PUSH nat 10 ; - PAIR ; - DIG 13 ; - SWAP ; - EXEC ; - DIG 2 ; - CAR ; - MUL ; - EDIV ; - IF_NONE { PUSH string "DIV by 0" ; FAILWITH } {} ; - CAR ; - ISNAT ; - IF_NONE { PUSH nat 119 ; FAILWITH } {} ; - DIG 5 ; - DIG 5 ; - DIG 2 ; - DIG 5 ; - DIG 4 ; - PAIR 4 ; - UPDATE 5 ; - SWAP ; - UPDATE 6 ; - DIG 2 ; - DIG 5 ; - DIG 2 ; - DIG 3 ; - PAIR ; - PAIR ; - LEFT (pair timestamp timestamp) ; - LEFT timestamp ; - UPDATE 3 ; - DUP 2 ; - DUP 3 ; - CDR ; - DUP 3 ; - SOME ; - DUP 4 ; - CAR ; - UPDATE ; - UPDATE 2 ; - DIG 2 ; - CAR ; - DUP 3 ; - CAR ; - SOME ; - DIG 3 ; - GET 7 ; - UNPAIR ; - DUP ; - DUP 3 ; - COMPARE ; - GT ; - IF { PUSH string "/" ; CONCAT ; SWAP ; CONCAT } - { SWAP ; PUSH string "/" ; CONCAT ; SWAP ; CONCAT } ; - UPDATE ; - UPDATE 1 } - { DIG 3 ; DIG 4 ; DIG 5 ; DROP 4 } ; - DUP 2 ; - DIG 2 ; - CAR ; - DUP ; - CAR ; - DUP ; - CAR ; - DIG 4 ; - UPDATE 2 ; - UPDATE 1 ; - UPDATE 1 ; - UPDATE 1 } ; - NIL operation ; - PAIR } } } } ; - view "get_fee_in_mutez" unit mutez { CDR ; CAR ; CAR ; CDR ; CDR } ; - view "get_valid_swaps" - unit - (map string - (pair (pair %swap (string %from) (string %to)) - (address %oracle_address) - (string %oracle_asset_name) - (nat %oracle_precision) - (bool %is_disabled_for_deposits))) - { CDR ; CDR ; CAR ; CDR ; CDR } ; - view "get_valid_tokens" - unit - (map string - (pair (nat %token_id) - (string %name) - (option %address address) - (nat %decimals) - (option %standard string))) - { CDR ; CDR ; CDR } ; - view "redeemable_holdings_available" - unit - bool - { CDR ; - SENDER ; - SWAP ; - CDR ; - CAR ; - CDR ; - CAR ; - SWAP ; - GET ; - IF_NONE - { PUSH bool False } - { PUSH bool False ; - SWAP ; - ITER { CDR ; - PUSH bool False ; - SWAP ; - ITER { CDR ; PUSH nat 0 ; SWAP ; COMPARE ; GT ; OR } ; - OR } } } ; - view "get_current_batches" - unit - (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) - (bool %market_vault_used))) - { CDR ; - NIL (pair nat - (or (or (pair (pair timestamp - (pair (pair nat nat nat) - (or (or unit unit) unit) - (pair nat nat nat nat) - (pair (pair string string) (pair int int) timestamp))) - (pair (pair string string) (pair int int) timestamp)) - (pair timestamp timestamp)) - timestamp) - (pair nat nat nat nat nat nat nat nat) - (pair string string) - nat - bool) ; - DUP 2 ; - CAR ; - CAR ; - CAR ; - CDR ; - CAR ; - ITER { CDR ; - DUP 3 ; - CAR ; - CAR ; - CAR ; - CDR ; - CDR ; - SWAP ; - GET ; - IF_NONE {} { CONS } } ; - SWAP ; - DROP } } - diff --git a/batcher/batcher-mainnet.tz b/batcher/batcher-mainnet.tz deleted file mode 100644 index 779c6c03..00000000 --- a/batcher/batcher-mainnet.tz +++ /dev/null @@ -1,4039 +0,0 @@ -{ parameter - (or (or (or (or (pair %add_or_update_metadata (string %key) (bytes %value)) - (pair %add_token_swap_pair - (pair %swap - (pair %from - (pair %token - (nat %token_id) - (string %name) - (option %address address) - (nat %decimals) - (option %standard string)) - (nat %amount)) - (pair %to - (nat %token_id) - (string %name) - (option %address address) - (nat %decimals) - (option %standard string))) - (address %oracle_address) - (string %oracle_asset_name) - (nat %oracle_precision) - (bool %is_disabled_for_deposits))) - (or (nat %amend_token_and_pair_limit) (address %change_admin_address))) - (or (or (nat %change_deposit_time_window) (mutez %change_fee)) - (or (pair %change_oracle_source_of_pair - (string %pair_name) - (address %oracle_address) - (string %oracle_asset_name) - (nat %oracle_precision)) - (nat %change_scale_factor)))) - (or (or (or (pair %deposit - (pair %swap - (pair %from - (pair %token - (nat %token_id) - (string %name) - (option %address address) - (nat %decimals) - (option %standard string)) - (nat %amount)) - (pair %to - (nat %token_id) - (string %name) - (option %address address) - (nat %decimals) - (option %standard string))) - (timestamp %created_at) - (nat %side) - (nat %tolerance)) - (string %disable_swap_pair_for_deposit)) - (or (string %enable_swap_pair_for_deposit) (unit %redeem))) - (or (or (string %remove_metadata) - (pair %remove_token_swap_pair - (pair %swap - (pair %from - (pair %token - (nat %token_id) - (string %name) - (option %address address) - (nat %decimals) - (option %standard string)) - (nat %amount)) - (pair %to - (nat %token_id) - (string %name) - (option %address address) - (nat %decimals) - (option %standard string))) - (address %oracle_address) - (string %oracle_asset_name) - (nat %oracle_precision) - (bool %is_disabled_for_deposits))) - (string %tick)))) ; - storage - (pair (pair (pair (pair (address %administrator) - (pair %batch_set - (map %current_batch_indices string nat) - (big_map %batches - nat - (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 %deposit_time_window_in_seconds) - (mutez %fee_in_mutez)) - (pair (address %fee_recipient) (nat %last_order_number)) - (nat %limit_on_tokens_or_pairs) - (big_map %metadata string bytes)) - (pair (pair (big_map %rates_current - string - (pair (pair %swap (string %from) (string %to)) - (pair %rate (int %p) (int %q)) - (timestamp %when))) - (nat %scale_factor_for_oracle_staleness)) - (big_map %user_batch_ordertypes - address - (map nat - (map (pair (or %side (unit %buy) (unit %sell)) - (or %tolerance (or (unit %exact) (unit %minus)) (unit %plus))) - nat))) - (map %valid_swaps - string - (pair (pair %swap (string %from) (string %to)) - (address %oracle_address) - (string %oracle_asset_name) - (nat %oracle_precision) - (bool %is_disabled_for_deposits)))) - (map %valid_tokens - string - (pair (nat %token_id) - (string %name) - (option %address address) - (nat %decimals) - (option %standard string)))) ; - code { LAMBDA - (pair nat nat) - nat - { UNPAIR ; - PUSH nat 1 ; - DUG 2 ; - 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 } } } ; - PUSH int 1 ; - PUSH int 10000 ; - PAIR ; - PUSH int 1 ; - PUSH int 10001 ; - PAIR ; - DUP 2 ; - CAR ; - DUP 2 ; - CDR ; - MUL ; - DIG 2 ; - CDR ; - DIG 2 ; - CAR ; - MUL ; - PAIR ; - LAMBDA - (pair (pair (pair nat string (option address) nat (option string)) nat) - (map string (pair (pair nat string (option address) nat (option string)) nat))) - (map string (pair (pair nat string (option address) nat (option string)) nat)) - { UNPAIR ; - SWAP ; - UNIT ; - RIGHT unit ; - DIG 2 ; - DUP ; - CAR ; - GET 3 ; - DUP 4 ; - DUP 2 ; - GET ; - IF_NONE - { DIG 2 ; DROP ; SWAP ; SOME ; SWAP ; UPDATE } - { DIG 3 ; - IF_LEFT - { DROP ; - DUP ; - CDR ; - DUP 4 ; - CDR ; - COMPARE ; - GT ; - IF { DROP ; PUSH nat 111 ; FAILWITH } - { DUP 3 ; CDR ; SWAP ; CDR ; SUB ; ABS } } - { DROP ; CDR ; DUP 3 ; CDR ; ADD } ; - DIG 3 ; - DIG 3 ; - DIG 2 ; - UPDATE 2 ; - SOME ; - DIG 2 ; - UPDATE } } ; - 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 4 ; - UNPAIR ; - IF_LEFT - { DIG 2 ; - DIG 3 ; - DIG 4 ; - DIG 5 ; - DROP 4 ; - IF_LEFT - { IF_LEFT - { IF_LEFT - { DUP 2 ; - CAR ; - CAR ; - CAR ; - CAR ; - SENDER ; - COMPARE ; - EQ ; - IF {} { PUSH nat 114 ; FAILWITH } ; - PUSH mutez 1 ; - AMOUNT ; - COMPARE ; - LT ; - IF {} { PUSH nat 118 ; FAILWITH } ; - DUP 2 ; - DUP 3 ; - CAR ; - DUP ; - CDR ; - DUP ; - CDR ; - DUP 6 ; - CAR ; - CDR ; - CDR ; - CDR ; - DUP 6 ; - CAR ; - GET ; - IF_NONE - { DIG 5 ; - CAR ; - CDR ; - CDR ; - CDR ; - DUP 6 ; - CDR ; - DIG 6 ; - CAR ; - SWAP ; - SOME ; - SWAP ; - UPDATE } - { DROP ; - DIG 5 ; - CAR ; - CDR ; - CDR ; - CDR ; - DUP 6 ; - CDR ; - SOME ; - DIG 6 ; - CAR ; - UPDATE } ; - UPDATE 2 ; - UPDATE 2 ; - UPDATE 2 ; - UPDATE 1 ; - NIL operation ; - PAIR } - { DUP 2 ; - CAR ; - CAR ; - CAR ; - CAR ; - SENDER ; - COMPARE ; - EQ ; - IF {} { PUSH nat 114 ; FAILWITH } ; - PUSH mutez 1 ; - AMOUNT ; - COMPARE ; - LT ; - IF {} { PUSH nat 118 ; FAILWITH } ; - PUSH nat 6 ; - DUP 2 ; - CAR ; - CAR ; - CAR ; - GET 7 ; - COMPARE ; - LT ; - IF { DROP 2 ; PUSH nat 134 ; FAILWITH } - { PUSH nat 6 ; - DUP 2 ; - CAR ; - CDR ; - GET 7 ; - COMPARE ; - LT ; - IF { DROP 2 ; PUSH nat 134 ; FAILWITH } - { PUSH nat 6 ; - DUP 2 ; - GET 7 ; - COMPARE ; - NEQ ; - IF { DROP 2 ; PUSH nat 133 ; FAILWITH } - { DUP 2 ; - CDR ; - CDR ; - DUP 3 ; - CDR ; - CAR ; - CDR ; - CDR ; - DUP 4 ; - CAR ; - CDR ; - CDR ; - CAR ; - DUP 4 ; - CAR ; - DUP ; - CAR ; - CAR ; - DUP 2 ; - CDR ; - DUP 4 ; - PUSH nat 1 ; - DUP 7 ; - SIZE ; - ADD ; - COMPARE ; - GT ; - IF { DIG 3 ; DROP ; PUSH nat 127 ; FAILWITH } - { PUSH bool False ; - DUP 7 ; - ITER { CDR ; - SWAP ; - DUP 2 ; - GET 8 ; - DUP 5 ; - GET 8 ; - COMPARE ; - EQ ; - DUP 3 ; - GET 7 ; - DUP 6 ; - GET 7 ; - COMPARE ; - EQ ; - DUP 4 ; - GET 5 ; - DUP 7 ; - GET 5 ; - COMPARE ; - EQ ; - DUP 5 ; - GET 3 ; - DUP 8 ; - GET 3 ; - COMPARE ; - EQ ; - DIG 5 ; - CAR ; - DUP 8 ; - CAR ; - COMPARE ; - EQ ; - AND ; - AND ; - AND ; - AND ; - OR } ; - PUSH bool False ; - DUP 8 ; - ITER { CDR ; - SWAP ; - DUP 2 ; - GET 8 ; - DUP 5 ; - GET 8 ; - COMPARE ; - EQ ; - DUP 3 ; - GET 7 ; - DUP 6 ; - GET 7 ; - COMPARE ; - EQ ; - DUP 4 ; - GET 5 ; - DUP 7 ; - GET 5 ; - COMPARE ; - EQ ; - DUP 5 ; - GET 3 ; - DUP 8 ; - GET 3 ; - COMPARE ; - EQ ; - DIG 5 ; - CAR ; - DUP 8 ; - CAR ; - COMPARE ; - EQ ; - AND ; - AND ; - AND ; - AND ; - OR } ; - AND ; - IF { PUSH nat 0 } - { PUSH bool False ; - DUP 7 ; - ITER { CDR ; - SWAP ; - DUP 2 ; - GET 8 ; - DUP 5 ; - GET 8 ; - COMPARE ; - EQ ; - DUP 3 ; - GET 7 ; - DUP 6 ; - GET 7 ; - COMPARE ; - EQ ; - DUP 4 ; - GET 5 ; - DUP 7 ; - GET 5 ; - COMPARE ; - EQ ; - DUP 5 ; - GET 3 ; - DUP 8 ; - GET 3 ; - COMPARE ; - EQ ; - DIG 5 ; - CAR ; - DUP 8 ; - CAR ; - COMPARE ; - EQ ; - AND ; - AND ; - AND ; - AND ; - OR } ; - PUSH bool False ; - DUP 8 ; - ITER { CDR ; - SWAP ; - DUP 2 ; - GET 8 ; - DUP 5 ; - GET 8 ; - COMPARE ; - EQ ; - DUP 3 ; - GET 7 ; - DUP 6 ; - GET 7 ; - COMPARE ; - EQ ; - DUP 4 ; - GET 5 ; - DUP 7 ; - GET 5 ; - COMPARE ; - EQ ; - DUP 5 ; - GET 3 ; - DUP 8 ; - GET 3 ; - COMPARE ; - EQ ; - DIG 5 ; - CAR ; - DUP 8 ; - CAR ; - COMPARE ; - EQ ; - AND ; - AND ; - AND ; - AND ; - OR } ; - OR ; - IF { PUSH nat 1 } { PUSH nat 2 } } ; - DIG 4 ; - SWAP ; - DUP 7 ; - SIZE ; - ADD ; - COMPARE ; - GT ; - IF { PUSH nat 126 ; FAILWITH } {} } ; - DUP 3 ; - CDR ; - GET 3 ; - DIG 3 ; - CAR ; - CAR ; - GET 3 ; - SWAP ; - DUP 5 ; - 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 - { DUP 4 ; - DUP 3 ; - GET 3 ; - GET ; - IF_NONE - { DIG 3 ; DUP 3 ; DIG 3 ; GET 3 ; SWAP ; SOME ; SWAP ; UPDATE } - { DUP 3 ; - GET 8 ; - DUP 2 ; - GET 8 ; - COMPARE ; - EQ ; - DUP 4 ; - GET 7 ; - DUP 3 ; - GET 7 ; - COMPARE ; - EQ ; - DUP 5 ; - GET 5 ; - DUP 4 ; - GET 5 ; - COMPARE ; - EQ ; - DUP 6 ; - GET 3 ; - DUP 5 ; - GET 3 ; - COMPARE ; - EQ ; - DIG 6 ; - CAR ; - DIG 5 ; - CAR ; - COMPARE ; - EQ ; - AND ; - AND ; - AND ; - AND ; - IF { DIG 2 } { DIG 2 ; DROP ; PUSH nat 115 ; FAILWITH } } ; - DUP ; - DUP 3 ; - GET 3 ; - GET ; - IF_NONE - { DUP 2 ; DIG 2 ; GET 3 ; SWAP ; SOME ; SWAP ; UPDATE } - { DUP 3 ; - GET 8 ; - DUP 2 ; - GET 8 ; - COMPARE ; - EQ ; - DUP 4 ; - GET 7 ; - DUP 3 ; - GET 7 ; - COMPARE ; - EQ ; - DUP 5 ; - GET 5 ; - DUP 4 ; - GET 5 ; - COMPARE ; - EQ ; - DUP 6 ; - GET 3 ; - DUP 5 ; - GET 3 ; - COMPARE ; - EQ ; - DIG 6 ; - CAR ; - DIG 5 ; - CAR ; - COMPARE ; - EQ ; - AND ; - AND ; - AND ; - AND ; - IF {} { DROP ; PUSH nat 115 ; FAILWITH } } ; - DUP 3 ; - CAR ; - DUP ; - CDR ; - GET 3 ; - SWAP ; - CAR ; - CAR ; - GET 3 ; - PAIR ; - SWAP ; - DIG 3 ; - DUP 5 ; - GET 8 ; - DUP 6 ; - GET 7 ; - DUP 7 ; - GET 5 ; - DUP 8 ; - GET 3 ; - DIG 8 ; - CAR ; - DUP ; - CDR ; - GET 3 ; - SWAP ; - CAR ; - CAR ; - GET 3 ; - PAIR ; - PAIR 5 ; - DUP 4 ; - DUP 4 ; - COMPARE ; - GT ; - IF { DIG 3 ; PUSH string "/" ; CONCAT ; DIG 3 ; CONCAT } - { DIG 2 ; PUSH string "/" ; CONCAT ; DIG 3 ; CONCAT } ; - SWAP ; - SOME ; - SWAP ; - UPDATE ; - PAIR } - { DROP 6 ; PUSH nat 116 ; FAILWITH } ; - UNPAIR ; - DUP 3 ; - DIG 3 ; - CDR ; - DUP ; - CAR ; - DUP ; - CDR ; - DIG 4 ; - UPDATE 2 ; - UPDATE 2 ; - UPDATE 1 ; - UPDATE 2 ; - DUP ; - CDR ; - DIG 2 ; - UPDATE 2 ; - UPDATE 2 ; - NIL operation ; - PAIR } } } } } - { IF_LEFT - { DUP 2 ; - CAR ; - CAR ; - 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 ; - SIZE ; - DUP 2 ; - COMPARE ; - LT ; - IF { DROP 2 ; PUSH nat 128 ; FAILWITH } - { DUP 2 ; - CDR ; - CAR ; - CDR ; - CDR ; - SIZE ; - DUP 2 ; - COMPARE ; - LT ; - IF { DROP 2 ; PUSH nat 129 ; FAILWITH } - { DUP 2 ; - DIG 2 ; - CAR ; - DUP ; - CDR ; - DUP ; - CDR ; - DIG 4 ; - UPDATE 1 ; - UPDATE 2 ; - UPDATE 2 ; - UPDATE 1 ; - NIL operation ; - PAIR } } } - { DUP 2 ; - CAR ; - CAR ; - 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 ; - DUP ; - CAR ; - DUP ; - CAR ; - DIG 4 ; - UPDATE 1 ; - UPDATE 1 ; - UPDATE 1 ; - UPDATE 1 ; - NIL operation ; - PAIR } } } - { IF_LEFT - { IF_LEFT - { DUP 2 ; - CAR ; - CAR ; - CAR ; - CAR ; - SENDER ; - COMPARE ; - EQ ; - IF {} { PUSH nat 114 ; FAILWITH } ; - PUSH mutez 1 ; - AMOUNT ; - COMPARE ; - LT ; - IF {} { PUSH nat 118 ; FAILWITH } ; - PUSH nat 600 ; - DUP 2 ; - COMPARE ; - LT ; - IF { DROP 2 ; PUSH nat 131 ; FAILWITH } - { PUSH nat 3600 ; - DUP 2 ; - COMPARE ; - GT ; - IF { DROP 2 ; PUSH nat 132 ; FAILWITH } - { DUP 2 ; - DIG 2 ; - CAR ; - DUP ; - CAR ; - DUP ; - CDR ; - DIG 4 ; - UPDATE 1 ; - UPDATE 2 ; - UPDATE 1 ; - UPDATE 1 ; - NIL operation ; - PAIR } } } - { DUP 2 ; - CAR ; - CAR ; - 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 ; - DUP ; - CAR ; - DUP ; - CDR ; - DIG 4 ; - UPDATE 2 ; - UPDATE 2 ; - UPDATE 1 ; - UPDATE 1 ; - NIL operation ; - PAIR } } - { IF_LEFT - { DUP 2 ; - CAR ; - CAR ; - CAR ; - CAR ; - SENDER ; - COMPARE ; - EQ ; - IF {} { PUSH nat 114 ; FAILWITH } ; - PUSH mutez 1 ; - AMOUNT ; - COMPARE ; - LT ; - IF {} { PUSH nat 118 ; FAILWITH } ; - DUP 2 ; - CDR ; - CAR ; - CDR ; - CDR ; - DUP 2 ; - CAR ; - GET ; - IF_NONE { PUSH nat 117 ; FAILWITH } {} ; - DUP ; - GET 3 ; - DUP 2 ; - GET 5 ; - VIEW "getPrice" (pair timestamp nat) ; - IF_NONE { PUSH nat 123 ; FAILWITH } { DROP } ; - DUP 3 ; - DUP 4 ; - CDR ; - DUP ; - CAR ; - DUP ; - CDR ; - DIG 6 ; - CDR ; - CAR ; - CDR ; - CDR ; - DIG 5 ; - DUP 7 ; - GET 3 ; - UPDATE 3 ; - DUP 7 ; - GET 5 ; - UPDATE 5 ; - DUP 7 ; - GET 6 ; - UPDATE 7 ; - SOME ; - DIG 6 ; - CAR ; - UPDATE ; - UPDATE 2 ; - UPDATE 2 ; - UPDATE 1 ; - UPDATE 2 ; - NIL operation ; - PAIR } - { DUP 2 ; - CAR ; - CAR ; - CAR ; - CAR ; - SENDER ; - COMPARE ; - EQ ; - IF {} { PUSH nat 114 ; FAILWITH } ; - PUSH mutez 1 ; - AMOUNT ; - COMPARE ; - LT ; - IF {} { PUSH nat 118 ; FAILWITH } ; - PUSH nat 1 ; - DUP 2 ; - COMPARE ; - LT ; - IF { DROP 2 ; PUSH nat 135 ; FAILWITH } - { PUSH nat 10 ; - DUP 2 ; - COMPARE ; - GT ; - IF { DROP 2 ; PUSH nat 136 ; FAILWITH } - { DUP 2 ; - DIG 2 ; - CDR ; - DUP ; - CAR ; - DUP ; - CAR ; - DIG 4 ; - UPDATE 2 ; - UPDATE 1 ; - UPDATE 1 ; - UPDATE 2 ; - NIL operation ; - PAIR } } } } } } - { IF_LEFT - { DIG 2 ; - DIG 4 ; - DROP 2 ; - IF_LEFT - { DIG 2 ; - DIG 3 ; - DROP 2 ; - IF_LEFT - { DUP ; - GET 5 ; - PUSH nat 0 ; - DUP 2 ; - COMPARE ; - EQ ; - IF { DROP ; UNIT ; LEFT unit } - { PUSH nat 1 ; - SWAP ; - COMPARE ; - EQ ; - IF { UNIT ; RIGHT unit } { PUSH nat 106 ; FAILWITH } } ; - DUP 3 ; - CDR ; - CDR ; - DUP 3 ; - CAR ; - DUP ; - CDR ; - GET 3 ; - SWAP ; - CAR ; - CAR ; - GET 3 ; - PAIR ; - DUP 2 ; - DUP 2 ; - CAR ; - DUP ; - CDR ; - GET 3 ; - SWAP ; - CAR ; - CAR ; - GET 3 ; - PAIR ; - SWAP ; - IF_LEFT { DROP } { DROP ; DUP ; CAR ; SWAP ; CDR ; PAIR } ; - NOW ; - DUP 4 ; - CDR ; - CAR ; - CDR ; - CDR ; - DUP 3 ; - UNPAIR ; - DUP ; - DUP 3 ; - COMPARE ; - GT ; - IF { PUSH string "/" ; CONCAT ; SWAP ; CONCAT } - { SWAP ; PUSH string "/" ; CONCAT ; SWAP ; CONCAT } ; - GET ; - IF_NONE { PUSH nat 117 ; FAILWITH } {} ; - DUP ; - GET 8 ; - IF { DROP 5 ; PUSH nat 125 ; FAILWITH } - { DUP 4 ; - CAR ; - DUP 5 ; - GET 5 ; - PUSH nat 0 ; - DUP 2 ; - COMPARE ; - EQ ; - IF { DROP ; UNIT ; LEFT unit } - { PUSH nat 1 ; - SWAP ; - COMPARE ; - EQ ; - IF { UNIT ; RIGHT unit } { PUSH nat 106 ; FAILWITH } } ; - IF_LEFT - { DROP ; - SWAP ; - CAR ; - CAR ; - CAR ; - GET 3 ; - SWAP ; - CAR ; - CAR ; - GET 3 ; - COMPARE ; - EQ ; - IF {} { PUSH nat 138 ; FAILWITH } } - { DROP ; - SWAP ; - CAR ; - CDR ; - GET 3 ; - SWAP ; - CAR ; - CAR ; - GET 3 ; - COMPARE ; - EQ ; - IF {} { PUSH nat 138 ; FAILWITH } } ; - DUP 4 ; - CAR ; - CAR ; - CDR ; - CDR ; - AMOUNT ; - DUP 2 ; - DUP 2 ; - COMPARE ; - LT ; - IF { DROP 6 ; PUSH nat 113 ; FAILWITH } - { COMPARE ; - GT ; - IF { DROP 4 ; PUSH nat 130 ; FAILWITH } - { DUP 4 ; - CAR ; - CAR ; - CAR ; - CDR ; - DUP ; - CDR ; - DUP 2 ; - CAR ; - DUP 5 ; - UNPAIR ; - DUP ; - DUP 3 ; - COMPARE ; - GT ; - IF { PUSH string "/" ; CONCAT ; SWAP ; CONCAT } - { SWAP ; PUSH string "/" ; CONCAT ; SWAP ; CONCAT } ; - GET ; - IF_NONE { PUSH nat 0 } {} ; - GET ; - IF_NONE - { PUSH nat 0 ; - DUP 2 ; - CAR ; - ITER { CDR ; DUP 2 ; DUP 2 ; COMPARE ; GT ; IF { SWAP ; DROP } { DROP } } ; - PUSH nat 1 ; - ADD ; - DUP 4 ; - PUSH nat 0 ; - PUSH nat 0 ; - PUSH nat 0 ; - PUSH nat 0 ; - PUSH nat 0 ; - PUSH nat 0 ; - PUSH nat 0 ; - PUSH nat 0 ; - PAIR 8 ; - DIG 4 ; - RIGHT - (or (pair (pair timestamp - (pair (pair nat nat nat) - (or (or unit unit) unit) - (pair nat nat nat nat) - (pair (pair string string) (pair int int) timestamp))) - (pair (pair string string) (pair int int) timestamp)) - (pair timestamp timestamp)) ; - DIG 3 ; - PAIR 4 ; - DUP 2 ; - DUP 3 ; - CDR ; - DUP 3 ; - SOME ; - DUP 4 ; - CAR ; - UPDATE ; - UPDATE 2 ; - DIG 2 ; - CAR ; - DUP 3 ; - CAR ; - SOME ; - DUP 4 ; - GET 6 ; - UNPAIR ; - DUP ; - DUP 3 ; - COMPARE ; - GT ; - IF { PUSH string "/" ; CONCAT ; SWAP ; CONCAT } - { SWAP ; PUSH string "/" ; CONCAT ; SWAP ; CONCAT } ; - UPDATE ; - UPDATE 1 } - { DUP 6 ; - CAR ; - CAR ; - CDR ; - CAR ; - DUP 2 ; - GET 3 ; - IF_LEFT - { SWAP ; - DROP ; - IF_LEFT - { DROP 2 ; - PUSH nat 0 ; - DUP 2 ; - CAR ; - ITER { CDR ; DUP 2 ; DUP 2 ; COMPARE ; GT ; IF { SWAP ; DROP } { DROP } } ; - PUSH nat 1 ; - ADD ; - DUP 4 ; - PUSH nat 0 ; - PUSH nat 0 ; - PUSH nat 0 ; - PUSH nat 0 ; - PUSH nat 0 ; - PUSH nat 0 ; - PUSH nat 0 ; - PUSH nat 0 ; - PAIR 8 ; - DIG 4 ; - RIGHT - (or (pair (pair timestamp - (pair (pair nat nat nat) - (or (or unit unit) unit) - (pair nat nat nat nat) - (pair (pair string string) (pair int int) timestamp))) - (pair (pair string string) (pair int int) timestamp)) - (pair timestamp timestamp)) ; - DIG 3 ; - PAIR 4 ; - DUP 2 ; - DUP 3 ; - CDR ; - DUP 3 ; - SOME ; - DUP 4 ; - CAR ; - UPDATE ; - UPDATE 2 ; - DIG 2 ; - CAR ; - DUP 3 ; - CAR ; - SOME ; - DUP 4 ; - GET 6 ; - UNPAIR ; - DUP ; - DUP 3 ; - COMPARE ; - GT ; - IF { PUSH string "/" ; CONCAT ; SWAP ; CONCAT } - { SWAP ; PUSH string "/" ; CONCAT ; SWAP ; CONCAT } ; - UPDATE ; - UPDATE 1 } - { DIG 3 ; DROP 2 ; SWAP } } - { DUP 2 ; - INT ; - ADD ; - DIG 4 ; - COMPARE ; - GE ; - IF { DUP 2 ; - GET 3 ; - IF_LEFT - { SWAP ; - DIG 2 ; - DROP 2 ; - IF_LEFT - { DROP ; PUSH nat 105 ; FAILWITH } - { DROP ; PUSH nat 105 ; FAILWITH } } - { SWAP ; - INT ; - DUP 2 ; - ADD ; - PAIR ; - RIGHT - (pair (pair timestamp - (pair (pair nat nat nat) - (or (or unit unit) unit) - (pair nat nat nat nat) - (pair (pair string string) (pair int int) timestamp))) - (pair (pair string string) (pair int int) timestamp)) ; - LEFT timestamp ; - UPDATE 3 } ; - DUP 2 ; - DUP 3 ; - CDR ; - DUP 3 ; - SOME ; - DUP 4 ; - CAR ; - UPDATE ; - UPDATE 2 ; - DIG 2 ; - CAR ; - DUP 3 ; - CAR ; - SOME ; - DUP 4 ; - GET 6 ; - UNPAIR ; - DUP ; - DUP 3 ; - COMPARE ; - GT ; - IF { PUSH string "/" ; CONCAT ; SWAP ; CONCAT } - { SWAP ; PUSH string "/" ; CONCAT ; SWAP ; CONCAT } ; - UPDATE ; - UPDATE 1 } - { DROP ; SWAP } } } ; - SWAP ; - DUP ; - GET 3 ; - IF_LEFT - { IF_LEFT { DROP ; PUSH bool False } { DROP ; PUSH bool False } } - { DROP ; PUSH bool True } ; - IF { DUP ; - GET 3 ; - IF_LEFT - { IF_LEFT { DROP ; PUSH bool False } { DROP ; PUSH bool False } } - { DROP ; PUSH bool True } ; - IF { DIG 2 ; DROP } - { DUP 5 ; - CDR ; - CAR ; - CDR ; - CDR ; - DIG 3 ; - UNPAIR ; - DUP ; - DUP 3 ; - COMPARE ; - GT ; - IF { PUSH string "/" ; CONCAT ; SWAP ; CONCAT } - { SWAP ; PUSH string "/" ; CONCAT ; SWAP ; CONCAT } ; - GET ; - IF_NONE { PUSH nat 117 ; FAILWITH } {} ; - DUP ; - GET 3 ; - SWAP ; - GET 5 ; - VIEW "getPrice" (pair timestamp nat) ; - IF_NONE { PUSH nat 124 ; FAILWITH } {} ; - CAR ; - DUP 5 ; - CAR ; - CAR ; - CDR ; - CAR ; - INT ; - DUP 6 ; - CDR ; - CAR ; - CAR ; - CDR ; - INT ; - MUL ; - NOW ; - SUB ; - COMPARE ; - LT ; - IF {} { PUSH nat 120 ; FAILWITH } } ; - DUP 4 ; - DIG 4 ; - CAR ; - DUP ; - CAR ; - DUP ; - CAR ; - DUP 6 ; - UPDATE 2 ; - UPDATE 1 ; - UPDATE 1 ; - UPDATE 1 ; - DUP 2 ; - CAR ; - PUSH nat 1 ; - DUP 3 ; - CAR ; - CDR ; - CAR ; - CDR ; - ADD ; - DUP 3 ; - CDR ; - CDR ; - DUP 7 ; - GET 5 ; - PUSH nat 0 ; - DUP 2 ; - COMPARE ; - EQ ; - IF { DROP ; UNIT ; LEFT unit } - { PUSH nat 1 ; - SWAP ; - COMPARE ; - EQ ; - IF { UNIT ; RIGHT unit } { PUSH nat 106 ; FAILWITH } } ; - DUP 8 ; - GET 6 ; - PUSH nat 0 ; - DUP 2 ; - COMPARE ; - EQ ; - IF { DROP ; UNIT ; RIGHT unit ; LEFT unit } - { PUSH nat 1 ; - DUP 2 ; - COMPARE ; - EQ ; - IF { DROP ; UNIT ; LEFT unit ; LEFT unit } - { PUSH nat 2 ; - SWAP ; - COMPARE ; - EQ ; - IF { UNIT ; RIGHT (or unit unit) } { PUSH nat 107 ; FAILWITH } } } ; - SENDER ; - DUP 10 ; - CAR ; - DUP ; - CAR ; - CAR ; - DUP 2 ; - CDR ; - DUP 7 ; - DUP 3 ; - GET 3 ; - GET ; - IF_NONE - { SWAP ; DIG 2 ; DIG 6 ; DROP 4 ; PUSH nat 110 ; FAILWITH } - { DIG 7 ; - DUP 3 ; - GET 3 ; - GET ; - IF_NONE - { DROP 5 ; PUSH nat 110 ; FAILWITH } - { DUP ; - GET 8 ; - DUP 4 ; - GET 8 ; - COMPARE ; - EQ ; - DUP 2 ; - GET 7 ; - DUP 5 ; - GET 7 ; - COMPARE ; - EQ ; - DUP 3 ; - GET 5 ; - DUP 6 ; - GET 5 ; - COMPARE ; - EQ ; - DUP 4 ; - GET 3 ; - DUP 7 ; - GET 3 ; - COMPARE ; - EQ ; - DIG 4 ; - CAR ; - DIG 6 ; - CAR ; - COMPARE ; - EQ ; - AND ; - AND ; - AND ; - AND ; - DUP 2 ; - GET 8 ; - DUP 4 ; - GET 8 ; - COMPARE ; - EQ ; - DUP 3 ; - GET 7 ; - DUP 5 ; - GET 7 ; - COMPARE ; - EQ ; - DUP 4 ; - GET 5 ; - DUP 6 ; - GET 5 ; - COMPARE ; - EQ ; - DUP 5 ; - GET 3 ; - DUP 7 ; - GET 3 ; - COMPARE ; - EQ ; - DIG 5 ; - CAR ; - DIG 6 ; - CAR ; - COMPARE ; - EQ ; - AND ; - AND ; - AND ; - AND ; - AND ; - IF { DUP ; - CDR ; - GET 3 ; - SWAP ; - CAR ; - CAR ; - GET 3 ; - PAIR ; - DUP 7 ; - CDR ; - GET 3 ; - SWAP ; - CAR ; - CAR ; - GET 3 ; - PAIR ; - DUP 2 ; - DUP 2 ; - CAR ; - GET ; - IF_NONE { PUSH nat 111 ; FAILWITH } {} ; - DUG 2 ; - CDR ; - GET ; - IF_NONE { PUSH nat 111 ; FAILWITH } {} ; - DUP 8 ; - CDR ; - DUP 5 ; - IF_LEFT { DROP ; SWAP } { DROP ; DUP 2 ; CAR ; DIG 2 ; CDR ; PAIR } ; - UNPAIR ; - DUP ; - DUP 3 ; - COMPARE ; - GT ; - IF { PUSH string "/" ; CONCAT ; SWAP ; CONCAT } - { SWAP ; PUSH string "/" ; CONCAT ; SWAP ; CONCAT } ; - MEM ; - IF {} { PUSH nat 110 ; FAILWITH } } - { DROP ; PUSH nat 110 ; FAILWITH } } } ; - PUSH bool False ; - DIG 2 ; - DIG 3 ; - DIG 9 ; - CAR ; - DIG 4 ; - DUP 7 ; - DUP 7 ; - PAIR 7 ; - DUP 4 ; - CDR ; - CAR ; - CDR ; - CAR ; - DUP 2 ; - GET 5 ; - GET ; - IF_NONE - { PUSH bool True } - { PUSH nat 0 ; - SWAP ; - ITER { CDR ; SIZE ; ADD } ; - PUSH nat 10 ; - SWAP ; - COMPARE ; - LE } ; - IF { DUP ; - GET 5 ; - DUP 5 ; - CDR ; - CAR ; - CDR ; - CAR ; - DUP 2 ; - GET ; - IF_NONE - { DUP 5 ; - CDR ; - CAR ; - CDR ; - CAR ; - EMPTY_MAP nat (map (pair (or unit unit) (or (or unit unit) unit)) nat) ; - EMPTY_MAP (pair (or unit unit) (or (or unit unit) unit)) nat ; - DUP 5 ; - GET 7 ; - CAR ; - CDR ; - DUP 6 ; - GET 11 ; - DUP 7 ; - GET 9 ; - PAIR ; - SWAP ; - SOME ; - SWAP ; - UPDATE ; - DUP 7 ; - SWAP ; - SOME ; - SWAP ; - UPDATE ; - DIG 2 ; - SWAP ; - SOME ; - SWAP ; - UPDATE } - { DUP ; - DUP 6 ; - GET ; - IF_NONE - { EMPTY_MAP (pair (or unit unit) (or (or unit unit) unit)) nat ; - DUP 4 ; - GET 7 ; - CAR ; - CDR ; - DUP 5 ; - GET 11 ; - DUP 6 ; - GET 9 ; - PAIR ; - SWAP ; - SOME ; - SWAP ; - UPDATE ; - DUP 6 ; - SWAP ; - SOME ; - SWAP ; - UPDATE } - { DUP 4 ; - GET 11 ; - DUP 5 ; - GET 9 ; - PAIR ; - DUP 2 ; - DUP 2 ; - GET ; - IF_NONE - { SWAP ; DUP 5 ; GET 7 ; CAR ; CDR ; DIG 2 ; SWAP ; SOME ; SWAP ; UPDATE } - { DUP 6 ; GET 7 ; CAR ; CDR ; ADD ; DIG 2 ; SWAP ; SOME ; DIG 2 ; UPDATE } ; - SOME ; - DUP 6 ; - UPDATE } ; - DUP 6 ; - CDR ; - CAR ; - CDR ; - CAR ; - SWAP ; - SOME ; - DIG 2 ; - UPDATE } ; - DUP 6 ; - GET 5 ; - DUP 3 ; - GET 9 ; - IF_LEFT - { DROP ; - DUP 3 ; - GET 7 ; - CAR ; - CDR ; - DUP 2 ; - GET 7 ; - ADD ; - DUP 4 ; - GET 11 ; - IF_LEFT - { IF_LEFT - { DROP ; - DUP 2 ; - DUP 5 ; - GET 7 ; - CAR ; - CDR ; - DIG 3 ; - GET 3 ; - ADD ; - UPDATE 3 ; - SWAP ; - UPDATE 7 } - { DROP ; - DUP 2 ; - DUP 5 ; - GET 7 ; - CAR ; - CDR ; - DIG 3 ; - CAR ; - ADD ; - UPDATE 1 ; - SWAP ; - UPDATE 7 } } - { DROP ; - DUP 2 ; - DUP 5 ; - GET 7 ; - CAR ; - CDR ; - DIG 3 ; - GET 5 ; - ADD ; - UPDATE 5 ; - SWAP ; - UPDATE 7 } } - { DROP ; - DUP 3 ; - GET 7 ; - CAR ; - CDR ; - DUP 2 ; - GET 14 ; - ADD ; - DUP 4 ; - GET 11 ; - IF_LEFT - { IF_LEFT - { DROP ; - DUP 2 ; - DUP 5 ; - GET 7 ; - CAR ; - CDR ; - DIG 3 ; - GET 11 ; - ADD ; - UPDATE 11 ; - SWAP ; - UPDATE 14 } - { DROP ; - DUP 2 ; - DUP 5 ; - GET 7 ; - CAR ; - CDR ; - DIG 3 ; - GET 9 ; - ADD ; - UPDATE 9 ; - SWAP ; - UPDATE 14 } } - { DROP ; - DUP 2 ; - DUP 5 ; - GET 7 ; - CAR ; - CDR ; - DIG 3 ; - GET 13 ; - ADD ; - UPDATE 13 ; - SWAP ; - UPDATE 14 } } ; - DUP 6 ; - DIG 6 ; - CAR ; - DUP ; - CAR ; - DUP ; - CAR ; - DUP 11 ; - DIG 11 ; - CDR ; - DIG 11 ; - DIG 7 ; - UPDATE 5 ; - SOME ; - DIG 10 ; - UPDATE ; - UPDATE 2 ; - UPDATE 2 ; - UPDATE 1 ; - UPDATE 1 ; - UPDATE 1 ; - DUP ; - CAR ; - DUP ; - CDR ; - DUP ; - CAR ; - DIG 6 ; - UPDATE 2 ; - UPDATE 1 ; - UPDATE 2 ; - UPDATE 1 ; - DUP 3 ; - GET 7 ; - CAR ; - SELF_ADDRESS ; - DUP 2 ; - CAR ; - GET 5 ; - IF_NONE - { SWAP ; DIG 4 ; DROP 3 ; PUSH nat 109 ; FAILWITH } - { DIG 5 ; - GET 5 ; - DUP 4 ; - CAR ; - GET 8 ; - IF_NONE - { DROP 4 ; PUSH nat 108 ; FAILWITH } - { PUSH string "FA1.2 token" ; - DUP 2 ; - COMPARE ; - EQ ; - IF { DROP ; - SWAP ; - CONTRACT %transfer (pair (address %from) (address %to) (nat %value)) ; - IF_NONE { PUSH nat 101 ; FAILWITH } {} ; - PUSH mutez 0 ; - DIG 4 ; - CDR ; - DIG 4 ; - DIG 4 ; - PAIR 3 ; - TRANSFER_TOKENS } - { PUSH string "FA2 token" ; - SWAP ; - COMPARE ; - EQ ; - IF { SWAP ; - CONTRACT %transfer - (list (pair (address %from_) (list %tx (pair (address %to_) (nat %token_id) (nat %amount))))) ; - IF_NONE { PUSH nat 101 ; FAILWITH } {} ; - PUSH mutez 0 ; - NIL (pair address (list (pair address nat nat))) ; - NIL (pair address nat nat) ; - DUP 7 ; - CDR ; - DIG 7 ; - CAR ; - CAR ; - DIG 7 ; - PAIR 3 ; - CONS ; - DIG 4 ; - PAIR ; - CONS ; - TRANSFER_TOKENS } - { DROP 4 ; PUSH nat 108 ; FAILWITH } } } } ; - DUP 2 ; - DIG 2 ; - CDR ; - DUP ; - CAR ; - DUP ; - CDR ; - DIG 5 ; - UPDATE 1 ; - UPDATE 2 ; - UPDATE 1 ; - UPDATE 2 ; - NIL operation ; - DIG 2 ; - CONS ; - PAIR } - { DROP 6 ; PUSH nat 112 ; FAILWITH } } - { DROP 5 ; PUSH nat 103 ; FAILWITH } } } } } - { DUP 2 ; - CAR ; - CAR ; - CAR ; - CAR ; - SENDER ; - COMPARE ; - EQ ; - IF {} { PUSH nat 114 ; FAILWITH } ; - PUSH mutez 1 ; - AMOUNT ; - COMPARE ; - LT ; - IF {} { PUSH nat 118 ; FAILWITH } ; - DUP 2 ; - CDR ; - CAR ; - CDR ; - CDR ; - DUP 2 ; - GET ; - IF_NONE { PUSH nat 117 ; FAILWITH } {} ; - DUP 3 ; - DUP 4 ; - CDR ; - DUP ; - CAR ; - DUP ; - CDR ; - DIG 6 ; - CDR ; - CAR ; - CDR ; - CDR ; - DIG 5 ; - PUSH bool True ; - UPDATE 8 ; - SOME ; - DIG 6 ; - UPDATE ; - UPDATE 2 ; - UPDATE 2 ; - UPDATE 1 ; - UPDATE 2 ; - NIL operation ; - PAIR } } - { IF_LEFT - { DIG 2 ; - DIG 3 ; - DROP 2 ; - DUP 2 ; - CAR ; - CAR ; - CAR ; - CAR ; - SENDER ; - COMPARE ; - EQ ; - IF {} { PUSH nat 114 ; FAILWITH } ; - PUSH mutez 1 ; - AMOUNT ; - COMPARE ; - LT ; - IF {} { PUSH nat 118 ; FAILWITH } ; - DUP 2 ; - CDR ; - CAR ; - CDR ; - CDR ; - DUP 2 ; - GET ; - IF_NONE { PUSH nat 117 ; FAILWITH } {} ; - DUP 3 ; - DUP 4 ; - CDR ; - DUP ; - CAR ; - DUP ; - CDR ; - DIG 6 ; - CDR ; - CAR ; - CDR ; - CDR ; - DIG 5 ; - PUSH bool False ; - UPDATE 8 ; - SOME ; - DIG 6 ; - UPDATE ; - UPDATE 2 ; - UPDATE 2 ; - UPDATE 1 ; - UPDATE 2 ; - NIL operation } - { DROP ; - SENDER ; - PUSH mutez 1 ; - AMOUNT ; - COMPARE ; - LT ; - IF {} { PUSH nat 118 ; FAILWITH } ; - SELF_ADDRESS ; - PUSH mutez 0 ; - PUSH mutez 0 ; - PAIR ; - DUP 3 ; - DUP 5 ; - CAR ; - CDR ; - CAR ; - CAR ; - PAIR ; - PAIR ; - DUP 4 ; - CDR ; - CAR ; - CDR ; - CAR ; - DUP ; - DUP 5 ; - GET ; - IF_NONE - { DIG 5 ; - DIG 6 ; - DROP 2 ; - EMPTY_MAP string (pair (pair nat string (option address) nat (option string)) nat) ; - SWAP } - { DUP 6 ; - CAR ; - CAR ; - CDR ; - CDR ; - DIG 3 ; - PAIR ; - DUP 6 ; - CDR ; - CDR ; - DUP 7 ; - CAR ; - CAR ; - CAR ; - CDR ; - PAIR ; - EMPTY_MAP string (pair (pair nat string (option address) nat (option string)) nat) ; - DUP 4 ; - PAIR ; - PAIR ; - PAIR ; - SWAP ; - ITER { SWAP ; - UNPAIR ; - UNPAIR ; - UNPAIR ; - DIG 2 ; - UNPAIR ; - DIG 4 ; - UNPAIR ; - DIG 6 ; - UNPAIR ; - DIG 4 ; - UNPAIR ; - DUP 3 ; - CDR ; - DUP 2 ; - GET ; - IF_NONE - { DROP 2 ; PAIR ; DUG 2 ; PAIR ; DIG 3 ; DIG 3 } - { DUP ; - GET 3 ; - IF_LEFT - { IF_LEFT - { CAR ; CDR ; SOME } - { DROP ; - NONE (pair (pair nat nat nat) - (or (or unit unit) unit) - (pair nat nat nat nat) - (pair (pair string string) (pair int int) timestamp)) } } - { DROP ; - NONE (pair (pair nat nat nat) - (or (or unit unit) unit) - (pair nat nat nat nat) - (pair (pair string string) (pair int int) timestamp)) } ; - IF_NONE - { DROP 3 ; PAIR ; DUG 2 ; PAIR ; DIG 3 ; DIG 3 } - { DUP 6 ; - DIG 5 ; - DUP 8 ; - DIG 3 ; - GET 5 ; - PAIR ; - DIG 9 ; - DIG 3 ; - PAIR ; - { DROP 3 ; PAIR ; DUG 2 } - { DUP 6 ; - DIG 2 ; - UNPAIR ; - UNPAIR ; - UNPAIR ; - DIG 2 ; - UNPAIR ; - DIG 4 ; - UNPAIR ; - DIG 6 ; - UNPAIR ; - PUSH nat 0 ; - DUP 4 ; - GET 7 ; - COMPARE ; - EQ ; - IF { PUSH bool False } - { PUSH nat 0 ; - DUP 4 ; - GET 14 ; - COMPARE ; - EQ ; - IF { PUSH bool False } - { DUP ; - CDR ; - DUP 8 ; - GET 3 ; - DUP 3 ; - CAR ; - IF_LEFT - { DROP ; - SWAP ; - IF_LEFT - { IF_LEFT - { DROP ; - IF_LEFT - { IF_LEFT { DROP ; PUSH bool True } { DROP ; PUSH bool False } } - { DROP ; PUSH bool True } } - { DROP ; - IF_LEFT - { IF_LEFT { DROP ; PUSH bool True } { DROP ; PUSH bool True } } - { DROP ; PUSH bool True } } } - { DROP ; - IF_LEFT - { IF_LEFT { DROP ; PUSH bool False } { DROP ; PUSH bool False } } - { DROP ; PUSH bool True } } } - { DROP ; - SWAP ; - IF_LEFT - { IF_LEFT - { DROP ; - IF_LEFT - { IF_LEFT { DROP ; PUSH bool True } { DROP ; PUSH bool True } } - { DROP ; PUSH bool False } } - { DROP ; - IF_LEFT - { IF_LEFT { DROP ; PUSH bool False } { DROP ; PUSH bool True } } - { DROP ; PUSH bool False } } } - { DROP ; - IF_LEFT - { IF_LEFT { DROP ; PUSH bool True } { DROP ; PUSH bool True } } - { DROP ; PUSH bool True } } } } } ; - IF { DUP 7 ; - GET 6 ; - CAR ; - DUP 7 ; - DUP 2 ; - CAR ; - GET ; - IF_NONE { PUSH nat 111 ; FAILWITH } {} ; - DUP 8 ; - DIG 2 ; - CDR ; - GET ; - IF_NONE { PUSH nat 111 ; FAILWITH } {} ; - DIG 2 ; - CAR ; - IF_LEFT - { DROP ; - DUP 8 ; - GET 5 ; - DUP ; - GET 5 ; - INT ; - SWAP ; - GET 3 ; - INT ; - DIG 4 ; - INT ; - PUSH int 1 ; - SWAP ; - PAIR ; - PUSH int 1 ; - DIG 2 ; - PAIR ; - DUP ; - CAR ; - DUP 3 ; - CDR ; - MUL ; - SWAP ; - CDR ; - DUP 3 ; - CAR ; - MUL ; - PAIR ; - PUSH int 1 ; - DIG 3 ; - PAIR ; - DUP ; - CDR ; - DUP 3 ; - CDR ; - MUL ; - SWAP ; - CAR ; - DIG 2 ; - CAR ; - MUL ; - PAIR ; - DUP 9 ; - GET 6 ; - GET 3 ; - DUP ; - CAR ; - DUP 3 ; - CDR ; - MUL ; - SWAP ; - CDR ; - DUP 3 ; - CAR ; - MUL ; - PAIR ; - DUP ; - CDR ; - DUP 4 ; - CDR ; - MUL ; - DUP 4 ; - CDR ; - DUP 3 ; - CAR ; - MUL ; - DIG 2 ; - CDR ; - DIG 4 ; - CAR ; - MUL ; - SUB ; - PAIR ; - PUSH int 0 ; - DUP 3 ; - CAR ; - COMPARE ; - LT ; - IF { PUSH int -1 ; DUP 3 ; CDR ; MUL ; PUSH int -1 ; DIG 3 ; CAR ; MUL ; PAIR } - { SWAP } ; - DUP ; - CDR ; - PUSH nat 0 ; - PUSH nat 10 ; - PAIR ; - DUP 23 ; - SWAP ; - EXEC ; - DIG 2 ; - CAR ; - MUL ; - EDIV ; - IF_NONE { PUSH string "DIV by 0" ; FAILWITH } {} ; - CAR ; - ISNAT ; - IF_NONE { PUSH nat 119 ; FAILWITH } {} ; - DIG 2 ; - PAIR ; - PUSH nat 0 ; - DUP 2 ; - CDR ; - COMPARE ; - GT ; - IF { DIG 8 ; SWAP ; PAIR ; DUP 18 ; SWAP ; EXEC } { DROP ; DIG 7 } ; - PUSH int 1 ; - PUSH int 0 ; - PAIR ; - DUP ; - CAR ; - DUP 4 ; - CDR ; - MUL ; - SWAP ; - CDR ; - DUP 4 ; - CAR ; - MUL ; - COMPARE ; - LE ; - NOT ; - IF { PUSH int 0 ; - DUP 3 ; - CAR ; - COMPARE ; - LT ; - IF { PUSH int -1 ; DUP 3 ; CDR ; MUL ; PUSH int -1 ; DIG 3 ; CAR ; MUL ; PAIR } - { SWAP } ; - DUP ; - CDR ; - PUSH nat 0 ; - PUSH nat 10 ; - PAIR ; - DUP 21 ; - SWAP ; - EXEC ; - DIG 2 ; - CAR ; - MUL ; - EDIV ; - IF_NONE { PUSH string "DIV by 0" ; FAILWITH } {} ; - CAR ; - ISNAT ; - IF_NONE { PUSH nat 119 ; FAILWITH } {} ; - DIG 2 ; - PAIR ; - PAIR ; - DUP 16 ; - SWAP ; - EXEC } - { SWAP ; DIG 2 ; DROP 2 } } - { DROP ; - DUP 8 ; - GET 5 ; - DUP ; - CAR ; - INT ; - SWAP ; - GET 6 ; - INT ; - DIG 4 ; - INT ; - PUSH int 1 ; - SWAP ; - PAIR ; - PUSH int 1 ; - DIG 2 ; - PAIR ; - DUP ; - CAR ; - DUP 3 ; - CDR ; - MUL ; - SWAP ; - CDR ; - DUP 3 ; - CAR ; - MUL ; - PAIR ; - PUSH int 1 ; - DIG 3 ; - PAIR ; - DUP ; - CDR ; - DUP 3 ; - CDR ; - MUL ; - SWAP ; - CAR ; - DIG 2 ; - CAR ; - MUL ; - PAIR ; - DUP 9 ; - GET 6 ; - GET 3 ; - DUP ; - CDR ; - DUP 3 ; - CDR ; - MUL ; - SWAP ; - CAR ; - DUP 3 ; - CAR ; - MUL ; - PAIR ; - DUP ; - CDR ; - DUP 4 ; - CDR ; - MUL ; - DUP 4 ; - CDR ; - DUP 3 ; - CAR ; - MUL ; - DIG 2 ; - CDR ; - DIG 4 ; - CAR ; - MUL ; - SUB ; - PAIR ; - PUSH int 0 ; - DUP 3 ; - CAR ; - COMPARE ; - LT ; - IF { PUSH int -1 ; DUP 3 ; CDR ; MUL ; PUSH int -1 ; DIG 3 ; CAR ; MUL ; PAIR } - { SWAP } ; - DUP ; - CDR ; - PUSH nat 0 ; - PUSH nat 10 ; - PAIR ; - DUP 23 ; - SWAP ; - EXEC ; - DIG 2 ; - CAR ; - MUL ; - EDIV ; - IF_NONE { PUSH string "DIV by 0" ; FAILWITH } {} ; - CAR ; - ISNAT ; - IF_NONE { PUSH nat 119 ; FAILWITH } {} ; - DIG 3 ; - PAIR ; - PUSH nat 0 ; - DUP 2 ; - CDR ; - COMPARE ; - GT ; - IF { DIG 8 ; SWAP ; PAIR ; DUP 18 ; SWAP ; EXEC } { DROP ; DIG 7 } ; - PUSH int 1 ; - PUSH int 0 ; - PAIR ; - DUP ; - CAR ; - DUP 4 ; - CDR ; - MUL ; - SWAP ; - CDR ; - DUP 4 ; - CAR ; - MUL ; - COMPARE ; - LE ; - NOT ; - IF { PUSH int 0 ; - DUP 3 ; - CAR ; - COMPARE ; - LT ; - IF { PUSH int -1 ; DUP 3 ; CDR ; MUL ; PUSH int -1 ; DIG 3 ; CAR ; MUL ; PAIR } - { SWAP } ; - DUP ; - CDR ; - PUSH nat 0 ; - PUSH nat 10 ; - PAIR ; - DUP 21 ; - SWAP ; - EXEC ; - DIG 2 ; - CAR ; - MUL ; - EDIV ; - IF_NONE { PUSH string "DIV by 0" ; FAILWITH } {} ; - CAR ; - ISNAT ; - IF_NONE { PUSH nat 119 ; FAILWITH } {} ; - DIG 2 ; - PAIR ; - PAIR ; - DUP 16 ; - SWAP ; - EXEC } - { SWAP ; DIG 2 ; DROP 2 } } ; - DUP 3 ; - DUP 3 ; - CDR ; - CAR ; - ADD ; - DUP 3 ; - DIG 3 ; - CDR ; - DIG 2 ; - UPDATE 1 ; - UPDATE 2 ; - SWAP } - { DUP 7 ; - GET 6 ; - CAR ; - SWAP ; - CAR ; - IF_LEFT - { DROP ; - DUP 6 ; - SWAP ; - CAR ; - GET ; - IF_NONE { PUSH nat 111 ; FAILWITH } {} } - { DROP ; - DUP 6 ; - SWAP ; - CDR ; - GET ; - IF_NONE { PUSH nat 111 ; FAILWITH } {} } ; - DUP 4 ; - DUP 4 ; - CDR ; - ADD ; - DUP 4 ; - DIG 4 ; - CDR ; - DIG 2 ; - UPDATE 2 ; - UPDATE 2 ; - DIG 7 ; - DIG 3 ; - DIG 3 ; - PAIR ; - PAIR ; - DUP 16 ; - DIG 5 ; - DUG 2 ; - PAIR ; - DIG 3 ; - DIG 3 ; - PAIR ; - DIG 2 ; - DIG 3 ; - PAIR ; - PAIR ; - PAIR } ; - UNPAIR ; - CAR ; - CDR ; - SWAP ; - CAR ; - DIG 3 ; - DIG 3 ; - PAIR ; - SWAP ; - PAIR ; - DIG 4 ; - DIG 4 ; - PAIR ; - DIG 2 ; - DIG 4 ; - DIG 4 ; - NONE (map (pair (or unit unit) (or (or unit unit) unit)) nat) ; - SWAP ; - UPDATE } } ; - PAIR ; - PAIR ; - PAIR } ; - DIG 5 ; - DIG 6 ; - DROP 2 ; - UNPAIR ; - CAR ; - UNPAIR ; - DIG 2 ; - CAR ; - DIG 2 ; - DIG 3 ; - DIG 3 ; - SOME ; - DUP 6 ; - UPDATE } ; - DIG 2 ; - NIL operation ; - DIG 3 ; - ITER { CDR ; - DUP ; - CAR ; - GET 5 ; - IF_NONE - { DROP ; PUSH nat 109 ; FAILWITH } - { DUP 2 ; - CAR ; - GET 8 ; - IF_NONE - { DROP 2 ; PUSH nat 108 ; FAILWITH } - { PUSH string "FA1.2 token" ; - DUP 2 ; - COMPARE ; - EQ ; - IF { DROP ; - CONTRACT %transfer (pair (address %from) (address %to) (nat %value)) ; - IF_NONE { PUSH nat 101 ; FAILWITH } {} ; - PUSH mutez 0 ; - DIG 2 ; - CDR ; - DUP 8 ; - DUP 8 ; - PAIR 3 ; - TRANSFER_TOKENS } - { PUSH string "FA2 token" ; - SWAP ; - COMPARE ; - EQ ; - IF { CONTRACT %transfer - (list (pair (address %from_) (list %tx (pair (address %to_) (nat %token_id) (nat %amount))))) ; - IF_NONE { PUSH nat 101 ; FAILWITH } {} ; - PUSH mutez 0 ; - NIL (pair address (list (pair address nat nat))) ; - NIL (pair address nat nat) ; - DUP 5 ; - CDR ; - DIG 5 ; - CAR ; - CAR ; - DUP 11 ; - PAIR 3 ; - CONS ; - DUP 8 ; - PAIR ; - CONS ; - TRANSFER_TOKENS } - { DROP 2 ; PUSH nat 108 ; FAILWITH } } } } ; - CONS } ; - DIG 3 ; - DIG 4 ; - DROP 2 ; - PUSH mutez 0 ; - DUP 3 ; - CDR ; - CDR ; - COMPARE ; - GT ; - IF { DUP 2 ; - CAR ; - CDR ; - CONTRACT unit ; - IF_NONE - { PUSH nat 102 ; FAILWITH } - { DUP 3 ; CDR ; CDR ; UNIT ; TRANSFER_TOKENS } ; - CONS } - {} ; - PUSH mutez 0 ; - DUP 3 ; - CDR ; - CAR ; - COMPARE ; - GT ; - IF { DUP 2 ; - CAR ; - CAR ; - CONTRACT unit ; - IF_NONE - { SWAP ; DROP ; PUSH nat 102 ; FAILWITH } - { DIG 2 ; CDR ; CAR ; UNIT ; TRANSFER_TOKENS } ; - CONS } - { SWAP ; DROP } ; - DUP 3 ; - DIG 3 ; - CDR ; - DUP ; - CAR ; - DUP ; - CDR ; - DIG 5 ; - UPDATE 1 ; - UPDATE 2 ; - UPDATE 1 ; - UPDATE 2 ; - SWAP } ; - PAIR } } - { DIG 3 ; - DROP ; - IF_LEFT - { DIG 2 ; - DIG 3 ; - DIG 4 ; - DROP 3 ; - IF_LEFT - { DUP 2 ; - CAR ; - CAR ; - CAR ; - CAR ; - SENDER ; - COMPARE ; - EQ ; - IF {} { PUSH nat 114 ; FAILWITH } ; - PUSH mutez 1 ; - AMOUNT ; - COMPARE ; - LT ; - IF {} { PUSH nat 118 ; FAILWITH } ; - DUP 2 ; - DUP 3 ; - CAR ; - DUP ; - CDR ; - DUP ; - CDR ; - DIG 5 ; - CAR ; - CDR ; - CDR ; - CDR ; - DIG 5 ; - NONE bytes ; - SWAP ; - UPDATE ; - UPDATE 2 ; - UPDATE 2 ; - UPDATE 2 ; - UPDATE 1 } - { DUP 2 ; - CAR ; - CAR ; - CAR ; - CAR ; - SENDER ; - COMPARE ; - EQ ; - IF {} { PUSH nat 114 ; FAILWITH } ; - PUSH mutez 1 ; - AMOUNT ; - COMPARE ; - LT ; - IF {} { PUSH nat 118 ; FAILWITH } ; - DUP ; - GET 8 ; - IF {} { PUSH nat 137 ; FAILWITH } ; - DUP 2 ; - CDR ; - CAR ; - CDR ; - CDR ; - DUP 2 ; - CAR ; - DUP ; - CDR ; - GET 3 ; - SWAP ; - CAR ; - CAR ; - GET 3 ; - PAIR ; - DUP 2 ; - DUP 2 ; - CAR ; - DIG 2 ; - CDR ; - DUP 2 ; - DUP 2 ; - COMPARE ; - GT ; - IF { SWAP ; PUSH string "/" ; CONCAT ; SWAP ; CONCAT } - { PUSH string "/" ; CONCAT ; SWAP ; CONCAT } ; - GET ; - IF_NONE - { DROP 2 ; PUSH nat 117 ; FAILWITH } - { DROP ; - DUP 3 ; - CDR ; - CDR ; - DIG 2 ; - CAR ; - DUP ; - CDR ; - GET 3 ; - SWAP ; - CAR ; - CAR ; - GET 3 ; - PAIR ; - DUP ; - CAR ; - DUP 2 ; - CDR ; - DIG 4 ; - DUP 3 ; - DUP 3 ; - COMPARE ; - 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) ; - SWAP ; - UPDATE ; - DUP 3 ; - DUP 3 ; - CAR ; - GET ; - IF_NONE { PUSH nat 111 ; FAILWITH } {} ; - DUP 4 ; - DIG 3 ; - CDR ; - GET ; - IF_NONE { PUSH nat 111 ; FAILWITH } {} ; - PUSH bool False ; - DUP 4 ; - ITER { CDR ; - CAR ; - DUP 6 ; - DUP 2 ; - CDR ; - GET ; - IF_NONE { PUSH nat 111 ; FAILWITH } {} ; - DUP 7 ; - DIG 2 ; - CAR ; - GET ; - IF_NONE { PUSH nat 111 ; FAILWITH } {} ; - DIG 2 ; - DUP 2 ; - GET 8 ; - DUP 6 ; - GET 8 ; - COMPARE ; - EQ ; - DUP 3 ; - GET 7 ; - DUP 7 ; - GET 7 ; - COMPARE ; - EQ ; - DUP 4 ; - GET 5 ; - DUP 8 ; - GET 5 ; - COMPARE ; - EQ ; - DUP 5 ; - GET 3 ; - DUP 9 ; - GET 3 ; - COMPARE ; - EQ ; - DIG 5 ; - CAR ; - DUP 9 ; - CAR ; - COMPARE ; - EQ ; - AND ; - AND ; - AND ; - AND ; - DUP 3 ; - GET 8 ; - DUP 6 ; - GET 8 ; - COMPARE ; - EQ ; - DUP 4 ; - GET 7 ; - DUP 7 ; - GET 7 ; - COMPARE ; - EQ ; - DUP 5 ; - GET 5 ; - DUP 8 ; - GET 5 ; - COMPARE ; - EQ ; - DUP 6 ; - GET 3 ; - DUP 9 ; - GET 3 ; - COMPARE ; - EQ ; - DIG 6 ; - CAR ; - DUP 9 ; - CAR ; - COMPARE ; - EQ ; - AND ; - AND ; - AND ; - AND ; - OR ; - OR } ; - IF { SWAP ; DROP ; DIG 2 } - { DUP 4 ; - DUP 3 ; - GET 3 ; - GET ; - IF_NONE - { SWAP ; DROP ; DIG 2 } - { DUP 3 ; - GET 8 ; - DUP 2 ; - GET 8 ; - COMPARE ; - EQ ; - DUP 4 ; - GET 7 ; - DUP 3 ; - GET 7 ; - COMPARE ; - EQ ; - DUP 5 ; - GET 5 ; - DUP 4 ; - GET 5 ; - COMPARE ; - EQ ; - DUP 6 ; - GET 3 ; - DUP 5 ; - GET 3 ; - COMPARE ; - EQ ; - DUP 7 ; - CAR ; - DIG 5 ; - CAR ; - COMPARE ; - EQ ; - AND ; - AND ; - AND ; - AND ; - IF { DIG 3 ; - DIG 2 ; - GET 3 ; - NONE (pair nat string (option address) nat (option string)) ; - SWAP ; - UPDATE } - { SWAP ; DIG 3 ; DROP 2 ; PUSH nat 115 ; FAILWITH } } } ; - PUSH bool False ; - DUP 4 ; - ITER { CDR ; - CAR ; - DUP 3 ; - DUP 2 ; - CDR ; - GET ; - IF_NONE { PUSH nat 111 ; FAILWITH } {} ; - DUP 4 ; - DIG 2 ; - CAR ; - GET ; - IF_NONE { PUSH nat 111 ; FAILWITH } {} ; - DIG 2 ; - DUP 2 ; - GET 8 ; - DUP 6 ; - GET 8 ; - COMPARE ; - EQ ; - DUP 3 ; - GET 7 ; - DUP 7 ; - GET 7 ; - COMPARE ; - EQ ; - DUP 4 ; - GET 5 ; - DUP 8 ; - GET 5 ; - COMPARE ; - EQ ; - DUP 5 ; - GET 3 ; - DUP 9 ; - GET 3 ; - COMPARE ; - EQ ; - DIG 5 ; - CAR ; - DUP 9 ; - CAR ; - COMPARE ; - EQ ; - AND ; - AND ; - AND ; - AND ; - DUP 3 ; - GET 8 ; - DUP 6 ; - GET 8 ; - COMPARE ; - EQ ; - DUP 4 ; - GET 7 ; - DUP 7 ; - GET 7 ; - COMPARE ; - EQ ; - DUP 5 ; - GET 5 ; - DUP 8 ; - GET 5 ; - COMPARE ; - EQ ; - DUP 6 ; - GET 3 ; - DUP 9 ; - GET 3 ; - COMPARE ; - EQ ; - DIG 6 ; - CAR ; - DUP 9 ; - CAR ; - COMPARE ; - EQ ; - AND ; - AND ; - AND ; - AND ; - OR ; - OR } ; - IF { SWAP ; DROP } - { DUP ; - DUP 3 ; - GET 3 ; - GET ; - IF_NONE - { SWAP ; DROP } - { DUP 3 ; - GET 8 ; - DUP 2 ; - GET 8 ; - COMPARE ; - EQ ; - DUP 4 ; - GET 7 ; - DUP 3 ; - GET 7 ; - COMPARE ; - EQ ; - DUP 5 ; - GET 5 ; - DUP 4 ; - GET 5 ; - COMPARE ; - EQ ; - DUP 6 ; - GET 3 ; - DUP 5 ; - GET 3 ; - COMPARE ; - EQ ; - DUP 7 ; - CAR ; - DIG 5 ; - CAR ; - COMPARE ; - EQ ; - AND ; - AND ; - AND ; - AND ; - IF { SWAP ; - GET 3 ; - NONE (pair nat string (option address) nat (option string)) ; - SWAP ; - UPDATE } - { DROP 2 ; PUSH nat 115 ; FAILWITH } } } ; - SWAP ; - PAIR } ; - UNPAIR ; - DUP 3 ; - DIG 3 ; - CDR ; - DUP ; - CAR ; - DUP ; - CDR ; - DIG 4 ; - UPDATE 2 ; - UPDATE 2 ; - UPDATE 1 ; - UPDATE 2 ; - DUP ; - CDR ; - DIG 2 ; - UPDATE 2 ; - UPDATE 2 } ; - NIL operation ; - PAIR } - { PUSH mutez 1 ; - AMOUNT ; - COMPARE ; - LT ; - IF {} { PUSH nat 118 ; FAILWITH } ; - DUP 2 ; - CDR ; - CAR ; - CDR ; - CDR ; - DUP 2 ; - GET ; - IF_NONE - { DROP 5 ; PUSH nat 117 ; FAILWITH } - { DUP 3 ; - CDR ; - CDR ; - DUP 2 ; - CAR ; - DUP 2 ; - DUP 2 ; - CAR ; - GET ; - IF_NONE { PUSH nat 111 ; FAILWITH } {} ; - DUG 2 ; - CDR ; - GET ; - IF_NONE { PUSH nat 111 ; FAILWITH } {} ; - DUP 3 ; - GET 8 ; - DUP 4 ; - GET 7 ; - DUP 5 ; - GET 5 ; - DIG 5 ; - GET 3 ; - DIG 4 ; - PUSH nat 1 ; - DIG 6 ; - PAIR ; - PAIR ; - PAIR 5 ; - DUP ; - GET 8 ; - DUP 2 ; - GET 7 ; - DUP 3 ; - GET 5 ; - DUP 4 ; - GET 3 ; - DUP 5 ; - CAR ; - DUP ; - CDR ; - GET 3 ; - SWAP ; - CAR ; - CAR ; - GET 3 ; - PAIR ; - PAIR 5 ; - DUP ; - GET 3 ; - SWAP ; - GET 5 ; - VIEW "getPrice" (pair timestamp nat) ; - IF_NONE { PUSH nat 122 ; FAILWITH } {} ; - UNPAIR ; - DUP 5 ; - CDR ; - CAR ; - CAR ; - CAR ; - DUP 5 ; - GET ; - IF_NONE - {} - { DUP 2 ; - SWAP ; - GET 4 ; - COMPARE ; - GE ; - IF { PUSH nat 121 ; FAILWITH } {} } ; - DUP 5 ; - CAR ; - CAR ; - CDR ; - CAR ; - INT ; - DUP 6 ; - CDR ; - CAR ; - CAR ; - CDR ; - INT ; - DUP 3 ; - DUG 2 ; - MUL ; - NOW ; - SUB ; - COMPARE ; - LT ; - IF {} { PUSH nat 120 ; FAILWITH } ; - DUP 5 ; - CDR ; - CDR ; - DUP 4 ; - CAR ; - DIG 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 8 ; - SWAP ; - EXEC ; - DIG 4 ; - MUL ; - ISNAT ; - IF_NONE { PUSH nat 119 ; FAILWITH } {} ; - DUP 2 ; - CAR ; - CAR ; - GET 7 ; - INT ; - PUSH int 10 ; - PAIR ; - DUP 8 ; - SWAP ; - EXEC ; - SWAP } - { INT ; PUSH int 10 ; PAIR ; DUP 8 ; SWAP ; EXEC ; DIG 4 } ; - 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 3 ; - SWAP ; - DUP 3 ; - CDR ; - GET 3 ; - DIG 3 ; - CAR ; - CAR ; - GET 3 ; - PAIR ; - PAIR 3 ; - DUP 3 ; - CDR ; - CDR ; - DUP 2 ; - CAR ; - DUP 2 ; - DUP 2 ; - CAR ; - GET ; - IF_NONE { PUSH nat 111 ; FAILWITH } {} ; - DUG 2 ; - CDR ; - GET ; - IF_NONE { PUSH nat 111 ; FAILWITH } {} ; - SWAP ; - GET 7 ; - SWAP ; - GET 7 ; - SUB ; - DUP ; - ABS ; - INT ; - PUSH int 10 ; - PAIR ; - DIG 5 ; - 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 ; - DUP 3 ; - CDR ; - CAR ; - CAR ; - CAR ; - DUP 4 ; - DIG 4 ; - CDR ; - DUP ; - CAR ; - DUP ; - CAR ; - DUP 5 ; - DUP 8 ; - GET ; - IF_NONE - { DIG 4 ; DUP 6 ; DIG 7 ; SWAP ; SOME ; SWAP ; UPDATE } - { GET 4 ; - DUP 7 ; - GET 4 ; - COMPARE ; - GT ; - IF { DIG 4 ; DUP 6 ; SOME ; DIG 7 ; UPDATE } { DIG 6 ; DROP ; DIG 4 } } ; - UPDATE 1 ; - UPDATE 1 ; - UPDATE 1 ; - UPDATE 2 ; - DUP ; - CDR ; - CDR ; - DUP 3 ; - CAR ; - UNIT ; - LEFT unit ; - IF_LEFT { DROP } { DROP ; DUP ; CAR ; SWAP ; CDR ; PAIR } ; - NOW ; - DUP 3 ; - CAR ; - CAR ; - CAR ; - CDR ; - CDR ; - DUP 4 ; - CAR ; - CAR ; - CAR ; - CDR ; - CAR ; - DUP 6 ; - UNPAIR ; - DUP ; - DUP 3 ; - COMPARE ; - GT ; - IF { PUSH string "/" ; CONCAT ; SWAP ; CONCAT } - { SWAP ; PUSH string "/" ; CONCAT ; SWAP ; CONCAT } ; - GET ; - IF_NONE { PUSH nat 0 } {} ; - GET ; - IF_NONE - { SWAP ; - DROP ; - DUP 2 ; - CAR ; - CAR ; - CAR ; - CDR ; - NONE (pair nat - (or (or (pair (pair timestamp - (pair (pair nat nat nat) - (or (or unit unit) unit) - (pair nat nat nat nat) - (pair (pair string string) (pair int int) timestamp))) - (pair (pair string string) (pair int int) timestamp)) - (pair timestamp timestamp)) - timestamp) - (pair nat nat nat nat nat nat nat nat) - (pair string string)) } - { DUP 4 ; - CAR ; - CAR ; - CAR ; - CDR ; - DUP 5 ; - CAR ; - CAR ; - CDR ; - CAR ; - DUP 3 ; - GET 3 ; - IF_LEFT - { SWAP ; - DROP ; - IF_LEFT - { DIG 2 ; - DROP 2 ; - PUSH nat 0 ; - DUP 2 ; - CAR ; - ITER { CDR ; DUP 2 ; DUP 2 ; COMPARE ; GT ; IF { SWAP ; DROP } { DROP } } ; - PUSH nat 1 ; - ADD ; - DIG 3 ; - PUSH nat 0 ; - PUSH nat 0 ; - PUSH nat 0 ; - PUSH nat 0 ; - PUSH nat 0 ; - PUSH nat 0 ; - PUSH nat 0 ; - PUSH nat 0 ; - PAIR 8 ; - DUP 5 ; - RIGHT - (or (pair (pair timestamp - (pair (pair nat nat nat) - (or (or unit unit) unit) - (pair nat nat nat nat) - (pair (pair string string) (pair int int) timestamp))) - (pair (pair string string) (pair int int) timestamp)) - (pair timestamp timestamp)) ; - DIG 3 ; - PAIR 4 ; - DUP 2 ; - DUP 3 ; - CDR ; - DUP 3 ; - SOME ; - DUP 4 ; - CAR ; - UPDATE ; - UPDATE 2 ; - DIG 2 ; - CAR ; - DUP 3 ; - CAR ; - SOME ; - DUP 4 ; - GET 6 ; - UNPAIR ; - DUP ; - DUP 3 ; - COMPARE ; - GT ; - IF { PUSH string "/" ; CONCAT ; SWAP ; CONCAT } - { SWAP ; PUSH string "/" ; CONCAT ; SWAP ; CONCAT } ; - UPDATE ; - UPDATE 1 } - { DIG 4 ; DROP 2 } } - { DIG 5 ; - DROP ; - DUP 2 ; - INT ; - ADD ; - DUP 5 ; - COMPARE ; - GE ; - IF { DUP 3 ; - GET 3 ; - IF_LEFT - { SWAP ; - DIG 3 ; - DROP 2 ; - IF_LEFT - { DROP ; PUSH nat 105 ; FAILWITH } - { DROP ; PUSH nat 105 ; FAILWITH } } - { SWAP ; - INT ; - DUP 2 ; - ADD ; - PAIR ; - RIGHT - (pair (pair timestamp - (pair (pair nat nat nat) - (or (or unit unit) unit) - (pair nat nat nat nat) - (pair (pair string string) (pair int int) timestamp))) - (pair (pair string string) (pair int int) timestamp)) ; - LEFT timestamp ; - DIG 2 ; - SWAP ; - UPDATE 3 } ; - DUP 2 ; - DUP 3 ; - CDR ; - DUP 3 ; - SOME ; - DUP 4 ; - CAR ; - UPDATE ; - UPDATE 2 ; - DIG 2 ; - CAR ; - DUP 3 ; - CAR ; - SOME ; - DUP 4 ; - GET 6 ; - UNPAIR ; - DUP ; - DUP 3 ; - COMPARE ; - GT ; - IF { PUSH string "/" ; CONCAT ; SWAP ; CONCAT } - { SWAP ; PUSH string "/" ; CONCAT ; SWAP ; CONCAT } ; - UPDATE ; - UPDATE 1 } - { DROP } } ; - SWAP ; - SOME } ; - IF_NONE - { SWAP ; DIG 3 ; DIG 4 ; DIG 5 ; DROP 5 } - { DUP ; - GET 3 ; - IF_LEFT - { IF_LEFT - { DIG 3 ; DROP 2 ; PUSH bool False } - { CAR ; PUSH int 120 ; ADD ; DIG 3 ; COMPARE ; GT } } - { DIG 3 ; DROP 2 ; PUSH bool False } ; - IF { NOW ; - DUP 2 ; - GET 5 ; - DUP ; - GET 9 ; - INT ; - DUP 2 ; - GET 11 ; - INT ; - DUP 3 ; - GET 13 ; - INT ; - DUP 4 ; - CAR ; - INT ; - DUP 5 ; - GET 3 ; - INT ; - DUP 6 ; - GET 5 ; - INT ; - DIG 3 ; - DIG 4 ; - DIG 5 ; - PAIR ; - PAIR ; - SWAP ; - DIG 2 ; - DIG 3 ; - PAIR ; - PAIR ; - DUP 8 ; - GET 3 ; - DUP 2 ; - CAR ; - CAR ; - DUP 4 ; - UNPAIR ; - UNPAIR ; - DUP 5 ; - DUP 15 ; - DIG 4 ; - DIG 4 ; - DIG 4 ; - ADD ; - ADD ; - PUSH int 1 ; - SWAP ; - PAIR ; - DUP 2 ; - CDR ; - DUP 2 ; - CDR ; - MUL ; - DIG 2 ; - CAR ; - DIG 2 ; - CAR ; - MUL ; - PAIR ; - DUP 2 ; - CAR ; - DUP 2 ; - CDR ; - MUL ; - DIG 2 ; - CDR ; - DIG 2 ; - CAR ; - MUL ; - PAIR ; - PUSH int 1 ; - DIG 2 ; - PAIR ; - DUP 2 ; - CAR ; - DUP 2 ; - CDR ; - MUL ; - DUP 3 ; - CDR ; - DUP 3 ; - CAR ; - MUL ; - COMPARE ; - LE ; - IF { SWAP ; DROP } { DROP } ; - DUP 3 ; - CAR ; - UNPAIR ; - DUP 6 ; - UNPAIR ; - CDR ; - DIG 3 ; - DIG 3 ; - ADD ; - DUP 5 ; - DIG 3 ; - DIG 3 ; - ADD ; - PUSH int 1 ; - SWAP ; - PAIR ; - DUP 2 ; - CAR ; - DUP 2 ; - CDR ; - MUL ; - DIG 2 ; - CDR ; - DIG 2 ; - CAR ; - MUL ; - PAIR ; - PUSH int 1 ; - DIG 2 ; - PAIR ; - DUP 2 ; - CAR ; - DUP 2 ; - CDR ; - MUL ; - DUP 3 ; - CDR ; - DUP 3 ; - CAR ; - MUL ; - COMPARE ; - LE ; - IF { SWAP ; DROP } { DROP } ; - DIG 3 ; - UNPAIR ; - UNPAIR ; - DIG 6 ; - CDR ; - DUG 3 ; - ADD ; - ADD ; - DUP 5 ; - CDR ; - DUP 13 ; - CDR ; - MUL ; - DIG 5 ; - CAR ; - DUP 13 ; - CAR ; - MUL ; - PAIR ; - PUSH int 1 ; - DIG 3 ; - PAIR ; - DUP 2 ; - CAR ; - DUP 2 ; - CDR ; - MUL ; - DIG 2 ; - CDR ; - DIG 2 ; - CAR ; - MUL ; - PAIR ; - PUSH int 1 ; - DIG 2 ; - PAIR ; - DUP 2 ; - CAR ; - DUP 2 ; - CDR ; - MUL ; - DUP 3 ; - CDR ; - DUP 3 ; - CAR ; - MUL ; - COMPARE ; - LE ; - IF { SWAP ; DROP } { DROP } ; - PUSH int 0 ; - DUP 4 ; - CAR ; - COMPARE ; - LT ; - IF { PUSH int -1 ; DUP 4 ; CDR ; MUL ; PUSH int -1 ; DUP 5 ; CAR ; MUL ; PAIR } - { DUP 3 } ; - DUP ; - CDR ; - PUSH nat 0 ; - PUSH nat 10 ; - PAIR ; - DUP 14 ; - SWAP ; - EXEC ; - DIG 2 ; - CAR ; - MUL ; - EDIV ; - IF_NONE { PUSH string "DIV by 0" ; FAILWITH } {} ; - CAR ; - ISNAT ; - IF_NONE { PUSH nat 119 ; FAILWITH } {} ; - PUSH int 0 ; - DUP 4 ; - CAR ; - COMPARE ; - LT ; - IF { PUSH int -1 ; DUP 4 ; CDR ; MUL ; PUSH int -1 ; DUP 5 ; CAR ; MUL ; PAIR } - { DUP 3 } ; - DUP ; - CDR ; - PUSH nat 0 ; - PUSH nat 10 ; - PAIR ; - DUP 15 ; - SWAP ; - EXEC ; - DIG 2 ; - CAR ; - MUL ; - EDIV ; - IF_NONE { PUSH string "DIV by 0" ; FAILWITH } {} ; - CAR ; - ISNAT ; - IF_NONE { PUSH nat 119 ; FAILWITH } {} ; - PUSH int 0 ; - DUP 4 ; - CAR ; - COMPARE ; - LT ; - IF { PUSH int -1 ; DUP 4 ; CDR ; MUL ; PUSH int -1 ; DUP 5 ; CAR ; MUL ; PAIR } - { DUP 3 } ; - DUP ; - CDR ; - PUSH nat 0 ; - PUSH nat 10 ; - PAIR ; - DUP 16 ; - SWAP ; - EXEC ; - DIG 2 ; - CAR ; - MUL ; - EDIV ; - IF_NONE { PUSH string "DIV by 0" ; FAILWITH } {} ; - CAR ; - ISNAT ; - IF_NONE { PUSH nat 119 ; FAILWITH } {} ; - DUP 4 ; - CAR ; - DUP 7 ; - CDR ; - MUL ; - DUP 5 ; - CDR ; - DUP 8 ; - CAR ; - MUL ; - COMPARE ; - LT ; - NOT ; - DUP 6 ; - CAR ; - DUP 8 ; - CDR ; - MUL ; - DUP 7 ; - CDR ; - DUP 9 ; - CAR ; - MUL ; - COMPARE ; - LT ; - NOT ; - AND ; - IF { DIG 3 ; DIG 4 ; DIG 5 ; DROP 3 ; UNIT ; RIGHT unit ; LEFT unit } - { DUP 4 ; - CAR ; - DUP 6 ; - CDR ; - MUL ; - DIG 4 ; - CDR ; - DUP 6 ; - CAR ; - MUL ; - COMPARE ; - LT ; - NOT ; - DUP 6 ; - CAR ; - DUP 6 ; - CDR ; - MUL ; - DIG 6 ; - CDR ; - DIG 6 ; - CAR ; - MUL ; - COMPARE ; - LT ; - NOT ; - AND ; - IF { UNIT ; LEFT unit ; LEFT unit } { UNIT ; RIGHT (or unit unit) } } ; - DUP 10 ; - PUSH nat 0 ; - PUSH nat 0 ; - PUSH nat 0 ; - PUSH nat 0 ; - PAIR 4 ; - DIG 2 ; - DIG 3 ; - DIG 4 ; - DIG 5 ; - PAIR 3 ; - PAIR 4 ; - DUP ; - GET 3 ; - IF_LEFT - { IF_LEFT - { DROP ; - DUP 2 ; - GET 3 ; - DUP 3 ; - CAR ; - ADD ; - DUP 3 ; - GET 13 ; - DIG 3 ; - GET 11 ; - ADD ; - SWAP } - { DROP ; - DUP 2 ; - GET 13 ; - DUP 3 ; - GET 11 ; - DUP 4 ; - GET 9 ; - ADD ; - ADD ; - DIG 2 ; - CAR } } - { DROP ; - DUP 2 ; - GET 5 ; - DUP 3 ; - GET 3 ; - DUP 4 ; - CAR ; - ADD ; - ADD ; - DIG 2 ; - GET 13 ; - SWAP } ; - DUP 3 ; - GET 3 ; - IF_LEFT - { IF_LEFT - { DIG 9 ; DROP 2 ; DUP 8 } - { DROP ; - DUP 8 ; - GET 3 ; - DUP 10 ; - CAR ; - DUP 2 ; - CDR ; - MUL ; - DIG 10 ; - CDR ; - DIG 2 ; - CAR ; - MUL ; - PAIR ; - DUP 9 ; - SWAP ; - UPDATE 3 } } - { DROP ; - DUP 8 ; - GET 3 ; - DUP 10 ; - CDR ; - DUP 2 ; - CDR ; - MUL ; - DIG 10 ; - CAR ; - DIG 2 ; - CAR ; - MUL ; - PAIR ; - DUP 9 ; - SWAP ; - UPDATE 3 } ; - DUP 4 ; - GET 3 ; - IF_LEFT - { IF_LEFT { DROP ; DUP 4 ; CAR ; GET 3 } { DROP ; DUP 4 ; CAR ; CAR } } - { DROP ; DUP 4 ; CAR ; GET 4 } ; - DUP 2 ; - GET 3 ; - DUP 2 ; - INT ; - PUSH int 1 ; - SWAP ; - PAIR ; - DUP 2 ; - CDR ; - DUP 2 ; - CDR ; - MUL ; - DIG 2 ; - 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 0 ; - PUSH nat 10 ; - PAIR ; - DIG 13 ; - SWAP ; - EXEC ; - DIG 2 ; - CAR ; - MUL ; - EDIV ; - IF_NONE { PUSH string "DIV by 0" ; FAILWITH } {} ; - CAR ; - ISNAT ; - IF_NONE { PUSH nat 119 ; FAILWITH } {} ; - DIG 5 ; - DIG 5 ; - DIG 2 ; - DIG 5 ; - DIG 4 ; - PAIR 4 ; - UPDATE 5 ; - SWAP ; - UPDATE 6 ; - DIG 2 ; - DIG 5 ; - DIG 2 ; - DIG 3 ; - PAIR ; - PAIR ; - LEFT (pair timestamp timestamp) ; - LEFT timestamp ; - UPDATE 3 ; - DUP 2 ; - DUP 3 ; - CDR ; - DUP 3 ; - SOME ; - DUP 4 ; - CAR ; - UPDATE ; - UPDATE 2 ; - DIG 2 ; - CAR ; - DUP 3 ; - CAR ; - SOME ; - DIG 3 ; - GET 6 ; - UNPAIR ; - DUP ; - DUP 3 ; - COMPARE ; - GT ; - IF { PUSH string "/" ; CONCAT ; SWAP ; CONCAT } - { SWAP ; PUSH string "/" ; CONCAT ; SWAP ; CONCAT } ; - UPDATE ; - UPDATE 1 } - { DIG 3 ; DIG 4 ; DIG 5 ; DROP 4 } ; - DUP 2 ; - DIG 2 ; - CAR ; - DUP ; - CAR ; - DUP ; - CAR ; - DIG 4 ; - UPDATE 2 ; - UPDATE 1 ; - UPDATE 1 ; - UPDATE 1 } ; - NIL operation ; - PAIR } } } } } ; - view "get_fee_in_mutez" unit mutez { CDR ; CAR ; CAR ; CDR ; CDR } ; - view "get_valid_swaps" - unit - (map string - (pair (pair %swap (string %from) (string %to)) - (address %oracle_address) - (string %oracle_asset_name) - (nat %oracle_precision) - (bool %is_disabled_for_deposits))) - { CDR ; CDR ; CAR ; CDR ; CDR } ; - view "get_valid_tokens" - unit - (map string - (pair (nat %token_id) - (string %name) - (option %address address) - (nat %decimals) - (option %standard string))) - { CDR ; CDR ; CDR } ; - view "get_current_batches" - unit - (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))) - { CDR ; - NIL (pair nat - (or (or (pair (pair timestamp - (pair (pair nat nat nat) - (or (or unit unit) unit) - (pair nat nat nat nat) - (pair (pair string string) (pair int int) timestamp))) - (pair (pair string string) (pair int int) timestamp)) - (pair timestamp timestamp)) - timestamp) - (pair nat nat nat nat nat nat nat nat) - (pair string string)) ; - DUP 2 ; - CAR ; - CAR ; - CAR ; - CDR ; - CAR ; - ITER { CDR ; - DUP 3 ; - CAR ; - CAR ; - CAR ; - CDR ; - CDR ; - SWAP ; - GET ; - IF_NONE {} { CONS } } ; - SWAP ; - DROP } } - diff --git a/batcher/batcher-storage-mainnet.tz b/batcher/batcher-storage-mainnet.tz deleted file mode 100644 index a55181dd..00000000 --- a/batcher/batcher-storage-mainnet.tz +++ /dev/null @@ -1,16 +0,0 @@ -(Pair (Pair (Pair (Pair "tz1ftWawLjmm6poX3R73Xc1UaFRoucCSpnhf" {} {}) 600 10000) - (Pair "tz1burnburnburnburnburnburnburjAYjjX" 0) - 10 - { Elt "" - 0x68747470733a2f2f697066732e6763702e6d617269676f6c642e6465762f697066732f516d56375a534b6358324d4e75656938745a3268723555484d5a66737039476b375675345878766d6246734a4e45 }) - (Pair (Pair {} 1) - {} - { Elt "tzBTC/EURL" - (Pair (Pair "tzBTC" "EURL") "KT1EhS7KVk6cAaYjUpg4jM1VjPGLJTrT9vqG" "BTC-EUR" 6 False) ; - Elt "tzBTC/USDT" - (Pair (Pair "tzBTC" "USDT") "KT1EhS7KVk6cAaYjUpg4jM1VjPGLJTrT9vqG" "BTC-USDT" 6 False) }) - { Elt "EURL" (Pair 0 "EURL" (Some "KT1JBNFcB5tiycHNdYGYCtR3kk6JaJysUCi8") 6 (Some "FA2 token")) ; - Elt "USDT" (Pair 0 "USDT" (Some "KT1XnTn74bUtxHfDtBmm2bGZAQfhPbvKWR8o") 6 (Some "FA2 token")) ; - Elt "tzBTC" - (Pair 0 "tzBTC" (Some "KT1PWx2mnDueood7fEmfbBDKx1D9BAnnXitn") 8 (Some "FA1.2 token")) }) - diff --git a/batcher/batcher.mligo b/batcher/batcher.mligo index ee61e80e..b01977b2 100644 --- a/batcher/batcher.mligo +++ b/batcher/batcher.mligo @@ -1,58 +1,8 @@ #import "@ligo/math-lib/rational/rational.mligo" "Rational" -#import "types.mligo" "Types" -#import "utils.mligo" "Utils" -#import "errors.mligo" "Errors" -#import "constants.mligo" "Constants" - -type side = Types.side -type tolerance = Types.tolerance -type token = Types.token -type token_amount = Types.token_amount -type token_amount_map = Types.token_amount_map -type token_holding_map = Types.token_holding_map -type token_holding = Types.token_holding -type swap = Types.swap -type swap_reduced = Types.swap_reduced -type valid_swap_reduced = Types.valid_swap_reduced -type valid_swap = Types.valid_swap -type exchange_rate_full = Types.exchange_rate_full -type exchange_rate = Types.exchange_rate -type swap_order = Types.swap_order -type external_swap_order = Types.external_swap_order -type batch_status = Types.batch_status -type total_cleared_volumes = Types.total_cleared_volumes -type clearing_volumes = Types.clearing_volumes -type clearing = Types.clearing -type buy_minus_token = Types.buy_minus_token -type buy_exact_token = Types.buy_exact_token -type buy_plus_token = Types.buy_plus_token -type buy_side = Types.buy_side -type sell_minus_token = Types.sell_minus_token -type sell_exact_token = Types.sell_exact_token -type sell_plus_token = Types.sell_plus_token -type sell_side = Types.sell_side -type batch_status = Types.batch_status -type volumes = Types.volumes -type pair = Types.pair -type ordertype = Types.ordertype -type ordertypes = Types.ordertypes -type batch_ordertypes = Types.batch_ordertypes -type user_batch_ordertypes = Types.user_batch_ordertypes -type batch = Types.batch -type reduced_batch = Types.reduced_batch -type batch_indices = Types.batch_indices -type batches = Types.batches -type batch_set = Types.batch_set -type metadata = Types.metadata -type metadata_update = Types.metadata_update -type orace_price_update = Types.oracle_price_update -type oracle_source_change = Types.oracle_source_change -type valid_tokens = Types.valid_tokens -type valid_swaps = Types.valid_swaps -type rates_current = Types.rates_current -type fees = Types.fees - - +#include "types.mligo" +#include "utils.mligo" +#include "errors.mligo" +#include "constants.mligo" module BatchHoldings_Utils = struct @@ -61,7 +11,7 @@ let increase_holding (batch_number: nat) (batches: batches): batches = match Big_map.find_opt batch_number batches with - | None -> failwith Errors.cannot_increase_holdings_of_batch_that_does_not_exist + | None -> failwith cannot_increase_holdings_of_batch_that_does_not_exist | Some b -> let bh = b.holdings + 1n in let b = { b with holdings = bh; } in Big_map.update batch_number (Some b) batches @@ -83,7 +33,7 @@ let remove_batch_holding (batch_number: nat) (batches: batches): batches = match Big_map.find_opt batch_number batches with - | None -> failwith Errors.cannot_decrease_holdings_of_removed_batch + | None -> failwith cannot_decrease_holdings_of_removed_batch | Some b -> let nh = abs(b.holdings - 1n) in let b = { b with holdings = nh; } in Big_map.update batch_number (Some b) batches @@ -94,7 +44,7 @@ let can_batch_be_removed (batch_number: nat) (batches: batches): bool = match Big_map.find_opt batch_number batches with - | None -> failwith Errors.cannot_decrease_holdings_of_removed_batch + | None -> failwith cannot_decrease_holdings_of_removed_batch | Some b -> b.holdings <= 0n end @@ -104,8 +54,6 @@ module Storage = struct type t = { metadata: metadata; - valid_tokens : valid_tokens; - valid_swaps : valid_swaps; rates_current : rates_current; batch_set : batch_set; last_order_number : nat; @@ -113,8 +61,10 @@ module Storage = struct fee_in_mutez: tez; fee_recipient : address; administrator : address; + tokenmanager : address; marketmaker : address; limit_on_tokens_or_pairs : nat; + liquidity_injection_limit_in_seconds : nat; deposit_time_window_in_seconds : nat; } @@ -232,21 +182,13 @@ let was_in_clearing | Sell -> was_in_clearing_for_sell clearing_tolerance order_tolerance -[@inline] -let get_clearing_volume - (clearing:clearing) : nat = - match clearing.clearing_tolerance with - | Minus -> clearing.clearing_volumes.minus - | Exact -> clearing.clearing_volumes.exact - | Plus -> clearing.clearing_volumes.plus - (* Filter 0 amount transfers out *) [@inline] let add_payout_if_not_zero (payout: token_amount) (tam: token_amount_map) : token_amount_map = if payout.amount > 0n then - Utils.TokenAmountMap.increase payout tam + TokenAmountMap.increase payout tam else tam @@ -276,17 +218,17 @@ let get_cleared_sell_side_payout (* Build payout amount *) let fill_payout: token_amount = { token = to; - amount = Utils.get_rounded_number_lower_bound payout; + amount = get_rounded_number_lower_bound payout; } in (* Add payout to transfers if not zero *) let u_tam = add_payout_if_not_zero fill_payout tam in (* Check if there is a partial fill. If so add partial fill payout plus remainder otherwise just add payout *) - if Utils.gt remaining (Rational.new 0) then + if gt remaining (Rational.new 0) then let token_rem : token_amount = { token = from; - amount = Utils.get_rounded_number_lower_bound remaining; + amount = get_rounded_number_lower_bound remaining; } in - Utils.TokenAmountMap.increase token_rem u_tam + TokenAmountMap.increase token_rem u_tam else u_tam @@ -315,17 +257,17 @@ let get_cleared_buy_side_payout (* Build payout amount *) let fill_payout = { token = to; - amount = Utils.get_rounded_number_lower_bound payout; + amount = get_rounded_number_lower_bound payout; } in (* Add payout to transfers if not zero *) let u_tam = add_payout_if_not_zero fill_payout tam in (* Check if there is a partial fill. If so add partial fill payout plus remainder otherwise just add payout *) - if Utils.gt remaining (Rational.new 0) then + if gt remaining (Rational.new 0) then let token_rem = { token = from; - amount = Utils.get_rounded_number_lower_bound remaining; + amount = get_rounded_number_lower_bound remaining; } in - Utils.TokenAmountMap.increase token_rem u_tam + TokenAmountMap.increase token_rem u_tam else u_tam @@ -335,34 +277,45 @@ let get_cleared_payout (amt: nat) (clearing: clearing) (tam: token_amount_map) - (tokens: valid_tokens): token_amount_map = + (tokens: ValidTokens.t_map): token_amount_map = let s = ot.side in let swap = clearing.clearing_rate.swap in - let from_token = Utils.get_token swap.from tokens in - let to_token = Utils.get_token swap.to tokens in + let from_token = get_token_from_map swap.from tokens in + let to_token = get_token_from_map swap.to tokens in match s with | Buy -> get_cleared_buy_side_payout from_token to_token amt clearing tam | Sell -> get_cleared_sell_side_payout to_token from_token amt clearing tam +[@inline] +let add_to_mm_map + (v:address) + (fee:tez) + (mmm: (address, tez) map) = + match Map.find_opt v mmm with + | None -> Map.add v fee mmm + | Some t -> let nf = t + fee in + Map.update v (Some nf) mmm + [@inline] let collect_order_payout_from_clearing - ((c, tam, vols, tokens, fees, fee_in_mutez, market_vault_used), (ot, amt): (clearing * token_amount_map * volumes * valid_tokens * fees * tez * bool) * (ordertype * nat)) : (clearing * token_amount_map * volumes * valid_tokens * fees * tez * bool) = + ((c, tam, vols, tokens, fees, fee_in_mutez, market_vault_used), (ot, amt): (clearing * token_amount_map * volumes * ValidTokens.t_map * fees * tez * market_vault_used) * (ordertype * nat)) : (clearing * token_amount_map * volumes * ValidTokens.t_map * fees * tez * market_vault_used) = let (u_tam, u_fees) = if was_in_clearing vols ot c then let tm = get_cleared_payout ot amt c tam tokens in - if market_vault_used then - let f = fees.to_market_maker + fee_in_mutez in - let uf = { fees with to_market_maker = f; } in + match market_vault_used with + | Some mva -> + let nmmf = add_to_mm_map mva fee_in_mutez fees.to_market_makers in + let uf = { fees with to_market_makers = nmmf; } in (tm, uf) - else + | None -> let f = fees.to_send + fee_in_mutez in let uf = { fees with to_send = f; } in (tm, uf) else - let ta: token_amount = Utils.TokenAmount.recover ot amt c tokens in + let ta: token_amount = TokenAmount.recover ot amt c tokens in let f = fees.to_refund + fee_in_mutez in let uf = { fees with to_refund = f; } in - (Utils.TokenAmountMap.increase ta tam, uf) + (TokenAmountMap.increase ta tam, uf) in (c, u_tam, vols, tokens, u_fees, fee_in_mutez, market_vault_used) @@ -392,7 +345,7 @@ let get_clearing [@inline] let collect_redemptions - ((bots, tam, bts, tokens, fees, fee_in_mutez),(batch_number,otps) : (batch_ordertypes * token_amount_map * batch_set * valid_tokens * fees * tez) * (nat * ordertypes)) : (batch_ordertypes * token_amount_map * batch_set * valid_tokens * fees * tez) = + ((bots, tam, bts, tokens, fees, fee_in_mutez),(batch_number,otps) : (batch_ordertypes * token_amount_map * batch_set * ValidTokens.t_map * fees * tez) * (nat * ordertypes)) : (batch_ordertypes * token_amount_map * batch_set * ValidTokens.t_map * fees * tez) = let batches = bts.batches in match Big_map.find_opt batch_number batches with | None -> bots, tam, bts, tokens, fees, fee_in_mutez @@ -418,7 +371,7 @@ let collect_redemption_payouts let fee_in_mutez = storage.fee_in_mutez in let batch_set = storage.batch_set in let ubots = storage.user_batch_ordertypes in - let tokens = storage.valid_tokens in + let tokens = TokenManagerUtils.get_valid_tokens storage.tokenmanager in let empty_tam = (Map.empty : token_amount_map) in match Big_map.find_opt holder ubots with | None -> fees, ubots, batch_set, empty_tam @@ -439,17 +392,27 @@ let is_within_limit match Big_map.find_opt holder ubots with | None -> true | Some bots -> let outstanding_token_items = Batch_OrderTypes.count bots in - outstanding_token_items <= Constants.limit_of_redeemable_items + outstanding_token_items <= limit_of_redeemable_items end - - - module Treasury = struct type storage = Storage.t +[@inline] +let resolve_fees_to_mms + (to_mms: (address,tez) map) + (token_ops: operation list): operation list = + let pay_mms (ops, (addr, amt) : operation list * (address * tez)) : operation list = + if amt > 0mutez then + let op = send_add_reward amt addr in + op :: ops + else + ops + in + Map.fold pay_mms to_mms token_ops + [@inline] let resolve_fees @@ -457,18 +420,13 @@ let resolve_fees (token_ops: operation list): operation list = let token_ops = if fees.to_refund > 0mutez then - Utils.Treasury_Utils.transfer_fee fees.payer fees.to_refund :: token_ops - else - token_ops - in - let token_ops = - if fees.to_market_maker > 0mutez then - Utils.Treasury_Utils.transfer_fee fees.market_maker fees.to_market_maker :: token_ops + Treasury_Utils.transfer_fee fees.payer fees.to_refund :: token_ops else token_ops in + let token_ops = resolve_fees_to_mms fees.to_market_makers token_ops in if fees.to_send > 0mutez then - Utils.Treasury_Utils.transfer_fee fees.recipient fees.to_send :: token_ops + Treasury_Utils.transfer_fee fees.recipient fees.to_send :: token_ops else token_ops @@ -476,223 +434,30 @@ let resolve_fees let deposit (deposit_address : address) (deposited_token : token_amount) : operation list = - let treasury_vault = Utils.get_vault () in - let deposit_op = Utils.Treasury_Utils.handle_transfer deposit_address treasury_vault deposited_token in + let treasury_vault = get_vault () in + let deposit_op = Treasury_Utils.handle_transfer deposit_address treasury_vault deposited_token in [ deposit_op] -[@inline] -let redeem_by_batch - (redeem_address : address) - (batch_id: nat) - (storage : storage) : operation list * storage = - let treasury_vault = Utils.get_vault () in - let fees = { - to_send = 0mutez; - to_refund = 0mutez; - to_market_maker = 0mutez; - payer = redeem_address; - recipient = storage.fee_recipient; - market_maker = storage.marketmaker; - } in - let fees, updated_ubots, updated_batch_set, payout_token_map = Ubots.collect_redemption_payouts redeem_address fees (Some batch_id) storage in - let operations = Utils.Treasury_Utils.transfer_holdings treasury_vault redeem_address payout_token_map in - let operations = resolve_fees fees operations in - let updated_storage = { storage with user_batch_ordertypes = updated_ubots; batch_set = updated_batch_set; } in - (operations, updated_storage) - [@inline] let redeem (redeem_address : address) (storage : storage) : operation list * storage = - let treasury_vault = Utils.get_vault () in - let fees = { + let treasury_vault = get_vault () in + let fees:fees = { to_send = 0mutez; to_refund = 0mutez; - to_market_maker = 0mutez; + to_market_makers = (Map.empty: (address,tez) map); payer = redeem_address; recipient = storage.fee_recipient; - market_maker = storage.marketmaker; } in let fees, updated_ubots, updated_batch_set, payout_token_map = Ubots.collect_redemption_payouts redeem_address fees None storage in - let operations = Utils.Treasury_Utils.transfer_holdings treasury_vault redeem_address payout_token_map in + let operations = Treasury_Utils.transfer_holdings treasury_vault redeem_address payout_token_map in let operations = resolve_fees fees operations in let updated_storage = { storage with user_batch_ordertypes = updated_ubots; batch_set = updated_batch_set; } in (operations, updated_storage) end -module Token_Utils = struct - -[@inline] -let is_valid_swap_pair - (side: side) - (swap: swap_reduced) - (valid_swaps: valid_swaps): swap_reduced = - let token_pair = Utils.pair_of_swap side swap in - let rate_name = Utils.get_rate_name_from_pair token_pair in - if Map.mem rate_name valid_swaps then swap else failwith Errors.unsupported_swap_type - -[@inline] -let remove_token - (token: token) - (valid_tokens: valid_tokens) : valid_tokens = - match Map.find_opt token.name valid_tokens with - | Some existing_token -> if Utils.are_equivalent_tokens existing_token token then - Map.remove token.name valid_tokens - else - failwith Errors.token_already_exists_but_details_are_different - | None -> valid_tokens - -[@inline] -let add_token - (token: token) - (valid_tokens: valid_tokens) : valid_tokens = - match Map.find_opt token.name valid_tokens with - | Some existing_token -> if Utils.are_equivalent_tokens existing_token token then - valid_tokens - else - failwith Errors.token_already_exists_but_details_are_different - | None -> Map.add token.name token valid_tokens - -[@inline] -let is_token_used - (token: token) - (valid_tokens: valid_tokens) : bool = - let is_token_in_tokens (acc, (_i, t) : bool * (string * token)) : bool = - Utils.are_equivalent_tokens token t || - acc - in - Map.fold is_token_in_tokens valid_tokens false - -[@inline] -let is_token_used_in_swaps - (token: token) - (valid_swaps: valid_swaps) - (tokens: valid_tokens): bool = - let is_token_used_in_swap (acc, (_i, valid_swap) : bool * (string * valid_swap_reduced)) : bool = - let swap = valid_swap.swap in - let to_token = Utils.get_token swap.to tokens in - let from_token = Utils.get_token swap.from tokens in - Utils.are_equivalent_tokens token to_token || - Utils.are_equivalent_tokens token from_token || - acc - in - Map.fold is_token_used_in_swap valid_swaps false - -[@inline] -let add_swap - (valid_swap: valid_swap) - (valid_swaps: valid_swaps) : valid_swaps = - let swap = valid_swap.swap in - let swap_reduced = Utils.swap_to_swap_reduced(swap) in - let rate_name = Utils.get_rate_name_from_swap swap_reduced in - let valid_swap_reduced = Utils.valid_swap_to_valid_swap_reduced valid_swap in - Map.add rate_name valid_swap_reduced valid_swaps - -[@inline] -let remove_swap - (valid_swap: valid_swap) - (valid_tokens: valid_tokens) - (valid_swaps: valid_swaps) : (valid_swaps * valid_tokens) = - let swap = valid_swap.swap in - let swap_reduced = Utils.swap_to_swap_reduced(swap) in - let rate_name = Utils.get_rate_name_from_swap swap_reduced in - let valid_swaps = Map.remove rate_name valid_swaps in - let from = Utils.get_token swap_reduced.from valid_tokens in - let to = Utils.get_token swap_reduced.to valid_tokens in - let valid_tokens = if is_token_used_in_swaps from valid_swaps valid_tokens then - valid_tokens - else - remove_token from valid_tokens - in - let valid_tokens = if is_token_used_in_swaps to valid_swaps valid_tokens then - valid_tokens - else - remove_token to valid_tokens - in - valid_swaps, valid_tokens - -end - -module Tokens = struct - - -[@inline] -let validate - (side: side) - (swap: swap) - (valid_tokens: valid_tokens) - (valid_swaps: valid_swaps): swap_reduced = - let from = swap.from.token in - let to = swap.to in - match Map.find_opt from.name valid_tokens with - | None -> failwith Errors.unsupported_swap_type - | Some ft -> (match Map.find_opt to.name valid_tokens with - | None -> failwith Errors.unsupported_swap_type - | Some tt -> if (Utils.are_equivalent_tokens from ft) && (Utils.are_equivalent_tokens to tt) then - let sr = Utils.swap_to_swap_reduced swap in - Token_Utils.is_valid_swap_pair side sr valid_swaps - else - failwith Errors.unsupported_swap_type) - -[@inline] -let check_tokens_size_or_fail - (tokens_size: nat) - (limit_on_tokens_or_pairs: nat) - (num_tokens: nat) : unit = if tokens_size + num_tokens > limit_on_tokens_or_pairs then failwith Errors.upper_limit_on_tokens_has_been_reached else () - -[@inline] -let can_add - (to: token) - (from: token) - (limit_on_tokens_or_pairs: nat) - (valid_tokens: valid_tokens) - (valid_swaps: valid_swaps): unit = - let pairs_size = Map.size valid_swaps in - if pairs_size + 1n > limit_on_tokens_or_pairs then failwith Errors.upper_limit_on_swap_pairs_has_been_reached else - let tokens_size = Map.size valid_tokens in - let unused_tokens_being_added = - if Token_Utils.is_token_used to valid_tokens && Token_Utils.is_token_used from valid_tokens then 0n else - if Token_Utils.is_token_used to valid_tokens || Token_Utils.is_token_used from valid_tokens then 1n else - 2n - in - check_tokens_size_or_fail tokens_size limit_on_tokens_or_pairs unused_tokens_being_added - -[@inline] -let remove_pair - (valid_swap: valid_swap) - (valid_swaps: valid_swaps) - (valid_tokens: valid_tokens) : valid_swaps * valid_tokens = - let swap = valid_swap.swap in - let swap_reduced = Utils.swap_to_swap_reduced swap in - let rate_name = Utils.get_rate_name_from_swap swap_reduced in - let rate_found = Map.find_opt rate_name valid_swaps in - match rate_found with - | Some _ -> Token_Utils.remove_swap valid_swap valid_tokens valid_swaps - | None -> failwith Errors.swap_does_not_exist - -[@inline] -let add_pair - (limit_on_tokens_or_pairs: nat) - (valid_swap: valid_swap) - (valid_swaps: valid_swaps) - (valid_tokens: valid_tokens) : valid_swaps * valid_tokens = - let swap = valid_swap.swap in - let from = swap.from.token in - let to = swap.to in - let () = can_add to from limit_on_tokens_or_pairs valid_tokens valid_swaps in - let swap_reduced = Utils.swap_to_swap_reduced swap in - let rate_name = Utils.get_rate_name_from_swap swap_reduced in - let rate_found = Map.find_opt rate_name valid_swaps in - match rate_found with - | Some _ -> failwith Errors.swap_already_exists - | None -> let valid_tokens = Token_Utils.add_token from valid_tokens in - let valid_tokens = Token_Utils.add_token to valid_tokens in - let valid_swaps = Token_Utils.add_swap valid_swap valid_swaps in - valid_swaps, valid_tokens - - -end module Batch_Utils = struct @@ -775,7 +540,7 @@ let make pair = pair; volumes = volumes; holdings = 0n; - market_vault_used = false; + market_vault_used = (None: address option); } [@inline] @@ -783,7 +548,7 @@ let update_current_batch_in_set (batch : batch) (batch_set : batch_set) : (batch * batch_set)= let updated_batches = Big_map.update batch.batch_number (Some batch) batch_set.batches in - let name = Utils.get_rate_name_from_pair batch.pair in + let name = get_rate_name_from_pair batch.pair in let updated_batch_indices = Map.update name (Some batch.batch_number) batch_set.current_batch_indices in batch, { batch_set with batches = updated_batches; current_batch_indices = updated_batch_indices; } @@ -793,7 +558,7 @@ let should_be_cleared (current_time : timestamp) : bool = match batch.status with | Closed { start_time = _; closing_time } -> - current_time > closing_time + Constants.price_wait_window_in_seconds + current_time > closing_time + price_wait_window_in_seconds | _ -> false @@ -809,7 +574,7 @@ let start_period (pair : pair) (batch_set : batch_set) (current_time : timestamp) : (batch * batch_set) = - let highest_batch_index = Utils.get_highest_batch_index batch_set.current_batch_indices in + let highest_batch_index = get_highest_batch_index batch_set.current_batch_indices in let new_batch_number = highest_batch_index + 1n in let new_batch = make new_batch_number current_time pair in update_current_batch_in_set new_batch batch_set @@ -824,7 +589,7 @@ let close let batch_close_time = start_time + (int deposit_time_window) in let new_status = Closed { start_time = start_time; closing_time = batch_close_time } in storage,{ batch with status = new_status } - | _ -> failwith Errors.trying_to_close_batch_which_is_not_open + | _ -> failwith trying_to_close_batch_which_is_not_open [@inline] let new_batch_set : batch_set = @@ -905,7 +670,7 @@ let get_current_batch_without_opening (current_time: timestamp) (storage: Storage.t) (batch_set: batch_set) : (batch option * batch_set * Storage.t) = - let current_batch_index = Utils.get_current_batch_index pair batch_set.current_batch_indices in + let current_batch_index = get_current_batch_index pair batch_set.current_batch_indices in match Big_map.find_opt current_batch_index batch_set.batches with | None -> None, batch_set,storage | Some cb -> let is_cleared = is_cleared cb in @@ -922,7 +687,7 @@ let get_current_batch (current_time: timestamp) (storage: Storage.t) (batch_set: batch_set) : (batch * batch_set * Storage.t) = - let current_batch_index = Utils.get_current_batch_index pair batch_set.current_batch_indices in + let current_batch_index = get_current_batch_index pair batch_set.current_batch_indices in match Big_map.find_opt current_batch_index batch_set.batches with | None -> let (b, bs) = start_period pair batch_set current_time in (b,bs,storage) @@ -961,9 +726,9 @@ let get_clearing_rate (exchange_rate: exchange_rate) : exchange_rate = match clearing.clearing_tolerance with | Exact -> exchange_rate - | Plus -> let rate = Rational.mul (exchange_rate.rate) Constants.ten_bips_constant in + | Plus -> let rate = Rational.mul (exchange_rate.rate) ten_bips_constant in { exchange_rate with rate = rate} - | Minus -> let rate = Rational.div (exchange_rate.rate) Constants.ten_bips_constant in + | Minus -> let rate = Rational.div (exchange_rate.rate) ten_bips_constant in { exchange_rate with rate = rate} [@inline] @@ -979,13 +744,6 @@ let filter_volumes | Plus -> let buy_vol = volumes.buy_minus_volume + volumes.buy_exact_volume + volumes.buy_plus_volume in buy_vol, volumes.sell_plus_volume -[@inline] -let compute_equivalent_amount (amount : nat) (rate : exchange_rate) (is_sell_side: bool) : nat = - let float_amount = Rational.new (int (amount)) in - if is_sell_side then - Utils.get_rounded_number_lower_bound (Rational.div float_amount rate.rate) - else - Utils.get_rounded_number_lower_bound (Rational.mul float_amount rate.rate) (* This function builds the order equivalence for the pro-rata redeemption. @@ -1007,7 +765,7 @@ let build_total_cleared_volumes in (* Convert cleared volume to sell side units to assist in payout claculations later *) let sell_side_total_cleared_volume_as_rational = Rational.mul (Rational.new (int buy_side_total_cleared_volume)) clearing_rate.rate in - let sell_side_total_cleared_volume = Utils.get_rounded_number_lower_bound sell_side_total_cleared_volume_as_rational in + let sell_side_total_cleared_volume = get_rounded_number_lower_bound sell_side_total_cleared_volume_as_rational in (* Build total volumes objects which represents the TOTAL cleared volume on each side of the swap along which will be used in the payout calculations *) let total_volumes = { buy_side_total_cleared_volume = buy_side_total_cleared_volume; @@ -1030,7 +788,7 @@ let compute_clearing_prices let buy_cp_plus = int (volumes.buy_plus_volume) in let buy_side : buy_side = buy_cp_minus, buy_cp_exact, buy_cp_plus in let sell_side : sell_side = sell_cp_minus, sell_cp_exact, sell_cp_plus in - let clearing = Utils.get_clearing_price rate buy_side sell_side in + let clearing = get_clearing_price rate buy_side sell_side in let with_total_cleared_vols = build_total_cleared_volumes volumes clearing rate in with_total_cleared_vols @@ -1048,37 +806,22 @@ type entrypoint = | Deposit of external_swap_order | Tick of string | Redeem - | RedeemByBatch of nat | Cancel of pair | Change_fee of tez | Change_admin_address of address + | Change_liquidity_injection_time_limit of nat | Change_marketmaker_address of address + | Change_tokenmanager_address of address | Change_fee_recipient_address of address - | Add_token_swap_pair of valid_swap - | Remove_token_swap_pair of valid_swap - | Amend_token_and_pair_limit of nat | Add_or_update_metadata of metadata_update | Remove_metadata of string - | Enable_swap_pair_for_deposit of string - | Disable_swap_pair_for_deposit of string - | Change_oracle_source_of_pair of oracle_source_change | Change_deposit_time_window of nat - -[@inline] -let get_oracle_price - (failure_code: nat) - (valid_swap: valid_swap_reduced) : orace_price_update = - match Tezos.call_view "getPrice" valid_swap.oracle_asset_name valid_swap.oracle_address with - | Some opu -> opu - | None -> failwith failure_code - - [@inline] let admin_and_fee_recipient_address_are_different (admin : address) (fee_recipient : address ): unit = - if admin = fee_recipient then failwith Errors.admin_and_fee_recipient_address_cannot_be_the_same else () + if admin = fee_recipient then failwith admin_and_fee_recipient_address_cannot_be_the_same else () [@inline] @@ -1099,10 +842,10 @@ let external_to_order (order: external_swap_order) (order_number: nat) (batch_number: nat) - (valid_tokens: valid_tokens) - (valid_swaps: valid_swaps): swap_order = - let side = Utils.nat_to_side order.side in - let tolerance = Utils.nat_to_tolerance order.tolerance in + (valid_tokens: ValidTokens.t_map) + (valid_swaps: ValidSwaps.t_map): swap_order = + let side = nat_to_side order.side in + let tolerance = nat_to_tolerance order.tolerance in let sender = Tezos.get_sender () in let converted_order : swap_order = { @@ -1114,19 +857,19 @@ let external_to_order tolerance = tolerance; redeemed = false; } in - let _ = Tokens.validate side order.swap valid_tokens valid_swaps in + let _ = Tokens.validate_from_map side order.swap valid_tokens valid_swaps in converted_order [@inline] let get_valid_swap_reduced (pair_name: string) (storage : storage) : valid_swap_reduced = - match Map.find_opt pair_name storage.valid_swaps with + let valid_swaps = TokenManagerUtils.get_valid_swaps storage.tokenmanager in + match Map.find_opt pair_name valid_swaps with | Some vswp -> vswp - | None -> failwith Errors.swap_does_not_exist + | None -> failwith swap_does_not_exist [@inline] - let remove_orders_from_batch (ots: ordertypes) (batch: batch): batch = @@ -1153,7 +896,7 @@ let remove_order_types (bot: batch_ordertypes) (storage:storage) : ordertypes * storage = match Map.find_opt batch_number bot with - | None -> failwith Errors.no_orders_for_user_address + | None -> failwith no_orders_for_user_address | Some ots -> let bot = Map.remove batch_number bot in let ubots = Big_map.update holder (Some bot) storage.user_batch_ordertypes in let storage = { storage with user_batch_ordertypes = ubots;} in @@ -1175,14 +918,14 @@ let refund_orders token = token; amount = amt; } in - let tam = Utils.TokenAmountMap.increase ta tam in + let tam = TokenAmountMap.increase ta tam in let mutez_to_ref = mutez_to_ref + fee in tam, mutez_to_ref in - let token_refunds, tez_refunds= Map.fold collect_refunds ots ((Map.empty: token_amount_map), 0mutez) in - let treasury_vault = Utils.get_vault () in - let operations = Utils.Treasury_Utils.transfer_holdings treasury_vault refund_address token_refunds in - let operations = if tez_refunds > 0mutez then Utils.Treasury_Utils.transfer_fee storage.fee_recipient tez_refunds :: operations else operations in + let token_refunds, tez_refunds = Map.fold collect_refunds ots ((Map.empty: token_amount_map), 0mutez) in + let treasury_vault = get_vault () in + let operations = Treasury_Utils.transfer_holdings treasury_vault refund_address token_refunds in + let operations = if tez_refunds > 0mutez then Treasury_Utils.transfer_fee storage.fee_recipient tez_refunds :: operations else operations in operations, storage [@inline] @@ -1194,9 +937,9 @@ let cancel_order let ubots = storage.user_batch_ordertypes in let current_time = Tezos.get_now () in let (batch, batch_set, storage) = Batch_Utils.get_current_batch storage.deposit_time_window_in_seconds pair current_time storage storage.batch_set in - let () = if not (Batch_Utils.is_batch_open batch) then failwith Errors.cannot_cancel_orders_for_a_batch_that_is_not_open in + let () = if not (Batch_Utils.is_batch_open batch) then failwith cannot_cancel_orders_for_a_batch_that_is_not_open in match Big_map.find_opt holder ubots with - | None -> failwith Errors.no_orders_for_user_address + | None -> failwith no_orders_for_user_address | Some bot -> let orders_to_remove, storage = remove_order_types batch.batch_number holder bot storage in let storage = remove_orders orders_to_remove batch batch_set storage in refund_orders holder orders_to_remove valid_swap storage @@ -1205,104 +948,76 @@ let cancel_order let cancel (pair: pair) (storage: storage): result = - let () = Utils.reject_if_tez_supplied () in + let () = reject_if_tez_supplied () in let sender = Tezos.get_sender () in let token_one, token_two = pair in - let pair_name = Utils.find_lexicographical_pair_name token_one token_two in - match Map.find_opt pair_name storage.valid_swaps with - | None -> failwith Errors.swap_does_not_exist - | Some vswpr -> let vswp = Utils.valid_swap_reduced_to_valid_swap vswpr 1n storage.valid_tokens in + let pair_name = find_lexicographical_pair_name token_one token_two in + let valid_swaps = TokenManagerUtils.get_valid_swaps storage.tokenmanager in + match Map.find_opt pair_name valid_swaps with + | None -> failwith swap_does_not_exist + | Some vswpr -> let valid_tokens = TokenManagerUtils.get_valid_tokens storage.tokenmanager in + let vswp = valid_swap_reduced_to_valid_swap vswpr 1n valid_tokens in cancel_order pair sender vswp storage -[@inline] -let oracle_price_is_not_stale - (deposit_time_window: nat) - (oracle_price_timestamp: timestamp) : unit = - let dtw_i = int deposit_time_window in - if (Tezos.get_now () - dtw_i) < oracle_price_timestamp then () else failwith Errors.oracle_price_is_stale - -[@inline] -let is_oracle_price_newer_than_current - (rate_name: string) - (oracle_price_timestamp: timestamp) - (storage: storage): unit = - let rates = storage.rates_current in - match Big_map.find_opt rate_name rates with - | Some r -> if r.when >=oracle_price_timestamp then failwith Errors.oracle_price_is_not_timely - | None -> () - - [@inline] let confirm_oracle_price_is_available_before_deposit (pair:pair) (batch:batch) (storage:storage) : unit = if Batch_Utils.is_batch_open batch then () else - let pair_name = Utils.get_rate_name_from_pair pair in + let pair_name = get_rate_name_from_pair pair in let valid_swap_reduced = get_valid_swap_reduced pair_name storage in - let (lastupdated, _price) = get_oracle_price Errors.oracle_price_should_be_available_before_deposit valid_swap_reduced in - oracle_price_is_not_stale storage.deposit_time_window_in_seconds lastupdated + let (lastupdated, _price) = OracleUtils.get_oracle_price oracle_price_should_be_available_before_deposit valid_swap_reduced in + OracleUtils.oracle_price_is_not_stale storage.deposit_time_window_in_seconds lastupdated [@inline] let confirm_swap_pair_is_disabled_prior_to_removal (valid_swap:valid_swap) : unit = - if valid_swap.is_disabled_for_deposits then () else failwith Errors.cannot_remove_swap_pair_that_is_not_disabled - + 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_reduced) : unit = let swap = order.swap in - let side = Utils.nat_to_side order.side in + let side = nat_to_side order.side in match side with | Buy -> - if swap.from.token.name = valid_swap.swap.from then () else failwith Errors.incorrect_side_specified - | Sell -> - if swap.from.token.name = valid_swap.swap.to then () else failwith Errors.incorrect_side_specified - - - -[@inline] -let enforce_correct_side - (order:external_swap_order) - (valid_swap:valid_swap) : unit = - let swap = order.swap in - let side = Utils.nat_to_side order.side in - match side with - | Buy -> - if swap.from.token.name = valid_swap.swap.from.token.name then () else failwith incorrect_side_specified + if swap.from.token.name = valid_swap.swap.from then () else failwith incorrect_side_specified | Sell -> - if swap.from.token.name = valid_swap.swap.to.name then () else failwith incorrect_side_specified + if swap.from.token.name = valid_swap.swap.to 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] let deposit (external_order: external_swap_order) (storage : storage) : result = - let pair = Utils.pair_of_external_swap external_order storage.valid_tokens in + let pair = pair_of_external_swap external_order in let current_time = Tezos.get_now () in - let pair_name = Utils.get_rate_name_from_pair pair in + let pair_name = 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 Errors.swap_is_disabled_for_deposits else + 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 Errors.insufficient_swap_fee else - if fee_provided > fee_amount_in_mutez then failwith Errors.more_tez_sent_than_fee_cost else + if fee_provided < fee_amount_in_mutez then failwith insufficient_swap_fee else + if fee_provided > fee_amount_in_mutez then failwith more_tez_sent_than_fee_cost else let (current_batch, current_batch_set, storage) = Batch_Utils.get_current_batch storage.deposit_time_window_in_seconds pair current_time storage storage.batch_set in if Batch_Utils.can_deposit current_batch then let () = confirm_oracle_price_is_available_before_deposit pair current_batch storage in let storage = { storage with batch_set = current_batch_set } in let current_batch_number = current_batch.batch_number in let depositor = Tezos.get_sender () in - let current_batch = if depositor = storage.marketmaker then - { current_batch with market_vault_used = true; } + let vaults = MarketMakerUtils.get_current_vaults storage.marketmaker in + let current_batch = if Vaults.mem_map depositor vaults then + { current_batch with market_vault_used = Some depositor; } else current_batch in let next_order_number = storage.last_order_number + 1n in - let order : swap_order = external_to_order external_order next_order_number current_batch_number storage.valid_tokens storage.valid_swaps in + let valid_swaps = TokenManagerUtils.get_valid_swaps storage.tokenmanager in + let valid_tokens = TokenManagerUtils.get_valid_tokens storage.tokenmanager in + let order : swap_order = external_to_order external_order next_order_number current_batch_number valid_tokens valid_swaps in (* We intentionally limit the amount of distinct orders that can be placed whilst unredeemed orders exist for a given user *) if Ubots.is_within_limit order.trader storage.user_batch_ordertypes then let _,updated_storage = Batch_Utils.update_storage_with_order order next_order_number current_batch_number current_batch current_batch_set storage in @@ -1310,53 +1025,32 @@ let deposit (external_order: external_swap_order) (storage : storage) : result = (treasury_ops, updated_storage) else - failwith Errors.too_many_unredeemed_orders + failwith too_many_unredeemed_orders else - failwith Errors.no_open_batch + failwith no_open_batch [@inline] let redeem (storage : storage) : result = let holder = Tezos.get_sender () in - let () = Utils.reject_if_tez_supplied () in + let () = reject_if_tez_supplied () in let (tokens_transfer_ops, new_storage) = Treasury.redeem holder storage in (tokens_transfer_ops, new_storage) -[@inline] -let redeem_by_batch - (batch_id:nat) - (storage : storage) : result = - let holder = Tezos.get_sender () in - let () = Utils.reject_if_tez_supplied () in - let (tokens_transfer_ops, new_storage) = Treasury.redeem_by_batch holder batch_id storage in - (tokens_transfer_ops, new_storage) - -[@inline] -let change_oracle_price_source - (source_change: oracle_source_change) - (storage: storage) : result = - let _ = Utils.is_administrator storage.administrator in - let () = Utils.reject_if_tez_supplied () in - let valid_swap_reduced = get_valid_swap_reduced source_change.pair_name storage in - let valid_swap = { valid_swap_reduced with oracle_address = source_change.oracle_address; oracle_asset_name = source_change.oracle_asset_name; oracle_precision = source_change.oracle_precision; } in - let _ = get_oracle_price Errors.unable_to_get_price_from_new_oracle_source valid_swap_reduced in - let updated_swaps = Map.update source_change.pair_name (Some valid_swap) storage.valid_swaps in - let storage = { storage with valid_swaps = updated_swaps} in - no_op (storage) - [@inline] let tick_price (rate_name: string) (valid_swap : valid_swap) (storage : storage) : storage = - let valid_swap_reduced = Utils.valid_swap_to_valid_swap_reduced valid_swap in - let (lastupdated, price) = Utils.get_oracle_price Errors.unable_to_get_price_from_oracle valid_swap_reduced in - let () = is_oracle_price_newer_than_current rate_name lastupdated storage in - let () = oracle_price_is_not_stale storage.deposit_time_window_in_seconds lastupdated in - let oracle_rate = Utils.convert_oracle_price valid_swap.oracle_precision valid_swap.swap lastupdated price storage.valid_tokens in - let rates_current = Utils.update_current_rate (rate_name) (oracle_rate) (storage.rates_current) in + let valid_swap_reduced = valid_swap_to_valid_swap_reduced valid_swap in + let (lastupdated, price) = OracleUtils.get_oracle_price unable_to_get_price_from_oracle valid_swap_reduced in + let () = OracleUtils.is_oracle_price_newer_than_current rate_name lastupdated storage.rates_current in + let () = OracleUtils.oracle_price_is_not_stale storage.deposit_time_window_in_seconds lastupdated in + let valid_tokens = TokenManagerUtils.get_valid_tokens storage.tokenmanager in + let oracle_rate = OracleUtils.convert_oracle_price valid_swap.oracle_precision valid_swap.swap lastupdated price valid_tokens in + let rates_current = update_current_rate (rate_name) (oracle_rate) (storage.rates_current) in let storage = { storage with rates_current = rates_current; } in - let pair = Utils.pair_of_rate oracle_rate in + let pair = pair_of_rate oracle_rate in let current_time = Tezos.get_now () in let batch_set = storage.batch_set in let (batch_opt, batch_set, storage) = Batch_Utils.get_current_batch_without_opening storage.deposit_time_window_in_seconds pair current_time storage batch_set in @@ -1371,19 +1065,21 @@ let tick_price let tick (rate_name: string) (storage : storage) : result = - let () = Utils.reject_if_tez_supplied () in - match Map.find_opt rate_name storage.valid_swaps with - | Some vswpr -> let vswp = Utils.valid_swap_reduced_to_valid_swap vswpr 1n storage.valid_tokens in - let storage = tick_price rate_name vswp storage in - no_op (storage) - | None -> failwith Errors.swap_does_not_exist + let () = reject_if_tez_supplied () in + let valid_swaps = TokenManagerUtils.get_valid_swaps storage.tokenmanager in + match Map.find_opt rate_name valid_swaps with + | Some vswpr -> let valid_tokens = TokenManagerUtils.get_valid_tokens storage.tokenmanager in + let vswp = valid_swap_reduced_to_valid_swap vswpr 1n valid_tokens in + let storage = tick_price rate_name vswp storage in + no_op (storage) + | None -> failwith swap_does_not_exist [@inline] let change_fee (new_fee: tez) (storage: storage) : result = - let () = Utils.is_administrator storage.administrator in - let () = Utils.reject_if_tez_supplied () in + let () = is_known_sender storage.administrator sender_not_administrator in + let () = reject_if_tez_supplied () in let storage = { storage with fee_in_mutez = new_fee; } in no_op storage @@ -1391,8 +1087,8 @@ let change_fee let change_admin_address (new_admin_address: address) (storage: storage) : result = - let () = Utils.is_administrator storage.administrator in - let () = Utils.reject_if_tez_supplied () in + let () = is_known_sender storage.administrator sender_not_administrator in + let () = reject_if_tez_supplied () in let () = admin_and_fee_recipient_address_are_different new_admin_address storage.fee_recipient in let storage = { storage with administrator = new_admin_address; } in no_op storage @@ -1401,114 +1097,79 @@ let change_admin_address let change_mm_address (new_marketmaker_address: address) (storage: storage) : result = - let () = Utils.is_administrator storage.administrator in - let () = Utils.reject_if_tez_supplied () in - let () = admin_and_fee_recipient_address_are_different new_marketmaker_address storage.fee_recipient in + let () = is_known_sender storage.administrator sender_not_administrator in + let () = reject_if_tez_supplied () in let storage = { storage with marketmaker = new_marketmaker_address; } in no_op storage +[@inline] +let change_tm_address + (new_tokenmanager_address: address) + (storage: storage) : result = + let () = is_known_sender storage.administrator sender_not_administrator in + let () = reject_if_tez_supplied () in + let storage = { storage with tokenmanager = new_tokenmanager_address; } in + no_op storage + [@inline] let change_fee_recipient_address (new_fee_recipient_address: address) (storage: storage) : result = - let () = Utils.is_administrator storage.administrator in - let () = Utils.reject_if_tez_supplied () in + let () = is_known_sender storage.administrator sender_not_administrator in + let () = reject_if_tez_supplied () in let () = admin_and_fee_recipient_address_are_different new_fee_recipient_address storage.administrator in let storage = { storage with fee_recipient = new_fee_recipient_address; } in no_op storage -[@inline] -let add_token_swap_pair - (valid_swap: valid_swap) - (storage: storage) : result = - let () = Utils.is_administrator storage.administrator in - let () = Utils.reject_if_tez_supplied () in - if valid_swap.swap.from.token.decimals < Constants.minimum_precision then failwith Errors.swap_precision_is_less_than_minimum else - if valid_swap.swap.to.decimals < Constants.minimum_precision then failwith Errors.swap_precision_is_less_than_minimum else - if valid_swap.oracle_precision <> Constants.minimum_precision then failwith Errors.oracle_must_be_equal_to_minimum_precision else - let (u_swaps,u_tokens) = Tokens.add_pair storage.limit_on_tokens_or_pairs valid_swap storage.valid_swaps storage.valid_tokens in - let storage = { storage with valid_swaps = u_swaps; valid_tokens = u_tokens; } in - no_op storage - -[@inline] -let remove_token_swap_pair - (swap: valid_swap) - (storage: storage) : result = - let () = Utils.is_administrator storage.administrator in - let () = Utils.reject_if_tez_supplied () in - let () = confirm_swap_pair_is_disabled_prior_to_removal swap in - let (u_swaps,u_tokens) = Tokens.remove_pair swap storage.valid_swaps storage.valid_tokens in - let storage = { storage with valid_swaps = u_swaps; valid_tokens = u_tokens; } in - no_op storage [@inline] let add_or_update_metadata (metadata_update: metadata_update) (storage:storage) : result = - let () = Utils.is_administrator storage.administrator in - let () = Utils.reject_if_tez_supplied () in - let updated_metadata = match Big_map.find_opt metadata_update.key storage.metadata with + let () = is_known_sender storage.administrator sender_not_administrator in + let () = reject_if_tez_supplied () in + let updated_metadata = match Big_map.find_opt metadata_update.key storage.metadata with | None -> Big_map.add metadata_update.key metadata_update.value storage.metadata | Some _ -> Big_map.update metadata_update.key (Some metadata_update.value) storage.metadata - in - let storage = {storage with metadata = updated_metadata } in - no_op storage + in + let storage = {storage with metadata = updated_metadata } in + no_op storage [@inline] let remove_metadata (key: string) (storage:storage) : result = - let () = Utils.is_administrator storage.administrator in - let () = Utils.reject_if_tez_supplied () in - let updated_metadata = Big_map.remove key storage.metadata in - let storage = {storage with metadata = updated_metadata } in - no_op storage - -[@inline] -let set_deposit_status - (pair_name: string) - (disabled: bool) - (storage: storage) : result = - let () = Utils.is_administrator storage.administrator in - let () = Utils.reject_if_tez_supplied () in - let valid_swap = get_valid_swap_reduced pair_name storage in - let valid_swap = { valid_swap with is_disabled_for_deposits = disabled; } in - let valid_swaps = Map.update pair_name (Some valid_swap) storage.valid_swaps in - let storage = { storage with valid_swaps = valid_swaps; } in - no_op (storage) + let () = is_known_sender storage.administrator sender_not_administrator in + let () = reject_if_tez_supplied () in + let updated_metadata = Big_map.remove key storage.metadata in + let storage = {storage with metadata = updated_metadata } in + no_op storage -[@inline] -let amend_token_and_pair_limit - (limit: nat) - (storage: storage) : result = - let () = Utils.is_administrator storage.administrator in - let () = Utils.reject_if_tez_supplied () in - let token_count = Map.size storage.valid_tokens in - let pair_count = Map.size storage.valid_swaps in - if limit < token_count then failwith Errors.cannot_reduce_limit_on_tokens_to_less_than_already_exists else - if limit < pair_count then failwith Errors.cannot_reduce_limit_on_swap_pairs_to_less_than_already_exists else - let storage = { storage with limit_on_tokens_or_pairs = limit} in - no_op (storage) [@inline] let change_deposit_time_window (new_window: nat) (storage: storage) : result = - let () = Utils.is_administrator storage.administrator in - let () = Utils.reject_if_tez_supplied () in - if new_window < Constants.minimum_deposit_time_in_seconds then failwith Errors.cannot_update_deposit_window_to_less_than_the_minimum else - if new_window > Constants.maximum_deposit_time_in_seconds then failwith Errors.cannot_update_deposit_window_to_more_than_the_maximum else + let () = is_known_sender storage.administrator sender_not_administrator in + let () = reject_if_tez_supplied () in + if new_window < minimum_deposit_time_in_seconds then failwith cannot_update_deposit_window_to_less_than_the_minimum else + if new_window > maximum_deposit_time_in_seconds then failwith cannot_update_deposit_window_to_more_than_the_maximum else let storage = { storage with deposit_time_window_in_seconds = new_window; } in no_op storage -[@view] -let get_fee_in_mutez ((), storage : unit * storage) : tez = storage.fee_in_mutez +[@inline] +let change_liquidity_injection_limit_in_seconds + (new_time_limit: nat) + (storage: storage) : result = + let () = is_known_sender storage.administrator sender_not_administrator in + let () = reject_if_tez_supplied () in + if new_time_limit > storage.deposit_time_window_in_seconds then failwith cannot_update_liquidity_injection_limit_to_more_than_deposit_window else + let storage = { storage with liquidity_injection_limit_in_seconds = new_time_limit; } in + no_op storage [@view] -let get_valid_swaps ((), storage : unit * storage) : valid_swaps = storage.valid_swaps +let get_fee_in_mutez ((), storage : unit * storage) : tez = storage.fee_in_mutez -[@view] -let get_valid_tokens ((), storage : unit * storage) : valid_tokens = storage.valid_tokens [@view] let redeemable_holdings_available ((), storage : unit * storage) : bool = @@ -1521,12 +1182,31 @@ let redeemable_holdings_available ((), storage : unit * storage) : bool = | None -> false | Some bots -> Map.fold find_non_zero_holding bots false +[@inline] +let does_batch_need_liquidity + (batch: batch) + (storage:storage): batch option = + let volumes = batch.volumes in + match batch.status with + | Open st -> let now = Tezos.get_now () in + let trig_liq = st.start_time + (int storage.liquidity_injection_limit_in_seconds) in + let batch_end = st.start_time + (int storage.deposit_time_window_in_seconds) in + if now < trig_liq && now > batch_end then (None: batch option) else + if volumes.buy_total_volume = 0n && volumes.sell_total_volume = 0n then (None: batch option) else + if volumes.buy_total_volume > 0n && volumes.sell_total_volume > 0n then (None: batch option) else + Some batch + | _ -> (None: batch option) + + + [@view] -let get_current_batches ((),storage: unit * storage) : batch list= +let get_batches_needing_liquidity ((),storage: unit * storage) : batch list= let collect_batches (acc, (_s, i) : batch list * (string * nat)) : batch list = match Big_map.find_opt i storage.batch_set.batches with | None -> acc - | Some b -> b :: acc + | Some b -> (match does_batch_need_liquidity b storage with + | None -> acc + | Some bl -> bl :: acc) in Map.fold collect_batches storage.batch_set.current_batch_indices [] @@ -1537,23 +1217,18 @@ let main (* User endpoints *) | Deposit order -> deposit order storage | Redeem -> redeem storage - | RedeemByBatch i -> redeem_by_batch i storage | Cancel pair -> cancel pair storage (* Maintenance endpoint *) | Tick r -> tick r storage (* Admin endpoints *) | Change_fee new_fee -> change_fee new_fee storage + | Change_liquidity_injection_time_limit new_time_limit -> change_liquidity_injection_limit_in_seconds new_time_limit storage | Change_admin_address new_admin_address -> change_admin_address new_admin_address storage | Change_marketmaker_address new_mm_address -> change_mm_address new_mm_address storage + | Change_tokenmanager_address new_tm_address -> change_tm_address new_tm_address storage | Change_fee_recipient_address new_fee_recipient_address -> change_fee_recipient_address new_fee_recipient_address storage - | Add_token_swap_pair valid_swap -> add_token_swap_pair valid_swap storage - | Remove_token_swap_pair valid_swap -> remove_token_swap_pair valid_swap storage - | Change_oracle_source_of_pair source_update -> change_oracle_price_source source_update storage - | Amend_token_and_pair_limit l -> amend_token_and_pair_limit l storage | Add_or_update_metadata mu -> add_or_update_metadata mu storage | Remove_metadata k -> remove_metadata k storage - | Enable_swap_pair_for_deposit pair_name -> set_deposit_status pair_name false storage - | Disable_swap_pair_for_deposit pair_name -> set_deposit_status pair_name true storage | Change_deposit_time_window t -> change_deposit_time_window t storage diff --git a/batcher/errors.mligo b/batcher/errors.mligo index d53824ed..a223dbb6 100644 --- a/batcher/errors.mligo +++ b/batcher/errors.mligo @@ -1,4 +1,3 @@ - [@inline] let no_rate_available_for_swap : nat = 100n [@inline] let invalid_token_address : nat = 101n [@inline] let invalid_tezos_address : nat = 102n @@ -61,3 +60,15 @@ [@inline] let unable_to_get_oracle_price = 159n [@inline] let contract_does_not_exist = 160n [@inline] let unable_to_call_on_chain_view = 161n +[@inline] let unable_to_get_tokens_from_token_manager = 162n +[@inline] let vault_name_is_incorrect = 163n +[@inline] let unable_to_get_native_token_from_vault = 164n +[@inline] let unable_to_get_swaps_from_token_manager = 165n +[@inline] let unable_to_get_vaults_from_marketmaker = 166n +[@inline] let unable_to_get_current_batches_from_batcher = 167n +[@inline] let sender_not_marketmaker : nat = 168n +[@inline] let cannot_update_liquidity_injection_limit_to_more_than_deposit_window= 169n +[@inline] let unable_to_get_balance_response_fa2_entrypoint_from_vault : nat = 170n +[@inline] let unable_to_get_balance_of_entrypoint_from_fa2_token : nat = 171n +[@inline] let unable_to_get_balance_response_fa12_entrypoint_from_vault : nat = 172n +[@inline] let unable_to_get_get_balance_entrypoint_from_fa12_token : nat = 173n diff --git a/batcher/ligo.json b/batcher/ligo.json new file mode 100644 index 00000000..b0affbae --- /dev/null +++ b/batcher/ligo.json @@ -0,0 +1,10 @@ +{ + "name": "batcher", + "version": "1.0.0", + "author": "batcher ", + "description": "Batcher for exchanging tokens", + "dependencies": { + "@ligo/math-lib": "^1.1.0", + "ligo-breathalyzer": "^1.4.0" + } +} diff --git a/batcher/marketmaker.mligo b/batcher/marketmaker.mligo index eb884c75..9b37a879 100644 --- a/batcher/marketmaker.mligo +++ b/batcher/marketmaker.mligo @@ -1,663 +1,187 @@ #import "@ligo/math-lib/rational/rational.mligo" "Rational" -#import "types.mligo" "Types" -#import "utils.mligo" "Utils" -#import "errors.mligo" "Errors" +#include "types.mligo" +#include "utils.mligo" +#include "errors.mligo" +module MarketMaker = struct -type token = Types.token -type side = Types.side -type token_amount = Types.token_amount -type token_amount_map = Types.token_amount_map -type market_maker_vault = Types.market_maker_vault -type market_vaults = Types.market_vaults -type market_vault_holding = Types.market_vault_holding -type valid_swaps = Types.valid_swaps -type valid_swap = Types.valid_swap -type valid_swap_reduced = Types.valid_swap_reduced -type valid_tokens = Types.valid_tokens -type exchange_rate = Types.exchange_rate -type user_holding_key = Types.user_holding_key -type user_holdings = Types.user_holdings -type vault_holdings = Types.vault_holdings -type metadata = Types.metadata -type metadata_update = Types.metadata_update -type swap_order = Types.swap_order -type batch = Types.batch -type batch_set = Types.batch_set -type external_swap_order = Types.external_swap_order - -module Storage = struct - type t = { - metadata: metadata; - valid_tokens : valid_tokens; - valid_swaps : valid_swaps; + type storage = { administrator : address; batcher : address; - limit_on_tokens_or_pairs : nat; - vaults: market_vaults; - last_holding_id: nat; - user_holdings: user_holdings; - vault_holdings: vault_holdings; + tokenmanager : address; + vaults: Vaults.t; } -end -module MarketVaultUtils = struct +type result = operation list * storage [@inline] -let deposit - (deposit_address : address) - (deposited_token : token_amount) : operation list = - let treasury_vault = Utils.get_vault () in - let deposit_op = Utils.Treasury_Utils.handle_transfer deposit_address treasury_vault deposited_token in - [ deposit_op] - -let find_liquidity_amount - (rate:exchange_rate) - (total_liquidity:nat) - (volume:nat) : nat = - let rat_volume = Rational.new (int volume) in - let equiv_vol = Rational.mul rate.rate rat_volume in - let resolved_equiv_vol = Utils.get_rounded_number_lower_bound equiv_vol in - if total_liquidity > resolved_equiv_vol then resolved_equiv_vol else total_liquidity - -let create_liq_order - (bn:nat) - (non:nat) - (from:string) - (to:string) - (side:side) - (liq:nat) - (valid_tokens: valid_tokens): swap_order = - let from_token = Option.unopt (Map.find_opt from valid_tokens) in - let to_token = Option.unopt (Map.find_opt to valid_tokens) in - { - order_number = non; - batch_number = bn; - trader = Utils.get_vault (); - swap = { - from = { - token = from_token; - amount = liq; - }; - to = to_token; - }; - side=side; - tolerance = Exact; - redeemed = false; - } - - -let create_or_update_market_vault_holding - (id: nat) - (token_amount: token_amount) - (holder:address) - (previous_holding: market_vault_holding option) : market_vault_holding = - match previous_holding with - | None -> { - id = id; - token = token_amount.token.name; - holder = holder; - shares = token_amount.amount; - unclaimed = 0mutez; - } - | Some ph -> if not (ph.holder = holder) then failwith Errors.incorrect_market_vault_holder else - if not (ph.id = id) then failwith Errors.incorrect_market_vault_id else - { ph with shares = ph.shares + token_amount.amount; } - -let create_or_update_market_maker_vault - (id: nat) - (token_amount: token_amount) - (mmv_opt: market_maker_vault option) : market_maker_vault = - match mmv_opt with - | None -> { - total_shares = token_amount.amount; - holdings = Set.literal [ id ]; - native_token = token_amount; - foreign_tokens = Utils.TokenAmountMap.new; - } - | Some mmv -> let nt = mmv.native_token in - if not Utils.are_equivalent_tokens token_amount.token nt.token then failwith Errors.token_already_exists_but_details_are_different else - let shares = mmv.total_shares + token_amount.amount in - let native_token = { nt with amount = nt.amount + token_amount.amount; } in - let hldgs = if Set.mem id mmv.holdings then mmv.holdings else Set.add id mmv.holdings in - { - mmv with holdings = hldgs; total_shares = shares; native_token = native_token; - } - -let add_liquidity - (h_key: user_holding_key) - (new_holding_id: nat) - (holder: address) - (token_amount: token_amount) - (storage: Storage.t): Storage.t = - let token_name = token_amount.token.name in - let vault_opt = Big_map.find_opt token_name storage.vaults in - let new_holding = { - id = new_holding_id; - token = token_amount.token.name; - holder = holder; - shares = token_amount.amount; - unclaimed = 0mutez; - } in - let vault = create_or_update_market_maker_vault new_holding_id token_amount vault_opt in - let vts = Big_map.update token_name (Some vault) storage.vaults in - let uhs = Big_map.add h_key new_holding_id storage.user_holdings in - let vhs = Big_map.add new_holding_id new_holding storage.vault_holdings in - { storage with - vaults = vts; - vault_holdings = vhs; - user_holdings = uhs; - last_holding_id = new_holding_id; - } - - -let update_liquidity - (id: nat) - (holder: address) - (token_amount: token_amount) - (storage: Storage.t): Storage.t = - let token_name = token_amount.token.name in - let vault_opt = Big_map.find_opt token_name storage.vaults in - let vault = create_or_update_market_maker_vault id token_amount vault_opt in - let vts = Big_map.update token_name (Some vault) storage.vaults in - let vh_opt = Big_map.find_opt id storage.vault_holdings in - if vh_opt = (None: market_vault_holding option) then failwith Errors.unable_to_find_vault_holding_for_id else - let vh = Option.unopt vh_opt in - let () = Utils.assert_or_fail_with (vh.holder = holder) Errors.user_in_holding_is_incorrect in - let vh = {vh with shares = vh.shares + token_amount.amount; } in - let vhs = Big_map.update id (Some vh) storage.vault_holdings in - { storage with - vaults = vts; - vault_holdings = vhs; - user_holdings = storage.user_holdings; - } - -let add_liquidity_to_market_maker - (holder: address) - (token_amount: token_amount) - (storage: Storage.t): ( operation list * Storage.t) = - let ops = deposit holder token_amount in - let last_holding_id = storage.last_holding_id in - let next_holding_id = last_holding_id + 1n in - let h_key = (holder, token_amount.token.name) in - let uh_opt = Big_map.find_opt h_key storage.user_holdings in - let storage = match uh_opt with - | None -> add_liquidity h_key next_holding_id holder token_amount storage - | Some uh_id -> update_liquidity uh_id holder token_amount storage - in - (ops, storage) - -let collect_from_vault - (perc_share: Rational.t) - (ta: token_amount) - (tam: token_amount_map): (token_amount * token_amount_map) = - let rat_amt = Rational.new (int ta.amount) in - let rat_amount_to_redeem = Rational.mul perc_share rat_amt in - let amount_to_redeem = Utils.get_rounded_number_lower_bound rat_amount_to_redeem in - if amount_to_redeem > ta.amount then failwith Errors.holding_amount_to_redeem_is_larger_than_holding else - let rem =abs ((int ta.amount) - amount_to_redeem) in - let ta_rem = {ta with amount = rem; } in - let ta_red = {ta with amount = amount_to_redeem; } in - let tam = if ta_red.amount = 0n then tam else Utils.TokenAmountMap.increase ta_red tam in - (ta_rem, tam) - -let collect_tokens_for_redemption - (holding_id: nat) - (perc_share: Rational.t) - (shares: nat) - (vault: market_maker_vault) = - let tokens = Utils.TokenAmountMap.new in - let (native,tokens) = collect_from_vault perc_share vault.native_token tokens in - let acc: (Rational.t * token_amount_map * token_amount_map) = (perc_share, Utils.TokenAmountMap.new, tokens ) in - let collect_redemptions = fun ((ps,rem_t,red_t),(_tn,ta):(Rational.t * token_amount_map * token_amount_map) * (string * token_amount)) -> - let (ta_rem,red_t) = collect_from_vault ps ta red_t in - let rem_t = Utils.TokenAmountMap.increase ta_rem rem_t in - (ps,rem_t,red_t) - in - let (_, foreign_tokens, tokens) = Map.fold collect_redemptions vault.foreign_tokens acc in - if shares > vault.total_shares then failwith Errors.holding_shares_greater_than_total_shares_remaining else - let rem_shares = abs (vault.total_shares - shares) in - let holdings = Set.remove holding_id vault.holdings in - ({ vault with native_token = native; foreign_tokens = foreign_tokens; holdings = holdings; total_shares = rem_shares;} ,tokens) - -let remove_liquidity - (id: nat) - (holder: address) - (token_name: string) - (h_key: user_holding_key) - (vault: market_maker_vault) - (storage: Storage.t): (operation list * Storage.t) = - let vaults = storage.vaults in - let user_holdings = storage.user_holdings in - let vault_holdings = storage.vault_holdings in - let holding = Utils.find_or_fail_with id Errors.unable_to_find_vault_holding_for_id vault_holdings in - let () = Utils.assert_or_fail_with (holder = holding.holder) Errors.user_in_holding_is_incorrect in - let unclaimed_tez = holding.unclaimed in - let shares = holding.shares in - let total_shares = vault.total_shares in - let perc_share = Rational.div (Rational.new (int shares)) (Rational.new (int total_shares)) in - let (vault, tam) = collect_tokens_for_redemption id perc_share shares vault in - let tez_op = Utils.Treasury_Utils.transfer_fee holder unclaimed_tez in - let treasury_vault = Utils.get_vault () in - let tok_ops = Utils.Treasury_Utils.transfer_holdings treasury_vault holder tam in - let vaults = Big_map.update token_name (Some vault) vaults in - let user_holdings = Big_map.remove h_key user_holdings in - let vault_holdings = Big_map.remove id vault_holdings in - let ops: operation list =if unclaimed_tez > 0mutez then tez_op :: tok_ops else tok_ops in - let storage = { storage with user_holdings = user_holdings; vault_holdings = vault_holdings; vaults = vaults; } in - (ops, storage) - -let remove_liquidity_from_market_maker - (holder: address) - (token_name: string) - (storage: Storage.t): ( operation list * Storage.t) = - let h_key = (holder, token_name) in - let uh_opt: nat option = Big_map.find_opt h_key storage.user_holdings in - let v_opt = Big_map.find_opt token_name storage.vaults in - let () = Utils.assert_some_or_fail_with uh_opt Errors.no_holding_in_market_maker_for_holder in - let () = Utils.assert_some_or_fail_with v_opt Errors.no_market_vault_for_token in - remove_liquidity (Option.unopt uh_opt) holder token_name h_key (Option.unopt v_opt) storage - -let claim_from_holding - (holder:address) - (id:nat) - (holding: market_vault_holding) - (storage: Storage.t) : (operation list * Storage.t) = - let unclaimed_tez = holding.unclaimed in - if unclaimed_tez = 0mutez then failwith Errors.no_holdings_to_claim else - let holding = { holding with unclaimed = 0tez; } in - let tez_op = Utils.Treasury_Utils.transfer_fee holder unclaimed_tez in - let vault_holdings = Big_map.update id (Some holding) storage.vault_holdings in - let storage = {storage with vault_holdings = vault_holdings;} in - ([tez_op], storage) - - -let claim_rewards - (holder:address) - (token_name:string) - (storage:Storage.t) : (operation list * Storage.t) = - let h_key = (holder, token_name) in - match Big_map.find_opt h_key storage.user_holdings with - | None -> failwith Errors.no_holdings_to_claim - | Some id -> (match Big_map.find_opt id storage.vault_holdings with - | None -> failwith Errors.no_holdings_to_claim - | Some h ->claim_from_holding holder id h storage) - -end - -module BatcherUtils = struct +let no_op (s : storage) : result = (([] : operation list), s) +(* [@entry] *) [@inline] -let get_contract_entrypoint - (entrypoint: string) - (batcher:address) = - match Tezos.get_entrypoint_opt entrypoint batcher with - Some contract -> contract - | None -> failwith Errors.entrypoint_does_not_exist - -end - -module TickUtils = struct - -let exchange_amount - (native_amount_to_move: token_amount) - (foreign_amount_to_move:token_amount) - (native_token_amount:token_amount) - (foreign_token_amount:token_amount) - (opposing_vault_foreign_token_amount:token_amount) - (opposing_vault_native_token_amount:token_amount) : (token_amount * token_amount * token_amount * token_amount) = - let native_token_amount = Utils.add_token_amounts native_token_amount native_amount_to_move in - let opposing_vault_native_token_amount = Utils.subtract_token_amounts opposing_vault_native_token_amount native_amount_to_move in - let foreign_token_amount =Utils.subtract_token_amounts foreign_token_amount foreign_amount_to_move in - let opposing_vault_foreign_token_amount = Utils.add_token_amounts opposing_vault_foreign_token_amount foreign_amount_to_move in - native_token_amount, foreign_token_amount, opposing_vault_foreign_token_amount, opposing_vault_native_token_amount - -let balance_token_amounts_with_rate - (native_token_amount:token_amount) - (foreign_token_amount:token_amount) - (opposing_vault_foreign_token_amount:token_amount) - (opposing_vault_native_token_amount:token_amount) - (vsr: valid_swap_reduced) - (valid_tokens:valid_tokens): (token_amount * token_amount * token_amount * token_amount) = - (* Get oracle price for the pair *) - let (ts,pu) = Utils.get_oracle_price Errors.unable_to_get_oracle_price vsr in - let vs = Utils.valid_swap_reduced_to_valid_swap vsr 1n valid_tokens in - let rate = Utils.convert_oracle_price vsr.oracle_precision vs.swap ts pu valid_tokens in - (* Check if exchange direction is the same as that of the swap; i.e. if tzBTC/USDT has from as tzBTC and to as USDT *) - if vsr.swap.from = native_token_amount.token.name && vsr.swap.to = foreign_token_amount.token.name then - (* 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 - else - native_token_amount, foreign_token_amount, opposing_vault_foreign_token_amount, opposing_vault_native_token_amount - - -let balance_token_amounts - (native_token_amount:token_amount) - (foreign_token_amount:token_amount) - (opposing_vault_foreign_token_amount:token_amount) - (opposing_vault_native_token_amount:token_amount) - (valid_tokens: valid_tokens) - (valid_swaps: valid_swaps) : (token_amount * token_amount * token_amount * token_amount) = - let pair_name = Utils.find_lexicographical_pair_name native_token_amount.token.name foreign_token_amount.token.name in - match Map.find_opt pair_name valid_swaps with - | None -> native_token_amount, foreign_token_amount, opposing_vault_foreign_token_amount, opposing_vault_native_token_amount - | Some vsr -> balance_token_amounts_with_rate native_token_amount foreign_token_amount opposing_vault_foreign_token_amount opposing_vault_native_token_amount vsr valid_tokens - -[@inline] -let find_and_rebalance_foreign_vault - (native_token_vault: market_maker_vault) - (foreign_token_vault: market_maker_vault) - (foreign_token_amount: token_amount) - (valid_swaps: valid_swaps) - (valid_tokens: valid_tokens) - (market_vaults: market_vaults ) : (market_maker_vault * market_vaults) = - match Map.find_opt native_token_vault.native_token.token.name foreign_token_vault.foreign_tokens with - | None -> (native_token_vault,market_vaults) - (* This is the native toen held as a foreign token in the foreign token vault; i.e. tzBTC held in the foreign tokens of the USDT vault *) - | Some ovnta -> let nta = native_token_vault.native_token in (*This is the native token of the vault that needs to be balanced i.e. tzBTC *) - let fta = foreign_token_amount in (* This is the foreign token in the vault that needs toe b balanced, i.e. USDT held as a foreign token in the tzBTC vault *) - let ovfta = foreign_token_vault.native_token in (* This is the foreign token in the foreign vault (but native in that vault), i.e, USDT in the USDT vault *) - let nta,fta,ovfta,ovnta = balance_token_amounts nta fta ovfta ovnta valid_tokens valid_swaps in - let updated_vault_foreign_tokens = Map.update fta.token.name (Some fta) native_token_vault.foreign_tokens in - let updated_vault = { native_token_vault with native_token = nta; foreign_tokens = updated_vault_foreign_tokens;} in - let opposing_vault_foreign_tokens = Map.update ovnta.token.name (Some ovnta) foreign_token_vault.foreign_tokens in - let updated_foreign_vault = { foreign_token_vault with native_token = ovfta; foreign_tokens = opposing_vault_foreign_tokens; } in - let market_vaults = Big_map.update updated_vault.native_token.token.name (Some updated_vault) market_vaults in - let market_vaults = Big_map.update updated_foreign_vault.native_token.token.name (Some updated_foreign_vault) market_vaults in - (updated_vault, market_vaults) - - +let change_admin_address + (new_admin_address: address) + (storage: storage) : operation list * storage = + 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 +(* [@entry] *) [@inline] -let rebalance_vault - (vault_to_balance: market_maker_vault) - (valid_swaps: valid_swaps) - (valid_tokens: valid_tokens) - (market_vaults: market_vaults ): market_vaults = - let rebalance = fun ((vtb,mvs),(foreign_token_name,foreign_token_amount):(market_maker_vault * market_vaults) * (string * token_amount)) -> - match Big_map.find_opt foreign_token_name market_vaults with - | None -> (vtb,mvs) - | Some foreign_token_vault -> find_and_rebalance_foreign_vault vault_to_balance foreign_token_vault foreign_token_amount valid_swaps valid_tokens market_vaults - in - let (_,market_vaults) = Map.fold rebalance vault_to_balance.foreign_tokens (vault_to_balance,market_vaults) in - market_vaults - - +let change_batcher_address + (new_batcher_address: address) + (storage: storage) : operation list * storage = + 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 +(* [@entry] *) [@inline] -let rebalance_vaults - (storage: Storage.t): Storage.t = - let get_token_names = fun ((l,(tn,_t)):(string list * (string * token))) -> tn :: l in - let tokens = Map.fold get_token_names storage.valid_tokens [] in - let rebalance_vault = fun ((s,tn):(Storage.t * string)) -> - match Big_map.find_opt tn s.vaults with - | Some v -> let mvaults = rebalance_vault v s.valid_swaps s.valid_tokens s.vaults in - {s with vaults = mvaults; } - | None -> s - in - List.fold rebalance_vault tokens storage +let change_tokenmanager_address + (new_tm_address: address) + (storage: storage) : operation list * storage = + 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 -[@inline] -let redeem_holdings - (storage: Storage.t): (operation option * Storage.t) = - let redeem = match Tezos.get_entrypoint_opt "%redeem" storage.batcher with - | Some ep -> ep - | None -> failwith Errors.entrypoint_does_not_exist - in - let op = Tezos.transaction () 0mutez redeem in - Some op,storage +(* [@entry] *) +[@inline] +let add_vault + (vault_name: string) + (vault_address: address) + (storage: storage) : operation list * storage = + let () = is_known_sender storage.administrator sender_not_administrator in + let () = reject_if_tez_supplied () in + let nt = get_native_token_from_vault vault_address in + if not (nt.name = vault_name) then failwith vault_name_is_incorrect else + let vaults = Vaults.upsert vault_name vault_address storage.vaults in + let storage = { storage with vaults = vaults; } in + no_op storage +(* [@entry] *) [@inline] -let redeem - (storage: Storage.t): (operation option * Storage.t) = - if Utils.has_redeemable_holdings storage.batcher then redeem_holdings storage else None,storage +let remove_vault + (vault_name: string) + (storage: storage) : operation list * storage = + let () = is_known_sender storage.administrator sender_not_administrator in + let () = reject_if_tez_supplied () in + match Vaults.find_opt vault_name storage.vaults with + | None -> failwith vault_name_is_incorrect + | Some va -> let nt = get_native_token_from_vault va in + if not (nt.name = vault_name) then failwith vault_name_is_incorrect else + let vaults = Vaults.remove vault_name storage.vaults in + let storage = { storage with vaults = vaults; } in + no_op storage -[@inline] -let construct_order - (side:side) - (from_token:token) - (to_token:token) - (amount:nat) : external_swap_order = - let side_nat = Utils.side_to_nat side in - let tolerance = Utils.tolerance_to_nat Exact in - let swap = { - from= { - token = from_token; - amount= amount - }; - to = to_token; - } in - { - swap = swap; - created_at = Tezos.get_now (); - side = side_nat; - tolerance = tolerance; - } -[@inline] -let find_available_liquidity - (token:token) - (volume:nat) - (vaults:market_vaults): nat * market_vaults = - match Big_map.find_opt token.name vaults with - | None -> failwith Errors.no_market_vault_for_token - | Some v -> let nt = v.native_token in - let avail_liq = v.native_token.amount in - let liq = if volume < avail_liq then volume else avail_liq in - let nt = { nt with amount = abs(nt.amount - liq); } in - let v = { v with native_token = nt; } in - let uvs = Big_map.update token.name (Some v) vaults in - liq, uvs [@inline] -let inject_buy_side_liq - (sell_side_volume:nat) - (batcher:address) - (batch:batch) - (storage:Storage.t) : (operation list * market_vaults) = - let (buy_token,sell_token) = batch.pair in - let buy_token_opt = Map.find_opt buy_token storage.valid_tokens in - let sell_token_opt = Map.find_opt sell_token storage.valid_tokens in - match (buy_token_opt,sell_token_opt) with - | Some bt, Some st -> let liq,vaults = find_available_liquidity bt sell_side_volume storage.vaults in - if liq = 0n then - ([],vaults) - else - let order = construct_order Buy bt st liq in - let ops = Utils.execute_deposit order batcher in - (ops, vaults) - | _, _ -> failwith Errors.token_name_not_in_list_of_valid_tokens - -[@inline] -let inject_sell_side_liq - (buy_side_volume:nat) - (batcher:address) - (batch:batch) - (storage:Storage.t) : (operation list * market_vaults) = - let (buy_token,sell_token) = batch.pair in - let buy_token_opt = Map.find_opt buy_token storage.valid_tokens in - let sell_token_opt = Map.find_opt sell_token storage.valid_tokens in - match (buy_token_opt,sell_token_opt) with - | Some bt, Some st -> let liq, vaults = find_available_liquidity st buy_side_volume storage.vaults in - if liq = 0n then - ([],vaults) - else - let order = construct_order Sell st bt liq in - let ops = Utils.execute_deposit order batcher in - (ops, vaults) - | _, _ -> failwith Errors.token_name_not_in_list_of_valid_tokens +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 inject_liquidity_if_required - (batcher:address) - (batch:batch) - (storage: Storage.t): (operation list * market_vaults) = - if batch.market_vault_used then ([], storage.vaults) else - 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 _ -> ([], storage.vaults) - | Some bv, None -> inject_sell_side_liq bv batcher batch storage - | None, Some sv -> inject_buy_side_liq sv batcher batch storage - | None, None -> ([], storage.vaults) +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) + (opposing_token: string) + (opposing_volume: nat) + (ops: operation list) + (valid_tokens:ValidTokens.t_map) + (valid_swaps:ValidSwaps.t_map) + (vaults: Vaults.t) : operation list = + let liq_token_opt = Map.find_opt liq_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 -> 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 deposit - (batcher:address) - (batches: batch list) - (storage: Storage.t): (operation list * Storage.t) = - let inject = fun ((ol,s),rb:((operation list* Storage.t) * batch)) -> - let (iops,vaults) = inject_liquidity_if_required batcher rb s in - let s = {s with vaults = vaults; } in - (Utils.concatlo iops ol,s) - in - let (deposit_ops,storage) = List.fold inject batches ([],storage) in - deposit_ops, storage +let tick + (storage: storage) : result = + let batches_needing_liquidity = BatcherUtils.get_batches_needing_liquidity storage.batcher in + 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 (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 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 + in + let ops = List.fold_left request_liquidity ([]:operation list) batches_needing_liquidity in + ops, storage end -type result = operation list * Storage.t - -[@inline] -let no_op (s : Storage.t) : result = (([] : operation list), s) type entrypoint = - | RemoveLiquidity of string - | AddLiquidity of token_amount - | Claim of string - | Tick | Change_admin_address of address | Change_batcher_address of address - -(* Add Liquidity into a market vault *) -[@inline] -let add_liquidity - (token_amount: token_amount) - (storage: Storage.t) : result = - let () = Utils.reject_if_tez_supplied () in - let holder = Tezos.get_sender () in - MarketVaultUtils.add_liquidity_to_market_maker holder token_amount storage - -(* Add Liquidity into a market vault *) -[@inline] -let claim - (token_name: string) - (storage: Storage.t) : result = - let () = Utils.reject_if_tez_supplied () in - let holder = Tezos.get_sender () in - MarketVaultUtils.claim_rewards holder token_name storage - -(* Remove Liquidity into a market vault *) -[@inline] -let remove_liquidity - (token_name: string) - (storage: Storage.t) : result = - let () = Utils.reject_if_tez_supplied () in - let holder = Tezos.get_sender () in - MarketVaultUtils.remove_liquidity_from_market_maker holder token_name storage - -[@inline] -let change_admin_address - (new_admin_address: address) - (storage: Storage.t) : result = - let () = Utils.is_administrator storage.administrator in - let () = Utils.reject_if_tez_supplied () in - let storage = { storage with administrator = new_admin_address; } in - no_op storage - -[@inline] -let change_batcher_address - (new_batcher_address: address) - (storage: Storage.t) : result = - let () = Utils.is_administrator storage.administrator in - let () = Utils.reject_if_tez_supplied () in - let storage = { storage with batcher = new_batcher_address; } in - no_op storage - -[@inline] -let get_batches - (failure_code: nat) - (batcher: address) : batch list = - match Tezos.call_view "get_current_batches" () batcher with - | Some bl -> bl - | None -> failwith failure_code - -[@inline] -let tick - (storage: Storage.t) : result = - let () = Utils.reject_if_tez_supplied () in - let batches = get_batches Errors.unable_to_get_batches_from_batcher storage.batcher in - let storage = TickUtils.rebalance_vaults storage in - let (redeem_op_opt, storage) = TickUtils.redeem storage in - let (deposit_ops, storage) = TickUtils.deposit storage.batcher batches storage in - let ops = match redeem_op_opt with - | Some op -> op :: deposit_ops - | None -> deposit_ops - in - (ops, storage) - -type vault_summary = (string, market_maker_vault) map -type holding_summary = (string, market_vault_holding) map - -type vault_holdings_summary = - { - holdings: holding_summary; - vaults: vault_summary; - } - - -[@view] -let get_market_vault_holdings ((), storage : unit * Storage.t) : vault_holdings_summary = - let vaults = storage.vaults in - let user_holdings = storage.user_holdings in - let vault_holdings = storage.vault_holdings in - let holder = Tezos.get_sender () in - let get_tokens = fun (l,(tn,_vt): string list * (string * token)) -> tn :: l in - let tokens = Map.fold get_tokens storage.valid_tokens [] in - let get_vaults = fun (vs,t: vault_summary * string) -> - match Big_map.find_opt t vaults with - | None -> vs - | Some v -> Map.add t v vs - in - let vaults = List.fold get_vaults tokens (Map.empty: vault_summary) in - let get_holdings = fun (hs,t: holding_summary * string) -> - let key = (holder, t) in - match Big_map.find_opt key user_holdings with - | None -> hs - | Some id -> (match Big_map.find_opt id vault_holdings with - | None -> hs - | Some h -> Map.add t h hs) - in - let holdings = List.fold get_holdings tokens (Map.empty: holding_summary) in - { - holdings = holdings; - vaults = vaults; - } + | Change_tokenmanager_address of address + | AddVault of string * address + | RemoveVault of string + | Tick let main - (action, storage : entrypoint * Storage.t) : operation list * Storage.t = + (action, storage : entrypoint * MarketMaker.storage) : operation list * MarketMaker.storage = match action with (* Market Liquidity endpoint *) - | AddLiquidity t -> add_liquidity t storage - | RemoveLiquidity tn -> remove_liquidity tn storage - | Claim tn -> claim tn storage - | Tick -> tick storage + | AddVault (n,a) -> MarketMaker.add_vault n a storage + | RemoveVault n -> MarketMaker.remove_vault n storage + | Tick -> MarketMaker.tick storage (* Admin endpoints *) - | Change_admin_address new_admin_address -> change_admin_address new_admin_address storage - | Change_batcher_address new_batcher_address -> change_batcher_address new_batcher_address storage + | Change_admin_address new_admin_address -> MarketMaker.change_admin_address new_admin_address storage + | Change_batcher_address new_batcher_address -> MarketMaker.change_batcher_address new_batcher_address storage + | Change_tokenmanager_address new_tokenmanager_address -> MarketMaker.change_tokenmanager_address new_tokenmanager_address storage diff --git a/batcher/michelson/batcher-ghostnet.tz b/batcher/michelson/batcher-ghostnet.tz new file mode 100644 index 00000000..6b53cd12 --- /dev/null +++ b/batcher/michelson/batcher-ghostnet.tz @@ -0,0 +1,4808 @@ +{ parameter + (or (or (or (or (pair %add_or_update_metadata (string %key) (bytes %value)) + (pair %cancel string string)) + (or (address %change_admin_address) (nat %change_deposit_time_window))) + (or (or (mutez %change_fee) (address %change_fee_recipient_address)) + (or (nat %change_liquidity_injection_time_limit) + (address %change_marketmaker_address)))) + (or (or (or (address %change_tokenmanager_address) + (pair %deposit + (pair %swap + (pair %from + (pair %token + (nat %token_id) + (string %name) + (option %address address) + (nat %decimals) + (option %standard string)) + (nat %amount)) + (pair %to + (nat %token_id) + (string %name) + (option %address address) + (nat %decimals) + (option %standard string))) + (timestamp %created_at) + (nat %side) + (nat %tolerance))) + (or (unit %redeem) (string %remove_metadata))) + (string %tick))) ; + storage + (pair (pair (pair (pair (address %administrator) + (pair %batch_set + (map %current_batch_indices string nat) + (big_map %batches + nat + (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))))) + (nat %deposit_time_window_in_seconds) + (mutez %fee_in_mutez)) + (pair (address %fee_recipient) (nat %last_order_number)) + (nat %limit_on_tokens_or_pairs) + (nat %liquidity_injection_limit_in_seconds)) + (pair (pair (address %marketmaker) (big_map %metadata string bytes)) + (big_map %rates_current + string + (pair (pair %swap (string %from) (string %to)) + (pair %rate (int %p) (int %q)) + (timestamp %when))) + (address %tokenmanager)) + (big_map %user_batch_ordertypes + address + (map nat + (map (pair (or %side (unit %buy) (unit %sell)) + (or %tolerance (or (unit %exact) (unit %minus)) (unit %plus))) + nat)))) ; + code { PUSH int 1 ; + PUSH int 10000 ; + PAIR ; + PUSH int 1 ; + PUSH int 10001 ; + PAIR ; + DUP 2 ; + CAR ; + DUP 2 ; + CDR ; + MUL ; + DIG 2 ; + CDR ; + DIG 2 ; + CAR ; + MUL ; + PAIR ; + 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 } ; + LAMBDA + (pair (pair (pair nat string (option address) nat (option string)) nat) + (map string (pair (pair nat string (option address) nat (option string)) nat))) + (map string (pair (pair nat string (option address) nat (option string)) nat)) + { UNPAIR ; + SWAP ; + UNIT ; + RIGHT unit ; + DIG 2 ; + DUP ; + CAR ; + GET 3 ; + DUP 4 ; + DUP 2 ; + GET ; + IF_NONE + { DIG 2 ; DROP ; SWAP ; SOME ; SWAP ; UPDATE } + { DIG 3 ; + IF_LEFT + { DROP ; + DUP ; + CDR ; + DUP 4 ; + CDR ; + COMPARE ; + GT ; + IF { DROP ; PUSH nat 111 ; FAILWITH } + { DUP 3 ; CDR ; SWAP ; CDR ; SUB ; ABS } } + { DROP ; CDR ; DUP 3 ; CDR ; ADD } ; + DIG 3 ; + DIG 3 ; + DIG 2 ; + UPDATE 2 ; + SOME ; + DIG 2 ; + UPDATE } } ; + PUSH int 1 ; + PUSH int 10000 ; + PAIR ; + PUSH int 1 ; + PUSH int 10001 ; + PAIR ; + DUP 2 ; + CAR ; + DUP 2 ; + CDR ; + MUL ; + DIG 2 ; + CDR ; + DIG 2 ; + CAR ; + MUL ; + PAIR ; + DIG 4 ; + UNPAIR ; + IF_LEFT + { DIG 2 ; + DIG 4 ; + DIG 5 ; + DROP 3 ; + IF_LEFT + { IF_LEFT + { IF_LEFT + { DIG 2 ; + DROP ; + DUP 2 ; + CAR ; + CAR ; + CAR ; + CAR ; + SENDER ; + COMPARE ; + EQ ; + IF {} { PUSH nat 114 ; FAILWITH } ; + PUSH mutez 1 ; + AMOUNT ; + COMPARE ; + LT ; + IF {} { PUSH nat 118 ; FAILWITH } ; + DUP 2 ; + DUP 3 ; + CDR ; + DUP ; + CAR ; + DUP ; + CAR ; + DUP 6 ; + CDR ; + CAR ; + CAR ; + CDR ; + DUP 6 ; + CAR ; + GET ; + IF_NONE + { DIG 5 ; + CDR ; + CAR ; + CAR ; + CDR ; + DUP 6 ; + CDR ; + DIG 6 ; + CAR ; + SWAP ; + SOME ; + SWAP ; + UPDATE } + { DROP ; + DIG 5 ; + CDR ; + CAR ; + CAR ; + CDR ; + DUP 6 ; + CDR ; + SOME ; + DIG 6 ; + CAR ; + UPDATE } ; + UPDATE 2 ; + UPDATE 1 ; + UPDATE 1 ; + UPDATE 2 ; + NIL operation ; + PAIR } + { PUSH mutez 1 ; + AMOUNT ; + COMPARE ; + LT ; + IF {} { PUSH nat 118 ; FAILWITH } ; + SENDER ; + DUP 2 ; + UNPAIR ; + DUP 5 ; + CDR ; + CAR ; + CDR ; + CDR ; + 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 } {} ; + 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 + { DROP 4 ; PUSH nat 117 ; FAILWITH } + { DUP 4 ; + CDR ; + CAR ; + CDR ; + CDR ; + 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 2 ; + CAR ; + DUP 2 ; + DUP 2 ; + CAR ; + GET ; + IF_NONE { PUSH nat 111 ; FAILWITH } {} ; + DUG 2 ; + CDR ; + GET ; + IF_NONE { PUSH nat 111 ; FAILWITH } {} ; + NOW ; + DUP 7 ; + CAR ; + CAR ; + CAR ; + CDR ; + DUP ; + CDR ; + DUP 2 ; + CAR ; + DUP 9 ; + UNPAIR ; + DUP ; + DUP 3 ; + COMPARE ; + GT ; + IF { PUSH string "/" ; CONCAT ; SWAP ; CONCAT } + { SWAP ; PUSH string "/" ; CONCAT ; SWAP ; CONCAT } ; + GET ; + IF_NONE { PUSH nat 0 } {} ; + GET ; + IF_NONE + { PUSH nat 0 ; + DUP 2 ; + CAR ; + ITER { CDR ; DUP 2 ; DUP 2 ; COMPARE ; GT ; IF { SWAP ; DROP } { DROP } } ; + PUSH nat 1 ; + ADD ; + NONE address ; + PUSH nat 0 ; + DIG 9 ; + PUSH nat 0 ; + PUSH nat 0 ; + PUSH nat 0 ; + PUSH nat 0 ; + PUSH nat 0 ; + PUSH nat 0 ; + PUSH nat 0 ; + PUSH nat 0 ; + PAIR 8 ; + DIG 6 ; + RIGHT + (or (pair (pair timestamp + (pair (pair nat nat nat) + (or (or unit unit) unit) + (pair nat nat nat nat) + (pair (pair string string) (pair int int) timestamp))) + (pair (pair string string) (pair int int) timestamp)) + (pair timestamp timestamp)) ; + DIG 5 ; + PAIR 6 ; + DUP 7 ; + DUP 3 ; + DUP 4 ; + CDR ; + DUP 4 ; + SOME ; + DUP 5 ; + CAR ; + UPDATE ; + UPDATE 2 ; + DIG 3 ; + CAR ; + DUP 4 ; + CAR ; + SOME ; + DUP 5 ; + GET 7 ; + UNPAIR ; + DUP ; + DUP 3 ; + COMPARE ; + GT ; + IF { PUSH string "/" ; CONCAT ; SWAP ; CONCAT } + { SWAP ; PUSH string "/" ; CONCAT ; SWAP ; CONCAT } ; + UPDATE ; + UPDATE 1 } + { DUP 9 ; + CAR ; + CAR ; + CDR ; + CAR ; + DUP 2 ; + GET 3 ; + IF_LEFT + { SWAP ; + DROP ; + IF_LEFT + { DROP 2 ; + PUSH nat 0 ; + DUP 2 ; + CAR ; + ITER { CDR ; DUP 2 ; DUP 2 ; COMPARE ; GT ; IF { SWAP ; DROP } { DROP } } ; + PUSH nat 1 ; + ADD ; + NONE address ; + PUSH nat 0 ; + DIG 9 ; + PUSH nat 0 ; + PUSH nat 0 ; + PUSH nat 0 ; + PUSH nat 0 ; + PUSH nat 0 ; + PUSH nat 0 ; + PUSH nat 0 ; + PUSH nat 0 ; + PAIR 8 ; + DIG 6 ; + RIGHT + (or (pair (pair timestamp + (pair (pair nat nat nat) + (or (or unit unit) unit) + (pair nat nat nat nat) + (pair (pair string string) (pair int int) timestamp))) + (pair (pair string string) (pair int int) timestamp)) + (pair timestamp timestamp)) ; + DIG 5 ; + PAIR 6 ; + DUP 7 ; + DUP 3 ; + DUP 4 ; + CDR ; + DUP 4 ; + SOME ; + DUP 5 ; + CAR ; + UPDATE ; + UPDATE 2 ; + DIG 3 ; + CAR ; + DUP 4 ; + CAR ; + SOME ; + DUP 5 ; + GET 7 ; + UNPAIR ; + DUP ; + DUP 3 ; + COMPARE ; + GT ; + IF { PUSH string "/" ; CONCAT ; SWAP ; CONCAT } + { SWAP ; PUSH string "/" ; CONCAT ; SWAP ; CONCAT } ; + UPDATE ; + UPDATE 1 } + { DIG 3 ; DIG 8 ; DROP 3 ; DUP 7 ; DIG 2 } } + { DIG 9 ; + DROP ; + DUP 2 ; + INT ; + ADD ; + DIG 4 ; + COMPARE ; + GE ; + IF { DUP 2 ; + GET 3 ; + IF_LEFT + { SWAP ; + DIG 2 ; + DROP 2 ; + IF_LEFT + { DROP ; PUSH nat 105 ; FAILWITH } + { DROP ; PUSH nat 105 ; FAILWITH } } + { SWAP ; + INT ; + DUP 2 ; + ADD ; + PAIR ; + RIGHT + (pair (pair timestamp + (pair (pair nat nat nat) + (or (or unit unit) unit) + (pair nat nat nat nat) + (pair (pair string string) (pair int int) timestamp))) + (pair (pair string string) (pair int int) timestamp)) ; + LEFT timestamp ; + UPDATE 3 ; + DUP 7 ; + PAIR } ; + UNPAIR ; + DUP 3 ; + DUP 4 ; + CDR ; + DUP 4 ; + SOME ; + DUP 5 ; + CAR ; + UPDATE ; + UPDATE 2 ; + DIG 3 ; + CAR ; + DUP 4 ; + CAR ; + SOME ; + DUP 5 ; + GET 7 ; + UNPAIR ; + DUP ; + DUP 3 ; + COMPARE ; + GT ; + IF { PUSH string "/" ; CONCAT ; SWAP ; CONCAT } + { SWAP ; PUSH string "/" ; CONCAT ; SWAP ; CONCAT } ; + UPDATE ; + UPDATE 1 } + { DROP ; DUP 7 ; DIG 2 } } } ; + DIG 2 ; + DUP ; + GET 3 ; + IF_LEFT + { IF_LEFT { DROP ; PUSH bool False } { DROP ; PUSH bool False } } + { DROP ; PUSH bool True } ; + NOT ; + IF { PUSH nat 140 ; FAILWITH } {} ; + DIG 7 ; + CDR ; + CDR ; + DUP 8 ; + GET ; + IF_NONE + { DROP 8 ; PUSH nat 139 ; FAILWITH } + { DUP 2 ; + CAR ; + DUP 2 ; + DUP 2 ; + GET ; + IF_NONE + { SWAP ; DIG 4 ; DROP 3 ; PUSH nat 139 ; FAILWITH } + { DUP 6 ; + DUP 7 ; + CDR ; + DIG 7 ; + CDR ; + CDR ; + DIG 5 ; + DIG 5 ; + NONE (map (pair (or unit unit) (or (or unit unit) unit)) nat) ; + SWAP ; + UPDATE ; + SOME ; + DUP 11 ; + UPDATE ; + UPDATE 2 ; + UPDATE 2 ; + SWAP ; + PAIR } ; + UNPAIR ; + DUP 3 ; + GET 5 ; + DUP 2 ; + ITER { UNPAIR ; + UNPAIR ; + IF_LEFT + { DROP ; + DUP 2 ; + DUP 4 ; + GET 7 ; + SUB ; + ABS ; + SWAP ; + IF_LEFT + { IF_LEFT + { DROP ; + DUP 3 ; + DIG 2 ; + DIG 3 ; + GET 3 ; + SUB ; + ABS ; + UPDATE 3 ; + SWAP ; + UPDATE 7 } + { DROP ; + DUP 3 ; + DIG 2 ; + DIG 3 ; + CAR ; + SUB ; + ABS ; + UPDATE 1 ; + SWAP ; + UPDATE 7 } } + { DROP ; + DUP 3 ; + DIG 2 ; + DIG 3 ; + GET 5 ; + SUB ; + ABS ; + UPDATE 5 ; + SWAP ; + UPDATE 7 } } + { DROP ; + DUP 2 ; + DUP 4 ; + GET 14 ; + SUB ; + ABS ; + SWAP ; + IF_LEFT + { IF_LEFT + { DROP ; + DUP 3 ; + DIG 2 ; + DIG 3 ; + GET 11 ; + SUB ; + ABS ; + UPDATE 11 ; + SWAP ; + UPDATE 14 } + { DROP ; + DUP 3 ; + DIG 2 ; + DIG 3 ; + GET 9 ; + SUB ; + ABS ; + UPDATE 9 ; + SWAP ; + UPDATE 14 } } + { DROP ; + DUP 3 ; + DIG 2 ; + DIG 3 ; + GET 13 ; + SUB ; + ABS ; + UPDATE 13 ; + SWAP ; + UPDATE 14 } } } ; + PUSH nat 1 ; + DUP 5 ; + GET 9 ; + SUB ; + ABS ; + DIG 4 ; + DIG 2 ; + UPDATE 5 ; + SWAP ; + UPDATE 9 ; + DUP 3 ; + DIG 3 ; + CAR ; + DUP ; + CAR ; + DUP ; + CAR ; + DUP 7 ; + DIG 7 ; + CDR ; + DUP 7 ; + SOME ; + DIG 7 ; + CAR ; + UPDATE ; + UPDATE 2 ; + UPDATE 2 ; + UPDATE 1 ; + UPDATE 1 ; + UPDATE 1 ; + DUP 5 ; + GET 8 ; + DUP 6 ; + GET 7 ; + DUP 7 ; + GET 5 ; + DIG 7 ; + GET 3 ; + DIG 6 ; + PUSH nat 1 ; + DIG 8 ; + PAIR ; + PAIR ; + PAIR 5 ; + PUSH mutez 0 ; + EMPTY_MAP string (pair (pair nat string (option address) nat (option string)) nat) ; + PAIR ; + DIG 3 ; + ITER { UNPAIR ; + DIG 2 ; + UNPAIR ; + DIG 3 ; + DIG 3 ; + CAR ; + IF_LEFT { DROP ; DUP 4 ; CAR ; CAR ; CAR } { DROP ; DUP 4 ; CAR ; CDR } ; + PAIR ; + PAIR ; + DUP 6 ; + SWAP ; + EXEC ; + DUP 4 ; + CAR ; + CAR ; + CDR ; + CDR ; + DIG 2 ; + ADD ; + SWAP ; + PAIR } ; + SWAP ; + DIG 4 ; + DROP 2 ; + UNPAIR ; + SELF_ADDRESS ; + NIL operation ; + DIG 2 ; + ITER { CDR ; + DUP ; + CAR ; + GET 5 ; + IF_NONE + { DROP ; PUSH nat 109 ; FAILWITH } + { DUP 2 ; + CAR ; + GET 8 ; + IF_NONE + { DROP 2 ; PUSH nat 108 ; FAILWITH } + { PUSH string "FA1.2 token" ; + DUP 2 ; + COMPARE ; + EQ ; + IF { DROP ; + CONTRACT %transfer (pair (address %from) (address %to) (nat %value)) ; + IF_NONE { PUSH nat 101 ; FAILWITH } {} ; + PUSH mutez 0 ; + DIG 2 ; + CDR ; + DUP 8 ; + DUP 6 ; + PAIR 3 ; + TRANSFER_TOKENS } + { PUSH string "FA2 token" ; + SWAP ; + COMPARE ; + EQ ; + IF { CONTRACT %transfer + (list (pair (address %from_) (list %tx (pair (address %to_) (nat %token_id) (nat %amount))))) ; + IF_NONE { PUSH nat 101 ; FAILWITH } {} ; + PUSH mutez 0 ; + NIL (pair address (list (pair address nat nat))) ; + NIL (pair address nat nat) ; + DUP 5 ; + CDR ; + DIG 5 ; + CAR ; + CAR ; + DUP 11 ; + PAIR 3 ; + CONS ; + DUP 6 ; + PAIR ; + CONS ; + TRANSFER_TOKENS } + { DROP 2 ; PUSH nat 108 ; FAILWITH } } } } ; + CONS } ; + SWAP ; + DIG 4 ; + DROP 2 ; + PUSH mutez 0 ; + DUP 3 ; + COMPARE ; + GT ; + IF { DUP 3 ; + CAR ; + CDR ; + CAR ; + CAR ; + CONTRACT unit ; + IF_NONE + { SWAP ; DROP ; PUSH nat 102 ; FAILWITH } + { DIG 2 ; UNIT ; TRANSFER_TOKENS } ; + CONS } + { SWAP ; DROP } ; + PAIR } } } } + { DIG 2 ; + DROP ; + IF_LEFT + { DUP 2 ; + CAR ; + CAR ; + CAR ; + CAR ; + SENDER ; + COMPARE ; + EQ ; + IF {} { PUSH nat 114 ; FAILWITH } ; + PUSH mutez 1 ; + AMOUNT ; + COMPARE ; + LT ; + IF {} { PUSH nat 118 ; FAILWITH } ; + DUP 2 ; + CAR ; + CDR ; + CAR ; + CAR ; + DUP 2 ; + COMPARE ; + EQ ; + IF { PUSH nat 144 ; FAILWITH } {} ; + DUP 2 ; + DIG 2 ; + CAR ; + DUP ; + CAR ; + DUP ; + CAR ; + DIG 4 ; + UPDATE 1 ; + UPDATE 1 ; + UPDATE 1 ; + UPDATE 1 ; + NIL operation ; + PAIR } + { DUP 2 ; + CAR ; + CAR ; + CAR ; + CAR ; + SENDER ; + COMPARE ; + EQ ; + IF {} { PUSH nat 114 ; FAILWITH } ; + PUSH mutez 1 ; + AMOUNT ; + COMPARE ; + LT ; + IF {} { PUSH nat 118 ; FAILWITH } ; + PUSH nat 600 ; + DUP 2 ; + COMPARE ; + LT ; + IF { DROP 2 ; PUSH nat 131 ; FAILWITH } + { PUSH nat 3600 ; + DUP 2 ; + COMPARE ; + GT ; + IF { DROP 2 ; PUSH nat 132 ; FAILWITH } + { DUP 2 ; + DIG 2 ; + CAR ; + DUP ; + CAR ; + DUP ; + CDR ; + DIG 4 ; + UPDATE 1 ; + UPDATE 2 ; + UPDATE 1 ; + UPDATE 1 ; + NIL operation ; + PAIR } } } } } + { DIG 2 ; + DROP ; + IF_LEFT + { IF_LEFT + { DUP 2 ; + CAR ; + CAR ; + 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 ; + DUP ; + CAR ; + DUP ; + CDR ; + DIG 4 ; + UPDATE 2 ; + UPDATE 2 ; + UPDATE 1 ; + UPDATE 1 } + { DUP 2 ; + CAR ; + CAR ; + CAR ; + CAR ; + SENDER ; + COMPARE ; + EQ ; + IF {} { PUSH nat 114 ; FAILWITH } ; + PUSH mutez 1 ; + AMOUNT ; + COMPARE ; + LT ; + IF {} { PUSH nat 118 ; FAILWITH } ; + DUP 2 ; + CAR ; + CAR ; + CAR ; + CAR ; + DUP 2 ; + COMPARE ; + EQ ; + IF { PUSH nat 144 ; FAILWITH } {} ; + DUP 2 ; + DIG 2 ; + CAR ; + DUP ; + CDR ; + DUP ; + CAR ; + DIG 4 ; + UPDATE 1 ; + UPDATE 1 ; + UPDATE 2 ; + UPDATE 1 } ; + NIL operation ; + PAIR } + { IF_LEFT + { DUP 2 ; + CAR ; + CAR ; + CAR ; + CAR ; + SENDER ; + COMPARE ; + EQ ; + IF {} { PUSH nat 114 ; FAILWITH } ; + PUSH mutez 1 ; + AMOUNT ; + COMPARE ; + LT ; + IF {} { PUSH nat 118 ; FAILWITH } ; + DUP 2 ; + CAR ; + CAR ; + CDR ; + CAR ; + DUP 2 ; + COMPARE ; + GT ; + IF { DROP 2 ; PUSH nat 169 ; FAILWITH } + { DUP 2 ; + DIG 2 ; + CAR ; + DUP ; + CDR ; + DUP ; + CDR ; + DIG 4 ; + UPDATE 2 ; + UPDATE 2 ; + UPDATE 2 ; + UPDATE 1 ; + NIL operation ; + PAIR } } + { DUP 2 ; + CAR ; + CAR ; + 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 ; + DUP ; + CAR ; + DUP ; + CAR ; + DIG 4 ; + UPDATE 1 ; + UPDATE 1 ; + UPDATE 1 ; + UPDATE 2 ; + NIL operation ; + PAIR } } } } + { IF_LEFT + { DIG 2 ; + DIG 4 ; + DIG 5 ; + DROP 3 ; + IF_LEFT + { DIG 2 ; + DROP ; + IF_LEFT + { DUP 2 ; + CAR ; + CAR ; + 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 ; + DUP ; + CAR ; + DUP ; + CDR ; + DIG 4 ; + UPDATE 2 ; + UPDATE 2 ; + UPDATE 1 ; + UPDATE 2 ; + NIL operation ; + PAIR } + { DUP ; + GET 5 ; + PUSH nat 0 ; + DUP 2 ; + COMPARE ; + EQ ; + IF { DROP ; UNIT ; LEFT unit } + { PUSH nat 1 ; + SWAP ; + COMPARE ; + EQ ; + IF { UNIT ; RIGHT unit } { PUSH nat 106 ; FAILWITH } } ; + DUP 2 ; + CAR ; + DUP ; + CDR ; + GET 3 ; + SWAP ; + CAR ; + CAR ; + GET 3 ; + PAIR ; + SWAP ; + IF_LEFT { DROP } { DROP ; DUP ; CAR ; SWAP ; CDR ; PAIR } ; + NOW ; + DUP 4 ; + CDR ; + CAR ; + CDR ; + CDR ; + 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 } {} ; + DUP 3 ; + UNPAIR ; + DUP ; + DUP 3 ; + COMPARE ; + GT ; + IF { PUSH string "/" ; CONCAT ; SWAP ; CONCAT } + { SWAP ; PUSH string "/" ; CONCAT ; SWAP ; CONCAT } ; + GET ; + IF_NONE { PUSH nat 117 ; FAILWITH } {} ; + DUP ; + GET 8 ; + IF { DROP 5 ; PUSH nat 125 ; FAILWITH } + { DUP 4 ; + CAR ; + DUP 5 ; + GET 5 ; + PUSH nat 0 ; + DUP 2 ; + COMPARE ; + EQ ; + IF { DROP ; UNIT ; LEFT unit } + { PUSH nat 1 ; + SWAP ; + COMPARE ; + EQ ; + IF { UNIT ; RIGHT unit } { PUSH nat 106 ; FAILWITH } } ; + IF_LEFT + { DROP ; + SWAP ; + CAR ; + CAR ; + SWAP ; + CAR ; + CAR ; + GET 3 ; + COMPARE ; + EQ ; + IF {} { PUSH nat 156 ; FAILWITH } } + { DROP ; + SWAP ; + CAR ; + CDR ; + SWAP ; + CAR ; + CAR ; + GET 3 ; + COMPARE ; + EQ ; + IF {} { PUSH nat 156 ; FAILWITH } } ; + DUP 4 ; + CAR ; + CAR ; + CDR ; + CDR ; + AMOUNT ; + DUP 2 ; + DUP 2 ; + COMPARE ; + LT ; + IF { DROP 6 ; PUSH nat 113 ; FAILWITH } + { COMPARE ; + GT ; + IF { DROP 4 ; PUSH nat 130 ; FAILWITH } + { DUP 4 ; + CAR ; + CAR ; + CAR ; + CDR ; + DUP ; + CDR ; + DUP 2 ; + CAR ; + DUP 5 ; + UNPAIR ; + DUP ; + DUP 3 ; + COMPARE ; + GT ; + IF { PUSH string "/" ; CONCAT ; SWAP ; CONCAT } + { SWAP ; PUSH string "/" ; CONCAT ; SWAP ; CONCAT } ; + GET ; + IF_NONE { PUSH nat 0 } {} ; + GET ; + IF_NONE + { PUSH nat 0 ; + DUP 2 ; + CAR ; + ITER { CDR ; DUP 2 ; DUP 2 ; COMPARE ; GT ; IF { SWAP ; DROP } { DROP } } ; + PUSH nat 1 ; + ADD ; + NONE address ; + PUSH nat 0 ; + DUP 6 ; + PUSH nat 0 ; + PUSH nat 0 ; + PUSH nat 0 ; + PUSH nat 0 ; + PUSH nat 0 ; + PUSH nat 0 ; + PUSH nat 0 ; + PUSH nat 0 ; + PAIR 8 ; + DIG 6 ; + RIGHT + (or (pair (pair timestamp + (pair (pair nat nat nat) + (or (or unit unit) unit) + (pair nat nat nat nat) + (pair (pair string string) (pair int int) timestamp))) + (pair (pair string string) (pair int int) timestamp)) + (pair timestamp timestamp)) ; + DIG 5 ; + PAIR 6 ; + DIG 4 ; + DUP 3 ; + DUP 4 ; + CDR ; + DUP 4 ; + SOME ; + DUP 5 ; + CAR ; + UPDATE ; + UPDATE 2 ; + DIG 3 ; + CAR ; + DUP 4 ; + CAR ; + SOME ; + DUP 5 ; + GET 7 ; + UNPAIR ; + DUP ; + DUP 3 ; + COMPARE ; + GT ; + IF { PUSH string "/" ; CONCAT ; SWAP ; CONCAT } + { SWAP ; PUSH string "/" ; CONCAT ; SWAP ; CONCAT } ; + UPDATE ; + UPDATE 1 } + { DUP 6 ; + CAR ; + CAR ; + CDR ; + CAR ; + DUP 2 ; + GET 3 ; + IF_LEFT + { SWAP ; + DROP ; + IF_LEFT + { DROP 2 ; + PUSH nat 0 ; + DUP 2 ; + CAR ; + ITER { CDR ; DUP 2 ; DUP 2 ; COMPARE ; GT ; IF { SWAP ; DROP } { DROP } } ; + PUSH nat 1 ; + ADD ; + NONE address ; + PUSH nat 0 ; + DUP 6 ; + PUSH nat 0 ; + PUSH nat 0 ; + PUSH nat 0 ; + PUSH nat 0 ; + PUSH nat 0 ; + PUSH nat 0 ; + PUSH nat 0 ; + PUSH nat 0 ; + PAIR 8 ; + DIG 6 ; + RIGHT + (or (pair (pair timestamp + (pair (pair nat nat nat) + (or (or unit unit) unit) + (pair nat nat nat nat) + (pair (pair string string) (pair int int) timestamp))) + (pair (pair string string) (pair int int) timestamp)) + (pair timestamp timestamp)) ; + DIG 5 ; + PAIR 6 ; + DIG 4 ; + DUP 3 ; + DUP 4 ; + CDR ; + DUP 4 ; + SOME ; + DUP 5 ; + CAR ; + UPDATE ; + UPDATE 2 ; + DIG 3 ; + CAR ; + DUP 4 ; + CAR ; + SOME ; + DUP 5 ; + GET 7 ; + UNPAIR ; + DUP ; + DUP 3 ; + COMPARE ; + GT ; + IF { PUSH string "/" ; CONCAT ; SWAP ; CONCAT } + { SWAP ; PUSH string "/" ; CONCAT ; SWAP ; CONCAT } ; + UPDATE ; + UPDATE 1 } + { DIG 3 ; DROP 2 ; DIG 4 ; DIG 2 } } + { DUP 2 ; + INT ; + ADD ; + DIG 4 ; + COMPARE ; + GE ; + IF { DUP 2 ; + GET 3 ; + IF_LEFT + { SWAP ; + DIG 2 ; + DIG 6 ; + DROP 3 ; + IF_LEFT + { DROP ; PUSH nat 105 ; FAILWITH } + { DROP ; PUSH nat 105 ; FAILWITH } } + { SWAP ; + INT ; + DUP 2 ; + ADD ; + PAIR ; + RIGHT + (pair (pair timestamp + (pair (pair nat nat nat) + (or (or unit unit) unit) + (pair nat nat nat nat) + (pair (pair string string) (pair int int) timestamp))) + (pair (pair string string) (pair int int) timestamp)) ; + LEFT timestamp ; + UPDATE 3 ; + DIG 4 ; + PAIR } ; + UNPAIR ; + DUP 3 ; + DUP 4 ; + CDR ; + DUP 4 ; + SOME ; + DUP 5 ; + CAR ; + UPDATE ; + UPDATE 2 ; + DIG 3 ; + CAR ; + DUP 4 ; + CAR ; + SOME ; + DUP 5 ; + GET 7 ; + UNPAIR ; + DUP ; + DUP 3 ; + COMPARE ; + GT ; + IF { PUSH string "/" ; CONCAT ; SWAP ; CONCAT } + { SWAP ; PUSH string "/" ; CONCAT ; SWAP ; CONCAT } ; + UPDATE ; + UPDATE 1 } + { DROP ; DIG 4 ; DIG 2 } } } ; + DIG 2 ; + DUP ; + GET 3 ; + IF_LEFT + { IF_LEFT { DROP ; PUSH bool False } { DROP ; PUSH bool False } } + { DROP ; PUSH bool True } ; + IF { DUP ; + GET 3 ; + IF_LEFT + { IF_LEFT { DROP ; PUSH bool False } { DROP ; PUSH bool False } } + { DROP ; PUSH bool True } ; + IF { DIG 3 ; DROP } + { DUP 3 ; + CDR ; + CAR ; + CDR ; + CDR ; + 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 } {} ; + DIG 4 ; + UNPAIR ; + DUP ; + DUP 3 ; + COMPARE ; + GT ; + IF { PUSH string "/" ; CONCAT ; SWAP ; CONCAT } + { SWAP ; PUSH string "/" ; CONCAT ; SWAP ; CONCAT } ; + GET ; + IF_NONE { PUSH nat 117 ; FAILWITH } {} ; + DUP ; + GET 3 ; + SWAP ; + GET 5 ; + VIEW "getPrice" (pair timestamp nat) ; + IF_NONE { PUSH nat 124 ; FAILWITH } {} ; + CAR ; + DUP 4 ; + CAR ; + CAR ; + CDR ; + CAR ; + INT ; + NOW ; + SUB ; + COMPARE ; + LT ; + IF {} { PUSH nat 120 ; FAILWITH } } ; + DUP 3 ; + DIG 3 ; + CAR ; + DUP ; + CAR ; + DUP ; + CAR ; + DUP 6 ; + UPDATE 2 ; + UPDATE 1 ; + UPDATE 1 ; + UPDATE 1 ; + DUP 2 ; + CAR ; + SENDER ; + DUP 3 ; + CDR ; + CAR ; + CAR ; + CAR ; + UNIT ; + VIEW "get_vaults" (map string address) ; + IF_NONE { PUSH nat 166 ; FAILWITH } {} ; + PUSH bool False ; + SWAP ; + ITER { CDR ; DUP 2 ; IF { DROP } { SWAP ; DROP ; DUP 2 ; COMPARE ; EQ } } ; + PUSH nat 1 ; + DUP 5 ; + CAR ; + CDR ; + CAR ; + CDR ; + ADD ; + DUP 5 ; + CDR ; + CAR ; + CDR ; + CDR ; + 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 } {} ; + DUP 6 ; + CDR ; + CAR ; + CDR ; + CDR ; + 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 10 ; + GET 5 ; + PUSH nat 0 ; + DUP 2 ; + COMPARE ; + EQ ; + IF { DROP ; UNIT ; LEFT unit } + { PUSH nat 1 ; + SWAP ; + COMPARE ; + EQ ; + IF { UNIT ; RIGHT unit } { PUSH nat 106 ; FAILWITH } } ; + DUP 11 ; + GET 6 ; + PUSH nat 0 ; + DUP 2 ; + COMPARE ; + EQ ; + IF { DROP ; UNIT ; RIGHT unit ; LEFT unit } + { PUSH nat 1 ; + DUP 2 ; + COMPARE ; + EQ ; + IF { DROP ; UNIT ; LEFT unit ; LEFT unit } + { PUSH nat 2 ; + SWAP ; + COMPARE ; + EQ ; + IF { UNIT ; RIGHT (or unit unit) } { PUSH nat 107 ; FAILWITH } } } ; + SENDER ; + DUP 13 ; + CAR ; + DUP ; + CAR ; + CAR ; + DUP 2 ; + CDR ; + DUP 7 ; + DUP 3 ; + GET 3 ; + GET ; + IF_NONE + { SWAP ; DIG 2 ; DIG 6 ; DIG 7 ; DROP 5 ; PUSH nat 110 ; FAILWITH } + { DIG 7 ; + DUP 3 ; + GET 3 ; + GET ; + IF_NONE + { SWAP ; DIG 2 ; DIG 3 ; DIG 7 ; DROP 5 ; PUSH nat 110 ; FAILWITH } + { DUP ; + GET 8 ; + DUP 4 ; + GET 8 ; + COMPARE ; + EQ ; + DUP 2 ; + GET 7 ; + DUP 5 ; + GET 7 ; + COMPARE ; + EQ ; + DUP 3 ; + GET 5 ; + DUP 6 ; + GET 5 ; + COMPARE ; + EQ ; + DUP 4 ; + GET 3 ; + DUP 7 ; + GET 3 ; + COMPARE ; + EQ ; + DIG 4 ; + CAR ; + DIG 6 ; + CAR ; + COMPARE ; + EQ ; + AND ; + AND ; + AND ; + AND ; + DUP 2 ; + GET 8 ; + DUP 4 ; + GET 8 ; + COMPARE ; + EQ ; + DUP 3 ; + GET 7 ; + DUP 5 ; + GET 7 ; + COMPARE ; + EQ ; + DUP 4 ; + GET 5 ; + DUP 6 ; + GET 5 ; + COMPARE ; + EQ ; + DUP 5 ; + GET 3 ; + DUP 7 ; + GET 3 ; + COMPARE ; + EQ ; + DIG 5 ; + CAR ; + DIG 6 ; + CAR ; + COMPARE ; + EQ ; + AND ; + AND ; + AND ; + AND ; + AND ; + IF { DUP ; + CDR ; + GET 3 ; + SWAP ; + CAR ; + CAR ; + GET 3 ; + PAIR ; + DIG 4 ; + DUP 5 ; + IF_LEFT { DROP ; SWAP } { DROP ; DUP 2 ; CAR ; DIG 2 ; CDR ; PAIR } ; + UNPAIR ; + DUP ; + DUP 3 ; + COMPARE ; + GT ; + IF { PUSH string "/" ; CONCAT ; SWAP ; CONCAT } + { SWAP ; PUSH string "/" ; CONCAT ; SWAP ; CONCAT } ; + MEM ; + IF {} { PUSH nat 110 ; FAILWITH } } + { DIG 4 ; DROP 2 ; PUSH nat 110 ; FAILWITH } } } ; + PUSH bool False ; + DIG 2 ; + DIG 3 ; + DIG 11 ; + CAR ; + DIG 4 ; + DUP 9 ; + DUP 7 ; + PAIR 7 ; + DUP 6 ; + CDR ; + CDR ; + DUP 2 ; + GET 5 ; + GET ; + IF_NONE + { PUSH bool True } + { PUSH nat 0 ; + SWAP ; + ITER { CDR ; SIZE ; ADD } ; + PUSH nat 10 ; + SWAP ; + COMPARE ; + LE } ; + IF { DIG 2 ; + IF { DIG 5 ; DIG 3 ; SOME ; UPDATE 10 } { DIG 2 ; DROP ; DIG 4 } ; + DUP ; + GET 5 ; + DUP 3 ; + GET 9 ; + IF_LEFT + { DROP ; + DUP 3 ; + GET 7 ; + CAR ; + CDR ; + DUP 2 ; + GET 7 ; + ADD ; + DUP 4 ; + GET 11 ; + IF_LEFT + { IF_LEFT + { DROP ; + DUP 2 ; + DUP 5 ; + GET 7 ; + CAR ; + CDR ; + DIG 3 ; + GET 3 ; + ADD ; + UPDATE 3 ; + SWAP ; + UPDATE 7 } + { DROP ; + DUP 2 ; + DUP 5 ; + GET 7 ; + CAR ; + CDR ; + DIG 3 ; + CAR ; + ADD ; + UPDATE 1 ; + SWAP ; + UPDATE 7 } } + { DROP ; + DUP 2 ; + DUP 5 ; + GET 7 ; + CAR ; + CDR ; + DIG 3 ; + GET 5 ; + ADD ; + UPDATE 5 ; + SWAP ; + UPDATE 7 } } + { DROP ; + DUP 3 ; + GET 7 ; + CAR ; + CDR ; + DUP 2 ; + GET 14 ; + ADD ; + DUP 4 ; + GET 11 ; + IF_LEFT + { IF_LEFT + { DROP ; + DUP 2 ; + DUP 5 ; + GET 7 ; + CAR ; + CDR ; + DIG 3 ; + GET 11 ; + ADD ; + UPDATE 11 ; + SWAP ; + UPDATE 14 } + { DROP ; + DUP 2 ; + DUP 5 ; + GET 7 ; + CAR ; + CDR ; + DIG 3 ; + GET 9 ; + ADD ; + UPDATE 9 ; + SWAP ; + UPDATE 14 } } + { DROP ; + DUP 2 ; + DUP 5 ; + GET 7 ; + CAR ; + CDR ; + DIG 3 ; + GET 13 ; + ADD ; + UPDATE 13 ; + SWAP ; + UPDATE 14 } } ; + DUP 7 ; + CDR ; + DUG 2 ; + UPDATE 5 ; + SOME ; + DUP 5 ; + UPDATE ; + DUP 5 ; + CDR ; + CDR ; + DUP 3 ; + GET 5 ; + GET ; + IF_NONE + { DUP ; + DUP 5 ; + GET ; + IF_NONE + { DROP ; PUSH nat 142 ; FAILWITH } + { PUSH nat 1 ; DUP 2 ; GET 9 ; ADD ; UPDATE 9 ; SOME ; DUP 5 ; UPDATE } } + { DUP 5 ; + GET ; + IF_NONE + { DUP ; + DUP 5 ; + GET ; + IF_NONE + { DROP ; PUSH nat 142 ; FAILWITH } + { PUSH nat 1 ; DUP 2 ; GET 9 ; ADD ; UPDATE 9 ; SOME ; DUP 5 ; UPDATE } } + { DROP } } ; + DUP 2 ; + GET 5 ; + DUP 6 ; + CDR ; + CDR ; + DUP 2 ; + GET ; + IF_NONE + { DUP 6 ; + CDR ; + CDR ; + EMPTY_MAP nat (map (pair (or unit unit) (or (or unit unit) unit)) nat) ; + EMPTY_MAP (pair (or unit unit) (or (or unit unit) unit)) nat ; + DUP 6 ; + GET 7 ; + CAR ; + CDR ; + DUP 7 ; + GET 11 ; + DUP 8 ; + GET 9 ; + PAIR ; + SWAP ; + SOME ; + SWAP ; + UPDATE ; + DIG 7 ; + SWAP ; + SOME ; + SWAP ; + UPDATE ; + DIG 2 ; + SWAP ; + SOME ; + SWAP ; + UPDATE } + { DUP ; + DUP 7 ; + GET ; + IF_NONE + { EMPTY_MAP (pair (or unit unit) (or (or unit unit) unit)) nat ; + DUP 5 ; + GET 7 ; + CAR ; + CDR ; + DUP 6 ; + GET 11 ; + DUP 7 ; + GET 9 ; + PAIR ; + SWAP ; + SOME ; + SWAP ; + UPDATE ; + DIG 6 ; + SWAP ; + SOME ; + SWAP ; + UPDATE } + { DUP 5 ; + GET 11 ; + DUP 6 ; + GET 9 ; + PAIR ; + DUP 2 ; + DUP 2 ; + GET ; + IF_NONE + { SWAP ; DUP 6 ; GET 7 ; CAR ; CDR ; DIG 2 ; SWAP ; SOME ; SWAP ; UPDATE } + { DUP 7 ; GET 7 ; CAR ; CDR ; ADD ; DIG 2 ; SWAP ; SOME ; DIG 2 ; UPDATE } ; + SOME ; + DIG 6 ; + UPDATE } ; + DUP 6 ; + CDR ; + CDR ; + SWAP ; + SOME ; + DIG 2 ; + UPDATE } ; + DUP 5 ; + DIG 5 ; + CAR ; + DUP ; + CAR ; + DUP ; + CAR ; + DIG 8 ; + DIG 6 ; + UPDATE 2 ; + UPDATE 2 ; + UPDATE 1 ; + UPDATE 1 ; + UPDATE 1 ; + DUP ; + CAR ; + DUP ; + CDR ; + DUP ; + CAR ; + DIG 6 ; + UPDATE 2 ; + UPDATE 1 ; + UPDATE 2 ; + UPDATE 1 ; + DUP 3 ; + GET 7 ; + CAR ; + DIG 3 ; + GET 5 ; + SELF_ADDRESS ; + DUP 3 ; + CAR ; + GET 5 ; + IF_NONE + { DROP 3 ; PUSH nat 109 ; FAILWITH } + { DUP 4 ; + CAR ; + GET 8 ; + IF_NONE + { DROP 4 ; PUSH nat 108 ; FAILWITH } + { PUSH string "FA1.2 token" ; + DUP 2 ; + COMPARE ; + EQ ; + IF { DROP ; + CONTRACT %transfer (pair (address %from) (address %to) (nat %value)) ; + IF_NONE { PUSH nat 101 ; FAILWITH } {} ; + PUSH mutez 0 ; + DIG 4 ; + CDR ; + DIG 3 ; + DIG 4 ; + PAIR 3 ; + TRANSFER_TOKENS } + { PUSH string "FA2 token" ; + SWAP ; + COMPARE ; + EQ ; + IF { CONTRACT %transfer + (list (pair (address %from_) (list %tx (pair (address %to_) (nat %token_id) (nat %amount))))) ; + IF_NONE { PUSH nat 101 ; FAILWITH } {} ; + PUSH mutez 0 ; + NIL (pair address (list (pair address nat nat))) ; + NIL (pair address nat nat) ; + DUP 7 ; + CDR ; + DIG 7 ; + CAR ; + CAR ; + DIG 6 ; + PAIR 3 ; + CONS ; + DIG 4 ; + PAIR ; + CONS ; + TRANSFER_TOKENS } + { DROP 4 ; PUSH nat 108 ; FAILWITH } } } } ; + DUP 2 ; + DIG 2 ; + CDR ; + DIG 3 ; + UPDATE 2 ; + UPDATE 2 ; + NIL operation ; + DIG 2 ; + CONS ; + PAIR } + { DROP 8 ; PUSH nat 112 ; FAILWITH } } + { DROP 5 ; PUSH nat 103 ; FAILWITH } } } } } } + { IF_LEFT + { DROP ; + SENDER ; + PUSH mutez 1 ; + AMOUNT ; + COMPARE ; + LT ; + IF {} { PUSH nat 118 ; FAILWITH } ; + SELF_ADDRESS ; + PUSH mutez 0 ; + PUSH mutez 0 ; + EMPTY_MAP address mutez ; + PAIR ; + DUP 5 ; + CAR ; + CDR ; + CAR ; + CAR ; + DUP 5 ; + PAIR ; + PAIR ; + PAIR ; + DUP 4 ; + CAR ; + CAR ; + CDR ; + CDR ; + DUP 5 ; + CAR ; + CAR ; + CAR ; + CDR ; + DUP 6 ; + CDR ; + CDR ; + DUP 7 ; + CDR ; + CAR ; + CDR ; + CDR ; + 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 2 ; + DUP 8 ; + GET ; + IF_NONE + { DIG 3 ; + DIG 8 ; + DROP 3 ; + EMPTY_MAP string (pair (pair nat string (option address) nat (option string)) nat) ; + DIG 2 ; + PAIR ; + SWAP } + { NONE nat ; + IF_NONE + { DIG 4 ; + DIG 5 ; + PAIR ; + DIG 2 ; + DIG 4 ; + PAIR ; + EMPTY_MAP string (pair (pair nat string (option address) nat (option string)) nat) ; + DUP 4 ; + PAIR ; + PAIR ; + PAIR ; + SWAP ; + ITER { UNPAIR ; + DIG 2 ; + UNPAIR ; + UNPAIR ; + UNPAIR ; + DIG 2 ; + UNPAIR ; + DIG 4 ; + UNPAIR ; + DUP 3 ; + CDR ; + DUP ; + DUP 9 ; + GET ; + IF_NONE + { DIG 7 ; DIG 8 ; DROP 3 ; PAIR ; DUG 2 ; PAIR ; DIG 3 ; DIG 3 } + { DUP ; + GET 3 ; + IF_LEFT + { IF_LEFT + { CAR ; CDR ; SOME } + { DROP ; + NONE (pair (pair nat nat nat) + (or (or unit unit) unit) + (pair nat nat nat nat) + (pair (pair string string) (pair int int) timestamp)) } } + { DROP ; + NONE (pair (pair nat nat nat) + (or (or unit unit) unit) + (pair nat nat nat nat) + (pair (pair string string) (pair int int) timestamp)) } ; + IF_NONE + { SWAP ; DIG 8 ; DIG 9 ; DROP 4 ; PAIR ; DUG 2 ; PAIR ; DIG 3 ; DIG 3 } + { DUP 2 ; + GET 10 ; + DUP 6 ; + DIG 5 ; + PAIR ; + PAIR ; + DUP 7 ; + DUP 4 ; + GET 5 ; + PAIR ; + DIG 9 ; + DIG 3 ; + PAIR ; + PAIR ; + PAIR ; + DIG 8 ; + ITER { UNPAIR ; + DIG 2 ; + UNPAIR ; + UNPAIR ; + UNPAIR ; + DIG 2 ; + UNPAIR ; + DIG 4 ; + UNPAIR ; + UNPAIR ; + PUSH nat 0 ; + DUP 5 ; + GET 7 ; + COMPARE ; + EQ ; + IF { PUSH bool False } + { PUSH nat 0 ; + DUP 5 ; + GET 14 ; + COMPARE ; + EQ ; + IF { PUSH bool False } + { DUP 8 ; + CDR ; + DUP 7 ; + GET 3 ; + DUP 10 ; + CAR ; + IF_LEFT + { DROP ; + SWAP ; + IF_LEFT + { IF_LEFT + { DROP ; + IF_LEFT + { IF_LEFT { DROP ; PUSH bool True } { DROP ; PUSH bool False } } + { DROP ; PUSH bool True } } + { DROP ; + IF_LEFT + { IF_LEFT { DROP ; PUSH bool True } { DROP ; PUSH bool True } } + { DROP ; PUSH bool True } } } + { DROP ; + IF_LEFT + { IF_LEFT { DROP ; PUSH bool False } { DROP ; PUSH bool False } } + { DROP ; PUSH bool True } } } + { DROP ; + SWAP ; + IF_LEFT + { IF_LEFT + { DROP ; + IF_LEFT + { IF_LEFT { DROP ; PUSH bool True } { DROP ; PUSH bool True } } + { DROP ; PUSH bool False } } + { DROP ; + IF_LEFT + { IF_LEFT { DROP ; PUSH bool False } { DROP ; PUSH bool True } } + { DROP ; PUSH bool False } } } + { DROP ; + IF_LEFT + { IF_LEFT { DROP ; PUSH bool True } { DROP ; PUSH bool True } } + { DROP ; PUSH bool True } } } } } ; + IF { DUP 6 ; + GET 6 ; + CAR ; + DUP 6 ; + DUP 2 ; + CAR ; + GET ; + IF_NONE { PUSH nat 111 ; FAILWITH } {} ; + DUP 7 ; + DIG 2 ; + CDR ; + GET ; + IF_NONE { PUSH nat 111 ; FAILWITH } {} ; + DIG 9 ; + CAR ; + IF_LEFT + { DROP ; + DUP 8 ; + GET 5 ; + DUP ; + GET 5 ; + INT ; + SWAP ; + GET 3 ; + INT ; + PUSH int 1 ; + SWAP ; + PAIR ; + DIG 11 ; + INT ; + PUSH int 1 ; + SWAP ; + PAIR ; + DUP 2 ; + CAR ; + DUP 2 ; + CDR ; + MUL ; + DIG 2 ; + CDR ; + DUP 3 ; + CAR ; + MUL ; + PAIR ; + PUSH int 1 ; + DIG 3 ; + PAIR ; + DUP ; + CDR ; + DUP 3 ; + CDR ; + MUL ; + SWAP ; + CAR ; + DIG 2 ; + CAR ; + MUL ; + PAIR ; + DUP 10 ; + GET 6 ; + GET 3 ; + DUP ; + CAR ; + DUP 3 ; + CDR ; + MUL ; + SWAP ; + CDR ; + DUP 3 ; + CAR ; + MUL ; + PAIR ; + DUP ; + CDR ; + DUP 4 ; + CDR ; + MUL ; + DUP 4 ; + CDR ; + DUP 3 ; + CAR ; + MUL ; + DIG 2 ; + CDR ; + DIG 4 ; + CAR ; + MUL ; + SUB ; + PAIR ; + PUSH int 0 ; + DUP 3 ; + CAR ; + COMPARE ; + LT ; + IF { PUSH int -1 ; DUP 3 ; CDR ; MUL ; PUSH int -1 ; DIG 3 ; CAR ; MUL ; PAIR } + { SWAP } ; + DUP ; + CDR ; + PUSH nat 1 ; + PUSH nat 0 ; + PUSH nat 10 ; + 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 } } ; + DIG 2 ; + CAR ; + MUL ; + EDIV ; + IF_NONE { PUSH string "DIV by 0" ; FAILWITH } {} ; + CAR ; + ISNAT ; + IF_NONE { PUSH nat 119 ; FAILWITH } {} ; + DIG 2 ; + PAIR ; + PUSH nat 0 ; + DUP 2 ; + CDR ; + COMPARE ; + GT ; + IF { DIG 9 ; SWAP ; PAIR ; DUP 21 ; SWAP ; EXEC } { DROP ; DIG 8 } ; + PUSH int 1 ; + PUSH int 0 ; + PAIR ; + DUP ; + CAR ; + DUP 4 ; + CDR ; + MUL ; + SWAP ; + CDR ; + DUP 4 ; + CAR ; + MUL ; + COMPARE ; + LE ; + NOT ; + IF { PUSH int 0 ; + DUP 3 ; + CAR ; + COMPARE ; + LT ; + IF { PUSH int -1 ; DUP 3 ; CDR ; MUL ; PUSH int -1 ; DIG 3 ; CAR ; MUL ; PAIR } + { SWAP } ; + DUP ; + CDR ; + PUSH nat 1 ; + PUSH nat 0 ; + PUSH nat 10 ; + 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 } } ; + DIG 2 ; + CAR ; + MUL ; + EDIV ; + IF_NONE { PUSH string "DIV by 0" ; FAILWITH } {} ; + CAR ; + ISNAT ; + IF_NONE { PUSH nat 119 ; FAILWITH } {} ; + DIG 2 ; + PAIR ; + PAIR ; + DUP 19 ; + SWAP ; + EXEC } + { SWAP ; DIG 2 ; DROP 2 } } + { DROP ; + DUP 8 ; + GET 5 ; + DUP ; + CAR ; + INT ; + SWAP ; + GET 6 ; + INT ; + PUSH int 1 ; + SWAP ; + PAIR ; + DIG 11 ; + INT ; + PUSH int 1 ; + SWAP ; + PAIR ; + DUP 2 ; + CAR ; + DUP 2 ; + CDR ; + MUL ; + DIG 2 ; + CDR ; + DUP 3 ; + CAR ; + MUL ; + PAIR ; + PUSH int 1 ; + DIG 3 ; + PAIR ; + DUP ; + CDR ; + DUP 3 ; + CDR ; + MUL ; + SWAP ; + CAR ; + DIG 2 ; + CAR ; + MUL ; + PAIR ; + DUP 10 ; + GET 6 ; + GET 3 ; + DUP ; + CDR ; + DUP 3 ; + CDR ; + MUL ; + SWAP ; + CAR ; + DUP 3 ; + CAR ; + MUL ; + PAIR ; + DUP ; + CDR ; + DUP 4 ; + CDR ; + MUL ; + DUP 4 ; + CDR ; + DUP 3 ; + CAR ; + MUL ; + DIG 2 ; + CDR ; + DIG 4 ; + CAR ; + MUL ; + SUB ; + PAIR ; + PUSH int 0 ; + DUP 3 ; + CAR ; + COMPARE ; + LT ; + IF { PUSH int -1 ; DUP 3 ; CDR ; MUL ; PUSH int -1 ; DIG 3 ; CAR ; MUL ; PAIR } + { SWAP } ; + DUP ; + CDR ; + PUSH nat 1 ; + PUSH nat 0 ; + PUSH nat 10 ; + 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 } } ; + DIG 2 ; + CAR ; + MUL ; + EDIV ; + IF_NONE { PUSH string "DIV by 0" ; FAILWITH } {} ; + CAR ; + ISNAT ; + IF_NONE { PUSH nat 119 ; FAILWITH } {} ; + DIG 3 ; + PAIR ; + PUSH nat 0 ; + DUP 2 ; + CDR ; + COMPARE ; + GT ; + IF { DIG 9 ; SWAP ; PAIR ; DUP 21 ; SWAP ; EXEC } { DROP ; DIG 8 } ; + PUSH int 1 ; + PUSH int 0 ; + PAIR ; + DUP ; + CAR ; + DUP 4 ; + CDR ; + MUL ; + SWAP ; + CDR ; + DUP 4 ; + CAR ; + MUL ; + COMPARE ; + LE ; + NOT ; + IF { PUSH int 0 ; + DUP 3 ; + CAR ; + COMPARE ; + LT ; + IF { PUSH int -1 ; DUP 3 ; CDR ; MUL ; PUSH int -1 ; DIG 3 ; CAR ; MUL ; PAIR } + { SWAP } ; + DUP ; + CDR ; + PUSH nat 1 ; + PUSH nat 0 ; + PUSH nat 10 ; + 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 } } ; + DIG 2 ; + CAR ; + MUL ; + EDIV ; + IF_NONE { PUSH string "DIV by 0" ; FAILWITH } {} ; + CAR ; + ISNAT ; + IF_NONE { PUSH nat 119 ; FAILWITH } {} ; + DIG 2 ; + PAIR ; + PAIR ; + DUP 19 ; + SWAP ; + EXEC } + { SWAP ; DIG 2 ; DROP 2 } } ; + DUP 4 ; + IF_NONE + { DUP 3 ; DUP 3 ; CDR ; ADD ; DIG 2 ; SWAP ; UPDATE 2 } + { DUP 3 ; + CAR ; + CDR ; + CAR ; + DUP ; + DUP 3 ; + GET ; + IF_NONE + { DUP 5 ; DIG 2 ; SWAP ; SOME ; SWAP ; UPDATE } + { DUP 6 ; ADD ; SOME ; DIG 2 ; UPDATE } ; + DUP 3 ; + DIG 3 ; + CAR ; + DUP ; + CDR ; + DIG 3 ; + UPDATE 1 ; + UPDATE 2 ; + UPDATE 1 } ; + SWAP } + { DUP 6 ; + GET 6 ; + CAR ; + DIG 8 ; + CAR ; + IF_LEFT + { DROP ; + DUP 6 ; + SWAP ; + CAR ; + GET ; + IF_NONE { PUSH nat 111 ; FAILWITH } {} } + { DROP ; + DUP 6 ; + SWAP ; + CDR ; + GET ; + IF_NONE { PUSH nat 111 ; FAILWITH } {} } ; + DUP 3 ; + DUP 3 ; + CAR ; + CDR ; + CDR ; + ADD ; + DUP 3 ; + DIG 3 ; + CAR ; + DUP ; + CDR ; + DIG 3 ; + UPDATE 2 ; + UPDATE 2 ; + UPDATE 1 ; + DIG 7 ; + DIG 8 ; + DIG 3 ; + PAIR ; + PAIR ; + DUP 19 ; + SWAP ; + EXEC } ; + DUG 3 ; + PAIR ; + PAIR ; + DIG 3 ; + DIG 3 ; + PAIR ; + DIG 2 ; + DIG 3 ; + PAIR ; + PAIR ; + PAIR } ; + UNPAIR ; + CAR ; + CDR ; + SWAP ; + CAR ; + CAR ; + DUP 3 ; + CAR ; + DUP 5 ; + DUP 2 ; + GET ; + IF_NONE + { DIG 4 ; DROP 2 ; PUSH nat 141 ; FAILWITH } + { PUSH nat 1 ; + DUP 2 ; + GET 9 ; + SUB ; + ABS ; + DIG 6 ; + DUG 2 ; + UPDATE 9 ; + SOME ; + DIG 2 ; + UPDATE } ; + DUP ; + DUP 5 ; + CAR ; + GET ; + IF_NONE + { PUSH nat 141 ; FAILWITH } + { PUSH nat 0 ; SWAP ; GET 9 ; COMPARE ; LE } ; + DIG 5 ; + DIG 3 ; + PAIR ; + DIG 6 ; + DIG 2 ; + IF { DIG 2 ; + DROP ; + DUP 5 ; + DIG 5 ; + CDR ; + DIG 5 ; + CAR ; + NONE (pair nat + (or (or (pair (pair timestamp + (pair (pair nat nat nat) + (or (or unit unit) unit) + (pair nat nat nat nat) + (pair (pair string string) (pair int int) timestamp))) + (pair (pair string string) (pair int int) timestamp)) + (pair timestamp timestamp)) + timestamp) + (pair nat nat nat nat nat nat nat nat) + (pair string string) + nat + (option address)) ; + SWAP ; + UPDATE ; + UPDATE 2 } + { DIG 4 ; DROP ; DIG 4 ; DIG 3 ; UPDATE 2 } ; + PAIR ; + DIG 2 ; + DIG 3 ; + DIG 4 ; + NONE (map (pair (or unit unit) (or (or unit unit) unit)) nat) ; + SWAP ; + UPDATE } } ; + PAIR ; + PAIR ; + PAIR } ; + DIG 5 ; + DROP } + { DUP 2 ; + DUP 2 ; + GET ; + IF_NONE + { DIG 10 ; + DROP 2 ; + DIG 4 ; + DIG 5 ; + PAIR ; + DIG 2 ; + DIG 4 ; + PAIR ; + EMPTY_MAP string (pair (pair nat string (option address) nat (option string)) nat) ; + DIG 3 } + { EMPTY_MAP string (pair (pair nat string (option address) nat (option string)) nat) ; + DUP 7 ; + CDR ; + DUP ; + DUP 5 ; + GET ; + IF_NONE + { DIG 2 ; + DIG 3 ; + DIG 13 ; + DROP 4 ; + DIG 5 ; + DIG 6 ; + PAIR ; + DIG 3 ; + DIG 5 ; + PAIR ; + DIG 2 ; + DIG 3 } + { DUP ; + GET 3 ; + IF_LEFT + { IF_LEFT + { CAR ; CDR ; SOME } + { DROP ; + NONE (pair (pair nat nat nat) + (or (or unit unit) unit) + (pair nat nat nat nat) + (pair (pair string string) (pair int int) timestamp)) } } + { DROP ; + NONE (pair (pair nat nat nat) + (or (or unit unit) unit) + (pair nat nat nat nat) + (pair (pair string string) (pair int int) timestamp)) } ; + IF_NONE + { SWAP ; + DIG 3 ; + DIG 4 ; + DIG 14 ; + DROP 5 ; + DIG 5 ; + DIG 6 ; + PAIR ; + DIG 3 ; + DIG 5 ; + PAIR ; + DIG 2 ; + DIG 3 } + { DUP 2 ; + GET 10 ; + DUP 12 ; + DIG 13 ; + PAIR ; + PAIR ; + DUP 9 ; + DUP 4 ; + GET 5 ; + PAIR ; + DIG 5 ; + DIG 3 ; + PAIR ; + PAIR ; + PAIR ; + DIG 3 ; + ITER { UNPAIR ; + DIG 2 ; + UNPAIR ; + UNPAIR ; + UNPAIR ; + DIG 2 ; + UNPAIR ; + DIG 4 ; + UNPAIR ; + UNPAIR ; + PUSH nat 0 ; + DUP 5 ; + GET 7 ; + COMPARE ; + EQ ; + IF { PUSH bool False } + { PUSH nat 0 ; + DUP 5 ; + GET 14 ; + COMPARE ; + EQ ; + IF { PUSH bool False } + { DUP 8 ; + CDR ; + DUP 7 ; + GET 3 ; + DUP 10 ; + CAR ; + IF_LEFT + { DROP ; + SWAP ; + IF_LEFT + { IF_LEFT + { DROP ; + IF_LEFT + { IF_LEFT { DROP ; PUSH bool True } { DROP ; PUSH bool False } } + { DROP ; PUSH bool True } } + { DROP ; + IF_LEFT + { IF_LEFT { DROP ; PUSH bool True } { DROP ; PUSH bool True } } + { DROP ; PUSH bool True } } } + { DROP ; + IF_LEFT + { IF_LEFT { DROP ; PUSH bool False } { DROP ; PUSH bool False } } + { DROP ; PUSH bool True } } } + { DROP ; + SWAP ; + IF_LEFT + { IF_LEFT + { DROP ; + IF_LEFT + { IF_LEFT { DROP ; PUSH bool True } { DROP ; PUSH bool True } } + { DROP ; PUSH bool False } } + { DROP ; + IF_LEFT + { IF_LEFT { DROP ; PUSH bool False } { DROP ; PUSH bool True } } + { DROP ; PUSH bool False } } } + { DROP ; + IF_LEFT + { IF_LEFT { DROP ; PUSH bool True } { DROP ; PUSH bool True } } + { DROP ; PUSH bool True } } } } } ; + IF { DUP 6 ; + GET 6 ; + CAR ; + DUP 6 ; + DUP 2 ; + CAR ; + GET ; + IF_NONE { PUSH nat 111 ; FAILWITH } {} ; + DUP 7 ; + DIG 2 ; + CDR ; + GET ; + IF_NONE { PUSH nat 111 ; FAILWITH } {} ; + DIG 9 ; + CAR ; + IF_LEFT + { DROP ; + DUP 8 ; + GET 5 ; + DUP ; + GET 5 ; + INT ; + SWAP ; + GET 3 ; + INT ; + PUSH int 1 ; + SWAP ; + PAIR ; + DIG 11 ; + INT ; + PUSH int 1 ; + SWAP ; + PAIR ; + DUP 2 ; + CAR ; + DUP 2 ; + CDR ; + MUL ; + DIG 2 ; + CDR ; + DUP 3 ; + CAR ; + MUL ; + PAIR ; + PUSH int 1 ; + DIG 3 ; + PAIR ; + DUP ; + CDR ; + DUP 3 ; + CDR ; + MUL ; + SWAP ; + CAR ; + DIG 2 ; + CAR ; + MUL ; + PAIR ; + DUP 10 ; + GET 6 ; + GET 3 ; + DUP ; + CAR ; + DUP 3 ; + CDR ; + MUL ; + SWAP ; + CDR ; + DUP 3 ; + CAR ; + MUL ; + PAIR ; + DUP ; + CDR ; + DUP 4 ; + CDR ; + MUL ; + DUP 4 ; + CDR ; + DUP 3 ; + CAR ; + MUL ; + DIG 2 ; + CDR ; + DIG 4 ; + CAR ; + MUL ; + SUB ; + PAIR ; + PUSH int 0 ; + DUP 3 ; + CAR ; + COMPARE ; + LT ; + IF { PUSH int -1 ; DUP 3 ; CDR ; MUL ; PUSH int -1 ; DIG 3 ; CAR ; MUL ; PAIR } + { SWAP } ; + DUP ; + CDR ; + PUSH nat 1 ; + PUSH nat 0 ; + PUSH nat 10 ; + 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 } } ; + DIG 2 ; + CAR ; + MUL ; + EDIV ; + IF_NONE { PUSH string "DIV by 0" ; FAILWITH } {} ; + CAR ; + ISNAT ; + IF_NONE { PUSH nat 119 ; FAILWITH } {} ; + DIG 2 ; + PAIR ; + PUSH nat 0 ; + DUP 2 ; + CDR ; + COMPARE ; + GT ; + IF { DIG 9 ; SWAP ; PAIR ; DUP 21 ; SWAP ; EXEC } { DROP ; DIG 8 } ; + PUSH int 1 ; + PUSH int 0 ; + PAIR ; + DUP ; + CAR ; + DUP 4 ; + CDR ; + MUL ; + SWAP ; + CDR ; + DUP 4 ; + CAR ; + MUL ; + COMPARE ; + LE ; + NOT ; + IF { PUSH int 0 ; + DUP 3 ; + CAR ; + COMPARE ; + LT ; + IF { PUSH int -1 ; DUP 3 ; CDR ; MUL ; PUSH int -1 ; DIG 3 ; CAR ; MUL ; PAIR } + { SWAP } ; + DUP ; + CDR ; + PUSH nat 1 ; + PUSH nat 0 ; + PUSH nat 10 ; + 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 } } ; + DIG 2 ; + CAR ; + MUL ; + EDIV ; + IF_NONE { PUSH string "DIV by 0" ; FAILWITH } {} ; + CAR ; + ISNAT ; + IF_NONE { PUSH nat 119 ; FAILWITH } {} ; + DIG 2 ; + PAIR ; + PAIR ; + DUP 19 ; + SWAP ; + EXEC } + { SWAP ; DIG 2 ; DROP 2 } } + { DROP ; + DUP 8 ; + GET 5 ; + DUP ; + CAR ; + INT ; + SWAP ; + GET 6 ; + INT ; + PUSH int 1 ; + SWAP ; + PAIR ; + DIG 11 ; + INT ; + PUSH int 1 ; + SWAP ; + PAIR ; + DUP 2 ; + CAR ; + DUP 2 ; + CDR ; + MUL ; + DIG 2 ; + CDR ; + DUP 3 ; + CAR ; + MUL ; + PAIR ; + PUSH int 1 ; + DIG 3 ; + PAIR ; + DUP ; + CDR ; + DUP 3 ; + CDR ; + MUL ; + SWAP ; + CAR ; + DIG 2 ; + CAR ; + MUL ; + PAIR ; + DUP 10 ; + GET 6 ; + GET 3 ; + DUP ; + CDR ; + DUP 3 ; + CDR ; + MUL ; + SWAP ; + CAR ; + DUP 3 ; + CAR ; + MUL ; + PAIR ; + DUP ; + CDR ; + DUP 4 ; + CDR ; + MUL ; + DUP 4 ; + CDR ; + DUP 3 ; + CAR ; + MUL ; + DIG 2 ; + CDR ; + DIG 4 ; + CAR ; + MUL ; + SUB ; + PAIR ; + PUSH int 0 ; + DUP 3 ; + CAR ; + COMPARE ; + LT ; + IF { PUSH int -1 ; DUP 3 ; CDR ; MUL ; PUSH int -1 ; DIG 3 ; CAR ; MUL ; PAIR } + { SWAP } ; + DUP ; + CDR ; + PUSH nat 1 ; + PUSH nat 0 ; + PUSH nat 10 ; + 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 } } ; + DIG 2 ; + CAR ; + MUL ; + EDIV ; + IF_NONE { PUSH string "DIV by 0" ; FAILWITH } {} ; + CAR ; + ISNAT ; + IF_NONE { PUSH nat 119 ; FAILWITH } {} ; + DIG 3 ; + PAIR ; + PUSH nat 0 ; + DUP 2 ; + CDR ; + COMPARE ; + GT ; + IF { DIG 9 ; SWAP ; PAIR ; DUP 21 ; SWAP ; EXEC } { DROP ; DIG 8 } ; + PUSH int 1 ; + PUSH int 0 ; + PAIR ; + DUP ; + CAR ; + DUP 4 ; + CDR ; + MUL ; + SWAP ; + CDR ; + DUP 4 ; + CAR ; + MUL ; + COMPARE ; + LE ; + NOT ; + IF { PUSH int 0 ; + DUP 3 ; + CAR ; + COMPARE ; + LT ; + IF { PUSH int -1 ; DUP 3 ; CDR ; MUL ; PUSH int -1 ; DIG 3 ; CAR ; MUL ; PAIR } + { SWAP } ; + DUP ; + CDR ; + PUSH nat 1 ; + PUSH nat 0 ; + PUSH nat 10 ; + 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 } } ; + DIG 2 ; + CAR ; + MUL ; + EDIV ; + IF_NONE { PUSH string "DIV by 0" ; FAILWITH } {} ; + CAR ; + ISNAT ; + IF_NONE { PUSH nat 119 ; FAILWITH } {} ; + DIG 2 ; + PAIR ; + PAIR ; + DUP 19 ; + SWAP ; + EXEC } + { SWAP ; DIG 2 ; DROP 2 } } ; + DUP 4 ; + IF_NONE + { DUP 3 ; DUP 3 ; CDR ; ADD ; DIG 2 ; SWAP ; UPDATE 2 } + { DUP 3 ; + CAR ; + CDR ; + CAR ; + DUP ; + DUP 3 ; + GET ; + IF_NONE + { DUP 5 ; DIG 2 ; SWAP ; SOME ; SWAP ; UPDATE } + { DUP 6 ; ADD ; SOME ; DIG 2 ; UPDATE } ; + DUP 3 ; + DIG 3 ; + CAR ; + DUP ; + CDR ; + DIG 3 ; + UPDATE 1 ; + UPDATE 2 ; + UPDATE 1 } ; + SWAP } + { DUP 6 ; + GET 6 ; + CAR ; + DIG 8 ; + CAR ; + IF_LEFT + { DROP ; + DUP 6 ; + SWAP ; + CAR ; + GET ; + IF_NONE { PUSH nat 111 ; FAILWITH } {} } + { DROP ; + DUP 6 ; + SWAP ; + CDR ; + GET ; + IF_NONE { PUSH nat 111 ; FAILWITH } {} } ; + DUP 3 ; + DUP 3 ; + CAR ; + CDR ; + CDR ; + ADD ; + DUP 3 ; + DIG 3 ; + CAR ; + DUP ; + CDR ; + DIG 3 ; + UPDATE 2 ; + UPDATE 2 ; + UPDATE 1 ; + DIG 7 ; + DIG 8 ; + DIG 3 ; + PAIR ; + PAIR ; + DUP 19 ; + SWAP ; + EXEC } ; + DUG 3 ; + PAIR ; + PAIR ; + DIG 3 ; + DIG 3 ; + PAIR ; + DIG 2 ; + DIG 3 ; + PAIR ; + PAIR ; + PAIR } ; + DIG 12 ; + DROP ; + UNPAIR ; + CAR ; + CDR ; + SWAP ; + CAR ; + CAR ; + DUP 3 ; + CAR ; + DUP 5 ; + DUP 2 ; + GET ; + IF_NONE + { DIG 4 ; DROP 2 ; PUSH nat 141 ; FAILWITH } + { PUSH nat 1 ; + DUP 2 ; + GET 9 ; + SUB ; + ABS ; + DIG 6 ; + DUG 2 ; + UPDATE 9 ; + SOME ; + DIG 2 ; + UPDATE } ; + DUP ; + DUP 5 ; + CAR ; + GET ; + IF_NONE + { PUSH nat 141 ; FAILWITH } + { PUSH nat 0 ; SWAP ; GET 9 ; COMPARE ; LE } ; + DIG 10 ; + DIG 3 ; + PAIR ; + DIG 7 ; + DIG 2 ; + IF { DIG 2 ; + DROP ; + DUP 8 ; + DIG 8 ; + CDR ; + DIG 5 ; + CAR ; + NONE (pair nat + (or (or (pair (pair timestamp + (pair (pair nat nat nat) + (or (or unit unit) unit) + (pair nat nat nat nat) + (pair (pair string string) (pair int int) timestamp))) + (pair (pair string string) (pair int int) timestamp)) + (pair timestamp timestamp)) + timestamp) + (pair nat nat nat nat nat nat nat nat) + (pair string string) + nat + (option address)) ; + SWAP ; + UPDATE ; + UPDATE 2 } + { DIG 4 ; DROP ; DIG 7 ; DIG 3 ; UPDATE 2 } ; + PAIR ; + DIG 2 ; + DIG 4 ; + DIG 4 ; + NONE (map (pair (or unit unit) (or (or unit unit) unit)) nat) ; + SWAP ; + UPDATE } } } ; + PAIR ; + PAIR ; + PAIR } ; + UNPAIR ; + UNPAIR ; + UNPAIR ; + DIG 2 ; + CAR ; + DIG 3 ; + CAR ; + DIG 3 ; + DIG 2 ; + PAIR ; + DIG 3 ; + DIG 3 ; + SOME ; + DUP 6 ; + UPDATE } ; + DUG 2 ; + UNPAIR ; + NIL operation ; + DIG 2 ; + ITER { CDR ; + DUP ; + CAR ; + GET 5 ; + IF_NONE + { DROP ; PUSH nat 109 ; FAILWITH } + { DUP 2 ; + CAR ; + GET 8 ; + IF_NONE + { DROP 2 ; PUSH nat 108 ; FAILWITH } + { PUSH string "FA1.2 token" ; + DUP 2 ; + COMPARE ; + EQ ; + IF { DROP ; + CONTRACT %transfer (pair (address %from) (address %to) (nat %value)) ; + IF_NONE { PUSH nat 101 ; FAILWITH } {} ; + PUSH mutez 0 ; + DIG 2 ; + CDR ; + DUP 9 ; + DUP 9 ; + PAIR 3 ; + TRANSFER_TOKENS } + { PUSH string "FA2 token" ; + SWAP ; + COMPARE ; + EQ ; + IF { CONTRACT %transfer + (list (pair (address %from_) (list %tx (pair (address %to_) (nat %token_id) (nat %amount))))) ; + IF_NONE { PUSH nat 101 ; FAILWITH } {} ; + PUSH mutez 0 ; + NIL (pair address (list (pair address nat nat))) ; + NIL (pair address nat nat) ; + DUP 5 ; + CDR ; + DIG 5 ; + CAR ; + CAR ; + DUP 12 ; + PAIR 3 ; + CONS ; + DUP 9 ; + PAIR ; + CONS ; + TRANSFER_TOKENS } + { DROP 2 ; PUSH nat 108 ; FAILWITH } } } } ; + CONS } ; + DIG 4 ; + DIG 5 ; + DROP 2 ; + PUSH mutez 0 ; + DUP 4 ; + CAR ; + CDR ; + CDR ; + COMPARE ; + GT ; + IF { DUP 3 ; + CAR ; + CAR ; + CAR ; + CONTRACT unit ; + IF_NONE + { PUSH nat 102 ; FAILWITH } + { DUP 4 ; CAR ; CDR ; CDR ; UNIT ; TRANSFER_TOKENS } ; + CONS } + {} ; + DUP 3 ; + CAR ; + CDR ; + CAR ; + ITER { UNPAIR ; + PUSH mutez 0 ; + DUP 3 ; + COMPARE ; + GT ; + IF { CONTRACT %addreward mutez ; + IF_NONE { PUSH nat 157 ; FAILWITH } {} ; + DUP 2 ; + DIG 2 ; + TRANSFER_TOKENS ; + CONS } + { DROP 2 } } ; + PUSH mutez 0 ; + DUP 4 ; + CDR ; + COMPARE ; + GT ; + IF { DUP 3 ; + CAR ; + CAR ; + CDR ; + CONTRACT unit ; + IF_NONE + { DIG 2 ; DROP ; PUSH nat 102 ; FAILWITH } + { DIG 3 ; CDR ; UNIT ; TRANSFER_TOKENS } ; + CONS } + { DIG 2 ; DROP } ; + DUP 4 ; + DIG 4 ; + CDR ; + DIG 4 ; + UPDATE 2 ; + UPDATE 2 ; + DUP ; + CAR ; + DUP ; + CAR ; + DUP ; + CAR ; + DIG 5 ; + UPDATE 2 ; + UPDATE 1 ; + UPDATE 1 ; + UPDATE 1 ; + SWAP } + { DIG 2 ; + DROP ; + DUP 2 ; + CAR ; + CAR ; + CAR ; + CAR ; + SENDER ; + COMPARE ; + EQ ; + IF {} { PUSH nat 114 ; FAILWITH } ; + PUSH mutez 1 ; + AMOUNT ; + COMPARE ; + LT ; + IF {} { PUSH nat 118 ; FAILWITH } ; + DUP 2 ; + DUP 3 ; + CDR ; + DUP ; + CAR ; + DUP ; + CAR ; + DIG 5 ; + CDR ; + CAR ; + CAR ; + CDR ; + DIG 5 ; + NONE bytes ; + SWAP ; + UPDATE ; + UPDATE 2 ; + UPDATE 1 ; + UPDATE 1 ; + UPDATE 2 ; + NIL operation } ; + PAIR } } + { DIG 3 ; + DROP ; + PUSH mutez 1 ; + AMOUNT ; + COMPARE ; + LT ; + IF {} { PUSH nat 118 ; FAILWITH } ; + DUP 2 ; + CDR ; + CAR ; + CDR ; + CDR ; + 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 } {} ; + DUP 2 ; + GET ; + IF_NONE + { DROP 5 ; PUSH nat 117 ; FAILWITH } + { DUP 3 ; + CDR ; + CAR ; + CDR ; + CDR ; + 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 2 ; + CAR ; + DUP 2 ; + DUP 2 ; + CAR ; + GET ; + IF_NONE { PUSH nat 111 ; FAILWITH } {} ; + DUG 2 ; + CDR ; + GET ; + IF_NONE { PUSH nat 111 ; FAILWITH } {} ; + DUP 3 ; + GET 8 ; + DUP 4 ; + GET 7 ; + DUP 5 ; + GET 5 ; + DIG 5 ; + GET 3 ; + DIG 4 ; + PUSH nat 1 ; + DIG 6 ; + PAIR ; + PAIR ; + PAIR 5 ; + DUP ; + GET 8 ; + DUP 2 ; + GET 7 ; + DUP 3 ; + GET 5 ; + DUP 4 ; + GET 3 ; + DUP 5 ; + CAR ; + DUP ; + CDR ; + GET 3 ; + SWAP ; + CAR ; + CAR ; + GET 3 ; + PAIR ; + PAIR 5 ; + DUP ; + GET 3 ; + SWAP ; + GET 5 ; + VIEW "getPrice" (pair timestamp nat) ; + IF_NONE { PUSH nat 122 ; FAILWITH } {} ; + UNPAIR ; + DUP 5 ; + CDR ; + CAR ; + CDR ; + CAR ; + DUP 5 ; + GET ; + IF_NONE + {} + { DUP 2 ; + SWAP ; + GET 4 ; + COMPARE ; + GE ; + IF { PUSH nat 121 ; FAILWITH } {} } ; + DUP 5 ; + CAR ; + CAR ; + CDR ; + CAR ; + INT ; + DUP 2 ; + SWAP ; + NOW ; + SUB ; + COMPARE ; + LT ; + IF {} { PUSH nat 120 ; FAILWITH } ; + DUP 5 ; + CDR ; + CAR ; + CDR ; + CDR ; + 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 ; + CAR ; + DIG 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 9 ; + SWAP ; + EXEC ; + DIG 4 ; + MUL ; + ISNAT ; + IF_NONE { PUSH nat 119 ; FAILWITH } {} ; + DUP 2 ; + CAR ; + CAR ; + GET 7 ; + INT ; + PUSH int 10 ; + PAIR ; + DUP 9 ; + SWAP ; + EXEC ; + SWAP } + { INT ; PUSH int 10 ; PAIR ; DUP 9 ; SWAP ; EXEC ; DIG 4 } ; + INT ; + PUSH int 1 ; + SWAP ; + PAIR ; + PUSH int 1 ; + DIG 2 ; + PAIR ; + DUP ; + CAR ; + DUP 3 ; + CDR ; + MUL ; + SWAP ; + CDR ; + DIG 2 ; + CAR ; + MUL ; + PAIR ; + DIG 3 ; + SWAP ; + DUP 3 ; + CDR ; + GET 3 ; + DIG 3 ; + CAR ; + CAR ; + GET 3 ; + PAIR ; + PAIR 3 ; + DUP ; + CAR ; + DUP 3 ; + DUP 2 ; + CAR ; + GET ; + IF_NONE { PUSH nat 111 ; FAILWITH } {} ; + DIG 3 ; + DIG 2 ; + CDR ; + GET ; + IF_NONE { PUSH nat 111 ; FAILWITH } {} ; + SWAP ; + GET 7 ; + SWAP ; + GET 7 ; + SUB ; + DUP ; + ABS ; + INT ; + PUSH int 10 ; + PAIR ; + DIG 6 ; + 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 ; + DUP 3 ; + DUP 4 ; + CDR ; + DUP ; + CAR ; + DUP ; + CDR ; + DIG 6 ; + CDR ; + CAR ; + CDR ; + CAR ; + DUP ; + DUP 8 ; + GET ; + IF_NONE + { DUP 6 ; DIG 7 ; SWAP ; SOME ; SWAP ; UPDATE } + { GET 4 ; + DUP 7 ; + GET 4 ; + COMPARE ; + GT ; + IF { DUP 6 ; SOME ; DIG 7 ; UPDATE } { DIG 6 ; DROP } } ; + UPDATE 1 ; + UPDATE 2 ; + UPDATE 1 ; + UPDATE 2 ; + DUP 2 ; + CAR ; + UNIT ; + LEFT unit ; + IF_LEFT { DROP } { DROP ; DUP ; CAR ; SWAP ; CDR ; PAIR } ; + NOW ; + DUP 3 ; + CAR ; + CAR ; + CAR ; + CDR ; + DUP ; + CDR ; + DUP 2 ; + CAR ; + DUP 5 ; + UNPAIR ; + DUP ; + DUP 3 ; + COMPARE ; + GT ; + IF { PUSH string "/" ; CONCAT ; SWAP ; CONCAT } + { SWAP ; PUSH string "/" ; CONCAT ; SWAP ; CONCAT } ; + GET ; + IF_NONE { PUSH nat 0 } {} ; + GET ; + IF_NONE + { DIG 2 ; + DROP ; + DIG 2 ; + SWAP ; + NONE (pair nat + (or (or (pair (pair timestamp + (pair (pair nat nat nat) + (or (or unit unit) unit) + (pair nat nat nat nat) + (pair (pair string string) (pair int int) timestamp))) + (pair (pair string string) (pair int int) timestamp)) + (pair timestamp timestamp)) + timestamp) + (pair nat nat nat nat nat nat nat nat) + (pair string string) + nat + (option address)) } + { DUP ; + GET 3 ; + IF_LEFT + { IF_LEFT { DROP ; PUSH bool True } { DROP ; PUSH bool False } } + { DROP ; PUSH bool False } ; + IF { DIG 3 ; DROP ; DIG 3 } + { DUP 5 ; + CAR ; + CAR ; + CDR ; + CAR ; + DUP 2 ; + GET 3 ; + IF_LEFT + { SWAP ; + DROP ; + IF_LEFT + { DROP 2 ; + PUSH nat 0 ; + DUP 2 ; + CAR ; + ITER { CDR ; DUP 2 ; DUP 2 ; COMPARE ; GT ; IF { SWAP ; DROP } { DROP } } ; + PUSH nat 1 ; + ADD ; + NONE address ; + PUSH nat 0 ; + DIG 5 ; + PUSH nat 0 ; + PUSH nat 0 ; + PUSH nat 0 ; + PUSH nat 0 ; + PUSH nat 0 ; + PUSH nat 0 ; + PUSH nat 0 ; + PUSH nat 0 ; + PAIR 8 ; + DUP 7 ; + RIGHT + (or (pair (pair timestamp + (pair (pair nat nat nat) + (or (or unit unit) unit) + (pair nat nat nat nat) + (pair (pair string string) (pair int int) timestamp))) + (pair (pair string string) (pair int int) timestamp)) + (pair timestamp timestamp)) ; + DIG 5 ; + PAIR 6 ; + DIG 3 ; + DUP 3 ; + DUP 4 ; + CDR ; + DUP 4 ; + SOME ; + DUP 5 ; + CAR ; + UPDATE ; + UPDATE 2 ; + DIG 3 ; + CAR ; + DUP 4 ; + CAR ; + SOME ; + DUP 5 ; + GET 7 ; + UNPAIR ; + DUP ; + DUP 3 ; + COMPARE ; + GT ; + IF { PUSH string "/" ; CONCAT ; SWAP ; CONCAT } + { SWAP ; PUSH string "/" ; CONCAT ; SWAP ; CONCAT } ; + UPDATE ; + UPDATE 1 } + { DIG 4 ; DROP 2 ; DIG 3 ; DIG 2 } } + { DIG 5 ; + DROP ; + DUP 2 ; + INT ; + ADD ; + DUP 5 ; + COMPARE ; + GE ; + IF { DUP 2 ; + GET 3 ; + IF_LEFT + { SWAP ; + DIG 2 ; + DIG 5 ; + DROP 3 ; + IF_LEFT + { DROP ; PUSH nat 105 ; FAILWITH } + { DROP ; PUSH nat 105 ; FAILWITH } } + { SWAP ; + INT ; + DUP 2 ; + ADD ; + PAIR ; + RIGHT + (pair (pair timestamp + (pair (pair nat nat nat) + (or (or unit unit) unit) + (pair nat nat nat nat) + (pair (pair string string) (pair int int) timestamp))) + (pair (pair string string) (pair int int) timestamp)) ; + LEFT timestamp ; + UPDATE 3 ; + DIG 3 ; + PAIR } ; + UNPAIR ; + DUP 3 ; + DUP 4 ; + CDR ; + DUP 4 ; + SOME ; + DUP 5 ; + CAR ; + UPDATE ; + UPDATE 2 ; + DIG 3 ; + CAR ; + DUP 4 ; + CAR ; + SOME ; + DUP 5 ; + GET 7 ; + UNPAIR ; + DUP ; + DUP 3 ; + COMPARE ; + GT ; + IF { PUSH string "/" ; CONCAT ; SWAP ; CONCAT } + { SWAP ; PUSH string "/" ; CONCAT ; SWAP ; CONCAT } ; + UPDATE ; + UPDATE 1 } + { DROP ; DIG 3 ; DIG 2 } } ; + DUG 2 } ; + DUG 2 ; + SOME } ; + IF_NONE + { DIG 2 ; DIG 3 ; DIG 4 ; DIG 5 ; DROP 5 } + { DUP ; + GET 3 ; + IF_LEFT + { IF_LEFT + { DIG 4 ; DROP 2 ; PUSH bool False } + { CAR ; PUSH int 120 ; ADD ; DIG 4 ; COMPARE ; GT } } + { DIG 4 ; DROP 2 ; PUSH bool False } ; + IF { NOW ; + DUP 2 ; + GET 5 ; + DUP ; + GET 9 ; + INT ; + DUP 2 ; + GET 11 ; + INT ; + DUP 3 ; + GET 13 ; + INT ; + DUP 4 ; + CAR ; + INT ; + DUP 5 ; + GET 3 ; + INT ; + DUP 6 ; + GET 5 ; + INT ; + DIG 3 ; + DIG 4 ; + DIG 5 ; + PAIR ; + PAIR ; + SWAP ; + DIG 2 ; + DIG 3 ; + PAIR ; + PAIR ; + DUP 8 ; + GET 3 ; + DUP 2 ; + CAR ; + CAR ; + DUP 4 ; + UNPAIR ; + UNPAIR ; + DUP 5 ; + DUP 16 ; + DIG 4 ; + DIG 4 ; + DIG 4 ; + ADD ; + ADD ; + PUSH int 1 ; + SWAP ; + PAIR ; + DUP 2 ; + CDR ; + DUP 2 ; + CDR ; + MUL ; + DIG 2 ; + CAR ; + DIG 2 ; + CAR ; + MUL ; + PAIR ; + DUP 2 ; + CAR ; + DUP 2 ; + CDR ; + MUL ; + DIG 2 ; + CDR ; + DIG 2 ; + CAR ; + MUL ; + PAIR ; + PUSH int 1 ; + DIG 2 ; + PAIR ; + DUP 2 ; + CAR ; + DUP 2 ; + CDR ; + MUL ; + DUP 3 ; + CDR ; + DUP 3 ; + CAR ; + MUL ; + COMPARE ; + LE ; + IF { SWAP ; DROP } { DROP } ; + DUP 3 ; + CAR ; + UNPAIR ; + DUP 6 ; + UNPAIR ; + CDR ; + DIG 3 ; + DIG 3 ; + ADD ; + DUP 5 ; + DIG 3 ; + DIG 3 ; + ADD ; + PUSH int 1 ; + SWAP ; + PAIR ; + DUP 2 ; + CAR ; + DUP 2 ; + CDR ; + MUL ; + DIG 2 ; + CDR ; + DIG 2 ; + CAR ; + MUL ; + PAIR ; + PUSH int 1 ; + DIG 2 ; + PAIR ; + DUP 2 ; + CAR ; + DUP 2 ; + CDR ; + MUL ; + DUP 3 ; + CDR ; + DUP 3 ; + CAR ; + MUL ; + COMPARE ; + LE ; + IF { SWAP ; DROP } { DROP } ; + DIG 3 ; + UNPAIR ; + UNPAIR ; + DIG 6 ; + CDR ; + DUG 3 ; + ADD ; + ADD ; + DUP 5 ; + CDR ; + DUP 14 ; + CDR ; + MUL ; + DIG 5 ; + CAR ; + DIG 13 ; + CAR ; + MUL ; + PAIR ; + PUSH int 1 ; + DIG 3 ; + PAIR ; + DUP 2 ; + CAR ; + DUP 2 ; + CDR ; + MUL ; + DIG 2 ; + CDR ; + DIG 2 ; + CAR ; + MUL ; + PAIR ; + PUSH int 1 ; + DIG 2 ; + PAIR ; + DUP 2 ; + CAR ; + DUP 2 ; + CDR ; + MUL ; + DUP 3 ; + CDR ; + DUP 3 ; + CAR ; + MUL ; + COMPARE ; + LE ; + IF { SWAP ; DROP } { DROP } ; + PUSH int 0 ; + DUP 4 ; + CAR ; + COMPARE ; + LT ; + IF { PUSH int -1 ; DUP 4 ; CDR ; MUL ; PUSH int -1 ; DUP 5 ; CAR ; MUL ; PAIR } + { DUP 3 } ; + DUP ; + CDR ; + PUSH nat 1 ; + PUSH nat 0 ; + PUSH nat 10 ; + 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 } } ; + DIG 2 ; + CAR ; + MUL ; + EDIV ; + IF_NONE { PUSH string "DIV by 0" ; FAILWITH } {} ; + CAR ; + ISNAT ; + IF_NONE { PUSH nat 119 ; FAILWITH } {} ; + PUSH int 0 ; + DUP 4 ; + CAR ; + COMPARE ; + LT ; + IF { PUSH int -1 ; DUP 4 ; CDR ; MUL ; PUSH int -1 ; DUP 5 ; CAR ; MUL ; PAIR } + { DUP 3 } ; + DUP ; + CDR ; + PUSH nat 1 ; + PUSH nat 0 ; + PUSH nat 10 ; + 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 } } ; + DIG 2 ; + CAR ; + MUL ; + EDIV ; + IF_NONE { PUSH string "DIV by 0" ; FAILWITH } {} ; + CAR ; + ISNAT ; + IF_NONE { PUSH nat 119 ; FAILWITH } {} ; + PUSH int 0 ; + DUP 4 ; + CAR ; + COMPARE ; + LT ; + IF { PUSH int -1 ; DUP 4 ; CDR ; MUL ; PUSH int -1 ; DUP 5 ; CAR ; MUL ; PAIR } + { DUP 3 } ; + DUP ; + CDR ; + PUSH nat 1 ; + PUSH nat 0 ; + PUSH nat 10 ; + 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 } } ; + DIG 2 ; + CAR ; + MUL ; + EDIV ; + IF_NONE { PUSH string "DIV by 0" ; FAILWITH } {} ; + CAR ; + ISNAT ; + IF_NONE { PUSH nat 119 ; FAILWITH } {} ; + DUP 4 ; + CAR ; + DUP 7 ; + CDR ; + MUL ; + DUP 5 ; + CDR ; + DUP 8 ; + CAR ; + MUL ; + COMPARE ; + LT ; + NOT ; + DUP 6 ; + CAR ; + DUP 8 ; + CDR ; + MUL ; + DUP 7 ; + CDR ; + DUP 9 ; + CAR ; + MUL ; + COMPARE ; + LT ; + NOT ; + AND ; + IF { DIG 3 ; DIG 4 ; DIG 5 ; DROP 3 ; UNIT ; RIGHT unit ; LEFT unit } + { DUP 4 ; + CAR ; + DUP 6 ; + CDR ; + MUL ; + DIG 4 ; + CDR ; + DUP 6 ; + CAR ; + MUL ; + COMPARE ; + LT ; + NOT ; + DUP 6 ; + CAR ; + DUP 6 ; + CDR ; + MUL ; + DIG 6 ; + CDR ; + DIG 6 ; + CAR ; + MUL ; + COMPARE ; + LT ; + NOT ; + AND ; + IF { UNIT ; LEFT unit ; LEFT unit } { UNIT ; RIGHT (or unit unit) } } ; + DUP 10 ; + PUSH nat 0 ; + PUSH nat 0 ; + PUSH nat 0 ; + PUSH nat 0 ; + PAIR 4 ; + DIG 2 ; + DIG 3 ; + DIG 4 ; + DIG 5 ; + PAIR 3 ; + PAIR 4 ; + DUP ; + GET 3 ; + IF_LEFT + { IF_LEFT + { DROP ; + DUP 2 ; + GET 3 ; + DUP 3 ; + CAR ; + ADD ; + DUP 3 ; + GET 13 ; + DIG 3 ; + GET 11 ; + ADD ; + SWAP } + { DROP ; + DUP 2 ; + GET 13 ; + DUP 3 ; + GET 11 ; + DUP 4 ; + GET 9 ; + ADD ; + ADD ; + DIG 2 ; + CAR } } + { DROP ; + DUP 2 ; + GET 5 ; + DUP 3 ; + GET 3 ; + DUP 4 ; + CAR ; + ADD ; + ADD ; + DIG 2 ; + GET 13 ; + SWAP } ; + DUP 3 ; + GET 3 ; + IF_LEFT + { IF_LEFT + { DIG 9 ; DROP 2 ; DUP 8 } + { DROP ; + DUP 8 ; + GET 3 ; + DUP 10 ; + CAR ; + DUP 2 ; + CDR ; + MUL ; + DIG 10 ; + CDR ; + DIG 2 ; + CAR ; + MUL ; + PAIR ; + DUP 9 ; + SWAP ; + UPDATE 3 } } + { DROP ; + DUP 8 ; + GET 3 ; + DUP 10 ; + CDR ; + DUP 2 ; + CDR ; + MUL ; + DIG 10 ; + CAR ; + DIG 2 ; + CAR ; + MUL ; + PAIR ; + DUP 9 ; + SWAP ; + UPDATE 3 } ; + DUP 4 ; + GET 3 ; + IF_LEFT + { IF_LEFT { DROP ; DUP 4 ; CAR ; GET 3 } { DROP ; DUP 4 ; CAR ; CAR } } + { DROP ; DUP 4 ; CAR ; GET 4 } ; + DUP 2 ; + GET 3 ; + DUP 2 ; + INT ; + PUSH int 1 ; + SWAP ; + PAIR ; + DUP 2 ; + CDR ; + DUP 2 ; + CDR ; + MUL ; + DIG 2 ; + 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 ; + 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 } } ; + DIG 2 ; + CAR ; + MUL ; + EDIV ; + IF_NONE { PUSH string "DIV by 0" ; FAILWITH } {} ; + CAR ; + ISNAT ; + IF_NONE { PUSH nat 119 ; FAILWITH } {} ; + DIG 5 ; + DIG 5 ; + DIG 2 ; + DIG 5 ; + DIG 4 ; + PAIR 4 ; + UPDATE 5 ; + SWAP ; + UPDATE 6 ; + DIG 2 ; + DIG 5 ; + DIG 2 ; + DIG 3 ; + PAIR ; + PAIR ; + LEFT (pair timestamp timestamp) ; + LEFT timestamp ; + UPDATE 3 ; + DUP 2 ; + DUP 3 ; + CDR ; + DUP 3 ; + SOME ; + DUP 4 ; + CAR ; + UPDATE ; + UPDATE 2 ; + DIG 2 ; + CAR ; + DUP 3 ; + CAR ; + SOME ; + DIG 3 ; + GET 7 ; + UNPAIR ; + DUP ; + DUP 3 ; + COMPARE ; + GT ; + IF { PUSH string "/" ; CONCAT ; SWAP ; CONCAT } + { SWAP ; PUSH string "/" ; CONCAT ; SWAP ; CONCAT } ; + UPDATE ; + UPDATE 1 } + { DIG 3 ; DIG 4 ; DIG 5 ; DROP 4 } ; + DUP 2 ; + DIG 2 ; + CAR ; + DUP ; + CAR ; + DUP ; + CAR ; + DIG 4 ; + UPDATE 2 ; + UPDATE 1 ; + UPDATE 1 ; + UPDATE 1 } ; + NIL operation ; + PAIR } } } } ; + view "get_fee_in_mutez" unit mutez { CDR ; CAR ; CAR ; CDR ; CDR } ; + view "redeemable_holdings_available" + unit + bool + { CDR ; + SENDER ; + SWAP ; + CDR ; + CDR ; + SWAP ; + GET ; + IF_NONE + { PUSH bool False } + { PUSH bool False ; + SWAP ; + ITER { CDR ; + PUSH bool False ; + SWAP ; + ITER { CDR ; PUSH nat 0 ; SWAP ; COMPARE ; GT ; OR } ; + OR } } } ; + view "get_batches_needing_liquidity" + unit + (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))) + { CDR ; + NIL (pair nat + (or (or (pair (pair timestamp + (pair (pair nat nat nat) + (or (or unit unit) unit) + (pair nat nat nat nat) + (pair (pair string string) (pair int int) timestamp))) + (pair (pair string string) (pair int int) timestamp)) + (pair timestamp timestamp)) + timestamp) + (pair nat nat nat nat nat nat nat nat) + (pair string string) + nat + (option address)) ; + DUP 2 ; + CAR ; + CAR ; + CAR ; + CDR ; + CAR ; + ITER { CDR ; + DUP 3 ; + CAR ; + CAR ; + CAR ; + CDR ; + CDR ; + SWAP ; + GET ; + IF_NONE + {} + { DUP ; + GET 5 ; + DUP 2 ; + GET 3 ; + IF_LEFT + { SWAP ; + DIG 2 ; + DROP 2 ; + IF_LEFT { DROP } { DROP } ; + NONE (pair nat + (or (or (pair (pair timestamp + (pair (pair nat nat nat) + (or (or unit unit) unit) + (pair nat nat nat nat) + (pair (pair string string) (pair int int) timestamp))) + (pair (pair string string) (pair int int) timestamp)) + (pair timestamp timestamp)) + timestamp) + (pair nat nat nat nat nat nat nat nat) + (pair string string) + nat + (option address)) } + { NOW ; + DUP 6 ; + CAR ; + CDR ; + CDR ; + CDR ; + INT ; + DUP 3 ; + ADD ; + DUP 7 ; + CAR ; + CAR ; + CDR ; + CAR ; + INT ; + DIG 3 ; + ADD ; + DUP 3 ; + COMPARE ; + GT ; + SWAP ; + DIG 2 ; + COMPARE ; + LT ; + AND ; + IF { DROP 2 ; + NONE (pair nat + (or (or (pair (pair timestamp + (pair (pair nat nat nat) + (or (or unit unit) unit) + (pair nat nat nat nat) + (pair (pair string string) (pair int int) timestamp))) + (pair (pair string string) (pair int int) timestamp)) + (pair timestamp timestamp)) + timestamp) + (pair nat nat nat nat nat nat nat nat) + (pair string string) + nat + (option address)) } + { PUSH nat 0 ; + DUP 2 ; + GET 14 ; + COMPARE ; + EQ ; + PUSH nat 0 ; + DUP 3 ; + GET 7 ; + COMPARE ; + EQ ; + AND ; + IF { DROP 2 ; + NONE (pair nat + (or (or (pair (pair timestamp + (pair (pair nat nat nat) + (or (or unit unit) unit) + (pair nat nat nat nat) + (pair (pair string string) (pair int int) timestamp))) + (pair (pair string string) (pair int int) timestamp)) + (pair timestamp timestamp)) + timestamp) + (pair nat nat nat nat nat nat nat nat) + (pair string string) + nat + (option address)) } + { PUSH nat 0 ; + DUP 2 ; + GET 14 ; + COMPARE ; + GT ; + PUSH nat 0 ; + DIG 2 ; + GET 7 ; + COMPARE ; + GT ; + AND ; + IF { DROP ; + NONE (pair nat + (or (or (pair (pair timestamp + (pair (pair nat nat nat) + (or (or unit unit) unit) + (pair nat nat nat nat) + (pair (pair string string) (pair int int) timestamp))) + (pair (pair string string) (pair int int) timestamp)) + (pair timestamp timestamp)) + timestamp) + (pair nat nat nat nat nat nat nat nat) + (pair string string) + nat + (option address)) } + { SOME } } } } ; + IF_NONE {} { CONS } } } ; + SWAP ; + DROP } } + diff --git a/batcher/michelson/batcher-storage-ghostnet.tz b/batcher/michelson/batcher-storage-ghostnet.tz new file mode 100644 index 00000000..3ce3c78b --- /dev/null +++ b/batcher/michelson/batcher-storage-ghostnet.tz @@ -0,0 +1,9 @@ +(Pair (Pair (Pair (Pair "tz1ca4batAsNxMYab3mUK5H4QRjY8drV4ViL" {} {}) 600 10000) + (Pair "tz1burnburnburnburnburnburnburjAYjjX" 0) + 10 + 420) + (Pair (Pair "KT1XKvKiTTj8N6WKv3MhnZhFjZopFGQGBTdT" {}) + {} + "KT1SG9z3pU1cNh8dSranm5C5HXWphWi2pLwx") + {}) + diff --git a/batcher/michelson/btctz-vault-ghostnet.tz b/batcher/michelson/btctz-vault-ghostnet.tz new file mode 100644 index 00000000..7713bed1 --- /dev/null +++ b/batcher/michelson/btctz-vault-ghostnet.tz @@ -0,0 +1,1650 @@ +{ parameter + (or (or (or (or (nat %addLiquidity) (mutez %addReward)) + (or (unit %assertBalances) (nat %balance_response_fa12))) + (or (or (list %balance_response_fa2 + (pair (pair %request (address %owner) (nat %token_id)) (nat %balance))) + (address %change_admin_address)) + (or (address %change_batcher_address) (address %change_marketmaker_address)))) + (or (or (address %change_tokenmanager_address) (unit %claim)) + (or (pair %injectLiquidity + (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))) + (unit %removeLiquidity)))) ; + storage + (pair (pair (pair (address %administrator) (address %batcher)) + (map %foreign_tokens + string + (pair (pair %token + (nat %token_id) + (string %name) + (option %address address) + (nat %decimals) + (option %standard string)) + (nat %amount))) + (address %marketmaker)) + (pair (pair %native_token + (pair %token + (nat %token_id) + (string %name) + (option %address address) + (nat %decimals) + (option %standard string)) + (nat %amount)) + (address %tokenmanager)) + (nat %total_shares) + (pair %vault_holdings + (set %keys address) + (big_map %values + address + (pair (pair (address %holder) (nat %shares)) (mutez %unclaimed))))) ; + code { LAMBDA + (pair (option address) nat) + address + { UNPAIR ; IF_NONE { FAILWITH } { SWAP ; DROP } } ; + EMPTY_MAP string (pair (pair nat string (option address) nat (option string)) nat) ; + LAMBDA + (pair (pair (pair nat string (option address) nat (option string)) nat) + (map string (pair (pair nat string (option address) nat (option string)) nat))) + (map string (pair (pair nat string (option address) nat (option string)) nat)) + { UNPAIR ; + SWAP ; + UNIT ; + RIGHT unit ; + DIG 2 ; + DUP ; + CAR ; + GET 3 ; + DUP 4 ; + DUP 2 ; + GET ; + IF_NONE + { DIG 2 ; DROP ; SWAP ; SOME ; SWAP ; UPDATE } + { DIG 3 ; + IF_LEFT + { DROP ; + DUP ; + CDR ; + DUP 4 ; + CDR ; + COMPARE ; + GT ; + IF { DROP ; PUSH nat 111 ; FAILWITH } + { DUP 3 ; CDR ; SWAP ; CDR ; SUB ; ABS } } + { DROP ; CDR ; DUP 3 ; CDR ; ADD } ; + DIG 3 ; + DIG 3 ; + DIG 2 ; + UPDATE 2 ; + SOME ; + DIG 2 ; + UPDATE } } ; + DIG 3 ; + UNPAIR ; + IF_LEFT + { DIG 2 ; + DIG 3 ; + DROP 2 ; + IF_LEFT + { IF_LEFT + { DIG 2 ; + DROP ; + IF_LEFT + { PUSH mutez 1 ; + AMOUNT ; + COMPARE ; + LT ; + IF {} { PUSH nat 118 ; FAILWITH } ; + SENDER ; + DUP 3 ; + CDR ; + CAR ; + CAR ; + DIG 2 ; + UPDATE 2 ; + SELF_ADDRESS ; + DUP 2 ; + CAR ; + GET 5 ; + IF_NONE + { DROP ; PUSH nat 109 ; FAILWITH } + { DUP 3 ; + CAR ; + GET 8 ; + IF_NONE + { DROP 2 ; PUSH nat 108 ; FAILWITH } + { PUSH string "FA1.2 token" ; + DUP 2 ; + COMPARE ; + EQ ; + IF { DROP ; + CONTRACT %transfer (pair (address %from) (address %to) (nat %value)) ; + IF_NONE { PUSH nat 101 ; FAILWITH } {} ; + PUSH mutez 0 ; + DUP 4 ; + CDR ; + DIG 3 ; + DUP 6 ; + PAIR 3 ; + TRANSFER_TOKENS } + { PUSH string "FA2 token" ; + SWAP ; + COMPARE ; + EQ ; + IF { CONTRACT %transfer + (list (pair (address %from_) (list %tx (pair (address %to_) (nat %token_id) (nat %amount))))) ; + IF_NONE { PUSH nat 101 ; FAILWITH } {} ; + PUSH mutez 0 ; + NIL (pair address (list (pair address nat nat))) ; + NIL (pair address nat nat) ; + DUP 6 ; + CDR ; + DUP 7 ; + CAR ; + CAR ; + DIG 6 ; + PAIR 3 ; + CONS ; + DUP 6 ; + PAIR ; + CONS ; + TRANSFER_TOKENS } + { DROP 2 ; PUSH nat 108 ; FAILWITH } } } } ; + DUP 4 ; + CDR ; + CAR ; + CAR ; + DUP ; + CAR ; + DUP 4 ; + CAR ; + DUP 2 ; + GET 8 ; + DUP 2 ; + GET 8 ; + COMPARE ; + EQ ; + DUP 3 ; + GET 7 ; + DUP 3 ; + GET 7 ; + COMPARE ; + EQ ; + DUP 4 ; + GET 5 ; + DUP 4 ; + GET 5 ; + COMPARE ; + EQ ; + DUP 5 ; + GET 3 ; + DUP 5 ; + GET 3 ; + COMPARE ; + EQ ; + DIG 5 ; + CAR ; + DIG 5 ; + CAR ; + COMPARE ; + EQ ; + AND ; + AND ; + AND ; + AND ; + NOT ; + IF { DIG 2 ; DIG 3 ; DIG 4 ; DROP 4 ; PUSH nat 115 ; FAILWITH } + { DUP 3 ; + CDR ; + DUP 6 ; + CDR ; + CDR ; + CAR ; + ADD ; + DUP 2 ; + DUP 5 ; + CDR ; + DIG 3 ; + CDR ; + ADD ; + UPDATE 2 ; + DUP 6 ; + CDR ; + CDR ; + CDR ; + DUP ; + CAR ; + DUP 7 ; + MEM ; + IF { CDR ; + DUP 6 ; + GET ; + IF_NONE { NONE (pair (pair address nat) mutez) } { SOME } } + { DROP ; NONE (pair (pair address nat) mutez) } ; + IF_NONE + { PUSH mutez 0 ; DIG 4 ; CDR ; DUP 6 ; PAIR ; PAIR } + { DIG 4 ; + CDR ; + DUP 2 ; + CAR ; + CDR ; + ADD ; + DUP 2 ; + DIG 2 ; + CAR ; + DIG 2 ; + UPDATE 2 ; + UPDATE 1 } ; + DUP 6 ; + DUP 7 ; + CDR ; + DUP ; + CDR ; + DIG 5 ; + UPDATE 1 ; + UPDATE 2 ; + UPDATE 2 ; + DUP ; + CDR ; + DUP ; + CDR ; + DIG 7 ; + CDR ; + CDR ; + CDR ; + DUP ; + CAR ; + DUP 9 ; + MEM ; + IF { DUP ; CDR ; DIG 5 ; SOME ; DIG 8 ; UPDATE ; UPDATE 2 } + { DUP ; + DUP 2 ; + CAR ; + DUP 10 ; + PUSH bool True ; + SWAP ; + UPDATE ; + UPDATE 1 ; + SWAP ; + CDR ; + DIG 5 ; + DIG 8 ; + SWAP ; + SOME ; + SWAP ; + UPDATE ; + UPDATE 2 } ; + UPDATE 2 ; + UPDATE 2 ; + UPDATE 2 ; + DUP ; + CDR ; + DUP ; + CAR ; + DIG 3 ; + UPDATE 1 ; + UPDATE 1 ; + UPDATE 2 } ; + NIL operation ; + DIG 2 ; + CONS } + { DUP 2 ; + CDR ; + CDR ; + CAR ; + INT ; + PUSH mutez 1 ; + DIG 2 ; + EDIV ; + IF_NONE { PUSH string "DIV by 0" ; FAILWITH } {} ; + CAR ; + INT ; + DUP 3 ; + CDR ; + CDR ; + CDR ; + EMPTY_MAP address (pair (pair address nat) mutez) ; + DUP 2 ; + CAR ; + ITER { SWAP ; + DUP 3 ; + CDR ; + DUP 3 ; + GET ; + IF_NONE { SWAP ; DROP } { DIG 2 ; SWAP ; SOME ; SWAP ; UPDATE } } ; + SWAP ; + DROP ; + EMPTY_BIG_MAP address (pair (pair address nat) mutez) ; + EMPTY_SET address ; + PAIR ; + SWAP ; + ITER { UNPAIR ; + DUP 2 ; + CAR ; + CDR ; + INT ; + PUSH int 1 ; + DUP 7 ; + PAIR ; + PUSH int 1 ; + DIG 2 ; + PAIR ; + DUP 2 ; + CAR ; + DUP 2 ; + CDR ; + MUL ; + DIG 2 ; + CDR ; + DIG 2 ; + CAR ; + MUL ; + PAIR ; + PUSH int 1 ; + DUP 6 ; + PAIR ; + 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 ; + 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 } } ; + DIG 2 ; + CAR ; + MUL ; + EDIV ; + IF_NONE { PUSH string "DIV by 0" ; FAILWITH } {} ; + CAR ; + ISNAT ; + IF_NONE { PUSH nat 119 ; FAILWITH } {} ; + PUSH mutez 1 ; + MUL ; + PUSH mutez 0 ; + DUP 2 ; + COMPARE ; + GT ; + IF { DUP 3 ; CDR ; ADD } { DROP ; DUP 2 ; CDR } ; + DIG 2 ; + SWAP ; + UPDATE 2 ; + DUP 3 ; + CAR ; + DUP 3 ; + MEM ; + IF { DUP 3 ; DIG 3 ; CDR ; DIG 2 ; SOME ; DIG 3 ; UPDATE ; UPDATE 2 } + { DUP 3 ; + DUP 4 ; + CAR ; + DUP 4 ; + PUSH bool True ; + SWAP ; + UPDATE ; + UPDATE 1 ; + DIG 3 ; + CDR ; + DIG 2 ; + DIG 3 ; + SWAP ; + SOME ; + SWAP ; + UPDATE ; + UPDATE 2 } } ; + SWAP ; + DIG 2 ; + DROP 2 ; + DUP 2 ; + DIG 2 ; + CDR ; + DUP ; + CDR ; + DIG 3 ; + UPDATE 2 ; + UPDATE 2 ; + UPDATE 2 ; + NIL operation } } + { IF_LEFT + { DIG 2 ; + DROP 2 ; + DUP ; + SELF_ADDRESS ; + DUP 3 ; + CDR ; + CAR ; + CAR ; + CAR ; + DUP ; + GET 5 ; + IF_NONE { PUSH nat 101 ; FAILWITH } {} ; + DUP 2 ; + GET 8 ; + IF_NONE { PUSH nat 108 ; FAILWITH } {} ; + PUSH string "FA1.2 token" ; + DUP 2 ; + COMPARE ; + EQ ; + IF { DIG 2 ; + DROP 2 ; + DUP 2 ; + CONTRACT %balance_response_fa12 nat ; + SWAP ; + CONTRACT %getBalance (pair address (contract nat)) ; + SWAP ; + IF_NONE + { DROP ; PUSH nat 172 ; FAILWITH } + { SWAP ; + IF_NONE + { DROP ; PUSH nat 173 ; FAILWITH } + { PUSH mutez 0 ; DIG 2 ; DUP 4 ; PAIR ; TRANSFER_TOKENS } } } + { PUSH string "FA2 token" ; + SWAP ; + COMPARE ; + EQ ; + IF { CONTRACT %balance_of + (pair (list %requests (pair (address %owner) (nat %token_id))) + (contract %callback + (list (pair (pair %request (address %owner) (nat %token_id)) (nat %balance))))) ; + DUP 3 ; + CONTRACT %balance_response_fa2 + (list (pair (pair %request (address %owner) (nat %token_id)) (nat %balance))) ; + IF_NONE + { DROP 2 ; PUSH nat 170 ; FAILWITH } + { SWAP ; + IF_NONE + { DROP 2 ; PUSH nat 171 ; FAILWITH } + { PUSH mutez 0 ; + DIG 2 ; + NIL (pair address nat) ; + DIG 4 ; + CAR ; + DUP 6 ; + PAIR ; + CONS ; + PAIR ; + TRANSFER_TOKENS } } } + { DROP 2 ; PUSH nat 108 ; FAILWITH } } ; + NIL operation ; + SWAP ; + CONS ; + DIG 3 ; + CAR ; + CDR ; + CAR ; + ITER { CDR ; + SWAP ; + DUP 2 ; + CAR ; + GET 5 ; + IF_NONE { PUSH nat 101 ; FAILWITH } {} ; + DUP 3 ; + CAR ; + GET 8 ; + IF_NONE { PUSH nat 108 ; FAILWITH } {} ; + PUSH string "FA1.2 token" ; + DUP 2 ; + COMPARE ; + EQ ; + IF { DIG 3 ; + DROP 2 ; + DUP 3 ; + CONTRACT %balance_response_fa12 nat ; + SWAP ; + CONTRACT %getBalance (pair address (contract nat)) ; + SWAP ; + IF_NONE + { DROP ; PUSH nat 172 ; FAILWITH } + { SWAP ; + IF_NONE + { DROP ; PUSH nat 173 ; FAILWITH } + { PUSH mutez 0 ; DIG 2 ; DUP 5 ; PAIR ; TRANSFER_TOKENS } } } + { PUSH string "FA2 token" ; + SWAP ; + COMPARE ; + EQ ; + IF { CONTRACT %balance_of + (pair (list %requests (pair (address %owner) (nat %token_id))) + (contract %callback + (list (pair (pair %request (address %owner) (nat %token_id)) (nat %balance))))) ; + DUP 4 ; + CONTRACT %balance_response_fa2 + (list (pair (pair %request (address %owner) (nat %token_id)) (nat %balance))) ; + IF_NONE + { DIG 2 ; DROP 2 ; PUSH nat 170 ; FAILWITH } + { SWAP ; + IF_NONE + { DIG 2 ; DROP 2 ; PUSH nat 171 ; FAILWITH } + { PUSH mutez 0 ; + DIG 2 ; + NIL (pair address nat) ; + DIG 5 ; + CAR ; + CAR ; + DUP 7 ; + PAIR ; + CONS ; + PAIR ; + TRANSFER_TOKENS } } } + { DIG 2 ; DROP 2 ; PUSH nat 108 ; FAILWITH } } ; + CONS } ; + SWAP ; + DROP } + { SENDER ; + PUSH nat 101 ; + DUP 4 ; + CDR ; + CAR ; + CAR ; + CAR ; + GET 5 ; + PAIR ; + DIG 4 ; + SWAP ; + EXEC ; + PUSH nat 0 ; + DUP 5 ; + CDR ; + CAR ; + CAR ; + CAR ; + CAR ; + COMPARE ; + EQ ; + DUP 3 ; + DIG 2 ; + COMPARE ; + EQ ; + AND ; + IF { DUP 3 ; + DUP 4 ; + CDR ; + DUP ; + CAR ; + DIG 5 ; + CDR ; + CAR ; + CAR ; + DUP 6 ; + UPDATE 2 ; + UPDATE 1 ; + UPDATE 1 ; + UPDATE 2 } + { DIG 2 } ; + DUP ; + CAR ; + CDR ; + CAR ; + DUP ; + ITER { CDR ; + DUP ; + CAR ; + GET 5 ; + IF_NONE { PUSH nat 101 ; FAILWITH } {} ; + PUSH nat 0 ; + DUP 3 ; + CAR ; + CAR ; + COMPARE ; + EQ ; + DUP 6 ; + DIG 2 ; + COMPARE ; + EQ ; + AND ; + IF { DUP 5 ; UPDATE 2 ; SWAP ; DUP 2 ; SOME ; DIG 2 ; CAR ; GET 3 ; UPDATE } + { DROP } } ; + DIG 2 ; + DIG 3 ; + DROP 2 ; + DUP 2 ; + DIG 2 ; + CAR ; + DUP ; + CDR ; + DIG 3 ; + UPDATE 1 ; + UPDATE 2 ; + UPDATE 1 ; + NIL operation } } } + { IF_LEFT + { IF_LEFT + { SENDER ; + DUG 2 ; + ITER { SWAP ; + DUP 2 ; + CDR ; + DIG 2 ; + CAR ; + CDR ; + PUSH nat 101 ; + DUP 4 ; + CDR ; + CAR ; + CAR ; + CAR ; + GET 5 ; + PAIR ; + DUP 6 ; + SWAP ; + EXEC ; + DUP 2 ; + DUP 5 ; + CDR ; + CAR ; + CAR ; + CAR ; + CAR ; + COMPARE ; + EQ ; + DUP 6 ; + DIG 2 ; + COMPARE ; + EQ ; + AND ; + IF { DUP 3 ; + DUP 4 ; + CDR ; + DUP ; + CAR ; + DIG 5 ; + CDR ; + CAR ; + CAR ; + DUP 6 ; + UPDATE 2 ; + UPDATE 1 ; + UPDATE 1 ; + UPDATE 2 } + { DIG 2 } ; + DUP ; + CAR ; + CDR ; + CAR ; + DUP ; + ITER { CDR ; + DUP ; + CAR ; + GET 5 ; + IF_NONE { PUSH nat 101 ; FAILWITH } {} ; + DUP 5 ; + DUP 3 ; + CAR ; + CAR ; + COMPARE ; + EQ ; + DUP 8 ; + DIG 2 ; + COMPARE ; + EQ ; + AND ; + IF { DUP 5 ; UPDATE 2 ; SWAP ; DUP 2 ; SOME ; DIG 2 ; CAR ; GET 3 ; UPDATE } + { DROP } } ; + DIG 2 ; + DIG 3 ; + DROP 2 ; + DUP 2 ; + DIG 2 ; + CAR ; + DUP ; + CDR ; + DIG 3 ; + UPDATE 1 ; + UPDATE 2 ; + UPDATE 1 } ; + SWAP ; + DIG 2 ; + DROP 2 } + { DIG 2 ; + DROP ; + DUP 2 ; + CAR ; + 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 ; + DUP ; + CAR ; + DIG 3 ; + UPDATE 1 ; + UPDATE 1 ; + UPDATE 1 } } + { DIG 2 ; + DROP ; + IF_LEFT + { DUP 2 ; + CAR ; + 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 ; + DUP ; + CAR ; + DIG 3 ; + UPDATE 2 ; + UPDATE 1 ; + UPDATE 1 } + { DUP 2 ; + CAR ; + 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 ; + DUP ; + CDR ; + DIG 3 ; + UPDATE 2 ; + UPDATE 2 ; + UPDATE 1 } } ; + NIL operation } ; + PAIR } + { DIG 4 ; + DROP ; + IF_LEFT + { DIG 2 ; + DIG 3 ; + DROP 2 ; + IF_LEFT + { DUP 2 ; + CAR ; + 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 ; + DUP ; + CAR ; + DIG 3 ; + UPDATE 2 ; + UPDATE 1 ; + UPDATE 2 ; + NIL operation ; + PAIR } + { DROP ; + PUSH mutez 1 ; + AMOUNT ; + COMPARE ; + LT ; + IF {} { PUSH nat 118 ; FAILWITH } ; + SENDER ; + DUP 2 ; + CDR ; + CDR ; + CDR ; + DUP ; + CAR ; + DUP 3 ; + MEM ; + IF { CDR ; + SWAP ; + GET ; + IF_NONE { NONE (pair (pair address nat) mutez) } { SOME } } + { DROP 2 ; NONE (pair (pair address nat) mutez) } ; + IF_NONE + { DROP ; PUSH nat 155 ; FAILWITH } + { DUP ; + CDR ; + PUSH mutez 0 ; + DUP 2 ; + COMPARE ; + EQ ; + IF { DROP 3 ; PUSH nat 155 ; FAILWITH } + { SWAP ; + PUSH mutez 0 ; + UPDATE 2 ; + DUP ; + CAR ; + CAR ; + CONTRACT unit ; + IF_NONE + { SWAP ; DROP ; PUSH nat 102 ; FAILWITH } + { DIG 2 ; UNIT ; TRANSFER_TOKENS } ; + DUP 3 ; + DUP 4 ; + CDR ; + DUP ; + CDR ; + DIG 5 ; + CDR ; + CDR ; + CDR ; + DUP 6 ; + CAR ; + CAR ; + DUP 2 ; + CAR ; + DUP 2 ; + MEM ; + IF { DUP 2 ; DIG 2 ; CDR ; DIG 7 ; SOME ; DIG 3 ; UPDATE ; UPDATE 2 } + { DUP 2 ; + DUP 3 ; + CAR ; + DUP 3 ; + PUSH bool True ; + SWAP ; + UPDATE ; + UPDATE 1 ; + DIG 2 ; + CDR ; + DIG 7 ; + DIG 3 ; + SWAP ; + SOME ; + SWAP ; + UPDATE ; + UPDATE 2 } ; + UPDATE 2 ; + UPDATE 2 ; + UPDATE 2 ; + NIL operation ; + DIG 2 ; + CONS ; + PAIR } } } } + { IF_LEFT + { DIG 2 ; + DIG 3 ; + DROP 2 ; + DUP 2 ; + CAR ; + CDR ; + CDR ; + SENDER ; + COMPARE ; + EQ ; + IF {} { PUSH nat 168 ; FAILWITH } ; + PUSH mutez 1 ; + AMOUNT ; + COMPARE ; + LT ; + IF {} { PUSH nat 118 ; FAILWITH } ; + UNIT ; + LEFT unit ; + LEFT unit ; + IF_LEFT + { IF_LEFT { DROP ; PUSH nat 1 } { DROP ; PUSH nat 0 } } + { DROP ; PUSH nat 2 } ; + DUP 2 ; + CDR ; + CAR ; + IF_LEFT { DROP ; PUSH nat 0 } { DROP ; PUSH nat 1 } ; + NOW ; + DUP 4 ; + CDR ; + CDR ; + DUP 5 ; + CAR ; + CAR ; + DIG 5 ; + CAR ; + CDR ; + PAIR ; + PAIR ; + PAIR 4 ; + DUP 2 ; + CAR ; + CAR ; + CDR ; + DUP 2 ; + CAR ; + CAR ; + CAR ; + GET 5 ; + IF_NONE + { DROP 2 ; PUSH nat 109 ; FAILWITH } + { DUP 3 ; + CAR ; + CAR ; + CAR ; + GET 8 ; + IF_NONE + { PUSH bool False } + { PUSH string "FA1.2 token" ; SWAP ; COMPARE ; EQ } ; + IF { DUP ; + CONTRACT %approve (pair (address %spender) (nat %value)) ; + IF_NONE { PUSH nat 157 ; FAILWITH } {} ; + PUSH mutez 0 ; + DUP 5 ; + CAR ; + CAR ; + CDR ; + DUP 5 ; + PAIR ; + TRANSFER_TOKENS } + { DUP 3 ; + CAR ; + CAR ; + CAR ; + GET 8 ; + IF_NONE + { PUSH bool False } + { PUSH string "FA2 token" ; SWAP ; COMPARE ; EQ } ; + IF { SELF_ADDRESS ; + DUP 2 ; + CONTRACT %add_operator + (pair (pair (address %operator) (address %owner)) (nat %token_id)) ; + IF_NONE { PUSH nat 157 ; FAILWITH } {} ; + PUSH mutez 0 ; + DUP 6 ; + CAR ; + CAR ; + CAR ; + CAR ; + DIG 3 ; + DUP 6 ; + PAIR ; + PAIR ; + TRANSFER_TOKENS } + { PUSH nat 108 ; FAILWITH } } ; + DUP 3 ; + CONTRACT %deposit + (pair (pair %swap + (pair %from + (pair %token + (nat %token_id) + (string %name) + (option %address address) + (nat %decimals) + (option %standard string)) + (nat %amount)) + (pair %to + (nat %token_id) + (string %name) + (option %address address) + (nat %decimals) + (option %standard string))) + (timestamp %created_at) + (nat %side) + (nat %tolerance)) ; + IF_NONE { PUSH nat 157 ; FAILWITH } {} ; + PUSH mutez 0 ; + DUP 6 ; + TRANSFER_TOKENS ; + DUP 5 ; + CAR ; + CAR ; + CAR ; + GET 8 ; + IF_NONE + { PUSH bool False } + { PUSH string "FA1.2 token" ; SWAP ; COMPARE ; EQ } ; + IF { DIG 2 ; DIG 3 ; DIG 4 ; DROP 3 ; NONE operation } + { DUP 5 ; + CAR ; + CAR ; + CAR ; + GET 8 ; + IF_NONE + { PUSH bool False } + { PUSH string "FA2 token" ; SWAP ; COMPARE ; EQ } ; + IF { SELF_ADDRESS ; + DIG 3 ; + CONTRACT %remove_operator + (pair (pair (address %operator) (address %owner)) (nat %token_id)) ; + IF_NONE { PUSH nat 157 ; FAILWITH } {} ; + PUSH mutez 0 ; + DIG 6 ; + CAR ; + CAR ; + CAR ; + CAR ; + DIG 3 ; + DIG 6 ; + PAIR ; + PAIR ; + TRANSFER_TOKENS ; + SOME } + { DIG 2 ; DIG 3 ; DIG 4 ; DROP 3 ; PUSH nat 108 ; FAILWITH } } ; + IF_NONE { NIL operation } { NIL operation ; SWAP ; CONS } ; + SWAP ; + CONS ; + SWAP ; + CONS } ; + SELF_ADDRESS ; + DUP 3 ; + CDR ; + CAR ; + CAR ; + CAR ; + DUP ; + GET 5 ; + IF_NONE { PUSH nat 101 ; FAILWITH } {} ; + DUP 2 ; + GET 8 ; + IF_NONE { PUSH nat 108 ; FAILWITH } {} ; + PUSH string "FA1.2 token" ; + DUP 2 ; + COMPARE ; + EQ ; + IF { DIG 2 ; + DROP 2 ; + DUP 2 ; + CONTRACT %balance_response_fa12 nat ; + SWAP ; + CONTRACT %getBalance (pair address (contract nat)) ; + SWAP ; + IF_NONE + { DROP ; PUSH nat 172 ; FAILWITH } + { SWAP ; + IF_NONE + { DROP ; PUSH nat 173 ; FAILWITH } + { PUSH mutez 0 ; DIG 2 ; DUP 4 ; PAIR ; TRANSFER_TOKENS } } } + { PUSH string "FA2 token" ; + SWAP ; + COMPARE ; + EQ ; + IF { CONTRACT %balance_of + (pair (list %requests (pair (address %owner) (nat %token_id))) + (contract %callback + (list (pair (pair %request (address %owner) (nat %token_id)) (nat %balance))))) ; + DUP 3 ; + CONTRACT %balance_response_fa2 + (list (pair (pair %request (address %owner) (nat %token_id)) (nat %balance))) ; + IF_NONE + { DROP 2 ; PUSH nat 170 ; FAILWITH } + { SWAP ; + IF_NONE + { DROP 2 ; PUSH nat 171 ; FAILWITH } + { PUSH mutez 0 ; + DIG 2 ; + NIL (pair address nat) ; + DIG 4 ; + CAR ; + DUP 6 ; + PAIR ; + CONS ; + PAIR ; + TRANSFER_TOKENS } } } + { DROP 2 ; PUSH nat 108 ; FAILWITH } } ; + NIL operation ; + SWAP ; + CONS ; + DUP 4 ; + CAR ; + CDR ; + CAR ; + ITER { CDR ; + SWAP ; + DUP 2 ; + CAR ; + GET 5 ; + IF_NONE { PUSH nat 101 ; FAILWITH } {} ; + DUP 3 ; + CAR ; + GET 8 ; + IF_NONE { PUSH nat 108 ; FAILWITH } {} ; + PUSH string "FA1.2 token" ; + DUP 2 ; + COMPARE ; + EQ ; + IF { DIG 3 ; + DROP 2 ; + DUP 3 ; + CONTRACT %balance_response_fa12 nat ; + SWAP ; + CONTRACT %getBalance (pair address (contract nat)) ; + SWAP ; + IF_NONE + { DROP ; PUSH nat 172 ; FAILWITH } + { SWAP ; + IF_NONE + { DROP ; PUSH nat 173 ; FAILWITH } + { PUSH mutez 0 ; DIG 2 ; DUP 5 ; PAIR ; TRANSFER_TOKENS } } } + { PUSH string "FA2 token" ; + SWAP ; + COMPARE ; + EQ ; + IF { CONTRACT %balance_of + (pair (list %requests (pair (address %owner) (nat %token_id))) + (contract %callback + (list (pair (pair %request (address %owner) (nat %token_id)) (nat %balance))))) ; + DUP 4 ; + CONTRACT %balance_response_fa2 + (list (pair (pair %request (address %owner) (nat %token_id)) (nat %balance))) ; + IF_NONE + { DIG 2 ; DROP 2 ; PUSH nat 170 ; FAILWITH } + { SWAP ; + IF_NONE + { DIG 2 ; DROP 2 ; PUSH nat 171 ; FAILWITH } + { PUSH mutez 0 ; + DIG 2 ; + NIL (pair address nat) ; + DIG 5 ; + CAR ; + CAR ; + DUP 7 ; + PAIR ; + CONS ; + PAIR ; + TRANSFER_TOKENS } } } + { DIG 2 ; DROP 2 ; PUSH nat 108 ; FAILWITH } } ; + CONS } ; + SWAP ; + DROP ; + NIL operation ; + SWAP ; + ITER { CONS } ; + SWAP ; + NIL operation ; + SWAP ; + ITER { CONS } ; + ITER { CONS } ; + NIL operation ; + SWAP ; + ITER { CONS } ; + PAIR } + { DROP ; + PUSH mutez 1 ; + AMOUNT ; + COMPARE ; + LT ; + IF {} { PUSH nat 118 ; FAILWITH } ; + SENDER ; + DUP 2 ; + CDR ; + CDR ; + CDR ; + DUP ; + CAR ; + DUP 3 ; + MEM ; + IF { CDR ; + DUP 2 ; + GET ; + IF_NONE { NONE (pair (pair address nat) mutez) } { SOME } } + { DROP ; NONE (pair (pair address nat) mutez) } ; + IF_NONE + { DROP 4 ; PUSH nat 151 ; FAILWITH } + { UNPAIR ; + CDR ; + DUP 4 ; + CDR ; + CDR ; + CAR ; + INT ; + PUSH int 1 ; + SWAP ; + PAIR ; + DUP 2 ; + INT ; + PUSH int 1 ; + SWAP ; + PAIR ; + DUP 2 ; + CAR ; + DUP 2 ; + CDR ; + MUL ; + DIG 2 ; + CDR ; + DIG 2 ; + CAR ; + MUL ; + PAIR ; + DUP 5 ; + CDR ; + CAR ; + CAR ; + DUP ; + CDR ; + INT ; + PUSH int 1 ; + SWAP ; + PAIR ; + DUP ; + CDR ; + DUP 4 ; + CDR ; + MUL ; + SWAP ; + CAR ; + DUP 4 ; + 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 ; + 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 } } ; + DIG 2 ; + CAR ; + MUL ; + EDIV ; + IF_NONE { PUSH string "DIV by 0" ; FAILWITH } {} ; + CAR ; + ISNAT ; + IF_NONE { PUSH nat 119 ; FAILWITH } {} ; + DUP 2 ; + CDR ; + DUP 2 ; + COMPARE ; + GT ; + IF { DROP 2 ; PUSH nat 153 ; FAILWITH } + { DUP ; + DUP 3 ; + CDR ; + INT ; + SUB ; + ABS ; + DUP 3 ; + DIG 2 ; + UPDATE 2 ; + PUSH nat 0 ; + DUP 2 ; + CDR ; + COMPARE ; + EQ ; + IF { DROP ; DUP 9 } { DUP 10 ; SWAP ; PAIR ; DUP 9 ; SWAP ; EXEC } ; + DUG 2 ; + UPDATE 2 ; + PAIR } ; + UNPAIR ; + SWAP ; + DIG 8 ; + DIG 3 ; + PAIR ; + PAIR ; + DUP 6 ; + CAR ; + CDR ; + CAR ; + ITER { CDR ; + SWAP ; + UNPAIR ; + UNPAIR ; + DUP 4 ; + CDR ; + INT ; + PUSH int 1 ; + SWAP ; + PAIR ; + DUP ; + CDR ; + DUP 3 ; + CDR ; + MUL ; + SWAP ; + CAR ; + DUP 3 ; + 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 ; + 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 } } ; + DIG 2 ; + CAR ; + MUL ; + EDIV ; + IF_NONE { PUSH string "DIV by 0" ; FAILWITH } {} ; + CAR ; + ISNAT ; + IF_NONE { PUSH nat 119 ; FAILWITH } {} ; + DUP 5 ; + CDR ; + DUP 2 ; + COMPARE ; + GT ; + IF { DIG 3 ; DIG 4 ; DROP 3 ; PUSH nat 153 ; FAILWITH } + { DUP ; + DUP 6 ; + CDR ; + INT ; + SUB ; + ABS ; + DUP 6 ; + DIG 2 ; + UPDATE 2 ; + PUSH nat 0 ; + DUP 2 ; + CDR ; + COMPARE ; + EQ ; + IF { DROP ; DIG 3 } { DIG 4 ; SWAP ; PAIR ; DUP 11 ; SWAP ; EXEC } ; + DIG 4 ; + DIG 2 ; + UPDATE 2 ; + PAIR } ; + UNPAIR ; + DIG 3 ; + SWAP ; + PAIR ; + DUP 9 ; + SWAP ; + EXEC ; + DIG 2 ; + PAIR ; + PAIR } ; + DIG 6 ; + DROP ; + UNPAIR ; + CDR ; + DUP 7 ; + CDR ; + CDR ; + CAR ; + DUP 5 ; + COMPARE ; + GT ; + IF { SWAP ; DIG 2 ; DIG 3 ; DIG 6 ; DROP 5 ; PUSH nat 154 ; FAILWITH } + { DIG 3 ; + DUP 7 ; + CDR ; + CDR ; + CAR ; + SUB ; + ABS ; + DIG 2 ; + DUP 7 ; + DIG 7 ; + CDR ; + DUP ; + CAR ; + DIG 6 ; + UPDATE 1 ; + UPDATE 1 ; + UPDATE 2 ; + DUP ; + CAR ; + DUP ; + CDR ; + DIG 5 ; + UPDATE 1 ; + UPDATE 2 ; + UPDATE 1 ; + DUP ; + CDR ; + DUP ; + CDR ; + DIG 4 ; + UPDATE 1 ; + UPDATE 2 ; + UPDATE 2 ; + PAIR } ; + UNPAIR ; + DUP 4 ; + CONTRACT unit ; + IF_NONE { PUSH nat 102 ; FAILWITH } { DUP 4 ; UNIT ; TRANSFER_TOKENS } ; + SELF_ADDRESS ; + NIL operation ; + DIG 4 ; + ITER { CDR ; + DUP ; + CAR ; + GET 5 ; + IF_NONE + { DROP ; PUSH nat 109 ; FAILWITH } + { DUP 2 ; + CAR ; + GET 8 ; + IF_NONE + { DROP 2 ; PUSH nat 108 ; FAILWITH } + { PUSH string "FA1.2 token" ; + DUP 2 ; + COMPARE ; + EQ ; + IF { DROP ; + CONTRACT %transfer (pair (address %from) (address %to) (nat %value)) ; + IF_NONE { PUSH nat 101 ; FAILWITH } {} ; + PUSH mutez 0 ; + DIG 2 ; + CDR ; + DUP 9 ; + DUP 6 ; + PAIR 3 ; + TRANSFER_TOKENS } + { PUSH string "FA2 token" ; + SWAP ; + COMPARE ; + EQ ; + IF { CONTRACT %transfer + (list (pair (address %from_) (list %tx (pair (address %to_) (nat %token_id) (nat %amount))))) ; + IF_NONE { PUSH nat 101 ; FAILWITH } {} ; + PUSH mutez 0 ; + NIL (pair address (list (pair address nat nat))) ; + NIL (pair address nat nat) ; + DUP 5 ; + CDR ; + DIG 5 ; + CAR ; + CAR ; + DUP 12 ; + PAIR 3 ; + CONS ; + DUP 6 ; + PAIR ; + CONS ; + TRANSFER_TOKENS } + { DROP 2 ; PUSH nat 108 ; FAILWITH } } } } ; + CONS } ; + SWAP ; + DROP ; + DUP 3 ; + CDR ; + CDR ; + CDR ; + DUP 4 ; + DIG 4 ; + CDR ; + DUP ; + CDR ; + DUP 4 ; + CAR ; + DUP 9 ; + MEM ; + IF { DUP 4 ; + DIG 4 ; + CDR ; + DIG 8 ; + NONE (pair (pair address nat) mutez) ; + SWAP ; + UPDATE ; + UPDATE 2 } + { DIG 7 ; DROP ; DIG 3 } ; + UPDATE 2 ; + UPDATE 2 ; + UPDATE 2 ; + PUSH mutez 0 ; + DIG 4 ; + COMPARE ; + GT ; + IF { SWAP ; DIG 2 ; CONS } { DIG 2 ; DROP ; SWAP } ; + PAIR } } } } } ; + view "get_native_token_of_vault" + unit + (pair (nat %token_id) + (string %name) + (option %address address) + (nat %decimals) + (option %standard string)) + { CDR ; CDR ; CAR ; CAR ; CAR } ; + view "check_entrypoints" + (pair address address) + (pair (pair bool bool) bool bool) + { CAR ; + UNPAIR ; + SELF_ADDRESS ; + SWAP ; + CONTRACT %balance_of + (pair (list %requests (pair (address %owner) (nat %token_id))) + (contract %callback + (list (pair (pair %request (address %owner) (nat %token_id)) (nat %balance))))) ; + DUP 2 ; + CONTRACT %balance_response_fa2 + (list (pair (pair %request (address %owner) (nat %token_id)) (nat %balance))) ; + DIG 3 ; + CONTRACT %getBalance (pair address (contract nat)) ; + DIG 3 ; + CONTRACT %balance_response_fa12 nat ; + IF_NONE { PUSH bool False } { DROP ; PUSH bool True } ; + SWAP ; + IF_NONE { PUSH bool False } { DROP ; PUSH bool True } ; + PAIR ; + SWAP ; + IF_NONE { PUSH bool False } { DROP ; PUSH bool True } ; + DIG 2 ; + IF_NONE { PUSH bool False } { DROP ; PUSH bool True } ; + PAIR ; + PAIR } } + diff --git a/batcher/michelson/btctz-vault-storage-ghostnet.tz b/batcher/michelson/btctz-vault-storage-ghostnet.tz new file mode 100644 index 00000000..c8e3e104 --- /dev/null +++ b/batcher/michelson/btctz-vault-storage-ghostnet.tz @@ -0,0 +1,9 @@ +(Pair (Pair (Pair "tz1ca4batAsNxMYab3mUK5H4QRjY8drV4ViL" "tz1ca4batAsNxMYab3mUK5H4QRjY8drV4ViL") + {} + "tz1ca4batAsNxMYab3mUK5H4QRjY8drV4ViL") + (Pair (Pair (Pair 0 "BTCtz" (Some "KT1ErLEYVsxqHxLgLucXViq5DYrtSyDuSFTe") 8 (Some "FA2 token")) 0) + "KT1SG9z3pU1cNh8dSranm5C5HXWphWi2pLwx") + 0 + {} + {}) + diff --git a/batcher/michelson/eurl-vault-ghostnet.tz b/batcher/michelson/eurl-vault-ghostnet.tz new file mode 100644 index 00000000..7713bed1 --- /dev/null +++ b/batcher/michelson/eurl-vault-ghostnet.tz @@ -0,0 +1,1650 @@ +{ parameter + (or (or (or (or (nat %addLiquidity) (mutez %addReward)) + (or (unit %assertBalances) (nat %balance_response_fa12))) + (or (or (list %balance_response_fa2 + (pair (pair %request (address %owner) (nat %token_id)) (nat %balance))) + (address %change_admin_address)) + (or (address %change_batcher_address) (address %change_marketmaker_address)))) + (or (or (address %change_tokenmanager_address) (unit %claim)) + (or (pair %injectLiquidity + (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))) + (unit %removeLiquidity)))) ; + storage + (pair (pair (pair (address %administrator) (address %batcher)) + (map %foreign_tokens + string + (pair (pair %token + (nat %token_id) + (string %name) + (option %address address) + (nat %decimals) + (option %standard string)) + (nat %amount))) + (address %marketmaker)) + (pair (pair %native_token + (pair %token + (nat %token_id) + (string %name) + (option %address address) + (nat %decimals) + (option %standard string)) + (nat %amount)) + (address %tokenmanager)) + (nat %total_shares) + (pair %vault_holdings + (set %keys address) + (big_map %values + address + (pair (pair (address %holder) (nat %shares)) (mutez %unclaimed))))) ; + code { LAMBDA + (pair (option address) nat) + address + { UNPAIR ; IF_NONE { FAILWITH } { SWAP ; DROP } } ; + EMPTY_MAP string (pair (pair nat string (option address) nat (option string)) nat) ; + LAMBDA + (pair (pair (pair nat string (option address) nat (option string)) nat) + (map string (pair (pair nat string (option address) nat (option string)) nat))) + (map string (pair (pair nat string (option address) nat (option string)) nat)) + { UNPAIR ; + SWAP ; + UNIT ; + RIGHT unit ; + DIG 2 ; + DUP ; + CAR ; + GET 3 ; + DUP 4 ; + DUP 2 ; + GET ; + IF_NONE + { DIG 2 ; DROP ; SWAP ; SOME ; SWAP ; UPDATE } + { DIG 3 ; + IF_LEFT + { DROP ; + DUP ; + CDR ; + DUP 4 ; + CDR ; + COMPARE ; + GT ; + IF { DROP ; PUSH nat 111 ; FAILWITH } + { DUP 3 ; CDR ; SWAP ; CDR ; SUB ; ABS } } + { DROP ; CDR ; DUP 3 ; CDR ; ADD } ; + DIG 3 ; + DIG 3 ; + DIG 2 ; + UPDATE 2 ; + SOME ; + DIG 2 ; + UPDATE } } ; + DIG 3 ; + UNPAIR ; + IF_LEFT + { DIG 2 ; + DIG 3 ; + DROP 2 ; + IF_LEFT + { IF_LEFT + { DIG 2 ; + DROP ; + IF_LEFT + { PUSH mutez 1 ; + AMOUNT ; + COMPARE ; + LT ; + IF {} { PUSH nat 118 ; FAILWITH } ; + SENDER ; + DUP 3 ; + CDR ; + CAR ; + CAR ; + DIG 2 ; + UPDATE 2 ; + SELF_ADDRESS ; + DUP 2 ; + CAR ; + GET 5 ; + IF_NONE + { DROP ; PUSH nat 109 ; FAILWITH } + { DUP 3 ; + CAR ; + GET 8 ; + IF_NONE + { DROP 2 ; PUSH nat 108 ; FAILWITH } + { PUSH string "FA1.2 token" ; + DUP 2 ; + COMPARE ; + EQ ; + IF { DROP ; + CONTRACT %transfer (pair (address %from) (address %to) (nat %value)) ; + IF_NONE { PUSH nat 101 ; FAILWITH } {} ; + PUSH mutez 0 ; + DUP 4 ; + CDR ; + DIG 3 ; + DUP 6 ; + PAIR 3 ; + TRANSFER_TOKENS } + { PUSH string "FA2 token" ; + SWAP ; + COMPARE ; + EQ ; + IF { CONTRACT %transfer + (list (pair (address %from_) (list %tx (pair (address %to_) (nat %token_id) (nat %amount))))) ; + IF_NONE { PUSH nat 101 ; FAILWITH } {} ; + PUSH mutez 0 ; + NIL (pair address (list (pair address nat nat))) ; + NIL (pair address nat nat) ; + DUP 6 ; + CDR ; + DUP 7 ; + CAR ; + CAR ; + DIG 6 ; + PAIR 3 ; + CONS ; + DUP 6 ; + PAIR ; + CONS ; + TRANSFER_TOKENS } + { DROP 2 ; PUSH nat 108 ; FAILWITH } } } } ; + DUP 4 ; + CDR ; + CAR ; + CAR ; + DUP ; + CAR ; + DUP 4 ; + CAR ; + DUP 2 ; + GET 8 ; + DUP 2 ; + GET 8 ; + COMPARE ; + EQ ; + DUP 3 ; + GET 7 ; + DUP 3 ; + GET 7 ; + COMPARE ; + EQ ; + DUP 4 ; + GET 5 ; + DUP 4 ; + GET 5 ; + COMPARE ; + EQ ; + DUP 5 ; + GET 3 ; + DUP 5 ; + GET 3 ; + COMPARE ; + EQ ; + DIG 5 ; + CAR ; + DIG 5 ; + CAR ; + COMPARE ; + EQ ; + AND ; + AND ; + AND ; + AND ; + NOT ; + IF { DIG 2 ; DIG 3 ; DIG 4 ; DROP 4 ; PUSH nat 115 ; FAILWITH } + { DUP 3 ; + CDR ; + DUP 6 ; + CDR ; + CDR ; + CAR ; + ADD ; + DUP 2 ; + DUP 5 ; + CDR ; + DIG 3 ; + CDR ; + ADD ; + UPDATE 2 ; + DUP 6 ; + CDR ; + CDR ; + CDR ; + DUP ; + CAR ; + DUP 7 ; + MEM ; + IF { CDR ; + DUP 6 ; + GET ; + IF_NONE { NONE (pair (pair address nat) mutez) } { SOME } } + { DROP ; NONE (pair (pair address nat) mutez) } ; + IF_NONE + { PUSH mutez 0 ; DIG 4 ; CDR ; DUP 6 ; PAIR ; PAIR } + { DIG 4 ; + CDR ; + DUP 2 ; + CAR ; + CDR ; + ADD ; + DUP 2 ; + DIG 2 ; + CAR ; + DIG 2 ; + UPDATE 2 ; + UPDATE 1 } ; + DUP 6 ; + DUP 7 ; + CDR ; + DUP ; + CDR ; + DIG 5 ; + UPDATE 1 ; + UPDATE 2 ; + UPDATE 2 ; + DUP ; + CDR ; + DUP ; + CDR ; + DIG 7 ; + CDR ; + CDR ; + CDR ; + DUP ; + CAR ; + DUP 9 ; + MEM ; + IF { DUP ; CDR ; DIG 5 ; SOME ; DIG 8 ; UPDATE ; UPDATE 2 } + { DUP ; + DUP 2 ; + CAR ; + DUP 10 ; + PUSH bool True ; + SWAP ; + UPDATE ; + UPDATE 1 ; + SWAP ; + CDR ; + DIG 5 ; + DIG 8 ; + SWAP ; + SOME ; + SWAP ; + UPDATE ; + UPDATE 2 } ; + UPDATE 2 ; + UPDATE 2 ; + UPDATE 2 ; + DUP ; + CDR ; + DUP ; + CAR ; + DIG 3 ; + UPDATE 1 ; + UPDATE 1 ; + UPDATE 2 } ; + NIL operation ; + DIG 2 ; + CONS } + { DUP 2 ; + CDR ; + CDR ; + CAR ; + INT ; + PUSH mutez 1 ; + DIG 2 ; + EDIV ; + IF_NONE { PUSH string "DIV by 0" ; FAILWITH } {} ; + CAR ; + INT ; + DUP 3 ; + CDR ; + CDR ; + CDR ; + EMPTY_MAP address (pair (pair address nat) mutez) ; + DUP 2 ; + CAR ; + ITER { SWAP ; + DUP 3 ; + CDR ; + DUP 3 ; + GET ; + IF_NONE { SWAP ; DROP } { DIG 2 ; SWAP ; SOME ; SWAP ; UPDATE } } ; + SWAP ; + DROP ; + EMPTY_BIG_MAP address (pair (pair address nat) mutez) ; + EMPTY_SET address ; + PAIR ; + SWAP ; + ITER { UNPAIR ; + DUP 2 ; + CAR ; + CDR ; + INT ; + PUSH int 1 ; + DUP 7 ; + PAIR ; + PUSH int 1 ; + DIG 2 ; + PAIR ; + DUP 2 ; + CAR ; + DUP 2 ; + CDR ; + MUL ; + DIG 2 ; + CDR ; + DIG 2 ; + CAR ; + MUL ; + PAIR ; + PUSH int 1 ; + DUP 6 ; + PAIR ; + 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 ; + 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 } } ; + DIG 2 ; + CAR ; + MUL ; + EDIV ; + IF_NONE { PUSH string "DIV by 0" ; FAILWITH } {} ; + CAR ; + ISNAT ; + IF_NONE { PUSH nat 119 ; FAILWITH } {} ; + PUSH mutez 1 ; + MUL ; + PUSH mutez 0 ; + DUP 2 ; + COMPARE ; + GT ; + IF { DUP 3 ; CDR ; ADD } { DROP ; DUP 2 ; CDR } ; + DIG 2 ; + SWAP ; + UPDATE 2 ; + DUP 3 ; + CAR ; + DUP 3 ; + MEM ; + IF { DUP 3 ; DIG 3 ; CDR ; DIG 2 ; SOME ; DIG 3 ; UPDATE ; UPDATE 2 } + { DUP 3 ; + DUP 4 ; + CAR ; + DUP 4 ; + PUSH bool True ; + SWAP ; + UPDATE ; + UPDATE 1 ; + DIG 3 ; + CDR ; + DIG 2 ; + DIG 3 ; + SWAP ; + SOME ; + SWAP ; + UPDATE ; + UPDATE 2 } } ; + SWAP ; + DIG 2 ; + DROP 2 ; + DUP 2 ; + DIG 2 ; + CDR ; + DUP ; + CDR ; + DIG 3 ; + UPDATE 2 ; + UPDATE 2 ; + UPDATE 2 ; + NIL operation } } + { IF_LEFT + { DIG 2 ; + DROP 2 ; + DUP ; + SELF_ADDRESS ; + DUP 3 ; + CDR ; + CAR ; + CAR ; + CAR ; + DUP ; + GET 5 ; + IF_NONE { PUSH nat 101 ; FAILWITH } {} ; + DUP 2 ; + GET 8 ; + IF_NONE { PUSH nat 108 ; FAILWITH } {} ; + PUSH string "FA1.2 token" ; + DUP 2 ; + COMPARE ; + EQ ; + IF { DIG 2 ; + DROP 2 ; + DUP 2 ; + CONTRACT %balance_response_fa12 nat ; + SWAP ; + CONTRACT %getBalance (pair address (contract nat)) ; + SWAP ; + IF_NONE + { DROP ; PUSH nat 172 ; FAILWITH } + { SWAP ; + IF_NONE + { DROP ; PUSH nat 173 ; FAILWITH } + { PUSH mutez 0 ; DIG 2 ; DUP 4 ; PAIR ; TRANSFER_TOKENS } } } + { PUSH string "FA2 token" ; + SWAP ; + COMPARE ; + EQ ; + IF { CONTRACT %balance_of + (pair (list %requests (pair (address %owner) (nat %token_id))) + (contract %callback + (list (pair (pair %request (address %owner) (nat %token_id)) (nat %balance))))) ; + DUP 3 ; + CONTRACT %balance_response_fa2 + (list (pair (pair %request (address %owner) (nat %token_id)) (nat %balance))) ; + IF_NONE + { DROP 2 ; PUSH nat 170 ; FAILWITH } + { SWAP ; + IF_NONE + { DROP 2 ; PUSH nat 171 ; FAILWITH } + { PUSH mutez 0 ; + DIG 2 ; + NIL (pair address nat) ; + DIG 4 ; + CAR ; + DUP 6 ; + PAIR ; + CONS ; + PAIR ; + TRANSFER_TOKENS } } } + { DROP 2 ; PUSH nat 108 ; FAILWITH } } ; + NIL operation ; + SWAP ; + CONS ; + DIG 3 ; + CAR ; + CDR ; + CAR ; + ITER { CDR ; + SWAP ; + DUP 2 ; + CAR ; + GET 5 ; + IF_NONE { PUSH nat 101 ; FAILWITH } {} ; + DUP 3 ; + CAR ; + GET 8 ; + IF_NONE { PUSH nat 108 ; FAILWITH } {} ; + PUSH string "FA1.2 token" ; + DUP 2 ; + COMPARE ; + EQ ; + IF { DIG 3 ; + DROP 2 ; + DUP 3 ; + CONTRACT %balance_response_fa12 nat ; + SWAP ; + CONTRACT %getBalance (pair address (contract nat)) ; + SWAP ; + IF_NONE + { DROP ; PUSH nat 172 ; FAILWITH } + { SWAP ; + IF_NONE + { DROP ; PUSH nat 173 ; FAILWITH } + { PUSH mutez 0 ; DIG 2 ; DUP 5 ; PAIR ; TRANSFER_TOKENS } } } + { PUSH string "FA2 token" ; + SWAP ; + COMPARE ; + EQ ; + IF { CONTRACT %balance_of + (pair (list %requests (pair (address %owner) (nat %token_id))) + (contract %callback + (list (pair (pair %request (address %owner) (nat %token_id)) (nat %balance))))) ; + DUP 4 ; + CONTRACT %balance_response_fa2 + (list (pair (pair %request (address %owner) (nat %token_id)) (nat %balance))) ; + IF_NONE + { DIG 2 ; DROP 2 ; PUSH nat 170 ; FAILWITH } + { SWAP ; + IF_NONE + { DIG 2 ; DROP 2 ; PUSH nat 171 ; FAILWITH } + { PUSH mutez 0 ; + DIG 2 ; + NIL (pair address nat) ; + DIG 5 ; + CAR ; + CAR ; + DUP 7 ; + PAIR ; + CONS ; + PAIR ; + TRANSFER_TOKENS } } } + { DIG 2 ; DROP 2 ; PUSH nat 108 ; FAILWITH } } ; + CONS } ; + SWAP ; + DROP } + { SENDER ; + PUSH nat 101 ; + DUP 4 ; + CDR ; + CAR ; + CAR ; + CAR ; + GET 5 ; + PAIR ; + DIG 4 ; + SWAP ; + EXEC ; + PUSH nat 0 ; + DUP 5 ; + CDR ; + CAR ; + CAR ; + CAR ; + CAR ; + COMPARE ; + EQ ; + DUP 3 ; + DIG 2 ; + COMPARE ; + EQ ; + AND ; + IF { DUP 3 ; + DUP 4 ; + CDR ; + DUP ; + CAR ; + DIG 5 ; + CDR ; + CAR ; + CAR ; + DUP 6 ; + UPDATE 2 ; + UPDATE 1 ; + UPDATE 1 ; + UPDATE 2 } + { DIG 2 } ; + DUP ; + CAR ; + CDR ; + CAR ; + DUP ; + ITER { CDR ; + DUP ; + CAR ; + GET 5 ; + IF_NONE { PUSH nat 101 ; FAILWITH } {} ; + PUSH nat 0 ; + DUP 3 ; + CAR ; + CAR ; + COMPARE ; + EQ ; + DUP 6 ; + DIG 2 ; + COMPARE ; + EQ ; + AND ; + IF { DUP 5 ; UPDATE 2 ; SWAP ; DUP 2 ; SOME ; DIG 2 ; CAR ; GET 3 ; UPDATE } + { DROP } } ; + DIG 2 ; + DIG 3 ; + DROP 2 ; + DUP 2 ; + DIG 2 ; + CAR ; + DUP ; + CDR ; + DIG 3 ; + UPDATE 1 ; + UPDATE 2 ; + UPDATE 1 ; + NIL operation } } } + { IF_LEFT + { IF_LEFT + { SENDER ; + DUG 2 ; + ITER { SWAP ; + DUP 2 ; + CDR ; + DIG 2 ; + CAR ; + CDR ; + PUSH nat 101 ; + DUP 4 ; + CDR ; + CAR ; + CAR ; + CAR ; + GET 5 ; + PAIR ; + DUP 6 ; + SWAP ; + EXEC ; + DUP 2 ; + DUP 5 ; + CDR ; + CAR ; + CAR ; + CAR ; + CAR ; + COMPARE ; + EQ ; + DUP 6 ; + DIG 2 ; + COMPARE ; + EQ ; + AND ; + IF { DUP 3 ; + DUP 4 ; + CDR ; + DUP ; + CAR ; + DIG 5 ; + CDR ; + CAR ; + CAR ; + DUP 6 ; + UPDATE 2 ; + UPDATE 1 ; + UPDATE 1 ; + UPDATE 2 } + { DIG 2 } ; + DUP ; + CAR ; + CDR ; + CAR ; + DUP ; + ITER { CDR ; + DUP ; + CAR ; + GET 5 ; + IF_NONE { PUSH nat 101 ; FAILWITH } {} ; + DUP 5 ; + DUP 3 ; + CAR ; + CAR ; + COMPARE ; + EQ ; + DUP 8 ; + DIG 2 ; + COMPARE ; + EQ ; + AND ; + IF { DUP 5 ; UPDATE 2 ; SWAP ; DUP 2 ; SOME ; DIG 2 ; CAR ; GET 3 ; UPDATE } + { DROP } } ; + DIG 2 ; + DIG 3 ; + DROP 2 ; + DUP 2 ; + DIG 2 ; + CAR ; + DUP ; + CDR ; + DIG 3 ; + UPDATE 1 ; + UPDATE 2 ; + UPDATE 1 } ; + SWAP ; + DIG 2 ; + DROP 2 } + { DIG 2 ; + DROP ; + DUP 2 ; + CAR ; + 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 ; + DUP ; + CAR ; + DIG 3 ; + UPDATE 1 ; + UPDATE 1 ; + UPDATE 1 } } + { DIG 2 ; + DROP ; + IF_LEFT + { DUP 2 ; + CAR ; + 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 ; + DUP ; + CAR ; + DIG 3 ; + UPDATE 2 ; + UPDATE 1 ; + UPDATE 1 } + { DUP 2 ; + CAR ; + 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 ; + DUP ; + CDR ; + DIG 3 ; + UPDATE 2 ; + UPDATE 2 ; + UPDATE 1 } } ; + NIL operation } ; + PAIR } + { DIG 4 ; + DROP ; + IF_LEFT + { DIG 2 ; + DIG 3 ; + DROP 2 ; + IF_LEFT + { DUP 2 ; + CAR ; + 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 ; + DUP ; + CAR ; + DIG 3 ; + UPDATE 2 ; + UPDATE 1 ; + UPDATE 2 ; + NIL operation ; + PAIR } + { DROP ; + PUSH mutez 1 ; + AMOUNT ; + COMPARE ; + LT ; + IF {} { PUSH nat 118 ; FAILWITH } ; + SENDER ; + DUP 2 ; + CDR ; + CDR ; + CDR ; + DUP ; + CAR ; + DUP 3 ; + MEM ; + IF { CDR ; + SWAP ; + GET ; + IF_NONE { NONE (pair (pair address nat) mutez) } { SOME } } + { DROP 2 ; NONE (pair (pair address nat) mutez) } ; + IF_NONE + { DROP ; PUSH nat 155 ; FAILWITH } + { DUP ; + CDR ; + PUSH mutez 0 ; + DUP 2 ; + COMPARE ; + EQ ; + IF { DROP 3 ; PUSH nat 155 ; FAILWITH } + { SWAP ; + PUSH mutez 0 ; + UPDATE 2 ; + DUP ; + CAR ; + CAR ; + CONTRACT unit ; + IF_NONE + { SWAP ; DROP ; PUSH nat 102 ; FAILWITH } + { DIG 2 ; UNIT ; TRANSFER_TOKENS } ; + DUP 3 ; + DUP 4 ; + CDR ; + DUP ; + CDR ; + DIG 5 ; + CDR ; + CDR ; + CDR ; + DUP 6 ; + CAR ; + CAR ; + DUP 2 ; + CAR ; + DUP 2 ; + MEM ; + IF { DUP 2 ; DIG 2 ; CDR ; DIG 7 ; SOME ; DIG 3 ; UPDATE ; UPDATE 2 } + { DUP 2 ; + DUP 3 ; + CAR ; + DUP 3 ; + PUSH bool True ; + SWAP ; + UPDATE ; + UPDATE 1 ; + DIG 2 ; + CDR ; + DIG 7 ; + DIG 3 ; + SWAP ; + SOME ; + SWAP ; + UPDATE ; + UPDATE 2 } ; + UPDATE 2 ; + UPDATE 2 ; + UPDATE 2 ; + NIL operation ; + DIG 2 ; + CONS ; + PAIR } } } } + { IF_LEFT + { DIG 2 ; + DIG 3 ; + DROP 2 ; + DUP 2 ; + CAR ; + CDR ; + CDR ; + SENDER ; + COMPARE ; + EQ ; + IF {} { PUSH nat 168 ; FAILWITH } ; + PUSH mutez 1 ; + AMOUNT ; + COMPARE ; + LT ; + IF {} { PUSH nat 118 ; FAILWITH } ; + UNIT ; + LEFT unit ; + LEFT unit ; + IF_LEFT + { IF_LEFT { DROP ; PUSH nat 1 } { DROP ; PUSH nat 0 } } + { DROP ; PUSH nat 2 } ; + DUP 2 ; + CDR ; + CAR ; + IF_LEFT { DROP ; PUSH nat 0 } { DROP ; PUSH nat 1 } ; + NOW ; + DUP 4 ; + CDR ; + CDR ; + DUP 5 ; + CAR ; + CAR ; + DIG 5 ; + CAR ; + CDR ; + PAIR ; + PAIR ; + PAIR 4 ; + DUP 2 ; + CAR ; + CAR ; + CDR ; + DUP 2 ; + CAR ; + CAR ; + CAR ; + GET 5 ; + IF_NONE + { DROP 2 ; PUSH nat 109 ; FAILWITH } + { DUP 3 ; + CAR ; + CAR ; + CAR ; + GET 8 ; + IF_NONE + { PUSH bool False } + { PUSH string "FA1.2 token" ; SWAP ; COMPARE ; EQ } ; + IF { DUP ; + CONTRACT %approve (pair (address %spender) (nat %value)) ; + IF_NONE { PUSH nat 157 ; FAILWITH } {} ; + PUSH mutez 0 ; + DUP 5 ; + CAR ; + CAR ; + CDR ; + DUP 5 ; + PAIR ; + TRANSFER_TOKENS } + { DUP 3 ; + CAR ; + CAR ; + CAR ; + GET 8 ; + IF_NONE + { PUSH bool False } + { PUSH string "FA2 token" ; SWAP ; COMPARE ; EQ } ; + IF { SELF_ADDRESS ; + DUP 2 ; + CONTRACT %add_operator + (pair (pair (address %operator) (address %owner)) (nat %token_id)) ; + IF_NONE { PUSH nat 157 ; FAILWITH } {} ; + PUSH mutez 0 ; + DUP 6 ; + CAR ; + CAR ; + CAR ; + CAR ; + DIG 3 ; + DUP 6 ; + PAIR ; + PAIR ; + TRANSFER_TOKENS } + { PUSH nat 108 ; FAILWITH } } ; + DUP 3 ; + CONTRACT %deposit + (pair (pair %swap + (pair %from + (pair %token + (nat %token_id) + (string %name) + (option %address address) + (nat %decimals) + (option %standard string)) + (nat %amount)) + (pair %to + (nat %token_id) + (string %name) + (option %address address) + (nat %decimals) + (option %standard string))) + (timestamp %created_at) + (nat %side) + (nat %tolerance)) ; + IF_NONE { PUSH nat 157 ; FAILWITH } {} ; + PUSH mutez 0 ; + DUP 6 ; + TRANSFER_TOKENS ; + DUP 5 ; + CAR ; + CAR ; + CAR ; + GET 8 ; + IF_NONE + { PUSH bool False } + { PUSH string "FA1.2 token" ; SWAP ; COMPARE ; EQ } ; + IF { DIG 2 ; DIG 3 ; DIG 4 ; DROP 3 ; NONE operation } + { DUP 5 ; + CAR ; + CAR ; + CAR ; + GET 8 ; + IF_NONE + { PUSH bool False } + { PUSH string "FA2 token" ; SWAP ; COMPARE ; EQ } ; + IF { SELF_ADDRESS ; + DIG 3 ; + CONTRACT %remove_operator + (pair (pair (address %operator) (address %owner)) (nat %token_id)) ; + IF_NONE { PUSH nat 157 ; FAILWITH } {} ; + PUSH mutez 0 ; + DIG 6 ; + CAR ; + CAR ; + CAR ; + CAR ; + DIG 3 ; + DIG 6 ; + PAIR ; + PAIR ; + TRANSFER_TOKENS ; + SOME } + { DIG 2 ; DIG 3 ; DIG 4 ; DROP 3 ; PUSH nat 108 ; FAILWITH } } ; + IF_NONE { NIL operation } { NIL operation ; SWAP ; CONS } ; + SWAP ; + CONS ; + SWAP ; + CONS } ; + SELF_ADDRESS ; + DUP 3 ; + CDR ; + CAR ; + CAR ; + CAR ; + DUP ; + GET 5 ; + IF_NONE { PUSH nat 101 ; FAILWITH } {} ; + DUP 2 ; + GET 8 ; + IF_NONE { PUSH nat 108 ; FAILWITH } {} ; + PUSH string "FA1.2 token" ; + DUP 2 ; + COMPARE ; + EQ ; + IF { DIG 2 ; + DROP 2 ; + DUP 2 ; + CONTRACT %balance_response_fa12 nat ; + SWAP ; + CONTRACT %getBalance (pair address (contract nat)) ; + SWAP ; + IF_NONE + { DROP ; PUSH nat 172 ; FAILWITH } + { SWAP ; + IF_NONE + { DROP ; PUSH nat 173 ; FAILWITH } + { PUSH mutez 0 ; DIG 2 ; DUP 4 ; PAIR ; TRANSFER_TOKENS } } } + { PUSH string "FA2 token" ; + SWAP ; + COMPARE ; + EQ ; + IF { CONTRACT %balance_of + (pair (list %requests (pair (address %owner) (nat %token_id))) + (contract %callback + (list (pair (pair %request (address %owner) (nat %token_id)) (nat %balance))))) ; + DUP 3 ; + CONTRACT %balance_response_fa2 + (list (pair (pair %request (address %owner) (nat %token_id)) (nat %balance))) ; + IF_NONE + { DROP 2 ; PUSH nat 170 ; FAILWITH } + { SWAP ; + IF_NONE + { DROP 2 ; PUSH nat 171 ; FAILWITH } + { PUSH mutez 0 ; + DIG 2 ; + NIL (pair address nat) ; + DIG 4 ; + CAR ; + DUP 6 ; + PAIR ; + CONS ; + PAIR ; + TRANSFER_TOKENS } } } + { DROP 2 ; PUSH nat 108 ; FAILWITH } } ; + NIL operation ; + SWAP ; + CONS ; + DUP 4 ; + CAR ; + CDR ; + CAR ; + ITER { CDR ; + SWAP ; + DUP 2 ; + CAR ; + GET 5 ; + IF_NONE { PUSH nat 101 ; FAILWITH } {} ; + DUP 3 ; + CAR ; + GET 8 ; + IF_NONE { PUSH nat 108 ; FAILWITH } {} ; + PUSH string "FA1.2 token" ; + DUP 2 ; + COMPARE ; + EQ ; + IF { DIG 3 ; + DROP 2 ; + DUP 3 ; + CONTRACT %balance_response_fa12 nat ; + SWAP ; + CONTRACT %getBalance (pair address (contract nat)) ; + SWAP ; + IF_NONE + { DROP ; PUSH nat 172 ; FAILWITH } + { SWAP ; + IF_NONE + { DROP ; PUSH nat 173 ; FAILWITH } + { PUSH mutez 0 ; DIG 2 ; DUP 5 ; PAIR ; TRANSFER_TOKENS } } } + { PUSH string "FA2 token" ; + SWAP ; + COMPARE ; + EQ ; + IF { CONTRACT %balance_of + (pair (list %requests (pair (address %owner) (nat %token_id))) + (contract %callback + (list (pair (pair %request (address %owner) (nat %token_id)) (nat %balance))))) ; + DUP 4 ; + CONTRACT %balance_response_fa2 + (list (pair (pair %request (address %owner) (nat %token_id)) (nat %balance))) ; + IF_NONE + { DIG 2 ; DROP 2 ; PUSH nat 170 ; FAILWITH } + { SWAP ; + IF_NONE + { DIG 2 ; DROP 2 ; PUSH nat 171 ; FAILWITH } + { PUSH mutez 0 ; + DIG 2 ; + NIL (pair address nat) ; + DIG 5 ; + CAR ; + CAR ; + DUP 7 ; + PAIR ; + CONS ; + PAIR ; + TRANSFER_TOKENS } } } + { DIG 2 ; DROP 2 ; PUSH nat 108 ; FAILWITH } } ; + CONS } ; + SWAP ; + DROP ; + NIL operation ; + SWAP ; + ITER { CONS } ; + SWAP ; + NIL operation ; + SWAP ; + ITER { CONS } ; + ITER { CONS } ; + NIL operation ; + SWAP ; + ITER { CONS } ; + PAIR } + { DROP ; + PUSH mutez 1 ; + AMOUNT ; + COMPARE ; + LT ; + IF {} { PUSH nat 118 ; FAILWITH } ; + SENDER ; + DUP 2 ; + CDR ; + CDR ; + CDR ; + DUP ; + CAR ; + DUP 3 ; + MEM ; + IF { CDR ; + DUP 2 ; + GET ; + IF_NONE { NONE (pair (pair address nat) mutez) } { SOME } } + { DROP ; NONE (pair (pair address nat) mutez) } ; + IF_NONE + { DROP 4 ; PUSH nat 151 ; FAILWITH } + { UNPAIR ; + CDR ; + DUP 4 ; + CDR ; + CDR ; + CAR ; + INT ; + PUSH int 1 ; + SWAP ; + PAIR ; + DUP 2 ; + INT ; + PUSH int 1 ; + SWAP ; + PAIR ; + DUP 2 ; + CAR ; + DUP 2 ; + CDR ; + MUL ; + DIG 2 ; + CDR ; + DIG 2 ; + CAR ; + MUL ; + PAIR ; + DUP 5 ; + CDR ; + CAR ; + CAR ; + DUP ; + CDR ; + INT ; + PUSH int 1 ; + SWAP ; + PAIR ; + DUP ; + CDR ; + DUP 4 ; + CDR ; + MUL ; + SWAP ; + CAR ; + DUP 4 ; + 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 ; + 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 } } ; + DIG 2 ; + CAR ; + MUL ; + EDIV ; + IF_NONE { PUSH string "DIV by 0" ; FAILWITH } {} ; + CAR ; + ISNAT ; + IF_NONE { PUSH nat 119 ; FAILWITH } {} ; + DUP 2 ; + CDR ; + DUP 2 ; + COMPARE ; + GT ; + IF { DROP 2 ; PUSH nat 153 ; FAILWITH } + { DUP ; + DUP 3 ; + CDR ; + INT ; + SUB ; + ABS ; + DUP 3 ; + DIG 2 ; + UPDATE 2 ; + PUSH nat 0 ; + DUP 2 ; + CDR ; + COMPARE ; + EQ ; + IF { DROP ; DUP 9 } { DUP 10 ; SWAP ; PAIR ; DUP 9 ; SWAP ; EXEC } ; + DUG 2 ; + UPDATE 2 ; + PAIR } ; + UNPAIR ; + SWAP ; + DIG 8 ; + DIG 3 ; + PAIR ; + PAIR ; + DUP 6 ; + CAR ; + CDR ; + CAR ; + ITER { CDR ; + SWAP ; + UNPAIR ; + UNPAIR ; + DUP 4 ; + CDR ; + INT ; + PUSH int 1 ; + SWAP ; + PAIR ; + DUP ; + CDR ; + DUP 3 ; + CDR ; + MUL ; + SWAP ; + CAR ; + DUP 3 ; + 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 ; + 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 } } ; + DIG 2 ; + CAR ; + MUL ; + EDIV ; + IF_NONE { PUSH string "DIV by 0" ; FAILWITH } {} ; + CAR ; + ISNAT ; + IF_NONE { PUSH nat 119 ; FAILWITH } {} ; + DUP 5 ; + CDR ; + DUP 2 ; + COMPARE ; + GT ; + IF { DIG 3 ; DIG 4 ; DROP 3 ; PUSH nat 153 ; FAILWITH } + { DUP ; + DUP 6 ; + CDR ; + INT ; + SUB ; + ABS ; + DUP 6 ; + DIG 2 ; + UPDATE 2 ; + PUSH nat 0 ; + DUP 2 ; + CDR ; + COMPARE ; + EQ ; + IF { DROP ; DIG 3 } { DIG 4 ; SWAP ; PAIR ; DUP 11 ; SWAP ; EXEC } ; + DIG 4 ; + DIG 2 ; + UPDATE 2 ; + PAIR } ; + UNPAIR ; + DIG 3 ; + SWAP ; + PAIR ; + DUP 9 ; + SWAP ; + EXEC ; + DIG 2 ; + PAIR ; + PAIR } ; + DIG 6 ; + DROP ; + UNPAIR ; + CDR ; + DUP 7 ; + CDR ; + CDR ; + CAR ; + DUP 5 ; + COMPARE ; + GT ; + IF { SWAP ; DIG 2 ; DIG 3 ; DIG 6 ; DROP 5 ; PUSH nat 154 ; FAILWITH } + { DIG 3 ; + DUP 7 ; + CDR ; + CDR ; + CAR ; + SUB ; + ABS ; + DIG 2 ; + DUP 7 ; + DIG 7 ; + CDR ; + DUP ; + CAR ; + DIG 6 ; + UPDATE 1 ; + UPDATE 1 ; + UPDATE 2 ; + DUP ; + CAR ; + DUP ; + CDR ; + DIG 5 ; + UPDATE 1 ; + UPDATE 2 ; + UPDATE 1 ; + DUP ; + CDR ; + DUP ; + CDR ; + DIG 4 ; + UPDATE 1 ; + UPDATE 2 ; + UPDATE 2 ; + PAIR } ; + UNPAIR ; + DUP 4 ; + CONTRACT unit ; + IF_NONE { PUSH nat 102 ; FAILWITH } { DUP 4 ; UNIT ; TRANSFER_TOKENS } ; + SELF_ADDRESS ; + NIL operation ; + DIG 4 ; + ITER { CDR ; + DUP ; + CAR ; + GET 5 ; + IF_NONE + { DROP ; PUSH nat 109 ; FAILWITH } + { DUP 2 ; + CAR ; + GET 8 ; + IF_NONE + { DROP 2 ; PUSH nat 108 ; FAILWITH } + { PUSH string "FA1.2 token" ; + DUP 2 ; + COMPARE ; + EQ ; + IF { DROP ; + CONTRACT %transfer (pair (address %from) (address %to) (nat %value)) ; + IF_NONE { PUSH nat 101 ; FAILWITH } {} ; + PUSH mutez 0 ; + DIG 2 ; + CDR ; + DUP 9 ; + DUP 6 ; + PAIR 3 ; + TRANSFER_TOKENS } + { PUSH string "FA2 token" ; + SWAP ; + COMPARE ; + EQ ; + IF { CONTRACT %transfer + (list (pair (address %from_) (list %tx (pair (address %to_) (nat %token_id) (nat %amount))))) ; + IF_NONE { PUSH nat 101 ; FAILWITH } {} ; + PUSH mutez 0 ; + NIL (pair address (list (pair address nat nat))) ; + NIL (pair address nat nat) ; + DUP 5 ; + CDR ; + DIG 5 ; + CAR ; + CAR ; + DUP 12 ; + PAIR 3 ; + CONS ; + DUP 6 ; + PAIR ; + CONS ; + TRANSFER_TOKENS } + { DROP 2 ; PUSH nat 108 ; FAILWITH } } } } ; + CONS } ; + SWAP ; + DROP ; + DUP 3 ; + CDR ; + CDR ; + CDR ; + DUP 4 ; + DIG 4 ; + CDR ; + DUP ; + CDR ; + DUP 4 ; + CAR ; + DUP 9 ; + MEM ; + IF { DUP 4 ; + DIG 4 ; + CDR ; + DIG 8 ; + NONE (pair (pair address nat) mutez) ; + SWAP ; + UPDATE ; + UPDATE 2 } + { DIG 7 ; DROP ; DIG 3 } ; + UPDATE 2 ; + UPDATE 2 ; + UPDATE 2 ; + PUSH mutez 0 ; + DIG 4 ; + COMPARE ; + GT ; + IF { SWAP ; DIG 2 ; CONS } { DIG 2 ; DROP ; SWAP } ; + PAIR } } } } } ; + view "get_native_token_of_vault" + unit + (pair (nat %token_id) + (string %name) + (option %address address) + (nat %decimals) + (option %standard string)) + { CDR ; CDR ; CAR ; CAR ; CAR } ; + view "check_entrypoints" + (pair address address) + (pair (pair bool bool) bool bool) + { CAR ; + UNPAIR ; + SELF_ADDRESS ; + SWAP ; + CONTRACT %balance_of + (pair (list %requests (pair (address %owner) (nat %token_id))) + (contract %callback + (list (pair (pair %request (address %owner) (nat %token_id)) (nat %balance))))) ; + DUP 2 ; + CONTRACT %balance_response_fa2 + (list (pair (pair %request (address %owner) (nat %token_id)) (nat %balance))) ; + DIG 3 ; + CONTRACT %getBalance (pair address (contract nat)) ; + DIG 3 ; + CONTRACT %balance_response_fa12 nat ; + IF_NONE { PUSH bool False } { DROP ; PUSH bool True } ; + SWAP ; + IF_NONE { PUSH bool False } { DROP ; PUSH bool True } ; + PAIR ; + SWAP ; + IF_NONE { PUSH bool False } { DROP ; PUSH bool True } ; + DIG 2 ; + IF_NONE { PUSH bool False } { DROP ; PUSH bool True } ; + PAIR ; + PAIR } } + diff --git a/batcher/michelson/eurl-vault-storage-ghostnet.tz b/batcher/michelson/eurl-vault-storage-ghostnet.tz new file mode 100644 index 00000000..d95d3442 --- /dev/null +++ b/batcher/michelson/eurl-vault-storage-ghostnet.tz @@ -0,0 +1,9 @@ +(Pair (Pair (Pair "tz1ca4batAsNxMYab3mUK5H4QRjY8drV4ViL" "tz1ca4batAsNxMYab3mUK5H4QRjY8drV4ViL") + {} + "tz1ca4batAsNxMYab3mUK5H4QRjY8drV4ViL") + (Pair (Pair (Pair 0 "EURL" (Some "KT1RcHjqDWWycYQGrz4KBYoGZSMmMuVpkmuS") 6 (Some "FA2 token")) 0) + "KT1SG9z3pU1cNh8dSranm5C5HXWphWi2pLwx") + 0 + {} + {}) + diff --git a/batcher/michelson/marketmaker-ghostnet.tz b/batcher/michelson/marketmaker-ghostnet.tz new file mode 100644 index 00000000..f5bdb77f --- /dev/null +++ b/batcher/michelson/marketmaker-ghostnet.tz @@ -0,0 +1,1029 @@ +{ 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 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 } ; + SWAP ; + UNPAIR ; + IF_LEFT + { DIG 2 ; + DROP ; + 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_of_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 ; + CDR ; + CDR ; + DUP 4 ; + DIG 4 ; + CDR ; + DUP 3 ; + CAR ; + DUP 5 ; + MEM ; + IF { DUP 3 ; DIG 3 ; CDR ; DIG 5 ; SOME ; DIG 5 ; UPDATE ; UPDATE 2 } + { DUP 3 ; + DUP 4 ; + CAR ; + DUP 6 ; + PUSH bool True ; + SWAP ; + UPDATE ; + UPDATE 1 ; + DIG 3 ; + 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 ; + DROP ; + 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_of_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 ; + 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 } } ; + 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 ; + SWAP ; + GET 3 ; + PUSH int 1 ; + DIG 2 ; + PAIR ; + DUP 2 ; + CDR ; + DUP 2 ; + CDR ; + MUL ; + DIG 2 ; + 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 ; + 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 } } ; + 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 ; + 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 } } ; + 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 ; + SWAP ; + GET 3 ; + PUSH int 1 ; + DIG 2 ; + PAIR ; + DUP 2 ; + CDR ; + DUP 2 ; + CDR ; + MUL ; + DIG 2 ; + 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 ; + 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 } } ; + 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 ; + DROP 4 ; + 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/tokenmanager-ghostnet.tz b/batcher/michelson/tokenmanager-ghostnet.tz new file mode 100644 index 00000000..cab9569c --- /dev/null +++ b/batcher/michelson/tokenmanager-ghostnet.tz @@ -0,0 +1,1365 @@ +{ parameter + (or (or (or (pair %add_token_swap_pair + (pair %swap + (pair %from + (pair %token + (nat %token_id) + (string %name) + (option %address address) + (nat %decimals) + (option %standard string)) + (nat %amount)) + (pair %to + (nat %token_id) + (string %name) + (option %address address) + (nat %decimals) + (option %standard string))) + (address %oracle_address) + (string %oracle_asset_name) + (nat %oracle_precision) + (bool %is_disabled_for_deposits)) + (nat %amend_token_and_pair_limit)) + (or (address %change_admin_address) + (pair %change_oracle_source_of_pair + (string %pair_name) + (address %oracle_address) + (string %oracle_asset_name) + (nat %oracle_precision)))) + (or (or (string %disable_swap_pair_for_deposit) (string %enable_swap_pair_for_deposit)) + (pair %remove_token_swap_pair + (pair %swap + (pair %from + (pair %token + (nat %token_id) + (string %name) + (option %address address) + (nat %decimals) + (option %standard string)) + (nat %amount)) + (pair %to + (nat %token_id) + (string %name) + (option %address address) + (nat %decimals) + (option %standard string))) + (address %oracle_address) + (string %oracle_asset_name) + (nat %oracle_precision) + (bool %is_disabled_for_deposits)))) ; + storage + (pair (pair (address %administrator) (nat %limit_on_tokens_or_pairs)) + (pair %valid_swaps + (set %keys string) + (big_map %values + string + (pair (pair %swap (string %from) (string %to)) + (address %oracle_address) + (string %oracle_asset_name) + (nat %oracle_precision) + (bool %is_disabled_for_deposits)))) + (pair %valid_tokens + (set %keys string) + (big_map %values + string + (pair (nat %token_id) + (string %name) + (option %address address) + (nat %decimals) + (option %standard string))))) ; + code { UNPAIR ; + IF_LEFT + { IF_LEFT + { 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 } ; + PUSH nat 6 ; + DUP 2 ; + CAR ; + CAR ; + CAR ; + GET 7 ; + COMPARE ; + LT ; + IF { DROP 2 ; PUSH nat 134 ; FAILWITH } + { PUSH nat 6 ; + DUP 2 ; + CAR ; + CDR ; + GET 7 ; + COMPARE ; + LT ; + IF { DROP 2 ; PUSH nat 134 ; FAILWITH } + { PUSH nat 6 ; + DUP 2 ; + GET 7 ; + COMPARE ; + NEQ ; + IF { DROP 2 ; PUSH nat 133 ; FAILWITH } + { DUP 2 ; + CDR ; + CDR ; + DUP 3 ; + CDR ; + CAR ; + DUP 3 ; + CAR ; + DUP ; + CAR ; + CAR ; + DUP 2 ; + CDR ; + DUP 7 ; + CAR ; + CDR ; + DUP ; + PUSH nat 1 ; + DUP 7 ; + CAR ; + SIZE ; + ADD ; + COMPARE ; + GT ; + IF { DROP ; PUSH nat 127 ; FAILWITH } + { EMPTY_MAP string (pair nat string (option address) nat (option string)) ; + DUP 7 ; + CAR ; + ITER { SWAP ; + DUP 8 ; + CDR ; + DUP 3 ; + GET ; + IF_NONE { SWAP ; DROP } { DIG 2 ; SWAP ; SOME ; SWAP ; UPDATE } } ; + PUSH bool False ; + SWAP ; + ITER { CDR ; + SWAP ; + DUP 2 ; + GET 8 ; + DUP 6 ; + GET 8 ; + COMPARE ; + EQ ; + DUP 3 ; + GET 7 ; + DUP 7 ; + GET 7 ; + COMPARE ; + EQ ; + DUP 4 ; + GET 5 ; + DUP 8 ; + GET 5 ; + COMPARE ; + EQ ; + DUP 5 ; + GET 3 ; + DUP 9 ; + GET 3 ; + COMPARE ; + EQ ; + DIG 5 ; + CAR ; + DUP 9 ; + CAR ; + COMPARE ; + EQ ; + AND ; + AND ; + AND ; + AND ; + OR } ; + EMPTY_MAP string (pair nat string (option address) nat (option string)) ; + DUP 8 ; + CAR ; + ITER { SWAP ; + DUP 9 ; + CDR ; + DUP 3 ; + GET ; + IF_NONE { SWAP ; DROP } { DIG 2 ; SWAP ; SOME ; SWAP ; UPDATE } } ; + PUSH bool False ; + SWAP ; + ITER { CDR ; + SWAP ; + DUP 2 ; + GET 8 ; + DUP 6 ; + GET 8 ; + COMPARE ; + EQ ; + DUP 3 ; + GET 7 ; + DUP 7 ; + GET 7 ; + COMPARE ; + EQ ; + DUP 4 ; + GET 5 ; + DUP 8 ; + GET 5 ; + COMPARE ; + EQ ; + DUP 5 ; + GET 3 ; + DUP 9 ; + GET 3 ; + COMPARE ; + EQ ; + DIG 5 ; + CAR ; + DUP 9 ; + CAR ; + COMPARE ; + EQ ; + AND ; + AND ; + AND ; + AND ; + OR } ; + AND ; + IF { PUSH nat 0 } + { EMPTY_MAP string (pair nat string (option address) nat (option string)) ; + DUP 7 ; + CAR ; + ITER { SWAP ; + DUP 8 ; + CDR ; + DUP 3 ; + GET ; + IF_NONE { SWAP ; DROP } { DIG 2 ; SWAP ; SOME ; SWAP ; UPDATE } } ; + PUSH bool False ; + SWAP ; + ITER { CDR ; + SWAP ; + DUP 2 ; + GET 8 ; + DUP 6 ; + GET 8 ; + COMPARE ; + EQ ; + DUP 3 ; + GET 7 ; + DUP 7 ; + GET 7 ; + COMPARE ; + EQ ; + DUP 4 ; + GET 5 ; + DUP 8 ; + GET 5 ; + COMPARE ; + EQ ; + DUP 5 ; + GET 3 ; + DUP 9 ; + GET 3 ; + COMPARE ; + EQ ; + DIG 5 ; + CAR ; + DUP 9 ; + CAR ; + COMPARE ; + EQ ; + AND ; + AND ; + AND ; + AND ; + OR } ; + EMPTY_MAP string (pair nat string (option address) nat (option string)) ; + DUP 8 ; + CAR ; + ITER { SWAP ; + DUP 9 ; + CDR ; + DUP 3 ; + GET ; + IF_NONE { SWAP ; DROP } { DIG 2 ; SWAP ; SOME ; SWAP ; UPDATE } } ; + PUSH bool False ; + SWAP ; + ITER { CDR ; + SWAP ; + DUP 2 ; + GET 8 ; + DUP 6 ; + GET 8 ; + COMPARE ; + EQ ; + DUP 3 ; + GET 7 ; + DUP 7 ; + GET 7 ; + COMPARE ; + EQ ; + DUP 4 ; + GET 5 ; + DUP 8 ; + GET 5 ; + COMPARE ; + EQ ; + DUP 5 ; + GET 3 ; + DUP 9 ; + GET 3 ; + COMPARE ; + EQ ; + DIG 5 ; + CAR ; + DUP 9 ; + CAR ; + COMPARE ; + EQ ; + AND ; + AND ; + AND ; + AND ; + OR } ; + OR ; + IF { PUSH nat 1 } { PUSH nat 2 } } ; + DUP 7 ; + CAR ; + SIZE ; + ADD ; + COMPARE ; + GT ; + IF { PUSH nat 126 ; FAILWITH } {} } ; + DUP 3 ; + CDR ; + GET 3 ; + DIG 3 ; + CAR ; + CAR ; + GET 3 ; + SWAP ; + DUP 2 ; + DUP 2 ; + COMPARE ; + GT ; + IF { SWAP ; PUSH string "/" ; CONCAT ; SWAP ; CONCAT } + { PUSH string "/" ; CONCAT ; SWAP ; CONCAT } ; + DUP 4 ; + CAR ; + DUP 2 ; + MEM ; + IF { DUP 4 ; + CDR ; + SWAP ; + GET ; + IF_NONE { NONE (pair (pair string string) address string nat bool) } { SOME } } + { DROP ; NONE (pair (pair string string) address string nat bool) } ; + IF_NONE + { DUP 2 ; + GET 3 ; + DUP 5 ; + CAR ; + DUP 2 ; + MEM ; + IF { DUP 5 ; + CDR ; + SWAP ; + GET ; + IF_NONE + { NONE (pair nat string (option address) nat (option string)) } + { SOME } } + { DROP ; NONE (pair nat string (option address) nat (option string)) } ; + IF_NONE + { DUP 2 ; + GET 3 ; + DUP 5 ; + CAR ; + DUP 2 ; + MEM ; + IF { DUP 5 ; DIG 5 ; CDR ; DIG 4 ; SOME ; DIG 3 ; UPDATE ; UPDATE 2 } + { DUP 5 ; + DUP 6 ; + CAR ; + DUP 3 ; + PUSH bool True ; + SWAP ; + UPDATE ; + UPDATE 1 ; + DIG 5 ; + CDR ; + DIG 4 ; + DIG 3 ; + SWAP ; + SOME ; + SWAP ; + UPDATE ; + UPDATE 2 } } + { DUP 3 ; + GET 8 ; + DUP 2 ; + GET 8 ; + COMPARE ; + EQ ; + DUP 4 ; + GET 7 ; + DUP 3 ; + GET 7 ; + COMPARE ; + EQ ; + DUP 5 ; + GET 5 ; + DUP 4 ; + GET 5 ; + COMPARE ; + EQ ; + DUP 6 ; + GET 3 ; + DUP 5 ; + GET 3 ; + COMPARE ; + EQ ; + DIG 6 ; + CAR ; + DIG 5 ; + CAR ; + COMPARE ; + EQ ; + AND ; + AND ; + AND ; + AND ; + IF { DIG 2 } { DIG 2 ; DROP ; PUSH nat 115 ; FAILWITH } } ; + DUP 2 ; + GET 3 ; + DUP 2 ; + CAR ; + DUP 2 ; + MEM ; + IF { DUP 2 ; + CDR ; + SWAP ; + GET ; + IF_NONE + { NONE (pair nat string (option address) nat (option string)) } + { SOME } } + { DROP ; NONE (pair nat string (option address) nat (option string)) } ; + IF_NONE + { DUP 2 ; + GET 3 ; + DUP 2 ; + CAR ; + DUP 2 ; + MEM ; + IF { DUP 2 ; DIG 2 ; CDR ; DIG 3 ; SOME ; DIG 3 ; UPDATE ; UPDATE 2 } + { DUP 2 ; + DUP 3 ; + CAR ; + DUP 3 ; + PUSH bool True ; + SWAP ; + UPDATE ; + UPDATE 1 ; + DIG 2 ; + CDR ; + DIG 3 ; + DIG 3 ; + SWAP ; + SOME ; + SWAP ; + UPDATE ; + UPDATE 2 } } + { DUP 3 ; + GET 8 ; + DUP 2 ; + GET 8 ; + COMPARE ; + EQ ; + DUP 4 ; + GET 7 ; + DUP 3 ; + GET 7 ; + COMPARE ; + EQ ; + DUP 5 ; + GET 5 ; + DUP 4 ; + GET 5 ; + COMPARE ; + EQ ; + DUP 6 ; + GET 3 ; + DUP 5 ; + GET 3 ; + COMPARE ; + EQ ; + DIG 6 ; + CAR ; + DIG 5 ; + CAR ; + COMPARE ; + EQ ; + AND ; + AND ; + AND ; + AND ; + IF {} { DROP ; PUSH nat 115 ; FAILWITH } } ; + DUP 3 ; + CAR ; + DUP ; + CDR ; + GET 3 ; + SWAP ; + CAR ; + CAR ; + GET 3 ; + SWAP ; + DUP 2 ; + DUP 2 ; + COMPARE ; + GT ; + IF { SWAP ; PUSH string "/" ; CONCAT ; SWAP ; CONCAT } + { PUSH string "/" ; CONCAT ; SWAP ; CONCAT } ; + SWAP ; + DUP 4 ; + GET 8 ; + DUP 5 ; + GET 7 ; + DUP 6 ; + GET 5 ; + DUP 7 ; + GET 3 ; + DIG 7 ; + CAR ; + DUP ; + CDR ; + GET 3 ; + SWAP ; + CAR ; + CAR ; + GET 3 ; + PAIR ; + PAIR 5 ; + DUP 4 ; + CAR ; + DUP 4 ; + MEM ; + IF { DUP 4 ; DIG 4 ; CDR ; DIG 2 ; SOME ; DIG 4 ; UPDATE ; UPDATE 2 } + { DUP 4 ; + DUP 5 ; + CAR ; + DUP 5 ; + PUSH bool True ; + SWAP ; + UPDATE ; + UPDATE 1 ; + DIG 4 ; + CDR ; + DIG 2 ; + DIG 4 ; + SWAP ; + SOME ; + SWAP ; + UPDATE ; + UPDATE 2 } ; + PAIR } + { DROP 6 ; PUSH nat 116 ; FAILWITH } ; + UNPAIR ; + DUP 3 ; + DIG 3 ; + CDR ; + DIG 2 ; + UPDATE 1 ; + UPDATE 2 ; + DUP ; + CDR ; + DIG 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 ; + CDR ; + CDR ; + CAR ; + SIZE ; + DUP 2 ; + COMPARE ; + LT ; + IF { DROP 2 ; PUSH nat 128 ; FAILWITH } + { DUP 2 ; + CDR ; + CAR ; + CAR ; + SIZE ; + DUP 2 ; + COMPARE ; + LT ; + IF { DROP 2 ; PUSH nat 129 ; FAILWITH } + { DUP 2 ; DIG 2 ; CAR ; DIG 2 ; UPDATE 2 ; 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 1 ; + 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 ; + CDR ; + CAR ; + DUP 2 ; + CAR ; + DUP 2 ; + CAR ; + DUP 2 ; + MEM ; + IF { SWAP ; + CDR ; + SWAP ; + GET ; + IF_NONE { NONE (pair (pair string string) address string nat bool) } { SOME } } + { DROP 2 ; NONE (pair (pair string string) address string nat bool) } ; + IF_NONE { PUSH nat 117 ; FAILWITH } {} ; + DUP ; + GET 3 ; + DUP 2 ; + GET 5 ; + VIEW "getPrice" (pair timestamp nat) ; + IF_NONE { PUSH nat 123 ; FAILWITH } { DROP } ; + DUP 3 ; + DUP 4 ; + CDR ; + DIG 4 ; + CDR ; + CAR ; + DIG 3 ; + DUP 5 ; + GET 3 ; + UPDATE 3 ; + DUP 5 ; + GET 5 ; + UPDATE 5 ; + DUP 5 ; + GET 6 ; + UPDATE 7 ; + DIG 4 ; + CAR ; + DUP 3 ; + CAR ; + DUP 2 ; + MEM ; + IF { DUP 3 ; DIG 3 ; CDR ; DIG 3 ; SOME ; DIG 3 ; UPDATE ; UPDATE 2 } + { DUP 3 ; + DUP 4 ; + CAR ; + DUP 3 ; + PUSH bool True ; + SWAP ; + UPDATE ; + UPDATE 1 ; + DIG 3 ; + CDR ; + DIG 3 ; + DIG 3 ; + SWAP ; + SOME ; + SWAP ; + UPDATE ; + UPDATE 2 } ; + UPDATE 1 ; + UPDATE 2 } ; + NIL operation ; + PAIR } } + { IF_LEFT + { 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 ; + CDR ; + CAR ; + DUP ; + CAR ; + DUP 3 ; + MEM ; + IF { CDR ; + DUP 2 ; + GET ; + IF_NONE { NONE (pair (pair string string) address string nat bool) } { SOME } } + { DROP ; NONE (pair (pair string string) address string nat bool) } ; + IF_NONE { PUSH nat 117 ; FAILWITH } {} ; + DUP 3 ; + DUP 4 ; + CDR ; + DIG 4 ; + CDR ; + CAR ; + DIG 3 ; + PUSH bool True ; + UPDATE 8 ; + DUP 2 ; + CAR ; + DUP 6 ; + MEM ; + IF { DUP 2 ; DIG 2 ; CDR ; DIG 2 ; SOME ; DIG 5 ; UPDATE ; UPDATE 2 } + { DUP 2 ; + DUP 3 ; + CAR ; + DUP 7 ; + PUSH bool True ; + SWAP ; + UPDATE ; + UPDATE 1 ; + DIG 2 ; + CDR ; + DIG 2 ; + DIG 5 ; + SWAP ; + SOME ; + SWAP ; + UPDATE ; + UPDATE 2 } ; + UPDATE 1 ; + UPDATE 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 ; + CAR ; + DUP ; + CAR ; + DUP 3 ; + MEM ; + IF { CDR ; + DUP 2 ; + GET ; + IF_NONE { NONE (pair (pair string string) address string nat bool) } { SOME } } + { DROP ; NONE (pair (pair string string) address string nat bool) } ; + IF_NONE { PUSH nat 117 ; FAILWITH } {} ; + DUP 3 ; + DUP 4 ; + CDR ; + DIG 4 ; + CDR ; + CAR ; + DIG 3 ; + PUSH bool False ; + UPDATE 8 ; + DUP 2 ; + CAR ; + DUP 6 ; + MEM ; + IF { DUP 2 ; DIG 2 ; CDR ; DIG 2 ; SOME ; DIG 5 ; UPDATE ; UPDATE 2 } + { DUP 2 ; + DUP 3 ; + CAR ; + DUP 7 ; + PUSH bool True ; + SWAP ; + UPDATE ; + UPDATE 1 ; + DIG 2 ; + CDR ; + DIG 2 ; + DIG 5 ; + SWAP ; + SOME ; + SWAP ; + UPDATE ; + UPDATE 2 } ; + UPDATE 1 ; + UPDATE 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 ; + GET 8 ; + IF {} { PUSH nat 137 ; FAILWITH } ; + DUP 2 ; + CDR ; + CAR ; + DUP 2 ; + CAR ; + DUP ; + CDR ; + GET 3 ; + SWAP ; + CAR ; + CAR ; + GET 3 ; + SWAP ; + DUP 2 ; + DUP 2 ; + COMPARE ; + GT ; + IF { SWAP ; PUSH string "/" ; CONCAT ; SWAP ; CONCAT } + { PUSH string "/" ; CONCAT ; SWAP ; CONCAT } ; + DUP 2 ; + CAR ; + DUP 2 ; + MEM ; + IF { DUP 2 ; + CDR ; + SWAP ; + GET ; + IF_NONE { NONE (pair (pair string string) address string nat bool) } { SOME } } + { DROP ; NONE (pair (pair string string) address string nat bool) } ; + IF_NONE + { DROP 2 ; PUSH nat 117 ; FAILWITH } + { DROP ; + DUP 3 ; + CDR ; + CDR ; + DIG 2 ; + CAR ; + DUP ; + CDR ; + GET 3 ; + SWAP ; + CAR ; + CAR ; + GET 3 ; + PAIR ; + DUP ; + CAR ; + DUP 2 ; + CDR ; + DUP 2 ; + DUP 2 ; + COMPARE ; + GT ; + IF { SWAP ; PUSH string "/" ; CONCAT ; SWAP ; CONCAT } + { PUSH string "/" ; CONCAT ; SWAP ; CONCAT } ; + DUP 4 ; + CAR ; + DUP 2 ; + MEM ; + IF { DUP 4 ; + DIG 4 ; + CDR ; + DIG 2 ; + NONE (pair (pair string string) address string nat bool) ; + SWAP ; + UPDATE ; + UPDATE 2 } + { DROP ; DIG 2 } ; + DUP 2 ; + CAR ; + DUP 4 ; + CAR ; + DUP 2 ; + MEM ; + IF { DUP 4 ; + CDR ; + SWAP ; + GET ; + IF_NONE + { NONE (pair nat string (option address) nat (option string)) } + { SOME } } + { DROP ; NONE (pair nat string (option address) nat (option string)) } ; + IF_NONE { PUSH nat 111 ; FAILWITH } {} ; + DIG 2 ; + CDR ; + DUP 4 ; + CAR ; + DUP 2 ; + MEM ; + IF { DUP 4 ; + CDR ; + SWAP ; + GET ; + IF_NONE + { NONE (pair nat string (option address) nat (option string)) } + { SOME } } + { DROP ; NONE (pair nat string (option address) nat (option string)) } ; + IF_NONE { PUSH nat 111 ; FAILWITH } {} ; + EMPTY_MAP string (pair (pair string string) address string nat bool) ; + DUP 4 ; + CAR ; + ITER { SWAP ; + DUP 5 ; + CDR ; + DUP 3 ; + GET ; + IF_NONE { SWAP ; DROP } { DIG 2 ; SWAP ; SOME ; SWAP ; UPDATE } } ; + PUSH bool False ; + SWAP ; + ITER { CDR ; + CAR ; + DUP ; + CDR ; + DUP 7 ; + CAR ; + DUP 2 ; + MEM ; + IF { DUP 7 ; + CDR ; + SWAP ; + GET ; + IF_NONE + { NONE (pair nat string (option address) nat (option string)) } + { SOME } } + { DROP ; NONE (pair nat string (option address) nat (option string)) } ; + IF_NONE { PUSH nat 111 ; FAILWITH } {} ; + SWAP ; + CAR ; + DUP 7 ; + CAR ; + DUP 2 ; + MEM ; + IF { DUP 7 ; + CDR ; + SWAP ; + GET ; + IF_NONE + { NONE (pair nat string (option address) nat (option string)) } + { SOME } } + { DROP ; NONE (pair nat string (option address) nat (option string)) } ; + IF_NONE { PUSH nat 111 ; FAILWITH } {} ; + DIG 2 ; + DUP 2 ; + GET 8 ; + DUP 6 ; + GET 8 ; + COMPARE ; + EQ ; + DUP 3 ; + GET 7 ; + DUP 7 ; + GET 7 ; + COMPARE ; + EQ ; + DUP 4 ; + GET 5 ; + DUP 8 ; + GET 5 ; + COMPARE ; + EQ ; + DUP 5 ; + GET 3 ; + DUP 9 ; + GET 3 ; + COMPARE ; + EQ ; + DIG 5 ; + CAR ; + DUP 9 ; + CAR ; + COMPARE ; + EQ ; + AND ; + AND ; + AND ; + AND ; + DUP 3 ; + GET 8 ; + DUP 6 ; + GET 8 ; + COMPARE ; + EQ ; + DUP 4 ; + GET 7 ; + DUP 7 ; + GET 7 ; + COMPARE ; + EQ ; + DUP 5 ; + GET 5 ; + DUP 8 ; + GET 5 ; + COMPARE ; + EQ ; + DUP 6 ; + GET 3 ; + DUP 9 ; + GET 3 ; + COMPARE ; + EQ ; + DIG 6 ; + CAR ; + DUP 9 ; + CAR ; + COMPARE ; + EQ ; + AND ; + AND ; + AND ; + AND ; + OR ; + OR } ; + IF { SWAP ; DROP ; DIG 2 } + { DUP 2 ; + GET 3 ; + DUP 5 ; + CAR ; + DUP 2 ; + MEM ; + IF { DUP 5 ; + CDR ; + SWAP ; + GET ; + IF_NONE + { NONE (pair nat string (option address) nat (option string)) } + { SOME } } + { DROP ; NONE (pair nat string (option address) nat (option string)) } ; + IF_NONE + { SWAP ; DROP ; DIG 2 } + { DUP 3 ; + GET 8 ; + DUP 2 ; + GET 8 ; + COMPARE ; + EQ ; + DUP 4 ; + GET 7 ; + DUP 3 ; + GET 7 ; + COMPARE ; + EQ ; + DUP 5 ; + GET 5 ; + DUP 4 ; + GET 5 ; + COMPARE ; + EQ ; + DUP 6 ; + GET 3 ; + DUP 5 ; + GET 3 ; + COMPARE ; + EQ ; + DUP 7 ; + CAR ; + DIG 5 ; + CAR ; + COMPARE ; + EQ ; + AND ; + AND ; + AND ; + AND ; + IF { SWAP ; + GET 3 ; + DUP 4 ; + CAR ; + DUP 2 ; + MEM ; + IF { DUP 4 ; + DIG 4 ; + CDR ; + DIG 2 ; + NONE (pair nat string (option address) nat (option string)) ; + SWAP ; + UPDATE ; + UPDATE 2 } + { DROP ; DIG 2 } } + { SWAP ; DIG 3 ; DROP 2 ; PUSH nat 115 ; FAILWITH } } } ; + EMPTY_MAP string (pair (pair string string) address string nat bool) ; + DUP 4 ; + CAR ; + ITER { SWAP ; + DUP 5 ; + CDR ; + DUP 3 ; + GET ; + IF_NONE { SWAP ; DROP } { DIG 2 ; SWAP ; SOME ; SWAP ; UPDATE } } ; + PUSH bool False ; + SWAP ; + ITER { CDR ; + CAR ; + DUP ; + CDR ; + DUP 4 ; + CAR ; + DUP 2 ; + MEM ; + IF { DUP 4 ; + CDR ; + SWAP ; + GET ; + IF_NONE + { NONE (pair nat string (option address) nat (option string)) } + { SOME } } + { DROP ; NONE (pair nat string (option address) nat (option string)) } ; + IF_NONE { PUSH nat 111 ; FAILWITH } {} ; + SWAP ; + CAR ; + DUP 4 ; + CAR ; + DUP 2 ; + MEM ; + IF { DUP 4 ; + CDR ; + SWAP ; + GET ; + IF_NONE + { NONE (pair nat string (option address) nat (option string)) } + { SOME } } + { DROP ; NONE (pair nat string (option address) nat (option string)) } ; + IF_NONE { PUSH nat 111 ; FAILWITH } {} ; + DIG 2 ; + DUP 2 ; + GET 8 ; + DUP 6 ; + GET 8 ; + COMPARE ; + EQ ; + DUP 3 ; + GET 7 ; + DUP 7 ; + GET 7 ; + COMPARE ; + EQ ; + DUP 4 ; + GET 5 ; + DUP 8 ; + GET 5 ; + COMPARE ; + EQ ; + DUP 5 ; + GET 3 ; + DUP 9 ; + GET 3 ; + COMPARE ; + EQ ; + DIG 5 ; + CAR ; + DUP 9 ; + CAR ; + COMPARE ; + EQ ; + AND ; + AND ; + AND ; + AND ; + DUP 3 ; + GET 8 ; + DUP 6 ; + GET 8 ; + COMPARE ; + EQ ; + DUP 4 ; + GET 7 ; + DUP 7 ; + GET 7 ; + COMPARE ; + EQ ; + DUP 5 ; + GET 5 ; + DUP 8 ; + GET 5 ; + COMPARE ; + EQ ; + DUP 6 ; + GET 3 ; + DUP 9 ; + GET 3 ; + COMPARE ; + EQ ; + DIG 6 ; + CAR ; + DUP 9 ; + CAR ; + COMPARE ; + EQ ; + AND ; + AND ; + AND ; + AND ; + OR ; + OR } ; + IF { SWAP ; DROP } + { DUP 2 ; + GET 3 ; + DUP 2 ; + CAR ; + DUP 2 ; + MEM ; + IF { DUP 2 ; + CDR ; + SWAP ; + GET ; + IF_NONE + { NONE (pair nat string (option address) nat (option string)) } + { SOME } } + { DROP ; NONE (pair nat string (option address) nat (option string)) } ; + IF_NONE + { SWAP ; DROP } + { DUP 3 ; + GET 8 ; + DUP 2 ; + GET 8 ; + COMPARE ; + EQ ; + DUP 4 ; + GET 7 ; + DUP 3 ; + GET 7 ; + COMPARE ; + EQ ; + DUP 5 ; + GET 5 ; + DUP 4 ; + GET 5 ; + COMPARE ; + EQ ; + DUP 6 ; + GET 3 ; + DUP 5 ; + GET 3 ; + COMPARE ; + EQ ; + DUP 7 ; + CAR ; + DIG 5 ; + CAR ; + COMPARE ; + EQ ; + AND ; + AND ; + AND ; + AND ; + IF { SWAP ; + GET 3 ; + DUP 2 ; + CAR ; + DUP 2 ; + MEM ; + IF { DUP 2 ; + DIG 2 ; + CDR ; + DIG 2 ; + NONE (pair nat string (option address) nat (option string)) ; + SWAP ; + UPDATE ; + UPDATE 2 } + { DROP } } + { DROP 2 ; PUSH nat 115 ; FAILWITH } } } ; + SWAP ; + PAIR } ; + UNPAIR ; + DUP 3 ; + DIG 3 ; + CDR ; + DIG 2 ; + UPDATE 1 ; + UPDATE 2 ; + DUP ; + CDR ; + DIG 2 ; + UPDATE 2 ; + UPDATE 2 } ; + NIL operation ; + PAIR } } ; + view "get_valid_swaps" + unit + (map string + (pair (pair %swap (string %from) (string %to)) + (address %oracle_address) + (string %oracle_asset_name) + (nat %oracle_precision) + (bool %is_disabled_for_deposits))) + { CDR ; + CDR ; + CAR ; + EMPTY_MAP string (pair (pair string string) address string nat bool) ; + DUP 2 ; + CAR ; + ITER { SWAP ; + DUP 3 ; + CDR ; + DUP 3 ; + GET ; + IF_NONE { SWAP ; DROP } { DIG 2 ; SWAP ; SOME ; SWAP ; UPDATE } } ; + SWAP ; + DROP } ; + view "get_valid_tokens" + unit + (map string + (pair (nat %token_id) + (string %name) + (option %address address) + (nat %decimals) + (option %standard string))) + { CDR ; + CDR ; + CDR ; + EMPTY_MAP string (pair nat string (option address) nat (option string)) ; + DUP 2 ; + CAR ; + ITER { SWAP ; + DUP 3 ; + CDR ; + DUP 3 ; + GET ; + IF_NONE { SWAP ; DROP } { DIG 2 ; SWAP ; SOME ; SWAP ; UPDATE } } ; + SWAP ; + DROP } } + diff --git a/batcher/batcher-storage-ghostnet.tz b/batcher/michelson/tokenmanager-storage-ghostnet.tz similarity index 83% rename from batcher/batcher-storage-ghostnet.tz rename to batcher/michelson/tokenmanager-storage-ghostnet.tz index 1f588915..785317ed 100644 --- a/batcher/batcher-storage-ghostnet.tz +++ b/batcher/michelson/tokenmanager-storage-ghostnet.tz @@ -1,9 +1,5 @@ -(Pair (Pair (Pair (Pair "tz1ca4batAsNxMYab3mUK5H4QRjY8drV4ViL" {} {}) 600 10000) - (Pair "tz1burnburnburnburnburnburnburjAYjjX" 0) - 10 - "KT1XKvKiTTj8N6WKv3MhnZhFjZopFGQGBTdT") - (Pair (Pair {} {}) - {} +(Pair (Pair "tz1ca4batAsNxMYab3mUK5H4QRjY8drV4ViL" 10) + (Pair { "BTCtz/USDT" ; "BTCtz/USDtz" ; "tzBTC/EURL" ; "tzBTC/USDT" ; "tzBTC/USDtz" } { Elt "BTCtz/USDT" (Pair (Pair "BTCtz" "USDT") "KT1DG2g5DPYWqyHKGpRL579YkYZwJxibwaAZ" "BTC-USDT" 6 False) ; Elt "BTCtz/USDtz" @@ -14,6 +10,7 @@ (Pair (Pair "tzBTC" "USDT") "KT1DG2g5DPYWqyHKGpRL579YkYZwJxibwaAZ" "BTC-USDT" 6 False) ; Elt "tzBTC/USDtz" (Pair (Pair "tzBTC" "USDtz") "KT1DG2g5DPYWqyHKGpRL579YkYZwJxibwaAZ" "BTC-USDT" 6 False) }) + { "BTCtz" ; "EURL" ; "USDT" ; "USDtz" ; "tzBTC" } { Elt "BTCtz" (Pair 0 "BTCtz" (Some "KT1ErLEYVsxqHxLgLucXViq5DYrtSyDuSFTe") 8 (Some "FA2 token")) ; Elt "EURL" (Pair 0 "EURL" (Some "KT1RcHjqDWWycYQGrz4KBYoGZSMmMuVpkmuS") 6 (Some "FA2 token")) ; diff --git a/batcher/michelson/tzbtc-vault-ghostnet.tz b/batcher/michelson/tzbtc-vault-ghostnet.tz new file mode 100644 index 00000000..7713bed1 --- /dev/null +++ b/batcher/michelson/tzbtc-vault-ghostnet.tz @@ -0,0 +1,1650 @@ +{ parameter + (or (or (or (or (nat %addLiquidity) (mutez %addReward)) + (or (unit %assertBalances) (nat %balance_response_fa12))) + (or (or (list %balance_response_fa2 + (pair (pair %request (address %owner) (nat %token_id)) (nat %balance))) + (address %change_admin_address)) + (or (address %change_batcher_address) (address %change_marketmaker_address)))) + (or (or (address %change_tokenmanager_address) (unit %claim)) + (or (pair %injectLiquidity + (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))) + (unit %removeLiquidity)))) ; + storage + (pair (pair (pair (address %administrator) (address %batcher)) + (map %foreign_tokens + string + (pair (pair %token + (nat %token_id) + (string %name) + (option %address address) + (nat %decimals) + (option %standard string)) + (nat %amount))) + (address %marketmaker)) + (pair (pair %native_token + (pair %token + (nat %token_id) + (string %name) + (option %address address) + (nat %decimals) + (option %standard string)) + (nat %amount)) + (address %tokenmanager)) + (nat %total_shares) + (pair %vault_holdings + (set %keys address) + (big_map %values + address + (pair (pair (address %holder) (nat %shares)) (mutez %unclaimed))))) ; + code { LAMBDA + (pair (option address) nat) + address + { UNPAIR ; IF_NONE { FAILWITH } { SWAP ; DROP } } ; + EMPTY_MAP string (pair (pair nat string (option address) nat (option string)) nat) ; + LAMBDA + (pair (pair (pair nat string (option address) nat (option string)) nat) + (map string (pair (pair nat string (option address) nat (option string)) nat))) + (map string (pair (pair nat string (option address) nat (option string)) nat)) + { UNPAIR ; + SWAP ; + UNIT ; + RIGHT unit ; + DIG 2 ; + DUP ; + CAR ; + GET 3 ; + DUP 4 ; + DUP 2 ; + GET ; + IF_NONE + { DIG 2 ; DROP ; SWAP ; SOME ; SWAP ; UPDATE } + { DIG 3 ; + IF_LEFT + { DROP ; + DUP ; + CDR ; + DUP 4 ; + CDR ; + COMPARE ; + GT ; + IF { DROP ; PUSH nat 111 ; FAILWITH } + { DUP 3 ; CDR ; SWAP ; CDR ; SUB ; ABS } } + { DROP ; CDR ; DUP 3 ; CDR ; ADD } ; + DIG 3 ; + DIG 3 ; + DIG 2 ; + UPDATE 2 ; + SOME ; + DIG 2 ; + UPDATE } } ; + DIG 3 ; + UNPAIR ; + IF_LEFT + { DIG 2 ; + DIG 3 ; + DROP 2 ; + IF_LEFT + { IF_LEFT + { DIG 2 ; + DROP ; + IF_LEFT + { PUSH mutez 1 ; + AMOUNT ; + COMPARE ; + LT ; + IF {} { PUSH nat 118 ; FAILWITH } ; + SENDER ; + DUP 3 ; + CDR ; + CAR ; + CAR ; + DIG 2 ; + UPDATE 2 ; + SELF_ADDRESS ; + DUP 2 ; + CAR ; + GET 5 ; + IF_NONE + { DROP ; PUSH nat 109 ; FAILWITH } + { DUP 3 ; + CAR ; + GET 8 ; + IF_NONE + { DROP 2 ; PUSH nat 108 ; FAILWITH } + { PUSH string "FA1.2 token" ; + DUP 2 ; + COMPARE ; + EQ ; + IF { DROP ; + CONTRACT %transfer (pair (address %from) (address %to) (nat %value)) ; + IF_NONE { PUSH nat 101 ; FAILWITH } {} ; + PUSH mutez 0 ; + DUP 4 ; + CDR ; + DIG 3 ; + DUP 6 ; + PAIR 3 ; + TRANSFER_TOKENS } + { PUSH string "FA2 token" ; + SWAP ; + COMPARE ; + EQ ; + IF { CONTRACT %transfer + (list (pair (address %from_) (list %tx (pair (address %to_) (nat %token_id) (nat %amount))))) ; + IF_NONE { PUSH nat 101 ; FAILWITH } {} ; + PUSH mutez 0 ; + NIL (pair address (list (pair address nat nat))) ; + NIL (pair address nat nat) ; + DUP 6 ; + CDR ; + DUP 7 ; + CAR ; + CAR ; + DIG 6 ; + PAIR 3 ; + CONS ; + DUP 6 ; + PAIR ; + CONS ; + TRANSFER_TOKENS } + { DROP 2 ; PUSH nat 108 ; FAILWITH } } } } ; + DUP 4 ; + CDR ; + CAR ; + CAR ; + DUP ; + CAR ; + DUP 4 ; + CAR ; + DUP 2 ; + GET 8 ; + DUP 2 ; + GET 8 ; + COMPARE ; + EQ ; + DUP 3 ; + GET 7 ; + DUP 3 ; + GET 7 ; + COMPARE ; + EQ ; + DUP 4 ; + GET 5 ; + DUP 4 ; + GET 5 ; + COMPARE ; + EQ ; + DUP 5 ; + GET 3 ; + DUP 5 ; + GET 3 ; + COMPARE ; + EQ ; + DIG 5 ; + CAR ; + DIG 5 ; + CAR ; + COMPARE ; + EQ ; + AND ; + AND ; + AND ; + AND ; + NOT ; + IF { DIG 2 ; DIG 3 ; DIG 4 ; DROP 4 ; PUSH nat 115 ; FAILWITH } + { DUP 3 ; + CDR ; + DUP 6 ; + CDR ; + CDR ; + CAR ; + ADD ; + DUP 2 ; + DUP 5 ; + CDR ; + DIG 3 ; + CDR ; + ADD ; + UPDATE 2 ; + DUP 6 ; + CDR ; + CDR ; + CDR ; + DUP ; + CAR ; + DUP 7 ; + MEM ; + IF { CDR ; + DUP 6 ; + GET ; + IF_NONE { NONE (pair (pair address nat) mutez) } { SOME } } + { DROP ; NONE (pair (pair address nat) mutez) } ; + IF_NONE + { PUSH mutez 0 ; DIG 4 ; CDR ; DUP 6 ; PAIR ; PAIR } + { DIG 4 ; + CDR ; + DUP 2 ; + CAR ; + CDR ; + ADD ; + DUP 2 ; + DIG 2 ; + CAR ; + DIG 2 ; + UPDATE 2 ; + UPDATE 1 } ; + DUP 6 ; + DUP 7 ; + CDR ; + DUP ; + CDR ; + DIG 5 ; + UPDATE 1 ; + UPDATE 2 ; + UPDATE 2 ; + DUP ; + CDR ; + DUP ; + CDR ; + DIG 7 ; + CDR ; + CDR ; + CDR ; + DUP ; + CAR ; + DUP 9 ; + MEM ; + IF { DUP ; CDR ; DIG 5 ; SOME ; DIG 8 ; UPDATE ; UPDATE 2 } + { DUP ; + DUP 2 ; + CAR ; + DUP 10 ; + PUSH bool True ; + SWAP ; + UPDATE ; + UPDATE 1 ; + SWAP ; + CDR ; + DIG 5 ; + DIG 8 ; + SWAP ; + SOME ; + SWAP ; + UPDATE ; + UPDATE 2 } ; + UPDATE 2 ; + UPDATE 2 ; + UPDATE 2 ; + DUP ; + CDR ; + DUP ; + CAR ; + DIG 3 ; + UPDATE 1 ; + UPDATE 1 ; + UPDATE 2 } ; + NIL operation ; + DIG 2 ; + CONS } + { DUP 2 ; + CDR ; + CDR ; + CAR ; + INT ; + PUSH mutez 1 ; + DIG 2 ; + EDIV ; + IF_NONE { PUSH string "DIV by 0" ; FAILWITH } {} ; + CAR ; + INT ; + DUP 3 ; + CDR ; + CDR ; + CDR ; + EMPTY_MAP address (pair (pair address nat) mutez) ; + DUP 2 ; + CAR ; + ITER { SWAP ; + DUP 3 ; + CDR ; + DUP 3 ; + GET ; + IF_NONE { SWAP ; DROP } { DIG 2 ; SWAP ; SOME ; SWAP ; UPDATE } } ; + SWAP ; + DROP ; + EMPTY_BIG_MAP address (pair (pair address nat) mutez) ; + EMPTY_SET address ; + PAIR ; + SWAP ; + ITER { UNPAIR ; + DUP 2 ; + CAR ; + CDR ; + INT ; + PUSH int 1 ; + DUP 7 ; + PAIR ; + PUSH int 1 ; + DIG 2 ; + PAIR ; + DUP 2 ; + CAR ; + DUP 2 ; + CDR ; + MUL ; + DIG 2 ; + CDR ; + DIG 2 ; + CAR ; + MUL ; + PAIR ; + PUSH int 1 ; + DUP 6 ; + PAIR ; + 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 ; + 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 } } ; + DIG 2 ; + CAR ; + MUL ; + EDIV ; + IF_NONE { PUSH string "DIV by 0" ; FAILWITH } {} ; + CAR ; + ISNAT ; + IF_NONE { PUSH nat 119 ; FAILWITH } {} ; + PUSH mutez 1 ; + MUL ; + PUSH mutez 0 ; + DUP 2 ; + COMPARE ; + GT ; + IF { DUP 3 ; CDR ; ADD } { DROP ; DUP 2 ; CDR } ; + DIG 2 ; + SWAP ; + UPDATE 2 ; + DUP 3 ; + CAR ; + DUP 3 ; + MEM ; + IF { DUP 3 ; DIG 3 ; CDR ; DIG 2 ; SOME ; DIG 3 ; UPDATE ; UPDATE 2 } + { DUP 3 ; + DUP 4 ; + CAR ; + DUP 4 ; + PUSH bool True ; + SWAP ; + UPDATE ; + UPDATE 1 ; + DIG 3 ; + CDR ; + DIG 2 ; + DIG 3 ; + SWAP ; + SOME ; + SWAP ; + UPDATE ; + UPDATE 2 } } ; + SWAP ; + DIG 2 ; + DROP 2 ; + DUP 2 ; + DIG 2 ; + CDR ; + DUP ; + CDR ; + DIG 3 ; + UPDATE 2 ; + UPDATE 2 ; + UPDATE 2 ; + NIL operation } } + { IF_LEFT + { DIG 2 ; + DROP 2 ; + DUP ; + SELF_ADDRESS ; + DUP 3 ; + CDR ; + CAR ; + CAR ; + CAR ; + DUP ; + GET 5 ; + IF_NONE { PUSH nat 101 ; FAILWITH } {} ; + DUP 2 ; + GET 8 ; + IF_NONE { PUSH nat 108 ; FAILWITH } {} ; + PUSH string "FA1.2 token" ; + DUP 2 ; + COMPARE ; + EQ ; + IF { DIG 2 ; + DROP 2 ; + DUP 2 ; + CONTRACT %balance_response_fa12 nat ; + SWAP ; + CONTRACT %getBalance (pair address (contract nat)) ; + SWAP ; + IF_NONE + { DROP ; PUSH nat 172 ; FAILWITH } + { SWAP ; + IF_NONE + { DROP ; PUSH nat 173 ; FAILWITH } + { PUSH mutez 0 ; DIG 2 ; DUP 4 ; PAIR ; TRANSFER_TOKENS } } } + { PUSH string "FA2 token" ; + SWAP ; + COMPARE ; + EQ ; + IF { CONTRACT %balance_of + (pair (list %requests (pair (address %owner) (nat %token_id))) + (contract %callback + (list (pair (pair %request (address %owner) (nat %token_id)) (nat %balance))))) ; + DUP 3 ; + CONTRACT %balance_response_fa2 + (list (pair (pair %request (address %owner) (nat %token_id)) (nat %balance))) ; + IF_NONE + { DROP 2 ; PUSH nat 170 ; FAILWITH } + { SWAP ; + IF_NONE + { DROP 2 ; PUSH nat 171 ; FAILWITH } + { PUSH mutez 0 ; + DIG 2 ; + NIL (pair address nat) ; + DIG 4 ; + CAR ; + DUP 6 ; + PAIR ; + CONS ; + PAIR ; + TRANSFER_TOKENS } } } + { DROP 2 ; PUSH nat 108 ; FAILWITH } } ; + NIL operation ; + SWAP ; + CONS ; + DIG 3 ; + CAR ; + CDR ; + CAR ; + ITER { CDR ; + SWAP ; + DUP 2 ; + CAR ; + GET 5 ; + IF_NONE { PUSH nat 101 ; FAILWITH } {} ; + DUP 3 ; + CAR ; + GET 8 ; + IF_NONE { PUSH nat 108 ; FAILWITH } {} ; + PUSH string "FA1.2 token" ; + DUP 2 ; + COMPARE ; + EQ ; + IF { DIG 3 ; + DROP 2 ; + DUP 3 ; + CONTRACT %balance_response_fa12 nat ; + SWAP ; + CONTRACT %getBalance (pair address (contract nat)) ; + SWAP ; + IF_NONE + { DROP ; PUSH nat 172 ; FAILWITH } + { SWAP ; + IF_NONE + { DROP ; PUSH nat 173 ; FAILWITH } + { PUSH mutez 0 ; DIG 2 ; DUP 5 ; PAIR ; TRANSFER_TOKENS } } } + { PUSH string "FA2 token" ; + SWAP ; + COMPARE ; + EQ ; + IF { CONTRACT %balance_of + (pair (list %requests (pair (address %owner) (nat %token_id))) + (contract %callback + (list (pair (pair %request (address %owner) (nat %token_id)) (nat %balance))))) ; + DUP 4 ; + CONTRACT %balance_response_fa2 + (list (pair (pair %request (address %owner) (nat %token_id)) (nat %balance))) ; + IF_NONE + { DIG 2 ; DROP 2 ; PUSH nat 170 ; FAILWITH } + { SWAP ; + IF_NONE + { DIG 2 ; DROP 2 ; PUSH nat 171 ; FAILWITH } + { PUSH mutez 0 ; + DIG 2 ; + NIL (pair address nat) ; + DIG 5 ; + CAR ; + CAR ; + DUP 7 ; + PAIR ; + CONS ; + PAIR ; + TRANSFER_TOKENS } } } + { DIG 2 ; DROP 2 ; PUSH nat 108 ; FAILWITH } } ; + CONS } ; + SWAP ; + DROP } + { SENDER ; + PUSH nat 101 ; + DUP 4 ; + CDR ; + CAR ; + CAR ; + CAR ; + GET 5 ; + PAIR ; + DIG 4 ; + SWAP ; + EXEC ; + PUSH nat 0 ; + DUP 5 ; + CDR ; + CAR ; + CAR ; + CAR ; + CAR ; + COMPARE ; + EQ ; + DUP 3 ; + DIG 2 ; + COMPARE ; + EQ ; + AND ; + IF { DUP 3 ; + DUP 4 ; + CDR ; + DUP ; + CAR ; + DIG 5 ; + CDR ; + CAR ; + CAR ; + DUP 6 ; + UPDATE 2 ; + UPDATE 1 ; + UPDATE 1 ; + UPDATE 2 } + { DIG 2 } ; + DUP ; + CAR ; + CDR ; + CAR ; + DUP ; + ITER { CDR ; + DUP ; + CAR ; + GET 5 ; + IF_NONE { PUSH nat 101 ; FAILWITH } {} ; + PUSH nat 0 ; + DUP 3 ; + CAR ; + CAR ; + COMPARE ; + EQ ; + DUP 6 ; + DIG 2 ; + COMPARE ; + EQ ; + AND ; + IF { DUP 5 ; UPDATE 2 ; SWAP ; DUP 2 ; SOME ; DIG 2 ; CAR ; GET 3 ; UPDATE } + { DROP } } ; + DIG 2 ; + DIG 3 ; + DROP 2 ; + DUP 2 ; + DIG 2 ; + CAR ; + DUP ; + CDR ; + DIG 3 ; + UPDATE 1 ; + UPDATE 2 ; + UPDATE 1 ; + NIL operation } } } + { IF_LEFT + { IF_LEFT + { SENDER ; + DUG 2 ; + ITER { SWAP ; + DUP 2 ; + CDR ; + DIG 2 ; + CAR ; + CDR ; + PUSH nat 101 ; + DUP 4 ; + CDR ; + CAR ; + CAR ; + CAR ; + GET 5 ; + PAIR ; + DUP 6 ; + SWAP ; + EXEC ; + DUP 2 ; + DUP 5 ; + CDR ; + CAR ; + CAR ; + CAR ; + CAR ; + COMPARE ; + EQ ; + DUP 6 ; + DIG 2 ; + COMPARE ; + EQ ; + AND ; + IF { DUP 3 ; + DUP 4 ; + CDR ; + DUP ; + CAR ; + DIG 5 ; + CDR ; + CAR ; + CAR ; + DUP 6 ; + UPDATE 2 ; + UPDATE 1 ; + UPDATE 1 ; + UPDATE 2 } + { DIG 2 } ; + DUP ; + CAR ; + CDR ; + CAR ; + DUP ; + ITER { CDR ; + DUP ; + CAR ; + GET 5 ; + IF_NONE { PUSH nat 101 ; FAILWITH } {} ; + DUP 5 ; + DUP 3 ; + CAR ; + CAR ; + COMPARE ; + EQ ; + DUP 8 ; + DIG 2 ; + COMPARE ; + EQ ; + AND ; + IF { DUP 5 ; UPDATE 2 ; SWAP ; DUP 2 ; SOME ; DIG 2 ; CAR ; GET 3 ; UPDATE } + { DROP } } ; + DIG 2 ; + DIG 3 ; + DROP 2 ; + DUP 2 ; + DIG 2 ; + CAR ; + DUP ; + CDR ; + DIG 3 ; + UPDATE 1 ; + UPDATE 2 ; + UPDATE 1 } ; + SWAP ; + DIG 2 ; + DROP 2 } + { DIG 2 ; + DROP ; + DUP 2 ; + CAR ; + 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 ; + DUP ; + CAR ; + DIG 3 ; + UPDATE 1 ; + UPDATE 1 ; + UPDATE 1 } } + { DIG 2 ; + DROP ; + IF_LEFT + { DUP 2 ; + CAR ; + 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 ; + DUP ; + CAR ; + DIG 3 ; + UPDATE 2 ; + UPDATE 1 ; + UPDATE 1 } + { DUP 2 ; + CAR ; + 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 ; + DUP ; + CDR ; + DIG 3 ; + UPDATE 2 ; + UPDATE 2 ; + UPDATE 1 } } ; + NIL operation } ; + PAIR } + { DIG 4 ; + DROP ; + IF_LEFT + { DIG 2 ; + DIG 3 ; + DROP 2 ; + IF_LEFT + { DUP 2 ; + CAR ; + 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 ; + DUP ; + CAR ; + DIG 3 ; + UPDATE 2 ; + UPDATE 1 ; + UPDATE 2 ; + NIL operation ; + PAIR } + { DROP ; + PUSH mutez 1 ; + AMOUNT ; + COMPARE ; + LT ; + IF {} { PUSH nat 118 ; FAILWITH } ; + SENDER ; + DUP 2 ; + CDR ; + CDR ; + CDR ; + DUP ; + CAR ; + DUP 3 ; + MEM ; + IF { CDR ; + SWAP ; + GET ; + IF_NONE { NONE (pair (pair address nat) mutez) } { SOME } } + { DROP 2 ; NONE (pair (pair address nat) mutez) } ; + IF_NONE + { DROP ; PUSH nat 155 ; FAILWITH } + { DUP ; + CDR ; + PUSH mutez 0 ; + DUP 2 ; + COMPARE ; + EQ ; + IF { DROP 3 ; PUSH nat 155 ; FAILWITH } + { SWAP ; + PUSH mutez 0 ; + UPDATE 2 ; + DUP ; + CAR ; + CAR ; + CONTRACT unit ; + IF_NONE + { SWAP ; DROP ; PUSH nat 102 ; FAILWITH } + { DIG 2 ; UNIT ; TRANSFER_TOKENS } ; + DUP 3 ; + DUP 4 ; + CDR ; + DUP ; + CDR ; + DIG 5 ; + CDR ; + CDR ; + CDR ; + DUP 6 ; + CAR ; + CAR ; + DUP 2 ; + CAR ; + DUP 2 ; + MEM ; + IF { DUP 2 ; DIG 2 ; CDR ; DIG 7 ; SOME ; DIG 3 ; UPDATE ; UPDATE 2 } + { DUP 2 ; + DUP 3 ; + CAR ; + DUP 3 ; + PUSH bool True ; + SWAP ; + UPDATE ; + UPDATE 1 ; + DIG 2 ; + CDR ; + DIG 7 ; + DIG 3 ; + SWAP ; + SOME ; + SWAP ; + UPDATE ; + UPDATE 2 } ; + UPDATE 2 ; + UPDATE 2 ; + UPDATE 2 ; + NIL operation ; + DIG 2 ; + CONS ; + PAIR } } } } + { IF_LEFT + { DIG 2 ; + DIG 3 ; + DROP 2 ; + DUP 2 ; + CAR ; + CDR ; + CDR ; + SENDER ; + COMPARE ; + EQ ; + IF {} { PUSH nat 168 ; FAILWITH } ; + PUSH mutez 1 ; + AMOUNT ; + COMPARE ; + LT ; + IF {} { PUSH nat 118 ; FAILWITH } ; + UNIT ; + LEFT unit ; + LEFT unit ; + IF_LEFT + { IF_LEFT { DROP ; PUSH nat 1 } { DROP ; PUSH nat 0 } } + { DROP ; PUSH nat 2 } ; + DUP 2 ; + CDR ; + CAR ; + IF_LEFT { DROP ; PUSH nat 0 } { DROP ; PUSH nat 1 } ; + NOW ; + DUP 4 ; + CDR ; + CDR ; + DUP 5 ; + CAR ; + CAR ; + DIG 5 ; + CAR ; + CDR ; + PAIR ; + PAIR ; + PAIR 4 ; + DUP 2 ; + CAR ; + CAR ; + CDR ; + DUP 2 ; + CAR ; + CAR ; + CAR ; + GET 5 ; + IF_NONE + { DROP 2 ; PUSH nat 109 ; FAILWITH } + { DUP 3 ; + CAR ; + CAR ; + CAR ; + GET 8 ; + IF_NONE + { PUSH bool False } + { PUSH string "FA1.2 token" ; SWAP ; COMPARE ; EQ } ; + IF { DUP ; + CONTRACT %approve (pair (address %spender) (nat %value)) ; + IF_NONE { PUSH nat 157 ; FAILWITH } {} ; + PUSH mutez 0 ; + DUP 5 ; + CAR ; + CAR ; + CDR ; + DUP 5 ; + PAIR ; + TRANSFER_TOKENS } + { DUP 3 ; + CAR ; + CAR ; + CAR ; + GET 8 ; + IF_NONE + { PUSH bool False } + { PUSH string "FA2 token" ; SWAP ; COMPARE ; EQ } ; + IF { SELF_ADDRESS ; + DUP 2 ; + CONTRACT %add_operator + (pair (pair (address %operator) (address %owner)) (nat %token_id)) ; + IF_NONE { PUSH nat 157 ; FAILWITH } {} ; + PUSH mutez 0 ; + DUP 6 ; + CAR ; + CAR ; + CAR ; + CAR ; + DIG 3 ; + DUP 6 ; + PAIR ; + PAIR ; + TRANSFER_TOKENS } + { PUSH nat 108 ; FAILWITH } } ; + DUP 3 ; + CONTRACT %deposit + (pair (pair %swap + (pair %from + (pair %token + (nat %token_id) + (string %name) + (option %address address) + (nat %decimals) + (option %standard string)) + (nat %amount)) + (pair %to + (nat %token_id) + (string %name) + (option %address address) + (nat %decimals) + (option %standard string))) + (timestamp %created_at) + (nat %side) + (nat %tolerance)) ; + IF_NONE { PUSH nat 157 ; FAILWITH } {} ; + PUSH mutez 0 ; + DUP 6 ; + TRANSFER_TOKENS ; + DUP 5 ; + CAR ; + CAR ; + CAR ; + GET 8 ; + IF_NONE + { PUSH bool False } + { PUSH string "FA1.2 token" ; SWAP ; COMPARE ; EQ } ; + IF { DIG 2 ; DIG 3 ; DIG 4 ; DROP 3 ; NONE operation } + { DUP 5 ; + CAR ; + CAR ; + CAR ; + GET 8 ; + IF_NONE + { PUSH bool False } + { PUSH string "FA2 token" ; SWAP ; COMPARE ; EQ } ; + IF { SELF_ADDRESS ; + DIG 3 ; + CONTRACT %remove_operator + (pair (pair (address %operator) (address %owner)) (nat %token_id)) ; + IF_NONE { PUSH nat 157 ; FAILWITH } {} ; + PUSH mutez 0 ; + DIG 6 ; + CAR ; + CAR ; + CAR ; + CAR ; + DIG 3 ; + DIG 6 ; + PAIR ; + PAIR ; + TRANSFER_TOKENS ; + SOME } + { DIG 2 ; DIG 3 ; DIG 4 ; DROP 3 ; PUSH nat 108 ; FAILWITH } } ; + IF_NONE { NIL operation } { NIL operation ; SWAP ; CONS } ; + SWAP ; + CONS ; + SWAP ; + CONS } ; + SELF_ADDRESS ; + DUP 3 ; + CDR ; + CAR ; + CAR ; + CAR ; + DUP ; + GET 5 ; + IF_NONE { PUSH nat 101 ; FAILWITH } {} ; + DUP 2 ; + GET 8 ; + IF_NONE { PUSH nat 108 ; FAILWITH } {} ; + PUSH string "FA1.2 token" ; + DUP 2 ; + COMPARE ; + EQ ; + IF { DIG 2 ; + DROP 2 ; + DUP 2 ; + CONTRACT %balance_response_fa12 nat ; + SWAP ; + CONTRACT %getBalance (pair address (contract nat)) ; + SWAP ; + IF_NONE + { DROP ; PUSH nat 172 ; FAILWITH } + { SWAP ; + IF_NONE + { DROP ; PUSH nat 173 ; FAILWITH } + { PUSH mutez 0 ; DIG 2 ; DUP 4 ; PAIR ; TRANSFER_TOKENS } } } + { PUSH string "FA2 token" ; + SWAP ; + COMPARE ; + EQ ; + IF { CONTRACT %balance_of + (pair (list %requests (pair (address %owner) (nat %token_id))) + (contract %callback + (list (pair (pair %request (address %owner) (nat %token_id)) (nat %balance))))) ; + DUP 3 ; + CONTRACT %balance_response_fa2 + (list (pair (pair %request (address %owner) (nat %token_id)) (nat %balance))) ; + IF_NONE + { DROP 2 ; PUSH nat 170 ; FAILWITH } + { SWAP ; + IF_NONE + { DROP 2 ; PUSH nat 171 ; FAILWITH } + { PUSH mutez 0 ; + DIG 2 ; + NIL (pair address nat) ; + DIG 4 ; + CAR ; + DUP 6 ; + PAIR ; + CONS ; + PAIR ; + TRANSFER_TOKENS } } } + { DROP 2 ; PUSH nat 108 ; FAILWITH } } ; + NIL operation ; + SWAP ; + CONS ; + DUP 4 ; + CAR ; + CDR ; + CAR ; + ITER { CDR ; + SWAP ; + DUP 2 ; + CAR ; + GET 5 ; + IF_NONE { PUSH nat 101 ; FAILWITH } {} ; + DUP 3 ; + CAR ; + GET 8 ; + IF_NONE { PUSH nat 108 ; FAILWITH } {} ; + PUSH string "FA1.2 token" ; + DUP 2 ; + COMPARE ; + EQ ; + IF { DIG 3 ; + DROP 2 ; + DUP 3 ; + CONTRACT %balance_response_fa12 nat ; + SWAP ; + CONTRACT %getBalance (pair address (contract nat)) ; + SWAP ; + IF_NONE + { DROP ; PUSH nat 172 ; FAILWITH } + { SWAP ; + IF_NONE + { DROP ; PUSH nat 173 ; FAILWITH } + { PUSH mutez 0 ; DIG 2 ; DUP 5 ; PAIR ; TRANSFER_TOKENS } } } + { PUSH string "FA2 token" ; + SWAP ; + COMPARE ; + EQ ; + IF { CONTRACT %balance_of + (pair (list %requests (pair (address %owner) (nat %token_id))) + (contract %callback + (list (pair (pair %request (address %owner) (nat %token_id)) (nat %balance))))) ; + DUP 4 ; + CONTRACT %balance_response_fa2 + (list (pair (pair %request (address %owner) (nat %token_id)) (nat %balance))) ; + IF_NONE + { DIG 2 ; DROP 2 ; PUSH nat 170 ; FAILWITH } + { SWAP ; + IF_NONE + { DIG 2 ; DROP 2 ; PUSH nat 171 ; FAILWITH } + { PUSH mutez 0 ; + DIG 2 ; + NIL (pair address nat) ; + DIG 5 ; + CAR ; + CAR ; + DUP 7 ; + PAIR ; + CONS ; + PAIR ; + TRANSFER_TOKENS } } } + { DIG 2 ; DROP 2 ; PUSH nat 108 ; FAILWITH } } ; + CONS } ; + SWAP ; + DROP ; + NIL operation ; + SWAP ; + ITER { CONS } ; + SWAP ; + NIL operation ; + SWAP ; + ITER { CONS } ; + ITER { CONS } ; + NIL operation ; + SWAP ; + ITER { CONS } ; + PAIR } + { DROP ; + PUSH mutez 1 ; + AMOUNT ; + COMPARE ; + LT ; + IF {} { PUSH nat 118 ; FAILWITH } ; + SENDER ; + DUP 2 ; + CDR ; + CDR ; + CDR ; + DUP ; + CAR ; + DUP 3 ; + MEM ; + IF { CDR ; + DUP 2 ; + GET ; + IF_NONE { NONE (pair (pair address nat) mutez) } { SOME } } + { DROP ; NONE (pair (pair address nat) mutez) } ; + IF_NONE + { DROP 4 ; PUSH nat 151 ; FAILWITH } + { UNPAIR ; + CDR ; + DUP 4 ; + CDR ; + CDR ; + CAR ; + INT ; + PUSH int 1 ; + SWAP ; + PAIR ; + DUP 2 ; + INT ; + PUSH int 1 ; + SWAP ; + PAIR ; + DUP 2 ; + CAR ; + DUP 2 ; + CDR ; + MUL ; + DIG 2 ; + CDR ; + DIG 2 ; + CAR ; + MUL ; + PAIR ; + DUP 5 ; + CDR ; + CAR ; + CAR ; + DUP ; + CDR ; + INT ; + PUSH int 1 ; + SWAP ; + PAIR ; + DUP ; + CDR ; + DUP 4 ; + CDR ; + MUL ; + SWAP ; + CAR ; + DUP 4 ; + 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 ; + 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 } } ; + DIG 2 ; + CAR ; + MUL ; + EDIV ; + IF_NONE { PUSH string "DIV by 0" ; FAILWITH } {} ; + CAR ; + ISNAT ; + IF_NONE { PUSH nat 119 ; FAILWITH } {} ; + DUP 2 ; + CDR ; + DUP 2 ; + COMPARE ; + GT ; + IF { DROP 2 ; PUSH nat 153 ; FAILWITH } + { DUP ; + DUP 3 ; + CDR ; + INT ; + SUB ; + ABS ; + DUP 3 ; + DIG 2 ; + UPDATE 2 ; + PUSH nat 0 ; + DUP 2 ; + CDR ; + COMPARE ; + EQ ; + IF { DROP ; DUP 9 } { DUP 10 ; SWAP ; PAIR ; DUP 9 ; SWAP ; EXEC } ; + DUG 2 ; + UPDATE 2 ; + PAIR } ; + UNPAIR ; + SWAP ; + DIG 8 ; + DIG 3 ; + PAIR ; + PAIR ; + DUP 6 ; + CAR ; + CDR ; + CAR ; + ITER { CDR ; + SWAP ; + UNPAIR ; + UNPAIR ; + DUP 4 ; + CDR ; + INT ; + PUSH int 1 ; + SWAP ; + PAIR ; + DUP ; + CDR ; + DUP 3 ; + CDR ; + MUL ; + SWAP ; + CAR ; + DUP 3 ; + 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 ; + 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 } } ; + DIG 2 ; + CAR ; + MUL ; + EDIV ; + IF_NONE { PUSH string "DIV by 0" ; FAILWITH } {} ; + CAR ; + ISNAT ; + IF_NONE { PUSH nat 119 ; FAILWITH } {} ; + DUP 5 ; + CDR ; + DUP 2 ; + COMPARE ; + GT ; + IF { DIG 3 ; DIG 4 ; DROP 3 ; PUSH nat 153 ; FAILWITH } + { DUP ; + DUP 6 ; + CDR ; + INT ; + SUB ; + ABS ; + DUP 6 ; + DIG 2 ; + UPDATE 2 ; + PUSH nat 0 ; + DUP 2 ; + CDR ; + COMPARE ; + EQ ; + IF { DROP ; DIG 3 } { DIG 4 ; SWAP ; PAIR ; DUP 11 ; SWAP ; EXEC } ; + DIG 4 ; + DIG 2 ; + UPDATE 2 ; + PAIR } ; + UNPAIR ; + DIG 3 ; + SWAP ; + PAIR ; + DUP 9 ; + SWAP ; + EXEC ; + DIG 2 ; + PAIR ; + PAIR } ; + DIG 6 ; + DROP ; + UNPAIR ; + CDR ; + DUP 7 ; + CDR ; + CDR ; + CAR ; + DUP 5 ; + COMPARE ; + GT ; + IF { SWAP ; DIG 2 ; DIG 3 ; DIG 6 ; DROP 5 ; PUSH nat 154 ; FAILWITH } + { DIG 3 ; + DUP 7 ; + CDR ; + CDR ; + CAR ; + SUB ; + ABS ; + DIG 2 ; + DUP 7 ; + DIG 7 ; + CDR ; + DUP ; + CAR ; + DIG 6 ; + UPDATE 1 ; + UPDATE 1 ; + UPDATE 2 ; + DUP ; + CAR ; + DUP ; + CDR ; + DIG 5 ; + UPDATE 1 ; + UPDATE 2 ; + UPDATE 1 ; + DUP ; + CDR ; + DUP ; + CDR ; + DIG 4 ; + UPDATE 1 ; + UPDATE 2 ; + UPDATE 2 ; + PAIR } ; + UNPAIR ; + DUP 4 ; + CONTRACT unit ; + IF_NONE { PUSH nat 102 ; FAILWITH } { DUP 4 ; UNIT ; TRANSFER_TOKENS } ; + SELF_ADDRESS ; + NIL operation ; + DIG 4 ; + ITER { CDR ; + DUP ; + CAR ; + GET 5 ; + IF_NONE + { DROP ; PUSH nat 109 ; FAILWITH } + { DUP 2 ; + CAR ; + GET 8 ; + IF_NONE + { DROP 2 ; PUSH nat 108 ; FAILWITH } + { PUSH string "FA1.2 token" ; + DUP 2 ; + COMPARE ; + EQ ; + IF { DROP ; + CONTRACT %transfer (pair (address %from) (address %to) (nat %value)) ; + IF_NONE { PUSH nat 101 ; FAILWITH } {} ; + PUSH mutez 0 ; + DIG 2 ; + CDR ; + DUP 9 ; + DUP 6 ; + PAIR 3 ; + TRANSFER_TOKENS } + { PUSH string "FA2 token" ; + SWAP ; + COMPARE ; + EQ ; + IF { CONTRACT %transfer + (list (pair (address %from_) (list %tx (pair (address %to_) (nat %token_id) (nat %amount))))) ; + IF_NONE { PUSH nat 101 ; FAILWITH } {} ; + PUSH mutez 0 ; + NIL (pair address (list (pair address nat nat))) ; + NIL (pair address nat nat) ; + DUP 5 ; + CDR ; + DIG 5 ; + CAR ; + CAR ; + DUP 12 ; + PAIR 3 ; + CONS ; + DUP 6 ; + PAIR ; + CONS ; + TRANSFER_TOKENS } + { DROP 2 ; PUSH nat 108 ; FAILWITH } } } } ; + CONS } ; + SWAP ; + DROP ; + DUP 3 ; + CDR ; + CDR ; + CDR ; + DUP 4 ; + DIG 4 ; + CDR ; + DUP ; + CDR ; + DUP 4 ; + CAR ; + DUP 9 ; + MEM ; + IF { DUP 4 ; + DIG 4 ; + CDR ; + DIG 8 ; + NONE (pair (pair address nat) mutez) ; + SWAP ; + UPDATE ; + UPDATE 2 } + { DIG 7 ; DROP ; DIG 3 } ; + UPDATE 2 ; + UPDATE 2 ; + UPDATE 2 ; + PUSH mutez 0 ; + DIG 4 ; + COMPARE ; + GT ; + IF { SWAP ; DIG 2 ; CONS } { DIG 2 ; DROP ; SWAP } ; + PAIR } } } } } ; + view "get_native_token_of_vault" + unit + (pair (nat %token_id) + (string %name) + (option %address address) + (nat %decimals) + (option %standard string)) + { CDR ; CDR ; CAR ; CAR ; CAR } ; + view "check_entrypoints" + (pair address address) + (pair (pair bool bool) bool bool) + { CAR ; + UNPAIR ; + SELF_ADDRESS ; + SWAP ; + CONTRACT %balance_of + (pair (list %requests (pair (address %owner) (nat %token_id))) + (contract %callback + (list (pair (pair %request (address %owner) (nat %token_id)) (nat %balance))))) ; + DUP 2 ; + CONTRACT %balance_response_fa2 + (list (pair (pair %request (address %owner) (nat %token_id)) (nat %balance))) ; + DIG 3 ; + CONTRACT %getBalance (pair address (contract nat)) ; + DIG 3 ; + CONTRACT %balance_response_fa12 nat ; + IF_NONE { PUSH bool False } { DROP ; PUSH bool True } ; + SWAP ; + IF_NONE { PUSH bool False } { DROP ; PUSH bool True } ; + PAIR ; + SWAP ; + IF_NONE { PUSH bool False } { DROP ; PUSH bool True } ; + DIG 2 ; + IF_NONE { PUSH bool False } { DROP ; PUSH bool True } ; + PAIR ; + PAIR } } + diff --git a/batcher/michelson/tzbtc-vault-storage-ghostnet.tz b/batcher/michelson/tzbtc-vault-storage-ghostnet.tz new file mode 100644 index 00000000..0ae4c4da --- /dev/null +++ b/batcher/michelson/tzbtc-vault-storage-ghostnet.tz @@ -0,0 +1,10 @@ +(Pair (Pair (Pair "tz1ca4batAsNxMYab3mUK5H4QRjY8drV4ViL" "tz1ca4batAsNxMYab3mUK5H4QRjY8drV4ViL") + {} + "tz1ca4batAsNxMYab3mUK5H4QRjY8drV4ViL") + (Pair (Pair (Pair 0 "tzBTC" (Some "KT1P8RdJ5MfHMK5phKJ5JsfNfask5v2b2NQS") 8 (Some "FA1.2 token")) + 0) + "KT1SG9z3pU1cNh8dSranm5C5HXWphWi2pLwx") + 0 + {} + {}) + diff --git a/batcher/michelson/usdt-vault-ghostnet.tz b/batcher/michelson/usdt-vault-ghostnet.tz new file mode 100644 index 00000000..7713bed1 --- /dev/null +++ b/batcher/michelson/usdt-vault-ghostnet.tz @@ -0,0 +1,1650 @@ +{ parameter + (or (or (or (or (nat %addLiquidity) (mutez %addReward)) + (or (unit %assertBalances) (nat %balance_response_fa12))) + (or (or (list %balance_response_fa2 + (pair (pair %request (address %owner) (nat %token_id)) (nat %balance))) + (address %change_admin_address)) + (or (address %change_batcher_address) (address %change_marketmaker_address)))) + (or (or (address %change_tokenmanager_address) (unit %claim)) + (or (pair %injectLiquidity + (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))) + (unit %removeLiquidity)))) ; + storage + (pair (pair (pair (address %administrator) (address %batcher)) + (map %foreign_tokens + string + (pair (pair %token + (nat %token_id) + (string %name) + (option %address address) + (nat %decimals) + (option %standard string)) + (nat %amount))) + (address %marketmaker)) + (pair (pair %native_token + (pair %token + (nat %token_id) + (string %name) + (option %address address) + (nat %decimals) + (option %standard string)) + (nat %amount)) + (address %tokenmanager)) + (nat %total_shares) + (pair %vault_holdings + (set %keys address) + (big_map %values + address + (pair (pair (address %holder) (nat %shares)) (mutez %unclaimed))))) ; + code { LAMBDA + (pair (option address) nat) + address + { UNPAIR ; IF_NONE { FAILWITH } { SWAP ; DROP } } ; + EMPTY_MAP string (pair (pair nat string (option address) nat (option string)) nat) ; + LAMBDA + (pair (pair (pair nat string (option address) nat (option string)) nat) + (map string (pair (pair nat string (option address) nat (option string)) nat))) + (map string (pair (pair nat string (option address) nat (option string)) nat)) + { UNPAIR ; + SWAP ; + UNIT ; + RIGHT unit ; + DIG 2 ; + DUP ; + CAR ; + GET 3 ; + DUP 4 ; + DUP 2 ; + GET ; + IF_NONE + { DIG 2 ; DROP ; SWAP ; SOME ; SWAP ; UPDATE } + { DIG 3 ; + IF_LEFT + { DROP ; + DUP ; + CDR ; + DUP 4 ; + CDR ; + COMPARE ; + GT ; + IF { DROP ; PUSH nat 111 ; FAILWITH } + { DUP 3 ; CDR ; SWAP ; CDR ; SUB ; ABS } } + { DROP ; CDR ; DUP 3 ; CDR ; ADD } ; + DIG 3 ; + DIG 3 ; + DIG 2 ; + UPDATE 2 ; + SOME ; + DIG 2 ; + UPDATE } } ; + DIG 3 ; + UNPAIR ; + IF_LEFT + { DIG 2 ; + DIG 3 ; + DROP 2 ; + IF_LEFT + { IF_LEFT + { DIG 2 ; + DROP ; + IF_LEFT + { PUSH mutez 1 ; + AMOUNT ; + COMPARE ; + LT ; + IF {} { PUSH nat 118 ; FAILWITH } ; + SENDER ; + DUP 3 ; + CDR ; + CAR ; + CAR ; + DIG 2 ; + UPDATE 2 ; + SELF_ADDRESS ; + DUP 2 ; + CAR ; + GET 5 ; + IF_NONE + { DROP ; PUSH nat 109 ; FAILWITH } + { DUP 3 ; + CAR ; + GET 8 ; + IF_NONE + { DROP 2 ; PUSH nat 108 ; FAILWITH } + { PUSH string "FA1.2 token" ; + DUP 2 ; + COMPARE ; + EQ ; + IF { DROP ; + CONTRACT %transfer (pair (address %from) (address %to) (nat %value)) ; + IF_NONE { PUSH nat 101 ; FAILWITH } {} ; + PUSH mutez 0 ; + DUP 4 ; + CDR ; + DIG 3 ; + DUP 6 ; + PAIR 3 ; + TRANSFER_TOKENS } + { PUSH string "FA2 token" ; + SWAP ; + COMPARE ; + EQ ; + IF { CONTRACT %transfer + (list (pair (address %from_) (list %tx (pair (address %to_) (nat %token_id) (nat %amount))))) ; + IF_NONE { PUSH nat 101 ; FAILWITH } {} ; + PUSH mutez 0 ; + NIL (pair address (list (pair address nat nat))) ; + NIL (pair address nat nat) ; + DUP 6 ; + CDR ; + DUP 7 ; + CAR ; + CAR ; + DIG 6 ; + PAIR 3 ; + CONS ; + DUP 6 ; + PAIR ; + CONS ; + TRANSFER_TOKENS } + { DROP 2 ; PUSH nat 108 ; FAILWITH } } } } ; + DUP 4 ; + CDR ; + CAR ; + CAR ; + DUP ; + CAR ; + DUP 4 ; + CAR ; + DUP 2 ; + GET 8 ; + DUP 2 ; + GET 8 ; + COMPARE ; + EQ ; + DUP 3 ; + GET 7 ; + DUP 3 ; + GET 7 ; + COMPARE ; + EQ ; + DUP 4 ; + GET 5 ; + DUP 4 ; + GET 5 ; + COMPARE ; + EQ ; + DUP 5 ; + GET 3 ; + DUP 5 ; + GET 3 ; + COMPARE ; + EQ ; + DIG 5 ; + CAR ; + DIG 5 ; + CAR ; + COMPARE ; + EQ ; + AND ; + AND ; + AND ; + AND ; + NOT ; + IF { DIG 2 ; DIG 3 ; DIG 4 ; DROP 4 ; PUSH nat 115 ; FAILWITH } + { DUP 3 ; + CDR ; + DUP 6 ; + CDR ; + CDR ; + CAR ; + ADD ; + DUP 2 ; + DUP 5 ; + CDR ; + DIG 3 ; + CDR ; + ADD ; + UPDATE 2 ; + DUP 6 ; + CDR ; + CDR ; + CDR ; + DUP ; + CAR ; + DUP 7 ; + MEM ; + IF { CDR ; + DUP 6 ; + GET ; + IF_NONE { NONE (pair (pair address nat) mutez) } { SOME } } + { DROP ; NONE (pair (pair address nat) mutez) } ; + IF_NONE + { PUSH mutez 0 ; DIG 4 ; CDR ; DUP 6 ; PAIR ; PAIR } + { DIG 4 ; + CDR ; + DUP 2 ; + CAR ; + CDR ; + ADD ; + DUP 2 ; + DIG 2 ; + CAR ; + DIG 2 ; + UPDATE 2 ; + UPDATE 1 } ; + DUP 6 ; + DUP 7 ; + CDR ; + DUP ; + CDR ; + DIG 5 ; + UPDATE 1 ; + UPDATE 2 ; + UPDATE 2 ; + DUP ; + CDR ; + DUP ; + CDR ; + DIG 7 ; + CDR ; + CDR ; + CDR ; + DUP ; + CAR ; + DUP 9 ; + MEM ; + IF { DUP ; CDR ; DIG 5 ; SOME ; DIG 8 ; UPDATE ; UPDATE 2 } + { DUP ; + DUP 2 ; + CAR ; + DUP 10 ; + PUSH bool True ; + SWAP ; + UPDATE ; + UPDATE 1 ; + SWAP ; + CDR ; + DIG 5 ; + DIG 8 ; + SWAP ; + SOME ; + SWAP ; + UPDATE ; + UPDATE 2 } ; + UPDATE 2 ; + UPDATE 2 ; + UPDATE 2 ; + DUP ; + CDR ; + DUP ; + CAR ; + DIG 3 ; + UPDATE 1 ; + UPDATE 1 ; + UPDATE 2 } ; + NIL operation ; + DIG 2 ; + CONS } + { DUP 2 ; + CDR ; + CDR ; + CAR ; + INT ; + PUSH mutez 1 ; + DIG 2 ; + EDIV ; + IF_NONE { PUSH string "DIV by 0" ; FAILWITH } {} ; + CAR ; + INT ; + DUP 3 ; + CDR ; + CDR ; + CDR ; + EMPTY_MAP address (pair (pair address nat) mutez) ; + DUP 2 ; + CAR ; + ITER { SWAP ; + DUP 3 ; + CDR ; + DUP 3 ; + GET ; + IF_NONE { SWAP ; DROP } { DIG 2 ; SWAP ; SOME ; SWAP ; UPDATE } } ; + SWAP ; + DROP ; + EMPTY_BIG_MAP address (pair (pair address nat) mutez) ; + EMPTY_SET address ; + PAIR ; + SWAP ; + ITER { UNPAIR ; + DUP 2 ; + CAR ; + CDR ; + INT ; + PUSH int 1 ; + DUP 7 ; + PAIR ; + PUSH int 1 ; + DIG 2 ; + PAIR ; + DUP 2 ; + CAR ; + DUP 2 ; + CDR ; + MUL ; + DIG 2 ; + CDR ; + DIG 2 ; + CAR ; + MUL ; + PAIR ; + PUSH int 1 ; + DUP 6 ; + PAIR ; + 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 ; + 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 } } ; + DIG 2 ; + CAR ; + MUL ; + EDIV ; + IF_NONE { PUSH string "DIV by 0" ; FAILWITH } {} ; + CAR ; + ISNAT ; + IF_NONE { PUSH nat 119 ; FAILWITH } {} ; + PUSH mutez 1 ; + MUL ; + PUSH mutez 0 ; + DUP 2 ; + COMPARE ; + GT ; + IF { DUP 3 ; CDR ; ADD } { DROP ; DUP 2 ; CDR } ; + DIG 2 ; + SWAP ; + UPDATE 2 ; + DUP 3 ; + CAR ; + DUP 3 ; + MEM ; + IF { DUP 3 ; DIG 3 ; CDR ; DIG 2 ; SOME ; DIG 3 ; UPDATE ; UPDATE 2 } + { DUP 3 ; + DUP 4 ; + CAR ; + DUP 4 ; + PUSH bool True ; + SWAP ; + UPDATE ; + UPDATE 1 ; + DIG 3 ; + CDR ; + DIG 2 ; + DIG 3 ; + SWAP ; + SOME ; + SWAP ; + UPDATE ; + UPDATE 2 } } ; + SWAP ; + DIG 2 ; + DROP 2 ; + DUP 2 ; + DIG 2 ; + CDR ; + DUP ; + CDR ; + DIG 3 ; + UPDATE 2 ; + UPDATE 2 ; + UPDATE 2 ; + NIL operation } } + { IF_LEFT + { DIG 2 ; + DROP 2 ; + DUP ; + SELF_ADDRESS ; + DUP 3 ; + CDR ; + CAR ; + CAR ; + CAR ; + DUP ; + GET 5 ; + IF_NONE { PUSH nat 101 ; FAILWITH } {} ; + DUP 2 ; + GET 8 ; + IF_NONE { PUSH nat 108 ; FAILWITH } {} ; + PUSH string "FA1.2 token" ; + DUP 2 ; + COMPARE ; + EQ ; + IF { DIG 2 ; + DROP 2 ; + DUP 2 ; + CONTRACT %balance_response_fa12 nat ; + SWAP ; + CONTRACT %getBalance (pair address (contract nat)) ; + SWAP ; + IF_NONE + { DROP ; PUSH nat 172 ; FAILWITH } + { SWAP ; + IF_NONE + { DROP ; PUSH nat 173 ; FAILWITH } + { PUSH mutez 0 ; DIG 2 ; DUP 4 ; PAIR ; TRANSFER_TOKENS } } } + { PUSH string "FA2 token" ; + SWAP ; + COMPARE ; + EQ ; + IF { CONTRACT %balance_of + (pair (list %requests (pair (address %owner) (nat %token_id))) + (contract %callback + (list (pair (pair %request (address %owner) (nat %token_id)) (nat %balance))))) ; + DUP 3 ; + CONTRACT %balance_response_fa2 + (list (pair (pair %request (address %owner) (nat %token_id)) (nat %balance))) ; + IF_NONE + { DROP 2 ; PUSH nat 170 ; FAILWITH } + { SWAP ; + IF_NONE + { DROP 2 ; PUSH nat 171 ; FAILWITH } + { PUSH mutez 0 ; + DIG 2 ; + NIL (pair address nat) ; + DIG 4 ; + CAR ; + DUP 6 ; + PAIR ; + CONS ; + PAIR ; + TRANSFER_TOKENS } } } + { DROP 2 ; PUSH nat 108 ; FAILWITH } } ; + NIL operation ; + SWAP ; + CONS ; + DIG 3 ; + CAR ; + CDR ; + CAR ; + ITER { CDR ; + SWAP ; + DUP 2 ; + CAR ; + GET 5 ; + IF_NONE { PUSH nat 101 ; FAILWITH } {} ; + DUP 3 ; + CAR ; + GET 8 ; + IF_NONE { PUSH nat 108 ; FAILWITH } {} ; + PUSH string "FA1.2 token" ; + DUP 2 ; + COMPARE ; + EQ ; + IF { DIG 3 ; + DROP 2 ; + DUP 3 ; + CONTRACT %balance_response_fa12 nat ; + SWAP ; + CONTRACT %getBalance (pair address (contract nat)) ; + SWAP ; + IF_NONE + { DROP ; PUSH nat 172 ; FAILWITH } + { SWAP ; + IF_NONE + { DROP ; PUSH nat 173 ; FAILWITH } + { PUSH mutez 0 ; DIG 2 ; DUP 5 ; PAIR ; TRANSFER_TOKENS } } } + { PUSH string "FA2 token" ; + SWAP ; + COMPARE ; + EQ ; + IF { CONTRACT %balance_of + (pair (list %requests (pair (address %owner) (nat %token_id))) + (contract %callback + (list (pair (pair %request (address %owner) (nat %token_id)) (nat %balance))))) ; + DUP 4 ; + CONTRACT %balance_response_fa2 + (list (pair (pair %request (address %owner) (nat %token_id)) (nat %balance))) ; + IF_NONE + { DIG 2 ; DROP 2 ; PUSH nat 170 ; FAILWITH } + { SWAP ; + IF_NONE + { DIG 2 ; DROP 2 ; PUSH nat 171 ; FAILWITH } + { PUSH mutez 0 ; + DIG 2 ; + NIL (pair address nat) ; + DIG 5 ; + CAR ; + CAR ; + DUP 7 ; + PAIR ; + CONS ; + PAIR ; + TRANSFER_TOKENS } } } + { DIG 2 ; DROP 2 ; PUSH nat 108 ; FAILWITH } } ; + CONS } ; + SWAP ; + DROP } + { SENDER ; + PUSH nat 101 ; + DUP 4 ; + CDR ; + CAR ; + CAR ; + CAR ; + GET 5 ; + PAIR ; + DIG 4 ; + SWAP ; + EXEC ; + PUSH nat 0 ; + DUP 5 ; + CDR ; + CAR ; + CAR ; + CAR ; + CAR ; + COMPARE ; + EQ ; + DUP 3 ; + DIG 2 ; + COMPARE ; + EQ ; + AND ; + IF { DUP 3 ; + DUP 4 ; + CDR ; + DUP ; + CAR ; + DIG 5 ; + CDR ; + CAR ; + CAR ; + DUP 6 ; + UPDATE 2 ; + UPDATE 1 ; + UPDATE 1 ; + UPDATE 2 } + { DIG 2 } ; + DUP ; + CAR ; + CDR ; + CAR ; + DUP ; + ITER { CDR ; + DUP ; + CAR ; + GET 5 ; + IF_NONE { PUSH nat 101 ; FAILWITH } {} ; + PUSH nat 0 ; + DUP 3 ; + CAR ; + CAR ; + COMPARE ; + EQ ; + DUP 6 ; + DIG 2 ; + COMPARE ; + EQ ; + AND ; + IF { DUP 5 ; UPDATE 2 ; SWAP ; DUP 2 ; SOME ; DIG 2 ; CAR ; GET 3 ; UPDATE } + { DROP } } ; + DIG 2 ; + DIG 3 ; + DROP 2 ; + DUP 2 ; + DIG 2 ; + CAR ; + DUP ; + CDR ; + DIG 3 ; + UPDATE 1 ; + UPDATE 2 ; + UPDATE 1 ; + NIL operation } } } + { IF_LEFT + { IF_LEFT + { SENDER ; + DUG 2 ; + ITER { SWAP ; + DUP 2 ; + CDR ; + DIG 2 ; + CAR ; + CDR ; + PUSH nat 101 ; + DUP 4 ; + CDR ; + CAR ; + CAR ; + CAR ; + GET 5 ; + PAIR ; + DUP 6 ; + SWAP ; + EXEC ; + DUP 2 ; + DUP 5 ; + CDR ; + CAR ; + CAR ; + CAR ; + CAR ; + COMPARE ; + EQ ; + DUP 6 ; + DIG 2 ; + COMPARE ; + EQ ; + AND ; + IF { DUP 3 ; + DUP 4 ; + CDR ; + DUP ; + CAR ; + DIG 5 ; + CDR ; + CAR ; + CAR ; + DUP 6 ; + UPDATE 2 ; + UPDATE 1 ; + UPDATE 1 ; + UPDATE 2 } + { DIG 2 } ; + DUP ; + CAR ; + CDR ; + CAR ; + DUP ; + ITER { CDR ; + DUP ; + CAR ; + GET 5 ; + IF_NONE { PUSH nat 101 ; FAILWITH } {} ; + DUP 5 ; + DUP 3 ; + CAR ; + CAR ; + COMPARE ; + EQ ; + DUP 8 ; + DIG 2 ; + COMPARE ; + EQ ; + AND ; + IF { DUP 5 ; UPDATE 2 ; SWAP ; DUP 2 ; SOME ; DIG 2 ; CAR ; GET 3 ; UPDATE } + { DROP } } ; + DIG 2 ; + DIG 3 ; + DROP 2 ; + DUP 2 ; + DIG 2 ; + CAR ; + DUP ; + CDR ; + DIG 3 ; + UPDATE 1 ; + UPDATE 2 ; + UPDATE 1 } ; + SWAP ; + DIG 2 ; + DROP 2 } + { DIG 2 ; + DROP ; + DUP 2 ; + CAR ; + 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 ; + DUP ; + CAR ; + DIG 3 ; + UPDATE 1 ; + UPDATE 1 ; + UPDATE 1 } } + { DIG 2 ; + DROP ; + IF_LEFT + { DUP 2 ; + CAR ; + 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 ; + DUP ; + CAR ; + DIG 3 ; + UPDATE 2 ; + UPDATE 1 ; + UPDATE 1 } + { DUP 2 ; + CAR ; + 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 ; + DUP ; + CDR ; + DIG 3 ; + UPDATE 2 ; + UPDATE 2 ; + UPDATE 1 } } ; + NIL operation } ; + PAIR } + { DIG 4 ; + DROP ; + IF_LEFT + { DIG 2 ; + DIG 3 ; + DROP 2 ; + IF_LEFT + { DUP 2 ; + CAR ; + 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 ; + DUP ; + CAR ; + DIG 3 ; + UPDATE 2 ; + UPDATE 1 ; + UPDATE 2 ; + NIL operation ; + PAIR } + { DROP ; + PUSH mutez 1 ; + AMOUNT ; + COMPARE ; + LT ; + IF {} { PUSH nat 118 ; FAILWITH } ; + SENDER ; + DUP 2 ; + CDR ; + CDR ; + CDR ; + DUP ; + CAR ; + DUP 3 ; + MEM ; + IF { CDR ; + SWAP ; + GET ; + IF_NONE { NONE (pair (pair address nat) mutez) } { SOME } } + { DROP 2 ; NONE (pair (pair address nat) mutez) } ; + IF_NONE + { DROP ; PUSH nat 155 ; FAILWITH } + { DUP ; + CDR ; + PUSH mutez 0 ; + DUP 2 ; + COMPARE ; + EQ ; + IF { DROP 3 ; PUSH nat 155 ; FAILWITH } + { SWAP ; + PUSH mutez 0 ; + UPDATE 2 ; + DUP ; + CAR ; + CAR ; + CONTRACT unit ; + IF_NONE + { SWAP ; DROP ; PUSH nat 102 ; FAILWITH } + { DIG 2 ; UNIT ; TRANSFER_TOKENS } ; + DUP 3 ; + DUP 4 ; + CDR ; + DUP ; + CDR ; + DIG 5 ; + CDR ; + CDR ; + CDR ; + DUP 6 ; + CAR ; + CAR ; + DUP 2 ; + CAR ; + DUP 2 ; + MEM ; + IF { DUP 2 ; DIG 2 ; CDR ; DIG 7 ; SOME ; DIG 3 ; UPDATE ; UPDATE 2 } + { DUP 2 ; + DUP 3 ; + CAR ; + DUP 3 ; + PUSH bool True ; + SWAP ; + UPDATE ; + UPDATE 1 ; + DIG 2 ; + CDR ; + DIG 7 ; + DIG 3 ; + SWAP ; + SOME ; + SWAP ; + UPDATE ; + UPDATE 2 } ; + UPDATE 2 ; + UPDATE 2 ; + UPDATE 2 ; + NIL operation ; + DIG 2 ; + CONS ; + PAIR } } } } + { IF_LEFT + { DIG 2 ; + DIG 3 ; + DROP 2 ; + DUP 2 ; + CAR ; + CDR ; + CDR ; + SENDER ; + COMPARE ; + EQ ; + IF {} { PUSH nat 168 ; FAILWITH } ; + PUSH mutez 1 ; + AMOUNT ; + COMPARE ; + LT ; + IF {} { PUSH nat 118 ; FAILWITH } ; + UNIT ; + LEFT unit ; + LEFT unit ; + IF_LEFT + { IF_LEFT { DROP ; PUSH nat 1 } { DROP ; PUSH nat 0 } } + { DROP ; PUSH nat 2 } ; + DUP 2 ; + CDR ; + CAR ; + IF_LEFT { DROP ; PUSH nat 0 } { DROP ; PUSH nat 1 } ; + NOW ; + DUP 4 ; + CDR ; + CDR ; + DUP 5 ; + CAR ; + CAR ; + DIG 5 ; + CAR ; + CDR ; + PAIR ; + PAIR ; + PAIR 4 ; + DUP 2 ; + CAR ; + CAR ; + CDR ; + DUP 2 ; + CAR ; + CAR ; + CAR ; + GET 5 ; + IF_NONE + { DROP 2 ; PUSH nat 109 ; FAILWITH } + { DUP 3 ; + CAR ; + CAR ; + CAR ; + GET 8 ; + IF_NONE + { PUSH bool False } + { PUSH string "FA1.2 token" ; SWAP ; COMPARE ; EQ } ; + IF { DUP ; + CONTRACT %approve (pair (address %spender) (nat %value)) ; + IF_NONE { PUSH nat 157 ; FAILWITH } {} ; + PUSH mutez 0 ; + DUP 5 ; + CAR ; + CAR ; + CDR ; + DUP 5 ; + PAIR ; + TRANSFER_TOKENS } + { DUP 3 ; + CAR ; + CAR ; + CAR ; + GET 8 ; + IF_NONE + { PUSH bool False } + { PUSH string "FA2 token" ; SWAP ; COMPARE ; EQ } ; + IF { SELF_ADDRESS ; + DUP 2 ; + CONTRACT %add_operator + (pair (pair (address %operator) (address %owner)) (nat %token_id)) ; + IF_NONE { PUSH nat 157 ; FAILWITH } {} ; + PUSH mutez 0 ; + DUP 6 ; + CAR ; + CAR ; + CAR ; + CAR ; + DIG 3 ; + DUP 6 ; + PAIR ; + PAIR ; + TRANSFER_TOKENS } + { PUSH nat 108 ; FAILWITH } } ; + DUP 3 ; + CONTRACT %deposit + (pair (pair %swap + (pair %from + (pair %token + (nat %token_id) + (string %name) + (option %address address) + (nat %decimals) + (option %standard string)) + (nat %amount)) + (pair %to + (nat %token_id) + (string %name) + (option %address address) + (nat %decimals) + (option %standard string))) + (timestamp %created_at) + (nat %side) + (nat %tolerance)) ; + IF_NONE { PUSH nat 157 ; FAILWITH } {} ; + PUSH mutez 0 ; + DUP 6 ; + TRANSFER_TOKENS ; + DUP 5 ; + CAR ; + CAR ; + CAR ; + GET 8 ; + IF_NONE + { PUSH bool False } + { PUSH string "FA1.2 token" ; SWAP ; COMPARE ; EQ } ; + IF { DIG 2 ; DIG 3 ; DIG 4 ; DROP 3 ; NONE operation } + { DUP 5 ; + CAR ; + CAR ; + CAR ; + GET 8 ; + IF_NONE + { PUSH bool False } + { PUSH string "FA2 token" ; SWAP ; COMPARE ; EQ } ; + IF { SELF_ADDRESS ; + DIG 3 ; + CONTRACT %remove_operator + (pair (pair (address %operator) (address %owner)) (nat %token_id)) ; + IF_NONE { PUSH nat 157 ; FAILWITH } {} ; + PUSH mutez 0 ; + DIG 6 ; + CAR ; + CAR ; + CAR ; + CAR ; + DIG 3 ; + DIG 6 ; + PAIR ; + PAIR ; + TRANSFER_TOKENS ; + SOME } + { DIG 2 ; DIG 3 ; DIG 4 ; DROP 3 ; PUSH nat 108 ; FAILWITH } } ; + IF_NONE { NIL operation } { NIL operation ; SWAP ; CONS } ; + SWAP ; + CONS ; + SWAP ; + CONS } ; + SELF_ADDRESS ; + DUP 3 ; + CDR ; + CAR ; + CAR ; + CAR ; + DUP ; + GET 5 ; + IF_NONE { PUSH nat 101 ; FAILWITH } {} ; + DUP 2 ; + GET 8 ; + IF_NONE { PUSH nat 108 ; FAILWITH } {} ; + PUSH string "FA1.2 token" ; + DUP 2 ; + COMPARE ; + EQ ; + IF { DIG 2 ; + DROP 2 ; + DUP 2 ; + CONTRACT %balance_response_fa12 nat ; + SWAP ; + CONTRACT %getBalance (pair address (contract nat)) ; + SWAP ; + IF_NONE + { DROP ; PUSH nat 172 ; FAILWITH } + { SWAP ; + IF_NONE + { DROP ; PUSH nat 173 ; FAILWITH } + { PUSH mutez 0 ; DIG 2 ; DUP 4 ; PAIR ; TRANSFER_TOKENS } } } + { PUSH string "FA2 token" ; + SWAP ; + COMPARE ; + EQ ; + IF { CONTRACT %balance_of + (pair (list %requests (pair (address %owner) (nat %token_id))) + (contract %callback + (list (pair (pair %request (address %owner) (nat %token_id)) (nat %balance))))) ; + DUP 3 ; + CONTRACT %balance_response_fa2 + (list (pair (pair %request (address %owner) (nat %token_id)) (nat %balance))) ; + IF_NONE + { DROP 2 ; PUSH nat 170 ; FAILWITH } + { SWAP ; + IF_NONE + { DROP 2 ; PUSH nat 171 ; FAILWITH } + { PUSH mutez 0 ; + DIG 2 ; + NIL (pair address nat) ; + DIG 4 ; + CAR ; + DUP 6 ; + PAIR ; + CONS ; + PAIR ; + TRANSFER_TOKENS } } } + { DROP 2 ; PUSH nat 108 ; FAILWITH } } ; + NIL operation ; + SWAP ; + CONS ; + DUP 4 ; + CAR ; + CDR ; + CAR ; + ITER { CDR ; + SWAP ; + DUP 2 ; + CAR ; + GET 5 ; + IF_NONE { PUSH nat 101 ; FAILWITH } {} ; + DUP 3 ; + CAR ; + GET 8 ; + IF_NONE { PUSH nat 108 ; FAILWITH } {} ; + PUSH string "FA1.2 token" ; + DUP 2 ; + COMPARE ; + EQ ; + IF { DIG 3 ; + DROP 2 ; + DUP 3 ; + CONTRACT %balance_response_fa12 nat ; + SWAP ; + CONTRACT %getBalance (pair address (contract nat)) ; + SWAP ; + IF_NONE + { DROP ; PUSH nat 172 ; FAILWITH } + { SWAP ; + IF_NONE + { DROP ; PUSH nat 173 ; FAILWITH } + { PUSH mutez 0 ; DIG 2 ; DUP 5 ; PAIR ; TRANSFER_TOKENS } } } + { PUSH string "FA2 token" ; + SWAP ; + COMPARE ; + EQ ; + IF { CONTRACT %balance_of + (pair (list %requests (pair (address %owner) (nat %token_id))) + (contract %callback + (list (pair (pair %request (address %owner) (nat %token_id)) (nat %balance))))) ; + DUP 4 ; + CONTRACT %balance_response_fa2 + (list (pair (pair %request (address %owner) (nat %token_id)) (nat %balance))) ; + IF_NONE + { DIG 2 ; DROP 2 ; PUSH nat 170 ; FAILWITH } + { SWAP ; + IF_NONE + { DIG 2 ; DROP 2 ; PUSH nat 171 ; FAILWITH } + { PUSH mutez 0 ; + DIG 2 ; + NIL (pair address nat) ; + DIG 5 ; + CAR ; + CAR ; + DUP 7 ; + PAIR ; + CONS ; + PAIR ; + TRANSFER_TOKENS } } } + { DIG 2 ; DROP 2 ; PUSH nat 108 ; FAILWITH } } ; + CONS } ; + SWAP ; + DROP ; + NIL operation ; + SWAP ; + ITER { CONS } ; + SWAP ; + NIL operation ; + SWAP ; + ITER { CONS } ; + ITER { CONS } ; + NIL operation ; + SWAP ; + ITER { CONS } ; + PAIR } + { DROP ; + PUSH mutez 1 ; + AMOUNT ; + COMPARE ; + LT ; + IF {} { PUSH nat 118 ; FAILWITH } ; + SENDER ; + DUP 2 ; + CDR ; + CDR ; + CDR ; + DUP ; + CAR ; + DUP 3 ; + MEM ; + IF { CDR ; + DUP 2 ; + GET ; + IF_NONE { NONE (pair (pair address nat) mutez) } { SOME } } + { DROP ; NONE (pair (pair address nat) mutez) } ; + IF_NONE + { DROP 4 ; PUSH nat 151 ; FAILWITH } + { UNPAIR ; + CDR ; + DUP 4 ; + CDR ; + CDR ; + CAR ; + INT ; + PUSH int 1 ; + SWAP ; + PAIR ; + DUP 2 ; + INT ; + PUSH int 1 ; + SWAP ; + PAIR ; + DUP 2 ; + CAR ; + DUP 2 ; + CDR ; + MUL ; + DIG 2 ; + CDR ; + DIG 2 ; + CAR ; + MUL ; + PAIR ; + DUP 5 ; + CDR ; + CAR ; + CAR ; + DUP ; + CDR ; + INT ; + PUSH int 1 ; + SWAP ; + PAIR ; + DUP ; + CDR ; + DUP 4 ; + CDR ; + MUL ; + SWAP ; + CAR ; + DUP 4 ; + 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 ; + 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 } } ; + DIG 2 ; + CAR ; + MUL ; + EDIV ; + IF_NONE { PUSH string "DIV by 0" ; FAILWITH } {} ; + CAR ; + ISNAT ; + IF_NONE { PUSH nat 119 ; FAILWITH } {} ; + DUP 2 ; + CDR ; + DUP 2 ; + COMPARE ; + GT ; + IF { DROP 2 ; PUSH nat 153 ; FAILWITH } + { DUP ; + DUP 3 ; + CDR ; + INT ; + SUB ; + ABS ; + DUP 3 ; + DIG 2 ; + UPDATE 2 ; + PUSH nat 0 ; + DUP 2 ; + CDR ; + COMPARE ; + EQ ; + IF { DROP ; DUP 9 } { DUP 10 ; SWAP ; PAIR ; DUP 9 ; SWAP ; EXEC } ; + DUG 2 ; + UPDATE 2 ; + PAIR } ; + UNPAIR ; + SWAP ; + DIG 8 ; + DIG 3 ; + PAIR ; + PAIR ; + DUP 6 ; + CAR ; + CDR ; + CAR ; + ITER { CDR ; + SWAP ; + UNPAIR ; + UNPAIR ; + DUP 4 ; + CDR ; + INT ; + PUSH int 1 ; + SWAP ; + PAIR ; + DUP ; + CDR ; + DUP 3 ; + CDR ; + MUL ; + SWAP ; + CAR ; + DUP 3 ; + 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 ; + 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 } } ; + DIG 2 ; + CAR ; + MUL ; + EDIV ; + IF_NONE { PUSH string "DIV by 0" ; FAILWITH } {} ; + CAR ; + ISNAT ; + IF_NONE { PUSH nat 119 ; FAILWITH } {} ; + DUP 5 ; + CDR ; + DUP 2 ; + COMPARE ; + GT ; + IF { DIG 3 ; DIG 4 ; DROP 3 ; PUSH nat 153 ; FAILWITH } + { DUP ; + DUP 6 ; + CDR ; + INT ; + SUB ; + ABS ; + DUP 6 ; + DIG 2 ; + UPDATE 2 ; + PUSH nat 0 ; + DUP 2 ; + CDR ; + COMPARE ; + EQ ; + IF { DROP ; DIG 3 } { DIG 4 ; SWAP ; PAIR ; DUP 11 ; SWAP ; EXEC } ; + DIG 4 ; + DIG 2 ; + UPDATE 2 ; + PAIR } ; + UNPAIR ; + DIG 3 ; + SWAP ; + PAIR ; + DUP 9 ; + SWAP ; + EXEC ; + DIG 2 ; + PAIR ; + PAIR } ; + DIG 6 ; + DROP ; + UNPAIR ; + CDR ; + DUP 7 ; + CDR ; + CDR ; + CAR ; + DUP 5 ; + COMPARE ; + GT ; + IF { SWAP ; DIG 2 ; DIG 3 ; DIG 6 ; DROP 5 ; PUSH nat 154 ; FAILWITH } + { DIG 3 ; + DUP 7 ; + CDR ; + CDR ; + CAR ; + SUB ; + ABS ; + DIG 2 ; + DUP 7 ; + DIG 7 ; + CDR ; + DUP ; + CAR ; + DIG 6 ; + UPDATE 1 ; + UPDATE 1 ; + UPDATE 2 ; + DUP ; + CAR ; + DUP ; + CDR ; + DIG 5 ; + UPDATE 1 ; + UPDATE 2 ; + UPDATE 1 ; + DUP ; + CDR ; + DUP ; + CDR ; + DIG 4 ; + UPDATE 1 ; + UPDATE 2 ; + UPDATE 2 ; + PAIR } ; + UNPAIR ; + DUP 4 ; + CONTRACT unit ; + IF_NONE { PUSH nat 102 ; FAILWITH } { DUP 4 ; UNIT ; TRANSFER_TOKENS } ; + SELF_ADDRESS ; + NIL operation ; + DIG 4 ; + ITER { CDR ; + DUP ; + CAR ; + GET 5 ; + IF_NONE + { DROP ; PUSH nat 109 ; FAILWITH } + { DUP 2 ; + CAR ; + GET 8 ; + IF_NONE + { DROP 2 ; PUSH nat 108 ; FAILWITH } + { PUSH string "FA1.2 token" ; + DUP 2 ; + COMPARE ; + EQ ; + IF { DROP ; + CONTRACT %transfer (pair (address %from) (address %to) (nat %value)) ; + IF_NONE { PUSH nat 101 ; FAILWITH } {} ; + PUSH mutez 0 ; + DIG 2 ; + CDR ; + DUP 9 ; + DUP 6 ; + PAIR 3 ; + TRANSFER_TOKENS } + { PUSH string "FA2 token" ; + SWAP ; + COMPARE ; + EQ ; + IF { CONTRACT %transfer + (list (pair (address %from_) (list %tx (pair (address %to_) (nat %token_id) (nat %amount))))) ; + IF_NONE { PUSH nat 101 ; FAILWITH } {} ; + PUSH mutez 0 ; + NIL (pair address (list (pair address nat nat))) ; + NIL (pair address nat nat) ; + DUP 5 ; + CDR ; + DIG 5 ; + CAR ; + CAR ; + DUP 12 ; + PAIR 3 ; + CONS ; + DUP 6 ; + PAIR ; + CONS ; + TRANSFER_TOKENS } + { DROP 2 ; PUSH nat 108 ; FAILWITH } } } } ; + CONS } ; + SWAP ; + DROP ; + DUP 3 ; + CDR ; + CDR ; + CDR ; + DUP 4 ; + DIG 4 ; + CDR ; + DUP ; + CDR ; + DUP 4 ; + CAR ; + DUP 9 ; + MEM ; + IF { DUP 4 ; + DIG 4 ; + CDR ; + DIG 8 ; + NONE (pair (pair address nat) mutez) ; + SWAP ; + UPDATE ; + UPDATE 2 } + { DIG 7 ; DROP ; DIG 3 } ; + UPDATE 2 ; + UPDATE 2 ; + UPDATE 2 ; + PUSH mutez 0 ; + DIG 4 ; + COMPARE ; + GT ; + IF { SWAP ; DIG 2 ; CONS } { DIG 2 ; DROP ; SWAP } ; + PAIR } } } } } ; + view "get_native_token_of_vault" + unit + (pair (nat %token_id) + (string %name) + (option %address address) + (nat %decimals) + (option %standard string)) + { CDR ; CDR ; CAR ; CAR ; CAR } ; + view "check_entrypoints" + (pair address address) + (pair (pair bool bool) bool bool) + { CAR ; + UNPAIR ; + SELF_ADDRESS ; + SWAP ; + CONTRACT %balance_of + (pair (list %requests (pair (address %owner) (nat %token_id))) + (contract %callback + (list (pair (pair %request (address %owner) (nat %token_id)) (nat %balance))))) ; + DUP 2 ; + CONTRACT %balance_response_fa2 + (list (pair (pair %request (address %owner) (nat %token_id)) (nat %balance))) ; + DIG 3 ; + CONTRACT %getBalance (pair address (contract nat)) ; + DIG 3 ; + CONTRACT %balance_response_fa12 nat ; + IF_NONE { PUSH bool False } { DROP ; PUSH bool True } ; + SWAP ; + IF_NONE { PUSH bool False } { DROP ; PUSH bool True } ; + PAIR ; + SWAP ; + IF_NONE { PUSH bool False } { DROP ; PUSH bool True } ; + DIG 2 ; + IF_NONE { PUSH bool False } { DROP ; PUSH bool True } ; + PAIR ; + PAIR } } + diff --git a/batcher/michelson/usdt-vault-storage-ghostnet.tz b/batcher/michelson/usdt-vault-storage-ghostnet.tz new file mode 100644 index 00000000..c887865c --- /dev/null +++ b/batcher/michelson/usdt-vault-storage-ghostnet.tz @@ -0,0 +1,9 @@ +(Pair (Pair (Pair "tz1ca4batAsNxMYab3mUK5H4QRjY8drV4ViL" "tz1ca4batAsNxMYab3mUK5H4QRjY8drV4ViL") + {} + "tz1ca4batAsNxMYab3mUK5H4QRjY8drV4ViL") + (Pair (Pair (Pair 0 "USDT" (Some "KT1WNrZ7pEbpmYBGPib1e7UVCeC6GA6TkJYR") 6 (Some "FA2 token")) 0) + "KT1SG9z3pU1cNh8dSranm5C5HXWphWi2pLwx") + 0 + {} + {}) + diff --git a/batcher/michelson/usdtz-vault-ghostnet.tz b/batcher/michelson/usdtz-vault-ghostnet.tz new file mode 100644 index 00000000..7713bed1 --- /dev/null +++ b/batcher/michelson/usdtz-vault-ghostnet.tz @@ -0,0 +1,1650 @@ +{ parameter + (or (or (or (or (nat %addLiquidity) (mutez %addReward)) + (or (unit %assertBalances) (nat %balance_response_fa12))) + (or (or (list %balance_response_fa2 + (pair (pair %request (address %owner) (nat %token_id)) (nat %balance))) + (address %change_admin_address)) + (or (address %change_batcher_address) (address %change_marketmaker_address)))) + (or (or (address %change_tokenmanager_address) (unit %claim)) + (or (pair %injectLiquidity + (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))) + (unit %removeLiquidity)))) ; + storage + (pair (pair (pair (address %administrator) (address %batcher)) + (map %foreign_tokens + string + (pair (pair %token + (nat %token_id) + (string %name) + (option %address address) + (nat %decimals) + (option %standard string)) + (nat %amount))) + (address %marketmaker)) + (pair (pair %native_token + (pair %token + (nat %token_id) + (string %name) + (option %address address) + (nat %decimals) + (option %standard string)) + (nat %amount)) + (address %tokenmanager)) + (nat %total_shares) + (pair %vault_holdings + (set %keys address) + (big_map %values + address + (pair (pair (address %holder) (nat %shares)) (mutez %unclaimed))))) ; + code { LAMBDA + (pair (option address) nat) + address + { UNPAIR ; IF_NONE { FAILWITH } { SWAP ; DROP } } ; + EMPTY_MAP string (pair (pair nat string (option address) nat (option string)) nat) ; + LAMBDA + (pair (pair (pair nat string (option address) nat (option string)) nat) + (map string (pair (pair nat string (option address) nat (option string)) nat))) + (map string (pair (pair nat string (option address) nat (option string)) nat)) + { UNPAIR ; + SWAP ; + UNIT ; + RIGHT unit ; + DIG 2 ; + DUP ; + CAR ; + GET 3 ; + DUP 4 ; + DUP 2 ; + GET ; + IF_NONE + { DIG 2 ; DROP ; SWAP ; SOME ; SWAP ; UPDATE } + { DIG 3 ; + IF_LEFT + { DROP ; + DUP ; + CDR ; + DUP 4 ; + CDR ; + COMPARE ; + GT ; + IF { DROP ; PUSH nat 111 ; FAILWITH } + { DUP 3 ; CDR ; SWAP ; CDR ; SUB ; ABS } } + { DROP ; CDR ; DUP 3 ; CDR ; ADD } ; + DIG 3 ; + DIG 3 ; + DIG 2 ; + UPDATE 2 ; + SOME ; + DIG 2 ; + UPDATE } } ; + DIG 3 ; + UNPAIR ; + IF_LEFT + { DIG 2 ; + DIG 3 ; + DROP 2 ; + IF_LEFT + { IF_LEFT + { DIG 2 ; + DROP ; + IF_LEFT + { PUSH mutez 1 ; + AMOUNT ; + COMPARE ; + LT ; + IF {} { PUSH nat 118 ; FAILWITH } ; + SENDER ; + DUP 3 ; + CDR ; + CAR ; + CAR ; + DIG 2 ; + UPDATE 2 ; + SELF_ADDRESS ; + DUP 2 ; + CAR ; + GET 5 ; + IF_NONE + { DROP ; PUSH nat 109 ; FAILWITH } + { DUP 3 ; + CAR ; + GET 8 ; + IF_NONE + { DROP 2 ; PUSH nat 108 ; FAILWITH } + { PUSH string "FA1.2 token" ; + DUP 2 ; + COMPARE ; + EQ ; + IF { DROP ; + CONTRACT %transfer (pair (address %from) (address %to) (nat %value)) ; + IF_NONE { PUSH nat 101 ; FAILWITH } {} ; + PUSH mutez 0 ; + DUP 4 ; + CDR ; + DIG 3 ; + DUP 6 ; + PAIR 3 ; + TRANSFER_TOKENS } + { PUSH string "FA2 token" ; + SWAP ; + COMPARE ; + EQ ; + IF { CONTRACT %transfer + (list (pair (address %from_) (list %tx (pair (address %to_) (nat %token_id) (nat %amount))))) ; + IF_NONE { PUSH nat 101 ; FAILWITH } {} ; + PUSH mutez 0 ; + NIL (pair address (list (pair address nat nat))) ; + NIL (pair address nat nat) ; + DUP 6 ; + CDR ; + DUP 7 ; + CAR ; + CAR ; + DIG 6 ; + PAIR 3 ; + CONS ; + DUP 6 ; + PAIR ; + CONS ; + TRANSFER_TOKENS } + { DROP 2 ; PUSH nat 108 ; FAILWITH } } } } ; + DUP 4 ; + CDR ; + CAR ; + CAR ; + DUP ; + CAR ; + DUP 4 ; + CAR ; + DUP 2 ; + GET 8 ; + DUP 2 ; + GET 8 ; + COMPARE ; + EQ ; + DUP 3 ; + GET 7 ; + DUP 3 ; + GET 7 ; + COMPARE ; + EQ ; + DUP 4 ; + GET 5 ; + DUP 4 ; + GET 5 ; + COMPARE ; + EQ ; + DUP 5 ; + GET 3 ; + DUP 5 ; + GET 3 ; + COMPARE ; + EQ ; + DIG 5 ; + CAR ; + DIG 5 ; + CAR ; + COMPARE ; + EQ ; + AND ; + AND ; + AND ; + AND ; + NOT ; + IF { DIG 2 ; DIG 3 ; DIG 4 ; DROP 4 ; PUSH nat 115 ; FAILWITH } + { DUP 3 ; + CDR ; + DUP 6 ; + CDR ; + CDR ; + CAR ; + ADD ; + DUP 2 ; + DUP 5 ; + CDR ; + DIG 3 ; + CDR ; + ADD ; + UPDATE 2 ; + DUP 6 ; + CDR ; + CDR ; + CDR ; + DUP ; + CAR ; + DUP 7 ; + MEM ; + IF { CDR ; + DUP 6 ; + GET ; + IF_NONE { NONE (pair (pair address nat) mutez) } { SOME } } + { DROP ; NONE (pair (pair address nat) mutez) } ; + IF_NONE + { PUSH mutez 0 ; DIG 4 ; CDR ; DUP 6 ; PAIR ; PAIR } + { DIG 4 ; + CDR ; + DUP 2 ; + CAR ; + CDR ; + ADD ; + DUP 2 ; + DIG 2 ; + CAR ; + DIG 2 ; + UPDATE 2 ; + UPDATE 1 } ; + DUP 6 ; + DUP 7 ; + CDR ; + DUP ; + CDR ; + DIG 5 ; + UPDATE 1 ; + UPDATE 2 ; + UPDATE 2 ; + DUP ; + CDR ; + DUP ; + CDR ; + DIG 7 ; + CDR ; + CDR ; + CDR ; + DUP ; + CAR ; + DUP 9 ; + MEM ; + IF { DUP ; CDR ; DIG 5 ; SOME ; DIG 8 ; UPDATE ; UPDATE 2 } + { DUP ; + DUP 2 ; + CAR ; + DUP 10 ; + PUSH bool True ; + SWAP ; + UPDATE ; + UPDATE 1 ; + SWAP ; + CDR ; + DIG 5 ; + DIG 8 ; + SWAP ; + SOME ; + SWAP ; + UPDATE ; + UPDATE 2 } ; + UPDATE 2 ; + UPDATE 2 ; + UPDATE 2 ; + DUP ; + CDR ; + DUP ; + CAR ; + DIG 3 ; + UPDATE 1 ; + UPDATE 1 ; + UPDATE 2 } ; + NIL operation ; + DIG 2 ; + CONS } + { DUP 2 ; + CDR ; + CDR ; + CAR ; + INT ; + PUSH mutez 1 ; + DIG 2 ; + EDIV ; + IF_NONE { PUSH string "DIV by 0" ; FAILWITH } {} ; + CAR ; + INT ; + DUP 3 ; + CDR ; + CDR ; + CDR ; + EMPTY_MAP address (pair (pair address nat) mutez) ; + DUP 2 ; + CAR ; + ITER { SWAP ; + DUP 3 ; + CDR ; + DUP 3 ; + GET ; + IF_NONE { SWAP ; DROP } { DIG 2 ; SWAP ; SOME ; SWAP ; UPDATE } } ; + SWAP ; + DROP ; + EMPTY_BIG_MAP address (pair (pair address nat) mutez) ; + EMPTY_SET address ; + PAIR ; + SWAP ; + ITER { UNPAIR ; + DUP 2 ; + CAR ; + CDR ; + INT ; + PUSH int 1 ; + DUP 7 ; + PAIR ; + PUSH int 1 ; + DIG 2 ; + PAIR ; + DUP 2 ; + CAR ; + DUP 2 ; + CDR ; + MUL ; + DIG 2 ; + CDR ; + DIG 2 ; + CAR ; + MUL ; + PAIR ; + PUSH int 1 ; + DUP 6 ; + PAIR ; + 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 ; + 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 } } ; + DIG 2 ; + CAR ; + MUL ; + EDIV ; + IF_NONE { PUSH string "DIV by 0" ; FAILWITH } {} ; + CAR ; + ISNAT ; + IF_NONE { PUSH nat 119 ; FAILWITH } {} ; + PUSH mutez 1 ; + MUL ; + PUSH mutez 0 ; + DUP 2 ; + COMPARE ; + GT ; + IF { DUP 3 ; CDR ; ADD } { DROP ; DUP 2 ; CDR } ; + DIG 2 ; + SWAP ; + UPDATE 2 ; + DUP 3 ; + CAR ; + DUP 3 ; + MEM ; + IF { DUP 3 ; DIG 3 ; CDR ; DIG 2 ; SOME ; DIG 3 ; UPDATE ; UPDATE 2 } + { DUP 3 ; + DUP 4 ; + CAR ; + DUP 4 ; + PUSH bool True ; + SWAP ; + UPDATE ; + UPDATE 1 ; + DIG 3 ; + CDR ; + DIG 2 ; + DIG 3 ; + SWAP ; + SOME ; + SWAP ; + UPDATE ; + UPDATE 2 } } ; + SWAP ; + DIG 2 ; + DROP 2 ; + DUP 2 ; + DIG 2 ; + CDR ; + DUP ; + CDR ; + DIG 3 ; + UPDATE 2 ; + UPDATE 2 ; + UPDATE 2 ; + NIL operation } } + { IF_LEFT + { DIG 2 ; + DROP 2 ; + DUP ; + SELF_ADDRESS ; + DUP 3 ; + CDR ; + CAR ; + CAR ; + CAR ; + DUP ; + GET 5 ; + IF_NONE { PUSH nat 101 ; FAILWITH } {} ; + DUP 2 ; + GET 8 ; + IF_NONE { PUSH nat 108 ; FAILWITH } {} ; + PUSH string "FA1.2 token" ; + DUP 2 ; + COMPARE ; + EQ ; + IF { DIG 2 ; + DROP 2 ; + DUP 2 ; + CONTRACT %balance_response_fa12 nat ; + SWAP ; + CONTRACT %getBalance (pair address (contract nat)) ; + SWAP ; + IF_NONE + { DROP ; PUSH nat 172 ; FAILWITH } + { SWAP ; + IF_NONE + { DROP ; PUSH nat 173 ; FAILWITH } + { PUSH mutez 0 ; DIG 2 ; DUP 4 ; PAIR ; TRANSFER_TOKENS } } } + { PUSH string "FA2 token" ; + SWAP ; + COMPARE ; + EQ ; + IF { CONTRACT %balance_of + (pair (list %requests (pair (address %owner) (nat %token_id))) + (contract %callback + (list (pair (pair %request (address %owner) (nat %token_id)) (nat %balance))))) ; + DUP 3 ; + CONTRACT %balance_response_fa2 + (list (pair (pair %request (address %owner) (nat %token_id)) (nat %balance))) ; + IF_NONE + { DROP 2 ; PUSH nat 170 ; FAILWITH } + { SWAP ; + IF_NONE + { DROP 2 ; PUSH nat 171 ; FAILWITH } + { PUSH mutez 0 ; + DIG 2 ; + NIL (pair address nat) ; + DIG 4 ; + CAR ; + DUP 6 ; + PAIR ; + CONS ; + PAIR ; + TRANSFER_TOKENS } } } + { DROP 2 ; PUSH nat 108 ; FAILWITH } } ; + NIL operation ; + SWAP ; + CONS ; + DIG 3 ; + CAR ; + CDR ; + CAR ; + ITER { CDR ; + SWAP ; + DUP 2 ; + CAR ; + GET 5 ; + IF_NONE { PUSH nat 101 ; FAILWITH } {} ; + DUP 3 ; + CAR ; + GET 8 ; + IF_NONE { PUSH nat 108 ; FAILWITH } {} ; + PUSH string "FA1.2 token" ; + DUP 2 ; + COMPARE ; + EQ ; + IF { DIG 3 ; + DROP 2 ; + DUP 3 ; + CONTRACT %balance_response_fa12 nat ; + SWAP ; + CONTRACT %getBalance (pair address (contract nat)) ; + SWAP ; + IF_NONE + { DROP ; PUSH nat 172 ; FAILWITH } + { SWAP ; + IF_NONE + { DROP ; PUSH nat 173 ; FAILWITH } + { PUSH mutez 0 ; DIG 2 ; DUP 5 ; PAIR ; TRANSFER_TOKENS } } } + { PUSH string "FA2 token" ; + SWAP ; + COMPARE ; + EQ ; + IF { CONTRACT %balance_of + (pair (list %requests (pair (address %owner) (nat %token_id))) + (contract %callback + (list (pair (pair %request (address %owner) (nat %token_id)) (nat %balance))))) ; + DUP 4 ; + CONTRACT %balance_response_fa2 + (list (pair (pair %request (address %owner) (nat %token_id)) (nat %balance))) ; + IF_NONE + { DIG 2 ; DROP 2 ; PUSH nat 170 ; FAILWITH } + { SWAP ; + IF_NONE + { DIG 2 ; DROP 2 ; PUSH nat 171 ; FAILWITH } + { PUSH mutez 0 ; + DIG 2 ; + NIL (pair address nat) ; + DIG 5 ; + CAR ; + CAR ; + DUP 7 ; + PAIR ; + CONS ; + PAIR ; + TRANSFER_TOKENS } } } + { DIG 2 ; DROP 2 ; PUSH nat 108 ; FAILWITH } } ; + CONS } ; + SWAP ; + DROP } + { SENDER ; + PUSH nat 101 ; + DUP 4 ; + CDR ; + CAR ; + CAR ; + CAR ; + GET 5 ; + PAIR ; + DIG 4 ; + SWAP ; + EXEC ; + PUSH nat 0 ; + DUP 5 ; + CDR ; + CAR ; + CAR ; + CAR ; + CAR ; + COMPARE ; + EQ ; + DUP 3 ; + DIG 2 ; + COMPARE ; + EQ ; + AND ; + IF { DUP 3 ; + DUP 4 ; + CDR ; + DUP ; + CAR ; + DIG 5 ; + CDR ; + CAR ; + CAR ; + DUP 6 ; + UPDATE 2 ; + UPDATE 1 ; + UPDATE 1 ; + UPDATE 2 } + { DIG 2 } ; + DUP ; + CAR ; + CDR ; + CAR ; + DUP ; + ITER { CDR ; + DUP ; + CAR ; + GET 5 ; + IF_NONE { PUSH nat 101 ; FAILWITH } {} ; + PUSH nat 0 ; + DUP 3 ; + CAR ; + CAR ; + COMPARE ; + EQ ; + DUP 6 ; + DIG 2 ; + COMPARE ; + EQ ; + AND ; + IF { DUP 5 ; UPDATE 2 ; SWAP ; DUP 2 ; SOME ; DIG 2 ; CAR ; GET 3 ; UPDATE } + { DROP } } ; + DIG 2 ; + DIG 3 ; + DROP 2 ; + DUP 2 ; + DIG 2 ; + CAR ; + DUP ; + CDR ; + DIG 3 ; + UPDATE 1 ; + UPDATE 2 ; + UPDATE 1 ; + NIL operation } } } + { IF_LEFT + { IF_LEFT + { SENDER ; + DUG 2 ; + ITER { SWAP ; + DUP 2 ; + CDR ; + DIG 2 ; + CAR ; + CDR ; + PUSH nat 101 ; + DUP 4 ; + CDR ; + CAR ; + CAR ; + CAR ; + GET 5 ; + PAIR ; + DUP 6 ; + SWAP ; + EXEC ; + DUP 2 ; + DUP 5 ; + CDR ; + CAR ; + CAR ; + CAR ; + CAR ; + COMPARE ; + EQ ; + DUP 6 ; + DIG 2 ; + COMPARE ; + EQ ; + AND ; + IF { DUP 3 ; + DUP 4 ; + CDR ; + DUP ; + CAR ; + DIG 5 ; + CDR ; + CAR ; + CAR ; + DUP 6 ; + UPDATE 2 ; + UPDATE 1 ; + UPDATE 1 ; + UPDATE 2 } + { DIG 2 } ; + DUP ; + CAR ; + CDR ; + CAR ; + DUP ; + ITER { CDR ; + DUP ; + CAR ; + GET 5 ; + IF_NONE { PUSH nat 101 ; FAILWITH } {} ; + DUP 5 ; + DUP 3 ; + CAR ; + CAR ; + COMPARE ; + EQ ; + DUP 8 ; + DIG 2 ; + COMPARE ; + EQ ; + AND ; + IF { DUP 5 ; UPDATE 2 ; SWAP ; DUP 2 ; SOME ; DIG 2 ; CAR ; GET 3 ; UPDATE } + { DROP } } ; + DIG 2 ; + DIG 3 ; + DROP 2 ; + DUP 2 ; + DIG 2 ; + CAR ; + DUP ; + CDR ; + DIG 3 ; + UPDATE 1 ; + UPDATE 2 ; + UPDATE 1 } ; + SWAP ; + DIG 2 ; + DROP 2 } + { DIG 2 ; + DROP ; + DUP 2 ; + CAR ; + 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 ; + DUP ; + CAR ; + DIG 3 ; + UPDATE 1 ; + UPDATE 1 ; + UPDATE 1 } } + { DIG 2 ; + DROP ; + IF_LEFT + { DUP 2 ; + CAR ; + 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 ; + DUP ; + CAR ; + DIG 3 ; + UPDATE 2 ; + UPDATE 1 ; + UPDATE 1 } + { DUP 2 ; + CAR ; + 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 ; + DUP ; + CDR ; + DIG 3 ; + UPDATE 2 ; + UPDATE 2 ; + UPDATE 1 } } ; + NIL operation } ; + PAIR } + { DIG 4 ; + DROP ; + IF_LEFT + { DIG 2 ; + DIG 3 ; + DROP 2 ; + IF_LEFT + { DUP 2 ; + CAR ; + 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 ; + DUP ; + CAR ; + DIG 3 ; + UPDATE 2 ; + UPDATE 1 ; + UPDATE 2 ; + NIL operation ; + PAIR } + { DROP ; + PUSH mutez 1 ; + AMOUNT ; + COMPARE ; + LT ; + IF {} { PUSH nat 118 ; FAILWITH } ; + SENDER ; + DUP 2 ; + CDR ; + CDR ; + CDR ; + DUP ; + CAR ; + DUP 3 ; + MEM ; + IF { CDR ; + SWAP ; + GET ; + IF_NONE { NONE (pair (pair address nat) mutez) } { SOME } } + { DROP 2 ; NONE (pair (pair address nat) mutez) } ; + IF_NONE + { DROP ; PUSH nat 155 ; FAILWITH } + { DUP ; + CDR ; + PUSH mutez 0 ; + DUP 2 ; + COMPARE ; + EQ ; + IF { DROP 3 ; PUSH nat 155 ; FAILWITH } + { SWAP ; + PUSH mutez 0 ; + UPDATE 2 ; + DUP ; + CAR ; + CAR ; + CONTRACT unit ; + IF_NONE + { SWAP ; DROP ; PUSH nat 102 ; FAILWITH } + { DIG 2 ; UNIT ; TRANSFER_TOKENS } ; + DUP 3 ; + DUP 4 ; + CDR ; + DUP ; + CDR ; + DIG 5 ; + CDR ; + CDR ; + CDR ; + DUP 6 ; + CAR ; + CAR ; + DUP 2 ; + CAR ; + DUP 2 ; + MEM ; + IF { DUP 2 ; DIG 2 ; CDR ; DIG 7 ; SOME ; DIG 3 ; UPDATE ; UPDATE 2 } + { DUP 2 ; + DUP 3 ; + CAR ; + DUP 3 ; + PUSH bool True ; + SWAP ; + UPDATE ; + UPDATE 1 ; + DIG 2 ; + CDR ; + DIG 7 ; + DIG 3 ; + SWAP ; + SOME ; + SWAP ; + UPDATE ; + UPDATE 2 } ; + UPDATE 2 ; + UPDATE 2 ; + UPDATE 2 ; + NIL operation ; + DIG 2 ; + CONS ; + PAIR } } } } + { IF_LEFT + { DIG 2 ; + DIG 3 ; + DROP 2 ; + DUP 2 ; + CAR ; + CDR ; + CDR ; + SENDER ; + COMPARE ; + EQ ; + IF {} { PUSH nat 168 ; FAILWITH } ; + PUSH mutez 1 ; + AMOUNT ; + COMPARE ; + LT ; + IF {} { PUSH nat 118 ; FAILWITH } ; + UNIT ; + LEFT unit ; + LEFT unit ; + IF_LEFT + { IF_LEFT { DROP ; PUSH nat 1 } { DROP ; PUSH nat 0 } } + { DROP ; PUSH nat 2 } ; + DUP 2 ; + CDR ; + CAR ; + IF_LEFT { DROP ; PUSH nat 0 } { DROP ; PUSH nat 1 } ; + NOW ; + DUP 4 ; + CDR ; + CDR ; + DUP 5 ; + CAR ; + CAR ; + DIG 5 ; + CAR ; + CDR ; + PAIR ; + PAIR ; + PAIR 4 ; + DUP 2 ; + CAR ; + CAR ; + CDR ; + DUP 2 ; + CAR ; + CAR ; + CAR ; + GET 5 ; + IF_NONE + { DROP 2 ; PUSH nat 109 ; FAILWITH } + { DUP 3 ; + CAR ; + CAR ; + CAR ; + GET 8 ; + IF_NONE + { PUSH bool False } + { PUSH string "FA1.2 token" ; SWAP ; COMPARE ; EQ } ; + IF { DUP ; + CONTRACT %approve (pair (address %spender) (nat %value)) ; + IF_NONE { PUSH nat 157 ; FAILWITH } {} ; + PUSH mutez 0 ; + DUP 5 ; + CAR ; + CAR ; + CDR ; + DUP 5 ; + PAIR ; + TRANSFER_TOKENS } + { DUP 3 ; + CAR ; + CAR ; + CAR ; + GET 8 ; + IF_NONE + { PUSH bool False } + { PUSH string "FA2 token" ; SWAP ; COMPARE ; EQ } ; + IF { SELF_ADDRESS ; + DUP 2 ; + CONTRACT %add_operator + (pair (pair (address %operator) (address %owner)) (nat %token_id)) ; + IF_NONE { PUSH nat 157 ; FAILWITH } {} ; + PUSH mutez 0 ; + DUP 6 ; + CAR ; + CAR ; + CAR ; + CAR ; + DIG 3 ; + DUP 6 ; + PAIR ; + PAIR ; + TRANSFER_TOKENS } + { PUSH nat 108 ; FAILWITH } } ; + DUP 3 ; + CONTRACT %deposit + (pair (pair %swap + (pair %from + (pair %token + (nat %token_id) + (string %name) + (option %address address) + (nat %decimals) + (option %standard string)) + (nat %amount)) + (pair %to + (nat %token_id) + (string %name) + (option %address address) + (nat %decimals) + (option %standard string))) + (timestamp %created_at) + (nat %side) + (nat %tolerance)) ; + IF_NONE { PUSH nat 157 ; FAILWITH } {} ; + PUSH mutez 0 ; + DUP 6 ; + TRANSFER_TOKENS ; + DUP 5 ; + CAR ; + CAR ; + CAR ; + GET 8 ; + IF_NONE + { PUSH bool False } + { PUSH string "FA1.2 token" ; SWAP ; COMPARE ; EQ } ; + IF { DIG 2 ; DIG 3 ; DIG 4 ; DROP 3 ; NONE operation } + { DUP 5 ; + CAR ; + CAR ; + CAR ; + GET 8 ; + IF_NONE + { PUSH bool False } + { PUSH string "FA2 token" ; SWAP ; COMPARE ; EQ } ; + IF { SELF_ADDRESS ; + DIG 3 ; + CONTRACT %remove_operator + (pair (pair (address %operator) (address %owner)) (nat %token_id)) ; + IF_NONE { PUSH nat 157 ; FAILWITH } {} ; + PUSH mutez 0 ; + DIG 6 ; + CAR ; + CAR ; + CAR ; + CAR ; + DIG 3 ; + DIG 6 ; + PAIR ; + PAIR ; + TRANSFER_TOKENS ; + SOME } + { DIG 2 ; DIG 3 ; DIG 4 ; DROP 3 ; PUSH nat 108 ; FAILWITH } } ; + IF_NONE { NIL operation } { NIL operation ; SWAP ; CONS } ; + SWAP ; + CONS ; + SWAP ; + CONS } ; + SELF_ADDRESS ; + DUP 3 ; + CDR ; + CAR ; + CAR ; + CAR ; + DUP ; + GET 5 ; + IF_NONE { PUSH nat 101 ; FAILWITH } {} ; + DUP 2 ; + GET 8 ; + IF_NONE { PUSH nat 108 ; FAILWITH } {} ; + PUSH string "FA1.2 token" ; + DUP 2 ; + COMPARE ; + EQ ; + IF { DIG 2 ; + DROP 2 ; + DUP 2 ; + CONTRACT %balance_response_fa12 nat ; + SWAP ; + CONTRACT %getBalance (pair address (contract nat)) ; + SWAP ; + IF_NONE + { DROP ; PUSH nat 172 ; FAILWITH } + { SWAP ; + IF_NONE + { DROP ; PUSH nat 173 ; FAILWITH } + { PUSH mutez 0 ; DIG 2 ; DUP 4 ; PAIR ; TRANSFER_TOKENS } } } + { PUSH string "FA2 token" ; + SWAP ; + COMPARE ; + EQ ; + IF { CONTRACT %balance_of + (pair (list %requests (pair (address %owner) (nat %token_id))) + (contract %callback + (list (pair (pair %request (address %owner) (nat %token_id)) (nat %balance))))) ; + DUP 3 ; + CONTRACT %balance_response_fa2 + (list (pair (pair %request (address %owner) (nat %token_id)) (nat %balance))) ; + IF_NONE + { DROP 2 ; PUSH nat 170 ; FAILWITH } + { SWAP ; + IF_NONE + { DROP 2 ; PUSH nat 171 ; FAILWITH } + { PUSH mutez 0 ; + DIG 2 ; + NIL (pair address nat) ; + DIG 4 ; + CAR ; + DUP 6 ; + PAIR ; + CONS ; + PAIR ; + TRANSFER_TOKENS } } } + { DROP 2 ; PUSH nat 108 ; FAILWITH } } ; + NIL operation ; + SWAP ; + CONS ; + DUP 4 ; + CAR ; + CDR ; + CAR ; + ITER { CDR ; + SWAP ; + DUP 2 ; + CAR ; + GET 5 ; + IF_NONE { PUSH nat 101 ; FAILWITH } {} ; + DUP 3 ; + CAR ; + GET 8 ; + IF_NONE { PUSH nat 108 ; FAILWITH } {} ; + PUSH string "FA1.2 token" ; + DUP 2 ; + COMPARE ; + EQ ; + IF { DIG 3 ; + DROP 2 ; + DUP 3 ; + CONTRACT %balance_response_fa12 nat ; + SWAP ; + CONTRACT %getBalance (pair address (contract nat)) ; + SWAP ; + IF_NONE + { DROP ; PUSH nat 172 ; FAILWITH } + { SWAP ; + IF_NONE + { DROP ; PUSH nat 173 ; FAILWITH } + { PUSH mutez 0 ; DIG 2 ; DUP 5 ; PAIR ; TRANSFER_TOKENS } } } + { PUSH string "FA2 token" ; + SWAP ; + COMPARE ; + EQ ; + IF { CONTRACT %balance_of + (pair (list %requests (pair (address %owner) (nat %token_id))) + (contract %callback + (list (pair (pair %request (address %owner) (nat %token_id)) (nat %balance))))) ; + DUP 4 ; + CONTRACT %balance_response_fa2 + (list (pair (pair %request (address %owner) (nat %token_id)) (nat %balance))) ; + IF_NONE + { DIG 2 ; DROP 2 ; PUSH nat 170 ; FAILWITH } + { SWAP ; + IF_NONE + { DIG 2 ; DROP 2 ; PUSH nat 171 ; FAILWITH } + { PUSH mutez 0 ; + DIG 2 ; + NIL (pair address nat) ; + DIG 5 ; + CAR ; + CAR ; + DUP 7 ; + PAIR ; + CONS ; + PAIR ; + TRANSFER_TOKENS } } } + { DIG 2 ; DROP 2 ; PUSH nat 108 ; FAILWITH } } ; + CONS } ; + SWAP ; + DROP ; + NIL operation ; + SWAP ; + ITER { CONS } ; + SWAP ; + NIL operation ; + SWAP ; + ITER { CONS } ; + ITER { CONS } ; + NIL operation ; + SWAP ; + ITER { CONS } ; + PAIR } + { DROP ; + PUSH mutez 1 ; + AMOUNT ; + COMPARE ; + LT ; + IF {} { PUSH nat 118 ; FAILWITH } ; + SENDER ; + DUP 2 ; + CDR ; + CDR ; + CDR ; + DUP ; + CAR ; + DUP 3 ; + MEM ; + IF { CDR ; + DUP 2 ; + GET ; + IF_NONE { NONE (pair (pair address nat) mutez) } { SOME } } + { DROP ; NONE (pair (pair address nat) mutez) } ; + IF_NONE + { DROP 4 ; PUSH nat 151 ; FAILWITH } + { UNPAIR ; + CDR ; + DUP 4 ; + CDR ; + CDR ; + CAR ; + INT ; + PUSH int 1 ; + SWAP ; + PAIR ; + DUP 2 ; + INT ; + PUSH int 1 ; + SWAP ; + PAIR ; + DUP 2 ; + CAR ; + DUP 2 ; + CDR ; + MUL ; + DIG 2 ; + CDR ; + DIG 2 ; + CAR ; + MUL ; + PAIR ; + DUP 5 ; + CDR ; + CAR ; + CAR ; + DUP ; + CDR ; + INT ; + PUSH int 1 ; + SWAP ; + PAIR ; + DUP ; + CDR ; + DUP 4 ; + CDR ; + MUL ; + SWAP ; + CAR ; + DUP 4 ; + 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 ; + 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 } } ; + DIG 2 ; + CAR ; + MUL ; + EDIV ; + IF_NONE { PUSH string "DIV by 0" ; FAILWITH } {} ; + CAR ; + ISNAT ; + IF_NONE { PUSH nat 119 ; FAILWITH } {} ; + DUP 2 ; + CDR ; + DUP 2 ; + COMPARE ; + GT ; + IF { DROP 2 ; PUSH nat 153 ; FAILWITH } + { DUP ; + DUP 3 ; + CDR ; + INT ; + SUB ; + ABS ; + DUP 3 ; + DIG 2 ; + UPDATE 2 ; + PUSH nat 0 ; + DUP 2 ; + CDR ; + COMPARE ; + EQ ; + IF { DROP ; DUP 9 } { DUP 10 ; SWAP ; PAIR ; DUP 9 ; SWAP ; EXEC } ; + DUG 2 ; + UPDATE 2 ; + PAIR } ; + UNPAIR ; + SWAP ; + DIG 8 ; + DIG 3 ; + PAIR ; + PAIR ; + DUP 6 ; + CAR ; + CDR ; + CAR ; + ITER { CDR ; + SWAP ; + UNPAIR ; + UNPAIR ; + DUP 4 ; + CDR ; + INT ; + PUSH int 1 ; + SWAP ; + PAIR ; + DUP ; + CDR ; + DUP 3 ; + CDR ; + MUL ; + SWAP ; + CAR ; + DUP 3 ; + 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 ; + 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 } } ; + DIG 2 ; + CAR ; + MUL ; + EDIV ; + IF_NONE { PUSH string "DIV by 0" ; FAILWITH } {} ; + CAR ; + ISNAT ; + IF_NONE { PUSH nat 119 ; FAILWITH } {} ; + DUP 5 ; + CDR ; + DUP 2 ; + COMPARE ; + GT ; + IF { DIG 3 ; DIG 4 ; DROP 3 ; PUSH nat 153 ; FAILWITH } + { DUP ; + DUP 6 ; + CDR ; + INT ; + SUB ; + ABS ; + DUP 6 ; + DIG 2 ; + UPDATE 2 ; + PUSH nat 0 ; + DUP 2 ; + CDR ; + COMPARE ; + EQ ; + IF { DROP ; DIG 3 } { DIG 4 ; SWAP ; PAIR ; DUP 11 ; SWAP ; EXEC } ; + DIG 4 ; + DIG 2 ; + UPDATE 2 ; + PAIR } ; + UNPAIR ; + DIG 3 ; + SWAP ; + PAIR ; + DUP 9 ; + SWAP ; + EXEC ; + DIG 2 ; + PAIR ; + PAIR } ; + DIG 6 ; + DROP ; + UNPAIR ; + CDR ; + DUP 7 ; + CDR ; + CDR ; + CAR ; + DUP 5 ; + COMPARE ; + GT ; + IF { SWAP ; DIG 2 ; DIG 3 ; DIG 6 ; DROP 5 ; PUSH nat 154 ; FAILWITH } + { DIG 3 ; + DUP 7 ; + CDR ; + CDR ; + CAR ; + SUB ; + ABS ; + DIG 2 ; + DUP 7 ; + DIG 7 ; + CDR ; + DUP ; + CAR ; + DIG 6 ; + UPDATE 1 ; + UPDATE 1 ; + UPDATE 2 ; + DUP ; + CAR ; + DUP ; + CDR ; + DIG 5 ; + UPDATE 1 ; + UPDATE 2 ; + UPDATE 1 ; + DUP ; + CDR ; + DUP ; + CDR ; + DIG 4 ; + UPDATE 1 ; + UPDATE 2 ; + UPDATE 2 ; + PAIR } ; + UNPAIR ; + DUP 4 ; + CONTRACT unit ; + IF_NONE { PUSH nat 102 ; FAILWITH } { DUP 4 ; UNIT ; TRANSFER_TOKENS } ; + SELF_ADDRESS ; + NIL operation ; + DIG 4 ; + ITER { CDR ; + DUP ; + CAR ; + GET 5 ; + IF_NONE + { DROP ; PUSH nat 109 ; FAILWITH } + { DUP 2 ; + CAR ; + GET 8 ; + IF_NONE + { DROP 2 ; PUSH nat 108 ; FAILWITH } + { PUSH string "FA1.2 token" ; + DUP 2 ; + COMPARE ; + EQ ; + IF { DROP ; + CONTRACT %transfer (pair (address %from) (address %to) (nat %value)) ; + IF_NONE { PUSH nat 101 ; FAILWITH } {} ; + PUSH mutez 0 ; + DIG 2 ; + CDR ; + DUP 9 ; + DUP 6 ; + PAIR 3 ; + TRANSFER_TOKENS } + { PUSH string "FA2 token" ; + SWAP ; + COMPARE ; + EQ ; + IF { CONTRACT %transfer + (list (pair (address %from_) (list %tx (pair (address %to_) (nat %token_id) (nat %amount))))) ; + IF_NONE { PUSH nat 101 ; FAILWITH } {} ; + PUSH mutez 0 ; + NIL (pair address (list (pair address nat nat))) ; + NIL (pair address nat nat) ; + DUP 5 ; + CDR ; + DIG 5 ; + CAR ; + CAR ; + DUP 12 ; + PAIR 3 ; + CONS ; + DUP 6 ; + PAIR ; + CONS ; + TRANSFER_TOKENS } + { DROP 2 ; PUSH nat 108 ; FAILWITH } } } } ; + CONS } ; + SWAP ; + DROP ; + DUP 3 ; + CDR ; + CDR ; + CDR ; + DUP 4 ; + DIG 4 ; + CDR ; + DUP ; + CDR ; + DUP 4 ; + CAR ; + DUP 9 ; + MEM ; + IF { DUP 4 ; + DIG 4 ; + CDR ; + DIG 8 ; + NONE (pair (pair address nat) mutez) ; + SWAP ; + UPDATE ; + UPDATE 2 } + { DIG 7 ; DROP ; DIG 3 } ; + UPDATE 2 ; + UPDATE 2 ; + UPDATE 2 ; + PUSH mutez 0 ; + DIG 4 ; + COMPARE ; + GT ; + IF { SWAP ; DIG 2 ; CONS } { DIG 2 ; DROP ; SWAP } ; + PAIR } } } } } ; + view "get_native_token_of_vault" + unit + (pair (nat %token_id) + (string %name) + (option %address address) + (nat %decimals) + (option %standard string)) + { CDR ; CDR ; CAR ; CAR ; CAR } ; + view "check_entrypoints" + (pair address address) + (pair (pair bool bool) bool bool) + { CAR ; + UNPAIR ; + SELF_ADDRESS ; + SWAP ; + CONTRACT %balance_of + (pair (list %requests (pair (address %owner) (nat %token_id))) + (contract %callback + (list (pair (pair %request (address %owner) (nat %token_id)) (nat %balance))))) ; + DUP 2 ; + CONTRACT %balance_response_fa2 + (list (pair (pair %request (address %owner) (nat %token_id)) (nat %balance))) ; + DIG 3 ; + CONTRACT %getBalance (pair address (contract nat)) ; + DIG 3 ; + CONTRACT %balance_response_fa12 nat ; + IF_NONE { PUSH bool False } { DROP ; PUSH bool True } ; + SWAP ; + IF_NONE { PUSH bool False } { DROP ; PUSH bool True } ; + PAIR ; + SWAP ; + IF_NONE { PUSH bool False } { DROP ; PUSH bool True } ; + DIG 2 ; + IF_NONE { PUSH bool False } { DROP ; PUSH bool True } ; + PAIR ; + PAIR } } + diff --git a/batcher/michelson/usdtz-vault-storage-ghostnet.tz b/batcher/michelson/usdtz-vault-storage-ghostnet.tz new file mode 100644 index 00000000..9529ad7e --- /dev/null +++ b/batcher/michelson/usdtz-vault-storage-ghostnet.tz @@ -0,0 +1,10 @@ +(Pair (Pair (Pair "tz1ca4batAsNxMYab3mUK5H4QRjY8drV4ViL" "tz1ca4batAsNxMYab3mUK5H4QRjY8drV4ViL") + {} + "tz1ca4batAsNxMYab3mUK5H4QRjY8drV4ViL") + (Pair (Pair (Pair 0 "USDtz" (Some "KT1B8tP5Q8Cb7HctLfxt4MVk2cWouHFrnbjW") 6 (Some "FA1.2 token")) + 0) + "KT1SG9z3pU1cNh8dSranm5C5HXWphWi2pLwx") + 0 + {} + {}) + diff --git a/batcher/storage/batcher_storage_ghostnet.mligo b/batcher/storage/batcher_storage_ghostnet.mligo new file mode 100644 index 00000000..545893b6 --- /dev/null +++ b/batcher/storage/batcher_storage_ghostnet.mligo @@ -0,0 +1,23 @@ +#import "../batcher.mligo" "Batcher" +let meta : bytes = + 0x68747470733a2f2f697066732e6763702e6d617269676f6c642e6465762f697066732f516d56375a534b6358324d4e75656938745a3268723555484d5a66737039476b375675345878766d6246734a4e45 + +let f(_:unit) : Batcher.Storage.t = { + metadata = (Big_map.empty : Batcher.metadata); + rates_current = (Big_map.empty : Batcher.rates_current); + batch_set = { + current_batch_indices = (Map.empty : (string,nat) map); + batches = (Big_map.empty : (nat,Batcher.batch) big_map); + }; + last_order_number = 0n; + user_batch_ordertypes = (Big_map.empty: Batcher.user_batch_ordertypes); + fee_in_mutez = 10_000mutez; + fee_recipient = ("tz1burnburnburnburnburnburnburjAYjjX" : address); + administrator = ("tz1ca4batAsNxMYab3mUK5H4QRjY8drV4ViL" : address); + marketmaker = ("KT1XKvKiTTj8N6WKv3MhnZhFjZopFGQGBTdT" : address); + tokenmanager = ("KT1SG9z3pU1cNh8dSranm5C5HXWphWi2pLwx" : address); + limit_on_tokens_or_pairs = 10n; + liquidity_injection_limit_in_seconds = 420n; + deposit_time_window_in_seconds = 600n; +} + diff --git a/batcher/storage/initial_storage_mainnet.mligo b/batcher/storage/batcher_storage_mainnet.mligo similarity index 98% rename from batcher/storage/initial_storage_mainnet.mligo rename to batcher/storage/batcher_storage_mainnet.mligo index 1a227742..4bfe8842 100644 --- a/batcher/storage/initial_storage_mainnet.mligo +++ b/batcher/storage/batcher_storage_mainnet.mligo @@ -74,5 +74,6 @@ let f (_ : unit) : Batcher.Storage.t = administrator = ("tz1aSL2gjFnfh96Xf1Zp4T36LxbzKuzyvVJ4" : address); marketmaker = ("tz1aSL2gjFnfh96Xf1Zp4T36LxbzKuzyvVJ4" : address); limit_on_tokens_or_pairs = 10n; + liquidity_injection_limit_in_seconds = 420n; deposit_time_window_in_seconds = 600n } diff --git a/batcher/storage/btctz_vault_storage_ghostnet.mligo b/batcher/storage/btctz_vault_storage_ghostnet.mligo new file mode 100644 index 00000000..99bb9e49 --- /dev/null +++ b/batcher/storage/btctz_vault_storage_ghostnet.mligo @@ -0,0 +1,22 @@ +#import "../vault.mligo" "Vault" +#import "../types.mligo" "Types" +let f(_:unit) : Vault.Vault.storage = { + administrator = ("tz1ca4batAsNxMYab3mUK5H4QRjY8drV4ViL" : address); + batcher = ("tz1ca4batAsNxMYab3mUK5H4QRjY8drV4ViL" : address); + marketmaker = ("tz1ca4batAsNxMYab3mUK5H4QRjY8drV4ViL" : address); + tokenmanager = ("KT1SG9z3pU1cNh8dSranm5C5HXWphWi2pLwx" : address); + total_shares = 0n; + native_token = { + token = { + token_id = 0n; + name = "BTCtz"; + address = Some(("KT1ErLEYVsxqHxLgLucXViq5DYrtSyDuSFTe" : address)); + decimals = 8n; + standard = Some "FA2 token" + }; + amount = 0n; + }; + foreign_tokens = (Map.empty:(string, Vault.token_amount) map ); + vault_holdings = Types.VaultHoldings.empty ; +} + diff --git a/batcher/storage/eurl_vault_storage_ghostnet.mligo b/batcher/storage/eurl_vault_storage_ghostnet.mligo new file mode 100644 index 00000000..02b86fd0 --- /dev/null +++ b/batcher/storage/eurl_vault_storage_ghostnet.mligo @@ -0,0 +1,22 @@ +#import "../vault.mligo" "Vault" +#import "../types.mligo" "Types" +let f(_:unit) : Vault.Vault.storage = { + administrator = ("tz1ca4batAsNxMYab3mUK5H4QRjY8drV4ViL" : address); + batcher = ("tz1ca4batAsNxMYab3mUK5H4QRjY8drV4ViL" : address); + marketmaker = ("tz1ca4batAsNxMYab3mUK5H4QRjY8drV4ViL" : address); + tokenmanager = ("KT1SG9z3pU1cNh8dSranm5C5HXWphWi2pLwx" : address); + total_shares = 0n; + native_token = { + token = { + token_id = 0n; + name = "EURL"; + address = Some(("KT1RcHjqDWWycYQGrz4KBYoGZSMmMuVpkmuS" : address)); + decimals = 6n; + standard = Some "FA2 token" + }; + amount = 0n; + }; + foreign_tokens = (Map.empty:(string, Vault.token_amount) map ); + vault_holdings = Types.VaultHoldings.empty ; +} + diff --git a/batcher/storage/marketmaker_storage_ghostnet.mligo b/batcher/storage/marketmaker_storage_ghostnet.mligo index 37a02041..9d83a352 100644 --- a/batcher/storage/marketmaker_storage_ghostnet.mligo +++ b/batcher/storage/marketmaker_storage_ghostnet.mligo @@ -1,182 +1,11 @@ #import "../marketmaker.mligo" "MarketMaker" -let f(_:unit) : MarketMaker.Storage.t = { - metadata = (Big_map.empty : MarketMaker.metadata); - valid_tokens = Map.literal [ - (("tzBTC"), { - token_id = 0n; - name = "tzBTC"; - address = Some(("KT1P8RdJ5MfHMK5phKJ5JsfNfask5v2b2NQS" : address)); - decimals = 8n; - standard = Some "FA1.2 token" - }); - (("BTCtz"), { - token_id = 0n; - name = "BTCtz"; - address = Some(("KT1ErLEYVsxqHxLgLucXViq5DYrtSyDuSFTe" : address)); - decimals = 8n; - standard = Some "FA2 token" - }); - (("EURL"),{ - token_id = 0n; - name = "EURL"; - address = Some(("KT1RcHjqDWWycYQGrz4KBYoGZSMmMuVpkmuS" : address)); - decimals = 6n; - standard = Some "FA2 token" - }); - (("USDT"),{ - token_id = 0n; - name = "USDT"; - address = Some(("KT1WNrZ7pEbpmYBGPib1e7UVCeC6GA6TkJYR" : address)); - decimals = 6n; - standard = Some "FA2 token" - }); - (("USDtz"),{ - token_id = 0n; - name = "USDtz"; - address = Some(("KT1B8tP5Q8Cb7HctLfxt4MVk2cWouHFrnbjW" : address)); - decimals = 6n; - standard = Some "FA1.2 token" - }) - ]; - valid_swaps = Map.literal [ - ("tzBTC/USDT", { - swap = { - from = "tzBTC"; - to = "USDT"; - }; - oracle_address = ("KT1DG2g5DPYWqyHKGpRL579YkYZwJxibwaAZ": address); - oracle_asset_name = "BTC-USDT"; - oracle_precision = 6n; - is_disabled_for_deposits = false - } - ); - ("BTCtz/USDtz", { - swap = { - from = "BTCtz"; - to = "USDtz"; - }; - oracle_address = ("KT1DG2g5DPYWqyHKGpRL579YkYZwJxibwaAZ": address); - oracle_asset_name = "BTC-USDT"; - oracle_precision = 6n; - is_disabled_for_deposits = false - } - ); - ("tzBTC/USDtz", { - swap = { - from = "tzBTC"; - to = "USDtz"; - }; - oracle_address = ("KT1DG2g5DPYWqyHKGpRL579YkYZwJxibwaAZ": address); - oracle_asset_name = "BTC-USDT"; - oracle_precision = 6n; - is_disabled_for_deposits = false - } - ); - ("BTCtz/USDT", { - swap = { - from = "BTCtz"; - to = "USDT"; - }; - oracle_address = ("KT1DG2g5DPYWqyHKGpRL579YkYZwJxibwaAZ": address); - oracle_asset_name = "BTC-USDT"; - oracle_precision = 6n; - is_disabled_for_deposits = false - } - ); - ("tzBTC/EURL", { - swap = { - from = "tzBTC"; - to = "EURL"; - }; - oracle_address = ("KT1DG2g5DPYWqyHKGpRL579YkYZwJxibwaAZ": address); - oracle_asset_name = "BTC-EUR"; - oracle_precision = 6n; - is_disabled_for_deposits = false - } - ) - ]; +let f(_:unit) : MarketMaker.MarketMaker.storage = { batcher = ("KT1LhTpwSGcFAUUM3JYjW8XW74UHP82YzERy" : address); administrator = ("tz1ca4batAsNxMYab3mUK5H4QRjY8drV4ViL" : address); - vaults = Big_map.literal [ - ("tzBTC", { - total_shares = 0n; - holdings = (Set.empty: nat set); - native_token = { - token = { - token_id = 0n; - name = "tzBTC"; - address = Some(("KT1P8RdJ5MfHMK5phKJ5JsfNfask5v2b2NQS" : address)); - decimals = 8n; - standard = Some "FA1.2 token" - }; - amount= 0n; - }; - foreign_tokens = (Map.empty: MarketMaker.token_amount_map); - }); - ("BTCtz", { - total_shares = 0n; - holdings = (Set.empty: nat set); - native_token = { - token = { - token_id = 0n; - name = "BTCtz"; - address = Some(("KT1ErLEYVsxqHxLgLucXViq5DYrtSyDuSFTe" : address)); - decimals = 8n; - standard = Some "FA2 token" - }; - amount= 0n; - }; - foreign_tokens = (Map.empty: MarketMaker.token_amount_map); - }); - ("EURL", { - total_shares = 0n; - holdings = (Set.empty: nat set); - native_token = { - token = { - token_id = 0n; - name = "EURL"; - address = Some(("KT1RcHjqDWWycYQGrz4KBYoGZSMmMuVpkmuS" : address)); - decimals = 6n; - standard = Some "FA2 token" - }; - amount= 0n; - }; - foreign_tokens = (Map.empty: MarketMaker.token_amount_map); - }); - ("USDtz", { - total_shares = 0n; - holdings = (Set.empty: nat set); - native_token = { - token = { - token_id = 0n; - name = "USDtz"; - address = Some(("KT1B8tP5Q8Cb7HctLfxt4MVk2cWouHFrnbjW" : address)); - decimals = 6n; - standard = Some "FA1.2 token" - }; - amount= 0n; - }; - foreign_tokens = (Map.empty: MarketMaker.token_amount_map); - }); - ("USDT", { - total_shares = 0n; - holdings = (Set.empty: nat set); - native_token = { - token = { - token_id = 0n; - name = "USDT"; - address = Some(("KT1WNrZ7pEbpmYBGPib1e7UVCeC6GA6TkJYR" : address)); - decimals = 6n; - standard = Some "FA2 token" - }; - amount= 0n; - }; - foreign_tokens = (Map.empty: MarketMaker.token_amount_map); - }) - ]; - limit_on_tokens_or_pairs = 10n; - last_holding_id = 0n; - user_holdings = (Big_map.empty: MarketMaker.user_holdings); - vault_holdings = (Big_map.empty: MarketMaker.vault_holdings); + tokenmanager = ("tz1ca4batAsNxMYab3mUK5H4QRjY8drV4ViL" : address); + vaults = { + keys = (Set.empty: string set); + values = (Big_map.empty: (string,address) big_map); + }; } diff --git a/batcher/storage/marketmaker_storage_mainnet.mligo b/batcher/storage/marketmaker_storage_mainnet.mligo deleted file mode 100644 index cf770de2..00000000 --- a/batcher/storage/marketmaker_storage_mainnet.mligo +++ /dev/null @@ -1,59 +0,0 @@ -#import "../marketmaker.mligo" "MarketMaker" - -let f(_:unit) : MarketMaker.Storage.t = { - metadata = (Big_map.empty : MarketMaker.metadata); - valid_tokens = Map.literal [ - (("tzBTC"), { - token_id = 0n; - name = "tzBTC"; - address = Some(("KT1P8RdJ5MfHMK5phKJ5JsfNfask5v2b2NQS" : address)); - decimals = 8n; - standard = Some "FA1.2 token" - }); - (("EURL"),{ - token_id = 0n; - name = "EURL"; - address = Some(("KT1RcHjqDWWycYQGrz4KBYoGZSMmMuVpkmuS" : address)); - decimals = 6n; - standard = Some "FA2 token" - }); - (("USDT"),{ - token_id = 0n; - name = "USDT"; - address = Some(("KT1WNrZ7pEbpmYBGPib1e7UVCeC6GA6TkJYR" : address)); - decimals = 6n; - standard = Some "FA2 token" - }) - ]; - valid_swaps = Map.literal [ - ("tzBTC/USDT", { - swap = { - from = "tzBTC"; - to = "USDT"; - }; - oracle_address = ("KT1DG2g5DPYWqyHKGpRL579YkYZwJxibwaAZ": address); - oracle_asset_name = "BTC-USDT"; - oracle_precision = 6n; - is_disabled_for_deposits = false - } - ); - ("tzBTC/EURL", { - swap = { - from = "tzBTC"; - to = "EURL"; - }; - oracle_address = ("KT1DG2g5DPYWqyHKGpRL579YkYZwJxibwaAZ": address); - oracle_asset_name = "BTC-EUR"; - oracle_precision = 6n; - is_disabled_for_deposits = false - } - ) - ]; - batcher = ("tz1burnburnburnburnburnburnburjAYjjX" : address); - administrator = ("tz1aSL2gjFnfh96Xf1Zp4T36LxbzKuzyvVJ4" : address); - vaults = (Big_map.empty: MarketMaker.market_vaults); - limit_on_tokens_or_pairs = 10n; - last_holding_id = 0n; - user_holdings = (Big_map.empty: MarketMaker.user_holdings); - vault_holdings = (Big_map.empty: MarketMaker.vault_holdings); -} diff --git a/batcher/storage/initial_storage_ghostnet.mligo b/batcher/storage/tokenmanager_storage_ghostnet.mligo similarity index 75% rename from batcher/storage/initial_storage_ghostnet.mligo rename to batcher/storage/tokenmanager_storage_ghostnet.mligo index e4036021..f184eb98 100644 --- a/batcher/storage/initial_storage_ghostnet.mligo +++ b/batcher/storage/tokenmanager_storage_ghostnet.mligo @@ -1,10 +1,8 @@ -#import "../batcher.mligo" "Batcher" -let meta : bytes = - 0x68747470733a2f2f697066732e6763702e6d617269676f6c642e6465762f697066732f516d56375a534b6358324d4e75656938745a3268723555484d5a66737039476b375675345878766d6246734a4e45 - -let f(_:unit) : Batcher.Storage.t = { - metadata = (Big_map.empty : Batcher.metadata); - valid_tokens = Map.literal [ +#import "../tokenmanager.mligo" "TokenManager" +let f(_:unit) : TokenManager.TokenManager.storage = { + valid_tokens = { + keys = Set.literal ["tzBTC";"BTCtz";"EURL";"USDT";"USDtz"]; + values = Big_map.literal [ (("tzBTC"), { token_id = 0n; name = "tzBTC"; @@ -41,7 +39,10 @@ let f(_:unit) : Batcher.Storage.t = { standard = Some "FA1.2 token" }) ]; - valid_swaps = Map.literal [ + }; + valid_swaps = { + keys = Set.literal ["tzBTC/USDT";"BTCtz/USDtz";"tzBTC/USDtz";"BTCtz/USDT";"tzBTC/EURL"] ; + values = Big_map.literal [ ("tzBTC/USDT", { swap = { from = "tzBTC"; @@ -98,18 +99,8 @@ let f(_:unit) : Batcher.Storage.t = { } ) ]; - rates_current = (Big_map.empty : Batcher.rates_current); - batch_set = { - current_batch_indices = (Map.empty : (string,nat) map); - batches = (Big_map.empty : (nat,Batcher.batch) big_map); }; - last_order_number = 0n; - user_batch_ordertypes = (Big_map.empty: Batcher.user_batch_ordertypes); - fee_in_mutez = 10_000mutez; - fee_recipient = ("tz1burnburnburnburnburnburnburjAYjjX" : address); administrator = ("tz1ca4batAsNxMYab3mUK5H4QRjY8drV4ViL" : address); - marketmaker = ("KT1XKvKiTTj8N6WKv3MhnZhFjZopFGQGBTdT" : address); limit_on_tokens_or_pairs = 10n; - deposit_time_window_in_seconds = 600n; } diff --git a/batcher/storage/tzbtc_vault_storage_ghostnet.mligo b/batcher/storage/tzbtc_vault_storage_ghostnet.mligo new file mode 100644 index 00000000..e766fc0b --- /dev/null +++ b/batcher/storage/tzbtc_vault_storage_ghostnet.mligo @@ -0,0 +1,22 @@ +#import "../vault.mligo" "Vault" +#import "../types.mligo" "Types" +let f(_:unit) : Vault.Vault.storage = { + administrator = ("tz1ca4batAsNxMYab3mUK5H4QRjY8drV4ViL" : address); + batcher = ("tz1ca4batAsNxMYab3mUK5H4QRjY8drV4ViL" : address); + marketmaker = ("tz1ca4batAsNxMYab3mUK5H4QRjY8drV4ViL" : address); + tokenmanager = ("KT1SG9z3pU1cNh8dSranm5C5HXWphWi2pLwx" : address); + total_shares = 0n; + native_token = { + token = { + token_id = 0n; + name = "tzBTC"; + address = Some(("KT1P8RdJ5MfHMK5phKJ5JsfNfask5v2b2NQS" : address)); + decimals = 8n; + standard = Some "FA1.2 token" + }; + amount = 0n; + }; + foreign_tokens = (Map.empty:(string, Vault.token_amount) map ); + vault_holdings = Types.VaultHoldings.empty ; +} + diff --git a/batcher/storage/usdt_vault_storage_ghostnet.mligo b/batcher/storage/usdt_vault_storage_ghostnet.mligo new file mode 100644 index 00000000..cfd09ca2 --- /dev/null +++ b/batcher/storage/usdt_vault_storage_ghostnet.mligo @@ -0,0 +1,22 @@ +#import "../vault.mligo" "Vault" +#import "../types.mligo" "Types" +let f(_:unit) : Vault.Vault.storage = { + administrator = ("tz1ca4batAsNxMYab3mUK5H4QRjY8drV4ViL" : address); + batcher = ("tz1ca4batAsNxMYab3mUK5H4QRjY8drV4ViL" : address); + marketmaker = ("tz1ca4batAsNxMYab3mUK5H4QRjY8drV4ViL" : address); + tokenmanager = ("KT1SG9z3pU1cNh8dSranm5C5HXWphWi2pLwx" : address); + total_shares = 0n; + native_token = { + token = { + token_id = 0n; + name = "USDT"; + address = Some(("KT1WNrZ7pEbpmYBGPib1e7UVCeC6GA6TkJYR" : address)); + decimals = 6n; + standard = Some "FA2 token" + }; + amount = 0n; + }; + foreign_tokens = (Map.empty:(string, Vault.token_amount) map ); + vault_holdings = Types.VaultHoldings.empty ; +} + diff --git a/batcher/storage/usdtz_vault_storage_ghostnet.mligo b/batcher/storage/usdtz_vault_storage_ghostnet.mligo new file mode 100644 index 00000000..e614c263 --- /dev/null +++ b/batcher/storage/usdtz_vault_storage_ghostnet.mligo @@ -0,0 +1,22 @@ +#import "../vault.mligo" "Vault" +#import "../types.mligo" "Types" +let f(_:unit) : Vault.Vault.storage = { + administrator = ("tz1ca4batAsNxMYab3mUK5H4QRjY8drV4ViL" : address); + batcher = ("tz1ca4batAsNxMYab3mUK5H4QRjY8drV4ViL" : address); + marketmaker = ("tz1ca4batAsNxMYab3mUK5H4QRjY8drV4ViL" : address); + tokenmanager = ("KT1SG9z3pU1cNh8dSranm5C5HXWphWi2pLwx" : address); + total_shares = 0n; + native_token = { + token = { + token_id = 0n; + name = "USDtz"; + address = Some(("KT1B8tP5Q8Cb7HctLfxt4MVk2cWouHFrnbjW" : address)); + decimals = 6n; + standard = Some "FA1.2 token" + }; + amount = 0n; + }; + foreign_tokens = (Map.empty:(string, Vault.token_amount) map ); + vault_holdings = Types.VaultHoldings.empty ; +} + diff --git a/batcher/test/common/helpers.mligo b/batcher/test/common/helpers.mligo index e4a31b0a..11cb7cba 100644 --- a/batcher/test/common/helpers.mligo +++ b/batcher/test/common/helpers.mligo @@ -1,34 +1,47 @@ #import "../../batcher.mligo" "Batcher" #import "../../marketmaker.mligo" "MarketMaker" +#import "../../tokenmanager.mligo" "TokenManager" +#import "../../vault.mligo" "Vault" #import "../tokens/fa12/main.mligo" "TZBTC" #import "../tokens/fa2/main.mligo" "USDT" #import "../tokens/fa2/main.mligo" "EURL" #import "../mocks/oracle.mligo" "Oracle" #import "./storage.mligo" "TestStorage" #import "./utils.mligo" "TestUtils" +#import "../../utils.mligo" "CommonUtils" +#import "../../types.mligo" "CommonTypes" #import "./batch.mligo" "TestBatch" #import "ligo-breathalyzer/lib/lib.mligo" "Breath" #import "@ligo/math-lib/rational/rational.mligo" "Rational" type originated = Breath.Contract.originated -type originated_contract = (Batcher.entrypoint, Batcher.storage) originated -type originated_mm_contract = (MarketMaker.entrypoint, MarketMaker.Storage.t) originated +type originated_batcher_contract = (Batcher.entrypoint, Batcher.storage) originated +type originated_mm_contract = (MarketMaker.entrypoint, MarketMaker.MarketMaker.storage) originated +type originated_tm_contract = (TokenManager.entrypoint, TokenManager.TokenManager.storage) originated +type originated_vault_contract = (Vault.entrypoint, Vault.Vault.storage) originated +type originated_tzbtc_contract = (TZBTC.parameter, TZBTC.storage) originated +type originated_usdt_contract = (USDT.parameter, USDT.storage) originated +type originated_eurl_contract = (EURL.parameter, EURL.storage) originated +type originated_oracle_contract = (Oracle.entrypoint, Oracle.Oracle.storage) originated type swap = Batcher.swap type side = Batcher.side type storage = Batcher.Storage.t type tolerance = Batcher.tolerance -type valid_tokens = Batcher.valid_tokens type level = Breath.Logger.level type test_contracts = { batcher: (Batcher.entrypoint, Batcher.storage) originated; - marketmaker: (MarketMaker.entrypoint, MarketMaker.Storage.t) originated; - oracle: (Oracle.entrypoint, Oracle.storage) originated; - additional_oracle: (Oracle.entrypoint, Oracle.storage) originated; - tzbtc: (TZBTC.parameter, TZBTC.storage) originated; - usdt: (USDT.parameter, USDT.storage) originated; - eurl: (EURL.parameter, EURL.storage) originated; + marketmaker: (MarketMaker.entrypoint, MarketMaker.MarketMaker.storage) originated; + tokenmanager: (TokenManager.entrypoint, TokenManager.TokenManager.storage) originated; + oracle: originated_oracle_contract; + additional_oracle: originated_oracle_contract; + tzbtc: originated_tzbtc_contract; + usdt: originated_usdt_contract; + eurl: originated_eurl_contract; + tzbtc_vault: (Vault.entrypoint, Vault.Vault.storage) originated; + usdt_vault: (Vault.entrypoint, Vault.Vault.storage) originated; + eurl_vault: (Vault.entrypoint, Vault.Vault.storage) originated; } type context = { @@ -59,7 +72,7 @@ let originate_module ; originated_address = address } let originate_oracle - (level: Breath.Logger.level) = + (level: Breath.Logger.level) : originated_oracle_contract = let storage = TestStorage.oracle_initial_storage in TestUtils.originate_oracle storage level @@ -83,28 +96,83 @@ let originate_eurl let storage = TestStorage.fa2_initial_storage trader in TestUtils.originate_eurl storage level -let originate +let originate_tokens (level: Breath.Logger.level) (tzbtc_trader: Breath.Context.actor) (usdt_trader: Breath.Context.actor) (eurl_trader: Breath.Context.actor) = + let tzbtc = originate_tzbtc tzbtc_trader usdt_trader eurl_trader level in + let usdt = originate_usdt usdt_trader level in + let eurl = originate_eurl eurl_trader level in + (tzbtc,usdt, eurl) + +let originate_tm + (level: Breath.Logger.level) + (tzbtc_trader: Breath.Context.actor) + (usdt_trader: Breath.Context.actor) + (eurl_trader: Breath.Context.actor) + (admin: Breath.Context.actor): (originated_tm_contract * originated_oracle_contract * originated_oracle_contract * originated_tzbtc_contract * originated_usdt_contract * originated_eurl_contract) = + let (tzbtc,usdt,eurl) = originate_tokens level tzbtc_trader usdt_trader eurl_trader in let oracle = originate_oracle level in let additional_oracle = originate_oracle level in + let initial_tm_storage = TestStorage.initial_tokenmanager_storage admin.address oracle.originated_address tzbtc.originated_address usdt.originated_address eurl.originated_address in + let tm =TestUtils.originate_tm initial_tm_storage level in + (tm,oracle,additional_oracle,tzbtc,usdt,eurl) + +let originate_vault_contract + (token:CommonTypes.token) + (amount:nat) + (batcher: originated_batcher_contract) + (marketmaker: originated_mm_contract ) + (tm:originated_tm_contract ) + (admin: Breath.Context.actor) + (level: Breath.Logger.level): originated_vault_contract = + let stor = TestStorage.initial_vault_storage token admin.address batcher.originated_address marketmaker.originated_address tm.originated_address amount in + TestUtils.originate_vault token.name stor level + +let originate_vault_contracts + (batcher: originated_batcher_contract) + (marketmaker: originated_mm_contract ) + (tm:originated_tm_contract ) + (admin: Breath.Context.actor) + (level: Breath.Logger.level): (originated_vault_contract * originated_vault_contract * originated_vault_contract)= + let tokens = CommonUtils.TokenManagerUtils.get_valid_tokens tm.originated_address in + let tzbtc_token = Option.unopt (Map.find_opt "tzBTC" tokens) in + let usdt_token = Option.unopt (Map.find_opt "USDT" tokens) in + let eurl_token = Option.unopt (Map.find_opt "EURL" tokens) in + let tzbtc_vault = originate_vault_contract tzbtc_token 0n batcher marketmaker tm admin level in + let usdt_vault = originate_vault_contract usdt_token 0n batcher marketmaker tm admin level in + let eurl_vault = originate_vault_contract eurl_token 0n batcher marketmaker tm admin level in + (tzbtc_vault,usdt_vault, eurl_vault) + + +let originate_with_admin + (level: Breath.Logger.level) + (tzbtc_trader: Breath.Context.actor) + (usdt_trader: Breath.Context.actor) + (eurl_trader: Breath.Context.actor) + (admin: Breath.Context.actor) = let tzbtc = originate_tzbtc tzbtc_trader usdt_trader eurl_trader level in let usdt = originate_usdt usdt_trader level in let eurl = originate_eurl eurl_trader level in - let initial_storage = TestStorage.initial_storage oracle.originated_address tzbtc.originated_address usdt.originated_address eurl.originated_address in + let (tm,oracle,additional_oracle,tzbtc,usdt,eurl) = originate_tm level tzbtc_trader usdt_trader eurl_trader admin in + let initial_storage = TestStorage.initial_storage_with_admin oracle.originated_address tzbtc.originated_address usdt.originated_address eurl.originated_address admin.address in let batcher = TestUtils.originate initial_storage level in - let initial_mm_storage: MarketMaker.Storage.t = TestStorage.initial_mm_storage oracle.originated_address tzbtc.originated_address usdt.originated_address eurl.originated_address initial_storage.administrator in + let initial_mm_storage: MarketMaker.MarketMaker.storage = TestStorage.initial_mm_storage oracle.originated_address tzbtc.originated_address usdt.originated_address eurl.originated_address admin.address batcher.originated_address tm.originated_address in let mm: originated_mm_contract = TestUtils.originate_mm initial_mm_storage level in + let (tzbtc_vault,usdt_vault, eurl_vault) = originate_vault_contracts batcher mm tm admin level in { batcher = batcher; marketmaker = mm; + tokenmanager = tm; oracle = oracle; additional_oracle = additional_oracle; tzbtc = tzbtc; usdt = usdt; eurl = eurl; + tzbtc_vault = tzbtc_vault; + usdt_vault = usdt_vault; + eurl_vault = eurl_vault; } let originate_with_admin_and_fee_recipient @@ -114,24 +182,29 @@ let originate_with_admin_and_fee_recipient (eurl_trader: Breath.Context.actor) (admin: Breath.Context.actor) (fee_recipient: address) = - let oracle = originate_oracle level in - let additional_oracle = originate_oracle level in let tzbtc = originate_tzbtc tzbtc_trader usdt_trader eurl_trader level in let usdt = originate_usdt usdt_trader level in let eurl = originate_eurl eurl_trader level in + let (tm,oracle,additional_oracle,tzbtc,usdt,eurl) = originate_tm level tzbtc_trader usdt_trader eurl_trader admin in let initial_storage = TestStorage.initial_storage_with_admin_and_fee_recipient oracle.originated_address tzbtc.originated_address usdt.originated_address eurl.originated_address admin.address fee_recipient in let batcher = TestUtils.originate initial_storage level in - let initial_mm_storage : MarketMaker.Storage.t = TestStorage.initial_mm_storage_with_admin oracle.originated_address tzbtc.originated_address usdt.originated_address eurl.originated_address admin.address batcher.originated_address in + let initial_mm_storage = TestStorage.initial_mm_storage oracle.originated_address tzbtc.originated_address usdt.originated_address eurl.originated_address admin.address batcher.originated_address tm.originated_address in let mm : originated_mm_contract = TestUtils.originate_mm initial_mm_storage level in - { + let (tzbtc_vault,usdt_vault, eurl_vault) = originate_vault_contracts batcher mm tm admin level in + let contracts: test_contracts = { batcher = batcher; marketmaker = mm; + tokenmanager = tm; oracle = oracle; additional_oracle = additional_oracle; tzbtc = tzbtc; usdt = usdt; eurl = eurl; - } + tzbtc_vault = tzbtc_vault; + usdt_vault = usdt_vault; + eurl_vault = eurl_vault; + } in + contracts let originate_with_batch_for_clearing (level: Breath.Logger.level) @@ -139,12 +212,12 @@ let originate_with_batch_for_clearing (usdt_trader: Breath.Context.actor) (eurl_trader: Breath.Context.actor) (batch: Batcher.batch) + (admin: Breath.Context.actor) (pair: string) = - let oracle = originate_oracle level in - let additional_oracle = originate_oracle level in let tzbtc = originate_tzbtc tzbtc_trader usdt_trader eurl_trader level in let usdt = originate_usdt usdt_trader level in let eurl = originate_eurl eurl_trader level in + let (tm,oracle,additional_oracle,tzbtc,usdt,eurl) = originate_tm level tzbtc_trader usdt_trader eurl_trader admin in let initial_storage = TestStorage.initial_storage oracle.originated_address tzbtc.originated_address usdt.originated_address eurl.originated_address in let batch_set = initial_storage.batch_set in let cbi = Map.add pair 1n batch_set.current_batch_indices in @@ -156,20 +229,28 @@ let originate_with_batch_for_clearing let initial_storage = { initial_storage with batch_set = batch_set; } in let batcher = TestUtils.originate initial_storage level in + let initial_mm_storage = TestStorage.initial_mm_storage oracle.originated_address tzbtc.originated_address usdt.originated_address eurl.originated_address admin.address batcher.originated_address tm.originated_address in + let mm : originated_mm_contract = TestUtils.originate_mm initial_mm_storage level in + let (tzbtc_vault,usdt_vault, eurl_vault) = originate_vault_contracts batcher mm tm admin level in { batcher = batcher; + marketmaker = mm; + tokenmanager = tm; oracle = oracle; additional_oracle = additional_oracle; tzbtc = tzbtc; usdt = usdt; eurl = eurl; + tzbtc_vault = tzbtc_vault; + usdt_vault = usdt_vault; + eurl_vault = eurl_vault; } let test_context (level: Breath.Logger.level) = let (_, (btc_trader, usdt_trader, eurl_trader)) = Breath.Context.init_default () in let fee_recipient_address = usdt_trader.address in - let contracts = originate_with_admin_and_fee_recipient level btc_trader usdt_trader eurl_trader eurl_trader fee_recipient_address in + let contracts:test_contracts = originate_with_admin_and_fee_recipient level btc_trader usdt_trader eurl_trader eurl_trader fee_recipient_address in { btc_trader = btc_trader; usdt_trader = usdt_trader; @@ -203,9 +284,9 @@ let create_order (amount: nat) (side: Batcher.side) (tolerance: Batcher.tolerance) - (valid_tokens: Batcher.valid_tokens) : Batcher.external_swap_order = - let fromToken = Map.find from valid_tokens in - let toToken = Map.find to valid_tokens in + (valid_tokens: CommonTypes.ValidTokens.t) : Batcher.external_swap_order = + let fromToken = CommonTypes.ValidTokens.find_or_fail from valid_tokens in + let toToken = CommonTypes.ValidTokens.find_or_fail to valid_tokens in let nside = TestUtils.side_to_nat side in let swap = { from = { @@ -233,28 +314,20 @@ let place_order (amount: nat) (side: Batcher.side) (tolerance: Batcher.tolerance) - (valid_tokens: valid_tokens) = + (valid_tokens: CommonTypes.ValidTokens.t) = let order = create_order from to amount side tolerance valid_tokens in Breath.Context.act_as actor (fun (_u:unit) -> (Breath.Contract.transfer_to contract (Deposit order) fee)) let add_liquidity (actor: Breath.Context.actor) - (contract: originated_mm_contract) - (token_name: string) - (amount: nat) - (valid_tokens: valid_tokens) = - let token = Option.unopt (Map.find_opt token_name valid_tokens) in - let token_amount = { - token = token; - amount = amount; - } in - Breath.Context.act_as actor (fun (_u:unit) -> (Breath.Contract.transfer_to contract (AddLiquidity token_amount) 0tez)) + (contract: originated_vault_contract) + (amount: nat) = + Breath.Context.act_as actor (fun (_u:unit) -> (Breath.Contract.transfer_to contract (AddLiquidity amount) 0tez)) let remove_liquidity (actor: Breath.Context.actor) - (contract: originated_mm_contract) - (token_name: string) = - Breath.Context.act_as actor (fun (_u:unit) -> (Breath.Contract.transfer_to contract (RemoveLiquidity token_name) 0tez)) + (contract: originated_vault_contract) = + Breath.Context.act_as actor (fun (_u:unit) -> (Breath.Contract.transfer_to contract (RemoveLiquidity ()) 0tez)) let expect_last_order_number (storage: storage) @@ -269,13 +342,11 @@ let expect_rate_value | Some r -> Breath.Assert.is_equal "rate value" r.rate rate let get_swap_pair - (contract: originated_contract) - (pair: string): Batcher.valid_swap_reduced option = + (contract: originated_tm_contract) + (pair: string): TokenManager.valid_swap_reduced option = let storage = Breath.Contract.storage_of contract in let valid_swaps = storage.valid_swaps in - match Map.find_opt pair valid_swaps with - | Some p -> Some p - | None -> None + CommonTypes.ValidSwaps.find_opt pair valid_swaps let get_source_update (pair: string) diff --git a/batcher/test/common/storage.mligo b/batcher/test/common/storage.mligo index 98fbacf4..29af287c 100644 --- a/batcher/test/common/storage.mligo +++ b/batcher/test/common/storage.mligo @@ -3,13 +3,17 @@ #import "../tokens/fa12/main.mligo" "TZBTC" #import "../tokens/fa2/main.mligo" "USDT" #import "../tokens/fa2/main.mligo" "EURL" +#import "../../tokenmanager.mligo" "TokenManager" +#import "../../vault.mligo" "Vault" +#import "../../types.mligo" "Types" #import "../mocks/oracle.mligo" "Oracle" #import "ligo-breathalyzer/lib/lib.mligo" "Breath" #import "@ligo/math-lib/rational/rational.mligo" "Rational" type level = Breath.Logger.level type batcher_storage = Batcher.Storage.t -type mm_storage = MarketMaker.Storage.t +type mm_storage = MarketMaker.MarketMaker.storage + let fee_recipient = ("tz1burnburnburnburnburnburnburjAYjjX" : address) let administrator = ("tz1aSL2gjFnfh96Xf1Zp4T36LxbzKuzyvVJ4" : address) @@ -65,7 +69,9 @@ let initial_storage_with_admin_and_fee_recipient (admin: address) (fee_recipient: address): batcher_storage = { metadata = (Big_map.empty : Batcher.metadata); - valid_tokens = Map.literal [ + valid_tokens = { + keys = Set.literal ["tzBTC"; "EURL"; "USDT"]; + values = Big_map.literal [ (("tzBTC"), { token_id = 0n; name = "tzBTC"; @@ -87,8 +93,10 @@ let initial_storage_with_admin_and_fee_recipient decimals = 6n; standard = Some "FA2 token" }) - ]; - valid_swaps = Map.literal [ + ];}; + valid_swaps = { + keys = Set.literal ["tzBTC/USDT"]; + values = Big_map.literal [ ("tzBTC/USDT", { swap = { from = "tzBTC"; @@ -101,6 +109,7 @@ let initial_storage_with_admin_and_fee_recipient } ) ]; + }; rates_current = (Big_map.empty : Batcher.rates_current); batch_set = { current_batch_indices = (Map.empty : (string,nat) map); @@ -117,6 +126,13 @@ let initial_storage_with_admin_and_fee_recipient } +let initial_storage_with_admin + (oracle_address: address) + (tzbtc_address: address) + (usdt_address:address) + (eurl_address:address) + (admin:address) : batcher_storage = + initial_storage_with_admin_and_fee_recipient oracle_address tzbtc_address usdt_address eurl_address admin fee_recipient let initial_storage @@ -126,15 +142,38 @@ let initial_storage (eurl_address:address) : batcher_storage = initial_storage_with_admin_and_fee_recipient oracle_address tzbtc_address usdt_address eurl_address administrator fee_recipient -let initial_mm_storage_with_admin +let initial_mm_storage (oracle_address: address) (tzbtc_address: address) (usdt_address:address) (eurl_address:address) (admin: address) - (batcher: address): mm_storage = { - metadata = (Big_map.empty : MarketMaker.metadata); - valid_tokens = Map.literal [ + (batcher: address) + (tokenmanager: address): mm_storage = { + administrator = admin; + batcher = batcher; + tokenmanager = tokenmanager; + vaults = { + keys = Set.literal ["tzBTC";"EURL";"USDT"]; + values = Big_map.literal [ + ("tzBTC", tzbtc_address); + ("EURL", eurl_address); + ("USDT", usdt_address); + ] ; + }; +} + +let initial_tokenmanager_storage + (administrator: address) + (oracle_address: address) + (tzbtc_address: address) + (usdt_address:address) + (eurl_address:address): TokenManager.TokenManager.storage = + { + valid_tokens = { + keys = Set.literal ["tzBTC";"EURL";"USDT"]; + values = Big_map.literal [ + (("tzBTC"), { token_id = 0n; name = "tzBTC"; @@ -155,41 +194,62 @@ let initial_mm_storage_with_admin address = Some(usdt_address); decimals = 6n; standard = Some "FA2 token" - }) + }); ]; - valid_swaps = Map.literal [ + }; + valid_swaps = { + keys = Set.literal ["tzBTC/USDT";"tzBTC/EURL"] ; + values = Big_map.literal [ ("tzBTC/USDT", { swap = { from = "tzBTC"; to = "USDT"; }; - oracle_address = oracle_address ; + oracle_address = oracle_address; oracle_asset_name = "BTC-USDT"; oracle_precision = 6n; is_disabled_for_deposits = false } + ); + ("tzBTC/EURL", { + swap = { + from = "tzBTC"; + to = "EURL"; + }; + oracle_address = oracle_address; + oracle_asset_name = "BTC-EUR"; + oracle_precision = 6n; + is_disabled_for_deposits = false + } ) ]; - administrator = admin; + }; + administrator = administrator; limit_on_tokens_or_pairs = 10n; - batcher = batcher; - vaults = (Big_map.empty: MarketMaker.market_vaults); - last_holding_id = 0n; - user_holdings = (Big_map.empty: MarketMaker.user_holdings); - vault_holdings = (Big_map.empty: MarketMaker.vault_holdings); } - -let initial_mm_storage - (oracle_address: address) - (tzbtc_address: address) - (usdt_address:address) - (eurl_address:address) - (batcher_address:address): mm_storage = - initial_mm_storage_with_admin oracle_address tzbtc_address usdt_address eurl_address administrator batcher_address +let initial_vault_storage + (token:Types.token) + (administrator: address) + (batcher: address) + (market_maker: address) + (tm:address) + (amount: nat): Vault.Vault.storage = { + administrator = administrator; + batcher = batcher; + marketmaker = market_maker; + tokenmanager = tm; + total_shares = 0n; + native_token = { + token = token; + amount = amount; + }; + foreign_tokens = (Map.empty:(string, Vault.token_amount) map ); + vault_holdings = (Big_map.empty: (address, Vault.vault_holding) big_map); + } -let oracle_initial_storage = +let oracle_initial_storage: Oracle.Oracle.storage = Map.literal [ (("BTC-USDT"), { diff --git a/batcher/test/common/utils.mligo b/batcher/test/common/utils.mligo index 727dd697..30a5135a 100644 --- a/batcher/test/common/utils.mligo +++ b/batcher/test/common/utils.mligo @@ -1,4 +1,5 @@ #import "../../batcher.mligo" "Batcher" +#import "../../vault.mligo" "Vault" #import "ligo-breathalyzer/lib/lib.mligo" "Breath" #import "@ligo/math-lib/rational/rational.mligo" "Rational" #import "../tokens/fa12/main.mligo" "TZBTC" @@ -7,17 +8,18 @@ #import "../mocks/oracle.mligo" "Oracle" #import "./storage.mligo" "TestStorage" #import "../../marketmaker.mligo" "MarketMaker" +#import "../../tokenmanager.mligo" "TokenManager" type level = Breath.Logger.level let log = Breath.Logger.log type batcher_storage = Batcher.Storage.t -type mm_storage = MarketMaker.Storage.t +type mm_storage = MarketMaker.MarketMaker.storage type originated = Breath.Contract.originated type valid_swap = Batcher.valid_swap type external_order = Batcher.external_swap_order type side = Batcher.side type tolerance = Batcher.tolerance -type oracle_storage = Oracle.storage +type oracle_storage = Oracle.Oracle.storage type tzbtc_storage = TZBTC.storage type usdt_storage = USDT.storage type eurl_storage = EURL.storage @@ -46,6 +48,41 @@ let originate (storage) (0tez) +let originate_mm +(storage: mm_storage) +(level: level) = + let () = log level storage in + Breath.Contract.originate_uncurried + level + "marketmaker" + (MarketMaker.main) + (storage) + (0tez) + +let originate_tm +(storage: TokenManager.TokenManager.storage) +(level: level) = + let () = log level storage in + Breath.Contract.originate_uncurried + level + "tokenmanager" + (TokenManager.main) + (storage) + (0tez) + +let originate_vault +(name: string) +(storage: Vault.Vault.storage) +(level: level) = + let () = log level storage in + Breath.Contract.originate_uncurried + level + name + (Vault.main) + (storage) + (0tez) + + let originate_mm (storage: mm_storage) (level: level) = @@ -61,10 +98,10 @@ let originate_oracle (storage: oracle_storage) (level: level) = let () = log level storage in - Breath.Contract.originate_module + Breath.Contract.originate_uncurried level "oracle" - (contract_of Oracle) + (Oracle.main) (storage) (0tez) diff --git a/batcher/test/mocks/oracle.mligo b/batcher/test/mocks/oracle.mligo index ea0fabf0..2a836654 100644 --- a/batcher/test/mocks/oracle.mligo +++ b/batcher/test/mocks/oracle.mligo @@ -1,3 +1,6 @@ + +module Oracle = struct + type rate_update = { name: string; value: nat; @@ -10,9 +13,6 @@ type result = (operation list) * storage let no_op (s : storage) : result = (([] : operation list), s) -type entrypoint = - | Update of rate_update - let update (update: rate_update) (storage: storage) : result = @@ -22,15 +22,21 @@ let update in no_op storage +end + + +type entrypoint = + | Update of Oracle.rate_update + [@entry] let main - (action, storage : entrypoint * storage) : result = + (action, storage : entrypoint * Oracle.storage) : Oracle.result = match action with - | Update ru -> update ru storage + | Update ru -> Oracle.update ru storage [@view] -let getPrice (asset, storage : string * storage) = +let getPrice (asset, storage : string * Oracle.storage) = match Map.find_opt asset storage with | None -> failwith "No rate available" | Some r -> (r.timestamp, r.value) diff --git a/batcher/test/test-tokenmanager.mligo b/batcher/test/test-tokenmanager.mligo new file mode 100644 index 00000000..a08d211f --- /dev/null +++ b/batcher/test/test-tokenmanager.mligo @@ -0,0 +1,44 @@ + +#import "ligo-breathalyzer/lib/lib.mligo" "Breath" +#import "./common/helpers.mligo" "Helpers" +#import "./tokenmanager/endpoints/admin/test_change_admin_address.mligo" "Admin_Change_Admin_Address" +#import "./tokenmanager/endpoints/admin/test_change_marketmaker_address.mligo" "Admin_Change_MarketMaker_Address" +#import "./tokenmanager/endpoints/admin/test_enable_disable_swap_pair_for_deposit.mligo" "Admin_Enable_Disable_Swap_Pair" +#import "./tokenmanager/endpoints/admin/test_amend_token_pair_limit.mligo" "Admin_Amend_Token_pair_Limit" +#import "./tokenmanager/endpoints/admin/test_change_oracle_source_of_pair.mligo" "Admin_Change_Oracle_Source_Of_Pair" +#import "./tokenmanager/endpoints/admin/test_add_remove_token_swap_pair.mligo" "Admin_Add_Remove_Token_Swap_Pair" + +let contract_can_be_originated = + Breath.Model.case + "test contract" + "can be originated" + (fun (level: Breath.Logger.level) -> + let () = Breath.Logger.log level "Originate Token Manager contract" in + let (_, (btc_trader, usdt_trader, eurl_trader)) = Breath.Context.init_default () in + let (tm,oracle,additional_oracle,tzbtc,usdt,eurl) = Helpers.originate_tm level btc_trader usdt_trader eurl_trader btc_trader in + let tm_storage = Breath.Contract.storage_of contracts.tokenmanager in + let tm_balance = Breath.Contract.balance_of contracts.tokenmanager in + + Breath.Result.reduce [ + Breath.Assert.is_equal "balance" tm_balance 0tez + ; Helpers.expect_last_order_number tm_storage 0n + ]) + + +let test_suite = + Breath.Model.suite "Suite for Contract" [ + contract_can_be_originated + ] + +let () = + Breath.Model.run_suites Void + [ + test_suite + (* ; Admin_Change_Admin_Address.test_suite *) + ; Admin_Change_MarketMaker_Address.test_suite + ; Admin_Enable_Disable_Swap_Pair.test_suite + ; Admin_Amend_Token_pair_Limit.test_suite + ; Admin_Change_Oracle_Source_Of_Pair.test_suite + ; Admin_Add_Remove_Token_Swap_Pair.test_suite *) + ] + diff --git a/batcher/test/test-vault.mligo b/batcher/test/test-vault.mligo new file mode 100644 index 00000000..e69de29b diff --git a/batcher/test/batcher/endpoints/admin/test_add_remove_token_swap_pair.mligo b/batcher/test/tokenmanager/endpoints/admin/test_add_remove_token_swap_pair.mligo similarity index 96% rename from batcher/test/batcher/endpoints/admin/test_add_remove_token_swap_pair.mligo rename to batcher/test/tokenmanager/endpoints/admin/test_add_remove_token_swap_pair.mligo index 0a4964fa..8a6c1798 100644 --- a/batcher/test/batcher/endpoints/admin/test_add_remove_token_swap_pair.mligo +++ b/batcher/test/tokenmanager/endpoints/admin/test_add_remove_token_swap_pair.mligo @@ -2,14 +2,15 @@ #import "./../../../common/helpers.mligo" "Helpers" #import "../../../../batcher.mligo" "Batcher" #import "../../../../errors.mligo" "Errors" +#import "../../../../types.mligo" "Types" let get_tzbtc_eurl_swap_pair (disabled: bool) (oracle: address) (storage: Batcher.Storage.t): (Batcher.valid_swap * Batcher.valid_swap_reduced) = let valid_tokens = storage.valid_tokens in - let tzbtc = Option.unopt (Map.find_opt "tzBTC" valid_tokens) in - let eurl = Option.unopt (Map.find_opt "EURL" valid_tokens) in + let tzbtc = Option.unopt (Types.ValidTokens.find_opt "tzBTC" valid_tokens) in + let eurl = Option.unopt (Types.ValidTokens.find_opt "EURL" valid_tokens) in let swap : Batcher.swap = { from = { token = tzbtc; @@ -47,12 +48,12 @@ let add_swap_pair_should_succeed_if_user_is_admin = let context = Helpers.test_context level in let batcher = context.contracts.batcher in let bstorage = Breath.Contract.storage_of batcher in - let swap_pair_does_not_already_exist = Map.find_opt "tzBTC/EURL" bstorage.valid_swaps in + let swap_pair_does_not_already_exist = Types.ValidSwaps.find_opt "tzBTC/EURL" bstorage.valid_swaps in let (swap_pair, swap_pair_reduced) = get_tzbtc_eurl_swap_pair true context.contracts.oracle.originated_address bstorage in let act_add_swap_pair = Breath.Context.act_as context.admin (fun (_u:unit) -> (Breath.Contract.transfer_to batcher (Add_token_swap_pair swap_pair) 0tez)) in let new_bstorage = Breath.Contract.storage_of batcher in - let added_swap_pair_reduced = Option.unopt (Map.find_opt "tzBTC/EURL" new_bstorage.valid_swaps) in + let added_swap_pair_reduced = Option.unopt (Types.ValidSwaps.find_opt "tzBTC/EURL" new_bstorage.valid_swaps) in Breath.Result.reduce [ Breath.Assert.is_equal "swap pair should not already exist" None swap_pair_does_not_already_exist diff --git a/batcher/test/batcher/endpoints/admin/test_amend_token_pair_limit.mligo b/batcher/test/tokenmanager/endpoints/admin/test_amend_token_pair_limit.mligo similarity index 100% rename from batcher/test/batcher/endpoints/admin/test_amend_token_pair_limit.mligo rename to batcher/test/tokenmanager/endpoints/admin/test_amend_token_pair_limit.mligo diff --git a/batcher/test/tokenmanager/endpoints/admin/test_change_admin_address.mligo b/batcher/test/tokenmanager/endpoints/admin/test_change_admin_address.mligo new file mode 100644 index 00000000..a89a4a4c --- /dev/null +++ b/batcher/test/tokenmanager/endpoints/admin/test_change_admin_address.mligo @@ -0,0 +1,87 @@ + +#import "ligo-breathalyzer/lib/lib.mligo" "Breath" +#import "./../../../common/helpers.mligo" "Helpers" +#import "../../../../batcher.mligo" "Batcher" +#import "../../../../errors.mligo" "Errors" + + +let change_admin_address_should_succeed_if_user_is_admin = + Breath.Model.case + "test change admin address" + "should be successful if user is admin" + (fun (level: Breath.Logger.level) -> + let context = Helpers.test_context level in + let batcher = context.contracts.batcher in + let old_storage = Breath.Contract.storage_of batcher in + let new_address = context.btc_trader.address in + let act_change_admin_address = Breath.Context.act_as context.admin (fun (_u:unit) -> (Breath.Contract.transfer_to batcher (Change_admin_address new_address) 0tez)) in + let new_storage = Breath.Contract.storage_of batcher in + + Breath.Result.reduce [ + Breath.Assert.is_equal "old address" context.admin.address old_storage.administrator + ; act_change_admin_address + ; Breath.Assert.is_equal "new address" new_address new_storage.administrator + ]) + +let change_admin_address_should_fail_if_user_is_not_admin = + Breath.Model.case + "test change admin address" + "should fail if user is not admin" + (fun (level: Breath.Logger.level) -> + let context = Helpers.test_context level in + let batcher = context.contracts.batcher in + let old_storage = Breath.Contract.storage_of batcher in + let new_address = context.usdt_trader.address in + let act_change_admin_address = Breath.Context.act_as context.non_admin (fun (_u:unit) -> (Breath.Contract.transfer_to batcher (Change_admin_address new_address) 0tez)) in + let new_storage = Breath.Contract.storage_of batcher in + + Breath.Result.reduce [ + Breath.Assert.is_equal "old address" context.admin.address old_storage.administrator + ; Breath.Expect.fail_with_value Errors.sender_not_administrator act_change_admin_address + ; Breath.Assert.is_equal "address unchanged" context.admin.address new_storage.administrator + ]) + +let change_admin_address_should_fail_if_tez_is_sent = + Breath.Model.case + "test change admin address" + "should fail if tez is sent" + (fun (level: Breath.Logger.level) -> + let context = Helpers.test_context level in + let batcher = context.contracts.batcher in + let old_storage = Breath.Contract.storage_of batcher in + let new_address = context.usdt_trader.address in + let act_change_admin_address = Breath.Context.act_as context.admin (fun (_u:unit) -> (Breath.Contract.transfer_to batcher (Change_admin_address new_address) 5tez)) in + let new_storage = Breath.Contract.storage_of batcher in + + Breath.Result.reduce [ + Breath.Assert.is_equal "old address" context.admin.address old_storage.administrator + ; Breath.Expect.fail_with_value Errors.endpoint_does_not_accept_tez act_change_admin_address + ; Breath.Assert.is_equal "address unchanged" context.admin.address new_storage.administrator + ]) + +let change_admin_address_should_fail_if_new_address_is_the_same_as_fee_recipient = + Breath.Model.case + "test change admin address" + "should fail if new address is the same as fee recipient" + (fun (level: Breath.Logger.level) -> + let context = Helpers.test_context level in + let batcher = context.contracts.batcher in + let old_storage = Breath.Contract.storage_of batcher in + let new_address = context.fee_recipient in + let act_change_admin_address = Breath.Context.act_as context.admin (fun (_u:unit) -> (Breath.Contract.transfer_to batcher (Change_admin_address new_address) 0tez)) in + let new_storage = Breath.Contract.storage_of batcher in + + Breath.Result.reduce [ + Breath.Assert.is_equal "old address" context.admin.address old_storage.administrator + ; Breath.Expect.fail_with_value Errors.admin_and_fee_recipient_address_cannot_be_the_same act_change_admin_address + ; Breath.Assert.is_equal "address unchanged" context.admin.address new_storage.administrator + ]) + +let test_suite = + Breath.Model.suite "Suite for Change Admin Address (Admin)" [ + change_admin_address_should_succeed_if_user_is_admin + ; change_admin_address_should_fail_if_user_is_not_admin + ; change_admin_address_should_fail_if_tez_is_sent + ; change_admin_address_should_fail_if_new_address_is_the_same_as_fee_recipient + ] + diff --git a/batcher/test/tokenmanager/endpoints/admin/test_change_marketmaker_address.mligo b/batcher/test/tokenmanager/endpoints/admin/test_change_marketmaker_address.mligo new file mode 100644 index 00000000..31fb4507 --- /dev/null +++ b/batcher/test/tokenmanager/endpoints/admin/test_change_marketmaker_address.mligo @@ -0,0 +1,87 @@ + +#import "ligo-breathalyzer/lib/lib.mligo" "Breath" +#import "./../../../common/helpers.mligo" "Helpers" +#import "../../../../batcher.mligo" "Batcher" +#import "../../../../errors.mligo" "Errors" + + +let change_marketmaker_address_should_succeed_if_user_is_admin = + Breath.Model.case + "test change marketmaker address" + "should be successful if user is admin" + (fun (level: Breath.Logger.level) -> + let context = Helpers.test_context level in + let batcher = context.contracts.batcher in + let old_storage = Breath.Contract.storage_of batcher in + let new_address = context.btc_trader.address in + let act_change_marketmaker_address = Breath.Context.act_as context.admin (fun (_u:unit) -> (Breath.Contract.transfer_to batcher (Change_marketmaker_address new_address) 0tez)) in + let new_storage = Breath.Contract.storage_of batcher in + + Breath.Result.reduce [ + Breath.Assert.is_equal "old address" context.admin.address old_storage.marketmaker + ; act_change_marketmaker_address + ; Breath.Assert.is_equal "new address" new_address new_storage.marketmaker + ]) + +let change_marketmaker_address_should_fail_if_user_is_not_admin = + Breath.Model.case + "test change marketmaker address" + "should fail if user is not admin" + (fun (level: Breath.Logger.level) -> + let context = Helpers.test_context level in + let batcher = context.contracts.batcher in + let old_storage = Breath.Contract.storage_of batcher in + let new_address = context.usdt_trader.address in + let act_change_marketmaker_address = Breath.Context.act_as context.non_admin (fun (_u:unit) -> (Breath.Contract.transfer_to batcher (Change_marketmaker_address new_address) 0tez)) in + let new_storage = Breath.Contract.storage_of batcher in + + Breath.Result.reduce [ + Breath.Assert.is_equal "old address" context.admin.address old_storage.marketmaker + ; Breath.Expect.fail_with_value Errors.sender_not_administrator act_change_marketmaker_address + ; Breath.Assert.is_equal "address unchanged" context.admin.address new_storage.marketmaker + ]) + +let change_marketmaker_address_should_fail_if_tez_is_sent = + Breath.Model.case + "test change marketmaker address" + "should fail if tez is sent" + (fun (level: Breath.Logger.level) -> + let context = Helpers.test_context level in + let batcher = context.contracts.batcher in + let old_storage = Breath.Contract.storage_of batcher in + let new_address = context.usdt_trader.address in + let act_change_marketmaker_address = Breath.Context.act_as context.admin (fun (_u:unit) -> (Breath.Contract.transfer_to batcher (Change_marketmaker_address new_address) 5tez)) in + let new_storage = Breath.Contract.storage_of batcher in + + Breath.Result.reduce [ + Breath.Assert.is_equal "old address" context.admin.address old_storage.marketmaker + ; Breath.Expect.fail_with_value Errors.endpoint_does_not_accept_tez act_change_marketmaker_address + ; Breath.Assert.is_equal "address unchanged" context.admin.address new_storage.marketmaker + ]) + +let change_marketmaker_address_should_fail_if_new_address_is_the_same_as_fee_recipient = + Breath.Model.case + "test change marketmaker address" + "should fail if new address is the same as fee recipient" + (fun (level: Breath.Logger.level) -> + let context = Helpers.test_context level in + let batcher = context.contracts.batcher in + let old_storage = Breath.Contract.storage_of batcher in + let new_address = context.fee_recipient in + let act_change_marketmaker_address = Breath.Context.act_as context.admin (fun (_u:unit) -> (Breath.Contract.transfer_to batcher (Change_marketmaker_address new_address) 0tez)) in + let new_storage = Breath.Contract.storage_of batcher in + + Breath.Result.reduce [ + Breath.Assert.is_equal "old address" context.admin.address old_storage.marketmaker + ; Breath.Expect.fail_with_value Errors.admin_and_fee_recipient_address_cannot_be_the_same act_change_marketmaker_address + ; Breath.Assert.is_equal "address unchanged" context.admin.address new_storage.marketmaker + ]) + +let test_suite = + Breath.Model.suite "Suite for Change MarketMaker Address (Admin)" [ + change_marketmaker_address_should_succeed_if_user_is_admin + ; change_marketmaker_address_should_fail_if_user_is_not_admin + ; change_marketmaker_address_should_fail_if_tez_is_sent + ; change_marketmaker_address_should_fail_if_new_address_is_the_same_as_fee_recipient + ] + diff --git a/batcher/test/batcher/endpoints/admin/test_change_oracle_source_of_pair.mligo b/batcher/test/tokenmanager/endpoints/admin/test_change_oracle_source_of_pair.mligo similarity index 100% rename from batcher/test/batcher/endpoints/admin/test_change_oracle_source_of_pair.mligo rename to batcher/test/tokenmanager/endpoints/admin/test_change_oracle_source_of_pair.mligo diff --git a/batcher/test/batcher/endpoints/admin/test_enable_disable_swap_pair_for_deposit.mligo b/batcher/test/tokenmanager/endpoints/admin/test_enable_disable_swap_pair_for_deposit.mligo similarity index 100% rename from batcher/test/batcher/endpoints/admin/test_enable_disable_swap_pair_for_deposit.mligo rename to batcher/test/tokenmanager/endpoints/admin/test_enable_disable_swap_pair_for_deposit.mligo diff --git a/batcher/test/vault/endpoints/admin/test_change_admin_address.mligo b/batcher/test/vault/endpoints/admin/test_change_admin_address.mligo new file mode 100644 index 00000000..a89a4a4c --- /dev/null +++ b/batcher/test/vault/endpoints/admin/test_change_admin_address.mligo @@ -0,0 +1,87 @@ + +#import "ligo-breathalyzer/lib/lib.mligo" "Breath" +#import "./../../../common/helpers.mligo" "Helpers" +#import "../../../../batcher.mligo" "Batcher" +#import "../../../../errors.mligo" "Errors" + + +let change_admin_address_should_succeed_if_user_is_admin = + Breath.Model.case + "test change admin address" + "should be successful if user is admin" + (fun (level: Breath.Logger.level) -> + let context = Helpers.test_context level in + let batcher = context.contracts.batcher in + let old_storage = Breath.Contract.storage_of batcher in + let new_address = context.btc_trader.address in + let act_change_admin_address = Breath.Context.act_as context.admin (fun (_u:unit) -> (Breath.Contract.transfer_to batcher (Change_admin_address new_address) 0tez)) in + let new_storage = Breath.Contract.storage_of batcher in + + Breath.Result.reduce [ + Breath.Assert.is_equal "old address" context.admin.address old_storage.administrator + ; act_change_admin_address + ; Breath.Assert.is_equal "new address" new_address new_storage.administrator + ]) + +let change_admin_address_should_fail_if_user_is_not_admin = + Breath.Model.case + "test change admin address" + "should fail if user is not admin" + (fun (level: Breath.Logger.level) -> + let context = Helpers.test_context level in + let batcher = context.contracts.batcher in + let old_storage = Breath.Contract.storage_of batcher in + let new_address = context.usdt_trader.address in + let act_change_admin_address = Breath.Context.act_as context.non_admin (fun (_u:unit) -> (Breath.Contract.transfer_to batcher (Change_admin_address new_address) 0tez)) in + let new_storage = Breath.Contract.storage_of batcher in + + Breath.Result.reduce [ + Breath.Assert.is_equal "old address" context.admin.address old_storage.administrator + ; Breath.Expect.fail_with_value Errors.sender_not_administrator act_change_admin_address + ; Breath.Assert.is_equal "address unchanged" context.admin.address new_storage.administrator + ]) + +let change_admin_address_should_fail_if_tez_is_sent = + Breath.Model.case + "test change admin address" + "should fail if tez is sent" + (fun (level: Breath.Logger.level) -> + let context = Helpers.test_context level in + let batcher = context.contracts.batcher in + let old_storage = Breath.Contract.storage_of batcher in + let new_address = context.usdt_trader.address in + let act_change_admin_address = Breath.Context.act_as context.admin (fun (_u:unit) -> (Breath.Contract.transfer_to batcher (Change_admin_address new_address) 5tez)) in + let new_storage = Breath.Contract.storage_of batcher in + + Breath.Result.reduce [ + Breath.Assert.is_equal "old address" context.admin.address old_storage.administrator + ; Breath.Expect.fail_with_value Errors.endpoint_does_not_accept_tez act_change_admin_address + ; Breath.Assert.is_equal "address unchanged" context.admin.address new_storage.administrator + ]) + +let change_admin_address_should_fail_if_new_address_is_the_same_as_fee_recipient = + Breath.Model.case + "test change admin address" + "should fail if new address is the same as fee recipient" + (fun (level: Breath.Logger.level) -> + let context = Helpers.test_context level in + let batcher = context.contracts.batcher in + let old_storage = Breath.Contract.storage_of batcher in + let new_address = context.fee_recipient in + let act_change_admin_address = Breath.Context.act_as context.admin (fun (_u:unit) -> (Breath.Contract.transfer_to batcher (Change_admin_address new_address) 0tez)) in + let new_storage = Breath.Contract.storage_of batcher in + + Breath.Result.reduce [ + Breath.Assert.is_equal "old address" context.admin.address old_storage.administrator + ; Breath.Expect.fail_with_value Errors.admin_and_fee_recipient_address_cannot_be_the_same act_change_admin_address + ; Breath.Assert.is_equal "address unchanged" context.admin.address new_storage.administrator + ]) + +let test_suite = + Breath.Model.suite "Suite for Change Admin Address (Admin)" [ + change_admin_address_should_succeed_if_user_is_admin + ; change_admin_address_should_fail_if_user_is_not_admin + ; change_admin_address_should_fail_if_tez_is_sent + ; change_admin_address_should_fail_if_new_address_is_the_same_as_fee_recipient + ] + diff --git a/batcher/test/vault/endpoints/admin/test_change_batcher_address.mligo b/batcher/test/vault/endpoints/admin/test_change_batcher_address.mligo new file mode 100644 index 00000000..a89a4a4c --- /dev/null +++ b/batcher/test/vault/endpoints/admin/test_change_batcher_address.mligo @@ -0,0 +1,87 @@ + +#import "ligo-breathalyzer/lib/lib.mligo" "Breath" +#import "./../../../common/helpers.mligo" "Helpers" +#import "../../../../batcher.mligo" "Batcher" +#import "../../../../errors.mligo" "Errors" + + +let change_admin_address_should_succeed_if_user_is_admin = + Breath.Model.case + "test change admin address" + "should be successful if user is admin" + (fun (level: Breath.Logger.level) -> + let context = Helpers.test_context level in + let batcher = context.contracts.batcher in + let old_storage = Breath.Contract.storage_of batcher in + let new_address = context.btc_trader.address in + let act_change_admin_address = Breath.Context.act_as context.admin (fun (_u:unit) -> (Breath.Contract.transfer_to batcher (Change_admin_address new_address) 0tez)) in + let new_storage = Breath.Contract.storage_of batcher in + + Breath.Result.reduce [ + Breath.Assert.is_equal "old address" context.admin.address old_storage.administrator + ; act_change_admin_address + ; Breath.Assert.is_equal "new address" new_address new_storage.administrator + ]) + +let change_admin_address_should_fail_if_user_is_not_admin = + Breath.Model.case + "test change admin address" + "should fail if user is not admin" + (fun (level: Breath.Logger.level) -> + let context = Helpers.test_context level in + let batcher = context.contracts.batcher in + let old_storage = Breath.Contract.storage_of batcher in + let new_address = context.usdt_trader.address in + let act_change_admin_address = Breath.Context.act_as context.non_admin (fun (_u:unit) -> (Breath.Contract.transfer_to batcher (Change_admin_address new_address) 0tez)) in + let new_storage = Breath.Contract.storage_of batcher in + + Breath.Result.reduce [ + Breath.Assert.is_equal "old address" context.admin.address old_storage.administrator + ; Breath.Expect.fail_with_value Errors.sender_not_administrator act_change_admin_address + ; Breath.Assert.is_equal "address unchanged" context.admin.address new_storage.administrator + ]) + +let change_admin_address_should_fail_if_tez_is_sent = + Breath.Model.case + "test change admin address" + "should fail if tez is sent" + (fun (level: Breath.Logger.level) -> + let context = Helpers.test_context level in + let batcher = context.contracts.batcher in + let old_storage = Breath.Contract.storage_of batcher in + let new_address = context.usdt_trader.address in + let act_change_admin_address = Breath.Context.act_as context.admin (fun (_u:unit) -> (Breath.Contract.transfer_to batcher (Change_admin_address new_address) 5tez)) in + let new_storage = Breath.Contract.storage_of batcher in + + Breath.Result.reduce [ + Breath.Assert.is_equal "old address" context.admin.address old_storage.administrator + ; Breath.Expect.fail_with_value Errors.endpoint_does_not_accept_tez act_change_admin_address + ; Breath.Assert.is_equal "address unchanged" context.admin.address new_storage.administrator + ]) + +let change_admin_address_should_fail_if_new_address_is_the_same_as_fee_recipient = + Breath.Model.case + "test change admin address" + "should fail if new address is the same as fee recipient" + (fun (level: Breath.Logger.level) -> + let context = Helpers.test_context level in + let batcher = context.contracts.batcher in + let old_storage = Breath.Contract.storage_of batcher in + let new_address = context.fee_recipient in + let act_change_admin_address = Breath.Context.act_as context.admin (fun (_u:unit) -> (Breath.Contract.transfer_to batcher (Change_admin_address new_address) 0tez)) in + let new_storage = Breath.Contract.storage_of batcher in + + Breath.Result.reduce [ + Breath.Assert.is_equal "old address" context.admin.address old_storage.administrator + ; Breath.Expect.fail_with_value Errors.admin_and_fee_recipient_address_cannot_be_the_same act_change_admin_address + ; Breath.Assert.is_equal "address unchanged" context.admin.address new_storage.administrator + ]) + +let test_suite = + Breath.Model.suite "Suite for Change Admin Address (Admin)" [ + change_admin_address_should_succeed_if_user_is_admin + ; change_admin_address_should_fail_if_user_is_not_admin + ; change_admin_address_should_fail_if_tez_is_sent + ; change_admin_address_should_fail_if_new_address_is_the_same_as_fee_recipient + ] + diff --git a/batcher/test/market_maker/test_add_update_liquidity.mligo b/batcher/test/vault/endpoints/user/test_add_update_liquidity.mligo similarity index 100% rename from batcher/test/market_maker/test_add_update_liquidity.mligo rename to batcher/test/vault/endpoints/user/test_add_update_liquidity.mligo diff --git a/batcher/test/market_maker/test_claim_rewards.mligo b/batcher/test/vault/endpoints/user/test_claim_rewards.mligo similarity index 100% rename from batcher/test/market_maker/test_claim_rewards.mligo rename to batcher/test/vault/endpoints/user/test_claim_rewards.mligo diff --git a/batcher/test/market_maker/test_remove_liquidity.mligo b/batcher/test/vault/endpoints/user/test_remove_liquidity.mligo similarity index 100% rename from batcher/test/market_maker/test_remove_liquidity.mligo rename to batcher/test/vault/endpoints/user/test_remove_liquidity.mligo diff --git a/batcher/tokenmanager.mligo b/batcher/tokenmanager.mligo new file mode 100644 index 00000000..172a8bd6 --- /dev/null +++ b/batcher/tokenmanager.mligo @@ -0,0 +1,136 @@ +#import "@ligo/math-lib/rational/rational.mligo" "Rational" +#include "types.mligo" +#include "utils.mligo" +#include "errors.mligo" + +module TokenManager = struct + + +type storage = { + valid_tokens : ValidTokens.t; + valid_swaps : ValidSwaps.t; + administrator : address; + limit_on_tokens_or_pairs : nat; +} + +type result = operation list * storage + +[@inline] +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 + +(* [@entry] *) +[@inline] +let change_admin_address + (new_admin_address: address) + (storage: storage) : operation list * storage = + 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 + +(* [@entry] *) +[@inline] +let set_deposit_status + (pair_name: string) + (disabled: bool) + (storage: storage) : result = + let () = is_known_sender storage.administrator sender_not_administrator in + let () = reject_if_tez_supplied () in + let valid_swap = get_valid_swap_reduced pair_name storage.valid_swaps in + let valid_swap = { valid_swap with is_disabled_for_deposits = disabled; } in + let valid_swaps = ValidSwaps.upsert pair_name valid_swap storage.valid_swaps in + let storage = { storage with valid_swaps = valid_swaps; } in + no_op (storage) + +(* [@entry] *) +[@inline] +let amend_token_and_pair_limit + (limit: nat) + (storage: storage) : result = + let () = is_known_sender storage.administrator sender_not_administrator in + let () = reject_if_tez_supplied () in + let token_count = ValidTokens.size storage.valid_tokens in + let pair_count = ValidSwaps.size storage.valid_swaps in + if limit < token_count then failwith cannot_reduce_limit_on_tokens_to_less_than_already_exists else + if limit < pair_count then failwith cannot_reduce_limit_on_swap_pairs_to_less_than_already_exists else + let storage = { storage with limit_on_tokens_or_pairs = limit} in + no_op (storage) + +(* [@entry] *) +[@inline] +let add_token_swap_pair + (valid_swap: valid_swap) + (storage: storage) : result = + let () = is_known_sender storage.administrator sender_not_administrator in + let () = reject_if_tez_supplied () in + if valid_swap.swap.from.token.decimals < minimum_precision then failwith swap_precision_is_less_than_minimum else + if valid_swap.swap.to.decimals < minimum_precision then failwith swap_precision_is_less_than_minimum else + if valid_swap.oracle_precision <> minimum_precision then failwith oracle_must_be_equal_to_minimum_precision else + let (u_swaps,u_tokens) = Tokens.add_pair storage.limit_on_tokens_or_pairs valid_swap storage.valid_swaps storage.valid_tokens in + let storage = { storage with valid_swaps = u_swaps; valid_tokens = u_tokens; } in + no_op storage + +(* [@entry] *) +[@inline] +let remove_token_swap_pair + (swap: valid_swap) + (storage: storage) : result = + let () = is_known_sender storage.administrator sender_not_administrator in + let () = reject_if_tez_supplied () in + let () = confirm_swap_pair_is_disabled_prior_to_removal swap in + let (u_swaps,u_tokens) = Tokens.remove_pair swap storage.valid_swaps storage.valid_tokens in + let storage = { storage with valid_swaps = u_swaps; valid_tokens = u_tokens; } in + no_op storage + + +(* [@entry] *) +[@inline] +let change_oracle_price_source + (source_change: oracle_source_change) + (storage: storage) : result = + let () = is_known_sender storage.administrator sender_not_administrator in + let () = reject_if_tez_supplied () in + let valid_swap_reduced = get_valid_swap_reduced source_change.pair_name storage.valid_swaps in + let valid_swap = { valid_swap_reduced with oracle_address = source_change.oracle_address; oracle_asset_name = source_change.oracle_asset_name; oracle_precision = source_change.oracle_precision; } in + let _ = get_oracle_price unable_to_get_price_from_new_oracle_source valid_swap_reduced in + let updated_swaps = ValidSwaps.upsert source_change.pair_name valid_swap storage.valid_swaps in + let storage = { storage with valid_swaps = updated_swaps} in + no_op (storage) + + +end + + +[@view] +let get_valid_swaps ((), storage : unit * TokenManager.storage) : ValidSwaps.t_map = ValidSwaps.to_map storage.valid_swaps + +[@view] +let get_valid_tokens ((), storage : unit * TokenManager.storage) : ValidTokens.t_map = ValidTokens.to_map storage.valid_tokens + + +type entrypoint = + | Change_admin_address of address + | Add_token_swap_pair of valid_swap + | Remove_token_swap_pair of valid_swap + | Amend_token_and_pair_limit of nat + | Enable_swap_pair_for_deposit of string + | Disable_swap_pair_for_deposit of string + | Change_oracle_source_of_pair of oracle_source_change + + +let main + (action, storage : entrypoint * TokenManager.storage) : operation list * TokenManager.storage = + match action with + (* Admin endpoints *) + | Change_admin_address new_admin_address -> TokenManager.change_admin_address new_admin_address storage + | Add_token_swap_pair valid_swap -> TokenManager.add_token_swap_pair valid_swap storage + | Remove_token_swap_pair valid_swap -> TokenManager.remove_token_swap_pair valid_swap storage + | Change_oracle_source_of_pair source_update -> TokenManager.change_oracle_price_source source_update storage + | Amend_token_and_pair_limit l -> TokenManager.amend_token_and_pair_limit l storage + | Enable_swap_pair_for_deposit pair_name -> TokenManager.set_deposit_status pair_name false storage + | Disable_swap_pair_for_deposit pair_name -> TokenManager.set_deposit_status pair_name true storage + + + diff --git a/batcher/types.mligo b/batcher/types.mligo index eaf9480c..f7548244 100644 --- a/batcher/types.mligo +++ b/batcher/types.mligo @@ -1,4 +1,5 @@ #import "@ligo/math-lib/rational/rational.mligo" "Rational" +#include "./errors.mligo" (* Side of an order, either BUY side or SELL side *) type side = @@ -166,6 +167,9 @@ type batch_ordertypes = (nat, ordertypes) map (* Associated user address to a given set of batches and ordertypes *) type user_batch_ordertypes = (address, batch_ordertypes) big_map +type market_vault_used = address option + + (* Batch of orders for the same pair of tokens *) type batch = [@layout:comb] { batch_number: nat; @@ -173,13 +177,13 @@ type batch = [@layout:comb] { volumes : volumes; pair : pair; holdings : nat; - market_vault_used : bool; + market_vault_used : market_vault_used; } type reduced_batch = [@layout:comb] { status: batch_status; volumes: volumes; - market_vault_used : bool; + market_vault_used : market_vault_used; } type batch_indices = (string, nat) map @@ -208,11 +212,194 @@ type oracle_source_change = [@layout:comb] { oracle_precision: nat; } -(* The tokens that are valid within the contract *) -type valid_tokens = (string, token) map -(* The swaps of valid tokens that are accepted by the contract *) -type valid_swaps = (string, valid_swap_reduced) map +module ValidTokens = struct + + type key = string + type value = token + +type t = { + keys: key set; + values: (key, value) big_map +} + +type t_map = (key,value) map + +[@inline] +let size (object:t) : nat = Set.size object.keys + +[@inline] +let mem (key:key) (object:t): bool = Set.mem key object.keys + +[@inline] +let find_opt (key:key) (object:t): value option = + if Set.mem key object.keys then + match Big_map.find_opt key object.values with + | None -> (None:value option) + | Some v -> (Some v) + else + (None: value option) + +[@inline] +let find_or_fail (key:key) (object:t): value = + match find_opt key object with + | None -> failwith token_name_not_in_list_of_valid_tokens + | Some v -> v + +[@inline] +let upsert (key:key) (value:value) (object:t): t = + if Set.mem key object.keys then + let values = Big_map.update key (Some value) object.values in + {object with values = values;} + else + let values = Big_map.add key value object.values in + let keys = Set.add key object.keys in + {object with keys = keys; values = values;} + +[@inline] +let remove (key:key) (object:t): t = + if Set.mem key object.keys then + let values = Big_map.remove key object.values in + {object with values = values;} + else + object + +[@inline] +let get_and_remove + (key:key) + (object:t): (value option * t) = + if Set.mem key object.keys then + let v_opt = Big_map.find_opt key object.values in + let values = Big_map.remove key object.values in + v_opt, {object with values = values;} + else + None, object + + +[@inline] +let to_map + (object:t) : (key,value) map = + let collect_from_bm ((acc, k) : ((key,value) map) * key) : (key,value) map = + match Big_map.find_opt k object.values with + | None -> acc + | Some v -> Map.add k v acc + in + Set.fold collect_from_bm object.keys (Map.empty: (key, value) map) + +[@inline] +let fold_map + (type a) + (folder: (a * (key * value)) -> a) + (object:t_map) + (seed: a): a = + Map.fold folder object seed + +[@inline] +let fold + (type a) + (folder: (a * (key * value)) -> a) + (object:t) + (seed: a): a = + let mp = to_map object in + Map.fold folder mp seed + + + + +end + +module ValidSwaps = struct + + type key = string + type value = valid_swap_reduced + +type t = { + keys: key set; + values: (key, value) big_map +} + +type t_map = (key,value) map + +[@inline] +let size (object:t) : nat = Set.size object.keys + + +[@inline] +let mem (key:key) (object:t): bool = Set.mem key object.keys + +[@inline] +let find_opt (key:key) (object:t): value option = + if Set.mem key object.keys then + match Big_map.find_opt key object.values with + | None -> (None:value option) + | Some v -> (Some v) + else + (None: value option) + +[@inline] +let find_or_fail (key:key) (object:t): value = + match find_opt key object with + | None -> failwith token_name_not_in_list_of_valid_tokens + | Some v -> v + +[@inline] +let upsert (key:key) (value:value) (object:t): t = + if Set.mem key object.keys then + let values = Big_map.update key (Some value) object.values in + {object with values = values;} + else + let values = Big_map.add key value object.values in + let keys = Set.add key object.keys in + {object with keys = keys; values = values;} + +[@inline] +let remove (key:key) (object:t): t = + if Set.mem key object.keys then + let values = Big_map.remove key object.values in + {object with values = values;} + else + object + +[@inline] +let get_and_remove + (key:key) + (object:t): (value option * t) = + if Set.mem key object.keys then + let v_opt = Big_map.find_opt key object.values in + let values = Big_map.remove key object.values in + v_opt, {object with values = values;} + else + None, object + +[@inline] +let to_map + (object:t) : (key,value) map = + let collect_from_bm ((acc, k) : ((key,value) map) * key) : (key,value) map = + match Big_map.find_opt k object.values with + | None -> acc + | Some v -> Map.add k v acc + in + Set.fold collect_from_bm object.keys (Map.empty: (key, value) map) + +[@inline] +let fold_map + (type a) + (folder: (a * (key * value)) -> a) + (object:t_map) + (seed: a): a = + Map.fold folder object seed + +[@inline] +let fold + (type a) + (folder: (a * (key * value)) -> a) + (object:t) + (seed: a): a = + let mp = to_map object in + Map.fold folder mp seed + +end + (* The current, most up to date exchange rates between tokens *) type rates_current = (string, exchange_rate) big_map @@ -220,32 +407,235 @@ type rates_current = (string, exchange_rate) big_map type fees = { to_send: tez; to_refund: tez; - to_market_maker: tez; + to_market_makers: (address,tez) map; payer: address; recipient: address; - market_maker: address; -} - -type market_maker_vault = { - total_shares: nat; - holdings: nat set; - native_token: token_amount; - foreign_tokens: token_amount_map; } -type market_vaults = (string, market_maker_vault) big_map -type market_vault_holding = { - id: nat; - token: string; +type vault_holding = { holder: address; shares: nat; unclaimed: tez; } -type user_holding_key = address * string -type user_holdings = (user_holding_key, nat) big_map +module VaultHoldings = struct + + type key = address + type value = vault_holding + +type t = { + keys: key set; + values: (key, value) big_map +} + +type t_map = (key,value) map -type vault_holdings = (nat, market_vault_holding) big_map +[@inline] +let empty:t = { + keys = Set.empty; + values = Big_map.empty; +} +[@inline] +let size (object:t) : nat = Set.size object.keys + + +[@inline] +let mem (key:key) (object:t): bool = Set.mem key object.keys + +[@inline] +let find_opt (key:key) (object:t): value option = + if Set.mem key object.keys then + match Big_map.find_opt key object.values with + | None -> (None:value option) + | Some v -> (Some v) + else + (None: value option) + +[@inline] +let find_or_fail (key:key) (object:t): value = + match find_opt key object with + | None -> failwith token_name_not_in_list_of_valid_tokens + | Some v -> v + +[@inline] +let upsert (key:key) (value:value) (object:t): t = + if Set.mem key object.keys then + let values = Big_map.update key (Some value) object.values in + {object with values = values;} + else + let values = Big_map.add key value object.values in + let keys = Set.add key object.keys in + {object with keys = keys; values = values;} + +[@inline] +let remove (key:key) (object:t): t = + if Set.mem key object.keys then + let values = Big_map.remove key object.values in + {object with values = values;} + else + object + +[@inline] +let get_and_remove + (key:key) + (object:t): (value option * t) = + if Set.mem key object.keys then + let v_opt = Big_map.find_opt key object.values in + let values = Big_map.remove key object.values in + v_opt, {object with values = values;} + else + None, object + +[@inline] +let to_map + (object:t) : (key,value) map = + let collect_from_bm ((acc, k) : ((key,value) map) * key) : (key,value) map = + match Big_map.find_opt k object.values with + | None -> acc + | Some v -> Map.add k v acc + in + Set.fold collect_from_bm object.keys (Map.empty: (key, value) map) + + +[@inline] +let fold + (type a) + (folder: (a * (key * value)) -> a) + (object:t) + (seed: a): a = + let mp = to_map object in + Map.fold folder mp seed + + +[@inline] +let mem_map + (to_find:value) + (m: (key, value) map) : bool = + let find (found, (_k,v): (bool * (key * value))) : bool = if found then found else to_find = v in + Map.fold find m false + +end + +module Vaults = struct + + type key = string + type value = address + +type t = { + keys: key set; + values: (key, value) big_map +} + +type t_map = (key,value) map + +[@inline] +let size (object:t) : nat = Set.size object.keys + + +[@inline] +let mem (key:key) (object:t): bool = Set.mem key object.keys + +[@inline] +let find_opt (key:key) (object:t): value option = + if Set.mem key object.keys then + match Big_map.find_opt key object.values with + | None -> (None:value option) + | Some v -> (Some v) + else + (None: value option) + +[@inline] +let find_or_fail (key:key) (object:t): value = + match find_opt key object with + | None -> failwith token_name_not_in_list_of_valid_tokens + | Some v -> v + +[@inline] +let upsert (key:key) (value:value) (object:t): t = + if Set.mem key object.keys then + let values = Big_map.update key (Some value) object.values in + {object with values = values;} + else + let values = Big_map.add key value object.values in + let keys = Set.add key object.keys in + {object with keys = keys; values = values;} + +[@inline] +let remove (key:key) (object:t): t = + if Set.mem key object.keys then + let values = Big_map.remove key object.values in + {object with values = values;} + else + object + +[@inline] +let get_and_remove + (key:key) + (object:t): (value option * t) = + if Set.mem key object.keys then + let v_opt = Big_map.find_opt key object.values in + let values = Big_map.remove key object.values in + v_opt, {object with values = values;} + else + None, object + +[@inline] +let to_map + (object:t) : (key,value) map = + let collect_from_bm ((acc, k) : ((key,value) map) * key) : (key,value) map = + match Big_map.find_opt k object.values with + | None -> acc + | Some v -> Map.add k v acc + in + Set.fold collect_from_bm object.keys (Map.empty: (key, value) map) + + +[@inline] +let fold + (type a) + (folder: (a * (key * value)) -> a) + (object:t) + (seed: a): a = + let mp = to_map object in + Map.fold folder mp seed + + +[@inline] +let mem_map + (to_find:value) + (m: (key, value) map) : bool = + let find (found, (_k,v): (bool * (key * value))) : bool = if found then found else to_find = v in + Map.fold find m false + +end + +type liquidity_injection_request = { + side:side; + from_token:token; + to_token:token; + amount:nat; +} + +type get_balance_request = address * nat contract + +type balance_request = { + owner : address; + token_id : nat; +} + +type balance_of_response = +[@layout:comb] { + request : balance_request; + balance : nat; +} + +type balance_of_responses = balance_of_response list + +type balance_of = +[@layout:comb] { + requests : balance_request list; + callback : balance_of_responses contract; +} diff --git a/batcher/utils.mligo b/batcher/utils.mligo index 7906e91c..b3805ecd 100644 --- a/batcher/utils.mligo +++ b/batcher/utils.mligo @@ -1,41 +1,32 @@ -#import "types.mligo" "Types" -#import "errors.mligo" "Errors" -#import "constants.mligo" "Constants" +#include "./types.mligo" +#include "./errors.mligo" +#include "./constants.mligo" #import "@ligo/math-lib/rational/rational.mligo" "Rational" -type buy_side = Types.buy_side -type sell_side = Types.sell_side -type token = Types.token -type valid_tokens = Types.valid_tokens -type swap = Types.swap -type swap_reduced = Types.swap_reduced -type valid_swap = Types.valid_swap -type valid_swap_reduced = Types.valid_swap_reduced -type total_cleared_volumes = Types.total_cleared_volumes -type tolerance = Types.tolerance -type exchange_rate = Types.exchange_rate -type clearing = Types.clearing -type side = Types.side -type pair = Types.pair -type batch_indices = Types.batch_indices -type rates_current = Types.rates_current -type external_swap_order = Types.external_swap_order -type token_amount_map = Types.token_amount_map -type token_amount = Types.token_amount -type ordertype = Types.ordertype -type swap_order = Types.swap_order + +[@inline] +let no_op (type storage) (s : storage) : operation list * storage = (([] : operation list), s) [@inline] let get_vault () : address = Tezos.get_self_address () [@inline] -let get_token +let get_token_from_map (token_name: string) - (tokens: valid_tokens): token = + (tokens: ValidTokens.t_map): token = let tok_opt = Map.find_opt token_name tokens in match tok_opt with | Some t -> t - | None -> failwith Errors.unable_to_reduce_token_amount_to_less_than_zero + | None -> failwith unable_to_reduce_token_amount_to_less_than_zero + +[@inline] +let get_token + (token_name: string) + (tokens: ValidTokens.t): token = + let tok_opt = ValidTokens.find_opt token_name tokens in + match tok_opt with + | Some t -> t + | None -> failwith unable_to_reduce_token_amount_to_less_than_zero [@inline] let swap_to_swap_reduced @@ -61,9 +52,9 @@ let valid_swap_to_valid_swap_reduced let swap_reduced_to_swap (swap_reduced: swap_reduced) (from_amount: nat) - (tokens: valid_tokens) : swap = - let from = get_token swap_reduced.from tokens in - let to = get_token swap_reduced.to tokens in + (tokens: ValidTokens.t_map) : swap = + let from = get_token_from_map swap_reduced.from tokens in + let to = get_token_from_map swap_reduced.to tokens in { from = { token = from; @@ -76,7 +67,7 @@ let swap_reduced_to_swap let valid_swap_reduced_to_valid_swap (valid_swap_reduced: valid_swap_reduced) (from_amount: nat) - (tokens: valid_tokens) : valid_swap = + (tokens: ValidTokens.t_map) : valid_swap = let swap = swap_reduced_to_swap valid_swap_reduced.swap from_amount tokens in { swap = swap; @@ -99,7 +90,7 @@ let empty_total_cleared_volumes : total_cleared_volumes = { let to_nat (i:int): nat = match is_nat i with | Some n -> n - | None -> failwith Errors.number_is_not_a_nat + | None -> failwith number_is_not_a_nat [@inline] let gt (a : Rational.t) (b : Rational.t) : bool = not (Rational.lte a b) @@ -139,7 +130,7 @@ let get_cp_minus let buy_minus_token, _, _ = buy_side in let sell_minus_token, sell_exact_token, sell_plus_token = sell_side in let left_number = Rational.new (buy_minus_token) in - let right_number = Rational.div (Rational.mul (Rational.new (sell_minus_token + sell_exact_token + sell_plus_token)) Constants.ten_bips_constant) rate in + let right_number = Rational.div (Rational.mul (Rational.new (sell_minus_token + sell_exact_token + sell_plus_token)) ten_bips_constant) rate in let min_number = get_min_number left_number right_number in min_number @@ -163,7 +154,7 @@ let get_cp_plus let buy_minus_token, buy_exact_token, buy_plus_token = buy_side in let _, _, sell_plus_token = sell_side in let left_number = Rational.new (buy_minus_token + buy_exact_token + buy_plus_token) in - let right_number = Rational.div (Rational.new (sell_plus_token)) (Rational.mul Constants.ten_bips_constant rate) in + let right_number = Rational.div (Rational.new (sell_plus_token)) (Rational.mul ten_bips_constant rate) in let min_number = get_min_number left_number right_number in min_number @@ -193,7 +184,7 @@ let get_clearing_price (exchange_rate : exchange_rate) (buy_side : buy_side) (se [@inline] let side_to_nat - (side:Types.side): nat = + (side:side): nat = match side with | Buy -> 0n | Sell -> 1n @@ -204,7 +195,7 @@ let nat_to_side if order_side = 0n then Buy else if order_side = 1n then Sell - else failwith Errors.unable_to_parse_side_from_external_order + else failwith unable_to_parse_side_from_external_order [@inline] let tolerance_to_nat (tolerance:tolerance) : nat = @@ -218,7 +209,7 @@ let nat_to_tolerance (tolerance : nat) : tolerance = if tolerance = 0n then Minus else if tolerance = 1n then Exact else if tolerance = 2n then Plus - else failwith Errors.unable_to_parse_tolerance_from_external_order + else failwith unable_to_parse_tolerance_from_external_order [@inline] let find_lexicographical_pair_name @@ -298,10 +289,10 @@ let update_current_rate (rate_name : string) (rate : exchange_rate) (rates_curre [@inline] let get_rate_scaling_power_of_10 (rate : exchange_rate) - (tokens: valid_tokens): Rational.t = + (tokens: ValidTokens.t_map): Rational.t = let swap = rate.swap in - let from_token = get_token swap.from tokens in - let to_token = get_token swap.to tokens in + let from_token = get_token_from_map swap.from tokens in + let to_token = get_token_from_map swap.to tokens in let from_decimals = from_token.decimals in let to_decimals = to_token.decimals in let diff = to_decimals - from_decimals in @@ -318,18 +309,26 @@ let get_rate_scaling_power_of_10 [@inline] let scale_on_receive_for_token_precision_difference (rate : exchange_rate) - (tokens: valid_tokens): exchange_rate = + (tokens: ValidTokens.t_map): exchange_rate = let scaling_rate = get_rate_scaling_power_of_10 rate tokens in let adjusted_rate = Rational.mul rate.rate scaling_rate in { rate with rate = adjusted_rate } + +let is_some + (type a) + (an_opt: a option): bool = + match an_opt with + | Some _ -> true + | None -> false + let assert_some_or_fail_with (type a) (an_opt: a option) - (error: nat) = + (error: nat) : a = match an_opt with + | Some v -> v | None -> failwith error - | Some _ -> () let assert_or_fail_with (predicate: bool) @@ -411,14 +410,11 @@ let are_equivalent_tokens [@inline] let reject_if_tez_supplied(): unit = - if Tezos.get_amount () < 1mutez then () else failwith Errors.endpoint_does_not_accept_tez + if Tezos.get_amount () < 1mutez then () else failwith endpoint_does_not_accept_tez + -[@inline] -let is_administrator - (administrator : address) : unit = - if Tezos.get_sender () = administrator then () else failwith Errors.sender_not_administrator -type orace_price_update = Types.oracle_price_update +type orace_price_update = oracle_price_update [@inline] let get_oracle_price @@ -428,6 +424,8 @@ let get_oracle_price | Some opu -> opu | None -> failwith failure_code + + module TokenAmountMap = struct type op = Increase | Decrease @@ -444,7 +442,7 @@ module TokenAmountMap = struct | Some prev -> let new_amt: nat = match op with | Increase -> ta.amount + prev.amount | Decrease -> if ta.amount > prev.amount then - (failwith Errors.unable_to_reduce_token_amount_to_less_than_zero : nat) + (failwith unable_to_reduce_token_amount_to_less_than_zero : nat) else abs (prev.amount - ta.amount) in @@ -464,11 +462,11 @@ module TokenAmount = struct (ot: ordertype) (amt: nat) (c: clearing) - (tokens: valid_tokens): token_amount = + (tokens: ValidTokens.t_map): token_amount = let swap = c.clearing_rate.swap in let token = match ot.side with - | Buy -> get_token swap.from tokens - | Sell -> get_token swap.to tokens + | Buy -> get_token_from_map swap.from tokens + | Sell -> get_token_from_map swap.to tokens in { token = token; @@ -514,7 +512,7 @@ let transfer_fa12_token (token_amount : nat) : operation = let transfer_entrypoint : fa12_transfer contract = match (Tezos.get_entrypoint_opt "%transfer" token_address : fa12_transfer contract option) with - | None -> failwith Errors.invalid_token_address + | None -> failwith invalid_token_address | Some transfer_entrypoint -> transfer_entrypoint in let transfer : fa12_transfer = { @@ -533,7 +531,7 @@ let transfer_fa2_token (token_amount : nat) : operation = let transfer_entrypoint : fa2_transfer contract = match (Tezos.get_entrypoint_opt "%transfer" token_address : fa2_transfer contract option) with - | None -> failwith Errors.invalid_token_address + | None -> failwith invalid_token_address | Some transfer_entrypoint -> transfer_entrypoint in let transfer : fa2_transfer = [ @@ -559,19 +557,19 @@ let transfer_token (token_amount : token_amount) : operation = match token_amount.token.standard with | Some standard -> - if standard = Constants.fa12_token then + if standard = fa12_token then transfer_fa12_token sender receiver token_address token_amount.amount - else if standard = Constants.fa2_token then + else if standard = fa2_token then transfer_fa2_token sender receiver token_address token_amount.token.token_id token_amount.amount else - failwith Errors.token_standard_not_found + failwith token_standard_not_found | None -> - failwith Errors.token_standard_not_found + failwith token_standard_not_found [@inline] let handle_transfer (sender : address) (receiver : address) (received_token : token_amount) : operation = match received_token.token.address with - | None -> failwith Errors.xtz_not_currently_supported + | None -> failwith xtz_not_currently_supported | Some token_address -> transfer_token sender receiver token_address received_token @@ -588,39 +586,12 @@ let transfer_holdings (treasury_vault : address) (holder: address) (holdings : [@inline] let transfer_fee (receiver : address) (amount : tez) : operation = match (Tezos.get_contract_opt receiver : unit contract option) with - | None -> failwith Errors.invalid_tezos_address + | None -> failwith invalid_tezos_address | Some rec_address -> Tezos.transaction () amount rec_address end -[@inline] -let convert_oracle_price - (precision: nat) - (swap: swap) - (lastupdated: timestamp) - (price: nat) - (tokens: valid_tokens): exchange_rate = - let prc,den : nat * int = if swap.from.token.decimals > precision then - let diff:int = swap.from.token.decimals - precision in - let diff_pow = pow 10 diff in - let adj_price = to_nat (price * diff_pow) in - let denom = pow 10 (int swap.from.token.decimals) in - (adj_price, denom) - else - let denom = pow 10 (int precision) in - (price, denom) - in - let rational_price = Rational.new (int prc) in - let rational_denom = Rational.new den in - let rational_rate: Rational.t = Rational.div rational_price rational_denom in - let swap_reduced: swap_reduced = swap_to_swap_reduced swap in - let rate = { - swap = swap_reduced; - rate = rational_rate; - when = lastupdated; - } in - scale_on_receive_for_token_precision_difference rate tokens [@inline] let add_token_amounts @@ -630,7 +601,7 @@ let add_token_amounts let new_amount = base_token_amount.amount + to_add.amount in {base_token_amount with amount = new_amount;} else - failwith Errors.token_already_exists_but_details_are_different + failwith token_already_exists_but_details_are_different [@inline] let subtract_token_amounts @@ -638,16 +609,16 @@ let subtract_token_amounts (to_subtract: token_amount) : token_amount = if are_equivalent_tokens base_token_amount.token to_subtract.token then let new_int_amount = base_token_amount.amount - to_subtract.amount in - if new_int_amount < 0 then failwith Errors.unable_to_reduce_token_amount_to_less_than_zero else + if new_int_amount < 0 then failwith unable_to_reduce_token_amount_to_less_than_zero else {base_token_amount with amount = abs (new_int_amount);} else - failwith Errors.token_already_exists_but_details_are_different + failwith token_already_exists_but_details_are_different [@inline] let has_redeemable_holdings (batcher: address) : bool = match Tezos.call_view "redeemable_holdings_available" () batcher with - | None -> failwith Errors.unable_to_call_on_chain_view + | None -> failwith unable_to_call_on_chain_view | Some has -> has [@inline] @@ -666,7 +637,7 @@ let approve_fa2_token_transfer let contract = Tezos.get_self_address () in let add_operator = match Tezos.get_entrypoint_opt "%add_operator" token_address with | Some ep -> ep - | None -> failwith Errors.entrypoint_does_not_exist + | None -> failwith entrypoint_does_not_exist in let param = { owner = contract; @@ -681,7 +652,7 @@ let approve_fa12_token_transfer (batcher:address): operation = let approve = match Tezos.get_entrypoint_opt "%approve" token_address with | Some ep -> ep - | None -> failwith Errors.entrypoint_does_not_exist + | None -> failwith entrypoint_does_not_exist in let param = { spender = batcher; @@ -693,12 +664,12 @@ let approve_token_transfer (order: external_swap_order) (token_address:address) (batcher:address): operation = - if has_token_standard order.swap.from.token Constants.fa12_token then + if has_token_standard order.swap.from.token fa12_token then approve_fa12_token_transfer order token_address batcher - else if has_token_standard order.swap.from.token Constants.fa2_token then + else if has_token_standard order.swap.from.token fa2_token then approve_fa2_token_transfer order token_address batcher else - failwith Errors.token_standard_not_found + failwith token_standard_not_found @@ -710,7 +681,7 @@ let revoke_fa2_token_transfer let contract = Tezos.get_self_address () in let remove_operator = match Tezos.get_entrypoint_opt "%remove_operator" token_address with | Some ep -> ep - | None -> failwith Errors.entrypoint_does_not_exist + | None -> failwith entrypoint_does_not_exist in let param = { owner = contract; @@ -723,12 +694,12 @@ let revoke_token_transfer (order: external_swap_order) (token_address:address) (batcher:address): operation option = - if has_token_standard order.swap.from.token Constants.fa12_token then + if has_token_standard order.swap.from.token fa12_token then (None:operation option) - else if has_token_standard order.swap.from.token Constants.fa2_token then + else if has_token_standard order.swap.from.token fa2_token then Some (revoke_fa2_token_transfer order token_address batcher) else - failwith Errors.token_standard_not_found + failwith token_standard_not_found [@inline] let deposit_to_contract @@ -736,7 +707,7 @@ let deposit_to_contract (batcher:address): operation = let deposit = match Tezos.get_entrypoint_opt "%deposit" batcher with | Some ep -> ep - | None -> failwith Errors.entrypoint_does_not_exist + | None -> failwith entrypoint_does_not_exist in Tezos.transaction order 0mutez deposit @@ -745,10 +716,410 @@ let execute_deposit (order:external_swap_order) (batcher: address): operation list = match order.swap.from.token.address with - | None -> failwith Errors.xtz_not_currently_supported + | None -> failwith xtz_not_currently_supported | Some ta -> (let app = approve_token_transfer order ta batcher in let dep = deposit_to_contract order batcher in match revoke_token_transfer order ta batcher with | Some rev -> app :: (dep :: (rev :: [])) | None -> app:: (dep :: [] )) +[@inline] +let get_valid_swap_reduced + (pair_name: string) + (valid_swaps : ValidSwaps.t) : valid_swap_reduced = + match ValidSwaps.find_opt pair_name valid_swaps with + | Some vswp -> vswp + | None -> failwith swap_does_not_exist + + +module Token_Utils = struct + +[@inline] +let is_valid_swap_pair + (side: side) + (swap: swap_reduced) + (valid_swaps: ValidSwaps.t): swap_reduced = + let token_pair = pair_of_swap side swap in + let rate_name = get_rate_name_from_pair token_pair in + if ValidSwaps.mem rate_name valid_swaps then swap else failwith unsupported_swap_type + +[@inline] +let is_valid_swap_map_pair + (side: side) + (swap: swap_reduced) + (valid_swaps: ValidSwaps.t_map): swap_reduced = + let token_pair = pair_of_swap side swap in + let rate_name = get_rate_name_from_pair token_pair in + if Map.mem rate_name valid_swaps then swap else failwith unsupported_swap_type + +[@inline] +let remove_token + (token: token) + (valid_tokens: ValidTokens.t) : ValidTokens.t = + match ValidTokens.find_opt token.name valid_tokens with + | Some existing_token -> if are_equivalent_tokens existing_token token then + ValidTokens.remove token.name valid_tokens + else + failwith token_already_exists_but_details_are_different + | None -> valid_tokens + +[@inline] +let add_token + (token: token) + (valid_tokens: ValidTokens.t) : ValidTokens.t = + match ValidTokens.find_opt token.name valid_tokens with + | Some existing_token -> if are_equivalent_tokens existing_token token then + valid_tokens + else + failwith token_already_exists_but_details_are_different + | None -> ValidTokens.upsert token.name token valid_tokens + +[@inline] +let is_token_used + (token: token) + (valid_tokens: ValidTokens.t) : bool = + let is_token_in_tokens (acc, (_i, t) : bool * (string * token)) : bool = + are_equivalent_tokens token t || + acc + in + ValidTokens.fold is_token_in_tokens valid_tokens false + +[@inline] +let is_token_used_in_swaps + (token: token) + (valid_swaps: ValidSwaps.t) + (tokens: ValidTokens.t): bool = + let is_token_used_in_swap (acc, (_i, valid_swap) : bool * (string * valid_swap_reduced)) : bool = + let swap = valid_swap.swap in + let to_token = get_token swap.to tokens in + let from_token = get_token swap.from tokens in + are_equivalent_tokens token to_token || + are_equivalent_tokens token from_token || + acc + in + ValidSwaps.fold is_token_used_in_swap valid_swaps false + +[@inline] +let add_swap + (valid_swap: valid_swap) + (valid_swaps: ValidSwaps.t) : ValidSwaps.t = + let swap = valid_swap.swap in + let swap_reduced = swap_to_swap_reduced(swap) in + let rate_name = get_rate_name_from_swap swap_reduced in + let valid_swap_reduced = valid_swap_to_valid_swap_reduced valid_swap in + ValidSwaps.upsert rate_name valid_swap_reduced valid_swaps + +[@inline] +let remove_swap + (valid_swap: valid_swap) + (valid_tokens: ValidTokens.t) + (valid_swaps: ValidSwaps.t) : (ValidSwaps.t * ValidTokens.t) = + let swap = valid_swap.swap in + let swap_reduced = swap_to_swap_reduced(swap) in + let rate_name = get_rate_name_from_swap swap_reduced in + let valid_swaps = ValidSwaps.remove rate_name valid_swaps in + let from = get_token swap_reduced.from valid_tokens in + let to = get_token swap_reduced.to valid_tokens in + let valid_tokens = if is_token_used_in_swaps from valid_swaps valid_tokens then + valid_tokens + else + remove_token from valid_tokens + in + let valid_tokens = if is_token_used_in_swaps to valid_swaps valid_tokens then + valid_tokens + else + remove_token to valid_tokens + in + valid_swaps, valid_tokens + +end + +module Tokens = struct + +[@inline] +let validate_from_map + (side: side) + (swap: swap) + (valid_tokens: ValidTokens.t_map) + (valid_swaps: ValidSwaps.t_map): swap_reduced = + let from = swap.from.token in + let to = swap.to in + match Map.find_opt from.name valid_tokens with + | None -> failwith unsupported_swap_type + | Some ft -> (match Map.find_opt to.name valid_tokens with + | None -> failwith unsupported_swap_type + | Some tt -> if (are_equivalent_tokens from ft) && (are_equivalent_tokens to tt) then + let sr = swap_to_swap_reduced swap in + Token_Utils.is_valid_swap_map_pair side sr valid_swaps + else + failwith unsupported_swap_type) + +[@inline] +let validate + (side: side) + (swap: swap) + (valid_tokens: ValidTokens.t) + (valid_swaps: ValidSwaps.t): swap_reduced = + let from = swap.from.token in + let to = swap.to in + match ValidTokens.find_opt from.name valid_tokens with + | None -> failwith unsupported_swap_type + | Some ft -> (match ValidTokens.find_opt to.name valid_tokens with + | None -> failwith unsupported_swap_type + | Some tt -> if (are_equivalent_tokens from ft) && (are_equivalent_tokens to tt) then + let sr = swap_to_swap_reduced swap in + Token_Utils.is_valid_swap_pair side sr valid_swaps + else + failwith unsupported_swap_type) + +[@inline] +let check_tokens_size_or_fail + (tokens_size: nat) + (limit_on_tokens_or_pairs: nat) + (num_tokens: nat) : unit = if tokens_size + num_tokens > limit_on_tokens_or_pairs then failwith upper_limit_on_tokens_has_been_reached else () + +[@inline] +let can_add + (to: token) + (from: token) + (limit_on_tokens_or_pairs: nat) + (valid_tokens: ValidTokens.t) + (valid_swaps: ValidSwaps.t): unit = + let pairs_size = ValidSwaps.size valid_swaps in + if pairs_size + 1n > limit_on_tokens_or_pairs then failwith upper_limit_on_swap_pairs_has_been_reached else + let tokens_size = ValidTokens.size valid_tokens in + let unused_tokens_being_added = + if Token_Utils.is_token_used to valid_tokens && Token_Utils.is_token_used from valid_tokens then 0n else + if Token_Utils.is_token_used to valid_tokens || Token_Utils.is_token_used from valid_tokens then 1n else + 2n + in + check_tokens_size_or_fail tokens_size limit_on_tokens_or_pairs unused_tokens_being_added + +[@inline] +let remove_pair + (valid_swap: valid_swap) + (valid_swaps: ValidSwaps.t) + (valid_tokens: ValidTokens.t) : ValidSwaps.t * ValidTokens.t = + let swap = valid_swap.swap in + let swap_reduced = swap_to_swap_reduced swap in + let rate_name = get_rate_name_from_swap swap_reduced in + let rate_found = ValidSwaps.find_opt rate_name valid_swaps in + match rate_found with + | Some _ -> Token_Utils.remove_swap valid_swap valid_tokens valid_swaps + | None -> failwith swap_does_not_exist + +[@inline] +let add_pair + (limit_on_tokens_or_pairs: nat) + (valid_swap: valid_swap) + (valid_swaps: ValidSwaps.t) + (valid_tokens: ValidTokens.t) : ValidSwaps.t * ValidTokens.t = + let swap = valid_swap.swap in + let from = swap.from.token in + let to = swap.to in + let () = can_add to from limit_on_tokens_or_pairs valid_tokens valid_swaps in + let swap_reduced = swap_to_swap_reduced swap in + let rate_name = get_rate_name_from_swap swap_reduced in + let rate_found = ValidSwaps.find_opt rate_name valid_swaps in + match rate_found with + | Some _ -> failwith swap_already_exists + | None -> let valid_tokens = Token_Utils.add_token from valid_tokens in + let valid_tokens = Token_Utils.add_token to valid_tokens in + let valid_swaps = Token_Utils.add_swap valid_swap valid_swaps in + valid_swaps, valid_tokens + + +end + +module TokenManagerUtils = struct + +[@inline] +let get_valid_tokens + (tokenmanager: address) : ValidTokens.t_map = + match Tezos.call_view "get_valid_tokens" () tokenmanager with + | Some tokns -> tokns + | None -> failwith unable_to_get_tokens_from_token_manager + +[@inline] +let get_valid_swaps + (tokenmanager: address) : ValidSwaps.t_map = + match Tezos.call_view "get_valid_swaps" () tokenmanager with + | Some swaps -> swaps + | None -> failwith unable_to_get_swaps_from_token_manager + +end + +module MarketMakerUtils = struct + +[@inline] +let get_current_vaults + (marketmaker: address) : Vaults.t_map = + match Tezos.call_view "get_vaults" () marketmaker with + | Some vaults -> vaults + | None -> failwith unable_to_get_vaults_from_marketmaker + + +end + +module BatcherUtils = struct + +[@inline] +let get_batches_needing_liquidity + (batcher:address): batch list = + match Tezos.call_view "get_current_batches" () batcher with + | Some batches -> batches + | None -> failwith unable_to_get_current_batches_from_batcher + +end + + +module OracleUtils = struct + +[@inline] +let get_oracle_price + (failure_code: nat) + (valid_swap: valid_swap_reduced) : orace_price_update = + match Tezos.call_view "getPrice" valid_swap.oracle_asset_name valid_swap.oracle_address with + | Some opu -> opu + | None -> failwith failure_code + +[@inline] +let oracle_price_is_not_stale + (deposit_time_window: nat) + (oracle_price_timestamp: timestamp) : unit = + let dtw_i = int deposit_time_window in + if (Tezos.get_now () - dtw_i) < oracle_price_timestamp then () else failwith oracle_price_is_stale + +[@inline] +let is_oracle_price_newer_than_current + (rate_name: string) + (oracle_price_timestamp: timestamp) + (rates: rates_current): unit = + match Big_map.find_opt rate_name rates with + | Some r -> if r.when >=oracle_price_timestamp then failwith oracle_price_is_not_timely + | None -> () + +[@inline] +let convert_oracle_price + (precision: nat) + (swap: swap) + (lastupdated: timestamp) + (price: nat) + (tokens: ValidTokens.t_map): exchange_rate = + let prc,den : nat * int = if swap.from.token.decimals > precision then + let diff:int = swap.from.token.decimals - precision in + let diff_pow = pow 10 diff in + let adj_price = to_nat (price * diff_pow) in + let denom = pow 10 (int swap.from.token.decimals) in + (adj_price, denom) + else + let denom = pow 10 (int precision) in + (price, denom) + in + let rational_price = Rational.new (int prc) in + let rational_denom = Rational.new den in + let rational_rate: Rational.t = Rational.div rational_price rational_denom in + let swap_reduced: swap_reduced = swap_to_swap_reduced swap in + let rate = { + swap = swap_reduced; + rate = rational_rate; + when = lastupdated; + } in + scale_on_receive_for_token_precision_difference rate tokens + +end + + +[@inline] +let get_native_token_from_vault + (vault_address: address) : token = + match Tezos.call_view "get_native_token_of_vault" () vault_address with + | Some tokn -> tokn + | None -> failwith unable_to_get_native_token_from_vault + +[@inline] +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 + +[@inline] +let send_add_reward + (amount: tez) + (vault:address) : operation = + let rew_req_ent = match Tezos.get_entrypoint_opt "%addreward" vault with + | Some ep -> ep + | None -> failwith entrypoint_does_not_exist + in + Tezos.transaction amount amount rew_req_ent + + +[@inline] +let entrypoints_exist + (callback: address) + (token_fa12_addr: address) + (token_fa2_addr: address) : bool * bool * bool * bool = + let bo_fa2_opt: balance_of contract option = Tezos.get_entrypoint_opt "%balance_of" token_fa2_addr in + let cb_fa2_opt: balance_of_responses contract option = Tezos.get_entrypoint_opt "%balance_response_fa2" callback in + let bo_fa12_opt: get_balance_request contract option = Tezos.get_entrypoint_opt "%getBalance" token_fa12_addr in + let cb_fa12_opt: nat contract option = Tezos.get_entrypoint_opt "%balance_response_fa12" callback in + (is_some bo_fa2_opt),(is_some cb_fa2_opt),(is_some bo_fa12_opt),(is_some cb_fa12_opt) + + +[@inline] + let getfa2tokenbalance + (owner: address) + (callback: address) + (token_id: nat) + (token_addr: address) : operation = + let balance_req = { + owner= owner; + token_id = token_id; + } in + let bo_opt: balance_of contract option = Tezos.get_entrypoint_opt "%balance_of" token_addr in + let cb_opt: balance_of_responses contract option = Tezos.get_entrypoint_opt "%balance_response_fa2" callback in + match cb_opt,bo_opt with + | None, _ -> failwith unable_to_get_balance_response_fa2_entrypoint_from_vault + | _, None -> failwith unable_to_get_balance_of_entrypoint_from_fa2_token + | Some cb, Some bo -> let bp : balance_of = { + requests = [ balance_req ]; + callback = cb; + } in + Tezos.transaction bp 0mutez bo + +[@inline] + let getfa12tokenbalance + (owner: address) + (callback: address) + (token_addr: address) : operation = + let cb_opt: nat contract option = Tezos.get_entrypoint_opt "%balance_response_fa12" callback in + let bo_opt = Tezos.get_entrypoint_opt "%getBalance" token_addr in + match cb_opt,bo_opt with + | None, _ -> failwith unable_to_get_balance_response_fa12_entrypoint_from_vault + | _, None -> failwith unable_to_get_get_balance_entrypoint_from_fa12_token + | Some cb, Some bo -> let br = (owner, cb) in + Tezos.transaction br 0mutez bo + + + [@inline] + let gettokenbalance + (owner: address) + (callback: address) + (token_id: nat) + (token_addr_opt: address option) + (token_standard_opt: string option) : operation = + let token_addr = assert_some_or_fail_with token_addr_opt invalid_token_address in + let token_standard = assert_some_or_fail_with token_standard_opt token_standard_not_found in + if token_standard = "FA1.2 token" then getfa12tokenbalance owner callback token_addr else + if token_standard = "FA2 token" then getfa2tokenbalance owner callback token_id token_addr else + failwith token_standard_not_found diff --git a/batcher/vault.mligo b/batcher/vault.mligo new file mode 100644 index 00000000..e47fd058 --- /dev/null +++ b/batcher/vault.mligo @@ -0,0 +1,407 @@ +#import "@ligo/math-lib/rational/rational.mligo" "Rational" +#include "types.mligo" +#include "utils.mligo" +#include "errors.mligo" + +module Vault = struct + + +type storage = { + total_shares: nat; + native_token: token_amount; + foreign_tokens: token_amount_map; + administrator : address; + batcher : address; + marketmaker : address; + tokenmanager : address; + vault_holdings: VaultHoldings.t; +} + +type result = operation list * storage + +[@inline] +let no_op (s : storage) : result = (([] : operation list), s) + + +[@inline] +let assert_balances + (storage:storage) : operation list = + let vault_address = Tezos.get_self_address () in + let nta = storage.native_token in + let nt = nta.token in + let ft = storage.foreign_tokens in + let ntop = gettokenbalance vault_address vault_address nt.token_id nt.address nt.standard in + let trigger_balance_update (ops,(_name,ta): (operation list * (string * token_amount))) : operation list = + (gettokenbalance vault_address vault_address ta.token.token_id ta.token.address ta.token.standard) :: ops + in + Map.fold trigger_balance_update ft [ ntop ] + + + + +[@inline] +let deposit + (deposit_address : address) + (deposited_token : token_amount) + (_storage:storage): operation list = + let treasury_vault = get_vault () in + let deposit_op = Treasury_Utils.handle_transfer deposit_address treasury_vault deposited_token in + (* let bal_ops = assert_balances storage in + deposit_op :: bal_ops *) + [ deposit_op ] + +[@inline] +let find_liquidity_amount + (rate:exchange_rate) + (total_liquidity:nat) + (volume:nat) : nat = + let rat_volume = Rational.new (int volume) in + let equiv_vol = Rational.mul rate.rate rat_volume in + let resolved_equiv_vol = get_rounded_number_lower_bound equiv_vol in + if total_liquidity > resolved_equiv_vol then resolved_equiv_vol else total_liquidity + +[@inline] +let create_liq_order + (bn:nat) + (non:nat) + (from:string) + (to:string) + (side:side) + (liq:nat) + (valid_tokens: (string,token) map): swap_order = + let from_token = Option.unopt (Map.find_opt from valid_tokens) in + let to_token = Option.unopt (Map.find_opt to valid_tokens) in + { + order_number = non; + batch_number = bn; + trader = get_vault (); + swap = { + from = { + token = from_token; + amount = liq; + }; + to = to_token; + }; + side=side; + tolerance = Exact; + redeemed = false; + } + +[@inline] +let add_or_update_liquidity + (holder: address) + (token_amount: token_amount) + (storage: storage): storage = + let nt = storage.native_token in + if not are_equivalent_tokens token_amount.token nt.token then failwith token_already_exists_but_details_are_different else + let shares = storage.total_shares + token_amount.amount in + let native_token = { nt with amount = nt.amount + token_amount.amount; } in + let new_holding = match VaultHoldings.find_opt holder storage.vault_holdings with + | None -> { + holder = holder; + shares = token_amount.amount; + unclaimed = 0mutez; + } + | Some ph -> let nshares = ph.shares + token_amount.amount in + { ph with shares = nshares;} + in + let vhs = VaultHoldings.upsert holder new_holding storage.vault_holdings in + { storage with + total_shares = shares ; + vault_holdings = vhs; + native_token = native_token; + } + +[@inline] +let collect_from_vault + (perc_share: Rational.t) + (ta: token_amount) + (tam: token_amount_map): (token_amount * token_amount_map) = + let rat_amt = Rational.new (int ta.amount) in + let rat_amount_to_redeem = Rational.mul perc_share rat_amt in + let amount_to_redeem = get_rounded_number_lower_bound rat_amount_to_redeem in + if amount_to_redeem > ta.amount then failwith holding_amount_to_redeem_is_larger_than_holding else + let rem =abs ((int ta.amount) - amount_to_redeem) in + let ta_rem = {ta with amount = rem; } in + let ta_red = {ta with amount = amount_to_redeem; } in + let tam = if ta_red.amount = 0n then tam else TokenAmountMap.increase ta_red tam in + (ta_rem, tam) + +[@inline] +let collect_tokens_for_redemption + (perc_share: Rational.t) + (shares: nat) + (storage: storage) = + let tokens = TokenAmountMap.new in + let (native,tokens_to_red) = collect_from_vault perc_share storage.native_token tokens in + let acc: (Rational.t * token_amount_map * token_amount_map) = (perc_share, TokenAmountMap.new, tokens_to_red ) in + let collect_redemptions = fun ((ps,rem_t,red_t),(_tn,ta):(Rational.t * token_amount_map * token_amount_map) * (string * token_amount)) -> + let (ta_rem,red_t) = collect_from_vault ps ta red_t in + let rem_t = TokenAmountMap.increase ta_rem rem_t in + (ps,rem_t,red_t) + in + let (_, foreign_tokens, tokens) = Map.fold collect_redemptions storage.foreign_tokens acc in + if shares > storage.total_shares then failwith holding_shares_greater_than_total_shares_remaining else + let rem_shares = abs (storage.total_shares - shares) in + ({ storage with native_token = native; foreign_tokens = foreign_tokens; total_shares = rem_shares;} ,tokens) + +[@inline] +let remove_liquidity_from_market_maker + (holder: address) + (storage: storage): ( operation list * storage) = + match VaultHoldings.find_opt holder storage.vault_holdings with + | None -> failwith no_holding_in_market_maker_for_holder + | Some holding -> let unclaimed_tez = holding.unclaimed in + let shares = holding.shares in + let total_shares = storage.total_shares in + let perc_share = Rational.div (Rational.new (int shares)) (Rational.new (int total_shares)) in + let (storage, tam) = collect_tokens_for_redemption perc_share shares storage in + let tez_op = Treasury_Utils.transfer_fee holder unclaimed_tez in + let treasury_vault = get_vault () in + let tok_ops = Treasury_Utils.transfer_holdings treasury_vault holder tam in + let vault_holdings = VaultHoldings.remove holder storage.vault_holdings in + (* let bal_ops = assert_balances storage in *) + let ops: operation list =if unclaimed_tez > 0mutez then tez_op :: tok_ops else tok_ops in + (* let ops = concatlo trans_ops bal_ops in *) + let storage = { storage with vault_holdings = vault_holdings; } in + (ops, storage) + +[@inline] +let claim_from_holding + (holding: vault_holding) + (storage: storage) : (operation list * storage) = + let unclaimed_tez = holding.unclaimed in + if unclaimed_tez = 0mutez then failwith no_holdings_to_claim else + let holding = { holding with unclaimed = 0tez; } in + let tez_op = Treasury_Utils.transfer_fee holding.holder unclaimed_tez in + let vault_holdings = VaultHoldings.upsert holding.holder holding storage.vault_holdings in + let storage = {storage with vault_holdings = vault_holdings;} in + ([tez_op], storage) + +let claim_rewards + (holder:address) + (storage:storage) : (operation list * storage) = + match VaultHoldings.find_opt holder storage.vault_holdings with + | None -> failwith no_holdings_to_claim + | Some h -> claim_from_holding h storage + +(* Add Liquidity into a market vault *) +[@inline] +let add_liquidity + (amount: nat) + (storage: storage) : result = + let () = reject_if_tez_supplied () in + let holder = Tezos.get_sender () in + let token_amount = { storage.native_token with amount = amount; } in + let ops = deposit holder token_amount storage in + let storage = add_or_update_liquidity holder token_amount storage in + ops,storage + +(* Add Liquidity into a market vault *) +[@inline] +let claim + (storage: storage) : result = + let () = reject_if_tez_supplied () in + let holder = Tezos.get_sender () in + claim_rewards holder storage + +(* Remove Liquidity into a market vault *) +[@inline] +let remove_liquidity + (storage: storage) : result = + let () = reject_if_tez_supplied () in + let holder = Tezos.get_sender () in + remove_liquidity_from_market_maker holder storage + +[@inline] +let change_admin_address + (new_admin_address: address) + (storage: storage) : result = + 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 + +[@inline] +let change_batcher_address + (new_batcher_address: address) + (storage: storage) : result = + 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 + +[@inline] +let construct_order + (side:side) + (from_token:token) + (to_token:token) + (amount:nat) : external_swap_order = + let side_nat = side_to_nat side in + let tolerance = tolerance_to_nat Exact in + let swap = { + from= { + token = from_token; + amount= amount + }; + to = to_token; + } in + { + swap = swap; + created_at = Tezos.get_now (); + side = side_nat; + tolerance = tolerance; + } + +[@inline] +let inject_liquidity + (lir: liquidity_injection_request) + (storage: storage) : result = + let () = is_known_sender storage.marketmaker sender_not_marketmaker in + let () = reject_if_tez_supplied () in + let o = construct_order lir.side lir.from_token lir.to_token lir.amount in + let dep_ops = execute_deposit o storage.batcher in + let bal_ops = assert_balances storage in + let ops = concatlo dep_ops bal_ops in + ops, storage + +[@inline] +let add_reward + (reward: tez) + (storage: storage) : result = + let rat_total_shares = Rational.new (int storage.total_shares) in + let int_tez_reward: int = int (reward / 1mutez) in + let rat_tez_reward = Rational.new int_tez_reward in + let add_rewards = fun (holdings,(addr,holding):VaultHoldings.t * (VaultHoldings.key * VaultHoldings.value)) -> + let rat_shares = Rational.new (int holding.shares) in + let perc_share = Rational.div rat_shares rat_total_shares in + let rew_to_user = Rational.mul perc_share rat_tez_reward in + let rew_to_user_in_tez = 1mutez * (get_rounded_number_lower_bound rew_to_user) in + let updated_rewards =if rew_to_user_in_tez > 0mutez then holding.unclaimed + rew_to_user_in_tez else holding.unclaimed in + let new_holding = { holding with unclaimed = updated_rewards; } in + VaultHoldings.upsert addr new_holding holdings + in + let vault_holdings = VaultHoldings.fold add_rewards storage.vault_holdings VaultHoldings.empty in + let storage = { storage with vault_holdings=vault_holdings; } in + no_op storage + + +[@inline] +let change_marketmaker_address + (new_marketmaker_address: address) + (storage: storage) : result = + let () = is_known_sender storage.administrator sender_not_administrator in + let () = reject_if_tez_supplied () in + let storage = { storage with marketmaker = new_marketmaker_address; } in + no_op storage + +[@inline] +let change_tokenmanager_address + (new_tokenmanager_address: address) + (storage: storage) : result = + let () = is_known_sender storage.administrator sender_not_administrator in + let () = reject_if_tez_supplied () in + let storage = { storage with tokenmanager = new_tokenmanager_address; } in + no_op storage + +[@inline] +let update_native_token_balance + (token_address: address) + (amount:nat) + (token_id: nat) + (storage:storage): storage = + let nta = assert_some_or_fail_with storage.native_token.token.address invalid_token_address in + if nta = token_address && storage.native_token.token.token_id = token_id then + let nt = { storage.native_token with amount=amount;} in + { storage with native_token = nt;} + else + storage + +[@inline] +let update_foreign_token_balances + (token_address: address) + (amount:nat) + (token_id: nat) + (storage:storage): storage = + let fts = storage.foreign_tokens in + let update_bals (fts, (_name,ta): token_amount_map * (string * token_amount)) : token_amount_map = + let ta_addr = assert_some_or_fail_with ta.token.address invalid_token_address in + if ta_addr = token_address && ta.token.token_id = token_id then + let ta = {ta with amount = amount;} in + Map.update ta.token.name (Some ta) fts + else + fts + in + let fts = Map.fold update_bals fts fts in + { storage with foreign_tokens = fts; } + +[@inline] +let process_balance_response_fa12 + (amount: nat) + (storage:storage): result = + let token_contract = Tezos.get_sender () in + let storage = update_native_token_balance token_contract amount 0n storage in + let storage = update_foreign_token_balances token_contract amount 0n storage in + no_op storage + +[@inline] +let process_balance_response_fa2 + (rs: balance_of_response list) + (storage:storage): result = + let token_contract = Tezos.get_sender () in + let process_responses (s,r:storage * balance_of_response):storage = + let amount = r.balance in + let token_id = r.request.token_id in + let s = update_native_token_balance token_contract amount token_id s in + update_foreign_token_balances token_contract amount token_id s in + let storage = List.fold process_responses rs storage in + no_op storage + +end + +[@view] +let get_native_token_of_vault ((),storage: unit * Vault.storage) : token = storage.native_token.token + +[@view] +let check_entrypoints ((fa2token,fa12token),_storage: (address * address) * Vault.storage) : bool * bool * bool * bool = + let vault_address = Tezos.get_self_address () in + entrypoints_exist vault_address fa12token fa2token + + + +type entrypoint = + | AddLiquidity of nat + | RemoveLiquidity + | Claim + | AddReward of tez + | InjectLiquidity of liquidity_injection_request + | AssertBalances + | Balance_response_fa2 of balance_of_responses + | Balance_response_fa12 of nat + | Change_admin_address of address + | Change_batcher_address of address + | Change_marketmaker_address of address + | Change_tokenmanager_address of address + +let main + (action, storage : entrypoint * Vault.storage) : operation list * Vault.storage = + match action with + (* Market Liquidity endpoint *) + | AddLiquidity a -> Vault.add_liquidity a storage + | RemoveLiquidity -> Vault.remove_liquidity storage + | Claim -> Vault.claim storage + (* Batcher endpoints *) + | AddReward r -> Vault.add_reward r storage + (* MarketMaker endpoints *) + | InjectLiquidity lir -> Vault.inject_liquidity lir storage + (* Balance endpoints *) + | AssertBalances -> (Vault.assert_balances storage, storage) + | Balance_response_fa2 r -> Vault.process_balance_response_fa2 r storage + | Balance_response_fa12 r -> Vault.process_balance_response_fa12 r storage + (* Admin endpoints *) + | Change_admin_address new_admin_address -> Vault.change_admin_address new_admin_address storage + | Change_batcher_address new_batcher_address -> Vault.change_batcher_address new_batcher_address storage + | Change_marketmaker_address new_marketmaker_address -> Vault.change_marketmaker_address new_marketmaker_address storage + | Change_tokenmanager_address new_tokenmanager_address -> Vault.change_tokenmanager_address new_tokenmanager_address storage + +