How P2P works.
One contract, four functions that move tokens, and no oracle. This page describes exactly what the code does and what it does not.
What P2P is
P2P is a peer-to-peer exchange for ERC-20 tokens. One party locks tokens in the P2POTC contract and states the exact amount of another token they want. A second party pays that amount and receives the locked tokens in the same transaction.
It is not a DEX, an aggregator, or an order book. There is no pool, no matching engine and no price feed.
Why OTC exists
An automated market maker prices each token of a trade worse than the previous one. In a deep pool that is negligible. In a shallow pool a large order can receive far less than its quoted value, and it moves the pool's price for everyone else.
If a buyer for the whole position exists, the two sides can simply agree a price. The only thing missing is a way to swap without one side having to send first. That is all P2P provides.
A direct exchange does not consume pool liquidity. It does not make the trade invisible, and it does not stop the buyer from selling into the pool later.
How a funded offer works
- Create. The maker approves the exact amount and calls
createOrder. The contract pulls the tokens, checks that it received exactly that amount, and records the order with the current fee rate. - Discover. The
OrderCreatedevent is indexed. Listed offers appear in the marketplace; every offer has a link of the form/deal/<chainId>/<orderId>. - Fill. The taker approves the exact asking amount and calls
fillOrder(id, termsHash). The hash commits to the terms the taker reviewed. - Settle. In that call the contract marks the order filled, pulls the payment, forwards it to the maker minus the fee, and releases the escrow to the taker.
Public, unlisted, restricted
| Mode | On-chain | Effect |
|---|---|---|
| Public | listed = true, no taker | Shown in the marketplace. Anyone can fill. |
| Unlisted | listed = false, no taker | Hidden from the marketplace. Anyone with the id can fill. |
| One wallet | allowedTaker set | Only that address can fill. Enforced by the contract. |
None of these is private. listed is a hint to indexers. Every offer, its amounts and its addresses are readable by anyone on the chain.
Escrow and atomic settlement
Offered tokens are held by the contract, not by a person or a team wallet. The contract tracks the total owed back per token (totalEscrowed) separately from fees it has earned (accruedFees); the test suite checks after every random action that the token balance equals the sum of the two.
fillOrder updates state first and transfers afterwards, behind a reentrancy guard. If the payment, the payout or the escrow release fails, the whole transaction reverts and nobody's balance changes. An order can be filled once.
Offers are full-fill only in this version. Partial fills are planned and deliberately not included yet.
Fees
P2P charges no fee. The taker pays exactly the asking amount, the maker receives all of it, and the taker receives the full escrow. The only cost is network gas, paid in HYPE by whoever sends each transaction.
- The contract does have a fee setting, currently 0. Its owner could raise it for future offers, never above 1% (
MAX_FEE_BPS = 100, a constant). - The rate is stored on each offer when it is created, so a later change can never touch an existing offer.
- The review step and the deal page always show the rate that applies to that offer, read from the contract.
Expiry, cancellation, recovery
- Every offer has an expiry timestamp, at most 365 days out. Expiry is a condition, not a transaction: once the time passes,
fillOrderreverts even though the stored status still says open. cancelOrder: the maker withdraws the escrow at any time before a fill, including after expiry.reclaimExpiredOrder: after expiry anyone may trigger the refund. The tokens go only to the maker.- Both keep working while the protocol is paused.
Supported assets
Both sides must be ERC-20 contracts. Native HYPE is not accepted directly; it needs a wrapped HYPE token, and a canonical one has not been verified for Elysium yet.
- Transfer-tax tokens are rejected. Every inbound transfer is checked by balance difference and reverts if less arrives than was sent.
- Tokens that return nothing from
transfer(USDT-style) work. - Rebasing tokens are not supported. A negative rebase would leave the escrow short.
- Pausable, blacklisting or upgradeable tokens can block a fill or a refund. That risk is the token's, and P2P cannot remove it.
- An optional on-chain allowlist can restrict which tokens new offers may use. On Elysium it is currently off, so any ERC-20 can be offered; the owner can turn it back on. It never blocks filling, cancelling or reclaiming an existing offer.
Reviewed tokens configured for this build (Elysium):
| Symbol | Address | Decimals |
|---|---|---|
| WHYPE | 0xbA876237B0F021A6c6D852d6c26E107997cC5E81 | 18 |
| USDC | 0xb47c4C8F73F009CC0C0d3f92B388d13E293F0B65 | 6 |
| kHYPE | 0x248888D396A546A69A188f3Deb476964e581E9d0 | 18 |
| KNTQ | 0xe45a355d9e9cAd2aD85F2d03E3eE3102A036acF0 | 18 |
| UBTC | 0xE9C29585EAe4B9a55b02a9605AEa892B40d972E8 | 8 |
| UETH | 0x7A66A75fe41Bc26867C17fe1bc7D1C076EBd4eCd | 18 |
| M10 | 0xB97b1A77C2039Addc78b594300C4f69EBBCbA3e2 | 18 |
| VOID | 0xD31B21Cb80E431AC996269deC31A40fCf048B77f | 18 |
| AGI | 0x74F811F35134D73221E5491135E4C8f963316953 | 18 |
| ELYSIAN | 0xb96EcE0Cfa2C9DFeD18e26A2F16D60a1be480755 | 18 |
| EGG | 0xCb0Bb01149163AfEB8E1a80787A265F87634b6b5 | 18 |
| PERP | 0x231e303Fc99f8Ff35fb089c707981e3767d4E6B7 | 18 |
| SYMB | 0x6668AA70A1F1a9E6e096Ae73eFe21Fe876855799 | 18 |
| JELLY | 0xC6673922B09570711675873F9dbd3B389117163b | 18 |
| HYPEPE | 0x5dCFb191f0cDB853BAc3A6A4385e160E779e377F | 18 |
| CITIZEN | 0x7b40B1999E1227aDd159AdA58C11C3Af3d84F64c | 18 |
| QUOTED | 0x66f46517D0C2CFa489bcBf776D127D59c79fA499 | 18 |
| GRASS | 0x2b2Ffc9435c470f4C96eAf3b9a51Fe212b8c0484 | 18 |
| RAM | 0x2ea9E66Adb86b0Ed71f79ab2e81a31147eDc3215 | 18 |
| CLU | 0x4888cd903c91Da581C82147Ff3C80aDDBc7c2eC8 | 18 |
| SMOOR | 0x0C4CB3d13067BD5D86A857F3344A47ECC7160C02 | 18 |
| LUMI | 0xD564380a0e9752D25e4E8305E796A0a58d0456bf | 18 |
| TREMOR | 0x5b601A07748cE9868dD46012EbC7F7ecFb640871 | 18 |
| INDEX | 0xBDF7119C6Fa191Ea0576792910c8db8ca3f0e801 | 18 |
| PANTHEON | 0x892723Bf41F2E1af70ADb1fF19036810888473a3 | 18 |
| HELIOS | 0xa698ddceaD546AC40ae09D3f9fbC235Cf6236797 | 18 |
| TANGENT | 0x5bc7c1F1afC2d1c51A0bdFC241Cb525Bc4b02Fc9 | 18 |
| MAXIMUS | 0xEb8bCC0fdE0e76D26F1FBcB38BF476C837b92927 | 18 |
| burn | 0x5A614150bdB6eE403b3F002cbCd3621a7240AdC4 | 18 |
| AGORA | 0x5e5Df82d563FCF36b6f853c4D09f89e2d18825B4 | 18 |
| CORPUS | 0xA0D3C65d7DE62931C1A0cf62FB9BbDAC7af29215 | 18 |
| CHAMELEON | 0xd662D66eC991A3eae4EcBdA34327264c53d4cF38 | 18 |
| LEASH | 0x0d442948A8748F0296aF853c85EC054D875c010f | 18 |
| Troy | 0x597E37295E8Ee74d55969def5007dD5Afb3A6b2a | 18 |
| TAIL | 0xC6333959D096f151dee397AC56c9259a1127B870 | 18 |
| PORTED | 0x21436b58f67724025A53c396f796DCd50C6D4f44 | 18 |
| ELO | 0xe107e5D99910F544f88ef961E3cA6d88F06f29DD | 18 |
| EVERMOR | 0x7f4f3b9770648262fe5133B9CB8A2155173be0d4 | 18 |
| EACCAT | 0x32193Afd14c53f12c45A4c04ECA9F7Ba98e3ec71 | 18 |
| MONTRA | 0x063F7Cc5339f92a5FD7BaF3D22233044FdA1F327 | 18 |
| BLOB | 0x69E58778c986a036cdF7EE93A18e173BFd47B10B | 18 |
| ICE | 0x49c08C6Bb912f512A467a2973FB93Cb2c91436dE | 18 |
0xF0394d1E25BE152C9746791f5DA3B287743f0E52 | 18 | |
| LiquidV | 0xd12609Ddb1CD18280C7C14fB2CB5091CFEa37f2D | 18 |
| HI | 0xC75f783646739542C1E3680FD64424A0c4088D69 | 18 |
| LONGCAT | 0xbb5629257e6A28Fe3dbd8f9eB032129FE238d7b6 | 18 |
| UNSEEN | 0x6d1523348ad84210eE51d08676618fF5DD2B2819 | 18 |
| e/acc | 0x8df4f39d592de2aAee15838B265C2392d19A4128 | 18 |
| HYDE | 0x594267928A0e4Aa76e34aC441B116E01ff231dF5 | 18 |
| KM | 0xCdA74aC622378106582102CE6Cd8599F3BA0d769 | 18 |
| YTR | 0x5eBd8EfB0ff0387702365Ec0BACcDA20621F54eb | 18 |
| NUM | 0xE9C952CD198Ff412113a465D34Ff2C233F6F4ca1 | 18 |
| VOLTA | 0x0f79931689Af199e7CF868ed1107bBA2C83c68f7 | 18 |
AMM comparison method
Where a pool is configured for a token pair, P2P reads its live reserves and computes what the same size would fetch there, using constant-product math in integers:
in' = amountIn × (10 000 − feeBps) out = in' × reserveOut / (reserveIn × 10 000 + in') spot = amountIn × reserveOut / reserveIn
- Seller view: pool proceeds versus what the deal pays.
- Buyer view: pool cost to acquire the same amount versus the deal's asking amount.
- The source, pool fee and age of the reserves are shown. Gas is excluded.
- If no verified pool exists the comparison says so. P2P does not estimate.
This math is exact only for x·y=k pools. Montra's pools on Elysium are Uniswap v4 pools with a hook, which need the v4 quoter, not this formula. That integration is not built, so on Elysium the comparison is unavailable until a verified adapter exists. The number is never used for settlement.
Pools configured for this build: none.
Contract architecture
A single immutable contract, P2POTC, Solidity 0.8.26, OpenZeppelin 5 (SafeERC20, ReentrancyGuard, Ownable2Step). No proxy, no upgrade path: a new version is a new address.
| Function | Caller | Does |
|---|---|---|
createOrder | maker | Escrows tokens, opens an order |
fillOrder | taker | Pays and receives, atomically |
cancelOrder | maker | Refunds an unfilled order |
reclaimExpiredOrder | anyone | Refunds the maker after expiry |
withdrawFees | anyone | Sends accrued fees to the fee recipient |
getOrder, effectiveStatus, isOrderFillable, calculateSettlement, getRemainingAmounts, orderTermsHash | views | Read state |
Orders live in a mapping keyed by an incrementing id. Nothing on-chain iterates over orders; discovery is by events.
Admin permissions
The owner (intended to be a multisig) can:
- set the fee rate for future offers, up to 1%;
- change the fee recipient;
- pause creating offers and/or filling them;
- enable the token allowlist and add or remove tokens.
The owner cannot, because no function exists to do it:
- move, seize or redirect escrow;
- change an offer's amounts, tokens, counterparty, expiry or fee;
- stop a maker cancelling or reclaiming;
- withdraw anything other than accrued fees, and those only to the fee recipient.
Security limits
- Not audited. 62 unit and fuzz tests and 5 invariant tests pass. That is evidence, not proof.
- No privacy. All offers and settlements are public.
- No ordering protection. On a public offer the first confirmed fill wins. Others revert and lose only gas.
- Token risk is not removed. See supported assets.
- Simulation is a hint. The interface simulates before asking for a signature; a passing simulation can still fail on-chain if state changes first.
- EVM target. Bytecode is compiled for the
parisEVM so it does not depend on newer opcodes, because Elysium's fork level could not be confirmed.
Indexer and API
The indexer reads P2POTC events, keys each by transaction hash and log index, re-reads the most recent 12 blocks on every pass to absorb reorganisations, and rebuilds from the deployment block if its checkpoint no longer matches the chain. It holds no keys and cannot affect settlement. Deal pages read the contract directly and work without it.
GET /api/orders?status=open|filled|cancelled|expired|all
&maker=0x… &taker=0x… &token=0x… &offered=0x… &requested=0x…
&sort=newest|oldest|expiring|size &limit=1..200 &offset=
GET /api/orders/:id
GET /api/activity?type=created|filled|cancelled|reclaimed&limit=&offset=
GET /api/stats
GET /api/tokens/:addressAll inputs are validated, responses are paginated, and requests are rate limited per client.
Deployment status
| This build targets | Elysium, chain ID 99901 |
| P2POTC address | 0x5FaBF29765132f800880EdD88f114AF172871ed7 |
| RPC configured | Yes |
| Elysium mainnet (99901) | Deployed at 0x5FaBF29765132f800880EdD88f114AF172871ed7 (block 16621591). Unaudited. |
| Audit | None |
Open items before a mainnet deployment:
- A general-purpose Elysium RPC. The Montra RPC only relays Montra's own transactions and refuses everything else, so it cannot deploy or call P2P.
- Confirmation of the chain's EVM fork level, a block explorer and its verification API.
- Verified addresses for wrapped HYPE and any stablecoin, added to the token config.
- A v4 quoter adapter if pool comparisons are wanted for Montra pools.
- An independent audit and a multisig owner.
FAQ
Does the P2P team hold my tokens?
No. They sit in the contract, and the contract has no function that lets an admin move them.
Can I get a better price than the pool?
Sometimes. For large size in thin liquidity, often. For small size in deep liquidity, usually not. The comparison shows both honestly when a pool is available.
What if nobody takes my offer?
Cancel whenever you like, or let it expire and reclaim. You pay gas, no fee.
Is there a P2P token?
No. The protocol does not need one.
Can I counter-offer?
Not in the contract. Create your own wallet-restricted offer with the terms you want and send the other side the link.