token

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultLimit = 50
	MaxLimit     = 200
)

Variables

This section is empty.

Functions

func RegisterRoutes

func RegisterRoutes(r chi.Router, svc ListService, logger *zap.Logger)

RegisterRoutes registers token endpoints on the given router.

Types

type Config

type Config struct {
	SupportedTokens map[common.Address]ERC20Token `yaml:"supported_tokens" validate:"required,min=1"`
}

Config holds token metadata indexed by contract address.

func NewConfig

func NewConfig() *Config

NewConfig creates a token Config.

func (*Config) AddToken

func (c *Config) AddToken(address common.Address, token ERC20Token)

AddToken registers a supported token contract.

type ERC20

type ERC20 interface {
	Name(ctx context.Context) string
	Symbol(ctx context.Context) string
	Decimals(ctx context.Context) uint8
	TotalSupply(ctx context.Context) big.Int
	BalanceOf(ctx context.Context, address common.Address) big.Int
	TransferFrom(ctx context.Context, idempotencyKey string, from, to common.Address, amount big.Int) error
	Approve(ctx context.Context, spender common.Address, amount big.Int) error
	Allowance(ctx context.Context, owner, spender common.Address) big.Int
}

ERC20 defines the ERC-20 surface exposed by this package.

func NewERC20

func NewERC20(address common.Address, tokenService *Service) ERC20

NewERC20 creates an ERC20 implementation bound to a contract address.

type ERC20Token

type ERC20Token struct {
	Name         string `yaml:"name" validate:"required"`
	Symbol       string `yaml:"symbol" validate:"required"`
	Decimals     int    `yaml:"decimals" validate:"gte=0,lte=18"`
	InstrumentID string `yaml:"instrument_id" validate:"required"`
}

ERC20Token contains ERC-20 token metadata and Canton instrument mapping.

type HTTP

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

HTTP wraps ListService to provide token HTTP endpoints.

type ListService

type ListService interface {
	GetSupportedTokens(ctx context.Context, cursor string, limit int) (*TokensPage, error)
}

ListService is the narrow interface the HTTP layer depends on.

type Native

type Native interface {
	GetBalance(ctx context.Context, address common.Address) (big.Int, error)
	Transfer(ctx context.Context, from, to common.Address, amount big.Int) error
}

Native defines the native-token surface exposed by this package.

func NewNative

func NewNative(svc *Service) Native

NewNative creates a Native implementation.

type Provider

type Provider interface {
	GetTotalSupply(ctx context.Context, tokenSymbol string) (string, error)
	GetBalance(ctx context.Context, tokenSymbol, partyID string) (string, error)
}

Provider defines token data provider.

type Service

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

Service provides token operations shared by API and EthRPC endpoints.

func NewTokenService

func NewTokenService(
	cfg *Config,
	provider Provider,
	userStore UserStore,
	cantonClient canton.Token,
) *Service

NewTokenService creates a Service.

func (*Service) ERC20

func (s *Service) ERC20(address common.Address) (ERC20, error)

ERC20 returns an ERC-20 view for the given contract address, or an error if the address is not a supported token contract.

func (*Service) GetSupportedTokens

func (s *Service) GetSupportedTokens(_ context.Context, cursor string, limit int) (*TokensPage, error)

GetSupportedTokens returns a cursor-paginated list of supported tokens sorted by address. cursor is the address of the last item from the previous page; empty string starts from the beginning.

func (*Service) Native

func (s *Service) Native() Native

Native returns the native token view.

type TokenItem

type TokenItem struct {
	Address  string `json:"address"`
	Name     string `json:"name"`
	Symbol   string `json:"symbol"`
	Decimals int    `json:"decimals"`
}

TokenItem is a single token entry in the list response.

type TokensPage

type TokensPage struct {
	Items      []TokenItem `json:"items"`
	NextCursor string      `json:"next_cursor,omitempty"`
	HasMore    bool        `json:"has_more"`
}

TokensPage is the cursor-paginated response for GET /tokens.

type Type

type Type string

Type identifies a token for balance operations.

const (
	Prompt Type = "PROMPT"
	Demo   Type = "DEMO"
)

type UserStore

type UserStore interface {
	GetUserByEVMAddress(ctx context.Context, evmAddress string) (*user.User, error)
	GetUserByCantonPartyID(ctx context.Context, partyID string) (*user.User, error)
}

UserStore defines user persistence required by Service.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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