Market Making Agent
This guide shows how a market maker listens for auction requests and provides signed bids.
Maker (liquidity provider) flow
- Connect to the WebSocket
- Listen for
auction.started { auctionId, maker, wager, resolver, predictedOutcomes[] }
- Construct and send
bid.submit { auctionId, taker, takerWager, takerDeadline, takerSignature, makerNonce }
- Receive
bid.ack { error? }
- Optionally
auction.subscribe { auctionId }
to keep receivingauction.bids
Minimal listener and bid (Node)
import WebSocket from 'ws';
const ws = new WebSocket('wss://api.sapience.xyz/auction');
ws.on('message', (data) => {
try {
const msg = JSON.parse(String(data));
if (msg.type === 'auction.started') {
const auction = msg.payload;
const bid = createBid(auction);
ws.send(JSON.stringify(bid));
}
} catch (e) {
console.error('parse error', e);
}
});
function createBid(auction: any) {
const now = Math.floor(Date.now() / 1000);
return {
type: 'bid.submit',
payload: {
auctionId: auction.auctionId,
taker: '0xMakerEOAUsedToProvideLiquidity...',
takerWager: (BigInt(auction.wager) / 2n).toString(),
takerDeadline: now + 60,
takerSignature: '0x' + '11'.repeat(32) + '22'.repeat(32),
makerNonce: 1,
},
} as const;
}
Notes
- Ensure ERC‑20 approvals for the collateral token if you automate on-chain fills
- The relayer enforces structure and expiry; optional strict EIP‑712 verification mirrors on‑chain
SignatureProcessor
Reference
- Builder Reference:
[Auction Relayer](/builder-guide/reference/auction-relayer)
- On-chain:
packages/protocol/src/predictionMarket/PredictionMarket.sol