Usage
Deploying Router contract manually
If you need to deploy the router contract manually you will need to pass the hashes of the other contracts as parameters. Following is the command to deploy the Router contract.
Before deploying a Router Contract, you need to deploy other contracts first and pass hashes of these contracts to the respective parameters above. We have already deployed these contracts and the tables belows displays the hashes of the contracts.
Factory
Testnet
hash-5028190b8a5b6addbf3d51ee2c6ae5b913f09223d65eff9bcf5985f74ae976ec
Casper Association
Wcspr
Testnet
hash-083756dee38a7e3a8a7190a17623cfbc8bc107511de206f03c3dbd1af5463a45
Casper Association
Library
Testnet
hash-fa073d1a95a606871983689633dab9464fb5fbe5f723b0855e025ea01b9bf308
Casper Association
Pair
Testnet
hash-8e6fbaae9f5ff3bb3cca7cb15723b2a47917d074922575187cb136e8d4b169a7
Casper Association
Manual Deployment
For manual deployments of these contracts, here are the command templates.
Factory
Wcspr
Library
Pair
Entry point methods
Here are the Router's entry point methods.
add_liquidity
This method adds liquidity to ERC-20⇄ERC-20 pool. To cover all possible scenarios, msg.sender should have already given the router an allowance of at least amount_a_desired/amount_b_desired on token_a/token_b. Always adds assets at the ideal ratio, according to the price when the transaction is executed.
Here is the table of parameters.
token_a
Key
token_b
Key
amount_a_desired
U256
amount_b_desired
U256
amount_a_min
U256
amount_b_min
U256
to
KEY
deadline
U256
This method returns amount_a:U256, amount_b:U256, liquidity:U256
add_liquidity_cspr
This method adds liquidity to ERC-20⇄CSPR pool with CSPR. To cover all possible scenarios, msg.sender should have already given the router an allowance of at least amount_token_desired on token. Always adds assets at the ideal ratio, according to the price when the transaction is executed. Leftovers of cspr tokens (if any), is returned to msg.sender
Here is the table of parameters.
token
Key
amount_token_desired
U256
amount_cspr_desired
U256
amount_token_min
U256
amount_cspr_min
U256
to
KEY
deadline
U256
This method returns amount_token:U256, amount_cspr:U256, liquidity:U256
remove_liquidity
This method Removes liquidity from an ERC-20⇄ERC-20 pool. msg.sender should have already given the router an allowance of at least liquidity on the pool.
Here is the table of parameters.
token_a
Key
token_b
Key
liquidity
U256
amount_a_min
U256
amount_b_min
U256
to
Key
deadline
U256
This method returns amount_a:U256, amount_b:U256
remove_liquidity_cspr
This method Removes liquidity from an ERC-20⇄ERC-20 pool. msg.sender should have already given the router an allowance of at least liquidity on the pool.
Here is the table of parameters.
token
Key
liquidity
U256
amount_token_min
U256
amount_cspr_min
U256
to
Key
deadline
U256
This method returns amount_token:U256, amount_cspr:U256
remove_liquidity_with_permit
This method Removes liquidity from an ERC-20⇄ERC-20 pool without pre-approval.
Here is the table of parameters.
token_a
Key
token_b
Key
liquidity
U256
amount_a_min
U256
amount_b_min
U256
to
Key
deadline
U256
approve_max
Bool
public_key
String
signature
String
This method returns amount_a:U256, amount_b:U256
Note: To know the steps of calculating the signature, refer to the documentation of Pair contract, in the pair repository.
remove_liquidity_cspr_with_permit
This method Removes liquidity from an ERC-20⇄ERC-20 pool without pre-approval.
Here is the table of parameters.
token
Key
liquidity
U256
amount_token_min
U256
amount_cspr_min
U256
to
Key
deadline
U256
approve_max
Bool
public_key
String
signature
String
This method returns amount_token:U256, amount_cspr:U256
Note: To know the steps of calculating the signature, refer to the documentation of Pair contract, in the pair repository.
swap_exact_tokens_for_tokens
Swaps an exact amount of input tokens for as many output tokens as possible, along the route determined by the path. The first element of the path is the input token, the last is the output token, and any intermediate elements represent intermediate pairs to trade through (if, for example, a direct pair does not exist). msg.sender should have already given the router an allowance of at least amount_in on the input token.
Here is the table of parameters.
amount_in
U256
amount_out_min
U256
path
Vec
to
Key
deadline
U256
This method returns amounts: Vector<U256>
swap_tokens_for_exact_tokens
Receive an exact amount of output tokens for as few input tokens as possible, along the route determined by the path. The first element of the path is the input token, the last is the output token, and any intermediate elements represent intermediate tokens to trade through (if, for example, a direct pair does not exist). msg.sender should have already given the router an allowance of at least amount_in_max on the input token.
Here is the table of parameters.
amount_out
U256
amount_in_max
U256
path
Vec
to
Key
deadline
U256
This method returns amounts: Vector<U256>
swap_exact_cspr_for_tokens
Swaps an exact amount of cspr for as many output tokens as possible, along the route determined by the path. The first element of the path must be WCSPR, the last is the output token, and any intermediate elements represent intermediate pairs to trade through (if, for example, a direct pair does not exist).
Here is the table of parameters.
amount_out_min
U256
amount_in
U256
path
Vec
to
Key
deadline
U256
This method returns amounts: Vector<U256>
swap_tokens_for_exact_cspr
Receive an exact amount of CSPR for as few input tokens as possible, along the route determined by the path. The first element of the path is the input token, the last must be WCSPR, and any intermediate elements represent intermediate pairs to trade through (if, for example, a direct pair does not exist). msg.sender should have already given the router an allowance of at least amount_in_max on the input token. If the address is a smart contract, it must have the ability to receive cspr.
Here is the table of parameters.
amount_out
U256
amount_in_max
U256
path
Vec
to
Key
deadline
U256
This method returns amounts: Vector<U256>
swap_exact_tokens_for_cspr
Swaps an exact amount of tokens for as much cspr as possible, along the route determined by the path. The first element of the path is the input token, the last must be WCSPR, and any intermediate elements represent intermediate pairs to trade through (if, for example, a direct pair does not exist). If the address is a smart contract, it must have the ability to receive cspr.
Here is the table of parameters.
amount_in
U256
amount_in_min
U256
path
Vec
to
Key
deadline
U256
This method returns amounts: Vector<U256>
swap_cspr_for_exact_tokens
Receive an exact amount of tokens for as little CSPR as possible, along the route determined by the path. The first element of the path must be WCSPR, the last is the output token and any intermediate elements represent intermediate pairs to trade through (if, for example, a direct pair does not exist). Leftover of CSPR tokens, if any, is returned to msg.sender.
Here is the table of parameters.
amount_out
U256
amount_in_max
U256
path
Vec
to
Key
deadline
U256
This method returns amounts: Vector<U256>
Last updated