@keetanetwork/anchor 0.0.12 → 0.0.14

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.
Files changed (81) hide show
  1. package/lib/certificates.d.ts +83 -21
  2. package/lib/certificates.d.ts.map +1 -1
  3. package/lib/certificates.generated.d.ts +3 -0
  4. package/lib/certificates.generated.d.ts.map +1 -0
  5. package/lib/certificates.generated.js +120 -0
  6. package/lib/certificates.generated.js.map +1 -0
  7. package/lib/certificates.js +579 -117
  8. package/lib/certificates.js.map +1 -1
  9. package/lib/http-server.d.ts +2 -1
  10. package/lib/http-server.d.ts.map +1 -1
  11. package/lib/http-server.js +4 -4
  12. package/lib/http-server.js.map +1 -1
  13. package/lib/resolver.d.ts +2 -1
  14. package/lib/resolver.d.ts.map +1 -1
  15. package/lib/resolver.js.map +1 -1
  16. package/lib/utils/asn1.d.ts +2 -1
  17. package/lib/utils/asn1.d.ts.map +1 -1
  18. package/lib/utils/asn1.js.map +1 -1
  19. package/lib/utils/buffer.d.ts +3 -0
  20. package/lib/utils/buffer.d.ts.map +1 -1
  21. package/lib/utils/buffer.js +26 -0
  22. package/lib/utils/buffer.js.map +1 -1
  23. package/lib/utils/guards.d.ts +14 -0
  24. package/lib/utils/guards.d.ts.map +1 -0
  25. package/lib/utils/guards.js +31 -0
  26. package/lib/utils/guards.js.map +1 -0
  27. package/lib/utils/index.d.ts +3 -1
  28. package/lib/utils/index.d.ts.map +1 -1
  29. package/lib/utils/index.js +3 -1
  30. package/lib/utils/index.js.map +1 -1
  31. package/lib/utils/json.d.ts +2 -2
  32. package/lib/utils/json.d.ts.map +1 -1
  33. package/lib/utils/json.js.map +1 -1
  34. package/lib/utils/oid.d.ts +7 -0
  35. package/lib/utils/oid.d.ts.map +1 -0
  36. package/lib/utils/oid.js +22 -0
  37. package/lib/utils/oid.js.map +1 -0
  38. package/lib/utils/signing.d.ts.map +1 -1
  39. package/lib/utils/signing.js +26 -2
  40. package/lib/utils/signing.js.map +1 -1
  41. package/npm-shrinkwrap.json +2 -8
  42. package/package.json +1 -2
  43. package/services/fx/client.d.ts +1 -0
  44. package/services/fx/client.d.ts.map +1 -1
  45. package/services/fx/client.js +72 -72
  46. package/services/fx/client.js.map +1 -1
  47. package/services/fx/common.d.ts +23 -14
  48. package/services/fx/common.d.ts.map +1 -1
  49. package/services/fx/common.js +177 -1
  50. package/services/fx/common.js.map +1 -1
  51. package/services/fx/server.d.ts +13 -4
  52. package/services/fx/server.d.ts.map +1 -1
  53. package/services/fx/server.js +58 -151
  54. package/services/fx/server.js.map +1 -1
  55. package/services/kyc/client.d.ts.map +1 -1
  56. package/services/kyc/client.js +1 -8
  57. package/services/kyc/client.js.map +1 -1
  58. package/services/kyc/common.d.ts +39 -3
  59. package/services/kyc/common.d.ts.map +1 -1
  60. package/services/kyc/common.generated.d.ts +5 -0
  61. package/services/kyc/common.generated.d.ts.map +1 -0
  62. package/services/kyc/common.generated.js +241 -0
  63. package/services/kyc/common.generated.js.map +1 -0
  64. package/services/kyc/common.js +68 -1
  65. package/services/kyc/common.js.map +1 -1
  66. package/services/kyc/iso20022.generated.d.ts +285 -0
  67. package/services/kyc/iso20022.generated.d.ts.map +1 -0
  68. package/services/kyc/iso20022.generated.js +205 -0
  69. package/services/kyc/iso20022.generated.js.map +1 -0
  70. package/services/kyc/oids.generated.d.ts +83 -0
  71. package/services/kyc/oids.generated.d.ts.map +1 -0
  72. package/services/kyc/oids.generated.js +130 -0
  73. package/services/kyc/oids.generated.js.map +1 -0
  74. package/services/kyc/server.d.ts +141 -0
  75. package/services/kyc/server.d.ts.map +1 -0
  76. package/services/kyc/server.js +183 -0
  77. package/services/kyc/server.js.map +1 -0
  78. package/services/kyc/utils/generate-kyc-schema.d.ts +3 -0
  79. package/services/kyc/utils/generate-kyc-schema.d.ts.map +1 -0
  80. package/services/kyc/utils/generate-kyc-schema.js +1154 -0
  81. package/services/kyc/utils/generate-kyc-schema.js.map +1 -0
@@ -1,36 +1,22 @@
1
- import * as __typia_transform__assertGuard from "typia/lib/internal/_assertGuard.js";
2
1
  import { lib as KeetaNetLib } from '@keetanetwork/keetanet-client';
3
- import { createAssert, createIs } from 'typia';
4
- import { Decimal } from 'decimal.js';
5
2
  import { getDefaultResolver } from '../../config.js';
6
3
  import { Buffer } from '../../lib/utils/buffer.js';
7
4
  import crypto from '../../lib/utils/crypto.js';
8
5
  import { validateURL } from '../../lib/utils/url.js';
6
+ import { assertKeetaNetTokenPublicKeyString, isKeetaFXAnchorEstimateResponse, isKeetaFXAnchorExchangeResponse, isKeetaFXAnchorQuoteResponse } from './common.js';
9
7
  import { KeetaAnchorUserError } from '../../lib/error.js';
10
8
  function typedFxServiceEntries(obj) {
11
9
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
12
10
  return Object.entries(obj);
13
11
  }
14
12
  const KeetaFXAnchorClientAccessToken = Symbol('KeetaFXAnchorClientAccessToken');
15
- const assertKeetaNetTokenPublicKeyString = (() => { const __is = input => "string" === typeof input && (RegExp(/^keeta_am(.*)/).test(input) || RegExp(/^keeta_an(.*)/).test(input) || RegExp(/^keeta_ao(.*)/).test(input) || RegExp(/^keeta_ap(.*)/).test(input) || RegExp(/^tyblocks_am(.*)/).test(input) || RegExp(/^tyblocks_an(.*)/).test(input) || RegExp(/^tyblocks_ao(.*)/).test(input) || RegExp(/^tyblocks_ap(.*)/).test(input)); let _errorFactory; return (input, errorFactory) => {
16
- if (false === __is(input)) {
17
- _errorFactory = errorFactory;
18
- ((input, _path, _exceptionable = true) => "string" === typeof input && (RegExp(/^keeta_am(.*)/).test(input) || RegExp(/^keeta_an(.*)/).test(input) || RegExp(/^keeta_ao(.*)/).test(input) || RegExp(/^keeta_ap(.*)/).test(input) || RegExp(/^tyblocks_am(.*)/).test(input) || RegExp(/^tyblocks_an(.*)/).test(input) || RegExp(/^tyblocks_ao(.*)/).test(input) || RegExp(/^tyblocks_ap(.*)/).test(input)) || __typia_transform__assertGuard._assertGuard(true, {
19
- method: "createAssert",
20
- path: _path + "",
21
- expected: "(`keeta_am${string}` | `keeta_an${string}` | `keeta_ao${string}` | `keeta_ap${string}` | `tyblocks_am${string}` | `tyblocks_an${string}` | `tyblocks_ao${string}` | `tyblocks_ap${string}`)",
22
- value: input
23
- }, _errorFactory))(input, "$input", true);
24
- }
25
- return input;
26
- }; })();
27
13
  async function getEndpoints(resolver, request, _ignored_account) {
28
14
  const criteria = {};
29
15
  if (request.from !== undefined) {
30
- criteria.inputCurrencyCode = request.from;
16
+ criteria.inputCurrencyCode = request.from.publicKeyString.get();
31
17
  }
32
18
  if (request.to !== undefined) {
33
- criteria.outputCurrencyCode = request.to;
19
+ criteria.outputCurrencyCode = request.to.publicKeyString.get();
34
20
  }
35
21
  const response = await resolver.lookup('fx', {
36
22
  ...criteria
@@ -100,30 +86,6 @@ async function getEndpoints(resolver, request, _ignored_account) {
100
86
  const retval = Object.fromEntries(await Promise.all(serviceInfoPromises));
101
87
  return (retval);
102
88
  }
103
- const isKeetaFXAnchorEstimateResponse = (() => { const _io0 = input => true === input.ok && ("object" === typeof input.estimate && null !== input.estimate && _io1(input.estimate)); const _io1 = input => "object" === typeof input.request && null !== input.request && _io2(input.request) && "string" === typeof input.convertedAmount && ("object" === typeof input.expectedCost && null !== input.expectedCost && _io3(input.expectedCost)); const _io2 = input => "string" === typeof input.from && (RegExp(/^keeta_am(.*)/).test(input.from) || RegExp(/^keeta_an(.*)/).test(input.from) || RegExp(/^keeta_ao(.*)/).test(input.from) || RegExp(/^keeta_ap(.*)/).test(input.from) || RegExp(/^tyblocks_am(.*)/).test(input.from) || RegExp(/^tyblocks_an(.*)/).test(input.from) || RegExp(/^tyblocks_ao(.*)/).test(input.from) || RegExp(/^tyblocks_ap(.*)/).test(input.from)) && ("string" === typeof input.to && (RegExp(/^keeta_am(.*)/).test(input.to) || RegExp(/^keeta_an(.*)/).test(input.to) || RegExp(/^keeta_ao(.*)/).test(input.to) || RegExp(/^keeta_ap(.*)/).test(input.to) || RegExp(/^tyblocks_am(.*)/).test(input.to) || RegExp(/^tyblocks_an(.*)/).test(input.to) || RegExp(/^tyblocks_ao(.*)/).test(input.to) || RegExp(/^tyblocks_ap(.*)/).test(input.to))) && "string" === typeof input.amount && ("from" === input.affinity || "to" === input.affinity); const _io3 = input => "string" === typeof input.min && "string" === typeof input.max && ("string" === typeof input.token && (RegExp(/^keeta_am(.*)/).test(input.token) || RegExp(/^keeta_an(.*)/).test(input.token) || RegExp(/^keeta_ao(.*)/).test(input.token) || RegExp(/^keeta_ap(.*)/).test(input.token) || RegExp(/^tyblocks_am(.*)/).test(input.token) || RegExp(/^tyblocks_an(.*)/).test(input.token) || RegExp(/^tyblocks_ao(.*)/).test(input.token) || RegExp(/^tyblocks_ap(.*)/).test(input.token))); const _io4 = input => false === input.ok && "string" === typeof input.error; const _iu0 = input => (() => {
104
- if (true === input.ok)
105
- return _io0(input);
106
- else if (false === input.ok)
107
- return _io4(input);
108
- else
109
- return false;
110
- })(); return input => "object" === typeof input && null !== input && _iu0(input); })();
111
- const isKeetaFXAnchorQuoteResponse = (() => { const _io0 = input => true === input.ok && ("object" === typeof input.quote && null !== input.quote && _io1(input.quote)); const _io1 = input => "object" === typeof input.request && null !== input.request && _io2(input.request) && "string" === typeof input.account && "string" === typeof input.convertedAmount && ("object" === typeof input.cost && null !== input.cost && _io3(input.cost)) && ("object" === typeof input.signed && null !== input.signed && _io4(input.signed)); const _io2 = input => "string" === typeof input.from && (RegExp(/^keeta_am(.*)/).test(input.from) || RegExp(/^keeta_an(.*)/).test(input.from) || RegExp(/^keeta_ao(.*)/).test(input.from) || RegExp(/^keeta_ap(.*)/).test(input.from) || RegExp(/^tyblocks_am(.*)/).test(input.from) || RegExp(/^tyblocks_an(.*)/).test(input.from) || RegExp(/^tyblocks_ao(.*)/).test(input.from) || RegExp(/^tyblocks_ap(.*)/).test(input.from)) && ("string" === typeof input.to && (RegExp(/^keeta_am(.*)/).test(input.to) || RegExp(/^keeta_an(.*)/).test(input.to) || RegExp(/^keeta_ao(.*)/).test(input.to) || RegExp(/^keeta_ap(.*)/).test(input.to) || RegExp(/^tyblocks_am(.*)/).test(input.to) || RegExp(/^tyblocks_an(.*)/).test(input.to) || RegExp(/^tyblocks_ao(.*)/).test(input.to) || RegExp(/^tyblocks_ap(.*)/).test(input.to))) && "string" === typeof input.amount && ("from" === input.affinity || "to" === input.affinity); const _io3 = input => "string" === typeof input.amount && ("string" === typeof input.token && (RegExp(/^keeta_am(.*)/).test(input.token) || RegExp(/^keeta_an(.*)/).test(input.token) || RegExp(/^keeta_ao(.*)/).test(input.token) || RegExp(/^keeta_ap(.*)/).test(input.token) || RegExp(/^tyblocks_am(.*)/).test(input.token) || RegExp(/^tyblocks_an(.*)/).test(input.token) || RegExp(/^tyblocks_ao(.*)/).test(input.token) || RegExp(/^tyblocks_ap(.*)/).test(input.token))); const _io4 = input => "string" === typeof input.nonce && "string" === typeof input.timestamp && "string" === typeof input.signature; const _io5 = input => false === input.ok && "string" === typeof input.error; const _iu0 = input => (() => {
112
- if (true === input.ok)
113
- return _io0(input);
114
- else if (false === input.ok)
115
- return _io5(input);
116
- else
117
- return false;
118
- })(); return input => "object" === typeof input && null !== input && _iu0(input); })();
119
- const isKeetaFXAnchorExchangeResponse = (() => { const _io0 = input => "string" === typeof input.exchangeID && true === input.ok; const _io1 = input => "string" === typeof input.exchangeID && false === input.ok && "string" === typeof input.error; const _iu0 = input => (() => {
120
- if (true === input.ok)
121
- return _io0(input);
122
- else if (false === input.ok)
123
- return _io1(input);
124
- else
125
- return false;
126
- })(); return input => "object" === typeof input && null !== input && _iu0(input); })();
127
89
  class KeetaFXAnchorBase {
128
90
  logger;
129
91
  client;
@@ -145,6 +107,14 @@ class KeetaFXAnchorProviderBase extends KeetaFXAnchorBase {
145
107
  this.conversion = conversion;
146
108
  this.parent = parent;
147
109
  }
110
+ #parseConversionRequest(input) {
111
+ return ({
112
+ from: KeetaNetLib.Account.fromPublicKeyString(input.from),
113
+ to: KeetaNetLib.Account.fromPublicKeyString(input.to),
114
+ amount: BigInt(input.amount),
115
+ affinity: input.affinity
116
+ });
117
+ }
148
118
  async getEstimate() {
149
119
  const serviceURL = await this.serviceInfo.operations.getEstimate;
150
120
  if (serviceURL !== undefined) {
@@ -156,7 +126,7 @@ class KeetaFXAnchorProviderBase extends KeetaFXAnchorBase {
156
126
  'Accept': 'application/json'
157
127
  },
158
128
  body: JSON.stringify({
159
- request: this.conversion
129
+ request: KeetaNetLib.Utils.Conversion.toJSONSerializable(this.conversion)
160
130
  })
161
131
  });
162
132
  const requestInformationJSON = await requestInformation.json();
@@ -166,8 +136,17 @@ class KeetaFXAnchorProviderBase extends KeetaFXAnchorBase {
166
136
  if (!requestInformationJSON.ok) {
167
137
  throw (new Error(`FX estimate request failed: ${requestInformationJSON.error}`));
168
138
  }
169
- this.logger?.debug(`FX estimate request successful, to provider ${estimateURL} for ${JSON.stringify(this.conversion)}`);
170
- return (requestInformationJSON.estimate);
139
+ this.logger?.debug(`FX estimate request successful, to provider ${estimateURL} for ${JSON.stringify(KeetaNetLib.Utils.Conversion.toJSONSerializable(this.conversion))}`);
140
+ const estimateJSON = requestInformationJSON.estimate;
141
+ return ({
142
+ request: this.#parseConversionRequest(estimateJSON.request),
143
+ convertedAmount: BigInt(estimateJSON.convertedAmount),
144
+ expectedCost: {
145
+ min: BigInt(estimateJSON.expectedCost.min),
146
+ max: BigInt(estimateJSON.expectedCost.max),
147
+ token: KeetaNetLib.Account.fromPublicKeyString(estimateJSON.expectedCost.token)
148
+ }
149
+ });
171
150
  }
172
151
  else {
173
152
  throw (new Error('Service getEstimate does not exist'));
@@ -194,7 +173,7 @@ class KeetaFXAnchorProviderBase extends KeetaFXAnchorBase {
194
173
  'Accept': 'application/json'
195
174
  },
196
175
  body: JSON.stringify({
197
- request: this.conversion
176
+ request: KeetaNetLib.Utils.Conversion.toJSONSerializable(this.conversion)
198
177
  })
199
178
  });
200
179
  const requestInformationJSON = await requestInformation.json();
@@ -205,32 +184,53 @@ class KeetaFXAnchorProviderBase extends KeetaFXAnchorBase {
205
184
  throw (new Error(`FX quote request failed: ${requestInformationJSON.error}`));
206
185
  }
207
186
  if (estimate !== undefined && tolerance !== undefined) {
208
- const quoteAmount = new Decimal(requestInformationJSON.quote.convertedAmount);
209
- const estimateAmount = new Decimal(estimate.convertedAmount);
210
- const variation = Math.abs(quoteAmount.dividedBy(estimateAmount).toNumber() - 1);
211
- if (variation > tolerance) {
187
+ const quoteAmount = BigInt(requestInformationJSON.quote.convertedAmount);
188
+ const estimateAmount = BigInt(estimate.convertedAmount);
189
+ const lowerBound = estimateAmount * BigInt(Math.round((1 - tolerance) * 100)) / 100n;
190
+ const upperBound = estimateAmount * BigInt(Math.round((1 + tolerance) * 100)) / 100n;
191
+ if (quoteAmount > upperBound || quoteAmount < lowerBound) {
212
192
  throw (new Error(`FX Quote amount: ${requestInformationJSON.quote.convertedAmount} differs more than tolerance limit: ${tolerance} from estimate`));
213
193
  }
214
194
  }
215
- this.logger?.debug(`FX quote request successful, to provider ${serviceURL} for ${JSON.stringify(this.conversion)}`);
216
- return (requestInformationJSON.quote);
195
+ this.logger?.debug(`FX quote request successful, to provider ${serviceURL} for ${JSON.stringify(KeetaNetLib.Utils.Conversion.toJSONSerializable(this.conversion))}`);
196
+ const quoteJSON = requestInformationJSON.quote;
197
+ return ({
198
+ request: this.#parseConversionRequest(quoteJSON.request),
199
+ account: KeetaNetLib.Account.fromPublicKeyString(quoteJSON.account),
200
+ convertedAmount: BigInt(quoteJSON.convertedAmount),
201
+ cost: {
202
+ amount: BigInt(quoteJSON.cost.amount),
203
+ token: KeetaNetLib.Account.fromPublicKeyString(quoteJSON.cost.token)
204
+ },
205
+ signed: quoteJSON.signed
206
+ });
217
207
  }
218
208
  async createExchange(quote, block) {
219
209
  let swapBlock = block;
220
210
  if (swapBlock === undefined) {
221
211
  /* Liquidity Provider that will complete the swap */
222
- const liquidityProvider = KeetaNetLib.Account.fromPublicKeyString(quote.account);
212
+ const liquidityProvider = quote.account;
223
213
  /* Assume affinity is 'from' and assign appropriate variables */
224
- let sendAmount = BigInt(quote.request.amount);
225
- let receiveAmount = BigInt(quote.convertedAmount);
214
+ let sendAmount = quote.request.amount;
215
+ let receiveAmount = quote.convertedAmount;
226
216
  /* If affinity is 'to' then reverse amounts */
227
217
  if (quote.request.affinity === 'to') {
228
- sendAmount = BigInt(quote.convertedAmount);
229
- receiveAmount = BigInt(quote.request.amount);
218
+ sendAmount = quote.convertedAmount;
219
+ receiveAmount = quote.request.amount;
220
+ }
221
+ /* Construct the required operations for the swap request */
222
+ const builder = this.client.initBuilder();
223
+ builder.send(liquidityProvider, sendAmount, quote.request.from);
224
+ builder.receive(liquidityProvider, receiveAmount, quote.request.to, true);
225
+ /* If cost is required then send the required amount as well */
226
+ if (quote.cost.amount > 0) {
227
+ builder.send(liquidityProvider, quote.cost.amount, quote.cost.token);
228
+ }
229
+ const blocks = await builder.computeBlocks();
230
+ if (blocks.blocks.length !== 1) {
231
+ throw (new Error('Creating Swap Generated more than 1 block'));
230
232
  }
231
- const from = { account: this.client.account, token: KeetaNetLib.Account.fromPublicKeyString(quote.request.from), amount: sendAmount };
232
- const to = { account: liquidityProvider, token: KeetaNetLib.Account.fromPublicKeyString(quote.request.to), amount: receiveAmount };
233
- swapBlock = await this.client.createSwapRequest({ from, to });
233
+ swapBlock = blocks.blocks[0];
234
234
  }
235
235
  if (swapBlock == undefined) {
236
236
  throw (new Error('User Swap Block is undefined'));
@@ -244,7 +244,7 @@ class KeetaFXAnchorProviderBase extends KeetaFXAnchorBase {
244
244
  },
245
245
  body: JSON.stringify({
246
246
  request: {
247
- quote: quote,
247
+ quote: KeetaNetLib.Utils.Conversion.toJSONSerializable(quote),
248
248
  block: Buffer.from(swapBlock.toBytes()).toString('base64')
249
249
  }
250
250
  })
@@ -363,7 +363,7 @@ class KeetaFXAnchorClient extends KeetaFXAnchorBase {
363
363
  if (input.from !== undefined) {
364
364
  let fromToken;
365
365
  if (KeetaNetLib.Account.isInstance(input.from) && input.from.isToken()) {
366
- fromToken = input.from.publicKeyString.get();
366
+ fromToken = input.from;
367
367
  }
368
368
  else {
369
369
  const tokenLookup = await this.resolver.lookupToken(input.from);
@@ -371,7 +371,7 @@ class KeetaFXAnchorClient extends KeetaFXAnchorBase {
371
371
  // eslint-disable-next-line @typescript-eslint/no-base-to-string
372
372
  throw (new Error(`Could not convert from: ${input.from} to a token address`));
373
373
  }
374
- fromToken = tokenLookup.token;
374
+ fromToken = KeetaNetLib.Account.fromPublicKeyString(tokenLookup.token);
375
375
  }
376
376
  from = { from: fromToken };
377
377
  }
@@ -379,7 +379,7 @@ class KeetaFXAnchorClient extends KeetaFXAnchorBase {
379
379
  if (input.to !== undefined) {
380
380
  let toToken;
381
381
  if (KeetaNetLib.Account.isInstance(input.to) && input.to.isToken()) {
382
- toToken = input.to.publicKeyString.get();
382
+ toToken = input.to;
383
383
  }
384
384
  else {
385
385
  const tokenLookup = await this.resolver.lookupToken(input.to);
@@ -387,16 +387,16 @@ class KeetaFXAnchorClient extends KeetaFXAnchorBase {
387
387
  // eslint-disable-next-line @typescript-eslint/no-base-to-string
388
388
  throw (new Error(`Could not convert to: ${input.to} to a token address`));
389
389
  }
390
- toToken = tokenLookup.token;
390
+ toToken = KeetaNetLib.Account.fromPublicKeyString(tokenLookup.token);
391
391
  }
392
392
  to = { to: toToken };
393
393
  }
394
394
  return ({ ...from, ...to });
395
395
  }
396
396
  async canonicalizeConversionInput(input) {
397
- const amount = new Decimal(input.amount);
398
- if (amount.isNaN() || amount.lte(0)) {
399
- throw (new Error('invalid amount'));
397
+ const amount = BigInt(input.amount);
398
+ if (amount < 0) {
399
+ throw (new Error('Invalid Conversion Amount'));
400
400
  }
401
401
  const { from, to } = await this.canonicalizeConversionTokens(input);
402
402
  if (from === undefined || to === undefined) {
@@ -405,7 +405,7 @@ class KeetaFXAnchorClient extends KeetaFXAnchorBase {
405
405
  return ({
406
406
  from,
407
407
  to,
408
- amount: amount.toString(),
408
+ amount: amount,
409
409
  affinity: input.affinity
410
410
  });
411
411
  }
@@ -427,18 +427,18 @@ class KeetaFXAnchorClient extends KeetaFXAnchorBase {
427
427
  for (const [_ignored_providerID, serviceInfo] of typedFxServiceEntries(providerEndpoints)) {
428
428
  for (const conversionPair of serviceInfo.from) {
429
429
  if (conversion.from !== undefined) {
430
- if (conversionPair.currencyCodes.includes(conversion.from)) {
430
+ if (conversionPair.currencyCodes.includes(conversion.from.publicKeyString.get())) {
431
431
  conversionPair.to.forEach((token) => {
432
- if (conversion.from !== token) {
432
+ if (conversion.from?.publicKeyString.get() !== token) {
433
433
  conversions.add(token);
434
434
  }
435
435
  });
436
436
  }
437
437
  }
438
438
  else if (conversion.to !== undefined) {
439
- if (conversionPair.to.includes(conversion.to)) {
439
+ if (conversionPair.to.includes(conversion.to.publicKeyString.get())) {
440
440
  conversionPair.currencyCodes.forEach((token) => {
441
- if (conversion.to !== token) {
441
+ if (conversion.to?.publicKeyString.get() !== token) {
442
442
  conversions.add(token);
443
443
  }
444
444
  });
@@ -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,YAAY,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAErC,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAQrD,OAAO,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AACnD,OAAO,MAAM,MAAM,2BAA2B,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAarD,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAyD1D,SAAS,qBAAqB,CAAmB,GAAM;IACtD,yEAAyE;IACzE,OAAO,MAAM,CAAC,OAAO,CAAC,GAAG,CAA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AAmB;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;SACtB,CAAC,CAAC;IAEJ,CAAC;CACD;AAED,eAAe,mBAAmB,CAAC","sourcesContent":["import { lib as KeetaNetLib } from '@keetanetwork/keetanet-client';\nimport { createAssert, createIs } from 'typia';\nimport { Decimal } from 'decimal.js';\n\nimport { getDefaultResolver } from '../../config.js';\n\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 } 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 type {\n\tConversionInput,\n\tConversionInputCanonical,\n\tKeetaFXAnchorEstimate,\n\tKeetaFXAnchorEstimateResponse,\n\tKeetaFXAnchorExchange,\n\tKeetaFXAnchorExchangeResponse,\n\tKeetaFXAnchorQuote,\n\tKeetaFXAnchorQuoteResponse,\n\tKeetaNetTokenPublicKeyString\n} from './common.ts';\nimport { KeetaAnchorUserError } from '../../lib/error.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 * 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;\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} & 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\ntype KeetaFXServiceInfo = {\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\nconst assertKeetaNetTokenPublicKeyString = createAssert<KeetaNetTokenPublicKeyString>();\nasync function getEndpoints(resolver: Resolver, request: Partial<Pick<ConversionInputCanonical, 'from' | 'to'>>, _ignored_account: InstanceType<typeof KeetaNetLib.Account>): Promise<GetEndpointsResult | null> {\n\tconst criteria: ServiceSearchCriteria<'fx'> = {};\n\tif (request.from !== undefined) {\n\t\tcriteria.inputCurrencyCode = request.from;\n\t}\n\tif (request.to !== undefined) {\n\t\tcriteria.outputCurrencyCode = request.to;\n\t}\n\n\tconst response = await resolver.lookup('fx', {\n\t\t...criteria\n\t\t// kycProviders: 'TODO' XXX:TODO\n\t});\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// 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\nconst isKeetaFXAnchorEstimateResponse = createIs<KeetaFXAnchorEstimateResponse>();\nconst isKeetaFXAnchorQuoteResponse = createIs<KeetaFXAnchorQuoteResponse>();\nconst isKeetaFXAnchorExchangeResponse = createIs<KeetaFXAnchorExchangeResponse>();\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\nclass KeetaFXAnchorProviderBase extends KeetaFXAnchorBase {\n\treadonly serviceInfo: KeetaFXServiceInfo;\n\treadonly providerID: ProviderID;\n\treadonly conversion: ConversionInputCanonical;\n\tprivate readonly parent: KeetaFXAnchorClient;\n\n\tconstructor(serviceInfo: KeetaFXServiceInfo, providerID: ProviderID, conversion: ConversionInputCanonical, parent: KeetaFXAnchorClient) {\n\t\tconst parentPrivate = parent._internals(KeetaFXAnchorClientAccessToken);\n\t\tsuper(parentPrivate);\n\n\t\tthis.serviceInfo = serviceInfo;\n\t\tthis.providerID = providerID;\n\t\tthis.conversion = conversion;\n\t\tthis.parent = parent;\n\t}\n\n\tasync getEstimate(): Promise<KeetaFXAnchorEstimate> {\n\t\tconst serviceURL = await this.serviceInfo.operations.getEstimate;\n\t\tif (serviceURL !== undefined) {\n\t\t\tconst estimateURL = serviceURL();\n\t\t\tconst requestInformation = await fetch(estimateURL, {\n\t\t\t\tmethod: 'POST',\n\t\t\t\theaders: {\n\t\t\t\t\t'Content-Type': 'application/json',\n\t\t\t\t\t'Accept': 'application/json'\n\t\t\t\t},\n\t\t\t\tbody: JSON.stringify({\n\t\t\t\t\trequest: this.conversion\n\t\t\t\t})\n\t\t\t});\n\n\t\t\tconst requestInformationJSON: unknown = await requestInformation.json();\n\t\t\tif (!isKeetaFXAnchorEstimateResponse(requestInformationJSON)) {\n\t\t\t\tthrow(new Error(`Invalid response from FX estimate service: ${JSON.stringify(requestInformationJSON)}`));\n\t\t\t}\n\n\t\t\tif (!requestInformationJSON.ok) {\n\t\t\t\tthrow(new Error(`FX estimate request failed: ${requestInformationJSON.error}`));\n\t\t\t}\n\n\t\t\tthis.logger?.debug(`FX estimate request successful, to provider ${estimateURL} for ${JSON.stringify(this.conversion)}`);\n\t\t\treturn(requestInformationJSON.estimate);\n\t\t} else {\n\t\t\tthrow(new Error('Service getEstimate does not exist'));\n\t\t}\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.serviceInfo.operations.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: 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(new Error(`FX quote request failed: ${requestInformationJSON.error}`));\n\t\t}\n\n\t\tif (estimate !== undefined && tolerance !== undefined) {\n\t\t\tconst quoteAmount = new Decimal(requestInformationJSON.quote.convertedAmount);\n\t\t\tconst estimateAmount = new Decimal(estimate.convertedAmount);\n\t\t\tconst variation = Math.abs(quoteAmount.dividedBy(estimateAmount).toNumber() - 1);\n\t\t\tif (variation > tolerance) {\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(this.conversion)}`);\n\t\treturn(requestInformationJSON.quote);\n\t}\n\n\tasync createExchange(quote: KeetaFXAnchorQuote, block?: InstanceType<typeof KeetaNetLib.Block>): Promise<KeetaFXAnchorExchange> {\n\t\tlet swapBlock = block;\n\t\tif (swapBlock === undefined) {\n\t\t\t/* Liquidity Provider that will complete the swap */\n\t\t\tconst liquidityProvider = KeetaNetLib.Account.fromPublicKeyString(quote.account);\n\n\t\t\t/* Assume affinity is 'from' and assign appropriate variables */\n\t\t\tlet sendAmount = BigInt(quote.request.amount);\n\t\t\tlet receiveAmount = BigInt(quote.convertedAmount);\n\n\t\t\t/* If affinity is 'to' then reverse amounts */\n\t\t\tif (quote.request.affinity === 'to') {\n\t\t\t\tsendAmount = BigInt(quote.convertedAmount);\n\t\t\t\treceiveAmount = BigInt(quote.request.amount);\n\t\t\t}\n\n\t\t\tconst from = { account: this.client.account, token: KeetaNetLib.Account.fromPublicKeyString(quote.request.from), amount: sendAmount };\n\t\t\tconst to = { account: liquidityProvider, token: KeetaNetLib.Account.fromPublicKeyString(quote.request.to), amount: receiveAmount };\n\t\t\tswapBlock = await this.client.createSwapRequest({ from, to });\n\t\t}\n\n\t\tif (swapBlock == undefined) {\n\t\t\tthrow(new Error('User Swap Block is undefined'));\n\t\t}\n\n\t\tconst serviceURL = (await this.serviceInfo.operations.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\tquote: quote,\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 requestInformationJSON: unknown = await requestInformation.json();\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(new Error(`FX exchange request failed: ${requestInformationJSON.error}`));\n\t\t}\n\n\t\tthis.logger?.debug(`FX exchange request successful, to provider ${serviceURL} for ${swapBlock.hash.toString()}`);\n\t\treturn({ exchangeID: requestInformationJSON.exchangeID });\n\t}\n\n\tasync getExchangeStatus(exchangeID: string): Promise<KeetaFXAnchorExchange> {\n\t\tconst serviceURL = (await this.serviceInfo.operations.getExchangeStatus)({ 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(new Error(`FX exchange status failed: ${requestInformationJSON.error}`));\n\t\t}\n\n\t\tthis.logger?.debug(`FX exchange status request successful, to provider ${serviceURL} for ${exchangeID}`);\n\t\treturn({ exchangeID: requestInformationJSON.exchangeID });\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\n\t}\n}\n\n/*\n * Various classes for the state machine:\n * Estimate(optional) -> Quote(optional) -> Exchange -> ExchangeStatus\n */\nclass KeetaFXAnchorExchangeWithProvider {\n\tprivate readonly 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\nclass KeetaFXAnchorQuoteWithProvider {\n\tprivate readonly provider: KeetaFXAnchorProviderBase;\n\treadonly quote: KeetaFXAnchorQuote;\n\n\tconstructor(provider: KeetaFXAnchorProviderBase, quote: KeetaFXAnchorQuote) {\n\t\tthis.provider = provider;\n\t\tthis.quote = quote;\n\t}\n\n\tasync createExchange(block?: InstanceType<typeof KeetaNetLib.Block>): Promise<KeetaFXAnchorExchangeWithProvider> {\n\t\tconst exchange = await this.provider.createExchange(this.quote, block);\n\t\treturn(new KeetaFXAnchorExchangeWithProvider(this.provider, exchange));\n\t}\n}\n\nclass KeetaFXAnchorEstimateWithProvider {\n\tprivate readonly provider: KeetaFXAnchorProviderBase;\n\treadonly estimate: KeetaFXAnchorEstimate;\n\n\tconstructor(provider: KeetaFXAnchorProviderBase, estimate: KeetaFXAnchorEstimate) {\n\t\tthis.provider = provider;\n\t\tthis.estimate = estimate;\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\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\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\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\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: KeetaNetTokenPublicKeyString;\n\t\t\tif (KeetaNetLib.Account.isInstance(input.from) && input.from.isToken()) {\n\t\t\t\tfromToken = input.from.publicKeyString.get();\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 = 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: KeetaNetTokenPublicKeyString;\n\t\t\tif (KeetaNetLib.Account.isInstance(input.to) && input.to.isToken()) {\n\t\t\t\ttoToken = input.to.publicKeyString.get();\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 = 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 = new Decimal(input.amount);\n\t\tif (amount.isNaN() || amount.lte(0)) {\n\t\t\tthrow(new Error('invalid 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\treturn({\n\t\t\tfrom,\n\t\t\tto,\n\t\t\tamount: amount.toString(),\n\t\t\taffinity: input.affinity\n\t\t});\n\t}\n\n\tasync listPossibleConversions(input: Partial<Pick<ConversionInput, 'from' | 'to'>>, options: AccountOptions = {}): 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);\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)) {\n\t\t\t\t\t\tconversionPair.to.forEach((token) => {\n\t\t\t\t\t\t\tif (conversion.from !== 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)) {\n\t\t\t\t\t\tconversionPair.currencyCodes.forEach((token) => {\n\t\t\t\t\t\t\tif (conversion.to !== 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: AccountOptions = {}): 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);\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));\n\t\t});\n\n\t\treturn(providers);\n\t}\n\n\tasync getEstimates(request: ConversionInput, options: AccountOptions = {}): Promise<KeetaFXAnchorEstimateWithProvider[] | null> {\n\t\tconst estimateProviders = await this.getBaseProvidersForConversion(request, options);\n\t\tif (estimateProviders === null) {\n\t\t\treturn(null);\n\t\t}\n\n\t\tconst estimates = await Promise.allSettled(estimateProviders.map(async (provider) => {\n\t\t\tconst estimate = await provider.getEstimate();\n\n\t\t\treturn(new KeetaFXAnchorEstimateWithProvider(provider, estimate));\n\t\t}));\n\n\t\tconst results = estimates.filter(function(result) {\n\t\t\treturn(result.status === 'fulfilled');\n\t\t}).map(function(result) {\n\t\t\treturn(result.value);\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 getQuotes(request: ConversionInput, options: AccountOptions = {}): Promise<KeetaFXAnchorQuoteWithProvider[] | null> {\n\t\tconst estimateProviders = await this.getBaseProvidersForConversion(request, options);\n\t\tif (estimateProviders === null) {\n\t\t\treturn(null);\n\t\t}\n\n\t\tconst quotes = await Promise.allSettled(estimateProviders.map(async (provider) => {\n\t\t\tconst quote = await provider.getQuote();\n\n\t\t\treturn(new KeetaFXAnchorQuoteWithProvider(provider, quote));\n\t\t}));\n\n\t\tconst results = quotes.filter(function(result) {\n\t\t\treturn(result.status === 'fulfilled');\n\t\t}).map(function(result) {\n\t\t\treturn(result.value);\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\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});\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,4BAA4B,EAC5B,MAAM,aAAa,CAAC;AAUrB,OAAO,EAAE,oBAA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AO,CAAC,UAAU,CAAC,iBAAiB,CAAC,GAAG,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE;YAChF,MAAM,KAAK,GAAG,MAAM,QAAQ,CAAC,QAAQ,EAAE,CAAC;YAExC,OAAM,CAAC,IAAI,8BAA8B,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAC;QAC7D,CAAC,CAAC,CAAC,CAAC;QAEJ,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,UAAS,MAAM;YAC5C,OAAM,CAAC,MAAM,CAAC,MAAM,KAAK,WAAW,CAAC,CAAC;QACvC,CAAC,CAAC,CAAC,GAAG,CAAC,UAAS,MAAM;YACrB,OAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACtB,CAAC,CAAC,CAAC;QAEH,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC1B,OAAM,CAAC,IAAI,CAAC,CAAC;QACd,CAAC;QAED,OAAM,CAAC,OAAO,CAAC,CAAC;IACjB,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;SACtB,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 } 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\tisKeetaFXAnchorQuoteResponse\n} from './common.js';\nimport type {\n\tConversionInput,\n\tConversionInputCanonical,\n\tConversionInputCanonicalJSON,\n\tKeetaFXAnchorEstimate,\n\tKeetaFXAnchorExchange,\n\tKeetaFXAnchorQuote,\n\tKeetaNetTokenPublicKeyString\n} from './common.ts';\nimport { KeetaAnchorUserError } from '../../lib/error.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 * 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;\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} & 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\ntype KeetaFXServiceInfo = {\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(resolver: Resolver, request: Partial<Pick<ConversionInputCanonical, 'from' | 'to'>>, _ignored_account: InstanceType<typeof KeetaNetLib.Account>): 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\tconst response = await resolver.lookup('fx', {\n\t\t...criteria\n\t\t// kycProviders: 'TODO' XXX:TODO\n\t});\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// 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\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\nclass KeetaFXAnchorProviderBase extends KeetaFXAnchorBase {\n\treadonly serviceInfo: KeetaFXServiceInfo;\n\treadonly providerID: ProviderID;\n\treadonly conversion: ConversionInputCanonical;\n\tprivate readonly parent: KeetaFXAnchorClient;\n\n\tconstructor(serviceInfo: KeetaFXServiceInfo, providerID: ProviderID, conversion: ConversionInputCanonical, parent: KeetaFXAnchorClient) {\n\t\tconst parentPrivate = parent._internals(KeetaFXAnchorClientAccessToken);\n\t\tsuper(parentPrivate);\n\n\t\tthis.serviceInfo = serviceInfo;\n\t\tthis.providerID = providerID;\n\t\tthis.conversion = conversion;\n\t\tthis.parent = parent;\n\t}\n\n\t#parseConversionRequest(input: ConversionInputCanonicalJSON): ConversionInputCanonical {\n\t\treturn({\n\t\t\tfrom: KeetaNetLib.Account.fromPublicKeyString(input.from),\n\t\t\tto: KeetaNetLib.Account.fromPublicKeyString(input.to),\n\t\t\tamount: BigInt(input.amount),\n\t\t\taffinity: input.affinity\n\t\t});\n\t}\n\n\tasync getEstimate(): Promise<KeetaFXAnchorEstimate> {\n\t\tconst serviceURL = await this.serviceInfo.operations.getEstimate;\n\t\tif (serviceURL !== undefined) {\n\t\t\tconst estimateURL = serviceURL();\n\t\t\tconst requestInformation = await fetch(estimateURL, {\n\t\t\t\tmethod: 'POST',\n\t\t\t\theaders: {\n\t\t\t\t\t'Content-Type': 'application/json',\n\t\t\t\t\t'Accept': 'application/json'\n\t\t\t\t},\n\t\t\t\tbody: JSON.stringify({\n\t\t\t\t\trequest: KeetaNetLib.Utils.Conversion.toJSONSerializable(this.conversion)\n\t\t\t\t})\n\t\t\t});\n\n\t\t\tconst requestInformationJSON: unknown = await requestInformation.json();\n\t\t\tif (!isKeetaFXAnchorEstimateResponse(requestInformationJSON)) {\n\t\t\t\tthrow(new Error(`Invalid response from FX estimate service: ${JSON.stringify(requestInformationJSON)}`));\n\t\t\t}\n\n\t\t\tif (!requestInformationJSON.ok) {\n\t\t\t\tthrow(new Error(`FX estimate request failed: ${requestInformationJSON.error}`));\n\t\t\t}\n\n\t\t\tthis.logger?.debug(`FX estimate request successful, to provider ${estimateURL} for ${JSON.stringify(KeetaNetLib.Utils.Conversion.toJSONSerializable(this.conversion))}`);\n\t\t\tconst estimateJSON = requestInformationJSON.estimate;\n\t\t\treturn({\n\t\t\t\trequest: this.#parseConversionRequest(estimateJSON.request),\n\t\t\t\tconvertedAmount: BigInt(estimateJSON.convertedAmount),\n\t\t\t\texpectedCost: {\n\t\t\t\t\tmin: BigInt(estimateJSON.expectedCost.min),\n\t\t\t\t\tmax: BigInt(estimateJSON.expectedCost.max),\n\t\t\t\t\ttoken: KeetaNetLib.Account.fromPublicKeyString(estimateJSON.expectedCost.token)\n\t\t\t\t}\n\t\t\t});\n\t\t} else {\n\t\t\tthrow(new Error('Service getEstimate does not exist'));\n\t\t}\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.serviceInfo.operations.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(new Error(`FX quote request failed: ${requestInformationJSON.error}`));\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\treturn({\n\t\t\trequest: this.#parseConversionRequest(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\t}\n\n\tasync createExchange(quote: KeetaFXAnchorQuote, block?: InstanceType<typeof KeetaNetLib.Block>): Promise<KeetaFXAnchorExchange> {\n\t\tlet swapBlock = block;\n\t\tif (swapBlock === undefined) {\n\t\t\t/* Liquidity Provider that will complete the swap */\n\t\t\tconst liquidityProvider = quote.account;\n\n\t\t\t/* Assume affinity is 'from' and assign appropriate variables */\n\t\t\tlet sendAmount = quote.request.amount;\n\t\t\tlet receiveAmount = quote.convertedAmount;\n\n\t\t\t/* If affinity is 'to' then reverse amounts */\n\t\t\tif (quote.request.affinity === 'to') {\n\t\t\t\tsendAmount = quote.convertedAmount;\n\t\t\t\treceiveAmount = quote.request.amount;\n\t\t\t}\n\n\t\t\t/* Construct the required operations for the swap request */\n\t\t\tconst builder = this.client.initBuilder();\n\t\t\tbuilder.send(liquidityProvider, sendAmount, quote.request.from);\n\t\t\tbuilder.receive(liquidityProvider, receiveAmount, quote.request.to, true);\n\n\t\t\t/* If cost is required then send the required amount as well */\n\t\t\tif (quote.cost.amount > 0) {\n\t\t\t\tbuilder.send(liquidityProvider, quote.cost.amount, quote.cost.token);\n\t\t\t}\n\n\t\t\tconst blocks = await builder.computeBlocks();\n\t\t\tif (blocks.blocks.length !== 1) {\n\t\t\t\tthrow(new Error('Creating Swap Generated more than 1 block'));\n\t\t\t}\n\t\t\tswapBlock = blocks.blocks[0];\n\t\t}\n\n\t\tif (swapBlock == undefined) {\n\t\t\tthrow(new Error('User Swap Block is undefined'));\n\t\t}\n\n\t\tconst serviceURL = (await this.serviceInfo.operations.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\tquote: KeetaNetLib.Utils.Conversion.toJSONSerializable(quote),\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 requestInformationJSON: unknown = await requestInformation.json();\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(new Error(`FX exchange request failed: ${requestInformationJSON.error}`));\n\t\t}\n\n\t\tthis.logger?.debug(`FX exchange request successful, to provider ${serviceURL} for ${swapBlock.hash.toString()}`);\n\t\treturn({ exchangeID: requestInformationJSON.exchangeID });\n\t}\n\n\tasync getExchangeStatus(exchangeID: string): Promise<KeetaFXAnchorExchange> {\n\t\tconst serviceURL = (await this.serviceInfo.operations.getExchangeStatus)({ 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(new Error(`FX exchange status failed: ${requestInformationJSON.error}`));\n\t\t}\n\n\t\tthis.logger?.debug(`FX exchange status request successful, to provider ${serviceURL} for ${exchangeID}`);\n\t\treturn({ exchangeID: requestInformationJSON.exchangeID });\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\n\t}\n}\n\n/*\n * Various classes for the state machine:\n * Estimate(optional) -> Quote(optional) -> Exchange -> ExchangeStatus\n */\nclass KeetaFXAnchorExchangeWithProvider {\n\tprivate readonly 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\nclass KeetaFXAnchorQuoteWithProvider {\n\tprivate readonly provider: KeetaFXAnchorProviderBase;\n\treadonly quote: KeetaFXAnchorQuote;\n\n\tconstructor(provider: KeetaFXAnchorProviderBase, quote: KeetaFXAnchorQuote) {\n\t\tthis.provider = provider;\n\t\tthis.quote = quote;\n\t}\n\n\tasync createExchange(block?: InstanceType<typeof KeetaNetLib.Block>): Promise<KeetaFXAnchorExchangeWithProvider> {\n\t\tconst exchange = await this.provider.createExchange(this.quote, block);\n\t\treturn(new KeetaFXAnchorExchangeWithProvider(this.provider, exchange));\n\t}\n}\n\nclass KeetaFXAnchorEstimateWithProvider {\n\tprivate readonly provider: KeetaFXAnchorProviderBase;\n\treadonly estimate: KeetaFXAnchorEstimate;\n\n\tconstructor(provider: KeetaFXAnchorProviderBase, estimate: KeetaFXAnchorEstimate) {\n\t\tthis.provider = provider;\n\t\tthis.estimate = estimate;\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\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\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\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\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\treturn({\n\t\t\tfrom,\n\t\t\tto,\n\t\t\tamount: amount,\n\t\t\taffinity: input.affinity\n\t\t});\n\t}\n\n\tasync listPossibleConversions(input: Partial<Pick<ConversionInput, 'from' | 'to'>>, options: AccountOptions = {}): 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);\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: AccountOptions = {}): 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);\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));\n\t\t});\n\n\t\treturn(providers);\n\t}\n\n\tasync getEstimates(request: ConversionInput, options: AccountOptions = {}): Promise<KeetaFXAnchorEstimateWithProvider[] | null> {\n\t\tconst estimateProviders = await this.getBaseProvidersForConversion(request, options);\n\t\tif (estimateProviders === null) {\n\t\t\treturn(null);\n\t\t}\n\n\t\tconst estimates = await Promise.allSettled(estimateProviders.map(async (provider) => {\n\t\t\tconst estimate = await provider.getEstimate();\n\n\t\t\treturn(new KeetaFXAnchorEstimateWithProvider(provider, estimate));\n\t\t}));\n\n\t\tconst results = estimates.filter(function(result) {\n\t\t\treturn(result.status === 'fulfilled');\n\t\t}).map(function(result) {\n\t\t\treturn(result.value);\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 getQuotes(request: ConversionInput, options: AccountOptions = {}): Promise<KeetaFXAnchorQuoteWithProvider[] | null> {\n\t\tconst estimateProviders = await this.getBaseProvidersForConversion(request, options);\n\t\tif (estimateProviders === null) {\n\t\t\treturn(null);\n\t\t}\n\n\t\tconst quotes = await Promise.allSettled(estimateProviders.map(async (provider) => {\n\t\t\tconst quote = await provider.getQuote();\n\n\t\t\treturn(new KeetaFXAnchorQuoteWithProvider(provider, quote));\n\t\t}));\n\n\t\tconst results = quotes.filter(function(result) {\n\t\t\treturn(result.status === 'fulfilled');\n\t\t}).map(function(result) {\n\t\t\treturn(result.value);\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\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});\n\n\t}\n}\n\nexport default KeetaFXAnchorClient;\n"]}
@@ -1,7 +1,8 @@
1
1
  import type { lib as KeetaNetLib } from '@keetanetwork/keetanet-client';
2
- import type { Decimal } from 'decimal.js';
3
2
  import type { ServiceSearchCriteria } from '../../lib/resolver.js';
3
+ import type { ToJSONSerializable } from '../../lib/utils/json.js';
4
4
  export type KeetaNetAccount = InstanceType<typeof KeetaNetLib.Account>;
5
+ export type KeetaNetStorageAccount = InstanceType<typeof KeetaNetLib.Account<typeof KeetaNetLib.Account.AccountKeyAlgorithm.STORAGE>>;
5
6
  export type KeetaNetToken = InstanceType<typeof KeetaNetLib.Account<typeof KeetaNetLib.Account.AccountKeyAlgorithm.TOKEN>>;
6
7
  export type KeetaNetTokenPublicKeyString = ReturnType<InstanceType<typeof KeetaNetLib.Account<typeof KeetaNetLib.Account.AccountKeyAlgorithm.TOKEN>>['publicKeyString']['get']>;
7
8
  export type ConversionInput = {
@@ -14,11 +15,11 @@ export type ConversionInput = {
14
15
  */
15
16
  to: ServiceSearchCriteria<'fx'>['outputCurrencyCode'] | KeetaNetToken;
16
17
  /**
17
- * The amount to convert. This is a string or Decimal representing the
18
+ * The amount to convert. This is a bigint representing the
18
19
  * amount in the currency specified by either `from` or `to`, as
19
20
  * specified by the `affinity` property.
20
21
  */
21
- amount: string | number | Decimal;
22
+ amount: bigint;
22
23
  /**
23
24
  * Indicates whether the amount specified is in terms of the `from`
24
25
  * currency (i.e., the user has this much) or the `to` currency
@@ -27,8 +28,9 @@ export type ConversionInput = {
27
28
  affinity: 'from' | 'to';
28
29
  };
29
30
  export type ConversionInputCanonical = {
30
- [k in keyof ConversionInput]: k extends 'amount' ? string : k extends 'from' ? KeetaNetTokenPublicKeyString : k extends 'to' ? KeetaNetTokenPublicKeyString : ConversionInput[k];
31
+ [k in keyof ConversionInput]: k extends 'amount' ? bigint : k extends 'from' ? KeetaNetToken : k extends 'to' ? KeetaNetToken : ConversionInput[k];
31
32
  };
33
+ export type ConversionInputCanonicalJSON = ToJSONSerializable<ConversionInputCanonical>;
32
34
  export type KeetaFXAnchorClientCreateExchangeRequest = {
33
35
  quote: KeetaFXAnchorQuote;
34
36
  block: InstanceType<typeof KeetaNetLib.Block>;
@@ -44,20 +46,20 @@ export type KeetaFXAnchorEstimate = {
44
46
  /**
45
47
  * Amount after the conversion as specified by either `from` or `to`, as specified by the `affinity` property in the request.
46
48
  */
47
- convertedAmount: string;
49
+ convertedAmount: bigint;
48
50
  /**
49
51
  * The expected cost of the fx request, in the form of a
50
52
  * token and a range of minimum and maximum expected costs
51
53
  */
52
54
  expectedCost: {
53
- min: string;
54
- max: string;
55
- token: KeetaNetTokenPublicKeyString;
55
+ min: bigint;
56
+ max: bigint;
57
+ token: KeetaNetToken;
56
58
  };
57
59
  };
58
60
  export type KeetaFXAnchorEstimateResponse = ({
59
61
  ok: true;
60
- estimate: KeetaFXAnchorEstimate;
62
+ estimate: ToJSONSerializable<KeetaFXAnchorEstimate>;
61
63
  } | {
62
64
  ok: false;
63
65
  error: string;
@@ -70,18 +72,18 @@ export type KeetaFXAnchorQuote = {
70
72
  /**
71
73
  * The public key of the liquidity provider account
72
74
  */
73
- account: string;
75
+ account: KeetaNetAccount | KeetaNetStorageAccount;
74
76
  /**
75
77
  * Amount after the conversion as specified by either `from` or `to`, as specified by the `affinity` property in the request.
76
78
  */
77
- convertedAmount: string;
79
+ convertedAmount: bigint;
78
80
  /**
79
81
  * The cost of the fx request, in the form of a
80
82
  * token and amount that should be included with the swap
81
83
  */
82
84
  cost: {
83
- amount: string;
84
- token: KeetaNetTokenPublicKeyString;
85
+ amount: bigint;
86
+ token: KeetaNetToken;
85
87
  };
86
88
  /**
87
89
  * Signature information to verify the quote
@@ -92,9 +94,10 @@ export type KeetaFXAnchorQuote = {
92
94
  signature: string;
93
95
  };
94
96
  };
97
+ export type KeetaFXAnchorQuoteJSON = ToJSONSerializable<KeetaFXAnchorQuote>;
95
98
  export type KeetaFXAnchorQuoteResponse = ({
96
99
  ok: true;
97
- quote: KeetaFXAnchorQuote;
100
+ quote: ToJSONSerializable<KeetaFXAnchorQuote>;
98
101
  } | {
99
102
  ok: false;
100
103
  error: string;
@@ -111,4 +114,10 @@ export type KeetaFXAnchorExchangeResponse = KeetaFXAnchorExchange & ({
111
114
  ok: false;
112
115
  error: string;
113
116
  });
117
+ export declare const isKeetaFXAnchorEstimateResponse: (input: unknown) => input is KeetaFXAnchorEstimateResponse;
118
+ export declare const isKeetaFXAnchorQuoteResponse: (input: unknown) => input is KeetaFXAnchorQuoteResponse;
119
+ export declare const isKeetaFXAnchorExchangeResponse: (input: unknown) => input is KeetaFXAnchorExchangeResponse;
120
+ export declare const assertKeetaNetTokenPublicKeyString: (input: unknown) => KeetaNetTokenPublicKeyString;
121
+ export declare const assertConversionInputCanonicalJSON: (input: unknown) => ConversionInputCanonicalJSON;
122
+ export declare const assertConversionQuoteJSON: (input: unknown) => KeetaFXAnchorQuoteJSON;
114
123
  //# sourceMappingURL=common.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../src/services/fx/common.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,IAAI,WAAW,EAAE,MAAO,+BAA+B,CAAC;AACzE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAE1C,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAEnE,MAAM,MAAM,eAAe,GAAG,YAAY,CAAC,OAAO,WAAW,CAAC,OAAO,CAAC,CAAC;AACvE,MAAM,MAAM,aAAa,GAAG,YAAY,CAAC,OAAO,WAAW,CAAC,OAAO,CAAC,OAAO,WAAW,CAAC,OAAO,CAAC,mBAAmB,CAAC,KAAK,CAAC,CAAC,CAAC;AAC3H,MAAM,MAAM,4BAA4B,GAAG,UAAU,CAAC,YAAY,CAAC,OAAO,WAAW,CAAC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