Skip to content
Draft
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
3 changes: 3 additions & 0 deletions Anchor.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
anchor_version = "0.20.1"
solana_version = "1.8.11"

[features]
seeds = true

[scripts]
test = "yarn mocha"

Expand Down
4 changes: 2 additions & 2 deletions ci.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ pkgs.buildEnv {
paths = with pkgs;
with saber-pkgs;
(pkgs.lib.optionals pkgs.stdenv.isLinux ([ libudev ])) ++ [
anchor-0_20_0
anchor-0_21_0
cargo-workspaces
solana-install
solana-basic

# sdk
nodejs
Expand Down
24 changes: 12 additions & 12 deletions flake.lock

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"@saberhq/token-utils": "^1.12.44",
"@saberhq/tsconfig": "^1.12.44",
"@solana/web3.js": "^1.34.0",
"@tribecahq/tribeca-sdk": "^0.4.0",
"@tribecahq/tribeca-sdk": "^0.4.1",
"@types/bn.js": "^5.1.0",
"@types/chai": "^4.3.0",
"@types/lodash": "^4.14.178",
Expand Down
2 changes: 1 addition & 1 deletion programs/gauge/src/instructions/create_gauge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub struct CreateGauge<'info> {
seeds = [
b"Gauge".as_ref(),
gaugemeister.key().as_ref(),
quarry.key().as_ref(),
quarry.key().as_ref()
],
bump,
payer = payer
Expand Down
50 changes: 50 additions & 0 deletions programs/gauge/src/instructions/create_gauge_delegation.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//! Creates a [GaugeDelegation].

use locked_voter::Escrow;
use vipers::assert_keys_eq;

use crate::*;

/// Accounts for [gauge::create_gauge_delegation].
#[derive(Accounts)]
pub struct CreateGaugeDelegation<'info> {
/// The [GaugeDelegation] to be created.
#[account(
init,
seeds = [
b"GaugeDelegation".as_ref(),
gauge_voter.key().as_ref()
],
bump,
payer = payer
)]
pub gauge_delegation: AccountLoader<'info, GaugeDelegation>,

/// [GaugeVoter].
pub gauge_voter: Account<'info, GaugeVoter>,

/// [Escrow].
pub escrow: Account<'info, Escrow>,

/// Payer.
#[account(mut)]
pub payer: Signer<'info>,

/// System program.
pub system_program: Program<'info, System>,
}

pub fn handler(ctx: Context<CreateGaugeDelegation>) -> ProgramResult {
let gauge_delegation = &mut ctx.accounts.gauge_delegation.load_init()?;
gauge_delegation.gauge_voter = ctx.accounts.gauge_voter.key();
gauge_delegation.vote_setter = Pubkey::default();
gauge_delegation.vote_committer = Pubkey::default();
Ok(())
}

impl<'info> Validate<'info> for CreateGaugeDelegation<'info> {
fn validate(&self) -> ProgramResult {
assert_keys_eq!(self.escrow, self.gauge_voter.escrow);
Ok(())
}
}
2 changes: 1 addition & 1 deletion programs/gauge/src/instructions/create_gauge_vote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub struct CreateGaugeVote<'info> {
seeds = [
b"GaugeVote".as_ref(),
gauge_voter.key().as_ref(),
gauge.key().as_ref(),
gauge.key().as_ref()
],
bump,
payer = payer
Expand Down
2 changes: 1 addition & 1 deletion programs/gauge/src/instructions/create_gaugemeister.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub struct CreateGaugemeister<'info> {
init,
seeds = [
b"Gaugemeister".as_ref(),
base.key().as_ref(),
base.key().as_ref()
],
bump,
payer = payer
Expand Down
35 changes: 35 additions & 0 deletions programs/gauge/src/instructions/delegated_gauge_commit_vote.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//! Votes for a [Gauge] using the [GaugeDelegation].

use vipers::assert_keys_eq;

use crate::*;

/// Accounts for [gauge::delegated_gauge_set_vote].
#[derive(Accounts)]
pub struct DelegatedGaugeCommitVote<'info> {
/// Common accounts for setting gauge votes.
/// The [GaugeCommitVoteV2::vote_delegate] is overloaded to be the [GaugeDelegation::vote_committer].
pub common: GaugeCommitVoteV2<'info>,
/// The [GaugeDelegation].
pub gauge_delegation: AccountLoader<'info, GaugeDelegation>,
}

impl<'info> DelegatedGaugeCommitVote<'info> {
fn commit_vote(&mut self) -> ProgramResult {
self.common.common.commit_vote()
}
}

pub fn handler(ctx: Context<DelegatedGaugeCommitVote>) -> ProgramResult {
ctx.accounts.commit_vote()
}

impl<'info> Validate<'info> for DelegatedGaugeCommitVote<'info> {
fn validate(&self) -> ProgramResult {
let delegation = self.gauge_delegation.load()?;
self.common.validate_without_delegate()?;
assert_keys_eq!(self.common.common.gauge_voter, delegation.gauge_voter);
assert_keys_eq!(self.common.vote_delegate, delegation.vote_committer);
Ok(())
}
}
36 changes: 36 additions & 0 deletions programs/gauge/src/instructions/delegated_gauge_revert_vote.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//! Votes for a [Gauge] using the [GaugeDelegation].

use vipers::assert_keys_eq;

use crate::*;

/// Accounts for [gauge::delegated_gauge_revert_vote].
#[derive(Accounts)]
pub struct DelegatedGaugeRevertVote<'info> {
/// Common accounts for setting gauge votes.
/// The [GaugeRevertVote::vote_delegate] is overloaded to be the [GaugeDelegation::vote_setter].
pub common: GaugeRevertVote<'info>,
/// The [GaugeDelegation].
pub gauge_delegation: AccountLoader<'info, GaugeDelegation>,
}

impl<'info> DelegatedGaugeRevertVote<'info> {
/// Sets a non-zero vote.
fn revert_vote(&mut self) -> ProgramResult {
self.common.revert_vote()
}
}

pub fn handler(ctx: Context<DelegatedGaugeRevertVote>) -> ProgramResult {
ctx.accounts.revert_vote()
}

impl<'info> Validate<'info> for DelegatedGaugeRevertVote<'info> {
fn validate(&self) -> ProgramResult {
let delegation = self.gauge_delegation.load()?;
self.common.validate_without_delegate()?;
assert_keys_eq!(self.common.gauge_voter, delegation.gauge_voter);
assert_keys_eq!(self.common.vote_delegate, delegation.vote_setter);
Ok(())
}
}
36 changes: 36 additions & 0 deletions programs/gauge/src/instructions/delegated_gauge_set_vote.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//! Votes for a [Gauge] using the [GaugeDelegation].

use vipers::assert_keys_eq;

use crate::*;

/// Accounts for [gauge::delegated_gauge_set_vote].
#[derive(Accounts)]
pub struct DelegatedGaugeSetVote<'info> {
/// Common accounts for setting gauge votes.
/// The [GaugeSetVote::vote_delegate] is overloaded to be the [GaugeDelegation::vote_setter].
pub common: GaugeSetVote<'info>,
/// The [GaugeDelegation].
pub gauge_delegation: AccountLoader<'info, GaugeDelegation>,
}

impl<'info> DelegatedGaugeSetVote<'info> {
/// Sets a non-zero vote.
fn set_vote(&mut self, weight: u32) -> ProgramResult {
self.common.set_vote(weight)
}
}

pub fn handler(ctx: Context<DelegatedGaugeSetVote>, weight: u32) -> ProgramResult {
ctx.accounts.set_vote(weight)
}

impl<'info> Validate<'info> for DelegatedGaugeSetVote<'info> {
fn validate(&self) -> ProgramResult {
let delegation = self.gauge_delegation.load()?;
self.common.validate_without_delegate()?;
assert_keys_eq!(self.common.gauge_voter, delegation.gauge_voter);
assert_keys_eq!(self.common.vote_delegate, delegation.vote_setter);
Ok(())
}
}
44 changes: 44 additions & 0 deletions programs/gauge/src/instructions/delegation_set_vote_committer.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//! Sets the [GaugeDelegation::vote_committer].

use locked_voter::Escrow;

use crate::*;

/// Accounts for [gauge::delegation_set_vote_committer].
#[derive(Accounts)]
pub struct DelegationSetVoteCommitter<'info> {
/// The [GaugeDelegation].
#[account(mut)]
pub gauge_delegation: AccountLoader<'info, GaugeDelegation>,
/// [GaugeVoter].
pub gauge_voter: Account<'info, GaugeVoter>,
/// The [Escrow].
pub escrow: Account<'info, Escrow>,
/// [Escrow::vote_delegate].
pub escrow_vote_delegate: Signer<'info>,
/// The new [GaugeDelegation::vote_committer].
pub new_vote_committer: UncheckedAccount<'info>,
}

impl<'info> DelegationSetVoteCommitter<'info> {
/// Sets a non-zero vote.
fn set_vote_committer(&self) -> ProgramResult {
let gauge_delegation = &mut self.gauge_delegation.load_mut()?;
gauge_delegation.vote_committer = self.new_vote_committer.key();
Ok(())
}
}

pub fn handler(ctx: Context<DelegationSetVoteCommitter>) -> ProgramResult {
ctx.accounts.set_vote_committer()
}

impl<'info> Validate<'info> for DelegationSetVoteCommitter<'info> {
fn validate(&self) -> ProgramResult {
let delegation = self.gauge_delegation.load()?;
assert_keys_eq!(self.gauge_voter, delegation.gauge_voter);
assert_keys_eq!(self.escrow, self.gauge_voter.escrow);
assert_keys_eq!(self.escrow_vote_delegate, self.escrow.vote_delegate);
Ok(())
}
}
44 changes: 44 additions & 0 deletions programs/gauge/src/instructions/delegation_set_vote_setter.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//! Sets the [GaugeDelegation::vote_setter].

use locked_voter::Escrow;

use crate::*;

/// Accounts for [gauge::delegation_set_vote_committer].
#[derive(Accounts)]
pub struct DelegationSetVoteSetter<'info> {
/// The [GaugeDelegation].
#[account(mut)]
pub gauge_delegation: AccountLoader<'info, GaugeDelegation>,
/// [GaugeVoter].
pub gauge_voter: Account<'info, GaugeVoter>,
/// The [Escrow].
pub escrow: Account<'info, Escrow>,
/// [Escrow::vote_delegate].
pub escrow_vote_delegate: Signer<'info>,
/// The new [GaugeDelegation::vote_setter].
pub new_vote_setter: UncheckedAccount<'info>,
}

impl<'info> DelegationSetVoteSetter<'info> {
/// Sets a non-zero vote.
fn set_vote_setter(&self) -> ProgramResult {
let gauge_delegation = &mut self.gauge_delegation.load_mut()?;
gauge_delegation.vote_setter = self.new_vote_setter.key();
Ok(())
}
}

pub fn handler(ctx: Context<DelegationSetVoteSetter>) -> ProgramResult {
ctx.accounts.set_vote_setter()
}

impl<'info> Validate<'info> for DelegationSetVoteSetter<'info> {
fn validate(&self) -> ProgramResult {
let delegation = self.gauge_delegation.load()?;
assert_keys_eq!(self.gauge_voter, delegation.gauge_voter);
assert_keys_eq!(self.escrow, self.gauge_voter.escrow);
assert_keys_eq!(self.escrow_vote_delegate, self.escrow.vote_delegate);
Ok(())
}
}
Loading