2021-12-05 05:23:21 +00:00
|
|
|
import { web3 } from "hardhat";
|
2021-12-10 17:29:55 +00:00
|
|
|
import abis from "../constant/abis";
|
2021-12-05 05:23:21 +00:00
|
|
|
|
2021-12-05 19:10:22 +00:00
|
|
|
export function encodeSpells(spells: any[]) {
|
2021-12-05 05:23:21 +00:00
|
|
|
const targets = spells.map((a) => a.connector);
|
|
|
|
const calldatas = spells.map((a) => {
|
|
|
|
const functionName = a.method;
|
|
|
|
// console.log(functionName)
|
|
|
|
const abi = abis.connectors[a.connector].find((b: { name: any }) => {
|
|
|
|
return b.name === functionName;
|
|
|
|
});
|
|
|
|
// console.log(functionName)
|
|
|
|
if (!abi) throw new Error("Couldn't find function");
|
|
|
|
return web3.eth.abi.encodeFunctionCall(abi, a.args);
|
|
|
|
});
|
|
|
|
return [targets, calldatas];
|
2021-12-05 19:10:22 +00:00
|
|
|
}
|