UNPKG

@devasher/kuru-sdk

Version:

Ethers v6 SDK to interact with Kuru (forked from @kuru-labs/kuru-sdk)

68 lines 2.55 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.constructUnwrapTransaction = exports.constructWrapTransaction = void 0; // ============ External Imports ============ const ethers_1 = require("ethers"); // ============ Internal Imports ============ const errorExtractor_1 = require("./errorExtractor"); const WMon_json_1 = __importDefault(require("../../abi/WMon.json")); const txConfig_1 = __importDefault(require("./txConfig")); /** * @dev Wraps native tokens into wrapped tokens (e.g. ETH -> WETH) * @param wrapperContract - The wrapper token contract instance * @param amount - Amount of native tokens to wrap * @returns Transaction hash */ async function constructWrapTransaction(signer, wrapperContractAddress, amount, txOptions) { try { const address = await signer.getAddress(); const wrapperContractInterface = new ethers_1.ethers.Interface(WMon_json_1.default); const data = wrapperContractInterface.encodeFunctionData('deposit'); return (0, txConfig_1.default)({ to: wrapperContractAddress, from: address, value: amount, data, txOptions, signer, }); } catch (e) { if (!e.error) { throw e; } throw (0, errorExtractor_1.extractErrorMessage)(e); } } exports.constructWrapTransaction = constructWrapTransaction; /** * @dev Unwraps wrapped tokens back to native tokens (e.g. WETH -> ETH) * @param wrapperContract - The wrapper token contract instance * @param amount - Amount of wrapped tokens to unwrap * @returns Transaction hash */ async function constructUnwrapTransaction(signer, wrapperContractAddress, amount, txOptions) { try { const address = await signer.getAddress(); const wrapperContractInterface = new ethers_1.ethers.Interface(WMon_json_1.default); const data = wrapperContractInterface.encodeFunctionData('withdraw', [amount]); return (0, txConfig_1.default)({ to: wrapperContractAddress, from: address, data, txOptions, signer, }); } catch (e) { if (!e.error) { throw e; } throw (0, errorExtractor_1.extractErrorMessage)(e); } } exports.constructUnwrapTransaction = constructUnwrapTransaction; //# sourceMappingURL=unwrap.js.map