Skip to main content
createTotalis runs every taker flow: it creates the RFQ, picks a quote, gets the signatures it needs, funds the stake, and follows the trade to the end.
The signer must be the account’s wallet. In a browser, pass window.ethereum or a wallet client instead (Wallets and partners).

Open a position

Legs go in strictly ascending outcome_id order. openPosition:
  1. Waits for the account stream, then creates the RFQ.
  2. Has the wallet sign any funding the vault is short of, while quotes arrive.
  3. Collects quotes and picks the best one.
  4. Has the wallet sign TakerAccept for it and sends the accept at once. If the answer is lost, it recovers the accept.
  5. If the quote was replaced or expired before the accept arrived, or the maker declined it or didn’t answer, nothing traded. It signs the best other quote paying at least minPayout and tries again. The next quote gets its own funding signature. It stops after refreshMs or maxAttempts.
Makers replace their quotes as they renew them, so step 5 is what keeps a slow wallet from losing its quote. It returns once a maker answers. status says what happened: The result also carries rfqId, acceptanceId, quoteId, positionId, the signed entry record, and bridged and bridging for an entry that bridged cash from HyperCore (Entry records). An accepted entry is not open yet. waitForOperation ends COMMITTED when it opened, or REVERTED or EXPIRED_UNEXECUTED when nothing traded.

Options

bestQuote() takes the highest payout still before its accept_before. A custom choose may be called again for a later time, so it must depend only on its arguments. Collection ends early if waiting would lose the quote or pass quoteTimeoutMs. Funding comes from free vault cash first, then the wallet, then a bridge of core. 0.05 USDC stays behind for the bridge’s gas.

How much one Combo can stake

readComboCash() reads the account’s balances and the signer’s HyperCore cash together, and answers the largest stake openPosition can fund now:
All amounts are atomic USDC. A field is null when it could not be read, and allowance is then null too: an unread balance is never counted as zero. Pass the read as cash and offeredCore as core so openPosition, signEntry and prepareEntryFunding plan from the same numbers.

Why an entry did not trade

An entry can fail before it is sent, or after it is accepted. Before anything is sent, while it plans the funding, openPosition throws EntryError and cancels the RFQ: After it is accepted, an operation that ends REVERTED or EXPIRED_UNEXECUTED traded nothing. entryFailure names the message to show:
Pass the latest record, as onSigned or onRecord last handed it to you. When the entry bridged and failed, see If an entry fails after its bridge.

Watch quotes yourself

To show quotes as they arrive instead of letting openPosition choose:
The listener gets the RFQ’s acceptable quotes, oldest first, and [] while the stream is down. A quote is dropped at its accept_before, and the listener is called again then. To take one, sign and send it as in Resume and retry.

Settlement

When a position’s markets resolve, Totalis settles it and pays the winnings into the owner’s vault balance. There is nothing to call.

Cash out

cashOut requests bids for the position, picks one with bestBid() (by default, the best bid with at least 25 seconds left), has the owner, or its vault agent, sign it, and sends one accept. It takes choose and collectMs like openPosition.

Withdraw

withdraw signs the Exit for any part of the amount the wallet is short of, plus the USDC payout, in one go. It resolves at PAYOUT_COMMITTED. After a restart, waitForWithdrawal(withdrawalId) follows it. To store the signed request before sending it, signWithdrawal returns { idempotencyKey, account, body } and sendWithdrawal(signed) sends it. A withdrawal with an unread balance throws BalanceUnknownError before anything is signed. To move cash to HyperCore instead, see Move cash to HyperCore.