Skip to content

Commit 5604ccf

Browse files
authored
Merge pull request #6 from buttonwood-protocol/updating-router-vault-deposit
feat(router): making vault whitelists compatible with router usage
2 parents 43573b1 + 9b3b69b commit 5604ccf

6 files changed

Lines changed: 368 additions & 100 deletions

File tree

addresses/addresses-999.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"fulfillmentVaultAddress": "0x8Bc1F48Ce0D241BB2B7EC05AF202B7dA9aaBd1d9",
33
"rolloverVaultAddress": "0x5e4A85D1BaD334A2Fdd07856201136bC6eE2e302",
4-
"routerAddress": "0x58B6943Ed3a48981eA58c0918830eFd4febbe5a1"
4+
"routerAddress": "0x2A868EFd3cdF2bE83Ff63dECdfdc07A8dCAda316"
55
}

broadcast/DeployRouter.s.sol/999/run-1766194143046.json

Lines changed: 253 additions & 0 deletions
Large diffs are not rendered by default.

broadcast/DeployRouter.s.sol/999/run-latest.json

Lines changed: 96 additions & 96 deletions
Large diffs are not rendered by default.

src/Router.sol

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {PythErrors} from "@pythnetwork/PythErrors.sol";
2929
import {MortgageMath} from "@core/libraries/MortgageMath.sol";
3030
import {MortgagePosition} from "@core/types/MortgagePosition.sol";
3131
import {ILiquidityVault} from "./interfaces/ILiquidityVault/ILiquidityVault.sol";
32+
import {IAccessControl} from "@openzeppelin/contracts/access/IAccessControl.sol";
3233

3334
/**
3435
* @title Router
@@ -466,18 +467,25 @@ contract Router is
466467
* @param usdTokenAmount The amount of usdToken to pull in
467468
*/
468469
function _vaultDeposit(address vault, address usdToken, uint256 usdTokenAmount) internal {
470+
if (
471+
ILiquidityVault(vault).whitelistEnforced()
472+
&& !IAccessControl(vault).hasRole(ILiquidityVault(vault).WHITELIST_ROLE(), _msgSender())
473+
) {
474+
revert VaultWhitelistEnforced(vault, _msgSender());
475+
}
476+
469477
// Convert the usdTokenAmount to USDX
470478
uint256 usdxAmount = convert(usdToken, usdx, usdTokenAmount);
471479

472480
// Pull in the usdToken from the user
473481
_pullUsdToken(usdToken, usdxAmount);
474482

475-
// Deposit the USDX into the rollover vault
483+
// Deposit the USDX into the vault
476484
IUSDX(usdx).approve(vault, usdxAmount);
477485
ILiquidityVault(vault).deposit(usdx, usdxAmount);
478486

479487
// Transfer the vault share tokens to the user
480-
ILiquidityVault(vault).transfer(msg.sender, ILiquidityVault(vault).balanceOf(address(this)));
488+
ILiquidityVault(vault).transfer(_msgSender(), ILiquidityVault(vault).balanceOf(address(this)));
481489
}
482490

483491
/**

src/interfaces/IRouter/IRouterErrors.sol

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,11 @@ interface IRouterErrors {
1414
* @param maxColllected The maximum amount that can be collected
1515
*/
1616
error CollectedAmountExceedsMaximum(address token, uint256 collectedAmount, uint256 maxColllected);
17+
18+
/**
19+
* @notice Thrown when the vault's whitelist is enforced and the sender is not whitelisted
20+
* @param vault The address of the vault
21+
* @param sender The address of the sender
22+
*/
23+
error VaultWhitelistEnforced(address vault, address sender);
1724
}

verification.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)