staking

package
v0.0.11-alpha Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MasaTokenABIPath         = "contracts/node_modules/@masa-finance/masa-contracts-oracle/artifacts/contracts/MasaToken.sol/MasaToken.json"
	NodeDataMetricsABIPath   = "contracts/node_modules/@masa-finance/masa-contracts-oracle/artifacts/contracts/NodeDataMetrics.sol/NodeDataMetrics.json"
	NodeRewardPoolABIPath    = "contracts/node_modules/@masa-finance/masa-contracts-oracle/artifacts/contracts/NodeRewardPool.sol/NodeRewardPool.json"
	OracleNodeStakingABIPath = "contracts/node_modules/@masa-finance/masa-contracts-oracle/artifacts/contracts/OracleNodeStaking.sol/OracleNodeStaking.json"
	StakedMasaTokenABIPath   = "contracts/node_modules/@masa-finance/masa-contracts-oracle/artifacts/contracts/StakedMasaToken.sol/StakedMasaToken.json"
)

Variables

View Source
var MasaTokenAddress common.Address
View Source
var OracleNodeStakingContractAddress common.Address

Functions

func GetABI

func GetABI(jsonPath string) (abi.ABI, error)

GetABI parses the ABI from the given JSON file path. It returns the parsed ABI, or an error if reading or parsing fails.

func VerifyStakingEvent

func VerifyStakingEvent(userAddress string) (bool, error)

VerifyStakingEvent checks if the given user address has staked tokens by calling the stakes() view function on the OracleNodeStaking contract. It connects to an Ethereum node, encodes the stakes call, calls the contract, unpacks the result, and returns true if the stakes amount is > 0.

Types

type Client

type Client struct {
	EthClient  *ethclient.Client
	PrivateKey *ecdsa.PrivateKey
}

func NewClient

func NewClient(privateKey *ecdsa.PrivateKey) (*Client, error)

NewClient initializes a new Client instance with the provided private key. It loads the contract addresses, initializes an Ethereum client, and returns a Client instance.

func (*Client) Approve

func (sc *Client) Approve(amount *big.Int) (string, error)

Approve approves the specified amount of MASA tokens for transfer from the caller's account to the OracleNodeStakingContractAddress. It constructs an Ethereum transaction with the approve call, signs it, sends it to the network, waits for confirmation, and returns the transaction hash if successful.

func (*Client) Stake

func (sc *Client) Stake(amount *big.Int) (string, error)

Stake stakes the given amount of tokens from the client's account. It retrieves the network ID, creates a transactor, binds the staking contract instance, sends the stake transaction, waits for it to be mined, and returns the transaction hash if successful. Returns any errors.

type ContractAddresses

type ContractAddresses struct {
	Sepolia struct {
		MasaToken         string `json:"MasaToken"`
		NodeDataMetrics   string `json:"NodeDataMetrics"`
		NodeRewardPool    string `json:"NodeRewardPool"`
		OracleNodeStaking string `json:"OracleNodeStaking"`
		StakedMasaToken   string `json:"StakedMasaToken"`
	} `json:"sepolia"`
}

func LoadContractAddresses

func LoadContractAddresses() (*ContractAddresses, error)

LoadContractAddresses loads the contract addresses from the addresses.json file. It returns a ContractAddresses struct containing the loaded addresses.

Jump to

Keyboard shortcuts

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