mirror of
https://github.com/logos-blockchain/lez-programs.git
synced 2026-08-26 06:31:19 +00:00
96 lines
5.9 KiB
Plaintext
96 lines
5.9 KiB
Plaintext
// QtRO view contract for the AMM UI backend. PROPs auto-sync to every QML
|
|
// replica; SLOTs are the async surface QML calls via logos.watch(...).
|
|
// The account list is exposed separately as a Q_PROPERTY model on the backend
|
|
// (reached from QML via logos.model("amm_ui", "accountModel")).
|
|
class AmmUiBackend
|
|
{
|
|
PROP(bool isWalletOpen READONLY)
|
|
// False while startup or reconnect is still resolving wallet state. This
|
|
// stays distinct from isWalletOpen because a disconnected wallet is ready.
|
|
PROP(bool walletStateReady READONLY)
|
|
PROP(bool walletExists READONLY)
|
|
PROP(QString configPath READONLY)
|
|
PROP(QString storagePath READONLY)
|
|
PROP(QString walletHome READONLY)
|
|
PROP(int lastSyncedBlock READONLY)
|
|
PROP(int currentBlockHeight READONLY)
|
|
PROP(QString sequencerAddr READONLY)
|
|
// Whether the configured sequencer answered the last reachability probe.
|
|
// Defaults true so the UI doesn't flash a warning before the first check.
|
|
PROP(bool sequencerReachable READONLY)
|
|
|
|
// Account management
|
|
SLOT(QString createAccountPublic())
|
|
SLOT(QString createAccountPrivate())
|
|
SLOT(void refreshAccounts())
|
|
SLOT(void refreshBalances())
|
|
SLOT(QString getBalance(QString accountIdHex, bool isPublic))
|
|
|
|
// New Position backend surface. QML calls these through logos.watch(...).
|
|
// The QVariant payloads are stable maps/lists so the UI never assembles AMM
|
|
// transactions or duplicates quote state.
|
|
PROP(QVariantMap newPositionContext READONLY)
|
|
SLOT(void refreshNewPositionContext(QVariantMap request))
|
|
SLOT(QVariantMap quoteNewPosition(QVariantMap request))
|
|
SLOT(QVariantMap submitNewPosition(QVariantMap request, QString quoteHash))
|
|
|
|
// Wallet lifecycle. createNewDefault() is the happy path: it creates a
|
|
// fresh wallet at the canonical walletHome with no path picking. createNew()
|
|
// keeps explicit paths for an "advanced" flow. Both return the new wallet's
|
|
// BIP39 mnemonic (empty on failure) so the UI can force a seed-phrase backup
|
|
// before the wallet is usable — this is the only chance to record it.
|
|
SLOT(QString createNewDefault(QString password))
|
|
SLOT(QString createNew(QString configPath, QString storagePath, QString password))
|
|
|
|
// Re-open the existing on-disk wallet after a disconnect.
|
|
SLOT(bool openExisting())
|
|
// Close this app's wallet view (lock); does not delete the wallet and, in
|
|
// Basecamp, does not close the wallet other apps share.
|
|
SLOT(void disconnectWallet())
|
|
|
|
// AMM
|
|
// Derives the AMM pool's PDAs (config/pool/vaults/current-tick) from the
|
|
// deployed AMM program binary (see AMM_PROGRAM_BIN — a RISC Zero
|
|
// ProgramBinary .bin, not a raw ELF) and reads the pool's
|
|
// on-chain reserves. Returns `{ exists: false }` if the AMM program bin
|
|
// isn't configured, the AMM isn't initialized, or the pool has no
|
|
// liquidity yet.
|
|
SLOT(QVariantMap resolvePool(QString defAHex, QString defBHex))
|
|
// Submits a real on-chain SwapExactInput transaction against the pool for
|
|
// (defAHex, defBHex). amountInDecimal/minOutDecimal are decimal-string
|
|
// u128 amounts in base units; deadlineDecimal is a decimal-string u64 unix
|
|
// timestamp in MILLISECONDS (matches amm_core's SwapExactInput deadline —
|
|
// passing seconds would expire the swap immediately once deadline handling
|
|
// is enforced). Returns the tx hash, or an empty string on failure
|
|
// (no pool, unreadable AMM_PROGRAM_BIN, bad inputs, or a failed tx).
|
|
SLOT(QString swapExactInput(QString defAHex, QString defBHex, QString userInputHoldingHex, QString userOutputHoldingHex, QString amountInDecimal, QString minOutDecimal, QString deadlineDecimal))
|
|
// Server-side SwapExactInput preview for (tokenInHex, tokenOutHex): reads the
|
|
// pool and returns { status:"ok", error:"", expectedOutRaw, minReceivedRaw,
|
|
// priceImpactBps }, oriented and priced via the shared on-chain formula.
|
|
// amountInDecimal is a decimal-string base-unit amount; slippageBps is basis
|
|
// points. On failure { status:"error", error:<code> } — no_pool,
|
|
// config_missing, bad_amount, invalid_slippage (slippageBps out of range),
|
|
// backend_error. Read-only, no submission.
|
|
SLOT(QVariantMap swapExactInQuote(QString tokenInHex, QString tokenOutHex, QString amountInDecimal, int slippageBps))
|
|
// Server-side SwapExactOutput preview for (tokenInHex, tokenOutHex): reads the
|
|
// pool and returns { status:"ok", error:"", requiredInRaw, maxInRaw,
|
|
// priceImpactBps } — the input needed for the desired output and the slippage
|
|
// ceiling on it — oriented and priced via the shared on-chain formula.
|
|
// amountOutDecimal is a decimal-string base-unit amount; slippageBps is basis
|
|
// points. On failure { status:"error", error:<code> } — no_pool,
|
|
// output_exceeds_liquidity, config_missing, bad_amount, backend_error.
|
|
// Read-only, no submission.
|
|
SLOT(QVariantMap swapExactOutQuote(QString tokenInHex, QString tokenOutHex, QString amountOutDecimal, int slippageBps))
|
|
// Submits a real on-chain SwapExactOutput transaction against the pool for
|
|
// (defAHex, defBHex). amountOutDecimal is the exact desired output (base
|
|
// units); maxInDecimal is the slippage ceiling on the input actually spent;
|
|
// deadlineDecimal is a decimal-string u64 unix timestamp in MILLISECONDS.
|
|
// Same return contract as swapExactInput (tx hash, empty string on failure).
|
|
SLOT(QString swapExactOutput(QString defAHex, QString defBHex, QString userInputHoldingHex, QString userOutputHoldingHex, QString amountOutDecimal, QString maxInDecimal, QString deadlineDecimal))
|
|
// Reads the token list config at TOKENS_CONFIG (absolute path, JSON array
|
|
// of { symbol, name, definitionId, decimals }). A legacy holding field is
|
|
// accepted but transaction inputs come from wallet-owned TokenHoldings.
|
|
// Returns an empty list if TOKENS_CONFIG is unset/unreadable/invalid.
|
|
SLOT(QVariantList tokenList())
|
|
}
|