Skip to content

Commit

Permalink
Improving gas estimates for l2s (#53)
Browse files Browse the repository at this point in the history
- Moved buildTrade and buildSwapMethodParameters to a separate library so we can access them in the gasModel
- On optimism the gasEstimate now considers the l1security fee
- Added a GasDataProvider that reads from the gas oracle contract to get gas constants for the l1 security fee calculations
- Surfaced initTicksCrossed, gasUseL1, and gasCostL1 to the logger so they’re printed at each run of the router (this was to help with manual gas estimation testing but can definitely be removed)
- Moved gasCost constants to be readable by chainId and updated some Arbitrum estimates
- Small nit change: added some logic so that if no protocols are specified in the CLI it defaults to V3 for chains that do not support v2

Co-authored-by: Lint Action <[email protected]>
  • Loading branch information
snreynolds and lint-action committed Feb 1, 2022
1 parent 0b5e989 commit 3091eb2
Show file tree
Hide file tree
Showing 15 changed files with 901 additions and 211 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

298 changes: 298 additions & 0 deletions src/abis/gasPriceOracle.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,298 @@
[
{
"inputs": [
{
"internalType": "address",
"name": "_owner",
"type": "address"
}
],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"name": "DecimalsUpdated",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"name": "GasPriceUpdated",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"name": "L1BaseFeeUpdated",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"name": "OverheadUpdated",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "previousOwner",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "newOwner",
"type": "address"
}
],
"name": "OwnershipTransferred",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"name": "ScalarUpdated",
"type": "event"
},
{
"inputs": [],
"name": "decimals",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "gasPrice",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "bytes",
"name": "_data",
"type": "bytes"
}
],
"name": "getL1Fee",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "bytes",
"name": "_data",
"type": "bytes"
}
],
"name": "getL1GasUsed",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "l1BaseFee",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "overhead",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "owner",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "renounceOwnership",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "scalar",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "_decimals",
"type": "uint256"
}
],
"name": "setDecimals",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "_gasPrice",
"type": "uint256"
}
],
"name": "setGasPrice",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "_baseFee",
"type": "uint256"
}
],
"name": "setL1BaseFee",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "_overhead",
"type": "uint256"
}
],
"name": "setOverhead",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "_scalar",
"type": "uint256"
}
],
"name": "setScalar",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "newOwner",
"type": "address"
}
],
"name": "transferOwnership",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
}
]
25 changes: 25 additions & 0 deletions src/providers/multicall-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ export type CallSameFunctionOnContractWithMultipleParams<
additionalConfig?: TAdditionalConfig;
};

export type CallMultipleFunctionsOnSameContractParams<
TFunctionParams,
TAdditionalConfig = any
> = {
address: string;
contractInterface: Interface;
functionNames: string[];
functionParams?: TFunctionParams[];
providerConfig?: ProviderConfig;
additionalConfig?: TAdditionalConfig;
};

export type SuccessResult<TReturn> = {
success: true;
result: TReturn;
Expand Down Expand Up @@ -96,4 +108,17 @@ export abstract class IMulticallProvider<TMulticallConfig = any> {
blockNumber: BigNumber;
results: Result<TReturn>[];
}>;

public abstract callMultipleFunctionsOnSameContract<
TFunctionParams extends any[] | undefined,
TReturn = any
>(
params: CallMultipleFunctionsOnSameContractParams<
TFunctionParams,
TMulticallConfig
>
): Promise<{
blockNumber: BigNumber;
results: Result<TReturn>[];
}>;
}
Loading

0 comments on commit 3091eb2

Please sign in to comment.