-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Supported: - Healthcheck. - Swapping. - Revert. - Tx. - Chains. - Routes. - Bridging.
- Loading branch information
1 parent
f457731
commit fcb4c1b
Showing
36 changed files
with
1,691 additions
and
22 deletions.
There are no files selected for viewing
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,21 @@ | ||
# ref: https://docs.codecov.com/docs/codecovyml-reference | ||
coverage: | ||
# Hold ourselves to a high bar | ||
range: 85..100 | ||
round: down | ||
precision: 1 | ||
status: | ||
# ref: https://docs.codecov.com/docs/commit-status | ||
project: | ||
default: | ||
# Avoid false negatives | ||
threshold: 1% | ||
|
||
# Test files aren't important for coverage | ||
ignore: | ||
- "tests" | ||
|
||
# Make comments less noisy | ||
comment: | ||
layout: "files" | ||
require_changes: true |
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,12 @@ | ||
on: | ||
push: | ||
branches: [main] | ||
name: main | ||
jobs: | ||
codecov: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Upload coverage reports to Codecov | ||
uses: codecov/codecov-action@v3 | ||
env: | ||
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} |
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 |
---|---|---|
@@ -1,10 +1,71 @@ | ||
# Symbiosis API Binding Written in Rust (currently support api-v2) | ||
# symbiosis-api | ||
|
||
You can find the Swagger of Symbiosis API at | ||
[this URL](https://api-v2.symbiosis.finance/crosschain/docs/). | ||
[![Crates.io](https://img.shields.io/crates/v/symbiosis-api.svg)](https://crates.io/crates/symbiosis-api) | ||
[![Documentation](https://docs.rs/symbiosis-api/badge.svg)](https://docs.rs/symbiosis-api/) | ||
[![Codecov](https://codecov.io/github/phnaharris/symbiosis-api/coverage.svg?branch=main)](https://codecov.io/gh/phnaharris/symbiosis-api) | ||
[![Build Status](https://github.com/phnaharris/symbiosis-api-rs/actions/workflows/main.yml/badge.svg)](https://github.com/phnaharris/symbiosis-api-rs/actions/workflows/main.yml) | ||
|
||
# Installation | ||
A high-level binding for Symbiosis API, written in Rust. | ||
|
||
```bash | ||
cargo add symbiosis-api | ||
Symbiosis API allows you to integrate the functionalities of the Symbiosis Protocol into your | ||
application, platform or protocol. | ||
|
||
By integrating the Symbiosis API, you can quickly and effectively enable decentralized | ||
cross-chain swaps and cross-chain liquidity management for your users. | ||
|
||
This crate uses the [reqwest] crate for a convenient, higher-level HTTP Client, for request and | ||
response, to and from Symbiosis, and [serde] for serialize and deserialize from and to | ||
appropriate data format. | ||
|
||
## Examples | ||
|
||
Let's start out swapping from ETH on Ethereum to MNT on Mantle network. | ||
|
||
```rust | ||
use ethers_core::types::Chain; | ||
use ethers_core::utils::parse_ether; | ||
use symbiosis_api::cores::query::Query; | ||
use symbiosis_api::{ | ||
api::swapping, | ||
api::swapping::SwapResponse, | ||
symbiosis::Symbiosis, | ||
types::token::{Token, TokenAmount}, | ||
}; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), anyhow::Error> { | ||
// Create the client. | ||
let client = Symbiosis::new(""); | ||
|
||
// Create a simple endpoint. | ||
let eth = Token::builder().build()?; | ||
let mnt = Token::builder().chain_id(Chain::Mantle).build()?; | ||
let token_amount_in = TokenAmount::builder() | ||
.token(eth) | ||
.amount(parse_ether(1)?) | ||
.build()?; | ||
let endpoint = swapping::SwappingExactIn::builder() | ||
.token_amount_in(token_amount_in) | ||
.token_out(mnt) | ||
.from( | ||
"0xe99E80EE4792395b2F639eE0661150D2b6B1996d" | ||
.parse() | ||
.unwrap(), | ||
) | ||
.to("0xe99E80EE4792395b2F639eE0661150D2b6B1996d" | ||
.parse() | ||
.unwrap()) | ||
.build()?; | ||
|
||
// Call the endpoint. The return type decides how to represent the value. | ||
let swapping: SwapResponse = endpoint.query(&client).await?; | ||
|
||
println!("{:?}", swapping); | ||
|
||
anyhow::Ok(()) | ||
} | ||
``` | ||
|
||
For more examples, take a look at the `examples/` directory. | ||
|
||
This crate design based on https://plume.benboeckel.net/~/JustAnotherBlog/designing-rust-bindings-for-rest-ap-is |
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,8 @@ | ||
# {{crate}} | ||
|
||
[![Crates.io](https://img.shields.io/crates/v/symbiosis-api.svg)](https://crates.io/crates/symbiosis-api) | ||
[![Documentation](https://docs.rs/symbiosis-api/badge.svg)](https://docs.rs/symbiosis-api/) | ||
[![Codecov](https://codecov.io/github/phnaharris/symbiosis-api/coverage.svg?branch=main)](https://codecov.io/gh/phnaharris/symbiosis-api) | ||
[![Build Status](https://github.com/phnaharris/symbiosis-api-rs/actions/workflows/main.yml/badge.svg)](https://github.com/phnaharris/symbiosis-api-rs/actions/workflows/main.yml) | ||
|
||
{{readme}} |
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,43 @@ | ||
use ethers_core::types::Chain; | ||
use ethers_core::utils::parse_ether; | ||
use symbiosis_api::api::bridging::{self, BridgeResponse}; | ||
use symbiosis_api::cores::query::Query; | ||
use symbiosis_api::{ | ||
symbiosis::Symbiosis, | ||
types::token::{Token, TokenAmount}, | ||
}; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), anyhow::Error> { | ||
// Create the client. | ||
let client = Symbiosis::new(""); | ||
|
||
// Create a simple endpoint. | ||
let usdc_eth = Token::builder() | ||
.address("0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48".into()) | ||
.decimals(6) | ||
.build()?; | ||
let token_amount_in = TokenAmount::builder() | ||
.token(usdc_eth) | ||
.amount(parse_ether(1)?) | ||
.build()?; | ||
let endpoint = bridging::BridgingExactIn::builder() | ||
.token_amount_in(token_amount_in) | ||
.chain_id_out(Chain::Boba) | ||
.from( | ||
"0xe99E80EE4792395b2F639eE0661150D2b6B1996d" | ||
.parse() | ||
.unwrap(), | ||
) | ||
.to("0xe99E80EE4792395b2F639eE0661150D2b6B1996d" | ||
.parse() | ||
.unwrap()) | ||
.build()?; | ||
|
||
// Call the endpoint. The return type decides how to represent the value. | ||
let bridging: BridgeResponse = endpoint.query(&client).await?; | ||
|
||
println!("{:?}", bridging); | ||
|
||
anyhow::Ok(()) | ||
} |
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,21 @@ | ||
use symbiosis_api::{ | ||
api::chain::{self, SymbiosisChain}, | ||
cores::query::Query, | ||
symbiosis::Symbiosis, | ||
}; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), anyhow::Error> { | ||
// Create the client. | ||
let client = Symbiosis::new(""); | ||
|
||
// Create a simple endpoint. | ||
let endpoint = chain::GetSupportedChains; | ||
|
||
// Call the endpoint. The return type decides how to represent the value. | ||
let chains: Vec<SymbiosisChain> = endpoint.query(&client).await?; | ||
|
||
println!("{:?}", chains); | ||
|
||
anyhow::Ok(()) | ||
} |
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,18 @@ | ||
use symbiosis_api::cores::query::Query; | ||
use symbiosis_api::{api::healthcheck, symbiosis::Symbiosis}; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), anyhow::Error> { | ||
// Create the client. | ||
let client = Symbiosis::new(""); | ||
|
||
// Create a simple endpoint. | ||
let endpoint = healthcheck::HealthCheck; | ||
|
||
// Call the endpoint. The return type decides how to represent the value. | ||
let healthcheck: Result<String, anyhow::Error> = endpoint.query(&client).await; | ||
|
||
println!("{:?}", healthcheck); | ||
|
||
anyhow::Ok(()) | ||
} |
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,21 @@ | ||
use symbiosis_api::api::revert::{Revert, RevertResponse}; | ||
use symbiosis_api::cores::query::Query; | ||
use symbiosis_api::symbiosis::Symbiosis; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), anyhow::Error> { | ||
// Create the client. | ||
let client = Symbiosis::new(""); | ||
|
||
// Create a simple endpoint. | ||
let endpoint = Revert::builder() | ||
.transaction_hash(Default::default()) | ||
.build()?; | ||
|
||
// Call the endpoint. The return type decides how to represent the value. | ||
let revert: RevertResponse = endpoint.query(&client).await?; | ||
|
||
println!("{:?}", revert); | ||
|
||
anyhow::Ok(()) | ||
} |
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,21 @@ | ||
use symbiosis_api::{ | ||
api::routes::{self, AvailableRoutesResponse}, | ||
cores::query::Query, | ||
symbiosis::Symbiosis, | ||
}; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), anyhow::Error> { | ||
// Create the client. | ||
let client = Symbiosis::new(""); | ||
|
||
// Create a simple endpoint. | ||
let endpoint = routes::GetAvailableRoutes; | ||
|
||
// Call the endpoint. The return type decides how to represent the value. | ||
let routes: Vec<AvailableRoutesResponse> = endpoint.query(&client).await?; | ||
|
||
println!("{:?}", routes); | ||
|
||
anyhow::Ok(()) | ||
} |
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,25 @@ | ||
use symbiosis_api::api::revert::{Stucked, StuckedResponse}; | ||
use symbiosis_api::cores::query::Query; | ||
use symbiosis_api::symbiosis::Symbiosis; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), anyhow::Error> { | ||
// Create the client. | ||
let client = Symbiosis::new(""); | ||
|
||
// Create a simple endpoint. | ||
let endpoint = Stucked::builder() | ||
.address( | ||
"0xe99E80EE4792395b2F639eE0661150D2b6B1996d" | ||
.parse() | ||
.unwrap(), | ||
) | ||
.build()?; | ||
|
||
// Call the endpoint. The return type decides how to represent the value. | ||
let stucked: Vec<StuckedResponse> = endpoint.query(&client).await?; | ||
|
||
println!("{:?}", stucked); | ||
|
||
anyhow::Ok(()) | ||
} |
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,42 @@ | ||
use ethers_core::types::Chain; | ||
use ethers_core::utils::parse_ether; | ||
use symbiosis_api::cores::query::Query; | ||
use symbiosis_api::{ | ||
api::swapping, | ||
api::swapping::SwapResponse, | ||
symbiosis::Symbiosis, | ||
types::token::{Token, TokenAmount}, | ||
}; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), anyhow::Error> { | ||
// Create the client. | ||
let client = Symbiosis::new(""); | ||
|
||
// Create a simple endpoint. | ||
let eth = Token::builder().build()?; | ||
let mnt = Token::builder().chain_id(Chain::Mantle).build()?; | ||
let token_amount_in = TokenAmount::builder() | ||
.token(eth) | ||
.amount(parse_ether(1)?) | ||
.build()?; | ||
let endpoint = swapping::SwappingExactIn::builder() | ||
.token_amount_in(token_amount_in) | ||
.token_out(mnt) | ||
.from( | ||
"0xe99E80EE4792395b2F639eE0661150D2b6B1996d" | ||
.parse() | ||
.unwrap(), | ||
) | ||
.to("0xe99E80EE4792395b2F639eE0661150D2b6B1996d" | ||
.parse() | ||
.unwrap()) | ||
.build()?; | ||
|
||
// Call the endpoint. The return type decides how to represent the value. | ||
let swapping: SwapResponse = endpoint.query(&client).await?; | ||
|
||
println!("{:?}", swapping); | ||
|
||
anyhow::Ok(()) | ||
} |
Oops, something went wrong.