trader-xyz / nft-swap-sdk

Ethereum's missing p2p NFT and token swap library for web3 developers. Written in TypeScript. Powered by 0x.
https://swapsdk.xyz
MIT License
219 stars 83 forks source link

V3 fillSignedOrder - MetaMask - RPC Error when signing #94

Closed jinsley8 closed 1 year ago

jinsley8 commented 2 years ago

Hi,

I'm working with V3 on Polygon and getting a Metamask internal error when using fillSignedOrder.

Before filling I verify the order signature is correct and that it passes.

Does anyone know what could be causing the following issue when using fillSignedOrder results in:

MetaMask - RPC Error: Internal JSON-RPC error.
code: -32603
data: 
    code: 3
    data: "0x4678472b43693c6356dfe50fa860e046b18bfc620c5c855517bfab74eebfdcb898531f4a00000000000000000000000000000000000000000000000000......."
    message:  "execution reverted"
message: "Internal JSON-RPC error."
johnrjj commented 2 years ago

If you manually provide a high gas limit to the transaction, and force the transaction to go through and fail, I can help debug if you can provide the reverted tx hash

jinsley8 commented 2 years ago

@johnrjj thank you!

I've tried all different configs for fillSignedOrder and can't get past this Metamask error. Everything is good up until this point.

I tried using the useFeeData hook from the wagmi package to get gasPrices too.

I also tried undefined instead of swapSdk.exchangeContract.address which I saw in one of the nft-swap-sdk tests but that didn't help either.

import { useFeeData } from 'wagmi';

const { data: FeeData } = useFeeData();
const gasFees = await FeeData?.formatted;

const fillTx = await swapSdk.fillSignedOrder(normalizedOrder, swapSdk.exchangeContract.address, {
                // gasPrice: gasFees?.gasPrice,
                // maxPriorityFee: gasFees?.maxFeePerGas,
                // maxFee: gasFees?.maxPriorityFeePerGas,
                gasLimit: '5000000000',
                // HACK(johnnrjj) - Rinkeby still has protocol fees, so we give it a little bit of ETH so its happy.
                // value: ethers.utils.parseEther('0.001'),
            });
gasFees: gasFees = {
    gasPrice: "82895985947"
    maxFeePerGas: "106339282574"
    maxPriorityFeePerGas: "1500000000"
}

I'm stumped on what I can try next even if it doesn't work to make gasLimit extremely high.

Could it be an issue with the original signedOrder even though verifying it works? or an issue with approvals?

I have WETH and MATIC in both accounts I'm testing so I don't think it's an issue with not enough funds for gas.

jinsley8 commented 2 years ago

Also, after I accept setApprovalForAll() for an NFT contract via approveTokenOrNftByAsset:

I check the token's approval with loadApprovalStatus and it returns:

{ 
  contractApproved: true,
  tokenIdApproved: false

}

Does anyone know if tokenIdApproved ever has to be set to true here?

jinsley8 commented 2 years ago

Could it have something to do with EIP1559 transaction fees?

https://wiki.polygon.technology/docs/develop/eip1559-transactions/how-to-send-eip1559-transactions/

TransactionOverrides interface does include this info though: https://github.com/trader-xyz/nft-swap-sdk/blob/8b3c3ebfa868cbbb1beb59f49521b956faed0201/src/sdk/common/types.ts#L42-L51

jinsley8 commented 1 year ago

Closing, this seems to be just a configuration error when building order.