Skip to content
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

Add bean support for TokenAmountHolding VC #2770

Merged
merged 5 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion local-setup/launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def get_flags(index, worker):

return list(filter(None, [
"--clean-reset",
"-T", "wss://localhost",
"-T", "ws://localhost",
"-P", ports['trusted_worker_port'],
"-w", ports['untrusted_worker_port'],
"-r", ports['mura_port'],
Expand Down
9 changes: 8 additions & 1 deletion primitives/core/src/assertion/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ pub enum Web3Network {
// solana
#[codec(index = 16)]
Solana,
// combo L2 of BSC
#[codec(index = 17)]
Combo,
}

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

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

pub fn is_bitcoin(&self) -> bool {
Expand Down Expand Up @@ -195,6 +198,7 @@ mod tests {
Web3Network::Polygon => true,
Web3Network::Arbitrum => true,
Web3Network::Solana => false,
Web3Network::Combo => true,
}
)
})
Expand Down Expand Up @@ -223,6 +227,7 @@ mod tests {
Web3Network::Polygon => false,
Web3Network::Arbitrum => false,
Web3Network::Solana => false,
Web3Network::Combo => false,
}
)
})
Expand Down Expand Up @@ -251,6 +256,7 @@ mod tests {
Web3Network::Polygon => false,
Web3Network::Arbitrum => false,
Web3Network::Solana => false,
Web3Network::Combo => false,
}
)
})
Expand Down Expand Up @@ -279,6 +285,7 @@ mod tests {
Web3Network::Polygon => false,
Web3Network::Arbitrum => false,
Web3Network::Solana => true,
Web3Network::Combo => false,
}
)
})
Expand Down
3 changes: 3 additions & 0 deletions primitives/core/src/assertion/web3_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ pub enum Web3TokenType {
Cro,
#[codec(index = 38)]
Inj,
#[codec(index = 39)]
Bean,
}

impl Web3TokenType {
Expand Down Expand Up @@ -134,6 +136,7 @@ impl Web3TokenType {
Self::Shib | Self::Leo | Self::Imx => vec![Web3Network::Ethereum],
Self::Atom => vec![Web3Network::Ethereum, Web3Network::Bsc, Web3Network::Polygon],
Self::Cro => vec![Web3Network::Ethereum, Web3Network::Solana],
Self::Bean => vec![Web3Network::Bsc, Web3Network::Combo],
_ => vec![Web3Network::Ethereum],
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ pub enum TokenHoldingAmountCommand {
Sol,
Mcrt,
Btc,
Bean,
}

#[derive(Subcommand, Debug)]
Expand Down Expand Up @@ -616,6 +617,7 @@ impl Command {
TokenHoldingAmountCommand::Sol => TokenHoldingAmount(Web3TokenType::Sol),
TokenHoldingAmountCommand::Mcrt => TokenHoldingAmount(Web3TokenType::Mcrt),
TokenHoldingAmountCommand::Btc => TokenHoldingAmount(Web3TokenType::Btc),
TokenHoldingAmountCommand::Bean => TokenHoldingAmount(Web3TokenType::Bean),
},
Command::PlatformUser(arg) => match arg {
PlatformUserCommand::KaratDaoUser => PlatformUser(PlatformUserType::KaratDaoUser),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ export default {
"Imx",
"Cro",
"Inj",
"Bean",
],
},
// PlatformUserType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -665,4 +665,44 @@ mod tests {
},
}
}

#[test]
fn build_bean_holding_amount_works() {
let data_provider_config: DataProviderConfig = init();
let address = decode_hex("0x75438d34c9125839c8b08d21b7f3167281659e3c".as_bytes().to_vec())
.unwrap()
.as_slice()
.try_into()
.unwrap();
let identities = vec![(Identity::Evm(address), vec![Web3Network::Bsc])];
let req = crate_assertion_build_request(Web3TokenType::Bean, identities);
match build(&req, Web3TokenType::Bean, &data_provider_config) {
Ok(credential) => {
log::info!("build bean TokenHoldingAmount done");
assert_eq!(
*(credential.credential_subject.assertions.first().unwrap()),
AssertionLogic::And {
items: vec![
create_token_assertion_logic(Web3TokenType::Bean),
create_network_address_assertion_logics(Web3TokenType::Bean),
Box::new(AssertionLogic::Item {
src: "$holding_amount".into(),
op: Op::GreaterEq,
dst: "5000".into()
}),
Box::new(AssertionLogic::Item {
src: "$holding_amount".into(),
op: Op::LessThan,
dst: "10000".into()
})
]
}
);
assert_eq!(*(credential.credential_subject.values.first().unwrap()), true);
},
Err(e) => {
panic!("build bean TokenHoldingAmount failed with error {:?}", e);
},
};
}
}
1 change: 1 addition & 0 deletions tee-worker/litentry/core/assertion-build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ fn pubkey_to_address(network: &Web3Network, pubkey: &str) -> String {
| Web3Network::Bsc
| Web3Network::Polygon
| Web3Network::Arbitrum
| Web3Network::Combo
| Web3Network::Solana => "".to_string(),
}
}
Expand Down
1 change: 1 addition & 0 deletions tee-worker/litentry/core/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,6 @@ pub fn web3_network_to_chain(network: &Web3Network) -> &'static str {
Web3Network::Polygon => "polygon",
Web3Network::Arbitrum => "arbitrum",
Web3Network::Solana => "solana",
Web3Network::Combo => "combo",
}
}
8 changes: 8 additions & 0 deletions tee-worker/litentry/core/common/src/web3_token/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ impl TokenName for Web3TokenType {
Self::Imx => "IMX",
Self::Cro => "CRO",
Self::Inj => "INJ",
Self::Bean => "BEAN",
}
}
}
Expand Down Expand Up @@ -246,6 +247,10 @@ impl TokenAddress for Web3TokenType {
Some("0xe28b3b32b6c345a34ff64674606124dd5aceca30"),
(Self::Inj, Web3Network::Bsc) => Some("0xa2b726b1145a4773f68593cf171187d8ebe4d495"),

// Bean
(Self::Bean, Web3Network::Bsc) => Some("0x07da81e9a684ab87fad7206b3bc8d0866f48cc7c"),
(Self::Bean, Web3Network::Combo) => Some("0xba7b9936a965fac23bb7a8190364fa60622b3cff"),

_ => None,
}
}
Expand Down Expand Up @@ -319,6 +324,9 @@ impl TokenHoldingAmountRange for Web3TokenType {
// Btc
Self::Btc => BTC_AMOUNT_RANGE.to_vec(),

// Bean
Self::Bean => BEAN_AMOUNT_RANGE.to_vec(),

_ => [0.0, 1.0, 50.0, 100.0, 200.0, 500.0, 800.0, 1200.0, 1600.0, 3000.0].to_vec(),
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,4 @@ pub const CRO_AMOUNT_RANGE: [f64; 7] =
pub const INJ_AMOUNT_RANGE: [f64; 6] = [0.0, 1.0, 5.0, 20.0, 50.0, 80.0];
pub const BTC_AMOUNT_RANGE: [f64; 14] =
[0.0, 0.001, 0.1, 0.3, 0.6, 1.0, 2.0, 5.0, 10.0, 15.0, 25.0, 30.0, 40.0, 50.0];
pub const BEAN_AMOUNT_RANGE: [f64; 5] = [0.0, 1_500.0, 5_000.0, 10_000.0, 50_000.0];
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ pub const TOKEN_DECIMALS_9: (u32, [(Web3TokenType, Web3Network); 4]) = (
],
);

pub const TOKEN_DECIMALS_18: (u32, [(Web3TokenType, Web3Network); 48]) = (
pub const TOKEN_DECIMALS_18: (u32, [(Web3TokenType, Web3Network); 50]) = (
18,
[
// Bnb
Expand Down Expand Up @@ -165,6 +165,9 @@ pub const TOKEN_DECIMALS_18: (u32, [(Web3TokenType, Web3Network); 48]) = (
// Inj
(Web3TokenType::Inj, Web3Network::Ethereum),
(Web3TokenType::Inj, Web3Network::Bsc),
// Bean
(Web3TokenType::Bean, Web3Network::Bsc),
(Web3TokenType::Bean, Web3Network::Combo),
],
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ pub fn get_schema_url(assertion: &Assertion) -> Option<String> {
Assertion::NftHolder(_) => Some(format!("{BASE_URL}/26-nft-holder/1-1-0.json")),

Assertion::TokenHoldingAmount(_) =>
Some(format!("{BASE_URL}/25-token-holding-amount/1-1-1.json")),
Some(format!("{BASE_URL}/25-token-holding-amount/1-1-2.json")),

Assertion::Dynamic(_) => None,
}
Expand Down
1 change: 1 addition & 0 deletions tee-worker/litentry/core/data-providers/src/achainable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ pub fn web3_network_to_chain(network: &Web3Network) -> String {
Web3Network::Polygon => "polygon".into(),
Web3Network::Arbitrum => "arbitrum".into(),
Web3Network::Solana => "solana".into(),
Web3Network::Combo => "combo".into(),
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ impl Web3NetworkNoderealJsonrpcClient for Web3Network {
Some(NoderealJsonrpcClient::new(NoderealChain::Eth, data_provider_config)),
Web3Network::Polygon =>
Some(NoderealJsonrpcClient::new(NoderealChain::Polygon, data_provider_config)),
Web3Network::Combo =>
Some(NoderealJsonrpcClient::new(NoderealChain::Combo, data_provider_config)),
_ => None,
}
}
Expand All @@ -79,6 +81,8 @@ pub enum NoderealChain {
Opt,
// Polygon
Polygon,
// Combo
Combo,
}

impl NoderealChain {
Expand All @@ -91,6 +95,7 @@ impl NoderealChain {
NoderealChain::Aptos => "aptos",
NoderealChain::Opt => "opt",
NoderealChain::Polygon => "polygon",
NoderealChain::Combo => "combo",
}
}
}
Expand Down
1 change: 1 addition & 0 deletions tee-worker/litentry/core/evm-dynamic-assertions/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ pub fn network_to_token(network: &Web3Network) -> Token {
Web3Network::Polygon => 14,
Web3Network::Arbitrum => 15,
Web3Network::Solana => 16,
Web3Network::Combo => 17,
}
.into(),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub fn get_balance(
let token_address = token_type.get_token_address(network).unwrap_or_default();

match network {
Web3Network::Bsc | Web3Network::Ethereum => {
Web3Network::Bsc | Web3Network::Ethereum | Web3Network::Combo => {
let decimals = token_type.get_decimals(network);
match network.create_nodereal_jsonrpc_client(data_provider_config) {
Some(mut client) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,12 @@ export const mockAssertions = [
TokenHoldingAmount: 'SHIB',
},
},
{
description: 'The amount of BEAN you are holding',
assertion: {
TokenHoldingAmount: 'BEAN',
},
},

{
description: 'The amount of LIT you are staking',
Expand Down