Skip to content

Commit

Permalink
extend connection config with fee options (#151)
Browse files Browse the repository at this point in the history
* extend connection config with fee options

* txnReceipt type fixes

* refactor submitZKPResponse with fee data params
  • Loading branch information
volodymyr-basiuk authored Nov 10, 2023
1 parent cf6f9cf commit 796a9a5
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@0xpolygonid/js-sdk",
"version": "1.4.1",
"version": "1.4.2",
"description": "SDK to work with Polygon ID",
"main": "dist/node/cjs/index.js",
"module": "dist/node/esm/index.js",
Expand Down
22 changes: 20 additions & 2 deletions src/storage/blockchain/onchain-zkp-verifier.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { JsonRpcProvider, Signer, Contract } from 'ethers';
import { JsonRpcProvider, Signer, Contract, TransactionRequest } from 'ethers';
import { EthConnectionConfig } from './state';
import { IOnChainZKPVerifier } from '../interfaces/onchain-zkp-verifier';
import { ContractInvokeTransactionData, ZeroKnowledgeProofResponse } from '../../iden3comm';
Expand Down Expand Up @@ -70,7 +70,25 @@ export class OnChainZKPVerifier implements IOnChainZKPVerifier {
zkProof.proof.pi_c.slice(0, 2)
];

const tx = await contract.submitZKPResponse(...payload);
const feeData = await provider.getFeeData();
const maxFeePerGas = chainConfig.maxFeePerGas
? BigInt(chainConfig.maxFeePerGas)
: feeData.maxFeePerGas;
const maxPriorityFeePerGas = chainConfig.maxPriorityFeePerGas
? BigInt(chainConfig.maxPriorityFeePerGas)
: feeData.maxPriorityFeePerGas;

const gasLimit = await contract.submitZKPResponse.estimateGas(...payload);
const txData = await contract.submitZKPResponse.populateTransaction(...payload);

const request: TransactionRequest = {
to: txData.to,
data: txData.data,
gasLimit,
maxFeePerGas,
maxPriorityFeePerGas
};
const tx = await ethSigner.sendTransaction(request);
const txnReceipt = await tx.wait();
if (!txnReceipt) {
throw new Error(`transaction: ${tx.hash} failed to mined`);
Expand Down
27 changes: 23 additions & 4 deletions src/storage/blockchain/state.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { RootInfo, StateProof } from './../entities/state';
import { ZKProof } from '@iden3/js-jwz';
import { IStateStorage } from '../interfaces/state';
import { Contract, JsonRpcProvider, Signer } from 'ethers';
import { Contract, JsonRpcProvider, Signer, TransactionRequest } from 'ethers';
import { StateInfo } from '../entities/state';
import { StateTransitionPubSignals } from '../../circuits';
import { byteEncoder } from '../../utils';
Expand All @@ -17,7 +17,9 @@ export interface EthConnectionConfig {
url: string;
defaultGasLimit: number;
minGasPrice?: string;
maxGasPrice?: string;
maxGasPrice?: string; // eip-1559 transaction do not support gasPrice
maxFeePerGas?: string;
maxPriorityFeePerGas?: string;
confirmationBlockCount: number;
confirmationTimeout: number;
contractAddress: string;
Expand Down Expand Up @@ -102,9 +104,26 @@ export class EthStateStorage implements IStateStorage {
proof.proof.pi_c.slice(0, 2)
];

await contract.transitState.estimateGas(...payload);
const feeData = await this.provider.getFeeData();

const tx = await contract.transitState(...payload);
const maxFeePerGas = defaultEthConnectionConfig.maxFeePerGas
? BigInt(defaultEthConnectionConfig.maxFeePerGas)
: feeData.maxFeePerGas;
const maxPriorityFeePerGas = defaultEthConnectionConfig.maxPriorityFeePerGas
? BigInt(defaultEthConnectionConfig.maxPriorityFeePerGas)
: feeData.maxPriorityFeePerGas;

const gasLimit = await contract.transitState.estimateGas(...payload);
const txData = await contract.transitState.populateTransaction(...payload);

const request: TransactionRequest = {
to: txData.to,
data: txData.data,
gasLimit,
maxFeePerGas,
maxPriorityFeePerGas
};
const tx = await signer.sendTransaction(request);

const txnReceipt = await tx.wait();
if (!txnReceipt) {
Expand Down

0 comments on commit 796a9a5

Please sign in to comment.