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

Add Airdrop Bot #6088

Merged
merged 29 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
882deaf
Airdrop bot part 1
megrogan Jul 22, 2024
a996297
candid
megrogan Jul 22, 2024
2eca588
WIP
megrogan Jul 23, 2024
97df0d4
Merge remote-tracking branch 'origin/master' into airdrop_bot
megrogan Jul 23, 2024
802f341
Move into canisters folder
megrogan Jul 23, 2024
0285238
Install Airdrop Bot
megrogan Jul 23, 2024
01ad02b
Merge branch 'master' into airdrop_bot
megrogan Jul 23, 2024
aa6ac51
CHANGELOG
megrogan Jul 23, 2024
0c289ec
Merge branch 'airdrop_bot' of github.com:dfinity-lab/open-chat into a…
megrogan Jul 23, 2024
5f770f3
cargo clippy --tests
megrogan Jul 23, 2024
00c4a65
Start integration tests
megrogan Jul 23, 2024
98c3425
WIP
megrogan Jul 24, 2024
fc38934
Merge remote-tracking branch 'origin/master' into airdrop_bot
megrogan Jul 24, 2024
d8558f9
WIP
megrogan Jul 24, 2024
f047a22
WIP
megrogan Jul 25, 2024
14d1e52
WIP
megrogan Jul 25, 2024
56d7599
Merge remote-tracking branch 'origin/master' into airdrop_bot
megrogan Jul 25, 2024
76d0e66
WIP
megrogan Jul 26, 2024
69dde4b
Merge remote-tracking branch 'origin/master' into airdrop_bot
megrogan Jul 26, 2024
55faf1d
Initialize airdrop_bot_canister_id
megrogan Jul 26, 2024
7338c3e
Merge remote-tracking branch 'origin/master' into airdrop_bot
megrogan Jul 26, 2024
a4a132f
Fix integration test
megrogan Jul 26, 2024
6ce2eb5
Remove integration test debug tracing
megrogan Jul 26, 2024
661d81e
Download all
megrogan Jul 26, 2024
da341fc
Improve integration test
megrogan Jul 26, 2024
08d2e59
Clippy
megrogan Jul 26, 2024
ba4a2ee
typo
megrogan Jul 26, 2024
30bc4ed
Merge branch 'master' into airdrop_bot
megrogan Jul 26, 2024
db1e685
Merge branch 'master' into airdrop_bot
hpeebles Jul 26, 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
68 changes: 68 additions & 0 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ members = [
"backend/tools/canister_installer",
"backend/tools/canister_upgrade_proposal_builder",
"backend/tools/canister_upgrader",
"backend/canisters/airdrop_bot/api",
"backend/canisters/airdrop_bot/client",
"backend/canisters/airdrop_bot/impl",
"backend/canisters/community/api",
"backend/canisters/community/c2c_client",
"backend/canisters/community/impl",
Expand Down
10 changes: 10 additions & 0 deletions backend/canisters/airdrop_bot/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [unreleased]

### Added

- Add Airdrop Bot ([#6088](https://github.com/open-chat-labs/open-chat/pull/6088))
15 changes: 15 additions & 0 deletions backend/canisters/airdrop_bot/api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "airdrop_bot_canister"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
bot_api = { path = "../../../bots/api" }
candid = { workspace = true }
candid_gen = { path = "../../../libraries/candid_gen" }
serde = { workspace = true }
user_canister = { path = "../../user/api" }
user_index_canister = { path = "../../user_index/api" }
types = { path = "../../../libraries/types" }
37 changes: 37 additions & 0 deletions backend/canisters/airdrop_bot/api/can.did
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import "../../../libraries/types/can.did";

type SetAvatarArgs = record {
avatar : opt Document;
};

type SetAvatarResponse = variant {
Success;
AvatarTooBig : FieldTooLongResult;
};

type SetAirdropArgs = record {
community_id : CommunityId;
channel_id : ChannelId;
start : TimestampMillis;
main_chat_fund : nat;
main_chit_band : nat32;
lottery_prizes : vec nat;
lottery_chit_band : nat32;
};

type CancelAirdropResponse = variant {
Success;
};

type SetAirdropResponse = variant {
Success;
ChannelUsed;
InThePast;
ClashesWithPrevious;
};

service : {
set_avatar : (SetAvatarArgs) -> (SetAvatarResponse);
set_airdrop : (SetAirdropArgs) -> (SetAirdropResponse);
cancel_airdrop : (EmptyArgs) -> (CancelAirdropResponse);
};
5 changes: 5 additions & 0 deletions backend/canisters/airdrop_bot/api/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mod lifecycle;
mod updates;

pub use lifecycle::*;
pub use updates::*;
13 changes: 13 additions & 0 deletions backend/canisters/airdrop_bot/api/src/lifecycle/init.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use candid::{CandidType, Principal};
use serde::{Deserialize, Serialize};
use types::{BuildVersion, CanisterId};

#[derive(CandidType, Serialize, Deserialize, Debug)]
pub struct Args {
pub user_index_canister_id: CanisterId,
pub local_user_index_canister_id: CanisterId,
pub chat_ledger_canister_id: CanisterId,
pub admins: Vec<Principal>,
pub wasm_version: BuildVersion,
pub test_mode: bool,
}
2 changes: 2 additions & 0 deletions backend/canisters/airdrop_bot/api/src/lifecycle/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod init;
pub mod post_upgrade;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use candid::CandidType;
use serde::{Deserialize, Serialize};
use types::BuildVersion;

#[derive(CandidType, Serialize, Deserialize, Debug)]
pub struct Args {
pub wasm_version: BuildVersion,
}
11 changes: 11 additions & 0 deletions backend/canisters/airdrop_bot/api/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use candid_gen::generate_candid_method;

#[allow(deprecated)]
fn main() {
generate_candid_method!(airdrop_bot, set_avatar, update);
generate_candid_method!(airdrop_bot, set_airdrop, update);
generate_candid_method!(airdrop_bot, cancel_airdrop, update);

candid::export_service!();
std::print!("{}", __export_service());
}
10 changes: 10 additions & 0 deletions backend/canisters/airdrop_bot/api/src/updates/cancel_airdrop.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use candid::CandidType;
use serde::{Deserialize, Serialize};
use types::Empty;

pub type Args = Empty;

#[derive(CandidType, Serialize, Deserialize, Debug)]
pub enum Response {
Success,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub use bot_api::handle_direct_message::{Response::*, *};
4 changes: 4 additions & 0 deletions backend/canisters/airdrop_bot/api/src/updates/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pub mod cancel_airdrop;
pub mod handle_direct_message;
pub mod set_airdrop;
pub mod set_avatar;
22 changes: 22 additions & 0 deletions backend/canisters/airdrop_bot/api/src/updates/set_airdrop.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use candid::CandidType;
use serde::{Deserialize, Serialize};
use types::{ChannelId, CommunityId, TimestampMillis};

#[derive(CandidType, Serialize, Deserialize, Debug)]
pub struct Args {
pub community_id: CommunityId,
pub channel_id: ChannelId,
pub start: TimestampMillis,
pub main_chat_fund: u128,
pub main_chit_band: u32,
pub lottery_prizes: Vec<u128>,
pub lottery_chit_band: u32,
}

#[derive(CandidType, Serialize, Deserialize, Debug)]
pub enum Response {
Success,
ChannelUsed,
InThePast,
ClashesWithPrevious,
}
15 changes: 15 additions & 0 deletions backend/canisters/airdrop_bot/api/src/updates/set_avatar.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use candid::CandidType;
use serde::{Deserialize, Serialize};
use std::fmt::Debug;
use types::{Document, FieldTooLongResult};

#[derive(CandidType, Serialize, Deserialize, Debug)]
pub struct Args {
pub avatar: Option<Document>,
}

#[derive(CandidType, Serialize, Deserialize, Debug)]
pub enum Response {
Success,
AvatarTooBig(FieldTooLongResult),
}
6 changes: 6 additions & 0 deletions backend/canisters/airdrop_bot/canister_ids.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"airdrop_bot": {
"ic": "wznbi-caaaa-aaaar-anvea-cai",
"ic_test": "uuw5d-uiaaa-aaaar-anzeq-cai"
}
}
13 changes: 13 additions & 0 deletions backend/canisters/airdrop_bot/client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "airdrop_bot_canister_client"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
candid = { workspace = true }
canister_client = { path = "../../../libraries/canister_client" }
ic-agent = { workspace = true }
airdrop_bot_canister = { path = "../api" }
types = { path = "../../../libraries/types" }
7 changes: 7 additions & 0 deletions backend/canisters/airdrop_bot/client/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use airdrop_bot_canister::*;
use canister_client::generate_update_call;

// Queries

// Updates
generate_update_call!(set_avatar);
46 changes: 46 additions & 0 deletions backend/canisters/airdrop_bot/impl/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
[package]
name = "airdrop_bot_canister_impl"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[lib]
path = "src/lib.rs"
crate-type = ["cdylib"]

[dependencies]
airdrop_bot_canister = { path = "../api" }
candid = { workspace = true }
canister_api_macros = { path = "../../../libraries/canister_api_macros" }
canister_logger = { path = "../../../libraries/canister_logger" }
canister_state_macros = { path = "../../../libraries/canister_state_macros" }
canister_tracing_macros = { path = "../../../libraries/canister_tracing_macros" }
community_canister_c2c_client = { path = "../../community/c2c_client" }
community_canister = { path = "../../community/api" }
futures = { workspace = true }
http_request = { path = "../../../libraries/http_request" }
ic-cdk = { workspace = true }
ic-cdk-timers = { workspace = true }
ic-ledger-types = { workspace = true }
ic-stable-structures = { workspace = true }
icrc_ledger_canister_c2c_client = { path = "../../../external_canisters/icrc_ledger/c2c_client" }
icrc-ledger-types = { workspace = true }
local_user_index_canister_c2c_client = { path = "../../local_user_index/c2c_client" }
local_user_index_canister = { path = "../../local_user_index/api" }
msgpack = { path = "../../../libraries/msgpack" }
rand = { workspace = true }
serde = { workspace = true }
serde_bytes = { workspace = true }
serde_json = { workspace = true }
serializer = { path = "../../../libraries/serializer" }
stable_memory = { path = "../../../libraries/stable_memory" }
testing = { path = "../../../libraries/testing" }
time = { workspace = true, features = ["macros", "formatting"] }
tracing = { workspace = true }
types = { path = "../../../libraries/types" }
user_canister_c2c_client = { path = "../../user/c2c_client" }
user_canister = { path = "../../user/api" }
user_index_canister_c2c_client = { path = "../../user_index/c2c_client" }
user_index_canister = { path = "../../user_index/api" }
utils = { path = "../../../libraries/utils" }
9 changes: 9 additions & 0 deletions backend/canisters/airdrop_bot/impl/src/guards.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use crate::read_state;

pub fn caller_is_admin() -> Result<(), String> {
if read_state(|state| state.is_caller_admin()) {
Ok(())
} else {
Err("Caller is not an admin".to_string())
}
}
Loading
Loading