Rates
The Rates ADO is a smart contract used to impose some kind of fees on funds transactions.
This contract is implemented as a module and attached to other contracts which would apply the specified rates on any fund transfers. The contract owner can specify specific addresses to be exempt from these rates. A small example on this would be putting rates on an NFT Collectible, sending a percentage as royalty to the original owner.
There are two main types of rates:
- Taxes: Funds are added to the price and paid by the buyer
- Royalties: Funds are deducted from the price and are paid by the seller.
Ado_type: rates
Rust
JSON
pub struct InstantiateMsg {
pub rates: Vec<RateInfo>,
}
{
"rates":
[
{
"rate":{
"percent":{
"percent":"0.1"
},
"is_additive": false,
"recipients":[{
"addr":"andr1..."
},
{
"addr":"andr1..."
}
]
},
...
]
}
Name | Type | Description |
---|---|---|
rates | A vector containing the different RateInfo of the contract. |
The information about the rates is stored in a
RateInfo
struct.Each of the recipients will receive the rate imposed. ( The rate is 3% and we have 5 recipients then 15 % would go to them in total.)
Taxes are added to the selling price (Paid by buyer) while royalties are deducted from the price (Paid by seller).
pub struct RateInfo {
pub rate: Rate,
pub is_additive: bool,
pub description: Option<String>,
pub recipients: Vec<Recipient>,
}
An enum used to define various types of fees which is used in the RateInfo.
pub enum Rate {
Flat(Coin),
Percent(PercentRate),
External(PrimitivePointer),
}
The Rate can be one of the three option seen above:
- Percent: A percentage based rate. Needs to have the percent to take specified.
- External: This refers to a rate that we want to use which is saved in a primitive contract. Needs the address of the primitive and the key of the stored Rate primitive to be specified.
pub struct PercentRate {
pub percent: Decimal,
}
Name | Type | Description |
---|---|---|
percent | Decimal | The percentage to take as rate. |
PrimitivePointer
pub struct PrimitivePointer {
pub address: AndrAddress,
pub key: Option<String>,
}
Name | Type | Description |
---|---|---|
address | The address of the primitive contract. | |
key | Option<String> | The optional key for the stored data. |
Only the contract owner can execute UpdateRates.
Rust
JSON
pub enum ExecuteMsg{
UpdateRates{
rates: Vec<RateInfo>
}
}
{
"update_rates":{
"rates":
[
{
"rate":{
"percent":{
"percent":"0.1"
},
"is_additive": false,
"recipients":[
{
"addr":"andr1..."
},
{
"addr":"andr1..."
},
...
]
},
...
]
}
}
Name | Type | Description |
---|---|---|
rates | A vector containing the new RateInfo to be used by the contract. |
Specifies an address to be exempt from any rates set by this contract.
Only available to the contract owner.
Rust
JSON
pub enum ExecuteMsg {
AddExemption {
address: String
}
}
{
"add_exemption":{
"address":"andr1..."
}
}
Name | Type | Description |
---|---|---|
address | String | The address that will not have the rates applied. |
Removes an address from the list of exempt addresses.
Rust
JSON
pub enum ExecuteMsg {
RemoveExemption {
address: String
}
}
{
"remove_exemption":{
"address":"andr1..."
}
}
Name | Type | Description |
---|---|---|
address | String | The address to remove the exemption from. |
Returns the rates used by the contract in a vector of
RateInfo
.Rust
JSON
pub enum QueryMsg{
#[returns(PaymentsResponse)]
Payments {}
}
{
"payments":{}
}
Rust
JSON
pub struct PaymentsResponse {
pub payments: Vec<RateInfo>,
}
{
"payments":
[
{
"rate":{
"percent":{
"percent":"0.3"
}
},
"is_additive": false,
"recipients":[
{
"addr":"andr1..."
},
{
"addr":"andr1..."
},
...
]
},
...
]
}
Name | Type | Description |
---|---|---|
payments | A vector of the RatInfo currently used by the contract. |
Checks if the specified address is exempt from rates.
Rust
JSON
pub enum QueryMsg {
#[returns(bool)]
IsExempt {address: String }
}
{
"is_exempt":{
"address":"andr1..."
}
}
Name | Type | Description |
---|---|---|
address | String | The address to check if exempt from rates. |
Returns true if included and false otherwise.
Queries the list of addresses exempt from rates.
Rust
JSON
pub enum QueryMsg {
#[returns(ExemptionsResponse)]
Exemptions {
limit: Option<u32>,
start_after: Option<String>,
}
}
{
"exemptions":{
"limit": 80
}
}
Name | Type | Description |
---|---|---|
limit | Option<u32> | An optional limit on how many are returned. Default limit is 50 and the maximum limit that can be set is 100. |
start_after | Option<String> | An optional Id for which to start after, used for pagination. |
Rust
JSON
pub struct ExemptionsResponse {
pub exemptions: Vec<String>,
}
{
"exemptions":["andr1...","andr1...",...]
}