mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
updated unit tests
This commit is contained in:
parent
96ec95cfa2
commit
ee6e935c0c
@ -816,9 +816,6 @@ export class Datatoken {
|
|||||||
* @param {String} consumer Consumer Address
|
* @param {String} consumer Consumer Address
|
||||||
* @param {String} amount Amount of tokens that is going to be transfered
|
* @param {String} amount Amount of tokens that is going to be transfered
|
||||||
* @param {Number} serviceIndex Service index in the metadata
|
* @param {Number} serviceIndex Service index in the metadata
|
||||||
* @param {String} mpFeeAddress Consume marketplace fee address
|
|
||||||
* @param {String} feeToken address of the token marketplace wants to add fee on top
|
|
||||||
* @param {String} feeAmount amount of feeToken to be transferred to mpFeeAddress on top, will be converted to WEI
|
|
||||||
* @param {Contract} contractInstance optional contract instance
|
* @param {Contract} contractInstance optional contract instance
|
||||||
* @return {Promise<any>}
|
* @return {Promise<any>}
|
||||||
*/
|
*/
|
||||||
@ -852,9 +849,6 @@ export class Datatoken {
|
|||||||
* @param {String} consumer Consumer Address
|
* @param {String} consumer Consumer Address
|
||||||
* @param {String} amount Amount of tokens that is going to be transfered
|
* @param {String} amount Amount of tokens that is going to be transfered
|
||||||
* @param {Number} serviceIndex Service index in the metadata
|
* @param {Number} serviceIndex Service index in the metadata
|
||||||
* @param {String} mpFeeAddress Consume marketplace fee address
|
|
||||||
* @param {String} feeToken address of the token marketplace wants to add fee on top
|
|
||||||
* @param {String} feeAmount amount of feeToken to be transferred to mpFeeAddress on top, will be converted to WEI
|
|
||||||
* @return {Promise<TransactionReceipt>} string
|
* @return {Promise<TransactionReceipt>} string
|
||||||
*/
|
*/
|
||||||
public async startOrder(
|
public async startOrder(
|
||||||
|
@ -15,6 +15,6 @@ export interface FreOrderParams {
|
|||||||
exchangeContract: string
|
exchangeContract: string
|
||||||
exchangeId: string
|
exchangeId: string
|
||||||
maxBaseTokenAmount: string
|
maxBaseTokenAmount: string
|
||||||
swapMarketFee: number
|
swapMarketFee: string
|
||||||
marketFeeAddress: string
|
marketFeeAddress: string
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,6 @@ import Decimal from 'decimal.js'
|
|||||||
import {
|
import {
|
||||||
CurrentFees,
|
CurrentFees,
|
||||||
TokenInOutMarket,
|
TokenInOutMarket,
|
||||||
AmountsInOutMaxFee,
|
|
||||||
AmountsInMaxFee,
|
AmountsInMaxFee,
|
||||||
AmountsOutMaxFee
|
AmountsOutMaxFee
|
||||||
} from '../../interfaces'
|
} from '../../interfaces'
|
||||||
@ -778,11 +777,8 @@ export class Pool {
|
|||||||
* Estimate gas cost for swapExactAmountIn
|
* Estimate gas cost for swapExactAmountIn
|
||||||
* @param {String} address
|
* @param {String} address
|
||||||
* @param {String} poolAddress
|
* @param {String} poolAddress
|
||||||
* @param {String} tokenIn
|
* @param {TokenInOutMarket} tokenInOutMarket
|
||||||
* @param {String} tokenAmountIn will be converted to wei
|
* @param {AmountsInMaxFee} amountsInOutMaxFee
|
||||||
* @param {String} tokenOut
|
|
||||||
* @param {String} minAmountOut will be converted to wei
|
|
||||||
* @param {String} maxPrice will be converted to wei
|
|
||||||
* @param {Contract} contractInstance optional contract instance
|
* @param {Contract} contractInstance optional contract instance
|
||||||
* @return {Promise<number>}
|
* @return {Promise<number>}
|
||||||
*/
|
*/
|
||||||
@ -811,7 +807,7 @@ export class Pool {
|
|||||||
amountsInOutMaxFee.tokenAmountIn,
|
amountsInOutMaxFee.tokenAmountIn,
|
||||||
amountsInOutMaxFee.minAmountOut,
|
amountsInOutMaxFee.minAmountOut,
|
||||||
this.web3.utils.toWei(amountsInOutMaxFee.maxPrice),
|
this.web3.utils.toWei(amountsInOutMaxFee.maxPrice),
|
||||||
amountsInOutMaxFee.swapMarketFee
|
this.web3.utils.toWei(amountsInOutMaxFee.swapMarketFee)
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
||||||
@ -822,21 +818,22 @@ export class Pool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* swapExactAmountIn - Trades an exact tokenAmountIn of tokenIn taken from the caller by the pool, in exchange for at least minAmountOut of tokenOut given to the caller from the pool, with a maximum marginal price of maxPrice. Returns (tokenAmountOut, spotPriceAfter), where tokenAmountOut is the amount of token that came out of the pool, and spotPriceAfter is the new marginal spot price, ie, the result of getSpotPrice after the call. (These values are what are limited by the arguments; you are guaranteed tokenAmountOut >= minAmountOut and spotPriceAfter <= maxPrice).
|
* swapExactAmountIn - Trades an exact tokenAmountIn of tokenIn taken from the caller by the pool,
|
||||||
|
* in exchange for at least minAmountOut of tokenOut given to the caller from the pool, with a maximum marginal price of maxPrice.
|
||||||
|
* Returns (tokenAmountOut, spotPriceAfter), where tokenAmountOut is the amount of token that came out of the pool,
|
||||||
|
* and spotPriceAfter is the new marginal spot price, ie, the result of getSpotPrice after the call.
|
||||||
|
* (These values are what are limited by the arguments; you are guaranteed tokenAmountOut >= minAmountOut and spotPriceAfter <= maxPrice).
|
||||||
* @param {String} address
|
* @param {String} address
|
||||||
* @param {String} poolAddress
|
* @param {String} poolAddress
|
||||||
* @param {String} tokenIn
|
* @param {TokenInOutMarket} tokenInOutMarket
|
||||||
* @param {String} tokenAmountIn will be converted to wei
|
* @param {AmountsInMaxFee} amountsInOutMaxFee
|
||||||
* @param {String} tokenOut
|
|
||||||
* @param {String} minAmountOut will be converted to wei
|
|
||||||
* @param {String} maxPrice will be converted to wei
|
|
||||||
* @return {TransactionReceipt}
|
* @return {TransactionReceipt}
|
||||||
*/
|
*/
|
||||||
async swapExactAmountIn(
|
async swapExactAmountIn(
|
||||||
address: string,
|
address: string,
|
||||||
poolAddress: string,
|
poolAddress: string,
|
||||||
tokenInOutMarket: TokenInOutMarket,
|
tokenInOutMarket: TokenInOutMarket,
|
||||||
amountsInOutMaxFee: AmountsInOutMaxFee
|
amountsInOutMaxFee: AmountsInMaxFee
|
||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
const pool = new this.web3.eth.Contract(this.poolABI, poolAddress)
|
const pool = new this.web3.eth.Contract(this.poolABI, poolAddress)
|
||||||
|
|
||||||
@ -871,7 +868,7 @@ export class Pool {
|
|||||||
amountsInOutMaxFee.tokenAmountIn,
|
amountsInOutMaxFee.tokenAmountIn,
|
||||||
amountsInOutMaxFee.minAmountOut,
|
amountsInOutMaxFee.minAmountOut,
|
||||||
this.web3.utils.toWei(amountsInOutMaxFee.maxPrice),
|
this.web3.utils.toWei(amountsInOutMaxFee.maxPrice),
|
||||||
amountsInOutMaxFee.swapMarketFee
|
this.web3.utils.toWei(amountsInOutMaxFee.swapMarketFee)
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
.send({
|
.send({
|
||||||
@ -890,11 +887,8 @@ export class Pool {
|
|||||||
* Estimate gas cost for swapExactAmountOut
|
* Estimate gas cost for swapExactAmountOut
|
||||||
* @param {String} address
|
* @param {String} address
|
||||||
* @param {String} poolAddress
|
* @param {String} poolAddress
|
||||||
* @param {String} tokenIn
|
* @param {TokenInOutMarket} tokenInOutMarket
|
||||||
* @param {String} tokenAmountIn will be converted to wei
|
* @param {AmountsOutMaxFee} amountsInOutMaxFee
|
||||||
* @param {String} tokenOut
|
|
||||||
* @param {String} minAmountOut will be converted to wei
|
|
||||||
* @param {String} maxPrice will be converted to wei
|
|
||||||
* @param {Contract} contractInstance optional contract instance
|
* @param {Contract} contractInstance optional contract instance
|
||||||
* @return {Promise<number>}
|
* @return {Promise<number>}
|
||||||
*/
|
*/
|
||||||
@ -923,7 +917,7 @@ export class Pool {
|
|||||||
amountsInOutMaxFee.maxAmountIn,
|
amountsInOutMaxFee.maxAmountIn,
|
||||||
amountsInOutMaxFee.tokenAmountOut,
|
amountsInOutMaxFee.tokenAmountOut,
|
||||||
this.web3.utils.toWei(amountsInOutMaxFee.maxPrice),
|
this.web3.utils.toWei(amountsInOutMaxFee.maxPrice),
|
||||||
amountsInOutMaxFee.swapMarketFee
|
this.web3.utils.toWei(amountsInOutMaxFee.swapMarketFee)
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
||||||
@ -937,11 +931,8 @@ export class Pool {
|
|||||||
* swapExactAmountOut
|
* swapExactAmountOut
|
||||||
* @param {String} account
|
* @param {String} account
|
||||||
* @param {String} poolAddress
|
* @param {String} poolAddress
|
||||||
* @param {String} tokenIn
|
* @param {TokenInOutMarket} tokenInOutMarket
|
||||||
* @param {String} maxAmountIn will be converted to wei
|
* @param {AmountsOutMaxFee} amountsInOutMaxFee
|
||||||
* @param {String} tokenOut
|
|
||||||
* @param {String} amountOut will be converted to wei
|
|
||||||
* @param {String} maxPrice will be converted to wei
|
|
||||||
* @return {TransactionReceipt}
|
* @return {TransactionReceipt}
|
||||||
*/
|
*/
|
||||||
async swapExactAmountOut(
|
async swapExactAmountOut(
|
||||||
@ -980,7 +971,7 @@ export class Pool {
|
|||||||
amountsInOutMaxFee.maxAmountIn,
|
amountsInOutMaxFee.maxAmountIn,
|
||||||
amountsInOutMaxFee.tokenAmountOut,
|
amountsInOutMaxFee.tokenAmountOut,
|
||||||
this.web3.utils.toWei(amountsInOutMaxFee.maxPrice),
|
this.web3.utils.toWei(amountsInOutMaxFee.maxPrice),
|
||||||
amountsInOutMaxFee.swapMarketFee
|
this.web3.utils.toWei(amountsInOutMaxFee.swapMarketFee)
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
.send({
|
.send({
|
||||||
@ -1470,13 +1461,14 @@ export class Pool {
|
|||||||
* @param {String} poolAddress
|
* @param {String} poolAddress
|
||||||
* @param {String} tokenIn
|
* @param {String} tokenIn
|
||||||
* @param {String} tokenOut
|
* @param {String} tokenOut
|
||||||
|
* @param {String} swapMarketFe
|
||||||
* @return {String}
|
* @return {String}
|
||||||
*/
|
*/
|
||||||
async getSpotPrice(
|
async getSpotPrice(
|
||||||
poolAddress: string,
|
poolAddress: string,
|
||||||
tokenIn: string,
|
tokenIn: string,
|
||||||
tokenOut: string,
|
tokenOut: string,
|
||||||
swapMarketFe: number
|
swapMarketFee: 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)
|
||||||
let decimalsTokenIn = 18
|
let decimalsTokenIn = 18
|
||||||
@ -1503,7 +1495,9 @@ export class Pool {
|
|||||||
|
|
||||||
let price = null
|
let price = null
|
||||||
try {
|
try {
|
||||||
price = await pool.methods.getSpotPrice(tokenIn, tokenOut, swapMarketFe).call()
|
price = await pool.methods
|
||||||
|
.getSpotPrice(tokenIn, tokenOut, this.web3.utils.toWei(swapMarketFee))
|
||||||
|
.call()
|
||||||
price = new BigNumber(price.toString())
|
price = new BigNumber(price.toString())
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.logger.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')
|
||||||
@ -1541,7 +1535,12 @@ export class Pool {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const result = await pool.methods
|
const result = await pool.methods
|
||||||
.getAmountInExactOut(tokenIn, tokenOut, amountOutFormatted, swapMarketFee)
|
.getAmountInExactOut(
|
||||||
|
tokenIn,
|
||||||
|
tokenOut,
|
||||||
|
amountOutFormatted,
|
||||||
|
this.web3.utils.toWei(swapMarketFee)
|
||||||
|
)
|
||||||
.call()
|
.call()
|
||||||
amount = await this.unitsToAmount(tokenIn, result)
|
amount = await this.unitsToAmount(tokenIn, result)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -1565,7 +1564,12 @@ export class Pool {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const result = await pool.methods
|
const result = await pool.methods
|
||||||
.getAmountOutExactIn(tokenIn, tokenOut, amountInFormatted, swapMarketFee)
|
.getAmountOutExactIn(
|
||||||
|
tokenIn,
|
||||||
|
tokenOut,
|
||||||
|
amountInFormatted,
|
||||||
|
this.web3.utils.toWei(swapMarketFee)
|
||||||
|
)
|
||||||
.call()
|
.call()
|
||||||
|
|
||||||
amount = await this.unitsToAmount(tokenOut, result)
|
amount = await this.unitsToAmount(tokenOut, result)
|
||||||
|
@ -253,16 +253,7 @@ describe('Datatoken', () => {
|
|||||||
'User2 does not hold 0 datatokens'
|
'User2 does not hold 0 datatokens'
|
||||||
)
|
)
|
||||||
|
|
||||||
const order = await datatoken.startOrder(
|
const order = await datatoken.startOrder(datatokenAddress, user1, user2, '1', 1)
|
||||||
datatokenAddress,
|
|
||||||
user1,
|
|
||||||
user2,
|
|
||||||
'1',
|
|
||||||
1,
|
|
||||||
user3,
|
|
||||||
'0x0000000000000000000000000000000000000000',
|
|
||||||
'0'
|
|
||||||
)
|
|
||||||
assert(order !== null)
|
assert(order !== null)
|
||||||
|
|
||||||
assert(
|
assert(
|
||||||
@ -282,10 +273,7 @@ describe('Datatoken', () => {
|
|||||||
const order: OrderParams = {
|
const order: OrderParams = {
|
||||||
consumer: user1,
|
consumer: user1,
|
||||||
amount: '1',
|
amount: '1',
|
||||||
serviceIndex: 1,
|
serviceIndex: 1
|
||||||
consumeFeeAddress: user1,
|
|
||||||
consumeFeeToken: '0x0000000000000000000000000000000000000000',
|
|
||||||
consumeFeeAmount: '0'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const buyFromDispenseTx = await datatoken.buyFromDispenserAndOrder(
|
const buyFromDispenseTx = await datatoken.buyFromDispenserAndOrder(
|
||||||
@ -301,15 +289,15 @@ describe('Datatoken', () => {
|
|||||||
const order: OrderParams = {
|
const order: OrderParams = {
|
||||||
consumer: user1,
|
consumer: user1,
|
||||||
amount: '1',
|
amount: '1',
|
||||||
serviceIndex: 1,
|
serviceIndex: 1
|
||||||
consumeFeeAddress: user1,
|
|
||||||
consumeFeeToken: '0x0000000000000000000000000000000000000000',
|
|
||||||
consumeFeeAmount: '0'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const fre: FreOrderParams = {
|
const fre: FreOrderParams = {
|
||||||
exchangeContract: fixedRateAddress,
|
exchangeContract: fixedRateAddress,
|
||||||
exchangeId: exchangeId,
|
exchangeId: exchangeId,
|
||||||
maxBaseTokenAmount: '1'
|
maxBaseTokenAmount: '1',
|
||||||
|
swapMarketFee: this.web3.utils.toWei('0.1'),
|
||||||
|
marketFeeAddress: '0x0000000000000000000000000000000000000000'
|
||||||
}
|
}
|
||||||
|
|
||||||
const buyTx = await datatoken.buyFromFreAndOrder(datatokenAddress, user1, order, fre)
|
const buyTx = await datatoken.buyFromFreAndOrder(datatokenAddress, user1, order, fre)
|
||||||
|
@ -14,7 +14,7 @@ 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 { LoggerInstance } from '../../src/utils'
|
import { LoggerInstance } from '../../src/utils'
|
||||||
// import { NFTDataToken } from '../../../src/datatokens/NFTDatatoken'
|
// import { NFTDataToken } from '../../../src/datatokens/NFTDatatoken'
|
||||||
import { NFTFactory, NFTCreateData } from '../../src/factories/NFTFactory'
|
import { NFTFactory, NFTCreateData, TokenOrder } from '../../src/factories/NFTFactory'
|
||||||
import {
|
import {
|
||||||
FreCreationParams,
|
FreCreationParams,
|
||||||
Erc20CreateParams,
|
Erc20CreateParams,
|
||||||
@ -343,24 +343,18 @@ describe('NFT Factory test', () => {
|
|||||||
expect(await dtContract.methods.balanceOf(user2).call()).to.equal(dtAmount)
|
expect(await dtContract.methods.balanceOf(user2).call()).to.equal(dtAmount)
|
||||||
expect(await dtContract2.methods.balanceOf(user2).call()).to.equal(dtAmount)
|
expect(await dtContract2.methods.balanceOf(user2).call()).to.equal(dtAmount)
|
||||||
|
|
||||||
const orders = [
|
const orders: TokenOrder[] = [
|
||||||
{
|
{
|
||||||
tokenAddress: dtAddress,
|
tokenAddress: dtAddress,
|
||||||
consumer: consumer,
|
consumer: consumer,
|
||||||
amount: dtAmount,
|
amount: dtAmount,
|
||||||
serviceIndex: serviceIndex,
|
serviceIndex: serviceIndex
|
||||||
consumeFeeAddress: consumeFeeAddress,
|
|
||||||
consumeFeeToken: consumeFeeToken,
|
|
||||||
consumeFeeAmount: consumeFeeAmount
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
tokenAddress: dtAddress2,
|
tokenAddress: dtAddress2,
|
||||||
consumer: consumer,
|
consumer: consumer,
|
||||||
amount: dtAmount,
|
amount: dtAmount,
|
||||||
serviceIndex: serviceIndex,
|
serviceIndex: serviceIndex
|
||||||
consumeFeeAddress: consumeFeeAddress,
|
|
||||||
consumeFeeToken: consumeFeeToken,
|
|
||||||
consumeFeeAmount: consumeFeeAmount
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -20,11 +20,16 @@ import { Pool } from '../../../../src/pools/balancer/Pool'
|
|||||||
import {
|
import {
|
||||||
PoolCreationParams,
|
PoolCreationParams,
|
||||||
Erc20CreateParams,
|
Erc20CreateParams,
|
||||||
CurrentFees
|
CurrentFees,
|
||||||
|
TokenInOutMarket,
|
||||||
|
AmountsInMaxFee,
|
||||||
|
AmountsOutMaxFee
|
||||||
} from '../../../../src/interfaces'
|
} 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'
|
||||||
|
const MaxUint256 =
|
||||||
|
'115792089237316195423570985008687907853269984665640564039457584007913129639934'
|
||||||
|
|
||||||
describe('Pool unit test', () => {
|
describe('Pool unit test', () => {
|
||||||
let factoryOwner: string
|
let factoryOwner: string
|
||||||
@ -272,13 +277,22 @@ describe('Pool unit test', () => {
|
|||||||
)
|
)
|
||||||
expect(await erc20Contract.methods.balanceOf(user2).call()).to.equal('0')
|
expect(await erc20Contract.methods.balanceOf(user2).call()).to.equal('0')
|
||||||
await pool.approve(user2, contracts.daiAddress, poolAddress, '10')
|
await pool.approve(user2, contracts.daiAddress, poolAddress, '10')
|
||||||
|
const tokenInOutMarket: TokenInOutMarket = {
|
||||||
|
tokenIn: contracts.daiAddress,
|
||||||
|
tokenOut: erc20Token,
|
||||||
|
marketFeeAddress: '0x0000000000000000000000000000000000000000'
|
||||||
|
}
|
||||||
|
const amountsInOutMaxFee: AmountsInMaxFee = {
|
||||||
|
tokenAmountIn: '10',
|
||||||
|
minAmountOut: '1',
|
||||||
|
maxPrice: MaxUint256,
|
||||||
|
swapMarketFee: '0.1'
|
||||||
|
}
|
||||||
const tx = await pool.swapExactAmountIn(
|
const tx = await pool.swapExactAmountIn(
|
||||||
user2,
|
user2,
|
||||||
poolAddress,
|
poolAddress,
|
||||||
contracts.daiAddress,
|
tokenInOutMarket,
|
||||||
'10',
|
amountsInOutMaxFee
|
||||||
erc20Token,
|
|
||||||
'1'
|
|
||||||
)
|
)
|
||||||
expect(await erc20Contract.methods.balanceOf(user2).call()).to.equal(
|
expect(await erc20Contract.methods.balanceOf(user2).call()).to.equal(
|
||||||
tx.events.LOG_SWAP.returnValues.tokenAmountOut
|
tx.events.LOG_SWAP.returnValues.tokenAmountOut
|
||||||
@ -290,13 +304,22 @@ describe('Pool unit test', () => {
|
|||||||
expect(await daiContract.methods.balanceOf(user2).call()).to.equal(
|
expect(await daiContract.methods.balanceOf(user2).call()).to.equal(
|
||||||
web3.utils.toWei('990')
|
web3.utils.toWei('990')
|
||||||
)
|
)
|
||||||
|
const tokenInOutMarket: TokenInOutMarket = {
|
||||||
|
tokenIn: contracts.daiAddress,
|
||||||
|
tokenOut: erc20Token,
|
||||||
|
marketFeeAddress: '0x0000000000000000000000000000000000000000'
|
||||||
|
}
|
||||||
|
const amountsInOutMaxFee: AmountsOutMaxFee = {
|
||||||
|
maxAmountIn: '100',
|
||||||
|
tokenAmountOut: '50',
|
||||||
|
maxPrice: MaxUint256,
|
||||||
|
swapMarketFee: '0.1'
|
||||||
|
}
|
||||||
const tx = await pool.swapExactAmountOut(
|
const tx = await pool.swapExactAmountOut(
|
||||||
user2,
|
user2,
|
||||||
poolAddress,
|
poolAddress,
|
||||||
contracts.daiAddress,
|
tokenInOutMarket,
|
||||||
'100',
|
amountsInOutMaxFee
|
||||||
erc20Token,
|
|
||||||
'50'
|
|
||||||
)
|
)
|
||||||
assert(tx != null)
|
assert(tx != null)
|
||||||
})
|
})
|
||||||
@ -428,7 +451,8 @@ describe('Pool unit test', () => {
|
|||||||
poolAddress,
|
poolAddress,
|
||||||
erc20Token,
|
erc20Token,
|
||||||
contracts.daiAddress,
|
contracts.daiAddress,
|
||||||
exactDAIOut
|
exactDAIOut,
|
||||||
|
'0.1'
|
||||||
)
|
)
|
||||||
|
|
||||||
assert(amountIn != null)
|
assert(amountIn != null)
|
||||||
@ -438,7 +462,8 @@ describe('Pool unit test', () => {
|
|||||||
const spotPrice = await pool.getSpotPrice(
|
const spotPrice = await pool.getSpotPrice(
|
||||||
poolAddress,
|
poolAddress,
|
||||||
erc20Token,
|
erc20Token,
|
||||||
contracts.daiAddress
|
contracts.daiAddress,
|
||||||
|
'0.1'
|
||||||
)
|
)
|
||||||
|
|
||||||
// amount of DAI In will be slightly bigger than spotPrice
|
// amount of DAI In will be slightly bigger than spotPrice
|
||||||
@ -452,7 +477,8 @@ describe('Pool unit test', () => {
|
|||||||
poolAddress,
|
poolAddress,
|
||||||
erc20Token,
|
erc20Token,
|
||||||
contracts.daiAddress,
|
contracts.daiAddress,
|
||||||
exactDTIn
|
exactDTIn,
|
||||||
|
'0.1'
|
||||||
)
|
)
|
||||||
|
|
||||||
assert(amountOut != null)
|
assert(amountOut != null)
|
||||||
@ -460,7 +486,8 @@ describe('Pool unit test', () => {
|
|||||||
const spotPrice = await pool.getSpotPrice(
|
const spotPrice = await pool.getSpotPrice(
|
||||||
poolAddress,
|
poolAddress,
|
||||||
contracts.daiAddress,
|
contracts.daiAddress,
|
||||||
erc20Token
|
erc20Token,
|
||||||
|
'0.1'
|
||||||
)
|
)
|
||||||
// amount of DAI received will be slightly less than spotPrice
|
// amount of DAI received will be slightly less than spotPrice
|
||||||
assert(amountOut < spotPrice)
|
assert(amountOut < spotPrice)
|
||||||
@ -468,10 +495,12 @@ describe('Pool unit test', () => {
|
|||||||
|
|
||||||
it('#getSpotPrice- should get the spot price', async () => {
|
it('#getSpotPrice- should get the spot price', async () => {
|
||||||
assert(
|
assert(
|
||||||
(await pool.getSpotPrice(poolAddress, erc20Token, contracts.daiAddress)) != null
|
(await pool.getSpotPrice(poolAddress, erc20Token, contracts.daiAddress, '0.1')) !=
|
||||||
|
null
|
||||||
)
|
)
|
||||||
assert(
|
assert(
|
||||||
(await pool.getSpotPrice(poolAddress, contracts.daiAddress, erc20Token)) != null
|
(await pool.getSpotPrice(poolAddress, contracts.daiAddress, erc20Token, '0.1')) !=
|
||||||
|
null
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -494,7 +523,8 @@ describe('Pool unit test', () => {
|
|||||||
const spotPriceBefore = await pool.getSpotPrice(
|
const spotPriceBefore = await pool.getSpotPrice(
|
||||||
poolAddress,
|
poolAddress,
|
||||||
erc20Token,
|
erc20Token,
|
||||||
contracts.daiAddress
|
contracts.daiAddress,
|
||||||
|
'0.1'
|
||||||
)
|
)
|
||||||
|
|
||||||
// contracts.accounts[0] is the marketFeeCollector
|
// contracts.accounts[0] is the marketFeeCollector
|
||||||
@ -508,8 +538,12 @@ describe('Pool unit test', () => {
|
|||||||
|
|
||||||
// Spot price hasn't changed after fee collection
|
// Spot price hasn't changed after fee collection
|
||||||
assert(
|
assert(
|
||||||
(await pool.getSpotPrice(poolAddress, erc20Token, contracts.daiAddress)) ===
|
(await pool.getSpotPrice(
|
||||||
spotPriceBefore
|
poolAddress,
|
||||||
|
erc20Token,
|
||||||
|
contracts.daiAddress,
|
||||||
|
'0.1'
|
||||||
|
)) === spotPriceBefore
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -526,7 +560,8 @@ describe('Pool unit test', () => {
|
|||||||
const spotPriceBefore = await pool.getSpotPrice(
|
const spotPriceBefore = await pool.getSpotPrice(
|
||||||
poolAddress,
|
poolAddress,
|
||||||
erc20Token,
|
erc20Token,
|
||||||
contracts.daiAddress
|
contracts.daiAddress,
|
||||||
|
'0.1'
|
||||||
)
|
)
|
||||||
// some fee are available in DAI
|
// some fee are available in DAI
|
||||||
assert((await pool.getCommunityFees(poolAddress, contracts.daiAddress)) > '0')
|
assert((await pool.getCommunityFees(poolAddress, contracts.daiAddress)) > '0')
|
||||||
@ -545,8 +580,12 @@ describe('Pool unit test', () => {
|
|||||||
)
|
)
|
||||||
// Spot price hasn't changed after fee collection
|
// Spot price hasn't changed after fee collection
|
||||||
assert(
|
assert(
|
||||||
(await pool.getSpotPrice(poolAddress, erc20Token, contracts.daiAddress)) ===
|
(await pool.getSpotPrice(
|
||||||
spotPriceBefore
|
poolAddress,
|
||||||
|
erc20Token,
|
||||||
|
contracts.daiAddress,
|
||||||
|
'0.1'
|
||||||
|
)) === spotPriceBefore
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -785,13 +824,22 @@ describe('Pool unit test', () => {
|
|||||||
|
|
||||||
expect(await erc20Contract.methods.balanceOf(user2).call()).to.equal('0')
|
expect(await erc20Contract.methods.balanceOf(user2).call()).to.equal('0')
|
||||||
await pool.approve(user2, contracts.usdcAddress, poolAddress, '10')
|
await pool.approve(user2, contracts.usdcAddress, poolAddress, '10')
|
||||||
|
const tokenInOutMarket: TokenInOutMarket = {
|
||||||
|
tokenIn: contracts.usdcAddress,
|
||||||
|
tokenOut: erc20Token,
|
||||||
|
marketFeeAddress: '0x0000000000000000000000000000000000000000'
|
||||||
|
}
|
||||||
|
const amountsInOutMaxFee: AmountsInMaxFee = {
|
||||||
|
tokenAmountIn: '10',
|
||||||
|
minAmountOut: '1',
|
||||||
|
maxPrice: MaxUint256,
|
||||||
|
swapMarketFee: '0.1'
|
||||||
|
}
|
||||||
const tx = await pool.swapExactAmountIn(
|
const tx = await pool.swapExactAmountIn(
|
||||||
user2,
|
user2,
|
||||||
poolAddress,
|
poolAddress,
|
||||||
contracts.usdcAddress,
|
tokenInOutMarket,
|
||||||
'10',
|
amountsInOutMaxFee
|
||||||
erc20Token,
|
|
||||||
'1'
|
|
||||||
)
|
)
|
||||||
expect(await erc20Contract.methods.balanceOf(user2).call()).to.equal(
|
expect(await erc20Contract.methods.balanceOf(user2).call()).to.equal(
|
||||||
tx.events.LOG_SWAP.returnValues.tokenAmountOut
|
tx.events.LOG_SWAP.returnValues.tokenAmountOut
|
||||||
@ -803,13 +851,22 @@ describe('Pool unit test', () => {
|
|||||||
(await pool.amountToUnits(contracts.usdcAddress, '990')).toString()
|
(await pool.amountToUnits(contracts.usdcAddress, '990')).toString()
|
||||||
)
|
)
|
||||||
await pool.approve(user2, contracts.usdcAddress, poolAddress, '100')
|
await pool.approve(user2, contracts.usdcAddress, poolAddress, '100')
|
||||||
|
const tokenInOutMarket: TokenInOutMarket = {
|
||||||
|
tokenIn: contracts.usdcAddress,
|
||||||
|
tokenOut: erc20Token,
|
||||||
|
marketFeeAddress: '0x0000000000000000000000000000000000000000'
|
||||||
|
}
|
||||||
|
const amountsInOutMaxFee: AmountsOutMaxFee = {
|
||||||
|
maxAmountIn: '100',
|
||||||
|
tokenAmountOut: '50',
|
||||||
|
maxPrice: MaxUint256,
|
||||||
|
swapMarketFee: '0.1'
|
||||||
|
}
|
||||||
const tx = await pool.swapExactAmountOut(
|
const tx = await pool.swapExactAmountOut(
|
||||||
user2,
|
user2,
|
||||||
poolAddress,
|
poolAddress,
|
||||||
contracts.usdcAddress,
|
tokenInOutMarket,
|
||||||
'100',
|
amountsInOutMaxFee
|
||||||
erc20Token,
|
|
||||||
'50'
|
|
||||||
)
|
)
|
||||||
assert(tx != null)
|
assert(tx != null)
|
||||||
// console.log(tx.events)
|
// console.log(tx.events)
|
||||||
@ -944,7 +1001,8 @@ describe('Pool unit test', () => {
|
|||||||
poolAddress,
|
poolAddress,
|
||||||
erc20Token,
|
erc20Token,
|
||||||
contracts.usdcAddress,
|
contracts.usdcAddress,
|
||||||
exactUSDCOut
|
exactUSDCOut,
|
||||||
|
'0.1'
|
||||||
)
|
)
|
||||||
|
|
||||||
assert(amountIn != null)
|
assert(amountIn != null)
|
||||||
@ -952,7 +1010,8 @@ describe('Pool unit test', () => {
|
|||||||
const spotPrice = await pool.getSpotPrice(
|
const spotPrice = await pool.getSpotPrice(
|
||||||
poolAddress,
|
poolAddress,
|
||||||
erc20Token,
|
erc20Token,
|
||||||
contracts.usdcAddress
|
contracts.usdcAddress,
|
||||||
|
'0.1'
|
||||||
)
|
)
|
||||||
// amount of USDC In will be slightly bigger than spotPrice
|
// amount of USDC In will be slightly bigger than spotPrice
|
||||||
assert(amountIn > spotPrice)
|
assert(amountIn > spotPrice)
|
||||||
@ -965,7 +1024,8 @@ describe('Pool unit test', () => {
|
|||||||
poolAddress,
|
poolAddress,
|
||||||
erc20Token,
|
erc20Token,
|
||||||
contracts.usdcAddress,
|
contracts.usdcAddress,
|
||||||
exactDTIn
|
exactDTIn,
|
||||||
|
'0.1'
|
||||||
)
|
)
|
||||||
|
|
||||||
assert(amountOut != null)
|
assert(amountOut != null)
|
||||||
@ -973,7 +1033,8 @@ describe('Pool unit test', () => {
|
|||||||
const spotPrice = await pool.getSpotPrice(
|
const spotPrice = await pool.getSpotPrice(
|
||||||
poolAddress,
|
poolAddress,
|
||||||
contracts.usdcAddress,
|
contracts.usdcAddress,
|
||||||
erc20Token
|
erc20Token,
|
||||||
|
'0.1'
|
||||||
)
|
)
|
||||||
// amount of USDC received will be slightly less than spotPrice
|
// amount of USDC received will be slightly less than spotPrice
|
||||||
assert(amountOut < spotPrice)
|
assert(amountOut < spotPrice)
|
||||||
@ -981,10 +1042,20 @@ describe('Pool unit test', () => {
|
|||||||
|
|
||||||
it('#getSpotPrice- should get the spot price', async () => {
|
it('#getSpotPrice- should get the spot price', async () => {
|
||||||
assert(
|
assert(
|
||||||
(await pool.getSpotPrice(poolAddress, erc20Token, contracts.usdcAddress)) != null
|
(await pool.getSpotPrice(
|
||||||
|
poolAddress,
|
||||||
|
erc20Token,
|
||||||
|
contracts.usdcAddress,
|
||||||
|
'0.1'
|
||||||
|
)) != null
|
||||||
)
|
)
|
||||||
assert(
|
assert(
|
||||||
(await pool.getSpotPrice(poolAddress, contracts.usdcAddress, erc20Token)) != null
|
(await pool.getSpotPrice(
|
||||||
|
poolAddress,
|
||||||
|
contracts.usdcAddress,
|
||||||
|
erc20Token,
|
||||||
|
'0.1'
|
||||||
|
)) != null
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -1007,7 +1078,8 @@ describe('Pool unit test', () => {
|
|||||||
const spotPriceBefore = await pool.getSpotPrice(
|
const spotPriceBefore = await pool.getSpotPrice(
|
||||||
poolAddress,
|
poolAddress,
|
||||||
erc20Token,
|
erc20Token,
|
||||||
contracts.usdcAddress
|
contracts.usdcAddress,
|
||||||
|
'0.1'
|
||||||
)
|
)
|
||||||
// contracts.accounts[0] is the marketFeeCollector
|
// contracts.accounts[0] is the marketFeeCollector
|
||||||
assert((await pool.getMarketFeeCollector(poolAddress)) === contracts.accounts[0])
|
assert((await pool.getMarketFeeCollector(poolAddress)) === contracts.accounts[0])
|
||||||
@ -1020,8 +1092,12 @@ describe('Pool unit test', () => {
|
|||||||
|
|
||||||
// Spot price hasn't changed after fee collection
|
// Spot price hasn't changed after fee collection
|
||||||
assert(
|
assert(
|
||||||
(await pool.getSpotPrice(poolAddress, erc20Token, contracts.usdcAddress)) ===
|
(await pool.getSpotPrice(
|
||||||
spotPriceBefore
|
poolAddress,
|
||||||
|
erc20Token,
|
||||||
|
contracts.usdcAddress,
|
||||||
|
'0.1'
|
||||||
|
)) === spotPriceBefore
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -1048,7 +1124,8 @@ describe('Pool unit test', () => {
|
|||||||
const spotPriceBefore = await pool.getSpotPrice(
|
const spotPriceBefore = await pool.getSpotPrice(
|
||||||
poolAddress,
|
poolAddress,
|
||||||
erc20Token,
|
erc20Token,
|
||||||
contracts.usdcAddress
|
contracts.usdcAddress,
|
||||||
|
'0.1'
|
||||||
)
|
)
|
||||||
// some fee are available in USDC
|
// some fee are available in USDC
|
||||||
assert((await pool.getCommunityFees(poolAddress, contracts.usdcAddress)) > '0')
|
assert((await pool.getCommunityFees(poolAddress, contracts.usdcAddress)) > '0')
|
||||||
@ -1067,8 +1144,12 @@ describe('Pool unit test', () => {
|
|||||||
)
|
)
|
||||||
// Spot price hasn't changed after fee collection
|
// Spot price hasn't changed after fee collection
|
||||||
assert(
|
assert(
|
||||||
(await pool.getSpotPrice(poolAddress, erc20Token, contracts.usdcAddress)) ===
|
(await pool.getSpotPrice(
|
||||||
spotPriceBefore
|
poolAddress,
|
||||||
|
erc20Token,
|
||||||
|
contracts.usdcAddress,
|
||||||
|
'0.1'
|
||||||
|
)) === spotPriceBefore
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -19,10 +19,18 @@ import { LoggerInstance } from '../../../../src/utils'
|
|||||||
import { NFTFactory, NFTCreateData } 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'
|
import {
|
||||||
|
Erc20CreateParams,
|
||||||
|
PoolCreationParams,
|
||||||
|
TokenInOutMarket,
|
||||||
|
AmountsInMaxFee,
|
||||||
|
AmountsOutMaxFee
|
||||||
|
} 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'
|
||||||
|
const MaxUint256 =
|
||||||
|
'115792089237316195423570985008687907853269984665640564039457584007913129639934'
|
||||||
|
|
||||||
describe('SideStaking unit test', () => {
|
describe('SideStaking unit test', () => {
|
||||||
let factoryOwner: string
|
let factoryOwner: string
|
||||||
@ -291,13 +299,23 @@ describe('SideStaking unit test', () => {
|
|||||||
)
|
)
|
||||||
expect(await erc20Contract.methods.balanceOf(user2).call()).to.equal('0')
|
expect(await erc20Contract.methods.balanceOf(user2).call()).to.equal('0')
|
||||||
await pool.approve(user2, contracts.daiAddress, poolAddress, '10')
|
await pool.approve(user2, contracts.daiAddress, poolAddress, '10')
|
||||||
|
const tokenInOutMarket: TokenInOutMarket = {
|
||||||
|
tokenIn: contracts.daiAddress,
|
||||||
|
tokenOut: erc20Token,
|
||||||
|
marketFeeAddress: '0x0000000000000000000000000000000000000000'
|
||||||
|
}
|
||||||
|
const amountsInOutMaxFee: AmountsInMaxFee = {
|
||||||
|
tokenAmountIn: '10',
|
||||||
|
minAmountOut: '1',
|
||||||
|
maxPrice: MaxUint256,
|
||||||
|
swapMarketFee: '0.1'
|
||||||
|
}
|
||||||
|
|
||||||
const tx = await pool.swapExactAmountIn(
|
const tx = await pool.swapExactAmountIn(
|
||||||
user2,
|
user2,
|
||||||
poolAddress,
|
poolAddress,
|
||||||
contracts.daiAddress,
|
tokenInOutMarket,
|
||||||
'10',
|
amountsInOutMaxFee
|
||||||
erc20Token,
|
|
||||||
'1'
|
|
||||||
)
|
)
|
||||||
expect(await erc20Contract.methods.balanceOf(user2).call()).to.equal(
|
expect(await erc20Contract.methods.balanceOf(user2).call()).to.equal(
|
||||||
tx.events.LOG_SWAP.returnValues.tokenAmountOut
|
tx.events.LOG_SWAP.returnValues.tokenAmountOut
|
||||||
@ -309,13 +327,22 @@ describe('SideStaking unit test', () => {
|
|||||||
expect(await daiContract.methods.balanceOf(user2).call()).to.equal(
|
expect(await daiContract.methods.balanceOf(user2).call()).to.equal(
|
||||||
web3.utils.toWei('990')
|
web3.utils.toWei('990')
|
||||||
)
|
)
|
||||||
|
const tokenInOutMarket: TokenInOutMarket = {
|
||||||
|
tokenIn: contracts.daiAddress,
|
||||||
|
tokenOut: erc20Token,
|
||||||
|
marketFeeAddress: '0x0000000000000000000000000000000000000000'
|
||||||
|
}
|
||||||
|
const amountsInOutMaxFee: AmountsOutMaxFee = {
|
||||||
|
maxAmountIn: '100',
|
||||||
|
tokenAmountOut: '50',
|
||||||
|
maxPrice: MaxUint256,
|
||||||
|
swapMarketFee: '0.1'
|
||||||
|
}
|
||||||
const tx = await pool.swapExactAmountOut(
|
const tx = await pool.swapExactAmountOut(
|
||||||
user2,
|
user2,
|
||||||
poolAddress,
|
poolAddress,
|
||||||
contracts.daiAddress,
|
tokenInOutMarket,
|
||||||
'100',
|
amountsInOutMaxFee
|
||||||
erc20Token,
|
|
||||||
'50'
|
|
||||||
)
|
)
|
||||||
assert(tx != null)
|
assert(tx != null)
|
||||||
})
|
})
|
||||||
@ -536,13 +563,22 @@ describe('SideStaking unit test', () => {
|
|||||||
|
|
||||||
expect(await erc20Contract.methods.balanceOf(user2).call()).to.equal('0')
|
expect(await erc20Contract.methods.balanceOf(user2).call()).to.equal('0')
|
||||||
await pool.approve(user2, contracts.usdcAddress, poolAddress, '10')
|
await pool.approve(user2, contracts.usdcAddress, poolAddress, '10')
|
||||||
|
const tokenInOutMarket: TokenInOutMarket = {
|
||||||
|
tokenIn: contracts.usdcAddress,
|
||||||
|
tokenOut: erc20Token,
|
||||||
|
marketFeeAddress: '0x0000000000000000000000000000000000000000'
|
||||||
|
}
|
||||||
|
const amountsInOutMaxFee: AmountsInMaxFee = {
|
||||||
|
tokenAmountIn: '10',
|
||||||
|
minAmountOut: '1',
|
||||||
|
maxPrice: MaxUint256,
|
||||||
|
swapMarketFee: '0.1'
|
||||||
|
}
|
||||||
const tx = await pool.swapExactAmountIn(
|
const tx = await pool.swapExactAmountIn(
|
||||||
user2,
|
user2,
|
||||||
poolAddress,
|
poolAddress,
|
||||||
contracts.usdcAddress,
|
tokenInOutMarket,
|
||||||
'10',
|
amountsInOutMaxFee
|
||||||
erc20Token,
|
|
||||||
'1'
|
|
||||||
)
|
)
|
||||||
expect(await erc20Contract.methods.balanceOf(user2).call()).to.equal(
|
expect(await erc20Contract.methods.balanceOf(user2).call()).to.equal(
|
||||||
tx.events.LOG_SWAP.returnValues.tokenAmountOut
|
tx.events.LOG_SWAP.returnValues.tokenAmountOut
|
||||||
|
Loading…
x
Reference in New Issue
Block a user