Skip to content

Commit

Permalink
improve setVaultConfigs
Browse files Browse the repository at this point in the history
  • Loading branch information
defi-dev committed Feb 19, 2022
1 parent 0ea3b9c commit 50aadcd
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 61 deletions.
42 changes: 11 additions & 31 deletions contracts/Erc20VaultPoolSwap.sol
Original file line number Diff line number Diff line change
Expand Up @@ -78,43 +78,23 @@ contract Erc20VaultPoolSwap is ProgressiveFee, IErc20VaultPoolSwap {

function setVaultConfigs(
address[] memory _tokens,
address[] memory _depositors,
uint8[] memory _depositorTypes,
uint8[] memory _depositorAmountLength,
uint8[] memory _depositorIndexes,
address[] memory _lpTokens,
address[] memory _curvePoolRegistries
VaultConfig[] memory _vaultConfigs
) external onlyOwner {
uint256 len = _tokens.length;
require(
len == _depositors.length &&
len == _depositorAmountLength.length &&
len == _depositorIndexes.length &&
len == _depositorTypes.length &&
len == _lpTokens.length &&
len == _curvePoolRegistries.length,
"L"
);
require(len == _vaultConfigs.length, "L");
for (uint256 i = 0; i < len; i++) {
vaultConfig[_tokens[i]] = VaultConfig(
_depositorAmountLength[i],
_depositorIndexes[i],
_depositorTypes[i],
_depositors[i],
_lpTokens[i],
_curvePoolRegistries[i]
);
vaultConfig[_tokens[i]] = _vaultConfigs[i];

usdc.approve(_depositors[i], uint256(-1));
IERC20(_lpTokens[i]).approve(_tokens[i], uint256(-1));
IERC20(_lpTokens[i]).approve(_depositors[i], uint256(-1));
usdc.approve(_vaultConfigs[i].depositor, uint256(-1));
IERC20(_vaultConfigs[i].lpToken).approve(_tokens[i], uint256(-1));
IERC20(_vaultConfigs[i].lpToken).approve(_vaultConfigs[i].depositor, uint256(-1));
emit SetVaultConfig(
_tokens[i],
_depositors[i],
_depositorAmountLength[i],
_depositorIndexes[i],
_lpTokens[i],
_curvePoolRegistries[i]
_vaultConfigs[i].depositor,
_vaultConfigs[i].depositorLength,
_vaultConfigs[i].depositorIndex,
_vaultConfigs[i].lpToken,
_vaultConfigs[i].curvePoolRegistry
);
}
}
Expand Down
14 changes: 8 additions & 6 deletions test/Erc20VaultPoolSwap.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,14 @@ describe('Erc20VaultPoolSwap', () => {
});
await vaultPoolSwap.setVaultConfigs(
vaults.map(v => v.vault.address),
vaults.map(v => v.depositor.address),
vaults.map(v => v.config.depositorType || 1),
vaults.map(v => v.config.amountsLength),
vaults.map(v => v.config.usdcIndex),
vaults.map(v => v.lpToken.address),
vaults.map(() => vaultRegistry.address),
vaults.map(v => ({
depositorLength: v.config.amountsLength,
depositorIndex: v.config.usdcIndex,
depositorType: v.config.depositorType || 1,
depositor: v.depositor.address,
lpToken: v.lpToken.address,
curvePoolRegistry: vaultRegistry.address,
})),
);
await vaultPoolSwap.updatePools([pool.address]);

Expand Down
14 changes: 8 additions & 6 deletions test/IndicesSupplyRedeemZap.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -692,12 +692,14 @@ describe('IndicesSupplyRedeemZap', () => {
});
await vaultPoolSwap.setVaultConfigs(
vaults.map(v => v.vault.address),
vaults.map(v => v.depositor.address),
vaults.map(v => v.config.depositorType || 1),
vaults.map(v => v.config.amountsLength),
vaults.map(v => v.config.usdcIndex),
vaults.map(v => v.lpToken.address),
vaults.map(() => vaultRegistry.address),
vaults.map(v => ({
depositorLength: v.config.amountsLength,
depositorIndex: v.config.usdcIndex,
depositorType: v.config.depositorType || 1,
depositor: v.depositor.address,
lpToken: v.lpToken.address,
curvePoolRegistry: vaultRegistry.address,
})),
);
await vaultPoolSwap.updatePools([pool.address]);

Expand Down
34 changes: 16 additions & 18 deletions test/pvp/CVPMaker.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1276,15 +1276,14 @@ describe('CVPMaker test', () => {

await vaultSwap.setVaultConfigs(
[ycrvVault.address],
[crvDepositor.address],
// depositorType
[1],
// amountsLength
[2],
// usdcIndex
[1],
[curvePoolToken.address],
[curvePoolRegistry.address]
[{
depositorLength: 2,
depositorIndex: 1,
depositorType: 1,
depositor: crvDepositor.address,
lpToken: curvePoolToken.address,
curvePoolRegistry: curvePoolRegistry.address,
}],
);

tokens.push(ycrvVault);
Expand Down Expand Up @@ -1411,15 +1410,14 @@ describe('CVPMaker test', () => {

await vaultSwap.setVaultConfigs(
[ycrvVault.address],
[crvDepositor.address],
// depositorType
[1],
// amountsLength
[2],
// usdcIndex
[1],
[curvePoolToken.address],
[curvePoolRegistry.address]
[{
depositorLength: 2,
depositorIndex: 1,
depositorType: 1,
depositor: crvDepositor.address,
lpToken: curvePoolToken.address,
curvePoolRegistry: curvePoolRegistry.address,
}],
);

await usdc.transfer(crvDepositor.address, mwei(1e12));
Expand Down

0 comments on commit 50aadcd

Please sign in to comment.