Balancer
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 balancer_utils
In [2]:
pool_id = '0xc35bdda2e93c401c6645e0d8a0b2c86906c51710000200000000000000000111'
pool_address = '0xc35bdda2e93c401c6645e0d8a0b2c86906c51710'
Get pool metadata¶
In [3]:
await balancer_utils.async_get_pool_address(pool_id)
Out[3]:
'0xc35bdda2e93c401c6645e0d8a0b2c86906c51710'
In [4]:
await balancer_utils.async_get_pool_id(pool_address)
Out[4]:
'0xc35bdda2e93c401c6645e0d8a0b2c86906c51710000200000000000000000111'
In [5]:
await balancer_utils.async_get_pool_tokens(pool_address=pool_address)
Out[5]:
['0x956f47f50a910163d8bf957cf5846d573e7f87ca', '0xc7283b66eb1eb5fb86327f08e1b5816b0720212b']
In [6]:
await balancer_utils.async_get_pool_fees(pool_address=pool_address)
Out[6]:
0.003
Get pool weights¶
In [7]:
await balancer_utils.async_get_pool_weights(pool_address=pool_address)
Out[7]:
{'0x956f47f50a910163d8bf957cf5846d573e7f87ca': 0.10000762951094835, '0xc7283b66eb1eb5fb86327f08e1b5816b0720212b': 0.9000076295109484}
Get pool weights over time¶
In [8]:
blocks = [13900000, 14000000, 14100000, 14200000]
await balancer_utils.async_get_pool_weights_by_block(
pool_address=pool_address, blocks=blocks
)
Out[8]:
{13900000: [0.4740023386036203, 0.5260129205271249], 14000000: [0.378524825351098, 0.6214904337518591], 14100000: [0.2143885819218613, 0.7856266771333252], 14200000: [0.10000762951094835, 0.9000076295109484]}
Get pool balances¶
In [9]:
await balancer_utils.async_get_pool_balances(pool_address=pool_address)
Out[9]:
{'0x956f47f50a910163d8bf957cf5846d573e7f87ca': 5.6968e-14, '0xc7283b66eb1eb5fb86327f08e1b5816b0720212b': 2.181534e-12}
Get pool summary¶
In [10]:
await balancer_utils.async_summarize_pool_state(pool_address=pool_address)
Out[10]:
{'pool_tokens': ['0x956f47f50a910163d8bf957cf5846d573e7f87ca', '0xc7283b66eb1eb5fb86327f08e1b5816b0720212b'], 'pool_fees': 0.003, 'pool_weights': {'0x956f47f50a910163d8bf957cf5846d573e7f87ca': 0.10000762951094835, '0xc7283b66eb1eb5fb86327f08e1b5816b0720212b': 0.9000076295109484}, 'pool_balances': {'0x956f47f50a910163d8bf957cf5846d573e7f87ca': 5.6968e-14, '0xc7283b66eb1eb5fb86327f08e1b5816b0720212b': 2.181534e-12}, 'block': 15613495}
Get pool swaps¶
In [11]:
swaps = await balancer_utils.async_get_pool_swaps(pool_address=pool_address)
swaps
Out[11]:
block_hash | transaction_hash | contract_address | event_name | arg__poolId | arg__tokenIn | arg__tokenOut | arg__amountIn | arg__amountOut | address | event_hash | |||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
block_number | transaction_index | log_index | |||||||||||
13875964 | 204 | 312 | 0xee9f76842a8564480f150c8564baa42fa251fcdeb04e... | 0x0b09e9be1e29d6784f1ec65b02e2a33e189d4dc8fddb... | 0xba12222222228d8ba445958a75a0704d566bf2c8 | Swap | 0xc35bdda2e93c401c6645e0d8a0b2c86906c517100002... | 0x956f47f50a910163d8bf957cf5846d573e7f87ca | 0xc7283b66eb1eb5fb86327f08e1b5816b0720212b | 9282037308505057802273 | 8862947236144171799780 | 0xba12222222228d8ba445958a75a0704d566bf2c8 | 0x2170c741c41531aec20e7c107c24eecfdd15e69c9bb0... |
13876219 | 130 | 155 | 0x80c1942ea8f77e4c7efeacfe8faa695f013ac194dfec... | 0xedaa5fa750337f247e955e753341d1c6bee8f4a58ce6... | 0xba12222222228d8ba445958a75a0704d566bf2c8 | Swap | 0xc35bdda2e93c401c6645e0d8a0b2c86906c517100002... | 0xc7283b66eb1eb5fb86327f08e1b5816b0720212b | 0x956f47f50a910163d8bf957cf5846d573e7f87ca | 6770515949298292329779 | 7425664489255906163987 | 0xba12222222228d8ba445958a75a0704d566bf2c8 | 0x2170c741c41531aec20e7c107c24eecfdd15e69c9bb0... |
13876260 | 152 | 199 | 0xb4bd4ec34dca399c3550d0a022ad4239bd35de7da96f... | 0x4f18f6cb47daf4f18efcea52f1cac7f37e5795a4d1d7... | 0xba12222222228d8ba445958a75a0704d566bf2c8 | Swap | 0xc35bdda2e93c401c6645e0d8a0b2c86906c517100002... | 0xc7283b66eb1eb5fb86327f08e1b5816b0720212b | 0x956f47f50a910163d8bf957cf5846d573e7f87ca | 14130662641515379930887 | 15214927899208771740928 | 0xba12222222228d8ba445958a75a0704d566bf2c8 | 0x2170c741c41531aec20e7c107c24eecfdd15e69c9bb0... |
13876558 | 263 | 498 | 0x2417372e1cb5569d55524d5a74948d96add4396d34ba... | 0x150eaf7b7271da325fa067c6512fb16b681c6b03d2cf... | 0xba12222222228d8ba445958a75a0704d566bf2c8 | Swap | 0xc35bdda2e93c401c6645e0d8a0b2c86906c517100002... | 0xc7283b66eb1eb5fb86327f08e1b5816b0720212b | 0x956f47f50a910163d8bf957cf5846d573e7f87ca | 14181099804346772686440 | 15589833329021211807661 | 0xba12222222228d8ba445958a75a0704d566bf2c8 | 0x2170c741c41531aec20e7c107c24eecfdd15e69c9bb0... |
13876669 | 124 | 219 | 0x7b78aa102ae489e65aadc43aa36a0405c74136166cc0... | 0x0f467d14428523705970c40c9f6a6a0767518c8b0ca2... | 0xba12222222228d8ba445958a75a0704d566bf2c8 | Swap | 0xc35bdda2e93c401c6645e0d8a0b2c86906c517100002... | 0xc7283b66eb1eb5fb86327f08e1b5816b0720212b | 0x956f47f50a910163d8bf957cf5846d573e7f87ca | 93485409984034479616 | 103028232766980855821 | 0xba12222222228d8ba445958a75a0704d566bf2c8 | 0x2170c741c41531aec20e7c107c24eecfdd15e69c9bb0... |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
15423403 | 2 | 4 | 0x00048c148422b390b2f78f8a0a46854e502162c17344... | 0x57b9735a44b5de014a3e69f0e8a564b0ac248343a800... | 0xba12222222228d8ba445958a75a0704d566bf2c8 | Swap | 0xc35bdda2e93c401c6645e0d8a0b2c86906c517100002... | 0xc7283b66eb1eb5fb86327f08e1b5816b0720212b | 0x956f47f50a910163d8bf957cf5846d573e7f87ca | 4033490073421730937398 | 911931499638810770275 | 0xba12222222228d8ba445958a75a0704d566bf2c8 | 0x2170c741c41531aec20e7c107c24eecfdd15e69c9bb0... |
15423473 | 5 | 24 | 0x742c397c1044d8c4b1c82e8b3097c58f22380251d03a... | 0x2a0f16fb89fa69e690d4ac132f01a468f258971db432... | 0xba12222222228d8ba445958a75a0704d566bf2c8 | Swap | 0xc35bdda2e93c401c6645e0d8a0b2c86906c517100002... | 0x956f47f50a910163d8bf957cf5846d573e7f87ca | 0xc7283b66eb1eb5fb86327f08e1b5816b0720212b | 918429602325991972769 | 4037765462202588666117 | 0xba12222222228d8ba445958a75a0704d566bf2c8 | 0x2170c741c41531aec20e7c107c24eecfdd15e69c9bb0... |
15423526 | 2 | 12 | 0x32c4a753e8322eeb8e887be865f4a907dcd398c7fbbb... | 0xe88deeffe0387b8518eee1a2512157b121b0e9c23bae... | 0xba12222222228d8ba445958a75a0704d566bf2c8 | Swap | 0xc35bdda2e93c401c6645e0d8a0b2c86906c517100002... | 0x956f47f50a910163d8bf957cf5846d573e7f87ca | 0xc7283b66eb1eb5fb86327f08e1b5816b0720212b | 1171187367098000834500 | 5042903288618799623107 | 0xba12222222228d8ba445958a75a0704d566bf2c8 | 0x2170c741c41531aec20e7c107c24eecfdd15e69c9bb0... |
15424132 | 105 | 30 | 0x2227c1e1ff4809206ca56539da601e7eebfd9e862983... | 0x8b506c15a6029dbe41284efed0b792c2a5946129888b... | 0xba12222222228d8ba445958a75a0704d566bf2c8 | Swap | 0xc35bdda2e93c401c6645e0d8a0b2c86906c517100002... | 0x956f47f50a910163d8bf957cf5846d573e7f87ca | 0xc7283b66eb1eb5fb86327f08e1b5816b0720212b | 1142575013928542396992 | 4809610304432969625612 | 0xba12222222228d8ba445958a75a0704d566bf2c8 | 0x2170c741c41531aec20e7c107c24eecfdd15e69c9bb0... |
15431183 | 7 | 51 | 0xa280533250c08f73d67781dd7be203b27d4ef711f3bb... | 0xacd745a361c67cfed48bb747b363c8323d6c15180c3a... | 0xba12222222228d8ba445958a75a0704d566bf2c8 | Swap | 0xc35bdda2e93c401c6645e0d8a0b2c86906c517100002... | 0xc7283b66eb1eb5fb86327f08e1b5816b0720212b | 0x956f47f50a910163d8bf957cf5846d573e7f87ca | 4125429707992706735197 | 975778707613648542701 | 0xba12222222228d8ba445958a75a0704d566bf2c8 | 0x2170c741c41531aec20e7c107c24eecfdd15e69c9bb0... |
1680 rows × 11 columns
Reference
- async ctc.protocols.balancer_utils.async_get_pool_address(pool_id, block=None)
- async ctc.protocols.balancer_utils.async_get_pool_balances(*, pool_address=None, pool_id=None, block=None, vault=None, normalize=True, provider=None)
- async ctc.protocols.balancer_utils.async_get_pool_fees(pool_address, *, block='latest', normalize=True)
- async ctc.protocols.balancer_utils.async_get_pool_id(pool_address, block=None, *, provider=None)
- async ctc.protocols.balancer_utils.async_get_pool_swaps(pool_address=None, *, start_block=None, end_block=None, start_time=None, end_time=None, include_timestamps=False)
- async ctc.protocols.balancer_utils.async_get_pool_tokens(*, pool_address=None, pool_id=None, block=None)
- async ctc.protocols.balancer_utils.async_get_pool_weights(pool_address, block='latest', *, normalize=True)
- async ctc.protocols.balancer_utils.async_get_pool_weights_by_block(pool_address, blocks, *, normalize=True)
- async ctc.protocols.balancer_utils.async_summarize_pool_state(pool_address, block='latest')