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

feat(relay-kit): make gas limit optional #414

Merged
merged 43 commits into from
Aug 1, 2023

Conversation

dasanra
Copy link
Collaborator

@dasanra dasanra commented Apr 20, 2023

What it solves

Resolves #362

Features added

  • GasLimit optional in the relay-kit
  • Full Counterfactual deployment feature added to the relay-kit.
  • Improved usability of the relay-kit (no need to manually encode transactions by developers)

New Syntax

 
  // dump transfer as an example
  const dumpTransfer = {
    to: '0x123', // to address
    data: '0x',
    value: '1000000000000000' // 0.001 ETH
  }

  // batch to be executed by Gelato
  const transactions: MetaTransactionData[] = [
     dumpTransfer
  ]

  // we create the Gelato relay pack instance
  const relayPack = new GelatoRelayPack()

  // we create the relayed transaction
  const safeTransaction = await relayPack.createRelayedTransaction({ safe, transactions })

  // we sign the relayed transaction with all the owners
  const signedSafeTransaction = await signTransactionWithAllOwners(safe, safeTransaction)

  // we execute the relayed transaction with all the signatures
  const { taskId } = await relayPack.executeRelayTransaction(signedSafeTransaction, safe)

How this PR fixes it

Added Functions:

Protocol-kit

estimation functions

  • estimateTxBaseGas: This function estimates the baseGas of a Safe transaction:
    • Generation of the Safe transaction hash (txHash)
    • Increasing the nonce of the Safe.
    • Verifying the signatures of the Safe transaction
    • Payment to relayers for executing the transaction
    • Emitting events ExecutionSuccess or ExecutionFailure

Note: estimateTxBaseGas estimation does not include the transaction execution cost (safeTxGas)
Note: estimateTxBaseGas estimation does not include guards execution cost (Manual GasLimit required in this case)

  • estimateSafeTxGas: This function estimates the safeTxGas of a Safe transaction. The safeTxGas value represents the amount of gas required to execute the Safe transaction itself. The estimation method differs based on the version of the Safe:

    • For versions >= 1.3.0, the simulate function defined in the simulateTxAccessor.sol Contract is used.
    • For versions < 1.3.0, the deprecated requiredTxGas method defined in the GnosisSafe contract is used.
  • estimateSafeDeploymentGas: This function estimates the gas cost of deploying a Safe.

Detailed Summary

Basic Tests

Safe 1/1, v1.3.0 Goerli chain

Test 1: 1 Transfer in Goerli chain with a Safe 1/1 v1.3.0 (already deployed)

Transaction hash: 0x14e55a35cb34fb6fbf6f36c16ba320496877041d4c5b67f84b1c75f435aa9f8e

BaseGas
Estimated Real Difference (%)
47904 gas 35163 gas 26,59%
SafeTxGas
Estimated Real Difference (%)
9.006 gas 8.771 gas 2,6%
DeploymentGas
Estimated Real Difference (%)
0 0 0%
TotalGas
Estimated Real Difference (%)
206.910 gas 183.194 gas 11,46%
Gelato payment vs Transaction fee cost
Gelato Payment Transaction Fee Cost Difference (%)
0.000630 ETH 0.00042404 ETH 32,69%
Links
Screenshots

Captura de pantalla 2023-07-04 a las 14 56 18

Test 2: 1 Contract Interaction in Goerli chain with a Safe 1/1 v1.3.0 (already deployed)

Transaction hash: 0x70115d1489133d4994ac6eebfbc80b82eab2455e8fa42102c1a6ed5f2b59aa7d

BaseGas
Estimated Real Difference (%)
48.032 gas 35.424 gas 26,24%
SafeTxGas
Estimated Real Difference (%)
396.499 gas 396.258 gas 0,06%
DeploymentGas
Estimated Real Difference (%)
0 0 0%
TotalGas
Estimated Real Difference (%)
594.531 gas 571.502 gas 3,8%
Gelato payment vs Transaction fee cost
Gelato Payment Transaction Fee Cost Difference (%)
0.002834 ETH 0.0025333 ETH 10,62%
Links
Screenshots

Captura de pantalla 2023-07-04 a las 15 05 24

Test 3: a batch of 5 Transfers & 3 contract interactions in Goerli chain with a Safe 1/1 v1.3.0 (already deployed)

Transaction hash: 0x9fb36e0560834834f2c1148aed7526f18e8f96e61a477fffcf3f3271aff5558a

BaseGas
Estimated Real Difference (%)
53.624 gas 42.005 gas 21,66%
SafeTxGas
Estimated Real Difference (%)
1.222.793 gas 1.222.407 gas 0,031%
DeploymentGas
Estimated Real Difference (%)
0 0 0%
TotalGas
Estimated Real Difference (%)
1.426.417 gas 1.420.444 gas 0,41%
Gelato payment vs Transaction fee cost
Gelato Payment Transaction Fee Cost Difference (%)
0.6804 ETH 0.5555 ETH 18,35%
Links
Screenshots

Captura de pantalla 2023-07-04 a las 17 02 27

Safe 2/3, v1.3.0 Goerli chain

Test 4: 1 Transfer in Goerli chain with a Safe 2/3 v1.3.0 (already deployed)

Transaction hash: 0xd71a3c9b59f01bc758c2d50d230d8587fbb677f2a5b3898bf26676baf68ab43d.

BaseGas
Estimated Real Difference (%)
54.944 Gas 41.844 Gas 23,84%
SafeTxGas
Estimated Real Difference (%)
9.006 Gas 8.771 Gas 2,6%
DeploymentGas
Estimated Real Difference (%)
0 0 0%
TotalGas
Estimated Real Difference (%)
213.950 Gas 191.771 Gas 10,39%
Gelato payment vs Transaction fee cost
Gelato Payment Transaction Fee Cost Difference (%)
0.000005824 ETH 0.00000463 ETH 20,44%
Links
Screenshots
Captura de pantalla 2023-07-09 a las 15 40 26
Test 5: 1 Contract Interaction in Goerli chain with a Safe 2/3 v1.3.0 (already deployed)

Transaction hash: 0x3c10b488dd44c7716825f4938b3f3c30bac1d7dc7406b48d57863edaf073c388.

BaseGas
Estimated Real Difference (%)
55.072 gas 42.105 gas 23,54%
SafeTxGas
Estimated Real Difference (%)
396.499 gas 396.258 Gas 0,06%
DeploymentGas
Estimated Real Difference (%)
0 0 0%
TotalGas
Estimated Real Difference (%)
601.571 gas 580.083 Gas 3,57%
Gelato payment vs Transaction fee cost
Gelato Payment Transaction Fee Cost Difference (%)
0.00001339 ETH 0.000009951 ETH 25,69%
Links
Screenshots
Captura de pantalla 2023-07-09 a las 15 45 47
Test 6: a batch of 5 Transfers & 3 contract interactions in Goerli chain with a Safe 2/3 v1.3.0 (already deployed)

Transaction hash: 0xdca18d1e9a92f1076fbdd1c2bd3570a26e4f958be10caea55b3bd4f6c6d73437

BaseGas
Estimated Real Difference (%)
60.664 gas 48.686 gas 19,74%
SafeTxGas
Estimated Real Difference (%)
1.222.793 gas 1.222.407 Gas 0,031%
DeploymentGas
Estimated Real Difference (%)
0 0 0%
TotalGas
Estimated Real Difference (%)
1.433.457 gas 1.429.007 Gas 0,31%
Gelato payment vs Transaction fee cost
Gelato Payment Transaction Fee Cost Difference (%)
0.00000783 ETH 0.0000060463 ETH 22,86%
Links
Screenshots
Captura de pantalla 2023-07-09 a las 16 02 42

Counterfactual deployment feature

Safe 1/1, v1.3.0 Goerli chain

Test 7: 1 Transfer & Counterfactual deployment in Goerli chain with a Safe 1/1 v1.3.0

Transaction hash: 0xc26bf2b11820be139fa1d07b173e1970dd1a0ad323ebd002dad8c370edfcaa6f

BaseGas
Estimated Real Difference (%)
62904 48263 23,27%
SafeTxGas
Estimated Real Difference (%)
9677 9442 Gas 2,42%
DeploymentGas
Estimated Real Difference (%)
261547 234.592 Gas 10,30%
TotalGas
Estimated Real Difference (%)
484128 446.355 Gas 7,80%
Gelato payment vs Transaction fee cost
Gelato Payment Transaction Fee Cost Difference (%)
0.000000536 ETH 0.000000431 ETH 19,58%
Links
Screenshots
Captura de pantalla 2023-07-09 a las 16 25 06
Test 8: 1 Contract Interaction & Counterfactual deployment in Goerli chain with a Safe 1/1 v1.3.0

Transaction hash: 0x20008d1b370f3525ae315d2411a9068495e4ae24f6cfadb0b7391fff8a554f29

BaseGas
Estimated Real Difference (%)
63.032 gas 48.524 gas 23,01%
SafeTxGas
Estimated Real Difference (%)
413.599 gas 413.358 Gas 0,058%
DeploymentGas
Estimated Real Difference (%)
261547 234.592 Gas 10,30%
TotalGas
Estimated Real Difference (%)
888.178 gas 851.157 Gas 4,16%
Gelato payment vs Transaction fee cost
Gelato Payment Transaction Fee Cost Difference (%)
0.0000009526 ETH 0.0000005810 ETH 39%
Links
Screenshots
Captura de pantalla 2023-07-09 a las 16 40 13
Test 9: a batch of 5 Transfers & 3 contract interactions & Counterfactual deployment in Goerli chain with a Safe 1/1 v1.3.0

Transaction hash: 0x6df17fa801efe102d574fd6d92a7d823d5b90e2515bdf39eacfd41104c27dd4d

BaseGas
Estimated Real Difference (%)
68.624 gas 55.105 gas 19,7%
SafeTxGas
Estimated Real Difference (%)
1.233.248 gas 1.232.862 Gas 0,031%
DeploymentGas
Estimated Real Difference (%)
261.547 gas 234.592 Gas 10,30%
TotalGas
Estimated Real Difference (%)
1713419 1.693.588 Gas 4,30%
Gelato payment vs Transaction fee cost
Gelato Payment Transaction Fee Cost Difference (%)
0.000001549 ETH 0.000001275 ETH 17,68%
Links
Screenshots
Captura de pantalla 2023-07-09 a las 16 51 54

Safe 5/7, v1.3.0 Goerli chain

Test 10: 1 Transfer & Counterfactual deployment in Goerli chain with a Safe 5/7 v1.3.0

Transaction hash: 0x2a24c3574cb6127d1c63b00ffe43c68a6d70a1ead9703234f1f4befef05ec947

BaseGas
Estimated Real Difference (%)
91064 66985 26,44%
SafeTxGas
Estimated Real Difference (%)
9677 9442 Gas 2,42%
DeploymentGas
Estimated Real Difference (%)
406815 373.242 Gas 8,25%
TotalGas
Estimated Real Difference (%)
657556 616.276 Gas 6,27%
Gelato payment vs Transaction fee cost
Gelato Payment Transaction Fee Cost Difference (%)
0.000000605 ETH 0.000000407 ETH 32,72%
Links
Screenshots
Captura de pantalla 2023-07-09 a las 17 27 39
Test 11: 1 Contract interaction & Counterfactual deployment in Goerli chain with a Safe 5/7 v1.3.0

Transaction hash: 0xa39fd07b22286cccae2365308091064a3468ccf0c77cb51b02d8d9c0b7ddeede

BaseGas
Estimated Real Difference (%)
91192 67246 26,25%
SafeTxGas
Estimated Real Difference (%)
413599 413.358 Gas 0,058%
DeploymentGas
Estimated Real Difference (%)
406815 373.242 Gas 8,25%
TotalGas
Estimated Real Difference (%)
1061606 1.021.027 Gas 3,82%
Gelato payment vs Transaction fee cost
Gelato Payment Transaction Fee Cost Difference (%)
0.00000123 ETH 0.000000900 ETH 26,82%
Links
Screenshots
Test 12: a batch of 5 Transfers & 3 contract interactions & Counterfactual deployment in Goerli chain with a Safe 5/7 v1.3.0

Transaction hash: 0xf3c1d9723965763c058df5af7f9e09192b0a5f35c758b04af7b45403c37549d7

BaseGas
Estimated Real Difference (%)
96784 73828 23,71%
SafeTxGas
Estimated Real Difference (%)
1233248 1232862 Gas 0,03%
DeploymentGas
Estimated Real Difference (%)
406815 373.242 Gas 8,25%
TotalGas
Estimated Real Difference (%)
1886847 1.863.528 Gas 1,23%
Gelato payment vs Transaction fee cost
Gelato Payment Transaction Fee Cost Difference (%)
0.00000172 ETH 0.00000123 ETH 28,48%
Links
Screenshots
Captura de pantalla 2023-07-09 a las 17 10 35

Production chains

Gnosis chain

Test 13: a batch of 5 Transfers & 3 contract interactions & Counterfactual deployment in Gnosis chain with a Safe 5/7 v1.3.0

Transaction hash: 0xec3b28b7ce9535a6197cb0aa120f9056f0cb88b1dec517218b7219c68299a52c

BaseGas
Estimated Real Difference (%)
96784 73828 23,71%
SafeTxGas
Estimated Real Difference (%)
1233248 1.232.862 Gas 0,031%
DeploymentGas
Estimated Real Difference (%)
418258 373.208 Gas 10,77%
TotalGas
Estimated Real Difference (%)
1898290 1.863.506 Gas 1,83%
Gelato payment vs Transaction fee cost
Gelato Payment Transaction Fee Cost Difference (%)
0.003107 xDAI 0.002378 xDAI 23,46%
Links
Screenshots
Captura de pantalla 2023-07-09 a las 18 31 22
Test 14: a batch of 5 Transfers & 3 contract interactions in Gnosis chain with a Safe 5/7 v1.3.0 (already deployed)

Transaction hash: 0x5015a04d41eadf85b4379fb2bd9342a1126c28d3dac779760a963d4eb92de03b

BaseGas
Estimated Real Difference (%)
53504 42005 21,49%
SafeTxGas
Estimated Real Difference (%)
1222781 1222407 0,03%
DeploymentGas
Estimated Real Difference (%)
0 0 0%
TotalGas
Estimated Real Difference (%)
1426285 1.420.256 Gas 0,42%
Gelato payment vs Transaction fee cost
Gelato Payment Transaction Fee Cost Difference (%)
0.002916 xDAI 0.002385 xDAI 18,20%
Links
Screenshots

Polygon chain

Test 15: 1 Transfer deployment in Gnosis chain with a Safe 2/3 v1.3.0 (already deployed)

Transaction hash: 0xa630476c12e54ed409fed1c61273584d20fc760294ac4be10ab29faa09886a0b

BaseGas
Estimated Real Difference (%)
54932 40844 25,64%
SafeTxGas
Estimated Real Difference (%)
9006 8771 2,60%
DeploymentGas
Estimated Real Difference (%)
0 0 0%
TotalGas
Estimated Real Difference (%)
213938 191.767 Gas 10,36%
Gelato payment vs Transaction fee cost
Gelato Payment Transaction Fee Cost Difference (%)
0.025112 MATIC 0.02077 MATIC 17,28%
Links
Screenshots
Captura de pantalla 2023-07-09 a las 19 34 25
Test 16: a batch of 3 Transfers & 1 Contract Interaction & Counterfactual deployment in Polygon chain with a Safe 5/7 v1.3.0

Transaction hash: 0xb7149eaf7601ed3a22beceb89c59da7f4554a345f7bfd451daaad63d55f29bd7

BaseGas
Estimated Real Difference (%)
94104 70821 24,74%
SafeTxGas
Estimated Real Difference (%)
56079 55.760 Gas 0,56%
DeploymentGas
Estimated Real Difference (%)
406781 373.208 Gas 8,25%
TotalGas
Estimated Real Difference (%)
706964 675.740 Gas 4,41%
Gelato payment vs Transaction fee cost
Gelato Payment Transaction Fee Cost Difference (%)
0.1130 MATIC 0.0741 MATIC 34,424%
Links
Screenshots
Captura de pantalla 2023-07-09 a las 19 48 19
Test 17: 5 Transfers & 3 Contract Interactions & Counterfactual deployment in Polygon chain with a Safe 5/7 v1.3.0

Transaction hash: 0x99cb0f5ab0362a7f09bba067a2c6815b60aa33f397fea3ecde778707f5051906

BaseGas
Estimated Real Difference (%)
96724 73838 23,66%
SafeTxGas
Estimated Real Difference (%)
78911 78.525 Gas 0,48%
DeploymentGas
Estimated Real Difference (%)
406781 373.208 Gas 8,25%
TotalGas
Estimated Real Difference (%)
732416 709.099 Gas 3,18%
Gelato payment vs Transaction fee cost
Gelato Payment Transaction Fee Cost Difference (%)
0.0955 MATIC 0.0784 MATIC 17,90%
Links
Screenshots
Captura de pantalla 2023-07-09 a las 20 19 05

Formula used to calculate the difference estimated vs real

( (Estimated - Real) / Estimated ) * 100 = X %

@dasanra dasanra changed the base branch from main to development April 20, 2023 08:50
@germartinez germartinez changed the title feature(relay-kit): make gas limit optional feat(relay-kit): make gas limit optional May 29, 2023
@coveralls
Copy link

coveralls commented Jul 12, 2023

Pull Request Test Coverage Report for Build 5668577336

  • 24 of 44 (54.55%) changed or added relevant lines in 1 file are covered.
  • 2 unchanged lines in 1 file lost coverage.
  • Overall coverage decreased (-2.3%) to 72.651%

Changes Missing Coverage Covered Lines Changed/Added Lines %
packages/relay-kit/src/packs/gelato/GelatoRelayPack.ts 24 44 54.55%
Files with Coverage Reduction New Missed Lines %
packages/relay-kit/src/packs/gelato/GelatoRelayPack.ts 2 67.96%
Totals Coverage Status
Change from base Build 5542834488: -2.3%
Covered Lines: 416
Relevant Lines: 530

💛 - Coveralls

nonce?: number
}

export interface MultiSendTransaction {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is MetaTransactionData at line 21

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!

@DaniSomoza DaniSomoza marked this pull request as ready for review July 26, 2023 12:19
} else {
const temporarySafeContract = await getSafeContract({
// We use the lastest version of the Safe contract to get the correct version of this Safe
const latestVersionOfTheSafeContract = await getSafeContract({
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking that this variable name may not be accurate, as the DEFAULT_SAFE_VERSION may not be the latest.

I would rename it to defaultSafeContractInstance

@dasanra dasanra merged commit 5b5fff3 into development Aug 1, 2023
14 of 15 checks passed
@dasanra dasanra deleted the make-gas-limit-optional branch August 1, 2023 14:45
@github-actions github-actions bot locked and limited conversation to collaborators Aug 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enable automatic gas estimation when using the relay-kit
5 participants