Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove redundant get in calcBaseInGivenOutDT #1283

Merged
merged 3 commits into from
Feb 14, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 6 additions & 18 deletions src/pools/fixedRate/FixedRateExchange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -539,41 +539,29 @@ export class FixedRateExchange {
exchangeId: string,
datatokenAmount: string
): Promise<PriceAndFees> {
const fixedRateExchange = await this.getExchange(exchangeId)
const result = await this.contract.methods
.calcBaseInGivenOutDT(
exchangeId,
await this.amountToUnits(
(
await this.getExchange(exchangeId)
).datatoken,
datatokenAmount
)
await this.amountToUnits(fixedRateExchange.datatoken, datatokenAmount)
)
.call()

const priceAndFees = {
baseTokenAmount: await this.unitsToAmount(
(
await this.getExchange(exchangeId)
).baseToken,
fixedRateExchange.baseToken,
result.baseTokenAmount
),
baseTokenAmountBeforeFee: await this.unitsToAmount(
(
await this.getExchange(exchangeId)
).baseToken,
fixedRateExchange.baseToken,
result.baseTokenAmountBeforeFee
),
marketFeeAmount: await this.unitsToAmount(
(
await this.getExchange(exchangeId)
).baseToken,
fixedRateExchange.baseToken,
result.marketFeeAmount
),
oceanFeeAmount: await this.unitsToAmount(
(
await this.getExchange(exchangeId)
).baseToken,
fixedRateExchange.baseToken,
result.oceanFeeAmount
)
} as PriceAndFees
Expand Down
4 changes: 2 additions & 2 deletions src/utils/ContractUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export async function unitsToAmount(
if (decimals === '0') {
decimals = 18
}
const amountFormatted = new BigNumber(parseInt(amount) / 10 ** decimals)
const amountFormatted = new BigNumber(amount).div(10).toExponential(decimals)
BigNumber.config({ EXPONENTIAL_AT: 50 })
return amountFormatted.toString()
} catch (e) {
Expand All @@ -140,7 +140,7 @@ export async function amountToUnits(
if (decimals === '0') {
decimals = 18
}
const amountFormatted = new BigNumber(parseInt(amount) * 10 ** decimals)
const amountFormatted = new BigNumber(amount).times(10).toExponential(decimals)
BigNumber.config({ EXPONENTIAL_AT: 50 })
return amountFormatted.toString()
} catch (e) {
Expand Down