Add reward amount guards (#14)
This commit is contained in:
parent
b1ff2b28a4
commit
a18a5fffbe
|
@ -6,7 +6,7 @@ env:
|
||||||
global:
|
global:
|
||||||
- NODE_VERSION="v14.7.0"
|
- NODE_VERSION="v14.7.0"
|
||||||
- SOLANA_VERSION="v1.6.6"
|
- SOLANA_VERSION="v1.6.6"
|
||||||
- ANCHOR_VERSION="v0.4.4"
|
- ANCHOR_VERSION="0.4.4"
|
||||||
|
|
||||||
before_deploy:
|
before_deploy:
|
||||||
- anchor build --verifiable
|
- anchor build --verifiable
|
||||||
|
@ -17,7 +17,7 @@ before_deploy:
|
||||||
- sha256sum target/idl/registry.json > registry_idl.txt
|
- sha256sum target/idl/registry.json > registry_idl.txt
|
||||||
- cat *.txt >> release_notes.md
|
- cat *.txt >> release_notes.md
|
||||||
- echo "" >> 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:
|
deploy:
|
||||||
provider: releases
|
provider: releases
|
||||||
|
@ -38,7 +38,7 @@ _defaults: &defaults
|
||||||
before_install:
|
before_install:
|
||||||
- nvm install $NODE_VERSION
|
- nvm install $NODE_VERSION
|
||||||
- npm install -g mocha
|
- 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/serum
|
||||||
- npm install -g @project-serum/common
|
- npm install -g @project-serum/common
|
||||||
- npm install -g @solana/spl-token
|
- 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 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}"
|
- export NODE_PATH="/home/travis/.nvm/versions/node/${NODE_VERSION}/lib/node_modules/:${NODE_PATH}"
|
||||||
- yes | solana-keygen new
|
- 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:
|
jobs:
|
||||||
include:
|
include:
|
||||||
|
|
|
@ -707,6 +707,7 @@ dependencies = [
|
||||||
"anchor-lang",
|
"anchor-lang",
|
||||||
"anchor-spl",
|
"anchor-spl",
|
||||||
"lockup",
|
"lockup",
|
||||||
|
"solana-program",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
|
@ -16,3 +16,4 @@ cpi = ["no-entrypoint"]
|
||||||
anchor-lang = "0.4.4"
|
anchor-lang = "0.4.4"
|
||||||
anchor-spl = "0.4.4"
|
anchor-spl = "0.4.4"
|
||||||
lockup = { path = "../lockup", features = ["cpi"] }
|
lockup = { path = "../lockup", features = ["cpi"] }
|
||||||
|
solana-program = "1.6.6"
|
||||||
|
|
|
@ -378,6 +378,28 @@ mod registry {
|
||||||
if ctx.accounts.clock.unix_timestamp >= expiry_ts {
|
if ctx.accounts.clock.unix_timestamp >= expiry_ts {
|
||||||
return Err(ErrorCode::InvalidExpiry.into());
|
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 {
|
if let RewardVendorKind::Locked {
|
||||||
start_ts,
|
start_ts,
|
||||||
end_ts,
|
end_ts,
|
||||||
|
@ -1252,6 +1274,8 @@ pub enum ErrorCode {
|
||||||
InvalidVestingSchedule,
|
InvalidVestingSchedule,
|
||||||
#[msg("Please specify the correct authority for this program.")]
|
#[msg("Please specify the correct authority for this program.")]
|
||||||
InvalidProgramAuthority,
|
InvalidProgramAuthority,
|
||||||
|
#[msg("Invalid mint supplied")]
|
||||||
|
InvalidMint,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'b, 'c, 'info> From<&mut Deposit<'info>>
|
impl<'a, 'b, 'c, 'info> From<&mut Deposit<'info>>
|
||||||
|
@ -1351,3 +1375,23 @@ pub fn no_available_rewards<'info>(
|
||||||
|
|
||||||
Ok(())
|
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");
|
||||||
|
}
|
||||||
|
|
|
@ -42,12 +42,12 @@ describe("Lockup and Registry", () => {
|
||||||
assert.ok(lockupAccount.authority.equals(provider.wallet.publicKey));
|
assert.ok(lockupAccount.authority.equals(provider.wallet.publicKey));
|
||||||
assert.ok(lockupAccount.whitelist.length === WHITELIST_SIZE);
|
assert.ok(lockupAccount.whitelist.length === WHITELIST_SIZE);
|
||||||
lockupAccount.whitelist.forEach((e) => {
|
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 () => {
|
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, {
|
await lockup.state.rpc.whitelistDelete(defaultEntry, {
|
||||||
accounts: {
|
accounts: {
|
||||||
authority: provider.wallet.publicKey,
|
authority: provider.wallet.publicKey,
|
||||||
|
@ -389,7 +389,7 @@ describe("Lockup and Registry", () => {
|
||||||
|
|
||||||
assert.ok(memberAccount.registrar.equals(registrar.publicKey));
|
assert.ok(memberAccount.registrar.equals(registrar.publicKey));
|
||||||
assert.ok(memberAccount.beneficiary.equals(provider.wallet.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(
|
assert.equal(
|
||||||
JSON.stringify(memberAccount.balances),
|
JSON.stringify(memberAccount.balances),
|
||||||
JSON.stringify(balances)
|
JSON.stringify(balances)
|
||||||
|
|
Loading…
Reference in New Issue