Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions cmd/tribes-dcm/root/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,12 @@ func init() {
Cmd.Flags().IntVar(&maxStartupTime, "max-startup-time", 10, "Maximum startup time in seconds")
cobra.CheckErr(viper.BindPFlag(configs.MAX_STARTUP_TIME, Cmd.Flags().Lookup("max-startup-time")))

// Database flags
Cmd.Flags().StringVar(&databaseUrl, "database-url", "sqlite:///mnt/data/rollup.db", "SQLite database connection string")
cobra.CheckErr(viper.BindPFlag(configs.DATABASE_URL, Cmd.Flags().Lookup("database-url")))

Cmd.Flags().IntVar(&issuanceFee, "issuance-fee", 500, "Issuance fee in basis points (e.g., 500 = 5%, 250 = 2.5%, 1000 = 10%)")
cobra.CheckErr(viper.BindPFlag(configs.ISSUANCE_FEE, Cmd.Flags().Lookup("issuance-fee")))

// Contracts flags
Cmd.Flags().StringVar(&adminAddress, "admin-address", "", "Address of the admin user")
cobra.CheckErr(viper.BindPFlag(configs.ADMIN_ADDRESS, Cmd.Flags().Lookup("admin-address")))
Expand All @@ -63,9 +65,6 @@ func init() {
Cmd.Flags().StringVar(&safeErc1155MintAddress, "safe-erc1155-mint-address", "", "Address for safe ERC1155 minting")
cobra.CheckErr(viper.BindPFlag(configs.SAFE_ERC1155_MINT_ADDRESS, Cmd.Flags().Lookup("safe-erc1155-mint-address")))

Cmd.Flags().IntVar(&issuanceFee, "issuance-fee", 500, "Issuance fee in basis points (e.g., 500 = 5%, 250 = 2.5%, 1000 = 10%)")
cobra.CheckErr(viper.BindPFlag(configs.ISSUANCE_FEE, Cmd.Flags().Lookup("issuance-fee")))

Cmd.PreRunE = func(cmd *cobra.Command, args []string) error {
var err error
cfg, err = configs.LoadRollupConfig()
Expand Down
2 changes: 1 addition & 1 deletion docs/configs.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ DO NOT EDIT.
-->

<!-- markdownlint-disable line_length -->
# rollup Rollup Configuration
# Rollup Configuration

This file documents the configuration options.

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/go-playground/validator/v10 v10.26.0
github.com/google/wire v0.6.0
github.com/holiman/uint256 v1.3.2
github.com/rollmelette/rollmelette v0.0.0-20251226042236-fcdb709c5635
github.com/rollmelette/rollmelette v0.1.2
github.com/spf13/cobra v1.9.1
github.com/spf13/viper v1.20.1
github.com/stretchr/testify v1.10.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRI
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
github.com/rollmelette/rollmelette v0.0.0-20251226042236-fcdb709c5635 h1:UpAdECibktivbj1ZNF+sanRCNFmdSdGacQAhC3oVzxk=
github.com/rollmelette/rollmelette v0.0.0-20251226042236-fcdb709c5635/go.mod h1:vi9BDrdDsL59Qb+AsuxHktniuXZ68esNc/UJlgW5fOI=
github.com/rollmelette/rollmelette v0.1.2 h1:flXAq1d0tBruXg2x6nAdeu7ZwvBpbUpt+dHawaEojrU=
github.com/rollmelette/rollmelette v0.1.2/go.mod h1:vi9BDrdDsL59Qb+AsuxHktniuXZ68esNc/UJlgW5fOI=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/sagikazarmark/locafero v0.7.0 h1:5MqpDsTGNDhY8sGp0Aowyf0qKsPrhewaLSsFaodPcyo=
github.com/sagikazarmark/locafero v0.7.0/go.mod h1:2za3Cg5rMaTMoG/2Ulr9AwtFaIppKXTRYnozin4aB5k=
Expand Down
20 changes: 10 additions & 10 deletions internal/domain/entity/issuance.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"errors"
"fmt"

"github.com/2025-2A-T20-G91-INTERNO/src/rollup/pkg/types"
. "github.com/2025-2A-T20-G91-INTERNO/src/rollup/pkg/types"
"github.com/holiman/uint256"
)

Expand All @@ -28,11 +28,11 @@ type Issuance struct {
Title string `json:"title,omitempty" gorm:"not null"`
Description string `json:"description,omitempty" gorm:"not null"`
Promotion string `json:"promotion,omitempty" gorm:"not null"`
Token types.Address `json:"token,omitempty" gorm:"types:text;not null"`
CreatorAddress types.Address `json:"creator_address,omitempty" gorm:"types:text;not null"`
CollateralAddress types.Address `json:"collateral_address,omitempty" gorm:"types:text;not null"`
Token Address `json:"token,omitempty" gorm:"types:text;not null"`
CreatorAddress Address `json:"creator_address,omitempty" gorm:"types:text;not null"`
CollateralAddress Address `json:"collateral_address,omitempty" gorm:"types:text;not null"`
CollateralAmount *uint256.Int `json:"collateral_amount,omitempty" gorm:"types:text;not null"`
BadgeAddress types.Address `json:"badge_address,omitempty" gorm:"types:text;not null"`
BadgeAddress Address `json:"badge_address,omitempty" gorm:"types:text;not null"`
DebtIssued *uint256.Int `json:"debt_issued,omitempty" gorm:"types:text;not null"`
MaxInterestRate *uint256.Int `json:"max_interest_rate,omitempty" gorm:"types:text;not null"`
TotalObligation *uint256.Int `json:"total_obligation,omitempty" gorm:"types:text;not null;default:0"`
Expand All @@ -45,7 +45,7 @@ type Issuance struct {
UpdatedAt int64 `json:"updated_at,omitempty" gorm:"default:0"`
}

func NewIssuance(title string, description string, promotion string, token types.Address, creatorAddress types.Address, collateralAddress types.Address, collateralAmount *uint256.Int, badgeAddress types.Address, debtIssued *uint256.Int, maxInterestRate *uint256.Int, closesAt int64, maturityAt int64, createdAt int64) (*Issuance, error) {
func NewIssuance(title string, description string, promotion string, token Address, creatorAddress Address, collateralAddress Address, collateralAmount *uint256.Int, badgeAddress Address, debtIssued *uint256.Int, maxInterestRate *uint256.Int, closesAt int64, maturityAt int64, createdAt int64) (*Issuance, error) {
issuance := &Issuance{
Title: title,
Description: description,
Expand Down Expand Up @@ -79,19 +79,19 @@ func (a *Issuance) validate() error {
if a.Promotion == "" {
return fmt.Errorf("%w: promotion cannot be empty", ErrInvalidIssuance)
}
if a.Token == (types.Address{}) {
if a.Token == (Address{}) {
return fmt.Errorf("%w: invalid token address", ErrInvalidIssuance)
}
if a.CreatorAddress == (types.Address{}) {
if a.CreatorAddress == (Address{}) {
return fmt.Errorf("%w: invalid creator address", ErrInvalidIssuance)
}
if a.CollateralAddress == (types.Address{}) {
if a.CollateralAddress == (Address{}) {
return fmt.Errorf("%w: invalid collateral address", ErrInvalidIssuance)
}
if a.CollateralAmount.Sign() == 0 {
return fmt.Errorf("%w: collateral amount cannot be zero", ErrInvalidIssuance)
}
if a.BadgeAddress == (types.Address{}) {
if a.BadgeAddress == (Address{}) {
return fmt.Errorf("%w: invalid badge address", ErrInvalidIssuance)
}
if a.DebtIssued.Sign() == 0 {
Expand Down
24 changes: 12 additions & 12 deletions internal/domain/entity/order.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"errors"
"fmt"

"github.com/2025-2A-T20-G91-INTERNO/src/rollup/pkg/types"
. "github.com/2025-2A-T20-G91-INTERNO/src/rollup/pkg/types"
"github.com/holiman/uint256"
)

Expand All @@ -26,23 +26,23 @@ const (
)

type Order struct {
Id uint `json:"id" gorm:"primaryKey"`
IssuanceId uint `json:"issuance_id" gorm:"not null;index"`
InvestorAddress types.Address `json:"investor_address,omitempty" gorm:"not null"`
Amount *uint256.Int `json:"amount,omitempty" gorm:"types:text;not null"`
InterestRate *uint256.Int `json:"interest_rate,omitempty" gorm:"types:text;not null"`
State OrderState `json:"state,omitempty" gorm:"types:text;not null"`
CreatedAt int64 `json:"created_at,omitempty" gorm:"not null"`
UpdatedAt int64 `json:"updated_at,omitempty" gorm:"default:0"`
Id uint `json:"id" gorm:"primaryKey"`
IssuanceId uint `json:"issuance_id" gorm:"not null;index"`
InvestorAddress Address `json:"investor_address,omitempty" gorm:"not null"`
Amount *uint256.Int `json:"amount,omitempty" gorm:"types:text;not null"`
InterestRate *uint256.Int `json:"interest_rate,omitempty" gorm:"types:text;not null"`
State OrderState `json:"state,omitempty" gorm:"types:text;not null"`
CreatedAt int64 `json:"created_at,omitempty" gorm:"not null"`
UpdatedAt int64 `json:"updated_at,omitempty" gorm:"default:0"`
}

func NewOrder(issuanceId uint, investorAddress types.Address, amount *uint256.Int, interestRate *uint256.Int, createdAt int64) (*Order, error) {
func NewOrder(issuanceId uint, investorAddress Address, amount *uint256.Int, interestRate *uint256.Int, state OrderState, createdAt int64) (*Order, error) {
order := &Order{
IssuanceId: issuanceId,
InvestorAddress: investorAddress,
Amount: amount,
InterestRate: interestRate,
State: OrderStatePending,
State: state,
CreatedAt: createdAt,
}
if err := order.validate(); err != nil {
Expand All @@ -55,7 +55,7 @@ func (b *Order) validate() error {
if b.IssuanceId == 0 {
return fmt.Errorf("%w: Issuance ID cannot be zero", ErrInvalidOrder)
}
if b.InvestorAddress == (types.Address{}) {
if b.InvestorAddress == (Address{}) {
return fmt.Errorf("%w: investor address cannot be empty", ErrInvalidOrder)
}
if b.Amount.Sign() <= 0 {
Expand Down
8 changes: 4 additions & 4 deletions internal/domain/entity/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"errors"
"fmt"

"github.com/2025-2A-T20-G91-INTERNO/src/rollup/pkg/types"
. "github.com/2025-2A-T20-G91-INTERNO/src/rollup/pkg/types"
)

var (
Expand All @@ -24,13 +24,13 @@ const (
type User struct {
Id uint `json:"id" gorm:"primaryKey"`
Role UserRole `json:"role,omitempty" gorm:"not null"`
Address types.Address `json:"address,omitempty" gorm:"types:text;uniqueIndex;not null"`
Address Address `json:"address,omitempty" gorm:"types:text;uniqueIndex;not null"`
SocialAccounts []*SocialAccount `json:"social_accounts,omitempty" gorm:"foreignKey:UserId;constraint:OnDelete:CASCADE"`
CreatedAt int64 `json:"created_at,omitempty" gorm:"not null"`
UpdatedAt int64 `json:"updated_at,omitempty" gorm:"default:0"`
}

func NewUser(role string, address types.Address, createdAt int64) (*User, error) {
func NewUser(role string, address Address, createdAt int64) (*User, error) {
user := &User{
Role: UserRole(role),
SocialAccounts: []*SocialAccount{},
Expand All @@ -50,7 +50,7 @@ func (u *User) validate() error {
if u.Role != UserRoleAdmin && u.Role != UserRoleCreator && u.Role != UserRoleInvestor && u.Role != UserRoleVerifier {
return fmt.Errorf("%w: invalid role", ErrInvalidUser)
}
if u.Address == (types.Address{}) {
if u.Address == (Address{}) {
return fmt.Errorf("%w: address cannot be empty", ErrInvalidUser)
}
if u.CreatedAt == 0 {
Expand Down
13 changes: 7 additions & 6 deletions internal/infra/repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package repository

import (
"github.com/2025-2A-T20-G91-INTERNO/src/rollup/internal/domain/entity"
types "github.com/2025-2A-T20-G91-INTERNO/src/rollup/pkg/types"
. "github.com/2025-2A-T20-G91-INTERNO/src/rollup/pkg/types"
)

type IssuanceRepository interface {
CreateIssuance(issuance *entity.Issuance) (*entity.Issuance, error)
FindIssuancesByCreatorAddress(creator types.Address) ([]*entity.Issuance, error)
FindIssuancesByInvestorAddress(investor types.Address) ([]*entity.Issuance, error)
FindIssuancesByCreatorAddress(creator Address) ([]*entity.Issuance, error)
FindOngoingIssuanceByCreatorAddress(creator Address) (*entity.Issuance, error)
FindIssuancesByInvestorAddress(investor Address) ([]*entity.Issuance, error)
FindIssuanceById(id uint) (*entity.Issuance, error)
FindAllIssuances() ([]*entity.Issuance, error)
UpdateIssuance(Issuance *entity.Issuance) (*entity.Issuance, error)
Expand All @@ -19,7 +20,7 @@ type OrderRepository interface {
FindOrderById(id uint) (*entity.Order, error)
FindOrdersByIssuanceId(id uint) ([]*entity.Order, error)
FindOrdersByState(issuanceId uint, state string) ([]*entity.Order, error)
FindOrdersByInvestorAddress(investor types.Address) ([]*entity.Order, error)
FindOrdersByInvestorAddress(investor Address) ([]*entity.Order, error)
FindAllOrders() ([]*entity.Order, error)
UpdateOrder(order *entity.Order) (*entity.Order, error)
DeleteOrder(id uint) error
Expand All @@ -35,9 +36,9 @@ type SocialAccountRepository interface {
type UserRepository interface {
CreateUser(user *entity.User) (*entity.User, error)
FindUsersByRole(role string) ([]*entity.User, error)
FindUserByAddress(address types.Address) (*entity.User, error)
FindUserByAddress(address Address) (*entity.User, error)
FindAllUsers() ([]*entity.User, error)
DeleteUser(address types.Address) error
DeleteUser(address Address) error
}

type Repository interface {
Expand Down
44 changes: 29 additions & 15 deletions internal/infra/repository/sqlite/issuance.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"

"github.com/2025-2A-T20-G91-INTERNO/src/rollup/internal/domain/entity"
"github.com/2025-2A-T20-G91-INTERNO/src/rollup/pkg/types"
. "github.com/2025-2A-T20-G91-INTERNO/src/rollup/pkg/types"
"gorm.io/gorm"
)

Expand All @@ -16,49 +16,63 @@ func (r *SQLiteRepository) CreateIssuance(input *entity.Issuance) (*entity.Issua
}

func (r *SQLiteRepository) FindIssuanceById(id uint) (*entity.Issuance, error) {
var Issuance entity.Issuance
var issuance entity.Issuance
if err := r.Db.
Preload("Orders").
First(&Issuance, id).Error; err != nil {
First(&issuance, id).Error; err != nil {
if err == gorm.ErrRecordNotFound {
return nil, entity.ErrIssuanceNotFound
}
return nil, fmt.Errorf("failed to find issuance by id: %w", err)
}
return &Issuance, nil
return &issuance, nil
}

func (r *SQLiteRepository) FindAllIssuances() ([]*entity.Issuance, error) {
var Issuances []*entity.Issuance
var issuance []*entity.Issuance
if err := r.Db.
Preload("Orders").
Find(&Issuances).Error; err != nil {
Find(&issuance).Error; err != nil {
return nil, fmt.Errorf("failed to find all issuances: %w", err)
}
return Issuances, nil
return issuance, nil
}

func (r *SQLiteRepository) FindIssuancesByInvestorAddress(investor types.Address) ([]*entity.Issuance, error) {
var Issuances []*entity.Issuance
func (r *SQLiteRepository) FindIssuancesByInvestorAddress(investor Address) ([]*entity.Issuance, error) {
var issuance []*entity.Issuance
if err := r.Db.
Joins("JOIN orders ON orders.issuance_id = issuances.id").
Where("orders.investor_address = ?", investor).
Preload("Orders").
Find(&Issuances).Error; err != nil {
Find(&issuance).Error; err != nil {
return nil, fmt.Errorf("failed to find Issuances by investor: %w", err)
}
return Issuances, nil
return issuance, nil
}

func (r *SQLiteRepository) FindIssuancesByCreatorAddress(creator types.Address) ([]*entity.Issuance, error) {
var Issuances []*entity.Issuance
func (r *SQLiteRepository) FindIssuancesByCreatorAddress(creator Address) ([]*entity.Issuance, error) {
var issuance []*entity.Issuance
if err := r.Db.
Where("creator_address = ?", creator).
Preload("Orders").
Find(&Issuances).Error; err != nil {
Find(&issuance).Error; err != nil {
return nil, fmt.Errorf("failed to find issuances by creator: %w", err)
}
return Issuances, nil
return issuance, nil
}

func (r *SQLiteRepository) FindOngoingIssuanceByCreatorAddress(creator Address) (*entity.Issuance, error) {
var issuance entity.Issuance
if err := r.Db.
Where("creator_address = ? AND state = ?", creator, entity.IssuanceStateOngoing).
Preload("Orders").
First(&issuance).Error; err != nil {
if err == gorm.ErrRecordNotFound {
return nil, entity.ErrIssuanceNotFound
}
return nil, fmt.Errorf("failed to find ongoing issuance by creator: %w", err)
}
return &issuance, nil
}

func (r *SQLiteRepository) UpdateIssuance(input *entity.Issuance) (*entity.Issuance, error) {
Expand Down
4 changes: 2 additions & 2 deletions internal/infra/repository/sqlite/order.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"

"github.com/2025-2A-T20-G91-INTERNO/src/rollup/internal/domain/entity"
"github.com/2025-2A-T20-G91-INTERNO/src/rollup/pkg/types"
. "github.com/2025-2A-T20-G91-INTERNO/src/rollup/pkg/types"
"gorm.io/gorm"
)

Expand Down Expand Up @@ -44,7 +44,7 @@ func (r *SQLiteRepository) FindOrdersByState(issuanceId uint, state string) ([]*
return orders, nil
}

func (r *SQLiteRepository) FindOrdersByInvestorAddress(investor types.Address) ([]*entity.Order, error) {
func (r *SQLiteRepository) FindOrdersByInvestorAddress(investor Address) ([]*entity.Order, error) {
var orders []*entity.Order
if err := r.Db.Where("investor_address = ?", investor).Find(&orders).Error; err != nil {
return nil, fmt.Errorf("failed to find orders by investor: %w", err)
Expand Down
12 changes: 6 additions & 6 deletions internal/infra/repository/sqlite/sqlite.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

"github.com/2025-2A-T20-G91-INTERNO/src/rollup/configs"
"github.com/2025-2A-T20-G91-INTERNO/src/rollup/internal/domain/entity"
types "github.com/2025-2A-T20-G91-INTERNO/src/rollup/pkg/types"
. "github.com/2025-2A-T20-G91-INTERNO/src/rollup/pkg/types"
)

type SQLiteRepository struct {
Expand Down Expand Up @@ -73,7 +73,7 @@ func NewSQLiteRepository(ctx context.Context, conn string) (*SQLiteRepository, e

configs.SetDefaults()

var adminAddr, verifierAddr types.Address
var adminAddr, verifierAddr Address

if isMemory {
a, err := configs.GetAdminAddressTest()
Expand All @@ -82,31 +82,31 @@ func NewSQLiteRepository(ctx context.Context, conn string) (*SQLiteRepository, e
} else if err == configs.ErrNotDefined {
return nil, fmt.Errorf("rollup_ADMIN_ADDRESS_TEST is required for the rollup service: %w", err)
}
adminAddr = types.HexToAddress(a.Hex())
adminAddr = HexToAddress(a.Hex())

v, err := configs.GetVerifierAddressTest()
if err != nil && err != configs.ErrNotDefined {
return nil, fmt.Errorf("failed to get rollup_VERIFIER_ADDRESS_TEST: %w", err)
} else if err == configs.ErrNotDefined {
return nil, fmt.Errorf("rollup_VERIFIER_ADDRESS_TEST is required for the rollup service: %w", err)
}
verifierAddr = types.HexToAddress(v.Hex())
verifierAddr = HexToAddress(v.Hex())
} else {
a, err := configs.GetAdminAddress()
if err != nil && err != configs.ErrNotDefined {
return nil, fmt.Errorf("failed to get rollup_ADMIN_ADDRESS: %w", err)
} else if err == configs.ErrNotDefined {
return nil, fmt.Errorf("rollup_ADMIN_ADDRESS is required for the rollup service: %w", err)
}
adminAddr = types.HexToAddress(a.Hex())
adminAddr = HexToAddress(a.Hex())

v, err := configs.GetVerifierAddress()
if err != nil && err != configs.ErrNotDefined {
return nil, fmt.Errorf("failed to get rollup_VERIFIER_ADDRESS: %w", err)
} else if err == configs.ErrNotDefined {
return nil, fmt.Errorf("rollup_VERIFIER_ADDRESS is required for the rollup service: %w", err)
}
verifierAddr = types.HexToAddress(v.Hex())
verifierAddr = HexToAddress(v.Hex())
}

baseTime := time.Now().Unix()
Expand Down
Loading
Loading