defillama-sdk 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,85 @@
1
+ """Yields module implementation."""
2
+
3
+ from typing import List
4
+ from urllib.parse import quote
5
+
6
+ from ..client import BaseClient
7
+ from ..types.yields import (
8
+ BorrowPoolsResponse,
9
+ LendBorrowChartResponse,
10
+ LsdRate,
11
+ PerpsResponse,
12
+ YieldChartResponse,
13
+ YieldPoolsOldResponse,
14
+ YieldPoolsResponse,
15
+ )
16
+
17
+
18
+ class YieldsModule:
19
+ """Access yield data from DefiLlama."""
20
+
21
+ def __init__(self, client: BaseClient) -> None:
22
+ self._client = client
23
+
24
+ def getPools(self) -> YieldPoolsResponse:
25
+ """Get all yield pools with current APY."""
26
+
27
+ return self._client.get(
28
+ "/pools",
29
+ requires_auth=True,
30
+ api_namespace="yields",
31
+ )
32
+
33
+ def getPoolsOld(self) -> YieldPoolsOldResponse:
34
+ """Get yield pools in legacy format."""
35
+
36
+ return self._client.get(
37
+ "/poolsOld",
38
+ requires_auth=True,
39
+ api_namespace="yields",
40
+ )
41
+
42
+ def getPoolChart(self, pool: str) -> YieldChartResponse:
43
+ """Get historical APY and TVL for a pool."""
44
+
45
+ return self._client.get(
46
+ f"/chart/{quote(pool)}",
47
+ requires_auth=True,
48
+ api_namespace="yields",
49
+ )
50
+
51
+ def getBorrowPools(self) -> BorrowPoolsResponse:
52
+ """Get lending/borrowing pools."""
53
+
54
+ return self._client.get(
55
+ "/poolsBorrow",
56
+ requires_auth=True,
57
+ api_namespace="yields",
58
+ )
59
+
60
+ def getLendBorrowChart(self, pool: str) -> LendBorrowChartResponse:
61
+ """Get historical lend/borrow rates."""
62
+
63
+ return self._client.get(
64
+ f"/chartLendBorrow/{quote(pool)}",
65
+ requires_auth=True,
66
+ api_namespace="yields",
67
+ )
68
+
69
+ def getPerps(self) -> PerpsResponse:
70
+ """Get perpetual futures funding rates."""
71
+
72
+ return self._client.get(
73
+ "/perps",
74
+ requires_auth=True,
75
+ api_namespace="yields",
76
+ )
77
+
78
+ def getLsdRates(self) -> List[LsdRate]:
79
+ """Get liquid staking derivative rates."""
80
+
81
+ return self._client.get(
82
+ "/lsdRates",
83
+ requires_auth=True,
84
+ api_namespace="yields",
85
+ )
defillama_api/py.typed ADDED
File without changes
@@ -0,0 +1,14 @@
1
+ """Type exports for DefiLlama API responses."""
2
+
3
+ from .account import *
4
+ from .bridges import *
5
+ from .dat import *
6
+ from .ecosystem import *
7
+ from .emissions import *
8
+ from .etfs import *
9
+ from .fees import *
10
+ from .prices import *
11
+ from .stablecoins import *
12
+ from .tvl import *
13
+ from .volumes import *
14
+ from .yields import *
@@ -0,0 +1,10 @@
1
+ """Account type definitions."""
2
+
3
+ from typing import TypedDict
4
+
5
+
6
+ class UsageResponse(TypedDict):
7
+ creditsLeft: int
8
+
9
+
10
+ __all__ = ["UsageResponse"]
@@ -0,0 +1,147 @@
1
+ """Bridge type definitions."""
2
+
3
+ from typing import Dict, List, Optional, TypedDict
4
+
5
+
6
+ class TransactionCounts(TypedDict):
7
+ deposits: int
8
+ withdrawals: int
9
+
10
+
11
+ class BridgeSummary(TypedDict, total=False):
12
+ id: int
13
+ defillamaId: Optional[str]
14
+ name: str
15
+ displayName: str
16
+ icon: Optional[str]
17
+ volumePrevDay: float
18
+ volumePrev2Day: Optional[float]
19
+ lastHourlyVolume: float
20
+ last24hVolume: float
21
+ lastDailyVolume: float
22
+ dayBeforeLastVolume: Optional[float]
23
+ weeklyVolume: Optional[float]
24
+ monthlyVolume: Optional[float]
25
+ chains: Optional[List[str]]
26
+ destinationChain: Optional[str]
27
+ url: Optional[str]
28
+ slug: Optional[str]
29
+
30
+
31
+ class BridgeChainInfo(TypedDict, total=False):
32
+ gecko_id: Optional[str]
33
+ volumePrevDay: float
34
+ tokenSymbol: Optional[str]
35
+ name: str
36
+
37
+
38
+ class BridgesResponse(TypedDict, total=False):
39
+ bridges: List[BridgeSummary]
40
+ chains: Optional[List[BridgeChainInfo]]
41
+
42
+
43
+ class ChainVolumeBreakdown(TypedDict):
44
+ lastHourlyVolume: float
45
+ currentDayVolume: float
46
+ lastDailyVolume: float
47
+ dayBeforeLastVolume: float
48
+ weeklyVolume: float
49
+ monthlyVolume: float
50
+ last24hVolume: float
51
+ lastHourlyTxs: TransactionCounts
52
+ currentDayTxs: TransactionCounts
53
+ prevDayTxs: TransactionCounts
54
+ dayBeforeLastTxs: TransactionCounts
55
+ weeklyTxs: TransactionCounts
56
+ monthlyTxs: TransactionCounts
57
+
58
+
59
+ class BridgeDetail(TypedDict, total=False):
60
+ id: int
61
+ name: str
62
+ displayName: str
63
+ lastHourlyVolume: float
64
+ currentDayVolume: float
65
+ lastDailyVolume: float
66
+ dayBeforeLastVolume: float
67
+ weeklyVolume: float
68
+ monthlyVolume: float
69
+ lastHourlyTxs: TransactionCounts
70
+ currentDayTxs: TransactionCounts
71
+ prevDayTxs: TransactionCounts
72
+ dayBeforeLastTxs: TransactionCounts
73
+ weeklyTxs: TransactionCounts
74
+ monthlyTxs: TransactionCounts
75
+ chainBreakdown: Optional[Dict[str, ChainVolumeBreakdown]]
76
+ destinationChain: Optional[str]
77
+
78
+
79
+ class BridgeVolumeDataPoint(TypedDict):
80
+ date: str
81
+ depositUSD: float
82
+ withdrawUSD: float
83
+ depositTxs: int
84
+ withdrawTxs: int
85
+
86
+
87
+ class TokenDayStats(TypedDict):
88
+ usdValue: float
89
+ amount: str
90
+ symbol: str
91
+ decimals: int
92
+
93
+
94
+ class AddressDayStats(TypedDict):
95
+ usdValue: float
96
+ txs: int
97
+
98
+
99
+ class BridgeDayStatsResponse(TypedDict):
100
+ date: int
101
+ totalTokensDeposited: Dict[str, TokenDayStats]
102
+ totalTokensWithdrawn: Dict[str, TokenDayStats]
103
+ totalAddressDeposited: Dict[str, AddressDayStats]
104
+ totalAddressWithdrawn: Dict[str, AddressDayStats]
105
+
106
+
107
+ class BridgesOptions(TypedDict, total=False):
108
+ includeChains: Optional[bool]
109
+
110
+
111
+ class BridgeTransactionsOptions(TypedDict, total=False):
112
+ limit: Optional[int]
113
+ startTimestamp: Optional[int]
114
+ endTimestamp: Optional[int]
115
+ sourceChain: Optional[str]
116
+ address: Optional[str]
117
+
118
+
119
+ class BridgeTransaction(TypedDict, total=False):
120
+ tx_hash: str
121
+ ts: str
122
+ tx_block: int
123
+ tx_from: str
124
+ tx_to: str
125
+ token: str
126
+ amount: str
127
+ is_deposit: bool
128
+ chain: str
129
+ bridge_name: str
130
+ usd_value: Optional[float]
131
+
132
+
133
+ __all__ = [
134
+ "TransactionCounts",
135
+ "BridgeSummary",
136
+ "BridgeChainInfo",
137
+ "BridgesResponse",
138
+ "ChainVolumeBreakdown",
139
+ "BridgeDetail",
140
+ "BridgeVolumeDataPoint",
141
+ "TokenDayStats",
142
+ "AddressDayStats",
143
+ "BridgeDayStatsResponse",
144
+ "BridgesOptions",
145
+ "BridgeTransactionsOptions",
146
+ "BridgeTransaction",
147
+ ]
@@ -0,0 +1,144 @@
1
+ """Digital Asset Treasury type definitions."""
2
+
3
+ from typing import Dict, List, Optional, Tuple, TypedDict, Union
4
+
5
+
6
+ class InstitutionHolding(TypedDict, total=False):
7
+ amount: float
8
+ avgPrice: Optional[float]
9
+ usdValue: float
10
+ cost: Optional[float]
11
+ transactionCount: Optional[int]
12
+ firstAnnouncementDate: Optional[str]
13
+ lastAnnouncementDate: Optional[str]
14
+ supplyPercentage: Optional[float]
15
+
16
+
17
+ class InstitutionMetadata(TypedDict, total=False):
18
+ institutionId: int
19
+ ticker: str
20
+ name: str
21
+ type: Optional[str]
22
+ price: Optional[float]
23
+ priceChange24h: Optional[float]
24
+ volume24h: Optional[float]
25
+ fd_realized: Optional[Union[float, str]]
26
+ fd_realistic: Optional[Union[float, str]]
27
+ fd_maximum: Optional[Union[float, str]]
28
+ mcapRealized: Optional[float]
29
+ mcapRealistic: Optional[float]
30
+ mcapMax: Optional[float]
31
+ realized_mNAV: Optional[float]
32
+ realistic_mNAV: Optional[float]
33
+ max_mNAV: Optional[float]
34
+ totalCost: Optional[float]
35
+ totalUsdValue: Optional[float]
36
+ holdings: Optional[Dict[str, InstitutionHolding]]
37
+ description: Optional[str]
38
+ logo: Optional[str]
39
+ url: Optional[str]
40
+ country: Optional[str]
41
+ exchange: Optional[str]
42
+ marketCap: Optional[float]
43
+ totalBitcoin: Optional[float]
44
+ totalEthereum: Optional[float]
45
+
46
+
47
+ class DatAssetMetadata(TypedDict, total=False):
48
+ name: str
49
+ ticker: str
50
+ geckoId: Optional[str]
51
+ companies: Optional[int]
52
+ totalAmount: Optional[float]
53
+ totalUsdValue: Optional[float]
54
+ circSupplyPerc: Optional[float]
55
+
56
+
57
+ class DatInstitutionSummary(TypedDict):
58
+ institutionId: int
59
+ totalUsdValue: float
60
+ totalCost: Optional[float]
61
+
62
+
63
+ class DatAssetInstitutionSummary(TypedDict):
64
+ institutionId: int
65
+ usdValue: float
66
+ amount: float
67
+
68
+
69
+ DatFlowPoint = Tuple[float, float, float, float, float, float]
70
+ DatMnavPoint = Tuple[float, float, float, float]
71
+ DatStatsPoint = Tuple[
72
+ float,
73
+ float,
74
+ float,
75
+ float,
76
+ float,
77
+ float,
78
+ float,
79
+ float,
80
+ float,
81
+ float,
82
+ ]
83
+ DatOhlcvPoint = Tuple[float, float, float, float, float, float]
84
+
85
+
86
+ class DatInstitutionsResponse(TypedDict, total=False):
87
+ institutionMetadata: Dict[str, InstitutionMetadata]
88
+ assetMetadata: Dict[str, DatAssetMetadata]
89
+ institutions: List[DatInstitutionSummary]
90
+ assets: Dict[str, List[DatAssetInstitutionSummary]]
91
+ flows: Optional[Dict[str, List[DatFlowPoint]]]
92
+ mNAV: Optional[Dict[str, Dict[str, List[DatMnavPoint]]]]
93
+ totalCompanies: int
94
+ lastUpdated: str
95
+
96
+
97
+ class DatInstitutionAssetMeta(TypedDict):
98
+ name: str
99
+ ticker: str
100
+
101
+
102
+ class DatInstitutionResponse(TypedDict, total=False):
103
+ institutionId: int
104
+ ticker: str
105
+ name: str
106
+ type: Optional[str]
107
+ rank: Optional[int]
108
+ price: Optional[float]
109
+ priceChange24h: Optional[float]
110
+ volume24h: Optional[float]
111
+ fd_realized: Optional[Union[float, str]]
112
+ fd_realistic: Optional[Union[float, str]]
113
+ fd_max: Optional[Union[float, str]]
114
+ mcap_realized: Optional[float]
115
+ mcap_realistic: Optional[float]
116
+ mcap_max: Optional[float]
117
+ realized_mNAV: Optional[float]
118
+ realistic_mNAV: Optional[float]
119
+ max_mNAV: Optional[float]
120
+ totalCost: Optional[float]
121
+ totalUsdValue: Optional[float]
122
+ assets: Optional[Dict[str, InstitutionHolding]]
123
+ assetsMeta: Optional[Dict[str, DatInstitutionAssetMeta]]
124
+ assetValue: Optional[List[Tuple[float, float]]]
125
+ stats: Optional[List[DatStatsPoint]]
126
+ ohlcv: Optional[List[DatOhlcvPoint]]
127
+ transactions: Optional[List[object]]
128
+ lastUpdated: Optional[str]
129
+
130
+
131
+ __all__ = [
132
+ "InstitutionHolding",
133
+ "InstitutionMetadata",
134
+ "DatAssetMetadata",
135
+ "DatInstitutionSummary",
136
+ "DatAssetInstitutionSummary",
137
+ "DatFlowPoint",
138
+ "DatMnavPoint",
139
+ "DatStatsPoint",
140
+ "DatOhlcvPoint",
141
+ "DatInstitutionsResponse",
142
+ "DatInstitutionAssetMeta",
143
+ "DatInstitutionResponse",
144
+ ]
@@ -0,0 +1,175 @@
1
+ """Ecosystem type definitions."""
2
+
3
+ from typing import Dict, List, Optional, TypedDict
4
+
5
+
6
+ class CategoryTvlDataPoint(TypedDict, total=False):
7
+ tvl: Optional[float]
8
+
9
+
10
+ class CategoriesResponse(TypedDict):
11
+ chart: Dict[str, Dict[str, CategoryTvlDataPoint]]
12
+ categories: Dict[str, List[str]]
13
+ categoryPercentages: Optional[Dict[str, float]]
14
+
15
+
16
+ class ForkTvlDataPoint(TypedDict):
17
+ tvl: float
18
+ forks: Optional[float]
19
+
20
+
21
+ class ForksResponse(TypedDict, total=False):
22
+ chart: Dict[str, Dict[str, ForkTvlDataPoint]]
23
+ forks: Dict[str, List[str]]
24
+ parentProtocols: Optional[Dict[str, str]]
25
+
26
+
27
+ class OracleTvlDataPoint(TypedDict, total=False):
28
+ tvl: float
29
+ protocolsSecured: Optional[float]
30
+
31
+
32
+ class OraclesResponse(TypedDict, total=False):
33
+ chart: Dict[str, Dict[str, OracleTvlDataPoint]]
34
+ chainChart: Optional[Dict[str, Dict[str, object]]]
35
+ oraclesTVS: Optional[Dict[str, object]]
36
+ oracles: Dict[str, List[str]]
37
+ chainsByOracle: Optional[Dict[str, List[str]]]
38
+ totalValueSecured: Optional[float]
39
+ dominance: Optional[Dict[str, float]]
40
+
41
+
42
+ class TokenBreakdowns(TypedDict):
43
+ ownTokens: float
44
+ stablecoins: float
45
+ majors: float
46
+ others: float
47
+
48
+
49
+ class Entity(TypedDict, total=False):
50
+ id: str
51
+ name: str
52
+ url: Optional[str]
53
+ description: Optional[str]
54
+ logo: Optional[str]
55
+ category: Optional[str]
56
+ module: Optional[str]
57
+ twitter: Optional[str]
58
+ symbol: Optional[str]
59
+ chain: Optional[str]
60
+ gecko_id: Optional[str]
61
+ cmcId: Optional[str]
62
+ chains: Optional[List[str]]
63
+ misrepresentedTokens: Optional[bool]
64
+ slug: Optional[str]
65
+ tvl: float
66
+ chainTvls: Optional[Dict[str, float]]
67
+ change_1h: Optional[float]
68
+ change_1d: Optional[float]
69
+ change_7d: Optional[float]
70
+ tokenBreakdowns: Optional[TokenBreakdowns]
71
+ mcap: Optional[float]
72
+
73
+
74
+ class Treasury(TypedDict, total=False):
75
+ id: str
76
+ name: str
77
+ address: Optional[str]
78
+ symbol: Optional[str]
79
+ url: Optional[str]
80
+ description: Optional[str]
81
+ chain: Optional[str]
82
+ logo: Optional[str]
83
+ audits: Optional[str]
84
+ audit_note: Optional[str]
85
+ audit_links: Optional[List[str]]
86
+ gecko_id: Optional[str]
87
+ cmcId: Optional[str]
88
+ category: Optional[str]
89
+ chains: Optional[List[str]]
90
+ module: Optional[str]
91
+ treasury: Optional[str]
92
+ forkedFrom: Optional[List[str]]
93
+ forkedFromIds: Optional[List[str]]
94
+ twitter: Optional[str]
95
+ misrepresentedTokens: Optional[bool]
96
+ slug: Optional[str]
97
+ tvl: float
98
+ chainTvls: Optional[Dict[str, float]]
99
+ change_1h: Optional[float]
100
+ change_1d: Optional[float]
101
+ change_7d: Optional[float]
102
+ tokenBreakdowns: Optional[TokenBreakdowns]
103
+ mcap: Optional[float]
104
+ oracles: Optional[List[str]]
105
+ oraclesBreakdown: Optional[object]
106
+ listedAt: Optional[int]
107
+ methodology: Optional[str]
108
+ governanceID: Optional[List[str]]
109
+ stablecoins: Optional[List[str]]
110
+ referralUrl: Optional[str]
111
+ openSource: Optional[bool]
112
+ deadUrl: Optional[bool]
113
+ deadFrom: Optional[int]
114
+ github: Optional[List[str]]
115
+ language: Optional[str]
116
+ assetToken: Optional[str]
117
+ dimensions: Optional[Dict[str, object]]
118
+ hallmarks: Optional[List[List[object]]]
119
+ previousNames: Optional[List[str]]
120
+ rugged: Optional[bool]
121
+ tags: Optional[List[str]]
122
+ warningBanners: Optional[List[str]]
123
+ wrongLiquidity: Optional[bool]
124
+
125
+
126
+ class Hack(TypedDict, total=False):
127
+ date: int
128
+ name: str
129
+ classification: str
130
+ technique: str
131
+ amount: Optional[float]
132
+ chain: List[str]
133
+ bridgeHack: Optional[bool]
134
+ targetType: Optional[str]
135
+ source: Optional[str]
136
+ returnedFunds: Optional[float]
137
+ defillamaId: Optional[object]
138
+ language: Optional[str]
139
+ parentProtocolId: Optional[str]
140
+
141
+
142
+ class Raise(TypedDict, total=False):
143
+ date: int
144
+ name: str
145
+ round: Optional[str]
146
+ amount: float
147
+ chains: Optional[List[str]]
148
+ sector: Optional[str]
149
+ category: Optional[str]
150
+ categoryGroup: Optional[str]
151
+ source: Optional[str]
152
+ leadInvestors: List[str]
153
+ otherInvestors: Optional[List[str]]
154
+ valuation: Optional[float]
155
+ defillamaId: Optional[str]
156
+
157
+
158
+ class RaisesResponse(TypedDict):
159
+ raises: List[Raise]
160
+
161
+
162
+ __all__ = [
163
+ "CategoryTvlDataPoint",
164
+ "CategoriesResponse",
165
+ "ForkTvlDataPoint",
166
+ "ForksResponse",
167
+ "OracleTvlDataPoint",
168
+ "OraclesResponse",
169
+ "TokenBreakdowns",
170
+ "Entity",
171
+ "Treasury",
172
+ "Hack",
173
+ "Raise",
174
+ "RaisesResponse",
175
+ ]