Skip to content

Commit

Permalink
feat: update gas limit constants for paris upgrade (#20)
Browse files Browse the repository at this point in the history
* feat: update gas limit constants for paris upgrade

* feat: update manifest

* feat: update dependencies

* feat: formatting
  • Loading branch information
AndreasGassmann authored Aug 21, 2024
1 parent e34be9f commit 58f52bd
Show file tree
Hide file tree
Showing 6 changed files with 281 additions and 487 deletions.
6 changes: 3 additions & 3 deletions packages/snap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@
"@metamask/eslint-config-jest": "^10.0.0",
"@metamask/eslint-config-nodejs": "^10.0.0",
"@metamask/eslint-config-typescript": "^10.0.0",
"@metamask/snaps-cli": "^0.30.0",
"@metamask/snaps-types": "^0.30.0",
"@metamask/snaps-ui": "^0.30.0",
"@metamask/snaps-cli": "^1.0.0",
"@metamask/snaps-types": "^1.0.0",
"@metamask/snaps-ui": "^1.0.0",
"@types/chai": "^4.3.1",
"@types/chai-as-promised": "^7.1.5",
"@types/sinon": "^10.0.11",
Expand Down
2 changes: 1 addition & 1 deletion packages/snap/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/airgap-it/tezos-metamask-snap.git"
},
"source": {
"shasum": "gZ8KD6mLrT9pHe/Lw3RBxFGg5d3ilAUFmEgAenZ5F/s=",
"shasum": "OuUVE1WhSr509x0ooIs4cf0qLcITjYWrMVNKHZYJkJw=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
8 changes: 5 additions & 3 deletions packages/snap/src/tezos/constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
export const MAX_GAS_PER_BLOCK = 2600000;
export const GAS_LIMIT_PLACEHOLDER = '1040000';
export const STORAGE_LIMIT_PLACEHOLDER = '60000';
// See constants on https://mainnet.ecadinfra.com/chains/main/blocks/head/context/constants

export const MAX_GAS_PER_BLOCK = 1733333;
export const GAS_LIMIT_PER_OPERATION = '1040000';
export const STORAGE_LIMIT_PER_OPERATION = '60000';
export const FEE_PLACEHOLDER = '0';

export const DEFAULT_GAS_LIMIT = '10300';
Expand Down
12 changes: 6 additions & 6 deletions packages/snap/src/tezos/estimate-fee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import {
} from './types';
import {
MAX_GAS_PER_BLOCK,
GAS_LIMIT_PLACEHOLDER,
STORAGE_LIMIT_PLACEHOLDER,
GAS_LIMIT_PER_OPERATION,
STORAGE_LIMIT_PER_OPERATION,
FEE_PLACEHOLDER,
MINIMAL_FEE,
MINIMAL_FEE_PER_BYTE,
Expand Down Expand Up @@ -126,14 +126,14 @@ const sumUpFees = async (

if (
((operation as any).gas_limit && overrideParameters) ||
(operation as any).gas_limit === GAS_LIMIT_PLACEHOLDER
(operation as any).gas_limit === GAS_LIMIT_PER_OPERATION
) {
(operation as any).gas_limit = gasLimit.toString();
}

if (
((operation as any).storage_limit && overrideParameters) ||
(operation as any).storage_limit === STORAGE_LIMIT_PLACEHOLDER
(operation as any).storage_limit === STORAGE_LIMIT_PER_OPERATION
) {
(operation as any).storage_limit = storageLimit.toString();
}
Expand Down Expand Up @@ -173,9 +173,9 @@ export const estimateAndReplaceLimitsAndFee = async (
const gasValue = new BigNumber(MAX_GAS_PER_BLOCK).dividedToIntegerBy(
tezosWrappedOperation.contents.length,
);
const gasLimit = new BigNumber(GAS_LIMIT_PLACEHOLDER).gt(gasValue)
const gasLimit = new BigNumber(GAS_LIMIT_PER_OPERATION).gt(gasValue)
? gasValue
: GAS_LIMIT_PLACEHOLDER;
: GAS_LIMIT_PER_OPERATION;
const counter = startingCounter
? startingCounter.plus(i).toString()
: op.counter;
Expand Down
12 changes: 6 additions & 6 deletions packages/snap/src/tezos/prepare-operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import {
ALLOCATION_STORAGE_LIMIT,
DEFAULT_GAS_LIMIT,
FEE_PLACEHOLDER,
GAS_LIMIT_PLACEHOLDER,
STORAGE_LIMIT_PLACEHOLDER,
GAS_LIMIT_PER_OPERATION,
STORAGE_LIMIT_PER_OPERATION,
} from './constants';
import { estimateAndReplaceLimitsAndFee } from './estimate-fee';
import { getBalanceOfAddress } from './get-balance-of-address';
Expand Down Expand Up @@ -92,10 +92,10 @@ export const handleTransactionOperation = async (
transactionOperation.counter = transactionOperation.counter ?? defaultCounter;
transactionOperation.fee = transactionOperation.fee ?? defaultFee;
transactionOperation.gas_limit =
transactionOperation.gas_limit ?? GAS_LIMIT_PLACEHOLDER;
transactionOperation.gas_limit ?? GAS_LIMIT_PER_OPERATION;

transactionOperation.storage_limit =
transactionOperation.storage_limit ?? STORAGE_LIMIT_PLACEHOLDER;
transactionOperation.storage_limit ?? STORAGE_LIMIT_PER_OPERATION;

return transactionOperation;
};
Expand All @@ -121,10 +121,10 @@ export const handleOriginationOperation = async (
originationOperation.counter = originationOperation.counter ?? defaultCounter;
originationOperation.fee = originationOperation.fee ?? defaultFee;
originationOperation.gas_limit =
originationOperation.gas_limit ?? GAS_LIMIT_PLACEHOLDER;
originationOperation.gas_limit ?? GAS_LIMIT_PER_OPERATION;

originationOperation.storage_limit =
originationOperation.storage_limit ?? STORAGE_LIMIT_PLACEHOLDER;
originationOperation.storage_limit ?? STORAGE_LIMIT_PER_OPERATION;

return originationOperation;
};
Expand Down
Loading

0 comments on commit 58f52bd

Please sign in to comment.