Interest rate swaps

INTEREST RATE SWAP 1 Parties agree terms 2 PartyA sends notional USDXT to SwapContract 3 PartyB sends notional USDXT to SwapContract 4 PartyA sends fixed interest USDXT to SwapContract 5 PartyB sends floating interest USDXT to SwapContract 6 SwapContract nets interest USDXT 7 SwapContract sends net interest USDXT to owed party 8 SwapContract returns notional USDXT to PartyA 9 SwapContract returns notional USDXT to PartyB

INTEREST RATE SWAP FLOW
Setup
1 PartyA agrees to pay fixed rate to PartyB
2 PartyB agrees to pay floating rate to PartyA
3 Both parties agree notional amount and maturity
Initiation
4 PartyA deposits notional USDXT to SwapContract
5 PartyB deposits notional USDXT to SwapContract
6 SwapContract locks both deposits until maturity
Settlement at Maturity
7 Admin sets floating rate in SwapContract
8 SwapContract calculates fixed payment from notional
9 SwapContract calculates floating payment from notional
10 SwapContract nets payments to find difference
11 SwapContract returns notional USDXT to PartyA
12 SwapContract returns notional USDXT to PartyB
13 SwapContract sends net interest USDXT to owed party


Setup
1 PartyA agrees to pay fixed rate to PartyB
2 PartyB agrees to pay floating rate to PartyA
3 Both parties agree notional amount and maturity

Initiation
4 PartyA deposits notional USDXT to SwapContract
5 PartyB deposits notional USDXT to SwapContract
6 SwapContract locks both deposits until maturity

Rate Management
7 Admin updates floating rate in SwapContract as needed
8 SwapContract stores current floating rate for all swaps

Settlement at Maturity
9 Admin calls settleSwap when swap reaches maturity
10 SwapContract calculates annualized fixed payment
11 SwapContract calculates annualized floating payment using current rate
12 SwapContract nets payments to find difference
13 SwapContract returns notional USDXT to PartyA
14 SwapContract returns notional USDXT to PartyB
15 SwapContract sends net interest USDXT to owed party



INTEREST RATE SWAP ATOMIC HTLC FLOW
Setup
1 PartyA agrees to pay fixed rate to PartyB
2 PartyB agrees to pay floating rate to PartyA
3 Both parties agree notional amount maturity bespoke rates and secret hash
Atomic Initiation
4 SwapContract creates swap struct with bespoke floating rate
5 PartyA transfers notional USDXT to SwapContract
6 PartyB transfers notional USDXT to SwapContract
7 SwapContract marks notionalDeposited only after both transfers succeed
8 If either transfer fails entire transaction reverts
Per-Swap Rate Management
9 Admin updates specific swap's floating rate as needed
10 Each swap maintains its own floating rate for bespoke terms
Atomic HTLC Settlement at Maturity
11 Admin reveals secret preimage to unlock specific swap
12 SwapContract verifies preimage matches swap's hashlock
13 SwapContract calculates payments using swap's specific rates
14 SwapContract transfers notional USDXT to PartyA
15 SwapContract transfers notional USDXT to PartyB
16 SwapContract transfers net interest USDXT to owed party
17 All transfers must succeed or entire settlement reverts
Atomic Refund Path
18 If admin doesn't settle after maturity either party can refund
19 SwapContract returns notional USDXT to PartyA
20 SwapContract returns notional USDXT to PartyB
21 Both refunds must succeed or transaction reverts



ENHANCED INTEREST RATE SWAP FLOW
Setup
1 PartyA agrees to pay fixed rate to PartyB
2 PartyB agrees to pay floating rate to PartyA
3 Both parties agree notional amount maturity rates secret hash and day count convention
Atomic Initiation with Gas Optimization
4 SwapContract creates swap with day count convention ACT_360 ACT_365 or ACTUAL
5 PartyA transfers 18-decimal collateral to SwapContract
6 PartyB transfers 18-decimal collateral to SwapContract
7 SwapContract marks notionalDeposited only after both succeed
8 SwapContract emits NotionalDeposited and SwapInitiated events
Restricted Rate Management
9 Admin updates swap's floating rate only before maturity
10 Rate updates blocked after maturity for finality
11 Each swap maintains bespoke floating rate
Enhanced Settlement with Storage Reclaim
12 Admin settles at maturity with preimage verification
13 SwapContract calculates payments using day count convention
14 SwapContract transfers notional and net payment atomically
15 SwapContract emits SwapSettled event
16 SwapContract deletes swap storage to reclaim gas
Enhanced Refund with Storage Reclaim
17 Either party can refund after maturity if not settled
18 SwapContract returns notional amounts atomically
19 SwapContract emits SwapRefunded event
20 SwapContract deletes swap storage to reclaim gas

PUBLIC AND EXTERNAL FUNCTIONS
initiateSwap(bytes32 _swapId, address _floatingPayer, IERC20 _collateralToken, uint256 _notionalAmount, uint256 _fixedRate, uint256 _floatingRate, uint256 _maturity, bytes32 _hashlock, DayCountConvention _dayCount): Creates swap with day count convention and atomic deposits.
updateFloatingRate(bytes32 _swapId, uint256 _newRate): Admin updates floating rate before maturity only.
settleSwap(bytes32 _swapId, bytes32 _preimage): Admin settles swap and clears storage for gas reclaim.
refundSwap(bytes32 _swapId): Parties refund after maturity and clear storage for gas reclaim.
getSwapDetails(bytes32 _swapId): Returns complete swap parameters including day count.
calculatePayments(bytes32 _swapId): Preview payments using specified day count convention.
swapExists(bytes32 _swapId): Check if swap exists before storage cleared.

PRIVATE AND INTERNAL FUNCTIONS
_calculatePayments(Swap storage swap): Internal payment calculation with day count support.
_getDayCountDivisor(DayCountConvention dayCount, uint256 duration): Returns day count divisor for calculations.

EVENTS
SwapInitiated(bytes32 swapId, address fixedPayer, address floatingPayer, uint256 notionalAmount, uint256 fixedRate, uint256 floatingRate, uint256 maturity, bytes32 hashlock, DayCountConvention dayCount): Includes day count convention.
NotionalDeposited(bytes32 swapId, address fixedPayer, address floatingPayer, uint256 notionalAmount): Emitted after successful atomic deposits.
FloatingRateUpdated(bytes32 swapId, uint256 newRate, uint256 timestamp): Per-swap rate updates before maturity.
SwapSettled(bytes32 swapId, uint256 fixedPayment, uint256 floatingPayment, uint256 netPayment, address recipient, bytes32 preimage): Settlement with storage cleanup.
SwapRefunded(bytes32 swapId, address refunder): Refund with storage cleanup.

Last updated