Skip to content

ForLoopCodes/polyml

Repository files navigation

PolyML

This repository contains an Anchor/Solana on‑chain program written in Rust and a set of TypeScript tests that exercise it.

Key points

  • On‑chain program: programs/polyml (Rust + Anchor)
  • Tests: tests/*.ts (TypeScript Mocha tests that run against a local test validator)
  • Tooling: Anchor, Cargo, Node/npm, Prettier

Quick commands

  • Build the on‑chain program: anchor build (or cargo build --manifest-path=programs/polyml/Cargo.toml)
  • Run the full test suite (builds program, launches validator, runs tests): anchor test
  • Run tests without rebuilding the program (fast): anchor test --skip-build
  • Run a single test with grep: anchor test -- --grep "pattern" or npx ts-mocha -p tsconfig.json tests/polyml.ts -g "pattern"
  • TypeScript typecheck: npx tsc --noEmit
  • Lint / format (Prettier): npm run lint (check) and npm run lint:fix (apply)

Repository layout

  • programs/polyml/ — Anchor program sources and Cargo manifest
  • programs/polyml/src/ — Rust source files
  • tests/ — TypeScript tests (Mocha + chai)
  • tsconfig.json — TypeScript configuration

Testing tips

  • Tests are async and can use long timeouts; increase Mocha timeout when running individual tests if needed: --timeout 120000.
  • When iterating only on tests, use anchor test --skip-build to avoid rebuilding the program each run.

Contributing

  • Run cargo fmt and cargo clippy --manifest-path=programs/polyml/Cargo.toml for Rust changes.
  • Keep commits small and focused. Do not commit secrets or large binary artifacts.

AMM METHOD

  • create market -> create 2 spl for yes and no, store in market
  • add liquidity (the creator) -> mint n yes and n no and deposit to market -> make user position on lp tokens to be able to withdraw later on
  • swap/bet -> buy: program gives user n yes in exchange of calculated sol (current price) -> sell: user sends: n yes coins, gets calculated sol back -> sell formula: amountOut = (reserveOut * amountIn)/(reserveIn * amountIn)
  • resolve market (the oracle) -> yes or no is decided and value assigned to the market -> buys in market are locked
  • final claim -> if YES wins -> amountOut = same formula -> no coin becomes worth 0

CLP METHOD

  • create market -> create 2 spl for yes and no, store in market -> 1 usdc = 1 yes = 1 no (current) -> current existent: 0 yes coins 0 no coins
  • swap/bet -> buy: program mints n yes in user's wallet in exchange of usdc (pre-set market price) -> buy 1 yes, sent 1 usdc wallet to vault, mint 1 yes to wallet and 1 no to the vault -> current existent: 1 yes coin 1 no coins -> buy 25 no, sent 0.5 usdc wallet to vault, mint 25 no to wallet -> current existent: 50 yes coins 25 no coins -> WHATEVER THE MATH IS JUST READ THE CODE -> sell: user sends: n yes coins, coins burned, user gets calculated usdc back (
  • resolve market (the settlement authority) -> yes or no is decided and value assigned to the market -> buys in market are locked
  • final claim -> if YES wins, user sends yes coin and gets back calculated usdc back -> no coin becomes worth 0

About

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors