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

add ocean.pool.totalSupply() #218

Merged
merged 4 commits into from
Aug 20, 2020
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
37 changes: 28 additions & 9 deletions src/balancer/Pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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 {
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 {
result = this.web3.utils.fromWei(
await token.methods
.balanceOf(account)
.call({ from: account, gas: this.GASLIMIT_DEFAULT })
)
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)
}
Expand Down
4 changes: 4 additions & 0 deletions test/unit/balancer/Balancer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down