From b0666d4fa158653d4d3a301423eb04f681e07ff2 Mon Sep 17 00:00:00 2001 From: Raffael Campos Date: Tue, 14 Nov 2023 15:06:20 -0300 Subject: [PATCH 1/9] Add customizable timeout to network response validation The network response validation function 'validateWithNetworkResponses' now includes an optional 'verificationOptions' parameter. This allows for a customizable timeout setting to be passed in, which overrides the previous hard-coded value. The changes also include updates to related files to handle this new addition, such as 'LogStoreClient.ts' and 'Queries.ts'. --- packages/client/src/LogStoreClient.ts | 12 +++-- packages/client/src/Queries.ts | 13 ++++-- .../validateNetworkResponses.ts | 46 +++++++++++++++---- 3 files changed, 56 insertions(+), 15 deletions(-) diff --git a/packages/client/src/LogStoreClient.ts b/packages/client/src/LogStoreClient.ts index d619cea3..3549e295 100644 --- a/packages/client/src/LogStoreClient.ts +++ b/packages/client/src/LogStoreClient.ts @@ -19,7 +19,13 @@ import { import { LogStoreClientEventEmitter, LogStoreClientEvents } from './events'; import { LogStoreClientConfig } from './LogStoreClientConfig'; import { LogStoreMessageStream } from './LogStoreMessageStream'; -import { HttpApiQueryDict, Queries, QueryInput, QueryType } from './Queries'; +import { + HttpApiQueryDict, + Queries, + QueryInput, + type QueryOptions, + QueryType, +} from './Queries'; import { LogStoreRegistry } from './registry/LogStoreRegistry'; import { QueryManager } from './registry/QueryManager'; import { TokenManager } from './registry/TokenManager'; @@ -128,9 +134,7 @@ export class LogStoreClient extends StreamrClient { streamDefinition: StreamDefinition, input: QueryInput, onMessage?: MessageListener, - options?: { - verifyNetworkResponses?: boolean; - } + options?: QueryOptions ): Promise { const streamPartId = await this.streamIdBuilder.toStreamPartID( streamDefinition diff --git a/packages/client/src/Queries.ts b/packages/client/src/Queries.ts index 08af4ce5..db9f5303 100644 --- a/packages/client/src/Queries.ts +++ b/packages/client/src/Queries.ts @@ -20,7 +20,10 @@ import { LogStoreClientConfigInjectionToken } from './Config'; import { HttpUtil } from './HttpUtil'; import { LogStoreMessageStream } from './LogStoreMessageStream'; import { NodeManager } from './registry/NodeManager'; -import { validateWithNetworkResponses } from './utils/networkValidation/validateNetworkResponses'; +import { + validateWithNetworkResponses, + type VerificationOptions, +} from './utils/networkValidation/validateNetworkResponses'; import { SystemMessageObservable } from './utils/SystemMessageObservable'; import { LogStoreClientSystemMessagesInjectionToken } from './utils/systemStreamUtils'; import { counterId } from './utils/utils'; @@ -132,7 +135,7 @@ function isQueryRange(options: any): options is T { } export type QueryOptions = { - verifyNetworkResponses?: boolean; + verifyNetworkResponses?: VerificationOptions | boolean; }; @scoped(Lifecycle.ContainerScoped) @@ -248,7 +251,7 @@ export class Queries implements IResends { ...query, // we will get raw request to desserialize and decrypt format: 'raw', - verifyNetworkResponses: options?.verifyNetworkResponses, + verifyNetworkResponses: !!options?.verifyNetworkResponses, }); const messageStream = createSubscribePipeline({ streamPartId, @@ -303,6 +306,10 @@ export class Queries implements IResends { nodeManager: this.nodeManager, logger: this.logger, queryUrl: nodeUrl, + verificationOptions: + typeof options.verifyNetworkResponses === 'object' + ? options.verifyNetworkResponses + : undefined, }); } diff --git a/packages/client/src/utils/networkValidation/validateNetworkResponses.ts b/packages/client/src/utils/networkValidation/validateNetworkResponses.ts index 429aa13c..5cc3bddf 100644 --- a/packages/client/src/utils/networkValidation/validateNetworkResponses.ts +++ b/packages/client/src/utils/networkValidation/validateNetworkResponses.ts @@ -1,17 +1,44 @@ import { Logger } from '@streamr/utils'; -import { catchError, combineLatest, concat, defer, delay, first, firstValueFrom, map, merge, of, race, share, startWith, switchMap, throwError, timer, toArray } from 'rxjs'; - - +import { + catchError, + combineLatest, + concat, + defer, + delay, + first, + firstValueFrom, + map, + merge, + of, + race, + share, + startWith, + switchMap, + throwError, + timer, + toArray, +} from 'rxjs'; import { LogStoreMessageStream } from '../../LogStoreMessageStream'; import { NodeManager } from '../../registry/NodeManager'; import { SystemMessageObservable } from '../SystemMessageObservable'; import { checkCollectionCompletion } from './checkCollectionCompletion'; -import { convertToStorageMatrix, nodesAgreeOnStorageMatrix, verifyMessagePresenceInStorageMatrix } from './manageStorageMatrix'; +import { + convertToStorageMatrix, + nodesAgreeOnStorageMatrix, + verifyMessagePresenceInStorageMatrix, +} from './manageStorageMatrix'; import { retrieveFilteredSystemMessages } from './retrieveFilteredSystemMessages'; import { QueryInputPayload } from './types'; -import { lowercaseRequestidFromLogstoreMetadata, nodeAddressFromUrl, rethrowErrorWithSourceActionName } from './utils'; - +import { + lowercaseRequestidFromLogstoreMetadata, + nodeAddressFromUrl, + rethrowErrorWithSourceActionName, +} from './utils'; + +export type VerificationOptions = { + timeout?: number; +}; /** * This function orchestrates the process of validating network responses against expected results. @@ -33,6 +60,7 @@ export const validateWithNetworkResponses = ({ nodeManager, systemMessages$, responseStream, + verificationOptions, }: { queryInput: QueryInputPayload; logger: Logger; @@ -40,7 +68,10 @@ export const validateWithNetworkResponses = ({ nodeManager: NodeManager; responseStream: LogStoreMessageStream; systemMessages$: SystemMessageObservable; + verificationOptions?: VerificationOptions; }) => { + const DEFAULT_TIMEOUT = 15_000; + // TODO might be good to have a good callback for when the system stream is really ready. For now, we're hardcoding it as // 500ms after start, which is not ideal. const systemStreamSubscriptionIsReady$ = merge(systemMessages$, of(1)).pipe( @@ -153,8 +184,7 @@ export const validateWithNetworkResponses = ({ propagates: propagates$, request: request$, responses: responses$, - // timeout: 5 seconds - timer: timer(5000), + timer: timer(verificationOptions?.timeout ?? DEFAULT_TIMEOUT), }).pipe( map(({ timer: _timer, ..._rest }) => { // this maybe useful for debugging, however it is too verbose for production (?) From a7fea493ec8a8f3e605fea7e7bf340f10d8adc07 Mon Sep 17 00:00:00 2001 From: Raffael Campos Date: Thu, 16 Nov 2023 08:51:33 -0300 Subject: [PATCH 2/9] Update client package version to 0.0.7 --- packages/client/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/client/package.json b/packages/client/package.json index d453b751..444cef9f 100644 --- a/packages/client/package.json +++ b/packages/client/package.json @@ -1,6 +1,6 @@ { "name": "@logsn/client", - "version": "0.0.6", + "version": "0.0.7", "description": "The Log Store Network Client", "author": "Ryan Soury , Victor Shevtsov ", "license": "Apache-2.0", From 31d5a7956b982159e50d0ffa796d5097d8c1a6ec Mon Sep 17 00:00:00 2001 From: Raffael Campos Date: Thu, 16 Nov 2023 11:46:00 -0300 Subject: [PATCH 3/9] Add dynamic gas pricing feature A gas pricing mechanism has been implemented for transaction fees. This new feature fetches gas prices from GasStation and uses the fast priority fee for the transactions - minting, staking, and querying. In addition, the gas price increase factor for speedup transactions has been decreased from 3x to 1.2x. --- packages/cli/src/commands/mint.ts | 6 ++- .../cli/src/commands/query/query-stake.ts | 5 ++- .../cli/src/commands/store/store-stake.ts | 6 ++- packages/cli/src/utils/gasStation.ts | 38 +++++++++++++++++++ packages/cli/src/utils/speedupTx.ts | 2 +- 5 files changed, 53 insertions(+), 4 deletions(-) create mode 100644 packages/cli/src/utils/gasStation.ts diff --git a/packages/cli/src/commands/mint.ts b/packages/cli/src/commands/mint.ts index ac30bb4f..1687b453 100644 --- a/packages/cli/src/commands/mint.ts +++ b/packages/cli/src/commands/mint.ts @@ -1,4 +1,5 @@ import { getRootOptions } from '@/commands/options'; +import { fastPriorityFee$ } from '@/utils/gasStation'; import { getCredentialsFromOptions, getLogStoreClientFromOptions, @@ -60,7 +61,10 @@ export const mintCommand = new Command() console.log(`Minting ${amountInToken} wei...`); const result = await client.mint( - BigInt(new Decimal(amountInToken).toHex()) + BigInt(new Decimal(amountInToken).toHex()), + { + maxPriorityFeePerGas: await firstValueFrom(fastPriorityFee$), + } ); console.log( diff --git a/packages/cli/src/commands/query/query-stake.ts b/packages/cli/src/commands/query/query-stake.ts index c80fca82..897a4807 100644 --- a/packages/cli/src/commands/query/query-stake.ts +++ b/packages/cli/src/commands/query/query-stake.ts @@ -1,4 +1,5 @@ import { getRootOptions } from '@/commands/options'; +import { fastPriorityFee$ } from '@/utils/gasStation'; import { getCredentialsFromOptions, getLogStoreClientFromOptions, @@ -85,7 +86,9 @@ const stakeCommand = new Command() const queryManagerContract = await getQueryManagerContract(signer); console.info(`Staking ${amountToStakeInLSAN} LSAN...`); - const tx = await queryManagerContract.stake(hexValue); + const tx = await queryManagerContract.stake(hexValue, { + maxPriorityFeePerGas: await firstValueFrom(fastPriorityFee$), + }); const receipt = await firstValueFrom( keepRetryingWithIncreasedGasPrice(signer, tx) diff --git a/packages/cli/src/commands/store/store-stake.ts b/packages/cli/src/commands/store/store-stake.ts index 8d9ff964..1de4675f 100644 --- a/packages/cli/src/commands/store/store-stake.ts +++ b/packages/cli/src/commands/store/store-stake.ts @@ -1,3 +1,4 @@ +import { fastPriorityFee$ } from '@/utils/gasStation'; import { getCredentialsFromOptions, getLogStoreClientFromOptions, @@ -65,7 +66,10 @@ const stakeCommand = new Command() Manager.StoreManager, BigInt(hexValue), signer, - !cmdOptions.assumeYes ? allowanceConfirm : undefined + !cmdOptions.assumeYes ? allowanceConfirm : undefined, + { + maxPriorityFeePerGas: await firstValueFrom(fastPriorityFee$), + } ); if (allowanceTx) { diff --git a/packages/cli/src/utils/gasStation.ts b/packages/cli/src/utils/gasStation.ts new file mode 100644 index 00000000..960bd7d4 --- /dev/null +++ b/packages/cli/src/utils/gasStation.ts @@ -0,0 +1,38 @@ +import { ethers } from 'ethers'; +import { catchError, defer, map, share, throwError } from 'rxjs'; + +type GasStationResponse = { + safeLow: { + maxPriorityFee: number; + maxFee: number; + }; + standard: { + maxPriorityFee: number; + maxFee: number; + }; + fast: { + maxPriorityFee: number; + maxFee: number; + }; + estimatedBaseFee: number; + blockTime: number; + blockNumber: number; +}; +const gasStationFees$ = defer(() => + fetch('https://gasstation.polygon.technology/v2').then( + (response) => response.json() as Promise + ) +).pipe( + catchError((err) => { + console.log('error fetching gas station fees: ', err); + return throwError(() => err); + }) +); +const mapGweiToBN = (gwei: number) => + ethers.utils.parseUnits(gwei.toString(), 'gwei'); + +export const fastPriorityFee$ = gasStationFees$.pipe( + map((gasStationResponse) => gasStationResponse.fast.maxPriorityFee), + map(mapGweiToBN), + share() +); diff --git a/packages/cli/src/utils/speedupTx.ts b/packages/cli/src/utils/speedupTx.ts index 6137d124..671f89cd 100644 --- a/packages/cli/src/utils/speedupTx.ts +++ b/packages/cli/src/utils/speedupTx.ts @@ -88,7 +88,7 @@ export const keepRetryingWithIncreasedGasPrice = ( const newTransaction = await createTransactionWithIncreasedTip( signer, oldTransaction, - 3 // 3x + 1.2 ); console.log(''); console.log('Replacing transaction with increased gas price'); From 999c04d1eb637a28b08b265b5bb925f35575b91b Mon Sep 17 00:00:00 2001 From: Raffael Campos Date: Thu, 16 Nov 2023 11:46:38 -0300 Subject: [PATCH 4/9] Add Overrides option to contract methods The commit introduces the Overrides option to several contract-related methods. These changes allow additional ethereal execution options to be passed in the QueryManager, TokenManager, LogStoreRegistry and LogStoreClient classes, providing enhanced flexibility during the execution of staking or minting transactions. --- packages/client/src/LogStoreClient.ts | 29 +++++++++++++++---- .../client/src/registry/LogStoreRegistry.ts | 13 +++++---- packages/client/src/registry/QueryManager.ts | 10 +++++-- packages/client/src/registry/TokenManager.ts | 11 +++++-- 4 files changed, 46 insertions(+), 17 deletions(-) diff --git a/packages/client/src/LogStoreClient.ts b/packages/client/src/LogStoreClient.ts index 3549e295..718092ea 100644 --- a/packages/client/src/LogStoreClient.ts +++ b/packages/client/src/LogStoreClient.ts @@ -1,3 +1,4 @@ +import type { Overrides } from '@ethersproject/contracts'; import type { MessageListener, Stream, @@ -115,8 +116,16 @@ export class LogStoreClient extends StreamrClient { /** * Stake funds so can query */ - async queryStake(amount: bigint, options = { usd: false }) { - return this.logStoreQueryManager.queryStake(amount, { usd: options.usd }); + async queryStake( + amount: bigint, + options = { usd: false }, + overrides?: Overrides + ) { + return this.logStoreQueryManager.queryStake( + amount, + { usd: options.usd }, + overrides + ); } /** @@ -187,9 +196,14 @@ export class LogStoreClient extends StreamrClient { */ async stakeOrCreateStore( streamIdOrPath: string, - amount: bigint + amount: bigint, + overrides?: Overrides ): Promise { - return this.logStoreRegistry.stakeOrCreateStore(streamIdOrPath, amount); + return this.logStoreRegistry.stakeOrCreateStore( + streamIdOrPath, + amount, + overrides + ); } /** @@ -227,8 +241,11 @@ export class LogStoreClient extends StreamrClient { return this.logstoreTokenManager.getBalance(); } - async mint(weiAmountToMint: bigint): Promise { - return this.logstoreTokenManager.mint(weiAmountToMint); + async mint( + weiAmountToMint: bigint, + overrides?: Overrides + ): Promise { + return this.logstoreTokenManager.mint(weiAmountToMint, overrides); } async getPrice(): Promise { diff --git a/packages/client/src/registry/LogStoreRegistry.ts b/packages/client/src/registry/LogStoreRegistry.ts index c03ba9b3..3c3286fc 100644 --- a/packages/client/src/registry/LogStoreRegistry.ts +++ b/packages/client/src/registry/LogStoreRegistry.ts @@ -1,4 +1,5 @@ import { BigNumber } from '@ethersproject/bignumber'; +import type { Overrides } from '@ethersproject/contracts'; import { Provider } from '@ethersproject/providers'; import type { LogStoreManager as LogStoreManagerContract } from '@logsn/contracts'; import { abi as LogStoreManagerAbi } from '@logsn/contracts/artifacts/src/StoreManager.sol/LogStoreManager.json'; @@ -173,7 +174,8 @@ export class LogStoreRegistry { async stakeOrCreateStore( streamIdOrPath: string, - amount: bigint + amount: bigint, + overrides?: Overrides ): Promise { const streamId = await this.streamIdBuilder.toStreamID(streamIdOrPath); this.logger.debug('adding stream %s to LogStore', streamId); @@ -185,11 +187,10 @@ export class LogStoreRegistry { await this.authentication.getStreamRegistryChainSigner(); await prepareStakeForStoreManager(chainSigner, amount, false); const ethersOverrides = getStreamRegistryOverrides(this.clientConfig); - return this.logStoreManagerContract!.stake( - streamId, - amount, - ethersOverrides - ); + return this.logStoreManagerContract!.stake(streamId, amount, { + ...ethersOverrides, + ...overrides, + }); } async getStreamBalance(streamIdOrPath: string): Promise { diff --git a/packages/client/src/registry/QueryManager.ts b/packages/client/src/registry/QueryManager.ts index e496741b..a8ecda0f 100644 --- a/packages/client/src/registry/QueryManager.ts +++ b/packages/client/src/registry/QueryManager.ts @@ -1,5 +1,5 @@ import { BigNumberish } from '@ethersproject/bignumber'; -import { ContractReceipt } from '@ethersproject/contracts'; +import { ContractReceipt, type Overrides } from '@ethersproject/contracts'; import { Provider } from '@ethersproject/providers'; import { LogStoreQueryManager as QueryManagerContract } from '@logsn/contracts'; import { abi as QueryManagerAbi } from '@logsn/contracts/artifacts/src/QueryManager.sol/LogStoreQueryManager.json'; @@ -99,7 +99,8 @@ export class QueryManager { async queryStake( amount: BigNumberish, - options = { usd: false } + options = { usd: false }, + overrides?: Overrides ): Promise { this.logger.debug( `Staking ${amount} with options: ${JSON.stringify(options)}...` @@ -118,7 +119,10 @@ export class QueryManager { const ethersOverrides = getStreamRegistryOverrides(this.clientConfig); return waitForTx( - this.queryManagerContract!.stake(stakeAmount, ethersOverrides) + this.queryManagerContract!.stake(stakeAmount, { + ...ethersOverrides, + ...overrides, + }) ); } } diff --git a/packages/client/src/registry/TokenManager.ts b/packages/client/src/registry/TokenManager.ts index d055d91a..26d0e58a 100644 --- a/packages/client/src/registry/TokenManager.ts +++ b/packages/client/src/registry/TokenManager.ts @@ -1,4 +1,5 @@ import { BigNumberish } from '@ethersproject/bignumber'; +import type { Overrides } from '@ethersproject/contracts'; import { Provider } from '@ethersproject/providers'; import { LSAN as LogStoreTokenManagerContract } from '@logsn/contracts'; import { abi as LogStoreTokenManagerAbi } from '@logsn/contracts/artifacts/src/alpha/Token.sol/LSAN.json'; @@ -100,10 +101,16 @@ export class TokenManager { }, this.logstoreTokenManagerContractsReadonly); } - public async mint(amount: BigNumberish): Promise { + public async mint( + amount: BigNumberish, + overrides?: Overrides + ): Promise { this.logger.debug('mint amount: ' + amount); await this.connectToContract(); - return this.logStoreTokenManagerContract!.mint({ value: amount }); + return this.logStoreTokenManagerContract!.mint({ + value: amount, + ...overrides, + }); } /** From 674b91dce54c6e0fd44cef6a082bd99ed6b082a1 Mon Sep 17 00:00:00 2001 From: Raffael Campos Date: Thu, 16 Nov 2023 11:46:48 -0300 Subject: [PATCH 5/9] Add Overrides to stake token approval function The commit adds an optional Overrides parameter to the stake token approval function in allowance.ts. This modification allows for the provision of custom transaction parameters when approving the stake token. The import statement has also been updated to include the Overrides type from 'ethers'. --- packages/shared/src/allowance.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/shared/src/allowance.ts b/packages/shared/src/allowance.ts index 7d57f2e7..1d84e634 100644 --- a/packages/shared/src/allowance.ts +++ b/packages/shared/src/allowance.ts @@ -1,5 +1,5 @@ import { LSAN__factory } from '@logsn/contracts'; -import { type ContractTransaction, Signer } from 'ethers'; +import { type ContractTransaction, type Overrides, Signer } from 'ethers'; import { getManagerContract } from './getManager'; import { Manager } from './types'; @@ -42,7 +42,8 @@ export const requestAllowanceIfNeeded = async ( manager: Exclude, amount: bigint, signer: Signer, - confirm?: allowanceConfirmFn + confirm?: allowanceConfirmFn, + overrides?: Overrides ): Promise => { const mangerContract = await getManagerContract(signer, manager); // @ts-expect-error -- manager excludes ReportManager @@ -62,7 +63,7 @@ export const requestAllowanceIfNeeded = async ( !confirm || (await confirm(currentAllowance, requiredAllowance)); if (confirmed) { - return stakeToken.approve(mangerContract.address, amount); + return stakeToken.approve(mangerContract.address, amount, overrides); } else { throw new Error('User didn’t confirm allowance'); } From d0aab151e2686ac7d98193cf93430d53d39e685a Mon Sep 17 00:00:00 2001 From: Raffael Campos Date: Thu, 16 Nov 2023 12:01:21 -0300 Subject: [PATCH 6/9] Update package versions in cli, shared, and client --- packages/cli/package.json | 2 +- packages/client/package.json | 2 +- packages/shared/package.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/cli/package.json b/packages/cli/package.json index 7c253c8c..357a8e96 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -1,6 +1,6 @@ { "name": "@logsn/cli", - "version": "0.0.4", + "version": "0.0.5", "author": "Ryan Soury ", "license": "GPL-3.0", "description": "The Log Store Network CLI", diff --git a/packages/client/package.json b/packages/client/package.json index 444cef9f..5fe5779c 100644 --- a/packages/client/package.json +++ b/packages/client/package.json @@ -1,6 +1,6 @@ { "name": "@logsn/client", - "version": "0.0.7", + "version": "0.0.8", "description": "The Log Store Network Client", "author": "Ryan Soury , Victor Shevtsov ", "license": "Apache-2.0", diff --git a/packages/shared/package.json b/packages/shared/package.json index 2c3355db..97359e4d 100644 --- a/packages/shared/package.json +++ b/packages/shared/package.json @@ -1,6 +1,6 @@ { "name": "@logsn/shared", - "version": "0.0.2", + "version": "0.0.3", "description": "The Log Store Network Shared Library", "repository": { "type": "git", From 967944b5f909e67bc20118bef5b255d10d84b63b Mon Sep 17 00:00:00 2001 From: Raffael Campos Date: Thu, 16 Nov 2023 14:23:28 -0300 Subject: [PATCH 7/9] Implement handling of priority fee for dev and main networks The code changes reflect the implementation of adjusted handling of "maxPriorityFeePerGas". Importantly, variable "fastPriorityFee$" has been replaced with "fastPriorityIfMainNet$", which considers if the system runs on a development network. Consequently, a new utility file "observableUtils.ts" has been introduced, and the prerequisite changes have been made across multiple files, resulting in the removal of --gas-tip option in the commands index file. --- packages/cli/src/commands/index.ts | 1 - packages/cli/src/commands/mint.ts | 9 ++++----- packages/cli/src/commands/query/query-stake.ts | 9 ++++++--- packages/cli/src/commands/store/store-stake.ts | 4 ++-- packages/cli/src/utils/gasStation.ts | 9 +++++++-- packages/cli/src/utils/observableUtils.ts | 11 +++++++++++ 6 files changed, 30 insertions(+), 13 deletions(-) create mode 100644 packages/cli/src/utils/observableUtils.ts diff --git a/packages/cli/src/commands/index.ts b/packages/cli/src/commands/index.ts index e57a944f..1e1ed28e 100644 --- a/packages/cli/src/commands/index.ts +++ b/packages/cli/src/commands/index.ts @@ -21,7 +21,6 @@ export const rootProgram = new Command() .version(appVersion) .option('-h, --host ', 'Polygon/EVM Node RPC Endpoint') .option('-w, --wallet ', 'Wallet private key') - .option('--gas-tip ', 'Initial gas tip to use for transactions') .option( '-c, --config ', 'Path to configuration file. Defaults to ~/.logstore-cli/default.json', diff --git a/packages/cli/src/commands/mint.ts b/packages/cli/src/commands/mint.ts index 1687b453..c4d77824 100644 --- a/packages/cli/src/commands/mint.ts +++ b/packages/cli/src/commands/mint.ts @@ -1,5 +1,4 @@ import { getRootOptions } from '@/commands/options'; -import { fastPriorityFee$ } from '@/utils/gasStation'; import { getCredentialsFromOptions, getLogStoreClientFromOptions, @@ -61,10 +60,10 @@ export const mintCommand = new Command() console.log(`Minting ${amountInToken} wei...`); const result = await client.mint( - BigInt(new Decimal(amountInToken).toHex()), - { - maxPriorityFeePerGas: await firstValueFrom(fastPriorityFee$), - } + BigInt(new Decimal(amountInToken).toHex()) + // { + // maxPriorityFeePerGas: await firstValueFrom(fastPriorityIfMainNet$), + // } ); console.log( diff --git a/packages/cli/src/commands/query/query-stake.ts b/packages/cli/src/commands/query/query-stake.ts index 897a4807..e521d2e8 100644 --- a/packages/cli/src/commands/query/query-stake.ts +++ b/packages/cli/src/commands/query/query-stake.ts @@ -1,5 +1,5 @@ import { getRootOptions } from '@/commands/options'; -import { fastPriorityFee$ } from '@/utils/gasStation'; +import { fastPriorityIfMainNet$ } from '@/utils/gasStation'; import { getCredentialsFromOptions, getLogStoreClientFromOptions, @@ -67,7 +67,10 @@ const stakeCommand = new Command() Manager.QueryManager, BigInt(hexValue), signer, - !cmdOptions.assumeYes ? allowanceConfirm : undefined + !cmdOptions.assumeYes ? allowanceConfirm : undefined, + { + maxPriorityFeePerGas: await firstValueFrom(fastPriorityIfMainNet$), + } ); if (allowanceTx) { @@ -87,7 +90,7 @@ const stakeCommand = new Command() console.info(`Staking ${amountToStakeInLSAN} LSAN...`); const tx = await queryManagerContract.stake(hexValue, { - maxPriorityFeePerGas: await firstValueFrom(fastPriorityFee$), + maxPriorityFeePerGas: await firstValueFrom(fastPriorityIfMainNet$), }); const receipt = await firstValueFrom( diff --git a/packages/cli/src/commands/store/store-stake.ts b/packages/cli/src/commands/store/store-stake.ts index 1de4675f..553c8dae 100644 --- a/packages/cli/src/commands/store/store-stake.ts +++ b/packages/cli/src/commands/store/store-stake.ts @@ -1,4 +1,4 @@ -import { fastPriorityFee$ } from '@/utils/gasStation'; +import { fastPriorityIfMainNet$ } from '@/utils/gasStation'; import { getCredentialsFromOptions, getLogStoreClientFromOptions, @@ -68,7 +68,7 @@ const stakeCommand = new Command() signer, !cmdOptions.assumeYes ? allowanceConfirm : undefined, { - maxPriorityFeePerGas: await firstValueFrom(fastPriorityFee$), + maxPriorityFeePerGas: await firstValueFrom(fastPriorityIfMainNet$), } ); diff --git a/packages/cli/src/utils/gasStation.ts b/packages/cli/src/utils/gasStation.ts index 960bd7d4..7793f819 100644 --- a/packages/cli/src/utils/gasStation.ts +++ b/packages/cli/src/utils/gasStation.ts @@ -1,5 +1,6 @@ +import { isDevNetwork$ } from '@/utils/observableUtils'; import { ethers } from 'ethers'; -import { catchError, defer, map, share, throwError } from 'rxjs'; +import { catchError, defer, map, of, share, switchMap, throwError } from 'rxjs'; type GasStationResponse = { safeLow: { @@ -31,8 +32,12 @@ const gasStationFees$ = defer(() => const mapGweiToBN = (gwei: number) => ethers.utils.parseUnits(gwei.toString(), 'gwei'); -export const fastPriorityFee$ = gasStationFees$.pipe( +const fastPriorityFee$ = gasStationFees$.pipe( map((gasStationResponse) => gasStationResponse.fast.maxPriorityFee), map(mapGweiToBN), share() ); + +export const fastPriorityIfMainNet$ = isDevNetwork$.pipe( + switchMap((isDevNet) => (isDevNet ? of(undefined) : fastPriorityFee$)) +); diff --git a/packages/cli/src/utils/observableUtils.ts b/packages/cli/src/utils/observableUtils.ts new file mode 100644 index 00000000..1a851528 --- /dev/null +++ b/packages/cli/src/utils/observableUtils.ts @@ -0,0 +1,11 @@ +import { getRootOptions } from '@/commands/options'; +import { getCredentialsFromOptions } from '@/utils/logstore-client'; +import { defer, map } from 'rxjs'; + +export const rootOptions$ = defer(async () => getRootOptions()); +export const credentials$ = defer(async () => getCredentialsFromOptions()); + +export const isDevNetwork$ = credentials$.pipe( + // enough to validate? + map(({ provider }) => provider.connection.url.includes('localhost')) +); From cc1b377ea0455d6fc72734d6e4e5c5cf85d46f8d Mon Sep 17 00:00:00 2001 From: Raffael Campos Date: Thu, 16 Nov 2023 14:29:41 -0300 Subject: [PATCH 8/9] Update stakeToken approval function This commit enhances the stakeToken's approve function. Specifically, it now accepts an additional parameter of 'overrides'. Previously, the function directly used the 'overrides' parameter, but it will now spread the 'overrides' object instead. This change provides more flexibility when additional parameters are required. --- packages/shared/src/allowance.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/shared/src/allowance.ts b/packages/shared/src/allowance.ts index 1d84e634..efca2d1d 100644 --- a/packages/shared/src/allowance.ts +++ b/packages/shared/src/allowance.ts @@ -63,7 +63,9 @@ export const requestAllowanceIfNeeded = async ( !confirm || (await confirm(currentAllowance, requiredAllowance)); if (confirmed) { - return stakeToken.approve(mangerContract.address, amount, overrides); + return stakeToken.approve(mangerContract.address, amount, { + ...overrides, + }); } else { throw new Error('User didn’t confirm allowance'); } From 0d7173d8577981be93c14c9a8e3377a3f6414797 Mon Sep 17 00:00:00 2001 From: Raffael Campos Date: Thu, 16 Nov 2023 14:35:18 -0300 Subject: [PATCH 9/9] re-enable fee override on mint --- packages/cli/src/commands/mint.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/cli/src/commands/mint.ts b/packages/cli/src/commands/mint.ts index c4d77824..078ac341 100644 --- a/packages/cli/src/commands/mint.ts +++ b/packages/cli/src/commands/mint.ts @@ -1,4 +1,5 @@ import { getRootOptions } from '@/commands/options'; +import { fastPriorityIfMainNet$ } from '@/utils/gasStation'; import { getCredentialsFromOptions, getLogStoreClientFromOptions, @@ -60,10 +61,10 @@ export const mintCommand = new Command() console.log(`Minting ${amountInToken} wei...`); const result = await client.mint( - BigInt(new Decimal(amountInToken).toHex()) - // { - // maxPriorityFeePerGas: await firstValueFrom(fastPriorityIfMainNet$), - // } + BigInt(new Decimal(amountInToken).toHex()), + { + maxPriorityFeePerGas: await firstValueFrom(fastPriorityIfMainNet$), + } ); console.log(