In which currency/unit are the fee and other amounts in Sonic Swap transactions?

In sonic swap: https://app.sonic.ooo/swap
for any swap this type of entry gets registered as transaction in sonic canister:

{
    "time":"1642878319429",
    "operation":"swap",
    "details":[
        ["pairId", {"Text":"aanaa-xaaaa-aaaah-aaeiq-cai:utozz-siaaa-aaaam-qaaxq-cai"}],
        ["from", {"Text":"utozz-siaaa-aaaam-qaaxq-cai"}],
        ["to", {"Text":"aanaa-xaaaa-aaaah-aaeiq-cai"}],
        ["amountIn", {"U64":"40000000"}],
        ["amountOut", {"U64":"5934203173278"}],
        ["reserve0", {"U64":"50190825314809436"}],
        ["reserve1", {"U64":"337340570120"}],
        ["fee", {"U64":"120000"}]
    ],
    "caller":{"__principal__":"5c26x-uoqgu-y3wa6-rftrl-ay476-dkauc-pdjnb-fxbwl-sspgx-35dfh-5ae"}
}

In this entry, the decimal precision and unit/currency of the amounts are not specified. For example, it’s unclear in which currency the fee is denoted, as well as for the amountIn and amountOut. I’m unsure if the DFINITY forum is the right platform for this question. Could someone from the Sonic team clarify or provide assistance? Thank you.

Sonic should be using decimals that the token uses which should be defined upon the creation of the token. Sonic references using the decimals that the token uses in the token metadata in several areas in their source code.

Tokens using the (newer) ICRC-1 / ICRC-2 standard should have an exposed function icrc1_decimals that you can query to get the number of decimals. You can use the following command to get the decimals of tokens using the (older) DIP20 standard using this command:

dfx canister --network=ic call --query token_canister_id decimals

For example, the command for XTC which has a canister id of utozz-siaaa-aaaam-qaaxq-cai:

dfx canister --network=ic call --query utozz-siaaa-aaaam-qaaxq-cai decimals

In this case, aanaa-xaaaa-aaaah-aaeiq-cai which is WICP and utozz-siaaa-aaaam-qaaxq-cai which is XTC are both DIP20. You can use the following commands:

For WICP:

dfx canister --network=ic call --query aanaa-xaaaa-aaaah-aaeiq-cai decimals

which should return 12 decimals

For XTC:

dfx canister --network=ic call --query utozz-siaaa-aaaam-qaaxq-cai decimals

which should return 8 decimals

Therefore, from this transaction, it looks like this user converted 0.4 XTC (40,000,000 / 100,000,000) for 5.9 WICP (5,934,203,173,278 / 1,000,000,000,000).

Hope this helps!

ok so according to that i can safely assume amountIn in is currency type of from token and amountOut is in currency type of to token? correct me if i’m wrong here.
what about fee ? which currency it is in?

It does seem like this according to the [source code definitions](sonic-js/src/math/swap.ts at 1e826a2c8069782d25e8455b4c3c43c9d6877817 · sonicdex/sonic-js · GitHub.

@memecake Can you please confirm the currency for the fee listed in the metadata?

Would like to follow-up here. Were you able to confirm the currency for the fee listed?

Apologies for the delayed response, I got caught up with other tasks.

I’m having trouble identifying the currency for the fee. Even after looking at the source code, it’s still unclear; it’s referenced as a percentage in the code, but the canister response provides exact numbers without specifying the currency or unit. Could you assist me in determining which currency the fee belongs to? I’ve been stuck on this for quite some time.

1 Like

The fees are assessed on token0 (the deposited token) and subsequently included in the LP.