Deposit
Token deposits can be made on any supported chains (list here )
To create a deposit request, users can follow the following steps:
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 .
String usdcAddress = "0x75faf114eafb1BDbe2F0316DF893fd58CE46AA4d" ;
String vaultAddress = "0x0EaC556c0C2321BA25b9DC01e4e3c95aD5CDCd2f" ;
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-sepolia.publicnode.com" ) ) ;
DefaultGasProvider gasProvider = new DefaultGasProvider ( ) ;
NativeUSDC USDC = new NativeUSDC ( usdcAddress, web3j, credentials, gasProvider) ;
BigInteger depositAmount = new BigInteger ( "10000000" ) ;
USDC . approve ( vaultAddress, depositAmount) . send ( ) ;
Determine necessary deposit fee in WEI
String brokerId = "woofi_pro" ;
String tokenId = "USDC" ;
String orderlyAccountId = "0x..." ;
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) ;
BigInteger depositFee = vault. getDepositFee ( credentials. getAddress ( ) , depositInput) . send ( ) ;
Call the `deposit` function of the smart contract
Contains the following structured data:
where:
Name Type Required Description accountId bytes Y The account id of the user in bytes. brokerHash bytes Y The keccak256 hash of the builder id (eg “woofi_dex”) tokenHash bytes Y The keccak256 hash of the token string (eg “USDC“) tokenAmount int Y Amount of tokens to be deposited
vault. deposit (
depositInput,
depositFee) . send ( ) ;
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
Code generation via ABI file
install Web3j CLI
web3j generate solidity -a <./path/to/Vault.json> -o <./out-path/to/Vault.java> -p <package-name>
install Web3j CLI
web3j generate solidity -a <./path/to/Vault.json> -o <./out-path/to/Vault.java> -p <package-name>
install Typechain
typechain --target=ethers-v6 <./path/to/Vault.json> --out-dir <out/path>
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_pro" ;
String tokenId = "USDC" ;
String orderlyAccountId = "0x..." ;
String usdcAddress = "0x75faf114eafb1BDbe2F0316DF893fd58CE46AA4d" ;
String vaultAddress = "0x0EaC556c0C2321BA25b9DC01e4e3c95aD5CDCd2f" ;
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-sepolia.publicnode.com" ) ) ;
DefaultGasProvider gasProvider = new DefaultGasProvider ( ) ;
NativeUSDC USDC = new NativeUSDC ( usdcAddress, web3j, credentials, gasProvider) ;
BigInteger depositAmount = new BigInteger ( "10000000" ) ;
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) ;
BigInteger depositFee = vault. getDepositFee ( credentials. getAddress ( ) , depositInput) . send ( ) ;
vault. deposit (
depositInput,
depositFee) . send ( ) ;
}
}
Withdrawal
Follow the following steps to withdraw your tokens from Orderly:
Choose a valid chain to withdraw your funds to
Check if the chain has sufficient liquidity
Since Orderly 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.
Obtain a withdrawal nonce
Obtain a signature from EIP-712
Sign an EIP-712 message of message type Withdraw
:
Example:
where:
Name Type Required Description brokerId string Y Builder ID, the valid list can be found [here] chainId int Y Chain ID of the chain that the funds should be withdrawn to (within those that are supported by the Network) receiver string Y Address of the receiver, which should be equal to the address of the account. token string Y The string representation of the token that is being withdrawn (eg “USDC”) amount int Y Amount of tokens to be withdrawn withdrawNonce int Y Valid withdrawal nonce from Get Withdrawal Nonce API timestamp timestamp Y current timestamp in UNIX milliseconds
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.