Open benjizhai opened 1 year ago
I realized I put this in the wrong place.
ICRC-4
: Batch TransfersStatus |
---|
Draft |
ICRC-4
is an extension of the base ICRC-1
standard.
ICRC-4
specifies a way for an account owner to transfer tokens to multiple addresses in one ledger call in order to drastically reduce the latency of multi account transactions.
The ICRC-4 interface is a generalized interface for submitting multiple transactions in one Internet computer call to an ICRC-1 ledger. It makes no guarantees about the atomicity of the execution of the items, but does outline convinience parameters and the data return in such away that the caller can self verify the results of the transactions.
The interface allows a principle to supply a set of transactions that move tokens from one of their sub accounts to another account. There is no restrictions on which subaccounts, or how many sub accounts can be used, but it is assumed that the principal has the rights to all the sub accounts provided.
Many contracts provide multiplarty transactions or settlment processes tht may move tokens from any accounts owned by a principal to many other accounts. With the ICRC-1 standard, each of these transactions must be submitted seperatelay and incure both call cylce charge(more if a subnet boundry is crossed) and a latency charge as a contract cannot blindly submit unlimited transactions without awaiting due to cycle limits.
This interface enables new application capabilities:
Send from multiple account to multiple accounts in one transaction. Alice can approve a transfer of 10 ICP from her sub-account 1 to Bob and 2 ICP from her sub-account 2 to Charlie.
Check that all transactions are valid befor starting tranfers. In some ledgers, transfers are atomic and we can check at the begining that all transactions will pass before performing the transactions.
The keywords "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119. Canisters implementing the
ICRC-4
standard MUST implement all the functions in theICRC-4
interface
Canisters implementing the ICRC-4
standard MUST include ICRC-4
in the list returned by the icrc1_supported_standards
method
type Account = record {
owner : principal;
subaccount : opt blob;
};
Moves tokens from many accounts { owner = caller; subaccount = from_subaccount }
to many other accounts.
The ledger MAY cap the total numbr of transactions in one batch as the IC has a current limitation of message size of around 2MB and thus neither outgoing messages or return types should be greater than this. In addition, some ledger may include extensive calculations to balances that could limit the number of processed transactions that may be exdcuted within the cycle limit.
icrc4_transfer_batch: (TransferBatchArgs) -> (variant { Ok : [(TransferArg, variant {Ok: Nat, Err: TransferError})]; Err : TransferBatchError });
type TransferBatchArgs = record {
pre_validate : bool;
transactions : [TransferArgs];
batch_fee : opt nat;
};
type TransferArgs = record {
from_subaccount : opt Subaccount;
to : Account;
amount : nat;
fee : opt nat;
memo : opt blob;
created_at_time : opt nat64;
};
type TransferError = variant {
BadFee : record { expected_fee : nat };
BadBurn : record { min_burn_amount : nat };
InsufficientFunds : record { balance : nat };
TooOld;
CreatedInFuture : record { ledger_time: nat64 };
Duplicate : record { duplicate_of : nat };
TemporarilyUnavailable;
GenericError : record { error_code : nat; message : text };
};
type TransferBatchError = variant {
BadBatchFee : record { expected_fee : nat };
TooManyTransactions : record { max : nat };
BadBurn : (TransferArg, record { min_burn_amount : nat });
InsufficientFunds : (TransferArgs, record { balance : nat });
TooOld: TransferArgs;
CreatedInFuture : (TransferArg, record { ledger_time: nat64 });
Duplicate : (TransferArg, record { duplicate_of : nat });
TemporarilyUnavailable;
GenericError : record { error_code : nat; message : text };
};
{ owner = caller; subaccount = from_subaccount }
account to pay the transfer fees required by the application. The application is free to determine the fee schema. It MAY require a batch fee and it MAY require a fee on each tranaaction.Allows anyone to query the ballance of a set of accounts.
icrc4_balance_of_batch : ([Account]) -> (record{
Ok: [(Account,nat)];
Err: BalanceBatchError) query;
});
type TransferBatchError = variant {
TooManyBalances : record { max : nat };
};
'
The number of accounts must be below max_balances in the request
Accounts are provide in an array with the original request associated with request such that ordering of request and response does not need to be synced.
Validates a batch of transactions. Returns Ok if the transactions pass the pre_validate conditions. If an Error is returned it should be the first error that triggerd a failure
icrc4_validate_batch: (ValidateBatchArgs) -> (variant { Ok : (); Err : TransferBatchError }) query;
type ValidateBatchArgs = record {
transactions : [TransferArgs];
batch_fee : opt nat;
};
Returns the metadata for the ICRC-4 specification.
icrc4_metatdata : () -> (ICRC4Metada) query;
type ICRC4Metada = record {
max_transactions : opt nat;
max_balances : opt nat;
batch_fee: opt nat;
};
Returns the list of standards this ledger supports.
Any ledger supporting ICRC-4
MUST include a record with the name
field equal to "ICRC-4"
in that list.
icrc1_supported_standards : () -> (vec record { name : text; url : text }) query;
my comment: https://github.com/dfinity/ICRC-1/pull/95#issuecomment-1489977614
It is recommended to implement the simplest compatible functionality for ICRC4. The main goal of icrc4 is to execute icrc1_transfer() in batch, is it necessary to introduce more features or restrictions?
Updates with latest learnings from ICRC7/37:
https://github.com/skilesare/ICRC/blob/main/ICRCs/ICRC-4/ICRC-4.md
Notes from KayICP: https://forum.dfinity.org/t/icrc4-batch-transfers-nearing-finalization-please-review/27395/9?u=skilesare
change maximum to max
get rid of batch on the transfer.
Reserved ICRC Number