{"constructor_args":null,"is_partially_verified":true,"is_changed_bytecode":false,"abi":[{"inputs":[{"internalType":"contract IAddressesRegistry","name":"_addressesRegistry","type":"address"},{"internalType":"contract ISystemParams","name":"_systemParams","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"BatchSharesRatioTooHigh","type":"error"},{"inputs":[],"name":"CallerNotBorrowerOperations","type":"error"},{"inputs":[],"name":"CallerNotCollateralRegistry","type":"error"},{"inputs":[],"name":"EmptyData","type":"error"},{"inputs":[],"name":"L2SequencerDown","type":"error"},{"inputs":[{"internalType":"uint256","name":"_coll","type":"uint256"}],"name":"MinCollNotReached","type":"error"},{"inputs":[],"name":"NotEnoughBoldBalance","type":"error"},{"inputs":[],"name":"NotShutDown","type":"error"},{"inputs":[],"name":"NothingToLiquidate","type":"error"},{"inputs":[],"name":"OnlyOneTroveLeft","type":"error"},{"inputs":[],"name":"ZeroAmount","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_newActivePoolAddress","type":"address"}],"name":"ActivePoolAddressChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_interestBatchManager","type":"address"},{"indexed":false,"internalType":"enum ITroveEvents.BatchOperation","name":"_operation","type":"uint8"},{"indexed":false,"internalType":"uint256","name":"_debt","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_coll","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_annualInterestRate","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_annualManagementFee","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_totalDebtShares","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_debtIncreaseFromUpfrontFee","type":"uint256"}],"name":"BatchUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"_troveId","type":"uint256"},{"indexed":false,"internalType":"address","name":"_interestBatchManager","type":"address"},{"indexed":false,"internalType":"uint256","name":"_batchDebtShares","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_coll","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_stake","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_snapshotOfTotalCollRedist","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_snapshotOfTotalDebtRedist","type":"uint256"}],"name":"BatchedTroveUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_newBoldTokenAddress","type":"address"}],"name":"BoldTokenAddressChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_newBorrowerOperationsAddress","type":"address"}],"name":"BorrowerOperationsAddressChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_collSurplusPoolAddress","type":"address"}],"name":"CollSurplusPoolAddressChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_collateralRegistryAddress","type":"address"}],"name":"CollateralRegistryAddressChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_newDefaultPoolAddress","type":"address"}],"name":"DefaultPoolAddressChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_gasPoolAddress","type":"address"}],"name":"GasPoolAddressChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"_debtOffsetBySP","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_debtRedistributed","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_boldGasCompensation","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_collGasCompensation","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_collSentToSP","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_collRedistributed","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_collSurplus","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_L_ETH","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_L_boldDebt","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_price","type":"uint256"}],"name":"Liquidation","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_newPriceFeedAddress","type":"address"}],"name":"PriceFeedAddressChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"_attemptedBoldAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_actualBoldAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_ETHSent","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_ETHFee","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_price","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_redemptionPrice","type":"uint256"}],"name":"Redemption","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"_troveId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_ETHFee","type":"uint256"}],"name":"RedemptionFeePaidToTrove","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_sortedTrovesAddress","type":"address"}],"name":"SortedTrovesAddressChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_stabilityPoolAddress","type":"address"}],"name":"StabilityPoolAddressChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_newTroveNFTAddress","type":"address"}],"name":"TroveNFTAddressChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"_troveId","type":"uint256"},{"indexed":false,"internalType":"enum ITroveEvents.Operation","name":"_operation","type":"uint8"},{"indexed":false,"internalType":"uint256","name":"_annualInterestRate","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_debtIncreaseFromRedist","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_debtIncreaseFromUpfrontFee","type":"uint256"},{"indexed":false,"internalType":"int256","name":"_debtChangeFromOperation","type":"int256"},{"indexed":false,"internalType":"uint256","name":"_collIncreaseFromRedist","type":"uint256"},{"indexed":false,"internalType":"int256","name":"_collChangeFromOperation","type":"int256"}],"name":"TroveOperation","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"_troveId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_debt","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_coll","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_stake","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_annualInterestRate","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_snapshotOfTotalCollRedist","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_snapshotOfTotalDebtRedist","type":"uint256"}],"name":"TroveUpdated","type":"event"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"Troves","outputs":[{"internalType":"uint256","name":"debt","type":"uint256"},{"internalType":"uint256","name":"coll","type":"uint256"},{"internalType":"uint256","name":"stake","type":"uint256"},{"internalType":"enum ITroveManager.Status","name":"status","type":"uint8"},{"internalType":"uint64","name":"arrayIndex","type":"uint64"},{"internalType":"uint64","name":"lastDebtUpdateTime","type":"uint64"},{"internalType":"uint64","name":"lastInterestRateAdjTime","type":"uint64"},{"internalType":"uint256","name":"annualInterestRate","type":"uint256"},{"internalType":"address","name":"interestBatchManager","type":"address"},{"internalType":"uint256","name":"batchDebtShares","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"activePool","outputs":[{"internalType":"contract IActivePool","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"batchIds","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"_troveArray","type":"uint256[]"}],"name":"batchLiquidateTroves","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"borrowerOperations","outputs":[{"internalType":"contract IBorrowerOperations","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_troveId","type":"uint256"},{"internalType":"uint256","name":"_price","type":"uint256"}],"name":"getCurrentICR","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getEntireBranchColl","outputs":[{"internalType":"uint256","name":"entireSystemColl","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getEntireBranchDebt","outputs":[{"internalType":"uint256","name":"entireSystemDebt","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_batchAddress","type":"address"}],"name":"getLatestBatchData","outputs":[{"components":[{"internalType":"uint256","name":"totalDebtShares","type":"uint256"},{"internalType":"uint256","name":"entireDebtWithoutRedistribution","type":"uint256"},{"internalType":"uint256","name":"entireCollWithoutRedistribution","type":"uint256"},{"internalType":"uint256","name":"accruedInterest","type":"uint256"},{"internalType":"uint256","name":"recordedDebt","type":"uint256"},{"internalType":"uint256","name":"annualInterestRate","type":"uint256"},{"internalType":"uint256","name":"weightedRecordedDebt","type":"uint256"},{"internalType":"uint256","name":"annualManagementFee","type":"uint256"},{"internalType":"uint256","name":"accruedManagementFee","type":"uint256"},{"internalType":"uint256","name":"weightedRecordedBatchManagementFee","type":"uint256"},{"internalType":"uint256","name":"lastDebtUpdateTime","type":"uint256"},{"internalType":"uint256","name":"lastInterestRateAdjTime","type":"uint256"}],"internalType":"struct LatestBatchData","name":"batch","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_troveId","type":"uint256"}],"name":"getLatestTroveData","outputs":[{"components":[{"internalType":"uint256","name":"entireDebt","type":"uint256"},{"internalType":"uint256","name":"entireColl","type":"uint256"},{"internalType":"uint256","name":"redistBoldDebtGain","type":"uint256"},{"internalType":"uint256","name":"redistCollGain","type":"uint256"},{"internalType":"uint256","name":"accruedInterest","type":"uint256"},{"internalType":"uint256","name":"recordedDebt","type":"uint256"},{"internalType":"uint256","name":"annualInterestRate","type":"uint256"},{"internalType":"uint256","name":"weightedRecordedDebt","type":"uint256"},{"internalType":"uint256","name":"accruedBatchManagementFee","type":"uint256"},{"internalType":"uint256","name":"lastInterestRateAdjTime","type":"uint256"}],"internalType":"struct LatestTroveData","name":"trove","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_troveId","type":"uint256"}],"name":"getTroveAnnualInterestRate","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_index","type":"uint256"}],"name":"getTroveFromTroveIdsArray","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getTroveIdsCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_troveId","type":"uint256"}],"name":"getTroveStatus","outputs":[{"internalType":"enum ITroveManager.Status","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getUnbackedPortionPriceAndRedeemability","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"lastZombieTroveId","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_troveId","type":"uint256"},{"internalType":"uint256","name":"_newColl","type":"uint256"},{"internalType":"uint256","name":"_newDebt","type":"uint256"},{"components":[{"internalType":"uint256","name":"appliedRedistBoldDebtGain","type":"uint256"},{"internalType":"uint256","name":"appliedRedistCollGain","type":"uint256"},{"internalType":"uint256","name":"collIncrease","type":"uint256"},{"internalType":"uint256","name":"collDecrease","type":"uint256"},{"internalType":"uint256","name":"debtIncrease","type":"uint256"},{"internalType":"uint256","name":"debtDecrease","type":"uint256"},{"internalType":"uint256","name":"newWeightedRecordedDebt","type":"uint256"},{"internalType":"uint256","name":"oldWeightedRecordedDebt","type":"uint256"},{"internalType":"uint256","name":"upfrontFee","type":"uint256"},{"internalType":"uint256","name":"batchAccruedManagementFee","type":"uint256"},{"internalType":"uint256","name":"newWeightedRecordedBatchManagementFee","type":"uint256"},{"internalType":"uint256","name":"oldWeightedRecordedBatchManagementFee","type":"uint256"}],"internalType":"struct TroveChange","name":"_troveChange","type":"tuple"}],"name":"onAdjustTrove","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_troveId","type":"uint256"},{"internalType":"uint256","name":"_newTroveColl","type":"uint256"},{"internalType":"uint256","name":"_newTroveDebt","type":"uint256"},{"components":[{"internalType":"uint256","name":"appliedRedistBoldDebtGain","type":"uint256"},{"internalType":"uint256","name":"appliedRedistCollGain","type":"uint256"},{"internalType":"uint256","name":"collIncrease","type":"uint256"},{"internalType":"uint256","name":"collDecrease","type":"uint256"},{"internalType":"uint256","name":"debtIncrease","type":"uint256"},{"internalType":"uint256","name":"debtDecrease","type":"uint256"},{"internalType":"uint256","name":"newWeightedRecordedDebt","type":"uint256"},{"internalType":"uint256","name":"oldWeightedRecordedDebt","type":"uint256"},{"internalType":"uint256","name":"upfrontFee","type":"uint256"},{"internalType":"uint256","name":"batchAccruedManagementFee","type":"uint256"},{"internalType":"uint256","name":"newWeightedRecordedBatchManagementFee","type":"uint256"},{"internalType":"uint256","name":"oldWeightedRecordedBatchManagementFee","type":"uint256"}],"internalType":"struct TroveChange","name":"_troveChange","type":"tuple"},{"internalType":"address","name":"_batchAddress","type":"address"},{"internalType":"uint256","name":"_newBatchColl","type":"uint256"},{"internalType":"uint256","name":"_newBatchDebt","type":"uint256"}],"name":"onAdjustTroveInsideBatch","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_troveId","type":"uint256"},{"internalType":"uint256","name":"_newColl","type":"uint256"},{"internalType":"uint256","name":"_newDebt","type":"uint256"},{"internalType":"uint256","name":"_newAnnualInterestRate","type":"uint256"},{"components":[{"internalType":"uint256","name":"appliedRedistBoldDebtGain","type":"uint256"},{"internalType":"uint256","name":"appliedRedistCollGain","type":"uint256"},{"internalType":"uint256","name":"collIncrease","type":"uint256"},{"internalType":"uint256","name":"collDecrease","type":"uint256"},{"internalType":"uint256","name":"debtIncrease","type":"uint256"},{"internalType":"uint256","name":"debtDecrease","type":"uint256"},{"internalType":"uint256","name":"newWeightedRecordedDebt","type":"uint256"},{"internalType":"uint256","name":"oldWeightedRecordedDebt","type":"uint256"},{"internalType":"uint256","name":"upfrontFee","type":"uint256"},{"internalType":"uint256","name":"batchAccruedManagementFee","type":"uint256"},{"internalType":"uint256","name":"newWeightedRecordedBatchManagementFee","type":"uint256"},{"internalType":"uint256","name":"oldWeightedRecordedBatchManagementFee","type":"uint256"}],"internalType":"struct TroveChange","name":"_troveChange","type":"tuple"}],"name":"onAdjustTroveInterestRate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_troveId","type":"uint256"},{"internalType":"uint256","name":"_newTroveColl","type":"uint256"},{"internalType":"uint256","name":"_newTroveDebt","type":"uint256"},{"internalType":"address","name":"_batchAddress","type":"address"},{"internalType":"uint256","name":"_newBatchColl","type":"uint256"},{"internalType":"uint256","name":"_newBatchDebt","type":"uint256"},{"components":[{"internalType":"uint256","name":"appliedRedistBoldDebtGain","type":"uint256"},{"internalType":"uint256","name":"appliedRedistCollGain","type":"uint256"},{"internalType":"uint256","name":"collIncrease","type":"uint256"},{"internalType":"uint256","name":"collDecrease","type":"uint256"},{"internalType":"uint256","name":"debtIncrease","type":"uint256"},{"internalType":"uint256","name":"debtDecrease","type":"uint256"},{"internalType":"uint256","name":"newWeightedRecordedDebt","type":"uint256"},{"internalType":"uint256","name":"oldWeightedRecordedDebt","type":"uint256"},{"internalType":"uint256","name":"upfrontFee","type":"uint256"},{"internalType":"uint256","name":"batchAccruedManagementFee","type":"uint256"},{"internalType":"uint256","name":"newWeightedRecordedBatchManagementFee","type":"uint256"},{"internalType":"uint256","name":"oldWeightedRecordedBatchManagementFee","type":"uint256"}],"internalType":"struct TroveChange","name":"_troveChange","type":"tuple"}],"name":"onApplyTroveInterest","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_troveId","type":"uint256"},{"components":[{"internalType":"uint256","name":"appliedRedistBoldDebtGain","type":"uint256"},{"internalType":"uint256","name":"appliedRedistCollGain","type":"uint256"},{"internalType":"uint256","name":"collIncrease","type":"uint256"},{"internalType":"uint256","name":"collDecrease","type":"uint256"},{"internalType":"uint256","name":"debtIncrease","type":"uint256"},{"internalType":"uint256","name":"debtDecrease","type":"uint256"},{"internalType":"uint256","name":"newWeightedRecordedDebt","type":"uint256"},{"internalType":"uint256","name":"oldWeightedRecordedDebt","type":"uint256"},{"internalType":"uint256","name":"upfrontFee","type":"uint256"},{"internalType":"uint256","name":"batchAccruedManagementFee","type":"uint256"},{"internalType":"uint256","name":"newWeightedRecordedBatchManagementFee","type":"uint256"},{"internalType":"uint256","name":"oldWeightedRecordedBatchManagementFee","type":"uint256"}],"internalType":"struct TroveChange","name":"_troveChange","type":"tuple"},{"internalType":"address","name":"_batchAddress","type":"address"},{"internalType":"uint256","name":"_newBatchColl","type":"uint256"},{"internalType":"uint256","name":"_newBatchDebt","type":"uint256"}],"name":"onCloseTrove","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_batchAddress","type":"address"},{"internalType":"uint256","name":"_newColl","type":"uint256"},{"internalType":"uint256","name":"_newDebt","type":"uint256"},{"internalType":"uint256","name":"_newAnnualManagementFee","type":"uint256"}],"name":"onLowerBatchManagerAnnualFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_owner","type":"address"},{"internalType":"uint256","name":"_troveId","type":"uint256"},{"components":[{"internalType":"uint256","name":"appliedRedistBoldDebtGain","type":"uint256"},{"internalType":"uint256","name":"appliedRedistCollGain","type":"uint256"},{"internalType":"uint256","name":"collIncrease","type":"uint256"},{"internalType":"uint256","name":"collDecrease","type":"uint256"},{"internalType":"uint256","name":"debtIncrease","type":"uint256"},{"internalType":"uint256","name":"debtDecrease","type":"uint256"},{"internalType":"uint256","name":"newWeightedRecordedDebt","type":"uint256"},{"internalType":"uint256","name":"oldWeightedRecordedDebt","type":"uint256"},{"internalType":"uint256","name":"upfrontFee","type":"uint256"},{"internalType":"uint256","name":"batchAccruedManagementFee","type":"uint256"},{"internalType":"uint256","name":"newWeightedRecordedBatchManagementFee","type":"uint256"},{"internalType":"uint256","name":"oldWeightedRecordedBatchManagementFee","type":"uint256"}],"internalType":"struct TroveChange","name":"_troveChange","type":"tuple"},{"internalType":"uint256","name":"_annualInterestRate","type":"uint256"}],"name":"onOpenTrove","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_owner","type":"address"},{"internalType":"uint256","name":"_troveId","type":"uint256"},{"components":[{"internalType":"uint256","name":"appliedRedistBoldDebtGain","type":"uint256"},{"internalType":"uint256","name":"appliedRedistCollGain","type":"uint256"},{"internalType":"uint256","name":"collIncrease","type":"uint256"},{"internalType":"uint256","name":"collDecrease","type":"uint256"},{"internalType":"uint256","name":"debtIncrease","type":"uint256"},{"internalType":"uint256","name":"debtDecrease","type":"uint256"},{"internalType":"uint256","name":"newWeightedRecordedDebt","type":"uint256"},{"internalType":"uint256","name":"oldWeightedRecordedDebt","type":"uint256"},{"internalType":"uint256","name":"upfrontFee","type":"uint256"},{"internalType":"uint256","name":"batchAccruedManagementFee","type":"uint256"},{"internalType":"uint256","name":"newWeightedRecordedBatchManagementFee","type":"uint256"},{"internalType":"uint256","name":"oldWeightedRecordedBatchManagementFee","type":"uint256"}],"internalType":"struct TroveChange","name":"_troveChange","type":"tuple"},{"internalType":"address","name":"_batchAddress","type":"address"},{"internalType":"uint256","name":"_batchColl","type":"uint256"},{"internalType":"uint256","name":"_batchDebt","type":"uint256"}],"name":"onOpenTroveAndJoinBatch","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_account","type":"address"},{"internalType":"uint256","name":"_annualInterestRate","type":"uint256"},{"internalType":"uint256","name":"_annualManagementFee","type":"uint256"}],"name":"onRegisterBatchManager","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_troveId","type":"uint256"},{"internalType":"uint256","name":"_newTroveColl","type":"uint256"},{"internalType":"uint256","name":"_newTroveDebt","type":"uint256"},{"components":[{"internalType":"uint256","name":"appliedRedistBoldDebtGain","type":"uint256"},{"internalType":"uint256","name":"appliedRedistCollGain","type":"uint256"},{"internalType":"uint256","name":"collIncrease","type":"uint256"},{"internalType":"uint256","name":"collDecrease","type":"uint256"},{"internalType":"uint256","name":"debtIncrease","type":"uint256"},{"internalType":"uint256","name":"debtDecrease","type":"uint256"},{"internalType":"uint256","name":"newWeightedRecordedDebt","type":"uint256"},{"internalType":"uint256","name":"oldWeightedRecordedDebt","type":"uint256"},{"internalType":"uint256","name":"upfrontFee","type":"uint256"},{"internalType":"uint256","name":"batchAccruedManagementFee","type":"uint256"},{"internalType":"uint256","name":"newWeightedRecordedBatchManagementFee","type":"uint256"},{"internalType":"uint256","name":"oldWeightedRecordedBatchManagementFee","type":"uint256"}],"internalType":"struct TroveChange","name":"_troveChange","type":"tuple"},{"internalType":"address","name":"_batchAddress","type":"address"},{"internalType":"uint256","name":"_newBatchColl","type":"uint256"},{"internalType":"uint256","name":"_newBatchDebt","type":"uint256"},{"internalType":"uint256","name":"_newAnnualInterestRate","type":"uint256"}],"name":"onRemoveFromBatch","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_batchAddress","type":"address"},{"internalType":"uint256","name":"_newColl","type":"uint256"},{"internalType":"uint256","name":"_newDebt","type":"uint256"},{"internalType":"uint256","name":"_newAnnualInterestRate","type":"uint256"},{"internalType":"uint256","name":"_upfrontFee","type":"uint256"}],"name":"onSetBatchManagerAnnualInterestRate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"troveId","type":"uint256"},{"internalType":"uint256","name":"troveColl","type":"uint256"},{"internalType":"uint256","name":"troveDebt","type":"uint256"},{"components":[{"internalType":"uint256","name":"appliedRedistBoldDebtGain","type":"uint256"},{"internalType":"uint256","name":"appliedRedistCollGain","type":"uint256"},{"internalType":"uint256","name":"collIncrease","type":"uint256"},{"internalType":"uint256","name":"collDecrease","type":"uint256"},{"internalType":"uint256","name":"debtIncrease","type":"uint256"},{"internalType":"uint256","name":"debtDecrease","type":"uint256"},{"internalType":"uint256","name":"newWeightedRecordedDebt","type":"uint256"},{"internalType":"uint256","name":"oldWeightedRecordedDebt","type":"uint256"},{"internalType":"uint256","name":"upfrontFee","type":"uint256"},{"internalType":"uint256","name":"batchAccruedManagementFee","type":"uint256"},{"internalType":"uint256","name":"newWeightedRecordedBatchManagementFee","type":"uint256"},{"internalType":"uint256","name":"oldWeightedRecordedBatchManagementFee","type":"uint256"}],"internalType":"struct TroveChange","name":"troveChange","type":"tuple"},{"internalType":"address","name":"newBatchAddress","type":"address"},{"internalType":"uint256","name":"newBatchColl","type":"uint256"},{"internalType":"uint256","name":"newBatchDebt","type":"uint256"}],"internalType":"struct ITroveManager.OnSetInterestBatchManagerParams","name":"_params","type":"tuple"}],"name":"onSetInterestBatchManager","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_redeemer","type":"address"},{"internalType":"uint256","name":"_boldamount","type":"uint256"},{"internalType":"uint256","name":"_price","type":"uint256"},{"internalType":"uint256","name":"_redemptionRate","type":"uint256"},{"internalType":"uint256","name":"_maxIterations","type":"uint256"}],"name":"redeemCollateral","outputs":[{"internalType":"uint256","name":"_redeemedAmount","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"rewardSnapshots","outputs":[{"internalType":"uint256","name":"coll","type":"uint256"},{"internalType":"uint256","name":"boldDebt","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_troveId","type":"uint256"}],"name":"setTroveStatusToActive","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"shutdown","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"shutdownTime","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"sortedTroves","outputs":[{"internalType":"contract ISortedTroves","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"stabilityPool","outputs":[{"internalType":"contract IStabilityPool","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"troveNFT","outputs":[{"internalType":"contract ITroveNFT","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_boldAmount","type":"uint256"},{"internalType":"uint256[]","name":"_troveIds","type":"uint256[]"},{"internalType":"uint256","name":"_minCollateral","type":"uint256"}],"name":"urgentRedemption","outputs":[],"stateMutability":"nonpayable","type":"function"}],"conflicting_implementations":null,"certified":false,"additional_sources":[{"file_path":"lib/bold/contracts/src/Types/LatestTroveData.sol","source_code":"// SPDX-License-Identifier: MIT\n\npragma solidity 0.8.24;\n\nstruct LatestTroveData {\n    uint256 entireDebt;\n    uint256 entireColl;\n    uint256 redistBoldDebtGain;\n    uint256 redistCollGain;\n    uint256 accruedInterest;\n    uint256 recordedDebt;\n    uint256 annualInterestRate;\n    uint256 weightedRecordedDebt;\n    uint256 accruedBatchManagementFee;\n    uint256 lastInterestRateAdjTime;\n}\n"},{"file_path":"lib/bold/contracts/lib/openzeppelin-contracts/contracts/token/ERC721/extensions/IERC721Metadata.sol","source_code":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (token/ERC721/extensions/IERC721Metadata.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../IERC721.sol\";\n\n/**\n * @title ERC-721 Non-Fungible Token Standard, optional metadata extension\n * @dev See https://eips.ethereum.org/EIPS/eip-721\n */\ninterface IERC721Metadata is IERC721 {\n    /**\n     * @dev Returns the token collection name.\n     */\n    function name() external view returns (string memory);\n\n    /**\n     * @dev Returns the token collection symbol.\n     */\n    function symbol() external view returns (string memory);\n\n    /**\n     * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.\n     */\n    function tokenURI(uint256 tokenId) external view returns (string memory);\n}\n"},{"file_path":"lib/bold/contracts/lib/openzeppelin-contracts/contracts/token/ERC721/IERC721.sol","source_code":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC721/IERC721.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../../utils/introspection/IERC165.sol\";\n\n/**\n * @dev Required interface of an ERC721 compliant contract.\n */\ninterface IERC721 is IERC165 {\n    /**\n     * @dev Emitted when `tokenId` token is transferred from `from` to `to`.\n     */\n    event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);\n\n    /**\n     * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.\n     */\n    event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);\n\n    /**\n     * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.\n     */\n    event ApprovalForAll(address indexed owner, address indexed operator, bool approved);\n\n    /**\n     * @dev Returns the number of tokens in ``owner``'s account.\n     */\n    function balanceOf(address owner) external view returns (uint256 balance);\n\n    /**\n     * @dev Returns the owner of the `tokenId` token.\n     *\n     * Requirements:\n     *\n     * - `tokenId` must exist.\n     */\n    function ownerOf(uint256 tokenId) external view returns (address owner);\n\n    /**\n     * @dev Safely transfers `tokenId` token from `from` to `to`.\n     *\n     * Requirements:\n     *\n     * - `from` cannot be the zero address.\n     * - `to` cannot be the zero address.\n     * - `tokenId` token must exist and be owned by `from`.\n     * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.\n     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.\n     *\n     * Emits a {Transfer} event.\n     */\n    function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external;\n\n    /**\n     * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients\n     * are aware of the ERC721 protocol to prevent tokens from being forever locked.\n     *\n     * Requirements:\n     *\n     * - `from` cannot be the zero address.\n     * - `to` cannot be the zero address.\n     * - `tokenId` token must exist and be owned by `from`.\n     * - If the caller is not `from`, it must have been allowed to move this token by either {approve} or {setApprovalForAll}.\n     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.\n     *\n     * Emits a {Transfer} event.\n     */\n    function safeTransferFrom(address from, address to, uint256 tokenId) external;\n\n    /**\n     * @dev Transfers `tokenId` token from `from` to `to`.\n     *\n     * WARNING: Note that the caller is responsible to confirm that the recipient is capable of receiving ERC721\n     * or else they may be permanently lost. Usage of {safeTransferFrom} prevents loss, though the caller must\n     * understand this adds an external call which potentially creates a reentrancy vulnerability.\n     *\n     * Requirements:\n     *\n     * - `from` cannot be the zero address.\n     * - `to` cannot be the zero address.\n     * - `tokenId` token must be owned by `from`.\n     * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.\n     *\n     * Emits a {Transfer} event.\n     */\n    function transferFrom(address from, address to, uint256 tokenId) external;\n\n    /**\n     * @dev Gives permission to `to` to transfer `tokenId` token to another account.\n     * The approval is cleared when the token is transferred.\n     *\n     * Only a single account can be approved at a time, so approving the zero address clears previous approvals.\n     *\n     * Requirements:\n     *\n     * - The caller must own the token or be an approved operator.\n     * - `tokenId` must exist.\n     *\n     * Emits an {Approval} event.\n     */\n    function approve(address to, uint256 tokenId) external;\n\n    /**\n     * @dev Approve or remove `operator` as an operator for the caller.\n     * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.\n     *\n     * Requirements:\n     *\n     * - The `operator` cannot be the caller.\n     *\n     * Emits an {ApprovalForAll} event.\n     */\n    function setApprovalForAll(address operator, bool approved) external;\n\n    /**\n     * @dev Returns the account approved for `tokenId` token.\n     *\n     * Requirements:\n     *\n     * - `tokenId` must exist.\n     */\n    function getApproved(uint256 tokenId) external view returns (address operator);\n\n    /**\n     * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.\n     *\n     * See {setApprovalForAll}\n     */\n    function isApprovedForAll(address owner, address operator) external view returns (bool);\n}\n"},{"file_path":"lib/bold/contracts/src/Interfaces/IBorrowerOperations.sol","source_code":"// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.0;\n\nimport \"./ILiquityBase.sol\";\nimport \"./IAddRemoveManagers.sol\";\nimport \"./IBoldToken.sol\";\nimport \"./IPriceFeed.sol\";\nimport \"./ISortedTroves.sol\";\nimport \"./ITroveManager.sol\";\nimport \"./IWETH.sol\";\n\n// Common interface for the Borrower Operations.\ninterface IBorrowerOperations is ILiquityBase, IAddRemoveManagers {\n    function CCR() external view returns (uint256);\n    function MCR() external view returns (uint256);\n\n    function openTrove(\n        address _owner,\n        uint256 _ownerIndex,\n        uint256 _ETHAmount,\n        uint256 _boldAmount,\n        uint256 _upperHint,\n        uint256 _lowerHint,\n        uint256 _annualInterestRate,\n        uint256 _maxUpfrontFee,\n        address _addManager,\n        address _removeManager,\n        address _receiver\n    ) external returns (uint256);\n\n    struct OpenTroveAndJoinInterestBatchManagerParams {\n        address owner;\n        uint256 ownerIndex;\n        uint256 collAmount;\n        uint256 boldAmount;\n        uint256 upperHint;\n        uint256 lowerHint;\n        address interestBatchManager;\n        uint256 maxUpfrontFee;\n        address addManager;\n        address removeManager;\n        address receiver;\n    }\n\n    function openTroveAndJoinInterestBatchManager(OpenTroveAndJoinInterestBatchManagerParams calldata _params)\n        external\n        returns (uint256);\n\n    function addColl(uint256 _troveId, uint256 _ETHAmount) external;\n\n    function withdrawColl(uint256 _troveId, uint256 _amount) external;\n\n    function withdrawBold(uint256 _troveId, uint256 _amount, uint256 _maxUpfrontFee) external;\n\n    function repayBold(uint256 _troveId, uint256 _amount) external;\n\n    function closeTrove(uint256 _troveId) external;\n\n    function adjustTrove(\n        uint256 _troveId,\n        uint256 _collChange,\n        bool _isCollIncrease,\n        uint256 _debtChange,\n        bool isDebtIncrease,\n        uint256 _maxUpfrontFee\n    ) external;\n\n    function adjustZombieTrove(\n        uint256 _troveId,\n        uint256 _collChange,\n        bool _isCollIncrease,\n        uint256 _boldChange,\n        bool _isDebtIncrease,\n        uint256 _upperHint,\n        uint256 _lowerHint,\n        uint256 _maxUpfrontFee\n    ) external;\n\n    function adjustTroveInterestRate(\n        uint256 _troveId,\n        uint256 _newAnnualInterestRate,\n        uint256 _upperHint,\n        uint256 _lowerHint,\n        uint256 _maxUpfrontFee\n    ) external;\n\n    function applyPendingDebt(uint256 _troveId, uint256 _lowerHint, uint256 _upperHint) external;\n\n    function onLiquidateTrove(uint256 _troveId) external;\n\n    function claimCollateral() external;\n\n    function hasBeenShutDown() external view returns (bool);\n    function shutdown() external;\n    function shutdownFromOracleFailure() external;\n\n    function checkBatchManagerExists(address _batchMananger) external view returns (bool);\n\n    // -- individual delegation --\n    struct InterestIndividualDelegate {\n        address account;\n        uint128 minInterestRate;\n        uint128 maxInterestRate;\n        uint256 minInterestRateChangePeriod;\n    }\n\n    function getInterestIndividualDelegateOf(uint256 _troveId)\n        external\n        view\n        returns (InterestIndividualDelegate memory);\n    function setInterestIndividualDelegate(\n        uint256 _troveId,\n        address _delegate,\n        uint128 _minInterestRate,\n        uint128 _maxInterestRate,\n        // only needed if trove was previously in a batch:\n        uint256 _newAnnualInterestRate,\n        uint256 _upperHint,\n        uint256 _lowerHint,\n        uint256 _maxUpfrontFee,\n        uint256 _minInterestRateChangePeriod\n    ) external;\n    function removeInterestIndividualDelegate(uint256 _troveId) external;\n\n    // -- batches --\n    struct InterestBatchManager {\n        uint128 minInterestRate;\n        uint128 maxInterestRate;\n        uint256 minInterestRateChangePeriod;\n    }\n\n    function registerBatchManager(\n        uint128 minInterestRate,\n        uint128 maxInterestRate,\n        uint128 currentInterestRate,\n        uint128 fee,\n        uint128 minInterestRateChangePeriod\n    ) external;\n    function lowerBatchManagementFee(uint256 _newAnnualFee) external;\n    function setBatchManagerAnnualInterestRate(\n        uint128 _newAnnualInterestRate,\n        uint256 _upperHint,\n        uint256 _lowerHint,\n        uint256 _maxUpfrontFee\n    ) external;\n    function interestBatchManagerOf(uint256 _troveId) external view returns (address);\n    function getInterestBatchManager(address _account) external view returns (InterestBatchManager memory);\n    function setInterestBatchManager(\n        uint256 _troveId,\n        address _newBatchManager,\n        uint256 _upperHint,\n        uint256 _lowerHint,\n        uint256 _maxUpfrontFee\n    ) external;\n    function kickFromBatch(uint256 _troveId, uint256 _upperHint, uint256 _lowerHint) external;\n    function removeFromBatch(\n        uint256 _troveId,\n        uint256 _newAnnualInterestRate,\n        uint256 _upperHint,\n        uint256 _lowerHint,\n        uint256 _maxUpfrontFee\n    ) external;\n    function switchBatchManager(\n        uint256 _troveId,\n        uint256 _removeUpperHint,\n        uint256 _removeLowerHint,\n        address _newBatchManager,\n        uint256 _addUpperHint,\n        uint256 _addLowerHint,\n        uint256 _maxUpfrontFee\n    ) external;\n}\n"},{"file_path":"lib/bold/contracts/src/Interfaces/IAddressesRegistry.sol","source_code":"// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.0;\n\nimport \"./IActivePool.sol\";\nimport \"./IBoldToken.sol\";\nimport \"./IBorrowerOperations.sol\";\nimport \"./ICollSurplusPool.sol\";\nimport \"./IDefaultPool.sol\";\nimport \"./IHintHelpers.sol\";\nimport \"./IMultiTroveGetter.sol\";\nimport \"./ISortedTroves.sol\";\nimport \"./IStabilityPool.sol\";\nimport \"./ITroveManager.sol\";\nimport \"./ITroveNFT.sol\";\nimport {IMetadataNFT} from \"../NFTMetadata/MetadataNFT.sol\";\nimport \"./ICollateralRegistry.sol\";\nimport \"./IInterestRouter.sol\";\nimport \"./IPriceFeed.sol\";\n\ninterface IAddressesRegistry {\n    struct AddressVars {\n        IERC20Metadata collToken;\n        IBorrowerOperations borrowerOperations;\n        ITroveManager troveManager;\n        ITroveNFT troveNFT;\n        IMetadataNFT metadataNFT;\n        IStabilityPool stabilityPool;\n        IPriceFeed priceFeed;\n        IActivePool activePool;\n        IDefaultPool defaultPool;\n        address gasPoolAddress;\n        ICollSurplusPool collSurplusPool;\n        ISortedTroves sortedTroves;\n        IInterestRouter interestRouter;\n        IHintHelpers hintHelpers;\n        IMultiTroveGetter multiTroveGetter;\n        ICollateralRegistry collateralRegistry;\n        IBoldToken boldToken;\n        IERC20Metadata gasToken;\n        address liquidityStrategy;\n    }\n\n    function collToken() external view returns (IERC20Metadata);\n    function borrowerOperations() external view returns (IBorrowerOperations);\n    function troveManager() external view returns (ITroveManager);\n    function troveNFT() external view returns (ITroveNFT);\n    function metadataNFT() external view returns (IMetadataNFT);\n    function stabilityPool() external view returns (IStabilityPool);\n    function priceFeed() external view returns (IPriceFeed);\n    function activePool() external view returns (IActivePool);\n    function defaultPool() external view returns (IDefaultPool);\n    function gasPoolAddress() external view returns (address);\n    function collSurplusPool() external view returns (ICollSurplusPool);\n    function sortedTroves() external view returns (ISortedTroves);\n    function interestRouter() external view returns (IInterestRouter);\n    function hintHelpers() external view returns (IHintHelpers);\n    function multiTroveGetter() external view returns (IMultiTroveGetter);\n    function collateralRegistry() external view returns (ICollateralRegistry);\n    function boldToken() external view returns (IBoldToken);\n    function gasToken() external view returns (IERC20Metadata);\n    function liquidityStrategy() external view returns (address);\n\n    function setAddresses(AddressVars memory _vars) external;\n}"},{"file_path":"lib/bold/contracts/src/Interfaces/IBoldRewardsReceiver.sol","source_code":"// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.0;\n\ninterface IBoldRewardsReceiver {\n    function triggerBoldRewards(uint256 _boldYield) external;\n}\n"},{"file_path":"lib/bold/contracts/lib/openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Metadata.sol","source_code":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../IERC20.sol\";\n\n/**\n * @dev Interface for the optional metadata functions from the ERC20 standard.\n *\n * _Available since v4.1._\n */\ninterface IERC20Metadata is IERC20 {\n    /**\n     * @dev Returns the name of the token.\n     */\n    function name() external view returns (string memory);\n\n    /**\n     * @dev Returns the symbol of the token.\n     */\n    function symbol() external view returns (string memory);\n\n    /**\n     * @dev Returns the decimals places of the token.\n     */\n    function decimals() external view returns (uint8);\n}\n"},{"file_path":"lib/bold/contracts/src/Interfaces/IMultiTroveGetter.sol","source_code":"// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.0;\n\ninterface IMultiTroveGetter {\n    struct CombinedTroveData {\n        uint256 id;\n        uint256 entireDebt;\n        uint256 entireColl;\n        uint256 redistBoldDebtGain;\n        uint256 redistCollGain;\n        uint256 accruedInterest;\n        uint256 recordedDebt;\n        uint256 annualInterestRate;\n        uint256 accruedBatchManagementFee;\n        uint256 lastInterestRateAdjTime;\n        uint256 stake;\n        uint256 lastDebtUpdateTime;\n        address interestBatchManager;\n        uint256 batchDebtShares;\n        uint256 snapshotETH;\n        uint256 snapshotBoldDebt;\n    }\n\n    struct DebtPerInterestRate {\n        address interestBatchManager;\n        uint256 interestRate;\n        uint256 debt;\n    }\n\n    function getMultipleSortedTroves(uint256 _collIndex, int256 _startIdx, uint256 _count)\n        external\n        view\n        returns (CombinedTroveData[] memory _troves);\n\n    function getDebtPerInterestRateAscending(uint256 _collIndex, uint256 _startId, uint256 _maxIterations)\n        external\n        view\n        returns (DebtPerInterestRate[] memory, uint256 currId);\n}\n"},{"file_path":"lib/bold/contracts/src/Interfaces/IHintHelpers.sol","source_code":"// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.0;\n\ninterface IHintHelpers {\n    function getApproxHint(uint256 _collIndex, uint256 _interestRate, uint256 _numTrials, uint256 _inputRandomSeed)\n        external\n        view\n        returns (uint256 hintId, uint256 diff, uint256 latestRandomSeed);\n\n    function predictOpenTroveUpfrontFee(uint256 _collIndex, uint256 _borrowedAmount, uint256 _interestRate)\n        external\n        view\n        returns (uint256);\n\n    function predictAdjustInterestRateUpfrontFee(uint256 _collIndex, uint256 _troveId, uint256 _newInterestRate)\n        external\n        view\n        returns (uint256);\n\n    function forcePredictAdjustInterestRateUpfrontFee(uint256 _collIndex, uint256 _troveId, uint256 _newInterestRate)\n        external\n        view\n        returns (uint256);\n\n    function predictAdjustTroveUpfrontFee(uint256 _collIndex, uint256 _troveId, uint256 _debtIncrease)\n        external\n        view\n        returns (uint256);\n\n    function predictAdjustBatchInterestRateUpfrontFee(\n        uint256 _collIndex,\n        address _batchAddress,\n        uint256 _newInterestRate\n    ) external view returns (uint256);\n\n    function predictJoinBatchInterestRateUpfrontFee(uint256 _collIndex, uint256 _troveId, address _batchAddress)\n        external\n        view\n        returns (uint256);\n}\n"},{"file_path":"lib/bold/contracts/src/Interfaces/ITroveNFT.sol","source_code":"// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.0;\n\nimport \"openzeppelin-contracts/contracts/token/ERC721/extensions/IERC721Metadata.sol\";\n\nimport \"./ITroveManager.sol\";\n\ninterface ITroveNFT is IERC721Metadata {\n    function mint(address _owner, uint256 _troveId) external;\n    function burn(uint256 _troveId) external;\n}\n"},{"file_path":"lib/bold/contracts/lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol","source_code":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Interface of the ERC20 standard as defined in the EIP.\n */\ninterface IERC20 {\n    /**\n     * @dev Emitted when `value` tokens are moved from one account (`from`) to\n     * another (`to`).\n     *\n     * Note that `value` may be zero.\n     */\n    event Transfer(address indexed from, address indexed to, uint256 value);\n\n    /**\n     * @dev Emitted when the allowance of a `spender` for an `owner` is set by\n     * a call to {approve}. `value` is the new allowance.\n     */\n    event Approval(address indexed owner, address indexed spender, uint256 value);\n\n    /**\n     * @dev Returns the amount of tokens in existence.\n     */\n    function totalSupply() external view returns (uint256);\n\n    /**\n     * @dev Returns the amount of tokens owned by `account`.\n     */\n    function balanceOf(address account) external view returns (uint256);\n\n    /**\n     * @dev Moves `amount` tokens from the caller's account to `to`.\n     *\n     * Returns a boolean value indicating whether the operation succeeded.\n     *\n     * Emits a {Transfer} event.\n     */\n    function transfer(address to, uint256 amount) external returns (bool);\n\n    /**\n     * @dev Returns the remaining number of tokens that `spender` will be\n     * allowed to spend on behalf of `owner` through {transferFrom}. This is\n     * zero by default.\n     *\n     * This value changes when {approve} or {transferFrom} are called.\n     */\n    function allowance(address owner, address spender) external view returns (uint256);\n\n    /**\n     * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.\n     *\n     * Returns a boolean value indicating whether the operation succeeded.\n     *\n     * IMPORTANT: Beware that changing an allowance with this method brings the risk\n     * that someone may use both the old and the new allowance by unfortunate\n     * transaction ordering. One possible solution to mitigate this race\n     * condition is to first reduce the spender's allowance to 0 and set the\n     * desired value afterwards:\n     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729\n     *\n     * Emits an {Approval} event.\n     */\n    function approve(address spender, uint256 amount) external returns (bool);\n\n    /**\n     * @dev Moves `amount` tokens from `from` to `to` using the\n     * allowance mechanism. `amount` is then deducted from the caller's\n     * allowance.\n     *\n     * Returns a boolean value indicating whether the operation succeeded.\n     *\n     * Emits a {Transfer} event.\n     */\n    function transferFrom(address from, address to, uint256 amount) external returns (bool);\n}\n"},{"file_path":"lib/bold/contracts/src/Interfaces/ITroveEvents.sol","source_code":"// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.0;\n\ninterface ITroveEvents {\n    enum Operation {\n        openTrove,\n        closeTrove,\n        adjustTrove,\n        adjustTroveInterestRate,\n        applyPendingDebt,\n        liquidate,\n        redeemCollateral,\n        // batch management\n        openTroveAndJoinBatch,\n        setInterestBatchManager,\n        removeFromBatch\n    }\n\n    event Liquidation(\n        uint256 _debtOffsetBySP,\n        uint256 _debtRedistributed,\n        uint256 _boldGasCompensation,\n        uint256 _collGasCompensation,\n        uint256 _collSentToSP,\n        uint256 _collRedistributed,\n        uint256 _collSurplus,\n        uint256 _L_ETH,\n        uint256 _L_boldDebt,\n        uint256 _price\n    );\n\n    event Redemption(\n        uint256 _attemptedBoldAmount,\n        uint256 _actualBoldAmount,\n        uint256 _ETHSent,\n        uint256 _ETHFee,\n        uint256 _price,\n        uint256 _redemptionPrice\n    );\n\n    // A snapshot of the Trove's latest state on-chain\n    event TroveUpdated(\n        uint256 indexed _troveId,\n        uint256 _debt,\n        uint256 _coll,\n        uint256 _stake,\n        uint256 _annualInterestRate,\n        uint256 _snapshotOfTotalCollRedist,\n        uint256 _snapshotOfTotalDebtRedist\n    );\n\n    // Details of an operation that modifies a Trove\n    event TroveOperation(\n        uint256 indexed _troveId,\n        Operation _operation,\n        uint256 _annualInterestRate,\n        uint256 _debtIncreaseFromRedist,\n        uint256 _debtIncreaseFromUpfrontFee,\n        int256 _debtChangeFromOperation,\n        uint256 _collIncreaseFromRedist,\n        int256 _collChangeFromOperation\n    );\n\n    event RedemptionFeePaidToTrove(uint256 indexed _troveId, uint256 _ETHFee);\n\n    // Batch management\n\n    enum BatchOperation {\n        registerBatchManager,\n        lowerBatchManagerAnnualFee,\n        setBatchManagerAnnualInterestRate,\n        applyBatchInterestAndFee,\n        joinBatch,\n        exitBatch,\n        // used when the batch is updated as a result of a Trove change inside the batch\n        troveChange\n    }\n\n    event BatchUpdated(\n        address indexed _interestBatchManager,\n        BatchOperation _operation,\n        uint256 _debt,\n        uint256 _coll,\n        uint256 _annualInterestRate,\n        uint256 _annualManagementFee,\n        uint256 _totalDebtShares,\n        uint256 _debtIncreaseFromUpfrontFee\n    );\n\n    event BatchedTroveUpdated(\n        uint256 indexed _troveId,\n        address _interestBatchManager,\n        uint256 _batchDebtShares,\n        uint256 _coll,\n        uint256 _stake,\n        uint256 _snapshotOfTotalCollRedist,\n        uint256 _snapshotOfTotalDebtRedist\n    );\n}\n"},{"file_path":"lib/bold/contracts/src/Interfaces/IDefaultPool.sol","source_code":"// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.0;\n\ninterface IDefaultPool {\n    function troveManagerAddress() external view returns (address);\n    function activePoolAddress() external view returns (address);\n    // --- Functions ---\n    function getCollBalance() external view returns (uint256);\n    function getBoldDebt() external view returns (uint256);\n    function sendCollToActivePool(uint256 _amount) external;\n    function receiveColl(uint256 _amount) external;\n\n    function increaseBoldDebt(uint256 _amount) external;\n    function decreaseBoldDebt(uint256 _amount) external;\n}\n"},{"file_path":"lib/bold/contracts/src/NFTMetadata/utils/SVG.sol","source_code":"//SPDX-License-Identifier: MIT\npragma solidity ^0.8.18;\n\nimport {utils, LibString} from \"./Utils.sol\";\n\n/// @notice Core SVG utility library which helps us construct onchain SVG's with a simple, web-like API.\n/// @author Modified from (https://github.com/w1nt3r-eth/hot-chain-svg/blob/main/contracts/SVG.sol) by w1nt3r-eth.\n\nlibrary svg {\n    /* GLOBAL CONSTANTS */\n    string internal constant _SVG = 'xmlns=\"http://www.w3.org/2000/svg\"';\n    string internal constant _HTML = 'xmlns=\"http://www.w3.org/1999/xhtml\"';\n    string internal constant _XMLNS = \"http://www.w3.org/2000/xmlns/ \";\n    string internal constant _XLINK = \"http://www.w3.org/1999/xlink \";\n\n    /* MAIN ELEMENTS */\n    function g(string memory _props, string memory _children) internal pure returns (string memory) {\n        return el(\"g\", _props, _children);\n    }\n\n    function _svg(string memory _props, string memory _children) internal pure returns (string memory) {\n        return el(\"svg\", string.concat(_SVG, \" \", _props), _children);\n    }\n\n    function style(string memory _title, string memory _props) internal pure returns (string memory) {\n        return el(\"style\", string.concat(\".\", _title, \" \", _props));\n    }\n\n    function path(string memory _d) internal pure returns (string memory) {\n        return el(\"path\", prop(\"d\", _d, true));\n    }\n\n    function path(string memory _d, string memory _props) internal pure returns (string memory) {\n        return el(\"path\", string.concat(prop(\"d\", _d), _props));\n    }\n\n    function path(string memory _d, string memory _props, string memory _children)\n        internal\n        pure\n        returns (string memory)\n    {\n        return el(\"path\", string.concat(prop(\"d\", _d), _props), _children);\n    }\n\n    function text(string memory _props, string memory _children) internal pure returns (string memory) {\n        return el(\"text\", _props, _children);\n    }\n\n    function line(string memory _props) internal pure returns (string memory) {\n        return el(\"line\", _props);\n    }\n\n    function line(string memory _props, string memory _children) internal pure returns (string memory) {\n        return el(\"line\", _props, _children);\n    }\n\n    function circle(string memory _props) internal pure returns (string memory) {\n        return el(\"circle\", _props);\n    }\n\n    function circle(string memory _props, string memory _children) internal pure returns (string memory) {\n        return el(\"circle\", _props, _children);\n    }\n\n    function circle(string memory cx, string memory cy, string memory r) internal pure returns (string memory) {\n        return el(\"circle\", string.concat(prop(\"cx\", cx), prop(\"cy\", cy), prop(\"r\", r, true)));\n    }\n\n    function circle(string memory cx, string memory cy, string memory r, string memory _children)\n        internal\n        pure\n        returns (string memory)\n    {\n        return el(\"circle\", string.concat(prop(\"cx\", cx), prop(\"cy\", cy), prop(\"r\", r, true)), _children);\n    }\n\n    function circle(string memory cx, string memory cy, string memory r, string memory _props, string memory _children)\n        internal\n        pure\n        returns (string memory)\n    {\n        return el(\"circle\", string.concat(prop(\"cx\", cx), prop(\"cy\", cy), prop(\"r\", r), _props), _children);\n    }\n\n    function ellipse(string memory _props) internal pure returns (string memory) {\n        return el(\"ellipse\", _props);\n    }\n\n    function ellipse(string memory _props, string memory _children) internal pure returns (string memory) {\n        return el(\"ellipse\", _props, _children);\n    }\n\n    function polygon(string memory _props) internal pure returns (string memory) {\n        return el(\"polygon\", _props);\n    }\n\n    function polygon(string memory _props, string memory _children) internal pure returns (string memory) {\n        return el(\"polygon\", _props, _children);\n    }\n\n    function polyline(string memory _props) internal pure returns (string memory) {\n        return el(\"polyline\", _props);\n    }\n\n    function polyline(string memory _props, string memory _children) internal pure returns (string memory) {\n        return el(\"polyline\", _props, _children);\n    }\n\n    function rect(string memory _props) internal pure returns (string memory) {\n        return el(\"rect\", _props);\n    }\n\n    function rect(string memory _props, string memory _children) internal pure returns (string memory) {\n        return el(\"rect\", _props, _children);\n    }\n\n    function filter(string memory _props, string memory _children) internal pure returns (string memory) {\n        return el(\"filter\", _props, _children);\n    }\n\n    function cdata(string memory _content) internal pure returns (string memory) {\n        return string.concat(\"<![CDATA[\", _content, \"]]>\");\n    }\n\n    /* GRADIENTS */\n    function radialGradient(string memory _props, string memory _children) internal pure returns (string memory) {\n        return el(\"radialGradient\", _props, _children);\n    }\n\n    function linearGradient(string memory _props, string memory _children) internal pure returns (string memory) {\n        return el(\"linearGradient\", _props, _children);\n    }\n\n    function gradientStop(uint256 offset, string memory stopColor, string memory _props)\n        internal\n        pure\n        returns (string memory)\n    {\n        return el(\n            \"stop\",\n            string.concat(\n                prop(\"stop-color\", stopColor),\n                \" \",\n                prop(\"offset\", string.concat(LibString.toString(offset), \"%\")),\n                \" \",\n                _props\n            ),\n            utils.NULL\n        );\n    }\n\n    /* ANIMATION */\n    function animateTransform(string memory _props) internal pure returns (string memory) {\n        return el(\"animateTransform\", _props);\n    }\n\n    function animate(string memory _props) internal pure returns (string memory) {\n        return el(\"animate\", _props);\n    }\n\n    /* COMMON */\n    // A generic element, can be used to construct any SVG (or HTML) element\n    function el(string memory _tag, string memory _props, string memory _children)\n        internal\n        pure\n        returns (string memory)\n    {\n        return string.concat(\"<\", _tag, \" \", _props, \">\", _children, \"</\", _tag, \">\");\n    }\n\n    // A generic element, can be used to construct SVG (or HTML) elements without children\n    function el(string memory _tag, string memory _props) internal pure returns (string memory) {\n        return string.concat(\"<\", _tag, \" \", _props, \"/>\");\n    }\n\n    // an SVG attribute\n    function prop(string memory _key, string memory _val) internal pure returns (string memory) {\n        return string.concat(_key, \"=\", '\"', _val, '\" ');\n    }\n\n    function prop(string memory _key, string memory _val, bool last) internal pure returns (string memory) {\n        if (last) {\n            return string.concat(_key, \"=\", '\"', _val, '\"');\n        } else {\n            return string.concat(_key, \"=\", '\"', _val, '\" ');\n        }\n    }\n}\n"},{"file_path":"lib/bold/contracts/src/Interfaces/ICollateralRegistry.sol","source_code":"// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.0;\n\nimport \"openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Metadata.sol\";\nimport \"./IBoldToken.sol\";\nimport \"./ITroveManager.sol\";\n\ninterface ICollateralRegistry {\n    function baseRate() external view returns (uint256);\n    function lastFeeOperationTime() external view returns (uint256);\n    function liquidityStrategy() external view returns (address);\n    function redeemCollateralRebalancing(uint256 _boldamount, uint256 _maxIterationsPerCollateral, uint256 _troveOwnerFee) external;\n    function redeemCollateral(uint256 _boldamount, uint256 _maxIterations, uint256 _maxFeePercentage) external;\n    // getters\n    function totalCollaterals() external view returns (uint256);\n    function getToken(uint256 _index) external view returns (IERC20Metadata);\n    function getTroveManager(uint256 _index) external view returns (ITroveManager);\n    function boldToken() external view returns (IBoldToken);\n\n    function getRedemptionRate() external view returns (uint256);\n    function getRedemptionRateWithDecay() external view returns (uint256);\n    function getRedemptionRateForRedeemedAmount(uint256 _redeemAmount) external view returns (uint256);\n\n    function getRedemptionFeeWithDecay(uint256 _ETHDrawn) external view returns (uint256);\n    function getEffectiveRedemptionFeeInBold(uint256 _redeemAmount) external view returns (uint256);\n}\n"},{"file_path":"lib/bold/contracts/src/Interfaces/ITroveManager.sol","source_code":"// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.0;\n\nimport \"./ILiquityBase.sol\";\nimport \"./ITroveNFT.sol\";\nimport \"./IBorrowerOperations.sol\";\nimport \"./IStabilityPool.sol\";\nimport \"./IBoldToken.sol\";\nimport \"./ISortedTroves.sol\";\nimport \"../Types/LatestTroveData.sol\";\nimport \"../Types/LatestBatchData.sol\";\n\n// Common interface for the Trove Manager.\ninterface ITroveManager is ILiquityBase {\n    enum Status {\n        nonExistent,\n        active,\n        closedByOwner,\n        closedByLiquidation,\n        zombie\n    }\n\n    function shutdownTime() external view returns (uint256);\n\n    function troveNFT() external view returns (ITroveNFT);\n    function stabilityPool() external view returns (IStabilityPool);\n    //function boldToken() external view returns (IBoldToken);\n    function sortedTroves() external view returns (ISortedTroves);\n    function borrowerOperations() external view returns (IBorrowerOperations);\n\n    function Troves(uint256 _id)\n        external\n        view\n        returns (\n            uint256 debt,\n            uint256 coll,\n            uint256 stake,\n            Status status,\n            uint64 arrayIndex,\n            uint64 lastDebtUpdateTime,\n            uint64 lastInterestRateAdjTime,\n            uint256 annualInterestRate,\n            address interestBatchManager,\n            uint256 batchDebtShares\n        );\n\n    function rewardSnapshots(uint256 _id) external view returns (uint256 coll, uint256 boldDebt);\n\n    function getTroveIdsCount() external view returns (uint256);\n\n    function getTroveFromTroveIdsArray(uint256 _index) external view returns (uint256);\n\n    function getCurrentICR(uint256 _troveId, uint256 _price) external view returns (uint256);\n\n    function lastZombieTroveId() external view returns (uint256);\n\n    function batchLiquidateTroves(uint256[] calldata _troveArray) external;\n\n    function redeemCollateral(\n        address _sender,\n        uint256 _boldAmount,\n        uint256 _price,\n        uint256 _redemptionRate,\n        uint256 _maxIterations\n    ) external returns (uint256 _redemeedAmount);\n\n    function shutdown() external;\n    function urgentRedemption(uint256 _boldAmount, uint256[] calldata _troveIds, uint256 _minCollateral) external;\n\n    function getUnbackedPortionPriceAndRedeemability() external returns (uint256, uint256, bool);\n\n    function getLatestTroveData(uint256 _troveId) external view returns (LatestTroveData memory);\n    function getTroveAnnualInterestRate(uint256 _troveId) external view returns (uint256);\n\n    function getTroveStatus(uint256 _troveId) external view returns (Status);\n\n    function getLatestBatchData(address _batchAddress) external view returns (LatestBatchData memory);\n\n    // -- permissioned functions called by BorrowerOperations\n\n    function onOpenTrove(address _owner, uint256 _troveId, TroveChange memory _troveChange, uint256 _annualInterestRate)\n        external;\n    function onOpenTroveAndJoinBatch(\n        address _owner,\n        uint256 _troveId,\n        TroveChange memory _troveChange,\n        address _batchAddress,\n        uint256 _batchColl,\n        uint256 _batchDebt\n    ) external;\n\n    // Called from `adjustZombieTrove()`\n    function setTroveStatusToActive(uint256 _troveId) external;\n\n    function onAdjustTroveInterestRate(\n        uint256 _troveId,\n        uint256 _newColl,\n        uint256 _newDebt,\n        uint256 _newAnnualInterestRate,\n        TroveChange calldata _troveChange\n    ) external;\n\n    function onAdjustTrove(uint256 _troveId, uint256 _newColl, uint256 _newDebt, TroveChange calldata _troveChange)\n        external;\n\n    function onAdjustTroveInsideBatch(\n        uint256 _troveId,\n        uint256 _newTroveColl,\n        uint256 _newTroveDebt,\n        TroveChange memory _troveChange,\n        address _batchAddress,\n        uint256 _newBatchColl,\n        uint256 _newBatchDebt\n    ) external;\n\n    function onApplyTroveInterest(\n        uint256 _troveId,\n        uint256 _newTroveColl,\n        uint256 _newTroveDebt,\n        address _batchAddress,\n        uint256 _newBatchColl,\n        uint256 _newBatchDebt,\n        TroveChange calldata _troveChange\n    ) external;\n\n    function onCloseTrove(\n        uint256 _troveId,\n        TroveChange memory _troveChange, // decrease vars: entire, with interest, batch fee and redistribution\n        address _batchAddress,\n        uint256 _newBatchColl,\n        uint256 _newBatchDebt // entire, with interest and batch fee\n    ) external;\n\n    // -- batches --\n    function onRegisterBatchManager(address _batchAddress, uint256 _annualInterestRate, uint256 _annualFee) external;\n    function onLowerBatchManagerAnnualFee(\n        address _batchAddress,\n        uint256 _newColl,\n        uint256 _newDebt,\n        uint256 _newAnnualManagementFee\n    ) external;\n    function onSetBatchManagerAnnualInterestRate(\n        address _batchAddress,\n        uint256 _newColl,\n        uint256 _newDebt,\n        uint256 _newAnnualInterestRate,\n        uint256 _upfrontFee // needed by BatchUpdated event\n    ) external;\n\n    struct OnSetInterestBatchManagerParams {\n        uint256 troveId;\n        uint256 troveColl; // entire, with redistribution\n        uint256 troveDebt; // entire, with interest, batch fee and redistribution\n        TroveChange troveChange;\n        address newBatchAddress;\n        uint256 newBatchColl; // updated collateral for new batch manager\n        uint256 newBatchDebt; // updated debt for new batch manager\n    }\n\n    function onSetInterestBatchManager(OnSetInterestBatchManagerParams calldata _params) external;\n    function onRemoveFromBatch(\n        uint256 _troveId,\n        uint256 _newTroveColl, // entire, with redistribution\n        uint256 _newTroveDebt, // entire, with interest, batch fee and redistribution\n        TroveChange memory _troveChange,\n        address _batchAddress,\n        uint256 _newBatchColl,\n        uint256 _newBatchDebt, // entire, with interest and batch fee\n        uint256 _newAnnualInterestRate\n    ) external;\n\n    // -- end of permissioned functions --\n}\n"},{"file_path":"lib/bold/contracts/src/NFTMetadata/utils/Utils.sol","source_code":"//SPDX-License-Identifier: MIT\npragma solidity 0.8.24;\n\nimport \"Solady/utils/LibString.sol\";\n\nlibrary numUtils {\n    function toLocale(string memory _wholeNumber) internal pure returns (string memory) {\n        bytes memory b = bytes(_wholeNumber);\n        uint256 len = b.length;\n        if (len < 4) return _wholeNumber;\n\n        uint256 numCommas = (len - 1) / 3;\n\n        bytes memory result = new bytes(len + numCommas);\n\n        uint256 j = result.length - 1;\n        uint256 k = len;\n        for (uint256 i = 0; i < len; i++) {\n            result[j] = b[k - 1];\n            j = j > 1 ? j - 1 : 0;\n            k--;\n            if (k > 0 && (len - k) % 3 == 0) {\n                result[j] = \",\";\n                j = j > 1 ? j - 1 : 0;\n            }\n        }\n\n        return string(result);\n    }\n\n    // returns a string representation of a number with commas, where result = _value / 10 ** _divisor\n    function toLocaleString(uint256 _value, uint8 _divisor, uint8 _precision) internal pure returns (string memory) {\n        uint256 whole;\n        uint256 fraction;\n\n        if (_divisor > 0) {\n            whole = _value / 10 ** _divisor;\n            // check if the divisor is less than the precision\n            if (_divisor <= _precision) {\n                fraction = (_value % 10 ** _divisor);\n                // adjust fraction to be the same as the precision\n                fraction = fraction * 10 ** (_precision - _divisor);\n\n                // if whole is zero, then add another zero to the fraction, special case if the value is 1\n                fraction = (whole == 0 && _value != 1) ? fraction * 10 : fraction;\n            } else {\n                fraction = (_value % 10 ** _divisor) / 10 ** (_divisor - _precision - 1);\n            }\n        } else {\n            whole = _value;\n        }\n\n        string memory wholeStr = toLocale(LibString.toString(whole));\n\n        if (fraction == 0) {\n            if (whole > 0 && _precision > 0) wholeStr = string.concat(wholeStr, \".\");\n            for (uint8 i = 0; i < _precision; i++) {\n                wholeStr = string.concat(wholeStr, \"0\");\n            }\n\n            return wholeStr;\n        }\n\n        string memory fractionStr = LibString.slice(LibString.toString(fraction), 0, _precision);\n\n        // pad with leading zeros\n        if (_precision > bytes(fractionStr).length) {\n            uint256 len = _precision - bytes(fractionStr).length;\n            string memory zeroStr = \"\";\n\n            for (uint8 i = 0; i < len; i++) {\n                zeroStr = string.concat(zeroStr, \"0\");\n            }\n\n            fractionStr = string.concat(zeroStr, fractionStr);\n        }\n\n        return string.concat(wholeStr, _precision > 0 ? \".\" : \"\", fractionStr);\n    }\n}\n\n/// @notice Core utils used extensively to format CSS and numbers.\n/// @author Modified from (https://github.com/w1nt3r-eth/hot-chain-svg/blob/main/contracts/Utils.sol) by w1nt3r-eth.\n\nlibrary utils {\n    // used to simulate empty strings\n    string internal constant NULL = \"\";\n\n    // formats a CSS variable line. includes a semicolon for formatting.\n    function setCssVar(string memory _key, string memory _val) internal pure returns (string memory) {\n        return string.concat(\"--\", _key, \":\", _val, \";\");\n    }\n\n    // formats getting a css variable\n    function getCssVar(string memory _key) internal pure returns (string memory) {\n        return string.concat(\"var(--\", _key, \")\");\n    }\n\n    // formats getting a def URL\n    function getDefURL(string memory _id) internal pure returns (string memory) {\n        return string.concat(\"url(#\", _id, \")\");\n    }\n\n    // formats rgba white with a specified opacity / alpha\n    function white_a(uint256 _a) internal pure returns (string memory) {\n        return rgba(255, 255, 255, _a);\n    }\n\n    // formats rgba black with a specified opacity / alpha\n    function black_a(uint256 _a) internal pure returns (string memory) {\n        return rgba(0, 0, 0, _a);\n    }\n\n    // formats generic rgba color in css\n    function rgba(uint256 _r, uint256 _g, uint256 _b, uint256 _a) internal pure returns (string memory) {\n        string memory formattedA = _a < 100 ? string.concat(\"0.\", LibString.toString(_a)) : \"1\";\n        return string.concat(\n            \"rgba(\",\n            LibString.toString(_r),\n            \",\",\n            LibString.toString(_g),\n            \",\",\n            LibString.toString(_b),\n            \",\",\n            formattedA,\n            \")\"\n        );\n    }\n\n    function cssBraces(string memory _attribute, string memory _value) internal pure returns (string memory) {\n        return string.concat(\" {\", _attribute, \": \", _value, \"}\");\n    }\n\n    function cssBraces(string[] memory _attributes, string[] memory _values) internal pure returns (string memory) {\n        require(_attributes.length == _values.length, \"Utils: Unbalanced Arrays\");\n\n        uint256 len = _attributes.length;\n\n        string memory results = \" {\";\n\n        for (uint256 i = 0; i < len; i++) {\n            results = string.concat(results, _attributes[i], \": \", _values[i], \"; \");\n        }\n\n        return string.concat(results, \"}\");\n    }\n\n    //deals with integers (i.e. no decimals)\n    function points(uint256[2][] memory pointsArray) internal pure returns (string memory) {\n        require(pointsArray.length >= 3, \"Utils: Array too short\");\n\n        uint256 len = pointsArray.length - 1;\n\n        string memory results = 'points=\"';\n\n        for (uint256 i = 0; i < len; i++) {\n            results = string.concat(\n                results, LibString.toString(pointsArray[i][0]), \",\", LibString.toString(pointsArray[i][1]), \" \"\n            );\n        }\n\n        return string.concat(\n            results, LibString.toString(pointsArray[len][0]), \",\", LibString.toString(pointsArray[len][1]), '\"'\n        );\n    }\n\n    // allows for a uniform precision to be applied to all points\n    function points(uint256[2][] memory pointsArray, uint256 decimalPrecision) internal pure returns (string memory) {\n        require(pointsArray.length >= 3, \"Utils: Array too short\");\n\n        uint256 len = pointsArray.length - 1;\n\n        string memory results = 'points=\"';\n\n        for (uint256 i = 0; i < len; i++) {\n            results = string.concat(\n                results,\n                toString(pointsArray[i][0], decimalPrecision),\n                \",\",\n                toString(pointsArray[i][1], decimalPrecision),\n                \" \"\n            );\n        }\n\n        return string.concat(\n            results,\n            toString(pointsArray[len][0], decimalPrecision),\n            \",\",\n            toString(pointsArray[len][1], decimalPrecision),\n            '\"'\n        );\n    }\n\n    // checks if two strings are equal\n    function stringsEqual(string memory _a, string memory _b) internal pure returns (bool) {\n        return keccak256(abi.encodePacked(_a)) == keccak256(abi.encodePacked(_b));\n    }\n\n    // returns the length of a string in characters\n    function utfStringLength(string memory _str) internal pure returns (uint256 length) {\n        uint256 i = 0;\n        bytes memory string_rep = bytes(_str);\n\n        while (i < string_rep.length) {\n            if (string_rep[i] >> 7 == 0) {\n                i += 1;\n            } else if (string_rep[i] >> 5 == bytes1(uint8(0x6))) {\n                i += 2;\n            } else if (string_rep[i] >> 4 == bytes1(uint8(0xE))) {\n                i += 3;\n            } else if (string_rep[i] >> 3 == bytes1(uint8(0x1E))) {\n                i += 4;\n            }\n            //For safety\n            else {\n                i += 1;\n            }\n\n            length++;\n        }\n    }\n\n    // allows the insertion of a decimal point in the returned string at precision\n    function toString(uint256 value, uint256 precision) internal pure returns (string memory) {\n        // Inspired by OraclizeAPI's implementation - MIT licence\n        // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol\n\n        if (value == 0) {\n            return \"0\";\n        }\n        uint256 temp = value;\n        uint256 digits;\n        while (temp != 0) {\n            digits++;\n            temp /= 10;\n        }\n        require(precision <= digits && precision > 0, \"Utils: precision invalid\");\n        precision == digits ? digits += 2 : digits++; //adds a space for the decimal point, 2 if it is the whole uint\n\n        uint256 decimalPlacement = digits - precision - 1;\n        bytes memory buffer = new bytes(digits);\n\n        buffer[decimalPlacement] = 0x2E; // add the decimal point, ASCII 46/hex 2E\n        if (decimalPlacement == 1) {\n            buffer[0] = 0x30;\n        }\n\n        while (value != 0) {\n            digits -= 1;\n            if (digits != decimalPlacement) {\n                buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));\n                value /= 10;\n            }\n        }\n\n        return string(buffer);\n    }\n}\n"},{"file_path":"lib/bold/contracts/lib/Solady/src/utils/SSTORE2.sol","source_code":"// SPDX-License-Identifier: MIT\npragma solidity ^0.8.4;\n\n/// @notice Read and write to persistent storage at a fraction of the cost.\n/// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/SSTORE2.sol)\n/// @author Saw-mon-and-Natalie (https://github.com/Saw-mon-and-Natalie)\n/// @author Modified from Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/SSTORE2.sol)\n/// @author Modified from 0xSequence (https://github.com/0xSequence/sstore2/blob/master/contracts/SSTORE2.sol)\n/// @author Modified from SSTORE3 (https://github.com/Philogy/sstore3)\nlibrary SSTORE2 {\n    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/\n    /*                         CONSTANTS                          */\n    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/\n\n    /// @dev The proxy initialization code.\n    uint256 private constant _CREATE3_PROXY_INITCODE = 0x67363d3d37363d34f03d5260086018f3;\n\n    /// @dev Hash of the `_CREATE3_PROXY_INITCODE`.\n    /// Equivalent to `keccak256(abi.encodePacked(hex\"67363d3d37363d34f03d5260086018f3\"))`.\n    bytes32 internal constant CREATE3_PROXY_INITCODE_HASH =\n        0x21c35dbe1b344a2488cf3321d6ce542f8e9f305544ff09e4993a62319a497c1f;\n\n    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/\n    /*                        CUSTOM ERRORS                       */\n    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/\n\n    /// @dev Unable to deploy the storage contract.\n    error DeploymentFailed();\n\n    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/\n    /*                         WRITE LOGIC                        */\n    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/\n\n    /// @dev Writes `data` into the bytecode of a storage contract and returns its address.\n    function write(bytes memory data) internal returns (address pointer) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            let n := mload(data) // Let `l` be `n + 1`. +1 as we prefix a STOP opcode.\n            /**\n             * ---------------------------------------------------+\n             * Opcode | Mnemonic       | Stack     | Memory       |\n             * ---------------------------------------------------|\n             * 61 l   | PUSH2 l        | l         |              |\n             * 80     | DUP1           | l l       |              |\n             * 60 0xa | PUSH1 0xa      | 0xa l l   |              |\n             * 3D     | RETURNDATASIZE | 0 0xa l l |              |\n             * 39     | CODECOPY       | l         | [0..l): code |\n             * 3D     | RETURNDATASIZE | 0 l       | [0..l): code |\n             * F3     | RETURN         |           | [0..l): code |\n             * 00     | STOP           |           |              |\n             * ---------------------------------------------------+\n             * @dev Prefix the bytecode with a STOP opcode to ensure it cannot be called.\n             * Also PUSH2 is used since max contract size cap is 24,576 bytes which is less than 2 ** 16.\n             */\n            // Do a out-of-gas revert if `n + 1` is more than 2 bytes.\n            mstore(add(data, gt(n, 0xfffe)), add(0xfe61000180600a3d393df300, shl(0x40, n)))\n            // Deploy a new contract with the generated creation code.\n            pointer := create(0, add(data, 0x15), add(n, 0xb))\n            if iszero(pointer) {\n                mstore(0x00, 0x30116425) // `DeploymentFailed()`.\n                revert(0x1c, 0x04)\n            }\n            mstore(data, n) // Restore the length of `data`.\n        }\n    }\n\n    /// @dev Writes `data` into the bytecode of a storage contract with `salt`\n    /// and returns its normal CREATE2 deterministic address.\n    function writeCounterfactual(bytes memory data, bytes32 salt)\n        internal\n        returns (address pointer)\n    {\n        /// @solidity memory-safe-assembly\n        assembly {\n            let n := mload(data)\n            // Do a out-of-gas revert if `n + 1` is more than 2 bytes.\n            mstore(add(data, gt(n, 0xfffe)), add(0xfe61000180600a3d393df300, shl(0x40, n)))\n            // Deploy a new contract with the generated creation code.\n            pointer := create2(0, add(data, 0x15), add(n, 0xb), salt)\n            if iszero(pointer) {\n                mstore(0x00, 0x30116425) // `DeploymentFailed()`.\n                revert(0x1c, 0x04)\n            }\n            mstore(data, n) // Restore the length of `data`.\n        }\n    }\n\n    /// @dev Writes `data` into the bytecode of a storage contract and returns its address.\n    /// This uses the so-called \"CREATE3\" workflow,\n    /// which means that `pointer` is agnostic to `data, and only depends on `salt`.\n    function writeDeterministic(bytes memory data, bytes32 salt)\n        internal\n        returns (address pointer)\n    {\n        /// @solidity memory-safe-assembly\n        assembly {\n            let n := mload(data)\n            mstore(0x00, _CREATE3_PROXY_INITCODE) // Store the `_PROXY_INITCODE`.\n            let proxy := create2(0, 0x10, 0x10, salt)\n            if iszero(proxy) {\n                mstore(0x00, 0x30116425) // `DeploymentFailed()`.\n                revert(0x1c, 0x04)\n            }\n            mstore(0x14, proxy) // Store the proxy's address.\n            // 0xd6 = 0xc0 (short RLP prefix) + 0x16 (length of: 0x94 ++ proxy ++ 0x01).\n            // 0x94 = 0x80 + 0x14 (0x14 = the length of an address, 20 bytes, in hex).\n            mstore(0x00, 0xd694)\n            mstore8(0x34, 0x01) // Nonce of the proxy contract (1).\n            pointer := keccak256(0x1e, 0x17)\n\n            // Do a out-of-gas revert if `n + 1` is more than 2 bytes.\n            mstore(add(data, gt(n, 0xfffe)), add(0xfe61000180600a3d393df300, shl(0x40, n)))\n            if iszero(\n                mul( // The arguments of `mul` are evaluated last to first.\n                    extcodesize(pointer),\n                    call(gas(), proxy, 0, add(data, 0x15), add(n, 0xb), codesize(), 0x00)\n                )\n            ) {\n                mstore(0x00, 0x30116425) // `DeploymentFailed()`.\n                revert(0x1c, 0x04)\n            }\n            mstore(data, n) // Restore the length of `data`.\n        }\n    }\n\n    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/\n    /*                    ADDRESS CALCULATIONS                    */\n    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/\n\n    /// @dev Returns the initialization code hash of the storage contract for `data`.\n    /// Used for mining vanity addresses with create2crunch.\n    function initCodeHash(bytes memory data) internal pure returns (bytes32 hash) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            let n := mload(data)\n            // Do a out-of-gas revert if `n + 1` is more than 2 bytes.\n            returndatacopy(returndatasize(), returndatasize(), gt(n, 0xfffe))\n            mstore(data, add(0x61000180600a3d393df300, shl(0x40, n)))\n            hash := keccak256(add(data, 0x15), add(n, 0xb))\n            mstore(data, n) // Restore the length of `data`.\n        }\n    }\n\n    /// @dev Equivalent to `predictCounterfactualAddress(data, salt, address(this))`\n    function predictCounterfactualAddress(bytes memory data, bytes32 salt)\n        internal\n        view\n        returns (address pointer)\n    {\n        pointer = predictCounterfactualAddress(data, salt, address(this));\n    }\n\n    /// @dev Returns the CREATE2 address of the storage contract for `data`\n    /// deployed with `salt` by `deployer`.\n    /// Note: The returned result has dirty upper 96 bits. Please clean if used in assembly.\n    function predictCounterfactualAddress(bytes memory data, bytes32 salt, address deployer)\n        internal\n        pure\n        returns (address predicted)\n    {\n        bytes32 hash = initCodeHash(data);\n        /// @solidity memory-safe-assembly\n        assembly {\n            // Compute and store the bytecode hash.\n            mstore8(0x00, 0xff) // Write the prefix.\n            mstore(0x35, hash)\n            mstore(0x01, shl(96, deployer))\n            mstore(0x15, salt)\n            predicted := keccak256(0x00, 0x55)\n            // Restore the part of the free memory pointer that has been overwritten.\n            mstore(0x35, 0)\n        }\n    }\n\n    /// @dev Equivalent to `predictDeterministicAddress(salt, address(this))`.\n    function predictDeterministicAddress(bytes32 salt) internal view returns (address pointer) {\n        pointer = predictDeterministicAddress(salt, address(this));\n    }\n\n    /// @dev Returns the \"CREATE3\" deterministic address for `salt` with `deployer`.\n    function predictDeterministicAddress(bytes32 salt, address deployer)\n        internal\n        pure\n        returns (address pointer)\n    {\n        /// @solidity memory-safe-assembly\n        assembly {\n            let m := mload(0x40) // Cache the free memory pointer.\n            mstore(0x00, deployer) // Store `deployer`.\n            mstore8(0x0b, 0xff) // Store the prefix.\n            mstore(0x20, salt) // Store the salt.\n            mstore(0x40, CREATE3_PROXY_INITCODE_HASH) // Store the bytecode hash.\n\n            mstore(0x14, keccak256(0x0b, 0x55)) // Store the proxy's address.\n            mstore(0x40, m) // Restore the free memory pointer.\n            // 0xd6 = 0xc0 (short RLP prefix) + 0x16 (length of: 0x94 ++ proxy ++ 0x01).\n            // 0x94 = 0x80 + 0x14 (0x14 = the length of an address, 20 bytes, in hex).\n            mstore(0x00, 0xd694)\n            mstore8(0x34, 0x01) // Nonce of the proxy contract (1).\n            pointer := keccak256(0x1e, 0x17)\n        }\n    }\n\n    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/\n    /*                         READ LOGIC                         */\n    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/\n\n    /// @dev Equivalent to `read(pointer, 0, 2 ** 256 - 1)`.\n    function read(address pointer) internal view returns (bytes memory data) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            data := mload(0x40)\n            let n := and(sub(extcodesize(pointer), 0x01), 0xffffffffff)\n            extcodecopy(pointer, add(data, 0x1f), 0x00, add(n, 0x21))\n            mstore(data, n) // Store the length.\n            mstore(0x40, add(n, add(data, 0x40))) // Allocate memory.\n        }\n    }\n\n    /// @dev Equivalent to `read(pointer, start, 2 ** 256 - 1)`.\n    function read(address pointer, uint256 start) internal view returns (bytes memory data) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            data := mload(0x40)\n            let n := and(sub(extcodesize(pointer), 0x01), 0xffffffffff)\n            extcodecopy(pointer, add(data, 0x1f), start, add(n, 0x21))\n            mstore(data, mul(sub(n, start), lt(start, n))) // Store the length.\n            mstore(0x40, add(data, add(0x40, mload(data)))) // Allocate memory.\n        }\n    }\n\n    /// @dev Returns a slice of the data on `pointer` from `start` to `end`.\n    /// `start` and `end` will be clamped to the range `[0, args.length]`.\n    /// The `pointer` MUST be deployed via the SSTORE2 write functions.\n    /// Otherwise, the behavior is undefined.\n    /// Out-of-gas reverts if `pointer` does not have any code.\n    function read(address pointer, uint256 start, uint256 end)\n        internal\n        view\n        returns (bytes memory data)\n    {\n        /// @solidity memory-safe-assembly\n        assembly {\n            data := mload(0x40)\n            if iszero(lt(end, 0xffff)) { end := 0xffff }\n            let d := mul(sub(end, start), lt(start, end))\n            extcodecopy(pointer, add(data, 0x1f), start, add(d, 0x01))\n            if iszero(and(0xff, mload(add(data, d)))) {\n                let n := sub(extcodesize(pointer), 0x01)\n                returndatacopy(returndatasize(), returndatasize(), shr(64, n))\n                d := mul(gt(n, start), sub(d, mul(gt(end, n), sub(end, n))))\n            }\n            mstore(data, d) // Store the length.\n            mstore(add(add(data, 0x20), d), 0) // Zeroize the slot after the bytes.\n            mstore(0x40, add(add(data, 0x40), d)) // Allocate memory.\n        }\n    }\n}\n"},{"file_path":"lib/bold/contracts/src/NFTMetadata/MetadataNFT.sol","source_code":"//SPDX-License-Identifier: MIT\npragma solidity 0.8.24;\n\nimport \"Solady/utils/SSTORE2.sol\";\nimport \"./utils/JSON.sol\";\n\nimport \"./utils/baseSVG.sol\";\nimport \"./utils/bauhaus.sol\";\n\nimport \"openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Metadata.sol\";\n\nimport {ITroveManager} from \"../Interfaces/ITroveManager.sol\";\n\ninterface IMetadataNFT {\n    struct TroveData {\n        uint256 _tokenId;\n        address _owner;\n        address _collToken;\n        address _boldToken;\n        uint256 _collAmount;\n        uint256 _debtAmount;\n        uint256 _interestRate;\n        ITroveManager.Status _status;\n    }\n\n    function uri(TroveData memory _troveData) external view returns (string memory);\n}\n\ncontract MetadataNFT is IMetadataNFT {\n    FixedAssetReader public immutable assetReader;\n\n    constructor(FixedAssetReader _assetReader) {\n        assetReader = _assetReader;\n    }\n\n    function uri(TroveData memory _troveData) public view returns (string memory) {\n        string memory attr = attributes(_troveData);\n        return json.formattedMetadata(\n            string.concat(\"Mento Liquity V2 - \", IERC20Metadata(_troveData._collToken).name()),\n            string.concat(\n                \"Mento Liquity V2 is a collateralized debt platform. Users can lock up \",\n                IERC20Metadata(_troveData._collToken).symbol(),\n                \" to issue \", \n                IERC20Metadata(_troveData._boldToken).symbol(), \n                \" to their own address. The individual collateralized debt positions are called Troves, and are represented as NFTs.\"\n            ),\n            renderSVGImage(_troveData),\n            attr\n        );\n    }\n\n    function renderSVGImage(TroveData memory _troveData) internal view returns (string memory) {\n        return svg._svg(\n            baseSVG._svgProps(),\n            string.concat(\n                baseSVG._baseElements(assetReader),\n                bauhaus._bauhaus(IERC20Metadata(_troveData._collToken).symbol(), _troveData._tokenId),\n                dynamicTextComponents(_troveData)\n            )\n        );\n    }\n\n    function attributes(TroveData memory _troveData) public pure returns (string memory) {\n        //include: collateral token address, collateral amount, debt token address, debt amount, interest rate, status\n        return string.concat(\n            '[{\"trait_type\": \"Collateral Token\", \"value\": \"',\n            LibString.toHexString(_troveData._collToken),\n            '\"}, {\"trait_type\": \"Collateral Amount\", \"value\": \"',\n            LibString.toString(_troveData._collAmount),\n            '\"}, {\"trait_type\": \"Debt Token\", \"value\": \"',\n            LibString.toHexString(_troveData._boldToken),\n            '\"}, {\"trait_type\": \"Debt Amount\", \"value\": \"',\n            LibString.toString(_troveData._debtAmount),\n            '\"}, {\"trait_type\": \"Interest Rate\", \"value\": \"',\n            LibString.toString(_troveData._interestRate),\n            '\"}, {\"trait_type\": \"Status\", \"value\": \"',\n            _status2Str(_troveData._status),\n            '\"} ]'\n        );\n    }\n\n    function dynamicTextComponents(TroveData memory _troveData) public view returns (string memory) {\n        string memory id = LibString.toHexString(_troveData._tokenId);\n        id = string.concat(LibString.slice(id, 0, 6), \"...\", LibString.slice(id, 38, 42));\n\n        return string.concat(\n            baseSVG._formattedIdEl(id),\n            baseSVG._formattedAddressEl(_troveData._owner),\n            baseSVG._collLogo(IERC20Metadata(_troveData._collToken).symbol(), assetReader),\n            baseSVG._statusEl(_status2Str(_troveData._status)),\n            baseSVG._dynamicTextEls(_troveData._debtAmount, _troveData._collAmount, _troveData._interestRate)\n        );\n    }\n\n    function _status2Str(ITroveManager.Status status) internal pure returns (string memory) {\n        if (status == ITroveManager.Status.active) return \"Active\";\n        if (status == ITroveManager.Status.closedByOwner) return \"Closed\";\n        if (status == ITroveManager.Status.closedByLiquidation) return \"Liquidated\";\n        if (status == ITroveManager.Status.zombie) return \"Below Min Debt\";\n        return \"\";\n    }\n}\n"},{"file_path":"lib/bold/contracts/src/NFTMetadata/utils/FixedAssets.sol","source_code":"//SPDX-License-Identifier: MIT\npragma solidity 0.8.24;\n\nimport \"Solady/utils/SSTORE2.sol\";\n\ncontract FixedAssetReader {\n    struct Asset {\n        uint128 start;\n        uint128 end;\n    }\n\n    address public immutable pointer;\n\n    mapping(bytes4 => Asset) public assets;\n\n    function readAsset(bytes4 _sig) public view returns (string memory) {\n        return string(SSTORE2.read(pointer, uint256(assets[_sig].start), uint256(assets[_sig].end)));\n    }\n\n    constructor(address _pointer, bytes4[] memory _sigs, Asset[] memory _assets) {\n        pointer = _pointer;\n        require(_sigs.length == _assets.length, \"FixedAssetReader: Invalid input\");\n        for (uint256 i = 0; i < _sigs.length; i++) {\n            assets[_sigs[i]] = _assets[i];\n        }\n    }\n}\n"},{"file_path":"lib/bold/contracts/src/Interfaces/IInterestRouter.sol","source_code":"// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.0;\n\ninterface IInterestRouter {\n// Currently the Interest Router doesn’t need any specific function\n}\n"},{"file_path":"lib/bold/contracts/src/NFTMetadata/utils/bauhaus.sol","source_code":"//SPDX-License-Identifier: MIT\npragma solidity 0.8.24;\n\nimport \"./SVG.sol\";\n\nlibrary bauhaus {\n    string constant GOLDEN = \"#F5D93A\";\n    string constant CORAL = \"#FB7C59\";\n    string constant GREEN = \"#63D77D\";\n    string constant CYAN = \"#95CBF3\";\n    string constant BLUE = \"#405AE5\";\n    string constant DARK_BLUE = \"#121B44\";\n    string constant BROWN = \"#D99664\";\n\n    enum colorCode {\n        GOLDEN,\n        CORAL,\n        GREEN,\n        CYAN,\n        BLUE,\n        DARK_BLUE,\n        BROWN\n    }\n\n    function _bauhaus(string memory _collName, uint256 _troveId) internal pure returns (string memory) {\n        bytes32 collSig = keccak256(bytes(_collName));\n        uint256 variant = _troveId % 4;\n        // Always use _img1 because in MentoV3 we only have one collateral token\n        return _img1(variant);\n    }\n\n    function _colorCode2Hex(colorCode _color) private pure returns (string memory) {\n        if (_color == colorCode.GOLDEN) {\n            return GOLDEN;\n        } else if (_color == colorCode.CORAL) {\n            return CORAL;\n        } else if (_color == colorCode.GREEN) {\n            return GREEN;\n        } else if (_color == colorCode.CYAN) {\n            return CYAN;\n        } else if (_color == colorCode.BLUE) {\n            return BLUE;\n        } else if (_color == colorCode.DARK_BLUE) {\n            return DARK_BLUE;\n        } else {\n            return BROWN;\n        }\n    }\n\n    struct COLORS {\n        colorCode rect1;\n        colorCode rect2;\n        colorCode rect3;\n        colorCode rect4;\n        colorCode rect5;\n        colorCode poly;\n        colorCode circle1;\n        colorCode circle2;\n        colorCode circle3;\n    }\n\n    function _colors1(uint256 _variant) internal pure returns (COLORS memory) {\n        if (_variant == 0) {\n            return COLORS(\n                colorCode.BLUE, // rect1\n                colorCode.GOLDEN, // rect2\n                colorCode.GOLDEN, // rect3\n                colorCode.BROWN, // rect4\n                colorCode.CORAL, // rect5\n                colorCode.CYAN, // poly\n                colorCode.GREEN, // circle1\n                colorCode.DARK_BLUE, // circle2\n                colorCode.GOLDEN // circle3\n            );\n        } else if (_variant == 1) {\n            return COLORS(\n                colorCode.GREEN, // rect1\n                colorCode.BLUE, // rect2\n                colorCode.GOLDEN, // rect3\n                colorCode.BROWN, // rect4\n                colorCode.GOLDEN, // rect5\n                colorCode.CORAL, // poly\n                colorCode.BLUE, // circle1\n                colorCode.DARK_BLUE, // circle2\n                colorCode.BLUE // circle3\n            );\n        } else if (_variant == 2) {\n            return COLORS(\n                colorCode.BLUE, // rect1\n                colorCode.GOLDEN, // rect2\n                colorCode.CYAN, // rect3\n                colorCode.GOLDEN, // rect4\n                colorCode.BROWN, // rect5\n                colorCode.GREEN, // poly\n                colorCode.CORAL, // circle1\n                colorCode.DARK_BLUE, // circle2\n                colorCode.BROWN // circle3\n            );\n        } else {\n            return COLORS(\n                colorCode.CYAN, // rect1\n                colorCode.BLUE, // rect2\n                colorCode.BLUE, // rect3\n                colorCode.BROWN, // rect4\n                colorCode.BLUE, // rect5\n                colorCode.GREEN, // poly\n                colorCode.GOLDEN, // circle1\n                colorCode.DARK_BLUE, // circle2\n                colorCode.BLUE // circle3\n            );\n        }\n    }\n\n    function _img1(uint256 _variant) internal pure returns (string memory) {\n        COLORS memory colors = _colors1(_variant);\n        return string.concat(_rects1(colors), _polygons1(colors), _circles1(colors));\n    }\n\n    function _rects1(COLORS memory _colors) internal pure returns (string memory) {\n        return string.concat(\n            //background\n            svg.rect(\n                string.concat(\n                    svg.prop(\"x\", \"16\"),\n                    svg.prop(\"y\", \"55\"),\n                    svg.prop(\"width\", \"268\"),\n                    svg.prop(\"height\", \"268\"),\n                    svg.prop(\"fill\", DARK_BLUE)\n                )\n            ),\n            // large right rect | rect1\n            svg.rect(\n                string.concat(\n                    svg.prop(\"x\", \"128\"),\n                    svg.prop(\"y\", \"55\"),\n                    svg.prop(\"width\", \"156\"),\n                    svg.prop(\"height\", \"268\"),\n                    svg.prop(\"fill\", _colorCode2Hex(_colors.rect1))\n                )\n            ),\n            // small upper right rect | rect2\n            svg.rect(\n                string.concat(\n                    svg.prop(\"x\", \"228\"),\n                    svg.prop(\"y\", \"55\"),\n                    svg.prop(\"width\", \"56\"),\n                    svg.prop(\"height\", \"56\"),\n                    svg.prop(\"fill\", _colorCode2Hex(_colors.rect2))\n                )\n            ),\n            // large central left rect | rect3\n            svg.rect(\n                string.concat(\n                    svg.prop(\"x\", \"16\"),\n                    svg.prop(\"y\", \"111\"),\n                    svg.prop(\"width\", \"134\"),\n                    svg.prop(\"height\", \"156\"),\n                    svg.prop(\"fill\", _colorCode2Hex(_colors.rect3))\n                )\n            ),\n            // small lower left rect | rect4\n            svg.rect(\n                string.concat(\n                    svg.prop(\"x\", \"16\"),\n                    svg.prop(\"y\", \"267\"),\n                    svg.prop(\"width\", \"112\"),\n                    svg.prop(\"height\", \"56\"),\n                    svg.prop(\"fill\", _colorCode2Hex(_colors.rect4))\n                )\n            ),\n            // small lower right rect | rect5\n            svg.rect(\n                string.concat(\n                    svg.prop(\"x\", \"228\"),\n                    svg.prop(\"y\", \"267\"),\n                    svg.prop(\"width\", \"56\"),\n                    svg.prop(\"height\", \"56\"),\n                    svg.prop(\"fill\", _colorCode2Hex(_colors.rect5))\n                )\n            )\n        );\n    }\n\n    function _polygons1(COLORS memory _colors) internal pure returns (string memory) {\n        return string.concat(\n            // left triangle | poly1\n            svg.polygon(\n                string.concat(svg.prop(\"points\", \"16,55 72,55 16,111\"), svg.prop(\"fill\", _colorCode2Hex(_colors.poly)))\n            ),\n            // right triangle | poly2\n            svg.polygon(\n                string.concat(svg.prop(\"points\", \"72,55 128,55 72,111\"), svg.prop(\"fill\", _colorCode2Hex(_colors.poly)))\n            )\n        );\n    }\n\n    function _circles1(COLORS memory _colors) internal pure returns (string memory) {\n        return string.concat(\n            //large central circle | circle1\n            svg.circle(\n                string.concat(\n                    svg.prop(\"cx\", \"150\"),\n                    svg.prop(\"cy\", \"189\"),\n                    svg.prop(\"r\", \"78\"),\n                    svg.prop(\"fill\", _colorCode2Hex(_colors.circle1))\n                )\n            ),\n            //small right circle | circle2\n            svg.circle(\n                string.concat(\n                    svg.prop(\"cx\", \"228\"),\n                    svg.prop(\"cy\", \"295\"),\n                    svg.prop(\"r\", \"28\"),\n                    svg.prop(\"fill\", _colorCode2Hex(_colors.circle2))\n                )\n            ),\n            //small right half circle | circle3\n            svg.path(\n                \"M228 267C220.574 267 213.452 269.95 208.201 275.201C202.95 280.452 200 287.574 200 295C200 302.426 202.95 309.548 208.201 314.799C213.452 320.05 220.574 323 228 323L228 267Z\",\n                svg.prop(\"fill\", _colorCode2Hex(_colors.circle3))\n            )\n        );\n    }\n\n    function _colors2(uint256 _variant) internal pure returns (COLORS memory) {\n        if (_variant == 0) {\n            return COLORS(\n                colorCode.BROWN, // rect1\n                colorCode.GOLDEN, // rect2\n                colorCode.BLUE, // rect3\n                colorCode.GREEN, // rect4\n                colorCode.CORAL, // rect5\n                colorCode.GOLDEN, // unused\n                colorCode.GOLDEN, // circle1\n                colorCode.CYAN, // circle2\n                colorCode.GREEN // circle3\n            );\n        } else if (_variant == 1) {\n            return COLORS(\n                colorCode.GREEN, // rect1\n                colorCode.BROWN, // rect2\n                colorCode.GOLDEN, // rect3\n                colorCode.BLUE, // rect4\n                colorCode.CYAN, // rect5\n                colorCode.GOLDEN, // unused\n                colorCode.GREEN, // circle1\n                colorCode.CORAL, // circle2\n                colorCode.BLUE // circle3\n            );\n        } else if (_variant == 2) {\n            return COLORS(\n                colorCode.BLUE, // rect1\n                colorCode.GOLDEN, // rect2\n                colorCode.GREEN, // rect3\n                colorCode.BLUE, // rect4\n                colorCode.CORAL, // rect5\n                colorCode.GOLDEN, // unused\n                colorCode.CYAN, // circle1\n                colorCode.BROWN, // circle2\n                colorCode.BROWN // circle3\n            );\n        } else {\n            return COLORS(\n                colorCode.GOLDEN, // rect1\n                colorCode.GREEN, // rect2\n                colorCode.BLUE, // rect3\n                colorCode.GOLDEN, // rect4\n                colorCode.BROWN, // rect5\n                colorCode.GOLDEN, // unused\n                colorCode.BROWN, // circle1\n                colorCode.CYAN, // circle2\n                colorCode.CORAL // circle3\n            );\n        }\n    }\n\n    function _img2(uint256 _variant) internal pure returns (string memory) {\n        COLORS memory colors = _colors2(_variant);\n        return string.concat(_rects2(colors), _circles2(colors));\n    }\n\n    function _rects2(COLORS memory _colors) internal pure returns (string memory) {\n        return string.concat(\n            //background\n            svg.rect(\n                string.concat(\n                    svg.prop(\"x\", \"16\"),\n                    svg.prop(\"y\", \"55\"),\n                    svg.prop(\"width\", \"268\"),\n                    svg.prop(\"height\", \"268\"),\n                    svg.prop(\"fill\", DARK_BLUE)\n                )\n            ),\n            // large upper right rect | rect1\n            svg.rect(\n                string.concat(\n                    svg.prop(\"x\", \"128\"),\n                    svg.prop(\"y\", \"55\"),\n                    svg.prop(\"width\", \"156\"),\n                    svg.prop(\"height\", \"156\"),\n                    svg.prop(\"fill\", _colorCode2Hex(_colors.rect1))\n                )\n            ),\n            // large central left rect | rect2\n            svg.rect(\n                string.concat(\n                    svg.prop(\"x\", \"16\"),\n                    svg.prop(\"y\", \"111\"),\n                    svg.prop(\"width\", \"134\"),\n                    svg.prop(\"height\", \"100\"),\n                    svg.prop(\"fill\", _colorCode2Hex(_colors.rect2))\n                )\n            ),\n            // large lower left rect | rect3\n            svg.rect(\n                string.concat(\n                    svg.prop(\"x\", \"16\"),\n                    svg.prop(\"y\", \"211\"),\n                    svg.prop(\"width\", \"212\"),\n                    svg.prop(\"height\", \"56\"),\n                    svg.prop(\"fill\", _colorCode2Hex(_colors.rect3))\n                )\n            ),\n            // small lower central rect | rect4\n            svg.rect(\n                string.concat(\n                    svg.prop(\"x\", \"72\"),\n                    svg.prop(\"y\", \"267\"),\n                    svg.prop(\"width\", \"78\"),\n                    svg.prop(\"height\", \"56\"),\n                    svg.prop(\"fill\", _colorCode2Hex(_colors.rect4))\n                )\n            ),\n            // small lower right rect | rect5\n            svg.rect(\n                string.concat(\n                    svg.prop(\"x\", \"150\"),\n                    svg.prop(\"y\", \"267\"),\n                    svg.prop(\"width\", \"134\"),\n                    svg.prop(\"height\", \"56\"),\n                    svg.prop(\"fill\", _colorCode2Hex(_colors.rect5))\n                )\n            )\n        );\n    }\n\n    function _circles2(COLORS memory _colors) internal pure returns (string memory) {\n        return string.concat(\n            //lower left circle | circle1\n            svg.circle(\n                string.concat(\n                    svg.prop(\"cx\", \"44\"),\n                    svg.prop(\"cy\", \"295\"),\n                    svg.prop(\"r\", \"28\"),\n                    svg.prop(\"fill\", _colorCode2Hex(_colors.circle1))\n                )\n            ),\n            //upper left half circle | circle2\n            svg.path(\n                \"M16 55C16 62.4 17.4 69.6 20.3 76.4C23.1 83.2 27.2 89.4 32.4 94.6C37.6 99.8 43.8 103.9 50.6 106.7C57.4 109.6 64.6 111 72 111C79.4 111 86.6 109.6 93.4 106.7C100.2 103.9 106.4 99.8 111.6 94.6C116.8 89.4 120.9 83.2 123.7 76.4C126.6 69.6 128 62.4 128 55L16 55Z\",\n                svg.prop(\"fill\", _colorCode2Hex(_colors.circle2))\n            ),\n            //central right half circle | circle3\n            svg.path(\n                \"M284 211C284 190.3 275.8 170.5 261.2 155.8C246.5 141.2 226.7 133 206 133C185.3 133 165.5 141.2 150.9 155.86C136.2 170.5 128 190.3 128 211L284 211Z\",\n                svg.prop(\"fill\", _colorCode2Hex(_colors.circle3))\n            )\n        );\n    }\n\n    function _colors3(uint256 _variant) internal pure returns (COLORS memory) {\n        if (_variant == 0) {\n            return COLORS(\n                colorCode.BLUE, // rect1\n                colorCode.CORAL, // rect2\n                colorCode.BLUE, // rect3\n                colorCode.GREEN, // rect4\n                colorCode.GOLDEN, // unused\n                colorCode.GOLDEN, // unused\n                colorCode.GOLDEN, // circle1\n                colorCode.CYAN, // circle2\n                colorCode.GOLDEN // circle3\n            );\n        } else if (_variant == 1) {\n            return COLORS(\n                colorCode.CORAL, // rect1\n                colorCode.GREEN, // rect2\n                colorCode.BROWN, // rect3\n                colorCode.GOLDEN, // rect4\n                colorCode.GOLDEN, // unused\n                colorCode.GOLDEN, // unused\n                colorCode.BLUE, // circle1\n                colorCode.BLUE, // circle2\n                colorCode.CYAN // circle3\n            );\n        } else if (_variant == 2) {\n            return COLORS(\n                colorCode.CORAL, // rect1\n                colorCode.CYAN, // rect2\n                colorCode.CORAL, // rect3\n                colorCode.GOLDEN, // rect4\n                colorCode.GOLDEN, // unused\n                colorCode.GOLDEN, // unused\n                colorCode.GREEN, // circle1\n                colorCode.BLUE, // circle2\n                colorCode.GREEN // circle3\n            );\n        } else {\n            return COLORS(\n                colorCode.GOLDEN, // rect1\n                colorCode.CORAL, // rect2\n                colorCode.GREEN, // rect3\n                colorCode.BLUE, // rect4\n                colorCode.GOLDEN, // unused\n                colorCode.GOLDEN, // unused\n                colorCode.BROWN, // circle1\n                colorCode.BLUE, // circle2\n                colorCode.GREEN // circle3\n            );\n        }\n    }\n\n    function _img3(uint256 _variant) internal pure returns (string memory) {\n        COLORS memory colors = _colors3(_variant);\n        return string.concat(_rects3(colors), _circles3(colors));\n    }\n\n    function _rects3(COLORS memory _colors) internal pure returns (string memory) {\n        return string.concat(\n            //background\n            svg.rect(\n                string.concat(\n                    svg.prop(\"x\", \"16\"),\n                    svg.prop(\"y\", \"55\"),\n                    svg.prop(\"width\", \"268\"),\n                    svg.prop(\"height\", \"268\"),\n                    svg.prop(\"fill\", DARK_BLUE)\n                )\n            ),\n            // lower left rect | rect1\n            svg.rect(\n                string.concat(\n                    svg.prop(\"x\", \"16\"),\n                    svg.prop(\"y\", \"205\"),\n                    svg.prop(\"width\", \"75\"),\n                    svg.prop(\"height\", \"118\"),\n                    svg.prop(\"fill\", _colorCode2Hex(_colors.rect1))\n                )\n            ),\n            // central rect | rect2\n            svg.rect(\n                string.concat(\n                    svg.prop(\"x\", \"91\"),\n                    svg.prop(\"y\", \"205\"),\n                    svg.prop(\"width\", \"136\"),\n                    svg.prop(\"height\", \"59\"),\n                    svg.prop(\"fill\", _colorCode2Hex(_colors.rect2))\n                )\n            ),\n            // central right rect | rect3\n            svg.rect(\n                string.concat(\n                    svg.prop(\"x\", \"166\"),\n                    svg.prop(\"y\", \"180\"),\n                    svg.prop(\"width\", \"118\"),\n                    svg.prop(\"height\", \"25\"),\n                    svg.prop(\"fill\", _colorCode2Hex(_colors.rect3))\n                )\n            ),\n            // upper right rect | rect4\n            svg.rect(\n                string.concat(\n                    svg.prop(\"x\", \"166\"),\n                    svg.prop(\"y\", \"55\"),\n                    svg.prop(\"width\", \"118\"),\n                    svg.prop(\"height\", \"126\"),\n                    svg.prop(\"fill\", _colorCode2Hex(_colors.rect4))\n                )\n            )\n        );\n    }\n\n    function _circles3(COLORS memory _colors) internal pure returns (string memory) {\n        return string.concat(\n            //upper left circle | circle1\n            svg.circle(\n                string.concat(\n                    svg.prop(\"cx\", \"91\"),\n                    svg.prop(\"cy\", \"130\"),\n                    svg.prop(\"r\", \"75\"),\n                    svg.prop(\"fill\", _colorCode2Hex(_colors.circle1))\n                )\n            ),\n            //upper right half circle | circle2\n            svg.path(\n                \"M284 264 166 264 166 263C166 232 193 206 225 205C258 206 284 232 284 264C284 264 284 264 284 264Z\",\n                svg.prop(\"fill\", _colorCode2Hex(_colors.circle2))\n            ),\n            //lower right half circle | circle3\n            svg.path(\n                \"M284 323 166 323 166 323C166 290 193 265 225 264C258 265 284 290 284 323C284 323 284 323 284 323Z\",\n                svg.prop(\"fill\", _colorCode2Hex(_colors.circle3))\n            )\n        );\n    }\n}\n"},{"file_path":"lib/bold/contracts/src/NFTMetadata/utils/baseSVG.sol","source_code":"//SPDX-License-Identifier: MIT\npragma solidity 0.8.24;\n\nimport {svg} from \"./SVG.sol\";\nimport {utils, LibString, numUtils} from \"./Utils.sol\";\nimport \"./FixedAssets.sol\";\n\nlibrary baseSVG {\n    string constant GEIST = 'style=\"font-family: Geist\" ';\n    string constant DARK_BLUE = \"#121B44\";\n    string constant STOIC_WHITE = \"#DEE4FB\";\n\n    function _svgProps() internal pure returns (string memory) {\n        return string.concat(\n            svg.prop(\"width\", \"300\"),\n            svg.prop(\"height\", \"484\"),\n            svg.prop(\"viewBox\", \"0 0 300 484\"),\n            svg.prop(\"style\", \"background:none\")\n        );\n    }\n\n    function _baseElements(FixedAssetReader _assetReader) internal view returns (string memory) {\n        return string.concat(\n            svg.rect(\n                string.concat(\n                    svg.prop(\"fill\", DARK_BLUE),\n                    svg.prop(\"rx\", \"8\"),\n                    svg.prop(\"width\", \"300\"),\n                    svg.prop(\"height\", \"484\")\n                )\n            ),\n            _styles(_assetReader),\n            _leverageLogo(),\n            _boldLogo(_assetReader),\n            _staticTextEls()\n        );\n    }\n\n    function _styles(FixedAssetReader _assetReader) private view returns (string memory) {\n        return svg.el(\n            \"style\",\n            utils.NULL,\n            string.concat(\n                '@font-face { font-family: \"Geist\"; src: url(\"data:font/woff2;utf-8;base64,',\n                _assetReader.readAsset(bytes4(keccak256(\"geist\"))),\n                '\"); }'\n            )\n        );\n    }\n\n    function _leverageLogo() internal pure returns (string memory) {\n        return string.concat(\n            svg.path(\n                \"M20.2 31.2C19.1 32.4 17.6 33 16 33L16 21C17.6 21 19.1 21.6 20.2 22.7C21.4 23.9 22 25.4 22 27C22 28.6 21.4 30.1 20.2 31.2Z\",\n                svg.prop(\"fill\", STOIC_WHITE)\n            ),\n            svg.path(\n                \"M22 27C22 25.4 22.6 23.9 23.8 22.7C25 21.6 26.4 21 28 21V33C26.4 33 25 32.4 24 31.2C22.6 30.1 22 28.6 22 27Z\",\n                svg.prop(\"fill\", STOIC_WHITE)\n            )\n        );\n    }\n\n    function _boldLogo(FixedAssetReader _assetReader) internal view returns (string memory) {\n        return svg.el(\n            \"image\",\n            string.concat(\n                svg.prop(\"x\", \"264\"),\n                svg.prop(\"y\", \"373.5\"),\n                svg.prop(\"width\", \"20\"),\n                svg.prop(\"height\", \"20\"),\n                svg.prop(\n                    \"href\",\n                    string.concat(\"data:image/svg+xml;base64,\", _assetReader.readAsset(bytes4(keccak256(\"BOLD\"))))\n                )\n            )\n        );\n    }\n\n    function _staticTextEls() internal pure returns (string memory) {\n        return string.concat(\n            svg.text(\n                string.concat(\n                    GEIST,\n                    svg.prop(\"x\", \"16\"),\n                    svg.prop(\"y\", \"358\"),\n                    svg.prop(\"font-size\", \"14\"),\n                    svg.prop(\"fill\", \"white\")\n                ),\n                \"Collateral\"\n            ),\n            svg.text(\n                string.concat(\n                    GEIST,\n                    svg.prop(\"x\", \"16\"),\n                    svg.prop(\"y\", \"389\"),\n                    svg.prop(\"font-size\", \"14\"),\n                    svg.prop(\"fill\", \"white\")\n                ),\n                \"Debt\"\n            ),\n            svg.text(\n                string.concat(\n                    GEIST,\n                    svg.prop(\"x\", \"16\"),\n                    svg.prop(\"y\", \"420\"),\n                    svg.prop(\"font-size\", \"14\"),\n                    svg.prop(\"fill\", \"white\")\n                ),\n                \"Interest Rate\"\n            ),\n            svg.text(\n                string.concat(\n                    GEIST,\n                    svg.prop(\"x\", \"265\"),\n                    svg.prop(\"y\", \"422\"),\n                    svg.prop(\"font-size\", \"20\"),\n                    svg.prop(\"fill\", \"white\")\n                ),\n                \"%\"\n            ),\n            svg.text(\n                string.concat(\n                    GEIST,\n                    svg.prop(\"x\", \"16\"),\n                    svg.prop(\"y\", \"462\"),\n                    svg.prop(\"font-size\", \"14\"),\n                    svg.prop(\"fill\", \"white\")\n                ),\n                \"Owner\"\n            )\n        );\n    }\n\n    function _formattedDynamicEl(string memory _value, uint256 _x, uint256 _y) internal pure returns (string memory) {\n        return svg.text(\n            string.concat(\n                GEIST,\n                svg.prop(\"text-anchor\", \"end\"),\n                svg.prop(\"x\", LibString.toString(_x)),\n                svg.prop(\"y\", LibString.toString(_y)),\n                svg.prop(\"font-size\", \"20\"),\n                svg.prop(\"fill\", \"white\")\n            ),\n            _value\n        );\n    }\n\n    function _formattedIdEl(string memory _id) internal pure returns (string memory) {\n        return svg.text(\n            string.concat(\n                GEIST,\n                svg.prop(\"text-anchor\", \"end\"),\n                svg.prop(\"x\", \"284\"),\n                svg.prop(\"y\", \"33\"),\n                svg.prop(\"font-size\", \"14\"),\n                svg.prop(\"fill\", \"white\")\n            ),\n            _id\n        );\n    }\n\n    function _formattedAddressEl(address _address) internal pure returns (string memory) {\n        return svg.text(\n            string.concat(\n                GEIST,\n                svg.prop(\"text-anchor\", \"end\"),\n                svg.prop(\"x\", \"284\"),\n                svg.prop(\"y\", \"462\"),\n                svg.prop(\"font-size\", \"14\"),\n                svg.prop(\"fill\", \"white\")\n            ),\n            string.concat(\n                LibString.slice(LibString.toHexStringChecksummed(_address), 0, 6),\n                \"...\",\n                LibString.slice(LibString.toHexStringChecksummed(_address), 38, 42)\n            )\n        );\n    }\n\n    function _collLogo(string memory _collName, FixedAssetReader _assetReader) internal view returns (string memory) {\n        return svg.el(\n            \"image\",\n            string.concat(\n                svg.prop(\"x\", \"264\"),\n                svg.prop(\"y\", \"342.5\"),\n                svg.prop(\"width\", \"20\"),\n                svg.prop(\"height\", \"20\"),\n                svg.prop(\n                    \"href\",\n                    string.concat(\n                        \"data:image/svg+xml;base64,\", _assetReader.readAsset(bytes4(keccak256(bytes(_collName))))\n                    )\n                )\n            )\n        );\n    }\n\n    function _statusEl(string memory _status) internal pure returns (string memory) {\n        return svg.text(\n            string.concat(\n                GEIST, svg.prop(\"x\", \"40\"), svg.prop(\"y\", \"33\"), svg.prop(\"font-size\", \"14\"), svg.prop(\"fill\", \"white\")\n            ),\n            _status\n        );\n    }\n\n    function _dynamicTextEls(uint256 _debt, uint256 _coll, uint256 _annualInterestRate)\n        internal\n        pure\n        returns (string memory)\n    {\n        return string.concat(\n            _formattedDynamicEl(numUtils.toLocaleString(_coll, 18, 4), 256, 360),\n            _formattedDynamicEl(numUtils.toLocaleString(_debt, 18, 2), 256, 391),\n            _formattedDynamicEl(numUtils.toLocaleString(_annualInterestRate, 16, 2), 256, 422)\n        );\n    }\n}\n"},{"file_path":"lib/bold/contracts/lib/Solady/src/utils/LibString.sol","source_code":"// SPDX-License-Identifier: MIT\npragma solidity ^0.8.4;\n\n/// @notice Library for converting numbers into strings and other string operations.\n/// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/LibString.sol)\n/// @author Modified from Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/LibString.sol)\n///\n/// @dev Note:\n/// For performance and bytecode compactness, most of the string operations are restricted to\n/// byte strings (7-bit ASCII), except where otherwise specified.\n/// Usage of byte string operations on charsets with runes spanning two or more bytes\n/// can lead to undefined behavior.\nlibrary LibString {\n    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/\n    /*                        CUSTOM ERRORS                       */\n    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/\n\n    /// @dev The length of the output is too small to contain all the hex digits.\n    error HexLengthInsufficient();\n\n    /// @dev The length of the string is more than 32 bytes.\n    error TooBigForSmallString();\n\n    /// @dev The input string must be a 7-bit ASCII.\n    error StringNot7BitASCII();\n\n    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/\n    /*                         CONSTANTS                          */\n    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/\n\n    /// @dev The constant returned when the `search` is not found in the string.\n    uint256 internal constant NOT_FOUND = type(uint256).max;\n\n    /// @dev Lookup for '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.\n    uint128 internal constant ALPHANUMERIC_7_BIT_ASCII = 0x7fffffe07fffffe03ff000000000000;\n\n    /// @dev Lookup for 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.\n    uint128 internal constant LETTERS_7_BIT_ASCII = 0x7fffffe07fffffe0000000000000000;\n\n    /// @dev Lookup for 'abcdefghijklmnopqrstuvwxyz'.\n    uint128 internal constant LOWERCASE_7_BIT_ASCII = 0x7fffffe000000000000000000000000;\n\n    /// @dev Lookup for 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.\n    uint128 internal constant UPPERCASE_7_BIT_ASCII = 0x7fffffe0000000000000000;\n\n    /// @dev Lookup for '0123456789'.\n    uint128 internal constant DIGITS_7_BIT_ASCII = 0x3ff000000000000;\n\n    /// @dev Lookup for '0123456789abcdefABCDEF'.\n    uint128 internal constant HEXDIGITS_7_BIT_ASCII = 0x7e0000007e03ff000000000000;\n\n    /// @dev Lookup for '01234567'.\n    uint128 internal constant OCTDIGITS_7_BIT_ASCII = 0xff000000000000;\n\n    /// @dev Lookup for '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!\"#$%&\\'()*+,-./:;<=>?@[\\\\]^_`{|}~ \\t\\n\\r\\x0b\\x0c'.\n    uint128 internal constant PRINTABLE_7_BIT_ASCII = 0x7fffffffffffffffffffffff00003e00;\n\n    /// @dev Lookup for '!\"#$%&\\'()*+,-./:;<=>?@[\\\\]^_`{|}~'.\n    uint128 internal constant PUNCTUATION_7_BIT_ASCII = 0x78000001f8000001fc00fffe00000000;\n\n    /// @dev Lookup for ' \\t\\n\\r\\x0b\\x0c'.\n    uint128 internal constant WHITESPACE_7_BIT_ASCII = 0x100003e00;\n\n    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/\n    /*                     DECIMAL OPERATIONS                     */\n    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/\n\n    /// @dev Returns the base 10 decimal representation of `value`.\n    function toString(uint256 value) internal pure returns (string memory str) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            // The maximum value of a uint256 contains 78 digits (1 byte per digit), but\n            // we allocate 0xa0 bytes to keep the free memory pointer 32-byte word aligned.\n            // We will need 1 word for the trailing zeros padding, 1 word for the length,\n            // and 3 words for a maximum of 78 digits.\n            str := add(mload(0x40), 0x80)\n            mstore(0x40, add(str, 0x20)) // Allocate the memory.\n            mstore(str, 0) // Zeroize the slot after the string.\n\n            let end := str // Cache the end of the memory to calculate the length later.\n            let w := not(0) // Tsk.\n            // We write the string from rightmost digit to leftmost digit.\n            // The following is essentially a do-while loop that also handles the zero case.\n            for { let temp := value } 1 {} {\n                str := add(str, w) // `sub(str, 1)`.\n                // Store the character to the pointer.\n                // The ASCII index of the '0' character is 48.\n                mstore8(str, add(48, mod(temp, 10)))\n                temp := div(temp, 10) // Keep dividing `temp` until zero.\n                if iszero(temp) { break }\n            }\n            let length := sub(end, str)\n            str := sub(str, 0x20) // Move the pointer 32 bytes back to make room for the length.\n            mstore(str, length) // Store the length.\n        }\n    }\n\n    /// @dev Returns the base 10 decimal representation of `value`.\n    function toString(int256 value) internal pure returns (string memory str) {\n        if (value >= 0) return toString(uint256(value));\n        unchecked {\n            str = toString(~uint256(value) + 1);\n        }\n        /// @solidity memory-safe-assembly\n        assembly {\n            // We still have some spare memory space on the left,\n            // as we have allocated 3 words (96 bytes) for up to 78 digits.\n            let length := mload(str) // Load the string length.\n            mstore(str, 0x2d) // Store the '-' character.\n            str := sub(str, 1) // Move back the string pointer by a byte.\n            mstore(str, add(length, 1)) // Update the string length.\n        }\n    }\n\n    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/\n    /*                   HEXADECIMAL OPERATIONS                   */\n    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/\n\n    /// @dev Returns the hexadecimal representation of `value`,\n    /// left-padded to an input length of `length` bytes.\n    /// The output is prefixed with \"0x\" encoded using 2 hexadecimal digits per byte,\n    /// giving a total length of `length * 2 + 2` bytes.\n    /// Reverts if `length` is too small for the output to contain all the digits.\n    function toHexString(uint256 value, uint256 length) internal pure returns (string memory str) {\n        str = toHexStringNoPrefix(value, length);\n        /// @solidity memory-safe-assembly\n        assembly {\n            let strLength := add(mload(str), 2) // Compute the length.\n            mstore(str, 0x3078) // Store the \"0x\" prefix.\n            str := sub(str, 2) // Move the pointer.\n            mstore(str, strLength) // Store the length.\n        }\n    }\n\n    /// @dev Returns the hexadecimal representation of `value`,\n    /// left-padded to an input length of `length` bytes.\n    /// The output is prefixed with \"0x\" encoded using 2 hexadecimal digits per byte,\n    /// giving a total length of `length * 2` bytes.\n    /// Reverts if `length` is too small for the output to contain all the digits.\n    function toHexStringNoPrefix(uint256 value, uint256 length)\n        internal\n        pure\n        returns (string memory str)\n    {\n        /// @solidity memory-safe-assembly\n        assembly {\n            // We need 0x20 bytes for the trailing zeros padding, `length * 2` bytes\n            // for the digits, 0x02 bytes for the prefix, and 0x20 bytes for the length.\n            // We add 0x20 to the total and round down to a multiple of 0x20.\n            // (0x20 + 0x20 + 0x02 + 0x20) = 0x62.\n            str := add(mload(0x40), and(add(shl(1, length), 0x42), not(0x1f)))\n            mstore(0x40, add(str, 0x20)) // Allocate the memory.\n            mstore(str, 0) // Zeroize the slot after the string.\n\n            let end := str // Cache the end to calculate the length later.\n            // Store \"0123456789abcdef\" in scratch space.\n            mstore(0x0f, 0x30313233343536373839616263646566)\n\n            let start := sub(str, add(length, length))\n            let w := not(1) // Tsk.\n            let temp := value\n            // We write the string from rightmost digit to leftmost digit.\n            // The following is essentially a do-while loop that also handles the zero case.\n            for {} 1 {} {\n                str := add(str, w) // `sub(str, 2)`.\n                mstore8(add(str, 1), mload(and(temp, 15)))\n                mstore8(str, mload(and(shr(4, temp), 15)))\n                temp := shr(8, temp)\n                if iszero(xor(str, start)) { break }\n            }\n            if temp {\n                mstore(0x00, 0x2194895a) // `HexLengthInsufficient()`.\n                revert(0x1c, 0x04)\n            }\n            let strLength := sub(end, str)\n            str := sub(str, 0x20)\n            mstore(str, strLength) // Store the length.\n        }\n    }\n\n    /// @dev Returns the hexadecimal representation of `value`.\n    /// The output is prefixed with \"0x\" and encoded using 2 hexadecimal digits per byte.\n    /// As address are 20 bytes long, the output will left-padded to have\n    /// a length of `20 * 2 + 2` bytes.\n    function toHexString(uint256 value) internal pure returns (string memory str) {\n        str = toHexStringNoPrefix(value);\n        /// @solidity memory-safe-assembly\n        assembly {\n            let strLength := add(mload(str), 2) // Compute the length.\n            mstore(str, 0x3078) // Store the \"0x\" prefix.\n            str := sub(str, 2) // Move the pointer.\n            mstore(str, strLength) // Store the length.\n        }\n    }\n\n    /// @dev Returns the hexadecimal representation of `value`.\n    /// The output is prefixed with \"0x\".\n    /// The output excludes leading \"0\" from the `toHexString` output.\n    /// `0x00: \"0x0\", 0x01: \"0x1\", 0x12: \"0x12\", 0x123: \"0x123\"`.\n    function toMinimalHexString(uint256 value) internal pure returns (string memory str) {\n        str = toHexStringNoPrefix(value);\n        /// @solidity memory-safe-assembly\n        assembly {\n            let o := eq(byte(0, mload(add(str, 0x20))), 0x30) // Whether leading zero is present.\n            let strLength := add(mload(str), 2) // Compute the length.\n            mstore(add(str, o), 0x3078) // Store the \"0x\" prefix, accounting for leading zero.\n            str := sub(add(str, o), 2) // Move the pointer, accounting for leading zero.\n            mstore(str, sub(strLength, o)) // Store the length, accounting for leading zero.\n        }\n    }\n\n    /// @dev Returns the hexadecimal representation of `value`.\n    /// The output excludes leading \"0\" from the `toHexStringNoPrefix` output.\n    /// `0x00: \"0\", 0x01: \"1\", 0x12: \"12\", 0x123: \"123\"`.\n    function toMinimalHexStringNoPrefix(uint256 value) internal pure returns (string memory str) {\n        str = toHexStringNoPrefix(value);\n        /// @solidity memory-safe-assembly\n        assembly {\n            let o := eq(byte(0, mload(add(str, 0x20))), 0x30) // Whether leading zero is present.\n            let strLength := mload(str) // Get the length.\n            str := add(str, o) // Move the pointer, accounting for leading zero.\n            mstore(str, sub(strLength, o)) // Store the length, accounting for leading zero.\n        }\n    }\n\n    /// @dev Returns the hexadecimal representation of `value`.\n    /// The output is encoded using 2 hexadecimal digits per byte.\n    /// As address are 20 bytes long, the output will left-padded to have\n    /// a length of `20 * 2` bytes.\n    function toHexStringNoPrefix(uint256 value) internal pure returns (string memory str) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            // We need 0x20 bytes for the trailing zeros padding, 0x20 bytes for the length,\n            // 0x02 bytes for the prefix, and 0x40 bytes for the digits.\n            // The next multiple of 0x20 above (0x20 + 0x20 + 0x02 + 0x40) is 0xa0.\n            str := add(mload(0x40), 0x80)\n            mstore(0x40, add(str, 0x20)) // Allocate the memory.\n            mstore(str, 0) // Zeroize the slot after the string.\n\n            let end := str // Cache the end to calculate the length later.\n            mstore(0x0f, 0x30313233343536373839616263646566) // Store the \"0123456789abcdef\" lookup.\n\n            let w := not(1) // Tsk.\n            // We write the string from rightmost digit to leftmost digit.\n            // The following is essentially a do-while loop that also handles the zero case.\n            for { let temp := value } 1 {} {\n                str := add(str, w) // `sub(str, 2)`.\n                mstore8(add(str, 1), mload(and(temp, 15)))\n                mstore8(str, mload(and(shr(4, temp), 15)))\n                temp := shr(8, temp)\n                if iszero(temp) { break }\n            }\n            let strLength := sub(end, str)\n            str := sub(str, 0x20)\n            mstore(str, strLength) // Store the length.\n        }\n    }\n\n    /// @dev Returns the hexadecimal representation of `value`.\n    /// The output is prefixed with \"0x\", encoded using 2 hexadecimal digits per byte,\n    /// and the alphabets are capitalized conditionally according to\n    /// https://eips.ethereum.org/EIPS/eip-55\n    function toHexStringChecksummed(address value) internal pure returns (string memory str) {\n        str = toHexString(value);\n        /// @solidity memory-safe-assembly\n        assembly {\n            let mask := shl(6, div(not(0), 255)) // `0b010000000100000000 ...`\n            let o := add(str, 0x22)\n            let hashed := and(keccak256(o, 40), mul(34, mask)) // `0b10001000 ... `\n            let t := shl(240, 136) // `0b10001000 << 240`\n            for { let i := 0 } 1 {} {\n                mstore(add(i, i), mul(t, byte(i, hashed)))\n                i := add(i, 1)\n                if eq(i, 20) { break }\n            }\n            mstore(o, xor(mload(o), shr(1, and(mload(0x00), and(mload(o), mask)))))\n            o := add(o, 0x20)\n            mstore(o, xor(mload(o), shr(1, and(mload(0x20), and(mload(o), mask)))))\n        }\n    }\n\n    /// @dev Returns the hexadecimal representation of `value`.\n    /// The output is prefixed with \"0x\" and encoded using 2 hexadecimal digits per byte.\n    function toHexString(address value) internal pure returns (string memory str) {\n        str = toHexStringNoPrefix(value);\n        /// @solidity memory-safe-assembly\n        assembly {\n            let strLength := add(mload(str), 2) // Compute the length.\n            mstore(str, 0x3078) // Store the \"0x\" prefix.\n            str := sub(str, 2) // Move the pointer.\n            mstore(str, strLength) // Store the length.\n        }\n    }\n\n    /// @dev Returns the hexadecimal representation of `value`.\n    /// The output is encoded using 2 hexadecimal digits per byte.\n    function toHexStringNoPrefix(address value) internal pure returns (string memory str) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            str := mload(0x40)\n            // Allocate the memory.\n            // We need 0x20 bytes for the trailing zeros padding, 0x20 bytes for the length,\n            // 0x02 bytes for the prefix, and 0x28 bytes for the digits.\n            // The next multiple of 0x20 above (0x20 + 0x20 + 0x02 + 0x28) is 0x80.\n            mstore(0x40, add(str, 0x80))\n            mstore(0x0f, 0x30313233343536373839616263646566) // Store the \"0123456789abcdef\" lookup.\n\n            str := add(str, 2)\n            mstore(str, 40) // Store the length.\n            let o := add(str, 0x20)\n            mstore(add(o, 40), 0) // Zeroize the slot after the string.\n            value := shl(96, value)\n            // We write the string from rightmost digit to leftmost digit.\n            // The following is essentially a do-while loop that also handles the zero case.\n            for { let i := 0 } 1 {} {\n                let p := add(o, add(i, i))\n                let temp := byte(i, value)\n                mstore8(add(p, 1), mload(and(temp, 15)))\n                mstore8(p, mload(shr(4, temp)))\n                i := add(i, 1)\n                if eq(i, 20) { break }\n            }\n        }\n    }\n\n    /// @dev Returns the hex encoded string from the raw bytes.\n    /// The output is encoded using 2 hexadecimal digits per byte.\n    function toHexString(bytes memory raw) internal pure returns (string memory str) {\n        str = toHexStringNoPrefix(raw);\n        /// @solidity memory-safe-assembly\n        assembly {\n            let strLength := add(mload(str), 2) // Compute the length.\n            mstore(str, 0x3078) // Store the \"0x\" prefix.\n            str := sub(str, 2) // Move the pointer.\n            mstore(str, strLength) // Store the length.\n        }\n    }\n\n    /// @dev Returns the hex encoded string from the raw bytes.\n    /// The output is encoded using 2 hexadecimal digits per byte.\n    function toHexStringNoPrefix(bytes memory raw) internal pure returns (string memory str) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            let length := mload(raw)\n            str := add(mload(0x40), 2) // Skip 2 bytes for the optional prefix.\n            mstore(str, add(length, length)) // Store the length of the output.\n\n            mstore(0x0f, 0x30313233343536373839616263646566) // Store the \"0123456789abcdef\" lookup.\n            let o := add(str, 0x20)\n            let end := add(raw, length)\n            for {} iszero(eq(raw, end)) {} {\n                raw := add(raw, 1)\n                mstore8(add(o, 1), mload(and(mload(raw), 15)))\n                mstore8(o, mload(and(shr(4, mload(raw)), 15)))\n                o := add(o, 2)\n            }\n            mstore(o, 0) // Zeroize the slot after the string.\n            mstore(0x40, add(o, 0x20)) // Allocate the memory.\n        }\n    }\n\n    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/\n    /*                   RUNE STRING OPERATIONS                   */\n    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/\n\n    /// @dev Returns the number of UTF characters in the string.\n    function runeCount(string memory s) internal pure returns (uint256 result) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            if mload(s) {\n                mstore(0x00, div(not(0), 255))\n                mstore(0x20, 0x0202020202020202020202020202020202020202020202020303030304040506)\n                let o := add(s, 0x20)\n                let end := add(o, mload(s))\n                for { result := 1 } 1 { result := add(result, 1) } {\n                    o := add(o, byte(0, mload(shr(250, mload(o)))))\n                    if iszero(lt(o, end)) { break }\n                }\n            }\n        }\n    }\n\n    /// @dev Returns if this string is a 7-bit ASCII string.\n    /// (i.e. all characters codes are in [0..127])\n    function is7BitASCII(string memory s) internal pure returns (bool result) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            let mask := shl(7, div(not(0), 255))\n            result := 1\n            let n := mload(s)\n            if n {\n                let o := add(s, 0x20)\n                let end := add(o, n)\n                let last := mload(end)\n                mstore(end, 0)\n                for {} 1 {} {\n                    if and(mask, mload(o)) {\n                        result := 0\n                        break\n                    }\n                    o := add(o, 0x20)\n                    if iszero(lt(o, end)) { break }\n                }\n                mstore(end, last)\n            }\n        }\n    }\n\n    /// @dev Returns if this string is a 7-bit ASCII string,\n    /// AND all characters are in the `allowed` lookup.\n    /// Note: If `s` is empty, returns true regardless of `allowed`.\n    function is7BitASCII(string memory s, uint128 allowed) internal pure returns (bool result) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            result := 1\n            if mload(s) {\n                let allowed_ := shr(128, shl(128, allowed))\n                let o := add(s, 0x20)\n                let end := add(o, mload(s))\n                for {} 1 {} {\n                    result := and(result, shr(byte(0, mload(o)), allowed_))\n                    o := add(o, 1)\n                    if iszero(and(result, lt(o, end))) { break }\n                }\n            }\n        }\n    }\n\n    /// @dev Converts the bytes in the 7-bit ASCII string `s` to\n    /// an allowed lookup for use in `is7BitASCII(s, allowed)`.\n    /// To save runtime gas, you can cache the result in an immutable variable.\n    function to7BitASCIIAllowedLookup(string memory s) internal pure returns (uint128 result) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            if mload(s) {\n                let o := add(s, 0x20)\n                let end := add(o, mload(s))\n                for {} 1 {} {\n                    result := or(result, shl(byte(0, mload(o)), 1))\n                    o := add(o, 1)\n                    if iszero(lt(o, end)) { break }\n                }\n                if shr(128, result) {\n                    mstore(0x00, 0xc9807e0d) // `StringNot7BitASCII()`.\n                    revert(0x1c, 0x04)\n                }\n            }\n        }\n    }\n\n    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/\n    /*                   BYTE STRING OPERATIONS                   */\n    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/\n\n    // For performance and bytecode compactness, byte string operations are restricted\n    // to 7-bit ASCII strings. All offsets are byte offsets, not UTF character offsets.\n    // Usage of byte string operations on charsets with runes spanning two or more bytes\n    // can lead to undefined behavior.\n\n    /// @dev Returns `subject` all occurrences of `search` replaced with `replacement`.\n    function replace(string memory subject, string memory search, string memory replacement)\n        internal\n        pure\n        returns (string memory result)\n    {\n        /// @solidity memory-safe-assembly\n        assembly {\n            let subjectLength := mload(subject)\n            let searchLength := mload(search)\n            let replacementLength := mload(replacement)\n\n            subject := add(subject, 0x20)\n            search := add(search, 0x20)\n            replacement := add(replacement, 0x20)\n            result := add(mload(0x40), 0x20)\n\n            let subjectEnd := add(subject, subjectLength)\n            if iszero(gt(searchLength, subjectLength)) {\n                let subjectSearchEnd := add(sub(subjectEnd, searchLength), 1)\n                let h := 0\n                if iszero(lt(searchLength, 0x20)) { h := keccak256(search, searchLength) }\n                let m := shl(3, sub(0x20, and(searchLength, 0x1f)))\n                let s := mload(search)\n                for {} 1 {} {\n                    let t := mload(subject)\n                    // Whether the first `searchLength % 32` bytes of\n                    // `subject` and `search` matches.\n                    if iszero(shr(m, xor(t, s))) {\n                        if h {\n                            if iszero(eq(keccak256(subject, searchLength), h)) {\n                                mstore(result, t)\n                                result := add(result, 1)\n                                subject := add(subject, 1)\n                                if iszero(lt(subject, subjectSearchEnd)) { break }\n                                continue\n                            }\n                        }\n                        // Copy the `replacement` one word at a time.\n                        for { let o := 0 } 1 {} {\n                            mstore(add(result, o), mload(add(replacement, o)))\n                            o := add(o, 0x20)\n                            if iszero(lt(o, replacementLength)) { break }\n                        }\n                        result := add(result, replacementLength)\n                        subject := add(subject, searchLength)\n                        if searchLength {\n                            if iszero(lt(subject, subjectSearchEnd)) { break }\n                            continue\n                        }\n                    }\n                    mstore(result, t)\n                    result := add(result, 1)\n                    subject := add(subject, 1)\n                    if iszero(lt(subject, subjectSearchEnd)) { break }\n                }\n            }\n\n            let resultRemainder := result\n            result := add(mload(0x40), 0x20)\n            let k := add(sub(resultRemainder, result), sub(subjectEnd, subject))\n            // Copy the rest of the string one word at a time.\n            for {} lt(subject, subjectEnd) {} {\n                mstore(resultRemainder, mload(subject))\n                resultRemainder := add(resultRemainder, 0x20)\n                subject := add(subject, 0x20)\n            }\n            result := sub(result, 0x20)\n            let last := add(add(result, 0x20), k) // Zeroize the slot after the string.\n            mstore(last, 0)\n            mstore(0x40, add(last, 0x20)) // Allocate the memory.\n            mstore(result, k) // Store the length.\n        }\n    }\n\n    /// @dev Returns the byte index of the first location of `search` in `subject`,\n    /// searching from left to right, starting from `from`.\n    /// Returns `NOT_FOUND` (i.e. `type(uint256).max`) if the `search` is not found.\n    function indexOf(string memory subject, string memory search, uint256 from)\n        internal\n        pure\n        returns (uint256 result)\n    {\n        /// @solidity memory-safe-assembly\n        assembly {\n            for { let subjectLength := mload(subject) } 1 {} {\n                if iszero(mload(search)) {\n                    if iszero(gt(from, subjectLength)) {\n                        result := from\n                        break\n                    }\n                    result := subjectLength\n                    break\n                }\n                let searchLength := mload(search)\n                let subjectStart := add(subject, 0x20)\n\n                result := not(0) // Initialize to `NOT_FOUND`.\n                subject := add(subjectStart, from)\n                let end := add(sub(add(subjectStart, subjectLength), searchLength), 1)\n\n                let m := shl(3, sub(0x20, and(searchLength, 0x1f)))\n                let s := mload(add(search, 0x20))\n\n                if iszero(and(lt(subject, end), lt(from, subjectLength))) { break }\n\n                if iszero(lt(searchLength, 0x20)) {\n                    for { let h := keccak256(add(search, 0x20), searchLength) } 1 {} {\n                        if iszero(shr(m, xor(mload(subject), s))) {\n                            if eq(keccak256(subject, searchLength), h) {\n                                result := sub(subject, subjectStart)\n                                break\n                            }\n                        }\n                        subject := add(subject, 1)\n                        if iszero(lt(subject, end)) { break }\n                    }\n                    break\n                }\n                for {} 1 {} {\n                    if iszero(shr(m, xor(mload(subject), s))) {\n                        result := sub(subject, subjectStart)\n                        break\n                    }\n                    subject := add(subject, 1)\n                    if iszero(lt(subject, end)) { break }\n                }\n                break\n            }\n        }\n    }\n\n    /// @dev Returns the byte index of the first location of `search` in `subject`,\n    /// searching from left to right.\n    /// Returns `NOT_FOUND` (i.e. `type(uint256).max`) if the `search` is not found.\n    function indexOf(string memory subject, string memory search)\n        internal\n        pure\n        returns (uint256 result)\n    {\n        result = indexOf(subject, search, 0);\n    }\n\n    /// @dev Returns the byte index of the first location of `search` in `subject`,\n    /// searching from right to left, starting from `from`.\n    /// Returns `NOT_FOUND` (i.e. `type(uint256).max`) if the `search` is not found.\n    function lastIndexOf(string memory subject, string memory search, uint256 from)\n        internal\n        pure\n        returns (uint256 result)\n    {\n        /// @solidity memory-safe-assembly\n        assembly {\n            for {} 1 {} {\n                result := not(0) // Initialize to `NOT_FOUND`.\n                let searchLength := mload(search)\n                if gt(searchLength, mload(subject)) { break }\n                let w := result\n\n                let fromMax := sub(mload(subject), searchLength)\n                if iszero(gt(fromMax, from)) { from := fromMax }\n\n                let end := add(add(subject, 0x20), w)\n                subject := add(add(subject, 0x20), from)\n                if iszero(gt(subject, end)) { break }\n                // As this function is not too often used,\n                // we shall simply use keccak256 for smaller bytecode size.\n                for { let h := keccak256(add(search, 0x20), searchLength) } 1 {} {\n                    if eq(keccak256(subject, searchLength), h) {\n                        result := sub(subject, add(end, 1))\n                        break\n                    }\n                    subject := add(subject, w) // `sub(subject, 1)`.\n                    if iszero(gt(subject, end)) { break }\n                }\n                break\n            }\n        }\n    }\n\n    /// @dev Returns the byte index of the first location of `search` in `subject`,\n    /// searching from right to left.\n    /// Returns `NOT_FOUND` (i.e. `type(uint256).max`) if the `search` is not found.\n    function lastIndexOf(string memory subject, string memory search)\n        internal\n        pure\n        returns (uint256 result)\n    {\n        result = lastIndexOf(subject, search, uint256(int256(-1)));\n    }\n\n    /// @dev Returns true if `search` is found in `subject`, false otherwise.\n    function contains(string memory subject, string memory search) internal pure returns (bool) {\n        return indexOf(subject, search) != NOT_FOUND;\n    }\n\n    /// @dev Returns whether `subject` starts with `search`.\n    function startsWith(string memory subject, string memory search)\n        internal\n        pure\n        returns (bool result)\n    {\n        /// @solidity memory-safe-assembly\n        assembly {\n            let searchLength := mload(search)\n            // Just using keccak256 directly is actually cheaper.\n            // forgefmt: disable-next-item\n            result := and(\n                iszero(gt(searchLength, mload(subject))),\n                eq(\n                    keccak256(add(subject, 0x20), searchLength),\n                    keccak256(add(search, 0x20), searchLength)\n                )\n            )\n        }\n    }\n\n    /// @dev Returns whether `subject` ends with `search`.\n    function endsWith(string memory subject, string memory search)\n        internal\n        pure\n        returns (bool result)\n    {\n        /// @solidity memory-safe-assembly\n        assembly {\n            let searchLength := mload(search)\n            let subjectLength := mload(subject)\n            // Whether `search` is not longer than `subject`.\n            let withinRange := iszero(gt(searchLength, subjectLength))\n            // Just using keccak256 directly is actually cheaper.\n            // forgefmt: disable-next-item\n            result := and(\n                withinRange,\n                eq(\n                    keccak256(\n                        // `subject + 0x20 + max(subjectLength - searchLength, 0)`.\n                        add(add(subject, 0x20), mul(withinRange, sub(subjectLength, searchLength))),\n                        searchLength\n                    ),\n                    keccak256(add(search, 0x20), searchLength)\n                )\n            )\n        }\n    }\n\n    /// @dev Returns `subject` repeated `times`.\n    function repeat(string memory subject, uint256 times)\n        internal\n        pure\n        returns (string memory result)\n    {\n        /// @solidity memory-safe-assembly\n        assembly {\n            let subjectLength := mload(subject)\n            if iszero(or(iszero(times), iszero(subjectLength))) {\n                subject := add(subject, 0x20)\n                result := mload(0x40)\n                let output := add(result, 0x20)\n                for {} 1 {} {\n                    // Copy the `subject` one word at a time.\n                    for { let o := 0 } 1 {} {\n                        mstore(add(output, o), mload(add(subject, o)))\n                        o := add(o, 0x20)\n                        if iszero(lt(o, subjectLength)) { break }\n                    }\n                    output := add(output, subjectLength)\n                    times := sub(times, 1)\n                    if iszero(times) { break }\n                }\n                mstore(output, 0) // Zeroize the slot after the string.\n                let resultLength := sub(output, add(result, 0x20))\n                mstore(result, resultLength) // Store the length.\n                mstore(0x40, add(result, add(resultLength, 0x40))) // Allocate the memory.\n            }\n        }\n    }\n\n    /// @dev Returns a copy of `subject` sliced from `start` to `end` (exclusive).\n    /// `start` and `end` are byte offsets.\n    function slice(string memory subject, uint256 start, uint256 end)\n        internal\n        pure\n        returns (string memory result)\n    {\n        /// @solidity memory-safe-assembly\n        assembly {\n            let subjectLength := mload(subject)\n            if iszero(gt(subjectLength, end)) { end := subjectLength }\n            if iszero(gt(subjectLength, start)) { start := subjectLength }\n            if lt(start, end) {\n                result := mload(0x40)\n                let resultLength := sub(end, start)\n                mstore(result, resultLength)\n                subject := add(subject, start)\n                let w := not(0x1f)\n                // Copy the `subject` one word at a time, backwards.\n                for { let o := and(add(resultLength, 0x1f), w) } 1 {} {\n                    mstore(add(result, o), mload(add(subject, o)))\n                    o := add(o, w) // `sub(o, 0x20)`.\n                    if iszero(o) { break }\n                }\n                // Zeroize the slot after the string.\n                mstore(add(add(result, 0x20), resultLength), 0)\n                mstore(0x40, add(result, add(resultLength, 0x40))) // Allocate the memory.\n            }\n        }\n    }\n\n    /// @dev Returns a copy of `subject` sliced from `start` to the end of the string.\n    /// `start` is a byte offset.\n    function slice(string memory subject, uint256 start)\n        internal\n        pure\n        returns (string memory result)\n    {\n        result = slice(subject, start, uint256(int256(-1)));\n    }\n\n    /// @dev Returns all the indices of `search` in `subject`.\n    /// The indices are byte offsets.\n    function indicesOf(string memory subject, string memory search)\n        internal\n        pure\n        returns (uint256[] memory result)\n    {\n        /// @solidity memory-safe-assembly\n        assembly {\n            let subjectLength := mload(subject)\n            let searchLength := mload(search)\n\n            if iszero(gt(searchLength, subjectLength)) {\n                subject := add(subject, 0x20)\n                search := add(search, 0x20)\n                result := add(mload(0x40), 0x20)\n\n                let subjectStart := subject\n                let subjectSearchEnd := add(sub(add(subject, subjectLength), searchLength), 1)\n                let h := 0\n                if iszero(lt(searchLength, 0x20)) { h := keccak256(search, searchLength) }\n                let m := shl(3, sub(0x20, and(searchLength, 0x1f)))\n                let s := mload(search)\n                for {} 1 {} {\n                    let t := mload(subject)\n                    // Whether the first `searchLength % 32` bytes of\n                    // `subject` and `search` matches.\n                    if iszero(shr(m, xor(t, s))) {\n                        if h {\n                            if iszero(eq(keccak256(subject, searchLength), h)) {\n                                subject := add(subject, 1)\n                                if iszero(lt(subject, subjectSearchEnd)) { break }\n                                continue\n                            }\n                        }\n                        // Append to `result`.\n                        mstore(result, sub(subject, subjectStart))\n                        result := add(result, 0x20)\n                        // Advance `subject` by `searchLength`.\n                        subject := add(subject, searchLength)\n                        if searchLength {\n                            if iszero(lt(subject, subjectSearchEnd)) { break }\n                            continue\n                        }\n                    }\n                    subject := add(subject, 1)\n                    if iszero(lt(subject, subjectSearchEnd)) { break }\n                }\n                let resultEnd := result\n                // Assign `result` to the free memory pointer.\n                result := mload(0x40)\n                // Store the length of `result`.\n                mstore(result, shr(5, sub(resultEnd, add(result, 0x20))))\n                // Allocate memory for result.\n                // We allocate one more word, so this array can be recycled for {split}.\n                mstore(0x40, add(resultEnd, 0x20))\n            }\n        }\n    }\n\n    /// @dev Returns a arrays of strings based on the `delimiter` inside of the `subject` string.\n    function split(string memory subject, string memory delimiter)\n        internal\n        pure\n        returns (string[] memory result)\n    {\n        uint256[] memory indices = indicesOf(subject, delimiter);\n        /// @solidity memory-safe-assembly\n        assembly {\n            let w := not(0x1f)\n            let indexPtr := add(indices, 0x20)\n            let indicesEnd := add(indexPtr, shl(5, add(mload(indices), 1)))\n            mstore(add(indicesEnd, w), mload(subject))\n            mstore(indices, add(mload(indices), 1))\n            let prevIndex := 0\n            for {} 1 {} {\n                let index := mload(indexPtr)\n                mstore(indexPtr, 0x60)\n                if iszero(eq(index, prevIndex)) {\n                    let element := mload(0x40)\n                    let elementLength := sub(index, prevIndex)\n                    mstore(element, elementLength)\n                    // Copy the `subject` one word at a time, backwards.\n                    for { let o := and(add(elementLength, 0x1f), w) } 1 {} {\n                        mstore(add(element, o), mload(add(add(subject, prevIndex), o)))\n                        o := add(o, w) // `sub(o, 0x20)`.\n                        if iszero(o) { break }\n                    }\n                    // Zeroize the slot after the string.\n                    mstore(add(add(element, 0x20), elementLength), 0)\n                    // Allocate memory for the length and the bytes,\n                    // rounded up to a multiple of 32.\n                    mstore(0x40, add(element, and(add(elementLength, 0x3f), w)))\n                    // Store the `element` into the array.\n                    mstore(indexPtr, element)\n                }\n                prevIndex := add(index, mload(delimiter))\n                indexPtr := add(indexPtr, 0x20)\n                if iszero(lt(indexPtr, indicesEnd)) { break }\n            }\n            result := indices\n            if iszero(mload(delimiter)) {\n                result := add(indices, 0x20)\n                mstore(result, sub(mload(indices), 2))\n            }\n        }\n    }\n\n    /// @dev Returns a concatenated string of `a` and `b`.\n    /// Cheaper than `string.concat()` and does not de-align the free memory pointer.\n    function concat(string memory a, string memory b)\n        internal\n        pure\n        returns (string memory result)\n    {\n        /// @solidity memory-safe-assembly\n        assembly {\n            let w := not(0x1f)\n            result := mload(0x40)\n            let aLength := mload(a)\n            // Copy `a` one word at a time, backwards.\n            for { let o := and(add(aLength, 0x20), w) } 1 {} {\n                mstore(add(result, o), mload(add(a, o)))\n                o := add(o, w) // `sub(o, 0x20)`.\n                if iszero(o) { break }\n            }\n            let bLength := mload(b)\n            let output := add(result, aLength)\n            // Copy `b` one word at a time, backwards.\n            for { let o := and(add(bLength, 0x20), w) } 1 {} {\n                mstore(add(output, o), mload(add(b, o)))\n                o := add(o, w) // `sub(o, 0x20)`.\n                if iszero(o) { break }\n            }\n            let totalLength := add(aLength, bLength)\n            let last := add(add(result, 0x20), totalLength)\n            mstore(last, 0) // Zeroize the slot after the string.\n            mstore(result, totalLength) // Store the length.\n            mstore(0x40, add(last, 0x20)) // Allocate the memory.\n        }\n    }\n\n    /// @dev Returns a copy of the string in either lowercase or UPPERCASE.\n    /// WARNING! This function is only compatible with 7-bit ASCII strings.\n    function toCase(string memory subject, bool toUpper)\n        internal\n        pure\n        returns (string memory result)\n    {\n        /// @solidity memory-safe-assembly\n        assembly {\n            let length := mload(subject)\n            if length {\n                result := add(mload(0x40), 0x20)\n                subject := add(subject, 1)\n                let flags := shl(add(70, shl(5, toUpper)), 0x3ffffff)\n                let w := not(0)\n                for { let o := length } 1 {} {\n                    o := add(o, w)\n                    let b := and(0xff, mload(add(subject, o)))\n                    mstore8(add(result, o), xor(b, and(shr(b, flags), 0x20)))\n                    if iszero(o) { break }\n                }\n                result := mload(0x40)\n                mstore(result, length) // Store the length.\n                let last := add(add(result, 0x20), length)\n                mstore(last, 0) // Zeroize the slot after the string.\n                mstore(0x40, add(last, 0x20)) // Allocate the memory.\n            }\n        }\n    }\n\n    /// @dev Returns a string from a small bytes32 string.\n    /// `s` must be null-terminated, or behavior will be undefined.\n    function fromSmallString(bytes32 s) internal pure returns (string memory result) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            result := mload(0x40)\n            let n := 0\n            for {} byte(n, s) { n := add(n, 1) } {} // Scan for '\\0'.\n            mstore(result, n) // Store the length.\n            let o := add(result, 0x20)\n            mstore(o, s) // Store the bytes of the string.\n            mstore(add(o, n), 0) // Zeroize the slot after the string.\n            mstore(0x40, add(result, 0x40)) // Allocate the memory.\n        }\n    }\n\n    /// @dev Returns the small string, with all bytes after the first null byte zeroized.\n    function normalizeSmallString(bytes32 s) internal pure returns (bytes32 result) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            for {} byte(result, s) { result := add(result, 1) } {} // Scan for '\\0'.\n            mstore(0x00, s)\n            mstore(result, 0x00)\n            result := mload(0x00)\n        }\n    }\n\n    /// @dev Returns the string as a normalized null-terminated small string.\n    function toSmallString(string memory s) internal pure returns (bytes32 result) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            result := mload(s)\n            if iszero(lt(result, 33)) {\n                mstore(0x00, 0xec92f9a3) // `TooBigForSmallString()`.\n                revert(0x1c, 0x04)\n            }\n            result := shl(shl(3, sub(32, result)), mload(add(s, result)))\n        }\n    }\n\n    /// @dev Returns a lowercased copy of the string.\n    /// WARNING! This function is only compatible with 7-bit ASCII strings.\n    function lower(string memory subject) internal pure returns (string memory result) {\n        result = toCase(subject, false);\n    }\n\n    /// @dev Returns an UPPERCASED copy of the string.\n    /// WARNING! This function is only compatible with 7-bit ASCII strings.\n    function upper(string memory subject) internal pure returns (string memory result) {\n        result = toCase(subject, true);\n    }\n\n    /// @dev Escapes the string to be used within HTML tags.\n    function escapeHTML(string memory s) internal pure returns (string memory result) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            let end := add(s, mload(s))\n            result := add(mload(0x40), 0x20)\n            // Store the bytes of the packed offsets and strides into the scratch space.\n            // `packed = (stride << 5) | offset`. Max offset is 20. Max stride is 6.\n            mstore(0x1f, 0x900094)\n            mstore(0x08, 0xc0000000a6ab)\n            // Store \"&quot;&amp;&#39;&lt;&gt;\" into the scratch space.\n            mstore(0x00, shl(64, 0x2671756f743b26616d703b262333393b266c743b2667743b))\n            for {} iszero(eq(s, end)) {} {\n                s := add(s, 1)\n                let c := and(mload(s), 0xff)\n                // Not in `[\"\\\"\",\"'\",\"&\",\"<\",\">\"]`.\n                if iszero(and(shl(c, 1), 0x500000c400000000)) {\n                    mstore8(result, c)\n                    result := add(result, 1)\n                    continue\n                }\n                let t := shr(248, mload(c))\n                mstore(result, mload(and(t, 0x1f)))\n                result := add(result, shr(5, t))\n            }\n            let last := result\n            mstore(last, 0) // Zeroize the slot after the string.\n            result := mload(0x40)\n            mstore(result, sub(last, add(result, 0x20))) // Store the length.\n            mstore(0x40, add(last, 0x20)) // Allocate the memory.\n        }\n    }\n\n    /// @dev Escapes the string to be used within double-quotes in a JSON.\n    /// If `addDoubleQuotes` is true, the result will be enclosed in double-quotes.\n    function escapeJSON(string memory s, bool addDoubleQuotes)\n        internal\n        pure\n        returns (string memory result)\n    {\n        /// @solidity memory-safe-assembly\n        assembly {\n            let end := add(s, mload(s))\n            result := add(mload(0x40), 0x20)\n            if addDoubleQuotes {\n                mstore8(result, 34)\n                result := add(1, result)\n            }\n            // Store \"\\\\u0000\" in scratch space.\n            // Store \"0123456789abcdef\" in scratch space.\n            // Also, store `{0x08:\"b\", 0x09:\"t\", 0x0a:\"n\", 0x0c:\"f\", 0x0d:\"r\"}`.\n            // into the scratch space.\n            mstore(0x15, 0x5c75303030303031323334353637383961626364656662746e006672)\n            // Bitmask for detecting `[\"\\\"\",\"\\\\\"]`.\n            let e := or(shl(0x22, 1), shl(0x5c, 1))\n            for {} iszero(eq(s, end)) {} {\n                s := add(s, 1)\n                let c := and(mload(s), 0xff)\n                if iszero(lt(c, 0x20)) {\n                    if iszero(and(shl(c, 1), e)) {\n                        // Not in `[\"\\\"\",\"\\\\\"]`.\n                        mstore8(result, c)\n                        result := add(result, 1)\n                        continue\n                    }\n                    mstore8(result, 0x5c) // \"\\\\\".\n                    mstore8(add(result, 1), c)\n                    result := add(result, 2)\n                    continue\n                }\n                if iszero(and(shl(c, 1), 0x3700)) {\n                    // Not in `[\"\\b\",\"\\t\",\"\\n\",\"\\f\",\"\\d\"]`.\n                    mstore8(0x1d, mload(shr(4, c))) // Hex value.\n                    mstore8(0x1e, mload(and(c, 15))) // Hex value.\n                    mstore(result, mload(0x19)) // \"\\\\u00XX\".\n                    result := add(result, 6)\n                    continue\n                }\n                mstore8(result, 0x5c) // \"\\\\\".\n                mstore8(add(result, 1), mload(add(c, 8)))\n                result := add(result, 2)\n            }\n            if addDoubleQuotes {\n                mstore8(result, 34)\n                result := add(1, result)\n            }\n            let last := result\n            mstore(last, 0) // Zeroize the slot after the string.\n            result := mload(0x40)\n            mstore(result, sub(last, add(result, 0x20))) // Store the length.\n            mstore(0x40, add(last, 0x20)) // Allocate the memory.\n        }\n    }\n\n    /// @dev Escapes the string to be used within double-quotes in a JSON.\n    function escapeJSON(string memory s) internal pure returns (string memory result) {\n        result = escapeJSON(s, false);\n    }\n\n    /// @dev Returns whether `a` equals `b`.\n    function eq(string memory a, string memory b) internal pure returns (bool result) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            result := eq(keccak256(add(a, 0x20), mload(a)), keccak256(add(b, 0x20), mload(b)))\n        }\n    }\n\n    /// @dev Returns whether `a` equals `b`, where `b` is a null-terminated small string.\n    function eqs(string memory a, bytes32 b) internal pure returns (bool result) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            // These should be evaluated on compile time, as far as possible.\n            let m := not(shl(7, div(not(iszero(b)), 255))) // `0x7f7f ...`.\n            let x := not(or(m, or(b, add(m, and(b, m)))))\n            let r := shl(7, iszero(iszero(shr(128, x))))\n            r := or(r, shl(6, iszero(iszero(shr(64, shr(r, x))))))\n            r := or(r, shl(5, lt(0xffffffff, shr(r, x))))\n            r := or(r, shl(4, lt(0xffff, shr(r, x))))\n            r := or(r, shl(3, lt(0xff, shr(r, x))))\n            // forgefmt: disable-next-item\n            result := gt(eq(mload(a), add(iszero(x), xor(31, shr(3, r)))),\n                xor(shr(add(8, r), b), shr(add(8, r), mload(add(a, 0x20)))))\n        }\n    }\n\n    /// @dev Packs a single string with its length into a single word.\n    /// Returns `bytes32(0)` if the length is zero or greater than 31.\n    function packOne(string memory a) internal pure returns (bytes32 result) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            // We don't need to zero right pad the string,\n            // since this is our own custom non-standard packing scheme.\n            result :=\n                mul(\n                    // Load the length and the bytes.\n                    mload(add(a, 0x1f)),\n                    // `length != 0 && length < 32`. Abuses underflow.\n                    // Assumes that the length is valid and within the block gas limit.\n                    lt(sub(mload(a), 1), 0x1f)\n                )\n        }\n    }\n\n    /// @dev Unpacks a string packed using {packOne}.\n    /// Returns the empty string if `packed` is `bytes32(0)`.\n    /// If `packed` is not an output of {packOne}, the output behavior is undefined.\n    function unpackOne(bytes32 packed) internal pure returns (string memory result) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            result := mload(0x40) // Grab the free memory pointer.\n            mstore(0x40, add(result, 0x40)) // Allocate 2 words (1 for the length, 1 for the bytes).\n            mstore(result, 0) // Zeroize the length slot.\n            mstore(add(result, 0x1f), packed) // Store the length and bytes.\n            mstore(add(add(result, 0x20), mload(result)), 0) // Right pad with zeroes.\n        }\n    }\n\n    /// @dev Packs two strings with their lengths into a single word.\n    /// Returns `bytes32(0)` if combined length is zero or greater than 30.\n    function packTwo(string memory a, string memory b) internal pure returns (bytes32 result) {\n        /// @solidity memory-safe-assembly\n        assembly {\n            let aLength := mload(a)\n            // We don't need to zero right pad the strings,\n            // since this is our own custom non-standard packing scheme.\n            result :=\n                mul(\n                    or( // Load the length and the bytes of `a` and `b`.\n                        shl(shl(3, sub(0x1f, aLength)), mload(add(a, aLength))),\n                        mload(sub(add(b, 0x1e), aLength))\n                    ),\n                    // `totalLength != 0 && totalLength < 31`. Abuses underflow.\n                    // Assumes that the lengths are valid and within the block gas limit.\n                    lt(sub(add(aLength, mload(b)), 1), 0x1e)\n                )\n        }\n    }\n\n    /// @dev Unpacks strings packed using {packTwo}.\n    /// Returns the empty strings if `packed` is `bytes32(0)`.\n    /// If `packed` is not an output of {packTwo}, the output behavior is undefined.\n    function unpackTwo(bytes32 packed)\n        internal\n        pure\n        returns (string memory resultA, string memory resultB)\n    {\n        /// @solidity memory-safe-assembly\n        assembly {\n            resultA := mload(0x40) // Grab the free memory pointer.\n            resultB := add(resultA, 0x40)\n            // Allocate 2 words for each string (1 for the length, 1 for the byte). Total 4 words.\n            mstore(0x40, add(resultB, 0x40))\n            // Zeroize the length slots.\n            mstore(resultA, 0)\n            mstore(resultB, 0)\n            // Store the lengths and bytes.\n            mstore(add(resultA, 0x1f), packed)\n            mstore(add(resultB, 0x1f), mload(add(add(resultA, 0x20), mload(resultA))))\n            // Right pad with zeroes.\n            mstore(add(add(resultA, 0x20), mload(resultA)), 0)\n            mstore(add(add(resultB, 0x20), mload(resultB)), 0)\n        }\n    }\n\n    /// @dev Directly returns `a` without copying.\n    function directReturn(string memory a) internal pure {\n        assembly {\n            // Assumes that the string does not start from the scratch space.\n            let retStart := sub(a, 0x20)\n            let retUnpaddedSize := add(mload(a), 0x40)\n            // Right pad with zeroes. Just in case the string is produced\n            // by a method that doesn't zero right pad.\n            mstore(add(retStart, retUnpaddedSize), 0)\n            mstore(retStart, 0x20) // Store the return offset.\n            // End the transaction, returning the string.\n            return(retStart, and(not(0x1f), add(0x1f, retUnpaddedSize)))\n        }\n    }\n}\n"},{"file_path":"lib/bold/contracts/src/Interfaces/IPriceFeed.sol","source_code":"// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.0;\n\ninterface IPriceFeed {\n    function fetchPrice() external returns (uint256);\n    function isL2SequencerUp() external view returns (bool);\n}\n"},{"file_path":"lib/bold/contracts/lib/openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Permit.sol","source_code":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.4) (token/ERC20/extensions/IERC20Permit.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in\n * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].\n *\n * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by\n * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't\n * need to send a transaction, and thus is not required to hold Ether at all.\n *\n * ==== Security Considerations\n *\n * There are two important considerations concerning the use of `permit`. The first is that a valid permit signature\n * expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be\n * considered as an intention to spend the allowance in any specific way. The second is that because permits have\n * built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should\n * take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be\n * generally recommended is:\n *\n * ```solidity\n * function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public {\n *     try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {}\n *     doThing(..., value);\n * }\n *\n * function doThing(..., uint256 value) public {\n *     token.safeTransferFrom(msg.sender, address(this), value);\n *     ...\n * }\n * ```\n *\n * Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of\n * `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also\n * {SafeERC20-safeTransferFrom}).\n *\n * Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so\n * contracts should have entry points that don't rely on permit.\n */\ninterface IERC20Permit {\n    /**\n     * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,\n     * given ``owner``'s signed approval.\n     *\n     * IMPORTANT: The same issues {IERC20-approve} has related to transaction\n     * ordering also apply here.\n     *\n     * Emits an {Approval} event.\n     *\n     * Requirements:\n     *\n     * - `spender` cannot be the zero address.\n     * - `deadline` must be a timestamp in the future.\n     * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`\n     * over the EIP712-formatted function arguments.\n     * - the signature must use ``owner``'s current nonce (see {nonces}).\n     *\n     * For more information on the signature format, see the\n     * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP\n     * section].\n     *\n     * CAUTION: See Security Considerations above.\n     */\n    function permit(\n        address owner,\n        address spender,\n        uint256 value,\n        uint256 deadline,\n        uint8 v,\n        bytes32 r,\n        bytes32 s\n    ) external;\n\n    /**\n     * @dev Returns the current nonce for `owner`. This value must be\n     * included whenever a signature is generated for {permit}.\n     *\n     * Every successful call to {permit} increases ``owner``'s nonce by one. This\n     * prevents a signature from being used multiple times.\n     */\n    function nonces(address owner) external view returns (uint256);\n\n    /**\n     * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.\n     */\n    // solhint-disable-next-line func-name-mixedcase\n    function DOMAIN_SEPARATOR() external view returns (bytes32);\n}\n"},{"file_path":"lib/bold/contracts/src/Interfaces/ISystemParams.sol","source_code":"// SPDX-License-Identifier: BUSL-1.1\n\npragma solidity 0.8.24;\n\ninterface ISystemParams {\n    /* ========== PARAMETER STRUCTS ========== */\n\n    struct DebtParams {\n        uint256 minDebt;\n    }\n\n    struct LiquidationParams {\n        uint256 liquidationPenaltySP;\n        uint256 liquidationPenaltyRedistribution;\n    }\n\n    struct GasCompParams {\n        uint256 collGasCompensationDivisor;\n        uint256 collGasCompensationCap;\n        uint256 ethGasCompensation;\n    }\n\n    struct CollateralParams {\n        uint256 ccr;\n        uint256 scr;\n        uint256 mcr;\n        uint256 bcr;\n    }\n\n    struct InterestParams {\n        uint256 minAnnualInterestRate;\n    }\n\n    struct RedemptionParams {\n        uint256 redemptionFeeFloor;\n        uint256 initialBaseRate;\n        uint256 redemptionMinuteDecayFactor;\n        uint256 redemptionBeta;\n    }\n\n    struct StabilityPoolParams {\n        uint256 spYieldSplit;\n        uint256 minBoldInSP;\n        uint256 minBoldAfterRebalance;\n    }\n\n    /* ========== ERRORS ========== */\n\n    error InvalidMinDebt();\n    error InvalidInterestRateBounds();\n    error InvalidFeeValue();\n    error InvalidTimeValue();\n    error InvalidGasCompensation();\n    error MinInterestRateGtMax();\n    error InvalidCCR();\n    error InvalidMCR();\n    error InvalidBCR();\n    error InvalidSCR();\n    error SPPenaltyTooLow();\n    error SPPenaltyGtRedist();\n    error RedistPenaltyTooHigh();\n    error InvalidMinBoldInSP();\n\n    /* ========== DEBT PARAMETERS ========== */\n\n    /// @notice Minimum amount of net debt a trove must have.\n    function MIN_DEBT() external view returns (uint256);\n\n    /* ========== LIQUIDATION PARAMETERS ========== */\n\n    /// @notice Liquidation penalty for troves offset to the SP\n    function LIQUIDATION_PENALTY_SP() external view returns (uint256);\n\n    /// @notice Liquidation penalty for troves redistributed.\n    function LIQUIDATION_PENALTY_REDISTRIBUTION() external view returns (uint256);\n\n    /* ========== GAS COMPENSATION PARAMETERS ========== */\n\n    /// @notice Divisor for calculating collateral gas compensation for liquidators.\n    function COLL_GAS_COMPENSATION_DIVISOR() external view returns (uint256);\n\n    /// @notice Maximum collateral gas compensation cap for liquidators.\n    function COLL_GAS_COMPENSATION_CAP() external view returns (uint256);\n\n    // TODO(@bayological): Consider rename to native(or just drop eth) if this makes sense\n    //              and update comment.\n    /// @notice Amount of ETH to be locked in gas pool on opening troves.\n    function ETH_GAS_COMPENSATION() external view returns (uint256);\n\n    /* ========== COLLATERAL PARAMETERS ========== */\n\n    /**\n     * @notice Critical system collateral ratio.\n     * @dev If the system's total collateral ratio (TCR) falls below the CCR, some borrowing\n     *      operation restrictions are applied.\n     */\n    function CCR() external view returns (uint256);\n\n    /**\n     * @notice Shutdown system collateral ratio.\n     * @dev If the system's total collateral ratio (TCR) for a given collateral falls below the SCR,\n     *      the protocol triggers the shutdown of the borrow market and permanently disables all\n     *      borrowing operations except for closing Troves.\n     */\n    function SCR() external view returns (uint256);\n\n    /// @notice Minimum collateral ratio for individual troves.\n    function MCR() external view returns (uint256);\n\n    /**\n     * @notice Extra buffer of collateral ratio to join a batch or adjust a trove inside\n     *         a batch (on top of MCR).\n     */\n    function BCR() external view returns (uint256);\n\n    /* ========== INTEREST PARAMETERS ========== */\n\n    /// @notice Min annual interest rate for a trove.\n    function MIN_ANNUAL_INTEREST_RATE() external view returns (uint256);\n\n    /* ========== REDEMPTION PARAMETERS ========== */\n\n    /// @notice Minimum redemption fee percentage.\n    function REDEMPTION_FEE_FLOOR() external view returns (uint256);\n\n    /// @notice The initial redemption fee value.\n    function INITIAL_BASE_RATE() external view returns (uint256);\n\n    /// @notice Factor to reduce the redemption fee per minute.\n    function REDEMPTION_MINUTE_DECAY_FACTOR() external view returns (uint256);\n\n    /// @notice Divisor controlling base rate sensitivity to redemption volume (higher = less sensitive).\n    function REDEMPTION_BETA() external view returns (uint256);\n\n    /* ========== STABILITY POOL PARAMETERS ========== */\n\n    /// @notice Percentage of minted interest yield allocated to Stability Pool depositors.\n    function SP_YIELD_SPLIT() external view returns (uint256);\n\n    /// @notice Minimum BOLD that must remain in Stability Pool to prevent complete drainage.\n    function MIN_BOLD_IN_SP() external view returns (uint256);\n\n    /// @notice Minimum BOLD that must remain in Stability Pool after a rebalance operation.\n    function MIN_BOLD_AFTER_REBALANCE() external view returns (uint256);\n\n    function initialize() external;\n}\n"},{"file_path":"lib/bold/contracts/src/Interfaces/IStabilityPool.sol","source_code":"// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.0;\n\nimport \"./IActivePool.sol\";\nimport \"./ILiquityBase.sol\";\nimport \"./IBoldToken.sol\";\nimport \"./ITroveManager.sol\";\nimport \"./IBoldRewardsReceiver.sol\";\nimport \"./IAddressesRegistry.sol\";\nimport \"./ISystemParams.sol\";\n\n/*\n * The Stability Pool holds Bold tokens deposited by Stability Pool depositors.\n *\n * When a trove is liquidated, then depending on system conditions, some of its Bold debt gets offset with\n * Bold in the Stability Pool:  that is, the offset debt evaporates, and an equal amount of Bold tokens in the Stability Pool is burned.\n *\n * Thus, a liquidation causes each depositor to receive a Bold loss, in proportion to their deposit as a share of total deposits.\n * They also receive an Coll gain, as the collateral of the liquidated trove is distributed among Stability depositors,\n * in the same proportion.\n *\n * When a liquidation occurs, it depletes every deposit by the same fraction: for example, a liquidation that depletes 40%\n * of the total Bold in the Stability Pool, depletes 40% of each deposit.\n *\n * A deposit that has experienced a series of liquidations is termed a \"compounded deposit\": each liquidation depletes the deposit,\n * multiplying it by some factor in range ]0,1[\n *\n * Please see the implementation spec in the proof document, which closely follows on from the compounded deposit / Coll gain derivations:\n * https://github.com/liquity/liquity/blob/master/papers/Scalable_Reward_Distribution_with_Compounding_Stakes.pdf\n *\n*/\ninterface IStabilityPool is ILiquityBase, IBoldRewardsReceiver {\n    function initialize(IAddressesRegistry _addressesRegistry) external;\n\n    function boldToken() external view returns (IBoldToken);\n    function troveManager() external view returns (ITroveManager);\n    function systemParams() external view returns (ISystemParams);\n    \n    /*  provideToSP():\n    * - Calculates depositor's Coll gain\n    * - Calculates the compounded deposit\n    * - Increases deposit, and takes new snapshots of accumulators P and S\n    * - Sends depositor's accumulated Coll gains to depositor\n    */\n    function provideToSP(uint256 _amount, bool _doClaim) external;\n\n    /*  withdrawFromSP():\n    * - Calculates depositor's Coll gain\n    * - Calculates the compounded deposit\n    * - Sends the requested BOLD withdrawal to depositor\n    * - (If _amount > userDeposit, the user withdraws all of their compounded deposit)\n    * - Decreases deposit by withdrawn amount and takes new snapshots of accumulators P and S\n    */\n    function withdrawFromSP(uint256 _amount, bool doClaim) external;\n\n    function claimAllCollGains() external;\n\n    /*\n    * Stable token liquidity in the stability pool can be used to rebalance FPMM pools.\n    * Collateral will be swapped for stable tokens in the SP.\n    * Removed stable tokens will be factored out from LPs' positions.\n    * Added collateral will be added to LPs collateral gain which can be later claimed by the depositor.\n    */\n    function swapCollateralForStable(uint256 amountCollIn, uint256 amountStableOut) external;\n\n    /*\n     * Initial checks:\n     * - Caller is TroveManager\n     * ---\n     * Cancels out the specified debt against the Bold contained in the Stability Pool (as far as possible)\n     * and transfers the Trove's collateral from ActivePool to StabilityPool.\n     * Only called by liquidation functions in the TroveManager.\n     */\n    function offset(uint256 _debt, uint256 _coll) external;\n\n    function deposits(address _depositor) external view returns (uint256 initialValue);\n    function stashedColl(address _depositor) external view returns (uint256);\n\n    /*\n     * Returns the total amount of Coll held by the pool, accounted in an internal variable instead of `balance`,\n     * to exclude edge cases like Coll received from a self-destruct.\n     */\n    function getCollBalance() external view returns (uint256);\n\n    /*\n     * Returns Bold held in the pool. Changes when users deposit/withdraw, and when Trove debt is offset.\n     */\n    function getTotalBoldDeposits() external view returns (uint256);\n\n    function getYieldGainsOwed() external view returns (uint256);\n    function getYieldGainsPending() external view returns (uint256);\n\n    /*\n     * Calculates the Coll gain earned by the deposit since its last snapshots were taken.\n     */\n    function getDepositorCollGain(address _depositor) external view returns (uint256);\n\n    /*\n     * Calculates the BOLD yield gain earned by the deposit since its last snapshots were taken.\n     */\n    function getDepositorYieldGain(address _depositor) external view returns (uint256);\n\n    /*\n     * Calculates what `getDepositorYieldGain` will be if interest is minted now.\n     */\n    function getDepositorYieldGainWithPending(address _depositor) external view returns (uint256);\n\n    /*\n     * Return the user's compounded deposit.\n     */\n    function getCompoundedBoldDeposit(address _depositor) external view returns (uint256);\n\n    function scaleToS(uint256 _scale) external view returns (uint256);\n\n    function scaleToB(uint256 _scale) external view returns (uint256);\n\n    function P() external view returns (uint256);\n    function currentScale() external view returns (uint256);\n    function liquidityStrategy() external view returns (address);\n\n    function P_PRECISION() external view returns (uint256);\n}\n"},{"file_path":"lib/bold/contracts/src/Interfaces/ILiquityBase.sol","source_code":"// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.0;\n\nimport \"./IActivePool.sol\";\nimport \"./IDefaultPool.sol\";\nimport \"./IPriceFeed.sol\";\n\ninterface ILiquityBase {\n    function activePool() external view returns (IActivePool);\n    function getEntireBranchDebt() external view returns (uint256);\n    function getEntireBranchColl() external view returns (uint256);\n}\n"},{"file_path":"lib/bold/contracts/src/Dependencies/Constants.sol","source_code":"// SPDX-License-Identifier: BUSL-1.1\npragma solidity 0.8.24;\n\naddress constant ZERO_ADDRESS = address(0);\n\nuint256 constant MAX_UINT256 = type(uint256).max;\n\nuint256 constant DECIMAL_PRECISION = 1e18;\nuint256 constant _100pct = DECIMAL_PRECISION;\nuint256 constant _1pct = DECIMAL_PRECISION / 100;\n\nuint256 constant ONE_MINUTE = 1 minutes;\nuint256 constant ONE_YEAR = 365 days;\n\n// Interest rate parameters\nuint256 constant MAX_ANNUAL_INTEREST_RATE = 250 * _1pct; // 250%\nuint128 constant MAX_ANNUAL_BATCH_MANAGEMENT_FEE = uint128(_100pct / 10); // 10%\nuint128 constant MIN_INTEREST_RATE_CHANGE_PERIOD = 1 hours;\nuint256 constant UPFRONT_INTEREST_PERIOD = 7 days;\nuint256 constant INTEREST_RATE_ADJ_COOLDOWN = 7 days;\n\n// Batch parameters\nuint256 constant MAX_BATCH_SHARES_RATIO = 1e9;\n\n// Redemption parameters\nuint256 constant URGENT_REDEMPTION_BONUS = 1 * _1pct; // 1%\n\n// Liquidation parameters\nuint256 constant MAX_LIQUIDATION_PENALTY_REDISTRIBUTION = 20 * _1pct; // 20%\n"},{"file_path":"lib/bold/contracts/src/NFTMetadata/utils/JSON.sol","source_code":"//SPDX-License-Identifier: MIT\npragma solidity ^0.8.12;\n\n// JSON utilities for base64 encoded ERC721 JSON metadata scheme\nlibrary json {\n    /////////////////////////////////////////////////////////////////////////////////////////////////////////////\n    /// @dev JSON requires that double quotes be escaped or JSONs will not build correctly\n    /// string.concat also requires an escape, use \\\\\" or the constant DOUBLE_QUOTES to represent \" in JSON\n    /////////////////////////////////////////////////////////////////////////////////////////////////////////////\n\n    string constant DOUBLE_QUOTES = '\\\\\"';\n\n    function formattedMetadata(\n        string memory name,\n        string memory description,\n        string memory svgImg,\n        string memory attributes\n    ) internal pure returns (string memory) {\n        return string.concat(\n            \"data:application/json;base64,\",\n            encode(\n                bytes(\n                    string.concat(\n                        \"{\",\n                        _prop(\"name\", name),\n                        _prop(\"description\", description),\n                        _xmlImage(svgImg),\n                        ',\"attributes\":',\n                        attributes,\n                        \"}\"\n                    )\n                )\n            )\n        );\n    }\n\n    function _xmlImage(string memory _svgImg) internal pure returns (string memory) {\n        return _prop(\"image\", string.concat(\"data:image/svg+xml;base64,\", encode(bytes(_svgImg))), true);\n    }\n\n    function _prop(string memory _key, string memory _val) internal pure returns (string memory) {\n        return string.concat('\"', _key, '\": ', '\"', _val, '\", ');\n    }\n\n    function _prop(string memory _key, string memory _val, bool last) internal pure returns (string memory) {\n        if (last) {\n            return string.concat('\"', _key, '\": ', '\"', _val, '\"');\n        } else {\n            return string.concat('\"', _key, '\": ', '\"', _val, '\", ');\n        }\n    }\n\n    function _object(string memory _key, string memory _val) internal pure returns (string memory) {\n        return string.concat('\"', _key, '\": ', \"{\", _val, \"}\");\n    }\n\n    /**\n     * taken from Openzeppelin\n     * @dev Base64 Encoding/Decoding Table\n     */\n    string internal constant _TABLE = \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\";\n\n    /**\n     * @dev Converts a `bytes` to its Bytes64 `string` representation.\n     */\n    function encode(bytes memory data) internal pure returns (string memory) {\n        /**\n         * Inspired by Brecht Devos (Brechtpd) implementation - MIT licence\n         * https://github.com/Brechtpd/base64/blob/e78d9fd951e7b0977ddca77d92dc85183770daf4/base64.sol\n         */\n        if (data.length == 0) return \"\";\n\n        // Loads the table into memory\n        string memory table = _TABLE;\n\n        // Encoding takes 3 bytes chunks of binary data from `bytes` data parameter\n        // and split into 4 numbers of 6 bits.\n        // The final Base64 length should be `bytes` data length multiplied by 4/3 rounded up\n        // - `data.length + 2`  -> Round up\n        // - `/ 3`              -> Number of 3-bytes chunks\n        // - `4 *`              -> 4 characters for each chunk\n        string memory result = new string(4 * ((data.length + 2) / 3));\n\n        assembly {\n            // Prepare the lookup table (skip the first \"length\" byte)\n            let tablePtr := add(table, 1)\n\n            // Prepare result pointer, jump over length\n            let resultPtr := add(result, 32)\n\n            // Run over the input, 3 bytes at a time\n            for {\n                let dataPtr := data\n                let endPtr := add(data, mload(data))\n            } lt(dataPtr, endPtr) {} {\n                // Advance 3 bytes\n                dataPtr := add(dataPtr, 3)\n                let input := mload(dataPtr)\n\n                // To write each character, shift the 3 bytes (18 bits) chunk\n                // 4 times in blocks of 6 bits for each character (18, 12, 6, 0)\n                // and apply logical AND with 0x3F which is the number of\n                // the previous character in the ASCII table prior to the Base64 Table\n                // The result is then added to the table to get the character to write,\n                // and finally write it in the result pointer but with a left shift\n                // of 256 (1 byte) - 8 (1 ASCII char) = 248 bits\n\n                mstore8(resultPtr, mload(add(tablePtr, and(shr(18, input), 0x3F))))\n                resultPtr := add(resultPtr, 1) // Advance\n\n                mstore8(resultPtr, mload(add(tablePtr, and(shr(12, input), 0x3F))))\n                resultPtr := add(resultPtr, 1) // Advance\n\n                mstore8(resultPtr, mload(add(tablePtr, and(shr(6, input), 0x3F))))\n                resultPtr := add(resultPtr, 1) // Advance\n\n                mstore8(resultPtr, mload(add(tablePtr, and(input, 0x3F))))\n                resultPtr := add(resultPtr, 1) // Advance\n            }\n\n            // When data `bytes` is not exactly 3 bytes long\n            // it is padded with `=` characters at the end\n            switch mod(mload(data), 3)\n            case 1 {\n                mstore8(sub(resultPtr, 1), 0x3d)\n                mstore8(sub(resultPtr, 2), 0x3d)\n            }\n            case 2 { mstore8(sub(resultPtr, 1), 0x3d) }\n        }\n\n        return result;\n    }\n}\n"},{"file_path":"lib/bold/contracts/src/Dependencies/LiquityBase.sol","source_code":"// SPDX-License-Identifier: BUSL-1.1\n\npragma solidity 0.8.24;\n\nimport \"./Constants.sol\";\nimport \"./LiquityMath.sol\";\nimport \"../Interfaces/IAddressesRegistry.sol\";\nimport \"../Interfaces/IActivePool.sol\";\nimport \"../Interfaces/IDefaultPool.sol\";\nimport \"../Interfaces/IPriceFeed.sol\";\nimport \"../Interfaces/ILiquityBase.sol\";\n\n/*\n* Base contract for TroveManager, BorrowerOperations and StabilityPool. Contains global system constants and\n* common functions.\n*/\ncontract LiquityBase is ILiquityBase {\n    IActivePool public activePool;\n    IDefaultPool internal defaultPool;\n    IPriceFeed internal priceFeed;\n\n    event ActivePoolAddressChanged(address _newActivePoolAddress);\n    event DefaultPoolAddressChanged(address _newDefaultPoolAddress);\n    event PriceFeedAddressChanged(address _newPriceFeedAddress);\n\n    constructor(IAddressesRegistry _addressesRegistry) {\n        activePool = _addressesRegistry.activePool();\n        defaultPool = _addressesRegistry.defaultPool();\n        priceFeed = _addressesRegistry.priceFeed();\n\n        emit ActivePoolAddressChanged(address(activePool));\n        emit DefaultPoolAddressChanged(address(defaultPool));\n        emit PriceFeedAddressChanged(address(priceFeed));\n    }\n    // --- Gas compensation functions ---\n\n    function getEntireBranchColl() public view returns (uint256 entireSystemColl) {\n        uint256 activeColl = activePool.getCollBalance();\n        uint256 liquidatedColl = defaultPool.getCollBalance();\n\n        return activeColl + liquidatedColl;\n    }\n\n    function getEntireBranchDebt() public view returns (uint256 entireSystemDebt) {\n        uint256 activeDebt = activePool.getBoldDebt();\n        uint256 closedDebt = defaultPool.getBoldDebt();\n\n        return activeDebt + closedDebt;\n    }\n\n    function _getTCR(uint256 _price) internal view returns (uint256 TCR) {\n        uint256 entireSystemColl = getEntireBranchColl();\n        uint256 entireSystemDebt = getEntireBranchDebt();\n\n        TCR = LiquityMath._computeCR(entireSystemColl, entireSystemDebt, _price);\n\n        return TCR;\n    }\n\n    function _checkBelowCriticalThreshold(uint256 _price, uint256 _CCR) internal view returns (bool) {\n        uint256 TCR = _getTCR(_price);\n\n        return TCR < _CCR;\n    }\n\n    function _calcInterest(uint256 _weightedDebt, uint256 _period) internal pure returns (uint256) {\n        return _weightedDebt * _period / ONE_YEAR / DECIMAL_PRECISION;\n    }\n}\n"},{"file_path":"lib/bold/contracts/src/Interfaces/IBoldToken.sol","source_code":"// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.0;\n\nimport \"openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Metadata.sol\";\nimport \"openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Permit.sol\";\nimport \"openzeppelin-contracts/contracts/interfaces/IERC5267.sol\";\n\ninterface IBoldToken is IERC20Metadata, IERC20Permit, IERC5267 {\n    function setBranchAddresses(\n        address _troveManagerAddress,\n        address _stabilityPoolAddress,\n        address _borrowerOperationsAddress,\n        address _activePoolAddress\n    ) external;\n\n    function setCollateralRegistry(address _collateralRegistryAddress) external;\n\n    function mint(address _account, uint256 _amount) external;\n\n    function burn(address _account, uint256 _amount) external;\n\n    function sendToPool(address _sender, address poolAddress, uint256 _amount) external;\n\n    function returnFromPool(address poolAddress, address user, uint256 _amount) external;\n}\n"},{"file_path":"lib/bold/contracts/src/Dependencies/LiquityMath.sol","source_code":"// SPDX-License-Identifier: MIT\n\npragma solidity 0.8.24;\n\nimport {DECIMAL_PRECISION} from \"./Constants.sol\";\n\nlibrary LiquityMath {\n    function _min(uint256 _a, uint256 _b) internal pure returns (uint256) {\n        return (_a < _b) ? _a : _b;\n    }\n\n    function _max(uint256 _a, uint256 _b) internal pure returns (uint256) {\n        return (_a >= _b) ? _a : _b;\n    }\n\n    function _sub_min_0(uint256 _a, uint256 _b) internal pure returns (uint256) {\n        return (_a > _b) ? _a - _b : 0;\n    }\n\n    /* \n    * Multiply two decimal numbers and use normal rounding rules:\n    * -round product up if 19'th mantissa digit >= 5\n    * -round product down if 19'th mantissa digit < 5\n    *\n    * Used only inside the exponentiation, _decPow().\n    */\n    function decMul(uint256 x, uint256 y) internal pure returns (uint256 decProd) {\n        uint256 prod_xy = x * y;\n\n        decProd = (prod_xy + DECIMAL_PRECISION / 2) / DECIMAL_PRECISION;\n    }\n\n    /* \n    * _decPow: Exponentiation function for 18-digit decimal base, and integer exponent n.\n    * \n    * Uses the efficient \"exponentiation by squaring\" algorithm. O(log(n)) complexity. \n    * \n    * Called by function CollateralRegistry._calcDecayedBaseRate, that represent time in units of minutes\n    *\n    * The exponent is capped to avoid reverting due to overflow. The cap 525600000 equals\n    * \"minutes in 1000 years\": 60 * 24 * 365 * 1000\n    * \n    * If a period of > 1000 years is ever used as an exponent in either of the above functions, the result will be\n    * negligibly different from just passing the cap, since: \n    *\n    * In function 1), the decayed base rate will be 0 for 1000 years or > 1000 years\n    * In function 2), the difference in tokens issued at 1000 years and any time > 1000 years, will be negligible\n    */\n    function _decPow(uint256 _base, uint256 _minutes) internal pure returns (uint256) {\n        if (_minutes > 525600000) _minutes = 525600000; // cap to avoid overflow\n\n        if (_minutes == 0) return DECIMAL_PRECISION;\n\n        uint256 y = DECIMAL_PRECISION;\n        uint256 x = _base;\n        uint256 n = _minutes;\n\n        // Exponentiation-by-squaring\n        while (n > 1) {\n            if (n % 2 == 0) {\n                x = decMul(x, x);\n                n = n / 2;\n            } else {\n                // if (n % 2 != 0)\n                y = decMul(x, y);\n                x = decMul(x, x);\n                n = (n - 1) / 2;\n            }\n        }\n\n        return decMul(x, y);\n    }\n\n    function _getAbsoluteDifference(uint256 _a, uint256 _b) internal pure returns (uint256) {\n        return (_a >= _b) ? _a - _b : _b - _a;\n    }\n\n    function _computeCR(uint256 _coll, uint256 _debt, uint256 _price) internal pure returns (uint256) {\n        if (_debt > 0) {\n            uint256 newCollRatio = _coll * _price / _debt;\n\n            return newCollRatio;\n        }\n        // Return the maximal value for uint256 if the debt is 0. Represents \"infinite\" CR.\n        else {\n            // if (_debt == 0)\n            return 2 ** 256 - 1;\n        }\n    }\n}\n"},{"file_path":"lib/bold/contracts/src/Types/BatchId.sol","source_code":"// SPDX-License-Identifier: MIT\n\npragma solidity 0.8.24;\n\ntype BatchId is address;\n\nusing {equals as ==, notEquals as !=, isZero, isNotZero} for BatchId global;\n\nfunction equals(BatchId a, BatchId b) pure returns (bool) {\n    return BatchId.unwrap(a) == BatchId.unwrap(b);\n}\n\nfunction notEquals(BatchId a, BatchId b) pure returns (bool) {\n    return !(a == b);\n}\n\nfunction isZero(BatchId x) pure returns (bool) {\n    return x == BATCH_ID_ZERO;\n}\n\nfunction isNotZero(BatchId x) pure returns (bool) {\n    return !x.isZero();\n}\n\nBatchId constant BATCH_ID_ZERO = BatchId.wrap(address(0));\n"},{"file_path":"lib/bold/contracts/src/Interfaces/IWETH.sol","source_code":"// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.0;\n\nimport \"openzeppelin-contracts/contracts/token/ERC20/extensions/IERC20Metadata.sol\";\n\ninterface IWETH is IERC20Metadata {\n    function deposit() external payable;\n    function withdraw(uint256 wad) external;\n}\n"},{"file_path":"lib/bold/contracts/src/Interfaces/ISortedTroves.sol","source_code":"// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.0;\n\nimport \"./ITroveManager.sol\";\nimport {BatchId, BATCH_ID_ZERO} from \"../Types/BatchId.sol\";\n\ninterface ISortedTroves {\n    // -- Mutating functions (permissioned) --\n    function insert(uint256 _id, uint256 _annualInterestRate, uint256 _prevId, uint256 _nextId) external;\n    function insertIntoBatch(\n        uint256 _troveId,\n        BatchId _batchId,\n        uint256 _annualInterestRate,\n        uint256 _prevId,\n        uint256 _nextId\n    ) external;\n\n    function remove(uint256 _id) external;\n    function removeFromBatch(uint256 _id) external;\n\n    function reInsert(uint256 _id, uint256 _newAnnualInterestRate, uint256 _prevId, uint256 _nextId) external;\n    function reInsertBatch(BatchId _id, uint256 _newAnnualInterestRate, uint256 _prevId, uint256 _nextId) external;\n\n    // -- View functions --\n\n    function contains(uint256 _id) external view returns (bool);\n    function isBatchedNode(uint256 _id) external view returns (bool);\n    function isEmptyBatch(BatchId _id) external view returns (bool);\n\n    function isEmpty() external view returns (bool);\n    function getSize() external view returns (uint256);\n\n    function getFirst() external view returns (uint256);\n    function getLast() external view returns (uint256);\n    function getNext(uint256 _id) external view returns (uint256);\n    function getPrev(uint256 _id) external view returns (uint256);\n\n    function validInsertPosition(uint256 _annualInterestRate, uint256 _prevId, uint256 _nextId)\n        external\n        view\n        returns (bool);\n    function findInsertPosition(uint256 _annualInterestRate, uint256 _prevId, uint256 _nextId)\n        external\n        view\n        returns (uint256, uint256);\n\n    // Public state variable getters\n    function borrowerOperationsAddress() external view returns (address);\n    function troveManager() external view returns (ITroveManager);\n    function size() external view returns (uint256);\n    function nodes(uint256 _id) external view returns (uint256 nextId, uint256 prevId, BatchId batchId, bool exists);\n    function batches(BatchId _id) external view returns (uint256 head, uint256 tail);\n}\n"},{"file_path":"lib/bold/contracts/src/Interfaces/IAddRemoveManagers.sol","source_code":"// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.0;\n\ninterface IAddRemoveManagers {\n    function setAddManager(uint256 _troveId, address _manager) external;\n    function setRemoveManager(uint256 _troveId, address _manager) external;\n    function setRemoveManagerWithReceiver(uint256 _troveId, address _manager, address _receiver) external;\n    function addManagerOf(uint256 _troveId) external view returns (address);\n    function removeManagerReceiverOf(uint256 _troveId) external view returns (address, address);\n}\n"},{"file_path":"lib/bold/contracts/lib/openzeppelin-contracts/contracts/utils/introspection/IERC165.sol","source_code":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Interface of the ERC165 standard, as defined in the\n * https://eips.ethereum.org/EIPS/eip-165[EIP].\n *\n * Implementers can declare support of contract interfaces, which can then be\n * queried by others ({ERC165Checker}).\n *\n * For an implementation, see {ERC165}.\n */\ninterface IERC165 {\n    /**\n     * @dev Returns true if this contract implements the interface defined by\n     * `interfaceId`. See the corresponding\n     * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]\n     * to learn more about how these ids are created.\n     *\n     * This function call must use less than 30 000 gas.\n     */\n    function supportsInterface(bytes4 interfaceId) external view returns (bool);\n}\n"},{"file_path":"lib/bold/contracts/src/Interfaces/IActivePool.sol","source_code":"// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.0;\n\nimport \"./IInterestRouter.sol\";\nimport \"./IBoldRewardsReceiver.sol\";\nimport \"../Types/TroveChange.sol\";\n\ninterface IActivePool {\n    function defaultPoolAddress() external view returns (address);\n    function borrowerOperationsAddress() external view returns (address);\n    function troveManagerAddress() external view returns (address);\n    function interestRouter() external view returns (IInterestRouter);\n    // We avoid IStabilityPool here in order to prevent creating a dependency cycle that would break flattening\n    function stabilityPool() external view returns (IBoldRewardsReceiver);\n\n    function getCollBalance() external view returns (uint256);\n    function getBoldDebt() external view returns (uint256);\n    function lastAggUpdateTime() external view returns (uint256);\n    function aggRecordedDebt() external view returns (uint256);\n    function aggWeightedDebtSum() external view returns (uint256);\n    function aggBatchManagementFees() external view returns (uint256);\n    function aggWeightedBatchManagementFeeSum() external view returns (uint256);\n    function calcPendingAggInterest() external view returns (uint256);\n    function calcPendingSPYield() external view returns (uint256);\n    function calcPendingAggBatchManagementFee() external view returns (uint256);\n    function getNewApproxAvgInterestRateFromTroveChange(TroveChange calldata _troveChange)\n        external\n        view\n        returns (uint256);\n\n    function mintAggInterest() external;\n    function mintAggInterestAndAccountForTroveChange(TroveChange calldata _troveChange, address _batchManager)\n        external;\n    function mintBatchManagementFeeAndAccountForChange(TroveChange calldata _troveChange, address _batchAddress)\n        external;\n\n    function setShutdownFlag() external;\n    function hasBeenShutDown() external view returns (bool);\n    function shutdownTime() external view returns (uint256);\n\n    function sendColl(address _account, uint256 _amount) external;\n    function sendCollToDefaultPool(uint256 _amount) external;\n    function receiveColl(uint256 _amount) external;\n    function accountForReceivedColl(uint256 _amount) external;\n}\n"},{"file_path":"lib/bold/contracts/src/Interfaces/ICollSurplusPool.sol","source_code":"// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.0;\n\ninterface ICollSurplusPool {\n    function getCollBalance() external view returns (uint256);\n\n    function getCollateral(address _account) external view returns (uint256);\n\n    function accountSurplus(address _account, uint256 _amount) external;\n\n    function claimColl(address _account) external;\n}\n"},{"file_path":"lib/bold/contracts/src/Types/TroveChange.sol","source_code":"// SPDX-License-Identifier: MIT\n\npragma solidity 0.8.24;\n\nstruct TroveChange {\n    uint256 appliedRedistBoldDebtGain;\n    uint256 appliedRedistCollGain;\n    uint256 collIncrease;\n    uint256 collDecrease;\n    uint256 debtIncrease;\n    uint256 debtDecrease;\n    uint256 newWeightedRecordedDebt;\n    uint256 oldWeightedRecordedDebt;\n    uint256 upfrontFee;\n    uint256 batchAccruedManagementFee;\n    uint256 newWeightedRecordedBatchManagementFee;\n    uint256 oldWeightedRecordedBatchManagementFee;\n}\n"},{"file_path":"lib/bold/contracts/lib/openzeppelin-contracts/contracts/interfaces/IERC5267.sol","source_code":"// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.0) (interfaces/IERC5267.sol)\n\npragma solidity ^0.8.0;\n\ninterface IERC5267 {\n    /**\n     * @dev MAY be emitted to signal that the domain could have changed.\n     */\n    event EIP712DomainChanged();\n\n    /**\n     * @dev returns the fields and values that describe the domain separator used by this contract for EIP-712\n     * signature.\n     */\n    function eip712Domain()\n        external\n        view\n        returns (\n            bytes1 fields,\n            string memory name,\n            string memory version,\n            uint256 chainId,\n            address verifyingContract,\n            bytes32 salt,\n            uint256[] memory extensions\n        );\n}\n"},{"file_path":"lib/bold/contracts/src/Types/LatestBatchData.sol","source_code":"// SPDX-License-Identifier: MIT\n\npragma solidity 0.8.24;\n\nstruct LatestBatchData {\n    uint256 totalDebtShares;\n    uint256 entireDebtWithoutRedistribution;\n    uint256 entireCollWithoutRedistribution;\n    uint256 accruedInterest;\n    uint256 recordedDebt;\n    uint256 annualInterestRate;\n    uint256 weightedRecordedDebt;\n    uint256 annualManagementFee;\n    uint256 accruedManagementFee;\n    uint256 weightedRecordedBatchManagementFee;\n    uint256 lastDebtUpdateTime;\n    uint256 lastInterestRateAdjTime;\n}\n"}],"is_verified_via_sourcify":false,"can_be_visualized_via_sol2uml":true,"evm_version":"cancun","language":"solidity","is_verified_via_eth_bytecode_db":false,"is_fully_verified":false,"license_type":"none","is_blueprint":false,"name":"TroveManager","creation_bytecode":"0x60c060405234801562000010575f80fd5b5060405162006a4838038062006a4883398101604081905262000033916200099d565b81806001600160a01b0316637f7dde4a6040518163ffffffff1660e01b8152600401602060405180830381865afa15801562000071573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190620000979190620009da565b5f806101000a8154816001600160a01b0302191690836001600160a01b03160217905550806001600160a01b0316633cc742256040518163ffffffff1660e01b8152600401602060405180830381865afa158015620000f8573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906200011e9190620009da565b60015f6101000a8154816001600160a01b0302191690836001600160a01b03160217905550806001600160a01b031663741bef1a6040518163ffffffff1660e01b8152600401602060405180830381865afa15801562000180573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190620001a69190620009da565b600280546001600160a01b0319166001600160a01b039283161790555f546040517f78f058b189175430c48dc02699e3a0031ea4ff781536dc2fab847de4babdd88292620001f6921690620009ff565b60405180910390a16001546040517f5ee0cae2f063ed938bb55046f6a932fb6ae792bf43624806bb90abe68a50be9b916200023d916001600160a01b0390911690620009ff565b60405180910390a16002546040517f8c537274438aa850a330284665d81a85dd38267d09e4050d416bfc94142db2649162000284916001600160a01b0390911690620009ff565b60405180910390a150806001600160a01b031660a0816001600160a01b031681525050816001600160a01b031663059e01136040518163ffffffff1660e01b8152600401602060405180830381865afa158015620002e4573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906200030a9190620009da565b60035f6101000a8154816001600160a01b0302191690836001600160a01b03160217905550816001600160a01b03166377553ad46040518163ffffffff1660e01b8152600401602060405180830381865afa1580156200036c573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190620003929190620009da565b600480546001600160a01b0319166001600160a01b039283161781556040805163048c661d60e01b815290519285169263048c661d928281019260209291908290030181865afa158015620003e9573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906200040f9190620009da565b60055f6101000a8154816001600160a01b0302191690836001600160a01b03160217905550816001600160a01b031663fe9d03236040518163ffffffff1660e01b8152600401602060405180830381865afa15801562000471573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190620004979190620009da565b60065f6101000a8154816001600160a01b0302191690836001600160a01b03160217905550816001600160a01b031663cda775f96040518163ffffffff1660e01b8152600401602060405180830381865afa158015620004f9573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906200051f9190620009da565b60075f6101000a8154816001600160a01b0302191690836001600160a01b03160217905550816001600160a01b031663630afce56040518163ffffffff1660e01b8152600401602060405180830381865afa15801562000581573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190620005a79190620009da565b60085f6101000a8154816001600160a01b0302191690836001600160a01b03160217905550816001600160a01b031663ae9187546040518163ffffffff1660e01b8152600401602060405180830381865afa15801562000609573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906200062f9190620009da565b60095f6101000a8154816001600160a01b0302191690836001600160a01b03160217905550816001600160a01b031663c91d59fe6040518163ffffffff1660e01b8152600401602060405180830381865afa15801562000691573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190620006b79190620009da565b6001600160a01b03166080816001600160a01b031681525050816001600160a01b031663d330fadd6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156200070d573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190620007339190620009da565b600a80546001600160a01b0319166001600160a01b039283161790556003546040517f39b3d3f08f5292d52497444fc183b3915a339c0b41fb021bf52ae59505e455b29262000784921690620009ff565b60405180910390a16004546040517f3ca631ffcd2a9b5d9ae18543fc82f58eb4ca33af9e6ab01b7a8e95331e6ed98591620007cb916001600160a01b0390911690620009ff565b60405180910390a16005546040517f82966d27eea39b038ee0fa30cd16532bb24f6e65d31cb58fb227aa5766cdcc7f9162000812916001600160a01b0390911690620009ff565b60405180910390a16006546040517fcfb07d791fcafc032b35837b50eb84b74df518cf4cc287e8084f47630fa70fa09162000859916001600160a01b0390911690620009ff565b60405180910390a16007546040517fe67f36a6e961157d6eff83b91f3af5a62131ceb6f04954ef74f51c1c05e7f88d91620008a0916001600160a01b0390911690620009ff565b60405180910390a16008546040517f28fe9b1bb8b27b863bb5635cb5bbd4e1beb7af490191ba03efe587680895b4fd91620008e7916001600160a01b0390911690620009ff565b60405180910390a16009546040517f65f4cf077bc01e4742eb5ad98326f6e95b63548ea24b17f8d5e823111fe78800916200092e916001600160a01b0390911690620009ff565b60405180910390a1600a546040517f4f8a3037ce0d3c62ab7c79fec792f6db7216b27b94e09faf499753381c33f8479162000975916001600160a01b0390911690620009ff565b60405180910390a1505062000a13565b6001600160a01b03811681146200099a575f80fd5b50565b5f8060408385031215620009af575f80fd5b8251620009bc8162000985565b6020840151909250620009cf8162000985565b809150509250929050565b5f60208284031215620009eb575f80fd5b8151620009f88162000985565b9392505050565b6001600160a01b0391909116815260200190565b60805160a051615fdb62000a6d5f395f81816110120152818161223e01528181613ca60152818161416101528181614f4601528181615132015281816151f20152818161526801526152f201525f613ff30152615fdb5ff3fe608060405234801561000f575f80fd5b50600436106101b5575f3560e01c806301540287146101b9578063048c661d146101d5578063059e0113146101f55780630f83069314610208578063105b403b1461021d5780631ca2d7d9146102255780631cf74075146102385780631d7be8001461024b5780631ef11b621461025e57806338116fa3146102715780633ecaaa3f14610284578063499b069f1461028c5780634aff96e11461029f5780634ea15f37146102a757806358569081146102cc5780635d648588146102d55780635ef3b8bf14610310578063613cacae146103235780636daed00014610343578063735ab2a41461035657806377553ad4146103695780637f7dde4a1461037c578063a411219c1461038e578063aad3f40414610422578063ae918754146104ad578063b0141775146104c0578063b3d346b9146104d3578063b3e16c30146104e6578063b5a672c2146104f9578063bf49e6491461050c578063c067e95c1461051f578063c2020f0414610532578063ca0ca8d214610545578063e47bfaf114610558578063ef49a6b41461058a578063f8a239e81461059d578063fc0e74d1146105b0575b5f80fd5b6101c260155481565b6040519081526020015b60405180910390f35b6005546101e8906001600160a01b031681565b6040516101cc919061551c565b6003546101e8906001600160a01b031681565b61021b610216366004615547565b6105b8565b005b6101c26106d3565b61021b6102333660046156aa565b6107c8565b61021b61024636600461570e565b610a46565b61021b610259366004615774565b610bd5565b6101c261026c3660046157b2565b610cff565b61021b61027f3660046157b2565b610d23565b6101c2610d58565b61021b61029a3660046157c9565b610e16565b6013546101c2565b6102af610ef8565b6040805193845260208401929092521515908201526060016101cc565b6101c260185481565b6102fb6102e33660046157b2565b60126020525f90815260409020805460019091015482565b604080519283526020830191909152016101cc565b6101c261031e3660046157b2565b6110b6565b6103366103313660046157fb565b6111ca565b6040516101cc9190615894565b61021b6103513660046158a3565b6111e1565b61021b6103643660046158e3565b611284565b6004546101e8906001600160a01b031681565b5f546101e8906001600160a01b031681565b61040c61039c3660046157b2565b600b6020525f9081526040902080546001820154600283015460038401546004850154600586015460069096015494959394929360ff8316936001600160401b036101008504811694600160481b8104821694600160881b9091049091169290916001600160a01b03909116908a565b6040516101cc9a9998979695949392919061595c565b6104356104303660046157b2565b6113ac565b6040516101cc91905f61014082019050825182526020830151602083015260408301516040830152606083015160608301526080830151608083015260a083015160a083015260c083015160c083015260e083015160e083015261010080840151818401525061012080840151818401525092915050565b6009546101e8906001600160a01b031681565b61021b6104ce3660046159c7565b6113be565b6101e86104e13660046157b2565b6115ab565b61021b6104f4366004615a0d565b6115d3565b61021b610507366004615a1e565b611979565b61021b61051a366004615a80565b611b4e565b6101c261052d366004615aed565b611cba565b61021b610540366004615b0d565b611ce9565b61021b610553366004615b8a565b612080565b61057d6105663660046157b2565b5f908152600b602052604090206003015460ff1690565b6040516101cc9190615bc2565b61021b610598366004615bd0565b612115565b6101c26105ab3660046158a3565b61253b565b61021b612a2e565b6105c0612a91565b5f858152600b6020908152604090912060018082018790558582556004820185905560039091018054600160481b600160c81b031916600160481b426001600160401b0316908102600160881b600160c81b03191691909117600160881b9190910217905554610641916001600160a01b0390911690833590840135612abe565b61064a85612b7b565b5f858152600b60205260409081902060020154601054601154925188935f80516020615ee6833981519152936106869389938b938a9291615c70565b60405180910390a2845f80516020615f46833981519152600384845f01358561010001355f87602001355f6040516106c49796959493929190615ca8565b60405180910390a25050505050565b5f8054604080516308aa0f3360e31b8152905183926001600160a01b03169163455079989160048083019260209291908290030181865afa15801561071a573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061073e9190615ce6565b90505f60015f9054906101000a90046001600160a01b03166001600160a01b031663455079986040518163ffffffff1660e01b8152600401602060405180830381865afa158015610791573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906107b59190615ce6565b90506107c18183615d11565b9250505090565b6107d0612a91565b5f6107de8560400151612b9a565b6040868101515f898152600b602052919091206001808201929092556002810183905560038101805460ff19811684178255601354600590930180546001600160a01b0319166001600160a01b038b161790556001600160481b03600160881b03600160c81b0319166101006001600160401b0393841602600160881b600160c81b03191617600160881b429390931692909202919091179091179055905061088686612b7b565b601380546001810182555f919091525f80516020615f068339815191520186905560808501516108b8576108b8615d24565b6108cc868587886080015187876001612bcd565b5f81600d546108db9190615d11565b600d8190556003546040516340c10f1960e01b81529192506001600160a01b0316906340c10f1990610913908b908b90600401615d38565b5f604051808303815f87803b15801561092a575f80fd5b505af115801561093c573d5f803e3d5ffd5b50505050865f80516020615f2683398151915286600b5f8b81526020019081526020015f206006015489604001518660105460115460405161098396959493929190615d51565b60405180910390a26001600160a01b0385165f908152600c60205260408082206003015461010089015160808a01518a84015193518c955f80516020615f46833981519152956109de95600795909492939092918491615ca8565b60405180910390a26001600160a01b0385165f818152600c602052604080822080546001820154600383015460048481015460059095015495515f80516020615f6683398151915297610a349792969291615d94565b60405180910390a25050505050505050565b610a4e612a91565b5f878152600b60205260409020600101869055610a6a87612b7b565b5f610a758888612f54565b90505f8611610a8657610a86615d24565b610a968885878987876001612bcd565b60015485516020870151610ab4926001600160a01b03169190612abe565b875f80516020615f2683398151915285600b5f8c81526020019081526020015f20600601548a85601054601154604051610af396959493929190615d51565b60405180910390a2875f80516020615f468339815191526002600c5f886001600160a01b03166001600160a01b031681526020019081526020015f2060030154885f01518961010001518a60a001518b60800151610b519190615da2565b8b602001518c606001518d60400151610b6a9190615da2565b604051610b7d9796959493929190615ca8565b60405180910390a26001600160a01b0384165f818152600c6020526040808220805460018201546003830154600484015460059094015494515f80516020615f6683398151915296610a349660069692909190615d94565b610bdd612a91565b5f848152600b60209081526040909120600180820186905584825560039091018054600160481b600160881b031916600160481b426001600160401b03160217905554610c3b916001600160a01b0390911690833590840135612abe565b5f610c468585612f54565b9050610c5185612b7b565b5f858152600b60205260409081902060040154601054601154925188935f80516020615ee683398151915293610c8e9389938b9389939291615c70565b60405180910390a25f858152600b602052604090206004015485905f80516020615f46833981519152906002908535610100870135610cd560a089013560808a0135615da2565b6020890135610cec60608b013560408c0135615da2565b6040516106c49796959493929190615ca8565b5f60138281548110610d1357610d13615dc8565b905f5260205f2001549050919050565b610d2b612a91565b5f818152600b60205260409020600301805460ff19166001179055601554819003610d55575f6015555b50565b5f8054604080516301b3d98160e11b8152905183926001600160a01b031691630367b3029160048083019260209291908290030181865afa158015610d9f573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610dc39190615ce6565b90505f60015f9054906101000a90046001600160a01b03166001600160a01b0316630367b3026040518163ffffffff1660e01b8152600401602060405180830381865afa158015610791573d5f803e3d5ffd5b610e1e612a91565b601480546001600160a01b0385165f818152600c6020526040808220600281018054600383018a90556004909201889055426001600160401b03908116600160801b026001600160401b03600160801b03600160c01b03199093169616959095171790935583546001810185559381527fce6d7b5282bd9a3661ae061feed1dbda4e52ab073b1f9285be6e155d9c38d4ec90930180546001600160a01b03191682179055905190915f80516020615f6683398151915291610eeb9190819081908890889083908190615d94565b60405180910390a2505050565b5f805f80610f046106d3565b90505f60055f9054906101000a90046001600160a01b03166001600160a01b031663f71c69406040518163ffffffff1660e01b8152600401602060405180830381865afa158015610f57573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610f7b9190615ce6565b90505f818311610f8b575f610f95565b610f958284615ddc565b90505f60025f9054906101000a90046001600160a01b03166001600160a01b0316630fdb11cf6040518163ffffffff1660e01b81526004016020604051808303815f875af1158015610fe9573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061100d9190615ce6565b90505f7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166358d5a9616040518163ffffffff1660e01b8152600401602060405180830381865afa15801561106c573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906110909190615ce6565b61109983612f9c565b101580156110a75750601854155b92989197509195509350505050565b5f818152600b6020908152604080832081516101408101835281548152600182015493810193909352600281015491830191909152600381015483929190606083019060ff16600481111561110d5761110d615934565b600481111561111e5761111e615934565b815260038201546001600160401b03610100820481166020840152600160481b820481166040840152600160881b9091041660608201526004820154608082015260058201546001600160a01b031660a082015260069091015460c09091015290505f61118d82610100015190565b90506001600160a01b038116156111bf576001600160a01b03165f908152600c60205260409020600301549392505050565b5060e0015192915050565b6111d26153ce565b6111dc8282612fc6565b919050565b6111e9612a91565b6001600160a01b0385165f818152600c602052604090819020600181018790558581556003810185905560028082018054600160401b600160c01b031916600160401b426001600160401b0316908102600160801b600160c01b03191691909117600160801b91909102179055600482015460059092015492515f80516020615f66833981519152936106c49389928b928a92918a90615d94565b61128c612a91565b61129b85858585856002613131565b600154845160208601516112b9926001600160a01b03169190612abe565b845f80516020615ee68339815191525f805f805f806040516112e096959493929190615c70565b60405180910390a2845f80516020615f4683398151915260015f875f01518861010001518960a001518a608001516113189190615da2565b8a602001518b606001518c604001516113319190615da2565b6040516113449796959493929190615ca8565b60405180910390a26001600160a01b038316156113a5576001600160a01b0383165f818152600c6020526040808220805460018201546003830154600484015460059485015495515f80516020615f66833981519152976106c49791615d94565b5050505050565b6113b4615423565b6111dc82826134a4565b6113c6612a91565b5f6113d48360400151612b9a565b905082610100015183608001516113eb9190615d11565b5f858152600b60205260408082209283558501516001808401919091556002830184905560038301805460ff19811683178255601380546001600160881b03199092166101006001600160401b0393841602600160481b600160881b03191617600160481b4293909316928302178417600160881b600160c81b031916600160881b92909202919091179091556004909301859055825490810183559181525f80516020615f06833981519152909101859055600d546114ac908390615d11565b600d8190556003546040516340c10f1960e01b81529192506001600160a01b0316906340c10f19906114e49089908990600401615d38565b5f604051808303815f87803b1580156114fb575f80fd5b505af115801561150d573d5f803e3d5ffd5b5050505061151a85612b7b565b845f80516020615ee6833981519152856101000151866080015161153e9190615d11565b8660400151858760105460115460405161155d96959493929190615c70565b60405180910390a2845f80516020615f468339815191525f855f88610100015189608001515f8b6040015160405161159b9796959493929190615ca8565b60405180910390a2505050505050565b601481815481106115ba575f80fd5b5f918252602090912001546001600160a01b0316905081565b6115db612a91565b5f6115ee36839003830160608401615def565b90506115fa8235612b7b565b81355f908152600b6020908152604082208281556004810192909255600382018054600160481b600160881b031916905583013560019091015561164661020083016101e084016157fb565b82355f908152600b602090815260409091206005810180546001600160a01b0319166001600160a01b03949094169390931790925560039091018054600160881b600160c81b031916600160881b426001600160401b031602179055818101516116b291840135615ddc565b604080830191909152610100820151825190916116d29190850135615ddc565b6116dc9190615ddc565b608082015260408201356116f2576116f2615d24565b611722823561170961020085016101e086016157fb565b8385604001358661020001358761022001356001612bcd565b60015481516020830151611740926001600160a01b03169190612abe565b81355f80516020615f2683398151915261176261020085016101e086016157fb565b84355f908152600b602090815260409182902060068101546002909101546010546011549451611799969593948b01359390615d51565b60405180910390a281355f80516020615f468339815191526008600c5f6117c861020088016101e089016157fb565b6001600160a01b03166001600160a01b031681526020019081526020015f2060030154845f01518561010001515f87602001515f60405161180f9796959493929190615ca8565b60405180910390a261182961020083016101e084016157fb565b6001600160a01b03165f80516020615f668339815191526004600c5f61185761020088016101e089016157fb565b6001600160a01b0316815260208101919091526040015f9081205490600c9061188861020089016101e08a016157fb565b6001600160a01b03166001600160a01b031681526020019081526020015f2060010154600c5f886101e00160208101906118c291906157fb565b6001600160a01b03166001600160a01b031681526020019081526020015f2060030154600c5f896101e00160208101906118fc91906157fb565b6001600160a01b03166001600160a01b031681526020019081526020015f2060040154600c5f8a6101e001602081019061193691906157fb565b6001600160a01b03166001600160a01b031681526020019081526020015f20600501545f60405161196d9796959493929190615d94565b60405180910390a25050565b611981612a91565b5f878152600b602052604090206001018690556001600160a01b03841615611a2b575f85116119b2576119b2615d24565b6119d087856119c636859003850185615def565b8887876001612bcd565b6001600160a01b0384165f818152600c6020526040808220600381810154600483015460059093015493515f80516020615f6683398151915295611a1e9593948a948c949391929091615d94565b60405180910390a2611a61565b5f878152600b602052604090208581556003018054600160481b600160881b031916600160481b426001600160401b0316021790555b600154611a7d906001600160a01b031682356020840135612abe565b611a8687612b7b565b5f878152600b602052604090819020600281015460049091015460105460115493518b945f80516020615ee683398151915294611acd948c948e9492939192909190615c70565b60405180910390a25f878152600b6020526040902060049081015488915f80516020615f46833981519152918435610100860135611b1360a08801356080890135615da2565b6020880135611b2a60608a013560408b0135615da2565b604051611b3d9796959493929190615ca8565b60405180910390a250505050505050565b611b56612a91565b611b658888888888888861365b565b5f888152600b60205260409020868155600181018890556003810180546004909201839055600160481b600160c81b0319909116600160481b426001600160401b0316908102600160881b600160c81b03191691909117600160881b91909102179055611bd188612b7b565b60015485516020870151611bef926001600160a01b03169190612abe565b5f888152600b6020526040908190206002015460105460115492518b935f80516020615ee683398151915293611c2b938c938e93899291615c70565b60405180910390a2845161010086015160208701516040518b935f80516020615f4683398151915293611c6893600993889392915f918290615ca8565b60405180910390a26001600160a01b0384165f818152600c6020526040808220805460018201546003830154600484015460059485015495515f80516020615f6683398151915297610a349791615d94565b5f611cc3615423565b611ccd84826134a4565b611cdf8160200151825f01518561382f565b9150505b92915050565b611cf161385f565b611cfa84613881565b600854611d11906001600160a01b031633866138a1565b5f546001600160a01b0316611d246153ce565b60025460408051630fdb11cf60e01b815290515f926001600160a01b031691630fdb11cf916004808301926020929190829003018187875af1158015611d6c573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611d909190615ce6565b9050865f5b86811015611eee578115611eee57611dab61546c565b888883818110611dbd57611dbd615dc8565b6020029190910135808352610140830151611dd892506134a4565b80515f908152600b6020526040902060030154611df79060ff16613931565b1580611e07575061014081015151155b15611e125750611ee6565b8051611e1d90613968565b6001600160a01b03166020820181905215611e4057611e40868260200151613985565b600154611e58906001600160a01b0316848684613a9c565b806060015185606001818151611e6e9190615d11565b905250604081015160a086018051611e87908390615d11565b90525060a081015185518690611e9e908390615d11565b90525060e081015160c086018051611eb7908390615d11565b90525060c081015160e086018051611ed0908390615d11565b9052506040810151611ee29084615ddc565b9250505b600101611d95565b508483606001511015611f2557826060015160405163de7c5c2d60e01b8152600401611f1c91815260200190565b60405180910390fd5b60a083015160608401516040515f80516020615f8683398151915292611f52928c925f9088908190615c70565b60405180910390a16040516371d4eb2160e01b81526001600160a01b038516906371d4eb2190611f889086905f90600401615e0a565b5f604051808303815f87803b158015611f9f575f80fd5b505af1158015611fb1573d5f803e3d5ffd5b505050506060830151604051634fa7288f60e11b81526001600160a01b03861691639f4e511e91611fe6913391600401615d38565b5f604051808303815f87803b158015611ffd575f80fd5b505af115801561200f573d5f803e3d5ffd5b505060085460a0860151604051632770a7eb60e21b81526001600160a01b039092169350639dc29fac925061204991339190600401615d38565b5f604051808303815f87803b158015612060575f80fd5b505af1158015612072573d5f803e3d5ffd5b505050505050505050505050565b612088612a91565b6001600160a01b0384165f818152600c6020526040808220600180820188905586825560048201869055600282018054600160401b600160801b031916600160401b426001600160401b031602179055600382015460059092015492515f80516020615f668339815191529461210794929389938b9391928a92615d94565b60405180910390a250505050565b61211d613b9b565b80515f0361213e576040516399d8fec960e01b815260040160405180910390fd5b5f546001546005546001600160a01b0392831692918216911661215f6153ce565b6121676154d9565b60025460408051630fdb11cf60e01b815290515f926001600160a01b031691630fdb11cf916004808301926020929190829003018187875af11580156121af573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906121d39190615ce6565b90505f846001600160a01b031663f71c69406040518163ffffffff1660e01b8152600401602060405180830381865afa158015612212573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906122369190615ce6565b90505f6122c27f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663d5cf2c576040518163ffffffff1660e01b8152600401602060405180830381865afa158015612298573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906122bc9190615ce6565b83613c2c565b90505f6122cf8284615ddc565b90506122df8885838d898b613c41565b8560a001515f0361230357604051638c20998d60e01b815260040160405180910390fd5b6040516371d4eb2160e01b81526001600160a01b038a16906371d4eb21906123319089905f90600401615e0a565b5f604051808303815f87803b158015612348575f80fd5b505af115801561235a573d5f803e3d5ffd5b505050505f8560200151118061237357505f8560400151115b156123e3576020850151604080870151905163335525ad60e01b81526001600160a01b038a169263335525ad926123b592600401918252602082015260400190565b5f604051808303815f87803b1580156123cc575f80fd5b505af11580156123de573d5f803e3d5ffd5b505050505b6123f7898987606001518860800151613d74565b60a0850151156124675760075460a0860151604051634fa7288f60e11b81526001600160a01b038c811693639f4e511e93612439939290911691600401615d38565b5f604051808303815f87803b158015612450575f80fd5b505af1158015612462573d5f803e3d5ffd5b505050505b61247489865f0151613ebb565b7f7243af9a1cff94d3429b2ee00b78c1c10589259f20dc167cb67704f38f9e824e856020015186606001518760c00151885f015189604001518a608001518b60a001516010546011548d6040516125149a99989796959493929190998a5260208a019890985260408901969096526060880194909452608087019290925260a086015260c085015260e08401526101008301526101208201526101400190565b60405180910390a161252f89338760c00151885f0151613fbc565b50505050505050505050565b5f612544614095565b5f546009546001600160a01b03918216911661255e6153ce565b61258e60405180608001604052805f81526020015f81526020015f6001600160a01b031681526020015f81525090565b6020810189905261259d61546c565b601554156125b7576015548152600161012082015261261a565b836001600160a01b0316634d6228316040518163ffffffff1660e01b8152600401602060405180830381865afa1580156125f3573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906126179190615ce6565b81525b5f60408381018290526002548151630fdb11cf60e01b815291516001600160a01b0390911691630fdb11cf916004808301926020929190829003018187875af1158015612669573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061268d9190615ce6565b9050875f0361269b575f1997505b8151158015906126ae57505f8360200151115b80156126b957505f88115b1561292657876126c881615e32565b9850508161012001511561274057846001600160a01b0316634d6228316040518163ffffffff1660e01b8152600401602060405180830381865afa158015612712573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906127369190615ce6565b60608401526127b0565b815160405163040de97d60e21b815260048101919091526001600160a01b03861690631037a5f490602401602060405180830381865afa158015612786573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906127aa9190615ce6565b60608401525b670de0b6b3a76400006127c6835f01518c611cba565b10156127df57606083015182525f61012083015261269b565b81516127ea90613968565b6001600160a01b03166020830181905215801590612822575082604001516001600160a01b031682602001516001600160a01b031614155b1561284957612835868360200151613985565b60208201516001600160a01b031660408401525b6001546020840151612868916001600160a01b0316908490848d6140c0565b81606001518460600181815161287e9190615d11565b905250604082015160a085018051612897908390615d11565b90525060a0820151845185906128ae908390615d11565b90525060e082015160c0850180516128c7908390615d11565b90525060c082015160e0850180516128e0908390615d11565b9052506080820151835184906128f7908390615d11565b9052506040820151602084018051612910908390615ddc565b905250606083015182525f61012083015261269b565b5f80516020615f868339815191528b8560a001518660600151865f01518e8660405161295796959493929190615c70565b60405180910390a16040516371d4eb2160e01b81526001600160a01b038716906371d4eb219061298d9087905f90600401615e0a565b5f604051808303815f87803b1580156129a4575f80fd5b505af11580156129b6573d5f803e3d5ffd5b50505050856001600160a01b0316639f4e511e8d86606001516040518363ffffffff1660e01b81526004016129ec929190615d38565b5f604051808303815f87803b158015612a03575f80fd5b505af1158015612a15573d5f803e3d5ffd5b50505060a0909401519c9b505050505050505050505050565b612a36612a91565b426018555f805460408051636d8f962d60e01b815290516001600160a01b0390921692636d8f962d9260048084019382900301818387803b158015612a79575f80fd5b505af1158015612a8b573d5f803e3d5ffd5b50505050565b6004546001600160a01b03163314612abc5760405163558b0d1f60e01b815260040160405180910390fd5b565b8115612b1a576040516330588f6f60e21b8152600481018390526001600160a01b0384169063c1623dbc906024015f604051808303815f87803b158015612b03575f80fd5b505af1158015612b15573d5f803e3d5ffd5b505050505b8015612b7657604051631eaed73d60e11b8152600481018290526001600160a01b03841690633d5dae7a906024015f604051808303815f87803b158015612b5f575f80fd5b505af1158015612b71573d5f803e3d5ffd5b505050505b505050565b6010545f91825260126020526040909120908155601154600190910155565b5f80600f545f03612bac575081611ce3565b600f54600e54612bbc9085615e47565b612bc69190615e5e565b9392505050565b6001600160a01b0386165f908152600c602052604081206005015486516101008801516080890151929392839291612c0491615d11565b612c0e9190615d11565b90505f8860a00151821115612c335760a0890151612c2c9083615ddc565b9150612c49565b818960a00151612c439190615ddc565b90505f91505b81158015612c55575080155b15612c79576001600160a01b038a165f908152600c60205260409020869055612e2a565b8115612d2357855f03612c8e57819250612cb1565b612c99848787614301565b85612ca48386615e47565b612cae9190615e5e565b92505b5f8b8152600b602052604081206006018054859290612cd1908490615d11565b90915550612ce190508287615d11565b6001600160a01b038b165f908152600c6020526040902055612d038385615d11565b6001600160a01b038b165f908152600c6020526040902060050155612e2a565b8015612e2a57875f03612da257612d3a8187615ddc565b6001600160a01b038b165f908152600c60209081526040808320939093558d8252600b90522060060154612d6e9085615ddc565b6001600160a01b038b165f908152600c60209081526040808320600501939093558d8252600b905290812060060155612e2a565b85612dad8286615e47565b612db79190615e5e565b925082600b5f8d81526020019081526020015f206006015f828254612ddc9190615ddc565b90915550612dec90508187615ddc565b6001600160a01b038b165f908152600c6020526040902055612e0e8385615ddc565b6001600160a01b038b165f908152600c60205260409020600501555b6001600160a01b038a165f908152600c602090815260408083206002018054600160401b600160801b031916600160401b426001600160401b031602179055908b0151908b0151612e7b9190615d11565b90505f8a60600151821115612ea05760608b0151612e999083615ddc565b9150612eb6565b818b60600151612eb09190615ddc565b90505f91505b81158015612ec2575080155b15612ee9576001600160a01b038c165f908152600c60205260409020600101899055612f45565b8115612f1957612ef9828a615d11565b6001600160a01b038d165f908152600c6020526040902060010155612f45565b8015612f4557612f29818a615ddc565b6001600160a01b038d165f908152600c60205260409020600101555b50505050505050505050505050565b5f612f5e82612b9a565b5f848152600b60205260409020600201805490829055600d54919250908290612f88908390615ddc565b612f929190615d11565b600d555092915050565b5f80612fa6610d58565b90505f612fb16106d3565b9050612fbe82828661382f565b949350505050565b6001600160a01b0382165f908152600c60209081526040918290208251610100810184528154815260018201549281019290925260028101546001600160401b0380821694840194909452600160401b810484166060840152600160801b9004909216608080830191909152600383015460a0808401918252600485015460c085015260059094015460e084018190528552825191850182905251928401839052909161307291615e47565b60c083015260608101515f90613090906001600160401b0316614338565b90506130a08360c0015182614378565b606084015260c082015160e0840181905260808401516130c09190615e47565b61012084018190526130d29082614378565b6101008401819052606084015160808501516130ee9190615d11565b6130f89190615d11565b60208085019190915282015160408401525060608101516001600160401b03908116610140840152608090910151166101609091015250565b60135460185415806131545750600382600481111561315257613152615934565b145b15613162576131628161439b565b61316c87826143bc565b5f878152600b60209081526040808320815161014081018352815481526001820154938101939093526002810154918301919091526003810154606083019060ff1660048111156131bf576131bf615934565b60048111156131d0576131d0615934565b815260038201546001600160401b03610100820481166020840152600160481b820481166040840152600160881b9091041660608201526004820154608082015260058201546001600160a01b0390811660a083015260069092015460c0909101529091508616156133035760018160600151600481111561325457613254615934565b036132b75760095460405163f476125960e01b8152600481018a90526001600160a01b039091169063f4761259906024015f604051808303815f87803b15801561329c575f80fd5b505af11580156132ae573d5f803e3d5ffd5b505050506132e7565b6004816060015160048111156132cf576132cf615934565b1480156132dd575087601554145b156132e7575f6015555b6132fe8888606001518960a001518a8a8a8a61365b565b6133ae565b60018160600151600481111561331b5761331b615934565b0361337e57600954604051634cc8221560e01b8152600481018a90526001600160a01b0390911690634cc82215906024015f604051808303815f87803b158015613363575f80fd5b505af1158015613375573d5f803e3d5ffd5b505050506133ae565b60048160600151600481111561339657613396615934565b1480156133a4575087601554145b156133ae575f6015555b5f8160400151600d546133c19190615ddc565b600d8190555f8a8152600b602052604081208181556001808201839055600282018390556003820180546001600160c81b03191680825560048085018690556005850180546001600160a01b031916905560069094019490945593945087939291849081111561343357613433615934565b02179055505f89815260126020526040808220828155600101919091556003549051630852cd8d60e31b8152600481018b90526001600160a01b03909116906342966c68906024015f604051808303815f87803b158015613492575f80fd5b505af1158015612f45573d5f803e3d5ffd5b5f6134ae83613968565b90506001600160a01b038116156134dc576134c76153ce565b6134d18282612fc6565b612a8b84848361448e565b5f838152600b6020908152604080832060020154601290925290912060010154601154670de0b6b3a76400009161351291615ddc565b61351c9083615e47565b6135269190615e5e565b6040808501919091525f85815260126020522054601054670de0b6b3a76400009161355091615ddc565b61355a9083615e47565b6135649190615e5e565b60608401525f848152600b602081815260408320805460a08801908152938890529190526004015460c08501819052905161359f9190615e47565b60e08401525f848152600b60205260408120600301546135ce90600160481b90046001600160401b0316614338565b90506135de8460e0015182614378565b60808501819052604085015160a08601516135f99190615d11565b6136039190615d11565b845260608401515f868152600b60205260409020600101546136259190615d11565b6020858101919091525f958652600b90525050604090922060030154600160881b90046001600160401b03166101209091015250565b5f878152600b60209081526040808320815161014081018352815481526001820154938101939093526002810154918301919091526003810154606083019060ff1660048111156136ae576136ae615934565b60048111156136bf576136bf615934565b815260038201546001600160401b0361010080830482166020850152600160481b830482166040850152600160881b9092041660608301526004830154608083015260058301546001600160a01b031660a083015260069092015460c0909101528651908701519192505f916137359089615ddc565b61373f9190615ddc565b90505f8660200151896137529190615ddc565b6101208401516001600160a01b0388165f908152600c6020526040812060050180549394509192613784908490615ddc565b9091555061379490508285615ddc565b6001600160a01b0387165f908152600c60205260409020556137b68186615ddc565b6001600160a01b03969096165f908152600c60209081526040808320600181019990995560029098018054600160401b600160801b031916600160401b426001600160401b0316021790559a8152600b909a525050509186206005810180546001600160a01b0319169055600601959095555050505050565b5f8215613855575f836138428487615e47565b61384c9190615e5e565b9150612bc69050565b505f199392505050565b6018545f03612abc5760405163f8b7c7bf60e01b815260040160405180910390fd5b805f03610d5557604051631f2a200560e01b815260040160405180910390fd5b6040516370a0823160e01b81525f906001600160a01b038516906370a08231906138cf90869060040161551c565b602060405180830381865afa1580156138ea573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061390e9190615ce6565b905081811015612a8b576040516307a5137f60e11b815260040160405180910390fd5b5f600182600481111561394657613946615934565b1480611ce35750600482600481111561396157613961615934565b1492915050565b5f908152600b60205260409020600501546001600160a01b031690565b61398d6153ce565b6139978282612fc6565b6020818101516001600160a01b0384165f908152600c90925260409091209081556002018054600160401b600160801b031916600160401b426001600160401b0316021790556139e56153ce565b60c082015160e082015260a08201516020830151613a039190615e47565b60c08201526101008201516101208083019190915282015161016082015260e08201516020830151613a359190615e47565b6101408201526040516371d4eb2160e01b81526001600160a01b038516906371d4eb2190613a699084908790600401615e0a565b5f604051808303815f87803b158015613a80575f80fd5b505af1158015613a92573d5f803e3d5ffd5b5050505050505050565b613aae838261014001515f0151613c2c565b604082015281613ac76064670de0b6b3a7640000615e5e565b613ad2906001615e47565b613ae490670de0b6b3a7640000615d11565b8260400151613af39190615e47565b613afd9190615e5e565b60608201819052610140820151602001511015613b7857610140810151602001516060820152613b366064670de0b6b3a7640000615e5e565b613b41906001615e47565b613b5390670de0b6b3a7640000615d11565b8282610140015160200151613b689190615e47565b613b729190615e5e565b60408201525b60208101516001600160a01b03161515613b938583836146f9565b505050505050565b60025f9054906101000a90046001600160a01b03166001600160a01b031663d9207f896040518163ffffffff1660e01b8152600401602060405180830381865afa158015613beb573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190613c0f9190615e7d565b612abc57604051631fcc003d60e31b815260040160405180910390fd5b5f818310613c3a5781612bc6565b5090919050565b835f5b8451811015613a92575f858281518110613c6057613c60615dc8565b6020908102919091018101515f818152600b909252604090912060030154909150613c8d9060ff16613931565b613c975750613d6c565b5f613ca2828a611cba565b90507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663794e57246040518163ffffffff1660e01b8152600401602060405180830381865afa158015613d00573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190613d249190615ce6565b811015613d6957613d336154d9565b613d3b615423565b613d498c85888e8587614b33565b6020820151613d589087615ddc565b9550613d6681838a8a614f2c565b50505b50505b600101613c44565b8115612a8b576016545f90613d91670de0b6b3a764000084615e47565b613d9b9190615d11565b90505f601754670de0b6b3a764000085613db59190615e47565b613dbf9190615d11565b90505f600d5483613dd09190615e5e565b90505f600d5483613de19190615e5e565b9050600d5482613df19190615e47565b613dfb9085615ddc565b601655600d54613e0b9082615e47565b613e159084615ddc565b601755601054613e26908390615d11565b601055601154613e37908290615d11565b60115560405162afc6b160e31b8152600481018790526001600160a01b0388169063057e3588906024015f604051808303815f87803b158015613e78575f80fd5b505af1158015613e8a573d5f803e3d5ffd5b505060405163c2283f1f60e01b8152600481018890526001600160a01b038b16925063c2283f1f9150602401612049565b600d54600e819055505f826001600160a01b0316630367b3026040518163ffffffff1660e01b8152600401602060405180830381865afa158015613f01573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190613f259190615ce6565b90505f60015f9054906101000a90046001600160a01b03166001600160a01b0316630367b3026040518163ffffffff1660e01b8152600401602060405180830381865afa158015613f78573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190613f9c9190615ce6565b905080613fa98484615ddc565b613fb39190615d11565b600f5550505050565b8115614061576006546040516323b872dd60e01b81526001600160a01b0391821660048201528482166024820152604481018490527f0000000000000000000000000000000000000000000000000000000000000000909116906323b872dd906064016020604051808303815f875af115801561403b573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061405f9190615e7d565b505b8015612a8b57604051634fa7288f60e11b81526001600160a01b03851690639f4e511e90613a699086908590600401615d38565b600a546001600160a01b03163314612abc57604051630126422b60e21b815260040160405180910390fd5b6140d2845f01518561014001516134a4565b6140e4838561014001515f0151613c2c565b604085018190525f90839061410290670de0b6b3a764000090615e47565b61410c9190615e5e565b9050670de0b6b3a76400006141218383615e47565b61412b9190615e5e565b6080860181905261413c9082615ddc565b606086015260208501516001600160a01b031615155f61415d8888846146f9565b90507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663a10341036040518163ffffffff1660e01b8152600401602060405180830381865afa1580156141bb573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906141df9190615ce6565b811015613a92578661012001516142ec5786515f908152600b60205260409020600301805460ff19166004179055811561427957600954875160405163f476125960e01b81526001600160a01b039092169163f4761259916142479160040190815260200190565b5f604051808303815f87803b15801561425e575f80fd5b505af1158015614270573d5f803e3d5ffd5b505050506142db565b6009548751604051634cc8221560e01b81526001600160a01b0390921691634cc82215916142ad9160040190815260200190565b5f604051808303815f87803b1580156142c4575f80fd5b505af11580156142d6573d5f803e3d5ffd5b505050505b80156142e75786516015555b613a92565b805f03613a92575f6015555050505050505050565b81614310633b9aca0085615e47565b10801561431a5750805b15612b765760405163086b275d60e31b815260040160405180910390fd5b5f6018545f0361434c57611ce38242615ddc565b5f60185411801561435e575060185482105b156143715781601854611ce39190615ddc565b505f919050565b5f670de0b6b3a76400006301e133806143918486615e47565b612bbc9190615e5e565b80600103610d5557604051633307cee360e01b815260040160405180910390fd5b5f828152600b602052604081206003015461010090046001600160401b0316906143e7600184615ddc565b90505f601382815481106143fd576143fd615dc8565b905f5260205f2001549050806013846001600160401b03168154811061442557614425615dc8565b5f91825260208083209190910192909255828152600b909152604090206003018054610100600160481b0319166101006001600160401b03861602179055601380548061447457614474615e9c565b600190038181905f5260205f20015f905590555050505050565b5f838152600b60209081526040808320815161014081018352815481526001820154938101939093526002810154918301919091526003810154606083019060ff1660048111156144e1576144e1615934565b60048111156144f2576144f2615934565b815260038201546001600160401b0361010082048116602080850191909152600160481b83048216604080860191909152600160881b90930490911660608401526004840154608084015260058401546001600160a01b031660a084015260069093015460c0909201919091526101208301518551848301515f8a8152601290955292909320600101546011549495509093670de0b6b3a76400009161459791615ddc565b6145a19083615e47565b6145ab9190615e5e565b6040808801919091525f88815260126020522054601054670de0b6b3a7640000916145d591615ddc565b6145df9083615e47565b6145e99190615e5e565b6060870152811561466d57818386608001516146059190615e47565b61460f9190615e5e565b60a080880182905286015161462391615e47565b60e08701526060850151829061463a908590615e47565b6146449190615e5e565b6080870152610100850151829061465c908590615e47565b6146669190615e5e565b6101008701525b8460a001518660c0018181525050856101000151866080015187604001518860a0015161469a9190615d11565b6146a49190615d11565b6146ae9190615d11565b8652606086015160208501516146c49190615d11565b602087015261016085015160c08501516146e791906001600160401b03166150d4565b61012090960195909552505050505050565b5f8083604001518461014001515f01516147139190615ddc565b90505f84606001518561014001516020015161472f9190615ddc565b6101408601516040015160a0870152905083156148b6576147598560200151866101600151612fc6565b5f8560400151866101400151604001518761016001516020015161477d9190615d11565b6147879190615ddc565b61016087015160c0808201519089015260a001519091506147a89082615e47565b60e08701526147b56153ce565b60408088015160a0830152606080890151818401526101408901805190920151835290510151602082015261016080880180516101200151918301919091525160e001516148039083615e47565b6101408201525f546020880151604051631bb3f79760e31b81526001600160a01b039092169163dd9fbcb89161483e91859190600401615e0a565b5f604051808303815f87803b158015614855575f80fd5b505af1158015614867573d5f803e3d5ffd5b5050505082600b5f895f015181526020019081526020015f20600101819055506148af875f0151886020015183878b6101600151604001518c6101600151602001515f612bcd565b5050614927565b61014085015160e081015160c08088019190915201516148d69083615e47565b60e086015284515f908152600b6020526040808220849055865182528082206001018390558651825290206003018054600160481b600160881b031916600160481b426001600160401b0316021790555b84516149339082612f54565b6101008601526101408501516040810151606090910151614955918891612abe565b845161496090612b7b565b83156149bd5784516020808701515f838152600b9092526040918290206006015461010089015160105460115494515f80516020615f26833981519152956149b095949389939092909190615d51565b60405180910390a2614a02565b845f01515f80516020615ee6833981519152838388610100015189610140015160c001516010546011546040516149f996959493929190615c70565b60405180910390a25b845f01515f80516020615f46833981519152600687610140015160c00151886101400151604001515f8a60400151614a3990615eb0565b8b6101400151606001518c60600151614a5190615eb0565b604051614a649796959493929190615ca8565b60405180910390a28315614af057602080860180516001600160a01b039081165f818152600c909452604080852054845184168652818620600101546101608c015160a081015160e0909101519651909516875282872060050154925193965f80516020615f6683398151915296614ae796600696949593949093919290615d94565b60405180910390a25b845160808601516040519081527fc7e8309b9b14e7a8561ed352b9fd8733de32417fb7b6a69f5671f79e7bb29ddd9060200160405180910390a250949350505050565b6003546040516331a9108f60e11b8152600481018790525f916001600160a01b031690636352211e90602401602060405180830381865afa158015614b7a573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190614b9e9190615eca565b9050614baa86846134a4565b5f614bb487613968565b90506001600160a01b0381161515614bca6153ce565b8115614bda57614bda8382612fc6565b614bed8a87604001518860600151612abe565b614c00865f015187602001518a8a6150e3565b60a08b015260808a01526060890152875260408701526020860152614c236153ce565b602080880151606080840191909152885160a084015288015182820152604080890151835283015190830151614c60918c91849188916003613131565b8215614d745760a082015160408801518851614c7c9190615ddc565b614c869190615e47565b8260c00151614c959190615d11565b60e087015260a08201516020830151614cae9190615e47565b6101008088019190915282015161012082015260e082015160408801518851614cd79190615ddc565b614ce19190615e47565b826101200151614cf19190615d11565b61016082015260e08201516020830151614d0b9190615e47565b6101408201525f54604051631bb3f79760e31b81526001600160a01b039091169063dd9fbcb890614d429084908890600401615e0a565b5f604051808303815f87803b158015614d59575f80fd5b505af1158015614d6b573d5f803e3d5ffd5b50505050614d7f565b60e080880151908701525b60a086015115614ded5760075460a0870151604051633f10abab60e01b81526001600160a01b0390921691633f10abab91614dbf91899190600401615d38565b5f604051808303815f87803b158015614dd6575f80fd5b505af1158015614de8573d5f803e3d5ffd5b505050505b60048054604051638fef27ab60e01b81529182018c90526001600160a01b031690638fef27ab906024015f604051808303815f87803b158015614e2e575f80fd5b505af1158015614e40573d5f803e3d5ffd5b50505050895f80516020615ee68339815191525f805f805f80604051614e6b96959493929190615c70565b60405180910390a2895f80516020615f4683398151915260055f8a604001515f8c5f0151614e9890615eb0565b8d606001518e60200151614eab90615eb0565b604051614ebe9796959493929190615ca8565b60405180910390a28215614f1f576001600160a01b0384165f818152600c60205260408082208054600182015460a088015160e089015160059485015495515f80516020615f6683398151915297614f169791615d94565b60405180910390a25b5050505050505050505050565b825182518390614f3d908390615d11565b915081815250507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316635397951f6040518163ffffffff1660e01b8152600401602060405180830381865afa158015614fa0573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190614fc49190615ce6565b8260c001818151614fd59190615d11565b905250835160a082018051614feb908390615d11565b9052506020840151606082018051615004908390615d11565b90525060408401518151829061501b908390615d11565b90525060e0808401519082018051615034908390615d11565b90525061010083015160c08201805161504e908390615d11565b9052506020808401519083018051615067908390615d11565b9052506040808401519083018051615080908390615d11565b9052506060808401519083018051615099908390615d11565b90525060808084015190830180516150b2908390615d11565b90525060a08084015190830180516150cb908390615d11565b90525050505050565b5f81831015613c3a5781612bc6565b5f80808080808088156151bd576150fa8b8a613c2c565b96508a615107888c615e47565b6151119190615e5e565b905061511c81615262565b94505f6151298683615ddc565b90506151b681897f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663370619be6040518163ffffffff1660e01b8152600401602060405180830381865afa15801561518c573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906151b09190615ce6565b8c615375565b9097509250505b6151c7878c615ddc565b93508315615254575f6151da828c615ddc565b905080156152525761524c6151ef8483615d11565b867f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316631170f2d46040518163ffffffff1660e01b8152600401602060405180830381865afa15801561518c573d5f803e3d5ffd5b90945092505b505b509499939850945094509450565b5f611ce37f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663f6e505a86040518163ffffffff1660e01b8152600401602060405180830381865afa1580156152c2573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906152e69190615ce6565b6152f09084615e5e565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663748782cb6040518163ffffffff1660e01b8152600401602060405180830381865afa15801561534c573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906153709190615ce6565b613c2c565b5f80808361538b86670de0b6b3a7640000615d11565b6153959088615e47565b61539f9190615e5e565b9050808711156153bd579150816153b68188615ddc565b91506153c4565b8692505f91505b5094509492505050565b6040518061018001604052805f81526020015f81526020015f81526020015f81526020015f81526020015f81526020015f81526020015f81526020015f81526020015f81526020015f81526020015f81525090565b6040518061014001604052805f81526020015f81526020015f81526020015f81526020015f81526020015f81526020015f81526020015f81526020015f81526020015f81525090565b6040518061018001604052805f81526020015f6001600160a01b031681526020015f81526020015f81526020015f81526020015f81526020015f81526020015f81526020015f81526020015f151581526020016154c7615423565b81526020016154d46153ce565b905290565b6040518061012001604052805f81526020015f81526020015f81526020015f81526020015f81526020015f81526020015f81526020015f81526020015f81525090565b6001600160a01b0391909116815260200190565b5f6101808284031215615541575f80fd5b50919050565b5f805f805f610200868803121561555c575f80fd5b853594506020860135935060408601359250606086013591506155828760808801615530565b90509295509295909350565b6001600160a01b0381168114610d55575f80fd5b634e487b7160e01b5f52604160045260245ffd5b60405161018081016001600160401b03811182821017156155d9576155d96155a2565b60405290565b604051601f8201601f191681016001600160401b0381118282101715615607576156076155a2565b604052919050565b5f6101808284031215615620575f80fd5b6156286155b6565b9050813581526020820135602082015260408201356040820152606082013560608201526080820135608082015260a082013560a082015260c082013560c082015260e082013560e082015261010080830135818301525061012080830135818301525061014080830135818301525061016080830135818301525092915050565b5f805f805f8061022087890312156156c0575f80fd5b86356156cb8161558e565b9550602087013594506156e1886040890161560f565b93506101c08701356156f28161558e565b959894975092956101e081013594610200909101359350915050565b5f805f805f805f610240888a031215615725575f80fd5b8735965060208801359550604088013594506157448960608a0161560f565b93506101e08801356157558161558e565b9699959850939692959461020084013594506102209093013592915050565b5f805f806101e08587031215615788575f80fd5b8435935060208501359250604085013591506157a78660608701615530565b905092959194509250565b5f602082840312156157c2575f80fd5b5035919050565b5f805f606084860312156157db575f80fd5b83356157e68161558e565b95602085013595506040909401359392505050565b5f6020828403121561580b575f80fd5b8135612bc68161558e565b805182526020810151602083015260408101516040830152606081015160608301526080810151608083015260a081015160a083015260c081015160c083015260e081015160e08301526101008082015181840152506101208082015181840152506101408082015181840152506101608082015181840152505050565b6101808101611ce38284615816565b5f805f805f60a086880312156158b7575f80fd5b85356158c28161558e565b97602087013597506040870135966060810135965060800135945092505050565b5f805f805f61020086880312156158f8575f80fd5b85359450615909876020880161560f565b93506101a086013561591a8161558e565b949793965093946101c081013594506101e0013592915050565b634e487b7160e01b5f52602160045260245ffd5b6005811061595857615958615934565b9052565b8a8152602081018a905260408101899052610140810161597f606083018a615948565b6001600160401b03978816608083015295871660a08201529390951660c084015260e08301919091526001600160a01b03166101008201526101200191909152949350505050565b5f805f806101e085870312156159db575f80fd5b84356159e68161558e565b9350602085013592506159fc866040870161560f565b939692955092936101c00135925050565b5f6102408284031215615541575f80fd5b5f805f805f805f610240888a031215615a35575f80fd5b8735965060208801359550604088013594506060880135615a558161558e565b93506080880135925060a08801359150615a728960c08a01615530565b905092959891949750929550565b5f805f805f805f80610260898b031215615a98575f80fd5b883597506020890135965060408901359550615ab78a60608b0161560f565b94506101e0890135615ac88161558e565b979a969950949793969561020085013595506102208501359461024001359350915050565b5f8060408385031215615afe575f80fd5b50508035926020909101359150565b5f805f8060608587031215615b20575f80fd5b8435935060208501356001600160401b0380821115615b3d575f80fd5b818701915087601f830112615b50575f80fd5b813581811115615b5e575f80fd5b8860208260051b8501011115615b72575f80fd5b95986020929092019750949560400135945092505050565b5f805f8060808587031215615b9d575f80fd5b8435615ba88161558e565b966020860135965060408601359560600135945092505050565b60208101611ce38284615948565b5f6020808385031215615be1575f80fd5b82356001600160401b0380821115615bf7575f80fd5b818501915085601f830112615c0a575f80fd5b813581811115615c1c57615c1c6155a2565b8060051b9150615c2d8483016155df565b8181529183018401918481019088841115615c46575f80fd5b938501935b83851015615c6457843582529385019390850190615c4b565b98975050505050505050565b958652602086019490945260408501929092526060840152608083015260a082015260c00190565b600a811061595857615958615934565b60e08101615cb6828a615c98565b8760208301528660408301528560608301528460808301528360a08301528260c083015298975050505050505050565b5f60208284031215615cf6575f80fd5b5051919050565b634e487b7160e01b5f52601160045260245ffd5b80820180821115611ce357611ce3615cfd565b634e487b7160e01b5f52600160045260245ffd5b6001600160a01b03929092168252602082015260400190565b6001600160a01b03969096168652602086019490945260408501929092526060840152608083015260a082015260c00190565b6007811061595857615958615934565b60e08101615cb6828a615d84565b8181035f831280158383131683831282161715615dc157615dc1615cfd565b5092915050565b634e487b7160e01b5f52603260045260245ffd5b81810381811115611ce357611ce3615cfd565b5f6101808284031215615e00575f80fd5b612bc6838361560f565b6101a08101615e198285615816565b6001600160a01b03929092166101809190910152919050565b5f81615e4057615e40615cfd565b505f190190565b8082028115828204841417611ce357611ce3615cfd565b5f82615e7857634e487b7160e01b5f52601260045260245ffd5b500490565b5f60208284031215615e8d575f80fd5b81518015158114612bc6575f80fd5b634e487b7160e01b5f52603160045260245ffd5b5f600160ff1b8201615ec457615ec4615cfd565b505f0390565b5f60208284031215615eda575f80fd5b8151612bc68161558e56fe0fba2673863b12c7b8463f3fa2f9b0cb1d534c573cdec5b5d895ee00d6ce6f5e66de8ffda797e3de9c05e8fc57b3bf0ec28a930d40b0d285d93c06501cf6a0906464838e073667756f10746b26734b60870fdcad31d7861c6e5603430bccac61962110f281c1213763cd97a546b337b3cbfd25a31ea9723e9d8b7376ba45da1aecf6daab6f1facdfdd8dfe32b525744d8a7a940824dd52e2b53c24028ee5faa084ec8e1674d62e3a8ff294b1a7f53527d2d10291765fadf94e0ce431b2334334a26469706673582212201f2aaf9aab7dd308b7014d612a3911976b6cc9f8a803e2e86c808c523f7432a664736f6c634300081800330000000000000000000000008f99aac2fe09a1390617d4acdd1519f775ee931a000000000000000000000000c7829c5d1701ab366d248ca384c4caefd87ecdf1","external_libraries":[],"proxy_type":null,"implementations":[],"verified_at":"2026-04-27T12:16:03.393946Z","is_verified_via_verifier_alliance":false,"compiler_version":"v0.8.24+commit.e11b9ed9","decoded_constructor_args":null,"sourcify_repo_url":null,"optimization_runs":0,"compiler_settings":{"evmVersion":"cancun","libraries":{},"metadata":{"appendCBOR":true,"bytecodeHash":"ipfs","useLiteralContent":false},"optimizer":{"enabled":true,"runs":0},"outputSelection":{"*":{"":["*"],"*":["*"]}},"remappings":["src/=src/","lib/mento-core/lib/bold/:openzeppelin-contracts/=lib/mento-core/lib/bold/contracts/lib/openzeppelin-contracts/","lib/bold/:openzeppelin-contracts/=lib/bold/contracts/lib/openzeppelin-contracts/","openzeppelin-contracts/=lib/mento-core/lib/openzeppelin-contracts-next/","safe-smart-account/=lib/treb-sol/lib/safe-utils/lib/safe-smart-account/contracts/","mento-core/=lib/mento-core/contracts/","@celo/=lib/mento-core/node_modules/@celo/contracts/","@chainlink/contracts/=lib/mento-core/lib/foundry-chainlink-toolkit/lib/chainlink-brownie-contracts/contracts/src/","@ds/=lib/mento-router/lib/multicall/lib/ds-test/src/","@openzeppelin/=lib/mento-core/lib/foundry-chainlink-toolkit/lib/openzeppelin-contracts/","@prb/test/=lib/mento-core/lib/prb-math/lib/prb-test/src/","@std/=lib/mento-router/lib/multicall/lib/forge-std/src/","BokkyPooBahsDateTimeLibrary/=lib/mento-core/lib/BokkyPooBahsDateTimeLibrary/","Solady/=lib/bold/contracts/lib/Solady/src/","V2-gov/=lib/bold/contracts/lib/V2-gov/","bold/=lib/bold/contracts/","celo/=lib/mento-core/node_modules/@celo/","chainlink-brownie-contracts/=lib/mento-core/lib/foundry-chainlink-toolkit/lib/chainlink-brownie-contracts/contracts/src/v0.6/vendor/@arbitrum/nitro-contracts/src/","chimera/=lib/bold/contracts/lib/V2-gov/lib/chimera/src/","contracts/=lib/mento-core/contracts/","createx-forge/=lib/treb-sol/lib/createx-forge/","ds-test/=lib/mento-router/lib/multicall/lib/ds-test/src/","erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/","forge-std/=lib/forge-std/src/","foundry-chainlink-toolkit/=lib/mento-core/lib/foundry-chainlink-toolkit/","halmos-cheatcodes/=lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/","mento-router/=lib/mento-router/","mento-std/=lib/mento-std/src/","multicall/=lib/mento-router/lib/multicall/src/","openzeppelin-contracts-next/=lib/mento-core/lib/openzeppelin-contracts-next/","openzeppelin-contracts-upgradeable/=lib/mento-core/lib/openzeppelin-contracts-upgradeable/","openzeppelin-solidity/=lib/mento-core/lib/openzeppelin-contracts/","openzeppelin/=lib/mento-core/lib/openzeppelin-contracts/","prb-math/=lib/mento-core/lib/prb-math/src/","prb-test/=lib/mento-core/lib/prb-math/lib/prb-test/src/","prb/math/=lib/mento-core/lib/prb-math/src/","safe-contracts/=lib/mento-core/lib/safe-contracts/","safe-utils/=lib/treb-sol/lib/safe-utils/src/","solidity-http/=lib/treb-sol/lib/safe-utils/lib/solidity-http/src/","solidity-stringutils/=lib/treb-sol/lib/safe-utils/lib/solidity-stringutils/","test/=lib/mento-core/test/","treb-sol/=lib/treb-sol/"],"viaIR":false},"is_verified":true,"verified_twin_address_hash":null,"optimization_enabled":true,"deployed_bytecode":"0x608060405234801561000f575f80fd5b50600436106101b5575f3560e01c806301540287146101b9578063048c661d146101d5578063059e0113146101f55780630f83069314610208578063105b403b1461021d5780631ca2d7d9146102255780631cf74075146102385780631d7be8001461024b5780631ef11b621461025e57806338116fa3146102715780633ecaaa3f14610284578063499b069f1461028c5780634aff96e11461029f5780634ea15f37146102a757806358569081146102cc5780635d648588146102d55780635ef3b8bf14610310578063613cacae146103235780636daed00014610343578063735ab2a41461035657806377553ad4146103695780637f7dde4a1461037c578063a411219c1461038e578063aad3f40414610422578063ae918754146104ad578063b0141775146104c0578063b3d346b9146104d3578063b3e16c30146104e6578063b5a672c2146104f9578063bf49e6491461050c578063c067e95c1461051f578063c2020f0414610532578063ca0ca8d214610545578063e47bfaf114610558578063ef49a6b41461058a578063f8a239e81461059d578063fc0e74d1146105b0575b5f80fd5b6101c260155481565b6040519081526020015b60405180910390f35b6005546101e8906001600160a01b031681565b6040516101cc919061551c565b6003546101e8906001600160a01b031681565b61021b610216366004615547565b6105b8565b005b6101c26106d3565b61021b6102333660046156aa565b6107c8565b61021b61024636600461570e565b610a46565b61021b610259366004615774565b610bd5565b6101c261026c3660046157b2565b610cff565b61021b61027f3660046157b2565b610d23565b6101c2610d58565b61021b61029a3660046157c9565b610e16565b6013546101c2565b6102af610ef8565b6040805193845260208401929092521515908201526060016101cc565b6101c260185481565b6102fb6102e33660046157b2565b60126020525f90815260409020805460019091015482565b604080519283526020830191909152016101cc565b6101c261031e3660046157b2565b6110b6565b6103366103313660046157fb565b6111ca565b6040516101cc9190615894565b61021b6103513660046158a3565b6111e1565b61021b6103643660046158e3565b611284565b6004546101e8906001600160a01b031681565b5f546101e8906001600160a01b031681565b61040c61039c3660046157b2565b600b6020525f9081526040902080546001820154600283015460038401546004850154600586015460069096015494959394929360ff8316936001600160401b036101008504811694600160481b8104821694600160881b9091049091169290916001600160a01b03909116908a565b6040516101cc9a9998979695949392919061595c565b6104356104303660046157b2565b6113ac565b6040516101cc91905f61014082019050825182526020830151602083015260408301516040830152606083015160608301526080830151608083015260a083015160a083015260c083015160c083015260e083015160e083015261010080840151818401525061012080840151818401525092915050565b6009546101e8906001600160a01b031681565b61021b6104ce3660046159c7565b6113be565b6101e86104e13660046157b2565b6115ab565b61021b6104f4366004615a0d565b6115d3565b61021b610507366004615a1e565b611979565b61021b61051a366004615a80565b611b4e565b6101c261052d366004615aed565b611cba565b61021b610540366004615b0d565b611ce9565b61021b610553366004615b8a565b612080565b61057d6105663660046157b2565b5f908152600b602052604090206003015460ff1690565b6040516101cc9190615bc2565b61021b610598366004615bd0565b612115565b6101c26105ab3660046158a3565b61253b565b61021b612a2e565b6105c0612a91565b5f858152600b6020908152604090912060018082018790558582556004820185905560039091018054600160481b600160c81b031916600160481b426001600160401b0316908102600160881b600160c81b03191691909117600160881b9190910217905554610641916001600160a01b0390911690833590840135612abe565b61064a85612b7b565b5f858152600b60205260409081902060020154601054601154925188935f80516020615ee6833981519152936106869389938b938a9291615c70565b60405180910390a2845f80516020615f46833981519152600384845f01358561010001355f87602001355f6040516106c49796959493929190615ca8565b60405180910390a25050505050565b5f8054604080516308aa0f3360e31b8152905183926001600160a01b03169163455079989160048083019260209291908290030181865afa15801561071a573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061073e9190615ce6565b90505f60015f9054906101000a90046001600160a01b03166001600160a01b031663455079986040518163ffffffff1660e01b8152600401602060405180830381865afa158015610791573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906107b59190615ce6565b90506107c18183615d11565b9250505090565b6107d0612a91565b5f6107de8560400151612b9a565b6040868101515f898152600b602052919091206001808201929092556002810183905560038101805460ff19811684178255601354600590930180546001600160a01b0319166001600160a01b038b161790556001600160481b03600160881b03600160c81b0319166101006001600160401b0393841602600160881b600160c81b03191617600160881b429390931692909202919091179091179055905061088686612b7b565b601380546001810182555f919091525f80516020615f068339815191520186905560808501516108b8576108b8615d24565b6108cc868587886080015187876001612bcd565b5f81600d546108db9190615d11565b600d8190556003546040516340c10f1960e01b81529192506001600160a01b0316906340c10f1990610913908b908b90600401615d38565b5f604051808303815f87803b15801561092a575f80fd5b505af115801561093c573d5f803e3d5ffd5b50505050865f80516020615f2683398151915286600b5f8b81526020019081526020015f206006015489604001518660105460115460405161098396959493929190615d51565b60405180910390a26001600160a01b0385165f908152600c60205260408082206003015461010089015160808a01518a84015193518c955f80516020615f46833981519152956109de95600795909492939092918491615ca8565b60405180910390a26001600160a01b0385165f818152600c602052604080822080546001820154600383015460048481015460059095015495515f80516020615f6683398151915297610a349792969291615d94565b60405180910390a25050505050505050565b610a4e612a91565b5f878152600b60205260409020600101869055610a6a87612b7b565b5f610a758888612f54565b90505f8611610a8657610a86615d24565b610a968885878987876001612bcd565b60015485516020870151610ab4926001600160a01b03169190612abe565b875f80516020615f2683398151915285600b5f8c81526020019081526020015f20600601548a85601054601154604051610af396959493929190615d51565b60405180910390a2875f80516020615f468339815191526002600c5f886001600160a01b03166001600160a01b031681526020019081526020015f2060030154885f01518961010001518a60a001518b60800151610b519190615da2565b8b602001518c606001518d60400151610b6a9190615da2565b604051610b7d9796959493929190615ca8565b60405180910390a26001600160a01b0384165f818152600c6020526040808220805460018201546003830154600484015460059094015494515f80516020615f6683398151915296610a349660069692909190615d94565b610bdd612a91565b5f848152600b60209081526040909120600180820186905584825560039091018054600160481b600160881b031916600160481b426001600160401b03160217905554610c3b916001600160a01b0390911690833590840135612abe565b5f610c468585612f54565b9050610c5185612b7b565b5f858152600b60205260409081902060040154601054601154925188935f80516020615ee683398151915293610c8e9389938b9389939291615c70565b60405180910390a25f858152600b602052604090206004015485905f80516020615f46833981519152906002908535610100870135610cd560a089013560808a0135615da2565b6020890135610cec60608b013560408c0135615da2565b6040516106c49796959493929190615ca8565b5f60138281548110610d1357610d13615dc8565b905f5260205f2001549050919050565b610d2b612a91565b5f818152600b60205260409020600301805460ff19166001179055601554819003610d55575f6015555b50565b5f8054604080516301b3d98160e11b8152905183926001600160a01b031691630367b3029160048083019260209291908290030181865afa158015610d9f573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610dc39190615ce6565b90505f60015f9054906101000a90046001600160a01b03166001600160a01b0316630367b3026040518163ffffffff1660e01b8152600401602060405180830381865afa158015610791573d5f803e3d5ffd5b610e1e612a91565b601480546001600160a01b0385165f818152600c6020526040808220600281018054600383018a90556004909201889055426001600160401b03908116600160801b026001600160401b03600160801b03600160c01b03199093169616959095171790935583546001810185559381527fce6d7b5282bd9a3661ae061feed1dbda4e52ab073b1f9285be6e155d9c38d4ec90930180546001600160a01b03191682179055905190915f80516020615f6683398151915291610eeb9190819081908890889083908190615d94565b60405180910390a2505050565b5f805f80610f046106d3565b90505f60055f9054906101000a90046001600160a01b03166001600160a01b031663f71c69406040518163ffffffff1660e01b8152600401602060405180830381865afa158015610f57573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610f7b9190615ce6565b90505f818311610f8b575f610f95565b610f958284615ddc565b90505f60025f9054906101000a90046001600160a01b03166001600160a01b0316630fdb11cf6040518163ffffffff1660e01b81526004016020604051808303815f875af1158015610fe9573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061100d9190615ce6565b90505f7f000000000000000000000000c7829c5d1701ab366d248ca384c4caefd87ecdf16001600160a01b03166358d5a9616040518163ffffffff1660e01b8152600401602060405180830381865afa15801561106c573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906110909190615ce6565b61109983612f9c565b101580156110a75750601854155b92989197509195509350505050565b5f818152600b6020908152604080832081516101408101835281548152600182015493810193909352600281015491830191909152600381015483929190606083019060ff16600481111561110d5761110d615934565b600481111561111e5761111e615934565b815260038201546001600160401b03610100820481166020840152600160481b820481166040840152600160881b9091041660608201526004820154608082015260058201546001600160a01b031660a082015260069091015460c09091015290505f61118d82610100015190565b90506001600160a01b038116156111bf576001600160a01b03165f908152600c60205260409020600301549392505050565b5060e0015192915050565b6111d26153ce565b6111dc8282612fc6565b919050565b6111e9612a91565b6001600160a01b0385165f818152600c602052604090819020600181018790558581556003810185905560028082018054600160401b600160c01b031916600160401b426001600160401b0316908102600160801b600160c01b03191691909117600160801b91909102179055600482015460059092015492515f80516020615f66833981519152936106c49389928b928a92918a90615d94565b61128c612a91565b61129b85858585856002613131565b600154845160208601516112b9926001600160a01b03169190612abe565b845f80516020615ee68339815191525f805f805f806040516112e096959493929190615c70565b60405180910390a2845f80516020615f4683398151915260015f875f01518861010001518960a001518a608001516113189190615da2565b8a602001518b606001518c604001516113319190615da2565b6040516113449796959493929190615ca8565b60405180910390a26001600160a01b038316156113a5576001600160a01b0383165f818152600c6020526040808220805460018201546003830154600484015460059485015495515f80516020615f66833981519152976106c49791615d94565b5050505050565b6113b4615423565b6111dc82826134a4565b6113c6612a91565b5f6113d48360400151612b9a565b905082610100015183608001516113eb9190615d11565b5f858152600b60205260408082209283558501516001808401919091556002830184905560038301805460ff19811683178255601380546001600160881b03199092166101006001600160401b0393841602600160481b600160881b03191617600160481b4293909316928302178417600160881b600160c81b031916600160881b92909202919091179091556004909301859055825490810183559181525f80516020615f06833981519152909101859055600d546114ac908390615d11565b600d8190556003546040516340c10f1960e01b81529192506001600160a01b0316906340c10f19906114e49089908990600401615d38565b5f604051808303815f87803b1580156114fb575f80fd5b505af115801561150d573d5f803e3d5ffd5b5050505061151a85612b7b565b845f80516020615ee6833981519152856101000151866080015161153e9190615d11565b8660400151858760105460115460405161155d96959493929190615c70565b60405180910390a2845f80516020615f468339815191525f855f88610100015189608001515f8b6040015160405161159b9796959493929190615ca8565b60405180910390a2505050505050565b601481815481106115ba575f80fd5b5f918252602090912001546001600160a01b0316905081565b6115db612a91565b5f6115ee36839003830160608401615def565b90506115fa8235612b7b565b81355f908152600b6020908152604082208281556004810192909255600382018054600160481b600160881b031916905583013560019091015561164661020083016101e084016157fb565b82355f908152600b602090815260409091206005810180546001600160a01b0319166001600160a01b03949094169390931790925560039091018054600160881b600160c81b031916600160881b426001600160401b031602179055818101516116b291840135615ddc565b604080830191909152610100820151825190916116d29190850135615ddc565b6116dc9190615ddc565b608082015260408201356116f2576116f2615d24565b611722823561170961020085016101e086016157fb565b8385604001358661020001358761022001356001612bcd565b60015481516020830151611740926001600160a01b03169190612abe565b81355f80516020615f2683398151915261176261020085016101e086016157fb565b84355f908152600b602090815260409182902060068101546002909101546010546011549451611799969593948b01359390615d51565b60405180910390a281355f80516020615f468339815191526008600c5f6117c861020088016101e089016157fb565b6001600160a01b03166001600160a01b031681526020019081526020015f2060030154845f01518561010001515f87602001515f60405161180f9796959493929190615ca8565b60405180910390a261182961020083016101e084016157fb565b6001600160a01b03165f80516020615f668339815191526004600c5f61185761020088016101e089016157fb565b6001600160a01b0316815260208101919091526040015f9081205490600c9061188861020089016101e08a016157fb565b6001600160a01b03166001600160a01b031681526020019081526020015f2060010154600c5f886101e00160208101906118c291906157fb565b6001600160a01b03166001600160a01b031681526020019081526020015f2060030154600c5f896101e00160208101906118fc91906157fb565b6001600160a01b03166001600160a01b031681526020019081526020015f2060040154600c5f8a6101e001602081019061193691906157fb565b6001600160a01b03166001600160a01b031681526020019081526020015f20600501545f60405161196d9796959493929190615d94565b60405180910390a25050565b611981612a91565b5f878152600b602052604090206001018690556001600160a01b03841615611a2b575f85116119b2576119b2615d24565b6119d087856119c636859003850185615def565b8887876001612bcd565b6001600160a01b0384165f818152600c6020526040808220600381810154600483015460059093015493515f80516020615f6683398151915295611a1e9593948a948c949391929091615d94565b60405180910390a2611a61565b5f878152600b602052604090208581556003018054600160481b600160881b031916600160481b426001600160401b0316021790555b600154611a7d906001600160a01b031682356020840135612abe565b611a8687612b7b565b5f878152600b602052604090819020600281015460049091015460105460115493518b945f80516020615ee683398151915294611acd948c948e9492939192909190615c70565b60405180910390a25f878152600b6020526040902060049081015488915f80516020615f46833981519152918435610100860135611b1360a08801356080890135615da2565b6020880135611b2a60608a013560408b0135615da2565b604051611b3d9796959493929190615ca8565b60405180910390a250505050505050565b611b56612a91565b611b658888888888888861365b565b5f888152600b60205260409020868155600181018890556003810180546004909201839055600160481b600160c81b0319909116600160481b426001600160401b0316908102600160881b600160c81b03191691909117600160881b91909102179055611bd188612b7b565b60015485516020870151611bef926001600160a01b03169190612abe565b5f888152600b6020526040908190206002015460105460115492518b935f80516020615ee683398151915293611c2b938c938e93899291615c70565b60405180910390a2845161010086015160208701516040518b935f80516020615f4683398151915293611c6893600993889392915f918290615ca8565b60405180910390a26001600160a01b0384165f818152600c6020526040808220805460018201546003830154600484015460059485015495515f80516020615f6683398151915297610a349791615d94565b5f611cc3615423565b611ccd84826134a4565b611cdf8160200151825f01518561382f565b9150505b92915050565b611cf161385f565b611cfa84613881565b600854611d11906001600160a01b031633866138a1565b5f546001600160a01b0316611d246153ce565b60025460408051630fdb11cf60e01b815290515f926001600160a01b031691630fdb11cf916004808301926020929190829003018187875af1158015611d6c573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611d909190615ce6565b9050865f5b86811015611eee578115611eee57611dab61546c565b888883818110611dbd57611dbd615dc8565b6020029190910135808352610140830151611dd892506134a4565b80515f908152600b6020526040902060030154611df79060ff16613931565b1580611e07575061014081015151155b15611e125750611ee6565b8051611e1d90613968565b6001600160a01b03166020820181905215611e4057611e40868260200151613985565b600154611e58906001600160a01b0316848684613a9c565b806060015185606001818151611e6e9190615d11565b905250604081015160a086018051611e87908390615d11565b90525060a081015185518690611e9e908390615d11565b90525060e081015160c086018051611eb7908390615d11565b90525060c081015160e086018051611ed0908390615d11565b9052506040810151611ee29084615ddc565b9250505b600101611d95565b508483606001511015611f2557826060015160405163de7c5c2d60e01b8152600401611f1c91815260200190565b60405180910390fd5b60a083015160608401516040515f80516020615f8683398151915292611f52928c925f9088908190615c70565b60405180910390a16040516371d4eb2160e01b81526001600160a01b038516906371d4eb2190611f889086905f90600401615e0a565b5f604051808303815f87803b158015611f9f575f80fd5b505af1158015611fb1573d5f803e3d5ffd5b505050506060830151604051634fa7288f60e11b81526001600160a01b03861691639f4e511e91611fe6913391600401615d38565b5f604051808303815f87803b158015611ffd575f80fd5b505af115801561200f573d5f803e3d5ffd5b505060085460a0860151604051632770a7eb60e21b81526001600160a01b039092169350639dc29fac925061204991339190600401615d38565b5f604051808303815f87803b158015612060575f80fd5b505af1158015612072573d5f803e3d5ffd5b505050505050505050505050565b612088612a91565b6001600160a01b0384165f818152600c6020526040808220600180820188905586825560048201869055600282018054600160401b600160801b031916600160401b426001600160401b031602179055600382015460059092015492515f80516020615f668339815191529461210794929389938b9391928a92615d94565b60405180910390a250505050565b61211d613b9b565b80515f0361213e576040516399d8fec960e01b815260040160405180910390fd5b5f546001546005546001600160a01b0392831692918216911661215f6153ce565b6121676154d9565b60025460408051630fdb11cf60e01b815290515f926001600160a01b031691630fdb11cf916004808301926020929190829003018187875af11580156121af573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906121d39190615ce6565b90505f846001600160a01b031663f71c69406040518163ffffffff1660e01b8152600401602060405180830381865afa158015612212573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906122369190615ce6565b90505f6122c27f000000000000000000000000c7829c5d1701ab366d248ca384c4caefd87ecdf16001600160a01b031663d5cf2c576040518163ffffffff1660e01b8152600401602060405180830381865afa158015612298573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906122bc9190615ce6565b83613c2c565b90505f6122cf8284615ddc565b90506122df8885838d898b613c41565b8560a001515f0361230357604051638c20998d60e01b815260040160405180910390fd5b6040516371d4eb2160e01b81526001600160a01b038a16906371d4eb21906123319089905f90600401615e0a565b5f604051808303815f87803b158015612348575f80fd5b505af115801561235a573d5f803e3d5ffd5b505050505f8560200151118061237357505f8560400151115b156123e3576020850151604080870151905163335525ad60e01b81526001600160a01b038a169263335525ad926123b592600401918252602082015260400190565b5f604051808303815f87803b1580156123cc575f80fd5b505af11580156123de573d5f803e3d5ffd5b505050505b6123f7898987606001518860800151613d74565b60a0850151156124675760075460a0860151604051634fa7288f60e11b81526001600160a01b038c811693639f4e511e93612439939290911691600401615d38565b5f604051808303815f87803b158015612450575f80fd5b505af1158015612462573d5f803e3d5ffd5b505050505b61247489865f0151613ebb565b7f7243af9a1cff94d3429b2ee00b78c1c10589259f20dc167cb67704f38f9e824e856020015186606001518760c00151885f015189604001518a608001518b60a001516010546011548d6040516125149a99989796959493929190998a5260208a019890985260408901969096526060880194909452608087019290925260a086015260c085015260e08401526101008301526101208201526101400190565b60405180910390a161252f89338760c00151885f0151613fbc565b50505050505050505050565b5f612544614095565b5f546009546001600160a01b03918216911661255e6153ce565b61258e60405180608001604052805f81526020015f81526020015f6001600160a01b031681526020015f81525090565b6020810189905261259d61546c565b601554156125b7576015548152600161012082015261261a565b836001600160a01b0316634d6228316040518163ffffffff1660e01b8152600401602060405180830381865afa1580156125f3573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906126179190615ce6565b81525b5f60408381018290526002548151630fdb11cf60e01b815291516001600160a01b0390911691630fdb11cf916004808301926020929190829003018187875af1158015612669573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061268d9190615ce6565b9050875f0361269b575f1997505b8151158015906126ae57505f8360200151115b80156126b957505f88115b1561292657876126c881615e32565b9850508161012001511561274057846001600160a01b0316634d6228316040518163ffffffff1660e01b8152600401602060405180830381865afa158015612712573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906127369190615ce6565b60608401526127b0565b815160405163040de97d60e21b815260048101919091526001600160a01b03861690631037a5f490602401602060405180830381865afa158015612786573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906127aa9190615ce6565b60608401525b670de0b6b3a76400006127c6835f01518c611cba565b10156127df57606083015182525f61012083015261269b565b81516127ea90613968565b6001600160a01b03166020830181905215801590612822575082604001516001600160a01b031682602001516001600160a01b031614155b1561284957612835868360200151613985565b60208201516001600160a01b031660408401525b6001546020840151612868916001600160a01b0316908490848d6140c0565b81606001518460600181815161287e9190615d11565b905250604082015160a085018051612897908390615d11565b90525060a0820151845185906128ae908390615d11565b90525060e082015160c0850180516128c7908390615d11565b90525060c082015160e0850180516128e0908390615d11565b9052506080820151835184906128f7908390615d11565b9052506040820151602084018051612910908390615ddc565b905250606083015182525f61012083015261269b565b5f80516020615f868339815191528b8560a001518660600151865f01518e8660405161295796959493929190615c70565b60405180910390a16040516371d4eb2160e01b81526001600160a01b038716906371d4eb219061298d9087905f90600401615e0a565b5f604051808303815f87803b1580156129a4575f80fd5b505af11580156129b6573d5f803e3d5ffd5b50505050856001600160a01b0316639f4e511e8d86606001516040518363ffffffff1660e01b81526004016129ec929190615d38565b5f604051808303815f87803b158015612a03575f80fd5b505af1158015612a15573d5f803e3d5ffd5b50505060a0909401519c9b505050505050505050505050565b612a36612a91565b426018555f805460408051636d8f962d60e01b815290516001600160a01b0390921692636d8f962d9260048084019382900301818387803b158015612a79575f80fd5b505af1158015612a8b573d5f803e3d5ffd5b50505050565b6004546001600160a01b03163314612abc5760405163558b0d1f60e01b815260040160405180910390fd5b565b8115612b1a576040516330588f6f60e21b8152600481018390526001600160a01b0384169063c1623dbc906024015f604051808303815f87803b158015612b03575f80fd5b505af1158015612b15573d5f803e3d5ffd5b505050505b8015612b7657604051631eaed73d60e11b8152600481018290526001600160a01b03841690633d5dae7a906024015f604051808303815f87803b158015612b5f575f80fd5b505af1158015612b71573d5f803e3d5ffd5b505050505b505050565b6010545f91825260126020526040909120908155601154600190910155565b5f80600f545f03612bac575081611ce3565b600f54600e54612bbc9085615e47565b612bc69190615e5e565b9392505050565b6001600160a01b0386165f908152600c602052604081206005015486516101008801516080890151929392839291612c0491615d11565b612c0e9190615d11565b90505f8860a00151821115612c335760a0890151612c2c9083615ddc565b9150612c49565b818960a00151612c439190615ddc565b90505f91505b81158015612c55575080155b15612c79576001600160a01b038a165f908152600c60205260409020869055612e2a565b8115612d2357855f03612c8e57819250612cb1565b612c99848787614301565b85612ca48386615e47565b612cae9190615e5e565b92505b5f8b8152600b602052604081206006018054859290612cd1908490615d11565b90915550612ce190508287615d11565b6001600160a01b038b165f908152600c6020526040902055612d038385615d11565b6001600160a01b038b165f908152600c6020526040902060050155612e2a565b8015612e2a57875f03612da257612d3a8187615ddc565b6001600160a01b038b165f908152600c60209081526040808320939093558d8252600b90522060060154612d6e9085615ddc565b6001600160a01b038b165f908152600c60209081526040808320600501939093558d8252600b905290812060060155612e2a565b85612dad8286615e47565b612db79190615e5e565b925082600b5f8d81526020019081526020015f206006015f828254612ddc9190615ddc565b90915550612dec90508187615ddc565b6001600160a01b038b165f908152600c6020526040902055612e0e8385615ddc565b6001600160a01b038b165f908152600c60205260409020600501555b6001600160a01b038a165f908152600c602090815260408083206002018054600160401b600160801b031916600160401b426001600160401b031602179055908b0151908b0151612e7b9190615d11565b90505f8a60600151821115612ea05760608b0151612e999083615ddc565b9150612eb6565b818b60600151612eb09190615ddc565b90505f91505b81158015612ec2575080155b15612ee9576001600160a01b038c165f908152600c60205260409020600101899055612f45565b8115612f1957612ef9828a615d11565b6001600160a01b038d165f908152600c6020526040902060010155612f45565b8015612f4557612f29818a615ddc565b6001600160a01b038d165f908152600c60205260409020600101555b50505050505050505050505050565b5f612f5e82612b9a565b5f848152600b60205260409020600201805490829055600d54919250908290612f88908390615ddc565b612f929190615d11565b600d555092915050565b5f80612fa6610d58565b90505f612fb16106d3565b9050612fbe82828661382f565b949350505050565b6001600160a01b0382165f908152600c60209081526040918290208251610100810184528154815260018201549281019290925260028101546001600160401b0380821694840194909452600160401b810484166060840152600160801b9004909216608080830191909152600383015460a0808401918252600485015460c085015260059094015460e084018190528552825191850182905251928401839052909161307291615e47565b60c083015260608101515f90613090906001600160401b0316614338565b90506130a08360c0015182614378565b606084015260c082015160e0840181905260808401516130c09190615e47565b61012084018190526130d29082614378565b6101008401819052606084015160808501516130ee9190615d11565b6130f89190615d11565b60208085019190915282015160408401525060608101516001600160401b03908116610140840152608090910151166101609091015250565b60135460185415806131545750600382600481111561315257613152615934565b145b15613162576131628161439b565b61316c87826143bc565b5f878152600b60209081526040808320815161014081018352815481526001820154938101939093526002810154918301919091526003810154606083019060ff1660048111156131bf576131bf615934565b60048111156131d0576131d0615934565b815260038201546001600160401b03610100820481166020840152600160481b820481166040840152600160881b9091041660608201526004820154608082015260058201546001600160a01b0390811660a083015260069092015460c0909101529091508616156133035760018160600151600481111561325457613254615934565b036132b75760095460405163f476125960e01b8152600481018a90526001600160a01b039091169063f4761259906024015f604051808303815f87803b15801561329c575f80fd5b505af11580156132ae573d5f803e3d5ffd5b505050506132e7565b6004816060015160048111156132cf576132cf615934565b1480156132dd575087601554145b156132e7575f6015555b6132fe8888606001518960a001518a8a8a8a61365b565b6133ae565b60018160600151600481111561331b5761331b615934565b0361337e57600954604051634cc8221560e01b8152600481018a90526001600160a01b0390911690634cc82215906024015f604051808303815f87803b158015613363575f80fd5b505af1158015613375573d5f803e3d5ffd5b505050506133ae565b60048160600151600481111561339657613396615934565b1480156133a4575087601554145b156133ae575f6015555b5f8160400151600d546133c19190615ddc565b600d8190555f8a8152600b602052604081208181556001808201839055600282018390556003820180546001600160c81b03191680825560048085018690556005850180546001600160a01b031916905560069094019490945593945087939291849081111561343357613433615934565b02179055505f89815260126020526040808220828155600101919091556003549051630852cd8d60e31b8152600481018b90526001600160a01b03909116906342966c68906024015f604051808303815f87803b158015613492575f80fd5b505af1158015612f45573d5f803e3d5ffd5b5f6134ae83613968565b90506001600160a01b038116156134dc576134c76153ce565b6134d18282612fc6565b612a8b84848361448e565b5f838152600b6020908152604080832060020154601290925290912060010154601154670de0b6b3a76400009161351291615ddc565b61351c9083615e47565b6135269190615e5e565b6040808501919091525f85815260126020522054601054670de0b6b3a76400009161355091615ddc565b61355a9083615e47565b6135649190615e5e565b60608401525f848152600b602081815260408320805460a08801908152938890529190526004015460c08501819052905161359f9190615e47565b60e08401525f848152600b60205260408120600301546135ce90600160481b90046001600160401b0316614338565b90506135de8460e0015182614378565b60808501819052604085015160a08601516135f99190615d11565b6136039190615d11565b845260608401515f868152600b60205260409020600101546136259190615d11565b6020858101919091525f958652600b90525050604090922060030154600160881b90046001600160401b03166101209091015250565b5f878152600b60209081526040808320815161014081018352815481526001820154938101939093526002810154918301919091526003810154606083019060ff1660048111156136ae576136ae615934565b60048111156136bf576136bf615934565b815260038201546001600160401b0361010080830482166020850152600160481b830482166040850152600160881b9092041660608301526004830154608083015260058301546001600160a01b031660a083015260069092015460c0909101528651908701519192505f916137359089615ddc565b61373f9190615ddc565b90505f8660200151896137529190615ddc565b6101208401516001600160a01b0388165f908152600c6020526040812060050180549394509192613784908490615ddc565b9091555061379490508285615ddc565b6001600160a01b0387165f908152600c60205260409020556137b68186615ddc565b6001600160a01b03969096165f908152600c60209081526040808320600181019990995560029098018054600160401b600160801b031916600160401b426001600160401b0316021790559a8152600b909a525050509186206005810180546001600160a01b0319169055600601959095555050505050565b5f8215613855575f836138428487615e47565b61384c9190615e5e565b9150612bc69050565b505f199392505050565b6018545f03612abc5760405163f8b7c7bf60e01b815260040160405180910390fd5b805f03610d5557604051631f2a200560e01b815260040160405180910390fd5b6040516370a0823160e01b81525f906001600160a01b038516906370a08231906138cf90869060040161551c565b602060405180830381865afa1580156138ea573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061390e9190615ce6565b905081811015612a8b576040516307a5137f60e11b815260040160405180910390fd5b5f600182600481111561394657613946615934565b1480611ce35750600482600481111561396157613961615934565b1492915050565b5f908152600b60205260409020600501546001600160a01b031690565b61398d6153ce565b6139978282612fc6565b6020818101516001600160a01b0384165f908152600c90925260409091209081556002018054600160401b600160801b031916600160401b426001600160401b0316021790556139e56153ce565b60c082015160e082015260a08201516020830151613a039190615e47565b60c08201526101008201516101208083019190915282015161016082015260e08201516020830151613a359190615e47565b6101408201526040516371d4eb2160e01b81526001600160a01b038516906371d4eb2190613a699084908790600401615e0a565b5f604051808303815f87803b158015613a80575f80fd5b505af1158015613a92573d5f803e3d5ffd5b5050505050505050565b613aae838261014001515f0151613c2c565b604082015281613ac76064670de0b6b3a7640000615e5e565b613ad2906001615e47565b613ae490670de0b6b3a7640000615d11565b8260400151613af39190615e47565b613afd9190615e5e565b60608201819052610140820151602001511015613b7857610140810151602001516060820152613b366064670de0b6b3a7640000615e5e565b613b41906001615e47565b613b5390670de0b6b3a7640000615d11565b8282610140015160200151613b689190615e47565b613b729190615e5e565b60408201525b60208101516001600160a01b03161515613b938583836146f9565b505050505050565b60025f9054906101000a90046001600160a01b03166001600160a01b031663d9207f896040518163ffffffff1660e01b8152600401602060405180830381865afa158015613beb573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190613c0f9190615e7d565b612abc57604051631fcc003d60e31b815260040160405180910390fd5b5f818310613c3a5781612bc6565b5090919050565b835f5b8451811015613a92575f858281518110613c6057613c60615dc8565b6020908102919091018101515f818152600b909252604090912060030154909150613c8d9060ff16613931565b613c975750613d6c565b5f613ca2828a611cba565b90507f000000000000000000000000c7829c5d1701ab366d248ca384c4caefd87ecdf16001600160a01b031663794e57246040518163ffffffff1660e01b8152600401602060405180830381865afa158015613d00573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190613d249190615ce6565b811015613d6957613d336154d9565b613d3b615423565b613d498c85888e8587614b33565b6020820151613d589087615ddc565b9550613d6681838a8a614f2c565b50505b50505b600101613c44565b8115612a8b576016545f90613d91670de0b6b3a764000084615e47565b613d9b9190615d11565b90505f601754670de0b6b3a764000085613db59190615e47565b613dbf9190615d11565b90505f600d5483613dd09190615e5e565b90505f600d5483613de19190615e5e565b9050600d5482613df19190615e47565b613dfb9085615ddc565b601655600d54613e0b9082615e47565b613e159084615ddc565b601755601054613e26908390615d11565b601055601154613e37908290615d11565b60115560405162afc6b160e31b8152600481018790526001600160a01b0388169063057e3588906024015f604051808303815f87803b158015613e78575f80fd5b505af1158015613e8a573d5f803e3d5ffd5b505060405163c2283f1f60e01b8152600481018890526001600160a01b038b16925063c2283f1f9150602401612049565b600d54600e819055505f826001600160a01b0316630367b3026040518163ffffffff1660e01b8152600401602060405180830381865afa158015613f01573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190613f259190615ce6565b90505f60015f9054906101000a90046001600160a01b03166001600160a01b0316630367b3026040518163ffffffff1660e01b8152600401602060405180830381865afa158015613f78573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190613f9c9190615ce6565b905080613fa98484615ddc565b613fb39190615d11565b600f5550505050565b8115614061576006546040516323b872dd60e01b81526001600160a01b0391821660048201528482166024820152604481018490527f000000000000000000000000471ece3750da237f93b8e339c536989b8978a438909116906323b872dd906064016020604051808303815f875af115801561403b573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061405f9190615e7d565b505b8015612a8b57604051634fa7288f60e11b81526001600160a01b03851690639f4e511e90613a699086908590600401615d38565b600a546001600160a01b03163314612abc57604051630126422b60e21b815260040160405180910390fd5b6140d2845f01518561014001516134a4565b6140e4838561014001515f0151613c2c565b604085018190525f90839061410290670de0b6b3a764000090615e47565b61410c9190615e5e565b9050670de0b6b3a76400006141218383615e47565b61412b9190615e5e565b6080860181905261413c9082615ddc565b606086015260208501516001600160a01b031615155f61415d8888846146f9565b90507f000000000000000000000000c7829c5d1701ab366d248ca384c4caefd87ecdf16001600160a01b031663a10341036040518163ffffffff1660e01b8152600401602060405180830381865afa1580156141bb573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906141df9190615ce6565b811015613a92578661012001516142ec5786515f908152600b60205260409020600301805460ff19166004179055811561427957600954875160405163f476125960e01b81526001600160a01b039092169163f4761259916142479160040190815260200190565b5f604051808303815f87803b15801561425e575f80fd5b505af1158015614270573d5f803e3d5ffd5b505050506142db565b6009548751604051634cc8221560e01b81526001600160a01b0390921691634cc82215916142ad9160040190815260200190565b5f604051808303815f87803b1580156142c4575f80fd5b505af11580156142d6573d5f803e3d5ffd5b505050505b80156142e75786516015555b613a92565b805f03613a92575f6015555050505050505050565b81614310633b9aca0085615e47565b10801561431a5750805b15612b765760405163086b275d60e31b815260040160405180910390fd5b5f6018545f0361434c57611ce38242615ddc565b5f60185411801561435e575060185482105b156143715781601854611ce39190615ddc565b505f919050565b5f670de0b6b3a76400006301e133806143918486615e47565b612bbc9190615e5e565b80600103610d5557604051633307cee360e01b815260040160405180910390fd5b5f828152600b602052604081206003015461010090046001600160401b0316906143e7600184615ddc565b90505f601382815481106143fd576143fd615dc8565b905f5260205f2001549050806013846001600160401b03168154811061442557614425615dc8565b5f91825260208083209190910192909255828152600b909152604090206003018054610100600160481b0319166101006001600160401b03861602179055601380548061447457614474615e9c565b600190038181905f5260205f20015f905590555050505050565b5f838152600b60209081526040808320815161014081018352815481526001820154938101939093526002810154918301919091526003810154606083019060ff1660048111156144e1576144e1615934565b60048111156144f2576144f2615934565b815260038201546001600160401b0361010082048116602080850191909152600160481b83048216604080860191909152600160881b90930490911660608401526004840154608084015260058401546001600160a01b031660a084015260069093015460c0909201919091526101208301518551848301515f8a8152601290955292909320600101546011549495509093670de0b6b3a76400009161459791615ddc565b6145a19083615e47565b6145ab9190615e5e565b6040808801919091525f88815260126020522054601054670de0b6b3a7640000916145d591615ddc565b6145df9083615e47565b6145e99190615e5e565b6060870152811561466d57818386608001516146059190615e47565b61460f9190615e5e565b60a080880182905286015161462391615e47565b60e08701526060850151829061463a908590615e47565b6146449190615e5e565b6080870152610100850151829061465c908590615e47565b6146669190615e5e565b6101008701525b8460a001518660c0018181525050856101000151866080015187604001518860a0015161469a9190615d11565b6146a49190615d11565b6146ae9190615d11565b8652606086015160208501516146c49190615d11565b602087015261016085015160c08501516146e791906001600160401b03166150d4565b61012090960195909552505050505050565b5f8083604001518461014001515f01516147139190615ddc565b90505f84606001518561014001516020015161472f9190615ddc565b6101408601516040015160a0870152905083156148b6576147598560200151866101600151612fc6565b5f8560400151866101400151604001518761016001516020015161477d9190615d11565b6147879190615ddc565b61016087015160c0808201519089015260a001519091506147a89082615e47565b60e08701526147b56153ce565b60408088015160a0830152606080890151818401526101408901805190920151835290510151602082015261016080880180516101200151918301919091525160e001516148039083615e47565b6101408201525f546020880151604051631bb3f79760e31b81526001600160a01b039092169163dd9fbcb89161483e91859190600401615e0a565b5f604051808303815f87803b158015614855575f80fd5b505af1158015614867573d5f803e3d5ffd5b5050505082600b5f895f015181526020019081526020015f20600101819055506148af875f0151886020015183878b6101600151604001518c6101600151602001515f612bcd565b5050614927565b61014085015160e081015160c08088019190915201516148d69083615e47565b60e086015284515f908152600b6020526040808220849055865182528082206001018390558651825290206003018054600160481b600160881b031916600160481b426001600160401b0316021790555b84516149339082612f54565b6101008601526101408501516040810151606090910151614955918891612abe565b845161496090612b7b565b83156149bd5784516020808701515f838152600b9092526040918290206006015461010089015160105460115494515f80516020615f26833981519152956149b095949389939092909190615d51565b60405180910390a2614a02565b845f01515f80516020615ee6833981519152838388610100015189610140015160c001516010546011546040516149f996959493929190615c70565b60405180910390a25b845f01515f80516020615f46833981519152600687610140015160c00151886101400151604001515f8a60400151614a3990615eb0565b8b6101400151606001518c60600151614a5190615eb0565b604051614a649796959493929190615ca8565b60405180910390a28315614af057602080860180516001600160a01b039081165f818152600c909452604080852054845184168652818620600101546101608c015160a081015160e0909101519651909516875282872060050154925193965f80516020615f6683398151915296614ae796600696949593949093919290615d94565b60405180910390a25b845160808601516040519081527fc7e8309b9b14e7a8561ed352b9fd8733de32417fb7b6a69f5671f79e7bb29ddd9060200160405180910390a250949350505050565b6003546040516331a9108f60e11b8152600481018790525f916001600160a01b031690636352211e90602401602060405180830381865afa158015614b7a573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190614b9e9190615eca565b9050614baa86846134a4565b5f614bb487613968565b90506001600160a01b0381161515614bca6153ce565b8115614bda57614bda8382612fc6565b614bed8a87604001518860600151612abe565b614c00865f015187602001518a8a6150e3565b60a08b015260808a01526060890152875260408701526020860152614c236153ce565b602080880151606080840191909152885160a084015288015182820152604080890151835283015190830151614c60918c91849188916003613131565b8215614d745760a082015160408801518851614c7c9190615ddc565b614c869190615e47565b8260c00151614c959190615d11565b60e087015260a08201516020830151614cae9190615e47565b6101008088019190915282015161012082015260e082015160408801518851614cd79190615ddc565b614ce19190615e47565b826101200151614cf19190615d11565b61016082015260e08201516020830151614d0b9190615e47565b6101408201525f54604051631bb3f79760e31b81526001600160a01b039091169063dd9fbcb890614d429084908890600401615e0a565b5f604051808303815f87803b158015614d59575f80fd5b505af1158015614d6b573d5f803e3d5ffd5b50505050614d7f565b60e080880151908701525b60a086015115614ded5760075460a0870151604051633f10abab60e01b81526001600160a01b0390921691633f10abab91614dbf91899190600401615d38565b5f604051808303815f87803b158015614dd6575f80fd5b505af1158015614de8573d5f803e3d5ffd5b505050505b60048054604051638fef27ab60e01b81529182018c90526001600160a01b031690638fef27ab906024015f604051808303815f87803b158015614e2e575f80fd5b505af1158015614e40573d5f803e3d5ffd5b50505050895f80516020615ee68339815191525f805f805f80604051614e6b96959493929190615c70565b60405180910390a2895f80516020615f4683398151915260055f8a604001515f8c5f0151614e9890615eb0565b8d606001518e60200151614eab90615eb0565b604051614ebe9796959493929190615ca8565b60405180910390a28215614f1f576001600160a01b0384165f818152600c60205260408082208054600182015460a088015160e089015160059485015495515f80516020615f6683398151915297614f169791615d94565b60405180910390a25b5050505050505050505050565b825182518390614f3d908390615d11565b915081815250507f000000000000000000000000c7829c5d1701ab366d248ca384c4caefd87ecdf16001600160a01b0316635397951f6040518163ffffffff1660e01b8152600401602060405180830381865afa158015614fa0573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190614fc49190615ce6565b8260c001818151614fd59190615d11565b905250835160a082018051614feb908390615d11565b9052506020840151606082018051615004908390615d11565b90525060408401518151829061501b908390615d11565b90525060e0808401519082018051615034908390615d11565b90525061010083015160c08201805161504e908390615d11565b9052506020808401519083018051615067908390615d11565b9052506040808401519083018051615080908390615d11565b9052506060808401519083018051615099908390615d11565b90525060808084015190830180516150b2908390615d11565b90525060a08084015190830180516150cb908390615d11565b90525050505050565b5f81831015613c3a5781612bc6565b5f80808080808088156151bd576150fa8b8a613c2c565b96508a615107888c615e47565b6151119190615e5e565b905061511c81615262565b94505f6151298683615ddc565b90506151b681897f000000000000000000000000c7829c5d1701ab366d248ca384c4caefd87ecdf16001600160a01b031663370619be6040518163ffffffff1660e01b8152600401602060405180830381865afa15801561518c573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906151b09190615ce6565b8c615375565b9097509250505b6151c7878c615ddc565b93508315615254575f6151da828c615ddc565b905080156152525761524c6151ef8483615d11565b867f000000000000000000000000c7829c5d1701ab366d248ca384c4caefd87ecdf16001600160a01b0316631170f2d46040518163ffffffff1660e01b8152600401602060405180830381865afa15801561518c573d5f803e3d5ffd5b90945092505b505b509499939850945094509450565b5f611ce37f000000000000000000000000c7829c5d1701ab366d248ca384c4caefd87ecdf16001600160a01b031663f6e505a86040518163ffffffff1660e01b8152600401602060405180830381865afa1580156152c2573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906152e69190615ce6565b6152f09084615e5e565b7f000000000000000000000000c7829c5d1701ab366d248ca384c4caefd87ecdf16001600160a01b031663748782cb6040518163ffffffff1660e01b8152600401602060405180830381865afa15801561534c573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906153709190615ce6565b613c2c565b5f80808361538b86670de0b6b3a7640000615d11565b6153959088615e47565b61539f9190615e5e565b9050808711156153bd579150816153b68188615ddc565b91506153c4565b8692505f91505b5094509492505050565b6040518061018001604052805f81526020015f81526020015f81526020015f81526020015f81526020015f81526020015f81526020015f81526020015f81526020015f81526020015f81526020015f81525090565b6040518061014001604052805f81526020015f81526020015f81526020015f81526020015f81526020015f81526020015f81526020015f81526020015f81526020015f81525090565b6040518061018001604052805f81526020015f6001600160a01b031681526020015f81526020015f81526020015f81526020015f81526020015f81526020015f81526020015f81526020015f151581526020016154c7615423565b81526020016154d46153ce565b905290565b6040518061012001604052805f81526020015f81526020015f81526020015f81526020015f81526020015f81526020015f81526020015f81526020015f81525090565b6001600160a01b0391909116815260200190565b5f6101808284031215615541575f80fd5b50919050565b5f805f805f610200868803121561555c575f80fd5b853594506020860135935060408601359250606086013591506155828760808801615530565b90509295509295909350565b6001600160a01b0381168114610d55575f80fd5b634e487b7160e01b5f52604160045260245ffd5b60405161018081016001600160401b03811182821017156155d9576155d96155a2565b60405290565b604051601f8201601f191681016001600160401b0381118282101715615607576156076155a2565b604052919050565b5f6101808284031215615620575f80fd5b6156286155b6565b9050813581526020820135602082015260408201356040820152606082013560608201526080820135608082015260a082013560a082015260c082013560c082015260e082013560e082015261010080830135818301525061012080830135818301525061014080830135818301525061016080830135818301525092915050565b5f805f805f8061022087890312156156c0575f80fd5b86356156cb8161558e565b9550602087013594506156e1886040890161560f565b93506101c08701356156f28161558e565b959894975092956101e081013594610200909101359350915050565b5f805f805f805f610240888a031215615725575f80fd5b8735965060208801359550604088013594506157448960608a0161560f565b93506101e08801356157558161558e565b9699959850939692959461020084013594506102209093013592915050565b5f805f806101e08587031215615788575f80fd5b8435935060208501359250604085013591506157a78660608701615530565b905092959194509250565b5f602082840312156157c2575f80fd5b5035919050565b5f805f606084860312156157db575f80fd5b83356157e68161558e565b95602085013595506040909401359392505050565b5f6020828403121561580b575f80fd5b8135612bc68161558e565b805182526020810151602083015260408101516040830152606081015160608301526080810151608083015260a081015160a083015260c081015160c083015260e081015160e08301526101008082015181840152506101208082015181840152506101408082015181840152506101608082015181840152505050565b6101808101611ce38284615816565b5f805f805f60a086880312156158b7575f80fd5b85356158c28161558e565b97602087013597506040870135966060810135965060800135945092505050565b5f805f805f61020086880312156158f8575f80fd5b85359450615909876020880161560f565b93506101a086013561591a8161558e565b949793965093946101c081013594506101e0013592915050565b634e487b7160e01b5f52602160045260245ffd5b6005811061595857615958615934565b9052565b8a8152602081018a905260408101899052610140810161597f606083018a615948565b6001600160401b03978816608083015295871660a08201529390951660c084015260e08301919091526001600160a01b03166101008201526101200191909152949350505050565b5f805f806101e085870312156159db575f80fd5b84356159e68161558e565b9350602085013592506159fc866040870161560f565b939692955092936101c00135925050565b5f6102408284031215615541575f80fd5b5f805f805f805f610240888a031215615a35575f80fd5b8735965060208801359550604088013594506060880135615a558161558e565b93506080880135925060a08801359150615a728960c08a01615530565b905092959891949750929550565b5f805f805f805f80610260898b031215615a98575f80fd5b883597506020890135965060408901359550615ab78a60608b0161560f565b94506101e0890135615ac88161558e565b979a969950949793969561020085013595506102208501359461024001359350915050565b5f8060408385031215615afe575f80fd5b50508035926020909101359150565b5f805f8060608587031215615b20575f80fd5b8435935060208501356001600160401b0380821115615b3d575f80fd5b818701915087601f830112615b50575f80fd5b813581811115615b5e575f80fd5b8860208260051b8501011115615b72575f80fd5b95986020929092019750949560400135945092505050565b5f805f8060808587031215615b9d575f80fd5b8435615ba88161558e565b966020860135965060408601359560600135945092505050565b60208101611ce38284615948565b5f6020808385031215615be1575f80fd5b82356001600160401b0380821115615bf7575f80fd5b818501915085601f830112615c0a575f80fd5b813581811115615c1c57615c1c6155a2565b8060051b9150615c2d8483016155df565b8181529183018401918481019088841115615c46575f80fd5b938501935b83851015615c6457843582529385019390850190615c4b565b98975050505050505050565b958652602086019490945260408501929092526060840152608083015260a082015260c00190565b600a811061595857615958615934565b60e08101615cb6828a615c98565b8760208301528660408301528560608301528460808301528360a08301528260c083015298975050505050505050565b5f60208284031215615cf6575f80fd5b5051919050565b634e487b7160e01b5f52601160045260245ffd5b80820180821115611ce357611ce3615cfd565b634e487b7160e01b5f52600160045260245ffd5b6001600160a01b03929092168252602082015260400190565b6001600160a01b03969096168652602086019490945260408501929092526060840152608083015260a082015260c00190565b6007811061595857615958615934565b60e08101615cb6828a615d84565b8181035f831280158383131683831282161715615dc157615dc1615cfd565b5092915050565b634e487b7160e01b5f52603260045260245ffd5b81810381811115611ce357611ce3615cfd565b5f6101808284031215615e00575f80fd5b612bc6838361560f565b6101a08101615e198285615816565b6001600160a01b03929092166101809190910152919050565b5f81615e4057615e40615cfd565b505f190190565b8082028115828204841417611ce357611ce3615cfd565b5f82615e7857634e487b7160e01b5f52601260045260245ffd5b500490565b5f60208284031215615e8d575f80fd5b81518015158114612bc6575f80fd5b634e487b7160e01b5f52603160045260245ffd5b5f600160ff1b8201615ec457615ec4615cfd565b505f0390565b5f60208284031215615eda575f80fd5b8151612bc68161558e56fe0fba2673863b12c7b8463f3fa2f9b0cb1d534c573cdec5b5d895ee00d6ce6f5e66de8ffda797e3de9c05e8fc57b3bf0ec28a930d40b0d285d93c06501cf6a0906464838e073667756f10746b26734b60870fdcad31d7861c6e5603430bccac61962110f281c1213763cd97a546b337b3cbfd25a31ea9723e9d8b7376ba45da1aecf6daab6f1facdfdd8dfe32b525744d8a7a940824dd52e2b53c24028ee5faa084ec8e1674d62e3a8ff294b1a7f53527d2d10291765fadf94e0ce431b2334334a26469706673582212201f2aaf9aab7dd308b7014d612a3911976b6cc9f8a803e2e86c808c523f7432a664736f6c63430008180033","source_code":"// SPDX-License-Identifier: BUSL-1.1\n\npragma solidity 0.8.24;\n\nimport \"./Interfaces/ITroveManager.sol\";\nimport \"./Interfaces/IAddressesRegistry.sol\";\nimport \"./Interfaces/IStabilityPool.sol\";\nimport \"./Interfaces/ICollSurplusPool.sol\";\nimport \"./Interfaces/IBoldToken.sol\";\nimport \"./Interfaces/ISortedTroves.sol\";\nimport \"./Interfaces/ITroveEvents.sol\";\nimport \"./Interfaces/ITroveNFT.sol\";\nimport \"./Interfaces/ICollateralRegistry.sol\";\nimport \"./Interfaces/IWETH.sol\";\nimport \"./Interfaces/ISystemParams.sol\";\nimport \"./Dependencies/LiquityBase.sol\";\nimport \"./Dependencies/Constants.sol\";\n\ncontract TroveManager is LiquityBase, ITroveManager, ITroveEvents {\n    // --- Connected contract declarations ---\n\n    ITroveNFT public troveNFT;\n    IBorrowerOperations public borrowerOperations;\n    IStabilityPool public stabilityPool;\n    address internal gasPoolAddress;\n    ICollSurplusPool internal collSurplusPool;\n    IBoldToken internal boldToken;\n    // A doubly linked list of Troves, sorted by their interest rate\n    ISortedTroves public sortedTroves;\n    ICollateralRegistry internal collateralRegistry;\n    // Gas token for liquidation reserve (gas compensation)\n    IERC20Metadata internal immutable gasToken;\n    ISystemParams immutable systemParams;\n\n    // --- Data structures ---\n\n    // Store the necessary data for a trove\n    struct Trove {\n        uint256 debt;\n        uint256 coll;\n        uint256 stake;\n        Status status;\n        uint64 arrayIndex;\n        uint64 lastDebtUpdateTime;\n        uint64 lastInterestRateAdjTime;\n        uint256 annualInterestRate;\n        address interestBatchManager;\n        uint256 batchDebtShares;\n    }\n\n    mapping(uint256 => Trove) public Troves;\n\n    // Store the necessary data for an interest batch manager. We treat each batch as a “big trove”.\n    // Each trove has a share of the debt of the global batch. Collateral is stored per trove (as CRs are different)\n    // Still the total amount of batch collateral is stored for informational purposes\n    struct Batch {\n        uint256 debt;\n        uint256 coll;\n        uint64 arrayIndex;\n        uint64 lastDebtUpdateTime;\n        uint64 lastInterestRateAdjTime;\n        uint256 annualInterestRate;\n        uint256 annualManagementFee;\n        uint256 totalDebtShares;\n    }\n\n    mapping(address => Batch) internal batches;\n\n    uint256 internal totalStakes;\n\n    // Snapshot of the value of totalStakes, taken immediately after the latest liquidation\n    uint256 internal totalStakesSnapshot;\n\n    // Snapshot of the total collateral across the ActivePool and DefaultPool, immediately after the latest liquidation.\n    uint256 internal totalCollateralSnapshot;\n\n    /*\n    * L_coll and L_boldDebt track the sums of accumulated liquidation rewards per unit staked. During its lifetime, each stake earns:\n    *\n    * An Coll gain of ( stake * [L_coll - L_coll(0)] )\n    * A boldDebt increase  of ( stake * [L_boldDebt - L_boldDebt(0)] )\n    *\n    * Where L_coll(0) and L_boldDebt(0) are snapshots of L_coll and L_boldDebt for the active Trove taken at the instant the stake was made\n    */\n    uint256 internal L_coll;\n    uint256 internal L_boldDebt;\n\n    // Map active troves to their RewardSnapshot\n    mapping(uint256 => RewardSnapshot) public rewardSnapshots;\n\n    // Object containing the Coll and Bold snapshots for a given active trove\n    struct RewardSnapshot {\n        uint256 coll;\n        uint256 boldDebt;\n    }\n\n    // Array of all active trove addresses - used to compute an approximate hint off-chain, for the sorted list insertion\n    uint256[] internal TroveIds;\n    // Array of all batch managers - used to fetch them off-chain\n    address[] public batchIds;\n\n    uint256 public lastZombieTroveId;\n\n    // Error trackers for the trove redistribution calculation\n    uint256 internal lastCollError_Redistribution;\n    uint256 internal lastBoldDebtError_Redistribution;\n\n    // Timestamp at which branch was shut down. 0 if not shut down.\n    uint256 public shutdownTime;\n\n    /*\n    * --- Variable container structs for liquidations ---\n    *\n    * These structs are used to hold, return and assign variables inside the liquidation functions,\n    * in order to avoid the error: \"CompilerError: Stack too deep\".\n    **/\n\n    struct LiquidationValues {\n        uint256 collGasCompensation;\n        uint256 debtToOffset;\n        uint256 collToSendToSP;\n        uint256 debtToRedistribute;\n        uint256 collToRedistribute;\n        uint256 collSurplus;\n        uint256 ETHGasCompensation;\n        uint256 oldWeightedRecordedDebt;\n        uint256 newWeightedRecordedDebt;\n    }\n\n    // --- Variable container structs for redemptions ---\n\n    struct RedeemCollateralValues {\n        uint256 totalCollFee;\n        uint256 remainingBold;\n        address lastBatchUpdatedInterest;\n        uint256 nextUserToCheck;\n    }\n\n    struct SingleRedemptionValues {\n        uint256 troveId;\n        address batchAddress;\n        uint256 boldLot;\n        uint256 collLot;\n        uint256 collFee;\n        uint256 appliedRedistBoldDebtGain;\n        uint256 oldWeightedRecordedDebt;\n        uint256 newWeightedRecordedDebt;\n        uint256 newStake;\n        bool isZombieTrove;\n        LatestTroveData trove;\n        LatestBatchData batch;\n    }\n\n    // --- Errors ---\n\n    error EmptyData();\n    error NothingToLiquidate();\n    error CallerNotBorrowerOperations();\n    error CallerNotCollateralRegistry();\n    error OnlyOneTroveLeft();\n    error NotShutDown();\n    error ZeroAmount();\n    error NotEnoughBoldBalance();\n    error MinCollNotReached(uint256 _coll);\n    error BatchSharesRatioTooHigh();\n    error L2SequencerDown();\n\n    // --- Events ---\n\n    event TroveNFTAddressChanged(address _newTroveNFTAddress);\n    event BorrowerOperationsAddressChanged(address _newBorrowerOperationsAddress);\n    event BoldTokenAddressChanged(address _newBoldTokenAddress);\n    event StabilityPoolAddressChanged(address _stabilityPoolAddress);\n    event GasPoolAddressChanged(address _gasPoolAddress);\n    event CollSurplusPoolAddressChanged(address _collSurplusPoolAddress);\n    event SortedTrovesAddressChanged(address _sortedTrovesAddress);\n    event CollateralRegistryAddressChanged(address _collateralRegistryAddress);\n\n    constructor(IAddressesRegistry _addressesRegistry, ISystemParams _systemParams) LiquityBase(_addressesRegistry) {\n        systemParams = _systemParams;\n\n        troveNFT = _addressesRegistry.troveNFT();\n        borrowerOperations = _addressesRegistry.borrowerOperations();\n        stabilityPool = _addressesRegistry.stabilityPool();\n        gasPoolAddress = _addressesRegistry.gasPoolAddress();\n        collSurplusPool = _addressesRegistry.collSurplusPool();\n        boldToken = _addressesRegistry.boldToken();\n        sortedTroves = _addressesRegistry.sortedTroves();\n        gasToken = _addressesRegistry.gasToken();\n        collateralRegistry = _addressesRegistry.collateralRegistry();\n\n        emit TroveNFTAddressChanged(address(troveNFT));\n        emit BorrowerOperationsAddressChanged(address(borrowerOperations));\n        emit StabilityPoolAddressChanged(address(stabilityPool));\n        emit GasPoolAddressChanged(gasPoolAddress);\n        emit CollSurplusPoolAddressChanged(address(collSurplusPool));\n        emit BoldTokenAddressChanged(address(boldToken));\n        emit SortedTrovesAddressChanged(address(sortedTroves));\n        emit CollateralRegistryAddressChanged(address(collateralRegistry));\n    }\n\n    // --- Getters ---\n\n    function getTroveIdsCount() external view override returns (uint256) {\n        return TroveIds.length;\n    }\n\n    function getTroveFromTroveIdsArray(uint256 _index) external view override returns (uint256) {\n        return TroveIds[_index];\n    }\n\n    // --- Trove Liquidation functions ---\n\n    // --- Inner single liquidation functions ---\n\n    // Liquidate one trove\n    function _liquidate(\n        IDefaultPool _defaultPool,\n        uint256 _troveId,\n        uint256 _boldInSPForOffsets,\n        uint256 _price,\n        LatestTroveData memory trove,\n        LiquidationValues memory singleLiquidation\n    ) internal {\n        address owner = troveNFT.ownerOf(_troveId);\n\n        _getLatestTroveData(_troveId, trove);\n        address batchAddress = _getBatchManager(_troveId);\n        bool isTroveInBatch = batchAddress != address(0);\n        LatestBatchData memory batch;\n        if (isTroveInBatch) _getLatestBatchData(batchAddress, batch);\n\n        _movePendingTroveRewardsToActivePool(_defaultPool, trove.redistBoldDebtGain, trove.redistCollGain);\n\n        (\n            singleLiquidation.debtToOffset,\n            singleLiquidation.collToSendToSP,\n            singleLiquidation.collGasCompensation,\n            singleLiquidation.debtToRedistribute,\n            singleLiquidation.collToRedistribute,\n            singleLiquidation.collSurplus\n        ) = _getOffsetAndRedistributionVals(trove.entireDebt, trove.entireColl, _boldInSPForOffsets, _price);\n\n        TroveChange memory troveChange;\n        troveChange.collDecrease = trove.entireColl;\n        troveChange.debtDecrease = trove.entireDebt;\n        troveChange.appliedRedistCollGain = trove.redistCollGain;\n        troveChange.appliedRedistBoldDebtGain = trove.redistBoldDebtGain;\n        _closeTrove(\n            _troveId,\n            troveChange,\n            batchAddress,\n            batch.entireCollWithoutRedistribution,\n            batch.entireDebtWithoutRedistribution,\n            Status.closedByLiquidation\n        );\n\n        if (isTroveInBatch) {\n            // the parenthesis in the old weighted term equals `recordedDebt + accruedInterest + accruedBatchManagementFee`\n            // We want to capture last 2 ones, as the batch part only has recorded debt. The recorded debt of the trove is duplicated there,\n            // but it needs to be, because it’s also included in `entireDebtWithoutRedistribution` in the next line.\n            // So in the end we add it once and subtract it twice, which is the same as subtracting it once.\n            singleLiquidation.oldWeightedRecordedDebt =\n                batch.weightedRecordedDebt + (trove.entireDebt - trove.redistBoldDebtGain) * batch.annualInterestRate;\n            singleLiquidation.newWeightedRecordedDebt = batch.entireDebtWithoutRedistribution * batch.annualInterestRate;\n            // Mint batch management fee\n            troveChange.batchAccruedManagementFee = batch.accruedManagementFee;\n            troveChange.oldWeightedRecordedBatchManagementFee = batch.weightedRecordedBatchManagementFee\n                + (trove.entireDebt - trove.redistBoldDebtGain) * batch.annualManagementFee;\n            troveChange.newWeightedRecordedBatchManagementFee =\n                batch.entireDebtWithoutRedistribution * batch.annualManagementFee;\n            activePool.mintBatchManagementFeeAndAccountForChange(troveChange, batchAddress);\n        } else {\n            singleLiquidation.oldWeightedRecordedDebt = trove.weightedRecordedDebt;\n        }\n\n        // Difference between liquidation penalty and liquidation threshold\n        if (singleLiquidation.collSurplus > 0) {\n            collSurplusPool.accountSurplus(owner, singleLiquidation.collSurplus);\n        }\n\n        // Wipe out state in BO\n        borrowerOperations.onLiquidateTrove(_troveId);\n\n        emit TroveUpdated({\n            _troveId: _troveId,\n            _debt: 0,\n            _coll: 0,\n            _stake: 0,\n            _annualInterestRate: 0,\n            _snapshotOfTotalCollRedist: 0,\n            _snapshotOfTotalDebtRedist: 0\n        });\n\n        emit TroveOperation({\n            _troveId: _troveId,\n            _operation: Operation.liquidate,\n            _annualInterestRate: 0,\n            _debtIncreaseFromRedist: trove.redistBoldDebtGain,\n            _debtIncreaseFromUpfrontFee: 0,\n            _debtChangeFromOperation: -int256(trove.entireDebt),\n            _collIncreaseFromRedist: trove.redistCollGain,\n            _collChangeFromOperation: -int256(trove.entireColl)\n        });\n\n        if (isTroveInBatch) {\n            emit BatchUpdated({\n                _interestBatchManager: batchAddress,\n                _operation: BatchOperation.exitBatch,\n                _debt: batches[batchAddress].debt,\n                _coll: batches[batchAddress].coll,\n                _annualInterestRate: batch.annualInterestRate,\n                _annualManagementFee: batch.annualManagementFee,\n                _totalDebtShares: batches[batchAddress].totalDebtShares,\n                _debtIncreaseFromUpfrontFee: 0\n            });\n        }\n    }\n\n    // Return the amount of Coll to be drawn from a trove's collateral and sent as gas compensation.\n    function _getCollGasCompensation(uint256 _coll) internal view returns (uint256) {\n        // _entireDebt should never be zero, but we add the condition defensively to avoid an unexpected revert\n        return LiquityMath._min(\n            _coll / systemParams.COLL_GAS_COMPENSATION_DIVISOR(), systemParams.COLL_GAS_COMPENSATION_CAP()\n        );\n    }\n\n    /* In a full liquidation, returns the values for a trove's coll and debt to be offset, and coll and debt to be\n    * redistributed to active troves.\n    */\n    function _getOffsetAndRedistributionVals(\n        uint256 _entireTroveDebt,\n        uint256 _entireTroveColl,\n        uint256 _boldInSPForOffsets,\n        uint256 _price\n    )\n        internal\n        view\n        returns (\n            uint256 debtToOffset,\n            uint256 collToSendToSP,\n            uint256 collGasCompensation,\n            uint256 debtToRedistribute,\n            uint256 collToRedistribute,\n            uint256 collSurplus\n        )\n    {\n        uint256 collSPPortion;\n        /*\n         * Offset as much debt & collateral as possible against the Stability Pool, and redistribute the remainder\n         * between all active troves.\n         *\n         *  If the trove's debt is larger than the deposited Bold in the Stability Pool:\n         *\n         *  - Offset an amount of the trove's debt equal to the Bold in the Stability Pool\n         *  - Send a fraction of the trove's collateral to the Stability Pool, equal to the fraction of its offset debt\n         *\n         */\n        if (_boldInSPForOffsets > 0) {\n            debtToOffset = LiquityMath._min(_entireTroveDebt, _boldInSPForOffsets);\n            collSPPortion = _entireTroveColl * debtToOffset / _entireTroveDebt;\n\n            collGasCompensation = _getCollGasCompensation(collSPPortion);\n            uint256 collToOffset = collSPPortion - collGasCompensation;\n\n            (collToSendToSP, collSurplus) =\n                _getCollPenaltyAndSurplus(collToOffset, debtToOffset, systemParams.LIQUIDATION_PENALTY_SP(), _price);\n        }\n\n        // Redistribution\n        debtToRedistribute = _entireTroveDebt - debtToOffset;\n        if (debtToRedistribute > 0) {\n            uint256 collRedistributionPortion = _entireTroveColl - collSPPortion;\n            if (collRedistributionPortion > 0) {\n                (collToRedistribute, collSurplus) = _getCollPenaltyAndSurplus(\n                    collRedistributionPortion + collSurplus, // Coll surplus from offset can be eaten up by red. penalty\n                    debtToRedistribute,\n                    systemParams.LIQUIDATION_PENALTY_REDISTRIBUTION(), // _penaltyRatio\n                    _price\n                );\n            }\n        }\n        // assert(_collToLiquidate == collToSendToSP + collToRedistribute + collSurplus);\n    }\n\n    function _getCollPenaltyAndSurplus(\n        uint256 _collToLiquidate,\n        uint256 _debtToLiquidate,\n        uint256 _penaltyRatio,\n        uint256 _price\n    ) internal pure returns (uint256 seizedColl, uint256 collSurplus) {\n        uint256 maxSeizedColl = _debtToLiquidate * (DECIMAL_PRECISION + _penaltyRatio) / _price;\n        if (_collToLiquidate > maxSeizedColl) {\n            seizedColl = maxSeizedColl;\n            collSurplus = _collToLiquidate - maxSeizedColl;\n        } else {\n            seizedColl = _collToLiquidate;\n            collSurplus = 0;\n        }\n    }\n\n    /*\n     * Attempt to liquidate a custom list of troves provided by the caller.\n     */\n    function batchLiquidateTroves(uint256[] memory _troveArray) public override {\n        _requireL2SequencerIsUp();\n        if (_troveArray.length == 0) {\n            revert EmptyData();\n        }\n\n        IActivePool activePoolCached = activePool;\n        IDefaultPool defaultPoolCached = defaultPool;\n        IStabilityPool stabilityPoolCached = stabilityPool;\n\n        TroveChange memory troveChange;\n        LiquidationValues memory totals;\n\n        uint256 price = priceFeed.fetchPrice();\n\n        // - If the SP has total deposits >= 1e18, we leave 1e18 in it untouched.\n        // - If it has 0 < x < 1e18 total deposits, we leave x in it.\n        uint256 totalBoldDeposits = stabilityPoolCached.getTotalBoldDeposits();\n        uint256 boldToLeaveInSP = LiquityMath._min(systemParams.MIN_BOLD_IN_SP(), totalBoldDeposits);\n        uint256 boldInSPForOffsets = totalBoldDeposits - boldToLeaveInSP;\n\n        // Perform the appropriate liquidation sequence - tally values and obtain their totals.\n        _batchLiquidateTroves(defaultPoolCached, price, boldInSPForOffsets, _troveArray, totals, troveChange);\n\n        if (troveChange.debtDecrease == 0) {\n            revert NothingToLiquidate();\n        }\n\n        activePoolCached.mintAggInterestAndAccountForTroveChange(troveChange, address(0));\n\n        // Move liquidated Coll and Bold to the appropriate pools\n        if (totals.debtToOffset > 0 || totals.collToSendToSP > 0) {\n            stabilityPoolCached.offset(totals.debtToOffset, totals.collToSendToSP);\n        }\n        // we check amount is not zero inside\n        _redistributeDebtAndColl(\n            activePoolCached, defaultPoolCached, totals.debtToRedistribute, totals.collToRedistribute\n        );\n        if (totals.collSurplus > 0) {\n            activePoolCached.sendColl(address(collSurplusPool), totals.collSurplus);\n        }\n\n        // Update system snapshots\n        _updateSystemSnapshots_excludeCollRemainder(activePoolCached, totals.collGasCompensation);\n\n        emit Liquidation(\n            totals.debtToOffset,\n            totals.debtToRedistribute,\n            totals.ETHGasCompensation,\n            totals.collGasCompensation,\n            totals.collToSendToSP,\n            totals.collToRedistribute,\n            totals.collSurplus,\n            L_coll,\n            L_boldDebt,\n            price\n        );\n\n        // Send gas compensation to caller\n        _sendGasCompensation(activePoolCached, msg.sender, totals.ETHGasCompensation, totals.collGasCompensation);\n    }\n\n    function _isActiveOrZombie(Status _status) internal pure returns (bool) {\n        return _status == Status.active || _status == Status.zombie;\n    }\n\n    function _batchLiquidateTroves(\n        IDefaultPool _defaultPool,\n        uint256 _price,\n        uint256 _boldInSPForOffsets,\n        uint256[] memory _troveArray,\n        LiquidationValues memory totals,\n        TroveChange memory troveChange\n    ) internal {\n        uint256 remainingBoldInSPForOffsets = _boldInSPForOffsets;\n\n        for (uint256 i = 0; i < _troveArray.length; i++) {\n            uint256 troveId = _troveArray[i];\n\n            // Skip non-liquidatable troves\n            if (!_isActiveOrZombie(Troves[troveId].status)) continue;\n\n            uint256 ICR = getCurrentICR(troveId, _price);\n\n            if (ICR < systemParams.MCR()) {\n                LiquidationValues memory singleLiquidation;\n                LatestTroveData memory trove;\n\n                _liquidate(_defaultPool, troveId, remainingBoldInSPForOffsets, _price, trove, singleLiquidation);\n                remainingBoldInSPForOffsets -= singleLiquidation.debtToOffset;\n\n                // Add liquidation values to their respective running totals\n                _addLiquidationValuesToTotals(trove, singleLiquidation, totals, troveChange);\n            }\n        }\n    }\n\n    // --- Liquidation helper functions ---\n\n    // Adds all values from `singleLiquidation` to their respective totals in `totals` in-place\n    function _addLiquidationValuesToTotals(\n        LatestTroveData memory _trove,\n        LiquidationValues memory _singleLiquidation,\n        LiquidationValues memory totals,\n        TroveChange memory troveChange\n    ) internal view {\n        // Tally all the values with their respective running totals\n        totals.collGasCompensation += _singleLiquidation.collGasCompensation;\n        totals.ETHGasCompensation += systemParams.ETH_GAS_COMPENSATION();\n        troveChange.debtDecrease += _trove.entireDebt;\n        troveChange.collDecrease += _trove.entireColl;\n        troveChange.appliedRedistBoldDebtGain += _trove.redistBoldDebtGain;\n        troveChange.oldWeightedRecordedDebt += _singleLiquidation.oldWeightedRecordedDebt;\n        troveChange.newWeightedRecordedDebt += _singleLiquidation.newWeightedRecordedDebt;\n        totals.debtToOffset += _singleLiquidation.debtToOffset;\n        totals.collToSendToSP += _singleLiquidation.collToSendToSP;\n        totals.debtToRedistribute += _singleLiquidation.debtToRedistribute;\n        totals.collToRedistribute += _singleLiquidation.collToRedistribute;\n        totals.collSurplus += _singleLiquidation.collSurplus;\n    }\n\n    function _sendGasCompensation(IActivePool _activePool, address _liquidator, uint256 _eth, uint256 _coll) internal {\n        if (_eth > 0) {\n            gasToken.transferFrom(gasPoolAddress, _liquidator, _eth);\n        }\n\n        if (_coll > 0) {\n            _activePool.sendColl(_liquidator, _coll);\n        }\n    }\n\n    // Move a Trove's pending debt and collateral rewards from distributions, from the Default Pool to the Active Pool\n    function _movePendingTroveRewardsToActivePool(IDefaultPool _defaultPool, uint256 _bold, uint256 _coll) internal {\n        if (_bold > 0) {\n            _defaultPool.decreaseBoldDebt(_bold);\n        }\n\n        if (_coll > 0) {\n            _defaultPool.sendCollToActivePool(_coll);\n        }\n    }\n\n    // --- Redemption functions ---\n\n    function _applySingleRedemption(\n        IDefaultPool _defaultPool,\n        SingleRedemptionValues memory _singleRedemption,\n        bool _isTroveInBatch\n    ) internal returns (uint256) {\n        // Decrease the debt and collateral of the current Trove according to the Bold lot and corresponding ETH to send\n        uint256 newDebt = _singleRedemption.trove.entireDebt - _singleRedemption.boldLot;\n        uint256 newColl = _singleRedemption.trove.entireColl - _singleRedemption.collLot;\n\n        _singleRedemption.appliedRedistBoldDebtGain = _singleRedemption.trove.redistBoldDebtGain;\n\n        if (_isTroveInBatch) {\n            _getLatestBatchData(_singleRedemption.batchAddress, _singleRedemption.batch);\n            // We know boldLot <= trove entire debt, so this subtraction is safe\n            uint256 newAmountForWeightedDebt = _singleRedemption.batch.entireDebtWithoutRedistribution\n                + _singleRedemption.trove.redistBoldDebtGain - _singleRedemption.boldLot;\n            _singleRedemption.oldWeightedRecordedDebt = _singleRedemption.batch.weightedRecordedDebt;\n            _singleRedemption.newWeightedRecordedDebt =\n                newAmountForWeightedDebt * _singleRedemption.batch.annualInterestRate;\n\n            TroveChange memory troveChange;\n            troveChange.debtDecrease = _singleRedemption.boldLot;\n            troveChange.collDecrease = _singleRedemption.collLot;\n            troveChange.appliedRedistBoldDebtGain = _singleRedemption.trove.redistBoldDebtGain;\n            troveChange.appliedRedistCollGain = _singleRedemption.trove.redistCollGain;\n            // batchAccruedManagementFee is handled in the outer function\n            troveChange.oldWeightedRecordedBatchManagementFee =\n                _singleRedemption.batch.weightedRecordedBatchManagementFee;\n            troveChange.newWeightedRecordedBatchManagementFee =\n                newAmountForWeightedDebt * _singleRedemption.batch.annualManagementFee;\n\n            activePool.mintBatchManagementFeeAndAccountForChange(troveChange, _singleRedemption.batchAddress);\n\n            Troves[_singleRedemption.troveId].coll = newColl;\n            // interest and fee were updated in the outer function\n            // This call could revert due to BatchSharesRatioTooHigh if trove.redistCollGain > boldLot\n            // so we skip that check to avoid blocking redemptions\n            _updateBatchShares(\n                _singleRedemption.troveId,\n                _singleRedemption.batchAddress,\n                troveChange,\n                newDebt,\n                _singleRedemption.batch.entireCollWithoutRedistribution,\n                _singleRedemption.batch.entireDebtWithoutRedistribution,\n                false // _checkBatchSharesRatio\n            );\n        } else {\n            _singleRedemption.oldWeightedRecordedDebt = _singleRedemption.trove.weightedRecordedDebt;\n            _singleRedemption.newWeightedRecordedDebt = newDebt * _singleRedemption.trove.annualInterestRate;\n            Troves[_singleRedemption.troveId].debt = newDebt;\n            Troves[_singleRedemption.troveId].coll = newColl;\n            Troves[_singleRedemption.troveId].lastDebtUpdateTime = uint64(block.timestamp);\n        }\n\n        _singleRedemption.newStake = _updateStakeAndTotalStakes(_singleRedemption.troveId, newColl);\n        _movePendingTroveRewardsToActivePool(\n            _defaultPool, _singleRedemption.trove.redistBoldDebtGain, _singleRedemption.trove.redistCollGain\n        );\n        _updateTroveRewardSnapshots(_singleRedemption.troveId);\n\n        if (_isTroveInBatch) {\n            emit BatchedTroveUpdated({\n                _troveId: _singleRedemption.troveId,\n                _interestBatchManager: _singleRedemption.batchAddress,\n                _batchDebtShares: Troves[_singleRedemption.troveId].batchDebtShares,\n                _coll: newColl,\n                _stake: _singleRedemption.newStake,\n                _snapshotOfTotalCollRedist: L_coll,\n                _snapshotOfTotalDebtRedist: L_boldDebt\n            });\n        } else {\n            emit TroveUpdated({\n                _troveId: _singleRedemption.troveId,\n                _debt: newDebt,\n                _coll: newColl,\n                _stake: _singleRedemption.newStake,\n                _annualInterestRate: _singleRedemption.trove.annualInterestRate,\n                _snapshotOfTotalCollRedist: L_coll,\n                _snapshotOfTotalDebtRedist: L_boldDebt\n            });\n        }\n\n        emit TroveOperation({\n            _troveId: _singleRedemption.troveId,\n            _operation: Operation.redeemCollateral,\n            _annualInterestRate: _singleRedemption.trove.annualInterestRate,\n            _debtIncreaseFromRedist: _singleRedemption.trove.redistBoldDebtGain,\n            _debtIncreaseFromUpfrontFee: 0,\n            _debtChangeFromOperation: -int256(_singleRedemption.boldLot),\n            _collIncreaseFromRedist: _singleRedemption.trove.redistCollGain,\n            _collChangeFromOperation: -int256(_singleRedemption.collLot)\n        });\n\n        if (_isTroveInBatch) {\n            emit BatchUpdated({\n                _interestBatchManager: _singleRedemption.batchAddress,\n                _operation: BatchOperation.troveChange,\n                _debt: batches[_singleRedemption.batchAddress].debt,\n                _coll: batches[_singleRedemption.batchAddress].coll,\n                _annualInterestRate: _singleRedemption.batch.annualInterestRate,\n                _annualManagementFee: _singleRedemption.batch.annualManagementFee,\n                _totalDebtShares: batches[_singleRedemption.batchAddress].totalDebtShares,\n                _debtIncreaseFromUpfrontFee: 0\n            });\n        }\n\n        emit RedemptionFeePaidToTrove(_singleRedemption.troveId, _singleRedemption.collFee);\n\n        return newDebt;\n    }\n\n    // Redeem as much collateral as possible from _borrower's Trove in exchange for Bold up to _maxBoldamount\n    function _redeemCollateralFromTrove(\n        IDefaultPool _defaultPool,\n        SingleRedemptionValues memory _singleRedemption,\n        uint256 _maxBoldamount,\n        uint256 _redemptionPrice,\n        uint256 _redemptionRate\n    ) internal {\n        _getLatestTroveData(_singleRedemption.troveId, _singleRedemption.trove);\n\n        // Determine the remaining amount (lot) to be redeemed, capped by the entire debt of the Trove\n        _singleRedemption.boldLot = LiquityMath._min(_maxBoldamount, _singleRedemption.trove.entireDebt);\n\n        // Get the amount of Coll equal in USD value to the boldLot redeemed\n        uint256 correspondingColl = _singleRedemption.boldLot * DECIMAL_PRECISION / _redemptionPrice;\n        // Calculate the collFee separately (for events)\n        _singleRedemption.collFee = correspondingColl * _redemptionRate / DECIMAL_PRECISION;\n        // Get the final collLot to send to redeemer, leaving the fee in the Trove\n        _singleRedemption.collLot = correspondingColl - _singleRedemption.collFee;\n\n        bool isTroveInBatch = _singleRedemption.batchAddress != address(0);\n        uint256 newDebt = _applySingleRedemption(_defaultPool, _singleRedemption, isTroveInBatch);\n\n        // Make Trove zombie if it's tiny (and it wasn’t already), in order to prevent griefing future (normal, sequential) redemptions\n        if (newDebt < systemParams.MIN_DEBT()) {\n            if (!_singleRedemption.isZombieTrove) {\n                Troves[_singleRedemption.troveId].status = Status.zombie;\n                if (isTroveInBatch) {\n                    sortedTroves.removeFromBatch(_singleRedemption.troveId);\n                } else {\n                    sortedTroves.remove(_singleRedemption.troveId);\n                }\n                // If it’s a partial redemption, let’s store a pointer to it so it’s used first in the next one\n                if (newDebt > 0) {\n                    lastZombieTroveId = _singleRedemption.troveId;\n                }\n            } else if (newDebt == 0) {\n                // Reset last zombie trove pointer if the previous one was fully redeemed now\n                lastZombieTroveId = 0;\n            }\n        }\n        // Note: technically, it could happen that the Trove pointed to by `lastZombieTroveId` ends up with\n        // newDebt >= systemParams.MIN_DEBT() thanks to BOLD debt redistribution, which means it _could_ be made active again,\n        // however we don't do that here, as it would require hints for re-insertion into `SortedTroves`.\n    }\n\n    function _updateBatchInterestPriorToRedemption(IActivePool _activePool, address _batchAddress) internal {\n        LatestBatchData memory batch;\n        _getLatestBatchData(_batchAddress, batch);\n        batches[_batchAddress].debt = batch.entireDebtWithoutRedistribution;\n        batches[_batchAddress].lastDebtUpdateTime = uint64(block.timestamp);\n        // As we are updating the batch, we update the ActivePool weighted sum too\n        TroveChange memory batchTroveChange;\n        batchTroveChange.oldWeightedRecordedDebt = batch.weightedRecordedDebt;\n        batchTroveChange.newWeightedRecordedDebt = batch.entireDebtWithoutRedistribution * batch.annualInterestRate;\n        batchTroveChange.batchAccruedManagementFee = batch.accruedManagementFee;\n        batchTroveChange.oldWeightedRecordedBatchManagementFee = batch.weightedRecordedBatchManagementFee;\n        batchTroveChange.newWeightedRecordedBatchManagementFee =\n            batch.entireDebtWithoutRedistribution * batch.annualManagementFee;\n\n        _activePool.mintAggInterestAndAccountForTroveChange(batchTroveChange, _batchAddress);\n    }\n\n    /* Send _boldamount Bold to the system and redeem the corresponding amount of collateral from as many Troves as are needed to fill the redemption\n    * request.  Applies redistribution gains to a Trove before reducing its debt and coll.\n    *\n    * Note that if _amount is very large, this function can run out of gas, specially if traversed troves are small. This can be easily avoided by\n    * splitting the total _amount in appropriate chunks and calling the function multiple times.\n    *\n    * Param `_maxIterations` can also be provided, so the loop through Troves is capped (if it’s zero, it will be ignored).This makes it easier to\n    * avoid OOG for the frontend, as only knowing approximately the average cost of an iteration is enough, without needing to know the “topology”\n    * of the trove list. It also avoids the need to set the cap in stone in the contract, nor doing gas calculations, as both gas price and opcode\n    * costs can vary.\n    *\n    * All Troves that are redeemed from -- with the likely exception of the last one -- will end up with no debt left, and therefore in “zombie” state\n    */\n    function redeemCollateral(\n        address _redeemer,\n        uint256 _boldamount,\n        uint256 _price,\n        uint256 _redemptionRate,\n        uint256 _maxIterations\n    ) external override returns (uint256 _redeemedAmount) {\n        _requireCallerIsCollateralRegistry();\n\n        IActivePool activePoolCached = activePool;\n        ISortedTroves sortedTrovesCached = sortedTroves;\n\n        TroveChange memory totalsTroveChange;\n        RedeemCollateralValues memory vars;\n\n        vars.remainingBold = _boldamount;\n\n        SingleRedemptionValues memory singleRedemption;\n        // Let’s check if there’s a pending zombie trove from previous redemption\n        if (lastZombieTroveId != 0) {\n            singleRedemption.troveId = lastZombieTroveId;\n            singleRedemption.isZombieTrove = true;\n        } else {\n            singleRedemption.troveId = sortedTrovesCached.getLast();\n        }\n        vars.lastBatchUpdatedInterest = address(0);\n\n        uint256 redemptionPrice = priceFeed.fetchPrice();\n\n        // Loop through the Troves starting from the one with lowest interest rate until _amount of Bold is exchanged for collateral\n        if (_maxIterations == 0) _maxIterations = type(uint256).max;\n        while (singleRedemption.troveId != 0 && vars.remainingBold > 0 && _maxIterations > 0) {\n            _maxIterations--;\n            // Save the uint256 of the Trove preceding the current one\n            if (singleRedemption.isZombieTrove) {\n                vars.nextUserToCheck = sortedTrovesCached.getLast();\n            } else {\n                vars.nextUserToCheck = sortedTrovesCached.getPrev(singleRedemption.troveId);\n            }\n\n            // Skip if ICR < 100%, to make sure that redemptions don’t decrease the CR of hit Troves.\n            // Use the normal price for the ICR check.\n            if (getCurrentICR(singleRedemption.troveId, _price) < _100pct) {\n                singleRedemption.troveId = vars.nextUserToCheck;\n                singleRedemption.isZombieTrove = false;\n                continue;\n            }\n\n            // If it’s in a batch, we need to update interest first\n            // We do it here outside, to avoid repeating for each trove in the same batch\n            singleRedemption.batchAddress = _getBatchManager(singleRedemption.troveId);\n            if (\n                singleRedemption.batchAddress != address(0)\n                    && singleRedemption.batchAddress != vars.lastBatchUpdatedInterest\n            ) {\n                _updateBatchInterestPriorToRedemption(activePoolCached, singleRedemption.batchAddress);\n                vars.lastBatchUpdatedInterest = singleRedemption.batchAddress;\n            }\n\n            _redeemCollateralFromTrove(\n                defaultPool, singleRedemption, vars.remainingBold, redemptionPrice, _redemptionRate\n            );\n\n            totalsTroveChange.collDecrease += singleRedemption.collLot;\n            totalsTroveChange.debtDecrease += singleRedemption.boldLot;\n            totalsTroveChange.appliedRedistBoldDebtGain += singleRedemption.appliedRedistBoldDebtGain;\n            // For recorded and weighted recorded debt totals, we need to capture the increases and decreases,\n            // since the net debt change for a given Trove could be positive or negative: redemptions decrease a Trove's recorded\n            // (and weighted recorded) debt, but the accrued interest increases it.\n            totalsTroveChange.newWeightedRecordedDebt += singleRedemption.newWeightedRecordedDebt;\n            totalsTroveChange.oldWeightedRecordedDebt += singleRedemption.oldWeightedRecordedDebt;\n            vars.totalCollFee += singleRedemption.collFee;\n\n            vars.remainingBold -= singleRedemption.boldLot;\n            singleRedemption.troveId = vars.nextUserToCheck;\n            singleRedemption.isZombieTrove = false;\n        }\n\n        // We are removing this condition to prevent blocking redemptions\n        //require(totals.totalCollDrawn > 0, \"TroveManager: Unable to redeem any amount\");\n\n        emit Redemption(\n            _boldamount,\n            totalsTroveChange.debtDecrease,\n            totalsTroveChange.collDecrease,\n            vars.totalCollFee,\n            _price,\n            redemptionPrice\n        );\n\n        activePoolCached.mintAggInterestAndAccountForTroveChange(totalsTroveChange, address(0));\n\n        // Send the redeemed Coll to sender\n        activePoolCached.sendColl(_redeemer, totalsTroveChange.collDecrease);\n        // We’ll burn all the Bold together out in the CollateralRegistry, to save gas\n\n        return totalsTroveChange.debtDecrease;\n    }\n\n    // Redeem as much collateral as possible from _borrower's Trove in exchange for Bold up to _maxBoldamount\n    function _urgentRedeemCollateralFromTrove(\n        IDefaultPool _defaultPool,\n        uint256 _maxBoldamount,\n        uint256 _price,\n        SingleRedemptionValues memory _singleRedemption\n    ) internal {\n        // Determine the remaining amount (lot) to be redeemed, capped by the entire debt of the Trove minus the liquidation reserve\n        _singleRedemption.boldLot = LiquityMath._min(_maxBoldamount, _singleRedemption.trove.entireDebt);\n\n        // Get the amount of ETH equal in USD value to the BOLD lot redeemed\n        _singleRedemption.collLot = _singleRedemption.boldLot * (DECIMAL_PRECISION + URGENT_REDEMPTION_BONUS) / _price;\n        // As here we can redeem when CR < 101% (accounting for 1% bonus), we need to cap by collateral too\n        if (_singleRedemption.collLot > _singleRedemption.trove.entireColl) {\n            _singleRedemption.collLot = _singleRedemption.trove.entireColl;\n            _singleRedemption.boldLot =\n                _singleRedemption.trove.entireColl * _price / (DECIMAL_PRECISION + URGENT_REDEMPTION_BONUS);\n        }\n\n        bool isTroveInBatch = _singleRedemption.batchAddress != address(0);\n        _applySingleRedemption(_defaultPool, _singleRedemption, isTroveInBatch);\n\n        // No need to make this Trove zombie if it has tiny debt, since:\n        // - This collateral branch has shut down and urgent redemptions are enabled\n        // - Urgent redemptions aren't sequential, so they can't be griefed by tiny Troves.\n    }\n\n    function urgentRedemption(uint256 _boldAmount, uint256[] calldata _troveIds, uint256 _minCollateral) external {\n        _requireIsShutDown();\n        _requireAmountGreaterThanZero(_boldAmount);\n        _requireBoldBalanceCoversRedemption(boldToken, msg.sender, _boldAmount);\n\n        IActivePool activePoolCached = activePool;\n        TroveChange memory totalsTroveChange;\n\n        // Use the standard fetchPrice here, since if branch has shut down we don't worry about small redemption arbs\n        uint256 price = priceFeed.fetchPrice();\n\n        uint256 remainingBold = _boldAmount;\n        for (uint256 i = 0; i < _troveIds.length; i++) {\n            if (remainingBold == 0) break;\n\n            SingleRedemptionValues memory singleRedemption;\n            singleRedemption.troveId = _troveIds[i];\n            _getLatestTroveData(singleRedemption.troveId, singleRedemption.trove);\n\n            if (!_isActiveOrZombie(Troves[singleRedemption.troveId].status) || singleRedemption.trove.entireDebt == 0) {\n                continue;\n            }\n\n            // If it’s in a batch, we need to update interest first\n            // As we don’t have them ordered now, we cannot avoid repeating for each trove in the same batch\n            singleRedemption.batchAddress = _getBatchManager(singleRedemption.troveId);\n            if (singleRedemption.batchAddress != address(0)) {\n                _updateBatchInterestPriorToRedemption(activePoolCached, singleRedemption.batchAddress);\n            }\n\n            _urgentRedeemCollateralFromTrove(defaultPool, remainingBold, price, singleRedemption);\n\n            totalsTroveChange.collDecrease += singleRedemption.collLot;\n            totalsTroveChange.debtDecrease += singleRedemption.boldLot;\n            totalsTroveChange.appliedRedistBoldDebtGain += singleRedemption.appliedRedistBoldDebtGain;\n            // For recorded and weighted recorded debt totals, we need to capture the increases and decreases,\n            // since the net debt change for a given Trove could be positive or negative: redemptions decrease a Trove's recorded\n            // (and weighted recorded) debt, but the accrued interest increases it.\n            totalsTroveChange.newWeightedRecordedDebt += singleRedemption.newWeightedRecordedDebt;\n            totalsTroveChange.oldWeightedRecordedDebt += singleRedemption.oldWeightedRecordedDebt;\n\n            remainingBold -= singleRedemption.boldLot;\n        }\n\n        if (totalsTroveChange.collDecrease < _minCollateral) {\n            revert MinCollNotReached(totalsTroveChange.collDecrease);\n        }\n\n        emit Redemption(_boldAmount, totalsTroveChange.debtDecrease, totalsTroveChange.collDecrease, 0, price, price);\n\n        // Since this branch is shut down, this will mint 0 interest.\n        // We call this only to update the aggregate debt and weighted debt trackers.\n        activePoolCached.mintAggInterestAndAccountForTroveChange(totalsTroveChange, address(0));\n\n        // Send the redeemed coll to caller\n        activePoolCached.sendColl(msg.sender, totalsTroveChange.collDecrease);\n        // Burn bold\n        boldToken.burn(msg.sender, totalsTroveChange.debtDecrease);\n    }\n\n    function shutdown() external {\n        _requireCallerIsBorrowerOperations();\n        shutdownTime = block.timestamp;\n        activePool.setShutdownFlag();\n    }\n\n    // --- Helper functions ---\n\n    // Return the current collateral ratio (ICR) of a given Trove. Takes a trove's pending coll and debt rewards from redistributions into account.\n    function getCurrentICR(uint256 _troveId, uint256 _price) public view override returns (uint256) {\n        LatestTroveData memory trove;\n        _getLatestTroveData(_troveId, trove);\n        return LiquityMath._computeCR(trove.entireColl, trove.entireDebt, _price);\n    }\n\n    function _updateTroveRewardSnapshots(uint256 _troveId) internal {\n        rewardSnapshots[_troveId].coll = L_coll;\n        rewardSnapshots[_troveId].boldDebt = L_boldDebt;\n    }\n\n    // Return the Troves entire debt and coll, including redistribution gains from redistributions.\n    function _getLatestTroveData(uint256 _troveId, LatestTroveData memory trove) internal view {\n        // If trove belongs to a batch, we fetch the batch and apply its share to obtained values\n        address batchAddress = _getBatchManager(_troveId);\n        if (batchAddress != address(0)) {\n            LatestBatchData memory batch;\n            _getLatestBatchData(batchAddress, batch);\n            _getLatestTroveDataFromBatch(_troveId, trove, batch);\n            return;\n        }\n\n        uint256 stake = Troves[_troveId].stake;\n        trove.redistBoldDebtGain = stake * (L_boldDebt - rewardSnapshots[_troveId].boldDebt) / DECIMAL_PRECISION;\n        trove.redistCollGain = stake * (L_coll - rewardSnapshots[_troveId].coll) / DECIMAL_PRECISION;\n\n        trove.recordedDebt = Troves[_troveId].debt;\n        trove.annualInterestRate = Troves[_troveId].annualInterestRate;\n        trove.weightedRecordedDebt = trove.recordedDebt * trove.annualInterestRate;\n\n        uint256 period = _getInterestPeriod(Troves[_troveId].lastDebtUpdateTime);\n        trove.accruedInterest = _calcInterest(trove.weightedRecordedDebt, period);\n\n        trove.entireDebt = trove.recordedDebt + trove.redistBoldDebtGain + trove.accruedInterest;\n        trove.entireColl = Troves[_troveId].coll + trove.redistCollGain;\n        trove.lastInterestRateAdjTime = Troves[_troveId].lastInterestRateAdjTime;\n    }\n\n    function _getLatestTroveDataFromBatch(\n        uint256 _troveId,\n        LatestTroveData memory _latestTroveData,\n        LatestBatchData memory _latestBatchData\n    ) internal view {\n        Trove memory trove = Troves[_troveId];\n        uint256 batchDebtShares = trove.batchDebtShares;\n        uint256 totalDebtShares = _latestBatchData.totalDebtShares;\n\n        uint256 stake = trove.stake;\n        _latestTroveData.redistBoldDebtGain =\n            stake * (L_boldDebt - rewardSnapshots[_troveId].boldDebt) / DECIMAL_PRECISION;\n        _latestTroveData.redistCollGain = stake * (L_coll - rewardSnapshots[_troveId].coll) / DECIMAL_PRECISION;\n\n        if (totalDebtShares > 0) {\n            _latestTroveData.recordedDebt = _latestBatchData.recordedDebt * batchDebtShares / totalDebtShares;\n            _latestTroveData.weightedRecordedDebt = _latestTroveData.recordedDebt * _latestBatchData.annualInterestRate;\n            _latestTroveData.accruedInterest = _latestBatchData.accruedInterest * batchDebtShares / totalDebtShares;\n            _latestTroveData.accruedBatchManagementFee =\n                _latestBatchData.accruedManagementFee * batchDebtShares / totalDebtShares;\n        }\n        _latestTroveData.annualInterestRate = _latestBatchData.annualInterestRate;\n\n        // We can’t do pro-rata batch entireDebt, because redist gains are proportional to coll, not to debt\n        _latestTroveData.entireDebt = _latestTroveData.recordedDebt + _latestTroveData.redistBoldDebtGain\n            + _latestTroveData.accruedInterest + _latestTroveData.accruedBatchManagementFee;\n        _latestTroveData.entireColl = trove.coll + _latestTroveData.redistCollGain;\n        _latestTroveData.lastInterestRateAdjTime =\n            LiquityMath._max(_latestBatchData.lastInterestRateAdjTime, trove.lastInterestRateAdjTime);\n    }\n\n    function getLatestTroveData(uint256 _troveId) external view returns (LatestTroveData memory trove) {\n        _getLatestTroveData(_troveId, trove);\n    }\n\n    function getTroveAnnualInterestRate(uint256 _troveId) external view returns (uint256) {\n        Trove memory trove = Troves[_troveId];\n        address batchAddress = _getBatchManager(trove);\n        if (batchAddress != address(0)) {\n            return batches[batchAddress].annualInterestRate;\n        }\n        return trove.annualInterestRate;\n    }\n\n    function _getBatchManager(uint256 _troveId) internal view returns (address) {\n        return Troves[_troveId].interestBatchManager;\n    }\n\n    function _getBatchManager(Trove memory trove) internal pure returns (address) {\n        return trove.interestBatchManager;\n    }\n\n    // Return the Batch entire debt and coll, including redistribution gains from redistributions.\n    function _getLatestBatchData(address _batchAddress, LatestBatchData memory latestBatchData) internal view {\n        Batch memory batch = batches[_batchAddress];\n\n        latestBatchData.totalDebtShares = batch.totalDebtShares;\n        latestBatchData.recordedDebt = batch.debt;\n        latestBatchData.annualInterestRate = batch.annualInterestRate;\n        latestBatchData.weightedRecordedDebt = latestBatchData.recordedDebt * latestBatchData.annualInterestRate;\n        uint256 period = _getInterestPeriod(batch.lastDebtUpdateTime);\n        latestBatchData.accruedInterest = _calcInterest(latestBatchData.weightedRecordedDebt, period);\n        latestBatchData.annualManagementFee = batch.annualManagementFee;\n        latestBatchData.weightedRecordedBatchManagementFee =\n            latestBatchData.recordedDebt * latestBatchData.annualManagementFee;\n        latestBatchData.accruedManagementFee = _calcInterest(latestBatchData.weightedRecordedBatchManagementFee, period);\n\n        latestBatchData.entireDebtWithoutRedistribution =\n            latestBatchData.recordedDebt + latestBatchData.accruedInterest + latestBatchData.accruedManagementFee;\n        latestBatchData.entireCollWithoutRedistribution = batch.coll;\n        latestBatchData.lastDebtUpdateTime = batch.lastDebtUpdateTime;\n        latestBatchData.lastInterestRateAdjTime = batch.lastInterestRateAdjTime;\n    }\n\n    function getLatestBatchData(address _batchAddress) external view returns (LatestBatchData memory batch) {\n        _getLatestBatchData(_batchAddress, batch);\n    }\n\n    // Update borrower's stake based on their latest collateral value\n    function _updateStakeAndTotalStakes(uint256 _troveId, uint256 _coll) internal returns (uint256 newStake) {\n        newStake = _computeNewStake(_coll);\n        uint256 oldStake = Troves[_troveId].stake;\n        Troves[_troveId].stake = newStake;\n\n        totalStakes = totalStakes - oldStake + newStake;\n    }\n\n    // Calculate a new stake based on the snapshots of the totalStakes and totalCollateral taken at the last liquidation\n    function _computeNewStake(uint256 _coll) internal view returns (uint256) {\n        uint256 stake;\n        if (totalCollateralSnapshot == 0) {\n            stake = _coll;\n        } else {\n            /*\n            * The following assert() holds true because:\n            * - The system always contains >= 1 trove\n            * - When we close or liquidate a trove, we redistribute the redistribution gains, so if all troves were closed/liquidated,\n            * rewards would’ve been emptied and totalCollateralSnapshot would be zero too.\n            */\n            // assert(totalStakesSnapshot > 0);\n            stake = _coll * totalStakesSnapshot / totalCollateralSnapshot;\n        }\n        return stake;\n    }\n\n    function _redistributeDebtAndColl(\n        IActivePool _activePool,\n        IDefaultPool _defaultPool,\n        uint256 _debtToRedistribute,\n        uint256 _collToRedistribute\n    ) internal {\n        if (_debtToRedistribute == 0) return; // Otherwise _collToRedistribute > 0 too\n\n        /*\n        * Add distributed coll and debt rewards-per-unit-staked to the running totals. Division uses a \"feedback\"\n        * error correction, to keep the cumulative error low in the running totals L_coll and L_boldDebt:\n        *\n        * 1) Form numerators which compensate for the floor division errors that occurred the last time this\n        * function was called.\n        * 2) Calculate \"per-unit-staked\" ratios.\n        * 3) Multiply each ratio back by its denominator, to reveal the current floor division error.\n        * 4) Store these errors for use in the next correction when this function is called.\n        * 5) Note: static analysis tools complain about this \"division before multiplication\", however, it is intended.\n        */\n        uint256 collNumerator = _collToRedistribute * DECIMAL_PRECISION + lastCollError_Redistribution;\n        uint256 boldDebtNumerator = _debtToRedistribute * DECIMAL_PRECISION + lastBoldDebtError_Redistribution;\n\n        // Get the per-unit-staked terms\n        uint256 collRewardPerUnitStaked = collNumerator / totalStakes;\n        uint256 boldDebtRewardPerUnitStaked = boldDebtNumerator / totalStakes;\n\n        lastCollError_Redistribution = collNumerator - collRewardPerUnitStaked * totalStakes;\n        lastBoldDebtError_Redistribution = boldDebtNumerator - boldDebtRewardPerUnitStaked * totalStakes;\n\n        // Add per-unit-staked terms to the running totals\n        L_coll = L_coll + collRewardPerUnitStaked;\n        L_boldDebt = L_boldDebt + boldDebtRewardPerUnitStaked;\n\n        _defaultPool.increaseBoldDebt(_debtToRedistribute);\n        _activePool.sendCollToDefaultPool(_collToRedistribute);\n    }\n\n    /*\n    * Updates snapshots of system total stakes and total collateral, excluding a given collateral remainder from the calculation.\n    * Used in a liquidation sequence.\n    */\n    function _updateSystemSnapshots_excludeCollRemainder(IActivePool _activePool, uint256 _collRemainder) internal {\n        totalStakesSnapshot = totalStakes;\n\n        uint256 activeColl = _activePool.getCollBalance();\n        uint256 liquidatedColl = defaultPool.getCollBalance();\n        totalCollateralSnapshot = activeColl - _collRemainder + liquidatedColl;\n    }\n\n    /*\n    * Remove a Trove owner from the TroveIds array, not preserving array order. Removing owner 'B' does the following:\n    * [A B C D E] => [A E C D], and updates E's Trove struct to point to its new array index.\n    */\n    function _removeTroveId(uint256 _troveId, uint256 TroveIdsArrayLength) internal {\n        uint64 index = Troves[_troveId].arrayIndex;\n        uint256 idxLast = TroveIdsArrayLength - 1;\n\n        // assert(index <= idxLast);\n\n        uint256 idToMove = TroveIds[idxLast];\n\n        TroveIds[index] = idToMove;\n        Troves[idToMove].arrayIndex = index;\n\n        TroveIds.pop();\n    }\n\n    function getTroveStatus(uint256 _troveId) external view override returns (Status) {\n        return Troves[_troveId].status;\n    }\n\n    // --- Interest rate calculations ---\n\n    function _getInterestPeriod(uint256 _lastDebtUpdateTime) internal view returns (uint256) {\n        if (shutdownTime == 0) {\n            // If branch is not shut down, interest is earned up to now.\n            return block.timestamp - _lastDebtUpdateTime;\n        } else if (shutdownTime > 0 && _lastDebtUpdateTime < shutdownTime) {\n            // If branch is shut down and the Trove was not updated since shut down, interest is earned up to the shutdown time.\n            return shutdownTime - _lastDebtUpdateTime;\n        } else {\n            // if (shutdownTime > 0 && _lastDebtUpdateTime >= shutdownTime)\n            // If branch is shut down and the Trove was updated after shutdown, no interest is earned since.\n            return 0;\n        }\n    }\n\n    // --- 'require' wrapper functions ---\n\n    function _requireCallerIsBorrowerOperations() internal view {\n        if (msg.sender != address(borrowerOperations)) {\n            revert CallerNotBorrowerOperations();\n        }\n    }\n\n    function _requireCallerIsCollateralRegistry() internal view {\n        if (msg.sender != address(collateralRegistry)) {\n            revert CallerNotCollateralRegistry();\n        }\n    }\n\n    function _requireMoreThanOneTroveInSystem(uint256 TroveIdsArrayLength) internal pure {\n        if (TroveIdsArrayLength == 1) {\n            revert OnlyOneTroveLeft();\n        }\n    }\n\n    function _requireIsShutDown() internal view {\n        if (shutdownTime == 0) {\n            revert NotShutDown();\n        }\n    }\n\n    function _requireAmountGreaterThanZero(uint256 _amount) internal pure {\n        if (_amount == 0) {\n            revert ZeroAmount();\n        }\n    }\n\n    function _requireBoldBalanceCoversRedemption(IBoldToken _boldToken, address _redeemer, uint256 _amount)\n        internal\n        view\n    {\n        uint256 boldBalance = _boldToken.balanceOf(_redeemer);\n        if (boldBalance < _amount) {\n            revert NotEnoughBoldBalance();\n        }\n    }\n\n    function _requireL2SequencerIsUp() internal view {\n        if (!priceFeed.isL2SequencerUp()) {\n            revert L2SequencerDown();\n        }\n    }\n\n    // --- Trove property getters ---\n\n    function getUnbackedPortionPriceAndRedeemability() external returns (uint256, uint256, bool) {\n        uint256 totalDebt = getEntireBranchDebt();\n        uint256 spSize = stabilityPool.getTotalBoldDeposits();\n        uint256 unbackedPortion = totalDebt > spSize ? totalDebt - spSize : 0;\n\n        uint256 price = priceFeed.fetchPrice();\n        // It's redeemable if the TCR is above the shutdown threshold, and branch has not been shut down.\n        // Use the normal price for the TCR check.\n        bool redeemable = _getTCR(price) >= systemParams.SCR() && shutdownTime == 0;\n\n        return (unbackedPortion, price, redeemable);\n    }\n\n    // --- Trove property setters, called by BorrowerOperations ---\n\n    function onOpenTrove(address _owner, uint256 _troveId, TroveChange memory _troveChange, uint256 _annualInterestRate)\n        external\n    {\n        _requireCallerIsBorrowerOperations();\n\n        uint256 newStake = _computeNewStake(_troveChange.collIncrease);\n\n        // Trove memory newTrove;\n        Troves[_troveId].debt = _troveChange.debtIncrease + _troveChange.upfrontFee;\n        Troves[_troveId].coll = _troveChange.collIncrease;\n        Troves[_troveId].stake = newStake;\n        Troves[_troveId].status = Status.active;\n        Troves[_troveId].arrayIndex = uint64(TroveIds.length);\n        Troves[_troveId].lastDebtUpdateTime = uint64(block.timestamp);\n        Troves[_troveId].lastInterestRateAdjTime = uint64(block.timestamp);\n        Troves[_troveId].annualInterestRate = _annualInterestRate;\n\n        // Push the trove's id to the Trove list\n        TroveIds.push(_troveId);\n\n        uint256 newTotalStakes = totalStakes + newStake;\n        totalStakes = newTotalStakes;\n\n        // mint ERC721\n        troveNFT.mint(_owner, _troveId);\n\n        _updateTroveRewardSnapshots(_troveId);\n\n        emit TroveUpdated({\n            _troveId: _troveId,\n            _debt: _troveChange.debtIncrease + _troveChange.upfrontFee,\n            _coll: _troveChange.collIncrease,\n            _stake: newStake,\n            _annualInterestRate: _annualInterestRate,\n            _snapshotOfTotalCollRedist: L_coll,\n            _snapshotOfTotalDebtRedist: L_boldDebt\n        });\n\n        emit TroveOperation({\n            _troveId: _troveId,\n            _operation: Operation.openTrove,\n            _annualInterestRate: _annualInterestRate,\n            _debtIncreaseFromRedist: 0,\n            _debtIncreaseFromUpfrontFee: _troveChange.upfrontFee,\n            _debtChangeFromOperation: int256(_troveChange.debtIncrease),\n            _collIncreaseFromRedist: 0,\n            _collChangeFromOperation: int256(_troveChange.collIncrease)\n        });\n    }\n\n    function onOpenTroveAndJoinBatch(\n        address _owner,\n        uint256 _troveId,\n        TroveChange memory _troveChange,\n        address _batchAddress,\n        uint256 _batchColl,\n        uint256 _batchDebt\n    ) external {\n        _requireCallerIsBorrowerOperations();\n        // assert(batchIds[batches[_batchAddress].arrayIndex] == _batchAddress);\n\n        uint256 newStake = _computeNewStake(_troveChange.collIncrease);\n\n        // Trove memory newTrove;\n        Troves[_troveId].coll = _troveChange.collIncrease;\n        Troves[_troveId].stake = newStake;\n        Troves[_troveId].status = Status.active;\n        Troves[_troveId].arrayIndex = uint64(TroveIds.length);\n        Troves[_troveId].interestBatchManager = _batchAddress;\n        Troves[_troveId].lastInterestRateAdjTime = uint64(block.timestamp);\n\n        _updateTroveRewardSnapshots(_troveId);\n\n        // Push the trove's id to the Trove list\n        TroveIds.push(_troveId);\n\n        assert(_troveChange.debtIncrease > 0);\n        _updateBatchShares(\n            _troveId, _batchAddress, _troveChange, _troveChange.debtIncrease, _batchColl, _batchDebt, true\n        );\n\n        uint256 newTotalStakes = totalStakes + newStake;\n        totalStakes = newTotalStakes;\n\n        // mint ERC721\n        troveNFT.mint(_owner, _troveId);\n\n        emit BatchedTroveUpdated({\n            _troveId: _troveId,\n            _interestBatchManager: _batchAddress,\n            _batchDebtShares: Troves[_troveId].batchDebtShares,\n            _coll: _troveChange.collIncrease,\n            _stake: newStake,\n            _snapshotOfTotalCollRedist: L_coll,\n            _snapshotOfTotalDebtRedist: L_boldDebt\n        });\n\n        emit TroveOperation({\n            _troveId: _troveId,\n            _operation: Operation.openTroveAndJoinBatch,\n            _annualInterestRate: batches[_batchAddress].annualInterestRate,\n            _debtIncreaseFromRedist: 0,\n            _debtIncreaseFromUpfrontFee: _troveChange.upfrontFee,\n            _debtChangeFromOperation: int256(_troveChange.debtIncrease),\n            _collIncreaseFromRedist: 0,\n            _collChangeFromOperation: int256(_troveChange.collIncrease)\n        });\n\n        emit BatchUpdated({\n            _interestBatchManager: _batchAddress,\n            _operation: BatchOperation.joinBatch,\n            _debt: batches[_batchAddress].debt,\n            _coll: batches[_batchAddress].coll,\n            _annualInterestRate: batches[_batchAddress].annualInterestRate,\n            _annualManagementFee: batches[_batchAddress].annualManagementFee,\n            _totalDebtShares: batches[_batchAddress].totalDebtShares,\n            // Although the Trove joining the batch pays an upfront fee,\n            // it is an individual fee, so we don't include it here\n            _debtIncreaseFromUpfrontFee: 0\n        });\n    }\n\n    function setTroveStatusToActive(uint256 _troveId) external {\n        _requireCallerIsBorrowerOperations();\n        Troves[_troveId].status = Status.active;\n        if (lastZombieTroveId == _troveId) {\n            lastZombieTroveId = 0;\n        }\n    }\n\n    function onAdjustTroveInterestRate(\n        uint256 _troveId,\n        uint256 _newColl,\n        uint256 _newDebt,\n        uint256 _newAnnualInterestRate,\n        TroveChange calldata _troveChange\n    ) external {\n        _requireCallerIsBorrowerOperations();\n\n        Troves[_troveId].coll = _newColl;\n        Troves[_troveId].debt = _newDebt;\n        Troves[_troveId].annualInterestRate = _newAnnualInterestRate;\n        Troves[_troveId].lastDebtUpdateTime = uint64(block.timestamp);\n        Troves[_troveId].lastInterestRateAdjTime = uint64(block.timestamp);\n\n        _movePendingTroveRewardsToActivePool(\n            defaultPool, _troveChange.appliedRedistBoldDebtGain, _troveChange.appliedRedistCollGain\n        );\n\n        _updateTroveRewardSnapshots(_troveId);\n\n        emit TroveUpdated({\n            _troveId: _troveId,\n            _debt: _newDebt,\n            _coll: _newColl,\n            _stake: Troves[_troveId].stake,\n            _annualInterestRate: _newAnnualInterestRate,\n            _snapshotOfTotalCollRedist: L_coll,\n            _snapshotOfTotalDebtRedist: L_boldDebt\n        });\n\n        emit TroveOperation({\n            _troveId: _troveId,\n            _operation: Operation.adjustTroveInterestRate,\n            _annualInterestRate: _newAnnualInterestRate,\n            _debtIncreaseFromRedist: _troveChange.appliedRedistBoldDebtGain,\n            _debtIncreaseFromUpfrontFee: _troveChange.upfrontFee,\n            _debtChangeFromOperation: 0,\n            _collIncreaseFromRedist: _troveChange.appliedRedistCollGain,\n            _collChangeFromOperation: 0\n        });\n    }\n\n    function onAdjustTrove(uint256 _troveId, uint256 _newColl, uint256 _newDebt, TroveChange calldata _troveChange)\n        external\n    {\n        _requireCallerIsBorrowerOperations();\n\n        Troves[_troveId].coll = _newColl;\n        Troves[_troveId].debt = _newDebt;\n        Troves[_troveId].lastDebtUpdateTime = uint64(block.timestamp);\n\n        _movePendingTroveRewardsToActivePool(\n            defaultPool, _troveChange.appliedRedistBoldDebtGain, _troveChange.appliedRedistCollGain\n        );\n\n        uint256 newStake = _updateStakeAndTotalStakes(_troveId, _newColl);\n        _updateTroveRewardSnapshots(_troveId);\n\n        emit TroveUpdated({\n            _troveId: _troveId,\n            _debt: _newDebt,\n            _coll: _newColl,\n            _stake: newStake,\n            _annualInterestRate: Troves[_troveId].annualInterestRate,\n            _snapshotOfTotalCollRedist: L_coll,\n            _snapshotOfTotalDebtRedist: L_boldDebt\n        });\n\n        emit TroveOperation({\n            _troveId: _troveId,\n            _operation: Operation.adjustTrove,\n            _annualInterestRate: Troves[_troveId].annualInterestRate,\n            _debtIncreaseFromRedist: _troveChange.appliedRedistBoldDebtGain,\n            _debtIncreaseFromUpfrontFee: _troveChange.upfrontFee,\n            _debtChangeFromOperation: int256(_troveChange.debtIncrease) - int256(_troveChange.debtDecrease),\n            _collIncreaseFromRedist: _troveChange.appliedRedistCollGain,\n            _collChangeFromOperation: int256(_troveChange.collIncrease) - int256(_troveChange.collDecrease)\n        });\n    }\n\n    function onCloseTrove(\n        uint256 _troveId,\n        TroveChange memory _troveChange, // decrease vars: entire, with interest, batch fee and redistribution\n        address _batchAddress,\n        uint256 _newBatchColl,\n        uint256 _newBatchDebt // entire, with interest and batch fee\n    ) external override {\n        _requireCallerIsBorrowerOperations();\n        _closeTrove(_troveId, _troveChange, _batchAddress, _newBatchColl, _newBatchDebt, Status.closedByOwner);\n        _movePendingTroveRewardsToActivePool(\n            defaultPool, _troveChange.appliedRedistBoldDebtGain, _troveChange.appliedRedistCollGain\n        );\n\n        emit TroveUpdated({\n            _troveId: _troveId,\n            _debt: 0,\n            _coll: 0,\n            _stake: 0,\n            _annualInterestRate: 0,\n            _snapshotOfTotalCollRedist: 0,\n            _snapshotOfTotalDebtRedist: 0\n        });\n\n        emit TroveOperation({\n            _troveId: _troveId,\n            _operation: Operation.closeTrove,\n            _annualInterestRate: 0,\n            _debtIncreaseFromRedist: _troveChange.appliedRedistBoldDebtGain,\n            _debtIncreaseFromUpfrontFee: _troveChange.upfrontFee,\n            _debtChangeFromOperation: int256(_troveChange.debtIncrease) - int256(_troveChange.debtDecrease),\n            _collIncreaseFromRedist: _troveChange.appliedRedistCollGain,\n            _collChangeFromOperation: int256(_troveChange.collIncrease) - int256(_troveChange.collDecrease)\n        });\n\n        if (_batchAddress != address(0)) {\n            emit BatchUpdated({\n                _interestBatchManager: _batchAddress,\n                _operation: BatchOperation.exitBatch,\n                _debt: batches[_batchAddress].debt,\n                _coll: batches[_batchAddress].coll,\n                _annualInterestRate: batches[_batchAddress].annualInterestRate,\n                _annualManagementFee: batches[_batchAddress].annualManagementFee,\n                _totalDebtShares: batches[_batchAddress].totalDebtShares,\n                _debtIncreaseFromUpfrontFee: 0\n            });\n        }\n    }\n\n    function _closeTrove(\n        uint256 _troveId,\n        TroveChange memory _troveChange, // decrease vars: entire, with interest, batch fee and redistribution\n        address _batchAddress,\n        uint256 _newBatchColl,\n        uint256 _newBatchDebt, // entire, with interest and batch fee\n        Status closedStatus\n    ) internal {\n        // assert(closedStatus == Status.closedByLiquidation || closedStatus == Status.closedByOwner);\n\n        uint256 TroveIdsArrayLength = TroveIds.length;\n        // If branch has not been shut down, or it's a liquidation,\n        // require at least 1 trove in the system\n        if (shutdownTime == 0 || closedStatus == Status.closedByLiquidation) {\n            _requireMoreThanOneTroveInSystem(TroveIdsArrayLength);\n        }\n\n        _removeTroveId(_troveId, TroveIdsArrayLength);\n\n        Trove memory trove = Troves[_troveId];\n\n        // If trove belongs to a batch, remove from it\n        if (_batchAddress != address(0)) {\n            if (trove.status == Status.active) {\n                sortedTroves.removeFromBatch(_troveId);\n            } else if (trove.status == Status.zombie && lastZombieTroveId == _troveId) {\n                lastZombieTroveId = 0;\n            }\n\n            _removeTroveSharesFromBatch(\n                _troveId,\n                _troveChange.collDecrease,\n                _troveChange.debtDecrease,\n                _troveChange,\n                _batchAddress,\n                _newBatchColl,\n                _newBatchDebt\n            );\n        } else {\n            if (trove.status == Status.active) {\n                sortedTroves.remove(_troveId);\n            } else if (trove.status == Status.zombie && lastZombieTroveId == _troveId) {\n                lastZombieTroveId = 0;\n            }\n        }\n\n        uint256 newTotalStakes = totalStakes - trove.stake;\n        totalStakes = newTotalStakes;\n\n        // Zero Trove properties\n        delete Troves[_troveId];\n        Troves[_troveId].status = closedStatus;\n\n        // Zero Trove snapshots\n        delete rewardSnapshots[_troveId];\n\n        // burn ERC721\n        troveNFT.burn(_troveId);\n    }\n\n    function onAdjustTroveInsideBatch(\n        uint256 _troveId,\n        uint256 _newTroveColl, // entire, with redistribution and trove change\n        uint256 _newTroveDebt, // entire, with redistribution and trove change\n        TroveChange memory _troveChange,\n        address _batchAddress,\n        uint256 _newBatchColl, // without trove change\n        uint256 _newBatchDebt // entire (with interest, batch fee), but without trove change nor upfront fee nor redistribution\n    ) external {\n        _requireCallerIsBorrowerOperations();\n\n        // Trove\n        Troves[_troveId].coll = _newTroveColl;\n        _updateTroveRewardSnapshots(_troveId);\n        uint256 newStake = _updateStakeAndTotalStakes(_troveId, _newTroveColl);\n\n        // Batch\n        assert(_newTroveDebt > 0);\n        _updateBatchShares(_troveId, _batchAddress, _troveChange, _newTroveDebt, _newBatchColl, _newBatchDebt, true);\n\n        _movePendingTroveRewardsToActivePool(\n            defaultPool, _troveChange.appliedRedistBoldDebtGain, _troveChange.appliedRedistCollGain\n        );\n\n        emit BatchedTroveUpdated({\n            _troveId: _troveId,\n            _interestBatchManager: _batchAddress,\n            _batchDebtShares: Troves[_troveId].batchDebtShares,\n            _coll: _newTroveColl,\n            _stake: newStake,\n            _snapshotOfTotalCollRedist: L_coll,\n            _snapshotOfTotalDebtRedist: L_boldDebt\n        });\n\n        emit TroveOperation({\n            _troveId: _troveId,\n            _operation: Operation.adjustTrove,\n            _annualInterestRate: batches[_batchAddress].annualInterestRate,\n            _debtIncreaseFromRedist: _troveChange.appliedRedistBoldDebtGain,\n            _debtIncreaseFromUpfrontFee: _troveChange.upfrontFee,\n            _debtChangeFromOperation: int256(_troveChange.debtIncrease) - int256(_troveChange.debtDecrease),\n            _collIncreaseFromRedist: _troveChange.appliedRedistCollGain,\n            _collChangeFromOperation: int256(_troveChange.collIncrease) - int256(_troveChange.collDecrease)\n        });\n\n        emit BatchUpdated({\n            _interestBatchManager: _batchAddress,\n            _operation: BatchOperation.troveChange,\n            _debt: batches[_batchAddress].debt,\n            _coll: batches[_batchAddress].coll,\n            _annualInterestRate: batches[_batchAddress].annualInterestRate,\n            _annualManagementFee: batches[_batchAddress].annualManagementFee,\n            _totalDebtShares: batches[_batchAddress].totalDebtShares,\n            // Although the Trove being adjusted may pay an upfront fee,\n            // it is an individual fee, so we don't include it here\n            _debtIncreaseFromUpfrontFee: 0\n        });\n    }\n\n    function onApplyTroveInterest(\n        uint256 _troveId,\n        uint256 _newTroveColl,\n        uint256 _newTroveDebt,\n        address _batchAddress,\n        uint256 _newBatchColl,\n        uint256 _newBatchDebt,\n        TroveChange calldata _troveChange\n    ) external {\n        _requireCallerIsBorrowerOperations();\n\n        Troves[_troveId].coll = _newTroveColl;\n\n        if (_batchAddress != address(0)) {\n            assert(_newTroveDebt > 0);\n            _updateBatchShares(_troveId, _batchAddress, _troveChange, _newTroveDebt, _newBatchColl, _newBatchDebt, true);\n\n            emit BatchUpdated({\n                _interestBatchManager: _batchAddress,\n                _operation: BatchOperation.applyBatchInterestAndFee,\n                _debt: _newBatchDebt,\n                _coll: _newBatchColl,\n                _annualInterestRate: batches[_batchAddress].annualInterestRate,\n                _annualManagementFee: batches[_batchAddress].annualManagementFee,\n                _totalDebtShares: batches[_batchAddress].totalDebtShares,\n                _debtIncreaseFromUpfrontFee: 0\n            });\n        } else {\n            Troves[_troveId].debt = _newTroveDebt;\n            Troves[_troveId].lastDebtUpdateTime = uint64(block.timestamp);\n        }\n\n        _movePendingTroveRewardsToActivePool(\n            defaultPool, _troveChange.appliedRedistBoldDebtGain, _troveChange.appliedRedistCollGain\n        );\n\n        _updateTroveRewardSnapshots(_troveId);\n\n        emit TroveUpdated({\n            _troveId: _troveId,\n            _debt: _newTroveDebt,\n            _coll: _newTroveColl,\n            _stake: Troves[_troveId].stake,\n            _annualInterestRate: Troves[_troveId].annualInterestRate,\n            _snapshotOfTotalCollRedist: L_coll,\n            _snapshotOfTotalDebtRedist: L_boldDebt\n        });\n\n        emit TroveOperation({\n            _troveId: _troveId,\n            _operation: Operation.applyPendingDebt,\n            _annualInterestRate: Troves[_troveId].annualInterestRate,\n            _debtIncreaseFromRedist: _troveChange.appliedRedistBoldDebtGain,\n            _debtIncreaseFromUpfrontFee: _troveChange.upfrontFee,\n            _debtChangeFromOperation: int256(_troveChange.debtIncrease) - int256(_troveChange.debtDecrease),\n            _collIncreaseFromRedist: _troveChange.appliedRedistCollGain,\n            _collChangeFromOperation: int256(_troveChange.collIncrease) - int256(_troveChange.collDecrease)\n        });\n    }\n\n    function onRegisterBatchManager(address _account, uint256 _annualInterestRate, uint256 _annualManagementFee)\n        external\n    {\n        _requireCallerIsBorrowerOperations();\n\n        batches[_account].arrayIndex = uint64(batchIds.length);\n        batches[_account].annualInterestRate = _annualInterestRate;\n        batches[_account].annualManagementFee = _annualManagementFee;\n        batches[_account].lastInterestRateAdjTime = uint64(block.timestamp);\n\n        batchIds.push(_account);\n\n        emit BatchUpdated({\n            _interestBatchManager: _account,\n            _operation: BatchOperation.registerBatchManager,\n            _debt: 0,\n            _coll: 0,\n            _annualInterestRate: _annualInterestRate,\n            _annualManagementFee: _annualManagementFee,\n            _totalDebtShares: 0,\n            _debtIncreaseFromUpfrontFee: 0\n        });\n    }\n\n    function onLowerBatchManagerAnnualFee(\n        address _batchAddress,\n        uint256 _newColl,\n        uint256 _newDebt,\n        uint256 _newAnnualManagementFee\n    ) external {\n        _requireCallerIsBorrowerOperations();\n\n        batches[_batchAddress].coll = _newColl;\n        batches[_batchAddress].debt = _newDebt;\n        batches[_batchAddress].annualManagementFee = _newAnnualManagementFee;\n        batches[_batchAddress].lastDebtUpdateTime = uint64(block.timestamp);\n\n        emit BatchUpdated({\n            _interestBatchManager: _batchAddress,\n            _operation: BatchOperation.lowerBatchManagerAnnualFee,\n            _debt: _newDebt,\n            _coll: _newColl,\n            _annualInterestRate: batches[_batchAddress].annualInterestRate,\n            _annualManagementFee: _newAnnualManagementFee,\n            _totalDebtShares: batches[_batchAddress].totalDebtShares,\n            _debtIncreaseFromUpfrontFee: 0\n        });\n    }\n\n    function onSetBatchManagerAnnualInterestRate(\n        address _batchAddress,\n        uint256 _newColl,\n        uint256 _newDebt,\n        uint256 _newAnnualInterestRate,\n        uint256 _upfrontFee\n    ) external {\n        _requireCallerIsBorrowerOperations();\n\n        batches[_batchAddress].coll = _newColl;\n        batches[_batchAddress].debt = _newDebt;\n        batches[_batchAddress].annualInterestRate = _newAnnualInterestRate;\n        batches[_batchAddress].lastDebtUpdateTime = uint64(block.timestamp);\n        batches[_batchAddress].lastInterestRateAdjTime = uint64(block.timestamp);\n\n        emit BatchUpdated({\n            _interestBatchManager: _batchAddress,\n            _operation: BatchOperation.setBatchManagerAnnualInterestRate,\n            _debt: _newDebt,\n            _coll: _newColl,\n            _annualInterestRate: _newAnnualInterestRate,\n            _annualManagementFee: batches[_batchAddress].annualManagementFee,\n            _totalDebtShares: batches[_batchAddress].totalDebtShares,\n            _debtIncreaseFromUpfrontFee: _upfrontFee\n        });\n    }\n\n    function onSetInterestBatchManager(OnSetInterestBatchManagerParams calldata _params) external {\n        _requireCallerIsBorrowerOperations();\n        TroveChange memory _troveChange = _params.troveChange;\n\n        // assert(batchIds[batches[_params.newBatchAddress].arrayIndex] == _params.newBatchAddress);\n\n        _updateTroveRewardSnapshots(_params.troveId);\n\n        // Clean Trove state\n        Troves[_params.troveId].debt = 0;\n        Troves[_params.troveId].annualInterestRate = 0;\n        Troves[_params.troveId].lastDebtUpdateTime = 0;\n        Troves[_params.troveId].coll = _params.troveColl;\n\n        Troves[_params.troveId].interestBatchManager = _params.newBatchAddress;\n        Troves[_params.troveId].lastInterestRateAdjTime = uint64(block.timestamp);\n\n        _troveChange.collIncrease = _params.troveColl - _troveChange.appliedRedistCollGain;\n        _troveChange.debtIncrease = _params.troveDebt - _troveChange.appliedRedistBoldDebtGain - _troveChange.upfrontFee;\n        assert(_params.troveDebt > 0);\n        _updateBatchShares(\n            _params.troveId,\n            _params.newBatchAddress,\n            _troveChange,\n            _params.troveDebt,\n            _params.newBatchColl,\n            _params.newBatchDebt,\n            true\n        );\n\n        _movePendingTroveRewardsToActivePool(\n            defaultPool, _troveChange.appliedRedistBoldDebtGain, _troveChange.appliedRedistCollGain\n        );\n\n        emit BatchedTroveUpdated({\n            _troveId: _params.troveId,\n            _interestBatchManager: _params.newBatchAddress,\n            _batchDebtShares: Troves[_params.troveId].batchDebtShares,\n            _coll: _params.troveColl,\n            _stake: Troves[_params.troveId].stake,\n            _snapshotOfTotalCollRedist: L_coll,\n            _snapshotOfTotalDebtRedist: L_boldDebt\n        });\n\n        emit TroveOperation({\n            _troveId: _params.troveId,\n            _operation: Operation.setInterestBatchManager,\n            _annualInterestRate: batches[_params.newBatchAddress].annualInterestRate,\n            _debtIncreaseFromRedist: _troveChange.appliedRedistBoldDebtGain,\n            _debtIncreaseFromUpfrontFee: _troveChange.upfrontFee,\n            _debtChangeFromOperation: 0,\n            _collIncreaseFromRedist: _troveChange.appliedRedistCollGain,\n            _collChangeFromOperation: 0\n        });\n\n        emit BatchUpdated({\n            _interestBatchManager: _params.newBatchAddress,\n            _operation: BatchOperation.joinBatch,\n            _debt: batches[_params.newBatchAddress].debt,\n            _coll: batches[_params.newBatchAddress].coll,\n            _annualInterestRate: batches[_params.newBatchAddress].annualInterestRate,\n            _annualManagementFee: batches[_params.newBatchAddress].annualManagementFee,\n            _totalDebtShares: batches[_params.newBatchAddress].totalDebtShares,\n            // Although the Trove joining the batch may pay an upfront fee,\n            // it is an individual fee, so we don't include it here\n            _debtIncreaseFromUpfrontFee: 0\n        });\n    }\n\n    // This function will revert if there’s a total debt increase and the ratio debt / shares has exceeded the max\n    function _updateBatchShares(\n        uint256 _troveId,\n        address _batchAddress,\n        TroveChange memory _troveChange,\n        uint256 _newTroveDebt, // entire, with interest, batch fee and redistribution\n        uint256 _batchColl, // without trove change\n        uint256 _batchDebt, // entire (with interest, batch fee), but without trove change, nor upfront fee nor redist\n        bool _checkBatchSharesRatio // whether we do the check on the resulting ratio inside the func call\n    ) internal {\n        // Debt\n        uint256 currentBatchDebtShares = batches[_batchAddress].totalDebtShares;\n        uint256 batchDebtSharesDelta;\n        uint256 debtIncrease =\n            _troveChange.debtIncrease + _troveChange.upfrontFee + _troveChange.appliedRedistBoldDebtGain;\n        uint256 debtDecrease;\n        if (debtIncrease > _troveChange.debtDecrease) {\n            debtIncrease -= _troveChange.debtDecrease;\n        } else {\n            debtDecrease = _troveChange.debtDecrease - debtIncrease;\n            debtIncrease = 0;\n        }\n\n        if (debtIncrease == 0 && debtDecrease == 0) {\n            batches[_batchAddress].debt = _batchDebt;\n        } else {\n            if (debtIncrease > 0) {\n                // Add debt\n                if (_batchDebt == 0) {\n                    batchDebtSharesDelta = debtIncrease;\n                } else {\n                    // To avoid rebasing issues, let’s make sure the ratio debt / shares is not too high\n                    _requireBelowMaxSharesRatio(currentBatchDebtShares, _batchDebt, _checkBatchSharesRatio);\n\n                    batchDebtSharesDelta = currentBatchDebtShares * debtIncrease / _batchDebt;\n                }\n\n                Troves[_troveId].batchDebtShares += batchDebtSharesDelta;\n                batches[_batchAddress].debt = _batchDebt + debtIncrease;\n                batches[_batchAddress].totalDebtShares = currentBatchDebtShares + batchDebtSharesDelta;\n            } else if (debtDecrease > 0) {\n                // Subtract debt\n                // We make sure that if final trove debt is zero, shares are too (avoiding rounding issues)\n                // This can only happen from redemptions, as otherwise we would be using _removeTroveSharesFromBatch\n                // In redemptions we don’t do that because we don’t want to kick the trove out of the batch (it’d be bad UX)\n                if (_newTroveDebt == 0) {\n                    batches[_batchAddress].debt = _batchDebt - debtDecrease;\n                    batches[_batchAddress].totalDebtShares = currentBatchDebtShares - Troves[_troveId].batchDebtShares;\n                    Troves[_troveId].batchDebtShares = 0;\n                } else {\n                    batchDebtSharesDelta = currentBatchDebtShares * debtDecrease / _batchDebt;\n\n                    Troves[_troveId].batchDebtShares -= batchDebtSharesDelta;\n                    batches[_batchAddress].debt = _batchDebt - debtDecrease;\n                    batches[_batchAddress].totalDebtShares = currentBatchDebtShares - batchDebtSharesDelta;\n                }\n            }\n        }\n        // Update debt checkpoint\n        batches[_batchAddress].lastDebtUpdateTime = uint64(block.timestamp);\n\n        // Collateral\n        uint256 collIncrease = _troveChange.collIncrease + _troveChange.appliedRedistCollGain;\n        uint256 collDecrease;\n        if (collIncrease > _troveChange.collDecrease) {\n            collIncrease -= _troveChange.collDecrease;\n        } else {\n            collDecrease = _troveChange.collDecrease - collIncrease;\n            collIncrease = 0;\n        }\n\n        if (collIncrease == 0 && collDecrease == 0) {\n            batches[_batchAddress].coll = _batchColl;\n        } else {\n            if (collIncrease > 0) {\n                // Add coll\n                batches[_batchAddress].coll = _batchColl + collIncrease;\n            } else if (collDecrease > 0) {\n                // Subtract coll\n                batches[_batchAddress].coll = _batchColl - collDecrease;\n            }\n        }\n    }\n\n    // For the debt / shares ratio to increase by a factor 1e9\n    // at a average annual debt increase (compounded interest + fees) of 10%, it would take more than 217 years (log(1e9)/log(1.1))\n    // at a average annual debt increase (compounded interest + fees) of 50%, it would take more than 51 years (log(1e9)/log(1.5))\n    // When that happens, no more debt can be manually added to the batch, so batch should be migrated to a new one\n    function _requireBelowMaxSharesRatio(\n        uint256 _currentBatchDebtShares,\n        uint256 _batchDebt,\n        bool _checkBatchSharesRatio\n    ) internal view {\n        // debt / shares should be below MAX_BATCH_SHARES_RATIO\n        if (_currentBatchDebtShares * MAX_BATCH_SHARES_RATIO < _batchDebt && _checkBatchSharesRatio) {\n            revert BatchSharesRatioTooHigh();\n        }\n    }\n\n    function onRemoveFromBatch(\n        uint256 _troveId,\n        uint256 _newTroveColl, // entire, with redistribution\n        uint256 _newTroveDebt, // entire, with interest, batch fee and redistribution\n        TroveChange memory _troveChange,\n        address _batchAddress,\n        uint256 _newBatchColl,\n        uint256 _newBatchDebt, // entire, with interest and batch fee\n        uint256 _newAnnualInterestRate\n    ) external {\n        _requireCallerIsBorrowerOperations();\n        // assert(batchIds[batches[_batchAddress].arrayIndex] == _batchAddress);\n\n        // Subtract from batch\n        _removeTroveSharesFromBatch(\n            _troveId, _newTroveColl, _newTroveDebt, _troveChange, _batchAddress, _newBatchColl, _newBatchDebt\n        );\n\n        // Restore Trove state\n        Troves[_troveId].debt = _newTroveDebt;\n        Troves[_troveId].coll = _newTroveColl;\n        Troves[_troveId].lastDebtUpdateTime = uint64(block.timestamp);\n        Troves[_troveId].annualInterestRate = _newAnnualInterestRate;\n        Troves[_troveId].lastInterestRateAdjTime = uint64(block.timestamp);\n\n        _updateTroveRewardSnapshots(_troveId);\n        _movePendingTroveRewardsToActivePool(\n            defaultPool, _troveChange.appliedRedistBoldDebtGain, _troveChange.appliedRedistCollGain\n        );\n\n        emit TroveUpdated({\n            _troveId: _troveId,\n            _debt: _newTroveDebt,\n            _coll: _newTroveColl,\n            _stake: Troves[_troveId].stake,\n            _annualInterestRate: _newAnnualInterestRate,\n            _snapshotOfTotalCollRedist: L_coll,\n            _snapshotOfTotalDebtRedist: L_boldDebt\n        });\n\n        emit TroveOperation({\n            _troveId: _troveId,\n            _operation: Operation.removeFromBatch,\n            _annualInterestRate: _newAnnualInterestRate,\n            _debtIncreaseFromRedist: _troveChange.appliedRedistBoldDebtGain,\n            _debtIncreaseFromUpfrontFee: _troveChange.upfrontFee,\n            _debtChangeFromOperation: 0,\n            _collIncreaseFromRedist: _troveChange.appliedRedistCollGain,\n            _collChangeFromOperation: 0\n        });\n\n        emit BatchUpdated({\n            _interestBatchManager: _batchAddress,\n            _operation: BatchOperation.exitBatch,\n            _debt: batches[_batchAddress].debt,\n            _coll: batches[_batchAddress].coll,\n            _annualInterestRate: batches[_batchAddress].annualInterestRate,\n            _annualManagementFee: batches[_batchAddress].annualManagementFee,\n            _totalDebtShares: batches[_batchAddress].totalDebtShares,\n            // Although the Trove leaving the batch may pay an upfront fee,\n            // it is an individual fee, so we don't include it here\n            _debtIncreaseFromUpfrontFee: 0\n        });\n    }\n\n    function _removeTroveSharesFromBatch(\n        uint256 _troveId,\n        uint256 _newTroveColl, // entire, with redistribution\n        uint256 _newTroveDebt, // entire, with interest, batch fee and redistribution\n        TroveChange memory _troveChange,\n        address _batchAddress,\n        uint256 _newBatchColl, // without trove change\n        uint256 _newBatchDebt // entire (with interest and batch fee), but without trove change\n    ) internal {\n        // As we are removing:\n        // assert(_newBatchDebt > 0 || _newBatchColl > 0);\n\n        Trove memory trove = Troves[_troveId];\n\n        // We don’t need to increase the shares corresponding to redistribution first, because they would be subtracted immediately after\n        // We don’t need to account for interest nor batch fee because it’s proportional to debt shares\n        uint256 batchDebtDecrease = _newTroveDebt - _troveChange.upfrontFee - _troveChange.appliedRedistBoldDebtGain;\n        uint256 batchCollDecrease = _newTroveColl - _troveChange.appliedRedistCollGain;\n\n        batches[_batchAddress].totalDebtShares -= trove.batchDebtShares;\n        batches[_batchAddress].debt = _newBatchDebt - batchDebtDecrease;\n        batches[_batchAddress].coll = _newBatchColl - batchCollDecrease;\n        batches[_batchAddress].lastDebtUpdateTime = uint64(block.timestamp);\n\n        Troves[_troveId].interestBatchManager = address(0);\n        Troves[_troveId].batchDebtShares = 0;\n    }\n}\n","creation_status":"success","file_path":"lib/bold/contracts/src/TroveManager.sol"}