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

Adapt to v1 #14

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
3 changes: 0 additions & 3 deletions esy.lock/.gitattributes

This file was deleted.

3 changes: 0 additions & 3 deletions esy.lock/.gitignore

This file was deleted.

33 changes: 0 additions & 33 deletions esy.lock/index.json

This file was deleted.

File renamed without changes.
42 changes: 10 additions & 32 deletions src/main.mligo
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,11 @@
#import "./vault.mligo" "Vault"
#import "./timelock.mligo" "Timelock"

type parameter =
[@layout:comb]
| Propose of Proposal.make_params
| Cancel of nat option
| Lock of Vault.amount_
| Release of Vault.amount_
| Execute of Outcome.execute_params
| Vote of Vote.choice
| End_vote

type storage = Storage.t
type result = operation list * storage

let execute (outcome_key, packed, s: nat * bytes * storage) : result =
[@entry] let execute (p : Outcome.execute_params) (s : storage) : result =
let { outcome_key; packed } = p in
let proposal = (match Big_map.find_opt outcome_key s.outcomes with
None -> failwith Errors.outcome_not_found
| Some(o) -> Outcome.get_executable_proposal(o)) in
Expand All @@ -42,7 +33,7 @@ let execute (outcome_key, packed, s: nat * bytes * storage) : result =
Storage.update_config(f,s)
)

let propose (p, s : Proposal.make_params * storage) : result =
[@entry] let propose (p : Proposal.make_params) (s : storage) : result =
match s.proposal with
Some(_) -> failwith Errors.proposal_already_exists
| None -> [
Expand All @@ -55,7 +46,7 @@ let propose (p, s : Proposal.make_params * storage) : result =
Proposal.make(p, s.config.start_delay, s.config.voting_period),
s)

let cancel (outcome_key_opt, s : nat option * storage) : result =
[@entry] let cancel (outcome_key_opt : nat option) (s : storage) : result =
[Token.transfer(
s.governance_token,
Tezos.get_self_address(),
Expand All @@ -81,7 +72,7 @@ let cancel (outcome_key_opt, s : nat option * storage) : result =
let () = Timelock._check_locked(p.timelock) in
Storage.update_outcome(outcome_key, (p, Canceled), s)))

let lock (amount_, s : nat * storage) : result =
[@entry] let lock (amount_ : nat) (s : storage) : result =
let () = Proposal._check_no_vote_ongoing(s.proposal) in
let current_amount = Vault.get_for_user(s.vault, Tezos.get_sender()) in

Expand All @@ -94,7 +85,7 @@ let lock (amount_, s : nat * storage) : result =
Tezos.get_sender(),
current_amount + amount_), s)

let release (amount_, s : nat * storage) : result =
[@entry] let release (amount_ : nat) (s : storage) : result =
let () = Proposal._check_no_vote_ongoing(s.proposal) in
let current_amount = Vault.get_for_user_exn(s.vault, Tezos.get_sender()) in
let _check_balance = assert_with_error
Expand All @@ -107,14 +98,14 @@ let release (amount_, s : nat * storage) : result =
Tezos.get_sender(),
abs(current_amount - amount_)), s)

let vote (choice, s : bool * storage) : storage =
match s.proposal with
[@entry] let vote (choice : bool) (s : storage) : result =
Constants.no_operation, (match s.proposal with
None -> failwith Errors.no_proposal
| Some(p) -> let () = Proposal._check_is_voting_period(p) in
let amount_ = Vault.get_for_user_exn(s.vault, Tezos.get_sender()) in
Storage.update_votes(p, (choice, amount_), s)
Storage.update_votes(p, (choice, amount_), s))

let end_vote (s : storage) : result =
[@entry] let end_vote (_ : unit) (s : storage) : result =
match s.proposal with
None -> failwith Errors.no_proposal
| Some(p) -> let () = Proposal._check_voting_period_ended(p) in
Expand All @@ -139,16 +130,3 @@ let end_vote (s : storage) : result =
transfer_to_addr,
s.config.deposit_amount)]
), Storage.add_outcome(outcome, s)

let main (action : parameter) (store : storage) : result =
let _check_amount_is_zero = assert_with_error
(Tezos.get_amount() = 0tez)
Errors.not_zero_amount
in match action with
Propose p -> propose(p, store)
| Cancel n_opt -> cancel(n_opt, store)
| Lock n -> lock(n, store)
| Release n -> release(n, store)
| Execute p -> execute(p.outcome_key, p.packed, store)
| Vote v -> Constants.no_operation, vote(v, store)
| End_vote -> end_vote(store)
2 changes: 1 addition & 1 deletion test/bootstrap/single_asset.mligo
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

(* Extension of FA2 to be used as governance token of the DAO *)

[@view] let total_supply (_, _s : unit * storage) : nat =
[@view] let total_supply (_ : unit) (_s : storage) : nat =
30n
8 changes: 4 additions & 4 deletions test/helpers/dao.mligo
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#import "./assert.mligo" "Assert"

(* Some types for readability *)
type taddr = (DAO.parameter, DAO.storage) typed_address
type contr = DAO.parameter contract
type taddr = (DAO parameter_of, DAO.storage) typed_address
type contr = DAO parameter_of contract
type originated = {
addr: address;
taddr: taddr;
Expand Down Expand Up @@ -51,13 +51,13 @@ let base_storage : DAO.storage = {

(* Originate a DAO contract with given init_storage storage *)
let originate (init_storage: DAO.storage) =
let (taddr, _, _) = Test.originate DAO.main init_storage 0tez in
let (taddr, _, _) = Test.originate_module (contract_of DAO) init_storage 0tez in
let contr = Test.to_contract taddr in
let addr = Tezos.address contr in
{ addr = addr; taddr = taddr; contr = contr }

(* Call entry point of DAO contr contract *)
let call (p, contr : DAO.parameter * contr) =
let call (p, contr : DAO parameter_of * contr) =
Test.transfer_to_contract contr p 0mutez

(* Entry points call helpers *)
Expand Down
8 changes: 4 additions & 4 deletions test/helpers/token.mligo
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#import "./assert.mligo" "Assert"

(* Some types for readability *)
type taddr = (SingleAsset.parameter, SingleAsset.storage) typed_address
type contr = SingleAsset.parameter contract
type taddr = (SingleAsset parameter_of, SingleAsset.storage) typed_address
type contr = SingleAsset parameter_of contract
type originated = {
addr: address;
taddr: taddr;
Expand All @@ -19,7 +19,7 @@ let originate (tok_amount : nat) =
tok_amount, tok_amount, tok_amount
) in
let v_mich = Test.run (fun (x:SingleAsset.Storage.t) -> x) init_storage in
let (addr, _, _) = Test.originate_from_file f "main" (["total_supply"]: string list) v_mich 0tez in
let (addr, _, _) = Test.originate_from_file f v_mich 0tez in
let taddr : taddr = Test.cast_address addr in
let contr = Test.to_contract taddr in
{
Expand Down Expand Up @@ -48,7 +48,7 @@ let transfer (contr, from_, to_, amount_ : contr * address * address * nat) =
Test.transfer_to_contract_exn contr (Transfer transfer_requests) 0tez

(* Batch add [operators] to [contr] contract *)
let add_operators (operators, contr : SingleAsset.operator list * SingleAsset.parameter contract) =
let add_operators (operators, contr : SingleAsset.operator list * SingleAsset parameter_of contract) =
let f (ys,x : (SingleAsset.unit_update list * SingleAsset.operator)) : SingleAsset.unit_update list = (Add_operator(x) : SingleAsset.unit_update) :: ys in
let add_operator = List.fold_left f ([] : SingleAsset.unit_update list) operators in
let r = Test.transfer_to_contract contr (Update_operators(add_operator)) 0mutez in
Expand Down