-
Notifications
You must be signed in to change notification settings - Fork 5
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
Nazrhom/fee escrow #297
Nazrhom/fee escrow #297
Conversation
cfecf29
to
739504c
Compare
…uction into nazrhom/fee-escrow
@@ -67,8 +69,8 @@ instance ToJSON AuctionTermsDynamic | |||
instance FromJSON AuctionTermsDynamic | |||
|
|||
-- | Stub for tests not checking MoveToHyda. Something not existent. | |||
nonExistentHeadIdStub :: CurrencySymbol | |||
nonExistentHeadIdStub = "DEADBEEF" | |||
nonExistentHeadIdStub :: HeadId |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks 👍
@@ -46,12 +46,12 @@ config = | |||
, configDiffVoucherExpiry = 8 | |||
, configDiffCleanup = 10 | |||
, configAuctionFeePerDelegate = fromJust $ intToNatural 4_000_000 | |||
, configStartingBid = fromJust $ intToNatural 8_000_000 | |||
, configMinimumBidIncrement = fromJust $ intToNatural 8_000_000 | |||
, configStartingBid = fromJust $ intToNatural 15_000_000 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why?
-- Prelude imports | ||
import PlutusTx.Prelude | ||
|
||
-- import Prelude (quot) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-- import Prelude (quot) |
feeEscrowUtxo <- scriptUtxos FeeEscrow terms | ||
|
||
feeEscrowValue <- case UTxO.pairs feeEscrowUtxo of | ||
[(_, txOut)] -> pure $ txOutValue txOut |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a scriptSingleUtxo
function for that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it work as nicely in this case, as I want both the reference to feeEscrowUtxo
and to look at its value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It returns Maybe (TxIn, TxOut CtxUTxO)
which seems the same that you use.
Probably the name ..Utxo
is confusing, but I still do not found how to name (TxIn, TxOut)
pair better. Utxo
term being overloaded is awful, and fixing better vocabluary would be cool, but I do not know how to name it better.
adaValueOf v = valueOf v adaSymbol adaToken | ||
|
||
expectedValuePerDelegate :: Integer | ||
expectedValuePerDelegate = adaValueOf singleFeeInputValue `quotient` length (delegates terms) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just auctionFeePerDelegate
. This cannot have a reminder, cuz Escrow
ensures that calculateTotalFee terms
is emitted. If it was not so amount should be checked anyway.
So no need for all this stuff.
spread 0 xs = xs | ||
spread k (x : xs) = (x + 1) : spread (k - 1) xs | ||
|
||
distributedLovelace = spread remainder (replicate delegateNumber quotient) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not needed because of auctionFeePerDelegate
too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or is all this code due to #298 ? In that case please put comments for spread
function and write about this motivation in spec.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we leave this kind of logic, it should have property-based unit test matching it with on-chain check.
So I think it may be simpler to just reuse this function in on-chain too. That way there is no need to test that they match each over. And it seems like there is no use for indeterminacy of remainder spreading anyway.
While this needs unit-test or property-based test anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or is all this code due to #298 ? I
No, this is only distributing ADA to the delegates in a balanced way.
If we leave this kind of logic, it should have property-based unit test matching it with on-chain check.
So I think it may be simpler to just reuse this function in on-chain too. That way there is no need to test that they match each over. And it seems like there is no use for indeterminacy of remainder spreading anyway.
While this needs unit-test or property-based test anyway.
I don't think we really need unit tests for this helper function, its quite a trivial implementation, we already have on and offchain tests for this anyway, so we are testing it.
Also, I don't think it would be nice to use this on-chain, this gives slightly more ADA to the delegates appearing first in the list. In the on-chain we should only verify that each delegates receives >= auctionFeePerDelegate
.
The off-chain has to actually consume the utxo, so in case there is more ada than auctionFeePerDelegate * length delegates
it can decide how to distribute the extra ada
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, this is only distributing ADA to the delegates in a balanced way.
I mean that if we do are not concerned with #298 then this ADA separation code is not needed and just auctionFeePerDelegate
can be used.
I don't think we really need unit tests for this helper function, its quite a trivial implementation
Integer division and such logic is exactly the kind of stuff where people get errors like off-by-one or something like that. Also we already got off-by-one errors in intervals helpers code.
we already have on and offchain tests for this anyway, so we are testing it.
Our tests do not test ADA amount at all and this is an accident waiting to be happen.
this gives slightly more ADA to the delegates appearing first in the list
Yes, and your specification says that this is okay. So why accept different remainder distributions then if spec says that any of them are good?
The off-chain has to actually consume the utxo, so in case there is more ada than auctionFeePerDelegate * length delegates it can decide how to distribute the extra ada
What is off-chain
? Why where can be extra ADA? If it is winning lot, then this does not interfere with delegate ADA distribution, cuz bidder cannot be an delegate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@GeorgeFlerovsky Can delegate be a bidder too?
src/HydraAuction/Tx/FeeEscrow.hs
Outdated
TxOutDatumNone | ||
ReferenceScriptNone | ||
|
||
zipDistributingValue :: Integer -> [PubKeyHash] -> [(PubKeyHash, Value)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
zipDistributingValue :: Integer -> [PubKeyHash] -> [(PubKeyHash, Value)] | |
zipDistributingValue :: Lovelace -> [PubKeyHash] -> [(PubKeyHash, Value)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I now noticed that now this code actually uses delegates list. But there is not way to actually get it now. It should be returned by delegate server I gues.
@uhbif19 this is currently hardcoded to be |
I understand. I meant real CLI. We can separate CLI fixing for that stuff in another issue, which probably requires delegates list returining, and merge this. |
src/HydraAuction/Tx/FeeEscrow.hs
Outdated
@@ -105,8 +104,8 @@ distributeFee terms = do | |||
TxOutDatumNone | |||
ReferenceScriptNone | |||
|
|||
zipDistributingValue :: Integer -> [PubKeyHash] -> [(PubKeyHash, Value)] | |||
zipDistributingValue lovelaceAmt delegatePKHs = zip delegatePKHs (lovelaceToValue . Lovelace <$> distributedLovelace) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-- Every delegate is payed at least the expected proportion of fee | ||
all receivesProportionOfFee (delegates terms) | ||
-- There is one input spent from the fee escrow validator with enough ADA to pay the fees | ||
adaValueOf singleFeeInputValue >= expectedFeePerDelegeate * length (delegates terms) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But if all delegates get their fee, then everything is okay by construction, no?
Part of #267