Become a payment processor

This page will go over some concepts which are important when building a sub2 payment processor, whether it be for profit or to ensure processing of your own payments without reliying on other payment processors.

Off-chain computation

The data of a Subscription struct provides all the information necessary to compute the exact state of the subscription, including:

  • If the subscription is on cooldown, in auction period, canceled or expired.

  • When the next auction period opens and for how long.

  • The exact amount of tokens the processor will be rewarded at any moment in the auction period.

Thus, querying on-chain information about a subscription is only necessary once and the state can be updated locally while listning for events.

Listen to events

Emitted events will tell when the state of a subscription is updated.

  • Payment happens when a payment is processed and therefore the cooldown is reset from when the last payment was due.

  • SubscriptionCreated alerts that a new subscription has been created which can now be observed. Note that subscriptions can be created using reused indices in the subscriptions array.

  • SubscriptionCanceled alerts that a subscription has been canceled should therefore not be observed anymore.

  • MaxProcessingFeeUpdated happens when the sponsor of the payment updates the maximum processing fee amount and token. This is important for a processor to keep track of since it determines the reward for processing the subscription.

Parallelisation

Since all subscriptions are stored in the public subscriptions array, payment processing can easy be parallelised. The array can simply be split into even sections that each processor takes care of.

The BatchProcessor contract

The BatchProcessor is a contract which enables processing multiple payments in a single batch. Even if one of the payments fails to be processed, the transaction as a whole will not revert. Furthermore, it returns a receipt for each successful payments processed containing information about the reward received. The contract can be found here.

Strict gas price monitoring

Strict gas price monitoring is crucial to implementing a profitable payment processor. The profit you can make on processing a specific payment is primarily depending on the current gas price together with how far into the auction period the subscription is. Having live gas monitoring will give you an edge over other payment processors.

Use the sub2-sdk

The sub2-sdk provides features like processing in batches, setting up event listeners and more, making implementing a sub2 payment processor much easier.

Last updated