Integrate via Smart Contracts

Integrating with Vertex via a Smart Contract

Smart contracts can use the LinkSigner transaction type (see Link Signer) to perform the following:

  1. Deposit into Vertex.

  2. LinkSigner an externally owned account (EOA).

  3. Have the externally owned account trade using the smart contract's assets on Vertex.

Setup: Depositing into Vertex + Linking an EOA

  1. Deposits are always on-chain, as such, users can simply have their smart contract call depositCollateral on our Endpoint contract (see Contracts for addresses).

  2. The contract needs to have 1 USDC available to pay for slow-mode fee and approve the endpoint contract, assemble the bytes for a slow mode linked signer transaction, and submit it via submitSlowModeTransaction.

You can find the requisite parsing logic in the Endpoint contract.

Example

struct LinkSigner {
    bytes32 sender;
    bytes32 signer;
    uint64 nonce;
}

function linkVertexSigner(
        address vertexEndpoint,
        address externalAccount,
        address usdcAddress
    ) external {
    // 1. a slow mode fee of 1 USDC needs to be avaliable and approved
    ERC20 usdcToken =  ERC20(usdcAddress);
    
    // NOTE: should double check the USDC decimals in the corresponding chain.
    // e.g: it's 1e6 on arbitrum, whereas it's 1e18 on blast, etc.
    uint256 SLOW_MODE_FEE = 1e6;
    usdcToken.transferFrom(msg.sender, address(this), SLOW_MODE_FEE);
    usdcToken.approve(vertexEndpoint, SLOW_MODE_FEE);
    
    // 2. assamble the link signer slow mode transaction
    bytes12 defaultSubaccountName = bytes12(abi.encodePacked("default"));
    bytes32 contractSubaccount = bytes32(
        abi.encodePacked(uint160(address(this)), defaultSubaccountName)
    );
    bytes32 externalSubaccount = bytes32(
        uint256(uint160(externalAccount)) << 96
    );
    LinkSigner memory linkSigner = LinkSigner(
        contractSubaccount,
        externalSubaccount,
        IEndpoint(vertexEndpoint).getNonce(externalAccount)
    );
    bytes memory txs = abi.encodePacked(
        uint8(19),
        abi.encode(linkSigner)
    );
    
    // 3. submit slow mode transaction
    IEndpoint(vertexEndpoint).submitSlowModeTransaction(txs);
}

Once the transaction is confirmed, it may take a few seconds for it to make its way into the vertex offchain sequencer. Afterwards, you can sign transactions that have sender contractSubaccount using externalSubaccount, and they will be accepted by the sequencer and the blockchain.

Last updated