UNPKG

@renproject/ren

Version:

Official Ren JavaScript SDK for bridging crypto assets cross-chain.

66 lines 3.29 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getInputAndOutputTypes = void 0; const utils_1 = require("@renproject/utils"); /** * Detect whether the transaction is a lock-and-mint, burn-and-release or * burn-and-mint, and return the selector. */ const getInputAndOutputTypes = async ({ asset, fromChain, toChain, }) => { const [isLockAssetOnFromChain, isLockAssetOnToChain, isMintAssetOnFromChain, isMintAssetOnToChain,] = await Promise.all([ fromChain.isLockAsset(asset), toChain.isLockAsset(asset), (0, utils_1.isContractChain)(fromChain) && fromChain.isMintAsset(asset), (0, utils_1.isContractChain)(toChain) && toChain.isMintAsset(asset), ]); if (isLockAssetOnToChain) { // Burn and release if (!(0, utils_1.isContractChain)(fromChain)) { throw utils_1.ErrorWithCode.updateError(new Error(`Cannot burn from non-contract chain ${fromChain.chain}.`), utils_1.RenJSError.PARAMETER_ERROR); } if (!isMintAssetOnFromChain) { throw utils_1.ErrorWithCode.updateError(new Error(`Asset '${asset}' is not supported on ${fromChain.chain}.`), utils_1.RenJSError.PARAMETER_ERROR); } return { inputType: utils_1.InputType.Burn, outputType: utils_1.OutputType.Release, selector: `${asset}/from${fromChain.chain}`, }; } else if (isLockAssetOnFromChain) { // Lock and mint if (!(0, utils_1.isContractChain)(toChain)) { throw utils_1.ErrorWithCode.updateError(new Error(`Cannot mint to non-contract chain ${toChain.chain}.`), utils_1.RenJSError.PARAMETER_ERROR); } if (!isMintAssetOnToChain) { throw utils_1.ErrorWithCode.updateError(new Error(`Asset '${asset}' is not supported on ${toChain.chain}.`), utils_1.RenJSError.PARAMETER_ERROR); } return { inputType: utils_1.InputType.Lock, outputType: utils_1.OutputType.Mint, selector: `${asset}/to${toChain.chain}`, }; } else { // Burn and mint if (!(0, utils_1.isContractChain)(toChain)) { throw utils_1.ErrorWithCode.updateError(new Error(`Cannot mint to non-contract chain ${toChain.chain}.`), utils_1.RenJSError.PARAMETER_ERROR); } if (!isMintAssetOnToChain) { throw utils_1.ErrorWithCode.updateError(new Error(`Asset '${asset}' is not supported on ${toChain.chain}.`), utils_1.RenJSError.PARAMETER_ERROR); } if (!(0, utils_1.isContractChain)(fromChain)) { throw utils_1.ErrorWithCode.updateError(new Error(`Cannot burn from non-contract chain ${fromChain.chain}.`), utils_1.RenJSError.PARAMETER_ERROR); } if (!isMintAssetOnFromChain) { throw utils_1.ErrorWithCode.updateError(new Error(`Asset '${asset}' is not supported on ${fromChain.chain}.`), utils_1.RenJSError.PARAMETER_ERROR); } return { inputType: utils_1.InputType.Burn, outputType: utils_1.OutputType.Mint, selector: `${asset}/from${fromChain.chain}_to${toChain.chain}`, }; } }; exports.getInputAndOutputTypes = getInputAndOutputTypes; //# sourceMappingURL=inputAndOutputTypes.js.map