Skip to content

[Encointer] use XCM V5 to remotely spend funds from encointer treasury accounts on AHK#679

Merged
acatangiu merged 135 commits into
polkadot-fellows:mainfrom
encointer:cl/xcm-treasury-rebased
Aug 23, 2025
Merged

[Encointer] use XCM V5 to remotely spend funds from encointer treasury accounts on AHK#679
acatangiu merged 135 commits into
polkadot-fellows:mainfrom
encointer:cl/xcm-treasury-rebased

Conversation

@clangenb
Copy link
Copy Markdown
Contributor

@clangenb clangenb commented Apr 17, 2025

Encointer's treasury beneficiaries would greatly benefit from receiving assets directly on asset hub (especially in the future, as we can assume that CEX exchanges will allow deposits from asset hub). Additionally, we want to give them stability by receiving funds in stable coins (potentially dUSD).

The remote transfer has been inspired by the fellowships approach, however, it is slightly different as encointer has to pay for that execution. Additionally, we need to have a configurable sender account on Asset Hub, as each encointer-community has its own unique treasury account. Similarly to the polkadot-sdk's pay trait, we have introduced the Transfer trait (mostly in order to allow for a configurable sender account on asset hub). Which we intend to upstream after testing and deploying it here.

The idea is that the following happens on asset hub:

  1. Descend into the origin of the encointer-treasury account's representation on asset hub
  2. Withdraw some native tokens to pay for the fees
  3. Withdraw the token to be transferred from the treasury-account to the beneficiary
  4. Transfer: treasury -> beneficiary
  5. Refund the excess weight

Changes in this PR:

Todo:

  • After testing, publish encointers crate enabling that feature and remove patches

@clangenb clangenb marked this pull request as draft April 17, 2025 12:26
Comment thread system-parachains/encointer/src/tests/xcm_mock.rs
Comment thread system-parachains/encointer/src/treasuries_xcm_payout.rs
Comment thread system-parachains/encointer/src/treasuries_xcm_payout.rs Outdated
Comment thread system-parachains/encointer/src/tests/unit_tests.rs Outdated
@clangenb clangenb changed the title [Encointer] use XCM V5 to remotely transfer funds from encointer treasury accounts [Encointer] use XCM V5 to remotely spend funds from encointer treasury accounts Apr 17, 2025
Comment thread integration-tests/emulated/tests/encointer/encointer-kusama/src/tests/mod.rs Outdated
Comment thread system-parachains/encointer/Cargo.toml Outdated
Copy link
Copy Markdown
Member

@ggwpez ggwpez left a comment

Choose a reason for hiding this comment

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

Encointer is not a trusted teleporter, or?

@acatangiu
Copy link
Copy Markdown
Contributor

acatangiu commented Aug 22, 2025

Encointer is not a trusted teleporter, or?

it is a trusted teleporter, it's para id is in the sys chains interval, and that's what's used for differentiating trusted teleporters

also a trusted teleported for Kusama RC

@clangenb
Copy link
Copy Markdown
Contributor Author

I think that the comments are addressed. Thanks for pointing this out!

@acatangiu
Copy link
Copy Markdown
Contributor

/merge

@acatangiu acatangiu merged commit 67dc0c5 into polkadot-fellows:main Aug 23, 2025
63 of 64 checks passed
Copy link
Copy Markdown
Member

@pandres95 pandres95 left a comment

Choose a reason for hiding this comment

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

LGTM 👍

Comment thread system-parachains/encointer/src/lib.rs

let sender = AccountId::new([1u8; 32]);
let sender_location_on_target =
Location::new(1, X2([Parachain(42), AccountId32 { network: None, id: [1; 32] }].into()));
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.

@clangenb just an nit, using too low values for parachain could be tricky in some scenarios (bellow 2000 are considered system parachains).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point. I copied this from upstreams Pay unit test. However, the Pay trait assumes free execution on the target parachain, so hence it was a reasonable assumption to put 42 as the parachain. I will make this a higher number when I move these tests upstream. 👍

pub Timeout: BlockNumber = 5; // 5 blocks
}

/// Scenario:
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.

@clangenb I didn't walk through these test, but just curios, if we could use emulated tests (EncointerKusama, AssetHubKusama, AssetHubPolkadot, PenpalKusama, PenpalPolkadot) to simulate this? That way we won't need all this mocking stuff.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I intend to upstream the Transfer trait and a TransferOverXCM generic implementation. In that process, I will move this test upstream. There is already mocking in place there, which I intend to re-use.

I agree with you that we can then delete the mocking and this unit test from here. 👍

ReportError(QueryResponseInfo {
destination: destination.clone(),
query_id,
max_weight: Weight::zero(),
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.

@clangenb is Weight::zero() really working? If I am checking it correctly, it should end up in the: https://github.com/paritytech/polkadot-sdk/blob/master/polkadot/xcm/pallet-xcm/src/lib.rs#L4052-L4064

if weight.any_gt(max_weight) {
								let e = Event::NotifyOverweight {

Ok, maybe not that critical if the ReportError does not work, but still :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hmm, interesting. I suspect that the mock that I copied from upstream is lacking some logic here. I will have a closer look here while upstreaming that part. 👍

// Measured: `733`
// Estimated: `6196`
// Minimum execution time: 70_344_000 picoseconds.
Weight::from_parts(72_445_000, 0)
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.

@clangenb Did we run fresh benchmarks for this? I think we should better run maybe as follow up - with mentioned small nits

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch, you are right. This call has not been properly benchmarked! Do I as a mere rank I member have the rights to run the benchmarks?

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.

... Do I as a mere rank I member have the rights to run the benchmarks?

Yes, you can :)

Comment thread system-parachains/encointer/src/treasuries_xcm_payout.rs
Comment thread system-parachains/encointer/src/treasuries_xcm_payout.rs
fellowship-merge-bot Bot pushed a commit that referenced this pull request Aug 27, 2025
@bkontur identified minor fixes after #679, which should be fixed. The
most important one would be to properly generate the weight of the new
dispatchable. Closes #864.

<!-- Remember that you can run `/merge` to enable auto-merge in the PR
-->

<!-- Remember to modify the changelog. If you don't need to modify it,
you can check the following box.
Instead, if you have already modified it, simply delete the following
line. -->

- [x] Does not require a CHANGELOG entry
@clangenb clangenb deleted the cl/xcm-treasury-rebased branch December 3, 2025 06:09
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.

6 participants