@lit-protocol/vincent-scaffold-sdk
Version:
Shared build configuration and utilities for Vincent abilities and policies
32 lines (31 loc) • 1.52 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.fundPKPIfNeeded = fundPKPIfNeeded;
const chalk_1 = __importDefault(require("chalk"));
const ethers_1 = require("ethers");
/**
* Fund a PKP if it has zero balance
* @param pkpAddress The PKP's Ethereum address
* @param isNewPKP Whether this is a newly minted PKP
* @param funderWallet The ethers wallet to fund from
* @param provider The ethers provider to check balance
* @param fundAmount Amount to fund (default: 0.01 ETH)
*/
async function fundPKPIfNeeded(pkpAddress, isNewPKP, funderWallet, provider, fundAmount = ethers_1.ethers.utils.parseEther("0.01")) {
console.log(`✅ PKP Address: ${pkpAddress}${isNewPKP ? chalk_1.default.yellow(" (newly minted)") : ""}`);
const balance = await provider.getBalance(pkpAddress);
console.log(" ↳ PKP Balance:", ethers_1.ethers.utils.formatEther(balance.toString()));
// Fund if new PKP with zero balance
if (isNewPKP && balance.eq(ethers_1.ethers.BigNumber.from(0))) {
console.log(chalk_1.default.yellow(" ↳ Funding new PKP..."));
const tx = await funderWallet.sendTransaction({
to: pkpAddress,
value: fundAmount,
});
await tx.wait();
console.log(chalk_1.default.green(` ↳ PKP funded with ${ethers_1.ethers.utils.formatEther(fundAmount)} ETH`));
}
}