diff --git a/Cargo.lock b/Cargo.lock index d001e363c8..a140d8300f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -140,7 +140,9 @@ dependencies = [ "ic-ledger-types", "ic-stable-structures", "icrc-ledger-types", + "icrc_ledger_canister", "icrc_ledger_canister_c2c_client", + "ledger_utils", "local_user_index_canister", "local_user_index_canister_c2c_client", "msgpack", diff --git a/backend/canisters/airdrop_bot/CHANGELOG.md b/backend/canisters/airdrop_bot/CHANGELOG.md index 5fc2da6919..97548d4b6f 100644 --- a/backend/canisters/airdrop_bot/CHANGELOG.md +++ b/backend/canisters/airdrop_bot/CHANGELOG.md @@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Serialize large integers as strings when using MessagePack ([#6315](https://github.com/open-chat-labs/open-chat/pull/6315)) - Increase max stable memory read / write buffer size ([#6440](https://github.com/open-chat-labs/open-chat/pull/6440)) - Introduce `TimerJobQueue` and use it for distributing airdrops ([#6498](https://github.com/open-chat-labs/open-chat/pull/6498)) +- Refund user who sent tokens to the AirdropBot ([#6521](https://github.com/open-chat-labs/open-chat/pull/6521)) ## [[2.0.1314](https://github.com/open-chat-labs/open-chat/releases/tag/v2.0.1314-airdrop_bot)] - 2024-09-02 diff --git a/backend/canisters/airdrop_bot/impl/Cargo.toml b/backend/canisters/airdrop_bot/impl/Cargo.toml index fe08e1123a..f8e37a094d 100644 --- a/backend/canisters/airdrop_bot/impl/Cargo.toml +++ b/backend/canisters/airdrop_bot/impl/Cargo.toml @@ -24,8 +24,10 @@ ic-cdk = { workspace = true } ic-cdk-timers = { workspace = true } ic-ledger-types = { workspace = true } ic-stable-structures = { workspace = true } +icrc_ledger_canister = { path = "../../../external_canisters/icrc_ledger/api" } icrc_ledger_canister_c2c_client = { path = "../../../external_canisters/icrc_ledger/c2c_client" } icrc-ledger-types = { workspace = true } +ledger_utils = { path = "../../../libraries/ledger_utils" } 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" } diff --git a/backend/canisters/airdrop_bot/impl/src/lifecycle/post_upgrade.rs b/backend/canisters/airdrop_bot/impl/src/lifecycle/post_upgrade.rs index 55ff5178da..ed27769947 100644 --- a/backend/canisters/airdrop_bot/impl/src/lifecycle/post_upgrade.rs +++ b/backend/canisters/airdrop_bot/impl/src/lifecycle/post_upgrade.rs @@ -2,11 +2,16 @@ use crate::lifecycle::{init_env, init_state}; use crate::memory::get_upgrades_memory; use crate::Data; use airdrop_bot_canister::post_upgrade::Args; +use candid::Principal; use canister_logger::LogEntry; use canister_tracing_macros::trace; use ic_cdk::post_upgrade; +use icrc_ledger_canister::icrc1_transfer; +use ledger_utils::convert_to_subaccount; use stable_memory::get_reader; +use std::time::Duration; use tracing::info; +use types::Cryptocurrency::CHAT; #[post_upgrade] #[trace] @@ -22,4 +27,22 @@ fn post_upgrade(args: Args) { init_state(env, data, args.wasm_version); info!(version = %args.wasm_version, "Post-upgrade complete"); + + ic_cdk_timers::set_timer(Duration::ZERO, || ic_cdk::spawn(refund_user())); +} + +async fn refund_user() { + let principal = Principal::from_text("ioprk-aqaaa-aaaaf-atcza-cai").unwrap(); + let _ = icrc_ledger_canister_c2c_client::icrc1_transfer( + CHAT.ledger_canister_id().unwrap(), + &icrc1_transfer::Args { + from_subaccount: Some(convert_to_subaccount(&principal).0), + to: principal.into(), + fee: None, + created_at_time: None, + memo: None, + amount: 1825800000u64.into(), + }, + ) + .await; }