Skip to content

SkandaBhat/ctf-utils

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ctf-utils

Rust helpers for working with UMA Conditional Token Framework identifiers. This is a Rust port of github.com/polymarket/go-ctf-utils, using alloy-primitives for Ethereum-native types.

Quick Start

use alloy_primitives::{address, U256};
use ctf_utils::{
    calculate_position_id, calculate_question_id, create_ancillary_data,
    get_condition_id_with_defaults,
};

let collateral = address!("0x2791bca1f2de4661ed88a30c99a7a9449aa84174");
let outcomes = ["Yes", "No"];

let ancillary = create_ancillary_data(
    "ETH greater than 10000?",
    "Will ETH trade above 10k USDC by 31 Dec 2024 on the Uniswap V3 5bps pool?",
    address!("0x6d8c4e9adf5748af82dabe2c6225207770d6b4fa"),
    outcomes,
)?;

let question_id = calculate_question_id(&ancillary);
let condition_id = get_condition_id_with_defaults(question_id);
let long_id: U256 = calculate_position_id(collateral, condition_id, 0);
let short_id: U256 = calculate_position_id(collateral, condition_id, 1);

println!("UMA question id  : {question_id}");
println!("Condition id     : {condition_id}");
println!("Long token id    : {long_id}");
println!("Short token id   : {short_id}");
# Ok::<(), ctf_utils::AncillaryError>(())

Foundry Fuzz Harness

Forge-based fuzz tests live under fuzz/. They compare the on-chain implementation (CTHelpers.sol) with this crate via Foundry's FFI cheatcode.

  1. Build the CLI binary: cargo build --bin ctf-utils-cli
  2. Run the tests with FFI enabled: FOUNDRY_FFI=1 forge test --ffi

Ensure forge is installed and available on your PATH.

About

Rust helpers for working with UMA Conditional Token Framework identifiers.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published