diff --git a/tee-worker/litentry/core/assertion-build-v2/src/token_holding_amount/mod.rs b/tee-worker/litentry/core/assertion-build-v2/src/token_holding_amount/mod.rs index 4082d9f593..f2e6112bec 100644 --- a/tee-worker/litentry/core/assertion-build-v2/src/token_holding_amount/mod.rs +++ b/tee-worker/litentry/core/assertion-build-v2/src/token_holding_amount/mod.rs @@ -447,13 +447,8 @@ mod tests { create_network_address_assertion_logics(Web3TokenType::Nfp), Box::new(AssertionLogic::Item { src: "$holding_amount".into(), - op: Op::GreaterEq, + op: Op::GreaterThan, dst: "0".into() - }), - Box::new(AssertionLogic::Item { - src: "$holding_amount".into(), - op: Op::LessThan, - dst: "1".into() }) ] } @@ -483,7 +478,7 @@ mod tests { create_network_address_assertion_logics(Web3TokenType::Nfp), Box::new(AssertionLogic::Item { src: "$holding_amount".into(), - op: Op::GreaterEq, + op: Op::GreaterThan, dst: "0".into() }), Box::new(AssertionLogic::Item { diff --git a/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/token_holding_amount/TokenHoldingAmount.sol b/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/token_holding_amount/TokenHoldingAmount.sol index 0369cd2f5a..2760f1c167 100644 --- a/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/token_holding_amount/TokenHoldingAmount.sol +++ b/tee-worker/litentry/core/assertion-build/src/dynamic/contracts/token_holding_amount/TokenHoldingAmount.sol @@ -45,7 +45,7 @@ abstract contract TokenHoldingAmount is DynamicAssertion { string memory description = "The amount of a particular token you are holding"; string memory assertion_type = "Token Holding Amount"; - schema_url = "https://raw.githubusercontent.com/litentry/vc-jsonschema/main/dist/schemas/25-token-holding-amount/1-1-3.json"; + schema_url = "https://raw.githubusercontent.com/litentry/vc-jsonschema/main/dist/schemas/25-token-holding-amount/1-1-4.json"; string memory tokenLowercaseName = abi.decode(params, (string)); @@ -68,6 +68,7 @@ abstract contract TokenHoldingAmount is DynamicAssertion { string[] memory assertions = assembleAssertions( min, max, + balance, tokenLowercaseName ); @@ -134,12 +135,13 @@ abstract contract TokenHoldingAmount is DynamicAssertion { function assembleAssertions( uint256 min, int256 max, + uint256 balance, string memory tokenName ) private pure returns (string[] memory) { string memory variable = "$holding_amount"; AssertionLogic.CompositeCondition memory cc = AssertionLogic .CompositeCondition( - new AssertionLogic.Condition[](max > 0 ? 3 : 2), + new AssertionLogic.Condition[](max > 0 && balance > 0 ? 3 : 2), true ); AssertionLogic.andOp( @@ -153,10 +155,12 @@ abstract contract TokenHoldingAmount is DynamicAssertion { cc, 1, variable, - AssertionLogic.Op.GreaterEq, + min == 0 + ? AssertionLogic.Op.GreaterThan + : AssertionLogic.Op.GreaterEq, StringShift.toShiftedString(min, Constants.decimals_factor) ); - if (max > 0) { + if (max > 0 && balance > 0) { AssertionLogic.andOp( cc, 2, diff --git a/tee-worker/litentry/core/assertion-build/src/dynamic/tests/token-holding-amount.ts b/tee-worker/litentry/core/assertion-build/src/dynamic/tests/token-holding-amount.ts index d422acbc9f..067401fb20 100644 --- a/tee-worker/litentry/core/assertion-build/src/dynamic/tests/token-holding-amount.ts +++ b/tee-worker/litentry/core/assertion-build/src/dynamic/tests/token-holding-amount.ts @@ -29,7 +29,7 @@ describe('TokenHoldingAmount', () => { await expectAssertionResult(contract, val, { tokenType: 'Token Holding Amount', tokenDesc: 'The amount of a particular token you are holding', - schemaUrl: assembleSchemaUrl('25-token-holding-amount/1-1-3.json'), + schemaUrl: assembleSchemaUrl('25-token-holding-amount/1-1-4.json'), assertions: [assertion], result, }) @@ -54,14 +54,9 @@ describe('TokenHoldingAmount', () => { }, { src: '$holding_amount', - op: Op.GTE, + op: Op.GT, dst: '0', }, - { - src: '$holding_amount', - op: Op.LT, - dst: '1', - }, ], }, false @@ -118,7 +113,7 @@ describe('TokenHoldingAmount', () => { }, { src: '$holding_amount', - op: Op.GTE, + op: Op.GT, dst: '0', }, { diff --git a/tee-worker/litentry/core/assertion-build/src/nodereal/amount_holding/evm_amount_holding.rs b/tee-worker/litentry/core/assertion-build/src/nodereal/amount_holding/evm_amount_holding.rs index a316c996ad..638a046244 100644 --- a/tee-worker/litentry/core/assertion-build/src/nodereal/amount_holding/evm_amount_holding.rs +++ b/tee-worker/litentry/core/assertion-build/src/nodereal/amount_holding/evm_amount_holding.rs @@ -226,7 +226,7 @@ mod tests { create_ton_network_assertion_logic(), Box::new(AssertionLogic::Item { src: "$holding_amount".into(), - op: Op::GreaterEq, + op: Op::GreaterThan, dst: "0".into() }), Box::new(AssertionLogic::Item { diff --git a/tee-worker/litentry/core/credentials-v2/src/token_holding_amount/mod.rs b/tee-worker/litentry/core/credentials-v2/src/token_holding_amount/mod.rs index 24451ba6bb..c0a7aeb7aa 100644 --- a/tee-worker/litentry/core/credentials-v2/src/token_holding_amount/mod.rs +++ b/tee-worker/litentry/core/credentials-v2/src/token_holding_amount/mod.rs @@ -86,13 +86,18 @@ fn update_assertion(token_type: Web3TokenType, balance: f64, credential: &mut Cr Some(index) => { let min = format!("{}", token_holding_amount_range[index]); let max = format!("{}", token_holding_amount_range[index + 1]); - let min_item = - AssertionLogic::new_item(ASSERTION_KEYS.holding_amount, Op::GreaterEq, &min); - let max_item = - AssertionLogic::new_item(ASSERTION_KEYS.holding_amount, Op::LessThan, &max); + let min_item = AssertionLogic::new_item( + ASSERTION_KEYS.holding_amount, + if index == 0 { Op::GreaterThan } else { Op::GreaterEq }, + &min, + ); assertion = assertion.add_item(min_item); - assertion = assertion.add_item(max_item); + if balance > 0_f64 { + let max_item = + AssertionLogic::new_item(ASSERTION_KEYS.holding_amount, Op::LessThan, &max); + assertion = assertion.add_item(max_item); + } credential.credential_subject.values.push(index != 0 || balance > 0_f64); }, diff --git a/tee-worker/litentry/core/credentials/src/brc20/amount_holder.rs b/tee-worker/litentry/core/credentials/src/brc20/amount_holder.rs index 770615ab44..f390565a72 100644 --- a/tee-worker/litentry/core/credentials/src/brc20/amount_holder.rs +++ b/tee-worker/litentry/core/credentials/src/brc20/amount_holder.rs @@ -150,13 +150,18 @@ fn update_assertion(token: &BRC20Token, balance: f64, credential: &mut Credentia Some(index) => { let min = format!("{}", range[index]); let max = format!("{}", range[index + 1]); - let min_item = - AssertionLogic::new_item(ASSERTION_KEYS.holding_amount, Op::GreaterEq, &min); - let max_item = - AssertionLogic::new_item(ASSERTION_KEYS.holding_amount, Op::LessThan, &max); + let min_item = AssertionLogic::new_item( + ASSERTION_KEYS.holding_amount, + if index == 0 { Op::GreaterThan } else { Op::GreaterEq }, + &min, + ); assertion = assertion.add_item(min_item); - assertion = assertion.add_item(max_item); + if balance > 0_f64 { + let max_item = + AssertionLogic::new_item(ASSERTION_KEYS.holding_amount, Op::LessThan, &max); + assertion = assertion.add_item(max_item); + } credential.credential_subject.values.push(index != 0 || balance > 0_f64); }, diff --git a/tee-worker/litentry/core/credentials/src/credential_schema.rs b/tee-worker/litentry/core/credentials/src/credential_schema.rs index be4d9019e1..282861d912 100644 --- a/tee-worker/litentry/core/credentials/src/credential_schema.rs +++ b/tee-worker/litentry/core/credentials/src/credential_schema.rs @@ -52,10 +52,10 @@ pub fn get_schema_url(assertion: &Assertion) -> Option { Assertion::Achainable(params) => match params { AchainableParams::AmountHolding(_) => - Some(format!("{BASE_URL}/17-token-holding-amount/1-1-0.json")), + Some(format!("{BASE_URL}/17-token-holding-amount/1-1-2.json")), AchainableParams::AmountToken(_) => - Some(format!("{BASE_URL}/17-token-holding-amount/1-1-0.json")), + Some(format!("{BASE_URL}/17-token-holding-amount/1-1-2.json")), AchainableParams::Amount(_) => Some(format!("{BASE_URL}/11-token-holder/1-1-0.json")), @@ -86,10 +86,10 @@ pub fn get_schema_url(assertion: &Assertion) -> Option { Some(format!("{BASE_URL}/14-generic-discord-role/1-1-0.json")), Assertion::BnbDomainHolding => - Some(format!("{BASE_URL}/15-bnb-domain-holding-amount/1-1-0.json")), + Some(format!("{BASE_URL}/15-bnb-domain-holding-amount/1-1-1.json")), Assertion::BnbDigitDomainClub(_) => - Some(format!("{BASE_URL}/16-bnb-3d-4d-club-domain-holding-amount/1-1-0.json")), + Some(format!("{BASE_URL}/16-bnb-3d-4d-club-domain-holding-amount/1-1-1.json")), Assertion::VIP3MembershipCard(_) => Some(format!("{BASE_URL}/19-vip3-card-holder/1-1-0.json")), @@ -97,13 +97,13 @@ pub fn get_schema_url(assertion: &Assertion) -> Option { Assertion::WeirdoGhostGangHolder => Some(format!("{BASE_URL}/18-weirdoghostgang-holder/1-1-0.json")), - Assertion::LITStaking => Some(format!("{BASE_URL}/17-token-holding-amount/1-1-0.json")), + Assertion::LITStaking => Some(format!("{BASE_URL}/17-token-holding-amount/1-1-2.json")), Assertion::EVMAmountHolding(_) => - Some(format!("{BASE_URL}/21-evm-holding-amount/1-1-0.json")), + Some(format!("{BASE_URL}/21-evm-holding-amount/1-1-2.json")), Assertion::BRC20AmountHolder => - Some(format!("{BASE_URL}/20-token-holding-amount-list/1-1-0.json")), + Some(format!("{BASE_URL}/20-token-holding-amount-list/1-1-1.json")), Assertion::CryptoSummary => Some(format!("{BASE_URL}/23-crypto-summary/1-1-0.json")), @@ -112,7 +112,7 @@ pub fn get_schema_url(assertion: &Assertion) -> Option { Assertion::NftHolder(_) => Some(format!("{BASE_URL}/26-nft-holder/1-1-2.json")), Assertion::TokenHoldingAmount(_) => - Some(format!("{BASE_URL}/25-token-holding-amount/1-1-3.json")), + Some(format!("{BASE_URL}/25-token-holding-amount/1-1-4.json")), Assertion::Dynamic(..) => None, } diff --git a/tee-worker/litentry/core/credentials/src/litentry_profile/token_balance.rs b/tee-worker/litentry/core/credentials/src/litentry_profile/token_balance.rs index f5868742c3..7b41ef043b 100644 --- a/tee-worker/litentry/core/credentials/src/litentry_profile/token_balance.rs +++ b/tee-worker/litentry/core/credentials/src/litentry_profile/token_balance.rs @@ -81,11 +81,17 @@ fn update_assertion(token: ETokenAddress, balance: f64, credential: &mut Credent Some(index) => { let min = format!("{}", range[index]); let max = format!("{}", range[index + 1]); - let min_item = AssertionLogic::new_item(content, Op::GreaterEq, &min); - let max_item = AssertionLogic::new_item(content, Op::LessThan, &max); + let min_item = AssertionLogic::new_item( + content, + if index == 0 { Op::GreaterThan } else { Op::GreaterEq }, + &min, + ); assertion = assertion.add_item(min_item); - assertion = assertion.add_item(max_item); + if balance > 0_f64 { + let max_item = AssertionLogic::new_item(content, Op::LessThan, &max); + assertion = assertion.add_item(max_item); + } credential.credential_subject.values.push(index != 0 || balance > 0_f64); }, diff --git a/tee-worker/litentry/core/credentials/src/nodereal/amount_holding/evm_amount_holding.rs b/tee-worker/litentry/core/credentials/src/nodereal/amount_holding/evm_amount_holding.rs index e590c61822..44b33faccb 100644 --- a/tee-worker/litentry/core/credentials/src/nodereal/amount_holding/evm_amount_holding.rs +++ b/tee-worker/litentry/core/credentials/src/nodereal/amount_holding/evm_amount_holding.rs @@ -113,13 +113,18 @@ fn update_assertion(token_type: EVMTokenType, balance: f64, credential: &mut Cre Some(index) => { let min = format!("{}", &EVM_HOLDING_AMOUNT_RANGE[index]); let max = format!("{}", &EVM_HOLDING_AMOUNT_RANGE[index + 1]); - let min_item = - AssertionLogic::new_item(ASSERTION_KEYS.holding_amount, Op::GreaterEq, &min); - let max_item = - AssertionLogic::new_item(ASSERTION_KEYS.holding_amount, Op::LessThan, &max); + let min_item = AssertionLogic::new_item( + ASSERTION_KEYS.holding_amount, + if index == 0 { Op::GreaterThan } else { Op::GreaterEq }, + &min, + ); assertion = assertion.add_item(min_item); - assertion = assertion.add_item(max_item); + if balance > 0_f64 { + let max_item = + AssertionLogic::new_item(ASSERTION_KEYS.holding_amount, Op::LessThan, &max); + assertion = assertion.add_item(max_item); + } credential.credential_subject.values.push(index != 0 || balance > 0_f64); }, diff --git a/tee-worker/litentry/core/credentials/src/nodereal/bnb_domain/mod.rs b/tee-worker/litentry/core/credentials/src/nodereal/bnb_domain/mod.rs index 651ba32826..a6dabffffd 100644 --- a/tee-worker/litentry/core/credentials/src/nodereal/bnb_domain/mod.rs +++ b/tee-worker/litentry/core/credentials/src/nodereal/bnb_domain/mod.rs @@ -41,12 +41,19 @@ pub trait RangeCredentialDetail { Some(index) => { let min = range[index - 1]; let max = range[index]; - let min_item = - AssertionLogic::new_item(breakdown, Op::GreaterEq, &format!("{}", min)); - let max_item = - AssertionLogic::new_item(breakdown, Op::LessThan, &format!("{}", max)); + let min_item = AssertionLogic::new_item( + breakdown, + if index == 1 { Op::GreaterThan } else { Op::GreaterEq }, + &format!("{}", min), + ); - vec![min_item, max_item] + if amount > 0 { + let max_item = + AssertionLogic::new_item(breakdown, Op::LessThan, &format!("{}", max)); + vec![min_item, max_item] + } else { + vec![min_item] + } }, None => { // >= last value