Skip to content

Commit

Permalink
Merge pull request #13 from itzmestar/stablecoins
Browse files Browse the repository at this point in the history
Stablecoins
  • Loading branch information
itzmestar committed May 9, 2024
2 parents f818733 + e659301 commit f2526e9
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ 3.7, 3.8, 3.9, '3.10' ]
python-version: [ 3.7, 3.8, 3.9, '3.10', '3.11', '3.12' ]

steps:
- uses: actions/checkout@v2
Expand Down
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# DeFiLlama

[![Python 3.6](https://img.shields.io/badge/python-3.6-blue.svg)](https://www.python.org/downloads/release/python-360/)
[![Python 3.7](https://img.shields.io/badge/python-3.7-blue.svg)](https://www.python.org/downloads/release/python-370/)
[![Python 3.8](https://img.shields.io/badge/python-3.8-blue.svg)](https://www.python.org/downloads/release/python-380/)
[![Python 3.9](https://img.shields.io/badge/python-3.9-blue.svg)](https://www.python.org/downloads/release/python-390/)
[![Python 3.10](https://img.shields.io/badge/python-3.10-blue.svg)](https://www.python.org/downloads/release/python-310/)
[![Python 3.10](https://img.shields.io/badge/python-3.10-blue.svg)](https://www.python.org/downloads/release/python-31014/)
[![Python 3.11](https://img.shields.io/badge/python-3.11-blue.svg)](https://www.python.org/downloads/release/python-3119/)
[![Python 3.12](https://img.shields.io/badge/python-3.12-blue.svg)](https://www.python.org/downloads/release/python-3123/)

[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)

Expand Down Expand Up @@ -46,6 +47,17 @@ response = llama.get_all_protocols()
response = llama.get_protocol(name='uniswap')
```

Data from stablecoins dashboard

```
# List all stablecoins along with their circulating amounts
response = llama.get_stablecoins()
# Get historical mcap sum of all stablecoins in a chain
response = llama.get_stablecoins_chains_all_historical_mcap_sum(chain='Ethereum', stablecoin_id=1)
```

-------
#### Donate & Help maintain the library

Expand Down
2 changes: 1 addition & 1 deletion defillama/__version__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
__title__ = 'DeFiLlama'
__description__ = 'Unofficial DeFi Llama API client.'
__url__ = 'https://github.com/itzmestar/DeFiLlama'
__version__ = '2.2.1'
__version__ = '2.3.0'
__build__ = 0x010001
__author__ = 'Tarique Anwer'
__author_email__ = '[email protected]'
Expand Down
62 changes: 62 additions & 0 deletions defillama/defillama.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,68 @@ def get_closest_ts_block(self, chain: str, timestamp: int):

return self._get(path)

# ##### Stablecoins EPs ###### #

def get_stablecoins(self, include_prices: bool = True):
"""
List all stablecoins along with their circulating amounts
"""
path = "https://stablecoins.llama.fi/stablecoins"

params = {
'includePrices': include_prices
}

return self._get(path, params=params, full_url=True)

def get_stablecoins_all_historical_mcap_sum(self, stablecoin_id: int):
"""
Get historical mcap sum of all stablecoins
"""
path = "https://stablecoins.llama.fi/stablecoincharts/all"

params = {
'stablecoin': stablecoin_id
}

return self._get(path, params=params, full_url=True)

def get_stablecoins_chains_all_historical_mcap_sum(self, chain: str, stablecoin_id: int):
"""
Get historical mcap sum of all stablecoins in a chain
"""
path = f"https://stablecoins.llama.fi/stablecoincharts/{chain}"

params = {
'stablecoin': stablecoin_id
}

return self._get(path, params=params, full_url=True)

def get_stablecoins_historical_mcap_n_chain_distribution(self, stablecoin_id: int):
"""
Get historical mcap & historical chain distribution of a stablecoin
"""
path = f"https://stablecoins.llama.fi/stablecoin/{stablecoin_id}"

return self._get(path, full_url=True)

def get_stablecoins_all_current_mcap_sum(self):
"""
Get current mcap sum of all stablecoins on each chain
"""
path = f"https://stablecoins.llama.fi/stablecoinchains"

return self._get(path, full_url=True)

def get_stablecoins_historical_prices(self):
"""
Get historical prices of all stablecoins
"""
path = f"https://stablecoins.llama.fi/stablecoinprices"

return self._get(path, full_url=True)

# ##### Yields EPs ###### #

def get_pools(self):
Expand Down
57 changes: 57 additions & 0 deletions tests/test_defillama.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,38 @@ def test_get_chains_current_tvl(self, llama):
assert 'chainId' in data
break

# ##### Test Coins EPs ###### #

# ##### Test Stablecoins EPs ###### #
def test_get_stablecoins(self, llama):
response = llama.get_stablecoins()
assert type(response) is dict
assert 'peggedAssets' in response
assert type(response['peggedAssets']) is list

def test_get_stablecoins_all_historical_mcap_sum(self, llama):
response = llama.get_stablecoins_all_historical_mcap_sum(1)
assert type(response) is list

def test_get_stablecoins_chains_all_historical_mcap_sum(self, llama):
response = llama.get_stablecoins_chains_all_historical_mcap_sum(chain='Ethereum', stablecoin_id=1)
assert type(response) is list

@pytest.mark.skip(reason='TBD')
def test_get_stablecoins_historical_mcap_n_chain_distribution(self, llama):
response = llama.get_stablecoins_historical_mcap_n_chain_distribution(stablecoin_id=1)
assert True

def test_get_stablecoins_all_current_mcap_sum(self, llama):
response = llama.get_stablecoins_all_current_mcap_sum()
assert type(response) is list

def test_get_stablecoins_historical_prices(self, llama):
response = llama.get_stablecoins_historical_prices()
assert type(response) is list

# ##### Test Yields EPs ###### #

def test_get_pools(self, llama):
response = llama.get_pools()
assert type(response) is dict
Expand All @@ -71,6 +103,7 @@ def test_get_pool(self, llama):
assert 'status' in response
assert 'data' in response

# ##### Test Volumes EPs ###### #
def test_get_dexs(self, llama):
response = llama.get_dexs()
assert type(response) is dict
Expand Down Expand Up @@ -114,3 +147,27 @@ def test_get_options_dex_summary(self, llama):
assert 'name' in response
assert 'url' in response
assert 'totalDataChart' in response

# ##### Test Fees & Revenue EPs ###### #

def test_get_fees(self, llama):
response = llama.get_fees()
assert type(response) is dict
assert 'totalDataChart' in response
assert 'totalDataChartBreakdown' in response
assert 'protocols' in response

def test_get_fees_chain(self, llama):
response = llama.get_fees_chain(chain='ethereum')
assert type(response) is dict
assert 'totalDataChart' in response
assert 'totalDataChartBreakdown' in response
assert 'protocols' in response

def test_get_fees_protocol(self, llama):
response = llama.get_fees_protocol(protocol='lyra')
assert type(response) is dict
assert 'id' in response
assert 'name' in response
assert 'url' in response
assert 'totalDataChart' in response

0 comments on commit f2526e9

Please sign in to comment.