diff --git a/Cargo.lock b/Cargo.lock index c98051e..5f65090 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -165,9 +165,9 @@ dependencies = [ "aurora-engine-precompiles", "aurora-engine-sdk", "aurora-engine-transactions", - "aurora-engine-types", + "aurora-engine-types 1.0.0 (git+https://github.com/aurora-is-near/aurora-engine.git?rev=d9763085157188055f62752fd499ac4c7db8331e)", "bitflags", - "borsh", + "borsh 0.9.3", "byte-slice-cast", "ethabi", "evm", @@ -184,8 +184,8 @@ version = "1.0.0" source = "git+https://github.com/aurora-is-near/aurora-engine.git?rev=d9763085157188055f62752fd499ac4c7db8331e#d9763085157188055f62752fd499ac4c7db8331e" dependencies = [ "aurora-engine-sdk", - "aurora-engine-types", - "borsh", + "aurora-engine-types 1.0.0 (git+https://github.com/aurora-is-near/aurora-engine.git?rev=d9763085157188055f62752fd499ac4c7db8331e)", + "borsh 0.9.3", "ethabi", "evm", "hex 0.4.3", @@ -202,9 +202,9 @@ name = "aurora-engine-sdk" version = "1.0.0" source = "git+https://github.com/aurora-is-near/aurora-engine.git?rev=d9763085157188055f62752fd499ac4c7db8331e#d9763085157188055f62752fd499ac4c7db8331e" dependencies = [ - "aurora-engine-types", + "aurora-engine-types 1.0.0 (git+https://github.com/aurora-is-near/aurora-engine.git?rev=d9763085157188055f62752fd499ac4c7db8331e)", "base64 0.21.0", - "borsh", + "borsh 0.9.3", "sha2 0.10.6", "sha3", ] @@ -216,18 +216,31 @@ source = "git+https://github.com/aurora-is-near/aurora-engine.git?rev=d976308515 dependencies = [ "aurora-engine-precompiles", "aurora-engine-sdk", - "aurora-engine-types", + "aurora-engine-types 1.0.0 (git+https://github.com/aurora-is-near/aurora-engine.git?rev=d9763085157188055f62752fd499ac4c7db8331e)", "evm", "rlp", "serde", ] +[[package]] +name = "aurora-engine-types" +version = "1.0.0" +source = "git+https://github.com/aurora-is-near/aurora-engine.git?tag=2.9.0#5b0054859b779b2aed2c819d12751cebd00be42d" +dependencies = [ + "borsh 0.10.3", + "borsh 0.9.3", + "hex 0.4.3", + "primitive-types 0.12.1", + "serde", + "serde_json", +] + [[package]] name = "aurora-engine-types" version = "1.0.0" source = "git+https://github.com/aurora-is-near/aurora-engine.git?rev=d9763085157188055f62752fd499ac4c7db8331e#d9763085157188055f62752fd499ac4c7db8331e" dependencies = [ - "borsh", + "borsh 0.9.3", "hex 0.4.3", "primitive-types 0.12.1", "serde", @@ -241,9 +254,9 @@ dependencies = [ "anyhow", "aurora-engine", "aurora-engine-sdk", - "aurora-engine-types", + "aurora-engine-types 1.0.0 (git+https://github.com/aurora-is-near/aurora-engine.git?rev=d9763085157188055f62752fd499ac4c7db8331e)", "aurora-workspace-types", - "borsh", + "borsh 0.9.3", "ethabi", "ethereum-types", "hex 0.4.3", @@ -262,10 +275,10 @@ name = "aurora-workspace-eth-connector" version = "0.1.0" dependencies = [ "anyhow", - "aurora-engine-types", + "aurora-engine-types 1.0.0 (git+https://github.com/aurora-is-near/aurora-engine.git?tag=2.9.0)", "aurora-workspace-types", "aurora-workspace-utils", - "borsh", + "borsh 0.9.3", "hex 0.4.3", "lazy_static", "near-contract-standards", @@ -280,7 +293,7 @@ dependencies = [ name = "aurora-workspace-types" version = "0.1.0" dependencies = [ - "aurora-engine-types", + "aurora-engine-types 1.0.0 (git+https://github.com/aurora-is-near/aurora-engine.git?rev=d9763085157188055f62752fd499ac4c7db8331e)", "ethereum-types", "hex 0.4.3", "near-account-id 0.15.0", @@ -296,7 +309,7 @@ version = "0.1.0" dependencies = [ "anyhow", "aurora-workspace-types", - "borsh", + "borsh 0.9.3", "near-sdk", "near-units", "serde", @@ -463,7 +476,17 @@ version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "15bf3650200d8bffa99015595e10f1fbd17de07abbc25bb067da79e769939bfa" dependencies = [ - "borsh-derive", + "borsh-derive 0.9.3", + "hashbrown 0.11.2", +] + +[[package]] +name = "borsh" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4114279215a005bc675e386011e594e1d9b800918cea18fcadadcce864a2046b" +dependencies = [ + "borsh-derive 0.10.3", "hashbrown 0.11.2", ] @@ -473,8 +496,21 @@ version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6441c552f230375d18e3cc377677914d2ca2b0d36e52129fe15450a2dce46775" dependencies = [ - "borsh-derive-internal", - "borsh-schema-derive-internal", + "borsh-derive-internal 0.9.3", + "borsh-schema-derive-internal 0.9.3", + "proc-macro-crate 0.1.5", + "proc-macro2", + "syn 1.0.109", +] + +[[package]] +name = "borsh-derive" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0754613691538d51f329cce9af41d7b7ca150bc973056f1156611489475f54f7" +dependencies = [ + "borsh-derive-internal 0.10.3", + "borsh-schema-derive-internal 0.10.3", "proc-macro-crate 0.1.5", "proc-macro2", "syn 1.0.109", @@ -491,6 +527,17 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "borsh-derive-internal" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afb438156919598d2c7bad7e1c0adf3d26ed3840dbc010db1a882a65583ca2fb" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "borsh-schema-derive-internal" version = "0.9.3" @@ -502,6 +549,17 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "borsh-schema-derive-internal" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "634205cc43f74a1b9046ef87c4540ebda95696ec0f315024860cad7c5b0f5ccd" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "bs58" version = "0.4.0" @@ -1800,7 +1858,7 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "885db39b08518fa700b73fa2214e8adbbfba316ba82dd510f50519173eadaf73" dependencies = [ - "borsh", + "borsh 0.9.3", "schemars", "semver", "serde", @@ -1812,7 +1870,7 @@ version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "71d258582a1878e6db67400b0504a5099db85718d22c2e07f747fe1706ae7150" dependencies = [ - "borsh", + "borsh 0.9.3", "serde", ] @@ -1822,7 +1880,7 @@ version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1d924011380de759c3dc6fdbcda37a19a5c061f56dab69d28a34ecee765e23e4" dependencies = [ - "borsh", + "borsh 0.9.3", "serde", ] @@ -1865,7 +1923,7 @@ checksum = "1e75673d69fd7365508f3d32483669fe45b03bfb34e4d9363e90adae9dfb416c" dependencies = [ "arrayref", "blake2", - "borsh", + "borsh 0.9.3", "bs58", "c2-chacha", "curve25519-dalek", @@ -1891,7 +1949,7 @@ checksum = "7754612b47737d277fb818e9fdbb1406e90f9e57151c55c3584d714421976cb6" dependencies = [ "arrayref", "blake2", - "borsh", + "borsh 0.9.3", "bs58", "c2-chacha", "curve25519-dalek", @@ -1914,7 +1972,7 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d1335ffce1476da6516dcd22b26cece1a495fc725c0e8fec1879073752ac068d" dependencies = [ - "borsh", + "borsh 0.9.3", "lazy_static", "log", "near-chain-configs", @@ -1949,7 +2007,7 @@ version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ad1a9a1640539c81f065425c31bffcfbf6b31ef1aeaade59ce905f5df6ac860" dependencies = [ - "borsh", + "borsh 0.9.3", "byteorder", "bytesize", "chrono", @@ -1978,7 +2036,7 @@ version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97670b302dce15f09bba50f24c67aa08130fd01528cc61d4415892401e88e974" dependencies = [ - "borsh", + "borsh 0.9.3", "byteorder", "bytesize", "cfg-if 1.0.0", @@ -2009,7 +2067,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "91d508f0fc340f6461e4e256417685720d3c4c00bb5a939b105160e49137caba" dependencies = [ "base64 0.11.0", - "borsh", + "borsh 0.9.3", "bs58", "derive_more", "near-account-id 0.14.0", @@ -2026,7 +2084,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7929e19d862221949734c4a0063a8f55e7069de3a2ebc2d4f4c13497a5e953cb" dependencies = [ "base64 0.13.1", - "borsh", + "borsh 0.9.3", "bs58", "derive_more", "near-account-id 0.15.0", @@ -2103,7 +2161,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "15eb3de2defe3626260cc209a6cdb985c6b27b0bd4619fad97dcfae002c3c5bd" dependencies = [ "base64 0.13.1", - "borsh", + "borsh 0.9.3", "bs58", "near-abi", "near-crypto 0.14.0", @@ -2175,7 +2233,7 @@ version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d0da466a30f0446639cbd788c30865086fac3e8dcb07a79e51d2b0775ed4261e" dependencies = [ - "borsh", + "borsh 0.9.3", "near-account-id 0.14.0", "near-rpc-error-macro 0.14.0", "serde", @@ -2187,7 +2245,7 @@ version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5591c9c8afa83a040cb5c3f29bc52b2efae2c32d4bcaee1bba723738da1a5cf6" dependencies = [ - "borsh", + "borsh 0.9.3", "near-account-id 0.15.0", "near-rpc-error-macro 0.15.0", "serde", @@ -2201,7 +2259,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "81b534828419bacbf1f7b11ef7b00420f248c548c485d3f0cfda8bb6931152f2" dependencies = [ "base64 0.13.1", - "borsh", + "borsh 0.9.3", "bs58", "byteorder", "near-account-id 0.14.0", @@ -3954,7 +4012,7 @@ dependencies = [ "async-process", "async-trait", "base64 0.13.1", - "borsh", + "borsh 0.9.3", "bs58", "chrono", "dirs 3.0.2", @@ -4028,7 +4086,7 @@ version = "0.5.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "71e61de68ede9ffdd69c01664f65a178c5188b73f78faa21f0936016a888ff7c" dependencies = [ - "borsh", + "borsh 0.9.3", "byteorder", "crunchy", "lazy_static", diff --git a/res/mock_eth_connector/src/connector.rs b/res/mock_eth_connector/src/connector.rs index d9a3faa..e8dac04 100644 --- a/res/mock_eth_connector/src/connector.rs +++ b/res/mock_eth_connector/src/connector.rs @@ -19,7 +19,7 @@ pub struct FinishDepositCallArgs { pub msg: Option>, } -#[derive(BorshSerialize, BorshDeserialize)] +#[derive(Debug, BorshSerialize, BorshDeserialize)] pub struct WithdrawResult { pub amount: Balance, pub recipient_id: Address, @@ -35,6 +35,13 @@ pub trait ConnectorDeposit { pub trait ConnectorWithdraw { #[result_serializer(borsh)] fn withdraw( + &mut self, + #[serializer(borsh)] recipient_address: Address, + #[serializer(borsh)] amount: Balance, + ) -> WithdrawResult; + + #[result_serializer(borsh)] + fn engine_withdraw( &mut self, #[serializer(borsh)] sender_id: AccountId, #[serializer(borsh)] recipient_address: Address, diff --git a/res/mock_eth_connector/src/lib.rs b/res/mock_eth_connector/src/lib.rs index 5c2466b..e4407a2 100644 --- a/res/mock_eth_connector/src/lib.rs +++ b/res/mock_eth_connector/src/lib.rs @@ -212,11 +212,26 @@ impl ConnectorWithdraw for EthConnectorContract { #[payable] #[result_serializer(borsh)] fn withdraw( + &mut self, + #[serializer(borsh)] recipient_address: Address, + #[serializer(borsh)] amount: Balance, + ) -> WithdrawResult { + WithdrawResult { + recipient_id: recipient_address, + amount, + eth_custodian_address: Address::decode(CUSTODIAN_ADDRESS).unwrap(), + } + } + + #[payable] + #[result_serializer(borsh)] + fn engine_withdraw( &mut self, #[serializer(borsh)] sender_id: AccountId, #[serializer(borsh)] recipient_address: Address, #[serializer(borsh)] amount: Balance, ) -> WithdrawResult { + let _ = sender_id; WithdrawResult { recipient_id: recipient_address, amount, diff --git a/workspace-eth-connector/Cargo.toml b/workspace-eth-connector/Cargo.toml index 0dc8d63..6a75330 100644 --- a/workspace-eth-connector/Cargo.toml +++ b/workspace-eth-connector/Cargo.toml @@ -7,7 +7,7 @@ description = "Aurora Workspace Eth Connector is a library for the Aurora Eth Co [dependencies] anyhow = "1" -aurora-engine-types = { git = "https://github.com/aurora-is-near/aurora-engine.git", rev = "d9763085157188055f62752fd499ac4c7db8331e", features = ["impl-serde"] } +aurora-engine-types = { git = "https://github.com/aurora-is-near/aurora-engine.git", tag = "2.9.0", default-features = false, features = ["impl-serde", "borsh-compat"] } aurora-workspace-types = { path = "../workspace-types" } aurora-workspace-utils = { path = "../workspace-utils" } borsh = { version = "0.9", default-features = false } diff --git a/workspace-eth-connector/src/contract.rs b/workspace-eth-connector/src/contract.rs index ec756b9..467b613 100644 --- a/workspace-eth-connector/src/contract.rs +++ b/workspace-eth-connector/src/contract.rs @@ -1,11 +1,11 @@ use crate::operation::{ CallDeposit, CallEngineFtTransfer, CallEngineFtTransferCall, CallEngineStorageDeposit, - CallEngineStorageUnregister, CallEngineStorageWithdraw, CallFtTransfer, CallFtTransferCall, - CallMigrate, CallNew, CallRemoveEngineAccount, CallSetAccessRight, CallSetEngineAccount, - CallSetPausedFlags, CallStorageDeposit, CallStorageUnregister, CallStorageWithdraw, - CallWithdraw, ViewCheckMigrationCorrectness, ViewFtBalanceOf, ViewFtMetadata, - ViewFtTotalSupply, ViewGetAccessRight, ViewGetAccountsCounter, ViewGetBridgeProver, - ViewGetEngineAccounts, ViewGetPausedFlags, ViewIsOwner, ViewIsUsedProof, + CallEngineStorageUnregister, CallEngineStorageWithdraw, CallEngineWithdraw, CallFtTransfer, + CallFtTransferCall, CallMigrate, CallNew, CallRemoveEngineAccount, CallSetAccessRight, + CallSetEngineAccount, CallSetPausedFlags, CallStorageDeposit, CallStorageUnregister, + CallStorageWithdraw, CallWithdraw, ViewCheckMigrationCorrectness, ViewFtBalanceOf, + ViewFtMetadata, ViewFtTotalSupply, ViewGetAccessRight, ViewGetAccountsCounter, + ViewGetBridgeProver, ViewGetEngineAccounts, ViewGetPausedFlags, ViewIsOwner, ViewIsUsedProof, ViewStorageBalanceBounds, ViewStorageBalanceOf, }; use crate::types::{MigrationInputData, PausedMask, Proof}; @@ -196,13 +196,17 @@ impl EthConnectorContract { CallSetAccessRight::call(&self.contract).args_json((account,)) } - pub fn withdraw( + pub fn withdraw(&self, recipient_address: Address, amount: Balance) -> CallWithdraw { + CallWithdraw::call(&self.contract).args_borsh((recipient_address, amount)) + } + + pub fn engine_withdraw( &self, sender_id: AccountId, recipient_address: Address, amount: Balance, - ) -> CallWithdraw { - CallWithdraw::call(&self.contract).args_borsh((sender_id, recipient_address, amount)) + ) -> CallEngineWithdraw { + CallEngineWithdraw::call(&self.contract).args_borsh((sender_id, recipient_address, amount)) } pub fn deposit(&self, raw_proof: Proof) -> CallDeposit { diff --git a/workspace-eth-connector/src/operation.rs b/workspace-eth-connector/src/operation.rs index 6c28085..82bfd3a 100644 --- a/workspace-eth-connector/src/operation.rs +++ b/workspace-eth-connector/src/operation.rs @@ -34,6 +34,7 @@ impl_call_return![ (CallEngineStorageUnregister => bool, Call::EngineStorageUnregister, json), (CallEngineStorageWithdraw => StorageBalance, Call::EngineStorageWithdraw, json), (CallWithdraw => WithdrawResult, Call::Withdraw, borsh), + (CallEngineWithdraw => WithdrawResult, Call::EngineWithdraw, borsh), ]; impl_view_return![ @@ -56,6 +57,7 @@ impl_view_return![ pub(crate) enum Call { New, Withdraw, + EngineWithdraw, Deposit, FtTransfer, FtTransferCall, @@ -80,6 +82,7 @@ impl AsRef for Call { match self { New => "new", Withdraw => "withdraw", + EngineWithdraw => "engine_withdraw", Deposit => "deposit", FtTransfer => "ft_transfer", FtTransferCall => "ft_transfer_call", diff --git a/workspace-eth-connector/src/types.rs b/workspace-eth-connector/src/types.rs index fbb8169..07500e2 100644 --- a/workspace-eth-connector/src/types.rs +++ b/workspace-eth-connector/src/types.rs @@ -1,5 +1,5 @@ use aurora_engine_types::types::Address; -use near_sdk::borsh::{self, BorshDeserialize, BorshSerialize}; +use borsh::{self, BorshDeserialize, BorshSerialize}; use near_sdk::{AccountId, Balance, StorageUsage}; use serde::{Deserialize, Serialize}; use std::collections::HashMap; @@ -40,7 +40,7 @@ pub const UNPAUSE_ALL: PausedMask = 0; pub const PAUSE_DEPOSIT: PausedMask = 1 << 0; pub const PAUSE_WITHDRAW: PausedMask = 1 << 1; -#[derive(BorshSerialize, BorshDeserialize)] +#[derive(Debug, BorshSerialize, BorshDeserialize)] pub struct WithdrawResult { pub amount: Balance, pub recipient_id: Address, diff --git a/workspace-eth-connector/tests/fungible_token_tests.rs b/workspace-eth-connector/tests/fungible_token_tests.rs index 8c13ef7..66f8085 100644 --- a/workspace-eth-connector/tests/fungible_token_tests.rs +++ b/workspace-eth-connector/tests/fungible_token_tests.rs @@ -301,11 +301,30 @@ async fn test_set_access_right() { #[tokio::test] async fn test_withdraw() { + let contract = deploy_and_init().await.unwrap(); + let recipient_address = Address::zero(); + let res = contract + .withdraw(recipient_address, 10) + .max_gas() + .transact() + .await + .unwrap() + .into_value(); + assert_eq!(res.recipient_id, recipient_address); + assert_eq!(res.amount, 10); + assert_eq!( + res.eth_custodian_address, + Address::decode(CUSTODIAN_ADDRESS).unwrap() + ); +} + +#[tokio::test] +async fn test_engine_withdraw() { let contract = deploy_and_init().await.unwrap(); let sender_id = AccountId::from_str("test.near").unwrap(); let recipient_address = Address::zero(); let res = contract - .withdraw(sender_id, recipient_address, 10) + .engine_withdraw(sender_id, recipient_address, 10) .max_gas() .transact() .await