Skip to content

Commit

Permalink
Proper conversion to wei of base token when ordering (#1527)
Browse files Browse the repository at this point in the history
* proper conversion to wei

Signed-off-by: mihaisc <[email protected]>

* fix conversion in pool

Signed-off-by: mihaisc <[email protected]>

* fix test

Signed-off-by: mihaisc <[email protected]>

* fix lint

Signed-off-by: mihaisc <[email protected]>
  • Loading branch information
mihaisc authored Jun 24, 2022
1 parent 50527fa commit 237e948
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/@types/FixedPrice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export interface FreOrderParams {
exchangeContract: string
exchangeId: string
maxBaseTokenAmount: string
baseTokenAddress: string
baseTokenDecimals?: number
swapMarketFee: string
marketFeeAddress: string
}
Expand Down
2 changes: 1 addition & 1 deletion src/pools/balancer/Pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1363,7 +1363,7 @@ export class Pool {
tokenAmount: await this.unitsToAmount(
tokenOut,
result.tokenAmountIn,
tokenOutDecimals
tokenInDecimals
),
liquidityProviderSwapFeeAmount: await this.unitsToAmount(
tokenIn,
Expand Down
2 changes: 1 addition & 1 deletion src/tokens/Datatoken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1037,7 +1037,7 @@ export class Datatoken {
): Promise<TransactionReceipt> {
const dtContract = new this.web3.eth.Contract(this.datatokensEnterpriseAbi, dtAddress)
try {
const freContractParams = getFreOrderParams(freParams)
const freContractParams = await getFreOrderParams(this.web3, freParams)

const estGas = await estimateGas(
address,
Expand Down
19 changes: 16 additions & 3 deletions src/utils/ContractUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,25 @@ export function getErcCreationParams(ercParams: Erc20CreateParams): any {
}
}

export function getFreOrderParams(freParams: FreOrderParams): any {
export async function getFreOrderParams(
web3: Web3,
freParams: FreOrderParams
): Promise<any> {
return {
exchangeContract: freParams.exchangeContract,
exchangeId: freParams.exchangeId,
maxBaseTokenAmount: Web3.utils.toWei(freParams.maxBaseTokenAmount),
swapMarketFee: Web3.utils.toWei(freParams.swapMarketFee),
maxBaseTokenAmount: await amountToUnits(
web3,
freParams.baseTokenAddress,
freParams.maxBaseTokenAmount,
freParams.baseTokenDecimals
),
swapMarketFee: await amountToUnits(
web3,
freParams.baseTokenAddress,
freParams.swapMarketFee,
freParams.baseTokenDecimals
),
marketFeeAddress: freParams.marketFeeAddress
}
}
Expand Down
2 changes: 2 additions & 0 deletions test/unit/tokens/Datatoken.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,8 @@ describe('Datatoken', () => {
exchangeContract: fixedRateAddress,
exchangeId: exchangeId,
maxBaseTokenAmount: '1',
baseTokenAddress: contracts.daiAddress,
baseTokenDecimals: 18,
swapMarketFee: '0.1',
marketFeeAddress: ZERO_ADDRESS
}
Expand Down

0 comments on commit 237e948

Please sign in to comment.