Skip to content

Commit

Permalink
clean
Browse files Browse the repository at this point in the history
  • Loading branch information
scab24 committed Sep 16, 2024
1 parent b25d61e commit 5bfe1e9
Show file tree
Hide file tree
Showing 15 changed files with 1,342 additions and 2,014 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@
[submodule "lib/abdk-libraries-solidity"]
path = lib/abdk-libraries-solidity
url = https://github.com/abdk-consulting/abdk-libraries-solidity
[submodule "lib/v1-core"]
path = lib/v1-core
url = https://github.com/gammaswap/v1-core
1 change: 1 addition & 0 deletions lib/v1-core
Submodule v1-core added at f27920
138 changes: 69 additions & 69 deletions send_logreturns.py
Original file line number Diff line number Diff line change
@@ -1,69 +1,69 @@
import json
from web3 import Web3
import math
import os
from dotenv import load_dotenv

# Cargar variables de entorno desde .env
load_dotenv()

# Configurar conexión a Anvil (nodo local)
w3 = Web3(Web3.HTTPProvider("http://127.0.0.1:8545"))

# Verificar conexión
assert w3.isConnected(), "No se pudo conectar al nodo Ethereum"

# Dirección del contrato desplegado (cambiando según tu despliegue)
contrato_direccion = "0xYourContractAddressHere"

# Cargar ABI del contrato
with open("out/VolatilityCalculator.sol/VolatilityCalculator.json", "r") as f:
contrato_abi = json.load(f)["abi"]

# Crear instancia del contrato
contrato = w3.eth.contract(address=contrato_direccion, abi=contrato_abi)

# Dirección de la cuenta que enviará las transacciones (usar cuenta #0 de Anvil)
account = w3.eth.account.from_key(os.getenv("PRIVATE_KEY"))

# Precios históricos
precios = [100, 105, 102, 108]

def calculate_log_returns(prices):
log_returns = []
for i in range(1, len(prices)):
log_return = math.log(prices[i] / prices[i - 1])
log_returns.append(log_return)
return log_returns

def to_64x64(value):
return int(value * (2**64))

if __name__ == "__main__":
# Calcular retornos logarítmicos
log_returns = calculate_log_returns(precios)
print("Retornos Logarítmicos:", log_returns)

# Convertir a 64.64 fija
log_returns_64x64 = [to_64x64(r) for r in log_returns]
print("Retornos Logarítmicos (64.64 fija):", log_returns_64x64)

# Preparar la transacción
# Para optimizar, se enviarán todos los retornos en una sola transacción
tx = contrato.functions.addLogReturns(log_returns_64x64).buildTransaction({
'from': account.address,
'nonce': w3.eth.get_transaction_count(account.address),
'gas': 500000, # Ajusta según sea necesario
'gasPrice': w3.toWei('1', 'gwei') # Ajusta según sea necesario
})

# Firmar la transacción
signed_tx = account.sign_transaction(tx)

# Enviar la transacción
tx_hash = w3.eth.send_raw_transaction(signed_tx.rawTransaction)
print(f"Transacción enviada con hash: {tx_hash.hex()}")

# Esperar a que la transacción sea minada
receipt = w3.eth.wait_for_transaction_receipt(tx_hash)
print(f"Transacción minada en bloque {receipt.blockNumber}")
# import json
# from web3 import Web3
# import math
# import os
# from dotenv import load_dotenv

# # Load environment variables from .env
# load_dotenv()

# # Configure connection to Anvil (local node)
# w3 = Web3(Web3.HTTPProvider("http://127.0.0.1:8545"))

# # Verify connection
# assert w3.isConnected(), "Failed to connect to Ethereum node"

# # Deployed contract address (change according to your deployment)
# contract_address = "0x.."

# # Load contract ABI
# with open("out/VolatilityCalculator.sol/VolatilityCalculator.json", "r") as f:
# contract_abi = json.load(f)["abi"]

# # Create contract instance
# contract = w3.eth.contract(address=contract_address, abi=contract_abi)

# # Address of the account that will send transactions (use Anvil's account #0)
# account = w3.eth.account.from_key(os.getenv("PRIVATE_KEY"))

# # Historical prices
# prices = [100, 105, 102, 108]

# def calculate_log_returns(prices):
# log_returns = []
# for i in range(1, len(prices)):
# log_return = math.log(prices[i] / prices[i - 1])
# log_returns.append(log_return)
# return log_returns

# def to_64x64(value):
# return int(value * (2**64))

# if __name__ == "__main__":
# # Calculate logarithmic returns
# log_returns = calculate_log_returns(prices)
# print("Logarithmic Returns:", log_returns)

# # Convert to 64.64 fixed point
# log_returns_64x64 = [to_64x64(r) for r in log_returns]
# print("Logarithmic Returns (64.64 fixed point):", log_returns_64x64)

# # Prepare the transaction
# # To optimize, all returns will be sent in a single transaction
# tx = contract.functions.addLogReturns(log_returns_64x64).buildTransaction({
# 'from': account.address,
# 'nonce': w3.eth.get_transaction_count(account.address),
# 'gas': 500000, # Adjust as necessary
# 'gasPrice': w3.toWei('1', 'gwei') # Adjust as necessary
# })

# # Sign the transaction
# signed_tx = account.sign_transaction(tx)

# # Send the transaction
# tx_hash = w3.eth.send_raw_transaction(signed_tx.rawTransaction)
# print(f"Transaction sent with hash: {tx_hash.hex()}")

# # Wait for the transaction to be mined
# receipt = w3.eth.wait_for_transaction_receipt(tx_hash)
# print(f"Transaction mined in block {receipt.blockNumber}")
Loading

0 comments on commit 5bfe1e9

Please sign in to comment.