mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
wip check allowance for dt and ocean at pool creation
This commit is contained in:
parent
db03bd3f77
commit
a5a55b19a1
@ -118,8 +118,11 @@ export class OceanPool extends Pool {
|
|||||||
const address = createTxid.events.BPoolRegistered.returnValues[0]
|
const address = createTxid.events.BPoolRegistered.returnValues[0]
|
||||||
const oceanWeight = 10 - parseFloat(dtWeight)
|
const oceanWeight = 10 - parseFloat(dtWeight)
|
||||||
this.dtAddress = dtAddress
|
this.dtAddress = dtAddress
|
||||||
observer.next(PoolCreateProgressStep.ApprovingDatatoken)
|
|
||||||
let txid
|
let txid
|
||||||
|
let dtAllowance
|
||||||
|
dtAllowance = await this.allowance(dtAddress, account, address)
|
||||||
|
if (dtAllowance < dtAmount){
|
||||||
|
observer.next(PoolCreateProgressStep.ApprovingDatatoken)
|
||||||
txid = await this.approve(
|
txid = await this.approve(
|
||||||
account,
|
account,
|
||||||
dtAddress,
|
dtAddress,
|
||||||
@ -130,6 +133,10 @@ export class OceanPool extends Pool {
|
|||||||
this.logger.error('ERROR: Failed to call approve DT token')
|
this.logger.error('ERROR: Failed to call approve DT token')
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
let oceanAllowance
|
||||||
|
oceanAllowance = await this.allowance(dtAddress, account, address)
|
||||||
|
if (oceanAllowance < oceanAmount){
|
||||||
observer.next(PoolCreateProgressStep.ApprovingOcean)
|
observer.next(PoolCreateProgressStep.ApprovingOcean)
|
||||||
txid = await this.approve(
|
txid = await this.approve(
|
||||||
account,
|
account,
|
||||||
@ -141,6 +148,7 @@ export class OceanPool extends Pool {
|
|||||||
this.logger.error('ERROR: Failed to call approve OCEAN token')
|
this.logger.error('ERROR: Failed to call approve OCEAN token')
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
}
|
||||||
observer.next(PoolCreateProgressStep.SetupPool)
|
observer.next(PoolCreateProgressStep.SetupPool)
|
||||||
txid = await super.setup(
|
txid = await super.setup(
|
||||||
account,
|
account,
|
||||||
|
@ -4,6 +4,7 @@ import { TransactionReceipt } from 'web3-core'
|
|||||||
import { Logger, getFairGasPrice } from '../utils'
|
import { Logger, getFairGasPrice } from '../utils'
|
||||||
import BigNumber from 'bignumber.js'
|
import BigNumber from 'bignumber.js'
|
||||||
import jsonpoolABI from '@oceanprotocol/contracts/artifacts/BPool.json'
|
import jsonpoolABI from '@oceanprotocol/contracts/artifacts/BPool.json'
|
||||||
|
import defaultDatatokensABI from '@oceanprotocol/contracts/artifacts/DataTokenTemplate.json'
|
||||||
import { PoolFactory } from './PoolFactory'
|
import { PoolFactory } from './PoolFactory'
|
||||||
|
|
||||||
const MaxUint256 =
|
const MaxUint256 =
|
||||||
@ -107,6 +108,25 @@ export class Pool extends PoolFactory {
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Alloance for both DataToken and Ocean
|
||||||
|
* @param {String } tokenAdress
|
||||||
|
* @param {String} owner
|
||||||
|
* @param {String} spender
|
||||||
|
*/
|
||||||
|
public async allowance(
|
||||||
|
tokenAdress: string,
|
||||||
|
owner: string,
|
||||||
|
spender: string
|
||||||
|
): Promise<string> {
|
||||||
|
const tokenAbi = (defaultDatatokensABI.abi as AbiItem[])
|
||||||
|
const datatoken = new this.web3.eth.Contract(tokenAbi, tokenAdress, {
|
||||||
|
from: spender
|
||||||
|
})
|
||||||
|
const trxReceipt = await datatoken.methods.allowance(owner, spender).call()
|
||||||
|
return this.web3.utils.fromWei(trxReceipt)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Approve spender to spent amount tokens
|
* Approve spender to spent amount tokens
|
||||||
* @param {String} account
|
* @param {String} account
|
||||||
|
Loading…
x
Reference in New Issue
Block a user