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

2447 update gas limit for reveal in nairobi #2494

Merged
merged 10 commits into from
Jun 2, 2023
2 changes: 1 addition & 1 deletion cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"precommit",
"println",
"Protofire",
"PtNairob",
"PtNairobi",
"rollups",
"Roxane",
"SAPLINGCONTRACT",
Expand Down
6 changes: 3 additions & 3 deletions integration-tests/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const nairobinetEphemeral = {
knownTzip1216Contract: process.env['TEZOS_NAIROBINET_TZIP1216CONTRACT_ADDRESS'] || knownTzip12BigMapOffChainContractPtNairobi,
knownSaplingContract: process.env['TEZOS_NAIROBINET_SAPLINGCONTRACT_ADDRESS'] || knownSaplingContractPtNairobi,
knownViewContract: process.env['TEZOS_NAIROBINET_ON_CHAIN_VIEW_CONTRACT'] || knownOnChainViewContractAddressPtNairobi,
protocol: Protocols.PtNairob,
protocol: Protocols.PtNairobi,
signerConfig: {
type: SignerType.EPHEMERAL_KEY as SignerType.EPHEMERAL_KEY,
keyUrl: 'https://api.tez.ie/keys/nairobinet',
Expand Down Expand Up @@ -119,7 +119,7 @@ const ghostnetEphemeral = {
knownTzip1216Contract: process.env['TEZOS_GHOSTNET_TZIP1216CONTRACT_ADDRESS'] || knownTzip12BigMapOffChainContractPtGhostnet,
knownSaplingContract: process.env['TEZOS_GHOSTNET_SAPLINGCONTRACT_ADDRESS'] || knownSaplingContractPtGhostnet,
knownViewContract: process.env['TEZOS_GHOSTNET_ON_CHAIN_VIEW_CONTRACT'] || knownOnChainViewContractAddressPtGhostnet,
protocol: Protocols.PtNairob,
protocol: Protocols.PtNairobi,
signerConfig: {
type: SignerType.EPHEMERAL_KEY as SignerType.EPHEMERAL_KEY,
keyUrl: 'https://api.tez.ie/keys/ghostnet',
Expand Down Expand Up @@ -155,7 +155,7 @@ const nairobinetSecretKey = {
knownTzip1216Contract: process.env['TEZOS_NAIROBINET_TZIP1216CONTRACT_ADDRESS'] || knownTzip12BigMapOffChainContractPtNairobi,
knownSaplingContract: process.env['TEZOS_NAIROBINET_SAPLINGCONTRACT_ADDRESS'] || knownSaplingContractPtNairobi,
knownViewContract: process.env['TEZOS_NAIROBINET_ON_CHAIN_VIEW_CONTRACT'] || knownOnChainViewContractAddressPtNairobi,
protocol: Protocols.PtNairob,
protocol: Protocols.PtNairobi,
signerConfig: defaultSecretKey
};

Expand Down
112 changes: 56 additions & 56 deletions integration-tests/contract-estimation-tests.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,27 +38,27 @@ CONFIGS().forEach(({ lib, setup, knownBaker, createAddress, rpc }) => {

it('Verify .estimate.transfer with allocated destination', async (done) => {
const estimate = await LowAmountTez.estimate.transfer({ to: await Tezos.signer.publicKeyHash(), amount: 0.019 });
expect(estimate.gasLimit).toEqual(1101);
expect(estimate.gasLimit).toEqual(201);
expect(estimate.storageLimit).toEqual(0);
expect(estimate.suggestedFeeMutez).toEqual(464);
expect(estimate.suggestedFeeMutez).toEqual(374);
expect(estimate.burnFeeMutez).toEqual(0);
expect(estimate.minimalFeeMutez).toEqual(364);
expect(estimate.totalCost).toEqual(364);
expect(estimate.usingBaseFeeMutez).toEqual(364);
expect(estimate.consumedMilligas).toEqual(1000040);
expect(estimate.minimalFeeMutez).toEqual(274);
expect(estimate.totalCost).toEqual(274);
expect(estimate.usingBaseFeeMutez).toEqual(274);
expect(estimate.consumedMilligas).toEqual(100040);
done();
});

it('Verify .estimate.transfer with unallocated destination', async (done) => {
const estimate = await LowAmountTez.estimate.transfer({ to: await (await createAddress()).signer.publicKeyHash(), amount: 0.017 });
expect(estimate.gasLimit).toEqual(1101);
expect(estimate.gasLimit).toEqual(201);
expect(estimate.storageLimit).toEqual(257);
expect(estimate.suggestedFeeMutez).toEqual(464);
expect(estimate.suggestedFeeMutez).toEqual(374);
expect(estimate.burnFeeMutez).toEqual(64250);
expect(estimate.minimalFeeMutez).toEqual(364);
expect(estimate.totalCost).toEqual(64614);
expect(estimate.usingBaseFeeMutez).toEqual(364);
expect(estimate.consumedMilligas).toEqual(1000040);
expect(estimate.minimalFeeMutez).toEqual(274);
expect(estimate.totalCost).toEqual(64524);
expect(estimate.usingBaseFeeMutez).toEqual(274);
expect(estimate.consumedMilligas).toEqual(100040);
done();
});

Expand All @@ -68,14 +68,14 @@ CONFIGS().forEach(({ lib, setup, knownBaker, createAddress, rpc }) => {
code: ligoSample,
storage: 0,
});
expect(estimate.gasLimit).toEqual(1577);
expect(estimate.gasLimit).toEqual(677);
expect(estimate.storageLimit).toEqual(571);
expect(estimate.suggestedFeeMutez).toEqual(803);
expect(estimate.suggestedFeeMutez).toEqual(713);
expect(estimate.burnFeeMutez).toEqual(142750);
expect(estimate.minimalFeeMutez).toEqual(703);
expect(estimate.totalCost).toEqual(143453);
expect(estimate.usingBaseFeeMutez).toEqual(703);
expect(estimate.consumedMilligas).toEqual(1476347);
expect(estimate.minimalFeeMutez).toEqual(613);
expect(estimate.totalCost).toEqual(143363);
expect(estimate.usingBaseFeeMutez).toEqual(613);
expect(estimate.consumedMilligas).toEqual(576347);
done();
});

Expand All @@ -84,28 +84,28 @@ CONFIGS().forEach(({ lib, setup, knownBaker, createAddress, rpc }) => {
delegate: knownBaker,
source: await LowAmountTez.signer.publicKeyHash(),
});
expect(estimate.gasLimit).toEqual(1100);
expect(estimate.gasLimit).toEqual(200);
expect(estimate.storageLimit).toEqual(0);
expect(estimate.suggestedFeeMutez).toEqual(459);
expect(estimate.suggestedFeeMutez).toEqual(369);
expect(estimate.burnFeeMutez).toEqual(0);
expect(estimate.minimalFeeMutez).toEqual(359);
expect(estimate.totalCost).toEqual(359);
expect(estimate.usingBaseFeeMutez).toEqual(359);
expect(estimate.consumedMilligas).toEqual(1000000);
expect(estimate.minimalFeeMutez).toEqual(269);
expect(estimate.totalCost).toEqual(269);
expect(estimate.usingBaseFeeMutez).toEqual(269);
expect(estimate.consumedMilligas).toEqual(100000);
done();
});

it('Verify .estimate.transfer for internal transfer to allocated implicit', async (done) => {
const tx = contract.methods.do(MANAGER_LAMBDA.transferImplicit(knownBaker, 5)).toTransferParams();
const estimate = await LowAmountTez.estimate.transfer(tx);
expect(estimate.gasLimit).toEqual(3257);
expect(estimate.gasLimit).toEqual(1457);
expect(estimate.storageLimit).toEqual(0);
expect(estimate.suggestedFeeMutez).toEqual(752);
expect(estimate.suggestedFeeMutez).toEqual(572);
expect(estimate.burnFeeMutez).toEqual(0);
expect(estimate.minimalFeeMutez).toEqual(652);
expect(estimate.totalCost).toEqual(652);
expect(estimate.usingBaseFeeMutez).toEqual(652);
expect(estimate.consumedMilligas).toEqual(3156735);
expect(estimate.minimalFeeMutez).toEqual(472);
expect(estimate.totalCost).toEqual(472);
expect(estimate.usingBaseFeeMutez).toEqual(472);
expect(estimate.consumedMilligas).toEqual(1356735);
done();
});

Expand All @@ -116,42 +116,42 @@ CONFIGS().forEach(({ lib, setup, knownBaker, createAddress, rpc }) => {
50)
).toTransferParams();
const estimate = await LowAmountTez.estimate.transfer(tx);
expect(estimate.gasLimit).toEqual(4272);
expect(estimate.gasLimit).toEqual(1572);
expect(estimate.storageLimit).toEqual(514);
expect(estimate.suggestedFeeMutez).toEqual(913);
expect(estimate.suggestedFeeMutez).toEqual(643);
expect(estimate.burnFeeMutez).toEqual(128500);
expect(estimate.minimalFeeMutez).toEqual(813);
expect(estimate.totalCost).toEqual(129313);
expect(estimate.usingBaseFeeMutez).toEqual(813);
expect(estimate.consumedMilligas).toEqual(4171270);
expect(estimate.minimalFeeMutez).toEqual(543);
expect(estimate.totalCost).toEqual(129043);
expect(estimate.usingBaseFeeMutez).toEqual(543);
expect(estimate.consumedMilligas).toEqual(1471270);
done();
});

it('Verify .estimate.transfer for internal origination', async (done) => {
const tx = contract.methods.do(originate()).toTransferParams();
const estimate = await LowAmountTez.estimate.transfer(tx);
expect(estimate.gasLimit).toEqual(3668);
expect(estimate.gasLimit).toEqual(1868);
expect(estimate.storageLimit).toEqual(317);
expect(estimate.suggestedFeeMutez).toEqual(799);
expect(estimate.suggestedFeeMutez).toEqual(619);
expect(estimate.burnFeeMutez).toEqual(79250);
expect(estimate.minimalFeeMutez).toEqual(699);
expect(estimate.totalCost).toEqual(79949);
expect(estimate.usingBaseFeeMutez).toEqual(699);
expect(estimate.consumedMilligas).toEqual(3567848);
expect(estimate.minimalFeeMutez).toEqual(519);
expect(estimate.totalCost).toEqual(79769);
expect(estimate.usingBaseFeeMutez).toEqual(519);
expect(estimate.consumedMilligas).toEqual(1767848);
done();
});

it('Verify .estimate.transfer for multiple internal originations', async (done) => {
const tx = contract.methods.do(originate2()).toTransferParams();
const estimate = await LowAmountTez.estimate.transfer(tx);
expect(estimate.gasLimit).toEqual(5094);
expect(estimate.gasLimit).toEqual(2394);
expect(estimate.storageLimit).toEqual(634);
expect(estimate.suggestedFeeMutez).toEqual(1007);
expect(estimate.suggestedFeeMutez).toEqual(737);
expect(estimate.burnFeeMutez).toEqual(158500);
expect(estimate.minimalFeeMutez).toEqual(907);
expect(estimate.totalCost).toEqual(159407);
expect(estimate.usingBaseFeeMutez).toEqual(907);
expect(estimate.consumedMilligas).toEqual(4993496);
expect(estimate.minimalFeeMutez).toEqual(637);
expect(estimate.totalCost).toEqual(159137);
expect(estimate.usingBaseFeeMutez).toEqual(637);
expect(estimate.consumedMilligas).toEqual(2293496);
// Do the actual operation
const op2 = await contract.methods.do(originate2()).send();
await op2.confirmation();
Expand All @@ -175,14 +175,14 @@ CONFIGS().forEach(({ lib, setup, knownBaker, createAddress, rpc }) => {

it('Verify .estimate.transfer to regular address', async (done) => {
let estimate = await LowAmountTez.estimate.transfer({ to: await Tezos.signer.publicKeyHash(), mutez: true, amount: amt - (1382 + DEFAULT_FEE.REVEAL) });
expect(estimate.gasLimit).toEqual(1101);
expect(estimate.gasLimit).toEqual(201);
expect(estimate.storageLimit).toEqual(0);
expect(estimate.suggestedFeeMutez).toEqual(462);
expect(estimate.suggestedFeeMutez).toEqual(372);
expect(estimate.burnFeeMutez).toEqual(0);
expect(estimate.minimalFeeMutez).toEqual(362);
expect(estimate.totalCost).toEqual(362);
expect(estimate.usingBaseFeeMutez).toEqual(362);
expect(estimate.consumedMilligas).toEqual(1000040);
expect(estimate.minimalFeeMutez).toEqual(272);
expect(estimate.totalCost).toEqual(272);
expect(estimate.usingBaseFeeMutez).toEqual(272);
expect(estimate.consumedMilligas).toEqual(100040);
done();
});

Expand All @@ -191,7 +191,7 @@ CONFIGS().forEach(({ lib, setup, knownBaker, createAddress, rpc }) => {
const params = { fee: 2000, to: await Tezos.signer.publicKeyHash(), mutez: true, amount: amt - (1382 + DEFAULT_FEE.REVEAL) };

await expect(LowAmountTez.estimate.transfer(params)).rejects.toMatchObject({
id: 'proto.016-PtMumbai.implicit.empty_implicit_contract',
id: 'proto.017-PtNairob.implicit.empty_implicit_contract',
});
done();
});
Expand All @@ -200,7 +200,7 @@ CONFIGS().forEach(({ lib, setup, knownBaker, createAddress, rpc }) => {
await expect(
LowAmountTez.estimate.transfer({ to: await Tezos.signer.publicKeyHash(), mutez: true, amount: amt })
).rejects.toMatchObject({
id: 'proto.016-PtMumbai.tez.subtraction_underflow',
id: 'proto.017-PtNairob.tez.subtraction_underflow',
});
done();
});
Expand Down
35 changes: 31 additions & 4 deletions packages/taquito/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@ export enum DEFAULT_GAS_LIMIT {
DELEGATION = 10600,
ORIGINATION = 10600,
TRANSFER = 10600,
REVEAL = 1100,
/* This is used for gas_limit. There is no harm in setting a higher limit.
Only if an account has a balance that is very close to the total gas consumption,
then this margin can fail the operation.
Another benefit of this higher value is that then Dapps build with Taquito 17 can
still work with Mumbainet, as this value is higher than the reveal cost in Mumbai.
*/
REVEAL_TZ1 = 2000,
REVEAL_TZ2 = 2000,
REVEAL_TZ3 = 2000,
REVEAL_TZ4 = 2000,
ac10n marked this conversation as resolved.
Show resolved Hide resolved
}
export enum DEFAULT_FEE {
DELEGATION = 1257,
Expand Down Expand Up @@ -36,7 +45,7 @@ export enum Protocols {
PtLimaPtL = 'PtLimaPtLMwfNinJi9rCfDPWea8dFgTZ1MeJ9f1m2SRic6ayiwW',
PtMumbaii = 'PtMumbaiiFFEGbew1rRjzSPyzRbA51Tm3RVZL5suHPxSZYDhCEc',
PtMumbai2 = 'PtMumbai2TmsJHNGRkD8v8YDbtao7BLUC3wjASn1inAKLFCjaH1',
PtNairob = 'PtNairobiyssHuh87hEhfVBGCVrK3WnS8Z2FT4ymB5tAa4r1nQf',
PtNairobi = 'PtNairobiyssHuh87hEhfVBGCVrK3WnS8Z2FT4ymB5tAa4r1nQf',
ProtoALpha = 'ProtoALphaALphaALphaALphaALphaALphaALphaALphaDdp3zK',
}

Expand All @@ -54,7 +63,7 @@ export const protocols = {
'014': [Protocols.PtKathman],
'015': [Protocols.PtLimaPtL],
'016': [Protocols.PtMumbai2], // mumbai v2
'017': [Protocols.PtNairob],
'017': [Protocols.PtNairobi],
'018': [Protocols.ProtoALpha],
};

Expand All @@ -73,5 +82,23 @@ export enum ChainIds {
LIMANET = 'NetXizpkH94bocH',
MUMBAINET = 'NetXQw6nWSnrJ5t',
MUMBAINET2 = 'NetXgbcrNtXD2yA',
NAIROBINET = 'NetXyuzvDo2Ugzb'
NAIROBINET = 'NetXyuzvDo2Ugzb',
}

export const getRevealGasLimit = (address: string) =>
Math.round((getRevealGasLimitInternal(address) * 11) / 10);

const getRevealGasLimitInternal = (address: string) => {
switch (address.substring(0, 3)) {
case 'tz1':
return DEFAULT_GAS_LIMIT.REVEAL_TZ1;
case 'tz2':
return DEFAULT_GAS_LIMIT.REVEAL_TZ2;
case 'tz3':
return DEFAULT_GAS_LIMIT.REVEAL_TZ3;
case 'tz4':
return DEFAULT_GAS_LIMIT.REVEAL_TZ4;
default:
throw new Error(`Cannot estimate reveal gas limit for ${address}`);
}
};
11 changes: 8 additions & 3 deletions packages/taquito/src/contract/prepare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ import {
ActivationParams,
RPCActivateOperation,
} from '../operations/types';
import { DEFAULT_FEE, DEFAULT_GAS_LIMIT, DEFAULT_STORAGE_LIMIT } from '../constants';
import {
DEFAULT_FEE,
DEFAULT_GAS_LIMIT,
DEFAULT_STORAGE_LIMIT,
getRevealGasLimit,
} from '../constants';
import { format } from '@taquito/utils';
import {
InvalidCodeParameter,
Expand Down Expand Up @@ -169,7 +174,7 @@ export const createRegisterDelegateOperation = async (
export const createRevealOperation = async (
{
fee = DEFAULT_FEE.REVEAL,
gasLimit = DEFAULT_GAS_LIMIT.REVEAL,
gasLimit = undefined,
storageLimit = DEFAULT_STORAGE_LIMIT.REVEAL,
}: RevealParams,
source: string,
Expand All @@ -180,7 +185,7 @@ export const createRevealOperation = async (
fee,
public_key: publicKey,
source,
gas_limit: gasLimit,
gas_limit: gasLimit ?? getRevealGasLimit(source),
storage_limit: storageLimit,
} as RPCRevealOperation;
};
Expand Down
8 changes: 4 additions & 4 deletions packages/taquito/src/prepare/prepare-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
ActivationParams,
} from '../operations/types';
import { PreparationProvider, PreparedOperation } from './interface';
import { DEFAULT_FEE, DEFAULT_GAS_LIMIT, DEFAULT_STORAGE_LIMIT, Protocols } from '../constants';
import { DEFAULT_FEE, DEFAULT_STORAGE_LIMIT, Protocols, getRevealGasLimit } from '../constants';
import { InvalidOperationKindError, DeprecationError } from '@taquito/utils';
import { PublicKeyNotFoundError, RPCResponseError } from '../error';
import { Context } from '../context';
Expand Down Expand Up @@ -164,7 +164,7 @@ export class PrepareProvider extends Provider implements PreparationProvider {
private async addRevealOperationIfNeeded(operation: RPCOperation, publicKeyHash: string) {
if (isOpRequireReveal(operation)) {
const ops: RPCOperation[] = [operation];
const { publicKey } = await this.getKeys();
const { publicKey, pkh } = await this.getKeys();
if (await this.isAccountRevealRequired(publicKeyHash)) {
if (!publicKey) {
throw new RevealEstimateError();
Expand All @@ -174,7 +174,7 @@ export class PrepareProvider extends Provider implements PreparationProvider {
{
fee: DEFAULT_FEE.REVEAL,
storageLimit: DEFAULT_STORAGE_LIMIT.REVEAL,
gasLimit: DEFAULT_GAS_LIMIT.REVEAL,
gasLimit: getRevealGasLimit(pkh),
},
publicKeyHash,
publicKey
Expand Down Expand Up @@ -987,7 +987,7 @@ export class PrepareProvider extends Provider implements PreparationProvider {
{
fee: DEFAULT_FEE.REVEAL,
storageLimit: DEFAULT_STORAGE_LIMIT.REVEAL,
gasLimit: DEFAULT_GAS_LIMIT.REVEAL,
gasLimit: getRevealGasLimit(pkh),
},
pkh,
publicKey
Expand Down
Loading