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

API response types mismatched #1582

Open
2 tasks done
mhrynenko opened this issue Nov 7, 2024 · 1 comment
Open
2 tasks done

API response types mismatched #1582

mhrynenko opened this issue Nov 7, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@mhrynenko
Copy link

Component

API

Have you ensured that all of these are up to date?

  • opensea-js
  • Node (minimum v16)

What version of opensea-js are you on?

7.1.14

What function is the bug in?

generateFulfillmentData

Operating System

macOS (Intel)

Describe the bug

Calling openseaSDK.api.generateFulfillmentData returns the data format that is not equal to the one specified in the package.

Response types specified in the package:

export type FulfillmentDataResponse = {
    protocol: string;
    fulfillment_data: FulfillmentData;
};

type FulfillmentData = {
    transaction: Transaction;
    orders: ProtocolData[];
};

type Transaction = {
    function: string;
    chain: number;
    to: string;
    value: number;
    input_data: {
        orders: OrderWithCounter[] | AdvancedOrder[] | BasicOrderParametersStruct[];
    };
};

actually input_data field has another format:

type InputData {
    parameters: BasicOrderParametersStruct;
};
Reproducible example:
import { BasicOrderParametersStruct } from "@opensea/seaport-js/lib/typechain-types/seaport/contracts/Seaport";
import { ethers } from "ethers";
import { Chain, OpenSeaSDK, OrderSide } from "opensea-js";

const provider = new ethers.JsonRpcProvider("https://sepolia.infura.io");
const openseaSDK = new OpenSeaSDK(provider, {
  chain: Chain.Sepolia,
});

async function generateFulfillmentData(
  collection: string,
  tokenID: string,
  fulfillerAddr: string,
  seaportAddr: string
): Promise<string> {
  const order = await openseaSDK.api.getOrder({
    side: OrderSide.LISTING,
    assetContractAddress: collection,
    tokenId: tokenID,
  });

  if (!order.orderHash) {
    throw new Error(`No order hash for ${collection}-${tokenID}`);
  }

  const { fulfillment_data: fulfillmentData } =
    await openseaSDK.api.generateFulfillmentData(
      fulfillerAddr,
      order.orderHash,
      seaportAddr,
      OrderSide.LISTING
    );

  //FIXME: pacakge api has invalid response type, actual response has another format
  const txInputData = fulfillmentData.transaction.input_data as any as {
    parameters: BasicOrderParametersStruct;
  };
  
  console.log(txInputData)
}
Response example
{
"protocol": "seaport1.6",
"fulfillment_data": {
  "transaction": {
    "function": "fulfillBasicOrder_efficient_6GL6yc((address,uint256,uint256,address,address,address,uint256,uint256,uint8,uint256,uint256,bytes32,uint256,bytes32,bytes32,uint256,(uint256,address)[],bytes))",
    "chain": 11155111,
    "to": "0x0000000000000068f116a894984e2db1123eb395",
    "value": 1000000000000000000,
    "input_data": {
      "parameters": {
        "considerationToken": "0x0000000000000000000000000000000000000000",
        "considerationIdentifier": "0",
        "considerationAmount": "900000000000000000",
        "offerer": "0x21eee56cf20cd8f8bb6c7503d592afab29ed5bc9",
        "zone": "0x004c00500000ad104d7dbd00e3ae0a5c00560c00",
        "offerToken": "0xeb713b46d975393ac7f1c0f4ce2878db7caf5a7a",
        "offerIdentifier": "49",
        "offerAmount": "1",
        "basicOrderType": 0,
        "startTime": "1730900602",
        "endTime": "1733492602",
        "zoneHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
        "salt": "24446860302761739304752683030156737591518664810215442929813035228098454551019",
        "offererConduitKey": "0x0000007b02230091a7ed01230072f7006a004d60a8d4e71d599b8104250f0000",
        "fulfillerConduitKey": "0x0000007b02230091a7ed01230072f7006a004d60a8d4e71d599b8104250f0000",
        "totalOriginalAdditionalRecipients": "2",
        "additionalRecipients": [
          {
            "amount": "25000000000000000",
            "recipient": "0x0000a26b00c1f0df003000390027140000faa719"
          },
          {
            "amount": "75000000000000000",
            "recipient": "0xeb713b46d975393ac7f1c0f4ce2878db7caf5a7a"
          }
        ],
        "signature": "0x844c7bb5fa60c1d6ffefd743e3f93dac381e6eed54bc19865a34e5fed7aa89f59cfdc4230567f177d092ce756cd923b71339e4cdff8e89929c3a8ab00f3d896d"
      }
    }
  },
  "orders": [
    {
      "parameters": {
        "offerer": "0x21eee56cf20cd8f8bb6c7503d592afab29ed5bc9",
        "offer": [
          {
            "itemType": 2,
            "token": "0xEB713b46d975393ac7F1C0F4CE2878dB7caF5a7a",
            "identifierOrCriteria": "49",
            "startAmount": "1",
            "endAmount": "1"
          }
        ],
        "consideration": [
          {
            "itemType": 0,
            "token": "0x0000000000000000000000000000000000000000",
            "identifierOrCriteria": "0",
            "startAmount": "900000000000000000",
            "endAmount": "900000000000000000",
            "recipient": "0x21eeE56cf20Cd8F8BB6C7503D592AFab29eD5bC9"
          },
          {
            "itemType": 0,
            "token": "0x0000000000000000000000000000000000000000",
            "identifierOrCriteria": "0",
            "startAmount": "25000000000000000",
            "endAmount": "25000000000000000",
            "recipient": "0x0000a26b00c1F0DF003000390027140000fAa719"
          },
          {
            "itemType": 0,
            "token": "0x0000000000000000000000000000000000000000",
            "identifierOrCriteria": "0",
            "startAmount": "75000000000000000",
            "endAmount": "75000000000000000",
            "recipient": "0xEB713b46d975393ac7F1C0F4CE2878dB7caF5a7a"
          }
        ],
        "startTime": "1730900602",
        "endTime": "1733492602",
        "orderType": 0,
        "zone": "0x004C00500000aD104D7DBd00e3ae0A5C00560C00",
        "zoneHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
        "salt": "0x360c6ebe0000000000000000000000000000000000000000af96d9c9a3b2f9eb",
        "conduitKey": "0x0000007b02230091a7ed01230072f7006a004d60a8d4e71d599b8104250f0000",
        "totalOriginalConsiderationItems": 3,
        "counter": 0
      },
      "signature": "0x844c7bb5fa60c1d6ffefd743e3f93dac381e6eed54bc19865a34e5fed7aa89f59cfdc4230567f177d092ce756cd923b71339e4cdff8e89929c3a8ab00f3d896d"
    }
  ]
}
}
@mhrynenko mhrynenko added the bug Something isn't working label Nov 7, 2024
@ryanio
Copy link
Collaborator

ryanio commented Nov 7, 2024

thanks for opening and the details! so I think it can be improved to specify:

  input_data: {
        orders: OrderWithCounter[] | AdvancedOrder[] | BasicOrderParametersStruct[];
    } | { parameters: BasicOrderParametersStruct; };

Do you want to open a PR for this? I can also do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants