ICRC ledger fee

Callers of icrc1_transfer can optionally define the field fee.
However, if this field is not exactly the defined fee in the ledger, it will return an error like below

(
  variant {
    Err = variant { BadFee = record { expected_fee = 10_000_000 : nat } }
  },
)

What is the point of even being able to optionally set this field if it has to be exactly the amount that is defined in the ledger config?

We have a use-case where it could be interesting to set this to a higher value than the defined value in the ledger config in some specific cases. Are you planning to enable something like this in the future?

1 Like

The Pan Industrial ICRC-1 library supports variable fees.

Set the fee behavior when you set up your token: icrc1.mo/src/ICRC1/migrations/v000_001_000/types.mo at a5ea2faf15faebe760e2fb9727e0b52f91d0088d · PanIndustrial-Org/icrc1.mo · GitHub

Define the function in your environment variable: icrc1.mo/src/ICRC1/migrations/v000_001_000/types.mo at a5ea2faf15faebe760e2fb9727e0b52f91d0088d · PanIndustrial-Org/icrc1.mo · GitHub

With this function, you can have it determine the fee for each transaction based on the transaction variables, your state or any other code that you want to write. ie: Fee per user, Lower fee if you’ve staked, Percentage based fee, etc

The get_fee function is called for each transaction

The fee in the ICRC-1 implementation from Dfinity is using a fixed fee. Originally, it was planned to have a variable fee, but a fixed fee was chosen as the better way forward. To preserve backwards compatibility the fee was kept optional and it can be set to only value. However, the icrc-1 ledger will reject any fee that is not either the default fee or set to None.

Hi @Dustin,

It is because the fee can change through canister upgrades, and when a canister (like a dex) that needs to keep track of every token-quantum, calls a ledger, the canister needs to be able to know exactly how much will be taken-out from the canister’s-account if the transfer is successful. The canister can choose to send along what it thinks is the fee, and if the set fee is wrong then the ledger will not perform the transfer, and like you mentioned, the ledger will return a expected_fee amount, so then the canister can choose, if the canister is ok making the transfer with the expected_fee amount then it will send a new transfer request with the new fee amount. The point is to let the caller-canisters, before making a transfer, be able to keep track of how many tokens will be taken out of the canister’s account if the transfer is successful.

@NikolasHai The fee can still change through canister upgrades. The ICP ledger can be upgraded with a new fee amount. When the price of ICP hits $10000, I’m sure the transfer fee will be lowered. In the SNS framework, using the ManageLedgerParameters proposal type an SNS can vote to change it’s ledger’s fee and in the background the SNS-ledger gets upgraded with the new fee amount. If the price of a token goes up or down, it is needed to calibrate the transfer fee.

1 Like