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

Proper conversion to wei of base token when ordering #1527

Merged
merged 4 commits into from
Jun 24, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
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