Skip to content

State parsing script for smart pools #21

Open
@Ramarti

Description

@Ramarti

For a regular Balancer Pool, token weights, swap fees, cap etc. can be inferred by calling correspondent view functions in their smart contract or by checking Balancer UI, since they are set once and can't change.

However, for Configurable Rights Pool like the one used by PERP protocol for liquidity bootstrapping, token weights were changed periodically.

In other cases, tokens can be dynamically added and removed, swap fees can change, and cap limits.

In order to have a reproducible set of actions, we need a script that either

  • connects to an archive node and uses BPool / ConfigurableRightsPool view functions to get change history
  • goes through every transaction to the pool parsing the anonymous log event
    event LogCall(
        bytes4  indexed sig,
        address indexed caller,
        bytes data
    ) anonymous;

Into a readable sequence of events with method names and parameters.
This would allow us also to know in detail which methods where used to add / remove liquidity from pools (Balancer has different methods where you know either the exact amount of pool share tokens you want in/out and give limits for tokens in/out of the pool, or viceversa)

Example json output for other actions we are using:

[
    {
        "unixtimestamp": "1607348054",
        "datetime": "2020-12-07 13:34:14",
        "tokens": {
            "DAI": [
                {
                    "from": "0x9d7c587709205fe908fac2be6df9bc15c4b56b37",
                    "to": "0x8b6e6e7b5b3801fed2cafd4b22b8a16c2f2db21a",
                    "value": "10000000"
                }
            ],
            "WETH": [
                {
                    "from": "0x9d7c587709205fe908fac2be6df9bc15c4b56b37",
                    "to": "0x8b6e6e7b5b3801fed2cafd4b22b8a16c2f2db21a",
                    "value": "67738.636173102396002749"
                }
            ],
            "BPT": [
                {
                    "from": "0x0000000000000000000000000000000000000000",
                    "to": "0x8b6e6e7b5b3801fed2cafd4b22b8a16c2f2db21a",
                    "value": "100"
                },
                {
                    "from": "0x8b6e6e7b5b3801fed2cafd4b22b8a16c2f2db21a",
                    "to": "0x9d7c587709205fe908fac2be6df9bc15c4b56b37",
                    "value": "100"
                }
            ]
        },
        "index": 0,
        "action": {
            "type": "join",
            "pool_amount_out": "100",
            "tokens_in": {
                "DAI": "10000000",
                "WETH": "67738.636173102396002749"
            }
        },
        "tx_hash": "0xb5875c4663360b8d311ddef2b394e64aae74a362332ae0212eea02c868ced7c3"
    },
    {
        "unixtimestamp": "1607348406",
        "datetime": "2020-12-07 13:40:06",
        "tokens": {
            "DAI": [
                {
                    "from": "0x0000000000007f150bd6f54c40a34d7c3d5e9f56",
                    "to": "0x8b6e6e7b5b3801fed2cafd4b22b8a16c2f2db21a",
                    "value": "11861.328308360999600128"
                }
            ],
            "WETH": [
                {
                    "from": "0x8b6e6e7b5b3801fed2cafd4b22b8a16c2f2db21a",
                    "to": "0x0000000000007f150bd6f54c40a34d7c3d5e9f56",
                    "value": "20.021734699893455844"
                }
            ]
        },
        "index": 1,
        "action": {
            "type": "swap",
            "token_in": "DAI",
            "token_amount_in": "11861.328308360999600128",
            "token_out": "WETH",
            "token_amount_out": "20.021734699893455844"
        },
        "tx_hash": "0x0319e9eacb5c6ec9905ccdda0e0d9971ac22410bfabf6f32212608d5f0565aef"
    },
]

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions