From c64976e136c8ef6b6e93b0db49ab7e53218f8818 Mon Sep 17 00:00:00 2001 From: SHAKOTN Date: Tue, 26 Sep 2023 13:16:21 +0300 Subject: [PATCH] feat: fix csv_airdrop.py script and generate proper json payload --- BIPs/00batched/2023-W38/BIP-431-airdrop.json | 118 +++++++++---------- tools/python/brownie/requirements.txt | 2 +- tools/python/brownie/scripts/csv_airdrop.py | 48 ++++++-- 3 files changed, 96 insertions(+), 72 deletions(-) diff --git a/BIPs/00batched/2023-W38/BIP-431-airdrop.json b/BIPs/00batched/2023-W38/BIP-431-airdrop.json index d75cc8458..667f7c85d 100644 --- a/BIPs/00batched/2023-W38/BIP-431-airdrop.json +++ b/BIPs/00batched/2023-W38/BIP-431-airdrop.json @@ -31,8 +31,8 @@ "payable": false }, "contractInputsValues": { - "to": "0xdf330ccb1d8fe97d176850bc127d0101cbe4e932", - "value": 1395061 + "to": "0xc59a1a2ed72eb7b31b8eaedab1f6f8d8c8881365", + "value": 3187040443 } }, { @@ -56,8 +56,8 @@ "payable": false }, "contractInputsValues": { - "to": "0xdf330ccb1d8fe97d176850bc127d0101cbe4e932", - "value": 1395061 + "to": "0xd56e9f604ba364d5df09730afcf946845ace6683", + "value": 2715625111 } }, { @@ -81,8 +81,8 @@ "payable": false }, "contractInputsValues": { - "to": "0xdf330ccb1d8fe97d176850bc127d0101cbe4e932", - "value": 1395061 + "to": "0x5c866c6ae5187130c234bc474a9fd55e3ea0ac5d", + "value": 1744260251 } }, { @@ -106,8 +106,8 @@ "payable": false }, "contractInputsValues": { - "to": "0xdf330ccb1d8fe97d176850bc127d0101cbe4e932", - "value": 1395061 + "to": "0xe356e05c77c4df64ffd033432b969e229980f28b", + "value": 1578000000 } }, { @@ -131,8 +131,8 @@ "payable": false }, "contractInputsValues": { - "to": "0xdf330ccb1d8fe97d176850bc127d0101cbe4e932", - "value": 1395061 + "to": "0x5a407865411253e5a991d3e49e8bc7a1fdbe82b0", + "value": 1262081183 } }, { @@ -156,8 +156,8 @@ "payable": false }, "contractInputsValues": { - "to": "0xdf330ccb1d8fe97d176850bc127d0101cbe4e932", - "value": 1395061 + "to": "0xc407d9993b29f0ada4a98686f134c78567d0f562", + "value": 1200000000 } }, { @@ -181,8 +181,8 @@ "payable": false }, "contractInputsValues": { - "to": "0xdf330ccb1d8fe97d176850bc127d0101cbe4e932", - "value": 1395061 + "to": "0xf7401728edd23290d8099ed73f155101dcf8cc0c", + "value": 1123482439 } }, { @@ -206,8 +206,8 @@ "payable": false }, "contractInputsValues": { - "to": "0xdf330ccb1d8fe97d176850bc127d0101cbe4e932", - "value": 1395061 + "to": "0xc4f91e9d571d1366551e01056a1c8a2b8b01f8ec", + "value": 1012546862 } }, { @@ -231,8 +231,8 @@ "payable": false }, "contractInputsValues": { - "to": "0xdf330ccb1d8fe97d176850bc127d0101cbe4e932", - "value": 1395061 + "to": "0x1a7c7f0c3defe3818a0a8d90b41573546717f145", + "value": 429375872 } }, { @@ -256,8 +256,8 @@ "payable": false }, "contractInputsValues": { - "to": "0xdf330ccb1d8fe97d176850bc127d0101cbe4e932", - "value": 1395061 + "to": "0x8484e288b7c2edad1b5214ed9df3bae4af7dadf5", + "value": 147906745 } }, { @@ -281,8 +281,8 @@ "payable": false }, "contractInputsValues": { - "to": "0xdf330ccb1d8fe97d176850bc127d0101cbe4e932", - "value": 1395061 + "to": "0x1928c92c7b9d9a9699776f9fb57ad6c84b44be33", + "value": 108302140 } }, { @@ -306,8 +306,8 @@ "payable": false }, "contractInputsValues": { - "to": "0xdf330ccb1d8fe97d176850bc127d0101cbe4e932", - "value": 1395061 + "to": "0x5614c860bfcb8d8ea59e14c8aee0b3f73511cd5b", + "value": 96394942 } }, { @@ -331,8 +331,8 @@ "payable": false }, "contractInputsValues": { - "to": "0xdf330ccb1d8fe97d176850bc127d0101cbe4e932", - "value": 1395061 + "to": "0xe69e85b87e46ff35b32bd93aa5e9cf0a09b1c221", + "value": 86010151 } }, { @@ -356,8 +356,8 @@ "payable": false }, "contractInputsValues": { - "to": "0xdf330ccb1d8fe97d176850bc127d0101cbe4e932", - "value": 1395061 + "to": "0xa24d30dd8cec57a8be66f7359c7cced581df29ed", + "value": 71995470 } }, { @@ -381,8 +381,8 @@ "payable": false }, "contractInputsValues": { - "to": "0xdf330ccb1d8fe97d176850bc127d0101cbe4e932", - "value": 1395061 + "to": "0xff4f7b726ee86f810531d2842b3bdd8a512db594", + "value": 67914668 } }, { @@ -406,8 +406,8 @@ "payable": false }, "contractInputsValues": { - "to": "0xdf330ccb1d8fe97d176850bc127d0101cbe4e932", - "value": 1395061 + "to": "0x83e92a956c551bec407d83e17f4317d9771466c3", + "value": 66156207 } }, { @@ -431,8 +431,8 @@ "payable": false }, "contractInputsValues": { - "to": "0xdf330ccb1d8fe97d176850bc127d0101cbe4e932", - "value": 1395061 + "to": "0x82b417ba7daf38c496435e23e7714b5860c1c85f", + "value": 64244563 } }, { @@ -456,8 +456,8 @@ "payable": false }, "contractInputsValues": { - "to": "0xdf330ccb1d8fe97d176850bc127d0101cbe4e932", - "value": 1395061 + "to": "0x53cfd45b8416322a72009bcf0f57f54d906d947b", + "value": 60076408 } }, { @@ -481,8 +481,8 @@ "payable": false }, "contractInputsValues": { - "to": "0xdf330ccb1d8fe97d176850bc127d0101cbe4e932", - "value": 1395061 + "to": "0xbc0b4983f6375b25ae7d0f8f56d029cc24f78d05", + "value": 40248605 } }, { @@ -506,8 +506,8 @@ "payable": false }, "contractInputsValues": { - "to": "0xdf330ccb1d8fe97d176850bc127d0101cbe4e932", - "value": 1395061 + "to": "0x73e47e110dd251bd6449381724f2bb51c11b14bc", + "value": 21667100 } }, { @@ -531,8 +531,8 @@ "payable": false }, "contractInputsValues": { - "to": "0xdf330ccb1d8fe97d176850bc127d0101cbe4e932", - "value": 1395061 + "to": "0x4624c8bde33545893bac01a999dda0f9296b3588", + "value": 19184894 } }, { @@ -556,8 +556,8 @@ "payable": false }, "contractInputsValues": { - "to": "0xdf330ccb1d8fe97d176850bc127d0101cbe4e932", - "value": 1395061 + "to": "0x3d631a345b1b45bf8a1456e43f91267304d5e048", + "value": 15997492 } }, { @@ -581,8 +581,8 @@ "payable": false }, "contractInputsValues": { - "to": "0xdf330ccb1d8fe97d176850bc127d0101cbe4e932", - "value": 1395061 + "to": "0x5388a7f24e86c9c9d855a98c2f5a339afa6a3acc", + "value": 12279972 } }, { @@ -606,8 +606,8 @@ "payable": false }, "contractInputsValues": { - "to": "0xdf330ccb1d8fe97d176850bc127d0101cbe4e932", - "value": 1395061 + "to": "0x892fac1beb41e5e4b44a21e2dbe238d92ff9564c", + "value": 6718158 } }, { @@ -631,8 +631,8 @@ "payable": false }, "contractInputsValues": { - "to": "0xdf330ccb1d8fe97d176850bc127d0101cbe4e932", - "value": 1395061 + "to": "0x6d7ac63aaa7ba8925dcb3e44be6355261dcf688f", + "value": 5723600 } }, { @@ -656,8 +656,8 @@ "payable": false }, "contractInputsValues": { - "to": "0xdf330ccb1d8fe97d176850bc127d0101cbe4e932", - "value": 1395061 + "to": "0xee49b4204275d1439d38af53ddaffa940b07f111", + "value": 3150087 } }, { @@ -681,8 +681,8 @@ "payable": false }, "contractInputsValues": { - "to": "0xdf330ccb1d8fe97d176850bc127d0101cbe4e932", - "value": 1395061 + "to": "0x40b1d8b0b7232eb3258a455445ecfb3813f13fb8", + "value": 3119999 } }, { @@ -706,8 +706,8 @@ "payable": false }, "contractInputsValues": { - "to": "0xdf330ccb1d8fe97d176850bc127d0101cbe4e932", - "value": 1395061 + "to": "0x125ad150043f25a8c0a09c8b82ac2a26eaac1400", + "value": 1868476 } }, { @@ -731,8 +731,8 @@ "payable": false }, "contractInputsValues": { - "to": "0xdf330ccb1d8fe97d176850bc127d0101cbe4e932", - "value": 1395061 + "to": "0x75c9aa37a479d5edf521a505d9b366b442c80dac", + "value": 1793849 } }, { @@ -761,4 +761,4 @@ } } ] -} +} \ No newline at end of file diff --git a/tools/python/brownie/requirements.txt b/tools/python/brownie/requirements.txt index 5e19d3a21..4215118c9 100644 --- a/tools/python/brownie/requirements.txt +++ b/tools/python/brownie/requirements.txt @@ -15,4 +15,4 @@ pytz==2021.1 numpy==1.22.4 web3==5.24.0 click<8.1.0 -#regex==2021.09.30 ## Fixes some issue with mac M1 and brownie 1.1 \ No newline at end of file +regex==2021.10.8 ## Fixes some issue with mac M1 and brownie 1.1 \ No newline at end of file diff --git a/tools/python/brownie/scripts/csv_airdrop.py b/tools/python/brownie/scripts/csv_airdrop.py index 0109cc218..0d5b3b1dd 100644 --- a/tools/python/brownie/scripts/csv_airdrop.py +++ b/tools/python/brownie/scripts/csv_airdrop.py @@ -1,28 +1,48 @@ import csv import json -from brownie import Contract +from copy import deepcopy + +from web3 import Web3 + +CSV = "../../../../BIPs/00batched/2023-w38/BIP-431-airdrop.csv" +JSON = "../../../../BIPs/00batched/2023-w38/BIP-431-airdrop.json" +TX_TEMPLATE = "../../tx_builder_templates/erc20_transfer.json" +BASE_TEMPLATE = "../../tx_builder_templates/base.json" + +ERC20_ABI = [ + { + "constant": True, + "inputs": [], + "name": "decimals", + "outputs": [{"name": "", "type": "uint8"}], + "payable": False, + "stateMutability": "view", + "type": "function", + }, +] -CSV="../../../BIPs/00batched/2023-w38/BIP-431-airdrop.csv" -JSON="../../../BIPs/00batched/2023-w38/BIP-431-airdrop.json" -TX_TEMPLATE="../tx_builder_templates/erc20_transfer.json" -BASE_TEMPLATE="../tx_builder_templates/base.json" def main(): + web3 = Web3(Web3.HTTPProvider("http://localhost:8545")) # TODO: change to arb node + csvfile = open(CSV, "r") txs = csv.reader(csvfile) with open(TX_TEMPLATE, "r") as jsonfile: tx_template = json.load(jsonfile) with open(BASE_TEMPLATE, "r") as jsonfile: - payload = json.load(jsonfile) + payload = json.load(jsonfile) txlist = [] for row in txs: - token_address= row[1] + token_address = row[1] + token_contract = web3.eth.contract( + address=Web3.toChecksumAddress(token_address), abi=ERC20_ABI + ) receiver = row[2] amount = float(row[3]) - print (token_address, amount) - token = Contract(token_address) - raw_amount = int(amount * 10**token.decimals()) - tx_data = tx_template + print(token_address, amount) + # token = Contract(token_address) + raw_amount = int(amount * 10 ** token_contract.functions.decimals().call()) + tx_data = deepcopy(tx_template) tx_data["contractInputsValues"]["to"] = receiver tx_data["contractInputsValues"]["value"] = raw_amount tx_data["to"] = token_address @@ -31,4 +51,8 @@ def main(): payload["transactions"] = txlist print(txlist) with open(JSON, "w") as output: - json.dump(payload, output, indent=2) \ No newline at end of file + json.dump(payload, output, indent=2) + + +if __name__ == "__main__": + main()