@heliofi/evm-adapter
Version:
API to interact with Helio Finances program on EVM chains.
32 lines • 1.44 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getPaymentTx = void 0;
const ethers_1 = require("ethers");
const abi_1 = require("./abi");
const constants_1 = require("./constants");
const utils_1 = require("./utils");
const getPaymentTx = async (provider, req, recipientsAndAmounts) => {
const { chainId } = await provider.getNetwork();
// @Todo: After ethers v6, chainId is a bigint, but in our system we use an enum with numbers
const contractAddress = (0, utils_1.getContractAddress)(Number(chainId));
if (!contractAddress) {
throw new Error(`Non existant contract address for chainId ${chainId}`);
}
const contract = new ethers_1.Contract(contractAddress, abi_1.helio.abi, provider);
const BNRecipientsAndAmounts = recipientsAndAmounts.map((r) => ({
recipient: r.recipient,
amount: r.amount,
}));
const overrides = {
value: Number(req.tokenAddress) === 0
? recipientsAndAmounts.reduce((acc, r) => acc + r.amount, 0n)
: 0n,
gasLimit: constants_1.gasLimit,
gasPrice: (await provider.getFeeData()).gasPrice,
};
const unsignedTx = await contract.payment.populateTransaction(req.tokenAddress, BNRecipientsAndAmounts, req.transactonDbId, overrides);
unsignedTx.chainId = chainId;
return unsignedTx;
};
exports.getPaymentTx = getPaymentTx;
//# sourceMappingURL=getPaymentTx.js.map