Skip to content

Commit

Permalink
Added debug view to vault to test token balance endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
glottologist committed Oct 30, 2023
1 parent a4103f6 commit a9c1535
Show file tree
Hide file tree
Showing 10 changed files with 523 additions and 575 deletions.
8 changes: 5 additions & 3 deletions batcher/errors.mligo
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@
[@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 unable_to_get_response_entrypoint_from_vault : nat = 169n
[@inline] let unable_to_get_balance_of_entrypoint_from_token : nat = 170n
[@inline] let cannot_update_liquidity_injection_limit_to_more_than_deposit_window= 171n
[@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
2 changes: 1 addition & 1 deletion batcher/michelson/batcher-ghostnet.tz
Original file line number Diff line number Diff line change
Expand Up @@ -944,7 +944,7 @@
DUP 2 ;
COMPARE ;
GT ;
IF { DROP 2 ; PUSH nat 171 ; FAILWITH }
IF { DROP 2 ; PUSH nat 169 ; FAILWITH }
{ DUP 2 ;
DIG 2 ;
CAR ;
Expand Down
203 changes: 93 additions & 110 deletions batcher/michelson/btctz-vault-ghostnet.tz

Large diffs are not rendered by default.

203 changes: 93 additions & 110 deletions batcher/michelson/eurl-vault-ghostnet.tz

Large diffs are not rendered by default.

203 changes: 93 additions & 110 deletions batcher/michelson/tzbtc-vault-ghostnet.tz

Large diffs are not rendered by default.

203 changes: 93 additions & 110 deletions batcher/michelson/usdt-vault-ghostnet.tz

Large diffs are not rendered by default.

203 changes: 93 additions & 110 deletions batcher/michelson/usdtz-vault-ghostnet.tz

Large diffs are not rendered by default.

30 changes: 16 additions & 14 deletions batcher/types.mligo
Original file line number Diff line number Diff line change
Expand Up @@ -619,23 +619,25 @@ type liquidity_injection_request = {
amount:nat;
}

type balance_of_request = {
owner: address;
token_id: nat;
}
type get_balance_request =
[@layout:comb]
{ owner : address;
callback : nat contract }

type balance_of_response = {
request: balance_of_request;
balance: nat;
type balance_request = {
owner : address;
token_id : nat;
}

type balance_of_param = {
requests: balance_of_request list;
callback: (balance_of_response list) contract;
type balance_of_response =
[@layout:comb] {
request : balance_request;
balance : nat;
}





type balance_of =
[@layout:comb] {
requests : balance_request list;
callback : balance_of_response list contract;
}

36 changes: 29 additions & 7 deletions batcher/utils.mligo
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,14 @@ let scale_on_receive_for_token_precision_difference
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)
Expand Down Expand Up @@ -1054,7 +1062,20 @@ let send_add_reward
| 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_response 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)
Expand All @@ -1065,11 +1086,11 @@ let send_add_reward
owner= owner;
token_id = token_id;
} in
let cb_opt : balance_of_response list contract option = Tezos.get_entrypoint_opt "%balance_response_fa2" callback in
let bo_opt = Tezos.get_entrypoint_opt "%balance_of" token_addr in
let cb_opt : balance_of_response list contract option = Tezos.get_entrypoint_opt "%balance_response_fa2" callback in
match cb_opt,bo_opt with
| None, _ -> failwith unable_to_get_response_entrypoint_from_vault
| _, None -> failwith unable_to_get_balance_of_entrypoint_from_token
| 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 = {
requests = [ balance_req ];
callback = cb;
Expand All @@ -1081,17 +1102,18 @@ let send_add_reward
(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
let cb_opt: nat contract option = Tezos.get_entrypoint_opt "%balance_response_fa12" callback in
match cb_opt,bo_opt with
| None, _ -> failwith unable_to_get_response_entrypoint_from_vault
| _, None -> failwith unable_to_get_balance_of_entrypoint_from_token
| 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 = owner;
callback = cb;
} in
Tezos.transaction br 0mutez bo


[@inline]
let gettokenbalance
(owner: address)
Expand Down
7 changes: 7 additions & 0 deletions batcher/vault.mligo
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,13 @@ 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
Expand Down

0 comments on commit a9c1535

Please sign in to comment.