Skip to content

Commit

Permalink
feat: addValidators proposal builder & proposal checker
Browse files Browse the repository at this point in the history
  • Loading branch information
0xvv committed Sep 25, 2024
1 parent 8498171 commit 92fb93e
Show file tree
Hide file tree
Showing 5 changed files with 7,550 additions and 0 deletions.
80 changes: 80 additions & 0 deletions utils/create-add-validator-proposal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import requests
import sys

def main():

if len(sys.argv) != 4:
print('Usage: create-add-validator-batch.py ACCOUNT_ID STAKING_CONTRACT FEE_RECIPIENT_IMPLEMENTATION')
sys.exit(1)

ACCOUNT_ID = sys.argv[1]
STAKING_CONTRACT = sys.argv[2]
FEE_RECIPIENT = sys.argv[3]

is_mainnet = input('Are you using mainnet? (y/n): ').lower() == 'y'
api_url = 'https://api.kiln.fi/v1/eth/onchain/v1/keys' if is_mainnet else 'https://api.testnet.kiln.fi/v1/eth/onchain/v1/keys'

api_token = input('Enter the Kiln API token: ')

total_count = input('Enter the total number of validators to create: ')

tx_batch_size = int(input('Enter the transaction batch size: '))

batch_size = int(input('Enter the API query batch size: '))

print("")

batch_count = int(total_count) // batch_size

concatenated_public_keys = ''
concatenated_signatures = ''

for i in range(batch_count):
print(f'Querying batch {i+1} of {batch_count}')
# Create the request
response = requests.post(
api_url,
headers={
'Content-Type': 'application/json',
'Authorization': f'Bearer {api_token}'
},
json={
'account_id': ACCOUNT_ID,
'fee_recipient_contract_address': FEE_RECIPIENT,
'staking_contract_address': STAKING_CONTRACT,
'number': batch_size,
'format': "cli_deposit"
}
)

# extract the json response
data = response.json()["data"]

for item in data:
concatenated_public_keys += item['pubkey']
concatenated_signatures += item['signature']

# extract the data and concatenate the public keys and signatures
print(f"Done with batch {i+1}")

print('All batches queried successfully')

for i in range(0, int(total_count) // int(tx_batch_size)):
pubkeys = concatenated_public_keys[i*tx_batch_size*96:(i+1)*tx_batch_size*96]
signatures = concatenated_signatures[i*tx_batch_size*192:(i+1)*tx_batch_size*192]

# dirty way to create the transaction json
transaction = '{"version":"1.0","chainId":"1","createdAt":1725982694510,"meta":{"name":"Transactions Batch","description":"","txBuilderVersion":"1.17.0","createdFromSafeAddress":"0xFafCba8F8F4282c4C629A6Bb4b98226A7C3E989f","createdFromOwnerAddress":"","checksum":"0x651d0ee6dc73fb8eb5bc170da82f9147e97267367af72e75cb38a05a27da26b7"},"transactions":[{"to":"'+ STAKING_CONTRACT +'","value":"0","data":null,"contractMethod":{"inputs":[{"internalType":"uint256","name":"_operatorIndex","type":"uint256"},{"internalType":"uint256","name":"_keyCount","type":"uint256"},{"internalType":"bytes","name":"_publicKeys","type":"bytes"},{"internalType":"bytes","name":"_signatures","type":"bytes"}],"name":"addValidators","payable":false},"contractInputsValues":{"_operatorIndex":"0","_keyCount":"'+str(tx_batch_size)+'","_publicKeys":"0x'+ pubkeys +'","_signatures":"0x'+ signatures +'"}}]}'

# save in file
with open(f'add-validators{i}.json', 'w') as f:
f.write(transaction)

print(f'Proposal saved in add-validators{i}.json')

print('All proposals saved successfully')


if __name__ == "__main__":
""" This is executed when run from the command line """
main()
64 changes: 64 additions & 0 deletions utils/proposal-check/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
"name": "proposal-check",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"build": "tsc",
"proposal-check": "ts-node ./src/index.ts",
"test": "ts-mocha tests/**/*.test.ts",
"test:coverage": "nyc ts-mocha tests/**/*.test.ts",
"lint": "eslint \"**/*.{ts,tsx}\"",
"lint:fix": "eslint \"**/*.{ts,tsx}\" --fix"
},
"license": "MIT",
"dependencies": {
"@chainsafe/as-sha256": "0.2.4",
"@chainsafe/bls": "6.0.3",
"@chainsafe/lodestar-params": "0.31.0",
"@chainsafe/lodestar-types": "0.31.0",
"@commitlint/cli": "^17.1.2",
"@commitlint/config-conventional": "^17.1.0",
"@semantic-release/changelog": "^6.0.1",
"@semantic-release/git": "^10.0.1",
"ethers": "^5.7.1",
"husky": "^8.0.1",
"semantic-release": "^19.0.5",
"ts-dotenv": "^0.8.3",
"ts-node": "^10.9.1",
"typescript": "^4.8.3"
},
"devDependencies": {
"@types/chai": "^4.3.3",
"@types/mocha": "^9.1.1",
"@typescript-eslint/eslint-plugin": "^5.36.2",
"@typescript-eslint/parser": "^5.36.2",
"chai": "^4.3.6",
"eslint": "8.22.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.2.1",
"mocha": "^10.0.0",
"nyc": "^15.1.0",
"prettier": "^2.7.1",
"ts-mocha": "^10.0.0"
},
"commitlint": {
"extends": [
"@commitlint/config-conventional"
]
},
"husky": {
"hooks": {
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
}
},
"release": {
"plugins": [
"@semantic-release/release-notes-generator",
"@semantic-release/changelog",
"@semantic-release/npm",
"@semantic-release/git",
"@semantic-release/github"
]
}
}

Loading

0 comments on commit 92fb93e

Please sign in to comment.