Skip to content

Commit

Permalink
update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
0xripleys committed Sep 27, 2024
1 parent 8156c67 commit 4b7d8e1
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 6 deletions.
9 changes: 6 additions & 3 deletions crates/sui-framework/docs/sui-system/staking_pool.md
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,12 @@ returns (principal_withdraw_amount, rewards_withdraw_amount)
// 1. <b>if</b> the entire <a href="staking_pool.md#0x3_staking_pool_FungibleStakedSuiData">FungibleStakedSuiData</a> supply is redeemed, how much <a href="../sui-framework/sui.md#0x2_sui">sui</a> should we receive?
<b>let</b> total_sui_amount = <a href="staking_pool.md#0x3_staking_pool_get_sui_amount">get_sui_amount</a>(&latest_exchange_rate, fungible_staked_sui_data_total_supply);

// <b>min</b> <b>with</b> total_sui_amount <b>to</b> prevent underflow
<b>let</b> fungible_staked_sui_data_principal_amount = std::u64::min(
fungible_staked_sui_data_principal_amount,
total_sui_amount
);

// 2. how much do we need <b>to</b> withdraw from the rewards pool?
<b>let</b> total_rewards = total_sui_amount - fungible_staked_sui_data_principal_amount;

Expand Down Expand Up @@ -1377,9 +1383,6 @@ Returns true if the input staking pool is inactive.

fungible_staked_sui.value = fungible_staked_sui.value - split_amount;

<b>assert</b>!(fungible_staked_sui.value &gt;= <a href="staking_pool.md#0x3_staking_pool_MIN_STAKING_THRESHOLD">MIN_STAKING_THRESHOLD</a>, <a href="staking_pool.md#0x3_staking_pool_EStakedSuiBelowThreshold">EStakedSuiBelowThreshold</a>);
<b>assert</b>!(split_amount &gt;= <a href="staking_pool.md#0x3_staking_pool_MIN_STAKING_THRESHOLD">MIN_STAKING_THRESHOLD</a>, <a href="staking_pool.md#0x3_staking_pool_EStakedSuiBelowThreshold">EStakedSuiBelowThreshold</a>);

<a href="staking_pool.md#0x3_staking_pool_FungibleStakedSui">FungibleStakedSui</a> {
id: <a href="../sui-framework/object.md#0x2_object_new">object::new</a>(ctx),
pool_id: fungible_staked_sui.pool_id,
Expand Down
118 changes: 116 additions & 2 deletions crates/sui-framework/docs/sui-system/validator.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ title: Module `0x3::validator`
- [Struct `Validator`](#0x3_validator_Validator)
- [Struct `StakingRequestEvent`](#0x3_validator_StakingRequestEvent)
- [Struct `UnstakingRequestEvent`](#0x3_validator_UnstakingRequestEvent)
- [Struct `ConvertingToFungibleStakedSuiEvent`](#0x3_validator_ConvertingToFungibleStakedSuiEvent)
- [Struct `RedeemingFungibleStakedSuiEvent`](#0x3_validator_RedeemingFungibleStakedSuiEvent)
- [Constants](#@Constants_0)
- [Function `new_metadata`](#0x3_validator_new_metadata)
- [Function `new`](#0x3_validator_new)
Expand Down Expand Up @@ -461,6 +463,92 @@ Event emitted when a new unstake request is received.
</dl>


</details>

<a name="0x3_validator_ConvertingToFungibleStakedSuiEvent"></a>

## Struct `ConvertingToFungibleStakedSuiEvent`

Event emitted when a staked SUI is converted to a fungible staked SUI.


<pre><code><b>struct</b> <a href="validator.md#0x3_validator_ConvertingToFungibleStakedSuiEvent">ConvertingToFungibleStakedSuiEvent</a> <b>has</b> <b>copy</b>, drop
</code></pre>



<details>
<summary>Fields</summary>


<dl>
<dt>
<code>pool_id: <a href="../sui-framework/object.md#0x2_object_ID">object::ID</a></code>
</dt>
<dd>

</dd>
<dt>
<code>stake_activation_epoch: <a href="../move-stdlib/u64.md#0x1_u64">u64</a></code>
</dt>
<dd>

</dd>
<dt>
<code>staked_sui_principal_amount: <a href="../move-stdlib/u64.md#0x1_u64">u64</a></code>
</dt>
<dd>

</dd>
<dt>
<code>fungible_staked_sui_amount: <a href="../move-stdlib/u64.md#0x1_u64">u64</a></code>
</dt>
<dd>

</dd>
</dl>


</details>

<a name="0x3_validator_RedeemingFungibleStakedSuiEvent"></a>

## Struct `RedeemingFungibleStakedSuiEvent`

Event emitted when a fungible staked SUI is redeemed.


<pre><code><b>struct</b> <a href="validator.md#0x3_validator_RedeemingFungibleStakedSuiEvent">RedeemingFungibleStakedSuiEvent</a> <b>has</b> <b>copy</b>, drop
</code></pre>



<details>
<summary>Fields</summary>


<dl>
<dt>
<code>pool_id: <a href="../sui-framework/object.md#0x2_object_ID">object::ID</a></code>
</dt>
<dd>

</dd>
<dt>
<code>fungible_staked_sui_amount: <a href="../move-stdlib/u64.md#0x1_u64">u64</a></code>
</dt>
<dd>

</dd>
<dt>
<code>sui_amount: <a href="../move-stdlib/u64.md#0x1_u64">u64</a></code>
</dt>
<dd>

</dd>
</dl>


</details>

<a name="@Constants_0"></a>
Expand Down Expand Up @@ -942,7 +1030,21 @@ Request to add stake to the validator's staking pool, processed at the end of th
staked_sui: StakedSui,
ctx: &<b>mut</b> TxContext,
) : FungibleStakedSui {
self.<a href="staking_pool.md#0x3_staking_pool">staking_pool</a>.<a href="validator.md#0x3_validator_convert_to_fungible_staked_sui">convert_to_fungible_staked_sui</a>(staked_sui, ctx)
<b>let</b> stake_activation_epoch = staked_sui.stake_activation_epoch();
<b>let</b> staked_sui_principal_amount = staked_sui.staked_sui_amount();

<b>let</b> fungible_staked_sui = self.<a href="staking_pool.md#0x3_staking_pool">staking_pool</a>.<a href="validator.md#0x3_validator_convert_to_fungible_staked_sui">convert_to_fungible_staked_sui</a>(staked_sui, ctx);

<a href="../sui-framework/event.md#0x2_event_emit">event::emit</a>(
<a href="validator.md#0x3_validator_ConvertingToFungibleStakedSuiEvent">ConvertingToFungibleStakedSuiEvent</a> {
pool_id: self.<a href="validator.md#0x3_validator_staking_pool_id">staking_pool_id</a>(),
stake_activation_epoch,
staked_sui_principal_amount,
fungible_staked_sui_amount: fungible_staked_sui.value(),
}
);

fungible_staked_sui
}
</code></pre>

Expand Down Expand Up @@ -970,7 +1072,19 @@ Request to add stake to the validator's staking pool, processed at the end of th
fungible_staked_sui: FungibleStakedSui,
ctx: &TxContext,
) : Balance&lt;SUI&gt; {
self.<a href="staking_pool.md#0x3_staking_pool">staking_pool</a>.<a href="validator.md#0x3_validator_redeem_fungible_staked_sui">redeem_fungible_staked_sui</a>(fungible_staked_sui, ctx)
<b>let</b> fungible_staked_sui_amount = fungible_staked_sui.value();

<b>let</b> <a href="../sui-framework/sui.md#0x2_sui">sui</a> = self.<a href="staking_pool.md#0x3_staking_pool">staking_pool</a>.<a href="validator.md#0x3_validator_redeem_fungible_staked_sui">redeem_fungible_staked_sui</a>(fungible_staked_sui, ctx);

<a href="../sui-framework/event.md#0x2_event_emit">event::emit</a>(
<a href="validator.md#0x3_validator_RedeemingFungibleStakedSuiEvent">RedeemingFungibleStakedSuiEvent</a> {
pool_id: self.<a href="validator.md#0x3_validator_staking_pool_id">staking_pool_id</a>(),
fungible_staked_sui_amount,
sui_amount: <a href="../sui-framework/sui.md#0x2_sui">sui</a>.value(),
}
);

<a href="../sui-framework/sui.md#0x2_sui">sui</a>
}
</code></pre>

Expand Down
2 changes: 1 addition & 1 deletion crates/sui-framework/docs/sui-system/validator_set.md
Original file line number Diff line number Diff line change
Expand Up @@ -976,7 +976,7 @@ the stake and any rewards corresponding to it will be immediately processed.
<b>let</b> staking_pool_id = pool_id(&staked_sui);
<b>let</b> <a href="validator.md#0x3_validator">validator</a> =
<b>if</b> (self.staking_pool_mappings.contains(staking_pool_id)) { // This is an active <a href="validator.md#0x3_validator">validator</a>.
<b>let</b> validator_address = self.staking_pool_mappings[pool_id(&staked_sui)];
<b>let</b> validator_address = self.staking_pool_mappings[staking_pool_id];
<a href="validator_set.md#0x3_validator_set_get_candidate_or_active_validator_mut">get_candidate_or_active_validator_mut</a>(self, validator_address)
} <b>else</b> { // This is an inactive pool.
<b>assert</b>!(self.inactive_validators.contains(staking_pool_id), <a href="validator_set.md#0x3_validator_set_ENoPoolFound">ENoPoolFound</a>);
Expand Down
Binary file modified crates/sui-framework/packages_compiled/sui-system
Binary file not shown.
6 changes: 6 additions & 0 deletions crates/sui-framework/published_api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,12 @@ StakingRequestEvent
UnstakingRequestEvent
public struct
0x3::validator
ConvertingToFungibleStakedSuiEvent
public struct
0x3::validator
RedeemingFungibleStakedSuiEvent
public struct
0x3::validator
new_metadata
public(package) fun
0x3::validator
Expand Down

0 comments on commit 4b7d8e1

Please sign in to comment.