From c95249ca4cb3ecbd7208c73537c4934141a024c0 Mon Sep 17 00:00:00 2001 From: nikdementev Date: Wed, 1 Dec 2021 17:49:33 +0300 Subject: [PATCH] fix: relayer fee --- src/constants/contracts.ts | 5 +---- src/modules/queue/transaction.processor.ts | 6 ++---- src/utilities/crypto.ts | 12 +++--------- 3 files changed, 6 insertions(+), 17 deletions(-) diff --git a/src/constants/contracts.ts b/src/constants/contracts.ts index 64fcbc1..05e6a19 100644 --- a/src/constants/contracts.ts +++ b/src/constants/contracts.ts @@ -1,10 +1,7 @@ import { ChainId } from '@/types'; export const CONTRACT_NETWORKS: { [chainId in ChainId]: string } = { - // [ChainId.MAINNET]: '0x8Bfac9EF3d73cE08C7CEC339C0fE3B2e57814c1E', - [ChainId.GOERLI]: '0xE2D9aF526edeB16a02FBC3B68B0eB9B534f9c114', - [ChainId.OPTIMISM]: '0xcd7318c299A82E887f5180EF865a4c350dFC9fe5', - // [ChainId.XDAI]: '0xdd85b1dbE3379AFA37F703822f9E328d4bAf8625', // BNB + // [ChainId.XDAI]: '0xE6DdD048304053Bf6ba258D47937289574971057', // BNB [ChainId.XDAI]: '0x9719570C85c93a74c72B5B2c08AA133fcBc35377', // ETH }; diff --git a/src/modules/queue/transaction.processor.ts b/src/modules/queue/transaction.processor.ts index 73b9f28..1b1efce 100644 --- a/src/modules/queue/transaction.processor.ts +++ b/src/modules/queue/transaction.processor.ts @@ -122,11 +122,9 @@ export class TransactionProcessor extends BaseProcessor { // for withdrawals the amount is negative if (amount.isNegative()) { - const integerMultiplier = getToIntegerMultiplier(serviceFee.withdrawal); + const oneEther = getToIntegerMultiplier(); - return BigNumber.from(amount) - .mul(serviceFee.withdrawal * integerMultiplier) - .div(numbers.ONE_HUNDRED * integerMultiplier); + return amount.mul(toWei(serviceFee.withdrawal)).div(oneEther); } return serviceFee.transfer; diff --git a/src/utilities/crypto.ts b/src/utilities/crypto.ts index ecc3a8c..a850512 100644 --- a/src/utilities/crypto.ts +++ b/src/utilities/crypto.ts @@ -11,7 +11,7 @@ export function toChecksumAddress(value: string): string { } export function toWei(value: string, uintName = 'ether') { - return utils.parseUnits(value, uintName); + return utils.parseUnits(String(value), uintName); } export function hexToNumber(hex: string) { @@ -26,12 +26,6 @@ export function fromWei(balance: BigNumberish) { return utils.formatUnits(balance, numbers.ETH_DECIMALS); } -export function getToIntegerMultiplier(value: number | string): number { - const [, decimals] = String(value).split('.'); - - if (!decimals) { - return numbers.ZERO; - } - - return Math.pow(numbers.TEN, decimals.length); +export function getToIntegerMultiplier(): BigNumber { + return toWei('1', 'ether'); }