Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add initial thorchain implementation #300

Merged
merged 10 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ members = [

"crates/security_*",
"crates/gem_*",
"crates/swap_*",

"crates/localizer",
"crates/job_runner",
Expand All @@ -53,6 +52,7 @@ default-members = [
typeshare = "1.0.3"
serde = { version = "1.0.196", features = ["derive"] }
serde_json = { version = "1.0.114" }
serde_urlencoded = { version = "0.7.1" }
tokio = { version = "1.36.0", features = ["macros", "rt-multi-thread"] }
reqwest = { version = "0.12.3", features = ["json"] }
reqwest-middleware = { version = "0.3.0" }
Expand Down
2 changes: 1 addition & 1 deletion crates/gem_evm/src/uniswap/deployment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub struct V3Deployment {
pub universal_router: &'static str,
}

pub fn get_deployment_by_chain(chain: Chain) -> Option<V3Deployment> {
pub fn get_deployment_by_chain(chain: &Chain) -> Option<V3Deployment> {
// https://docs.uniswap.org/contracts/v3/reference/deployments/
match chain {
Chain::Ethereum => Some(V3Deployment {
Expand Down
10 changes: 2 additions & 8 deletions crates/name_resolver/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ mod tests {
block_on(async {
let provider = Provider::new(String::from("https://eth.llamarpc.com"));
let addres = provider.resolve_name("vitalik.eth", Chain::Ethereum).await;
assert_eq!(
addres.unwrap(),
"0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045".to_lowercase()
)
assert_eq!(addres.unwrap(), "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045".to_lowercase())
});
}

Expand All @@ -24,10 +21,7 @@ mod tests {
block_on(async {
let client = BNSClient::new(String::from("https://resolver-api.basename.app"));
let addres = client.resolve("hello.base", Chain::Base).await;
assert_eq!(
addres.unwrap(),
"0x4fb3f133951bF1B2d52fF6CEab2c703fbB6E98cC"
)
assert_eq!(addres.unwrap(), "0x4fb3f133951bF1B2d52fF6CEab2c703fbB6E98cC")
});
}
}
11 changes: 2 additions & 9 deletions crates/primitives/src/big_number_formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,8 @@ mod tests {
assert_eq!(result, "0.4567");

// Test case 4: u256 input
let result = BigNumberFormatter::value(
"115792089237316195423570985008687907853269984665640564039457000000000000000000",
18,
)
.unwrap();
assert_eq!(
result,
"115792089237316195423570985008687907853269984665640564039457"
);
let result = BigNumberFormatter::value("115792089237316195423570985008687907853269984665640564039457000000000000000000", 18).unwrap();
assert_eq!(result, "115792089237316195423570985008687907853269984665640564039457");

// Test case 5: Invalid input
let result = BigNumberFormatter::value("abc", 2);
Expand Down
11 changes: 0 additions & 11 deletions crates/swap_thorchain/Cargo.toml

This file was deleted.

86 changes: 0 additions & 86 deletions crates/swap_thorchain/src/client.rs

This file was deleted.

2 changes: 0 additions & 2 deletions crates/swap_thorchain/src/lib.rs

This file was deleted.

18 changes: 0 additions & 18 deletions crates/swap_thorchain/src/model.rs

This file was deleted.

3 changes: 3 additions & 0 deletions gemstone/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,13 @@ anyhow.workspace = true
base64.workspace = true
serde.workspace = true
serde_json.workspace = true
serde_urlencoded.workspace = true
async-trait.workspace = true
alloy-core.workspace = true
alloy-primitives.workspace = true
hex.workspace = true
url.workspace = true
num-bigint.workspace = true

[build-dependencies]
uniffi = { workspace = true, features = ["build"] }
Expand Down
21 changes: 5 additions & 16 deletions gemstone/src/config/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,19 @@ impl Node {
}

pub fn get_nodes() -> HashMap<String, Vec<Node>> {
Chain::all()
.into_iter()
.map(|chain| (chain.to_string(), get_nodes_for_chain(chain)))
.collect()
Chain::all().into_iter().map(|chain| (chain.to_string(), get_nodes_for_chain(chain))).collect()
}

pub fn get_nodes_for_chain(chain: Chain) -> Vec<Node> {
match chain {
Chain::Bitcoin | Chain::Litecoin => vec![],
Chain::Ethereum => vec![
Node::new("https://eth.llamarpc.com", NodePriority::High),
Node::new("https://ethereum.publicnode.com", NodePriority::High),
Node::new("https://rpc.ankr.com/eth", NodePriority::High),
Node::new("https://ethereum-rpc.polkachu.com", NodePriority::High),
Node::new("https://eth.merkle.io", NodePriority::High),
],
Chain::SmartChain => vec![
Node::new("https://binance.llamarpc.com", NodePriority::High),
Node::new("https://bsc.publicnode.com", NodePriority::High),
Node::new("https://bsc.merkle.io", NodePriority::High),
],
Expand Down Expand Up @@ -114,7 +109,7 @@ pub fn get_nodes_for_chain(chain: Chain) -> Vec<Node> {
],
Chain::Celestia => vec![
Node::new("https://celestia-rest.publicnode.com", NodePriority::High),
Node::new("https://celestia-api.polkachu.com", NodePriority::High)
Node::new("https://celestia-api.polkachu.com", NodePriority::High),
],
Chain::Injective => vec![
Node::new("https://injective-rest.publicnode.com", NodePriority::High),
Expand All @@ -129,9 +124,7 @@ pub fn get_nodes_for_chain(chain: Chain) -> Vec<Node> {
Node::new("https://pacific-rpc.manta.network/http", NodePriority::High),
Node::new("https://manta-pacific.drpc.org", NodePriority::High),
],
Chain::Blast => vec![
Node::new("https://blast-rpc.polkachu.com", NodePriority::High),
],
Chain::Blast => vec![Node::new("https://blast-rpc.polkachu.com", NodePriority::High)],
Chain::Noble => vec![
Node::new("https://rest.cosmos.directory/noble", NodePriority::High),
Node::new("https://noble-api.polkachu.com", NodePriority::High),
Expand All @@ -140,14 +133,10 @@ pub fn get_nodes_for_chain(chain: Chain) -> Vec<Node> {
Node::new("https://zksync.drpc.org", NodePriority::High),
Node::new("https://mainnet.era.zksync.io", NodePriority::High),
],
Chain::Linea => vec![
Node::new("https://linea-rpc.polkachu.com", NodePriority::High),
],
Chain::Linea => vec![Node::new("https://linea-rpc.polkachu.com", NodePriority::High)],
Chain::Mantle => vec![Node::new("https://rpc.ankr.com/mantle", NodePriority::High)],
Chain::Celo => vec![Node::new("https://rpc.ankr.com/celo", NodePriority::High)],
Chain::Near => vec![Node::new("https://rpc.mainnet.near.org", NodePriority::High)],
Chain::World => vec![
Node::new("https://worldchain-mainnet.gateway.tenderly.co", NodePriority::High)
],
Chain::World => vec![Node::new("https://worldchain-mainnet.gateway.tenderly.co", NodePriority::High)],
}
}
44 changes: 30 additions & 14 deletions gemstone/src/config/swap_config.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,45 @@
#[derive(uniffi::Record, Debug, Clone, PartialEq)]
pub struct SwapConfig {
slippage_bps: u32,
referral_fee: SwapReferralFees,
pub default_slippage_bps: u32,
pub referral_fee: SwapReferralFees,
}

#[derive(uniffi::Record, Debug, Clone, PartialEq)]
#[derive(uniffi::Record, Default, Debug, Clone, PartialEq)]
pub struct SwapReferralFees {
evm: SwapReferralFee,
solana: SwapReferralFee,
thorchain: SwapReferralFee,
pub evm: SwapReferralFee,
pub solana: SwapReferralFee,
pub thorchain: SwapReferralFee,
}

#[derive(uniffi::Record, Debug, Clone, PartialEq)]
#[derive(uniffi::Record, Default, Debug, Clone, PartialEq)]
pub struct SwapReferralFee {
address: String,
bps: u32,
pub address: String,
pub bps: u32,
}

impl SwapReferralFees {
pub fn evm(evm: SwapReferralFee) -> SwapReferralFees {
SwapReferralFees {
evm,
solana: SwapReferralFee::default(),
thorchain: SwapReferralFee::default(),
}
}
}

pub fn get_swap_config() -> SwapConfig {
SwapConfig {
slippage_bps: 100,
default_slippage_bps: 100,
referral_fee: SwapReferralFees {
evm: SwapReferralFee { address: "0x0D9DAB1A248f63B0a48965bA8435e4de7497a3dC".into(), bps: 50 },
solana: SwapReferralFee { address: "5fmLrs2GuhfDP1B51ziV5Kd1xtAr9rw1jf3aQ4ihZ2gy".into(), bps: 50 },
thorchain: SwapReferralFee { address: "gemwallet".into(), bps: 50 },
evm: SwapReferralFee {
address: "0x0D9DAB1A248f63B0a48965bA8435e4de7497a3dC".into(),
bps: 50,
},
solana: SwapReferralFee {
address: "5fmLrs2GuhfDP1B51ziV5Kd1xtAr9rw1jf3aQ4ihZ2gy".into(),
bps: 50,
},
thorchain: SwapReferralFee { address: "g1".into(), bps: 50 },
},
}
}
}
6 changes: 5 additions & 1 deletion gemstone/src/swapper/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@ mod custom_types;
mod models;
mod permit2_data;
mod slippage;
mod thorchain;
mod uniswap;

use models::*;
use primitives::Chain;

#[async_trait]
pub trait GemSwapProvider: Send + Sync + Debug {
fn name(&self) -> &'static str;
async fn supported_chains(&self) -> Result<Vec<Chain>, SwapperError>;
async fn fetch_quote(&self, request: &SwapQuoteRequest, provider: Arc<dyn AlienProvider>) -> Result<SwapQuote, SwapperError>;
async fn fetch_quote_data(&self, quote: &SwapQuote, provider: Arc<dyn AlienProvider>, data: FetchQuoteData) -> Result<SwapQuoteData, SwapperError>;
}
Expand All @@ -30,7 +34,7 @@ impl GemSwapper {
fn new(rpc_provider: Arc<dyn AlienProvider>) -> Self {
Self {
rpc_provider,
swappers: vec![Box::new(uniswap::UniswapV3::new())],
swappers: vec![Box::new(uniswap::UniswapV3::new()), Box::new(thorchain::ThorChain::new())],
}
}

Expand Down
Loading
Loading