Skip to content

Commit

Permalink
feat: P-212 Club3 NFT VC (#2492)
Browse files Browse the repository at this point in the history
* feat: P-212 added new data provider morails, added arbitrum and polygon network, added general nft holder VC using this new data provider, added Club3 VC, migrated existing WeirdoGhostGang VC under it

* add fail fast config for retryable api, add RetryableError

* fix build error

---------

Co-authored-by: higherordertech <higherordertech>
  • Loading branch information
higherordertech committed Feb 20, 2024
1 parent cb19d09 commit 4de61c8
Show file tree
Hide file tree
Showing 42 changed files with 1,584 additions and 214 deletions.
6 changes: 5 additions & 1 deletion primitives/core/src/assertion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
use crate::{
all_web3networks, AccountId, BnbDigitDomainType, BoundedWeb3Network, EVMTokenType,
GenericDiscordRoleType, OneBlockCourseType, PlatformUserType, VIP3MembershipCardLevel,
Web3Network, Web3TokenType,
Web3Network, Web3NftType, Web3TokenType,
};
use codec::{Decode, Encode, MaxEncodedLen};
use scale_info::TypeInfo;
Expand Down Expand Up @@ -232,6 +232,9 @@ pub enum Assertion {

#[codec(index = 25)]
PlatformUser(PlatformUserType),

#[codec(index = 26)]
NftHolder(Web3NftType),
}

impl Assertion {
Expand Down Expand Up @@ -281,6 +284,7 @@ impl Assertion {
Self::A2(..) | Self::A3(..) | Self::A6 | Self::GenericDiscordRole(..) => vec![],
Self::TokenHoldingAmount(t_type) => t_type.get_supported_networks(),
Self::PlatformUser(p_type) => p_type.get_supported_networks(),
Self::NftHolder(t_type) => t_type.get_supported_networks(),
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions primitives/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ pub use web3_token::*;
mod platform_user;
pub use platform_user::*;

mod web3_nft;
pub use web3_nft::*;

/// Common types of parachains.
mod types {
use sp_runtime::{
Expand Down
14 changes: 13 additions & 1 deletion primitives/core/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ pub enum Web3Network {
BitcoinP2wpkh,
#[codec(index = 13)]
BitcoinP2wsh,

// evm
#[codec(index = 14)]
Polygon,
#[codec(index = 15)]
Arbitrum,
}

// mainly used in CLI
Expand All @@ -114,7 +120,7 @@ impl Web3Network {
}

pub fn is_evm(&self) -> bool {
matches!(self, Self::Ethereum | Self::Bsc)
matches!(self, Self::Ethereum | Self::Bsc | Self::Polygon | Self::Arbitrum)
}

pub fn is_bitcoin(&self) -> bool {
Expand Down Expand Up @@ -175,6 +181,8 @@ mod tests {
Web3Network::BitcoinP2sh => false,
Web3Network::BitcoinP2wpkh => false,
Web3Network::BitcoinP2wsh => false,
Web3Network::Polygon => true,
Web3Network::Arbitrum => true,
}
)
})
Expand All @@ -200,6 +208,8 @@ mod tests {
Web3Network::BitcoinP2sh => false,
Web3Network::BitcoinP2wpkh => false,
Web3Network::BitcoinP2wsh => false,
Web3Network::Polygon => false,
Web3Network::Arbitrum => false,
}
)
})
Expand All @@ -225,6 +235,8 @@ mod tests {
Web3Network::BitcoinP2sh => true,
Web3Network::BitcoinP2wpkh => true,
Web3Network::BitcoinP2wsh => true,
Web3Network::Polygon => false,
Web3Network::Arbitrum => false,
}
)
})
Expand Down
38 changes: 38 additions & 0 deletions primitives/core/src/web3_nft.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright 2020-2024 Trust Computing GmbH.
// This file is part of Litentry.
//
// Litentry is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Litentry is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Litentry. If not, see <https://www.gnu.org/licenses/>.

use codec::{Decode, Encode, MaxEncodedLen};
use scale_info::TypeInfo;
use sp_std::{vec, vec::Vec};

use crate::Web3Network;

#[derive(Encode, Decode, Clone, Debug, PartialEq, Eq, MaxEncodedLen, TypeInfo)]
pub enum Web3NftType {
#[codec(index = 0)]
WeirdoGhostGang,
#[codec(index = 1)]
Club3Sbt,
}

impl Web3NftType {
pub fn get_supported_networks(&self) -> Vec<Web3Network> {
match self {
Self::WeirdoGhostGang => vec![Web3Network::Ethereum],
Self::Club3Sbt => vec![Web3Network::Bsc, Web3Network::Polygon, Web3Network::Arbitrum],
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use litentry_primitives::{
AchainableDate, AchainableDateInterval, AchainableDatePercent, AchainableParams,
AchainableToken, Assertion, BoundedWeb3Network, ContestType, EVMTokenType,
GenericDiscordRoleType, Identity, OneBlockCourseType, ParameterString, PlatformUserType,
RequestAesKey, SoraQuizType, VIP3MembershipCardLevel, Web3Network, Web3TokenType,
RequestAesKey, SoraQuizType, VIP3MembershipCardLevel, Web3Network, Web3NftType, Web3TokenType,
REQUEST_AES_KEY_LEN,
};
use sp_core::Pair;
Expand Down Expand Up @@ -111,6 +111,8 @@ pub enum Command {
TokenHoldingAmount(TokenHoldingAmountCommand),
#[clap(subcommand)]
PlatformUser(PlatformUserCommand),
#[clap(subcommand)]
NftHolder(NftHolderCommand),
}

#[derive(Args, Debug)]
Expand Down Expand Up @@ -228,6 +230,12 @@ pub enum PlatformUserCommand {
KaratDaoUser,
}

#[derive(Subcommand, Debug)]
pub enum NftHolderCommand {
WeirdoGhostGang,
Club3Sbt,
}

// positional args (to vec) + required arg + optional arg is a nightmare combination for clap parser,
// additionally, only the last positional argument, or second to last positional argument may be set to `.num_args()`
//
Expand Down Expand Up @@ -491,6 +499,11 @@ impl RequestVcCommand {
PlatformUserCommand::KaratDaoUser =>
Assertion::PlatformUser(PlatformUserType::KaratDaoUser),
},
Command::NftHolder(arg) => match arg {
NftHolderCommand::WeirdoGhostGang =>
Assertion::NftHolder(Web3NftType::WeirdoGhostGang),
NftHolderCommand::Club3Sbt => Assertion::NftHolder(Web3NftType::Club3Sbt),
},
};

let key = Self::random_aes_key();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use litentry_primitives::{
AchainableDate, AchainableDateInterval, AchainableDatePercent, AchainableParams,
AchainableToken, Assertion, ContestType, EVMTokenType, GenericDiscordRoleType, Identity,
OneBlockCourseType, PlatformUserType, RequestAesKey, SoraQuizType, VIP3MembershipCardLevel,
Web3Network, Web3TokenType, REQUEST_AES_KEY_LEN,
Web3Network, Web3NftType, Web3TokenType, REQUEST_AES_KEY_LEN,
};
use sp_core::Pair;

Expand Down Expand Up @@ -257,6 +257,11 @@ impl RequestVcDirectCommand {
PlatformUserCommand::KaratDaoUser =>
Assertion::PlatformUser(PlatformUserType::KaratDaoUser),
},
Command::NftHolder(arg) => match arg {
NftHolderCommand::WeirdoGhostGang =>
Assertion::NftHolder(Web3NftType::WeirdoGhostGang),
NftHolderCommand::Club3Sbt => Assertion::NftHolder(Web3NftType::Club3Sbt),
},
};

let key: [u8; 32] = Self::random_aes_key();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ export default {
"BitcoinP2sh",
"BitcoinP2wpkh",
"BitcoinP2wsh",
"Polygon",
"Arbitrum",
],
},
LitentryValidationData: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export default {
CyptoSummary: "Null",
TokenHoldingAmount: "Web3TokenType",
PlatformUser: "PlatformUserType",
NftHolder: "Web3NftType",
},
},
AssertionSupportedNetwork: {
Expand Down Expand Up @@ -178,5 +179,9 @@ export default {
PlatformUserType: {
_enum: ["KaratDaoUser"],
},
// Web3NftType
Web3NftType: {
_enum: ["WeirdoGhostGang", "Club3Sbt"],
},
},
};
1 change: 1 addition & 0 deletions tee-worker/litentry/core/assertion-build-v2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@ use lc_assertion_build::{transpose_identity, Result};
use lc_service::DataProviderConfig;
use log::*;

pub mod nft_holder;
pub mod platform_user;
pub mod token_holding_amount;

0 comments on commit 4de61c8

Please sign in to comment.