Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support EIP-2930 tx #928

Merged
merged 2 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,7 @@ describe('JsonRpcProvider', async () => {
expect(await echo.echo()).to.equal('hello Vegito!');
});

// TODO: enable me when we support type 1 tx
it.skip('call contract with access list', async () => {
it('call contract with access list', async () => {
const echoFactory = new ContractFactory(echoJson.abi, echoJson.bytecode, wallet);
const echo = await echoFactory.deploy();
await echo.deployed();
Expand All @@ -170,7 +169,8 @@ describe('JsonRpcProvider', async () => {
const receipt2 = await (await echo.scream('hello Vegito!', { accessList, type: 1 })).wait();
expect(await echo.echo()).to.equal('hello Vegito!');

expect(receipt1.gasUsed).to.be.gt(receipt2.gasUsed);
// interestingly passing empty access list can still reduce gas cost
expect(BigInt(receipt1.gasUsed)).toBeGreaterThan(BigInt(receipt2.gasUsed));
});
});

Expand Down
12 changes: 11 additions & 1 deletion packages/eth-providers/src/base-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1232,6 +1232,7 @@ export abstract class BaseProvider extends AbstractProvider {
} else if (
ethTx.type === undefined || // legacy
ethTx.type === null || // legacy
ethTx.type === 1 || // EIP-2930
ethTx.type === 0 // EIP-155
) {
try {
Expand Down Expand Up @@ -1266,7 +1267,7 @@ export abstract class BaseProvider extends AbstractProvider {
gasPrice: ethTx.gasPrice,
});
}
} else if (ethTx.type === 1 || ethTx.type === 2) {
} else if (ethTx.type === 2) {
return logger.throwError(
`unsupported transaction type: ${ethTx.type}, please use legacy or EIP-712 instead.`,
Logger.errors.UNSUPPORTED_OPERATION,
Expand All @@ -1275,6 +1276,15 @@ export abstract class BaseProvider extends AbstractProvider {
transactionType: ethTx.type,
}
);
} else {
return logger.throwError(
`unknwon transaction type: ${ethTx.type}`,
Logger.errors.UNSUPPORTED_OPERATION,
{
operation: '_getSubstrateGasParams',
transactionType: ethTx.type,
}
);
}

return {
Expand Down
5 changes: 3 additions & 2 deletions packages/eth-transactions/src/parseTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function _parseEip712Signature(
);
}

export type SignatureType = 'Ethereum' | 'AcalaEip712' | 'Eip1559';
export type SignatureType = 'Ethereum' | 'AcalaEip712' | 'Eip1559' | 'Eip2930';

// rlp([chainId, salt, nonce, gasLimit, storageLimit, to, value, data, validUntil, tip, accessList, eip712sig])
export function parseEip712(payload: Uint8Array): AcalaEvmTX {
Expand Down Expand Up @@ -134,7 +134,8 @@ export function parseTransaction(rawTransaction: BytesLike): AcalaEvmTX {
export function checkSignatureType(rawTransaction: BytesLike): SignatureType {
const payload = arrayify(rawTransaction);

if (payload[0] > 0x7f || payload[0] === 1) return 'Ethereum'; // Legacy and EIP-155
if (payload[0] > 0x7f) return 'Ethereum'; // Legacy and EIP-155
if (payload[0] === 1) return 'Eip2930'; // EIP-2930
if (payload[0] === 96) return 'AcalaEip712'; // Acala EIP-712

return logger.throwError(`unsupported transaction type: ${payload[0]}, please use legacy or EIP-712 instead. More info about EVM+ gas: https://evmdocs.acala.network/network/gas-parameters`, Logger.errors.UNSUPPORTED_OPERATION, {
Expand Down
Loading