80 lines
18 KiB
TypeScript
80 lines
18 KiB
TypeScript
import { expect } from 'chai';
|
|
import { estimateArbitrumL1CalldataGasCost } from '../../src/utils/l2_gas_utils';
|
|
|
|
const L2_GAS_PRICE = 100_000_000; // 0.1 gwei
|
|
|
|
describe('L2 Gas Utils', () => {
|
|
describe('estimateArbitrumL1CalldataGasCost', () => {
|
|
// `actualGasCost` is from the transaction receipt (`gasUsedForL1`).
|
|
// `l1CalldataPricePerUnit` is the rough value returned by `ArbGasInfo` precompile (`getGasPrices`) around the time of the transaction.
|
|
const transactions = [
|
|
// https://explorer.arbitrum.io/tx/0xc0ea49eabe8301dd6b019d0a44d5284f6fc41a7bf56b986f737a8366c655f534
|
|
{
|
|
calldata:
|
|
'0x5ae401dc0000000000000000000000000000000000000000000000000000000063265d0000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000e404e45aaf00000000000000000000000082af49447d8a07e3bd95bd0d56f35241523fbab1000000000000000000000000d3f1da62cafb7e7bc6531ff1cef6f414291f03d30000000000000000000000000000000000000000000000000000000000000bb8000000000000000000000000316473a2b173f5a8a23890c99f200ba00b2dc213000000000000000000000000000000000000000000000000000000a2fb405800000000000000000000000000000000000000000000000000002873df8aaccfa9000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
|
|
l1CalldataPricePerUnit: 47938616128 / 16,
|
|
actualL1GasCost: 166189,
|
|
},
|
|
// https://explorer.arbitrum.io/tx/0x8c17cd075c5e79c8f5653815dac292172376512056b9ecd9b872b3726062685f
|
|
{
|
|
calldata:
|
|
'0x095ea7b3000000000000000000000000362fa9d0bca5d19f743db50738345ce2b40ec99f000000000000000000000000000000000000000000000000000000002f62bcc0',
|
|
l1CalldataPricePerUnit: 39613693856 / 16,
|
|
actualL1GasCost: 71700,
|
|
},
|
|
// https://explorer.arbitrum.io/tx/0xf90e58cdae58525ed81c8d2162d62be67a44c8778eecb6ebf0fb10be27ae9ea8
|
|
{
|
|
calldata:
|
|
'0x39c6e45d4254432d555344000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000002dc6c00000000000000000000000000000000000000000000000000000000008f0d180',
|
|
l1CalldataPricePerUnit: 38582540240 / 16,
|
|
actualL1GasCost: 109960,
|
|
},
|
|
// https://explorer.arbitrum.io/tx/0x80ca74be9d08b8910654a09b65cb7670ea65d4c663481af014b8f3a8a4ca7fcc
|
|
{
|
|
calldata: '0xee7524a46387039f9dcaa611177b158b4aada819b05f31d75152fb19b7473864e81cdb7f',
|
|
l1CalldataPricePerUnit: 38582540240 / 16,
|
|
actualL1GasCost: 57873,
|
|
},
|
|
// https://explorer.arbitrum.io/tx/0xea94fce4adca9b034004fbcf22c2857609a9167e60254ee288f56e79a023bde3
|
|
{
|
|
calldata:
|
|
'0x7c02520000000000000000000000000093131efee501d5721737c32576238f619548edda0000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000018000000000000000000000000032eb7902d4134bf98a28b963d26de779af92a212000000000000000000000000539bde0d7dbd336b79148aa742883198bbf6034200000000000000000000000093131efee501d5721737c32576238f619548edda00000000000000000000000098e073b579fd483eac8f10d5bd0b32c8c3bbd7e000000000000000000000000000000000000000000000000006ff55fd19b9b99f000000000000000000000000000000000000000000000001ff3974ad69a23d410000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000cc00000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000001c00000000000000000000000000000000000000000000000000000000000000420000000000000000000000000000000000000000000000000000000000000064000000000000000000000000000000000000000000000000000000000000007800000000000000000000000000000000000000000000000000000000000000a608000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000064eb5625d900000000000000000000000032eb7902d4134bf98a28b963d26de779af92a212000000000000000000000000ba12222222228d8ba445958a75a0704d566bf2c800000000000000000000000000000000000000000000000006ff55fd19b9b99f00000000000000000000000000000000000000000000000000000000800000000000000000000000ba12222222228d8ba445958a75a0704d566bf2c80000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000001c452bbbe2900000000000000000000000000000000000000000000000000000000000000e000000000000000000000000093131efee501d5721737c32576238f619548edda000000000000000000000000000000000000000000000000000000000000000000000000000000000000000093131efee501d5721737c32576238f619548edda00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020b4742a383f8a000000000000000000000000000000000000000000000000000000006327b8a5b340b6b1a34019853cb05b2de6ee8ffd0b89a008000100000000000000000036000000000000000000000000000000000000000000000000000000000000000000000000000000000000000032eb7902d4134bf98a28b963d26de779af92a21200000000000000000000000082af49447d8a07e3bd95bd0d56f35241523fbab100000000000000000000000000000000000000000000000006ff55fd19b9b99f00000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000018414284aab0000000000000000000000000000000000000000000000000000000000000080800000000000000000000000000000000000000000000000000000000000004400000000000000000000000082af49447d8a07e3bd95bd0d56f35241523fbab100000000000000000000000000000001000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000064d1660f9900000000000000000000000082af49447d8a07e3bd95bd0d56f35241523fbab1000000000000000000000000b7e50106a5bd3cf21af210a755f9c8740890a8c90000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a4b757fed6000000000000000000000000b7e50106a5bd3cf21af210a755f9c8740890a8c900000000000000000000000082af49447d8a07e3bd95bd0d56f35241523fbab1000000000000000000000000539bde0d7dbd336b79148aa742883198bbf603420000000000000000002dc6c093131efee501d5721737c32576238f619548edda000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000024432ce0a7c0000000000000000000000000000000000000000000000000000000000000080800000000000000000000000000000000000000000000000000000000000004400000000000000000000000093131efee501d5721737c32576238f619548edda00000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a405971224000000000000000000000000539bde0d7dbd336b79148aa742883198bbf60342000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000100000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004470bdb947000000000000000000000000539bde0d7dbd336b79148aa742883198bbf60342000000000000000000000000000000000000000000000002046368ed3991c6ed0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000018414284aab00000000000000000000000000000000000000000000000000000000000000808000000000000000000000000000000000000000000000000000000000000044000000000000000000000000539bde0d7dbd336b79148aa742883198bbf6034200000000000000000000000000000001000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000064d1660f99000000000000000000000000539bde0d7dbd336b79148aa742883198bbf603420000000000000000000000001111111254fb6c44bac0bed2854e76f90643097d00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e26b9977',
|
|
l1CalldataPricePerUnit: 38249029712 / 16,
|
|
actualL1GasCost: 340416,
|
|
},
|
|
// https://explorer.arbitrum.io/tx/0xc096648b4ec5aaa51a73031b147d42905008eee1edc6ab9589b3147c039cadc1
|
|
{
|
|
calldata:
|
|
'0x415565b0000000000000000000000000d4d42f0b6def4ce0383636770ef773390d85c61a00000000000000000000000082af49447d8a07e3bd95bd0d56f35241523fbab100000000000000000000000000000000000000000000000011cd20db72dd27c8000000000000000000000000000000000000000000000000000379457767077100000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000003a0000000000000000000000000000000000000000000000000000000000000000b0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000d4d42f0b6def4ce0383636770ef773390d85c61a00000000000000000000000082af49447d8a07e3bd95bd0d56f35241523fbab1000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000002c000000000000000000000000000000000000000000000000000000000000002c000000000000000000000000000000000000000000000000000000000000002a000000000000000000000000000000000000000000000000011cd20db72dd27c8000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000025375736869537761700000000000000000000000000000000000000000000000000000000000000011cd20db72dd27c80000000000000000000000000000000000000000000000000003794577670771000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000001b02da8cb0d097eb8d57a175b88c7d8b4799750600000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000002000000000000000000000000d4d42f0b6def4ce0383636770ef773390d85c61a00000000000000000000000082af49447d8a07e3bd95bd0d56f35241523fbab1000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000e00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000002000000000000000000000000d4d42f0b6def4ce0383636770ef773390d85c61a000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee0000000000000000000000000000000000000000000000000000000000000000869584cd00000000000000000000000086003b044f70dac0abc80ac8957305b6370893ed00000000000000000000000000000000000000000000001df4eb5c626327ace7',
|
|
l1CalldataPricePerUnit: 54913607344 / 16,
|
|
actualL1GasCost: 316302,
|
|
},
|
|
];
|
|
|
|
transactions.forEach(({ calldata, l1CalldataPricePerUnit, actualL1GasCost }, i) => {
|
|
it(`returns an estimate within the bound (tx ${i})`, () => {
|
|
const gasCost = estimateArbitrumL1CalldataGasCost({
|
|
l1CalldataPricePerUnit,
|
|
l2GasPrice: L2_GAS_PRICE,
|
|
calldata,
|
|
});
|
|
expect(gasCost).gt(actualL1GasCost);
|
|
expect(gasCost).lt(actualL1GasCost * 2); // it's okay to overestimate but ideally not too much
|
|
});
|
|
});
|
|
|
|
it(`returns an estimate using the default L1 calldata price when it's missing`, () => {
|
|
const gasCost = estimateArbitrumL1CalldataGasCost({
|
|
// l1CalldataPricePerUnit is missing
|
|
l2GasPrice: L2_GAS_PRICE,
|
|
calldata:
|
|
'0x415565b0000000000000000000000000d4d42f0b6def4ce0383636770ef773390d85c61a00000000000000000000000082af49447d8a07e3bd95bd0d56f35241523fbab100000000000000000000000000000000000000000000000011cd20db72dd27c8000000000000000000000000000000000000000000000000000379457767077100000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000003a0000000000000000000000000000000000000000000000000000000000000000b0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000d4d42f0b6def4ce0383636770ef773390d85c61a00000000000000000000000082af49447d8a07e3bd95bd0d56f35241523fbab1000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000002c000000000000000000000000000000000000000000000000000000000000002c000000000000000000000000000000000000000000000000000000000000002a000000000000000000000000000000000000000000000000011cd20db72dd27c8000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000025375736869537761700000000000000000000000000000000000000000000000000000000000000011cd20db72dd27c80000000000000000000000000000000000000000000000000003794577670771000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000001b02da8cb0d097eb8d57a175b88c7d8b4799750600000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000002000000000000000000000000d4d42f0b6def4ce0383636770ef773390d85c61a00000000000000000000000082af49447d8a07e3bd95bd0d56f35241523fbab1000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000e00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000002000000000000000000000000d4d42f0b6def4ce0383636770ef773390d85c61a000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee0000000000000000000000000000000000000000000000000000000000000000869584cd00000000000000000000000086003b044f70dac0abc80ac8957305b6370893ed00000000000000000000000000000000000000000000001df4eb5c626327ace7',
|
|
});
|
|
|
|
const expectedL1GasCost = 578000;
|
|
expect(gasCost).gt(expectedL1GasCost);
|
|
expect(gasCost).lt(expectedL1GasCost * 2); // it's okay to overestimate but ideally not too much
|
|
});
|
|
});
|
|
});
|