---
# System prepended metadata

title: cw-subscription design notes

---

# cw-subscription design notes

- Off-chain task discover collectible subscriptions either by off-chain indexing or query on-chain queue ordered by `next_collection_time`.

- Off-chain task compute `current_collection_time` and `next_collection_time` for collectible subscriptions, send them together with subscription ids to contract.

- Contract verifies (verification is much more efficient than datetime rounding):

  - Both `current_collection_time` and `next_collection_time` matches the cron spec
  - `next_collection_time > current_collection_time > last_collection_time`
    > it's possible that some periods are skipped, if the off-chain task made mistake, and those skipped periods can't be retried later.

- off chain task is free to choose different strategies:

  - collect all, platform can do this as public good.
  - collect those owned by himself, merchant can do this if platform failed to do the above.

- off chain task is free to choose different failure retry strategries.

- Require some amount of deposit for active plans/subscriptions, which is refunded when plans/subscriptions are deleted, incentivise user to delete unused stuff and reclaim on-chain resources.

- Use self-incremented u128 for plan/subscription id, when overflow, wrap around and try to find an unused one.

- Support cw20(cw1155 too?) tokens, subscribers should set approval to allow subscription contract to transfer fund, native tokens can be used through 1-to-1 mapped cw20 token.

- Subscriber specify expiration time when subscription expire automatically, it can also unsubscribe at any time anyway. Plan can't enfore a minimal duration for subscription.