DeFiCh / ain

DeFi Blockchain - enabling decentralized finance on Bitcoin
https://defichain.com
MIT License
401 stars 119 forks source link

`testpoolswap` RPC should check for a direct swap first when `auto` is specified. #1114

Closed surangap closed 2 years ago

surangap commented 2 years ago

What happened:

  1. add a CAT-DFI pool.
  2. call testpoolswap from CAT -> DFI with path = auto, verbose = true
  3. response have as follows. note pools field. { path: 'auto', pools: [ '2', '2', '2' ], amount: '48.48437068@0' }

The above should be a direct swap since CAT-DFI pool is present. RCA even in compositeswap check for a direct swap is done first and then goes to the CalculateSwaps() and compositeswap() ref -> https://github.com/DeFiCh/ain/blob/c0a25f727f32c1b2c32a5120059276ec97e38bd2/src/masternodes/rpc_poolpair.cpp#L919

but in the scenario mentioned above, it will call CalculateSwaps() straight. ref -> https://github.com/DeFiCh/ain/blob/c0a25f727f32c1b2c32a5120059276ec97e38bd2/src/masternodes/rpc_poolpair.cpp#L1091

it could be that the CalculateSwaps() is unable to handle this scenario well. But simply adding a check for a direct swap first should solve the issue(same as the compositeswap flow. ). https://github.com/DeFiCh/ain/blob/c0a25f727f32c1b2c32a5120059276ec97e38bd2/src/masternodes/rpc_poolpair.cpp#L1091

What you expected to happen:

How to reproduce it (as minimally and precisely as possible):

What are your environment parameters:

Anything else we need to know?:

defichain-bot commented 2 years ago

@surangap: Thanks for opening an issue, it is currently awaiting triage.

The triage/accepted label can be added by foundation members by writing /triage accepted in a comment.

Details I am a bot created to help the [DeFiCh](https://github.com/DeFiCh) developers manage community feedback and contributions. You can check out my [manifest file](https://github.com/DeFiCh/ain/blob/master/.github/governance.yml) to understand my behavior and what I can do. If you want to use this for your project, you can check out the [DeFiCh/oss-governance-bot](https://github.com/DeFiCh/oss-governance-bot) repository.
surangap commented 2 years ago

relates to https://github.com/DeFiCh/jellyfish/pull/1074

eli-lim commented 2 years ago

It seems like CPoolSwap::CalculateSwaps / CalculatePoolPaths doesn't look for a direct path.

Just curious, which of the following are we looking to achieve for testpoolswap?