Skip to content

Commit 0347df2

Browse files
authored
feat: TD-971 sdk changes for fees arrays (#891)
1 parent 389c4de commit 0347df2

File tree

7 files changed

+42
-43
lines changed

7 files changed

+42
-43
lines changed

packages/orderbook/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"build": "NODE_ENV=production rollup --config rollup.config.js",
3333
"generate-types": "typechain --target=ethers-v5 --out-dir=src/typechain/types 'abi/*.json'",
3434
"lint": "eslint ./src --ext .ts,.jsx,.tsx --max-warnings=0",
35+
"lint:fix": "eslint ./src --ext .ts,.jsx,.tsx --max-warnings=0 --fix",
3536
"run:demo": "jest --runInBand --testMatch \"**/?(*.)+(demo).[jt]s?(x)\"",
3637
"run:demo-expiry": "jest --runInBand --testMatch \"**/(expiry.demo).[jt]s?(x)\"",
3738
"run:demo-fulfil": "jest --runInBand --testMatch \"**/(fulfil.demo).[jt]s?(x)\"",

packages/orderbook/src/api-client/api-client.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ describe('ImmutableApiClient', () => {
6565
orderComponents,
6666
orderHash: '0x123',
6767
orderSignature: '0x123',
68+
makerFees: [],
6869
});
6970

7071
await expect(createListingPromise).rejects.toThrowError();
@@ -95,6 +96,7 @@ describe('ImmutableApiClient', () => {
9596
orderComponents,
9697
orderHash: '0x123',
9798
orderSignature: '0x123',
99+
makerFees: [],
98100
});
99101

100102
await expect(createListingPromise).rejects.toThrowError();
@@ -143,6 +145,7 @@ describe('ImmutableApiClient', () => {
143145
orderComponents,
144146
orderHash: '0x123',
145147
orderSignature: '0x123',
148+
makerFees: [],
146149
});
147150

148151
await expect(createListingPromise).rejects.toThrowError();
@@ -202,6 +205,7 @@ describe('ImmutableApiClient', () => {
202205
orderComponents,
203206
orderHash: '0x123',
204207
orderSignature: '0x123',
208+
makerFees: [],
205209
});
206210

207211
expect(orderResult.result.id).toEqual(orderId);

packages/orderbook/src/api-client/api-client.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import {
2-
ProtocolData,
2+
Fee,
33
ListingResult,
44
ListListingsResult,
55
ListTradeResult,
66
OrdersService,
7-
Fee,
7+
ProtocolData,
88
TradeResult,
99
} from 'openapi/sdk';
1010
import {
@@ -24,8 +24,9 @@ export class ImmutableApiClient {
2424
private readonly seaportAddress: string,
2525
) {}
2626

27-
async fulfillmentData(requests: Array<FulfillmentDataRequest>):
28-
Promise<{ result: FulfillmentDataResult[] }> {
27+
async fulfillmentData(
28+
requests: Array<FulfillmentDataRequest>,
29+
): Promise<{ result: FulfillmentDataResult[] }> {
2930
return this.orderbookService.fulfillmentData({
3031
chainName: this.chainName,
3132
requestBody: requests,
@@ -68,7 +69,7 @@ export class ImmutableApiClient {
6869
orderHash,
6970
orderComponents,
7071
orderSignature,
71-
makerFee,
72+
makerFees,
7273
}: CreateListingParams): Promise<ListingResult> {
7374
if (orderComponents.offer.length !== 1) {
7475
throw new Error('Only one item can be listed at a time');
@@ -102,11 +103,11 @@ export class ImmutableApiClient {
102103
contract_address: orderComponents.consideration[0].token,
103104
},
104105
],
105-
fee: makerFee ? {
106-
amount: makerFee.amount,
106+
fees: makerFees.map((x) => ({
107+
amount: x.amount,
107108
fee_type: FeeType.MAKER_MARKETPLACE as unknown as Fee.fee_type,
108-
recipient: makerFee.recipient,
109-
} : undefined,
109+
recipient: x.recipient,
110+
})),
110111
end_time: new Date(
111112
parseInt(`${orderComponents.endTime.toString()}000`, 10),
112113
).toISOString(),

packages/orderbook/src/openapi/sdk/models/CreateListingRequestBody.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ export type CreateListingRequestBody = {
1313
* Buy item for listing should either be NATIVE or ERC20 item
1414
*/
1515
buy: Array<Item>;
16-
fee?: Fee;
16+
/**
17+
* Buy fees should only include maker marketplace fees and should be no more than two entries as more entires will incur more gas. It is best practice to have this as few as possible.
18+
*/
19+
fees: Array<Fee>;
1720
/**
1821
* Time after which the Order is considered expired
1922
*/

packages/orderbook/src/openapi/sdk/models/FulfillmentDataRequest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ import type { Fee } from './Fee';
66

77
export type FulfillmentDataRequest = {
88
order_id: string;
9-
fee?: Fee;
9+
fees: Array<Fee>;
1010
};
1111

packages/orderbook/src/orderbook.ts

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,24 @@ import {
66
OrderbookOverrides,
77
} from './config/config';
88
import { Fee as OpenApiFee } from './openapi/sdk';
9-
import { mapFromOpenApiOrder, mapFromOpenApiPage, mapFromOpenApiTrade } from './openapi/mapper';
9+
import {
10+
mapFromOpenApiOrder,
11+
mapFromOpenApiPage,
12+
mapFromOpenApiTrade,
13+
} from './openapi/mapper';
1014
import { Seaport } from './seaport';
1115
import { SeaportLibFactory } from './seaport/seaport-lib-factory';
1216
import {
1317
CancelOrderResponse,
1418
CreateListingParams,
15-
Fee,
1619
FeeType,
1720
FeeValue,
1821
FulfillOrderResponse,
22+
ListingResult,
1923
ListListingsParams,
2024
ListListingsResult,
2125
ListTradesParams,
2226
ListTradesResult,
23-
ListingResult,
2427
OrderStatus,
2528
PrepareListingParams,
2629
PrepareListingResponse,
@@ -175,16 +178,8 @@ export class Orderbook {
175178
async createListing(
176179
createListingParams: CreateListingParams,
177180
): Promise<ListingResult> {
178-
const makerFee: Fee | undefined = createListingParams.makerFee
179-
? {
180-
...createListingParams.makerFee,
181-
type: FeeType.MAKER_MARKETPLACE,
182-
}
183-
: undefined;
184-
185181
const apiListingResponse = await this.apiClient.createListing({
186182
...createListingParams,
187-
makerFee,
188183
});
189184

190185
return {
@@ -203,18 +198,17 @@ export class Orderbook {
203198
async fulfillOrder(
204199
listingId: string,
205200
takerAddress: string,
206-
takerFee?: FeeValue,
201+
takerFees: FeeValue[],
207202
): Promise<FulfillOrderResponse> {
208203
const fulfillmentDataRes = await this.apiClient.fulfillmentData([
209204
{
210205
order_id: listingId,
211-
fee: takerFee
212-
? {
213-
amount: takerFee.amount,
214-
fee_type: FeeType.TAKER_MARKETPLACE as unknown as OpenApiFee.fee_type.TAKER_MARKETPLACE,
215-
recipient: takerFee.recipient,
216-
}
217-
: undefined,
206+
fees: takerFees.map((fee) => ({
207+
amount: fee.amount,
208+
fee_type:
209+
FeeType.TAKER_MARKETPLACE as unknown as OpenApiFee.fee_type.TAKER_MARKETPLACE,
210+
recipient: fee.recipient,
211+
})),
218212
},
219213
]);
220214

packages/orderbook/src/types.ts

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
import { OrderComponents } from '@opensea/seaport-js/lib/types';
22
import { PopulatedTransaction, TypedDataDomain, TypedDataField } from 'ethers';
3-
import {
4-
Fee as OpenapiFee,
5-
OrdersService,
6-
OrderStatus,
7-
} from './openapi/sdk';
3+
import { Fee as OpenapiFee, OrdersService, OrderStatus } from './openapi/sdk';
84

95
// Strictly re-export only the OrderStatus enum from the openapi types
106
export { OrderStatus } from './openapi/sdk';
@@ -48,7 +44,7 @@ export interface CreateListingParams {
4844
orderComponents: OrderComponents;
4945
orderHash: string;
5046
orderSignature: string;
51-
makerFee?: FeeValue
47+
makerFees: FeeValue[];
5248
}
5349

5450
// Expose the list order filtering and ordering directly from the openAPI SDK, except
@@ -108,7 +104,7 @@ export interface SignableAction {
108104
domain: TypedDataDomain;
109105
types: Record<string, TypedDataField[]>;
110106
value: Record<string, any>;
111-
}
107+
};
112108
}
113109

114110
export type Action = TransactionAction | SignableAction;
@@ -154,7 +150,7 @@ export interface Order {
154150
counter: string;
155151
seaportAddress: string;
156152
seaportVersion: string;
157-
}
153+
};
158154
salt: string;
159155
signature: string;
160156
status: OrderStatus;
@@ -190,10 +186,10 @@ export interface Trade {
190186
buy: (ERC20Item | NativeItem)[];
191187
sell: ERC721Item[];
192188
buyerFees: Fee[];
193-
sellerAddress: string
194-
buyerAddress: string
195-
makerAddress: string
196-
takerAddress: string
189+
sellerAddress: string;
190+
buyerAddress: string;
191+
makerAddress: string;
192+
takerAddress: string;
197193
/**
198194
* Time the on-chain event was indexed by the Immutable order book service
199195
*/
@@ -215,7 +211,7 @@ export interface Trade {
215211
* The log index of the fulfillment event in a block (uint32 as string)
216212
*/
217213
logIndex: string;
218-
}
214+
};
219215
}
220216

221217
export interface TradeResult {

0 commit comments

Comments
 (0)