-
Notifications
You must be signed in to change notification settings - Fork 24
Airdrop | completion flags #127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
da1f724
d08dd68
145d912
40bcaf1
a8c4823
619eea0
9eb0acf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,46 @@ | ||
use cosmwasm_std::{to_binary, Api, Binary, Env, Extern, HandleResponse, InitResponse, Querier, StdResult, Storage}; | ||
use cosmwasm_std::{to_binary, Api, Binary, Env, Extern, HandleResponse, InitResponse, Querier, StdResult, Storage, Uint128, StdError}; | ||
use shade_protocol::{ | ||
airdrop::{ | ||
InitMsg, HandleMsg, | ||
QueryMsg, Config | ||
} | ||
}; | ||
use crate::{state::{config_w, reward_w, claim_status_w}, | ||
handle::{try_update_config, try_claim}, | ||
handle::{try_update_config, try_add_tasks, try_complete_task, try_claim}, | ||
query }; | ||
use shade_protocol::airdrop::RequiredTask; | ||
|
||
pub fn init<S: Storage, A: Api, Q: Querier>( | ||
deps: &mut Extern<S, A, Q>, | ||
env: Env, | ||
msg: InitMsg, | ||
) -> StdResult<InitResponse> { | ||
|
||
// Setup task claim | ||
let mut task_claim= vec![RequiredTask { | ||
address: env.contract.address, | ||
percent: msg.default_claim | ||
}]; | ||
let mut claim = msg.task_claim; | ||
task_claim.append(&mut claim); | ||
|
||
// Validate claim percentage | ||
let mut count = Uint128::zero(); | ||
for claim in task_claim.iter() { | ||
count += claim.percent; | ||
} | ||
FloppyDisck marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if count > Uint128(100) { | ||
return Err(StdError::GenericErr { msg: "tasks above 100%".to_string(), backtrace: None }) | ||
} | ||
Comment on lines
+33
to
+35
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you switch to decimal this can be
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You would need to convert everything to decimal for that since Uint128 and Decimal dont match when comparing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But for the purposes of a percentage, integer precision is entirely inadequate and is guaranteed to introduce error into the calculation. It also disallows having any kind of resolution when setting/using these values. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Considering the amount is already in uShade, any "decimal" value will still be ignored when claiming so it wouldn't make a difference There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see no reason for this to be integers, the calculation will be inaccurate and there will be lots of error. But if that doesn't matter I will approve. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It does matter but decimals doesn't provide a solution for when the number is inevitably converted back into Uint128. Maybe a final calculation once that user's airdrop completion is 100% could give him the possible 1-2 uToken loss |
||
|
||
let config = Config{ | ||
admin: match msg.admin { | ||
None => { env.message.sender.clone() } | ||
Some(admin) => { admin } | ||
}, | ||
airdrop_snip20: msg.airdrop_snip20.clone(), | ||
airdrop_snip20: msg.airdrop_token.clone(), | ||
task_claim, | ||
start_date: match msg.start_time { | ||
None => env.block.time, | ||
Some(date) => date | ||
|
@@ -34,7 +55,8 @@ pub fn init<S: Storage, A: Api, Q: Querier>( | |
let key = reward.address.to_string(); | ||
|
||
reward_w(&mut deps.storage).save(key.as_bytes(), &reward)?; | ||
claim_status_w(&mut deps.storage).save(key.as_bytes(), &false)?; | ||
// Save the initial claim | ||
claim_status_w(&mut deps.storage, 0).save(key.as_bytes(), &false)?; | ||
} | ||
|
||
Ok(InitResponse { | ||
|
@@ -52,6 +74,10 @@ pub fn handle<S: Storage, A: Api, Q: Querier>( | |
HandleMsg::UpdateConfig { | ||
admin, start_date, end_date | ||
} => try_update_config(deps, env, admin, start_date, end_date), | ||
HandleMsg::AddTasks { tasks | ||
} => try_add_tasks(deps, &env, tasks), | ||
HandleMsg::CompleteTask { address | ||
} => try_complete_task(deps, &env, address), | ||
HandleMsg::Claim { } => try_claim(deps, &env), | ||
} | ||
} | ||
|
@@ -66,4 +92,4 @@ pub fn query<S: Storage, A: Api, Q: Querier>( | |
QueryMsg::GetEligibility { address } => to_binary( | ||
&query::airdrop_amount(&deps, address)?), | ||
} | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.