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

chore: refactor ABI interfaces and improve example code usage #117

Merged
merged 1 commit into from
Dec 23, 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
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ use uniswap_v3_sdk::prelude::*;

## Note on `no_std`

By default, this library does not depend on the standard library (`std`). However, the `std` feature can be enabled to
use `thiserror` for error handling.
By default, this library does not depend on the standard library (`std`). However, the `std` feature can be enabled.

## Examples

Expand Down
20 changes: 10 additions & 10 deletions examples/from_pool_key_with_tick_data_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,21 @@ use alloy::{
eips::BlockId,
providers::{Provider, ProviderBuilder},
rpc::types::TransactionRequest,
transports::http::reqwest::Url,
shuhuiluo marked this conversation as resolved.
Show resolved Hide resolved
};
use alloy_primitives::{address, ruint::aliases::U256, U160};
use alloy_sol_types::SolValue;
use alloy_sol_types::SolCall;
use uniswap_sdk_core::{prelude::*, token};
use uniswap_v3_sdk::prelude::*;

#[tokio::main]
async fn main() {
dotenv::dotenv().ok();
let rpc_url = std::env::var("MAINNET_RPC_URL").unwrap().parse().unwrap();
let rpc_url: Url = std::env::var("MAINNET_RPC_URL").unwrap().parse().unwrap();
shuhuiluo marked this conversation as resolved.
Show resolved Hide resolved
let provider = ProviderBuilder::new().on_http(rpc_url);
let block_id = BlockId::from(17000000);
let wbtc = token!(1, "2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599", 8, "WBTC");
let weth = token!(1, "C02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", 18, "WETH");
let weth = WETH9::on_chain(1).unwrap();

// Create a pool with a tick map data provider
let pool = Pool::<EphemeralTickMapDataProvider>::from_pool_key_with_tick_data_provider(
Expand Down Expand Up @@ -53,15 +54,14 @@ async fn main() {
use_quoter_v2: false,
}),
);
let quoter_addr = *QUOTER_ADDRESSES.get(&1).unwrap();
let tx = TransactionRequest {
to: Some(quoter_addr.into()),
input: params.calldata.into(),
..Default::default()
};
let tx = TransactionRequest::default()
.to(*QUOTER_ADDRESSES.get(&1).unwrap())
.input(params.calldata.into());
// Get the output amount from the quoter
let res = provider.call(&tx).block(block_id).await.unwrap();
let amount_out = U256::abi_decode(res.as_ref(), true).unwrap();
let amount_out = IQuoter::quoteExactInputSingleCall::abi_decode_returns(res.as_ref(), true)
.unwrap()
.amountOut;
shuhuiluo marked this conversation as resolved.
Show resolved Hide resolved
println!("Quoter amount out: {}", amount_out);

// Compare local calculation with on-chain quoter to ensure accuracy
Expand Down
6 changes: 6 additions & 0 deletions src/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ sol! {
interface IMulticall {
function multicall(bytes[] calldata data) external payable returns (bytes[] memory results);
}
}

sol! {
interface INonfungiblePositionManager {
function createAndInitializePoolIfNecessary(
address token0,
Expand Down Expand Up @@ -187,7 +189,9 @@ sol! {
uint256 amountRequested
) external returns (uint256 reward);
}
}

sol! {
shuhuiluo marked this conversation as resolved.
Show resolved Hide resolved
interface IQuoter {
function quoteExactInput(bytes memory path, uint256 amountIn) external returns (uint256 amountOut);

Expand Down Expand Up @@ -267,7 +271,9 @@ sol! {
uint256 gasEstimate
);
}
}

sol! {
interface ISwapRouter {
#[derive(Debug, Default, PartialEq, Eq)]
struct ExactInputSingleParams {
Expand Down
Loading