Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

State parsing script for smart pools #21

Open
Ramarti opened this issue Jan 15, 2021 · 1 comment
Open

State parsing script for smart pools #21

Ramarti opened this issue Jan 15, 2021 · 1 comment
Assignees

Comments

@Ramarti
Copy link
Collaborator

Ramarti commented Jan 15, 2021

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"
    },
]
@Ramarti
Copy link
Collaborator Author

Ramarti commented Jan 15, 2021

@jzaki

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant