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
140 changes: 140 additions & 0 deletions api/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -3158,6 +3158,114 @@
],
"type": "object"
},
"DefiAsset": {
"properties": {
"amount": {
"description": "amount in token units; negative for lending debt",
"example": 1000000000,
"format": "int64",
"type": "integer",
"x-js-format": "bigint"
},
"jetton": {
"$ref": "#/components/schemas/JettonPreview"
},
"nft": {
"$ref": "#/components/schemas/DefiNftPreview"
},
"position": {
"description": "current position value in nanoTON",
"example": 2000000000,
"format": "int64",
"type": "integer",
"x-js-format": "bigint"
},
"provider": {
"$ref": "#/components/schemas/DefiProvider"
},
"type": {
"$ref": "#/components/schemas/DefiAssetType"
}
},
"required": [
"type",
"provider",
"amount",
"position"
],
"type": "object"
},
"DefiAssetType": {
"enum": [
"liquid_staking",
"liquid_pool",
"staking",
"lending",
"farming"
],
"type": "string"
},
"DefiAssets": {
"properties": {
"assets": {
"items": {
"$ref": "#/components/schemas/DefiAsset"
},
"type": "array"
}
},
"required": [
"assets"
],
"type": "object"
},
"DefiNftPreview": {
"properties": {
"address": {
"example": "0:0BB5A9F69043EEBDDA5AD2E946EB953242BD8F603FE795D90698CEEC6BFC60A0",
"format": "address",
"type": "string"
},
"collection": {
"example": "0:0BB5A9F69043EEBDDA5AD2E946EB953242BD8F603FE795D90698CEEC6BFC60A0",
"format": "address",
"type": "string"
},
"token0": {
"$ref": "#/components/schemas/JettonPreview"
},
"token1": {
"$ref": "#/components/schemas/JettonPreview"
}
},
"required": [
"address",
"collection"
],
"type": "object"
},
"DefiProvider": {
"properties": {
"image": {
"example": "https://tonstakers.com/logo.png",
"type": "string"
},
"name": {
"example": "Tonstakers",
"type": "string"
},
"url": {
"example": "https://app.tonstakers.com/",
"type": "string"
}
},
"required": [
"name",
"url",
"image"
],
"type": "object"
},
"DepositStakeAction": {
"description": "validator's participation in elections",
"properties": {
Expand Down Expand Up @@ -9674,6 +9782,35 @@
]
}
},
"/v2/defi/{account_id}/assets": {
"get": {
"description": "Get all DeFi assets (liquid staking, liquid pools, staking, lending, farming) for an account",
"operationId": "getAccountDefiAssets",
"parameters": [
{
"$ref": "#/components/parameters/accountIDParameter"
}
],
"responses": {
"200": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/DefiAssets"
}
}
},
"description": "defi assets"
},
"default": {
"$ref": "#/components/responses/Error"
}
},
"tags": [
"DeFi"
]
}
},
"/v2/dns/auctions": {
"get": {
"description": "Get all auctions",
Expand Down Expand Up @@ -12874,6 +13011,9 @@
},
{
"name": "Purchases"
},
{
"name": "DeFi"
}
]
}
103 changes: 103 additions & 0 deletions api/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ tags:
description: Additional documentation
url: https://docs.tonconsole.com/tonapi/rest-api/extra-currency
- name: Purchases
- name: DeFi

paths:
/v2/openapi.json:
Expand Down Expand Up @@ -1832,6 +1833,24 @@ paths:
'default':
$ref: '#/components/responses/Error'

/v2/defi/{account_id}/assets:
get:
description: Get all DeFi assets (liquid staking, liquid pools, staking, lending, farming) for an account
operationId: getAccountDefiAssets
tags:
- DeFi
parameters:
- $ref: '#/components/parameters/accountIDParameter'
responses:
'200':
description: defi assets
content:
application/json:
schema:
$ref: '#/components/schemas/DefiAssets'
'default':
$ref: '#/components/responses/Error'

/v2/storage/providers:
get:
description: Get TON storage providers deployed to the blockchain.
Expand Down Expand Up @@ -9017,6 +9036,90 @@ components:
items:
type: number
format: double
DefiAssetType:
type: string
enum:
- liquid_staking
- liquid_pool
- staking
- lending
- farming

DefiProvider:
type: object
required:
- name
- url
- image
properties:
name:
type: string
example: Tonstakers
url:
type: string
example: https://app.tonstakers.com/
image:
type: string
example: https://tonstakers.com/logo.png

DefiNftPreview:
type: object
required:
- address
- collection
properties:
address:
type: string
format: address
example: 0:0BB5A9F69043EEBDDA5AD2E946EB953242BD8F603FE795D90698CEEC6BFC60A0
collection:
type: string
format: address
example: 0:0BB5A9F69043EEBDDA5AD2E946EB953242BD8F603FE795D90698CEEC6BFC60A0
token0:
$ref: '#/components/schemas/JettonPreview'
token1:
$ref: '#/components/schemas/JettonPreview'

DefiAsset:
type: object
required:
- type
- provider
- amount
- position
properties:
type:
$ref: '#/components/schemas/DefiAssetType'
jetton:
$ref: '#/components/schemas/JettonPreview'
nft:
$ref: '#/components/schemas/DefiNftPreview'
provider:
$ref: '#/components/schemas/DefiProvider'
amount:
type: integer
format: int64
description: amount in token units; negative for lending debt
example: 1000000000
x-js-format: bigint
position:
type: integer
format: int64
description: current position value in nanoTON
example: 2000000000
x-js-format: bigint

DefiAssets:
type: object
required:
- assets
properties:
assets:
type: array
items:
$ref: '#/components/schemas/DefiAsset'

responses:
Error:
description: Some error during request processing
Expand Down
45 changes: 45 additions & 0 deletions pkg/api/defi_handlers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package api

import (
"context"
"net/http"

"github.com/tonkeeper/opentonapi/pkg/defi"
"github.com/tonkeeper/opentonapi/pkg/oas"
"github.com/tonkeeper/tongo"
)

func (h *Handler) defiDeps() defi.Deps {
return defi.Deps{
Storage: h.storage,
Executor: h.executor,
Score: h.score,
Logger: h.logger,
ProxyURL: h.proxyURL,
JettonMeta: func(ctx context.Context, m tongo.AccountID) defi.NormalizedJettonMeta {
x := h.GetJettonNormalizedMetadata(ctx, m)
return defi.NormalizedJettonMeta{
Name: x.Name,
Description: x.Description,
Image: x.Image,
Symbol: x.Symbol,
Decimals: x.Decimals,
Verification: x.Verification,
Social: x.Social,
Websites: x.Websites,
CustomPayloadApiUri: x.CustomPayloadApiUri,
PreviewImage: x.PreviewImage,
}
},
}
}

func (h *Handler) GetAccountDefiAssets(ctx context.Context, params oas.GetAccountDefiAssetsParams) (*oas.DefiAssets, error) {
account, err := tongo.ParseAddress(params.AccountID)
if err != nil {
return nil, toError(http.StatusBadRequest, err)
}

todayRates, _, _, _, _ := h.getRates()
return defi.GetDefiAssets(ctx, h.defiDeps(), account.ID, todayRates), nil
}
10 changes: 10 additions & 0 deletions pkg/api/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ type Handler struct {
ctxToDetails ctxToDetails
tongoVersion int

proxyURL string

// mempoolEmulateIgnoreAccounts, we don't track pending transactions for this list of accounts.
mempoolEmulateIgnoreAccounts map[tongo.AccountID]struct{}

Expand Down Expand Up @@ -99,6 +101,7 @@ type Options struct {
score scoreSource
parallelTraceProcessing bool
archiveLiteServers []config.LiteServer
proxyURL string
}

type Option func(o *Options)
Expand Down Expand Up @@ -192,6 +195,12 @@ func WithArchiveLiteServers(s []config.LiteServer) Option {
}
}

func WithProxyURL(baseURL string) Option {
return func(o *Options) {
o.proxyURL = baseURL
}
}

func NewHandler(logger *zap.Logger, opts ...Option) (*Handler, error) {
options := &Options{}
for _, o := range opts {
Expand Down Expand Up @@ -269,6 +278,7 @@ func NewHandler(logger *zap.Logger, opts ...Option) (*Handler, error) {
ctxToDetails: options.ctxToDetails,
gasless: options.gasless,
score: options.score,
proxyURL: options.proxyURL,
ratesSource: rates.InitCalculator(options.ratesSource),
verifierSource: options.verifier,
metaCache: metadataCache{
Expand Down
4 changes: 4 additions & 0 deletions pkg/bath/bath_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ func (m *mockInfoSource) DedustPools(ctx context.Context, contracts []tongo.Acco
return map[tongo.AccountID]core.DedustPool{}, nil
}

func (m *mockInfoSource) BidaskPools(_ context.Context) ([]tongo.AccountID, error) {
return nil, nil
}

var _ core.InformationSource = &mockInfoSource{}

func isFocusedRun() bool {
Expand Down
1 change: 1 addition & 0 deletions pkg/core/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ type InformationSource interface {
STONfiPools(ctx context.Context, poolIDs []STONfiPoolID) (map[tongo.AccountID]STONfiPool, error)
DedustPools(ctx context.Context, contracts []tongo.AccountID) (map[tongo.AccountID]DedustPool, error)
SubscriptionInfos(ctx context.Context, ids []SubscriptionID) (map[tongo.AccountID]SubscriptionInfo, error)
BidaskPools(ctx context.Context) ([]tongo.AccountID, error)
GetFfVaultPositionDatas(ctx context.Context, positions []tongo.AccountID) (map[tongo.AccountID]VaultPositionData, error)
GetFfVaultJettonMasters(ctx context.Context, vaults []tongo.AccountID) (map[tongo.AccountID]tongo.AccountID, error)
GetPythPriceFeedMeta(id string) (pyth.PriceFeedAttributes, bool)
Expand Down
Loading
Loading