At this stage, the solver calls openPosition() or a combined function (lockAndOpenQuote()).
Partial Fills are possible: if Hedger only wants to open half the quantity, the remainder might get reposted as a new Intent.
The contract does a final solvency check via Muon. If any party is insolvent, the contract disallows opening.
Before a Hedger can lockQuote() or openPosition(), sufficient collateral must be allocated to PartyB. This allocation ensures that PartyB meets the margin requirements for handling the position. If the allocated balance is insufficient, the contract will reject the lockQuote or openPosition transaction.
Allocating Collateral for partyB
Below is a short script that shows how a solver would allocate collateral to a partyA. More information can be found here.
asyncfunctionallocateForPartyB(amount, partyB, partyA) {try {console.log(`Allocating ${amount} tokens for PartyB with address ${partyA} from ${partyB}...`);// Estimate gas for the transactionconstallocateGasEstimate=awaitdiamondContract.methods.allocateForPartyB(amount, partyA).estimateGas({ from: partyB });console.log("Estimated Gas: ", allocateGasEstimate);// Fetch current gas priceconstallocateGasPrice=awaitweb3.eth.getGasPrice();console.log("Current Gas Price: ", allocateGasPrice);// Execute the allocation transactionconstreceipt=awaitdiamondContract.methods.allocateForPartyB(amount, partyA).send({ from: partyB, gas: allocateGasEstimate, gasPrice: allocateGasPrice, });console.log("Allocation successful!");return { success:true, receipt: receipt }; } catch (error) {console.error("Error during allocation:", error);return { success:false, error:error.toString() }; }}
Locking the Quote
Locking the quote ensures that no other Hedger can act on the same quoteId. This step requires a valid Muon signature for the uPnl (uPnl_B) of the position. You can read more about this method here. The formatted signature and quoteId must be passed to the lockQuote() method.
The Muon uPnlWithSymbolPrice method is used for solvency verification. The positionState will change to OPENED upon successful execution. If any party is insolvent, the contract will reject the transaction.
Combined Methods: lockAndOpenQuote()
For efficiency, solvers can use combined methods like lockAndOpenQuote(). These methods execute the locking and opening steps in a single transaction.
The same signature is required as for opening a Quote.
Once opened, the position remains active until fully closed or liquidated. PartyA can place limit or market close requests, which the solver can fill. If the solver fails to respond within a certain timeframe the partyA can execute force closes or force cancels.
Closing a Position
PartyA calls requestToCloseQuote() with parameters (quantity, price if limit, etc.). The solver can close his corresponding off-chain hedge, then call fillCloseRequest() on-chain.
Closing a position on SYMMIO involves calling the fillCloseRequest() function. The solver (PartyB) can close an open position partially or fully, depending on the request type and specified amount.
How fillCloseRequest Works
Parameters:
quoteId: The unique identifier of the quote to be closed.
filledAmount: The amount being closed.
closedPrice: The final price at which the position is being closed.
upnlSig: A Muon signature that ensures solvency and validates the closing action.
LIMIT requests can be closed incrementally in multiple steps however MARKET requests must be closed in a single transaction.
Preconditions for Closing
Ensure the Hedger (PartyB) is authorized to act on the quote. If not, contact SYMMIO developers to enable whitelisting.
A Muon signature validates solvency for both parties before the close action is processed.
The position must not be in the LIQUIDATED state, and the partyA must be solvent after the close.
The script allows PartyB to close a trade initiated by PartyA using the fillCloseRequest() function on the smart contract. The Muon signature is used for solvency validation. The correct Muon method here is also uPnlWithSymbolPrice