@@ -964,6 +964,78 @@ func (msa *minerStateAPI) StateMinerInitialPledgeForSector(ctx context.Context,
964964 return types .BigDiv (types .BigMul (initialPledge , initialPledgeNum ), initialPledgeDen ), nil
965965}
966966
967+ func (msa * minerStateAPI ) StateMinerCreationDeposit (ctx context.Context , tsk types.TipSetKey ) (types.BigInt , error ) {
968+ // Reference implementation: https://github.com/filecoin-project/builtin-actors/blob/00db828d09c3dfb61fe768ff6a19416a313444bd/actors/miner/src/lib.rs#L5264-L5279
969+ nv , err := msa .ChainSubmodule .API ().StateNetworkVersion (ctx , tsk )
970+ if err != nil {
971+ return types .EmptyInt , fmt .Errorf ("getting network version: %w" , err )
972+ }
973+
974+ if nv < network .Version27 {
975+ return big .Zero (), nil
976+ }
977+
978+ // Get current chain head
979+ ts , err := msa .ChainReader .GetTipSet (ctx , tsk )
980+ if err != nil {
981+ return types .EmptyInt , fmt .Errorf ("loading tipset %s: %w" , tsk , err )
982+ }
983+
984+ _ , state , err := msa .ChainSubmodule .Stmgr .ParentState (ctx , ts )
985+ if err != nil {
986+ return types .EmptyInt , fmt .Errorf ("loading state %s: %w" , tsk , err )
987+ }
988+
989+ rewardActor , found , err := state .GetActor (ctx , reward .Address )
990+ if err != nil {
991+ return types .EmptyInt , fmt .Errorf ("loading reward actor: %w" , err )
992+ }
993+ if ! found {
994+ return types .EmptyInt , errors .New ("not found reward" )
995+ }
996+
997+ rewardState , err := reward .Load (msa .ChainReader .Store (ctx ), rewardActor )
998+ if err != nil {
999+ return types .EmptyInt , fmt .Errorf ("loading reward actor state: %w" , err )
1000+ }
1001+
1002+ circSupply , err := msa .StateVMCirculatingSupplyInternal (ctx , ts .Key ())
1003+ if err != nil {
1004+ return types .EmptyInt , fmt .Errorf ("getting circulating supply: %w" , err )
1005+ }
1006+
1007+ pledgeCollateral , powerSmoothed , err := msa .pledgeCalculationInputs (ctx , state )
1008+ if err != nil {
1009+ return types .EmptyInt , err
1010+ }
1011+
1012+ // Get network parameters to obtain ConsensusMinerMinPower
1013+ networkParams , err := msa .ChainSubmodule .API ().StateGetNetworkParams (ctx )
1014+ if err != nil {
1015+ return types .EmptyInt , fmt .Errorf ("getting network params: %w" , err )
1016+ }
1017+ createMinerDepositPower := big .Div (networkParams .ConsensusMinerMinPower , big .NewInt (10 ))
1018+
1019+ epochsSinceRampStart , rampDurationEpochs , err := msa .getPledgeRampParams (ctx , ts .Height (), state )
1020+ if err != nil {
1021+ return types .EmptyInt , fmt .Errorf ("getting pledge ramp params: %w" , err )
1022+ }
1023+
1024+ deposit , err := rewardState .InitialPledgeForPower (
1025+ createMinerDepositPower ,
1026+ pledgeCollateral ,
1027+ powerSmoothed ,
1028+ circSupply .FilCirculating ,
1029+ epochsSinceRampStart ,
1030+ rampDurationEpochs ,
1031+ )
1032+ if err != nil {
1033+ return types .EmptyInt , fmt .Errorf ("calculating initial pledge for power: %w" , err )
1034+ }
1035+
1036+ return deposit , nil
1037+ }
1038+
9671039// StateVMCirculatingSupplyInternal returns an approximation of the circulating supply of Filecoin at the given tipset.
9681040// This is the value reported by the runtime interface to actors code.
9691041func (msa * minerStateAPI ) StateVMCirculatingSupplyInternal (ctx context.Context , tsk types.TipSetKey ) (types.CirculatingSupply , error ) {
0 commit comments