wayfinder-paths 0.1.29__py3-none-any.whl → 0.1.30__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of wayfinder-paths might be problematic. Click here for more details.
- wayfinder_paths/adapters/boros_adapter/adapter.py +313 -12
- wayfinder_paths/adapters/boros_adapter/test_adapter.py +125 -14
- wayfinder_paths/adapters/hyperliquid_adapter/adapter.py +2 -2
- wayfinder_paths/adapters/hyperliquid_adapter/exchange.py +2 -2
- wayfinder_paths/adapters/hyperliquid_adapter/local_signer.py +2 -33
- wayfinder_paths/core/constants/hype_oft_abi.py +151 -0
- wayfinder_paths/core/strategies/Strategy.py +1 -2
- wayfinder_paths/mcp/tools/quotes.py +4 -125
- wayfinder_paths/strategies/basis_trading_strategy/strategy.py +1 -2
- wayfinder_paths/strategies/boros_hype_strategy/boros_ops_mixin.py +57 -201
- wayfinder_paths/strategies/boros_hype_strategy/constants.py +1 -152
- wayfinder_paths/strategies/hyperlend_stable_yield_strategy/strategy.py +2 -0
- wayfinder_paths/strategies/moonwell_wsteth_loop_strategy/strategy.py +2 -0
- wayfinder_paths/strategies/stablecoin_yield_strategy/strategy.py +2 -0
- {wayfinder_paths-0.1.29.dist-info → wayfinder_paths-0.1.30.dist-info}/METADATA +1 -1
- {wayfinder_paths-0.1.29.dist-info → wayfinder_paths-0.1.30.dist-info}/RECORD +18 -18
- wayfinder_paths/core/types.py +0 -19
- {wayfinder_paths-0.1.29.dist-info → wayfinder_paths-0.1.30.dist-info}/LICENSE +0 -0
- {wayfinder_paths-0.1.29.dist-info → wayfinder_paths-0.1.30.dist-info}/WHEEL +0 -0
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
"""LayerZero OFT ABI subset used for bridging native HYPE from HyperEVM."""
|
|
2
|
+
|
|
3
|
+
HYPE_OFT_ABI = [
|
|
4
|
+
{
|
|
5
|
+
"inputs": [
|
|
6
|
+
{
|
|
7
|
+
"components": [
|
|
8
|
+
{"internalType": "uint32", "name": "dstEid", "type": "uint32"},
|
|
9
|
+
{"internalType": "bytes32", "name": "to", "type": "bytes32"},
|
|
10
|
+
{"internalType": "uint256", "name": "amountLD", "type": "uint256"},
|
|
11
|
+
{
|
|
12
|
+
"internalType": "uint256",
|
|
13
|
+
"name": "minAmountLD",
|
|
14
|
+
"type": "uint256",
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"internalType": "bytes",
|
|
18
|
+
"name": "extraOptions",
|
|
19
|
+
"type": "bytes",
|
|
20
|
+
},
|
|
21
|
+
{"internalType": "bytes", "name": "composeMsg", "type": "bytes"},
|
|
22
|
+
{"internalType": "bytes", "name": "oftCmd", "type": "bytes"},
|
|
23
|
+
],
|
|
24
|
+
"internalType": "struct SendParam",
|
|
25
|
+
"name": "_sendParam",
|
|
26
|
+
"type": "tuple",
|
|
27
|
+
},
|
|
28
|
+
{"internalType": "bool", "name": "_payInLzToken", "type": "bool"},
|
|
29
|
+
],
|
|
30
|
+
"name": "quoteSend",
|
|
31
|
+
"outputs": [
|
|
32
|
+
{
|
|
33
|
+
"components": [
|
|
34
|
+
{"internalType": "uint256", "name": "nativeFee", "type": "uint256"},
|
|
35
|
+
{
|
|
36
|
+
"internalType": "uint256",
|
|
37
|
+
"name": "lzTokenFee",
|
|
38
|
+
"type": "uint256",
|
|
39
|
+
},
|
|
40
|
+
],
|
|
41
|
+
"internalType": "struct MessagingFee",
|
|
42
|
+
"name": "",
|
|
43
|
+
"type": "tuple",
|
|
44
|
+
}
|
|
45
|
+
],
|
|
46
|
+
"stateMutability": "view",
|
|
47
|
+
"type": "function",
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
"inputs": [
|
|
51
|
+
{
|
|
52
|
+
"components": [
|
|
53
|
+
{"internalType": "uint32", "name": "dstEid", "type": "uint32"},
|
|
54
|
+
{"internalType": "bytes32", "name": "to", "type": "bytes32"},
|
|
55
|
+
{"internalType": "uint256", "name": "amountLD", "type": "uint256"},
|
|
56
|
+
{
|
|
57
|
+
"internalType": "uint256",
|
|
58
|
+
"name": "minAmountLD",
|
|
59
|
+
"type": "uint256",
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
"internalType": "bytes",
|
|
63
|
+
"name": "extraOptions",
|
|
64
|
+
"type": "bytes",
|
|
65
|
+
},
|
|
66
|
+
{"internalType": "bytes", "name": "composeMsg", "type": "bytes"},
|
|
67
|
+
{"internalType": "bytes", "name": "oftCmd", "type": "bytes"},
|
|
68
|
+
],
|
|
69
|
+
"internalType": "struct SendParam",
|
|
70
|
+
"name": "_sendParam",
|
|
71
|
+
"type": "tuple",
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
"components": [
|
|
75
|
+
{"internalType": "uint256", "name": "nativeFee", "type": "uint256"},
|
|
76
|
+
{
|
|
77
|
+
"internalType": "uint256",
|
|
78
|
+
"name": "lzTokenFee",
|
|
79
|
+
"type": "uint256",
|
|
80
|
+
},
|
|
81
|
+
],
|
|
82
|
+
"internalType": "struct MessagingFee",
|
|
83
|
+
"name": "_fee",
|
|
84
|
+
"type": "tuple",
|
|
85
|
+
},
|
|
86
|
+
{"internalType": "address", "name": "_refundAddress", "type": "address"},
|
|
87
|
+
],
|
|
88
|
+
"name": "send",
|
|
89
|
+
"outputs": [
|
|
90
|
+
{
|
|
91
|
+
"components": [
|
|
92
|
+
{"internalType": "bytes32", "name": "guid", "type": "bytes32"},
|
|
93
|
+
{"internalType": "uint64", "name": "nonce", "type": "uint64"},
|
|
94
|
+
{
|
|
95
|
+
"components": [
|
|
96
|
+
{
|
|
97
|
+
"internalType": "uint256",
|
|
98
|
+
"name": "nativeFee",
|
|
99
|
+
"type": "uint256",
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
"internalType": "uint256",
|
|
103
|
+
"name": "lzTokenFee",
|
|
104
|
+
"type": "uint256",
|
|
105
|
+
},
|
|
106
|
+
],
|
|
107
|
+
"internalType": "struct MessagingFee",
|
|
108
|
+
"name": "fee",
|
|
109
|
+
"type": "tuple",
|
|
110
|
+
},
|
|
111
|
+
],
|
|
112
|
+
"internalType": "struct MessagingReceipt",
|
|
113
|
+
"name": "",
|
|
114
|
+
"type": "tuple",
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
"components": [
|
|
118
|
+
{
|
|
119
|
+
"internalType": "uint256",
|
|
120
|
+
"name": "amountSentLD",
|
|
121
|
+
"type": "uint256",
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
"internalType": "uint256",
|
|
125
|
+
"name": "amountReceivedLD",
|
|
126
|
+
"type": "uint256",
|
|
127
|
+
},
|
|
128
|
+
],
|
|
129
|
+
"internalType": "struct OFTReceipt",
|
|
130
|
+
"name": "",
|
|
131
|
+
"type": "tuple",
|
|
132
|
+
},
|
|
133
|
+
],
|
|
134
|
+
"stateMutability": "payable",
|
|
135
|
+
"type": "function",
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
"inputs": [],
|
|
139
|
+
"name": "sharedDecimals",
|
|
140
|
+
"outputs": [{"internalType": "uint8", "name": "", "type": "uint8"}],
|
|
141
|
+
"stateMutability": "view",
|
|
142
|
+
"type": "function",
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
"inputs": [],
|
|
146
|
+
"name": "decimalConversionRate",
|
|
147
|
+
"outputs": [{"internalType": "uint256", "name": "", "type": "uint256"}],
|
|
148
|
+
"stateMutability": "view",
|
|
149
|
+
"type": "function",
|
|
150
|
+
},
|
|
151
|
+
]
|
|
@@ -8,7 +8,6 @@ from loguru import logger
|
|
|
8
8
|
|
|
9
9
|
from wayfinder_paths.core.clients.TokenClient import TokenDetails
|
|
10
10
|
from wayfinder_paths.core.strategies.descriptors import StratDescriptor
|
|
11
|
-
from wayfinder_paths.core.types import HyperliquidSignCallback
|
|
12
11
|
|
|
13
12
|
|
|
14
13
|
class StatusDict(TypedDict):
|
|
@@ -52,7 +51,7 @@ class Strategy(ABC):
|
|
|
52
51
|
main_wallet_signing_callback: Callable[[dict], Awaitable[str]] | None = None,
|
|
53
52
|
strategy_wallet_signing_callback: Callable[[dict], Awaitable[str]]
|
|
54
53
|
| None = None,
|
|
55
|
-
strategy_sign_typed_data:
|
|
54
|
+
strategy_sign_typed_data: Callable[[dict], Awaitable[str]] | None = None,
|
|
56
55
|
):
|
|
57
56
|
self.ledger_adapter = None
|
|
58
57
|
self.logger = logger.bind(strategy=self.__class__.__name__)
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
-
import re
|
|
4
3
|
from typing import Any
|
|
5
4
|
|
|
6
5
|
from wayfinder_paths.core.clients.BRAPClient import BRAPClient
|
|
7
6
|
from wayfinder_paths.core.clients.TokenClient import TokenClient
|
|
8
|
-
from wayfinder_paths.
|
|
7
|
+
from wayfinder_paths.mcp.tools.execute import (
|
|
8
|
+
_resolve_token_meta,
|
|
9
|
+
_select_token_chain,
|
|
10
|
+
)
|
|
9
11
|
from wayfinder_paths.mcp.utils import (
|
|
10
12
|
err,
|
|
11
13
|
find_wallet_by_label,
|
|
@@ -15,129 +17,6 @@ from wayfinder_paths.mcp.utils import (
|
|
|
15
17
|
)
|
|
16
18
|
|
|
17
19
|
|
|
18
|
-
def _chain_id(token: dict[str, Any]) -> int | None:
|
|
19
|
-
# Token payloads often include a database/internal `id` field; do not treat that as a chain id.
|
|
20
|
-
if token.get("chain_id") is not None:
|
|
21
|
-
try:
|
|
22
|
-
return int(token.get("chain_id"))
|
|
23
|
-
except (TypeError, ValueError):
|
|
24
|
-
return None
|
|
25
|
-
|
|
26
|
-
chain = token.get("chain") or {}
|
|
27
|
-
if not isinstance(chain, dict):
|
|
28
|
-
return None
|
|
29
|
-
|
|
30
|
-
for key in ("chain_id", "chainId", "id"):
|
|
31
|
-
if chain.get(key) is None:
|
|
32
|
-
continue
|
|
33
|
-
try:
|
|
34
|
-
return int(chain.get(key))
|
|
35
|
-
except (TypeError, ValueError):
|
|
36
|
-
return None
|
|
37
|
-
|
|
38
|
-
return None
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
_SIMPLE_CHAIN_SUFFIX_RE = re.compile(r"^[a-z0-9]+\s+[a-z0-9-]+$", re.IGNORECASE)
|
|
42
|
-
_ASSET_CHAIN_SPLIT_RE = re.compile(
|
|
43
|
-
r"^(?P<asset>[a-z0-9]+)[- _](?P<chain>[a-z0-9-]+)$", re.IGNORECASE
|
|
44
|
-
)
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
def _normalize_token_query(query: str) -> str:
|
|
48
|
-
q = " ".join(str(query).strip().split())
|
|
49
|
-
if not q or "-" in q or "_" in q:
|
|
50
|
-
return q
|
|
51
|
-
if not _SIMPLE_CHAIN_SUFFIX_RE.match(q):
|
|
52
|
-
return q
|
|
53
|
-
asset, chain_code = q.rsplit(" ", 1)
|
|
54
|
-
if chain_code.lower() in CHAIN_CODE_TO_ID:
|
|
55
|
-
return f"{asset}-{chain_code}"
|
|
56
|
-
return q
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
def _is_eth_like_token(meta: dict[str, Any]) -> bool:
|
|
60
|
-
asset_id = str(meta.get("asset_id") or "").lower()
|
|
61
|
-
symbol = str(meta.get("symbol") or "").lower()
|
|
62
|
-
return asset_id == "ethereum" or symbol == "eth"
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
def _split_asset_chain(query: str) -> tuple[str, str] | None:
|
|
66
|
-
q = str(query).strip()
|
|
67
|
-
if not q:
|
|
68
|
-
return None
|
|
69
|
-
m = _ASSET_CHAIN_SPLIT_RE.match(q)
|
|
70
|
-
if not m:
|
|
71
|
-
return None
|
|
72
|
-
return m.group("asset").lower(), m.group("chain").lower()
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
async def _resolve_token_meta(
|
|
76
|
-
token_client: TokenClient,
|
|
77
|
-
*,
|
|
78
|
-
query: str,
|
|
79
|
-
) -> tuple[str, dict[str, Any]]:
|
|
80
|
-
q = _normalize_token_query(query)
|
|
81
|
-
split = _split_asset_chain(q)
|
|
82
|
-
if split:
|
|
83
|
-
asset, chain_code = split
|
|
84
|
-
if asset in {"eth", "ethereum"}:
|
|
85
|
-
try:
|
|
86
|
-
gas_meta = await token_client.get_gas_token(chain_code)
|
|
87
|
-
if isinstance(gas_meta, dict) and _is_eth_like_token(gas_meta):
|
|
88
|
-
return q, gas_meta
|
|
89
|
-
except Exception:
|
|
90
|
-
pass
|
|
91
|
-
meta = await token_client.get_token_details(q)
|
|
92
|
-
return q, meta
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
def _infer_chain_code_from_query(query: str, meta: dict[str, Any]) -> str | None:
|
|
96
|
-
q = str(query).strip().lower()
|
|
97
|
-
if not q:
|
|
98
|
-
return None
|
|
99
|
-
|
|
100
|
-
candidates: set[str] = {str(k).lower() for k in CHAIN_CODE_TO_ID.keys()}
|
|
101
|
-
addrs = meta.get("addresses") or {}
|
|
102
|
-
if isinstance(addrs, dict):
|
|
103
|
-
candidates.update(str(k).lower() for k in addrs.keys())
|
|
104
|
-
|
|
105
|
-
best: str | None = None
|
|
106
|
-
for code in candidates:
|
|
107
|
-
if q.endswith(f"-{code}"):
|
|
108
|
-
if best is None or len(code) > len(best):
|
|
109
|
-
best = code
|
|
110
|
-
return best
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
def _address_for_chain(meta: dict[str, Any], chain_code: str) -> str | None:
|
|
114
|
-
addrs = meta.get("addresses") or {}
|
|
115
|
-
if not isinstance(addrs, dict):
|
|
116
|
-
return None
|
|
117
|
-
for key, val in addrs.items():
|
|
118
|
-
if str(key).lower() == chain_code and val:
|
|
119
|
-
return str(val)
|
|
120
|
-
return None
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
def _select_token_chain(
|
|
124
|
-
meta: dict[str, Any], *, query: str
|
|
125
|
-
) -> tuple[int | None, str | None]:
|
|
126
|
-
chain_id = _chain_id(meta)
|
|
127
|
-
token_address = meta.get("address")
|
|
128
|
-
|
|
129
|
-
desired_chain = _infer_chain_code_from_query(query, meta)
|
|
130
|
-
if desired_chain:
|
|
131
|
-
addr = _address_for_chain(meta, desired_chain)
|
|
132
|
-
if addr:
|
|
133
|
-
token_address = addr
|
|
134
|
-
if desired_chain in CHAIN_CODE_TO_ID:
|
|
135
|
-
chain_id = CHAIN_CODE_TO_ID[desired_chain]
|
|
136
|
-
|
|
137
|
-
token_address_out = str(token_address).strip() if token_address else None
|
|
138
|
-
return chain_id, token_address_out
|
|
139
|
-
|
|
140
|
-
|
|
141
20
|
def _slippage_float(slippage_bps: int) -> float:
|
|
142
21
|
return max(0.0, float(int(slippage_bps)) / 10_000.0)
|
|
143
22
|
|
|
@@ -58,7 +58,6 @@ from wayfinder_paths.core.strategies.descriptors import (
|
|
|
58
58
|
Volatility,
|
|
59
59
|
)
|
|
60
60
|
from wayfinder_paths.core.strategies.Strategy import StatusDict, StatusTuple, Strategy
|
|
61
|
-
from wayfinder_paths.core.types import HyperliquidSignCallback
|
|
62
61
|
from wayfinder_paths.policies.erc20 import any_erc20_function
|
|
63
62
|
from wayfinder_paths.policies.hyperliquid import (
|
|
64
63
|
any_hyperliquid_l1_payload,
|
|
@@ -182,7 +181,7 @@ class BasisTradingStrategy(BasisSnapshotMixin, Strategy):
|
|
|
182
181
|
*,
|
|
183
182
|
main_wallet: dict[str, Any] | None = None,
|
|
184
183
|
strategy_wallet: dict[str, Any] | None = None,
|
|
185
|
-
strategy_sign_typed_data:
|
|
184
|
+
strategy_sign_typed_data: Callable[[dict], Awaitable[str]] | None = None,
|
|
186
185
|
main_wallet_signing_callback: Callable[[dict], Awaitable[str]] | None = None,
|
|
187
186
|
strategy_wallet_signing_callback: Callable[[dict], Awaitable[str]]
|
|
188
187
|
| None = None,
|
|
@@ -11,22 +11,18 @@ from datetime import datetime
|
|
|
11
11
|
from typing import Any
|
|
12
12
|
|
|
13
13
|
from loguru import logger
|
|
14
|
-
from web3 import AsyncWeb3
|
|
15
14
|
|
|
16
15
|
from wayfinder_paths.core.utils.transaction import encode_call, send_transaction
|
|
17
|
-
from wayfinder_paths.core.utils.web3 import web3_from_chain_id
|
|
18
16
|
|
|
19
17
|
from .constants import (
|
|
20
18
|
BOROS_HYPE_MARKET_ID,
|
|
21
19
|
BOROS_HYPE_TOKEN_ID,
|
|
22
20
|
BOROS_MIN_DEPOSIT_HYPE,
|
|
23
21
|
HYPE_NATIVE,
|
|
24
|
-
HYPE_OFT_ABI,
|
|
25
22
|
HYPE_OFT_ADDRESS,
|
|
26
23
|
HYPEREVM_CHAIN_ID,
|
|
27
24
|
KHYPE_LST,
|
|
28
25
|
LOOPED_HYPE,
|
|
29
|
-
LZ_EID_ARBITRUM,
|
|
30
26
|
MIN_HYPE_GAS,
|
|
31
27
|
USDC_ARB,
|
|
32
28
|
USDT_ARB,
|
|
@@ -37,11 +33,6 @@ from .constants import (
|
|
|
37
33
|
from .types import Inventory
|
|
38
34
|
|
|
39
35
|
|
|
40
|
-
def _pad_address_bytes32(address: str) -> bytes:
|
|
41
|
-
checksum = AsyncWeb3.to_checksum_address(address)
|
|
42
|
-
return bytes.fromhex(checksum[2:]).rjust(32, b"\x00")
|
|
43
|
-
|
|
44
|
-
|
|
45
36
|
class BorosHypeBorosOpsMixin:
|
|
46
37
|
async def _fund_boros(
|
|
47
38
|
self, params: dict[str, Any], inventory: Inventory
|
|
@@ -267,84 +258,21 @@ class BorosHypeBorosOpsMixin:
|
|
|
267
258
|
bridge_amount_wei = min(target_wei, max_value_wei)
|
|
268
259
|
if bridge_amount_wei <= 0:
|
|
269
260
|
return True, "Boros funding: nothing to bridge"
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
)
|
|
278
|
-
|
|
279
|
-
conversion_rate = int(
|
|
280
|
-
await contract.functions.decimalConversionRate().call()
|
|
281
|
-
) # OFT sharedDecimals rounding
|
|
282
|
-
if conversion_rate > 0:
|
|
283
|
-
bridge_amount_wei = (
|
|
284
|
-
bridge_amount_wei // conversion_rate
|
|
285
|
-
) * conversion_rate
|
|
286
|
-
if bridge_amount_wei <= 0:
|
|
287
|
-
return True, "Boros funding: amount too small after OFT rounding"
|
|
288
|
-
|
|
289
|
-
# Quote fee, then clamp amount to fit balance (amount + fee) while
|
|
290
|
-
# still leaving MIN_HYPE_GAS behind for future gas.
|
|
291
|
-
send_params = (
|
|
292
|
-
int(LZ_EID_ARBITRUM),
|
|
293
|
-
to_bytes32,
|
|
294
|
-
int(bridge_amount_wei),
|
|
295
|
-
0,
|
|
296
|
-
b"",
|
|
297
|
-
b"",
|
|
298
|
-
b"",
|
|
299
|
-
)
|
|
300
|
-
fee = await contract.functions.quoteSend(send_params, False).call()
|
|
301
|
-
native_fee = int(fee[0])
|
|
302
|
-
lz_token_fee = int(fee[1])
|
|
303
|
-
|
|
304
|
-
max_send_amount_wei = max(0, max_value_wei - native_fee)
|
|
305
|
-
if conversion_rate > 0:
|
|
306
|
-
max_send_amount_wei = (
|
|
307
|
-
max_send_amount_wei // conversion_rate
|
|
308
|
-
) * conversion_rate
|
|
309
|
-
if bridge_amount_wei > max_send_amount_wei:
|
|
310
|
-
bridge_amount_wei = max_send_amount_wei
|
|
311
|
-
if bridge_amount_wei <= 0:
|
|
312
|
-
return False, "Insufficient HyperEVM HYPE to cover OFT bridge fee"
|
|
313
|
-
|
|
314
|
-
send_params = (
|
|
315
|
-
int(LZ_EID_ARBITRUM),
|
|
316
|
-
to_bytes32,
|
|
317
|
-
int(bridge_amount_wei),
|
|
318
|
-
0,
|
|
319
|
-
b"",
|
|
320
|
-
b"",
|
|
321
|
-
b"",
|
|
322
|
-
)
|
|
323
|
-
fee = await contract.functions.quoteSend(send_params, False).call()
|
|
324
|
-
native_fee = int(fee[0])
|
|
325
|
-
lz_token_fee = int(fee[1])
|
|
326
|
-
|
|
327
|
-
total_value_wei = int(bridge_amount_wei) + int(native_fee)
|
|
328
|
-
if total_value_wei > max_value_wei:
|
|
329
|
-
return False, "Insufficient HyperEVM HYPE to bridge after fee quote"
|
|
330
|
-
|
|
331
|
-
tx = await encode_call(
|
|
332
|
-
target=HYPE_OFT_ADDRESS,
|
|
333
|
-
abi=HYPE_OFT_ABI,
|
|
334
|
-
fn_name="send",
|
|
335
|
-
args=[
|
|
336
|
-
send_params,
|
|
337
|
-
(int(native_fee), int(lz_token_fee)),
|
|
338
|
-
AsyncWeb3.to_checksum_address(wallet_address),
|
|
339
|
-
],
|
|
340
|
-
from_address=wallet_address,
|
|
341
|
-
chain_id=HYPEREVM_CHAIN_ID,
|
|
342
|
-
value=total_value_wei,
|
|
261
|
+
(
|
|
262
|
+
ok_bridge,
|
|
263
|
+
bridge_res,
|
|
264
|
+
) = await self.boros_adapter.bridge_hype_oft_hyperevm_to_arbitrum(
|
|
265
|
+
amount_wei=int(bridge_amount_wei),
|
|
266
|
+
max_value_wei=int(max_value_wei),
|
|
267
|
+
to_address=str(wallet_address),
|
|
268
|
+
from_address=str(wallet_address),
|
|
343
269
|
)
|
|
270
|
+
if not ok_bridge:
|
|
271
|
+
return False, f"OFT bridge failed: {bridge_res}"
|
|
344
272
|
|
|
345
|
-
tx_hash =
|
|
346
|
-
|
|
347
|
-
bridged_hype = float(
|
|
273
|
+
tx_hash = str(bridge_res.get("tx_hash") or "")
|
|
274
|
+
bridged_wei = int(bridge_res.get("amount_wei") or 0)
|
|
275
|
+
bridged_hype = float(bridged_wei) / 1e18
|
|
348
276
|
bridged_usd = bridged_hype * hype_price
|
|
349
277
|
|
|
350
278
|
# Track in-flight amount so planner doesn't double-fund while the bridge settles.
|
|
@@ -360,7 +288,7 @@ class BorosHypeBorosOpsMixin:
|
|
|
360
288
|
|
|
361
289
|
return True, (
|
|
362
290
|
f"Bridging {bridged_hype:.6f} HYPE (≈${bridged_usd:.2f}) HyperEVM→Arbitrum via OFT; "
|
|
363
|
-
f"tx={tx_hash} (LayerZero:
|
|
291
|
+
f"tx={tx_hash} (LayerZero: {bridge_res.get('layerzeroscan')}). "
|
|
364
292
|
"Once bridged HYPE lands on Arbitrum, the next tick will deposit it to Boros."
|
|
365
293
|
)
|
|
366
294
|
|
|
@@ -431,41 +359,15 @@ class BorosHypeBorosOpsMixin:
|
|
|
431
359
|
f"({depositable_hype:.6f} HYPE)",
|
|
432
360
|
)
|
|
433
361
|
|
|
434
|
-
# 0)
|
|
435
|
-
# Boros markets expire, so we need to get the actual market ID from isolated positions.
|
|
362
|
+
# 0) Cleanup: sweep any isolated collateral back to cross margin.
|
|
436
363
|
try:
|
|
437
|
-
|
|
364
|
+
ok_sweep, sweep_res = await self.boros_adapter.sweep_isolated_to_cross(
|
|
438
365
|
token_id=int(token_id)
|
|
439
366
|
)
|
|
440
|
-
if
|
|
441
|
-
|
|
442
|
-
logger.debug(
|
|
443
|
-
f"Boros position check: isolated={balances.get('isolated', 0):.6f}, "
|
|
444
|
-
f"cross={balances.get('cross', 0):.6f}, "
|
|
445
|
-
f"total={balances.get('total', 0):.6f}, "
|
|
446
|
-
f"isolated_positions={isolated_positions}"
|
|
447
|
-
)
|
|
448
|
-
for iso_pos in isolated_positions:
|
|
449
|
-
iso_market_id = iso_pos.get("market_id")
|
|
450
|
-
iso_balance = float(iso_pos.get("balance", 0) or 0.0)
|
|
451
|
-
if iso_market_id and iso_balance > 0.001:
|
|
452
|
-
iso_wei = int(iso_balance * 1e18) # Boros cash units
|
|
453
|
-
logger.info(
|
|
454
|
-
f"Moving {iso_balance:.6f} collateral from isolated market {iso_market_id} to cross"
|
|
455
|
-
)
|
|
456
|
-
ok_xfer, res_xfer = await self.boros_adapter.cash_transfer(
|
|
457
|
-
market_id=int(iso_market_id),
|
|
458
|
-
amount_wei=iso_wei,
|
|
459
|
-
is_deposit=False, # isolated -> cross
|
|
460
|
-
)
|
|
461
|
-
if ok_xfer:
|
|
462
|
-
await asyncio.sleep(2)
|
|
463
|
-
else:
|
|
464
|
-
logger.warning(
|
|
465
|
-
f"Failed Boros isolated->cross transfer for market {iso_market_id}: {res_xfer}"
|
|
466
|
-
)
|
|
367
|
+
if not ok_sweep:
|
|
368
|
+
logger.warning(f"Failed Boros isolated->cross sweep: {sweep_res}")
|
|
467
369
|
except Exception as exc: # noqa: BLE001
|
|
468
|
-
logger.warning(f"Failed Boros isolated->cross
|
|
370
|
+
logger.warning(f"Failed Boros isolated->cross sweep: {exc}")
|
|
469
371
|
|
|
470
372
|
# 1) Best-effort: if any OFT HYPE is sitting idle on Arbitrum, deposit it to cross margin.
|
|
471
373
|
if inventory.hype_oft_arb_balance > 0.0:
|
|
@@ -491,104 +393,58 @@ class BorosHypeBorosOpsMixin:
|
|
|
491
393
|
except Exception as exc: # noqa: BLE001
|
|
492
394
|
logger.warning(f"Failed to deposit OFT HYPE to Boros: {exc}")
|
|
493
395
|
|
|
494
|
-
# Deposits can land as isolated cash for the given market_id; ensure we
|
|
495
|
-
# sweep isolated -> cross again before attempting to trade.
|
|
496
|
-
try:
|
|
497
|
-
ok_bal, balances = await self.boros_adapter.get_account_balances(
|
|
498
|
-
token_id=int(token_id)
|
|
499
|
-
)
|
|
500
|
-
if ok_bal and isinstance(balances, dict):
|
|
501
|
-
isolated_positions = balances.get("isolated_positions", [])
|
|
502
|
-
for iso_pos in isolated_positions:
|
|
503
|
-
iso_market_id = iso_pos.get("market_id")
|
|
504
|
-
iso_balance = float(iso_pos.get("balance", 0) or 0.0)
|
|
505
|
-
if iso_market_id and iso_balance > 0.001:
|
|
506
|
-
iso_wei = int(iso_balance * 1e18) # Boros cash units
|
|
507
|
-
logger.info(
|
|
508
|
-
f"Moving {iso_balance:.6f} collateral from isolated market {iso_market_id} to cross"
|
|
509
|
-
)
|
|
510
|
-
ok_xfer, res_xfer = await self.boros_adapter.cash_transfer(
|
|
511
|
-
market_id=int(iso_market_id),
|
|
512
|
-
amount_wei=iso_wei,
|
|
513
|
-
is_deposit=False, # isolated -> cross
|
|
514
|
-
)
|
|
515
|
-
if ok_xfer:
|
|
516
|
-
await asyncio.sleep(2)
|
|
517
|
-
else:
|
|
518
|
-
logger.warning(
|
|
519
|
-
f"Failed Boros isolated->cross transfer for market {iso_market_id}: {res_xfer}"
|
|
520
|
-
)
|
|
521
|
-
except Exception as exc: # noqa: BLE001
|
|
522
|
-
logger.warning(
|
|
523
|
-
f"Failed Boros isolated->cross transfer after deposit: {exc}"
|
|
524
|
-
)
|
|
525
|
-
|
|
526
396
|
# 2) Rollover: close positions in other markets (best effort).
|
|
527
397
|
try:
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
await self.boros_adapter.close_positions_market(
|
|
537
|
-
mid_int, token_id=int(token_id)
|
|
538
|
-
)
|
|
539
|
-
await asyncio.sleep(2)
|
|
540
|
-
except Exception as exc: # noqa: BLE001
|
|
541
|
-
logger.warning(f"Failed to close Boros market {mid_int}: {exc}")
|
|
398
|
+
ok_roll, roll_res = await self.boros_adapter.close_positions_except(
|
|
399
|
+
keep_market_id=int(market_id),
|
|
400
|
+
token_id=int(token_id),
|
|
401
|
+
market_ids=inventory.boros_position_market_ids or [],
|
|
402
|
+
best_effort=True,
|
|
403
|
+
)
|
|
404
|
+
if not ok_roll:
|
|
405
|
+
logger.warning(f"Failed Boros rollover close: {roll_res}")
|
|
542
406
|
except Exception as exc: # noqa: BLE001
|
|
543
407
|
logger.warning(f"Failed Boros rollover close: {exc}")
|
|
544
408
|
|
|
545
|
-
|
|
546
|
-
|
|
409
|
+
yu_to_usd = (
|
|
410
|
+
float(inventory.hype_price_usd or 0.0)
|
|
411
|
+
if int(token_id) == BOROS_HYPE_TOKEN_ID
|
|
412
|
+
else 1.0
|
|
547
413
|
)
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
market_id=int(market_id),
|
|
568
|
-
token_id=int(token_id),
|
|
569
|
-
size_yu_wei=size_yu_wei,
|
|
570
|
-
side="short",
|
|
571
|
-
tif="IOC",
|
|
414
|
+
ok_set, set_res = await self.boros_adapter.ensure_position_size_yu(
|
|
415
|
+
market_id=int(market_id),
|
|
416
|
+
token_id=int(token_id),
|
|
417
|
+
target_size_yu=float(target_size_yu),
|
|
418
|
+
tif="IOC",
|
|
419
|
+
min_resize_excess_usd=float(
|
|
420
|
+
self._planner_config.boros_resize_min_excess_usd
|
|
421
|
+
),
|
|
422
|
+
yu_to_usd=float(yu_to_usd),
|
|
423
|
+
)
|
|
424
|
+
if not ok_set:
|
|
425
|
+
return False, f"Failed to ensure Boros position: {set_res}"
|
|
426
|
+
|
|
427
|
+
action = str(set_res.get("action") or "unknown")
|
|
428
|
+
diff_yu = float(set_res.get("diff_yu") or 0.0)
|
|
429
|
+
if action == "no_op":
|
|
430
|
+
return (
|
|
431
|
+
True,
|
|
432
|
+
f"Boros position already at target ({set_res.get('current_size_yu', 0.0):.4f} YU)",
|
|
572
433
|
)
|
|
573
|
-
|
|
574
|
-
return False, f"Failed to open Boros position: {open_res}"
|
|
434
|
+
if action == "increase_short":
|
|
575
435
|
return (
|
|
576
436
|
True,
|
|
577
437
|
f"Boros position increased by {diff_yu:.4f} YU on market {market_id}",
|
|
578
438
|
)
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
size_yu_wei=size_yu_wei,
|
|
585
|
-
)
|
|
586
|
-
if not ok_close:
|
|
587
|
-
return False, f"Failed to close Boros position: {close_res}"
|
|
439
|
+
if action == "decrease":
|
|
440
|
+
return (
|
|
441
|
+
True,
|
|
442
|
+
f"Boros position decreased by {abs(diff_yu):.4f} YU on market {market_id}",
|
|
443
|
+
)
|
|
588
444
|
|
|
589
445
|
return (
|
|
590
446
|
True,
|
|
591
|
-
f"Boros position
|
|
447
|
+
f"Boros position adjusted ({action}) on market {market_id}: Δ={diff_yu:.4f} YU",
|
|
592
448
|
)
|
|
593
449
|
|
|
594
450
|
async def _complete_pending_withdrawal(
|