diff --git a/src/pools/fixedRate/FixedRateExchange.ts b/src/pools/fixedRate/FixedRateExchange.ts index 51f1ddcc..c718c97f 100644 --- a/src/pools/fixedRate/FixedRateExchange.ts +++ b/src/pools/fixedRate/FixedRateExchange.ts @@ -576,6 +576,7 @@ export class FixedRateExchange { ) ) .call() + return await this.unitsToAmount( ( await this.getExchange(exchangeId) @@ -641,18 +642,9 @@ export class FixedRateExchange { */ public async getFeesInfo(exchangeId: string): Promise { const result: FeesInfo = await this.contract.methods.getFeesInfo(exchangeId).call() - result.opfFee = await this.unitsToAmount( - ( - await this.getExchange(exchangeId) - ).baseToken, - result.opfFee - ) - result.marketFee = await this.unitsToAmount( - ( - await this.getExchange(exchangeId) - ).baseToken, - result.marketFee - ) + result.opfFee = this.web3.utils.fromWei(result.opfFee.toString()) + result.marketFee = this.web3.utils.fromWei(result.marketFee.toString()) + result.marketFeeAvailable = await this.unitsToAmount( ( await this.getExchange(exchangeId) @@ -994,19 +986,19 @@ export class FixedRateExchange { return result } - /** + /** * Get Router address set in fixed rate contract * @return {String} */ - async getRouter(): Promise { - let result = null - try { - result = await this.contract.methods.router().call() - } catch (e) { - this.logger.error(`ERROR: Failed to get Router address: ${e.message}`) - } - return result + async getRouter(): Promise { + let result = null + try { + result = await this.contract.methods.router().call() + } catch (e) { + this.logger.error(`ERROR: Failed to get Router address: ${e.message}`) } + return result + } /** * Get Exchange Owner given an exchangeId @@ -1062,7 +1054,6 @@ export class FixedRateExchange { exchangeId: string, newMarketFee: string ): Promise { - const estGas = await this.estSetRate( address, exchangeId, @@ -1078,58 +1069,57 @@ export class FixedRateExchange { return trxReceipt } - /** + /** * Estimate gas cost for updateMarketFeeCollector * @param {String} account - * @param {String} exchangeId ExchangeId + * @param {String} exchangeId ExchangeId * @param {String} newMarketFee New market fee collector * @param {Contract} contractInstance optional contract instance * @return {Promise} */ - public async estUpdateMarketFeeCollector( - account: string, - exchangeId: string, - newMarketFeeCollector: string, - contractInstance?: Contract - ): Promise { - const fixedRate = contractInstance || this.fixedRateContract - const gasLimitDefault = this.GASLIMIT_DEFAULT - let estGas - try { - estGas = await fixedRate.methods - .updateMarketFeeCollector(exchangeId, newMarketFeeCollector) - .estimateGas({ from: account }, (err, estGas) => (err ? gasLimitDefault : estGas)) - } catch (e) { - estGas = gasLimitDefault - } - return estGas - } - - /** - * Set new market fee collector, only market fee collector can update it - * @param {String} address user address - * @param {String} exchangeId ExchangeId - * @param {String} newMarketFeeCollector New market fee collector - * @return {Promise} transaction receipt - */ - public async updateMarketFeeCollector( - address: string, - exchangeId: string, - newMarketFeeCollector: string - ): Promise { - - const estGas = await this.estUpdateMarketFeeCollector( - address, - exchangeId, - newMarketFeeCollector - ) - const trxReceipt = await this.contract.methods + public async estUpdateMarketFeeCollector( + account: string, + exchangeId: string, + newMarketFeeCollector: string, + contractInstance?: Contract + ): Promise { + const fixedRate = contractInstance || this.fixedRateContract + const gasLimitDefault = this.GASLIMIT_DEFAULT + let estGas + try { + estGas = await fixedRate.methods .updateMarketFeeCollector(exchangeId, newMarketFeeCollector) - .send({ - from: address, - gas: estGas + 1, - gasPrice: await getFairGasPrice(this.web3) - }) - return trxReceipt + .estimateGas({ from: account }, (err, estGas) => (err ? gasLimitDefault : estGas)) + } catch (e) { + estGas = gasLimitDefault } + return estGas + } + + /** + * Set new market fee collector, only market fee collector can update it + * @param {String} address user address + * @param {String} exchangeId ExchangeId + * @param {String} newMarketFeeCollector New market fee collector + * @return {Promise} transaction receipt + */ + public async updateMarketFeeCollector( + address: string, + exchangeId: string, + newMarketFeeCollector: string + ): Promise { + const estGas = await this.estUpdateMarketFeeCollector( + address, + exchangeId, + newMarketFeeCollector + ) + const trxReceipt = await this.contract.methods + .updateMarketFeeCollector(exchangeId, newMarketFeeCollector) + .send({ + from: address, + gas: estGas + 1, + gasPrice: await getFairGasPrice(this.web3) + }) + return trxReceipt + } } diff --git a/src/pools/ssContracts/SideStaking.ts b/src/pools/ssContracts/SideStaking.ts index 1b47306c..b1f5bdff 100644 --- a/src/pools/ssContracts/SideStaking.ts +++ b/src/pools/ssContracts/SideStaking.ts @@ -63,7 +63,7 @@ export class SideStaking { } /** - * Get DTs in circulation (amount vested not accounted) + * Get (total vesting amount + token released from the contract when adding liquidity) * @param {String} ssAddress side staking contract address * @param {String} datatokenAddress datatoken address * @return {String} @@ -81,7 +81,30 @@ export class SideStaking { } catch (e) { this.logger.error(`ERROR: Failed to get: ${e.message}`) } - return result + return result.toString() + } + + /** + * Get actual dts in circulation (vested token withdrawn from the contract + + token released from the contract when adding liquidity) + * @param {String} ssAddress side staking contract address + * @param {String} datatokenAddress datatoken address + * @return {String} + */ + async getDataTokenCurrentCirculatingSupply( + ssAddress: string, + datatokenAddress: string + ): Promise { + const sideStaking = new this.web3.eth.Contract(this.ssABI, ssAddress) + let result = null + try { + result = await sideStaking.methods + .getDataTokenCurrentCirculatingSupply(datatokenAddress) + .call() + } catch (e) { + this.logger.error(`ERROR: Failed to get: ${e.message}`) + } + return result.toString() } /** @@ -316,4 +339,20 @@ export class SideStaking { } return result } + + /** + * Get Router address set in side staking contract + * @param {String} ssAddress side staking contract address + * @return {String} + */ + async getRouter(ssAddress: string): Promise { + const sideStaking = new this.web3.eth.Contract(this.ssABI, ssAddress) + let result = null + try { + result = await sideStaking.methods.router().call() + } catch (e) { + this.logger.error(`ERROR: Failed to get Router address: ${e.message}`) + } + return result + } } diff --git a/test/unit/pools/fixedRate/FixedRateExchange.test.ts b/test/unit/pools/fixedRate/FixedRateExchange.test.ts index 92e9f52e..e1a9955e 100644 --- a/test/unit/pools/fixedRate/FixedRateExchange.test.ts +++ b/test/unit/pools/fixedRate/FixedRateExchange.test.ts @@ -408,6 +408,325 @@ describe('Fixed Rate unit test', () => { expect((await fixedRate.getFeesInfo(exchangeId)).marketFee).to.equal('0.01') }) + it('#updateMarketFeeCollector - should update Market fee collector if market fee collector', async () => { + expect((await fixedRate.getFeesInfo(exchangeId)).marketFeeCollector).to.equal(user3) + + await fixedRate.updateMarketFeeCollector(user3, exchangeId, user2) + + expect((await fixedRate.getFeesInfo(exchangeId)).marketFeeCollector).to.equal(user2) + }) + }) + describe('Test a Fixed Rate Exchange with USDC (6 Decimals)', () => { + it('#create an exchange', async () => { + // CREATE AN Exchange + // we prepare transaction parameters objects + const nftData = { + name: '72120Bundle', + symbol: '72Bundle', + templateIndex: 1, + baseURI: 'https://oceanprotocol.com/nft/' + } + const ercData = { + templateIndex: 1, + strings: ['ERC20B1', 'ERC20DT1Symbol'], + addresses: [contracts.accounts[0], user3, contracts.accounts[0], ADDRESS_ZERO], + uints: [web3.utils.toWei('1000000'), 0], + bytess: [] + } + + // [baseToken,owner,marketFeeCollector,allowedSwapper] + const fixedRateData = { + fixedPriceAddress: contracts.fixedRateAddress, + addresses: [contracts.usdcAddress, exchangeOwner, user3, ADDRESS_ZERO], + uints: [6, 18, web3.utils.toWei('1'), 1e15, 0] + } + + const nftFactory = new NFTFactory(contracts.factory721Address, web3, LoggerInstance) + + const txReceipt = await nftFactory.createNftErcWithFixedRate( + exchangeOwner, + nftData, + ercData, + fixedRateData + ) + + initialBlock = await web3.eth.getBlockNumber() + dtAddress = txReceipt.events.TokenCreated.returnValues.newTokenAddress + exchangeId = txReceipt.events.NewFixedRate.returnValues.exchangeId + + dtContract = new web3.eth.Contract(ERC20Template.abi as AbiItem[], dtAddress) + // user2 has no dt1 + expect(await dtContract.methods.balanceOf(user2).call()).to.equal('0') + + fixedRateAddress = contracts.fixedRateAddress + fixedRate = new FixedRateExchange( + web3, + LoggerInstance, + fixedRateAddress, + FixedRate.abi as AbiItem[], + contracts.oceanAddress + ) + assert(fixedRate != null) + }) + + it('#isActive - should return true if exchange is active', async () => { + expect(await fixedRate.isActive(exchangeId)).to.equal(true) + expect(await fixedRate.isActive('0x00')).to.equal(false) + }) + it('#getOwner - should get exchange owner given an id', async () => { + expect(await fixedRate.getExchangeOwner(exchangeId)).to.equal(exchangeOwner) + }) + it('#getOPFCollector - should get OPF collector', async () => { + expect(await fixedRate.getOPFCollector()).to.equal(contracts.opfCollectorAddress) + }) + it('#getRouter - should get Router address', async () => { + expect(await fixedRate.getRouter()).to.equal(contracts.routerAddress) + }) + + it('#deactivate - should deactivate an exchange if exchangeOwner', async () => { + expect(await fixedRate.isActive(exchangeId)).to.equal(true) + await fixedRate.deactivate(exchangeOwner, exchangeId) + + expect(await fixedRate.isActive(exchangeId)).to.equal(false) + }) + + it('#activate - should activate an exchange if exchangeOwner', async () => { + expect(await fixedRate.isActive(exchangeId)).to.equal(false) + await fixedRate.activate(exchangeOwner, exchangeId) + expect(await fixedRate.isActive(exchangeId)).to.equal(true) + }) + + it('#activateMint - should activate Mint(allows fixed rate contract to mint dts if required), if exchangeOwner', async () => { + expect((await fixedRate.getExchange(exchangeId)).withMint).to.equal(false) + await fixedRate.activateMint(exchangeOwner, exchangeId) + expect((await fixedRate.getExchange(exchangeId)).withMint).to.equal(true) + }) + + it('#dectivateMint - should deactivate Mint if exchangeOwner', async () => { + expect((await fixedRate.getExchange(exchangeId)).withMint).to.equal(true) + await fixedRate.deactivateMint(exchangeOwner, exchangeId) + expect((await fixedRate.getExchange(exchangeId)).withMint).to.equal(false) + }) + + it('#generate exchangeId - should generate a specific exchangeId', async () => { + expect( + await fixedRate.generateExchangeId( + contracts.usdcAddress, + dtAddress, + exchangeOwner + ) + ).to.equal(exchangeId) + }) + + it('#getNumberOfExchanges - should return total number of exchanges', async () => { + expect(await fixedRate.getNumberOfExchanges()).to.equal('2') + }) + + it('#getExchanges - should return all exchanges ids', async () => { + const exchangeIds = await fixedRate.getExchanges() + expect(exchangeIds[1]).to.equal(exchangeId) + }) + + it('#getRate - should return rate', async () => { + expect(await fixedRate.getRate(exchangeId)).to.equal('1') + }) + + it('#setRate - set new rate if exchangeOwner', async () => { + await fixedRate.setRate(exchangeOwner, exchangeId, '2') + expect(await fixedRate.getRate(exchangeId)).to.equal('2') + await fixedRate.setRate(exchangeOwner, exchangeId, '1') + expect(await fixedRate.getRate(exchangeId)).to.equal('1') + }) + + it('#getDTSupply - should get the dt supply in the exchange', async () => { + // exchange owner hasn't approved any DT for sell + expect(await fixedRate.getDTSupply(exchangeId)).to.equal('0') + }) + it('#getBTSupply - should get the bt supply in the exchange', async () => { + // no basetoken at the beginning + expect(await fixedRate.getBTSupply(exchangeId)).to.equal('0') + }) + it('#getAmountBTIn - should get bt amount in for a specific dt amount', async () => { + // 100.2 USDC for 100 DT (0.1% market fee and 0.1% ocean fee) + expect(await fixedRate.getAmountBTIn(exchangeId, '100')).to.equal('100.2') + }) + it('#getAmountBTOut - should get bt amount out for a specific dt amount', async () => { + // 99.8 USDC for 100 DT (0.1% market fee and 0.1% ocean fee) + expect(await fixedRate.getAmountBTOut(exchangeId, '100')).to.equal('99.8') + }) + + it('#buyDT - user2 should buy some dt', async () => { + // total supply is ZERO right now so dt owner mints 1000 DT and approves the fixed rate contract + await dtContract.methods + .mint(exchangeOwner, web3.utils.toWei('1000')) + .send({ from: exchangeOwner }) + await dtContract.methods + .approve(fixedRateAddress, web3.utils.toWei('1000')) + .send({ from: exchangeOwner }) + // user2 gets 100 USDC so he can buy DTs + await usdcContract.methods.transfer(user2, 100 * 1e6).send({ from: exchangeOwner }) + await usdcContract.methods + .approve(fixedRateAddress, 100 * 1e6) + .send({ from: user2 }) + + // user2 has no dts but has 100 USDC + expect(await dtContract.methods.balanceOf(user2).call()).to.equal('0') + const usdcBalanceBefore = new BN(await usdcContract.methods.balanceOf(user2).call()) + expect(usdcBalanceBefore.toString()).to.equal(new BN(100 * 1e6).toString()) + + // user2 buys 10 DT + const tx = await fixedRate.buyDT(user2, exchangeId, '10', '11') + // console.log(tx.events.Swapped.returnValues) + assert(tx.events.Swapped != null) + const args = tx.events.Swapped.returnValues + expect(args.exchangeId).to.equal(exchangeId) + expect(args.by).to.equal(user2) + expect(args.dataTokenSwappedAmount).to.equal(web3.utils.toWei('10')) + expect(args.tokenOutAddress).to.equal(dtAddress) + expect(await dtContract.methods.balanceOf(user2).call()).to.equal( + args.dataTokenSwappedAmount + ) + expect( + usdcBalanceBefore.sub(new BN(args.baseTokenSwappedAmount)).toString() + ).to.equal(await usdcContract.methods.balanceOf(user2).call()) + // basetoken stays in the contract + expect((await fixedRate.getExchange(exchangeId)).btBalance).to.equal('10') + // no dt in the contract + expect((await fixedRate.getExchange(exchangeId)).dtBalance).to.equal('0') + }) + + it('#sellDT - user2 should sell some dt', async () => { + await dtContract.methods + .approve(fixedRateAddress, web3.utils.toWei('10')) + .send({ from: user2 }) + const usdcBalanceBefore = new BN(await usdcContract.methods.balanceOf(user2).call()) + const tx = await fixedRate.sellDT(user2, exchangeId, '10', '9') + // console.log(tx.events.Swapped.returnValues) + assert(tx.events.Swapped != null) + const args = tx.events.Swapped.returnValues + expect(args.exchangeId).to.equal(exchangeId) + expect(args.by).to.equal(user2) + expect(args.dataTokenSwappedAmount).to.equal(web3.utils.toWei('10')) + expect(args.tokenOutAddress).to.equal(contracts.usdcAddress) + expect(await dtContract.methods.balanceOf(user2).call()).to.equal('0') + expect( + usdcBalanceBefore.add(new BN(args.baseTokenSwappedAmount)).toString() + ).to.equal(await usdcContract.methods.balanceOf(user2).call()) + // DTs stay in the contract + expect((await fixedRate.getExchange(exchangeId)).dtBalance).to.equal('10') + // no BTs in the contract (except for the fees, but not accounted here) + expect((await fixedRate.getExchange(exchangeId)).btBalance).to.equal('0') + // DT supply is back at 1000 (exchange Owner allowance + dt balance in the fixed rate) + expect(await fixedRate.getDTSupply(exchangeId)).to.equal('1000') + }) + + it('#getExchange - should return exchange details', async () => { + const result = await fixedRate.getExchange(exchangeId) + expect(result.active).to.equal(true) + expect(result.btDecimals).to.equal('6') + expect(result.dtDecimals).to.equal('18') + expect(result.baseToken).to.equal(contracts.usdcAddress) + expect(result.dataToken).to.equal(dtAddress) + expect(result.exchangeOwner).to.equal(exchangeOwner) + expect(result.withMint).to.equal(false) + expect(result.dtBalance).to.equal('10') // balance in the fixedRate + expect(result.btBalance).to.equal('0') // balance in the fixedRate + expect(result.dtSupply).to.equal('1000') // total supply available (owner allowance + dtBalance) + expect(result.btSupply).to.equal('0') // total supply available of basetoken in the contract + expect(result.fixedRate).to.equal('1') + }) + + it('#getFeesInfo - should return exchange fee details', async () => { + const result = await fixedRate.getFeesInfo(exchangeId) + expect(result.marketFee).to.equal('0.001') + // we made 2 swaps for 10 DT at rate 1, the fee is 0.1% for market and always in basetoken so it's 0.01 USDC + // we made 2 swaps for 10 DT at rate 1, the fee is 0.1% for ocean community and always in basetoken so it's 0.01 USDC + expect(result.marketFeeAvailable).to.equal('0.02') // formatted for basetoken decimals + expect(result.oceanFeeAvailable).to.equal('0.02') // formatted for basetoken decimals + expect(result.marketFeeCollector).to.equal(user3) + expect(result.opfFee).to.equal('0.001') + }) + + it('#getAllowedSwapper- should return address(0) if not set, if exchangeOwner', async () => { + expect(await fixedRate.getAllowedSwapper(exchangeId)).to.equal(ADDRESS_ZERO) + }) + it('#setAllowedSwapper- should set an allowed swapper, if exchangeOwner', async () => { + await fixedRate.setAllowedSwapper(exchangeOwner, exchangeId, user2) + expect(await fixedRate.getAllowedSwapper(exchangeId)).to.equal(user2) + }) + it('#setAllowedSwapper- should disable allowed swapper(return address(0)), if exchangeOwner', async () => { + await fixedRate.setAllowedSwapper(exchangeOwner, exchangeId, ADDRESS_ZERO) + expect(await fixedRate.getAllowedSwapper(exchangeId)).to.equal(ADDRESS_ZERO) + }) + it('#collectBT- should collect BT in the contract, if exchangeOwner', async () => { + // there are no bt in the contract + expect((await fixedRate.getExchange(exchangeId)).btBalance).to.equal('0') + // user2 buys 1 DT + await fixedRate.buyDT(user2, exchangeId, '1', '2') + // 1 DAI in the contract + expect((await fixedRate.getExchange(exchangeId)).btBalance).to.equal('1') + // owner collects BTs + await fixedRate.collectBT(exchangeOwner, exchangeId) + // btBalance is zero + expect((await fixedRate.getExchange(exchangeId)).btBalance).to.equal('0') + }) + it('#collectDT- should collect DT in the contract, if exchangeOwner', async () => { + const result = await fixedRate.getExchange(exchangeId) + // 9 dts left + expect(result.dtBalance).to.equal('9') + // owner collects DTs + await fixedRate.collectDT(exchangeOwner, exchangeId) + // no more dts in the contract + const result2 = await fixedRate.getExchange(exchangeId) + expect(result2.dtBalance).to.equal('0') + // Only allowance left since dt is ZERO + expect(result2.dtSupply).to.equal('990') + }) + it('#collectMarketFee- should collect marketFee and send it to marketFeeCollector, anyone can call it', async () => { + let result = await fixedRate.getFeesInfo(exchangeId) + // we made 2 swaps for 10 DT at rate 1, the fee is 0.1% for market and always in basetoken so it's 0.01 USDC + // plus another swap for 1 DT + expect(result.marketFeeAvailable).to.equal('0.021') // formatted for basetoken decimals + // same for ocean fee + expect(result.oceanFeeAvailable).to.equal('0.021') // formatted for basetoken decimals + expect(result.marketFeeCollector).to.equal(user3) + + // user4 calls collectMarketFee + await fixedRate.collectMarketFee(user4, exchangeId) + result = await fixedRate.getFeesInfo(exchangeId) + expect(result.marketFeeAvailable).to.equal('0') + // ocean fee still available + expect(result.oceanFeeAvailable).to.equal('0.021') + // user3 is the marketFeeCollector + expect(await usdcContract.methods.balanceOf(user3).call()).to.equal( + (0.021 * 1e6).toString() + ) + }) + it('#collectOceanFee- should collect oceanFee and send it to OPF Collector, anyone can call it', async () => { + let result = await fixedRate.getFeesInfo(exchangeId) + // we made 2 swaps for 10 DT at rate 1, the fee is 0.1% for market and always in basetoken so it's 0.01 DAI + // plus another swap for 1 DT + expect(result.oceanFeeAvailable).to.equal('0.021') // formatted for basetoken decimals + + // user4 calls collectOceanFee + await fixedRate.collectOceanFee(user4, exchangeId) + result = await fixedRate.getFeesInfo(exchangeId) + // fee has been reset + expect(result.oceanFeeAvailable).to.equal('0') + // OPF collector got the fee + expect( + await usdcContract.methods.balanceOf(await fixedRate.getOPFCollector()).call() + ).to.equal((0.021 * 1e6).toString()) + }) + + it('#updateMarketFee- should update Market fee if market fee collector', async () => { + expect((await fixedRate.getFeesInfo(exchangeId)).marketFee).to.equal('0.001') + // user3 is marketFeeCollector + await fixedRate.updateMarketFee(user3, exchangeId, '0.01') + + expect((await fixedRate.getFeesInfo(exchangeId)).marketFee).to.equal('0.01') + }) + it('#updateMarketFeeCollector - should update Market fee collector if market fee collector', async () => { expect((await fixedRate.getFeesInfo(exchangeId)).marketFeeCollector).to.equal(user3) diff --git a/test/unit/pools/ssContracts/SideStaking.test.ts b/test/unit/pools/ssContracts/SideStaking.test.ts index 5f27e8dc..09a46407 100644 --- a/test/unit/pools/ssContracts/SideStaking.test.ts +++ b/test/unit/pools/ssContracts/SideStaking.test.ts @@ -4,6 +4,7 @@ import { TestContractHandler } from '../../../TestContractHandler' import { Contract } from 'web3-eth-contract' import Web3 from 'web3' import BigNumber from 'bignumber.js' +import BN from 'bn.js' import ERC721Factory from '@oceanprotocol/contracts/artifacts/contracts/ERC721Factory.sol/ERC721Factory.json' import ERC721Template from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC721Template.sol/ERC721Template.json' import SSContract from '@oceanprotocol/contracts/artifacts/contracts/pools/ssContracts/SideStaking.sol/SideStaking.json' @@ -194,13 +195,27 @@ describe('SideStaking unit test', () => { sideStakingAddress = contracts.sideStakingAddress }) + it('#getRouter - should get Router address', async () => { + expect(await sideStaking.getRouter(sideStakingAddress)).to.equal( + contracts.routerAddress + ) + }) + it('#getDataTokenCirculatingSupply - should get datatoken supply in circulation (vesting amount excluded)', async () => { - console.log( + expect( await sideStaking.getDataTokenCirculatingSupply( contracts.sideStakingAddress, erc20Token ) - ) + ).to.equal(web3.utils.toWei('12000')) + }) + it('#getDataTokenCurrentCirculatingSupply - should get datatoken supply in circulation ', async () => { + expect( + await sideStaking.getDataTokenCurrentCirculatingSupply( + contracts.sideStakingAddress, + erc20Token + ) + ).to.equal(web3.utils.toWei('2000')) }) it('#getBasetoken - should get basetoken address', async () => { expect(await sideStaking.getBasetoken(sideStakingAddress, erc20Token)).to.equal( @@ -457,7 +472,7 @@ describe('SideStaking unit test', () => { ercData, poolData ) - + initialBlock = await web3.eth.getBlockNumber() erc20Token = txReceipt.events.TokenCreated.returnValues.newTokenAddress poolAddress = txReceipt.events.NewPool.returnValues.poolAddress @@ -466,6 +481,62 @@ describe('SideStaking unit test', () => { expect(await erc20Contract.methods.balanceOf(user2).call()).to.equal('0') }) + it('#getBasetokenBalance ', async () => { + expect( + await sideStaking.getBasetokenBalance(sideStakingAddress, erc20Token) + ).to.equal('0') + }) + it('#getDatatokenBalance ', async () => { + expect( + await sideStaking.getDatatokenBalance(sideStakingAddress, erc20Token) + ).to.equal('988000') + }) + + it('#getvestingAmount ', async () => { + expect(await sideStaking.getvestingAmount(sideStakingAddress, erc20Token)).to.equal( + '10000' + ) + }) + it('#getvestingLastBlock ', async () => { + expect( + await sideStaking.getvestingLastBlock(sideStakingAddress, erc20Token) + ).to.equal(initialBlock.toString()) + }) + + it('#getvestingEndBlock ', async () => { + expect( + await sideStaking.getvestingEndBlock(sideStakingAddress, erc20Token) + ).to.equal((initialBlock + vestedBlocks).toString()) + }) + it('#getvestingAmountSoFar ', async () => { + expect( + await sideStaking.getvestingAmountSoFar(sideStakingAddress, erc20Token) + ).to.equal('0') + }) + + it('#getVesting ', async () => { + expect( + await erc20Contract.methods.balanceOf(contracts.accounts[0]).call() + ).to.equal('0') + + const tx = await sideStaking.getVesting( + contracts.accounts[0], + sideStakingAddress, + erc20Token + ) + + expect( + await sideStaking.unitsToAmount( + erc20Token, + await erc20Contract.methods.balanceOf(contracts.accounts[0]).call() + ) + ).to.equal(await sideStaking.getvestingAmountSoFar(sideStakingAddress, erc20Token)) + + expect( + await sideStaking.getvestingLastBlock(sideStakingAddress, erc20Token) + ).to.equal((await web3.eth.getBlockNumber()).toString()) + }) + it('#swapExactAmountIn - should swap', async () => { const transferAmount = await pool.amountToUnits(contracts.usdcAddress, '1000') // 1000 USDC await usdcContract.methods