fix: always consider user input when performing swap (#572)

* fix: always consider user input when performing swap

* refactor: extract decimal places constants

* refactor: extract minimumOptimalValue

* fix: handle bzz precision and tweak message
This commit is contained in:
Cafe137
2022-11-09 14:21:34 +01:00
committed by GitHub
parent a4b8e7ca25
commit ec8fdf0315
5 changed files with 98 additions and 47 deletions
+8 -2
View File
@@ -1,8 +1,14 @@
import { BigNumber } from 'bignumber.js'
import { Token } from './Token'
export const BZZ_DECIMAL_PLACES = 16
export class BzzToken extends Token {
constructor(amount: BigNumber | string | bigint) {
super(amount, 16)
constructor(value: BigNumber | string | bigint) {
super(value, BZZ_DECIMAL_PLACES)
}
static fromDecimal(value: BigNumber | string | bigint): BzzToken {
return Token.fromDecimal(value, BZZ_DECIMAL_PLACES)
}
}
+8 -2
View File
@@ -1,8 +1,14 @@
import { BigNumber } from 'bignumber.js'
import { Token } from './Token'
const DAI_DECIMAL_PLACES = 18
export class DaiToken extends Token {
constructor(amount: BigNumber | string | bigint) {
super(amount, 18)
constructor(value: BigNumber | string | bigint) {
super(value, DAI_DECIMAL_PLACES)
}
static fromDecimal(value: BigNumber | string | bigint): DaiToken {
return Token.fromDecimal(value, DAI_DECIMAL_PLACES)
}
}
+7
View File
@@ -87,4 +87,11 @@ export class Token {
this.decimals,
)
}
plusBaseUnits(amount: string): Token {
return new Token(
this.toBigNumber.plus(new BigNumber(amount).multipliedBy(new BigNumber(10).pow(this.decimals))),
this.decimals,
)
}
}