Skip to content

Commit

Permalink
Merge pull request #195 from zikriya/develop
Browse files Browse the repository at this point in the history
numberIntoDecimals__ new method added and replaced in fiberNode module
  • Loading branch information
zikriya committed Mar 5, 2024
2 parents a137edd + 1f8f361 commit 15e3c5a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
8 changes: 8 additions & 0 deletions app/lib/middlewares/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,14 @@ module.exports = {
return amountFormatted;
},

numberIntoDecimals__(amount: any, decimal: any) {
amount = Big(amount);
decimal = Big(10 ** Number(decimal));
let amountFormatted = amount.mul(decimal).toString();
amountFormatted = parseInt(amountFormatted);
return amountFormatted;
},

decimalsIntoNumber(amount: any, decimal: any) {
const bigNumberValue = ethers.BigNumber.from(amount.toString());
let formattedValue = ethers.utils.formatUnits(bigNumberValue, decimal);
Expand Down
24 changes: 14 additions & 10 deletions scripts/fiberNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,10 @@ module.exports = {
const targetTokenDecimal = await targetTokenContract.decimals();
const targetFoundryTokenDecimal =
await targetFoundryTokenContract.decimals();
let amountIn: any = (
sourceBridgeAmount *
10 ** Number(targetFoundryTokenDecimal)
).toString();
let amountIn: any = (global as any).commonFunctions.numberIntoDecimals__(
sourceBridgeAmount,
targetFoundryTokenDecimal
);
amountIn = parseInt(amountIn);
let targetTypeResponse = await getTargetAssetTypes(
targetNetwork,
Expand All @@ -173,19 +173,23 @@ module.exports = {
);
destinationAmountOut = sourceBridgeAmount;
machineDestinationAmountIn = (
sourceBridgeAmount *
10 ** Number(targetFoundryTokenDecimal)
).toString();
global as any
).commonFunctions.numberIntoDecimals__(
sourceBridgeAmount,
targetFoundryTokenDecimal
);
machineDestinationAmountIn = parseInt(machineDestinationAmountIn);
} else {
sourceBridgeAmount = getSourceAmountOut(
gasEstimationDestinationAmount,
sourceBridgeAmount
);
let machineAmount: any = (
sourceBridgeAmount *
10 ** Number(targetFoundryTokenDecimal)
).toString();
global as any
).commonFunctions.numberIntoDecimals__(
sourceBridgeAmount,
targetFoundryTokenDecimal
);
machineAmount = parseInt(machineAmount);
machineDestinationAmountIn = machineAmount;
machineAmount = (global as any).utils.convertFromExponentialToDecimal(
Expand Down

0 comments on commit 15e3c5a

Please sign in to comment.