lamarge 0.6.0

Client for the LaMarge API: sign-in, takes, transfers, withdrawals and market making, each request checked before it is signed.
Documentation
use super::*;
use crate::deployments;

fn withdrawal() -> SendAsset {
    SendAsset {
        hyperliquid_chain: "Mainnet".to_owned(),
        destination: format!("{:#x}", deployments::HYPERLIQUID_BRIDGE),
        source_dex: String::new(),
        destination_dex: "spot".to_owned(),
        token: deployments::HYPERLIQUID_USDC.to_owned(),
        amount: "12.5".to_owned(),
        from_sub_account: String::new(),
        nonce: 1_790_000_000_000,
    }
}

#[test]
fn the_schema_is_hyperliquids() {
    assert_eq!(
        SendAsset::encode_type(),
        "HyperliquidTransaction:SendAsset(string hyperliquidChain,string destination,string sourceDex,string destinationDex,string token,string amount,string fromSubAccount,uint64 nonce)"
    );
    let typed = withdrawal().typed_data();
    assert_eq!(typed.encode_type().unwrap(), SendAsset::encode_type());
    assert_eq!(typed.resolver.encode_type("EIP712Domain").unwrap(), typed.domain.encode_type());
}

#[test]
fn the_built_payload_reads_back_and_hashes_by_its_values() {
    let send = withdrawal();
    let typed = send.typed_data();
    let raw = serde_json::to_value(&typed).unwrap();
    let parsed = eip712::parse_in::<SendAsset>(&raw, &domain()).unwrap();
    assert_eq!(parsed.message, send);
    assert_eq!(parsed.digest, typed.eip712_signing_hash().unwrap());
    let more = SendAsset { amount: "12.6".to_owned(), ..send };
    assert_ne!(more.typed_data().eip712_signing_hash().unwrap(), parsed.digest);
}

#[test]
fn system_addresses_are_recognised() {
    assert!(is_system_address("0x2000000000000000000000000000000000000000"));
    assert!(is_system_address("0x20000000000000000000000000000000000000c8"));
    assert!(is_system_address("0x2222222222222222222222222222222222222222"));
    assert!(!is_system_address("0x2000000000000000000000000000000000100000"));
    assert!(!is_system_address("0x84026d3beff123aab7dff957574d1362d6f880a5"));
    assert!(!is_system_address("0x2222222222222222222222222222222222222223"));
}