Skip to content

Commit

Permalink
refactor: allow paymentVault not deployed
Browse files Browse the repository at this point in the history
  • Loading branch information
hopeyen committed Dec 13, 2024
1 parent cd399d4 commit 4eff180
Showing 1 changed file with 36 additions and 6 deletions.
42 changes: 36 additions & 6 deletions core/eth/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,16 +210,19 @@ func (t *Reader) updateContractBindings(blsOperatorStateRetrieverAddr, eigenDASe
}
}

var contractPaymentVault *paymentvault.ContractPaymentVault
paymentVaultAddr, err := contractEigenDAServiceManager.PaymentVault(&bind.CallOpts{})
if err != nil {
t.logger.Error("Failed to fetch PaymentVault address", "err", err)
return err
}
//TODO(hopeyen): return err when the contract is deployed
// return err
} else {
contractPaymentVault, err = paymentvault.NewContractPaymentVault(paymentVaultAddr, t.ethClient)
if err != nil {
t.logger.Error("Failed to fetch PaymentVault contract", "err", err)
return err
}

contractPaymentVault, err := paymentvault.NewContractPaymentVault(paymentVaultAddr, t.ethClient)
if err != nil {
t.logger.Error("Failed to fetch PaymentVault contract", "err", err)
return err
}

t.bindings = &ContractBindings{
Expand Down Expand Up @@ -703,6 +706,9 @@ func (t *Reader) GetAllVersionedBlobParams(ctx context.Context) (map[uint16]*cor
}

func (t *Reader) GetReservedPayments(ctx context.Context, accountIDs []gethcommon.Address) (map[gethcommon.Address]*core.ReservedPayment, error) {
if t.bindings.PaymentVault == nil {
return nil, errors.New("payment vault not deployed")
}
reservationsMap := make(map[gethcommon.Address]*core.ReservedPayment)
reservations, err := t.bindings.PaymentVault.GetReservations(&bind.CallOpts{
Context: ctx,
Expand All @@ -726,6 +732,9 @@ func (t *Reader) GetReservedPayments(ctx context.Context, accountIDs []gethcommo
}

func (t *Reader) GetReservedPaymentByAccount(ctx context.Context, accountID gethcommon.Address) (*core.ReservedPayment, error) {
if t.bindings.PaymentVault == nil {
return nil, errors.New("payment vault not deployed")
}
reservation, err := t.bindings.PaymentVault.GetReservation(&bind.CallOpts{
Context: ctx,
}, accountID)
Expand All @@ -736,6 +745,9 @@ func (t *Reader) GetReservedPaymentByAccount(ctx context.Context, accountID geth
}

func (t *Reader) GetOnDemandPayments(ctx context.Context, accountIDs []gethcommon.Address) (map[gethcommon.Address]*core.OnDemandPayment, error) {
if t.bindings.PaymentVault == nil {
return nil, errors.New("payment vault not deployed")
}
paymentsMap := make(map[gethcommon.Address]*core.OnDemandPayment)
payments, err := t.bindings.PaymentVault.GetOnDemandTotalDeposits(&bind.CallOpts{
Context: ctx}, accountIDs)
Expand All @@ -758,6 +770,9 @@ func (t *Reader) GetOnDemandPayments(ctx context.Context, accountIDs []gethcommo
}

func (t *Reader) GetOnDemandPaymentByAccount(ctx context.Context, accountID gethcommon.Address) (*core.OnDemandPayment, error) {
if t.bindings.PaymentVault == nil {
return nil, errors.New("payment vault not deployed")
}
onDemandPayment, err := t.bindings.PaymentVault.GetOnDemandTotalDeposit(&bind.CallOpts{
Context: ctx,
}, accountID)
Expand All @@ -773,6 +788,9 @@ func (t *Reader) GetOnDemandPaymentByAccount(ctx context.Context, accountID geth
}

func (t *Reader) GetGlobalSymbolsPerSecond(ctx context.Context) (uint64, error) {
if t.bindings.PaymentVault == nil {
return 0, errors.New("payment vault not deployed")
}
globalSymbolsPerSecond, err := t.bindings.PaymentVault.GlobalRatePeriodInterval(&bind.CallOpts{
Context: ctx,
})
Expand All @@ -783,6 +801,9 @@ func (t *Reader) GetGlobalSymbolsPerSecond(ctx context.Context) (uint64, error)
}

func (t *Reader) GetGlobalRatePeriodInterval(ctx context.Context) (uint32, error) {
if t.bindings.PaymentVault == nil {
return 0, errors.New("payment vault not deployed")
}
globalRateBinInterval, err := t.bindings.PaymentVault.GlobalRatePeriodInterval(&bind.CallOpts{
Context: ctx,
})
Expand All @@ -792,6 +813,9 @@ func (t *Reader) GetGlobalRatePeriodInterval(ctx context.Context) (uint32, error
return uint32(globalRateBinInterval), nil
}
func (t *Reader) GetMinNumSymbols(ctx context.Context) (uint32, error) {
if t.bindings.PaymentVault == nil {
return 0, errors.New("payment vault not deployed")
}
minNumSymbols, err := t.bindings.PaymentVault.MinNumSymbols(&bind.CallOpts{
Context: ctx,
})
Expand All @@ -802,6 +826,9 @@ func (t *Reader) GetMinNumSymbols(ctx context.Context) (uint32, error) {
}

func (t *Reader) GetPricePerSymbol(ctx context.Context) (uint32, error) {
if t.bindings.PaymentVault == nil {
return 0, errors.New("payment vault not deployed")
}
pricePerSymbol, err := t.bindings.PaymentVault.PricePerSymbol(&bind.CallOpts{
Context: ctx,
})
Expand All @@ -812,6 +839,9 @@ func (t *Reader) GetPricePerSymbol(ctx context.Context) (uint32, error) {
}

func (t *Reader) GetReservationWindow(ctx context.Context) (uint32, error) {
if t.bindings.PaymentVault == nil {
return 0, errors.New("payment vault not deployed")
}
reservationWindow, err := t.bindings.PaymentVault.ReservationPeriodInterval(&bind.CallOpts{
Context: ctx})
if err != nil {
Expand Down

0 comments on commit 4eff180

Please sign in to comment.