Skip to content

Commit

Permalink
Update to use Seaport v1.6 (#1421)
Browse files Browse the repository at this point in the history
* update to seaport v1.6

* update package-lock

* fix + lint

* update default offer amount

* Revert "update default offer amount"

This reverts commit 620366c.

* fix sepolia weth address to use same one as opensea
  • Loading branch information
ryanio authored Mar 25, 2024
1 parent 9521da0 commit 8750020
Show file tree
Hide file tree
Showing 9 changed files with 996 additions and 1,065 deletions.
18 changes: 0 additions & 18 deletions .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,21 +73,3 @@ jobs:
SELL_ORDER_CONTRACT_ADDRESS_POLYGON: ${{ secrets.SELL_ORDER_CONTRACT_ADDRESS_POLYGON }}
SELL_ORDER_TOKEN_ID_POLYGON: ${{ secrets.SELL_ORDER_TOKEN_ID_POLYGON }}
run: npm run test:integration

test-earliest-node-engine-support:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 16.0.0 # specified in the package.json engines.node field
cache: npm

- name: Install dependencies
run: npm install

- name: Run tests
env:
OPENSEA_API_KEY: ${{ secrets.OPENSEA_API_KEY }}
ALCHEMY_API_KEY: ${{ secrets.ALCHEMY_API_KEY }}
run: npm run test
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
18.19.1
20.9.0
1,960 changes: 947 additions & 1,013 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "opensea-js",
"version": "7.0.9",
"version": "7.1.0",
"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 Expand Up @@ -38,15 +38,15 @@
},
"types": "lib/index.d.ts",
"dependencies": {
"@opensea/seaport-js": "^3.0.0",
"@opensea/seaport-js": "^4.0.0",
"ethers": "^6.9.0"
},
"devDependencies": {
"@typechain/ethers-v6": "^0.5.1",
"@types/chai": "4.3.14",
"@types/chai-as-promised": "^7.1.5",
"@types/mocha": "^10.0.0",
"@types/node": "^18.0.0",
"@types/node": "^20.0.0",
"@typescript-eslint/eslint-plugin": "^7.0.0",
"@typescript-eslint/parser": "^7.0.0",
"chai": "^4.4.1",
Expand Down Expand Up @@ -86,7 +86,7 @@
"typescript"
],
"engines": {
"node": ">=16.0.0"
"node": ">=20.0.0"
},
"lint-staged": {
"package.json": [
Expand Down
2 changes: 1 addition & 1 deletion src/orders/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BasicOrderParametersStruct } from "@opensea/seaport-js/lib/typechain-types/seaport_v1_5/contracts/Seaport";
import { BasicOrderParametersStruct } from "@opensea/seaport-js/lib/typechain-types/seaport/contracts/Seaport";
import { AdvancedOrder, OrderWithCounter } from "@opensea/seaport-js/lib/types";
import { OpenSeaAccount, OrderSide } from "../types";

Expand Down
4 changes: 2 additions & 2 deletions src/orders/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CROSS_CHAIN_SEAPORT_V1_5_ADDRESS } from "@opensea/seaport-js/lib/constants";
import { CROSS_CHAIN_SEAPORT_V1_6_ADDRESS } from "@opensea/seaport-js/lib/constants";
import {
OrdersQueryOptions,
OrderV2,
Expand All @@ -9,7 +9,7 @@ import { Chain, OrderSide } from "../types";
import { accountFromJSON } from "../utils";

export const DEFAULT_SEAPORT_CONTRACT_ADDRESS =
CROSS_CHAIN_SEAPORT_V1_5_ADDRESS;
CROSS_CHAIN_SEAPORT_V1_6_ADDRESS;

export const getPostCollectionOfferPayload = (
collectionSlug: string,
Expand Down
22 changes: 11 additions & 11 deletions src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ import {
export class OpenSeaSDK {
/** Provider to use for transactions. */
public provider: JsonRpcProvider;
/** Seaport v1.5 client @see {@link https://github.com/ProjectOpenSea/seaport-js} */
public seaport_v1_5: Seaport;
/** Seaport v1.6 client @see {@link https://github.com/ProjectOpenSea/seaport-js} */
public seaport: Seaport;
/** Logger function to use when debugging */
public logger: (arg: string) => void;
/** API instance */
Expand Down Expand Up @@ -105,7 +105,7 @@ export class OpenSeaSDK {
this._signerOrProvider = signerOrProvider ?? this.provider;

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

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

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

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

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

const { executeAllActions } = await this.seaport_v1_5.fulfillOrder({
const { executeAllActions } = await this.seaport.fulfillOrder({
order: protocolData,
accountAddress,
recipientAddress,
Expand Down Expand Up @@ -812,7 +812,7 @@ export class OpenSeaSDK {
);
}

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

Expand Down Expand Up @@ -881,7 +881,7 @@ export class OpenSeaSDK {
requireValidProtocol(order.protocolAddress);

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

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

Expand Down
12 changes: 7 additions & 5 deletions src/utils/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
CROSS_CHAIN_SEAPORT_V1_5_ADDRESS,
CROSS_CHAIN_SEAPORT_V1_6_ADDRESS,
ItemType,
} from "@opensea/seaport-js/lib/constants";
import { ethers, FixedNumber } from "ethers";
Expand Down Expand Up @@ -175,7 +176,7 @@ export const getWETHAddress = (chain: Chain) => {
case Chain.Mumbai:
return "0xa6fa4fb5f76172d178d61b04b0ecd319c5d1c0aa";
case Chain.Sepolia:
return "0xfFf9976782d46CC05630D1f6eBAb18b2324d6B14";
return "0x7b79995e5f793a07bc00c21412e50ecae098e7f9";
case Chain.Klaytn:
return "0xfd844c2fca5e595004b17615f891620d1cb9bbb2";
case Chain.Baobab:
Expand Down Expand Up @@ -277,9 +278,10 @@ export const isTestChain = (chain: Chain): boolean => {
*/
export const isValidProtocol = (protocolAddress: string): boolean => {
const checkSumAddress = ethers.getAddress(protocolAddress);
const validProtocolAddresses = [CROSS_CHAIN_SEAPORT_V1_5_ADDRESS].map(
(address) => ethers.getAddress(address),
);
const validProtocolAddresses = [
CROSS_CHAIN_SEAPORT_V1_6_ADDRESS,
CROSS_CHAIN_SEAPORT_V1_5_ADDRESS,
].map((address) => ethers.getAddress(address));
return validProtocolAddresses.includes(checkSumAddress);
};

Expand All @@ -289,7 +291,7 @@ export const isValidProtocol = (protocolAddress: string): boolean => {
*/
export const requireValidProtocol = (protocolAddress: string) => {
if (!isValidProtocol(protocolAddress)) {
throw new Error("Unsupported protocol");
throw new Error(`Unsupported protocol address: ${protocolAddress}`);
}
};

Expand Down
33 changes: 23 additions & 10 deletions test/utils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,34 @@
import { CROSS_CHAIN_SEAPORT_V1_5_ADDRESS } from "@opensea/seaport-js/lib/constants";
import { assert } from "chai";
import {
CROSS_CHAIN_SEAPORT_V1_5_ADDRESS,
CROSS_CHAIN_SEAPORT_V1_6_ADDRESS,
} from "@opensea/seaport-js/lib/constants";
import { expect } from "chai";
import { ethers } from "ethers";
import { suite, test } from "mocha";
import { isValidProtocol } from "../src/utils/utils";

suite("Utils: utils", () => {
test("isValidProtocol works with all forms of address", async () => {
const seaport_v1_5 = CROSS_CHAIN_SEAPORT_V1_5_ADDRESS;
const randomAddress = "0x1F7Cf51573Bf5270323a395F0bb5Fd3c3a4DB867";
const randomAddress = ethers.Wallet.createRandom().address;

assert.isTrue(isValidProtocol(seaport_v1_5));
assert.isFalse(isValidProtocol(randomAddress));
// Mapping of [address, isValid]
const addressesToCheck: [string, boolean][] = [
[CROSS_CHAIN_SEAPORT_V1_5_ADDRESS, true],
[CROSS_CHAIN_SEAPORT_V1_6_ADDRESS, true],
[randomAddress, false],
];

assert.isTrue(isValidProtocol(seaport_v1_5.toLowerCase()));
assert.isFalse(isValidProtocol(randomAddress.toLowerCase()));
// Check default, lowercase, and checksum addresses
const formatsToCheck = (address: string) => [
address,
address.toLowerCase(),
ethers.getAddress(address),
];

assert.isTrue(isValidProtocol(ethers.getAddress(seaport_v1_5)));
assert.isFalse(isValidProtocol(ethers.getAddress(randomAddress)));
for (const [address, isValid] of addressesToCheck) {
for (const formattedAddress of formatsToCheck(address)) {
expect(isValidProtocol(formattedAddress)).to.equal(isValid);
}
}
});
});

0 comments on commit 8750020

Please sign in to comment.