- The Anafi fee, a fee transfer inside the payment, to the
treasuryaddress. - The gas charge, the network gas of the payment, which the adapter takes back from the account.
An
erc20_allow account always pays the gas of its own owner transactions, in all 3 cases. See Accounts.
Fees are on today on polygon, xlayer and polygon-amoy.
The fee terms: GET /api/fees
GET /api/fees on the API host of a network returns the live fee terms of that network. In the SDK, call fetchFeeTerms(). The route needs no authentication.
The
gas object:
The SDK returns the
gas values as bigint, and the floors amounts as decimal strings. A field of the wrong shape makes fetchFeeTerms() throw.
The values of today, from the code of each network:
So the fee is 0.2% of each moved amount, and at least USD 0.20. ana.fi/pricing states the same rate and minimum for the dApp. Read
GET /api/fees at run time and do not hard-code these values. The API answer is the price that applies.
The Anafi fee
The fee of one payment
The engine computes the fee in US dollars for each moved amount:- each recipient of a
send_oneor asend_batch, - the sold amount of an
exchange.
amount_usd × bps / 10000, and the floor of floorUsdCents. The engine converts each fee into the fee token, rounds it up to a whole base unit, and adds the results. The payment then carries one fee transfer of that sum to treasury.
A dollar stablecoin of the fee-token list counts as exactly USD 1 for each whole token. Other tokens use the price of the engine at the fire.
The floor refuses small amounts
The engine refuses a moved amount that is at or below the floor of its token,floors[].amountRaw. In a send_batch, one such recipient refuses the whole batch, and no recipient is paid. Nothing is sent.
Check each amount in your form against the floor of its token. For a dollar stablecoin with 6 decimals and a floor of USD 0.20, the floor is 200000, so the smallest amount that the engine accepts is 0.200001.
The fee token: global.fees_method
The document chooses its fee token with global.fees_method:
fixed_token is the only type. The rules:
- The token must be in
feeTokensof the network. - If the document sets
global.token_allowlist, the list must hold the fee token. - A Safe document without
fees_methodpays its fees in the native coin of the network. - An
erc20_allowdocument must setfees_method, to an ERC-20. The native coin is not a valid fee token for this kind. - An
erc20_allowaccount must approve the fee token to the adapter, as for any token that it spends.
readFeesMethod(yaml) and documentWithFeesMethod(yaml, method) read and set the field.
How the fee appears
The gas charge
Anafi submits each payment and pays its network gas. If fees are on and the account has no sponsor, the adapter takes the gas back from the account in the same transaction:- Before the transfers, the adapter collects a maximum charge,
maxCharge, from the account, in the fee token. - After the transfers, it computes the real charge: the gas that the transaction used, plus fixed parts, times the gas price of the transaction. A token charge converts the cost with
tokenUnitsPerNativeCoinand rounds up. - It pays the real charge, never more than
maxCharge, totreasury, and pays the rest back to the account. - It emits
GasCharged(nonce, digest, token, charge).
erc20_allow account, maxCharge also counts against the cap of the fee token.
If the transfers of a payment fail after the checks pass, the payment still pays its gas charge. If a check fails before the transfers, the whole transaction reverts and the account pays nothing.
The bound before a rule fires
GET /api/fees gives a bound that is at or above the most a payment can charge:
- A transfer payment with
ntransfers, the fee transfer included:transferCostBoundBaseWei + n × transferCostBoundPerLegWeiwei. - An
exchangepayment:swapCostBoundWeiwei. - In an ERC-20 fee token:
ceil(wei × tokenUnitsPerNativeCoin / 10^18)base units.
transferCostBoundWei(gas, legs) and tokenAmountOfWei(costWei, tokenUnitsPerNativeCoin) do this arithmetic. Show the bound as “at most” in your form. The real charge is usually lower.
Where the charge appears
The activity row has agasCharge field: tokenAddress, the zero address for the native coin, and amountRaw, the charge in base units. It is null for a payment with no recorded charge.
Gas credit
If the adapter cannot pay a charge or a refund, for example because a token transfer fails, the amount becomes a gas credit of its payee in the adapter. Read it withgasCredit(payee, token) or readGasCredit in the SDK. The payee claims it with claimGasCredit(token, to). See Redeem for the rules of the gas credit.
Sponsorship
A sponsor is a partner that pays for an account. For a sponsored account:- The engine adds no fee transfer.
- The adapter takes no gas charge.
maxChargeis 0, andGasChargedreports a charge of 0. - The Anafi API relays the Safe owner transactions and pays their gas.
GET /api/wallets/:aa/sponsorship returns { "feesOn": boolean, "sponsored": boolean }. In the SDK, call fetchWalletSponsorship(aa). sponsored is true for an account with a sponsor, also when fees are off.
Anafi sets the sponsor of an account. To pay for your users, write to hi@ana.fi.
Worked examples
All examples usepolygon, bps 20, floorUsdCents 20, and USDC as the fee token. USDC has 6 decimals and counts as USD 1.
1. A payment of 500 USDC
- Moved amount: 500 USDC, which is USD 500.
- Rate part:
500 × 20 / 10000= USD 1.00. - Floor: USD 0.20.
- Fee: the larger value, USD 1.00, which is
1000000base units of USDC.
treasury.
2. A payment of 50 USDC
- Rate part:
50 × 20 / 10000= USD 0.10. - Fee: the floor, USD 0.20, which is
200000base units.
3. A batch of 50, 100 and 1000 USDC
The payment carries one fee transfer of USD 2.40, which is
2400000 base units.
4. A payment of 0.20 USDC
The amount is200000 base units. It is at the floor of USDC, 200000, so the engine refuses it. Nothing is sent.
5. The gas bound of example 1
This example uses one answer ofGET /api/fees on polygon. The values change with the price of gas and of POL.
- Bound in wei:
350378308000000000 + 2 × 24098396000000000=398575100000000000, which is 0.3985751POL. - Bound in USDC:
ceil(398575100000000000 × 71010 / 10^18)=28303base units, which is 0.028303 USDC.