TokenRegister: Fix anchor seed derivation

It likes names constant, but not constant literals.
This commit is contained in:
Christian Kamm 2022-08-04 08:25:41 +02:00 committed by microwavedcola1
parent cc17f2a95a
commit 22080fdcc1
2 changed files with 8 additions and 4 deletions

View File

@ -9,6 +9,8 @@ use crate::util::fill16_from_str;
pub const INDEX_START: I80F48 = I80F48!(1_000_000);
const FIRST_BANK_NUM: u32 = 0;
#[derive(Accounts)]
#[instruction(token_index: TokenIndex)]
pub struct TokenRegister<'info> {
@ -23,7 +25,7 @@ pub struct TokenRegister<'info> {
#[account(
init,
// using the token_index in this seed guards against reusing it
seeds = [group.key().as_ref(), b"Bank".as_ref(), &token_index.to_le_bytes(), &0u32.to_le_bytes()],
seeds = [group.key().as_ref(), b"Bank".as_ref(), &token_index.to_le_bytes(), &FIRST_BANK_NUM.to_le_bytes()],
bump,
payer = payer,
space = 8 + std::mem::size_of::<Bank>(),
@ -32,7 +34,7 @@ pub struct TokenRegister<'info> {
#[account(
init,
seeds = [group.key().as_ref(), b"Vault".as_ref(), &token_index.to_le_bytes(), &0u32.to_le_bytes()],
seeds = [group.key().as_ref(), b"Vault".as_ref(), &token_index.to_le_bytes(), &FIRST_BANK_NUM.to_le_bytes()],
bump,
token::authority = group,
token::mint = mint,

View File

@ -7,6 +7,8 @@ use crate::instructions::INDEX_START;
use crate::state::*;
use crate::util::fill16_from_str;
const FIRST_BANK_NUM: u32 = 0;
#[derive(Accounts)]
#[instruction(token_index: TokenIndex)]
pub struct TokenRegisterTrustless<'info> {
@ -21,7 +23,7 @@ pub struct TokenRegisterTrustless<'info> {
#[account(
init,
// using the token_index in this seed guards against reusing it
seeds = [group.key().as_ref(), b"Bank".as_ref(), &token_index.to_le_bytes(), &0u32.to_le_bytes()],
seeds = [group.key().as_ref(), b"Bank".as_ref(), &token_index.to_le_bytes(), &FIRST_BANK_NUM.to_le_bytes()],
bump,
payer = payer,
space = 8 + std::mem::size_of::<Bank>(),
@ -30,7 +32,7 @@ pub struct TokenRegisterTrustless<'info> {
#[account(
init,
seeds = [group.key().as_ref(), b"Vault".as_ref(), &token_index.to_le_bytes(), &0u32.to_le_bytes()],
seeds = [group.key().as_ref(), b"Vault".as_ref(), &token_index.to_le_bytes(), &FIRST_BANK_NUM.to_le_bytes()],
bump,
token::authority = group,
token::mint = mint,