2023-03-07 11:25:42 -08:00
|
|
|
package transactions
|
|
|
|
|
2023-03-15 12:52:50 -07:00
|
|
|
import (
|
2023-05-10 13:39:18 -07:00
|
|
|
"fmt"
|
2023-03-15 12:52:50 -07:00
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/wormhole-foundation/wormhole-explorer/api/internal/pagination"
|
2023-04-25 11:34:29 -07:00
|
|
|
sdk "github.com/wormhole-foundation/wormhole/sdk/vaa"
|
2023-03-15 12:52:50 -07:00
|
|
|
)
|
|
|
|
|
2023-04-20 12:01:10 -07:00
|
|
|
type Scorecards struct {
|
2023-05-17 11:04:17 -07:00
|
|
|
// Total value locked in USD.
|
|
|
|
Tvl string
|
|
|
|
|
2023-04-20 12:01:10 -07:00
|
|
|
// Number of VAAs emitted since the creation of the network (does not include Pyth messages)
|
|
|
|
TotalTxCount string
|
|
|
|
|
2023-05-15 11:15:12 -07:00
|
|
|
//Volume transferred since the creation of the network, in USD.
|
|
|
|
TotalTxVolume string
|
|
|
|
|
2023-04-20 12:01:10 -07:00
|
|
|
// Number of VAAs emitted in the last 24 hours (does not include Pyth messages).
|
|
|
|
TxCount24h string
|
2023-05-04 16:17:03 -07:00
|
|
|
|
|
|
|
// Volume transferred through the token bridge in the last 24 hours, in USD.
|
|
|
|
Volume24h string
|
2023-04-20 12:01:10 -07:00
|
|
|
}
|
|
|
|
|
2023-05-12 09:05:18 -07:00
|
|
|
// AssetDTO is used for the return value of the function `GetTopAssets`.
|
2023-05-10 13:39:18 -07:00
|
|
|
type AssetDTO struct {
|
|
|
|
EmitterChain sdk.ChainID
|
|
|
|
TokenChain sdk.ChainID
|
|
|
|
TokenAddress string
|
|
|
|
Volume string
|
|
|
|
}
|
|
|
|
|
2023-05-12 09:05:18 -07:00
|
|
|
// ChainPairDTO is used for the return value of the function `GetTopChainPairs`.
|
|
|
|
type ChainPairDTO struct {
|
|
|
|
EmitterChain sdk.ChainID
|
|
|
|
DestinationChain sdk.ChainID
|
|
|
|
NumberOfTransfers string
|
|
|
|
}
|
|
|
|
|
|
|
|
// TopStatisticsTimeSpan is used as an input parameter for the functions `GetTopAssets` and `GetTopChainPairs`.
|
|
|
|
type TopStatisticsTimeSpan string
|
2023-05-10 13:39:18 -07:00
|
|
|
|
|
|
|
const (
|
2023-05-12 09:05:18 -07:00
|
|
|
TimeSpan7Days TopStatisticsTimeSpan = "7d"
|
|
|
|
TimeSpan15Days TopStatisticsTimeSpan = "15d"
|
|
|
|
TimeSpan30Days TopStatisticsTimeSpan = "30d"
|
2023-05-10 13:39:18 -07:00
|
|
|
)
|
|
|
|
|
2023-05-12 09:05:18 -07:00
|
|
|
// ParseTopStatisticsTimeSpan parses a string and returns a `TopAssetsTimeSpan`.
|
|
|
|
func ParseTopStatisticsTimeSpan(s string) (*TopStatisticsTimeSpan, error) {
|
2023-05-10 13:39:18 -07:00
|
|
|
|
2023-05-12 09:05:18 -07:00
|
|
|
if s == string(TimeSpan7Days) ||
|
|
|
|
s == string(TimeSpan15Days) ||
|
|
|
|
s == string(TimeSpan30Days) {
|
2023-05-10 13:39:18 -07:00
|
|
|
|
2023-05-12 09:05:18 -07:00
|
|
|
tmp := TopStatisticsTimeSpan(s)
|
2023-05-10 13:39:18 -07:00
|
|
|
return &tmp, nil
|
|
|
|
}
|
|
|
|
|
2023-05-12 09:05:18 -07:00
|
|
|
return nil, fmt.Errorf("invalid time span: %s", s)
|
2023-05-10 13:39:18 -07:00
|
|
|
}
|
|
|
|
|
2023-03-15 12:52:50 -07:00
|
|
|
type GlobalTransactionDoc struct {
|
|
|
|
ID string `bson:"_id" json:"id"`
|
|
|
|
OriginTx *OriginTx `bson:"originTx" json:"originTx"`
|
|
|
|
DestinationTx *DestinationTx `bson:"destinationTx" json:"destinationTx"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// OriginTx representa a origin transaction.
|
|
|
|
type OriginTx struct {
|
2023-04-25 11:34:29 -07:00
|
|
|
ChainID sdk.ChainID `bson:"chainId" json:"chainId"`
|
2023-04-05 06:33:28 -07:00
|
|
|
TxHash string `bson:"nativeTxHash" json:"txHash"`
|
2023-03-15 12:52:50 -07:00
|
|
|
Timestamp *time.Time `bson:"timestamp" json:"timestamp"`
|
2023-04-25 11:34:29 -07:00
|
|
|
Status string `bson:"status" json:"status"`
|
2023-03-15 12:52:50 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// DestinationTx representa a destination transaction.
|
|
|
|
type DestinationTx struct {
|
2023-04-25 11:34:29 -07:00
|
|
|
ChainID sdk.ChainID `bson:"chainId" json:"chainId"`
|
2023-03-15 12:52:50 -07:00
|
|
|
Status string `bson:"status" json:"status"`
|
|
|
|
Method string `bson:"method" json:"method"`
|
|
|
|
TxHash string `bson:"txHash" json:"txHash"`
|
|
|
|
From string `bson:"from" json:"from"`
|
|
|
|
To string `bson:"to" json:"to"`
|
|
|
|
BlockNumber string `bson:"blockNumber" json:"blockNumber"`
|
2023-03-21 07:57:46 -07:00
|
|
|
Timestamp *time.Time `bson:"timestamp" json:"timestamp"`
|
2023-03-15 12:52:50 -07:00
|
|
|
UpdatedAt *time.Time `bson:"updatedAt" json:"updatedAt"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// TransactionUpdate represents a transaction document.
|
|
|
|
type TransactionUpdate struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
// GlobalTransactionQuery respresent a query for the globalTransactions mongodb document.
|
|
|
|
type GlobalTransactionQuery struct {
|
|
|
|
pagination.Pagination
|
|
|
|
id string
|
|
|
|
}
|
|
|
|
|
|
|
|
// Query create a new VaaQuery with default pagination vaues.
|
|
|
|
func Query() *GlobalTransactionQuery {
|
|
|
|
p := pagination.Default()
|
|
|
|
return &GlobalTransactionQuery{Pagination: *p}
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetId set the chainId field of the VaaQuery struct.
|
|
|
|
func (q *GlobalTransactionQuery) SetId(id string) *GlobalTransactionQuery {
|
|
|
|
q.id = id
|
|
|
|
return q
|
|
|
|
}
|
2023-03-07 11:25:42 -08:00
|
|
|
|
|
|
|
type TransactionCountQuery struct {
|
|
|
|
TimeSpan string
|
|
|
|
SampleRate string
|
|
|
|
CumulativeSum bool
|
|
|
|
}
|
|
|
|
|
|
|
|
type TransactionCountResult struct {
|
|
|
|
Time time.Time `json:"time" mapstructure:"_time"`
|
2023-05-10 14:18:32 -07:00
|
|
|
Count uint64 `json:"count" mapstructure:"_value"`
|
2023-03-07 11:25:42 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
type ChainActivityResult struct {
|
2023-05-15 11:15:12 -07:00
|
|
|
ChainSourceID string `mapstructure:"emitter_chain"`
|
|
|
|
ChainDestinationID string `mapstructure:"destination_chain"`
|
2023-03-07 11:25:42 -08:00
|
|
|
Volume uint64 `mapstructure:"volume"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type ChainActivityQuery struct {
|
|
|
|
Start *time.Time
|
|
|
|
End *time.Time
|
|
|
|
AppIDs []string
|
|
|
|
IsNotional bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *ChainActivityQuery) HasAppIDS() bool {
|
|
|
|
return len(q.AppIDs) > 0
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *ChainActivityQuery) GetAppIDs() []string {
|
|
|
|
return q.AppIDs
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *ChainActivityQuery) GetStart() time.Time {
|
|
|
|
if q.Start == nil {
|
|
|
|
return time.UnixMilli(0)
|
|
|
|
}
|
|
|
|
return *q.Start
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *ChainActivityQuery) GetEnd() time.Time {
|
|
|
|
if q.End == nil {
|
|
|
|
return time.Now()
|
|
|
|
}
|
|
|
|
return *q.End
|
|
|
|
}
|