@rarimo/swap
Version:
Internal tools that other Rarimo packages use to swap tokens.
31 lines (30 loc) • 1.23 kB
JavaScript
import { BUNDLE_SALT_BYTES, isUndefined } from "@rarimo/shared";
import { utils } from "ethers";
import { SwapCommands } from "../../../enums";
import { buildIntermediateBundleData } from "./intermediate-bundle";
import { buildPayload } from "./payload";
export const getBridgeData = (isBridgingRequired, intermediateOpts, chainTo, to, amountOut, receiver, bundle, isWrapped)=>{
if (!isBridgingRequired) return [];
if (isUndefined(isWrapped) || !intermediateOpts) {
throw new TypeError('isWrapped, intermediateOpts arguments are required for bridging');
}
const bundleTuple = [
(bundle === null || bundle === void 0 ? void 0 : bundle.salt) || utils.hexlify(utils.randomBytes(BUNDLE_SALT_BYTES)),
buildIntermediateBundleData(intermediateOpts, chainTo, receiver, bundle)
];
return [
buildPayload(to.isNative ? SwapCommands.BridgeNative : SwapCommands.BridgeErc20, [
...to.isNative ? [] : [
to.address
],
amountOut.value,
bundleTuple,
chainTo.name,
receiver,
...to.isNative ? [] : [
isWrapped
]
])
];
};
//# sourceMappingURL=bridge.js.map