UNPKG

@kiroboio/fct-core

Version:

Kirobo.io FCT Core library

84 lines 2.74 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getPlugin = getPlugin; exports.getPluginClass = getPluginClass; exports.getPluginData = getPluginData; const fct_plugins_1 = require("@kiroboio/fct-plugins"); const helpers_1 = require("../../helpers"); function getPlugin(index) { const chainId = this.chainId; const call = this.getCall(index); if (call.plugin) { return call.plugin; } const callData = call.get(); if (helpers_1.InstanceOf.Variable(callData.to)) { throw new Error("To value cannot be a variable"); } let PluginClass; const pluginData = (0, fct_plugins_1.getPlugin)({ signature: call.getFunctionSignature(), address: callData.to, chainId: chainId, }); if (pluginData === null || pluginData === undefined) { throw new Error("Plugin not found"); } if (pluginData instanceof fct_plugins_1.Multicall) { PluginClass = pluginData; } else { if (Array.isArray(pluginData) || !pluginData.plugin) { throw new Error("Plugin not found"); } // @ts-ignore PluginClass = new pluginData.plugin({ chainId: chainId.toString(), }); } PluginClass.input.set({ to: callData.to, value: callData.value, // TODO: Temporary fix, need to fix the type in plugins methodParams: callData.params ? callData.params.reduce((acc, param) => { return { ...acc, [param.name]: param.value }; }, {}) : {}, }); return PluginClass; } async function getPluginClass(index) { const chainId = this.chainId; const call = this.getCall(index); const callData = call.get(); if (helpers_1.InstanceOf.Variable(callData.to)) { throw new Error("To value cannot be a variable"); } const pluginData = (0, fct_plugins_1.getPlugin)({ signature: call.getFunctionSignature(), address: callData.to, chainId: chainId.toString(), }); return pluginData; } async function getPluginData(index) { const plugin = await this.getPlugin(index); // get the plugin from the index const call = this.getCall(index); // get the call from the index const callData = call.get(); const input = { to: callData.to, value: callData.value, methodParams: callData.params ? callData.params.reduce((acc, param) => { return { ...acc, [param.name]: param.value }; }, {}) : {}, }; return { protocol: plugin.protocol, type: plugin.type, method: plugin.method, input, }; } //# sourceMappingURL=plugins.js.map