UNPKG

@renegade-fi/core

Version:
32 lines 1.63 kB
import invariant from 'tiny-invariant'; import { ASSEMBLE_EXTERNAL_MATCH_ROUTE, RENEGADE_API_KEY_HEADER, } from '../constants.js'; import { BaseError } from '../errors/base.js'; import { stringifyForWasm } from '../utils/bigJSON.js'; import { postWithSymmetricKey } from '../utils/http.js'; export async function assembleExternalQuote(config, parameters) { const { quote, updatedOrder, doGasEstimation = false, receiverAddress = '', requestGasSponsorship, refundAddress, } = parameters; if (requestGasSponsorship !== undefined || refundAddress !== undefined) { console.warn('`requestGasSponsorship` and `refundAddress` are deprecated. Request gas sponsorship when requesting the quote.'); } const { apiSecret, apiKey } = config; invariant(apiSecret, 'API secret not specified in config'); invariant(apiKey, 'API key not specified in config'); const symmetricKey = config.utils.b64_to_hex_hmac_key(apiSecret); const stringifiedQuote = stringifyForWasm(quote); const stringifiedOrder = updatedOrder ? stringifyForWasm(updatedOrder) : ''; const body = config.utils.assemble_external_match(doGasEstimation, stringifiedOrder, stringifiedQuote, receiverAddress); const url = config.getBaseUrl(ASSEMBLE_EXTERNAL_MATCH_ROUTE); const res = await postWithSymmetricKey(config, { url, body, key: symmetricKey, headers: { [RENEGADE_API_KEY_HEADER]: apiKey, }, }); if (!res.match_bundle) { throw new BaseError('Failed to assemble external quote'); } return res; } //# sourceMappingURL=assembleExternalQuote.js.map