econ

package
v1.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 4, 2024 License: Apache-2.0 Imports: 26 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var INITIAL_PLEDGE_INTERPOLATION_REL_DIFF = big.NewFloat(3.00) // 3%
View Source
var MAX_SAMPLED_SECTORS = 1000

Functions

func AllSectors added in v1.1.0

func AllSectors(ctx context.Context, api *lotusapi.FullNodeStruct, minerAddr address.Address, ts *types.TipSet) ([]uint64, error)

func ComputeAgentData

func ComputeAgentData(
	ctx context.Context,
	agentAddr common.Address,

	agentBalDelta *big.Int,
	principal *big.Int,

	rmMiner address.Address,
	sdk poolstypes.PoolsSDK,
	tsk *types.TipSet,
) (*vc.AgentData, error)

TODO https://github.com/glif-confidential/ado/issues/9 note that this function is supposed to implement a post action credential in some cases, it's incomplete example 1 - pay - if the amount should reduce principal, principal in the credential is not updated - V2 pools does not use principal in the cred anyways example 2 - add miner - there are no cred checks on adding miner

func ComputeBorrowAgentData added in v1.1.0

func ComputeBorrowAgentData(ctx context.Context, agentAddr common.Address, amount *big.Int, psdk pooltypes.PoolsSDK, ts *types.TipSet) (*vc.AgentData, error)

func ComputeEDR added in v1.1.0

func ComputeEDR(ctx context.Context, minerAddr address.Address, ts *types.TipSet, api *api.FullNodeStruct) (*big.Int, error)

func ComputePayAgentData added in v1.1.0

func ComputePayAgentData(ctx context.Context, agentAddr common.Address, value *big.Int, psdk pooltypes.PoolsSDK, ts *types.TipSet) (*vc.AgentData, error)

func ComputePushFundsAgentData added in v1.1.0

func ComputePushFundsAgentData(ctx context.Context, agentAddr common.Address, minerAddr address.Address, psdk pooltypes.PoolsSDK, ts *types.TipSet) (*vc.AgentData, error)

func ComputeRmMinerAgentData added in v1.1.0

func ComputeRmMinerAgentData(ctx context.Context, agentAddr common.Address, miner address.Address, psdk pooltypes.PoolsSDK, ts *types.TipSet) (*vc.AgentData, error)

func ComputeWithdrawAgentData added in v1.1.0

func ComputeWithdrawAgentData(ctx context.Context, agentAddr common.Address, withdrawAmount *big.Int, psdk pooltypes.PoolsSDK, ts *types.TipSet) (*vc.AgentData, error)

func GetAgentEcon added in v1.1.0

func GetAgentEcon(ctx context.Context, agentAddr common.Address, psdk pooltypes.PoolsSDK, ts *types.TipSet) (*big.Int, *big.Int, error)

func InterestOwed

func InterestOwed(ctx context.Context, account abigen.Account, rate *big.Int, chainHeadHeight abi.ChainEpoch) *big.Int

@dev rates have 2 WADs worth of precision (1e36) to maintain per epoch rate precision

func SampleSectors added in v1.1.0

func SampleSectors(sectors []uint64, samples int) []uint64

Types

type AgentFi added in v1.1.0

type AgentFi struct {
	BaseFi
	Liability
	// represents the amount of FIL and WFIL that is held by the Agent's smart contract
	SpendableBalance *big.Int `json:"spendableBalance"`
}

func EmptyAgentFi added in v1.1.0

func EmptyAgentFi() *AgentFi

func EstimateTerminationFeeAgent added in v1.1.0

func EstimateTerminationFeeAgent(
	ctx context.Context,
	agentAddr common.Address,
	withoutMiner address.Address,
	psdk poolstypes.PoolsSDK,
	tsk *types.TipSet,
) (*AgentFi, error)

func GetAgentFiFromAPI added in v1.1.0

func GetAgentFiFromAPI(agentAddr common.Address, eventsURL string) (*AgentFi, error)

func NewAgentFi added in v1.1.0

func NewAgentFi(
	agentAvailableBalance *big.Int,
	liability Liability,
	minerFis []*BaseFi,
) *AgentFi

func (*AgentFi) BorrowLimit added in v1.1.0

func (afi *AgentFi) BorrowLimit() *big.Int

func (*AgentFi) DTL added in v1.1.0

func (afi *AgentFi) DTL() *big.Float

func (*AgentFi) LeverageRatio added in v1.1.0

func (afi *AgentFi) LeverageRatio() *big.Float

leverage ratio = liquidation value / margin

func (*AgentFi) Margin added in v1.1.0

func (afi *AgentFi) Margin() *big.Int

margin = liquidation value - principal

func (*AgentFi) MarginCall added in v1.1.0

func (afi *AgentFi) MarginCall() *big.Int

func (*AgentFi) MaxBorrowAndSeal added in v1.1.0

func (afi *AgentFi) MaxBorrowAndSeal() *big.Int

MaxBorrowAndSeal = margin / (1 - max borrow DTL) - margin

func (*AgentFi) MaxBorrowAndWithdraw added in v1.1.0

func (afi *AgentFi) MaxBorrowAndWithdraw() *big.Int

MaxBorrowAndWithdraw = margin - lv * (1 - max borrow DTL)

func (*AgentFi) WithdrawLimit added in v1.1.0

func (afi *AgentFi) WithdrawLimit() *big.Int

type AgentInfo added in v1.1.0

type AgentInfo struct {
	TxHash        string         `json:"txHash"`
	Height        uint64         `json:"height"`
	Id            uint64         `json:"id"`
	Address       string         `json:"address"`
	AddressNative common.Address `json:"addressNative"`
	// BALANCE DEPRECATED
	Balance          string `json:"balance"`
	Miners           uint64 `json:"miners"`
	AvailableBalance string `json:"availableBalance"`
	PrincipalBalance string `json:"principalBalance"`
}

type AgentMarginJSON added in v1.1.0

type AgentMarginJSON struct {
	AgentId                uint64  `json:"agentId"`
	Balance                string  `json:"balance"`
	SpendableBalance       string  `json:"spendableBalance"`
	AvailableBalance       string  `json:"availableBalance"`
	LockedRewards          string  `json:"lockedRewards"`
	FeeDebt                string  `json:"feeDebt"`
	InitialPledge          string  `json:"initialPledge"`
	TerminationFee         string  `json:"terminationFee"`
	LiquidationValue       string  `json:"liquidationValue"`
	Margin                 string  `json:"margin"`
	MarginCall             string  `json:"marginCall"`
	Principal              string  `json:"principal"`
	Interest               string  `json:"interest"`
	DTL                    float64 `json:"dtl"`
	LeverageRatio          float64 `json:"leverageRatio"`
	BorrowLimit            string  `json:"borrowLimit"`
	BorrowAndWithdrawLimit string  `json:"borrowAndWithdrawLimit"`
	WithdrawLimit          string  `json:"withdrawLimit"`
	LiveSectors            string  `json:"liveSectors"`
	FaultySectors          string  `json:"faultySectors"`
}

type BaseFi added in v1.1.0

type BaseFi struct {
	// total balance of the miner (and in the case of an Agent, includes Agent balance and locked FIL)
	Balance *big.Int `json:"balance"`
	// liquid FIL on the miner (and in the case of an Agent, includes Agent available balance, does not account for any fee debt)
	AvailableBalance *big.Int `json:"availableBalance"`
	LockedRewards    *big.Int `json:"lockedRewards"`
	InitialPledge    *big.Int `json:"initialPledge"`
	FeeDebt          *big.Int `json:"feeDebt"`
	TerminationFee   *big.Int `json:"terminationFee"`

	LiveSectors   *big.Int `json:"liveSectors"`
	FaultySectors *big.Int `json:"faultySectors"`
}

func EmptyBaseFi added in v1.1.0

func EmptyBaseFi() *BaseFi

func GetBaseFisFromAPI added in v1.1.0

func GetBaseFisFromAPI(agentAddr common.Address, eventsURL string) (miners []address.Address, baseFis []*BaseFi, err error)

func NewBaseFi added in v1.1.0

func NewBaseFi(
	balance *big.Int,
	availableBalance *big.Int,
	lockedRewards *big.Int,
	initialPledge *big.Int,
	feeDebt *big.Int,
	terminationFee *big.Int,
	liveSectors *big.Int,
	faultySectors *big.Int,
) *BaseFi

func (*BaseFi) LiquidationValue added in v1.1.0

func (bfi *BaseFi) LiquidationValue() *big.Int

func (*BaseFi) RecoveryRate added in v1.1.0

func (bfi *BaseFi) RecoveryRate() *big.Float

type Liability added in v1.1.0

type Liability struct {
	Principal *big.Int `json:"principal"`
	Interest  *big.Int `json:"interest"`
}

func (*Liability) Debt added in v1.1.0

func (l *Liability) Debt() *big.Int

type MinerDetailsJSON added in v1.1.0

type MinerDetailsJSON struct {
	Miner                  uint64          `json:"miner"`
	AgentId                uint64          `json:"agentId"`
	Actions                uint16          `json:"actions"`
	MinerAddr              address.Address `json:"minerAddr"`
	AvailableBalance       string          `json:"availableBalance"`
	InitialPledge          string          `json:"initialPledge"`
	LockedRewards          string          `json:"lockedRewards"`
	FeeDebt                string          `json:"feeDebt"`
	Balance                string          `json:"balance"`
	EstimatedWeeklyRewards string          `json:"estimatedWeeklyRewards"`
	QAP                    string          `json:"qap"`
	RBP                    string          `json:"rbp"`
	LiveSectors            string          `json:"liveSectors"`
	FaultySectors          string          `json:"faultySectors"`
	RecoveringSectors      string          `json:"recoveringSectors"`
	Ratio                  string          `json:"ratio"`
	TerminationFee         string          `json:"terminationFee"`
	LiquidationValue       string          `json:"liquidationValue"`
}

type MinerFi added in v1.1.0

type MinerFi struct {
	BaseFi
}

func EmptyMinerFi added in v1.1.0

func EmptyMinerFi() *MinerFi

func NewMinerFi added in v1.1.0

func NewMinerFi(
	balance *big.Int,
	availableBalance *big.Int,
	lockedRewards *big.Int,
	initialPledge *big.Int,
	feeDebt *big.Int,
	terminationFee *big.Int,
	liveSectors *big.Int,
	faultySectors *big.Int,
) *MinerFi

func (*MinerFi) MaxBorrowAndSeal added in v1.1.0

func (mfi *MinerFi) MaxBorrowAndSeal() *big.Int

func (*MinerFi) MaxBorrowAndWithdraw added in v1.1.0

func (mfi *MinerFi) MaxBorrowAndWithdraw() *big.Int

type TerminateSectorResult added in v1.1.0

type TerminateSectorResult struct {
	TotalBalance     *big.Int
	AvailableBalance *big.Int
	VestingFunds     *big.Int
	InitialPledge    *big.Int
	FeeDebt          *big.Int

	EstimatedInitialPledge    *big.Int
	InitialPledgeFromSample   *big.Int
	AvgInitialPledgePerSector *big.Int

	EstimatedTerminationFee    *big.Int
	TerminationFeeFromSample   *big.Int
	AvgTerminationFeePerPledge *big.Int

	SampledSectors uint64
	LiveSectors    uint64
	FaultySectors  uint64
}

note that in feeDebt, AvailableBalance will be kept at 0, and feeDebt will be a positive number lotus actually returns a negative number for availableBalance, but we scrap that and return 0

func EstimateTerminationFeeMiner added in v1.1.0

func EstimateTerminationFeeMiner(ctx context.Context, api *lotusapi.FullNodeStruct, minerAddr address.Address, ts *types.TipSet) (*TerminateSectorResult, error)

func TerminateSectors added in v1.1.0

func TerminateSectors(ctx context.Context, api *lotusapi.FullNodeStruct, minerAddr address.Address, sectors *bitfield.BitField, ts *types.TipSet) (*TerminateSectorResult, error)

func (*TerminateSectorResult) ToBaseFi added in v1.1.0

func (termRes *TerminateSectorResult) ToBaseFi() *BaseFi

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL