import { Connection } from "@solana/web3.js"; import { FormattedGlobalConfig, GlobalConfig, GlobalConfigLayout } from "../layouts/config"; import { getGlobalConfigPda } from "../instructions/pda"; import { fractionToDecimal } from "../layouts/fraction"; export async function fetchGlobalConfig(connection: Connection): Promise { let globalConfig = getGlobalConfigPda(); let globalConfigData = await connection.getAccountInfo(globalConfig); let globalConfigState: GlobalConfig = GlobalConfigLayout.decode(globalConfigData?.data.slice(8) ?? Buffer.alloc(0)); let formatted: FormattedGlobalConfig = { pubkey: globalConfig.toBase58(), admin: globalConfigState.admin.toBase58(), owners: globalConfigState.owners.map(owner => owner.toBase58()), total_number_of_baskets: parseInt(globalConfigState.totalNumberOfBaskets.toString()), allow_interactions: globalConfigState.allowInteractions === 1, allow_creation: globalConfigState.allowCreation === 1, allow_management: globalConfigState.allowManagement === 1, allow_automation: globalConfigState.allowAutomation === 1, allow_deposits: globalConfigState.allowDeposits === 1, allow_withdraws: globalConfigState.allowWithdraws === 1, max_deposit_fee_bps: globalConfigState.maxDepositFeeBps, max_withdraw_fee_bps: globalConfigState.maxWithdrawFeeBps, max_management_fee_bps: globalConfigState.maxManagementFeeBps, max_performance_fee_bps: globalConfigState.maxPerformanceFeeBps, symmetry_fee_collector: globalConfigState.symmetryFeeCollector.toBase58(), symmetry_deposit_fee_bps: globalConfigState.symmetryDepositFeeBps, symmetry_deposit_fee_share_bps: globalConfigState.symmetryDepositFeeShareBps, symmetry_withdraw_fee_bps: globalConfigState.symmetryWithdrawFeeBps, symmetry_withdraw_fee_share_bps: globalConfigState.symmetryWithdrawFeeShareBps, symmetry_management_fee_bps: globalConfigState.symmetryManagementFeeBps, symmetry_management_fee_share_bps: globalConfigState.symmetryManagementFeeShareBps, symmetry_performance_fee_bps: globalConfigState.symmetryPerformanceFeeBps, symmetry_performance_fee_share_bps: globalConfigState.symmetryPerformanceFeeShareBps, symmetry_trade_fee_bps: globalConfigState.symmetryTradeFeeBps, symmetry_limit_order_fee_bps: globalConfigState.symmetryLimitOrderFeeBps, bounty_mint: globalConfigState.bountyMint.toBase58(), min_bounty_for_basket_automation: parseInt(globalConfigState.minBountyForBasketAutomation.toString()), bounty_bond_amount: parseInt(globalConfigState.bountyBondAmount.toString()), bounty_per_task: { min_bounty: parseInt(globalConfigState.bountyPerTask.minBounty.toString()), max_bounty: parseInt(globalConfigState.bountyPerTask.maxBounty.toString()), min_bounty_until: parseInt(globalConfigState.bountyPerTask.minBountyUntil.toString()), max_bounty_after: parseInt(globalConfigState.bountyPerTask.maxBountyAfter.toString()), }, bounty_per_price_update_task_divisor: parseInt(globalConfigState.bountyPerPriceUpdateTaskDivisor.toString()), min_remaining_value: fractionToDecimal(globalConfigState.minRemainingValue).toNumber(), min_mint_ratio: fractionToDecimal(globalConfigState.minMintRatio).toNumber(), apr_bps_per_year: globalConfigState.aprBpsPerYear, rebalance_intent_lifetime: parseInt(globalConfigState.rebalanceIntentLifetime.toString()), rebalance_auction_1_timeframe: parseInt(globalConfigState.rebalanceAuction1Timeframe.toString()), rebalance_auction_2_timeframe: parseInt(globalConfigState.rebalanceAuction2Timeframe.toString()), rebalance_auction_3_timeframe: parseInt(globalConfigState.rebalanceAuction3Timeframe.toString()), price_update_delay_after_creation: parseInt(globalConfigState.priceUpdateDelayAfterCreation.toString()), price_update_lifetime: parseInt(globalConfigState.priceUpdateLifetime.toString()), price_update_reexecution_delay: parseInt(globalConfigState.priceUpdateReexecutionDelay.toString()), }; return { ...globalConfigState, formatted: formatted, }; }