Skip to content

Commit

Permalink
updating all
Browse files Browse the repository at this point in the history
  • Loading branch information
dzmitry-lahoda committed Mar 12, 2024
1 parent 202e3eb commit ef78d36
Show file tree
Hide file tree
Showing 25 changed files with 551 additions and 49 deletions.
34 changes: 20 additions & 14 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ cosmwasm-std = { version = "^1.5.0", features = [
"iterator",
], default-features = false }

log = { version = "0.4.21", default-features = true}
parity-scale-codec = { version = "^3.6.5", default-features = false }
cw20 = { version = "^1.1.2", default-features = false }
cw-controllers = { version = "^1.1.1", default-features = false }
Expand Down
4 changes: 2 additions & 2 deletions contracts/cosmwasm/executor/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ fn initiate_execution(
deps: DepsMut,
env: Env,
tip: Addr,
program: shared::XcProgram,
program: shared::CvmProgram,
) -> Result {
// Reset instruction pointer to zero.
INSTRUCTION_POINTER_REGISTER.save(deps.storage, &0)?;
Expand Down Expand Up @@ -379,7 +379,7 @@ pub fn execute_spawn(
network_id: NetworkId,
salt: Vec<u8>,
assets: Funds<Amount>,
program: shared::XcProgram,
program: shared::CvmProgram,
) -> Result {
let Config {
executor_origin,
Expand Down
6 changes: 3 additions & 3 deletions contracts/cosmwasm/order/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub use types::*;
pub use crate::sv::{ExecMsg, QueryMsg};

use cosmwasm_std::{wasm_execute, Addr, BankMsg, Coin, Event, Order, StdError, Storage};
use cvm_runtime::shared::{XcInstruction, XcProgram};
use cvm_runtime::shared::{CvmInstruction, CvmProgram};
use cw_storage_plus::{Index, IndexList, IndexedMap, Item, Map};
use sylvia::{
contract,
Expand Down Expand Up @@ -206,14 +206,14 @@ impl OrderContract<'_> {
},
];
let cvm = wasm_execute(contract, &cvm, funds)?;

trust_fill();
Ok(Response::default().add_message(cvm))
}

/// Provides solution for set of orders.
/// All fully
#[msg(exec)]
pub fn solve(&self, ctx: ExecCtx, msg: SolutionSubMsg) -> StdResult<Response> {
pub fn settle(&self, ctx: ExecCtx, msg: SolutionSubMsg) -> StdResult<Response> {
// read all orders as solver provided
let mut all_orders = join_solution_with_orders(&self.orders, &msg, &ctx)?;
let at_least_one = all_orders.first().expect("at least one");
Expand Down
4 changes: 2 additions & 2 deletions contracts/cosmwasm/order/src/simulator.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use cosmwasm_std::Storage;
use cvm_runtime::shared::XcProgram;
use cvm_runtime::shared::CvmProgram;

use crate::prelude::*;
use crate::CowFilledOrder;
Expand Down Expand Up @@ -66,7 +66,7 @@ pub fn simulate_cows_via_bank(
/// Produces remaining each order will receive proportional to what is given.
pub fn simulate_route(
storage: &mut dyn Storage,
route: XcProgram,
route: CvmProgram,
token_a_remaining: Coin,
token_b_remaining: Coin,
orders: Vec<SolvedOrder>,
Expand Down
2 changes: 1 addition & 1 deletion contracts/cosmwasm/order/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use cosmwasm_std::{ensure, BankMsg, Event, StdResult, Uint64, WasmMsg};
use cvm_runtime::{outpost::ExecuteProgramMsg, shared::XcProgram, AssetId, ExchangeId, NetworkId};
use cvm_runtime::{outpost::ExecuteProgramMsg, shared::CvmProgram, AssetId, ExchangeId, NetworkId};

use crate::prelude::*;

Expand Down
10 changes: 5 additions & 5 deletions contracts/cosmwasm/outpost/src/contract/ibc/ics20.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use cosmwasm_std::{
use cvm_route::asset::{AssetItem, AssetReference};
use cvm_runtime::{
outpost::{ExecuteMsg, ExecuteProgramMsg, OutpostId},
shared::{XcFunds, XcPacket, XcProgram},
shared::{CvmFunds, CvmPacket, CvmProgram},
transport::ibc::{to_cosmwasm_message, IbcIcs20ProgramRoute, XcMessageData},
AssetId, CallOrigin,
};
Expand Down Expand Up @@ -69,7 +69,7 @@ pub(crate) fn handle_bridge_forward(
.map(|(_, amount)| (route.on_remote_asset, *amount))
.expect("not empty");

let packet = XcPacket {
let packet = CvmPacket {
executor: String::from(info.sender).into_bytes(),
user_origin: msg.executor_origin.user_origin.clone(),
salt: msg.msg.salt,
Expand Down Expand Up @@ -235,14 +235,14 @@ pub(crate) fn ics20_message_hook(
env: Env,
info: MessageInfo,
) -> Result<Response, ContractError> {
let packet: XcPacket = msg.packet;
let packet: CvmPacket = msg.packet;
ensure_anonymous(&packet.program)?;
deps.api.debug(&format!(
"cvm::outpost::ibc::ics20:: received assets {:?}, packet assets {:?}",
&info.funds, &packet.assets
));

let assets: Result<XcFunds, ContractError> = info
let assets: Result<CvmFunds, ContractError> = info
.funds
.into_iter()
.map(|coin| {
Expand Down Expand Up @@ -271,7 +271,7 @@ pub(crate) fn ics20_message_hook(
Ok(Response::new().add_submessage(SubMsg::reply_always(msg, ReplyId::ExecProgram.into())))
}

fn ensure_anonymous(program: &XcProgram) -> Result<()> {
fn ensure_anonymous(program: &CvmProgram) -> Result<()> {
use cvm_runtime::Instruction::*;
for ix in &program.instructions {
match ix {
Expand Down
10 changes: 5 additions & 5 deletions contracts/cosmwasm/outpost/src/contract/ibc/ics27.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use cosmwasm_std::{
IbcPacketTimeoutMsg, IbcReceiveResponse, MessageInfo, Response, SubMsg,
};
use cvm_route::transport::ChannelInfo;
use cvm_runtime::{proto::Isomorphism, shared::XcPacket, CallOrigin, XCVMAck};
use cvm_runtime::{proto::Isomorphism, shared::CvmPacket, CallOrigin, XCVMAck};
use ibc_core_host_types::identifiers::{ChannelId, ConnectionId};

use super::make_ibc_failure_event;
Expand Down Expand Up @@ -92,7 +92,7 @@ pub fn ibc_packet_receive(
) -> Result<IbcReceiveResponse> {
let response = IbcReceiveResponse::default().add_event(make_event("receive"));
let msg = (|| -> Result<_> {
let packet = XcPacket::decode(&msg.packet.data)?;
let packet = CvmPacket::decode(&msg.packet.data)?;
let call_origin = CallOrigin::Remote {
user_origin: packet.user_origin,
};
Expand Down Expand Up @@ -122,7 +122,7 @@ pub fn ibc_packet_receive(
pub fn ibc_packet_ack(_deps: DepsMut, _env: Env, msg: IbcPacketAckMsg) -> Result<IbcBasicResponse> {
let ack = XCVMAck::try_from(msg.acknowledgement.data.as_slice())
.map_err(|_| ContractError::InvalidAck)?;
XcPacket::decode(&msg.original_packet.data)?;
CvmPacket::decode(&msg.original_packet.data)?;
Ok(IbcBasicResponse::default().add_event(make_event("ack").add_attribute("ack", ack)))
}

Expand All @@ -132,7 +132,7 @@ pub fn ibc_packet_timeout(
_env: Env,
msg: IbcPacketTimeoutMsg,
) -> Result<IbcBasicResponse> {
XcPacket::decode(&msg.packet.data)?;
CvmPacket::decode(&msg.packet.data)?;
// https://github.com/cosmos/ibc/pull/998
Ok(IbcBasicResponse::default())
}
Expand All @@ -157,7 +157,7 @@ pub(crate) fn handle_bridge_forward_no_assets(
let channel_id = other.connection.ics27_channel.map(|x| x.id).ok_or(
ContractError::ConnectionFromToNotFoundOverIcs27(this.network_id, msg.to_network),
)?;
let executor = XcPacket {
let executor = CvmPacket {
executor: String::from(info.sender).into_bytes(),
user_origin: msg.executor_origin.user_origin,
salt: msg.msg.salt,
Expand Down
4 changes: 4 additions & 0 deletions contracts/solana/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Overview

Describes solana-outpost and solana-executor contracts.

2 changes: 2 additions & 0 deletions contracts/solana/executor/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

Per user program instance.
2 changes: 2 additions & 0 deletions contracts/solana/outpost/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

ICS27 like implementation adhering to solana-ibc app module.
6 changes: 6 additions & 0 deletions crates/cvm-glt/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
authors = ["Composable Developers"]
edition = "2021"
homepage = "https://composable.finance"
name = "cvm-glt"
version = "0.1.0"
8 changes: 8 additions & 0 deletions crates/cvm-glt/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Global Lookup Table

Accounts, connections and assets abstractions registry.

Configuration stored on each routeable chain.


Naming inspired by https://solana.com/docs/advanced/lookup-tables . Unlike registry, which usually in native identifiers, it also stores mapping for some global indexes to local native names.
Empty file added crates/cvm-glt/src/lib.rs
Empty file.
6 changes: 3 additions & 3 deletions crates/cvm-runtime/src/executor.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use cosmwasm_std::Event;

use crate::prelude::*;
use crate::shared::XcProgram;
use crate::shared::CvmProgram;
use crate::ExecutorOrigin;

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
Expand Down Expand Up @@ -32,7 +32,7 @@ pub struct Step {
/// instructions we already consumed.
pub instruction_pointer: u16,
/// The next instructions to execute (actual program).
pub program: XcProgram,
pub program: CvmProgram,
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
Expand All @@ -43,7 +43,7 @@ pub struct Step {
#[serde(rename_all = "snake_case")]
pub enum ExecuteMsg {
/// Execute an CVM program
Execute { tip: Addr, program: XcProgram },
Execute { tip: Addr, program: CvmProgram },

/// This is only meant to be used by the executor itself, otherwise it will return an error
/// The existence of this message is to allow the execution of the `Call` instruction. Once we
Expand Down
2 changes: 1 addition & 1 deletion crates/cvm-runtime/src/outpost/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ pub struct ExecuteProgramMsg<Assets = Option<Funds<crate::shared::Displayed<u128
#[serde(skip_serializing_if = "Vec::is_empty", default)]
pub salt: Vec<u8>,
/// The program.
pub program: crate::shared::XcProgram,
pub program: crate::shared::CvmProgram,
/// Assets to fund the CVM executor instance.
/// The executor is funded prior to execution.
/// If None, 100% of received funds go to executor.
Expand Down
4 changes: 4 additions & 0 deletions crates/cvm-runtime/src/outpost/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,7 @@ pub struct GetConfigResponse {
pub networks: Vec<NetworkItem>,
pub network_assets: Vec<NetworkAssetItem>,
}

// impl GetConfigResponse {
// pub fn
// }
28 changes: 19 additions & 9 deletions crates/cvm-runtime/src/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,29 @@ use serde::{de::DeserializeOwned, Serialize};
pub use cvm::shared::*;
pub type Salt = Vec<u8>;
/// absolute amounts
pub type XcFunds = Vec<(AssetId, Displayed<u128>)>;
/// like `XcFunds`, but allow relative(percentages) amounts. Similar to assets filters in XCM
pub type XcBalanceFilter = crate::asset::Amount;
pub type XcFundsFilter = crate::Funds<XcBalanceFilter>;
pub type XcInstruction = crate::Instruction<Vec<u8>, XcAddr, XcFundsFilter>;
pub type XcPacket = crate::Packet<XcProgram>;
pub type XcProgram = crate::Program<Vec<XcInstruction>>;
pub type CvmFunds = Vec<(AssetId, Displayed<u128>)>;
/// like `CvmFunds`, but allow relative(percentages) amounts. Similar to assets filters in XCM
pub type CvmBalanceFilter = crate::asset::Amount;
pub type CvmFundsFilter = crate::Funds<CvmBalanceFilter>;
pub type CvmInstruction = crate::Instruction<Vec<u8>, XcAddr, CvmFundsFilter>;
pub type CvmPacket = crate::Packet<CvmProgram>;
pub type CvmProgram = crate::Program<Vec<CvmInstruction>>;

impl XcInstruction {
impl CvmProgram {
fn new(instructions: Vec<CvmInstruction>) -> Self {
Self {
tag: vec![0],
instructions,
}
}
}


impl CvmInstruction {
pub fn transfer_absolute_to_account(to: &str, asset_id: u128, amount: u128) -> Self {
Self::Transfer {
to: crate::Destination::Account(XcAddr(to.to_owned())),
assets: XcFundsFilter::one(asset_id.into(), crate::Amount::new(amount, 0)),
assets: CvmFundsFilter::one(asset_id.into(), crate::Amount::new(amount, 0)),
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions crates/cvm-runtime/src/transport/ibc/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
outpost::{self, Ics20Features, OutpostId},
prelude::*,
shared::XcPacket,
shared::CvmPacket,
AssetId, NetworkId,
};
use cosmwasm_std::{Api, BlockInfo, CosmosMsg, Deps, IbcEndpoint, StdResult};
Expand All @@ -25,7 +25,7 @@ use ibc_apps_more::{
)]
pub struct XcMessageData {
pub from_network_id: NetworkId,
pub packet: XcPacket,
pub packet: CvmPacket,
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
Expand Down Expand Up @@ -68,7 +68,7 @@ pub fn to_cosmwasm_message<T>(
api: &dyn Api,
coin: Coin,
route: IbcIcs20ProgramRoute,
packet: XcPacket,
packet: CvmPacket,
block: BlockInfo,
to_outpost: Addr,
) -> StdResult<CosmosMsg<T>> {
Expand Down
Loading

0 comments on commit ef78d36

Please sign in to comment.