cic-go/cic_net/erc20_demurrage_token.go

80 lines
2.7 KiB
Go
Raw Normal View History

2022-05-06 13:19:44 +02:00
package cic_net
import (
"context"
"github.com/ethereum/go-ethereum/common"
"github.com/lmittmann/w3"
"github.com/lmittmann/w3/module/eth"
"math/big"
)
type DemurrageTokenInfo struct {
DemurrageAmount big.Int
DemurrageTimestamp big.Int
MinimumParticipantSpend big.Int
ResolutionFactor big.Int
PeriodStart big.Int
PeriodDuration big.Int
TaxLevel big.Int
ActualPeriod big.Int
RedistributionCount big.Int
IsDemurrageToken bool
2022-05-06 13:19:44 +02:00
}
func (c *CicNet) DemurrageTokenInfo(ctx context.Context, tokenAddress common.Address) (DemurrageTokenInfo, error) {
2022-05-06 13:19:44 +02:00
var (
demurrageAmount big.Int
demurrageTimestamp big.Int
minimumParticipantSpend big.Int
resolutionFactor big.Int
periodStart big.Int
periodDuration big.Int
taxLevel big.Int
actualPeriod big.Int
redistributionCount big.Int
2022-05-06 13:19:44 +02:00
)
err := c.ethClient.CallCtx(
ctx,
eth.CallFunc(w3.MustNewFunc("demurrageAmount()", "uint128"), tokenAddress).Returns(&demurrageAmount),
eth.CallFunc(w3.MustNewFunc("demurrageTimestamp()", "uint256"), tokenAddress).Returns(&demurrageTimestamp),
eth.CallFunc(w3.MustNewFunc("minimumParticipantSpend()", "uint256"), tokenAddress).Returns(&minimumParticipantSpend),
eth.CallFunc(w3.MustNewFunc("resolutionFactor()", "uint256"), tokenAddress).Returns(&resolutionFactor),
eth.CallFunc(w3.MustNewFunc("periodStart()", "uint256"), tokenAddress).Returns(&periodStart),
eth.CallFunc(w3.MustNewFunc("periodDuration()", "uint256"), tokenAddress).Returns(&periodDuration),
eth.CallFunc(w3.MustNewFunc("taxLevel()", "uint256"), tokenAddress).Returns(&taxLevel),
eth.CallFunc(w3.MustNewFunc("actualPeriod()", "uint256"), tokenAddress).Returns(&actualPeriod),
eth.CallFunc(w3.MustNewFunc("redistributionCount()", "uint256"), tokenAddress).Returns(&redistributionCount),
2022-05-06 13:19:44 +02:00
)
2022-05-06 13:19:44 +02:00
if err != nil {
return DemurrageTokenInfo{}, err
2022-05-06 13:19:44 +02:00
}
return DemurrageTokenInfo{
DemurrageAmount: demurrageAmount,
DemurrageTimestamp: demurrageTimestamp,
MinimumParticipantSpend: minimumParticipantSpend,
ResolutionFactor: resolutionFactor,
PeriodStart: periodStart,
PeriodDuration: periodDuration,
TaxLevel: taxLevel,
ActualPeriod: actualPeriod,
RedistributionCount: redistributionCount,
2022-05-06 13:19:44 +02:00
}, nil
}
func (c *CicNet) BaseBalanceOf(ctx context.Context, tokenAddress common.Address, accountAddress common.Address) (big.Int, error) {
var balance big.Int
err := c.ethClient.CallCtx(
ctx,
eth.CallFunc(w3.MustNewFunc("baseBalanceOf(address _account)", "uint256"), tokenAddress, accountAddress).Returns(&balance),
)
if err != nil {
return big.Int{}, err
}
return balance, nil
}