Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: sponsorships #351

Closed
wants to merge 102 commits into from
Closed

feat: sponsorships #351

wants to merge 102 commits into from

Conversation

al3mart
Copy link
Collaborator

@al3mart al3mart commented Oct 23, 2024

Introduce the PoC for sponsored transactions.

Means to keeps track of sponsorship relations between a sponsor account and a beneficiary account such that sponsors can cover transaction fees for the beneficiaries.

This PoC introduces a simple pallet that maintains sponsorships in a double map

/// Register of sponsorships.
/// - K1: Account acting as sponsor.
/// - K2: Sponsored account.
/// - V: If specified, the sponsored amount.
#[pallet::storage]
pub type Sponsorships<T: Config> = StorageDoubleMap<
	_,
	Twox64Concat,
	AccountIdOf<T>,
	Twox64Concat,
	AccountIdOf<T>,
	BalanceOf<T>,
	OptionQuery,
>;

Note that the value stored is of type Weigth with the idea that each relation could have different limits for how much a sponsor should cover for its beneficiary. Although, that is not explored in this PoC.

Implements two extrinsics to modify said state:

  • pub fn sponsor_account(origin: OriginFor<T>, beneficiary: T::AccountId) -> DispatchResult {}
  • pub fn remove_sponsorship_for(origin: OriginFor<T>, beneficiary: T::AccountId) -> DispatchResult {}
  • pub fn set_sponsorship_amount( origin: OriginFor<T>, beneficiary: AccountIdOf<T>, new_amount: BalanceOf<T>) -> DispatchResult {}

And the struct Sponsored implements SignedExtension and it is expected to wrap another implementer of SignedExtension that handles the deduction of the relevant transaction fees.
Sponsored implementation takes care of verifying the sponsorship exists and forwards to the wrapper extension the correct account to deduct fees from.
In this PoC the only possible interaction that can be sponsored is a call to a contract.

This pallet is exposed to ink! contracts via pop-api. A contract is included showing how an account can be registered to be sponsor in the example contract "sponsorships": pop-api/examples/sponsorships/lib.rs.

@al3mart al3mart changed the title feaT: Sponsorships PoC feat: Sponsorships PoC Oct 23, 2024
@al3mart al3mart marked this pull request as draft October 23, 2024 18:15
@al3mart al3mart marked this pull request as ready for review October 23, 2024 22:27
@al3mart
Copy link
Collaborator Author

al3mart commented Oct 31, 2024

Closing in favor of #362 as I messed up the commit history and the PR was difficult to review.

@al3mart al3mart closed this Oct 31, 2024
@al3mart al3mart mentioned this pull request Oct 31, 2024
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