mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
Merge pull request #218 from oceanprotocol/feature/totalsupply
add ocean.pool.totalSupply()
This commit is contained in:
commit
b50ec110a1
@ -89,7 +89,7 @@ export class Pool extends PoolFactory {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Pool shares
|
||||
* Get user shares of pool tokens
|
||||
* @param {String} account
|
||||
* @param {String} poolAddress
|
||||
* @return {String}
|
||||
@ -116,16 +116,35 @@ export class Pool extends PoolFactory {
|
||||
type: 'function'
|
||||
}
|
||||
] as AbiItem[]
|
||||
const token = new this.web3.eth.Contract(minABI, poolAddress, {
|
||||
from: account
|
||||
})
|
||||
|
||||
let result = null
|
||||
|
||||
try {
|
||||
result = this.web3.utils.fromWei(
|
||||
await token.methods
|
||||
.balanceOf(account)
|
||||
.call({ from: account, gas: this.GASLIMIT_DEFAULT })
|
||||
)
|
||||
const token = new this.web3.eth.Contract(minABI, poolAddress, {
|
||||
from: account
|
||||
})
|
||||
const balance = await token.methods
|
||||
.balanceOf(account)
|
||||
.call({ from: account, gas: this.GASLIMIT_DEFAULT })
|
||||
result = this.web3.utils.fromWei(balance)
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Get total supply of pool tokens
|
||||
* @param {String} poolAddress
|
||||
* @return {String}
|
||||
*/
|
||||
async totalSupply(poolAddress: string): Promise<string> {
|
||||
let result = null
|
||||
|
||||
try {
|
||||
const pool = new this.web3.eth.Contract(this.poolABI, poolAddress)
|
||||
const totalSupply = await pool.methods.totalSupply().call()
|
||||
result = this.web3.utils.fromWei(totalSupply)
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
|
@ -133,6 +133,10 @@ describe('Balancer flow', () => {
|
||||
const currentOceanReserve = await Pool.getOceanReserve(alice, alicePoolAddress)
|
||||
assert(currentOceanReserve > 0)
|
||||
})
|
||||
it('Get total supply of pool tokens', async () => {
|
||||
const totalSupply = await Pool.totalSupply(alicePoolAddress)
|
||||
assert(totalSupply > 0)
|
||||
})
|
||||
it('Get amount of Ocean needed to buy 1 dtToken', async () => {
|
||||
const requiredOcean = await Pool.getOceanNeeded(alice, alicePoolAddress, '1')
|
||||
assert(requiredOcean > 0)
|
||||
|
Loading…
x
Reference in New Issue
Block a user