VELOCORE V2
V1 DocszkSyncEraLineaTelos
  • Introduction
  • Our Philosophy
    • Vision
    • Gas Optimization
    • General Bedrock for All Kinds of AMM
    • Epoch-less Predictability
    • Free Flowing Easy Vote System
  • DEX Innovation
    • Token Vault
      • Flashloan
    • Gas Saving Matters : Benchmark
    • AMM Flexibility
    • Multi In/Out Swap
    • Batch Swap
    • Adjustable Trading Fee Mechanics
    • Accumulating Swap Fees in LP Tokens
  • ve(3,3) Innovation
    • Removing 'Epoch' Systems
      • Bribe Optimization
    • Fungible Votes ($veVC)
      • No Decay & Easy Liquidation
    • Decentralized Gauge Deployment
    • Rebase Elimination
  • Security & Contract Address
    • zkSyncEra Contracts
    • Linea Contracts
    • Telos Contracts
    • V1 zkSyncEra (deprecated)
    • Three Rounds of Audits
  • Technical Docs
    • Concepts
    • Architecture Overview
      • Source Files Overview
    • How to interact with VELOCORE
      • Uniswap compatible interface
    • How to Read Data
    • Example Codes
      • Swap
      • Add liquidity
      • Stake
      • Voting
      • Multicall operations
      • cf) wrapper functions
    • Typescript Examples for Integration
    • Pool Specifics
      • Generalized CPMM
      • Wombat Stableswap
    • Events & Chart Integration
      • Getting a pair list
      • Interpreting Swap / LP events
    • Flashloan
  • zkSync Era
    • Migration Plan
      • $VC 1:1 Exchange
      • veNFT -> $veVC
      • One-Step LP Migration
      • Migration Schedule
      • Emission Migration
    • V2 Tokenomics
      • $VC Gauge
      • Bribe Mechanics
      • $veVC VOTING
    • Paymaster as a Service
  • Linea
    • Launch Details
      • Getting Ready
      • Bridging
      • V2 Launch Event
      • $LVC Presale
    • $LVC Tokenomics
      • $LVC Gauge
      • Bribe Mechanics
      • $veLVC VOTING
  • Telos
    • Launch Details
      • Getting Ready
      • Bridging
      • Launch Event
    • $TVC Tokenomics
      • $TVC Gauge
      • Bribe Mechanics
      • $veTVC VOTING
  • Free Loot Box for Future Airdrops
  • PASSPORT - F'air drops
  • Legal Disclaimer
  • Velocore Brand Assets
Powered by GitBook
On this page
  1. Technical Docs
  2. Example Codes

cf) wrapper functions

execute2() / execute3()

Last updated 1 year ago

For those who don't feel comfortable writing all functions using execute directly, I've added some frequently used functions as execute2/3 functions via a helper facet. However, remember that stable pools have different addresses for gauge and pool, so you can't interact with gauge through this wrapper function.

You could see the actual implementation of execute2/3 wrapper .

This example allows you to harvest, swap each tokens, add lp, and stake all in one transaction without deploying a separate contract.

pragma solidity ^0.8.19;

import "src/lib/Token.sol";
import "src/interfaces/IVault.sol";
import "src/interfaces/IFactory.sol";
import "src/interfaces/IPool.sol";

contract Example {
    using TokenLib for Token;

    IVault vault = IVault(0x1d0188c4B276A09366D05d6Be06aF61a73bC7535);

    uint8 constant SWAP = 0;
    uint8 constant GAUGE = 1;

    uint8 constant EXACTLY = 0;
    uint8 constant AT_MOST = 1;
    uint8 constant ALL = 2;

    function run() external {
        address usdc = 0x176211869cA2b568f2A7D4EE941E073a821EE1ff;
        address vc = 0xcc22F6AA610D1b2a0e89EF228079cB3e1831b1D1;
        address eth = address(0);
        address usdc_eth_pool = vault.getPair(usdc, eth);
        address usdc_eth_lp = usdc_eth_pool;

        IERC20(0x176211869cA2b568f2A7D4EE941E073a821EE1ff).approve(address(vault), type(uint256).max);
        // you can optimize gas by batching operations.
        // this example will execute them separately for clarity

        //swap usdc->eth
        vault.execute2(
            usdc_eth_pool, SWAP,
            usdc, EXACTLY, 0.1e6,
            eth, AT_MOST, 0,
            ""
        );

        //add lp and stake
        vault.execute3{value: 0.001e18}(
            usdc_eth_pool, SWAP,
            usdc, EXACTLY, 0.1e6,
            eth, EXACTLY, 0.001e18,
            usdc_eth_lp, AT_MOST, 0,
            ""
        );
        vault.execute2(
            usdc_eth_pool, GAUGE,
            usdc_eth_lp, EXACTLY, int128(int256(IERC20(usdc_eth_lp).balanceOf(address(this)))),
            vc, AT_MOST, 0,
            ""
        );



        address[] memory path = new address[](3);
        path[0] = usdc;
        path[1] = eth;
        path[2] = vc;


        //you can also use uniswap-like interface
        vault.swapExactTokensForTokens(
            1e18, 0.9e18, path, address(this), block.timestamp
        );
    }
}

```
link here