From 8f5983d582287926bf32957f29498c049d3783c8 Mon Sep 17 00:00:00 2001 From: Frank Li Date: Thu, 9 Nov 2023 11:58:19 +1100 Subject: [PATCH] TD-1047 Use chainId in TXNs (#1137) Signed-off-by: Frank Li --- .../orderbook/src/seaport/seaport.test.ts | 5 ++++ packages/orderbook/src/seaport/seaport.ts | 30 +++++++++++++++---- packages/orderbook/src/seaport/transaction.ts | 3 ++ 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/packages/orderbook/src/seaport/seaport.test.ts b/packages/orderbook/src/seaport/seaport.test.ts index 0c5ad078b4..31cff6e0ed 100644 --- a/packages/orderbook/src/seaport/seaport.test.ts +++ b/packages/orderbook/src/seaport/seaport.test.ts @@ -420,6 +420,11 @@ describe('Seaport', () => { const mockedSeaportJs = mock(SeaportLib); const mockedSeaportLibFactory = mock(SeaportLibFactory); const mockedProvider = mock(providers.JsonRpcProvider); + when(mockedProvider.getNetwork()).thenReturn( + Promise.resolve({ + chainId: 0, + } as any), + ); const exchangeTransactionMethods = mock>(); const exchangeAction = mock>(); diff --git a/packages/orderbook/src/seaport/seaport.ts b/packages/orderbook/src/seaport/seaport.ts index 0d60572a46..e15a8b8855 100644 --- a/packages/orderbook/src/seaport/seaport.ts +++ b/packages/orderbook/src/seaport/seaport.ts @@ -67,7 +67,10 @@ export class Seaport { listingActions.push({ type: ActionType.TRANSACTION, purpose: TransactionPurpose.APPROVAL, - buildTransaction: prepareTransaction(approvalAction.transactionMethods), + buildTransaction: prepareTransaction( + approvalAction.transactionMethods, + (await this.provider.getNetwork()).chainId, + ), }); } @@ -126,7 +129,10 @@ export class Seaport { if (approvalAction) { fulfillmentActions.push({ type: ActionType.TRANSACTION, - buildTransaction: prepareTransaction(approvalAction.transactionMethods), + buildTransaction: prepareTransaction( + approvalAction.transactionMethods, + (await this.provider.getNetwork()).chainId, + ), purpose: TransactionPurpose.APPROVAL, }); } @@ -141,7 +147,10 @@ export class Seaport { fulfillmentActions.push({ type: ActionType.TRANSACTION, - buildTransaction: prepareTransaction(fulfilOrderAction.transactionMethods), + buildTransaction: prepareTransaction( + fulfilOrderAction.transactionMethods, + (await this.provider.getNetwork()).chainId, + ), purpose: TransactionPurpose.FULFILL_ORDER, }); @@ -186,7 +195,10 @@ export class Seaport { if (approvalAction) { fulfillmentActions.push({ type: ActionType.TRANSACTION, - buildTransaction: prepareTransaction(approvalAction.transactionMethods), + buildTransaction: prepareTransaction( + approvalAction.transactionMethods, + (await this.provider.getNetwork()).chainId, + ), purpose: TransactionPurpose.APPROVAL, }); } @@ -201,7 +213,10 @@ export class Seaport { fulfillmentActions.push({ type: ActionType.TRANSACTION, - buildTransaction: prepareTransaction(fulfilOrderAction.transactionMethods), + buildTransaction: prepareTransaction( + fulfilOrderAction.transactionMethods, + (await this.provider.getNetwork()).chainId, + ), purpose: TransactionPurpose.FULFILL_ORDER, }); @@ -224,7 +239,10 @@ export class Seaport { return { type: ActionType.TRANSACTION, - buildTransaction: prepareTransaction(cancellationTransaction), + buildTransaction: prepareTransaction( + cancellationTransaction, + (await this.provider.getNetwork()).chainId, + ), purpose: TransactionPurpose.CANCEL, }; } diff --git a/packages/orderbook/src/seaport/transaction.ts b/packages/orderbook/src/seaport/transaction.ts index f552d45b42..68497aab68 100644 --- a/packages/orderbook/src/seaport/transaction.ts +++ b/packages/orderbook/src/seaport/transaction.ts @@ -5,12 +5,15 @@ import { TransactionBuilder } from 'types'; // This can always be overwritten by the user signing the transaction export function prepareTransaction( transactionMethods: TransactionMethods, + // chainId is required for EIP155 + chainId: number, ): TransactionBuilder { return async () => { const transaction = await transactionMethods.buildTransaction(); transaction.gasLimit = await transactionMethods.estimateGas(); transaction.gasLimit = transaction.gasLimit .add(transaction.gasLimit.div(5)); + transaction.chainId = chainId; return transaction; };