Skip to content

Commit

Permalink
doc: Add documents for new features
Browse files Browse the repository at this point in the history
  • Loading branch information
OnedgeLee committed Dec 13, 2024
1 parent 815fa51 commit 04db96d
Show file tree
Hide file tree
Showing 8 changed files with 271 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Lib9c/Action/ValidatorDelegation/SetValidatorCommission.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

namespace Nekoyume.Action.ValidatorDelegation
{
/// <summary>
/// Set the commission percentage of the validator.
/// </summary>
[ActionType(TypeIdentifier)]
public sealed class SetValidatorCommission : ActionBase
{
Expand Down
27 changes: 27 additions & 0 deletions Lib9c/Delegation/Delegatee.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,32 @@ public Address UnbondLockInAddress(Address delegatorAddress)
public Address RebondGraceAddress(Address delegatorAddress)
=> Metadata.RebondGraceAddress(delegatorAddress);

/// <summary>
/// Get the <see cref="Address"/> of the distribution pool
/// where the rewards are distributed from.
/// </summary>
/// <returns>
/// <see cref="Address"/> of the distribution pool.
/// </returns>
public Address DistributionPoolAddress()
=> Metadata.DistributionPoolAddress();

/// <summary>
/// Get the <see cref="Address"/> of the current <see cref="RewardBase"/>.
/// </summary>
/// <returns>
/// <see cref="Address"/> of the current <see cref="RewardBase"/>.
/// </returns>
public Address CurrentRewardBaseAddress()
=> Metadata.CurrentRewardBaseAddress();

/// <summary>
/// Get the <see cref="Address"/> of the <see cref="RewardBase"/> at the given height.
/// </summary>
/// <param name="height"></param>
/// <returns>
/// <see cref="Address"/> of the <see cref="RewardBase"/> at the given height.
/// </returns>
public Address RewardBaseAddress(long height)
=> Metadata.RewardBaseAddress(height);

Expand Down Expand Up @@ -404,6 +424,13 @@ ImmutableDictionary<Currency, FungibleAssetValue> reward
return reward;
}

/// <summary>
/// Start a new reward period.
/// It generates a new <see cref="RewardBase"/> and archives the current one.
/// </summary>
/// <param name="height">
/// The height of the block where the new reward period starts.
/// </param>
public void StartNewRewardPeriod(long height)
{
MigrateLumpSumRewardsRecords();
Expand Down
78 changes: 78 additions & 0 deletions Lib9c/Delegation/DelegateeMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,47 @@ public class DelegateeMetadata : IDelegateeMetadata
private Address? _address;
private readonly IComparer<Currency> _currencyComparer = new CurrencyComparer();

/// <summary>
/// Create a new instance of DelegateeMetadata.
/// </summary>
/// <param name="delegateeAddress">
/// The <see cref="Address"/> of the <see cref="Delegatee{T, TSelf}"/>.
/// </param>
/// <param name="delegateeAccountAddress">
/// The <see cref="Address"/> of the account of the <see cref="Delegatee{T, TSelf}"/>.
/// </param>
/// <param name="delegationCurrency">
/// The <see cref="Currency"/> used for delegation.
/// </param>
/// <param name="rewardCurrencies">
/// The enumerable of <see cref="Currency"/>s used for reward.
/// </param>
/// <param name="delegationPoolAddress">
/// The <see cref="Address"/> of the delegation pool that stores
/// delegated <see cref="FungibleAssetValue"/>s.
/// </param>
/// <param name="rewardPoolAddress">
/// The <see cref="Address"/> of the reward pool that gathers
/// rewards to be distributed.
/// </param>
/// <param name="rewardRemainderPoolAddress">
/// The <see cref="Address"/> of the reward remainder pool to
/// sends the remainder of the rewards to.
/// </param>
/// <param name="slashedPoolAddress">
/// The <see cref="Address"/> of the pool that sends the slashed
/// <see cref="FungibleAssetValue"/>s to.
/// </param>
/// <param name="unbondingPeriod">
/// The period in blocks that the unbonded <see cref="FungibleAssetValue"/>s
/// can be withdrawn.
/// </param>
/// <param name="maxUnbondLockInEntries">
/// The maximum number of entries that can be locked in for unbonding.
/// </param>
/// <param name="maxRebondGraceEntries">
/// The maximum number of entries that can be locked in for rebonding.
/// </param>
public DelegateeMetadata(
Address delegateeAddress,
Address delegateeAccountAddress,
Expand Down Expand Up @@ -340,18 +381,55 @@ public Address UnbondLockInAddress(Address delegatorAddress)
public virtual Address RebondGraceAddress(Address delegatorAddress)
=> DelegationAddress.RebondGraceAddress(Address, delegatorAddress);

/// <summary>
/// Get the <see cref="Address"/> of the distribution pool
/// where the rewards are distributed from.
/// </summary>
/// <returns>
/// <see cref="Address"/> of the distribution pool.
/// </returns>
public virtual Address DistributionPoolAddress()
=> DelegationAddress.DistributionPoolAddress(Address);

/// <summary>
/// Get the <see cref="Address"/> of the current <see cref="RewardBase"/>.
/// </summary>
/// <returns>
/// <see cref="Address"/> of the current <see cref="RewardBase"/>.
/// </returns>
public virtual Address CurrentRewardBaseAddress()
=> DelegationAddress.CurrentRewardBaseAddress(Address);

/// <summary>
/// Get the <see cref="Address"/> of the <see cref="RewardBase"/> at the given height.
/// </summary>
/// <param name="height"></param>
/// <returns>
/// <see cref="Address"/> of the <see cref="RewardBase"/> at the given height.
/// </returns>
public virtual Address RewardBaseAddress(long height)
=> DelegationAddress.RewardBaseAddress(Address, height);

/// <summary>
/// Get the <see cref="Address"/> of the current lump sum rewards record.
/// This will be removed after the migration is done.
/// </summary>
/// <returns>
/// <see cref="Address"/> of the current lump sum rewards record.
/// </returns>
public virtual Address CurrentLumpSumRewardsRecordAddress()
=> DelegationAddress.CurrentRewardBaseAddress(Address);

/// <summary>
/// Get the <see cref="Address"/> of the lump sum rewards record at the given height.
/// This will be removed after the migration is done.
/// </summary>
/// <param name="height">
/// The height of the lump sum rewards record.
/// </param>
/// <returns>
/// <see cref="Address"/> of the lump sum rewards record at the given height.
/// </returns>
public virtual Address LumpSumRewardsRecordAddress(long height)
=> DelegationAddress.RewardBaseAddress(Address, height);

Expand Down
71 changes: 71 additions & 0 deletions Lib9c/Delegation/DelegationAddress.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,25 +65,73 @@ public static Address RebondGraceAddress(
delegateeMetadataAddress,
delegatorAddress.ByteArray);

/// <summary>
/// Get the <see cref="Address"/> of the current <see cref="RewardBase"/>.
/// </summary>
/// <param name="delegateeAddress">
/// <see cref="Address"/> of the <see cref="Delegatee{T, TSelf}"/>.
/// </param>
/// <param name="delegateeAccountAddress">
/// <see cref="Address"/> of the account of the <see cref="Delegatee{T, TSelf}"/>.
/// </param>
/// <returns>
/// <see cref="Address"/> of the current <see cref="RewardBase"/>.
/// </returns>
public static Address CurrentRewardBaseAddress(
Address delegateeAddress, Address delegateeAccountAddress)
=> DeriveAddress(
DelegationElementType.RewardBase,
DelegateeMetadataAddress(delegateeAddress, delegateeAccountAddress));

/// <summary>
/// Get the <see cref="Address"/> of the current <see cref="RewardBase"/>.
/// </summary>
/// <param name="delegateeMetadataAddress">
/// <see cref="Address"/> of the <see cref="DelegateeMetadata"/>.
/// </param>
/// <returns>
/// <see cref="Address"/> of the current <see cref="RewardBase"/>.
/// </returns>
public static Address CurrentRewardBaseAddress(
Address delegateeMetadataAddress)
=> DeriveAddress(
DelegationElementType.RewardBase,
delegateeMetadataAddress);

/// <summary>
/// Get the <see cref="Address"/> of the <see cref="RewardBase"/> at the given height.
/// </summary>
/// <param name="delegateeAddress">
/// <see cref="Address"/> of the <see cref="Delegatee{T, TSelf}"/>.
/// </param>
/// <param name="delegateeAccountAddress">
/// <see cref="Address"/> of the account of the <see cref="Delegatee{T, TSelf}"/>.
/// </param>
/// <param name="height">
/// The height of the <see cref="RewardBase"/>.
/// </param>
/// <returns>
/// <see cref="Address"/> of the <see cref="RewardBase"/> at the given height.
/// </returns>
public static Address RewardBaseAddress(
Address delegateeAddress, Address delegateeAccountAddress, long height)
=> DeriveAddress(
DelegationElementType.RewardBase,
DelegateeMetadataAddress(delegateeAddress, delegateeAccountAddress),
BitConverter.GetBytes(height));

/// <summary>
/// Get the <see cref="Address"/> of the <see cref="RewardBase"/> at the given height.
/// </summary>
/// <param name="delegateeMetadataAddress">
/// <see cref="Address"/> of the <see cref="DelegateeMetadata"/>.
/// </param>
/// <param name="height">
/// The height of the <see cref="RewardBase"/>.
/// </param>
/// <returns>
/// <see cref="Address"/> of the <see cref="RewardBase"/> at the given height.
/// </returns>
public static Address RewardBaseAddress(
Address delegateeMetadataAddress, long height)
=> DeriveAddress(
Expand All @@ -103,12 +151,35 @@ public static Address RewardPoolAddress(
DelegationElementType.RewardPool,
delegateeMetadataAddress);

/// <summary>
/// Get the <see cref="Address"/> of the distribution pool
/// where the rewards are distributed from.
/// </summary>
/// <param name="delegateeAddress">
/// <see cref="Address"/> of the <see cref="Delegatee{T, TSelf}"/>.
/// </param>
/// <param name="delegateeAccountAddress">
/// <see cref="Address"/> of the account of the <see cref="Delegatee{T, TSelf}"/>.
/// </param>
/// <returns>
/// <see cref="Address"/> of the distribution pool.
/// </returns>
public static Address DistributionPoolAddress(
Address delegateeAddress, Address delegateeAccountAddress)
=> DeriveAddress(
DelegationElementType.DistributionPool,
DelegateeMetadataAddress(delegateeAddress, delegateeAccountAddress));

/// <summary>
/// Get the <see cref="Address"/> of the distribution pool
/// where the rewards are distributed from.
/// </summary>
/// <param name="delegateeMetadataAddress">
/// <see cref="Address"/> of the <see cref="DelegateeMetadata"/>.
/// </param>
/// <returns>
/// <see cref="Address"/> of the distribution pool.
/// </returns>
public static Address DistributionPoolAddress(
Address delegateeMetadataAddress)
=> DeriveAddress(
Expand Down
37 changes: 37 additions & 0 deletions Lib9c/Delegation/DelegationRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,26 +74,59 @@ public DelegationRepository(
.SetAccount(RewardBaseAccountAddress, rewardBaseAccount)
.SetAccount(LumpSumRewardsRecordAccountAddress, lumpSumRewardsRecordAccount);

/// <summary>
/// <see cref="IActionContext"/> of the current action.
/// </summary>
public IActionContext ActionContext { get; }

/// <summary>
/// <see cref="Address"> of the <see cref="Delegatee{T, TSelf}"> account.
/// </summary>
public Address DelegateeAccountAddress { get; }

/// <summary>
/// <see cref="Address"> of the <see cref="Delegator{T, TSelf}"> account.
/// </summary>
public Address DelegatorAccountAddress { get; }

/// <summary>
/// <see cref="Address"> of the <see cref="DelegateeMetadata"/> account.
/// </summary>
public Address DelegateeMetadataAccountAddress { get; }

/// <summary>
/// <see cref="Address"> of the <see cref="DelegatorMetadata"> account.
/// </summary>
public Address DelegatorMetadataAccountAddress { get; }

/// <summary>
/// <see cref="Address"/> of the <see cref="Bond"/> account.
/// </summary>
public Address BondAccountAddress { get; }

/// <summary>
/// <see cref="Address"/> of the <see cref="UnbondLockIn"/> account.
/// </summary>
public Address UnbondLockInAccountAddress { get; }

/// <summary>
/// <see cref="Address"/> of the <see cref="RebondGrace"/> account
/// </summary>
public Address RebondGraceAccountAddress { get; }

/// <summary>
/// <see cref="Address"/> of the <see cref="UnbondingSet"/> account.
/// </summary>
public Address UnbondingSetAccountAddress { get; }

/// <summary>
/// <see cref="Address"/> of the <see cref="RewardBase"/> account.
/// </summary>
public Address RewardBaseAccountAddress { get; }

/// <summary>
/// <see cref="Address"/> of the <see cref="LumpSumRewardsRecord"/> account.
/// </summary>
public Address LumpSumRewardsRecordAccountAddress { get; }

public abstract IDelegatee GetDelegatee(Address address);
Expand Down Expand Up @@ -170,6 +203,7 @@ public UnbondingSet GetUnbondingSet()
? new UnbondingSet(bencoded, this)
: new UnbondingSet(this);

/// <inheritdoc/>
public RewardBase? GetCurrentRewardBase(IDelegatee delegatee)
{
Address address = delegatee.CurrentRewardBaseAddress();
Expand All @@ -179,6 +213,7 @@ public UnbondingSet GetUnbondingSet()
: null;
}

/// <inheritdoc/>
public RewardBase? GetRewardBase(IDelegatee delegatee, long height)
{
Address address = delegatee.RewardBaseAddress(height);
Expand Down Expand Up @@ -251,6 +286,7 @@ public void SetUnbondingSet(UnbondingSet unbondingSet)
: unbondingSetAccount.SetState(UnbondingSet.Address, unbondingSet.Bencoded);
}

/// <inheritdoc/>
public void SetRewardBase(RewardBase rewardBase)
{
rewardBaseAccount = rewardBaseAccount.SetState(rewardBase.Address, rewardBase.Bencoded);
Expand All @@ -262,6 +298,7 @@ public void SetLumpSumRewardsRecord(LumpSumRewardsRecord lumpSumRewardsRecord)
lumpSumRewardsRecord.Address, lumpSumRewardsRecord.Bencoded);
}

/// <inheritdoc/>
public void RemoveLumpSumRewardsRecord(LumpSumRewardsRecord lumpSumRewardsRecord)
{
lumpSumRewardsRecordAccount = lumpSumRewardsRecordAccount.RemoveState(lumpSumRewardsRecord.Address);
Expand Down
15 changes: 15 additions & 0 deletions Lib9c/Delegation/IDelegatee.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,23 @@ public interface IDelegatee

Address RebondGraceAddress(Address delegatorAddress);

/// <summary>
/// Get the <see cref="Address"/> of the current <see cref="RewardBase"/>.
/// </summary>
/// <returns>
/// The <see cref="Address"/> of the current <see cref="RewardBase"/>.
/// </returns>
Address CurrentRewardBaseAddress();

/// <summary>
/// Get the <see cref="Address"/> of the <see cref="RewardBase"/> at the given height.
/// </summary>
/// <param name="height">
/// The height of the <see cref="RewardBase"/>.
/// </param>
/// <returns>
/// The <see cref="Address"/> of the <see cref="RewardBase"/> at the given height.
/// </returns>
Address RewardBaseAddress(long height);

Address CurrentLumpSumRewardsRecordAddress();
Expand Down
Loading

0 comments on commit 04db96d

Please sign in to comment.