diff --git a/aptos/requirements.txt b/aptos/requirements.txt index e3dcfc61..fafcc226 100644 --- a/aptos/requirements.txt +++ b/aptos/requirements.txt @@ -1,6 +1,8 @@ aptos_sdk python-dotenv pathlib -yaml +pyyaml toml requests +eth-brownie +ccxt==1.72.64 diff --git a/aptos/scripts/relayer/oracle_aptos.py b/aptos/scripts/relayer/oracle_aptos.py new file mode 100644 index 00000000..2e774f02 --- /dev/null +++ b/aptos/scripts/relayer/oracle_aptos.py @@ -0,0 +1,69 @@ +from brownie import network +import ccxt + +from scripts.serde_aptos import get_serde_facet +from scripts.struct import omniswap_aptos_path, hex_str_to_vector_u8 +from scripts.utils import aptos_brownie + + +def set_so_gas(): + package = aptos_brownie.AptosPackage( + project_path=omniswap_aptos_path, + network="aptos-mainnet" + ) + + serde = get_serde_facet(package, network.show_active()) + + nets = ["mainnet", "bsc-main", "avax-main", "polygon-main"] + + for net in nets: + base_gas = hex_str_to_vector_u8(str(serde.normalizeU256( + package.network_config["wormhole"]["gas"][net]["base_gas"]))) + gas_per_bytes = hex_str_to_vector_u8(str(serde.normalizeU256( + package.network_config["wormhole"]["gas"][net]["per_byte_gas"]))) + print(f"Set wormhole gas for:{net}") + package["wormhole_facet::set_wormhole_gas"]( + package.network_config["wormhole"]["gas"][net]["dst_chainid"], + base_gas, + gas_per_bytes + ) + + +def set_so_price(): + api = ccxt.binance() + symbols = ["ETH/USDT", "BNB/USDT", "MATIC/USDT", "AVAX/USDT", "APT/USDT"] + prices = {} + + for symbol in symbols: + result = api.fetch_ohlcv(symbol=symbol, + timeframe="1m", + limit=1) + price = result[-1][4] + print(f"Symbol:{symbol}, price:{price}") + prices[symbol] = price + + ratio_decimal = 1e8 + multiply = 1.1 + package = aptos_brownie.AptosPackage( + project_path=omniswap_aptos_path, + network="aptos-mainnet" + ) + + nets = ["mainnet", "bsc-main", "avax-main", "polygon-main"] + + if "mainnet" in nets: + ratio = int(prices["ETH/USDT"] / prices["APT/USDT"] * ratio_decimal * multiply) + print(f"Set price ratio for mainnet:{ratio}") + package["so_fee_wormhole::set_price_ratio"](2, ratio) + if "bsc-main" in nets: + ratio = int(prices["BNB/USDT"] / prices["APT/USDT"] * ratio_decimal * multiply) + print(f"Set price ratio for bsc-main:{ratio}") + package["so_fee_wormhole::set_price_ratio"](4, ratio) + if "polygon-main" in nets: + ratio = int(prices["MATIC/USDT"] / prices["APT/USDT"] * ratio_decimal * multiply) + print(f"Set price ratio for polygon-main:{ratio}") + package["so_fee_wormhole::set_price_ratio"](5, ratio) + if "avax-main" in nets: + ratio = int(prices["AVAX/USDT"] / prices["APT/USDT"] * ratio_decimal * multiply) + print(f"Set price ratio for avax-main:{ratio}") + package["so_fee_wormhole::set_price_ratio"](6, ratio) diff --git a/ethereum/requirements.txt b/ethereum/requirements.txt index df51ac01..fafcc226 100644 --- a/ethereum/requirements.txt +++ b/ethereum/requirements.txt @@ -1,2 +1,8 @@ -eth-brownie +aptos_sdk python-dotenv +pathlib +pyyaml +toml +requests +eth-brownie +ccxt==1.72.64 diff --git a/ethereum/scripts/relayer/oracle_evm.py b/ethereum/scripts/relayer/oracle_evm.py new file mode 100644 index 00000000..e04a0134 --- /dev/null +++ b/ethereum/scripts/relayer/oracle_evm.py @@ -0,0 +1,81 @@ +from brownie import network, Contract, SoDiamond, WormholeFacet, LibSoFeeWormholeV1 +import ccxt + +from scripts.helpful_scripts import get_wormhole_info, get_account +from scripts.utils import aptos_brownie + + +def set_so_gas(): + proxy_wormhole = Contract.from_abi( + "WormholeFacet", SoDiamond[-1].address, WormholeFacet.abi) + + nets = ["mainnet", "bsc-main", "avax-main", "polygon-main"] + + gas = get_wormhole_info()["gas"] + for net in nets: + if net == network.show_active(): + continue + print(f"network:{network.show_active()}, " + f"set dst net {net} wormhole gas: " + f"base_gas:{gas[net]['base_gas']}," + f"per_byte_gas:{gas[net]['per_byte_gas']}") + proxy_wormhole.setWormholeGas( + gas[net]["dst_chainid"], + gas[net]["base_gas"], + gas[net]["per_byte_gas"], + {'from': get_account()} + ) + + +def set_so_price(): + api = ccxt.binance() + symbols = ["ETH/USDT", "BNB/USDT", "MATIC/USDT", "AVAX/USDT", "APT/USDT"] + prices = {} + + for symbol in symbols: + result = api.fetch_ohlcv(symbol=symbol, + timeframe="1m", + limit=1) + price = result[-1][4] + print(f"Symbol:{symbol}, price:{price}") + prices[symbol] = price + + decimal = 1e27 + multiply = 1.1 + if network.show_active() == "avax-main": + # bnb + dst_wormhole_id = 2 + ratio = int(prices["BNB/USDT"] / prices["AVAX/USDT"] * decimal * multiply) + print(f"Set price ratio for bnb-main:{ratio}") + LibSoFeeWormholeV1[-1].setPriceRatio(dst_wormhole_id, + ratio, {"from": get_account()}) + # aptos + dst_wormhole_id = 22 + ratio = int(prices["APT/USDT"] / prices["AVAX/USDT"] * decimal * multiply) + print(f"Set price ratio for aptos-mainnet:{ratio}") + LibSoFeeWormholeV1[-1].setPriceRatio(dst_wormhole_id, + ratio, {"from": get_account()}) + + if network.show_active() == "mainnet": + # aptos + dst_wormhole_id = 22 + ratio = int(prices["APT/USDT"] / prices["ETH/USDT"] * decimal * multiply) + print(f"Set price ratio for aptos-mainnet:{ratio}") + LibSoFeeWormholeV1[-1].setPriceRatio(dst_wormhole_id, + ratio, {"from": get_account()}) + + if network.show_active() == "polygon-main": + # aptos + dst_wormhole_id = 22 + ratio = int(prices["APT/USDT"] / prices["MATIC/USDT"] * decimal * multiply) + print(f"Set price ratio for aptos-mainnet:{ratio}") + LibSoFeeWormholeV1[-1].setPriceRatio(dst_wormhole_id, + ratio, {"from": get_account()}) + + if network.show_active() == "bsc-main": + # aptos + dst_wormhole_id = 22 + ratio = int(prices["APT/USDT"] / prices["BNB/USDT"] * decimal * multiply) + print(f"Set price ratio for aptos-mainnet:{ratio}") + LibSoFeeWormholeV1[-1].setPriceRatio(dst_wormhole_id, + ratio, {"from": get_account()})