TokenEngineeringCommunity / BalancerPools_Model

cadCAD model to simulate Balancer AMMs
MIT License
54 stars 29 forks source link

State parsing script for smart pools #21

Open Ramarti opened 3 years ago

Ramarti commented 3 years ago

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

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 commented 3 years ago

@jzaki