indexer icon indicating copy to clipboard operation
indexer copied to clipboard

Can't create ERC-1155 orders with infinite prices (e.g. 133.33333333)

Open johanneskares opened this issue 1 year ago • 2 comments

Whenever I try to create an ERC-1155 listing or bid where price and quantity diveded are an infinite number (e.g. 133.3333333333) I receive an error. Here is an example, in this case I want to offer 30_000 ERC-1155 tokens for 4_000_000 ERC-20 tokens (USDC). The price for one ERC_1155 token is 133.3333333 and I can't set the order and receive an invalid error.

Request URL

https://api-sepolia.reservoir.tools/order/v3?signature=0x8b6250541c0254a452d35e87f7abe4f4f4c3f189fb16ce847340bb4107c8a8ba2b3ed8f0f32cf3bc560df87139d1816c2d5da46f9dcdc1beafe427367933c45b1c

Payload

{
  "order": {
    "kind": "seaport-v1.5",
    "data": {
      "kind": "single-token",
      "offerer": "0xe0a942ff2e1724a2fe10627728be327a43fe8c26",
      "zone": "0xfb2b693819e866ec87e574903f6e4943723c8ff7",
      "offer": [
        {
          "itemType": 3,
          "token": "0x7c55db8c35a9b570afa34d7c50c15d1f1965b8c9",
          "identifierOrCriteria": "102507459532467741335579904537267007394703392395388500702707291948264537651140",
          "startAmount": "30000",
          "endAmount": "30000"
        }
      ],
      "consideration": [
        {
          "itemType": 1,
          "token": "0x7fc21ceb0c5003576ab5e101eb240c2b822c95d2",
          "identifierOrCriteria": "0",
          "startAmount": "4000000",
          "endAmount": "4000000",
          "recipient": "0xe0a942ff2e1724a2fe10627728be327a43fe8c26"
        }
      ],
      "orderType": 3,
      "startTime": 1707234671,
      "endTime": 1722786731,
      "zoneHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
      "salt": "0x1d4da48b0000000000000000000000007a592ec2d1396054c8d64bd45b519257",
      "conduitKey": "0x0000007b02230091a7ed01230072f7006a004d60a8d4e71d599b8104250f0000",
      "counter": "0",
      "signature": "0x0000000000000000000000000000000000000000000000000000000000000000"
    }
  },
  "orderbook": "reservoir"
}

Response

{"statusCode":400,"error":"Bad Request","message":"invalid","orderId":"0x5731f78d0191a41522d8cebeb5ae2f500f7794cbea4bbdb76c6ee5828d95ba7a"}

johanneskares avatar Feb 06 '24 16:02 johanneskares

I did some digging on my own and I think I found the line that produces the error:

!bn(info.price).div(info.amount).mul(info.amount).eq(info.price)

Not sure why this is in there. Is this a limitation of Seaport?

johanneskares avatar Feb 07 '24 17:02 johanneskares

For anyone running into the same problem: My pretty crazy workaround right now:

For listings I do:

function findAdjustedUsdcPrice(usdPrice: bigint, quantity: bigint) {
    let adjustedPrice: bigint;
    for (adjustedPrice = usdPrice; adjustedPrice >= 0; adjustedPrice -= 1n) {
        const royalty = (adjustedPrice * 25n) / 1000n;

        // royalty is subtracted twice from the original price (Artist Royalty + Marketplace Fee)
        const netPrice = adjustedPrice - 2n * royalty;

        // Reservoir backend only accepts orders where the quantity is a multiple of the net price
        const isValidOrder = netPrice % quantity === 0n;
        if (isValidOrder) {
            break;
        }
    }
    return adjustedPrice;
}

and for bids I do

const updatedUsdcQuantity = (usdcQuantity / quantity) * quantity;

It reduces the USD by a little bit, but that's ok for me.

johanneskares avatar Feb 07 '24 20:02 johanneskares