keep-network / local-setup

Allow to easily set up tBTC and Keep locally for development and test purposes.
MIT License
8 stars 16 forks source link

Check bonded ETH for operators #48

Open nkuba opened 3 years ago

nkuba commented 3 years ago

We are getting bond creation events to obtain values of bonds created for all the ECDSA operators.

pdyraga commented 3 years ago

I was testing this script locally with four operators:

Scenario 1 ✅

Initial state:

┌─────────┬──────────────────────────────────────────────┬───────────────────┬──────────────────────────────────────────────────┬────────────────────┬────────────────────┬──────────────────┬────────────────┬─────────────────┬────────────────────────┬──────────────────────┐
│ (index) │                   address                    │ eligibleStakeKeep │                operatorBalanceEth                │ depositedAmountEth │ withdrawnAmountEth │ unbondedValueEth │ bondsAmountEth │ seizedAmountEth │ isRegisteredInTbtcPool │ isUpToDateInTbtcPool │
├─────────┼──────────────────────────────────────────────┼───────────────────┼──────────────────────────────────────────────────┼────────────────────┼────────────────────┼──────────────────┼────────────────┼─────────────────┼────────────────────────┼──────────────────────┤
│    0    │ '0x3365d0ed0e526d3b1d8b417fc0fde5b1cef2f416' │    '20000000'     │ '999999999999999999999999999999999999.996875216' │        '50'        │        '0'         │       '50'       │      '0'       │       '0'       │          true          │         true         │
│    1    │ '0x7020a5556ba1ce5f92c81063a13d33512cf1305c' │    '20000000'     │ '999999999999999999999999999999999999.996874897' │        '50'        │        '0'         │       '50'       │      '0'       │       '0'       │          true          │         true         │
│    2    │ '0x524f2e0176350d950fa630d9a5a59a0a190daf48' │    '20000000'     │ '999999999999999999999999999999999999.996875535' │        '50'        │        '0'         │       '50'       │      '0'       │       '0'       │          true          │         true         │
│    3    │ '0x65ea55c1f10491038425725dc00dffeab2a1e28a' │    '20000000'     │ '999999999999999999999999999999999999.883456701' │        '50'        │        '0'         │       '50'       │      '0'       │       '0'       │          true          │         true         │
└─────────┴──────────────────────────────────────────────┴───────────────────┴──────────────────────────────────────────────────┴────────────────────┴────────────────────┴──────────────────┴────────────────┴─────────────────┴────────────────────────┴──────────────────────┘

Created keep 0x43293fFe178B64A7342a0346F9D57974DB22d3EC with members:

Intermediate state:

┌─────────┬──────────────────────────────────────────────┬───────────────────┬───────────────────────────────────────────────────────────┬────────────────────┬────────────────────┬─────────────────────────┬────────────────────────┬─────────────────┬────────────────────────┬──────────────────────┐
│ (index) │                   address                    │ eligibleStakeKeep │                    operatorBalanceEth                     │ depositedAmountEth │ withdrawnAmountEth │    unbondedValueEth     │     bondsAmountEth     │ seizedAmountEth │ isRegisteredInTbtcPool │ isUpToDateInTbtcPool │
├─────────┼──────────────────────────────────────────────┼───────────────────┼───────────────────────────────────────────────────────────┼────────────────────┼────────────────────┼─────────────────────────┼────────────────────────┼─────────────────┼────────────────────────┼──────────────────────┤
│    0    │ '0x3365d0ed0e526d3b1d8b417fc0fde5b1cef2f416' │    '20000000'     │     '999999999999999999999999999999999999.996875216'      │        '50'        │        '0'         │          '50'           │          '0'           │       '0'       │          true          │         true         │
│    1    │ '0x7020a5556ba1ce5f92c81063a13d33512cf1305c' │    '20000000'     │     '999999999999999999999999999999999999.996733331'      │        '50'        │        '0'         │ '49.999999999999999996' │ '0.000000000000000004' │       '0'       │          true          │         true         │
│    2    │ '0x524f2e0176350d950fa630d9a5a59a0a190daf48' │    '20000000'     │     '999999999999999999999999999999999999.996703122'      │        '50'        │        '0'         │ '49.999999999999999996' │ '0.000000000000000004' │       '0'       │          true          │         true         │
│    3    │ '0x65ea55c1f10491038425725dc00dffeab2a1e28a' │    '20000000'     │ '999999999999999999999999999999999999.899962083444444444' │        '50'        │        '0'         │ '49.999999999999999996' │ '0.000000000000000004' │       '0'       │          true          │         true         │
└─────────┴──────────────────────────────────────────────┴───────────────────┴───────────────────────────────────────────────────────────┴────────────────────┴────────────────────┴─────────────────────────┴────────────────────────┴─────────────────┴────────────────────────┴──────────────────────┘

Closed keep 0x43293fFe178B64A7342a0346F9D57974DB22d3EC.

End state:

┌─────────┬──────────────────────────────────────────────┬───────────────────┬───────────────────────────────────────────────────────────┬────────────────────┬────────────────────┬──────────────────┬────────────────┬─────────────────┬────────────────────────┬──────────────────────┐
│ (index) │                   address                    │ eligibleStakeKeep │                    operatorBalanceEth                     │ depositedAmountEth │ withdrawnAmountEth │ unbondedValueEth │ bondsAmountEth │ seizedAmountEth │ isRegisteredInTbtcPool │ isUpToDateInTbtcPool │
├─────────┼──────────────────────────────────────────────┼───────────────────┼───────────────────────────────────────────────────────────┼────────────────────┼────────────────────┼──────────────────┼────────────────┼─────────────────┼────────────────────────┼──────────────────────┤
│    0    │ '0x3365d0ed0e526d3b1d8b417fc0fde5b1cef2f416' │    '20000000'     │     '999999999999999999999999999999999999.996875216'      │        '50'        │        '0'         │       '50'       │      '0'       │       '0'       │          true          │         true         │
│    1    │ '0x7020a5556ba1ce5f92c81063a13d33512cf1305c' │    '20000000'     │     '999999999999999999999999999999999999.996733331'      │        '50'        │        '0'         │       '50'       │      '0'       │       '0'       │          true          │         true         │
│    2    │ '0x524f2e0176350d950fa630d9a5a59a0a190daf48' │    '20000000'     │     '999999999999999999999999999999999999.996703122'      │        '50'        │        '0'         │       '50'       │      '0'       │       '0'       │          true          │         true         │
│    3    │ '0x65ea55c1f10491038425725dc00dffeab2a1e28a' │    '20000000'     │ '999999999999999999999999999999999999.899962083444444444' │        '50'        │        '0'         │       '50'       │      '0'       │       '0'       │          true          │         true         │
└─────────┴──────────────────────────────────────────────┴───────────────────┴───────────────────────────────────────────────────────────┴────────────────────┴────────────────────┴──────────────────┴────────────────┴─────────────────┴────────────────────────┴──────────────────────┘

Scenario 2 ❌

Initial state:

┌─────────┬──────────────────────────────────────────────┬───────────────────┬───────────────────────────────────────────────────────────┬────────────────────┬────────────────────┬──────────────────┬────────────────┬─────────────────┬────────────────────────┬──────────────────────┐
│ (index) │                   address                    │ eligibleStakeKeep │                    operatorBalanceEth                     │ depositedAmountEth │ withdrawnAmountEth │ unbondedValueEth │ bondsAmountEth │ seizedAmountEth │ isRegisteredInTbtcPool │ isUpToDateInTbtcPool │
├─────────┼──────────────────────────────────────────────┼───────────────────┼───────────────────────────────────────────────────────────┼────────────────────┼────────────────────┼──────────────────┼────────────────┼─────────────────┼────────────────────────┼──────────────────────┤
│    0    │ '0x3365d0ed0e526d3b1d8b417fc0fde5b1cef2f416' │    '20000000'     │     '999999999999999999999999999999999999.996875216'      │        '50'        │        '0'         │       '50'       │      '0'       │       '0'       │          true          │         true         │
│    1    │ '0x7020a5556ba1ce5f92c81063a13d33512cf1305c' │    '20000000'     │     '999999999999999999999999999999999999.996733331'      │        '50'        │        '0'         │       '50'       │      '0'       │       '0'       │          true          │         true         │
│    2    │ '0x524f2e0176350d950fa630d9a5a59a0a190daf48' │    '20000000'     │     '999999999999999999999999999999999999.996703122'      │        '50'        │        '0'         │       '50'       │      '0'       │       '0'       │          true          │         true         │
│    3    │ '0x65ea55c1f10491038425725dc00dffeab2a1e28a' │    '20000000'     │ '999999999999999999999999999999999999.899962083444444444' │        '50'        │        '0'         │       '50'       │      '0'       │       '0'       │          true          │         true         │
└─────────┴──────────────────────────────────────────────┴───────────────────┴───────────────────────────────────────────────────────────┴────────────────────┴────────────────────┴──────────────────┴────────────────┴─────────────────┴────────────────────────┴──────────────────────┘

Created keep 0x6a613E21cc3Ea0D14eCa39Ac3131531F3296fDdc with members:

Created keep 0xddE46d893748662CE6102944f6cdA9517D0092D7 with members:

Created keep 0xcD1C4B4e17D0Ae5fCCc9150cfe23B67cb33364Fb with members:

Intermediate state:

┌─────────┬──────────────────────────────────────────────┬───────────────────┬───────────────────────────────────────────────────────────┬────────────────────┬────────────────────┬─────────────────────────┬────────────────────────┬─────────────────┬────────────────────────┬──────────────────────┐
│ (index) │                   address                    │ eligibleStakeKeep │                    operatorBalanceEth                     │ depositedAmountEth │ withdrawnAmountEth │    unbondedValueEth     │     bondsAmountEth     │ seizedAmountEth │ isRegisteredInTbtcPool │ isUpToDateInTbtcPool │
├─────────┼──────────────────────────────────────────────┼───────────────────┼───────────────────────────────────────────────────────────┼────────────────────┼────────────────────┼─────────────────────────┼────────────────────────┼─────────────────┼────────────────────────┼──────────────────────┤
│    0    │ '0x3365d0ed0e526d3b1d8b417fc0fde5b1cef2f416' │    '20000000'     │     '999999999999999999999999999999999999.996450858'      │        '50'        │        '0'         │ '49.999999999999999988' │ '0.000000000000000012' │       '0'       │          true          │         true         │
│    1    │ '0x7020a5556ba1ce5f92c81063a13d33512cf1305c' │    '20000000'     │     '999999999999999999999999999999999999.996454601'      │        '50'        │        '0'         │ '49.999999999999999992' │ '0.000000000000000008' │       '0'       │          true          │         true         │
│    2    │ '0x524f2e0176350d950fa630d9a5a59a0a190daf48' │    '20000000'     │     '999999999999999999999999999999999999.996358004'      │        '50'        │        '0'         │ '49.999999999999999992' │ '0.000000000000000008' │       '0'       │          true          │         true         │
│    3    │ '0x65ea55c1f10491038425725dc00dffeab2a1e28a' │    '20000000'     │ '999999999999999999999999999999999999.949629693777777776' │        '50'        │        '0'         │ '49.999999999999999992' │ '0.000000000000000008' │       '0'       │          true          │         true         │
└─────────┴──────────────────────────────────────────────┴───────────────────┴───────────────────────────────────────────────────────────┴────────────────────┴────────────────────┴─────────────────────────┴────────────────────────┴─────────────────┴────────────────────────┴──────────────────────┘

Seized bonds from keep 0xcD1C4B4e17D0Ae5fCCc9150cfe23B67cb33364Fb.

End state:

┌─────────┬──────────────────────────────────────────────┬───────────────────┬───────────────────────────────────────────────────────────┬────────────────────┬────────────────────┬─────────────────────────┬────────────────────────┬─────────────────┬────────────────────────┬──────────────────────┐
│ (index) │                   address                    │ eligibleStakeKeep │                    operatorBalanceEth                     │ depositedAmountEth │ withdrawnAmountEth │    unbondedValueEth     │     bondsAmountEth     │ seizedAmountEth │ isRegisteredInTbtcPool │ isUpToDateInTbtcPool │
├─────────┼──────────────────────────────────────────────┼───────────────────┼───────────────────────────────────────────────────────────┼────────────────────┼────────────────────┼─────────────────────────┼────────────────────────┼─────────────────┼────────────────────────┼──────────────────────┤
│    0    │ '0x3365d0ed0e526d3b1d8b417fc0fde5b1cef2f416' │    '20000000'     │     '999999999999999999999999999999999999.996450858'      │        '50'        │        '0'         │ '49.999999999999999988' │ '0.000000000000000008' │       '0'       │          true          │         true         │
│    1    │ '0x7020a5556ba1ce5f92c81063a13d33512cf1305c' │    '20000000'     │     '999999999999999999999999999999999999.996454601'      │        '50'        │        '0'         │ '49.999999999999999992' │ '0.000000000000000004' │       '0'       │          true          │         true         │
│    2    │ '0x524f2e0176350d950fa630d9a5a59a0a190daf48' │    '20000000'     │     '999999999999999999999999999999999999.996358004'      │        '50'        │        '0'         │ '49.999999999999999992' │ '0.000000000000000008' │       '0'       │          true          │         true         │
│    3    │ '0x65ea55c1f10491038425725dc00dffeab2a1e28a' │    '20000000'     │ '999999999999999999999999999999999999.949629693777777776' │        '50'        │        '0'         │ '49.999999999999999992' │ '0.000000000000000004' │       '0'       │          true          │         true         │
└─────────┴──────────────────────────────────────────────┴───────────────────┴───────────────────────────────────────────────────────────┴────────────────────┴────────────────────┴─────────────────────────┴────────────────────────┴─────────────────┴────────────────────────┴──────────────────────┘

Problem: Please see that seizedAmountEth shows 0. I thought it's a precision issue and removed all fromWei calls for seized bonds but it still shows 0.

Scenario 3 :x:

Initial state:

┌─────────┬──────────────────────────────────────────────┬───────────────────┬───────────────────────────────────────────────────────────┬────────────────────┬────────────────────┬─────────────────────────┬────────────────────────┬─────────────────┬────────────────────────┬──────────────────────┐
│ (index) │                   address                    │ eligibleStakeKeep │                    operatorBalanceEth                     │ depositedAmountEth │ withdrawnAmountEth │    unbondedValueEth     │     bondsAmountEth     │ seizedAmountEth │ isRegisteredInTbtcPool │ isUpToDateInTbtcPool │
├─────────┼──────────────────────────────────────────────┼───────────────────┼───────────────────────────────────────────────────────────┼────────────────────┼────────────────────┼─────────────────────────┼────────────────────────┼─────────────────┼────────────────────────┼──────────────────────┤
│    0    │ '0x3365d0ed0e526d3b1d8b417fc0fde5b1cef2f416' │    '20000000'     │     '999999999999999999999999999999999999.996450858'      │        '50'        │        '0'         │ '49.999999999999999988' │ '0.000000000000000008' │       '0'       │          true          │         true         │
│    1    │ '0x7020a5556ba1ce5f92c81063a13d33512cf1305c' │    '20000000'     │     '999999999999999999999999999999999999.996454601'      │        '50'        │        '0'         │ '49.999999999999999992' │ '0.000000000000000004' │       '0'       │          true          │         true         │
│    2    │ '0x524f2e0176350d950fa630d9a5a59a0a190daf48' │    '20000000'     │     '999999999999999999999999999999999999.996358004'      │        '50'        │        '0'         │ '49.999999999999999992' │ '0.000000000000000008' │       '0'       │          true          │         true         │
│    3    │ '0x65ea55c1f10491038425725dc00dffeab2a1e28a' │    '20000000'     │ '999999999999999999999999999999999999.949629693777777776' │        '50'        │        '0'         │ '49.999999999999999992' │ '0.000000000000000004' │       '0'       │          true          │         true         │
└─────────┴──────────────────────────────────────────────┴───────────────────┴───────────────────────────────────────────────────────────┴────────────────────┴────────────────────┴─────────────────────────┴────────────────────────┴─────────────────┴────────────────────────┴──────────────────────┘

Note that seizedAmountEth value is not accurate - see the previous scenario.

Returned 12 wei to keep 0xcD1C4B4e17D0Ae5fCCc9150cfe23B67cb33364Fb.

End state:

┌─────────┬──────────────────────────────────────────────┬───────────────────┬───────────────────────────────────────────────────────────┬─────────────────────────┬────────────────────┬─────────────────────────┬────────────────────────┬─────────────────┬────────────────────────┬──────────────────────┐
│ (index) │                   address                    │ eligibleStakeKeep │                    operatorBalanceEth                     │   depositedAmountEth    │ withdrawnAmountEth │    unbondedValueEth     │     bondsAmountEth     │ seizedAmountEth │ isRegisteredInTbtcPool │ isUpToDateInTbtcPool │
├─────────┼──────────────────────────────────────────────┼───────────────────┼───────────────────────────────────────────────────────────┼─────────────────────────┼────────────────────┼─────────────────────────┼────────────────────────┼─────────────────┼────────────────────────┼──────────────────────┤
│    0    │ '0x3365d0ed0e526d3b1d8b417fc0fde5b1cef2f416' │    '20000000'     │     '999999999999999999999999999999999999.996450858'      │ '50.000000000000000004' │        '0'         │ '49.999999999999999992' │ '0.000000000000000008' │       '0'       │          true          │         true         │
│    1    │ '0x7020a5556ba1ce5f92c81063a13d33512cf1305c' │    '20000000'     │     '999999999999999999999999999999999999.996454601'      │ '50.000000000000000004' │        '0'         │ '49.999999999999999996' │ '0.000000000000000004' │       '0'       │          true          │         true         │
│    2    │ '0x524f2e0176350d950fa630d9a5a59a0a190daf48' │    '20000000'     │     '999999999999999999999999999999999999.996358004'      │          '50'           │        '0'         │ '49.999999999999999992' │ '0.000000000000000008' │       '0'       │          true          │         true         │
│    3    │ '0x65ea55c1f10491038425725dc00dffeab2a1e28a' │    '20000000'     │ '999999999999999999999999999999999999.949629693777777776' │ '50.000000000000000004' │        '0'         │ '49.999999999999999996' │ '0.000000000000000004' │       '0'       │          true          │         true         │
└─────────┴──────────────────────────────────────────────┴───────────────────┴───────────────────────────────────────────────────────────┴─────────────────────────┴────────────────────┴─────────────────────────┴────────────────────────┴─────────────────┴────────────────────────┴──────────────────────┘

Problem: Please see that the depositedAmountEth increased. It should never be higher than the initial 50 ETH.