From 35a14c7640979a4f4ef77756877936214d8566cc Mon Sep 17 00:00:00 2001 From: Paul Bellamy Date: Tue, 4 Oct 2022 02:40:00 -0700 Subject: [PATCH] Use new soroban-cli token create subcommand (#20) * Use soroban-cli token wrap subcommand * have to update xdr Identifier * Fix bug in account address parsing * upd soroban-examples * Use latest soroban-sdk, soroban-token-spec, and use Invoker for tests * update sdk again * soroban-cli -> soroban * recompiled the token spec to sdk 864a309b Co-authored-by: Leigh McCulloch <351529+leighmcculloch@users.noreply.github.com> --- Cargo.lock | 120 +++++++++++++++----- Cargo.toml | 22 ++-- contracts/crowdfund/Cargo.toml | 8 +- contracts/crowdfund/src/lib.rs | 39 ++++--- contracts/crowdfund/src/test.rs | 99 +++++++++------- contracts/token/soroban_token_contract.wasm | Bin 54338 -> 0 bytes contracts/token/soroban_token_spec.wasm | Bin 0 -> 9793 bytes initialize.sh | 31 ++--- next.config.js | 4 + pages/index.tsx | 66 +++++++---- 10 files changed, 241 insertions(+), 148 deletions(-) delete mode 100755 contracts/token/soroban_token_contract.wasm create mode 100755 contracts/token/soroban_token_spec.wasm diff --git a/Cargo.lock b/Cargo.lock index 4e26d6f..39d330d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -38,6 +38,12 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "base32" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23ce669cd6c8588f79e15cf450314f9638f967fc5770ff1c7c1deb0925ea7cfa" + [[package]] name = "base64" version = "0.13.0" @@ -79,9 +85,9 @@ checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" [[package]] name = "bytes-lit" -version = "0.0.3" +version = "0.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3a949b8abd1d84c29a91f4c8480dac1b426d53cebc9a31a8424a5cbe5be32f6" +checksum = "1c181bca161a49348b90fa75f9a54fe11b7138098eed90d841a1055d574b4250" dependencies = [ "num-bigint", "proc-macro2", @@ -216,7 +222,7 @@ checksum = "c762bae6dcaf24c4c84667b8579785430908723d5c889f469d76a41d59cc7a9d" dependencies = [ "curve25519-dalek", "ed25519", - "rand", + "rand 0.7.3", "serde", "sha2 0.9.9", "zeroize", @@ -252,7 +258,18 @@ checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" dependencies = [ "cfg-if", "libc", - "wasi", + "wasi 0.9.0+wasi-snapshot-preview1", +] + +[[package]] +name = "getrandom" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4eb1a864a501629691edf6c15a593b7a51eebaa1e8468e9ddc623de7c9b58ec6" +dependencies = [ + "cfg-if", + "libc", + "wasi 0.11.0+wasi-snapshot-preview1", ] [[package]] @@ -435,6 +452,16 @@ version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872" +[[package]] +name = "prettyplease" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a49e86d2c26a24059894a3afa13fd17d063419b05dfb83f06d9c3566060c3f5a" +dependencies = [ + "proc-macro2", + "syn", +] + [[package]] name = "proc-macro2" version = "1.0.43" @@ -459,13 +486,24 @@ version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" dependencies = [ - "getrandom", + "getrandom 0.1.16", "libc", - "rand_chacha", + "rand_chacha 0.2.2", "rand_core 0.5.1", "rand_hc", ] +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha 0.3.1", + "rand_core 0.6.4", +] + [[package]] name = "rand_chacha" version = "0.2.2" @@ -476,13 +514,23 @@ dependencies = [ "rand_core 0.5.1", ] +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core 0.6.4", +] + [[package]] name = "rand_core" version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" dependencies = [ - "getrandom", + "getrandom 0.1.16", ] [[package]] @@ -490,6 +538,9 @@ name = "rand_core" version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom 0.2.7", +] [[package]] name = "rand_hc" @@ -595,8 +646,10 @@ dependencies = [ [[package]] name = "soroban-auth" version = "0.0.4" -source = "git+https://github.com/stellar/rs-soroban-sdk?rev=bf6b383e#bf6b383ef4cc817223e7bd07725df468d880bb27" +source = "git+https://github.com/stellar/rs-soroban-sdk?rev=864a309b#864a309bca7ad91d6c7189fe87e018f64ad6ba06" dependencies = [ + "ed25519-dalek", + "rand 0.7.3", "soroban-sdk", ] @@ -604,20 +657,17 @@ dependencies = [ name = "soroban-crowdfund-contract" version = "0.0.0" dependencies = [ - "ed25519-dalek", - "rand", - "sha2 0.10.6", + "rand 0.7.3", "soroban-auth", "soroban-crowdfund-contract", "soroban-sdk", - "soroban-token-contract", "stellar-xdr 0.0.1", ] [[package]] name = "soroban-env-common" version = "0.0.5" -source = "git+https://github.com/stellar/rs-soroban-env?rev=0a826765#0a826765e9728e263ec3eafa3ed81a1d38a8716a" +source = "git+https://github.com/stellar/rs-soroban-env?rev=fb8a384e#fb8a384eb73b1d157c13b073efa9c82ff490119f" dependencies = [ "soroban-env-macros", "soroban-wasmi", @@ -628,7 +678,7 @@ dependencies = [ [[package]] name = "soroban-env-guest" version = "0.0.5" -source = "git+https://github.com/stellar/rs-soroban-env?rev=0a826765#0a826765e9728e263ec3eafa3ed81a1d38a8716a" +source = "git+https://github.com/stellar/rs-soroban-env?rev=fb8a384e#fb8a384eb73b1d157c13b073efa9c82ff490119f" dependencies = [ "soroban-env-common", "static_assertions", @@ -637,7 +687,7 @@ dependencies = [ [[package]] name = "soroban-env-host" version = "0.0.5" -source = "git+https://github.com/stellar/rs-soroban-env?rev=0a826765#0a826765e9728e263ec3eafa3ed81a1d38a8716a" +source = "git+https://github.com/stellar/rs-soroban-env?rev=fb8a384e#fb8a384eb73b1d157c13b073efa9c82ff490119f" dependencies = [ "backtrace", "dyn-fmt", @@ -660,7 +710,7 @@ dependencies = [ [[package]] name = "soroban-env-macros" version = "0.0.5" -source = "git+https://github.com/stellar/rs-soroban-env?rev=0a826765#0a826765e9728e263ec3eafa3ed81a1d38a8716a" +source = "git+https://github.com/stellar/rs-soroban-env?rev=fb8a384e#fb8a384eb73b1d157c13b073efa9c82ff490119f" dependencies = [ "itertools", "proc-macro2", @@ -672,7 +722,7 @@ dependencies = [ [[package]] name = "soroban-native-sdk-macros" version = "0.0.5" -source = "git+https://github.com/stellar/rs-soroban-env?rev=0a826765#0a826765e9728e263ec3eafa3ed81a1d38a8716a" +source = "git+https://github.com/stellar/rs-soroban-env?rev=fb8a384e#fb8a384eb73b1d157c13b073efa9c82ff490119f" dependencies = [ "itertools", "proc-macro2", @@ -683,19 +733,21 @@ dependencies = [ [[package]] name = "soroban-sdk" version = "0.0.4" -source = "git+https://github.com/stellar/rs-soroban-sdk?rev=bf6b383e#bf6b383ef4cc817223e7bd07725df468d880bb27" +source = "git+https://github.com/stellar/rs-soroban-sdk?rev=864a309b#864a309bca7ad91d6c7189fe87e018f64ad6ba06" dependencies = [ "bytes-lit", "ed25519-dalek", + "rand 0.8.5", "soroban-env-guest", "soroban-env-host", "soroban-sdk-macros", + "stellar-strkey", ] [[package]] name = "soroban-sdk-macros" version = "0.0.4" -source = "git+https://github.com/stellar/rs-soroban-sdk?rev=bf6b383e#bf6b383ef4cc817223e7bd07725df468d880bb27" +source = "git+https://github.com/stellar/rs-soroban-sdk?rev=864a309b#864a309bca7ad91d6c7189fe87e018f64ad6ba06" dependencies = [ "darling", "itertools", @@ -711,11 +763,12 @@ dependencies = [ [[package]] name = "soroban-spec" version = "0.0.4" -source = "git+https://github.com/stellar/rs-soroban-sdk?rev=bf6b383e#bf6b383ef4cc817223e7bd07725df468d880bb27" +source = "git+https://github.com/stellar/rs-soroban-sdk?rev=864a309b#864a309bca7ad91d6c7189fe87e018f64ad6ba06" dependencies = [ "base64", "darling", "itertools", + "prettyplease", "proc-macro2", "quote", "serde", @@ -729,16 +782,6 @@ dependencies = [ "wasmparser", ] -[[package]] -name = "soroban-token-contract" -version = "0.0.4" -source = "git+https://github.com/stellar/soroban-examples?rev=821dd95#821dd958275c6af827091c5fed75ed72f6dcbcc1" -dependencies = [ - "ed25519-dalek", - "soroban-auth", - "soroban-sdk", -] - [[package]] name = "soroban-wasmi" version = "0.16.0" @@ -773,6 +816,15 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" +[[package]] +name = "stellar-strkey" +version = "0.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "350ec80765002d972f7fa9bc2bd9e550fc3bf9fbe3f1c0e55b30755fccc2fd34" +dependencies = [ + "base32", +] + [[package]] name = "stellar-xdr" version = "0.0.1" @@ -782,7 +834,7 @@ checksum = "015594b09942b9f9cbe6972ba8c7de3a05a25c4994bbc7282f5f2fa6d28a81c4" [[package]] name = "stellar-xdr" version = "0.0.2" -source = "git+https://github.com/stellar/rs-stellar-xdr?rev=cebf5259#cebf52595c78fc3a4b5b40ba53ea1c0753777b5d" +source = "git+https://github.com/stellar/rs-stellar-xdr?rev=88ded341#88ded341ffbf54372ce851f766610ef978784d2a" dependencies = [ "base64", "serde", @@ -888,6 +940,12 @@ version = "0.9.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + [[package]] name = "wasmparser" version = "0.88.0" diff --git a/Cargo.toml b/Cargo.toml index fe564dc..a9c7b3a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,14 +16,14 @@ codegen-units = 1 lto = true [patch.crates-io] -soroban-sdk = { git = "https://github.com/stellar/rs-soroban-sdk", rev = "bf6b383e" } -soroban-spec = { git = "https://github.com/stellar/rs-soroban-sdk", rev = "bf6b383e" } -soroban-auth = { git = "https://github.com/stellar/rs-soroban-sdk", rev = "bf6b383e" } -soroban-sdk-macros = { git = "https://github.com/stellar/rs-soroban-sdk", rev = "bf6b383e" } -soroban-env-common = { git = "https://github.com/stellar/rs-soroban-env", rev = "0a826765" } -soroban-env-guest = { git = "https://github.com/stellar/rs-soroban-env", rev = "0a826765" } -soroban-env-host = { git = "https://github.com/stellar/rs-soroban-env", rev = "0a826765" } -soroban-env-macros = { git = "https://github.com/stellar/rs-soroban-env", rev = "0a826765" } -soroban-native-sdk-macros = { git = "https://github.com/stellar/rs-soroban-env", rev = "0a826765" } -stellar-xdr = { git = "https://github.com/stellar/rs-stellar-xdr", rev = "cebf5259" } -wasmi = { package = "soroban-wasmi", git = "https://github.com/stellar/wasmi", rev = "a61b6df" } \ No newline at end of file +soroban-sdk = { git = "https://github.com/stellar/rs-soroban-sdk", rev = "864a309b" } +soroban-spec = { git = "https://github.com/stellar/rs-soroban-sdk", rev = "864a309b" } +soroban-auth = { git = "https://github.com/stellar/rs-soroban-sdk", rev = "864a309b" } +soroban-sdk-macros = { git = "https://github.com/stellar/rs-soroban-sdk", rev = "864a309b" } +soroban-env-common = { git = "https://github.com/stellar/rs-soroban-env", rev = "fb8a384e" } +soroban-env-guest = { git = "https://github.com/stellar/rs-soroban-env", rev = "fb8a384e" } +soroban-env-host = { git = "https://github.com/stellar/rs-soroban-env", rev = "fb8a384e" } +soroban-env-macros = { git = "https://github.com/stellar/rs-soroban-env", rev = "fb8a384e" } +soroban-native-sdk-macros = { git = "https://github.com/stellar/rs-soroban-env", rev = "fb8a384e" } +stellar-xdr = { git = "https://github.com/stellar/rs-stellar-xdr", rev = "88ded341" } +wasmi = { package = "soroban-wasmi", git = "https://github.com/stellar/wasmi", rev = "a61b6df" } diff --git a/contracts/crowdfund/Cargo.toml b/contracts/crowdfund/Cargo.toml index 49ac25e..95f8613 100644 --- a/contracts/crowdfund/Cargo.toml +++ b/contracts/crowdfund/Cargo.toml @@ -10,21 +10,15 @@ crate-type = ["cdylib", "rlib"] [features] default = ["export"] export = [] -testutils = ["soroban-sdk/testutils", "soroban-auth/testutils", "soroban-token-contract/testutils", "dep:ed25519-dalek", "dep:sha2", "dep:stellar-xdr"] +testutils = ["soroban-sdk/testutils", "soroban-auth/testutils", "dep:stellar-xdr"] [dependencies] soroban-sdk = { version = "0.0.4" } soroban-auth = { version = "0.0.4" } stellar-xdr = { version = "0.0.1", features = ["next", "std"], optional = true } -ed25519-dalek = { version = "1.0.1", optional = true } -sha2 = { version = "0.10.2", optional = true } - -[target.'cfg(not(target_family="wasm"))'.dependencies] -soroban-token-contract = { git = "https://github.com/stellar/soroban-examples", rev = "821dd95", default-features = false, optional = true } [dev_dependencies] soroban-sdk = { version = "0.0.4", features = ["testutils"] } soroban-auth = { version = "0.0.4", features = ["testutils"] } -soroban-token-contract = { git = "https://github.com/stellar/soroban-examples", rev = "821dd95", default-features = false, features = ["testutils"] } soroban-crowdfund-contract = { path = ".", default-features = false, features = ["testutils"] } rand = { version = "0.7.3" } diff --git a/contracts/crowdfund/src/lib.rs b/contracts/crowdfund/src/lib.rs index c659096..b65233b 100644 --- a/contracts/crowdfund/src/lib.rs +++ b/contracts/crowdfund/src/lib.rs @@ -3,7 +3,7 @@ use soroban_auth::{Identifier, Signature}; use soroban_sdk::{contractimpl, contracttype, BigInt, BytesN, Env, IntoVal, RawVal}; mod token { - soroban_sdk::contractimport!(file = "../token/soroban_token_contract.wasm"); + soroban_sdk::contractimport!(file = "../token/soroban_token_spec.wasm"); } mod test; @@ -43,49 +43,49 @@ fn get_ledger_timestamp(e: &Env) -> u64 { } fn get_owner(e: &Env) -> Identifier { - e.contract_data() + e.data() .get(DataKey::Owner) .expect("not initialized") .unwrap() } fn get_deadline(e: &Env) -> u64 { - e.contract_data() + e.data() .get(DataKey::Deadline) .expect("not initialized") .unwrap() } fn get_started(e: &Env) -> u64 { - e.contract_data() + e.data() .get(DataKey::Started) .expect("not initialized") .unwrap() } fn get_target_amount(e: &Env) -> BigInt { - e.contract_data() + e.data() .get(DataKey::Target) .expect("not initialized") .unwrap() } fn get_token(e: &Env) -> BytesN<32> { - e.contract_data() + e.data() .get(DataKey::Token) .expect("not initialized") .unwrap() } fn get_user_deposited(e: &Env, user: &Identifier) -> BigInt { - e.contract_data() + e.data() .get(DataKey::User(user.clone())) .unwrap_or_else(|| Ok(BigInt::zero(&e))) .unwrap() } fn get_balance(e: &Env, contract_id: BytesN<32>) -> BigInt { - let client = token::ContractClient::new(&e, &contract_id); + let client = token::Client::new(&e, &contract_id); client.balance(&get_contract_id(e)) } @@ -106,13 +106,13 @@ fn get_state(e: &Env) -> State { } fn set_user_deposited(e: &Env, user: &Identifier, amount: BigInt) { - e.contract_data().set(DataKey::User(user.clone()), amount) + e.data().set(DataKey::User(user.clone()), amount) } fn transfer(e: &Env, contract_id: BytesN<32>, to: &Identifier, amount: &BigInt) { let nonce: BigInt = BigInt::zero(&e); - let client = token::ContractClient::new(&e, &contract_id); - client.xfer(&Signature::Contract, &nonce, to, amount); + let client = token::Client::new(&e, &contract_id); + client.xfer(&Signature::Invoker, &nonce, to, amount); } struct Crowdfund; @@ -134,16 +134,15 @@ impl Crowdfund { target_amount: BigInt, token: BytesN<32>, ) { - if e.contract_data().has(DataKey::Owner) { + if e.data().has(DataKey::Owner) { panic!("already initialized"); } - e.contract_data().set(DataKey::Owner, owner); - e.contract_data() - .set(DataKey::Started, get_ledger_timestamp(&e)); - e.contract_data().set(DataKey::Deadline, deadline); - e.contract_data().set(DataKey::Target, target_amount); - e.contract_data().set(DataKey::Token, token); + e.data().set(DataKey::Owner, owner); + e.data().set(DataKey::Started, get_ledger_timestamp(&e)); + e.data().set(DataKey::Deadline, deadline); + e.data().set(DataKey::Target, target_amount); + e.data().set(DataKey::Token, token); } pub fn deadline(e: Env) -> u64 { @@ -192,9 +191,9 @@ impl Crowdfund { set_user_deposited(&e, &user, balance + amount.clone()); let nonce = BigInt::zero(&e); - let client = token::ContractClient::new(&e, &get_token(&e)); + let client = token::Client::new(&e, &get_token(&e)); client.xfer_from( - &Signature::Contract, + &Signature::Invoker, &nonce, &user, &get_contract_id(&e), diff --git a/contracts/crowdfund/src/test.rs b/contracts/crowdfund/src/test.rs index 7250d59..95666fd 100644 --- a/contracts/crowdfund/src/test.rs +++ b/contracts/crowdfund/src/test.rs @@ -1,11 +1,13 @@ #![cfg(test)] +use super::token::{Client as Token, TokenMetadata}; use crate::testutils::{register_test_contract as register_crowdfund, Crowdfund}; -use ed25519_dalek::Keypair; use rand::{thread_rng, RngCore}; -use soroban_auth::Identifier; -use soroban_sdk::{testutils::LedgerInfo, BigInt, BytesN, Env, IntoVal}; -use soroban_token_contract::testutils::{register_test_contract as register_token, Token}; +use soroban_auth::{Identifier, Signature}; +use soroban_sdk::{ + testutils::{Accounts, Ledger}, + AccountId, BigInt, BytesN, Env, IntoVal, +}; fn generate_contract_id() -> [u8; 32] { let mut id: [u8; 32] = Default::default(); @@ -13,26 +15,25 @@ fn generate_contract_id() -> [u8; 32] { id } -fn generate_keypair() -> Keypair { - Keypair::generate(&mut thread_rng()) -} - -fn to_ed25519(e: &Env, kp: &Keypair) -> Identifier { - Identifier::Ed25519(kp.public.to_bytes().into_val(e)) -} - -fn create_token_contract(e: &Env, admin: &Keypair) -> (BytesN<32>, Token) { +fn create_token_contract(e: &Env, admin: &AccountId) -> (BytesN<32>, Token) { let id = generate_contract_id(); - register_token(&e, &id); + e.register_contract_token(&BytesN::from_array(e, &id)); let token = Token::new(e, &id); // decimals, name, symbol don't matter in tests - token.initialize(&to_ed25519(&e, admin), 7, "name", "symbol"); + token.init( + &Identifier::Account(admin.clone()), + &TokenMetadata { + name: "name".into_val(&e), + symbol: "symbol".into_val(&e), + decimals: 7, + }, + ); (BytesN::from_array(&e, &id), token) } fn create_crowdfund_contract( e: &Env, - owner: &Keypair, + owner: &AccountId, deadline: &u64, target_amount: &BigInt, token: &BytesN<32>, @@ -40,25 +41,24 @@ fn create_crowdfund_contract( let id = generate_contract_id(); register_crowdfund(&e, &id); let crowdfund = Crowdfund::new(e, &id); - crowdfund - .client() - .initialize(&to_ed25519(&e, owner), &deadline, &target_amount, &token); + crowdfund.client().initialize( + &Identifier::Account(owner.clone()), + &deadline, + &target_amount, + &token, + ); (BytesN::from_array(&e, &id), crowdfund) } fn advance_ledger(e: &Env, delta: u64) { - e.set_ledger(LedgerInfo { - protocol_version: e.ledger().protocol_version(), - sequence_number: e.ledger().sequence(), - timestamp: e.ledger().timestamp() + delta, - base_reserve: 1, // TODO: can't get current base reserve... does this matter for tests? - network_passphrase: Default::default(), //TODO: Figure out how to go from Bytes to Vec so we can use ledger.network_passphrase? + e.ledger().with_mut(|l| { + l.timestamp += delta; }); } struct Setup { env: Env, - user2: Keypair, + user2: AccountId, owner_id: Identifier, user1_id: Identifier, user2_id: Identifier, @@ -75,28 +75,43 @@ struct Setup { impl Setup { fn new() -> Self { let e: Env = Default::default(); - let owner = generate_keypair(); - let owner_id = to_ed25519(&e, &owner); - let user1 = generate_keypair(); - let user1_id = to_ed25519(&e, &user1); - let user2 = generate_keypair(); - let user2_id = to_ed25519(&e, &user2); + let owner = e.accounts().generate_and_create(); + let owner_id = Identifier::Account(owner.clone()); + let user1 = e.accounts().generate_and_create(); + let user1_id = Identifier::Account(user1.clone()); + let user2 = e.accounts().generate_and_create(); + let user2_id = Identifier::Account(user2.clone()); // the deadline is 10 seconds from now let deadline = e.ledger().timestamp() + 10; let target_amount = BigInt::from_i32(&e, 15); - let token_admin = generate_keypair(); + let token_admin = e.accounts().generate_and_create(); let (contract_token, token) = create_token_contract(&e, &token_admin); let (contract_crowdfund, crowdfund) = create_crowdfund_contract(&e, &owner, &deadline, &target_amount, &contract_token); let crowdfund_id = Identifier::Contract(contract_crowdfund); - token.mint(&token_admin, &user1_id, &BigInt::from_u32(&e, 10)); - token.mint(&token_admin, &user2_id, &BigInt::from_u32(&e, 5)); - - token.approve(&user1, &crowdfund_id, &BigInt::from_u32(&e, 10)); + token.with_source_account(&token_admin).mint( + &Signature::Invoker, + &BigInt::zero(&e), + &user1_id, + &BigInt::from_u32(&e, 10), + ); + token.with_source_account(&token_admin).mint( + &Signature::Invoker, + &BigInt::zero(&e), + &user2_id, + &BigInt::from_u32(&e, 5), + ); + + token.with_source_account(&user1).approve( + &Signature::Invoker, + &BigInt::zero(&e), + &crowdfund_id, + &BigInt::from_u32(&e, 10), + ); crowdfund .client() .deposit(&user1_id, &BigInt::from_u32(&e, 10)); @@ -134,8 +149,9 @@ fn test_expired() { #[test] fn test_success() { let setup = Setup::new(); - setup.token.approve( - &setup.user2, + setup.token.with_source_account(&setup.user2).approve( + &Signature::Invoker, + &BigInt::zero(&setup.env), &setup.crowdfund_id, &BigInt::from_u32(&setup.env, 5), ); @@ -189,8 +205,9 @@ fn sale_still_running() { #[should_panic(expected = "sale was successful, only the owner may withdraw")] fn sale_successful_only_owner() { let setup = Setup::new(); - setup.token.approve( - &setup.user2, + setup.token.with_source_account(&setup.user2).approve( + &Signature::Invoker, + &BigInt::zero(&setup.env), &setup.crowdfund_id, &BigInt::from_u32(&setup.env, 5), ); diff --git a/contracts/token/soroban_token_contract.wasm b/contracts/token/soroban_token_contract.wasm deleted file mode 100755 index f158a5489d4458a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iuEZ z-BTA#oHC_uYFs6gCYfa`<{=s~cd<~}uzrs`51(`tNX8AkOXg3Q)JB2`~Y-=ISzhnT5>5$HS(IFY&AFp?? zF_q&|&I9GRpzmnhWjGb{OL2(u`=a;2h|qIdE?&~nvfy0pr%;cj!u=4W8B0oq9!ngD p_I&q69i0r5iA>tqcg8Gm4&;yXRz60zyie32Zf4MTNZ&qj`+xS~Fhc+U diff --git a/contracts/token/soroban_token_spec.wasm b/contracts/token/soroban_token_spec.wasm new file mode 100755 index 0000000000000000000000000000000000000000..ed5e0943f3df555268b975b5d63eaf19e8fd0a04 GIT binary patch literal 9793 zcmcIqU2I%O6`r5F_BtCko6sL8O~ZAlg#DJ3HVH4qyHy|+0;K^#-<-9*Y3$g$#@?h! z5w=B8jU1-r3E@ z`9a+%zH?{hoH^&rcfOgOSyh>y&`K%&xxz^^JEKnO89j5-%XSLedvD?n-(%jsdD$J_VqJJ*&*?C#t+c8m{s83xmDjKbgHq^GR%J_Kw z=}K+5iuTInU9Oizyv zt760+YI`(vcB+QQ#AvOdws%ce8-tY*yr>=dv$aGpSF3ZR?yk{k>U^eJQ{7RmGEs%y z(-$U&>f>r>exy1)I#C&)MiJvoPgJHFs;CFm?rnpEBb7#Fuv#0jx-d9+x>}hW9I8xL zt=abNLp={@Jrk>b3zPQi@{WsTeIgoAg;1Z@y24cgP;$ho^_MWjmqe_$C=tk#$+tX{yYP%^E%DT|2V-?%OHjjrsY^f|B zdr%b?BCTgJ#D-4BSk_~)Dt1wGzg^assEfrFh^=atORIVeHXpWYcrCqv{-(61$BOr` z+Y9>A(Qai1ocxmBugZ%rzyIFy^A@hfs{H!mPrm==^U)LC8ZV2#eeoY3E&ffP=(b)* zzNEh>FYBsF?J;O&pChR4x5ta0h)th4an35kbESFQ(~xELWhXo727a^;$~3aao&kBB9cAmUnxh-(=l=FDL`kHEr+dE*eVz?Ul${{`a_ais|n zS8oRq)R7{>0WDQ4KqDk%y8G>tc5^eYQ&gnlwCZxRRhJV~th2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>Su8c%unJA%jvZ;%C{AV?7En0Zb>#LJ>i#JPv5?erctMcwsE|Xf5BzB zj7}R`V|BCGhV#&hxjV7R-OD@wTQU9r*m9#7BtH^h0LTruJLXooL7n`#9~s=4Pj?c- z;MWW?{+;;MRjWSje-S|)ZE+>a@hAJm#K#xIke4|w^O67gN%)*)){)2g3Avr`VO#cF z4QF#Wk2k|vh$V7S@(F)u!aBzN|J6&Iw@=rn>O+;f7nwSsETD8K%0Y(GefFHo3Mzw;srvwk_2y z9qnH|R&Hctt1qpwX3RPtubson?G{eHdw*#MY!)oG)8FZB5BqK9Ppd7h{6$;xkNNF~ z8(U%*qugRsR^Mzxy6(4*wJQzq@ydnqdS&EmZeK$@b=Inlr|VN^P;`5eWQP;XX@dC< h^oc4{Pa*n@y?i)Vt>YD2$3q{^zwzTHacyhY{{Xjb+@=5k literal 0 HcmV?d00001 diff --git a/initialize.sh b/initialize.sh index 17fdd9b..7fcd8b4 100755 --- a/initialize.sh +++ b/initialize.sh @@ -3,31 +3,32 @@ set -e # TODO: Set the owner to something reasonable here. Probably whatever account -# soroban-cli is running stuff as? -admin="AAAABAAAAAEAAAAAAAAAAgAAAAUAAAAHQWNjb3VudAAAAAAEAAAAAQAAAAQAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=" +# soroban is running stuff as? +# This is an Identifier for Account GAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAWHF +# TODO: Have a nicer way to build Identifiers on the CLI +admin="AAAABAAAAAEAAAAAAAAAAgAAAAUAAAAHQWNjb3VudAAAAAAEAAAAAQAAAAcAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" echo Deploy the token contract -soroban-cli deploy --id 1 --wasm contracts/token/soroban_token_contract.wasm - -echo Initialize the token contract -soroban-cli invoke --id 1 \ - --fn initialize \ - --arg-xdr "$admin" \ - --arg-xdr AAAAAQAAAAc= \ - --arg-xdr AAAABAAAAAEAAAAEAAAAEENpcmNsZSBVUyBEb2xsYXI= \ - --arg-xdr AAAABAAAAAEAAAAEAAAABFVTREM= +TOKEN_ID="$( + soroban token create \ + --name "Example Token" \ + --symbol "EXT" \ + --decimal 2 +)" +mkdir -p .soroban +echo "$TOKEN_ID" > .soroban/token_id echo Build the crowdfund contract -cargo build --release --target wasm32-unknown-unknown +make build echo Deploy the crowdfund contract -soroban-cli deploy --id 0 --wasm target/wasm32-unknown-unknown/release/soroban_crowdfund_contract.wasm +soroban deploy --id 0 --wasm target/wasm32-unknown-unknown/release/soroban_crowdfund_contract.wasm echo Initialize the crowdfund contract deadline="$(($(date +"%s") + 86400))" -soroban-cli invoke --id 0 \ +soroban invoke --id 0 \ --fn initialize \ --arg-xdr "$admin" \ --arg "$deadline" \ --arg "1000000000" \ - --arg '[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]' + --arg "$TOKEN_ID" diff --git a/next.config.js b/next.config.js index 3dd7ef1..d37a6ab 100644 --- a/next.config.js +++ b/next.config.js @@ -1,4 +1,8 @@ +var fs = require('fs'); /** @type {import('next').NextConfig} */ module.exports = { reactStrictMode: true, + env: { + TOKEN_ID: fs.readFileSync('.soroban/token_id').toString().trim(), + }, }; diff --git a/pages/index.tsx b/pages/index.tsx index 6fffbf9..a6fe70e 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -5,32 +5,25 @@ import Head from 'next/head'; import * as SorobanSdk from 'soroban-sdk'; import styles from '../styles/Home.module.css'; import * as convert from "../convert"; -import { useNetwork, useAccount, useContractValue, useSendTransaction, ConnectButton } from "../wallet"; +import { ContractValue, useNetwork, useAccount, useContractValue, useSendTransaction, ConnectButton } from "../wallet"; let xdr = SorobanSdk.xdr; // Stub dummy data for now. const source = new SorobanSdk.Account('GCEZWKCA5VLDNRLN3RPRJMRZOX3Z6G5CHCGSNFHEYVXM3XOJMDS674JZ', '0'); const CROWDFUND_ID = "0000000000000000000000000000000000000000000000000000000000000000"; -const TOKEN_ID = "0000000000000000000000000000000000000000000000000000000000000001"; +const TOKEN_ID: string = process.env.TOKEN_ID ?? ""; const Home: NextPage = () => { const { data: account } = useAccount(); // Call the contract rpcs to fetch values const token = { - balance: useContractValue(TOKEN_ID, "balance", xdr.ScVal.scvObject(xdr.ScObject.scoVec([ - xdr.ScVal.scvSymbol("Account"), - xdr.ScVal.scvObject(xdr.ScObject.scoBytes(Buffer.from(CROWDFUND_ID, 'hex'))) - ]))), + balance: useContractValue(TOKEN_ID, "balance", accountIdentifier(Buffer.from(CROWDFUND_ID, 'hex'))), decimals: useContractValue(TOKEN_ID, "decimals"), name: useContractValue(TOKEN_ID, "name"), symbol: useContractValue(TOKEN_ID, "symbol"), }; const deadline = useContractValue(CROWDFUND_ID, "deadline"); const started = useContractValue(CROWDFUND_ID, "started"); - const yourDepositsXdr = useContractValue(CROWDFUND_ID, "balance", xdr.ScVal.scvObject(xdr.ScObject.scoVec([ - xdr.ScVal.scvSymbol("Account"), - xdr.ScVal.scvObject(account ? xdr.ScObject.scoBytes(Buffer.from(account.address)) : null) - ]))); // Convert the result ScVals to js types const tokenBalance = convert.scvalToBigNumber(token.balance.result); @@ -39,7 +32,6 @@ const Home: NextPage = () => { const tokenSymbol = token.symbol.result && convert.scvalToString(token.symbol.result); const deadlineDate = deadline.result && new Date(convert.xdrUint64ToNumber(deadline.result.obj()?.u64() ?? xdr.Int64.fromString("0")) * 1000); const startedDate = started.result && new Date(convert.xdrUint64ToNumber(started.result.obj()?.u64() ?? xdr.Int64.fromString("0")) * 1000); - const yourDeposits = convert.scvalToBigNumber(yourDepositsXdr.result); return (
@@ -89,13 +81,7 @@ const Home: NextPage = () => { )}
- Your Deposits: {yourDepositsXdr.loading || token.decimals.loading || token.name.loading || token.symbol.loading ? ( - Loading... - ) : yourDeposits ? ( - {formatAmount(yourDeposits, tokenDecimals)} {tokenSymbol} - ) : ( - {JSON.stringify(yourDepositsXdr.error)} - )} + Your Deposits:
)} @@ -112,11 +98,7 @@ function DepositForm({account, decimals}: {account: {address: string}, decimals: const { activeChain } = useNetwork(); const networkPassphrase = activeChain?.networkPassphrase ?? ""; - const user = xdr.ScVal.scvObject(xdr.ScObject.scoVec([ - xdr.ScVal.scvSymbol("Account"), - // TODO: Parse this as an address or whatever. - xdr.ScVal.scvObject(xdr.ScObject.scoBytes(Buffer.from(account.address, 'hex'))) - ])); + const user = accountIdentifier(SorobanSdk.StrKey.decodeEd25519PublicKey(account.address)); const spender = xdr.ScVal.scvObject(xdr.ScObject.scoVec([ xdr.ScVal.scvSymbol("Contract"), // TODO: Parse this as an address or whatever. @@ -156,6 +138,33 @@ function DepositForm({account, decimals}: {account: {address: string}, decimals: ); } +function YourDeposits( + {account, token}: { + account: {address: string}, + token: { + decimals: ContractValue, + name: ContractValue, + symbol: ContractValue + } + } +) { + const yourDepositsXdr = useContractValue(CROWDFUND_ID, "balance", accountIdentifier(SorobanSdk.StrKey.decodeEd25519PublicKey(account.address))); + + if (token.decimals.loading || token.name.loading || token.symbol.loading) { + return Loading...; + } + if (token.decimals.error || token.name.error || token.symbol.error) { + return {JSON.stringify(token.decimals.error || token.name.error || token.symbol.error)}; + } + + const yourDeposits = convert.scvalToBigNumber(yourDepositsXdr.result); + const tokenDecimals = token.decimals.result && (token.decimals.result?.u32() ?? 7); + const tokenName = token.name.result && convert.scvalToString(token.name.result); + const tokenSymbol = token.symbol.result && convert.scvalToString(token.symbol.result); + + return {formatAmount(yourDeposits, tokenDecimals)} {tokenSymbol}; +} + // Small helper to build a contract invokation transaction function contractTransaction(networkPassphrase: string, contractId: string, method: string, ...params: SorobanSdk.xdr.ScVal[]): SorobanSdk.Transaction { const contract = new SorobanSdk.Contract(contractId); @@ -169,4 +178,15 @@ function contractTransaction(networkPassphrase: string, contractId: string, meth .build(); } +function accountIdentifier(account: Buffer): SorobanSdk.xdr.ScVal { + return xdr.ScVal.scvObject( + xdr.ScObject.scoVec([ + xdr.ScVal.scvSymbol("Account"), + xdr.ScVal.scvObject( + xdr.ScObject.scoAccountId(xdr.PublicKey.publicKeyTypeEd25519(account)) + ) + ]) + ); +} + export default Home