Top-up allocations Take 2 - #14
Conversation
| unlockedAmuletCid <- unlockAmulet (ForOwner with dso; owner) holding | ||
| unlockedAmulet <- fetchChecked @Amulet (ForOwner with dso; owner) unlockedAmuletCid | ||
|
|
||
| -- TODO: Should change holding here always be none? Like if we want to topup, |
There was a problem hiding this comment.
Either we should assert that it's None, if that's indeed the case, or it should be part of the result of the operation probably.
| unlockedAmulet <- fetchChecked @Amulet (ForOwner with dso; owner) unlockedAmuletCid | ||
|
|
||
| -- TODO: Should change holding here always be none? Like if we want to topup, | ||
| -- we want to do the full amount we're asked of? |
There was a problem hiding this comment.
I expect that change can be non-None here, they don't have to make a new Amulet just to control how much they top up by. It's not change relative to the amount we're asked, it's the change from breaking down the input holdings into the amount we're adding to the lock and the change we get back.
|
|
||
| -- TODO: Should change holding here always be none? Like if we want to topup, | ||
| -- we want to do the full amount we're asked of? | ||
| ([newHolding], changeHolding) <- lockAmulet |
There was a problem hiding this comment.
I'd like this to be a helper below for "add this amount from these holdings to this LockedAmulet", not just unlockAmulet. It can take the amount to increase as well, rather than the amount of the new lock.
I'd be inclined to make it have "cannot net unlock Amulet" as a checked invariant as well, but we could also plausibly relax those invariants and merge it and partialUnlock.
There was a problem hiding this comment.
I think I have what was asked here in the first paragraph. I'm a little lost on the second, but I can ask you about that tomorrow.
| governanceLock : Optional (ContractId GovernanceLock) | ||
| deriving (Eq, Show, Serializable) | ||
|
|
||
| data GovernanceLock_TopUpResult |
There was a problem hiding this comment.
This should also have the change output, I think that enables chaining a few operations together with their "change" outputs and it's just sensible to report the new holdings.
| actors : [Party] | ||
| controller owner | ||
| do | ||
| require "Only the owner may Top Up on an GovernanceLock" $ actors == [owner] -- TODO: custom controllers |
There was a problem hiding this comment.
Definitely also need to know that the amount is positive, so this isn't also "unlock without vesting".
meiersi-da
left a comment
There was a problem hiding this comment.
Thanks. Looks like straight top-ups are simple. Thanks for adding the test and catching the bug in your implementation.
| inputs <- fmap fst <$> queryInterface @Holding owner | ||
| (Some governanceLock) <- queryContractId @GovernanceLock owner cid | ||
| -- We want to make sure that we don't include the governanceLock holding as an input | ||
| let inputs' : [ContractId Holding] = deleteBy (==) (toInterfaceContractId @Holding governanceLock.holding) inputs |
There was a problem hiding this comment.
use listUnlockedHoldingCidsFor (basicAccount owner) owner env.amuletId where https://github.com/canton-network/splice/blob/1ee0f00917d8f741bd6f33779bebcdaef5bcbc84/token-standard/splice-token-standard-v2-test/daml/Splice/Testing/TokenStandard/WalletClientV2.daml#L190-L194 and I assume that you define amuletId in your TestEnv. The AmuletRegistryV2 has it directly: https://github.com/canton-network/splice/blob/1ee0f00917d8f741bd6f33779bebcdaef5bcbc84/token-standard/splice-token-standard-v2-test/daml/Splice/Testing/Registries/AmuletRegistryV2.daml#L79-L82
| actors : [Party] | ||
| controller owner |
There was a problem hiding this comment.
This doesn't make sense: don't accept actors when you set a fixed controller.
| actors : [Party] | |
| controller owner | |
| controller owner |
| actors : [Party] | ||
| controller owner | ||
| do | ||
| require "Only the owner may Top Up on a GovernanceLock" $ actors == [owner] -- TODO: custom controllers |
There was a problem hiding this comment.
| require "Only the owner may Top Up on a GovernanceLock" $ actors == [owner] -- TODO: custom controllers |
| unlockedAmulet <- fetchChecked @Amulet forOwner unlockedAmuletCid | ||
| lockAmulet | ||
| forOwner | ||
| [unlockedAmulet.amount.initialAmount + amount] |
There was a problem hiding this comment.
@jonored : I remember you wanted to change GovernanceLock to store its own amount directly, correct? That should also be pulled through to the code here.
There was a problem hiding this comment.
This is true, I have now merged in the latest code from Jonathan's branch
|
|
||
| choice GovernanceLock_TopUp : GovernanceLock_TopUpResult | ||
| with | ||
| amount : Decimal |
There was a problem hiding this comment.
| amount : Decimal | |
| topupAmount : Decimal -- ^ Amount by which the locked amount should be increased. |
meiersi-da
left a comment
There was a problem hiding this comment.
Thanks. Looks good to me assuming you address the suggestions I've added.
| pure holdingView.amount | ||
|
|
||
| addAmountToLockedAmulet : ContractId LockedAmulet -> ForOwner -> ExternalPartyTransferContext -> [ContractId Holding] -> Decimal -> Update ([ContractId LockedAmulet], Optional (ContractId Amulet)) | ||
| addAmountToLockedAmulet lockedAmulet forOwner context inputHoldingCids amount = do |
There was a problem hiding this comment.
| addAmountToLockedAmulet lockedAmulet forOwner context inputHoldingCids amount = do | |
| changeLockedAmuletAmount lockedAmulet forOwner context inputHoldingCids amount = do |
as you are not doing an add, but a change.
|
|
||
| ([newHolding], changeHolding) <- addAmountToLockedAmulet lockedAmulet (ForOwner with dso; owner) context inputs (amount + topupAmount) |
There was a problem hiding this comment.
| ([newHolding], changeHolding) <- addAmountToLockedAmulet lockedAmulet (ForOwner with dso; owner) context inputs (amount + topupAmount) | |
| let newAmount = amount + topupAmount | |
| ([newHolding], changeHolding) <- addAmountToLockedAmulet lockedAmulet (ForOwner with dso; owner) context inputs newAmount |
this way you can reuse it below, and are guaranteed the amounts are in sync
Pull Request Checklist
Cluster Testing
/cluster_teston this PR to request it, and ping someone with access to the DA-internal system to approve it./upgrade_teston this PR to request it, and ping someone with access to the DA-internal system to approve it./hdm_teston this PR to request it, and ping someone with access to the DA-internal system to approve it./lsu_teston this PR to request it, and ping someone with access to the DA-internal system to approve it.PR Guidelines
Fixes #n, and mention issues worked on using#nMerge Guidelines