mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
Fix/pool_approve (#1207)
* fix * fixes * fix estimate * fix approve * convert to wei * final fix
This commit is contained in:
parent
aa1c1fcfbf
commit
33ca7f43c1
@ -58,11 +58,11 @@ export class Pool {
|
|||||||
let estGas
|
let estGas
|
||||||
try {
|
try {
|
||||||
estGas = await tokenContract.methods
|
estGas = await tokenContract.methods
|
||||||
.approve(spender, new BigNumber(amount))
|
.approve(spender, amount)
|
||||||
.estimateGas({ from: account }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
.estimateGas({ from: account }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
estGas = gasLimitDefault
|
estGas = gasLimitDefault
|
||||||
LoggerInstance.error('estimage gas failed for approve!', e)
|
LoggerInstance.error('estimate gas failed for approve!', e)
|
||||||
}
|
}
|
||||||
return estGas
|
return estGas
|
||||||
}
|
}
|
||||||
@ -128,7 +128,7 @@ export class Pool {
|
|||||||
const token = new this.web3.eth.Contract(minABI, tokenAddress)
|
const token = new this.web3.eth.Contract(minABI, tokenAddress)
|
||||||
if (!force) {
|
if (!force) {
|
||||||
const currentAllowence = await this.allowance(tokenAddress, account, spender)
|
const currentAllowence = await this.allowance(tokenAddress, account, spender)
|
||||||
if (new Decimal(currentAllowence).greaterThanOrEqualTo(amount)) {
|
if (new Decimal(currentAllowence).greaterThanOrEqualTo(new Decimal(amount))) {
|
||||||
return currentAllowence
|
return currentAllowence
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -137,13 +137,11 @@ export class Pool {
|
|||||||
const estGas = await this.estApprove(account, tokenAddress, spender, amountFormatted)
|
const estGas = await this.estApprove(account, tokenAddress, spender, amountFormatted)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
result = await token.methods
|
result = await token.methods.approve(spender, amountFormatted).send({
|
||||||
.approve(spender, new BigNumber(await this.amountToUnits(tokenAddress, amount)))
|
from: account,
|
||||||
.send({
|
gas: estGas + 1,
|
||||||
from: account,
|
gasPrice: await getFairGasPrice(this.web3)
|
||||||
gas: estGas + 1,
|
})
|
||||||
gasPrice: await getFairGasPrice(this.web3)
|
|
||||||
})
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.logger.error(`ERRPR: Failed to approve spender to spend tokens : ${e.message}`)
|
this.logger.error(`ERRPR: Failed to approve spender to spend tokens : ${e.message}`)
|
||||||
}
|
}
|
||||||
@ -747,6 +745,7 @@ export class Pool {
|
|||||||
decimals = 18
|
decimals = 18
|
||||||
}
|
}
|
||||||
const amountFormatted = new BigNumber(parseInt(amount) * 10 ** decimals)
|
const amountFormatted = new BigNumber(parseInt(amount) * 10 ** decimals)
|
||||||
|
BigNumber.config({ EXPONENTIAL_AT: 50 })
|
||||||
return amountFormatted.toString()
|
return amountFormatted.toString()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.logger.error('ERROR: FAILED TO CALL DECIMALS(), USING 18')
|
this.logger.error('ERROR: FAILED TO CALL DECIMALS(), USING 18')
|
||||||
@ -1056,7 +1055,6 @@ export class Pool {
|
|||||||
const amount = await this.amountToUnits(tokens[i], maxAmountsIn[i])
|
const amount = await this.amountToUnits(tokens[i], maxAmountsIn[i])
|
||||||
weiMaxAmountsIn.push(amount)
|
weiMaxAmountsIn.push(amount)
|
||||||
}
|
}
|
||||||
// console.log(weiMaxAmountsIn)
|
|
||||||
|
|
||||||
let result = null
|
let result = null
|
||||||
|
|
||||||
@ -1524,14 +1522,11 @@ export class Pool {
|
|||||||
if (decimalsTokenIn > decimalsTokenOut) {
|
if (decimalsTokenIn > decimalsTokenOut) {
|
||||||
decimalsDiff = decimalsTokenIn - decimalsTokenOut
|
decimalsDiff = decimalsTokenIn - decimalsTokenOut
|
||||||
price = new BigNumber(price / 10 ** decimalsDiff)
|
price = new BigNumber(price / 10 ** decimalsDiff)
|
||||||
// console.log(price.toString())
|
|
||||||
price = price / 10 ** decimalsTokenOut
|
price = price / 10 ** decimalsTokenOut
|
||||||
// console.log('dtIn')
|
|
||||||
} else {
|
} else {
|
||||||
decimalsDiff = decimalsTokenOut - decimalsTokenIn
|
decimalsDiff = decimalsTokenOut - decimalsTokenIn
|
||||||
price = new BigNumber(price * 10 ** (2 * decimalsDiff))
|
price = new BigNumber(price * 10 ** (2 * decimalsDiff))
|
||||||
price = price / 10 ** decimalsTokenOut
|
price = price / 10 ** decimalsTokenOut
|
||||||
// console.log('usdcIn')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return price.toString()
|
return price.toString()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user