@wormhole-foundation/sdk-evm-portico
Version:
SDK for EVM chains, used in conjunction with @wormhole-foundation/sdk
31 lines • 1.48 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.PorticoApi = exports.RELAYER_FEE_API_URL = void 0;
const sdk_connect_1 = require("@wormhole-foundation/sdk-connect");
const axios_1 = __importDefault(require("axios"));
exports.RELAYER_FEE_API_URL = 'https://gfx.relayers.xlabs.xyz/api/v1/swap/quote';
class PorticoApi {
static async quoteRelayer(chain, from, to) {
if ((0, sdk_connect_1.isNative)(from) || (0, sdk_connect_1.isNative)(to))
throw new Error('how did you get here tho?');
const sourceToken = sdk_connect_1.encoding.hex.encode(from.toUniversalAddress().toUint8Array(), false);
const targetToken = sdk_connect_1.encoding.hex.encode(to.toUniversalAddress().toUint8Array(), false);
const targetChain = (0, sdk_connect_1.toChainId)(chain);
const request = { targetChain, sourceToken, targetToken };
try {
const response = await axios_1.default.post(exports.RELAYER_FEE_API_URL, request);
return BigInt(response.data.fee);
}
catch (e) {
if (axios_1.default.isAxiosError(e)) {
throw new Error(`Error getting relayer fee: ${e.response?.statusText}`);
}
throw e;
}
}
}
exports.PorticoApi = PorticoApi;
//# sourceMappingURL=api.js.map