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(dryRun): return operation #1

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40,980 changes: 8,864 additions & 32,116 deletions package-lock.json

Large diffs are not rendered by default.

10,911 changes: 123 additions & 10,788 deletions packages/taquito/package-lock.json

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions packages/taquito/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export enum DEFAULT_FEE {
DELEGATION = 1257,
ORIGINATION = 10000,
TRANSFER = 10000,
REVEAL = 1420,
REVEAL = Number(process.env['DEFAULT_FEE_REVEAL'] || '1420'),
}
export enum DEFAULT_STORAGE_LIMIT {
DELEGATION = 0,
Expand All @@ -23,27 +23,27 @@ export enum Protocols {
PsBabyM1 = 'PsBabyM1eUXZseaJdmXFApDSBqj8YBfwELoxZHHW77EMcAbbwAS',
PsCARTHA = 'PsCARTHAGazKbHtnKfLzQg3kms52kSRpgnDY982a9oYsSXRLQEb',
PsDELPH1 = 'PsDELPH1Kxsxt8f9eWbxQeRxkjfbxoqM52jvs5Y5fBxWWh4ifpo',
PtEdo2Zk = 'PtEdo2ZkT9oKpimTah6x2embF25oss54njMuPzkJTEi5RqfdZFA'
PtEdo2Zk = 'PtEdo2ZkT9oKpimTah6x2embF25oss54njMuPzkJTEi5RqfdZFA',
}

export const protocols = {
'004': [Protocols.Pt24m4xi],
'005': [Protocols.PsBABY5H, Protocols.PsBabyM1],
'006': [Protocols.PsCARTHA],
'007': [Protocols.PsDELPH1],
'008': [Protocols.PtEdo2Zk] // edonet v2
'008': [Protocols.PtEdo2Zk], // edonet v2
};

export enum DefaultLambdaAddresses {
MAINNET = 'KT1CPuTzwC7h7uLXd5WQmpMFso1HxrLBUtpE',
CARTHAGENET = 'KT1VAy1o1FGiXYfD3YT7x7k5eF5HSHhmc1u6',
DELPHINET = 'KT19abMFs3haqyKYwqdLjK9GbtofryZLvpiK',
EDONET = 'KT1A64nVZDccAHGAsf1ZyVajXZcbiwjV3SnN'
EDONET = 'KT1A64nVZDccAHGAsf1ZyVajXZcbiwjV3SnN',
}

export enum ChainIds {
MAINNET = "NetXdQprcVkpaWU",
CARTHAGENET = "NetXjD3HPJJjmcd",
DELPHINET = "NetXm8tYqnMWky1",
EDONET = "NetXSgo1ZT2DRUG"
MAINNET = 'NetXdQprcVkpaWU',
CARTHAGENET = 'NetXjD3HPJJjmcd',
DELPHINET = 'NetXm8tYqnMWky1',
EDONET = 'NetXSgo1ZT2DRUG',
}
2 changes: 2 additions & 0 deletions packages/taquito/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { NoopSigner } from './signer/noop';
import { OperationFactory } from './wallet/opreation-factory';
import { RpcTzProvider } from './tz/rpc-tz-provider';
import { RPCEstimateProvider } from './contract/rpc-estimate-provider';
import { RPCDryRunProvider } from './contract/rpc-dry-run-provider';
import { RpcContractProvider } from './contract/rpc-contract-provider';
import { RPCBatchProvider } from './batch/rpc-batch-provider';

Expand Down Expand Up @@ -50,6 +51,7 @@ export class Context {

public readonly tz = new RpcTzProvider(this);
public readonly estimate = new RPCEstimateProvider(this);
public readonly dryRun = new RPCDryRunProvider(this);
public readonly contract = new RpcContractProvider(this, this.estimate);
public readonly batch = new RPCBatchProvider(this, this.estimate);
public readonly wallet = new Wallet(this);
Expand Down
44 changes: 44 additions & 0 deletions packages/taquito/src/contract/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
} from '../operations/types';
import { ContractAbstraction } from './contract';
import { Estimate } from './estimate';
import { PreapplyResponse } from '@taquito/rpc';

export type ContractSchema = Schema | unknown;

Expand Down Expand Up @@ -58,6 +59,49 @@ export interface EstimationProvider {
batch(params: ParamsWithKind[]): Promise<Estimate[]>;
}

export interface DryRunProvider {
/**
*
* @description Estimate gasLimit, storageLimit and fees for an origination operation
*
* @returns An estimation of gasLimit, storageLimit and fees for the operation
*
* @param Estimate
*/
originate(params: OriginateParams): Promise<PreapplyResponse>;

/**
*
* @description Estimate gasLimit, storageLimit and fees for an transfer operation
*
* @returns An estimation of gasLimit, storageLimit and fees for the operation
*
* @param Estimate
*/
transfer({ fee, storageLimit, gasLimit, ...rest }: TransferParams): Promise<PreapplyResponse>;

/**
*
* @description Estimate gasLimit, storageLimit and fees for a delegate operation
*
* @returns An estimation of gasLimit, storageLimit and fees for the operation
*
* @param Estimate
*/
setDelegate(params: DelegateParams): Promise<PreapplyResponse>;

/**
*
* @description Estimate gasLimit, storageLimit and fees for a delegate operation
*
* @returns An estimation of gasLimit, storageLimit and fees for the operation
*
* @param Estimate
*/
registerDelegate(params?: RegisterDelegateParams): Promise<PreapplyResponse>;
batch(params: ParamsWithKind[]): Promise<PreapplyResponse>;
}

export interface StorageProvider {
/**
*
Expand Down
143 changes: 143 additions & 0 deletions packages/taquito/src/contract/rpc-dry-run-provider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
import { OpKind } from '@taquito/rpc';
import {
DelegateParams,
OriginateParams,
ParamsWithKind,
RegisterDelegateParams,
RPCOperation,
TransferParams,
} from '../operations/types';
import { DryRunProvider } from './interface';
import {
createOriginationOperation,
createRegisterDelegateOperation,
createSetDelegateOperation,
createTransferOperation,
} from './prepare';
import { PreaplyEmitter, mergeLimits } from '../operations/preaply-emitter';

export class RPCDryRunProvider extends PreaplyEmitter implements DryRunProvider {
/**
*
* @description Estimate gasLimit, storageLimit and fees for an origination operation
*
* @returns An estimation of gasLimit, storageLimit and fees for the operation
*
* @param OriginationOperation Originate operation parameter
*/
async originate({ fee, storageLimit, gasLimit, ...rest }: OriginateParams) {
const pkh = await this.signer.publicKeyHash();
const DEFAULT_PARAMS = await this.getAccountLimits(pkh);
const op = await createOriginationOperation(
await this.context.parser.prepareCodeOrigination({
...rest,
...mergeLimits({ fee, storageLimit, gasLimit }, DEFAULT_PARAMS),
})
);
const transaction = await this.makeOperation({ operation: op, source: pkh });
return transaction;
}
/**
*
* @description Estimate gasLimit, storageLimit and fees for an transfer operation
*
* @returns An estimation of gasLimit, storageLimit and fees for the operation
*
* @param TransferOperation Originate operation parameter
*/
async transfer({ fee, storageLimit, gasLimit, ...rest }: TransferParams) {
const pkh = await this.signer.publicKeyHash();
const DEFAULT_PARAMS = await this.getAccountLimits(pkh);
const op = await createTransferOperation({
...rest,
...mergeLimits({ fee, storageLimit, gasLimit }, DEFAULT_PARAMS),
});

const transaction = await this.makeOperation({ operation: op, source: pkh });
return transaction;
}

/**
*
* @description Estimate gasLimit, storageLimit and fees for a delegate operation
*
* @returns An estimation of gasLimit, storageLimit and fees for the operation
*
* @param Estimate
*/
async setDelegate({ fee, gasLimit, storageLimit, ...rest }: DelegateParams) {
const sourceOrDefault = rest.source || (await this.signer.publicKeyHash());
const DEFAULT_PARAMS = await this.getAccountLimits(sourceOrDefault);
const op = await createSetDelegateOperation({
...rest,
...mergeLimits({ fee, storageLimit, gasLimit }, DEFAULT_PARAMS),
});
const transaction = await this.makeOperation({ operation: op, source: sourceOrDefault });
return transaction;
}

async batch(params: ParamsWithKind[]) {
const operations: RPCOperation[] = [];
const DEFAULT_PARAMS = await this.getAccountLimits(await this.signer.publicKeyHash());
for (const param of params) {
switch (param.kind) {
case OpKind.TRANSACTION:
operations.push(
await createTransferOperation({
...param,
...mergeLimits(param, DEFAULT_PARAMS),
})
);
break;
case OpKind.ORIGINATION:
operations.push(
await createOriginationOperation({
...param,
...mergeLimits(param, DEFAULT_PARAMS),
})
);
break;
case OpKind.DELEGATION:
operations.push(
await createSetDelegateOperation({
...param,
...mergeLimits(param, DEFAULT_PARAMS),
})
);
break;
case OpKind.ACTIVATION:
operations.push({
...param,
...DEFAULT_PARAMS,
});
break;
default:
throw new Error(`Unsupported operation kind: ${(param as any).kind}`);
}
}

const transaction = await this.makeOperation({ operation: operations });
return transaction;
}

/**
*
* @description Estimate gasLimit, storageLimit and fees for a delegate operation
*
* @returns An estimation of gasLimit, storageLimit and fees for the operation
*
* @param Estimate
*/
async registerDelegate(params: RegisterDelegateParams) {
const DEFAULT_PARAMS = await this.getAccountLimits(await this.signer.publicKeyHash());
const op = await createRegisterDelegateOperation(
{ ...params, ...DEFAULT_PARAMS },
await this.signer.publicKeyHash()
);
const trasactions = await this.makeOperation({
operation: op,
source: await this.signer.publicKeyHash(),
});
return trasactions;
}
}
Loading