diff --git a/.gitignore b/.gitignore index 3862e43..9e27562 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. # dependencies -/node_modules +trivex_frontend/node_modules/ /.pnp .pnp.js diff --git a/README.md b/README.md index a5393c8..24dbcc1 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,20 @@ npm install npm run start ``` +## Trivex Smart Contracts + +```bash +cd trivex_web +cd trivex_contract +``` + +## Trivex Titan Bot + +```bash +cd trivex_web +cd trivex titan +``` + ## 🌐 Community & Support - Website: [https://official-trivex.xyz](https://official-trivex.xyz) diff --git a/titan/titan.py b/titan/titan.py new file mode 100644 index 0000000..3216722 --- /dev/null +++ b/titan/titan.py @@ -0,0 +1,83 @@ +from starknet_py.contract import Contract +import asyncio +from starknet_py.net.full_node_client import FullNodeClient +from trader.hyperliquidTrader import hyperliquidTrader +import math + +contract_address = "0x05083aa7aba0aa78514ac84d70a7c969360a6095189d2fdfaafcb689b4734d38" + +async def get_all_user_addresses(contract): + addresses_result = await contract.functions["get_all_user_addresses"].call() + addresses = addresses_result[0] + hex_addresses = ["0x" + hex(addr)[2:].rjust(64, "0") for addr in addresses] + return hex_addresses + +async def get_internal_order_book(contract): + order_book_result = await contract.functions["get_internal_order_book"].call() + order_book_raw = order_book_result[0] + + order_book_cleaned = [] + for order in order_book_raw: + symbol_int = order['symbol'] + try: + symbol_str = bytes.fromhex(hex(symbol_int)[2:]).decode('utf-8').rstrip('\x00') + except: + symbol_str = str(symbol_int) + cleaned_order = { + 'symbol': symbol_str, + 'leverage': order['leverage'], + 'amount': order['amount'] / 1_000_000 + } + order_book_cleaned.append(cleaned_order) + + return order_book_cleaned + +def dynamic_round(num, size): + if num == 0: + return 0 + abs_num = abs(num) + + if abs_num >= 1: + digits_before_decimal = int(math.log10(abs_num)) + 1 + else: + digits_before_decimal = 0 + decimal_places = max(1, digits_before_decimal) + return float(round(size, decimal_places)) + +async def external_hedge(orders): + trader = hyperliquidTrader() + exchange = trader.getExchange() + info = trader.getInfo() + external_balance = info["marginSummary"]["accountValue"] + + print(external_balance) + + for order in orders: + print("************************************") + print(f"Order — Symbol: {order['symbol']}, Amount: {order['amount']}, Leverage: {order['leverage']}") + symbol = order["symbol"] + price = trader.getCurrentPrice(order["symbol"]) + price = float(price) + print(f"{symbol} price: {price}") + amount = order["amount"] + amount = float(amount) + leverage = order['leverage'] + size = dynamic_round(price, leverage*amount/price) + print(f"{symbol} size: {size}") + # trader.updateLeverage(exchange, leverage, symbol) + # trader.openOrder(True, symbol, size, exchange) + print("************************************") + +async def main(): + client = FullNodeClient(node_url="https://starknet-sepolia.public.blastapi.io") + contract = await Contract.from_address(contract_address, client) + + addresses = await get_all_user_addresses(contract) + print("User Addresses:", addresses) + + order_book = await get_internal_order_book(contract) + print("Internal Order Book:", order_book) + + await external_hedge(order_book) + +asyncio.run(main()) diff --git a/package-lock.json b/trivex_frontend/package-lock.json similarity index 100% rename from package-lock.json rename to trivex_frontend/package-lock.json diff --git a/package.json b/trivex_frontend/package.json similarity index 100% rename from package.json rename to trivex_frontend/package.json diff --git a/public/Titan.png b/trivex_frontend/public/Titan.png similarity index 100% rename from public/Titan.png rename to trivex_frontend/public/Titan.png diff --git a/public/_redirects b/trivex_frontend/public/_redirects similarity index 100% rename from public/_redirects rename to trivex_frontend/public/_redirects diff --git a/public/favicon.ico b/trivex_frontend/public/favicon.ico similarity index 100% rename from public/favicon.ico rename to trivex_frontend/public/favicon.ico diff --git a/public/index.html b/trivex_frontend/public/index.html similarity index 100% rename from public/index.html rename to trivex_frontend/public/index.html diff --git a/public/logo192.png b/trivex_frontend/public/logo192.png similarity index 100% rename from public/logo192.png rename to trivex_frontend/public/logo192.png diff --git a/public/logo5.png b/trivex_frontend/public/logo5.png similarity index 100% rename from public/logo5.png rename to trivex_frontend/public/logo5.png diff --git a/public/logo512.png b/trivex_frontend/public/logo512.png similarity index 100% rename from public/logo512.png rename to trivex_frontend/public/logo512.png diff --git a/public/logo_color.png b/trivex_frontend/public/logo_color.png similarity index 100% rename from public/logo_color.png rename to trivex_frontend/public/logo_color.png diff --git a/public/logo_round.png b/trivex_frontend/public/logo_round.png similarity index 100% rename from public/logo_round.png rename to trivex_frontend/public/logo_round.png diff --git a/public/logo_t.png b/trivex_frontend/public/logo_t.png similarity index 100% rename from public/logo_t.png rename to trivex_frontend/public/logo_t.png diff --git a/public/manifest.json b/trivex_frontend/public/manifest.json similarity index 100% rename from public/manifest.json rename to trivex_frontend/public/manifest.json diff --git a/public/robots.txt b/trivex_frontend/public/robots.txt similarity index 100% rename from public/robots.txt rename to trivex_frontend/public/robots.txt diff --git a/public/trivex_round.png b/trivex_frontend/public/trivex_round.png similarity index 100% rename from public/trivex_round.png rename to trivex_frontend/public/trivex_round.png diff --git a/src/App.css b/trivex_frontend/src/App.css similarity index 100% rename from src/App.css rename to trivex_frontend/src/App.css diff --git a/src/App.js b/trivex_frontend/src/App.js similarity index 100% rename from src/App.js rename to trivex_frontend/src/App.js diff --git a/src/App.test.js b/trivex_frontend/src/App.test.js similarity index 100% rename from src/App.test.js rename to trivex_frontend/src/App.test.js diff --git a/src/assets/Trivex1.png b/trivex_frontend/src/assets/Trivex1.png similarity index 100% rename from src/assets/Trivex1.png rename to trivex_frontend/src/assets/Trivex1.png diff --git a/src/assets/layers.png b/trivex_frontend/src/assets/layers.png similarity index 100% rename from src/assets/layers.png rename to trivex_frontend/src/assets/layers.png diff --git a/src/assets/layers_removed.png b/trivex_frontend/src/assets/layers_removed.png similarity index 100% rename from src/assets/layers_removed.png rename to trivex_frontend/src/assets/layers_removed.png diff --git a/src/assets/logo.png b/trivex_frontend/src/assets/logo.png similarity index 100% rename from src/assets/logo.png rename to trivex_frontend/src/assets/logo.png diff --git a/src/assets/logo5.png b/trivex_frontend/src/assets/logo5.png similarity index 100% rename from src/assets/logo5.png rename to trivex_frontend/src/assets/logo5.png diff --git a/src/assets/starknet.png b/trivex_frontend/src/assets/starknet.png similarity index 100% rename from src/assets/starknet.png rename to trivex_frontend/src/assets/starknet.png diff --git a/src/assets/tokens.csv b/trivex_frontend/src/assets/tokens.csv similarity index 100% rename from src/assets/tokens.csv rename to trivex_frontend/src/assets/tokens.csv diff --git a/src/components/Alert.jsx b/trivex_frontend/src/components/Alert.jsx similarity index 100% rename from src/components/Alert.jsx rename to trivex_frontend/src/components/Alert.jsx diff --git a/src/components/AppContract.jsx b/trivex_frontend/src/components/AppContract.jsx similarity index 100% rename from src/components/AppContract.jsx rename to trivex_frontend/src/components/AppContract.jsx diff --git a/src/components/AppProvider.jsx b/trivex_frontend/src/components/AppProvider.jsx similarity index 100% rename from src/components/AppProvider.jsx rename to trivex_frontend/src/components/AppProvider.jsx diff --git a/src/components/CloseOrder.jsx b/trivex_frontend/src/components/CloseOrder.jsx similarity index 100% rename from src/components/CloseOrder.jsx rename to trivex_frontend/src/components/CloseOrder.jsx diff --git a/src/components/Footer.jsx b/trivex_frontend/src/components/Footer.jsx similarity index 100% rename from src/components/Footer.jsx rename to trivex_frontend/src/components/Footer.jsx diff --git a/src/components/Loading.jsx b/trivex_frontend/src/components/Loading.jsx similarity index 100% rename from src/components/Loading.jsx rename to trivex_frontend/src/components/Loading.jsx diff --git a/src/components/Navbar.jsx b/trivex_frontend/src/components/Navbar.jsx similarity index 100% rename from src/components/Navbar.jsx rename to trivex_frontend/src/components/Navbar.jsx diff --git a/src/components/OpenOrder.jsx b/trivex_frontend/src/components/OpenOrder.jsx similarity index 100% rename from src/components/OpenOrder.jsx rename to trivex_frontend/src/components/OpenOrder.jsx diff --git a/src/components/Stake.jsx b/trivex_frontend/src/components/Stake.jsx similarity index 100% rename from src/components/Stake.jsx rename to trivex_frontend/src/components/Stake.jsx diff --git a/src/components/TradingViewWidget.js b/trivex_frontend/src/components/TradingViewWidget.js similarity index 100% rename from src/components/TradingViewWidget.js rename to trivex_frontend/src/components/TradingViewWidget.js diff --git a/src/components/Unstake.jsx b/trivex_frontend/src/components/Unstake.jsx similarity index 100% rename from src/components/Unstake.jsx rename to trivex_frontend/src/components/Unstake.jsx diff --git a/src/index.css b/trivex_frontend/src/index.css similarity index 100% rename from src/index.css rename to trivex_frontend/src/index.css diff --git a/src/index.js b/trivex_frontend/src/index.js similarity index 100% rename from src/index.js rename to trivex_frontend/src/index.js diff --git a/src/logo.svg b/trivex_frontend/src/logo.svg similarity index 100% rename from src/logo.svg rename to trivex_frontend/src/logo.svg diff --git a/src/pages/SettingPage.js b/trivex_frontend/src/pages/SettingPage.js similarity index 100% rename from src/pages/SettingPage.js rename to trivex_frontend/src/pages/SettingPage.js diff --git a/src/pages/StakePage.js b/trivex_frontend/src/pages/StakePage.js similarity index 100% rename from src/pages/StakePage.js rename to trivex_frontend/src/pages/StakePage.js diff --git a/src/pages/StrategyPage.js b/trivex_frontend/src/pages/StrategyPage.js similarity index 100% rename from src/pages/StrategyPage.js rename to trivex_frontend/src/pages/StrategyPage.js diff --git a/src/pages/TradePage.js b/trivex_frontend/src/pages/TradePage.js similarity index 100% rename from src/pages/TradePage.js rename to trivex_frontend/src/pages/TradePage.js diff --git a/src/reportWebVitals.js b/trivex_frontend/src/reportWebVitals.js similarity index 100% rename from src/reportWebVitals.js rename to trivex_frontend/src/reportWebVitals.js diff --git a/src/setupTests.js b/trivex_frontend/src/setupTests.js similarity index 100% rename from src/setupTests.js rename to trivex_frontend/src/setupTests.js