ISubscriptionManager

Git Source

Interface for the SubscriptionManager diamond

Defines all functions available on the SubscriptionManager diamond

Functions

subscribeCMX

Subscribes to a tier using CMX tokens directly (convenience function)

function subscribeCMX(uint8 tierLevel) external;

Parameters

Name
Type
Description

tierLevel

uint8

The tier level to subscribe to

subscribe

Subscribes to a tier using any accepted token

function subscribe(uint8 tierLevel, address paymentToken) external;

Parameters

Name
Type
Description

tierLevel

uint8

The tier level to subscribe to

paymentToken

address

The token to pay with (CMX or stablecoin)

subscribeWithETH

Subscribes to a tier using ETH (for future implementation)

function subscribeWithETH(uint8 tierLevel) external payable;

Parameters

Name
Type
Description

tierLevel

uint8

The tier level to subscribe to

renewSubscription

Renews a subscription using the same token as last payment

function renewSubscription() external;

renewSubscription

Renews a subscription with a specific token

function renewSubscription(address paymentToken) external;

Parameters

Name
Type
Description

paymentToken

address

The token to pay with

changeTierCMX

Changes subscription tier using CMX (convenience function)

function changeTierCMX(uint8 newTierLevel) external;

Parameters

Name
Type
Description

newTierLevel

uint8

The new tier level

changeTier

Changes subscription tier

function changeTier(uint8 newTierLevel, address paymentToken) external;

Parameters

Name
Type
Description

newTierLevel

uint8

The new tier level

paymentToken

address

The token to pay with

cancelSubscription

Cancels a subscription

function cancelSubscription() external;

hasActiveSubscription

Check if an address has an active subscription at or above specified tier

function hasActiveSubscription(address subscriber, uint8 minTierLevel) external view returns (bool);

Parameters

Name
Type
Description

subscriber

address

The subscriber address

minTierLevel

uint8

Minimum tier level required

Returns

Name
Type
Description

<none>

bool

bool True if subscriber has active subscription at or above the tier

getUserTier

Get the current tier level for a subscriber

function getUserTier(address subscriber) external view returns (uint8);

Parameters

Name
Type
Description

subscriber

address

The subscriber address

Returns

Name
Type
Description

<none>

uint8

tierLevel The subscriber's current tier level (0 if no active subscription)

getSubscriptionDetails

Get subscription details for a subscriber

function getSubscriptionDetails(address subscriber)
    external
    view
    returns (
        uint8 tierLevel,
        uint256 nextPaymentDue,
        bool isActive,
        uint256 lastPaymentAmount,
        address lastPaymentToken
    );

Parameters

Name
Type
Description

subscriber

address

The subscriber address

Returns

Name
Type
Description

tierLevel

uint8

The subscriber's current tier level

nextPaymentDue

uint256

When the next payment is due

isActive

bool

Whether the subscription is active

lastPaymentAmount

uint256

The last payment amount

lastPaymentToken

address

The token used for last payment

getPaymentAmount

Calculates the payment amount for a subscriber and tier with a specific token

function getPaymentAmount(address subscriber, uint8 tierLevel, address paymentToken) external view returns (uint256);

Parameters

Name
Type
Description

subscriber

address

The subscriber address

tierLevel

uint8

The tier level

paymentToken

address

The token to pay with

Returns

Name
Type
Description

<none>

uint256

uint256 The payment amount in the token's decimals

initialize

Initialize the subscription manager

function initialize(address _cmxToken, address _swapRouter, address _treasury, address _initialOwner) external;

Parameters

Name
Type
Description

_cmxToken

address

Address of the CMX token

_swapRouter

address

Address of the Uniswap V3 SwapRouter

_treasury

address

Address to receive payments

_initialOwner

address

Address that will become the owner of the contract

setTier

Creates or updates a subscription tier

function setTier(uint8 tierLevel, string calldata name, uint256 monthlyFeeUSD, bool isActive) external;

Parameters

Name
Type
Description

tierLevel

uint8

The tier level

name

string

The tier name

monthlyFeeUSD

uint256

The monthly fee in USD (6 decimals)

isActive

bool

Whether the tier is active

addAcceptedToken

Adds a new payment token

function addAcceptedToken(address token, uint8 decimals, bool isStablecoin) external;

Parameters

Name
Type
Description

token

address

The token address to add

decimals

uint8

The token decimals

isStablecoin

bool

Whether this is a stablecoin (true) or CMX (false)

removeAcceptedToken

Removes a token from the accepted tokens list

function removeAcceptedToken(address token) external;

Parameters

Name
Type
Description

token

address

The token address to remove

setCMXDiscount

Sets the CMX discount percentage

function setCMXDiscount(uint256 discountBasisPoints) external;

Parameters

Name
Type
Description

discountBasisPoints

uint256

Discount in basis points (e.g., 2000 = 20%)

setAddressTierDiscount

Sets a customer-specific discount for a specific tier (only applies to CMX payments)

function setAddressTierDiscount(address subscriber, uint8 tierLevel, uint256 discountBasisPoints) external;

Parameters

Name
Type
Description

subscriber

address

The subscriber address

tierLevel

uint8

The tier level

discountBasisPoints

uint256

Discount in basis points (10000 = 100%)

adminSetSubscription

Admin function to set a subscription as active for a specific period

function adminSetSubscription(address subscriber, uint8 tierLevel, uint256 durationInSeconds) external;

Parameters

Name
Type
Description

subscriber

address

The subscriber address

tierLevel

uint8

The tier level

durationInSeconds

uint256

Duration of subscription

adminCancelSubscription

Admin function to force cancel a subscription

function adminCancelSubscription(address subscriber) external;

Parameters

Name
Type
Description

subscriber

address

The subscriber address

setTreasury

Updates the treasury address

function setTreasury(address newTreasury) external;

Parameters

Name
Type
Description

newTreasury

address

New treasury address

setUniswapPoolFee

Sets the Uniswap pool fee for token swaps (for future ETH support)

function setUniswapPoolFee(uint24 newFee) external;

Parameters

Name
Type
Description

newFee

uint24

New fee tier (e.g., 3000 for 0.3%)

getSubscriptionInfo

Get full subscription info for a subscriber

function getSubscriptionInfo(address subscriber)
    external
    view
    returns (
        uint8 tierLevel,
        uint256 nextPaymentDue,
        bool isActive,
        uint256 lastPaymentAmount,
        string memory tierName,
        uint256 tierFeeUSD,
        address lastPaymentToken
    );

Parameters

Name
Type
Description

subscriber

address

The subscriber address

Returns

Name
Type
Description

tierLevel

uint8

Current tier level

nextPaymentDue

uint256

Next payment due timestamp

isActive

bool

Whether subscription is active and not expired

lastPaymentAmount

uint256

Last payment amount

tierName

string

Name of current tier

tierFeeUSD

uint256

Monthly fee for current tier in USD (6 decimals)

lastPaymentToken

address

Token used for last payment

getTierInfo

Get tier information

function getTierInfo(uint8 tierLevel)
    external
    view
    returns (string memory name, uint256 monthlyFeeUSD, bool isActive);

Parameters

Name
Type
Description

tierLevel

uint8

The tier level

Returns

Name
Type
Description

name

string

The tier name

monthlyFeeUSD

uint256

The monthly fee in USD (6 decimals)

isActive

bool

Whether the tier is active

getTokenConfig

Get token configuration for a specific token

function getTokenConfig(address token) external view returns (bool accepted, uint8 decimals, bool isStablecoin);

Parameters

Name
Type
Description

token

address

The token address

Returns

Name
Type
Description

accepted

bool

Whether the token is accepted

decimals

uint8

Token decimals

isStablecoin

bool

Whether it's a stablecoin

getAddressTierDiscount

Gets the discount for a specific address and tier

function getAddressTierDiscount(address subscriber, uint8 tierLevel) external view returns (uint256);

Parameters

Name
Type
Description

subscriber

address

The subscriber address

tierLevel

uint8

The tier level

Returns

Name
Type
Description

<none>

uint256

discountBasisPoints Discount in basis points

getCMXDiscount

Get the CMX discount percentage

function getCMXDiscount() external view returns (uint256);

Returns

Name
Type
Description

<none>

uint256

discountBasisPoints Discount in basis points

getCMXToken

Get the CMX token address

function getCMXToken() external view returns (address);

Returns

Name
Type
Description

<none>

address

cmxToken The CMX token address

getTreasury

Get the treasury address

function getTreasury() external view returns (address);

Returns

Name
Type
Description

<none>

address

treasury The treasury address

getSwapRouter

Get the swap router address

function getSwapRouter() external view returns (address);

Returns

Name
Type
Description

<none>

address

swapRouter The swap router address

getUniswapPoolFee

Get the Uniswap pool fee

function getUniswapPoolFee() external view returns (uint24);

Returns

Name
Type
Description

<none>

uint24

poolFee The pool fee

isInitialized

Check if the contract is initialized

function isInitialized() external view returns (bool);

Returns

Name
Type
Description

<none>

bool

initialized Whether the contract is initialized

cmxToken

Get the CMX token address (convenience function)

function cmxToken() external view returns (address);

Returns

Name
Type
Description

<none>

address

The CMX token address

tiers

Get tier information (convenience function)

function tiers(uint8 tierLevel) external view returns (string memory name, uint256 monthlyFeeUSD, bool isActive);

Parameters

Name
Type
Description

tierLevel

uint8

The tier level

Returns

Name
Type
Description

name

string

The tier name

monthlyFeeUSD

uint256

The monthly fee in USD (6 decimals)

isActive

bool

Whether the tier is active

Events

SubscriptionCreated

event SubscriptionCreated(
    address indexed subscriber, uint8 tierLevel, uint256 paymentAmount, uint256 nextDue, address paymentToken
);

SubscriptionRenewed

event SubscriptionRenewed(
    address indexed subscriber, uint8 tierLevel, uint256 paymentAmount, uint256 nextDue, address paymentToken
);

SubscriptionCancelled

event SubscriptionCancelled(address indexed subscriber);

SubscriptionTierUpdated

event SubscriptionTierUpdated(address indexed subscriber, uint8 oldTier, uint8 newTier);

TierCreated

event TierCreated(uint8 tierLevel, string name, uint256 monthlyFeeUSD);

TierUpdated

event TierUpdated(uint8 tierLevel, string name, uint256 monthlyFeeUSD, bool isActive);

CMXDiscountUpdated

event CMXDiscountUpdated(uint256 oldDiscount, uint256 newDiscount);

AcceptedTokenAdded

event AcceptedTokenAdded(address indexed token, uint8 decimals, bool isStablecoin);

AcceptedTokenRemoved

event AcceptedTokenRemoved(address indexed token);

TreasuryUpdated

event TreasuryUpdated(address indexed oldTreasury, address indexed newTreasury);

UniswapPoolFeeUpdated

event UniswapPoolFeeUpdated(uint24 oldFee, uint24 newFee);

Last updated

Was this helpful?