{"version":3,"file":"PriceServiceConnection.mjs","names":[],"sources":["../../src/pyth/PriceServiceConnection.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\nimport axios from 'axios';\nimport type { AxiosInstance } from 'axios';\nimport axiosRetry from 'axios-retry';\n\nexport type HexString = string;\nexport type PriceFeedRequestConfig = {\n\tverbose?: boolean;\n\tbinary?: boolean;\n};\nexport type PriceServiceConnectionConfig = {\n\ttimeout?: number;\n\thttpRetries?: number;\n\taccessToken?: string;\n};\nexport class PriceServiceConnection {\n\tprivate httpClient: AxiosInstance;\n\t/**\n\t * Constructs a new Connection.\n\t *\n\t * @param endpoint endpoint URL to the price service.\n\t * @param config Optional configuration for custom setups.\n\t */\n\tconstructor(endpoint: string, config?: PriceServiceConnectionConfig) {\n\t\tthis.httpClient = axios.create({\n\t\t\tbaseURL: endpoint,\n\t\t\ttimeout: config?.timeout || 5000,\n\t\t\theaders: config?.accessToken ? { Authorization: `Bearer ${config.accessToken}` } : undefined,\n\t\t});\n\t\taxiosRetry(this.httpClient, {\n\t\t\tretries: config?.httpRetries || 3,\n\t\t\tretryDelay: axiosRetry.exponentialDelay,\n\t\t});\n\t}\n\t/**\n\t * Fetch latest VAAs of given price IDs.\n\t *\n\t * @param priceIds Array of hex-encoded price IDs.\n\t * @returns Array of base64 encoded VAAs.\n\t */\n\tasync getLatestVaas(priceIds: HexString[]): Promise<string[]> {\n\t\tconst response = await this.httpClient.get('/v2/updates/price/latest', {\n\t\t\tparams: {\n\t\t\t\t'ids[]': priceIds,\n\t\t\t\tencoding: 'base64',\n\t\t\t\tparsed: false,\n\t\t\t},\n\t\t});\n\t\tconst data = response.data?.binary?.data;\n\t\tif (!Array.isArray(data)) {\n\t\t\tthrow new Error('Unexpected Hermes response: missing `binary.data`.');\n\t\t}\n\t\treturn data;\n\t}\n}\n"],"mappings":";;;;AAgBA,IAAa,yBAAb,MAAoC;;;;;;;CAQnC,YAAY,UAAkB,QAAuC;AACpE,OAAK,aAAa,MAAM,OAAO;GAC9B,SAAS;GACT,0DAAS,OAAQ,YAAW;GAC5B,0DAAS,OAAQ,eAAc,EAAE,eAAe,UAAU,OAAO,eAAe,GAAG;GACnF,CAAC;AACF,aAAW,KAAK,YAAY;GAC3B,0DAAS,OAAQ,gBAAe;GAChC,YAAY,WAAW;GACvB,CAAC;;;;;;;;CAQH,MAAM,cAAc,UAA0C;;EAQ7D,MAAM,0BAPW,MAAM,KAAK,WAAW,IAAI,4BAA4B,EACtE,QAAQ;GACP,SAAS;GACT,UAAU;GACV,QAAQ;GACR,EACD,CAAC,EACoB,gFAAM,wEAAQ;AACpC,MAAI,CAAC,MAAM,QAAQ,KAAK,CACvB,OAAM,IAAI,MAAM,qDAAqD;AAEtE,SAAO"}