PAIR

Deploying PAIR contract manually

If you wish to deploy the PAIR contract manually, you will need to pass the other contracts hashes as parameters.

Below is the command template necessary to deploy the PAIR 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="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='Flash Swapper Contract Hash'" \

You will need to deploy other contracts before deploying a PAIR Contract, and pass their hashes to the respective parameters above.

These contracts have already been deployed and their hashes are listed in the table below:

NameNetworkAccount info contract hashContract owner

Factory

Testnet

hash-13cc83616c3fb4e6ea22ead5e61eb6319d728783ed02eab51b1f442085e605a7

Casper Association

Flash Swapper

Testnet

hash-1c23f9e89033e5c2d2a21a6926411b2645c000cf43fc0db495821633da2aed6e

Casper Association

Manual Deployment

For manual deployment of these contracts, refer to the following sections.

Entry point methods

PAIR's entry point methods are listed below:

transfer

Let self.get_caller send pool tokens to a recipient hash.

Parameters table:

Parameter NameType

recipient

Key

amount

U256

This method returns nothing.

transfer_from

Sends pool tokens from one hash to another.

Note: The user needs to call the approve method before callingtranfer_from .

Parameters table:

Parameter NameType

owner

Key

recipient

Key

amount

U256

This method returns nothing.

swap

Swaps tokens. For regular swaps, data.length must be 0.

Note: In order call this method explicitly, the user must first deploy a Factory contract, and then call the create_pair method, which in turn invokes the initialize methods of Pair contract. In this way, the Pair contract can access token0 and token1. Upon this, the user needs to mint token0 and token1 by calling an erc20_mint method in pair contract, or alternatively transfer some tokens to it, so that they have some balance in them. In order to call the swap method, the user must have some balance in reserve0 and reserve1.

Parameters table:

Parameter NameType

amount0_out

U256

amount1_out

U256

to

Key

data

String

This method returns nothing.

skim

Note: In order to call this method explicitly, the user must first deploy a Factory contractand then call the create_pair method, which in turn invokes the initialize methods of Pair contract. In this way, the Pair contract can access token0 and token1. Upon this, the user needs to mint token0 and token1 by calling an erc20_mint method in pair contract, or alternatively transfer some tokens to it, so that they have some balance in them. In order to call the skim method, the user needs to have some balance in reserve0 and reserve1.

Parameters table:

Parameter NameType

to

Key

This method returns nothing.

sync

Note: In order to call this method explicitly, the user must first deploy a Factory contractand then call the create_pair method, which in turn invokes the initialize methods of Pair contract. In this way, the Pair contract can access token0 and token1. Upon this, the user needs to mint token0 and token1 by calling an erc20_mint method in pair contract, or alternatively transfer some tokens to it, so that they have some balance in them.

Parameters table:

This method returns nothing.

permit

Sets the allowance for a spender in a scenario where approval is granted via a signature.

Parameters table:

Parameter NameType

public

String

signature

String

owner

Key

spender

Key

value

U256

deadline

u64

This method returns nothing.

approvetransfer_from on such a standard should forward these recommendations to app developers who implement their token contract.

balance_of

Returns the amount of pool tokens owned by a hash.

Parameters table:

Parameter NameType

owner

Key

This method returns an U256.

nonce

Returns the current nonce for an address for use in permit.

Parameters table:

Parameter NameType

owner

Key

This method returns an U256.

allowance

Returns the amount of liquidity tokens owned by a hash that a spender is allowed to transfer via transfer_from.

Parameters table:

Parameter NameType

owner

Key

spender

Key

This method returns an U256.

Recommendation:

Possible exploits should be taken into account.

Using functions that increase/decrease the allowance relative to its current value is highly encouraged. We recommend developers of applications dependant on approve() / transferFrom() to set allowance to 0 first and verify if it was used before setting a new value.

Note: Teams who decide to rely on such a standard should forward these recommendations to app developers who implement their token contract.

total_supply

Returns the total amount of pool tokens for a pair.

Parameters Table:

This method returns an U256.

mint

Creates pool tokens.

Note: In order to call this method explicitly, the user has to deploy a Factory contract first and then call the method create_pair, which in turn invokes the initialize methods of Pair contract. This way the Pair contract can access token0 and token1. To flawleslly call the mint, the user needs to perform all the above steps.

Parameters table:

Parameter NameType

to

Key

This method returns an U256.

burn

Destroys pool tokens.

Note: The user needs to mint tokens before burning them. Additionally, he has to first deploy a Factory contract and then call the method create_pair, which in turn invokes the initialize method of Pair contract. This way the Pair contract can access token0 and token1. To flawlessly call the burn, the user needs to perform all the above steps.

Parameters table:

Parameter NameType

to

Key

This method returns a Tuple(U256, U256).

treasury_fee

Returns the Treasury Fee for a pair.

Parameters table:

This method returns an U256.

set_treasury_fee_percent

Sets the treasury fee for a pair.

Note: treasury_fee_percent can't be larger than 30 or fewer than 3. On the case where it’s larger than30 it will automatically set as 30 and conversely if it's less than 3 it will be automatically set as '3'.

Parameters table:

Parameter NameType

treasury_fee

U256

This method returns nothing.

token0

Returns the hash of the pair token with the lowest sort order.

Parameters table:

This method returns a Key.

token1

Returns the address of the pair token with the highest sort order.

Parameters table:

This method returns a Key.

initialize

Setstoken0 and token1 in a pair contract.

Note: This method will be solely called by Factory contract and it's up to the user to pass the factory's hash in order to confirm wether it's a factory or not.

Parameters table:

Parameter NameType

token0

Key

token1

Key

factory_hash

Key

This method returns nothing.

get_reserves

Returns token0 and token1 reserves used to price trades and distribute liquidity. Also, it returns the block_time_stamp (mod 2**32) of the last block during which an interaction occured for the pair.

Parameters table:

This method returns a Tupe3(U128, U128, U64).

erc20_mint

Mints a number of tokens against a hash, both provided by the user.

Parameters table:

Parameter NameType

to

Key

amount

U256

This method returns nothing.

Last updated