import { SuperPaymasterABI } from './chunk-ZSSNU3UF.js';
import { parseAbi, formatEther } from 'viem';

var STAKING_ABI = parseAbi([
  "function stake(uint256)",
  "function withdraw(uint256)"
]);
var ERC20_ABI = parseAbi([
  "function balanceOf(address) view returns (uint256)",
  "function totalSupply() view returns (uint256)",
  "function approve(address,uint256) returns (bool)",
  "function transfer(address,uint256) returns (bool)"
]);
var FinanceClient = class _FinanceClient {
  publicClient;
  walletClient;
  /**
   * Initialize FinanceClient
   * @param publicClient The public client for queries
   * @param walletClient The wallet client for transactions
   */
  constructor(publicClient, walletClient) {
    this.publicClient = publicClient;
    this.walletClient = walletClient;
  }
  // ========== Existing static methods (preserved for backward compatibility) ==========
  /** @deprecated Use instance methods instead */
  static async depositToPaymaster(wallet, paymaster, amount) {
    return wallet.writeContract({
      address: paymaster,
      abi: SuperPaymasterABI,
      functionName: "deposit",
      args: [amount],
      chain: wallet.chain
    });
  }
  /** @deprecated Use instance methods instead */
  static async depositViaTransferAndCall(wallet, token, paymaster, amount) {
    const ERC1363_ABI = [{
      name: "transferAndCall",
      type: "function",
      stateMutability: "nonpayable",
      inputs: [{ type: "address", name: "to" }, { type: "uint256", name: "value" }],
      outputs: [{ type: "bool" }]
    }];
    return wallet.writeContract({
      address: token,
      abi: ERC1363_ABI,
      functionName: "transferAndCall",
      args: [paymaster, amount],
      chain: wallet.chain
    });
  }
  /** @deprecated Use instance methods instead */
  static async stakeGToken(wallet, stakingAddr, amount) {
    return wallet.writeContract({
      address: stakingAddr,
      abi: STAKING_ABI,
      functionName: "stake",
      args: [amount],
      chain: wallet.chain
    });
  }
  /** @deprecated Use instance methods instead */
  static async withdrawProtocolRevenue(wallet, paymaster, to, amount) {
    return wallet.writeContract({
      address: paymaster,
      abi: SuperPaymasterABI,
      functionName: "withdrawProtocolRevenue",
      args: [to, amount],
      chain: wallet.chain
    });
  }
  /** @deprecated Use instance methods instead */
  static async depositToEntryPoint(wallet, entryPoint, paymaster, amount) {
    return wallet.writeContract({
      address: entryPoint,
      abi: parseAbi(["function depositTo(address) payable"]),
      functionName: "depositTo",
      args: [paymaster],
      value: amount,
      chain: wallet.chain
    });
  }
  /** @deprecated Use instance methods instead */
  static async getEntryPointBalance(client, entryPoint, account) {
    return client.readContract({
      address: entryPoint,
      abi: parseAbi(["function balanceOf(address) view returns (uint256)"]),
      functionName: "balanceOf",
      args: [account]
    });
  }
  /** @deprecated Use instance methods instead */
  static async operatorDeposit(wallet, paymaster, amount) {
    return wallet.writeContract({
      address: paymaster,
      abi: SuperPaymasterABI,
      functionName: "deposit",
      args: [amount],
      chain: wallet.chain
    });
  }
  /** @deprecated Use instance methods instead */
  static async operatorNotifyDeposit(wallet, paymaster, amount) {
    return wallet.writeContract({
      address: paymaster,
      abi: SuperPaymasterABI,
      functionName: "notifyDeposit",
      args: [amount],
      chain: wallet.chain
    });
  }
  // ========== New instance methods (business primitives) ==========
  /**
   * Get GToken balance
   */
  async getGTokenBalance(address) {
    const { CORE_ADDRESSES } = await import('./index.node-55LOPHNQ.js');
    return this.publicClient.readContract({
      address: CORE_ADDRESSES.gToken,
      abi: ERC20_ABI,
      functionName: "balanceOf",
      args: [address]
    });
  }
  /**
   * Get aPNTs balance
   */
  async getAPNTsBalance(address) {
    const { CORE_ADDRESSES } = await import('./index.node-55LOPHNQ.js');
    return this.publicClient.readContract({
      address: CORE_ADDRESSES.aPNTs,
      abi: ERC20_ABI,
      functionName: "balanceOf",
      args: [address]
    });
  }
  /**
   * One-step stake: Approve (if needed) + Stake
   *
   * @param amount Amount of GToken to stake
   * @returns Transaction hash of the stake action
   */
  async approveAndStake(amount) {
    const account = this.walletClient.account;
    if (!account)
      throw new Error("Account required");
    const { CORE_ADDRESSES } = await import('./index.node-55LOPHNQ.js');
    const gTokenAddress = CORE_ADDRESSES.gToken;
    const stakingAddress = CORE_ADDRESSES.gTokenStaking;
    const allowance = await this.publicClient.readContract({
      address: gTokenAddress,
      abi: parseAbi(["function allowance(address owner, address spender) view returns (uint256)"]),
      functionName: "allowance",
      args: [account.address, stakingAddress]
    });
    if (allowance < amount) {
      console.log(`[FinanceClient] Approving ${formatEther(amount)} GToken...`);
      const approveTx = await this.walletClient.writeContract({
        address: gTokenAddress,
        abi: parseAbi(["function approve(address spender, uint256 amount) returns (bool)"]),
        functionName: "approve",
        args: [stakingAddress, amount],
        chain: this.walletClient.chain,
        account
      });
      await this.publicClient.waitForTransactionReceipt({ hash: approveTx });
      console.log(`[FinanceClient] Approved.`);
    }
    console.log(`[FinanceClient] Staking...`);
    return _FinanceClient.stakeGToken(this.walletClient, stakingAddress, amount);
  }
  /**
   * Get circulating supply (total - locked)
   */
  async getCirculatingSupply() {
    const { CORE_ADDRESSES } = await import('./index.node-55LOPHNQ.js');
    const gTokenAddress = CORE_ADDRESSES.gToken;
    const total = await this.publicClient.readContract({
      address: gTokenAddress,
      abi: ERC20_ABI,
      functionName: "totalSupply"
    });
    const locked = 0n;
    return {
      total,
      locked,
      circulating: total - locked
    };
  }
  /**
   * Get comprehensive tokenomics data
   */
  async getTokenomicsOverview() {
    const { CORE_ADDRESSES } = await import('./index.node-55LOPHNQ.js');
    const [totalSupply, totalStaked, blackholeBalance] = await Promise.all([
      this.publicClient.readContract({
        address: CORE_ADDRESSES.gToken,
        abi: parseAbi(["function totalSupply() view returns (uint256)"]),
        functionName: "totalSupply"
      }),
      this.publicClient.readContract({
        address: CORE_ADDRESSES.gTokenStaking,
        abi: parseAbi(["function totalStaked() view returns (uint256)"]),
        functionName: "totalStaked"
      }),
      this.publicClient.readContract({
        address: CORE_ADDRESSES.gToken,
        abi: parseAbi(["function balanceOf(address) view returns (uint256)"]),
        functionName: "balanceOf",
        args: ["0x000000000000000000000000000000000000dEaD"]
      })
    ]);
    const circulating = totalSupply - totalStaked - blackholeBalance;
    const ratio = Number(formatEther(totalStaked)) / Number(formatEther(totalSupply)) * 100;
    return {
      totalSupply,
      totalStaked,
      totalBurned: blackholeBalance,
      circulatingSupply: circulating,
      stakingRatio: ratio
    };
  }
};

export { FinanceClient };
//# sourceMappingURL=chunk-PCLPYRTX.js.map
//# sourceMappingURL=chunk-PCLPYRTX.js.map