bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 75쪽 중 12쪽
echanism.md).
<a id="parameters"></a>
## Parameters
| Signature | Mutability | Returns | Unit / meaning |
| --- | --- | --- | --- |
| `A()` | view | `uint256` | Amplification parameter in contract precision |
| `gamma()` | view | `uint256` | Compatibility value; unused by the FXSwap invariant |
| `precisions()` | view | `uint256[2]` | Token precision multipliers |
| `allowed_extra_profit()` | view | `uint256` | Recentring profit buffer, 1e18 |
| `adjustment_step()` | view | `uint256` | Minimum recentering step, 1e18 |
| `ma_time()` | view | `uint256` | Approximate EMA half-life, seconds |
<a id="lp-token-methods"></a>
## LP Token Methods
The pool is its own 18-decimal ERC-20 LP token:
| Signature | Mutability | Returns |
| --- | --- | --- |
| `name()` | view | `string` |
| `symbol()` | view | `string` |
| `decimals()` | view | `uint8` |
| `version()` | view | `string` |
| `totalSupply()` | view | `uint256` |
| `balanceOf(address owner)` | view | `uint256` |
| `allowance(address owner, address spender)` | view | `uint256` |
| `approve(address spender, uint256 value)` | nonpayable | `bool` |
| `transfer(address to, uint256 value)` | nonpayable | `bool` |
| `transferFrom(address from, address to, uint256 value)` | nonpayable | `bool` |
`totalSupply()` includes refuel shares. Use `user_supply()` when an application needs the user-owned LP supply.
<a id="contract-info"></a>
## Contract Info
| Signature | Mutability | Returns | Meaning |
| --- | --- | --- | --- |
| `coins(uint256 i)` | view | `address` | Token address at index `i` |
| `balances(uint256 i)` | view | `uint256` | Internally accounted raw token balance |
| `factory()` | view | `address` | Factory and admin source |
| `admin()` | view | `address` | Admin read through the factory |
| `fee_receiver()` | view | `address` | Fee receiver read through the factory |
| `MATH()` | view | `address` | Current Math contract |
| `VIEW()` | view | `address` | Current Views contract |
| `D()` | view | `uint256` | Cached invariant |
| `initial_A_gamma()` | view | `uint256` | Packed ramp start |
| `future_A_gamma()` | view | `uint256` | Packed ramp target |
| `initial_A_gamma_time()` | view | `uint256` | Ramp start timestamp |
| `future_A_gamma_time()` | view | `uint256` | Ramp end timestamp |
| `packed_fee_params()` | view | `uint256` | Packed dynamic-fee configuration |
| `packed_rebalancing_params()` | view | `uint256` | Packed recentering configuration |
Prefer decoded getters such as `mid_fee()`, `out_fee()`, `fee_gamma()`, `allowed_extra_profit()`, `adjustment_step()`, and `ma_time()` instead of unpacking values in application code.
<a id="admin-controls"></a>
## Admin controls
Every method below is nonpayable and checks the factory-provided admin:
| Signature | Guard / effect |
| --- | --- |
| `ramp_A_gamma(uint256 future_A, uint256 future_gamma, uint256 future_time)` | Starts a bounded ramp lasting at least the contract minimum |
| `stop_ramp_A_gamma()` | Stops an active ramp at current values |
| `apply_new_parameters(uint256 mid_fee, uint256 out_fee, uint256 fee_gamma, uint256 allowed_extra_profit, uint256 adjustment_step, uint256 ma_exp_time)` | Updates validated fee and recentering parameters; the last argument is the internal EMA exponent denominator, approximately `half_life / ln(2)` |
| `set_donation_duration(uint256 duration)` | Requires `duration > 0`; emits `SetDonationDuration` |
| `set_donation_protection_params(uint256 period, uint256 threshold, uint256 max_shares_ratio)` | Requires positive values; ratios use 1e18 precision; emits `SetDonationProtection` |
| `set_admin_fee(uint256 admin_fee)` | Requires a value at or below the contract maximum; 1e10 precision; emits `SetAdminFee` |
| `set_periphery(address views, address math)` | Updates either or both periphery addresses; at least one must be non-zero; emits `SetPeriphery` |
`apply_new_parameters` uses compatibility-preserving sentinel behavior: out-of-range values for an individual field retain that field's current value, while combinations such as `mid_fee > out_fee` still revert. Read the emitted `NewParameters` event or decoded getters after the transaction instead of assuming every requested value was applied. `NewParameters.ma_time` is the internal exponent parameter; `ma_time()` returns its approximate half-life in seconds.
Version boundary
`set_donation_parameters`, `POLICY`, allowlist methods, and `reserved_profit_fraction` occur in a later development design. They are not part of deployed `v2.1.0d` and are intentionally absent from this reference.
<a id="events"></a>
## Events
```solidity
event TokenExchange(
address indexed buyer,
uint256 sold_id,
uint256 tokens_sold,
uint256 bought_id,
uint256 tokens_bought,
uint256 fee,
uint256 price_scale
);
event AddLiquidity(
address indexed provider,
address indexed receiver,
uint256[2] token_amounts,
uint256 fee,
uint256 token_supply,
uint256 price_scale
);
event Donation(address indexed donor, uint256[2] token_amounts);
event RemoveLiquidity(address indexed provider, uint256[2] token_amounts, uint256 token_supply);
event RemoveLiquidityOne(
address indexed provider,
uint256 token_amount,
uint256 coin_index,
uint256 coin_amount,
uint256 approx_fee,
uint256 packed_price_scale
);
event RemoveLiquidityImbalance(
address indexed provider,
uint256 lp_token_amount,
uint256[2] token_amounts,
uint256 approx_fee,
uint256 price_scale
);
event NewParameters(
uint256 mid_fee,
uint256 out_fee,
uint256 fee_gamma,
uint256 allowed_extra_profit,
uint256 adjustment_step,
uint256 ma_time
);
event RampAgamma(
uint256 initial_A,
uint256 future_A,
uint256 initial_gamma,
uint256 future_gamma,
uint256 initial_time,
uint256 future_time
);
event StopRampA(uint256 current_A, uint256 current_gamma, uint256 time);
event ClaimAdminFee(address indexed admin, uint256[2] tokens);
event SetDonationDuration(uint256 duration);
event SetDonationProtection(
uint256 donation_protection_period,
uint256 donation_protection_lp_threshold,
uint256 donation_shares_max_ratio
);
event SetAdminFee(uint256 admin_fee);
event SetPeriphery(address views, address math);
event Transfer(address indexed sender, address indexed receiver, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
```
`Donation` is the immutable deployed event name for a refuel. Its token amounts and all swap/liquidity event amounts are raw token units. Decode events by pool address and versioned ABI.
---
# FXSwap Mechanism and Parameter Design
Source: [https://docs.curve.finance/developer/amm/fxswap/pools/mechanism](https://docs.curve.finance/developer/amm/fxswap/pools/mechanism)
FXSwap concentrates passive, full-range liquidity around a moving `price_scale`. It is designed for two-asset markets whose primary price discovery happens outside the pool and whose liquidity can be recentered through arbitrage, trading profit, and a finite refuel budget.
This page is for protocol teams evaluating or operating a market. Route aggregators can start with the [integration guide](https://docs.curve.finance/developer/amm/fxswap/guides/integration.md); contract researchers should use the [FXSwap Pool](https://docs.curve.finance/developer/amm/fxswap/pools/fxswap.md).
<a id="when-fxswap-fits"></a>
## When FXSwap fits
Volatility alone does not determine whether a pair fits FXSwap. The important inputs are external price discovery, market depth, arbitrage access, desired concentration, and the cost of recentering.
| Market property | FXSwap implication |
| --- | --- |
| Reliable external reference market | Gives arbitrageurs a price against which to trade the pool |
| Sufficient external depth | Makes it more likely that arbitrage remains economical at useful trade sizes |
| Passive liquidity is preferred | Avoids requiring LPs to choose and manage active ranges |
| Sustainable recentering budget | Supports the desired concentration as the external price moves |
| Primary price discovery occurs in this Curve pool | Usually favors CryptoSwap rather than FXSwap |
Fiat FX pairs are a natural use case, but externally priced volatile pairs such as BTC/USD can also fit. They generally require more careful parameter selection and stress testing because larger or faster moves can increase recentering demand.
<a id="price-tracking-and-recentering"></a>
## Price tracking and recentering
The pool maintains three related prices:
| Getter | Precision | Role |
| --- | --- | --- |
| `last_prices()` | 1e18 | Most recently observed normalized trade price |
| `price_oracle()` | 1e18 | Exponential moving-average target derived from recent prices |
| `price_scale()` | 1e18 | Current center of the pool's concentrated liquidity |
Each expresses the price of `coins(1)` in `coins(0)` units. A state-changing pool operation can update the oracle and, when the contract's conditions are satisfied, move `price_scale` toward `price_oracle`.
The deployed implementation evaluates `tweak_price` after swaps, liquidity additions, fixed-out withdrawals, and one-coin withdrawals. A call does not guarantee a recenter. The contract first updates price and profit state, then checks the oracle distance, configured step, profit threshold, and available refuel support before accepting a new `price_scale`.
The invariant concentrates liquidity around `price_scale` with amplification `A`. Unlike ordinary Twocrypto, the reviewed FXSwap invariant does not use `gamma` to shape a CryptoSwap curve; `gamma()` remains in the ABI for compatibility. Higher concentration can improve execution near the center but raises sensitivity to movement away from it and can increase the budget required to recenter.
The deployed source makes the state transition boundary explicit:
```vyper
def tweak_price(
A_gamma: uint256[2],
_xp: uint256[N_COINS],
D: uint256,
) -> uint256:
"""
Updates price_oracle, last_price and conditionally adjusts
price_scale. This is called whenever there is an unbalanced
liquidity operation.
"""
```
Refuels do not set an external price and do not force a rebalance. They help pay the cost when the pool's normal recentering logic moves concentrated liquidity. Read [Refuels](https://docs.curve.finance/developer/amm/fxswap/pools/refuels.md) for unlocking, protection, burn priority, and depletion.
Read [FXSwap Oracles](https://docs.curve.finance/developer/amm/fxswap/pools/oracles.md) for the complete price direction, update cadence, EMA calculation, and safe integration boundary.
<a id="the-recentering-budget"></a>
## The recentering budget
Moving concentrated liquidity can reduce the pool's measured profit. FXSwap can fund that movement from:
1. unlocked refuel shares that have passed the protection rules; and
2. the pool's normal profit buffer when more funding is required.
This makes refuels a spendable market-liquidity budget, not recoverable principal. A protocol can observe the outstanding shares and public unlock parameters, but the deployed `v2.1.0d` interface does not expose separate getters for the exact locked, unlocked, protected, and immediately burnable amounts.
<a id="dynamic-fees"></a>
## Dynamic fees
The swap fee moves between `mid_fee()` and `out_fee()` according to the pool's normalized balance. `fee_gamma()` controls the transition. A more balanced pool receives a fee nearer `mid_fee`; increasing imbalance moves the fee toward `out_fee`.
The deployed calculation uses the normalized `xp` balances, not raw token balances:
```vyper
# balance indicator: 1e18 when balanced, toward 0 when imbalanced
B = PRECISION * N_COINS**N_COINS * xp[0] // B * xp[1] // B
# fee_gamma shapes the transition between the bounds
B = fee_gamma * B // (fee_gamma * B // 10**18 + 10**18 - B)
return (mid_fee * B + out_fee * (10**18 - B)) // 10**18
```
This excerpt names unpacked values for readability; the deployed contract stores the three fee parameters in `packed_fee_params`. Applications should call `fee()` or `fee_calc(xp)` rather than reimplementing the packed-state logic unless exact reproduction is required and versioned.
<a id="parameter-interactions"></a>
## Parameter interactions
Parameters must be selected together. Raising concentration without providing enough room, fees, or recentering budget can improve quotes near the center while making the pool more fragile when the external price moves.
| Parameter | Unit / precision | Primary effect | Interaction to test |
| --- | --- | --- | --- |
| `A()` | Contract amplification precision | Controls StableSwap-style concentration around `price_scale` | Higher concentration can improve near-center depth and increase recentering cost |
| `mid_fee()` | 1e10 | Lower dynamic-fee bound | Affects routine execution and fee income |
| `out_fee()` | 1e10 | Upper dynamic-fee bound | Must remain low enough for useful rebalancing flow while charging adverse imbalance |
| `fee_gamma()` | 1e18 | Shapes the transition between fee bounds | Changes how quickly fees rise with imbalance |
| `ma_time()` | approximate half-life, seconds | Controls oracle smoothing | Too slow can lag the external market; too fast can follow short-lived moves |
| `allowed_extra_profit()` | 1e18 | Profit buffer before recentering | Interacts with how readily the pool moves `price_scale` |
| `adjustment_step()` | 1e18 | Minimum recentering step | Affects the size and frequency of adjustments |
| Refuel schedule | Token amounts and seconds | Supplies the finite external budget | Must be evaluated against volatility, concentration, fees, and expected flow |
`gamma()` remains in the ABI for compatibility but is unused by the reviewed FXSwap invariant.
<a id="mutable-parameters"></a>
### Mutable parameters
The factory admin can:
- ramp `A` through `ramp_A_gamma` and stop a ramp;
- update `mid_fee`, `out_fee`, `fee_gamma`, `allowed_extra_profit`, `adjustment_step`, and the internal EMA exponent parameter together through `apply_new_parameters`;
- update refuel duration and protection parameters;
- update `admin_fee`, `VIEW()`, and `MATH()`.
After a parameter event, applications should invalidate cached fee and recentering configuration, re-read the target pool, and reassess quotes, monitoring thresholds, withdrawal assumptions, and refuel demand. Index `NewParameters`, `RampAgamma`, `StopRampA`, `SetDonationDuration`, `SetDonationProtection`, `SetAdminFee`, and `SetPeriphery`.
<a id="separate-facts-from-model-inputs"></a>
## Separate facts from model inputs
| Category | Examples | Interpretation |
| --- | --- | --- |
| Onchain getters | `A`, fees, `ma_time`, `price_oracle`, `price_scale`, refuel state | Current deployed pool state at a specific block |
| Simulation inputs | Assumed refuel or boost rate, parameter search ranges, historical replay window | Choices made by the model; not necessarily onchain getters or future settings |
| Offchain market assumptions | External depth, reference prices, arbitrage costs, organic flow, gas | Inputs outside the pool that must be sourced and stress-tested |
Do not present a simulation input as a deployed default or an offchain assumption as a contract guarantee.
Do not copy example parameters
Parameters that work for one pair, time period, or external market can fail for another. Read the target pool's current values and treat historical configurations as dated evidence, not defaults.
<a id="simulation-driven-design"></a>
## Simulation-driven design
The Curve simulation workflow described in [FXSwap Simulations: Behind the Scenes](https://news.curve.finance/fxswap-simulations/) replays historical price data against many parameter combinations. It models whether arbitrage would be economical after external market depth and trading costs, then measures outcomes such as price tracking, imbalance, execution, pool profitability, and refuel demand.
A practical design workflow is:
1. Define the external reference market, coin order, token behavior, and usable historical data.
2. Model external liquidity depth and arbitrage costs instead of assuming unlimited rebalancing.
3. Search combinations of `A`, dynamic-fee settings, oracle smoothing, recentering parameters, and a proposed refuel schedule.
4. Evaluate several outcomes together; do not optimize only for the best near-center quote.
5. Stress periods with fast moves, thin external liquidity, and prolonged one-directional flow.
6. Deploy conservatively, monitor observed behavior, and re-simulate before changing parameters.
In simulation discussions, **refuel rate** or **boost rate** describes an assumed funding schedule. It is not a deployed pool getter.
Backtests are decision support, not guarantees
The published simulation methodology models arbitrage flow and relies on assumptions about external depth and costs. Organic flow is uncertain, historical volatility may not repeat, and parameter optimization does not eliminate market or LP risk.
<a id="dated-performance-evidence"></a>
## Dated performance evidence
An independent analysis summarized in the [January 9, 2026 FXSwap article](https://news.curve.finance/fxswap/) compared a YieldBasis WBTC route with a Uniswap V3 WBTC/USDC pool over November 1–December 17. For a $10 million quoted trade, the article reports better FXSwap execution in approximately 80% of observed blocks, with about 2% average improvement. Quotes included swap fees and excluded gas.
This is evidence for those pools, trade sizes, market conditions, and dates. It is not a general promise about another FXSwap deployment or smaller trades. Integrators should quote the live pool, and protocol teams should reproduce relevant simulations for their own market.
<a id="operating-checklist"></a>
## Operating checklist
- Monitor `price_oracle()` relative to `price_scale()` and the external reference market.
- Track pool balances, realized fees, refuel shares, and refuel depletion.
- Measure live execution across representative trade sizes, not only spot price.
- Revisit assumptions when external market depth, token redemption paths, volatility, or flow changes.
- Simulate and govern parameter changes as a coordinated set.
---
# FXSwap Oracles
Source: [https://docs.curve.finance/developer/amm/fxswap/pools/oracles](https://docs.curve.finance/developer/amm/fxswap/pools/oracles)
FXSwap uses an exponential moving average (EMA) of its own observed prices to guide gradual changes to the center of liquidity. The oracle is AMM state: it helps the pool recenter, but it is not automatically suitable as a lending, liquidation, or solvency oracle.
Contract Source & Deployment
This page documents the oracle behavior of deployed FXSwap pools reporting `version() == "v2.1.0d"`. The verified pool source was compiled with Vyper `0.4.3` and is closest to [`curvefi/twocrypto-ng@387fbe5`](https://github.com/curvefi/twocrypto-ng/commit/387fbe5f12473ef0e1f0c6a76bc38f1ca0da669d).
Read these getters from the target pool. They are pool methods, not a separate external-price oracle contract.
<a id="price-direction-and-precision"></a>
## Price direction and precision
`last_prices()`, `price_oracle()`, and `price_scale()` all use 1e18 precision and express the price of `coins(1)` in units of `coins(0)`.
For a USDC/WBTC pool ordered as `[USDC, WBTC]`, a value near `100_000e18` means one WBTC is worth approximately 100,000 USDC. Always read `coins(0)` and `coins(1)` instead of inferring direction from a pool name.
| Getter | Meaning | Update behavior |
| --- | --- | --- |
| `last_prices() -> uint256` | Latest normalized price observed by the pool | Stored during a state-changing operation; explicitly treated as manipulable spot state |
| `price_oracle() -> uint256` | Current EMA value | Calculates the time-decayed value at the current timestamp, even when cached storage has not yet changed |
| `price_scale() -> uint256` | Center around which liquidity is concentrated | Changes only when the recentering conditions pass |
| `last_timestamp() -> u프로젝트로 돌아가기