From b950bd6a307623844980a3e9622fd9c90d8c70ae Mon Sep 17 00:00:00 2001 From: Maxim Kucherov Date: Fri, 19 Aug 2022 14:08:45 +0300 Subject: [PATCH] Return estimated and max fees; Refactor --- .../atomexProtocolV1/atomexProtocolV1.ts | 8 +++---- src/blockchain/index.ts | 2 +- src/blockchain/models/feesInfo.ts | 6 +++++ src/blockchain/models/index.ts | 1 + .../erc20EthereumWeb3AtomexProtocolV1.ts | 8 +++---- .../ethereumWeb3AtomexProtocolV1.ts | 8 +++---- .../atomexProtocol/web3AtomexProtocolV1.ts | 8 +++---- .../fa12TezosTaquitoAtomexProtocolV1.ts | 14 +++++------ .../fa2TezosTaquitoAtomexProtocolV1.ts | 14 +++++------ .../atomexProtocol/taquitoAtomexProtocolV1.ts | 23 +++++++++++-------- .../tezosTaquitoAtomexProtocolV1.ts | 14 +++++------ 11 files changed, 58 insertions(+), 48 deletions(-) create mode 100644 src/blockchain/models/feesInfo.ts diff --git a/src/blockchain/atomexProtocolV1/atomexProtocolV1.ts b/src/blockchain/atomexProtocolV1/atomexProtocolV1.ts index 66c86cfa..4ae40d6b 100644 --- a/src/blockchain/atomexProtocolV1/atomexProtocolV1.ts +++ b/src/blockchain/atomexProtocolV1/atomexProtocolV1.ts @@ -2,7 +2,7 @@ import type { BigNumber } from 'bignumber.js'; import type { Currency } from '../../common/index'; import type { AtomexProtocol } from '../atomexProtocol'; -import type { Transaction } from '../models/index'; +import type { FeesInfo, Transaction } from '../models/index'; import type { AtomexProtocolV1InitiateParameters } from './initiateParameters'; import type { AtomexProtocolV1RedeemParameters } from './redeemParameters'; import type { AtomexProtocolV1RefundParameters } from './refundParameters'; @@ -12,12 +12,12 @@ export interface AtomexProtocolV1 extends AtomexProtocol { readonly currencyId: Currency['id']; initiate(params: AtomexProtocolV1InitiateParameters): Promise; - getEstimatedInitiateFees(params: Partial): Promise; + getInitiateFees(params: Partial): Promise; redeem(params: AtomexProtocolV1RedeemParameters): Promise; - getEstimatedRedeemFees(params: Partial): Promise; + getRedeemFees(params: Partial): Promise; getRedeemReward(nativeTokenPriceInUsd: number, nativeTokenPriceInCurrency: number): Promise; refund(params: AtomexProtocolV1RefundParameters): Promise; - getEstimatedRefundFees(params: Partial): Promise; + getRefundFees(params: Partial): Promise; } diff --git a/src/blockchain/index.ts b/src/blockchain/index.ts index 01fe8224..6a6b72c0 100644 --- a/src/blockchain/index.ts +++ b/src/blockchain/index.ts @@ -1,7 +1,7 @@ export { WalletsManager } from './walletsManager'; export { isAtomexProtocolV1 } from './atomexProtocolV1/index'; -export type { AtomexProtocolOptions, AtomexSignature, Transaction } from './models/index'; +export type { AtomexProtocolOptions, AtomexSignature, Transaction, FeesInfo } from './models/index'; export type { AtomexProtocol } from './atomexProtocol'; export type { AtomexProtocolV1, AtomexProtocolV1Options, diff --git a/src/blockchain/models/feesInfo.ts b/src/blockchain/models/feesInfo.ts new file mode 100644 index 00000000..4fe96bb1 --- /dev/null +++ b/src/blockchain/models/feesInfo.ts @@ -0,0 +1,6 @@ +import type BigNumber from 'bignumber.js'; + +export interface FeesInfo { + estimated: BigNumber; + max: BigNumber; +} diff --git a/src/blockchain/models/index.ts b/src/blockchain/models/index.ts index 05fa6acc..95213d87 100644 --- a/src/blockchain/models/index.ts +++ b/src/blockchain/models/index.ts @@ -1,3 +1,4 @@ export type { AtomexProtocolOptions } from './atomexProtocolOptions'; export type { AtomexSignature } from './atomexSignature'; export type { Transaction } from './transaction'; +export type { FeesInfo } from './feesInfo'; diff --git a/src/ethereum/atomexProtocol/erc20EthereumWeb3AtomexProtocolV1.ts b/src/ethereum/atomexProtocol/erc20EthereumWeb3AtomexProtocolV1.ts index 1d3a681b..b176f625 100644 --- a/src/ethereum/atomexProtocol/erc20EthereumWeb3AtomexProtocolV1.ts +++ b/src/ethereum/atomexProtocol/erc20EthereumWeb3AtomexProtocolV1.ts @@ -3,7 +3,7 @@ import type BigNumber from 'bignumber.js'; import type { AtomexBlockchainProvider, AtomexProtocolV1InitiateParameters, AtomexProtocolV1RedeemParameters, AtomexProtocolV1RefundParameters, - Transaction, WalletsManager + FeesInfo, Transaction, WalletsManager } from '../../blockchain/index'; import type { AtomexNetwork } from '../../common/index'; import type { DeepReadonly } from '../../core/index'; @@ -28,7 +28,7 @@ export class ERC20EthereumWeb3AtomexProtocolV1 extends Web3AtomexProtocolV1 { throw new Error('Method not implemented.'); } - getEstimatedInitiateFees(_params: Partial): Promise { + getInitiateFees(_params: Partial): Promise { throw new Error('Method not implemented.'); } @@ -40,7 +40,7 @@ export class ERC20EthereumWeb3AtomexProtocolV1 extends Web3AtomexProtocolV1 { throw new Error('Method not implemented.'); } - getEstimatedRedeemFees(_params: Partial): Promise { + getRedeemFees(_params: Partial): Promise { throw new Error('Method not implemented.'); } @@ -48,7 +48,7 @@ export class ERC20EthereumWeb3AtomexProtocolV1 extends Web3AtomexProtocolV1 { throw new Error('Method not implemented.'); } - getEstimatedRefundFees(_params: Partial): Promise { + getRefundFees(_params: Partial): Promise { throw new Error('Method not implemented.'); } } diff --git a/src/ethereum/atomexProtocol/ethereumWeb3AtomexProtocolV1.ts b/src/ethereum/atomexProtocol/ethereumWeb3AtomexProtocolV1.ts index 487ed575..d55632c9 100644 --- a/src/ethereum/atomexProtocol/ethereumWeb3AtomexProtocolV1.ts +++ b/src/ethereum/atomexProtocol/ethereumWeb3AtomexProtocolV1.ts @@ -3,7 +3,7 @@ import type BigNumber from 'bignumber.js'; import type { AtomexBlockchainProvider, AtomexProtocolV1InitiateParameters, AtomexProtocolV1RedeemParameters, AtomexProtocolV1RefundParameters, - Transaction, WalletsManager + FeesInfo, Transaction, WalletsManager } from '../../blockchain/index'; import type { AtomexNetwork } from '../../common/index'; import type { DeepReadonly } from '../../core/index'; @@ -24,7 +24,7 @@ export class EthereumWeb3AtomexProtocolV1 extends Web3AtomexProtocolV1 { throw new Error('Method not implemented.'); } - async getEstimatedInitiateFees(_params: Partial): Promise { + async getInitiateFees(_params: Partial): Promise { throw new Error('Method not implemented.'); } @@ -36,7 +36,7 @@ export class EthereumWeb3AtomexProtocolV1 extends Web3AtomexProtocolV1 { throw new Error('Method not implemented.'); } - getEstimatedRedeemFees(_params: Partial): Promise { + getRedeemFees(_params: Partial): Promise { throw new Error('Method not implemented.'); } @@ -44,7 +44,7 @@ export class EthereumWeb3AtomexProtocolV1 extends Web3AtomexProtocolV1 { throw new Error('Method not implemented.'); } - getEstimatedRefundFees(_params: Partial): Promise { + getRefundFees(_params: Partial): Promise { throw new Error('Method not implemented.'); } } diff --git a/src/evm/atomexProtocol/web3AtomexProtocolV1.ts b/src/evm/atomexProtocol/web3AtomexProtocolV1.ts index 869063fa..623cbfa2 100644 --- a/src/evm/atomexProtocol/web3AtomexProtocolV1.ts +++ b/src/evm/atomexProtocol/web3AtomexProtocolV1.ts @@ -4,7 +4,7 @@ import type Web3 from 'web3'; import type { AtomexBlockchainProvider, AtomexProtocolV1, AtomexProtocolV1InitiateParameters, AtomexProtocolV1RedeemParameters, AtomexProtocolV1RefundParameters, - BlockchainWallet, Transaction, WalletsManager + BlockchainWallet, FeesInfo, Transaction, WalletsManager } from '../../blockchain/index'; import type { AtomexNetwork } from '../../common/index'; import type { DeepReadonly } from '../../core/index'; @@ -28,17 +28,17 @@ export abstract class Web3AtomexProtocolV1 implements AtomexProtocolV1 { abstract initiate(_params: AtomexProtocolV1InitiateParameters): Promise; - abstract getEstimatedInitiateFees(_params: Partial): Promise; + abstract getInitiateFees(_params: Partial): Promise; abstract redeem(_params: AtomexProtocolV1RedeemParameters): Promise; abstract getRedeemReward(_nativeTokenPriceInUsd: number, _nativeTokenPriceInCurrency: number): Promise; - abstract getEstimatedRedeemFees(_params: Partial): Promise; + abstract getRedeemFees(_params: Partial): Promise; abstract refund(_params: AtomexProtocolV1RefundParameters): Promise; - abstract getEstimatedRefundFees(_params: Partial): Promise; + abstract getRefundFees(_params: Partial): Promise; protected async getReadonlyWeb3(): Promise { const toolkit = await this.atomexBlockchainProvider.getReadonlyToolkit('web3', this.blockchain); diff --git a/src/tezos/atomexProtocol/fa12TezosTaquitoAtomexProtocolV1.ts b/src/tezos/atomexProtocol/fa12TezosTaquitoAtomexProtocolV1.ts index 6dc75cc4..db6fcdbd 100644 --- a/src/tezos/atomexProtocol/fa12TezosTaquitoAtomexProtocolV1.ts +++ b/src/tezos/atomexProtocol/fa12TezosTaquitoAtomexProtocolV1.ts @@ -3,7 +3,7 @@ import type BigNumber from 'bignumber.js'; import type { AtomexBlockchainProvider, AtomexProtocolV1InitiateParameters, AtomexProtocolV1RedeemParameters, AtomexProtocolV1RefundParameters, - Transaction, WalletsManager + FeesInfo, Transaction, WalletsManager } from '../../blockchain/index'; import type { AtomexNetwork } from '../../common/index'; import type { DeepReadonly } from '../../core/index'; @@ -28,8 +28,8 @@ export class FA12TezosTaquitoAtomexProtocolV1 extends TaquitoAtomexProtocolV1 { throw new Error('Method not implemented.'); } - getEstimatedInitiateFees(params: Partial): Promise { - return super.getEstimatedInitiateFees(params); + getInitiateFees(params: Partial): Promise { + return super.getInitiateFees(params); } redeem(_params: AtomexProtocolV1RedeemParameters): Promise { @@ -40,15 +40,15 @@ export class FA12TezosTaquitoAtomexProtocolV1 extends TaquitoAtomexProtocolV1 { throw new Error('Method not implemented.'); } - getEstimatedRedeemFees(params: Partial): Promise { - return super.getEstimatedRedeemFees(params); + getRedeemFees(params: Partial): Promise { + return super.getRedeemFees(params); } refund(_params: AtomexProtocolV1RefundParameters): Promise { throw new Error('Method not implemented.'); } - getEstimatedRefundFees(params: Partial): Promise { - return super.getEstimatedRefundFees(params); + getRefundFees(params: Partial): Promise { + return super.getRefundFees(params); } } diff --git a/src/tezos/atomexProtocol/fa2TezosTaquitoAtomexProtocolV1.ts b/src/tezos/atomexProtocol/fa2TezosTaquitoAtomexProtocolV1.ts index 9d3e9b19..694a602b 100644 --- a/src/tezos/atomexProtocol/fa2TezosTaquitoAtomexProtocolV1.ts +++ b/src/tezos/atomexProtocol/fa2TezosTaquitoAtomexProtocolV1.ts @@ -3,7 +3,7 @@ import type BigNumber from 'bignumber.js'; import type { AtomexBlockchainProvider, AtomexProtocolV1InitiateParameters, AtomexProtocolV1RedeemParameters, AtomexProtocolV1RefundParameters, - Transaction, WalletsManager + FeesInfo, Transaction, WalletsManager } from '../../blockchain/index'; import type { AtomexNetwork } from '../../common/index'; import type { DeepReadonly } from '../../core/index'; @@ -28,8 +28,8 @@ export class FA2TezosTaquitoAtomexProtocolV1 extends TaquitoAtomexProtocolV1 { throw new Error('Method not implemented.'); } - getEstimatedInitiateFees(params: Partial): Promise { - return super.getEstimatedInitiateFees(params); + getInitiateFees(params: Partial): Promise { + return super.getInitiateFees(params); } redeem(_params: AtomexProtocolV1RedeemParameters): Promise { @@ -40,15 +40,15 @@ export class FA2TezosTaquitoAtomexProtocolV1 extends TaquitoAtomexProtocolV1 { throw new Error('Method not implemented.'); } - getEstimatedRedeemFees(params: Partial): Promise { - return super.getEstimatedRedeemFees(params); + getRedeemFees(params: Partial): Promise { + return super.getRedeemFees(params); } refund(_params: AtomexProtocolV1RefundParameters): Promise { throw new Error('Method not implemented.'); } - getEstimatedRefundFees(params: Partial): Promise { - return super.getEstimatedRefundFees(params); + getRefundFees(params: Partial): Promise { + return super.getRefundFees(params); } } diff --git a/src/tezos/atomexProtocol/taquitoAtomexProtocolV1.ts b/src/tezos/atomexProtocol/taquitoAtomexProtocolV1.ts index 9090d6f3..1cf02e91 100644 --- a/src/tezos/atomexProtocol/taquitoAtomexProtocolV1.ts +++ b/src/tezos/atomexProtocol/taquitoAtomexProtocolV1.ts @@ -3,7 +3,7 @@ import BigNumber from 'bignumber.js'; import type { AtomexBlockchainProvider, - AtomexProtocolV1, AtomexProtocolV1InitiateParameters, AtomexProtocolV1RedeemParameters, AtomexProtocolV1RefundParameters, + AtomexProtocolV1, FeesInfo, AtomexProtocolV1InitiateParameters, AtomexProtocolV1RedeemParameters, AtomexProtocolV1RefundParameters, BlockchainWallet, Transaction, WalletsManager } from '../../blockchain/index'; import type { AtomexNetwork } from '../../common/index'; @@ -29,28 +29,31 @@ export abstract class TaquitoAtomexProtocolV1 implements AtomexProtocolV1 { abstract initiate(_params: AtomexProtocolV1InitiateParameters): Promise; - getEstimatedInitiateFees(_params: Partial): Promise { - const fee = new BigNumber(this.atomexProtocolOptions.initiateOperation.fee).div(mutezInTez); + getInitiateFees(_params: Partial): Promise { + const estimated = new BigNumber(this.atomexProtocolOptions.initiateOperation.fee).div(mutezInTez); + const result: FeesInfo = { estimated, max: estimated }; - return Promise.resolve(fee); + return Promise.resolve(result); } abstract redeem(_params: AtomexProtocolV1RedeemParameters): Promise; abstract getRedeemReward(_nativeTokenPriceInUsd: number, _nativeTokenPriceInCurrency: number): Promise; - getEstimatedRedeemFees(_params: Partial): Promise { - const fee = new BigNumber(this.atomexProtocolOptions.redeemOperation.fee).div(mutezInTez); + getRedeemFees(_params: Partial): Promise { + const estimated = new BigNumber(this.atomexProtocolOptions.redeemOperation.fee).div(mutezInTez); + const result: FeesInfo = { estimated, max: estimated }; - return Promise.resolve(fee); + return Promise.resolve(result); } abstract refund(_params: AtomexProtocolV1RefundParameters): Promise; - getEstimatedRefundFees(_params: Partial): Promise { - const fee = new BigNumber(this.atomexProtocolOptions.refundOperation.fee).div(mutezInTez); + getRefundFees(_params: Partial): Promise { + const estimated = new BigNumber(this.atomexProtocolOptions.refundOperation.fee).div(mutezInTez); + const result: FeesInfo = { estimated, max: estimated }; - return Promise.resolve(fee); + return Promise.resolve(result); } protected async getReadonlyTezosToolkit(): Promise { diff --git a/src/tezos/atomexProtocol/tezosTaquitoAtomexProtocolV1.ts b/src/tezos/atomexProtocol/tezosTaquitoAtomexProtocolV1.ts index ca15758e..d2d9064f 100644 --- a/src/tezos/atomexProtocol/tezosTaquitoAtomexProtocolV1.ts +++ b/src/tezos/atomexProtocol/tezosTaquitoAtomexProtocolV1.ts @@ -3,7 +3,7 @@ import type BigNumber from 'bignumber.js'; import type { AtomexBlockchainProvider, AtomexProtocolV1InitiateParameters, AtomexProtocolV1RedeemParameters, AtomexProtocolV1RefundParameters, - Transaction, WalletsManager + FeesInfo, Transaction, WalletsManager } from '../../blockchain/index'; import type { AtomexNetwork } from '../../common/index'; import type { DeepReadonly } from '../../core/index'; @@ -28,8 +28,8 @@ export class TezosTaquitoAtomexProtocolV1 extends TaquitoAtomexProtocolV1 { throw new Error('Method not implemented.'); } - getEstimatedInitiateFees(params: Partial): Promise { - return super.getEstimatedInitiateFees(params); + getInitiateFees(params: Partial): Promise { + return super.getInitiateFees(params); } redeem(_params: AtomexProtocolV1RedeemParameters): Promise { @@ -40,15 +40,15 @@ export class TezosTaquitoAtomexProtocolV1 extends TaquitoAtomexProtocolV1 { throw new Error('Method not implemented.'); } - getEstimatedRedeemFees(params: Partial): Promise { - return super.getEstimatedRedeemFees(params); + getRedeemFees(params: Partial): Promise { + return super.getRedeemFees(params); } refund(_params: AtomexProtocolV1RefundParameters): Promise { throw new Error('Method not implemented.'); } - getEstimatedRefundFees(params: Partial): Promise { - return super.getEstimatedRefundFees(params); + getRefundFees(params: Partial): Promise { + return super.getRefundFees(params); } }