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.

sudo casper-client put-deploy \
    --chain-name chain_name \
    --node-address http://$NODE_ADDRESS:7777/ \
    --secret-key path_to_secret_key.pem \
    --session-path path_to_wasm_file \
    --payment-amount 10000000000 \
    --session-arg="public_key:public_key='Public Key In Hex'" \
    --session-arg="factory:Key='Hash of factory Contract'" \
    --session-arg="wcspr:Key='Hash of WCSPR Contract'" \
    --session-arg="library:Key='Hash of Library Contract'" \
    --session-arg="pair:Key='Hash of Pair Contract'" \
    --session-arg="contract_name:string='contract_name'"

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.

Name
Network
Account info contract hash
Contract owner

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

sudo casper-client put-deploy \
    --chain-name chain_name \
    --node-address http://$NODE_ADDRESS:7777/ \
    --secret-key path_to_secret_key.pem \
    --session-path path_to_wasm_file \
    --payment-amount 10000000000 \
    --session-arg="public_key:public_key='Public Key In Hex'" \
    --session-arg="fee_to_setter:Key='Hash of fee-to-setter Contract'" \
    --session-arg="contract_name:string='contract_name'"

Wcspr

sudo casper-client put-deploy \
    --chain-name chain_name \
    --node-address http://$NODE_ADDRESS:7777/ \
    --secret-key path_to_secret_key.pem \
    --session-path path_to_wasm_file \
    --payment-amount 10000000000 \
    --session-arg="public_key:public_key='Public Key In Hex'" \
    --session-arg="name:string='token-name'" \
    --session-arg="symbol:string='token-symbol'" \
    --session-arg="decimals:u8='unsigned integer value'" \
    --session-arg="initial_supply:u256='unsigned integer value'" \
    --session-arg="contract_name:string='contract_name'"

Library

sudo casper-client put-deploy \
    --chain-name chain_name \
    --node-address http://$NODE_ADDRESS:7777/ \
    --secret-key path_to_secret_key.pem \
    --session-path path_to_wasm_file \
    --payment-amount 10000000000 \
    --session-arg="public_key:public_key='Public Key In Hex'" \
    --session-arg="contract_name:string='contract_name'"

Pair

sudo casper-client put-deploy \
    --chain-name chain_name \
    --node-address http://$NODE_ADDRESS:7777/ \
    --secret-key path_to_secret_key.pem \
    --session-path path_to_wasm_file \
    --payment-amount 10000000000 \
    --session-arg="public_key:public_key='Public Key In Hex'" \
    --session-arg="name:string='token-name'" \
    --session-arg="symbol:string='token-symbol'" \
    --session-arg="decimals:u8='unsigned integer value'" \
    --session-arg="initial_supply:u256='unsigned integer value'" \
    --session-arg="contract_name:string='contract_name'"
    --session-arg="factory_hash:Key='Hash of factory Contract'" \
    --session-arg="callee_contract_hash:Key='Callee Contract Hash'" \

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.

Parameter Name
Type

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.

Parameter Name
Type

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.

Parameter Name
Type

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.

Parameter Name
Type

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.

Parameter Name
Type

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.

Parameter Name
Type

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.

Parameter Name
Type

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.

Parameter Name
Type

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.

Parameter Name
Type

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.

Parameter Name
Type

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.

Parameter Name
Type

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.

Parameter Name
Type

amount_out

U256

amount_in_max

U256

path

Vec

to

Key

deadline

U256

This method returns amounts: Vector<U256>

Last updated