staking

package
v0.8.5 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MasaTokenABIPath       = "node_modules/@masa-finance/masa-token/deployments/sepolia/MasaToken.json"
	MasaFaucetABIPath      = "node_modules/@masa-finance/masa-contracts-oracle/artifacts/contracts/MasaFaucet.sol/MasaFaucet.json"
	ProtocolStakingABIPath = "node_modules/@masa-finance/masa-contracts-oracle/artifacts/contracts/ProtocolStaking.sol/ProtocolStaking.json"
)

Variables

View Source
var MasaTokenAddress common.Address
View Source
var ProtocolStakingContractAddress 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 ProtocolStaking 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 ProtocolStakingContractAddress. 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) RunFaucet

func (sc *Client) RunFaucet() (string, error)

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 {
		MasaFaucet      string `json:"MasaFaucet"`
		MasaToken       string `json:"MasaToken"`
		ProtocolStaking string `json:"ProtocolStaking"`
	} `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