Skip to content

added crosschain vaults and escrows#385

Open
Omurshid wants to merge 7 commits intomasterfrom
cross-chain-eth
Open

added crosschain vaults and escrows#385
Omurshid wants to merge 7 commits intomasterfrom
cross-chain-eth

Conversation

@Omurshid
Copy link
Copy Markdown
Contributor

No description provided.

@openzeppelin-code
Copy link
Copy Markdown

openzeppelin-code bot commented Jan 30, 2024

added crosschain vaults and escrows

Generated at commit: 6d0f7d5f9137019239d75d0c32b2b10f9027b062

🚨 Report Summary

Severity Level Results
Contracts Critical
High
Medium
Low
Note
Total
2
1
0
9
37
49
Dependencies Critical
High
Medium
Low
Note
Total
0
0
1
0
113
114

For more details view the full report in OpenZeppelin Code Inspector

if(currBalance<amountRequested){
uint256 amountToLiquidate = amountRequested - currBalance;
totalStrategyHoldings -= amountToLiquidate;
parentVault.withdraw(amountToLiquidate, address(this), address(this));
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should withdraw in proportion to tvl. if the parent vault has a loss in the system. then it shouldn't withdraw requested amount. should withdraw in ration of tvl and amount requested. otherwise person withdrawing last will pay the whole gas fees.

}

// function to withdraw tokens from the contract
function withdrawToken(address _token, uint256 _amount) external onlyGovernance{
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we use sweep to withdraw token from vault. and should transfer all assets of that token.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better to keep it in BaseVaultV2.

}

function setParentVault(address _parentVault) external onlyGovernance {
parentVault = Vault(_parentVault);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to have a check if it has the same assets or not. Also if its swapping the existing vault or not. should have the same gov address.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in case of swapping existing one. should withdraw all from existing parent vault.

import {BridgeEscrow} from "../BridgeEscrow.sol";
import {L1Vault} from "src/vaults/cross-chain-vault/L1Vault.sol";

interface IBaseBridge {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use the interface file in interface directory.


// TODO: change to mainnet address
// IBaseBridge public baseBridge = IBaseBridge(payable(0x49048044D57e1C92A77f79988d21Fa8fAF74E97e)); // mainnet
IBaseBridge public baseBridge = IBaseBridge(payable(0x49f53e41452C74589E85cA1677426Ba426459e85)); // testnet
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should set on constructor.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is similar as existing L2Wormhole router. Do we need this? or extend existing one?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment as prev one.

shares = previewDeposit(assets);
_deposit(_msgSender(), receiver, assets, shares);
uint256 amountToReturn = MathUpgradeable.min(assets, _asset.balanceOf(address(this)));
_asset.safeTransfer(receiver, amountToReturn);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this test code from PR.

}

// function to withdraw tokens from the contract
function withdrawToken(address _token, uint256 _amount) external onlyGovernance{
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be sweep in base vault. and transfer whole asset in case on emergency.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is similar as L2Vault. except TransferToL1 method. We can use the existing one with this new transfer method.
Also can put this percent in escrow and trigger this from escrow.

wormholeRouter = _router;
}

function sweep() external onlyGovernance {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Transferring full amount is nice. should have a token params in case of transfer any erc20 assets.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need this base vault

}

function setParentVault(address _parentVault) external onlyGovernance {
Vault temp = Vault(_parentVault);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should rename this to something like parentVault and params parentVaultAddress

baseBridge.depositTransaction{value: amountToBridge}(
l2EscrowAddress,
amountToBridge,
100000,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to have named variable for this constants.

IBaseBridge public baseBridge;
// IBaseBridge public baseBridge = IBaseBridge(payable(0x49f53e41452C74589E85cA1677426Ba426459e85)); // testnet
address public l2EscrowAddress;
IWETH public constant WETH = IWETH(payable(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2)); //mainnet
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should set as vault assets.

acrossBridge = IAcrossBridge(payable(0x09aea4b2242abC8bb4BB78D537A67a245A7bEC64));
}

fallback() external payable {}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need fallback and receive both?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IDE/ compiler gives warning if i only have one

constructor(L2Vault _vault) BridgeEscrow(_vault) {
vault = _vault;
asset.safeApprove(address(acrossBridge), type(uint256).max);
acrossBridge = IAcrossBridge(payable(0x09aea4b2242abC8bb4BB78D537A67a245A7bEC64));
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can pass it as params in constructor.

ERC20(_token).safeTransfer(governance, _amount);
}

function setAcrossBridge(address _acrossBridgeAddress) external onlyGovernance {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should have a check to validate if this is a valid bridge contract.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there even a way to make sure? I can try to see if some of the read variables in the ABI return something but those can still be spoofed with a similar abi

l1EscrowAddress,
address(WETH),
amountToWithdraw,
1,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Constants.

);

bytes memory delimiterAndReferrer = abi.encodePacked(
hex"d00dfeeddeadbeef",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using direct hex is fine. Please use comment for the original text.

* @author Affine Devs. Inspired by OpenZeppelin and Rari-Capital.
*/

contract L2VaultBase is
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we just do L2VaultBase is L2Vault here ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants