Skip to content
This repository was archived by the owner on Jul 23, 2024. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions proxy-cli/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ def _neon_address_info(self, _) -> None:
balance = self._get_neon_balance(neon_acct)
total_balance += balance

print(f'{ address }\t { str(sol_acct.pubkey()) }\t { balance:,.18f} NEON')
print(f'{ address }\t { str(sol_acct.pubkey()) }\t { balance:,.18f} {self._config.default_token_name}')

print(f'total_balance\t { total_balance:,.18f} NEON')
print(f'total_balance\t { total_balance:,.18f} {self._config.default_token_name}')

def _solana_accounts_info(self, _) -> None:
total_balance = Decimal(0)
Expand Down
16 changes: 9 additions & 7 deletions proxy-cli/neon.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@
from eth_typing import Address
from eth_account import Account

from proxy.common_neon.config import Config
from proxy.common_neon.address import NeonAddress

from .secret import get_solana_acct_list


class NeonHandler:
def __init__(self):
def __init__(self, config: Option[Config]=Config()):
self._config = config
self.command = 'neon-account'

@staticmethod
Expand All @@ -34,7 +36,7 @@ def init_args_parser(parsers) -> NeonHandler:
n.withdraw_parser.add_argument('amount', type=int, help='withdrawing amount')
n.withdraw_parser.add_argument(
'type', type=str, default='PERCENT', nargs='?',
help='type of amount <PERCENT|NEON>'
help=f"type of amount <PERCENT|{n._config.default_token_name}>"
)
return n

Expand Down Expand Up @@ -85,7 +87,7 @@ def _send_tx(self, from_addr: NeonAddress, to_addr: Address, amount: int, gas: i
tx_hash = self._proxy.send_raw_transaction(tx_signed.rawTransaction)
amount = self._get_neon_amount(amount)

print(f'send {amount:,.18} NEON from {str(from_addr)} to 0x{to_addr.hex()}: {tx_hash.hex()}')
print(f'send {amount:,.18} {self._config.default_token_name} from {str(from_addr)} to 0x{to_addr.hex()}: {tx_hash.hex()}')

def _estimate_tx(self, from_addr: NeonAddress, to_addr: Address) -> int:
tx = self._create_tx(from_addr, to_addr, 1)
Expand Down Expand Up @@ -113,8 +115,8 @@ def _withdraw_neon(self, args) -> None:

amount = args.amount
a_type = args.type.upper()
if a_type not in {'PERCENT', 'NEON'}:
print(f'wrong type of amount type {a_type}, should be PERCENT or NEON', file=sys.stderr)
if a_type not in {'PERCENT', self._config.default_token_name}:
print(f'wrong type of amount type {a_type}, should be PERCENT or {self._config.default_token_name}', file=sys.stderr)
return
elif amount <= 0:
print(f'amount {amount} should be more than 0', file=sys.stderr)
Expand All @@ -131,7 +133,7 @@ def _withdraw_neon(self, args) -> None:
for balance in neon_acct_dict.values():
total_balance += balance

if a_type == 'NEON':
if a_type == self._config.default_token_name:
check_balance = math.ceil(total_balance / 1_000_000_000 / 1_000_000_000)
if check_balance < amount:
print(f'amount {amount} is too big, should be less than {check_balance}', file=sys.stderr)
Expand Down Expand Up @@ -162,4 +164,4 @@ def _withdraw_neon(self, args) -> None:
break

total_amount = self._get_neon_amount(total_amount)
print(f'successfully send {total_amount:,.18} NEON to 0x{dest_addr.hex()}')
print(f'successfully send {total_amount:,.18} {self._config.default_token_name} to 0x{dest_addr.hex()}')
6 changes: 6 additions & 0 deletions proxy/common_neon/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ def __init__(self):
self._const_gas_price = self._env_num('CONST_GAS_PRICE', -1, min_gas_price, 100_000_000) * (10 ** 9)

# Operator resource settings
self._default_token_name = os.environ.get("DEFAULT_TOKEN_NAME", "NEON")
self._holder_size = self._env_num('HOLDER_SIZE', 256 * 1024, 1024, 10 * 1024 * 1024)
self._min_op_balance_to_warn = self._env_num('MIN_OPERATOR_BALANCE_TO_WARN', 9_000_000_000, 1)
self._min_op_balance_to_err = self._env_num('MIN_OPERATOR_BALANCE_TO_ERR', 1_000_000_000, 1)
Expand Down Expand Up @@ -320,6 +321,11 @@ def _env_num(

###################
# Base settings

@property
def default_token_name(self) -> str:
return self._default_token_name

@property
def solana_url_list(self) -> List[str]:
return self._solana_url_list
Expand Down
2 changes: 1 addition & 1 deletion proxy/gas_tank/gas_tank.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def _process_write_holder_ix(self, sol_neon_ix: SolNeonIxReceiptInfo) -> None:

holder = self._neon_holder_dict.get(key.value, None)
if holder is None:
LOG.debug(f'new NEON tx {key}: {str(chunk)}')
LOG.debug(f'new {self._config.default_token_name} tx {key}: {str(chunk)}')
holder = NeonIndexedHolderInfo(key)
self._neon_holder_dict[key.value] = holder

Expand Down
7 changes: 6 additions & 1 deletion proxy/indexer/neon_ix_decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from typing import Any, List, Type, Optional, Iterator

from ..common_neon.config import Config
from ..common_neon.utils import NeonTxInfo
from ..common_neon.neon_instruction import EvmIxCode, EvmIxCodeName
from ..common_neon.utils.evm_log_decoder import NeonLogTxEvent
Expand Down Expand Up @@ -582,8 +583,12 @@ class Deposit3IxDecoder(DummyIxDecoder):
_ix_code = EvmIxCode.DepositV03
_is_deprecated = False

def __init__(self, state: SolNeonDecoderCtx, config=Config()):
super().__init__(state)
self._config = config

def execute(self) -> bool:
return self._decoding_success(None, 'deposit NEONs')
return self._decoding_success(None, f"deposit {self._config._default_token_name}s")


def get_neon_ix_decoder_list() -> List[Type[DummyIxDecoder]]:
Expand Down
6 changes: 3 additions & 3 deletions proxy/mempool/gas_price_calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

class GasPriceCalculator:
_sol_price_symbol = 'Crypto.SOL/USD'
_neon_price_symbol = 'Crypto.NEON/USD'

def __init__(self, config: Config, solana: SolInteractor) -> None:
self._config = config
Expand All @@ -26,6 +25,7 @@ def __init__(self, config: Config, solana: SolInteractor) -> None:
self._is_const_gas_price = True
self._min_gas_price: Optional[int] = None
self._suggested_gas_price: Optional[int] = None
self._neon_price_symbol = f"Crypto.{self._config.default_token_name}/USD"

def set_price_account(self, sol_price_account: Optional[SolPubKey], neon_price_account: Optional[SolPubKey]):
if (sol_price_account is None) or (neon_price_account is None):
Expand Down Expand Up @@ -95,9 +95,9 @@ def _get_tokens_prices_from_net(self) -> None:
try:
self._neon_price_usd = self._get_token_price(self._neon_price_symbol)
except PythNetworkError as exc:
LOG.debug(f'Failed to retrieve NEON price: {str(exc)}')
LOG.debug(f'Failed to retrieve {self._config.default_token_name} price: {str(exc)}')
except BaseException as exc:
LOG.error('Failed to retrieve NEON price', exc_info=exc)
LOG.error(f'Failed to retrieve {self._config.default_token_name} price', exc_info=exc)

try:
self._sol_price_usd = self._get_token_price(self._sol_price_symbol)
Expand Down
2 changes: 1 addition & 1 deletion proxy/statistic/proxy_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def _init_metric_list(self) -> None:
registry=self._registry
)
self._metr_op_neon_balance = Gauge(
'operator_neon_balance', 'Operator Balance in NEONs',
'operator_neon_balance', f"Operator Balance in {self._config.default_token_name}s",
registry=self._registry
)
self._metr_key_total = Gauge(
Expand Down
2 changes: 1 addition & 1 deletion proxy/testing/test_gas_tank_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def create_token_account(self, owner: SolPubKey, mint_amount: int):
def create_eth_account(self):
self.acc_num += 1
account = self.proxy.create_account(f'neonlabsorg/proxy-model.py/issues/344/eth_account{self.acc_num}')
print(f"NEON account created: {account.address}")
print(f"{self.config.default_token_name} account created: {account.address}")
return account

def build_tx(self, name: str, ix_list) -> SolLegacyTx:
Expand Down