def create_account_instruction(self, eth_address: str, payer: PublicKey): dest_address_solana, nonce = get_evm_loader_account_address( eth_address) neon_token_account = get_associated_token_address( dest_address_solana, ETH_TOKEN_MINT_ID) return TransactionInstruction( program_id=EVM_LOADER_ID, data=create_account_layout(0, 0, bytes.fromhex(eth_address[2:]), nonce), keys=[ AccountMeta(pubkey=payer, is_signer=True, is_writable=True), AccountMeta(pubkey=dest_address_solana, is_signer=False, is_writable=True), AccountMeta(pubkey=neon_token_account, 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), ])
def transfer(params: TransferParams) -> TransactionInstruction: """Generate an instruction that transfers lamports from one account to another. >>> from solana.publickey import PublicKey >>> sender, reciever = PublicKey(1), PublicKey(2) >>> instruction = transfer( ... TransferParams(from_pubkey=sender, to_pubkey=reciever, lamports=1000) ... ) >>> type(instruction) <class 'solana.transaction.TransactionInstruction'> """ data = SYSTEM_INSTRUCTIONS_LAYOUT.build( dict(instruction_type=InstructionType.Transfer, args=dict(lamports=params.lamports))) return TransactionInstruction( keys=[ AccountMeta(pubkey=params.from_pubkey, is_signer=True, is_writable=True), AccountMeta(pubkey=params.to_pubkey, is_signer=False, is_writable=True), ], program_id=SYS_PROGRAM_ID, data=data, )
def create_neon_erc20_account_instruction(self, payer: PublicKey, eth_address: str): return TransactionInstruction( program_id=self.evm_loader_id, data=bytes.fromhex('0F'), keys=[ AccountMeta(pubkey=payer, is_signer=True, is_writable=True), AccountMeta( pubkey=self.get_neon_erc20_account_address(eth_address), is_signer=False, is_writable=True), AccountMeta(pubkey=self.get_neon_account_address(eth_address), is_signer=False, is_writable=True), AccountMeta(pubkey=self.solana_contract_address, is_signer=False, is_writable=True), AccountMeta(pubkey=self.token.pubkey, is_signer=False, is_writable=True), AccountMeta(pubkey=SYS_PROGRAM_ID, is_signer=False, is_writable=False), AccountMeta(pubkey=TOKEN_PROGRAM_ID, is_signer=False, is_writable=False), AccountMeta(pubkey=SYSVAR_RENT_PUBKEY, is_signer=False, is_writable=False), ])
def assign( params: Union[AssignParams, AssignWithSeedParams]) -> TransactionInstruction: """Generate an instruction that assigns an account to a program. >>> from solana.publickey import PublicKey >>> account, program_id = PublicKey(1), PublicKey(2) >>> instruction = assign( ... AssignParams(account_pubkey=account, program_id=program_id) ... ) >>> type(instruction) <class 'solana.transaction.TransactionInstruction'> """ if isinstance(params, AssignWithSeedParams): raise NotImplementedError("assign with key is not implemented") else: data = SYSTEM_INSTRUCTIONS_LAYOUT.build( dict(instruction_type=InstructionType.Assign, args=dict(program_id=bytes(params.program_id)))) return TransactionInstruction( keys=[ AccountMeta(pubkey=params.account_pubkey, is_signer=True, is_writable=True), ], program_id=SYS_PROGRAM_ID, data=data, )
def initialize_account(params: InitializeAccountParams) -> TransactionInstruction: """Creates a transaction instruction to initialize a new account to hold tokens. This instruction requires no signers and MUST be included within the same Transaction as the system program's `CreateInstruction` that creates the account being initialized. Otherwise another party can acquire ownership of the uninitialized account. >>> account, mint, owner, token = PublicKey(1), PublicKey(2), PublicKey(3), PublicKey(4) >>> params = InitializeAccountParams( ... account=account, ... mint=mint, ... owner=owner, ... program_id=token, ... ) >>> type(initialize_account(params)) <class 'solana.transaction.TransactionInstruction'> """ data = INSTRUCTIONS_LAYOUT.build(dict(instruction_type=InstructionType.InitializeAccount, args=None)) return TransactionInstruction( keys=[ AccountMeta(pubkey=params.account, is_signer=False, is_writable=True), AccountMeta(pubkey=params.mint, is_signer=False, is_writable=False), AccountMeta(pubkey=params.owner, is_signer=False, is_writable=False), AccountMeta(pubkey=SYSVAR_RENT_PUBKEY, is_signer=False, is_writable=False), ], program_id=params.program_id, data=data, )
def createERC20TokenAccountTrx(self, token_info) -> Transaction: trx = Transaction() trx.add( TransactionInstruction( program_id=EVM_LOADER_ID, data=bytes.fromhex('0F'), keys=[ AccountMeta(pubkey=self.operator_account, is_signer=True, is_writable=True), AccountMeta(pubkey=PublicKey(token_info["key"]), is_signer=False, is_writable=True), AccountMeta(pubkey=PublicKey(token_info["owner"]), is_signer=False, is_writable=True), AccountMeta(pubkey=PublicKey(token_info["contract"]), is_signer=False, is_writable=True), AccountMeta(pubkey=PublicKey(token_info["mint"]), is_signer=False, is_writable=True), AccountMeta(pubkey=SYS_PROGRAM_ID, is_signer=False, is_writable=False), AccountMeta(pubkey=TOKEN_PROGRAM_ID, is_signer=False, is_writable=False), AccountMeta(pubkey=SYSVAR_RENT_PUBKEY, is_signer=False, is_writable=False), ])) return trx
def make_partial_call_or_continue_instruction(self, steps=0 ) -> TransactionInstruction: data = bytearray.fromhex( "0D") + self.collateral_pool_index_buf + steps.to_bytes( 8, byteorder="little") + self.msg return TransactionInstruction( program_id=EVM_LOADER_ID, data=data, keys=[ AccountMeta( pubkey=self.storage, is_signer=False, is_writable=True), AccountMeta(pubkey=SYSVAR_INSTRUCTION_PUBKEY, is_signer=False, is_writable=False), AccountMeta(pubkey=self.operator_account, is_signer=True, is_writable=True), AccountMeta(pubkey=self.collateral_pool_address, is_signer=False, is_writable=True), AccountMeta(pubkey=self.operator_neon_address, is_signer=False, is_writable=True), AccountMeta(pubkey=self.caller_token, is_signer=False, is_writable=True), AccountMeta( pubkey=SYS_PROGRAM_ID, is_signer=False, is_writable=False), ] + self.eth_accounts + [ AccountMeta(pubkey=SYSVAR_INSTRUCTION_PUBKEY, is_signer=False, is_writable=False), ] + obligatory_accounts)
def set_authority(params: SetAuthorityParams) -> TransactionInstruction: """Creates a transaction instruction to sets a new authority of a mint or account. >>> account, current_authority, new_authority, token = ( ... PublicKey(1), PublicKey(2), PublicKey(3), PublicKey(4) ... ) >>> params = SetAuthorityParams( ... account=account, ... authority=AuthorityType.ACCOUNT_OWNER, ... current_authority=current_authority, ... new_authority=new_authority, ... program_id=token, ... ) >>> type(set_authority(params)) <class 'solana.transaction.TransactionInstruction'> """ new_authority, opt = (params.new_authority, 1) if params.new_authority else (PublicKey(0), 0) data = INSTRUCTIONS_LAYOUT.build( dict( instruction_type=InstructionType.SET_AUTHORITY, args=dict(authority_type=params.authority, new_authority_option=opt, new_authority=bytes(new_authority)), )) keys = [ AccountMeta(pubkey=params.account, is_signer=False, is_writable=True) ] __add_signers(keys, params.current_authority, params.signers) return TransactionInstruction(keys=keys, program_id=params.program_id, data=data)
def sol_instr_partial_call_or_continue(self, storage_account, step_count, evm_instruction): return TransactionInstruction( program_id=self.loader.loader_id, data=bytearray.fromhex("0D") + self.collateral_pool_index_buf + step_count.to_bytes(8, byteorder='little') + evm_instruction, keys=[ AccountMeta(pubkey=storage_account, is_signer=False, is_writable=True), # System instructions account: AccountMeta(pubkey=PublicKey(SYSVAR_INSTRUCTION_PUBKEY), is_signer=False, is_writable=False), # Operator address: AccountMeta(pubkey=self.acc.public_key(), is_signer=True, is_writable=True), # Collateral pool address: AccountMeta(pubkey=self.collateral_pool_address, is_signer=False, is_writable=True), # Operator's NEON token account: AccountMeta(pubkey=get_associated_token_address(self.acc.public_key(), ETH_TOKEN_MINT_ID), is_signer=False, is_writable=True), # User's NEON token account: AccountMeta(pubkey=self.caller_token, is_signer=False, is_writable=True), # System program account: AccountMeta(pubkey=PublicKey(SYS_PROGRAM_ID), is_signer=False, is_writable=False), AccountMeta(pubkey=self.reId, is_signer=False, is_writable=True), AccountMeta(pubkey=self.re_code, is_signer=False, is_writable=True), AccountMeta(pubkey=self.caller, is_signer=False, is_writable=True), AccountMeta(pubkey=self.caller_token, is_signer=False, is_writable=True), AccountMeta(pubkey=self.loader.loader_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), ])
def delegate_stake(params: DelegateStakeParams) -> TransactionInstruction: """Creates an instruction to delegate a stake account.""" return TransactionInstruction( keys=[ AccountMeta(pubkey=params.stake, is_signer=False, is_writable=True), AccountMeta(pubkey=params.vote, is_signer=False, is_writable=False), AccountMeta(pubkey=params.clock_sysvar, is_signer=False, is_writable=False), AccountMeta(pubkey=params.stake_history_sysvar, is_signer=False, is_writable=False), AccountMeta(pubkey=params.stake_config_id, is_signer=False, is_writable=False), AccountMeta(pubkey=params.staker, is_signer=True, is_writable=False), ], program_id=STAKE_PROGRAM_ID, data=INSTRUCTIONS_LAYOUT.build( dict( instruction_type=InstructionType.DELEGATE_STAKE, args=None, )))
def initialize_binary_option_instruction( pool_account, escrow_mint_account, escrow_account, long_token_mint_account, short_token_mint_account, mint_authority_account, update_authority_account, token_account, system_account, rent_account, decimals): keys = [ AccountMeta(pubkey=pool_account, is_signer=True, is_writable=True), AccountMeta(pubkey=escrow_mint_account, is_signer=False, is_writable=False), AccountMeta(pubkey=escrow_account, is_signer=True, is_writable=True), AccountMeta(pubkey=long_token_mint_account, is_signer=True, is_writable=False), AccountMeta(pubkey=short_token_mint_account, is_signer=True, is_writable=False), AccountMeta(pubkey=mint_authority_account, is_signer=True, is_writable=False), AccountMeta(pubkey=update_authority_account, is_signer=True, is_writable=False), AccountMeta(pubkey=token_account, is_signer=False, is_writable=False), AccountMeta(pubkey=system_account, is_signer=False, is_writable=False), AccountMeta(pubkey=rent_account, is_signer=False, is_writable=False), ] data = struct.pack("<BB", 0, decimals) return TransactionInstruction( keys=keys, program_id=PublicKey(BINARY_OPTION_PROGRAM_ID), data=data)
def cancel_order(params: CancelOrderParams) -> TransactionInstruction: """Generate a transaction instruction to cancel order.""" return TransactionInstruction( keys=[ AccountMeta(pubkey=params.market, is_signer=False, is_writable=False), AccountMeta(pubkey=params.open_orders, is_signer=False, is_writable=True), AccountMeta(pubkey=params.request_queue, is_signer=False, is_writable=True), AccountMeta(pubkey=params.owner, is_signer=True, is_writable=False), ], program_id=params.program_id, data=INSTRUCTIONS_LAYOUT.build( dict( instruction_type=InstructionType.CancelOrder, args=dict( side=params.side, order_id=params.order_id.to_bytes(16, byteorder="little"), open_orders=bytes(params.open_orders), open_orders_slot=params.open_orders_slot, ), )), )
def settle_funds(params: SettleFundsParams) -> TransactionInstruction: """Generate a transaction instruction to settle fund.""" return TransactionInstruction( keys=[ AccountMeta(pubkey=params.market, is_signer=False, is_writable=True), AccountMeta(pubkey=params.open_orders, is_signer=False, is_writable=True), AccountMeta(pubkey=params.owner, is_signer=True, is_writable=False), AccountMeta(pubkey=params.base_vault, is_signer=False, is_writable=True), AccountMeta(pubkey=params.quote_vault, is_signer=False, is_writable=True), AccountMeta(pubkey=params.base_wallet, is_signer=False, is_writable=True), AccountMeta(pubkey=params.quote_wallet, is_signer=False, is_writable=True), AccountMeta(pubkey=params.vault_signer, is_signer=False, is_writable=False), AccountMeta(pubkey=TOKEN_PROGRAM_ID, is_signer=False, is_writable=False), ], program_id=params.program_id, data=INSTRUCTIONS_LAYOUT.build( dict(instruction_type=InstructionType.SettleFunds, args=dict())), )
def match_orders(params: MatchOrdersParams) -> TransactionInstruction: """Generate a transaction instruction to match order.""" return TransactionInstruction( keys=[ AccountMeta(pubkey=params.market, is_signer=False, is_writable=True), AccountMeta(pubkey=params.request_queue, is_signer=False, is_writable=True), AccountMeta(pubkey=params.event_queue, is_signer=False, is_writable=True), AccountMeta(pubkey=params.bids, is_signer=False, is_writable=True), AccountMeta(pubkey=params.asks, is_signer=False, is_writable=True), AccountMeta(pubkey=params.base_vault, is_signer=False, is_writable=True), AccountMeta(pubkey=params.quote_vault, is_signer=False, is_writable=True), ], program_id=params.program_id, data=INSTRUCTIONS_LAYOUT.build( dict(instruction_type=InstructionType.MatchOrder, args=dict(limit=params.limit))), )
def update_stake_pool_balance( params: UpdateStakePoolBalanceParams) -> TransactionInstruction: """Creates instruction to update the overall stake pool balance.""" return TransactionInstruction( keys=[ AccountMeta(pubkey=params.stake_pool, is_signer=False, is_writable=True), AccountMeta(pubkey=params.withdraw_authority, is_signer=False, is_writable=False), AccountMeta(pubkey=params.validator_list, is_signer=False, is_writable=True), AccountMeta(pubkey=params.reserve_stake, is_signer=False, is_writable=False), AccountMeta(pubkey=params.manager_fee_account, is_signer=False, is_writable=True), AccountMeta(pubkey=params.pool_mint, is_signer=False, is_writable=True), AccountMeta(pubkey=params.token_program_id, is_signer=False, is_writable=False), ], program_id=params.program_id, data=INSTRUCTIONS_LAYOUT.build( dict( instruction_type=InstructionType.UPDATE_STAKE_POOL_BALANCE, args=None, )))
def initialize_multisig(params: InitializeMultisigParams) -> TransactionInstruction: """Creates a transaction instruction to initialize a multisignature account with N provided signers. This instruction requires no signers and MUST be included within the same Transaction as the system program's `CreateInstruction` that creates the account being initialized. Otherwise another party can acquire ownership of the uninitialized account. >>> m = 2 # Two signers >>> signers = [PublicKey(i) for i in range(m)] >>> multisig_account, token = PublicKey(1), PublicKey(2) >>> params = InitializeMultisigParams( ... m=m, ... multisig=multisig_account, ... signers=signers, ... program_id=token, ... ) >>> type(initialize_multisig(params)) <class 'solana.transaction.TransactionInstruction'> """ data = INSTRUCTIONS_LAYOUT.build(dict(instruction_type=InstructionType.InitializeMultisig, args=dict(m=params.m))) keys = [ AccountMeta(pubkey=params.multisig, is_signer=False, is_writable=True), AccountMeta(pubkey=SYSVAR_RENT_PUBKEY, is_signer=False, is_writable=False), ] for signer in params.signers: keys.append(AccountMeta(pubkey=signer, is_signer=False, is_writable=False)) return TransactionInstruction(keys=keys, program_id=params.program_id, data=data)
def transfer(params: TransferParams) -> TransactionInstruction: """Creates a transaction instruction to transfers tokens from one account to another. Either directly or via a delegate. >>> dest, owner, source, token = PublicKey(1), PublicKey(2), PublicKey(3), PublicKey(4) >>> params = TransferParams( ... amount=1000, ... dest=dest, ... owner=owner, ... program_id=token, ... source=source, ... ) >>> type(transfer(params)) <class 'solana.transaction.TransactionInstruction'> """ data = INSTRUCTIONS_LAYOUT.build( dict(instruction_type=InstructionType.TRANSFER, args=dict(amount=params.amount))) keys = [ AccountMeta(pubkey=params.source, is_signer=False, is_writable=True), AccountMeta(pubkey=params.dest, is_signer=False, is_writable=True), ] __add_signers(keys, params.owner, params.signers) return TransactionInstruction(keys=keys, program_id=params.program_id, data=data)
def close_account(params: CloseAccountParams) -> TransactionInstruction: """Creates a transaction instruction to close an account by transferring all its SOL to the destination account. Non-native accounts may only be closed if its token amount is zero. Example: >>> account, dest, owner, token = PublicKey(1), PublicKey(2), PublicKey(3), PublicKey(4) >>> params = CloseAccountParams( ... account=account, dest=dest, owner=owner, program_id=token) >>> type(close_account(params)) <class 'solana.transaction.TransactionInstruction'> Returns: The close-account instruction. """ data = INSTRUCTIONS_LAYOUT.build( dict(instruction_type=InstructionType.CLOSE_ACCOUNT, args=None)) keys = [ AccountMeta(pubkey=params.account, is_signer=False, is_writable=True), AccountMeta(pubkey=params.dest, is_signer=False, is_writable=True), ] __add_signers(keys, params.owner, params.signers) return TransactionInstruction(keys=keys, program_id=params.program_id, data=data)
def approve(params: ApproveParams) -> TransactionInstruction: """Creates a transaction instruction to approves a delegate. >>> delegate, owner, source, token = PublicKey(1), PublicKey(2), PublicKey(3), PublicKey(4) >>> params = ApproveParams( ... amount=123, ... delegate=delegate, ... owner=owner, ... program_id=token, ... source=source ... ) >>> type(approve(params)) <class 'solana.transaction.TransactionInstruction'> """ data = INSTRUCTIONS_LAYOUT.build( dict(instruction_type=InstructionType.APPROVE, args=dict(amount=params.amount))) keys = [ AccountMeta(pubkey=params.source, is_signer=False, is_writable=True), AccountMeta(pubkey=params.delegate, is_signer=False, is_writable=False), ] __add_signers(keys, params.owner, params.signers) return TransactionInstruction(keys=keys, program_id=params.program_id, data=data)
def transfer_checked(params: TransferCheckedParams) -> TransactionInstruction: """This instruction differs from `transfer` in that the token mint and decimals value is asserted by the caller. Example: >>> dest, mint, owner, source, token = PublicKey(1), PublicKey(2), PublicKey(3), PublicKey(4), PublicKey(5) >>> params = TransferCheckedParams( ... amount=1000, ... decimals=6, ... dest=dest, ... mint=mint, ... owner=owner, ... program_id=token, ... source=source, ... ) >>> type(transfer_checked(params)) <class 'solana.transaction.TransactionInstruction'> Returns: The transfer-checked instruction. """ data = INSTRUCTIONS_LAYOUT.build( dict(instruction_type=InstructionType.TRANSFER2, args=dict(amount=params.amount, decimals=params.decimals))) keys = [ AccountMeta(pubkey=params.source, is_signer=False, is_writable=True), AccountMeta(pubkey=params.mint, is_signer=False, is_writable=False), AccountMeta(pubkey=params.dest, is_signer=False, is_writable=True), ] __add_signers(keys, params.owner, params.signers) return TransactionInstruction(keys=keys, program_id=params.program_id, data=data)
def approve2(params: Approve2Params) -> TransactionInstruction: """This instruction differs from `approve` in that the token mint and decimals value is asserted by the caller. >>> delegate, mint, owner, source, token = PublicKey(1), PublicKey(2), PublicKey(3), PublicKey(4), PublicKey(5) >>> params = Approve2Params( ... amount=1000, ... decimals=6, ... delegate=delegate, ... mint=mint, ... owner=owner, ... program_id=token, ... source=source, ... ) >>> type(approve2(params)) <class 'solana.transaction.TransactionInstruction'> """ data = INSTRUCTIONS_LAYOUT.build( dict(instruction_type=InstructionType.APPROVE2, args=dict(amount=params.amount, decimals=params.decimals))) keys = [ AccountMeta(pubkey=params.source, is_signer=False, is_writable=True), AccountMeta(pubkey=params.mint, is_signer=False, is_writable=False), AccountMeta(pubkey=params.delegate, is_signer=False, is_writable=False), ] __add_signers(keys, params.owner, params.signers) return TransactionInstruction(keys=keys, program_id=params.program_id, data=data)
def create_associated_token_account(payer: PublicKey, owner: PublicKey, mint: PublicKey) -> TransactionInstruction: """Creates a transaction instruction to create an associated token account. Returns: The instruction to create the associated token account. """ associated_token_address = get_associated_token_address(owner, mint) return TransactionInstruction( keys=[ AccountMeta(pubkey=payer, is_signer=True, is_writable=True), AccountMeta(pubkey=associated_token_address, is_signer=False, is_writable=True), AccountMeta(pubkey=owner, is_signer=False, is_writable=False), AccountMeta(pubkey=mint, is_signer=False, is_writable=False), AccountMeta(pubkey=SYS_PROGRAM_ID, is_signer=False, is_writable=False), AccountMeta(pubkey=TOKEN_PROGRAM_ID, is_signer=False, is_writable=False), AccountMeta(pubkey=SYSVAR_RENT_PUBKEY, is_signer=False, is_writable=False), ], program_id=ASSOCIATED_TOKEN_PROGRAM_ID, )
def transfer(params: TransferParams) -> Transaction: """Generate a Transaction that transfers lamports from one account to another. >>> from solana.publickey import PublicKey >>> sender, reciever = PublicKey(1), PublicKey(2) >>> transfer_tx = transfer( ... TransferParams(from_pubkey=sender, to_pubkey=reciever, lamports=1000) ... ) >>> type(transfer_tx) <class 'solana.transaction.Transaction'> """ layout = SYSTEM_INSTRUCTION_LAYOUTS[_TRANSFER] data = encode_data(layout, params.lamports) txn = Transaction() txn.add( TransactionInstruction( keys=[ AccountMeta(pubkey=params.from_pubkey, is_signer=True, is_writable=True), AccountMeta(pubkey=params.to_pubkey, is_signer=False, is_writable=True), ], program_id=sys_program_id(), data=data, )) return txn
def revoke(params: RevokeParams) -> TransactionInstruction: """Creates a transaction instruction that revokes delegate authority for a given account. Example: >>> account, owner, token = PublicKey(1), PublicKey(2), PublicKey(3) >>> params = RevokeParams( ... account=account, owner=owner, program_id=token ... ) >>> type(revoke(params)) <class 'solana.transaction.TransactionInstruction'> Returns: The revoke instruction. """ data = INSTRUCTIONS_LAYOUT.build( dict(instruction_type=InstructionType.REVOKE, args=None)) keys = [ AccountMeta(pubkey=params.account, is_signer=False, is_writable=True) ] __add_signers(keys, params.owner, params.signers) return TransactionInstruction(keys=keys, program_id=params.program_id, data=data)
def make_resize_instruction(self, account, code_account_old, code_account_new, seed) -> TransactionInstruction: return TransactionInstruction( program_id=EVM_LOADER_ID, data=bytearray.fromhex("11") + bytes(seed), # 17- ResizeStorageAccount keys=[ AccountMeta(pubkey=PublicKey(account), is_signer=False, is_writable=True), (AccountMeta( pubkey=code_account_old, is_signer=False, is_writable=True) if code_account_old else AccountMeta( pubkey=PublicKey("11111111111111111111111111111111"), is_signer=False, is_writable=False)), AccountMeta(pubkey=code_account_new, is_signer=False, is_writable=True), AccountMeta(pubkey=self.operator_account, is_signer=True, is_writable=False) ], )
def nonce_advance(params: AdvanceNonceParams) -> TransactionInstruction: """Generate an instruction to advance the nonce in a Nonce account. Args: params: The advance nonce params Returns: The instruction to advance the nonce. """ data = SYSTEM_INSTRUCTIONS_LAYOUT.build( dict( instruction_type=InstructionType.ADVANCE_NONCE_ACCOUNT, args={}, )) return TransactionInstruction( keys=[ AccountMeta(pubkey=params.nonce_pubkey, is_signer=False, is_writable=True), AccountMeta(pubkey=sysvar.SYSVAR_RECENT_BLOCKHASHES_PUBKEY, is_signer=False, is_writable=False), AccountMeta(pubkey=params.authorized_pubkey, is_signer=True, is_writable=True), ], program_id=SYS_PROGRAM_ID, data=data, )
def create_account(params: CreateAccountParams) -> TransactionInstruction: """Generate an instruction that creates a new account. >>> from solana.publickey import PublicKey >>> from_account, new_account, program_id = PublicKey(1), PublicKey(2), PublicKey(3) >>> instruction = create_account( ... CreateAccountParams( ... from_pubkey=from_account, new_account_pubkey=new_account, ... lamports=1, space=1, program_id=program_id) ... ) >>> type(instruction) <class 'solana.transaction.TransactionInstruction'> """ data = SYSTEM_INSTRUCTIONS_LAYOUT.build( dict( instruction_type=InstructionType.CreateAccount, args=dict(lamports=params.lamports, space=params.space, program_id=bytes(params.program_id)), )) return TransactionInstruction( keys=[ AccountMeta(pubkey=params.from_pubkey, is_signer=True, is_writable=True), AccountMeta(pubkey=params.new_account_pubkey, is_signer=False, is_writable=True), ], program_id=SYS_PROGRAM_ID, data=data, )
def initialize(params: InitializeParams) -> TransactionInstruction: """Creates a transaction instruction to initialize a new stake.""" data = INSTRUCTIONS_LAYOUT.build( dict( instruction_type=InstructionType.INITIALIZE, args=dict( node=bytes(params.node), authorized_voter=bytes(params.authorized_voter), authorized_withdrawer=bytes(params.authorized_withdrawer), commission=params.commission, ), )) return TransactionInstruction( keys=[ AccountMeta(pubkey=params.vote, is_signer=False, is_writable=True), AccountMeta(pubkey=params.rent_sysvar or SYSVAR_RENT_PUBKEY, is_signer=False, is_writable=False), AccountMeta(pubkey=params.clock_sysvar or SYSVAR_CLOCK_PUBKEY, is_signer=False, is_writable=False), AccountMeta(pubkey=params.node, is_signer=True, is_writable=False), ], program_id=VOTE_PROGRAM_ID, data=data, )
def nonce_initialization( params: InitializeNonceParams) -> TransactionInstruction: """Generate an instruction to initialize a Nonce account. Args: params: The nonce initialization params. Returns: The instruction to initialize the nonce account. """ data = SYSTEM_INSTRUCTIONS_LAYOUT.build( dict( instruction_type=InstructionType.INITIALIZE_NONCE_ACCOUNT, args=dict(authorized=bytes(params.authorized_pubkey), ), )) return TransactionInstruction( keys=[ AccountMeta(pubkey=params.nonce_pubkey, is_signer=True, is_writable=True), AccountMeta(pubkey=sysvar.SYSVAR_RECENT_BLOCKHASHES_PUBKEY, is_signer=False, is_writable=False), AccountMeta(pubkey=sysvar.SYSVAR_RENT_PUBKEY, is_signer=False, is_writable=False), ], program_id=SYS_PROGRAM_ID, data=data, )
def __mint_to_instruction(params: Union[MintToParams, MintTo2Params], data: Any) -> TransactionInstruction: keys = [ AccountMeta(pubkey=params.mint, is_signer=False, is_writable=True), AccountMeta(pubkey=params.dest, is_signer=False, is_writable=True), ] __add_signers(keys, params.mint_authority, params.signers) return TransactionInstruction(keys=keys, program_id=params.program_id, data=data)