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.
event CurrencyChanged(string symbol, address token)
event VatRateChanged(uint16 countryISO, uint256 rate)
event PriceRateChanged(enum Billing.SubscriptionPeriod period, uint256 rate)
enum SubscriptionPeriod {
Week,
Month,
Year
}
mapping(string => address) currencies
List of supported currencies (example: USDT => 0x...)
mapping(uint16 => uint256) vatRates
Indexed VAT rates by country (country ISO 3166 ALPHA-2)
mapping(uint16 => bool) deniedCountry
List of unauthorized countries
mapping(uint8 => uint256) priceRates
List of prices indexed by subscription period
function initialize(address _accessControl, address _usdtToken, address _usdcToken) public
Public initializer with published default settings
Name | Type | Description |
---|
_accessControl | address | The c-chain address of access control contract |
_usdtToken | address | The c-chain address of USDT contract |
_usdcToken | address | |
function setDeniedCountry(uint16 _country, bool deny) public
Adds or remove a country to the list of rejected countries
Name | Type | Description |
---|
_country | uint16 | The country ISO 3166 ALPHA-2 |
deny | bool | If true, the country is to be denied |
function setVatRate(uint16 _countryIso, uint256 _rate) public
Modifies a country's VAT rate
Name | Type | Description |
---|
_countryIso | uint16 | The country ISO 3166 ALPHA-2 |
_rate | uint256 | VAT rate (example: 20 for 20%) |
function setCurrency(string _currencySymbol, address _token) public
Adds or remove an accepted currency
Name | Type | Description |
---|
_currencySymbol | string | The currency name (example: USDT) |
_token | address | The currency c-chain address |
function setPriceRate(enum Billing.SubscriptionPeriod _period, uint256 _rate) public
Modifies the price of a period
Name | Type | Description |
---|
_period | enum Billing.SubscriptionPeriod | The period (see SubscriptionPeriod enum) |
_rate | uint256 | The new rate (example: 1200 for 12.00 / two decimal) |
function isDeniedCountry(uint16 _country) public view returns (bool)
Checks if the country is denied by the contract
Name | Type | Description |
---|
_country | uint16 | The country ISO 3166 ALPHA-2 |
Name | Type | Description |
---|
[0] | bool | boolean True if the country is denied |
function isValidCountryCode(uint16 _countryCode) public pure returns (bool)
Checks if the provided country code is valid
Name | Type | Description |
---|
_countryCode | uint16 | The country ISO 3166 ALPHA-2 |
Name | Type | Description |
---|
[0] | bool | boolean True if country code is valid, otherwise false |
function usdToCurrency(uint256 _amount, string _symbol) public view returns (uint256)
Computes and returns the amount with the correct number of decimal digits
Name | Type | Description |
---|
_amount | uint256 | The amount with two digits (ex: for 12$ contract expects 1200) |
_symbol | string | The currency name (ex: USDT) |
Name | Type | Description |
---|
[0] | uint256 | amount returns the amount with the correct number of decimal digits |
function isSupportedCurrency(string _currencySymbol) public view returns (bool)
Returns if currency is supported
Name | Type | Description |
---|
_currencySymbol | string | The currency name (ex: USDT) |
Name | Type | Description |
---|
[0] | bool | boolean True if supported otherwise false |
function usdPriceExcludingTax(enum Billing.SubscriptionPeriod _period, uint256 nbPeriods) public view returns (uint256)
Computes price given the period and the number of periods, excluding VAT
Name | Type | Description |
---|
_period | enum Billing.SubscriptionPeriod | The period (see SubscriptionPeriod enum) |
nbPeriods | uint256 | the number of periods (at least 1) |
Name | Type | Description |
---|
[0] | uint256 | price return the price excluding VAT |
function taxAmount(uint256 _usdAmount, uint16 _countryOfResidence) public view returns (uint256)
Computes price VAT
Name | Type | Description |
---|
_usdAmount | uint256 | The USD amount |
_countryOfResidence | uint16 | The country ISO 3166 ALPHA-2 |
Name | Type | Description |
---|
[0] | uint256 | Price VAT |