UNPKG

@renproject/ren

Version:

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

71 lines 3.65 kB
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; import { ErrorWithCode, InputType, isContractChain, OutputType, RenJSError, } from "@renproject/utils"; /** * Detect whether the transaction is a lock-and-mint, burn-and-release or * burn-and-mint, and return the selector. */ export const getInputAndOutputTypes = ({ asset, fromChain, toChain, }) => __awaiter(void 0, void 0, void 0, function* () { const [isLockAssetOnFromChain, isLockAssetOnToChain, isMintAssetOnFromChain, isMintAssetOnToChain,] = yield Promise.all([ fromChain.isLockAsset(asset), toChain.isLockAsset(asset), isContractChain(fromChain) && fromChain.isMintAsset(asset), isContractChain(toChain) && toChain.isMintAsset(asset), ]); if (isLockAssetOnToChain) { // Burn and release if (!isContractChain(fromChain)) { throw ErrorWithCode.updateError(new Error(`Cannot burn from non-contract chain ${fromChain.chain}.`), RenJSError.PARAMETER_ERROR); } if (!isMintAssetOnFromChain) { throw ErrorWithCode.updateError(new Error(`Asset '${asset}' is not supported on ${fromChain.chain}.`), RenJSError.PARAMETER_ERROR); } return { inputType: InputType.Burn, outputType: OutputType.Release, selector: `${asset}/from${fromChain.chain}`, }; } else if (isLockAssetOnFromChain) { // Lock and mint if (!isContractChain(toChain)) { throw ErrorWithCode.updateError(new Error(`Cannot mint to non-contract chain ${toChain.chain}.`), RenJSError.PARAMETER_ERROR); } if (!isMintAssetOnToChain) { throw ErrorWithCode.updateError(new Error(`Asset '${asset}' is not supported on ${toChain.chain}.`), RenJSError.PARAMETER_ERROR); } return { inputType: InputType.Lock, outputType: OutputType.Mint, selector: `${asset}/to${toChain.chain}`, }; } else { // Burn and mint if (!isContractChain(toChain)) { throw ErrorWithCode.updateError(new Error(`Cannot mint to non-contract chain ${toChain.chain}.`), RenJSError.PARAMETER_ERROR); } if (!isMintAssetOnToChain) { throw ErrorWithCode.updateError(new Error(`Asset '${asset}' is not supported on ${toChain.chain}.`), RenJSError.PARAMETER_ERROR); } if (!isContractChain(fromChain)) { throw ErrorWithCode.updateError(new Error(`Cannot burn from non-contract chain ${fromChain.chain}.`), RenJSError.PARAMETER_ERROR); } if (!isMintAssetOnFromChain) { throw ErrorWithCode.updateError(new Error(`Asset '${asset}' is not supported on ${fromChain.chain}.`), RenJSError.PARAMETER_ERROR); } return { inputType: InputType.Burn, outputType: OutputType.Mint, selector: `${asset}/from${fromChain.chain}_to${toChain.chain}`, }; } }); //# sourceMappingURL=inputAndOutputTypes.js.map