However, it's not possible to remove all deposits from the strategy because the logic within strategy.withdraw(totalStrategyDeposits, _strategyWithdrawalData)
requires that the total deposits must remain greater than or equal to the minimum specified in getMinDeposits()
within the strategy contract. Therefore, if the owner attempts to remove all deposits, they will encounter a revert with the message "Total deposits must remain >= minimum"
.
it('unable to remove strategies with token balance', async () => {
const { signers, accounts } = await getAccounts()
const adrs: any = {}
const token = (await deploy('contracts/core/tokens/base/ERC677.sol:ERC677', [
'Chainlink',
'LINK',
1000000000,
])) as ERC677
adrs.token = await token.getAddress()
await setupToken(token, accounts)
const erc677Receiver = (await deploy('ERC677ReceiverMock')) as ERC677ReceiverMock
adrs.erc677Receiver = await erc677Receiver.getAddress()
const stakingPool = (await deployUpgradeable('StakingPool', [
adrs.token,
'LinkPool LINK',
'lpLINK',
[
[accounts[4], 1000],
[adrs.erc677Receiver, 2000],
],
toEther(10000),
])) as StakingPool
adrs.stakingPool = await stakingPool.getAddress()
const strategy1 = (await deployUpgradeable('StrategyMock', [
adrs.token,
adrs.stakingPool,
toEther(1000),
toEther(10),
])) as StrategyMock
adrs.strategy1 = await strategy1.getAddress()
const strategy2 = (await deployUpgradeable('StrategyMock', [
adrs.token,
adrs.stakingPool,
toEther(2000),
toEther(20),
])) as StrategyMock
adrs.strategy2 = await strategy2.getAddress()
const strategy3 = (await deployUpgradeable('StrategyMock', [
adrs.token,
adrs.stakingPool,
toEther(10000),
toEther(10),
])) as StrategyMock
adrs.strategy3 = await strategy3.getAddress()
await stakingPool.addStrategy(adrs.strategy1)
await stakingPool.addStrategy(adrs.strategy2)
await stakingPool.addStrategy(adrs.strategy3)
await stakingPool.setPriorityPool(accounts[0])
await stakingPool.setRebaseController(accounts[0])
await token.approve(adrs.stakingPool, ethers.MaxUint256)
await stakingPool.deposit(accounts[0], toEther(1000), ['0x', '0x'])
await stakingPool.removeStrategy(1, '0x', '0x')
let strategies = await stakingPool.getStrategies()
assert.equal(
JSON.stringify(strategies),
JSON.stringify([adrs.strategy1, adrs.strategy3]),
'Remaining strategies incorrect'
)
await stakingPool.removeStrategy(1, '0x', '0x')
strategies = await stakingPool.getStrategies()
assert.equal(
JSON.stringify(strategies),
JSON.stringify([adrs.strategy1]),
'Remaining strategies incorrect'
)
await expect(stakingPool.removeStrategy(0, '0x', '0x')).to.be.revertedWith(
'Total deposits must remain >= minimum'
)
let canWithdraw = BigInt(await strategy1.canWithdraw())
const strategy1BalanceBefore = BigInt(await token.balanceOf(adrs.strategy1));
assert.isTrue(strategy1BalanceBefore - canWithdraw > 0)
await stakingPool.strategyWithdraw(0, canWithdraw, '0x')
canWithdraw = BigInt(await strategy1.canWithdraw())
const strategy1BalanceAfter = BigInt(await token.balanceOf(adrs.strategy1))
let totalStrategyDeposits = BigInt(await strategy1.getTotalDeposits())
assert.equal(canWithdraw, BigInt(0), "can withdraw 0")
assert.isTrue(strategy1BalanceAfter > 0, "token locked in strategy")
assert.isTrue(totalStrategyDeposits > 0, "total strategy deposits still great than 0")
await expect(stakingPool.removeStrategy(0, '0x', '0x')).to.be.revertedWith(
'Total deposits must remain >= minimum'
)
})