-
Notifications
You must be signed in to change notification settings - Fork 6
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
Showing
8 changed files
with
138 additions
and
64 deletions.
There are no files selected for viewing
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
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,16 @@ | ||
[package] | ||
name = "rain_orderbook_common" | ||
version = "0.0.1" | ||
edition = "2021" | ||
license = "CAL-1.0" | ||
description = "Rain Orderbook CLI." | ||
homepage = "https://github.com/rainprotocol/rain.orderbook" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
rain_orderbook_bindings = { path = "../bindings" } | ||
alloy-primitives = "0.5.4" | ||
alloy-ethers-typecast = { git = "https://github.com/rainlanguage/alloy-ethers-typecast", rev = "d35a8e08ef240c4a66177f6de4e1de6fcb165b5f" } | ||
anyhow = "1.0.70" | ||
alloy-sol-types = { version = "0.5.4" } |
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,49 @@ | ||
use alloy_primitives::{Address, U256}; | ||
use anyhow::Result; | ||
use rain_orderbook_bindings::IOrderBookV3::depositCall; | ||
|
||
pub struct DepositArgs { | ||
pub token: String, | ||
pub amount: u64, | ||
pub vault_id: u64, | ||
} | ||
|
||
impl DepositArgs { | ||
pub fn to_deposit_call(&self) -> Result<depositCall> { | ||
let token_address = self.token.parse::<Address>()?; | ||
let amount = U256::from(self.amount); | ||
let vault_id = U256::from(self.vault_id); | ||
|
||
Ok(depositCall { | ||
token: token_address, | ||
amount, | ||
vaultId: vault_id, | ||
}) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn test_to_deposit_call_valid() { | ||
let args = DepositArgs { | ||
token: "0xdcdee0E7a58Bba7e305dB3Abc42F4887CE8EF729".to_string(), | ||
amount: 100, | ||
vault_id: 1, | ||
}; | ||
let result = args.to_deposit_call(); | ||
assert!(result.is_ok()); | ||
} | ||
|
||
#[test] | ||
fn test_to_deposit_call_invalid_token() { | ||
let args = DepositArgs { | ||
token: "invalid".to_string(), | ||
amount: 100, | ||
vault_id: 1, | ||
}; | ||
assert!(args.to_deposit_call().is_err()); | ||
} | ||
} |
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,2 @@ | ||
pub mod deposit; | ||
pub mod transaction; |
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,26 @@ | ||
use alloy_ethers_typecast::{client::LedgerClient, request_shim::AlloyTransactionRequest}; | ||
use alloy_primitives::{Address, U64}; | ||
pub struct TransactionArgs { | ||
pub orderbook_address: String, | ||
pub derivation_path: Option<usize>, | ||
pub chain_id: u64, | ||
pub rpc_url: String, | ||
} | ||
|
||
impl TransactionArgs { | ||
pub async fn to_transaction_request( | ||
&self, | ||
call_data: Vec<u8>, | ||
) -> anyhow::Result<AlloyTransactionRequest> { | ||
let tx = AlloyTransactionRequest::default() | ||
.with_to(self.orderbook_address.parse::<Address>()?) | ||
.with_data(call_data.clone()) | ||
.with_chain_id(U64::from(self.chain_id)); | ||
|
||
Ok(tx) | ||
} | ||
|
||
pub async fn to_ledger_client(self) -> anyhow::Result<LedgerClient> { | ||
LedgerClient::new(self.derivation_path, self.chain_id, self.rpc_url.clone()).await | ||
} | ||
} |