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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

This method returns amounts: Vector<U256>

Last updated