Comment on page
Weighted Distribution Splitter
The Weighted-Distribution-Splitter ADO is a smart contract to split funds among a set of defined recipients. Each of the recipients is assigned a weight which is divided by the total weight to get the percentage of each of the recipients.
In the Weighted Distribution Splitter ADO, each recipient is assigned a weight. The weight represents the proportion of funds that the recipient will receive. The total weight of all recipients is calculated, and then each recipient's weight is divided by the total weight to determine their percentage of the funds.
Whenever the splitter receives funds by executing a
send,
it automatically splits the funds for distribution to the defined recipients. The splitter can be locked for a predetermined period, acting as a guarantee for recipients that their allocated weights will remain constant during that time.For example, if there are three recipients with weights 4, 7, and 2 respectively, the total weight is 13. The first recipient will receive 4/13 of the funds, the second recipient will receive 7/13 of the funds, and the third recipient will receive 2/13 of the funds.
If a recipient is then added, the total weight is increased and the percentages are recalculated.
ado_type: weighted-distribution-splitter
A maximum of 100 recipients can be set.
The minimum lock_time that can be set is 86,400 which is 1 day.
The maximum lock_time that can be set is 31,536,000 which is 1 year.
Rust
JSON
pub struct InstantiateMsg {
pub recipients: Vec<AddressWeight>,
pub lock_time: Option<u64>,
pub modules: Option<Vec<Module>>,
pub kernel_address: String,
pub owner: Option<String>
}
{
"recipients":[
{
"recipient":{
"address":"andr1..."
},
"weight": 4
},
{
"recipient":{
"address":"andr1..."
},
"weight": 7
},
{
"recipient":{
"address":"andr1..."
},
"weight": 2
}
],
"kernel_address":"andr1..."
}
Name | Type | Description |
---|---|---|
recipients | The vector of recipients for the contract. Anytime a Send execute message is sent the amount sent will be divided amongst these recipients depending on their assigned weight. | |
lock_time | Option<u64> | How long the splitter is locked. When locked, no recipients/weights can be added/changed. In seconds. |
modules | An optional vector of Andromeda Modules that can be attached to the contract."address-list" module can be added. | |
kernel_address | String | Contract address of the kernel contract to be used for AMP messaging. Kernel contract address can be found in our deployed contracts. |
owner | Option<String> | Optional address to specify as the owner of the ADO being created. Defaults to the sender if not specified. |
Struct containing the recipient of the funds and the assigned weight for that recipient.
pub struct AddressWeight {
pub recipient: Recipient,
pub weight: Uint128,
}
Name | Type | Description |
---|---|---|
recipient | The address to receive the funds. | |
weight | Uint128 | The weight of the above recipient. |
Updates the recipients of the splitter. When executed, the previous recipients and distribution are replaced by the new list.
Only available to the contract owner/operator when the contract is not locked.
Rust
JSON
pub enum ExecuteMsg {
UpdateRecipients {
recipients: Vec<AddressWeight>,
}
}
{
"update_recipients":{
"recipients":[
{
"recipient":{
"address":"andr1..."
},
"weight": 1
},
{
"recipient":{
"address":"andr1..."
},
"weight": 4
},
{
"recipient":{
"address":"andr1..."
},
"weight": 12
}
]
}
}
Name | Type | Description |
---|---|---|
recipients | The new recipients of the split funds with their assigned weights. |
Add a recipient to the list.
Only available to the contract owner/operator.
When a recipient is added, the total weight is changed and all the weights are recalculated appropriately.
Rust
JSON
pub enum ExecuteMsg {
AddRecipient {
recipient: AddressWeight,
}
}
{
"add_recipient":{
"recipient":{
"recipient":{
"address":"andr1..."
},
"weight": 1
}
}
Name | Type | Description |
---|---|---|
recipient | The recipient to add along with the corresponding weight. |
Only available to the contract owner/ operator.
Remove a recipient from the distribution.
Rust
JSON
pub enum ExecuteMsg {
RemoveRecipient {
recipient: Recipient,
}
}
{
"remove_recipient":{
"recipient":{
"address":"andr1..."
}
}
Name | Type | Description |
---|---|---|
recipient | The recipient to remove from the list. |
Used to lock the contract for a certain period of time making it unmodifiable in any way. This can serve as a way to ensure for recipients that their weights from the splitter are fixed for a certain amount of time. The time is calculated in seconds.
Only available to the contract owner/operator.
Cannot be called if a lock is already in action.
The minimum time that can be set is 86,400 which is 1 day.
The maximum time that can be set is 31,536,000 which is 1 year.
Rust
JSON
pub enum ExecuteMsg {
UpdateLock {
lock_time: u64,
}
}
{
"update_lock":{
"lock_time": 200000
}
}
Name | Type | Description |
---|---|---|
lock_time | u64 | The time in seconds to lock the contract for. |
Updates the weight of a specific recipient from the list of recipients.
Only available to the contract owner/operator.
Rust
JSON
pub enum ExecuteMsg {
UpdateRecipientWeight {
recipient: AddressWeight,
}
}
{
"update_recipient_weight":{
"recipient":{
"recipient":{
"address":"andr1..."
},
"weight": 1
}
}
Name | Type | Description |
---|---|---|
recipient | The new weight for the recipient. |
Divides any attached funds to the message amongst the recipients list.
A maximum of 5 types of funds can be sent in one send message.
Rust
JSON
pub enum ExecuteMsg {
Send {}
}
{
"send":{}
}
Uses the modules feature.
Queries the current config of the contract.
Rust
JSON
pub enum QueryMsg {
#[returns(GetSplitterConfigResponse)]
GetSplitterConfig {},
}
{
"get_splitter_config":{}
}
Rust
JSON
pub struct GetSplitterConfigResponse {
pub config: Splitter,
}
{
"config":{
"recipients":[
{
"recipient":{
"address":"andr1..."
},
"weight": 1
},
{
"recipient":{
"address":"andr1..."
},
"weight": 4
},
{
"recipient":{
"address":"andr1..."
},
"weight": 12
}
],
"lock": {
"at_time": "1655212973934"
}
}
}
pub struct Splitter {
pub recipients: Vec<AddressWeight>,
pub lock: Expiration,
}
Name | Type | Description |
---|---|---|
recipients | The vector of recipients for the contract. Anytime a Send execute message is sent the amount sent will be divided amongst these recipients depending on their assigned weight. | |
locked | The expiration time of the lock. Will return an epoc time which is equal to the current_time + lock_time taken at the point of setting the lock. (Current time refers to the time the lock was set and not the time now.) |
Queries the user's allocated weight.
Rust
JSON
pub enum QueryMsg {
#[returns(GetUserWeightResponse)]
GetUserWeight {
user: Recipient,
}
}
{
"get_user_weight":{
"user":{
"address":"andr1..."
}
}
}
Name | Type | Description |
---|---|---|
user | Recipient | The user we want to check the weight for. |
pub struct GetUserWeightResponse {
pub weight: Uint128,
pub total_weight: Uint128,
}
Name | Type | Description |
---|---|---|
weight | Uint128 | The weight of the user. |
total_weight | Uint128 | The total weight of the splitter. |