Skip to content

Commit

Permalink
Protocol address fix (#863)
Browse files Browse the repository at this point in the history
* fix: protocol address condition fix (#861)

---------

Co-authored-by: Pravin kumar <[email protected]>
  • Loading branch information
JoshuaSchmidt-OpenSea and pravin120993 authored Mar 6, 2023
1 parent 099605b commit df72323
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 34 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": "4.0.17",
"version": "4.0.18",
"description": "JavaScript SDK for the OpenSea marketplace. Let users buy or sell crypto collectibles and other cryptogoods, all on your own site!",
"license": "MIT",
"author": "OpenSea Developers",
Expand Down
38 changes: 6 additions & 32 deletions src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ import {
BigNumberInput,
getAddressAfterRemappingSharedStorefrontAddressToLazyMintAdapterAddress,
feesToBasisPoints,
isValidProtocol,
} from "./utils/utils";

export class OpenSeaSDK {
Expand Down Expand Up @@ -975,12 +976,7 @@ export class OpenSeaSDK {
accountAddress: string;
domain?: string;
}): Promise<string> {
if (
!(
order.protocolAddress in
[CROSS_CHAIN_SEAPORT_ADDRESS, CROSS_CHAIN_SEAPORT_V1_4_ADDRESS]
)
) {
if (!isValidProtocol(order.protocolAddress)) {
throw new Error("Unsupported protocol");
}

Expand Down Expand Up @@ -1039,12 +1035,7 @@ export class OpenSeaSDK {
recipientAddress?: string;
domain?: string;
}): Promise<string> {
if (
!(
order.protocolAddress in
[CROSS_CHAIN_SEAPORT_ADDRESS, CROSS_CHAIN_SEAPORT_V1_4_ADDRESS]
)
) {
if (!isValidProtocol(order.protocolAddress)) {
throw new Error("Unsupported protocol");
}

Expand Down Expand Up @@ -1182,12 +1173,7 @@ export class OpenSeaSDK {
accountAddress: string;
domain?: string;
}) {
if (
!(
order.protocolAddress in
[CROSS_CHAIN_SEAPORT_ADDRESS, CROSS_CHAIN_SEAPORT_V1_4_ADDRESS]
)
) {
if (!isValidProtocol(order.protocolAddress)) {
throw new Error("Unsupported protocol");
}

Expand Down Expand Up @@ -1759,12 +1745,7 @@ export class OpenSeaSDK {
order: OrderV2;
accountAddress: string;
}): Promise<boolean> {
if (
!(
order.protocolAddress in
[CROSS_CHAIN_SEAPORT_ADDRESS, CROSS_CHAIN_SEAPORT_V1_4_ADDRESS]
)
) {
if (!isValidProtocol(order.protocolAddress)) {
throw new Error("Unsupported protocol");
}

Expand Down Expand Up @@ -2794,14 +2775,7 @@ export class OpenSeaSDK {
* @returns Transaction hash of the approval transaction
*/
public async approveOrder(order: OrderV2, domain?: string) {
if (
!(
order.protocolAddress.toLowerCase() ===
CROSS_CHAIN_SEAPORT_ADDRESS.toLowerCase() ||
order.protocolAddress.toLowerCase() ===
CROSS_CHAIN_SEAPORT_V1_4_ADDRESS.toLowerCase()
)
) {
if (!isValidProtocol(order.protocolAddress)) {
throw new Error("Unsupported protocol");
}

Expand Down
19 changes: 18 additions & 1 deletion src/utils/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { ItemType } from "@opensea/seaport-js/lib/constants";
import {
CROSS_CHAIN_SEAPORT_ADDRESS,
CROSS_CHAIN_SEAPORT_V1_4_ADDRESS,
ItemType,
} from "@opensea/seaport-js/lib/constants";
import BigNumber from "bignumber.js";
import { AbiType, CallData, TxData } from "ethereum-types";
import * as ethUtil from "ethereumjs-util";
Expand Down Expand Up @@ -1131,3 +1135,16 @@ export const feesToBasisPoints = (
0
);
};

/**
* checks protocol address
* @param protocolAddress a protocol address
*/
export const isValidProtocol = (protocolAddress: string): boolean => {
const checkSumAddress = Web3.utils.toChecksumAddress(protocolAddress);
const validProtocolAddresses = [
CROSS_CHAIN_SEAPORT_ADDRESS,
CROSS_CHAIN_SEAPORT_V1_4_ADDRESS,
];
return validProtocolAddresses.includes(checkSumAddress);
};

0 comments on commit df72323

Please sign in to comment.