model

package
v0.0.0-...-6a97216 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2023 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

Functions

func DbConnect

func DbConnect() (*sqlx.DB, error)

Types

type Account

type Account struct {
	ID      int        `json:"id"`
	Address string     `json:"address"`
	Events  []AnyEvent `json:"events"`
}

type AccountStore

type AccountStore struct {
	// contains filtered or unexported fields
}

func NewAccountStore

func NewAccountStore(db *sqlx.DB) *AccountStore

func (*AccountStore) All

func (s *AccountStore) All() ([]*Account, error)

func (*AccountStore) CreateAccount

func (s *AccountStore) CreateAccount(address string) (*Account, error)

func (*AccountStore) FindByAddress

func (s *AccountStore) FindByAddress(address string) (*Account, error)

func (*AccountStore) FindById

func (s *AccountStore) FindById(id int) (*Account, error)

func (*AccountStore) FindOrCreateByAddress

func (s *AccountStore) FindOrCreateByAddress(address string) (*Account, error)

type AllEvent

type AllEvent struct {
	// Common
	ID                 int
	Type               EventType
	ProtocolInstanceId int
	EventDefinitionId  int
	Txhash             string
	Blocknumber        int
	Index              int
	OccuredAt          time.Time

	// Borrow
	DepositorAccountId *int
	AmountDeposited    *int
	DepositTokenId     *int

	// Borrow
	BorrowerAccountId *int
	AmountBorrowed    *int
	BorrowTokenId     *int

	// Repay
	RepayerAccountId *int
	AmountRepayed    *int
	RepayTokenId     *int

	// Liquidation
	LiquidatorAccountId *int
	AmountSeized        *int
	CollateralTokenId   *int
	DebtTokenId         *int
}

func (AllEvent) AnyEvent

func (e AllEvent) AnyEvent(accountStore *AccountStore, tokenStore *TokenStore) (AnyEvent, error)

type AnyEvent

type AnyEvent interface {
	IsAnyEvent()
}

type BorrowEvent

type BorrowEvent struct {
	ID             int       `json:"id"`
	Type           EventType `json:"type"`
	Txhash         string    `json:"txhash"`
	Blocknumber    int       `json:"blocknumber"`
	Index          int       `json:"index"`
	OccuredAt      time.Time `json:"occuredAt"`
	Borrower       *Account  `json:"borrower"`
	AmountBorrowed int       `json:"amountBorrowed"`
	Token          *Token    `json:"token"`
}

func (BorrowEvent) IsAnyEvent

func (BorrowEvent) IsAnyEvent()

func (BorrowEvent) IsEvent

func (BorrowEvent) IsEvent()

type Chain

type Chain struct {
	ID             int         `json:"id"`
	Name           string      `json:"name"`
	RPCURL         string      `json:"rpcUrl"`
	BlockFetchSize int         `json:"blockFetchSize"`
	Protocols      []*Protocol `json:"protocols"`
	Tokens         []*Token    `json:"tokens"`
}

func (Chain) EthClient

func (c Chain) EthClient() (*ethclient.Client, error)

type ChainStore

type ChainStore struct {
	// contains filtered or unexported fields
}

func NewChainStore

func NewChainStore(db *sqlx.DB) *ChainStore

func (*ChainStore) All

func (s *ChainStore) All() ([]*Chain, error)

func (*ChainStore) CreateChain

func (s *ChainStore) CreateChain(input NewChain) (*Chain, error)

func (*ChainStore) DeleteByName

func (s *ChainStore) DeleteByName(name string) error

func (*ChainStore) FindById

func (s *ChainStore) FindById(id int) (*Chain, error)

func (*ChainStore) FindByName

func (s *ChainStore) FindByName(name string) (*Chain, error)

type DepositEvent

type DepositEvent struct {
	ID              int       `json:"id"`
	Type            EventType `json:"type"`
	Txhash          string    `json:"txhash"`
	Blocknumber     int       `json:"blocknumber"`
	Index           int       `json:"index"`
	OccuredAt       time.Time `json:"occuredAt"`
	Depositor       *Account  `json:"depositor"`
	AmountDeposited int       `json:"amountDeposited"`
	Token           *Token    `json:"token"`
}

func (DepositEvent) IsAnyEvent

func (DepositEvent) IsAnyEvent()

func (DepositEvent) IsEvent

func (DepositEvent) IsEvent()

type Event

type Event interface {
	IsEvent()
}

type EventDefn

type EventDefn struct {
	ID           int    `json:"id"`
	TopicName    string `json:"topicName"`
	TopicHashHex string `json:"topicHashHex"`
	AbiSignature string `json:"abiSignature"`
}

type EventStore

type EventStore struct {
	// contains filtered or unexported fields
}

func NewEventStore

func NewEventStore(db *sqlx.DB) *EventStore

func (*EventStore) AllByAccount

func (s *EventStore) AllByAccount(accountId int) ([]AllEvent, error)

func (*EventStore) StoreBorrowEvent

func (s *EventStore) StoreBorrowEvent(protocolInstanceId int, eventDefinitionId int, txHash string, blockNumber int64, index int, occuredAt time.Time, borrowerId int, borrowAmount *big.Int, borrowTokenId int) (int, error)

func (*EventStore) StoreDepositEvent

func (s *EventStore) StoreDepositEvent(protocolInstanceId int, eventDefinitionId int, txHash string, blockNumber int64, index int, occuredAt time.Time, depositorAccountId int, amountDeposited *big.Int, depositTokenId int) (int, error)

func (*EventStore) StoreLiquidationEvent

func (s *EventStore) StoreLiquidationEvent(protocolInstanceId int, eventDefinitionId int, txHash string, blockNumber int64, index int, occuredAt time.Time, borrowerAccountId int, liquidatorAccountId int, amountRepayed *big.Int, amountSeized *big.Int, debtTokenId int, collateralTokenId int) (int, error)

func (*EventStore) StoreRepayEvent

func (s *EventStore) StoreRepayEvent(protocolInstanceId int, eventDefinitionId int, txHash string, blockNumber int64, index int, occuredAt time.Time, repayerAccountId int, repayAmount *big.Int, repayTokenId int) (int, error)

type EventType

type EventType string
const (
	EventTypeBorrow      EventType = "Borrow"
	EventTypeRepay       EventType = "Repay"
	EventTypeLiquidation EventType = "Liquidation"
	EventTypeDeposit     EventType = "Deposit"
)

func (EventType) IsValid

func (e EventType) IsValid() bool

func (EventType) MarshalGQL

func (e EventType) MarshalGQL(w io.Writer)

func (EventType) String

func (e EventType) String() string

func (*EventType) UnmarshalGQL

func (e *EventType) UnmarshalGQL(v interface{}) error

type LiquidationEvent

type LiquidationEvent struct {
	ID              int       `json:"id"`
	Type            EventType `json:"type"`
	Txhash          string    `json:"txhash"`
	Blocknumber     int       `json:"blocknumber"`
	Index           int       `json:"index"`
	OccuredAt       time.Time `json:"occuredAt"`
	Borrower        *Account  `json:"borrower"`
	Liquidator      *Account  `json:"liquidator"`
	AmountRepayed   int       `json:"amountRepayed"`
	AmountSeized    int       `json:"amountSeized"`
	CollateralToken *Token    `json:"collateralToken"`
	DebtToken       *Token    `json:"debtToken"`
}

func (LiquidationEvent) IsAnyEvent

func (LiquidationEvent) IsAnyEvent()

func (LiquidationEvent) IsEvent

func (LiquidationEvent) IsEvent()

type NewChain

type NewChain struct {
	Name           string `json:"name"`
	RPCURL         string `json:"rpcUrl"`
	BlockFetchSize int    `json:"blockFetchSize"`
}

type NewEventDefn

type NewEventDefn struct {
	Protocol     string `json:"protocol"`
	TopicName    string `json:"topicName"`
	AbiSignature string `json:"abiSignature"`
}

type NewProtocol

type NewProtocol struct {
	Name string `json:"name"`
	Abi  string `json:"abi"`
}

type NewProtocolInstance

type NewProtocolInstance struct {
	Protocol         string `json:"protocol"`
	Chain            string `json:"chain"`
	ContractAddress  string `json:"contractAddress"`
	FirstBlockToRead int    `json:"firstBlockToRead"`
}

type NewScan

type NewScan struct {
	Protocol string `json:"protocol"`
	Chain    string `json:"chain"`
}

type Protocol

type Protocol struct {
	ID              int          `json:"id"`
	Name            string       `json:"name"`
	Abi             string       `json:"abi"`
	ScannableEvents []*EventDefn `json:"scannableEvents"`
}

type ProtocolInstance

type ProtocolInstance struct {
	ID         int `json:"id"`
	Protocol   *Protocol
	Chain      *Chain
	ProtocolID int `json:"protocolId"`
	ChainID    int `json:"chainId"`

	ContractAddress  string `json:"contractAddress"`
	FirstBlockToRead int    `json:"firstBlockToRead"`
	LastBlockRead    int    `json:"lastBlockRead"`
}

func (*ProtocolInstance) ScanStartBlock

func (pi *ProtocolInstance) ScanStartBlock() int

type ProtocolInstanceStore

type ProtocolInstanceStore struct {
	// contains filtered or unexported fields
}

func NewProtocolInstanceStore

func NewProtocolInstanceStore(db *sqlx.DB) *ProtocolInstanceStore

func (*ProtocolInstanceStore) All

func (*ProtocolInstanceStore) CreateProtocolInstance

func (s *ProtocolInstanceStore) CreateProtocolInstance(input NewProtocolInstance) (*ProtocolInstance, error)

func (*ProtocolInstanceStore) DeleteByProtocolAndChain

func (s *ProtocolInstanceStore) DeleteByProtocolAndChain(protocolName string, chainName string) error

func (*ProtocolInstanceStore) FindById

func (s *ProtocolInstanceStore) FindById(id int) (*ProtocolInstance, error)

func (*ProtocolInstanceStore) FindByProtocolIdAndChainId

func (s *ProtocolInstanceStore) FindByProtocolIdAndChainId(protocolId int, chainId int) (*ProtocolInstance, error)

func (*ProtocolInstanceStore) FindChainById

func (s *ProtocolInstanceStore) FindChainById(id int) (*Chain, error)

func (*ProtocolInstanceStore) FindProtocolById

func (s *ProtocolInstanceStore) FindProtocolById(id int) (*Protocol, error)

func (*ProtocolInstanceStore) UpdateLastBlockRead

func (s *ProtocolInstanceStore) UpdateLastBlockRead(protocolInstanceId int, lastBlock uint) error

func (*ProtocolInstanceStore) UpdateProtocolInstance

func (s *ProtocolInstanceStore) UpdateProtocolInstance(protocolInstance *ProtocolInstance) (*ProtocolInstance, error)

type ProtocolStore

type ProtocolStore struct {
	// contains filtered or unexported fields
}

func NewProtocolStore

func NewProtocolStore(db *sqlx.DB) *ProtocolStore

func (*ProtocolStore) AddEventDefn

func (s *ProtocolStore) AddEventDefn(protocolName string, topicName string, topicHashHex string, abiSignature string) (*EventDefn, error)

func (*ProtocolStore) All

func (s *ProtocolStore) All() ([]*Protocol, error)

func (*ProtocolStore) AllByChain

func (s *ProtocolStore) AllByChain(chainId int) ([]*Protocol, error)

func (*ProtocolStore) AllEventsByProtocol

func (s *ProtocolStore) AllEventsByProtocol(id int) ([]*EventDefn, error)

func (*ProtocolStore) AllEventsByProtocolAndTopicName

func (s *ProtocolStore) AllEventsByProtocolAndTopicName(id int, topicName string) ([]*EventDefn, error)

func (*ProtocolStore) CreateProtocol

func (s *ProtocolStore) CreateProtocol(input NewProtocol) (*Protocol, error)

func (*ProtocolStore) DeleteByName

func (s *ProtocolStore) DeleteByName(name string) error

func (*ProtocolStore) FindById

func (s *ProtocolStore) FindById(id int) (*Protocol, error)

func (*ProtocolStore) FindByName

func (s *ProtocolStore) FindByName(name string) (*Protocol, error)

func (*ProtocolStore) FindEventById

func (s *ProtocolStore) FindEventById(id int) (*EventDefn, error)

type RepayEvent

type RepayEvent struct {
	ID            int       `json:"id"`
	Type          EventType `json:"type"`
	Txhash        string    `json:"txhash"`
	Blocknumber   int       `json:"blocknumber"`
	Index         int       `json:"index"`
	OccuredAt     time.Time `json:"occuredAt"`
	Borrower      *Account  `json:"borrower"`
	AmountRepayed int       `json:"amountRepayed"`
	Token         *Token    `json:"token"`
}

func (RepayEvent) IsAnyEvent

func (RepayEvent) IsAnyEvent()

func (RepayEvent) IsEvent

func (RepayEvent) IsEvent()

type Stores

type Stores struct {
	Protocol         *ProtocolStore
	Chain            *ChainStore
	ProtocolInstance *ProtocolInstanceStore
	Account          *AccountStore
	Event            *EventStore
	Token            *TokenStore
	// contains filtered or unexported fields
}

func GenerateStores

func GenerateStores(db *sqlx.DB) Stores

func NewStores

func NewStores() (Stores, error)

func (Stores) Close

func (s Stores) Close()

type Token

type Token struct {
	ID       int     `json:"id"`
	Address  string  `json:"address"`
	Name     *string `json:"name"`
	Ticker   *string `json:"ticker"`
	Decimals int     `json:"decimals"`
}

type TokenInfo

type TokenInfo struct {
	Address  string `json:"address"`
	Name     string `json:"name"`
	Ticker   string `json:"ticker"`
	Chain    string `json:"chain"`
	Decimals int    `json:"decimals"`
}

type TokenStore

type TokenStore struct {
	// contains filtered or unexported fields
}

func NewTokenStore

func NewTokenStore(db *sqlx.DB) *TokenStore

func (*TokenStore) All

func (s *TokenStore) All() ([]*Token, error)

func (*TokenStore) AllByChain

func (s *TokenStore) AllByChain(chainId int) ([]*Token, error)

func (*TokenStore) CreateToken

func (s *TokenStore) CreateToken(address string, name *string, ticker *string, chainId int) (*Token, error)

func (*TokenStore) FindById

func (s *TokenStore) FindById(id int) (*Token, error)

func (*TokenStore) FindByName

func (s *TokenStore) FindByName(name string) (*Token, error)

func (*TokenStore) FindOrCreateByAddress

func (s *TokenStore) FindOrCreateByAddress(address string, chainId int) (*Token, error)

func (*TokenStore) UpdateToken

func (s *TokenStore) UpdateToken(id int, address string, name string, ticker string, decimals int) (*Token, error)

type UpdateProtocolInstance

type UpdateProtocolInstance struct {
	Protocol         string `json:"protocol"`
	Chain            string `json:"chain"`
	ContractAddress  string `json:"contractAddress"`
	FirstBlockToRead int    `json:"firstBlockToRead"`
	LastBlockRead    int    `json:"lastBlockRead"`
}

Jump to

Keyboard shortcuts

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