forked from xdevguild/esdt-and-egld-airdrop-scripts
-
Notifications
You must be signed in to change notification settings - Fork 1
/
LKMEXSender_WeightedByNFTHold.py
128 lines (89 loc) · 4.03 KB
/
LKMEXSender_WeightedByNFTHold.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import binascii
from tokenize import Hexnumber
from erdpy.accounts import Account
from erdpy.proxy import ElrondProxy
from erdpy.transactions import Transaction
import argparse
import pandas as pd
pd.options.mode.chained_assignment = None # default='warn'
# ---------------------------------------------------------------- #
# INPUTS
# ---------------------------------------------------------------- #
parser = argparse.ArgumentParser()
parser.add_argument("--filename", help="CSV file with two cols : Address and Count", required=True)
parser.add_argument("--amount_airdrop", help="The total amount of LKMEX ot be airdropped", required=True)
parser.add_argument("--id", help="The collection id of the LKMEX (The last 6 alphanumericals)", required=True)
parser.add_argument("--pem", help="The wallet that sends txs (needs to hold the LKMEX)", required=True)
args = parser.parse_args()
# Read the input file
data_df = pd.read_csv(args.filename)
# If not done already, remove SC addresses
eligible_holders = data_df[data_df.Address.apply(lambda x: "qqqqqq" not in x)]
# Compute the total of LKMEX per address (given the number of NFT hold)
# TMP FIX : Remove 0.1 LKMEX per NFT to avoid "insufficient founds" (due to Python's loss of precision)
airdrop_per_NFT = float(args.amount_airdrop) / ( eligible_holders.Count.sum() ) - 0.1
eligible_holders["Airdrop"] = airdrop_per_NFT*data_df.Count
# ---------------------------------------------------------------- #
# CONSTANTS
# ---------------------------------------------------------------- #
TOKEN_DECIMALS = 1000000000000000000 # 10^18 (18 decimals)
TOKEN_COLLECTION = "LKMEX-aab910"
TOKEN_ID = args.id
# ---------------------------------------------------------------- #
# HELPER FUNCTIONS
# ---------------------------------------------------------------- #
def text_to_hex(text) :
return binascii.hexlify(text.encode()).decode()
# Sometimes need to add a 0 (if it's even, to be sure that is grouped by bytes)
def num_to_hex(num) :
hexa = format(num, "x")
if len(hexa)%2==1 :
return "0" + hexa
return hexa
def int_to_BigInt(num) :
return int(f"{num*TOKEN_DECIMALS:.1f}".split(".")[0])
# ---------------------------------------------------------------- #
# MAIN LKMEX FONCTION
# ---------------------------------------------------------------- #
def sendLKMEX(owner, receiver, amount):
payload = "ESDTNFTTransfer@" + "@".join([text_to_hex(TOKEN_COLLECTION),
TOKEN_ID,
num_to_hex(int_to_BigInt(amount)),
receiver.address.hex()])
tx = Transaction()
tx.nonce = owner.nonce
tx.value = "0"
tx.sender = owner.address.bech32()
tx.receiver = owner.address.bech32()
tx.gasPrice = gas_price
tx.gasLimit = 500000
tx.data = payload
tx.chainID = chain
tx.version = tx_version
tx.sign(owner)
tx_hash = tx.send(proxy)
owner.nonce+=1
return tx_hash
# ---------------------------------------------------------------- #
# SETTING MAINNET PARAMS
# ---------------------------------------------------------------- #
proxy_address = "https://gateway.elrond.com"
proxy = ElrondProxy(proxy_address)
network = proxy.get_network_config()
chain = network.chain_id
gas_price = network.min_gas_price
tx_version = network.min_tx_version
# The owner of the tokens, that will send them
owner = Account(pem_file=args.pem)
owner.sync_nonce(proxy)
# ---------------------------------------------------------------- #
# AIRDROP LOOP
# ---------------------------------------------------------------- #
for _, row in eligible_holders.iterrows():
quantity = row["Airdrop"]
address = row["Address"]
try :
sendLKMEX(owner, Account(address),quantity)
except :
# Keep those addresses aside for debugging, and re-sending after
print(address)