mirror of
https://github.com/d0zingcat/ore.git
synced 2026-05-13 23:16:52 +00:00
delegate
This commit is contained in:
30
Cargo.lock
generated
30
Cargo.lock
generated
@@ -1299,6 +1299,36 @@ dependencies = [
|
||||
"thiserror 1.0.69",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ore-delegate-api"
|
||||
version = "3.7.0"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"const-crypto",
|
||||
"mpl-token-metadata",
|
||||
"num_enum",
|
||||
"solana-program",
|
||||
"spl-associated-token-account",
|
||||
"spl-token 4.0.2",
|
||||
"steel",
|
||||
"thiserror 1.0.69",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ore-delegate-program"
|
||||
version = "3.7.0"
|
||||
dependencies = [
|
||||
"bincode",
|
||||
"mpl-token-metadata",
|
||||
"ore-delegate-api",
|
||||
"rand 0.8.5",
|
||||
"solana-program",
|
||||
"spl-associated-token-account",
|
||||
"spl-token 4.0.2",
|
||||
"spl-token-2022 7.0.0",
|
||||
"steel",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ore-program"
|
||||
version = "3.7.0"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[workspace]
|
||||
resolver = "2"
|
||||
members = ["api", "program"]
|
||||
members = ["ore/*", "ore-delegate/*"]
|
||||
|
||||
[workspace.package]
|
||||
version = "3.7.0"
|
||||
@@ -21,7 +21,8 @@ bytemuck_derive = "1.7.0"
|
||||
const-crypto = "0.1.0"
|
||||
mpl-token-metadata = "5.1"
|
||||
num_enum = "0.7.2"
|
||||
ore-api = { path = "api" }
|
||||
ore-api = { path = "./ore/api" }
|
||||
ore-delegate-api = { path = "./ore-delegate/api" }
|
||||
ore-boost-api = "4.0.0-alpha"
|
||||
solana-account-decoder = "^2.1"
|
||||
solana-program = "^2.1"
|
||||
|
||||
37
README.md
37
README.md
@@ -2,37 +2,6 @@
|
||||
|
||||
**Mine blockspace. Trade hashpower. Win rewards.**
|
||||
|
||||
## API
|
||||
- [`Consts`](api/src/consts.rs) – Program constants.
|
||||
- [`Error`](api/src/error.rs) – Custom program errors.
|
||||
- [`Event`](api/src/error.rs) – Custom program events.
|
||||
- [`Instruction`](api/src/instruction.rs) – Declared instructions and arguments.
|
||||
|
||||
## Instructions
|
||||
|
||||
- [`Open`](program/src/open.rs) - Open a new block.
|
||||
- [`Close`](program/src/close.rs) - Close a block and pay out the reward.
|
||||
- [`Mine`](program/src/mine.rs) - Mine the current block.
|
||||
- [`Swap`](program/src/swap.rs) - Trade in a hashpower market.
|
||||
|
||||
## State
|
||||
- [`Block`](api/src/state/block.rs) - A period of time for mining.
|
||||
- [`Config`](api/src/state/config.rs) - Global program configuration.
|
||||
- [`Market`](api/src/state/market.rs) - Hashpower market for a given block.
|
||||
- [`Miner`](api/src/state/miner.rs) - Tracks a miner state and history.
|
||||
- [`Treasury`](api/src/state/treasury.rs) - The mint authority of the ORE token.
|
||||
|
||||
|
||||
## Tests
|
||||
|
||||
To run the test suite, use the Solana toolchain:
|
||||
|
||||
```
|
||||
cargo test-sbf
|
||||
```
|
||||
|
||||
For line coverage, use llvm-cov:
|
||||
|
||||
```
|
||||
cargo llvm-cov
|
||||
```
|
||||
## Programs
|
||||
- [`ore`](ore/README.md.rs) – ORE mining program.
|
||||
- [`ore-delegate`](ore-delegate/README.md.rs) – Delegate mining to another party.
|
||||
|
||||
33
ore-delegate/README.md
Normal file
33
ore-delegate/README.md
Normal file
@@ -0,0 +1,33 @@
|
||||
# ORE Delegate
|
||||
|
||||
**Delegate mining to another party.**
|
||||
|
||||
## API
|
||||
- [`Consts`](api/src/consts.rs) – Program constants.
|
||||
- [`Error`](api/src/error.rs) – Custom program errors.
|
||||
- [`Event`](api/src/error.rs) – Custom program events.
|
||||
- [`Instruction`](api/src/instruction.rs) – Declared instructions and arguments.
|
||||
|
||||
## Instructions
|
||||
- [`Deposit`](program/src/deposit.rs) - Deposit hash tokens.
|
||||
- [`Withdraw`](program/src/withdraw.rs) - Withdraw hash tokens.
|
||||
- [`Crank`](program/src/crank.rs) - Crank mine instructions.
|
||||
- [`Payout`](program/src/payout.rs) - Payout mining rewards.
|
||||
|
||||
## State
|
||||
- [`Delegate`](api/src/state/delegate.rs) - Escrows hash tokens on behalf of a miner.
|
||||
|
||||
|
||||
## Tests
|
||||
|
||||
To run the test suite, use the Solana toolchain:
|
||||
|
||||
```
|
||||
cargo test-sbf
|
||||
```
|
||||
|
||||
For line coverage, use llvm-cov:
|
||||
|
||||
```
|
||||
cargo llvm-cov
|
||||
```
|
||||
21
ore-delegate/api/Cargo.toml
Normal file
21
ore-delegate/api/Cargo.toml
Normal file
@@ -0,0 +1,21 @@
|
||||
[package]
|
||||
name = "ore-delegate-api"
|
||||
description.workspace = true
|
||||
version.workspace = true
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
homepage.workspace = true
|
||||
documentation.workspace = true
|
||||
repository.workspace = true
|
||||
keywords.workspace = true
|
||||
|
||||
[dependencies]
|
||||
bytemuck.workspace = true
|
||||
const-crypto.workspace = true
|
||||
mpl-token-metadata.workspace = true
|
||||
num_enum.workspace = true
|
||||
solana-program.workspace = true
|
||||
spl-token.workspace = true
|
||||
spl-associated-token-account.workspace = true
|
||||
steel.workspace = true
|
||||
thiserror.workspace = true
|
||||
2
ore-delegate/api/src/consts.rs
Normal file
2
ore-delegate/api/src/consts.rs
Normal file
@@ -0,0 +1,2 @@
|
||||
/// The seed of the delegate account PDA.
|
||||
pub const DELEGATE: &[u8] = b"delegate";
|
||||
10
ore-delegate/api/src/error.rs
Normal file
10
ore-delegate/api/src/error.rs
Normal file
@@ -0,0 +1,10 @@
|
||||
use steel::*;
|
||||
|
||||
#[derive(Debug, Error, Clone, Copy, PartialEq, Eq, IntoPrimitive)]
|
||||
#[repr(u32)]
|
||||
pub enum OreError {
|
||||
#[error("Placeholder error")]
|
||||
Dummy = 0,
|
||||
}
|
||||
|
||||
error!(OreError);
|
||||
1
ore-delegate/api/src/event.rs
Normal file
1
ore-delegate/api/src/event.rs
Normal file
@@ -0,0 +1 @@
|
||||
use steel::*;
|
||||
37
ore-delegate/api/src/instruction.rs
Normal file
37
ore-delegate/api/src/instruction.rs
Normal file
@@ -0,0 +1,37 @@
|
||||
use steel::*;
|
||||
|
||||
#[repr(u8)]
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, TryFromPrimitive)]
|
||||
pub enum OreDelegateInstruction {
|
||||
Deposit = 0,
|
||||
Withdraw = 1,
|
||||
Crank = 2,
|
||||
Payout = 3,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
|
||||
pub struct Deposit {
|
||||
pub amount: [u8; 8],
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
|
||||
pub struct Withdraw {
|
||||
pub amount: [u8; 8],
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
|
||||
pub struct Crank {
|
||||
pub amount: [u8; 8],
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, Pod, Zeroable)]
|
||||
pub struct Payout {}
|
||||
|
||||
instruction!(OreDelegateInstruction, Deposit);
|
||||
instruction!(OreDelegateInstruction, Withdraw);
|
||||
instruction!(OreDelegateInstruction, Crank);
|
||||
instruction!(OreDelegateInstruction, Payout);
|
||||
3
ore-delegate/api/src/sdk.rs
Normal file
3
ore-delegate/api/src/sdk.rs
Normal file
@@ -0,0 +1,3 @@
|
||||
use steel::*;
|
||||
|
||||
use crate::{instruction::*, state::*};
|
||||
21
ore-delegate/api/src/state/delegate.rs
Normal file
21
ore-delegate/api/src/state/delegate.rs
Normal file
@@ -0,0 +1,21 @@
|
||||
use steel::*;
|
||||
|
||||
use super::OreDelegateAccount;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable)]
|
||||
pub struct Delegate {
|
||||
/// The authority of the delegate.
|
||||
pub authority: Pubkey,
|
||||
|
||||
/// The number of hash tokens deposited for mining.
|
||||
pub balance: u64,
|
||||
|
||||
/// The block these hash tokens are associated with.
|
||||
pub block_id: u64,
|
||||
|
||||
/// The fee to payout per crank (lamports).
|
||||
pub fee: u64,
|
||||
}
|
||||
|
||||
account!(OreDelegateAccount, Delegate);
|
||||
20
ore-delegate/api/src/state/mod.rs
Normal file
20
ore-delegate/api/src/state/mod.rs
Normal file
@@ -0,0 +1,20 @@
|
||||
mod delegate;
|
||||
|
||||
pub use delegate::*;
|
||||
|
||||
use crate::consts::*;
|
||||
|
||||
use steel::*;
|
||||
|
||||
#[repr(u8)]
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, IntoPrimitive, TryFromPrimitive)]
|
||||
pub enum OreDelegateAccount {
|
||||
Delegate = 100,
|
||||
}
|
||||
|
||||
pub fn delegate_pda(authority: Pubkey, block_id: u64) -> (Pubkey, u8) {
|
||||
Pubkey::find_program_address(
|
||||
&[DELEGATE, &authority.to_bytes(), &block_id.to_le_bytes()],
|
||||
&crate::ID,
|
||||
)
|
||||
}
|
||||
31
ore-delegate/program/Cargo.toml
Normal file
31
ore-delegate/program/Cargo.toml
Normal file
@@ -0,0 +1,31 @@
|
||||
[package]
|
||||
name = "ore-delegate-program"
|
||||
description.workspace = true
|
||||
version.workspace = true
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
homepage.workspace = true
|
||||
documentation.workspace = true
|
||||
repository.workspace = true
|
||||
readme.workspace = true
|
||||
keywords.workspace = true
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib", "lib"]
|
||||
name = "ore_delegate"
|
||||
|
||||
[features]
|
||||
default = []
|
||||
|
||||
[dependencies]
|
||||
bincode.workspace = true
|
||||
mpl-token-metadata.workspace = true
|
||||
ore-delegate-api.workspace = true
|
||||
solana-program.workspace = true
|
||||
spl-token.workspace = true
|
||||
spl-token-2022.workspace = true
|
||||
spl-associated-token-account.workspace = true
|
||||
steel.workspace = true
|
||||
|
||||
[dev-dependencies]
|
||||
rand = "0.8.5"
|
||||
155
ore-delegate/program/src/crank.rs
Normal file
155
ore-delegate/program/src/crank.rs
Normal file
@@ -0,0 +1,155 @@
|
||||
use ore_delegate_api::prelude::*;
|
||||
use solana_program::program_pack::Pack;
|
||||
use spl_token_2022::instruction::AuthorityType;
|
||||
use steel::*;
|
||||
|
||||
/// Cranks a mining transaction.
|
||||
pub fn process_crank(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult {
|
||||
// Parse data.
|
||||
let args = Crank::try_from_bytes(data)?;
|
||||
// let id = u64::from_le_bytes(args.id);
|
||||
|
||||
// Load accounts.
|
||||
// let [signer_info, block_info, market_info, mint_base_info, mint_quote_info, system_program, vault_base_info, vault_quote_info, token_program, associated_token_program, rent_sysvar] =
|
||||
// accounts
|
||||
// else {
|
||||
// return Err(ProgramError::NotEnoughAccountKeys);
|
||||
// };
|
||||
// signer_info.is_signer()?;
|
||||
// block_info
|
||||
// .is_empty()?
|
||||
// .is_writable()?
|
||||
// .has_seeds(&[BLOCK, &id.to_le_bytes()], &ore_api::ID)?;
|
||||
// market_info
|
||||
// .is_empty()?
|
||||
// .is_writable()?
|
||||
// .has_seeds(&[MARKET, &id.to_le_bytes()], &ore_api::ID)?;
|
||||
// mint_base_info
|
||||
// .is_empty()?
|
||||
// .is_writable()?
|
||||
// .has_seeds(&[MINT, &id.to_le_bytes()], &ore_api::ID)?;
|
||||
// mint_quote_info.has_address(&MINT_ADDRESS)?.as_mint()?;
|
||||
// system_program.is_program(&system_program::ID)?;
|
||||
// token_program.is_program(&spl_token::ID)?;
|
||||
// associated_token_program.is_program(&spl_associated_token_account::ID)?;
|
||||
// rent_sysvar.is_sysvar(&sysvar::rent::ID)?;
|
||||
|
||||
// // Initialize config.
|
||||
// create_program_account::<Block>(
|
||||
// block_info,
|
||||
// system_program,
|
||||
// signer_info,
|
||||
// &ore_api::ID,
|
||||
// &[BLOCK, &id.to_le_bytes()],
|
||||
// )?;
|
||||
// let block = block_info.as_account_mut::<Block>(&ore_api::ID)?;
|
||||
// block.best_hash = [0; 32];
|
||||
// block.best_miner = Pubkey::default();
|
||||
// block.id = id;
|
||||
// block.reward = ONE_ORE * 10;
|
||||
// block.slot_hash = [0; 32];
|
||||
// block.start_slot = 1500 * id;
|
||||
|
||||
// // Initialize market.
|
||||
// create_program_account::<Market>(
|
||||
// market_info,
|
||||
// system_program,
|
||||
// signer_info,
|
||||
// &ore_api::ID,
|
||||
// &[MARKET, &id.to_le_bytes()],
|
||||
// )?;
|
||||
// let market = market_info.as_account_mut::<Market>(&ore_api::ID)?;
|
||||
// market.base = TokenParams {
|
||||
// mint: *mint_base_info.key,
|
||||
// balance: HASH_TOKEN_SUPPLY,
|
||||
// balance_virtual: 0,
|
||||
// };
|
||||
// market.quote = TokenParams {
|
||||
// mint: *mint_quote_info.key,
|
||||
// balance: 0,
|
||||
// balance_virtual: ONE_ORE,
|
||||
// };
|
||||
// market.fee = FeeParams {
|
||||
// rate: FEE_RATE_BPS,
|
||||
// uncollected: 0,
|
||||
// cumulative: 0,
|
||||
// };
|
||||
// market.snapshot = Snapshot {
|
||||
// enabled: 1,
|
||||
// base_balance: 0,
|
||||
// quote_balance: 0,
|
||||
// slot: 0,
|
||||
// };
|
||||
// market.id = id;
|
||||
|
||||
// // Initialize hash token mint.
|
||||
// allocate_account(
|
||||
// mint_base_info,
|
||||
// system_program,
|
||||
// signer_info,
|
||||
// spl_token::state::Mint::LEN,
|
||||
// &spl_token::ID,
|
||||
// &[MINT, &id.to_le_bytes()],
|
||||
// )?;
|
||||
// initialize_mint_signed(
|
||||
// mint_base_info,
|
||||
// block_info,
|
||||
// None,
|
||||
// token_program,
|
||||
// rent_sysvar,
|
||||
// 0,
|
||||
// &[MINT, &id.to_le_bytes()],
|
||||
// )?;
|
||||
|
||||
// // TODO Initialize hash token metadata.
|
||||
|
||||
// // Initialize vault token accounts.
|
||||
// if vault_base_info.data_is_empty() {
|
||||
// create_associated_token_account(
|
||||
// signer_info,
|
||||
// market_info,
|
||||
// vault_base_info,
|
||||
// mint_base_info,
|
||||
// system_program,
|
||||
// token_program,
|
||||
// associated_token_program,
|
||||
// )?;
|
||||
// } else {
|
||||
// vault_base_info.as_associated_token_account(market_info.key, mint_base_info.key)?;
|
||||
// }
|
||||
// if vault_quote_info.data_is_empty() {
|
||||
// create_associated_token_account(
|
||||
// signer_info,
|
||||
// market_info,
|
||||
// vault_quote_info,
|
||||
// mint_quote_info,
|
||||
// system_program,
|
||||
// token_program,
|
||||
// associated_token_program,
|
||||
// )?;
|
||||
// } else {
|
||||
// vault_quote_info.as_associated_token_account(market_info.key, mint_quote_info.key)?;
|
||||
// }
|
||||
|
||||
// // Mint hash tokens to market.
|
||||
// mint_to_signed(
|
||||
// mint_base_info,
|
||||
// vault_base_info,
|
||||
// block_info,
|
||||
// token_program,
|
||||
// HASH_TOKEN_SUPPLY,
|
||||
// &[BLOCK, &id.to_le_bytes()],
|
||||
// )?;
|
||||
|
||||
// // Burn mint authority.
|
||||
// set_authority_signed(
|
||||
// mint_base_info,
|
||||
// block_info,
|
||||
// None,
|
||||
// AuthorityType::MintTokens,
|
||||
// token_program,
|
||||
// &[BLOCK, &id.to_le_bytes()],
|
||||
// )?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
69
ore-delegate/program/src/deposit.rs
Normal file
69
ore-delegate/program/src/deposit.rs
Normal file
@@ -0,0 +1,69 @@
|
||||
use ore_delegate_api::prelude::*;
|
||||
use steel::*;
|
||||
|
||||
/// Deposits hash tokens for cranking.
|
||||
pub fn process_deposit(accounts: &[AccountInfo<'_>], _data: &[u8]) -> ProgramResult {
|
||||
// Load accounts.
|
||||
// let clock = Clock::get()?;
|
||||
// let [signer_info, block_info, market_info, mint_base_info, mint_quote_info, recipient_info, treasury_info, vault_base_info, vault_quote_info, system_program, token_program] =
|
||||
// accounts
|
||||
// else {
|
||||
// return Err(ProgramError::NotEnoughAccountKeys);
|
||||
// };
|
||||
// signer_info.is_signer()?;
|
||||
// let block = block_info
|
||||
// .as_account_mut::<Block>(&ore_api::ID)?
|
||||
// .assert_mut(|b| clock.slot >= b.start_slot + 1500)?;
|
||||
// let market = market_info
|
||||
// .as_account_mut::<Market>(&ore_api::ID)?
|
||||
// .assert_mut(|m| m.id == block.id)?;
|
||||
// mint_base_info.has_address(&market.base.mint)?.as_mint()?;
|
||||
// mint_quote_info.has_address(&market.quote.mint)?.as_mint()?;
|
||||
// let vault_base =
|
||||
// vault_base_info.as_associated_token_account(market_info.key, mint_base_info.key)?;
|
||||
// let vault_quote =
|
||||
// vault_quote_info.as_associated_token_account(market_info.key, mint_quote_info.key)?;
|
||||
// system_program.is_program(&system_program::ID)?;
|
||||
// token_program.is_program(&spl_token::ID)?;
|
||||
|
||||
// // Payout block reward.
|
||||
// if block.best_miner != Pubkey::default() {
|
||||
// recipient_info.as_associated_token_account(&block.best_miner, &MINT_ADDRESS)?;
|
||||
// mint_to_signed(
|
||||
// mint_quote_info,
|
||||
// recipient_info,
|
||||
// treasury_info,
|
||||
// token_program,
|
||||
// block.reward,
|
||||
// &[TREASURY],
|
||||
// )?;
|
||||
// }
|
||||
|
||||
// // Burn base liquidity.
|
||||
// burn_signed(
|
||||
// vault_base_info,
|
||||
// mint_base_info,
|
||||
// market_info,
|
||||
// token_program,
|
||||
// vault_base.amount(),
|
||||
// &[MARKET, &market.id.to_le_bytes()],
|
||||
// )?;
|
||||
|
||||
// // Burn quote liquidity.
|
||||
// burn_signed(
|
||||
// vault_quote_info,
|
||||
// mint_quote_info,
|
||||
// market_info,
|
||||
// token_program,
|
||||
// vault_quote.amount(),
|
||||
// &[MARKET, &market.id.to_le_bytes()],
|
||||
// )?;
|
||||
|
||||
// // Close block.
|
||||
// block_info.close(signer_info)?;
|
||||
|
||||
// // Close market.
|
||||
// market_info.close(signer_info)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
31
ore-delegate/program/src/lib.rs
Normal file
31
ore-delegate/program/src/lib.rs
Normal file
@@ -0,0 +1,31 @@
|
||||
mod crank;
|
||||
mod deposit;
|
||||
mod payout;
|
||||
mod withdraw;
|
||||
|
||||
use crank::*;
|
||||
use deposit::*;
|
||||
use payout::*;
|
||||
use withdraw::*;
|
||||
|
||||
use ore_delegate_api::instruction::*;
|
||||
use steel::*;
|
||||
|
||||
pub fn process_instruction(
|
||||
program_id: &Pubkey,
|
||||
accounts: &[AccountInfo],
|
||||
data: &[u8],
|
||||
) -> ProgramResult {
|
||||
let (ix, data) = parse_instruction(&ore_delegate_api::ID, program_id, data)?;
|
||||
|
||||
match ix {
|
||||
OreDelegateInstruction::Deposit => process_deposit(accounts, data)?,
|
||||
OreDelegateInstruction::Withdraw => process_withdraw(accounts, data)?,
|
||||
OreDelegateInstruction::Crank => process_crank(accounts, data)?,
|
||||
OreDelegateInstruction::Payout => process_payout(accounts, data)?,
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
entrypoint!(process_instruction);
|
||||
99
ore-delegate/program/src/payout.rs
Normal file
99
ore-delegate/program/src/payout.rs
Normal file
@@ -0,0 +1,99 @@
|
||||
use ore_delegate_api::prelude::*;
|
||||
use steel::*;
|
||||
|
||||
/// Payouts a block reward.
|
||||
pub fn process_payout(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult {
|
||||
// Parse args.
|
||||
// let args = Payout::try_from_bytes(data)?;
|
||||
// let amount = u64::from_le_bytes(args.amount);
|
||||
// let direction = PayoutDirection::try_from(args.direction).unwrap();
|
||||
// let precision = PayoutPrecision::try_from(args.precision).unwrap();
|
||||
|
||||
// // Load accounts.
|
||||
// let clock = Clock::get()?;
|
||||
// let [signer_info, block_info, market_info, mint_base_info, mint_quote_info, tokens_base_info, tokens_quote_info, vault_base_info, vault_quote_info, system_program, token_program] =
|
||||
// accounts
|
||||
// else {
|
||||
// return Err(ProgramError::NotEnoughAccountKeys);
|
||||
// };
|
||||
// signer_info.is_signer()?;
|
||||
// let block = block_info
|
||||
// .as_account_mut::<Block>(&ore_api::ID)?
|
||||
// .assert_mut(|b| clock.slot >= b.start_slot + 1500)?;
|
||||
// let market = market_info
|
||||
// .as_account_mut::<Market>(&ore_api::ID)?
|
||||
// .assert_mut(|m| m.id == block.id)?
|
||||
// .assert_mut_err(
|
||||
// |m| m.base.liquidity() > 0,
|
||||
// OreError::InsufficientLiquidity.into(),
|
||||
// )?
|
||||
// .assert_mut_err(
|
||||
// |m| m.quote.liquidity() > 0,
|
||||
// OreError::InsufficientLiquidity.into(),
|
||||
// )?;
|
||||
// mint_base_info.has_address(&market.base.mint)?.as_mint()?;
|
||||
// mint_quote_info.has_address(&market.quote.mint)?.as_mint()?;
|
||||
// tokens_base_info
|
||||
// .is_writable()?
|
||||
// .as_associated_token_account(signer_info.key, mint_base_info.key)?;
|
||||
// tokens_quote_info
|
||||
// .is_writable()?
|
||||
// .as_associated_token_account(signer_info.key, mint_quote_info.key)?;
|
||||
// vault_base_info
|
||||
// .is_writable()?
|
||||
// .as_associated_token_account(market_info.key, mint_base_info.key)?;
|
||||
// vault_quote_info
|
||||
// .is_writable()?
|
||||
// .as_associated_token_account(market_info.key, mint_quote_info.key)?;
|
||||
// system_program.is_program(&system_program::ID)?;
|
||||
// token_program.is_program(&spl_token::ID)?;
|
||||
|
||||
// // Update market state.
|
||||
// let swap_result = market.swap(amount, direction, precision, clock)?;
|
||||
// swap_result.log_return();
|
||||
|
||||
// // Get transfer amounts and accounts.
|
||||
// let (in_amount, in_from, in_to, out_amount, out_from, out_to) = match direction {
|
||||
// SwapDirection::Buy => (
|
||||
// swap_result.quote_to_transfer,
|
||||
// tokens_quote_info,
|
||||
// vault_quote_info,
|
||||
// swap_result.base_to_transfer,
|
||||
// vault_base_info,
|
||||
// tokens_base_info,
|
||||
// ),
|
||||
// SwapDirection::Sell => (
|
||||
// swap_result.base_to_transfer,
|
||||
// tokens_base_info,
|
||||
// vault_base_info,
|
||||
// swap_result.quote_to_transfer,
|
||||
// vault_quote_info,
|
||||
// tokens_quote_info,
|
||||
// ),
|
||||
// };
|
||||
|
||||
// // Transfer tokens.
|
||||
// transfer(signer_info, in_from, in_to, token_program, in_amount)?;
|
||||
// transfer_signed(
|
||||
// market_info,
|
||||
// out_from,
|
||||
// out_to,
|
||||
// token_program,
|
||||
// out_amount,
|
||||
// &[
|
||||
// MARKET,
|
||||
// market.base.mint.as_ref(),
|
||||
// market.quote.mint.as_ref(),
|
||||
// market.id.to_le_bytes().as_ref(),
|
||||
// ],
|
||||
// )?;
|
||||
|
||||
// // Validate vault reserves.
|
||||
// let vault_base =
|
||||
// vault_base_info.as_associated_token_account(market_info.key, mint_base_info.key)?;
|
||||
// let vault_quote =
|
||||
// vault_quote_info.as_associated_token_account(market_info.key, mint_quote_info.key)?;
|
||||
// market.check_vaults(&vault_base, &vault_quote)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
79
ore-delegate/program/src/withdraw.rs
Normal file
79
ore-delegate/program/src/withdraw.rs
Normal file
@@ -0,0 +1,79 @@
|
||||
use ore_delegate_api::prelude::*;
|
||||
use solana_program::keccak;
|
||||
use steel::*;
|
||||
|
||||
/// Withdraws hash tokens from the delegate.
|
||||
pub fn process_withdraw(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult {
|
||||
// Parse data.
|
||||
let args = Withdraw::try_from_bytes(data)?;
|
||||
let amount = u64::from_le_bytes(args.amount);
|
||||
|
||||
// Load accounts.
|
||||
// let clock = Clock::get()?;
|
||||
// let [signer_info, block_info, market_info, miner_info, mint_info, sender_info, system_program, token_program] =
|
||||
// accounts
|
||||
// else {
|
||||
// return Err(ProgramError::NotEnoughAccountKeys);
|
||||
// };
|
||||
// signer_info.is_signer()?;
|
||||
// let block = block_info
|
||||
// .as_account_mut::<Block>(&ore_api::ID)?
|
||||
// .assert_mut(|b| clock.slot >= b.start_slot)?
|
||||
// .assert_mut(|b| clock.slot < b.start_slot + 1500)?;
|
||||
// let market = market_info
|
||||
// .as_account::<Market>(&ore_api::ID)?
|
||||
// .assert(|m| m.id == block.id)?;
|
||||
// mint_info.has_address(&market.base.mint)?.as_mint()?;
|
||||
// sender_info
|
||||
// .is_writable()?
|
||||
// .as_associated_token_account(signer_info.key, &mint_info.key)?
|
||||
// .assert(|t| t.amount() >= amount)?;
|
||||
// system_program.is_program(&system_program::ID)?;
|
||||
// token_program.is_program(&spl_token::ID)?;
|
||||
|
||||
// // Load miner account.
|
||||
// let miner = if miner_info.data_is_empty() {
|
||||
// create_program_account::<Miner>(
|
||||
// miner_info,
|
||||
// system_program,
|
||||
// signer_info,
|
||||
// &ore_api::ID,
|
||||
// &[MINER, &signer_info.key.to_bytes()],
|
||||
// )?;
|
||||
// let miner = miner_info.as_account_mut::<Miner>(&ore_api::ID)?;
|
||||
// miner.authority = *signer_info.key;
|
||||
// miner.block_id = 0;
|
||||
// miner.hash = [0; 32];
|
||||
// miner.total_hashes = 0;
|
||||
// miner.total_rewards = 0;
|
||||
// miner
|
||||
// } else {
|
||||
// miner_info
|
||||
// .as_account_mut::<Miner>(&ore_api::ID)?
|
||||
// .assert_mut(|m| m.authority == *signer_info.key)?
|
||||
// };
|
||||
|
||||
// // Reset miner hash if mining new block.
|
||||
// if miner.block_id != block.id {
|
||||
// miner.block_id = block.id;
|
||||
// miner.hash =
|
||||
// keccak::hashv(&[block.slot_hash.as_ref(), miner.authority.as_ref()]).to_bytes();
|
||||
// }
|
||||
|
||||
// // Mine.
|
||||
// for _ in 0..amount {
|
||||
// miner.hash = keccak::hashv(&[miner.hash.as_ref()]).to_bytes();
|
||||
// if miner.hash < block.best_hash {
|
||||
// block.best_hash = miner.hash;
|
||||
// block.best_miner = miner.authority;
|
||||
// }
|
||||
// }
|
||||
|
||||
// // Update miner stats.
|
||||
// miner.total_hashes += amount;
|
||||
|
||||
// // Burn hash tokens.
|
||||
// burn(sender_info, mint_info, signer_info, token_program, amount)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
38
ore/README.md
Normal file
38
ore/README.md
Normal file
@@ -0,0 +1,38 @@
|
||||
# ORE
|
||||
|
||||
**Mine blockspace. Trade hashpower. Win rewards.**
|
||||
|
||||
## API
|
||||
- [`Consts`](api/src/consts.rs) – Program constants.
|
||||
- [`Error`](api/src/error.rs) – Custom program errors.
|
||||
- [`Event`](api/src/error.rs) – Custom program events.
|
||||
- [`Instruction`](api/src/instruction.rs) – Declared instructions and arguments.
|
||||
|
||||
## Instructions
|
||||
|
||||
- [`Open`](program/src/open.rs) - Open a new block.
|
||||
- [`Close`](program/src/close.rs) - Close a block and pay out the reward.
|
||||
- [`Mine`](program/src/mine.rs) - Mine the current block.
|
||||
- [`Swap`](program/src/swap.rs) - Trade in a hashpower market.
|
||||
|
||||
## State
|
||||
- [`Block`](api/src/state/block.rs) - A period of time for mining.
|
||||
- [`Config`](api/src/state/config.rs) - Global program configuration.
|
||||
- [`Market`](api/src/state/market.rs) - Hashpower market for a given block.
|
||||
- [`Miner`](api/src/state/miner.rs) - Tracks a miner state and history.
|
||||
- [`Treasury`](api/src/state/treasury.rs) - The mint authority of the ORE token.
|
||||
|
||||
|
||||
## Tests
|
||||
|
||||
To run the test suite, use the Solana toolchain:
|
||||
|
||||
```
|
||||
cargo test-sbf
|
||||
```
|
||||
|
||||
For line coverage, use llvm-cov:
|
||||
|
||||
```
|
||||
cargo llvm-cov
|
||||
```
|
||||
18
ore/api/src/lib.rs
Normal file
18
ore/api/src/lib.rs
Normal file
@@ -0,0 +1,18 @@
|
||||
pub mod consts;
|
||||
pub mod error;
|
||||
pub mod event;
|
||||
pub mod instruction;
|
||||
pub mod sdk;
|
||||
pub mod state;
|
||||
|
||||
pub mod prelude {
|
||||
pub use crate::consts::*;
|
||||
pub use crate::error::*;
|
||||
pub use crate::event::*;
|
||||
pub use crate::instruction::*;
|
||||
pub use crate::state::*;
|
||||
}
|
||||
|
||||
use steel::*;
|
||||
|
||||
declare_id!("oreV2ZymfyeXgNgBdqMkumTqqAprVqgBWQfoYkrtKWQ");
|
||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user