Example Codes

I'll define a few pseudo-code functions and constants to make snippets more concise.

Some are also defined in the lib/Token.sol

// Let's define a function for you to see more comfortably
function toTokenInfo(bytes1 _tokenRefIndex,uint8 _method,int128 _amount) pure returns (bytes32) {
    return bytes32(bytes1(_tokenRefIndex)) | bytes32(bytes2(uint16(_method))) | bytes32(uint256(uint128(uint256(int256(_amount)))));;
}
function toPoolId(uint8 _optype,address _pool) pure returns (bytes32){
    return bytes32(bytes1(_optype)) | bytes32(uint256(uint160(address(_pool))));
}
function toToken(IERC20 tok) pure returns (Token) {
    return Token.wrap(bytes32(uint256(uint160(address(tok)))));
}
function toToken(TokenSpecType spec_, uint88 id_, address addr_) pure returns (Token) {
    return Token.wrap(
        TokenSpecType.unwrap(spec_) | bytes32((bytes32(uint256(id_)) << ID_SHIFT) & ID_MASK)
            | bytes32(uint256(uint160(addr_)))
    );
}
// use NATIVE_TOKEN for ETH since we don't use weth internally
Token constant NATIVE_TOKEN = Token.wrap(0xEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE); //ref: lib/Token.sol
uint8 constant SWAP = 0;
uint8 constant GAUGE = 1;
uint8 constant CONVERT = 2;
uint8 constant VOTE = 3;
uint8 constant USERBALANCE = 4;

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

The helper functions above will help you populate the Token/poolId/TokenInfo struct.

These 3 components are all you need for execute!

Swap

Add liquidity

Stake

Voting

Multicall operations

cf) wrapper functions

Last updated