@pushchain/core
Version:
Push Chain is a true universal L1 that is 100% EVM compatible. It allows developers to deploy once and make their apps instantly compatible with users from all other L1s (Ethereum, Solana, etc) with zero on-chain code change.
59 lines • 2.24 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildExecuteMulticall = buildExecuteMulticall;
const viem_1 = require("viem");
const push_chain_1 = require("../push-chain/push-chain");
const abi_1 = require("../constants/abi");
function buildExecuteMulticall({ execute, ueaAddress, }) {
var _a, _b;
const multicallData = [];
// *** We will pass the value alongside with the data in a single message now ***
if (!execute.data && execute.value) {
multicallData.push({
to: execute.to,
value: execute.value,
data: '0x',
});
}
if ((_a = execute.funds) === null || _a === void 0 ? void 0 : _a.amount) {
const erc20Transfer = (0, viem_1.encodeFunctionData)({
abi: abi_1.ERC20_EVM,
functionName: 'transfer',
args: [execute.to, (_b = execute.funds) === null || _b === void 0 ? void 0 : _b.amount],
});
const token = execute.funds.token;
const pushChainTo = push_chain_1.PushChain.utils.tokens.getPRC20Address(token);
multicallData.push({
to: pushChainTo,
value: BigInt(0),
data: erc20Transfer,
});
}
if (execute.data) {
// *************************
// Check for `execute.to`
// *************************
// For multicall, there is no validation for execute.to. Only if that's a valid EVM address
if (Array.isArray(execute.data)) {
if (!(0, viem_1.isAddress)(execute.to))
throw new Error(`Invalid EVM address at execute.to ${execute.to}`);
}
else {
// We can't execute payload against our UEA.
if (execute.to === ueaAddress)
throw new Error(`You can't execute data on the UEA address`);
}
if (Array.isArray(execute.data)) {
multicallData.push(...execute.data);
}
else {
multicallData.push({
to: execute.to,
value: execute.value ? execute.value : BigInt(0),
data: execute.data,
});
}
}
return multicallData;
}
//# sourceMappingURL=payload-builders.js.map