@ophis/sdk
v0.2.2
Published
Integration helpers for Ophis (a CoW Protocol fork): correct orderbook hosts, the CIP-75 partner-fee appData fragment, the per-chain EIP-712 signing domain, and order receiver-safety guards.
Downloads
1,059
Maintainers
Readme
@ophis/sdk
Integration helpers for Ophis — a CoW Protocol fork with a natural-language intent layer.
Non-custodial. These helpers build and guard order parameters. They never hold keys or sign on your behalf. See Security before wiring up an automated signer.
Install
npm install @ophis/sdkWhat's in it
getOphisOrderbookUrl(chainId)— the correct orderbook host per chain. Optimism is self-hosted atoptimism-mainnet.ophis.fi, notapi.cow.fi; getting this wrong silently bypasses the Ophis solver and partner fee.getOphisOrderDomain(chainId)/getOphisSettlementAddress(chainId)— the EIP-712 signing domain with the correct per-chainverifyingContract(the OP settlement is non-canonical, so the cow-sdk default is wrong there).buildOphisAppDataPartnerFee(chainId)— the exact CIP-75 volume-fee fragment ({ volumeBps, recipient }) forappData.metadata.partnerFee.ophisOrderReceiver/assertReceiverIsOwner— pin a CoW order'sreceiverto the owner. An unpinned receiver is the #1 drain vector for an automated signer.buildOphisOrderMetadata/enrollOphisTrader/buildOphisOrderCreation— the high-level order-flow helpers that collapse the integration footguns into one call each:appCodeis always'ophis'(a custom one silently forfeits the rebate), each trader wallet is enrolled with the rebate indexer, the receiver is asserted, and thesendOrderwire shape (fullappDatastring +appDataHash) is correct.getOphisVaultRelayer(chainId)— the correctapprovespender for the one-time sell-token approval. On Optimism the Ophis relayer is not cow-sdk's canonical one, so resolve it here.buildOphisEthFlowOrder/getOphisEthFlowAddress/isOphisEthFlowChain— sell native ETH through Ophis via the on-chain eth-flowcreateOrder, with the Ophis partner-fee appData embedded. Without this an integrator has to wrap to WETH first and Ophis is unavailable on native-ETH sells. The builder pins the receiver to the taker, hardcodes the eth-flowfeeAmount/msg.valuecorrectly, and (optionally) verifies the committed appData hash binds to the JSON you upload.assignTier,ophisDefaults, and the partner-fee constants.
Example
import {
getOphisOrderbookUrl,
getOphisOrderDomain,
buildOphisAppDataPartnerFee,
assertReceiverIsOwner,
} from '@ophis/sdk';
const orderbook = getOphisOrderbookUrl(10); // https://optimism-mainnet.ophis.fi
const domain = getOphisOrderDomain(10); // { name, version, chainId, verifyingContract }
const partnerFee = buildOphisAppDataPartnerFee(10); // { volumeBps, recipient }
assertReceiverIsOwner(owner, order.receiver); // throws if proceeds would leave the accountSecurity
These are off-chain misuse guards, not an authorization boundary — they make the safe path the easy path, but a caller can ignore them. For an agent that signs without a human in the loop, enforce policy on-chain (a Safe + an EIP-1271 policy validator: pinned receiver, pinned appData/hooks, an oracle-bounded limit price, spend caps, and a guardian). See the AI agent integration guide.
