Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,11 @@ EVM_PRIVATE_KEY=your_private_key_here
EVM_RPC_URL=your_rpc_url_here

AVAX_RPC_URL=https://your-avalanche-fuji-rpc-url
SOLANA_RPC_URL=https://your-solana-devnet-rpc-url
SOLANA_RPC_URL=https://your-solana-devnet-rpc-url

# If you've already deployed contracts to devnet and
# you'd like to run the typescript tests directly via
# yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/**/*.ts
#
# ANCHOR_PROVIDER_URL=https://your-solana-devnet-rpc-url
# ANCHOR_WALLET=/Users/path/to/local/wallet/.config/solana/id.json
17 changes: 9 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ pappas99@Pappas solana-starter-kit % yarn read-data
301331000000
```

### Testing
### Testing Data Feeds Contracts

You can execute the [integration test](./tests/chainlink-solana-demo-int-test.ts) with the following command

Expand All @@ -267,6 +267,14 @@ Price Is: 105.52
✨ Done in 10.49s.
```

If you'd like to run the test after initial deployment of the contracts, you can run the tests directly via yarn.

```
yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/**/*.ts
```

You will be asked to provide anchor environment variables. See `.env.example` for details.

## Cross-Chain Interoperability Protocol (CCIP)

This repository also includes comprehensive scripts and libraries for **Chainlink CCIP**, enabling cross-chain communication between Solana and EVM-compatible blockchains.
Expand Down
4 changes: 2 additions & 2 deletions programs/chainlink_solana_demo/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "chainlink-solana-demo"
version = "0.1.0"
version = "0.2.0"
description = "Created with Anchor"
edition = "2018"

Expand All @@ -18,4 +18,4 @@ idl-build = ["anchor-lang/idl-build"]

[dependencies]
anchor-lang = "0.31.1"
chainlink_solana = { git = "https://github.com/smartcontractkit/chainlink-solana", branch = "solana-2.1" }
chainlink_solana = "2.0.0"
37 changes: 20 additions & 17 deletions programs/chainlink_solana_demo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,29 @@ declare_id!("CnrgKig7fjYfWkxNVWkNwNMziuarP1Aiu7MkJuXRWEY5");
#[program]
pub mod chainlink_solana_demo {

use chainlink_solana::Round;
use chainlink_solana::v2::read_feed_v2;

use super::*;
pub fn execute(
ctx: Context<Execute>
) -> Result<()> {
let round: Round = chainlink::latest_round_data(
ctx.accounts.chainlink_program.to_account_info(),
ctx.accounts.chainlink_feed.to_account_info(),
)?;
let feed = &ctx.accounts.chainlink_feed;
let result = read_feed_v2(
feed.try_borrow_data()?,
feed.owner.to_bytes()
).map_err(|_| DemoError::ReadError)?;

let description: String = chainlink::description(
ctx.accounts.chainlink_program.to_account_info(),
ctx.accounts.chainlink_feed.to_account_info(),
)?;

let decimals: u8 = chainlink::decimals(
ctx.accounts.chainlink_program.to_account_info(),
ctx.accounts.chainlink_feed.to_account_info())?;
let round = result.latest_round_data().ok_or(DemoError::RoundDataMissing)?;

let description = result.description();
let decimals = result.decimals();

let decimal: &mut Account<Decimal> = &mut ctx.accounts.decimal;
decimal.value = round.answer;
decimal.decimals = u32::from(decimals);

let decimal_print: Decimal = Decimal::new(round.answer, u32::from(decimals));
msg!("{} price is {}", description, decimal_print);
let decimal_print: Decimal = Decimal::new(round.answer, u32::from(result.decimals()));
msg!("price is {}", decimal_print);
Ok(())
}
}
Expand All @@ -50,8 +47,6 @@ pub struct Execute<'info> {

/// CHECK: We're reading data from this specified chainlink feed
pub chainlink_feed: AccountInfo<'info>,
/// CHECK: This is the Chainlink program library on Devnet
pub chainlink_program: AccountInfo<'info>,
/// CHECK: This is the devnet system program
pub system_program: Program<'info, System>,
}
Expand Down Expand Up @@ -82,4 +77,12 @@ impl std::fmt::Display for Decimal {
}
f.write_str(&scaled_val)
}
}

#[error_code]
pub enum DemoError {
#[msg("read error")]
ReadError,
#[msg("no round data")]
RoundDataMissing,
}
5 changes: 4 additions & 1 deletion tests/chainlink-solana-demo-int-test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import * as anchor from '@coral-xyz/anchor';
import * as dotenv from 'dotenv';
const assert = require("assert");

// Load environment variables from .env file
dotenv.config();

const CHAINLINK_PROGRAM_ID = "HEvSKofvBgfaexv23kMabbYqxasxU3mQ4ibBMEmJWHny";
// SOL/USD feed account
const CHAINLINK_FEED = "669U43LNHx7LsVj95uYksnhXUfWKDsdzVqev3V4Jpw3P";
Expand All @@ -23,7 +27,6 @@ describe('chainlink-solana-demo', () => {
.accounts({
decimal: priceFeedAccount.publicKey,
chainlinkFeed: CHAINLINK_FEED,
chainlinkProgram: CHAINLINK_PROGRAM_ID,
})
.signers([priceFeedAccount])
.rpc()
Expand Down
Loading