Skip to content

Commit

Permalink
fix: ID-3186 Resolve @imtbl/orderbook Seaport module issue (#2506)
Browse files Browse the repository at this point in the history
  • Loading branch information
haydenfowler authored Jan 23, 2025
1 parent 2211e96 commit 0674564
Show file tree
Hide file tree
Showing 12 changed files with 157 additions and 73 deletions.
12 changes: 11 additions & 1 deletion packages/orderbook/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,16 @@ module.exports = {
"format": ["camelCase","snake_case"]
}
],
"import/prefer-default-export": ["off"]
"import/prefer-default-export": ["off"],
"no-restricted-imports": [
"error",
{
"paths": [],
// Importing types from seaport-js using a relative path (e.g. @opensea/seaport-js/lib/constants)
// can cause issues for consumers of the SDK, e.g: https://github.com/immutable/ts-immutable-sdk/issues/2472.
// Instead, alias or duplicate the types in src/seaport/types.ts and import from there.
"patterns": ["@opensea/seaport-js/*"]
}
]
}
}
4 changes: 2 additions & 2 deletions packages/orderbook/src/api-client/api-client.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
anything, deepEqual, instance, mock, when,
} from 'ts-mockito';
import type { OrderComponents } from '@opensea/seaport-js/lib/types';
import { OrderType } from '@opensea/seaport-js/lib/constants';
import type { OrderComponents } from '../seaport/types';
import { OrderType } from '../seaport/constants';
import { ListingResult, OrdersService } from '../openapi/sdk';
import { ItemType } from '../seaport';
import { ImmutableApiClient } from './api-client';
Expand Down
6 changes: 3 additions & 3 deletions packages/orderbook/src/seaport/components.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { ItemType, OrderType } from '@opensea/seaport-js/lib/constants';
import { BigNumber } from 'ethers';
import type {
ConsiderationItem,
OfferItem,
OrderComponents,
} from '@opensea/seaport-js/lib/types';
import { BigNumber } from 'ethers';
} from './types';
import { getBulkOrderTree } from './lib/bulk-orders';
import { ItemType, OrderType } from './constants';

function orderTypeStringToEnum(orderTypeString: string): OrderType {
if (
Expand Down
2 changes: 1 addition & 1 deletion packages/orderbook/src/seaport/lib/bulk-orders.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { OrderComponents } from '@opensea/seaport-js/lib/types';
import { TypedDataEncoder, keccak256, toUtf8Bytes } from 'ethers-v6';
import type { OrderComponents } from '../types';
import { EIP_712_ORDER_TYPE } from '../constants';

import { Eip712MerkleTree } from './merkle';
Expand Down
9 changes: 6 additions & 3 deletions packages/orderbook/src/seaport/map-to-immutable-order.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { ConsiderationItem, OfferItem } from '@opensea/seaport-js/lib/types';
import { ItemType, OrderType } from '@opensea/seaport-js/lib/constants';
import { ItemType, OrderType } from './constants';
import { ConsiderationItem, OfferItem } from './types';
import {
AssetCollectionItem, ERC20Item, Item, ProtocolData,
AssetCollectionItem,
ERC20Item,
Item,
ProtocolData,
} from '../openapi/sdk';
import { exhaustiveSwitch } from '../utils';

Expand Down
30 changes: 15 additions & 15 deletions packages/orderbook/src/seaport/map-to-seaport-order.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
import { constants } from 'ethers';
import { Item, Order, ProtocolData } from '../openapi/sdk';
import { exhaustiveSwitch } from '../utils';
import { ItemType, OrderType } from './constants';
import {
ConsiderationItem,
OfferItem,
OrderComponents,
TipInputItem,
} from '@opensea/seaport-js/lib/types';
import { constants } from 'ethers';
import { Item, Order, ProtocolData } from '../openapi/sdk';
import { exhaustiveSwitch } from '../utils';
import { ItemType, OrderType } from './constants';
} from './types';

function mapImmutableItemToSeaportOfferItem(item: Item): OfferItem {
switch (item.type) {
case 'NATIVE':
throw new Error('NATIVE items are not supported in the offer');
case 'ERC20':
return {
itemType: ItemType.ERC20,
itemType: ItemType.ERC20.valueOf(),
token: item.contract_address,
identifierOrCriteria: '0',
startAmount: item.amount,
endAmount: item.amount,
};
case 'ERC721':
return {
itemType: ItemType.ERC721,
itemType: ItemType.ERC721.valueOf(),
token: item.contract_address,
identifierOrCriteria: item.token_id,
startAmount: '1',
endAmount: '1',
};
case 'ERC1155':
return {
itemType: ItemType.ERC1155,
itemType: ItemType.ERC1155.valueOf(),
token: item.contract_address,
identifierOrCriteria: item.token_id,
startAmount: item.amount,
Expand All @@ -53,7 +53,7 @@ function mapImmutableItemToSeaportConsiderationItem(
switch (item.type) {
case 'NATIVE':
return {
itemType: ItemType.NATIVE,
itemType: ItemType.NATIVE.valueOf(),
startAmount: item.amount,
endAmount: item.amount,
token: constants.AddressZero,
Expand All @@ -62,7 +62,7 @@ function mapImmutableItemToSeaportConsiderationItem(
};
case 'ERC20':
return {
itemType: ItemType.ERC20,
itemType: ItemType.ERC20.valueOf(),
startAmount: item.amount,
endAmount: item.amount,
token: item.contract_address,
Expand All @@ -71,7 +71,7 @@ function mapImmutableItemToSeaportConsiderationItem(
};
case 'ERC721':
return {
itemType: ItemType.ERC721,
itemType: ItemType.ERC721.valueOf(),
startAmount: '1',
endAmount: '1',
token: item.contract_address,
Expand All @@ -80,7 +80,7 @@ function mapImmutableItemToSeaportConsiderationItem(
};
case 'ERC1155':
return {
itemType: ItemType.ERC1155,
itemType: ItemType.ERC1155.valueOf(),
startAmount: item.amount,
endAmount: item.amount,
token: item.contract_address,
Expand All @@ -89,7 +89,7 @@ function mapImmutableItemToSeaportConsiderationItem(
};
case 'ERC721_COLLECTION':
return {
itemType: ItemType.ERC721_WITH_CRITERIA,
itemType: ItemType.ERC721_WITH_CRITERIA.valueOf(),
startAmount: item.amount,
endAmount: item.amount,
token: item.contract_address,
Expand All @@ -98,7 +98,7 @@ function mapImmutableItemToSeaportConsiderationItem(
};
case 'ERC1155_COLLECTION':
return {
itemType: ItemType.ERC1155_WITH_CRITERIA,
itemType: ItemType.ERC1155_WITH_CRITERIA.valueOf(),
startAmount: item.amount,
endAmount: item.amount,
token: item.contract_address,
Expand Down Expand Up @@ -156,7 +156,7 @@ export function mapImmutableOrderToSeaportOrderComponents(
zone: order.protocol_data.zone_address,
offer: offerItems,
consideration: considerationItems,
orderType: seaportOrderType,
orderType: seaportOrderType.valueOf(),
startTime: Math.round(
new Date(order.start_at).getTime() / 1000,
).toString(),
Expand Down
25 changes: 13 additions & 12 deletions packages/orderbook/src/seaport/seaport.test.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
import {
anything, deepEqual, instance, mock, when,
} from 'ts-mockito';
import type { TransactionMethods } from '@opensea/seaport-js/lib/utils/usecase';
import { ContractTransaction, ZeroHash, ZeroAddress } from 'ethers-v6';
import { Seaport as SeaportLib } from '@opensea/seaport-js';
import type {
ApprovalAction,
ConsiderationItem,
CreateOrderAction,
ExchangeAction,
OfferItem,
OrderComponents,
} from '@opensea/seaport-js/lib/types';
import { BigNumber, providers } from 'ethers';
import { OrderType } from '@opensea/seaport-js/lib/constants';
import {
ActionType,
TransactionAction,
Expand All @@ -27,11 +17,22 @@ import { ProtocolData, Order, OrderStatusName } from '../openapi/sdk';
import {
EIP_712_ORDER_TYPE,
ItemType,
OrderType,
SEAPORT_CONTRACT_NAME,
SEAPORT_CONTRACT_VERSION_V1_5,
} from './constants';
import { Seaport } from './seaport';
import { SeaportLibFactory } from './seaport-lib-factory';
import {
ApprovalAction,
ConsiderationItem,
CreateOrderAction,
CreateOrderReturnType,
ExchangeAction,
OfferItem,
OrderComponents,
TransactionMethods,
} from './types';

const fakeExtraData = '0x0000000000000000000000000000000000000000000000000064ec2faca1186bef338313426612ad6ed494b50e5ddc65ad4e6067df53d6625f921b22156ac9435d4fd946bc5f07859ecd7aca94f87da703b9204f9c09f0089be18d5c268a5f36c80c779ed3cbf6ed54b7c7bf2991a4b11065b01c1a2594619f1a0d49f9';

Expand Down Expand Up @@ -176,7 +177,7 @@ describe('Seaport', () => {
Promise.resolve({
actions: [createActionInstance],
executeAllActions: () => undefined as any,
}),
} as CreateOrderReturnType),
);

sut = new Seaport(
Expand Down Expand Up @@ -402,7 +403,7 @@ describe('Seaport', () => {
Promise.resolve({
actions: [approvalActionInstance, createActionInstance],
executeAllActions: () => undefined as any,
}),
} as CreateOrderReturnType),
);

sut = new Seaport(
Expand Down
Loading

0 comments on commit 0674564

Please sign in to comment.