Skip to content

Commit

Permalink
Fix listing fee transfer (#6949)
Browse files Browse the repository at this point in the history
  • Loading branch information
megrogan authored Dec 3, 2024
1 parent 41e1720 commit ce08390
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 7 deletions.
4 changes: 4 additions & 0 deletions backend/canisters/community/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [unreleased]

### Fixed

- Don't supply a fee when BURNing ([#6948](https://github.com/open-chat-labs/open-chat/pull/6948))

## [[2.0.1486](https://github.com/open-chat-labs/open-chat/releases/tag/v2.0.1486-community)] - 2024-12-02

### Changed
Expand Down
5 changes: 3 additions & 2 deletions backend/canisters/community/impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use canister_state_macros::canister_state;
use canister_timer_jobs::TimerJobs;
use chat_events::ChatMetricsInternal;
use community_canister::EventsResponse;
use constants::MINUTE_IN_MS;
use constants::{MINUTE_IN_MS, SNS_LEDGER_CANISTER_ID};
use event_store_producer::{EventStoreClient, EventStoreClientBuilder, EventStoreClientInfo};
use event_store_producer_cdk_runtime::CdkRuntime;
use fire_and_forget_handler::FireAndForgetHandler;
Expand Down Expand Up @@ -141,9 +141,10 @@ impl RuntimeState {
let treasury_share = payment.amount.saturating_sub(owner_share * owner_count);
let amount = treasury_share.saturating_sub(payment.fee);
if amount > 0 {
let is_chat = payment.ledger_canister_id == SNS_LEDGER_CANISTER_ID;
self.data.pending_payments_queue.push(PendingPayment {
amount,
fee: payment.fee,
fee: if is_chat { 0 } else { payment.fee }, // No fee for BURNing
ledger_canister: payment.ledger_canister_id,
recipient: PaymentRecipient::Treasury,
reason: PendingPaymentReason::AccessGate,
Expand Down
4 changes: 4 additions & 0 deletions backend/canisters/group/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [unreleased]

### Fixed

- Don't supply a fee when BURNing ([#6948](https://github.com/open-chat-labs/open-chat/pull/6948))

## [[2.0.1487](https://github.com/open-chat-labs/open-chat/releases/tag/v2.0.1487-group)] - 2024-12-02

### Changed
Expand Down
5 changes: 3 additions & 2 deletions backend/canisters/group/impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use candid::Principal;
use canister_state_macros::canister_state;
use canister_timer_jobs::TimerJobs;
use chat_events::Reader;
use constants::{DAY_IN_MS, HOUR_IN_MS, MINUTE_IN_MS, OPENCHAT_BOT_USER_ID};
use constants::{DAY_IN_MS, HOUR_IN_MS, MINUTE_IN_MS, OPENCHAT_BOT_USER_ID, SNS_LEDGER_CANISTER_ID};
use event_store_producer::{EventStoreClient, EventStoreClientBuilder, EventStoreClientInfo};
use event_store_producer_cdk_runtime::CdkRuntime;
use fire_and_forget_handler::FireAndForgetHandler;
Expand Down Expand Up @@ -149,9 +149,10 @@ impl RuntimeState {
let treasury_share = payment.amount.saturating_sub(owner_share * owner_count);
let amount = treasury_share.saturating_sub(payment.fee);
if amount > 0 {
let is_chat = payment.ledger_canister_id == SNS_LEDGER_CANISTER_ID;
self.data.pending_payments_queue.push(PendingPayment {
amount,
fee: payment.fee,
fee: if is_chat { 0 } else { payment.fee }, // No fee for BURNing
ledger_canister: payment.ledger_canister_id,
recipient: PaymentRecipient::Treasury,
reason: PendingPaymentReason::AccessGate,
Expand Down
4 changes: 4 additions & 0 deletions backend/canisters/registry/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [unreleased]

### Fixed

- Fix listing fee transfer ([#6948](https://github.com/open-chat-labs/open-chat/pull/6948))

## [[2.0.1483](https://github.com/open-chat-labs/open-chat/releases/tag/v2.0.1483-registry)] - 2024-11-29

### Added
Expand Down
39 changes: 38 additions & 1 deletion backend/canisters/registry/impl/src/lifecycle/init.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
use std::time::Duration;

use crate::lifecycle::{init_env, init_state};
use crate::updates::add_token::add_token_impl;
use crate::Data;
use candid::Principal;
use canister_tracing_macros::trace;
use ic_cdk::init;
use registry_canister::init::Args;
use tracing::info;
use tracing::{error, info};
use utils::cycles::init_cycles_dispenser_client;
use utils::env::Environment;

Expand Down Expand Up @@ -34,4 +38,37 @@ fn init(args: Args) {
init_state(env, data, args.wasm_version);

info!(version = %args.wasm_version, "Initialization complete");

ic_cdk_timers::set_timer(Duration::ZERO, add_token);
}

fn add_token() {
ic_cdk::spawn(add_token_inner());

async fn add_token_inner() {
let ledger_canister_id = Principal::from_text("npnnq-naaaa-aaaam-qb7va-cai").unwrap();
let payer = Principal::from_text("icbn4-5qaaa-aaaaf-bp72q-cai").unwrap().into();
let info_url = "https://info.icpswap.com/token/details/npnnq-naaaa-aaaam-qb7va-cai".to_string();
let how_to_buy_url =
"https://app.icpswap.com/swap?input=ryjl3-tyaaa-aaaaa-aaaba-cai&output=npnnq-naaaa-aaaam-qb7va-cai".to_string();
let transaction_url_format = "https://ic.house/token/npnnq-naaaa-aaaam-qb7va-cai".to_string();

let response = add_token_impl(
ledger_canister_id,
Some(payer),
None,
Some(info_url),
Some(how_to_buy_url),
Some(transaction_url_format),
None,
)
.await;

match response {
registry_canister::add_token::Response::Success => {
info!("AWB added");
}
_ => error!("Failed to add AWB: {response:?}"),
}
}
}
4 changes: 2 additions & 2 deletions backend/canisters/registry/impl/src/updates/add_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub(crate) async fn add_sns_token(nervous_system: NervousSystemDetails) {
}

#[allow(clippy::too_many_arguments)]
async fn add_token_impl(
pub(crate) async fn add_token_impl(
ledger_canister_id: CanisterId,
payer: Option<UserId>,
nervous_system: Option<NervousSystemDetails>,
Expand Down Expand Up @@ -115,7 +115,7 @@ async fn add_token_impl(
from: from.into(),
to: SNS_GOVERNANCE_CANISTER_ID.into(),
amount: amount.into(),
fee: Cryptocurrency::CHAT.fee().map(|fee| fee.into()),
fee: None, // No transfer fee for BURNing
memo: Some(MEMO_LIST_TOKEN.to_vec().into()),
created_at_time: Some(now_nanos),
};
Expand Down

0 comments on commit ce08390

Please sign in to comment.