andromeda_finance/weighted_splitter.rs
1use andromeda_std::{
2 amp::recipient::Recipient, andr_exec, andr_instantiate, andr_instantiate_modules, andr_query,
3};
4use cosmwasm_schema::{cw_serde, QueryResponses};
5use cosmwasm_std::Uint128;
6use cw_utils::Expiration;
7
8#[cw_serde]
9pub struct AddressWeight {
10 pub recipient: Recipient,
11 pub weight: Uint128,
12}
13
14#[cw_serde]
15/// A config struct for a `Splitter` contract.
16pub struct Splitter {
17 /// 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.
18 pub recipients: Vec<AddressWeight>,
19 /// Whether or not the contract is currently locked. This restricts updating any config related fields.
20 pub lock: Expiration,
21}
22
23#[andr_instantiate]
24#[andr_instantiate_modules]
25#[cw_serde]
26pub struct InstantiateMsg {
27 /// The vector of recipients for the contract. Anytime a `Send` execute message is
28 /// sent the amount sent will be divided amongst these recipients depending on their assigned weight.
29 pub recipients: Vec<AddressWeight>,
30 pub lock_time: Option<u64>,
31}
32
33#[andr_exec]
34#[cw_serde]
35pub enum ExecuteMsg {
36 /// Update the recipients list. Only executable by the contract owner when the contract is not locked.
37 UpdateRecipients { recipients: Vec<AddressWeight> },
38 /// Update a specific recipient's weight. Only executable by the contract owner when the contract is not locked.
39 UpdateRecipientWeight { recipient: AddressWeight },
40 /// Add a single recipient to the recipient list. Only executable by the contract owner when the contract is not locked.
41 AddRecipient { recipient: AddressWeight },
42 /// Remove a single recipient from the recipient list. Only executable by the contract owner when the contract is not locked.
43 RemoveRecipient { recipient: Recipient },
44 /// Used to lock/unlock the contract allowing the config to be updated.
45 UpdateLock { lock_time: u64 },
46 /// Divides any attached funds to the message amongst the recipients list.
47 Send {},
48}
49
50#[andr_query]
51#[cw_serde]
52#[derive(QueryResponses)]
53pub enum QueryMsg {
54 /// The current config of the Splitter contract
55 #[returns(GetSplitterConfigResponse)]
56 GetSplitterConfig {},
57 /// Gets user's allocated weight
58 #[returns(GetUserWeightResponse)]
59 GetUserWeight { user: Recipient },
60}
61
62#[cw_serde]
63pub struct GetSplitterConfigResponse {
64 pub config: Splitter,
65}
66/// In addition to returning a specific recipient's weight, this function also returns the total weight of all recipients.
67/// This serves to put the user's weight into perspective.
68#[cw_serde]
69pub struct GetUserWeightResponse {
70 pub weight: Uint128,
71 pub total_weight: Uint128,
72}