Skip to content

Commit

Permalink
Fix Seaport v1.5 fulfillments (#1427)
Browse files Browse the repository at this point in the history
* fix 1.5 fulfillments

* add comment
  • Loading branch information
ryanio committed Mar 26, 2024
1 parent 27ff826 commit e51c683
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 18 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "opensea-js",
"version": "7.1.1",
"version": "7.1.2",
"description": "TypeScript SDK for the OpenSea marketplace helps developers build new experiences using NFTs and our marketplace data",
"license": "MIT",
"author": "OpenSea Developers",
Expand Down
65 changes: 48 additions & 17 deletions src/sdk.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import EventEmitter = require("events");
import { Seaport } from "@opensea/seaport-js";
import { OPENSEA_CONDUIT_KEY } from "@opensea/seaport-js/lib/constants";
import {
CROSS_CHAIN_SEAPORT_V1_5_ADDRESS,
CROSS_CHAIN_SEAPORT_V1_6_ADDRESS,
OPENSEA_CONDUIT_KEY,
} from "@opensea/seaport-js/lib/constants";
import {
AdvancedOrder,
ConsiderationInputItem,
Expand Down Expand Up @@ -69,7 +73,9 @@ export class OpenSeaSDK {
/** Provider to use for transactions. */
public provider: JsonRpcProvider;
/** Seaport v1.6 client @see {@link https://github.com/ProjectOpenSea/seaport-js} */
public seaport: Seaport;
public seaport_v1_6: Seaport;
/** Seaport v1.5 client @see {@link https://github.com/ProjectOpenSea/seaport-js} */
public seaport_v1_5: Seaport;
/** Logger function to use when debugging */
public logger: (arg: string) => void;
/** API instance */
Expand Down Expand Up @@ -105,7 +111,16 @@ export class OpenSeaSDK {
this._signerOrProvider = signerOrProvider ?? this.provider;

// eslint-disable-next-line @typescript-eslint/no-explicit-any
this.seaport = new Seaport(this._signerOrProvider as any, {
this.seaport_v1_5 = new Seaport(this._signerOrProvider as any, {
overrides: {
contractAddress: CROSS_CHAIN_SEAPORT_V1_5_ADDRESS,
seaportVersion: "1.5",
defaultConduitKey: OPENSEA_CONDUIT_KEY,
},
});

// eslint-disable-next-line @typescript-eslint/no-explicit-any
this.seaport_v1_6 = new Seaport(this._signerOrProvider as any, {
overrides: { defaultConduitKey: OPENSEA_CONDUIT_KEY },
});

Expand Down Expand Up @@ -378,7 +393,7 @@ export class OpenSeaSDK {
excludeOptionalCreatorFees,
});

const { executeAllActions } = await this.seaport.createOrder(
const { executeAllActions } = await this.seaport_v1_6.createOrder(
{
offer: [
{
Expand Down Expand Up @@ -496,7 +511,7 @@ export class OpenSeaSDK {
);
}

const { executeAllActions } = await this.seaport.createOrder(
const { executeAllActions } = await this.seaport_v1_6.createOrder(
{
offer: offerAssetItems,
consideration: considerationFeeItems,
Expand Down Expand Up @@ -614,7 +629,7 @@ export class OpenSeaSDK {
allowPartialFills: true,
};

const { executeAllActions } = await this.seaport.createOrder(
const { executeAllActions } = await this.seaport_v1_6.createOrder(
payload,
accountAddress,
);
Expand Down Expand Up @@ -654,7 +669,8 @@ export class OpenSeaSDK {
order.taker.address,
);
const fulfillments = getPrivateListingFulfillments(order.protocolData);
const transaction = await this.seaport
const seaport = this.getSeaport(order.protocolAddress);
const transaction = await seaport
.matchOrders({
orders: [order.protocolData, counterOrder],
fulfillments,
Expand Down Expand Up @@ -759,7 +775,8 @@ export class OpenSeaSDK {
});
}

const { executeAllActions } = await this.seaport.fulfillOrder({
const seaport = this.getSeaport(protocolAddress);
const { executeAllActions } = await seaport.fulfillOrder({
order: protocolData,
accountAddress,
recipientAddress,
Expand All @@ -782,6 +799,22 @@ export class OpenSeaSDK {
return transactionHash;
}

/**
* Utility function to get the Seaport client based on the address.
* @param protocolAddress The Seaport address.
*/
private getSeaport(protocolAddress: string): Seaport {
const checksummedProtocolAddress = ethers.getAddress(protocolAddress);
switch (checksummedProtocolAddress) {
case CROSS_CHAIN_SEAPORT_V1_5_ADDRESS:
return this.seaport_v1_5;
case CROSS_CHAIN_SEAPORT_V1_6_ADDRESS:
return this.seaport_v1_6;
default:
throw new Error(`Unsupported protocol address: ${protocolAddress}`);
}
}

/**
* Cancel orders onchain, preventing them from being fulfilled.
* @param options
Expand All @@ -805,14 +838,9 @@ export class OpenSeaSDK {
protocolAddress?: string;
overrides?: Overrides;
}): Promise<string> {
const checksummedProtocolAddress = ethers.getAddress(protocolAddress);
if (checksummedProtocolAddress !== DEFAULT_SEAPORT_CONTRACT_ADDRESS) {
throw new Error(
`Only ${DEFAULT_SEAPORT_CONTRACT_ADDRESS} is currently supported for cancelling orders.`,
);
}
const seaport = this.getSeaport(protocolAddress);

const transaction = await this.seaport
const transaction = await seaport
.cancelOrders(orders, accountAddress, domain, overrides)
.transact();

Expand Down Expand Up @@ -880,8 +908,10 @@ export class OpenSeaSDK {
}): Promise<boolean> {
requireValidProtocol(order.protocolAddress);

const seaport = this.getSeaport(order.protocolAddress);

try {
const isValid = await this.seaport
const isValid = await seaport
.validate([order.protocolData], accountAddress)
.staticCall();
return !!isValid;
Expand Down Expand Up @@ -1068,7 +1098,8 @@ export class OpenSeaSDK {
accountAddress: order.maker.address,
});

const transaction = await this.seaport
const seaport = this.getSeaport(order.protocolAddress);
const transaction = await seaport
.validate([order.protocolData], order.maker.address, domain)
.transact();

Expand Down

0 comments on commit e51c683

Please sign in to comment.