Files
ritmex-bot/docs/nado/developer-resources/api/gateway/signing.md
T

7.2 KiB

Signing

All executes are signed using EIP712. Each execute request contains:

  1. A piece of structured data that includes the sender address i.e: the primaryType that needs to be signed.
  2. A signature of the hash of that structured data, signed by the sender.

Domain

The following is the domain required as part of the EIP712 structure:

{
    name: 'Nado',
    version: '0.0.1',
    chainId: chainId,
    verifyingContract: contractAddress
}

You can retrieve the corresponding chain id and verifying contract via the contracts query.

{% hint style="warning" %} Note: make sure to use the correct verifying contract for each execute:

  • For place order: should use address(producId) i.e: the 20 bytes hex representation of the productId for the order. For example, the verify contract of product 18 is 0x0000000000000000000000000000000000000012 .
  • For everything else: should use the endpoint address.

See more details in the contracts query page. {% endhint %}

def gen_order_verifying_contract(product_id: int) -> str:
    """
    Generates the order verifying contract address based on the product ID.

    Args:
        product_id (int): The product ID for which to generate the verifying contract address.

    Returns:
        str: The generated order verifying contract address in hexadecimal format.
    """
    be_bytes = product_id.to_bytes(20, byteorder="big", signed=False)
    return "0x" + be_bytes.hex()

EIP712 Types

See below the EIP712 type for each execute:

{% hint style="info" %} See more details in the Signing section of each execute's page. {% endhint %}

Place Order

Primary Type: Order

Solidity struct that needs to be signed:

struct Order {
    bytes32 sender;
    int128 priceX18;
    int128 amount;
    uint64 expiration;
    uint64 nonce;
    uint128 appendix;
}

JSON representation:

{
  Order: [
    { name: 'sender', type: 'bytes32' },
    { name: 'priceX18', type: 'int128' },
    { name: 'amount', type: 'int128' },
    { name: 'expiration', type: 'uint64' },
    { name: 'nonce', type: 'uint64' },
    { name: 'appendix', type: 'uint128' }
  ],
}

Cancel Orders

Primary Type: Cancellation

Solidity struct that needs to be signed:

struct Cancellation {
    bytes32 sender;
    uint32[] productIds;
    bytes32[] digests;
    uint64 nonce;
}

JSON representation:

{
  Cancellation: [
    { name: 'sender', type: 'bytes32' },
    { name: 'productIds', type: 'uint32[]' },
    { name: 'digests', type: 'bytes32[]' },
    { name: 'nonce', type: 'uint64' },
  ],
}

Cancel Product Orders

Primary Type: CancellationProducts

Solidity struct that needs to be signed:

struct CancellationProducts {
    bytes32 sender;
    uint32[] productIds;
    uint64 nonce;
}

JSON representation:

{
  CancellationProducts: [
    { name: 'sender', type: 'bytes32' },
    { name: 'productIds', type: 'uint32[]' },
    { name: 'nonce', type: 'uint64' },
  ],
}

Withdraw Collateral

Primary Type: WithdrawCollateral

Solidity struct that needs to be signed:

struct WithdrawCollateral {
    bytes32 sender;
    uint32 productId;
    uint128 amount;
    uint64 nonce;
}

JSON representation:

{
  WithdrawCollateral: [
    { name: 'sender', type: 'bytes32' },
    { name: 'productId', type: 'uint32' },
    { name: 'amount', type: 'uint128' },
    { name: 'nonce', type: 'uint64' },
  ],
}

Liquidate Subaccount

Primary Type: LiquidateSubaccount

Solidity struct that needs to be signed:

struct LiquidateSubaccount {
    bytes32 sender;
    bytes32 liquidatee;
    uint32 productId;
    bool isEncodedSpread;
    int128 amount;
    uint64 nonce;
}

JSON representation:

{
  LiquidateSubaccount: [
    { name: 'sender', type: 'bytes32' },
    { name: 'liquidatee', type: 'bytes32' },
    { name: 'productId', type: 'uint32' },
    { name: 'isEncodedSpread', type: 'bool' },
    { name: 'amount', type: 'int128' },
    { name: 'nonce', type: 'uint64' },
  ],
}

Mint NLP

Primary Type: MintNlp

Solidity struct that needs to be signed:

struct MintNlp {
    bytes32 sender;
    uint32 productId;
    uint128 quoteAmount;
    uint64 nonce;
}

JSON representation:

{
  MintLp: [
    { name: 'sender', type: 'bytes32' },
    { name: 'quoteAmount', type: 'uint128' },
    { name: 'nonce', type: 'uint64' },
  ],
}

Burn NLP

Primary Type: BurnNlp

Solidity struct that needs to be signed:

struct BurnLp {
    bytes32 sender;
    uint128 nlpAmount;
    uint64 nonce;
}

JSON representation:

{
  BurnLp: [
    { name: 'sender', type: 'bytes32' },
    { name: 'nlpAmount', type: 'uint128' },
    { name: 'nonce', type: 'uint64' },
  ],
}

Primary Type: LinkSigner

Solidity struct that needs to be signed:

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

JSON representation:

{
  LinkSigner: [
    { name: 'sender', type: 'bytes32' },
    { name: 'signer', type: 'bytes32' },
    { name: 'nonce', type: 'uint64' },
  ],
}

List Trigger Orders

Primary Type: ListTriggerOrders

Solidity struct that needs to be signed:

struct ListTriggerOrders {
    bytes32 sender;
    uint64 recvTime;
}

JSON representation:

{
  ListTriggerOrders: [
    { name: 'sender', type: 'bytes32' },
    { name: 'recvTime', type: 'uint64' },
  ],
}

Authenticate Subscription Streams

Primary Type: StreamAuthentication

Struct that needs to be signed:

struct StreamAuthentication {
    bytes32 sender;
    uint64 expiration;
}

JSON representation:

{
  StreamAuthentication: [
    { name: 'sender', type: 'bytes32' },
    { name: 'expiration', type: 'uint64' },
  ],
}