Andromeda
Search
⌃K

Weighted Distribution Splitter

Introduction

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. Whenever the splitter receives funds by executing a send it automatically splits the funds to the defined recipients. The splitter can be locked for a specified time as a kind of insurance for recipients that their weights will not be changed for a certain period of time.

Example:

On instantiation, the following weights are assigned:
  • User A weight: 5
  • User B weight: 3
  • User C weight: 4
Then the total weight is 12 and A receives 5/12 of the funds, B receives 3/12 of the funds and C receives 4/12 of the funds. If a recipient is then added, the total weight is increased and the percentages are recalculated.
The contract supports modules to extend it's functionality.
ado_type: weighted-distribution-splitter

InstantiateMsg

A maximum of 100 recipients can be set.
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 struct InstantiateMsg {
pub recipients: Vec<AddressWeight>,
pub lock_time: Option<u64>,
pub modules: Option<Vec<Module>>,
}
{
"recipients":[
{
"recipient":{
"addr":"andr1..."
},
"weight": 4
},
{
"recipient":{
"addr":"andr1..."
},
"weight": 7
},
{
"recipient":{
"addr":"andr1..."
},
"weight": 2
}
]
}
Name
Type
Description
recipients
Vec<AddressWeight>
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.
modules
Option<Vec<Module>>
An optional vector of Andromeda Modules that can be attached to the contract."address-list" module can be added.

AddressWeight

struct containing the recipient of the funds and the assigned weight for that recipient.
pub struct AddressWeight {
pub recipient: Recipient,
pub weight: Uint128,
}

ExecuteMsg

UpdateRecipients

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":{
"addr":"andr1..."
},
"weight": 1
},
{
"recipient":{
"addr":"andr1..."
},
"weight": 4
},
{
"recipient":{
"addr":"andr1..."
},
"weight": 12
}
]
}
}
Name
Type
Description
recipients
The new recipients of the split funds with their assigned weights.

AddRecipient

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":{
"addr":"andr1..."
},
"weight": 1
}
}
Name
Type
Description
recipient
The recipient to add along with the corresponding weight.

RemoveRecipient

Only available to the contract owner/ operator.
Remove a recipient from the distribution.
Rust
JSON
pub enum ExecuteMsg {
RemoveRecipient {
recipient: Recipient,
}
}
{
"remove_recipient":{
"recipient":{
"addr":"andr1..."
}
}
Name
Type
Description
recipient
Recipient
The recipient to remove from the list.

UpdateLock

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.
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.

UpdateRecipientWeight

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":{
"addr":"andr1..."
},
"weight": 1
}
}
Name
Type
Description
recipient
The new weight for the recipient.

Send

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":{}
}

AndrReceive

This contract uses the modules feature
The rest of the executes can be found in the AndrReceive section.

QueryMsg

GetSplitterConfig

Queries the current config of the contract.
Rust
JSON
pub enum QueryMsg {
#[returns(GetSplitterConfigResponse)]
GetSplitterConfig {},
}
{
"get_splitter_config":{}
}

GetSplitterConfigResponse

Rust
JSON
pub struct GetSplitterConfigResponse {
pub config: Splitter,
}
{
"config":{
"recipients":[
{
"recipient":{
"addr":"andr1..."
},
"weight": 1
},
{
"recipient":{
"addr":"andr1..."
},
"weight": 4
},
{
"recipient":{
"addr":"andr1..."
},
"weight": 12
}
],
"lock": {
"at_time": "1655212973"
}
}
}

Splitter

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.)

GetUserWeight

Queries the user's allocated weight.
Rust
JSON
pub enum QueryMsg {
#[returns(GetUserWeightResponse)]
GetUserWeight {
user: Recipient,
}
}
{
"get_user_weight":{
"user":{
"addr":"andr1..."
}
}
}
Name
Type
Description
user
Recipient
The user we want to check the weight for.

GetUserWeightResponse

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.

AndrQuery

A set of base queries common to all Andromeda ADOs. Check AndrQuery.