Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add cw20 support for splitter #703

Merged
merged 35 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
1d78861
feat: optional config for splitter send
joemonem Dec 4, 2024
3b4b8eb
feat: optional config for weighted distribution splitter
joemonem Dec 4, 2024
f942549
feat: optional config for set amount splitter
joemonem Dec 4, 2024
15cd988
chore: version bumps
joemonem Dec 4, 2024
54ff73e
test: send for weighted distribution splitter
joemonem Dec 4, 2024
f393e9d
feat: default recipient for additional funds in splitter
joemonem Dec 4, 2024
726601c
feat: default recipient for additional funds in weighted distribution…
joemonem Dec 4, 2024
6c7ef64
chore: changelog entry
joemonem Dec 4, 2024
6436ada
test: add config test case in splitter integration test
joemonem Dec 4, 2024
a26bedf
ref: validate config in splitter
joemonem Dec 4, 2024
39bed13
fix: clippy
joemonem Dec 4, 2024
2c9bd09
fix: allow removing default recipient, adjust default recipient in we…
joemonem Dec 5, 2024
e63c574
feat: default recipient for set amount splitter
joemonem Dec 5, 2024
731997e
fix: merge conflicts with splitter-send-config branch
joemonem Dec 5, 2024
ccedff1
feat: add cw20 support for splitter + integration tests
joemonem Dec 5, 2024
17f6ffd
chore: version bump and changelog entry
joemonem Dec 6, 2024
66da425
feat: Splitter Default Recipient (#698)
joemonem Dec 6, 2024
a833340
chore: changelog adjustment
joemonem Dec 6, 2024
cc95889
Merge branch 'splitter-send-config' of https://github.com/andromedapr…
joemonem Dec 6, 2024
b6d1123
merge with splitter-send-config
joemonem Dec 6, 2024
bfbfa15
ref: use generate_direct_msg where applicable
joemonem Dec 6, 2024
757be4b
Merge branch 'development' into splitter-cw20
crnbarr93 Dec 6, 2024
e5b794a
test: fix tests
crnbarr93 Dec 6, 2024
c17f02f
chore: fixed beta tag to be "b"
crnbarr93 Dec 6, 2024
75eef77
feat: cw20 support for set-amount-splitter
joemonem Dec 9, 2024
ebd366a
Merge branch 'main' into splitter-cw20
crnbarr93 Dec 9, 2024
158a5a9
wip: rstest for set-amount-splitter
joemonem Dec 10, 2024
2fb44b9
Merge branch 'splitter-cw20' of https://github.com/andromedaprotocol/…
joemonem Dec 10, 2024
bd54220
fix + test: refund recipient fixed, rstest integration tests for set_…
joemonem Dec 10, 2024
f51d97f
test: rstest for splitter integration test
joemonem Dec 10, 2024
c1a46bb
Merge branch 'main' into splitter-cw20
joemonem Dec 10, 2024
6abc865
chore: version bump set amount splitter
joemonem Dec 11, 2024
2947cd4
Merge branch 'splitter-cw20' of https://github.com/andromedaprotocol/…
joemonem Dec 11, 2024
fcc5541
ref: simplify init in splitter and set amount splitter
joemonem Dec 11, 2024
abe11b2
fix: version change
joemonem Dec 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added Validator Staking ADO [(#330)](https://github.com/andromedaprotocol/andromeda-core/pull/330)
- Added Restake and Redelegate to Validator Staking [(#622)](https://github.com/andromedaprotocol/andromeda-core/pull/622)
- Added andromeda-math and andromeda-account packages[(#672)](https://github.com/andromedaprotocol/andromeda-core/pull/672)
- Added optional config for Send in Splitter contracts [(#686)](https://github.com/andromedaprotocol/andromeda-core/pull/686)
- Added CW20 suppport in Splitter contracts [(#703)](https://github.com/andromedaprotocol/andromeda-core/pull/703)
joemonem marked this conversation as resolved.
Show resolved Hide resolved


### Changed
Expand Down
8 changes: 5 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion contracts/finance/andromeda-set-amount-splitter/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "andromeda-set-amount-splitter"
version = "1.0.3-beta"
version = "1.1.0-beta"
edition = "2021"
rust-version = "1.75.0"

Expand Down
75 changes: 69 additions & 6 deletions contracts/finance/andromeda-set-amount-splitter/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use andromeda_finance::{
};
use andromeda_std::{
ado_base::{InstantiateMsg as BaseInstantiateMsg, MigrateMsg},
amp::messages::AMPPkt,
amp::{messages::AMPPkt, Recipient},
common::{actions::call_action, encode_binary, expiration::Expiry, Milliseconds},
error::ContractError,
};
Expand Down Expand Up @@ -52,13 +52,15 @@ pub fn instantiate(
Splitter {
recipients: msg.recipients.clone(),
lock: lock_time.get_time(&env.block),
default_recipient: msg.default_recipient.clone(),
}
}
None => {
Splitter {
recipients: msg.recipients.clone(),
// If locking isn't desired upon instantiation, it's automatically set to 0
lock: Milliseconds::default(),
default_recipient: msg.default_recipient.clone(),
}
}
};
Expand Down Expand Up @@ -124,7 +126,10 @@ pub fn handle_execute(mut ctx: ExecuteContext, msg: ExecuteMsg) -> Result<Respon
let res = match msg {
ExecuteMsg::UpdateRecipients { recipients } => execute_update_recipients(ctx, recipients),
ExecuteMsg::UpdateLock { lock_time } => execute_update_lock(ctx, lock_time),
ExecuteMsg::Send {} => execute_send(ctx),
ExecuteMsg::UpdateDefaultRecipient { recipient } => {
execute_default_recipient(ctx, recipient)
}
ExecuteMsg::Send { config } => execute_send(ctx, config),
_ => ADOContract::default().execute(ctx, msg),
}?;
Ok(res
Expand All @@ -133,7 +138,53 @@ pub fn handle_execute(mut ctx: ExecuteContext, msg: ExecuteMsg) -> Result<Respon
.add_events(action_response.events))
}

fn execute_send(ctx: ExecuteContext) -> Result<Response, ContractError> {
fn execute_default_recipient(
ctx: ExecuteContext,
recipient: Option<Recipient>,
) -> Result<Response, ContractError> {
let ExecuteContext {
deps, info, env, ..
} = ctx;

nonpayable(&info)?;

ensure!(
ADOContract::default().is_owner_or_operator(deps.storage, info.sender.as_str())?,
ContractError::Unauthorized {}
);

let mut splitter = SPLITTER.load(deps.storage)?;

// Can't call this function while the lock isn't expired
ensure!(
splitter.lock.is_expired(&env.block),
ContractError::ContractLocked {}
);

if let Some(ref recipient) = recipient {
recipient.validate(&deps.as_ref())?;
}
splitter.default_recipient = recipient;

SPLITTER.save(deps.storage, &splitter)?;

Ok(Response::default().add_attributes(vec![
attr("action", "update_default_recipient"),
attr(
"recipient",
splitter
.default_recipient
.map_or("no default recipient".to_string(), |r| {
r.address.to_string()
}),
),
]))
}

fn execute_send(
ctx: ExecuteContext,
config: Option<Vec<AddressAmount>>,
) -> Result<Response, ContractError> {
let ExecuteContext { deps, info, .. } = ctx;

ensure!(
Expand All @@ -158,8 +209,13 @@ fn execute_send(ctx: ExecuteContext) -> Result<Response, ContractError> {
);
denom_set.insert(coin.denom);
}

let splitter = SPLITTER.load(deps.storage)?;
let splitter_recipients = if let Some(config) = config {
validate_recipient_list(deps.as_ref(), config.clone())?;
config
} else {
splitter.recipients
};

let mut msgs: Vec<SubMsg> = Vec::new();
let mut amp_funds: Vec<Coin> = Vec::new();
Expand All @@ -171,7 +227,7 @@ fn execute_send(ctx: ExecuteContext) -> Result<Response, ContractError> {
let mut remainder_funds = coin.amount;
let denom = coin.denom;

for recipient in &splitter.recipients {
for recipient in splitter_recipients.clone() {
// Find the recipient's corresponding denom for the current iteration of the sent funds
let recipient_coin = recipient
.coins
Expand Down Expand Up @@ -200,8 +256,15 @@ fn execute_send(ctx: ExecuteContext) -> Result<Response, ContractError> {

// Refund message for sender
if !remainder_funds.is_zero() {
let remainder_recipient = splitter
.default_recipient
.clone()
.unwrap_or(Recipient::new(info.sender.to_string(), None));
let msg = SubMsg::new(CosmosMsg::Bank(BankMsg::Send {
to_address: info.sender.clone().into_string(),
to_address: remainder_recipient
.address
.get_raw_address(&deps.as_ref())?
.into_string(),
amount: coins(remainder_funds.u128(), denom),
}));
msgs.push(msg);
Expand Down
28 changes: 21 additions & 7 deletions contracts/finance/andromeda-set-amount-splitter/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use crate::contract::{execute, instantiate, query, reply};
use andromeda_finance::set_amount_splitter::{AddressAmount, ExecuteMsg, InstantiateMsg, QueryMsg};
use andromeda_std::common::expiration::Expiry;
use andromeda_std::{amp::Recipient, common::expiration::Expiry};
use andromeda_testing::{
mock::MockApp, mock_ado, mock_contract::ExecuteResult, MockADO, MockContract,
};
Expand All @@ -21,16 +21,28 @@ impl MockSetAmountSplitter {
kernel_address: impl Into<String>,
lock_time: Option<Expiry>,
owner: Option<String>,
default_recipient: Option<Recipient>,
) -> Self {
let msg =
mock_set_amount_splitter_instantiate_msg(recipients, kernel_address, lock_time, owner);
let msg = mock_set_amount_splitter_instantiate_msg(
recipients,
kernel_address,
lock_time,
owner,
default_recipient,
);
let res = app.instantiate_contract(code_id, sender, &msg, &[], "Andromeda Splitter", None);

Self(res.unwrap())
}

pub fn execute_send(&self, app: &mut MockApp, sender: Addr, funds: &[Coin]) -> ExecuteResult {
let msg = mock_set_amount_splitter_send_msg();
pub fn execute_send(
&self,
app: &mut MockApp,
sender: Addr,
funds: &[Coin],
config: Option<Vec<AddressAmount>>,
) -> ExecuteResult {
let msg = mock_set_amount_splitter_send_msg(config);

self.execute(app, &msg, sender, funds)
}
Expand All @@ -46,15 +58,17 @@ pub fn mock_set_amount_splitter_instantiate_msg(
kernel_address: impl Into<String>,
lock_time: Option<Expiry>,
owner: Option<String>,
default_recipient: Option<Recipient>,
) -> InstantiateMsg {
InstantiateMsg {
recipients,
lock_time,
kernel_address: kernel_address.into(),
owner,
default_recipient,
}
}

pub fn mock_set_amount_splitter_send_msg() -> ExecuteMsg {
ExecuteMsg::Send {}
pub fn mock_set_amount_splitter_send_msg(config: Option<Vec<AddressAmount>>) -> ExecuteMsg {
ExecuteMsg::Send { config }
}
Loading
Loading