Skip to content
This repository has been archived by the owner on Aug 30, 2024. It is now read-only.

Commit

Permalink
[Temp] Use HIGH gas specifier instead of custom gas
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeychr committed Dec 27, 2023
1 parent 4ac97ea commit faabe49
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 69 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@debridge-finance/dln-taker",
"version": "3.1.0-beta.7",
"version": "3.1.0-beta.10",
"description": "DLN executor is the rule-based daemon service developed to automatically execute orders placed on the deSwap Liquidity Network (DLN) across supported blockchains",
"license": "GPL-3.0-only",
"author": "deBridge",
Expand Down
132 changes: 66 additions & 66 deletions src/chain-evm/fordefi-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { ChainId, OrderDataWithId } from '@debridge-finance/dln-client';
import { helpers } from '@debridge-finance/solana-utils';
import { Logger, LoggerOptions } from 'pino';
import Web3 from 'web3';
import { EvmFeeManager } from './feeManager';
import { EVM_GAS_LIMIT_MULTIPLIER, InputTransaction } from './signer';
import { ForDefiTransactionBuilderAdapter } from '../authority-forDefi/tx-builder';
import { createBatchOrderUnlockTx } from './tx-generators/createBatchOrderUnlockTx';
Expand Down Expand Up @@ -34,8 +33,6 @@ function encodeNote<T extends ForDefiTransactionAction>(
export class EvmForDefiTransactionAdapter implements ForDefiTransactionBuilderAdapter {
readonly #chainId: ChainId;

readonly #feeManager: EvmFeeManager;

readonly #vaultId: string;

readonly #vaultAddress: Uint8Array;
Expand All @@ -59,7 +56,6 @@ export class EvmForDefiTransactionAdapter implements ForDefiTransactionBuilderAd
this.#executor = executor;
this.#connection = connection;
this.#contractsForApprove = contractsForApprove;
this.#feeManager = new EvmFeeManager(chain, connection);
}

public get address(): string {
Expand Down Expand Up @@ -135,7 +131,11 @@ export class EvmForDefiTransactionAdapter implements ForDefiTransactionBuilderAd
type: 'evm_raw_transaction',
use_secure_node: false,
chain: convertChainIdToChain(this.#chainId as any as SupportedChain),
gas: await this.safeGetCustomGasPricing(tx, gasLimit),
gas: {
type: 'priority',
priority_level: 'high',
gas_limit: (gasLimit * 1.3).toString(),
},
to: tx.to,
value: tx.value?.toString() || '0',
data: {
Expand All @@ -149,65 +149,65 @@ export class EvmForDefiTransactionAdapter implements ForDefiTransactionBuilderAd
return request;
}

private async safeGetCustomGasPricing(
tx: InputTransaction,
gasLimit: number,
): Promise<CreateEvmRawTransactionRequest['details']['gas']> {
if (tx.cappedFee && tx.cappedFee > 0)
return this.#feeManager.isLegacy
? this.safeGetCustomLegacyGas(tx.cappedFee, gasLimit)
: this.safeGetCustomGas(tx.cappedFee, gasLimit);
return {
type: 'priority',
priority_level: 'high',
gas_limit: gasLimit.toString(),
};
}

private async safeGetCustomLegacyGas(
cappedFee: bigint,
gasLimit: number,
): Promise<CreateEvmRawTransactionRequest['details']['gas']> {
const gasPrice = await this.#feeManager.getOptimisticLegacyFee();
if (cappedFee > 0n) {
const actualFee = BigInt(gasLimit) * gasPrice;
if (cappedFee < actualFee)
throw new Error(
`can't populate pricing: actualFee (${actualFee}) > cappedFee (${cappedFee})`,
);
}

return {
gas_limit: gasLimit.toString(),
type: 'custom',
details: {
type: 'legacy',
price: gasPrice.toString(),
},
};
}

private async safeGetCustomGas(
cappedFee: bigint,
gasLimit: number,
): Promise<CreateEvmRawTransactionRequest['details']['gas']> {
const fee = await this.#feeManager.getOptimisticFee();
if (cappedFee > 0n) {
const actualFee = BigInt(gasLimit) * fee.maxFeePerGas;
if (cappedFee < actualFee)
throw new Error(
`can't populate pricing: actualFee (${actualFee}) > cappedFee (${cappedFee})`,
);
}

return {
gas_limit: gasLimit.toString(),
type: 'custom',
details: {
type: 'dynamic',
max_fee_per_gas: fee.maxFeePerGas.toString(),
max_priority_fee_per_gas: fee.maxPriorityFeePerGas.toString(),
},
};
}
// private async safeGetCustomGasPricing(
// tx: InputTransaction,
// gasLimit: number,
// ): Promise<CreateEvmRawTransactionRequest['details']['gas']> {
// if (tx.cappedFee && tx.cappedFee > 0)
// return this.#feeManager.isLegacy
// ? this.safeGetCustomLegacyGas(tx.cappedFee, gasLimit)
// : this.safeGetCustomGas(tx.cappedFee, gasLimit);
// return {
// type: 'priority',
// priority_level: 'high',
// gas_limit: gasLimit.toString(),
// };
// }
//
// private async safeGetCustomLegacyGas(
// cappedFee: bigint,
// gasLimit: number,
// ): Promise<CreateEvmRawTransactionRequest['details']['gas']> {
// const gasPrice = await this.#feeManager.getOptimisticLegacyFee();
// if (cappedFee > 0n) {
// const actualFee = BigInt(gasLimit) * gasPrice;
// if (cappedFee < actualFee)
// throw new Error(
// `can't populate pricing: actualFee (${actualFee}) > cappedFee (${cappedFee})`,
// );
// }

// return {
// gas_limit: gasLimit.toString(),
// type: 'custom',
// details: {
// type: 'legacy',
// price: gasPrice.toString(),
// },
// };
// }

// private async safeGetCustomGas(
// cappedFee: bigint,
// gasLimit: number,
// ): Promise<CreateEvmRawTransactionRequest['details']['gas']> {
// const fee = await this.#feeManager.getOptimisticFee();
// if (cappedFee > 0n) {
// const actualFee = BigInt(gasLimit) * fee.maxFeePerGas;
// if (cappedFee < actualFee)
// throw new Error(
// `can't populate pricing: actualFee (${actualFee}) > cappedFee (${cappedFee})`,
// );
// }

// return {
// gas_limit: gasLimit.toString(),
// type: 'custom',
// details: {
// type: 'dynamic',
// max_fee_per_gas: fee.maxFeePerGas.toString(),
// max_priority_fee_per_gas: fee.maxPriorityFeePerGas.toString(),
// },
// };
// }
}

0 comments on commit faabe49

Please sign in to comment.