Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

12 minimum balance #75

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion pkg/pool-weighted/contracts/smart/IndexPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,13 @@ contract IndexPool is BaseWeightedPool, ReentrancyGuard, IIndexPool {
);
}

/// @dev Sets token minimum balance.
/// @param token Token to set minimal balance.
/// @param minimumBalance Minimal balance to set.
function setMinimumBalance(IERC20 token, uint256 minimumBalance) external authenticate {
minBalances[token] = minimumBalance;
}

/// @dev Identifies new tokens, registers them with pool and initiates weight change.
/// @param tokens List of pool tokens.
/// @param desiredWeights List of desired weights for tokens.
Expand Down Expand Up @@ -243,7 +250,7 @@ contract IndexPool is BaseWeightedPool, ReentrancyGuard, IIndexPool {

// check if uninitialized token will be swapped INTO the pool
if (minBalances[swapRequest.tokenIn] != 0) {
/*
/*
check if swap makes token become initialized
*/
if (currentBalanceTokenIn.add(swapRequest.amount) >= minBalances[swapRequest.tokenIn]) {
Expand Down Expand Up @@ -416,6 +423,7 @@ contract IndexPool is BaseWeightedPool, ReentrancyGuard, IIndexPool {
return
(actionId == getActionId(this.reindexTokens.selector)) ||
(actionId == getActionId(this.reweighTokens.selector)) ||
(actionId == getActionId(this.setMinimumBalance.selector)) ||
super._isOwnerOnlyAction(actionId);
}
}
30 changes: 30 additions & 0 deletions pkg/pool-weighted/test/IndexPool.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,36 @@ describe('IndexPool', function () {
});
});

describe('#setMinimumWeight', () => {
sharedBeforeEach('deploy pool', async () => {
const params = {
tokens,
weights,
owner,
poolType: WeightedPoolType.INDEX_POOL,
swapEnabledOnStart: false,
};
pool = await WeightedPool.create(params);
});

context('when called by not owner', () => {
it('reverts: "BAL#401 (SENDER_NOT_ALLOWED)"', async () => {
const address = allTokens.tokens.map((token) => token.address)[0];
const minimalBalance = fp(0.001);
await expect(pool.setMinimumBalance(randomDude, address, minimalBalance)).to.be.revertedWith('BAL#401');
});
});

context('when called by owner', () => {
it('Changes minimal balance', async () => {
const address = allTokens.tokens.map((token) => token.address)[0];
const minimalBalance = fp(0.001);
await pool.setMinimumBalance(owner, address, minimalBalance);
expect(await pool.minBalances(address)).to.equal(minimalBalance);
});
});
});

describe('#reweighTokens', () => {
sharedBeforeEach('deploy pool', async () => {
const params = {
Expand Down
1 change: 1 addition & 0 deletions pkg/solidity-utils/contracts/helpers/BalancerErrors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -227,4 +227,5 @@ library Errors {
// Index
uint256 internal constant INVALID_ZERO_MINIMUM_BALANCE = 700;
uint256 internal constant UNINITIALIZED_TOKEN = 701;
uint256 internal constant REMOVED_TOKEN = 702;
}
9 changes: 9 additions & 0 deletions pvt/helpers/src/models/pools/weighted/WeightedPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,15 @@ export default class WeightedPool {
return { amounts: result.collectedFees, tokenAddresses: result.tokens };
}

async setMinimumBalance(
from: SignerWithAddress,
token: string,
minimumBalance: BigNumberish
): Promise<ContractTransaction> {
const pool = this.instance.connect(from);
return await pool.setMinimumBalance(token, minimumBalance);
}

async reweighTokens(
from: SignerWithAddress,
tokens: string[],
Expand Down