Skip to content

Commit

Permalink
Added Collection verification status to api.getAsset (#729) (#965)
Browse files Browse the repository at this point in the history
* Added Collection verification status to api.getAsset (#729)

Added SafelistStatus Enum
Added safelistRequestStatus to OpenSeaCollection
Added safelistRequestStatus to collectionFromJSON

* Add getCollection integration test

* Move shared initialization logic for integration test to common file

---------

Co-authored-by: William Dashan Gan <[email protected]>
  • Loading branch information
JoshuaSchmidt-OpenSea and w1ll14m64n authored May 18, 2023
1 parent abe5e95 commit 56b51da
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 39 deletions.
1 change: 0 additions & 1 deletion src/__integration_tests__/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ Environment variables for integration tests are set using `.env`. This file is n

```
API_KEY = "" # OpenSea API Key
WALLET_ADDRESS = ""
WALLET_PRIV_KEY = ""
ALCHEMY_API_KEY = ""
# The following needs to be an NFT owned by the WALLET_ADDRESS
Expand Down
19 changes: 19 additions & 0 deletions src/__integration_tests__/getCollection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { assert } from "chai";
import { suite, test } from "mocha";
import { sdk } from "./init";
import { SafelistStatus } from "../types";

suite("SDK: getCollection", () => {
test("Get Verified Collection", async () => {
const slug = "cool-cats-nft";
const collection = await sdk.api.getCollection(slug);

assert(collection, "Collection should not be null");
assert(collection.name, "Collection name should exist");
assert(collection.slug === slug, "Collection slug should match.");
assert(
collection.safelistRequestStatus === SafelistStatus.VERIFIED,
"Collection should be verified."
);
});
});
35 changes: 35 additions & 0 deletions src/__integration_tests__/init.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { ethers } from "ethers";
import Web3 from "web3";
import { Network } from "wyvern-js/lib/types";
import {
ALCHEMY_API_KEY,
MAINNET_API_KEY,
WALLET_PRIV_KEY,
} from "../__tests__/constants";
import { OpenSeaSDK } from "../sdk";

export const TOKEN_ADDRESS = process.env.SELL_ORDER_CONTRACT_ADDRESS;
export const TOKEN_ID = process.env.SELL_ORDER_TOKEN_ID;
export const LISTING_AMOUNT = process.env.LISTING_AMOUNT;

const webProvider = new Web3.providers.HttpProvider(
`https://eth-mainnet.g.alchemy.com/v2/${ALCHEMY_API_KEY}`
);

const rpcProvider = new ethers.providers.JsonRpcProvider(
`https://eth-mainnet.g.alchemy.com/v2/${ALCHEMY_API_KEY}`
);

const wallet = new ethers.Wallet(WALLET_PRIV_KEY ?? "", rpcProvider);

export const walletAddress = wallet.address;

export const sdk = new OpenSeaSDK(
webProvider,
{
networkName: Network.Main,
apiKey: MAINNET_API_KEY,
},
(line) => console.info(`MAINNET: ${line}`),
wallet
);
44 changes: 7 additions & 37 deletions src/__integration_tests__/postOrder.ts
Original file line number Diff line number Diff line change
@@ -1,44 +1,14 @@
import { expect } from "chai";
import { ethers } from "ethers";
import { suite, test } from "mocha";
import Web3 from "web3";
import {
MAINNET_API_KEY,
WALLET_ADDRESS,
WALLET_PRIV_KEY,
ALCHEMY_API_KEY,
WETH_ADDRESS,
OFFER_AMOUNT,
} from "../__tests__/constants";
LISTING_AMOUNT,
TOKEN_ADDRESS,
TOKEN_ID,
sdk,
walletAddress,
} from "./init";
import { WETH_ADDRESS, OFFER_AMOUNT } from "../__tests__/constants";
import { expectValidOrder } from "../__tests__/utils";
import { OpenSeaSDK } from "../index";
import { Network } from "../types";

const TOKEN_ADDRESS = process.env.SELL_ORDER_CONTRACT_ADDRESS;
const TOKEN_ID = process.env.SELL_ORDER_TOKEN_ID;
const LISTING_AMOUNT = process.env.LISTING_AMOUNT;

const walletAddress = WALLET_ADDRESS ?? "";

const webProvider = new Web3.providers.HttpProvider(
`https://eth-mainnet.g.alchemy.com/v2/${ALCHEMY_API_KEY}`
);

const rpcProvider = new ethers.providers.JsonRpcProvider(
`https://eth-mainnet.g.alchemy.com/v2/${ALCHEMY_API_KEY}`
);

const wallet = new ethers.Wallet(WALLET_PRIV_KEY ?? "", rpcProvider);

const sdk = new OpenSeaSDK(
webProvider,
{
networkName: Network.Main,
apiKey: MAINNET_API_KEY,
},
(line) => console.info(`MAINNET: ${line}`),
wallet
);

suite("SDK: order posting", () => {
test("Post Buy Order", async () => {
Expand Down
1 change: 0 additions & 1 deletion src/__tests__/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { OpenSeaAPI } from "../api";
import { Network } from "../types";

export const MAINNET_API_KEY = process.env.API_KEY;
export const WALLET_ADDRESS = process.env.WALLET_ADDRESS;
export const WALLET_PRIV_KEY = process.env.WALLET_PRIV_KEY;
export const ALCHEMY_API_KEY = process.env.ALCHEMY_API_KEY;
export const OFFER_AMOUNT = process.env.OFFER_AMOUNT;
Expand Down
18 changes: 18 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,22 @@ export enum TokenStandardVersion {
ERC721v3 = "3.0",
}

/**
* The collection's approval status within OpenSea.
* Can be not_requested (brand new collections)
* requested (collections that requested safelisting on our site)
* approved (collections that are approved on our site and can be found in search results)
* verified (verified collections)
*/

export enum SafelistStatus {
NOT_REQUESTED = "not_requested",
REQUESTED = "requested",
APPROVED = "approved",
VERIFIED = "verified",
DISABLED_TOP_TRENDING = "disabled_top_trending",
}

// Collection fees mapping recipient address to basis points
export interface Fees {
openseaFees: Map<string, number>;
Expand Down Expand Up @@ -334,6 +350,8 @@ export interface OpenSeaCollection extends OpenSeaFees {
stats: object;
// Data about displaying cards
displayData: object;
// The collection's approval status
safelistRequestStatus: SafelistStatus;
// Tokens allowed for this collection
paymentTokens: OpenSeaFungibleToken[];
// Address for dev fee payouts
Expand Down
1 change: 1 addition & 0 deletions src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ export const collectionFromJSON = (collection: any): OpenSeaCollection => {
featured: collection.featured,
featuredImageUrl: collection.featured_image_url,
displayData: collection.display_data,
safelistRequestStatus: collection.safelist_request_status,
paymentTokens: (collection.payment_tokens || []).map(tokenFromJSON),
openseaBuyerFeeBasisPoints: +collection.opensea_buyer_fee_basis_points,
openseaSellerFeeBasisPoints: +collection.opensea_seller_fee_basis_points,
Expand Down

0 comments on commit 56b51da

Please sign in to comment.