1
0
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:
Bogdan Fazakas 2021-12-06 23:25:48 +02:00
parent 96ec95cfa2
commit ee6e935c0c
7 changed files with 218 additions and 121 deletions

View File

@ -816,9 +816,6 @@ export class Datatoken {
* @param {String} consumer Consumer Address
* @param {String} amount Amount of tokens that is going to be transfered
* @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
* @return {Promise<any>}
*/
@ -852,9 +849,6 @@ export class Datatoken {
* @param {String} consumer Consumer Address
* @param {String} amount Amount of tokens that is going to be transfered
* @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
*/
public async startOrder(

View File

@ -15,6 +15,6 @@ export interface FreOrderParams {
exchangeContract: string
exchangeId: string
maxBaseTokenAmount: string
swapMarketFee: number
swapMarketFee: string
marketFeeAddress: string
}

View File

@ -11,7 +11,6 @@ import Decimal from 'decimal.js'
import {
CurrentFees,
TokenInOutMarket,
AmountsInOutMaxFee,
AmountsInMaxFee,
AmountsOutMaxFee
} from '../../interfaces'
@ -778,11 +777,8 @@ export class Pool {
* Estimate gas cost for swapExactAmountIn
* @param {String} address
* @param {String} poolAddress
* @param {String} tokenIn
* @param {String} tokenAmountIn will be converted to wei
* @param {String} tokenOut
* @param {String} minAmountOut will be converted to wei
* @param {String} maxPrice will be converted to wei
* @param {TokenInOutMarket} tokenInOutMarket
* @param {AmountsInMaxFee} amountsInOutMaxFee
* @param {Contract} contractInstance optional contract instance
* @return {Promise<number>}
*/
@ -811,7 +807,7 @@ export class Pool {
amountsInOutMaxFee.tokenAmountIn,
amountsInOutMaxFee.minAmountOut,
this.web3.utils.toWei(amountsInOutMaxFee.maxPrice),
amountsInOutMaxFee.swapMarketFee
this.web3.utils.toWei(amountsInOutMaxFee.swapMarketFee)
]
)
.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} poolAddress
* @param {String} tokenIn
* @param {String} tokenAmountIn will be converted to wei
* @param {String} tokenOut
* @param {String} minAmountOut will be converted to wei
* @param {String} maxPrice will be converted to wei
* @param {TokenInOutMarket} tokenInOutMarket
* @param {AmountsInMaxFee} amountsInOutMaxFee
* @return {TransactionReceipt}
*/
async swapExactAmountIn(
address: string,
poolAddress: string,
tokenInOutMarket: TokenInOutMarket,
amountsInOutMaxFee: AmountsInOutMaxFee
amountsInOutMaxFee: AmountsInMaxFee
): Promise<TransactionReceipt> {
const pool = new this.web3.eth.Contract(this.poolABI, poolAddress)
@ -871,7 +868,7 @@ export class Pool {
amountsInOutMaxFee.tokenAmountIn,
amountsInOutMaxFee.minAmountOut,
this.web3.utils.toWei(amountsInOutMaxFee.maxPrice),
amountsInOutMaxFee.swapMarketFee
this.web3.utils.toWei(amountsInOutMaxFee.swapMarketFee)
]
)
.send({
@ -890,11 +887,8 @@ export class Pool {
* Estimate gas cost for swapExactAmountOut
* @param {String} address
* @param {String} poolAddress
* @param {String} tokenIn
* @param {String} tokenAmountIn will be converted to wei
* @param {String} tokenOut
* @param {String} minAmountOut will be converted to wei
* @param {String} maxPrice will be converted to wei
* @param {TokenInOutMarket} tokenInOutMarket
* @param {AmountsOutMaxFee} amountsInOutMaxFee
* @param {Contract} contractInstance optional contract instance
* @return {Promise<number>}
*/
@ -923,7 +917,7 @@ export class Pool {
amountsInOutMaxFee.maxAmountIn,
amountsInOutMaxFee.tokenAmountOut,
this.web3.utils.toWei(amountsInOutMaxFee.maxPrice),
amountsInOutMaxFee.swapMarketFee
this.web3.utils.toWei(amountsInOutMaxFee.swapMarketFee)
]
)
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
@ -937,11 +931,8 @@ export class Pool {
* swapExactAmountOut
* @param {String} account
* @param {String} poolAddress
* @param {String} tokenIn
* @param {String} maxAmountIn will be converted to wei
* @param {String} tokenOut
* @param {String} amountOut will be converted to wei
* @param {String} maxPrice will be converted to wei
* @param {TokenInOutMarket} tokenInOutMarket
* @param {AmountsOutMaxFee} amountsInOutMaxFee
* @return {TransactionReceipt}
*/
async swapExactAmountOut(
@ -980,7 +971,7 @@ export class Pool {
amountsInOutMaxFee.maxAmountIn,
amountsInOutMaxFee.tokenAmountOut,
this.web3.utils.toWei(amountsInOutMaxFee.maxPrice),
amountsInOutMaxFee.swapMarketFee
this.web3.utils.toWei(amountsInOutMaxFee.swapMarketFee)
]
)
.send({
@ -1470,13 +1461,14 @@ export class Pool {
* @param {String} poolAddress
* @param {String} tokenIn
* @param {String} tokenOut
* @param {String} swapMarketFe
* @return {String}
*/
async getSpotPrice(
poolAddress: string,
tokenIn: string,
tokenOut: string,
swapMarketFe: number
swapMarketFee: string
): Promise<string> {
const pool = new this.web3.eth.Contract(this.poolABI, poolAddress)
let decimalsTokenIn = 18
@ -1503,7 +1495,9 @@ export class Pool {
let price = null
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())
} catch (e) {
this.logger.error('ERROR: Failed to get spot price of swapping tokenIn to tokenOut')
@ -1541,7 +1535,12 @@ export class Pool {
try {
const result = await pool.methods
.getAmountInExactOut(tokenIn, tokenOut, amountOutFormatted, swapMarketFee)
.getAmountInExactOut(
tokenIn,
tokenOut,
amountOutFormatted,
this.web3.utils.toWei(swapMarketFee)
)
.call()
amount = await this.unitsToAmount(tokenIn, result)
} catch (e) {
@ -1565,7 +1564,12 @@ export class Pool {
try {
const result = await pool.methods
.getAmountOutExactIn(tokenIn, tokenOut, amountInFormatted, swapMarketFee)
.getAmountOutExactIn(
tokenIn,
tokenOut,
amountInFormatted,
this.web3.utils.toWei(swapMarketFee)
)
.call()
amount = await this.unitsToAmount(tokenOut, result)

View File

@ -253,16 +253,7 @@ describe('Datatoken', () => {
'User2 does not hold 0 datatokens'
)
const order = await datatoken.startOrder(
datatokenAddress,
user1,
user2,
'1',
1,
user3,
'0x0000000000000000000000000000000000000000',
'0'
)
const order = await datatoken.startOrder(datatokenAddress, user1, user2, '1', 1)
assert(order !== null)
assert(
@ -282,10 +273,7 @@ describe('Datatoken', () => {
const order: OrderParams = {
consumer: user1,
amount: '1',
serviceIndex: 1,
consumeFeeAddress: user1,
consumeFeeToken: '0x0000000000000000000000000000000000000000',
consumeFeeAmount: '0'
serviceIndex: 1
}
const buyFromDispenseTx = await datatoken.buyFromDispenserAndOrder(
@ -301,15 +289,15 @@ describe('Datatoken', () => {
const order: OrderParams = {
consumer: user1,
amount: '1',
serviceIndex: 1,
consumeFeeAddress: user1,
consumeFeeToken: '0x0000000000000000000000000000000000000000',
consumeFeeAmount: '0'
serviceIndex: 1
}
const fre: FreOrderParams = {
exchangeContract: fixedRateAddress,
exchangeId: exchangeId,
maxBaseTokenAmount: '1'
maxBaseTokenAmount: '1',
swapMarketFee: this.web3.utils.toWei('0.1'),
marketFeeAddress: '0x0000000000000000000000000000000000000000'
}
const buyTx = await datatoken.buyFromFreAndOrder(datatokenAddress, user1, order, fre)

View File

@ -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 { LoggerInstance } from '../../src/utils'
// import { NFTDataToken } from '../../../src/datatokens/NFTDatatoken'
import { NFTFactory, NFTCreateData } from '../../src/factories/NFTFactory'
import { NFTFactory, NFTCreateData, TokenOrder } from '../../src/factories/NFTFactory'
import {
FreCreationParams,
Erc20CreateParams,
@ -343,24 +343,18 @@ describe('NFT Factory test', () => {
expect(await dtContract.methods.balanceOf(user2).call()).to.equal(dtAmount)
expect(await dtContract2.methods.balanceOf(user2).call()).to.equal(dtAmount)
const orders = [
const orders: TokenOrder[] = [
{
tokenAddress: dtAddress,
consumer: consumer,
amount: dtAmount,
serviceIndex: serviceIndex,
consumeFeeAddress: consumeFeeAddress,
consumeFeeToken: consumeFeeToken,
consumeFeeAmount: consumeFeeAmount
serviceIndex: serviceIndex
},
{
tokenAddress: dtAddress2,
consumer: consumer,
amount: dtAmount,
serviceIndex: serviceIndex,
consumeFeeAddress: consumeFeeAddress,
consumeFeeToken: consumeFeeToken,
consumeFeeAmount: consumeFeeAmount
serviceIndex: serviceIndex
}
]

View File

@ -20,11 +20,16 @@ import { Pool } from '../../../../src/pools/balancer/Pool'
import {
PoolCreationParams,
Erc20CreateParams,
CurrentFees
CurrentFees,
TokenInOutMarket,
AmountsInMaxFee,
AmountsOutMaxFee
} from '../../../../src/interfaces'
const { keccak256 } = require('@ethersproject/keccak256')
const web3 = new Web3('http://127.0.0.1:8545')
const communityCollector = '0xeE9300b7961e0a01d9f0adb863C7A227A07AaD75'
const MaxUint256 =
'115792089237316195423570985008687907853269984665640564039457584007913129639934'
describe('Pool unit test', () => {
let factoryOwner: string
@ -272,13 +277,22 @@ describe('Pool unit test', () => {
)
expect(await erc20Contract.methods.balanceOf(user2).call()).to.equal('0')
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(
user2,
poolAddress,
contracts.daiAddress,
'10',
erc20Token,
'1'
tokenInOutMarket,
amountsInOutMaxFee
)
expect(await erc20Contract.methods.balanceOf(user2).call()).to.equal(
tx.events.LOG_SWAP.returnValues.tokenAmountOut
@ -290,13 +304,22 @@ describe('Pool unit test', () => {
expect(await daiContract.methods.balanceOf(user2).call()).to.equal(
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(
user2,
poolAddress,
contracts.daiAddress,
'100',
erc20Token,
'50'
tokenInOutMarket,
amountsInOutMaxFee
)
assert(tx != null)
})
@ -428,7 +451,8 @@ describe('Pool unit test', () => {
poolAddress,
erc20Token,
contracts.daiAddress,
exactDAIOut
exactDAIOut,
'0.1'
)
assert(amountIn != null)
@ -438,7 +462,8 @@ describe('Pool unit test', () => {
const spotPrice = await pool.getSpotPrice(
poolAddress,
erc20Token,
contracts.daiAddress
contracts.daiAddress,
'0.1'
)
// amount of DAI In will be slightly bigger than spotPrice
@ -452,7 +477,8 @@ describe('Pool unit test', () => {
poolAddress,
erc20Token,
contracts.daiAddress,
exactDTIn
exactDTIn,
'0.1'
)
assert(amountOut != null)
@ -460,7 +486,8 @@ describe('Pool unit test', () => {
const spotPrice = await pool.getSpotPrice(
poolAddress,
contracts.daiAddress,
erc20Token
erc20Token,
'0.1'
)
// amount of DAI received will be slightly less than spotPrice
assert(amountOut < spotPrice)
@ -468,10 +495,12 @@ describe('Pool unit test', () => {
it('#getSpotPrice- should get the spot price', async () => {
assert(
(await pool.getSpotPrice(poolAddress, erc20Token, contracts.daiAddress)) != null
(await pool.getSpotPrice(poolAddress, erc20Token, contracts.daiAddress, '0.1')) !=
null
)
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(
poolAddress,
erc20Token,
contracts.daiAddress
contracts.daiAddress,
'0.1'
)
// contracts.accounts[0] is the marketFeeCollector
@ -508,8 +538,12 @@ describe('Pool unit test', () => {
// Spot price hasn't changed after fee collection
assert(
(await pool.getSpotPrice(poolAddress, erc20Token, contracts.daiAddress)) ===
spotPriceBefore
(await pool.getSpotPrice(
poolAddress,
erc20Token,
contracts.daiAddress,
'0.1'
)) === spotPriceBefore
)
})
@ -526,7 +560,8 @@ describe('Pool unit test', () => {
const spotPriceBefore = await pool.getSpotPrice(
poolAddress,
erc20Token,
contracts.daiAddress
contracts.daiAddress,
'0.1'
)
// some fee are available in DAI
assert((await pool.getCommunityFees(poolAddress, contracts.daiAddress)) > '0')
@ -545,8 +580,12 @@ describe('Pool unit test', () => {
)
// Spot price hasn't changed after fee collection
assert(
(await pool.getSpotPrice(poolAddress, erc20Token, contracts.daiAddress)) ===
spotPriceBefore
(await pool.getSpotPrice(
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')
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(
user2,
poolAddress,
contracts.usdcAddress,
'10',
erc20Token,
'1'
tokenInOutMarket,
amountsInOutMaxFee
)
expect(await erc20Contract.methods.balanceOf(user2).call()).to.equal(
tx.events.LOG_SWAP.returnValues.tokenAmountOut
@ -803,13 +851,22 @@ describe('Pool unit test', () => {
(await pool.amountToUnits(contracts.usdcAddress, '990')).toString()
)
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(
user2,
poolAddress,
contracts.usdcAddress,
'100',
erc20Token,
'50'
tokenInOutMarket,
amountsInOutMaxFee
)
assert(tx != null)
// console.log(tx.events)
@ -944,7 +1001,8 @@ describe('Pool unit test', () => {
poolAddress,
erc20Token,
contracts.usdcAddress,
exactUSDCOut
exactUSDCOut,
'0.1'
)
assert(amountIn != null)
@ -952,7 +1010,8 @@ describe('Pool unit test', () => {
const spotPrice = await pool.getSpotPrice(
poolAddress,
erc20Token,
contracts.usdcAddress
contracts.usdcAddress,
'0.1'
)
// amount of USDC In will be slightly bigger than spotPrice
assert(amountIn > spotPrice)
@ -965,7 +1024,8 @@ describe('Pool unit test', () => {
poolAddress,
erc20Token,
contracts.usdcAddress,
exactDTIn
exactDTIn,
'0.1'
)
assert(amountOut != null)
@ -973,7 +1033,8 @@ describe('Pool unit test', () => {
const spotPrice = await pool.getSpotPrice(
poolAddress,
contracts.usdcAddress,
erc20Token
erc20Token,
'0.1'
)
// amount of USDC received will be slightly less than spotPrice
assert(amountOut < spotPrice)
@ -981,10 +1042,20 @@ describe('Pool unit test', () => {
it('#getSpotPrice- should get the spot price', async () => {
assert(
(await pool.getSpotPrice(poolAddress, erc20Token, contracts.usdcAddress)) != null
(await pool.getSpotPrice(
poolAddress,
erc20Token,
contracts.usdcAddress,
'0.1'
)) != null
)
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(
poolAddress,
erc20Token,
contracts.usdcAddress
contracts.usdcAddress,
'0.1'
)
// contracts.accounts[0] is the marketFeeCollector
assert((await pool.getMarketFeeCollector(poolAddress)) === contracts.accounts[0])
@ -1020,8 +1092,12 @@ describe('Pool unit test', () => {
// Spot price hasn't changed after fee collection
assert(
(await pool.getSpotPrice(poolAddress, erc20Token, contracts.usdcAddress)) ===
spotPriceBefore
(await pool.getSpotPrice(
poolAddress,
erc20Token,
contracts.usdcAddress,
'0.1'
)) === spotPriceBefore
)
})
@ -1048,7 +1124,8 @@ describe('Pool unit test', () => {
const spotPriceBefore = await pool.getSpotPrice(
poolAddress,
erc20Token,
contracts.usdcAddress
contracts.usdcAddress,
'0.1'
)
// some fee are available in USDC
assert((await pool.getCommunityFees(poolAddress, contracts.usdcAddress)) > '0')
@ -1067,8 +1144,12 @@ describe('Pool unit test', () => {
)
// Spot price hasn't changed after fee collection
assert(
(await pool.getSpotPrice(poolAddress, erc20Token, contracts.usdcAddress)) ===
spotPriceBefore
(await pool.getSpotPrice(
poolAddress,
erc20Token,
contracts.usdcAddress,
'0.1'
)) === spotPriceBefore
)
})

View File

@ -19,10 +19,18 @@ import { LoggerInstance } from '../../../../src/utils'
import { NFTFactory, NFTCreateData } from '../../../../src/factories/NFTFactory'
import { Pool } from '../../../../src/pools/balancer/Pool'
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 web3 = new Web3('http://127.0.0.1:8545')
const communityCollector = '0xeE9300b7961e0a01d9f0adb863C7A227A07AaD75'
const MaxUint256 =
'115792089237316195423570985008687907853269984665640564039457584007913129639934'
describe('SideStaking unit test', () => {
let factoryOwner: string
@ -291,13 +299,23 @@ describe('SideStaking unit test', () => {
)
expect(await erc20Contract.methods.balanceOf(user2).call()).to.equal('0')
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(
user2,
poolAddress,
contracts.daiAddress,
'10',
erc20Token,
'1'
tokenInOutMarket,
amountsInOutMaxFee
)
expect(await erc20Contract.methods.balanceOf(user2).call()).to.equal(
tx.events.LOG_SWAP.returnValues.tokenAmountOut
@ -309,13 +327,22 @@ describe('SideStaking unit test', () => {
expect(await daiContract.methods.balanceOf(user2).call()).to.equal(
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(
user2,
poolAddress,
contracts.daiAddress,
'100',
erc20Token,
'50'
tokenInOutMarket,
amountsInOutMaxFee
)
assert(tx != null)
})
@ -536,13 +563,22 @@ describe('SideStaking unit test', () => {
expect(await erc20Contract.methods.balanceOf(user2).call()).to.equal('0')
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(
user2,
poolAddress,
contracts.usdcAddress,
'10',
erc20Token,
'1'
tokenInOutMarket,
amountsInOutMaxFee
)
expect(await erc20Contract.methods.balanceOf(user2).call()).to.equal(
tx.events.LOG_SWAP.returnValues.tokenAmountOut