How Cross-Program Invocation Unlocks BTC Composability
This post introduces Arch's Cross-Program Invocation capabilities on Bitcoin, allowing for greater composability between apps to better unlock DeFi use cases.

Modern DeFi demands seamless interaction between multiple financial protocols.
Composability is critical because it turns isolated apps into “money legos” — financial primitives that can be combined in countless ways.
A single Bitcoin-native lending protocol has limited utility. But when it can seamlessly interact with DEXs, derivatives platforms, and staking protocols? Liquidity, and possibilities, multiply exponentially.
Bitcoin can’t support a composable app ecosystem natively. However, developers can use Arch execution to create composable apps with Cross-Program Invocation.
Arch’s CPI framework makes it possible for multiple protocols to work together atomically and securely, unlocking possibilities that were previously out of reach on Bitcoin.
This piece …
- Outlines how Cross-Program Invocation unlocks Bitcoin composability
- Explains how CPI works within Arch instructions, with code examples
- Lists practical DeFi use cases that rely on CPI
- Shows how to get started building composable Bitcoin apps with Arch
Cross-Program Invocation: The Heart of Modern DeFi
At its core, CPI enables different programs to communicate and interact within a single, atomic transaction.
When a DeFi application processes a transaction on Arch Network, it can use CPI to orchestrate dependent interactions between different programs — ensuring that either all operations succeed or none of them do.
This atomic execution guarantee protects users from partial or failed transactions that could otherwise put their funds at risk.
The Power of Atomic Composition
CPI enables sophisticated financial operations by combining different primitives in a single transaction:
- Check prices across multiple oracles for the best rates
- Execute trades across several liquidity pools
- Update lending positions and collateral ratios
- Adjust insurance coverage based on new positions
- Stake rewards in yield-generating protocols
These operations execute atomically while inheriting Bitcoin's security guarantees.
Building Complex DeFi Applications
Consider a leveraged trading protocol built on Arch Network.
Through CPI, multiple programs work together seamlessly:
- The margin protocol checks the user's collateral
- Price oracles provide real-time asset valuations
- AMM protocols execute the leveraged trade
- Insurance protocols assess and cover potential risks
Each step in this process is part of a single atomic transaction, eliminating the risk of stuck trades or partial executions that plague many DeFi platforms.
How CPI works within Arch instructions
An instruction is the basic unit of program execution in Arch. It contains all the information needed for a program to execute a specific operation. Instructions are processed atomically, meaning they either complete entirely or have no effect.
Instructions can invoke other programs through CPI, enabling composability:
- Create new instruction for target program:
- Specify program ID
- Include required accounts
- Prepare instruction data
- Pass required accounts:
- Include all necessary accounts
- Set proper permissions
- Handle PDA derivation
- Invoke using invoke or invoke_signed:
- For regular accounts: invoke
- For PDAs: invoke_signed
- Handle return values
- Handle results:
- Check return status
- Process any returned data
- Handle errors appropriately
CODE EXAMPLES:
// Example of one program calling another
pub fn process_instruction(
program_id: &Pubkey,
accounts: &[AccountInfo],
instruction_data: &[u8],
) -> ProgramResult {
// Deserialize accounts
let account_info_iter = &mut accounts.iter();
let source_info = next_account_info(account_info_iter)?;
let dest_info = next_account_info(account_info_iter)?;
let system_program = next_account_info(account_info_iter)?;
// Create CPI context
let cpi_accounts = Transfer {
from: source_info.clone(),
to: dest_info.clone(),
};
let cpi_program = system_program.clone();
let cpi_ctx = CpiContext::new(cpi_program, cpi_accounts);
// Perform cross-program invocation
transfer(cpi_ctx, amount)?;
Ok(())
}
Tangible Use Cases
Let's explore how CPI enables sophisticated DeFi applications through practical examples:
1. Automated Portfolio Management
Imagine a portfolio rebalancing protocol that needs to:
- Query multiple price oracles to determine optimal asset allocation
- Execute trades across different AMMs to get the best prices
- Adjust lending positions to maintain target collateral ratios
- Update insurance coverage based on the new portfolio composition
With CPI, all these operations happen in a single atomic transaction.
If any step fails (like if a price slips too much), the entire transaction reverts, protecting the user's funds.
2. Flash Loan Arbitrage
A flash loan arbitrage bot can:
- Borrow assets from a lending protocol
- Execute trades across multiple DEXs to capture price differences
- Repay the loan with profits
- Distribute rewards to stakeholders
CPI ensures that either the entire arbitrage succeeds and the loan is repaid, or the transaction reverts with no effect. This atomic execution is crucial for flash loan security.
3. Yield Farming Optimization
A yield optimization protocol can automatically:
- Harvest rewards from multiple farming positions
- Swap rewards for optimal tokens using the best available rates
- Reinvest into the highest-yielding opportunities
- Update user positions and reward distributions
All these steps execute as one atomic operation, maximizing efficiency and minimizing gas costs while ensuring safety.
Start Building Composable DeFi Apps on Bitcoin
The next generation of DeFi applications will be built as compositions of specialized protocols. Arch Network's CPI system provides the foundation for this future, enabling complex interactions while maintaining the security and atomicity that DeFi users demand.
Want to go deeper? Read our full whitepaper or reach out to our developer team on Discord to learn how to build with Arch.