@keetanetwork/anchor 0.0.88 → 0.0.90
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/lib/metadata.types.d.ts +6 -0
- package/lib/metadata.types.d.ts.map +1 -1
- package/lib/metadata.types.js +33 -0
- package/lib/metadata.types.js.map +1 -1
- package/lib/queue/drivers/queue_firestore.js +1 -1
- package/lib/queue/drivers/queue_firestore.js.map +1 -1
- package/lib/queue/index.d.ts +8 -2
- package/lib/queue/index.d.ts.map +1 -1
- package/lib/queue/index.js +48 -12
- package/lib/queue/index.js.map +1 -1
- package/lib/resolver.d.ts +6 -1
- package/lib/resolver.d.ts.map +1 -1
- package/lib/resolver.generated.js +400 -295
- package/lib/resolver.generated.js.map +1 -1
- package/lib/resolver.js.map +1 -1
- package/npm-shrinkwrap.json +5 -5
- package/package.json +2 -2
- package/services/fx/client.d.ts +15 -2
- package/services/fx/client.d.ts.map +1 -1
- package/services/fx/client.js +199 -19
- package/services/fx/client.js.map +1 -1
- package/services/fx/common.d.ts +41 -0
- package/services/fx/common.d.ts.map +1 -1
- package/services/fx/common.js +29 -0
- package/services/fx/common.js.map +1 -1
- package/services/fx/server.d.ts +55 -1
- package/services/fx/server.d.ts.map +1 -1
- package/services/fx/server.js +95 -1
- package/services/fx/server.js.map +1 -1
- package/services/storage/client.d.ts +43 -0
- package/services/storage/client.d.ts.map +1 -1
- package/services/storage/client.js +65 -0
- package/services/storage/client.js.map +1 -1
- package/services/storage/clients/icon.d.ts +8 -0
- package/services/storage/clients/icon.d.ts.map +1 -1
- package/services/storage/clients/icon.js +10 -0
- package/services/storage/clients/icon.js.map +1 -1
- package/services/storage/test-utils.d.ts +16 -2
- package/services/storage/test-utils.d.ts.map +1 -1
- package/services/storage/test-utils.js +27 -2
- package/services/storage/test-utils.js.map +1 -1
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@keetanetwork/anchor",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.90",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@keetanetwork/anchor",
|
|
9
|
-
"version": "0.0.
|
|
9
|
+
"version": "0.0.90",
|
|
10
10
|
"license": "SEE LICENSE IN LICENSE",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@keetanetwork/currency-info": "1.2.5",
|
|
13
|
-
"@keetanetwork/keetanet-client": "0.18.
|
|
13
|
+
"@keetanetwork/keetanet-client": "0.18.3",
|
|
14
14
|
"@noble/hashes": "1.5.0",
|
|
15
15
|
"typia": "9.5.0"
|
|
16
16
|
},
|
|
@@ -186,8 +186,8 @@
|
|
|
186
186
|
"license": "ISC"
|
|
187
187
|
},
|
|
188
188
|
"node_modules/@keetanetwork/keetanet-client": {
|
|
189
|
-
"version": "0.18.
|
|
190
|
-
"integrity": "sha512-
|
|
189
|
+
"version": "0.18.3",
|
|
190
|
+
"integrity": "sha512-MgeUMnFIB3DNnF611KmTRQ4ME1rfwUVE5HBeUTeD06/szurd7+aALcwQCBOIbtfy7YhyGR2K6HRqktMel11DpQ==",
|
|
191
191
|
"license": "see LICENSE",
|
|
192
192
|
"dependencies": {
|
|
193
193
|
"secp256k1": "5.0.1"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@keetanetwork/anchor",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.90",
|
|
4
4
|
"description": "KeetaNetwork Network Anchor",
|
|
5
5
|
"main": "client/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"sideEffects": false,
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@keetanetwork/currency-info": "1.2.5",
|
|
27
|
-
"@keetanetwork/keetanet-client": "0.18.
|
|
27
|
+
"@keetanetwork/keetanet-client": "0.18.3",
|
|
28
28
|
"@noble/hashes": "1.5.0",
|
|
29
29
|
"typia": "9.5.0"
|
|
30
30
|
},
|
package/services/fx/client.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import type { Logger } from '../../lib/log/index.ts';
|
|
|
5
5
|
import type Resolver from '../../lib/resolver.ts';
|
|
6
6
|
import type { ServiceMetadata, SharedLookupCriteria } from '../../lib/resolver.ts';
|
|
7
7
|
import type { BrandedString } from '../../lib/utils/brand.ts';
|
|
8
|
-
import type { ConversionInput, ConversionInputCanonical, KeetaFXAnchorEstimate, KeetaFXAnchorExchange, KeetaFXAnchorQuote, KeetaNetTokenPublicKeyString } from './common.ts';
|
|
8
|
+
import type { ConversionInput, ConversionInputCanonical, KeetaFXAnchorEstimate, KeetaFXAnchorExchange, KeetaFXAnchorMarketPrices, KeetaFXAnchorMarketPricesRequest, KeetaFXAnchorMarketPriceRatio, KeetaFXAnchorQuote, KeetaNetTokenPublicKeyString } from './common.ts';
|
|
9
9
|
import type { AnchorExternalInput } from '../../lib/anchor-external.js';
|
|
10
10
|
import type { AnchorMetadataLegalField, SharedAnchorMetadataLegalExtension } from '../../lib/metadata.types.js';
|
|
11
11
|
import type { AnchorReference } from '../../lib/anchor-status.js';
|
|
@@ -110,6 +110,7 @@ export declare class KeetaFXAnchorProviderBase extends KeetaFXAnchorBase {
|
|
|
110
110
|
}, block?: InstanceType<typeof KeetaNetLib.Block>, options?: {
|
|
111
111
|
inputs?: readonly AnchorExternalInput[];
|
|
112
112
|
}): Promise<KeetaFXAnchorExchange>;
|
|
113
|
+
getMarketPrices(request: KeetaFXAnchorMarketPricesRequest): Promise<KeetaFXAnchorMarketPrices>;
|
|
113
114
|
getExchangeStatus(exchangeID: string): Promise<KeetaFXAnchorExchange>;
|
|
114
115
|
}
|
|
115
116
|
declare class KeetaFXAnchorExchangeWithProvider {
|
|
@@ -164,6 +165,10 @@ interface GetProvidersOptions extends AccountOptions {
|
|
|
164
165
|
interface GetPricesAssetReturnValue {
|
|
165
166
|
value: bigint;
|
|
166
167
|
averageConvertedAmount: number;
|
|
168
|
+
providerMarketPrices: {
|
|
169
|
+
provider: KeetaFXAnchorProviderBase;
|
|
170
|
+
price: KeetaFXAnchorMarketPriceRatio;
|
|
171
|
+
}[];
|
|
167
172
|
providerEstimates: KeetaFXAnchorEstimateWithProvider[];
|
|
168
173
|
}
|
|
169
174
|
export interface GetPricesArgs<Asset extends ConversionInput['from']> {
|
|
@@ -171,6 +176,13 @@ export interface GetPricesArgs<Asset extends ConversionInput['from']> {
|
|
|
171
176
|
priceIn: ConversionInput['from'];
|
|
172
177
|
conversionValue?: bigint | ((input: Asset) => bigint | Promise<bigint>);
|
|
173
178
|
conversionAffinity?: ConversionInput['affinity'];
|
|
179
|
+
/**
|
|
180
|
+
* Behavior when a provider returns an invalid market price ratio
|
|
181
|
+
* (e.g. zero quote/base). Defaults to `'omit'`.
|
|
182
|
+
*
|
|
183
|
+
* Invalid ratios are always logged regardless of this setting.
|
|
184
|
+
*/
|
|
185
|
+
onInvalidRatio?: 'omit' | 'throw';
|
|
174
186
|
}
|
|
175
187
|
declare class KeetaFXAnchorClient extends KeetaFXAnchorBase {
|
|
176
188
|
#private;
|
|
@@ -190,8 +202,9 @@ declare class KeetaFXAnchorClient extends KeetaFXAnchorBase {
|
|
|
190
202
|
getEstimates(request: ConversionInput, options?: Omit<GetProvidersOptions, 'requiredOperations'>, sharedCriteria?: SharedLookupCriteria): Promise<KeetaFXAnchorEstimateWithProvider[] | null>;
|
|
191
203
|
getQuotes(request: ConversionInput, options?: AccountOptions, sharedCriteria?: SharedLookupCriteria): Promise<KeetaFXAnchorQuoteWithProvider[] | null>;
|
|
192
204
|
getQuotesOrEstimates(request: ConversionInput, options?: AccountOptions, sharedCriteria?: SharedLookupCriteria): Promise<(KeetaFXAnchorQuoteWithProvider | KeetaFXAnchorEstimateWithProvider)[] | null>;
|
|
193
|
-
getPrices<Asset extends ConversionInput['from']>(input: GetPricesArgs<Asset
|
|
205
|
+
getPrices<Asset extends ConversionInput['from']>(input: GetPricesArgs<Asset>, options?: Omit<GetProvidersOptions, 'requiredOperations'>, sharedCriteria?: SharedLookupCriteria): Promise<Map<Asset, GetPricesAssetReturnValue | null>>;
|
|
194
206
|
getLegalDisclaimersById(providerID: string): Promise<NonNullable<AnchorMetadataLegalField['disclaimers']> | null>;
|
|
207
|
+
getMarketPrices(providerID: string, request: KeetaFXAnchorMarketPricesRequest): Promise<KeetaFXAnchorMarketPrices | null>;
|
|
195
208
|
}
|
|
196
209
|
export default KeetaFXAnchorClient;
|
|
197
210
|
//# sourceMappingURL=client.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","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;AACrD,OAAO,KAAK,EACX,UAAU,IAAI,kBAAkB,EAChC,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,KAAK,QAAQ,MAAM,uBAAuB,CAAC;AAClD,OAAO,KAAK,EAAE,eAAe,EAAyB,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAI1G,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"client.d.ts","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;AACrD,OAAO,KAAK,EACX,UAAU,IAAI,kBAAkB,EAChC,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wB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AAI,CAAC;CAuC/H;AAED,eAAe,mBAAmB,CAAC"}
|
package/services/fx/client.js
CHANGED
|
@@ -3,7 +3,7 @@ import { getDefaultResolver } from '../../config.js';
|
|
|
3
3
|
import { Buffer } from '../../lib/utils/buffer.js';
|
|
4
4
|
import crypto from '../../lib/utils/crypto.js';
|
|
5
5
|
import { validateURL } from '../../lib/utils/url.js';
|
|
6
|
-
import { assertKeetaNetTokenPublicKeyString, isKeetaFXAnchorEstimateResponse, isKeetaFXAnchorExchangeResponse, isKeetaFXAnchorQuoteResponse, Errors as FXErrors } from './common.js';
|
|
6
|
+
import { assertKeetaNetTokenPublicKeyString, isKeetaFXAnchorEstimateResponse, isKeetaFXAnchorExchangeResponse, isKeetaFXAnchorMarketPricesResponse, isKeetaFXAnchorQuoteResponse, Errors as FXErrors } from './common.js';
|
|
7
7
|
import { AnchorExternalBuilder } from '../../lib/anchor-external.js';
|
|
8
8
|
import { KeetaAnchorError, KeetaAnchorUserError } from '../../lib/error.js';
|
|
9
9
|
import { resolveSharedAnchorMetadataLegalExtension } from '../../lib/metadata.types.js';
|
|
@@ -371,6 +371,29 @@ export class KeetaFXAnchorProviderBase extends KeetaFXAnchorBase {
|
|
|
371
371
|
this.logger?.debug(`FX exchange request successful, to provider ${serviceURL} for ${swapBlock.hash.toString()}`);
|
|
372
372
|
return (requestInformationJSON);
|
|
373
373
|
}
|
|
374
|
+
async getMarketPrices(request) {
|
|
375
|
+
const serviceURL = await this.#getEndpoint('getMarketPrices');
|
|
376
|
+
serviceURL.searchParams.set('quoteAssets', request.quoteAssets.join(','));
|
|
377
|
+
serviceURL.searchParams.set('base', request.base);
|
|
378
|
+
const requestInformation = await fetch(serviceURL, {
|
|
379
|
+
method: 'GET',
|
|
380
|
+
headers: {
|
|
381
|
+
'Accept': 'application/json'
|
|
382
|
+
}
|
|
383
|
+
});
|
|
384
|
+
const requestInformationJSON = await requestInformation.json();
|
|
385
|
+
if (!isKeetaFXAnchorMarketPricesResponse(requestInformationJSON)) {
|
|
386
|
+
throw (new Error(`Invalid response from FX market prices service: ${JSON.stringify(requestInformationJSON)}`));
|
|
387
|
+
}
|
|
388
|
+
if (!requestInformationJSON.ok) {
|
|
389
|
+
throw (await this.#parseResponseError(requestInformationJSON));
|
|
390
|
+
}
|
|
391
|
+
this.logger?.debug(`FX market prices request successful, to provider ${serviceURL} for quoteAssets=${request.quoteAssets.join(',')} base=${request.base}`);
|
|
392
|
+
return ({
|
|
393
|
+
base: requestInformationJSON.base,
|
|
394
|
+
quoteAssets: requestInformationJSON.quoteAssets
|
|
395
|
+
});
|
|
396
|
+
}
|
|
374
397
|
async getExchangeStatus(exchangeID) {
|
|
375
398
|
const serviceURL = await this.#getEndpoint('getExchangeStatus', { id: exchangeID });
|
|
376
399
|
const requestInformation = await fetch(serviceURL, {
|
|
@@ -469,6 +492,20 @@ class KeetaFXAnchorEstimateWithProvider {
|
|
|
469
492
|
return (new KeetaFXAnchorEstimateWithProvider(this.provider, estimate));
|
|
470
493
|
}
|
|
471
494
|
}
|
|
495
|
+
function providerSupportsGetMarketPrices(provider) {
|
|
496
|
+
return (Object.prototype.hasOwnProperty.call(provider.serviceInfo.operations, 'getMarketPrices'));
|
|
497
|
+
}
|
|
498
|
+
function convertUsingMarketPriceRatio(ratio, conversionValue, affinity) {
|
|
499
|
+
const quote = BigInt(ratio.quote);
|
|
500
|
+
const base = BigInt(ratio.base);
|
|
501
|
+
if (quote === 0n || base === 0n) {
|
|
502
|
+
throw (new Error(`Invalid market price ratio: quote=${ratio.quote} base=${ratio.base}`));
|
|
503
|
+
}
|
|
504
|
+
if (affinity === 'from') {
|
|
505
|
+
return (conversionValue * base / quote);
|
|
506
|
+
}
|
|
507
|
+
return (conversionValue * quote / base);
|
|
508
|
+
}
|
|
472
509
|
class KeetaFXAnchorClient extends KeetaFXAnchorBase {
|
|
473
510
|
resolver;
|
|
474
511
|
id;
|
|
@@ -739,10 +776,20 @@ class KeetaFXAnchorClient extends KeetaFXAnchorBase {
|
|
|
739
776
|
}
|
|
740
777
|
return (retval);
|
|
741
778
|
}
|
|
742
|
-
async getPrices(input) {
|
|
743
|
-
const
|
|
744
|
-
|
|
745
|
-
|
|
779
|
+
async getPrices(input, options = {}, sharedCriteria) {
|
|
780
|
+
const priceInCanonical = await this.canonicalizeConversionTokens({ to: input.priceIn ?? 'USD' });
|
|
781
|
+
if (priceInCanonical.to === undefined) {
|
|
782
|
+
throw (new Error('Could not canonicalize priceIn asset'));
|
|
783
|
+
}
|
|
784
|
+
const base = priceInCanonical.to.publicKeyString.get();
|
|
785
|
+
const affinity = input.conversionAffinity ?? 'from';
|
|
786
|
+
const priceIn = input.priceIn ?? 'USD';
|
|
787
|
+
const onInvalidRatio = input.onInvalidRatio ?? 'omit';
|
|
788
|
+
const assetEntries = await Promise.all(input.assets.map(async (asset) => {
|
|
789
|
+
const canonical = await this.canonicalizeConversionTokens({ from: asset });
|
|
790
|
+
if (canonical.from === undefined) {
|
|
791
|
+
throw (new Error(`Could not canonicalize asset: ${String(asset)}`));
|
|
792
|
+
}
|
|
746
793
|
let conversionValue;
|
|
747
794
|
if (input.conversionValue !== undefined) {
|
|
748
795
|
if (typeof input.conversionValue === 'function') {
|
|
@@ -755,27 +802,140 @@ class KeetaFXAnchorClient extends KeetaFXAnchorBase {
|
|
|
755
802
|
else {
|
|
756
803
|
conversionValue = 1n;
|
|
757
804
|
}
|
|
758
|
-
const
|
|
805
|
+
const providers = await this.getBaseProvidersForConversion({
|
|
759
806
|
from: asset,
|
|
760
|
-
to:
|
|
807
|
+
to: priceIn,
|
|
761
808
|
amount: conversionValue,
|
|
762
|
-
affinity
|
|
809
|
+
affinity
|
|
810
|
+
}, options, sharedCriteria);
|
|
811
|
+
return ({
|
|
812
|
+
asset,
|
|
813
|
+
quoteAsset: canonical.from.publicKeyString.get(),
|
|
814
|
+
conversionValue,
|
|
815
|
+
providers
|
|
763
816
|
});
|
|
764
|
-
|
|
765
|
-
|
|
817
|
+
}));
|
|
818
|
+
const providerAssets = new Map();
|
|
819
|
+
const estimateEntries = [];
|
|
820
|
+
for (const entry of assetEntries) {
|
|
821
|
+
if (entry.providers === null) {
|
|
822
|
+
continue;
|
|
766
823
|
}
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
824
|
+
for (const provider of entry.providers) {
|
|
825
|
+
if (providerSupportsGetMarketPrices(provider)) {
|
|
826
|
+
const existing = providerAssets.get(provider.providerID) ?? [];
|
|
827
|
+
existing.push({
|
|
828
|
+
asset: entry.asset,
|
|
829
|
+
quoteAsset: entry.quoteAsset,
|
|
830
|
+
conversionValue: entry.conversionValue,
|
|
831
|
+
provider
|
|
832
|
+
});
|
|
833
|
+
providerAssets.set(provider.providerID, existing);
|
|
834
|
+
}
|
|
835
|
+
else {
|
|
836
|
+
estimateEntries.push({
|
|
837
|
+
asset: entry.asset,
|
|
838
|
+
conversionValue: entry.conversionValue,
|
|
839
|
+
provider
|
|
840
|
+
});
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
const providerPriceResults = await Promise.all([...providerAssets.entries()].map(async ([_ignore_providerID, entries]) => {
|
|
845
|
+
const firstEntry = entries[0];
|
|
846
|
+
if (firstEntry === undefined) {
|
|
847
|
+
return (null);
|
|
848
|
+
}
|
|
849
|
+
const provider = firstEntry.provider;
|
|
850
|
+
const quoteAssets = [...new Set(entries.map(function (entry) {
|
|
851
|
+
return (entry.quoteAsset);
|
|
852
|
+
}))];
|
|
853
|
+
try {
|
|
854
|
+
const marketPrices = await provider.getMarketPrices({ quoteAssets, base });
|
|
855
|
+
return ({ provider, marketPrices, entries });
|
|
856
|
+
}
|
|
857
|
+
catch (error) {
|
|
858
|
+
this.logger?.error(`Failed to get market prices from provider ${String(provider.providerID)}:`, error);
|
|
859
|
+
return (null);
|
|
860
|
+
}
|
|
861
|
+
}));
|
|
862
|
+
const assetProviderPrices = new Map();
|
|
863
|
+
for (const result of providerPriceResults) {
|
|
864
|
+
if (result === null) {
|
|
865
|
+
continue;
|
|
866
|
+
}
|
|
867
|
+
for (const entry of result.entries) {
|
|
868
|
+
const priceEntry = result.marketPrices.quoteAssets[entry.quoteAsset];
|
|
869
|
+
if (priceEntry === undefined) {
|
|
870
|
+
continue;
|
|
871
|
+
}
|
|
872
|
+
try {
|
|
873
|
+
// Validate ratio early so convertUsingMarketPriceRatio cannot crash the batch later.
|
|
874
|
+
convertUsingMarketPriceRatio(priceEntry.valueRatio, entry.conversionValue, affinity);
|
|
875
|
+
}
|
|
876
|
+
catch (error) {
|
|
877
|
+
this.logger?.error(`Invalid market price ratio from provider ${String(result.provider.providerID)} for quote asset ${entry.quoteAsset} against base ${base}:`, error, priceEntry.valueRatio);
|
|
878
|
+
if (onInvalidRatio === 'throw') {
|
|
879
|
+
throw (error);
|
|
880
|
+
}
|
|
881
|
+
continue;
|
|
882
|
+
}
|
|
883
|
+
const prices = assetProviderPrices.get(entry.asset) ?? [];
|
|
884
|
+
prices.push({
|
|
885
|
+
provider: result.provider,
|
|
886
|
+
price: priceEntry.valueRatio
|
|
887
|
+
});
|
|
888
|
+
assetProviderPrices.set(entry.asset, prices);
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
const estimateResults = await Promise.all(estimateEntries.map(async (entry) => {
|
|
892
|
+
try {
|
|
893
|
+
const estimate = await entry.provider.getEstimate();
|
|
894
|
+
return ({
|
|
895
|
+
asset: entry.asset,
|
|
896
|
+
estimate: new KeetaFXAnchorEstimateWithProvider(entry.provider, estimate)
|
|
776
897
|
});
|
|
777
898
|
}
|
|
899
|
+
catch (error) {
|
|
900
|
+
this.logger?.error(`Failed to get estimate from provider ${String(entry.provider.providerID)}:`, error);
|
|
901
|
+
return (null);
|
|
902
|
+
}
|
|
778
903
|
}));
|
|
904
|
+
const assetProviderEstimates = new Map();
|
|
905
|
+
for (const result of estimateResults) {
|
|
906
|
+
if (result === null) {
|
|
907
|
+
continue;
|
|
908
|
+
}
|
|
909
|
+
const estimates = assetProviderEstimates.get(result.asset) ?? [];
|
|
910
|
+
estimates.push(result.estimate);
|
|
911
|
+
assetProviderEstimates.set(result.asset, estimates);
|
|
912
|
+
}
|
|
913
|
+
const retval = new Map();
|
|
914
|
+
for (const entry of assetEntries) {
|
|
915
|
+
const providerMarketPrices = assetProviderPrices.get(entry.asset) ?? [];
|
|
916
|
+
const providerEstimates = assetProviderEstimates.get(entry.asset) ?? [];
|
|
917
|
+
if (providerMarketPrices.length === 0 && providerEstimates.length === 0) {
|
|
918
|
+
retval.set(entry.asset, null);
|
|
919
|
+
continue;
|
|
920
|
+
}
|
|
921
|
+
const convertedAmountSum = [
|
|
922
|
+
...providerMarketPrices.map(function (providerPrice) {
|
|
923
|
+
return (convertUsingMarketPriceRatio(providerPrice.price, entry.conversionValue, affinity));
|
|
924
|
+
}),
|
|
925
|
+
...providerEstimates.map(function (providerEstimate) {
|
|
926
|
+
return (providerEstimate.estimate.convertedAmount);
|
|
927
|
+
})
|
|
928
|
+
].reduce(function (sum, convertedAmount) {
|
|
929
|
+
return (sum + convertedAmount);
|
|
930
|
+
}, 0n);
|
|
931
|
+
const providerCount = providerMarketPrices.length + providerEstimates.length;
|
|
932
|
+
retval.set(entry.asset, {
|
|
933
|
+
value: entry.conversionValue,
|
|
934
|
+
averageConvertedAmount: Number(convertedAmountSum) / providerCount,
|
|
935
|
+
providerMarketPrices,
|
|
936
|
+
providerEstimates
|
|
937
|
+
});
|
|
938
|
+
}
|
|
779
939
|
return (retval);
|
|
780
940
|
}
|
|
781
941
|
async getLegalDisclaimersById(providerID) {
|
|
@@ -793,6 +953,26 @@ class KeetaFXAnchorClient extends KeetaFXAnchorBase {
|
|
|
793
953
|
}
|
|
794
954
|
return (disclaimers);
|
|
795
955
|
}
|
|
956
|
+
async getMarketPrices(providerID, request) {
|
|
957
|
+
const endpoints = await getEndpoints(this.resolver, {
|
|
958
|
+
requiredOperations: ['getMarketPrices']
|
|
959
|
+
}, this.#account, { providerIDs: [providerID] }, { logger: this.logger });
|
|
960
|
+
if (endpoints === null) {
|
|
961
|
+
return (null);
|
|
962
|
+
}
|
|
963
|
+
const serviceEntry = typedFxServiceEntries(endpoints)[0];
|
|
964
|
+
if (!serviceEntry) {
|
|
965
|
+
return (null);
|
|
966
|
+
}
|
|
967
|
+
const [resolvedProviderID, serviceInfo] = serviceEntry;
|
|
968
|
+
const provider = new KeetaFXAnchorProviderBase(serviceInfo, resolvedProviderID, {
|
|
969
|
+
from: KeetaNetLib.Account.fromPublicKeyString(request.quoteAssets[0] ?? request.base),
|
|
970
|
+
to: KeetaNetLib.Account.fromPublicKeyString(request.base),
|
|
971
|
+
amount: 1n,
|
|
972
|
+
affinity: 'from'
|
|
973
|
+
}, this);
|
|
974
|
+
return (await provider.getMarketPrices(request));
|
|
975
|
+
}
|
|
796
976
|
/** @internal */
|
|
797
977
|
_internals(accessToken) {
|
|
798
978
|
if (accessToken !== KeetaFXAnchorClientAccessToken) {
|