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(ca_orchestration): implementing chain agnostic orchestration check endpoint #795

Merged
merged 2 commits into from
Oct 24, 2024

Conversation

geekbrother
Copy link
Contributor

@geekbrother geekbrother commented Sep 27, 2024

Description

This PR implements the chain agnostic bridging check endpoint according to the research draft doc.

The endpoint processing the transaction object and making the following checks to return is the bridging required for the transaction:

  • Checking the native token balance of the address and compare it to the transaction value. If the native token value >= transaction amount, then return false for the bridging.
  • Checking the transaction data by decoding it to the ERC20 contract ABI and check is the function call is transfer. If it's not, return false for the bridging.
  • Checking the address balances for each of the supported bridging assets and if the balance is more or equal then transaction value returns true for the bridging.
  • Returning false if no bridging assets was found.

What's not included:

  • Partners ABIs are out of scope in this PR and should be a follow-up.

How Has This Been Tested?

  • Manually at the moment, integration tests TBD.

Due Diligence

  • Breaking change
  • Requires a documentation update
  • Requires a e2e/integration test update

@geekbrother geekbrother self-assigned this Sep 27, 2024
@geekbrother geekbrother marked this pull request as ready for review September 27, 2024 13:15
@geekbrother geekbrother marked this pull request as draft September 27, 2024 13:53
@geekbrother geekbrother force-pushed the feat/ca_orchestration_check branch from e2071a1 to 6af3a0c Compare September 27, 2024 17:26
@geekbrother geekbrother changed the title feat(ca_orchestration): implementing chain agnostic orchestration check endpoint DRAFT: feat(ca_orchestration): implementing chain agnostic orchestration check endpoint Sep 27, 2024
@geekbrother geekbrother changed the title DRAFT: feat(ca_orchestration): implementing chain agnostic orchestration check endpoint feat(ca_orchestration): implementing chain agnostic orchestration check endpoint Sep 27, 2024
@geekbrother geekbrother marked this pull request as ready for review September 27, 2024 17:31
)
.await?;
let transfer_value_stripped = request_payload.transaction.value.trim_start_matches("0x");
let transfer_value = U256::from_dec_str(transfer_value_stripped)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be from_hex_str not decimal? Didn't look at docs though

}

// Check the ERC20 tokens balance for each of supported assets
for (asset, chains) in BRIDGING_AVAILABLE_ASSETS.entries() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a LOT of looping. This will take a long time as well as exhaust a lot of API calls.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 on this. Now we have 3 chains and 1 asset for the demo purposes, however this is very much going to increase in the future in both ways

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use our balance API (which is Zerion API actually) to get the available balance without JSON-RPC calls for each contract, but the issue is that the address balance in this case is not the latest (Zerion cache is about 2 minutes) and we are using the JSON-RPC call as well to fetch the latest balance for example for swaps. Not sure how this will impact the UX.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@geekbrother Balance call is extremely expensive. We should look into minimizing the amount of those.

) -> Result<Erc20FunctionType, CryptoUitlsError> {
// Get the 4 bytes function selector
let selector: [u8; 4] = function_data[0..4].try_into().map_err(|_| {
CryptoUitlsError::Erc20DecodeError("Function data is less then 4 bytes.".into())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this error be caught by the handler function? If they aren't using ERC-20 transfer should it still require multi chain bridging?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's another case: the function selector in the ERC20 contract is 4 bytes, so if the function data is less, that means that's not the ERC20 contract. The function type check is in the handler here and we are returning false for the bridging if that's not a transfer. I don't think we should check the balance if that's not a transfer cc @lukaisailovic
The web example also have this check btw.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@geekbrother The web code works only for ERC20 transfers and nothing else. Its meant to be used as a showcase

@geekbrother geekbrother force-pushed the feat/ca_orchestration_check branch from 68a1395 to a8568ac Compare October 24, 2024 18:22
@geekbrother geekbrother merged commit 3909b8d into master Oct 24, 2024
19 checks passed
@geekbrother geekbrother deleted the feat/ca_orchestration_check branch October 24, 2024 18:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants