Skip to main content

Billing Contract

This Smart Contract handles the billing part: supported currencies, exchange rates to USD (for the moment only USD-stable ERC20 tokens are supported), VAT rates, pricing rates, deposit rate, authorized countries of residence.

Events

CurrencyChanged

event CurrencyChanged(string symbol, address token)

VatRateChanged

event VatRateChanged(uint16 countryISO, uint256 rate)

PriceRateChanged

event PriceRateChanged(enum Billing.SubscriptionPeriod period, uint256 rate)

Variables

SubscriptionPeriod

enum SubscriptionPeriod {
Week,
Month,
Year
}

currencies

mapping(string => address) currencies

List of supported currencies (example: USDT => 0x...)

vatRates

mapping(uint16 => uint256) vatRates

Indexed VAT rates by country (country ISO 3166 ALPHA-2)

deniedCountry

mapping(uint16 => bool) deniedCountry

List of unauthorized countries

priceRates

mapping(uint8 => uint256) priceRates

List of prices indexed by subscription period

Functions

initialize

function initialize(address _accessControl, address _usdtToken, address _usdcToken) public

Public initializer with published default settings

Parameters

NameTypeDescription
_accessControladdressThe c-chain address of access control contract
_usdtTokenaddressThe c-chain address of USDT contract
_usdcTokenaddress

setDeniedCountry

function setDeniedCountry(uint16 _country, bool deny) public

Adds or remove a country to the list of rejected countries

Parameters

NameTypeDescription
_countryuint16The country ISO 3166 ALPHA-2
denyboolIf true, the country is to be denied

setVatRate

function setVatRate(uint16 _countryIso, uint256 _rate) public

Modifies a country's VAT rate

Parameters

NameTypeDescription
_countryIsouint16The country ISO 3166 ALPHA-2
_rateuint256VAT rate (example: 20 for 20%)

setCurrency

function setCurrency(string _currencySymbol, address _token) public

Adds or remove an accepted currency

Parameters

NameTypeDescription
_currencySymbolstringThe currency name (example: USDT)
_tokenaddressThe currency c-chain address

setPriceRate

function setPriceRate(enum Billing.SubscriptionPeriod _period, uint256 _rate) public

Modifies the price of a period

Parameters

NameTypeDescription
_periodenum Billing.SubscriptionPeriodThe period (see SubscriptionPeriod enum)
_rateuint256The new rate (example: 1200 for 12.00 / two decimal)

isDeniedCountry

function isDeniedCountry(uint16 _country) public view returns (bool)

Checks if the country is denied by the contract

Parameters

NameTypeDescription
_countryuint16The country ISO 3166 ALPHA-2

Return Values

NameTypeDescription
[0]boolboolean True if the country is denied

isValidCountryCode

function isValidCountryCode(uint16 _countryCode) public pure returns (bool)

Checks if the provided country code is valid

Parameters

NameTypeDescription
_countryCodeuint16The country ISO 3166 ALPHA-2

Return Values

NameTypeDescription
[0]boolboolean True if country code is valid, otherwise false

usdToCurrency

function usdToCurrency(uint256 _amount, string _symbol) public view returns (uint256)

Computes and returns the amount with the correct number of decimal digits

Parameters

NameTypeDescription
_amountuint256The amount with two digits (ex: for 12$ contract expects 1200)
_symbolstringThe currency name (ex: USDT)

Return Values

NameTypeDescription
[0]uint256amount returns the amount with the correct number of decimal digits

isSupportedCurrency

function isSupportedCurrency(string _currencySymbol) public view returns (bool)

Returns if currency is supported

Parameters

NameTypeDescription
_currencySymbolstringThe currency name (ex: USDT)

Return Values

NameTypeDescription
[0]boolboolean True if supported otherwise false

usdPriceExcludingTax

function usdPriceExcludingTax(enum Billing.SubscriptionPeriod _period, uint256 nbPeriods) public view returns (uint256)

Computes price given the period and the number of periods, excluding VAT

Parameters

NameTypeDescription
_periodenum Billing.SubscriptionPeriodThe period (see SubscriptionPeriod enum)
nbPeriodsuint256the number of periods (at least 1)

Return Values

NameTypeDescription
[0]uint256price return the price excluding VAT

taxAmount

function taxAmount(uint256 _usdAmount, uint16 _countryOfResidence) public view returns (uint256)

Computes price VAT

Parameters

NameTypeDescription
_usdAmountuint256The USD amount
_countryOfResidenceuint16The country ISO 3166 ALPHA-2

Return Values

NameTypeDescription
[0]uint256Price VAT