From 286c30d38b77a74283636b146e27664f312a3abc Mon Sep 17 00:00:00 2001 From: Yang Chun Ung Date: Tue, 31 Dec 2024 14:35:55 +0900 Subject: [PATCH] Extract GetFeeAddress --- Lib9c/Action/AuraSummon.cs | 10 +------ Lib9c/Action/BattleArena.cs | 8 +---- Lib9c/Action/Buy.cs | 11 ++----- Lib9c/Action/BuyProduct.cs | 21 ++----------- Lib9c/Action/CombinationEquipment.cs | 11 +------ Lib9c/Action/CostumeSummon.cs | 10 +------ .../CustomEquipmentCraft.cs | 10 +------ Lib9c/Action/ItemEnhancement.cs | 10 +------ Lib9c/Action/ItemEnhancement11.cs | 10 +------ Lib9c/Action/ItemEnhancement12.cs | 10 +------ Lib9c/Action/ItemEnhancement13.cs | 10 +------ Lib9c/Action/JoinArena.cs | 10 ++----- Lib9c/Action/JoinArena1.cs | 8 +---- Lib9c/Action/JoinArena3.cs | 8 +---- Lib9c/Action/PetEnhancement.cs | 10 +------ Lib9c/Action/Raid.cs | 10 +------ Lib9c/Action/RuneEnhancement.cs | 10 +------ Lib9c/Action/RuneSummon.cs | 10 +------ Lib9c/Action/UnlockCombinationSlot.cs | 20 +------------ Lib9c/Action/UnlockRuneSlot.cs | 10 +------ Lib9c/Extensions/WorldExtensions.cs | 30 +++++++++++++++++++ 21 files changed, 54 insertions(+), 193 deletions(-) diff --git a/Lib9c/Action/AuraSummon.cs b/Lib9c/Action/AuraSummon.cs index fb0aa96087..c6ad74202a 100644 --- a/Lib9c/Action/AuraSummon.cs +++ b/Lib9c/Action/AuraSummon.cs @@ -210,15 +210,7 @@ public override IWorld Execute(IActionContext context) // Transfer Cost NCG first for fast-fail if (summonRow.CostNcg > 0L) { - var feeAddress = Addresses.RewardPool; - // TODO: [GuildMigration] Remove this after migration - if (states.GetDelegationMigrationHeight() is long migrationHeight - && context.BlockIndex < migrationHeight) - { - var arenaSheet = states.GetSheet(); - var arenaData = arenaSheet.GetRoundByBlockIndex(context.BlockIndex); - feeAddress = ArenaHelper.DeriveArenaAddress(arenaData.ChampionshipId, arenaData.Round); - } + var feeAddress = states.GetFeeAddress(context.BlockIndex); states = states.TransferAsset( context, diff --git a/Lib9c/Action/BattleArena.cs b/Lib9c/Action/BattleArena.cs index c413843398..64cf2f9aa5 100644 --- a/Lib9c/Action/BattleArena.cs +++ b/Lib9c/Action/BattleArena.cs @@ -331,13 +331,7 @@ public override IWorld Execute(IActionContext context) purchasedCountDuringInterval++; - var feeAddress = Addresses.RewardPool; - // TODO: [GuildMigration] Remove this after migration - if (states.GetDelegationMigrationHeight() is long migrationHeight - && context.BlockIndex < migrationHeight) - { - feeAddress = ArenaHelper.DeriveArenaAddress(roundData.ChampionshipId, roundData.Round); - } + var feeAddress = states.GetFeeAddress(context.BlockIndex); states = states .TransferAsset(context, context.Signer, feeAddress, ticketBalance) diff --git a/Lib9c/Action/Buy.cs b/Lib9c/Action/Buy.cs index a202e16be0..1fc47fadf0 100644 --- a/Lib9c/Action/Buy.cs +++ b/Lib9c/Action/Buy.cs @@ -12,6 +12,7 @@ using Libplanet.Types.Assets; using Nekoyume.Action.Guild.Migration.LegacyModels; using Nekoyume.Arena; +using Nekoyume.Extensions; using Nekoyume.Model.EnumType; using Nekoyume.Model.Mail; using Nekoyume.Model.State; @@ -251,15 +252,7 @@ public override IWorld Execute(IActionContext context) var taxedPrice = order.Price - tax; // Transfer tax. - var feeAddress = Addresses.RewardPool; - // TODO: [GuildMigration] Remove this after migration - if (states.GetDelegationMigrationHeight() is long migrationHeight - && context.BlockIndex < migrationHeight) - { - var arenaSheet = states.GetSheet(); - var arenaData = arenaSheet.GetRoundByBlockIndex(context.BlockIndex); - feeAddress = ArenaHelper.DeriveArenaAddress(arenaData.ChampionshipId, arenaData.Round); - } + var feeAddress = states.GetFeeAddress(context.BlockIndex); states = states .TransferAsset(context, context.Signer, feeAddress, tax); diff --git a/Lib9c/Action/BuyProduct.cs b/Lib9c/Action/BuyProduct.cs index 3ffe6d8fe3..285f837f79 100644 --- a/Lib9c/Action/BuyProduct.cs +++ b/Lib9c/Action/BuyProduct.cs @@ -12,6 +12,7 @@ using Nekoyume.Action.Guild.Migration.LegacyModels; using Nekoyume.Arena; using Nekoyume.Battle; +using Nekoyume.Extensions; using Nekoyume.Model.EnumType; using Nekoyume.Model.Item; using Nekoyume.Model.Mail; @@ -176,15 +177,7 @@ private IWorld Buy(IActionContext context, IProductInfo productInfo, Address sel var receipt = new ProductReceipt(productId, sellerAvatarAddress, buyerAvatarState.address, product.Price, context.BlockIndex); - var feeAddress = Addresses.RewardPool; - // TODO: [GuildMigration] Remove this after migration - if (states.GetDelegationMigrationHeight() is long migrationHeight - && context.BlockIndex < migrationHeight) - { - var arenaSheet = states.GetSheet(); - var arenaData = arenaSheet.GetRoundByBlockIndex(context.BlockIndex); - feeAddress = ArenaHelper.DeriveArenaAddress(arenaData.ChampionshipId, arenaData.Round); - } + var feeAddress = states.GetFeeAddress(context.BlockIndex); states = states .RemoveLegacyState(productAddress) @@ -308,15 +301,7 @@ private static IWorld Buy_Order(PurchaseInfo purchaseInfo, IActionContext contex var taxedPrice = order.Price - tax; // Transfer tax. - var feeAddress = Addresses.RewardPool; - // TODO: [GuildMigration] Remove this after migration - if (states.GetDelegationMigrationHeight() is long migrationHeight - && context.BlockIndex < migrationHeight) - { - var arenaSheet = states.GetSheet(); - var arenaData = arenaSheet.GetRoundByBlockIndex(context.BlockIndex); - feeAddress = ArenaHelper.DeriveArenaAddress(arenaData.ChampionshipId, arenaData.Round); - } + var feeAddress = states.GetFeeAddress(context.BlockIndex); states = states.TransferAsset( context, diff --git a/Lib9c/Action/CombinationEquipment.cs b/Lib9c/Action/CombinationEquipment.cs index 405610e32a..f30ed9605e 100644 --- a/Lib9c/Action/CombinationEquipment.cs +++ b/Lib9c/Action/CombinationEquipment.cs @@ -376,16 +376,7 @@ public override IWorld Execute(IActionContext context) if (costNcg > 0L) { // Transfer tax. - var feeAddress = Addresses.RewardPool; - // TODO: [GuildMigration] Remove this after migration - if (states.GetDelegationMigrationHeight() is long migrationHeight - && context.BlockIndex < migrationHeight) - { - var arenaSheet = states.GetSheet(); - var arenaData = arenaSheet.GetRoundByBlockIndex(context.BlockIndex); - feeAddress = ArenaHelper.DeriveArenaAddress(arenaData.ChampionshipId, arenaData.Round); - } - + var feeAddress = states.GetFeeAddress(context.BlockIndex); states = states.TransferAsset( context, context.Signer, diff --git a/Lib9c/Action/CostumeSummon.cs b/Lib9c/Action/CostumeSummon.cs index 196524b52c..8c4c5ae746 100644 --- a/Lib9c/Action/CostumeSummon.cs +++ b/Lib9c/Action/CostumeSummon.cs @@ -162,15 +162,7 @@ public override IWorld Execute(IActionContext context) // Transfer Cost NCG first for fast-fail if (summonRow.CostNcg > 0L) { - var feeAddress = Addresses.RewardPool; - // TODO: [GuildMigration] Remove this after migration - if (states.GetDelegationMigrationHeight() is long migrationHeight - && context.BlockIndex < migrationHeight) - { - var arenaSheet = states.GetSheet(); - var arenaData = arenaSheet.GetRoundByBlockIndex(context.BlockIndex); - feeAddress = ArenaHelper.DeriveArenaAddress(arenaData.ChampionshipId, arenaData.Round); - } + var feeAddress = states.GetFeeAddress(context.BlockIndex); states = states.TransferAsset( context, diff --git a/Lib9c/Action/CustomEquipmentCraft/CustomEquipmentCraft.cs b/Lib9c/Action/CustomEquipmentCraft/CustomEquipmentCraft.cs index 5fddeca3ef..6aaa1c81bf 100644 --- a/Lib9c/Action/CustomEquipmentCraft/CustomEquipmentCraft.cs +++ b/Lib9c/Action/CustomEquipmentCraft/CustomEquipmentCraft.cs @@ -193,15 +193,7 @@ public override IWorld Execute(IActionContext context) if (ncgCost > 0) { - var feeAddress = Addresses.RewardPool; - // TODO: [GuildMigration] Remove this after migration - if (states.GetDelegationMigrationHeight() is long migrationHeight - && context.BlockIndex < migrationHeight) - { - var arenaSheet = states.GetSheet(); - var arenaData = arenaSheet.GetRoundByBlockIndex(context.BlockIndex); - feeAddress = ArenaHelper.DeriveArenaAddress(arenaData.ChampionshipId, arenaData.Round); - } + var feeAddress = states.GetFeeAddress(context.BlockIndex); states = states.TransferAsset(context, context.Signer, feeAddress, ncgCost * states.GetGoldCurrency()); } diff --git a/Lib9c/Action/ItemEnhancement.cs b/Lib9c/Action/ItemEnhancement.cs index 773c4b3783..3d8a257d35 100644 --- a/Lib9c/Action/ItemEnhancement.cs +++ b/Lib9c/Action/ItemEnhancement.cs @@ -373,15 +373,7 @@ public override IWorld Execute(IActionContext context) var requiredNcg = targetCostRow.Cost - startCostRow.Cost; if (requiredNcg > 0) { - var feeAddress = Addresses.RewardPool; - // TODO: [GuildMigration] Remove this after migration - if (states.GetDelegationMigrationHeight() is long migrationHeight - && context.BlockIndex < migrationHeight) - { - var arenaSheet = states.GetSheet(); - var arenaData = arenaSheet.GetRoundByBlockIndex(context.BlockIndex); - feeAddress = ArenaHelper.DeriveArenaAddress(arenaData.ChampionshipId, arenaData.Round); - } + var feeAddress = states.GetFeeAddress(context.BlockIndex); states = states.TransferAsset(ctx, ctx.Signer, feeAddress, states.GetGoldCurrency() * requiredNcg); diff --git a/Lib9c/Action/ItemEnhancement11.cs b/Lib9c/Action/ItemEnhancement11.cs index 23fd47b565..b1c1941965 100644 --- a/Lib9c/Action/ItemEnhancement11.cs +++ b/Lib9c/Action/ItemEnhancement11.cs @@ -291,15 +291,7 @@ public override IWorld Execute(IActionContext context) var requiredNcg = row.Cost; if (requiredNcg > 0) { - var feeAddress = Addresses.RewardPool; - // TODO: [GuildMigration] Remove this after migration - if (states.GetDelegationMigrationHeight() is long migrationHeight - && context.BlockIndex < migrationHeight) - { - var arenaSheet = states.GetSheet(); - var arenaData = arenaSheet.GetRoundByBlockIndex(context.BlockIndex); - feeAddress = ArenaHelper.DeriveArenaAddress(arenaData.ChampionshipId, arenaData.Round); - } + var feeAddress = states.GetFeeAddress(context.BlockIndex); states = states.TransferAsset(ctx, ctx.Signer, feeAddress, states.GetGoldCurrency() * requiredNcg); } diff --git a/Lib9c/Action/ItemEnhancement12.cs b/Lib9c/Action/ItemEnhancement12.cs index 10fc68c4e2..596a1a9060 100644 --- a/Lib9c/Action/ItemEnhancement12.cs +++ b/Lib9c/Action/ItemEnhancement12.cs @@ -363,15 +363,7 @@ public override IWorld Execute(IActionContext context) var requiredNcg = targetCostRow.Cost - startCostRow.Cost; if (requiredNcg > 0) { - var feeAddress = Addresses.RewardPool; - // TODO: [GuildMigration] Remove this after migration - if (states.GetDelegationMigrationHeight() is long migrationHeight - && context.BlockIndex < migrationHeight) - { - var arenaSheet = states.GetSheet(); - var arenaData = arenaSheet.GetRoundByBlockIndex(context.BlockIndex); - feeAddress = ArenaHelper.DeriveArenaAddress(arenaData.ChampionshipId, arenaData.Round); - } + var feeAddress = states.GetFeeAddress(context.BlockIndex); states = states.TransferAsset(ctx, ctx.Signer, feeAddress, states.GetGoldCurrency() * requiredNcg); diff --git a/Lib9c/Action/ItemEnhancement13.cs b/Lib9c/Action/ItemEnhancement13.cs index 2f866d1578..5225351068 100644 --- a/Lib9c/Action/ItemEnhancement13.cs +++ b/Lib9c/Action/ItemEnhancement13.cs @@ -366,15 +366,7 @@ public override IWorld Execute(IActionContext context) var requiredNcg = targetCostRow.Cost - startCostRow.Cost; if (requiredNcg > 0) { - var feeAddress = Addresses.RewardPool; - // TODO: [GuildMigration] Remove this after migration - if (states.GetDelegationMigrationHeight() is long migrationHeight - && context.BlockIndex < migrationHeight) - { - var arenaSheet = states.GetSheet(); - var arenaData = arenaSheet.GetRoundByBlockIndex(context.BlockIndex); - feeAddress = ArenaHelper.DeriveArenaAddress(arenaData.ChampionshipId, arenaData.Round); - } + var feeAddress = states.GetFeeAddress(context.BlockIndex); states = states.TransferAsset(ctx, ctx.Signer, feeAddress, states.GetGoldCurrency() * requiredNcg); diff --git a/Lib9c/Action/JoinArena.cs b/Lib9c/Action/JoinArena.cs index 0de20477d8..aff907f656 100644 --- a/Lib9c/Action/JoinArena.cs +++ b/Lib9c/Action/JoinArena.cs @@ -92,7 +92,7 @@ public override IWorld Execute(IActionContext context) $"[{nameof(JoinArena)}] Aborted as the avatar state of the signer was failed to load."); } - // check the avatar already joined the arena. + // check the avatar already joined the arena. if (states.GetArenaParticipant(championshipId, round, avatarAddress) is not null) { throw new AlreadyJoinedArenaException(championshipId, round, avatarAddress); @@ -174,13 +174,7 @@ public override IWorld Execute(IActionContext context) $"required {fee}, but balance is {crystalBalance}"); } - var feeAddress = Addresses.RewardPool; - // TODO: [GuildMigration] Remove this after migration - if (states.GetDelegationMigrationHeight() is long migrationHeight - && context.BlockIndex < migrationHeight) - { - feeAddress = ArenaHelper.DeriveArenaAddress(roundData.ChampionshipId, roundData.Round); - } + var feeAddress = states.GetFeeAddress(context.BlockIndex); states = states.TransferAsset(context, context.Signer, feeAddress, fee); } diff --git a/Lib9c/Action/JoinArena1.cs b/Lib9c/Action/JoinArena1.cs index 5ac087ace0..d391483034 100644 --- a/Lib9c/Action/JoinArena1.cs +++ b/Lib9c/Action/JoinArena1.cs @@ -146,13 +146,7 @@ public override IWorld Execute(IActionContext context) $"required {fee}, but balance is {crystalBalance}"); } - var feeAddress = Addresses.RewardPool; - // TODO: [GuildMigration] Remove this after migration - if (states.GetDelegationMigrationHeight() is long migrationHeight - && context.BlockIndex < migrationHeight) - { - feeAddress = ArenaHelper.DeriveArenaAddress(roundData.ChampionshipId, roundData.Round); - } +var feeAddress = states.GetFeeAddress(context.BlockIndex); states = states.TransferAsset(context, context.Signer, feeAddress, fee); } diff --git a/Lib9c/Action/JoinArena3.cs b/Lib9c/Action/JoinArena3.cs index 7573de49e7..c6873118b1 100644 --- a/Lib9c/Action/JoinArena3.cs +++ b/Lib9c/Action/JoinArena3.cs @@ -163,13 +163,7 @@ public override IWorld Execute(IActionContext context) $"required {fee}, but balance is {crystalBalance}"); } - var feeAddress = Addresses.RewardPool; - // TODO: [GuildMigration] Remove this after migration - if (states.GetDelegationMigrationHeight() is long migrationHeight - && context.BlockIndex < migrationHeight) - { - feeAddress = ArenaHelper.DeriveArenaAddress(roundData.ChampionshipId, roundData.Round); - } +var feeAddress = states.GetFeeAddress(context.BlockIndex); states = states.TransferAsset(context, context.Signer, feeAddress, fee); } diff --git a/Lib9c/Action/PetEnhancement.cs b/Lib9c/Action/PetEnhancement.cs index 31194dec54..a49eac06dc 100644 --- a/Lib9c/Action/PetEnhancement.cs +++ b/Lib9c/Action/PetEnhancement.cs @@ -139,15 +139,7 @@ public override IWorld Execute(IActionContext context) currentNcg); } - var feeAddress = Addresses.RewardPool; - // TODO: [GuildMigration] Remove this after migration - if (states.GetDelegationMigrationHeight() is long migrationHeight - && context.BlockIndex < migrationHeight) - { - var arenaSheet = states.GetSheet(); - var arenaData = arenaSheet.GetRoundByBlockIndex(context.BlockIndex); - feeAddress = ArenaHelper.DeriveArenaAddress(arenaData.ChampionshipId, arenaData.Round); - } + var feeAddress = states.GetFeeAddress(context.BlockIndex); states = states.TransferAsset(context, context.Signer, feeAddress, ncgCost); } diff --git a/Lib9c/Action/Raid.cs b/Lib9c/Action/Raid.cs index 3e6a335749..1cef0b108d 100644 --- a/Lib9c/Action/Raid.cs +++ b/Lib9c/Action/Raid.cs @@ -151,15 +151,7 @@ public override IWorld Execute(IActionContext context) } var goldCurrency = states.GetGoldCurrency(); - var feeAddress = Addresses.RewardPool; - // TODO: [GuildMigration] Remove this after migration - if (states.GetDelegationMigrationHeight() is long migrationHeight - && context.BlockIndex < migrationHeight) - { - var arenaSheet = states.GetSheet(); - var arenaData = arenaSheet.GetRoundByBlockIndex(context.BlockIndex); - feeAddress = ArenaHelper.DeriveArenaAddress(arenaData.ChampionshipId, arenaData.Round); - } + var feeAddress = states.GetFeeAddress(context.BlockIndex); states = states.TransferAsset(context, context.Signer, feeAddress, WorldBossHelper.CalculateTicketPrice(row, raiderState, goldCurrency)); diff --git a/Lib9c/Action/RuneEnhancement.cs b/Lib9c/Action/RuneEnhancement.cs index d01babfd8d..83334e688a 100644 --- a/Lib9c/Action/RuneEnhancement.cs +++ b/Lib9c/Action/RuneEnhancement.cs @@ -153,15 +153,7 @@ public override IWorld Execute(IActionContext context) runeState.LevelUp(levelUpResult.LevelUpCount); states = states.SetRuneState(AvatarAddress, allRuneState); - var feeAddress = Addresses.RewardPool; - // TODO: [GuildMigration] Remove this after migration - if (states.GetDelegationMigrationHeight() is long migrationHeight - && context.BlockIndex < migrationHeight) - { - var arenaSheet = states.GetSheet(); - var arenaData = arenaSheet.GetRoundByBlockIndex(context.BlockIndex); - feeAddress = ArenaHelper.DeriveArenaAddress(arenaData.ChampionshipId, arenaData.Round); - } + var feeAddress = states.GetFeeAddress(context.BlockIndex); // Burn costs if (levelUpResult.NcgCost > 0) diff --git a/Lib9c/Action/RuneSummon.cs b/Lib9c/Action/RuneSummon.cs index 61b40cb22c..c5faa3ce5e 100644 --- a/Lib9c/Action/RuneSummon.cs +++ b/Lib9c/Action/RuneSummon.cs @@ -91,15 +91,7 @@ public override IWorld Execute(IActionContext context) // Transfer Cost NCG first for fast-fail if (summonRow.CostNcg > 0L) { - var feeAddress = Addresses.RewardPool; - // TODO: [GuildMigration] Remove this after migration - if (states.GetDelegationMigrationHeight() is long migrationHeight - && context.BlockIndex < migrationHeight) - { - var arenaSheet = states.GetSheet(); - var arenaData = arenaSheet.GetRoundByBlockIndex(context.BlockIndex); - feeAddress = ArenaHelper.DeriveArenaAddress(arenaData.ChampionshipId, arenaData.Round); - } + var feeAddress = states.GetFeeAddress(context.BlockIndex); states = states.TransferAsset( context, diff --git a/Lib9c/Action/UnlockCombinationSlot.cs b/Lib9c/Action/UnlockCombinationSlot.cs index 8e4877d194..91922824bb 100644 --- a/Lib9c/Action/UnlockCombinationSlot.cs +++ b/Lib9c/Action/UnlockCombinationSlot.cs @@ -75,7 +75,7 @@ public override IWorld Execute(IActionContext context) throw new SlotAlreadyUnlockedException($"[{nameof(UnlockRuneSlot)}] Index : {SlotIndex}"); } - var feeStoreAddress = GetFeeStoreAddress(states, context.BlockIndex); + var feeStoreAddress = states.GetFeeAddress(context.BlockIndex); var costSheet = sheets.GetSheet(); if (!costSheet.ContainsKey(SlotIndex)) @@ -175,23 +175,5 @@ public override IWorld Execute(IActionContext context) allSlotState.UnlockSlot(AvatarAddress, SlotIndex); return states.SetCombinationSlotState(AvatarAddress, allSlotState); } - - private Address GetFeeStoreAddress(IWorld states, long blockIndex) - { - if (states.GetDelegationMigrationHeight() is long migrationHeight - && blockIndex < migrationHeight) - { - var sheets = states.GetSheets( - sheetTypes: new[] - { - typeof(ArenaSheet), - }); - - var arenaSheet = sheets.GetSheet(); - var arenaData = arenaSheet.GetRoundByBlockIndex(blockIndex); - return ArenaHelper.DeriveArenaAddress(arenaData.ChampionshipId, arenaData.Round); - } - return Addresses.RewardPool; - } } } diff --git a/Lib9c/Action/UnlockRuneSlot.cs b/Lib9c/Action/UnlockRuneSlot.cs index a3b127cc11..263a8b291a 100644 --- a/Lib9c/Action/UnlockRuneSlot.cs +++ b/Lib9c/Action/UnlockRuneSlot.cs @@ -104,15 +104,7 @@ public override IWorld Execute(IActionContext context) arenaSlotState.Unlock(SlotIndex); raidSlotState.Unlock(SlotIndex); - var feeAddress = Addresses.RewardPool; - // TODO: [GuildMigration] Remove this after migration - if (states.GetDelegationMigrationHeight() is long migrationHeight - && context.BlockIndex < migrationHeight) - { - var arenaSheet = states.GetSheet(); - var arenaData = arenaSheet.GetRoundByBlockIndex(context.BlockIndex); - feeAddress = ArenaHelper.DeriveArenaAddress(arenaData.ChampionshipId, arenaData.Round); - } + var feeAddress = states.GetFeeAddress(context.BlockIndex); return states .TransferAsset(context, context.Signer, feeAddress, cost * currency) diff --git a/Lib9c/Extensions/WorldExtensions.cs b/Lib9c/Extensions/WorldExtensions.cs index 90d2c7b950..882460ce04 100644 --- a/Lib9c/Extensions/WorldExtensions.cs +++ b/Lib9c/Extensions/WorldExtensions.cs @@ -1,6 +1,10 @@ using System; using Libplanet.Action.State; using Libplanet.Crypto; +using Nekoyume.Action.Guild.Migration.LegacyModels; +using Nekoyume.Arena; +using Nekoyume.Module; +using Nekoyume.TableData; namespace Nekoyume.Extensions { @@ -13,5 +17,31 @@ public static IWorld MutateAccount(this IWorld world, Address accountAddress, account = mutateFn(account); return world.SetAccount(accountAddress, account); } + + /// + /// Retrieves the fee address based on the block index and migration height. + /// + /// The current world instance. + /// The block index for which the fee address is required. + /// The fee address, which may vary based on migration height and arena data. + public static Address GetFeeAddress(this IWorld world, long blockIndex) + { + // Default fee address is set to the RewardPool address. + var feeAddress = Addresses.RewardPool; + + // Check if the block index is before the migration height to determine if an arena-specific address should be used. + if (world.GetDelegationMigrationHeight() is long migrationHeight + && blockIndex < migrationHeight) + { + // Fetch arena data from the ArenaSheet to derive the fee address. + var arenaSheet = world.GetSheet(); + var arenaData = arenaSheet.GetRoundByBlockIndex(blockIndex); + + // Derive the fee address based on the championship ID and round. + feeAddress = ArenaHelper.DeriveArenaAddress(arenaData.ChampionshipId, arenaData.Round); + } + + return feeAddress; + } } }