Skip to content

Commit

Permalink
Add KYC check to BridgerL2, update constructors and tests for kintoID…
Browse files Browse the repository at this point in the history
… integration.
  • Loading branch information
ylv-io committed Jan 10, 2025
1 parent 897b9f1 commit 44e5632
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 34 deletions.
2 changes: 1 addition & 1 deletion script/actions/deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ contract DeployerScript is Create2Helper, DeployerHelper {

function deployBridgerL2() public returns (BridgerL2 _bridgerL2, BridgerL2 _bridgerL2Impl) {
bytes memory creationCode = type(BridgerL2).creationCode;
bytes memory bytecode = abi.encodePacked(creationCode, abi.encode(address(factory)));
bytes memory bytecode = abi.encodePacked(creationCode, abi.encode(address(factory), address(kintoID)));
address implementation = _deployImplementation("BridgerL2", bytecode, false);
address proxy = _deployProxy("BridgerL2", implementation, false);

Expand Down
17 changes: 11 additions & 6 deletions src/bridger/BridgerL2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
pragma solidity ^0.8.18;

import {IBridger} from "@kinto-core/interfaces/bridger/IBridger.sol";
import {IKintoID} from "@kinto-core/interfaces/IKintoID.sol";

import "@kinto-core/interfaces/bridger/IBridgerL2.sol";
import "@kinto-core/interfaces/IKintoWalletFactory.sol";
Expand Down Expand Up @@ -37,8 +38,10 @@ contract BridgerL2 is Initializable, UUPSUpgradeable, OwnableUpgradeable, Reentr
address public constant TREASURY = 0x793500709506652Fcc61F0d2D0fDa605638D4293;

/* ============ State Variables ============ */
/// @notice
IKintoID public immutable kintoID;
/// @notice
IKintoWalletFactory public immutable walletFactory;

/// @notice Mapping of all depositors by user address and asset address
mapping(address => mapping(address => uint256)) public override deposits;
/// @notice Deposit totals per asset
Expand All @@ -49,16 +52,15 @@ contract BridgerL2 is Initializable, UUPSUpgradeable, OwnableUpgradeable, Reentr
bool public override unlocked;
/// @notice Phase IV assets
address[] public depositedAssets;
/// @notice admin wallet
address public immutable adminWallet;
/// @notice List of allowed vaults for the Bridge.
mapping(address => bool) public bridgeVaults;

/* ============ Constructor & Upgrades ============ */
constructor(address _walletFactory) {
constructor(address _walletFactory, address _kintoID) {
_disableInitializers();

walletFactory = IKintoWalletFactory(_walletFactory);
adminWallet = 0x2e2B1c42E38f5af81771e65D87729E57ABD1337a;
kintoID = IKintoID(_kintoID);
}

/**
Expand Down Expand Up @@ -104,6 +106,9 @@ contract BridgerL2 is Initializable, UUPSUpgradeable, OwnableUpgradeable, Reentr
if (walletFactory.walletTs(msg.sender) == 0) {
revert InvalidWallet(msg.sender);
}
if (!kintoID.isKYC(IKintoWallet(msg.sender).owners(0))) {
revert KYCRequired(receiver);
}
if (!IKintoWallet(msg.sender).isFunderWhitelisted(receiver)) {
revert InvalidReceiver(receiver);
}
Expand Down Expand Up @@ -255,5 +260,5 @@ contract BridgerL2 is Initializable, UUPSUpgradeable, OwnableUpgradeable, Reentr
}

contract BridgerL2V9 is BridgerL2 {
constructor(address _walletFactory) BridgerL2(_walletFactory) {}
constructor(address walletFactory, address kintoID) BridgerL2(walletFactory, kintoID) {}
}
1 change: 1 addition & 0 deletions src/interfaces/bridger/IBridgerL2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pragma solidity ^0.8.18;
interface IBridgerL2 {
/* ============ Errors ============ */

error KYCRequired(address user);
error InvalidReceiver(address wallet);
error InvalidWallet(address wallet);
error NotUnlockedYet();
Expand Down
2 changes: 1 addition & 1 deletion test/fork/bridger/BridgerL2.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ contract BridgerL2Test is SignatureHelper, SharedSetup, BridgeDataHelper {

// upgrade Bridger L2 to latest version
// TODO: remove upgrade after having actually upgraded the contract on mainnet
BridgerL2 _newImpl = new BridgerL2(address(_walletFactory));
BridgerL2 _newImpl = new BridgerL2(address(_walletFactory), address(_kintoID));
vm.prank(_owner);
_bridgerL2.upgradeTo(address(_newImpl));

Expand Down
29 changes: 3 additions & 26 deletions test/unit/bridger/BridgerL2.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ contract BridgerL2NewUpgrade is BridgerL2 {
return 1;
}

constructor(address factory) BridgerL2(factory) {}
constructor(address factory, address kintoID) BridgerL2(factory, kintoID) {}
}

contract BridgerL2Test is SignatureHelper, SharedSetup {
Expand All @@ -43,14 +43,14 @@ contract BridgerL2Test is SignatureHelper, SharedSetup {
/* ============ Upgrade tests ============ */

function testUpgradeTo() public {
BridgerL2NewUpgrade _newImpl = new BridgerL2NewUpgrade(address(_walletFactory));
BridgerL2NewUpgrade _newImpl = new BridgerL2NewUpgrade(address(_walletFactory), address(_kintoID));
vm.prank(_owner);
_bridgerL2.upgradeTo(address(_newImpl));
assertEq(BridgerL2NewUpgrade(payable(address(_bridgerL2))).newFunction(), 1);
}

function testUpgradeTo_RevertWhen_CallerIsNotOwner() public {
BridgerL2NewUpgrade _newImpl = new BridgerL2NewUpgrade(address(_walletFactory));
BridgerL2NewUpgrade _newImpl = new BridgerL2NewUpgrade(address(_walletFactory), address(_kintoID));
vm.expectRevert("Ownable: caller is not the owner");
_bridgerL2.upgradeToAndCall(address(_newImpl), bytes(""));
}
Expand Down Expand Up @@ -159,27 +159,6 @@ contract BridgerL2Test is SignatureHelper, SharedSetup {
assertEq(ERC20(sDAIL2).balanceOf(address(_kintoWallet)), _amount);
}

function testClaimCommitment_RevertWhen_WalletIsInvalid() public {
address _asset = sDAI;
uint256 _amount = 100;

address[] memory _assets = new address[](1);
_assets[0] = _asset;
deal(sDAIL2, address(_bridgerL2), _amount);

vm.startPrank(_owner);

_bridgerL2.setDepositedAssets(_assets);
_bridgerL2.writeL2Deposit(address(_kintoWallet), _asset, _amount);
_bridgerL2.unlockCommitments();

vm.stopPrank();

vm.prank(_user);
vm.expectRevert(IBridgerL2.InvalidWallet.selector);
_bridgerL2.claimCommitment();
}

function testClaimCommitment_RevertWhen_NotUnlocked() public {
address _asset = sDAI;
uint256 _amount = 100;
Expand Down Expand Up @@ -243,6 +222,4 @@ contract BridgerL2Test is SignatureHelper, SharedSetup {
assertEq(amounts[0], 1 ether);
assertEq(amounts[1], 4 ether);
}

// todo: test everything through user ops because it is what we will use
}

0 comments on commit 44e5632

Please sign in to comment.