Skip to content

Commit

Permalink
Add reward amount guards (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
armaniferrante authored Jul 8, 2021
1 parent b1ff2b2 commit a18a5ff
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 7 deletions.
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ env:
global:
- NODE_VERSION="v14.7.0"
- SOLANA_VERSION="v1.6.6"
- ANCHOR_VERSION="v0.4.4"
- ANCHOR_VERSION="0.4.4"

before_deploy:
- anchor build --verifiable
Expand All @@ -17,7 +17,7 @@ before_deploy:
- sha256sum target/idl/registry.json > registry_idl.txt
- cat *.txt >> release_notes.md
- echo "" >> release_notes.md
- echo "Built with Anchor [${ANCHOR_VERSION}](https://github.com/project-serum/anchor/releases/tag/${ANCHOR_VERSION})." >> release_notes.md
- echo "Built with Anchor [v${ANCHOR_VERSION}](https://github.com/project-serum/anchor/releases/tag/v${ANCHOR_VERSION})." >> release_notes.md

deploy:
provider: releases
Expand All @@ -38,7 +38,7 @@ _defaults: &defaults
before_install:
- nvm install $NODE_VERSION
- npm install -g mocha
- npm install -g @project-serum/anchor
- npm install -g @project-serum/anchor@${ANCHOR_VERSION}
- npm install -g @project-serum/serum
- npm install -g @project-serum/common
- npm install -g @solana/spl-token
Expand All @@ -47,7 +47,7 @@ _defaults: &defaults
- export PATH="/home/travis/.local/share/solana/install/active_release/bin:$PATH"
- export NODE_PATH="/home/travis/.nvm/versions/node/${NODE_VERSION}/lib/node_modules/:${NODE_PATH}"
- yes | solana-keygen new
- cargo install --git https://github.com/project-serum/anchor --tag ${ANCHOR_VERSION} anchor-cli --locked
- cargo install --git https://github.com/project-serum/anchor --tag v${ANCHOR_VERSION} anchor-cli --locked

jobs:
include:
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions programs/registry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ cpi = ["no-entrypoint"]
anchor-lang = "0.4.4"
anchor-spl = "0.4.4"
lockup = { path = "../lockup", features = ["cpi"] }
solana-program = "1.6.6"
44 changes: 44 additions & 0 deletions programs/registry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,28 @@ mod registry {
if ctx.accounts.clock.unix_timestamp >= expiry_ts {
return Err(ErrorCode::InvalidExpiry.into());
}
if ctx.accounts.registrar.to_account_info().key == &fida_registrar::ID {
if ctx.accounts.vendor_vault.mint != fida_mint::ID {
return Err(ErrorCode::InvalidMint.into());
}
if total < FIDA_MIN_REWARD {
return Err(ErrorCode::InsufficientReward.into());
}
} else if ctx.accounts.registrar.to_account_info().key == &srm_registrar::ID
|| ctx.accounts.registrar.to_account_info().key == &msrm_registrar::ID
{
if ctx.accounts.vendor_vault.mint != srm_mint::ID {
return Err(ErrorCode::InvalidMint.into());
}
if total < SRM_MIN_REWARD {
return Err(ErrorCode::InsufficientReward.into());
}
} else {
// TODO: in a future major version upgrade. Add the amount + mint
// to the registrar so that one can remove the hardcoded
// variables.
solana_program::msg!("Reward amount not constrained. Please open a pull request.");
}
if let RewardVendorKind::Locked {
start_ts,
end_ts,
Expand Down Expand Up @@ -1252,6 +1274,8 @@ pub enum ErrorCode {
InvalidVestingSchedule,
#[msg("Please specify the correct authority for this program.")]
InvalidProgramAuthority,
#[msg("Invalid mint supplied")]
InvalidMint,
}

impl<'a, 'b, 'c, 'info> From<&mut Deposit<'info>>
Expand Down Expand Up @@ -1351,3 +1375,23 @@ pub fn no_available_rewards<'info>(

Ok(())
}

// Native units.
pub const SRM_MIN_REWARD: u64 = 500_000_000;
pub const FIDA_MIN_REWARD: u64 = 900_000_000;

pub mod srm_registrar {
solana_program::declare_id!("5vJRzKtcp4fJxqmR7qzajkaKSiAb6aT9grRsaZKXU222");
}
pub mod msrm_registrar {
solana_program::declare_id!("7uURiX2DwCpRuMFebKSkFtX9v5GK1Cd8nWLL8tyoyxZY");
}
pub mod fida_registrar {
solana_program::declare_id!("5C2ayX1E2SJ5kKEmDCA9ue9eeo3EPR34QFrhyzbbs3qh");
}
pub mod srm_mint {
solana_program::declare_id!("SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt");
}
pub mod fida_mint {
solana_program::declare_id!("EchesyfXePKdLtoiZSL8pBe8Myagyy8ZRqsACNCFGnvp");
}
6 changes: 3 additions & 3 deletions tests/lockup.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ describe("Lockup and Registry", () => {
assert.ok(lockupAccount.authority.equals(provider.wallet.publicKey));
assert.ok(lockupAccount.whitelist.length === WHITELIST_SIZE);
lockupAccount.whitelist.forEach((e) => {
assert.ok(e.programId.equals(new anchor.web3.PublicKey()));
assert.ok(e.programId.equals(anchor.web3.PublicKey.default));
});
});

it("Deletes the default whitelisted addresses", async () => {
const defaultEntry = { programId: new anchor.web3.PublicKey() };
const defaultEntry = { programId: anchor.web3.PublicKey.default };
await lockup.state.rpc.whitelistDelete(defaultEntry, {
accounts: {
authority: provider.wallet.publicKey,
Expand Down Expand Up @@ -389,7 +389,7 @@ describe("Lockup and Registry", () => {

assert.ok(memberAccount.registrar.equals(registrar.publicKey));
assert.ok(memberAccount.beneficiary.equals(provider.wallet.publicKey));
assert.ok(memberAccount.metadata.equals(new anchor.web3.PublicKey()));
assert.ok(memberAccount.metadata.equals(anchor.web3.PublicKey.default));
assert.equal(
JSON.stringify(memberAccount.balances),
JSON.stringify(balances)
Expand Down

0 comments on commit a18a5ff

Please sign in to comment.