Skip to content

Commit

Permalink
Add V16 Builtin Actors (#350)
Browse files Browse the repository at this point in the history
  • Loading branch information
sudo-shashank authored Dec 6, 2024
1 parent ee9fe74 commit f1d88b4
Show file tree
Hide file tree
Showing 126 changed files with 19,360 additions and 16 deletions.
28 changes: 14 additions & 14 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ members = [
resolver = "2"

[workspace.package]
version = "18.0.0"
version = "19.0.0"
license = "MIT OR Apache-2.0"
repository = "https://github.com/ChainSafe/fil-actor-states"
authors = [
Expand Down Expand Up @@ -81,18 +81,18 @@ toml = "0.8"
uint = { version = "0.10", default-features = false }
unsigned-varint = "0.8"

fil_actor_account_state = { version = "18.0.0", path = "./actors/account" }
fil_actor_cron_state = { version = "18.0.0", path = "./actors/cron" }
fil_actor_datacap_state = { version = "18.0.0", path = "./actors/datacap" }
fil_actor_evm_state = { version = "18.0.0", path = "./actors/evm" }
fil_actor_init_state = { version = "18.0.0", path = "./actors/init" }
fil_actor_market_state = { version = "18.0.0", path = "./actors/market" }
fil_actor_miner_state = { version = "18.0.0", path = "./actors/miner" }
fil_actor_multisig_state = { version = "18.0.0", path = "./actors/multisig" }
fil_actor_power_state = { version = "18.0.0", path = "./actors/power" }
fil_actor_reward_state = { version = "18.0.0", path = "./actors/reward" }
fil_actor_system_state = { version = "18.0.0", path = "./actors/system" }
fil_actor_verifreg_state = { version = "18.0.0", path = "./actors/verifreg" }
fil_actors_shared = { version = "18.0.0", path = "./fil_actors_shared" }
fil_actor_account_state = { version = "19.0.0", path = "./actors/account" }
fil_actor_cron_state = { version = "19.0.0", path = "./actors/cron" }
fil_actor_datacap_state = { version = "19.0.0", path = "./actors/datacap" }
fil_actor_evm_state = { version = "19.0.0", path = "./actors/evm" }
fil_actor_init_state = { version = "19.0.0", path = "./actors/init" }
fil_actor_market_state = { version = "19.0.0", path = "./actors/market" }
fil_actor_miner_state = { version = "19.0.0", path = "./actors/miner" }
fil_actor_multisig_state = { version = "19.0.0", path = "./actors/multisig" }
fil_actor_power_state = { version = "19.0.0", path = "./actors/power" }
fil_actor_reward_state = { version = "19.0.0", path = "./actors/reward" }
fil_actor_system_state = { version = "19.0.0", path = "./actors/system" }
fil_actor_verifreg_state = { version = "19.0.0", path = "./actors/verifreg" }
fil_actors_shared = { version = "19.0.0", path = "./fil_actors_shared" }

fil_actors_test_utils = { path = "./fil_actors_test_utils" }
1 change: 1 addition & 0 deletions actors/account/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ version.workspace = true
keywords.workspace = true

[dependencies]
frc42_dispatch = { workspace = true }
frc42_macros = { workspace = true }
fvm_ipld_encoding = { workspace = true }
fvm_shared = { workspace = true }
Expand Down
1 change: 1 addition & 0 deletions actors/account/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ pub mod v12;
pub mod v13;
pub mod v14;
pub mod v15;
pub mod v16;
pub mod v8;
pub mod v9;
20 changes: 20 additions & 0 deletions actors/account/src/v16/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright 2019-2022 ChainSafe Systems
// SPDX-License-Identifier: Apache-2.0, MIT

pub use self::state::State;
use fvm_shared4::METHOD_CONSTRUCTOR;
use num_derive::FromPrimitive;

mod state;
pub mod types;

/// Account actor methods available
#[derive(FromPrimitive)]
#[repr(u64)]
pub enum Method {
Constructor = METHOD_CONSTRUCTOR,
PubkeyAddress = 2,
// Deprecated in v10
// AuthenticateMessage = 3,
AuthenticateMessageExported = frc42_dispatch::method_hash!("AuthenticateMessage"),
}
11 changes: 11 additions & 0 deletions actors/account/src/v16/state.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright 2019-2022 ChainSafe Systems
// SPDX-License-Identifier: Apache-2.0, MIT

use fvm_ipld_encoding::tuple::*;
use fvm_shared4::address::Address;

/// State includes the address for the actor
#[derive(Serialize_tuple, Deserialize_tuple, Debug, Clone)]
pub struct State {
pub address: Address,
}
29 changes: 29 additions & 0 deletions actors/account/src/v16/types.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use fvm_ipld_encoding::strict_bytes;
use fvm_ipld_encoding::tuple::*;
use fvm_shared4::address::Address;

#[derive(Debug, Serialize_tuple, Deserialize_tuple)]
#[serde(transparent)]
pub struct ConstructorParams {
pub address: Address,
}

#[derive(Debug, Serialize_tuple, Deserialize_tuple)]
#[serde(transparent)]
pub struct PubkeyAddressReturn {
pub address: Address,
}

#[derive(Debug, Serialize_tuple, Deserialize_tuple)]
pub struct AuthenticateMessageParams {
#[serde(with = "strict_bytes")]
pub signature: Vec<u8>,
#[serde(with = "strict_bytes")]
pub message: Vec<u8>,
}

#[derive(Debug, Serialize_tuple, Deserialize_tuple)]
#[serde(transparent)]
pub struct AuthenticateMessageReturn {
pub authenticated: bool,
}
1 change: 1 addition & 0 deletions actors/cron/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ pub mod v12;
pub mod v13;
pub mod v14;
pub mod v15;
pub mod v16;
pub mod v8;
pub mod v9;
27 changes: 27 additions & 0 deletions actors/cron/src/v16/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2019-2022 ChainSafe Systems
// SPDX-License-Identifier: Apache-2.0, MIT

use fvm_ipld_encoding::tuple::*;

use fvm_shared4::METHOD_CONSTRUCTOR;
use num_derive::FromPrimitive;

pub use self::state::{Entry, State};

mod state;

/// Cron actor methods available
#[derive(FromPrimitive)]
#[repr(u64)]
pub enum Method {
Constructor = METHOD_CONSTRUCTOR,
EpochTick = 2,
}

/// Constructor parameters for Cron actor, contains entries
/// of actors and methods to call on each epoch
#[derive(Default, Debug, Serialize_tuple, Deserialize_tuple)]
pub struct ConstructorParams {
/// Entries is a set of actors (and corresponding methods) to call during EpochTick.
pub entries: Vec<Entry>,
}
21 changes: 21 additions & 0 deletions actors/cron/src/v16/state.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright 2019-2022 ChainSafe Systems
// SPDX-License-Identifier: Apache-2.0, MIT

use fvm_ipld_encoding::tuple::*;
use fvm_shared4::address::Address;
use fvm_shared4::MethodNum;

/// Cron actor state which holds entries to call during epoch tick
#[derive(Default, Serialize_tuple, Deserialize_tuple, Clone, Debug)]
pub struct State {
/// Entries is a set of actors (and corresponding methods) to call during EpochTick.
pub entries: Vec<Entry>,
}

#[derive(Clone, PartialEq, Eq, Debug, Serialize_tuple, Deserialize_tuple)]
pub struct Entry {
/// The actor to call (ID address)
pub receiver: Address,
/// The method number to call (must accept empty parameters)
pub method_num: MethodNum,
}
1 change: 1 addition & 0 deletions actors/datacap/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ keywords.workspace = true

[dependencies]
fil_actors_shared = { workspace = true }
frc42_dispatch = { workspace = true }
frc42_macros = { workspace = true }
frc46_token = { workspace = true }
fvm_ipld_blockstore = { workspace = true }
Expand Down
1 change: 1 addition & 0 deletions actors/datacap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ pub mod v12;
pub mod v13;
pub mod v14;
pub mod v15;
pub mod v16;
pub mod v9;
63 changes: 63 additions & 0 deletions actors/datacap/src/v16/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright 2019-2022 ChainSafe Systems
// SPDX-License-Identifier: Apache-2.0, MIT

use frc46_token::token::TOKEN_PRECISION;
use fvm_shared4::bigint::BigInt;
use fvm_shared4::econ::TokenAmount;
use fvm_shared4::METHOD_CONSTRUCTOR;
use lazy_static::lazy_static;
use num_derive::FromPrimitive;

pub use self::state::State;
pub use self::types::*;

mod state;
mod types;

pub const DATACAP_GRANULARITY: u64 = TOKEN_PRECISION;

lazy_static! {
// > 800 EiB
pub static ref INFINITE_ALLOWANCE: TokenAmount = TokenAmount::from_atto(
BigInt::from(TOKEN_PRECISION)
* BigInt::from(1_000_000_000_000_000_000_000_i128)
);
}

/// Datacap actor methods available
#[derive(FromPrimitive)]
#[repr(u64)]
pub enum Method {
Constructor = METHOD_CONSTRUCTOR,
// Deprecated in v10
// Mint = 2,
// Destroy = 3,
// Name = 10,
// Symbol = 11,
// TotalSupply = 12,
// BalanceOf = 13,
// Transfer = 14,
// TransferFrom = 15,
// IncreaseAllowance = 16,
// DecreaseAllowance = 17,
// RevokeAllowance = 18,
// Burn = 19,
// BurnFrom = 20,
// Allowance = 21,
// Method numbers derived from FRC-0042 standards
MintExported = frc42_dispatch::method_hash!("Mint"),
DestroyExported = frc42_dispatch::method_hash!("Destroy"),
NameExported = frc42_dispatch::method_hash!("Name"),
SymbolExported = frc42_dispatch::method_hash!("Symbol"),
GranularityExported = frc42_dispatch::method_hash!("Granularity"),
TotalSupplyExported = frc42_dispatch::method_hash!("TotalSupply"),
BalanceExported = frc42_dispatch::method_hash!("Balance"),
TransferExported = frc42_dispatch::method_hash!("Transfer"),
TransferFromExported = frc42_dispatch::method_hash!("TransferFrom"),
IncreaseAllowanceExported = frc42_dispatch::method_hash!("IncreaseAllowance"),
DecreaseAllowanceExported = frc42_dispatch::method_hash!("DecreaseAllowance"),
RevokeAllowanceExported = frc42_dispatch::method_hash!("RevokeAllowance"),
BurnExported = frc42_dispatch::method_hash!("Burn"),
BurnFromExported = frc42_dispatch::method_hash!("BurnFrom"),
AllowanceExported = frc42_dispatch::method_hash!("Allowance"),
}
37 changes: 37 additions & 0 deletions actors/datacap/src/v16/state.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use frc46_token::token;
use fvm_ipld_blockstore::Blockstore;
use fvm_ipld_encoding::tuple::*;
use fvm_shared4::address::Address;
use fvm_shared4::econ::TokenAmount;
use fvm_shared4::error::ExitCode;
use fvm_shared4::ActorID;

use fil_actors_shared::v16::{ActorError, AsActorError};

#[derive(Debug, Serialize_tuple, Deserialize_tuple)]
pub struct State {
pub governor: Address,
pub token: token::state::TokenState,
}

impl State {
pub fn new<BS: Blockstore>(store: &BS, governor: Address) -> Result<State, ActorError> {
let token_state = token::state::TokenState::new(store)
.context_code(ExitCode::USR_ILLEGAL_STATE, "failed to create token state")?;
Ok(State {
governor,
token: token_state,
})
}

// Visible for testing
pub fn balance<BS: Blockstore>(
&self,
bs: &BS,
owner: ActorID,
) -> Result<TokenAmount, ActorError> {
self.token
.get_balance(bs, owner)
.context_code(ExitCode::USR_ILLEGAL_STATE, "failed to get balance")
}
}
85 changes: 85 additions & 0 deletions actors/datacap/src/v16/types.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
use fvm_ipld_encoding::tuple::*;
use fvm_shared4::address::Address;
use fvm_shared4::econ::TokenAmount;

#[derive(Clone, Debug, PartialEq, Eq, Serialize_tuple, Deserialize_tuple)]
#[serde(transparent)]
pub struct ConstructorParams {
pub governor: Address,
}

#[derive(Clone, Debug, PartialEq, Eq, Serialize_tuple, Deserialize_tuple)]
#[serde(transparent)]
pub struct NameReturn {
pub name: String,
}

#[derive(Clone, Debug, PartialEq, Eq, Serialize_tuple, Deserialize_tuple)]
#[serde(transparent)]
pub struct SymbolReturn {
pub symbol: String,
}

#[derive(Clone, Debug, PartialEq, Eq, Serialize_tuple, Deserialize_tuple)]
#[serde(transparent)]
pub struct TotalSupplyReturn {
pub supply: TokenAmount,
}

#[derive(Clone, Debug, PartialEq, Eq, Serialize_tuple, Deserialize_tuple)]
#[serde(transparent)]
pub struct BalanceParams {
pub address: Address,
}

#[derive(Clone, Debug, PartialEq, Eq, Serialize_tuple, Deserialize_tuple)]
#[serde(transparent)]
pub struct BalanceReturn {
pub balance: TokenAmount,
}

#[derive(Clone, Debug, PartialEq, Eq, Serialize_tuple, Deserialize_tuple)]
#[serde(transparent)]
pub struct GetAllowanceReturn {
pub allowance: TokenAmount,
}

#[derive(Clone, Debug, PartialEq, Eq, Serialize_tuple, Deserialize_tuple)]
#[serde(transparent)]
pub struct IncreaseAllowanceReturn {
pub new_allowance: TokenAmount,
}

#[derive(Clone, Debug, PartialEq, Eq, Serialize_tuple, Deserialize_tuple)]
#[serde(transparent)]
pub struct DecreaseAllowanceReturn {
pub new_allowance: TokenAmount,
}

#[derive(Clone, Debug, PartialEq, Eq, Serialize_tuple, Deserialize_tuple)]
#[serde(transparent)]
pub struct RevokeAllowanceReturn {
pub old_allowance: TokenAmount,
}

#[derive(Clone, Debug, PartialEq, Eq, Serialize_tuple, Deserialize_tuple)]
pub struct MintParams {
// Recipient of the newly minted tokens.
pub to: Address,
// Amount of tokens to mint.
pub amount: TokenAmount,
// Addresses to be granted effectively-infinite operator allowance for the recipient.
pub operators: Vec<Address>,
}

#[derive(Clone, Debug, PartialEq, Eq, Serialize_tuple, Deserialize_tuple)]
pub struct DestroyParams {
pub owner: Address,
pub amount: TokenAmount,
}

#[derive(Clone, Debug, PartialEq, Eq, Serialize_tuple, Deserialize_tuple)]
#[serde(transparent)]
pub struct GranularityReturn {
pub granularity: u64,
}
1 change: 1 addition & 0 deletions actors/eam/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ pub mod v12;
pub mod v13;
pub mod v14;
pub mod v15;
pub mod v16;
Loading

0 comments on commit f1d88b4

Please sign in to comment.