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,
|
LoggerInstance,
|
||||||
getFairGasPrice,
|
getFairGasPrice,
|
||||||
configHelperNetworks,
|
configHelperNetworks,
|
||||||
setContractDefaults
|
setContractDefaults,
|
||||||
|
amountToUnits,
|
||||||
|
unitsToAmount
|
||||||
} from '../../utils'
|
} from '../../utils'
|
||||||
import { Config } from '../../models/index.js'
|
import { Config } from '../../models/index.js'
|
||||||
import { PriceAndFees } from '../..'
|
import { PriceAndFees } from '../..'
|
||||||
@ -89,38 +91,11 @@ export class FixedRateExchange {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async amountToUnits(token: string, amount: string): Promise<string> {
|
async amountToUnits(token: string, amount: string): Promise<string> {
|
||||||
let decimals = 18
|
return amountToUnits(this.web3, token, amount)
|
||||||
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()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async unitsToAmount(token: string, amount: string): Promise<string> {
|
async unitsToAmount(token: string, amount: string): Promise<string> {
|
||||||
let decimals = 18
|
return unitsToAmount(this.web3, token, amount)
|
||||||
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()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -80,7 +80,7 @@ export function getFreCreationParams(freParams: FreCreationParams): any {
|
|||||||
uints: [
|
uints: [
|
||||||
freParams.baseTokenDecimals,
|
freParams.baseTokenDecimals,
|
||||||
freParams.datatokenDecimals,
|
freParams.datatokenDecimals,
|
||||||
freParams.fixedRate,
|
Web3.utils.toWei(freParams.fixedRate),
|
||||||
Web3.utils.toWei(freParams.marketFee),
|
Web3.utils.toWei(freParams.marketFee),
|
||||||
withMint
|
withMint
|
||||||
]
|
]
|
||||||
|
@ -121,7 +121,7 @@ describe('Fixed Rate unit test', () => {
|
|||||||
marketFeeCollector: user3,
|
marketFeeCollector: user3,
|
||||||
baseTokenDecimals: 18,
|
baseTokenDecimals: 18,
|
||||||
datatokenDecimals: 18,
|
datatokenDecimals: 18,
|
||||||
fixedRate: web3.utils.toWei('1'),
|
fixedRate: '1',
|
||||||
marketFee: '0.001',
|
marketFee: '0.001',
|
||||||
allowedConsumer: ADDRESS_ZERO,
|
allowedConsumer: ADDRESS_ZERO,
|
||||||
withMint: false
|
withMint: false
|
||||||
@ -453,7 +453,7 @@ describe('Fixed Rate unit test', () => {
|
|||||||
marketFeeCollector: user3,
|
marketFeeCollector: user3,
|
||||||
baseTokenDecimals: 6,
|
baseTokenDecimals: 6,
|
||||||
datatokenDecimals: 18,
|
datatokenDecimals: 18,
|
||||||
fixedRate: web3.utils.toWei('1'),
|
fixedRate: '1',
|
||||||
marketFee: '0.001',
|
marketFee: '0.001',
|
||||||
allowedConsumer: ADDRESS_ZERO,
|
allowedConsumer: ADDRESS_ZERO,
|
||||||
withMint: false
|
withMint: false
|
||||||
|
Loading…
x
Reference in New Issue
Block a user