Skip to content
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
22b10f9
307 implement withdraw instruction (#591)
ivandzen Mar 11, 2022
0ec3c9e
intro
Mar 11, 2022
9fb9fa7
upd creds
Mar 11, 2022
7ef74d6
fix
Mar 11, 2022
60124c2
wip
Mar 11, 2022
ebf8ea0
typo
Mar 11, 2022
432bac7
fix
Mar 11, 2022
dbe118d
wip
Mar 11, 2022
600d6ca
wip
Mar 11, 2022
cb18d20
wip
Mar 11, 2022
e9fd64c
wip
Mar 11, 2022
b37c3cb
wip
Mar 11, 2022
2f443c7
wip
Mar 11, 2022
885a0ad
upd SG
Mar 11, 2022
d35af72
enable tests
Mar 11, 2022
ba6750e
wip
Mar 11, 2022
332c031
wip
Mar 11, 2022
805e4ae
Merge branch '583-introduce-full-test-suite' into 583-introduce-full-…
Mar 12, 2022
9c9447b
wip
Mar 12, 2022
991cc46
wip
Mar 12, 2022
fde5590
wip
Mar 12, 2022
331a33e
#368 move sql schema to distinct file (#586)
vasiliy-zaznobin Mar 12, 2022
5cbce09
#631 extract Airdropper class (#632)
rozhkovdmitrii Mar 12, 2022
76b68aa
debug
Mar 14, 2022
db98d44
merge
Mar 14, 2022
69798e9
merge
Mar 14, 2022
ecb4831
remove unused port
Mar 14, 2022
92d207b
wip
Mar 14, 2022
38edd9a
wip
Mar 14, 2022
c677de9
wip
Mar 14, 2022
9e6af06
wip
Mar 14, 2022
509d49b
wip
Mar 14, 2022
c59129b
wip
Mar 14, 2022
b2144cc
change instance type
Mar 14, 2022
f8a6c03
Fix eth_estimageGas for Metamask transfer (#634)
anton-lisanin Mar 14, 2022
f959e82
wip
Mar 14, 2022
c11abaa
fix path
Mar 14, 2022
9b0b676
wip
Mar 14, 2022
5dd2ec9
wip
Mar 14, 2022
3dba0fd
wip
Mar 14, 2022
6a68eae
artifacts
Mar 15, 2022
6bd5b62
enable required step
Mar 15, 2022
8809fde
wip
Mar 15, 2022
cc853d1
wip
Mar 15, 2022
0045faa
proxy artefacts
Mar 15, 2022
82847a3
redirect stderr
Mar 15, 2022
77429f5
enable test step
Mar 15, 2022
3938e6a
typo
Mar 15, 2022
ea7b59f
typo
Mar 15, 2022
e8c9696
faucet
Mar 15, 2022
3d30b36
wip
Mar 15, 2022
a76732a
debug
Mar 15, 2022
d61c342
Add implementation of neon_getSolanaTransactionByNeonTransaction. #639
afalaleev Mar 15, 2022
0488307
wip
Mar 15, 2022
5f4f39e
Add SOLANA_COMMITMENT
Mar 15, 2022
9b45c08
Merge pull request #643 from neonlabsorg/639-neon-api
afalaleev Mar 15, 2022
cff0952
Enable cleaning step
Mar 16, 2022
86cecc7
wip
Mar 16, 2022
e7ddf25
wip
Mar 16, 2022
bda6d60
debug
Mar 16, 2022
cf72092
debug
Mar 16, 2022
9fa4281
testdrive
Mar 16, 2022
cf05a0f
Last changes from v0.7.x to develop (#660)
afalaleev Mar 16, 2022
ab84e08
solana tune
Mar 16, 2022
94af2b5
debug
Mar 16, 2022
6f0322c
wip
Mar 16, 2022
fd0cb99
wip
Mar 16, 2022
fa3d60d
confirmed
Mar 16, 2022
9b950fc
test
Mar 17, 2022
a15be09
Revert "test"
Mar 17, 2022
831b378
Comment extra steps
rozhkovdmitrii Mar 18, 2022
2f7f154
Comment extra steps
rozhkovdmitrii Mar 18, 2022
03ffaea
refactoring
Mar 18, 2022
20b0c54
typo
Mar 18, 2022
7d90442
Merge branch 'develop' into 583-introduce-full-test-suite-tf
Mar 18, 2022
b43719e
enable basic logic
Mar 18, 2022
f118b79
add dependences
Mar 18, 2022
d9c5aa5
playground for if
Mar 18, 2022
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
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ COPY --from=spl /opt/solana_utils.py \
/spl/bin/
COPY --from=spl /opt/neon-cli /spl/bin/emulator

COPY proxy/operator-keypairs/* /root/.config/solana/
COPY proxy/operator-keypairs/id.json /root/.config/solana/

COPY . /opt
ARG PROXY_REVISION
Expand Down
23 changes: 15 additions & 8 deletions proxy/common_neon/estimate.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,20 @@
@logged_group("neon.Proxy")
class GasEstimate:
def __init__(self, request: dict, solana: SolanaInteractor):
self.sender = request.get('from', "0x0000000000000000000000000000000000000000")[2:]
self.contract = request.get('to', '0x')[2:]
self.value = request.get('value', '0x00')
self.data = request.get('data', '0x')[2:]
self.sender = request.get('from') or '0x0000000000000000000000000000000000000000'
if self.sender:
self.sender = self.sender[2:]

self.contract = request.get('to') or ''
if self.contract:
self.contract = self.contract[2:]

self.data = request.get('data') or ''
if self.data:
self.data = self.data[2:]

self.value = request.get('value') or '0x00'

self.solana = solana

def execution_cost(self) -> int:
Expand Down Expand Up @@ -76,10 +85,8 @@ def estimate(self):
overhead = self.iterative_overhead_cost()

gas = execution_cost + trx_size_cost + overhead + EXTRA_GAS

# TODO: MM restriction. Uncomment ?
# if gas < 21000:
# gas = 21000
if gas < 21000:
gas = 21000

self.debug(f'execution_cost: {execution_cost}, ' +
f'trx_size_cost: {trx_size_cost}, ' +
Expand Down
2 changes: 2 additions & 0 deletions proxy/deploy-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ set -xeuo pipefail
echo "Deploy test..."

solana config set -u $SOLANA_URL
ln -s /opt/proxy/operator-keypairs/id?*.json /root/.config/solana/

solana address || solana-keygen new --no-passphrase
export $(/spl/bin/neon-cli --commitment confirmed --url $SOLANA_URL --evm_loader "$EVM_LOADER" neon-elf-params)

Expand Down
3 changes: 3 additions & 0 deletions proxy/indexer/indexer_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,6 @@ def get_contract_code(self, address) -> str:

def fill_account_info_by_indexer(self, neon_account: str, pda_account: str, code_account: str, slot: int):
self._account_db.set_acc_indexer(neon_account, pda_account, code_account, slot)

def get_sol_sign_list_by_neon_sign(self, neon_sign: str) -> [str]:
return self._txs_db.get_sol_sign_list_by_neon_sign(neon_sign)
19 changes: 19 additions & 0 deletions proxy/indexer/transactions_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,22 @@ def set_txs(self, neon_sign: str, used_ixs: [SolanaIxSignInfo]):
VALUES(%s, %s, %s, %s) ON CONFLICT DO NOTHING''',
rows)

def get_sol_sign_list_by_neon_sign(self, neon_sign: str) -> [str]:
request = f'''
SELECT sol_sign
FROM {self._table_name} AS a
WHERE neon_sign = %s
'''

with self._conn.cursor() as cursor:
cursor.execute(request, [neon_sign])
values = cursor.fetchall()

if not values:
return []

return [v[0] for v in values]


class NeonTxsDB(BaseDB):
def __init__(self):
Expand Down Expand Up @@ -112,3 +128,6 @@ def get_tx_list_by_sol_sign(self, sol_sign_list: [str]) -> [NeonTxFullInfo]:
return []

return [self._tx_from_value(v) for v in values if v is not None]

def get_sol_sign_list_by_neon_sign(self, neon_sign: str) -> [str]:
return self._sol_neon_txs_db.get_sol_sign_list_by_neon_sign(neon_sign)
3 changes: 3 additions & 0 deletions proxy/memdb/memdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,6 @@ def get_logs(self, from_block, to_block, addresses, topics, block_hash):

def get_contract_code(self, address: str) -> str:
return self._db.get_contract_code(address)

def get_sol_sign_list_by_neon_sign(self, neon_sign: str) -> [str]:
return self._db.get_sol_sign_list_by_neon_sign(neon_sign)
8 changes: 7 additions & 1 deletion proxy/plugin/solana_rest_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
modelInstanceLock = threading.Lock()
modelInstance = None

NEON_PROXY_PKG_VERSION = '0.6.0-dev'
NEON_PROXY_PKG_VERSION = '0.7.1-dev'
NEON_PROXY_REVISION = 'NEON_PROXY_REVISION_TO_BE_REPLACED'


Expand Down Expand Up @@ -386,6 +386,12 @@ def eth_sendRawTransaction(self, rawTrx):
# self.error(f"eth_sendRawTransaction type(err): {type(err}}, Exception: {err}")
raise

def neon_getSolanaTransactionByNeonTransaction(self, neonTxId: str) -> [str]:
if not isinstance(neonTxId, str):
return []
return self._db.get_sol_sign_list_by_neon_sign(neonTxId)



class JsonEncoder(json.JSONEncoder):
def default(self, obj):
Expand Down
1 change: 1 addition & 0 deletions proxy/run-test-proxy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ if [ -z "$SOLANA_URL" ]; then
fi

solana config set -u $SOLANA_URL
ln -s /opt/proxy/operator-keypairs/id?*.json /root/.config/solana/

echo "$(date "+%F %X.%3N") I $(basename "$0"):${LINENO} $$ ${COMPONENT}:StartScript {} Dumping evm_loader and extracting ELF parameters"
export EVM_LOADER=$(solana address -k /spl/bin/evm_loader-keypair.json)
Expand Down
30 changes: 15 additions & 15 deletions proxy/testing/test_neon_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def deploy_contract(self):
artifacts = compile_source(NEON_TOKEN_CONTRACT)
_, self.neon_token_iface = artifacts.popitem()

self.neon_contract = proxy.eth.contract(abi=self.neon_token_iface['abi'],
self.neon_contract = proxy.eth.contract(abi=self.neon_token_iface['abi'],
bytecode=self.neon_token_iface['bin'])

deployer = self.create_eth_account(self, 100)
Expand All @@ -79,7 +79,7 @@ def deploy_contract(self):
print(f'deploy status: {tx_deploy_receipt.status}')
self.neon_token_address = tx_deploy_receipt.contractAddress
print(f'NeonToken contract address is: {self.neon_token_address}')
self.neon_contract = proxy.eth.contract(address=self.neon_token_address,
self.neon_contract = proxy.eth.contract(address=self.neon_token_address,
abi=self.neon_token_iface['abi'])

def withdraw(self, source_acc: NeonAccount, dest_acc: SolanaAccount, withdraw_amount_alan: int):
Expand All @@ -92,7 +92,7 @@ def withdraw(self, source_acc: NeonAccount, dest_acc: SolanaAccount, withdraw_am
withdraw_tx_receipt = proxy.eth.wait_for_transaction_receipt(withdraw_tx_hash)
print(f'withdraw_tx_receipt: {withdraw_tx_receipt}')
print(f'deploy status: {withdraw_tx_receipt.status}')

def test_success_withdraw_to_non_existing_account(self):
"""
Should succesfully withdraw NEON tokens to previously non-existing Associated Token Account
Expand All @@ -102,7 +102,7 @@ def test_success_withdraw_to_non_existing_account(self):

dest_token_acc = get_associated_token_address(dest_acc.public_key(), NEON_TOKEN_MINT)
print(f"Destination token account: {dest_token_acc}")

withdraw_amount_alan = pow(10, 18) # 1 NEON
withdraw_amount_galan = int(withdraw_amount_alan / 1_000_000_000)

Expand All @@ -126,7 +126,7 @@ def test_success_withdraw_to_non_existing_account(self):
destination_balance_after_galan = self.spl_neon_token.get_balance(dest_token_acc, commitment=Confirmed)
print(f'Destination account balance after (Galan): {destination_balance_after_galan}')
self.assertEqual(int(destination_balance_after_galan['result']['value']['amount']), withdraw_amount_galan)

def test_success_withdraw_to_existing_account(self):
"""
Should succesfully withdraw NEON tokens to existing Associated Token Account
Expand All @@ -138,17 +138,17 @@ def test_success_withdraw_to_existing_account(self):
trx = Transaction()
trx.add(
create_associated_token_account(
dest_acc.public_key(),
dest_acc.public_key(),
dest_acc.public_key(),
dest_acc.public_key(),
NEON_TOKEN_MINT
)
)
opts = TxOpts(skip_preflight=True, skip_confirmation=False)
solana.send_transaction(trx, dest_acc, opts=opts)

dest_token_acc = get_associated_token_address(dest_acc.public_key(), NEON_TOKEN_MINT)
print(f"Destination token account: {dest_token_acc}")

withdraw_amount_alan = 2_123_000_321_000_000_000
withdraw_amount_galan = int(withdraw_amount_alan / 1_000_000_000)

Expand All @@ -174,7 +174,7 @@ def test_success_withdraw_to_existing_account(self):
destination_balance_after_galan = int(resp['result']['value']['amount'])
print(f'Destination account balance after (Galan): {destination_balance_after_galan}')
self.assertEqual(destination_balance_after_galan, withdraw_amount_galan)

def test_failed_withdraw_non_divisible_amount(self):
"""
Should fail withdrawal because amount not divised by 1 billion
Expand All @@ -184,7 +184,7 @@ def test_failed_withdraw_non_divisible_amount(self):

dest_token_acc = get_associated_token_address(dest_acc.public_key(), NEON_TOKEN_MINT)
print(f"Destination token account: {dest_token_acc}")

withdraw_amount_alan = pow(10, 18) + 123 # NEONs

# Check source balance
Expand All @@ -209,7 +209,7 @@ def test_failed_withdraw_non_divisible_amount(self):
destination_balance_after_galan = self.spl_neon_token.get_balance(dest_token_acc, commitment=Confirmed)
print(f'Destination account balance after (Galan): {destination_balance_after_galan}')
self.assertTrue(destination_balance_after_galan['error'] is not None)

def test_failed_withdraw_insufficient_balance(self):
"""
Should fail withdrawal because of insufficient balance
Expand All @@ -219,7 +219,7 @@ def test_failed_withdraw_insufficient_balance(self):

dest_token_acc = get_associated_token_address(dest_acc.public_key(), NEON_TOKEN_MINT)
print(f"Destination token account: {dest_token_acc}")

withdraw_amount_alan = 2 * pow(10, 18) # 2 NEONs

# Check source balance
Expand All @@ -244,7 +244,7 @@ def test_failed_withdraw_insufficient_balance(self):
destination_balance_after_galan = self.spl_neon_token.get_balance(dest_token_acc, commitment=Confirmed)
print(f'Destination account balance after (Galan): {destination_balance_after_galan}')
self.assertTrue(destination_balance_after_galan['error'] is not None)

def test_failed_withdraw_all_balance(self):
"""
Should fail withdrawal all balance
Expand All @@ -254,7 +254,7 @@ def test_failed_withdraw_all_balance(self):

dest_token_acc = get_associated_token_address(dest_acc.public_key(), NEON_TOKEN_MINT)
print(f"Destination token account: {dest_token_acc}")

withdraw_amount_alan = 1_000_000_000_000_000_000 # 1 NEON

# Check source balance
Expand Down