@vechain/vebetterdao-contracts
Version:
Open-source repository that houses the smart contracts powering the decentralized VeBetterDAO on the VeChain Thor blockchain.
69 lines (68 loc) • 4.13 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.seedNavigators = void 0;
const typechain_types_1 = require("../../typechain-types");
const sdk_core_1 = require("@vechain/sdk-core");
const utils_1 = require("@repo/utils");
const config_1 = require("@repo/config");
const sdk_network_1 = require("@vechain/sdk-network");
const thorClient = sdk_network_1.ThorClient.at((0, config_1.getConfig)().nodeUrl);
const NAV_METADATA_URIS = [
"ipfs://bafkreigvg5ylnewzgknwloglhpaaog5ywq7f7wd6fdo75j3sx5vbh3ngoe",
"ipfs://bafkreihdwdcefgh4dqkjv67uzcmw7ojee6xedzdetojuzjevtenasqhntm",
];
/**
* Seed 2 navigators using accounts[1] and accounts[2].
* Mints B3TR to the admin, creates VOT3 supply, funds navigators, and registers them.
*/
const seedNavigators = async (b3tr, vot3, accounts, config) => {
console.log("================");
console.log("Seeding navigators...");
const admin = accounts[0];
const nav1 = accounts[1];
const nav2 = accounts[2];
const navigatorRegistryAddr = config.navigatorRegistryContractAddress;
if (!navigatorRegistryAddr) {
console.log(" NavigatorRegistry address not found in config, skipping navigator seeding");
return;
}
const b3trAddr = await b3tr.getAddress();
const vot3Addr = await vot3.getAddress();
const navRegAbi = sdk_core_1.ABIContract.ofAbi(typechain_types_1.NavigatorRegistry__factory.abi);
const b3trAbi = sdk_core_1.ABIContract.ofAbi(typechain_types_1.B3TR__factory.abi);
const vot3Abi = sdk_core_1.ABIContract.ofAbi(typechain_types_1.VOT3__factory.abi);
// Read min stake from contract
const minStakeResult = await thorClient.contracts.executeCall(sdk_core_1.Address.of(navigatorRegistryAddr).toString(), navRegAbi.getFunction("getMinStake"), []);
const minStake = BigInt(minStakeResult[0].toString());
const stakeAmount = minStake * 2n; // Stake double the minimum
console.log(` Min stake: ${minStake.toString()}, staking: ${stakeAmount.toString()}`);
// Mint B3TR to admin for distribution + VOT3 supply
const totalNeeded = stakeAmount * 2n + stakeAmount * 4n; // 2 navigators + VOT3 supply buffer
await utils_1.TransactionUtils.sendTx(thorClient, [sdk_core_1.Clause.callFunction(sdk_core_1.Address.of(b3trAddr), b3trAbi.getFunction("mint"), [admin.address.toString(), totalNeeded])], admin.pk);
console.log(` Minted ${totalNeeded.toString()} B3TR to admin`);
// Create VOT3 supply (needed for maxStake check: vot3Supply * maxPercentage / 10000)
const vot3Supply = stakeAmount * 4n;
await utils_1.TransactionUtils.sendTx(thorClient, [sdk_core_1.Clause.callFunction(sdk_core_1.Address.of(b3trAddr), b3trAbi.getFunction("approve"), [vot3Addr, vot3Supply])], admin.pk);
await utils_1.TransactionUtils.sendTx(thorClient, [sdk_core_1.Clause.callFunction(sdk_core_1.Address.of(vot3Addr), vot3Abi.getFunction("convertToVOT3"), [vot3Supply])], admin.pk);
console.log(` Created ${vot3Supply.toString()} VOT3 supply`);
// Register navigators
for (let i = 0; i < 2; i++) {
const nav = i === 0 ? nav1 : nav2;
const uri = NAV_METADATA_URIS[i];
// Transfer B3TR from admin to navigator
await utils_1.TransactionUtils.sendTx(thorClient, [
sdk_core_1.Clause.callFunction(sdk_core_1.Address.of(b3trAddr), b3trAbi.getFunction("transfer"), [
nav.address.toString(),
stakeAmount,
]),
], admin.pk);
// Approve + Register in one multi-clause tx
await utils_1.TransactionUtils.sendTx(thorClient, [
sdk_core_1.Clause.callFunction(sdk_core_1.Address.of(b3trAddr), b3trAbi.getFunction("approve"), [navigatorRegistryAddr, stakeAmount]),
sdk_core_1.Clause.callFunction(sdk_core_1.Address.of(navigatorRegistryAddr), navRegAbi.getFunction("register"), [stakeAmount, uri]),
], nav.pk);
console.log(` Navigator ${i + 1} registered: ${nav.address.toString()} (stake: ${stakeAmount.toString()})`);
}
console.log("Navigator seeding complete!");
};
exports.seedNavigators = seedNavigators;