r0gue-io / pop-node

Pop Network makes it easy for smart contract developers to use the Power of Polkadot.
The Unlicense
24 stars 6 forks source link

feat: sponsorships #362

Closed al3mart closed 3 weeks ago

al3mart commented 3 weeks ago

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:

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.