tendermint/liquidity

Transaction bug when exchanging an asset

Opened this issue · 2 comments

described the bug in the wrong place, so just click on the links.

Summary of Bug

cosmos/cosmos#126

Steps to Reproduce

  1. Log in to app.emeris.com
  2. Exchange ATOM for CRO

Hi, When analyzing block_result's swap_transacted event for transaction C99F5ABDA65BBC1AC7BD510E37D36DA75D9FEEA2888911F9C73E6DDCC02C4BF0,

the swap tx was failed in batch stage because the requested order_price(21717.390869999999267748) was higher than swap_price(21635.548999405792868217) and offer_coin_amount(1000000) + reserved_offer_coin_fee_amount(1500) refunded as well on the end block.

currently, you can set advanced functionality to set a custom slippage (i.e. a limit price, order_price) in the Emeris app or manual tx. If the swap sets the price better than the expected swap_price, it can be transacted.

[
  {
    "type": "swap_transacted",
    "attributes": [
      {
        "key": "pool_id",
        "value": "9",
        "index": true
      },
      {
        "key": "batch_index",
        "value": "1849",
        "index": true
      },
      {
        "key": "msg_index",
        "value": "1632",
        "index": true
      },
      {
        "key": "swap_requester",
        "value": "cosmos19wtkh935tx2ut2n4m6tjvkfvew4shaeep6td8u",
        "index": true
      },
      {
        "key": "swap_type_id",
        "value": "1",
        "index": true
      },
      {
        "key": "offer_coin_denom",
        "value": "uatom",
        "index": true
      },
      {
        "key": "offer_coin_amount",
        "value": "1000000",
        "index": true
      },
      {
        "key": "demand_coin_denom",
        "value": "ibc/C932ADFE2B4216397A4F17458B6E4468499B86C3BC8116180F85D799D6F5CC1B",
        "index": true
      },
      {
        "key": "order_price",
        "value": "21717.390869999999267748",
        "index": true
      },
      {
        "key": "swap_price",
        "value": "21635.548999405792868217",
        "index": true
      },
      {
        "key": "remaining_offer_coin_amount",
        "value": "1000000",
        "index": true
      },
      {
        "key": "exchanged_offer_coin_amount",
        "value": "0",
        "index": true
      },
      {
        "key": "reserved_offer_coin_fee_amount",
        "value": "1500",
        "index": true
      },
      {
        "key": "order_expiry_height",
        "value": "7654402",
        "index": true
      },
      {
        "key": "success",
        "value": "failure",
        "index": true
      }
    ]
  },
  {
    "type": "message",
    "attributes": [
      {
        "key": "sender",
        "value": "cosmos1tx68a8k9yz54z06qfve9l2zxvgsz4ka3hr8962",
        "index": true
      }
    ]
  },
  {
    "type": "transfer",
    "attributes": [
      {
        "key": "recipient",
        "value": "cosmos19wtkh935tx2ut2n4m6tjvkfvew4shaeep6td8u",
        "index": true
      },
      {
        "key": "amount",
        "value": "1001500uatom",
        "index": true
      }
    ]
  }
]

Hi, When analyzing block_result's swap_transacted event for transaction C99F5ABDA65BBC1AC7BD510E37D36DA75D9FEEA2888911F9C73E6DDCC02C4BF0,

the swap tx was failed in batch stage because the requested order_price(21717.390869999999267748) was higher than swap_price(21635.548999405792868217) and offer_coin_amount(1000000) + reserved_offer_coin_fee_amount(1500) refunded as well on the end block.

currently, you can set advanced functionality to set a custom slippage (i.e. a limit price, order_price) in the Emeris app or manual tx. If the swap sets the price better than the expected swap_price, it can be transacted.

[
  {
    "type": "swap_transacted",
    "attributes": [
      {
        "key": "pool_id",
        "value": "9",
        "index": true
      },
      {
        "key": "batch_index",
        "value": "1849",
        "index": true
      },
      {
        "key": "msg_index",
        "value": "1632",
        "index": true
      },
      {
        "key": "swap_requester",
        "value": "cosmos19wtkh935tx2ut2n4m6tjvkfvew4shaeep6td8u",
        "index": true
      },
      {
        "key": "swap_type_id",
        "value": "1",
        "index": true
      },
      {
        "key": "offer_coin_denom",
        "value": "uatom",
        "index": true
      },
      {
        "key": "offer_coin_amount",
        "value": "1000000",
        "index": true
      },
      {
        "key": "demand_coin_denom",
        "value": "ibc/C932ADFE2B4216397A4F17458B6E4468499B86C3BC8116180F85D799D6F5CC1B",
        "index": true
      },
      {
        "key": "order_price",
        "value": "21717.390869999999267748",
        "index": true
      },
      {
        "key": "swap_price",
        "value": "21635.548999405792868217",
        "index": true
      },
      {
        "key": "remaining_offer_coin_amount",
        "value": "1000000",
        "index": true
      },
      {
        "key": "exchanged_offer_coin_amount",
        "value": "0",
        "index": true
      },
      {
        "key": "reserved_offer_coin_fee_amount",
        "value": "1500",
        "index": true
      },
      {
        "key": "order_expiry_height",
        "value": "7654402",
        "index": true
      },
      {
        "key": "success",
        "value": "failure",
        "index": true
      }
    ]
  },
  {
    "type": "message",
    "attributes": [
      {
        "key": "sender",
        "value": "cosmos1tx68a8k9yz54z06qfve9l2zxvgsz4ka3hr8962",
        "index": true
      }
    ]
  },
  {
    "type": "transfer",
    "attributes": [
      {
        "key": "recipient",
        "value": "cosmos19wtkh935tx2ut2n4m6tjvkfvew4shaeep6td8u",
        "index": true
      },
      {
        "key": "amount",
        "value": "1001500uatom",
        "index": true
      }
    ]
  }
]

There is no such function in emeris :)