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

feat: improve opensea wrapper #790

Merged
merged 1 commit into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/core-sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export * as groups from "./groups";
export * as forwarder from "./forwarder";
export * as voucher from "./voucher";
export * as seaport from "./seaport";
export * as marketplaces from "./marketplaces";

export {
envConfigs,
Expand Down
1 change: 1 addition & 0 deletions packages/core-sdk/src/marketplaces/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./types";
36 changes: 32 additions & 4 deletions packages/core-sdk/src/marketplaces/opensea.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
FulfillmentDataResponse,
GetNFTResponse,
OrderAPIOptions,
OrderSide,
OrderV2,
OrdersQueryOptions,
ProtocolData
Expand All @@ -18,6 +17,8 @@ import {
Marketplace,
MarketplaceType,
Order,
OrderFilterOptions,
OrderSide,
SignedOrder,
Wrapper
} from "./types";
Expand Down Expand Up @@ -68,6 +69,9 @@ export type OpenSeaSDKHandler = {
api: {
apiBaseUrl: string;
getOrder(order: Omit<OrdersQueryOptions, "limit">): Promise<OrderV2>;
getOrders(
order: Omit<OrdersQueryOptions, "limit">
): Promise<{ orders: OrderV2[] }>;
generateFulfillmentData(
fulfillerAddress: string,
orderHash: string,
Expand Down Expand Up @@ -270,13 +274,15 @@ export class OpenSeaMarketplace extends Marketplace {
contract: string;
tokenId: string;
},
filter: OrderFilterOptions = {},
withWrapper = false
): Promise<AdvancedOrder> {
// Asumption: we're fulfilling a Bid Order (don't know if it makes sense with an Ask order)
// Assumption: we're fulfilling a Bid Order (don't know if it makes sense with an Ask order)
const osOrder = await this._handler.api.getOrder({
assetContractAddress: asset.contract,
tokenId: asset.tokenId,
side: OrderSide.BID
side: OrderSide.BID,
...filter
});
const fulfillerAddress = withWrapper
? asset.contract // If the token is wrapped, the fulfiller is the wrapper contract itself
Expand Down Expand Up @@ -589,12 +595,14 @@ export class OpenSeaMarketplace extends Marketplace {
contract: string;
tokenId: string;
},
filter: OrderFilterOptions = {},
side: Side
): Promise<SignedOrder> {
const osOrder = await this._handler.api.getOrder({
assetContractAddress: asset.contract,
tokenId: asset.tokenId,
side: side === Side.Ask ? OrderSide.ASK : OrderSide.BID
side: side === Side.Ask ? OrderSide.ASK : OrderSide.BID,
...filter
});
return osOrder
? {
Expand All @@ -603,4 +611,24 @@ export class OpenSeaMarketplace extends Marketplace {
}
: undefined;
}

public async getOrders(
asset: {
contract: string;
tokenIds: string[];
},
filter: OrderFilterOptions = {},
side: Side
): Promise<SignedOrder[]> {
const { orders } = await this._handler.api.getOrders({
assetContractAddress: asset.contract,
tokenIds: asset.tokenIds,
side: side === Side.Ask ? OrderSide.ASK : OrderSide.BID,
...filter
});
return orders.map((osOrder) => ({
...this.convertOsOrder(osOrder),
signature: osOrder.protocolData?.signature
}));
}
}
21 changes: 20 additions & 1 deletion packages/core-sdk/src/marketplaces/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ export enum MarketplaceType {
OPENSEA
}

export enum OrderSide {}
export enum OrderSide {
ASK = "ask",
BID = "bid"
}

export type MarketplaceHandler = OpenSeaSDKHandler | DefaultHandler;

Expand Down Expand Up @@ -64,6 +67,12 @@ export abstract class Wrapper {
public abstract get address(): string;
}

export type OrderFilterOptions = {
maker?: string;
listedAfter?: number | string;
listedBefore?: number | string;
};

export abstract class Marketplace {
constructor(protected _type: MarketplaceType) {}
public abstract createListing(listing: Listing): Promise<Order>;
Expand All @@ -73,8 +82,17 @@ export abstract class Marketplace {
contract: string;
tokenId: string;
},
filter: OrderFilterOptions,
side: Side
): Promise<SignedOrder>;
public abstract getOrders(
asset: {
contract: string;
tokenIds: string[];
},
filter: OrderFilterOptions,
side: Side
): Promise<SignedOrder[]>;
public abstract generateFulfilmentData(
asset: {
contract: string;
Expand All @@ -87,6 +105,7 @@ export abstract class Marketplace {
contract: string;
tokenId: string;
},
filter: OrderFilterOptions,
withWrapper?: boolean
): Promise<AdvancedOrder>;
public abstract wrapVouchers(
Expand Down
Loading