Skip to content

Commit

Permalink
Merge branch 'master' into edit-mode
Browse files Browse the repository at this point in the history
  • Loading branch information
julianjelfs authored Feb 2, 2024
2 parents b8581a5 + 615a2d0 commit 27cfde8
Show file tree
Hide file tree
Showing 115 changed files with 2,072 additions and 684 deletions.
10 changes: 6 additions & 4 deletions .github/workflows/pre_release_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Wait for wasms to be built
uses: lewagon/[email protected]
with:
ref: master
check-name: "Push canister wasms"
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Download canister wasms
run: ./scripts/download-all-canister-wasms.sh $GITHUB_REF_NAME
continue-on-error: true
- name: Build canister wasms
if: ${{ failure() }}
uses: ./.github/workflows/push_canister_wasms.yaml
- uses: actions-rs/toolchain@v1
with:
profile: minimal
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.dfx/
.vscode/
target/
dist/
node_modules/
Expand All @@ -15,4 +16,4 @@ msg.json
notes.md
notification.did
summary.md
temp.did
temp.did
27 changes: 0 additions & 27 deletions .vscode/settings.json

This file was deleted.

6 changes: 6 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions backend/canister_installer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ async fn install_service_canisters_impl(

let translations_canister_wasm = get_canister_wasm(CanisterName::Translations, version);
let translations_init_args = translations_canister::init::Args {
deployment_operators: vec![principal],
user_index_canister_id: canister_ids.user_index,
cycles_dispenser_canister_id: canister_ids.cycles_dispenser,
wasm_version: version,
test_mode,
Expand Down
1 change: 1 addition & 0 deletions backend/canisters/community/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Changed

- Hack to cater for SNEED's unique handling of transfer fees ([#5280](https://github.com/open-chat-labs/open-chat/pull/5280))
- Add `minimum_yes_proportion_of_total` to SNS proposals ([#5284](https://github.com/open-chat-labs/open-chat/pull/5284))

## [[2.0.1021](https://github.com/open-chat-labs/open-chat/releases/tag/v2.0.1021-community)] - 2024-01-24

Expand Down
1 change: 1 addition & 0 deletions backend/canisters/group/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Changed

- Hack to cater for SNEED's unique handling of transfer fees ([#5280](https://github.com/open-chat-labs/open-chat/pull/5280))
- Add `minimum_yes_proportion_of_total` to SNS proposals ([#5284](https://github.com/open-chat-labs/open-chat/pull/5284))

## [[2.0.1022](https://github.com/open-chat-labs/open-chat/releases/tag/v2.0.1022-group)] - 2024-01-24

Expand Down
1 change: 1 addition & 0 deletions backend/canisters/identity/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Implement ability to update user principals ([#5220](https://github.com/open-chat-labs/open-chat/pull/5220))
- Sync user principals from the UserIndex canister ([#5264](https://github.com/open-chat-labs/open-chat/pull/5264))
- Implement `migrate_legacy_principal` ([#5274](https://github.com/open-chat-labs/open-chat/pull/5274))
- Expose count of `legacy_principals` in metrics ([#5311](https://github.com/open-chat-labs/open-chat/pull/5311))
2 changes: 2 additions & 0 deletions backend/canisters/identity/impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ impl RuntimeState {
cycles_balance: self.env.cycles_balance(),
wasm_version: WASM_VERSION.with_borrow(|v| **v),
git_commit_id: utils::git::git_commit_id().to_string(),
legacy_principals: self.data.legacy_principals.len() as u32,
canister_ids: CanisterIds {
user_index: self.data.user_index_canister_id,
cycles_dispenser: self.data.cycles_dispenser_canister_id,
Expand Down Expand Up @@ -114,6 +115,7 @@ pub struct Metrics {
pub cycles_balance: Cycles,
pub wasm_version: BuildVersion,
pub git_commit_id: String,
pub legacy_principals: u32,
pub canister_ids: CanisterIds,
}

Expand Down
4 changes: 4 additions & 0 deletions backend/canisters/local_user_index/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [unreleased]

### Changed

- Add `timestamp` to `chat_events` responses ([#5309](https://github.com/open-chat-labs/open-chat/pull/5309))

## [[2.0.1031](https://github.com/open-chat-labs/open-chat/releases/tag/v2.0.1031-local_user_index)] - 2024-01-25

### Added
Expand Down
17 changes: 11 additions & 6 deletions backend/canisters/local_user_index/api/can.did
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ type ChatEventsArgs = record {
requests : vec ChatEventsArgsInner;
};

type EventsContext = variant {
Direct : UserId;
Group : record { ChatId; opt MessageIndex; };
Channel : record { CommunityId; ChannelId; opt MessageIndex};
};

type ChatEventsArgsInner = record {
context : variant {
Direct : UserId;
Group : record { ChatId; opt MessageIndex; };
Channel : record { CommunityId; ChannelId; opt MessageIndex};
};
context : EventsContext;
args: variant {
Page : record {
start_index: EventIndex;
Expand All @@ -30,7 +32,10 @@ type ChatEventsArgsInner = record {
};

type ChatEventsResponse = variant {
Success : vec ChatEventsResponseInner;
Success : record {
responses: vec ChatEventsResponseInner;
timestamp: TimestampMillis;
};
};

type ChatEventsResponseInner = variant {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,13 @@ pub struct EventsWindowArgs {

#[derive(CandidType, Serialize, Deserialize, Debug)]
pub enum Response {
Success(Vec<EventsResponse>),
Success(SuccessResult),
}

#[derive(CandidType, Serialize, Deserialize, Debug)]
pub struct SuccessResult {
pub responses: Vec<EventsResponse>,
pub timestamp: TimestampMillis,
}

#[derive(CandidType, Serialize, Deserialize, Debug)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,20 @@ use types::UserId;

#[query(composite = true, guard = "caller_is_openchat_user")]
async fn chat_events(args: Args) -> Response {
let user = read_state(|state| state.calling_user());
let (user, now) = read_state(|state| (state.calling_user(), state.env.now()));

let futures: Vec<_> = args
.requests
.into_iter()
.map(|r| make_c2c_call(r, user.principal, user.user_id))
.collect();

let results = futures::future::join_all(futures).await;
let responses = futures::future::join_all(futures).await;

Success(results)
Success(SuccessResult {
responses,
timestamp: now,
})
}

async fn make_c2c_call(events_args: EventsArgs, principal: Principal, user_id: UserId) -> EventsResponse {
Expand Down
12 changes: 12 additions & 0 deletions backend/canisters/market_maker/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,21 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [unreleased]

### Added

- Add `ICDex_V2` so that we can run both while making the switch ([#5313](https://github.com/open-chat-labs/open-chat/pull/5313))

### Changed

- Copy config from ICDex over to ICDex_V2 ([#5316](https://github.com/open-chat-labs/open-chat/pull/5316))

## [[2.0.1038](https://github.com/open-chat-labs/open-chat/releases/tag/v2.0.1038-market_maker)] - 2024-01-31

### Changed

- Avoid usages of `make_c2c_call` and use macro instead ([#5252](https://github.com/open-chat-labs/open-chat/pull/5252))
- Filter out orders which have 0 amount remaining ([#5301](https://github.com/open-chat-labs/open-chat/pull/5301))
- Increase page size when retrieving orders ([#5302](https://github.com/open-chat-labs/open-chat/pull/5302))

## [[2.0.999](https://github.com/open-chat-labs/open-chat/releases/tag/v2.0.999-market_maker)] - 2024-01-05

Expand Down
1 change: 1 addition & 0 deletions backend/canisters/market_maker/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub use queries::*;
pub use updates::*;

pub const ICDEX_EXCHANGE_ID: ExchangeId = ExchangeId::new(1);
pub const ICDEX_EXCHANGE_V2_ID: ExchangeId = ExchangeId::new(2);

#[derive(CandidType, Serialize, Deserialize, Clone, Debug)]
pub struct ExchangeInfo {
Expand Down
5 changes: 0 additions & 5 deletions backend/canisters/market_maker/impl/src/exchanges/icdex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,10 @@ use crate::exchanges::Exchange;
use async_trait::async_trait;
use ic_cdk::api::call::CallResult;
use icdex_client::ICDexClient;
use market_maker_canister::{ExchangeId, ICDEX_EXCHANGE_ID};
use types::{AggregatedOrders, CancelOrderRequest, MakeOrderRequest, Order, TokenInfo};

#[async_trait]
impl<M: Fn(MakeOrderRequest) + Send + Sync, C: Fn(CancelOrderRequest) + Send + Sync> Exchange for ICDexClient<M, C> {
fn exchange_id(&self) -> ExchangeId {
ICDEX_EXCHANGE_ID
}

fn quote_token(&self) -> &TokenInfo {
self.quote_token()
}
Expand Down
2 changes: 0 additions & 2 deletions backend/canisters/market_maker/impl/src/exchanges/mod.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
use async_trait::async_trait;
use ic_cdk::api::call::CallResult;
use market_maker_canister::ExchangeId;
use types::{AggregatedOrders, CancelOrderRequest, MakeOrderRequest, MarketState, Order, TokenInfo};

pub mod icdex;

#[async_trait]
pub trait Exchange: Send + Sync {
fn exchange_id(&self) -> ExchangeId;
fn quote_token(&self) -> &TokenInfo;
fn base_token(&self) -> &TokenInfo;
async fn latest_price(&self) -> CallResult<u64>;
Expand Down
16 changes: 7 additions & 9 deletions backend/canisters/market_maker/impl/src/jobs/run_market_maker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fn run() {
}
}

fn get_active_exchanges(state: &RuntimeState) -> Vec<(Box<dyn Exchange>, Config)> {
fn get_active_exchanges(state: &RuntimeState) -> Vec<(ExchangeId, Box<dyn Exchange>, Config)> {
let now = state.env.now();

state
Expand All @@ -41,21 +41,19 @@ fn get_active_exchanges(state: &RuntimeState) -> Vec<(Box<dyn Exchange>, Config)
.get(&id)
.map_or(true, |ts| now.saturating_sub(*ts) > 10 * MINUTE_IN_MS)
})
.filter_map(|(&id, c)| state.get_exchange_client(id).map(|e| (e, c.clone())))
.filter_map(|(&id, c)| state.get_exchange_client(id).map(|e| (id, e, c.clone())))
.collect()
}

async fn run_async(exchanges: Vec<(Box<dyn Exchange>, Config)>) {
futures::future::join_all(exchanges.into_iter().map(|(e, c)| async {
let exchange_id = e.exchange_id();
let _ = run_single(e, c).await;
mark_market_maker_complete(&exchange_id);
async fn run_async(exchanges: Vec<(ExchangeId, Box<dyn Exchange>, Config)>) {
futures::future::join_all(exchanges.into_iter().map(|(id, e, c)| async move {
let _ = run_single(id, e, c).await;
mark_market_maker_complete(&id);
}))
.await;
}

async fn run_single(exchange_client: Box<dyn Exchange>, config: Config) -> CallResult<()> {
let exchange_id = exchange_client.exchange_id();
async fn run_single(exchange_id: ExchangeId, exchange_client: Box<dyn Exchange>, config: Config) -> CallResult<()> {
trace!(%exchange_id, "Running market maker");

let my_previous_open_orders = mutate_state(|state| {
Expand Down
49 changes: 30 additions & 19 deletions backend/canisters/market_maker/impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::exchanges::Exchange;
use crate::model::orders_log::OrdersLog;
use canister_state_macros::canister_state;
use icdex_client::ICDexClient;
use market_maker_canister::{ExchangeId, ICDEX_EXCHANGE_ID};
use market_maker_canister::{ExchangeId, ICDEX_EXCHANGE_ID, ICDEX_EXCHANGE_V2_ID};
use serde::{Deserialize, Serialize};
use std::cell::RefCell;
use std::collections::{BTreeMap, HashMap, VecDeque};
Expand Down Expand Up @@ -38,25 +38,14 @@ impl RuntimeState {

pub fn get_exchange_client(&self, exchange_id: ExchangeId) -> Option<Box<dyn Exchange>> {
match exchange_id {
ICDEX_EXCHANGE_ID => Some(Box::new(ICDexClient::new(
self.env.canister_id(),
ICDEX_EXCHANGE_ID => Some(self.create_icdex_client(
ICDEX_EXCHANGE_ID,
CanisterId::from_text("3we4s-lyaaa-aaaak-aegrq-cai").unwrap(),
TokenInfo {
token: Cryptocurrency::InternetComputer,
ledger: self.data.icp_ledger_canister_id,
decimals: 8,
fee: 10_000,
},
TokenInfo {
token: Cryptocurrency::CHAT,
ledger: self.data.chat_ledger_canister_id,
decimals: 8,
fee: 100_000,
},
10_000_000,
|order| on_order_made(ICDEX_EXCHANGE_ID, order),
|order| on_order_cancelled(ICDEX_EXCHANGE_ID, order),
))),
)),
ICDEX_EXCHANGE_V2_ID => Some(self.create_icdex_client(
ICDEX_EXCHANGE_V2_ID,
CanisterId::from_text("52ypw-riaaa-aaaar-qadjq-cai").unwrap(),
)),
_ => None,
}
}
Expand All @@ -79,6 +68,28 @@ impl RuntimeState {
},
}
}

fn create_icdex_client(&self, exchange_id: ExchangeId, dex_canister_id: CanisterId) -> Box<dyn Exchange> {
Box::new(ICDexClient::new(
self.env.canister_id(),
dex_canister_id,
TokenInfo {
token: Cryptocurrency::InternetComputer,
ledger: self.data.icp_ledger_canister_id,
decimals: 8,
fee: 10_000,
},
TokenInfo {
token: Cryptocurrency::CHAT,
ledger: self.data.chat_ledger_canister_id,
decimals: 8,
fee: 100_000,
},
10_000_000,
move |order| on_order_made(exchange_id, order),
move |order| on_order_cancelled(exchange_id, order),
))
}
}

#[derive(Serialize, Deserialize)]
Expand Down
Loading

0 comments on commit 27cfde8

Please sign in to comment.