balancednetwork / balanced-java-contracts

Java contracts for Balanced
Apache License 2.0
10 stars 15 forks source link

Error trying to make a swap from bnusd to baln #448

Closed FidelVe closed 2 months ago

FidelVe commented 2 months ago

Description of the transaction that is failing

im sending a transaction to swap bnusd to baln tokens, this is the transaction https://tracker.lisbon.icon.community/transaction/0x19ef2df75a13ab00e01acfcba74678e24892f80da9433fb059111c693c8f0db8

this is the transaction payload:

{
    "method": "transfer",
    "params": {
        "_data": "f853855f73776170aa68783430366365363765346232643039653731346561663438323234663265306261343965313466626389389240021972184000d7019501c3c552054ba6823107b56086134c2afc26ab1dfa",
        "_to": "cx2576925d931f3be8ff195914c10a87da2094c5e5",
        "_value": "0xde0b6b3a7640000"
    }
}

Decoding the _data field with RLP shows the following:

[
  '_swap',
  'hx406ce67e4b2d09e714eaf48224f2e0ba49e14fbc',
  '389240021972184000',
  [ 1, 'cxc3c552054ba6823107b56086134c2afc26ab1dfa' ]
]

the amount of bnUSD token sent is 1 the price of the pool at the time of the transaction is 2.440887722886505 the expected amount of BALN token to receive is 0.4096870128944057 with a slippage of 5% the minimum amount that was inputted in the transaction is 0.3892026622496854

The transaction is failing indicating that the minimum amount is 1043.5560935640935

FRAME[4] INVOKE done status=Reverted(0) msg=E0032:Balanced Router: Below minimum receive amount of 1043556093564093480960 steps=8108693

This is incorrect because you can see that in the payload the amount that is defined as the minimum amount is 0.3892026622496854

Example of a successfull transaction for the same swap

The following is a successfull transaction done on mainnet with the balanced web app https://tracker.icon.community/transaction/0xc87bebcd53e06aca817ae01d3900b13796a24945dcd4386d8fb33fc5bf248eba

this is the transaction payload:

{
    "method": "transfer",
    "params": {
        "_data": "f852855f73776170aa687834303663653637653462326430396537313465616634383232346632653062613439653134666263880c0c78540bfeda96d7019501f61cd5a45dc9f91c15aa65831a30a90d59a09619",
        "_to": "cx21e94c08c03daee80c25d8ee3ea22a20786ec231",
        "_value": "0x351da03b95eb6b4"
    }
}

decoding the _data field with RLP shows the following:

[
  '_swap',
  'hx406ce67e4b2d09e714eaf48224f2e0ba49e14fbc',
  '0c0c78540bfeda96',
  [ 1, 'cxf61cd5a45dc9f91c15aa65831a30a90d59a09619' ]
]

Conclusion

The only difference is that im sending my transaction on Lisbon and the transaction that is a success and was done using the balanced webapp was done on mainnet

Given that all the data for executing the transaction on lisbon seems correct Im thinking that the reason for the transaction failing is that different versions of the router contract are currently live on lisbon an on mainnet but im not able to verify this.

if someone can spot the bug in this I appreciate it.

FidelVe commented 2 months ago

figure out the issue:

the transaction im trying to make has the "minimum to receive" amount as an int when it should be a hex

it was this:

[
  '_swap',
  'hx406ce67e4b2d09e714eaf48224f2e0ba49e14fbc',
  '389240021972184000',
  [ 1, 'cxc3c552054ba6823107b56086134c2afc26ab1dfa' ]
]

after changing it like this the tx is a success

[
  '_swap',
  'hx406ce67e4b2d09e714eaf48224f2e0ba49e14fbc',
  '566b9c25d0761c',
  [ 1, 'cxc3c552054ba6823107b56086134c2afc26ab1dfa' ]
]