Skip to content

Commit

Permalink
Refund user who sent tokens to the AirdropBot (#6521)
Browse files Browse the repository at this point in the history
  • Loading branch information
hpeebles authored Oct 7, 2024
1 parent 4bb9da1 commit d0f04be
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions backend/canisters/airdrop_bot/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions backend/canisters/airdrop_bot/impl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
23 changes: 23 additions & 0 deletions backend/canisters/airdrop_bot/impl/src/lifecycle/post_upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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;
}

0 comments on commit d0f04be

Please sign in to comment.