Skip to content

Commit

Permalink
Improve logic for funded/fully funded and keep track of initial due i…
Browse files Browse the repository at this point in the history
…n escrows
  • Loading branch information
ismellike committed Dec 6, 2023
1 parent 86964cf commit 123ca94
Show file tree
Hide file tree
Showing 14 changed files with 451 additions and 181 deletions.
2 changes: 1 addition & 1 deletion contracts/arena-core/schema/arena-core.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"contract_name": "arena-core",
"contract_version": "0.9.0",
"contract_version": "0.9.5",
"idl_version": "1.0.0",
"instantiate": {
"$schema": "http://json-schema.org/draft-07/schema#",
Expand Down
277 changes: 216 additions & 61 deletions contracts/arena-escrow/schema/arena-escrow.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"contract_name": "arena-escrow",
"contract_version": "0.9.0",
"contract_version": "0.9.5",
"idl_version": "1.0.0",
"instantiate": {
"$schema": "http://json-schema.org/draft-07/schema#",
Expand Down Expand Up @@ -569,6 +569,35 @@
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"initial_dues"
],
"properties": {
"initial_dues": {
"type": "object",
"properties": {
"limit": {
"type": [
"integer",
"null"
],
"format": "uint32",
"minimum": 0.0
},
"start_after": {
"type": [
"string",
"null"
]
}
},
"additionalProperties": false
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
Expand Down Expand Up @@ -710,39 +739,49 @@
"responses": {
"balance": {
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "BalanceVerified",
"type": "object",
"required": [
"cw20",
"cw721",
"native"
],
"properties": {
"cw20": {
"type": "array",
"items": {
"$ref": "#/definitions/Cw20CoinVerified"
}
},
"cw721": {
"type": "array",
"items": {
"$ref": "#/definitions/Cw721CollectionVerified"
}
"title": "Nullable_BalanceVerified",
"anyOf": [
{
"$ref": "#/definitions/BalanceVerified"
},
"native": {
"type": "array",
"items": {
"$ref": "#/definitions/Coin"
}
{
"type": "null"
}
},
"additionalProperties": false,
],
"definitions": {
"Addr": {
"description": "A human readable address.\n\nIn Cosmos, this is typically bech32 encoded. But for multi-chain smart contracts no assumptions should be made other than being UTF-8 encoded and of reasonable length.\n\nThis type represents a validated address. It can be created in the following ways 1. Use `Addr::unchecked(input)` 2. Use `let checked: Addr = deps.api.addr_validate(input)?` 3. Use `let checked: Addr = deps.api.addr_humanize(canonical_addr)?` 4. Deserialize from JSON. This must only be done from JSON that was validated before such as a contract's state. `Addr` must not be used in messages sent by the user because this would result in unvalidated instances.\n\nThis type is immutable. If you really need to mutate it (Really? Are you sure?), create a mutable copy using `let mut mutable = Addr::to_string()` and operate on that `String` instance.",
"type": "string"
},
"BalanceVerified": {
"type": "object",
"required": [
"cw20",
"cw721",
"native"
],
"properties": {
"cw20": {
"type": "array",
"items": {
"$ref": "#/definitions/Cw20CoinVerified"
}
},
"cw721": {
"type": "array",
"items": {
"$ref": "#/definitions/Cw721CollectionVerified"
}
},
"native": {
"type": "array",
"items": {
"$ref": "#/definitions/Coin"
}
}
},
"additionalProperties": false
},
"Coin": {
"type": "object",
"required": [
Expand Down Expand Up @@ -944,39 +983,49 @@
},
"due": {
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "BalanceVerified",
"type": "object",
"required": [
"cw20",
"cw721",
"native"
],
"properties": {
"cw20": {
"type": "array",
"items": {
"$ref": "#/definitions/Cw20CoinVerified"
}
},
"cw721": {
"type": "array",
"items": {
"$ref": "#/definitions/Cw721CollectionVerified"
}
"title": "Nullable_BalanceVerified",
"anyOf": [
{
"$ref": "#/definitions/BalanceVerified"
},
"native": {
"type": "array",
"items": {
"$ref": "#/definitions/Coin"
}
{
"type": "null"
}
},
"additionalProperties": false,
],
"definitions": {
"Addr": {
"description": "A human readable address.\n\nIn Cosmos, this is typically bech32 encoded. But for multi-chain smart contracts no assumptions should be made other than being UTF-8 encoded and of reasonable length.\n\nThis type represents a validated address. It can be created in the following ways 1. Use `Addr::unchecked(input)` 2. Use `let checked: Addr = deps.api.addr_validate(input)?` 3. Use `let checked: Addr = deps.api.addr_humanize(canonical_addr)?` 4. Deserialize from JSON. This must only be done from JSON that was validated before such as a contract's state. `Addr` must not be used in messages sent by the user because this would result in unvalidated instances.\n\nThis type is immutable. If you really need to mutate it (Really? Are you sure?), create a mutable copy using `let mut mutable = Addr::to_string()` and operate on that `String` instance.",
"type": "string"
},
"BalanceVerified": {
"type": "object",
"required": [
"cw20",
"cw721",
"native"
],
"properties": {
"cw20": {
"type": "array",
"items": {
"$ref": "#/definitions/Cw20CoinVerified"
}
},
"cw721": {
"type": "array",
"items": {
"$ref": "#/definitions/Cw721CollectionVerified"
}
},
"native": {
"type": "array",
"items": {
"$ref": "#/definitions/Coin"
}
}
},
"additionalProperties": false
},
"Coin": {
"type": "object",
"required": [
Expand Down Expand Up @@ -1151,20 +1200,29 @@
"title": "DumpStateResponse",
"type": "object",
"required": [
"balance",
"dues",
"is_locked",
"total_balance"
],
"properties": {
"balance": {
"$ref": "#/definitions/BalanceVerified"
"anyOf": [
{
"$ref": "#/definitions/BalanceVerified"
},
{
"type": "null"
}
]
},
"dues": {
"type": "array",
"items": {
"$ref": "#/definitions/MemberBalanceVerified"
}
"due": {
"anyOf": [
{
"$ref": "#/definitions/BalanceVerified"
},
{
"type": "null"
}
]
},
"is_locked": {
"type": "boolean"
Expand All @@ -1174,6 +1232,103 @@
}
},
"additionalProperties": false,
"definitions": {
"Addr": {
"description": "A human readable address.\n\nIn Cosmos, this is typically bech32 encoded. But for multi-chain smart contracts no assumptions should be made other than being UTF-8 encoded and of reasonable length.\n\nThis type represents a validated address. It can be created in the following ways 1. Use `Addr::unchecked(input)` 2. Use `let checked: Addr = deps.api.addr_validate(input)?` 3. Use `let checked: Addr = deps.api.addr_humanize(canonical_addr)?` 4. Deserialize from JSON. This must only be done from JSON that was validated before such as a contract's state. `Addr` must not be used in messages sent by the user because this would result in unvalidated instances.\n\nThis type is immutable. If you really need to mutate it (Really? Are you sure?), create a mutable copy using `let mut mutable = Addr::to_string()` and operate on that `String` instance.",
"type": "string"
},
"BalanceVerified": {
"type": "object",
"required": [
"cw20",
"cw721",
"native"
],
"properties": {
"cw20": {
"type": "array",
"items": {
"$ref": "#/definitions/Cw20CoinVerified"
}
},
"cw721": {
"type": "array",
"items": {
"$ref": "#/definitions/Cw721CollectionVerified"
}
},
"native": {
"type": "array",
"items": {
"$ref": "#/definitions/Coin"
}
}
},
"additionalProperties": false
},
"Coin": {
"type": "object",
"required": [
"amount",
"denom"
],
"properties": {
"amount": {
"$ref": "#/definitions/Uint128"
},
"denom": {
"type": "string"
}
}
},
"Cw20CoinVerified": {
"type": "object",
"required": [
"address",
"amount"
],
"properties": {
"address": {
"$ref": "#/definitions/Addr"
},
"amount": {
"$ref": "#/definitions/Uint128"
}
},
"additionalProperties": false
},
"Cw721CollectionVerified": {
"type": "object",
"required": [
"address",
"token_ids"
],
"properties": {
"address": {
"$ref": "#/definitions/Addr"
},
"token_ids": {
"type": "array",
"items": {
"type": "string"
}
}
},
"additionalProperties": false
},
"Uint128": {
"description": "A thin wrapper around u128 that is using strings for JSON encoding/decoding, such that the full u128 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u128` to get the value out:\n\n``` # use cosmwasm_std::Uint128; let a = Uint128::from(123u128); assert_eq!(a.u128(), 123);\n\nlet b = Uint128::from(42u64); assert_eq!(b.u128(), 42);\n\nlet c = Uint128::from(70u32); assert_eq!(c.u128(), 70); ```",
"type": "string"
}
}
},
"initial_dues": {
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Array_of_MemberBalanceVerified",
"type": "array",
"items": {
"$ref": "#/definitions/MemberBalanceVerified"
},
"definitions": {
"Addr": {
"description": "A human readable address.\n\nIn Cosmos, this is typically bech32 encoded. But for multi-chain smart contracts no assumptions should be made other than being UTF-8 encoded and of reasonable length.\n\nThis type represents a validated address. It can be created in the following ways 1. Use `Addr::unchecked(input)` 2. Use `let checked: Addr = deps.api.addr_validate(input)?` 3. Use `let checked: Addr = deps.api.addr_humanize(canonical_addr)?` 4. Deserialize from JSON. This must only be done from JSON that was validated before such as a contract's state. `Addr` must not be used in messages sent by the user because this would result in unvalidated instances.\n\nThis type is immutable. If you really need to mutate it (Really? Are you sure?), create a mutable copy using `let mut mutable = Addr::to_string()` and operate on that `String` instance.",
Expand Down
11 changes: 7 additions & 4 deletions contracts/arena-escrow/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{
execute,
msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg},
query,
state::{DUE, IS_FUNDED, IS_LOCKED, TOTAL_BALANCE},
state::{self, DUE, INITIAL_DUE, IS_LOCKED, TOTAL_BALANCE},
ContractError,
};
use cosmwasm_std::{
Expand Down Expand Up @@ -43,16 +43,16 @@ pub fn instantiate_contract(
for member_balance in due {
let member_balance = member_balance.to_verified(deps.as_ref())?;

if DUE.has(deps.storage, &member_balance.addr) {
if INITIAL_DUE.has(deps.storage, &member_balance.addr) {
return Err(ContractError::StdError(
cosmwasm_std::StdError::GenericErr {
msg: "Cannot have duplicate addresses due".to_string(),
},
));
}

INITIAL_DUE.save(deps.storage, &member_balance.addr, &member_balance.balance)?;
DUE.save(deps.storage, &member_balance.addr, &member_balance.balance)?;
IS_FUNDED.save(deps.storage, &member_balance.addr, &false)?;
}
TOTAL_BALANCE.save(deps.storage, &BalanceVerified::new())?;

Expand Down Expand Up @@ -104,13 +104,16 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
QueryMsg::IsLocked {} => to_json_binary(&query::is_locked(deps)),
QueryMsg::Distribution { addr } => to_json_binary(&query::distribution(deps, addr)?),
QueryMsg::IsFunded { addr } => to_json_binary(&query::is_funded(deps, addr)?),
QueryMsg::IsFullyFunded {} => to_json_binary(&query::is_fully_funded(deps)?),
QueryMsg::IsFullyFunded {} => to_json_binary(&state::is_fully_funded(deps)),
QueryMsg::Balances { start_after, limit } => {
to_json_binary(&query::balances(deps, start_after, limit)?)
}
QueryMsg::Dues { start_after, limit } => {
to_json_binary(&query::dues(deps, start_after, limit)?)
}
QueryMsg::InitialDues { start_after, limit } => {
to_json_binary(&query::initial_dues(deps, start_after, limit)?)
}
QueryMsg::Ownership {} => to_json_binary(&cw_ownable::get_ownership(deps.storage)?),
QueryMsg::DumpState { addr } => to_json_binary(&query::dump_state(deps, addr)?),
}
Expand Down
Loading

0 comments on commit 123ca94

Please sign in to comment.