@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,461 @@
|
|
|
1
|
+
import { PEER_ENVIRONMENT } from "../../config.js";
|
|
2
|
+
import { getContracts, Zkp2pClient, parseDeferredPayoutFromLogs, DISPUTE_PROTECTION_POLICY_V2_ABI, resolveFiatCurrencyBytes32, apiGetPayeeDetails, apiSignIntentV3Raw } from "@zkp2p/sdk";
|
|
3
|
+
import { parseEventLogs, formatUnits, erc20Abi } from "viem";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
import { peerConfiguration, boundedPeerRead } from "./discovery.js";
|
|
6
|
+
import { digest, normalizePeerQuotes } from "./normalization.js";
|
|
7
|
+
import { PEER_ATTESTATION_ORIGIN, peerRequiresLinkedSession, PeerSigningSetupRequired } from "./onramp.js";
|
|
8
|
+
const buyerEvents = [
|
|
9
|
+
{
|
|
10
|
+
type: "event",
|
|
11
|
+
name: "IntentSignaled",
|
|
12
|
+
inputs: [
|
|
13
|
+
{ name: "intentHash", type: "bytes32", indexed: true },
|
|
14
|
+
{ name: "escrow", type: "address", indexed: true },
|
|
15
|
+
{ name: "depositId", type: "uint256", indexed: true },
|
|
16
|
+
{ name: "paymentMethod", type: "bytes32", indexed: false },
|
|
17
|
+
{ name: "owner", type: "address", indexed: false },
|
|
18
|
+
{ name: "to", type: "address", indexed: false },
|
|
19
|
+
{ name: "amount", type: "uint256", indexed: false },
|
|
20
|
+
{ name: "fiatCurrency", type: "bytes32", indexed: false },
|
|
21
|
+
{ name: "conversionRate", type: "uint256", indexed: false },
|
|
22
|
+
{ name: "timestamp", type: "uint256", indexed: false },
|
|
23
|
+
{ name: "groupId", type: "bytes32", indexed: false },
|
|
24
|
+
{ name: "arbitrator", type: "address", indexed: false }
|
|
25
|
+
]
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
type: "event",
|
|
29
|
+
name: "IntentFulfilled",
|
|
30
|
+
inputs: [
|
|
31
|
+
{ name: "intentHash", type: "bytes32", indexed: true },
|
|
32
|
+
{ name: "fundsTransferredTo", type: "address", indexed: true },
|
|
33
|
+
{ name: "amount", type: "uint256", indexed: false },
|
|
34
|
+
{ name: "releasedBy", type: "address", indexed: false }
|
|
35
|
+
]
|
|
36
|
+
}
|
|
37
|
+
];
|
|
38
|
+
const uint = z.string().regex(/^(0|[1-9][0-9]*)$/).max(78);
|
|
39
|
+
const hex32 = z.string().regex(/^0x[0-9a-fA-F]{64}$/);
|
|
40
|
+
const address = z.string().regex(/^0x[0-9a-fA-F]{40}$/);
|
|
41
|
+
const executionQuote = z.object({
|
|
42
|
+
conversionRate: uint,
|
|
43
|
+
signalIntentAmount: uint,
|
|
44
|
+
intent: z.object({
|
|
45
|
+
depositId: z.union([uint, z.number().int().nonnegative().max(Number.MAX_SAFE_INTEGER)]),
|
|
46
|
+
escrowAddress: address,
|
|
47
|
+
payeeDetails: hex32,
|
|
48
|
+
toAddress: address,
|
|
49
|
+
processorName: z.string(),
|
|
50
|
+
fiatCurrencyCode: z.string()
|
|
51
|
+
})
|
|
52
|
+
});
|
|
53
|
+
const urls = {
|
|
54
|
+
production: "https://api.zkp2p.xyz",
|
|
55
|
+
preproduction: "https://api-preprod.zkp2p.xyz",
|
|
56
|
+
staging: "https://api-staging.zkp2p.xyz"
|
|
57
|
+
};
|
|
58
|
+
const resumeCheckpoint = z.object({
|
|
59
|
+
terms: hex32,
|
|
60
|
+
payee: hex32,
|
|
61
|
+
payAtomic: uint,
|
|
62
|
+
receiveAtomic: uint,
|
|
63
|
+
after: z.number().int().nonnegative().safe(),
|
|
64
|
+
before: z.number().int().nonnegative().safe()
|
|
65
|
+
});
|
|
66
|
+
const submissionWindowMs = 12e4;
|
|
67
|
+
const resumeKey = (id) => `xochi:peer-buyer-binding:v1:${id}`;
|
|
68
|
+
function termsDigest(facts) {
|
|
69
|
+
return digest([
|
|
70
|
+
facts.owner.toLowerCase(),
|
|
71
|
+
facts.to.toLowerCase(),
|
|
72
|
+
facts.escrow.toLowerCase(),
|
|
73
|
+
facts.depositId.toString(),
|
|
74
|
+
facts.amount.toString(),
|
|
75
|
+
facts.conversionRate.toString(),
|
|
76
|
+
facts.paymentMethod.toLowerCase(),
|
|
77
|
+
facts.fiatCurrency.toLowerCase()
|
|
78
|
+
]);
|
|
79
|
+
}
|
|
80
|
+
function peerRecipientTransfer(logs, token, recipient, amount, from) {
|
|
81
|
+
const same = (a, b) => a.toLowerCase() === b.toLowerCase();
|
|
82
|
+
return parseEventLogs({ abi: erc20Abi, eventName: "Transfer", logs }).some(
|
|
83
|
+
(log) => same(log.address, token) && same(log.args.to, recipient) && log.args.value === amount && (!from || same(log.args.from, from))
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
function createPeerBuyerDriver(options) {
|
|
87
|
+
const config = peerConfiguration(options);
|
|
88
|
+
const environment = options.environment ?? PEER_ENVIRONMENT;
|
|
89
|
+
const escrowAbi = getContracts(8453, environment).abis.escrowV2;
|
|
90
|
+
if (!escrowAbi) throw new Error("capabilities_unavailable");
|
|
91
|
+
const account = options.wallet.account;
|
|
92
|
+
if (!account || options.publicClient.chain?.id !== 8453) throw new Error("invalid_request");
|
|
93
|
+
const sdk = new Zkp2pClient({
|
|
94
|
+
walletClient: options.wallet,
|
|
95
|
+
chainId: 8453,
|
|
96
|
+
runtimeEnv: environment,
|
|
97
|
+
baseApiUrl: urls[environment]
|
|
98
|
+
});
|
|
99
|
+
const bindings = /* @__PURE__ */ new Map();
|
|
100
|
+
function storage() {
|
|
101
|
+
return options.resumeStorage ?? globalThis.localStorage;
|
|
102
|
+
}
|
|
103
|
+
async function send(prepared) {
|
|
104
|
+
if (prepared.chainId !== 8453 || prepared.to.toLowerCase() !== config.orchestrator.toLowerCase() || prepared.value !== 0n || await options.wallet.getChainId() !== 8453 || (await options.wallet.getAddresses())[0]?.toLowerCase() !== account.address.toLowerCase())
|
|
105
|
+
throw new Error("invalid_request");
|
|
106
|
+
return options.wallet.sendTransaction({
|
|
107
|
+
account,
|
|
108
|
+
chain: options.wallet.chain,
|
|
109
|
+
to: prepared.to,
|
|
110
|
+
data: prepared.data,
|
|
111
|
+
value: prepared.value
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
async function confirmed(hash) {
|
|
115
|
+
const receipt = await options.publicClient.waitForTransactionReceipt({
|
|
116
|
+
hash,
|
|
117
|
+
confirmations: 2
|
|
118
|
+
});
|
|
119
|
+
if (receipt.status !== "success") throw new Error("provider_declined");
|
|
120
|
+
return receipt;
|
|
121
|
+
}
|
|
122
|
+
function same(a, b) {
|
|
123
|
+
return a.toLowerCase() === b.toLowerCase();
|
|
124
|
+
}
|
|
125
|
+
function paid(logs, recipient, amount, from) {
|
|
126
|
+
return peerRecipientTransfer(logs, config.settlement.asset_id, recipient, amount, from);
|
|
127
|
+
}
|
|
128
|
+
return {
|
|
129
|
+
async quote(intent, offer, signal) {
|
|
130
|
+
if (!same(intent.recipient, account.address)) throw new Error("invalid_request");
|
|
131
|
+
const request = {
|
|
132
|
+
fiatCurrency: intent.fiat.currency,
|
|
133
|
+
user: account.address,
|
|
134
|
+
recipient: intent.recipient,
|
|
135
|
+
destinationChainId: 8453,
|
|
136
|
+
destinationToken: config.settlement.asset_id,
|
|
137
|
+
escrowAddresses: [config.escrow],
|
|
138
|
+
amount: intent.exact.side === "fiat" ? formatUnits(BigInt(intent.exact.money.atomic), intent.fiat.decimals) : intent.exact.money.atomic,
|
|
139
|
+
isExactFiat: intent.exact.side === "fiat",
|
|
140
|
+
mode: "eligible",
|
|
141
|
+
quotePreference: "EXCLUSIVE_BUYER_TEE",
|
|
142
|
+
paymentPlatforms: [offer.rail.id],
|
|
143
|
+
quotesToReturn: 1,
|
|
144
|
+
includeNearbyQuotes: false
|
|
145
|
+
};
|
|
146
|
+
const raw = await boundedPeerRead(async (readSignal) => {
|
|
147
|
+
if (options.reads) return options.reads.quote(request, readSignal);
|
|
148
|
+
const { amount, isExactFiat, quotesToReturn, ...body } = request;
|
|
149
|
+
const response = await fetch(
|
|
150
|
+
`${urls[environment]}/v3/quote/${isExactFiat ? "exact-fiat" : "exact-token"}?quotesToReturn=${quotesToReturn}`,
|
|
151
|
+
{
|
|
152
|
+
method: "POST",
|
|
153
|
+
headers: { "Content-Type": "application/json" },
|
|
154
|
+
signal: readSignal,
|
|
155
|
+
body: JSON.stringify({
|
|
156
|
+
...body,
|
|
157
|
+
[isExactFiat ? "exactFiatAmount" : "exactTokenAmount"]: amount
|
|
158
|
+
})
|
|
159
|
+
}
|
|
160
|
+
);
|
|
161
|
+
if (!response.ok) throw new Error("capabilities_unavailable");
|
|
162
|
+
return response.json();
|
|
163
|
+
}, signal);
|
|
164
|
+
const normalized = normalizePeerQuotes(
|
|
165
|
+
raw,
|
|
166
|
+
intent,
|
|
167
|
+
config,
|
|
168
|
+
(options.now ?? Date.now)(),
|
|
169
|
+
offer.rail.id
|
|
170
|
+
)[0];
|
|
171
|
+
if (!normalized || normalized.offer.availability.state !== "available" || normalized.offer.capability_revision !== offer.capability_revision)
|
|
172
|
+
throw new Error("quote_changed");
|
|
173
|
+
const rows = z.object({ responseObject: z.object({ quotes: z.array(executionQuote).length(1) }) }).parse(raw).responseObject.quotes;
|
|
174
|
+
const q = rows[0];
|
|
175
|
+
if (!same(q.intent.escrowAddress, config.escrow) || !same(q.intent.toAddress, intent.recipient) || q.intent.processorName !== offer.rail.id)
|
|
176
|
+
throw new Error("quote_changed");
|
|
177
|
+
const preview = {
|
|
178
|
+
contract_version: "ramp/1",
|
|
179
|
+
kind: "preview",
|
|
180
|
+
operation_id: crypto.randomUUID(),
|
|
181
|
+
quote_id: crypto.randomUUID(),
|
|
182
|
+
offer_id: offer.offer_id,
|
|
183
|
+
capability_revision: offer.capability_revision,
|
|
184
|
+
request_digest: digest(intent),
|
|
185
|
+
pay: normalized.pay,
|
|
186
|
+
receive: normalized.receive,
|
|
187
|
+
fees: normalized.fees,
|
|
188
|
+
expires_at: normalized.offer.availability.valid_until,
|
|
189
|
+
leg_order: ["peer"],
|
|
190
|
+
disclosures: normalized.offer.disclosures
|
|
191
|
+
};
|
|
192
|
+
return {
|
|
193
|
+
preview,
|
|
194
|
+
paymentRecipient: "",
|
|
195
|
+
async signal() {
|
|
196
|
+
if (Date.parse(preview.expires_at) <= (options.now ?? Date.now)())
|
|
197
|
+
throw new Error("quote_expired");
|
|
198
|
+
const signed = await apiSignIntentV3Raw(
|
|
199
|
+
{
|
|
200
|
+
processorName: offer.rail.id,
|
|
201
|
+
payeeDetails: q.intent.payeeDetails,
|
|
202
|
+
depositId: String(q.intent.depositId),
|
|
203
|
+
amount: q.signalIntentAmount,
|
|
204
|
+
toAddress: intent.recipient,
|
|
205
|
+
paymentMethod: config.rails[offer.rail.id].paymentMethodHash,
|
|
206
|
+
fiatCurrency: resolveFiatCurrencyBytes32(intent.fiat.currency),
|
|
207
|
+
conversionRate: q.conversionRate,
|
|
208
|
+
chainId: "8453",
|
|
209
|
+
orchestratorAddress: config.orchestrator,
|
|
210
|
+
escrowAddress: config.escrow,
|
|
211
|
+
callerAddress: account.address,
|
|
212
|
+
referralFees: []
|
|
213
|
+
},
|
|
214
|
+
{ baseApiUrl: urls[environment], timeoutMs: 1e4 }
|
|
215
|
+
).catch((error) => {
|
|
216
|
+
if (peerRequiresLinkedSession(error)) throw new PeerSigningSetupRequired();
|
|
217
|
+
throw new Error("provider_declined");
|
|
218
|
+
});
|
|
219
|
+
if (signed.gating !== "curator-signed") throw new Error("provider_declined");
|
|
220
|
+
const response = signed.response;
|
|
221
|
+
const expiry = response.intentData?.signatureExpiration ?? response.signatureExpiration;
|
|
222
|
+
if (!response.offchainId || response.offchainId.length > 512 || !expiry || !/^[1-9][0-9]*$/.test(expiry) || !response.intentData?.payerCommitment || (response.referralFees?.length ?? response.intentData?.referralFees?.length ?? 0) !== 0)
|
|
223
|
+
throw new Error("quote_changed");
|
|
224
|
+
const tx = await sdk.signalIntent.prepare({
|
|
225
|
+
gatingServiceSignature: response.signedIntent,
|
|
226
|
+
signatureExpiration: expiry,
|
|
227
|
+
payerCommitment: response.intentData.payerCommitment,
|
|
228
|
+
depositId: BigInt(q.intent.depositId),
|
|
229
|
+
amount: q.signalIntentAmount,
|
|
230
|
+
toAddress: intent.recipient,
|
|
231
|
+
processorName: offer.rail.id,
|
|
232
|
+
payeeDetails: q.intent.payeeDetails,
|
|
233
|
+
fiatCurrencyCode: intent.fiat.currency,
|
|
234
|
+
conversionRate: q.conversionRate,
|
|
235
|
+
escrowAddress: config.escrow,
|
|
236
|
+
orchestratorAddress: config.orchestrator
|
|
237
|
+
});
|
|
238
|
+
if (Date.parse(preview.expires_at) <= (options.now ?? Date.now)())
|
|
239
|
+
throw new Error("quote_expired");
|
|
240
|
+
const after = (options.now ?? Date.now)();
|
|
241
|
+
const terms = termsDigest({
|
|
242
|
+
owner: account.address,
|
|
243
|
+
to: intent.recipient,
|
|
244
|
+
escrow: config.escrow,
|
|
245
|
+
depositId: BigInt(q.intent.depositId),
|
|
246
|
+
amount: BigInt(q.signalIntentAmount),
|
|
247
|
+
conversionRate: BigInt(q.conversionRate),
|
|
248
|
+
paymentMethod: config.rails[offer.rail.id].paymentMethodHash,
|
|
249
|
+
fiatCurrency: resolveFiatCurrencyBytes32(intent.fiat.currency)
|
|
250
|
+
});
|
|
251
|
+
storage().setItem(
|
|
252
|
+
resumeKey(preview.operation_id),
|
|
253
|
+
JSON.stringify({
|
|
254
|
+
terms,
|
|
255
|
+
payee: digest([terms, q.intent.payeeDetails.toLowerCase()]),
|
|
256
|
+
payAtomic: preview.pay.atomic,
|
|
257
|
+
receiveAtomic: preview.receive.atomic,
|
|
258
|
+
after,
|
|
259
|
+
before: Math.min(after + submissionWindowMs, Date.parse(preview.expires_at))
|
|
260
|
+
})
|
|
261
|
+
);
|
|
262
|
+
const receipt = await confirmed(await send(tx));
|
|
263
|
+
const events = parseEventLogs({
|
|
264
|
+
abi: buyerEvents,
|
|
265
|
+
eventName: "IntentSignaled",
|
|
266
|
+
logs: receipt.logs
|
|
267
|
+
});
|
|
268
|
+
const event = events.find(
|
|
269
|
+
(log) => same(log.address, config.orchestrator) && same(log.args.owner, account.address) && same(log.args.to, intent.recipient) && same(log.args.escrow, config.escrow) && log.args.depositId === BigInt(q.intent.depositId) && log.args.amount === BigInt(q.signalIntentAmount) && log.args.conversionRate === BigInt(q.conversionRate) && same(log.args.paymentMethod, config.rails[offer.rail.id].paymentMethodHash) && same(log.args.fiatCurrency, resolveFiatCurrencyBytes32(intent.fiat.currency))
|
|
270
|
+
);
|
|
271
|
+
if (!event) throw new Error("peer_in_doubt");
|
|
272
|
+
const intentExpiry = await options.publicClient.readContract({
|
|
273
|
+
address: config.escrow,
|
|
274
|
+
abi: escrowAbi,
|
|
275
|
+
functionName: "intentExpirationPeriod",
|
|
276
|
+
blockNumber: receipt.blockNumber
|
|
277
|
+
});
|
|
278
|
+
bindings.set(event.args.intentHash, {
|
|
279
|
+
intent,
|
|
280
|
+
depositId: BigInt(q.intent.depositId),
|
|
281
|
+
amount: BigInt(q.signalIntentAmount),
|
|
282
|
+
expectedNetAmount: BigInt(preview.receive.atomic),
|
|
283
|
+
conversionRate: BigInt(q.conversionRate),
|
|
284
|
+
paymentMethod: event.args.paymentMethod,
|
|
285
|
+
payeeDetails: q.intent.payeeDetails,
|
|
286
|
+
signalBlock: receipt.blockNumber
|
|
287
|
+
});
|
|
288
|
+
return {
|
|
289
|
+
intentHash: event.args.intentHash,
|
|
290
|
+
expiresAt: Number(event.args.timestamp + BigInt(intentExpiry)) * 1e3,
|
|
291
|
+
paymentRecipient: response.offchainId,
|
|
292
|
+
signaledAt: Number(event.args.timestamp) * 1e3
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
};
|
|
296
|
+
},
|
|
297
|
+
async resume(lookup) {
|
|
298
|
+
if (!same(lookup.wallet, account.address)) return void 0;
|
|
299
|
+
if (!lookup.operationId) return void 0;
|
|
300
|
+
let checkpoint;
|
|
301
|
+
try {
|
|
302
|
+
checkpoint = resumeCheckpoint.parse(
|
|
303
|
+
JSON.parse(storage().getItem(resumeKey(lookup.operationId)) ?? "null")
|
|
304
|
+
);
|
|
305
|
+
} catch {
|
|
306
|
+
return void 0;
|
|
307
|
+
}
|
|
308
|
+
if (checkpoint.payAtomic !== lookup.payAtomic || checkpoint.receiveAtomic !== lookup.receiveAtomic || !Number.isSafeInteger(lookup.approvedAfter) || checkpoint.after < lookup.approvedAfter || checkpoint.before < checkpoint.after || checkpoint.before - checkpoint.after > submissionWindowMs)
|
|
309
|
+
return void 0;
|
|
310
|
+
const rail = config.rails[lookup.rail];
|
|
311
|
+
if (!rail) return void 0;
|
|
312
|
+
const currency = resolveFiatCurrencyBytes32(lookup.currency);
|
|
313
|
+
const rows = (await (options.resumeReads?.ownerIntents() ?? sdk.indexer.getOwnerIntents(account.address))).filter(
|
|
314
|
+
(row2) => same(row2.owner, account.address) && same(row2.toAddress, lookup.wallet) && same(row2.orchestratorAddress, config.orchestrator) && !!row2.paymentMethodHash && same(row2.paymentMethodHash, rail.paymentMethodHash) && same(row2.fiatCurrency, currency) && uint.safeParse(row2.signalTimestamp).success && Number(row2.signalTimestamp) >= Math.floor(checkpoint.after / 1e3) && Number(row2.signalTimestamp) <= Math.floor(checkpoint.before / 1e3) && uint.safeParse(row2.amount).success && uint.safeParse(row2.conversionRate).success && uint.safeParse(row2.depositId).success && termsDigest({
|
|
315
|
+
owner: row2.owner,
|
|
316
|
+
to: row2.toAddress,
|
|
317
|
+
escrow: config.escrow,
|
|
318
|
+
depositId: BigInt(row2.depositId),
|
|
319
|
+
amount: BigInt(row2.amount),
|
|
320
|
+
conversionRate: BigInt(row2.conversionRate),
|
|
321
|
+
paymentMethod: row2.paymentMethodHash,
|
|
322
|
+
fiatCurrency: row2.fiatCurrency
|
|
323
|
+
}) === checkpoint.terms
|
|
324
|
+
);
|
|
325
|
+
if (rows.length !== 1) return void 0;
|
|
326
|
+
const row = rows[0];
|
|
327
|
+
const hash = row.intentHash;
|
|
328
|
+
if (!hex32.safeParse(hash).success || !hex32.safeParse(row.signalTxHash).success)
|
|
329
|
+
return void 0;
|
|
330
|
+
const receipt = await confirmed(row.signalTxHash);
|
|
331
|
+
if (!same(receipt.from, account.address) || !receipt.to || !same(receipt.to, config.orchestrator))
|
|
332
|
+
return void 0;
|
|
333
|
+
const event = parseEventLogs({
|
|
334
|
+
abi: buyerEvents,
|
|
335
|
+
eventName: "IntentSignaled",
|
|
336
|
+
logs: receipt.logs
|
|
337
|
+
}).find((log) => same(log.address, config.orchestrator) && same(log.args.intentHash, hash));
|
|
338
|
+
if (!event || termsDigest(event.args) !== checkpoint.terms || event.args.timestamp.toString() !== row.signalTimestamp)
|
|
339
|
+
return void 0;
|
|
340
|
+
if (row.status === "PRUNED") return { kind: "expired" };
|
|
341
|
+
if (row.status === "FULFILLED") {
|
|
342
|
+
if (!row.fulfillTxHash || !/^0x[0-9a-fA-F]{64}$/.test(row.fulfillTxHash)) return void 0;
|
|
343
|
+
bindings.set(hash, {
|
|
344
|
+
intent: {
|
|
345
|
+
recipient: lookup.wallet,
|
|
346
|
+
fiat: { kind: "fiat", currency: lookup.currency, decimals: 6 }
|
|
347
|
+
},
|
|
348
|
+
depositId: BigInt(row.depositId),
|
|
349
|
+
amount: BigInt(row.amount),
|
|
350
|
+
expectedNetAmount: BigInt(lookup.receiveAtomic),
|
|
351
|
+
conversionRate: BigInt(row.conversionRate),
|
|
352
|
+
paymentMethod: rail.paymentMethodHash,
|
|
353
|
+
payeeDetails: "",
|
|
354
|
+
signalBlock: receipt.blockNumber,
|
|
355
|
+
fulfillHash: row.fulfillTxHash
|
|
356
|
+
});
|
|
357
|
+
return { kind: "fulfilled", intentHash: hash };
|
|
358
|
+
}
|
|
359
|
+
if (row.status !== "SIGNALED") return void 0;
|
|
360
|
+
const live = options.resumeReads ? await options.resumeReads.intent(hash) : (await sdk.getIntent(hash)).intent;
|
|
361
|
+
if (!live.payeeId || !hex32.safeParse(live.payeeId).success || termsDigest(live) !== checkpoint.terms || digest([checkpoint.terms, live.payeeId.toLowerCase()]) !== checkpoint.payee || live.timestamp !== event.args.timestamp)
|
|
362
|
+
return void 0;
|
|
363
|
+
const period = await options.publicClient.readContract({
|
|
364
|
+
address: config.escrow,
|
|
365
|
+
abi: escrowAbi,
|
|
366
|
+
functionName: "intentExpirationPeriod",
|
|
367
|
+
blockNumber: receipt.blockNumber
|
|
368
|
+
});
|
|
369
|
+
bindings.set(hash, {
|
|
370
|
+
intent: {
|
|
371
|
+
recipient: lookup.wallet,
|
|
372
|
+
fiat: { kind: "fiat", currency: lookup.currency, decimals: 6 }
|
|
373
|
+
},
|
|
374
|
+
depositId: live.depositId,
|
|
375
|
+
amount: live.amount,
|
|
376
|
+
expectedNetAmount: BigInt(lookup.receiveAtomic),
|
|
377
|
+
conversionRate: live.conversionRate,
|
|
378
|
+
paymentMethod: live.paymentMethod,
|
|
379
|
+
payeeDetails: live.payeeId,
|
|
380
|
+
signalBlock: receipt.blockNumber
|
|
381
|
+
});
|
|
382
|
+
const payee = options.resumeReads ? void 0 : await apiGetPayeeDetails(
|
|
383
|
+
{ hashedOnchainId: live.payeeId, processorName: lookup.rail },
|
|
384
|
+
urls[environment],
|
|
385
|
+
1e4
|
|
386
|
+
).catch(() => void 0);
|
|
387
|
+
const offchainId = options.resumeReads ? await options.resumeReads.payee(live.payeeId, lookup.rail) : payee?.responseObject?.offchainId;
|
|
388
|
+
const result = {
|
|
389
|
+
kind: "active",
|
|
390
|
+
intentHash: hash,
|
|
391
|
+
signaledAt: Number(live.timestamp) * 1e3,
|
|
392
|
+
expiresAt: Number(live.timestamp + BigInt(period)) * 1e3,
|
|
393
|
+
...typeof offchainId === "string" && offchainId.length > 0 && offchainId.length <= 512 ? { paymentRecipient: offchainId } : {}
|
|
394
|
+
};
|
|
395
|
+
return result;
|
|
396
|
+
},
|
|
397
|
+
async fulfill(hash, proof) {
|
|
398
|
+
const binding = bindings.get(hash);
|
|
399
|
+
if (!binding) throw new Error("invalid_request");
|
|
400
|
+
const live = (await sdk.getIntent(hash)).intent;
|
|
401
|
+
if (!same(live.owner, account.address) || !same(live.to, binding.intent.recipient) || !same(live.escrow, config.escrow) || live.depositId !== binding.depositId || live.amount !== binding.amount || live.conversionRate !== binding.conversionRate || !same(live.paymentMethod, binding.paymentMethod) || !same(live.fiatCurrency, resolveFiatCurrencyBytes32(binding.intent.fiat.currency)) || live.payeeId !== void 0 && !same(live.payeeId, binding.payeeDetails))
|
|
402
|
+
throw new Error("proof_failed");
|
|
403
|
+
const tx = await sdk.fulfillIntent.prepare({
|
|
404
|
+
intentHash: hash,
|
|
405
|
+
proof,
|
|
406
|
+
orchestratorAddress: config.orchestrator,
|
|
407
|
+
attestationServiceUrl: PEER_ATTESTATION_ORIGIN,
|
|
408
|
+
attestationServiceFallbackUrls: []
|
|
409
|
+
});
|
|
410
|
+
binding.fulfillHash = await send(tx);
|
|
411
|
+
await confirmed(binding.fulfillHash);
|
|
412
|
+
},
|
|
413
|
+
async status(hash) {
|
|
414
|
+
const binding = bindings.get(hash);
|
|
415
|
+
if (!binding) return "unknown";
|
|
416
|
+
if (!binding.fulfillHash) return "pending";
|
|
417
|
+
const receipt = await confirmed(binding.fulfillHash);
|
|
418
|
+
const fulfilled = parseEventLogs({
|
|
419
|
+
abi: buyerEvents,
|
|
420
|
+
eventName: "IntentFulfilled",
|
|
421
|
+
logs: receipt.logs
|
|
422
|
+
}).find((log) => same(log.address, config.orchestrator) && same(log.args.intentHash, hash));
|
|
423
|
+
if (!fulfilled || fulfilled.args.amount !== binding.expectedNetAmount) return "unknown";
|
|
424
|
+
const deferred = parseDeferredPayoutFromLogs(
|
|
425
|
+
receipt.logs,
|
|
426
|
+
hash,
|
|
427
|
+
config.orchestrator
|
|
428
|
+
);
|
|
429
|
+
if (!deferred)
|
|
430
|
+
return same(fulfilled.args.fundsTransferredTo, binding.intent.recipient) && paid(receipt.logs, binding.intent.recipient, fulfilled.args.amount) ? "paid" : "unknown";
|
|
431
|
+
if (!same(deferred.recipient, binding.intent.recipient)) return "unknown";
|
|
432
|
+
binding.held = { vault: deferred.vault, amount: deferred.amount, block: receipt.blockNumber };
|
|
433
|
+
const payout = await sdk.getPayoutStatus(hash);
|
|
434
|
+
if (payout.state === "HELD" || payout.state === "CLAIMABLE") return "held";
|
|
435
|
+
if (payout.state !== "RELEASED") return "held";
|
|
436
|
+
const policy = getContracts(8453, environment).addresses.disputeProtectionPolicyV2;
|
|
437
|
+
if (!policy) return "unknown";
|
|
438
|
+
const event = DISPUTE_PROTECTION_POLICY_V2_ABI.find(
|
|
439
|
+
(item) => item.type === "event" && item.name === "ProtectionReleased"
|
|
440
|
+
);
|
|
441
|
+
const logs = await options.publicClient.getLogs({
|
|
442
|
+
address: policy,
|
|
443
|
+
event,
|
|
444
|
+
args: { intentHash: hash },
|
|
445
|
+
fromBlock: receipt.blockNumber,
|
|
446
|
+
toBlock: "latest"
|
|
447
|
+
});
|
|
448
|
+
for (const log of logs) {
|
|
449
|
+
if (!log.transactionHash) continue;
|
|
450
|
+
const released = await confirmed(log.transactionHash);
|
|
451
|
+
if (paid(released.logs, binding.intent.recipient, deferred.amount, deferred.vault))
|
|
452
|
+
return "released";
|
|
453
|
+
}
|
|
454
|
+
return "unknown";
|
|
455
|
+
}
|
|
456
|
+
};
|
|
457
|
+
}
|
|
458
|
+
export {
|
|
459
|
+
createPeerBuyerDriver,
|
|
460
|
+
peerRecipientTransfer
|
|
461
|
+
};
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import { validateRampSettlement, parseRamp, sameRampAsset } from "@xochi/client";
|
|
2
|
+
import { getContracts, getPaymentMethodsCatalog, resolveFiatCurrencyBytes32 } from "@zkp2p/sdk";
|
|
3
|
+
import { PEER_ENVIRONMENT } from "../../config.js";
|
|
4
|
+
import { isPeerMobileWeb } from "./environment.js";
|
|
5
|
+
import { formatUnits } from "viem";
|
|
6
|
+
import { unavailable, normalizePeerQuotes, livePeerRails } from "./normalization.js";
|
|
7
|
+
import { normalizePeerMakerEvidence } from "./maker.js";
|
|
8
|
+
const URLS = {
|
|
9
|
+
production: "https://api.zkp2p.xyz",
|
|
10
|
+
preproduction: "https://api-preprod.zkp2p.xyz",
|
|
11
|
+
staging: "https://api-staging.zkp2p.xyz"
|
|
12
|
+
};
|
|
13
|
+
const TIMEOUT_MS = 1e4;
|
|
14
|
+
class ReadTimeout extends Error {
|
|
15
|
+
}
|
|
16
|
+
class PeerReadAborted extends Error {
|
|
17
|
+
constructor() {
|
|
18
|
+
super("peer_read_aborted");
|
|
19
|
+
this.name = "AbortError";
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function checkPeerAbort(signal) {
|
|
23
|
+
if (signal?.aborted) throw new PeerReadAborted();
|
|
24
|
+
}
|
|
25
|
+
async function boundedPeerRead(read, signal) {
|
|
26
|
+
checkPeerAbort(signal);
|
|
27
|
+
const controller = new AbortController();
|
|
28
|
+
let timer;
|
|
29
|
+
let abort;
|
|
30
|
+
try {
|
|
31
|
+
return await Promise.race([
|
|
32
|
+
Promise.resolve().then(() => {
|
|
33
|
+
checkPeerAbort(signal);
|
|
34
|
+
return read(controller.signal);
|
|
35
|
+
}),
|
|
36
|
+
new Promise((_, reject) => {
|
|
37
|
+
abort = () => {
|
|
38
|
+
controller.abort();
|
|
39
|
+
reject(new PeerReadAborted());
|
|
40
|
+
};
|
|
41
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
42
|
+
timer = setTimeout(() => {
|
|
43
|
+
controller.abort();
|
|
44
|
+
reject(new ReadTimeout());
|
|
45
|
+
}, TIMEOUT_MS);
|
|
46
|
+
})
|
|
47
|
+
]);
|
|
48
|
+
} finally {
|
|
49
|
+
clearTimeout(timer);
|
|
50
|
+
if (abort) signal?.removeEventListener("abort", abort);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function peerConfiguration(options = {}) {
|
|
54
|
+
const environment = options.environment ?? PEER_ENVIRONMENT;
|
|
55
|
+
const addresses = getContracts(8453, environment).addresses;
|
|
56
|
+
const settlement = validateRampSettlement({
|
|
57
|
+
kind: "crypto",
|
|
58
|
+
chain_id: "eip155:8453",
|
|
59
|
+
asset_id: addresses.usdc,
|
|
60
|
+
decimals: 6,
|
|
61
|
+
symbol: "USDC"
|
|
62
|
+
});
|
|
63
|
+
if (!settlement || !addresses.escrowV2 || !addresses.orchestratorV4 || !/^0x[0-9a-fA-F]{40}$/.test(addresses.orchestratorV4) || /^0x0{40}$/i.test(addresses.orchestratorV4))
|
|
64
|
+
throw new Error("capabilities_unavailable");
|
|
65
|
+
return {
|
|
66
|
+
settlement,
|
|
67
|
+
orchestrator: addresses.orchestratorV4,
|
|
68
|
+
escrow: addresses.escrowV2,
|
|
69
|
+
currencyHash: resolveFiatCurrencyBytes32("USD"),
|
|
70
|
+
rails: getPaymentMethodsCatalog(8453, environment)
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
function peerReads(options) {
|
|
74
|
+
const url = URLS[options.environment ?? PEER_ENVIRONMENT];
|
|
75
|
+
const quoteRead = async (request, best, signal) => {
|
|
76
|
+
const { amount, isExactFiat, quotesToReturn, ...body } = request;
|
|
77
|
+
const exactFiat = isExactFiat !== false;
|
|
78
|
+
const endpoint = best ? exactFiat ? "best-by-platform" : "best-by-platform-exact-token" : exactFiat ? "exact-fiat" : "exact-token";
|
|
79
|
+
const query = !best && quotesToReturn ? `?quotesToReturn=${quotesToReturn}` : "";
|
|
80
|
+
const response = await fetch(`${url}/v3/quote/${endpoint}${query}`, {
|
|
81
|
+
method: "POST",
|
|
82
|
+
headers: { "Content-Type": "application/json" },
|
|
83
|
+
signal,
|
|
84
|
+
body: JSON.stringify({
|
|
85
|
+
...body,
|
|
86
|
+
[exactFiat ? "exactFiatAmount" : "exactTokenAmount"]: String(amount)
|
|
87
|
+
})
|
|
88
|
+
});
|
|
89
|
+
if (!response.ok) throw new Error("capabilities_unavailable");
|
|
90
|
+
return response.json();
|
|
91
|
+
};
|
|
92
|
+
return options.reads ?? {
|
|
93
|
+
bestByPlatform: (request, signal) => quoteRead(request, true, signal),
|
|
94
|
+
quote: (request, signal) => quoteRead(request, false, signal)
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
function requestFor(intent, config, user) {
|
|
98
|
+
return {
|
|
99
|
+
fiatCurrency: intent.fiat.currency,
|
|
100
|
+
user: user ?? intent.recipient,
|
|
101
|
+
recipient: intent.recipient,
|
|
102
|
+
destinationChainId: 8453,
|
|
103
|
+
destinationToken: config.settlement.asset_id,
|
|
104
|
+
escrowAddresses: [config.escrow],
|
|
105
|
+
amount: intent.exact.side === "fiat" ? formatUnits(BigInt(intent.exact.money.atomic), 6) : intent.exact.money.atomic,
|
|
106
|
+
isExactFiat: intent.exact.side === "fiat",
|
|
107
|
+
mode: "eligible",
|
|
108
|
+
quotePreference: "EXCLUSIVE_BUYER_TEE"
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
async function readPeerQuotes(input, options = {}, rail) {
|
|
112
|
+
try {
|
|
113
|
+
checkPeerAbort(options.signal);
|
|
114
|
+
const parsed = parseRamp(input), config = peerConfiguration(options);
|
|
115
|
+
if (!parsed.ok || parsed.value.kind !== "intent" || parsed.value.route || parsed.value.fiat.currency !== "USD" || parsed.value.fiat.decimals !== 6 || !sameRampAsset(parsed.value.crypto, config.settlement) || BigInt(parsed.value.exact.money.atomic) === 0n || parsed.value.exact.money.atomic.length > 78 || options.user !== void 0 && !/^0x[0-9a-fA-F]{40}$/.test(options.user))
|
|
116
|
+
return { quotes: [], result: { ...unavailable(), code: "invalid_request" } };
|
|
117
|
+
if (parsed.value.direction === "onramp" && (options.mobileWeb === true || isPeerMobileWeb()))
|
|
118
|
+
return {
|
|
119
|
+
quotes: [],
|
|
120
|
+
result: {
|
|
121
|
+
offers: [],
|
|
122
|
+
estimates: [],
|
|
123
|
+
availability: {
|
|
124
|
+
state: "setup_required",
|
|
125
|
+
requirement_codes: ["peer_desktop_extension_or_app"]
|
|
126
|
+
},
|
|
127
|
+
code: "capability_unavailable"
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
const intent = parsed.value, reads = peerReads(options), request = requestFor(intent, config, options.user);
|
|
131
|
+
const raw = await boundedPeerRead(
|
|
132
|
+
(signal) => rail === void 0 || intent.direction === "offramp" ? reads.bestByPlatform(request, signal) : reads.quote(
|
|
133
|
+
{
|
|
134
|
+
...request,
|
|
135
|
+
paymentPlatforms: [rail],
|
|
136
|
+
quotesToReturn: 1,
|
|
137
|
+
includeNearbyQuotes: false
|
|
138
|
+
},
|
|
139
|
+
signal
|
|
140
|
+
),
|
|
141
|
+
options.signal
|
|
142
|
+
);
|
|
143
|
+
checkPeerAbort(options.signal);
|
|
144
|
+
const now = (options.now ?? Date.now)();
|
|
145
|
+
if (!Number.isSafeInteger(now)) return { quotes: [], result: unavailable() };
|
|
146
|
+
let quotes;
|
|
147
|
+
if (intent.direction === "onramp") {
|
|
148
|
+
quotes = normalizePeerQuotes(raw, intent, config, now, rail);
|
|
149
|
+
} else {
|
|
150
|
+
const rails = livePeerRails(raw, config, intent, now).filter(
|
|
151
|
+
(value) => rail === void 0 || value === rail
|
|
152
|
+
);
|
|
153
|
+
quotes = await Promise.all(
|
|
154
|
+
rails.map(async (value) => {
|
|
155
|
+
let evidence;
|
|
156
|
+
try {
|
|
157
|
+
evidence = reads.makerEvidence ? await boundedPeerRead(
|
|
158
|
+
(signal) => reads.makerEvidence(intent, value, options.user, signal),
|
|
159
|
+
options.signal
|
|
160
|
+
) : void 0;
|
|
161
|
+
} catch {
|
|
162
|
+
}
|
|
163
|
+
return normalizePeerMakerEvidence(
|
|
164
|
+
evidence,
|
|
165
|
+
intent,
|
|
166
|
+
config,
|
|
167
|
+
value,
|
|
168
|
+
(options.now ?? Date.now)(),
|
|
169
|
+
options.user
|
|
170
|
+
);
|
|
171
|
+
})
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
checkPeerAbort(options.signal);
|
|
175
|
+
const available = quotes.filter((q) => q.offer.availability.state === "available");
|
|
176
|
+
const availability = available.length ? {
|
|
177
|
+
state: "available",
|
|
178
|
+
valid_until: new Date(
|
|
179
|
+
Math.min(
|
|
180
|
+
...available.map(
|
|
181
|
+
(q) => q.offer.availability.state === "available" ? Date.parse(q.offer.availability.valid_until) : Infinity
|
|
182
|
+
)
|
|
183
|
+
)
|
|
184
|
+
).toISOString()
|
|
185
|
+
} : { state: "availability_unknown", reason_code: "capability_unavailable" };
|
|
186
|
+
return {
|
|
187
|
+
quotes,
|
|
188
|
+
result: {
|
|
189
|
+
offers: quotes.map((q) => q.offer),
|
|
190
|
+
estimates: available.flatMap(
|
|
191
|
+
(q) => q.offer.availability.state === "available" ? [
|
|
192
|
+
{
|
|
193
|
+
offerId: q.offer.offer_id,
|
|
194
|
+
pay: q.pay,
|
|
195
|
+
receive: q.receive,
|
|
196
|
+
fees: q.fees.map(({ code, money }) => ({ code, money })),
|
|
197
|
+
observedAt: q.offer.observed_at,
|
|
198
|
+
validUntil: q.offer.availability.valid_until
|
|
199
|
+
}
|
|
200
|
+
] : []
|
|
201
|
+
),
|
|
202
|
+
availability,
|
|
203
|
+
...quotes.length ? {} : { code: "capability_unavailable" }
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
} catch (error) {
|
|
207
|
+
checkPeerAbort(options.signal);
|
|
208
|
+
if (error instanceof PeerReadAborted) throw error;
|
|
209
|
+
return {
|
|
210
|
+
quotes: [],
|
|
211
|
+
result: {
|
|
212
|
+
offers: [],
|
|
213
|
+
estimates: [],
|
|
214
|
+
availability: { state: "temporarily_unavailable", reason_code: "capabilities_unavailable" },
|
|
215
|
+
code: error instanceof ReadTimeout ? "provider_timeout" : "capabilities_unavailable"
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
async function fetchPeerCapabilities(intent, options = {}) {
|
|
221
|
+
return (await readPeerQuotes(intent, options)).result;
|
|
222
|
+
}
|
|
223
|
+
export {
|
|
224
|
+
PeerReadAborted,
|
|
225
|
+
boundedPeerRead,
|
|
226
|
+
checkPeerAbort,
|
|
227
|
+
fetchPeerCapabilities,
|
|
228
|
+
peerConfiguration,
|
|
229
|
+
peerReads,
|
|
230
|
+
readPeerQuotes
|
|
231
|
+
};
|