Quickstart Solidity APIs

We use Foundry for integrating solidity APIs from Standard Exchange.

Install Foundry if you haven’t already.

curl -L https://foundry.paradigm.xyz | bash

Create a new Foundry project

forge init hello_standard

Install Standard's contracts from Github repo.

forge install https://github.com/standardweb3/standard3.0-contracts

Create remappings.txt to import installed Standard contracts.

forge remappings > remappings.txt

Usage

Once installed, you can use the contracts in the library by importing them:

pragma solidity ^0.8.24;

import {IMatchingEngine} from "standard3.0-contracts/src/exchange/interfaces/IMatchingEngine.sol";

contract CLOB {
    IMatchingEngine public matchingEngine;

    // Get matching address from  
    constructor(address _engine) {
        matchingEngine = IMatchingEngine(_engine);
    }

    function limitBuy(address base, address quote, uint256 price, uint256 quoteAmount, bool isMaker, uint32 matchingN, address recipient) public {
        matchingEngine.limitBuy(
            base,
            quote,
            price,
            quoteAmount,
            isMaker,
            matchingN,
            recipient
        );
    }

    function limitSell(address base, address quote, uint256 price, uint256 baseAmount, bool isMaker, uint32 matchingN, address recipient) public {
        matchingEngine.limitSell(
            base,
            quote,
            price,
            baseAmount,
            isMaker,
            matchingN,
            recipient
        );
    }
}

To keep your system secure, you should always use the installed code as-is, and neither copy-paste it from online sources nor modify it yourself. The library is designed so that only the contracts and functions you use are deployed, so you don't need to worry about it needlessly increasing gas costs.

Last updated