-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
86dff9d
commit ad805f8
Showing
127 changed files
with
22,550 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -328,3 +328,5 @@ cython_debug/ | |
# Built Visual Studio Code Extensions | ||
*.vsix | ||
.vscode/settings.json | ||
|
||
**/schema/** |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
[package] | ||
authors = ["Composable Developers"] | ||
description = "CVM Executor contract" | ||
edition = "2021" | ||
name = "cw-xc-executor" | ||
repository = "https://github.com/ComposableFi/composable" | ||
version = "0.2.0" | ||
|
||
[lib] | ||
crate-type = ["cdylib", "rlib"] | ||
|
||
[features] | ||
library = [] | ||
std = ["xc-core/std", "dep:cosmwasm-schema", "dep:serde_json"] | ||
default = ["std"] | ||
|
||
[dependencies] | ||
serde_json = { workspace = true, optional = true } | ||
cosmwasm-std = { workspace = true } | ||
cw-storage-plus = { workspace = true } | ||
cosmwasm-schema = { workspace = true, optional = true } | ||
cw-utils = { workspace = true } | ||
cw2 = { workspace = true } | ||
cw20 = { workspace = true } | ||
num = { workspace = true } | ||
hex = { workspace = true, default-features = false, features = ["alloc"] } | ||
schemars = { workspace = true } | ||
serde = { workspace = true } | ||
serde-json-wasm = { workspace = true } | ||
serde-cw-value = { workspace = true } | ||
thiserror = { workspace = true } | ||
prost = { workspace = true, features = ["prost-derive"] } | ||
xc-core = { path = "../../../lib/core", features = [ | ||
"cosmwasm", | ||
], default-features = false } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
# CVM Executor | ||
|
||
Receives and stores user funds. | ||
Fully owned by user. | ||
Delegates cross chain execution to gateway. | ||
|
||
Instantiated as many instances of the CVM interpreter contract. On some chains, we can use probabilistically generated sub_accounts, but for most, we instantiate a contract instance. | ||
|
||
## Events | ||
|
||
Note that these events will be yield from the router in production. | ||
|
||
### Instantiate contract | ||
```json | ||
{ | ||
"type": "wasm-xcvm.executor.instantiated", | ||
"attributes": [ | ||
{ | ||
"key": "data", | ||
"value": "{BASE64_ENCODED_DATA}" | ||
} | ||
] | ||
} | ||
``` | ||
|
||
- **BASE64_ENCODED_DATA**: base64 encoded `(network_id, user_id)` pair. | ||
|
||
### Execute contract | ||
```json | ||
{ | ||
"type": "wasm-xcvm.executor.executed", | ||
"attributes": [ | ||
{ | ||
"key": "program", | ||
"value": "{XCVM_PROGRAM_TAG}" | ||
} | ||
] | ||
} | ||
``` | ||
|
||
- **XCVM_PROGRAM_TAG**: Tag of the executed XCVM program | ||
|
||
### Execute spawn instruction | ||
|
||
```json | ||
{ | ||
"type": "wasm-xcvm.executor.spawn", | ||
"attributes": [ | ||
{ | ||
"key": "origin_network_id", | ||
"value": "{ORIGIN_NETWORK_ID}" | ||
}, | ||
{ | ||
"key": "origin_user_id", | ||
"value": "{ORIGIN_USER_ID}" | ||
}, | ||
{ | ||
"key": "program", | ||
"value": "{XCVM_PROGRAM}" | ||
} | ||
] | ||
} | ||
``` | ||
|
||
- **ORIGIN_NETWORK_ID**: Network id of the origin. Eg. Picasso, Ethereum | ||
- **ORIGIN_USER_ID**: Chain agnostic user identifier of the origin. Eg. contract_address in Juno | ||
- **XCVM_PROGRAM**: Json-encoded xcvm program. Note that although it is json-encoded, it is put as a string because of the restrictions of cosmwasm. | ||
|
||
## Usage | ||
|
||
The XCVM interpreter contract interprets the XCVM programs. Available instructions are: | ||
|
||
|
||
### Call | ||
Which is used to call a contract. See that the encoded payload must be in a format: | ||
``` | ||
{ | ||
"address": "contract-addr", | ||
"payload": "json-encoded ExecuteMsg struct" | ||
} | ||
``` | ||
|
||
### Transfer | ||
Queries `gateway`, gets the contract address and then executes that contract to do the transfer. | ||
|
||
### Spawn | ||
Emits `spawn` event with the given parameters. | ||
|
||
## Compile | ||
|
||
```sh | ||
RUSTFLAGS='-C link-arg=-s' cargo b --package=xcvm-interpreter --target=wasm32-unknown-unknown --profile="cosmwasm-contracts" | ||
``` | ||
|
||
* `-C link-arg=-s` is used for stripping the binary which reduces the binary size drastically. | ||
* `--profile="cosmwasm-contracts"` must be used for cosmwasm contracts. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
disallowed-types = [ | ||
# { path = "usize", reason = "variable size" }, # cannot on now, because serde, even if there is no usize in type | ||
{ path = "f64", resdason = "harware dependant" }, | ||
{ path = "f32", reason = "harware dependant" }, | ||
{ path = "num_traits::float::*", reason = "harware dependant" }, | ||
{ path = "serde_json::to_string", reason = "use serde_json_wasm::* and serde_cw_value::*" }, | ||
] | ||
|
||
disallowed-methods = ["std::time::Duration::as_secs_f64"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
use crate::{ | ||
error::{ContractError, Result}, | ||
state::OWNERS, | ||
}; | ||
use cosmwasm_std::{Addr, Deps}; | ||
|
||
/// Authenticated token, MUST be private and kept in this module. | ||
/// MUST ONLY be instantiated by [`ensure_owner`]. | ||
pub struct Authenticated(()); | ||
|
||
/// Ensure that the caller is either the current interpreter or listed in the owners of the | ||
/// interpreter. | ||
/// Any operation executing against the interpreter must pass this check. | ||
pub fn ensure_owner(deps: Deps, self_addr: &Addr, sender: Addr) -> Result<Authenticated> { | ||
if sender == self_addr || OWNERS.has(deps.storage, sender) { | ||
Ok(Authenticated(())) | ||
} else { | ||
Err(ContractError::NotAuthorized) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#[cfg(feature = "std")] | ||
#[allow(clippy::disallowed_methods)] | ||
fn main() { | ||
use cosmwasm_schema::write_api; | ||
use cw_xc_executor::msg::*; | ||
|
||
write_api! { | ||
instantiate: InstantiateMsg, | ||
query: QueryMsg, | ||
execute: ExecuteMsg, | ||
} | ||
let events = schemars::gen::SchemaGenerator::default() | ||
.into_root_schema_for::<cw_xc_executor::events::CvmInterpreter>(); | ||
|
||
// same as in above macro | ||
let mut out_dir = std::env::current_dir().unwrap(); | ||
out_dir.push("schema"); | ||
|
||
use ::std::fs::write; | ||
|
||
let path = out_dir.join(concat!("events", ".json")); | ||
|
||
write(&path, serde_json::to_string_pretty(&events).unwrap()).unwrap(); | ||
} | ||
|
||
#[cfg(not(feature = "std"))] | ||
fn main() {} |
Oops, something went wrong.