1
0
mirror of https://github.com/oceanprotocol/ocean.js.git synced 2024-11-26 20:39:05 +01:00
This commit is contained in:
Matthias Kretschmann 2020-10-14 17:39:58 +02:00
parent 452b0b6b78
commit 8ee1172d21
Signed by: m
GPG Key ID: 606EEEF3C479A91F

View File

@ -390,28 +390,31 @@ export class OceanPool extends Pool {
}
/**
* Returns datatoken & Ocean amounts received after spending poolShares
* @param poolAddress
* @param poolShares
* Returns Datatoken & Ocean amounts received after spending poolShares
* @param {String} poolAddress
* @param {String} poolShares
* @return {TokensReceived}
*/
public async getTokensRemovedforPoolShares(
poolAddress: string,
poolShares: string
): Promise<TokensReceived> {
const amounts = { dtAmount: '0', oceanAmount: '0' }
try {
const totalPoolTokens = await this.getPoolSharesTotalSupply(poolAddress)
amounts.dtAmount = String(
(Number(poolShares) / Number(totalPoolTokens)) *
Number(await this.getDTReserve(poolAddress))
)
amounts.oceanAmount = String(
(Number(poolShares) / Number(totalPoolTokens)) *
Number(await this.getOceanReserve(poolAddress))
)
} catch (e) {}
return amounts
const dtReserve = await this.getDTReserve(poolAddress)
const oceanReserve = await this.getOceanReserve(poolAddress)
const dtAmount = `${
(Number(poolShares) / Number(totalPoolTokens)) * Number(dtReserve)
}`
const oceanAmount = `${
(Number(poolShares) / Number(totalPoolTokens)) * Number(oceanReserve)
}`
return { dtAmount, oceanAmount }
} catch (e) {
console.error(`ERROR: Unable to get token info. ${e.message}`)
}
}
/**