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

extend connection config with fee options #151

Merged
merged 5 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
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();
volodymyr-basiuk marked this conversation as resolved.
Show resolved Hide resolved

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
};
volodymyr-basiuk marked this conversation as resolved.
Show resolved Hide resolved
const tx = await signer.sendTransaction(request);

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