Skip to content

Commit 427b1df

Browse files
authored
An and tuna holding amount vc (#2884)
* 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>
1 parent b3082f7 commit 427b1df

File tree

10 files changed

+131
-3
lines changed

10 files changed

+131
-3
lines changed

primitives/core/src/assertion/web3_token.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ pub enum Web3TokenType {
102102
Inj,
103103
#[codec(index = 39)]
104104
Bean,
105+
#[codec(index = 40)]
106+
An,
107+
#[codec(index = 41)]
108+
Tuna,
105109
}
106110

107111
impl Web3TokenType {
@@ -137,6 +141,7 @@ impl Web3TokenType {
137141
Self::Atom => vec![Web3Network::Ethereum, Web3Network::Bsc, Web3Network::Polygon],
138142
Self::Cro => vec![Web3Network::Ethereum, Web3Network::Solana],
139143
Self::Bean => vec![Web3Network::Bsc, Web3Network::Combo],
144+
Self::An => vec![Web3Network::Bsc],
140145
_ => vec![Web3Network::Ethereum],
141146
}
142147
}

tee-worker/cli/src/trusted_base_cli/commands/litentry/request_vc.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,8 @@ pub enum TokenHoldingAmountCommand {
278278
Mcrt,
279279
Btc,
280280
Bean,
281+
An,
282+
Tuna,
281283
}
282284

283285
#[derive(Subcommand, Debug)]
@@ -645,6 +647,8 @@ impl Command {
645647
TokenHoldingAmountCommand::Mcrt => TokenHoldingAmount(Web3TokenType::Mcrt),
646648
TokenHoldingAmountCommand::Btc => TokenHoldingAmount(Web3TokenType::Btc),
647649
TokenHoldingAmountCommand::Bean => TokenHoldingAmount(Web3TokenType::Bean),
650+
TokenHoldingAmountCommand::An => TokenHoldingAmount(Web3TokenType::An),
651+
TokenHoldingAmountCommand::Tuna => TokenHoldingAmount(Web3TokenType::Tuna),
648652
}),
649653
Command::PlatformUser(arg) => Ok(match arg {
650654
PlatformUserCommand::KaratDaoUser => PlatformUser(PlatformUserType::KaratDaoUser),

tee-worker/client-api/parachain-api/prepare-build/interfaces/vc/definitions.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,8 @@ export default {
236236
"Cro",
237237
"Inj",
238238
"Bean",
239+
"An",
240+
"Tuna",
239241
],
240242
},
241243
// PlatformUserType

tee-worker/litentry/core/assertion-build-v2/src/token_holding_amount/mod.rs

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,4 +695,84 @@ mod tests {
695695
},
696696
};
697697
}
698+
699+
#[test]
700+
fn build_an_holding_amount_works() {
701+
let data_provider_config: DataProviderConfig = init();
702+
let address = decode_hex("0x75438d34c9125839c8b08d21b7f3167281659e4c".as_bytes().to_vec())
703+
.unwrap()
704+
.as_slice()
705+
.try_into()
706+
.unwrap();
707+
let identities = vec![(Identity::Evm(address), vec![Web3Network::Bsc])];
708+
let req = crate_assertion_build_request(Web3TokenType::An, identities);
709+
match build(&req, Web3TokenType::An, &data_provider_config) {
710+
Ok(credential) => {
711+
log::info!("build an TokenHoldingAmount done");
712+
assert_eq!(
713+
*(credential.credential_subject.assertions.first().unwrap()),
714+
AssertionLogic::And {
715+
items: vec![
716+
create_token_assertion_logic(Web3TokenType::An),
717+
create_network_address_assertion_logics(Web3TokenType::An),
718+
Box::new(AssertionLogic::Item {
719+
src: "$holding_amount".into(),
720+
op: Op::GreaterEq,
721+
dst: "100000".into()
722+
}),
723+
Box::new(AssertionLogic::Item {
724+
src: "$holding_amount".into(),
725+
op: Op::LessThan,
726+
dst: "900000".into()
727+
})
728+
]
729+
}
730+
);
731+
assert_eq!(*(credential.credential_subject.values.first().unwrap()), true);
732+
},
733+
Err(e) => {
734+
panic!("build an TokenHoldingAmount failed with error {:?}", e);
735+
},
736+
};
737+
}
738+
739+
#[test]
740+
fn build_tuna_holding_amount_works() {
741+
let data_provider_config: DataProviderConfig = init();
742+
let address = decode_hex("0x75438d34c9125839c8b08d21b7f3167281659e5c".as_bytes().to_vec())
743+
.unwrap()
744+
.as_slice()
745+
.try_into()
746+
.unwrap();
747+
let identities = vec![(Identity::Evm(address), vec![Web3Network::Ethereum])];
748+
let req = crate_assertion_build_request(Web3TokenType::Tuna, identities);
749+
match build(&req, Web3TokenType::Tuna, &data_provider_config) {
750+
Ok(credential) => {
751+
log::info!("build tuna TokenHoldingAmount done");
752+
assert_eq!(
753+
*(credential.credential_subject.assertions.first().unwrap()),
754+
AssertionLogic::And {
755+
items: vec![
756+
create_token_assertion_logic(Web3TokenType::Tuna),
757+
create_network_address_assertion_logics(Web3TokenType::Tuna),
758+
Box::new(AssertionLogic::Item {
759+
src: "$holding_amount".into(),
760+
op: Op::GreaterEq,
761+
dst: "1000".into()
762+
}),
763+
Box::new(AssertionLogic::Item {
764+
src: "$holding_amount".into(),
765+
op: Op::LessThan,
766+
dst: "2000".into()
767+
})
768+
]
769+
}
770+
);
771+
assert_eq!(*(credential.credential_subject.values.first().unwrap()), true);
772+
},
773+
Err(e) => {
774+
panic!("build tuna TokenHoldingAmount failed with error {:?}", e);
775+
},
776+
};
777+
}
698778
}

tee-worker/litentry/core/common/src/web3_token/mod.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ impl TokenName for Web3TokenType {
7777
Self::Cro => "CRO",
7878
Self::Inj => "INJ",
7979
Self::Bean => "BEAN",
80+
Self::An => "AN",
81+
Self::Tuna => "TUNA",
8082
}
8183
}
8284
}
@@ -251,6 +253,13 @@ impl TokenAddress for Web3TokenType {
251253
(Self::Bean, Web3Network::Bsc) => Some("0x07da81e9a684ab87fad7206b3bc8d0866f48cc7c"),
252254
(Self::Bean, Web3Network::Combo) => Some("0xba7b9936a965fac23bb7a8190364fa60622b3cff"),
253255

256+
// An
257+
(Self::An, Web3Network::Bsc) => Some("0x68d806380ce01e994f7583d796d0aea9ab470219"),
258+
259+
// Tuna
260+
(Self::Tuna, Web3Network::Ethereum) =>
261+
Some("0xadd353fb2e2c563383ff3272a500f3e7134dafe4"),
262+
254263
_ => None,
255264
}
256265
}
@@ -327,6 +336,12 @@ impl TokenHoldingAmountRange for Web3TokenType {
327336
// Bean
328337
Self::Bean => BEAN_AMOUNT_RANGE.to_vec(),
329338

339+
// An
340+
Self::An => AN_AMOUNT_RANGE.to_vec(),
341+
342+
// Tuna
343+
Self::Tuna => TUNA_AMOUNT_RANGE.to_vec(),
344+
330345
_ => [0.0, 1.0, 50.0, 100.0, 200.0, 500.0, 800.0, 1200.0, 1600.0, 3000.0].to_vec(),
331346
}
332347
}

tee-worker/litentry/core/common/src/web3_token/token_amount_range.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,6 @@ pub const INJ_AMOUNT_RANGE: [f64; 6] = [0.0, 1.0, 5.0, 20.0, 50.0, 80.0];
4949
pub const BTC_AMOUNT_RANGE: [f64; 14] =
5050
[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];
5151
pub const BEAN_AMOUNT_RANGE: [f64; 5] = [0.0, 1_500.0, 5_000.0, 10_000.0, 50_000.0];
52+
pub const AN_AMOUNT_RANGE: [f64; 7] =
53+
[0.0, 100_000.0, 900_000.0, 1_800_000.0, 3_600_000.0, 7_200_000.0, 10_000_000.0];
54+
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];

tee-worker/litentry/core/common/src/web3_token/token_decimals_filter.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ pub const TOKEN_DECIMALS_9: (u32, [(Web3TokenType, Web3Network); 4]) = (
8383
],
8484
);
8585

86-
pub const TOKEN_DECIMALS_18: (u32, [(Web3TokenType, Web3Network); 50]) = (
86+
pub const TOKEN_DECIMALS_18: (u32, [(Web3TokenType, Web3Network); 52]) = (
8787
18,
8888
[
8989
// Bnb
@@ -168,6 +168,10 @@ pub const TOKEN_DECIMALS_18: (u32, [(Web3TokenType, Web3Network); 50]) = (
168168
// Bean
169169
(Web3TokenType::Bean, Web3Network::Bsc),
170170
(Web3TokenType::Bean, Web3Network::Combo),
171+
// An
172+
(Web3TokenType::An, Web3Network::Bsc),
173+
// Tuna
174+
(Web3TokenType::Tuna, Web3Network::Ethereum),
171175
],
172176
);
173177

tee-worker/litentry/core/credentials/src/credential_schema.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ pub fn get_schema_url(assertion: &Assertion) -> Option<String> {
112112
Assertion::NftHolder(_) => Some(format!("{BASE_URL}/26-nft-holder/1-1-1.json")),
113113

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

117117
Assertion::Dynamic(..) => None,
118118
}

tee-worker/litentry/core/mock-server/src/nodereal_jsonrpc.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,10 @@ pub(crate) fn query() -> impl Filter<Extract = impl warp::Reply, Error = warp::R
118118
"0x75438d34c9125839c8b08d21b7f3167281659e2c" => "0x1158e460913d00000",
119119
// 5000 * 10^18
120120
"0x75438d34c9125839c8b08d21b7f3167281659e3c" => "0x10f0cf064dd59200000",
121-
// 800
121+
// 120_000 * 10^18
122+
"0x75438d34c9125839c8b08d21b7f3167281659e4c" => "0x1969368974c05b000000",
123+
// 1_500 * 10 ^ 18
124+
"0x75438d34c9125839c8b08d21b7f3167281659e5c" => "0x5150ae84a8cdf00000",
122125
_ => "0x320",
123126
};
124127
let body = RpcResponse {

tee-worker/ts-tests/integration-tests/common/utils/vc-helper.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,18 @@ export const mockAssertions = [
278278
TokenHoldingAmount: 'BEAN',
279279
},
280280
},
281+
{
282+
description: 'The amount of AN you are holding',
283+
assertion: {
284+
TokenHoldingAmount: 'AN',
285+
},
286+
},
287+
{
288+
description: 'The amount of TUNA you are holding',
289+
assertion: {
290+
TokenHoldingAmount: 'TUNA',
291+
},
292+
},
281293

282294
{
283295
description: 'The amount of LIT you are staking',

0 commit comments

Comments
 (0)