mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
fix redundancy (#1278)
* fix redundancy * convert to wei fixed price * fix test
This commit is contained in:
parent
88c0b3046d
commit
6f12e28ada
@ -9,7 +9,9 @@ import {
|
||||
LoggerInstance,
|
||||
getFairGasPrice,
|
||||
configHelperNetworks,
|
||||
setContractDefaults
|
||||
setContractDefaults,
|
||||
amountToUnits,
|
||||
unitsToAmount
|
||||
} from '../../utils'
|
||||
import { Config } from '../../models/index.js'
|
||||
import { PriceAndFees } from '../..'
|
||||
@ -89,38 +91,11 @@ export class FixedRateExchange {
|
||||
}
|
||||
|
||||
async amountToUnits(token: string, amount: string): Promise<string> {
|
||||
let decimals = 18
|
||||
const tokenContract = setContractDefaults(
|
||||
new this.web3.eth.Contract(defaultErc20Abi.abi as AbiItem[], token),
|
||||
this.config
|
||||
)
|
||||
|
||||
try {
|
||||
decimals = await tokenContract.methods.decimals().call()
|
||||
} catch (e) {
|
||||
LoggerInstance.error('ERROR: FAILED TO CALL DECIMALS(), USING 18')
|
||||
}
|
||||
|
||||
const amountFormatted = new BigNumber(parseInt(amount) * 10 ** decimals)
|
||||
|
||||
return amountFormatted.toString()
|
||||
return amountToUnits(this.web3, token, amount)
|
||||
}
|
||||
|
||||
async unitsToAmount(token: string, amount: string): Promise<string> {
|
||||
let decimals = 18
|
||||
const tokenContract = setContractDefaults(
|
||||
new this.web3.eth.Contract(defaultErc20Abi.abi as AbiItem[], token),
|
||||
this.config
|
||||
)
|
||||
try {
|
||||
decimals = await tokenContract.methods.decimals().call()
|
||||
} catch (e) {
|
||||
LoggerInstance.error('ERROR: FAILED TO CALL DECIMALS(), USING 18')
|
||||
}
|
||||
|
||||
const amountFormatted = new BigNumber(parseInt(amount) / 10 ** decimals)
|
||||
|
||||
return amountFormatted.toString()
|
||||
return unitsToAmount(this.web3, token, amount)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -80,7 +80,7 @@ export function getFreCreationParams(freParams: FreCreationParams): any {
|
||||
uints: [
|
||||
freParams.baseTokenDecimals,
|
||||
freParams.datatokenDecimals,
|
||||
freParams.fixedRate,
|
||||
Web3.utils.toWei(freParams.fixedRate),
|
||||
Web3.utils.toWei(freParams.marketFee),
|
||||
withMint
|
||||
]
|
||||
|
@ -121,7 +121,7 @@ describe('Fixed Rate unit test', () => {
|
||||
marketFeeCollector: user3,
|
||||
baseTokenDecimals: 18,
|
||||
datatokenDecimals: 18,
|
||||
fixedRate: web3.utils.toWei('1'),
|
||||
fixedRate: '1',
|
||||
marketFee: '0.001',
|
||||
allowedConsumer: ADDRESS_ZERO,
|
||||
withMint: false
|
||||
@ -453,7 +453,7 @@ describe('Fixed Rate unit test', () => {
|
||||
marketFeeCollector: user3,
|
||||
baseTokenDecimals: 6,
|
||||
datatokenDecimals: 18,
|
||||
fixedRate: web3.utils.toWei('1'),
|
||||
fixedRate: '1',
|
||||
marketFee: '0.001',
|
||||
allowedConsumer: ADDRESS_ZERO,
|
||||
withMint: false
|
||||
|
Loading…
x
Reference in New Issue
Block a user