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

Bid with DAI logic #163

Merged
merged 2 commits into from
Mar 29, 2022
Merged

Bid with DAI logic #163

merged 2 commits into from
Mar 29, 2022

Conversation

valiafetisov
Copy link
Contributor

@valiafetisov valiafetisov commented Mar 29, 2022

Contributes to #160

In order to test:

  1. Restart an auction, note down the id, eg ETH-A:120
  2. Make sure you have enough DAI in the VAT (more than Auction Price Total)
    • open wallet modal via $nuxt.$store.dispatch("modals/setWalletModalAndFetchData", true)
    • deposit enough DAI
  3. Participate using correct auction id
    id = 'ETH-A:120'; $nuxt.$store.dispatch("auctions/bidWithDai", { id, bidAmountDai: $nuxt.$store.state.auctions.auctionStorage[id].totalPrice.toFixed() })
    

Note: this will bid total amount.

@LukSteib LukSteib self-requested a review March 29, 2022 13:10
Copy link
Contributor

@LukSteib LukSteib left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@valiafetisov
Copy link
Contributor Author

According to the execution trace it seems like the collateral ended up in the VAT, using flux function, which simply moves collateral from one user to another within VAT:

Screenshot 2022-03-29 at 15 24 35

Therefore, we may actually need initially proposed "collateral withdrawal" step 🙁
(or should make a callee which does it one step)

@valiafetisov
Copy link
Contributor Author

Anyway, take input data is correct: who has your address, therefore I suppose this functionality is implemented correctly on our side:

Screenshot 2022-03-29 at 15 32 27

@LukSteib
Copy link
Contributor

Therefore, we may actually need initially proposed "collateral withdrawal" step 🙁

:( yes, seems like it. So we definitely need a solution for a user to get the funds in the wallet

Anyway, take input data is correct: who has your address, therefore I suppose this functionality is implemented correctly on our side

Yes. Is there an easy command to fetch VAT balance for a certain collateral? Similar to the one we use for Dai. Just in order to doublecheck that collateral ends up in VAT associated with wallet address

@valiafetisov
Copy link
Contributor Author

Is there an easy command to fetch VAT balance for a certain collateral?

Not really. Here is where they are stored in vat contract. So in order to get this number, you need to:

So it's actually less than 0.1, most probably because you don't actually get the whole amount (just like with the swap) and profit calculation should be done depending on the debt:

export const calculateTransactionGrossProfit = function (auction: Auction): BigNumber {
if (!auction.marketUnitPrice) {
return new BigNumber(0);
}
const totalMarketPrice = auction.collateralAmount.multipliedBy(auction.marketUnitPrice);
if (totalMarketPrice <= auction.debtDAI) {
return totalMarketPrice.minus(auction.totalPrice);
}
const collateralAmountLimitedByDebt = auction.debtDAI.dividedBy(auction.approximateUnitPrice);
const totalMarketPriceLimitedByDebt = collateralAmountLimitedByDebt.multipliedBy(auction.marketUnitPrice);
return totalMarketPriceLimitedByDebt.minus(auction.debtDAI);
};

But I think we should open another PR for both implementing gem fetching and fixing "profit" calculation

@LukSteib
Copy link
Contributor

So it's actually less than 0.1, most probably because you don't actually get the whole amount (just like with the swap) and profit calculation should be done depending on the debt

Yes, with the caveat that in the case of Dai bidding it also affects to amount to bid. So I assume the total amount to bid is not always auction amount * auction price :(

So going to approve this PR and we need to figure out gem and profit / total amount to bid related parts in other PRs

@valiafetisov
Copy link
Contributor Author

valiafetisov commented Mar 29, 2022

So I assume the total amount to bid is not always auction amount * auction price

No, that's impossible because take actually accepts amt: Upper limit on amount of collateral to buy (and not DAI that user enters). In other words, user can only take auction partially, but can not ask for more collateral than there is. The actual amount to be transferred to the user (slice) is calculated based on the tab, amt and current price here: https://github.com/makerdao/dss/blob/60690042965500992490f695cf259256cc94c140/src/clip.sol#L357-L380

@valiafetisov valiafetisov merged commit c57c90b into main Mar 29, 2022
@valiafetisov valiafetisov deleted the bidding-with-dai-logic branch March 29, 2022 16:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants