Create a New Pair

A pre-stored pair is used in this procedure. Token contract should be instantiated in advance.

The Factory JSON parameter for instantiation is below:

{
"pair_code_id": 1,
"pair_code_hash": "<HASH>",
"token_code_id": 2,
"token_code_hash": "<HASH>",
"init_hook": { // optional
"msg": "base64_encoded_json_data",
"contract_addr": "secret...",
"callback_code_hash": "<HASH>"
}
}

The factory contract is responsible for creation of SecretSwap pairs as well as being the directory for all pairs. You may input numbers corresponding to pair_code_id and token_code_id. If an init_hook is given, the factory will call init_hook.contract_addr with init_hook.msg after being initialized.

After the factory is created, to create a new pair, you must first organize another JSON as below:

{
"create_pair": {
"asset_infos": [
{
"token": {
"contract_addr": "secret...",
"token_code_hash": "<HASH>",
"viewing_key": "" // ignored, can be whatever
}
},
{
"token": {
"contract_addr": "secret...",
"token_code_hash": "<HASH>",
"viewing_key": "" // ignored, can be whatever
}
}
],
"init_hook": { // optional
"msg": "base64_encoded_json_data",
"contract_addr": "secret...",
"callback_code_hash": "<HASH>"
}
}
}

This is a JSON constructor of pair contract.

  • A token pair can be either a contract-based token, or a Native token (SCRT).

    • asset_infos[x].token.contract_addr: SNIP20 token address is entered here.

    • asset_infos[x].native_token.denom: Native token denominator is entered here.

The use of SCRT (the network's native token) is discouraged, as swaps involving SCRT would not be front-running resistant.