mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
Merge pull request #1399 from oceanprotocol/issue-1352-rewrite-sidestaking-test
Issue-#1352: Rewrite SideStaking test
This commit is contained in:
commit
34e968803f
@ -1,9 +1,8 @@
|
|||||||
import { assert, expect } from 'chai'
|
import { assert, expect } from 'chai'
|
||||||
import { AbiItem } from 'web3-utils/types'
|
import { AbiItem } from 'web3-utils/types'
|
||||||
import { Contract } from 'web3-eth-contract'
|
import { Contract } from 'web3-eth-contract'
|
||||||
import SSContract from '@oceanprotocol/contracts/artifacts/contracts/pools/ssContracts/SideStaking.sol/SideStaking.json'
|
import BigNumber from 'bignumber.js'
|
||||||
import ERC20Template from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC20Template.sol/ERC20Template.json'
|
import ERC20Template from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC20Template.sol/ERC20Template.json'
|
||||||
import PoolTemplate from '@oceanprotocol/contracts/artifacts/contracts/pools/balancer/BPool.sol/BPool.json'
|
|
||||||
import MockERC20 from '@oceanprotocol/contracts/artifacts/contracts/utils/mock/MockERC20Decimals.sol/MockERC20Decimals.json'
|
import MockERC20 from '@oceanprotocol/contracts/artifacts/contracts/utils/mock/MockERC20Decimals.sol/MockERC20Decimals.json'
|
||||||
import { deployContracts, Addresses } from '../../../TestContractHandler'
|
import { deployContracts, Addresses } from '../../../TestContractHandler'
|
||||||
import { web3 } from '../../../config'
|
import { web3 } from '../../../config'
|
||||||
@ -15,7 +14,8 @@ import {
|
|||||||
NftCreateData,
|
NftCreateData,
|
||||||
Pool,
|
Pool,
|
||||||
SideStaking,
|
SideStaking,
|
||||||
unitsToAmount
|
unitsToAmount,
|
||||||
|
ZERO_ADDRESS
|
||||||
} from '../../../../src'
|
} from '../../../../src'
|
||||||
import {
|
import {
|
||||||
Erc20CreateParams,
|
Erc20CreateParams,
|
||||||
@ -27,93 +27,21 @@ import {
|
|||||||
|
|
||||||
describe('SideStaking unit test', () => {
|
describe('SideStaking unit test', () => {
|
||||||
let factoryOwner: string
|
let factoryOwner: string
|
||||||
let nftOwner: string
|
|
||||||
let user1: string
|
let user1: string
|
||||||
let user2: string
|
let user2: string
|
||||||
let user3: string
|
|
||||||
let initialBlock: number
|
let initialBlock: number
|
||||||
let sideStakingAddress: string
|
|
||||||
let contracts: Addresses
|
let contracts: Addresses
|
||||||
let pool: Pool
|
let pool: Pool
|
||||||
let sideStaking: SideStaking
|
let sideStaking: SideStaking
|
||||||
let dtAddress: string
|
|
||||||
let dtAddress2: string
|
|
||||||
let poolAddress: string
|
let poolAddress: string
|
||||||
let erc20Token: string
|
let erc20Token: string
|
||||||
let erc20Contract: Contract
|
let erc20Contract: Contract
|
||||||
let daiContract: Contract
|
let daiContract: Contract
|
||||||
let usdcContract: Contract
|
let usdcContract: Contract
|
||||||
const vestedBlocks = 2500000
|
|
||||||
|
|
||||||
before(async () => {
|
const VESTED_BLOCKS = 2500000
|
||||||
const accounts = await web3.eth.getAccounts()
|
const VESTING_AMOUNT = '10000'
|
||||||
factoryOwner = accounts[0]
|
const BASE_TOKEN_LIQUIDITY = 2000
|
||||||
nftOwner = accounts[1]
|
|
||||||
user1 = accounts[2]
|
|
||||||
user2 = accounts[3]
|
|
||||||
user3 = accounts[4]
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should deploy contracts', async () => {
|
|
||||||
contracts = await deployContracts(web3, factoryOwner)
|
|
||||||
sideStakingAddress = contracts.sideStakingAddress
|
|
||||||
|
|
||||||
// initialize Pool instance
|
|
||||||
pool = new Pool(web3, 8996, PoolTemplate.abi as AbiItem[])
|
|
||||||
assert(pool != null)
|
|
||||||
//
|
|
||||||
sideStaking = new SideStaking(web3, 8996, SSContract.abi as AbiItem[])
|
|
||||||
assert(sideStaking != null)
|
|
||||||
|
|
||||||
daiContract = new web3.eth.Contract(MockERC20.abi as AbiItem[], contracts.daiAddress)
|
|
||||||
|
|
||||||
usdcContract = new web3.eth.Contract(
|
|
||||||
MockERC20.abi as AbiItem[],
|
|
||||||
contracts.usdcAddress
|
|
||||||
)
|
|
||||||
await approve(
|
|
||||||
web3,
|
|
||||||
factoryOwner,
|
|
||||||
contracts.daiAddress,
|
|
||||||
contracts.erc721FactoryAddress,
|
|
||||||
'2000'
|
|
||||||
)
|
|
||||||
await approve(
|
|
||||||
web3,
|
|
||||||
factoryOwner,
|
|
||||||
contracts.usdcAddress,
|
|
||||||
contracts.erc721FactoryAddress,
|
|
||||||
'10000'
|
|
||||||
)
|
|
||||||
|
|
||||||
let allowCheck = await allowance(
|
|
||||||
web3,
|
|
||||||
contracts.daiAddress,
|
|
||||||
factoryOwner,
|
|
||||||
contracts.erc721FactoryAddress
|
|
||||||
)
|
|
||||||
assert(parseInt(allowCheck) >= 2000)
|
|
||||||
allowCheck = await allowance(
|
|
||||||
web3,
|
|
||||||
contracts.usdcAddress,
|
|
||||||
factoryOwner,
|
|
||||||
contracts.erc721FactoryAddress
|
|
||||||
)
|
|
||||||
assert(parseInt(allowCheck) >= 10000)
|
|
||||||
|
|
||||||
console.log(
|
|
||||||
await usdcContract.methods.decimals().call(),
|
|
||||||
'USDC DECIMALS IN THIS TEST'
|
|
||||||
)
|
|
||||||
|
|
||||||
await amountToUnits(web3, contracts.usdcAddress, '20')
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('Test a pool with DAI (18 Decimals)', () => {
|
|
||||||
it('#create a pool', async () => {
|
|
||||||
// CREATE A POOL
|
|
||||||
// we prepare transaction parameters objects
|
|
||||||
const nftFactory = new NftFactory(contracts.erc721FactoryAddress, web3)
|
|
||||||
|
|
||||||
const nftData: NftCreateData = {
|
const nftData: NftCreateData = {
|
||||||
name: '72120Bundle',
|
name: '72120Bundle',
|
||||||
@ -121,21 +49,94 @@ describe('SideStaking unit test', () => {
|
|||||||
templateIndex: 1,
|
templateIndex: 1,
|
||||||
tokenURI: 'https://oceanprotocol.com/nft/',
|
tokenURI: 'https://oceanprotocol.com/nft/',
|
||||||
transferable: true,
|
transferable: true,
|
||||||
owner: factoryOwner
|
owner: null
|
||||||
}
|
}
|
||||||
|
|
||||||
const ercParams: Erc20CreateParams = {
|
const ercParams: Erc20CreateParams = {
|
||||||
templateIndex: 1,
|
templateIndex: 1,
|
||||||
minter: factoryOwner,
|
minter: null,
|
||||||
paymentCollector: user3,
|
paymentCollector: null,
|
||||||
mpFeeAddress: factoryOwner,
|
mpFeeAddress: null,
|
||||||
feeToken: '0x0000000000000000000000000000000000000000',
|
feeToken: ZERO_ADDRESS,
|
||||||
cap: '1000000',
|
cap: '1000000',
|
||||||
feeAmount: '0',
|
feeAmount: '0',
|
||||||
name: 'ERC20B1',
|
name: 'ERC20B1',
|
||||||
symbol: 'ERC20DT1Symbol'
|
symbol: 'ERC20DT1Symbol'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
before(async () => {
|
||||||
|
const accounts = await web3.eth.getAccounts()
|
||||||
|
factoryOwner = accounts[0]
|
||||||
|
user1 = accounts[1]
|
||||||
|
user2 = accounts[2]
|
||||||
|
|
||||||
|
nftData.owner = factoryOwner
|
||||||
|
ercParams.minter = factoryOwner
|
||||||
|
ercParams.paymentCollector = user2
|
||||||
|
ercParams.mpFeeAddress = factoryOwner
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should deploy contracts', async () => {
|
||||||
|
contracts = await deployContracts(web3, factoryOwner)
|
||||||
|
|
||||||
|
// initialize Pool instance
|
||||||
|
pool = new Pool(web3, 8996)
|
||||||
|
assert(pool != null)
|
||||||
|
//
|
||||||
|
sideStaking = new SideStaking(web3, 8996)
|
||||||
|
assert(sideStaking != null)
|
||||||
|
|
||||||
|
daiContract = new web3.eth.Contract(MockERC20.abi as AbiItem[], contracts.daiAddress)
|
||||||
|
usdcContract = new web3.eth.Contract(
|
||||||
|
MockERC20.abi as AbiItem[],
|
||||||
|
contracts.usdcAddress
|
||||||
|
)
|
||||||
|
|
||||||
|
await approve(
|
||||||
|
web3,
|
||||||
|
factoryOwner,
|
||||||
|
contracts.daiAddress,
|
||||||
|
contracts.erc721FactoryAddress,
|
||||||
|
BASE_TOKEN_LIQUIDITY.toString()
|
||||||
|
)
|
||||||
|
|
||||||
|
assert(
|
||||||
|
parseInt(
|
||||||
|
await allowance(
|
||||||
|
web3,
|
||||||
|
contracts.daiAddress,
|
||||||
|
factoryOwner,
|
||||||
|
contracts.erc721FactoryAddress
|
||||||
|
)
|
||||||
|
) >= BASE_TOKEN_LIQUIDITY
|
||||||
|
)
|
||||||
|
|
||||||
|
await approve(
|
||||||
|
web3,
|
||||||
|
factoryOwner,
|
||||||
|
contracts.usdcAddress,
|
||||||
|
contracts.erc721FactoryAddress,
|
||||||
|
BASE_TOKEN_LIQUIDITY.toString()
|
||||||
|
)
|
||||||
|
|
||||||
|
assert(
|
||||||
|
parseInt(
|
||||||
|
await allowance(
|
||||||
|
web3,
|
||||||
|
contracts.usdcAddress,
|
||||||
|
factoryOwner,
|
||||||
|
contracts.erc721FactoryAddress
|
||||||
|
)
|
||||||
|
) >= BASE_TOKEN_LIQUIDITY
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('Test a pool with DAI (18 Decimals)', () => {
|
||||||
|
it('#create a pool', async () => {
|
||||||
|
// CREATE A POOL
|
||||||
|
// we prepare transaction parameters objects
|
||||||
|
const nftFactory = new NftFactory(contracts.erc721FactoryAddress, web3)
|
||||||
|
|
||||||
const poolParams: PoolCreationParams = {
|
const poolParams: PoolCreationParams = {
|
||||||
ssContract: contracts.sideStakingAddress,
|
ssContract: contracts.sideStakingAddress,
|
||||||
baseTokenAddress: contracts.daiAddress,
|
baseTokenAddress: contracts.daiAddress,
|
||||||
@ -145,9 +146,9 @@ describe('SideStaking unit test', () => {
|
|||||||
poolTemplateAddress: contracts.poolTemplateAddress,
|
poolTemplateAddress: contracts.poolTemplateAddress,
|
||||||
rate: '1',
|
rate: '1',
|
||||||
baseTokenDecimals: 18,
|
baseTokenDecimals: 18,
|
||||||
vestingAmount: '10000',
|
vestingAmount: VESTING_AMOUNT,
|
||||||
vestedBlocks: vestedBlocks,
|
vestedBlocks: VESTED_BLOCKS,
|
||||||
initialBaseTokenLiquidity: '2000',
|
initialBaseTokenLiquidity: BASE_TOKEN_LIQUIDITY.toString(),
|
||||||
swapFeeLiquidityProvider: '0.001',
|
swapFeeLiquidityProvider: '0.001',
|
||||||
swapFeeMarketRunner: '0.001'
|
swapFeeMarketRunner: '0.001'
|
||||||
}
|
}
|
||||||
@ -164,13 +165,12 @@ describe('SideStaking unit test', () => {
|
|||||||
poolAddress = txReceipt.events.NewPool.returnValues.poolAddress
|
poolAddress = txReceipt.events.NewPool.returnValues.poolAddress
|
||||||
|
|
||||||
erc20Contract = new web3.eth.Contract(ERC20Template.abi as AbiItem[], erc20Token)
|
erc20Contract = new web3.eth.Contract(ERC20Template.abi as AbiItem[], erc20Token)
|
||||||
// user2 has no dt1
|
// user1 has no dt1
|
||||||
expect(await erc20Contract.methods.balanceOf(user2).call()).to.equal('0')
|
expect(await erc20Contract.methods.balanceOf(user1).call()).to.equal('0')
|
||||||
|
|
||||||
sideStakingAddress = contracts.sideStakingAddress
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('#getRouter - should get Router address', async () => {
|
it('#getRouter - should get Router address', async () => {
|
||||||
expect(await sideStaking.getRouter(sideStakingAddress)).to.equal(
|
expect(await sideStaking.getRouter(contracts.sideStakingAddress)).to.equal(
|
||||||
contracts.routerAddress
|
contracts.routerAddress
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
@ -181,69 +181,87 @@ describe('SideStaking unit test', () => {
|
|||||||
contracts.sideStakingAddress,
|
contracts.sideStakingAddress,
|
||||||
erc20Token
|
erc20Token
|
||||||
)
|
)
|
||||||
).to.equal(web3.utils.toWei('2000'))
|
).to.equal(web3.utils.toWei(BASE_TOKEN_LIQUIDITY.toString()))
|
||||||
})
|
})
|
||||||
|
|
||||||
it('#getDatatokenCurrentCirculatingSupply - should get datatoken supply in circulation ', async () => {
|
it('#getDatatokenCurrentCirculatingSupply - should get datatoken supply in circulation ', async () => {
|
||||||
expect(
|
expect(
|
||||||
await sideStaking.getDatatokenCurrentCirculatingSupply(
|
await sideStaking.getDatatokenCurrentCirculatingSupply(
|
||||||
contracts.sideStakingAddress,
|
contracts.sideStakingAddress,
|
||||||
erc20Token
|
erc20Token
|
||||||
)
|
)
|
||||||
).to.equal(web3.utils.toWei('2000'))
|
).to.equal(web3.utils.toWei(BASE_TOKEN_LIQUIDITY.toString()))
|
||||||
})
|
})
|
||||||
|
|
||||||
it('#getBaseToken - should get baseToken address', async () => {
|
it('#getBaseToken - should get baseToken address', async () => {
|
||||||
expect(await sideStaking.getBaseToken(sideStakingAddress, erc20Token)).to.equal(
|
expect(
|
||||||
contracts.daiAddress
|
await sideStaking.getBaseToken(contracts.sideStakingAddress, erc20Token)
|
||||||
)
|
).to.equal(contracts.daiAddress)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('#getPoolAddress - should get pool address', async () => {
|
it('#getPoolAddress - should get pool address', async () => {
|
||||||
expect(await sideStaking.getPoolAddress(sideStakingAddress, erc20Token)).to.equal(
|
expect(
|
||||||
poolAddress
|
await sideStaking.getPoolAddress(contracts.sideStakingAddress, erc20Token)
|
||||||
)
|
).to.equal(poolAddress)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('#getPublisherAddress - should get publisher address', async () => {
|
it('#getPublisherAddress - should get publisher address', async () => {
|
||||||
expect(
|
expect(
|
||||||
await sideStaking.getPublisherAddress(sideStakingAddress, erc20Token)
|
await sideStaking.getPublisherAddress(contracts.sideStakingAddress, erc20Token)
|
||||||
).to.equal(factoryOwner)
|
).to.equal(factoryOwner)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('#getBaseTokenBalance ', async () => {
|
it('#getBaseTokenBalance ', async () => {
|
||||||
expect(
|
expect(
|
||||||
await sideStaking.getBaseTokenBalance(sideStakingAddress, erc20Token)
|
await sideStaking.getBaseTokenBalance(contracts.sideStakingAddress, erc20Token)
|
||||||
).to.equal('0')
|
).to.equal('0')
|
||||||
})
|
})
|
||||||
// it('#getDatatokenBalance ', async () => {
|
|
||||||
// expect(
|
|
||||||
// await sideStaking.getDatatokenBalance(sideStakingAddress, erc20Token)
|
|
||||||
// ).to.equal('997999.9999999999')
|
|
||||||
// })
|
|
||||||
|
|
||||||
it('#getvestingAmount ', async () => {
|
it('#getDatatokenBalance ', async () => {
|
||||||
expect(await sideStaking.getvestingAmount(sideStakingAddress, erc20Token)).to.equal(
|
expect(
|
||||||
'0'
|
await (
|
||||||
|
await sideStaking.getDatatokenBalance(contracts.sideStakingAddress, erc20Token)
|
||||||
|
).toString()
|
||||||
|
).to.equal(
|
||||||
|
new BigNumber(2)
|
||||||
|
.exponentiatedBy(256)
|
||||||
|
.minus(1)
|
||||||
|
.dividedBy(new BigNumber(10).exponentiatedBy(18))
|
||||||
|
.minus(BASE_TOKEN_LIQUIDITY)
|
||||||
|
.toString()
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('#getvestingAmount ', async () => {
|
||||||
|
expect(
|
||||||
|
await sideStaking.getvestingAmount(contracts.sideStakingAddress, erc20Token)
|
||||||
|
).to.equal('0')
|
||||||
|
})
|
||||||
|
|
||||||
it('#getvestingLastBlock ', async () => {
|
it('#getvestingLastBlock ', async () => {
|
||||||
expect(
|
expect(
|
||||||
await sideStaking.getvestingLastBlock(sideStakingAddress, erc20Token)
|
await sideStaking.getvestingLastBlock(contracts.sideStakingAddress, erc20Token)
|
||||||
).to.equal(initialBlock.toString())
|
).to.equal(initialBlock.toString())
|
||||||
})
|
})
|
||||||
|
|
||||||
it('#getvestingAmountSoFar ', async () => {
|
it('#getvestingAmountSoFar ', async () => {
|
||||||
expect(
|
expect(
|
||||||
await sideStaking.getvestingAmountSoFar(sideStakingAddress, erc20Token)
|
await sideStaking.getvestingAmountSoFar(contracts.sideStakingAddress, erc20Token)
|
||||||
).to.equal('0')
|
).to.equal('0')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('#swapExactAmountIn - should swap', async () => {
|
it('#swapExactAmountIn - should swap', async () => {
|
||||||
await daiContract.methods
|
await daiContract.methods
|
||||||
.transfer(user2, web3.utils.toWei('1000'))
|
.transfer(user1, web3.utils.toWei('1000'))
|
||||||
.send({ from: factoryOwner })
|
.send({ from: factoryOwner })
|
||||||
await approve(web3, user2, contracts.daiAddress, poolAddress, '10')
|
await approve(web3, user1, contracts.daiAddress, poolAddress, '10')
|
||||||
|
|
||||||
const tokenInOutMarket: TokenInOutMarket = {
|
const tokenInOutMarket: TokenInOutMarket = {
|
||||||
tokenIn: contracts.daiAddress,
|
tokenIn: contracts.daiAddress,
|
||||||
tokenOut: erc20Token,
|
tokenOut: erc20Token,
|
||||||
marketFeeAddress: factoryOwner
|
marketFeeAddress: factoryOwner
|
||||||
}
|
}
|
||||||
|
|
||||||
const amountsInOutMaxFee: AmountsInMaxFee = {
|
const amountsInOutMaxFee: AmountsInMaxFee = {
|
||||||
tokenAmountIn: '10',
|
tokenAmountIn: '10',
|
||||||
minAmountOut: '1',
|
minAmountOut: '1',
|
||||||
@ -251,18 +269,19 @@ describe('SideStaking unit test', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const tx = await pool.swapExactAmountIn(
|
const tx = await pool.swapExactAmountIn(
|
||||||
user2,
|
user1,
|
||||||
poolAddress,
|
poolAddress,
|
||||||
tokenInOutMarket,
|
tokenInOutMarket,
|
||||||
amountsInOutMaxFee
|
amountsInOutMaxFee
|
||||||
)
|
)
|
||||||
expect(await erc20Contract.methods.balanceOf(user2).call()).to.equal(
|
|
||||||
|
expect(await erc20Contract.methods.balanceOf(user1).call()).to.equal(
|
||||||
tx.events.LOG_SWAP.returnValues.tokenAmountOut
|
tx.events.LOG_SWAP.returnValues.tokenAmountOut
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('#swapExactAmountOut - should swap', async () => {
|
it('#swapExactAmountOut - should swap', async () => {
|
||||||
await approve(web3, user2, contracts.daiAddress, poolAddress, '100')
|
await approve(web3, user1, contracts.daiAddress, poolAddress, '100')
|
||||||
const tokenInOutMarket: TokenInOutMarket = {
|
const tokenInOutMarket: TokenInOutMarket = {
|
||||||
tokenIn: contracts.daiAddress,
|
tokenIn: contracts.daiAddress,
|
||||||
tokenOut: erc20Token,
|
tokenOut: erc20Token,
|
||||||
@ -274,7 +293,7 @@ describe('SideStaking unit test', () => {
|
|||||||
swapMarketFee: '0.1'
|
swapMarketFee: '0.1'
|
||||||
}
|
}
|
||||||
const tx = await pool.swapExactAmountOut(
|
const tx = await pool.swapExactAmountOut(
|
||||||
user2,
|
user1,
|
||||||
poolAddress,
|
poolAddress,
|
||||||
tokenInOutMarket,
|
tokenInOutMarket,
|
||||||
amountsInOutMaxFee
|
amountsInOutMaxFee
|
||||||
@ -282,15 +301,15 @@ describe('SideStaking unit test', () => {
|
|||||||
assert(tx != null)
|
assert(tx != null)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('#joinswapExternAmountIn- user2 should add liquidity, receiving LP tokens', async () => {
|
it('#joinswapExternAmountIn- user1 should add liquidity, receiving LP tokens', async () => {
|
||||||
const daiAmountIn = '100'
|
const daiAmountIn = '100'
|
||||||
const minBPTOut = '0.1'
|
const minBPTOut = '0.1'
|
||||||
await approve(web3, user2, contracts.daiAddress, poolAddress, '100', true)
|
await approve(web3, user1, contracts.daiAddress, poolAddress, '100', true)
|
||||||
expect(await allowance(web3, contracts.daiAddress, user2, poolAddress)).to.equal(
|
expect(await allowance(web3, contracts.daiAddress, user1, poolAddress)).to.equal(
|
||||||
'100'
|
'100'
|
||||||
)
|
)
|
||||||
const tx = await pool.joinswapExternAmountIn(
|
const tx = await pool.joinswapExternAmountIn(
|
||||||
user2,
|
user1,
|
||||||
poolAddress,
|
poolAddress,
|
||||||
daiAmountIn,
|
daiAmountIn,
|
||||||
minBPTOut
|
minBPTOut
|
||||||
@ -306,12 +325,12 @@ describe('SideStaking unit test', () => {
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('#exitswapPoolAmountIn- user2 exit the pool receiving only DAI', async () => {
|
it('#exitswapPoolAmountIn- user1 exit the pool receiving only DAI', async () => {
|
||||||
const BPTAmountIn = '0.5'
|
const BPTAmountIn = '0.5'
|
||||||
const minDAIOut = '0.5'
|
const minDAIOut = '0.5'
|
||||||
|
|
||||||
const tx = await pool.exitswapPoolAmountIn(
|
const tx = await pool.exitswapPoolAmountIn(
|
||||||
user2,
|
user1,
|
||||||
poolAddress,
|
poolAddress,
|
||||||
BPTAmountIn,
|
BPTAmountIn,
|
||||||
minDAIOut
|
minDAIOut
|
||||||
@ -332,27 +351,6 @@ describe('SideStaking unit test', () => {
|
|||||||
// we prepare transaction parameters objects
|
// we prepare transaction parameters objects
|
||||||
const nftFactory = new NftFactory(contracts.erc721FactoryAddress, web3)
|
const nftFactory = new NftFactory(contracts.erc721FactoryAddress, web3)
|
||||||
|
|
||||||
const nftData: NftCreateData = {
|
|
||||||
name: '72120Bundle',
|
|
||||||
symbol: '72Bundle',
|
|
||||||
templateIndex: 1,
|
|
||||||
tokenURI: 'https://oceanprotocol.com/nft/',
|
|
||||||
transferable: true,
|
|
||||||
owner: factoryOwner
|
|
||||||
}
|
|
||||||
|
|
||||||
const ercParams: Erc20CreateParams = {
|
|
||||||
templateIndex: 1,
|
|
||||||
minter: factoryOwner,
|
|
||||||
paymentCollector: user3,
|
|
||||||
mpFeeAddress: factoryOwner,
|
|
||||||
feeToken: '0x0000000000000000000000000000000000000000',
|
|
||||||
cap: '1000000',
|
|
||||||
feeAmount: '0',
|
|
||||||
name: 'ERC20B1',
|
|
||||||
symbol: 'ERC20DT1Symbol'
|
|
||||||
}
|
|
||||||
|
|
||||||
const poolParams: PoolCreationParams = {
|
const poolParams: PoolCreationParams = {
|
||||||
ssContract: contracts.sideStakingAddress,
|
ssContract: contracts.sideStakingAddress,
|
||||||
baseTokenAddress: contracts.usdcAddress,
|
baseTokenAddress: contracts.usdcAddress,
|
||||||
@ -362,12 +360,16 @@ describe('SideStaking unit test', () => {
|
|||||||
poolTemplateAddress: contracts.poolTemplateAddress,
|
poolTemplateAddress: contracts.poolTemplateAddress,
|
||||||
rate: '1',
|
rate: '1',
|
||||||
baseTokenDecimals: await usdcContract.methods.decimals().call(),
|
baseTokenDecimals: await usdcContract.methods.decimals().call(),
|
||||||
vestingAmount: '10000',
|
vestingAmount: VESTING_AMOUNT,
|
||||||
vestedBlocks: 2500000,
|
vestedBlocks: VESTED_BLOCKS,
|
||||||
initialBaseTokenLiquidity: await unitsToAmount(
|
initialBaseTokenLiquidity: await unitsToAmount(
|
||||||
web3,
|
web3,
|
||||||
contracts.usdcAddress,
|
contracts.usdcAddress,
|
||||||
await amountToUnits(web3, contracts.usdcAddress, '2000')
|
await amountToUnits(
|
||||||
|
web3,
|
||||||
|
contracts.usdcAddress,
|
||||||
|
BASE_TOKEN_LIQUIDITY.toString()
|
||||||
|
)
|
||||||
),
|
),
|
||||||
swapFeeLiquidityProvider: '0.001',
|
swapFeeLiquidityProvider: '0.001',
|
||||||
swapFeeMarketRunner: '0.001'
|
swapFeeMarketRunner: '0.001'
|
||||||
@ -385,45 +387,56 @@ describe('SideStaking unit test', () => {
|
|||||||
poolAddress = txReceipt.events.NewPool.returnValues.poolAddress
|
poolAddress = txReceipt.events.NewPool.returnValues.poolAddress
|
||||||
|
|
||||||
erc20Contract = new web3.eth.Contract(ERC20Template.abi as AbiItem[], erc20Token)
|
erc20Contract = new web3.eth.Contract(ERC20Template.abi as AbiItem[], erc20Token)
|
||||||
// user2 has no dt1
|
// user1 has no dt1
|
||||||
expect(await erc20Contract.methods.balanceOf(user2).call()).to.equal('0')
|
expect(await erc20Contract.methods.balanceOf(user1).call()).to.equal('0')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('#getBaseTokenBalance ', async () => {
|
it('#getBaseTokenBalance ', async () => {
|
||||||
expect(
|
expect(
|
||||||
await sideStaking.getBaseTokenBalance(sideStakingAddress, erc20Token)
|
await sideStaking.getBaseTokenBalance(contracts.sideStakingAddress, erc20Token)
|
||||||
).to.equal('0')
|
).to.equal('0')
|
||||||
})
|
})
|
||||||
// it('#getDatatokenBalance ', async () => {
|
|
||||||
// expect(
|
|
||||||
// await sideStaking.getDatatokenBalance(sideStakingAddress, erc20Token)
|
|
||||||
// ).to.equal('997999.9999999999')
|
|
||||||
// })
|
|
||||||
|
|
||||||
it('#getvestingAmount ', async () => {
|
it('#getDatatokenBalance ', async () => {
|
||||||
expect(await sideStaking.getvestingAmount(sideStakingAddress, erc20Token)).to.equal(
|
expect(
|
||||||
'0'
|
await (
|
||||||
|
await sideStaking.getDatatokenBalance(contracts.sideStakingAddress, erc20Token)
|
||||||
|
).toString()
|
||||||
|
).to.equal(
|
||||||
|
new BigNumber(2)
|
||||||
|
.exponentiatedBy(256)
|
||||||
|
.minus(1)
|
||||||
|
.dividedBy(new BigNumber(10).exponentiatedBy(18))
|
||||||
|
.minus(BASE_TOKEN_LIQUIDITY)
|
||||||
|
.toString()
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('#getvestingAmount ', async () => {
|
||||||
|
expect(
|
||||||
|
await sideStaking.getvestingAmount(contracts.sideStakingAddress, erc20Token)
|
||||||
|
).to.equal('0')
|
||||||
|
})
|
||||||
|
|
||||||
it('#getvestingLastBlock ', async () => {
|
it('#getvestingLastBlock ', async () => {
|
||||||
expect(
|
expect(
|
||||||
await sideStaking.getvestingLastBlock(sideStakingAddress, erc20Token)
|
await sideStaking.getvestingLastBlock(contracts.sideStakingAddress, erc20Token)
|
||||||
).to.equal(initialBlock.toString())
|
).to.equal(initialBlock.toString())
|
||||||
})
|
})
|
||||||
|
|
||||||
it('#getvestingAmountSoFar ', async () => {
|
it('#getvestingAmountSoFar ', async () => {
|
||||||
expect(
|
expect(
|
||||||
await sideStaking.getvestingAmountSoFar(sideStakingAddress, erc20Token)
|
await sideStaking.getvestingAmountSoFar(contracts.sideStakingAddress, erc20Token)
|
||||||
).to.equal('0')
|
).to.equal('0')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('#swapExactAmountIn - should swap', async () => {
|
it('#swapExactAmountIn - should swap', async () => {
|
||||||
const transferAmount = await amountToUnits(web3, contracts.usdcAddress, '1000') // 1000 USDC
|
const transferAmount = await amountToUnits(web3, contracts.usdcAddress, '1000') // 1000 USDC
|
||||||
await usdcContract.methods
|
await usdcContract.methods
|
||||||
.transfer(user2, transferAmount)
|
.transfer(user1, transferAmount)
|
||||||
.send({ from: factoryOwner })
|
.send({ from: factoryOwner })
|
||||||
|
|
||||||
await approve(web3, user2, contracts.usdcAddress, poolAddress, '10')
|
await approve(web3, user1, contracts.usdcAddress, poolAddress, '10')
|
||||||
const tokenInOutMarket: TokenInOutMarket = {
|
const tokenInOutMarket: TokenInOutMarket = {
|
||||||
tokenIn: contracts.usdcAddress,
|
tokenIn: contracts.usdcAddress,
|
||||||
tokenOut: erc20Token,
|
tokenOut: erc20Token,
|
||||||
@ -435,18 +448,18 @@ describe('SideStaking unit test', () => {
|
|||||||
swapMarketFee: '0.1'
|
swapMarketFee: '0.1'
|
||||||
}
|
}
|
||||||
const tx = await pool.swapExactAmountIn(
|
const tx = await pool.swapExactAmountIn(
|
||||||
user2,
|
user1,
|
||||||
poolAddress,
|
poolAddress,
|
||||||
tokenInOutMarket,
|
tokenInOutMarket,
|
||||||
amountsInOutMaxFee
|
amountsInOutMaxFee
|
||||||
)
|
)
|
||||||
expect(await erc20Contract.methods.balanceOf(user2).call()).to.equal(
|
expect(await erc20Contract.methods.balanceOf(user1).call()).to.equal(
|
||||||
tx.events.LOG_SWAP.returnValues.tokenAmountOut
|
tx.events.LOG_SWAP.returnValues.tokenAmountOut
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('#swapExactAmountOut - should swap', async () => {
|
it('#swapExactAmountOut - should swap', async () => {
|
||||||
await approve(web3, user2, contracts.usdcAddress, poolAddress, '100')
|
await approve(web3, user1, contracts.usdcAddress, poolAddress, '100')
|
||||||
const tokenInOutMarket: TokenInOutMarket = {
|
const tokenInOutMarket: TokenInOutMarket = {
|
||||||
tokenIn: contracts.usdcAddress,
|
tokenIn: contracts.usdcAddress,
|
||||||
tokenOut: erc20Token,
|
tokenOut: erc20Token,
|
||||||
@ -458,22 +471,21 @@ describe('SideStaking unit test', () => {
|
|||||||
swapMarketFee: '0.1'
|
swapMarketFee: '0.1'
|
||||||
}
|
}
|
||||||
const tx = await pool.swapExactAmountOut(
|
const tx = await pool.swapExactAmountOut(
|
||||||
user2,
|
user1,
|
||||||
poolAddress,
|
poolAddress,
|
||||||
tokenInOutMarket,
|
tokenInOutMarket,
|
||||||
amountsInOutMaxFee
|
amountsInOutMaxFee
|
||||||
)
|
)
|
||||||
assert(tx != null)
|
assert(tx != null)
|
||||||
// console.log(tx.events)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('#joinswapExternAmountIn- user2 should add liquidity, receiving LP tokens', async () => {
|
it('#joinswapExternAmountIn- user1 should add liquidity, receiving LP tokens', async () => {
|
||||||
const usdcAmountIn = '100'
|
const usdcAmountIn = '100'
|
||||||
const minBPTOut = '0.1'
|
const minBPTOut = '0.1'
|
||||||
await approve(web3, user2, contracts.usdcAddress, poolAddress, '100', true)
|
await approve(web3, user1, contracts.usdcAddress, poolAddress, '100', true)
|
||||||
|
|
||||||
const tx = await pool.joinswapExternAmountIn(
|
const tx = await pool.joinswapExternAmountIn(
|
||||||
user2,
|
user1,
|
||||||
poolAddress,
|
poolAddress,
|
||||||
usdcAmountIn,
|
usdcAmountIn,
|
||||||
minBPTOut
|
minBPTOut
|
||||||
@ -489,12 +501,12 @@ describe('SideStaking unit test', () => {
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('#exitswapPoolAmountIn- user2 exit the pool receiving only USDC', async () => {
|
it('#exitswapPoolAmountIn- user1 exit the pool receiving only USDC', async () => {
|
||||||
const BPTAmountIn = '0.5'
|
const BPTAmountIn = '0.5'
|
||||||
const minUSDCOut = '0.5'
|
const minUSDCOut = '0.5'
|
||||||
|
|
||||||
const tx = await pool.exitswapPoolAmountIn(
|
const tx = await pool.exitswapPoolAmountIn(
|
||||||
user2,
|
user1,
|
||||||
poolAddress,
|
poolAddress,
|
||||||
BPTAmountIn,
|
BPTAmountIn,
|
||||||
minUSDCOut
|
minUSDCOut
|
||||||
|
Loading…
x
Reference in New Issue
Block a user