credmark

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2024 License: MIT Imports: 14 Imported by: 0

README

Credmark SDK for Go (Unofficial)

Go Report Card License

This is an unofficial Golang SDK for interacting with the Credmark API. Credmark is a protocol that provides on-chain risk analytics and portfolio optimization services.

Table of Contents

Installation

To install the Credmark SDK for Go, run the following command:

go get github.com/truetribe/credmark-sdk-go

Documentation

Index

Constants

View Source
const (
	CHAIN_ID_ETHEREUM  = 1
	CHAIN_ID_POLYGON   = 137
	CHAIN_ID_BNB_CHAIN = 56
	CHAIN_ID_ARBITRUM  = 42161
	CHAIN_ID_OPTIMISM  = 10
)
View Source
const (
	CLIENT_VERSION = "0.0.0"

	CREDMARK_API_V1_XR_URI = "/v1/model/run"

	CREDMARK_GATEWAY_URL = "https://gateway.credmark.com"
)
View Source
const (
	CREDMARK_API_V1_TOKEN_META = "/v1/tokens/%s/%s" //chainId, tokenAddress
)
View Source
const (
	CREDMARK_API_V1_TOKEN_NAME = "/v1/tokens/%s/%s/name" //chainId, tokenAddress
)
View Source
const (
	CREDMARK_API_V1_URI_TOKEN_HOLDER = "/v1/tokens/%s/%s/holders" //chainId, tokenAddress
)
View Source
const (
	CREDMARK_API_V1_URI_TOKEN_HOLDER_COUNT = "/v1/tokens/%s/%s/holders/count" //chainId, tokenAddress
)
View Source
const (
	CREDMARK_API_V1_URI_TOKEN_HOLDER_COUNT_HISTORICAL = "/v1/tokens/%s/%s/holders/count/historical" //chainId, tokenAddress
)
View Source
const (
	CREDMARK_API_V1_URI_TOKEN_PRICE = "/v1/tokens/%s/%s/price" //chainId, tokenAddress
)
View Source
const (
	CREDMARK_API_V1_URI_TOKEN_PRICE_HISTORICAL = "/v1/tokens/%s/%s/price" //chainId, tokenAddress
)
View Source
const (
	CREDMARK_API_V1_URI_TOKEN_VOLUME_HISTORICAL = "/v1/tokens/%s/%s/volume/historical" //chainId, tokenAddress
)
View Source
const (
	CREDMARK_TOKEN_API_V1_TOTAL_SUPPLY = "/v1/tokens/%s/%s/total-supply" //chainId, tokenAddress
)
View Source
const (
	CREDMARK_TOKEN_API_V1_VOLUME = "/v1/tokens/%s/%s/volume" //chainId, tokenAddress
)
View Source
const (
	CREDMARK_UTIL_V1_GET_BLOCK_NUM_FROM_TIMESTAMP = "/v1/utilities/chains/%s/block/from-timestamp"
)

Variables

This section is empty.

Functions

func GetCurrentFuncName

func GetCurrentFuncName() string

func ValidateStruct

func ValidateStruct(reqPayload interface{}) error

ValidateStruct will validate the reqPayload based on the struct tags

Types

type ApiRequest

type ApiRequest struct {
	Endpoint string `validate:"required"`
	Method   string `validate:"required"`
	Body     string `validate:"required"`
	Header   RequestHeader
}

type ChainlinkGetFeedRegistry

type ChainlinkGetFeedRegistry struct {
	One0 int `json:"1.0"`
}

type ChainlinkPriceByRegistry

type ChainlinkPriceByRegistry struct {
	One3 int `json:"1.3"`
}

type ChainlinkPriceFromRegistryMaybe

type ChainlinkPriceFromRegistryMaybe struct {
	One2 int `json:"1.2"`
}

type Client

type Client struct {
	HttpClient          *http.Client
	Config              *Config
	RetryablehttpClient *retryablehttp.Client
}

func NewClient

func NewClient(cfg *Config) (*Client, error)

func (*Client) GetBlockNumberFromTimestamp added in v0.2.0

func (c *Client) GetBlockNumberFromTimestamp(payload GetBlockNumberFromTimestamp) (response GetBlockNumberFromTimestampResponse, err error)

func (*Client) GetTokenHolders

func (c *Client) GetTokenHolders(payload GetTokenHoldersPayload) (response GetTokenHoldersCredmarkResponse, err error)

func (*Client) GetTokenHoldersCount added in v0.4.0

func (c *Client) GetTokenHoldersCount(payload GetTokenHoldersCountPayload) (response TokenHoldersCountResponse, err error)

func (*Client) GetTokenHoldersCountHistorical

func (c *Client) GetTokenHoldersCountHistorical(payload GetTokenHoldersCountHistoricalPayload) (response TokenHistoricalHoldersCountResponse, err error)

func (*Client) GetTokenMeta added in v0.3.0

func (c *Client) GetTokenMeta(payload GetTokenMetaPayload) (response GetTokenMetaResponse, err error)

func (*Client) GetTokenName added in v0.3.0

func (c *Client) GetTokenName(payload GetTokenNamePayload) (response GetTokenNameResponse, err error)

func (*Client) GetTokenPrice

func (c *Client) GetTokenPrice(payload GetTokenPricePayload) (response GetTokenPriceCredmarkResponse, err error)

func (*Client) GetTokenPriceHistorical

func (c *Client) GetTokenPriceHistorical(payload GetTokenPriceHistoricalPayload) (response GetTokenPriceHistoricalCredmarkResponse, err error)

func (*Client) GetTokenTotalSupply added in v0.2.0

func (c *Client) GetTokenTotalSupply(payload GetTokenTotalSupplyPayload) (response GetTokenTotalSupplyResponse, err error)

func (*Client) GetTokenVolume

func (c *Client) GetTokenVolume(payload GetTokenVolumePayload) (response GetTokenVolumeResponse, err error)

func (*Client) GetTokenVolumeHistorical

func (c *Client) GetTokenVolumeHistorical(payload GetTokenVolumeHistoricalPayload) (response TokenVolumeHistoricalResponse, err error)

func (*Client) RunModel added in v0.4.0

func (c *Client) RunModel(payload string) (response string, err error)

type Config

type Config struct {
	ApiKey       string `validate:"required"`
	RetryWaitMin int    // Second
	RetryWaitMax int    // Second
	RetryMax     int    // Time. e.g. 10 for 10 times
}

type ContractMetadata

type ContractMetadata struct {
	One0 int `json:"1.0"`
}

type CredmarkModelGetTokenVolumePayload added in v0.2.0

type CredmarkModelGetTokenVolumePayload struct {
	Slug        string                                  `json:"slug"`
	ChainID     int                                     `json:"chainId"`
	BlockNumber string                                  `json:"blockNumber"`
	Input       CredmarkModelGetTokenVolumePayloadInput `json:"input"`
}

type CredmarkModelGetTokenVolumePayloadInput added in v0.2.0

type CredmarkModelGetTokenVolumePayloadInput struct {
	Address      string `json:"address"`
	Window       string `json:"window"`
	IncludePrice bool   `json:"include_price"`
}

type CredmarkModelResponse added in v0.4.0

type CredmarkModelResponse struct {
	Slug         string      `json:"slug"`
	Version      string      `json:"version"`
	ChainID      int         `json:"chainId"`
	BlockNumber  int         `json:"blockNumber"`
	Output       interface{} `json:"output"`
	Dependencies interface{} `json:"dependencies"`
	Cached       bool        `json:"cached"`
	Runtime      int         `json:"runtime"`
}

type CredmarkTokenVolumeModelResponse added in v0.2.0

type CredmarkTokenVolumeModelResponse struct {
	Slug         string                                  `json:"slug"`
	Version      string                                  `json:"version"`
	ChainID      int                                     `json:"chainId"`
	BlockNumber  int                                     `json:"blockNumber"`
	Output       CredmarkTokenVolumeResponseOutput       `json:"output"`
	Dependencies CredmarkTokenVolumeResponseDependencies `json:"dependencies"`
	Runtime      int                                     `json:"runtime"`
}

type CredmarkTokenVolumeResponseDependencies

type CredmarkTokenVolumeResponseDependencies struct {
	RPCGetBlocknumber               RPCGetBlocknumber               `json:"rpc.get-blocknumber"`
	LedgerErc20TokenTransferData    LedgerErc20TokenTransferData    `json:"ledger.erc20_token_transfer_data"`
	ContractMetadata                ContractMetadata                `json:"contract.metadata"`
	TokenUnderlyingMaybe            TokenUnderlyingMaybe            `json:"token.underlying-maybe"`
	ChainlinkGetFeedRegistry        ChainlinkGetFeedRegistry        `json:"chainlink.get-feed-registry"`
	ChainlinkPriceByRegistry        ChainlinkPriceByRegistry        `json:"chainlink.price-by-registry"`
	ChainlinkPriceFromRegistryMaybe ChainlinkPriceFromRegistryMaybe `json:"chainlink.price-from-registry-maybe"`
	PriceOracleChainlink            PriceOracleChainlink            `json:"price.oracle-chainlink"`
	PriceOracleChainlinkMaybe       PriceOracleChainlinkMaybe       `json:"price.oracle-chainlink-maybe"`
	PriceQuote                      PriceQuote                      `json:"price.quote"`
	TokenOverallVolumeBlock         TokenOverallVolumeBlock         `json:"token.overall-volume-block"`
	TokenOverallVolumeWindow        TokenOverallVolumeWindow        `json:"token.overall-volume-window"`
}

type CredmarkTokenVolumeResponseOutput

type CredmarkTokenVolumeResponseOutput struct {
	Address      string  `json:"address"`
	Volume       int64   `json:"volume"`
	VolumeScaled float64 `json:"volume_scaled"`
	ValueLast    float64 `json:"value_last"`
	FromBlock    int     `json:"from_block"`
	ToBlock      int     `json:"to_block"`
}

type GetBlockNumberFromTimestamp added in v0.2.0

type GetBlockNumberFromTimestamp struct {
	ChainID   int    `validate:"required"`
	Timestamp string `validate:"required"`
}

type GetBlockNumberFromTimestampResponse added in v0.2.0

type GetBlockNumberFromTimestampResponse struct {
	BlockNumber    uint `json:"blockNumber"`
	BlockTimestamp uint `json:"blockTimestamp"`
}

type GetTokenHoldersCountHistoricalPayload

type GetTokenHoldersCountHistoricalPayload struct {
	ChainID          int    `validate:"required"`
	TokenAddress     string `validate:"required"`
	StartBlockNumber *uint64
	EndBlockNumber   *uint64
	BlockInterval    *uint64
	StartTimestamp   *uint64
	EndTimestamp     *uint64
	TimeInterval     *uint64
}

type GetTokenHoldersCountPayload added in v0.4.0

type GetTokenHoldersCountPayload struct {
	ChainID      int    `validate:"required"`
	TokenAddress string `validate:"required"`
	BlockNumber  *uint64
	Timestamp    *uint64
}

type GetTokenHoldersCredmarkResponse

type GetTokenHoldersCredmarkResponse struct {
	ChainID        int    `json:"chainId"`
	BlockNumber    int    `json:"blockNumber"`
	BlockTimestamp int    `json:"blockTimestamp"`
	TokenAddress   string `json:"tokenAddress"`
	Scaled         bool   `json:"scaled"`
	QuoteAddress   string `json:"quoteAddress"`
	Data           []struct {
		Address string  `json:"address"`
		Balance float64 `json:"balance"`
		Value   float64 `json:"value"`
	} `json:"data"`
	Total  int    `json:"total"`
	Cursor string `json:"cursor"`
}

type GetTokenHoldersPayload

type GetTokenHoldersPayload struct {
	ChainID   int    `validate:"required"` //Chain ID. Use 1 for mainnet.
	TokenAddr string `validate:"required"` //The address of the token requested.
	PageSize  int    `validate:"required"` //The size of the returned page. Do not change this from page to page when using a cursor.
	Cursor    string //The cursor from the results of a previous page. Use empty string (or undefined/null) for first page.
	QuoteAddr string //The address of the token/currency used as the currency of the returned price. Defaults to USD (address 0x0000000000000000000000000000000000000348)
	Scaled    bool   //Scale holders' balance by token decimals. Defaults to true.
	BlockNum  int    //Block number of the price quote. Defaults to the latest block.
	Timestamp int    //Timestamp of a block number can be specified instead of a block number. Finds a block at or before the number of seconds since January 1, 1970.
}

type GetTokenMetaPayload added in v0.3.0

type GetTokenMetaPayload struct {
	ChainID      int    `validate:"required"`
	TokenAddress string `validate:"required"`
	BlockNumber  *uint64
	Timestamp    *uint64
}

type GetTokenMetaResponse added in v0.3.0

type GetTokenMetaResponse struct {
	ChainID        int    `json:"chainId"`
	BlockNumber    int    `json:"blockNumber"`
	BlockTimestamp int    `json:"blockTimestamp"`
	TokenAddress   string `json:"tokenAddress"`
	Name           string `json:"name"`
	Symbol         string `json:"symbol"`
	Decimals       int    `json:"decimals"`
}

type GetTokenNamePayload added in v0.3.0

type GetTokenNamePayload struct {
	ChainID      int    `validate:"required"`
	TokenAddress string `validate:"required"`
	BlockNumber  *uint64
	Timestamp    *uint64
}

type GetTokenNameResponse added in v0.3.0

type GetTokenNameResponse struct {
	ChainID        int    `json:"chainId"`
	BlockNumber    int    `json:"blockNumber"`
	BlockTimestamp int    `json:"blockTimestamp"`
	TokenAddress   string `json:"tokenAddress"`
	Name           string `json:"name"`
}

type GetTokenPriceCredmarkResponse

type GetTokenPriceCredmarkResponse struct {
	ChainID        int     `json:"chainId"`
	BlockNumber    int     `json:"blockNumber"`
	BlockTimestamp int     `json:"blockTimestamp"`
	TokenAddress   string  `json:"tokenAddress"`
	QuoteAddress   string  `json:"quoteAddress"`
	Price          float64 `json:"price"`
	Src            string  `json:"src"`
	SrcInternal    string  `json:"srcInternal"`
}

type GetTokenPriceHistoricalCredmarkResponse

type GetTokenPriceHistoricalCredmarkResponse struct {
	ChainID          int    `json:"chainId"`
	StartBlockNumber int    `json:"startBlockNumber"`
	EndBlockNumber   int    `json:"endBlockNumber"`
	StartTimestamp   int    `json:"startTimestamp"`
	EndTimestamp     int    `json:"endTimestamp"`
	TokenAddress     string `json:"tokenAddress"`
	QuoteAddress     string `json:"quoteAddress"`
	Data             []struct {
		BlockNumber    int     `json:"blockNumber"`
		BlockTimestamp int     `json:"blockTimestamp"`
		Price          float64 `json:"price"`
		Src            string  `json:"src"`
		SrcInternal    string  `json:"srcInternal"`
	} `json:"data"`
}

type GetTokenPriceHistoricalPayload

type GetTokenPriceHistoricalPayload struct {
	ChainID          int    `validate:"required"` //Chain ID. Use 1 for mainnet.
	TokenAddr        string `validate:"required"` //The address of the token requested.
	StartBlockNumber *uint64
	EndBlockNumber   *uint64
	BlockInterval    *uint64
	StartTimestamp   *uint64
	EndTimestamp     *uint64
	TimeInterval     *uint64
	QuoteAddress     string
	Src              string
}

type GetTokenPricePayload

type GetTokenPricePayload struct {
	ChainID   int    `validate:"required"` //Chain ID. Use 1 for mainnet.
	TokenAddr string `validate:"required"` //The address of the token requested.
	QuoteAddr string //The address of the token/currency used as the currency of the returned price. Defaults to USD (address 0x0000000000000000000000000000000000000348)
	BlockNum  int    //Block number of the price quote. Defaults to the latest block.
	Timestamp int    //Timestamp of a block number can be specified instead of a block number. Finds a block at or before the number of seconds since January 1, 1970.
	Source    string `validate:"oneof='' 'dex' 'cex'"` //(Optional) Available values : dex, cex, specify preferred source to be queried first, choices: "dex" (pre-calculated, default), or "cex" (from call to price.quote model)
	Align     string //(Optional) Available values : 5min, 15min; specify align block number or timestamp to nearest mark for pre-calculated price, choose "5min" for 0,5,10...45,50,55 minutes in every hour
}

type GetTokenTotalSupplyPayload added in v0.2.0

type GetTokenTotalSupplyPayload struct {
	ChainID     int    `validate:"required"`
	TokenAddr   string `validate:"required"`
	BlockNumber *uint64
	Timestamp   *uint64
	Scaled      bool
}

type GetTokenTotalSupplyResponse added in v0.2.0

type GetTokenTotalSupplyResponse struct {
	ChainID        int    `json:"chainId"`
	BlockNumber    int    `json:"blockNumber"`
	BlockTimestamp int    `json:"blockTimestamp"`
	TokenAddress   string `json:"tokenAddress"`
	Scaled         bool   `json:"scaled"`
	TotalSupply    int    `json:"totalSupply"`
}

type GetTokenVolumeHistoricalPayload

type GetTokenVolumeHistoricalPayload struct {
	ChainID          int    `validate:"required"`
	TokenAddress     string `validate:"required"`
	StartBlockNumber *uint64
	EndBlockNumber   *uint64
	BlockInterval    *uint64
	StartTimestamp   *uint64
	EndTimestamp     *uint64
	TimeInterval     *uint64
}

type GetTokenVolumeModelResponse added in v0.2.0

type GetTokenVolumeModelResponse struct {
	Raw    string
	Output CredmarkTokenVolumeResponseOutput
}

type GetTokenVolumePayload

type GetTokenVolumePayload struct {
	ChainID          int    `validate:"required"`
	TokenAddr        string `validate:"required"`
	Scaled           bool
	StartBlockNumber *uint64
	EndBlockNumber   *uint64
	StartTimestamp   *uint64
	EndTimestamp     *uint64
}

type GetTokenVolumeResponse

type GetTokenVolumeResponse struct {
	ChainID          int     `json:"chainId"`
	StartBlockNumber int     `json:"startBlockNumber"`
	EndBlockNumber   int     `json:"endBlockNumber"`
	StartTimestamp   int     `json:"startTimestamp"`
	EndTimestamp     int     `json:"endTimestamp"`
	TokenAddress     string  `json:"tokenAddress"`
	Scaled           bool    `json:"scaled"`
	Volume           float64 `json:"volume"`
}

type LedgerErc20TokenTransferData

type LedgerErc20TokenTransferData struct {
	One0 int `json:"1.0"`
}

type ModelError

type ModelError struct {
	Type    string `json:"type"`
	Message string `json:"message"`
	Stack   []struct {
		Slug string `json:"slug"`
	} `json:"stack"`
}

type ModelGetTokenVolumePayload added in v0.2.0

type ModelGetTokenVolumePayload struct {
	Address      string `validate:"required"`
	Window       string `validate:"required"` //"24 hours"
	IncludePrice bool
}
type PriceOracleChainlink struct {
	One7 int `json:"1.7"`
}

type PriceOracleChainlinkMaybe

type PriceOracleChainlinkMaybe struct {
	One2 int `json:"1.2"`
}

type PriceQuote

type PriceQuote struct {
	One9 int `json:"1.9"`
}

type RPCGetBlocknumber

type RPCGetBlocknumber struct {
	One0 int `json:"1.0"`
}

type RequestHeader

type RequestHeader struct {
	ContentType   string
	Authorization string
	Connection    string
}

type TokenHistoricalHoldersCountResponse

type TokenHistoricalHoldersCountResponse struct {
	ChainID          int                               `json:"chainId"`
	StartBlockNumber int                               `json:"startBlockNumber"`
	EndBlockNumber   int                               `json:"endBlockNumber"`
	StartTimestamp   int64                             `json:"startTimestamp"`
	EndTimestamp     int64                             `json:"endTimestamp"`
	TokenAddress     string                            `json:"tokenAddress"`
	Data             []TokenHoldersCountHistoricalItem `json:"data"`
}

type TokenHoldersCountHistoricalItem

type TokenHoldersCountHistoricalItem struct {
	BlockNumber    int64 `json:"blockNumber"`
	BlockTimestamp int64 `json:"blockTimestamp"`
	Count          int64 `json:"count"`
}

type TokenHoldersCountResponse added in v0.4.0

type TokenHoldersCountResponse struct {
	ChainID      int    `json:"chainId"`
	BlockNumber  int64  `json:"blockNumber"`
	Timestamp    int64  `json:"blockTimestamp"`
	TokenAddress string `json:"tokenAddress"`
	Count        int64  `json:"count"`
}

type TokenOverallVolumeBlock

type TokenOverallVolumeBlock struct {
	One0 int `json:"1.0"`
}

type TokenOverallVolumeWindow

type TokenOverallVolumeWindow struct {
	One0 int `json:"1.0"`
}

type TokenUnderlyingMaybe

type TokenUnderlyingMaybe struct {
	One1 int `json:"1.1"`
}

type TokenVolumeHistoricalItem

type TokenVolumeHistoricalItem struct {
	StartBlockNumber int     `json:"startBlockNumber"`
	EndBlockNumber   int     `json:"endBlockNumber"`
	StartTimestamp   int     `json:"startTimestamp"`
	EndTimestamp     int     `json:"endTimestamp"`
	Volume           float64 `json:"volume"`
}

type TokenVolumeHistoricalResponse

type TokenVolumeHistoricalResponse struct {
	ChainID          int                         `json:"chainId"`
	StartBlockNumber int                         `json:"startBlockNumber"`
	EndBlockNumber   int                         `json:"endBlockNumber"`
	StartTimestamp   int                         `json:"startTimestamp"`
	EndTimestamp     int                         `json:"endTimestamp"`
	TokenAddress     string                      `json:"tokenAddress"`
	Scaled           bool                        `json:"scaled"`
	Data             []TokenVolumeHistoricalItem `json:"data"`
}

Jump to

Keyboard shortcuts

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