11import { OrderComponents } from "@opensea/seaport-js/lib/types" ;
22import { Overrides , Signer } from "ethers" ;
3+ import { GetOrderByHashResponse } from "../api/types" ;
34import { OrderV2 } from "../orders/types" ;
45import { DEFAULT_SEAPORT_CONTRACT_ADDRESS } from "../orders/utils" ;
56import { Chain , EventType } from "../types" ;
@@ -55,37 +56,41 @@ export class CancellationManager {
5556 // Check account availability after parameter validation
5657 await this . context . requireAccountIsAvailable ( accountAddress ) ;
5758
58- let orderToCancel : OrderV2 ;
59+ let orderComponents : OrderComponents ;
60+ let effectiveProtocolAddress : string ;
5961
6062 if ( order ) {
6163 // Using OrderV2 object directly
6264 requireValidProtocol ( order . protocolAddress ) ;
63- orderToCancel = order ;
65+ effectiveProtocolAddress = order . protocolAddress ;
66+ orderComponents = order . protocolData . parameters ;
67+
68+ this . context . dispatch ( EventType . CancelOrder , {
69+ orderV2 : order ,
70+ accountAddress,
71+ } ) ;
6472 } else if ( orderHash ) {
6573 // Fetch order from API using order hash
6674 requireValidProtocol ( protocolAddress ) ;
67- orderToCancel = await this . context . api . getOrderByHash (
75+ const fetchedOrder = await this . context . api . getOrderByHash (
6876 orderHash ,
6977 protocolAddress ,
7078 this . context . chain ,
7179 ) ;
72- requireValidProtocol ( orderToCancel . protocolAddress ) ;
80+ requireValidProtocol ( fetchedOrder . protocol_address ) ;
81+ effectiveProtocolAddress = fetchedOrder . protocol_address ;
82+ orderComponents = fetchedOrder . protocol_data . parameters ;
7383 } else {
7484 // Should never reach here due to earlier validation
7585 throw new Error ( "Invalid input" ) ;
7686 }
7787
78- this . context . dispatch ( EventType . CancelOrder , {
79- orderV2 : orderToCancel ,
80- accountAddress,
81- } ) ;
82-
8388 // Transact and get the transaction hash
8489 const transactionHash = await this . cancelSeaportOrders ( {
85- orders : [ orderToCancel . protocolData . parameters ] ,
90+ orders : [ orderComponents ] ,
8691 accountAddress,
8792 domain,
88- protocolAddress : orderToCancel . protocolAddress ,
93+ protocolAddress : effectiveProtocolAddress ,
8994 } ) ;
9095
9196 // Await transaction confirmation
@@ -176,9 +181,17 @@ export class CancellationManager {
176181 return order as OrderComponents ;
177182 }
178183 } ) ;
184+
185+ // Dispatch event for the first order if available (for backwards compatibility with cancelOrder)
186+ if ( firstOrderV2 ) {
187+ this . context . dispatch ( EventType . CancelOrder , {
188+ orderV2 : firstOrderV2 ,
189+ accountAddress,
190+ } ) ;
191+ }
179192 } else if ( orderHashes ) {
180193 // Fetch orders from the API using order hashes
181- const fetchedOrders : OrderV2 [ ] = [ ] ;
194+ const fetchedOrders : GetOrderByHashResponse [ ] = [ ] ;
182195 for ( const orderHash of orderHashes ) {
183196 const order = await this . context . api . getOrderByHash (
184197 orderHash ,
@@ -190,26 +203,15 @@ export class CancellationManager {
190203
191204 // Extract OrderComponents from the fetched orders
192205 orderComponents = fetchedOrders . map ( ( order ) => {
193- requireValidProtocol ( order . protocolAddress ) ;
194- effectiveProtocolAddress = order . protocolAddress ;
195- return order . protocolData . parameters ;
206+ requireValidProtocol ( order . protocol_address ) ;
207+ effectiveProtocolAddress = order . protocol_address ;
208+ return order . protocol_data . parameters ;
196209 } ) ;
197-
198- // Save the first order for event dispatching
199- firstOrderV2 = fetchedOrders [ 0 ] ;
200210 } else {
201211 // Should never reach here due to earlier validation
202212 throw new Error ( "Invalid input" ) ;
203213 }
204214
205- // Dispatch event for the first order if available (for backwards compatibility with cancelOrder)
206- if ( firstOrderV2 ) {
207- this . context . dispatch ( EventType . CancelOrder , {
208- orderV2 : firstOrderV2 ,
209- accountAddress,
210- } ) ;
211- }
212-
213215 // Transact and get the transaction hash
214216 const transactionHash = await this . cancelSeaportOrders ( {
215217 orders : orderComponents ,
0 commit comments