Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement gas refunds as an interaction. (gnosis/gp-v2-contracts#445)
Closes #442 The idea is to make gas refunds be encoded as interactions instead of being part of the settlement parameters. ### Gas Cost Analysis #### Native Order Refunds  #### Interaction Based Order Refunds  #### Results: So, as @fleupold mentioned, it would be smarter to accumulate refunds and then use them all at once. This reduces the overall gas cost per order. In the case of **native order refunds**, the optimal "refund batch" size to use is 7: - The "cold start" gas cost per order is `181490` (this is the average cost per order when doing 7 settlements without refunds, and then an 8th settlement with 7 refunds) - The "continuous" gas cost per order is `180467` (this is the average cost per order when doing 6 settlements without refunds, then a 7th settlement with 7 refunds) In the case of **interaction based order refunds**, the optimal "refund batch" size is 8: - The "cold start" gas cost per order is `181237` - The "continuous" gas cost per order is `180484` (only 17 gas more) This means that the gas cost per order is almost the same 🎉. One other bonus of keeping order refunds as interactions, is that if, for whatever reason, storage refunds get removed from the EVM, we don't pay additional costs per settlement for a dead feature if we use interaction based storage refunds. #### Full Settlements The full settlement benchmarks show a similar story, where settlements without gas costs become cheaper, and settlements without become more expensive. <details><summary>Benchmarks</summary> ``` === Settlement Gas Benchmarks === --------------+--------------+--------------+--------------+-------------- tokens | trades | interactions | refunds | gas --------------+--------------+--------------+--------------+-------------- 2 | 10 | 0 | 0 | 752558 (change: -137 / trade) 3 | 10 | 0 | 0 | 753102 (change: -136 / trade) 4 | 10 | 0 | 0 | 762034 (change: -139 / trade) 5 | 10 | 0 | 0 | 766766 (change: -137 / trade) 6 | 10 | 0 | 0 | 763086 (change: -139 / trade) 7 | 10 | 0 | 0 | 772018 (change: -134 / trade) 8 | 10 | 0 | 0 | 776690 (change: -136 / trade) 8 | 20 | 0 | 0 | 1463360 (change: -72 / trade) 8 | 30 | 0 | 0 | 2111933 (change: -47 / trade) 8 | 40 | 0 | 0 | 2764685 (change: -33 / trade) 8 | 50 | 0 | 0 | 3418082 (change: -28 / trade) 8 | 60 | 0 | 0 | 4067559 (change: -24 / trade) 8 | 70 | 0 | 0 | 4721274 (change: -19 / trade) 8 | 80 | 0 | 0 | 5374021 (change: -18 / trade) 2 | 10 | 1 | 0 | 823946 (change: -137 / trade) 2 | 10 | 2 | 0 | 870598 (change: -142 / trade) 2 | 10 | 3 | 0 | 917286 (change: -133 / trade) 2 | 10 | 4 | 0 | 963926 (change: -135 / trade) 2 | 10 | 5 | 0 | 1010614 (change: -136 / trade) 2 | 10 | 6 | 0 | 1057230 (change: -135 / trade) 2 | 10 | 7 | 0 | 1103870 (change: -139 / trade) 2 | 10 | 8 | 0 | 1150498 (change: -142 / trade) 2 | 50 | 0 | 10 | 3126161 (change: 196 / trade) 2 | 50 | 0 | 15 | 3085349 (change: 197 / trade) 2 | 50 | 0 | 20 | 3044429 (change: 200 / trade) 2 | 50 | 0 | 25 | 3003485 (change: 197 / trade) 2 | 50 | 0 | 30 | 2962745 (change: 202 / trade) 2 | 50 | 0 | 35 | 2921813 (change: 203 / trade) 2 | 50 | 0 | 40 | 2880953 (change: 204 / trade) 2 | 50 | 0 | 45 | 2839997 (change: 202 / trade) 2 | 50 | 0 | 50 | 2799233 (change: 207 / trade) 2 | 2 | 0 | 0 | 186781 (change: -683 / trade) 2 | 1 | 1 | 0 | 187309 (change: -1378 / trade) 10 | 100 | 10 | 20 | 6618975 (change: 100 / trade) ``` </details> ### Test Plan CI, added new unit tests for interaction-only methods. Coverage stays at 100%.
- Loading branch information