Let's use this transaction as an example:
https://bscscan.com/tx/0xf30f0de71911e52c68a6e4b5e3821eed3fe00e0c51b2650a028c82afdcc862b0#eventlog
As a benchmark, let's use BoggedFinance data. It says that:
bnb_usd=342
phx_usd=0.00000000570810
bnb_phx=60643119461
PHX - BNB LP PancakeSwap V2
7,924,800,360.499 PHX + 0.131 BNB
Liquidity Pool Totals
Pool adds $631,122 to total liquidity
PHX pooled: 55,236,876,104,150
BNB pooled: 910
Total LP Tokens: 6,970
KI pooled: 1,314,655,947,122
BNB pooled: 0.000
Total LP Tokens: 2,141.465
It is a swap between these two tokens:
Token0: PHX
Token0.decimals=9
Token0.address: 0xb98d864ddcb573567b3a2258c9e5cab58fe7974e
Token1: WBNB
Token1.decimals=18
Token1.address: 0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c
Other addresses mentioned in the logs:
Initiator: 0xC5f0Ac8AEd9D12C0645d16aB5892bb09Fc297590
Router (v2): 0x10ed43c718714eb63d5aa57b78b54704e256024e
PHX-WBNB LP: 0x2c3a0aa216cefb8c887716b993c3158f011f967e
BscScan says that the following amounts were transferred:
For 0.1 ($34.01) Wrapped BNB (WBNB)
For 5,314,263,769 PhoenixProtocol (PHX)
i.e. 0.1 WBNB was transferred in exchange for 5,314,263,769 PHX
actual=5,314,263,769 = 5,314,263,769
However, if we were to use Bogged provided quote, the expected amount should be:
0.1 x bnb_phx = 6,064,311,946.1
expected=6,064,311,946
((expected-actual)/((expected+actual)/2))*100 = 13.18351603551288580585
i.e. We would expect 13.18% more than what we got.
0.2% is a PancakeSwap fee.
The rest must be a combination of slippage and error between when the Bogged values were observed and when the trade took time (it is volatile market afterall).
A comment in the contract states that there is a 10% fee on every transaction, which may account for the difference.
The following events have been recorded:
Deposit
Address: 0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c
Destination: 0x10ed43c718714eb63d5aa57b78b54704e256024e
Wad: 100000000000000000
This is initiator transferring 0.1 (100000000000000000/10^18) WBNB to Router.
Transfer
Address: 0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c
Source: 0x10ed43c718714eb63d5aa57b78b54704e256024e
Destination: 0x2c3a0aa216cefb8c887716b993c3158f011f967e
Wad: 100000000000000000
This is Router adding 0.1 WBNB to PHX-WBNB LP.
Transfer
Address: 0xb98d864ddcb573567b3a2258c9e5cab58fe7974e
Source: 0x2c3a0aa216cefb8c887716b993c3158f011f967e
Destination: 0xc5f0ac8aed9d12c0645d16ab5892bb09fc297590
Wad: 5314263769851279617
This is PHX-WBNB LP sending 5,314,263,769 (5314263769851279617/10^9) to Buyer.
Sync:
Address: 0x2c3a0aa216cefb8c887716b993c3158f011f967e
Reserve0: 54569750545915728248786
Reserve1: 921958306311444356872
This event indicates that PHX-WBNB LP have been updated.
Swap
Address: 0x2c3a0aa216cefb8c887716b993c3158f011f967e
Sender: 0x10ed43c718714eb63d5aa57b78b54704e256024e
Addressee: 0xc5f0ac8aed9d12c0645d16ab5892bb09fc297590
amount0In: 12888802144710313
amount1In: 100000000000000000
amount0Out: 5904737522056977352
amount1Out: 0
This event describes how much was sold (amount0In
, amount1In
) and how much was received (amount0Out
, amount1Out
).
What's interesting is that 5904737522056977352 does not align with the actual amount transferred.
amount_out=5,904,737,522
actual=5,314,263,769
i.e. actual amount is 10.52% less than what amount_out
says
((actual-amount_out)/((actual+amount_out)/2))*100 = -10.52631580448580946687
There is also the amount_in_0
parameter.
amount_in_0=12,888,802
This equal to 0.2% of the amount_out, which appears to be PancakeSwap fee.
(amount_in_0/amount_out)*100 = 0.21827899973501988968
At the end, amount_out
does not account for 10%, which aligns with the advertised contract fee, and it seems that there is no way to get the actual amount transferred just by looking at the Swap
event.
It is worth noting that the quote that we calculated using two reserves does not reflect the 10% fee, i.e. The initial expected amount (6,064,311,946) closely aligns with the amount0Out
(5,904,737,522).
i.e. Looks like the only way to get the actual amount is by looking at the Transfer
events.