Skip to content

Commit

Permalink
Henry/sto 690 a series of small fixes (#86)
Browse files Browse the repository at this point in the history
* Fixed broken file link in solana readme.

* Added insert final newline to vscode settings.

* Corrected path to solana example in rust analyzer settings.

* Refactored sdk to stork-solana-sdk and stork_solana_sdk

* Finished refactoring for stork-solana-sdk.

* Change stork-sdk to stork-solana-sdk.

* Small fixes.

* Remove unused tests file in example.

* A few more stork-solana-sdk conversions.
  • Loading branch information
HenryMBaldwin authored Jan 30, 2025
1 parent 1095b1d commit bd61936
Show file tree
Hide file tree
Showing 22 changed files with 258 additions and 267 deletions.
7 changes: 4 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"solidity.compileUsingRemoteVersion": "v0.8.24+commit.e11b9ed9",
"rust-analyzer.linkedProjects": [
"./contracts/solana/programs/stork/Cargo.toml",
"./contracts/solana/programs/example/Cargo.toml",
"./sdks/solana/stork-sdk/Cargo.toml"
]
"./examples/solana/programs/example/Cargo.toml",
"./sdks/solana/stork-solana-sdk/Cargo.toml"
],
"files.insertFinalNewline": true
}
4 changes: 2 additions & 2 deletions contracts/solana/Cargo.lock

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

4 changes: 2 additions & 2 deletions contracts/solana/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

This directory contains an [Anchor](https://www.anchor-lang.com/) project used to manage and deploy the Stork Solana compatible contract.

This contract is used to write the latest values from the Stork network on-chain. For reading values on chain, see the [stork-sdk](../../sdks/solana/stork-sdk).
This contract is used to write the latest values from the Stork network on-chain. For reading values on chain, see the [stork-solana-sdk](../../sdks/solana/stork-solana-sdk).

### TemporalNumericValueFeed Accounts

On Solana, Stork price feeds exist as on-chain accounts. These accounts are instances of the [`TemporalNumericValueFeed` account](../../sdks/solana/stork-sdk/src/temporal_numeric_value.rs), and are created and owned by the Stork Oracle contract. These account have an ID which associates them with a specific asset, and a `latest_value` field which stores the latest price update. The ID of a TemporalNumericValueFeed account is determined by taking the keccak256 hash of the asset ID.
On Solana, Stork price feeds exist as on-chain accounts. These accounts are instances of the [`TemporalNumericValueFeed` account](../../sdks/solana/stork-solana-sdk/src/temporal_numeric_value.rs), and are created and owned by the Stork Oracle contract. These account have an ID which associates them with a specific asset, and a `latest_value` field which stores the latest price update. The ID of a TemporalNumericValueFeed account is determined by taking the keccak256 hash of the asset ID.

#### Writing to a TemporalNumericValueFeed Account

Expand Down
2 changes: 1 addition & 1 deletion contracts/solana/programs/stork/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ idl-build = ["anchor-lang/idl-build"]

[dependencies]
anchor-lang = { version = "0.30.1", features = ["init-if-needed"] }
stork-sdk = { path = "../../../../sdks/solana/stork-sdk/" }
stork-solana-sdk = { path = "../../../../sdks/solana/stork-solana-sdk/" }
6 changes: 3 additions & 3 deletions contracts/solana/programs/stork/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ use anchor_lang::solana_program::system_instruction;
mod verify;
use verify::{verify_stork_evm_signature, EvmPubkey};

use stork_sdk::{
use stork_solana_sdk::{
pda::{STORK_CONFIG_SEED, STORK_FEED_SEED, STORK_TREASURY_SEED},
temporal_numeric_value::{TemporalNumericValue, TemporalNumericValueFeed},
};

// This needs to match the ID in the stork-sdk crate
declare_id!(stork_sdk::PROGRAM_ID);
// This needs to match the ID in the stork-solana-sdk crate
declare_id!(stork_solana_sdk::PROGRAM_ID);

#[program]
pub mod stork {
Expand Down
8 changes: 4 additions & 4 deletions examples/solana/Cargo.lock

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

2 changes: 1 addition & 1 deletion examples/solana/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ anchor build
```
anchor deploy
```
5. Read the price from the Stork feed using the cli in [example.ts](example.ts)
5. Read the price from the Stork feed using the cli in [example.ts](app/example.ts)
```
ANCHOR_PROVIDER_URL=http://localhost:8899 ANCHOR_WALLET=~/.config/solana/id.json npx ts-node ./app/example.ts read-price <encoded_asset_id>
```
3 changes: 2 additions & 1 deletion examples/solana/app/example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,13 @@ cliProgram
const { program } = initializeCliProgram();
try {
const feedIdBytes = hexStringToByteArray(feedId);
await program.methods
const response = await program.methods
.readPrice(feedIdBytes)
.accounts({})
.rpc();

console.log("Price read successfully from feed:", feedId);
console.log("TX:", response);
} catch (error) {
console.error("Error reading price:", error);
if (error instanceof anchor.web3.SendTransactionError) {
Expand Down
15 changes: 8 additions & 7 deletions examples/solana/package.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
{
"license": "ISC",
"license": "ISC",
"scripts": {
"lint:fix": "prettier */*.js \"*/**/*{.js,.ts}\" -w",
"lint": "prettier */*.js \"*/**/*{.js,.ts}\" --check"
},
"dependencies": {
"@coral-xyz/anchor": "^0.30.1"
"@coral-xyz/anchor": "^0.30.1",
"commander": "^13.1.0"
},
"devDependencies": {
"chai": "^4.3.4",
"mocha": "^9.0.3",
"ts-mocha": "^10.0.0",
"@types/bn.js": "^5.1.0",
"@types/chai": "^4.3.0",
"@types/mocha": "^9.0.0",
"typescript": "^4.3.5",
"prettier": "^2.6.2"
"chai": "^4.3.4",
"mocha": "^9.0.3",
"prettier": "^2.6.2",
"ts-mocha": "^10.0.0",
"typescript": "^4.3.5"
}
}
2 changes: 1 addition & 1 deletion examples/solana/programs/example/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ idl-build = ["anchor-lang/idl-build"]

[dependencies]
anchor-lang = "0.30.1"
stork-sdk = "0.0.5"
stork-solana-sdk = "0.0.5"
hex = "0.4.3"
7 changes: 4 additions & 3 deletions examples/solana/programs/example/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use anchor_lang::prelude::*;
use stork_sdk::{
use stork_solana_sdk::{
pda::STORK_FEED_SEED,
temporal_numeric_value::TemporalNumericValueFeed,
};

declare_id!("FGpoDwQC8gYadJAsB9vrsgPN38qkqDgSk3qQcaRiyPra");
// Change this to the program ID you're using
declare_id!("GzkgPe7VSGeqC6QsUMJjL9FWSqfyqbqcJxe5FW2Xjm61");

#[program]
pub mod example {
Expand Down Expand Up @@ -40,7 +41,7 @@ pub struct ReadPrice<'info> {
#[account(
seeds = [STORK_FEED_SEED.as_ref(), feed_id.as_ref()],
bump,
seeds::program = stork_sdk::ID
seeds::program = stork_solana_sdk::ID
)]
pub feed: Account<'info, TemporalNumericValueFeed>,
}
Loading

0 comments on commit bd61936

Please sign in to comment.