Skip to content

Commit

Permalink
TD-1713: Implement collection bids SDK support (#2246)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdymalla authored Oct 1, 2024
1 parent fb77b89 commit 5c44b7d
Show file tree
Hide file tree
Showing 14 changed files with 762 additions and 51 deletions.
1 change: 1 addition & 0 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ jobs:

# zkevm envs
ZKEVM_ORDERBOOK_BANKER: ${{ secrets.ZKEVM_ORDERBOOK_BANKER }}
ZKEVM_ORDERBOOK_ERC20: "0x70dCEF6C22F50497eafc77D252E8E175af21bF75"
ZKEVM_ORDERBOOK_ERC721: "0xBE8B131f39825282Ace9eFf99C0Bb14972417b49"
ZKEVM_ORDERBOOK_ERC1155: "0x2efB9B7810B1d1520c0822aa20F1889ABd2c2146"
SEAPORT_CONTRACT_ADDRESS: "0x7d117aA8BD6D31c4fa91722f246388f38ab1942c"
Expand Down
83 changes: 81 additions & 2 deletions packages/orderbook/src/api-client/api-client.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
BidResult,
CancelOrdersResult,
CollectionBidResult,
Fee,
ListBidsResult,
ListingResult,
Expand All @@ -13,11 +14,17 @@ import { FulfillableOrder } from '../openapi/sdk/models/FulfillableOrder';
import { FulfillmentDataRequest } from '../openapi/sdk/models/FulfillmentDataRequest';
import { UnfulfillableOrder } from '../openapi/sdk/models/UnfulfillableOrder';
import { ItemType, SEAPORT_CONTRACT_VERSION_V1_5 } from '../seaport';
import { mapSeaportItemToImmutableItem, mapSeaportOrderTypeToImmutableProtocolDataOrderType } from '../seaport/map-to-immutable-order';
import {
mapSeaportItemToImmutableAssetCollectionItem,
mapSeaportItemToImmutableERC20Item,
mapSeaportItemToImmutableItem,
mapSeaportOrderTypeToImmutableProtocolDataOrderType,
} from '../seaport/map-to-immutable-order';
import {
CreateBidParams,
CreateListingParams,
ListBidsParams,
ListCollectionBidsParams,
ListListingsParams,
ListTradesParams,
} from '../types';
Expand Down Expand Up @@ -57,6 +64,13 @@ export class ImmutableApiClient {
});
}

async getCollectionBid(collectionBidId: string): Promise<CollectionBidResult> {
return this.orderbookService.getCollectionBid({
chainName: this.chainName,
collectionBidId,
});
}

async getTrade(tradeId: string): Promise<TradeResult> {
return this.orderbookService.getTrade({
chainName: this.chainName,
Expand All @@ -82,6 +96,15 @@ export class ImmutableApiClient {
});
}

async listCollectionBids(
listOrderParams: ListCollectionBidsParams,
): Promise<ListBidsResult> {
return this.orderbookService.listCollectionBids({
chainName: this.chainName,
...listOrderParams,
});
}

async listTrades(
listTradesParams: ListTradesParams,
): Promise<ListTradeResult> {
Expand Down Expand Up @@ -205,7 +228,63 @@ export class ImmutableApiClient {
counter: orderComponents.counter.toString(),
},
salt: orderComponents.salt,
sell: orderComponents.offer.map(mapSeaportItemToImmutableItem),
sell: orderComponents.offer.map(mapSeaportItemToImmutableERC20Item),
signature: orderSignature,
start_at: new Date(
parseInt(`${orderComponents.startTime.toString()}000`, 10),
).toISOString(),
},
});
}

async createCollectionBid({
orderHash,
orderComponents,
orderSignature,
makerFees,
}: CreateBidParams): Promise<CollectionBidResult> {
if (orderComponents.offer.length !== 1) {
throw new Error('Only one item can be listed for a collection bid');
}

if (orderComponents.consideration.length !== 1) {
throw new Error('Only one item can be used as currency for a collection bid');
}

if (ItemType.ERC20 !== orderComponents.offer[0].itemType) {
throw new Error('Only ERC20 tokens can be used as the currency item in a collection bid');
}

if (![ItemType.ERC721_WITH_CRITERIA, ItemType.ERC1155_WITH_CRITERIA]
.includes(orderComponents.consideration[0].itemType)
) {
throw new Error('Only ERC721 / ERC1155 collection based tokens can be bid against');
}

return this.orderbookService.createCollectionBid({
chainName: this.chainName,
requestBody: {
account_address: orderComponents.offerer,
buy: orderComponents.consideration.map(mapSeaportItemToImmutableAssetCollectionItem),
fees: makerFees.map((f) => ({
type: Fee.type.MAKER_ECOSYSTEM,
amount: f.amount,
recipient_address: f.recipientAddress,
})),
end_at: new Date(
parseInt(`${orderComponents.endTime.toString()}000`, 10),
).toISOString(),
order_hash: orderHash,
protocol_data: {
order_type:
mapSeaportOrderTypeToImmutableProtocolDataOrderType(orderComponents.orderType),
zone_address: orderComponents.zone,
seaport_address: this.seaportAddress,
seaport_version: SEAPORT_CONTRACT_VERSION_V1_5,
counter: orderComponents.counter.toString(),
},
salt: orderComponents.salt,
sell: orderComponents.offer.map(mapSeaportItemToImmutableERC20Item),
signature: orderSignature,
start_at: new Date(
parseInt(`${orderComponents.startTime.toString()}000`, 10),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/* tslint:disable */
/* eslint-disable */

import type { ERC20Item } from './ERC20Item';
import type { Fee } from './Fee';
import type { Item } from './Item';
import type { ProtocolData } from './ProtocolData';
Expand All @@ -10,7 +11,7 @@ export type CreateBidRequestBody = {
account_address: string;
order_hash: string;
/**
* Buy item for listing should either be ERC721 or ERC1155 item
* Buy item for bid should either be ERC721 or ERC1155 item
*/
buy: Array<Item>;
/**
Expand All @@ -27,9 +28,9 @@ export type CreateBidRequestBody = {
*/
salt: string;
/**
* Sell item for listing should be an ERC20 item
* Sell item for bid should be an ERC20 item
*/
sell: Array<Item>;
sell: Array<ERC20Item>;
/**
* Digital signature generated by the user for the specific Order
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export type CreateCollectionBidRequestBody = {
account_address: string;
order_hash: string;
/**
* Buy item for listing should either be ERC721 or ERC1155 collection item
* Buy item for collection bid should either be ERC721 or ERC1155 collection item
*/
buy: Array<AssetCollectionItem>;
/**
Expand All @@ -28,7 +28,7 @@ export type CreateCollectionBidRequestBody = {
*/
salt: string;
/**
* Sell item for listing should be an ERC20 item
* Sell item for collection bid should be an ERC20 item
*/
sell: Array<ERC20Item>;
/**
Expand Down
16 changes: 16 additions & 0 deletions packages/orderbook/src/openapi/sdk/models/Trade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,19 @@ import type { Item } from './Item';
import type { TradeBlockchainMetadata } from './TradeBlockchainMetadata';

export type Trade = {
/**
* Buy items are transferred from the taker to the maker.
*/
buy: Array<Item>;
/**
* Deprecated. Use maker and taker addresses instead of buyer and seller addresses.
*/
buyer_address: string;
/**
* Deprecated. Use fees instead. The taker always pays the fees.
*/
buyer_fees: Array<Fee>;
fees: Array<Fee>;
chain: Chain;
order_id: string;
blockchain_metadata: TradeBlockchainMetadata;
Expand All @@ -22,7 +32,13 @@ export type Trade = {
* Global Trade identifier
*/
id: string;
/**
* Sell items are transferred from the maker to the taker.
*/
sell: Array<Item>;
/**
* Deprecated. Use maker and taker addresses instead of buyer and seller addresses.
*/
seller_address: string;
maker_address: string;
taker_address: string;
Expand Down
8 changes: 4 additions & 4 deletions packages/orderbook/src/openapi/sdk/services/OrdersService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ export class OrdersService {
}

/**
* List a paginated array of bids with optional filter parameters
* List a paginated array of bids with optional filter parameters
* List all bids
* List all bids
* @returns ListBidsResult OK response.
* @throws ApiError
*/
Expand Down Expand Up @@ -313,8 +313,8 @@ export class OrdersService {
}

/**
* List a paginated array of collection bids with optional filter parameters
* List a paginated array of collection bids with optional filter parameters
* List all collection bids
* List all collection bids
* @returns ListCollectionBidsResult OK response.
* @throws ApiError
*/
Expand Down
Loading

0 comments on commit 5c44b7d

Please sign in to comment.