|
6 | 6 |
|
7 | 7 | from solana.publickey import PublicKey
|
8 | 8 | from solana.transaction import AccountMeta, TransactionInstruction
|
| 9 | +from solana.system_program import SYS_PROGRAM_ID |
| 10 | +from solana.sysvar import SYSVAR_CLOCK_PUBKEY, SYSVAR_RENT_PUBKEY, SYSVAR_STAKE_HISTORY_PUBKEY |
9 | 11 | from spl.token.constants import TOKEN_PROGRAM_ID
|
10 | 12 |
|
| 13 | +from stake.constants import STAKE_PROGRAM_ID, SYSVAR_STAKE_CONFIG_ID |
| 14 | +from stake_pool.constants import find_stake_program_address, find_transient_stake_program_address |
| 15 | +from stake_pool.constants import find_withdraw_authority_program_address |
| 16 | +from stake_pool.constants import STAKE_POOL_PROGRAM_ID |
11 | 17 | from stake_pool.state import Fee, FEE_LAYOUT
|
12 | 18 |
|
13 | 19 |
|
@@ -478,3 +484,115 @@ def initialize(params: InitializeParams) -> TransactionInstruction:
|
478 | 484 | program_id=params.program_id,
|
479 | 485 | data=data,
|
480 | 486 | )
|
| 487 | + |
| 488 | + |
| 489 | +def add_validator_to_pool(params: AddValidatorToPoolParams) -> TransactionInstruction: |
| 490 | + return TransactionInstruction( |
| 491 | + keys=[ |
| 492 | + AccountMeta(pubkey=params.stake_pool, is_signer=False, is_writable=False), |
| 493 | + AccountMeta(pubkey=params.staker, is_signer=True, is_writable=False), |
| 494 | + AccountMeta(pubkey=params.funding_account, is_signer=True, is_writable=True), |
| 495 | + AccountMeta(pubkey=params.withdraw_authority, is_signer=False, is_writable=False), |
| 496 | + AccountMeta(pubkey=params.validator_list, is_signer=False, is_writable=True), |
| 497 | + AccountMeta(pubkey=params.validator_stake, is_signer=False, is_writable=True), |
| 498 | + AccountMeta(pubkey=params.validator_vote, is_signer=False, is_writable=False), |
| 499 | + AccountMeta(pubkey=params.rent_sysvar, is_signer=False, is_writable=False), |
| 500 | + AccountMeta(pubkey=params.clock_sysvar, is_signer=False, is_writable=False), |
| 501 | + AccountMeta(pubkey=params.stake_history_sysvar, is_signer=False, is_writable=False), |
| 502 | + AccountMeta(pubkey=params.stake_config_sysvar, is_signer=False, is_writable=False), |
| 503 | + AccountMeta(pubkey=params.system_program_id, is_signer=False, is_writable=False), |
| 504 | + AccountMeta(pubkey=params.stake_program_id, is_signer=False, is_writable=False), |
| 505 | + ], |
| 506 | + program_id=params.program_id, |
| 507 | + data=INSTRUCTIONS_LAYOUT.build( |
| 508 | + dict( |
| 509 | + instruction_type=InstructionType.ADD_VALIDATOR_TO_POOL, |
| 510 | + args=None |
| 511 | + ) |
| 512 | + ) |
| 513 | + ) |
| 514 | + |
| 515 | + |
| 516 | +def add_validator_to_pool_with_vote( |
| 517 | + program_id: PublicKey, |
| 518 | + stake_pool: PublicKey, |
| 519 | + staker: PublicKey, |
| 520 | + validator_list: PublicKey, |
| 521 | + funder: PublicKey, |
| 522 | + validator: PublicKey |
| 523 | +) -> TransactionInstruction: |
| 524 | + (withdraw_authority, seed) = find_withdraw_authority_program_address(program_id, stake_pool) |
| 525 | + (validator_stake, seed) = find_stake_program_address(program_id, validator, stake_pool) |
| 526 | + return add_validator_to_pool( |
| 527 | + AddValidatorToPoolParams( |
| 528 | + program_id=STAKE_POOL_PROGRAM_ID, |
| 529 | + stake_pool=stake_pool, |
| 530 | + staker=staker, |
| 531 | + funding_account=funder, |
| 532 | + withdraw_authority=withdraw_authority, |
| 533 | + validator_list=validator_list, |
| 534 | + validator_stake=validator_stake, |
| 535 | + validator_vote=validator, |
| 536 | + rent_sysvar=SYSVAR_RENT_PUBKEY, |
| 537 | + clock_sysvar=SYSVAR_CLOCK_PUBKEY, |
| 538 | + stake_history_sysvar=SYSVAR_STAKE_HISTORY_PUBKEY, |
| 539 | + stake_config_sysvar=SYSVAR_STAKE_CONFIG_ID, |
| 540 | + system_program_id=SYS_PROGRAM_ID, |
| 541 | + stake_program_id=STAKE_PROGRAM_ID, |
| 542 | + ) |
| 543 | + ) |
| 544 | + |
| 545 | + |
| 546 | +def remove_validator_from_pool(params: RemoveValidatorFromPoolParams) -> TransactionInstruction: |
| 547 | + return TransactionInstruction( |
| 548 | + keys=[ |
| 549 | + AccountMeta(pubkey=params.stake_pool, is_signer=False, is_writable=False), |
| 550 | + AccountMeta(pubkey=params.staker, is_signer=True, is_writable=False), |
| 551 | + AccountMeta(pubkey=params.withdraw_authority, is_signer=False, is_writable=False), |
| 552 | + AccountMeta(pubkey=params.new_stake_authority, is_signer=False, is_writable=True), |
| 553 | + AccountMeta(pubkey=params.validator_list, is_signer=False, is_writable=True), |
| 554 | + AccountMeta(pubkey=params.validator_stake, is_signer=False, is_writable=True), |
| 555 | + AccountMeta(pubkey=params.transient_stake, is_signer=False, is_writable=False), |
| 556 | + AccountMeta(pubkey=params.destination_stake, is_signer=False, is_writable=True), |
| 557 | + AccountMeta(pubkey=params.clock_sysvar, is_signer=False, is_writable=False), |
| 558 | + AccountMeta(pubkey=params.stake_program_id, is_signer=False, is_writable=False), |
| 559 | + ], |
| 560 | + program_id=params.program_id, |
| 561 | + data=INSTRUCTIONS_LAYOUT.build( |
| 562 | + dict( |
| 563 | + instruction_type=InstructionType.REMOVE_VALIDATOR_FROM_POOL, |
| 564 | + args=None |
| 565 | + ) |
| 566 | + ) |
| 567 | + ) |
| 568 | + |
| 569 | + |
| 570 | +def remove_validator_from_pool_with_vote( |
| 571 | + program_id: PublicKey, |
| 572 | + stake_pool: PublicKey, |
| 573 | + staker: PublicKey, |
| 574 | + validator_list: PublicKey, |
| 575 | + new_stake_authority: PublicKey, |
| 576 | + validator: PublicKey, |
| 577 | + transient_stake_seed: int, |
| 578 | + destination_stake: PublicKey, |
| 579 | +) -> TransactionInstruction: |
| 580 | + (withdraw_authority, seed) = find_withdraw_authority_program_address(program_id, stake_pool) |
| 581 | + (validator_stake, seed) = find_stake_program_address(program_id, validator, stake_pool) |
| 582 | + (transient_stake, seed) = find_transient_stake_program_address( |
| 583 | + program_id, validator, stake_pool, transient_stake_seed) |
| 584 | + return remove_validator_from_pool( |
| 585 | + RemoveValidatorFromPoolParams( |
| 586 | + program_id=STAKE_POOL_PROGRAM_ID, |
| 587 | + stake_pool=stake_pool, |
| 588 | + staker=staker, |
| 589 | + withdraw_authority=withdraw_authority, |
| 590 | + new_stake_authority=new_stake_authority, |
| 591 | + validator_list=validator_list, |
| 592 | + validator_stake=validator_stake, |
| 593 | + transient_stake=transient_stake, |
| 594 | + destination_stake=destination_stake, |
| 595 | + clock_sysvar=SYSVAR_CLOCK_PUBKEY, |
| 596 | + stake_program_id=STAKE_PROGRAM_ID, |
| 597 | + ) |
| 598 | + ) |
0 commit comments