This tutorial demonstrates the behaviour of the min swap fee functionality.
- Start and run the chain:
make init
make run
- Create a pool:
sifnoded tx clp create-pool \
--from sif \
--keyring-backend test \
--symbol ceth \
--nativeAmount 2000000000000000000 \
--externalAmount 2000000000000000000 \
--fees 100000000000000000rowan \
--broadcast-mode block \
--chain-id localnet \
-y
- Confirm pool has been created:
sifnoded q clp pools --output json | jq
returns:
{
"pools": [
{
"external_asset": {
"symbol": "ceth"
},
"native_asset_balance": "2000000000000000000",
"external_asset_balance": "2000000000000000000",
"pool_units": "2000000000000000000",
"swap_price_native": "1.000000000000000000",
"swap_price_external": "1.000000000000000000",
"reward_period_native_distributed": "0",
"external_liabilities": "0",
"external_custody": "0",
"native_liabilities": "0",
"native_custody": "0",
"health": "0.000000000000000000",
"interest_rate": "0.000000000000000000",
"last_height_interest_rate_computed": "0",
"unsettled_external_liabilities": "0",
"unsettled_native_liabilities": "0",
"block_interest_native": "0",
"block_interest_external": "0"
}
],
"clp_module_address": "sif1pjm228rsgwqf23arkx7lm9ypkyma7mzr3y2n85",
"height": "5",
"pagination": {
"next_key": null,
"total": "0"
}
}
- Query the current swap fee params:
sifnoded q clp swap-fee-params --output json | jq
{
"default_swap_fee_rate": "0.003000000000000000",
"token_params": []
}
- Set new swap fee params
sifnoded tx clp set-swap-fee-params \
--from sif \
--keyring-backend test \
--chain-id localnet \
--broadcast-mode block \
--fees 100000000000000000rowan \
-y \
--path <( echo '{
"default_swap_fee_rate": "0.003",
"token_params": [{
"asset": "ceth",
"swap_fee_rate": "0.004",
"min_swap_fee": "0"
},
{
"asset": "rowan",
"swap_fee_rate": "0.002",
"min_swap_fee": "600000000000"
}
]
}' )
- Check swap fee params have been updated:
sifnoded q clp swap-fee-params --output json | jq
{
"default_swap_fee_rate": "0.003000000000000000",
"token_params": [
{
"asset": "ceth",
"min_swap_fee": "0",
"swap_fee_rate": "0.004000000000000000"
},
{
"asset": "rowan",
"min_swap_fee": "600000000000",
"swap_fee_rate": "0.002000000000000000"
}
]
}
- Do a swap:
sifnoded tx clp swap \
--from sif \
--keyring-backend test \
--sentSymbol ceth \
--receivedSymbol rowan \
--sentAmount 200000000000000 \
--minReceivingAmount 0 \
--fees 100000000000000000rowan \
--chain-id localnet \
--broadcast-mode block \
--output json \
-y | jq '.logs[0].events[] | select(.type=="swap_successful").attributes[] | select(.key=="swap_amount" or .key=="liquidity_fee")'
Returns:
{
"key": "swap_amount",
"value": "199380001999800"
}
{
"key": "liquidity_fee",
"value": "600000000000"
}
The fee and swap amount are as expected:
adjusted_output = x * Y / ((x + X)(1 + r))
= 200000000000000 * 2000000000000000000 / ((200000000000000 + 2000000000000000000) * (1 + 0))
= 199980001999800
fee = min(max(f * adjusted_output, min_swap_fee), adjusted_output)
= min(max(0.002 * 199980001999800, 600000000000), adjusted_output)
= min(max(399960003999, 600000000000), 199980001999800)
= 600000000000
y = adjusted_amount - fee
= 199980001999800 - 600000000000
= 199380001999800
- Confirm that setting swap fee rate greater than one fails:
sifnoded tx clp set-swap-fee-params \
--from sif \
--keyring-backend test \
--chain-id localnet \
--broadcast-mode block \
--fees 100000000000000000rowan \
-y \
--path <( echo '{
"default_swap_fee_rate": "0.003",
"token_params": [{
"asset": "ceth",
"swap_fee_rate": "1.2",
"min_swap_fee": "0"
},
{
"asset": "rowan",
"swap_fee_rate": "0.002",
"min_swap_fee": "600000000000"
}
]
}' )