Skip to main content
added 36 characters in body
Source Link
Jimii
  • 7.7k
  • 1
  • 8
  • 22

use crate::state::; use crate::error::; use std::str::FromStr; use anchor_lang::prelude::*; use switchboard_v2::AggregatorAccountData;

pub fn withdraw_handler(ctx: Context) -> Result<()> { let feed: &! = &ctx.accounts.feed_aggregator.load()?; let escrow_state: &Account = &ctx.accounts.escrow_account;

// get result
let val: f64 = feed.get_result()?.try_into()?;

// check whether the feed has been updated in the last 300 seconds
feed.check_staleness(Clock::get().unwrap().unix_timestamp, 300)
.map_err(|_| error!(EscrowErrorCode::StaleFeed))?;

msg!("Current feed result is {}!", val);
msg!("Unlock price is {}", escrow_state.unlock_price);

if val < escrow_state.unlock_price as f64 {
    return Err(EscrowErrorCode::SolPriceAboveUnlockPrice.into())
}

// 'Transfer: `from` must not carry data'
**escrow_state.to_account_info().try_borrow_mut_lamports()? = escrow_state
    .to_account_info()
    .lamports()
    .checked_sub(escrow_state.escrow_amount)
    .ok_or(ProgramError::InvalidArgument)?;

**ctx.accounts.user.to_account_info().try_borrow_mut_lamports()? = ctx.accounts.user
    .to_account_info()
    .lamports()
    .checked_add(escrow_state.escrow_amount)
    .ok_or(ProgramError::InvalidArgument)?;

Ok(())

}

[derive(Accounts)] pub struct Withdraw<'info> { // user accounts [account(mut)] pub user: Signer<'info>, // escrow account [account( mut, seeds = [ESCROW_SEED, user.key().as_ref()], bump, close = user )] pub escrow_account: Account<'info, EscrowState>, // Switchboard SOL feed aggregator [account( address = Pubkey::from_str(SOL_USDC_FEED).unwrap(), zero, )] pub feed_aggregator: AccountLoader<'info, AggregatorAccountData>, pub system_program: Program<'info, System>, }

use crate::state::*;
use crate::error::*;
use std::str::FromStr;
use anchor_lang::prelude::*;
use switchboard_v2::AggregatorAccountData;


 
pub fn withdraw_handler(ctx: Context<Withdraw>) -> Result<()> {
    let feed: &! = &ctx.accounts.feed_aggregator.load()?;
    let escrow_state: &Account<EscrowState> = &ctx.accounts.escrow_account;
 
    // get result
    let val: f64 = feed.get_result()?.try_into()?;
 
    // check whether the feed has been updated in the last 300 seconds
    feed.check_staleness(Clock::get().unwrap().unix_timestamp, 300)
    .map_err(|_| error!(EscrowErrorCode::StaleFeed))?;
 
    msg!("Current feed result is {}!", val);
    msg!("Unlock price is {}", escrow_state.unlock_price);
 
    if val < escrow_state.unlock_price as f64 {
        return Err(EscrowErrorCode::SolPriceAboveUnlockPrice.into())
    }
 
    // 'Transfer: `from` must not carry data'
    **escrow_state.to_account_info().try_borrow_mut_lamports()? = escrow_state
        .to_account_info()
        .lamports()
        .checked_sub(escrow_state.escrow_amount)
        .ok_or(ProgramError::InvalidArgument)?;
 
    **ctx.accounts.user.to_account_info().try_borrow_mut_lamports()? = ctx.accounts.user
        .to_account_info()
        .lamports()
        .checked_add(escrow_state.escrow_amount)
        .ok_or(ProgramError::InvalidArgument)?;
 
    Ok(())
}
 
[derive(Accounts)]
pub struct Withdraw<'info> {
    // user accounts
    [account(mut)]
    pub user: Signer<'info>,
    // escrow account
    [account(
        mut,
        seeds = [ESCROW_SEED, user.key().as_ref()],
        bump,
        close = user
    )]
    pub escrow_account: Account<'info, EscrowState>,
    // Switchboard SOL feed aggregator
    [account(
        address = Pubkey::from_str(SOL_USDC_FEED).unwrap(),
        zero,
    )]
    pub feed_aggregator: AccountLoader<'info, AggregatorAccountData>,
    pub system_program: Program<'info, System>,
}

##II am working through the oraclesOracles and the oracle networks course, and after completing all the code, i'mI'm getting the error below:

the trait bound AggregatorAccountData: ZeroCopy is not satisfied.

the trait bound `AggregatorAccountData: ZeroCopy` is not satisfied.

#[account( address = Pubkey::from_str(SOL_USDC_FEED).unwrap(), zero, )]

  #[account(
        address = Pubkey::from_str(SOL_USDC_FEED).unwrap(),
        zero,
    )]

Any ideas? thanks..##

use crate::state::; use crate::error::; use std::str::FromStr; use anchor_lang::prelude::*; use switchboard_v2::AggregatorAccountData;

pub fn withdraw_handler(ctx: Context) -> Result<()> { let feed: &! = &ctx.accounts.feed_aggregator.load()?; let escrow_state: &Account = &ctx.accounts.escrow_account;

// get result
let val: f64 = feed.get_result()?.try_into()?;

// check whether the feed has been updated in the last 300 seconds
feed.check_staleness(Clock::get().unwrap().unix_timestamp, 300)
.map_err(|_| error!(EscrowErrorCode::StaleFeed))?;

msg!("Current feed result is {}!", val);
msg!("Unlock price is {}", escrow_state.unlock_price);

if val < escrow_state.unlock_price as f64 {
    return Err(EscrowErrorCode::SolPriceAboveUnlockPrice.into())
}

// 'Transfer: `from` must not carry data'
**escrow_state.to_account_info().try_borrow_mut_lamports()? = escrow_state
    .to_account_info()
    .lamports()
    .checked_sub(escrow_state.escrow_amount)
    .ok_or(ProgramError::InvalidArgument)?;

**ctx.accounts.user.to_account_info().try_borrow_mut_lamports()? = ctx.accounts.user
    .to_account_info()
    .lamports()
    .checked_add(escrow_state.escrow_amount)
    .ok_or(ProgramError::InvalidArgument)?;

Ok(())

}

[derive(Accounts)] pub struct Withdraw<'info> { // user accounts [account(mut)] pub user: Signer<'info>, // escrow account [account( mut, seeds = [ESCROW_SEED, user.key().as_ref()], bump, close = user )] pub escrow_account: Account<'info, EscrowState>, // Switchboard SOL feed aggregator [account( address = Pubkey::from_str(SOL_USDC_FEED).unwrap(), zero, )] pub feed_aggregator: AccountLoader<'info, AggregatorAccountData>, pub system_program: Program<'info, System>, }

##I am working through the oracles and the oracle networks course, and after completing all the code, i'm getting the error below:

the trait bound AggregatorAccountData: ZeroCopy is not satisfied.

#[account( address = Pubkey::from_str(SOL_USDC_FEED).unwrap(), zero, )]

Any ideas? thanks..##

use crate::state::*;
use crate::error::*;
use std::str::FromStr;
use anchor_lang::prelude::*;
use switchboard_v2::AggregatorAccountData;


 
pub fn withdraw_handler(ctx: Context<Withdraw>) -> Result<()> {
    let feed: &! = &ctx.accounts.feed_aggregator.load()?;
    let escrow_state: &Account<EscrowState> = &ctx.accounts.escrow_account;
 
    // get result
    let val: f64 = feed.get_result()?.try_into()?;
 
    // check whether the feed has been updated in the last 300 seconds
    feed.check_staleness(Clock::get().unwrap().unix_timestamp, 300)
    .map_err(|_| error!(EscrowErrorCode::StaleFeed))?;
 
    msg!("Current feed result is {}!", val);
    msg!("Unlock price is {}", escrow_state.unlock_price);
 
    if val < escrow_state.unlock_price as f64 {
        return Err(EscrowErrorCode::SolPriceAboveUnlockPrice.into())
    }
 
    // 'Transfer: `from` must not carry data'
    **escrow_state.to_account_info().try_borrow_mut_lamports()? = escrow_state
        .to_account_info()
        .lamports()
        .checked_sub(escrow_state.escrow_amount)
        .ok_or(ProgramError::InvalidArgument)?;
 
    **ctx.accounts.user.to_account_info().try_borrow_mut_lamports()? = ctx.accounts.user
        .to_account_info()
        .lamports()
        .checked_add(escrow_state.escrow_amount)
        .ok_or(ProgramError::InvalidArgument)?;
 
    Ok(())
}
 
[derive(Accounts)]
pub struct Withdraw<'info> {
    // user accounts
    [account(mut)]
    pub user: Signer<'info>,
    // escrow account
    [account(
        mut,
        seeds = [ESCROW_SEED, user.key().as_ref()],
        bump,
        close = user
    )]
    pub escrow_account: Account<'info, EscrowState>,
    // Switchboard SOL feed aggregator
    [account(
        address = Pubkey::from_str(SOL_USDC_FEED).unwrap(),
        zero,
    )]
    pub feed_aggregator: AccountLoader<'info, AggregatorAccountData>,
    pub system_program: Program<'info, System>,
}

I am working through the Oracles and the oracle networks course, and after completing all the code, I'm getting the error below:

the trait bound `AggregatorAccountData: ZeroCopy` is not satisfied.
  #[account(
        address = Pubkey::from_str(SOL_USDC_FEED).unwrap(),
        zero,
    )]

Any ideas? thanks..

added 1 character in body
Source Link

use crate::state::; use crate::error::; use std::str::FromStr; use anchor_lang::prelude::*; use switchboard_v2::AggregatorAccountData;

pub fn withdraw_handler(ctx: Context) -> Result<()> { let feed: &! = &ctx.accounts.feed_aggregator.load()?; let escrow_state: &Account = &ctx.accounts.escrow_account;

// get result
let val: f64 = feed.get_result()?.try_into()?;

// check whether the feed has been updated in the last 300 seconds
feed.check_staleness(Clock::get().unwrap().unix_timestamp, 300)
.map_err(|_| error!(EscrowErrorCode::StaleFeed))?;

msg!("Current feed result is {}!", val);
msg!("Unlock price is {}", escrow_state.unlock_price);

if val < escrow_state.unlock_price as f64 {
    return Err(EscrowErrorCode::SolPriceAboveUnlockPrice.into())
}

// 'Transfer: `from` must not carry data'
**escrow_state.to_account_info().try_borrow_mut_lamports()? = escrow_state
    .to_account_info()
    .lamports()
    .checked_sub(escrow_state.escrow_amount)
    .ok_or(ProgramError::InvalidArgument)?;

**ctx.accounts.user.to_account_info().try_borrow_mut_lamports()? = ctx.accounts.user
    .to_account_info()
    .lamports()
    .checked_add(escrow_state.escrow_amount)
    .ok_or(ProgramError::InvalidArgument)?;

Ok(())

}

#[derive[derive(Accounts)] pub struct Withdraw<'info> { // user accounts #[account[account(mut)] pub user: Signer<'info>, // escrow account #[account[account( mut, seeds = [ESCROW_SEED, user.key().as_ref()], bump, close = user )] pub escrow_account: Account<'info, EscrowState>, // Switchboard SOL feed aggregator #[account[account( address = Pubkey::from_str(SOL_USDC_FEED).unwrap(), zero, )] pub feed_aggregator: AccountLoader<'info, AggregatorAccountData>, pub system_program: Program<'info, System>, }

##I am working through the oracles and the oracle networks course, and after completing all the code, imi'm getting the error below:

the trait bound AggregatorAccountData: ZeroCopy is not satisfied.

I have tried adding the zero property to enable ZeroCopy but that does not seem to work:

#[account( address = Pubkey::from_str(SOL_USDC_FEED).unwrap(), zero, )]

Any ideas? thanks..##

use crate::state::; use crate::error::; use std::str::FromStr; use anchor_lang::prelude::*; use switchboard_v2::AggregatorAccountData;

pub fn withdraw_handler(ctx: Context) -> Result<()> { let feed: &! = &ctx.accounts.feed_aggregator.load()?; let escrow_state: &Account = &ctx.accounts.escrow_account;

// get result
let val: f64 = feed.get_result()?.try_into()?;

// check whether the feed has been updated in the last 300 seconds
feed.check_staleness(Clock::get().unwrap().unix_timestamp, 300)
.map_err(|_| error!(EscrowErrorCode::StaleFeed))?;

msg!("Current feed result is {}!", val);
msg!("Unlock price is {}", escrow_state.unlock_price);

if val < escrow_state.unlock_price as f64 {
    return Err(EscrowErrorCode::SolPriceAboveUnlockPrice.into())
}

// 'Transfer: `from` must not carry data'
**escrow_state.to_account_info().try_borrow_mut_lamports()? = escrow_state
    .to_account_info()
    .lamports()
    .checked_sub(escrow_state.escrow_amount)
    .ok_or(ProgramError::InvalidArgument)?;

**ctx.accounts.user.to_account_info().try_borrow_mut_lamports()? = ctx.accounts.user
    .to_account_info()
    .lamports()
    .checked_add(escrow_state.escrow_amount)
    .ok_or(ProgramError::InvalidArgument)?;

Ok(())

}

#[derive(Accounts)] pub struct Withdraw<'info> { // user accounts #[account(mut)] pub user: Signer<'info>, // escrow account #[account( mut, seeds = [ESCROW_SEED, user.key().as_ref()], bump, close = user )] pub escrow_account: Account<'info, EscrowState>, // Switchboard SOL feed aggregator #[account( address = Pubkey::from_str(SOL_USDC_FEED).unwrap(), zero, )] pub feed_aggregator: AccountLoader<'info, AggregatorAccountData>, pub system_program: Program<'info, System>, }

##I am working through the oracles and oracle networks course, and after completing all the code, im getting the error below:

the trait bound AggregatorAccountData: ZeroCopy is not satisfied.

I have tried adding the zero property to enable ZeroCopy but that does not seem to work:

#[account( address = Pubkey::from_str(SOL_USDC_FEED).unwrap(), zero, )]

Any ideas? thanks..##

use crate::state::; use crate::error::; use std::str::FromStr; use anchor_lang::prelude::*; use switchboard_v2::AggregatorAccountData;

pub fn withdraw_handler(ctx: Context) -> Result<()> { let feed: &! = &ctx.accounts.feed_aggregator.load()?; let escrow_state: &Account = &ctx.accounts.escrow_account;

// get result
let val: f64 = feed.get_result()?.try_into()?;

// check whether the feed has been updated in the last 300 seconds
feed.check_staleness(Clock::get().unwrap().unix_timestamp, 300)
.map_err(|_| error!(EscrowErrorCode::StaleFeed))?;

msg!("Current feed result is {}!", val);
msg!("Unlock price is {}", escrow_state.unlock_price);

if val < escrow_state.unlock_price as f64 {
    return Err(EscrowErrorCode::SolPriceAboveUnlockPrice.into())
}

// 'Transfer: `from` must not carry data'
**escrow_state.to_account_info().try_borrow_mut_lamports()? = escrow_state
    .to_account_info()
    .lamports()
    .checked_sub(escrow_state.escrow_amount)
    .ok_or(ProgramError::InvalidArgument)?;

**ctx.accounts.user.to_account_info().try_borrow_mut_lamports()? = ctx.accounts.user
    .to_account_info()
    .lamports()
    .checked_add(escrow_state.escrow_amount)
    .ok_or(ProgramError::InvalidArgument)?;

Ok(())

}

[derive(Accounts)] pub struct Withdraw<'info> { // user accounts [account(mut)] pub user: Signer<'info>, // escrow account [account( mut, seeds = [ESCROW_SEED, user.key().as_ref()], bump, close = user )] pub escrow_account: Account<'info, EscrowState>, // Switchboard SOL feed aggregator [account( address = Pubkey::from_str(SOL_USDC_FEED).unwrap(), zero, )] pub feed_aggregator: AccountLoader<'info, AggregatorAccountData>, pub system_program: Program<'info, System>, }

##I am working through the oracles and the oracle networks course, and after completing all the code, i'm getting the error below:

the trait bound AggregatorAccountData: ZeroCopy is not satisfied.

I have tried adding the zero property to enable ZeroCopy but that does not seem to work:

#[account( address = Pubkey::from_str(SOL_USDC_FEED).unwrap(), zero, )]

Any ideas? thanks..##

added 4 characters in body
Source Link

use crate::state::; use crate::error::; use std::str::FromStr; use anchor_lang::prelude::*; use switchboard_v2::AggregatorAccountData;

pub fn withdraw_handler(ctx: Context) -> Result<()> { let feed: &! = &ctx.accounts.feed_aggregator.load()?; let escrow_state: &Account = &ctx.accounts.escrow_account;

// get result
let val: f64 = feed.get_result()?.try_into()?;

// check whether the feed has been updated in the last 300 seconds
feed.check_staleness(Clock::get().unwrap().unix_timestamp, 300)
.map_err(|_| error!(EscrowErrorCode::StaleFeed))?;

msg!("Current feed result is {}!", val);
msg!("Unlock price is {}", escrow_state.unlock_price);

if val < escrow_state.unlock_price as f64 {
    return Err(EscrowErrorCode::SolPriceAboveUnlockPrice.into())
}

// 'Transfer: `from` must not carry data'
**escrow_state.to_account_info().try_borrow_mut_lamports()? = escrow_state
    .to_account_info()
    .lamports()
    .checked_sub(escrow_state.escrow_amount)
    .ok_or(ProgramError::InvalidArgument)?;

**ctx.accounts.user.to_account_info().try_borrow_mut_lamports()? = ctx.accounts.user
    .to_account_info()
    .lamports()
    .checked_add(escrow_state.escrow_amount)
    .ok_or(ProgramError::InvalidArgument)?;

Ok(())

}

#[derive(Accounts)] pub struct Withdraw<'info> { // user accounts #[account(mut)] pub user: Signer<'info>, // escrow account #[account( mut, seeds = [ESCROW_SEED, user.key().as_ref()], bump, close = user )] pub escrow_account: Account<'info, EscrowState>, // Switchboard SOL feed aggregator #[account( address = Pubkey::from_str(SOL_USDC_FEED).unwrap(), zero, )] pub feed_aggregator: AccountLoader<'info, AggregatorAccountData>, pub system_program: Program<'info, System>, }

I##I am working through the oracles and oracle networks course, and after completing all the code, im getting the error below:

the trait bound AggregatorAccountData: ZeroCopy is not satisfied.

I have tried adding the zero property to enable ZeroCopy but that does not seem to work:

#[account( address = Pubkey::from_str(SOL_USDC_FEED).unwrap(), zero, )]

Any ideas? thanks..##

use crate::state::; use crate::error::; use std::str::FromStr; use anchor_lang::prelude::*; use switchboard_v2::AggregatorAccountData;

pub fn withdraw_handler(ctx: Context) -> Result<()> { let feed: &! = &ctx.accounts.feed_aggregator.load()?; let escrow_state: &Account = &ctx.accounts.escrow_account;

// get result
let val: f64 = feed.get_result()?.try_into()?;

// check whether the feed has been updated in the last 300 seconds
feed.check_staleness(Clock::get().unwrap().unix_timestamp, 300)
.map_err(|_| error!(EscrowErrorCode::StaleFeed))?;

msg!("Current feed result is {}!", val);
msg!("Unlock price is {}", escrow_state.unlock_price);

if val < escrow_state.unlock_price as f64 {
    return Err(EscrowErrorCode::SolPriceAboveUnlockPrice.into())
}

// 'Transfer: `from` must not carry data'
**escrow_state.to_account_info().try_borrow_mut_lamports()? = escrow_state
    .to_account_info()
    .lamports()
    .checked_sub(escrow_state.escrow_amount)
    .ok_or(ProgramError::InvalidArgument)?;

**ctx.accounts.user.to_account_info().try_borrow_mut_lamports()? = ctx.accounts.user
    .to_account_info()
    .lamports()
    .checked_add(escrow_state.escrow_amount)
    .ok_or(ProgramError::InvalidArgument)?;

Ok(())

}

#[derive(Accounts)] pub struct Withdraw<'info> { // user accounts #[account(mut)] pub user: Signer<'info>, // escrow account #[account( mut, seeds = [ESCROW_SEED, user.key().as_ref()], bump, close = user )] pub escrow_account: Account<'info, EscrowState>, // Switchboard SOL feed aggregator #[account( address = Pubkey::from_str(SOL_USDC_FEED).unwrap(), zero, )] pub feed_aggregator: AccountLoader<'info, AggregatorAccountData>, pub system_program: Program<'info, System>, }

I am working through the oracles and oracle networks course, and after completing all the code, im getting the error below:

the trait bound AggregatorAccountData: ZeroCopy is not satisfied.

I have tried adding the zero property to enable ZeroCopy but that does not seem to work:

#[account( address = Pubkey::from_str(SOL_USDC_FEED).unwrap(), zero, )]

Any ideas? thanks..

use crate::state::; use crate::error::; use std::str::FromStr; use anchor_lang::prelude::*; use switchboard_v2::AggregatorAccountData;

pub fn withdraw_handler(ctx: Context) -> Result<()> { let feed: &! = &ctx.accounts.feed_aggregator.load()?; let escrow_state: &Account = &ctx.accounts.escrow_account;

// get result
let val: f64 = feed.get_result()?.try_into()?;

// check whether the feed has been updated in the last 300 seconds
feed.check_staleness(Clock::get().unwrap().unix_timestamp, 300)
.map_err(|_| error!(EscrowErrorCode::StaleFeed))?;

msg!("Current feed result is {}!", val);
msg!("Unlock price is {}", escrow_state.unlock_price);

if val < escrow_state.unlock_price as f64 {
    return Err(EscrowErrorCode::SolPriceAboveUnlockPrice.into())
}

// 'Transfer: `from` must not carry data'
**escrow_state.to_account_info().try_borrow_mut_lamports()? = escrow_state
    .to_account_info()
    .lamports()
    .checked_sub(escrow_state.escrow_amount)
    .ok_or(ProgramError::InvalidArgument)?;

**ctx.accounts.user.to_account_info().try_borrow_mut_lamports()? = ctx.accounts.user
    .to_account_info()
    .lamports()
    .checked_add(escrow_state.escrow_amount)
    .ok_or(ProgramError::InvalidArgument)?;

Ok(())

}

#[derive(Accounts)] pub struct Withdraw<'info> { // user accounts #[account(mut)] pub user: Signer<'info>, // escrow account #[account( mut, seeds = [ESCROW_SEED, user.key().as_ref()], bump, close = user )] pub escrow_account: Account<'info, EscrowState>, // Switchboard SOL feed aggregator #[account( address = Pubkey::from_str(SOL_USDC_FEED).unwrap(), zero, )] pub feed_aggregator: AccountLoader<'info, AggregatorAccountData>, pub system_program: Program<'info, System>, }

##I am working through the oracles and oracle networks course, and after completing all the code, im getting the error below:

the trait bound AggregatorAccountData: ZeroCopy is not satisfied.

I have tried adding the zero property to enable ZeroCopy but that does not seem to work:

#[account( address = Pubkey::from_str(SOL_USDC_FEED).unwrap(), zero, )]

Any ideas? thanks..##

Source Link
Loading