Solana
Programming API reference for the Stork Solana contract.
SDK
Solana contracts can program against Stork's contract using the stork-sdk rust crate available on crates.io. This SDK provides useful methods and structs for reading from stork price feed account. For thorough documentation, please also see the docs.rs page. The Stork contract and SDK are built on top of Anchor.
Installation
After setting up your Anchor project, add the stork-sdk to your project dependencies by adding the following line to the [dependencies]
section of the programs Cargo.toml
:
or the following command:
You can now import the stork-sdk's interfaces with:
Documentation
Documentation for the methods, structs, and constants provided by the stork-sdk can be found on doc.rs.
Examples
Example usage of the stork-sdk for consuming Stork prices can be found in the stork-external github repo.
Contract
Stork's contract depends on the stork-sdk crate and Anchor, and contains useful methods for writing to the Stork Config account, as well as Temporal Numeric Value Feed PDA accounts that represent Stork data feeds. The full source-code can be found in the stork-external github repo. For the official deployments, please see the Solana Contract Addresses.
Methods
Initialize
Description
Initializes the Stork configuration by creating the StorkConfig
PDA account. The signer is set as the owner in the owner
field.
Parameters
ctx: Context<Initialize>
: Context containing the accounts and required for initialization.stork_sol_public_key: Pubkey
: The Stork Solana public key.stork_evm_public_key: EvmPubkey
: The Stork EVM public key.single_update_fee_in_lamports: u64
: The fee for a single update in lamports.
Behavior
Creates the
StorkConfig
PDA account.Sets the signer as the owner in the
ow
Description
Updates the latest value in the feed account for a specific asset using data signed by the Stork EVM private key.
Parameters
ctx: Context<UpdateTemporalNumericValue>
: Context containing the accounts required for the update.update_data: TemporalNumericValueEvmInput
: Signed data for a single asset update.
Behavior
Verifies the signature of the update data using the
stork_evm_public_key
stored in the config account.Checks if the new update is more recent than the current feed data.
Transfers the update fee from the payer to the treasury.
Updates the feed account with the new data if all checks pass.
Errors
StorkError::InvalidSignature
: If the update data signature verification fails.StorkError::InsufficientFunds
: If the payer does not have enough lamports to cover the update fee.
Returns
Result<()>
: IsOk(())
if the update is successful.
ner
field.
Errors
StorkError::Unauthorized
: If the signer is not the owner of the contract.
Returns
Result<()>
: IsOk(())
on success or aStorkError
on failure.
Update Temporal Numeric Value EVM
Description
Updates the latest value in the feed account for a specific asset using data signed by the Stork EVM private key.
Parameters
ctx: Context<UpdateTemporalNumericValue>
: Context containing the accounts required for the update.update_data: TemporalNumericValueEvmInput
: Signed data for a single asset update.
Behavior
Verifies the signature of the update data using the
stork_evm_public_key
stored in the config account.Verifies if the new update is more recent than the current feed data.
Does not error, but does not update if the recency verification fails.
Transfers the update fee from the payer to the treasury.
Updates the feed account with the new data if all verifications pass.
Errors
StorkError::InvalidSignature
: If the update data signature verification fails.StorkError::InsufficientFunds
: If the payer does not have enough lamports to cover the update fee.
Returns
Result<()>
: IsOk(())
if the update is successful.
Update Single Update Fee
Description
Updates the fee required to perform a single feed update.
Parameters
ctx: Context<AdminUpdate>
: Context containing the config PDA account.new_single_update_fee_in_lamports: u64
: The new single update fee in lamports.
Behavior
Updates the
single_update_fee_in_lamports
field in theStorkConfig
PDA account.
Errors
StorkError::Unauthorized
: If the signer is not the owner defined in theowner
field of theStorkConfig
PDA account.
Returns
Result<()>
: IsOk(())
on success or aStorkError
on failure.
Update Stork Sol Pub Key
Description
Updates the Stork Solana public key in the StorkConfig
PDA account.
Parameters
ctx: Context<AdminUpdate>
: Context containing the config PDA account.new_stork_sol_public_key: Pubkey
: The new Stork Solana public key.
Behavior
Updates the
stork_sol_public_key
field in theStorkConfig
PDA account.
Errors
StorkError::Unauthorized
: If the signer is not the owner defined in theowner
field of theStorkConfig
PDA account.
Returns
Result<()>
: IsOk(())
on success or aStorkError
on failure.
Update Stork EVM Pub Key
Description
Updates the Stork EVM public key in the StorkConfig
PDA account. This key is used to verify the signatures of update data passed to the update_temporal_numeric_value_evm
function.
Parameters
ctx: Context<AdminUpdate>
: Context containing the config PDA account.new_stork_evm_public_key: EvmPubkey
: The new Stork EVM public key.
Behavior
Updates the
stork_evm_public_key
field in theStorkConfig
PDA account.
Errors
StorkError::Unauthorized
: If the signer is not the owner defined in theowner
field of theStorkConfig
PDA account.
Returns
Result<()>
: IsOk(())
on success or aStorkError
on failure.
Last updated