Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
13e9f5f
Add see field in user profile response
hzmangel Jul 30, 2025
d1607ac
feat(asset_records): add asset transfer functionality with validation
hzmangel Jul 30, 2025
de3c430
feat(model): add UserAssetTransferLog to MigrateTables
hzmangel Jul 30, 2025
edb3f6f
refactor(asset-transfer): simplify transfer logic and improve error h…
hzmangel Jul 31, 2025
051bad7
Move see asset fetch to correct place, and add const for SEE to avoid…
hzmangel Aug 1, 2025
ef4e4f0
fix(user_asset_record): normalize asset names to uppercase for consis…
hzmangel Aug 1, 2025
187f038
refactor(asset_records): rename default asset name and improve transf…
hzmangel Aug 1, 2025
7eeedf1
feat(asset_records): add wallet validation and formatting in transfer
hzmangel Aug 1, 2025
8f0fcb1
Add new const value for budget_p2 and asset name
hzmangel Aug 7, 2025
76a2f19
Update magic string into const variable
hzmangel Aug 7, 2025
b073150
Handle budget component p2 and change code to switch mode
hzmangel Aug 7, 2025
0e77284
Add some debug log
hzmangel Aug 8, 2025
652119d
Move budget_p2 processing to another branch
hzmangel Aug 8, 2025
9cd607c
Remove test log
hzmangel Aug 8, 2025
4f9aa37
feat(treasury): add SEE asset support and refactor asset constants
hzmangel Aug 8, 2025
afbafee
Update SEE related stats function
hzmangel Aug 8, 2025
9c9cbd6
Try to fix query of sum
hzmangel Aug 8, 2025
4a83181
Another fix for get total asset amount
hzmangel Aug 8, 2025
0f4b00d
Fix score leaderboard error
hzmangel Aug 8, 2025
16cf1a6
Fix scr qurey error
hzmangel Aug 8, 2025
6bd0dfc
Fix asset query error
hzmangel Aug 8, 2025
7a34c05
Fix query error
hzmangel Aug 8, 2025
ad160c9
Fix sum query
hzmangel Aug 8, 2025
1db0586
Fix auto xfer SCR task to send WANG
hzmangel Aug 9, 2025
a554c68
Some text changes to remove SCR
hzmangel Aug 9, 2025
3dd0305
Add SELECT FOR UPDATE locking to prevent race conditions of transferi…
hzmangel Aug 9, 2025
846ee82
Merge pull request #209 from Taoist-Labs/feature/see_backend
hzmangel Aug 9, 2025
f5b06d2
Fix minus with text error
hzmangel Aug 9, 2025
28aed8a
Update deps
hzmangel Aug 9, 2025
d13ff24
Fix asset add error
hzmangel Aug 9, 2025
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
3 changes: 3 additions & 0 deletions cmd/apiserver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
admin_inject "github.com/theseed-labs/os-backend/internal_inject/admin"
appbundles_inject "github.com/theseed-labs/os-backend/internal_inject/app_bundles"
applications_inject "github.com/theseed-labs/os-backend/internal_inject/applications"
assetrecords_inject "github.com/theseed-labs/os-backend/internal_inject/asset_records"
cityhall_inject "github.com/theseed-labs/os-backend/internal_inject/city_hall"
common_budget_sources_inject "github.com/theseed-labs/os-backend/internal_inject/common_budget_sources"
datasrv_inject "github.com/theseed-labs/os-backend/internal_inject/data_srv"
Expand Down Expand Up @@ -261,6 +262,8 @@ func setupRouter(cfg *config.Config, db *gorm.DB, enforcer *casbin.SyncedEnforce

// publicity
publicity_inject.Register(v1)
// asset records
assetrecords_inject.Register(v1)
}
// --> no auth required
{
Expand Down
10 changes: 9 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ require (
github.com/casbin/casbin/v2 v2.77.2
github.com/casbin/gorm-adapter/v3 v3.20.0
github.com/ethereum/go-ethereum v1.13.8
github.com/facebookgo/inject v0.0.0-20180706035515-f23751cae28b
github.com/getsentry/sentry-go v0.25.0
github.com/gin-contrib/cors v1.4.0
github.com/gin-contrib/gzip v0.0.6
Expand All @@ -34,6 +35,7 @@ require (
github.com/samber/lo v1.38.1
github.com/shopspring/decimal v1.3.1
github.com/spruceid/siwe-go v0.2.1
github.com/stretchr/testify v1.8.4
github.com/swaggo/files v1.0.1
github.com/swaggo/gin-swagger v1.6.0
github.com/swaggo/swag v1.16.2
Expand All @@ -51,6 +53,7 @@ require (
gorm.io/datatypes v1.2.0
gorm.io/driver/mysql v1.5.2
gorm.io/driver/postgres v1.5.0
gorm.io/driver/sqlite v1.4.3
gorm.io/gorm v1.25.5
)

Expand Down Expand Up @@ -83,6 +86,7 @@ require (
github.com/containerd/log v0.1.0 // indirect
github.com/cpuguy83/dockercfg v0.3.1 // indirect
github.com/crate-crypto/go-kzg-4844 v0.7.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dchest/uniuri v1.2.0 // indirect
github.com/deckarep/golang-set/v2 v2.1.0 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0 // indirect
Expand All @@ -92,8 +96,10 @@ require (
github.com/docker/go-units v0.5.0 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/ethereum/c-kzg-4844 v0.4.0 // indirect
github.com/facebookgo/inject v0.0.0-20180706035515-f23751cae28b // indirect
github.com/facebookgo/ensure v0.0.0-20200202191622-63f1cf65ac4c // indirect
github.com/facebookgo/stack v0.0.0-20160209184415-751773369052 // indirect
github.com/facebookgo/structtag v0.0.0-20150214074306-217e25fb9691 // indirect
github.com/facebookgo/subset v0.0.0-20200203212716-c811ad88dec4 // indirect
github.com/felixge/httpsnoop v1.0.3 // indirect
github.com/forta-network/go-multicall v0.0.0-20230701154355-9467c4ddaa83 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
Expand Down Expand Up @@ -142,6 +148,7 @@ require (
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mattn/go-sqlite3 v1.14.16 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/microsoft/go-mssqldb v0.17.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
Expand All @@ -159,6 +166,7 @@ require (
github.com/patrickmn/go-cache v2.1.0+incompatible // indirect
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
github.com/prometheus/client_model v0.4.1-0.20230718164431-9a2bf3000d16 // indirect
github.com/prometheus/common v0.44.0 // indirect
Expand Down
7 changes: 7 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,16 @@ github.com/ethereum/c-kzg-4844 v0.4.0 h1:3MS1s4JtA868KpJxroZoepdV0ZKBp3u/O5HcZ7R
github.com/ethereum/c-kzg-4844 v0.4.0/go.mod h1:VewdlzQmpT5QSrVhbBuGoCdFJkpaJlO1aQputP83wc0=
github.com/ethereum/go-ethereum v1.13.8 h1:1od+thJel3tM52ZUNQwvpYOeRHlbkVFZ5S8fhi0Lgsg=
github.com/ethereum/go-ethereum v1.13.8/go.mod h1:sc48XYQxCzH3fG9BcrXCOOgQk2JfZzNAmIKnceogzsA=
github.com/facebookgo/ensure v0.0.0-20200202191622-63f1cf65ac4c h1:8ISkoahWXwZR41ois5lSJBSVw4D0OV19Ht/JSTzvSv0=
github.com/facebookgo/ensure v0.0.0-20200202191622-63f1cf65ac4c/go.mod h1:Yg+htXGokKKdzcwhuNDwVvN+uBxDGXJ7G/VN1d8fa64=
github.com/facebookgo/inject v0.0.0-20180706035515-f23751cae28b h1:V6c4/dSTNhSaNn4c5ulbakfv277qCvs7byFYv7P83iQ=
github.com/facebookgo/inject v0.0.0-20180706035515-f23751cae28b/go.mod h1:oO8UHw+fDHjDsk4CTy/E96WDzFUYozAtBAaGNoVL0+c=
github.com/facebookgo/stack v0.0.0-20160209184415-751773369052 h1:JWuenKqqX8nojtoVVWjGfOF9635RETekkoH6Cc9SX0A=
github.com/facebookgo/stack v0.0.0-20160209184415-751773369052/go.mod h1:UbMTZqLaRiH3MsBH8va0n7s1pQYcu3uTb8G4tygF4Zg=
github.com/facebookgo/structtag v0.0.0-20150214074306-217e25fb9691 h1:KnnwHN59Jxec0htA2pe/i0/WI9vxXLQifdhBrP3lqcQ=
github.com/facebookgo/structtag v0.0.0-20150214074306-217e25fb9691/go.mod h1:sKLL1iua/0etWfo/nPCmyz+v2XDMXy+Ho53W7RAuZNY=
github.com/facebookgo/subset v0.0.0-20200203212716-c811ad88dec4 h1:7HZCaLC5+BZpmbhCOZJ293Lz68O7PYrF2EzeiFMwCLk=
github.com/facebookgo/subset v0.0.0-20200203212716-c811ad88dec4/go.mod h1:5tD+neXqOorC30/tWg0LCSkrqj/AR6gu8yY8/fpw1q0=
github.com/felixge/httpsnoop v1.0.3 h1:s/nj+GCswXYzN5v2DpNMuMQYe+0DDwt5WVCU6CWBdXk=
github.com/felixge/httpsnoop v1.0.3/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
github.com/fjl/memsize v0.0.0-20190710130421-bcb5799ab5e5 h1:FtmdgXiUlNeRsoNMFlKLDt+S+6hbjVMEW6RGQ7aUf7c=
Expand Down Expand Up @@ -452,6 +458,7 @@ github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APP
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU=
github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/mattn/go-sqlite3 v1.14.15/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
github.com/mattn/go-sqlite3 v1.14.16 h1:yOQRA0RpS5PFz/oikGwBEqvAWhWg5ufRz4ETLjwpU1Y=
github.com/mattn/go-sqlite3 v1.14.16/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo=
Expand Down
17 changes: 9 additions & 8 deletions internal/api/proposal/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -1777,35 +1777,36 @@ func CreateProjectFromAutoTasks(db *gorm.DB, proposalId uint) (*model.Project, e

for _, pComponentRecord := range pComponents {
if compName, found := getProposalComponentIdNameMapping(db)[pComponentRecord.ComponentID]; found {
if compName == internal.ComponentNameBudgetP1 {
switch compName {
case internal.ComponentNameBudgetP1:
var budgetParams budgetComponentDataP1
err := json.Unmarshal([]byte(pComponentRecord.Data), &budgetParams)
err = json.Unmarshal([]byte(pComponentRecord.Data), &budgetParams)
if err != nil {
log.Error().Msgf("unmarshal project deliverables data error: %+v", err)
return nil, err
}

projectBudgetRcds = budgetParams.prepareBudgetRecords(proposalId)
} else if compName == internal.ComponentNameBudget {
case internal.ComponentNameBudget, internal.ComponentNameBudgetP2:
var budgetParams budgetComponentData
err := json.Unmarshal([]byte(pComponentRecord.Data), &budgetParams)
err = json.Unmarshal([]byte(pComponentRecord.Data), &budgetParams)
if err != nil {
log.Error().Msgf("unmarshal project deliverables data error: %+v", err)
return nil, err
}

projectBudgetRcds = budgetParams.prepareBudgetRecords(proposalId)
} else if compName == internal.ComponentNameDeliverables {
case internal.ComponentNameDeliverables:
var deliverableParams commonCreateProjectRelatedData
err := json.Unmarshal([]byte(pComponentRecord.Data), &deliverableParams)
err = json.Unmarshal([]byte(pComponentRecord.Data), &deliverableParams)
if err != nil {
log.Error().Msgf("unmarshal project deliverables data error: %+v", err)
return nil, err
}
newProjectData.Deliverable = deliverableParams.Desc
} else if compName == internal.ComponentNameDeadline {
case internal.ComponentNameDeadline:
var deadlineParams commonCreateProjectRelatedData
err := json.Unmarshal([]byte(pComponentRecord.Data), &deadlineParams)
err = json.Unmarshal([]byte(pComponentRecord.Data), &deadlineParams)
if err != nil {
log.Error().Msgf("unmarshal project deadline data error: %+v", err)
return nil, err
Expand Down
3 changes: 2 additions & 1 deletion internal/api/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,9 @@ func RefreshSeepassDataCache(sppClient *sdk.SppClient, wallet string) (*sdk.Seep

func CreateAutoTransferScrTask(db *gorm.DB, applications []*model.Application, proposalId uint) error {
// Issue send SCR tasks
// 20250809 - Change the SCR into WANG, and only change the asset name in DB, but keep the variable name to minimal changes
scrApplications := lo.Filter(applications, func(app *model.Application, _ int) bool {
return app.Type == model.ApplicationNewReward && app.AssetName == "SCR"
return app.Type == model.ApplicationNewReward && app.AssetName == internal.AssetNameWANG
})

if len(scrApplications) > 0 {
Expand Down
24 changes: 20 additions & 4 deletions internal/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ const (

const (
ComponentNameBudgetP1 = "budget_p1"
ComponentNameBudgetP2 = "budget_p2"
ComponentNameBudget = "budget"
ComponentNameDeliverables = "deliverables"
ComponentNameDeadline = "deadline"
Expand All @@ -134,15 +135,30 @@ type DecimalsAndContractAddr struct {
Addr string
}

var (
AssetNameWANG = "WANG"
AssetNameSCR = "SCR"
AssetNameSEE = "SEE"
AssetNameUSDT = "USDT"
AssetNameUSDC = "USDC"

// This is for DB query of USD* asssets
AssetPrefixUSD = "USD"

SNSInviteRewardsToken = AssetNameWANG
)

// AssertDecimalsAndContractAddr supported token for sending application to QuickAccounting
var AssertDecimalsAndContractAddr = map[string]*DecimalsAndContractAddr{
"SCR": {Decimals: 18, Addr: ScrContractAddr},
"USDT": {Decimals: 6, Addr: USDTContractAddr},
AssetNameSCR: {Decimals: 18, Addr: ScrContractAddr},
AssetNameWANG: {Decimals: 18, Addr: ScrContractAddr},
AssetNameSEE: {Decimals: 18, Addr: ""},
AssetNameUSDT: {Decimals: 6, Addr: USDTContractAddr},
AssetNameUSDC: {Decimals: 6, Addr: ""},
}

const (
SNSInviteRewardsToken = "SCR"
SNSInviteItem = "邀请 SNS"
SNSInviteItem = "邀请 SNS"
)

const (
Expand Down
10 changes: 5 additions & 5 deletions internal/model/treasury_asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ func (r *TreasuryAsset) ToTreasuryAssetsResponse(db *gorm.DB) (*TreasuryAssetsRe

// Calculate total amount
for _, detailedRcd := range r.DetailedRecords {
if strings.HasPrefix(detailedRcd.AssetName, "USD") {
if strings.HasPrefix(detailedRcd.AssetName, internal.AssetPrefixUSD) {
tokenTotal = tokenTotal.Add(detailedRcd.TotalAmount)
} else if strings.EqualFold(detailedRcd.AssetName, "SCR") {
} else if strings.EqualFold(detailedRcd.AssetName, internal.AssetNameWANG) {
creditTotal = creditTotal.Add(detailedRcd.TotalAmount)
} else {
log.Warn().Msgf("non token or credit asset %s, ignore the treasury record: %+v", detailedRcd.AssetName, detailedRcd)
Expand All @@ -85,13 +85,13 @@ func (r *TreasuryAsset) ToTreasuryAssetsResponse(db *gorm.DB) (*TreasuryAssetsRe
creditUsed = decimal.Zero
tokenUsed = decimal.Zero
for _, application := range applications {
if strings.HasPrefix(application.AssetName, "USD") {
if strings.HasPrefix(application.AssetName, internal.AssetPrefixUSD) {
// only calculate completed USD
if application.State == ApplicationStateCompleted {
tokenUsed = tokenUsed.Add(application.AssetAmount)
}
} else if strings.EqualFold(application.AssetName, "SCR") {
// calculate processing and completed SCR
} else if strings.EqualFold(application.AssetName, internal.AssetNameWANG) {
// calculate processing and completed asset
creditUsed = creditUsed.Add(application.AssetAmount)
} else {
log.Warn().Msgf("non token or credit asset %s, ignore the application record: %+v", application.AssetName, application)
Expand Down
4 changes: 4 additions & 0 deletions internal/model/typedef.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,10 @@ type TreasuryAssetsResponse struct {
CreditUsedAmount decimal.Decimal `json:"credit_used_amount"`
TokenTotalAmount decimal.Decimal `json:"token_total_amount"`
TokenUsedAmount decimal.Decimal `json:"token_used_amount"`

// Total issued SEE and season used SEE. The variable name here is to keep with old naming rule
SeeTotalAmount decimal.Decimal `json:"see_total_amount"`
SeeUsedAmount decimal.Decimal `json:"see_used_amount"`
}

// NewApplicationRequest is used to save new application request data passed from frontend
Expand Down
9 changes: 5 additions & 4 deletions internal/model/user_asset_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package model

import (
"fmt"
"strings"
"time"

"github.com/shopspring/decimal"
Expand Down Expand Up @@ -49,7 +50,7 @@ func (*userAssetRecordModel) FindWithUserWalletAndAssetProps(db *gorm.DB, userWa
}
}

querySeg := db.Where(&UserAssetRecord{UserWallet: formattedUserWallet, AssetName: assetName})
querySeg := db.Where(&UserAssetRecord{UserWallet: formattedUserWallet, AssetName: strings.ToUpper(assetName)})
return QueryRows[UserAssetRecord](querySeg, nil)
}

Expand All @@ -66,7 +67,7 @@ func (*userAssetRecordModel) CreateOrUpdate(db *gorm.DB, userWallet string, asse
if len(assetRecords) == 0 {
return db.Save(&UserAssetRecord{
UserWallet: common.FormatUserWallet(userWallet),
AssetName: assetName,
AssetName: strings.ToUpper(assetName),
DealtAmount: dealtAmount,
ProcessingAmount: processingAmount,
}).Error
Expand All @@ -79,7 +80,7 @@ func (*userAssetRecordModel) CreateOrUpdate(db *gorm.DB, userWallet string, asse

// Rollback extracts processing and dealt amount from records
func (*userAssetRecordModel) Rollback(db *gorm.DB, userWallet string, assetName string, processingAmount, dealtAmount decimal.Decimal) error {
assetRecords, err := UserAssetRecordModel.FindWithUserWalletAndAssetProps(db, common.FormatUserWallet(userWallet), assetName)
assetRecords, err := UserAssetRecordModel.FindWithUserWalletAndAssetProps(db, common.FormatUserWallet(userWallet), strings.ToUpper(assetName))
if err != nil {
return err
}
Expand All @@ -95,7 +96,7 @@ func (*userAssetRecordModel) Rollback(db *gorm.DB, userWallet string, assetName
}

func (*userAssetRecordModel) CompleteAssetTransaction(db *gorm.DB, userWallet string, assetName string, amountToBeDealt decimal.Decimal) error {
assetRecords, err := UserAssetRecordModel.FindWithUserWalletAndAssetProps(db, common.FormatUserWallet(userWallet), assetName)
assetRecords, err := UserAssetRecordModel.FindWithUserWalletAndAssetProps(db, common.FormatUserWallet(userWallet), strings.ToUpper(assetName))
if err != nil {
return err
}
Expand Down
Loading
Loading