Skip to content

Implement spender approvals and transfers#1903

Merged
Neopallium merged 16 commits intodevelopfrom
MESH-2299-erc20-spender-approvals
Apr 14, 2026
Merged

Implement spender approvals and transfers#1903
Neopallium merged 16 commits intodevelopfrom
MESH-2299-erc20-spender-approvals

Conversation

@tgntr
Copy link
Copy Markdown
Contributor

@tgntr tgntr commented Mar 17, 2026

Implements spender approval primitives for the asset pallet and adds a transfer_funds extrinsic to the settlement pallet for spending approved allowances and same-identity direct transfers.

changelog

new features

  • Added spender allowance system — owners can approve other accounts to transfer fungible assets on their behalf
  • Added transfer_funds to the settlement pallet — supports same-identity direct transfers and spender-approved transfers without going through the settlement engine
  • Same-identity transfers for transfer_asset
  • Added transfer_nft to the NFT pallet — transfer NFTs between accounts/portfolios with same routing logic as transfer_funds

modified external API

  • transfer_asset now uses ensure_origin_call_permissions and routes same-DID transfers directly instead of always creating a settlement instruction

new external API

  • Added approve extrinsic to the asset pallet — set, replace, or revoke a spender allowance for a given asset
  • Added transfer_funds extrinsic to the settlement pallet — transfer assets with optional spender approval, defaults source to caller's account when from is None
  • Added allowance(owner, spender, asset_id) Runtime API — query remaining spender allowance without a transaction
  • Added transfer_nft extrinsic to the NFT pallet — transfer NFTs with same-DID direct / cross-DID settlement routing

new events

  • Added Approval { owner, spender, asset_id, amount } event — emitted on approve calls, not on spend

other

  • Added Allowances storage map to the asset pallet — maps (owner, spender, asset_id) to approved balance
  • Added InsufficientAllowance error to the asset pallet
  • Added SenderSameAsReceiver and AllowancesNotSupportedForNFTs errors to the settlement pallet
  • Added spend_allowance public helper to the asset pallet — used by the settlement pallet to check and decrement allowances
  • Infinite allowance (Balance::MAX) is never decremented on spend; allowance depleted to zero removes the storage entry
  • Added tests for approve, allowance Runtime API, and transfer_funds covering spender mode, same-identity transfers, cross-identity settlement, portfolio custody, NFT transfers, atomicity, and edge cases
  • Added PortfolioFnTrait / PortfolioFnConfig
  • Added transfer_funds / transfer_funds_weight to SettlementFnTrait — exposes routing logic for cross-pallet callers
  • simplified_nft_transfer now accepts Option<InstructionId> (was required)
  • Removed dead code: transfer_asset_base_weight benchmark, transfer_asset_and_try_execute, transfer_nft_and_try_execute

Comment thread pallets/asset/src/lib.rs
Comment thread pallets/asset/src/lib.rs
Comment thread pallets/settlement/src/lib.rs Outdated
@tgntr tgntr requested a review from Neopallium March 19, 2026 11:28
Comment thread pallets/asset/src/lib.rs Outdated
Comment thread pallets/settlement/src/benchmarking.rs Outdated
Comment thread pallets/settlement/src/benchmarking.rs
Comment thread pallets/nft/src/lib.rs Outdated
Comment thread pallets/asset/src/lib.rs
Comment thread pallets/settlement/src/lib.rs
Comment thread pallets/settlement/src/lib.rs Outdated
Comment thread pallets/settlement/src/lib.rs Outdated
Comment thread pallets/settlement/src/lib.rs Outdated
Comment thread pallets/weights/src/pallet_settlement.rs Outdated
Comment thread pallets/settlement/src/benchmarking.rs Outdated
@tgntr tgntr requested a review from Neopallium April 1, 2026 10:21
Comment thread pallets/weights/src/pallet_settlement.rs
Comment thread pallets/asset/src/lib.rs Outdated
Comment thread pallets/asset/src/lib.rs
Comment thread pallets/settlement/src/benchmarking.rs Outdated
Comment thread pallets/settlement/src/benchmarking.rs Outdated
Comment thread pallets/settlement/src/benchmarking.rs Outdated
Comment thread pallets/settlement/src/lib.rs Outdated
Comment thread pallets/settlement/src/lib.rs Outdated
@tgntr tgntr requested a review from Neopallium April 8, 2026 11:47
Copy link
Copy Markdown
Contributor

@Neopallium Neopallium left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overview of changes for this PR:

  1. Update the benchmarks/weights for NFTs.
  2. Nft.transfer_nft use AccountId instead of AssetHolder for from/to.

For follow-up PR:

  1. Use the fund, from, to parameters to select a more optimal worse-case weight (to lower the estimated tx fee).
  2. Don't include compliance/transfer rule and execution cost in base weights, so that the meter can be used for calculating a better actual fee.

Comment thread pallets/settlement/src/lib.rs Outdated
Comment thread pallets/nft/src/lib.rs Outdated
Comment thread pallets/nft/src/lib.rs Outdated
Comment thread pallets/settlement/src/lib.rs Outdated
Comment thread pallets/settlement/src/lib.rs
@HenriqueNogara HenriqueNogara self-requested a review April 9, 2026 11:49
@tgntr tgntr requested a review from Neopallium April 14, 2026 08:35
Comment on lines +4146 to +4147
let asset_count = Self::fungible_asset_count(is_fungible);
Self::base_try_execute_instruction(origin, instruction_id, &asset_count, weight_meter)?;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now the is_fungible flag is only set to true, since this method is only called for the fungible case. If we decide to add a Nft.receiver_affirm_nft_transfer extrinsic, then we will need to have the AssetCount include the correct number of NFTs.

For this PR, this is fine as is.

@Neopallium Neopallium changed the title Implement spender approvals and transfers Implement spender approvals and transfers. Apr 14, 2026
@Neopallium Neopallium changed the title Implement spender approvals and transfers. Implement spender approvals and transfers Apr 14, 2026
@Neopallium Neopallium merged commit 6680ba0 into develop Apr 14, 2026
17 of 19 checks passed
@Neopallium Neopallium deleted the MESH-2299-erc20-spender-approvals branch April 14, 2026 12:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants