From 361adf99207c038425bb280a916acd13553fb33c Mon Sep 17 00:00:00 2001 From: Hendrik Hofstadt Date: Mon, 2 Aug 2021 21:27:10 +0200 Subject: [PATCH] Add token bridge CLI This also automatically initializes the token bridge in the devnet Change-Id: I473a97da1ff55e7c9a104983087951268eb7a27d --- Dockerfile.client | 5 +- solana/bridge/Cargo.lock | 740 +----------------- solana/devnet_setup.sh | 4 + solana/modules/token_bridge/Cargo.lock | 29 + solana/modules/token_bridge/Cargo.toml | 2 +- solana/modules/token_bridge/client/Cargo.toml | 20 + .../modules/token_bridge/client/src/main.rs | 300 +++++++ 7 files changed, 384 insertions(+), 716 deletions(-) create mode 100644 solana/modules/token_bridge/client/Cargo.toml create mode 100644 solana/modules/token_bridge/client/src/main.rs diff --git a/Dockerfile.client b/Dockerfile.client index 01f3e1910..3282b6ec3 100644 --- a/Dockerfile.client +++ b/Dockerfile.client @@ -16,9 +16,12 @@ RUN --mount=type=cache,target=/usr/local/cargo,from=rust,source=/usr/local/cargo --mount=type=cache,target=/root/.cache \ --mount=type=cache,target=target \ --mount=type=cache,target=bridge/target \ + --mount=type=cache,target=modules/token_bridge/target \ cargo install --version =1.7.0 solana-cli && \ cargo install --version =2.0.12 spl-token-cli && \ cargo build --manifest-path ./bridge/Cargo.toml --package client --release && \ + cargo build --manifest-path ./modules/token_bridge/Cargo.toml --package client --release && \ cp /usr/local/cargo/bin/solana /usr/local/bin && \ cp /usr/local/cargo/bin/spl-token /usr/local/bin && \ - cp bridge/target/release/client /usr/local/bin + cp bridge/target/release/client /usr/local/bin && \ + cp modules/token_bridge/target/release/client /usr/local/bin/token-bridge-client diff --git a/solana/bridge/Cargo.lock b/solana/bridge/Cargo.lock index 0b99d796e..06328a826 100644 --- a/solana/bridge/Cargo.lock +++ b/solana/bridge/Cargo.lock @@ -27,40 +27,6 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" -[[package]] -name = "agent" -version = "0.1.0" -dependencies = [ - "borsh", - "bridge", - "bs58", - "byteorder", - "clap", - "futures 0.3.15", - "hex", - "libc", - "log", - "primitive-types 0.7.3", - "prost", - "prost-types", - "serde", - "serde_bytes", - "serde_derive", - "serde_json", - "sha3", - "solana-client", - "solana-program", - "solana-sdk", - "solitaire", - "solitaire-client", - "thiserror", - "tokio 0.2.25", - "tonic", - "tonic-build", - "tungstenite 0.11.1", - "url", -] - [[package]] name = "ahash" version = "0.4.7" @@ -109,38 +75,6 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b34d609dfbaf33d6889b2b7106d3ca345eacad44200913df5ba02bfd31d2ba9" -[[package]] -name = "async-stream" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22068c0c19514942eefcfd4daf8976ef1aad84e61539f95cd200c35202f80af5" -dependencies = [ - "async-stream-impl", - "futures-core", -] - -[[package]] -name = "async-stream-impl" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25f9db3b38af870bf7e5cc649167533b493928e50744e2c30ae350230b414670" -dependencies = [ - "proc-macro2 1.0.28", - "quote 1.0.9", - "syn 1.0.74", -] - -[[package]] -name = "async-trait" -version = "0.1.50" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b98e84bbb4cbcdd97da190ba0c58a1bb0de2c1fdf67d159e192ed766aeca722" -dependencies = [ - "proc-macro2 1.0.28", - "quote 1.0.9", - "syn 1.0.74", -] - [[package]] name = "atty" version = "0.2.14" @@ -213,16 +147,6 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" -[[package]] -name = "bitvec" -version = "0.17.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41262f11d771fd4a61aa3ce019fca363b4b6c282fca9da2a31186d3965a47a5c" -dependencies = [ - "either", - "radium", -] - [[package]] name = "blake3" version = "0.3.8" @@ -329,7 +253,7 @@ dependencies = [ "hex", "hex-literal", "libsecp256k1", - "primitive-types 0.9.1", + "primitive-types", "rand 0.7.3", "serde", "sha3", @@ -351,7 +275,7 @@ dependencies = [ "hex", "hex-literal", "libsecp256k1", - "primitive-types 0.9.1", + "primitive-types", "rand 0.7.3", "sha3", "solana-client", @@ -383,12 +307,6 @@ dependencies = [ "serde", ] -[[package]] -name = "byte-slice-cast" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0a5e3906bcbf133e33c1d4d95afc664ad37fbdb9f6568d8043e7ea8c27d93d3" - [[package]] name = "byte-tools" version = "0.3.1" @@ -589,7 +507,7 @@ dependencies = [ "hex", "hex-literal", "libsecp256k1", - "primitive-types 0.9.1", + "primitive-types", "rand 0.7.3", "sha3", "solana-client", @@ -1005,18 +923,6 @@ dependencies = [ "winapi 0.3.9", ] -[[package]] -name = "fixed-hash" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11498d382790b7a8f2fd211780bec78619bba81cdad3a283997c0c41f836759c" -dependencies = [ - "byteorder", - "rand 0.7.3", - "rustc-hex", - "static_assertions", -] - [[package]] name = "fixed-hash" version = "0.7.0" @@ -1026,12 +932,6 @@ dependencies = [ "static_assertions", ] -[[package]] -name = "fixedbitset" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37ab347416e802de484e4d03c7316c48f1ecb56574dfd4a46a80f173ce1de04d" - [[package]] name = "flate2" version = "1.0.20" @@ -1184,7 +1084,7 @@ dependencies = [ "futures-sink", "futures-task", "memchr", - "pin-project-lite 0.2.7", + "pin-project-lite", "pin-utils", "proc-macro-hack", "proc-macro-nested", @@ -1255,26 +1155,6 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" -[[package]] -name = "h2" -version = "0.2.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e4728fd124914ad25e99e3d15a9361a879f6620f63cb56bbb08f95abb97a535" -dependencies = [ - "bytes 0.5.6", - "fnv", - "futures-core", - "futures-sink", - "futures-util", - "http", - "indexmap", - "slab", - "tokio 0.2.25", - "tokio-util 0.3.1", - "tracing", - "tracing-futures", -] - [[package]] name = "h2" version = "0.3.3" @@ -1290,7 +1170,7 @@ dependencies = [ "indexmap", "slab", "tokio 1.9.0", - "tokio-util 0.6.7", + "tokio-util", "tracing", ] @@ -1309,15 +1189,6 @@ version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" -[[package]] -name = "heck" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" -dependencies = [ - "unicode-segmentation", -] - [[package]] name = "hermit-abi" version = "0.1.19" @@ -1412,16 +1283,6 @@ dependencies = [ "itoa", ] -[[package]] -name = "http-body" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13d5ff830006f7646652e057693569bfe0d51760c0085a071769d142a205111b" -dependencies = [ - "bytes 0.5.6", - "http", -] - [[package]] name = "http-body" version = "0.4.2" @@ -1430,7 +1291,7 @@ checksum = "60daa14be0e0786db0f03a9e57cb404c9d756eed2b6c62b9ea98ec5743ec75a9" dependencies = [ "bytes 1.0.1", "http", - "pin-project-lite 0.2.7", + "pin-project-lite", ] [[package]] @@ -1439,12 +1300,6 @@ version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3a87b616e37e93c22fb19bcd386f02f3af5ea98a25670ad0fce773de23c5e68" -[[package]] -name = "httpdate" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "494b4d60369511e7dea41cf646832512a94e542f68bb9c49e54518e0f468eb47" - [[package]] name = "httpdate" version = "1.0.1" @@ -1457,30 +1312,6 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" -[[package]] -name = "hyper" -version = "0.13.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a6f157065790a3ed2f88679250419b5cdd96e714a0d65f7797fd337186e96bb" -dependencies = [ - "bytes 0.5.6", - "futures-channel", - "futures-core", - "futures-util", - "h2 0.2.7", - "http", - "http-body 0.3.1", - "httparse", - "httpdate 0.3.2", - "itoa", - "pin-project 1.0.8", - "socket2 0.3.19", - "tokio 0.2.25", - "tower-service", - "tracing", - "want", -] - [[package]] name = "hyper" version = "0.14.11" @@ -1491,13 +1322,13 @@ dependencies = [ "futures-channel", "futures-core", "futures-util", - "h2 0.3.3", + "h2", "http", - "http-body 0.4.2", + "http-body", "httparse", - "httpdate 1.0.1", + "httpdate", "itoa", - "pin-project-lite 0.2.7", + "pin-project-lite", "socket2 0.4.0", "tokio 1.9.0", "tower-service", @@ -1512,7 +1343,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5f9f7a97316d44c0af9b0301e65010573a853a9fc97046d7331d7f6bc0fd5a64" dependencies = [ "futures-util", - "hyper 0.14.11", + "hyper", "log", "rustls", "tokio 1.9.0", @@ -1531,15 +1362,6 @@ dependencies = [ "unicode-normalization", ] -[[package]] -name = "impl-codec" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1be51a921b067b0eaca2fad532d9400041561aa922221cc65f95a85641c6bf53" -dependencies = [ - "parity-scale-codec", -] - [[package]] name = "indexmap" version = "1.7.0" @@ -1595,15 +1417,6 @@ version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "68f2d64f2edebec4ce84ad108148e67e1064789bee435edc5b60ad398714a3a9" -[[package]] -name = "itertools" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f56a2d0bc861f9165be4eb3442afd3c236d8a98afd426f65d92324ae1091a484" -dependencies = [ - "either", -] - [[package]] name = "itertools" version = "0.9.0" @@ -1865,12 +1678,6 @@ dependencies = [ "winapi 0.3.9", ] -[[package]] -name = "multimap" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5ce46fe64a9d73be07dcbe690a38ce1b293be448fd8ce1e6c1b8062c9f72c6a" - [[package]] name = "native-tls" version = "0.2.7" @@ -2074,18 +1881,6 @@ dependencies = [ "syn 1.0.74", ] -[[package]] -name = "parity-scale-codec" -version = "1.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4b26b16c7687c3075982af47719e481815df30bc544f7a6690763a25ca16e9d" -dependencies = [ - "arrayvec", - "bitvec", - "byte-slice-cast", - "serde", -] - [[package]] name = "parking_lot" version = "0.9.0" @@ -2194,62 +1989,6 @@ dependencies = [ "ucd-trie", ] -[[package]] -name = "petgraph" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "467d164a6de56270bd7c4d070df81d07beace25012d5103ced4e9ff08d6afdb7" -dependencies = [ - "fixedbitset", - "indexmap", -] - -[[package]] -name = "pin-project" -version = "0.4.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "918192b5c59119d51e0cd221f4d49dde9112824ba717369e903c97d076083d0f" -dependencies = [ - "pin-project-internal 0.4.28", -] - -[[package]] -name = "pin-project" -version = "1.0.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "576bc800220cc65dac09e99e97b08b358cfab6e17078de8dc5fee223bd2d0c08" -dependencies = [ - "pin-project-internal 1.0.8", -] - -[[package]] -name = "pin-project-internal" -version = "0.4.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3be26700300be6d9d23264c73211d8190e755b6b5ca7a1b28230025511b52a5e" -dependencies = [ - "proc-macro2 1.0.28", - "quote 1.0.9", - "syn 1.0.74", -] - -[[package]] -name = "pin-project-internal" -version = "1.0.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e8fe8163d14ce7f0cdac2e040116f22eac817edabff0be91e8aff7e9accf389" -dependencies = [ - "proc-macro2 1.0.28", - "quote 1.0.9", - "syn 1.0.74", -] - -[[package]] -name = "pin-project-lite" -version = "0.1.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "257b64915a082f7811703966789728173279bdebb956b143dbcd23f6f970a777" - [[package]] name = "pin-project-lite" version = "0.2.7" @@ -2274,25 +2013,14 @@ version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857" -[[package]] -name = "primitive-types" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dd39dcacf71411ba488570da7bbc89b717225e46478b30ba99b92db6b149809" -dependencies = [ - "fixed-hash 0.6.1", - "impl-codec", - "uint 0.8.5", -] - [[package]] name = "primitive-types" version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "06345ee39fbccfb06ab45f3a1a5798d9dafa04cb8921a76d227040003a234b0e" dependencies = [ - "fixed-hash 0.7.0", - "uint 0.9.1", + "fixed-hash", + "uint", ] [[package]] @@ -2344,57 +2072,6 @@ dependencies = [ "unicode-xid 0.2.2", ] -[[package]] -name = "prost" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce49aefe0a6144a45de32927c77bd2859a5f7677b55f220ae5b744e87389c212" -dependencies = [ - "bytes 0.5.6", - "prost-derive", -] - -[[package]] -name = "prost-build" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02b10678c913ecbd69350e8535c3aef91a8676c0773fc1d7b95cdd196d7f2f26" -dependencies = [ - "bytes 0.5.6", - "heck", - "itertools 0.8.2", - "log", - "multimap", - "petgraph", - "prost", - "prost-types", - "tempfile", - "which", -] - -[[package]] -name = "prost-derive" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "537aa19b95acde10a12fec4301466386f757403de4cd4e5b4fa78fb5ecb18f72" -dependencies = [ - "anyhow", - "itertools 0.8.2", - "proc-macro2 1.0.28", - "quote 1.0.9", - "syn 1.0.74", -] - -[[package]] -name = "prost-types" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1834f67c0697c001304b75be76f67add9c89742eda3a085ad8ee0bb38c3417aa" -dependencies = [ - "bytes 0.5.6", - "prost", -] - [[package]] name = "qstring" version = "0.7.2" @@ -2422,12 +2099,6 @@ dependencies = [ "proc-macro2 1.0.28", ] -[[package]] -name = "radium" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "def50a86306165861203e7f84ecffbbdfdea79f0e51039b33de1e952358c47ac" - [[package]] name = "rand" version = "0.7.3" @@ -2439,7 +2110,6 @@ dependencies = [ "rand_chacha 0.2.2", "rand_core 0.5.1", "rand_hc 0.2.0", - "rand_pcg", ] [[package]] @@ -2510,15 +2180,6 @@ dependencies = [ "rand_core 0.6.3", ] -[[package]] -name = "rand_pcg" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16abd0c1b639e9eb4d7c50c0b8100b0d0f849be2349829c740fe8e6eb4816429" -dependencies = [ - "rand_core 0.5.1", -] - [[package]] name = "rayon" version = "1.5.1" @@ -2607,8 +2268,8 @@ dependencies = [ "futures-core", "futures-util", "http", - "http-body 0.4.2", - "hyper 0.14.11", + "http-body", + "hyper", "hyper-rustls", "ipnet", "js-sys", @@ -2616,7 +2277,7 @@ dependencies = [ "log", "mime", "percent-encoding", - "pin-project-lite 0.2.7", + "pin-project-lite", "rustls", "serde", "serde_json", @@ -2680,12 +2341,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" -[[package]] -name = "rustc-hex" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e75f6a532d0fd9f7f13144f392b6ad56a32696bfcd9c78f797f16bbb6f072d6" - [[package]] name = "rustc_version" version = "0.2.3" @@ -2887,19 +2542,6 @@ dependencies = [ "opaque-debug 0.2.3", ] -[[package]] -name = "sha-1" -version = "0.9.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a0c8611594e2ab4ebbf06ec7cbbf0a99450b8570e96cbf5188b5d5f6ef18d81" -dependencies = [ - "block-buffer 0.9.0", - "cfg-if 1.0.0", - "cpufeatures", - "digest 0.9.0", - "opaque-debug 0.3.0", -] - [[package]] name = "sha2" version = "0.8.2" @@ -3088,7 +2730,7 @@ dependencies = [ "solana-vote-program", "thiserror", "tokio 1.9.0", - "tungstenite 0.10.1", + "tungstenite", "url", ] @@ -3258,7 +2900,7 @@ dependencies = [ "bv", "curve25519-dalek 2.1.3", "hex", - "itertools 0.9.0", + "itertools", "lazy_static", "log", "num-derive", @@ -3326,7 +2968,7 @@ dependencies = [ "dir-diff", "flate2", "fnv", - "itertools 0.9.0", + "itertools", "lazy_static", "libc", "libloading", @@ -3379,7 +3021,7 @@ dependencies = [ "generic-array 0.14.4", "hex", "hmac 0.10.1", - "itertools 0.9.0", + "itertools", "lazy_static", "libsecp256k1", "log", @@ -3800,27 +3442,6 @@ dependencies = [ "tokio-uds", ] -[[package]] -name = "tokio" -version = "0.2.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6703a273949a90131b290be1fe7b039d0fc884aa1935860dfcbe056f28cd8092" -dependencies = [ - "bytes 0.5.6", - "fnv", - "futures-core", - "iovec", - "lazy_static", - "libc", - "memchr", - "mio 0.6.23", - "mio-uds", - "num_cpus", - "pin-project-lite 0.1.12", - "slab", - "tokio-macros 0.2.6", -] - [[package]] name = "tokio" version = "1.9.0" @@ -3835,9 +3456,9 @@ dependencies = [ "num_cpus", "once_cell", "parking_lot 0.11.1", - "pin-project-lite 0.2.7", + "pin-project-lite", "signal-hook-registry", - "tokio-macros 1.3.0", + "tokio-macros", "winapi 0.3.9", ] @@ -3894,17 +3515,6 @@ dependencies = [ "log", ] -[[package]] -name = "tokio-macros" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e44da00bfc73a25f814cd8d7e57a68a5c31b74b3152a0a1d1f590c97ed06265a" -dependencies = [ - "proc-macro2 1.0.28", - "quote 1.0.9", - "syn 1.0.74", -] - [[package]] name = "tokio-macros" version = "1.3.0" @@ -4032,20 +3642,6 @@ dependencies = [ "tokio-reactor", ] -[[package]] -name = "tokio-util" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be8242891f2b6cbef26a2d7e8605133c2c554cd35b3e4948ea892d6d68436499" -dependencies = [ - "bytes 0.5.6", - "futures-core", - "futures-sink", - "log", - "pin-project-lite 0.1.12", - "tokio 0.2.25", -] - [[package]] name = "tokio-util" version = "0.6.7" @@ -4056,7 +3652,7 @@ dependencies = [ "futures-core", "futures-sink", "log", - "pin-project-lite 0.2.7", + "pin-project-lite", "tokio 1.9.0", ] @@ -4069,226 +3665,12 @@ dependencies = [ "serde", ] -[[package]] -name = "tonic" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74a5d6e7439ecf910463667080de772a9c7ddf26bc9fb4f3252ac3862e43337d" -dependencies = [ - "async-stream", - "async-trait", - "base64 0.12.3", - "bytes 0.5.6", - "futures-core", - "futures-util", - "http", - "http-body 0.3.1", - "hyper 0.13.10", - "percent-encoding", - "pin-project 0.4.28", - "prost", - "prost-derive", - "tokio 0.2.25", - "tokio-util 0.3.1", - "tower", - "tower-balance", - "tower-load", - "tower-make", - "tower-service", - "tracing", - "tracing-futures", -] - -[[package]] -name = "tonic-build" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19970cf58f3acc820962be74c4021b8bbc8e8a1c4e3a02095d0aa60cde5f3633" -dependencies = [ - "proc-macro2 1.0.28", - "prost-build", - "quote 1.0.9", - "syn 1.0.74", -] - -[[package]] -name = "tower" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd3169017c090b7a28fce80abaad0ab4f5566423677c9331bb320af7e49cfe62" -dependencies = [ - "futures-core", - "tower-buffer", - "tower-discover", - "tower-layer", - "tower-limit", - "tower-load-shed", - "tower-retry", - "tower-service", - "tower-timeout", - "tower-util", -] - -[[package]] -name = "tower-balance" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a792277613b7052448851efcf98a2c433e6f1d01460832dc60bef676bc275d4c" -dependencies = [ - "futures-core", - "futures-util", - "indexmap", - "pin-project 0.4.28", - "rand 0.7.3", - "slab", - "tokio 0.2.25", - "tower-discover", - "tower-layer", - "tower-load", - "tower-make", - "tower-ready-cache", - "tower-service", - "tracing", -] - -[[package]] -name = "tower-buffer" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4887dc2a65d464c8b9b66e0e4d51c2fd6cf5b3373afc72805b0a60bce00446a" -dependencies = [ - "futures-core", - "pin-project 0.4.28", - "tokio 0.2.25", - "tower-layer", - "tower-service", - "tracing", -] - -[[package]] -name = "tower-discover" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f6b5000c3c54d269cc695dff28136bb33d08cbf1df2c48129e143ab65bf3c2a" -dependencies = [ - "futures-core", - "pin-project 0.4.28", - "tower-service", -] - -[[package]] -name = "tower-layer" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "343bc9466d3fe6b0f960ef45960509f84480bf4fd96f92901afe7ff3df9d3a62" - -[[package]] -name = "tower-limit" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92c3040c5dbed68abffaa0d4517ac1a454cd741044f33ab0eefab6b8d1361404" -dependencies = [ - "futures-core", - "pin-project 0.4.28", - "tokio 0.2.25", - "tower-layer", - "tower-load", - "tower-service", -] - -[[package]] -name = "tower-load" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8cc79fc3afd07492b7966d7efa7c6c50f8ed58d768a6075dd7ae6591c5d2017b" -dependencies = [ - "futures-core", - "log", - "pin-project 0.4.28", - "tokio 0.2.25", - "tower-discover", - "tower-service", -] - -[[package]] -name = "tower-load-shed" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f021e23900173dc315feb4b6922510dae3e79c689b74c089112066c11f0ae4e" -dependencies = [ - "futures-core", - "pin-project 0.4.28", - "tower-layer", - "tower-service", -] - -[[package]] -name = "tower-make" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce50370d644a0364bf4877ffd4f76404156a248d104e2cc234cd391ea5cdc965" -dependencies = [ - "tokio 0.2.25", - "tower-service", -] - -[[package]] -name = "tower-ready-cache" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4eabb6620e5481267e2ec832c780b31cad0c15dcb14ed825df5076b26b591e1f" -dependencies = [ - "futures-core", - "futures-util", - "indexmap", - "log", - "tokio 0.2.25", - "tower-service", -] - -[[package]] -name = "tower-retry" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6727956aaa2f8957d4d9232b308fe8e4e65d99db30f42b225646e86c9b6a952" -dependencies = [ - "futures-core", - "pin-project 0.4.28", - "tokio 0.2.25", - "tower-layer", - "tower-service", -] - [[package]] name = "tower-service" version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "360dfd1d6d30e05fda32ace2c8c70e9c0a9da713275777f5a4dbb8a1893930c6" -[[package]] -name = "tower-timeout" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "127b8924b357be938823eaaec0608c482d40add25609481027b96198b2e4b31e" -dependencies = [ - "pin-project 0.4.28", - "tokio 0.2.25", - "tower-layer", - "tower-service", -] - -[[package]] -name = "tower-util" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d1093c19826d33807c72511e68f73b4a0469a3f22c2bd5f7d5212178b4b89674" -dependencies = [ - "futures-core", - "futures-util", - "pin-project 0.4.28", - "tower-service", -] - [[package]] name = "tracing" version = "0.1.26" @@ -4296,23 +3678,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09adeb8c97449311ccd28a427f96fb563e7fd31aabf994189879d9da2394b89d" dependencies = [ "cfg-if 1.0.0", - "log", - "pin-project-lite 0.2.7", - "tracing-attributes", + "pin-project-lite", "tracing-core", ] -[[package]] -name = "tracing-attributes" -version = "0.1.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c42e6fa53307c8a17e4ccd4dc81cf5ec38db9209f59b222210375b54ee40d1e2" -dependencies = [ - "proc-macro2 1.0.28", - "quote 1.0.9", - "syn 1.0.74", -] - [[package]] name = "tracing-core" version = "0.1.18" @@ -4322,16 +3691,6 @@ dependencies = [ "lazy_static", ] -[[package]] -name = "tracing-futures" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97d095ae15e245a057c8e8451bab9b3ee1e1f68e9ba2b4fbc18d0ac5237835f2" -dependencies = [ - "pin-project 1.0.8", - "tracing", -] - [[package]] name = "try-lock" version = "0.2.3" @@ -4353,27 +3712,7 @@ dependencies = [ "log", "native-tls", "rand 0.7.3", - "sha-1 0.8.2", - "url", - "utf-8", -] - -[[package]] -name = "tungstenite" -version = "0.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0308d80d86700c5878b9ef6321f020f29b1bb9d5ff3cab25e75e23f3a492a23" -dependencies = [ - "base64 0.12.3", - "byteorder", - "bytes 0.5.6", - "http", - "httparse", - "input_buffer", - "log", - "native-tls", - "rand 0.7.3", - "sha-1 0.9.7", + "sha-1", "url", "utf-8", ] @@ -4390,18 +3729,6 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "56dee185309b50d1f11bfedef0fe6d036842e3fb77413abef29f8f8d1c5d4c1c" -[[package]] -name = "uint" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9db035e67dfaf7edd9aebfe8676afcd63eed53c8a4044fed514c8cccf1835177" -dependencies = [ - "byteorder", - "crunchy", - "rustc-hex", - "static_assertions", -] - [[package]] name = "uint" version = "0.9.1" @@ -4432,12 +3759,6 @@ dependencies = [ "tinyvec", ] -[[package]] -name = "unicode-segmentation" -version = "1.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8895849a949e7845e06bd6dc1aa51731a103c42707010a5b591c0038fb73385b" - [[package]] name = "unicode-width" version = "0.1.8" @@ -4638,15 +3959,6 @@ dependencies = [ "webpki", ] -[[package]] -name = "which" -version = "3.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d011071ae14a2f6671d0b74080ae0cd8ebf3a6f8c9589a2cd45f23126fe29724" -dependencies = [ - "libc", -] - [[package]] name = "winapi" version = "0.2.8" @@ -4775,6 +4087,6 @@ checksum = "a1e6e8778706838f43f771d80d37787cb2fe06dafe89dd3aebaf6721b9eaec81" dependencies = [ "cc", "glob", - "itertools 0.9.0", + "itertools", "libc", ] diff --git a/solana/devnet_setup.sh b/solana/devnet_setup.sh index 826eb398f..14be92706 100755 --- a/solana/devnet_setup.sh +++ b/solana/devnet_setup.sh @@ -18,6 +18,7 @@ EOF # Constants cli_address=6sbzC1eH4FTujJXWj51eQe25cYvr4xfXbJ1vAj7j2k5J bridge_address=Bridge1p5gheXUvJ6jGWGeCsgPKgnE3YgdGKRVCMY9o +token_bridge_address=B6RHG3mfcckmrYN1UhmJzyS1XX3fZKbkeUcpJe9Sy3FE initial_guardian=befa429d57cd18b7f8a4d91a2da9ab4af05d0fbe recipient_address=90F8bf6A479f320ead074411a4B0e7944Ea8c9C1 chain_id_ethereum=2 @@ -46,5 +47,8 @@ spl-token mint "$token" 10000000000 "$account" # OK to fail on subsequent attempts (already created). retry client create-bridge "$bridge_address" "$initial_guardian" 86400 100 +# Initialize the token bridge +retry token-bridge-client create-bridge "$token_bridge_address" "$bridge_address" + # Let k8s startup probe succeed nc -k -l -p 2000 diff --git a/solana/modules/token_bridge/Cargo.lock b/solana/modules/token_bridge/Cargo.lock index 41ba2b0d9..499cf6e4c 100644 --- a/solana/modules/token_bridge/Cargo.lock +++ b/solana/modules/token_bridge/Cargo.lock @@ -386,6 +386,26 @@ dependencies = [ "vec_map", ] +[[package]] +name = "client" +version = "0.1.0" +dependencies = [ + "anyhow", + "borsh", + "clap", + "hex", + "rand 0.7.3", + "shellexpand", + "solana-clap-utils", + "solana-cli-config", + "solana-client", + "solana-program", + "solana-sdk", + "solitaire", + "solitaire-client", + "token-bridge", +] + [[package]] name = "cloudabi" version = "0.0.3" @@ -2495,6 +2515,15 @@ dependencies = [ "opaque-debug 0.3.0", ] +[[package]] +name = "shellexpand" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83bdb7831b2d85ddf4a7b148aa19d0587eddbe8671a436b7bd1182eaad0f2829" +dependencies = [ + "dirs-next", +] + [[package]] name = "signal-hook-registry" version = "1.4.0" diff --git a/solana/modules/token_bridge/Cargo.toml b/solana/modules/token_bridge/Cargo.toml index c79096a15..f4cc51394 100644 --- a/solana/modules/token_bridge/Cargo.toml +++ b/solana/modules/token_bridge/Cargo.toml @@ -1,5 +1,5 @@ [workspace] -members = ["program"] +members = ["program", "client"] [patch.crates-io] memmap2 = { path = "../../bridge/memmap2-rs" } \ No newline at end of file diff --git a/solana/modules/token_bridge/client/Cargo.toml b/solana/modules/token_bridge/client/Cargo.toml new file mode 100644 index 000000000..d5a663e71 --- /dev/null +++ b/solana/modules/token_bridge/client/Cargo.toml @@ -0,0 +1,20 @@ +[package] +name = "client" +version = "0.1.0" +edition = "2018" + +[dependencies] +anyhow = "1.0.40" +borsh = "0.8.1" +token-bridge = { path = "../program", features = ["client"] } +clap = "2.33.0" +rand = "0.7.3" +shellexpand = "2.1.0" +solana-client = "=1.7.0" +solana-program = "=1.7.0" +solana-sdk = "=1.7.0" +solana-cli-config = "=1.7.0" +solitaire = { path = "../../../solitaire/program" } +solitaire-client = { path = "../../../solitaire/client" } +solana-clap-utils = "=1.7.0" +hex = "0.4.3" \ No newline at end of file diff --git a/solana/modules/token_bridge/client/src/main.rs b/solana/modules/token_bridge/client/src/main.rs new file mode 100644 index 000000000..3a2d7d238 --- /dev/null +++ b/solana/modules/token_bridge/client/src/main.rs @@ -0,0 +1,300 @@ +#![feature(const_generics)] +#![allow(warnings)] + +use std::{ + fmt::Display, + mem::size_of, + process::exit, +}; + +use borsh::BorshDeserialize; +use clap::{ + crate_description, + crate_name, + crate_version, + value_t, + App, + AppSettings, + Arg, + SubCommand, +}; +use hex; +use solana_clap_utils::{ + input_parsers::{ + keypair_of, + pubkey_of, + value_of, + }, + input_validators::{ + is_keypair, + is_pubkey_or_keypair, + is_url, + }, +}; +use solana_client::{ + rpc_client::RpcClient, + rpc_config::RpcSendTransactionConfig, +}; +use solana_sdk::{ + commitment_config::{ + CommitmentConfig, + CommitmentLevel, + }, + native_token::*, + program_error::ProgramError::AccountAlreadyInitialized, + pubkey::Pubkey, + signature::{ + read_keypair_file, + Keypair, + Signer, + }, + system_instruction::transfer, + transaction::Transaction, +}; +use solitaire::{ + processors::seeded::Seeded, + AccountState, + Info, +}; +use solitaire_client::Derive; + +struct Config { + rpc_client: RpcClient, + owner: Keypair, + fee_payer: Keypair, + commitment_config: CommitmentConfig, +} + +type Error = Box; +type CommmandResult = Result, Error>; + +fn command_init_bridge(config: &Config, bridge: &Pubkey, core_bridge: &Pubkey) -> CommmandResult { + println!("Initializing Token bridge {}", bridge); + + let minimum_balance_for_rent_exemption = config + .rpc_client + .get_minimum_balance_for_rent_exemption(size_of::())?; + + let ix = token_bridge::instructions::initialize(*bridge, config.owner.pubkey(), *core_bridge) + .unwrap(); + println!("config account: {}, ", ix.accounts[1].pubkey.to_string()); + let mut transaction = Transaction::new_with_payer(&[ix], Some(&config.fee_payer.pubkey())); + + let (recent_blockhash, fee_calculator) = config.rpc_client.get_recent_blockhash()?; + check_fee_payer_balance( + config, + minimum_balance_for_rent_exemption + fee_calculator.calculate_fee(&transaction.message()), + )?; + transaction.sign(&[&config.fee_payer, &config.owner], recent_blockhash); + Ok(Some(transaction)) +} + +fn main() { + let matches = App::new(crate_name!()) + .about(crate_description!()) + .version(crate_version!()) + .setting(AppSettings::SubcommandRequiredElseHelp) + .arg({ + let arg = Arg::with_name("config_file") + .short("C") + .long("config") + .value_name("PATH") + .takes_value(true) + .global(true) + .help("Configuration file to use"); + if let Some(ref config_file) = *solana_cli_config::CONFIG_FILE { + arg.default_value(&config_file) + } else { + arg + } + }) + .arg( + Arg::with_name("json_rpc_url") + .long("url") + .value_name("URL") + .takes_value(true) + .validator(is_url) + .help("JSON RPC URL for the cluster. Default from the configuration file."), + ) + .arg( + Arg::with_name("owner") + .long("owner") + .value_name("KEYPAIR") + .validator(is_keypair) + .takes_value(true) + .help( + "Specify the contract payer account. \ + This may be a keypair file, the ASK keyword. \ + Defaults to the client keypair.", + ), + ) + .arg( + Arg::with_name("fee_payer") + .long("fee-payer") + .value_name("KEYPAIR") + .validator(is_keypair) + .takes_value(true) + .help( + "Specify the fee-payer account. \ + This may be a keypair file, the ASK keyword. \ + Defaults to the client keypair.", + ), + ) + .subcommand( + SubCommand::with_name("create-bridge") + .about("Create a new bridge") + .arg( + Arg::with_name("bridge") + .long("bridge") + .value_name("BRIDGE_KEY") + .validator(is_pubkey_or_keypair) + .takes_value(true) + .index(1) + .required(true) + .help("Specify the token bridge program address"), + ) + .arg( + Arg::with_name("core-bridge") + .validator(is_pubkey_or_keypair) + .value_name("CORE_BRIDGE_KEY") + .takes_value(true) + .index(2) + .required(true) + .help("Address of the Wormhole core bridge program"), + ), + ) + .get_matches(); + + let config = { + let cli_config = if let Some(config_file) = matches.value_of("config_file") { + solana_cli_config::Config::load(config_file).unwrap_or_default() + } else { + solana_cli_config::Config::default() + }; + let json_rpc_url = value_t!(matches, "json_rpc_url", String) + .unwrap_or_else(|_| cli_config.json_rpc_url.clone()); + + let client_keypair = || { + read_keypair_file(&cli_config.keypair_path).unwrap_or_else(|err| { + eprintln!("Unable to read {}: {}", cli_config.keypair_path, err); + exit(1) + }) + }; + + let owner = keypair_of(&matches, "owner").unwrap_or_else(client_keypair); + let fee_payer = keypair_of(&matches, "fee_payer").unwrap_or_else(client_keypair); + + Config { + rpc_client: RpcClient::new(json_rpc_url), + owner, + fee_payer, + commitment_config: CommitmentConfig::processed(), + } + }; + + let _ = match matches.subcommand() { + ("create-bridge", Some(arg_matches)) => { + let bridge = pubkey_of(arg_matches, "bridge").unwrap(); + let core_bridge = pubkey_of(arg_matches, "core-bridge").unwrap(); + + command_init_bridge(&config, &bridge, &core_bridge) + } + + _ => unreachable!(), + } + .and_then(|transaction| { + if let Some(transaction) = transaction { + let signature = config + .rpc_client + .send_and_confirm_transaction_with_spinner_and_config( + &transaction, + config.commitment_config, + RpcSendTransactionConfig { + skip_preflight: true, + preflight_commitment: None, + encoding: None, + }, + )?; + println!("Signature: {}", signature); + } + Ok(()) + }) + .map_err(|err| { + eprintln!("{}", err); + exit(1); + }); +} + +pub fn is_u8(amount: T) -> Result<(), String> +where + T: AsRef + Display, +{ + if amount.as_ref().parse::().is_ok() { + Ok(()) + } else { + Err(format!( + "Unable to parse input amount as integer, provided: {}", + amount + )) + } +} + +pub fn is_u32(amount: T) -> Result<(), String> +where + T: AsRef + Display, +{ + if amount.as_ref().parse::().is_ok() { + Ok(()) + } else { + Err(format!( + "Unable to parse input amount as integer, provided: {}", + amount + )) + } +} + +pub fn is_u64(amount: T) -> Result<(), String> +where + T: AsRef + Display, +{ + if amount.as_ref().parse::().is_ok() { + Ok(()) + } else { + Err(format!( + "Unable to parse input amount as integer, provided: {}", + amount + )) + } +} + +pub fn is_hex(value: T) -> Result<(), String> +where + T: AsRef + Display, +{ + hex::decode(value.to_string()) + .map(|_| ()) + .map_err(|e| format!("{}", e)) +} + +fn check_fee_payer_balance(config: &Config, required_balance: u64) -> Result<(), Error> { + let balance = config + .rpc_client + .get_balance_with_commitment( + &config.fee_payer.pubkey(), + CommitmentConfig { + commitment: CommitmentLevel::Processed, + }, + )? + .value; + if balance < required_balance { + Err(format!( + "Fee payer, {}, has insufficient balance: {} required, {} available", + config.fee_payer.pubkey(), + lamports_to_sol(required_balance), + lamports_to_sol(balance) + ) + .into()) + } else { + Ok(()) + } +}