mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
refactor
This commit is contained in:
parent
272fb9a17c
commit
c7f3144526
@ -2,7 +2,7 @@ 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 { Contract } from 'web3-eth-contract'
|
import { Contract } from 'web3-eth-contract'
|
||||||
import { Logger, getFairGasPrice } from '../../utils'
|
import { Logger, getFairGasPrice, LoggerInstance } from '../../utils'
|
||||||
import BigNumber from 'bignumber.js'
|
import BigNumber from 'bignumber.js'
|
||||||
import PoolTemplate from '@oceanprotocol/contracts/artifacts/contracts/pools/balancer/BPool.sol/BPool.json'
|
import PoolTemplate from '@oceanprotocol/contracts/artifacts/contracts/pools/balancer/BPool.sol/BPool.json'
|
||||||
import defaultPool from '@oceanprotocol/contracts/artifacts/contracts/pools/FactoryRouter.sol/FactoryRouter.json'
|
import defaultPool from '@oceanprotocol/contracts/artifacts/contracts/pools/FactoryRouter.sol/FactoryRouter.json'
|
||||||
@ -58,7 +58,7 @@ export class Pool {
|
|||||||
.estimateGas({ from: account }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
.estimateGas({ from: account }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
estGas = gasLimitDefault
|
estGas = gasLimitDefault
|
||||||
console.log(e)
|
LoggerInstance.error('estimage gas failed for approve!', e)
|
||||||
}
|
}
|
||||||
return estGas
|
return estGas
|
||||||
}
|
}
|
||||||
@ -751,44 +751,38 @@ export class Pool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async amountToUnits(token: string, amount: string): Promise<string> {
|
async amountToUnits(token: string, amount: string): Promise<string> {
|
||||||
let decimals = 18
|
|
||||||
const tokenContract = new this.web3.eth.Contract(
|
|
||||||
defaultERC20ABI.abi as AbiItem[],
|
|
||||||
token
|
|
||||||
)
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
decimals = await tokenContract.methods.decimals().call()
|
const tokenContract = new this.web3.eth.Contract(
|
||||||
if (decimals === 0) {
|
defaultERC20ABI.abi as AbiItem[],
|
||||||
|
token
|
||||||
|
)
|
||||||
|
let decimals = await tokenContract.methods.decimals().call()
|
||||||
|
if (decimals == 0) {
|
||||||
decimals = 18
|
decimals = 18
|
||||||
}
|
}
|
||||||
|
const amountFormatted = new BigNumber(parseInt(amount) * 10 ** decimals)
|
||||||
|
return amountFormatted.toString()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.logger.error('ERROR: FAILED TO CALL DECIMALS(), USING 18')
|
this.logger.error('ERROR: FAILED TO CALL DECIMALS(), USING 18')
|
||||||
}
|
}
|
||||||
|
|
||||||
const amountFormatted = new BigNumber(parseInt(amount) * 10 ** decimals)
|
|
||||||
|
|
||||||
return amountFormatted.toString()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async unitsToAmount(token: string, amount: string): Promise<string> {
|
async unitsToAmount(token: string, amount: string): Promise<string> {
|
||||||
let decimals = 18
|
|
||||||
const tokenContract = new this.web3.eth.Contract(
|
|
||||||
defaultERC20ABI.abi as AbiItem[],
|
|
||||||
token
|
|
||||||
)
|
|
||||||
try {
|
try {
|
||||||
decimals = await tokenContract.methods.decimals().call()
|
const tokenContract = new this.web3.eth.Contract(
|
||||||
if (decimals === 0) {
|
defaultERC20ABI.abi as AbiItem[],
|
||||||
|
token
|
||||||
|
)
|
||||||
|
let decimals = await tokenContract.methods.decimals().call()
|
||||||
|
if (decimals == 0) {
|
||||||
decimals = 18
|
decimals = 18
|
||||||
}
|
}
|
||||||
|
const amountFormatted = new BigNumber(parseInt(amount) / 10 ** decimals)
|
||||||
|
|
||||||
|
return amountFormatted.toString()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.logger.error('ERROR: FAILED TO CALL DECIMALS(), USING 18')
|
this.logger.error('ERROR: FAILED TO CALL DECIMALS(), USING 18')
|
||||||
}
|
}
|
||||||
|
|
||||||
const amountFormatted = new BigNumber(parseInt(amount) / 10 ** decimals)
|
|
||||||
|
|
||||||
return amountFormatted.toString()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1534,6 +1528,7 @@ export class Pool {
|
|||||||
tokenAmountIn: string
|
tokenAmountIn: 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)
|
||||||
|
console.log('pool ', pool.methods)
|
||||||
let amount = null
|
let amount = null
|
||||||
try {
|
try {
|
||||||
const result = await pool.methods
|
const result = await pool.methods
|
||||||
@ -1553,7 +1548,6 @@ export class Pool {
|
|||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
const pool = new this.web3.eth.Contract(this.poolABI, poolAddress)
|
const pool = new this.web3.eth.Contract(this.poolABI, poolAddress)
|
||||||
let amount = null
|
let amount = null
|
||||||
|
|
||||||
const amountFormatted = await this.amountToUnits(poolAddress, poolAmountOut)
|
const amountFormatted = await this.amountToUnits(poolAddress, poolAmountOut)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -1561,7 +1555,6 @@ export class Pool {
|
|||||||
.calcSingleInPoolOut(tokenIn, amountFormatted)
|
.calcSingleInPoolOut(tokenIn, amountFormatted)
|
||||||
|
|
||||||
.call()
|
.call()
|
||||||
|
|
||||||
amount = await this.unitsToAmount(tokenIn, result)
|
amount = await this.unitsToAmount(tokenIn, result)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.logger.error(`ERROR: Failed to calculate SingleInGivenPoolOut : ${e.message}`)
|
this.logger.error(`ERROR: Failed to calculate SingleInGivenPoolOut : ${e.message}`)
|
||||||
|
@ -5,7 +5,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 { Logger, getFairGasPrice } from '../../utils'
|
import { LoggerInstance, getFairGasPrice } from '../../utils'
|
||||||
|
|
||||||
const MAX_AWAIT_PROMISES = 10
|
const MAX_AWAIT_PROMISES = 10
|
||||||
|
|
||||||
@ -55,7 +55,6 @@ export class FixedRateExchange {
|
|||||||
public fixedRateContract: Contract
|
public fixedRateContract: Contract
|
||||||
public web3: Web3
|
public web3: Web3
|
||||||
public contract: Contract = null
|
public contract: Contract = null
|
||||||
private logger: Logger
|
|
||||||
|
|
||||||
public startBlock: number
|
public startBlock: number
|
||||||
public ssABI: AbiItem | AbiItem[]
|
public ssABI: AbiItem | AbiItem[]
|
||||||
@ -67,7 +66,6 @@ export class FixedRateExchange {
|
|||||||
*/
|
*/
|
||||||
constructor(
|
constructor(
|
||||||
web3: Web3,
|
web3: Web3,
|
||||||
logger: Logger,
|
|
||||||
fixedRateAddress: string,
|
fixedRateAddress: string,
|
||||||
fixedRateExchangeABI: AbiItem | AbiItem[] = null,
|
fixedRateExchangeABI: AbiItem | AbiItem[] = null,
|
||||||
oceanAddress: string = null,
|
oceanAddress: string = null,
|
||||||
@ -85,8 +83,6 @@ export class FixedRateExchange {
|
|||||||
this.fixedRateExchangeABI,
|
this.fixedRateExchangeABI,
|
||||||
this.fixedRateAddress
|
this.fixedRateAddress
|
||||||
)
|
)
|
||||||
|
|
||||||
this.logger = logger
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async amountToUnits(token: string, amount: string): Promise<string> {
|
async amountToUnits(token: string, amount: string): Promise<string> {
|
||||||
@ -99,7 +95,7 @@ export class FixedRateExchange {
|
|||||||
try {
|
try {
|
||||||
decimals = await tokenContract.methods.decimals().call()
|
decimals = await tokenContract.methods.decimals().call()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.logger.error('ERROR: FAILED TO CALL DECIMALS(), USING 18')
|
LoggerInstance.error('ERROR: FAILED TO CALL DECIMALS(), USING 18')
|
||||||
}
|
}
|
||||||
|
|
||||||
const amountFormatted = new BigNumber(parseInt(amount) * 10 ** decimals)
|
const amountFormatted = new BigNumber(parseInt(amount) * 10 ** decimals)
|
||||||
@ -116,7 +112,7 @@ export class FixedRateExchange {
|
|||||||
try {
|
try {
|
||||||
decimals = await tokenContract.methods.decimals().call()
|
decimals = await tokenContract.methods.decimals().call()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.logger.error('ERROR: FAILED TO CALL DECIMALS(), USING 18')
|
LoggerInstance.error('ERROR: FAILED TO CALL DECIMALS(), USING 18')
|
||||||
}
|
}
|
||||||
|
|
||||||
const amountFormatted = new BigNumber(parseInt(amount) / 10 ** decimals)
|
const amountFormatted = new BigNumber(parseInt(amount) / 10 ** decimals)
|
||||||
@ -212,7 +208,7 @@ export class FixedRateExchange {
|
|||||||
})
|
})
|
||||||
return trxReceipt
|
return trxReceipt
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.logger.error(`ERROR: Failed to buy datatokens: ${e.message}`)
|
LoggerInstance.error(`ERROR: Failed to buy datatokens: ${e.message}`)
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -287,7 +283,7 @@ export class FixedRateExchange {
|
|||||||
})
|
})
|
||||||
return trxReceipt
|
return trxReceipt
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.logger.error(`ERROR: Failed to sell datatokens: ${e.message}`)
|
LoggerInstance.error(`ERROR: Failed to sell datatokens: ${e.message}`)
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -981,7 +977,7 @@ export class FixedRateExchange {
|
|||||||
try {
|
try {
|
||||||
result = await this.contract.methods.opfCollector().call()
|
result = await this.contract.methods.opfCollector().call()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.logger.error(`ERROR: Failed to get OPF Collector address: ${e.message}`)
|
LoggerInstance.error(`ERROR: Failed to get OPF Collector address: ${e.message}`)
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
@ -995,7 +991,7 @@ export class FixedRateExchange {
|
|||||||
try {
|
try {
|
||||||
result = await this.contract.methods.router().call()
|
result = await this.contract.methods.router().call()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.logger.error(`ERROR: Failed to get Router address: ${e.message}`)
|
LoggerInstance.error(`ERROR: Failed to get Router address: ${e.message}`)
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
@ -1010,7 +1006,7 @@ export class FixedRateExchange {
|
|||||||
try {
|
try {
|
||||||
result = await (await this.getExchange(exchangeId)).exchangeOwner
|
result = await (await this.getExchange(exchangeId)).exchangeOwner
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.logger.error(`ERROR: Failed to get OPF Collector address: ${e.message}`)
|
LoggerInstance.error(`ERROR: Failed to get OPF Collector address: ${e.message}`)
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
@ -2,12 +2,11 @@ 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 { Contract } from 'web3-eth-contract'
|
import { Contract } from 'web3-eth-contract'
|
||||||
import { Logger, getFairGasPrice } from '../../utils'
|
import { LoggerInstance, getFairGasPrice } from '../../utils'
|
||||||
import BigNumber from 'bignumber.js'
|
import BigNumber from 'bignumber.js'
|
||||||
import SideStakingTemplate from '@oceanprotocol/contracts/artifacts/contracts/pools/ssContracts/SideStaking.sol/SideStaking.json'
|
import SideStakingTemplate from '@oceanprotocol/contracts/artifacts/contracts/pools/ssContracts/SideStaking.sol/SideStaking.json'
|
||||||
import defaultPool from '@oceanprotocol/contracts/artifacts/contracts/pools/FactoryRouter.sol/FactoryRouter.json'
|
import defaultPool from '@oceanprotocol/contracts/artifacts/contracts/pools/FactoryRouter.sol/FactoryRouter.json'
|
||||||
import defaultERC20ABI from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC20Template.sol/ERC20Template.json'
|
import defaultERC20ABI from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC20Template.sol/ERC20Template.json'
|
||||||
import Decimal from 'decimal.js'
|
|
||||||
|
|
||||||
const MaxUint256 =
|
const MaxUint256 =
|
||||||
'115792089237316195423570985008687907853269984665640564039457584007913129639934'
|
'115792089237316195423570985008687907853269984665640564039457584007913129639934'
|
||||||
@ -19,13 +18,11 @@ export class SideStaking {
|
|||||||
public ssABI: AbiItem | AbiItem[]
|
public ssABI: AbiItem | AbiItem[]
|
||||||
public web3: Web3
|
public web3: Web3
|
||||||
public GASLIMIT_DEFAULT = 1000000
|
public GASLIMIT_DEFAULT = 1000000
|
||||||
private logger: Logger
|
|
||||||
|
|
||||||
constructor(web3: Web3, logger: Logger, ssABI: AbiItem | AbiItem[] = null) {
|
constructor(web3: Web3, ssABI: AbiItem | AbiItem[] = null) {
|
||||||
if (ssABI) this.ssABI = ssABI
|
if (ssABI) this.ssABI = ssABI
|
||||||
else this.ssABI = SideStakingTemplate.abi as AbiItem[]
|
else this.ssABI = SideStakingTemplate.abi as AbiItem[]
|
||||||
this.web3 = web3
|
this.web3 = web3
|
||||||
this.logger = logger
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async amountToUnits(token: string, amount: string): Promise<string> {
|
async amountToUnits(token: string, amount: string): Promise<string> {
|
||||||
@ -37,7 +34,7 @@ export class SideStaking {
|
|||||||
try {
|
try {
|
||||||
decimals = await tokenContract.methods.decimals().call()
|
decimals = await tokenContract.methods.decimals().call()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.logger.error('ERROR: FAILED TO CALL DECIMALS(), USING 18')
|
LoggerInstance.error('ERROR: FAILED TO CALL DECIMALS(), USING 18')
|
||||||
}
|
}
|
||||||
|
|
||||||
const amountFormatted = new BigNumber(parseInt(amount) * 10 ** decimals)
|
const amountFormatted = new BigNumber(parseInt(amount) * 10 ** decimals)
|
||||||
@ -54,7 +51,7 @@ export class SideStaking {
|
|||||||
try {
|
try {
|
||||||
decimals = await tokenContract.methods.decimals().call()
|
decimals = await tokenContract.methods.decimals().call()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.logger.error('ERROR: FAILED TO CALL DECIMALS(), USING 18')
|
LoggerInstance.error('ERROR: FAILED TO CALL DECIMALS(), USING 18')
|
||||||
}
|
}
|
||||||
|
|
||||||
const amountFormatted = new BigNumber(parseInt(amount) / 10 ** decimals)
|
const amountFormatted = new BigNumber(parseInt(amount) / 10 ** decimals)
|
||||||
@ -79,7 +76,7 @@ export class SideStaking {
|
|||||||
.getDataTokenCirculatingSupply(datatokenAddress)
|
.getDataTokenCirculatingSupply(datatokenAddress)
|
||||||
.call()
|
.call()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.logger.error(`ERROR: Failed to get: ${e.message}`)
|
LoggerInstance.error(`ERROR: Failed to get: ${e.message}`)
|
||||||
}
|
}
|
||||||
return result.toString()
|
return result.toString()
|
||||||
}
|
}
|
||||||
@ -102,7 +99,7 @@ export class SideStaking {
|
|||||||
.getDataTokenCurrentCirculatingSupply(datatokenAddress)
|
.getDataTokenCurrentCirculatingSupply(datatokenAddress)
|
||||||
.call()
|
.call()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.logger.error(`ERROR: Failed to get: ${e.message}`)
|
LoggerInstance.error(`ERROR: Failed to get: ${e.message}`)
|
||||||
}
|
}
|
||||||
return result.toString()
|
return result.toString()
|
||||||
}
|
}
|
||||||
@ -122,7 +119,7 @@ export class SideStaking {
|
|||||||
try {
|
try {
|
||||||
result = await sideStaking.methods.getPublisherAddress(datatokenAddress).call()
|
result = await sideStaking.methods.getPublisherAddress(datatokenAddress).call()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.logger.error(`ERROR: Failed to get: ${e.message}`)
|
LoggerInstance.error(`ERROR: Failed to get: ${e.message}`)
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
@ -139,7 +136,7 @@ export class SideStaking {
|
|||||||
try {
|
try {
|
||||||
result = await sideStaking.methods.getBaseTokenAddress(datatokenAddress).call()
|
result = await sideStaking.methods.getBaseTokenAddress(datatokenAddress).call()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.logger.error(`ERROR: Failed to get: ${e.message}`)
|
LoggerInstance.error(`ERROR: Failed to get: ${e.message}`)
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
@ -156,7 +153,7 @@ export class SideStaking {
|
|||||||
try {
|
try {
|
||||||
result = await sideStaking.methods.getPoolAddress(datatokenAddress).call()
|
result = await sideStaking.methods.getPoolAddress(datatokenAddress).call()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.logger.error(`ERROR: Failed to get: ${e.message}`)
|
LoggerInstance.error(`ERROR: Failed to get: ${e.message}`)
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
@ -176,7 +173,7 @@ export class SideStaking {
|
|||||||
try {
|
try {
|
||||||
result = await sideStaking.methods.getBaseTokenBalance(datatokenAddress).call()
|
result = await sideStaking.methods.getBaseTokenBalance(datatokenAddress).call()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.logger.error(`ERROR: Failed to get: ${e.message}`)
|
LoggerInstance.error(`ERROR: Failed to get: ${e.message}`)
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
@ -196,7 +193,7 @@ export class SideStaking {
|
|||||||
try {
|
try {
|
||||||
result = await sideStaking.methods.getDataTokenBalance(datatokenAddress).call()
|
result = await sideStaking.methods.getDataTokenBalance(datatokenAddress).call()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.logger.error(`ERROR: Failed to get: ${e.message}`)
|
LoggerInstance.error(`ERROR: Failed to get: ${e.message}`)
|
||||||
}
|
}
|
||||||
result = await this.unitsToAmount(datatokenAddress, result)
|
result = await this.unitsToAmount(datatokenAddress, result)
|
||||||
return result
|
return result
|
||||||
@ -214,7 +211,7 @@ export class SideStaking {
|
|||||||
try {
|
try {
|
||||||
result = await sideStaking.methods.getvestingEndBlock(datatokenAddress).call()
|
result = await sideStaking.methods.getvestingEndBlock(datatokenAddress).call()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.logger.error(`ERROR: Failed to get: ${e.message}`)
|
LoggerInstance.error(`ERROR: Failed to get: ${e.message}`)
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
@ -231,7 +228,7 @@ export class SideStaking {
|
|||||||
try {
|
try {
|
||||||
result = await sideStaking.methods.getvestingAmount(datatokenAddress).call()
|
result = await sideStaking.methods.getvestingAmount(datatokenAddress).call()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.logger.error(`ERROR: Failed to get: ${e.message}`)
|
LoggerInstance.error(`ERROR: Failed to get: ${e.message}`)
|
||||||
}
|
}
|
||||||
result = await this.unitsToAmount(datatokenAddress, result)
|
result = await this.unitsToAmount(datatokenAddress, result)
|
||||||
return result
|
return result
|
||||||
@ -252,7 +249,7 @@ export class SideStaking {
|
|||||||
try {
|
try {
|
||||||
result = await sideStaking.methods.getvestingLastBlock(datatokenAddress).call()
|
result = await sideStaking.methods.getvestingLastBlock(datatokenAddress).call()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.logger.error(`ERROR: Failed to get: ${e.message}`)
|
LoggerInstance.error(`ERROR: Failed to get: ${e.message}`)
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
@ -272,7 +269,7 @@ export class SideStaking {
|
|||||||
try {
|
try {
|
||||||
result = await sideStaking.methods.getvestingAmountSoFar(datatokenAddress).call()
|
result = await sideStaking.methods.getvestingAmountSoFar(datatokenAddress).call()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.logger.error(`ERROR: Failed to get: ${e.message}`)
|
LoggerInstance.error(`ERROR: Failed to get: ${e.message}`)
|
||||||
}
|
}
|
||||||
result = await this.unitsToAmount(datatokenAddress, result)
|
result = await this.unitsToAmount(datatokenAddress, result)
|
||||||
return result
|
return result
|
||||||
@ -335,7 +332,7 @@ export class SideStaking {
|
|||||||
gasPrice: await getFairGasPrice(this.web3)
|
gasPrice: await getFairGasPrice(this.web3)
|
||||||
})
|
})
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.logger.error('ERROR: Failed to join swap pool amount out')
|
LoggerInstance.error('ERROR: Failed to join swap pool amount out')
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
@ -351,7 +348,7 @@ export class SideStaking {
|
|||||||
try {
|
try {
|
||||||
result = await sideStaking.methods.router().call()
|
result = await sideStaking.methods.router().call()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.logger.error(`ERROR: Failed to get Router address: ${e.message}`)
|
LoggerInstance.error(`ERROR: Failed to get Router address: ${e.message}`)
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
@ -16,10 +16,11 @@ import MockERC20 from '@oceanprotocol/contracts/artifacts/contracts/utils/mock/M
|
|||||||
import PoolTemplate from '@oceanprotocol/contracts/artifacts/contracts/pools/balancer/BPool.sol/BPool.json'
|
import PoolTemplate from '@oceanprotocol/contracts/artifacts/contracts/pools/balancer/BPool.sol/BPool.json'
|
||||||
import OPFCollector from '@oceanprotocol/contracts/artifacts/contracts/communityFee/OPFCommunityFeeCollector.sol/OPFCommunityFeeCollector.json'
|
import OPFCollector from '@oceanprotocol/contracts/artifacts/contracts/communityFee/OPFCommunityFeeCollector.sol/OPFCommunityFeeCollector.json'
|
||||||
import { LoggerInstance } from '../../../../src/utils'
|
import { LoggerInstance } from '../../../../src/utils'
|
||||||
import { NFTFactory } from '../../../../src/factories/NFTFactory'
|
import { NFTFactory, NFTCreateData } from '../../../../src/factories/NFTFactory'
|
||||||
import { Pool } from '../../../../src/pools/balancer/Pool'
|
import { Pool } from '../../../../src/pools/balancer/Pool'
|
||||||
import { FixedRateExchange } from '../../../../src/pools/fixedRate/FixedRateExchange'
|
import { FixedRateExchange } from '../../../../src/pools/fixedRate/FixedRateExchange'
|
||||||
import { BADFAMILY } from 'dns'
|
import { BADFAMILY } from 'dns'
|
||||||
|
import { FreCreationParams, Erc20CreateParams } from '../../../../src/interfaces'
|
||||||
const { keccak256 } = require('@ethersproject/keccak256')
|
const { keccak256 } = require('@ethersproject/keccak256')
|
||||||
const web3 = new Web3('http://127.0.0.1:8545')
|
const web3 = new Web3('http://127.0.0.1:8545')
|
||||||
const communityCollector = '0xeE9300b7961e0a01d9f0adb863C7A227A07AaD75'
|
const communityCollector = '0xeE9300b7961e0a01d9f0adb863C7A227A07AaD75'
|
||||||
@ -103,34 +104,46 @@ describe('Fixed Rate unit test', () => {
|
|||||||
it('#create an exchange', async () => {
|
it('#create an exchange', async () => {
|
||||||
// CREATE AN Exchange
|
// CREATE AN Exchange
|
||||||
// we prepare transaction parameters objects
|
// we prepare transaction parameters objects
|
||||||
const nftData = {
|
|
||||||
|
const nftFactory = new NFTFactory(contracts.factory721Address, web3)
|
||||||
|
|
||||||
|
const nftData: NFTCreateData = {
|
||||||
name: '72120Bundle',
|
name: '72120Bundle',
|
||||||
symbol: '72Bundle',
|
symbol: '72Bundle',
|
||||||
templateIndex: 1,
|
templateIndex: 1,
|
||||||
baseURI: 'https://oceanprotocol.com/nft/'
|
baseURI: 'https://oceanprotocol.com/nft/'
|
||||||
}
|
}
|
||||||
const ercData = {
|
|
||||||
|
const ercParams: Erc20CreateParams = {
|
||||||
templateIndex: 1,
|
templateIndex: 1,
|
||||||
strings: ['ERC20B1', 'ERC20DT1Symbol'],
|
minter: contracts.accounts[0],
|
||||||
addresses: [contracts.accounts[0], user3, contracts.accounts[0], ADDRESS_ZERO],
|
feeManager: user3,
|
||||||
uints: [web3.utils.toWei('1000000'), 0],
|
mpFeeAddress: contracts.accounts[0],
|
||||||
bytess: []
|
feeToken: ADDRESS_ZERO,
|
||||||
|
cap: '1000000',
|
||||||
|
feeAmount: '0',
|
||||||
|
name: 'ERC20B1',
|
||||||
|
symbol: 'ERC20DT1Symbol'
|
||||||
}
|
}
|
||||||
|
|
||||||
// [baseToken,owner,marketFeeCollector,allowedSwapper]
|
const freParams: FreCreationParams = {
|
||||||
const fixedRateData = {
|
fixedRateAddress: contracts.fixedRateAddress,
|
||||||
fixedPriceAddress: contracts.fixedRateAddress,
|
baseTokenAddress: contracts.daiAddress,
|
||||||
addresses: [contracts.daiAddress, exchangeOwner, user3, ADDRESS_ZERO],
|
owner: exchangeOwner,
|
||||||
uints: [18, 18, web3.utils.toWei('1'), 1e15, 0]
|
marketFeeCollector: user3,
|
||||||
|
baseTokenDecimals: 18,
|
||||||
|
dataTokenDecimals: 18,
|
||||||
|
fixedRate: '1',
|
||||||
|
marketFee: 1e15,
|
||||||
|
allowedConsumer: ADDRESS_ZERO,
|
||||||
|
withMint: false
|
||||||
}
|
}
|
||||||
|
|
||||||
const nftFactory = new NFTFactory(contracts.factory721Address, web3, LoggerInstance)
|
|
||||||
|
|
||||||
const txReceipt = await nftFactory.createNftErcWithFixedRate(
|
const txReceipt = await nftFactory.createNftErcWithFixedRate(
|
||||||
exchangeOwner,
|
exchangeOwner,
|
||||||
nftData,
|
nftData,
|
||||||
ercData,
|
ercParams,
|
||||||
fixedRateData
|
freParams
|
||||||
)
|
)
|
||||||
|
|
||||||
initialBlock = await web3.eth.getBlockNumber()
|
initialBlock = await web3.eth.getBlockNumber()
|
||||||
@ -144,7 +157,6 @@ describe('Fixed Rate unit test', () => {
|
|||||||
fixedRateAddress = contracts.fixedRateAddress
|
fixedRateAddress = contracts.fixedRateAddress
|
||||||
fixedRate = new FixedRateExchange(
|
fixedRate = new FixedRateExchange(
|
||||||
web3,
|
web3,
|
||||||
LoggerInstance,
|
|
||||||
fixedRateAddress,
|
fixedRateAddress,
|
||||||
FixedRate.abi as AbiItem[],
|
FixedRate.abi as AbiItem[],
|
||||||
contracts.oceanAddress
|
contracts.oceanAddress
|
||||||
@ -420,34 +432,46 @@ describe('Fixed Rate unit test', () => {
|
|||||||
it('#create an exchange', async () => {
|
it('#create an exchange', async () => {
|
||||||
// CREATE AN Exchange
|
// CREATE AN Exchange
|
||||||
// we prepare transaction parameters objects
|
// we prepare transaction parameters objects
|
||||||
const nftData = {
|
|
||||||
|
const nftFactory = new NFTFactory(contracts.factory721Address, web3)
|
||||||
|
|
||||||
|
const nftData: NFTCreateData = {
|
||||||
name: '72120Bundle',
|
name: '72120Bundle',
|
||||||
symbol: '72Bundle',
|
symbol: '72Bundle',
|
||||||
templateIndex: 1,
|
templateIndex: 1,
|
||||||
baseURI: 'https://oceanprotocol.com/nft/'
|
baseURI: 'https://oceanprotocol.com/nft/'
|
||||||
}
|
}
|
||||||
const ercData = {
|
|
||||||
|
const ercParams: Erc20CreateParams = {
|
||||||
templateIndex: 1,
|
templateIndex: 1,
|
||||||
strings: ['ERC20B1', 'ERC20DT1Symbol'],
|
minter: contracts.accounts[0],
|
||||||
addresses: [contracts.accounts[0], user3, contracts.accounts[0], ADDRESS_ZERO],
|
feeManager: user3,
|
||||||
uints: [web3.utils.toWei('1000000'), 0],
|
mpFeeAddress: contracts.accounts[0],
|
||||||
bytess: []
|
feeToken: ADDRESS_ZERO,
|
||||||
|
cap: '1000000',
|
||||||
|
feeAmount: '0',
|
||||||
|
name: 'ERC20B1',
|
||||||
|
symbol: 'ERC20DT1Symbol'
|
||||||
}
|
}
|
||||||
|
|
||||||
// [baseToken,owner,marketFeeCollector,allowedSwapper]
|
const freParams: FreCreationParams = {
|
||||||
const fixedRateData = {
|
fixedRateAddress: contracts.fixedRateAddress,
|
||||||
fixedPriceAddress: contracts.fixedRateAddress,
|
baseTokenAddress: contracts.usdcAddress,
|
||||||
addresses: [contracts.usdcAddress, exchangeOwner, user3, ADDRESS_ZERO],
|
owner: exchangeOwner,
|
||||||
uints: [6, 18, web3.utils.toWei('1'), 1e15, 0]
|
marketFeeCollector: user3,
|
||||||
|
baseTokenDecimals: 6,
|
||||||
|
dataTokenDecimals: 18,
|
||||||
|
fixedRate: '1',
|
||||||
|
marketFee: 1e15,
|
||||||
|
allowedConsumer: ADDRESS_ZERO,
|
||||||
|
withMint: false
|
||||||
}
|
}
|
||||||
|
|
||||||
const nftFactory = new NFTFactory(contracts.factory721Address, web3, LoggerInstance)
|
|
||||||
|
|
||||||
const txReceipt = await nftFactory.createNftErcWithFixedRate(
|
const txReceipt = await nftFactory.createNftErcWithFixedRate(
|
||||||
exchangeOwner,
|
exchangeOwner,
|
||||||
nftData,
|
nftData,
|
||||||
ercData,
|
ercParams,
|
||||||
fixedRateData
|
freParams
|
||||||
)
|
)
|
||||||
|
|
||||||
initialBlock = await web3.eth.getBlockNumber()
|
initialBlock = await web3.eth.getBlockNumber()
|
||||||
@ -461,7 +485,6 @@ describe('Fixed Rate unit test', () => {
|
|||||||
fixedRateAddress = contracts.fixedRateAddress
|
fixedRateAddress = contracts.fixedRateAddress
|
||||||
fixedRate = new FixedRateExchange(
|
fixedRate = new FixedRateExchange(
|
||||||
web3,
|
web3,
|
||||||
LoggerInstance,
|
|
||||||
fixedRateAddress,
|
fixedRateAddress,
|
||||||
FixedRate.abi as AbiItem[],
|
FixedRate.abi as AbiItem[],
|
||||||
contracts.oceanAddress
|
contracts.oceanAddress
|
||||||
|
@ -16,9 +16,10 @@ import MockERC20 from '@oceanprotocol/contracts/artifacts/contracts/utils/mock/M
|
|||||||
import PoolTemplate from '@oceanprotocol/contracts/artifacts/contracts/pools/balancer/BPool.sol/BPool.json'
|
import PoolTemplate from '@oceanprotocol/contracts/artifacts/contracts/pools/balancer/BPool.sol/BPool.json'
|
||||||
import OPFCollector from '@oceanprotocol/contracts/artifacts/contracts/communityFee/OPFCommunityFeeCollector.sol/OPFCommunityFeeCollector.json'
|
import OPFCollector from '@oceanprotocol/contracts/artifacts/contracts/communityFee/OPFCommunityFeeCollector.sol/OPFCommunityFeeCollector.json'
|
||||||
import { LoggerInstance } from '../../../../src/utils'
|
import { LoggerInstance } from '../../../../src/utils'
|
||||||
import { NFTFactory } from '../../../../src/factories/NFTFactory'
|
import { NFTFactory, NFTCreateData } from '../../../../src/factories/NFTFactory'
|
||||||
import { Pool } from '../../../../src/pools/balancer/Pool'
|
import { Pool } from '../../../../src/pools/balancer/Pool'
|
||||||
import { SideStaking } from '../../../../src/pools/ssContracts/SideStaking'
|
import { SideStaking } from '../../../../src/pools/ssContracts/SideStaking'
|
||||||
|
import { Erc20CreateParams, PoolCreationParams } from '../../../../src/interfaces'
|
||||||
const { keccak256 } = require('@ethersproject/keccak256')
|
const { keccak256 } = require('@ethersproject/keccak256')
|
||||||
const web3 = new Web3('http://127.0.0.1:8545')
|
const web3 = new Web3('http://127.0.0.1:8545')
|
||||||
const communityCollector = '0xeE9300b7961e0a01d9f0adb863C7A227A07AaD75'
|
const communityCollector = '0xeE9300b7961e0a01d9f0adb863C7A227A07AaD75'
|
||||||
@ -79,7 +80,7 @@ describe('SideStaking unit test', () => {
|
|||||||
pool = new Pool(web3, LoggerInstance, PoolTemplate.abi as AbiItem[])
|
pool = new Pool(web3, LoggerInstance, PoolTemplate.abi as AbiItem[])
|
||||||
assert(pool != null)
|
assert(pool != null)
|
||||||
//
|
//
|
||||||
sideStaking = new SideStaking(web3, LoggerInstance, SSContract.abi as AbiItem[])
|
sideStaking = new SideStaking(web3, SSContract.abi as AbiItem[])
|
||||||
assert(sideStaking != null)
|
assert(sideStaking != null)
|
||||||
|
|
||||||
daiContract = new web3.eth.Contract(
|
daiContract = new web3.eth.Contract(
|
||||||
@ -134,57 +135,50 @@ describe('SideStaking unit test', () => {
|
|||||||
it('#create a pool', async () => {
|
it('#create a pool', async () => {
|
||||||
// CREATE A POOL
|
// CREATE A POOL
|
||||||
// we prepare transaction parameters objects
|
// we prepare transaction parameters objects
|
||||||
const nftData = {
|
const nftFactory = new NFTFactory(contracts.factory721Address, web3)
|
||||||
|
|
||||||
|
const nftData: NFTCreateData = {
|
||||||
name: '72120Bundle',
|
name: '72120Bundle',
|
||||||
symbol: '72Bundle',
|
symbol: '72Bundle',
|
||||||
templateIndex: 1,
|
templateIndex: 1,
|
||||||
baseURI: 'https://oceanprotocol.com/nft/'
|
baseURI: 'https://oceanprotocol.com/nft/'
|
||||||
}
|
}
|
||||||
const ercData = {
|
|
||||||
|
const ercParams: Erc20CreateParams = {
|
||||||
templateIndex: 1,
|
templateIndex: 1,
|
||||||
strings: ['ERC20B1', 'ERC20DT1Symbol'],
|
minter: contracts.accounts[0],
|
||||||
addresses: [
|
feeManager: user3,
|
||||||
contracts.accounts[0],
|
mpFeeAddress: contracts.accounts[0],
|
||||||
user3,
|
feeToken: '0x0000000000000000000000000000000000000000',
|
||||||
contracts.accounts[0],
|
cap: '1000000',
|
||||||
'0x0000000000000000000000000000000000000000'
|
feeAmount: '0',
|
||||||
],
|
name: 'ERC20B1',
|
||||||
uints: [web3.utils.toWei('1000000'), 0],
|
symbol: 'ERC20DT1Symbol'
|
||||||
bytess: []
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const basetokenInitialLiq = await pool.amountToUnits(contracts.daiAddress, '2000')
|
const poolParams: PoolCreationParams = {
|
||||||
|
ssContract: contracts.sideStakingAddress,
|
||||||
const poolData = {
|
basetokenAddress: contracts.daiAddress,
|
||||||
addresses: [
|
basetokenSender: contracts.factory721Address,
|
||||||
contracts.sideStakingAddress,
|
publisherAddress: contracts.accounts[0],
|
||||||
contracts.daiAddress,
|
marketFeeCollector: contracts.accounts[0],
|
||||||
contracts.factory721Address,
|
poolTemplateAddress: contracts.poolTemplateAddress,
|
||||||
contracts.accounts[0],
|
rate: '1',
|
||||||
contracts.accounts[0],
|
basetokenDecimals: 18,
|
||||||
contracts.poolTemplateAddress
|
vestingAmount: '10000',
|
||||||
],
|
vestedBlocks: vestedBlocks,
|
||||||
ssParams: [
|
initialBasetokenLiquidity: '2000',
|
||||||
web3.utils.toWei('1'), // rate
|
swapFeeLiquidityProvider: 1e15,
|
||||||
18, // basetokenDecimals
|
swapFeeMarketPlaceRunner: 1e15
|
||||||
web3.utils.toWei('10000'),
|
|
||||||
vestedBlocks, // vested blocks
|
|
||||||
web3.utils.toWei('2000') // baseToken initial pool liquidity
|
|
||||||
],
|
|
||||||
swapFees: [
|
|
||||||
1e15, //
|
|
||||||
1e15
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const nftFactory = new NFTFactory(contracts.factory721Address, web3, LoggerInstance)
|
|
||||||
|
|
||||||
const txReceipt = await nftFactory.createNftErcWithPool(
|
const txReceipt = await nftFactory.createNftErcWithPool(
|
||||||
contracts.accounts[0],
|
contracts.accounts[0],
|
||||||
nftData,
|
nftData,
|
||||||
ercData,
|
ercParams,
|
||||||
poolData
|
poolParams
|
||||||
)
|
)
|
||||||
|
|
||||||
initialBlock = await web3.eth.getBlockNumber()
|
initialBlock = await web3.eth.getBlockNumber()
|
||||||
erc20Token = txReceipt.events.TokenCreated.returnValues.newTokenAddress
|
erc20Token = txReceipt.events.TokenCreated.returnValues.newTokenAddress
|
||||||
poolAddress = txReceipt.events.NewPool.returnValues.poolAddress
|
poolAddress = txReceipt.events.NewPool.returnValues.poolAddress
|
||||||
@ -420,58 +414,52 @@ describe('SideStaking unit test', () => {
|
|||||||
it('#create a pool', async () => {
|
it('#create a pool', async () => {
|
||||||
// CREATE A POOL
|
// CREATE A POOL
|
||||||
// we prepare transaction parameters objects
|
// we prepare transaction parameters objects
|
||||||
const nftData = {
|
const nftFactory = new NFTFactory(contracts.factory721Address, web3)
|
||||||
|
|
||||||
|
const nftData: NFTCreateData = {
|
||||||
name: '72120Bundle',
|
name: '72120Bundle',
|
||||||
symbol: '72Bundle',
|
symbol: '72Bundle',
|
||||||
templateIndex: 1,
|
templateIndex: 1,
|
||||||
baseURI: 'https://oceanprotocol.com/nft/'
|
baseURI: 'https://oceanprotocol.com/nft/'
|
||||||
}
|
}
|
||||||
const ercData = {
|
|
||||||
|
const ercParams: Erc20CreateParams = {
|
||||||
templateIndex: 1,
|
templateIndex: 1,
|
||||||
strings: ['ERC20B1', 'ERC20DT1Symbol'],
|
minter: contracts.accounts[0],
|
||||||
addresses: [
|
feeManager: user3,
|
||||||
contracts.accounts[0],
|
mpFeeAddress: contracts.accounts[0],
|
||||||
user3,
|
feeToken: '0x0000000000000000000000000000000000000000',
|
||||||
contracts.accounts[0],
|
cap: '1000000',
|
||||||
'0x0000000000000000000000000000000000000000'
|
feeAmount: '0',
|
||||||
],
|
name: 'ERC20B1',
|
||||||
uints: [web3.utils.toWei('1000000'), 0],
|
symbol: 'ERC20DT1Symbol'
|
||||||
bytess: []
|
|
||||||
}
|
|
||||||
const basetokenInitialLiq = Number(
|
|
||||||
await pool.amountToUnits(contracts.usdcAddress, '2000')
|
|
||||||
)
|
|
||||||
|
|
||||||
const poolData = {
|
|
||||||
addresses: [
|
|
||||||
contracts.sideStakingAddress,
|
|
||||||
contracts.usdcAddress,
|
|
||||||
contracts.factory721Address,
|
|
||||||
contracts.accounts[0],
|
|
||||||
contracts.accounts[0],
|
|
||||||
contracts.poolTemplateAddress
|
|
||||||
],
|
|
||||||
ssParams: [
|
|
||||||
web3.utils.toWei('1'), // rate
|
|
||||||
await usdcContract.methods.decimals().call(), // basetokenDecimals
|
|
||||||
web3.utils.toWei('10000'),
|
|
||||||
2500000, // vested blocks
|
|
||||||
basetokenInitialLiq // baseToken initial pool liquidity
|
|
||||||
],
|
|
||||||
swapFees: [
|
|
||||||
1e15, //
|
|
||||||
1e15
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const nftFactory = new NFTFactory(contracts.factory721Address, web3, LoggerInstance)
|
const poolParams: PoolCreationParams = {
|
||||||
|
ssContract: contracts.sideStakingAddress,
|
||||||
|
basetokenAddress: contracts.usdcAddress,
|
||||||
|
basetokenSender: contracts.factory721Address,
|
||||||
|
publisherAddress: contracts.accounts[0],
|
||||||
|
marketFeeCollector: contracts.accounts[0],
|
||||||
|
poolTemplateAddress: contracts.poolTemplateAddress,
|
||||||
|
rate: '1',
|
||||||
|
basetokenDecimals: await usdcContract.methods.decimals().call(),
|
||||||
|
vestingAmount: '10000',
|
||||||
|
vestedBlocks: 2500000,
|
||||||
|
initialBasetokenLiquidity: web3.utils.fromWei(
|
||||||
|
await pool.amountToUnits(contracts.usdcAddress, '2000')
|
||||||
|
),
|
||||||
|
swapFeeLiquidityProvider: 1e15,
|
||||||
|
swapFeeMarketPlaceRunner: 1e15
|
||||||
|
}
|
||||||
|
|
||||||
const txReceipt = await nftFactory.createNftErcWithPool(
|
const txReceipt = await nftFactory.createNftErcWithPool(
|
||||||
contracts.accounts[0],
|
contracts.accounts[0],
|
||||||
nftData,
|
nftData,
|
||||||
ercData,
|
ercParams,
|
||||||
poolData
|
poolParams
|
||||||
)
|
)
|
||||||
|
|
||||||
initialBlock = await web3.eth.getBlockNumber()
|
initialBlock = await web3.eth.getBlockNumber()
|
||||||
erc20Token = txReceipt.events.TokenCreated.returnValues.newTokenAddress
|
erc20Token = txReceipt.events.TokenCreated.returnValues.newTokenAddress
|
||||||
poolAddress = txReceipt.events.NewPool.returnValues.poolAddress
|
poolAddress = txReceipt.events.NewPool.returnValues.poolAddress
|
||||||
|
Loading…
x
Reference in New Issue
Block a user