Deposit

Token deposits can be made on any supported chains (list here)

To create a deposit request, users can follow the following steps:

1

Approve spending of the token by the Vault smart contract

Get Vault & USDC deposit address from here. All our smart contracts are verified, so you can get Vault & USDC ABI files via explorer, e.g. on Arbitrum Sepolia you can copy Vault ABI from here.

2

Determine necessary deposit fee in WEI

3

Call the `deposit` function of the smart contract

Contains the following structured data:

struct DepositData {
  bytes32 accountId;
  bytes32 brokerHash;
  bytes32 tokenHash;
  uint128 tokenAmount;
}

where:

NameTypeRequiredDescription
accountIdbytesYThe account id of the user in bytes.
brokerHashbytesYThe keccak256 hash of the broker id (eg “woofi_dex”)
tokenHashbytesYThe keccak256 hash of the token string (eg “USDC“)
tokenAmountintYAmount of tokens to be deposited

Deposits will take some time to reflect depending on the origin chain, to allow for finalizing of the cross-chain transaction involved in the deposit. Once the deposit is credited, the balance will update and the transaction can be seen on the Get asset history API.

Full example

  • install Web3j CLI
  • web3j generate solidity -a <./path/to/Vault.json> -o <./out-path/to/Vault.java> -p <package-name>
import java.math.BigInteger;

import org.apache.commons.codec.binary.Hex;
import org.bouncycastle.jcajce.provider.digest.Keccak;
import org.web3j.crypto.Credentials;
import org.web3j.crypto.ECKeyPair;
import org.web3j.protocol.Web3j;
import org.web3j.protocol.http.HttpService;
import org.web3j.tx.gas.DefaultGasProvider;
import io.github.cdimascio.dotenv.Dotenv;

public class DepositExample {
public static void main(String[] args) throws Exception {
String brokerId = "woofi_dex";
String tokenId = "USDC";
String orderlyAccountId = "0x...";

      String usdcAddress = "0xfd064a18f3bf249cf1f87fc203e90d8f650f2d63";
      String vaultAddress = "0x0c554ddb6a9010ed1fd7e50d92559a06655da482";

      Dotenv dotenv = Dotenv.load();
      String pk = dotenv.get("PRIVATE_KEY");
      Credentials credentials = Credentials.create(ECKeyPair.create(Hex.decodeHex(pk)));

      Web3j web3j = Web3j.build(new HttpService("https://arbitrum-goerli.publicnode.com"));
      DefaultGasProvider gasProvider = new DefaultGasProvider();

      NativeUSDC USDC = new NativeUSDC(usdcAddress, web3j, credentials, gasProvider);

      BigInteger depositAmount = new BigInteger("100000");

      // approve USDC ERC-20 to be transferred to Vault contract
      USDC.approve(vaultAddress, depositAmount).send();

      Vault vault = new Vault(vaultAddress, web3j, credentials, gasProvider);

      Keccak.Digest256 brokerHash = new Keccak.Digest256();
      byte[] brokerIdBytes = brokerId.getBytes("UTF-8");
      brokerHash.update(brokerIdBytes, 0, brokerIdBytes.length);

      Keccak.Digest256 tokenHash = new Keccak.Digest256();
      byte[] usdcBytes = tokenId.getBytes("UTF-8");
      tokenHash.update(usdcBytes, 0, usdcBytes.length);

      Vault.VaultDepositFE depositInput = new Vault.VaultDepositFE(
            Hex.decodeHex(orderlyAccountId.substring(2)),
            brokerHash.digest(),
            tokenHash.digest(),
            depositAmount);

      // get wei deposit fee for `deposit` call
      BigInteger depositFee = vault.getDepositFee(vaultAddress, depositInput).send();

      // deposit USDC into Vault contract
      vault.deposit(
            depositInput,
            depositFee).send();

}
}

Withdrawal

Follow the following steps to withdraw your tokens from Orderly Network:

1

Choose a valid chain to withdraw your funds to

A list of supported chains can be found on our Smart Contract Addresses page.

2

Check if the chain has sufficient liquidity

Since Orderly Network is an omnichain trading infrastructure, the liquidity of withdrawn assets might need to move across chains. If there is not enough liquidity of the withdrawn asset on the target chain, then an additional cross-chain transaction fee will be deducted from the user’s account.

3

Obtain a withdrawal nonce

Get a nonce from Get Withdrawal Nonce API.

4

Obtain a signature from EIP-712

Sign an EIP-712 message of message type Withdraw:

"Withdraw": [
    {"name": "brokerId", "type": "string"},
    {"name": "chainId", "type": "uint256"},
    {"name": "receiver", "type": "address"},
    {"name": "token", "type": "string"},
    {"name": "amount", "type": "uint256"},
    {"name": "withdrawNonce", "type": "uint64"},
    {"name": "timestamp", "type": "uint64"},
]

Example:

{
  "brokerId": "woofi_dex",
  "chainId": 80001,
  "receiver": "0x036Cb579025d3535a0ADcD929D05481a3189714b",
  "token": "USDC",
  "amount": 1000000,
  "withdrawNonce": 1,
  "timestamp": 1685973017064
}

where:

NameTypeRequiredDescription
brokerIdstringYBroker ID, the valid list can be found [here]
chainIdintYChain ID of the chain that the funds should be withdrawn to (within those that are supported by the Network)
receiverstringYAddress of the receiver, which should be equal to the address of the account.
tokenstringYThe string representation of the token that is being withdrawn (eg “USDC”)
amountintYAmount of tokens to be withdrawn
withdrawNonceintYValid withdrawal nonce from Get Withdrawal Nonce API
timestamptimestampYcurrent timestamp in UNIX milliseconds
5

Make a withdraw request

Example

The example code is very similar to the Orderly key registration, except it uses the EIP-712 on-chain domain and the signed message is different.