@xochi/widget 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +76 -0
- package/LICENSE +21 -0
- package/README.md +420 -2
- package/THIRD_PARTY_NOTICES.txt +44 -0
- package/dist/ConfiguratorApp.js +19 -0
- package/dist/EmbedApp.js +57 -0
- package/dist/assets/MonaspaceArgon-Bold-D9kWRRK5.woff2 +0 -0
- package/dist/assets/MonaspaceArgon-Light-Dt_6qXbW.woff2 +0 -0
- package/dist/assets/MonaspaceArgon-Medium-B1gMZwrU.woff2 +0 -0
- package/dist/assets/MonaspaceArgon-Regular-RS-2TGNg.woff2 +0 -0
- package/dist/assets/MonaspaceArgon-SemiBold-PYusZXE_.woff2 +0 -0
- package/dist/assets/MonaspaceNeon-Italic-C9u9eioB.woff2 +0 -0
- package/dist/assets/MonaspaceNeon-Light-CJkxpyfT.woff2 +0 -0
- package/dist/assets/MonaspaceNeon-Medium-DCChELAx.woff2 +0 -0
- package/dist/assets/MonaspaceNeon-Regular-BZtV1wRa.woff2 +0 -0
- package/dist/assets/MonaspaceXenon-Bold-KacFhGOf.woff2 +0 -0
- package/dist/assets/MonaspaceXenon-Medium-Dqqg-cnL.woff2 +0 -0
- package/dist/assets/MonaspaceXenon-Regular-BRsdKART.woff2 +0 -0
- package/dist/assets/MonaspaceXenon-SemiBold-DNjPl3uE.woff2 +0 -0
- package/dist/assets/alipay-3tx9-HPp.svg +1 -0
- package/dist/assets/arb-CCfLcB_X.svg +7 -0
- package/dist/assets/arc-Dy98eSCd.svg +10 -0
- package/dist/assets/aztec-DiLp9qTG.svg +4 -0
- package/dist/assets/base-Ch0ino36.svg +4 -0
- package/dist/assets/cashapp-lOg0DIt8.svg +1 -0
- package/dist/assets/chains/arbitrum.svg.js +4 -0
- package/dist/assets/chains/arc.svg.js +4 -0
- package/dist/assets/chains/aztec.svg.js +4 -0
- package/dist/assets/chains/base.svg.js +4 -0
- package/dist/assets/chains/ethereum.svg.js +4 -0
- package/dist/assets/chains/gnosis.png.js +4 -0
- package/dist/assets/chains/index.js +31 -0
- package/dist/assets/chains/optimism.svg.js +4 -0
- package/dist/assets/chains/polygon.svg.js +4 -0
- package/dist/assets/chains/robinhood.svg.js +4 -0
- package/dist/assets/chains/tron.svg.js +4 -0
- package/dist/assets/chains/xochi.svg.js +4 -0
- package/dist/assets/dai-XuyZLceZ.png +0 -0
- package/dist/assets/defillama-BU037Unq.svg +1 -0
- package/dist/assets/defillama.svg.js +4 -0
- package/dist/assets/eth-Dvbng9UB.svg +8 -0
- package/dist/assets/eurc-NI9zNgOQ.png +0 -0
- package/dist/assets/eure-BH9vpwcv.png +0 -0
- package/dist/assets/gnosis-fRzAZQFj.png +0 -0
- package/dist/assets/mercadopago-gjsFb6F7.svg +1 -0
- package/dist/assets/monzo-B9XD4bL5.png +0 -0
- package/dist/assets/monzo-SZnIdUKN.svg +1 -0
- package/dist/assets/monzo-dark-Bwzg90UC.png +0 -0
- package/dist/assets/n26-cANcjY2T.svg +1 -0
- package/dist/assets/op-DF67SbB6.png +0 -0
- package/dist/assets/optimism-B3cTNxEQ.svg +4 -0
- package/dist/assets/paypal-D8xqXEtN.svg +1 -0
- package/dist/assets/pol-uLmSo2O8.svg +3 -0
- package/dist/assets/rails/SOURCES.md +50 -0
- package/dist/assets/rails/alipay.svg.js +4 -0
- package/dist/assets/rails/cashapp.svg.js +4 -0
- package/dist/assets/rails/index.js +59 -0
- package/dist/assets/rails/mercadopago.svg.js +4 -0
- package/dist/assets/rails/monzo-dark.png.js +4 -0
- package/dist/assets/rails/monzo.png.js +4 -0
- package/dist/assets/rails/monzo.svg.js +4 -0
- package/dist/assets/rails/n26.svg.js +4 -0
- package/dist/assets/rails/paypal.svg.js +4 -0
- package/dist/assets/rails/revolut-dark.png.js +4 -0
- package/dist/assets/rails/revolut.png.js +4 -0
- package/dist/assets/rails/revolut.svg.js +4 -0
- package/dist/assets/rails/venmo.svg.js +4 -0
- package/dist/assets/rails/wise-dark.png.js +4 -0
- package/dist/assets/rails/wise.png.js +4 -0
- package/dist/assets/rails/wise.svg.js +4 -0
- package/dist/assets/rails/xmoney.svg.js +4 -0
- package/dist/assets/rails/zelle.svg.js +4 -0
- package/dist/assets/raxol-86FmC34h.png +0 -0
- package/dist/assets/revolut-CiBtyALA.png +0 -0
- package/dist/assets/revolut-D7qr5Vzs.svg +1 -0
- package/dist/assets/revolut-dark-RQdWGM_p.png +0 -0
- package/dist/assets/robinhood-DgdGTQ1I.svg +8 -0
- package/dist/assets/tokens/arb.svg.js +4 -0
- package/dist/assets/tokens/dai.png.js +4 -0
- package/dist/assets/tokens/eth.svg.js +4 -0
- package/dist/assets/tokens/eurc.png.js +4 -0
- package/dist/assets/tokens/eure.png.js +4 -0
- package/dist/assets/tokens/index.js +36 -0
- package/dist/assets/tokens/op.png.js +4 -0
- package/dist/assets/tokens/pol.svg.js +4 -0
- package/dist/assets/tokens/raxol.png.js +4 -0
- package/dist/assets/tokens/usdc.png.js +4 -0
- package/dist/assets/tokens/usdg.png.js +4 -0
- package/dist/assets/tokens/usdt.png.js +4 -0
- package/dist/assets/tokens/wbtc.png.js +4 -0
- package/dist/assets/tokens/wsteth.png.js +4 -0
- package/dist/assets/tokens/zchf.png.js +4 -0
- package/dist/assets/tron-Dtumyzha.svg +4 -0
- package/dist/assets/usdc-UHSd0FoM.png +0 -0
- package/dist/assets/usdg-Cd5nCzbC.png +0 -0
- package/dist/assets/usdt-3G3YdPq8.png +0 -0
- package/dist/assets/venmo-CMHeCn-D.svg +1 -0
- package/dist/assets/wbtc-CV8uE44Q.png +0 -0
- package/dist/assets/wise-BUOflsWL.svg +1 -0
- package/dist/assets/wise-JLpDvCdq.png +0 -0
- package/dist/assets/wise-dark-_Q8pbCom.png +0 -0
- package/dist/assets/wsteth-BamwtTCR.png +0 -0
- package/dist/assets/xmoney-CwY9KVlD.svg +1 -0
- package/dist/assets/xochi-DL2f8G4R.svg +4 -0
- package/dist/assets/zchf-BLBNdTGJ.png +0 -0
- package/dist/assets/zelle-t15cG4SB.svg +1 -0
- package/dist/browser.js +4 -0
- package/dist/components/AccountChip.js +29 -0
- package/dist/components/ActivityFeed.js +710 -0
- package/dist/components/AssetsStrip.js +133 -0
- package/dist/components/AuthorizedAgents.js +197 -0
- package/dist/components/Chevron.js +22 -0
- package/dist/components/ErrorDisplay.js +66 -0
- package/dist/components/InfoButton.js +27 -0
- package/dist/components/IntentTimeline.js +202 -0
- package/dist/components/LinksSignIn.js +26 -0
- package/dist/components/MobileSigningBanner.js +44 -0
- package/dist/components/PrivacyBars.js +44 -0
- package/dist/components/PrivacyPanel.js +99 -0
- package/dist/components/QuoteDetails.js +327 -0
- package/dist/components/ReceiptCommand.js +46 -0
- package/dist/components/SessionReloadBanner.js +19 -0
- package/dist/components/SolverRace.js +62 -0
- package/dist/components/StealthClaims.js +179 -0
- package/dist/components/SwapFlowModal.js +398 -0
- package/dist/components/Toast.js +40 -0
- package/dist/components/TokenIcon.js +21 -0
- package/dist/components/TokenSearchModal.js +331 -0
- package/dist/components/TransactionPreview.js +207 -0
- package/dist/components/WalletProvider.js +41 -0
- package/dist/components/WrapModal.js +192 -0
- package/dist/components/swap-flow/CantonEscrowPanel.js +28 -0
- package/dist/components/swap-flow/CantonEscrowStatus.js +160 -0
- package/dist/components/swap-flow/DepositInstructions.js +156 -0
- package/dist/components/swap-flow/QrCode.js +22 -0
- package/dist/components/swap-flow/SwapResult.js +323 -0
- package/dist/components/swap-flow/depositScreen.js +36 -0
- package/dist/components/widgetTabsContext.js +17 -0
- package/dist/config.js +132 -0
- package/dist/configurator-model.js +71 -0
- package/dist/configurator.js +11 -0
- package/dist/constants.js +53 -0
- package/dist/hooks/applyTheme.js +10 -0
- package/dist/hooks/useAgentRegistry.js +28 -0
- package/dist/hooks/useAgentStream.js +89 -0
- package/dist/hooks/useCantonEscrow.js +89 -0
- package/dist/hooks/useCapabilities.js +86 -0
- package/dist/hooks/useEmbedLook.js +23 -0
- package/dist/hooks/useFocusTrap.js +44 -0
- package/dist/hooks/useIntent.js +435 -0
- package/dist/hooks/useIntentStatusPoll.js +71 -0
- package/dist/hooks/useIntentStream.js +95 -0
- package/dist/hooks/useLocalActivity.js +114 -0
- package/dist/hooks/useLocalSends.js +15 -0
- package/dist/hooks/useLocalStorage.js +26 -0
- package/dist/hooks/useOrderHistory.js +307 -0
- package/dist/hooks/usePermit.js +131 -0
- package/dist/hooks/usePrices.js +49 -0
- package/dist/hooks/usePublicBalances.js +186 -0
- package/dist/hooks/useRampSummaries.js +19 -0
- package/dist/hooks/useRecipientBalance.js +98 -0
- package/dist/hooks/useSettlements.js +33 -0
- package/dist/hooks/useStealth.js +324 -0
- package/dist/hooks/useStealthClaim.js +183 -0
- package/dist/hooks/useStealthScanner.js +259 -0
- package/dist/hooks/useTheme.js +48 -0
- package/dist/hooks/useTierInfo.js +20 -0
- package/dist/hooks/useTrustScore.js +16 -0
- package/dist/hooks/useWalletSession.js +70 -0
- package/dist/hooks/useWrapEth.js +60 -0
- package/dist/index.js +41 -0
- package/dist/integration.js +19 -0
- package/dist/lib/activityValue.js +20 -0
- package/dist/lib/agentConnect.js +11 -0
- package/dist/lib/agentRegistry.js +83 -0
- package/dist/lib/agentStreamVerify.js +47 -0
- package/dist/lib/api.js +67 -0
- package/dist/lib/auth.js +8 -0
- package/dist/lib/authFetch.js +33 -0
- package/dist/lib/aztecTokens.js +13 -0
- package/dist/lib/balances.js +77 -0
- package/dist/lib/capabilities.js +40 -0
- package/dist/lib/claimSubmitPoll.js +63 -0
- package/dist/lib/debug.js +7 -0
- package/dist/lib/declineGuidance.js +31 -0
- package/dist/lib/displayFallbacks.js +25 -0
- package/dist/lib/eip712.js +38 -0
- package/dist/lib/errorCategory.js +200 -0
- package/dist/lib/errorReport.js +19 -0
- package/dist/lib/explorerLinks.js +30 -0
- package/dist/lib/feesLabel.js +19 -0
- package/dist/lib/glyphs.js +58 -0
- package/dist/lib/hostBridge.js +41 -0
- package/dist/lib/hostOrigin.js +52 -0
- package/dist/lib/intentAPI.js +39 -0
- package/dist/lib/linksSignIn.js +9 -0
- package/dist/lib/localActivity.js +247 -0
- package/dist/lib/localSends.js +129 -0
- package/dist/lib/mobileWallet.js +17 -0
- package/dist/lib/pairAvailability.js +29 -0
- package/dist/lib/paymentSummary.js +23 -0
- package/dist/lib/permits.js +27 -0
- package/dist/lib/priceImpact.js +101 -0
- package/dist/lib/providers.js +124 -0
- package/dist/lib/qr.js +20 -0
- package/dist/lib/quoteCost.js +34 -0
- package/dist/lib/quoteCountdown.js +24 -0
- package/dist/lib/rampHostGate.js +24 -0
- package/dist/lib/rampLifecycle.js +63 -0
- package/dist/lib/receiptCost.js +64 -0
- package/dist/lib/recipient/index.js +302 -0
- package/dist/lib/recipient/recent.js +47 -0
- package/dist/lib/recipientReceipt.js +16 -0
- package/dist/lib/reportClient.js +32 -0
- package/dist/lib/sessionExpiry.js +11 -0
- package/dist/lib/settlementAvailability.js +34 -0
- package/dist/lib/stealth.js +110 -0
- package/dist/lib/swapFlowPhase.js +52 -0
- package/dist/lib/swapStatusCopy.js +59 -0
- package/dist/lib/tradeLifecycle.js +40 -0
- package/dist/lib/tronlink.js +71 -0
- package/dist/lib/walletSession.js +87 -0
- package/dist/pages/Configurator.js +390 -0
- package/dist/pages/Trade.js +635 -0
- package/dist/pages/configurator/AllowedAssetsSection.js +98 -0
- package/dist/pages/configurator/AppearanceSection.js +44 -0
- package/dist/pages/configurator/CodeDock.js +140 -0
- package/dist/pages/configurator/DeveloperSection.js +40 -0
- package/dist/pages/configurator/IntegrationSection.js +105 -0
- package/dist/pages/configurator/LayoutSection.js +83 -0
- package/dist/pages/configurator/PolicyNote.js +7 -0
- package/dist/pages/configurator/PreviewStage.js +165 -0
- package/dist/pages/configurator/PrivacySection.js +54 -0
- package/dist/pages/configurator/RouteSection.js +211 -0
- package/dist/pages/configurator/Settings.js +35 -0
- package/dist/pages/configurator/SharedLinkBanner.js +25 -0
- package/dist/pages/configurator/SurfaceSection.js +124 -0
- package/dist/pages/configurator/WhatUsersSee.js +268 -0
- package/dist/pages/configurator/codeShown.js +8 -0
- package/dist/pages/configurator/configuratorUrl.js +33 -0
- package/dist/pages/configurator/paramsDraft.js +82 -0
- package/dist/pages/configurator/previewModel.js +10 -0
- package/dist/pages/configurator/previewQuote.js +109 -0
- package/dist/pages/configurator/routePicks.js +131 -0
- package/dist/pages/configurator/snippets.js +98 -0
- package/dist/pages/configurator/surfaceParams.js +51 -0
- package/dist/pages/configurator/useCodeCheck.js +79 -0
- package/dist/pages/configurator/useConfiguratorUrl.js +24 -0
- package/dist/pages/configurator/useMediaQuery.js +20 -0
- package/dist/pages/configurator/useParamsDraft.js +33 -0
- package/dist/pages/configurator/usePreviewFee.js +100 -0
- package/dist/pages/send/MetaAddressValue.js +28 -0
- package/dist/pages/send/Receive.js +168 -0
- package/dist/pages/send/RecentRecipients.js +23 -0
- package/dist/pages/send/RecipientChip.js +26 -0
- package/dist/pages/send/ScanRecipient.js +85 -0
- package/dist/pages/send/SendForm.js +516 -0
- package/dist/pages/send/SendPanel.js +30 -0
- package/dist/pages/send/ShieldedDisclosure.js +12 -0
- package/dist/pages/send/StealthInvite.js +27 -0
- package/dist/pages/send/addressSend.js +92 -0
- package/dist/pages/send/sendCopy.js +10 -0
- package/dist/pages/send/sendRetry.js +24 -0
- package/dist/pages/send/stealthRecipient.js +65 -0
- package/dist/pages/send/stealthSend.js +15 -0
- package/dist/pages/send/useAddressSend.js +257 -0
- package/dist/pages/send/useSendRecipient.js +61 -0
- package/dist/pages/trade/BuyPanel.js +70 -0
- package/dist/pages/trade/RampRecovery.js +41 -0
- package/dist/pages/trade/RecipientSheet.js +182 -0
- package/dist/pages/trade/Selectors.js +152 -0
- package/dist/pages/trade/SwapPanel.js +971 -0
- package/dist/pages/trade/WidgetTabs.js +109 -0
- package/dist/pages/trade/canton.js +122 -0
- package/dist/pages/trade/config.js +70 -0
- package/dist/pages/trade/embedNarrowing.js +25 -0
- package/dist/pages/trade/embedParams.js +532 -0
- package/dist/pages/trade/embedTheme.js +9 -0
- package/dist/pages/trade/orderMinimum.js +8 -0
- package/dist/pages/trade/resumeSwap.js +55 -0
- package/dist/pages/trade/settlementCopy.js +32 -0
- package/dist/pages/trade/useAmountFit.js +31 -0
- package/dist/pages/trade/useEmbedDefaults.js +18 -0
- package/dist/pages/trade/useSettlementGating.js +289 -0
- package/dist/pages/trade/useSwapAmount.js +191 -0
- package/dist/pages/trade/useSwapFlow.js +511 -0
- package/dist/pages/trade/useSwapPanel.js +475 -0
- package/dist/pages/trade/useSwapRoute.js +634 -0
- package/dist/pages/trade/useTronLinkFill.js +34 -0
- package/dist/pages/trade/zkMoney.js +46 -0
- package/dist/promiseWithResolvers.js +20 -0
- package/dist/ramp/availability/RailTiles.js +156 -0
- package/dist/ramp/availability/RampDisclosure.js +38 -0
- package/dist/ramp/availability/RampRails.js +170 -0
- package/dist/ramp/availability/model.js +207 -0
- package/dist/ramp/availability/useRampDiscovery.js +83 -0
- package/dist/ramp/offramp/CompletedPrerequisite.js +23 -0
- package/dist/ramp/offramp/OfframpActivityList.js +16 -0
- package/dist/ramp/offramp/OfframpRoute.js +222 -0
- package/dist/ramp/offramp/OfframpRouteReview.js +94 -0
- package/dist/ramp/offramp/PaymentAppSend.js +765 -0
- package/dist/ramp/offramp/localOfframps.js +101 -0
- package/dist/ramp/offramp/model.js +154 -0
- package/dist/ramp/offramp/port.js +134 -0
- package/dist/ramp/offramp/prerequisite.js +143 -0
- package/dist/ramp/offramp/useOfframp.js +505 -0
- package/dist/ramp/offramp/useOfframpRails.js +73 -0
- package/dist/ramp/peer/BuyOnramp.js +292 -0
- package/dist/ramp/peer/OnrampSteps.js +148 -0
- package/dist/ramp/peer/buyerDriver.js +461 -0
- package/dist/ramp/peer/discovery.js +231 -0
- package/dist/ramp/peer/environment.js +7 -0
- package/dist/ramp/peer/liveProvider.js +87 -0
- package/dist/ramp/peer/liveReads.js +488 -0
- package/dist/ramp/peer/maker.js +92 -0
- package/dist/ramp/peer/normalization.js +184 -0
- package/dist/ramp/peer/offramp.js +648 -0
- package/dist/ramp/peer/onramp.js +353 -0
- package/dist/ramp/peer/preview.js +52 -0
- package/dist/ramp/peer/protectedMapping.js +67 -0
- package/dist/ramp/peer/runtime.js +55 -0
- package/dist/ramp/peer/sdkMaker.js +107 -0
- package/dist/ramp/recovery/ResumeOnramp.js +153 -0
- package/dist/ramp/recovery/summaries.js +173 -0
- package/dist/ramp/route/OnrampRoute.js +255 -0
- package/dist/ramp/route/RampRouteSteps.js +148 -0
- package/dist/ramp/route/routeActivity.js +12 -0
- package/dist/ramp/route/useXochiRampDriver.js +203 -0
- package/dist/styles.css +17448 -0
- package/dist/styles.js +2 -0
- package/dist/types/ConfiguratorApp.d.ts +6 -0
- package/dist/types/EmbedApp.d.ts +2 -0
- package/dist/types/activity.js +50 -0
- package/dist/types/asset.d.ts +2 -0
- package/dist/types/assets/chains/index.d.ts +3 -0
- package/dist/types/assets/rails/index.d.ts +12 -0
- package/dist/types/assets/tokens/index.d.ts +1 -0
- package/dist/types/browser.d.ts +1 -0
- package/dist/types/components/AccountChip.d.ts +10 -0
- package/dist/types/components/ActivityFeed.d.ts +46 -0
- package/dist/types/components/AssetsStrip.d.ts +14 -0
- package/dist/types/components/AuthorizedAgents.d.ts +15 -0
- package/dist/types/components/Chevron.d.ts +16 -0
- package/dist/types/components/ErrorDisplay.d.ts +44 -0
- package/dist/types/components/InfoButton.d.ts +6 -0
- package/dist/types/components/IntentTimeline.d.ts +41 -0
- package/dist/types/components/LinksSignIn.d.ts +13 -0
- package/dist/types/components/MobileSigningBanner.d.ts +16 -0
- package/dist/types/components/PermitBadge.d.ts +17 -0
- package/dist/types/components/PrivacyBars.d.ts +12 -0
- package/dist/types/components/PrivacyPanel.d.ts +33 -0
- package/dist/types/components/QuoteDetails.d.ts +56 -0
- package/dist/types/components/RampActivityList.d.ts +14 -0
- package/dist/types/components/ReceiptCommand.d.ts +12 -0
- package/dist/types/components/SessionReloadBanner.d.ts +8 -0
- package/dist/types/components/SolverRace.d.ts +35 -0
- package/dist/types/components/StealthClaims.d.ts +51 -0
- package/dist/types/components/SwapFlowModal.d.ts +138 -0
- package/dist/types/components/Toast.d.ts +10 -0
- package/dist/types/components/TokenIcon.d.ts +17 -0
- package/dist/types/components/TokenSearchModal.d.ts +28 -0
- package/dist/types/components/TransactionPreview.d.ts +34 -0
- package/dist/types/components/WalletProvider.d.ts +12 -0
- package/dist/types/components/WrapModal.d.ts +19 -0
- package/dist/types/components/swap-flow/CantonEscrowPanel.d.ts +14 -0
- package/dist/types/components/swap-flow/CantonEscrowStatus.d.ts +30 -0
- package/dist/types/components/swap-flow/DepositInstructions.d.ts +75 -0
- package/dist/types/components/swap-flow/QrCode.d.ts +18 -0
- package/dist/types/components/swap-flow/SwapResult.d.ts +66 -0
- package/dist/types/components/swap-flow/depositScreen.d.ts +67 -0
- package/dist/types/components/widgetTabsContext.d.ts +21 -0
- package/dist/types/config.d.ts +104 -0
- package/dist/types/configurator-model.d.ts +9 -0
- package/dist/types/configurator.d.ts +3 -0
- package/dist/types/constants.d.ts +52 -0
- package/dist/types/hooks/applyTheme.d.ts +7 -0
- package/dist/types/hooks/useAgentRegistry.d.ts +13 -0
- package/dist/types/hooks/useAgentStream.d.ts +15 -0
- package/dist/types/hooks/useCantonEscrow.d.ts +40 -0
- package/dist/types/hooks/useCapabilities.d.ts +83 -0
- package/dist/types/hooks/useEmbedLook.d.ts +4 -0
- package/dist/types/hooks/useFocusTrap.d.ts +7 -0
- package/dist/types/hooks/useIntent.d.ts +156 -0
- package/dist/types/hooks/useIntentStatusPoll.d.ts +107 -0
- package/dist/types/hooks/useIntentStream.d.ts +34 -0
- package/dist/types/hooks/useLocalActivity.d.ts +22 -0
- package/dist/types/hooks/useLocalSends.d.ts +8 -0
- package/dist/types/hooks/useLocalStorage.d.ts +8 -0
- package/dist/types/hooks/useOrderHistory.d.ts +52 -0
- package/dist/types/hooks/usePermit.d.ts +84 -0
- package/dist/types/hooks/usePrices.d.ts +72 -0
- package/dist/types/hooks/usePublicBalances.d.ts +19 -0
- package/dist/types/hooks/useRampSummaries.d.ts +9 -0
- package/dist/types/hooks/useRecipientBalance.d.ts +58 -0
- package/dist/types/hooks/useSettlements.d.ts +14 -0
- package/dist/types/hooks/useStealth.d.ts +72 -0
- package/dist/types/hooks/useStealthClaim.d.ts +96 -0
- package/dist/types/hooks/useStealthScanner.d.ts +44 -0
- package/dist/types/hooks/useTheme.d.ts +29 -0
- package/dist/types/hooks/useTierInfo.d.ts +23 -0
- package/dist/types/hooks/useTrustScore.d.ts +16 -0
- package/dist/types/hooks/useWalletSession.d.ts +21 -0
- package/dist/types/hooks/useWrapEth.d.ts +21 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/index.js +8 -0
- package/dist/types/integration.d.ts +9 -0
- package/dist/types/intent.js +85 -0
- package/dist/types/lib/activityValue.d.ts +16 -0
- package/dist/types/lib/agentConnect.d.ts +23 -0
- package/dist/types/lib/agentRegistry.d.ts +47 -0
- package/dist/types/lib/agentStreamVerify.d.ts +29 -0
- package/dist/types/lib/api.d.ts +41 -0
- package/dist/types/lib/auth.d.ts +6 -0
- package/dist/types/lib/authFetch.d.ts +14 -0
- package/dist/types/lib/aztecTokens.d.ts +15 -0
- package/dist/types/lib/balances.d.ts +88 -0
- package/dist/types/lib/capabilities.d.ts +3 -0
- package/dist/types/lib/claimSubmitPoll.d.ts +114 -0
- package/dist/types/lib/debug.d.ts +13 -0
- package/dist/types/lib/declineGuidance.d.ts +55 -0
- package/dist/types/lib/displayFallbacks.d.ts +7 -0
- package/dist/types/lib/eip712.d.ts +61 -0
- package/dist/types/lib/errorCategory.d.ts +48 -0
- package/dist/types/lib/errorReport.d.ts +15 -0
- package/dist/types/lib/explorerLinks.d.ts +67 -0
- package/dist/types/lib/feesLabel.d.ts +20 -0
- package/dist/types/lib/glyphs.d.ts +52 -0
- package/dist/types/lib/hostBridge.d.ts +11 -0
- package/dist/types/lib/hostOrigin.d.ts +30 -0
- package/dist/types/lib/intentAPI.d.ts +15 -0
- package/dist/types/lib/linksSignIn.d.ts +13 -0
- package/dist/types/lib/localActivity.d.ts +135 -0
- package/dist/types/lib/localSends.d.ts +55 -0
- package/dist/types/lib/mobileWallet.d.ts +27 -0
- package/dist/types/lib/pairAvailability.d.ts +106 -0
- package/dist/types/lib/paymentSummary.d.ts +18 -0
- package/dist/types/lib/permits.d.ts +25 -0
- package/dist/types/lib/priceImpact.d.ts +165 -0
- package/dist/types/lib/providers.d.ts +14 -0
- package/dist/types/lib/qr.d.ts +19 -0
- package/dist/types/lib/quoteCost.d.ts +45 -0
- package/dist/types/lib/quoteCountdown.d.ts +34 -0
- package/dist/types/lib/rampHostGate.d.ts +15 -0
- package/dist/types/lib/rampLifecycle.d.ts +20 -0
- package/dist/types/lib/receiptCost.d.ts +64 -0
- package/dist/types/lib/recipient/index.d.ts +33 -0
- package/dist/types/lib/recipient/recent.d.ts +5 -0
- package/dist/types/lib/recipientReceipt.d.ts +25 -0
- package/dist/types/lib/reportClient.d.ts +9 -0
- package/dist/types/lib/sessionExpiry.d.ts +11 -0
- package/dist/types/lib/settlementAvailability.d.ts +61 -0
- package/dist/types/lib/stealth.d.ts +75 -0
- package/dist/types/lib/swapFlowPhase.d.ts +76 -0
- package/dist/types/lib/swapStatusCopy.d.ts +57 -0
- package/dist/types/lib/tierProgressDisplay.d.ts +35 -0
- package/dist/types/lib/tierUnlock.d.ts +25 -0
- package/dist/types/lib/tradeLifecycle.d.ts +32 -0
- package/dist/types/lib/tronlink.d.ts +62 -0
- package/dist/types/lib/walletSession.d.ts +38 -0
- package/dist/types/pages/Configurator.d.ts +25 -0
- package/dist/types/pages/Trade.d.ts +36 -0
- package/dist/types/pages/configurator/AllowedAssetsSection.d.ts +17 -0
- package/dist/types/pages/configurator/AppearanceSection.d.ts +22 -0
- package/dist/types/pages/configurator/CodeDock.d.ts +19 -0
- package/dist/types/pages/configurator/DeveloperSection.d.ts +12 -0
- package/dist/types/pages/configurator/IntegrationSection.d.ts +20 -0
- package/dist/types/pages/configurator/LayoutSection.d.ts +20 -0
- package/dist/types/pages/configurator/PolicyNote.d.ts +6 -0
- package/dist/types/pages/configurator/PreviewStage.d.ts +22 -0
- package/dist/types/pages/configurator/PrivacySection.d.ts +16 -0
- package/dist/types/pages/configurator/RouteSection.d.ts +30 -0
- package/dist/types/pages/configurator/Settings.d.ts +25 -0
- package/dist/types/pages/configurator/SharedLinkBanner.d.ts +16 -0
- package/dist/types/pages/configurator/SurfaceSection.d.ts +5 -0
- package/dist/types/pages/configurator/WhatUsersSee.d.ts +30 -0
- package/dist/types/pages/configurator/codeShown.d.ts +15 -0
- package/dist/types/pages/configurator/configuratorUrl.d.ts +38 -0
- package/dist/types/pages/configurator/paramsDraft.d.ts +32 -0
- package/dist/types/pages/configurator/previewModel.d.ts +20 -0
- package/dist/types/pages/configurator/previewQuote.d.ts +96 -0
- package/dist/types/pages/configurator/routePicks.d.ts +75 -0
- package/dist/types/pages/configurator/snippets.d.ts +23 -0
- package/dist/types/pages/configurator/surfaceParams.d.ts +9 -0
- package/dist/types/pages/configurator/useCodeCheck.d.ts +56 -0
- package/dist/types/pages/configurator/useConfiguratorUrl.d.ts +21 -0
- package/dist/types/pages/configurator/useMediaQuery.d.ts +5 -0
- package/dist/types/pages/configurator/useParamsDraft.d.ts +29 -0
- package/dist/types/pages/configurator/usePreviewFee.d.ts +74 -0
- package/dist/types/pages/send/MetaAddressValue.d.ts +9 -0
- package/dist/types/pages/send/Receive.d.ts +3 -0
- package/dist/types/pages/send/RecentRecipients.d.ts +3 -0
- package/dist/types/pages/send/RecipientChip.d.ts +4 -0
- package/dist/types/pages/send/ScanRecipient.d.ts +3 -0
- package/dist/types/pages/send/SendForm.d.ts +17 -0
- package/dist/types/pages/send/SendPanel.d.ts +19 -0
- package/dist/types/pages/send/ShieldedDisclosure.d.ts +1 -0
- package/dist/types/pages/send/StealthInvite.d.ts +1 -0
- package/dist/types/pages/send/addressSend.d.ts +62 -0
- package/dist/types/pages/send/sendCopy.d.ts +9 -0
- package/dist/types/pages/send/sendRetry.d.ts +10 -0
- package/dist/types/pages/send/stealthRecipient.d.ts +37 -0
- package/dist/types/pages/send/stealthSend.d.ts +18 -0
- package/dist/types/pages/send/useAddressSend.d.ts +61 -0
- package/dist/types/pages/send/useSendRecipient.d.ts +13 -0
- package/dist/types/pages/trade/BuyPanel.d.ts +22 -0
- package/dist/types/pages/trade/RampRecovery.d.ts +22 -0
- package/dist/types/pages/trade/RecipientSheet.d.ts +11 -0
- package/dist/types/pages/trade/Selectors.d.ts +24 -0
- package/dist/types/pages/trade/SwapPanel.d.ts +34 -0
- package/dist/types/pages/trade/WidgetTabs.d.ts +46 -0
- package/dist/types/pages/trade/canton.d.ts +94 -0
- package/dist/types/pages/trade/config.d.ts +185 -0
- package/dist/types/pages/trade/embedNarrowing.d.ts +28 -0
- package/dist/types/pages/trade/embedParams.d.ts +299 -0
- package/dist/types/pages/trade/embedTheme.d.ts +14 -0
- package/dist/types/pages/trade/harness.d.ts +120 -0
- package/dist/types/pages/trade/orderMinimum.d.ts +5 -0
- package/dist/types/pages/trade/resumeSwap.d.ts +139 -0
- package/dist/types/pages/trade/settlementCopy.d.ts +42 -0
- package/dist/types/pages/trade/useAmountFit.d.ts +25 -0
- package/dist/types/pages/trade/useEmbedDefaults.d.ts +28 -0
- package/dist/types/pages/trade/useSettlementGating.d.ts +152 -0
- package/dist/types/pages/trade/useSwapAmount.d.ts +93 -0
- package/dist/types/pages/trade/useSwapFlow.d.ts +152 -0
- package/dist/types/pages/trade/useSwapPanel.d.ts +170 -0
- package/dist/types/pages/trade/useSwapRoute.d.ts +215 -0
- package/dist/types/pages/trade/useTronLinkFill.d.ts +13 -0
- package/dist/types/pages/trade/zkMoney.d.ts +28 -0
- package/dist/types/promiseWithResolvers.d.ts +12 -0
- package/dist/types/ramp/availability/RailTiles.d.ts +26 -0
- package/dist/types/ramp/availability/RampDisclosure.d.ts +9 -0
- package/dist/types/ramp/availability/RampRails.d.ts +27 -0
- package/dist/types/ramp/availability/model.d.ts +51 -0
- package/dist/types/ramp/availability/useRampDiscovery.d.ts +60 -0
- package/dist/types/ramp/offramp/CompletedPrerequisite.d.ts +5 -0
- package/dist/types/ramp/offramp/OfframpActivityList.d.ts +12 -0
- package/dist/types/ramp/offramp/OfframpRoute.d.ts +8 -0
- package/dist/types/ramp/offramp/OfframpRouteReview.d.ts +12 -0
- package/dist/types/ramp/offramp/PaymentAppSend.d.ts +27 -0
- package/dist/types/ramp/offramp/localOfframps.d.ts +58 -0
- package/dist/types/ramp/offramp/model.d.ts +46 -0
- package/dist/types/ramp/offramp/port.d.ts +55 -0
- package/dist/types/ramp/offramp/prerequisite.d.ts +271 -0
- package/dist/types/ramp/offramp/useOfframp.d.ts +87 -0
- package/dist/types/ramp/offramp/useOfframpRails.d.ts +36 -0
- package/dist/types/ramp/peer/BuyOnramp.d.ts +21 -0
- package/dist/types/ramp/peer/OnrampSteps.d.ts +32 -0
- package/dist/types/ramp/peer/buyerDriver.d.ts +48 -0
- package/dist/types/ramp/peer/discovery.d.ts +17 -0
- package/dist/types/ramp/peer/environment.d.ts +2 -0
- package/dist/types/ramp/peer/index.d.ts +14 -0
- package/dist/types/ramp/peer/liveProvider.d.ts +15 -0
- package/dist/types/ramp/peer/liveReads.d.ts +102 -0
- package/dist/types/ramp/peer/maker.d.ts +4 -0
- package/dist/types/ramp/peer/normalization.d.ts +33 -0
- package/dist/types/ramp/peer/offramp.d.ts +130 -0
- package/dist/types/ramp/peer/onramp.d.ts +134 -0
- package/dist/types/ramp/peer/preview.d.ts +14 -0
- package/dist/types/ramp/peer/protectedMapping.d.ts +22 -0
- package/dist/types/ramp/peer/runtime.d.ts +15 -0
- package/dist/types/ramp/peer/sdkMaker.d.ts +67 -0
- package/dist/types/ramp/peer/types.d.ts +64 -0
- package/dist/types/ramp/recovery/ResumeOnramp.d.ts +37 -0
- package/dist/types/ramp/recovery/summaries.d.ts +71 -0
- package/dist/types/ramp/route/OnrampRoute.d.ts +12 -0
- package/dist/types/ramp/route/RampRouteSteps.d.ts +16 -0
- package/dist/types/ramp/route/routeActivity.d.ts +4 -0
- package/dist/types/ramp/route/useXochiRampDriver.d.ts +22 -0
- package/dist/types/result.js +14 -0
- package/dist/types/styles.d.ts +1 -0
- package/dist/types/types/activity.d.ts +184 -0
- package/dist/types/types/index.d.ts +20 -0
- package/dist/types/types/intent.d.ts +85 -0
- package/dist/types/types/result.d.ts +53 -0
- package/dist/types/utils/format.d.ts +88 -0
- package/dist/types/wagmi.d.ts +142 -0
- package/dist/types/widgetLibModule.d.ts +8 -0
- package/dist/utils/format.js +109 -0
- package/dist/wagmi.js +188 -0
- package/dist/widgetLibModule.js +4 -0
- package/licenses/Monaspace-OFL-1.1.txt +93 -0
- package/licenses/assets.json +132 -0
- package/licenses/rainbowkit-MIT.txt +9 -0
- package/licenses/xochi-shared-MIT.txt +21 -0
- package/package.json +115 -4
|
@@ -0,0 +1,648 @@
|
|
|
1
|
+
import { parseRamp, atomic, RampMoneySchema } from "@xochi/client";
|
|
2
|
+
import { peerConfiguration, checkPeerAbort, fetchPeerCapabilities, boundedPeerRead } from "./discovery.js";
|
|
3
|
+
import { makeOffer } from "./normalization.js";
|
|
4
|
+
import { browserMakerStorage, ProtectedMakerMappings } from "./protectedMapping.js";
|
|
5
|
+
import { previewPeerOffer } from "./preview.js";
|
|
6
|
+
class MakerSetupRequired extends Error {
|
|
7
|
+
constructor() {
|
|
8
|
+
super("setup_required");
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
class MakerWithdrawalBlocked extends Error {
|
|
12
|
+
constructor() {
|
|
13
|
+
super("active_intent_blocks_withdrawal");
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
const privateStores = /* @__PURE__ */ new WeakMap();
|
|
17
|
+
class PeerMakerPrivateStore {
|
|
18
|
+
constructor() {
|
|
19
|
+
privateStores.set(this, { entries: /* @__PURE__ */ new Map(), tail: Promise.resolve() });
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function access(store, run) {
|
|
23
|
+
const data = privateStores.get(store);
|
|
24
|
+
const pending = data.tail.then(() => run(data.entries));
|
|
25
|
+
data.tail = pending.catch(() => void 0);
|
|
26
|
+
return pending;
|
|
27
|
+
}
|
|
28
|
+
const copy = (value) => structuredClone(value);
|
|
29
|
+
class LocalFailure extends Error {
|
|
30
|
+
constructor(code) {
|
|
31
|
+
super(code);
|
|
32
|
+
this.code = code;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function fail(code = "invalid_request") {
|
|
36
|
+
if (code === "setup_required") throw new MakerSetupRequired();
|
|
37
|
+
throw new LocalFailure(code === "oracle_paused" ? "capability_unavailable" : code);
|
|
38
|
+
}
|
|
39
|
+
function factsValid(facts, total) {
|
|
40
|
+
try {
|
|
41
|
+
const remaining = BigInt(atomic(facts.remaining));
|
|
42
|
+
const unmatched = BigInt(atomic(facts.unmatched));
|
|
43
|
+
const filled = BigInt(atomic(facts.filled));
|
|
44
|
+
const withdrawn = BigInt(atomic(facts.withdrawn));
|
|
45
|
+
return remaining >= unmatched && remaining + filled + withdrawn === BigInt(total) && Number.isSafeInteger(facts.activeIntents) && facts.activeIntents >= 0 && (!facts.closed || remaining === 0n);
|
|
46
|
+
} catch {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function readinessCode(value) {
|
|
51
|
+
if (value.oracleFresh !== true) return "oracle_paused";
|
|
52
|
+
if (value.requiresIdentityAttestation && value.identityAttested !== true || value.sellerSetup === "required")
|
|
53
|
+
return "setup_required";
|
|
54
|
+
if (value.sellerSetup !== "ready") return "capability_unavailable";
|
|
55
|
+
}
|
|
56
|
+
function createPeerOfframpProvider(options) {
|
|
57
|
+
const store = options.store ?? new PeerMakerPrivateStore();
|
|
58
|
+
const now = options.discovery.now ?? Date.now;
|
|
59
|
+
const io = options.io;
|
|
60
|
+
const refusedRails = /* @__PURE__ */ new Set();
|
|
61
|
+
const recoveredWithdrawalHashes = /* @__PURE__ */ new Map();
|
|
62
|
+
const registrations = /* @__PURE__ */ new Map();
|
|
63
|
+
const config = peerConfiguration(options.discovery);
|
|
64
|
+
const browserStorage = options.storage === null ? void 0 : options.storage ?? browserMakerStorage();
|
|
65
|
+
const mappings = browserStorage && options.discovery.user ? new ProtectedMakerMappings(browserStorage, options.discovery.user, config.escrow) : void 0;
|
|
66
|
+
function persist(e) {
|
|
67
|
+
if (!mappings) return;
|
|
68
|
+
if (e.snapshot.terminal) {
|
|
69
|
+
mappings.remove(e.snapshot.operation_id);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
if (!e.depositId && !e.creationHash && e.claimed !== "create_deposit") {
|
|
73
|
+
mappings.remove(e.snapshot.operation_id);
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
if (e.depositId || e.creationHash || e.claimed === "create_deposit")
|
|
77
|
+
mappings.put({
|
|
78
|
+
operationRef: e.snapshot.operation_id,
|
|
79
|
+
escrowAddress: config.escrow,
|
|
80
|
+
depositId: e.depositId ?? null,
|
|
81
|
+
creationTxHash: e.creationHash ?? null,
|
|
82
|
+
legRevision: e.snapshot.revision
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
async function restore(entries, id, signal) {
|
|
86
|
+
const saved = mappings?.get(id);
|
|
87
|
+
if (!saved) fail();
|
|
88
|
+
const snapshot = {
|
|
89
|
+
contract_version: "ramp/1",
|
|
90
|
+
kind: "snapshot",
|
|
91
|
+
operation_id: id,
|
|
92
|
+
revision: saved.legRevision,
|
|
93
|
+
direction: "offramp",
|
|
94
|
+
leg_order: ["peer"],
|
|
95
|
+
peer: { name: "peer", state: "in_doubt", recoverable: true, failure_code: "peer_in_doubt" },
|
|
96
|
+
allowed_actions: ["check_status"],
|
|
97
|
+
updated_at: new Date(now()).toISOString(),
|
|
98
|
+
terminal: false
|
|
99
|
+
};
|
|
100
|
+
const rebuilt = await (io.rebuild ? boundedPeerRead(
|
|
101
|
+
(bound) => io.rebuild(saved, recoveredWithdrawalHashes.get(id), bound),
|
|
102
|
+
signal
|
|
103
|
+
) : void 0);
|
|
104
|
+
checkPeerAbort(signal);
|
|
105
|
+
if (!rebuilt || rebuilt.state === "pending") return snapshot;
|
|
106
|
+
const amount = atomic(rebuilt.amount);
|
|
107
|
+
const intent = {
|
|
108
|
+
contract_version: "ramp/1",
|
|
109
|
+
kind: "intent",
|
|
110
|
+
direction: "offramp",
|
|
111
|
+
exact: { side: "crypto", money: { asset: config.settlement, atomic: amount } },
|
|
112
|
+
fiat: { kind: "fiat", currency: "USD", decimals: 6 },
|
|
113
|
+
crypto: config.settlement,
|
|
114
|
+
recipient: options.discovery.user
|
|
115
|
+
};
|
|
116
|
+
const offer = makeOffer(
|
|
117
|
+
intent,
|
|
118
|
+
config,
|
|
119
|
+
"recovered",
|
|
120
|
+
now(),
|
|
121
|
+
{ state: "availability_unknown", reason_code: "capability_unavailable" },
|
|
122
|
+
["recovered"]
|
|
123
|
+
);
|
|
124
|
+
const preview = {
|
|
125
|
+
contract_version: "ramp/1",
|
|
126
|
+
kind: "preview",
|
|
127
|
+
operation_id: id,
|
|
128
|
+
quote_id: "recovered",
|
|
129
|
+
offer_id: offer.offer_id,
|
|
130
|
+
capability_revision: offer.capability_revision,
|
|
131
|
+
request_digest: `0x${"0".repeat(64)}`,
|
|
132
|
+
pay: { asset: config.settlement, atomic: amount },
|
|
133
|
+
receive: { asset: intent.fiat, atomic: atomic("0") },
|
|
134
|
+
fees: [],
|
|
135
|
+
expires_at: (/* @__PURE__ */ new Date(0)).toISOString(),
|
|
136
|
+
leg_order: ["peer"],
|
|
137
|
+
disclosures: offer.disclosures
|
|
138
|
+
};
|
|
139
|
+
entries.set(id, {
|
|
140
|
+
intent,
|
|
141
|
+
offer,
|
|
142
|
+
preview,
|
|
143
|
+
snapshot,
|
|
144
|
+
depositId: rebuilt.depositId,
|
|
145
|
+
creationHash: saved.creationTxHash ?? void 0,
|
|
146
|
+
approved: false,
|
|
147
|
+
transactionHashes: new Set(saved.creationTxHash ? [saved.creationTxHash.toLowerCase()] : []),
|
|
148
|
+
// S4 owns its persisted public CAS counter; it is independent of this leg revision.
|
|
149
|
+
commandRevision: 0n,
|
|
150
|
+
receipts: /* @__PURE__ */ new Map()
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
async function readReady(intent, rail, signal) {
|
|
154
|
+
try {
|
|
155
|
+
const result = await boundedPeerRead((bound) => io.readiness(intent, rail, bound), signal);
|
|
156
|
+
checkPeerAbort(signal);
|
|
157
|
+
return {
|
|
158
|
+
...result,
|
|
159
|
+
requiresIdentityAttestation: result.requiresIdentityAttestation || ["wise", "paypal", "alipay"].includes(rail)
|
|
160
|
+
};
|
|
161
|
+
} catch {
|
|
162
|
+
checkPeerAbort(signal);
|
|
163
|
+
fail("capability_unavailable");
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
function entry(entries, id) {
|
|
167
|
+
const value = entries.get(id) ?? fail();
|
|
168
|
+
if (options.discovery.user && value.intent.recipient.toLowerCase() !== options.discovery.user.toLowerCase())
|
|
169
|
+
fail("session_conflict");
|
|
170
|
+
return value;
|
|
171
|
+
}
|
|
172
|
+
function update(e, state, actions, failure) {
|
|
173
|
+
e.snapshot = {
|
|
174
|
+
...e.snapshot,
|
|
175
|
+
// An odd provider revision durably marks a withdrawal wallet handoff. After
|
|
176
|
+
// reload it cannot be re-authorized until its known wallet hash is reconciled.
|
|
177
|
+
revision: (() => {
|
|
178
|
+
let next = BigInt(e.snapshot.revision) + 1n;
|
|
179
|
+
const parity = e.claimed === "withdraw_unmatched" ? 1n : 0n;
|
|
180
|
+
if (next % 2n !== parity) next++;
|
|
181
|
+
return next.toString();
|
|
182
|
+
})(),
|
|
183
|
+
peer: {
|
|
184
|
+
name: "peer",
|
|
185
|
+
state,
|
|
186
|
+
recoverable: !["completed", "refunded"].includes(state),
|
|
187
|
+
...failure ? { failure_code: failure } : {},
|
|
188
|
+
...state === "completed" && e.amounts && BigInt(e.amounts.filled) > 0n && BigInt(e.amounts.withdrawn) > 0n ? {
|
|
189
|
+
partial_result: {
|
|
190
|
+
settlement: "base_usdc",
|
|
191
|
+
filled_atomic: e.amounts.filled,
|
|
192
|
+
returned_atomic: e.amounts.withdrawn
|
|
193
|
+
}
|
|
194
|
+
} : {}
|
|
195
|
+
},
|
|
196
|
+
allowed_actions: actions,
|
|
197
|
+
updated_at: new Date(now()).toISOString(),
|
|
198
|
+
terminal: ["completed", "refunded"].includes(state)
|
|
199
|
+
};
|
|
200
|
+
persist(e);
|
|
201
|
+
return copy(e.snapshot);
|
|
202
|
+
}
|
|
203
|
+
async function fresh(e, signal) {
|
|
204
|
+
if (Date.parse(e.preview.expires_at) <= now()) fail("quote_expired");
|
|
205
|
+
const ready = await readReady(e.intent, e.offer.rail.id, signal);
|
|
206
|
+
const code = refusedRails.has(e.offer.rail.id) ? "setup_required" : readinessCode(ready);
|
|
207
|
+
if (code) fail(code);
|
|
208
|
+
const preview = await previewPeerOffer(e.offer, e.intent, e.preview.operation_id, {
|
|
209
|
+
...options.discovery,
|
|
210
|
+
signal
|
|
211
|
+
});
|
|
212
|
+
checkPeerAbort(signal);
|
|
213
|
+
if (!preview.ok) fail(preview.code);
|
|
214
|
+
}
|
|
215
|
+
function validatePlan(transaction, action, expiresAt) {
|
|
216
|
+
if (transaction.chainId !== 8453 || transaction.value !== 0n || !/^0x[0-9a-fA-F]{40}$/.test(transaction.to) || !/^0x(?:[0-9a-fA-F]{2})+$/.test(transaction.data))
|
|
217
|
+
fail("provider_declined");
|
|
218
|
+
return { action, transaction: copy(transaction), expiresAt, account: options.discovery.user };
|
|
219
|
+
}
|
|
220
|
+
async function refresh(e, signal) {
|
|
221
|
+
checkPeerAbort(signal);
|
|
222
|
+
if (e.snapshot.terminal) return copy(e.snapshot);
|
|
223
|
+
if (e.claimed) {
|
|
224
|
+
if (!e.hash) return update(e, "in_doubt", ["check_status"], "peer_in_doubt");
|
|
225
|
+
const result = await boundedPeerRead(
|
|
226
|
+
(bound) => io.reconcile(e.hash, e.claimed, e.intent.recipient, e.plan.transaction, bound),
|
|
227
|
+
signal
|
|
228
|
+
);
|
|
229
|
+
checkPeerAbort(signal);
|
|
230
|
+
if (result.state === "pending")
|
|
231
|
+
return update(e, "in_doubt", ["check_status"], "peer_in_doubt");
|
|
232
|
+
const action = e.claimed;
|
|
233
|
+
if (result.state === "confirmed" && action === "create_deposit") {
|
|
234
|
+
if (!result.depositId) return update(e, "in_doubt", ["check_status"], "peer_in_doubt");
|
|
235
|
+
e.depositId = result.depositId;
|
|
236
|
+
delete e.ownAccount;
|
|
237
|
+
delete e.payeeHash;
|
|
238
|
+
registrations.delete(e.offer.rail.id);
|
|
239
|
+
}
|
|
240
|
+
delete e.claimed;
|
|
241
|
+
delete e.hash;
|
|
242
|
+
delete e.plan;
|
|
243
|
+
if (result.state === "reverted")
|
|
244
|
+
return update(e, "failed", ["check_status", "recover_peer"], "provider_declined");
|
|
245
|
+
if (action === "approve_usdc")
|
|
246
|
+
return update(e, "action_required", ["interact", "check_status"]);
|
|
247
|
+
}
|
|
248
|
+
if (!e.depositId) return copy(e.snapshot);
|
|
249
|
+
const facts = await boundedPeerRead(
|
|
250
|
+
(bound) => io.deposit(e.depositId, e.intent.recipient, bound),
|
|
251
|
+
signal
|
|
252
|
+
);
|
|
253
|
+
checkPeerAbort(signal);
|
|
254
|
+
if (!factsValid(facts, e.preview.pay.atomic)) fail("provider_declined");
|
|
255
|
+
const filled = BigInt(facts.filled), withdrawn = BigInt(facts.withdrawn), remaining = BigInt(facts.remaining);
|
|
256
|
+
const fiat = RampMoneySchema.safeParse(facts.deliveredFiat);
|
|
257
|
+
const deliveredFiat = fiat.success && fiat.data.asset.kind === "fiat" && fiat.data.asset.currency === e.intent.fiat.currency && filled > 0n ? fiat.data : void 0;
|
|
258
|
+
e.amounts = {
|
|
259
|
+
...deliveredFiat ? { deliveredFiat } : {},
|
|
260
|
+
deposited: atomic(e.preview.pay.atomic),
|
|
261
|
+
filled: atomic(facts.filled),
|
|
262
|
+
reserved: atomic(remaining - BigInt(facts.unmatched)),
|
|
263
|
+
withdrawable: atomic(facts.unmatched),
|
|
264
|
+
withdrawn: atomic(facts.withdrawn)
|
|
265
|
+
};
|
|
266
|
+
e.phase = remaining === 0n && facts.activeIntents === 0 ? filled > 0n ? "delivered" : withdrawn > 0n ? "returned" : void 0 : filled > 0n ? "delivering" : facts.activeIntents > 0 ? "matched" : "awaiting_buyer";
|
|
267
|
+
if (!e.phase) return update(e, "in_doubt", ["check_status"], "peer_in_doubt");
|
|
268
|
+
if (e.phase === "delivered") return update(e, "completed", []);
|
|
269
|
+
if (e.phase === "returned") return update(e, "refunded", []);
|
|
270
|
+
return update(e, "processing", [
|
|
271
|
+
"check_status",
|
|
272
|
+
...BigInt(facts.unmatched) > 0n ? ["interact"] : []
|
|
273
|
+
]);
|
|
274
|
+
}
|
|
275
|
+
async function command(id, name, context, run, signal) {
|
|
276
|
+
return access(store, async (entries) => {
|
|
277
|
+
checkPeerAbort(signal);
|
|
278
|
+
const e = copy(entry(entries, id));
|
|
279
|
+
const fingerprint = JSON.stringify([name, context]);
|
|
280
|
+
const receipt = e.receipts.get(context.idempotency_key);
|
|
281
|
+
if (receipt)
|
|
282
|
+
return receipt.fingerprint === fingerprint ? copy(receipt.snapshot) : fail("session_conflict");
|
|
283
|
+
if (e.snapshot.terminal) fail("invalid_request");
|
|
284
|
+
if (!context.idempotency_key || !/^(0|[1-9][0-9]*)$/.test(context.expected_revision) || // S4 owns public revisions and increments around its reservations. Provider-local
|
|
285
|
+
// observations/wallet handoffs have their own revisions, so compare command order
|
|
286
|
+
// rather than equating those independent counters.
|
|
287
|
+
BigInt(context.expected_revision) < e.commandRevision || e.claimed)
|
|
288
|
+
fail("session_conflict");
|
|
289
|
+
e.commandRevision = BigInt(context.expected_revision) + 1n;
|
|
290
|
+
let snapshot;
|
|
291
|
+
try {
|
|
292
|
+
snapshot = await run(e);
|
|
293
|
+
} catch (error) {
|
|
294
|
+
checkPeerAbort(signal);
|
|
295
|
+
if (error instanceof MakerSetupRequired) {
|
|
296
|
+
refusedRails.add(e.offer.rail.id);
|
|
297
|
+
e.reason = "setup_required";
|
|
298
|
+
} else if (error instanceof MakerWithdrawalBlocked)
|
|
299
|
+
e.reason = "active_intent_blocks_withdrawal";
|
|
300
|
+
else if (error instanceof LocalFailure && (error.code === "quote_expired" || error.code === "quote_changed"))
|
|
301
|
+
e.reason = error.code;
|
|
302
|
+
snapshot = update(
|
|
303
|
+
e,
|
|
304
|
+
"failed",
|
|
305
|
+
["requote", "check_status"],
|
|
306
|
+
error instanceof MakerSetupRequired ? "capability_unavailable" : error instanceof LocalFailure ? error.code : "provider_declined"
|
|
307
|
+
);
|
|
308
|
+
}
|
|
309
|
+
checkPeerAbort(signal);
|
|
310
|
+
entries.set(id, e);
|
|
311
|
+
e.receipts.set(context.idempotency_key, { fingerprint, snapshot: copy(snapshot) });
|
|
312
|
+
return snapshot;
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
async function readStatus(entries, id, signal) {
|
|
316
|
+
checkPeerAbort(signal);
|
|
317
|
+
const staged = new Map(entries);
|
|
318
|
+
if (staged.has(id)) staged.set(id, copy(staged.get(id)));
|
|
319
|
+
if (!staged.has(id)) {
|
|
320
|
+
try {
|
|
321
|
+
const pending = await restore(staged, id, signal);
|
|
322
|
+
if (pending) return pending;
|
|
323
|
+
} catch {
|
|
324
|
+
checkPeerAbort(signal);
|
|
325
|
+
fail("peer_in_doubt");
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
const e = entry(staged, id);
|
|
329
|
+
let snapshot;
|
|
330
|
+
try {
|
|
331
|
+
snapshot = await refresh(e, signal);
|
|
332
|
+
} catch {
|
|
333
|
+
checkPeerAbort(signal);
|
|
334
|
+
snapshot = update(e, "in_doubt", ["check_status"], "peer_in_doubt");
|
|
335
|
+
}
|
|
336
|
+
checkPeerAbort(signal);
|
|
337
|
+
entries.set(id, e);
|
|
338
|
+
return snapshot;
|
|
339
|
+
}
|
|
340
|
+
const provider = {
|
|
341
|
+
id: "peer",
|
|
342
|
+
async setupOwnAccount(rail, account, ownership) {
|
|
343
|
+
if (ownership !== "own_account" || !account || account.length > 256 || !Object.hasOwn(config.rails, rail))
|
|
344
|
+
fail();
|
|
345
|
+
try {
|
|
346
|
+
const hash = await io.registerOwnPayee(rail, account);
|
|
347
|
+
registrations.set(rail, { account, hash });
|
|
348
|
+
refusedRails.delete(rail);
|
|
349
|
+
} catch (error) {
|
|
350
|
+
if (error instanceof MakerSetupRequired) {
|
|
351
|
+
refusedRails.add(rail);
|
|
352
|
+
throw new MakerSetupRequired();
|
|
353
|
+
}
|
|
354
|
+
fail("provider_declined");
|
|
355
|
+
}
|
|
356
|
+
},
|
|
357
|
+
async capabilities(intent, signal) {
|
|
358
|
+
checkPeerAbort(signal);
|
|
359
|
+
if (intent.direction !== "offramp") return { offers: [] };
|
|
360
|
+
const result = await fetchPeerCapabilities(intent, { ...options.discovery, signal });
|
|
361
|
+
for (const offer of result.offers) {
|
|
362
|
+
try {
|
|
363
|
+
const code = refusedRails.has(offer.rail.id) ? "setup_required" : readinessCode(await readReady(intent, offer.rail.id, signal));
|
|
364
|
+
if (code)
|
|
365
|
+
offer.availability = code === "setup_required" ? { state: "setup_required", requirement_codes: ["maker_account_setup"] } : { state: "temporarily_unavailable", reason_code: code };
|
|
366
|
+
} catch {
|
|
367
|
+
checkPeerAbort(signal);
|
|
368
|
+
offer.availability = {
|
|
369
|
+
state: "availability_unknown",
|
|
370
|
+
reason_code: "capability_unavailable"
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
checkPeerAbort(signal);
|
|
375
|
+
const available = result.offers.filter((o) => o.availability.state === "available");
|
|
376
|
+
result.availability = available.length ? {
|
|
377
|
+
state: "available",
|
|
378
|
+
valid_until: new Date(
|
|
379
|
+
Math.min(
|
|
380
|
+
...available.map(
|
|
381
|
+
(o) => o.availability.state === "available" ? Date.parse(o.availability.valid_until) : Infinity
|
|
382
|
+
)
|
|
383
|
+
)
|
|
384
|
+
).toISOString()
|
|
385
|
+
} : result.offers.length && result.offers.every((o) => o.availability.state === "setup_required") ? { state: "setup_required", requirement_codes: ["maker_account_setup"] } : { state: "availability_unknown", reason_code: "capability_unavailable" };
|
|
386
|
+
return result;
|
|
387
|
+
},
|
|
388
|
+
normalizeCapabilities(raw) {
|
|
389
|
+
if (!raw || typeof raw !== "object" || !("offers" in raw) || !Array.isArray(raw.offers))
|
|
390
|
+
return [];
|
|
391
|
+
return raw.offers.flatMap((value) => {
|
|
392
|
+
const parsed = parseRamp(value);
|
|
393
|
+
return parsed.ok && parsed.value.kind === "offer" && parsed.value.direction === "offramp" ? [parsed.value] : [];
|
|
394
|
+
});
|
|
395
|
+
},
|
|
396
|
+
async preview(intent, offer, signal) {
|
|
397
|
+
checkPeerAbort(signal);
|
|
398
|
+
if (intent.direction !== "offramp" || options.discovery.user?.toLowerCase() !== intent.recipient.toLowerCase())
|
|
399
|
+
fail();
|
|
400
|
+
const id = (options.mintOperationId ?? (() => crypto.randomUUID()))();
|
|
401
|
+
const result = await previewPeerOffer(offer, intent, id, { ...options.discovery, signal });
|
|
402
|
+
if (!result.ok) fail(result.code);
|
|
403
|
+
const code = refusedRails.has(offer.rail.id) ? "setup_required" : readinessCode(await readReady(intent, offer.rail.id, signal));
|
|
404
|
+
if (code) fail(code);
|
|
405
|
+
return access(store, async (entries) => {
|
|
406
|
+
checkPeerAbort(signal);
|
|
407
|
+
if (entries.has(id)) fail("session_conflict");
|
|
408
|
+
const preview = result.preview;
|
|
409
|
+
const snapshot = {
|
|
410
|
+
contract_version: "ramp/1",
|
|
411
|
+
kind: "snapshot",
|
|
412
|
+
operation_id: id,
|
|
413
|
+
revision: "0",
|
|
414
|
+
direction: "offramp",
|
|
415
|
+
leg_order: ["peer"],
|
|
416
|
+
peer: { name: "peer", state: "quoted", recoverable: true },
|
|
417
|
+
allowed_actions: ["approve", "requote"],
|
|
418
|
+
updated_at: new Date(now()).toISOString(),
|
|
419
|
+
terminal: false
|
|
420
|
+
};
|
|
421
|
+
entries.set(id, {
|
|
422
|
+
intent: copy(intent),
|
|
423
|
+
offer: copy(offer),
|
|
424
|
+
preview: copy(preview),
|
|
425
|
+
snapshot,
|
|
426
|
+
approved: false,
|
|
427
|
+
...registrations.has(offer.rail.id) ? {
|
|
428
|
+
ownAccount: registrations.get(offer.rail.id).account,
|
|
429
|
+
payeeHash: registrations.get(offer.rail.id).hash
|
|
430
|
+
} : {},
|
|
431
|
+
transactionHashes: /* @__PURE__ */ new Set(),
|
|
432
|
+
commandRevision: 0n,
|
|
433
|
+
receipts: /* @__PURE__ */ new Map()
|
|
434
|
+
});
|
|
435
|
+
return copy(preview);
|
|
436
|
+
});
|
|
437
|
+
},
|
|
438
|
+
approve(preview, context, signal) {
|
|
439
|
+
return command(
|
|
440
|
+
preview.operation_id,
|
|
441
|
+
`approve:${JSON.stringify(preview)}`,
|
|
442
|
+
context,
|
|
443
|
+
async (e) => {
|
|
444
|
+
if (JSON.stringify(e.preview) !== JSON.stringify(preview) || e.depositId || e.approved)
|
|
445
|
+
fail("quote_changed");
|
|
446
|
+
await fresh(e, signal);
|
|
447
|
+
e.approved = true;
|
|
448
|
+
return update(e, "action_required", ["interact", "check_status"]);
|
|
449
|
+
},
|
|
450
|
+
signal
|
|
451
|
+
);
|
|
452
|
+
},
|
|
453
|
+
interact(id, context, signal) {
|
|
454
|
+
return command(
|
|
455
|
+
id,
|
|
456
|
+
"interact",
|
|
457
|
+
context,
|
|
458
|
+
async (e) => {
|
|
459
|
+
if (e.depositId) return refresh(e, signal);
|
|
460
|
+
if (e.plan) return copy(e.snapshot);
|
|
461
|
+
if (!e.approved) fail();
|
|
462
|
+
await fresh(e, signal);
|
|
463
|
+
if (!e.ownAccount) fail("setup_required");
|
|
464
|
+
if (!await boundedPeerRead(
|
|
465
|
+
(bound) => io.allowance(e.intent.recipient, e.preview.pay.atomic, bound),
|
|
466
|
+
signal
|
|
467
|
+
)) {
|
|
468
|
+
e.plan = validatePlan(
|
|
469
|
+
await io.prepareApproval(e.preview.pay.atomic),
|
|
470
|
+
"approve_usdc",
|
|
471
|
+
e.preview.expires_at
|
|
472
|
+
);
|
|
473
|
+
} else {
|
|
474
|
+
checkPeerAbort(signal);
|
|
475
|
+
if (!e.ownAccount) fail("setup_required");
|
|
476
|
+
e.payeeHash ??= await io.registerOwnPayee(e.offer.rail.id, e.ownAccount);
|
|
477
|
+
checkPeerAbort(signal);
|
|
478
|
+
e.plan = validatePlan(
|
|
479
|
+
await io.prepareDeposit(
|
|
480
|
+
{
|
|
481
|
+
intent: e.intent,
|
|
482
|
+
rail: e.offer.rail.id,
|
|
483
|
+
amount: e.preview.pay.atomic,
|
|
484
|
+
payeeHash: e.payeeHash,
|
|
485
|
+
capabilityRevision: e.preview.capability_revision
|
|
486
|
+
},
|
|
487
|
+
signal
|
|
488
|
+
),
|
|
489
|
+
"create_deposit",
|
|
490
|
+
e.preview.expires_at
|
|
491
|
+
);
|
|
492
|
+
}
|
|
493
|
+
checkPeerAbort(signal);
|
|
494
|
+
return update(e, "action_required", ["check_status"]);
|
|
495
|
+
},
|
|
496
|
+
signal
|
|
497
|
+
);
|
|
498
|
+
},
|
|
499
|
+
async status(id, signal) {
|
|
500
|
+
checkPeerAbort(signal);
|
|
501
|
+
return access(store, (entries) => readStatus(entries, id, signal));
|
|
502
|
+
},
|
|
503
|
+
async recover(id, action, context, signal) {
|
|
504
|
+
checkPeerAbort(signal);
|
|
505
|
+
if (action === "check_status") return provider.status(id, signal);
|
|
506
|
+
if (action !== "recover_peer" && action !== "requote") fail();
|
|
507
|
+
return command(
|
|
508
|
+
id,
|
|
509
|
+
action,
|
|
510
|
+
context,
|
|
511
|
+
async (e) => {
|
|
512
|
+
if (e.depositId) return refresh(e, signal);
|
|
513
|
+
delete e.plan;
|
|
514
|
+
e.approved = false;
|
|
515
|
+
return update(e, "quoted", ["requote"]);
|
|
516
|
+
},
|
|
517
|
+
signal
|
|
518
|
+
);
|
|
519
|
+
},
|
|
520
|
+
async setOwnAccount(id, account, ownership) {
|
|
521
|
+
await access(store, async (entries) => {
|
|
522
|
+
const e = entry(entries, id);
|
|
523
|
+
if (ownership !== "own_account" || !account || account.length > 256 || e.depositId || e.approved || e.claimed || e.payeeHash)
|
|
524
|
+
fail();
|
|
525
|
+
e.ownAccount = account;
|
|
526
|
+
});
|
|
527
|
+
},
|
|
528
|
+
async takeUnsignedPlan(id, signal) {
|
|
529
|
+
checkPeerAbort(signal);
|
|
530
|
+
return access(store, async (entries) => {
|
|
531
|
+
const e = entry(entries, id);
|
|
532
|
+
if (!e.plan || e.claimed) fail();
|
|
533
|
+
if (Date.parse(e.plan.expiresAt) <= now()) {
|
|
534
|
+
delete e.plan;
|
|
535
|
+
fail("quote_expired");
|
|
536
|
+
}
|
|
537
|
+
if (e.plan.action !== "withdraw_unmatched") await fresh(e, signal);
|
|
538
|
+
else {
|
|
539
|
+
if (!e.depositId || !e.withdrawalAmount) fail();
|
|
540
|
+
let facts;
|
|
541
|
+
try {
|
|
542
|
+
facts = await boundedPeerRead(
|
|
543
|
+
(bound) => io.deposit(e.depositId, e.intent.recipient, bound),
|
|
544
|
+
signal
|
|
545
|
+
);
|
|
546
|
+
} catch {
|
|
547
|
+
checkPeerAbort(signal);
|
|
548
|
+
fail("peer_in_doubt");
|
|
549
|
+
}
|
|
550
|
+
if (!factsValid(facts, e.preview.pay.atomic) || BigInt(e.withdrawalAmount) > BigInt(facts.unmatched) || BigInt(e.withdrawalAmount) === BigInt(facts.remaining) && facts.activeIntents > 0)
|
|
551
|
+
throw new MakerWithdrawalBlocked();
|
|
552
|
+
}
|
|
553
|
+
checkPeerAbort(signal);
|
|
554
|
+
e.claimed = e.plan.action;
|
|
555
|
+
update(e, "in_doubt", ["check_status"], "peer_in_doubt");
|
|
556
|
+
return copy(e.plan);
|
|
557
|
+
});
|
|
558
|
+
},
|
|
559
|
+
async recordSubmission(id, action, hash) {
|
|
560
|
+
await access(store, async (entries) => {
|
|
561
|
+
if (!entries.has(id)) {
|
|
562
|
+
const saved = mappings?.get(id);
|
|
563
|
+
if (saved?.depositId && action === "withdraw_unmatched" && BigInt(saved.legRevision) % 2n === 1n && /^0x[0-9a-fA-F]{64}$/.test(hash)) {
|
|
564
|
+
recoveredWithdrawalHashes.set(id, hash);
|
|
565
|
+
return;
|
|
566
|
+
}
|
|
567
|
+
if (!saved || saved.creationTxHash || action !== "create_deposit" || !/^0x[0-9a-fA-F]{64}$/.test(hash))
|
|
568
|
+
fail();
|
|
569
|
+
mappings.put({ ...saved, creationTxHash: hash });
|
|
570
|
+
return;
|
|
571
|
+
}
|
|
572
|
+
const e = entry(entries, id);
|
|
573
|
+
if (e.claimed !== action || e.hash || !/^0x[0-9a-fA-F]{64}$/.test(hash)) fail();
|
|
574
|
+
if ([...entries.values()].some((other) => other.transactionHashes.has(hash.toLowerCase())))
|
|
575
|
+
fail("session_conflict");
|
|
576
|
+
e.transactionHashes.add(hash.toLowerCase());
|
|
577
|
+
e.hash = hash;
|
|
578
|
+
if (action === "create_deposit") e.creationHash = hash;
|
|
579
|
+
persist(e);
|
|
580
|
+
});
|
|
581
|
+
},
|
|
582
|
+
async recordWalletRejection(id) {
|
|
583
|
+
await access(store, async (entries) => {
|
|
584
|
+
const e = entry(entries, id);
|
|
585
|
+
if (!e.claimed || e.hash) fail();
|
|
586
|
+
delete e.claimed;
|
|
587
|
+
delete e.plan;
|
|
588
|
+
update(
|
|
589
|
+
e,
|
|
590
|
+
e.depositId ? "processing" : "action_required",
|
|
591
|
+
["interact", "check_status"],
|
|
592
|
+
"approval_rejected"
|
|
593
|
+
);
|
|
594
|
+
});
|
|
595
|
+
},
|
|
596
|
+
prepareWithdrawal(id, amount, context, signal) {
|
|
597
|
+
return command(
|
|
598
|
+
id,
|
|
599
|
+
`withdraw:${amount}`,
|
|
600
|
+
context,
|
|
601
|
+
async (e) => {
|
|
602
|
+
if (!e.depositId || e.plan) fail();
|
|
603
|
+
const requested = BigInt(atomic(amount));
|
|
604
|
+
const facts = await boundedPeerRead(
|
|
605
|
+
(bound) => io.deposit(e.depositId, e.intent.recipient, bound),
|
|
606
|
+
signal
|
|
607
|
+
);
|
|
608
|
+
if (!factsValid(facts, e.preview.pay.atomic) || requested <= 0n || requested > BigInt(facts.unmatched))
|
|
609
|
+
fail();
|
|
610
|
+
const full = requested === BigInt(facts.remaining);
|
|
611
|
+
if (full && facts.activeIntents > 0) throw new MakerWithdrawalBlocked();
|
|
612
|
+
e.withdrawalAmount = amount;
|
|
613
|
+
e.plan = validatePlan(
|
|
614
|
+
await io.prepareWithdrawal(e.depositId, amount, full, signal),
|
|
615
|
+
"withdraw_unmatched",
|
|
616
|
+
new Date(now() + 3e4).toISOString()
|
|
617
|
+
);
|
|
618
|
+
checkPeerAbort(signal);
|
|
619
|
+
return update(e, "action_required", ["check_status"]);
|
|
620
|
+
},
|
|
621
|
+
signal
|
|
622
|
+
);
|
|
623
|
+
},
|
|
624
|
+
async orderStatus(id, signal) {
|
|
625
|
+
checkPeerAbort(signal);
|
|
626
|
+
return access(store, async (entries) => {
|
|
627
|
+
const snapshot = await readStatus(entries, id, signal);
|
|
628
|
+
checkPeerAbort(signal);
|
|
629
|
+
const current = entries.get(id);
|
|
630
|
+
const depositTransaction = current?.depositId ? current.creationHash : void 0;
|
|
631
|
+
return {
|
|
632
|
+
snapshot,
|
|
633
|
+
...depositTransaction && /^0x[0-9a-fA-F]{64}$/.test(depositTransaction) ? { depositTransaction } : {},
|
|
634
|
+
...snapshot.peer.state !== "in_doubt" && entries.get(id)?.amounts ? { amounts: copy(entries.get(id).amounts) } : {},
|
|
635
|
+
...snapshot.peer.state !== "in_doubt" && entries.get(id)?.phase ? { phase: entries.get(id)?.phase } : {},
|
|
636
|
+
...entries.get(id)?.reason ? { reason: entries.get(id)?.reason } : {}
|
|
637
|
+
};
|
|
638
|
+
});
|
|
639
|
+
}
|
|
640
|
+
};
|
|
641
|
+
return provider;
|
|
642
|
+
}
|
|
643
|
+
export {
|
|
644
|
+
MakerSetupRequired,
|
|
645
|
+
MakerWithdrawalBlocked,
|
|
646
|
+
PeerMakerPrivateStore,
|
|
647
|
+
createPeerOfframpProvider
|
|
648
|
+
};
|