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

feat: P-584 added bitcoin holding amount VC #2689

Merged
merged 3 commits into from
May 2, 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
1 change: 1 addition & 0 deletions bitacross-worker/docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ services:
- CONTEST_LEGEND_DISCORD_ROLE_ID=CONTEST_LEGEND_DISCORD_ROLE_ID
- CONTEST_POPULARITY_DISCORD_ROLE_ID=CONTEST_POPULARITY_DISCORD_ROLE_ID
- CONTEST_PARTICIPANT_DISCORD_ROLE_ID=CONTEST_PARTICIPANT_DISCORD_ROLE_ID
- BLOCKCHAIN_INFO_API_URL=http://localhost:19527/blockchain_info/
networks:
- litentry-test-network
healthcheck:
Expand Down
3 changes: 3 additions & 0 deletions bitacross-worker/docker/multiworker-docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ services:
- CONTEST_LEGEND_DISCORD_ROLE_ID=CONTEST_LEGEND_DISCORD_ROLE_ID
- CONTEST_POPULARITY_DISCORD_ROLE_ID=CONTEST_POPULARITY_DISCORD_ROLE_ID
- CONTEST_PARTICIPANT_DISCORD_ROLE_ID=CONTEST_PARTICIPANT_DISCORD_ROLE_ID
- BLOCKCHAIN_INFO_API_URL=http://localhost:19527/blockchain_info/
networks:
- litentry-test-network
healthcheck:
Expand Down Expand Up @@ -196,6 +197,7 @@ services:
- CONTEST_LEGEND_DISCORD_ROLE_ID=CONTEST_LEGEND_DISCORD_ROLE_ID
- CONTEST_POPULARITY_DISCORD_ROLE_ID=CONTEST_POPULARITY_DISCORD_ROLE_ID
- CONTEST_PARTICIPANT_DISCORD_ROLE_ID=CONTEST_PARTICIPANT_DISCORD_ROLE_ID
- BLOCKCHAIN_INFO_API_URL=http://localhost:19527/blockchain_info/
networks:
- litentry-test-network
healthcheck:
Expand Down Expand Up @@ -251,6 +253,7 @@ services:
- CONTEST_LEGEND_DISCORD_ROLE_ID=CONTEST_LEGEND_DISCORD_ROLE_ID
- CONTEST_POPULARITY_DISCORD_ROLE_ID=CONTEST_POPULARITY_DISCORD_ROLE_ID
- CONTEST_PARTICIPANT_DISCORD_ROLE_ID=CONTEST_PARTICIPANT_DISCORD_ROLE_ID
- BLOCKCHAIN_INFO_API_URL=http://localhost:19527/blockchain_info/
networks:
- litentry-test-network
healthcheck:
Expand Down
1 change: 1 addition & 0 deletions local-setup/.env.dev
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,4 @@ LITENTRY_ARCHIVE_URL=http://localhost:19527
MORALIS_API_URL=http://localhost:19527/moralis/
MORALIS_SOLANA_API_URL=http://localhost:19527/moralis_solana/
KARAT_DAO_API_URL=http://localhost:19527/karat_dao/
BLOCKCHAIN_INFO_API_URL=http://localhost:19527/blockchain_info/
9 changes: 9 additions & 0 deletions primitives/core/src/assertion/web3_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ pub enum Web3TokenType {
Sol,
#[codec(index = 24)]
Mcrt,
#[codec(index = 25)]
Btc,
}

impl Web3TokenType {
Expand All @@ -88,6 +90,13 @@ impl Web3TokenType {
Self::Nfp => vec![Web3Network::Bsc],
Self::Sol | Self::Mcrt =>
vec![Web3Network::Bsc, Web3Network::Ethereum, Web3Network::Solana],
Self::Btc => vec![
Web3Network::BitcoinP2tr,
Web3Network::BitcoinP2pkh,
Web3Network::BitcoinP2sh,
Web3Network::BitcoinP2wpkh,
Web3Network::BitcoinP2wsh,
],
_ => vec![Web3Network::Ethereum],
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ pub enum TokenHoldingAmountCommand {
Nfp,
Sol,
Mcrt,
Btc,
}

#[derive(Subcommand, Debug)]
Expand Down Expand Up @@ -606,6 +607,7 @@ impl Command {
TokenHoldingAmountCommand::Nfp => TokenHoldingAmount(Web3TokenType::Nfp),
TokenHoldingAmountCommand::Sol => TokenHoldingAmount(Web3TokenType::Sol),
TokenHoldingAmountCommand::Mcrt => TokenHoldingAmount(Web3TokenType::Mcrt),
TokenHoldingAmountCommand::Btc => TokenHoldingAmount(Web3TokenType::Btc),
},
Command::PlatformUser(arg) => match arg {
PlatformUserCommand::KaratDaoUser => PlatformUser(PlatformUserType::KaratDaoUser),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ export default {
"Nfp",
"Sol",
"Mcrt",
"Btc",
],
},
// PlatformUserType
Expand Down
1 change: 1 addition & 0 deletions tee-worker/docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ services:
- CONTEST_PARTICIPANT_DISCORD_ROLE_ID=CONTEST_PARTICIPANT_DISCORD_ROLE_ID
- LITENTRY_ARCHIVE_URL=http://localhost:19527
- VIP3_URL=http://localhost:19527
- BLOCKCHAIN_INFO_API_URL=http://localhost:19527/blockchain_info/
networks:
- litentry-test-network
healthcheck:
Expand Down
3 changes: 3 additions & 0 deletions tee-worker/docker/multiworker-docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ services:
- CONTEST_PARTICIPANT_DISCORD_ROLE_ID=CONTEST_PARTICIPANT_DISCORD_ROLE_ID
- LITENTRY_ARCHIVE_URL=http://localhost:19527
- VIP3_URL=http://localhost:19527
- BLOCKCHAIN_INFO_API_URL=http://localhost:19527/blockchain_info/
networks:
- litentry-test-network
healthcheck:
Expand Down Expand Up @@ -200,6 +201,7 @@ services:
- CONTEST_PARTICIPANT_DISCORD_ROLE_ID=CONTEST_PARTICIPANT_DISCORD_ROLE_ID
- LITENTRY_ARCHIVE_URL=http://localhost:19527
- VIP3_URL=http://localhost:19527
- BLOCKCHAIN_INFO_API_URL=http://localhost:19527/blockchain_info/
networks:
- litentry-test-network
healthcheck:
Expand Down Expand Up @@ -257,6 +259,7 @@ services:
- CONTEST_PARTICIPANT_DISCORD_ROLE_ID=CONTEST_PARTICIPANT_DISCORD_ROLE_ID
- LITENTRY_ARCHIVE_URL=http://localhost:19527
- VIP3_URL=http://localhost:19527
- BLOCKCHAIN_INFO_API_URL=http://localhost:19527/blockchain_info/
networks:
- litentry-test-network
healthcheck:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ mod tests {
data_provider_config
.set_nodereal_api_chain_network_url(url.clone() + "/nodereal_jsonrpc/")
.unwrap();
data_provider_config
.set_blockchain_info_api_url(url.clone() + "/blockchain_info/")
.unwrap();
data_provider_config.set_achainable_url(url.clone()).unwrap();
data_provider_config.set_moralis_api_url(url.clone() + "/moralis/").unwrap();
data_provider_config
Expand Down Expand Up @@ -608,4 +611,52 @@ mod tests {
},
}
}

#[test]
fn build_btc_holding_amount_works() {
let data_provider_config: DataProviderConfig = init();
// bc1pgr5fw4p9gl9me0vzjklnlnap669caxc0gsk4j62gff2qktlw6naqm4m3d0
let address = decode_hex(
"0x02e8c39e82aaaa143c3def8d3c7084a539b227244ac9067c3f7fc86cb73a0b7aed"
.as_bytes()
.to_vec(),
)
.unwrap()
.as_slice()
.try_into()
.unwrap();
let identities: Vec<IdentityNetworkTuple> =
vec![(Identity::Bitcoin(address), vec![Web3Network::BitcoinP2tr])];

let req = crate_assertion_build_request(Web3TokenType::Btc, identities);

match build(&req, Web3TokenType::Btc, &data_provider_config) {
Ok(credential) => {
log::info!("build btc TokenHoldingAmount done");
assert_eq!(
*(credential.credential_subject.assertions.first().unwrap()),
AssertionLogic::And {
items: vec![
create_token_assertion_logic(Web3TokenType::Btc),
create_network_address_assertion_logics(Web3TokenType::Btc),
Box::new(AssertionLogic::Item {
src: "$holding_amount".into(),
op: Op::GreaterEq,
dst: "1600".into()
}),
Box::new(AssertionLogic::Item {
src: "$holding_amount".into(),
op: Op::LessThan,
dst: "3000".into()
})
]
}
);
assert_eq!(*(credential.credential_subject.values.first().unwrap()), true);
},
Err(e) => {
panic!("build btc TokenHoldingAmount failed with error {:?}", e);
},
}
}
}
7 changes: 6 additions & 1 deletion tee-worker/litentry/core/common/src/web3_token/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ impl TokenName for Web3TokenType {
Self::Nfp => "NFP",
Self::Sol => "SOL",
Self::Mcrt => "MCRT",
Self::Btc => "BTC",
}
}
}
Expand Down Expand Up @@ -214,7 +215,11 @@ impl TokenDecimals for Web3TokenType {
// Wbtc
(Self::Wbtc, Web3Network::Bsc) | (Self::Wbtc, Web3Network::Ethereum) |
// Mcrt
(Self::Mcrt, Web3Network::Solana) => 8,
(Self::Mcrt, Web3Network::Solana) |
// Btc
(Self::Btc, Web3Network::BitcoinP2tr) | (Self::Btc, Web3Network::BitcoinP2pkh) |
(Self::Btc, Web3Network::BitcoinP2sh) | (Self::Btc, Web3Network::BitcoinP2wpkh) |
(Self::Btc, Web3Network::BitcoinP2wsh) => 8,
// Usdc
(Self::Usdc, Web3Network::Ethereum) |
// Usdt
Expand Down
6 changes: 4 additions & 2 deletions tee-worker/litentry/core/credentials/src/credential_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ pub fn get_schema_url(assertion: &Assertion) -> String {

Assertion::LITStaking => format!("{BASE_URL}/17-token-holding-amount/1-1-0.json"),

Assertion::TokenHoldingAmount(_) | Assertion::EVMAmountHolding(_) =>
format!("{BASE_URL}/21-evm-holding-amount/1-1-0.json"),
Assertion::EVMAmountHolding(_) => format!("{BASE_URL}/21-evm-holding-amount/1-1-0.json"),

Assertion::BRC20AmountHolder =>
format!("{BASE_URL}/20-token-holding-amount-list/1-1-0.json"),
Expand All @@ -104,6 +103,9 @@ pub fn get_schema_url(assertion: &Assertion) -> String {

Assertion::PlatformUser(_) => format!("{BASE_URL}/24-platform-user/1-1-0.json"),

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

Assertion::NftHolder(_) => format!("{BASE_URL}/26-nft-holder/1-1-0.json"),
}
}
Loading