@keetanetwork/anchor 0.0.116 → 0.1.1
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/README.md +118 -0
- package/lib/chaining.d.ts +12 -0
- package/lib/chaining.d.ts.map +1 -1
- package/lib/chaining.js +65 -4
- package/lib/chaining.js.map +1 -1
- package/lib/queue/index.d.ts.map +1 -1
- package/lib/queue/index.js +36 -43
- package/lib/queue/index.js.map +1 -1
- package/npm-shrinkwrap.json +5 -5
- package/package.json +27 -3
- package/services/fx/client.d.ts +5 -1
- package/services/fx/client.d.ts.map +1 -1
- package/services/fx/client.js +13 -2
- package/services/fx/client.js.map +1 -1
- package/services/fx/common.d.ts +5 -2
- package/services/fx/common.d.ts.map +1 -1
- package/services/fx/common.js.map +1 -1
- package/services/fx/server.d.ts +2 -2
- package/services/fx/server.d.ts.map +1 -1
- package/services/fx/server.js +49 -11
- package/services/fx/server.js.map +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/services/fx/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,IAAI,WAAW,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAOrD,OAAO,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AACnD,OAAO,MAAM,MAAM,2BAA2B,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAErD,OAAO,EACN,kCAAkC,EAClC,+BAA+B,EAC/B,+BAA+B,EAC/B,mCAAmC,EACnC,4BAA4B,EAC5B,MAAM,IAAI,QAAQ,EAClB,MAAM,aAAa,CAAC;AAcrB,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAErE,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC5E,OAAO,EAAE,yCAA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IAAI,CAAC,CAAC;QACd,CAAC;QAED,MAAM,CAAE,kBAAkB,EAAE,WAAW,CAAE,GAAG,YAAY,CAAC;QACzD,MAAM,QAAQ,GAAG,IAAI,yBAAyB,CAAC,WAAW,EAAE,kBAAkB,EAAE;YAC/E,IAAI,EAAE,WAAW,CAAC,OAAO,CAAC,mBAAmB,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC;YACrF,EAAE,EAAE,WAAW,CAAC,OAAO,CAAC,mBAAmB,CAAC,OAAO,CAAC,IAAI,CAAC;YACzD,MAAM,EAAE,EAAE;YACV,QAAQ,EAAE,MAAM;SAChB,EAAE,IAAI,CAAC,CAAC;QAET,OAAM,CAAC,MAAM,QAAQ,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC;IACjD,CAAC;IAED,gBAAgB;IAChB,UAAU,CAAC,WAAmB;QAC7B,IAAI,WAAW,KAAK,8BAA8B,EAAE,CAAC;YACpD,MAAK,CAAC,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC,CAAC;QAC1C,CAAC;QAED,OAAM,CAAC;YACN,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,MAAM,EAAE,IAAI,CAAC,OAAO;YACpB,OAAO,EAAE,IAAI,CAAC,QAAQ;YACtB,aAAa,EAAE,IAAI,CAAC,cAAc;SAClC,CAAC,CAAC;IAEJ,CAAC;CACD;AAED,eAAe,mBAAmB,CAAC","sourcesContent":["import { lib as KeetaNetLib } from '@keetanetwork/keetanet-client';\nimport { getDefaultResolver } from '../../config.js';\nimport type {\n\tUserClient as KeetaNetUserClient\n} from '@keetanetwork/keetanet-client';\nimport type { Logger } from '../../lib/log/index.ts';\nimport type Resolver from '../../lib/resolver.ts';\nimport type { ServiceMetadata, ServiceSearchCriteria, SharedLookupCriteria } from '../../lib/resolver.ts';\nimport { Buffer } from '../../lib/utils/buffer.js';\nimport crypto from '../../lib/utils/crypto.js';\nimport { validateURL } from '../../lib/utils/url.js';\nimport type { BrandedString } from '../../lib/utils/brand.ts';\nimport {\n\tassertKeetaNetTokenPublicKeyString,\n\tisKeetaFXAnchorEstimateResponse,\n\tisKeetaFXAnchorExchangeResponse,\n\tisKeetaFXAnchorMarketPricesResponse,\n\tisKeetaFXAnchorQuoteResponse,\n\tErrors as FXErrors\n} from './common.js';\nimport type {\n\tConversionInput,\n\tConversionInputCanonical,\n\tConversionInputCanonicalJSON,\n\tKeetaFXAnchorEstimate,\n\tKeetaFXAnchorExchange,\n\tKeetaFXAnchorMarketPrices,\n\tKeetaFXAnchorMarketPricesRequest,\n\tKeetaFXAnchorMarketPriceRatio,\n\tKeetaFXAnchorQuote,\n\tKeetaNetToken,\n\tKeetaNetTokenPublicKeyString\n} from './common.ts';\nimport { AnchorExternalBuilder } from '../../lib/anchor-external.js';\nimport type { AnchorExternalInput } from '../../lib/anchor-external.js';\nimport { KeetaAnchorError, KeetaAnchorUserError } from '../../lib/error.js';\nimport { resolveSharedAnchorMetadataLegalExtension } from '../../lib/metadata.types.js';\nimport type { AnchorMetadataLegalField, SharedAnchorMetadataLegalExtension } from '../../lib/metadata.types.js';\nimport type { AnchorReference } from '../../lib/anchor-status.js';\n\n/**\n * An opaque type that represents a provider ID.\n */\ntype ProviderID = BrandedString<'FXProviderID'>;\n\ntype AccountOptions = {\n\t/**\n\t * The account to use for signing requests. If not provided, the\n\t * account associated with the provided client will be used. If there\n\t * is no account associated with the client, an error occurs.\n\t */\n\tsigner?: InstanceType<typeof KeetaNetLib.Account>;\n\t/**\n\t * Account to perform changes on. If not provided, the account\n\t * associated with the provided client will be used. If there is no\n\t * account associated with the client, an error occurs.\n\t */\n\taccount?: InstanceType<typeof KeetaNetLib.Account>;\n};\n\n/**\n * Controls how {@link KeetaFXAnchorClient.getPrices} coalesces concurrent\n * calls that share the same base (`priceIn`) into fewer `getMarketPrices`\n * requests.\n */\nexport interface KeetaFXAnchorClientGetPricesBatching {\n\t/**\n\t * How long to wait after each `getPrices` call for additional calls\n\t * with the same base before sending the batched `getMarketPrices`\n\t * request. Each new same-base call resets this timer.\n\t *\n\t * Defaults to `25`.\n\t */\n\twaitMs: number;\n\t/**\n\t * Maximum time to wait from the first `getPrices` call in a batch\n\t * before flushing, even if new same-base calls keep arriving.\n\t *\n\t * Defaults to `100` for the client default. When omitted from a custom\n\t * object, defaults to `4 * waitMs`.\n\t */\n\tmaxWaitMs?: number;\n}\n\n/**\n * The configuration options for the FX Anchor client.\n */\nexport type KeetaFXAnchorClientConfig = {\n\t/**\n\t * The ID of the client. This is used to identify the client in logs.\n\t * If not provided, a random ID will be generated.\n\t */\n\tid?: string;\n\t/**\n\t * The logger to use for logging messages. If not provided, no logging\n\t * will be done.\n\t */\n\tlogger?: Logger | undefined;\n\t/**\n\t * The resolver to use for resolving FX Anchor services. If not\n\t * provided, a default resolver will be created using the provided\n\t * client and network (if the network is also not provided and the\n\t * client is not a UserClient, an error occurs).\n\t */\n\tresolver?: Resolver;\n\t/**\n\t * The account to use for signing requests. If not provided, the\n\t * account associated with the provided client will be used. If there\n\t * is no account associated with the client, an error occurs.\n\t */\n\tsigner?: InstanceType<typeof KeetaNetLib.Account>;\n\t/**\n\t * Account to perform changes on. If not provided, the account\n\t * associated with the provided client will be used. If there is no\n\t * account associated with the client, an error occurs.\n\t */\n\taccount?: InstanceType<typeof KeetaNetLib.Account>;\n\t/**\n\t * How long `getPrices` waits for additional calls with the same base\n\t * so their provider `getMarketPrices` requests can be batched together.\n\t *\n\t * - `true` / omitted - (`waitMs: 25`, `maxWaitMs: 100`)\n\t * - `false` - disable batching\n\t * - `{ waitMs, maxWaitMs? }` - custom timing (`maxWaitMs` defaults to `4 * waitMs`)\n\t */\n\tgetPricesBatching?: KeetaFXAnchorClientGetPricesBatching | boolean;\n\t/**\n\t * Caps the client applies to every quote and estimate. See\n\t * {@link KeetaFXAnchorClientDefaultLimits}.\n\t */\n\tdefaultLimits?: KeetaFXAnchorClientDefaultLimits;\n} & Omit<NonNullable<Parameters<typeof getDefaultResolver>[1]>, 'client'> & AccountOptions;\n\nfunction typedFxServiceEntries<T extends object>(obj: T): [keyof T, T[keyof T]][] {\n\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\treturn(Object.entries(obj) as [keyof T, T[keyof T]][]);\n}\n\ntype KeetaFXAnchorOperations = {\n\t[operation in keyof NonNullable<ServiceMetadata['services']['fx']>[string]['operations']]: (params?: { [key: string]: string; }) => URL;\n};\n\ninterface KeetaFXServiceInfo extends SharedAnchorMetadataLegalExtension {\n\toperations: {\n\t\t[operation in keyof KeetaFXAnchorOperations]: Promise<KeetaFXAnchorOperations[operation]>;\n\t},\n\tfrom: NonNullable<ServiceMetadata['services']['fx']>[string]['from'];\n}\n\ntype GetEndpointsResult = {\n\t[providerID: ProviderID]: KeetaFXServiceInfo;\n};\n\nconst KeetaFXAnchorClientAccessToken = Symbol('KeetaFXAnchorClientAccessToken');\n\nasync function getEndpoints(\n\tresolver: Resolver,\n\trequest: Partial<Pick<ConversionInputCanonical, 'from' | 'to' | 'affinity'>> & Pick<GetProvidersOptions, 'requiredOperations'>,\n\t_ignored_account: InstanceType<typeof KeetaNetLib.Account>,\n\tsharedCriteria?: SharedLookupCriteria,\n\toptions?: { logger?: Logger | undefined; }\n): Promise<GetEndpointsResult | null> {\n\tconst criteria: ServiceSearchCriteria<'fx'> = {};\n\tif (request.from !== undefined) {\n\t\tcriteria.inputCurrencyCode = request.from.publicKeyString.get();\n\t}\n\tif (request.to !== undefined) {\n\t\tcriteria.outputCurrencyCode = request.to.publicKeyString.get();\n\t}\n\n\tif (request.requiredOperations) {\n\t\tcriteria.requiredOperations = request.requiredOperations;\n\t}\n\n\tif (request.affinity !== undefined) {\n\t\tcriteria.supportedAffinity = request.affinity;\n\t}\n\n\tconst response = await resolver.lookup('fx', {\n\t\t...criteria\n\t\t// kycProviders: 'TODO' XXX:TODO\n\t}, sharedCriteria);\n\n\tif (response === undefined) {\n\t\treturn(null);\n\t}\n\n\tconst serviceInfoPromises = Object.entries(response).map(async function([id, serviceInfo]): Promise<[ProviderID, KeetaFXServiceInfo]> {\n\t\tconst operations = await serviceInfo.operations('object');\n\t\tconst operationsFunctions: Partial<KeetaFXServiceInfo['operations']> = {};\n\t\tfor (const [key, operation] of Object.entries(operations)) {\n\t\t\tif (operation === undefined) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tObject.defineProperty(operationsFunctions, key, {\n\t\t\t\tget: async function() {\n\t\t\t\t\tconst url = await operation('string');\n\t\t\t\t\treturn(function(params?: { [key: string]: string; }): URL {\n\t\t\t\t\t\tlet substitutedURL = url;\n\t\t\t\t\t\tfor (const [paramKey, paramValue] of Object.entries(params ?? {})) {\n\t\t\t\t\t\t\tsubstitutedURL = substitutedURL.replace(`{${paramKey}}`, encodeURIComponent(paramValue));\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn(validateURL(substitutedURL));\n\t\t\t\t\t});\n\t\t\t\t},\n\t\t\t\tenumerable: true,\n\t\t\t\tconfigurable: true\n\t\t\t});\n\t\t}\n\n\t\tconst fromInfo = await serviceInfo.from('array');\n\t\tconst allFrom = await Promise.all(fromInfo.map(async function(fromFn) {\n\t\t\tconst from = await fromFn('object');\n\n\t\t\tconst currencyCodes = await Promise.all((await from.currencyCodes('array')).map(async (currencyCode) => {\n\t\t\t\tconst code = await currencyCode('string');\n\t\t\t\treturn(assertKeetaNetTokenPublicKeyString(code));\n\t\t\t}));\n\n\t\t\tconst to = await Promise.all((await from.to('array')).map(async (currencyCode) => {\n\t\t\t\tconst code = await currencyCode('string');\n\t\t\t\treturn(assertKeetaNetTokenPublicKeyString(code));\n\t\t\t}));\n\n\t\t\tconst kycProvidersEntry = (await from.kycProviders?.('array'))?.map(async (providerFn) => {\n\t\t\t\tconst provider = await providerFn('string');\n\t\t\t\treturn(provider);\n\t\t\t});\n\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-empty-object-type\n\t\t\tlet kycProviders: { kycProviders: string[] } | {} = {};\n\t\t\tif (kycProvidersEntry && kycProvidersEntry.length > 0) {\n\t\t\t\tkycProviders = { kycProviders: await Promise.all(kycProvidersEntry) }\n\t\t\t}\n\n\t\t\treturn({ currencyCodes, to, ...kycProviders });\n\t\t}));\n\t\treturn([\n\t\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\t\tid as unknown as ProviderID,\n\t\t\t{\n\t\t\t\t...(await resolveSharedAnchorMetadataLegalExtension(serviceInfo.legal, { logger: options?.logger })),\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\t\t\toperations: operationsFunctions as KeetaFXServiceInfo['operations'],\n\t\t\t\tfrom: allFrom\n\t\t\t}\n\t\t]);\n\t});\n\n\tif (serviceInfoPromises.length === 0) {\n\t\treturn(null);\n\t}\n\n\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\tconst retval = Object.fromEntries(await Promise.all(serviceInfoPromises)) satisfies GetEndpointsResult as GetEndpointsResult;\n\n\treturn(retval);\n}\n\n/**\n * Limits the caller sets on the block that `createExchange` builds, from\n * the terms it showed the user. The limits apply only when\n * `createExchange` builds the block, not to a block the caller gives.\n *\n * The limits add to the client's `defaultLimits`; they never lift them.\n * - With affinity `to`, the anchor sets the amount sent, so `maxSend` is\n * required. With affinity `from`, it sets the amount received, so\n * `minReceive` is required.\n * - A fee in a token other than `from` or `to` needs `maxCost`, since no\n * default can price it.\n * - A fee in `from` or `to` must also be within `defaultLimits.maxCostBps`.\n * - An estimate bound must also be within\n * `defaultLimits.maxEstimateBoundBps` of its converted amount.\n */\nexport interface KeetaFXAnchorExchangeLimits {\n\t/**\n\t * The most of the `from` token the block may send for the conversion,\n\t * not counting the fee. Required for affinity `to`.\n\t */\n\tmaxSend?: bigint;\n\t/**\n\t * The least of the `to` token the block may receive. Required for\n\t * affinity `from`.\n\t */\n\tminReceive?: bigint;\n\t/**\n\t * The most the fee may be. A non-zero fee must also be in this token.\n\t * A fee in `from` or `to` must also be within the default fee cap.\n\t */\n\tmaxCost?: { token: KeetaNetToken; amount: bigint; };\n}\n\nexport interface KeetaFXAnchorCreateExchangeOptions {\n\tinputs?: readonly AnchorExternalInput[];\n\tlimits?: KeetaFXAnchorExchangeLimits;\n}\n\n/**\n * Caps `createExchange` applies to every block it builds, on top of any\n * caller limits. They do not filter quotes or estimates. Set a cap to\n * `null` to turn it off, or raise it to accept larger terms.\n */\nexport interface KeetaFXAnchorClientDefaultLimits {\n\t/**\n\t * The most a fee in the `from` or `to` token may be, in basis points\n\t * of the amount the conversion sends or receives in that token.\n\t *\n\t * Defaults to `100` (1%).\n\t */\n\tmaxCostBps?: number | null;\n\t/**\n\t * The furthest an estimate's bound may be from its converted amount,\n\t * in basis points of the converted amount.\n\t *\n\t * Defaults to `500` (5%).\n\t */\n\tmaxEstimateBoundBps?: number | null;\n}\n\ntype ResolvedDefaultLimits = { [K in keyof KeetaFXAnchorClientDefaultLimits]-?: number | null; };\n\nfunction resolveDefaultLimits(input: KeetaFXAnchorClientDefaultLimits | undefined): ResolvedDefaultLimits {\n\tconst resolved: ResolvedDefaultLimits = {\n\t\tmaxCostBps: input?.maxCostBps === undefined ? 100 : input.maxCostBps,\n\t\tmaxEstimateBoundBps: input?.maxEstimateBoundBps === undefined ? 500 : input.maxEstimateBoundBps\n\t};\n\n\tfor (const [ name, value ] of Object.entries(resolved)) {\n\t\tif (value !== null && (!Number.isInteger(value) || value < 0)) {\n\t\t\tthrow(new Error(`defaultLimits.${name} must be a non-negative integer or null`));\n\t\t}\n\t}\n\n\tif (resolved.maxEstimateBoundBps !== null && resolved.maxEstimateBoundBps > 10000) {\n\t\tthrow(new Error('defaultLimits.maxEstimateBoundBps must be at most 10000'));\n\t}\n\n\treturn(resolved);\n}\n\ntype ExchangeTerms = { sendAmount: bigint; receiveAmount: bigint; costAmount: bigint; costToken: KeetaNetToken; };\n\n/**\n * The amounts an exchange block sends and receives for a conversion, given\n * the converted amount it commits to and its fee.\n */\nfunction exchangeTerms(conversion: ConversionInputCanonical, convertedAmount: bigint, cost: { amount: bigint; token: KeetaNetToken; }): ExchangeTerms {\n\tif (conversion.affinity === 'to') {\n\t\treturn({ sendAmount: convertedAmount, receiveAmount: conversion.amount, costAmount: cost.amount, costToken: cost.token });\n\t}\n\n\treturn({ sendAmount: conversion.amount, receiveAmount: convertedAmount, costAmount: cost.amount, costToken: cost.token });\n}\n\ninterface KeetaFXAnchorBaseConfig {\n\tclient: KeetaNetUserClient;\n\tlogger?: Logger | undefined;\n}\n\nclass KeetaFXAnchorBase {\n\tprotected readonly logger?: Logger | undefined;\n\tprotected readonly client: KeetaNetUserClient;\n\n\tconstructor(config: KeetaFXAnchorBaseConfig) {\n\t\tthis.client = config.client;\n\t\tthis.logger = config.logger;\n\t}\n}\n\nexport class KeetaFXAnchorProviderBase extends KeetaFXAnchorBase {\n\treadonly serviceInfo: KeetaFXServiceInfo;\n\treadonly providerID: ProviderID;\n\treadonly conversion: ConversionInputCanonical;\n\treadonly options: Pick<AccountOptions, 'account'> | undefined;\n\tprivate readonly parent: KeetaFXAnchorClient;\n\treadonly #defaultLimits: ResolvedDefaultLimits;\n\n\tconstructor(serviceInfo: KeetaFXServiceInfo, providerID: ProviderID, conversion: ConversionInputCanonical, parent: KeetaFXAnchorClient, options?: Pick<AccountOptions, 'account'>) {\n\t\tconst parentPrivate = parent._internals(KeetaFXAnchorClientAccessToken);\n\t\tsuper(parentPrivate);\n\n\t\tthis.#defaultLimits = parentPrivate.defaultLimits;\n\t\tthis.serviceInfo = serviceInfo;\n\t\tthis.providerID = providerID;\n\t\tthis.conversion = conversion;\n\t\tthis.parent = parent;\n\t\tthis.options = options;\n\t}\n\n\t/**\n\t * Checks that the anchor's echoed request matches this conversion and\n\t * returns `this.conversion`. Throws when any field differs.\n\t */\n\t#bindConversion(echoed: ConversionInputCanonical | ConversionInputCanonicalJSON): ConversionInputCanonical {\n\t\tconst own = this.conversion;\n\t\tconst mismatched: string[] = [];\n\t\tif (!KeetaNetLib.Account.toAccount(echoed.from).comparePublicKey(own.from)) {\n\t\t\tmismatched.push('from');\n\t\t}\n\t\tif (!KeetaNetLib.Account.toAccount(echoed.to).comparePublicKey(own.to)) {\n\t\t\tmismatched.push('to');\n\t\t}\n\t\tif (BigInt(echoed.amount) !== own.amount) {\n\t\t\tmismatched.push('amount');\n\t\t}\n\t\tif (echoed.affinity !== own.affinity) {\n\t\t\tmismatched.push('affinity');\n\t\t}\n\t\tif (echoed.preferredCostAsset !== own.preferredCostAsset) {\n\t\t\tmismatched.push('preferredCostAsset');\n\t\t}\n\t\tif (mismatched.length > 0) {\n\t\t\tthrow(new FXErrors.ResponseMismatch(`FX provider ${String(this.providerID)} answered for a different conversion than requested (${mismatched.join(', ')})`));\n\t\t}\n\n\t\treturn(own);\n\t}\n\n\t/**\n\t * Checks that the anchor's amounts are possible: a positive converted\n\t * amount and bound, and a fee range that is not negative or reversed.\n\t */\n\t#assertAmounts(convertedAmount: bigint, convertedAmountBound: bigint | undefined, costMin: bigint, costMax: bigint): void {\n\t\tconst isConvertedInvalid = convertedAmount <= 0n || (convertedAmountBound ?? 1n) <= 0n;\n\t\tconst isCostInvalid = costMin < 0n || costMax < costMin;\n\t\tif (isConvertedInvalid || isCostInvalid) {\n\t\t\tthrow(new FXErrors.ResponseMismatch(`FX provider ${String(this.providerID)} gave invalid amounts (converted ${convertedAmount}, bound ${convertedAmountBound ?? 'none'}, fee ${costMin} to ${costMax})`));\n\t\t}\n\t}\n\n\t/**\n\t * Checks that a non-zero fee is in a token the user expects to pay\n\t * with: the `from` or `to` token, the network base token, or the\n\t * requested `preferredCostAsset`. Throws when it is any other token.\n\t */\n\t#assertCostToken(cost: { amount: bigint; token: KeetaNetToken }): void {\n\t\tif (cost.amount === 0n) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst own = this.conversion;\n\t\tconst allowed = [ own.from, own.to, this.client.baseToken ];\n\t\tif (own.preferredCostAsset !== undefined) {\n\t\t\tallowed.push(KeetaNetLib.Account.fromPublicKeyString(own.preferredCostAsset));\n\t\t}\n\n\t\tconst isAllowed = allowed.some(function(token) {\n\t\t\treturn(token.comparePublicKey(cost.token));\n\t\t});\n\t\tif (!isAllowed) {\n\t\t\tthrow(new FXErrors.ResponseMismatch(`FX provider ${String(this.providerID)} charges its fee in a token that is not part of the conversion (${cost.token.publicKeyString.get()})`));\n\t\t}\n\t}\n\n\t/**\n\t * Checks that an estimate's bound is on the safe side of its converted\n\t * amount: no more for affinity `from`, no less for affinity `to`.\n\t * Throws when it is on the other side.\n\t */\n\t#assertEstimateBound(convertedAmount: bigint, convertedAmountBound: bigint | undefined): void {\n\t\tif (convertedAmountBound === undefined) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst affinity = this.conversion.affinity;\n\t\tconst isInvalid = affinity === 'from' ? convertedAmountBound > convertedAmount : convertedAmountBound < convertedAmount;\n\t\tif (isInvalid) {\n\t\t\tthrow(new FXErrors.ResponseMismatch(`FX provider ${String(this.providerID)} gave an estimate bound of ${convertedAmountBound} that is on the wrong side of its converted amount ${convertedAmount} for affinity \"${affinity}\"`));\n\t\t}\n\t}\n\n\t/**\n\t * Checks every amount the anchor sets in the block against the\n\t * caller's limits and the client's default caps. Both must hold, so\n\t * a limit copied from the anchor's own quote cannot lift a default.\n\t * Throws when an amount is not bounded or is past its bound. See\n\t * {@link KeetaFXAnchorExchangeLimits}.\n\t */\n\t#assertSigningLimits(terms: ExchangeTerms, estimate: { convertedAmount: bigint; convertedAmountBound: bigint; } | undefined, limits: KeetaFXAnchorExchangeLimits | undefined): void {\n\t\tthis.#assertAmountLimits(terms, limits);\n\t\tif (estimate !== undefined) {\n\t\t\tthis.#assertBoundCap(estimate.convertedAmount, estimate.convertedAmountBound);\n\t\t}\n\t\tthis.#assertCostLimits(terms, limits?.maxCost);\n\t}\n\n\t/**\n\t * Checks the amounts sent and received against the caller's limits.\n\t * The side the provider sets must have a limit: `maxSend` for affinity\n\t * `to`, `minReceive` for affinity `from`.\n\t */\n\t#assertAmountLimits(terms: ExchangeTerms, limits: KeetaFXAnchorExchangeLimits | undefined): void {\n\t\tconst affinity = this.conversion.affinity;\n\t\tif (affinity === 'to' && limits?.maxSend === undefined) {\n\t\t\tthrow(new FXErrors.ExchangeLimitExceeded('FX exchange with affinity \"to\" needs limits.maxSend, because the provider sets the amount sent'));\n\t\t}\n\t\tif (affinity === 'from' && limits?.minReceive === undefined) {\n\t\t\tthrow(new FXErrors.ExchangeLimitExceeded('FX exchange with affinity \"from\" needs limits.minReceive, because the provider sets the amount received'));\n\t\t}\n\n\t\tif (limits?.maxSend !== undefined && terms.sendAmount > limits.maxSend) {\n\t\t\tthrow(new FXErrors.ExchangeLimitExceeded(`FX exchange would send ${terms.sendAmount}, more than the limit of ${limits.maxSend}`));\n\t\t}\n\t\tif (limits?.minReceive !== undefined && terms.receiveAmount < limits.minReceive) {\n\t\t\tthrow(new FXErrors.ExchangeLimitExceeded(`FX exchange would receive ${terms.receiveAmount}, less than the limit of ${limits.minReceive}`));\n\t\t}\n\t}\n\n\t/**\n\t * Checks that an estimate's bound is within the default cap of its\n\t * converted amount.\n\t */\n\t#assertBoundCap(convertedAmount: bigint, convertedAmountBound: bigint): void {\n\t\tconst maxBps = this.#defaultLimits.maxEstimateBoundBps;\n\t\tif (maxBps === null) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst distance = convertedAmount > convertedAmountBound ? convertedAmount - convertedAmountBound : convertedAmountBound - convertedAmount;\n\t\tif (distance * 10000n > convertedAmount * BigInt(maxBps)) {\n\t\t\tthrow(new FXErrors.ExchangeLimitExceeded(`FX estimate bound of ${convertedAmountBound} is more than ${maxBps} basis points from its converted amount ${convertedAmount}; raise defaultLimits.maxEstimateBoundBps to accept it`));\n\t\t}\n\t}\n\n\t/**\n\t * Checks a non-zero fee against the caller's `maxCost` and, for a fee\n\t * in `from` or `to`, against the default fee cap. A fee in any other\n\t * token needs `maxCost`.\n\t */\n\t#assertCostLimits(terms: ExchangeTerms, maxCost: KeetaFXAnchorExchangeLimits['maxCost']): void {\n\t\tif (terms.costAmount === 0n) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (maxCost !== undefined) {\n\t\t\tif (!maxCost.token.comparePublicKey(terms.costToken)) {\n\t\t\t\tthrow(new FXErrors.ExchangeLimitExceeded(`FX exchange fee is in ${terms.costToken.publicKeyString.get()}, not in the limit token ${maxCost.token.publicKeyString.get()}`));\n\t\t\t}\n\t\t\tif (terms.costAmount > maxCost.amount) {\n\t\t\t\tthrow(new FXErrors.ExchangeLimitExceeded(`FX exchange fee of ${terms.costAmount} is more than the limit of ${maxCost.amount}`));\n\t\t\t}\n\t\t}\n\n\t\tconst base = this.#costBase(terms);\n\t\tif (base === null) {\n\t\t\tif (maxCost === undefined) {\n\t\t\t\tthrow(new FXErrors.ExchangeLimitExceeded(`FX exchange fee is in ${terms.costToken.publicKeyString.get()}, which is not part of the conversion; set limits.maxCost to accept it`));\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tconst maxBps = this.#defaultLimits.maxCostBps;\n\t\tif (maxBps !== null && terms.costAmount * 10000n > base * BigInt(maxBps)) {\n\t\t\tthrow(new FXErrors.ExchangeLimitExceeded(`FX exchange fee of ${terms.costAmount} is more than ${maxBps} basis points of ${base}; raise defaultLimits.maxCostBps to accept it`));\n\t\t}\n\t}\n\n\t/**\n\t * The amount a fee is capped against: what the conversion sends when\n\t * the fee is in `from`, what it receives when the fee is in `to`, or\n\t * `null` for a fee in any other token.\n\t */\n\t#costBase(terms: ExchangeTerms): bigint | null {\n\t\tif (terms.costToken.comparePublicKey(this.conversion.from)) {\n\t\t\treturn(terms.sendAmount);\n\t\t}\n\t\tif (terms.costToken.comparePublicKey(this.conversion.to)) {\n\t\t\treturn(terms.receiveAmount);\n\t\t}\n\t\treturn(null);\n\t}\n\n\tasync #parseResponseError(data: { ok: false }) {\n\t\tif (typeof data !== 'object' || data === null) {\n\t\t\tthrow(new Error('Response is not an error'));\n\t\t}\n\n\t\tif (!('ok' in data) || data.ok) {\n\t\t\tthrow(new Error('Response is not an error'));\n\t\t}\n\n\t\tlet errorStr;\n\n\t\ttry {\n\t\t\treturn(await KeetaAnchorError.fromJSON(data));\n\t\t} catch (error: unknown) {\n\t\t\tthis.logger?.debug('Failed to parse error response as KeetaAnchorError', error, data);\n\t\t}\n\n\t\tif ('error' in data && typeof data.error === 'string') {\n\t\t\terrorStr = data.error;\n\t\t} else {\n\t\t\terrorStr = 'Unknown error';\n\t\t}\n\n\t\treturn(new Error(`FX request failed: ${errorStr}`));\n\t}\n\n\tasync #getEndpoint(operation: keyof KeetaFXAnchorOperations, params?: { [key: string]: string; }): Promise<URL> {\n\t\tconst operationFn = await this.serviceInfo.operations[operation];\n\t\tif (operationFn === undefined) {\n\t\t\tthrow(new KeetaAnchorUserError(`Provider ${String(this.providerID)} does not support \"${operation}\" operation`));\n\t\t}\n\t\treturn(operationFn(params));\n\t}\n\n\tasync getEstimate(): Promise<KeetaFXAnchorEstimate> {\n\t\tconst estimateURL = await this.#getEndpoint('getEstimate');\n\n\t\tconst requestInformation = await fetch(estimateURL, {\n\t\t\tmethod: 'POST',\n\t\t\theaders: {\n\t\t\t\t'Content-Type': 'application/json',\n\t\t\t\t'Accept': 'application/json'\n\t\t\t},\n\t\t\tbody: JSON.stringify({\n\t\t\t\trequest: KeetaNetLib.Utils.Conversion.toJSONSerializable(this.conversion)\n\t\t\t})\n\t\t});\n\n\t\tconst requestInformationJSON: unknown = await requestInformation.json();\n\t\tif (!isKeetaFXAnchorEstimateResponse(requestInformationJSON)) {\n\t\t\tthrow(new Error(`Invalid response from FX estimate service: ${JSON.stringify(requestInformationJSON)}`));\n\t\t}\n\n\t\tif (!requestInformationJSON.ok) {\n\t\t\tthrow(await this.#parseResponseError(requestInformationJSON));\n\t\t}\n\n\t\tthis.logger?.debug(`FX estimate request successful, to provider ${estimateURL} for ${JSON.stringify(KeetaNetLib.Utils.Conversion.toJSONSerializable(this.conversion))}`);\n\t\tconst estimateJSON = requestInformationJSON.estimate;\n\t\tconst estimate: KeetaFXAnchorEstimate = {\n\t\t\trequest: this.#bindConversion(estimateJSON.request),\n\t\t\tconvertedAmount: BigInt(estimateJSON.convertedAmount),\n\t\t\texpectedCost: {\n\t\t\t\tmin: BigInt(estimateJSON.expectedCost.min),\n\t\t\t\tmax: BigInt(estimateJSON.expectedCost.max),\n\t\t\t\ttoken: KeetaNetLib.Account.fromPublicKeyString(estimateJSON.expectedCost.token)\n\t\t\t},\n\t\t\t...(estimateJSON.convertedAmountBound !== undefined ? { convertedAmountBound: BigInt(estimateJSON.convertedAmountBound) } : {}),\n\t\t\t...(() => {\n\t\t\t\tif (estimateJSON.canPerformExchange === false) {\n\t\t\t\t\treturn({ canPerformExchange: false });\n\t\t\t\t} else if (estimateJSON.requiresQuote === undefined) {\n\t\t\t\t\treturn({})\n\t\t\t\t} else if (estimateJSON.requiresQuote) {\n\t\t\t\t\treturn({ requiresQuote: true });\n\t\t\t\t// We have to disable this as doing !estimateJSON.requiresQuote breaks the compiler, and that is what eslint wants us to do\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unnecessary-boolean-literal-compare\n\t\t\t\t} else if (estimateJSON.requiresQuote === false) {\n\t\t\t\t\treturn({\n\t\t\t\t\t\trequiresQuote: false,\n\t\t\t\t\t\taccount: KeetaNetLib.Account.fromPublicKeyString(estimateJSON.account)\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t})()\n\t\t};\n\n\t\tconst estimateCost = { amount: estimate.expectedCost.max, token: estimate.expectedCost.token };\n\t\tthis.#assertAmounts(estimate.convertedAmount, estimate.convertedAmountBound, estimate.expectedCost.min, estimate.expectedCost.max);\n\t\tthis.#assertEstimateBound(estimate.convertedAmount, estimate.convertedAmountBound);\n\t\tthis.#assertCostToken(estimateCost);\n\n\t\treturn(estimate);\n\t}\n\n\t/**\n\t * Get a quote from the provider. If an estimate is provided, it will\n\t * be used to validate the quote is within the tolerance range.\n\t *\n\t * @param estimate An optional estimate to validate the quote against\n\t * @param tolerance The tolerance, in percentage points, to allow the\n\t * quote to vary from the estimate. For example, a\n\t * tolerance of 1.0 allows the quote to be 100% more\n\t * or less than the estimate. The default is 0.10\n\t * (10%).\n\t * @returns A promise that resolves to the quote response\n\t */\n\tasync getQuote(estimate?: KeetaFXAnchorEstimate, tolerance: number = 0.1): Promise<KeetaFXAnchorQuote> {\n\t\tconst serviceURL = await this.#getEndpoint('getQuote');\n\t\tconst requestInformation = await fetch(serviceURL, {\n\t\t\tmethod: 'POST',\n\t\t\theaders: {\n\t\t\t\t'Content-Type': 'application/json',\n\t\t\t\t'Accept': 'application/json'\n\t\t\t},\n\t\t\tbody: JSON.stringify({\n\t\t\t\trequest: KeetaNetLib.Utils.Conversion.toJSONSerializable(this.conversion)\n\t\t\t})\n\t\t});\n\n\t\tconst requestInformationJSON: unknown = await requestInformation.json();\n\t\tif (!isKeetaFXAnchorQuoteResponse(requestInformationJSON)) {\n\t\t\tthrow(new Error(`Invalid response from FX quote service: ${JSON.stringify(requestInformationJSON)}`));\n\t\t}\n\n\t\tif (!requestInformationJSON.ok) {\n\t\t\tthrow(await this.#parseResponseError(requestInformationJSON));\n\t\t}\n\n\t\tif (estimate !== undefined && tolerance !== undefined) {\n\t\t\tconst quoteAmount = BigInt(requestInformationJSON.quote.convertedAmount);\n\t\t\tconst estimateAmount = BigInt(estimate.convertedAmount);\n\t\t\tconst lowerBound = estimateAmount * BigInt(Math.round((1 - tolerance) * 100)) / 100n;\n\t\t\tconst upperBound = estimateAmount * BigInt(Math.round((1 + tolerance) * 100)) / 100n;\n\t\t\tif (quoteAmount > upperBound || quoteAmount < lowerBound) {\n\t\t\t\tthrow(new Error(`FX Quote amount: ${requestInformationJSON.quote.convertedAmount} differs more than tolerance limit: ${tolerance} from estimate`));\n\t\t\t}\n\t\t}\n\n\t\tthis.logger?.debug(`FX quote request successful, to provider ${serviceURL} for ${JSON.stringify(KeetaNetLib.Utils.Conversion.toJSONSerializable(this.conversion))}`);\n\t\tconst quoteJSON = requestInformationJSON.quote;\n\t\tconst quote: KeetaFXAnchorQuote = {\n\t\t\trequest: this.#bindConversion(quoteJSON.request),\n\t\t\taccount: KeetaNetLib.Account.fromPublicKeyString(quoteJSON.account),\n\t\t\tconvertedAmount: BigInt(quoteJSON.convertedAmount),\n\t\t\tcost: {\n\t\t\t\tamount: BigInt(quoteJSON.cost.amount),\n\t\t\t\ttoken: KeetaNetLib.Account.fromPublicKeyString(quoteJSON.cost.token)\n\t\t\t},\n\t\t\tsigned: quoteJSON.signed\n\t\t};\n\n\t\tthis.#assertAmounts(quote.convertedAmount, undefined, quote.cost.amount, quote.cost.amount);\n\t\tthis.#assertCostToken(quote.cost);\n\n\t\treturn(quote);\n\t}\n\n\t/**\n\t * Checks the terms of a quote or estimate as `createExchange` would\n\t * before it signs, without building or sending anything. Throws the\n\t * same errors `createExchange` would.\n\t */\n\tcheckExchange(input: { quote: KeetaFXAnchorQuote } | { estimate: KeetaFXAnchorEstimate; }, options?: Pick<KeetaFXAnchorCreateExchangeOptions, 'limits'>): void {\n\t\tthis.#bindConversion('quote' in input ? input.quote.request : input.estimate.request);\n\t\tthis.#checkExchangeTerms(input, options?.limits);\n\t}\n\n\t/**\n\t * Every check `createExchange` runs on the anchor's terms before it\n\t * builds the block. Returns the terms the block commits to.\n\t */\n\t#checkExchangeTerms(input: { quote: KeetaFXAnchorQuote } | { estimate: KeetaFXAnchorEstimate; }, limits: KeetaFXAnchorExchangeLimits | undefined): { liquidityProvider: KeetaFXAnchorQuote['account']; terms: ExchangeTerms; } {\n\t\tlet liquidityProvider;\n\t\tlet convertedAmountBound: bigint;\n\t\tlet costAmount;\n\t\tlet costToken;\n\t\tlet estimateTerms;\n\n\t\tif ('estimate' in input) {\n\t\t\tif (input.estimate.canPerformExchange === false) {\n\t\t\t\tthrow(new KeetaAnchorUserError('The provided estimate indicates that the exchange cannot be performed'));\n\t\t\t}\n\n\t\t\tif (input.estimate.requiresQuote !== false) {\n\t\t\t\tthrow(new FXErrors.QuoteRequired());\n\t\t\t}\n\n\t\t\tliquidityProvider = input.estimate.account;\n\t\t\tconvertedAmountBound = input.estimate.convertedAmountBound ?? input.estimate.convertedAmount;\n\t\t\tcostAmount = input.estimate.expectedCost.max;\n\t\t\tcostToken = input.estimate.expectedCost.token;\n\t\t\tthis.#assertAmounts(input.estimate.convertedAmount, input.estimate.convertedAmountBound, input.estimate.expectedCost.min, costAmount);\n\t\t\tthis.#assertEstimateBound(input.estimate.convertedAmount, input.estimate.convertedAmountBound);\n\t\t\testimateTerms = { convertedAmount: input.estimate.convertedAmount, convertedAmountBound: convertedAmountBound };\n\t\t} else {\n\t\t\tliquidityProvider = input.quote.account;\n\t\t\tconvertedAmountBound = input.quote.convertedAmount;\n\t\t\tcostAmount = input.quote.cost.amount;\n\t\t\tcostToken = input.quote.cost.token;\n\t\t\tthis.#assertAmounts(input.quote.convertedAmount, undefined, costAmount, costAmount);\n\t\t}\n\n\t\tthis.#assertCostToken({ amount: costAmount, token: costToken });\n\t\tconst terms = exchangeTerms(this.conversion, convertedAmountBound, { amount: costAmount, token: costToken });\n\t\tthis.#assertSigningLimits(terms, estimateTerms, limits);\n\n\t\treturn({ liquidityProvider, terms });\n\t}\n\n\t/**\n\t * Builds the swap block from this conversion and the anchor's checked\n\t * terms. Throws when a term fails a check; see `checkExchange`.\n\t */\n\tasync #buildSwapBlock(input: { quote: KeetaFXAnchorQuote } | { estimate: KeetaFXAnchorEstimate; }, options: KeetaFXAnchorCreateExchangeOptions | undefined): Promise<InstanceType<typeof KeetaNetLib.Block>> {\n\t\tconst request = this.conversion;\n\t\tconst { liquidityProvider, terms } = this.#checkExchangeTerms(input, options?.limits);\n\t\tconst { sendAmount, receiveAmount, costAmount, costToken } = terms;\n\n\t\t/* Construct the required operations for the swap request */\n\t\tconst builder = this.client.initBuilder(this.options);\n\n\t\t/*\n\t\t * When the fee is charged in the same token as the swap send,\n\t\t * combine them into a single SEND. The principal send carries an\n\t\t * external, so the builder will not merge a separate cost send\n\t\t * of the same token into that operation.\n\t\t */\n\t\tconst costUsesSendToken = costAmount > 0n && costToken.comparePublicKey(request.from);\n\n\t\tif (costAmount > 0n && !costUsesSendToken) {\n\t\t\tbuilder.send(liquidityProvider, costAmount, costToken);\n\t\t}\n\n\t\tbuilder.receive(liquidityProvider, receiveAmount, request.to, request.affinity === 'to');\n\n\t\t/*\n\t\t * Tag the principal send with an anchor external naming the FX\n\t\t * provider and a client-chosen correlation id.\n\t\t */\n\t\tconst correlationId = crypto.randomUUID();\n\t\tconst externalBuilder = new AnchorExternalBuilder().setAnchor(liquidityProvider, { transactionId: correlationId });\n\t\tfor (const inputReference of options?.inputs ?? []) {\n\t\t\texternalBuilder.addInput(inputReference.blockHash, inputReference.operationIndex);\n\t\t}\n\n\t\tconst external = await externalBuilder.build();\n\t\tconst taggedSendAmount = costUsesSendToken ? sendAmount + costAmount : sendAmount;\n\t\tbuilder.send(liquidityProvider, taggedSendAmount, request.from, external);\n\n\t\tconst blocks = await builder.computeBlocks();\n\t\tif (blocks.blocks.length !== 1) {\n\t\t\tthrow(new Error('Creating Swap Generated more than 1 block'));\n\t\t}\n\t\tconst swapBlock = blocks.blocks[0];\n\t\tif (swapBlock === undefined) {\n\t\t\tthrow(new Error('User Swap Block is undefined'));\n\t\t}\n\n\t\treturn(swapBlock);\n\t}\n\n\tasync createExchange(input: { quote: KeetaFXAnchorQuote } | { estimate: KeetaFXAnchorEstimate; }, block?: InstanceType<typeof KeetaNetLib.Block>, options?: KeetaFXAnchorCreateExchangeOptions): Promise<KeetaFXAnchorExchange> {\n\t\tconst request = this.#bindConversion('quote' in input ? input.quote.request : input.estimate.request);\n\t\tif (block !== undefined && options?.limits !== undefined) {\n\t\t\tthrow(new KeetaAnchorUserError('createExchange applies limits only to a block it builds, not to a given block'));\n\t\t}\n\n\t\tconst swapBlock = block ?? await this.#buildSwapBlock(input, options);\n\n\t\tlet bodyAdditionalData: { quote: KeetaFXAnchorQuote; } | { request: ConversionInputCanonical; };\n\n\t\tif ('quote' in input) {\n\t\t\tbodyAdditionalData = { quote: { ...input.quote, request }};\n\t\t} else {\n\t\t\tbodyAdditionalData = { request };\n\t\t}\n\n\t\tconst serviceURL = await this.#getEndpoint('createExchange');\n\t\tconst requestInformation = await fetch(serviceURL, {\n\t\t\tmethod: 'POST',\n\t\t\theaders: {\n\t\t\t\t'Content-Type': 'application/json',\n\t\t\t\t'Accept': 'application/json'\n\t\t\t},\n\t\t\tbody: JSON.stringify({\n\t\t\t\trequest: {\n\t\t\t\t\t...(KeetaNetLib.Utils.Conversion.toJSONSerializable(bodyAdditionalData)),\n\t\t\t\t\tblock: Buffer.from(swapBlock.toBytes()).toString('base64')\n\t\t\t\t}\n\t\t\t})\n\t\t});\n\n\t\tconst exchange = await this.#parseExchangeResponse(await requestInformation.json(), swapBlock);\n\t\tthis.logger?.debug(`FX exchange request successful, to provider ${serviceURL} for ${swapBlock.hash.toString()}`);\n\t\treturn(exchange);\n\t}\n\n\tasync #parseExchangeResponse(requestInformationJSON: unknown, swapBlock: InstanceType<typeof KeetaNetLib.Block>): Promise<KeetaFXAnchorExchange> {\n\t\t// Ensure status defaults to 'completed' if not provided (for backward compatibility)\n\t\tif (typeof requestInformationJSON === 'object' && requestInformationJSON !== null && !('status' in requestInformationJSON)) {\n\t\t\tObject.assign(requestInformationJSON, { status: 'completed' });\n\t\t\tObject.assign(requestInformationJSON, { blockhash: swapBlock.hash.toString() });\n\t\t}\n\n\t\t// Validate response\n\t\tif (!isKeetaFXAnchorExchangeResponse(requestInformationJSON)) {\n\t\t\tthrow(new Error(`Invalid response from FX exchange service: ${JSON.stringify(requestInformationJSON)}`));\n\t\t}\n\n\t\tif (!requestInformationJSON.ok) {\n\t\t\tthrow(await this.#parseResponseError(requestInformationJSON));\n\t\t}\n\n\t\treturn(requestInformationJSON);\n\t}\n\n\tasync getMarketPrices(request: KeetaFXAnchorMarketPricesRequest): Promise<KeetaFXAnchorMarketPrices> {\n\t\tconst serviceURL = await this.#getEndpoint('getMarketPrices');\n\t\tserviceURL.searchParams.set('quoteAssets', request.quoteAssets.join(','));\n\t\tserviceURL.searchParams.set('base', request.base);\n\n\t\tconst requestInformation = await fetch(serviceURL, {\n\t\t\tmethod: 'GET',\n\t\t\theaders: {\n\t\t\t\t'Accept': 'application/json'\n\t\t\t}\n\t\t});\n\n\t\tconst requestInformationJSON: unknown = await requestInformation.json();\n\t\tif (!isKeetaFXAnchorMarketPricesResponse(requestInformationJSON)) {\n\t\t\tthrow(new Error(`Invalid response from FX market prices service: ${JSON.stringify(requestInformationJSON)}`));\n\t\t}\n\n\t\tif (!requestInformationJSON.ok) {\n\t\t\tthrow(await this.#parseResponseError(requestInformationJSON));\n\t\t}\n\n\t\tthis.logger?.debug(`FX market prices request successful, to provider ${serviceURL} for quoteAssets=${request.quoteAssets.join(',')} base=${request.base}`);\n\t\treturn({\n\t\t\tbase: requestInformationJSON.base,\n\t\t\tquoteAssets: requestInformationJSON.quoteAssets\n\t\t});\n\t}\n\n\tasync getExchangeStatus(exchangeID: string): Promise<KeetaFXAnchorExchange> {\n\t\tconst serviceURL = await this.#getEndpoint('getExchangeStatus', { id: exchangeID });\n\t\tconst requestInformation = await fetch(serviceURL, {\n\t\t\tmethod: 'GET',\n\t\t\theaders: {\n\t\t\t\t'Accept': 'application/json'\n\t\t\t}\n\t\t});\n\n\t\tconst requestInformationJSON: unknown = await requestInformation.json();\n\t\tif (!isKeetaFXAnchorExchangeResponse(requestInformationJSON)) {\n\t\t\tthrow(new Error(`Invalid response from FX exchange status service: ${JSON.stringify(requestInformationJSON)}`));\n\t\t}\n\n\t\tif (!requestInformationJSON.ok) {\n\t\t\tthrow(await this.#parseResponseError(requestInformationJSON));\n\t\t}\n\n\t\tthis.logger?.debug(`FX exchange status request successful, to provider ${serviceURL} for ${exchangeID}`);\n\t\treturn(requestInformationJSON);\n\t}\n\n\t/** @internal */\n\t_internals(accessToken: symbol) {\n\t\tif (accessToken !== KeetaFXAnchorClientAccessToken) {\n\t\t\tthrow(new Error('invalid access token'));\n\t\t}\n\n\t\treturn({\n\t\t\tparent: this.parent\n\t\t});\n\t}\n}\n\n/*\n * Various classes for the state machine:\n * Estimate(optional) -> Quote(optional) -> Exchange -> ExchangeStatus\n */\nclass KeetaFXAnchorExchangeWithProvider {\n\treadonly provider: KeetaFXAnchorProviderBase;\n\treadonly exchange: KeetaFXAnchorExchange\n\n\tconstructor(provider: KeetaFXAnchorProviderBase, exchange: KeetaFXAnchorExchange) {\n\t\tthis.provider = provider;\n\t\tthis.exchange = exchange;\n\t}\n\n\tasync getExchangeStatus(): Promise<KeetaFXAnchorExchange> {\n\t\t/* XXX:TODO: This should return something useful -- right now it just returns the exchange ID... */\n\t\treturn(await this.provider.getExchangeStatus(this.exchange.exchangeID));\n\t}\n}\n\ninterface CanCreateExchange {\n\treadonly isQuote: boolean;\n\n\tget request(): ConversionInputCanonical;\n\n\tcreateExchange(block?: InstanceType<typeof KeetaNetLib.Block>, options?: KeetaFXAnchorCreateExchangeOptions): Promise<KeetaFXAnchorExchangeWithProvider>;\n\n\tcheckExchange(options?: Pick<KeetaFXAnchorCreateExchangeOptions, 'limits'>): void;\n}\n\nclass KeetaFXAnchorQuoteWithProvider implements CanCreateExchange {\n\treadonly provider: KeetaFXAnchorProviderBase;\n\treadonly quote: KeetaFXAnchorQuote;\n\treadonly isQuote = true as const;\n\n\tconstructor(provider: KeetaFXAnchorProviderBase, quote: KeetaFXAnchorQuote) {\n\t\tthis.provider = provider;\n\t\tthis.quote = quote;\n\t}\n\n\tget request(): ConversionInputCanonical {\n\t\treturn(this.quote.request);\n\t}\n\n\tasync createExchange(block?: InstanceType<typeof KeetaNetLib.Block>, options?: KeetaFXAnchorCreateExchangeOptions): Promise<KeetaFXAnchorExchangeWithProvider> {\n\t\tconst exchange = await this.provider.createExchange({ quote: this.quote }, block, options);\n\t\treturn(new KeetaFXAnchorExchangeWithProvider(this.provider, exchange));\n\t}\n\n\t/**\n\t * Checks this quote's terms as `createExchange` would, without\n\t * signing. See {@link KeetaFXAnchorProviderBase.checkExchange}.\n\t */\n\tcheckExchange(options?: Pick<KeetaFXAnchorCreateExchangeOptions, 'limits'>): void {\n\t\tthis.provider.checkExchange({ quote: this.quote }, options);\n\t}\n\n\t/**\n\t * Re-fetch the quote from the provider.\n\t *\n\t * @returns a new KeetaFXAnchorQuoteWithProvider with the updated quote\n\t */\n\tasync refetch(): Promise<KeetaFXAnchorQuoteWithProvider> {\n\t\tconst quote = await this.provider.getQuote();\n\t\treturn(new KeetaFXAnchorQuoteWithProvider(this.provider, quote));\n\t}\n}\n\nclass KeetaFXAnchorEstimateWithProvider implements CanCreateExchange {\n\treadonly provider: KeetaFXAnchorProviderBase;\n\treadonly estimate: KeetaFXAnchorEstimate;\n\treadonly isQuote = false as const;\n\n\tconstructor(provider: KeetaFXAnchorProviderBase, estimate: KeetaFXAnchorEstimate) {\n\t\tthis.provider = provider;\n\t\tthis.estimate = estimate;\n\t}\n\n\tget request(): ConversionInputCanonical {\n\t\treturn(this.estimate.request);\n\t}\n\n\tasync getQuote(tolerance?: number): Promise<KeetaFXAnchorQuoteWithProvider> {\n\t\tconst quote = await this.provider.getQuote(this.estimate, tolerance);\n\t\treturn(new KeetaFXAnchorQuoteWithProvider(this.provider, quote));\n\t}\n\n\tasync createExchange(block?: InstanceType<typeof KeetaNetLib.Block>, options?: KeetaFXAnchorCreateExchangeOptions): Promise<KeetaFXAnchorExchangeWithProvider> {\n\t\tconst exchange = await this.provider.createExchange({ estimate: this.estimate }, block, options);\n\t\treturn(new KeetaFXAnchorExchangeWithProvider(this.provider, exchange));\n\t}\n\n\t/**\n\t * Checks this estimate's terms as `createExchange` would, without\n\t * signing. See {@link KeetaFXAnchorProviderBase.checkExchange}.\n\t */\n\tcheckExchange(options?: Pick<KeetaFXAnchorCreateExchangeOptions, 'limits'>): void {\n\t\tthis.provider.checkExchange({ estimate: this.estimate }, options);\n\t}\n\n\t/**\n\t * Re-fetch the estimate from the provider.\n\t *\n\t * @returns a new KeetaFXAnchorEstimateWithProvider with the updated estimate\n\t */\n\tasync refetch(): Promise<KeetaFXAnchorEstimateWithProvider> {\n\t\tconst estimate = await this.provider.getEstimate();\n\t\treturn(new KeetaFXAnchorEstimateWithProvider(this.provider, estimate));\n\t}\n}\n\ninterface GetProvidersOptions extends AccountOptions {\n\trequiredOperations?: (keyof KeetaFXAnchorOperations)[];\n}\n\ninterface GetPricesAssetReturnValue {\n\tvalue: bigint;\n\taverageConvertedAmount: number;\n\tproviderMarketPrices: {\n\t\tprovider: KeetaFXAnchorProviderBase;\n\t\tprice: KeetaFXAnchorMarketPriceRatio;\n\t}[];\n\tproviderEstimates: KeetaFXAnchorEstimateWithProvider[];\n}\n\nfunction providerSupportsGetMarketPrices(provider: KeetaFXAnchorProviderBase): boolean {\n\treturn(Object.prototype.hasOwnProperty.call(provider.serviceInfo.operations, 'getMarketPrices'));\n}\n\nfunction convertUsingMarketPriceRatio(\n\tratio: KeetaFXAnchorMarketPriceRatio,\n\tconversionValue: bigint,\n\taffinity: 'from' | 'to'\n): bigint {\n\tconst quote = BigInt(ratio.quote);\n\tconst base = BigInt(ratio.base);\n\tif (quote === 0n || base === 0n) {\n\t\tthrow(new Error(`Invalid market price ratio: quote=${ratio.quote} base=${ratio.base}`));\n\t}\n\n\tif (affinity === 'from') {\n\t\treturn(conversionValue * base / quote);\n\t}\n\n\treturn(conversionValue * quote / base);\n}\n\nexport interface GetPricesArgs<Asset extends ConversionInput['from']> {\n\tassets: Asset[],\n\tpriceIn: ConversionInput['from'],\n\tconversionValue?: bigint | ((input: Asset) => bigint | Promise<bigint>)\n\tconversionAffinity?: ConversionInput['affinity']\n\t/**\n\t * Behavior when a provider returns an invalid market price ratio\n\t * (e.g. zero quote/base). Defaults to `'omit'`.\n\t *\n\t * Invalid ratios are always logged regardless of this setting.\n\t */\n\tonInvalidRatio?: 'omit' | 'throw';\n}\n\nclass KeetaFXAnchorClient extends KeetaFXAnchorBase {\n\treadonly resolver: Resolver;\n\treadonly id: string;\n\treadonly #signer: InstanceType<typeof KeetaNetLib.Account>;\n\treadonly #account: InstanceType<typeof KeetaNetLib.Account>;\n\treadonly #getPricesBatching: Required<KeetaFXAnchorClientGetPricesBatching>;\n\treadonly #defaultLimits: ResolvedDefaultLimits;\n\treadonly #pendingGetMarketPricesBatches = new Map<string, {\n\t\tprovider: KeetaFXAnchorProviderBase;\n\t\tbase: KeetaNetTokenPublicKeyString;\n\t\tquoteAssets: Set<KeetaNetTokenPublicKeyString>;\n\t\twaiters: {\n\t\t\tresolve: (prices: KeetaFXAnchorMarketPrices) => void;\n\t\t\treject: (error: unknown) => void;\n\t\t}[];\n\t\twaitTimer: ReturnType<typeof setTimeout> | null;\n\t\tmaxWaitTimer: ReturnType<typeof setTimeout> | null;\n\t}>();\n\n\tstatic #resolveGetPricesBatching(input?: KeetaFXAnchorClientGetPricesBatching | boolean): Required<KeetaFXAnchorClientGetPricesBatching> {\n\t\tif (input === false) {\n\t\t\treturn({ waitMs: 0, maxWaitMs: 0 });\n\t\t} else {\n\t\t\tif (input === true || input === undefined) {\n\t\t\t\tinput = { waitMs: 25 }\n\t\t\t}\n\n\t\t\treturn({\n\t\t\t\twaitMs: input.waitMs,\n\t\t\t\tmaxWaitMs: input.maxWaitMs ?? (input.waitMs * 4)\n\t\t\t});\n\t\t}\n\t}\n\n\tconstructor(client: KeetaNetUserClient, config: KeetaFXAnchorClientConfig = {}) {\n\t\tsuper({ client, logger: config.logger });\n\t\tthis.resolver = config.resolver ?? getDefaultResolver(client, config);\n\t\tthis.id = config.id ?? crypto.randomUUID();\n\t\tthis.#getPricesBatching = KeetaFXAnchorClient.#resolveGetPricesBatching(config.getPricesBatching);\n\t\tthis.#defaultLimits = resolveDefaultLimits(config.defaultLimits);\n\n\t\tif (!Number.isFinite(this.#getPricesBatching.waitMs) || this.#getPricesBatching.waitMs < 0) {\n\t\t\tthrow(new Error('getPricesBatching.waitMs must be a non-negative finite number'));\n\t\t}\n\t\tif (!Number.isFinite(this.#getPricesBatching.maxWaitMs) || this.#getPricesBatching.maxWaitMs < 0) {\n\t\t\tthrow(new Error('getPricesBatching.maxWaitMs must be a non-negative finite number'));\n\t\t}\n\t\tif (this.#getPricesBatching.maxWaitMs < this.#getPricesBatching.waitMs) {\n\t\t\tthrow(new Error('getPricesBatching.maxWaitMs must be greater than or equal to waitMs'));\n\t\t}\n\n\t\tif (config.signer) {\n\t\t\tthis.#signer = config.signer;\n\t\t} else if ('signer' in client && client.signer !== null) {\n\t\t\tthis.#signer = client.signer;\n\t\t} else if ('account' in client && client.account.hasPrivateKey) {\n\t\t\tthis.#signer = client.account;\n\t\t} else {\n\t\t\tthrow(new Error('KeetaFXAnchorClient requires a Signer or a UserClient with an associated Signer'));\n\t\t}\n\n\t\tif (config.account) {\n\t\t\tthis.#account = config.account;\n\t\t} else if ('account' in client) {\n\t\t\tthis.#account = client.account;\n\t\t} else {\n\t\t\tthrow(new Error('KeetaFXAnchorClient requires an Account or a UserClient with an associated Account'));\n\t\t}\n\t}\n\n\t#getMarketPricesBatchKey(providerID: ProviderID, base: KeetaNetTokenPublicKeyString): string {\n\t\treturn(`${String(providerID)}\\0${base}`);\n\t}\n\n\t#flushGetMarketPricesBatch(batchKey: string) {\n\t\tconst batch = this.#pendingGetMarketPricesBatches.get(batchKey);\n\t\tif (batch === undefined) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.#pendingGetMarketPricesBatches.delete(batchKey);\n\t\tif (batch.waitTimer !== null) {\n\t\t\tclearTimeout(batch.waitTimer);\n\t\t}\n\t\tif (batch.maxWaitTimer !== null) {\n\t\t\tclearTimeout(batch.maxWaitTimer);\n\t\t}\n\n\t\tconst quoteAssets = [...batch.quoteAssets];\n\t\tbatch.provider.getMarketPrices({ quoteAssets, base: batch.base }).then(function(marketPrices) {\n\t\t\tfor (const waiter of batch.waiters) {\n\t\t\t\twaiter.resolve(marketPrices);\n\t\t\t}\n\t\t}, function(error: unknown) {\n\t\t\tfor (const waiter of batch.waiters) {\n\t\t\t\twaiter.reject(error);\n\t\t\t}\n\t\t});\n\t}\n\n\t#getMarketPricesBatched(provider: KeetaFXAnchorProviderBase, request: KeetaFXAnchorMarketPricesRequest): Promise<KeetaFXAnchorMarketPrices> {\n\t\tconst batching = this.#getPricesBatching;\n\t\tif (batching.waitMs === 0 && batching.maxWaitMs === 0) {\n\t\t\treturn(provider.getMarketPrices(request));\n\t\t}\n\n\t\tconst batchKey = this.#getMarketPricesBatchKey(provider.providerID, request.base);\n\t\tlet batch = this.#pendingGetMarketPricesBatches.get(batchKey);\n\t\tif (batch === undefined) {\n\t\t\tbatch = {\n\t\t\t\tprovider,\n\t\t\t\tbase: request.base,\n\t\t\t\tquoteAssets: new Set(),\n\t\t\t\twaiters: [],\n\t\t\t\twaitTimer: null,\n\t\t\t\tmaxWaitTimer: null\n\t\t\t};\n\t\t\tthis.#pendingGetMarketPricesBatches.set(batchKey, batch);\n\n\t\t\tbatch.maxWaitTimer = setTimeout(() => {\n\t\t\t\tthis.#flushGetMarketPricesBatch(batchKey);\n\t\t\t}, batching.maxWaitMs);\n\t\t}\n\n\t\tfor (const quoteAsset of request.quoteAssets) {\n\t\t\tbatch.quoteAssets.add(quoteAsset);\n\t\t}\n\n\t\tconst activeBatch = batch;\n\t\tconst result = new Promise<KeetaFXAnchorMarketPrices>(function(resolve, reject) {\n\t\t\tactiveBatch.waiters.push({ resolve, reject });\n\t\t});\n\n\t\tif (activeBatch.waitTimer !== null) {\n\t\t\tclearTimeout(activeBatch.waitTimer);\n\t\t}\n\n\t\tif (batching.waitMs === 0) {\n\t\t\tthis.#flushGetMarketPricesBatch(batchKey);\n\t\t} else {\n\t\t\tactiveBatch.waitTimer = setTimeout(() => {\n\t\t\t\tthis.#flushGetMarketPricesBatch(batchKey);\n\t\t\t}, batching.waitMs);\n\t\t}\n\n\t\treturn(result);\n\t}\n\n\tprivate async canonicalizeConversionTokens(input: Partial<ConversionInput>): Promise<Partial<Pick<ConversionInputCanonical, 'from' | 'to'>>> {\n\t\tlet from = {}\n\t\tif (input.from !== undefined) {\n\t\t\tlet fromToken: ConversionInputCanonical['from'];\n\t\t\tif (KeetaNetLib.Account.isInstance(input.from) && input.from.isToken()) {\n\t\t\t\tfromToken = input.from;\n\t\t\t} else {\n\t\t\t\tconst tokenLookup = await this.resolver.lookupToken(input.from);\n\t\t\t\tif (tokenLookup === null) {\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-base-to-string\n\t\t\t\t\tthrow(new Error(`Could not convert from: ${input.from} to a token address`));\n\t\t\t\t}\n\t\t\t\tfromToken = KeetaNetLib.Account.fromPublicKeyString(tokenLookup.token);\n\t\t\t}\n\t\t\tfrom = { from: fromToken };\n\t\t}\n\n\t\tlet to = {};\n\t\tif (input.to !== undefined) {\n\t\t\tlet toToken: ConversionInputCanonical['to'];\n\t\t\tif (KeetaNetLib.Account.isInstance(input.to) && input.to.isToken()) {\n\t\t\t\ttoToken = input.to;\n\t\t\t} else {\n\t\t\t\tconst tokenLookup = await this.resolver.lookupToken(input.to);\n\t\t\t\tif (tokenLookup === null) {\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-base-to-string\n\t\t\t\t\tthrow(new Error(`Could not convert to: ${input.to} to a token address`));\n\t\t\t\t}\n\t\t\t\ttoToken = KeetaNetLib.Account.fromPublicKeyString(tokenLookup.token);\n\t\t\t}\n\t\t\tto = { to: toToken };\n\t\t}\n\t\treturn({ ...from, ...to });\n\t}\n\n\tprivate async canonicalizeConversionInput(input: ConversionInput): Promise<ConversionInputCanonical> {\n\t\tconst amount = BigInt(input.amount);\n\t\tif (amount < 0) {\n\t\t\tthrow(new Error('Invalid Conversion Amount'));\n\t\t}\n\n\t\tconst { from, to } = await this.canonicalizeConversionTokens(input);\n\n\t\tif (from === undefined || to === undefined) {\n\t\t\tthrow(new Error('From and To are both required for a conversion'));\n\t\t}\n\n\t\tconst canonical: ConversionInputCanonical = {\n\t\t\tfrom,\n\t\t\tto,\n\t\t\tamount: amount,\n\t\t\taffinity: input.affinity\n\t\t};\n\n\t\tif (input.preferredCostAsset !== undefined) {\n\t\t\tcanonical.preferredCostAsset = input.preferredCostAsset;\n\t\t}\n\n\t\treturn(canonical);\n\t}\n\n\tasync listPossibleConversions(input: Partial<Pick<ConversionInput, 'from' | 'to'>>, options: AccountOptions = {}, sharedCriteria?: SharedLookupCriteria): Promise<{ conversions: KeetaNetTokenPublicKeyString[] } | null> {\n\t\tif (input.from !== undefined && input.to !== undefined) {\n\t\t\tthrow(new KeetaAnchorUserError('Only one of from or two should be provided'));\n\t\t}\n\t\tif (input.from === undefined && input.to === undefined) {\n\t\t\tthrow(new KeetaAnchorUserError('At least one of from or two should be provided'));\n\t\t}\n\t\tconst conversion = await this.canonicalizeConversionTokens(input);\n\t\tconst account = options.account ?? this.#account;\n\t\tconst providerEndpoints = await getEndpoints(this.resolver, conversion, account, sharedCriteria, { logger: this.logger });\n\t\tif (providerEndpoints === null) {\n\t\t\treturn(null);\n\t\t}\n\n\t\tconst conversions = new Set<KeetaNetTokenPublicKeyString>();\n\t\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\t\tfor (const [_ignored_providerID, serviceInfo] of typedFxServiceEntries(providerEndpoints)) {\n\t\t\tfor (const conversionPair of serviceInfo.from) {\n\t\t\t\tif (conversion.from !== undefined) {\n\t\t\t\t\tif (conversionPair.currencyCodes.includes(conversion.from.publicKeyString.get())) {\n\t\t\t\t\t\tconversionPair.to.forEach((token) => {\n\t\t\t\t\t\t\tif (conversion.from?.publicKeyString.get() !== token) {\n\t\t\t\t\t\t\t\tconversions.add(token);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t} else if (conversion.to !== undefined) {\n\t\t\t\t\tif (conversionPair.to.includes(conversion.to.publicKeyString.get())) {\n\t\t\t\t\t\tconversionPair.currencyCodes.forEach((token) => {\n\t\t\t\t\t\t\tif (conversion.to?.publicKeyString.get() !== token) {\n\t\t\t\t\t\t\t\tconversions.add(token);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\n\t\treturn({ conversions: [...conversions] });\n\t}\n\n\tasync getBaseProvidersForConversion(request: ConversionInput, options: GetProvidersOptions = {}, sharedCriteria?: SharedLookupCriteria): Promise<KeetaFXAnchorProviderBase[] | null> {\n\t\tconst conversion = await this.canonicalizeConversionInput(request);\n\t\tconst account = options.account ?? this.#account;\n\t\tconst providerEndpoints = await getEndpoints(this.resolver, conversion, account, sharedCriteria, { logger: this.logger });\n\t\tif (providerEndpoints === null) {\n\t\t\treturn(null);\n\t\t}\n\n\t\tconst providers = typedFxServiceEntries(providerEndpoints).map(([providerID, serviceInfo]) => {\n\t\t\treturn(new KeetaFXAnchorProviderBase(serviceInfo, providerID, conversion, this, options));\n\t\t});\n\n\t\treturn(providers);\n\t}\n\n\t/**\n\t * Resolve an FX provider by the account that signs its advertised service metadata.\n\t */\n\tasync getProviderByAccount(anchor: AnchorReference, requiredOperations?: (keyof KeetaFXAnchorOperations)[]): Promise<KeetaFXAnchorProviderBase | null> {\n\t\tconst request: Parameters<typeof getEndpoints>[1] = {};\n\t\tif (requiredOperations !== undefined) {\n\t\t\trequest.requiredOperations = requiredOperations;\n\t\t}\n\n\t\tconst providerEndpoints = await getEndpoints(this.resolver, request, this.#account, { accounts: [ anchor ] }, { logger: this.logger });\n\t\tif (providerEndpoints === null) {\n\t\t\treturn(null);\n\t\t}\n\n\t\tconst [ entry ] = typedFxServiceEntries(providerEndpoints);\n\t\tif (entry === undefined) {\n\t\t\treturn(null);\n\t\t}\n\n\t\tconst [ providerID, serviceInfo ] = entry;\n\n\t\tconst pair = serviceInfo.from[0];\n\t\tif (pair === undefined) {\n\t\t\treturn(null);\n\t\t}\n\n\t\tconst fromCode = pair.currencyCodes[0];\n\t\tconst toCode = pair.to[0];\n\t\tif (fromCode === undefined || toCode === undefined) {\n\t\t\treturn(null);\n\t\t}\n\n\t\tconst conversion: ConversionInputCanonical = {\n\t\t\tfrom: KeetaNetLib.Account.fromPublicKeyString(fromCode),\n\t\t\tto: KeetaNetLib.Account.fromPublicKeyString(toCode),\n\t\t\tamount: 0n,\n\t\t\taffinity: 'from'\n\t\t};\n\n\t\tconst provider = new KeetaFXAnchorProviderBase(serviceInfo, providerID, conversion, this);\n\t\treturn(provider);\n\t}\n\n\tasync getEstimates(request: ConversionInput, options: Omit<GetProvidersOptions, 'requiredOperations'> = {}, sharedCriteria?: SharedLookupCriteria): Promise<KeetaFXAnchorEstimateWithProvider[] | null> {\n\t\tconst estimateProviders = await this.getBaseProvidersForConversion(request, {\n\t\t\t...options,\n\t\t\trequiredOperations: ['getEstimate']\n\t\t}, sharedCriteria);\n\n\t\tif (estimateProviders === null) {\n\t\t\treturn(null);\n\t\t}\n\n\t\tconst estimates = await Promise.all(estimateProviders.map(async (provider) => {\n\t\t\ttry {\n\t\t\t\tconst estimate = await provider.getEstimate();\n\n\t\t\t\treturn(new KeetaFXAnchorEstimateWithProvider(provider, estimate));\n\t\t\t} catch (error) {\n\t\t\t\tif (FXErrors.ResponseMismatch.isInstance(error)) {\n\t\t\t\t\tthis.logger?.warn(`Ignoring estimate from FX provider ${String(provider.providerID)}:`, error);\n\t\t\t\t} else {\n\t\t\t\t\tthis.logger?.error(`Failed to get estimate from provider ${String(provider.providerID)}:`, error);\n\t\t\t\t}\n\n\t\t\t\treturn(null);\n\t\t\t}\n\t\t}));\n\n\t\tconst results = estimates.filter(function(result) {\n\t\t\treturn(result !== null);\n\t\t});\n\n\t\tif (results.length === 0) {\n\t\t\treturn(null);\n\t\t}\n\n\t\treturn(results);\n\t}\n\n\tasync #multiRequestQuotes(request: ConversionInput, options: AccountOptions = {}, sharedCriteria?: SharedLookupCriteria): Promise<({\n\t\tprovider: KeetaFXAnchorProviderBase;\n\t} & ({\n\t\tquote: KeetaFXAnchorQuoteWithProvider;\n\t} | {\n\t\tquote: null;\n\t\terror: unknown;\n\t}))[]> {\n\t\tconst estimateProviders = await this.getBaseProvidersForConversion(request, {\n\t\t\t...options,\n\t\t\trequiredOperations: ['getQuote']\n\t\t}, sharedCriteria);\n\t\tif (estimateProviders === null) {\n\t\t\treturn([]);\n\t\t}\n\n\t\treturn(await Promise.all(estimateProviders.map(async (provider) => {\n\t\t\ttry {\n\t\t\t\tconst quote = await provider.getQuote();\n\t\t\t\treturn({ provider, quote: new KeetaFXAnchorQuoteWithProvider(provider, quote) });\n\t\t\t} catch (error) {\n\t\t\t\tif (FXErrors.ResponseMismatch.isInstance(error)) {\n\t\t\t\t\tthis.logger?.warn(`Ignoring quote from FX provider ${String(provider.providerID)}:`, error);\n\t\t\t\t}\n\n\t\t\t\treturn({ provider, quote: null, error });\n\t\t\t}\n\t\t})));\n\t}\n\n\n\tasync getQuotes(request: ConversionInput, options: AccountOptions = {}, sharedCriteria?: SharedLookupCriteria): Promise<KeetaFXAnchorQuoteWithProvider[] | null> {\n\t\tconst quotes = await this.#multiRequestQuotes(request, options, sharedCriteria);\n\n\t\tconst results = quotes\n\t\t\t.map(function(quote) {\n\t\t\t\treturn(quote.quote);\n\t\t\t})\n\t\t\t.filter(function(quote): quote is KeetaFXAnchorQuoteWithProvider {\n\t\t\t\treturn(quote !== null);\n\t\t\t});\n\n\t\tif (results.length === 0) {\n\t\t\treturn(null);\n\t\t}\n\n\t\treturn(results);\n\t}\n\n\tasync getQuotesOrEstimates(request: ConversionInput, options: AccountOptions = {}, sharedCriteria?: SharedLookupCriteria): Promise<(KeetaFXAnchorQuoteWithProvider | KeetaFXAnchorEstimateWithProvider)[] | null> {\n\t\tconst [ quotesAndEstimates, estimateProviders ] = await Promise.all([\n\t\t\tthis.#multiRequestQuotes(request, options, sharedCriteria),\n\t\t\tthis.getBaseProvidersForConversion(request, {\n\t\t\t\t...options,\n\t\t\t\trequiredOperations: ['getEstimate']\n\t\t\t}, sharedCriteria)\n\t\t]);\n\n\t\tconst estimateProviderIDs = new Set<ProviderID>();\n\n\t\tif (estimateProviders !== null) {\n\t\t\tfor (const provider of estimateProviders) {\n\t\t\t\testimateProviderIDs.add(provider.providerID);\n\t\t\t}\n\t\t}\n\n\t\tconst retval = [];\n\n\t\tfor (const quoteOrEstimate of quotesAndEstimates) {\n\t\t\tif (!quoteOrEstimate.quote) {\n\t\t\t\tif (quoteOrEstimate.error && !FXErrors.QuoteIssuanceDisabled.isInstance(quoteOrEstimate.error)) {\n\t\t\t\t\tthis.logger?.debug(`Failed to get quote from provider ${String(quoteOrEstimate.provider.providerID)}:`, quoteOrEstimate.error);\n\t\t\t\t}\n\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tretval.push(quoteOrEstimate.quote);\n\t\t\testimateProviderIDs.delete(quoteOrEstimate.provider.providerID);\n\t\t}\n\n\t\tconst estimates = await this.getEstimates(request, options, {\n\t\t\t...sharedCriteria,\n\t\t\tproviderIDs: Array.from(estimateProviderIDs).map(function(id) {\n\t\t\t\treturn(String(id));\n\t\t\t})\n\t\t});\n\n\t\tif (estimates !== null) {\n\t\t\tretval.push(...estimates);\n\t\t}\n\n\t\tif (retval.length === 0) {\n\t\t\treturn(null);\n\t\t}\n\n\t\treturn(retval);\n\t}\n\n\tasync getPrices<Asset extends ConversionInput['from']>(input: GetPricesArgs<Asset>, options: Omit<GetProvidersOptions, 'requiredOperations'> = {}, sharedCriteria?: SharedLookupCriteria): Promise<Map<Asset, GetPricesAssetReturnValue | null>> {\n\t\tconst priceInCanonical = await this.canonicalizeConversionTokens({ to: input.priceIn ?? 'USD' });\n\t\tif (priceInCanonical.to === undefined) {\n\t\t\tthrow(new Error('Could not canonicalize priceIn asset'));\n\t\t}\n\n\t\tconst base = priceInCanonical.to.publicKeyString.get();\n\t\tconst affinity = input.conversionAffinity ?? 'from';\n\t\tconst priceIn = input.priceIn ?? 'USD';\n\t\tconst onInvalidRatio = input.onInvalidRatio ?? 'omit';\n\n\t\tconst assetEntries = await Promise.all(input.assets.map(async (asset) => {\n\t\t\tconst canonical = await this.canonicalizeConversionTokens({ from: asset });\n\t\t\tif (canonical.from === undefined) {\n\t\t\t\tthrow(new Error(`Could not canonicalize asset: ${String(asset)}`));\n\t\t\t}\n\n\t\t\tlet conversionValue: bigint;\n\t\t\tif (input.conversionValue !== undefined) {\n\t\t\t\tif (typeof input.conversionValue === 'function') {\n\t\t\t\t\tconversionValue = await input.conversionValue(asset);\n\t\t\t\t} else {\n\t\t\t\t\tconversionValue = input.conversionValue;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tconversionValue = 1n;\n\t\t\t}\n\n\t\t\tconst providers = await this.getBaseProvidersForConversion({\n\t\t\t\tfrom: asset,\n\t\t\t\tto: priceIn,\n\t\t\t\tamount: conversionValue,\n\t\t\t\taffinity\n\t\t\t}, options, sharedCriteria);\n\n\t\t\treturn({\n\t\t\t\tasset,\n\t\t\t\tquoteAsset: canonical.from.publicKeyString.get(),\n\t\t\t\tconversionValue,\n\t\t\t\tproviders\n\t\t\t});\n\t\t}));\n\n\t\ttype ProviderAssetEntry = {\n\t\t\tasset: Asset;\n\t\t\tquoteAsset: KeetaNetTokenPublicKeyString;\n\t\t\tconversionValue: bigint;\n\t\t\tprovider: KeetaFXAnchorProviderBase;\n\t\t};\n\n\t\ttype EstimateAssetEntry = {\n\t\t\tasset: Asset;\n\t\t\tconversionValue: bigint;\n\t\t\tprovider: KeetaFXAnchorProviderBase;\n\t\t};\n\n\t\tconst providerAssets = new Map<ProviderID, ProviderAssetEntry[]>();\n\t\tconst estimateEntries: EstimateAssetEntry[] = [];\n\t\tfor (const entry of assetEntries) {\n\t\t\tif (entry.providers === null) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tfor (const provider of entry.providers) {\n\t\t\t\tif (providerSupportsGetMarketPrices(provider)) {\n\t\t\t\t\tconst existing = providerAssets.get(provider.providerID) ?? [];\n\t\t\t\t\texisting.push({\n\t\t\t\t\t\tasset: entry.asset,\n\t\t\t\t\t\tquoteAsset: entry.quoteAsset,\n\t\t\t\t\t\tconversionValue: entry.conversionValue,\n\t\t\t\t\t\tprovider\n\t\t\t\t\t});\n\t\t\t\t\tproviderAssets.set(provider.providerID, existing);\n\t\t\t\t} else {\n\t\t\t\t\testimateEntries.push({\n\t\t\t\t\t\tasset: entry.asset,\n\t\t\t\t\t\tconversionValue: entry.conversionValue,\n\t\t\t\t\t\tprovider\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tconst providerPriceResults = await Promise.all([...providerAssets.entries()].map(async ([_ignore_providerID, entries]) => {\n\t\t\tconst firstEntry = entries[0];\n\t\t\tif (firstEntry === undefined) {\n\t\t\t\treturn(null);\n\t\t\t}\n\n\t\t\tconst provider = firstEntry.provider;\n\t\t\tconst quoteAssets = [...new Set(entries.map(function(entry) {\n\t\t\t\treturn(entry.quoteAsset);\n\t\t\t}))];\n\n\t\t\ttry {\n\t\t\t\tconst marketPrices = await this.#getMarketPricesBatched(provider, { quoteAssets, base });\n\t\t\t\treturn({ provider, marketPrices, entries });\n\t\t\t} catch (error) {\n\t\t\t\tthis.logger?.error(`Failed to get market prices from provider ${String(provider.providerID)}:`, error);\n\t\t\t\treturn(null);\n\t\t\t}\n\t\t}));\n\n\t\tconst assetProviderPrices = new Map<Asset, GetPricesAssetReturnValue['providerMarketPrices']>();\n\t\tfor (const result of providerPriceResults) {\n\t\t\tif (result === null) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tfor (const entry of result.entries) {\n\t\t\t\tconst priceEntry = result.marketPrices.quoteAssets[entry.quoteAsset];\n\t\t\t\tif (priceEntry === undefined) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\ttry {\n\t\t\t\t\t// Validate ratio early so convertUsingMarketPriceRatio cannot crash the batch later.\n\t\t\t\t\tconvertUsingMarketPriceRatio(priceEntry.valueRatio, entry.conversionValue, affinity);\n\t\t\t\t} catch (error) {\n\t\t\t\t\tthis.logger?.error(`Invalid market price ratio from provider ${String(result.provider.providerID)} for quote asset ${entry.quoteAsset} against base ${base}:`, error, priceEntry.valueRatio);\n\t\t\t\t\tif (onInvalidRatio === 'throw') {\n\t\t\t\t\t\tthrow(error);\n\t\t\t\t\t}\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tconst prices = assetProviderPrices.get(entry.asset) ?? [];\n\t\t\t\tprices.push({\n\t\t\t\t\tprovider: result.provider,\n\t\t\t\t\tprice: priceEntry.valueRatio\n\t\t\t\t});\n\t\t\t\tassetProviderPrices.set(entry.asset, prices);\n\t\t\t}\n\t\t}\n\n\t\tconst estimateResults = await Promise.all(estimateEntries.map(async (entry) => {\n\t\t\ttry {\n\t\t\t\tconst estimate = await entry.provider.getEstimate();\n\t\t\t\treturn({\n\t\t\t\t\tasset: entry.asset,\n\t\t\t\t\testimate: new KeetaFXAnchorEstimateWithProvider(entry.provider, estimate)\n\t\t\t\t});\n\t\t\t} catch (error) {\n\t\t\t\tthis.logger?.error(`Failed to get estimate from provider ${String(entry.provider.providerID)}:`, error);\n\t\t\t\treturn(null);\n\t\t\t}\n\t\t}));\n\n\t\tconst assetProviderEstimates = new Map<Asset, KeetaFXAnchorEstimateWithProvider[]>();\n\t\tfor (const result of estimateResults) {\n\t\t\tif (result === null) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst estimates = assetProviderEstimates.get(result.asset) ?? [];\n\t\t\testimates.push(result.estimate);\n\t\t\tassetProviderEstimates.set(result.asset, estimates);\n\t\t}\n\n\t\tconst retval = new Map<Asset, GetPricesAssetReturnValue | null>();\n\t\tfor (const entry of assetEntries) {\n\t\t\tconst providerMarketPrices = assetProviderPrices.get(entry.asset) ?? [];\n\t\t\tconst providerEstimates = assetProviderEstimates.get(entry.asset) ?? [];\n\t\t\tif (providerMarketPrices.length === 0 && providerEstimates.length === 0) {\n\t\t\t\tretval.set(entry.asset, null);\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst convertedAmountSum = [\n\t\t\t\t...providerMarketPrices.map(function(providerPrice) {\n\t\t\t\t\treturn(convertUsingMarketPriceRatio(providerPrice.price, entry.conversionValue, affinity));\n\t\t\t\t}),\n\t\t\t\t...providerEstimates.map(function(providerEstimate) {\n\t\t\t\t\treturn(providerEstimate.estimate.convertedAmount);\n\t\t\t\t})\n\t\t\t].reduce(function(sum, convertedAmount) {\n\t\t\t\treturn(sum + convertedAmount);\n\t\t\t}, 0n);\n\n\t\t\tconst providerCount = providerMarketPrices.length + providerEstimates.length;\n\n\t\t\tretval.set(entry.asset, {\n\t\t\t\tvalue: entry.conversionValue,\n\t\t\t\taverageConvertedAmount: Number(convertedAmountSum) / providerCount,\n\t\t\t\tproviderMarketPrices,\n\t\t\t\tproviderEstimates\n\t\t\t});\n\t\t}\n\n\t\treturn(retval);\n\t}\n\n\tasync getLegalDisclaimersById(providerID: string): Promise<NonNullable<AnchorMetadataLegalField['disclaimers']> | null>{\n\t\tconst endpoints = await getEndpoints(this.resolver, {}, this.#account, { providerIDs: [providerID] }, { logger: this.logger });\n\t\tif (endpoints === null) {\n\t\t\treturn(null);\n\t\t}\n\n\t\tconst serviceEntry = typedFxServiceEntries(endpoints)[0];\n\t\tif (!serviceEntry) {\n\t\t\treturn(null);\n\t\t}\n\n\t\tconst disclaimers = serviceEntry[1].legal?.disclaimers;\n\t\tif (!disclaimers || disclaimers.length === 0) {\n\t\t\treturn(null)\n\t\t}\n\n\t\treturn(disclaimers);\n\t}\n\n\tasync getMarketPrices(providerID: string, request: KeetaFXAnchorMarketPricesRequest): Promise<KeetaFXAnchorMarketPrices | null> {\n\t\tconst endpoints = await getEndpoints(this.resolver, {\n\t\t\trequiredOperations: ['getMarketPrices']\n\t\t}, this.#account, { providerIDs: [providerID] }, { logger: this.logger });\n\t\tif (endpoints === null) {\n\t\t\treturn(null);\n\t\t}\n\n\t\tconst serviceEntry = typedFxServiceEntries(endpoints)[0];\n\t\tif (!serviceEntry) {\n\t\t\treturn(null);\n\t\t}\n\n\t\tconst [ resolvedProviderID, serviceInfo ] = serviceEntry;\n\t\tconst provider = new KeetaFXAnchorProviderBase(serviceInfo, resolvedProviderID, {\n\t\t\tfrom: KeetaNetLib.Account.fromPublicKeyString(request.quoteAssets[0] ?? request.base),\n\t\t\tto: KeetaNetLib.Account.fromPublicKeyString(request.base),\n\t\t\tamount: 1n,\n\t\t\taffinity: 'from'\n\t\t}, this);\n\n\t\treturn(await provider.getMarketPrices(request));\n\t}\n\n\t/** @internal */\n\t_internals(accessToken: symbol) {\n\t\tif (accessToken !== KeetaFXAnchorClientAccessToken) {\n\t\t\tthrow(new Error('invalid access token'));\n\t\t}\n\n\t\treturn({\n\t\t\tresolver: this.resolver,\n\t\t\tlogger: this.logger,\n\t\t\tclient: this.client,\n\t\t\tsigner: this.#signer,\n\t\t\taccount: this.#account,\n\t\t\tdefaultLimits: this.#defaultLimits\n\t\t});\n\n\t}\n}\n\nexport default KeetaFXAnchorClient;\n"]}
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/services/fx/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,IAAI,WAAW,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAOrD,OAAO,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AACnD,OAAO,MAAM,MAAM,2BAA2B,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAErD,OAAO,EACN,kCAAkC,EAClC,+BAA+B,EAC/B,+BAA+B,EAC/B,mCAAmC,EACnC,4BAA4B,EAC5B,MAAM,IAAI,QAAQ,EAClB,MAAM,aAAa,CAAC;AAcrB,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAErE,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC5E,OAAO,EAAE,yCAAyC,EAAE,MAAM,6BAA6B,CAAC;AAi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,OAAO,EAAE,IAAI,CAAC,QAAQ;YACtB,aAAa,EAAE,IAAI,CAAC,cAAc;SAClC,CAAC,CAAC;IAEJ,CAAC;CACD;AAED,eAAe,mBAAmB,CAAC","sourcesContent":["import { lib as KeetaNetLib } from '@keetanetwork/keetanet-client';\nimport { getDefaultResolver } from '../../config.js';\nimport type {\n\tUserClient as KeetaNetUserClient\n} from '@keetanetwork/keetanet-client';\nimport type { Logger } from '../../lib/log/index.ts';\nimport type Resolver from '../../lib/resolver.ts';\nimport type { ServiceMetadata, ServiceSearchCriteria, SharedLookupCriteria } from '../../lib/resolver.ts';\nimport { Buffer } from '../../lib/utils/buffer.js';\nimport crypto from '../../lib/utils/crypto.js';\nimport { validateURL } from '../../lib/utils/url.js';\nimport type { BrandedString } from '../../lib/utils/brand.ts';\nimport {\n\tassertKeetaNetTokenPublicKeyString,\n\tisKeetaFXAnchorEstimateResponse,\n\tisKeetaFXAnchorExchangeResponse,\n\tisKeetaFXAnchorMarketPricesResponse,\n\tisKeetaFXAnchorQuoteResponse,\n\tErrors as FXErrors\n} from './common.js';\nimport type {\n\tConversionInput,\n\tConversionInputCanonical,\n\tConversionInputCanonicalJSON,\n\tKeetaFXAnchorEstimate,\n\tKeetaFXAnchorExchange,\n\tKeetaFXAnchorMarketPrices,\n\tKeetaFXAnchorMarketPricesRequest,\n\tKeetaFXAnchorMarketPriceRatio,\n\tKeetaFXAnchorQuote,\n\tKeetaNetToken,\n\tKeetaNetTokenPublicKeyString\n} from './common.ts';\nimport { AnchorExternalBuilder } from '../../lib/anchor-external.js';\nimport type { AnchorExternalInput } from '../../lib/anchor-external.js';\nimport { KeetaAnchorError, KeetaAnchorUserError } from '../../lib/error.js';\nimport { resolveSharedAnchorMetadataLegalExtension } from '../../lib/metadata.types.js';\nimport type { AnchorMetadataLegalField, SharedAnchorMetadataLegalExtension } from '../../lib/metadata.types.js';\nimport type { AnchorReference } from '../../lib/anchor-status.js';\n\n/**\n * An opaque type that represents a provider ID.\n */\ntype ProviderID = BrandedString<'FXProviderID'>;\n\ntype AccountOptions = {\n\t/**\n\t * The account to use for signing requests. If not provided, the\n\t * account associated with the provided client will be used. If there\n\t * is no account associated with the client, an error occurs.\n\t */\n\tsigner?: InstanceType<typeof KeetaNetLib.Account>;\n\t/**\n\t * Account to perform changes on. If not provided, the account\n\t * associated with the provided client will be used. If there is no\n\t * account associated with the client, an error occurs.\n\t */\n\taccount?: InstanceType<typeof KeetaNetLib.Account>;\n};\n\n/**\n * Controls how {@link KeetaFXAnchorClient.getPrices} coalesces concurrent\n * calls that share the same base (`priceIn`) into fewer `getMarketPrices`\n * requests.\n */\nexport interface KeetaFXAnchorClientGetPricesBatching {\n\t/**\n\t * How long to wait after each `getPrices` call for additional calls\n\t * with the same base before sending the batched `getMarketPrices`\n\t * request. Each new same-base call resets this timer.\n\t *\n\t * Defaults to `25`.\n\t */\n\twaitMs: number;\n\t/**\n\t * Maximum time to wait from the first `getPrices` call in a batch\n\t * before flushing, even if new same-base calls keep arriving.\n\t *\n\t * Defaults to `100` for the client default. When omitted from a custom\n\t * object, defaults to `4 * waitMs`.\n\t */\n\tmaxWaitMs?: number;\n}\n\n/**\n * The configuration options for the FX Anchor client.\n */\nexport type KeetaFXAnchorClientConfig = {\n\t/**\n\t * The ID of the client. This is used to identify the client in logs.\n\t * If not provided, a random ID will be generated.\n\t */\n\tid?: string;\n\t/**\n\t * The logger to use for logging messages. If not provided, no logging\n\t * will be done.\n\t */\n\tlogger?: Logger | undefined;\n\t/**\n\t * The resolver to use for resolving FX Anchor services. If not\n\t * provided, a default resolver will be created using the provided\n\t * client and network (if the network is also not provided and the\n\t * client is not a UserClient, an error occurs).\n\t */\n\tresolver?: Resolver;\n\t/**\n\t * The account to use for signing requests. If not provided, the\n\t * account associated with the provided client will be used. If there\n\t * is no account associated with the client, an error occurs.\n\t */\n\tsigner?: InstanceType<typeof KeetaNetLib.Account>;\n\t/**\n\t * Account to perform changes on. If not provided, the account\n\t * associated with the provided client will be used. If there is no\n\t * account associated with the client, an error occurs.\n\t */\n\taccount?: InstanceType<typeof KeetaNetLib.Account>;\n\t/**\n\t * How long `getPrices` waits for additional calls with the same base\n\t * so their provider `getMarketPrices` requests can be batched together.\n\t *\n\t * - `true` / omitted - (`waitMs: 25`, `maxWaitMs: 100`)\n\t * - `false` - disable batching\n\t * - `{ waitMs, maxWaitMs? }` - custom timing (`maxWaitMs` defaults to `4 * waitMs`)\n\t */\n\tgetPricesBatching?: KeetaFXAnchorClientGetPricesBatching | boolean;\n\t/**\n\t * Caps the client applies to every quote and estimate. See\n\t * {@link KeetaFXAnchorClientDefaultLimits}.\n\t */\n\tdefaultLimits?: KeetaFXAnchorClientDefaultLimits;\n} & Omit<NonNullable<Parameters<typeof getDefaultResolver>[1]>, 'client'> & AccountOptions;\n\nfunction typedFxServiceEntries<T extends object>(obj: T): [keyof T, T[keyof T]][] {\n\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\treturn(Object.entries(obj) as [keyof T, T[keyof T]][]);\n}\n\ntype KeetaFXAnchorOperations = {\n\t[operation in keyof NonNullable<ServiceMetadata['services']['fx']>[string]['operations']]: (params?: { [key: string]: string; }) => URL;\n};\n\ninterface KeetaFXServiceInfo extends SharedAnchorMetadataLegalExtension {\n\toperations: {\n\t\t[operation in keyof KeetaFXAnchorOperations]: Promise<KeetaFXAnchorOperations[operation]>;\n\t},\n\tfrom: NonNullable<ServiceMetadata['services']['fx']>[string]['from'];\n}\n\ntype GetEndpointsResult = {\n\t[providerID: ProviderID]: KeetaFXServiceInfo;\n};\n\nconst KeetaFXAnchorClientAccessToken = Symbol('KeetaFXAnchorClientAccessToken');\n\nasync function getEndpoints(\n\tresolver: Resolver,\n\trequest: Partial<Pick<ConversionInputCanonical, 'from' | 'to' | 'affinity'>> & Pick<GetProvidersOptions, 'requiredOperations'>,\n\t_ignored_account: InstanceType<typeof KeetaNetLib.Account>,\n\tsharedCriteria?: SharedLookupCriteria,\n\toptions?: { logger?: Logger | undefined; }\n): Promise<GetEndpointsResult | null> {\n\tconst criteria: ServiceSearchCriteria<'fx'> = {};\n\tif (request.from !== undefined) {\n\t\tcriteria.inputCurrencyCode = request.from.publicKeyString.get();\n\t}\n\tif (request.to !== undefined) {\n\t\tcriteria.outputCurrencyCode = request.to.publicKeyString.get();\n\t}\n\n\tif (request.requiredOperations) {\n\t\tcriteria.requiredOperations = request.requiredOperations;\n\t}\n\n\tif (request.affinity !== undefined) {\n\t\tcriteria.supportedAffinity = request.affinity;\n\t}\n\n\tconst response = await resolver.lookup('fx', {\n\t\t...criteria\n\t\t// kycProviders: 'TODO' XXX:TODO\n\t}, sharedCriteria);\n\n\tif (response === undefined) {\n\t\treturn(null);\n\t}\n\n\tconst serviceInfoPromises = Object.entries(response).map(async function([id, serviceInfo]): Promise<[ProviderID, KeetaFXServiceInfo]> {\n\t\tconst operations = await serviceInfo.operations('object');\n\t\tconst operationsFunctions: Partial<KeetaFXServiceInfo['operations']> = {};\n\t\tfor (const [key, operation] of Object.entries(operations)) {\n\t\t\tif (operation === undefined) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tObject.defineProperty(operationsFunctions, key, {\n\t\t\t\tget: async function() {\n\t\t\t\t\tconst url = await operation('string');\n\t\t\t\t\treturn(function(params?: { [key: string]: string; }): URL {\n\t\t\t\t\t\tlet substitutedURL = url;\n\t\t\t\t\t\tfor (const [paramKey, paramValue] of Object.entries(params ?? {})) {\n\t\t\t\t\t\t\tsubstitutedURL = substitutedURL.replace(`{${paramKey}}`, encodeURIComponent(paramValue));\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn(validateURL(substitutedURL));\n\t\t\t\t\t});\n\t\t\t\t},\n\t\t\t\tenumerable: true,\n\t\t\t\tconfigurable: true\n\t\t\t});\n\t\t}\n\n\t\tconst fromInfo = await serviceInfo.from('array');\n\t\tconst allFrom = await Promise.all(fromInfo.map(async function(fromFn) {\n\t\t\tconst from = await fromFn('object');\n\n\t\t\tconst currencyCodes = await Promise.all((await from.currencyCodes('array')).map(async (currencyCode) => {\n\t\t\t\tconst code = await currencyCode('string');\n\t\t\t\treturn(assertKeetaNetTokenPublicKeyString(code));\n\t\t\t}));\n\n\t\t\tconst to = await Promise.all((await from.to('array')).map(async (currencyCode) => {\n\t\t\t\tconst code = await currencyCode('string');\n\t\t\t\treturn(assertKeetaNetTokenPublicKeyString(code));\n\t\t\t}));\n\n\t\t\tconst kycProvidersEntry = (await from.kycProviders?.('array'))?.map(async (providerFn) => {\n\t\t\t\tconst provider = await providerFn('string');\n\t\t\t\treturn(provider);\n\t\t\t});\n\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-empty-object-type\n\t\t\tlet kycProviders: { kycProviders: string[] } | {} = {};\n\t\t\tif (kycProvidersEntry && kycProvidersEntry.length > 0) {\n\t\t\t\tkycProviders = { kycProviders: await Promise.all(kycProvidersEntry) }\n\t\t\t}\n\n\t\t\treturn({ currencyCodes, to, ...kycProviders });\n\t\t}));\n\t\treturn([\n\t\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\t\tid as unknown as ProviderID,\n\t\t\t{\n\t\t\t\t...(await resolveSharedAnchorMetadataLegalExtension(serviceInfo.legal, { logger: options?.logger })),\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\t\t\toperations: operationsFunctions as KeetaFXServiceInfo['operations'],\n\t\t\t\tfrom: allFrom\n\t\t\t}\n\t\t]);\n\t});\n\n\tif (serviceInfoPromises.length === 0) {\n\t\treturn(null);\n\t}\n\n\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\tconst retval = Object.fromEntries(await Promise.all(serviceInfoPromises)) satisfies GetEndpointsResult as GetEndpointsResult;\n\n\treturn(retval);\n}\n\n/**\n * Limits the caller sets on the block that `createExchange` builds, from\n * the terms it showed the user. The limits apply only when\n * `createExchange` builds the block, not to a block the caller gives.\n *\n * The limits add to the client's `defaultLimits`; they never lift them.\n * - With affinity `to`, the anchor sets the amount sent, so `maxSend` is\n * required. With affinity `from`, it sets the amount received, so\n * `minReceive` is required.\n * - A fee in a token other than `from` or `to` needs `maxCost`, since no\n * default can price it.\n * - A fee in `from` or `to` must also be within `defaultLimits.maxCostBps`.\n * - An estimate bound must also be within\n * `defaultLimits.maxEstimateBoundBps` of its converted amount.\n */\nexport interface KeetaFXAnchorExchangeLimits {\n\t/**\n\t * The most of the `from` token the block may send for the conversion,\n\t * not counting the fee. Required for affinity `to`.\n\t */\n\tmaxSend?: bigint;\n\t/**\n\t * The least of the `to` token the block may receive. Required for\n\t * affinity `from`.\n\t */\n\tminReceive?: bigint;\n\t/**\n\t * The most the fee may be. A non-zero fee must also be in this token.\n\t * A fee in `from` or `to` must also be within the default fee cap.\n\t */\n\tmaxCost?: { token: KeetaNetToken; amount: bigint; };\n}\n\nexport interface KeetaFXAnchorCreateExchangeOptions {\n\tinputs?: readonly AnchorExternalInput[];\n\tlimits?: KeetaFXAnchorExchangeLimits;\n}\n\n/**\n * Caps `createExchange` applies to every block it builds, on top of any\n * caller limits. They do not filter quotes or estimates. Set a cap to\n * `null` to turn it off, or raise it to accept larger terms.\n */\nexport interface KeetaFXAnchorClientDefaultLimits {\n\t/**\n\t * The most a fee in the `from` or `to` token may be, in basis points\n\t * of the amount the conversion sends or receives in that token.\n\t *\n\t * Defaults to `100` (1%).\n\t */\n\tmaxCostBps?: number | null;\n\t/**\n\t * The furthest an estimate's bound may be from its converted amount,\n\t * in basis points of the converted amount.\n\t *\n\t * Defaults to `500` (5%).\n\t */\n\tmaxEstimateBoundBps?: number | null;\n}\n\ntype ResolvedDefaultLimits = { [K in keyof KeetaFXAnchorClientDefaultLimits]-?: number | null; };\n\nfunction resolveDefaultLimits(input: KeetaFXAnchorClientDefaultLimits | undefined): ResolvedDefaultLimits {\n\tconst resolved: ResolvedDefaultLimits = {\n\t\tmaxCostBps: input?.maxCostBps === undefined ? 100 : input.maxCostBps,\n\t\tmaxEstimateBoundBps: input?.maxEstimateBoundBps === undefined ? 500 : input.maxEstimateBoundBps\n\t};\n\n\tfor (const [ name, value ] of Object.entries(resolved)) {\n\t\tif (value !== null && (!Number.isInteger(value) || value < 0)) {\n\t\t\tthrow(new Error(`defaultLimits.${name} must be a non-negative integer or null`));\n\t\t}\n\t}\n\n\tif (resolved.maxEstimateBoundBps !== null && resolved.maxEstimateBoundBps > 10000) {\n\t\tthrow(new Error('defaultLimits.maxEstimateBoundBps must be at most 10000'));\n\t}\n\n\treturn(resolved);\n}\n\ntype ExchangeTerms = { sendAmount: bigint; receiveAmount: bigint; costAmount: bigint; costToken: KeetaNetToken; };\n\n/**\n * The amounts an exchange block sends and receives for a conversion, given\n * the converted amount it commits to and its fee.\n */\nfunction exchangeTerms(conversion: ConversionInputCanonical, convertedAmount: bigint, cost: { amount: bigint; token: KeetaNetToken; }): ExchangeTerms {\n\tif (conversion.affinity === 'to') {\n\t\treturn({ sendAmount: convertedAmount, receiveAmount: conversion.amount, costAmount: cost.amount, costToken: cost.token });\n\t}\n\n\treturn({ sendAmount: conversion.amount, receiveAmount: convertedAmount, costAmount: cost.amount, costToken: cost.token });\n}\n\ninterface KeetaFXAnchorBaseConfig {\n\tclient: KeetaNetUserClient;\n\tlogger?: Logger | undefined;\n}\n\nclass KeetaFXAnchorBase {\n\tprotected readonly logger?: Logger | undefined;\n\tprotected readonly client: KeetaNetUserClient;\n\n\tconstructor(config: KeetaFXAnchorBaseConfig) {\n\t\tthis.client = config.client;\n\t\tthis.logger = config.logger;\n\t}\n}\n\nexport class KeetaFXAnchorProviderBase extends KeetaFXAnchorBase {\n\treadonly serviceInfo: KeetaFXServiceInfo;\n\treadonly providerID: ProviderID;\n\treadonly conversion: ConversionInputCanonical;\n\treadonly options: Pick<AccountOptions, 'account'> | undefined;\n\tprivate readonly parent: KeetaFXAnchorClient;\n\treadonly #defaultLimits: ResolvedDefaultLimits;\n\n\tconstructor(serviceInfo: KeetaFXServiceInfo, providerID: ProviderID, conversion: ConversionInputCanonical, parent: KeetaFXAnchorClient, options?: Pick<AccountOptions, 'account'>) {\n\t\tconst parentPrivate = parent._internals(KeetaFXAnchorClientAccessToken);\n\t\tsuper(parentPrivate);\n\n\t\tthis.#defaultLimits = parentPrivate.defaultLimits;\n\t\tthis.serviceInfo = serviceInfo;\n\t\tthis.providerID = providerID;\n\t\tthis.conversion = conversion;\n\t\tthis.parent = parent;\n\t\tthis.options = options;\n\t}\n\n\t/**\n\t * Checks that the anchor's echoed request matches this conversion and\n\t * returns `this.conversion`. Throws when any field differs.\n\t */\n\t#bindConversion(echoed: ConversionInputCanonical | ConversionInputCanonicalJSON): ConversionInputCanonical {\n\t\tconst own = this.conversion;\n\t\tconst mismatched: string[] = [];\n\t\tif (!KeetaNetLib.Account.toAccount(echoed.from).comparePublicKey(own.from)) {\n\t\t\tmismatched.push('from');\n\t\t}\n\t\tif (!KeetaNetLib.Account.toAccount(echoed.to).comparePublicKey(own.to)) {\n\t\t\tmismatched.push('to');\n\t\t}\n\t\tif (BigInt(echoed.amount) !== own.amount) {\n\t\t\tmismatched.push('amount');\n\t\t}\n\t\tif (echoed.affinity !== own.affinity) {\n\t\t\tmismatched.push('affinity');\n\t\t}\n\t\tif (echoed.preferredCostAsset !== own.preferredCostAsset) {\n\t\t\tmismatched.push('preferredCostAsset');\n\t\t}\n\t\tif (mismatched.length > 0) {\n\t\t\tthrow(new FXErrors.ResponseMismatch(`FX provider ${String(this.providerID)} answered for a different conversion than requested (${mismatched.join(', ')})`));\n\t\t}\n\n\t\treturn(own);\n\t}\n\n\t/**\n\t * Checks that the anchor's amounts are possible: a positive converted\n\t * amount and bound, and a fee range that is not negative or reversed.\n\t */\n\t#assertAmounts(convertedAmount: bigint, convertedAmountBound: bigint | undefined, costMin: bigint, costMax: bigint): void {\n\t\tconst isConvertedInvalid = convertedAmount <= 0n || (convertedAmountBound ?? 1n) <= 0n;\n\t\tconst isCostInvalid = costMin < 0n || costMax < costMin;\n\t\tif (isConvertedInvalid || isCostInvalid) {\n\t\t\tthrow(new FXErrors.ResponseMismatch(`FX provider ${String(this.providerID)} gave invalid amounts (converted ${convertedAmount}, bound ${convertedAmountBound ?? 'none'}, fee ${costMin} to ${costMax})`));\n\t\t}\n\t}\n\n\t/**\n\t * Checks that a non-zero fee is in a token the user expects to pay\n\t * with: the `from` or `to` token, the network base token, or the\n\t * requested `preferredCostAsset`. Throws when it is any other token.\n\t */\n\t#assertCostToken(cost: { amount: bigint; token: KeetaNetToken }): void {\n\t\tif (cost.amount === 0n) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst own = this.conversion;\n\t\tconst allowed = [ own.from, own.to, this.client.baseToken ];\n\t\tif (own.preferredCostAsset !== undefined) {\n\t\t\tallowed.push(KeetaNetLib.Account.fromPublicKeyString(own.preferredCostAsset));\n\t\t}\n\n\t\tconst isAllowed = allowed.some(function(token) {\n\t\t\treturn(token.comparePublicKey(cost.token));\n\t\t});\n\t\tif (!isAllowed) {\n\t\t\tthrow(new FXErrors.ResponseMismatch(`FX provider ${String(this.providerID)} charges its fee in a token that is not part of the conversion (${cost.token.publicKeyString.get()})`));\n\t\t}\n\t}\n\n\t/**\n\t * Checks that an estimate's bound is on the safe side of its converted\n\t * amount: no more for affinity `from`, no less for affinity `to`.\n\t * Throws when it is on the other side.\n\t */\n\t#assertEstimateBound(convertedAmount: bigint, convertedAmountBound: bigint | undefined): void {\n\t\tif (convertedAmountBound === undefined) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst affinity = this.conversion.affinity;\n\t\tconst isInvalid = affinity === 'from' ? convertedAmountBound > convertedAmount : convertedAmountBound < convertedAmount;\n\t\tif (isInvalid) {\n\t\t\tthrow(new FXErrors.ResponseMismatch(`FX provider ${String(this.providerID)} gave an estimate bound of ${convertedAmountBound} that is on the wrong side of its converted amount ${convertedAmount} for affinity \"${affinity}\"`));\n\t\t}\n\t}\n\n\t/**\n\t * Checks every amount the anchor sets in the block against the\n\t * caller's limits and the client's default caps. Both must hold, so\n\t * a limit copied from the anchor's own quote cannot lift a default.\n\t * Throws when an amount is not bounded or is past its bound. See\n\t * {@link KeetaFXAnchorExchangeLimits}.\n\t */\n\t#assertSigningLimits(terms: ExchangeTerms, estimate: { convertedAmount: bigint; convertedAmountBound: bigint; } | undefined, limits: KeetaFXAnchorExchangeLimits | undefined): void {\n\t\tthis.#assertAmountLimits(terms, limits);\n\t\tif (estimate !== undefined) {\n\t\t\tthis.#assertBoundCap(estimate.convertedAmount, estimate.convertedAmountBound);\n\t\t}\n\t\tthis.#assertCostLimits(terms, limits?.maxCost);\n\t}\n\n\t/**\n\t * Checks the amounts sent and received against the caller's limits.\n\t * The side the provider sets must have a limit: `maxSend` for affinity\n\t * `to`, `minReceive` for affinity `from`.\n\t */\n\t#assertAmountLimits(terms: ExchangeTerms, limits: KeetaFXAnchorExchangeLimits | undefined): void {\n\t\tconst affinity = this.conversion.affinity;\n\t\tif (affinity === 'to' && limits?.maxSend === undefined) {\n\t\t\tthrow(new FXErrors.ExchangeLimitExceeded('FX exchange with affinity \"to\" needs limits.maxSend, because the provider sets the amount sent'));\n\t\t}\n\t\tif (affinity === 'from' && limits?.minReceive === undefined) {\n\t\t\tthrow(new FXErrors.ExchangeLimitExceeded('FX exchange with affinity \"from\" needs limits.minReceive, because the provider sets the amount received'));\n\t\t}\n\n\t\tif (limits?.maxSend !== undefined && terms.sendAmount > limits.maxSend) {\n\t\t\tthrow(new FXErrors.ExchangeLimitExceeded(`FX exchange would send ${terms.sendAmount}, more than the limit of ${limits.maxSend}`));\n\t\t}\n\t\tif (limits?.minReceive !== undefined && terms.receiveAmount < limits.minReceive) {\n\t\t\tthrow(new FXErrors.ExchangeLimitExceeded(`FX exchange would receive ${terms.receiveAmount}, less than the limit of ${limits.minReceive}`));\n\t\t}\n\t}\n\n\t/**\n\t * Checks that an estimate's bound is within the default cap of its\n\t * converted amount.\n\t */\n\t#assertBoundCap(convertedAmount: bigint, convertedAmountBound: bigint): void {\n\t\tconst maxBps = this.#defaultLimits.maxEstimateBoundBps;\n\t\tif (maxBps === null) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst distance = convertedAmount > convertedAmountBound ? convertedAmount - convertedAmountBound : convertedAmountBound - convertedAmount;\n\t\tif (distance * 10000n > convertedAmount * BigInt(maxBps)) {\n\t\t\tthrow(new FXErrors.ExchangeLimitExceeded(`FX estimate bound of ${convertedAmountBound} is more than ${maxBps} basis points from its converted amount ${convertedAmount}; raise defaultLimits.maxEstimateBoundBps to accept it`));\n\t\t}\n\t}\n\n\t/**\n\t * Checks a non-zero fee against the caller's `maxCost` and, for a fee\n\t * in `from` or `to`, against the default fee cap. A fee in any other\n\t * token needs `maxCost`.\n\t */\n\t#assertCostLimits(terms: ExchangeTerms, maxCost: KeetaFXAnchorExchangeLimits['maxCost']): void {\n\t\tif (terms.costAmount === 0n) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (maxCost !== undefined) {\n\t\t\tif (!maxCost.token.comparePublicKey(terms.costToken)) {\n\t\t\t\tthrow(new FXErrors.ExchangeLimitExceeded(`FX exchange fee is in ${terms.costToken.publicKeyString.get()}, not in the limit token ${maxCost.token.publicKeyString.get()}`));\n\t\t\t}\n\t\t\tif (terms.costAmount > maxCost.amount) {\n\t\t\t\tthrow(new FXErrors.ExchangeLimitExceeded(`FX exchange fee of ${terms.costAmount} is more than the limit of ${maxCost.amount}`));\n\t\t\t}\n\t\t}\n\n\t\tconst base = this.#costBase(terms);\n\t\tif (base === null) {\n\t\t\tif (maxCost === undefined) {\n\t\t\t\tthrow(new FXErrors.ExchangeLimitExceeded(`FX exchange fee is in ${terms.costToken.publicKeyString.get()}, which is not part of the conversion; set limits.maxCost to accept it`));\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tconst maxBps = this.#defaultLimits.maxCostBps;\n\t\tif (maxBps !== null && terms.costAmount * 10000n > base * BigInt(maxBps)) {\n\t\t\tthrow(new FXErrors.ExchangeLimitExceeded(`FX exchange fee of ${terms.costAmount} is more than ${maxBps} basis points of ${base}; raise defaultLimits.maxCostBps to accept it`));\n\t\t}\n\t}\n\n\t/**\n\t * The amount a fee is capped against: what the conversion sends when\n\t * the fee is in `from`, what it receives when the fee is in `to`, or\n\t * `null` for a fee in any other token.\n\t */\n\t#costBase(terms: ExchangeTerms): bigint | null {\n\t\tif (terms.costToken.comparePublicKey(this.conversion.from)) {\n\t\t\treturn(terms.sendAmount);\n\t\t}\n\t\tif (terms.costToken.comparePublicKey(this.conversion.to)) {\n\t\t\treturn(terms.receiveAmount);\n\t\t}\n\t\treturn(null);\n\t}\n\n\tasync #parseResponseError(data: { ok: false }) {\n\t\tif (typeof data !== 'object' || data === null) {\n\t\t\tthrow(new Error('Response is not an error'));\n\t\t}\n\n\t\tif (!('ok' in data) || data.ok) {\n\t\t\tthrow(new Error('Response is not an error'));\n\t\t}\n\n\t\tlet errorStr;\n\n\t\ttry {\n\t\t\treturn(await KeetaAnchorError.fromJSON(data));\n\t\t} catch (error: unknown) {\n\t\t\tthis.logger?.debug('Failed to parse error response as KeetaAnchorError', error, data);\n\t\t}\n\n\t\tif ('error' in data && typeof data.error === 'string') {\n\t\t\terrorStr = data.error;\n\t\t} else {\n\t\t\terrorStr = 'Unknown error';\n\t\t}\n\n\t\treturn(new Error(`FX request failed: ${errorStr}`));\n\t}\n\n\tasync #getEndpoint(operation: keyof KeetaFXAnchorOperations, params?: { [key: string]: string; }): Promise<URL> {\n\t\tconst operationFn = await this.serviceInfo.operations[operation];\n\t\tif (operationFn === undefined) {\n\t\t\tthrow(new KeetaAnchorUserError(`Provider ${String(this.providerID)} does not support \"${operation}\" operation`));\n\t\t}\n\t\treturn(operationFn(params));\n\t}\n\n\tasync getEstimate(): Promise<KeetaFXAnchorEstimate> {\n\t\tconst estimateURL = await this.#getEndpoint('getEstimate');\n\n\t\tconst requestInformation = await fetch(estimateURL, {\n\t\t\tmethod: 'POST',\n\t\t\theaders: {\n\t\t\t\t'Content-Type': 'application/json',\n\t\t\t\t'Accept': 'application/json'\n\t\t\t},\n\t\t\tbody: JSON.stringify({\n\t\t\t\trequest: KeetaNetLib.Utils.Conversion.toJSONSerializable(this.conversion)\n\t\t\t})\n\t\t});\n\n\t\tconst requestInformationJSON: unknown = await requestInformation.json();\n\t\tif (!isKeetaFXAnchorEstimateResponse(requestInformationJSON)) {\n\t\t\tthrow(new Error(`Invalid response from FX estimate service: ${JSON.stringify(requestInformationJSON)}`));\n\t\t}\n\n\t\tif (!requestInformationJSON.ok) {\n\t\t\tthrow(await this.#parseResponseError(requestInformationJSON));\n\t\t}\n\n\t\tthis.logger?.debug(`FX estimate request successful, to provider ${estimateURL} for ${JSON.stringify(KeetaNetLib.Utils.Conversion.toJSONSerializable(this.conversion))}`);\n\t\tconst estimateJSON = requestInformationJSON.estimate;\n\t\tconst estimate: KeetaFXAnchorEstimate = {\n\t\t\trequest: this.#bindConversion(estimateJSON.request),\n\t\t\tconvertedAmount: BigInt(estimateJSON.convertedAmount),\n\t\t\texpectedCost: {\n\t\t\t\tmin: BigInt(estimateJSON.expectedCost.min),\n\t\t\t\tmax: BigInt(estimateJSON.expectedCost.max),\n\t\t\t\ttoken: KeetaNetLib.Account.fromPublicKeyString(estimateJSON.expectedCost.token)\n\t\t\t},\n\t\t\t...(estimateJSON.convertedAmountBound !== undefined ? { convertedAmountBound: BigInt(estimateJSON.convertedAmountBound) } : {}),\n\t\t\t...(() => {\n\t\t\t\tif (estimateJSON.canPerformExchange === false) {\n\t\t\t\t\treturn({ canPerformExchange: false });\n\t\t\t\t} else if (estimateJSON.requiresQuote === undefined) {\n\t\t\t\t\treturn({})\n\t\t\t\t} else if (estimateJSON.requiresQuote) {\n\t\t\t\t\treturn({ requiresQuote: true });\n\t\t\t\t// We have to disable this as doing !estimateJSON.requiresQuote breaks the compiler, and that is what eslint wants us to do\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unnecessary-boolean-literal-compare\n\t\t\t\t} else if (estimateJSON.requiresQuote === false) {\n\t\t\t\t\treturn({\n\t\t\t\t\t\trequiresQuote: false,\n\t\t\t\t\t\taccount: KeetaNetLib.Account.fromPublicKeyString(estimateJSON.account)\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t})()\n\t\t};\n\n\t\tconst estimateCost = { amount: estimate.expectedCost.max, token: estimate.expectedCost.token };\n\t\tthis.#assertAmounts(estimate.convertedAmount, estimate.convertedAmountBound, estimate.expectedCost.min, estimate.expectedCost.max);\n\t\tthis.#assertEstimateBound(estimate.convertedAmount, estimate.convertedAmountBound);\n\t\tthis.#assertCostToken(estimateCost);\n\n\t\treturn(estimate);\n\t}\n\n\t/**\n\t * Get a quote from the provider. If an estimate is provided, it will\n\t * be used to validate the quote is within the tolerance range.\n\t *\n\t * @param estimate An optional estimate to validate the quote against\n\t * @param tolerance The tolerance, in percentage points, to allow the\n\t * quote to vary from the estimate. For example, a\n\t * tolerance of 1.0 allows the quote to be 100% more\n\t * or less than the estimate. The default is 0.10\n\t * (10%).\n\t * @returns A promise that resolves to the quote response\n\t */\n\tasync getQuote(estimate?: KeetaFXAnchorEstimate, tolerance: number = 0.1): Promise<KeetaFXAnchorQuote> {\n\t\tconst serviceURL = await this.#getEndpoint('getQuote');\n\t\tconst requestInformation = await fetch(serviceURL, {\n\t\t\tmethod: 'POST',\n\t\t\theaders: {\n\t\t\t\t'Content-Type': 'application/json',\n\t\t\t\t'Accept': 'application/json'\n\t\t\t},\n\t\t\tbody: JSON.stringify({\n\t\t\t\trequest: KeetaNetLib.Utils.Conversion.toJSONSerializable(this.conversion)\n\t\t\t})\n\t\t});\n\n\t\tconst requestInformationJSON: unknown = await requestInformation.json();\n\t\tif (!isKeetaFXAnchorQuoteResponse(requestInformationJSON)) {\n\t\t\tthrow(new Error(`Invalid response from FX quote service: ${JSON.stringify(requestInformationJSON)}`));\n\t\t}\n\n\t\tif (!requestInformationJSON.ok) {\n\t\t\tthrow(await this.#parseResponseError(requestInformationJSON));\n\t\t}\n\n\t\tif (estimate !== undefined && tolerance !== undefined) {\n\t\t\tconst quoteAmount = BigInt(requestInformationJSON.quote.convertedAmount);\n\t\t\tconst estimateAmount = BigInt(estimate.convertedAmount);\n\t\t\tconst lowerBound = estimateAmount * BigInt(Math.round((1 - tolerance) * 100)) / 100n;\n\t\t\tconst upperBound = estimateAmount * BigInt(Math.round((1 + tolerance) * 100)) / 100n;\n\t\t\tif (quoteAmount > upperBound || quoteAmount < lowerBound) {\n\t\t\t\tthrow(new Error(`FX Quote amount: ${requestInformationJSON.quote.convertedAmount} differs more than tolerance limit: ${tolerance} from estimate`));\n\t\t\t}\n\t\t}\n\n\t\tthis.logger?.debug(`FX quote request successful, to provider ${serviceURL} for ${JSON.stringify(KeetaNetLib.Utils.Conversion.toJSONSerializable(this.conversion))}`);\n\t\tconst quoteJSON = requestInformationJSON.quote;\n\t\tconst quote: KeetaFXAnchorQuote = {\n\t\t\trequest: this.#bindConversion(quoteJSON.request),\n\t\t\taccount: KeetaNetLib.Account.fromPublicKeyString(quoteJSON.account),\n\t\t\tconvertedAmount: BigInt(quoteJSON.convertedAmount),\n\t\t\tcost: {\n\t\t\t\tamount: BigInt(quoteJSON.cost.amount),\n\t\t\t\ttoken: KeetaNetLib.Account.fromPublicKeyString(quoteJSON.cost.token)\n\t\t\t},\n\t\t\tsigned: quoteJSON.signed\n\t\t};\n\n\t\tthis.#assertAmounts(quote.convertedAmount, undefined, quote.cost.amount, quote.cost.amount);\n\t\tthis.#assertCostToken(quote.cost);\n\n\t\treturn(quote);\n\t}\n\n\t/**\n\t * Checks the terms of a quote or estimate as `createExchange` would\n\t * before it signs, without building or sending anything. Throws the\n\t * same errors `createExchange` would.\n\t */\n\tcheckExchange(input: { quote: KeetaFXAnchorQuote } | { estimate: KeetaFXAnchorEstimate; }, options?: Pick<KeetaFXAnchorCreateExchangeOptions, 'limits'>): void {\n\t\tthis.#bindConversion('quote' in input ? input.quote.request : input.estimate.request);\n\t\tthis.#checkExchangeTerms(input, options?.limits);\n\t}\n\n\t/**\n\t * Every check `createExchange` runs on the anchor's terms before it\n\t * builds the block. Returns the terms the block commits to.\n\t */\n\t#checkExchangeTerms(input: { quote: KeetaFXAnchorQuote } | { estimate: KeetaFXAnchorEstimate; }, limits: KeetaFXAnchorExchangeLimits | undefined): { liquidityProvider: KeetaFXAnchorQuote['account']; terms: ExchangeTerms; } {\n\t\tlet liquidityProvider;\n\t\tlet convertedAmountBound: bigint;\n\t\tlet costAmount;\n\t\tlet costToken;\n\t\tlet estimateTerms;\n\n\t\tif ('estimate' in input) {\n\t\t\tif (input.estimate.canPerformExchange === false) {\n\t\t\t\tthrow(new KeetaAnchorUserError('The provided estimate indicates that the exchange cannot be performed'));\n\t\t\t}\n\n\t\t\tif (input.estimate.requiresQuote !== false) {\n\t\t\t\tthrow(new FXErrors.QuoteRequired());\n\t\t\t}\n\n\t\t\tliquidityProvider = input.estimate.account;\n\t\t\tconvertedAmountBound = input.estimate.convertedAmountBound ?? input.estimate.convertedAmount;\n\t\t\tcostAmount = input.estimate.expectedCost.max;\n\t\t\tcostToken = input.estimate.expectedCost.token;\n\t\t\tthis.#assertAmounts(input.estimate.convertedAmount, input.estimate.convertedAmountBound, input.estimate.expectedCost.min, costAmount);\n\t\t\tthis.#assertEstimateBound(input.estimate.convertedAmount, input.estimate.convertedAmountBound);\n\t\t\testimateTerms = { convertedAmount: input.estimate.convertedAmount, convertedAmountBound: convertedAmountBound };\n\t\t} else {\n\t\t\tliquidityProvider = input.quote.account;\n\t\t\tconvertedAmountBound = input.quote.convertedAmount;\n\t\t\tcostAmount = input.quote.cost.amount;\n\t\t\tcostToken = input.quote.cost.token;\n\t\t\tthis.#assertAmounts(input.quote.convertedAmount, undefined, costAmount, costAmount);\n\t\t}\n\n\t\tthis.#assertCostToken({ amount: costAmount, token: costToken });\n\t\tconst terms = exchangeTerms(this.conversion, convertedAmountBound, { amount: costAmount, token: costToken });\n\t\tthis.#assertSigningLimits(terms, estimateTerms, limits);\n\n\t\treturn({ liquidityProvider, terms });\n\t}\n\n\t/**\n\t * Builds the swap block from this conversion and the anchor's checked\n\t * terms. Throws when a term fails a check; see `checkExchange`.\n\t */\n\tasync #buildSwapBlock(input: { quote: KeetaFXAnchorQuote } | { estimate: KeetaFXAnchorEstimate; }, options: KeetaFXAnchorCreateExchangeOptions | undefined): Promise<InstanceType<typeof KeetaNetLib.Block>> {\n\t\tconst request = this.conversion;\n\t\tconst { liquidityProvider, terms } = this.#checkExchangeTerms(input, options?.limits);\n\t\tconst { sendAmount, receiveAmount, costAmount, costToken } = terms;\n\n\t\t/* Construct the required operations for the swap request */\n\t\tconst builder = this.client.initBuilder(this.options);\n\n\t\t/*\n\t\t * When the fee is charged in the same token as the swap send,\n\t\t * combine them into a single SEND. The principal send carries an\n\t\t * external, so the builder will not merge a separate cost send\n\t\t * of the same token into that operation.\n\t\t */\n\t\tconst costUsesSendToken = costAmount > 0n && costToken.comparePublicKey(request.from);\n\n\t\tif (costAmount > 0n && !costUsesSendToken) {\n\t\t\tbuilder.send(liquidityProvider, costAmount, costToken);\n\t\t}\n\n\t\tbuilder.receive(liquidityProvider, receiveAmount, request.to, request.affinity === 'to');\n\n\t\t/*\n\t\t * Tag the principal send with an anchor external naming the FX\n\t\t * provider and a client-chosen correlation id.\n\t\t */\n\t\tconst correlationId = crypto.randomUUID();\n\t\tconst externalBuilder = new AnchorExternalBuilder().setAnchor(liquidityProvider, { transactionId: correlationId });\n\t\tfor (const inputReference of options?.inputs ?? []) {\n\t\t\texternalBuilder.addInput(inputReference.blockHash, inputReference.operationIndex);\n\t\t}\n\n\t\tconst external = await externalBuilder.build();\n\t\tconst taggedSendAmount = costUsesSendToken ? sendAmount + costAmount : sendAmount;\n\t\tbuilder.send(liquidityProvider, taggedSendAmount, request.from, external);\n\n\t\tconst blocks = await builder.computeBlocks();\n\t\tif (blocks.blocks.length !== 1) {\n\t\t\tthrow(new Error('Creating Swap Generated more than 1 block'));\n\t\t}\n\t\tconst swapBlock = blocks.blocks[0];\n\t\tif (swapBlock === undefined) {\n\t\t\tthrow(new Error('User Swap Block is undefined'));\n\t\t}\n\n\t\treturn(swapBlock);\n\t}\n\n\tasync createExchange(input: { quote: KeetaFXAnchorQuote } | { estimate: KeetaFXAnchorEstimate; }, block?: InstanceType<typeof KeetaNetLib.Block>, options?: KeetaFXAnchorCreateExchangeOptions): Promise<KeetaFXAnchorExchange> {\n\t\tconst request = this.#bindConversion('quote' in input ? input.quote.request : input.estimate.request);\n\t\tif (block !== undefined && options?.limits !== undefined) {\n\t\t\tthrow(new KeetaAnchorUserError('createExchange applies limits only to a block it builds, not to a given block'));\n\t\t}\n\n\t\tconst swapBlock = block ?? await this.#buildSwapBlock(input, options);\n\n\t\tlet bodyAdditionalData: { quote: KeetaFXAnchorQuote; } | { request: ConversionInputCanonical; };\n\n\t\tif ('quote' in input) {\n\t\t\tbodyAdditionalData = { quote: { ...input.quote, request }};\n\t\t} else {\n\t\t\tbodyAdditionalData = { request };\n\t\t}\n\n\t\tconst serviceURL = await this.#getEndpoint('createExchange');\n\t\tconst requestInformation = await fetch(serviceURL, {\n\t\t\tmethod: 'POST',\n\t\t\theaders: {\n\t\t\t\t'Content-Type': 'application/json',\n\t\t\t\t'Accept': 'application/json'\n\t\t\t},\n\t\t\tbody: JSON.stringify({\n\t\t\t\trequest: {\n\t\t\t\t\t...(KeetaNetLib.Utils.Conversion.toJSONSerializable(bodyAdditionalData)),\n\t\t\t\t\tblock: Buffer.from(swapBlock.toBytes()).toString('base64')\n\t\t\t\t}\n\t\t\t})\n\t\t});\n\n\t\tconst exchange = await this.#parseExchangeResponse(await requestInformation.json(), swapBlock);\n\t\tthis.logger?.debug(`FX exchange request successful, to provider ${serviceURL} for ${swapBlock.hash.toString()}`);\n\t\treturn(exchange);\n\t}\n\n\tasync #parseExchangeResponse(requestInformationJSON: unknown, swapBlock: InstanceType<typeof KeetaNetLib.Block>): Promise<KeetaFXAnchorExchange> {\n\t\t// Ensure status defaults to 'completed' if not provided (for backward compatibility)\n\t\tif (typeof requestInformationJSON === 'object' && requestInformationJSON !== null && !('status' in requestInformationJSON)) {\n\t\t\tObject.assign(requestInformationJSON, { status: 'completed' });\n\t\t\tObject.assign(requestInformationJSON, { blockhash: swapBlock.hash.toString() });\n\t\t}\n\n\t\t// Validate response\n\t\tif (!isKeetaFXAnchorExchangeResponse(requestInformationJSON)) {\n\t\t\tthrow(new Error(`Invalid response from FX exchange service: ${JSON.stringify(requestInformationJSON)}`));\n\t\t}\n\n\t\tif (!requestInformationJSON.ok) {\n\t\t\tthrow(await this.#parseResponseError(requestInformationJSON));\n\t\t}\n\n\t\treturn(requestInformationJSON);\n\t}\n\n\tasync getMarketPrices(request: KeetaFXAnchorMarketPricesRequest): Promise<KeetaFXAnchorMarketPrices> {\n\t\tconst serviceURL = await this.#getEndpoint('getMarketPrices');\n\t\tserviceURL.searchParams.set('quoteAssets', request.quoteAssets.join(','));\n\t\tserviceURL.searchParams.set('base', request.base);\n\n\t\tconst requestInformation = await fetch(serviceURL, {\n\t\t\tmethod: 'GET',\n\t\t\theaders: {\n\t\t\t\t'Accept': 'application/json'\n\t\t\t}\n\t\t});\n\n\t\tconst requestInformationJSON: unknown = await requestInformation.json();\n\t\tif (!isKeetaFXAnchorMarketPricesResponse(requestInformationJSON)) {\n\t\t\tthrow(new Error(`Invalid response from FX market prices service: ${JSON.stringify(requestInformationJSON)}`));\n\t\t}\n\n\t\tif (!requestInformationJSON.ok) {\n\t\t\tthrow(await this.#parseResponseError(requestInformationJSON));\n\t\t}\n\n\t\tthis.logger?.debug(`FX market prices request successful, to provider ${serviceURL} for quoteAssets=${request.quoteAssets.join(',')} base=${request.base}`);\n\t\treturn({\n\t\t\tbase: requestInformationJSON.base,\n\t\t\tquoteAssets: requestInformationJSON.quoteAssets\n\t\t});\n\t}\n\n\tasync getExchangeStatus(exchangeID: string): Promise<KeetaFXAnchorExchange> {\n\t\tconst serviceURL = await this.#getEndpoint('getExchangeStatus', { id: exchangeID });\n\t\tconst requestInformation = await fetch(serviceURL, {\n\t\t\tmethod: 'GET',\n\t\t\theaders: {\n\t\t\t\t'Accept': 'application/json'\n\t\t\t}\n\t\t});\n\n\t\tconst requestInformationJSON: unknown = await requestInformation.json();\n\t\tif (!isKeetaFXAnchorExchangeResponse(requestInformationJSON)) {\n\t\t\tthrow(new Error(`Invalid response from FX exchange status service: ${JSON.stringify(requestInformationJSON)}`));\n\t\t}\n\n\t\tif (!requestInformationJSON.ok) {\n\t\t\tthrow(await this.#parseResponseError(requestInformationJSON));\n\t\t}\n\n\t\tthis.logger?.debug(`FX exchange status request successful, to provider ${serviceURL} for ${exchangeID}`);\n\t\treturn(requestInformationJSON);\n\t}\n\n\t/** @internal */\n\t_internals(accessToken: symbol) {\n\t\tif (accessToken !== KeetaFXAnchorClientAccessToken) {\n\t\t\tthrow(new Error('invalid access token'));\n\t\t}\n\n\t\treturn({\n\t\t\tparent: this.parent\n\t\t});\n\t}\n}\n\n/*\n * Various classes for the state machine:\n * Estimate(optional) -> Quote(optional) -> Exchange -> ExchangeStatus\n */\nclass KeetaFXAnchorExchangeWithProvider {\n\treadonly provider: KeetaFXAnchorProviderBase;\n\treadonly exchange: KeetaFXAnchorExchange\n\n\tconstructor(provider: KeetaFXAnchorProviderBase, exchange: KeetaFXAnchorExchange) {\n\t\tthis.provider = provider;\n\t\tthis.exchange = exchange;\n\t}\n\n\tasync getExchangeStatus(): Promise<KeetaFXAnchorExchange> {\n\t\t/* XXX:TODO: This should return something useful -- right now it just returns the exchange ID... */\n\t\treturn(await this.provider.getExchangeStatus(this.exchange.exchangeID));\n\t}\n}\n\ninterface CanCreateExchange {\n\treadonly isQuote: boolean;\n\n\tget request(): ConversionInputCanonical;\n\n\tcreateExchange(block?: InstanceType<typeof KeetaNetLib.Block>, options?: KeetaFXAnchorCreateExchangeOptions): Promise<KeetaFXAnchorExchangeWithProvider>;\n\n\tcheckExchange(options?: Pick<KeetaFXAnchorCreateExchangeOptions, 'limits'>): void;\n}\n\nclass KeetaFXAnchorQuoteWithProvider implements CanCreateExchange {\n\treadonly provider: KeetaFXAnchorProviderBase;\n\treadonly quote: KeetaFXAnchorQuote;\n\treadonly isQuote = true as const;\n\n\tconstructor(provider: KeetaFXAnchorProviderBase, quote: KeetaFXAnchorQuote) {\n\t\tthis.provider = provider;\n\t\tthis.quote = quote;\n\t}\n\n\tget request(): ConversionInputCanonical {\n\t\treturn(this.quote.request);\n\t}\n\n\tasync createExchange(block?: InstanceType<typeof KeetaNetLib.Block>, options?: KeetaFXAnchorCreateExchangeOptions): Promise<KeetaFXAnchorExchangeWithProvider> {\n\t\tconst exchange = await this.provider.createExchange({ quote: this.quote }, block, options);\n\t\treturn(new KeetaFXAnchorExchangeWithProvider(this.provider, exchange));\n\t}\n\n\t/**\n\t * Checks this quote's terms as `createExchange` would, without\n\t * signing. See {@link KeetaFXAnchorProviderBase.checkExchange}.\n\t */\n\tcheckExchange(options?: Pick<KeetaFXAnchorCreateExchangeOptions, 'limits'>): void {\n\t\tthis.provider.checkExchange({ quote: this.quote }, options);\n\t}\n\n\t/**\n\t * Re-fetch the quote from the provider.\n\t *\n\t * @returns a new KeetaFXAnchorQuoteWithProvider with the updated quote\n\t */\n\tasync refetch(): Promise<KeetaFXAnchorQuoteWithProvider> {\n\t\tconst quote = await this.provider.getQuote();\n\t\treturn(new KeetaFXAnchorQuoteWithProvider(this.provider, quote));\n\t}\n}\n\nclass KeetaFXAnchorEstimateWithProvider implements CanCreateExchange {\n\treadonly provider: KeetaFXAnchorProviderBase;\n\treadonly estimate: KeetaFXAnchorEstimate;\n\treadonly isQuote = false as const;\n\n\tconstructor(provider: KeetaFXAnchorProviderBase, estimate: KeetaFXAnchorEstimate) {\n\t\tthis.provider = provider;\n\t\tthis.estimate = estimate;\n\t}\n\n\tget request(): ConversionInputCanonical {\n\t\treturn(this.estimate.request);\n\t}\n\n\tasync getQuote(tolerance?: number): Promise<KeetaFXAnchorQuoteWithProvider> {\n\t\tconst quote = await this.provider.getQuote(this.estimate, tolerance);\n\t\treturn(new KeetaFXAnchorQuoteWithProvider(this.provider, quote));\n\t}\n\n\tasync createExchange(block?: InstanceType<typeof KeetaNetLib.Block>, options?: KeetaFXAnchorCreateExchangeOptions): Promise<KeetaFXAnchorExchangeWithProvider> {\n\t\tconst exchange = await this.provider.createExchange({ estimate: this.estimate }, block, options);\n\t\treturn(new KeetaFXAnchorExchangeWithProvider(this.provider, exchange));\n\t}\n\n\t/**\n\t * Checks this estimate's terms as `createExchange` would, without\n\t * signing. See {@link KeetaFXAnchorProviderBase.checkExchange}.\n\t */\n\tcheckExchange(options?: Pick<KeetaFXAnchorCreateExchangeOptions, 'limits'>): void {\n\t\tthis.provider.checkExchange({ estimate: this.estimate }, options);\n\t}\n\n\t/**\n\t * Re-fetch the estimate from the provider.\n\t *\n\t * @returns a new KeetaFXAnchorEstimateWithProvider with the updated estimate\n\t */\n\tasync refetch(): Promise<KeetaFXAnchorEstimateWithProvider> {\n\t\tconst estimate = await this.provider.getEstimate();\n\t\treturn(new KeetaFXAnchorEstimateWithProvider(this.provider, estimate));\n\t}\n}\n\ninterface GetProvidersOptions extends AccountOptions {\n\trequiredOperations?: (keyof KeetaFXAnchorOperations)[];\n}\n\ninterface GetPricesAssetReturnValue {\n\tvalue: bigint;\n\t/**\n\t * The mean of every provider's converted amount, in base units of the\n\t * converted token. Rounded down for affinity \"from\" and up for \"to\".\n\t */\n\taverageConvertedAmount: bigint;\n\tproviderMarketPrices: {\n\t\tprovider: KeetaFXAnchorProviderBase;\n\t\tprice: KeetaFXAnchorMarketPriceRatio;\n\t}[];\n\tproviderEstimates: KeetaFXAnchorEstimateWithProvider[];\n}\n\nfunction providerSupportsGetMarketPrices(provider: KeetaFXAnchorProviderBase): boolean {\n\treturn(Object.prototype.hasOwnProperty.call(provider.serviceInfo.operations, 'getMarketPrices'));\n}\n\nfunction divideRoundingUp(numerator: bigint, denominator: bigint): bigint {\n\tconst quotient = numerator / denominator;\n\tif (numerator % denominator !== 0n) {\n\t\treturn(quotient + 1n);\n\t}\n\n\treturn(quotient);\n}\n\nfunction convertUsingMarketPriceRatio(\n\tratio: KeetaFXAnchorMarketPriceRatio,\n\tconversionValue: bigint,\n\taffinity: 'from' | 'to'\n): bigint {\n\tconst quote = BigInt(ratio.quote);\n\tconst base = BigInt(ratio.base);\n\tif (quote === 0n || base === 0n) {\n\t\tthrow(new Error(`Invalid market price ratio: quote=${ratio.quote} base=${ratio.base}`));\n\t}\n\n\t/*\n\t * Round in the provider's favor, as estimates do: down for what is\n\t * received (affinity \"from\"), up for what has to be sent (affinity \"to\").\n\t */\n\tif (affinity === 'from') {\n\t\treturn(conversionValue * base / quote);\n\t}\n\n\treturn(divideRoundingUp(conversionValue * quote, base));\n}\n\nexport interface GetPricesArgs<Asset extends ConversionInput['from']> {\n\tassets: Asset[],\n\tpriceIn: ConversionInput['from'],\n\tconversionValue?: bigint | ((input: Asset) => bigint | Promise<bigint>)\n\tconversionAffinity?: ConversionInput['affinity']\n\t/**\n\t * Behavior when a provider returns an invalid market price ratio\n\t * (e.g. zero quote/base). Defaults to `'omit'`.\n\t *\n\t * Invalid ratios are always logged regardless of this setting.\n\t */\n\tonInvalidRatio?: 'omit' | 'throw';\n}\n\nclass KeetaFXAnchorClient extends KeetaFXAnchorBase {\n\treadonly resolver: Resolver;\n\treadonly id: string;\n\treadonly #signer: InstanceType<typeof KeetaNetLib.Account>;\n\treadonly #account: InstanceType<typeof KeetaNetLib.Account>;\n\treadonly #getPricesBatching: Required<KeetaFXAnchorClientGetPricesBatching>;\n\treadonly #defaultLimits: ResolvedDefaultLimits;\n\treadonly #pendingGetMarketPricesBatches = new Map<string, {\n\t\tprovider: KeetaFXAnchorProviderBase;\n\t\tbase: KeetaNetTokenPublicKeyString;\n\t\tquoteAssets: Set<KeetaNetTokenPublicKeyString>;\n\t\twaiters: {\n\t\t\tresolve: (prices: KeetaFXAnchorMarketPrices) => void;\n\t\t\treject: (error: unknown) => void;\n\t\t}[];\n\t\twaitTimer: ReturnType<typeof setTimeout> | null;\n\t\tmaxWaitTimer: ReturnType<typeof setTimeout> | null;\n\t}>();\n\n\tstatic #resolveGetPricesBatching(input?: KeetaFXAnchorClientGetPricesBatching | boolean): Required<KeetaFXAnchorClientGetPricesBatching> {\n\t\tif (input === false) {\n\t\t\treturn({ waitMs: 0, maxWaitMs: 0 });\n\t\t} else {\n\t\t\tif (input === true || input === undefined) {\n\t\t\t\tinput = { waitMs: 25 }\n\t\t\t}\n\n\t\t\treturn({\n\t\t\t\twaitMs: input.waitMs,\n\t\t\t\tmaxWaitMs: input.maxWaitMs ?? (input.waitMs * 4)\n\t\t\t});\n\t\t}\n\t}\n\n\tconstructor(client: KeetaNetUserClient, config: KeetaFXAnchorClientConfig = {}) {\n\t\tsuper({ client, logger: config.logger });\n\t\tthis.resolver = config.resolver ?? getDefaultResolver(client, config);\n\t\tthis.id = config.id ?? crypto.randomUUID();\n\t\tthis.#getPricesBatching = KeetaFXAnchorClient.#resolveGetPricesBatching(config.getPricesBatching);\n\t\tthis.#defaultLimits = resolveDefaultLimits(config.defaultLimits);\n\n\t\tif (!Number.isFinite(this.#getPricesBatching.waitMs) || this.#getPricesBatching.waitMs < 0) {\n\t\t\tthrow(new Error('getPricesBatching.waitMs must be a non-negative finite number'));\n\t\t}\n\t\tif (!Number.isFinite(this.#getPricesBatching.maxWaitMs) || this.#getPricesBatching.maxWaitMs < 0) {\n\t\t\tthrow(new Error('getPricesBatching.maxWaitMs must be a non-negative finite number'));\n\t\t}\n\t\tif (this.#getPricesBatching.maxWaitMs < this.#getPricesBatching.waitMs) {\n\t\t\tthrow(new Error('getPricesBatching.maxWaitMs must be greater than or equal to waitMs'));\n\t\t}\n\n\t\tif (config.signer) {\n\t\t\tthis.#signer = config.signer;\n\t\t} else if ('signer' in client && client.signer !== null) {\n\t\t\tthis.#signer = client.signer;\n\t\t} else if ('account' in client && client.account.hasPrivateKey) {\n\t\t\tthis.#signer = client.account;\n\t\t} else {\n\t\t\tthrow(new Error('KeetaFXAnchorClient requires a Signer or a UserClient with an associated Signer'));\n\t\t}\n\n\t\tif (config.account) {\n\t\t\tthis.#account = config.account;\n\t\t} else if ('account' in client) {\n\t\t\tthis.#account = client.account;\n\t\t} else {\n\t\t\tthrow(new Error('KeetaFXAnchorClient requires an Account or a UserClient with an associated Account'));\n\t\t}\n\t}\n\n\t#getMarketPricesBatchKey(providerID: ProviderID, base: KeetaNetTokenPublicKeyString): string {\n\t\treturn(`${String(providerID)}\\0${base}`);\n\t}\n\n\t#flushGetMarketPricesBatch(batchKey: string) {\n\t\tconst batch = this.#pendingGetMarketPricesBatches.get(batchKey);\n\t\tif (batch === undefined) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.#pendingGetMarketPricesBatches.delete(batchKey);\n\t\tif (batch.waitTimer !== null) {\n\t\t\tclearTimeout(batch.waitTimer);\n\t\t}\n\t\tif (batch.maxWaitTimer !== null) {\n\t\t\tclearTimeout(batch.maxWaitTimer);\n\t\t}\n\n\t\tconst quoteAssets = [...batch.quoteAssets];\n\t\tbatch.provider.getMarketPrices({ quoteAssets, base: batch.base }).then(function(marketPrices) {\n\t\t\tfor (const waiter of batch.waiters) {\n\t\t\t\twaiter.resolve(marketPrices);\n\t\t\t}\n\t\t}, function(error: unknown) {\n\t\t\tfor (const waiter of batch.waiters) {\n\t\t\t\twaiter.reject(error);\n\t\t\t}\n\t\t});\n\t}\n\n\t#getMarketPricesBatched(provider: KeetaFXAnchorProviderBase, request: KeetaFXAnchorMarketPricesRequest): Promise<KeetaFXAnchorMarketPrices> {\n\t\tconst batching = this.#getPricesBatching;\n\t\tif (batching.waitMs === 0 && batching.maxWaitMs === 0) {\n\t\t\treturn(provider.getMarketPrices(request));\n\t\t}\n\n\t\tconst batchKey = this.#getMarketPricesBatchKey(provider.providerID, request.base);\n\t\tlet batch = this.#pendingGetMarketPricesBatches.get(batchKey);\n\t\tif (batch === undefined) {\n\t\t\tbatch = {\n\t\t\t\tprovider,\n\t\t\t\tbase: request.base,\n\t\t\t\tquoteAssets: new Set(),\n\t\t\t\twaiters: [],\n\t\t\t\twaitTimer: null,\n\t\t\t\tmaxWaitTimer: null\n\t\t\t};\n\t\t\tthis.#pendingGetMarketPricesBatches.set(batchKey, batch);\n\n\t\t\tbatch.maxWaitTimer = setTimeout(() => {\n\t\t\t\tthis.#flushGetMarketPricesBatch(batchKey);\n\t\t\t}, batching.maxWaitMs);\n\t\t}\n\n\t\tfor (const quoteAsset of request.quoteAssets) {\n\t\t\tbatch.quoteAssets.add(quoteAsset);\n\t\t}\n\n\t\tconst activeBatch = batch;\n\t\tconst result = new Promise<KeetaFXAnchorMarketPrices>(function(resolve, reject) {\n\t\t\tactiveBatch.waiters.push({ resolve, reject });\n\t\t});\n\n\t\tif (activeBatch.waitTimer !== null) {\n\t\t\tclearTimeout(activeBatch.waitTimer);\n\t\t}\n\n\t\tif (batching.waitMs === 0) {\n\t\t\tthis.#flushGetMarketPricesBatch(batchKey);\n\t\t} else {\n\t\t\tactiveBatch.waitTimer = setTimeout(() => {\n\t\t\t\tthis.#flushGetMarketPricesBatch(batchKey);\n\t\t\t}, batching.waitMs);\n\t\t}\n\n\t\treturn(result);\n\t}\n\n\tprivate async canonicalizeConversionTokens(input: Partial<ConversionInput>): Promise<Partial<Pick<ConversionInputCanonical, 'from' | 'to'>>> {\n\t\tlet from = {}\n\t\tif (input.from !== undefined) {\n\t\t\tlet fromToken: ConversionInputCanonical['from'];\n\t\t\tif (KeetaNetLib.Account.isInstance(input.from) && input.from.isToken()) {\n\t\t\t\tfromToken = input.from;\n\t\t\t} else {\n\t\t\t\tconst tokenLookup = await this.resolver.lookupToken(input.from);\n\t\t\t\tif (tokenLookup === null) {\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-base-to-string\n\t\t\t\t\tthrow(new Error(`Could not convert from: ${input.from} to a token address`));\n\t\t\t\t}\n\t\t\t\tfromToken = KeetaNetLib.Account.fromPublicKeyString(tokenLookup.token);\n\t\t\t}\n\t\t\tfrom = { from: fromToken };\n\t\t}\n\n\t\tlet to = {};\n\t\tif (input.to !== undefined) {\n\t\t\tlet toToken: ConversionInputCanonical['to'];\n\t\t\tif (KeetaNetLib.Account.isInstance(input.to) && input.to.isToken()) {\n\t\t\t\ttoToken = input.to;\n\t\t\t} else {\n\t\t\t\tconst tokenLookup = await this.resolver.lookupToken(input.to);\n\t\t\t\tif (tokenLookup === null) {\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-base-to-string\n\t\t\t\t\tthrow(new Error(`Could not convert to: ${input.to} to a token address`));\n\t\t\t\t}\n\t\t\t\ttoToken = KeetaNetLib.Account.fromPublicKeyString(tokenLookup.token);\n\t\t\t}\n\t\t\tto = { to: toToken };\n\t\t}\n\t\treturn({ ...from, ...to });\n\t}\n\n\tprivate async canonicalizeConversionInput(input: ConversionInput): Promise<ConversionInputCanonical> {\n\t\tconst amount = BigInt(input.amount);\n\t\tif (amount < 0) {\n\t\t\tthrow(new Error('Invalid Conversion Amount'));\n\t\t}\n\n\t\tconst { from, to } = await this.canonicalizeConversionTokens(input);\n\n\t\tif (from === undefined || to === undefined) {\n\t\t\tthrow(new Error('From and To are both required for a conversion'));\n\t\t}\n\n\t\tconst canonical: ConversionInputCanonical = {\n\t\t\tfrom,\n\t\t\tto,\n\t\t\tamount: amount,\n\t\t\taffinity: input.affinity\n\t\t};\n\n\t\tif (input.preferredCostAsset !== undefined) {\n\t\t\tcanonical.preferredCostAsset = input.preferredCostAsset;\n\t\t}\n\n\t\treturn(canonical);\n\t}\n\n\tasync listPossibleConversions(input: Partial<Pick<ConversionInput, 'from' | 'to'>>, options: AccountOptions = {}, sharedCriteria?: SharedLookupCriteria): Promise<{ conversions: KeetaNetTokenPublicKeyString[] } | null> {\n\t\tif (input.from !== undefined && input.to !== undefined) {\n\t\t\tthrow(new KeetaAnchorUserError('Only one of from or two should be provided'));\n\t\t}\n\t\tif (input.from === undefined && input.to === undefined) {\n\t\t\tthrow(new KeetaAnchorUserError('At least one of from or two should be provided'));\n\t\t}\n\t\tconst conversion = await this.canonicalizeConversionTokens(input);\n\t\tconst account = options.account ?? this.#account;\n\t\tconst providerEndpoints = await getEndpoints(this.resolver, conversion, account, sharedCriteria, { logger: this.logger });\n\t\tif (providerEndpoints === null) {\n\t\t\treturn(null);\n\t\t}\n\n\t\tconst conversions = new Set<KeetaNetTokenPublicKeyString>();\n\t\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\t\tfor (const [_ignored_providerID, serviceInfo] of typedFxServiceEntries(providerEndpoints)) {\n\t\t\tfor (const conversionPair of serviceInfo.from) {\n\t\t\t\tif (conversion.from !== undefined) {\n\t\t\t\t\tif (conversionPair.currencyCodes.includes(conversion.from.publicKeyString.get())) {\n\t\t\t\t\t\tconversionPair.to.forEach((token) => {\n\t\t\t\t\t\t\tif (conversion.from?.publicKeyString.get() !== token) {\n\t\t\t\t\t\t\t\tconversions.add(token);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t} else if (conversion.to !== undefined) {\n\t\t\t\t\tif (conversionPair.to.includes(conversion.to.publicKeyString.get())) {\n\t\t\t\t\t\tconversionPair.currencyCodes.forEach((token) => {\n\t\t\t\t\t\t\tif (conversion.to?.publicKeyString.get() !== token) {\n\t\t\t\t\t\t\t\tconversions.add(token);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\n\t\treturn({ conversions: [...conversions] });\n\t}\n\n\tasync getBaseProvidersForConversion(request: ConversionInput, options: GetProvidersOptions = {}, sharedCriteria?: SharedLookupCriteria): Promise<KeetaFXAnchorProviderBase[] | null> {\n\t\tconst conversion = await this.canonicalizeConversionInput(request);\n\t\tconst account = options.account ?? this.#account;\n\t\tconst providerEndpoints = await getEndpoints(this.resolver, conversion, account, sharedCriteria, { logger: this.logger });\n\t\tif (providerEndpoints === null) {\n\t\t\treturn(null);\n\t\t}\n\n\t\tconst providers = typedFxServiceEntries(providerEndpoints).map(([providerID, serviceInfo]) => {\n\t\t\treturn(new KeetaFXAnchorProviderBase(serviceInfo, providerID, conversion, this, options));\n\t\t});\n\n\t\treturn(providers);\n\t}\n\n\t/**\n\t * Resolve an FX provider by the account that signs its advertised service metadata.\n\t */\n\tasync getProviderByAccount(anchor: AnchorReference, requiredOperations?: (keyof KeetaFXAnchorOperations)[]): Promise<KeetaFXAnchorProviderBase | null> {\n\t\tconst request: Parameters<typeof getEndpoints>[1] = {};\n\t\tif (requiredOperations !== undefined) {\n\t\t\trequest.requiredOperations = requiredOperations;\n\t\t}\n\n\t\tconst providerEndpoints = await getEndpoints(this.resolver, request, this.#account, { accounts: [ anchor ] }, { logger: this.logger });\n\t\tif (providerEndpoints === null) {\n\t\t\treturn(null);\n\t\t}\n\n\t\tconst [ entry ] = typedFxServiceEntries(providerEndpoints);\n\t\tif (entry === undefined) {\n\t\t\treturn(null);\n\t\t}\n\n\t\tconst [ providerID, serviceInfo ] = entry;\n\n\t\tconst pair = serviceInfo.from[0];\n\t\tif (pair === undefined) {\n\t\t\treturn(null);\n\t\t}\n\n\t\tconst fromCode = pair.currencyCodes[0];\n\t\tconst toCode = pair.to[0];\n\t\tif (fromCode === undefined || toCode === undefined) {\n\t\t\treturn(null);\n\t\t}\n\n\t\tconst conversion: ConversionInputCanonical = {\n\t\t\tfrom: KeetaNetLib.Account.fromPublicKeyString(fromCode),\n\t\t\tto: KeetaNetLib.Account.fromPublicKeyString(toCode),\n\t\t\tamount: 0n,\n\t\t\taffinity: 'from'\n\t\t};\n\n\t\tconst provider = new KeetaFXAnchorProviderBase(serviceInfo, providerID, conversion, this);\n\t\treturn(provider);\n\t}\n\n\tasync getEstimates(request: ConversionInput, options: Omit<GetProvidersOptions, 'requiredOperations'> = {}, sharedCriteria?: SharedLookupCriteria): Promise<KeetaFXAnchorEstimateWithProvider[] | null> {\n\t\tconst estimateProviders = await this.getBaseProvidersForConversion(request, {\n\t\t\t...options,\n\t\t\trequiredOperations: ['getEstimate']\n\t\t}, sharedCriteria);\n\n\t\tif (estimateProviders === null) {\n\t\t\treturn(null);\n\t\t}\n\n\t\tconst estimates = await Promise.all(estimateProviders.map(async (provider) => {\n\t\t\ttry {\n\t\t\t\tconst estimate = await provider.getEstimate();\n\n\t\t\t\treturn(new KeetaFXAnchorEstimateWithProvider(provider, estimate));\n\t\t\t} catch (error) {\n\t\t\t\tif (FXErrors.ResponseMismatch.isInstance(error)) {\n\t\t\t\t\tthis.logger?.warn(`Ignoring estimate from FX provider ${String(provider.providerID)}:`, error);\n\t\t\t\t} else {\n\t\t\t\t\tthis.logger?.error(`Failed to get estimate from provider ${String(provider.providerID)}:`, error);\n\t\t\t\t}\n\n\t\t\t\treturn(null);\n\t\t\t}\n\t\t}));\n\n\t\tconst results = estimates.filter(function(result) {\n\t\t\treturn(result !== null);\n\t\t});\n\n\t\tif (results.length === 0) {\n\t\t\treturn(null);\n\t\t}\n\n\t\treturn(results);\n\t}\n\n\tasync #multiRequestQuotes(request: ConversionInput, options: AccountOptions = {}, sharedCriteria?: SharedLookupCriteria): Promise<({\n\t\tprovider: KeetaFXAnchorProviderBase;\n\t} & ({\n\t\tquote: KeetaFXAnchorQuoteWithProvider;\n\t} | {\n\t\tquote: null;\n\t\terror: unknown;\n\t}))[]> {\n\t\tconst estimateProviders = await this.getBaseProvidersForConversion(request, {\n\t\t\t...options,\n\t\t\trequiredOperations: ['getQuote']\n\t\t}, sharedCriteria);\n\t\tif (estimateProviders === null) {\n\t\t\treturn([]);\n\t\t}\n\n\t\treturn(await Promise.all(estimateProviders.map(async (provider) => {\n\t\t\ttry {\n\t\t\t\tconst quote = await provider.getQuote();\n\t\t\t\treturn({ provider, quote: new KeetaFXAnchorQuoteWithProvider(provider, quote) });\n\t\t\t} catch (error) {\n\t\t\t\tif (FXErrors.ResponseMismatch.isInstance(error)) {\n\t\t\t\t\tthis.logger?.warn(`Ignoring quote from FX provider ${String(provider.providerID)}:`, error);\n\t\t\t\t}\n\n\t\t\t\treturn({ provider, quote: null, error });\n\t\t\t}\n\t\t})));\n\t}\n\n\n\tasync getQuotes(request: ConversionInput, options: AccountOptions = {}, sharedCriteria?: SharedLookupCriteria): Promise<KeetaFXAnchorQuoteWithProvider[] | null> {\n\t\tconst quotes = await this.#multiRequestQuotes(request, options, sharedCriteria);\n\n\t\tconst results = quotes\n\t\t\t.map(function(quote) {\n\t\t\t\treturn(quote.quote);\n\t\t\t})\n\t\t\t.filter(function(quote): quote is KeetaFXAnchorQuoteWithProvider {\n\t\t\t\treturn(quote !== null);\n\t\t\t});\n\n\t\tif (results.length === 0) {\n\t\t\treturn(null);\n\t\t}\n\n\t\treturn(results);\n\t}\n\n\tasync getQuotesOrEstimates(request: ConversionInput, options: AccountOptions = {}, sharedCriteria?: SharedLookupCriteria): Promise<(KeetaFXAnchorQuoteWithProvider | KeetaFXAnchorEstimateWithProvider)[] | null> {\n\t\tconst [ quotesAndEstimates, estimateProviders ] = await Promise.all([\n\t\t\tthis.#multiRequestQuotes(request, options, sharedCriteria),\n\t\t\tthis.getBaseProvidersForConversion(request, {\n\t\t\t\t...options,\n\t\t\t\trequiredOperations: ['getEstimate']\n\t\t\t}, sharedCriteria)\n\t\t]);\n\n\t\tconst estimateProviderIDs = new Set<ProviderID>();\n\n\t\tif (estimateProviders !== null) {\n\t\t\tfor (const provider of estimateProviders) {\n\t\t\t\testimateProviderIDs.add(provider.providerID);\n\t\t\t}\n\t\t}\n\n\t\tconst retval = [];\n\n\t\tfor (const quoteOrEstimate of quotesAndEstimates) {\n\t\t\tif (!quoteOrEstimate.quote) {\n\t\t\t\tif (quoteOrEstimate.error && !FXErrors.QuoteIssuanceDisabled.isInstance(quoteOrEstimate.error)) {\n\t\t\t\t\tthis.logger?.debug(`Failed to get quote from provider ${String(quoteOrEstimate.provider.providerID)}:`, quoteOrEstimate.error);\n\t\t\t\t}\n\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tretval.push(quoteOrEstimate.quote);\n\t\t\testimateProviderIDs.delete(quoteOrEstimate.provider.providerID);\n\t\t}\n\n\t\tconst estimates = await this.getEstimates(request, options, {\n\t\t\t...sharedCriteria,\n\t\t\tproviderIDs: Array.from(estimateProviderIDs).map(function(id) {\n\t\t\t\treturn(String(id));\n\t\t\t})\n\t\t});\n\n\t\tif (estimates !== null) {\n\t\t\tretval.push(...estimates);\n\t\t}\n\n\t\tif (retval.length === 0) {\n\t\t\treturn(null);\n\t\t}\n\n\t\treturn(retval);\n\t}\n\n\tasync getPrices<Asset extends ConversionInput['from']>(input: GetPricesArgs<Asset>, options: Omit<GetProvidersOptions, 'requiredOperations'> = {}, sharedCriteria?: SharedLookupCriteria): Promise<Map<Asset, GetPricesAssetReturnValue | null>> {\n\t\tconst priceInCanonical = await this.canonicalizeConversionTokens({ to: input.priceIn ?? 'USD' });\n\t\tif (priceInCanonical.to === undefined) {\n\t\t\tthrow(new Error('Could not canonicalize priceIn asset'));\n\t\t}\n\n\t\tconst base = priceInCanonical.to.publicKeyString.get();\n\t\tconst affinity = input.conversionAffinity ?? 'from';\n\t\tconst priceIn = input.priceIn ?? 'USD';\n\t\tconst onInvalidRatio = input.onInvalidRatio ?? 'omit';\n\n\t\tconst assetEntries = await Promise.all(input.assets.map(async (asset) => {\n\t\t\tconst canonical = await this.canonicalizeConversionTokens({ from: asset });\n\t\t\tif (canonical.from === undefined) {\n\t\t\t\tthrow(new Error(`Could not canonicalize asset: ${String(asset)}`));\n\t\t\t}\n\n\t\t\tlet conversionValue: bigint;\n\t\t\tif (input.conversionValue !== undefined) {\n\t\t\t\tif (typeof input.conversionValue === 'function') {\n\t\t\t\t\tconversionValue = await input.conversionValue(asset);\n\t\t\t\t} else {\n\t\t\t\t\tconversionValue = input.conversionValue;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tconversionValue = 1n;\n\t\t\t}\n\n\t\t\tconst providers = await this.getBaseProvidersForConversion({\n\t\t\t\tfrom: asset,\n\t\t\t\tto: priceIn,\n\t\t\t\tamount: conversionValue,\n\t\t\t\taffinity\n\t\t\t}, options, sharedCriteria);\n\n\t\t\treturn({\n\t\t\t\tasset,\n\t\t\t\tquoteAsset: canonical.from.publicKeyString.get(),\n\t\t\t\tconversionValue,\n\t\t\t\tproviders\n\t\t\t});\n\t\t}));\n\n\t\ttype ProviderAssetEntry = {\n\t\t\tasset: Asset;\n\t\t\tquoteAsset: KeetaNetTokenPublicKeyString;\n\t\t\tconversionValue: bigint;\n\t\t\tprovider: KeetaFXAnchorProviderBase;\n\t\t};\n\n\t\ttype EstimateAssetEntry = {\n\t\t\tasset: Asset;\n\t\t\tconversionValue: bigint;\n\t\t\tprovider: KeetaFXAnchorProviderBase;\n\t\t};\n\n\t\tconst providerAssets = new Map<ProviderID, ProviderAssetEntry[]>();\n\t\tconst estimateEntries: EstimateAssetEntry[] = [];\n\t\tfor (const entry of assetEntries) {\n\t\t\tif (entry.providers === null) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tfor (const provider of entry.providers) {\n\t\t\t\tif (providerSupportsGetMarketPrices(provider)) {\n\t\t\t\t\tconst existing = providerAssets.get(provider.providerID) ?? [];\n\t\t\t\t\texisting.push({\n\t\t\t\t\t\tasset: entry.asset,\n\t\t\t\t\t\tquoteAsset: entry.quoteAsset,\n\t\t\t\t\t\tconversionValue: entry.conversionValue,\n\t\t\t\t\t\tprovider\n\t\t\t\t\t});\n\t\t\t\t\tproviderAssets.set(provider.providerID, existing);\n\t\t\t\t} else {\n\t\t\t\t\testimateEntries.push({\n\t\t\t\t\t\tasset: entry.asset,\n\t\t\t\t\t\tconversionValue: entry.conversionValue,\n\t\t\t\t\t\tprovider\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tconst providerPriceResults = await Promise.all([...providerAssets.entries()].map(async ([_ignore_providerID, entries]) => {\n\t\t\tconst firstEntry = entries[0];\n\t\t\tif (firstEntry === undefined) {\n\t\t\t\treturn(null);\n\t\t\t}\n\n\t\t\tconst provider = firstEntry.provider;\n\t\t\tconst quoteAssets = [...new Set(entries.map(function(entry) {\n\t\t\t\treturn(entry.quoteAsset);\n\t\t\t}))];\n\n\t\t\ttry {\n\t\t\t\tconst marketPrices = await this.#getMarketPricesBatched(provider, { quoteAssets, base });\n\t\t\t\treturn({ provider, marketPrices, entries });\n\t\t\t} catch (error) {\n\t\t\t\tthis.logger?.error(`Failed to get market prices from provider ${String(provider.providerID)}:`, error);\n\t\t\t\treturn(null);\n\t\t\t}\n\t\t}));\n\n\t\tconst assetProviderPrices = new Map<Asset, GetPricesAssetReturnValue['providerMarketPrices']>();\n\t\tfor (const result of providerPriceResults) {\n\t\t\tif (result === null) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tfor (const entry of result.entries) {\n\t\t\t\tconst priceEntry = result.marketPrices.quoteAssets[entry.quoteAsset];\n\t\t\t\tif (priceEntry === undefined) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\ttry {\n\t\t\t\t\t// Validate ratio early so convertUsingMarketPriceRatio cannot crash the batch later.\n\t\t\t\t\tconvertUsingMarketPriceRatio(priceEntry.valueRatio, entry.conversionValue, affinity);\n\t\t\t\t} catch (error) {\n\t\t\t\t\tthis.logger?.error(`Invalid market price ratio from provider ${String(result.provider.providerID)} for quote asset ${entry.quoteAsset} against base ${base}:`, error, priceEntry.valueRatio);\n\t\t\t\t\tif (onInvalidRatio === 'throw') {\n\t\t\t\t\t\tthrow(error);\n\t\t\t\t\t}\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tconst prices = assetProviderPrices.get(entry.asset) ?? [];\n\t\t\t\tprices.push({\n\t\t\t\t\tprovider: result.provider,\n\t\t\t\t\tprice: priceEntry.valueRatio\n\t\t\t\t});\n\t\t\t\tassetProviderPrices.set(entry.asset, prices);\n\t\t\t}\n\t\t}\n\n\t\tconst estimateResults = await Promise.all(estimateEntries.map(async (entry) => {\n\t\t\ttry {\n\t\t\t\tconst estimate = await entry.provider.getEstimate();\n\t\t\t\treturn({\n\t\t\t\t\tasset: entry.asset,\n\t\t\t\t\testimate: new KeetaFXAnchorEstimateWithProvider(entry.provider, estimate)\n\t\t\t\t});\n\t\t\t} catch (error) {\n\t\t\t\tthis.logger?.error(`Failed to get estimate from provider ${String(entry.provider.providerID)}:`, error);\n\t\t\t\treturn(null);\n\t\t\t}\n\t\t}));\n\n\t\tconst assetProviderEstimates = new Map<Asset, KeetaFXAnchorEstimateWithProvider[]>();\n\t\tfor (const result of estimateResults) {\n\t\t\tif (result === null) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst estimates = assetProviderEstimates.get(result.asset) ?? [];\n\t\t\testimates.push(result.estimate);\n\t\t\tassetProviderEstimates.set(result.asset, estimates);\n\t\t}\n\n\t\tconst retval = new Map<Asset, GetPricesAssetReturnValue | null>();\n\t\tfor (const entry of assetEntries) {\n\t\t\tconst providerMarketPrices = assetProviderPrices.get(entry.asset) ?? [];\n\t\t\tconst providerEstimates = assetProviderEstimates.get(entry.asset) ?? [];\n\t\t\tif (providerMarketPrices.length === 0 && providerEstimates.length === 0) {\n\t\t\t\tretval.set(entry.asset, null);\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst convertedAmountSum = [\n\t\t\t\t...providerMarketPrices.map(function(providerPrice) {\n\t\t\t\t\treturn(convertUsingMarketPriceRatio(providerPrice.price, entry.conversionValue, affinity));\n\t\t\t\t}),\n\t\t\t\t...providerEstimates.map(function(providerEstimate) {\n\t\t\t\t\treturn(providerEstimate.estimate.convertedAmount);\n\t\t\t\t})\n\t\t\t].reduce(function(sum, convertedAmount) {\n\t\t\t\treturn(sum + convertedAmount);\n\t\t\t}, 0n);\n\n\t\t\tconst providerCount = providerMarketPrices.length + providerEstimates.length;\n\n\t\t\tretval.set(entry.asset, {\n\t\t\t\tvalue: entry.conversionValue,\n\t\t\t\taverageConvertedAmount: affinity === 'from' ? convertedAmountSum / BigInt(providerCount) : divideRoundingUp(convertedAmountSum, BigInt(providerCount)),\n\t\t\t\tproviderMarketPrices,\n\t\t\t\tproviderEstimates\n\t\t\t});\n\t\t}\n\n\t\treturn(retval);\n\t}\n\n\tasync getLegalDisclaimersById(providerID: string): Promise<NonNullable<AnchorMetadataLegalField['disclaimers']> | null>{\n\t\tconst endpoints = await getEndpoints(this.resolver, {}, this.#account, { providerIDs: [providerID] }, { logger: this.logger });\n\t\tif (endpoints === null) {\n\t\t\treturn(null);\n\t\t}\n\n\t\tconst serviceEntry = typedFxServiceEntries(endpoints)[0];\n\t\tif (!serviceEntry) {\n\t\t\treturn(null);\n\t\t}\n\n\t\tconst disclaimers = serviceEntry[1].legal?.disclaimers;\n\t\tif (!disclaimers || disclaimers.length === 0) {\n\t\t\treturn(null)\n\t\t}\n\n\t\treturn(disclaimers);\n\t}\n\n\tasync getMarketPrices(providerID: string, request: KeetaFXAnchorMarketPricesRequest): Promise<KeetaFXAnchorMarketPrices | null> {\n\t\tconst endpoints = await getEndpoints(this.resolver, {\n\t\t\trequiredOperations: ['getMarketPrices']\n\t\t}, this.#account, { providerIDs: [providerID] }, { logger: this.logger });\n\t\tif (endpoints === null) {\n\t\t\treturn(null);\n\t\t}\n\n\t\tconst serviceEntry = typedFxServiceEntries(endpoints)[0];\n\t\tif (!serviceEntry) {\n\t\t\treturn(null);\n\t\t}\n\n\t\tconst [ resolvedProviderID, serviceInfo ] = serviceEntry;\n\t\tconst provider = new KeetaFXAnchorProviderBase(serviceInfo, resolvedProviderID, {\n\t\t\tfrom: KeetaNetLib.Account.fromPublicKeyString(request.quoteAssets[0] ?? request.base),\n\t\t\tto: KeetaNetLib.Account.fromPublicKeyString(request.base),\n\t\t\tamount: 1n,\n\t\t\taffinity: 'from'\n\t\t}, this);\n\n\t\treturn(await provider.getMarketPrices(request));\n\t}\n\n\t/** @internal */\n\t_internals(accessToken: symbol) {\n\t\tif (accessToken !== KeetaFXAnchorClientAccessToken) {\n\t\t\tthrow(new Error('invalid access token'));\n\t\t}\n\n\t\treturn({\n\t\t\tresolver: this.resolver,\n\t\t\tlogger: this.logger,\n\t\t\tclient: this.client,\n\t\t\tsigner: this.#signer,\n\t\t\taccount: this.#account,\n\t\t\tdefaultLimits: this.#defaultLimits\n\t\t});\n\n\t}\n}\n\nexport default KeetaFXAnchorClient;\n"]}
|
package/services/fx/common.d.ts
CHANGED
|
@@ -113,13 +113,16 @@ export type KeetaFXAnchorEstimateResponse = ({
|
|
|
113
113
|
ok: false;
|
|
114
114
|
error: string;
|
|
115
115
|
});
|
|
116
|
+
/**
|
|
117
|
+
* Base-unit exchange rate: a client converts with amount * base / quote. Not a whole-token price.
|
|
118
|
+
*/
|
|
116
119
|
export type KeetaFXAnchorMarketPriceRatio = {
|
|
117
120
|
/**
|
|
118
|
-
* Amount of the base (destination) token in the price ratio
|
|
121
|
+
* Amount of the base (destination) token in the price ratio, in base units
|
|
119
122
|
*/
|
|
120
123
|
base: string;
|
|
121
124
|
/**
|
|
122
|
-
* Amount of the quote (source) token in the price ratio
|
|
125
|
+
* Amount of the quote (source) token in the price ratio, in base units
|
|
123
126
|
*/
|
|
124
127
|
quote: string;
|
|
125
128
|
};
|