UNPKG

@coinbase/agentkit

Version:

Coinbase AgentKit core primitives

63 lines (62 loc) 2.34 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getMemecoinAddressFromReceipt = getMemecoinAddressFromReceipt; exports.ethRequiredToFlaunch = ethRequiredToFlaunch; const viem_1 = require("viem"); const constants_1 = require("./constants"); /** * Gets the memecoin address from the transaction receipt * * @param receipt - The transaction receipt * @param chainId - The chain id * @returns The memecoin address */ function getMemecoinAddressFromReceipt(receipt, chainId) { const filteredPoolCreatedEvent = receipt.logs .map(log => { try { if (log.address.toLowerCase() !== constants_1.FlaunchPositionManagerV1_1Address[chainId].toLowerCase()) { return null; } const event = (0, viem_1.decodeEventLog)({ abi: constants_1.POSITION_MANAGERV1_1_ABI, data: log.data, topics: log.topics, }); return event.eventName === "PoolCreated" ? event.args : null; } catch { return null; } }) .filter((event) => event !== null)[0]; if (!filteredPoolCreatedEvent) { throw new Error("Could not find PoolCreated event in transaction receipt"); } return filteredPoolCreatedEvent._memecoin; } /** * Calculates the ETH required to flaunch a token, takes into account the ETH for premine and the flaunching fee * * @param walletProvider - The EVM wallet provider * @param params - The flaunch parameters * @param params.premineAmount - The amount to premine * @param params.initialPriceParams - The initial price parameters * @param params.slippagePercent - The slippage percentage (optional, defaults to 5%) * @returns Promise that resolves to the ETH amount required */ function ethRequiredToFlaunch(walletProvider, params) { const chainId = walletProvider.getNetwork().chainId; if (!chainId) throw new Error("Chain ID is not set."); return walletProvider.readContract({ address: constants_1.FlaunchZapAddress[chainId], abi: constants_1.FLAUNCH_ZAP_ABI, functionName: "calculateFee", args: [ params.premineAmount ?? 0n, BigInt(params.slippagePercent ?? 5 * 100), params.initialPriceParams, ], }); }