Skip to content

Commit

Permalink
TD-1047 Use chainId in TXNs (#1137)
Browse files Browse the repository at this point in the history
Signed-off-by: Frank Li <[email protected]>
  • Loading branch information
frankisawesome authored Nov 9, 2023
1 parent 5ae3e30 commit 8f5983d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
5 changes: 5 additions & 0 deletions packages/orderbook/src/seaport/seaport.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<TransactionMethods<boolean>>();
const exchangeAction = mock<ExchangeAction<any>>();
Expand Down
30 changes: 24 additions & 6 deletions packages/orderbook/src/seaport/seaport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
),
});
}

Expand Down Expand Up @@ -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,
});
}
Expand All @@ -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,
});

Expand Down Expand Up @@ -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,
});
}
Expand All @@ -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,
});

Expand All @@ -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,
};
}
Expand Down
3 changes: 3 additions & 0 deletions packages/orderbook/src/seaport/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down

0 comments on commit 8f5983d

Please sign in to comment.