Skip to content

Commit

Permalink
Update dependencies (#166)
Browse files Browse the repository at this point in the history
* added padding

* updated tests

* fixed privacy leak

* updated documentation

* updated dependencies

* fixed dep update conflicts

Co-authored-by: Guy Garcia <[email protected]>
Co-authored-by: Guy S Garcia <[email protected]>
Co-authored-by: Guy <[email protected]>
  • Loading branch information
4 people authored Jan 17, 2022
1 parent fb5ff9c commit 1dd88cd
Show file tree
Hide file tree
Showing 23 changed files with 117 additions and 50 deletions.
4 changes: 2 additions & 2 deletions contracts/airdrop/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ debug-print = ["cosmwasm-std/debug-print"]

[dependencies]
cosmwasm-std = { version = "0.10", package = "secret-cosmwasm-std" }
cosmwasm-schema = { git = "https://github.com/scrtlabs/SecretNetwork", tag = "v1.0.4-debug-print" }
cosmwasm-storage = { version = "0.10", package = "secret-cosmwasm-storage" }
cosmwasm-schema = "0.10.1"
secret-toolkit = { version = "0.2" }
shade-protocol = { version = "0.1.0", path = "../../packages/shade_protocol" }
schemars = "0.7"
Expand All @@ -38,4 +38,4 @@ mockall = "0.10.2"
mockall_double = "0.2.0"

[dev-dependencies]
flexible-permits = {git = "https://github.com/securesecrets/flexible-permits", tag = "v1.0.0"}
flexible-permits = {git = "https://github.com/securesecrets/flexible-permits", tag = "v1.0.1"}
50 changes: 43 additions & 7 deletions contracts/airdrop/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
* Messages
* [CreateAccount](#CreateAccount)
* [UpdateAccount](#UpdateAccount)
* [DisablePermitKey](#DisablePermitKey)
* [Claim](#Claim)
* Queries
* [GetConfig](#GetConfig)
* [GetDates](#GetDates)
* [GetAccount](#GetAccount)
* [Config](#Config)
* [Dates](#Dates)
* [TotalClaimed](#TotalClaimed)
* [Account](#Account)

# Introduction
Contract responsible to handle snip20 airdrop
Expand All @@ -42,6 +44,7 @@ Contract responsible to handle snip20 airdrop
|max_amount | String | Used to limit the user permit amounts (lowers exploit possibility) | no|
|default_claim | String | The default amount to be gifted regardless of tasks | no |
|task_claim | RequiredTasks | The amounts per tasks to gift | no |
|query_rounding | string | To prevent leaking information, total claimed is rounded off to this value | no

##Admin

Expand All @@ -57,13 +60,15 @@ Updates the given values
|start_date | u64 | When the airdrop starts in UNIX time | yes |
|end_date | u64 | When the airdrop ends in UNIX time | yes |
|decay_start | u64 | When the airdrop decay starts in UNIX time | yes |
|padding | string | Allows for enforcing constant length messages | yes |

#### AddTasks
Adds more tasks to complete
##### Request
|Name |Type |Description | optional |
|------|-------|---------------------------|----------|
|Tasks | Tasks | The new tasks to be added | no |
|tasks | Tasks | The new tasks to be added | no |
|padding | string | Allows for enforcing constant length messages | yes |

##### Response
```json
Expand Down Expand Up @@ -96,6 +101,7 @@ Complete that address' tasks for a given user
|Name |Type |Description | optional |
|--------|--------|-------------------------------------|----------|
|address | String | The address that completed the task | no |
|padding | string | Allows for enforcing constant length messages | yes |

##### Response
```json
Expand All @@ -117,6 +123,7 @@ Creates an account from which the user will claim all of his given addresses' re
|-----------|----------------------------------|------------------------------------------|----------|
| addresses | Array of [AddressProofPermit](#AddressProofPermit) | Proof that the user owns those addresses | no |
| partial_tree | Array of string | An array of nodes that serve as a proof for the addresses | no |
|padding | string | Allows for enforcing constant length messages | yes |

##### Response
```json
Expand All @@ -134,6 +141,7 @@ Updates a users accounts with more addresses
|-----------|-----------------------------|------------------------------------------|----------|
| addresses | Array of [AddressProofPermit](#AddressProofPermit) | Proof that the user owns those addresses | no |
| partial_tree | Array of string | An array of nodes that serve as a proof for the addresses | no |
|padding | string | Allows for enforcing constant length messages | yes |

##### Response
```json
Expand All @@ -144,6 +152,23 @@ Updates a users accounts with more addresses
}
```

### DisablePermitKey
Disables that permit's key. Any permit that has that key for that address will be declined.
##### Request
| Name | Type | Description | optional |
|-----------|-----------------------------|------------------------------------------|----------|
| key | string | Permit key | no |
|padding | string | Allows for enforcing constant length messages | yes |

##### Response
```json
{
"disable_permit_key": {
"status": "success"
}
}
```

#### Claim
Claim the user's available claimable amount

Expand All @@ -169,7 +194,7 @@ Gets the contract's config
}
```

## GetDates
## Dates
Get the contracts airdrop timeframe, can calculate the decay factor if a time is given
##### Request
|Name |Type |Description | optional |
Expand All @@ -186,7 +211,18 @@ Get the contracts airdrop timeframe, can calculate the decay factor if a time is
}
```

## GetAccount
## TotalClaimed
Shows the total amount of the token that has been claimed. If airdrop hasn't ended then it'll just show an estimation.
##### Request
```json
{
"total_claimed": {
"claimed": "Claimed amount"
}
}
```

## Account
Get the account's information
##### Request
|Name |Type |Description | optional |
Expand All @@ -195,7 +231,7 @@ Get the account's information
|current_date | u64 | Current time in UNIT format | yes |
```json
{
"eligibility": {
"account": {
"total": "Total airdrop amount",
"claimed": "Claimed amount",
"unclaimed": "Amount available to claim",
Expand Down
25 changes: 16 additions & 9 deletions contracts/airdrop/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ use cosmwasm_std::{
Uint128,
};
use shade_protocol::airdrop::{claim_info::RequiredTask, Config, HandleMsg, InitMsg, QueryMsg};
use secret_toolkit::utils::{pad_handle_result, pad_query_result};

// Used to pad up responses for better privacy.
pub const RESPONSE_BLOCK_SIZE: usize = 256;

pub fn init<S: Storage, A: Api, Q: Querier>(
deps: &mut Extern<S, A, Q>,
Expand Down Expand Up @@ -119,14 +123,15 @@ pub fn handle<S: Storage, A: Api, Q: Querier>(
env: Env,
msg: HandleMsg,
) -> StdResult<HandleResponse> {
match msg {
pad_handle_result(match msg {
HandleMsg::UpdateConfig {
admin,
dump_address,
query_rounding: redeem_step_size,
start_date,
end_date,
decay_start: start_decay,
..
} => try_update_config(
deps,
env,
Expand All @@ -137,33 +142,35 @@ pub fn handle<S: Storage, A: Api, Q: Querier>(
end_date,
start_decay,
),
HandleMsg::AddTasks { tasks } => try_add_tasks(deps, &env, tasks),
HandleMsg::CompleteTask { address } => try_complete_task(deps, &env, address),
HandleMsg::AddTasks { tasks, .. } => try_add_tasks(deps, &env, tasks),
HandleMsg::CompleteTask { address, .. } => try_complete_task(deps, &env, address),
HandleMsg::CreateAccount {
addresses,
partial_tree,
..
} => try_create_account(deps, &env, addresses, partial_tree),
HandleMsg::UpdateAccount {
addresses,
partial_tree,
..
} => try_update_account(deps, &env, addresses, partial_tree),
HandleMsg::DisablePermitKey { key } => try_disable_permit_key(deps, &env, key),
HandleMsg::Claim {} => try_claim(deps, &env),
HandleMsg::ClaimDecay {} => try_claim_decay(deps, &env),
}
HandleMsg::DisablePermitKey { key, .. } => try_disable_permit_key(deps, &env, key),
HandleMsg::Claim { .. } => try_claim(deps, &env),
HandleMsg::ClaimDecay { .. } => try_claim_decay(deps, &env),
}, RESPONSE_BLOCK_SIZE)
}

pub fn query<S: Storage, A: Api, Q: Querier>(
deps: &Extern<S, A, Q>,
msg: QueryMsg,
) -> StdResult<Binary> {
match msg {
pad_query_result(match msg {
QueryMsg::Config {} => to_binary(&query::config(deps)?),
QueryMsg::Dates { current_date } => to_binary(&query::dates(deps, current_date)?),
QueryMsg::TotalClaimed {} => to_binary(&query::total_claimed(deps)?),
QueryMsg::Account {
permit,
current_date,
} => to_binary(&query::account(deps, permit, current_date)?),
}
}, RESPONSE_BLOCK_SIZE)
}
4 changes: 4 additions & 0 deletions contracts/airdrop/src/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ pub fn try_create_account<S: Storage, A: Api, Q: Querier>(
redeem_amount,
None,
None,
None,
0,
config.airdrop_snip20.code_hash,
config.airdrop_snip20.address,
Expand Down Expand Up @@ -323,6 +324,7 @@ pub fn try_update_account<S: Storage, A: Api, Q: Querier>(
redeem_amount,
None,
None,
None,
0,
config.airdrop_snip20.code_hash,
config.airdrop_snip20.address,
Expand Down Expand Up @@ -426,6 +428,7 @@ pub fn try_claim<S: Storage, A: Api, Q: Querier>(
redeem_amount,
None,
None,
None,
0,
config.airdrop_snip20.code_hash,
config.airdrop_snip20.address,
Expand Down Expand Up @@ -462,6 +465,7 @@ pub fn try_claim_decay<S: Storage, A: Api, Q: Querier>(
send_total,
None,
None,
None,
1,
config.airdrop_snip20.code_hash,
config.airdrop_snip20.address,
Expand Down
1 change: 0 additions & 1 deletion contracts/airdrop/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use shade_protocol::{
pub fn config<S: Storage, A: Api, Q: Querier>(deps: &Extern<S, A, Q>) -> StdResult<QueryAnswer> {
Ok(QueryAnswer::Config {
config: config_r(&deps.storage).load()?,
total_claimed: total_claimed_r(&deps.storage).load()?,
})
}

Expand Down
13 changes: 4 additions & 9 deletions contracts/airdrop/src/test.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
#[cfg(test)]
pub mod tests {
use crate::{contract::init, handle::inverse_normalizer};
use crate::handle::inverse_normalizer;
use cosmwasm_std::{
testing::{mock_dependencies, mock_env},
Binary,
CanonicalAddr,
HumanAddr,
Uint128,
};
Expand All @@ -15,10 +13,7 @@ pub mod tests {
use shade_protocol::{
airdrop::{
account::{AddressProofMsg, AddressProofPermit},
claim_info::RequiredTask,
InitMsg,
},
asset::Contract,
math::{div, mult},
};

Expand Down Expand Up @@ -59,7 +54,7 @@ pub mod tests {
let permit_addr = permit.validate().expect("Signature validation failed");
assert_eq!(
permit_addr.as_canonical(),
bech32_to_canonical(permit.params.address.clone().as_str())
bech32_to_canonical(permit.params.address.as_str())
);
assert_ne!(
permit_addr.as_canonical(),
Expand Down Expand Up @@ -94,7 +89,7 @@ pub mod tests {
let permit_addr = permit.validate().expect("Signature validation failed");
assert_eq!(
permit_addr.as_canonical(),
bech32_to_canonical(permit.params.address.clone().as_str())
bech32_to_canonical(permit.params.address.as_str())
);
assert_ne!(
permit_addr.as_canonical(),
Expand Down Expand Up @@ -129,7 +124,7 @@ pub mod tests {
let permit_addr = permit.validate().expect("Signature validation failed");
assert_eq!(
permit_addr.as_canonical(),
bech32_to_canonical(permit.params.address.clone().as_str())
bech32_to_canonical(permit.params.address.as_str())
);
assert_ne!(
permit_addr.as_canonical(),
Expand Down
2 changes: 1 addition & 1 deletion contracts/governance/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ debug-print = ["cosmwasm-std/debug-print"]

[dependencies]
cosmwasm-std = { version = "0.10", package = "secret-cosmwasm-std" }
cosmwasm-schema = { git = "https://github.com/scrtlabs/SecretNetwork", tag = "v1.0.4-debug-print" }
cosmwasm-storage = { version = "0.10", package = "secret-cosmwasm-storage" }
cosmwasm-schema = "0.10.1"
secret-toolkit = { version = "0.2" }
shade-protocol = { version = "0.1.0", path = "../../packages/shade_protocol" }
schemars = "0.7"
Expand Down
3 changes: 2 additions & 1 deletion contracts/governance/src/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ use cosmwasm_std::{
Uint128,
WasmMsg,
};
use secret_toolkit::snip20::{batch_send_msg, send_msg, SendAction};
use secret_toolkit::snip20::{batch_send_msg, send_msg, batch::SendAction};
use shade_protocol::{
asset::Contract,
generic_response::{
Expand Down Expand Up @@ -213,6 +213,7 @@ pub fn try_fund_proposal<S: Storage, A: Api, Q: Querier>(
if let Some(mut amounts) = amounts {
amounts.push(SendAction {
recipient: sender.clone(),
recipient_code_hash: None,
amount: adjusted_amount,
msg: None,
memo: None,
Expand Down
2 changes: 1 addition & 1 deletion contracts/initializer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ debug-print = ["cosmwasm-std/debug-print"]

[dependencies]
cosmwasm-std = { version = "0.10", package = "secret-cosmwasm-std" }
cosmwasm-schema = { git = "https://github.com/scrtlabs/SecretNetwork", tag = "v1.0.4-debug-print" }
cosmwasm-storage = { version = "0.10", package = "secret-cosmwasm-storage" }
cosmwasm-schema = "0.10.1"
secret-toolkit = { version = "0.2" }
shade-protocol = { version = "0.1.0", path = "../../packages/shade_protocol" }
schemars = "0.7"
Expand Down
2 changes: 1 addition & 1 deletion contracts/micro_mint/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ debug-print = ["cosmwasm-std/debug-print"]

[dependencies]
cosmwasm-std = { version = "0.10", package = "secret-cosmwasm-std" }
cosmwasm-schema = { git = "https://github.com/scrtlabs/SecretNetwork", tag = "v1.0.4-debug-print" }
cosmwasm-storage = { version = "0.10", package = "secret-cosmwasm-storage" }
cosmwasm-schema = "0.10.1"
secret-toolkit = { version = "0.2" }
shade-protocol = { version = "0.1.0", path = "../../packages/shade_protocol" }
schemars = "0.7"
Expand Down
5 changes: 5 additions & 0 deletions contracts/micro_mint/src/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ pub fn try_burn<S: Storage, A: Api, Q: Querier>(
capture_amount,
None,
None,
None,
1,
burn_asset.asset.contract.code_hash.clone(),
burn_asset.asset.contract.address.clone(),
Expand All @@ -152,6 +153,7 @@ pub fn try_burn<S: Storage, A: Api, Q: Querier>(
messages.push(burn_msg(
burn_amount,
None,
None,
256,
burn_asset.asset.contract.code_hash.clone(),
burn_asset.asset.contract.address.clone(),
Expand All @@ -162,6 +164,7 @@ pub fn try_burn<S: Storage, A: Api, Q: Querier>(
burn_amount,
None,
None,
None,
1,
burn_asset.asset.contract.code_hash.clone(),
burn_asset.asset.contract.address.clone(),
Expand All @@ -173,6 +176,7 @@ pub fn try_burn<S: Storage, A: Api, Q: Querier>(
burn_amount,
None,
None,
None,
1,
burn_asset.asset.contract.code_hash.clone(),
burn_asset.asset.contract.address.clone(),
Expand Down Expand Up @@ -235,6 +239,7 @@ pub fn try_burn<S: Storage, A: Api, Q: Querier>(
from,
amount_to_mint,
None,
None,
256,
mint_asset.contract.code_hash.clone(),
mint_asset.contract.address,
Expand Down
Loading

0 comments on commit 1dd88cd

Please sign in to comment.