From 55217fa2d1f2d9f4752952b39c2a8266793f1da6 Mon Sep 17 00:00:00 2001 From: ilgyu Date: Mon, 18 Nov 2024 09:08:22 +0900 Subject: [PATCH 1/5] fix: Stake without guild not to send guild gold --- .Lib9c.Tests/Action/ApprovePledgeTest.cs | 5 ++- .Lib9c.Tests/Delegation/DelegatorTest.cs | 12 +++--- .../Migration/MigratePlanetariumGuild.cs | 3 +- Lib9c/Action/Stake.cs | 11 ----- .../ReleaseValidatorUnbondings.cs | 35 ++++++++-------- .../ValidatorDelegation/SlashValidator.cs | 8 ++-- .../ValidatorDelegation/UpdateValidators.cs | 12 +++--- .../ValidatorDelegation/ValidatorConfig.cs | 13 ------ Lib9c/Delegation/IUnbonding.cs | 2 +- Lib9c/Delegation/RebondGrace.cs | 6 ++- Lib9c/Delegation/UnbondLockIn.cs | 22 ++++------ Lib9c/Module/Guild/GuildDelegateeModule.cs | 6 +-- .../ValidatorUnbondingModule.cs | 41 ------------------- 13 files changed, 52 insertions(+), 124 deletions(-) delete mode 100644 Lib9c/Action/ValidatorDelegation/ValidatorConfig.cs delete mode 100644 Lib9c/Module/ValidatorDelegation/ValidatorUnbondingModule.cs diff --git a/.Lib9c.Tests/Action/ApprovePledgeTest.cs b/.Lib9c.Tests/Action/ApprovePledgeTest.cs index 7f93df5d73..ad75f5b149 100644 --- a/.Lib9c.Tests/Action/ApprovePledgeTest.cs +++ b/.Lib9c.Tests/Action/ApprovePledgeTest.cs @@ -58,6 +58,7 @@ public void Execute(int mead) public void Execute_JoinGuild(int mead) { var address = new PrivateKey().Address; + var validatorKey = new PrivateKey(); var patron = MeadConfig.PatronAddress; var contractAddress = address.Derive(nameof(RequestPledge)); var guildAddress = AddressUtil.CreateGuildAddress(); @@ -71,7 +72,7 @@ public void Execute_JoinGuild(int mead) ); states = DelegationUtil.EnsureValidatorPromotionReady( - states, ValidatorConfig.PlanetariumValidatorPublicKey, 0L); + states, validatorKey.PublicKey, 0L); states = new GuildRepository( states, @@ -79,7 +80,7 @@ public void Execute_JoinGuild(int mead) { Signer = GuildConfig.PlanetariumGuildOwner, }) - .MakeGuild(guildAddress, ValidatorConfig.PlanetariumValidatorAddress).World; + .MakeGuild(guildAddress, validatorKey.Address).World; var action = new ApprovePledge { diff --git a/.Lib9c.Tests/Delegation/DelegatorTest.cs b/.Lib9c.Tests/Delegation/DelegatorTest.cs index c599e2fb25..e230a91fec 100644 --- a/.Lib9c.Tests/Delegation/DelegatorTest.cs +++ b/.Lib9c.Tests/Delegation/DelegatorTest.cs @@ -141,7 +141,7 @@ public void Undelegate() Assert.Equal(unbondLockIn.Address, Assert.Single(unbondingSet.FlattenedUnbondingRefs).Address); Assert.Equal(2, unbondLockIn.Entries.Count); - unbondLockIn = unbondLockIn.Release(10L + delegatee.UnbondingPeriod - 1); + unbondLockIn = unbondLockIn.Release(10L + delegatee.UnbondingPeriod - 1, out _); delegatorBalance = repo.World.GetBalance(delegator.Address, delegatee.DelegationCurrency); delegateeBalance = repo.World.GetBalance(delegatee.DelegationPoolAddress, delegatee.DelegationCurrency); Assert.Equal(2, unbondLockIn.Entries.Count); @@ -162,7 +162,7 @@ public void Undelegate() Assert.Equal(delegatorInitialBalance - delegatingFAV, delegatorBalance); Assert.Equal(delegatingFAV, delegateeBalance); - unbondLockIn = unbondLockIn.Release(10L + delegatee.UnbondingPeriod); + unbondLockIn = unbondLockIn.Release(10L + delegatee.UnbondingPeriod, out _); delegatorBalance = repo.World.GetBalance(delegator.Address, delegatee.DelegationCurrency); delegateeBalance = repo.World.GetBalance(delegatee.DelegationPoolAddress, delegatee.DelegationCurrency); entriesByExpireHeight = Assert.Single(unbondLockIn.Entries); @@ -175,7 +175,7 @@ public void Undelegate() Assert.Equal(delegatorInitialBalance - delegatingFAV + undelegatingFAV, delegatorBalance); Assert.Equal(delegatingFAV - undelegatingFAV, delegateeBalance); - unbondLockIn = unbondLockIn.Release(12L + delegatee.UnbondingPeriod); + unbondLockIn = unbondLockIn.Release(12L + delegatee.UnbondingPeriod, out _); delegatorBalance = repo.World.GetBalance(delegator.Address, delegatee.DelegationCurrency); delegateeBalance = repo.World.GetBalance(delegatee.DelegationPoolAddress, delegatee.DelegationCurrency); Assert.Empty(unbondLockIn.Entries); @@ -253,7 +253,7 @@ public void Redelegate() Assert.Equal(rebondGrace.Address, Assert.Single(unbondingSet.FlattenedUnbondingRefs).Address); Assert.Equal(2, rebondGrace.Entries.Count); - rebondGrace = rebondGrace.Release(10L + delegatee1.UnbondingPeriod - 1); + rebondGrace = rebondGrace.Release(10L + delegatee1.UnbondingPeriod - 1, out _); Assert.Equal(2, rebondGrace.Entries.Count); entriesByExpireHeight = rebondGrace.Entries.ElementAt(0); Assert.Equal(10L + delegatee1.UnbondingPeriod, entriesByExpireHeight.Key); @@ -272,7 +272,7 @@ public void Redelegate() Assert.Equal(12L, entry.CreationHeight); Assert.Equal(12L + delegatee1.UnbondingPeriod, entry.ExpireHeight); - rebondGrace = rebondGrace.Release(10L + delegatee1.UnbondingPeriod); + rebondGrace = rebondGrace.Release(10L + delegatee1.UnbondingPeriod, out _); entriesByExpireHeight = Assert.Single(rebondGrace.Entries); Assert.Equal(12L + delegatee1.UnbondingPeriod, entriesByExpireHeight.Key); entry = Assert.Single(entriesByExpireHeight.Value); @@ -282,7 +282,7 @@ public void Redelegate() Assert.Equal(12L, entry.CreationHeight); Assert.Equal(12L + delegatee1.UnbondingPeriod, entry.ExpireHeight); - rebondGrace = rebondGrace.Release(12L + delegatee1.UnbondingPeriod); + rebondGrace = rebondGrace.Release(12L + delegatee1.UnbondingPeriod, out _); Assert.Empty(rebondGrace.Entries); } diff --git a/Lib9c/Action/Guild/Migration/MigratePlanetariumGuild.cs b/Lib9c/Action/Guild/Migration/MigratePlanetariumGuild.cs index cd7dbc37fa..216a39ded5 100644 --- a/Lib9c/Action/Guild/Migration/MigratePlanetariumGuild.cs +++ b/Lib9c/Action/Guild/Migration/MigratePlanetariumGuild.cs @@ -2,7 +2,6 @@ using Bencodex.Types; using Libplanet.Action.State; using Libplanet.Action; -using Nekoyume.Action.ValidatorDelegation; using Nekoyume.Model.Guild; using Nekoyume.Action.Guild.Migration.LegacyModels; using Lib9c; @@ -59,7 +58,7 @@ public override IWorld Execute(IActionContext context) var guild = new Model.Guild.Guild( guildAddress, legacyGuild.GuildMasterAddress, - ValidatorConfig.PlanetariumValidatorAddress, + context.Miner, repository); repository.SetGuild(guild); diff --git a/Lib9c/Action/Stake.cs b/Lib9c/Action/Stake.cs index 3ebd0d63c2..d26a10b0b5 100644 --- a/Lib9c/Action/Stake.cs +++ b/Lib9c/Action/Stake.cs @@ -210,12 +210,6 @@ private static IWorld ContractNewStake( guildParticipant.Delegate(guild, gg, height); state = guildRepository.World; } - else - { - state = state - .TransferAsset(context, stakeStateAddr, Addresses.NonValidatorDelegatee, gg); - } - } else if (additionalBalance.Sign < 0) { @@ -239,13 +233,8 @@ private static IWorld ContractNewStake( validatorDelegatee.Unbond(validatorDelegator, share, height); state = validatorRepository.World; - state = state.BurnAsset(context, guildDelegatee.DelegationPoolAddress, gg); } - else - { - state = state.BurnAsset(context, Addresses.NonValidatorDelegatee, gg); - } state = state.TransferAsset(context, stakeStateAddr, context.Signer, -additionalBalance); diff --git a/Lib9c/Action/ValidatorDelegation/ReleaseValidatorUnbondings.cs b/Lib9c/Action/ValidatorDelegation/ReleaseValidatorUnbondings.cs index 280f7f7a8e..6a7d98f8ae 100644 --- a/Lib9c/Action/ValidatorDelegation/ReleaseValidatorUnbondings.cs +++ b/Lib9c/Action/ValidatorDelegation/ReleaseValidatorUnbondings.cs @@ -46,20 +46,18 @@ public override IWorld Execute(IActionContext context) var unbondingSet = repository.GetUnbondingSet(); var unbondings = unbondingSet.UnbondingsToRelease(context.BlockIndex); - unbondings = unbondings.Select(unbonding => unbonding.Release(context.BlockIndex)).ToImmutableArray(); - foreach (var unbonding in unbondings) { switch (unbonding) { case UnbondLockIn unbondLockIn: - { - repository.SetUnbondLockIn(unbondLockIn); - repository.UpdateWorld( - Unstake(repository.World, context, unbondLockIn.DelegatorAddress)); - } + unbondLockIn.Release(context.BlockIndex, out var releasedFAV); + repository.SetUnbondLockIn(unbondLockIn); + repository.UpdateWorld( + Unstake(repository.World, context, unbondLockIn, releasedFAV)); break; case RebondGrace rebondGrace: + rebondGrace.Release(context.BlockIndex, out _); repository.SetRebondGrace(rebondGrace); break; default: @@ -72,9 +70,10 @@ public override IWorld Execute(IActionContext context) return repository.World; } - private IWorld Unstake(IWorld world, IActionContext context, Address address) + private IWorld Unstake( + IWorld world, IActionContext context, UnbondLockIn unbondLockIn, FungibleAssetValue? releasedFAV) { - var agentAddress = new AgentAddress(address); + var agentAddress = new AgentAddress(unbondLockIn.DelegatorAddress); var guildRepository = new GuildRepository(world, context); var goldCurrency = world.GetGoldCurrency(); if (guildRepository.TryGetGuildParticipant(agentAddress, out var guildParticipant)) @@ -87,20 +86,20 @@ private IWorld Unstake(IWorld world, IActionContext context, Address address) var (ncg, _) = ConvertToGoldCurrency(gg, goldCurrency); world = world.BurnAsset(context, stakeStateAddress, gg); world = world.TransferAsset( - context, stakeStateAddress, address, ncg); + context, stakeStateAddress, agentAddress, ncg); } } - else if (!IsValidator(world, context, address)) + else if (!IsValidator(world, context, unbondLockIn.DelegateeAddress)) { - var stakeStateAddress = StakeState.DeriveAddress(address); - var gg = world.GetBalance(stakeStateAddress, Currencies.GuildGold); - if (gg.Sign > 0) + if (releasedFAV is not FungibleAssetValue gg) { - var (ncg, _) = ConvertToGoldCurrency(gg, goldCurrency); - world = world.BurnAsset(context, stakeStateAddress, gg); - world = world.TransferAsset( - context, stakeStateAddress, address, ncg); + return world; } + + var stakeStateAddress = StakeState.DeriveAddress(agentAddress); + var (ncg, _) = ConvertToGoldCurrency(gg, goldCurrency); + world = world.TransferAsset( + context, stakeStateAddress, agentAddress, ncg); } return world; diff --git a/Lib9c/Action/ValidatorDelegation/SlashValidator.cs b/Lib9c/Action/ValidatorDelegation/SlashValidator.cs index 59ca7beba6..5d9fc74550 100644 --- a/Lib9c/Action/ValidatorDelegation/SlashValidator.cs +++ b/Lib9c/Action/ValidatorDelegation/SlashValidator.cs @@ -56,8 +56,8 @@ public override IWorld Execute(IActionContext context) validatorDelegatee.Jail(context.BlockIndex + AbstainJailTime); var guildRepository = new GuildRepository(repository.World, repository.ActionContext); - var validatorDelegateeForGuildParticipant = guildRepository.GetGuildDelegatee(abstain.Address); - validatorDelegateeForGuildParticipant.Slash(LivenessSlashFactor, context.BlockIndex, context.BlockIndex); + var guildDelegatee = guildRepository.GetGuildDelegatee(abstain.Address); + guildDelegatee.Slash(LivenessSlashFactor, context.BlockIndex, context.BlockIndex); repository.UpdateWorld(guildRepository.World); } @@ -76,8 +76,8 @@ public override IWorld Execute(IActionContext context) validatorDelegatee.Tombstone(); var guildRepository = new GuildRepository(repository.World, repository.ActionContext); - var validatorDelegateeForGuildParticipant = guildRepository.GetGuildDelegatee(e.TargetAddress); - validatorDelegateeForGuildParticipant.Slash(DuplicateVoteSlashFactor, e.Height, context.BlockIndex); + var guildDelegatee = guildRepository.GetGuildDelegatee(e.TargetAddress); + guildDelegatee.Slash(DuplicateVoteSlashFactor, e.Height, context.BlockIndex); repository.UpdateWorld(guildRepository.World); break; default: diff --git a/Lib9c/Action/ValidatorDelegation/UpdateValidators.cs b/Lib9c/Action/ValidatorDelegation/UpdateValidators.cs index fb1c87075b..ff6b42355d 100644 --- a/Lib9c/Action/ValidatorDelegation/UpdateValidators.cs +++ b/Lib9c/Action/ValidatorDelegation/UpdateValidators.cs @@ -39,9 +39,9 @@ public override IWorld Execute(IActionContext context) validatorDelegatee.Deactivate(); repository.SetValidatorDelegatee(validatorDelegatee); var guildRepository = new GuildRepository(repository.World, repository.ActionContext); - var validatorDelegateeForGuildParticipant = guildRepository.GetGuildDelegatee(deactivated); - validatorDelegateeForGuildParticipant.Deactivate(); - guildRepository.SetGuildDelgatee(validatorDelegateeForGuildParticipant); + var guildDelegatee = guildRepository.GetGuildDelegatee(deactivated); + guildDelegatee.Deactivate(); + guildRepository.SetGuildDelgatee(guildDelegatee); repository.UpdateWorld(guildRepository.World); } @@ -52,9 +52,9 @@ public override IWorld Execute(IActionContext context) validatorDelegatee.Activate(); repository.SetValidatorDelegatee(validatorDelegatee); var guildRepository = new GuildRepository(repository.World, repository.ActionContext); - var validatorDelegateeForGuildParticipant = guildRepository.GetGuildDelegatee(activated); - validatorDelegateeForGuildParticipant.Activate(); - guildRepository.SetGuildDelgatee(validatorDelegateeForGuildParticipant); + var guildDelegatee = guildRepository.GetGuildDelegatee(activated); + guildDelegatee.Activate(); + guildRepository.SetGuildDelgatee(guildDelegatee); repository.UpdateWorld(guildRepository.World); } diff --git a/Lib9c/Action/ValidatorDelegation/ValidatorConfig.cs b/Lib9c/Action/ValidatorDelegation/ValidatorConfig.cs deleted file mode 100644 index 985f631c29..0000000000 --- a/Lib9c/Action/ValidatorDelegation/ValidatorConfig.cs +++ /dev/null @@ -1,13 +0,0 @@ -using Libplanet.Crypto; - -namespace Nekoyume.Action.ValidatorDelegation -{ - public static class ValidatorConfig - { - public static readonly Address PlanetariumValidatorAddress = - new Address("0x8E1b572db70aB80bb02783A0D2c594A0edE6db28"); - - public static readonly PublicKey PlanetariumValidatorPublicKey = - PublicKey.FromHex("03a0f95711564d10c60ba1889d068c26cb8e5fcd5211d5aeb8810e133d629aa306"); - } -} diff --git a/Lib9c/Delegation/IUnbonding.cs b/Lib9c/Delegation/IUnbonding.cs index 4248733506..fae5adbea5 100644 --- a/Lib9c/Delegation/IUnbonding.cs +++ b/Lib9c/Delegation/IUnbonding.cs @@ -14,7 +14,7 @@ public interface IUnbonding bool IsEmpty { get; } - IUnbonding Release(long height); + IUnbonding Release(long height, out FungibleAssetValue? releasedFAV); IUnbonding Slash( BigInteger slashFactor, diff --git a/Lib9c/Delegation/RebondGrace.cs b/Lib9c/Delegation/RebondGrace.cs index f8ab128390..ac158207d1 100644 --- a/Lib9c/Delegation/RebondGrace.cs +++ b/Lib9c/Delegation/RebondGrace.cs @@ -111,8 +111,10 @@ public List Bencoded IValue IBencodable.Bencoded => Bencoded; - public RebondGrace Release(long height) + public RebondGrace Release(long height, out FungibleAssetValue? releasedFAV) { + releasedFAV = null; + if (height <= 0) { throw new ArgumentOutOfRangeException( @@ -137,7 +139,7 @@ public RebondGrace Release(long height) return UpdateEntries(updatedEntries); } - IUnbonding IUnbonding.Release(long height) => Release(height); + IUnbonding IUnbonding.Release(long height, out FungibleAssetValue? releasedFAV) => Release(height, out releasedFAV); public RebondGrace Slash( BigInteger slashFactor, diff --git a/Lib9c/Delegation/UnbondLockIn.cs b/Lib9c/Delegation/UnbondLockIn.cs index dd86120b0d..22987f5cac 100644 --- a/Lib9c/Delegation/UnbondLockIn.cs +++ b/Lib9c/Delegation/UnbondLockIn.cs @@ -137,7 +137,7 @@ public List Bencoded IValue IBencodable.Bencoded => Bencoded; - public UnbondLockIn Release(long height) + public UnbondLockIn Release(long height, out FungibleAssetValue? releasedFAV) { CannotMutateRelationsWithoutRepository(); if (height <= 0) @@ -149,7 +149,7 @@ public UnbondLockIn Release(long height) } var updatedEntries = Entries; - FungibleAssetValue? releasingFAV = null; + releasedFAV = null; foreach (var (expireHeight, entries) in updatedEntries) { if (expireHeight <= height) @@ -157,8 +157,8 @@ public UnbondLockIn Release(long height) FungibleAssetValue entriesFAV = entries .Select(e => e.UnbondingFAV) .Aggregate((accum, next) => accum + next); - releasingFAV = releasingFAV.HasValue - ? releasingFAV.Value + entriesFAV + releasedFAV = releasedFAV.HasValue + ? releasedFAV.Value + entriesFAV : entriesFAV; updatedEntries = updatedEntries.Remove(expireHeight); } @@ -168,7 +168,7 @@ public UnbondLockIn Release(long height) } } - if (releasingFAV.HasValue) + if (releasedFAV.HasValue) { if (DelegateeAddress != Addresses.NonValidatorDelegatee) { @@ -177,22 +177,14 @@ public UnbondLockIn Release(long height) _repository!.TransferAsset( delegateeMetadata.DelegationPoolAddress, delegatorMetadata.DelegationPoolAddress, - releasingFAV.Value); - } - else - { - var stakeStateAddress = StakeState.DeriveAddress(DelegatorAddress); - _repository!.TransferAsset( - Addresses.NonValidatorDelegatee, - stakeStateAddress, - releasingFAV.Value); + releasedFAV.Value); } } return UpdateEntries(updatedEntries); } - IUnbonding IUnbonding.Release(long height) => Release(height); + IUnbonding IUnbonding.Release(long height, out FungibleAssetValue? releasedFAV) => Release(height, out releasedFAV); public UnbondLockIn Slash( BigInteger slashFactor, diff --git a/Lib9c/Module/Guild/GuildDelegateeModule.cs b/Lib9c/Module/Guild/GuildDelegateeModule.cs index d92f827569..16a721a797 100644 --- a/Lib9c/Module/Guild/GuildDelegateeModule.cs +++ b/Lib9c/Module/Guild/GuildDelegateeModule.cs @@ -15,16 +15,16 @@ public static class GuildDelegateeModule public static bool TryGetGuildDelegatee( this GuildRepository repository, Address address, - [NotNullWhen(true)] out GuildDelegatee? validatorDelegateeForGuildParticipant) + [NotNullWhen(true)] out GuildDelegatee? guildDelegatee) { try { - validatorDelegateeForGuildParticipant = repository.GetGuildDelegatee(address); + guildDelegatee = repository.GetGuildDelegatee(address); return true; } catch { - validatorDelegateeForGuildParticipant = null; + guildDelegatee = null; return false; } } diff --git a/Lib9c/Module/ValidatorDelegation/ValidatorUnbondingModule.cs b/Lib9c/Module/ValidatorDelegation/ValidatorUnbondingModule.cs deleted file mode 100644 index f1a6030c0f..0000000000 --- a/Lib9c/Module/ValidatorDelegation/ValidatorUnbondingModule.cs +++ /dev/null @@ -1,41 +0,0 @@ -using System; -using Nekoyume.Delegation; -using Nekoyume.ValidatorDelegation; - -namespace Nekoyume.Module.ValidatorDelegation -{ - public static class ValidatorUnbondingModule - { - public static ValidatorRepository ReleaseUnbondings( - this ValidatorRepository repository) - { - var context = repository.ActionContext; - var unbondingSet = repository.GetUnbondingSet(); - var unbondings = unbondingSet.UnbondingsToRelease(context.BlockIndex); - - IUnbonding released; - foreach (var unbonding in unbondings) - { - released = unbonding.Release(context.BlockIndex); - - switch (released) - { - case UnbondLockIn unbondLockIn: - repository.SetUnbondLockIn(unbondLockIn); - break; - case RebondGrace rebondGrace: - repository.SetRebondGrace(rebondGrace); - break; - default: - throw new ArgumentException("Invalid unbonding type."); - } - - unbondingSet = unbondingSet.SetUnbonding(released); - } - - repository.SetUnbondingSet(unbondingSet); - - return repository; - } - } -} From 2e8e26de9d0e6f6fec8820350a2ff91070ec27c3 Mon Sep 17 00:00:00 2001 From: ilgyu Date: Mon, 18 Nov 2024 10:30:31 +0900 Subject: [PATCH 2/5] test: Fix unstake test --- .Lib9c.Tests/Action/StakeTest.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.Lib9c.Tests/Action/StakeTest.cs b/.Lib9c.Tests/Action/StakeTest.cs index 5de72ac960..9185cc33b1 100644 --- a/.Lib9c.Tests/Action/StakeTest.cs +++ b/.Lib9c.Tests/Action/StakeTest.cs @@ -429,8 +429,6 @@ public void Execute_Success_When_Exist_StakeStateV3_Without_Guild( world = world.MintAsset(new ActionContext(), _agentAddr, ncgToStake); world = world.TransferAsset( new ActionContext(), _agentAddr, stakeStateAddr, ncgToStake); - world = world.TransferAsset( - new ActionContext(), stakeStateAddr, Addresses.NonValidatorDelegatee, gg); } world = world.SetLegacyState(stakeStateAddr, stakeState.Serialize()); @@ -459,7 +457,10 @@ public void Execute_Success_When_Exist_StakeStateV3_Without_Guild( var expectedBalance = _ncg * Math.Max(0, previousAmount - amount); var actualBalance = world.GetBalance(_agentAddr, _ncg); + var nonValidatorDelegateeBalance = world.GetBalance( + Addresses.NonValidatorDelegatee, Currencies.GuildGold); Assert.Equal(expectedBalance, actualBalance); + Assert.Equal(Currencies.GuildGold * 0, nonValidatorDelegateeBalance); } private IWorld Execute( From f0d5b6beb58ed8b554ad35c9d1a7ebe7dff34739 Mon Sep 17 00:00:00 2001 From: ilgyu Date: Mon, 18 Nov 2024 10:33:17 +0900 Subject: [PATCH 3/5] fix: Add sign checker for fav --- Lib9c/Action/ValidatorDelegation/ReleaseValidatorUnbondings.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib9c/Action/ValidatorDelegation/ReleaseValidatorUnbondings.cs b/Lib9c/Action/ValidatorDelegation/ReleaseValidatorUnbondings.cs index 6a7d98f8ae..236b865368 100644 --- a/Lib9c/Action/ValidatorDelegation/ReleaseValidatorUnbondings.cs +++ b/Lib9c/Action/ValidatorDelegation/ReleaseValidatorUnbondings.cs @@ -91,7 +91,7 @@ private IWorld Unstake( } else if (!IsValidator(world, context, unbondLockIn.DelegateeAddress)) { - if (releasedFAV is not FungibleAssetValue gg) + if (releasedFAV is not FungibleAssetValue gg || gg.Sign < 1) { return world; } From bfc2e1715f426f59a73ec70ae8fe95d63a2b2084 Mon Sep 17 00:00:00 2001 From: ilgyu Date: Mon, 18 Nov 2024 10:43:41 +0900 Subject: [PATCH 4/5] fix: Burn Guild Gold --- Lib9c/Action/Stake.cs | 7 ++++++- .../ValidatorDelegation/ReleaseValidatorUnbondings.cs | 5 +++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Lib9c/Action/Stake.cs b/Lib9c/Action/Stake.cs index d26a10b0b5..81cbdef1da 100644 --- a/Lib9c/Action/Stake.cs +++ b/Lib9c/Action/Stake.cs @@ -235,8 +235,13 @@ private static IWorld ContractNewStake( state = validatorRepository.World; state = state.BurnAsset(context, guildDelegatee.DelegationPoolAddress, gg); } + else + { + state = state.BurnAsset(context, stakeStateAddr, gg); + } - state = state.TransferAsset(context, stakeStateAddr, context.Signer, -additionalBalance); + state = state + .TransferAsset(context, stakeStateAddr, context.Signer, -additionalBalance); // TODO : [GuildMigration] Revive below code when the migration is done. // if (guildRepository.TryGetGuildParticipant(agentAddress, out var guildParticipant)) diff --git a/Lib9c/Action/ValidatorDelegation/ReleaseValidatorUnbondings.cs b/Lib9c/Action/ValidatorDelegation/ReleaseValidatorUnbondings.cs index 236b865368..c68def6be6 100644 --- a/Lib9c/Action/ValidatorDelegation/ReleaseValidatorUnbondings.cs +++ b/Lib9c/Action/ValidatorDelegation/ReleaseValidatorUnbondings.cs @@ -98,8 +98,9 @@ private IWorld Unstake( var stakeStateAddress = StakeState.DeriveAddress(agentAddress); var (ncg, _) = ConvertToGoldCurrency(gg, goldCurrency); - world = world.TransferAsset( - context, stakeStateAddress, agentAddress, ncg); + world = world + .TransferAsset(context, stakeStateAddress, agentAddress, ncg) + .BurnAsset(context, stakeStateAddress, gg); } return world; From 0ac599d640acb4045d2812621d4d0cf2bd513c89 Mon Sep 17 00:00:00 2001 From: ilgyu Date: Mon, 18 Nov 2024 10:57:30 +0900 Subject: [PATCH 5/5] test: Fix test to check GuildGold balance --- .Lib9c.Tests/Action/StakeTest.cs | 2 ++ Lib9c/Action/Stake.cs | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.Lib9c.Tests/Action/StakeTest.cs b/.Lib9c.Tests/Action/StakeTest.cs index 9185cc33b1..4441136909 100644 --- a/.Lib9c.Tests/Action/StakeTest.cs +++ b/.Lib9c.Tests/Action/StakeTest.cs @@ -459,8 +459,10 @@ public void Execute_Success_When_Exist_StakeStateV3_Without_Guild( var actualBalance = world.GetBalance(_agentAddr, _ncg); var nonValidatorDelegateeBalance = world.GetBalance( Addresses.NonValidatorDelegatee, Currencies.GuildGold); + var stakeBalance = world.GetBalance(stakeStateAddr, Currencies.GuildGold); Assert.Equal(expectedBalance, actualBalance); Assert.Equal(Currencies.GuildGold * 0, nonValidatorDelegateeBalance); + Assert.Equal(Currencies.GuildGold * amount, stakeBalance); } private IWorld Execute( diff --git a/Lib9c/Action/Stake.cs b/Lib9c/Action/Stake.cs index 81cbdef1da..b87ce5a9c2 100644 --- a/Lib9c/Action/Stake.cs +++ b/Lib9c/Action/Stake.cs @@ -9,7 +9,6 @@ using Libplanet.Action.State; using Libplanet.Crypto; using Libplanet.Types.Assets; -using Nekoyume.Delegation; using Nekoyume.Exceptions; using Nekoyume.Extensions; using Nekoyume.Model.Guild; @@ -23,7 +22,6 @@ using Nekoyume.ValidatorDelegation; using Serilog; using static Lib9c.SerializeKeys; -using static Nekoyume.Model.WorldInformation; namespace Nekoyume.Action {