Skip to content

Commit

Permalink
An and tuna holding amount vc (#2884)
Browse files Browse the repository at this point in the history
* feat: P-915 implemented token holding amount for AN

* feat: P-915 implemented token holding amount for TUNA

* fix: updated TokenHoldingAmount credentials schema

---------

Co-authored-by: higherordertech <higherordertech>
  • Loading branch information
higherordertech authored Jul 10, 2024
1 parent b3082f7 commit 427b1df
Show file tree
Hide file tree
Showing 10 changed files with 131 additions and 3 deletions.
5 changes: 5 additions & 0 deletions primitives/core/src/assertion/web3_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ pub enum Web3TokenType {
Inj,
#[codec(index = 39)]
Bean,
#[codec(index = 40)]
An,
#[codec(index = 41)]
Tuna,
}

impl Web3TokenType {
Expand Down Expand Up @@ -137,6 +141,7 @@ impl Web3TokenType {
Self::Atom => vec![Web3Network::Ethereum, Web3Network::Bsc, Web3Network::Polygon],
Self::Cro => vec![Web3Network::Ethereum, Web3Network::Solana],
Self::Bean => vec![Web3Network::Bsc, Web3Network::Combo],
Self::An => vec![Web3Network::Bsc],
_ => vec![Web3Network::Ethereum],
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,8 @@ pub enum TokenHoldingAmountCommand {
Mcrt,
Btc,
Bean,
An,
Tuna,
}

#[derive(Subcommand, Debug)]
Expand Down Expand Up @@ -645,6 +647,8 @@ impl Command {
TokenHoldingAmountCommand::Mcrt => TokenHoldingAmount(Web3TokenType::Mcrt),
TokenHoldingAmountCommand::Btc => TokenHoldingAmount(Web3TokenType::Btc),
TokenHoldingAmountCommand::Bean => TokenHoldingAmount(Web3TokenType::Bean),
TokenHoldingAmountCommand::An => TokenHoldingAmount(Web3TokenType::An),
TokenHoldingAmountCommand::Tuna => TokenHoldingAmount(Web3TokenType::Tuna),
}),
Command::PlatformUser(arg) => Ok(match arg {
PlatformUserCommand::KaratDaoUser => PlatformUser(PlatformUserType::KaratDaoUser),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ export default {
"Cro",
"Inj",
"Bean",
"An",
"Tuna",
],
},
// PlatformUserType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -695,4 +695,84 @@ mod tests {
},
};
}

#[test]
fn build_an_holding_amount_works() {
let data_provider_config: DataProviderConfig = init();
let address = decode_hex("0x75438d34c9125839c8b08d21b7f3167281659e4c".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::An, identities);
match build(&req, Web3TokenType::An, &data_provider_config) {
Ok(credential) => {
log::info!("build an TokenHoldingAmount done");
assert_eq!(
*(credential.credential_subject.assertions.first().unwrap()),
AssertionLogic::And {
items: vec![
create_token_assertion_logic(Web3TokenType::An),
create_network_address_assertion_logics(Web3TokenType::An),
Box::new(AssertionLogic::Item {
src: "$holding_amount".into(),
op: Op::GreaterEq,
dst: "100000".into()
}),
Box::new(AssertionLogic::Item {
src: "$holding_amount".into(),
op: Op::LessThan,
dst: "900000".into()
})
]
}
);
assert_eq!(*(credential.credential_subject.values.first().unwrap()), true);
},
Err(e) => {
panic!("build an TokenHoldingAmount failed with error {:?}", e);
},
};
}

#[test]
fn build_tuna_holding_amount_works() {
let data_provider_config: DataProviderConfig = init();
let address = decode_hex("0x75438d34c9125839c8b08d21b7f3167281659e5c".as_bytes().to_vec())
.unwrap()
.as_slice()
.try_into()
.unwrap();
let identities = vec![(Identity::Evm(address), vec![Web3Network::Ethereum])];
let req = crate_assertion_build_request(Web3TokenType::Tuna, identities);
match build(&req, Web3TokenType::Tuna, &data_provider_config) {
Ok(credential) => {
log::info!("build tuna TokenHoldingAmount done");
assert_eq!(
*(credential.credential_subject.assertions.first().unwrap()),
AssertionLogic::And {
items: vec![
create_token_assertion_logic(Web3TokenType::Tuna),
create_network_address_assertion_logics(Web3TokenType::Tuna),
Box::new(AssertionLogic::Item {
src: "$holding_amount".into(),
op: Op::GreaterEq,
dst: "1000".into()
}),
Box::new(AssertionLogic::Item {
src: "$holding_amount".into(),
op: Op::LessThan,
dst: "2000".into()
})
]
}
);
assert_eq!(*(credential.credential_subject.values.first().unwrap()), true);
},
Err(e) => {
panic!("build tuna TokenHoldingAmount failed with error {:?}", e);
},
};
}
}
15 changes: 15 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 @@ -77,6 +77,8 @@ impl TokenName for Web3TokenType {
Self::Cro => "CRO",
Self::Inj => "INJ",
Self::Bean => "BEAN",
Self::An => "AN",
Self::Tuna => "TUNA",
}
}
}
Expand Down Expand Up @@ -251,6 +253,13 @@ impl TokenAddress for Web3TokenType {
(Self::Bean, Web3Network::Bsc) => Some("0x07da81e9a684ab87fad7206b3bc8d0866f48cc7c"),
(Self::Bean, Web3Network::Combo) => Some("0xba7b9936a965fac23bb7a8190364fa60622b3cff"),

// An
(Self::An, Web3Network::Bsc) => Some("0x68d806380ce01e994f7583d796d0aea9ab470219"),

// Tuna
(Self::Tuna, Web3Network::Ethereum) =>
Some("0xadd353fb2e2c563383ff3272a500f3e7134dafe4"),

_ => None,
}
}
Expand Down Expand Up @@ -327,6 +336,12 @@ impl TokenHoldingAmountRange for Web3TokenType {
// Bean
Self::Bean => BEAN_AMOUNT_RANGE.to_vec(),

// An
Self::An => AN_AMOUNT_RANGE.to_vec(),

// Tuna
Self::Tuna => TUNA_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 @@ -49,3 +49,6 @@ 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];
pub const AN_AMOUNT_RANGE: [f64; 7] =
[0.0, 100_000.0, 900_000.0, 1_800_000.0, 3_600_000.0, 7_200_000.0, 10_000_000.0];
pub const TUNA_AMOUNT_RANGE: [f64; 7] = [0.0, 100.0, 1_000.0, 2_000.0, 4_000.0, 8_000.0, 12_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); 50]) = (
pub const TOKEN_DECIMALS_18: (u32, [(Web3TokenType, Web3Network); 52]) = (
18,
[
// Bnb
Expand Down Expand Up @@ -168,6 +168,10 @@ pub const TOKEN_DECIMALS_18: (u32, [(Web3TokenType, Web3Network); 50]) = (
// Bean
(Web3TokenType::Bean, Web3Network::Bsc),
(Web3TokenType::Bean, Web3Network::Combo),
// An
(Web3TokenType::An, Web3Network::Bsc),
// Tuna
(Web3TokenType::Tuna, Web3Network::Ethereum),
],
);

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-1.json")),

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

Assertion::Dynamic(..) => None,
}
Expand Down
5 changes: 4 additions & 1 deletion tee-worker/litentry/core/mock-server/src/nodereal_jsonrpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,10 @@ pub(crate) fn query() -> impl Filter<Extract = impl warp::Reply, Error = warp::R
"0x75438d34c9125839c8b08d21b7f3167281659e2c" => "0x1158e460913d00000",
// 5000 * 10^18
"0x75438d34c9125839c8b08d21b7f3167281659e3c" => "0x10f0cf064dd59200000",
// 800
// 120_000 * 10^18
"0x75438d34c9125839c8b08d21b7f3167281659e4c" => "0x1969368974c05b000000",
// 1_500 * 10 ^ 18
"0x75438d34c9125839c8b08d21b7f3167281659e5c" => "0x5150ae84a8cdf00000",
_ => "0x320",
};
let body = RpcResponse {
Expand Down
12 changes: 12 additions & 0 deletions tee-worker/ts-tests/integration-tests/common/utils/vc-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,18 @@ export const mockAssertions = [
TokenHoldingAmount: 'BEAN',
},
},
{
description: 'The amount of AN you are holding',
assertion: {
TokenHoldingAmount: 'AN',
},
},
{
description: 'The amount of TUNA you are holding',
assertion: {
TokenHoldingAmount: 'TUNA',
},
},

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

0 comments on commit 427b1df

Please sign in to comment.