exportfunctioncalculateBlockColdAccessReimbursement(baseFeePerGas:string,accessDetailsMap:AddressAccessDetails[]):Map<string,Reimbursement>{constreimbursements=newMap<string,Reimbursement>()for(constaccessDetailofaccessDetailsMap){calculateItemColdAccessReimbursement(accessDetail.accessors,baseFeePerGas,COLD_ACCOUNT_ACCESS_COST,reimbursements)for(constslotofaccessDetail.slots){calculateItemColdAccessReimbursement(slot.accessors,baseFeePerGas,COLD_SLOAD_COST,reimbursements)}}returnreimbursements}functioncalculateItemColdAccessReimbursement(unsortedAccessors:AccessDetails[],baseFeePerGas:string,accessGasCost:string,reimbursements:Map<string,Reimbursement>):void{constsortedAccessDetails=unsortedAccessors.sort((a,b)=>{returnparseInt(b.priorityFeePerGas)-parseInt(a.priorityFeePerGas)})constaddressAccessN=sortedAccessDetails.lengthconstreimbursementPercent=(addressAccessN-1)/addressAccessNconstreimbursementsFromCoinbase=calculatePriorityFeeReimbursements(sortedAccessDetails,accessGasCost)for(leti=0;i<sortedAccessDetails.length;i++){constaccessor=sortedAccessDetails[i]constreimbursement=reimbursements.get(accessor.sender)??{reimbursementFromBurn:0n,reimbursementFromCoinbase:0n}constadjustedAccessGasCost=Math.max(MIN_ACCESS_LIST_ENTRY_COST,parseInt(accessGasCost)*reimbursementPercent)reimbursement.reimbursementFromBurn+=BigInt(adjustedAccessGasCost*parseInt(baseFeePerGas))reimbursement.reimbursementFromCoinbase+=BigInt(reimbursementsFromCoinbase[i])reimbursements.set(accessor.sender,reimbursement)}}exportfunctioncalculatePriorityFeeReimbursements(sortedAccesses:AccessDetails[],accessGasCost:string){// Validator charge is based on the highest paid priority fee per gas// 验证者费用基于每次 gas 支付的最高优先级费用constvalidatorFee=parseInt(sortedAccesses[0].priorityFeePerGas)*parseInt(accessGasCost)// Accumulate the sum of all "contributions", at least the top transaction contribution// 累积所有“贡献”的总和,至少是顶级交易贡献lettotalContributions=validatorFee// Accumulate cost of gas paid to validator for accessing the same address/slot/chunk// 累积支付给验证者以访问相同地址/插槽/块的 gas 成本lettotalSendersCharged=parseInt(sortedAccesses[0].priorityFeePerGas)*parseInt(accessGasCost)// Starting with `1` as element at `0` is explicitly shown here to be used as `validatorFee`// 从“1”开始,元素“0”在此处明确显示为用作“validatorFee”for(leti=1;i<sortedAccesses.length;i++){constcharge=parseInt(sortedAccesses[i].priorityFeePerGas)*parseInt(accessGasCost)totalContributions+=chargetotalSendersCharged+=charge}// Calculate the total amount of ether to be reimbursed for this access// 计算为此访问报销的 ether 总量consttotalReimbursement=totalSendersCharged-validatorFeeif(totalReimbursement==0){// possible if only single transaction or if all priority fees are 0// 如果只有单个交易或所有优先级费用都为 0,则可能returnArray(sortedAccesses.length).fill(0)}// Calculate actual charges and reimbursements// 计算实际费用和报销constreimbursements=[Math.floor(totalReimbursement*topTransactionContribution/totalContributions)]for(leti=1;i<sortedAccesses.length;i++){constcharge=parseInt(sortedAccesses[i].priorityFeePerGas)*parseInt(accessGasCost)constcalldataCharge=parseInt(sortedAccesses[i].priorityFeePerGas)*MIN_ACCESS_LIST_ENTRY_COSTconstreimbursementToCalldata=charge-calldataChargeconstreimbursementToContribution=Math.floor(totalReimbursement*charge/totalContributions)reimbursements.push(Math.min(reimbursementToCalldata,reimbursementToContribution))}returnreimbursements}