Skip to content

Commit

Permalink
feat(CA): removing check endpoint, updating the route and status resp…
Browse files Browse the repository at this point in the history
…onse schema
  • Loading branch information
geekbrother committed Nov 11, 2024
1 parent f8b25d5 commit 7a31c8e
Show file tree
Hide file tree
Showing 8 changed files with 216 additions and 418 deletions.
61 changes: 13 additions & 48 deletions integration/chain_orchestrator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,37 +31,6 @@ describe('Chain abstraction orchestrator', () => {

let orchestration_id = "";

it('bridging available', async () => {
// Sending USDC to Optimism, but having the USDC balance on Base chain
const data_encoded = erc20Interface.encodeFunctionData('transfer', [
receiver_address,
amount_to_send,
]);

let transactionObj = {
transaction: {
from: from_address_with_funds,
to: usdc_contract_optimism,
value: "0x00", // Zero native tokens
gas: "0x00",
gasPrice: "0x00",
data: data_encoded,
nonce: "0x00",
maxFeePerGas: "0x00",
maxPriorityFeePerGas: "0x00",
chainId: chain_id_optimism,
}
}

let resp: any = await httpClient.post(
`${baseUrl}/v1/ca/orchestrator/check?projectId=${projectId}`,
transactionObj
)
expect(resp.status).toBe(200)
expect(typeof resp.data.requiresMultiChain).toBe('boolean')
expect(resp.data.requiresMultiChain).toBe(true)
})

it('bridging unavailable (insufficient funds)', async () => {
// Having the USDC balance on Base chain less then the amount to send
const amount_to_send_in_decimals = usdc_funds_on_base + 10_000_000
Expand All @@ -86,12 +55,11 @@ describe('Chain abstraction orchestrator', () => {
}

let resp: any = await httpClient.post(
`${baseUrl}/v1/ca/orchestrator/check?projectId=${projectId}`,
`${baseUrl}/v1/ca/orchestrator/route?projectId=${projectId}`,
transactionObj
)
expect(resp.status).toBe(200)
expect(typeof resp.data.requiresMultiChain).toBe('boolean')
expect(resp.data.requiresMultiChain).toBe(false)
expect(resp.data.error).toBe("INSUFFICIENT_FUNDS")
})

it('bridging unavailable (empty wallet)', async () => {
Expand Down Expand Up @@ -119,18 +87,16 @@ describe('Chain abstraction orchestrator', () => {
}

let resp: any = await httpClient.post(
`${baseUrl}/v1/ca/orchestrator/check?projectId=${projectId}`,
`${baseUrl}/v1/ca/orchestrator/route?projectId=${projectId}`,
transactionObj
)
expect(resp.status).toBe(200)
expect(typeof resp.data.requiresMultiChain).toBe('boolean')
expect(resp.data.requiresMultiChain).toBe(false)
expect(resp.data.error).toBe("INSUFFICIENT_FUNDS")
})

it('bridging routes (no routes)', async () => {
it('bridging routes (no bridging needed)', async () => {
// Sending USDC to Optimism, having the USDC balance on Base chain
// with MIN_AMOUNT_NOT_MET error expected
const amount_to_send_in_decimals = 20_000 // Less then minimum amount required
const amount_to_send_in_decimals = 20_000 // Less then bridging needed amount
const data_encoded = erc20Interface.encodeFunctionData('transfer', [
receiver_address,
amount_to_send_in_decimals,
Expand All @@ -155,7 +121,9 @@ describe('Chain abstraction orchestrator', () => {
`${baseUrl}/v1/ca/orchestrator/route?projectId=${projectId}`,
transactionObj
)
expect(resp.status).toBe(400)
expect(resp.status).toBe(200)
expect(resp.data.transactions.length).toBe(0)

})

it('bridging routes (routes available)', async () => {
Expand Down Expand Up @@ -188,8 +156,8 @@ describe('Chain abstraction orchestrator', () => {

const data = resp.data
expect(typeof data.orchestrationId).toBe('string')
// Expecting 3 transactions in the route
expect(data.transactions.length).toBe(3)
// Expecting 2 transactions in the route
expect(data.transactions.length).toBe(2)

// First transaction expected to be the approval transaction
const approvalTransaction = data.transactions[0]
Expand All @@ -205,10 +173,6 @@ describe('Chain abstraction orchestrator', () => {
expect(bridgingTransaction.nonce).not.toBe("0x00")
expect(bridgingTransaction.gas).toBe(gas_estimate)

// Last transaction expected to be the initial one
const initialTransaction = data.transactions[2]
expect(initialTransaction.data).toBe(transactionObj.transaction.data)

// Check the metadata fundingFrom
const fundingFrom = data.metadata.fundingFrom[0]
expect(fundingFrom.chainId).toBe(chain_id_base)
Expand All @@ -226,6 +190,7 @@ describe('Chain abstraction orchestrator', () => {
expect(resp.status).toBe(200)
const data = resp.data
expect(typeof data.status).toBe('string')
expect(data.status).toBe('pending')
expect(data.status).toBe('PENDING')
expect(data.checkIn).toBe(3000)
})
})
33 changes: 0 additions & 33 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,15 +239,6 @@ pub enum RpcError {
#[error("ABI decoding error: {0}")]
AbiDecodingError(String),

#[error("No bridging needed")]
NoBridgingNeeded,

#[error("No bridging available")]
NoBridgingAvailable,

#[error("No routes available for the bridging")]
NoBridgingRoutesAvailable,

#[error("Orchestration ID is not found: {0}")]
OrchestrationIdNotFound(String),
}
Expand Down Expand Up @@ -634,30 +625,6 @@ impl IntoResponse for RpcError {
)),
)
.into_response(),
Self::NoBridgingNeeded => (
StatusCode::BAD_REQUEST,
Json(new_error_response(
"".to_string(),
"No bridging needed".to_string(),
)),
)
.into_response(),
Self::NoBridgingAvailable => (
StatusCode::BAD_REQUEST,
Json(new_error_response(
"".to_string(),
"No bridging available".to_string(),
)),
)
.into_response(),
Self::NoBridgingRoutesAvailable => (
StatusCode::BAD_REQUEST,
Json(new_error_response(
"".to_string(),
"No bridging routes available".to_string(),
)),
)
.into_response(),
Self::OrchestrationIdNotFound(id) => (
StatusCode::BAD_REQUEST,
Json(new_error_response(
Expand Down
172 changes: 0 additions & 172 deletions src/handlers/chain_agnostic/check.rs

This file was deleted.

4 changes: 2 additions & 2 deletions src/handlers/chain_agnostic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use {
std::{collections::HashMap, str::FromStr},
};

pub mod check;
pub mod route;
pub mod status;

Expand Down Expand Up @@ -36,11 +35,12 @@ pub struct StorageBridgingItem {
contract: Address,
amount_expected: U256,
status: BridgingStatus,
error_reason: Option<String>,
}

/// Bridging status
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[serde(rename_all = "UPPERCASE")]
pub enum BridgingStatus {
Pending,
Completed,
Expand Down
Loading

0 comments on commit 7a31c8e

Please sign in to comment.