Building DeFi Applications on NEAR Protocol: Developer Tutorial
NEAR's DeFi ecosystem is smaller than Ethereum but has key advantages: low transaction fees (under $0.01), 1-2 second finality, and the Aurora EVM for bridging Ethereum DeFi strategies.
Key DeFi Protocols on NEAR
Ref.finance: The primary DEX AMM on NEAR. Supports constant-product pools (xy=k), stable pools, and rated pools for liquid staking tokens. TVL typically ranges $50-150M.
Burrow: NEAR's lending protocol similar to Aave. Supports USDC, wNEAR, USDT, and other assets. Interest rates are algorithmically determined by utilization.
Meta Pool: Liquid staking for NEAR. Deposit NEAR, receive stNEAR which accrues staking rewards while remaining liquid.
Calling Ref.finance from a Contract
use near_sdk::ext_contract;
#[ext_contract(ext_ref)]
trait RefFinance {
fn swap(
&mut self,
actions: Vec<SwapAction>,
referral_id: Option<AccountId>
) -> U128;
}
// In your contract:
pub fn execute_swap(&mut self, pool_id: u64, amount_in: U128) -> Promise {
let action = SwapAction {
pool_id,
token_in: self.token_in.clone(),
amount_in: Some(amount_in),
token_out: self.token_out.clone(),
min_amount_out: U128(1),
};
ext_ref::ext(REF_FINANCE_ACCOUNT)
.with_attached_deposit(1)
.swap(vec![action], None)
}
NEP-141 Token Standard for DeFi
All DeFi on NEAR uses fungible tokens via NEP-141. The key method for DeFi integrations is ft_transfer_call which atomically transfers tokens and calls a receiver contract. This is how Ref.finance, Burrow, and other protocols accept deposits.
Flash Loans on NEAR
NEAR's async execution model makes traditional flash loans more complex than Ethereum. Flash loans must complete within a single transaction receipt chain. Ref.finance supports flash loans via its swap mechanism where you can borrow, use, and repay within the same action chain.
Yield Strategy Patterns
A typical yield aggregator on NEAR follows this pattern:
- User deposits USDC via ft_transfer_call to your strategy contract
- Strategy splits deposit: 50% to Burrow for lending yield, 50% to Ref.finance LP
- Strategy mints receipt tokens representing proportional claim
- Harvest function periodically claims rewards and reinvests
- User withdraws by burning receipt tokens
Aurora EVM Bridge
Aurora is an EVM running on NEAR, enabling Solidity contracts to interact with NEAR native contracts. Use Aurora if you want to port existing Ethereum DeFi strategies to NEAR without rewriting in Rust. Gas costs on Aurora are paid in ETH but ultimately settled on NEAR.
Security Considerations for NEAR DeFi
- Always use checked arithmetic for token amount calculations
- Validate that ft_transfer_call sender matches expected token contract
- Implement slippage protection with min_amount_out parameters
- Test all cross-contract call flows in NEAR Sandbox before testnet deployment
- Consider storage staking requirements for user position tracking
Written by Alex Chen | alexchen.chitacloud.dev | February 26, 2026