mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
commit
b8c0a9fe15
@ -4,7 +4,8 @@ import { TransactionReceipt } from 'web3-core'
|
|||||||
import { Pool } from './Pool'
|
import { Pool } from './Pool'
|
||||||
import { EventData, Filter } from 'web3-eth-contract'
|
import { EventData, Filter } from 'web3-eth-contract'
|
||||||
import BigNumber from 'bignumber.js'
|
import BigNumber from 'bignumber.js'
|
||||||
import { SubscribablePromise } from '../utils'
|
import { SubscribablePromise, Logger } from '../utils'
|
||||||
|
|
||||||
declare type PoolTransactionType = 'swap' | 'join' | 'exit'
|
declare type PoolTransactionType = 'swap' | 'join' | 'exit'
|
||||||
|
|
||||||
const POOL_MAX_AMOUNT_IN_LIMIT = 0.25 // maximum 1/4 of the pool reserve
|
const POOL_MAX_AMOUNT_IN_LIMIT = 0.25 // maximum 1/4 of the pool reserve
|
||||||
@ -50,13 +51,14 @@ export class OceanPool extends Pool {
|
|||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
web3: Web3,
|
web3: Web3,
|
||||||
|
logger: Logger,
|
||||||
factoryABI: AbiItem | AbiItem[] = null,
|
factoryABI: AbiItem | AbiItem[] = null,
|
||||||
poolABI: AbiItem | AbiItem[] = null,
|
poolABI: AbiItem | AbiItem[] = null,
|
||||||
factoryAddress: string = null,
|
factoryAddress: string = null,
|
||||||
oceanAddress: string = null,
|
oceanAddress: string = null,
|
||||||
gaslimit?: number
|
gaslimit?: number
|
||||||
) {
|
) {
|
||||||
super(web3, factoryABI, poolABI, factoryAddress, gaslimit)
|
super(web3, logger, factoryABI, poolABI, factoryAddress, gaslimit)
|
||||||
if (oceanAddress) {
|
if (oceanAddress) {
|
||||||
this.oceanAddress = oceanAddress
|
this.oceanAddress = oceanAddress
|
||||||
}
|
}
|
||||||
@ -79,22 +81,22 @@ export class OceanPool extends Pool {
|
|||||||
fee: string
|
fee: string
|
||||||
): SubscribablePromise<PoolCreateProgressStep, TransactionReceipt> {
|
): SubscribablePromise<PoolCreateProgressStep, TransactionReceipt> {
|
||||||
if (this.oceanAddress == null) {
|
if (this.oceanAddress == null) {
|
||||||
console.error('ERROR: oceanAddress is not defined')
|
this.logger.error('ERROR: oceanAddress is not defined')
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
if (parseFloat(fee) > 0.1) {
|
if (parseFloat(fee) > 0.1) {
|
||||||
console.error('ERROR: Swap fee too high. The maximum allowed swapFee is 0.1 (10%).')
|
this.logger.error('ERROR: Swap fee too high. The maximum allowed swapFee is 10%')
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
if (parseFloat(weight) > 9 || parseFloat(weight) < 1) {
|
if (parseFloat(weight) > 9 || parseFloat(weight) < 1) {
|
||||||
console.error('ERROR: Weight out of bounds (min 1, max9)')
|
this.logger.error('ERROR: Weight out of bounds (min 1, max9)')
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
return new SubscribablePromise(async (observer) => {
|
return new SubscribablePromise(async (observer) => {
|
||||||
observer.next(PoolCreateProgressStep.CreatingPool)
|
observer.next(PoolCreateProgressStep.CreatingPool)
|
||||||
const createTxid = await super.createPool(account)
|
const createTxid = await super.createPool(account)
|
||||||
if (!createTxid) {
|
if (!createTxid) {
|
||||||
console.error('ERROR: Failed to call approve DT token')
|
this.logger.error('ERROR: Failed to call approve DT token')
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
const address = createTxid.events.BPoolRegistered.returnValues[0]
|
const address = createTxid.events.BPoolRegistered.returnValues[0]
|
||||||
@ -110,7 +112,7 @@ export class OceanPool extends Pool {
|
|||||||
this.web3.utils.toWei(String(amount))
|
this.web3.utils.toWei(String(amount))
|
||||||
)
|
)
|
||||||
if (!txid) {
|
if (!txid) {
|
||||||
console.error('ERROR: Failed to call approve DT token')
|
this.logger.error('ERROR: Failed to call approve DT token')
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
observer.next(PoolCreateProgressStep.ApprovingOcean)
|
observer.next(PoolCreateProgressStep.ApprovingOcean)
|
||||||
@ -121,7 +123,7 @@ export class OceanPool extends Pool {
|
|||||||
this.web3.utils.toWei(String(oceanAmount))
|
this.web3.utils.toWei(String(oceanAmount))
|
||||||
)
|
)
|
||||||
if (!txid) {
|
if (!txid) {
|
||||||
console.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)
|
||||||
@ -137,7 +139,7 @@ export class OceanPool extends Pool {
|
|||||||
this.web3.utils.toWei(fee)
|
this.web3.utils.toWei(fee)
|
||||||
)
|
)
|
||||||
if (!txid) {
|
if (!txid) {
|
||||||
console.error('ERROR: Failed to create a new pool')
|
this.logger.error('ERROR: Failed to create a new pool')
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
return createTxid
|
return createTxid
|
||||||
@ -169,7 +171,7 @@ export class OceanPool extends Pool {
|
|||||||
*/
|
*/
|
||||||
public async getOceanReserve(poolAddress: string): Promise<string> {
|
public async getOceanReserve(poolAddress: string): Promise<string> {
|
||||||
if (this.oceanAddress == null) {
|
if (this.oceanAddress == null) {
|
||||||
console.error('ERROR: oceanAddress is not defined')
|
this.logger.error('ERROR: oceanAddress is not defined')
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
return super.getReserve(poolAddress, this.oceanAddress)
|
return super.getReserve(poolAddress, this.oceanAddress)
|
||||||
@ -434,7 +436,7 @@ export class OceanPool extends Pool {
|
|||||||
|
|
||||||
return { dtAmount, oceanAmount }
|
return { dtAmount, oceanAmount }
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(`ERROR: Unable to get token info. ${e.message}`)
|
this.logger.error(`ERROR: Unable to get token info. ${e.message}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -529,20 +531,20 @@ export class OceanPool extends Pool {
|
|||||||
maxPrice?: string
|
maxPrice?: string
|
||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
if (this.oceanAddress == null) {
|
if (this.oceanAddress == null) {
|
||||||
console.error('ERROR: undefined ocean token contract address')
|
this.logger.error('ERROR: undefined ocean token contract address')
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
const dtAddress = await this.getDTAddress(poolAddress)
|
const dtAddress = await this.getDTAddress(poolAddress)
|
||||||
if (
|
if (
|
||||||
parseFloat(dtAmountWanted) > parseFloat(await this.getDTMaxBuyQuantity(poolAddress))
|
parseFloat(dtAmountWanted) > parseFloat(await this.getDTMaxBuyQuantity(poolAddress))
|
||||||
) {
|
) {
|
||||||
console.error('ERROR: Buy quantity exceeds quantity allowed')
|
this.logger.error('ERROR: Buy quantity exceeds quantity allowed')
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
const calcInGivenOut = await this.getOceanNeeded(poolAddress, dtAmountWanted)
|
const calcInGivenOut = await this.getOceanNeeded(poolAddress, dtAmountWanted)
|
||||||
|
|
||||||
if (parseFloat(calcInGivenOut) > parseFloat(maxOceanAmount)) {
|
if (parseFloat(calcInGivenOut) > parseFloat(maxOceanAmount)) {
|
||||||
console.error('ERROR: Not enough Ocean Tokens')
|
this.logger.error('ERROR: Not enough Ocean Tokens')
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
// TODO - check balances first
|
// TODO - check balances first
|
||||||
@ -553,7 +555,7 @@ export class OceanPool extends Pool {
|
|||||||
this.web3.utils.toWei(maxOceanAmount)
|
this.web3.utils.toWei(maxOceanAmount)
|
||||||
)
|
)
|
||||||
if (!txid) {
|
if (!txid) {
|
||||||
console.error('ERROR: OCEAN approve failed')
|
this.logger.error('ERROR: OCEAN approve failed')
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
return this.swapExactAmountOut(
|
return this.swapExactAmountOut(
|
||||||
@ -584,7 +586,7 @@ export class OceanPool extends Pool {
|
|||||||
maxPrice?: string
|
maxPrice?: string
|
||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
if (this.oceanAddress == null) {
|
if (this.oceanAddress == null) {
|
||||||
console.error('ERROR: oceanAddress is not defined')
|
this.logger.error('ERROR: oceanAddress is not defined')
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
const dtAddress = await this.getDTAddress(poolAddress)
|
const dtAddress = await this.getDTAddress(poolAddress)
|
||||||
@ -592,13 +594,13 @@ export class OceanPool extends Pool {
|
|||||||
parseFloat(oceanAmountWanted) >
|
parseFloat(oceanAmountWanted) >
|
||||||
parseFloat(await this.getOceanMaxBuyQuantity(poolAddress))
|
parseFloat(await this.getOceanMaxBuyQuantity(poolAddress))
|
||||||
) {
|
) {
|
||||||
console.error('ERROR: Buy quantity exceeds quantity allowed')
|
this.logger.error('ERROR: Buy quantity exceeds quantity allowed')
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
const calcOutGivenIn = await this.getOceanReceived(poolAddress, dtAmount)
|
const calcOutGivenIn = await this.getOceanReceived(poolAddress, dtAmount)
|
||||||
|
|
||||||
if (parseFloat(calcOutGivenIn) < parseFloat(oceanAmountWanted)) {
|
if (parseFloat(calcOutGivenIn) < parseFloat(oceanAmountWanted)) {
|
||||||
console.error('ERROR: Not enough datatokens')
|
this.logger.error('ERROR: Not enough datatokens')
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
const txid = await super.approve(
|
const txid = await super.approve(
|
||||||
@ -608,7 +610,7 @@ export class OceanPool extends Pool {
|
|||||||
this.web3.utils.toWei(dtAmount)
|
this.web3.utils.toWei(dtAmount)
|
||||||
)
|
)
|
||||||
if (!txid) {
|
if (!txid) {
|
||||||
console.error('ERROR: DT approve failed')
|
this.logger.error('ERROR: DT approve failed')
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
return this.swapExactAmountIn(
|
return this.swapExactAmountIn(
|
||||||
@ -637,7 +639,7 @@ export class OceanPool extends Pool {
|
|||||||
const dtAddress = await this.getDTAddress(poolAddress)
|
const dtAddress = await this.getDTAddress(poolAddress)
|
||||||
const maxAmount = await this.getMaxAddLiquidity(poolAddress, dtAddress)
|
const maxAmount = await this.getMaxAddLiquidity(poolAddress, dtAddress)
|
||||||
if (parseFloat(amount) > parseFloat(maxAmount)) {
|
if (parseFloat(amount) > parseFloat(maxAmount)) {
|
||||||
console.error('ERROR: Too much reserve to add')
|
this.logger.error('ERROR: Too much reserve to add')
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
const txid = await super.approve(
|
const txid = await super.approve(
|
||||||
@ -647,7 +649,7 @@ export class OceanPool extends Pool {
|
|||||||
this.web3.utils.toWei(amount)
|
this.web3.utils.toWei(amount)
|
||||||
)
|
)
|
||||||
if (!txid) {
|
if (!txid) {
|
||||||
console.error('ERROR: DT approve failed')
|
this.logger.error('ERROR: DT approve failed')
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
const result = await super.joinswapExternAmountIn(
|
const result = await super.joinswapExternAmountIn(
|
||||||
@ -676,19 +678,19 @@ export class OceanPool extends Pool {
|
|||||||
const dtAddress = await this.getDTAddress(poolAddress)
|
const dtAddress = await this.getDTAddress(poolAddress)
|
||||||
const maxAmount = await this.getDTMaxRemoveLiquidity(poolAddress)
|
const maxAmount = await this.getDTMaxRemoveLiquidity(poolAddress)
|
||||||
if (parseFloat(amount) > parseFloat(maxAmount)) {
|
if (parseFloat(amount) > parseFloat(maxAmount)) {
|
||||||
console.error('ERROR: Too much reserve to remove')
|
this.logger.error('ERROR: Too much reserve to remove')
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
const usershares = await this.sharesBalance(account, poolAddress)
|
const usershares = await this.sharesBalance(account, poolAddress)
|
||||||
if (parseFloat(usershares) < parseFloat(maximumPoolShares)) {
|
if (parseFloat(usershares) < parseFloat(maximumPoolShares)) {
|
||||||
console.error('ERROR: Not enough poolShares')
|
this.logger.error('ERROR: Not enough poolShares')
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
parseFloat(maximumPoolShares) <
|
parseFloat(maximumPoolShares) <
|
||||||
parseFloat(await this.getPoolSharesRequiredToRemoveDT(poolAddress, amount))
|
parseFloat(await this.getPoolSharesRequiredToRemoveDT(poolAddress, amount))
|
||||||
) {
|
) {
|
||||||
console.error('ERROR: Not enough poolShares')
|
this.logger.error('ERROR: Not enough poolShares')
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
return this.exitswapExternAmountOut(
|
return this.exitswapExternAmountOut(
|
||||||
@ -713,12 +715,12 @@ export class OceanPool extends Pool {
|
|||||||
amount: string
|
amount: string
|
||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
if (this.oceanAddress == null) {
|
if (this.oceanAddress == null) {
|
||||||
console.error('ERROR: oceanAddress is not defined')
|
this.logger.error('ERROR: oceanAddress is not defined')
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
const maxAmount = await this.getOceanMaxAddLiquidity(poolAddress)
|
const maxAmount = await this.getOceanMaxAddLiquidity(poolAddress)
|
||||||
if (parseFloat(amount) > parseFloat(maxAmount)) {
|
if (parseFloat(amount) > parseFloat(maxAmount)) {
|
||||||
console.error('ERROR: Too much reserve to add')
|
this.logger.error('ERROR: Too much reserve to add')
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
const txid = await super.approve(
|
const txid = await super.approve(
|
||||||
@ -728,7 +730,7 @@ export class OceanPool extends Pool {
|
|||||||
this.web3.utils.toWei(amount)
|
this.web3.utils.toWei(amount)
|
||||||
)
|
)
|
||||||
if (!txid) {
|
if (!txid) {
|
||||||
console.error('ERROR: OCEAN approve failed')
|
this.logger.error('ERROR: OCEAN approve failed')
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
const result = await super.joinswapExternAmountIn(
|
const result = await super.joinswapExternAmountIn(
|
||||||
@ -755,24 +757,24 @@ export class OceanPool extends Pool {
|
|||||||
maximumPoolShares: string
|
maximumPoolShares: string
|
||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
if (this.oceanAddress == null) {
|
if (this.oceanAddress == null) {
|
||||||
console.error('ERROR: oceanAddress is not defined')
|
this.logger.error('ERROR: oceanAddress is not defined')
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
const maxAmount = await this.getOceanMaxRemoveLiquidity(poolAddress)
|
const maxAmount = await this.getOceanMaxRemoveLiquidity(poolAddress)
|
||||||
if (parseFloat(amount) > parseFloat(maxAmount)) {
|
if (parseFloat(amount) > parseFloat(maxAmount)) {
|
||||||
console.error('ERROR: Too much reserve to remove')
|
this.logger.error('ERROR: Too much reserve to remove')
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
const usershares = await this.sharesBalance(account, poolAddress)
|
const usershares = await this.sharesBalance(account, poolAddress)
|
||||||
if (parseFloat(usershares) < parseFloat(maximumPoolShares)) {
|
if (parseFloat(usershares) < parseFloat(maximumPoolShares)) {
|
||||||
console.error('ERROR: Not enough poolShares')
|
this.logger.error('ERROR: Not enough poolShares')
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
parseFloat(maximumPoolShares) <
|
parseFloat(maximumPoolShares) <
|
||||||
parseFloat(await this.getPoolSharesRequiredToRemoveOcean(poolAddress, amount))
|
parseFloat(await this.getPoolSharesRequiredToRemoveOcean(poolAddress, amount))
|
||||||
) {
|
) {
|
||||||
console.error('ERROR: Not enough poolShares')
|
this.logger.error('ERROR: Not enough poolShares')
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
return super.exitswapExternAmountOut(
|
return super.exitswapExternAmountOut(
|
||||||
@ -802,7 +804,7 @@ export class OceanPool extends Pool {
|
|||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
const usershares = await this.sharesBalance(account, poolAddress)
|
const usershares = await this.sharesBalance(account, poolAddress)
|
||||||
if (parseFloat(usershares) < parseFloat(poolShares)) {
|
if (parseFloat(usershares) < parseFloat(poolShares)) {
|
||||||
console.error('ERROR: Not enough poolShares')
|
this.logger.error('ERROR: Not enough poolShares')
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -816,7 +818,7 @@ export class OceanPool extends Pool {
|
|||||||
*/
|
*/
|
||||||
public async getDTPrice(poolAddress: string): Promise<string> {
|
public async getDTPrice(poolAddress: string): Promise<string> {
|
||||||
if (this.oceanAddress == null) {
|
if (this.oceanAddress == null) {
|
||||||
console.error('ERROR: oceanAddress is not defined')
|
this.logger.error('ERROR: oceanAddress is not defined')
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
return this.getOceanNeeded(poolAddress, '1')
|
return this.getOceanNeeded(poolAddress, '1')
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import Web3 from 'web3'
|
import Web3 from 'web3'
|
||||||
import { AbiItem } from 'web3-utils/types'
|
import { AbiItem } from 'web3-utils/types'
|
||||||
import { TransactionReceipt } from 'web3-core'
|
import { TransactionReceipt } from 'web3-core'
|
||||||
import Decimal from 'decimal.js'
|
import { Logger } 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 { PoolFactory } from './PoolFactory'
|
import { PoolFactory } from './PoolFactory'
|
||||||
@ -23,12 +23,13 @@ export class Pool extends PoolFactory {
|
|||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
web3: Web3,
|
web3: Web3,
|
||||||
|
logger: Logger,
|
||||||
factoryABI: AbiItem | AbiItem[] = null,
|
factoryABI: AbiItem | AbiItem[] = null,
|
||||||
poolABI: AbiItem | AbiItem[] = null,
|
poolABI: AbiItem | AbiItem[] = null,
|
||||||
factoryAddress: string = null,
|
factoryAddress: string = null,
|
||||||
gaslimit?: number
|
gaslimit?: number
|
||||||
) {
|
) {
|
||||||
super(web3, factoryABI, factoryAddress, gaslimit)
|
super(web3, logger, factoryABI, factoryAddress, gaslimit)
|
||||||
if (poolABI) this.poolABI = poolABI
|
if (poolABI) this.poolABI = poolABI
|
||||||
else this.poolABI = jsonpoolABI.abi as AbiItem[]
|
else this.poolABI = jsonpoolABI.abi as AbiItem[]
|
||||||
}
|
}
|
||||||
@ -82,7 +83,7 @@ export class Pool extends PoolFactory {
|
|||||||
)
|
)
|
||||||
.send({ from: account, gas: this.GASLIMIT_DEFAULT })
|
.send({ from: account, gas: this.GASLIMIT_DEFAULT })
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(`ERROR: Failed to setup a pool: ${e.message}`)
|
this.logger.error(`ERROR: Failed to setup a pool: ${e.message}`)
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
@ -134,7 +135,7 @@ export class Pool extends PoolFactory {
|
|||||||
.approve(spender, amount)
|
.approve(spender, amount)
|
||||||
.send({ from: account, gas: this.GASLIMIT_DEFAULT })
|
.send({ from: account, gas: this.GASLIMIT_DEFAULT })
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(`ERRPR: Failed to approve spender to spend tokens : ${e.message}`)
|
this.logger.error(`ERRPR: Failed to approve spender to spend tokens : ${e.message}`)
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
@ -152,7 +153,7 @@ export class Pool extends PoolFactory {
|
|||||||
const balance = await token.methods.balanceOf(account).call()
|
const balance = await token.methods.balanceOf(account).call()
|
||||||
result = this.web3.utils.fromWei(balance)
|
result = this.web3.utils.fromWei(balance)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(`ERROR: Failed to get shares of pool : ${e.message}`)
|
this.logger.error(`ERROR: Failed to get shares of pool : ${e.message}`)
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
@ -190,7 +191,7 @@ export class Pool extends PoolFactory {
|
|||||||
)
|
)
|
||||||
.send({ from: account, gas: this.GASLIMIT_DEFAULT })
|
.send({ from: account, gas: this.GASLIMIT_DEFAULT })
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(`ERROR: Failed to add tokens to pool: ${e.message}`)
|
this.logger.error(`ERROR: Failed to add tokens to pool: ${e.message}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -215,7 +216,7 @@ export class Pool extends PoolFactory {
|
|||||||
.setSwapFee(this.web3.utils.toWei(fee))
|
.setSwapFee(this.web3.utils.toWei(fee))
|
||||||
.send({ from: account, gas: this.GASLIMIT_DEFAULT })
|
.send({ from: account, gas: this.GASLIMIT_DEFAULT })
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(`ERROR: Failed to set pool swap fee: ${e.message}`)
|
this.logger.error(`ERROR: Failed to set pool swap fee: ${e.message}`)
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
@ -235,7 +236,7 @@ export class Pool extends PoolFactory {
|
|||||||
.finalize()
|
.finalize()
|
||||||
.send({ from: account, gas: this.GASLIMIT_DEFAULT })
|
.send({ from: account, gas: this.GASLIMIT_DEFAULT })
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(`ERROR: Failed to finalize pool: ${e.message}`)
|
this.logger.error(`ERROR: Failed to finalize pool: ${e.message}`)
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
@ -251,7 +252,7 @@ export class Pool extends PoolFactory {
|
|||||||
try {
|
try {
|
||||||
result = await pool.methods.getNumTokens().call()
|
result = await pool.methods.getNumTokens().call()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(`ERROR: Failed to get number of tokens: ${e.message}`)
|
this.logger.error(`ERROR: Failed to get number of tokens: ${e.message}`)
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
@ -268,7 +269,7 @@ export class Pool extends PoolFactory {
|
|||||||
const result = await pool.methods.totalSupply().call()
|
const result = await pool.methods.totalSupply().call()
|
||||||
amount = this.web3.utils.fromWei(result)
|
amount = this.web3.utils.fromWei(result)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(`ERROR: Failed to get total supply of pool shares: ${e.message}`)
|
this.logger.error(`ERROR: Failed to get total supply of pool shares: ${e.message}`)
|
||||||
}
|
}
|
||||||
return amount
|
return amount
|
||||||
}
|
}
|
||||||
@ -284,7 +285,7 @@ export class Pool extends PoolFactory {
|
|||||||
try {
|
try {
|
||||||
result = await pool.methods.getCurrentTokens().call()
|
result = await pool.methods.getCurrentTokens().call()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(`ERROR: Failed to get tokens composing this pool: ${e.message}`)
|
this.logger.error(`ERROR: Failed to get tokens composing this pool: ${e.message}`)
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
@ -300,7 +301,7 @@ export class Pool extends PoolFactory {
|
|||||||
try {
|
try {
|
||||||
result = await pool.methods.getFinalTokens().call()
|
result = await pool.methods.getFinalTokens().call()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(`ERROR: Failed to get the final tokens composing this pool`)
|
this.logger.error(`ERROR: Failed to get the final tokens composing this pool`)
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
@ -316,7 +317,7 @@ export class Pool extends PoolFactory {
|
|||||||
try {
|
try {
|
||||||
result = await pool.methods.getController().call()
|
result = await pool.methods.getController().call()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(`ERROR: Failed to get pool controller address: ${e.message}`)
|
this.logger.error(`ERROR: Failed to get pool controller address: ${e.message}`)
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
@ -342,7 +343,7 @@ export class Pool extends PoolFactory {
|
|||||||
.setController(controllerAddress)
|
.setController(controllerAddress)
|
||||||
.send({ from: account, gas: this.GASLIMIT_DEFAULT })
|
.send({ from: account, gas: this.GASLIMIT_DEFAULT })
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(`ERROR: Failed to set pool controller: ${e.message}`)
|
this.logger.error(`ERROR: Failed to set pool controller: ${e.message}`)
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
@ -359,7 +360,8 @@ export class Pool extends PoolFactory {
|
|||||||
try {
|
try {
|
||||||
result = await pool.methods.isBound(token).call()
|
result = await pool.methods.isBound(token).call()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(`ERROR: Failed to check if a token bounded to a pool: ${e.message}`)
|
this.logger.error(`ERROR: Failed to check whether a token \
|
||||||
|
bounded to a pool. ${e.message}`)
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
@ -377,7 +379,8 @@ export class Pool extends PoolFactory {
|
|||||||
const result = await pool.methods.getBalance(token).call()
|
const result = await pool.methods.getBalance(token).call()
|
||||||
amount = this.web3.utils.fromWei(result)
|
amount = this.web3.utils.fromWei(result)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(`ERROR: Failed to get how many tokens are in the pool: ${e.message}`)
|
this.logger.error(`ERROR: Failed to get how many tokens \
|
||||||
|
are in the pool: ${e.message}`)
|
||||||
}
|
}
|
||||||
return amount
|
return amount
|
||||||
}
|
}
|
||||||
@ -393,7 +396,7 @@ export class Pool extends PoolFactory {
|
|||||||
try {
|
try {
|
||||||
result = await pool.methods.isFinalized().call()
|
result = await pool.methods.isFinalized().call()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(`ERROR: Failed to check whether pool is finalized: ${e.message}`)
|
this.logger.error(`ERROR: Failed to check whether pool is finalized: ${e.message}`)
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
@ -410,7 +413,7 @@ export class Pool extends PoolFactory {
|
|||||||
const result = await pool.methods.getSwapFee().call()
|
const result = await pool.methods.getSwapFee().call()
|
||||||
fee = this.web3.utils.fromWei(result)
|
fee = this.web3.utils.fromWei(result)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(`ERROR: Failed to get pool fee: ${e.message}`)
|
this.logger.error(`ERROR: Failed to get pool fee: ${e.message}`)
|
||||||
}
|
}
|
||||||
return fee
|
return fee
|
||||||
}
|
}
|
||||||
@ -428,7 +431,7 @@ export class Pool extends PoolFactory {
|
|||||||
const result = await pool.methods.getNormalizedWeight(token).call()
|
const result = await pool.methods.getNormalizedWeight(token).call()
|
||||||
weight = this.web3.utils.fromWei(result)
|
weight = this.web3.utils.fromWei(result)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(`ERROR: Failed to get normalized weight of a token: ${e.message}`)
|
this.logger.error(`ERROR: Failed to get normalized weight of a token: ${e.message}`)
|
||||||
}
|
}
|
||||||
return weight
|
return weight
|
||||||
}
|
}
|
||||||
@ -446,7 +449,7 @@ export class Pool extends PoolFactory {
|
|||||||
const result = await pool.methods.getDenormalizedWeight(token).call()
|
const result = await pool.methods.getDenormalizedWeight(token).call()
|
||||||
weight = this.web3.utils.fromWei(result)
|
weight = this.web3.utils.fromWei(result)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('ERROR: Failed to get denormalized weight of a token in pool')
|
this.logger.error('ERROR: Failed to get denormalized weight of a token in pool')
|
||||||
}
|
}
|
||||||
return weight
|
return weight
|
||||||
}
|
}
|
||||||
@ -463,7 +466,7 @@ export class Pool extends PoolFactory {
|
|||||||
const result = await pool.methods.getTotalDenormalizedWeight().call()
|
const result = await pool.methods.getTotalDenormalizedWeight().call()
|
||||||
weight = this.web3.utils.fromWei(result)
|
weight = this.web3.utils.fromWei(result)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('ERROR: Failed to get total denormalized weight in pool')
|
this.logger.error('ERROR: Failed to get total denormalized weight in pool')
|
||||||
}
|
}
|
||||||
return weight
|
return weight
|
||||||
}
|
}
|
||||||
@ -503,7 +506,7 @@ export class Pool extends PoolFactory {
|
|||||||
)
|
)
|
||||||
.send({ from: account, gas: this.GASLIMIT_DEFAULT })
|
.send({ from: account, gas: this.GASLIMIT_DEFAULT })
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(`ERROR: Failed to swap exact amount in : ${e.message}`)
|
this.logger.error(`ERROR: Failed to swap exact amount in : ${e.message}`)
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
@ -543,7 +546,7 @@ export class Pool extends PoolFactory {
|
|||||||
)
|
)
|
||||||
.send({ from: account, gas: this.GASLIMIT_DEFAULT })
|
.send({ from: account, gas: this.GASLIMIT_DEFAULT })
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(`ERROR: Failed to swap exact amount out: ${e.message}`)
|
this.logger.error(`ERROR: Failed to swap exact amount out: ${e.message}`)
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
@ -580,7 +583,7 @@ export class Pool extends PoolFactory {
|
|||||||
.joinPool(this.web3.utils.toWei(poolAmountOut), weiMaxAmountsIn)
|
.joinPool(this.web3.utils.toWei(poolAmountOut), weiMaxAmountsIn)
|
||||||
.send({ from: account, gas: this.GASLIMIT_DEFAULT })
|
.send({ from: account, gas: this.GASLIMIT_DEFAULT })
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(`ERROR: Failed to join pool: ${e.message}`)
|
this.logger.error(`ERROR: Failed to join pool: ${e.message}`)
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
@ -614,7 +617,7 @@ export class Pool extends PoolFactory {
|
|||||||
.exitPool(this.web3.utils.toWei(poolAmountIn), weiMinAmountsOut)
|
.exitPool(this.web3.utils.toWei(poolAmountIn), weiMinAmountsOut)
|
||||||
.send({ from: account, gas: this.GASLIMIT_DEFAULT })
|
.send({ from: account, gas: this.GASLIMIT_DEFAULT })
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(`ERROR: Failed to exit pool: ${e.message}`)
|
this.logger.error(`ERROR: Failed to exit pool: ${e.message}`)
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
@ -648,7 +651,8 @@ export class Pool extends PoolFactory {
|
|||||||
)
|
)
|
||||||
.send({ from: account, gas: this.GASLIMIT_DEFAULT })
|
.send({ from: account, gas: this.GASLIMIT_DEFAULT })
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(`ERROR: Failed to pay tokens in order to join the pool: ${e.message}`)
|
this.logger.error(`ERROR: Failed to pay tokens in order to \
|
||||||
|
join the pool: ${e.message}`)
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
@ -682,7 +686,7 @@ export class Pool extends PoolFactory {
|
|||||||
)
|
)
|
||||||
.send({ from: account, gas: this.GASLIMIT_DEFAULT })
|
.send({ from: account, gas: this.GASLIMIT_DEFAULT })
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('ERROR: Failed to join swap pool amount out')
|
this.logger.error('ERROR: Failed to join swap pool amount out')
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
@ -716,7 +720,7 @@ export class Pool extends PoolFactory {
|
|||||||
)
|
)
|
||||||
.send({ from: account, gas: this.GASLIMIT_DEFAULT })
|
.send({ from: account, gas: this.GASLIMIT_DEFAULT })
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(`ERROR: Failed to pay pool shares into the pool: ${e.message}`)
|
this.logger.error(`ERROR: Failed to pay pool shares into the pool: ${e.message}`)
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
@ -750,7 +754,7 @@ export class Pool extends PoolFactory {
|
|||||||
)
|
)
|
||||||
.send({ from: account, gas: this.GASLIMIT_DEFAULT })
|
.send({ from: account, gas: this.GASLIMIT_DEFAULT })
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('ERROR: Failed to exitswapExternAmountOut')
|
this.logger.error('ERROR: Failed to exitswapExternAmountOut')
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
@ -773,7 +777,7 @@ export class Pool extends PoolFactory {
|
|||||||
const result = await pool.methods.getSpotPrice(tokenIn, tokenOut).call()
|
const result = await pool.methods.getSpotPrice(tokenIn, tokenOut).call()
|
||||||
price = this.web3.utils.fromWei(result)
|
price = this.web3.utils.fromWei(result)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('ERROR: Failed to get spot price of swapping tokenIn to tokenOut')
|
this.logger.error('ERROR: Failed to get spot price of swapping tokenIn to tokenOut')
|
||||||
}
|
}
|
||||||
return price
|
return price
|
||||||
}
|
}
|
||||||
@ -796,7 +800,7 @@ export class Pool extends PoolFactory {
|
|||||||
const result = await pool.methods.getSpotPriceSansFee(tokenIn, tokenOut).call()
|
const result = await pool.methods.getSpotPriceSansFee(tokenIn, tokenOut).call()
|
||||||
price = this.web3.utils.fromWei(result)
|
price = this.web3.utils.fromWei(result)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('ERROR: Failed to getSpotPriceSansFee')
|
this.logger.error('ERROR: Failed to getSpotPriceSansFee')
|
||||||
}
|
}
|
||||||
return price
|
return price
|
||||||
}
|
}
|
||||||
@ -826,7 +830,7 @@ export class Pool extends PoolFactory {
|
|||||||
.call()
|
.call()
|
||||||
amount = this.web3.utils.fromWei(result)
|
amount = this.web3.utils.fromWei(result)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('ERROR: Failed to calcInGivenOut')
|
this.logger.error('ERROR: Failed to calcInGivenOut')
|
||||||
}
|
}
|
||||||
return amount
|
return amount
|
||||||
}
|
}
|
||||||
@ -855,7 +859,7 @@ export class Pool extends PoolFactory {
|
|||||||
.call()
|
.call()
|
||||||
amount = this.web3.utils.fromWei(result)
|
amount = this.web3.utils.fromWei(result)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('ERROR: Failed to calcOutGivenIn')
|
this.logger.error('ERROR: Failed to calcOutGivenIn')
|
||||||
}
|
}
|
||||||
return amount
|
return amount
|
||||||
}
|
}
|
||||||
@ -884,7 +888,7 @@ export class Pool extends PoolFactory {
|
|||||||
.call()
|
.call()
|
||||||
amount = this.web3.utils.fromWei(result)
|
amount = this.web3.utils.fromWei(result)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(`ERROR: Failed to calculate PoolOutGivenSingleIn : ${e.message}`)
|
this.logger.error(`ERROR: Failed to calculate PoolOutGivenSingleIn : ${e.message}`)
|
||||||
}
|
}
|
||||||
return amount
|
return amount
|
||||||
}
|
}
|
||||||
@ -913,7 +917,7 @@ export class Pool extends PoolFactory {
|
|||||||
.call()
|
.call()
|
||||||
amount = this.web3.utils.fromWei(result)
|
amount = this.web3.utils.fromWei(result)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(`ERROR: Failed to calculate SingleInGivenPoolOut : ${e.message}`)
|
this.logger.error(`ERROR: Failed to calculate SingleInGivenPoolOut : ${e.message}`)
|
||||||
}
|
}
|
||||||
return amount
|
return amount
|
||||||
}
|
}
|
||||||
@ -942,7 +946,7 @@ export class Pool extends PoolFactory {
|
|||||||
.call()
|
.call()
|
||||||
amount = this.web3.utils.fromWei(result)
|
amount = this.web3.utils.fromWei(result)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(`ERROR: Failed to calculate SingleOutGivenPoolIn : ${e.message}`)
|
this.logger.error(`ERROR: Failed to calculate SingleOutGivenPoolIn : ${e.message}`)
|
||||||
}
|
}
|
||||||
return amount
|
return amount
|
||||||
}
|
}
|
||||||
@ -971,7 +975,7 @@ export class Pool extends PoolFactory {
|
|||||||
.call()
|
.call()
|
||||||
amount = this.web3.utils.fromWei(result)
|
amount = this.web3.utils.fromWei(result)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(`ERROR: Failed to calculate PoolInGivenSingleOut : ${e.message}`)
|
this.logger.error(`ERROR: Failed to calculate PoolInGivenSingleOut : ${e.message}`)
|
||||||
}
|
}
|
||||||
return amount
|
return amount
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import Web3 from 'web3'
|
import Web3 from 'web3'
|
||||||
import { AbiItem } from 'web3-utils/types'
|
import { AbiItem } from 'web3-utils/types'
|
||||||
|
import { Logger } from '../utils'
|
||||||
import jsonFactoryABI from '@oceanprotocol/contracts/artifacts/BFactory.json'
|
import jsonFactoryABI from '@oceanprotocol/contracts/artifacts/BFactory.json'
|
||||||
import { TransactionReceipt } from 'web3-core'
|
import { TransactionReceipt } from 'web3-core'
|
||||||
|
|
||||||
@ -8,9 +9,11 @@ export class PoolFactory {
|
|||||||
public web3: Web3 = null
|
public web3: Web3 = null
|
||||||
public factoryABI: AbiItem | AbiItem[]
|
public factoryABI: AbiItem | AbiItem[]
|
||||||
public factoryAddress: string
|
public factoryAddress: string
|
||||||
|
public logger: Logger
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
web3: Web3,
|
web3: Web3,
|
||||||
|
logger: Logger,
|
||||||
factoryABI: AbiItem | AbiItem[] = null,
|
factoryABI: AbiItem | AbiItem[] = null,
|
||||||
factoryAddress: string = null,
|
factoryAddress: string = null,
|
||||||
gaslimit?: number
|
gaslimit?: number
|
||||||
@ -23,6 +26,7 @@ export class PoolFactory {
|
|||||||
this.factoryAddress = factoryAddress
|
this.factoryAddress = factoryAddress
|
||||||
}
|
}
|
||||||
if (gaslimit) this.GASLIMIT_DEFAULT = gaslimit
|
if (gaslimit) this.GASLIMIT_DEFAULT = gaslimit
|
||||||
|
this.logger = logger
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -30,12 +34,12 @@ export class PoolFactory {
|
|||||||
*/
|
*/
|
||||||
async createPool(account: string): Promise<TransactionReceipt> {
|
async createPool(account: string): Promise<TransactionReceipt> {
|
||||||
if (this.web3 === null) {
|
if (this.web3 === null) {
|
||||||
console.error('ERROR: Web3 object is null')
|
this.logger.error('ERROR: Web3 object is null')
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.factoryAddress === null) {
|
if (this.factoryAddress === null) {
|
||||||
console.error('ERROR: bfactoryAddress is null')
|
this.logger.error('ERROR: bfactoryAddress is null')
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,7 +53,7 @@ export class PoolFactory {
|
|||||||
.send({ from: account, gas: this.GASLIMIT_DEFAULT })
|
.send({ from: account, gas: this.GASLIMIT_DEFAULT })
|
||||||
// pooladdress = transactiondata.events.BPoolRegistered.returnValues[0]
|
// pooladdress = transactiondata.events.BPoolRegistered.returnValues[0]
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(`ERROR: Failed to create new pool: ${e.message}`)
|
this.logger.error(`ERROR: Failed to create new pool: ${e.message}`)
|
||||||
}
|
}
|
||||||
return txid
|
return txid
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ import { AbiItem } from 'web3-utils/types'
|
|||||||
|
|
||||||
import defaultFactoryABI from '@oceanprotocol/contracts/artifacts/DTFactory.json'
|
import defaultFactoryABI from '@oceanprotocol/contracts/artifacts/DTFactory.json'
|
||||||
import defaultDatatokensABI from '@oceanprotocol/contracts/artifacts/DataTokenTemplate.json'
|
import defaultDatatokensABI from '@oceanprotocol/contracts/artifacts/DataTokenTemplate.json'
|
||||||
|
import { Logger } from '../utils'
|
||||||
import wordListDefault from '../data/words.json'
|
import wordListDefault from '../data/words.json'
|
||||||
import { TransactionReceipt } from 'web3-core'
|
import { TransactionReceipt } from 'web3-core'
|
||||||
import BigNumber from 'bignumber.js'
|
import BigNumber from 'bignumber.js'
|
||||||
@ -16,7 +16,7 @@ export class DataTokens {
|
|||||||
public factoryABI: AbiItem | AbiItem[]
|
public factoryABI: AbiItem | AbiItem[]
|
||||||
public datatokensABI: AbiItem | AbiItem[]
|
public datatokensABI: AbiItem | AbiItem[]
|
||||||
public web3: Web3
|
public web3: Web3
|
||||||
|
private logger: Logger
|
||||||
/**
|
/**
|
||||||
* Instantiate DataTokens (independently of Ocean).
|
* Instantiate DataTokens (independently of Ocean).
|
||||||
* @param {String} factoryAddress
|
* @param {String} factoryAddress
|
||||||
@ -28,12 +28,14 @@ export class DataTokens {
|
|||||||
factoryAddress: string,
|
factoryAddress: string,
|
||||||
factoryABI: AbiItem | AbiItem[],
|
factoryABI: AbiItem | AbiItem[],
|
||||||
datatokensABI: AbiItem | AbiItem[],
|
datatokensABI: AbiItem | AbiItem[],
|
||||||
web3: Web3
|
web3: Web3,
|
||||||
|
logger: Logger
|
||||||
) {
|
) {
|
||||||
this.factoryAddress = factoryAddress
|
this.factoryAddress = factoryAddress
|
||||||
this.factoryABI = factoryABI || (defaultFactoryABI.abi as AbiItem[])
|
this.factoryABI = factoryABI || (defaultFactoryABI.abi as AbiItem[])
|
||||||
this.datatokensABI = datatokensABI || (defaultDatatokensABI.abi as AbiItem[])
|
this.datatokensABI = datatokensABI || (defaultDatatokensABI.abi as AbiItem[])
|
||||||
this.web3 = web3
|
this.web3 = web3
|
||||||
|
this.logger = logger
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -108,7 +110,7 @@ export class DataTokens {
|
|||||||
try {
|
try {
|
||||||
tokenAddress = trxReceipt.events.TokenCreated.returnValues[0]
|
tokenAddress = trxReceipt.events.TokenCreated.returnValues[0]
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(`ERROR: Failed to create datatoken : ${e.message}`)
|
this.logger.error(`ERROR: Failed to create datatoken : ${e.message}`)
|
||||||
}
|
}
|
||||||
return tokenAddress
|
return tokenAddress
|
||||||
}
|
}
|
||||||
@ -373,7 +375,7 @@ export class DataTokens {
|
|||||||
.send({ from: address, gas: 600000 })
|
.send({ from: address, gas: 600000 })
|
||||||
return trxReceipt
|
return trxReceipt
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(`ERROR: Failed to start order : ${e.message}`)
|
this.logger.error(`ERROR: Failed to start order : ${e.message}`)
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ import { TransactionReceipt } from 'web3-core'
|
|||||||
import { Contract, EventData } from 'web3-eth-contract'
|
import { Contract, EventData } from 'web3-eth-contract'
|
||||||
import { AbiItem } from 'web3-utils/types'
|
import { AbiItem } from 'web3-utils/types'
|
||||||
import Web3 from 'web3'
|
import Web3 from 'web3'
|
||||||
import { SubscribablePromise } from '../utils'
|
import { SubscribablePromise, Logger } from '../utils'
|
||||||
import { DataTokens } from '../datatokens/Datatokens'
|
import { DataTokens } from '../datatokens/Datatokens'
|
||||||
|
|
||||||
export interface FixedPriceExchange {
|
export interface FixedPriceExchange {
|
||||||
@ -38,6 +38,7 @@ export class OceanFixedRateExchange {
|
|||||||
public fixedRateExchangeABI: AbiItem | AbiItem[]
|
public fixedRateExchangeABI: AbiItem | AbiItem[]
|
||||||
public web3: Web3
|
public web3: Web3
|
||||||
public contract: Contract = null
|
public contract: Contract = null
|
||||||
|
private logger: Logger
|
||||||
public datatokens: DataTokens
|
public datatokens: DataTokens
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -49,6 +50,7 @@ export class OceanFixedRateExchange {
|
|||||||
*/
|
*/
|
||||||
constructor(
|
constructor(
|
||||||
web3: Web3,
|
web3: Web3,
|
||||||
|
logger: Logger,
|
||||||
fixedRateExchangeAddress: string = null,
|
fixedRateExchangeAddress: string = null,
|
||||||
fixedRateExchangeABI: AbiItem | AbiItem[] = null,
|
fixedRateExchangeABI: AbiItem | AbiItem[] = null,
|
||||||
oceanAddress: string = null,
|
oceanAddress: string = null,
|
||||||
@ -65,6 +67,7 @@ export class OceanFixedRateExchange {
|
|||||||
this.fixedRateExchangeABI,
|
this.fixedRateExchangeABI,
|
||||||
this.fixedRateExchangeAddress
|
this.fixedRateExchangeAddress
|
||||||
)
|
)
|
||||||
|
this.logger = logger
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -110,7 +113,7 @@ export class OceanFixedRateExchange {
|
|||||||
})
|
})
|
||||||
exchangeId = trxReceipt.events.ExchangeCreated.returnValues[0]
|
exchangeId = trxReceipt.events.ExchangeCreated.returnValues[0]
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(`ERROR: Failed to create new exchange: ${e.message}`)
|
this.logger.error(`ERROR: Failed to create new exchange: ${e.message}`)
|
||||||
}
|
}
|
||||||
if (amount && exchangeId) {
|
if (amount && exchangeId) {
|
||||||
observer.next(FixedRateCreateProgressStep.ApprovingDatatoken)
|
observer.next(FixedRateCreateProgressStep.ApprovingDatatoken)
|
||||||
@ -168,7 +171,7 @@ export class OceanFixedRateExchange {
|
|||||||
})
|
})
|
||||||
return trxReceipt
|
return trxReceipt
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(`ERROR: Failed to buy datatokens: ${e.message}`)
|
this.logger.error(`ERROR: Failed to buy datatokens: ${e.message}`)
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -244,6 +247,7 @@ export class OceanFixedRateExchange {
|
|||||||
return estGas
|
return estGas
|
||||||
})
|
})
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
this.logger.error(`ERROR: FixedPriceExchange: ${e.message}`)
|
||||||
estGas = DEFAULT_GAS_LIMIT
|
estGas = DEFAULT_GAS_LIMIT
|
||||||
}
|
}
|
||||||
const trxReceipt = await this.contract.methods.toggleExchangeState(exchangeId).send({
|
const trxReceipt = await this.contract.methods.toggleExchangeState(exchangeId).send({
|
||||||
@ -278,6 +282,7 @@ export class OceanFixedRateExchange {
|
|||||||
return estGas
|
return estGas
|
||||||
})
|
})
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
this.logger.error(`ERROR: FixedPriceExchange: ${e.message}`)
|
||||||
estGas = DEFAULT_GAS_LIMIT
|
estGas = DEFAULT_GAS_LIMIT
|
||||||
}
|
}
|
||||||
const trxReceipt = await this.contract.methods.toggleExchangeState(exchangeId).send({
|
const trxReceipt = await this.contract.methods.toggleExchangeState(exchangeId).send({
|
||||||
|
@ -4,8 +4,7 @@ import { Contract } from 'web3-eth-contract'
|
|||||||
import { AbiItem } from 'web3-utils/types'
|
import { AbiItem } from 'web3-utils/types'
|
||||||
import Web3 from 'web3'
|
import Web3 from 'web3'
|
||||||
import defaultDDOContractABI from '@oceanprotocol/contracts/artifacts/Metadata.json'
|
import defaultDDOContractABI from '@oceanprotocol/contracts/artifacts/Metadata.json'
|
||||||
import { didZeroX } from '../utils'
|
import { didZeroX, Logger } from '../utils'
|
||||||
|
|
||||||
// Using limited, compress-only version
|
// Using limited, compress-only version
|
||||||
// See https://github.com/LZMA-JS/LZMA-JS#but-i-dont-want-to-use-web-workers
|
// See https://github.com/LZMA-JS/LZMA-JS#but-i-dont-want-to-use-web-workers
|
||||||
import { LZMA } from 'lzma/src/lzma-c'
|
import { LZMA } from 'lzma/src/lzma-c'
|
||||||
@ -19,11 +18,13 @@ export class OnChainMetadataCache {
|
|||||||
public DDOContractABI: AbiItem | AbiItem[]
|
public DDOContractABI: AbiItem | AbiItem[]
|
||||||
public web3: Web3
|
public web3: Web3
|
||||||
public DDOContract: Contract = null
|
public DDOContract: Contract = null
|
||||||
|
private logger: Logger
|
||||||
/**
|
/**
|
||||||
* Instantiate OnChainMetadata Store for on-chain interaction.
|
* Instantiate OnChainMetadata Store for on-chain interaction.
|
||||||
*/
|
*/
|
||||||
constructor(
|
constructor(
|
||||||
web3: Web3,
|
web3: Web3,
|
||||||
|
logger: Logger,
|
||||||
DDOContractAddress: string = null,
|
DDOContractAddress: string = null,
|
||||||
DDOContractABI: AbiItem | AbiItem[] = null
|
DDOContractABI: AbiItem | AbiItem[] = null
|
||||||
) {
|
) {
|
||||||
@ -35,6 +36,7 @@ export class OnChainMetadataCache {
|
|||||||
this.DDOContractABI,
|
this.DDOContractABI,
|
||||||
this.DDOContractAddress
|
this.DDOContractAddress
|
||||||
)
|
)
|
||||||
|
this.logger = logger
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -100,7 +102,7 @@ export class OnChainMetadataCache {
|
|||||||
consumerAccount: string
|
consumerAccount: string
|
||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
if (!this.DDOContract) {
|
if (!this.DDOContract) {
|
||||||
console.error('ERROR: Missing DDOContract')
|
this.logger.error('ERROR: Missing DDOContract')
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@ -116,7 +118,7 @@ export class OnChainMetadataCache {
|
|||||||
.send({ from: consumerAccount })
|
.send({ from: consumerAccount })
|
||||||
return trxReceipt
|
return trxReceipt
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(`ERROR: Failed to publish raw DDO : ${e.message}`)
|
this.logger.error(`ERROR: Failed to publish raw DDO : ${e.message}`)
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -136,7 +138,7 @@ export class OnChainMetadataCache {
|
|||||||
consumerAccount: string
|
consumerAccount: string
|
||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
if (!this.DDOContract) {
|
if (!this.DDOContract) {
|
||||||
console.error('ERROR: Missing DDOContract')
|
this.logger.error('ERROR: Missing DDOContract')
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@ -145,7 +147,7 @@ export class OnChainMetadataCache {
|
|||||||
.send({ from: consumerAccount })
|
.send({ from: consumerAccount })
|
||||||
return trxReceipt
|
return trxReceipt
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(`ERROR: Failed to update raw DDO : ${e.message}`)
|
this.logger.error(`ERROR: Failed to update raw DDO : ${e.message}`)
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -171,7 +173,7 @@ export class OnChainMetadataCache {
|
|||||||
})
|
})
|
||||||
return trxReceipt
|
return trxReceipt
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(`ERROR: Failed to transfer DDO ownership : ${e.message}`)
|
this.logger.error(`ERROR: Failed to transfer DDO ownership : ${e.message}`)
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -201,7 +203,7 @@ export class OnChainMetadataCache {
|
|||||||
hex += '' + hexChar[(message[i] >> 4) & 0x0f] + hexChar[message[i] & 0x0f]
|
hex += '' + hexChar[(message[i] >> 4) & 0x0f] + hexChar[message[i] & 0x0f]
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(`ERROR: Failed to get hex message value : ${e.message}`)
|
this.logger.error(`ERROR: Failed to get hex message value : ${e.message}`)
|
||||||
}
|
}
|
||||||
const hexMessage = '0x' + hex
|
const hexMessage = '0x' + hex
|
||||||
return hexMessage
|
return hexMessage
|
||||||
|
@ -111,7 +111,7 @@ export default class Account extends Instantiable {
|
|||||||
})
|
})
|
||||||
result = this.web3.utils.fromWei(await token.methods.balanceOf(this.id).call())
|
result = this.web3.utils.fromWei(await token.methods.balanceOf(this.id).call())
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(`ERROR: Failed to get the balance: ${e.message}`)
|
this.logger.error(`ERROR: Failed to get the balance: ${e.message}`)
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
@ -504,7 +504,7 @@ export class Assets extends Instantiable {
|
|||||||
)
|
)
|
||||||
const totalCost = new BigNumber(String(providerData.numTokens))
|
const totalCost = new BigNumber(String(providerData.numTokens))
|
||||||
if (balance.isLessThan(totalCost)) {
|
if (balance.isLessThan(totalCost)) {
|
||||||
console.error(
|
this.logger.error(
|
||||||
'ERROR: Not enough funds Needed ' +
|
'ERROR: Not enough funds Needed ' +
|
||||||
totalCost.toString() +
|
totalCost.toString() +
|
||||||
' but balance is ' +
|
' but balance is ' +
|
||||||
@ -522,7 +522,7 @@ export class Assets extends Instantiable {
|
|||||||
)
|
)
|
||||||
if (txid) return txid.transactionHash
|
if (txid) return txid.transactionHash
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(`ERROR: Failed to order: ${e.message}`)
|
this.logger.error(`ERROR: Failed to order: ${e.message}`)
|
||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
@ -395,7 +395,7 @@ export class Compute extends Instantiable {
|
|||||||
// check if raw algo is allowed
|
// check if raw algo is allowed
|
||||||
if (service.attributes.main.privacy)
|
if (service.attributes.main.privacy)
|
||||||
if (!service.attributes.main.privacy.allowRawAlgorithm) {
|
if (!service.attributes.main.privacy.allowRawAlgorithm) {
|
||||||
console.error('ERROR: This service does not allow raw algorithm')
|
this.logger.error('ERROR: This service does not allow raw algorithm')
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -407,7 +407,7 @@ export class Compute extends Instantiable {
|
|||||||
if (
|
if (
|
||||||
!service.attributes.main.privacy.trustedAlgorithms.includes(algorithmDid)
|
!service.attributes.main.privacy.trustedAlgorithms.includes(algorithmDid)
|
||||||
) {
|
) {
|
||||||
console.error('ERROR: This service does not allow this algorithm')
|
this.logger.error('ERROR: This service does not allow this algorithm')
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,10 +50,12 @@ export class Ocean extends Instantiable {
|
|||||||
instanceConfig.config.factoryAddress,
|
instanceConfig.config.factoryAddress,
|
||||||
instanceConfig.config.factoryABI,
|
instanceConfig.config.factoryABI,
|
||||||
instanceConfig.config.datatokensABI,
|
instanceConfig.config.datatokensABI,
|
||||||
instanceConfig.config.web3Provider
|
instanceConfig.config.web3Provider,
|
||||||
|
instanceConfig.logger
|
||||||
)
|
)
|
||||||
instance.pool = new OceanPool(
|
instance.pool = new OceanPool(
|
||||||
instanceConfig.config.web3Provider,
|
instanceConfig.config.web3Provider,
|
||||||
|
instanceConfig.logger,
|
||||||
instanceConfig.config.poolFactoryABI,
|
instanceConfig.config.poolFactoryABI,
|
||||||
instanceConfig.config.poolABI,
|
instanceConfig.config.poolABI,
|
||||||
instanceConfig.config.poolFactoryAddress,
|
instanceConfig.config.poolFactoryAddress,
|
||||||
@ -61,6 +63,7 @@ export class Ocean extends Instantiable {
|
|||||||
)
|
)
|
||||||
instance.fixedRateExchange = new OceanFixedRateExchange(
|
instance.fixedRateExchange = new OceanFixedRateExchange(
|
||||||
instanceConfig.config.web3Provider,
|
instanceConfig.config.web3Provider,
|
||||||
|
instanceConfig.logger,
|
||||||
instanceConfig.config.fixedRateExchangeAddress,
|
instanceConfig.config.fixedRateExchangeAddress,
|
||||||
instanceConfig.config.fixedRateExchangeAddressABI,
|
instanceConfig.config.fixedRateExchangeAddressABI,
|
||||||
instanceConfig.config.oceanTokenAddress,
|
instanceConfig.config.oceanTokenAddress,
|
||||||
@ -68,6 +71,7 @@ export class Ocean extends Instantiable {
|
|||||||
)
|
)
|
||||||
instance.OnChainMetadataCache = new OnChainMetadataCache(
|
instance.OnChainMetadataCache = new OnChainMetadataCache(
|
||||||
instanceConfig.config.web3Provider,
|
instanceConfig.config.web3Provider,
|
||||||
|
instanceConfig.logger,
|
||||||
instanceConfig.config.metadataContractAddress,
|
instanceConfig.config.metadataContractAddress,
|
||||||
instanceConfig.config.metadataContractABI
|
instanceConfig.config.metadataContractABI
|
||||||
)
|
)
|
||||||
|
@ -10,6 +10,7 @@ import factory from '@oceanprotocol/contracts/artifacts/DTFactory.json'
|
|||||||
import datatokensTemplate from '@oceanprotocol/contracts/artifacts/DataTokenTemplate.json'
|
import datatokensTemplate from '@oceanprotocol/contracts/artifacts/DataTokenTemplate.json'
|
||||||
import { Account, DDO, Metadata } from '../../src/lib'
|
import { Account, DDO, Metadata } from '../../src/lib'
|
||||||
import { Cluster, Container, Server } from '../../src/ocean/Compute'
|
import { Cluster, Container, Server } from '../../src/ocean/Compute'
|
||||||
|
import { LoggerInstance } from '../../src/utils'
|
||||||
const web3 = new Web3('http://127.0.0.1:8545')
|
const web3 = new Web3('http://127.0.0.1:8545')
|
||||||
|
|
||||||
function sleep(ms: number) {
|
function sleep(ms: number) {
|
||||||
@ -87,7 +88,8 @@ describe('Compute flow', () => {
|
|||||||
contracts.factoryAddress,
|
contracts.factoryAddress,
|
||||||
factory.abi as AbiItem[],
|
factory.abi as AbiItem[],
|
||||||
datatokensTemplate.abi as AbiItem[],
|
datatokensTemplate.abi as AbiItem[],
|
||||||
web3
|
web3,
|
||||||
|
LoggerInstance
|
||||||
)
|
)
|
||||||
tokenAddress = await datatoken.create(
|
tokenAddress = await datatoken.create(
|
||||||
blob,
|
blob,
|
||||||
|
@ -9,6 +9,7 @@ import { Account, EditableMetadata, Service, ServiceAccess } from '../../src/lib
|
|||||||
import { Ocean } from '../../src/ocean/Ocean'
|
import { Ocean } from '../../src/ocean/Ocean'
|
||||||
import { ConfigHelper } from '../../src/utils/ConfigHelper'
|
import { ConfigHelper } from '../../src/utils/ConfigHelper'
|
||||||
import { TestContractHandler } from '../TestContractHandler'
|
import { TestContractHandler } from '../TestContractHandler'
|
||||||
|
import { LoggerInstance } from '../../src/utils'
|
||||||
|
|
||||||
const web3 = new Web3('http://127.0.0.1:8545')
|
const web3 = new Web3('http://127.0.0.1:8545')
|
||||||
|
|
||||||
@ -65,7 +66,8 @@ describe('Marketplace flow', () => {
|
|||||||
contracts.factoryAddress,
|
contracts.factoryAddress,
|
||||||
factory.abi as AbiItem[],
|
factory.abi as AbiItem[],
|
||||||
datatokensTemplate.abi as AbiItem[],
|
datatokensTemplate.abi as AbiItem[],
|
||||||
web3
|
web3,
|
||||||
|
LoggerInstance
|
||||||
)
|
)
|
||||||
tokenAddress = await datatoken.create(
|
tokenAddress = await datatoken.create(
|
||||||
blob,
|
blob,
|
||||||
|
@ -5,6 +5,7 @@ import { AbiItem } from 'web3-utils/types'
|
|||||||
import Web3 from 'web3'
|
import Web3 from 'web3'
|
||||||
import factory from '@oceanprotocol/contracts/artifacts/DTFactory.json'
|
import factory from '@oceanprotocol/contracts/artifacts/DTFactory.json'
|
||||||
import datatokensTemplate from '@oceanprotocol/contracts/artifacts/DataTokenTemplate.json'
|
import datatokensTemplate from '@oceanprotocol/contracts/artifacts/DataTokenTemplate.json'
|
||||||
|
import { LoggerInstance } from '../../src/utils'
|
||||||
const web3 = new Web3('http://127.0.0.1:8545')
|
const web3 = new Web3('http://127.0.0.1:8545')
|
||||||
|
|
||||||
describe('Simple flow', () => {
|
describe('Simple flow', () => {
|
||||||
@ -40,7 +41,8 @@ describe('Simple flow', () => {
|
|||||||
contracts.factoryAddress,
|
contracts.factoryAddress,
|
||||||
factory.abi as AbiItem[],
|
factory.abi as AbiItem[],
|
||||||
datatokensTemplate.abi as AbiItem[],
|
datatokensTemplate.abi as AbiItem[],
|
||||||
web3
|
web3,
|
||||||
|
LoggerInstance
|
||||||
)
|
)
|
||||||
tokenAddress = await datatoken.create(blob, alice, '10000000000', 'AliceDT', 'DTA')
|
tokenAddress = await datatoken.create(blob, alice, '10000000000', 'AliceDT', 'DTA')
|
||||||
})
|
})
|
||||||
|
@ -2,7 +2,7 @@ import { assert } from 'chai'
|
|||||||
import { AbiItem } from 'web3-utils/types'
|
import { AbiItem } from 'web3-utils/types'
|
||||||
import { TestContractHandler } from '../TestContractHandler'
|
import { TestContractHandler } from '../TestContractHandler'
|
||||||
import { DataTokens } from '../../src/datatokens/Datatokens'
|
import { DataTokens } from '../../src/datatokens/Datatokens'
|
||||||
|
import { LoggerInstance } from '../../src/utils'
|
||||||
import Web3 from 'web3'
|
import Web3 from 'web3'
|
||||||
import factory from '@oceanprotocol/contracts/artifacts/DTFactory.json'
|
import factory from '@oceanprotocol/contracts/artifacts/DTFactory.json'
|
||||||
import datatokensTemplate from '@oceanprotocol/contracts/artifacts/DataTokenTemplate.json'
|
import datatokensTemplate from '@oceanprotocol/contracts/artifacts/DataTokenTemplate.json'
|
||||||
@ -38,7 +38,8 @@ describe('DataTokens', () => {
|
|||||||
contracts.factoryAddress,
|
contracts.factoryAddress,
|
||||||
factory.abi as AbiItem[],
|
factory.abi as AbiItem[],
|
||||||
datatokensTemplate.abi as AbiItem[],
|
datatokensTemplate.abi as AbiItem[],
|
||||||
web3
|
web3,
|
||||||
|
LoggerInstance
|
||||||
)
|
)
|
||||||
assert(datatoken !== null)
|
assert(datatoken !== null)
|
||||||
})
|
})
|
||||||
|
@ -12,6 +12,7 @@ import datatokensTemplate from '@oceanprotocol/contracts/artifacts/DataTokenTemp
|
|||||||
// this will be replaced by our SFactory/SPool
|
// this will be replaced by our SFactory/SPool
|
||||||
import OceanPoolFactory from '@oceanprotocol/contracts/artifacts/BFactory.json'
|
import OceanPoolFactory from '@oceanprotocol/contracts/artifacts/BFactory.json'
|
||||||
import OceanSPool from '@oceanprotocol/contracts/artifacts/BPool.json'
|
import OceanSPool from '@oceanprotocol/contracts/artifacts/BPool.json'
|
||||||
|
import { LoggerInstance } from '../../../src/utils'
|
||||||
const web3 = new Web3('http://127.0.0.1:8545')
|
const web3 = new Web3('http://127.0.0.1:8545')
|
||||||
|
|
||||||
function sleep(ms: number) {
|
function sleep(ms: number) {
|
||||||
@ -74,7 +75,8 @@ describe('Balancer flow', () => {
|
|||||||
contracts.factoryAddress,
|
contracts.factoryAddress,
|
||||||
factory.abi as AbiItem[],
|
factory.abi as AbiItem[],
|
||||||
datatokensTemplate.abi as AbiItem[],
|
datatokensTemplate.abi as AbiItem[],
|
||||||
web3
|
web3,
|
||||||
|
LoggerInstance
|
||||||
)
|
)
|
||||||
assert(datatoken !== null)
|
assert(datatoken !== null)
|
||||||
})
|
})
|
||||||
@ -89,7 +91,8 @@ describe('Balancer flow', () => {
|
|||||||
contracts.factoryAddress,
|
contracts.factoryAddress,
|
||||||
factory.abi as AbiItem[],
|
factory.abi as AbiItem[],
|
||||||
datatokensTemplate.abi as AbiItem[],
|
datatokensTemplate.abi as AbiItem[],
|
||||||
web3
|
web3,
|
||||||
|
LoggerInstance
|
||||||
)
|
)
|
||||||
oceanTokenAddress = await oceandatatoken.create(
|
oceanTokenAddress = await oceandatatoken.create(
|
||||||
blob,
|
blob,
|
||||||
@ -102,6 +105,7 @@ describe('Balancer flow', () => {
|
|||||||
it('should initialize OceanPool class', async () => {
|
it('should initialize OceanPool class', async () => {
|
||||||
Pool = new OceanPool(
|
Pool = new OceanPool(
|
||||||
web3,
|
web3,
|
||||||
|
LoggerInstance,
|
||||||
OceanPoolFactory.abi as AbiItem[],
|
OceanPoolFactory.abi as AbiItem[],
|
||||||
OceanSPool.abi as AbiItem[],
|
OceanSPool.abi as AbiItem[],
|
||||||
OceanPoolFactoryAddress,
|
OceanPoolFactoryAddress,
|
||||||
|
@ -4,7 +4,7 @@ import { TestContractHandler } from '../../TestContractHandler'
|
|||||||
import { FixedPricedContractHandler } from '../../FixedPriceContractHandler'
|
import { FixedPricedContractHandler } from '../../FixedPriceContractHandler'
|
||||||
import { DataTokens } from '../../../src/datatokens/Datatokens'
|
import { DataTokens } from '../../../src/datatokens/Datatokens'
|
||||||
import { OceanFixedRateExchange } from '../../../src/exchange/FixedRateExchange'
|
import { OceanFixedRateExchange } from '../../../src/exchange/FixedRateExchange'
|
||||||
|
import { LoggerInstance } from '../../../src/utils'
|
||||||
import Web3 from 'web3'
|
import Web3 from 'web3'
|
||||||
import factory from '@oceanprotocol/contracts/artifacts/DTFactory.json'
|
import factory from '@oceanprotocol/contracts/artifacts/DTFactory.json'
|
||||||
import datatokensTemplate from '@oceanprotocol/contracts/artifacts/DataTokenTemplate.json'
|
import datatokensTemplate from '@oceanprotocol/contracts/artifacts/DataTokenTemplate.json'
|
||||||
@ -66,7 +66,8 @@ describe('FixedRateExchange flow', () => {
|
|||||||
contracts.factoryAddress,
|
contracts.factoryAddress,
|
||||||
factory.abi as AbiItem[],
|
factory.abi as AbiItem[],
|
||||||
datatokensTemplate.abi as AbiItem[],
|
datatokensTemplate.abi as AbiItem[],
|
||||||
web3
|
web3,
|
||||||
|
LoggerInstance
|
||||||
)
|
)
|
||||||
assert(datatoken !== null)
|
assert(datatoken !== null)
|
||||||
})
|
})
|
||||||
@ -89,7 +90,8 @@ describe('FixedRateExchange flow', () => {
|
|||||||
contracts.factoryAddress,
|
contracts.factoryAddress,
|
||||||
factory.abi as AbiItem[],
|
factory.abi as AbiItem[],
|
||||||
datatokensTemplate.abi as AbiItem[],
|
datatokensTemplate.abi as AbiItem[],
|
||||||
web3
|
web3,
|
||||||
|
LoggerInstance
|
||||||
)
|
)
|
||||||
oceanTokenAddress = await oceandatatoken.create(
|
oceanTokenAddress = await oceandatatoken.create(
|
||||||
blob,
|
blob,
|
||||||
@ -105,6 +107,7 @@ describe('FixedRateExchange flow', () => {
|
|||||||
it('should initialize FixedExchangeRate class', async () => {
|
it('should initialize FixedExchangeRate class', async () => {
|
||||||
FixedRateClass = new OceanFixedRateExchange(
|
FixedRateClass = new OceanFixedRateExchange(
|
||||||
web3,
|
web3,
|
||||||
|
LoggerInstance,
|
||||||
FixedRateExchangeAddress,
|
FixedRateExchangeAddress,
|
||||||
FixedRateExchangeContract.abi as AbiItem[],
|
FixedRateExchangeContract.abi as AbiItem[],
|
||||||
oceanTokenAddress,
|
oceanTokenAddress,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user