Skip to content

Commit

Permalink
fix: [TD-1098] Order Book OpenAPI SDK update (#1216)
Browse files Browse the repository at this point in the history
  • Loading branch information
lfportal authored Dec 5, 2023
1 parent a62e82d commit c0b991a
Show file tree
Hide file tree
Showing 22 changed files with 151 additions and 103 deletions.
28 changes: 14 additions & 14 deletions packages/checkout/sdk/src/smartCheckout/buy/buy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ describe('buy', () => {
'0xADDRESS',
[
{
recipient: '0xFEERECIPIENT',
recipientAddress: '0xFEERECIPIENT',
amount: '25000000000000000',
},
],
Expand Down Expand Up @@ -337,7 +337,7 @@ describe('buy', () => {
'0xADDRESS',
[
{
recipient: '0xFEERECIPIENT',
recipientAddress: '0xFEERECIPIENT',
amount: '25000000000000000',
},
],
Expand Down Expand Up @@ -1224,7 +1224,7 @@ describe('buy', () => {
}],
expectedTakerFee: [
{
recipient: '0xFEERECIPIENT',
recipientAddress: '0xFEERECIPIENT',
amount: '25000000000000000',
},
],
Expand All @@ -1237,7 +1237,7 @@ describe('buy', () => {
}],
expectedTakerFee: [
{
recipient: '0xFEERECIPIENT',
recipientAddress: '0xFEERECIPIENT',
amount: '100000000000000000',
},
],
Expand All @@ -1260,11 +1260,11 @@ describe('buy', () => {
}],
expectedTakerFee: [
{
recipient: '0xFEERECIPIENT',
recipientAddress: '0xFEERECIPIENT',
amount: '100000000000000000',
},
{
recipient: '0xFEERECIPIENT',
recipientAddress: '0xFEERECIPIENT',
amount: '100000000000000000',
},
],
Expand All @@ -1287,11 +1287,11 @@ describe('buy', () => {
}],
expectedTakerFee: [
{
recipient: '0xFEERECIPIENT',
recipientAddress: '0xFEERECIPIENT',
amount: '100000000000000000',
},
{
recipient: '0xFEERECIPIENT',
recipientAddress: '0xFEERECIPIENT',
amount: '100000000000000000',
},
],
Expand Down Expand Up @@ -1419,7 +1419,7 @@ describe('buy', () => {
}],
expectedTakerFee: [
{
recipient: '0xFEERECIPIENT',
recipientAddress: '0xFEERECIPIENT',
amount: '25000',
},
],
Expand All @@ -1432,7 +1432,7 @@ describe('buy', () => {
}],
expectedTakerFee: [
{
recipient: '0xFEERECIPIENT',
recipientAddress: '0xFEERECIPIENT',
amount: '100000',
},
],
Expand All @@ -1455,11 +1455,11 @@ describe('buy', () => {
}],
expectedTakerFee: [
{
recipient: '0xFEERECIPIENT',
recipientAddress: '0xFEERECIPIENT',
amount: '100000',
},
{
recipient: '0xFEERECIPIENT',
recipientAddress: '0xFEERECIPIENT',
amount: '100000',
},
],
Expand All @@ -1482,11 +1482,11 @@ describe('buy', () => {
}],
expectedTakerFee: [
{
recipient: '0xFEERECIPIENT',
recipientAddress: '0xFEERECIPIENT',
amount: '100000',
},
{
recipient: '0xFEERECIPIENT',
recipientAddress: '0xFEERECIPIENT',
amount: '100000',
},
],
Expand Down
26 changes: 13 additions & 13 deletions packages/checkout/sdk/src/smartCheckout/fees/fees.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe.only('orderbook fees', () => {

expect(result).toEqual([{
amount: '250000000000000000',
recipient: '0x222',
recipientAddress: '0x222',
}]);
});

Expand Down Expand Up @@ -61,7 +61,7 @@ describe.only('orderbook fees', () => {

expect(result).toEqual([{
amount: '1000000',
recipient: '0x222',
recipientAddress: '0x222',
}]);
});

Expand Down Expand Up @@ -90,7 +90,7 @@ describe.only('orderbook fees', () => {

expect(result).toEqual([{
amount: '12500000000000000',
recipient: '0x222',
recipientAddress: '0x222',
}]);
});

Expand All @@ -109,10 +109,10 @@ describe.only('orderbook fees', () => {

expect(result).toEqual([{
amount: '250000000000000000',
recipient: '0x222',
recipientAddress: '0x222',
}, {
amount: '500000000000000000',
recipient: '0x333',
recipientAddress: '0x333',
}]);
});

Expand All @@ -131,10 +131,10 @@ describe.only('orderbook fees', () => {

expect(result).toEqual([{
amount: '7000000000000000000',
recipient: '0x222',
recipientAddress: '0x222',
}, {
amount: '3000000000000000000',
recipient: '0x333',
recipientAddress: '0x333',
}]);
});

Expand Down Expand Up @@ -173,7 +173,7 @@ describe.only('orderbook fees', () => {

expect(result).toEqual([{
amount: '1000000000000000000',
recipient: '0x222',
recipientAddress: '0x222',
}]);
});

Expand All @@ -189,7 +189,7 @@ describe.only('orderbook fees', () => {

expect(result).toEqual([{
amount: '100000000000000000',
recipient: '0x222',
recipientAddress: '0x222',
}]);
});

Expand All @@ -208,10 +208,10 @@ describe.only('orderbook fees', () => {

expect(result).toEqual([{
amount: '1000000000000000000',
recipient: '0x222',
recipientAddress: '0x222',
}, {
amount: '500000000000000000',
recipient: '0x333',
recipientAddress: '0x333',
}]);
});

Expand Down Expand Up @@ -253,10 +253,10 @@ describe.only('orderbook fees', () => {

expect(result).toEqual([{
amount: '250000000000000000',
recipient: '0x222',
recipientAddress: '0x222',
}, {
amount: '500000000000000000',
recipient: '0x333',
recipientAddress: '0x333',
}]);
});

Expand Down
2 changes: 1 addition & 1 deletion packages/checkout/sdk/src/smartCheckout/fees/fees.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export const calculateFees = (
if (currentFeeBn.gt(0)) {
calculateFeesResult.push({
amount: currentFeeBn.toString(),
recipient: orderFee.recipient,
recipientAddress: orderFee.recipient,
});
}
}// for
Expand Down
2 changes: 1 addition & 1 deletion packages/checkout/sdk/src/smartCheckout/sell/sell.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ describe('sell', () => {
{
makerFees: [{
amount: '25000000000000000',
recipient: '0xEac347177DbA4a190B632C7d9b8da2AbfF57c772',
recipientAddress: '0xEac347177DbA4a190B632C7d9b8da2AbfF57c772',
}],
orderComponents: {},
orderHash: 'hash',
Expand Down
10 changes: 5 additions & 5 deletions packages/orderbook/src/api-client/api-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,10 @@ export class ImmutableApiClient {
return this.orderbookService.createListing({
chainName: this.chainName,
requestBody: {
order_hash: orderHash,
account_address: orderComponents.offerer,
buy: [
{
item_type:
type:
Number(orderComponents.consideration[0].itemType)
=== ItemType.NATIVE
? 'NATIVE'
Expand All @@ -127,12 +126,13 @@ export class ImmutableApiClient {
],
fees: makerFees.map((x) => ({
amount: x.amount,
fee_type: FeeType.MAKER_ECOSYSTEM as unknown as Fee.fee_type,
recipient: x.recipient,
type: FeeType.MAKER_ECOSYSTEM as unknown as Fee.type,
recipient_address: x.recipientAddress,
})),
end_at: new Date(
parseInt(`${orderComponents.endTime.toString()}000`, 10),
).toISOString(),
order_hash: orderHash,
protocol_data: {
order_type: ProtocolData.order_type.FULL_RESTRICTED,
zone_address: orderComponents.zone,
Expand All @@ -145,7 +145,7 @@ export class ImmutableApiClient {
{
contract_address: orderComponents.offer[0].token,
token_id: orderComponents.offer[0].identifierOrCriteria,
item_type: 'ERC721',
type: 'ERC721',
},
],
signature: orderSignature,
Expand Down
24 changes: 13 additions & 11 deletions packages/orderbook/src/openapi/mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ import {

export function mapFromOpenApiOrder(order: OpenApiOrder): Order {
const buyItems: (ERC20Item | NativeItem)[] = order.buy.map((item) => {
if (item.item_type === 'ERC20') {
if (item.type === 'ERC20') {
return {
type: 'ERC20',
contractAddress: item.contract_address,
amount: item.amount,
};
}

if (item.item_type === 'NATIVE') {
if (item.type === 'NATIVE') {
return {
type: 'NATIVE',
amount: item.amount,
Expand All @@ -32,7 +32,7 @@ export function mapFromOpenApiOrder(order: OpenApiOrder): Order {
});

const sellItems: ERC721Item[] = order.sell.map((item) => {
if (item.item_type === 'ERC721') {
if (item.type === 'ERC721') {
return {
type: 'ERC721',
contractAddress: item.contract_address,
Expand All @@ -45,20 +45,22 @@ export function mapFromOpenApiOrder(order: OpenApiOrder): Order {

return {
id: order.id,
type: order.type,
accountAddress: order.account_address,
buy: buyItems,
sell: sellItems,
fees: order.fees.map((fee) => ({
amount: fee.amount,
recipient: fee.recipient,
type: fee.fee_type as unknown as FeeType,
recipientAddress: fee.recipient_address,
type: fee.type as unknown as FeeType,
})),
chain: order.chain,
createdAt: order.created_at,
endAt: order.end_at,
orderHash: order.order_hash,
protocolData: {
counter: order.protocol_data.counter,
orderType: order.protocol_data.order_type,
counter: order.protocol_data.counter,
seaportAddress: order.protocol_data.seaport_address,
seaportVersion: order.protocol_data.seaport_version,
zoneAddress: order.protocol_data.zone_address,
Expand All @@ -73,15 +75,15 @@ export function mapFromOpenApiOrder(order: OpenApiOrder): Order {

export function mapFromOpenApiTrade(trade: OpenApiTrade): Trade {
const buyItems: (ERC20Item | NativeItem)[] = trade.buy.map((item) => {
if (item.item_type === 'ERC20') {
if (item.type === 'ERC20') {
return {
type: 'ERC20',
contractAddress: item.contract_address,
amount: item.amount,
};
}

if (item.item_type === 'NATIVE') {
if (item.type === 'NATIVE') {
return {
type: 'NATIVE',
amount: item.amount,
Expand All @@ -92,7 +94,7 @@ export function mapFromOpenApiTrade(trade: OpenApiTrade): Trade {
});

const sellItems: ERC721Item[] = trade.sell.map((item) => {
if (item.item_type === 'ERC721') {
if (item.type === 'ERC721') {
return {
type: 'ERC721',
contractAddress: item.contract_address,
Expand All @@ -110,8 +112,8 @@ export function mapFromOpenApiTrade(trade: OpenApiTrade): Trade {
sell: sellItems,
buyerFees: trade.buyer_fees.map((fee) => ({
amount: fee.amount,
recipient: fee.recipient,
type: fee.fee_type as unknown as FeeType,
recipientAddress: fee.recipient_address,
type: fee.type as unknown as FeeType,
})),
chain: trade.chain,
indexedAt: trade.indexed_at,
Expand Down
3 changes: 2 additions & 1 deletion packages/orderbook/src/openapi/sdk/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export type { CancelOrdersResultData } from './models/CancelOrdersResultData';
export type { Chain } from './models/Chain';
export type { ChainName } from './models/ChainName';
export type { CreateListingRequestBody } from './models/CreateListingRequestBody';
export type { ERC1155Item } from './models/ERC1155Item';
export type { ERC20Item } from './models/ERC20Item';
export type { ERC721Item } from './models/ERC721Item';
export type { Error } from './models/Error';
Expand All @@ -32,7 +33,7 @@ export type { ListingResult } from './models/ListingResult';
export type { ListListingsResult } from './models/ListListingsResult';
export type { ListTradeResult } from './models/ListTradeResult';
export type { NativeItem } from './models/NativeItem';
export type { Order } from './models/Order';
export { Order } from './models/Order';
export type { OrderStatus } from './models/OrderStatus';
export { OrderStatusName } from './models/OrderStatusName';
export type { Page } from './models/Page';
Expand Down
23 changes: 23 additions & 0 deletions packages/orderbook/src/openapi/sdk/models/ERC1155Item.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */

export type ERC1155Item = {
/**
* Token type user is offering, which in this case is ERC1155
*/
type: 'ERC1155';
/**
* Address of ERC1155 token
*/
contract_address: string;
/**
* ID of ERC1155 token
*/
token_id: string;
/**
* A string representing the price at which the user is willing to sell the token. This value is provided in the smallest unit of the token (e.g., wei for Ethereum).
*/
amount: string;
};

Loading

0 comments on commit c0b991a

Please sign in to comment.