mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
fix #341
This commit is contained in:
parent
002a38d487
commit
6fd0dc0c1f
@ -80,16 +80,28 @@ export class OceanPool extends Pool {
|
|||||||
const oceanWeight = 10 - parseFloat(weight)
|
const oceanWeight = 10 - parseFloat(weight)
|
||||||
const oceanAmount = (parseFloat(amount) * oceanWeight) / parseFloat(weight)
|
const oceanAmount = (parseFloat(amount) * oceanWeight) / parseFloat(weight)
|
||||||
this.dtAddress = token
|
this.dtAddress = token
|
||||||
|
let txid
|
||||||
await this.approve(account, token, address, this.web3.utils.toWei(String(amount)))
|
txid = await this.approve(
|
||||||
await this.approve(
|
account,
|
||||||
|
token,
|
||||||
|
address,
|
||||||
|
this.web3.utils.toWei(String(amount))
|
||||||
|
)
|
||||||
|
if (!txid) {
|
||||||
|
console.error('DT approve failed')
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
txid = await this.approve(
|
||||||
account,
|
account,
|
||||||
this.oceanAddress,
|
this.oceanAddress,
|
||||||
address,
|
address,
|
||||||
this.web3.utils.toWei(String(oceanAmount))
|
this.web3.utils.toWei(String(oceanAmount))
|
||||||
)
|
)
|
||||||
|
if (!txid) {
|
||||||
await super.setup(
|
console.error('OCEAN approve failed')
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
txid = await super.setup(
|
||||||
account,
|
account,
|
||||||
address,
|
address,
|
||||||
token,
|
token,
|
||||||
@ -100,7 +112,10 @@ export class OceanPool extends Pool {
|
|||||||
this.web3.utils.toWei(String(oceanWeight)),
|
this.web3.utils.toWei(String(oceanWeight)),
|
||||||
this.web3.utils.toWei(fee)
|
this.web3.utils.toWei(fee)
|
||||||
)
|
)
|
||||||
|
if (!txid) {
|
||||||
|
console.error('Pool creation failed')
|
||||||
|
return null
|
||||||
|
}
|
||||||
return address
|
return address
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -415,7 +430,7 @@ export class OceanPool extends Pool {
|
|||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
const balance = await super.getReserve(poolAddress, tokenAddress)
|
const balance = await super.getReserve(poolAddress, tokenAddress)
|
||||||
const result = new BigNumber(this.web3.utils.toWei(balance))
|
const result = new BigNumber(this.web3.utils.toWei(balance))
|
||||||
.dividedBy(3)
|
.dividedBy(4)
|
||||||
.integerValue(BigNumber.ROUND_DOWN)
|
.integerValue(BigNumber.ROUND_DOWN)
|
||||||
.minus(1)
|
.minus(1)
|
||||||
return this.web3.utils.fromWei(result.toString())
|
return this.web3.utils.fromWei(result.toString())
|
||||||
@ -474,13 +489,16 @@ export class OceanPool extends Pool {
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
// TODO - check balances first
|
// TODO - check balances first
|
||||||
await super.approve(
|
const txid = await super.approve(
|
||||||
account,
|
account,
|
||||||
this.oceanAddress,
|
this.oceanAddress,
|
||||||
poolAddress,
|
poolAddress,
|
||||||
this.web3.utils.toWei(maxOceanAmount)
|
this.web3.utils.toWei(maxOceanAmount)
|
||||||
)
|
)
|
||||||
|
if (!txid) {
|
||||||
|
console.error('OCEAN approve failed')
|
||||||
|
return null
|
||||||
|
}
|
||||||
return this.swapExactAmountOut(
|
return this.swapExactAmountOut(
|
||||||
account,
|
account,
|
||||||
poolAddress,
|
poolAddress,
|
||||||
@ -526,7 +544,16 @@ export class OceanPool extends Pool {
|
|||||||
console.error('Not enough Data Tokens')
|
console.error('Not enough Data Tokens')
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
await super.approve(account, dtAddress, poolAddress, this.web3.utils.toWei(dtAmount))
|
const txid = await super.approve(
|
||||||
|
account,
|
||||||
|
dtAddress,
|
||||||
|
poolAddress,
|
||||||
|
this.web3.utils.toWei(dtAmount)
|
||||||
|
)
|
||||||
|
if (!txid) {
|
||||||
|
console.error('DT approve failed')
|
||||||
|
return null
|
||||||
|
}
|
||||||
return this.swapExactAmountIn(
|
return this.swapExactAmountIn(
|
||||||
account,
|
account,
|
||||||
poolAddress,
|
poolAddress,
|
||||||
@ -556,7 +583,16 @@ export class OceanPool extends Pool {
|
|||||||
console.error('Too much reserve to add')
|
console.error('Too much reserve to add')
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
await super.approve(account, dtAddress, poolAddress, this.web3.utils.toWei(amount))
|
const txid = await super.approve(
|
||||||
|
account,
|
||||||
|
dtAddress,
|
||||||
|
poolAddress,
|
||||||
|
this.web3.utils.toWei(amount)
|
||||||
|
)
|
||||||
|
if (!txid) {
|
||||||
|
console.error('DT approve failed')
|
||||||
|
return null
|
||||||
|
}
|
||||||
const result = await super.joinswapExternAmountIn(
|
const result = await super.joinswapExternAmountIn(
|
||||||
account,
|
account,
|
||||||
poolAddress,
|
poolAddress,
|
||||||
@ -628,12 +664,16 @@ export class OceanPool extends Pool {
|
|||||||
console.error('Too much reserve to add')
|
console.error('Too much reserve to add')
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
await super.approve(
|
const txid = await super.approve(
|
||||||
account,
|
account,
|
||||||
this.oceanAddress,
|
this.oceanAddress,
|
||||||
poolAddress,
|
poolAddress,
|
||||||
this.web3.utils.toWei(amount)
|
this.web3.utils.toWei(amount)
|
||||||
)
|
)
|
||||||
|
if (!txid) {
|
||||||
|
console.error('OCEAN approve failed')
|
||||||
|
return null
|
||||||
|
}
|
||||||
const result = await super.joinswapExternAmountIn(
|
const result = await super.joinswapExternAmountIn(
|
||||||
account,
|
account,
|
||||||
poolAddress,
|
poolAddress,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user