Vault

Git Source

Inherits: ECDSAUtils, Events, ReentrancyGuard, OwnableUpgradeable

Abstract contract providing common vault functionality for bridge contracts

State Variables

nextUserTransferIndexes

Stores the transfer index for each user for unique transfer tracking

mapping(address => uint256) public nextUserTransferIndexes;

currentBridgeRequestId

Global unique bridge request ID

uint256 public currentBridgeRequestId;

bridgeRequests

Stores history of bridge requests

mapping(uint256 => Structs.BridgeRequestData) public bridgeRequests;

bridgeFee

Total fee charged to the user for bridging

uint256 public bridgeFee;

AVSReward

Total reward for AVS attestation

uint256 public AVSReward;

crankGasCost

Estimated gas cost for calling release funds, used to calculate rebate and incentivize users to call

uint256 public crankGasCost;

deployer

Address of the contract deployer

address deployer;

Functions

constructor

Initializes the contract with the necessary parameters

constructor(uint256 _crankGasCost, uint256 _AVSReward, uint256 _bridgeFee, string memory _name, string memory _version)
    ECDSAUtils(_name, _version);

Parameters

NameTypeDescription
_crankGasCostuint256The estimated gas cost for calling release funds, used to calculate rebate and incentivize users to call
_AVSRewarduint256The total reward for AVS attestation
_bridgeFeeuint256The total fee charged to the user for bridging
_namestringThe name of the contract, used for EIP-712 domain construction
_versionstringThe version of the contract, used for EIP-712 domain construction

initialize

Initializes the contract and transfers ownership to the deployer

function initialize() public initializer;

setBridgeFee

Sets the bridge fee

function setBridgeFee(uint256 _bridgeFee) external onlyOwner;

Parameters

NameTypeDescription
_bridgeFeeuint256The new bridge fee

setAVSReward

Sets the AVS reward

function setAVSReward(uint256 _AVSReward) external onlyOwner;

Parameters

NameTypeDescription
_AVSRewarduint256The new AVS reward

setCrankGasCost

Sets the crank gas cost

function setCrankGasCost(uint256 _crankGasCost) external onlyOwner;

Parameters

NameTypeDescription
_crankGasCostuint256The new crank gas cost

bridgeERC20

Internal function to transfer ERC20 tokens for bridging

function bridgeERC20(address tokenAddress, uint256 amountIn) internal;

Parameters

NameTypeDescription
tokenAddressaddressThe address of the token to be transferred
amountInuint256The amount of tokens to be transferred

bridge

Initiates a bridge request

function bridge(
    address tokenAddress,
    uint256 amountIn,
    uint256 amountOut,
    address destinationVault,
    address destinationAddress
) public payable nonReentrant;

Parameters

NameTypeDescription
tokenAddressaddressThe address of the token to be bridged
amountInuint256The amount of tokens to be bridged
amountOutuint256The amount of tokens expected at the destination
destinationVaultaddressThe address of the destination vault
destinationAddressaddressThe address of the recipient at the destination

_releaseFunds

Abstract function to release funds, to be implemented by inheriting contracts

function _releaseFunds(bytes memory data) public virtual;

Parameters

NameTypeDescription
databytesThe bridge request data and signatures