### Install SDK from Dev Tag on npm Source: https://github.com/zkp2p/zkp2p-client-sdk/blob/main/PUBLISHING.md This snippet provides the command to install the offramp SDK specifically using the 'dev' tag from npm. This allows integrators to test the latest development version before it's released as stable. ```bash npm i @zkp2p/offramp-sdk@dev ``` -------------------------------- ### Install @zkp2p/offramp-sdk and viem Source: https://github.com/zkp2p/zkp2p-client-sdk/blob/main/README.md Installs the necessary packages for using the Offramp SDK, including the core SDK and the viem library for interacting with Ethereum-compatible blockchains. ```bash npm install @zkp2p/offramp-sdk viem ``` -------------------------------- ### Installing and Building ZKP2P Offramp SDK Dependencies Source: https://github.com/zkp2p/zkp2p-client-sdk/blob/main/CONTRIBUTING.md Steps to install dependencies and build the ZKP2P Offramp SDK. It emphasizes running commands from the `packages/offramp-sdk/` directory for deterministic installs and CI parity. Includes commands for installing, building, and testing the SDK. ```bash cd packages/offramp-sdk npm ci npm run build npm test ``` -------------------------------- ### Quick Start with OfframpClient Initialization and Operations Source: https://github.com/zkp2p/zkp2p-client-sdk/blob/main/README.md Demonstrates how to initialize the OfframpClient with a wallet client and chain configuration, and perform common operations such as querying deposits and intents, creating new deposits, and using the advanced indexer. It utilizes viem for wallet management and the Offramp SDK for blockchain interactions. ```typescript import { OfframpClient, Currency } from '@zkp2p/offramp-sdk'; import { createWalletClient, custom } from 'viem'; import { base } from 'viem/chains'; const walletClient = createWalletClient({ chain: base, transport: custom(window.ethereum), }); const client = new OfframpClient({ walletClient, chainId: base.id, apiKey: 'YOUR_API_KEY', }); // Query deposits (RPC - instant, real-time) const deposits = await client.getDeposits(); const deposit = await client.getDeposit(42n); // Query intents (RPC - instant, real-time) const intents = await client.getIntents(); // Create a deposit to provide liquidity await client.createDeposit({ token: '0xUSDC', amount: 10000000000n, intentAmountRange: { min: 100000n, max: 1000000000n }, processorNames: ['wise', 'revolut'], depositData: [{ email: 'maker@example.com' }, { tag: '@maker' }], conversionRates: [[{ currency: Currency.USD, conversionRate: '1.02' }]], }); // Advanced indexer queries (for historical/filtered data) const activeDeposits = await client.indexer.getDeposits({ status: 'ACTIVE' }); ``` -------------------------------- ### Build and Verify @zkp2p/offramp-sdk Package Source: https://github.com/zkp2p/zkp2p-client-sdk/blob/main/packages/offramp-sdk/PUBLISHING.md Installs dependencies, runs type checking, tests, and builds the package. Optionally, it allows for a dry run to inspect the tarball contents before publishing. ```bash cd packages/offramp-sdk npm install npm run typecheck npm run test npm run build ``` ```bash npm pack --dry-run ``` -------------------------------- ### Example Test Case for OfframpClient in TypeScript Source: https://github.com/zkp2p/zkp2p-client-sdk/blob/main/CONTRIBUTING.md An example of a unit test written in TypeScript for the `OfframpClient` class. It demonstrates how to instantiate the client, call a method like `getQuote`, and assert the expected results using Jest syntax. ```typescript describe('OfframpClient', () => { it('should fetch quotes successfully', async () => { const client = new OfframpClient({ /* config */ }); const quotes = await client.getQuote({ /* params */ }); expect(quotes).toBeDefined(); expect(quotes.success).toBe(true); }); }); ``` -------------------------------- ### Publish Stable Release of Offramp SDK to npm Source: https://github.com/zkp2p/zkp2p-client-sdk/blob/main/PUBLISHING.md This snippet demonstrates how to publish a stable release of the offramp SDK to npm. It assumes the version has been bumped and the package is ready for release. It includes the command for publishing with the `--no-provenance` flag, suitable for manual releases or private repositories. ```bash npm publish --access public --no-provenance ``` -------------------------------- ### Get Quote Source: https://context7.com/zkp2p/zkp2p-client-sdk/llms.txt Queries available liquidity and pricing across different payment platforms to find the best rates for currency conversion. ```APIDOC ## Get Quote ### Description Query available liquidity and pricing across payment platforms. ### Method This is a client SDK method for retrieving quotes. ### Endpoint N/A (This is an SDK method call, not a direct API endpoint) ### Parameters #### `getQuote` - **quoteRequest** (object) - Required - The request object for fetching quotes. - **paymentPlatforms** (array of strings) - Required - List of payment platforms to query (e.g., ['wise', 'revolut']). - **fiatCurrency** (string) - Required - The fiat currency code (e.g., 'USD'). Use `Currency` enum. - **user** (string) - Required - The user's address. - **recipient** (string) - Required - The recipient's address. - **destinationChainId** (number) - Required - The chain ID of the destination network (e.g., 8453 for Base). - **destinationToken** (string) - Required - The address of the destination token (e.g., USDC address). - **amount** (string) - Required - The amount to convert. - **isExactFiat** (boolean) - Required - Whether the amount is exact fiat. - **includeNearbyQuotes** (boolean) - Optional - Whether to include nearby quotes if an exact match is not found. - **nearbySearchRange** (number) - Optional - The search range for nearby quotes. - **nearbyQuotesCount** (number) - Optional - The number of nearby quotes to retrieve. ### Request Example ```typescript import { Currency, type QuoteRequest } from '@zkp2p/offramp-sdk'; const quoteRequest: QuoteRequest = { paymentPlatforms: ['wise', 'revolut', 'venmo'], fiatCurrency: Currency.USD, user: '0xUserAddress', recipient: '0xRecipientAddress', destinationChainId: 8453, // Base destinationToken: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913', // USDC amount: '100', isExactFiat: false, includeNearbyQuotes: true, nearbySearchRange: 10, nearbyQuotesCount: 3 }; const quote = await client.getQuote(quoteRequest); console.log(`Found ${quote.responseObject.quotes.length} quotes`); quote.responseObject.quotes.forEach((q, i) => { console.log(`Quote ${i + 1}:`, { platform: q.paymentMethod, fiatAmount: q.fiatAmountFormatted, tokenAmount: q.tokenAmountFormatted, rate: q.conversionRate, depositId: q.intent.depositId }); }); // Handle nearby suggestions when no exact match if (quote.responseObject.nearbySuggestions) { console.log('Nearby suggestions below:', quote.responseObject.nearbySuggestions.below); console.log('Nearby suggestions above:', quote.responseObject.nearbySuggestions.above); } ``` ### Response #### Success Response (200) - **responseObject** (object) - The main response object containing quotes and suggestions. - **quotes** (array) - An array of quote objects. - **paymentMethod** (string) - The payment method used for the quote. - **fiatAmountFormatted** (string) - The fiat amount formatted. - **tokenAmountFormatted** (string) - The token amount formatted. - **conversionRate** (string) - The conversion rate. - **intent** (object) - Details of the intent associated with the quote. - **depositId** (bigint) - The ID of the deposit. - **nearbySuggestions** (object) - Optional - Contains suggestions for nearby quotes. - **below** (array) - Quotes below the requested range. - **above** (array) - Quotes above the requested range. #### Response Example ```json { "responseObject": { "quotes": [ { "paymentMethod": "wise", "fiatAmountFormatted": "100.00 USD", "tokenAmountFormatted": "98.00 USDC", "conversionRate": "1.02", "intent": { "depositId": 1n } } ], "nearbySuggestions": { "below": [...], "above": [...] } } } ``` ``` -------------------------------- ### Get Payment Methods Catalog and Metadata (TypeScript) Source: https://github.com/zkp2p/zkp2p-client-sdk/blob/main/packages/offramp-sdk/README.md Retrieves a catalog of available payment methods and their associated metadata. This function requires a network chain ID and environment (e.g., 'production'). It returns a list of supported payment platforms and detailed information about specific platforms like Wise. ```typescript import { getPaymentMethodsCatalog, PLATFORM_METADATA, PAYMENT_PLATFORMS } from '@zkp2p/offramp-sdk'; // Available payment platforms console.log(PAYMENT_PLATFORMS); // ['wise', 'venmo', 'revolut', 'cashapp', 'mercadopago', 'zelle', 'paypal', 'monzo'] // Get payment method hashes const methods = getPaymentMethodsCatalog(8453, 'production'); const wiseHash = methods['wise'].paymentMethodHash; // Get platform metadata const wiseInfo = PLATFORM_METADATA['wise']; console.log(wiseInfo.displayName); // "Wise" ``` -------------------------------- ### Access Payment Methods Catalog and Metadata (TypeScript) Source: https://context7.com/zkp2p/zkp2p-client-sdk/llms.txt Retrieves the payment methods catalog, including metadata and hashes, for a specific chain ID and environment. It allows listing available platforms, getting payment method hashes and supported currencies, and accessing platform display metadata. Requires importing functions and constants from '@zkp2p/offramp-sdk'. ```typescript import { getPaymentMethodsCatalog, PLATFORM_METADATA, PAYMENT_PLATFORMS } from '@zkp2p/offramp-sdk'; // List all available platforms console.log('Available platforms:', PAYMENT_PLATFORMS); // ['wise', 'venmo', 'revolut', 'cashapp', 'mercadopago', 'zelle', 'paypal', 'monzo'] // Get payment method hashes for Base mainnet const methods = getPaymentMethodsCatalog(8453, 'production'); const wiseHash = methods['wise'].paymentMethodHash; const wiseSupported = methods['wise'].currencies; // Supported currency codes // Get platform display metadata const wiseInfo = PLATFORM_METADATA['wise']; console.log('Display name:', wiseInfo.displayName); // "Wise" ``` -------------------------------- ### Currency Utilities: Codes, Metadata, and Conversions (TypeScript) Source: https://context7.com/zkp2p/zkp2p-client-sdk/llms.txt Provides utilities for working with currency codes and metadata, including constants for currencies, functions to get currency information from hash, and methods to resolve fiat currency to bytes32 format for on-chain operations. Requires imports from '@zkp2p/offramp-sdk'. Useful for handling currency data in financial applications. ```typescript import { Currency, currencyInfo, getCurrencyInfoFromHash, resolveFiatCurrencyBytes32 } from '@zkp2p/offramp-sdk'; // Use currency constants const usdRate = { currency: Currency.USD, conversionRate: '1020000000000000000' }; const eurRate = { currency: Currency.EUR, conversionRate: '1100000000000000000' }; // Get currency metadata const usdInfo = currencyInfo[Currency.USD]; console.log('Symbol:', usdInfo.currencySymbol); // "$" console.log('Name:', usdInfo.currencyName); // "United States Dollar" console.log('Hash:', usdInfo.currencyCodeHash); // "0x..." // Convert to bytes32 for on-chain operations const usdBytes32 = resolveFiatCurrencyBytes32('USD'); const eurBytes32 = resolveFiatCurrencyBytes32('EUR'); // Reverse lookup from hash const currencyData = getCurrencyInfoFromHash('0x...'); console.log('Currency code:', currencyData.currencyCode); ``` -------------------------------- ### Development Commands for Offramp SDK Source: https://github.com/zkp2p/zkp2p-client-sdk/blob/main/README.md Provides the standard commands for setting up, building, testing, and linting the @zkp2p/offramp-sdk package within a development environment. These commands are executed from the package's directory. ```bash cd packages/offramp-sdk npm install npm run build npm run test npm run lint ``` -------------------------------- ### Querying Intents Source: https://github.com/zkp2p/zkp2p-client-sdk/blob/main/packages/offramp-sdk/README.md Methods for retrieving intent data. You can get all your intents, intents for a specific address, or a single intent by its hash. ```APIDOC ## Querying Intents ### Description Methods for retrieving intent data. You can get all your intents, intents for a specific address, or a single intent by its hash. ### Method Various (related to client object methods) ### Endpoints - `client.getIntents()` - `client.getAccountIntents(ownerAddress: string)` - `client.getIntent(intentHash: string)` ### Request Example ```typescript // Get all your intents const intents = await client.getIntents(); // Get intents for any address const ownerIntents = await client.getAccountIntents('0xOwnerAddress'); // Get a specific intent by hash const intent = await client.getIntent('0xIntentHash...'); ``` ### Response Returns intent objects based on the query. ``` -------------------------------- ### Initialize OfframpClient with viem Source: https://github.com/zkp2p/zkp2p-client-sdk/blob/main/packages/offramp-sdk/README.md Initializes the OfframpClient using viem for wallet integration and chain configuration. Requires a wallet client and chain ID, with an optional API key for specific operations. ```typescript import { OfframpClient } from '@zkp2p/offramp-sdk'; import { createWalletClient, custom } from 'viem'; import { base } from 'viem/chains'; const walletClient = createWalletClient({ chain: base, transport: custom(window.ethereum), }); const client = new OfframpClient({ walletClient, chainId: base.id, apiKey: 'YOUR_API_KEY', // Optional for API operations }); ``` -------------------------------- ### Getting Quotes Source: https://github.com/zkp2p/zkp2p-client-sdk/blob/main/packages/offramp-sdk/README.md Primarily used by frontend applications to display available liquidity. Retrieves a quote based on specified payment platforms, currency, user, recipient, and destination chain/token. ```APIDOC ## Getting Quotes ### Description Primarily used by frontend applications to display available liquidity. Retrieves a quote based on specified payment platforms, currency, user, recipient, and destination chain/token. ### Method `client.getQuote(params: object)` ### Parameters #### Request Body - `paymentPlatforms` (string[]) - Required - List of payment platforms to consider. - `fiatCurrency` (string) - Required - The fiat currency code. - `user` (string) - Required - The user's address. - `recipient` (string) - Required - The recipient's address. - `destinationChainId` (number) - Required - The destination chain ID. - `destinationToken` (string) - Required - The destination token address. - `amount` (string) - Required - The amount for the quote. ### Request Example ```typescript const quote = await client.getQuote({ paymentPlatforms: ['wise', 'revolut'], fiatCurrency: 'USD', user: '0xUserAddress', recipient: '0xRecipientAddress', destinationChainId: 8453, destinationToken: '0xUSDC', amount: '100', }); ``` ### Response Returns a quote object containing liquidity information. ``` -------------------------------- ### Cloning and Setting Up ZKP2P SDK Repository Source: https://github.com/zkp2p/zkp2p-client-sdk/blob/main/CONTRIBUTING.md Instructions for cloning the ZKP2P Offramp SDK repository and setting up remotes for local development. This involves forking the repository, cloning the fork, and adding the upstream remote for tracking changes. ```bash git clone https://github.com/YOUR_USERNAME/zkp2p-client-sdk.git cd zkp2p-client-sdk git remote add upstream https://github.com/zkp2p/zkp2p-client-sdk.git ``` -------------------------------- ### Get Taker Tier Information Source: https://github.com/zkp2p/zkp2p-client-sdk/blob/main/packages/offramp-sdk/README.md Retrieve the taker tier for a given owner and chain ID. This functionality requires either an `authorizationToken` or an `apiKey` to be set on the client. The response contains information about the user's tier level. ```typescript const tier = await client.getTakerTier({ owner: '0xUserAddress', chainId: 8453, }); console.log(tier.responseObject.tier); ``` -------------------------------- ### Initialize Client Source: https://context7.com/zkp2p/zkp2p-client-sdk/llms.txt Initializes the OfframpClient for connecting to the Base blockchain and ZKP2P SDK services. Requires wallet client, chain ID, runtime environment, API key, and base API URL. ```APIDOC ## Initialize Client ### Description Client initialization for connecting to the Base blockchain and SDK services. ### Method N/A (Constructor) ### Endpoint N/A ### Parameters #### Request Body - **walletClient** (object) - Required - Viem wallet client instance. - **chainId** (number) - Required - The chain ID of the blockchain (e.g., Base chain ID). - **runtimeEnv** (string) - Required - The runtime environment ('production' or 'development'). - **apiKey** (string) - Required - Your ZKP2P API key. - **baseApiUrl** (string) - Required - The base URL for the ZKP2P API. ### Request Example ```typescript import { OfframpClient } from '@zkp2p/offramp-sdk'; import { createWalletClient, http } from 'viem'; import { privateKeyToAccount } from 'viem/accounts'; import { base } from 'viem/chains'; const privateKey = process.env.PRIVATE_KEY as `0x${string}`; const account = privateKeyToAccount(privateKey); const walletClient = createWalletClient({ account, chain: base, transport: http('https://base-mainnet.g.alchemy.com/v2/YOUR_API_KEY'), }); const client = new OfframpClient({ walletClient, chainId: base.id, runtimeEnv: 'production', apiKey: 'YOUR_API_KEY', baseApiUrl: 'https://api.zkp2p.xyz', }); // Client is ready for operations console.log('Connected to chain:', client.chainId); ``` ### Response N/A (Returns an instance of OfframpClient) ``` -------------------------------- ### Get Contract Addresses and ABIs (TypeScript) Source: https://github.com/zkp2p/zkp2p-client-sdk/blob/main/packages/offramp-sdk/README.md Fetches contract addresses and their corresponding Application Binary Interfaces (ABIs) for a given network chain ID and environment. This is crucial for interacting with smart contracts on the blockchain, such as the escrow and orchestrator contracts. ```typescript import { getContracts, getPaymentMethodsCatalog } from '@zkp2p/offramp-sdk'; // Get contract addresses and ABIs const { addresses, abis } = getContracts(8453, 'production'); console.log(addresses.escrow); // Contract addresses use camelCase console.log(addresses.orchestrator); // Get payment methods catalog const catalog = getPaymentMethodsCatalog(8453, 'production'); ``` -------------------------------- ### Initialize Offramp Client Source: https://context7.com/zkp2p/zkp2p-client-sdk/llms.txt Initializes the OfframpClient for connecting to the Base blockchain and ZKP2P SDK services. Requires wallet client configuration, chain ID, runtime environment, API key, and base API URL. ```typescript import { OfframpClient } from '@zkp2p/offramp-sdk'; import { createWalletClient, http } from 'viem'; import { privateKeyToAccount } from 'viem/accounts'; import { base } from 'viem/chains'; const privateKey = process.env.PRIVATE_KEY as `0x${string}`; const account = privateKeyToAccount(privateKey); const walletClient = createWalletClient({ account, chain: base, transport: http('https://base-mainnet.g.alchemy.com/v2/YOUR_API_KEY'), }); const client = new OfframpClient({ walletClient, chainId: base.id, runtimeEnv: 'production', apiKey: 'YOUR_API_KEY', baseApiUrl: 'https://api.zkp2p.xyz', }); // Client is ready for operations console.log('Connected to chain:', client.chainId); ``` -------------------------------- ### Get Liquidity Quote Source: https://github.com/zkp2p/zkp2p-client-sdk/blob/main/packages/offramp-sdk/README.md Obtain a quote for available liquidity based on specified payment platforms, currency, user, recipient, destination chain, token, and amount. This is primarily used by frontend applications to display real-time liquidity information to users. ```typescript const quote = await client.getQuote({ paymentPlatforms: ['wise', 'revolut'], fiatCurrency: 'USD', user: '0xUserAddress', recipient: '0xRecipientAddress', destinationChainId: 8453, destinationToken: '0xUSDC', amount: '100', }); ``` -------------------------------- ### Contract Utilities for zkp2p Offramp SDK Source: https://context7.com/zkp2p/zkp2p-client-sdk/llms.txt Demonstrates how to access contract addresses and ABIs programmatically using the '@zkp2p/offramp-sdk'. It shows how to retrieve contract details for a specific chainId and environment (e.g., Base mainnet production) and how to fetch the payment methods catalog. This is useful for direct contract interaction or understanding deployed contract locations. ```typescript import { getContracts, getPaymentMethodsCatalog } from '@zkp2p/offramp-sdk'; // Get contract addresses and ABIs for Base mainnet const { addresses, abis } = getContracts(8453, 'production'); console.log('Escrow:', addresses.escrow); console.log('Orchestrator:', addresses.orchestrator); console.log('ProtocolViewer:', addresses.protocolViewer); console.log('UnifiedPaymentVerifier:', addresses.unifiedPaymentVerifier); // Access ABIs for direct contract interaction const escrowAbi = abis.escrow; const orchestratorAbi = abis.orchestrator; // Get payment methods catalog const catalog = getPaymentMethodsCatalog(8453, 'production'); Object.entries(catalog).forEach(([platform, data]) => { console.log(`${platform}: ${data.paymentMethodHash}`); console.log(` Supported currencies:`, data.currencies); }); ``` -------------------------------- ### Create New Deposit Source: https://context7.com/zkp2p/zkp2p-client-sdk/llms.txt Creates a new liquidity deposit on the Base blockchain. Configures token, amount, intent range, accepted payment processors, deposit details, and conversion rates. Includes success, error, and mined event handlers. ```typescript import { Currency } from '@zkp2p/offramp-sdk'; const result = await client.createDeposit({ token: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913', // USDC on Base amount: 10000_000000n, // 10,000 USDC (6 decimals) intentAmountRange: { min: 100_000000n, // 100 USDC minimum max: 1000_000000n // 1,000 USDC maximum }, processorNames: ['wise', 'revolut'], depositData: [ { email: 'maker@example.com' }, // Wise payment details { tag: '@maker' } // Revolut payment details ], conversionRates: [ [ { currency: Currency.USD, conversionRate: '1020000000000000000' }, // 1.02 (18 decimals) { currency: Currency.EUR, conversionRate: '950000000000000000' } // 0.95 (18 decimals) ], [ { currency: Currency.USD, conversionRate: '1010000000000000000' }, // 1.01 for Revolut { currency: Currency.GBP, conversionRate: '800000000000000000' } // 0.80 (18 decimals) ] ], onSuccess: ({ hash }) => console.log('Deposit created:', hash), onError: (error) => console.error('Creation failed:', error), onMined: ({ hash }) => console.log('Transaction mined:', hash), }); console.log('Transaction hash:', result.hash); console.log('Deposit details:', result.depositDetails); ``` -------------------------------- ### Get Quote - TypeScript Source: https://context7.com/zkp2p/zkp2p-client-sdk/llms.txt Queries available liquidity and pricing across different payment platforms. It allows specifying payment platforms, currency, user/recipient addresses, destination chain and token, and amount. The function can also include nearby quotes if an exact match is not found. ```typescript import { Currency, type QuoteRequest } from '@zkp2p/offramp-sdk'; const quoteRequest: QuoteRequest = { paymentPlatforms: ['wise', 'revolut', 'venmo'], fiatCurrency: Currency.USD, user: '0xUserAddress', recipient: '0xRecipientAddress', destinationChainId: 8453, // Base destinationToken: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913', // USDC amount: '100', isExactFiat: false, includeNearbyQuotes: true, nearbySearchRange: 10, nearbyQuotesCount: 3 }; const quote = await client.getQuote(quoteRequest); console.log(`Found ${quote.responseObject.quotes.length} quotes`); quote.responseObject.quotes.forEach((q, i) => { console.log(`Quote ${i + 1}:`, { platform: q.paymentMethod, fiatAmount: q.fiatAmountFormatted, tokenAmount: q.tokenAmountFormatted, rate: q.conversionRate, depositId: q.intent.depositId }); }); // Handle nearby suggestions when no exact match if (quote.responseObject.nearbySuggestions) { console.log('Nearby suggestions below:', quote.responseObject.nearbySuggestions.below); console.log('Nearby suggestions above:', quote.responseObject.nearbySuggestions.above); } ``` -------------------------------- ### Publish Stable (latest) to npm Source: https://github.com/zkp2p/zkp2p-client-sdk/blob/main/packages/offramp-sdk/PUBLISHING.md Publishes a stable version of the @zkp2p/offramp-sdk to npm with the 'latest' dist-tag. This can be done by publishing a new version or promoting an existing version. Requires npm access and Node 18+. ```bash cd packages/offramp-sdk npm publish --access public --no-provenance --otp ``` ```bash # Or promote an existing version: npm dist-tag add @zkp2p/offramp-sdk@ latest --otp ``` -------------------------------- ### Add JSDoc Comments for Fiat-to-Crypto Quotes API (TypeScript) Source: https://github.com/zkp2p/zkp2p-client-sdk/blob/main/CONTRIBUTING.md This snippet demonstrates adding JSDoc comments to the `getQuote` API function in TypeScript. It includes parameter descriptions, return types, and a usage example for fetching crypto quotes based on payment platforms and fiat currency. ```typescript /** * Fetches quotes for fiat-to-crypto exchange * @param params - Quote request parameters * @param params.paymentPlatforms - Array of payment platforms * @param params.fiatCurrency - Fiat currency code * @returns Promise resolving to quote response * @example * const quotes = await client.getQuote({ * paymentPlatforms: ['wise'], * fiatCurrency: 'USD', * amount: '100' * }); */ ``` -------------------------------- ### Utilize TypeScript Types with zkp2p-offramp-sdk Source: https://github.com/zkp2p/zkp2p-client-sdk/blob/main/packages/offramp-sdk/README.md Highlights the full TypeScript support provided by the zkp2p-offramp-sdk. It demonstrates importing various types for parameters, deposit/intent data, and currency/payment platform information. ```typescript import type { CreateDepositParams, SignalIntentParams, FulfillIntentParams, IndexerDeposit, IndexerIntent, CurrencyType, PaymentPlatformType, } from '@zkp2p/offramp-sdk'; ``` -------------------------------- ### Running ZKP2P SDK Tests Source: https://github.com/zkp2p/zkp2p-client-sdk/blob/main/CONTRIBUTING.md Commands for executing tests within the ZKP2P Offramp SDK. Provides options to run all tests, run tests in watch mode for continuous feedback, and generate test coverage reports. ```bash npm test npm run test:watch npm run test:coverage ``` -------------------------------- ### Create Deposit Source: https://context7.com/zkp2p/zkp2p-client-sdk/llms.txt Creates a new liquidity deposit on the Base blockchain. Allows configuration of accepted tokens, amounts, payment methods, conversion rates, and user-defined data. ```APIDOC ## Create Deposit ### Description Create a new liquidity deposit with payment methods and conversion rates. ### Method POST (Internal) ### Endpoint N/A (Method on OfframpClient instance) ### Parameters #### Request Body - **token** (string) - Required - The address of the token to deposit (e.g., USDC on Base). - **amount** (bigint) - Required - The total amount of the token to deposit (e.g., 10,000 USDC). - **intentAmountRange** (object) - Required - The minimum and maximum amount for intents. - **min** (bigint) - Required - Minimum intent amount. - **max** (bigint) - Required - Maximum intent amount. - **processorNames** (string[]) - Required - An array of payment processor names (e.g., ['wise', 'revolut']). - **depositData** (object[]) - Required - An array of payment details corresponding to `processorNames`. - Example: `[{ email: 'maker@example.com' }]` for Wise, `[{ tag: '@maker' }]` for Revolut. - **conversionRates** (Array>) - Required - Nested array of conversion rates for each processor. - Each inner array corresponds to a processor and contains objects with `currency` (Currency enum) and `conversionRate` (string, 18 decimals). - **onSuccess** (function) - Optional - Callback function executed on successful deposit creation. - **onError** (function) - Optional - Callback function executed on error during creation. - **onMined** (function) - Optional - Callback function executed when the transaction is mined. ### Request Example ```typescript import { Currency } from '@zkp2p/offramp-sdk'; const result = await client.createDeposit({ token: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913', // USDC on Base amount: 10000_000000n, // 10,000 USDC (6 decimals) intentAmountRange: { min: 100_000000n, // 100 USDC minimum max: 1000_000000n // 1,000 USDC maximum }, processorNames: ['wise', 'revolut'], depositData: [ { email: 'maker@example.com' }, // Wise payment details { tag: '@maker' } // Revolut payment details ], conversionRates: [ [ { currency: Currency.USD, conversionRate: '1020000000000000000' }, // 1.02 (18 decimals) { currency: Currency.EUR, conversionRate: '950000000000000000' } // 0.95 (18 decimals) ], [ { currency: Currency.USD, conversionRate: '1010000000000000000' }, // 1.01 for Revolut { currency: Currency.GBP, conversionRate: '800000000000000000' } // 0.80 (18 decimals) ] ], onSuccess: ({ hash }) => console.log('Deposit created:', hash), onError: (error) => console.error('Creation failed:', error), onMined: ({ hash }) => console.log('Transaction mined:', hash), }); console.log('Transaction hash:', result.hash); console.log('Deposit details:', result.depositDetails); ``` ### Response #### Success Response (200) - **hash** (string) - The transaction hash of the deposit creation. - **depositDetails** (object) - Details of the created deposit. - **depositId** (bigint) - The unique identifier for the deposit. - **owner** (string) - The address of the deposit owner. - **token** (string) - The address of the deposited token. - **amount** (bigint) - The total amount deposited. - ... (other deposit-related fields) #### Response Example ```json { "hash": "0xabc123...", "depositDetails": { "depositId": 1n, "owner": "0xOwnerAddress", "token": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", "amount": 10000000000n, "availableLiquidity": 10000000000n, "acceptingIntents": true, "intentAmountMin": 100000000n, "intentAmountMax": 1000000000n, "paymentMethods": [ { "processor": "wise", "data": {"email": "maker@example.com"} }, { "processor": "revolut", "data": {"tag": "@maker"} } ], "conversionRates": [ [ {"currency": "USD", "conversionRate": "1020000000000000000"}, {"currency": "EUR", "conversionRate": "950000000000000000"} ], [ {"currency": "USD", "conversionRate": "1010000000000000000"}, {"currency": "GBP", "conversionRate": "800000000000000000"} ] ] } } ``` ``` -------------------------------- ### Low-Level Method Parameters Source: https://github.com/zkp2p/zkp2p-client-sdk/blob/main/packages/offramp-sdk/README.md Utilize low-level methods for direct interaction with on-chain data. Parameters for these methods require bytes32 hex strings for identifiers like payment methods and currency codes. ```APIDOC ## Low-Level Method Parameters ### Description Provides methods for direct on-chain data manipulation, requiring parameters in bytes32 hex string format. ### Methods #### `addCurrencies` ##### Description Adds currencies to a specified payment method. ##### Parameters - **depositId** (bigint) - Required - The ID of the deposit. - **paymentMethod** (string) - Required - The bytes32 hex string representing the payment method. - **currencies** (Array) - Required - An array of currency objects to add. - **code** (string) - Required - The bytes32 hex string representing the currency code. - **minConversionRate** (bigint) - Required - The minimum conversion rate for the currency (18 decimals). ```typescript await client.addCurrencies({ depositId: 1n, paymentMethod: '0x...', // bytes32 payment method hash currencies: [ { code: '0x...', minConversionRate: 1020000000000000000n }, ], }); ``` #### `deactivateCurrency` ##### Description Removes a currency from a specified payment method. ##### Parameters - **depositId** (bigint) - Required - The ID of the deposit. - **paymentMethod** (string) - Required - The bytes32 hex string representing the payment method. - **currencyCode** (string) - Required - The bytes32 hex string representing the currency code. ```typescript await client.deactivateCurrency({ depositId: 1n, paymentMethod: '0x...', // bytes32 payment method hash currencyCode: '0x...', // bytes32 currency code }); ``` #### `setPaymentMethodActive` ##### Description Enables or disables a specified payment method. ##### Parameters - **depositId** (bigint) - Required - The ID of the deposit. - **paymentMethod** (string) - Required - The bytes32 hex string representing the payment method. - **isActive** (boolean) - Required - Boolean indicating if the payment method should be active. ```typescript await client.setPaymentMethodActive({ depositId: 1n, paymentMethod: '0x...', // bytes32 payment method hash (not paymentMethodHash) isActive: true, }); ``` #### `setCurrencyMinRate` ##### Description Updates the minimum conversion rate for a currency within a payment method. ##### Parameters - **depositId** (bigint) - Required - The ID of the deposit. - **paymentMethod** (string) - Required - The bytes32 hex string representing the payment method. - **fiatCurrency** (string) - Required - The bytes32 hex string representing the fiat currency code. - **minConversionRate** (bigint) - Required - The new minimum conversion rate (18 decimals). ```typescript await client.setCurrencyMinRate({ depositId: 1n, paymentMethod: '0x...', // bytes32 payment method hash fiatCurrency: '0x...', // bytes32 currency code (not currencyCode) minConversionRate: 1020000000000000000n, // 18 decimals }); ``` ``` -------------------------------- ### Get Taker Tier Limits and Cooldown Status (TypeScript) Source: https://context7.com/zkp2p/zkp2p-client-sdk/llms.txt Queries the taker tier limits and cooldown status for a given owner and chain ID. It returns information about the current tier, per-intent caps, cooldown status, and platform-specific limits. Dependencies include the client object. Inputs are owner address and chain ID. Outputs are tier information, caps, and cooldown status. ```typescript const tierInfo = await client.getTakerTier({ owner: '0xUserAddress', chainId: 8453 }); console.log('Taker tier:', tierInfo.responseObject.tier); console.log('Per-intent cap:', tierInfo.responseObject.perIntentCapDisplay); console.log('Cooldown active:', tierInfo.responseObject.cooldownActive); console.log('Cooldown remaining:', tierInfo.responseObject.cooldownRemainingSeconds, 'seconds'); // Platform-specific limits tierInfo.responseObject.platformLimits?.forEach(limit => { console.log(`${limit.platformName}:`, { effectiveCap: limit.effectiveCapDisplay, riskLevel: limit.riskLevel, isLocked: limit.isLocked, hasCooldown: limit.hasCooldown }); }); ``` -------------------------------- ### Running ZKP2P SDK Linting and Type Checking Source: https://github.com/zkp2p/zkp2p-client-sdk/blob/main/CONTRIBUTING.md Commands to ensure code quality and correctness in the ZKP2P Offramp SDK. Includes commands for linting, fixing linting issues, and performing TypeScript type checking. ```bash npm run typecheck npm run lint npm run lint:fix ``` -------------------------------- ### Publish Prerelease (dev) to npm Source: https://github.com/zkp2p/zkp2p-client-sdk/blob/main/packages/offramp-sdk/PUBLISHING.md Publishes a development prerelease version of the @zkp2p/offramp-sdk to npm using the 'dev' dist-tag. This allows consumers to test new versions without affecting the 'latest' tag. Requires npm access and Node 18+. ```bash cd packages/offramp-sdk npm publish --access public --tag dev --no-provenance --otp ``` ```bash # Without 2FA: npm publish --access public --tag dev --no-provenance ``` -------------------------------- ### Indexer Queries (Historical Data) Source: https://context7.com/zkp2p/zkp2p-client-sdk/llms.txt Provides advanced filtering and pagination for historical data, including querying deposits with various filters, retrieving deposits with related payment methods and intents, fetching historical fulfillment records, and finding deposits by payee hash. ```APIDOC ## Indexer Queries (Historical Data) ### Description Advanced filtering and pagination for historical data. ### Method This section describes the methods available for querying historical data via the indexer. ### Endpoints N/A (These are SDK method calls, not direct API endpoints) ### Parameters #### `indexer.getDeposits` - **filter** (object) - Optional - Filters for deposits. - **status** (string) - Optional - Status of the deposit (e.g., 'ACTIVE'). - **minLiquidity** (string) - Optional - Minimum liquidity amount. - **depositor** (string) - Optional - The depositor's address. - **pagination** (object) - Optional - Pagination and sorting options. - **limit** (number) - Optional - Maximum number of results. - **orderBy** (string) - Optional - Field to order by (e.g., 'remainingDeposits'). - **orderDirection** (string) - Optional - Order direction ('asc' or 'desc'). #### `indexer.getDepositsWithRelations` - **filter** (object) - Optional - Filters for deposits. - **status** (string) - Optional - Status of the deposit (e.g., 'ACTIVE'). - **pagination** (object) - Optional - Pagination options. - **limit** (number) - Optional - Maximum number of results. - **include** (object) - Optional - Specifies related data to include. - **includeIntents** (boolean) - Optional - Whether to include intents. - **intentStatuses** (array of strings) - Optional - Filter intents by status (e.g., ['SIGNALED']). #### `indexer.getFulfilledIntentEvents` - **intentHashes** (array of strings) - Required - An array of intent hashes to query fulfillment events for. #### `indexer.getDepositsByPayeeHash` - **payeeHash** (string) - Required - The hash of the payee to find deposits for. ### Request Example ```typescript // Query deposits with filters const activeDeposits = await client.indexer.getDeposits( { status: 'ACTIVE', minLiquidity: '1000000', depositor: '0xYourAddress' }, { limit: 50, orderBy: 'remainingDeposits', orderDirection: 'desc' } ); // Get deposits with related data (payment methods and intents) const depositsWithRelations = await client.indexer.getDepositsWithRelations( { status: 'ACTIVE' }, { limit: 50 }, { includeIntents: true, intentStatuses: ['SIGNALED'] } ); // Get historical fulfillment records const fulfillments = await client.indexer.getFulfilledIntentEvents(['0xIntent1...', '0xIntent2...']); ulfillments.forEach(f => { console.log('Intent fulfilled:', f.intentHash, 'to:', f.fundsTransferredTo); }); // Find deposits by payee hash const payeeDeposits = await client.indexer.getDepositsByPayeeHash('0xPayeeHash...'); ``` ### Response #### Success Response (200) - **deposits** (array) - An array of deposit objects. - **fulfillments** (array) - An array of fulfillment event objects. - **intentHash** (string) - The hash of the fulfilled intent. - **fundsTransferredTo** (string) - The address where funds were transferred. - **deposits** (array) - An array of deposit objects (for `getDepositsByPayeeHash`). #### Response Example ```json { "fulfillments": [ { "intentHash": "0xabc...", "fundsTransferredTo": "0xRecipientAddress" } ] } ``` ``` -------------------------------- ### Create USDC Deposit with Payment Methods and Rates Source: https://github.com/zkp2p/zkp2p-client-sdk/blob/main/packages/offramp-sdk/README.md Creates a new USDC deposit, specifying the token address, amount, acceptable intent range, payment processors, deposit details, and conversion rates. The `onSuccess` callback logs the transaction hash upon successful deposit creation. ```typescript import { Currency } from '@zkp2p/offramp-sdk'; await client.createDeposit({ token: '0xUSDC_ADDRESS', amount: 10000000000n, // 10,000 USDC (6 decimals) intentAmountRange: { min: 100000n, max: 1000000000n }, processorNames: ['wise', 'revolut'], depositData: [ { email: 'maker@example.com' }, // Wise payment details { tag: '@maker' }, // Revolut payment details ], conversionRates: [ [{ currency: Currency.USD, conversionRate: '1020000000000000000' }], // 1.02 (18 decimals) [{ currency: Currency.EUR, conversionRate: '950000000000000000' }], // 0.95 (18 decimals) ], onSuccess: ({ hash }) => console.log('Deposit created:', hash), }); ``` -------------------------------- ### Interact with On-Chain Data using Low-Level Parameters in zkp2p-client-sdk Source: https://github.com/zkp2p/zkp2p-client-sdk/blob/main/packages/offramp-sdk/README.md Provides methods for direct interaction with on-chain data, utilizing bytes32 hex strings for parameters. These methods include adding/deactivating currencies for payment methods, enabling/disabling payment methods, and updating currency conversion rates. ```typescript // addCurrencies - Add currencies to a payment method await client.addCurrencies({ depositId: 1n, paymentMethod: '0x...', // bytes32 payment method hash currencies: [ { code: '0x...', minConversionRate: 1020000000000000000n }, // bytes32 currency code, 18 decimals ], }); // deactivateCurrency - Remove a currency from a payment method await client.deactivateCurrency({ depositId: 1n, paymentMethod: '0x...', // bytes32 payment method hash currencyCode: '0x...', // bytes32 currency code }); // setPaymentMethodActive - Enable/disable a payment method await client.setPaymentMethodActive({ depositId: 1n, paymentMethod: '0x...', // bytes32 payment method hash (not paymentMethodHash) isActive: true, }); // setCurrencyMinRate - Update minimum conversion rate await client.setCurrencyMinRate({ depositId: 1n, paymentMethod: '0x...', // bytes32 payment method hash fiatCurrency: '0x...', // bytes32 currency code (not currencyCode) minConversionRate: 1020000000000000000n, // 18 decimals }); ```