Skip to content

tentou-tech/evm-core-vault

Repository files navigation

evm-core-vault

A vault for solvers to keep liquidity between HyperEvm and Hyper Core

Building and Testing

This project requires Node.js version 22.10.0 or higher and yarn 4.6.0 or higher. Before building, install dependencies:

yarn install

To compile the contracts, run:

npx hardhat compile

To run tests, use:

npx hardhat test

Deployment

Deployment scripts are located in the deploy/ directory. You can deploy the contracts using Hardhat's deploy plugin. Make sure to configure your network settings in hardhat.config.ts before deploying.

npx hardhat deploy --network <network-name>

The flow

  1. The solver deposits liquidity into the vault by sending tokens to the vault contract. We don't track the balance of each token in the vault, the solver is responsible for ensuring there is enough liquidity for exchanges.
  2. There is only the settlement contract that can call the exchange function on the vault. This is enforced by the onlySettlement modifier.
  3. When the settlement contract calls the exchange function, it specifies the input token, output token, the amount to be exchanged, the expiration time, and the signatures from a group of trusted signers that were pre-designated by the solver. Note that the signatures are over the hash of the exchange parameters, ensuring authenticity and integrity. This is the data in the message that is signed:
    bytes32 orderUid,        // unique identifier for the order
    address tokenIn,         // address of the input token
    uint256 amountIn,        // amount of the input token
    address tokenOut,        // address of the output token
    uint256 amountOut,       // amount of the output token
    uint256 validTo,         // expiration time of the order
    uint256 block.chainid,   // enforce on current chainId to avoid replay attacks across chains
    uint256 nonce,           // unique number to avoid replay attacks
    address contractAddress, // address of this Vault contract
    address sender           // address of the settlement contract
    
    All parameters are concatenated using abi.encode before hashing. The signatures are signed using ECDSA on the resulting hash (https://ethereum.org/developers/docs/apis/json-rpc/#eth_sign).
  4. The vault verifies the signatures against the pre-designated trusted signers for the solver. If all the signatures are valid and meet the required threshold, the vault proceeds with the exchange.
  5. The vault takes the specified amount of the input token from the settlement contract, transferring the corresponding amount of the output token to the settlement contract, completing the exchange.

About

A vault for solvers to keep liquidity between HyperEvm and Hyper Core

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors