Skip to content

Interest Protocol Swaps

Fetch swaps for versions 0 to 126000.

Code

Rust
use futures::StreamExt;
use std::{collections::HashSet, sync::Arc};
use pangea_client::{
    core::types::ChainId, query::Bound,
    ClientBuilder, Format, WsProvider,
    provider::MoveProvider, requests::interest::GetSwapsRequest, 
};
 
#[tokio::main]
async fn main() {
    dotenvy::dotenv_override().ok();
 
    let client = match ClientBuilder::default()
        .endpoint("movement.app.pangea.foundation")
        .build::<WsProvider>()
        .await
    {
        Ok(client) => Arc::new(client),
        Err(e) => {
            eprintln!("Client failed to initialize:\n{e}");
            return;
        }
    };
 
    {
        let request = GetSwapsRequest { 
            chains: HashSet::from([ChainId::MOVEMENT]), 
            from_block: Bound::Exact(0), 
            to_block: Bound::Exact(126000), 
            ..Default::default() 
        }; 
        let stream = match client 
            .get_move_interest_v1_swaps_by_format(request, Format::JsonStream, false) 
            .await
        {
            Ok(stream) => stream,
            Err(e) => {
                eprintln!("Request failed\n{e}");
                return;
            }
        };
 
        futures::pin_mut!(stream);
 
        while let Some(chunk) = stream.next().await {
            let chunk = String::from_utf8(chunk.unwrap()).unwrap();
            println!("{chunk}");
        }
    }
}

Response

{
  ...
  {
    "block_number": 125976,
    "transaction_hash": "0xf2ff7e0e16267ac4143a8d443241ea4127590dc2e49752eb1529ee0bd76dbc6f",
    "log_index": 5,
    "timestamp": 1741597357539806,
    "account_address": "0x13418bb00810eca160f77aa03e134d6d62b0859653f9236ccc6293acf1a6513d",
    "sender": "0x49286b4778003f071c53150b73526b326ad954c5ddef75ca4400d62990b9255a",
    "pool_address": "0x4487140c34467abd4bde7d635046c529d01dcdaa47d7550466f3a85afe946dc1",
    "token0_address": "0x000000000000000000000000000000000000000000000000000000000000000a",
    "token0_decimals": 8,
    "token0_name": "Move Coin",
    "token0_symbol": "MOVE",
    "token1_address": "0x5f7f59e38a96dfe79830f53fe49a19e770f70a13ff30ce598a49e8f0a2b46861",
    "token1_decimals": 8,
    "token1_name": "🔥",
    "token1_symbol": "🔥",
    "side": "Sell",
    "amount0": 0.1,
    "amount1": 689996.17726426,
    "fee_in": 0.0003,
    "slot_balance0": 0,
    "slot_balance1": 0,
    "bid_liquidity": 0,
    "last_slot_timestamp": 0,
    "execution_price": 6899961.772642599,
    "settlement_price": 6920723.944476027
  }
}

Query parameters

  • chains: Filters the data by chain.
  • from_block: Filters the data by a starting version. As Move chains use a per-transaction versioned database, we use version interchangably with block_number and omit blocks altogether.
  • to_block: Filters the data by an ending version. As Move chains use a per-transaction versioned database, we use version interchangably with block_number and omit blocks altogether.
  • pool_address__in: Filters the data by a list of pool_address.
  • token0_address__in: Filters the data by a list of token0_address.
  • token1_address__in: Filters the data by a list of token1_address.
  • tokens_address__in: Filters the data by a list of both token0_address and token1_address.