1
0
mirror of https://github.com/oceanprotocol/ocean.js.git synced 2024-11-26 20:39:05 +01:00

Merge pull request #323 from oceanprotocol/feature/contracts_050

Feature/contracts 0.5.0 & account removed where possible
This commit is contained in:
Alex Coseru 2020-10-01 11:52:55 +03:00 committed by GitHub
commit 42cb8e358b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 79 additions and 150 deletions

View File

@ -23,6 +23,7 @@ before_script:
- export ADDRESS_FILE="${HOME}/.ocean/ocean-contracts/artifacts/address.json" - export ADDRESS_FILE="${HOME}/.ocean/ocean-contracts/artifacts/address.json"
- export AQUARIUS_URI="http://172.15.0.5:5000" - export AQUARIUS_URI="http://172.15.0.5:5000"
- export DEPLOY_CONTRACTS=true - export DEPLOY_CONTRACTS=true
- export CONTRACTS_VERSION=v0.5.0
- bash -x start_ocean.sh --no-dashboard 2>&1 > start_ocean.log & - bash -x start_ocean.sh --no-dashboard 2>&1 > start_ocean.log &
- cd .. - cd ..
- ./scripts/waitforcontracts.sh - ./scripts/waitforcontracts.sh

6
package-lock.json generated
View File

@ -939,9 +939,9 @@
} }
}, },
"@oceanprotocol/contracts": { "@oceanprotocol/contracts": {
"version": "0.4.4", "version": "0.5.0",
"resolved": "https://registry.npmjs.org/@oceanprotocol/contracts/-/contracts-0.4.4.tgz", "resolved": "https://registry.npmjs.org/@oceanprotocol/contracts/-/contracts-0.5.0.tgz",
"integrity": "sha512-0+Tp6UdoDTBJZp4yX3kkSrV+CcOS/hJ3SJ4HuWiL5FE5Nlj3JCeV86iuWPkFuXzIdgri00DaGvQhP58knzJ2Uw==" "integrity": "sha512-6HQVP/Dvbh5b+wdu0rBR78pDwH4I+KeVaK80U5q47R/CvuSin5VpGSii3ZiCLY+O6JRxzjAMzCYo9ugL1cXvbg=="
}, },
"@octokit/auth-token": { "@octokit/auth-token": {
"version": "2.4.2", "version": "2.4.2",

View File

@ -42,7 +42,7 @@
}, },
"dependencies": { "dependencies": {
"@ethereum-navigator/navigator": "^0.5.0", "@ethereum-navigator/navigator": "^0.5.0",
"@oceanprotocol/contracts": "^0.4.4", "@oceanprotocol/contracts": "^0.5.0",
"decimal.js": "^10.2.0", "decimal.js": "^10.2.0",
"fs": "0.0.1-security", "fs": "0.0.1-security",
"lzma": "^2.3.2", "lzma": "^2.3.2",

View File

@ -118,27 +118,25 @@ export class OceanPool extends Pool {
/** /**
* Get Ocean Token balance of a pool * Get Ocean Token balance of a pool
* @param {String} account
* @param {String} poolAddress * @param {String} poolAddress
* @return {String} * @return {String}
*/ */
public async getOceanReserve(account: string, poolAddress: string): Promise<string> { public async getOceanReserve(poolAddress: string): Promise<string> {
if (this.oceanAddress == null) { if (this.oceanAddress == null) {
console.error('oceanAddress is not defined') console.error('oceanAddress is not defined')
return null return null
} }
return super.getReserve(account, poolAddress, this.oceanAddress) return super.getReserve(poolAddress, this.oceanAddress)
} }
/** /**
* Get Data Token balance of a pool * Get Data Token balance of a pool
* @param {String} account
* @param {String} poolAddress * @param {String} poolAddress
* @return {String} * @return {String}
*/ */
public async getDTReserve(account: string, poolAddress: string): Promise<string> { public async getDTReserve(poolAddress: string): Promise<string> {
await this.getDTAddress(poolAddress) await this.getDTAddress(poolAddress)
return super.getReserve(account, poolAddress, this.dtAddress) return super.getReserve(poolAddress, this.dtAddress)
} }
/** /**
@ -328,29 +326,25 @@ export class OceanPool extends Pool {
/** /**
* Get Data Token price from pool * Get Data Token price from pool
* @param {String} account
* @param {String} poolAddress * @param {String} poolAddress
* @return {String} * @return {String}
*/ */
public async getDTPrice(account: string, poolAddress: string): Promise<string> { public async getDTPrice(poolAddress: string): Promise<string> {
if (this.oceanAddress == null) { if (this.oceanAddress == null) {
console.error('oceanAddress is not defined') console.error('oceanAddress is not defined')
return null return null
} }
return this.getOceanNeeded(account, poolAddress, '1') return this.getOceanNeeded(poolAddress, '1')
} }
/** /**
* Search all pools that have Data Token in their composition * Search all pools that have Data Token in their composition
* @param {String} account
* @param {String} dtAddress * @param {String} dtAddress
* @return {String[]} * @return {String[]}
*/ */
public async searchPoolforDT(account: string, dtAddress: string): Promise<string[]> { public async searchPoolforDT(dtAddress: string): Promise<string[]> {
const result: string[] = [] const result: string[] = []
const factory = new this.web3.eth.Contract(this.factoryABI, this.factoryAddress, { const factory = new this.web3.eth.Contract(this.factoryABI, this.factoryAddress)
from: account
})
const events = await factory.getPastEvents('BPoolRegistered', { const events = await factory.getPastEvents('BPoolRegistered', {
filter: {}, filter: {},
fromBlock: 0, fromBlock: 0,
@ -363,25 +357,13 @@ export class OceanPool extends Pool {
return result return result
} }
public async getOceanNeeded( public async getOceanNeeded(poolAddress: string, dtRequired: string): Promise<string> {
account: string,
poolAddress: string,
dtRequired: string
): Promise<string> {
await this.getDTAddress(poolAddress) await this.getDTAddress(poolAddress)
const tokenBalanceIn = await this.getReserve(account, poolAddress, this.oceanAddress) const tokenBalanceIn = await this.getReserve(poolAddress, this.oceanAddress)
const tokenWeightIn = await this.getDenormalizedWeight( const tokenWeightIn = await this.getDenormalizedWeight(poolAddress, this.oceanAddress)
account, const tokenBalanceOut = await this.getReserve(poolAddress, this.dtAddress)
poolAddress, const tokenWeightOut = await this.getDenormalizedWeight(poolAddress, this.dtAddress)
this.oceanAddress const swapFee = await this.getSwapFee(poolAddress)
)
const tokenBalanceOut = await this.getReserve(account, poolAddress, this.dtAddress)
const tokenWeightOut = await this.getDenormalizedWeight(
account,
poolAddress,
this.dtAddress
)
const swapFee = await this.getSwapFee(account, poolAddress)
return super.calcInGivenOut( return super.calcInGivenOut(
tokenBalanceIn, tokenBalanceIn,
tokenWeightIn, tokenWeightIn,
@ -428,7 +410,7 @@ export class OceanPool extends Pool {
/** /**
* Get all actions from a pool (join,exit,swap) * Get all actions from a pool (join,exit,swap)
* @param {String} poolAddress Pool address * @param {String} poolAddress Pool address
* @param {String} account * @param {String} account Optional, filter for this address
* @return {PoolTransaction[]} * @return {PoolTransaction[]}
*/ */
public async getPoolLogs( public async getPoolLogs(

View File

@ -256,14 +256,11 @@ export class Pool extends PoolFactory {
/** /**
* Get number of tokens composing this pool * Get number of tokens composing this pool
* @param {String} account
* @param {String} poolAddress * @param {String} poolAddress
* @return {String} * @return {String}
*/ */
async getNumTokens(account: string, poolAddress: string): Promise<string> { async getNumTokens(poolAddress: string): Promise<string> {
const pool = new this.web3.eth.Contract(this.poolABI, poolAddress, { const pool = new this.web3.eth.Contract(this.poolABI, poolAddress)
from: account
})
let result = null let result = null
try { try {
result = await pool.methods.getNumTokens().call() result = await pool.methods.getNumTokens().call()
@ -307,14 +304,11 @@ export class Pool extends PoolFactory {
/** /**
* Get controller address of this pool * Get controller address of this pool
* @param {String} account
* @param {String} poolAddress * @param {String} poolAddress
* @return {String} * @return {String}
*/ */
async getController(account: string, poolAddress: string): Promise<string> { async getController(poolAddress: string): Promise<string> {
const pool = new this.web3.eth.Contract(this.poolABI, poolAddress, { const pool = new this.web3.eth.Contract(this.poolABI, poolAddress)
from: account
})
let result = null let result = null
try { try {
result = await pool.methods.getController().call() result = await pool.methods.getController().call()
@ -352,15 +346,12 @@ export class Pool extends PoolFactory {
/** /**
* Get if a token is bounded to a pool * Get if a token is bounded to a pool
* @param {String} account
* @param {String} poolAddress * @param {String} poolAddress
* @param {String} token Address of the token * @param {String} token Address of the token
* @return {Boolean} * @return {Boolean}
*/ */
async isBound(account: string, poolAddress: string, token: string): Promise<boolean> { async isBound(poolAddress: string, token: string): Promise<boolean> {
const pool = new this.web3.eth.Contract(this.poolABI, poolAddress, { const pool = new this.web3.eth.Contract(this.poolABI, poolAddress)
from: account
})
let result = null let result = null
try { try {
result = await pool.methods.isBound(token).call() result = await pool.methods.isBound(token).call()
@ -372,15 +363,12 @@ export class Pool extends PoolFactory {
/** /**
* Get how many tokens are in the pool * Get how many tokens are in the pool
* @param {String} account
* @param {String} poolAddress * @param {String} poolAddress
* @param {String} token Address of the token * @param {String} token Address of the token
* @return {String} * @return {String}
*/ */
async getReserve(account: string, poolAddress: string, token: string): Promise<string> { async getReserve(poolAddress: string, token: string): Promise<string> {
const pool = new this.web3.eth.Contract(this.poolABI, poolAddress, { const pool = new this.web3.eth.Contract(this.poolABI, poolAddress)
from: account
})
let amount = null let amount = null
try { try {
const result = await pool.methods.getBalance(token).call() const result = await pool.methods.getBalance(token).call()
@ -393,14 +381,11 @@ export class Pool extends PoolFactory {
/** /**
* Get if a pool is finalized * Get if a pool is finalized
* @param {String} account
* @param {String} poolAddress * @param {String} poolAddress
* @return {Boolean} * @return {Boolean}
*/ */
async isFinalized(account: string, poolAddress: string): Promise<boolean> { async isFinalized(poolAddress: string): Promise<boolean> {
const pool = new this.web3.eth.Contract(this.poolABI, poolAddress, { const pool = new this.web3.eth.Contract(this.poolABI, poolAddress)
from: account
})
let result = null let result = null
try { try {
result = await pool.methods.isFinalized().call() result = await pool.methods.isFinalized().call()
@ -412,14 +397,11 @@ export class Pool extends PoolFactory {
/** /**
* Get pool fee * Get pool fee
* @param {String} account
* @param {String} poolAddress * @param {String} poolAddress
* @return {String} Swap fee in wei * @return {String} Swap fee in wei
*/ */
async getSwapFee(account: string, poolAddress: string): Promise<string> { async getSwapFee(poolAddress: string): Promise<string> {
const pool = new this.web3.eth.Contract(this.poolABI, poolAddress, { const pool = new this.web3.eth.Contract(this.poolABI, poolAddress)
from: account
})
let fee = null let fee = null
try { try {
const result = await pool.methods.getSwapFee().call() const result = await pool.methods.getSwapFee().call()
@ -432,19 +414,12 @@ export class Pool extends PoolFactory {
/** /**
* The normalized weight of a token. The combined normalized weights of all tokens will sum up to 1. (Note: the actual sum may be 1 plus or minus a few wei due to division precision loss) * The normalized weight of a token. The combined normalized weights of all tokens will sum up to 1. (Note: the actual sum may be 1 plus or minus a few wei due to division precision loss)
* @param {String} account
* @param {String} poolAddress * @param {String} poolAddress
* @param {String} token * @param {String} token
* @return {String} * @return {String}
*/ */
async getNormalizedWeight( async getNormalizedWeight(poolAddress: string, token: string): Promise<string> {
account: string, const pool = new this.web3.eth.Contract(this.poolABI, poolAddress)
poolAddress: string,
token: string
): Promise<string> {
const pool = new this.web3.eth.Contract(this.poolABI, poolAddress, {
from: account
})
let weight = null let weight = null
try { try {
const result = await pool.methods.getNormalizedWeight(token).call() const result = await pool.methods.getNormalizedWeight(token).call()
@ -457,19 +432,12 @@ export class Pool extends PoolFactory {
/** /**
* getDenormalizedWeight of a token in pool * getDenormalizedWeight of a token in pool
* @param {String} account
* @param {String} poolAddress * @param {String} poolAddress
* @param {String} token * @param {String} token
* @return {String} * @return {String}
*/ */
async getDenormalizedWeight( async getDenormalizedWeight(poolAddress: string, token: string): Promise<string> {
account: string, const pool = new this.web3.eth.Contract(this.poolABI, poolAddress)
poolAddress: string,
token: string
): Promise<string> {
const pool = new this.web3.eth.Contract(this.poolABI, poolAddress, {
from: account
})
let weight = null let weight = null
try { try {
const result = await pool.methods.getDenormalizedWeight(token).call() const result = await pool.methods.getDenormalizedWeight(token).call()
@ -482,17 +450,11 @@ export class Pool extends PoolFactory {
/** /**
* getTotalDenormalizedWeight in pool * getTotalDenormalizedWeight in pool
* @param {String} account
* @param {String} poolAddress * @param {String} poolAddress
* @return {String} * @return {String}
*/ */
async getTotalDenormalizedWeight( async getTotalDenormalizedWeight(poolAddress: string): Promise<string> {
account: string, const pool = new this.web3.eth.Contract(this.poolABI, poolAddress)
poolAddress: string
): Promise<string> {
const pool = new this.web3.eth.Contract(this.poolABI, poolAddress, {
from: account
})
let weight = null let weight = null
try { try {
const result = await pool.methods.getTotalDenormalizedWeight().call() const result = await pool.methods.getTotalDenormalizedWeight().call()
@ -792,21 +754,17 @@ export class Pool extends PoolFactory {
/** /**
* Get Spot Price of swaping tokenIn to tokenOut * Get Spot Price of swaping tokenIn to tokenOut
* @param {String} account
* @param {String} poolAddress * @param {String} poolAddress
* @param {String} tokenIn * @param {String} tokenIn
* @param {String} tokenOut * @param {String} tokenOut
* @return {String} * @return {String}
*/ */
async getSpotPrice( async getSpotPrice(
account: string,
poolAddress: string, poolAddress: string,
tokenIn: string, tokenIn: string,
tokenOut: string tokenOut: string
): Promise<string> { ): Promise<string> {
const pool = new this.web3.eth.Contract(this.poolABI, poolAddress, { const pool = new this.web3.eth.Contract(this.poolABI, poolAddress)
from: account
})
let price = null let price = null
try { try {
const result = await pool.methods.getSpotPrice(tokenIn, tokenOut).call() const result = await pool.methods.getSpotPrice(tokenIn, tokenOut).call()
@ -819,21 +777,17 @@ export class Pool extends PoolFactory {
/** /**
* Get Spot Price of swaping tokenIn to tokenOut without fees * Get Spot Price of swaping tokenIn to tokenOut without fees
* @param {String} account
* @param {String} poolAddress * @param {String} poolAddress
* @param {String} tokenIn * @param {String} tokenIn
* @param {String} tokenOut * @param {String} tokenOut
* @return {String} * @return {String}
*/ */
async getSpotPriceSansFee( async getSpotPriceSansFee(
account: string,
poolAddress: string, poolAddress: string,
tokenIn: string, tokenIn: string,
tokenOut: string tokenOut: string
): Promise<string> { ): Promise<string> {
const pool = new this.web3.eth.Contract(this.poolABI, poolAddress, { const pool = new this.web3.eth.Contract(this.poolABI, poolAddress)
from: account
})
let price = null let price = null
try { try {
const result = await pool.methods.getSpotPriceSansFee(tokenIn, tokenOut).call() const result = await pool.methods.getSpotPriceSansFee(tokenIn, tokenOut).call()

View File

@ -287,52 +287,40 @@ export class DataTokens {
/** Get Blob /** Get Blob
* @param {String} dataTokenAddress * @param {String} dataTokenAddress
* @param {String} address
* @return {Promise<string>} string * @return {Promise<string>} string
*/ */
public async getBlob(dataTokenAddress: string, address: string): Promise<string> { public async getBlob(dataTokenAddress: string): Promise<string> {
const datatoken = new this.web3.eth.Contract(this.datatokensABI, dataTokenAddress, { const datatoken = new this.web3.eth.Contract(this.datatokensABI, dataTokenAddress)
from: address
})
const trxReceipt = await datatoken.methods.blob().call() const trxReceipt = await datatoken.methods.blob().call()
return trxReceipt return trxReceipt
} }
/** Get Name /** Get Name
* @param {String} dataTokenAddress * @param {String} dataTokenAddress
* @param {String} address
* @return {Promise<string>} string * @return {Promise<string>} string
*/ */
public async getName(dataTokenAddress: string, address: string): Promise<string> { public async getName(dataTokenAddress: string): Promise<string> {
const datatoken = new this.web3.eth.Contract(this.datatokensABI, dataTokenAddress, { const datatoken = new this.web3.eth.Contract(this.datatokensABI, dataTokenAddress)
from: address
})
const trxReceipt = await datatoken.methods.name().call() const trxReceipt = await datatoken.methods.name().call()
return trxReceipt return trxReceipt
} }
/** Get Symbol /** Get Symbol
* @param {String} dataTokenAddress * @param {String} dataTokenAddress
* @param {String} address
* @return {Promise<string>} string * @return {Promise<string>} string
*/ */
public async getSymbol(dataTokenAddress: string, address: string): Promise<string> { public async getSymbol(dataTokenAddress: string): Promise<string> {
const datatoken = new this.web3.eth.Contract(this.datatokensABI, dataTokenAddress, { const datatoken = new this.web3.eth.Contract(this.datatokensABI, dataTokenAddress)
from: address
})
const trxReceipt = await datatoken.methods.symbol().call() const trxReceipt = await datatoken.methods.symbol().call()
return trxReceipt return trxReceipt
} }
/** Get Cap /** Get Cap
* @param {String} dataTokenAddress * @param {String} dataTokenAddress
* @param {String} address
* @return {Promise<string>} string * @return {Promise<string>} string
*/ */
public async getCap(dataTokenAddress: string, address: string): Promise<string> { public async getCap(dataTokenAddress: string): Promise<string> {
const datatoken = new this.web3.eth.Contract(this.datatokensABI, dataTokenAddress, { const datatoken = new this.web3.eth.Contract(this.datatokensABI, dataTokenAddress)
from: address
})
const trxReceipt = await datatoken.methods.cap().call() const trxReceipt = await datatoken.methods.cap().call()
return this.web3.utils.fromWei(trxReceipt) return this.web3.utils.fromWei(trxReceipt)
} }

View File

@ -205,10 +205,13 @@ export class OceanFixedRateExchange {
exchangeId: string, exchangeId: string,
address: string address: string
): Promise<TransactionReceipt> { ): Promise<TransactionReceipt> {
const exchange = await this.getExchange(exchangeId)
if (!exchange) return null
if (exchange.active === true) return null
let estGas let estGas
try { try {
estGas = await this.contract.methods estGas = await this.contract.methods
.activate(exchangeId) .toggleExchangeState(exchangeId)
.estimateGas(function (err, estGas) { .estimateGas(function (err, estGas) {
if (err) { if (err) {
// console.log('FixedPriceExchange: ' + err) // console.log('FixedPriceExchange: ' + err)
@ -219,7 +222,7 @@ export class OceanFixedRateExchange {
} catch (e) { } catch (e) {
estGas = DEFAULT_GAS_LIMIT estGas = DEFAULT_GAS_LIMIT
} }
const trxReceipt = await this.contract.methods.activate(exchangeId).send({ const trxReceipt = await this.contract.methods.toggleExchangeState(exchangeId).send({
from: address, from: address,
gas: estGas + 1 gas: estGas + 1
}) })
@ -236,10 +239,13 @@ export class OceanFixedRateExchange {
exchangeId: string, exchangeId: string,
address: string address: string
): Promise<TransactionReceipt> { ): Promise<TransactionReceipt> {
const exchange = await this.getExchange(exchangeId)
if (!exchange) return null
if (exchange.active === false) return null
let estGas let estGas
try { try {
estGas = await this.contract.methods estGas = await this.contract.methods
.deactivate(exchangeId) .toggleExchangeState(exchangeId)
.estimateGas(function (err, estGas) { .estimateGas(function (err, estGas) {
if (err) { if (err) {
// console.log('FixedPriceExchange: ' + err) // console.log('FixedPriceExchange: ' + err)
@ -250,7 +256,7 @@ export class OceanFixedRateExchange {
} catch (e) { } catch (e) {
estGas = DEFAULT_GAS_LIMIT estGas = DEFAULT_GAS_LIMIT
} }
const trxReceipt = await this.contract.methods.deactivate(exchangeId).send({ const trxReceipt = await this.contract.methods.toggleExchangeState(exchangeId).send({
from: address, from: address,
gas: estGas + 1 gas: estGas + 1
}) })

View File

@ -32,13 +32,13 @@ const configs: ConfigHelperConfig[] = [
chainId: 4, chainId: 4,
network: 'rinkeby', network: 'rinkeby',
nodeUri: 'https://rinkeby.infura.io/v3', nodeUri: 'https://rinkeby.infura.io/v3',
factoryAddress: '0x732cad3502e2A543118C8047D6bb20D5DB9c3242', factoryAddress: '0xA7a711A09396DF82D9be46A26B48BafdB9BB4fA6',
oceanTokenAddress: '0x8967BCF84170c91B0d24D4302C2376283b0B3a07', oceanTokenAddress: '0x8967BCF84170c91B0d24D4302C2376283b0B3a07',
metadataStoreUri: 'https://aquarius.rinkeby.v3.dev-ocean.com', metadataStoreUri: 'https://aquarius.rinkeby.v3.dev-ocean.com',
providerUri: 'https://provider.rinkeby.v3.dev-ocean.com', providerUri: 'https://provider.rinkeby.v3.dev-ocean.com',
poolFactoryAddress: '0x1735C3A59EcedC617bB570b79A71A6FC7C0380E8', poolFactoryAddress: '0x4658cD157B57E9D0053Bb2d5CbC7B2Aad06dA5E6',
fixedRateExchangeAddress: '0x2B8da1F6DE33EfCDEc254ebE57d1D854a314b81b', fixedRateExchangeAddress: '0x09285F0290D74f01D3287ED9B45d2456956758B4',
metadataContractAddress: '0x01906293EAd697f6038b0E3E1f0591F56ABf8EC0' metadataContractAddress: '0x1da8E04D2ae9b7c32C24e4DB94899b93d8E4751A'
}, },
{ {
chainId: 1, chainId: 1,

View File

@ -52,8 +52,8 @@ describe('DataTokens', () => {
tokenAddress = await datatoken.create(blob, minter) tokenAddress = await datatoken.create(blob, minter)
assert(tokenAddress !== null) assert(tokenAddress !== null)
const tokenName = await datatoken.getName(tokenAddress, minter) const tokenName = await datatoken.getName(tokenAddress)
const tokenSymbol = await datatoken.getSymbol(tokenAddress, minter) const tokenSymbol = await datatoken.getSymbol(tokenAddress)
assert(tokenName !== null || tokenName !== '') assert(tokenName !== null || tokenName !== '')
assert(tokenSymbol !== null || tokenSymbol !== '') assert(tokenSymbol !== null || tokenSymbol !== '')
}) })

View File

@ -118,7 +118,7 @@ describe('Balancer flow', () => {
alicePoolAddress = await Pool.createDTPool(alice, tokenAddress, '45', '9', '0.02') alicePoolAddress = await Pool.createDTPool(alice, tokenAddress, '45', '9', '0.02')
const s = await Pool.totalSupply(alicePoolAddress) const s = await Pool.totalSupply(alicePoolAddress)
assert(String(s) === '100', 'totalSupply does not match: ' + s) assert(String(s) === '100', 'totalSupply does not match: ' + s)
const n = await Pool.getNumTokens(alice, alicePoolAddress) const n = await Pool.getNumTokens(alicePoolAddress)
assert(String(n) === '2', 'unexpected num tokens: ' + n) assert(String(n) === '2', 'unexpected num tokens: ' + n)
}) })
it('Get pool information', async () => { it('Get pool information', async () => {
@ -129,13 +129,12 @@ describe('Balancer flow', () => {
}) })
it('Get pool swap fee', async () => { it('Get pool swap fee', async () => {
const currentSwapFee = await Pool.getSwapFee(alice, alicePoolAddress) const currentSwapFee = await Pool.getSwapFee(alicePoolAddress)
assert(currentSwapFee === '0.02') assert(currentSwapFee === '0.02')
}) })
it('Get spot price for swapping', async () => { it('Get spot price for swapping', async () => {
const spotPrice = await Pool.getSpotPrice( const spotPrice = await Pool.getSpotPrice(
alice,
alicePoolAddress, alicePoolAddress,
tokenAddress, tokenAddress,
oceanTokenAddress oceanTokenAddress
@ -145,7 +144,6 @@ describe('Balancer flow', () => {
it('Get spot price for swapping without fees', async () => { it('Get spot price for swapping without fees', async () => {
const spotPrice = await Pool.getSpotPriceSansFee( const spotPrice = await Pool.getSpotPriceSansFee(
alice,
alicePoolAddress, alicePoolAddress,
tokenAddress, tokenAddress,
oceanTokenAddress oceanTokenAddress
@ -154,15 +152,15 @@ describe('Balancer flow', () => {
}) })
it('Get dtPrice from the pool ', async () => { it('Get dtPrice from the pool ', async () => {
currentDtPrice = await Pool.getDTPrice(alice, alicePoolAddress) currentDtPrice = await Pool.getDTPrice(alicePoolAddress)
assert(Number(currentDtPrice) > 0) assert(Number(currentDtPrice) > 0)
}) })
it('Get dtToken pool reserve ', async () => { it('Get dtToken pool reserve ', async () => {
const currentDtReserve = await Pool.getDTReserve(alice, alicePoolAddress) const currentDtReserve = await Pool.getDTReserve(alicePoolAddress)
assert(Number(currentDtReserve) > 0) assert(Number(currentDtReserve) > 0)
}) })
it('Get Ocean pool reserve ', async () => { it('Get Ocean pool reserve ', async () => {
const currentOceanReserve = await Pool.getOceanReserve(alice, alicePoolAddress) const currentOceanReserve = await Pool.getOceanReserve(alicePoolAddress)
assert(Number(currentOceanReserve) > 0) assert(Number(currentOceanReserve) > 0)
}) })
it('Get total supply of pool tokens', async () => { it('Get total supply of pool tokens', async () => {
@ -170,12 +168,12 @@ describe('Balancer flow', () => {
assert(Number(totalSupply) > 0) assert(Number(totalSupply) > 0)
}) })
it('Get amount of Ocean needed to buy 1 dtToken', async () => { it('Get amount of Ocean needed to buy 1 dtToken', async () => {
const requiredOcean = await Pool.getOceanNeeded(alice, alicePoolAddress, '1') const requiredOcean = await Pool.getOceanNeeded(alicePoolAddress, '1')
assert(Number(requiredOcean) > 0) assert(Number(requiredOcean) > 0)
}) })
it('Bob should search for pools with this DT', async () => { it('Bob should search for pools with this DT', async () => {
const pools = await Pool.searchPoolforDT(bob, tokenAddress) const pools = await Pool.searchPoolforDT(tokenAddress)
assert(pools.length > 0) assert(pools.length > 0)
greatPool = pools[0] greatPool = pools[0]
}) })
@ -188,7 +186,7 @@ describe('Balancer flow', () => {
assert(Number(bobOceanBalance) > 0) assert(Number(bobOceanBalance) > 0)
}) })
it('Bob should add DT liquidity to pool ', async () => { it('Bob should add DT liquidity to pool ', async () => {
const currentDtReserve = await Pool.getDTReserve(bob, greatPool) const currentDtReserve = await Pool.getDTReserve(greatPool)
if (consoleDebug) console.log('currentDtReserve:' + currentDtReserve) if (consoleDebug) console.log('currentDtReserve:' + currentDtReserve)
const bobDtBalance = await datatoken.balance(tokenAddress, bob) const bobDtBalance = await datatoken.balance(tokenAddress, bob)
if (consoleDebug) console.log('BOB DT Balance:' + bobDtBalance) if (consoleDebug) console.log('BOB DT Balance:' + bobDtBalance)
@ -196,7 +194,7 @@ describe('Balancer flow', () => {
const newbobDtBalance = await datatoken.balance(tokenAddress, bob) const newbobDtBalance = await datatoken.balance(tokenAddress, bob)
const newDtReserve = await Pool.getDTReserve(bob, greatPool) const newDtReserve = await Pool.getDTReserve(greatPool)
const sharesBalance = await Pool.sharesBalance(bob, greatPool) const sharesBalance = await Pool.sharesBalance(bob, greatPool)
if (consoleDebug) console.log('newDtReserve:' + newDtReserve) if (consoleDebug) console.log('newDtReserve:' + newDtReserve)
@ -208,7 +206,7 @@ describe('Balancer flow', () => {
}) })
it('Bob should remove DT liquidity from pool ', async () => { it('Bob should remove DT liquidity from pool ', async () => {
const currentDtReserve = await Pool.getDTReserve(bob, greatPool) const currentDtReserve = await Pool.getDTReserve(greatPool)
if (consoleDebug) console.log('currentDtReserve:' + currentDtReserve) if (consoleDebug) console.log('currentDtReserve:' + currentDtReserve)
const bobDtBalance = await datatoken.balance(tokenAddress, bob) const bobDtBalance = await datatoken.balance(tokenAddress, bob)
if (consoleDebug) console.log('bobDtBalance:' + bobDtBalance) if (consoleDebug) console.log('bobDtBalance:' + bobDtBalance)
@ -216,7 +214,7 @@ describe('Balancer flow', () => {
if (consoleDebug) console.log('poolShares:' + poolShares) if (consoleDebug) console.log('poolShares:' + poolShares)
await Pool.removeDTLiquidity(bob, greatPool, '0.75', poolShares) await Pool.removeDTLiquidity(bob, greatPool, '0.75', poolShares)
const newDtReserve = await Pool.getDTReserve(bob, greatPool) const newDtReserve = await Pool.getDTReserve(greatPool)
if (consoleDebug) console.log('newDtReserve:' + newDtReserve) if (consoleDebug) console.log('newDtReserve:' + newDtReserve)
const newbobDtBalance = await datatoken.balance(tokenAddress, bob) const newbobDtBalance = await datatoken.balance(tokenAddress, bob)
if (consoleDebug) console.log('newbobDtBalance:' + newbobDtBalance) if (consoleDebug) console.log('newbobDtBalance:' + newbobDtBalance)
@ -228,7 +226,7 @@ describe('Balancer flow', () => {
}) })
it('Bob should add Ocean liquidity to pool ', async () => { it('Bob should add Ocean liquidity to pool ', async () => {
const currentDtReserve = await Pool.getOceanReserve(bob, greatPool) const currentDtReserve = await Pool.getOceanReserve(greatPool)
const bobDtBalance = await datatoken.balance(oceanTokenAddress, bob) const bobDtBalance = await datatoken.balance(oceanTokenAddress, bob)
if (consoleDebug) console.log('currentDtReserve:' + currentDtReserve) if (consoleDebug) console.log('currentDtReserve:' + currentDtReserve)
if (consoleDebug) console.log('bobDtBalance:' + bobDtBalance) if (consoleDebug) console.log('bobDtBalance:' + bobDtBalance)
@ -237,7 +235,7 @@ describe('Balancer flow', () => {
const newbobDtBalance = await datatoken.balance(oceanTokenAddress, bob) const newbobDtBalance = await datatoken.balance(oceanTokenAddress, bob)
const newDtReserve = await Pool.getOceanReserve(bob, greatPool) const newDtReserve = await Pool.getOceanReserve(greatPool)
const sharesBalance = await Pool.sharesBalance(bob, greatPool) const sharesBalance = await Pool.sharesBalance(bob, greatPool)
if (consoleDebug) console.log('newDtReserve:' + newDtReserve) if (consoleDebug) console.log('newDtReserve:' + newDtReserve)
@ -249,7 +247,7 @@ describe('Balancer flow', () => {
}) })
it('Bob should remove Ocean liquidity from pool ', async () => { it('Bob should remove Ocean liquidity from pool ', async () => {
const currentDtReserve = await Pool.getOceanReserve(bob, greatPool) const currentDtReserve = await Pool.getOceanReserve(greatPool)
const bobDtBalance = await datatoken.balance(oceanTokenAddress, bob) const bobDtBalance = await datatoken.balance(oceanTokenAddress, bob)
const poolShares = await Pool.sharesBalance(bob, greatPool) const poolShares = await Pool.sharesBalance(bob, greatPool)
@ -259,7 +257,7 @@ describe('Balancer flow', () => {
await Pool.removeOceanLiquidity(bob, greatPool, '0.75', poolShares) await Pool.removeOceanLiquidity(bob, greatPool, '0.75', poolShares)
const newDtReserve = await Pool.getOceanReserve(bob, greatPool) const newDtReserve = await Pool.getOceanReserve(greatPool)
const newbobDtBalance = await datatoken.balance(oceanTokenAddress, bob) const newbobDtBalance = await datatoken.balance(oceanTokenAddress, bob)
const newpoolShares = await Pool.sharesBalance(bob, greatPool) const newpoolShares = await Pool.sharesBalance(bob, greatPool)