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

Set Offer Amount sending incorrect amount of ETH #4

Open
HashHaran opened this issue Aug 30, 2022 · 0 comments
Open

Set Offer Amount sending incorrect amount of ETH #4

HashHaran opened this issue Aug 30, 2022 · 0 comments

Comments

@HashHaran
Copy link

Hi 0xTranqui, I was working on extending your zora starter kit to support my Barter based zora offers market place. I found a bug in code when going through it.

When setOfferAmount is called by the user with a particular offer price we're sending the offer price as it is as msg.value to the OffersV1 contract.

`
const offerPrice = setOffer.amount ? ethers.utils.parseEther(setOffer.amount) : ""

const { data: setOfferData, isError: setOfferError, isLoading: setOfferLoading, isSuccess: setOfferSuccess, write: setOfferWrite  } = useContractWrite({
    addressOrName: mainnetZoraAddresses.OffersV1,
    contractInterface: abi,
    functionName: 'setOfferAmount',
    args: [
        offerContractAddress,
        offerTokenId,
        setOffer.offerId,
        setOffer.currency,
        offerPrice,
    ],
    overrides: {
        value: offerPrice
    },
    onError(error, variables, context) {
        console.log("error", error)
    },
    onSuccess(setOfferData, variables, context) {
        console.log("Success!", setOfferData)
    },
})

`

Say I made an initial offer of 0.1 ETH for a NFT. Now say I want to increase my offer to 0.2 ETH. The current SetOfferAmount component will send the whole 0.2 ETH again. As a result I would have paid the OffersV1 contract 0.3 ETH but according to my offer stored in OffersV1 storage I have only paid 0.2 ETH. Only 0.2 ETH would be refunded in the case where I cancel the offer.

To fix this I have first read the offer from OffersV1 storage to get the previous amount and then computed the difference with current amount and only sent the difference to OffersV1.

In case current amount is less than prev amount we send 0 ETH. Letting OffersV1 take care of the refunds. In case of crypto currencies other ETH we send 0 ETH too.

I made the fix and created a pull request here: #3

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

No branches or pull requests

1 participant