Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the delegate from the burrow representation #238

Merged
merged 2 commits into from
Aug 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions docs/spec/burrow-state-liquidations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ State
it’s considered “inactive”.
- ``address``: the address of the contract holding the burrow's collateral and
creation deposit.
- ``delegate``: the delegate for the amount of tez (collateral + creation
deposit) the burrow holds.
- ``collateral``: the amount of tez stored in the burrow. Collateral
that has been sent to auctions **does not** count towards this
amount; for all we know, it’s gone forever.
Expand Down
15 changes: 2 additions & 13 deletions src/burrow.ml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ type burrow =
active : bool;
(* Address of the contract holding the burrow's collateral. *)
address: Ligo.address;
(* The delegate for the tez (collateral + creation_deposit) the burrow
* holds. *) (* TOKFIX: Should be part of the wrapper contract. *)
delegate : Ligo.key_hash option;
(* Collateral currently stored in the burrow. *)
collateral : tok;
(* Outstanding kit minted out of the burrow. *)
Expand Down Expand Up @@ -176,13 +173,12 @@ let burrow_return_kit_from_auction
assert (eq_kit_kit (kit_add returned_kit excess_kit) kit);
(burrow_out, returned_kit, excess_kit)

let burrow_create (p: parameters) (addr: Ligo.address) (tok: tok) (delegate_opt: Ligo.key_hash option) : burrow =
let burrow_create (p: parameters) (addr: Ligo.address) (tok: tok) : burrow =
if lt_tok_tok tok creation_deposit
then (Ligo.failwith error_InsufficientFunds : burrow)
else
{ active = true;
address = addr;
delegate = delegate_opt;
collateral = tok_sub tok creation_deposit;
outstanding_kit = kit_zero;
adjustment_index = compute_adjustment_index p;
Expand Down Expand Up @@ -278,12 +274,6 @@ let burrow_deactivate (p: parameters) (b: burrow) : (burrow * tok) =
assert (b.address = burrow_out.address);
burrow_out, return

let burrow_set_delegate (p: parameters) (new_delegate: Ligo.key_hash option) (b: burrow) : burrow =
let b = burrow_touch p b in
let burrow_out = { b with delegate = new_delegate; } in
assert (b.address = burrow_out.address);
burrow_out

(* ************************************************************************* *)
(** LIQUIDATION-RELATED *)
(* ************************************************************************* *)
Expand Down Expand Up @@ -566,13 +556,12 @@ let burrow_active (b: burrow) : bool =
let make_burrow_for_test
~active
~address
~delegate
~collateral
~outstanding_kit
~adjustment_index
~collateral_at_auction
~last_checker_timestamp =
{ delegate = delegate;
{
address = address;
active = active;
collateral = collateral;
Expand Down
6 changes: 1 addition & 5 deletions src/burrow.mli
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ val burrow_return_slice_from_auction : LiquidationAuctionPrimitiveTypes.liquidat
(** Given an amount of collateral (including a creation deposit, not counting
* towards that collateral), create a burrow with its owner set to the input
* address. Fail if the collateral given is less than the creation deposit. *)
val burrow_create : parameters -> Ligo.address -> tok -> Ligo.key_hash option -> burrow
val burrow_create : parameters -> Ligo.address -> tok -> burrow

(** Add non-negative collateral to a burrow. *)
val burrow_deposit_collateral : parameters -> tok -> burrow -> burrow
Expand All @@ -105,9 +105,6 @@ val burrow_activate : parameters -> tok -> burrow -> burrow
* outstanding, or (d) has collateral sent off to auctions. *)
val burrow_deactivate : parameters -> burrow -> (burrow * tok)

(** Set the delegate of a burrow. *)
val burrow_set_delegate : parameters -> Ligo.key_hash option -> burrow -> burrow

(* ************************************************************************* *)
(* Liquidation-related *)
(* ************************************************************************* *)
Expand Down Expand Up @@ -154,7 +151,6 @@ val burrow_active : burrow -> bool
val make_burrow_for_test :
active:bool ->
address:Ligo.address ->
delegate:(Ligo.key_hash option) ->
collateral:tok ->
outstanding_kit:kit ->
adjustment_index:fixedpoint ->
Expand Down
4 changes: 1 addition & 3 deletions src/checker.ml
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ let[@inline] entrypoint_create_burrow (state, (burrow_no, delegate_opt): checker
!Ligo.Tezos.amount (* NOTE!!! The creation deposit is in the burrow too, even if we don't consider it to be collateral! *)
{checker_address = !Ligo.Tezos.self_address; burrow_id = burrow_id; } in

let burrow = burrow_create state.parameters burrow_address (tok_of_tez !Ligo.Tezos.amount) delegate_opt in
let burrow = burrow_create state.parameters burrow_address (tok_of_tez !Ligo.Tezos.amount) in
let state = {state with burrows = Ligo.Big_map.update burrow_id (Some burrow) state.burrows} in
assert_checker_invariants state;
([op], state)
Expand Down Expand Up @@ -283,11 +283,9 @@ let entrypoint_set_burrow_delegate (state, (burrow_no, delegate_opt): checker *
let burrow_id = (!Ligo.Tezos.sender, burrow_no) in
let burrow = find_burrow state.burrows burrow_id in
let _ = ensure_burrow_has_no_unclaimed_slices state.liquidation_auctions burrow_id in
let burrow = burrow_set_delegate state.parameters delegate_opt burrow in
let op = match (LigoOp.Tezos.get_entrypoint_opt "%burrowSetDelegate" (burrow_address burrow) : Ligo.key_hash option Ligo.contract option) with
| Some c -> LigoOp.Tezos.opt_key_hash_transaction delegate_opt (Ligo.tez_from_literal "0mutez") c
| None -> (Ligo.failwith error_GetEntrypointOptFailureBurrowSetDelegate : LigoOp.operation) in
let state = {state with burrows = Ligo.Big_map.update burrow_id (Some burrow) state.burrows} in
assert_checker_invariants state;
([op], state)

Expand Down
49 changes: 3 additions & 46 deletions tests/testBurrow.ml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ let make_test_burrow ~outstanding_kit ~collateral ~active = Burrow.make_burrow_f
~outstanding_kit:outstanding_kit
~active:active
~address:burrow_addr
~delegate:None
~collateral:collateral
~adjustment_index:fixedpoint_one
~collateral_at_auction:tok_zero
Expand Down Expand Up @@ -111,30 +110,6 @@ let suite =
~real:(Burrow.burrow_address burrow)
);

("burrow_set_delegate - does not fail for a burrow which needs to be touched" >::
fun _ ->
let _ =
Burrow.burrow_set_delegate
{Parameters.initial_parameters with last_touched=(Ligo.timestamp_from_seconds_literal 1)}
(Some charles_key_hash)
burrow_for_needs_touch_tests
in ()
);

("burrow_set_delegate - does not change burrow address" >::
fun _ ->
let burrow0 = make_test_burrow
~outstanding_kit:kit_zero
~active:true
~collateral:tok_zero in

let burrow = Burrow.burrow_set_delegate Parameters.initial_parameters (Some charles_key_hash) burrow0 in

assert_address_equal
~expected:(Burrow.burrow_address burrow0)
~real:(Burrow.burrow_address burrow)
);

("burrow_deposit_collateral - does not fail for a burrow which needs to be touched" >::
fun _ ->
let _ =
Expand Down Expand Up @@ -446,7 +421,6 @@ let suite =
~outstanding_kit:(kit_of_denomination (Ligo.nat_from_literal "0n"))
~active:true
~address:burrow_addr
~delegate:None
~collateral:(tok_of_denomination (Ligo.nat_from_literal "10n"))
~adjustment_index:fixedpoint_one
~collateral_at_auction:(tok_of_denomination (Ligo.nat_from_literal "1n"))
Expand Down Expand Up @@ -481,7 +455,7 @@ let suite =
(* Note: this is a bit overkill but testing anyways since the address field is extremely important *)
("burrow_create - address matches provided address" >::
fun _ ->
let burrow = Burrow.burrow_create Parameters.initial_parameters burrow_addr Constants.creation_deposit None in
let burrow = Burrow.burrow_create Parameters.initial_parameters burrow_addr Constants.creation_deposit in

assert_address_equal
~expected:burrow_addr
Expand All @@ -492,7 +466,7 @@ let suite =
(
"burrow_create - created burrow has zero collateral at auction" >::
fun _ ->
let burrow = Burrow.burrow_create Parameters.initial_parameters burrow_addr Constants.creation_deposit None in
let burrow = Burrow.burrow_create Parameters.initial_parameters burrow_addr Constants.creation_deposit in

assert_tok_equal
~expected:tok_zero
Expand All @@ -502,7 +476,7 @@ let suite =
(
"burrow_create - created burrow has zero outstanding kit" >::
fun _ ->
let burrow = Burrow.burrow_create Parameters.initial_parameters burrow_addr Constants.creation_deposit None in
let burrow = Burrow.burrow_create Parameters.initial_parameters burrow_addr Constants.creation_deposit in

assert_kit_equal
~expected:kit_zero
Expand Down Expand Up @@ -533,7 +507,6 @@ let suite =
~outstanding_kit:(kit_of_denomination (Ligo.nat_from_literal "1n"))
~active:true
~address:burrow_addr
~delegate:None
~collateral:tok_zero
~adjustment_index:fixedpoint_one
~collateral_at_auction:(tok_of_denomination (Ligo.nat_from_literal "1n"))
Expand All @@ -557,7 +530,6 @@ let suite =
~outstanding_kit:(kit_of_denomination (Ligo.nat_from_literal "2n"))
~active:true
~address:burrow_addr
~delegate:None
~collateral:(tok_of_denomination (Ligo.nat_from_literal "2n"))
~adjustment_index:fixedpoint_one
~collateral_at_auction:(tok_of_denomination (Ligo.nat_from_literal "3n"))
Expand All @@ -572,7 +544,6 @@ let suite =
~outstanding_kit:(kit_of_denomination (Ligo.nat_from_literal "2n"))
~active:true
~address:burrow_addr
~delegate:None
~collateral:(tok_of_denomination (Ligo.nat_from_literal "3n"))
~adjustment_index:fixedpoint_one
~collateral_at_auction:(tok_of_denomination (Ligo.nat_from_literal "2n"))
Expand All @@ -590,7 +561,6 @@ let suite =
~outstanding_kit:(kit_of_denomination (Ligo.nat_from_literal "1n"))
~active:true
~address:burrow_addr
~delegate:None
~collateral:tok_zero
~adjustment_index:fixedpoint_one
~collateral_at_auction:(tok_of_denomination (Ligo.nat_from_literal "1n"))
Expand Down Expand Up @@ -670,7 +640,6 @@ let suite =
~outstanding_kit:(kit_of_denomination (Ligo.nat_from_literal "5n"))
~active:true
~address:burrow_addr
~delegate:None
~collateral:(tok_of_denomination (Ligo.nat_from_literal "2n"))
~adjustment_index:fixedpoint_one
~collateral_at_auction:(tok_of_denomination (Ligo.nat_from_literal "2n"))
Expand Down Expand Up @@ -708,7 +677,6 @@ let suite =
~outstanding_kit:(kit_of_denomination (Ligo.nat_from_literal "3n"))
~active:true
~address:alice_addr
~delegate:None
~collateral:(tok_of_denomination (Ligo.nat_from_literal "3n"))
~adjustment_index:fixedpoint_one
~collateral_at_auction:(tok_of_denomination (Ligo.nat_from_literal "3n"))
Expand All @@ -729,7 +697,6 @@ let suite =
~outstanding_kit:(kit_of_denomination (Ligo.nat_from_literal "3n"))
~active:true
~address:alice_addr
~delegate:None
~collateral:(tok_of_denomination (Ligo.nat_from_literal "3n"))
~adjustment_index:fixedpoint_one
~collateral_at_auction:(tok_of_denomination (Ligo.nat_from_literal "3n"))
Expand All @@ -747,7 +714,6 @@ let suite =
~outstanding_kit:(kit_of_denomination (Ligo.nat_from_literal "10n"))
~active:true
~address:alice_addr
~delegate:None
~collateral:tok_zero
~adjustment_index:fixedpoint_one
~collateral_at_auction:(tok_of_denomination (Ligo.nat_from_literal "3n"))
Expand All @@ -766,7 +732,6 @@ let suite =
~outstanding_kit:(kit_of_denomination (Ligo.nat_from_literal "1n"))
~active:true
~address:alice_addr
~delegate:None
~collateral:tok_zero
~adjustment_index:fixedpoint_one
~collateral_at_auction:(tok_of_denomination (Ligo.nat_from_literal "1n"))
Expand All @@ -784,7 +749,6 @@ let suite =
~outstanding_kit:(kit_of_denomination (Ligo.nat_from_literal "4_657_142n"))
~active:true
~address:alice_addr
~delegate:None
~collateral:(tok_of_denomination (Ligo.nat_from_literal "5_000_000n"))
~adjustment_index:fixedpoint_one
~collateral_at_auction:(tok_of_denomination (Ligo.nat_from_literal "3_000_000n"))
Expand All @@ -803,7 +767,6 @@ let suite =
~outstanding_kit:(kit_of_denomination (Ligo.nat_from_literal "4_657_143n"))
~active:true
~address:alice_addr
~delegate:None
~collateral:(tok_of_denomination (Ligo.nat_from_literal "5_000_000n"))
~adjustment_index:fixedpoint_one
~collateral_at_auction:(tok_of_denomination (Ligo.nat_from_literal "3_000_000n"))
Expand All @@ -822,7 +785,6 @@ let suite =
~outstanding_kit:(kit_of_denomination (Ligo.nat_from_literal "4_000_000n"))
~active:true
~address:alice_addr
~delegate:None
~collateral:(tok_of_denomination (Ligo.nat_from_literal "2_469_999n"))
~adjustment_index:fixedpoint_one
~collateral_at_auction:(tok_of_denomination (Ligo.nat_from_literal "3_000_000n"))
Expand All @@ -840,7 +802,6 @@ let suite =
~outstanding_kit:(kit_of_denomination (Ligo.nat_from_literal "4_000_000n"))
~active:true
~address:alice_addr
~delegate:None
~collateral:(tok_of_denomination (Ligo.nat_from_literal "2_470_000n"))
~adjustment_index:fixedpoint_one
~collateral_at_auction:(tok_of_denomination (Ligo.nat_from_literal "3_000_000n"))
Expand All @@ -858,7 +819,6 @@ let suite =
~outstanding_kit:(kit_of_denomination (Ligo.nat_from_literal "1_000_000n"))
~active:true
~address:alice_addr
~delegate:None
~collateral:(tok_of_denomination (Ligo.nat_from_literal "2_000_000n"))
~adjustment_index:fixedpoint_one
~collateral_at_auction:(tok_of_denomination (Ligo.nat_from_literal "3_000_000n"))
Expand All @@ -876,7 +836,6 @@ let suite =
~outstanding_kit:(kit_of_denomination (Ligo.nat_from_literal "1_000_000n"))
~active:false
~address:alice_addr
~delegate:None
~collateral:(tok_of_denomination (Ligo.nat_from_literal "2_000_000n"))
~adjustment_index:fixedpoint_one
~collateral_at_auction:(tok_of_denomination (Ligo.nat_from_literal "3_000_000n"))
Expand Down Expand Up @@ -1031,7 +990,6 @@ let suite =
~outstanding_kit:outstanding
~active:true
~address:burrow_addr
~delegate:None
~collateral:(tok_of_denomination (Ligo.nat_from_literal "1n"))
~adjustment_index:fixedpoint_one
~collateral_at_auction:tok_zero
Expand Down Expand Up @@ -1059,7 +1017,6 @@ let suite =
~outstanding_kit:outstanding_kit
~active:true
~address:burrow_addr
~delegate:None
~collateral:collateral
~adjustment_index:fixedpoint_one
~collateral_at_auction:collateral_at_auction
Expand Down
Loading