From 6c8db940233014de0d12f99205cf1fa3fac37b52 Mon Sep 17 00:00:00 2001 From: Naveen <116692862+naveen-imtb@users.noreply.github.com> Date: Wed, 26 Jun 2024 16:26:01 +1000 Subject: [PATCH] TD:1516: chore: upgrade to latest seaport-js (#1944) --- packages/orderbook/package.json | 2 +- .../src/seaport/fillable-units.spec.ts | 116 ------------------ .../orderbook/src/seaport/fillable-units.ts | 22 ---- packages/orderbook/src/seaport/seaport.ts | 5 +- sdk/package.json | 2 +- tests/func-tests/zkevm/yarn.lock | 15 +-- yarn.lock | 12 +- 7 files changed, 18 insertions(+), 156 deletions(-) delete mode 100644 packages/orderbook/src/seaport/fillable-units.spec.ts delete mode 100644 packages/orderbook/src/seaport/fillable-units.ts diff --git a/packages/orderbook/package.json b/packages/orderbook/package.json index eb69b52c23..559d70e62a 100644 --- a/packages/orderbook/package.json +++ b/packages/orderbook/package.json @@ -5,7 +5,7 @@ "bugs": "https://github.com/immutable/ts-immutable-sdk/issues", "dependencies": { "@imtbl/config": "0.0.0", - "@opensea/seaport-js": "4.0.2", + "@opensea/seaport-js": "4.0.3", "axios": "^1.6.5", "ethers": "^5.7.2", "ethers-v6": "npm:ethers@6.11.1", diff --git a/packages/orderbook/src/seaport/fillable-units.spec.ts b/packages/orderbook/src/seaport/fillable-units.spec.ts deleted file mode 100644 index 47c4bc4c7d..0000000000 --- a/packages/orderbook/src/seaport/fillable-units.spec.ts +++ /dev/null @@ -1,116 +0,0 @@ -import { expect } from 'chai'; -import { Fee, Order, ProtocolData } from '../openapi/sdk'; -import { determineFillableUnits } from './fillable-units'; - -describe('determineFillableUnits', () => { - function createOrder(overrides?: Partial): Order { - // Default order object - const defaultOrder: Order = { - sell: [ - { - type: 'ERC1155', - amount: '100', - contract_address: '0xEEb7Da6De152597830eD16361633e362A2F59410', - token_id: '123', - }, - ], - buy: [ - { - type: 'ERC20', - amount: '100', - contract_address: '0xFFb7Da6De152597830eD16361633e362A2F59411', - }, - ], - type: Order.type.LISTING, - fill_status: { - numerator: '0', - denominator: '0', - }, - account_address: '0x1237Da6De152597830eD16361633e362A2F59412', - fees: [ - { - type: Fee.type.PROTOCOL, - amount: '100', - recipient_address: '0x4567Da6De152597830eD16361633e362A2F59413', - }, - ], - chain: { - id: 'eip155:13473', - name: 'imtbl-zkevm-testnet', - }, - created_at: '2024-06-18T06:16:57.902738Z', - end_at: '2026-06-18T06:16:14Z', - id: '019029fd-cf21-0a33-c77f-e121f5162f22', - order_hash: '0xba8ebe0b4ac6f1cc21a2274199b238959aaa0c59e1f2b31a8b7e8a66bf9f9635', - protocol_data: { - order_type: ProtocolData.order_type.PARTIAL_RESTRICTED, - counter: '0', - zone_address: '0x1004f9615e79462c711ff05a386bdba91a762822', - seaport_address: '0x7d117aa8bd6d31c4fa91722f246388f38ab19482', - seaport_version: '1.5', - }, - salt: '0x3217c152146bf9f5', - signature: '0xf1522af4913159cdf1172d1c1bd511a3ca617f6c1d0b0ed588b2ce27618a2ac832c31ed4ee6ab2cea8af0efc2ad522468aa1c8c206291f4b343239acfea0a75e1b', - start_at: '2024-06-18T06:16:14Z', - status: { - name: 'ACTIVE', - }, - updated_at: '2024-06-18T06:16:59.006679Z', - }; - - // Merge the overrides with the default order - return { ...defaultOrder, ...overrides }; - } - - it('should return the remaining fillable units for ERC1155 type when amountToFill is not provided', () => { - const orderInput = createOrder({ - fill_status: { - numerator: '40', - denominator: '100', - }, - }); - - const result = determineFillableUnits(orderInput); - expect(result).to.equal('60'); // (100 - 40) * 100 / 100 - }); - - it('should return the original offer amount if order is unfilled i.e numerator or denominator is 0', () => { - const order: Order = createOrder(); - - const result = determineFillableUnits(order); - expect(result).to.equal('100'); - }); - - it('should return amountToFill if provided', () => { - const order: Order = createOrder({ - fill_status: { - numerator: '40', - denominator: '100', - }, - }); - - const amountToFill = '50'; - const result = determineFillableUnits(order, amountToFill); - expect(result).to.equal(amountToFill); - }); - - it('should return undefined if order type is not ERC1155', () => { - const order: Order = createOrder({ - sell: [ - { - type: 'ERC721', - contract_address: '0xEEb7Da6De152597830eD16361633e362A2F59410', - token_id: '123', - }, - ], - fill_status: { - numerator: '0', - denominator: '0', - }, - }); - - const result = determineFillableUnits(order); - // eslint-disable-next-line @typescript-eslint/no-unused-expressions - expect(result).to.be.undefined; - }); -}); diff --git a/packages/orderbook/src/seaport/fillable-units.ts b/packages/orderbook/src/seaport/fillable-units.ts deleted file mode 100644 index 5cebba8a38..0000000000 --- a/packages/orderbook/src/seaport/fillable-units.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { Order } from '../openapi/sdk'; - -export function determineFillableUnits(order: Order, amountToFill?: string): string | undefined { - if (order.sell[0].type === 'ERC1155' && !amountToFill) { - // fill status is expressed as a ratio - const { numerator, denominator } = order.fill_status; - const originalOfferAmt = BigInt(order.sell[0].amount); - - if (numerator === '0' || denominator === '0') { - return originalOfferAmt.toString(); - } - - // calculate the remaining amount to fill - // remaining = ((denominator - numerator) * originalOfferAmt) / denominator - const remaining = ((BigInt(denominator) - BigInt(numerator)) * BigInt(originalOfferAmt)) - / BigInt(denominator); - - return remaining.toString(); - } - - return amountToFill; -} diff --git a/packages/orderbook/src/seaport/seaport.ts b/packages/orderbook/src/seaport/seaport.ts index d7983c2b1f..320572cb8b 100644 --- a/packages/orderbook/src/seaport/seaport.ts +++ b/packages/orderbook/src/seaport/seaport.ts @@ -36,7 +36,6 @@ import { getBulkOrderComponentsFromMessage, getOrderComponentsFromMessage } from import { SeaportLibFactory } from './seaport-lib-factory'; import { prepareTransaction } from './transaction'; import { mapImmutableOrderToSeaportOrderComponents } from './map-to-seaport-order'; -import { determineFillableUnits } from './fillable-units'; export class Seaport { constructor( @@ -176,7 +175,7 @@ export class Seaport { parameters: orderComponents, signature: order.signature, }, - unitsToFill: determineFillableUnits(order, unitsToFill), + unitsToFill, extraData, tips, }, @@ -245,7 +244,7 @@ export class Seaport { parameters: orderComponents, signature: o.order.signature, }, - unitsToFill: determineFillableUnits(o.order, o.unitsToFill), + unitsToFill: o.unitsToFill, extraData: o.extraData, tips, }; diff --git a/sdk/package.json b/sdk/package.json index be271f8590..a57e87ef43 100644 --- a/sdk/package.json +++ b/sdk/package.json @@ -20,7 +20,7 @@ "@jest/globals": "^29.5.0", "@magic-ext/oidc": "4.2.0", "@metamask/detect-provider": "^2.0.0", - "@opensea/seaport-js": "4.0.2", + "@opensea/seaport-js": "4.0.3", "@rive-app/react-canvas-lite": "^4.9.0", "@stdlib/number-float64-base-normalize": "0.0.8", "@uniswap/router-sdk": "^1.4.0", diff --git a/tests/func-tests/zkevm/yarn.lock b/tests/func-tests/zkevm/yarn.lock index dc83a5e3cb..d46cc6bcff 100644 --- a/tests/func-tests/zkevm/yarn.lock +++ b/tests/func-tests/zkevm/yarn.lock @@ -1105,7 +1105,7 @@ __metadata: "@imtbl/sdk@file:../../../sdk::locator=func-tests-imx%40workspace%3A.": version: 0.0.0 - resolution: "@imtbl/sdk@file:../../../sdk#../../../sdk::hash=27c191&locator=func-tests-imx%40workspace%3A." + resolution: "@imtbl/sdk@file:../../../sdk#../../../sdk::hash=8b5ee2&locator=func-tests-imx%40workspace%3A." dependencies: "@0xsequence/abi": ^1.4.3 "@0xsequence/core": ^1.4.3 @@ -1121,7 +1121,7 @@ __metadata: "@jest/globals": ^29.5.0 "@magic-ext/oidc": 4.2.0 "@metamask/detect-provider": ^2.0.0 - "@opensea/seaport-js": 4.0.2 + "@opensea/seaport-js": 4.0.3 "@rive-app/react-canvas-lite": ^4.9.0 "@stdlib/number-float64-base-normalize": 0.0.8 "@uniswap/router-sdk": ^1.4.0 @@ -1146,6 +1146,7 @@ __metadata: jwt-decode: ^3.1.2 lru-memorise: 0.3.0 magic-sdk: ^21.2.0 + merkletreejs: ^0.3.11 oidc-client-ts: 2.4.0 os-browserify: ^0.3.0 pako: ^2.1.0 @@ -1162,7 +1163,7 @@ __metadata: optional: true prisma: optional: true - checksum: ece1b9f5eb071b687eb942e1885e5718dbec44ec6bd656b1dd7bffcee58f30f46d4dbc48ee0149a00d4b99ddb20af07c990f92e435b914e3ce39764bfba8072c + checksum: ac8ed34c340f70e54e3d4a0ca9f7369473a6088ab9689693128362d6cd25da10e5c8f40b17857d2d40437ff4d5e7af8e349360b10f83df7b193056db048f4bd8 languageName: node linkType: hard @@ -2375,13 +2376,13 @@ __metadata: languageName: node linkType: hard -"@opensea/seaport-js@npm:4.0.2": - version: 4.0.2 - resolution: "@opensea/seaport-js@npm:4.0.2" +"@opensea/seaport-js@npm:4.0.3": + version: 4.0.3 + resolution: "@opensea/seaport-js@npm:4.0.3" dependencies: ethers: ^6.9.0 merkletreejs: ^0.3.11 - checksum: dd156947e85fe98ed8ad22064132dd65a7b3dd4feb0197c29c6325c6a776b50cf62cb3e0030d3fe23f76bd49b0f16fbe54e757d1049a1f917bc3318f3b30ecc0 + checksum: 63fe127f4b968137db1227f9c417af1e009dc1ba58ced87e6734720221b39dee2004ef56dfa77580994f1b3fcd6da4e3befb33b75b621fb53cf92bb28ce3233b languageName: node linkType: hard diff --git a/yarn.lock b/yarn.lock index 974172f120..f62b71c2e0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3743,7 +3743,7 @@ __metadata: resolution: "@imtbl/orderbook@workspace:packages/orderbook" dependencies: "@imtbl/config": 0.0.0 - "@opensea/seaport-js": 4.0.2 + "@opensea/seaport-js": 4.0.3 "@rollup/plugin-typescript": ^11.0.0 "@swc/jest": ^0.2.24 "@typechain/ethers-v5": ^10.2.0 @@ -3887,7 +3887,7 @@ __metadata: "@jest/globals": ^29.5.0 "@magic-ext/oidc": 4.2.0 "@metamask/detect-provider": ^2.0.0 - "@opensea/seaport-js": 4.0.2 + "@opensea/seaport-js": 4.0.3 "@rive-app/react-canvas-lite": ^4.9.0 "@rollup/plugin-babel": ^6.0.4 "@rollup/plugin-commonjs": ^24.0.1 @@ -5464,13 +5464,13 @@ __metadata: languageName: node linkType: hard -"@opensea/seaport-js@npm:4.0.2": - version: 4.0.2 - resolution: "@opensea/seaport-js@npm:4.0.2" +"@opensea/seaport-js@npm:4.0.3": + version: 4.0.3 + resolution: "@opensea/seaport-js@npm:4.0.3" dependencies: ethers: ^6.9.0 merkletreejs: ^0.3.11 - checksum: dd156947e85fe98ed8ad22064132dd65a7b3dd4feb0197c29c6325c6a776b50cf62cb3e0030d3fe23f76bd49b0f16fbe54e757d1049a1f917bc3318f3b30ecc0 + checksum: 63fe127f4b968137db1227f9c417af1e009dc1ba58ced87e6734720221b39dee2004ef56dfa77580994f1b3fcd6da4e3befb33b75b621fb53cf92bb28ce3233b languageName: node linkType: hard