Skip to content

Commit

Permalink
Merge pull request #135 from sotatek-dev/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Sotatek-TanHoang authored Oct 3, 2024
2 parents 074f6c9 + 97ca623 commit 3624a99
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
6 changes: 3 additions & 3 deletions src/modules/crawler/sender.evmbridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import assert from 'assert';
import { BigNumber } from 'bignumber.js';
import { isNumberString } from 'class-validator';
import { ethers } from 'ethers';

import { getEthBridgeAddress } from '../../config/common.config.js';
Expand Down Expand Up @@ -46,8 +45,9 @@ export class SenderEVMBridge {
return { error: null, success: false };
}

assert(isNumberString(dataLock.tip.toString()), 'invalid gasFee');
assert(isNumberString(dataLock.gasFee.toString()), 'invalid tips');
assert(dataLock.tip.toString(), 'invalid gasFee');
assert(dataLock.gasFee.toString(), 'invalid tips');
assert(dataLock.amountReceived, 'invalida amount to unlock');

const { tokenReceivedAddress, txHashLock, receiveAddress, amountFrom } = dataLock;

Expand Down
5 changes: 2 additions & 3 deletions src/modules/crawler/sender.minabridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import assert from 'assert';
import { BigNumber } from 'bignumber.js';
import { isNumberString } from 'class-validator';
import { FungibleToken, FungibleTokenAdmin } from 'mina-fungible-token';
import { AccountUpdate, Bool, fetchAccount, Mina, PrivateKey, PublicKey, Signature, UInt64 } from 'o1js';

Expand Down Expand Up @@ -89,8 +88,8 @@ export class SenderMinaBridge {
this.logger.warn(`Not found tx with id ${txId}`);
return { error: null, success: false };
}
assert(isNumberString(dataLock.tip.toString()), 'invalid gasFee');
assert(isNumberString(dataLock.gasFee.toString()), 'invalid tips');
assert(dataLock.tip.toString(), 'invalid gasFee');
assert(dataLock.gasFee.toString(), 'invalid tips');
assert(dataLock.amountReceived, 'invalida amount to unlock');

await this.eventLogRepository.updateLockEvenLog(dataLock.id, EEventStatus.PROCESSING);
Expand Down
8 changes: 4 additions & 4 deletions src/modules/crawler/tests/calculation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { calculateUnlockFee } from '../../../shared/utils/bignumber.js';

describe('test amount fee calculation', () => {
it('correct amount', () => {
const fromDecimal = 18,
toDecimal = 9,
const fromDecimal = 9,
toDecimal = 18,
gasFeeWithDecimalPlaces = '0.000001',
inputAmountNoDecimalPlaces = '159719371259000000',
tipPercent = 5;
inputAmountNoDecimalPlaces = '200000',
tipPercent = 0.0001;
const result = calculateUnlockFee({
fromDecimal,
gasFeeWithDecimalPlaces,
Expand Down
6 changes: 3 additions & 3 deletions src/shared/utils/bignumber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ export const calculateUnlockFee = ({
.dividedBy(BigNumber(DECIMAL_BASE).pow(fromDecimal))
.multipliedBy(BigNumber(DECIMAL_BASE).pow(toDecimal));

const gasFeeMina = addDecimal(gasFeeWithDecimalPlaces, toDecimal);
const gasFee = addDecimal(gasFeeWithDecimalPlaces, toDecimal);

const tip = calculateTip(amountReceiveConvert.toString(), gasFeeMina, tipPercent);
const tip = calculateTip(amountReceiveConvert.toString(), gasFee, tipPercent);

// protocol fee = tip + gas_fee
const protocolFeeNoDecimalPlace = tip.plus(gasFeeMina);
const protocolFeeNoDecimalPlace = tip.plus(gasFee);

// amount received= total amount - protocol fee
const amountReceived = BigNumber(amountReceiveConvert).minus(protocolFeeNoDecimalPlace);
Expand Down

0 comments on commit 3624a99

Please sign in to comment.