Skip to content
Open
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
39 changes: 30 additions & 9 deletions api/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -3179,9 +3179,6 @@
"format": "address",
"type": "string"
},
"asset_type": {
"$ref": "#/components/schemas/DefiAssetAssetType"
},
"defi_provider": {
"$ref": "#/components/schemas/DefiProvider"
},
Expand All @@ -3191,17 +3188,20 @@
"pool_address": {
"format": "address",
"type": "string"
},
"type": {
"$ref": "#/components/schemas/DefiAssetType"
}
},
"required": [
"asset_type",
"type",
"amount",
"defi_provider",
"locked_asset"
],
"type": "object"
},
"DefiAssetAssetType": {
"DefiAssetType": {
"enum": [
"staking",
"lending_supply",
Expand All @@ -3226,6 +3226,21 @@
],
"type": "object"
},
"DefiLiquidPoolAssets": {
"properties": {
"asset0": {
"$ref": "#/components/schemas/DefiLockedAsset"
},
"asset1": {
"$ref": "#/components/schemas/DefiLockedAsset"
}
},
"required": [
"asset0",
"asset1"
],
"type": "object"
},
"DefiLockedAsset": {
"properties": {
"jetton": {
Expand Down Expand Up @@ -4037,8 +4052,14 @@
"defi_provider": {
"$ref": "#/components/schemas/DefiProvider"
},
"pool_assets": {
"$ref": "#/components/schemas/DefiLiquidPoolAssets"
},
"token_type": {
"$ref": "#/components/schemas/DefiAssetAssetType"
"$ref": "#/components/schemas/DefiAssetType"
},
"type": {
"$ref": "#/components/schemas/DefiAssetType"
}
},
"required": [
Expand All @@ -4054,6 +4075,9 @@
"type": "string",
"x-js-format": "bigint"
},
"defi_asset": {
"$ref": "#/components/schemas/JettonAssetInfo"
},
"extensions": {
"example": [
"custom_payload",
Expand Down Expand Up @@ -4522,9 +4546,6 @@
"format": "address",
"type": "string"
},
"asset_info": {
"$ref": "#/components/schemas/JettonAssetInfo"
},
"custom_payload_api_uri": {
"type": "string"
},
Expand Down
29 changes: 22 additions & 7 deletions api/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6073,18 +6073,31 @@ components:
$ref: '#/components/schemas/ScaledUI'
description:
type: string
asset_info:
$ref: '#/components/schemas/JettonAssetInfo'
JettonAssetInfo:
type: object
required:
- token_type
- defi_provider
properties:
# use type
token_type:
$ref: '#/components/schemas/DefiAssetAssetType'
$ref: '#/components/schemas/DefiAssetType'
type:
$ref: '#/components/schemas/DefiAssetType'
defi_provider:
$ref: '#/components/schemas/DefiProvider'
pool_assets:
$ref: '#/components/schemas/DefiLiquidPoolAssets'
DefiLiquidPoolAssets:
type: object
required:
- asset0
- asset1
properties:
asset0:
$ref: '#/components/schemas/DefiLockedAsset'
asset1:
$ref: '#/components/schemas/DefiLockedAsset'
ScaledUI:
type: object
required:
Expand Down Expand Up @@ -6116,6 +6129,8 @@ components:
$ref: '#/components/schemas/AccountAddress'
jetton:
$ref: '#/components/schemas/JettonPreview'
defi_asset:
$ref: '#/components/schemas/JettonAssetInfo'
extensions:
type: array
items:
Expand Down Expand Up @@ -8181,7 +8196,7 @@ components:
type: array
items:
$ref: '#/components/schemas/DefiAsset'
DefiAssetAssetType:
DefiAssetType:
type: string
enum:
- staking
Expand All @@ -8193,13 +8208,13 @@ components:
DefiAsset:
type: object
required:
- asset_type
- type
- amount
- defi_provider
- locked_asset
properties:
asset_type:
$ref: '#/components/schemas/DefiAssetAssetType'
type:
$ref: '#/components/schemas/DefiAssetType'
amount:
type: string
x-js-format: bigint
Expand Down
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ require (
github.com/sourcegraph/conc v0.3.0
github.com/stretchr/testify v1.11.1
github.com/tonkeeper/scam_backoffice_rules v0.0.11
github.com/tonkeeper/tongo v1.22.20
github.com/tonkeeper/tongo v1.22.30
go.opentelemetry.io/otel v1.43.0
go.opentelemetry.io/otel/metric v1.43.0
go.opentelemetry.io/otel/trace v1.43.0
go.uber.org/zap v1.27.1
golang.org/x/exp v0.0.0-20260603202125-055de637280b
golang.org/x/net v0.55.0
golang.org/x/exp v0.0.0-20260611194520-c48552f49976
golang.org/x/net v0.56.0
golang.org/x/sync v0.21.0
golang.org/x/text v0.38.0
google.golang.org/grpc v1.80.0
Expand Down Expand Up @@ -62,9 +62,9 @@ require (
go.uber.org/multierr v1.11.0 // indirect
go.yaml.in/yaml/v2 v2.4.4 // indirect
golang.org/x/crypto v0.53.0 // indirect
golang.org/x/mod v0.36.0 // indirect
golang.org/x/mod v0.37.0 // indirect
golang.org/x/sys v0.46.0 // indirect
golang.org/x/tools v0.45.0 // indirect
golang.org/x/tools v0.46.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20260401024825-9d38bb4040a9 // indirect
google.golang.org/protobuf v1.36.11 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
Expand Down
20 changes: 10 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
github.com/tonkeeper/scam_backoffice_rules v0.0.11 h1:VXbNNyTO49OArvQwPRCU+1WUEyfQgkqG7Q8NVhQ7320=
github.com/tonkeeper/scam_backoffice_rules v0.0.11/go.mod h1:SqZXYO9vbID8ku+xnnaKXeNGmehxigODGrk5V1KqbRA=
github.com/tonkeeper/tongo v1.22.20 h1:dr7q+lJp+3vO1BLWG5cyRgKGwdb66zoJ5zsWCqaF7wY=
github.com/tonkeeper/tongo v1.22.20/go.mod h1:nHmdEXPfT0/EvkEaBzPiY599/0OYjQSW4dWR7aX+OII=
github.com/tonkeeper/tongo v1.22.30 h1:OpS39mqoYjehmf15MB3QjZ7QQBiic3nzNlEkE+v5m6k=
github.com/tonkeeper/tongo v1.22.30/go.mod h1:nHmdEXPfT0/EvkEaBzPiY599/0OYjQSW4dWR7aX+OII=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQD0Loo=
Expand All @@ -123,21 +123,21 @@ go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc=
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
golang.org/x/crypto v0.53.0 h1:QZ4Muo8THX6CizN2vPPd5fBGHyogrdK9fG4wLPFUsto=
golang.org/x/crypto v0.53.0/go.mod h1:DNLU434OwVakk9PzuwV8w62mAJpRJL3vsgcfp4Qnsio=
golang.org/x/exp v0.0.0-20260603202125-055de637280b h1:v1uXiEBHo8QA0LiGCo7UgHMzHT4Kdfpl2zmtH5vaP1Q=
golang.org/x/exp v0.0.0-20260603202125-055de637280b/go.mod h1:d2fgXJLVs4dYDHUk5lwMIfzRzSrWCfGZb0ZqeLa/Vcw=
golang.org/x/mod v0.36.0 h1:JJjpVx6myfUsUdAzZuOSTTmRE0PfZeNWzzvKrP7amb4=
golang.org/x/mod v0.36.0/go.mod h1:moc6ELqsWcOw5Ef3xVprK5ul/MvtVvkIXLziUOICjUQ=
golang.org/x/net v0.55.0 h1:bcvxaJn3e1U6InsFWt1JUq1aSjnRxLzT2rtD2KfkDF8=
golang.org/x/net v0.55.0/go.mod h1:L5U2KuzuOe1lY7Z+aWVIKK6qEeJXnXV9yzGA+WCHJww=
golang.org/x/exp v0.0.0-20260611194520-c48552f49976 h1:X8Hz2ImujgbmetVuW+w2YkyZChE3cBpZi2P158rTG9M=
golang.org/x/exp v0.0.0-20260611194520-c48552f49976/go.mod h1:vnf4pv9iKZXY58sQE1L86zmNWJ4159e1RkcWiLCkeEY=
golang.org/x/mod v0.37.0 h1:vF1DjpVEshcIqoEaauuHebaLk1O1forxjxBaVn884JQ=
golang.org/x/mod v0.37.0/go.mod h1:m8S8VeM9r4dzDwjrKO0a1sZP3YjeMamRRlD+fmR2Q/0=
golang.org/x/net v0.56.0 h1:Rw8j/hFzGvJUZwNBXnAtf5sVDVt+65SK2C7IxCxZt5o=
golang.org/x/net v0.56.0/go.mod h1:D3Ku6r+V6JROoZK144D2XfMHFcMq/0zSfLelVTCFKec=
golang.org/x/sync v0.21.0 h1:HLII4xRRTtCRkxYp4HNFF0Js/Og6q2i++KXbg0gHCwM=
golang.org/x/sync v0.21.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.46.0 h1:noSf2Fq6F8DBgS+LysIkx7rIExoNHJsxOAtPp4rthXw=
golang.org/x/sys v0.46.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
golang.org/x/text v0.38.0 h1:sXmwo9DwP3OK9EZ7PqAdaooSGozfl/3a6/xJcbzPRhE=
golang.org/x/text v0.38.0/go.mod h1:YXZt3QhHUKYT53r2lLKFIVi6Ao1jdzrTR/KQ09qyxF4=
golang.org/x/tools v0.45.0 h1:18qN3FAooORvApf5XjCXgsuayZOEtXf6JK18I3+ONa8=
golang.org/x/tools v0.45.0/go.mod h1:LuUGqqaXcXMEFEruIVJVm5mgDD8vww/z/SR1gQ4uE/0=
golang.org/x/tools v0.46.0 h1:7jTurBkPZu4moS/Uy4OQT1M+QBlsj3wejyZwsT8Z7rk=
golang.org/x/tools v0.46.0/go.mod h1:FrD85F8l+NWL+9XWBSyVSHO6Ne4jutsfIFba7AWQ5Ys=
google.golang.org/genproto/googleapis/rpc v0.0.0-20260401024825-9d38bb4040a9 h1:m8qni9SQFH0tJc1X0vmnpw/0t+AImlSvp30sEupozUg=
google.golang.org/genproto/googleapis/rpc v0.0.0-20260401024825-9d38bb4040a9/go.mod h1:4Hqkh8ycfw05ld/3BWL7rJOSfebL2Q+DVDeRgYgxUU8=
google.golang.org/grpc v1.80.0 h1:Xr6m2WmWZLETvUNvIUmeD5OAagMw3FiKmMlTdViWsHM=
Expand Down
14 changes: 14 additions & 0 deletions internal/g/hash.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package g

import (
"encoding/base64"
"encoding/hex"
)

func MustHex2Base64(hexHash string) string {
b, err := hex.DecodeString(hexHash)
if err != nil {
panic(err)
}
return base64.StdEncoding.EncodeToString(b)
}
37 changes: 20 additions & 17 deletions pkg/api/defi_converters.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ func (h *Handler) GetAccountDefiAssets(ctx context.Context, params oas.GetAccoun

func (h *Handler) convertDefiAsset(ctx context.Context, asset defi.Asset) oas.DefiAsset {
result := oas.DefiAsset{
AssetType: convertDefiAssetType(asset.Type),
Amount: asset.Amount,
Type: convertDefiAssetType(asset.Type),
Amount: asset.LockedAsset.Amount.String(),
DefiProvider: h.convertDefiProvider(asset.Provider),
LockedAsset: h.convertDefiLockedAsset(ctx, asset.LockedAsset),
}
Expand All @@ -45,16 +45,16 @@ func (h *Handler) convertDefiAsset(ctx context.Context, asset defi.Asset) oas.De
return result
}

var defi2oasMap = map[defi.AssetType]oas.DefiAssetAssetType{
defi.AssetTypeStaking: oas.DefiAssetAssetTypeStaking,
defi.AssetTypeLiquidStaking: oas.DefiAssetAssetTypeLiquidStaking,
defi.AssetTypeLiquidPool: oas.DefiAssetAssetTypeLiquidPool,
defi.AssetTypeYieldToken: oas.DefiAssetAssetTypeYieldToken,
defi.AssetTypeLendingSupply: oas.DefiAssetAssetTypeLendingSupply,
defi.AssetTypeLendingBorrow: oas.DefiAssetAssetTypeLendingBorrow,
var defi2oasMap = map[defi.AssetType]oas.DefiAssetType{
defi.AssetTypeStaking: oas.DefiAssetTypeStaking,
defi.AssetTypeLiquidStaking: oas.DefiAssetTypeLiquidStaking,
defi.AssetTypeLiquidPool: oas.DefiAssetTypeLiquidPool,
defi.AssetTypeYieldToken: oas.DefiAssetTypeYieldToken,
defi.AssetTypeLendingSupply: oas.DefiAssetTypeLendingSupply,
defi.AssetTypeLendingBorrow: oas.DefiAssetTypeLendingBorrow,
}

func convertDefiAssetType(assetType defi.AssetType) oas.DefiAssetAssetType {
func convertDefiAssetType(assetType defi.AssetType) oas.DefiAssetType {
if oasType, ok := defi2oasMap[assetType]; ok {
return oasType
}
Expand All @@ -80,19 +80,22 @@ func (h *Handler) convertDefiJettonPreview(ctx context.Context, master ton.Accou
return jettonPreview(master, meta, score, nil)
}

func (h *Handler) optJettonAssetInfo(info defi.AssetInfo, ok bool) *oas.JettonAssetInfo {
func (h *Handler) optJettonAssetInfo(ctx context.Context, info defi.AssetInfo, ok bool) *oas.JettonAssetInfo {
if !ok {
return nil
}
converted := h.convertJettonAssetInfo(info)
return &converted
}

func (h *Handler) convertJettonAssetInfo(info defi.AssetInfo) oas.JettonAssetInfo {
return oas.JettonAssetInfo{
result := oas.JettonAssetInfo{
TokenType: convertDefiAssetType(info.TokenType),
DefiProvider: h.convertDefiProvider(info.DefiProvider),
}
if info.LiquidityPool != nil {
result.PoolAssets = oas.NewOptDefiLiquidPoolAssets(oas.DefiLiquidPoolAssets{
Asset0: h.convertDefiLockedAsset(ctx, info.LiquidityPool.Asset0),
Asset1: h.convertDefiLockedAsset(ctx, info.LiquidityPool.Asset1),
})
}
converted := result
return &converted
}

func (h *Handler) convertDefiProvider(provider defi.Provider) oas.DefiProvider {
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/jetton_converters.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func (h *Handler) convertJettonBalance(ctx context.Context, wallet core.JettonWa
score, _ := h.score.GetJettonScore(wallet.JettonAddress)
jettonBalance.Jetton = jettonPreview(wallet.JettonAddress, normalizedMetadata, score, scaledUiParams)
if assetInfo != nil {
jettonBalance.Jetton.AssetInfo.SetTo(*assetInfo)
jettonBalance.DefiAsset.SetTo(*assetInfo)
}

return jettonBalance, nil
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/jetton_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (h *Handler) GetAccountJettonsBalances(ctx context.Context, params oas.GetA
}
for _, wallet := range wallets {
assetInfo, ok := assetInfos[wallet.JettonAddress]
jettonBalance, err := h.convertJettonBalance(ctx, wallet, params.Currencies, nil, h.optJettonAssetInfo(assetInfo, ok))
jettonBalance, err := h.convertJettonBalance(ctx, wallet, params.Currencies, nil, h.optJettonAssetInfo(ctx, assetInfo, ok))
if err != nil {
h.logger.Warn(fmt.Sprintf("Failed to convert jetton balance for wallet %v", wallet.JettonAddress.ToRaw()), zap.Error(err))
continue
Expand Down Expand Up @@ -76,7 +76,7 @@ func (h *Handler) GetAccountJettonBalance(ctx context.Context, params oas.GetAcc
assetInfos = defi.AssetInfos(ctx, h.storage, h.logger, []tongo.AccountID{wallets[0].JettonAddress})
}
assetInfo, ok := assetInfos[wallets[0].JettonAddress]
jettonBalance, err := h.convertJettonBalance(ctx, wallets[0], params.Currencies, nil, h.optJettonAssetInfo(assetInfo, ok))
jettonBalance, err := h.convertJettonBalance(ctx, wallets[0], params.Currencies, nil, h.optJettonAssetInfo(ctx, assetInfo, ok))
if err != nil {
return nil, err
}
Expand Down
7 changes: 7 additions & 0 deletions pkg/core/price.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,10 @@ func PriceNanoGram(amount int64) Price {
Amount: *big.NewInt(amount),
}
}

func NewCurrencyJetton(master *tongo.AccountID) Currency {
return Currency{
Type: CurrencyJetton,
Jetton: master,
}
}
Loading
Loading