Skip to content

Commit

Permalink
fix on context entities
Browse files Browse the repository at this point in the history
  • Loading branch information
NanezX committed Nov 1, 2023
1 parent e19b252 commit 1498f2d
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 19 deletions.
2 changes: 1 addition & 1 deletion subgraph/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ type Transaction @entity(immutable: true) {
events: [Event!] @derivedFrom(field: "transaction")
}

type ContextEntity implements Event @entity {
type ContextEntity @entity {
id: ID!
"Base caller"
caller: Account!
Expand Down
4 changes: 1 addition & 3 deletions subgraph/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,9 +376,7 @@ export function createSignedContext(
}
return new SignedContext("");
}
export function createContextEntity(
txHash: string
): ContextEntity {
export function createContextEntity(txHash: string): ContextEntity {
for (let i = 0; ; i++) {
let contextEntity = ContextEntity.load(`${txHash}-${i}`);
if (!contextEntity) {
Expand Down
13 changes: 0 additions & 13 deletions subgraph/tests/entities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2847,12 +2847,6 @@ async fn take_order_entity_take_order_test() -> anyhow::Result<()> {
)
.await?;

let vault_balance_alice: U256 = orderbook
.vault_balance(alice.address(), token_output.address(), vault_id)
.call()
.await?;
println!("vault_balance_alice_0: {}", vault_balance_alice);

// Take the order
let take_order_func = orderbook
.connect(&bob)
Expand All @@ -2867,15 +2861,8 @@ async fn take_order_entity_take_order_test() -> anyhow::Result<()> {

let block_data = get_block_data(&take_order_tx_hash).await?;

let vault_balance_alice: U256 = orderbook
.vault_balance(alice.address(), token_output.address(), vault_id)
.call()
.await?;
println!("vault_balance_alice_1: {}", vault_balance_alice);

// Using index 0 since only one take order was made in this tx
let take_order_entity = format!("{:?}-{}", take_order_tx_hash, 0);
println!("take_order_entity: {}", take_order_entity);

let input_token = take_order_event
.config
Expand Down
7 changes: 5 additions & 2 deletions subgraph/tests/utils/numbers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pub fn display_number(number: U256, decimals: u8) -> String {
result
}

/// TODO: WOrk in return a Result<Option<String>>
pub fn divide_decimal_strings(value_1: &str, value_2: &str) -> Option<String> {
// Parse the input strings into BigDecimal values
let decimal_1 = BigDecimal::from_str(value_1).expect("Invalid decimal value for value_1");
Expand All @@ -51,8 +52,10 @@ pub fn divide_decimal_strings(value_1: &str, value_2: &str) -> Option<String> {
// Perform the division
let result = decimal_1 / decimal_2;

let formatted_result = format!("{:.2}", result);

// Format the result as a string with a specific precision
let formatted_result = format!("{:.1}", result); // Adjust the precision as needed
let formatted_value = formatted_result.trim_end_matches('0').trim_end_matches('.');

Some(formatted_result)
Some(formatted_value.to_string())
}

0 comments on commit 1498f2d

Please sign in to comment.