Skip to content

Commit

Permalink
[#256] Allow more xtz entrypoints
Browse files Browse the repository at this point in the history
Problem: We currently have a safety check for most entrypoints to
disallow xtz tokens to be mistakenly sent to the contract and allow
these funds to be stuck there.
We need to reconsider on which entrypoints we should keep this check
and on which we don't need to (see #91).

Solution: Add `accept_ownership` and `transfer_ownership` to
`allowing_xtz` entrypoints.
  • Loading branch information
rinn7e committed May 26, 2021
1 parent 9d2d3c1 commit 6a2cad8
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 26 deletions.
6 changes: 3 additions & 3 deletions haskell/src/Ligo/BaseDAO/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -456,12 +456,10 @@ type UnfreezeParam = ("amount" :! Natural)
-- issue has been fixed:
-- https://gitlab.com/morley-framework/morley/-/issues/527
data ForbidXTZParam
= Accept_ownership ()
| Call_FA2 FA2.Parameter
= Call_FA2 FA2.Parameter
| Drop_proposal ProposalKey
| Flush Natural
| Freeze FreezeParam
| Transfer_ownership TransferOwnershipParam
| Unfreeze UnfreezeParam
| Vote [PermitProtected VoteParam]
deriving stock (Show)
Expand All @@ -470,6 +468,8 @@ data AllowXTZParam
= CallCustom CallCustomParam
| Propose ProposeParams
| Transfer_contract_tokens TransferContractTokensParam
| Transfer_ownership TransferOwnershipParam
| Accept_ownership ()
deriving stock (Show)

data Parameter
Expand Down
20 changes: 1 addition & 19 deletions haskell/test/Test/Ligo/BaseDAO/Management.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ import Lorentz as L hiding (now, (>>))
import Michelson.Runtime.GState (genesisAddress)
import Michelson.Typed (convertContract)
import Michelson.Typed.Convert (untypeValue)
import Michelson.Untyped.Entrypoints (unsafeBuildEpName)
import Morley.Nettest
import Morley.Nettest.Tasty (nettestScenarioCaps)
import Tezos.Core (unsafeMkMutez)
import Util.Named

import Ligo.BaseDAO.Contract
Expand Down Expand Up @@ -51,18 +49,7 @@ withOriginated addrCount storageFn tests = do
test_BaseDAO_Management :: [TestTree]
test_BaseDAO_Management =
[ testGroup "Ownership transfer"
[ nettestScenarioCaps "Contract forbids XTZ transfer" $ do
now <- getNow
withOriginated 2 (\(owner:_) -> initialStorage now owner) $ \[owner, wallet1] baseDao ->
withSender owner $ transfer TransferData
{ tdTo = unTAddress baseDao
, tdAmount = unsafeMkMutez 1
, tdEntrypoint = unsafeBuildEpName "transfer_ownership"
, tdParameter = (#newOwner .! wallet1)
}
& expectForbiddenXTZ baseDao

, nettestScenarioCaps "transfer ownership entrypoint authenticates sender" $ do
[ nettestScenarioCaps "transfer ownership entrypoint authenticates sender" $ do
now <- getNow
transferOwnership withOriginated (initialStorage now)

Expand Down Expand Up @@ -259,8 +246,3 @@ expectNotPendingOwner
:: (MonadNettest caps base m, ToAddress addr)
=> addr -> m a -> m ()
expectNotPendingOwner = expectCustomErrorNoArg #nOT_PENDING_ADMIN

expectForbiddenXTZ
:: (MonadNettest caps base m, ToAddress addr)
=> addr -> m a -> m ()
expectForbiddenXTZ = expectCustomErrorNoArg #fORBIDDEN_XTZ
4 changes: 2 additions & 2 deletions src/base_DAO.mligo
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ let requiring_no_xtz (param, store, config : forbid_xtz_params * storage * confi
match param with
| Call_FA2 (p) -> call_fa2(p, store)
| Drop_proposal (p) -> drop_proposal(p, config, store)
| Transfer_ownership (p) -> transfer_ownership(p, store)
| Accept_ownership -> accept_ownership(store)
| Vote (p) -> vote(p, config, store)
| Flush (p) -> flush (p, config, store)
| Freeze p -> freeze(p, config, store)
Expand All @@ -38,6 +36,8 @@ let allowing_xtz (param, store, config : allow_xtz_params * storage * config) =
| CallCustom p -> call_custom(p, store, config)
| Propose (p) -> propose(p, config, store)
| Transfer_contract_tokens p -> transfer_contract_tokens(p, store)
| Transfer_ownership (p) -> transfer_ownership(p, store)
| Accept_ownership -> accept_ownership(store)

(*
* The actual DAO contract, which in this version is the same independently from
Expand Down
4 changes: 2 additions & 2 deletions src/types.mligo
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,6 @@ type transfer_contract_tokens_param =
type forbid_xtz_params =
| Call_FA2 of fa2_parameter
| Drop_proposal of proposal_key
| Transfer_ownership of transfer_ownership_param
| Accept_ownership of unit
| Vote of vote_param_permited list
| Flush of nat
| Freeze of freeze_param
Expand All @@ -278,6 +276,8 @@ type allow_xtz_params =
| CallCustom of custom_ep_param
| Propose of propose_params
| Transfer_contract_tokens of transfer_contract_tokens_param
| Transfer_ownership of transfer_ownership_param
| Accept_ownership of unit

(*
* Full parameter of the contract.
Expand Down

0 comments on commit 6a2cad8

Please sign in to comment.