Rari
Examples
Note
These examples are crafted as a Jupyter notebook. You can download the original notebook file here.
Also note that inside Jupyter notebooks, await
can be used freely outside of asyncio.run()
.
In [1]:
from ctc.protocols import rari_utils
In [2]:
comptroller = '0xc54172e34046c1653d1920d40333dd358c7a1af4'
ctoken = '0xd8553552f8868c1ef160eedf031cf0bcf9686945'
underlying_token = '0x956f47f50a910163d8bf957cf5846d573e7f87ca'
Get all pools¶
In [3]:
fuse_pools = await rari_utils.async_get_all_pools()
len(fuse_pools)
Out[3]:
202
Get pool metadata¶
In [4]:
ctokens = await rari_utils.async_get_pool_ctokens(comptroller=comptroller)
ctokens
Out[4]:
('0xd8553552f8868c1ef160eedf031cf0bcf9686945', '0xfd3300a9a74b3250f1b2abc12b47611171910b07', '0xbb025d470162cc5ea24daf7d4566064ee7f5f111', '0x7e9ce3caa9910cc048590801e64174957ed41d43', '0x5ca8ffe4dad9452ed880fa429dd0a08574225936', '0xbfb6f7532d2db0fe4d83abb001c5c2b0842af4db', '0x30fa046ba48c193230722ec9068ba7234e40ffd2', '0xb723e1dbd267d215b40c2be756b158f83b68503b', '0x7259ee19d6b5e755e7c65cecfd2466c09e251185', '0x647a36d421183a0a9fa62717a64b664a24e469c7', '0x0d54596900df651e6954226e1e1141f1e4980258')
In [5]:
underlying_tokens = await rari_utils.async_get_pool_underlying_tokens(comptroller=comptroller)
underlying_tokens
Out[5]:
{'0xd8553552f8868c1ef160eedf031cf0bcf9686945': '0x956f47f50a910163d8bf957cf5846d573e7f87ca', '0xfd3300a9a74b3250f1b2abc12b47611171910b07': '0xc7283b66eb1eb5fb86327f08e1b5816b0720212b', '0xbb025d470162cc5ea24daf7d4566064ee7f5f111': '0x0000000000000000000000000000000000000000', '0x7e9ce3caa9910cc048590801e64174957ed41d43': '0x6b175474e89094c44da98b954eedeac495271d0f', '0x5ca8ffe4dad9452ed880fa429dd0a08574225936': '0xbaaa1f5dba42c3389bdbc2c9d2de134f5cd0dc89', '0xbfb6f7532d2db0fe4d83abb001c5c2b0842af4db': '0x06cb22615ba53e60d67bf6c341a0fd5e718e1655', '0x30fa046ba48c193230722ec9068ba7234e40ffd2': '0x3d1556e84783672f2a3bd187a592520291442539', '0xb723e1dbd267d215b40c2be756b158f83b68503b': '0xcf84a3dc12319531e3debd48c86e68eaeaff224a', '0x7259ee19d6b5e755e7c65cecfd2466c09e251185': '0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0', '0x647a36d421183a0a9fa62717a64b664a24e469c7': '0x5f98805a4e8be255a32880fdec7f6728c6568ba0', '0x0d54596900df651e6954226e1e1141f1e4980258': '0x559ebc30b0e58a45cc9ff573f77ef1e5eb1b3e18'}
Get pool state¶
In [6]:
tvl_and_tvb = await rari_utils.async_get_pool_tvl_and_tvb(comptroller=comptroller)
tvl_and_tvb
Out[6]:
{'tvl': 21484187.085672226, 'tvb': 18539823.760518614}
In [7]:
prices = await rari_utils.async_get_pool_prices(comptroller=comptroller)
prices
Out[7]:
{'0xd8553552f8868c1ef160eedf031cf0bcf9686945': 1.0075195576032028, '0xfd3300a9a74b3250f1b2abc12b47611171910b07': 0.2094838515, '0xbb025d470162cc5ea24daf7d4566064ee7f5f111': 1295.91, '0x7e9ce3caa9910cc048590801e64174957ed41d43': 1.0050559596000002, '0x5ca8ffe4dad9452ed880fa429dd0a08574225936': 1.004836828418787, '0xbfb6f7532d2db0fe4d83abb001c5c2b0842af4db': 1.0126434312735182, '0x30fa046ba48c193230722ec9068ba7234e40ffd2': 0.010655016237218972, '0xb723e1dbd267d215b40c2be756b158f83b68503b': 520.7037161447378, '0x7259ee19d6b5e755e7c65cecfd2466c09e251185': 1402.1244992788068, '0x647a36d421183a0a9fa62717a64b664a24e469c7': 1.0341835199999998, '0x0d54596900df651e6954226e1e1141f1e4980258': 1.0594131586349256}
Get ctoken state¶
In [8]:
await rari_utils.async_get_ctoken_state(ctoken)
Out[8]:
{'tvl': 12274901.507479219, 'tvb': 12274901.507479219, 'supply_apy': 0.024947221966542532, 'borrow_apy': 0.026546236787341915}
Get ctoken state across multiple blocks¶
In [9]:
blocks = [14000000, 14100000, 14200000]
await rari_utils.async_get_ctoken_state_by_block(ctoken, blocks=blocks)
Out[9]:
{'tvl': [25592342.86812161, 27846764.4866587, 26131727.36829893], 'tvb': [21279628.94118887, 25522233.17882379, 21041419.8055125], 'supply_apy': [0.1577145831367548, 0.5777531640145352, 0.06528371436195024], 'borrow_apy': [0.20572510722810078, 0.6961907149308775, 0.08695883809682425]}
Print Fuse summmary¶
In [10]:
await rari_utils.async_print_all_pool_summary()
Rari Fuse ─────────
- TVL: $176.47M - TVB: $149.63M - block: 15613498
# │ pool │ TVL │ TVB ───────┼───────────────────────────┼────────────┼──────────── 136 │ ICHI Pool │ $64.97M │ $63.83M 8 │ FeiRari (Fei DAO Pool) │ $21.48M │ $18.54M 18 │ Olympus Pool Party │ $21.2M │ $18.15M 156 │ Tribe Convex Pool │ $14.54M │ $14.41M 127 │ 0xb1's Kitchen Sink │ $13.57M │ $13.38M 6 │ Tetranode's Pool │ $12.97M │ $2.7M 27 │ Stake DAO Pool │ $5.55M │ $4.29M 7 │ Tetranode's ETH Pool │ $4.72M │ $1.09M 144 │ Babylon's Gold Lender │ $4.52M │ $4.5M 90 │ Float Protocol Pool │ $4.41M │ $4.41M 146 │ Tribe ETH Pool │ $3.15M │ $3.15M 102 │ DeFiGeek Community Pool │ $2.27M │ $337.68K 9 │ FRAX RAI Stable Pool │ $1.51M │ $834.1K 116 │ handle globalFX │ $864.62K │ $0 31 │ NFTX Pool │ $733.71K │ $4.72K
Print single token stats across multiple pools¶
In [11]:
await rari_utils.async_print_fuse_token_summary(underlying_token)
FEI Token Fuse Usage ────────────────────
- TVL: $24.77M - TVB: $24.57M - block: 15613499
pool │ TVL │ TVB │ supply % │ borrow % │ util % ─────────────────────────────────────┼────────────┼──────────────┼──────────────┼─────────────┼────────── Tetranode's Flavor of the Month │ $12.27M │ $12.27M │ 2.49% │ 2.65% │ 100% Tribe Convex Pool │ $8.54M │ $8.54M │ 124.35% │ 143.57% │ 100% Stake DAO Pool │ $1.31M │ $1.31M │ 2.15% │ 2.65% │ 100% Babylon's Gold Lender │ $857.84K │ $857.54K │ 118.74% │ 159.82% │ 99.97% Tetranode's ETH Pool │ $716.05K │ $715.62K │ 149.16% │ 168.52% │ 99.94% Float Protocol Pool │ $713.37K │ $713.37K │ 853.32% │ 1,063.27% │ 100% Tetranode's Pool │ $246.53K │ $100.47K │ 3.1% │ 8.59% │ 40.75% Olympus Pool Party │ $40.27K │ $25.66K │ 682.04% │ 656.18% │ 63.72% UMA Community Pool │ $32.29K │ $28.41K │ 153.18% │ 238.92% │ 88% Fox and Frens │ $31.38K │ $3.92K │ inf% │ inf% │ 12.49% Badger Pool │ $5.69K │ $2.99K │ inf% │ 31.65% │ 52.62% NFTX Pool │ $4.02K │ $49.62 │ 0.002473% │ 0.248939% │ 1.23% Barnbridge pool │ $1.38K │ $888.26 │ 3.2% │ 5.39% │ 64.6% Harvest FARMstead │ $1.13K │ $31.75 │ inf% │ inf% │ 2.81% troopersGarage │ $485.53 │ $2.681e-13 │ 0% │ 2.53% │ 0% Token Mass Injection Pool │ $122.48 │ $1.04e-12 │ 683.91% │ 31.65% │ 0% Index Coop Pool │ $85.46 │ $1.569e-12 │ 0% │ 0.000123% │ 0% G-UNI │ $49.84 │ $2.587e-13 │ 50,616.83% │ 1,151.29% │ 0% Frax & Reflexer Stable Asset Pool │ $10.31 │ $5.648e-13 │ 0% │ 0.000003% │ 0%
Get token stats across multiple pools¶
In [12]:
token_stats = await rari_utils.async_get_token_multipool_stats('0x956f47f50a910163d8bf957cf5846d573e7f87ca')
print('- aggregate stats:', token_stats['total'])
print('- # pools:', len(token_stats['per_pool']))
print('- stats given for each pool:', list(token_stats['per_pool'][comptroller].keys()))
- aggregate stats: {'tvl': 24772786.543556392, 'tvb': 24570960.8652956} - # pools: 42 - stats given for each pool: ['tvl', 'tvb', 'ctoken', 'matches', 'supply_apy', 'borrow_apy', 'name', 'pool_index']
Reference
- async ctc.protocols.rari_utils.async_get_all_pools(block=None, provider=None)
- async ctc.protocols.rari_utils.async_get_ctoken_state(ctoken, *, block='latest', metrics=None, eth_price=None, in_usd=True)
- async ctc.protocols.rari_utils.async_get_ctoken_state_by_block(ctoken, blocks, *, metrics=None, eth_price=None, in_usd=True)
- async ctc.protocols.rari_utils.async_get_pool_ctokens(comptroller, *, block='latest')
- async ctc.protocols.rari_utils.async_get_pool_prices(*, oracle=None, ctokens=None, comptroller=None, block='latest', to_usd=True)
- async ctc.protocols.rari_utils.async_get_pool_tvl_and_tvb(*, comptroller=None, ctokens=None, oracle=None, block='latest')
- async ctc.protocols.rari_utils.async_get_pool_underlying_tokens(*, ctokens=None, comptroller=None, block='latest')
- async ctc.protocols.rari_utils.async_get_token_multipool_stats(token, block='latest', *, in_usd=True)
- async ctc.protocols.rari_utils.async_print_all_pool_summary(block='latest', n_display=15)
- async ctc.protocols.rari_utils.async_print_fuse_token_summary(token, *, block='latest', in_usd=True)