@yoroi/swap
Version:
The Swap package of Yoroi SDK
41 lines (40 loc) • 1.59 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getSwapConfigApiMaker = void 0;
var _types = require("@yoroi/types");
var _portfolio = require("@yoroi/portfolio");
var _common = require("@yoroi/common");
var _immer = require("immer");
var _zod = require("zod");
const initialDeps = (0, _immer.freeze)({
request: _common.fetchData
}, true);
const getSwapConfigApiMaker = ({
request
} = initialDeps) => async () => {
const response = await request({
url: 'https://daehx1qv45z7c.cloudfront.net/swapConfig.json'
});
if ((0, _common.isLeft)(response)) throw (0, _common.getApiError)(response.error);
const parsedResponse = SwapConfigResponseSchema.safeParse(response.value.data);
if (!parsedResponse.success) {
throw new _types.Api.Errors.ResponseMalformed('Invalid swap config response: ' + JSON.stringify(response.value.data));
}
return parsedResponse.data;
};
exports.getSwapConfigApiMaker = getSwapConfigApiMaker;
const SwapConfigResponseSchema = _zod.z.object({
initialPair: _zod.z.object({
tokenIn: _portfolio.TokenIdSchema.refine(_ => true),
tokenOut: _portfolio.TokenIdSchema.refine(_ => true)
}).optional(),
verifiedTokens: _zod.z.array(_portfolio.TokenIdSchema.refine(_ => true)).optional(),
excludedTokens: _zod.z.array(_portfolio.TokenIdSchema.refine(_ => true)).optional(),
partners: _zod.z.object({
[_types.Swap.Aggregator.Dexhunter]: _zod.z.string().optional(),
[_types.Swap.Aggregator.Muesliswap]: _zod.z.string().optional()
}).optional()
});
//# sourceMappingURL=getSwapConfig.js.map