Add reward amount guards (#14)

This commit is contained in:
Armani Ferrante 2021-07-08 13:30:52 -07:00 committed by GitHub
parent b1ff2b28a4
commit a18a5fffbe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 53 additions and 7 deletions

View File

@ -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
@ -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
@ -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
@ -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:

1
Cargo.lock generated
View File

@ -707,6 +707,7 @@ dependencies = [
"anchor-lang",
"anchor-spl",
"lockup",
"solana-program",
]
[[package]]

View File

@ -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"

View File

@ -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,
@ -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>>
@ -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");
}

View File

@ -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,
@ -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)