Skip to content

Commit

Permalink
Calculate estimated fees for all tezos operations
Browse files Browse the repository at this point in the history
  • Loading branch information
maxima-net committed Aug 19, 2022
1 parent 5f8f729 commit 067240b
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 22 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"cSpell.words": [
"atomex",
"esbuild",
"mutez",
"outdir",
"taquito",
"tezos",
Expand Down
12 changes: 6 additions & 6 deletions src/tezos/atomexProtocol/fa12TezosTaquitoAtomexProtocolV1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ export class FA12TezosTaquitoAtomexProtocolV1 extends TaquitoAtomexProtocolV1 {
throw new Error('Method not implemented.');
}

getEstimatedInitiateFees(_params: Partial<AtomexProtocolV1InitiateParameters>): Promise<BigNumber> {
throw new Error('Method not implemented.');
getEstimatedInitiateFees(params: Partial<AtomexProtocolV1InitiateParameters>): Promise<BigNumber> {
return super.getEstimatedInitiateFees(params);
}

redeem(_params: AtomexProtocolV1RedeemParameters): Promise<Transaction> {
Expand All @@ -40,15 +40,15 @@ export class FA12TezosTaquitoAtomexProtocolV1 extends TaquitoAtomexProtocolV1 {
throw new Error('Method not implemented.');
}

getEstimatedRedeemFees(_params: Partial<AtomexProtocolV1InitiateParameters>): Promise<BigNumber> {
throw new Error('Method not implemented.');
getEstimatedRedeemFees(params: Partial<AtomexProtocolV1InitiateParameters>): Promise<BigNumber> {
return super.getEstimatedRedeemFees(params);
}

refund(_params: AtomexProtocolV1RefundParameters): Promise<Transaction> {
throw new Error('Method not implemented.');
}

getEstimatedRefundFees(_params: Partial<AtomexProtocolV1InitiateParameters>): Promise<BigNumber> {
throw new Error('Method not implemented.');
getEstimatedRefundFees(params: Partial<AtomexProtocolV1InitiateParameters>): Promise<BigNumber> {
return super.getEstimatedRefundFees(params);
}
}
12 changes: 6 additions & 6 deletions src/tezos/atomexProtocol/fa2TezosTaquitoAtomexProtocolV1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ export class FA2TezosTaquitoAtomexProtocolV1 extends TaquitoAtomexProtocolV1 {
throw new Error('Method not implemented.');
}

getEstimatedInitiateFees(_params: Partial<AtomexProtocolV1InitiateParameters>): Promise<BigNumber> {
throw new Error('Method not implemented.');
getEstimatedInitiateFees(params: Partial<AtomexProtocolV1InitiateParameters>): Promise<BigNumber> {
return super.getEstimatedInitiateFees(params);
}

redeem(_params: AtomexProtocolV1RedeemParameters): Promise<Transaction> {
Expand All @@ -40,15 +40,15 @@ export class FA2TezosTaquitoAtomexProtocolV1 extends TaquitoAtomexProtocolV1 {
throw new Error('Method not implemented.');
}

getEstimatedRedeemFees(_params: Partial<AtomexProtocolV1InitiateParameters>): Promise<BigNumber> {
throw new Error('Method not implemented.');
getEstimatedRedeemFees(params: Partial<AtomexProtocolV1InitiateParameters>): Promise<BigNumber> {
return super.getEstimatedRedeemFees(params);
}

refund(_params: AtomexProtocolV1RefundParameters): Promise<Transaction> {
throw new Error('Method not implemented.');
}

getEstimatedRefundFees(_params: Partial<AtomexProtocolV1InitiateParameters>): Promise<BigNumber> {
throw new Error('Method not implemented.');
getEstimatedRefundFees(params: Partial<AtomexProtocolV1InitiateParameters>): Promise<BigNumber> {
return super.getEstimatedRefundFees(params);
}
}
21 changes: 17 additions & 4 deletions src/tezos/atomexProtocol/taquitoAtomexProtocolV1.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { TezosToolkit } from '@taquito/taquito';
import type BigNumber from 'bignumber.js';
import BigNumber from 'bignumber.js';

import type {
AtomexBlockchainProvider,
Expand All @@ -9,6 +9,7 @@ import type {
import type { AtomexNetwork } from '../../common/index';
import type { DeepReadonly } from '../../core/index';
import type { TaquitoAtomexProtocolV1Options } from '../models/index';
import { mutezInTez } from '../utils';

export abstract class TaquitoAtomexProtocolV1 implements AtomexProtocolV1 {
readonly version = 1;
Expand All @@ -28,17 +29,29 @@ export abstract class TaquitoAtomexProtocolV1 implements AtomexProtocolV1 {

abstract initiate(_params: AtomexProtocolV1InitiateParameters): Promise<Transaction>;

abstract getEstimatedInitiateFees(_params: Partial<AtomexProtocolV1InitiateParameters>): Promise<BigNumber>;
getEstimatedInitiateFees(_params: Partial<AtomexProtocolV1InitiateParameters>): Promise<BigNumber> {
const fee = new BigNumber(this.atomexProtocolOptions.initiateOperation.fee).div(mutezInTez);

return Promise.resolve(fee);
}

abstract redeem(_params: AtomexProtocolV1RedeemParameters): Promise<Transaction>;

abstract getRedeemReward(_nativeTokenPriceInUsd: number, _nativeTokenPriceInCurrency: number): Promise<BigNumber>;

abstract getEstimatedRedeemFees(_params: Partial<AtomexProtocolV1InitiateParameters>): Promise<BigNumber>;
getEstimatedRedeemFees(_params: Partial<AtomexProtocolV1InitiateParameters>): Promise<BigNumber> {
const fee = new BigNumber(this.atomexProtocolOptions.redeemOperation.fee).div(mutezInTez);

return Promise.resolve(fee);
}

abstract refund(_params: AtomexProtocolV1RefundParameters): Promise<Transaction>;

abstract getEstimatedRefundFees(_params: Partial<AtomexProtocolV1InitiateParameters>): Promise<BigNumber>;
getEstimatedRefundFees(_params: Partial<AtomexProtocolV1InitiateParameters>): Promise<BigNumber> {
const fee = new BigNumber(this.atomexProtocolOptions.refundOperation.fee).div(mutezInTez);

return Promise.resolve(fee);
}

protected async getReadonlyTezosToolkit(): Promise<TezosToolkit> {
const toolkit = await this.atomexBlockchainProvider.getReadonlyToolkit<TezosToolkit>('taquito', this.blockchain);
Expand Down
12 changes: 6 additions & 6 deletions src/tezos/atomexProtocol/tezosTaquitoAtomexProtocolV1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ export class TezosTaquitoAtomexProtocolV1 extends TaquitoAtomexProtocolV1 {
throw new Error('Method not implemented.');
}

getEstimatedInitiateFees(_params: Partial<AtomexProtocolV1InitiateParameters>): Promise<BigNumber> {
throw new Error('Method not implemented.');
getEstimatedInitiateFees(params: Partial<AtomexProtocolV1InitiateParameters>): Promise<BigNumber> {
return super.getEstimatedInitiateFees(params);
}

redeem(_params: AtomexProtocolV1RedeemParameters): Promise<Transaction> {
Expand All @@ -40,15 +40,15 @@ export class TezosTaquitoAtomexProtocolV1 extends TaquitoAtomexProtocolV1 {
throw new Error('Method not implemented.');
}

getEstimatedRedeemFees(_params: Partial<AtomexProtocolV1InitiateParameters>): Promise<BigNumber> {
throw new Error('Method not implemented.');
getEstimatedRedeemFees(params: Partial<AtomexProtocolV1InitiateParameters>): Promise<BigNumber> {
return super.getEstimatedRedeemFees(params);
}

refund(_params: AtomexProtocolV1RefundParameters): Promise<Transaction> {
throw new Error('Method not implemented.');
}

getEstimatedRefundFees(_params: Partial<AtomexProtocolV1InitiateParameters>): Promise<BigNumber> {
throw new Error('Method not implemented.');
getEstimatedRefundFees(params: Partial<AtomexProtocolV1InitiateParameters>): Promise<BigNumber> {
return super.getEstimatedRefundFees(params);
}
}
3 changes: 3 additions & 0 deletions src/tezos/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { b58cdecode, prefix, validatePkAndExtractPrefix } from '@taquito/utils';
import BigNumber from 'bignumber.js';

import { Buffer } from '../../native';
export { isTezosCurrency } from './guards';

export const mutezInTez = new BigNumber(1_000_000);

export const decodePublicKey = (publicKey: string) => {
const keyPrefix = validatePkAndExtractPrefix(publicKey);
const decodedKeyBytes = b58cdecode(publicKey, prefix[keyPrefix]);
Expand Down

0 comments on commit 067240b

Please sign in to comment.