-
Notifications
You must be signed in to change notification settings - Fork 20
#291 Proxy refactoring #324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
90a4e56
#291 extract transaction sender class
otselnik 143913b
#291 move perm accs to transaction sender
otselnik 16c9bff
#291 fix state
otselnik f2c0303
#291 fix errors
otselnik 57f3b53
Merge remote-tracking branch 'origin/develop' into 291_proxy_refactoring
otselnik 3369f67
#291 merge fixes
otselnik af721bb
#291 refactoring
otselnik e512bb8
#291 move EXTRA_GAS to environment
otselnik 8dc5e29
#291 capitalize CONFIRMATION_CHECK_DELAY
otselnik 8dce2a5
#291 sort imports
otselnik cef8f21
#291 relative paths
otselnik 1bf8383
#291 Should be fixed in #326
otselnik 9672438
#291 testing chnages
otselnik 2d42b73
fix storage account check
sinev-valentine ac2755c
Merge remote-tracking branch 'origin/develop' into 291_proxy_refactoring
otselnik 3519c61
Merge branch '371_add_FinalizedStorage_to_check' into 291_proxy_refac…
otselnik bf313a2
#291 rename `trx_with_create_and_airdrop` -> `make_trx_with_create_an…
otselnik 3093fcc
Merge remote-tracking branch 'origin/develop' into 291_proxy_refactoring
otselnik 4d685db
#291 pull request fixes
otselnik 6f63338
Merge remote-tracking branch 'origin/develop' into 291_proxy_refactoring
otselnik 5ebf76a
Merge remote-tracking branch 'origin/develop' into 291_proxy_refactoring
otselnik b464b1e
#291 merge fix
otselnik 75c8e9a
#291 rename operator and associated token accounts
otselnik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Merge remote-tracking branch 'origin/develop' into 291_proxy_refactoring
- Loading branch information
commit 57f3b534f5021d9e171088c86c6f701a740309b4
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| import logging | ||
| import struct | ||
| import eth_utils | ||
| from construct import Bytes, Int8ul, Int64ul | ||
| from construct import Struct as cStruct | ||
| from solana._layouts.system_instructions import SYSTEM_INSTRUCTIONS_LAYOUT, InstructionType | ||
|
|
@@ -8,9 +9,10 @@ | |
| from solana.sysvar import SYSVAR_CLOCK_PUBKEY, SYSVAR_RENT_PUBKEY | ||
| from solana.transaction import AccountMeta, TransactionInstruction, Transaction | ||
| from spl.token.constants import ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID | ||
| from spl.token.instructions import transfer2, Transfer2Params | ||
| from sha3 import keccak_256 | ||
|
|
||
| from proxy.environment import evm_loader_id as EVM_LOADER_ID, ETH_TOKEN_MINT_ID , COLLATERAL_POOL_BASE | ||
| from proxy.environment import evm_loader_id as EVM_LOADER_ID, ETH_TOKEN_MINT_ID , COLLATERAL_POOL_BASE, NEW_USER_AIRDROP_AMOUNT | ||
| from .constants import SYSVAR_INSTRUCTION_PUBKEY, INCINERATOR_PUBKEY, KECCAK_PROGRAM, COLLATERALL_POOL_MAX | ||
| from .address import accountWithSeed, ether2program, getTokenAddr | ||
|
|
||
|
|
@@ -148,25 +150,21 @@ def create_account_with_seed_trx(self, seed, lamports, space): | |
| ) | ||
|
|
||
|
|
||
| def createEtherAccountTrx(self, ether, code_acc=None): | ||
| if isinstance(ether, str): | ||
| if ether.startswith('0x'): ether = ether[2:] | ||
| else: ether = ether.hex() | ||
| (sol, nonce) = ether2program(ether) | ||
| associated_token = getTokenAddr(PublicKey(sol)) | ||
| logger.debug('createEtherAccount: {} {} => {}'.format(ether, nonce, sol)) | ||
| logger.debug('associatedTokenAccount: {}'.format(associated_token)) | ||
| def make_create_eth_account_trx(self, eth_address, code_acc=None): | ||
|
||
| solana_address, nonce = ether2program(eth_address) | ||
| token_acc_address = getTokenAddr(PublicKey(solana_address)) | ||
| logger.debug(f'Create eth account: {eth_address}, sol account: {solana_address}, token_acc_address: {token_acc_address}, nonce: {nonce}') | ||
| base = self.operator | ||
| data=create_account_layout(0, 0, bytes.fromhex(ether), nonce) | ||
| data = create_account_layout(0, 0, bytes(eth_address), nonce) | ||
| trx = Transaction() | ||
| if code_acc is None: | ||
| trx.add(TransactionInstruction( | ||
| program_id=EVM_LOADER_ID, | ||
| data=data, | ||
| keys=[ | ||
| AccountMeta(pubkey=base, is_signer=True, is_writable=True), | ||
| AccountMeta(pubkey=PublicKey(sol), is_signer=False, is_writable=True), | ||
| AccountMeta(pubkey=associated_token, is_signer=False, is_writable=True), | ||
| AccountMeta(pubkey=PublicKey(solana_address), is_signer=False, is_writable=True), | ||
| AccountMeta(pubkey=token_acc_address, is_signer=False, is_writable=True), | ||
| AccountMeta(pubkey=SYS_PROGRAM_ID, is_signer=False, is_writable=False), | ||
| AccountMeta(pubkey=ETH_TOKEN_MINT_ID, is_signer=False, is_writable=False), | ||
| AccountMeta(pubkey=TOKEN_PROGRAM_ID, is_signer=False, is_writable=False), | ||
|
|
@@ -179,19 +177,19 @@ def createEtherAccountTrx(self, ether, code_acc=None): | |
| data=data, | ||
| keys=[ | ||
| AccountMeta(pubkey=base, is_signer=True, is_writable=True), | ||
| AccountMeta(pubkey=PublicKey(sol), is_signer=False, is_writable=True), | ||
| AccountMeta(pubkey=associated_token, is_signer=False, is_writable=True), | ||
| AccountMeta(pubkey=PublicKey(solana_address), is_signer=False, is_writable=True), | ||
| AccountMeta(pubkey=token_acc_address, is_signer=False, is_writable=True), | ||
| AccountMeta(pubkey=PublicKey(code_acc), is_signer=False, is_writable=True), | ||
| AccountMeta(pubkey=SYS_PROGRAM_ID, is_signer=False, is_writable=False), | ||
| AccountMeta(pubkey=ETH_TOKEN_MINT_ID, is_signer=False, is_writable=False), | ||
| AccountMeta(pubkey=TOKEN_PROGRAM_ID, is_signer=False, is_writable=False), | ||
| AccountMeta(pubkey=ASSOCIATED_TOKEN_PROGRAM_ID, is_signer=False, is_writable=False), | ||
| AccountMeta(pubkey=SYSVAR_RENT_PUBKEY, is_signer=False, is_writable=False), | ||
| ])) | ||
| return (trx, sol, associated_token) | ||
| return trx, token_acc_address | ||
|
|
||
|
|
||
| def createERC20TokenAccountTrx(self, token_info): | ||
| def createERC20TokenAccountTrx(self, token_info) -> Transaction: | ||
| trx = Transaction() | ||
| trx.add(TransactionInstruction( | ||
| program_id=EVM_LOADER_ID, | ||
|
|
@@ -211,7 +209,35 @@ def createERC20TokenAccountTrx(self, token_info): | |
| return trx | ||
|
|
||
|
|
||
| def make_write_transaction(self, offset: int, data: bytes): | ||
| def make_transfer_instruction(self, associated_token_account: PublicKey) -> TransactionInstruction: | ||
| owner_associated_token_account = getTokenAddr(self.operator) | ||
|
||
| transfer_instruction = transfer2(Transfer2Params( | ||
| source=owner_associated_token_account, | ||
| owner=self.operator, | ||
| dest=associated_token_account, | ||
| amount=NEW_USER_AIRDROP_AMOUNT * eth_utils.denoms.gwei, | ||
| decimals=9, | ||
| mint=ETH_TOKEN_MINT_ID, | ||
| program_id=TOKEN_PROGRAM_ID | ||
| )) | ||
| logger.debug(f"Token transfer from token: {owner_associated_token_account}, owned by: {self.operator}, to token: " | ||
| f"{associated_token_account}, owned by: {associated_token_account} , value: {NEW_USER_AIRDROP_AMOUNT}") | ||
| return transfer_instruction | ||
|
|
||
|
|
||
| def trx_with_create_and_airdrop(self, eth_account, code_acc=None) -> Transaction: | ||
rozhkovdmitrii marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| trx = Transaction() | ||
| create_trx, associated_token_account = self.make_create_eth_account_trx(eth_account, code_acc) | ||
| trx.add(create_trx) | ||
| if NEW_USER_AIRDROP_AMOUNT <= 0: | ||
| return trx | ||
| transfer_instruction = self.make_transfer_instruction(associated_token_account) | ||
| trx.add(transfer_instruction) | ||
|
|
||
| return trx | ||
|
|
||
|
|
||
| def make_write_transaction(self, offset: int, data: bytes) -> Transaction: | ||
| return Transaction().add(TransactionInstruction( | ||
| program_id=EVM_LOADER_ID, | ||
| data=write_holder_layout(self.perm_accs_id, offset, data), | ||
|
|
@@ -222,7 +248,7 @@ def make_write_transaction(self, offset: int, data: bytes): | |
| )) | ||
|
|
||
|
|
||
| def make_keccak_instruction(self, check_instruction_index, msg_len, data_start): | ||
| def make_keccak_instruction(self, check_instruction_index, msg_len, data_start) -> TransactionInstruction: | ||
| return TransactionInstruction( | ||
| program_id=KECCAK_PROGRAM, | ||
| data=make_keccak_instruction_data(check_instruction_index, msg_len, data_start), | ||
|
|
@@ -232,7 +258,7 @@ def make_keccak_instruction(self, check_instruction_index, msg_len, data_start): | |
| ) | ||
|
|
||
|
|
||
| def make_05_call_instruction(self): | ||
| def make_05_call_instruction(self) -> TransactionInstruction: | ||
| return TransactionInstruction( | ||
| program_id = EVM_LOADER_ID, | ||
| data = bytearray.fromhex("05") + self.collateral_pool_index_buf + self.msg, | ||
|
|
@@ -255,7 +281,7 @@ def make_noniterative_call_transaction(self, length_before: int = 0) -> Transact | |
| return trx | ||
|
|
||
|
|
||
| def make_partial_call_instruction(self): | ||
| def make_partial_call_instruction(self) -> TransactionInstruction: | ||
| return TransactionInstruction( | ||
| program_id = EVM_LOADER_ID, | ||
| data = bytearray.fromhex("13") + self.collateral_pool_index_buf + int(0).to_bytes(8, byteorder="little") + self.msg, | ||
|
|
@@ -304,7 +330,7 @@ def make_call_from_account_instruction(self) -> Transaction: | |
| )) | ||
|
|
||
|
|
||
| def make_continue_instruction(self, steps, index=None): | ||
| def make_continue_instruction(self, steps, index=None) -> Transaction: | ||
| data = bytearray.fromhex("14") + self.collateral_pool_index_buf + steps.to_bytes(8, byteorder="little") | ||
| if index: | ||
| data = data + index.to_bytes(8, byteorder="little") | ||
|
|
@@ -328,7 +354,7 @@ def make_continue_instruction(self, steps, index=None): | |
| )) | ||
|
|
||
|
|
||
| def make_cancel_instruction(self): | ||
| def make_cancel_instruction(self) -> Transaction: | ||
| return Transaction().add(TransactionInstruction( | ||
| program_id = EVM_LOADER_ID, | ||
| data = bytearray.fromhex("15") + self.eth_trx.nonce.to_bytes(8, 'little'), | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
You are viewing a condensed version of this merge commit. You can view the full changes here.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.