Address Contract Partially Verified
Address
0x3df39f74e9538414bccA0ec71abcA3B487B89a86
Balance
0 ETH
Nonce
1
Code Size
9016 bytes
Creator
0x2F1567c4...f63e at tx 0x0654671d...df0e06
Indexed Transactions
0 (1 on-chain, 1.0% indexed)
Contract Bytecode
9016 bytes
0x6080604052600436106100e0575f3560e01c80638234acf91161007e578063c290a92511610058578063c290a9251461028a578063ce31a06b146102a9578063f2fde38b146102bd578063fe6d8124146102dc576100e7565b80638234acf91461022657806389a30271146102455780638da5cb5b1461026c576100e7565b80634460d3cf116100ba5780634460d3cf1461019857806356febbb5146101b95780636fd29f4b146101e0578063720167c4146101ff576100e7565b80631308e8a5146101005780631a6bcfbb146101445780633064081214610171576100e7565b366100e757005b60405163201f3fd360e11b815260040160405180910390fd5b34801561010b575f5ffd5b5061012773085780639cc2cacd35e474e71f4d000e2405d8f681565b6040516001600160a01b0390911681526020015b60405180910390f35b34801561014f575f5ffd5b5061016361015e36600461217b565b61030f565b60405190815260200161013b565b34801561017c575f5ffd5b506101277333636d49fbefbe798e15e7f356e8dbef543cc70881565b3480156101a3575f5ffd5b506101b76101b23660046121b0565b610a28565b005b3480156101c4575f5ffd5b50610127737743e50f534a7f9f1791dde7dcd89f7783eefc3981565b3480156101eb575f5ffd5b506101636101fa36600461217b565b610ab5565b34801561020a575f5ffd5b506101277312af4529129303d7fbd2563e242c4a289052591281565b348015610231575f5ffd5b5061016361024036600461217b565b61112c565b348015610250575f5ffd5b5061012773a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4881565b348015610277575f5ffd5b505f54610127906001600160a01b031681565b348015610295575f5ffd5b506101636102a436600461217b565b6117a3565b3480156102b4575f5ffd5b506101b7611e1a565b3480156102c8575f5ffd5b506101b76102d73660046121b0565b611e59565b3480156102e7575f5ffd5b506101277f000000000000000000000000d6e2f8e57b4afb51c6fa4cbc012e1ce6aead989f81565b5f610318611eee565b835f0361033857604051631f2a200560e01b815260040160405180910390fd5b6001600160a01b03831661035f5760405163e6c4247b60e01b815260040160405180910390fd5b61037f73085780639cc2cacd35e474e71f4d000e2405d8f6333087611f56565b604051636eb1769f60e11b81523060048201527333636d49fbefbe798e15e7f356e8dbef543cc708602482015273085780639cc2cacd35e474e71f4d000e2405d8f6905f90829063dd62ed3e90604401602060405180830381865afa1580156103ea573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061040e91906121cb565b111561043c5761043c6001600160a01b0382167333636d49fbefbe798e15e7f356e8dbef543cc7085f611f97565b6104646001600160a01b0382167333636d49fbefbe798e15e7f356e8dbef543cc70887611f97565b60405173085780639cc2cacd35e474e71f4d000e2405d8f66024820152604481018690525f606482018190526080608483015260a482018190529063ed52d54c9060c40160408051601f19818403018152918152602080830180516001600160e01b031660e09590951b94909417909352805160c08101825273085780639cc2cacd35e474e71f4d000e2405d8f681528084018a90527312af4529129303d7fbd2563e242c4a289052591281830152606081018390525f608082018190528251948501835280855260a082019490945290516370a0823160e01b81523060048201529193509190737743e50f534a7f9f1791dde7dcd89f7783eefc39906370a0823190602401602060405180830381865afa158015610585573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906105a991906121cb565b60405162fa8d3760e61b81529091507333636d49fbefbe798e15e7f356e8dbef543cc70890633ea34dc0905f906105fe90869073085780639cc2cacd35e474e71f4d000e2405d8f69084903090600401612210565b5f604051808303818588803b158015610615575f5ffd5b505af1158015610627573d5f5f3e3d5ffd5b50506040516370a0823160e01b81523060048201525f9350849250737743e50f534a7f9f1791dde7dcd89f7783eefc3991506370a0823190602401602060405180830381865afa15801561067d573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906106a191906121cb565b6106ab91906122c2565b90505f7f000000000000000000000000d6e2f8e57b4afb51c6fa4cbc012e1ce6aead989f6001600160a01b031663510fe1206040518163ffffffff1660e01b8152600401602060405180830381865afa15801561070a573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061072e91906122e7565b6040516370a0823160e01b81526001600160a01b038b811660048301529192505f918316906370a0823190602401602060405180830381865afa158015610777573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061079b91906121cb565b90506107dc737743e50f534a7f9f1791dde7dcd89f7783eefc397f000000000000000000000000d6e2f8e57b4afb51c6fa4cbc012e1ce6aead989f85611f97565b60405163d0a9d91b60e01b8152600481018490526001600160a01b038b81166024830152604482018b90527f000000000000000000000000d6e2f8e57b4afb51c6fa4cbc012e1ce6aead989f169063d0a9d91b906064016020604051808303815f875af115801561084f573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061087391906121cb565b6040516370a0823160e01b81526001600160a01b038c8116600483015291995089918391908516906370a0823190602401602060405180830381865afa1580156108bf573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906108e391906121cb565b6108ed91906122c2565b1415806108f8575087155b156109155760405162ec6f7b60e31b815260040160405180910390fd5b604080518c8152602081018590529081018990526001600160a01b03808c16917f000000000000000000000000d6e2f8e57b4afb51c6fa4cbc012e1ce6aead989f9091169033907f64c74d309cbc72aefd89433f068367f35fa21b0613cb07cd6beb061dd4b97c24906060015b60405180910390a46109b26001600160a01b0388167333636d49fbefbe798e15e7f356e8dbef543cc7085f611f97565b6109f1737743e50f534a7f9f1791dde7dcd89f7783eefc397f000000000000000000000000d6e2f8e57b4afb51c6fa4cbc012e1ce6aead989f5f611f97565b50505050505050610a2160017f9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f0055565b9392505050565b610a30612016565b5f546040516370a0823160e01b8152306004820152610ab2916001600160a01b0390811691908416906370a0823190602401602060405180830381865afa158015610a7d573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610aa191906121cb565b6001600160a01b0384169190612041565b50565b5f610abe611eee565b835f03610ade57604051631f2a200560e01b815260040160405180910390fd5b6001600160a01b038316610b055760405163e6c4247b60e01b815260040160405180910390fd5b610b2573085780639cc2cacd35e474e71f4d000e2405d8f6333087611f56565b604051636eb1769f60e11b81523060048201527333636d49fbefbe798e15e7f356e8dbef543cc708602482015273085780639cc2cacd35e474e71f4d000e2405d8f6905f90829063dd62ed3e90604401602060405180830381865afa158015610b90573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610bb491906121cb565b1115610be257610be26001600160a01b0382167333636d49fbefbe798e15e7f356e8dbef543cc7085f611f97565b610c0a6001600160a01b0382167333636d49fbefbe798e15e7f356e8dbef543cc70887611f97565b60405173085780639cc2cacd35e474e71f4d000e2405d8f66024820152604481018690525f606482018190526080608483015260a482018190529063ed52d54c9060c40160408051601f19818403018152918152602080830180516001600160e01b031660e09590951b94909417909352805160c08101825273085780639cc2cacd35e474e71f4d000e2405d8f681528084018a90527312af4529129303d7fbd2563e242c4a289052591281830152606081018390525f608082018190528251948501835280855260a082019490945290516370a0823160e01b81523060048201529193509190737743e50f534a7f9f1791dde7dcd89f7783eefc39906370a0823190602401602060405180830381865afa158015610d2b573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610d4f91906121cb565b60405162fa8d3760e61b81529091507333636d49fbefbe798e15e7f356e8dbef543cc70890633ea34dc0905f90610da490869073085780639cc2cacd35e474e71f4d000e2405d8f69084903090600401612210565b5f604051808303818588803b158015610dbb575f5ffd5b505af1158015610dcd573d5f5f3e3d5ffd5b50506040516370a0823160e01b81523060048201525f9350849250737743e50f534a7f9f1791dde7dcd89f7783eefc3991506370a0823190602401602060405180830381865afa158015610e23573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610e4791906121cb565b610e5191906122c2565b90505f7f000000000000000000000000d6e2f8e57b4afb51c6fa4cbc012e1ce6aead989f6001600160a01b0316634e485cf76040518163ffffffff1660e01b8152600401602060405180830381865afa158015610eb0573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610ed491906122e7565b6040516370a0823160e01b81526001600160a01b038b811660048301529192505f918316906370a0823190602401602060405180830381865afa158015610f1d573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610f4191906121cb565b9050610f82737743e50f534a7f9f1791dde7dcd89f7783eefc397f000000000000000000000000d6e2f8e57b4afb51c6fa4cbc012e1ce6aead989f85611f97565b604051634b65df0360e11b8152600481018490526001600160a01b038b81166024830152604482018b90527f000000000000000000000000d6e2f8e57b4afb51c6fa4cbc012e1ce6aead989f16906396cbbe06906064016020604051808303815f875af1158015610ff5573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061101991906121cb565b6040516370a0823160e01b81526001600160a01b038c8116600483015291995089918391908516906370a0823190602401602060405180830381865afa158015611065573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061108991906121cb565b61109391906122c2565b14158061109e575087155b156110bb5760405162ec6f7b60e31b815260040160405180910390fd5b604080518c8152602081018590529081018990526001600160a01b03808c16917f000000000000000000000000d6e2f8e57b4afb51c6fa4cbc012e1ce6aead989f9091169033907f8464764433e48700f3f0191c8711e0256e5f0206894a5c0ff77cba1e8613537590606001610982565b5f611135611eee565b835f0361115557604051631f2a200560e01b815260040160405180910390fd5b6001600160a01b03831661117c5760405163e6c4247b60e01b815260040160405180910390fd5b61119c73a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48333087611f56565b604051636eb1769f60e11b81523060048201527333636d49fbefbe798e15e7f356e8dbef543cc708602482015273a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48905f90829063dd62ed3e90604401602060405180830381865afa158015611207573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061122b91906121cb565b1115611259576112596001600160a01b0382167333636d49fbefbe798e15e7f356e8dbef543cc7085f611f97565b6112816001600160a01b0382167333636d49fbefbe798e15e7f356e8dbef543cc70887611f97565b60405173a0b86991c6218b36c1d19d4a2e9eb0ce3606eb486024820152604481018690525f606482018190526080608483015260a482018190529063ed52d54c9060c40160408051601f19818403018152918152602080830180516001600160e01b031660e09590951b94909417909352805160c08101825273a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4881528084018a90527312af4529129303d7fbd2563e242c4a289052591281830152606081018390525f608082018190528251948501835280855260a082019490945290516370a0823160e01b81523060048201529193509190737743e50f534a7f9f1791dde7dcd89f7783eefc39906370a0823190602401602060405180830381865afa1580156113a2573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906113c691906121cb565b60405162fa8d3760e61b81529091507333636d49fbefbe798e15e7f356e8dbef543cc70890633ea34dc0905f9061141b90869073a0b86991c6218b36c1d19d4a2e9eb0ce3606eb489084903090600401612210565b5f604051808303818588803b158015611432575f5ffd5b505af1158015611444573d5f5f3e3d5ffd5b50506040516370a0823160e01b81523060048201525f9350849250737743e50f534a7f9f1791dde7dcd89f7783eefc3991506370a0823190602401602060405180830381865afa15801561149a573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906114be91906121cb565b6114c891906122c2565b90505f7f000000000000000000000000d6e2f8e57b4afb51c6fa4cbc012e1ce6aead989f6001600160a01b0316634e485cf76040518163ffffffff1660e01b8152600401602060405180830381865afa158015611527573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061154b91906122e7565b6040516370a0823160e01b81526001600160a01b038b811660048301529192505f918316906370a0823190602401602060405180830381865afa158015611594573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906115b891906121cb565b90506115f9737743e50f534a7f9f1791dde7dcd89f7783eefc397f000000000000000000000000d6e2f8e57b4afb51c6fa4cbc012e1ce6aead989f85611f97565b604051634b65df0360e11b8152600481018490526001600160a01b038b81166024830152604482018b90527f000000000000000000000000d6e2f8e57b4afb51c6fa4cbc012e1ce6aead989f16906396cbbe06906064016020604051808303815f875af115801561166c573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061169091906121cb565b6040516370a0823160e01b81526001600160a01b038c8116600483015291995089918391908516906370a0823190602401602060405180830381865afa1580156116dc573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061170091906121cb565b61170a91906122c2565b141580611715575087155b156117325760405162ec6f7b60e31b815260040160405180910390fd5b604080518c8152602081018590529081018990526001600160a01b03808c16917f000000000000000000000000d6e2f8e57b4afb51c6fa4cbc012e1ce6aead989f9091169033907fa8386ae0ba6176619dea9aec4e8a2e037080a1bdc120985ae2caf05b0f3ccac690606001610982565b5f6117ac611eee565b835f036117cc57604051631f2a200560e01b815260040160405180910390fd5b6001600160a01b0383166117f35760405163e6c4247b60e01b815260040160405180910390fd5b61181373a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48333087611f56565b604051636eb1769f60e11b81523060048201527333636d49fbefbe798e15e7f356e8dbef543cc708602482015273a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48905f90829063dd62ed3e90604401602060405180830381865afa15801561187e573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906118a291906121cb565b11156118d0576118d06001600160a01b0382167333636d49fbefbe798e15e7f356e8dbef543cc7085f611f97565b6118f86001600160a01b0382167333636d49fbefbe798e15e7f356e8dbef543cc70887611f97565b60405173a0b86991c6218b36c1d19d4a2e9eb0ce3606eb486024820152604481018690525f606482018190526080608483015260a482018190529063ed52d54c9060c40160408051601f19818403018152918152602080830180516001600160e01b031660e09590951b94909417909352805160c08101825273a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4881528084018a90527312af4529129303d7fbd2563e242c4a289052591281830152606081018390525f608082018190528251948501835280855260a082019490945290516370a0823160e01b81523060048201529193509190737743e50f534a7f9f1791dde7dcd89f7783eefc39906370a0823190602401602060405180830381865afa158015611a19573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611a3d91906121cb565b60405162fa8d3760e61b81529091507333636d49fbefbe798e15e7f356e8dbef543cc70890633ea34dc0905f90611a9290869073a0b86991c6218b36c1d19d4a2e9eb0ce3606eb489084903090600401612210565b5f604051808303818588803b158015611aa9575f5ffd5b505af1158015611abb573d5f5f3e3d5ffd5b50506040516370a0823160e01b81523060048201525f9350849250737743e50f534a7f9f1791dde7dcd89f7783eefc3991506370a0823190602401602060405180830381865afa158015611b11573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611b3591906121cb565b611b3f91906122c2565b90505f7f000000000000000000000000d6e2f8e57b4afb51c6fa4cbc012e1ce6aead989f6001600160a01b031663510fe1206040518163ffffffff1660e01b8152600401602060405180830381865afa158015611b9e573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611bc291906122e7565b6040516370a0823160e01b81526001600160a01b038b811660048301529192505f918316906370a0823190602401602060405180830381865afa158015611c0b573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611c2f91906121cb565b9050611c70737743e50f534a7f9f1791dde7dcd89f7783eefc397f000000000000000000000000d6e2f8e57b4afb51c6fa4cbc012e1ce6aead989f85611f97565b60405163d0a9d91b60e01b8152600481018490526001600160a01b038b81166024830152604482018b90527f000000000000000000000000d6e2f8e57b4afb51c6fa4cbc012e1ce6aead989f169063d0a9d91b906064016020604051808303815f875af1158015611ce3573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611d0791906121cb565b6040516370a0823160e01b81526001600160a01b038c8116600483015291995089918391908516906370a0823190602401602060405180830381865afa158015611d53573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611d7791906121cb565b611d8191906122c2565b141580611d8c575087155b15611da95760405162ec6f7b60e31b815260040160405180910390fd5b604080518c8152602081018590529081018990526001600160a01b03808c16917f000000000000000000000000d6e2f8e57b4afb51c6fa4cbc012e1ce6aead989f9091169033907f55085790b17ce00dc88697f359db6ed893a03f14006bc6f99e172cf54d4a375a90606001610982565b611e22612016565b5f80546040516001600160a01b03909116914780156108fc02929091818181858888f19350505050158015610ab2573d5f5f3e3d5ffd5b611e61612016565b6001600160a01b038116611e885760405163e6c4247b60e01b815260040160405180910390fd5b5f80546040516001600160a01b03808516939216917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e091a35f805473ffffffffffffffffffffffffffffffffffffffff19166001600160a01b0392909216919091179055565b7f9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f0054600203611f3057604051633ee5aeb560e01b815260040160405180910390fd5b60027f9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f0055565b611f6484848484600161204e565b611f9157604051635274afe760e01b81526001600160a01b03851660048201526024015b60405180910390fd5b50505050565b611fa38383835f6120bb565b61201157611fb483835f60016120bb565b611fdc57604051635274afe760e01b81526001600160a01b0384166004820152602401611f88565b611fe983838360016120bb565b61201157604051635274afe760e01b81526001600160a01b0384166004820152602401611f88565b505050565b5f546001600160a01b0316331461203f576040516282b42960e81b815260040160405180910390fd5b565b611fe9838383600161211d565b6040516323b872dd60e01b5f8181526001600160a01b038781166004528616602452604485905291602083606481808c5af1925060015f511483166120aa57838315161561209e573d5f823e3d81fd5b5f883b113d1516831692505b604052505f60605295945050505050565b60405163095ea7b360e01b5f8181526001600160a01b038616600452602485905291602083604481808b5af1925060015f51148316612111578383151615612105573d5f823e3d81fd5b5f873b113d1516831692505b60405250949350505050565b60405163a9059cbb60e01b5f8181526001600160a01b038616600452602485905291602083604481808b5af1925060015f51148316612111578383151615612105573d5f823e3d81fd5b6001600160a01b0381168114610ab2575f5ffd5b5f5f5f6060848603121561218d575f5ffd5b83359250602084013561219f81612167565b929592945050506040919091013590565b5f602082840312156121c0575f5ffd5b8135610a2181612167565b5f602082840312156121db575f5ffd5b5051919050565b5f81518084528060208401602086015e5f602082860101526020601f19601f83011685010191505092915050565b608081526001600160a01b038551166080820152602085015160a08201526001600160a01b0360408601511660c08201525f606086015160c060e084015261225c6101408401826121e2565b9050608087015161010084015260a0870151607f198483030161012085015261228582826121e2565b9250505061229e60208301866001600160a01b03169052565b8360408301526122b960608301846001600160a01b03169052565b95945050505050565b818103818111156122e157634e487b7160e01b5f52601160045260245ffd5b92915050565b5f602082840312156122f7575f5ffd5b8151610a218161216756fea26469706673582212209811ee1bc0ac50cc2b246a97135cd6bd0e48b3c1f4e707460a42462e6add537164736f6c634300081e0033
Verified Source Code Partial Match
Compiler: v0.8.30+commit.73712a01
EVM: cancun
Optimization: Yes (700 runs)
MinterUSDCZap_v2.sol 446 lines
// SPDX-License-Identifier: MIT
pragma solidity 0.8.30;
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {ReentrancyGuard} from "src/util/ReentrancyGuard.sol";
import {IMinter} from "src/interfaces/IMinter.sol";
/// @notice Interface for the diamond contract's depositToFxSave function
interface IFxUSDDiamondV2 {
struct ConvertInParams {
address tokenIn;
uint256 amount;
address target;
bytes data;
uint256 minOut;
bytes signature;
}
function depositToFxSave(
ConvertInParams memory params,
address tokenOut,
uint256 minShares,
address receiver
) external payable;
}
/// @title MinterUSDCZapV2
/// @notice One-click zapper for minting pegged or leveraged tokens with USDC or fxUSD via fxSAVE
/// @dev Enables users to mint pegged or leveraged tokens in a single transaction
/// @dev Flow: USDC/fxUSD → fxSAVE → Minter mint
/// @author Harbor Yield Protocol
contract MinterUSDCZapV2 is ReentrancyGuard {
using SafeERC20 for IERC20;
// ============ Constants ============
/// @notice USDC address (mainnet)
address public constant USDC = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48;
/// @notice fxSAVE vault address (mainnet)
address public constant FXSAVE = 0x7743e50F534a7f9F1791DdE7dCD89F7783Eefc39;
/// @notice fxUSD Diamond contract address (handles deposits to fxSAVE)
address public constant FXUSD_DIAMOND = 0x33636D49FbefBE798e15e7F356E8DBef543CC708;
/// @notice fxUSD swap router/converter address (for USDC and fxUSD deposits)
address public constant FXUSD_SWAP_ROUTER = 0x12AF4529129303D7FbD2563E242C4a2890525912;
/// @notice fxUSD token address (mainnet)
address public constant FXUSD = 0x085780639CC2cACd35E474e71f4d000e2405d8f6;
// ============ Immutables ============
/// @notice Minter contract address
address public immutable MINTER;
// ============ Configurable ============
address public owner;
// ============ Events ============
/// @notice Emitted when USDC is zapped to mint pegged tokens
/// @param user Address that initiated the zap
/// @param minter Address of the Minter contract
/// @param receiver Address that will receive the pegged tokens
/// @param usdcAmount Amount of USDC deposited
/// @param fxSaveAmount Amount of fxSAVE received
/// @param peggedOut Amount of pegged tokens minted
event USDCZappedToPegged(
address indexed user,
address indexed minter,
address indexed receiver,
uint256 usdcAmount,
uint256 fxSaveAmount,
uint256 peggedOut
);
/// @notice Emitted when USDC is zapped to mint leveraged tokens
/// @param user Address that initiated the zap
/// @param minter Address of the Minter contract
/// @param receiver Address that will receive the leveraged tokens
/// @param usdcAmount Amount of USDC deposited
/// @param fxSaveAmount Amount of fxSAVE received
/// @param leveragedOut Amount of leveraged tokens minted
event USDCZappedToLeveraged(
address indexed user,
address indexed minter,
address indexed receiver,
uint256 usdcAmount,
uint256 fxSaveAmount,
uint256 leveragedOut
);
/// @notice Emitted when fxUSD is zapped to mint pegged tokens
/// @param user Address that initiated the zap
/// @param minter Address of the Minter contract
/// @param receiver Address that will receive the pegged tokens
/// @param fxUsdAmount Amount of fxUSD deposited
/// @param fxSaveAmount Amount of fxSAVE received
/// @param peggedOut Amount of pegged tokens minted
event FXUSDZappedToPegged(
address indexed user,
address indexed minter,
address indexed receiver,
uint256 fxUsdAmount,
uint256 fxSaveAmount,
uint256 peggedOut
);
/// @notice Emitted when fxUSD is zapped to mint leveraged tokens
/// @param user Address that initiated the zap
/// @param minter Address of the Minter contract
/// @param receiver Address that will receive the leveraged tokens
/// @param fxUsdAmount Amount of fxUSD deposited
/// @param fxSaveAmount Amount of fxSAVE received
/// @param leveragedOut Amount of leveraged tokens minted
event FXUSDZappedToLeveraged(
address indexed user,
address indexed minter,
address indexed receiver,
uint256 fxUsdAmount,
uint256 fxSaveAmount,
uint256 leveragedOut
);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
// ============ Errors ============
/// @notice Thrown when zero amount is provided
error ZeroAmount();
/// @notice Thrown when contract addresses are invalid
error InvalidAddress();
/// @notice Thrown when fxSAVE address doesn't match Minter wrapped collateral token
error CollateralMismatch(address expected, address provided);
error Unauthorized();
error MintFailed();
error FunctionNotFound();
// ============ Constructor ============
/// @notice Constructor sets the Minter address
/// @param minter_ Address of the Minter contract (must accept fxSAVE as wrapped collateral)
constructor(address minter_) {
if (minter_ == address(0)) revert InvalidAddress();
// Verify that fxSAVE matches the Minter wrapped collateral token
address expectedCollateral = IMinter(minter_).WRAPPED_COLLATERAL_TOKEN();
if (FXSAVE != expectedCollateral) {
revert CollateralMismatch(expectedCollateral, FXSAVE);
}
MINTER = minter_;
owner = msg.sender;
emit OwnershipTransferred(address(0), msg.sender);
}
// ============ Modifiers ============
modifier onlyOwner() {
_checkOwner();
_;
}
function _checkOwner() internal view {
if (msg.sender != owner) revert Unauthorized();
}
// ============ External Functions ============
/// @notice Zap USDC into pegged tokens in one transaction
/// @dev Flow: USDC → fxSAVE → Minter mint pegged
/// @param usdcAmount Amount of USDC to zap
/// @param receiver Address that will receive the pegged tokens
/// @param minPeggedOut Minimum amount of pegged tokens to receive
/// @return peggedOut Amount of pegged tokens minted
function zapUsdcToPegged(
uint256 usdcAmount,
address receiver,
uint256 minPeggedOut
) external nonReentrant returns (uint256 peggedOut) {
if (usdcAmount == 0) revert ZeroAmount();
if (receiver == address(0)) revert InvalidAddress();
// 1. Pull USDC from user
IERC20(USDC).safeTransferFrom(msg.sender, address(this), usdcAmount);
// 2. USDC → fxSAVE via diamond contract
IERC20 usdcToken = IERC20(USDC);
if (usdcToken.allowance(address(this), FXUSD_DIAMOND) > 0) {
usdcToken.forceApprove(FXUSD_DIAMOND, 0);
}
usdcToken.forceApprove(FXUSD_DIAMOND, usdcAmount);
bytes memory swapData = abi.encodeWithSelector(0xed52d54c, USDC, usdcAmount, uint256(0), "");
IFxUSDDiamondV2.ConvertInParams memory params = IFxUSDDiamondV2.ConvertInParams({
tokenIn: USDC,
amount: usdcAmount,
target: FXUSD_SWAP_ROUTER,
data: swapData,
minOut: 0,
signature: ""
});
uint256 fxSaveBalanceBefore = IERC20(FXSAVE).balanceOf(address(this));
IFxUSDDiamondV2(FXUSD_DIAMOND).depositToFxSave{value: 0}(params, USDC, 0, address(this));
uint256 fxSaveAmount = IERC20(FXSAVE).balanceOf(address(this)) - fxSaveBalanceBefore;
// 3. fxSAVE → Minter mint pegged
address peggedToken = IMinter(MINTER).PEGGED_TOKEN();
uint256 peggedBalanceBefore = IERC20(peggedToken).balanceOf(receiver);
IERC20(FXSAVE).forceApprove(MINTER, fxSaveAmount);
peggedOut = IMinter(MINTER).mintPeggedToken(fxSaveAmount, receiver, minPeggedOut);
// Validate that tokens were actually minted
if (IERC20(peggedToken).balanceOf(receiver) - peggedBalanceBefore != peggedOut || peggedOut == 0) {
revert MintFailed();
}
emit USDCZappedToPegged(msg.sender, MINTER, receiver, usdcAmount, fxSaveAmount, peggedOut);
// Reset allowances to limit exposure
usdcToken.forceApprove(FXUSD_DIAMOND, 0);
IERC20(FXSAVE).forceApprove(MINTER, 0);
}
/// @notice Zap USDC into leveraged tokens in one transaction
/// @dev Flow: USDC → fxSAVE → Minter mint leveraged
/// @param usdcAmount Amount of USDC to zap
/// @param receiver Address that will receive the leveraged tokens
/// @param minLeveragedOut Minimum amount of leveraged tokens to receive
/// @return leveragedOut Amount of leveraged tokens minted
function zapUsdcToLeveraged(
uint256 usdcAmount,
address receiver,
uint256 minLeveragedOut
) external nonReentrant returns (uint256 leveragedOut) {
if (usdcAmount == 0) revert ZeroAmount();
if (receiver == address(0)) revert InvalidAddress();
// 1. Pull USDC from user
IERC20(USDC).safeTransferFrom(msg.sender, address(this), usdcAmount);
// 2. USDC → fxSAVE via diamond contract
IERC20 usdcToken = IERC20(USDC);
if (usdcToken.allowance(address(this), FXUSD_DIAMOND) > 0) {
usdcToken.forceApprove(FXUSD_DIAMOND, 0);
}
usdcToken.forceApprove(FXUSD_DIAMOND, usdcAmount);
bytes memory swapData = abi.encodeWithSelector(0xed52d54c, USDC, usdcAmount, uint256(0), "");
IFxUSDDiamondV2.ConvertInParams memory params = IFxUSDDiamondV2.ConvertInParams({
tokenIn: USDC,
amount: usdcAmount,
target: FXUSD_SWAP_ROUTER,
data: swapData,
minOut: 0,
signature: ""
});
uint256 fxSaveBalanceBefore = IERC20(FXSAVE).balanceOf(address(this));
IFxUSDDiamondV2(FXUSD_DIAMOND).depositToFxSave{value: 0}(params, USDC, 0, address(this));
uint256 fxSaveAmount = IERC20(FXSAVE).balanceOf(address(this)) - fxSaveBalanceBefore;
// 3. fxSAVE → Minter mint leveraged
address leveragedToken = IMinter(MINTER).LEVERAGED_TOKEN();
uint256 leveragedBalanceBefore = IERC20(leveragedToken).balanceOf(receiver);
IERC20(FXSAVE).forceApprove(MINTER, fxSaveAmount);
leveragedOut = IMinter(MINTER).mintLeveragedToken(fxSaveAmount, receiver, minLeveragedOut);
// Validate that tokens were actually minted
if (IERC20(leveragedToken).balanceOf(receiver) - leveragedBalanceBefore != leveragedOut || leveragedOut == 0) {
revert MintFailed();
}
emit USDCZappedToLeveraged(msg.sender, MINTER, receiver, usdcAmount, fxSaveAmount, leveragedOut);
// Reset allowances to limit exposure
usdcToken.forceApprove(FXUSD_DIAMOND, 0);
IERC20(FXSAVE).forceApprove(MINTER, 0);
}
/// @notice Zap fxUSD into pegged tokens in one transaction
/// @dev Flow: fxUSD → fxSAVE → Minter mint pegged
/// @param fxUsdAmount Amount of fxUSD to zap
/// @param receiver Address that will receive the pegged tokens
/// @param minPeggedOut Minimum amount of pegged tokens to receive
/// @return peggedOut Amount of pegged tokens minted
function zapFxUsdToPegged(
uint256 fxUsdAmount,
address receiver,
uint256 minPeggedOut
) external nonReentrant returns (uint256 peggedOut) {
if (fxUsdAmount == 0) revert ZeroAmount();
if (receiver == address(0)) revert InvalidAddress();
// 1. Pull fxUSD from user
IERC20(FXUSD).safeTransferFrom(msg.sender, address(this), fxUsdAmount);
// 2. fxUSD → fxSAVE via diamond contract
IERC20 fxUsdToken = IERC20(FXUSD);
if (fxUsdToken.allowance(address(this), FXUSD_DIAMOND) > 0) {
fxUsdToken.forceApprove(FXUSD_DIAMOND, 0);
}
fxUsdToken.forceApprove(FXUSD_DIAMOND, fxUsdAmount);
// Build swap data: fxUSD to fxSAVE (similar to USDC flow)
bytes memory swapData = abi.encodeWithSelector(0xed52d54c, FXUSD, fxUsdAmount, uint256(0), "");
IFxUSDDiamondV2.ConvertInParams memory params = IFxUSDDiamondV2.ConvertInParams({
tokenIn: FXUSD,
amount: fxUsdAmount,
target: FXUSD_SWAP_ROUTER,
data: swapData,
minOut: 0,
signature: ""
});
uint256 fxSaveBalanceBefore = IERC20(FXSAVE).balanceOf(address(this));
IFxUSDDiamondV2(FXUSD_DIAMOND).depositToFxSave{value: 0}(params, FXUSD, 0, address(this));
uint256 fxSaveAmount = IERC20(FXSAVE).balanceOf(address(this)) - fxSaveBalanceBefore;
// 3. fxSAVE → Minter mint pegged
address peggedToken = IMinter(MINTER).PEGGED_TOKEN();
uint256 peggedBalanceBefore = IERC20(peggedToken).balanceOf(receiver);
IERC20(FXSAVE).forceApprove(MINTER, fxSaveAmount);
peggedOut = IMinter(MINTER).mintPeggedToken(fxSaveAmount, receiver, minPeggedOut);
// Validate that tokens were actually minted
if (IERC20(peggedToken).balanceOf(receiver) - peggedBalanceBefore != peggedOut || peggedOut == 0) {
revert MintFailed();
}
emit FXUSDZappedToPegged(msg.sender, MINTER, receiver, fxUsdAmount, fxSaveAmount, peggedOut);
// Reset allowances to limit exposure
fxUsdToken.forceApprove(FXUSD_DIAMOND, 0);
IERC20(FXSAVE).forceApprove(MINTER, 0);
}
/// @notice Zap fxUSD into leveraged tokens in one transaction
/// @dev Flow: fxUSD → fxSAVE → Minter mint leveraged
/// @param fxUsdAmount Amount of fxUSD to zap
/// @param receiver Address that will receive the leveraged tokens
/// @param minLeveragedOut Minimum amount of leveraged tokens to receive
/// @return leveragedOut Amount of leveraged tokens minted
function zapFxUsdToLeveraged(
uint256 fxUsdAmount,
address receiver,
uint256 minLeveragedOut
) external nonReentrant returns (uint256 leveragedOut) {
if (fxUsdAmount == 0) revert ZeroAmount();
if (receiver == address(0)) revert InvalidAddress();
// 1. Pull fxUSD from user
IERC20(FXUSD).safeTransferFrom(msg.sender, address(this), fxUsdAmount);
// 2. fxUSD → fxSAVE via diamond contract
IERC20 fxUsdToken = IERC20(FXUSD);
if (fxUsdToken.allowance(address(this), FXUSD_DIAMOND) > 0) {
fxUsdToken.forceApprove(FXUSD_DIAMOND, 0);
}
fxUsdToken.forceApprove(FXUSD_DIAMOND, fxUsdAmount);
// Build swap data: fxUSD to fxSAVE (similar to USDC flow)
bytes memory swapData = abi.encodeWithSelector(0xed52d54c, FXUSD, fxUsdAmount, uint256(0), "");
IFxUSDDiamondV2.ConvertInParams memory params = IFxUSDDiamondV2.ConvertInParams({
tokenIn: FXUSD,
amount: fxUsdAmount,
target: FXUSD_SWAP_ROUTER,
data: swapData,
minOut: 0,
signature: ""
});
uint256 fxSaveBalanceBefore = IERC20(FXSAVE).balanceOf(address(this));
IFxUSDDiamondV2(FXUSD_DIAMOND).depositToFxSave{value: 0}(params, FXUSD, 0, address(this));
uint256 fxSaveAmount = IERC20(FXSAVE).balanceOf(address(this)) - fxSaveBalanceBefore;
// 3. fxSAVE → Minter mint leveraged
address leveragedToken = IMinter(MINTER).LEVERAGED_TOKEN();
uint256 leveragedBalanceBefore = IERC20(leveragedToken).balanceOf(receiver);
IERC20(FXSAVE).forceApprove(MINTER, fxSaveAmount);
leveragedOut = IMinter(MINTER).mintLeveragedToken(fxSaveAmount, receiver, minLeveragedOut);
// Validate that tokens were actually minted
if (IERC20(leveragedToken).balanceOf(receiver) - leveragedBalanceBefore != leveragedOut || leveragedOut == 0) {
revert MintFailed();
}
emit FXUSDZappedToLeveraged(msg.sender, MINTER, receiver, fxUsdAmount, fxSaveAmount, leveragedOut);
// Reset allowances to limit exposure
fxUsdToken.forceApprove(FXUSD_DIAMOND, 0);
IERC20(FXSAVE).forceApprove(MINTER, 0);
}
// ============ Owner Functions ============
function transferOwnership(address newOwner) external onlyOwner {
if (newOwner == address(0)) revert InvalidAddress();
emit OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
function rescueEth() external onlyOwner {
payable(owner).transfer(address(this).balance);
}
function rescueToken(address token) external onlyOwner {
IERC20(token).safeTransfer(owner, IERC20(token).balanceOf(address(this)));
}
// ============ Safety Functions ============
receive() external payable {
// Allow contract to receive ETH for recovery
}
fallback() external payable {
revert FunctionNotFound();
}
}
IERC20.sol 79 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (token/ERC20/IERC20.sol)
pragma solidity >=0.4.16;
/**
* @dev Interface of the ERC-20 standard as defined in the ERC.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the value of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the value of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 value) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the
* allowance mechanism. `value` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 value) external returns (bool);
}
SafeERC20.sol 280 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.5.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
import {IERC1363} from "../../../interfaces/IERC1363.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC-20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
/**
* @dev An operation with an ERC-20 token failed.
*/
error SafeERC20FailedOperation(address token);
/**
* @dev Indicates a failed `decreaseAllowance` request.
*/
error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);
/**
* @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeTransfer(IERC20 token, address to, uint256 value) internal {
if (!_safeTransfer(token, to, value, true)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
* calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
*/
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
if (!_safeTransferFrom(token, from, to, value, true)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Variant of {safeTransfer} that returns a bool instead of reverting if the operation is not successful.
*/
function trySafeTransfer(IERC20 token, address to, uint256 value) internal returns (bool) {
return _safeTransfer(token, to, value, false);
}
/**
* @dev Variant of {safeTransferFrom} that returns a bool instead of reverting if the operation is not successful.
*/
function trySafeTransferFrom(IERC20 token, address from, address to, uint256 value) internal returns (bool) {
return _safeTransferFrom(token, from, to, value, false);
}
/**
* @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*
* IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
* smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
* this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
* that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
*/
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 oldAllowance = token.allowance(address(this), spender);
forceApprove(token, spender, oldAllowance + value);
}
/**
* @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no
* value, non-reverting calls are assumed to be successful.
*
* IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
* smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
* this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
* that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
*/
function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
unchecked {
uint256 currentAllowance = token.allowance(address(this), spender);
if (currentAllowance < requestedDecrease) {
revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
}
forceApprove(token, spender, currentAllowance - requestedDecrease);
}
}
/**
* @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
* to be set to zero before setting it to a non-zero value, such as USDT.
*
* NOTE: If the token implements ERC-7674, this function will not modify any temporary allowance. This function
* only sets the "standard" allowance. Any temporary allowance will remain active, in addition to the value being
* set here.
*/
function forceApprove(IERC20 token, address spender, uint256 value) internal {
if (!_safeApprove(token, spender, value, false)) {
if (!_safeApprove(token, spender, 0, true)) revert SafeERC20FailedOperation(address(token));
if (!_safeApprove(token, spender, value, true)) revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Performs an {ERC1363} transferAndCall, with a fallback to the simple {ERC20} transfer if the target has no
* code. This can be used to implement an {ERC721}-like safe transfer that relies on {ERC1363} checks when
* targeting contracts.
*
* Reverts if the returned value is other than `true`.
*/
function transferAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
if (to.code.length == 0) {
safeTransfer(token, to, value);
} else if (!token.transferAndCall(to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Performs an {ERC1363} transferFromAndCall, with a fallback to the simple {ERC20} transferFrom if the target
* has no code. This can be used to implement an {ERC721}-like safe transfer that relies on {ERC1363} checks when
* targeting contracts.
*
* Reverts if the returned value is other than `true`.
*/
function transferFromAndCallRelaxed(
IERC1363 token,
address from,
address to,
uint256 value,
bytes memory data
) internal {
if (to.code.length == 0) {
safeTransferFrom(token, from, to, value);
} else if (!token.transferFromAndCall(from, to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Performs an {ERC1363} approveAndCall, with a fallback to the simple {ERC20} approve if the target has no
* code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* NOTE: When the recipient address (`to`) has no code (i.e. is an EOA), this function behaves as {forceApprove}.
* Oppositely, when the recipient address (`to`) has code, this function only attempts to call {ERC1363-approveAndCall}
* once without retrying, and relies on the returned value to be true.
*
* Reverts if the returned value is other than `true`.
*/
function approveAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
if (to.code.length == 0) {
forceApprove(token, to, value);
} else if (!token.approveAndCall(to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Imitates a Solidity `token.transfer(to, value)` call, relaxing the requirement on the return value: the
* return value is optional (but if data is returned, it must not be false).
*
* @param token The token targeted by the call.
* @param to The recipient of the tokens
* @param value The amount of token to transfer
* @param bubble Behavior switch if the transfer call reverts: bubble the revert reason or return a false boolean.
*/
function _safeTransfer(IERC20 token, address to, uint256 value, bool bubble) private returns (bool success) {
bytes4 selector = IERC20.transfer.selector;
assembly ("memory-safe") {
let fmp := mload(0x40)
mstore(0x00, selector)
mstore(0x04, and(to, shr(96, not(0))))
mstore(0x24, value)
success := call(gas(), token, 0, 0x00, 0x44, 0x00, 0x20)
// if call success and return is true, all is good.
// otherwise (not success or return is not true), we need to perform further checks
if iszero(and(success, eq(mload(0x00), 1))) {
// if the call was a failure and bubble is enabled, bubble the error
if and(iszero(success), bubble) {
returndatacopy(fmp, 0x00, returndatasize())
revert(fmp, returndatasize())
}
// if the return value is not true, then the call is only successful if:
// - the token address has code
// - the returndata is empty
success := and(success, and(iszero(returndatasize()), gt(extcodesize(token), 0)))
}
mstore(0x40, fmp)
}
}
/**
* @dev Imitates a Solidity `token.transferFrom(from, to, value)` call, relaxing the requirement on the return
* value: the return value is optional (but if data is returned, it must not be false).
*
* @param token The token targeted by the call.
* @param from The sender of the tokens
* @param to The recipient of the tokens
* @param value The amount of token to transfer
* @param bubble Behavior switch if the transfer call reverts: bubble the revert reason or return a false boolean.
*/
function _safeTransferFrom(
IERC20 token,
address from,
address to,
uint256 value,
bool bubble
) private returns (bool success) {
bytes4 selector = IERC20.transferFrom.selector;
assembly ("memory-safe") {
let fmp := mload(0x40)
mstore(0x00, selector)
mstore(0x04, and(from, shr(96, not(0))))
mstore(0x24, and(to, shr(96, not(0))))
mstore(0x44, value)
success := call(gas(), token, 0, 0x00, 0x64, 0x00, 0x20)
// if call success and return is true, all is good.
// otherwise (not success or return is not true), we need to perform further checks
if iszero(and(success, eq(mload(0x00), 1))) {
// if the call was a failure and bubble is enabled, bubble the error
if and(iszero(success), bubble) {
returndatacopy(fmp, 0x00, returndatasize())
revert(fmp, returndatasize())
}
// if the return value is not true, then the call is only successful if:
// - the token address has code
// - the returndata is empty
success := and(success, and(iszero(returndatasize()), gt(extcodesize(token), 0)))
}
mstore(0x40, fmp)
mstore(0x60, 0)
}
}
/**
* @dev Imitates a Solidity `token.approve(spender, value)` call, relaxing the requirement on the return value:
* the return value is optional (but if data is returned, it must not be false).
*
* @param token The token targeted by the call.
* @param spender The spender of the tokens
* @param value The amount of token to transfer
* @param bubble Behavior switch if the transfer call reverts: bubble the revert reason or return a false boolean.
*/
function _safeApprove(IERC20 token, address spender, uint256 value, bool bubble) private returns (bool success) {
bytes4 selector = IERC20.approve.selector;
assembly ("memory-safe") {
let fmp := mload(0x40)
mstore(0x00, selector)
mstore(0x04, and(spender, shr(96, not(0))))
mstore(0x24, value)
success := call(gas(), token, 0, 0x00, 0x44, 0x00, 0x20)
// if call success and return is true, all is good.
// otherwise (not success or return is not true), we need to perform further checks
if iszero(and(success, eq(mload(0x00), 1))) {
// if the call was a failure and bubble is enabled, bubble the error
if and(iszero(success), bubble) {
returndatacopy(fmp, 0x00, returndatasize())
revert(fmp, returndatasize())
}
// if the return value is not true, then the call is only successful if:
// - the token address has code
// - the returndata is empty
success := and(success, and(iszero(returndatasize()), gt(extcodesize(token), 0)))
}
mstore(0x40, fmp)
}
}
}
ReentrancyGuard.sol 73 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.5.0) (utils/ReentrancyGuard.sol)
pragma solidity 0.8.30;
import {StorageSlot} from "src/util/StorageSlot.sol";
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* IMPORTANT: This storage-based reentrancy guard is marked as deprecated in OpenZeppelin v5.x,
* but is kept here locally to support non-upgradeable contracts until the transient variant
* becomes universally available.
*/
abstract contract ReentrancyGuard {
using StorageSlot for bytes32;
// keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.ReentrancyGuard")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant _REENTRANCY_GUARD_STORAGE =
0x9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f00;
uint256 private constant _NOT_ENTERED = 1;
uint256 private constant _ENTERED = 2;
/**
* @dev Unauthorized reentrant call.
*/
error ReentrancyGuardReentrantCall();
constructor() {
_reentrancyGuardStorageSlot().getUint256Slot().value = _NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
if (_reentrancyGuardEntered()) {
revert ReentrancyGuardReentrantCall();
}
_reentrancyGuardStorageSlot().getUint256Slot().value = _ENTERED;
}
function _nonReentrantAfter() private {
_reentrancyGuardStorageSlot().getUint256Slot().value = _NOT_ENTERED;
}
/**
* @dev Returns true if the reentrancy guard is currently set to "entered".
*/
function _reentrancyGuardEntered() internal view returns (bool) {
return _reentrancyGuardStorageSlot().getUint256Slot().value == _ENTERED;
}
function _reentrancyGuardStorageSlot() internal pure returns (bytes32) {
return _REENTRANCY_GUARD_STORAGE;
}
}
IMinter.sol 497 lines
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.28 <0.9.0;
/// @title Bao Minter
/// @author rootminus0x1 based on (albeit significantly modified) Aladdin's FX system
/// @notice Provides an interface for minting and redeeming pegged and leveraged tokens, some with fees, others without.
/// <br>
/// For the fee'd fuctions equivalent "dry run" functions are available that could allow a user to know what
/// fees, discounts, etc. are expected (modulo slippage). This id designed for a user interface to use.
/// <br>
/// Configuration functions are available such as for allowing setting of:
/// <ul>
/// <li>the fee/discount/disallow configuration
/// <li>the collateral ratio that rebalancing can start
/// <li>the price oracle and rate (for wrapped) of the collateral
/// <li>the fee receiver and discount provider (reserve pool)
/// </ul>
/// Various queries are provided such as:
/// <ul>
/// <li>the net asset values of the tokens,
/// <li>leverage ratio of the leveraged tokens
/// <li>collateral ratio of the system
/// </ul>
interface IMinter {
/*//////////////////////////////////////////////////////////////
DATA STRUCTURES
//////////////////////////////////////////////////////////////*/
struct IncentiveConfig {
// note: incentive ratios have one more entry than the band bounds do
// the boundaries of the collateral ratio where the incentive ratios apply
// must be strictly increasing at the precision of 18 decimals
uint256[] collateralRatioBandUpperBounds;
// incentive ratios for the above bands , interval (-1 ether, 1 ether]
// positive = fee ratio, negative for discount, == 1 ether disallow
// any 1 ether values must be at index 0
// no negative values are allowed in the highest band
int256[] incentiveRatios;
}
struct Config {
// bonus/fees
IncentiveConfig mintPeggedIncentiveConfig;
IncentiveConfig redeemPeggedIncentiveConfig;
// leverage tokens have their own intrinsic value in that they increase in leverage the lower the collateral
// ratio, so there is a convenient intrinsic incentive to mint at low collateral ratios
IncentiveConfig mintLeveragedIncentiveConfig;
IncentiveConfig redeemLeveragedIncentiveConfig;
}
/*//////////////////////////////////////////////////////////////
EVENTS
//////////////////////////////////////////////////////////////*/
/// @notice Emitted when peggedToken is minted.
/// @param sender The address of collateral token owner.
/// @param receiver The address of receiver for peggedToken or leveragedToken.
/// @param collateralIn The amount of collateral token deposited.
/// @param peggedOut The amount of peggedToken minted.
event MintPeggedToken(address indexed sender, address indexed receiver, uint256 collateralIn, uint256 peggedOut);
/// @notice Emitted when leveragedToken is minted.
/// @param sender The address of collateral token owner.
/// @param receiver The address of receiver for peggedToken or leveragedToken.
/// @param collateralIn The amount of collateral token deposited.
/// @param leveragedOut The amount of leveragedToken minted.
event MintLeveragedToken(
address indexed sender,
address indexed receiver,
uint256 collateralIn,
uint256 leveragedOut
);
/// @notice Emitted when someone redeems a peggedToken .
/// @param sender The address of peggedToken owner.
/// @param receiver The address of receiver for collateral and leveraged token.
/// @param peggedTokenBurned The amount of peggedToken burned.
/// @param collateralOut The amount of collateral token redeemed.
/// @param leveragedOut The amount of leveraged token redeemed
event RedeemPeggedToken(
address indexed sender,
address indexed receiver,
uint256 peggedTokenBurned,
uint256 collateralOut,
uint256 leveragedOut
);
/// @notice Emitted when someone redeem collateral token with peggedToken or leveragedToken.
/// @param sender The address of peggedToken and leveragedToken owner.
/// @param receiver The address of receiver for collateral token.
/// @param leveragedTokenBurned The amount of leveragedToken burned.
/// @param collateralOut The amount of collateral token redeemed.
event RedeemLeveragedToken(
address indexed sender,
address indexed receiver,
uint256 leveragedTokenBurned,
uint256 collateralOut
);
/// @notice Emitted when there's been a slashing event and Zhenglong responds by calling reset.
event Reset(uint256 oldCollateral, uint256 newCollateral);
/// @notice Emitted whenever the config is updated.
event UpdateConfig(Config newConfig);
/// @notice Emitted when the fee receiving contract is updated.
/// @param oldFeeReceiver The address of previous fee receiving contract.
/// @param newFeeReceiver The address of the new (current) fee receiving contract.
event UpdateFeeReceiver(address indexed oldFeeReceiver, address indexed newFeeReceiver);
/// @notice Emitted when the platform contract is updated.
/// @param oldReservePool The address of previous reserve pool contract.
/// @param newReservePool The address of new (current) reserve pool contract.
event UpdateReservePool(address indexed oldReservePool, address indexed newReservePool);
/// @notice Emitted when the price oracle contract is updated.
/// @param oldPriceOracle The address of previous price oracle contract.
/// @param newPriceOracle The address of current price oracle contract.
event UpdatePriceOracle(address indexed oldPriceOracle, address indexed newPriceOracle);
/*//////////////////////////////////////////////////////////////
ERRORS
//////////////////////////////////////////////////////////////*/
/// @dev Thrown when the oracle price is invalid.
error InvalidOraclePrice();
/// @dev Thrown when the oracle price is zero.
error ZeroOraclePrice();
// @inderitdoc Token
/// @dev thrown when zero collateral is passed in or -1 is passed in and the balance is zero
error ZeroInputBalance(address token);
error RequestedBonusNotGiven(uint256 requested, uint256 available);
/// @dev Thrown when collateral is passed but minting is prevented for some other reason.
error MintZeroAmount(address mintingToken);
/// @dev Thrown when collateral is passed but minting is reduced below the miniumum requested.
error MintInsufficientAmount(address mintingToken, uint256 actual, uint256 miniumum);
/// @dev Thrown when pegged or leveraged is passed but redeeming is prevented for some other reason.
error ReturnZeroAmount(address returningToken);
/// @dev Thrown when pegged or leveraged is passed but redeeming is reduced below the miniumum requested.
error ReturnInsufficientAmount(address returningToken, uint256 actual, uint256 miniumum);
error NoRedeemableTokens(address redeemingToken);
error InsufficientRedeemableTokens(address redeemingToken, uint256 available, uint256 requested);
/// @dev thrown if a ratio doesn't make sense in some context
error InvalidRatio();
error TooManyCollateralRatioBounds(string config, uint count, uint max); // solhint-disable-line explicit-types
error InvalidCollateralRatioBoundValue(string config, uint256 value, uint index, string reason); // solhint-disable-line explicit-types
error CollateralRatioBoundValueNotIncreasing(
string config,
uint256 shouldBeLessOrEqual,
uint index, // solhint-disable-line explicit-types
uint256 shouldBeGreaterOrEqual
);
error TooManyIncentiveRatios(string config, uint count, uint max); // solhint-disable-line explicit-types
error TooFewIncentiveRatios(string config, uint count, uint min); // solhint-disable-line explicit-types
error InvalidIncentiveRatioValue(string config, uint index, int256 shouldBeMinusOnetoOne, string reason); // solhint-disable-line explicit-types
error IncentiveRatioTooPrecise(string config, int256 value);
error CollateralRatioBoundsIncentivesLengthsMismatch(string config, uint256 oneLess, uint256 oneMore);
error CollateralRatioBoundTooPrecise(string config, uint256 value);
error NoDepegBoundaryOrDisallow(string config);
/// @notice Thrown when the burn interface does not match one known by this contract
error UnsupportedBurnInterface(bytes4 interfaceId);
/*//////////////////////////////////////////////////////////////
PUBLIC READ FUNCTIONS
//////////////////////////////////////////////////////////////*/
/// @notice returns the role needed to access the zero fee functions (free*)
// solhint-disable-next-line func-name-mixedcase
function ZERO_FEE_ROLE() external view returns (uint256);
/// @notice returns the role needed to access the harvesting function
// solhint-disable-next-line func-name-mixedcase
function HARVESTER_ROLE() external view returns (uint256);
/// @notice Return the address of the collateral token
// solhint-disable-next-line func-name-mixedcase
function WRAPPED_COLLATERAL_TOKEN() external view returns (address);
/// @notice Return the address of the pegged token.
// solhint-disable-next-line func-name-mixedcase
function PEGGED_TOKEN() external view returns (address);
/// @notice Return the address of the leveraged token.
// solhint-disable-next-line func-name-mixedcase
function LEVERAGED_TOKEN() external view returns (address);
/// @notice Return the current config.
function config() external view returns (Config memory);
/// @notice Return the current collateral ratio of the system (18 decimals).
/// This is the raw ratio of (collateral value) / (pegged token balance) without any flooring.
/// When the system is depegged (ratio < 1), this function will return the actual value below 1.
///
/// Special cases:
/// - If both collateral and pegged tokens are zero: Returns 1 ether (to avoid discontinuity when first minting)
/// - If pegged tokens are zero but collateral exists: Returns a very large number (1 ether * 1 ether * 1 ether)
/// - If collateral price is zero: Returns 1 ether * 1 ether
///
/// This value is used for critical system operations like rebalancing, especially in depegged scenarios.
/// For the real market value of the pegged token, see peggedTokenPrice() instead.
function collateralRatio() external view returns (uint256);
/// @notice Return the current leveraged ratio of the leveragedToken (18 decimals).
function leverageRatio() external view returns (uint256);
/// @notice Return the price of a leveraged token in terms of the pegged token's underlying (18 decimals).
function leveragedTokenPrice() external view returns (uint256);
/// @notice Return the price of a pegged token in terms of the pegged token's underlying (18 decimals).
/// this should normally be 1 ether but if the token depegs then this number will be this token's share of the
/// collateral.
function peggedTokenPrice() external view returns (uint256);
/// @notice Returns the amount of Pegged tokens that need to be redeemed to achieve a given target collateral ratio
/// This is based on the fact that redeeming pegged tokens has a upward pressure on collateral ratio
/// If, however, there are no leveraged tokens, or their value is 0 due to a depeg, then no amount of redemption can
/// change the collateral ratio.
/// In the case of total leveraged token value being zero we return the supply minted by this Minter
/// @param targetCollateralRatio The collateral ratio that we aim to meet by the returned pegged tokens redeemed.
/// Must be greater than 1 ether
/// @return peggedForCollateral The number of pegged tokens that need to be redeemed to achieve the `targetCollateralRatio`
/// given the current collateral ratio and redeeming into collateral
/// @return peggedForLeveraged The number of pegged tokens that need to be redeemed to achieve the `targetCollateralRatio`
/// given the current collateral ratio and redeeming into leveaged tokens
function redeemPeggedForCollateralRatio(
uint256 targetCollateralRatio
) external view returns (uint256 peggedForCollateral, uint256 peggedForLeveraged);
/// @notice Returns the address of the price oracle contract
function priceOracle() external view returns (address);
/// @notice Returns the address of the reserve pool contract that provides the collateral for discounts
function reservePool() external view returns (address);
/// @notice Returns the address of the fee receiver contract
function feeReceiver() external view returns (address);
/// @notice Returns the totalAmount of pegged tokens minted, and not redeemed, by the minter
function peggedTokenBalance() external view returns (uint256);
/// @notice Returns the totalAmount of leveraged tokens minted, and not redeemed, by the minter
/// This number is the same as the totelSupply of the leveraged token
function leveragedTokenBalance() external view returns (uint256);
/// @notice Returns the totalAmount of collateral tokens received in exchange for pegged and leveraged tokens
/// (18 decimals)
function collateralTokenBalance() external view returns (uint256);
/// @notice Returns the current instantaneous incentive ratio for minting pegged tokens (18 decimals).
/// A positive number is a fee ratio; a negative number indicates a discount.
function mintPeggedTokenIncentiveRatio() external view returns (int256 incentiveRatio);
/// @notice Returns the current instantaneous incentive ratio for redeeming pegged tokens (18 decimals).
/// A positive number is a fee ratio; a negative number indicates a discount.
function redeemPeggedTokenIncentiveRatio() external view returns (int256 incentiveRatio);
/// @notice Returns the current instantaneous incentive ratio for minting leveraged tokens (18 decimals).
/// A positive number is a fee ratio; a negative number indicates a discount.
function mintLeveragedTokenIncentiveRatio() external view returns (int256 incentiveRatio);
/// @notice Returns the current instantaneous incentive ratio for redeeming leveraged tokens (18 decimals).
/// A positive number is a fee ratio; a negative number indicates a discount.
function redeemLeveragedTokenIncentiveRatio() external view returns (int256 incentiveRatio);
/// @notice Returns values that will be used if an actual `mintPeggedToken` function call is made.
/// This function is useful to give a user an indication of the actual transfers that would occur if the function
/// was to be called.
///
/// ┌──────┐ ┌────────┐ ┌──────────┐
/// │ user │ ─── collateralTaken ──► │ minter │ ─────── fee ───────► │ fee │
/// │ │ ◀════ peggedMinted ════ │ │ (only +ve, i.e. fee) │ receiver │
/// └──────┘ └────────┘ └──────────┘
/// │
/// collateral held += collateralTaken - fee
///
/// @param collateralIn The amount of wrapped collateral to be exchanged for pegged tokens.
/// @return incentiveRatio the effective incentive ratio for `collateralIn` collateral tokens. A positive number is
/// a fee ratio; a negative number indicates a discount.
/// @return fee The amount deducted from `collateralIn` as a fee.
/// @return collateralTaken The amount of collateral used in the exchange.
/// This is usually the same as `collateralIn` but at certain collateral ratio levels minting pegged tokens may be
/// disallowed by configuration.
/// @return peggedMinted The amount of pegged tokens that would be minted, given the 'collateralTaken' value and 'fee'.
/// @return price The price of collateral in terms of pegged tokens used in the calculations.
/// @return rate The conversion rate from underlying collateral to wrapped collateral.
function mintPeggedTokenDryRun(
uint256 collateralIn
)
external
view
returns (
int256 incentiveRatio,
uint256 fee,
uint256 collateralTaken,
uint256 peggedMinted,
uint256 price,
uint256 rate
);
/// @notice Returns values that will be used if an actual `redeemPeggedToken` function call is made.
/// ┌──────────────┐
/// ┌──────┐ ┌────────┐ ┌─► │ fee receiver │
/// │ user │ ════ peggedRedeemed ════▶ │ minter │ ───── fee ────┘ └──────────────┘
/// │ │ ◄── collateralReturned ── │ │ ◄── discount ─┐ ┌──────────────┐
/// └──────┘ (including any discount) └────────┘ └── │ reserve pool │
/// │ └──────────────┘
/// collateral held -= collateral value of peggedRedeemed - fee
///
/// @param peggedIn The amount of pegged token to be redeemed.
/// @return incentiveRatio the effective incentive ratio for `peggedIn` pegged tokens. A positive number is a fee
/// ratio; a negative number indicates a discount. This is the theoretic value.
/// @return fee The amount deducted in wrapped collateral from 'peggedIn' as a fee.
/// @return discount The amount in wrapped collateral added to 'collateralReturned' taken from the reserve pool.
/// This takes into account the possibility the reserve pool may be exhausted by this action.
/// @return peggedRedeemed The amount of pegged tokens that would be redeemed.
/// @return wrappedCollateralReturned The amount of collateral returned to the caller including from the reserve pool (if a discount has been configured)
/// @return price is the price of collateral in terms of pegged tokens used in the calculations.
/// @return rate The conversion rate from underlying collateral to wrapped collateral.
function redeemPeggedTokenDryRun(
uint256 peggedIn
)
external
view
returns (
int256 incentiveRatio,
uint256 fee,
uint256 discount,
uint256 peggedRedeemed,
uint256 wrappedCollateralReturned,
uint256 price,
uint256 rate
);
/// @notice Returns values that will be used if an actual `mintLeveragedToken` function call is made.
/// @param collateralIn The amount of collateral to be exchanged for leveraged tokens.
/// @return incentiveRatio the effective incentive ratio for `collateralIn` collateral tokens. A positive number is
/// a fee ratio; a negative number indicates a discount.
/// @return fee The amount deducted from 'collateralIn' as a fee.
/// @return discount The amount in wrapped collateral added to 'leverageMinted' taken from the reserve pool.
/// This takes into account the possibility the reserve pool may be exhausted by this action.
/// @return collateralUsed The amount of collateral used in the exchange.
/// @return leveragedMinted The amount of leveraged tokens that would be minted. This takes into account the discount applied.
function mintLeveragedTokenDryRun(
uint256 collateralIn
)
external
view
returns (
int256 incentiveRatio,
uint256 fee,
uint256 discount,
uint256 collateralUsed,
uint256 leveragedMinted,
uint256 price,
uint256 rate
);
/// @notice Returns values that will be used if an actual `redeemLeveragedToken` function call is made.
/// @param leveragedIn The amount of pegged token to be redeemed.
/// @return incentiveRatio the effective incentive ratio for `leveragedIn` pegged tokens. A positive number is a
/// fee ratio; a negative number indicates a discount.
/// @return fee The amount deducted from the returned collateral as a fee.
/// @return leveragedRedeemed The amount of leveraged tokens that would be redeemed.
/// This could be limited (some or all redeeming being disallowed) by configuration
/// @return collateralReturned The amount of collateral returned from the reserve pool and passed to the caller.
/// @return price is the price of collateral in terms of pegged tokens used in the calculations.
/// @return rate The conversion rate from underlying collateral to wrapped collateral.
function redeemLeveragedTokenDryRun(
uint256 leveragedIn
)
external
view
returns (
int256 incentiveRatio,
uint256 fee,
uint256 leveragedRedeemed,
uint256 collateralReturned,
uint256 price,
uint256 rate
);
/// @notice Returns value accrued, and thus harvestable, by holding wrapped collateral tokens as opposed to underlying
/// @return wrappedAmount the amount of wrapped collateral that can be distributed as rewards.
function harvestable() external view returns (uint256 wrappedAmount);
/*//////////////////////////////////////////////////////////////
PUBLIC UPDATE FUNCTIONS
//////////////////////////////////////////////////////////////*/
/// @notice Mint some pegged tokens in exchange for collateral tokens.
/// @param collateralIn The amount of wrapped value of collateral token supplied, use `uint256(-1)` to supply all
/// collateral token.
/// @param receiver The address of receiver for peggedToken.
/// @param minPeggedOut The minimum amount of peggedToken should be received. 0 means no check is made.
/// @return peggedOut The amount of peggedToken should be received.
function mintPeggedToken(
uint256 collateralIn,
address receiver,
uint256 minPeggedOut
) external returns (uint256 peggedOut);
/// @notice Redeem some pegged tokens for collateral tokens.
/// @param peggedIn the amount of peggedToken to redeem, use `uint256(-1)` to redeem all peggedToken.
/// @param receiver The address of receiver for collateral token.
/// @param minCollateralOut The minimum amount of wrapped value of collateral token should be received. 0 means no
/// check is made.
/// @return collateralOut The amount of wrapped value of collateral token should be received.
function redeemPeggedToken(
uint256 peggedIn,
address receiver,
uint256 minCollateralOut
) external returns (uint256 collateralOut);
/// @notice Mint some leveraged tokens in exchange for collateral tokens.
/// @param collateralIn The amount of wrapped value of collateral token supplied, use `uint256(-1)` to supply all
/// collateral token.
/// @param receiver The address of receiver for leveragedToken.
/// @param minLeveragedOut The minimum amount of leveragedToken should be received. 0 means no check is made.
/// @return leveragedOut The amount of leveragedToken should be received.
function mintLeveragedToken(
uint256 collateralIn,
address receiver,
uint256 minLeveragedOut
) external returns (uint256 leveragedOut);
/// @notice Redeem some leveraged tokens for collateral tokens.
/// @param leveragedIn the amount of leveragedToken to redeem, use `uint256(-1)` to redeem all leveragedToken.
/// @param receiver The address of receiver for collateral token.
/// @param minCollateralOut The minimum amount of wrapped value of collateral token should be received. 0 means no
/// check is made.
/// @return collateralOut The amount of wrapped value of collateral token should be received.
function redeemLeveragedToken(
uint256 leveragedIn,
address receiver,
uint256 minCollateralOut
) external returns (uint256 collateralOut);
/*//////////////////////////////////////////////////////////////
PROTECTED UPDATE FUNCTIONS
//////////////////////////////////////////////////////////////*/
/// @notice Resets the underlying collateral count to equal the value of the held wrapped collateral
/// This is anticipation of a slashing event for the wrapped collateral which could
/// leave the whole system with overvalued collateral which would prevent a rebalancing
function reset() external;
/// @notice Updates the config to the given config
/// @param config_ The new config
function updateConfig(Config calldata config_) external;
/// @notice Updates the fee receiver to the given address
/// @param feeReceiver_ The new fee receiver
function updateFeeReceiver(address feeReceiver_) external;
/// @notice Updates the reserve pool to the given address
/// @param reservePool_ The new reserve pool
function updateReservePool(address reservePool_) external;
/// @notice Updates the price oracle to the given address
/// @param priceOracle_ The new price oracle
function updatePriceOracle(address priceOracle_) external;
/// @notice Mint some pegged tokens in exchange for collateral tokens.
/// @param collateralIn The amount of wrapped value of collateral token supplied, use `uint256(-1)` to supply all
/// collateral token.
/// @param receiver The address of receiver for peggedToken.
/// @return peggedOut The amount of pegged tokens received.
function freeMintPeggedToken(uint256 collateralIn, address receiver) external returns (uint256 peggedOut);
/// @notice Redeem some pegged tokens for collateral tokens and leveraged tokens.
/// @param peggedForCollateral the amount of peggedToken to redeem for collateral.
/// @param peggedForLeveraged the amount of peggedToken to redeem for leveraged tokens.
/// @param receiver The address of receiver for collateral token.
/// @return wrappedCollateralOut The amount of collateral tokens received.
/// @return leveragedOut The amount of leveraged tokens received.
function freeRedeemPeggedToken(
uint256 peggedForCollateral,
uint256 peggedForLeveraged,
address receiver
) external returns (uint256 wrappedCollateralOut, uint256 leveragedOut);
/// @notice Mint some leveraged tokens in exchange for collateral tokens.
/// @param collateralIn The amount of wrapped value of collateral token supplied, use `uint256(-1)` to supply all
/// collateral token.
/// @param receiver The address of receiver for leveraged Tokens.
/// @return leveragedOut The amount of leveraged tokens received.
function freeMintLeveragedToken(uint256 collateralIn, address receiver) external returns (uint256 leveragedOut);
/// @notice Redeem some leveraged tokens for collateral tokens.
/// @param leveragedIn the amount of leveragedToken to redeem, use `uint256(-1)` to redeem all leveragedToken.
/// @param receiver The address of receiver for collateral token.
/// @return collateralOut The amount of collateral tokens received.
function freeRedeemLeveragedToken(uint256 leveragedIn, address receiver) external returns (uint256 collateralOut);
}
IERC1363.sol 86 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC1363.sol)
pragma solidity >=0.6.2;
import {IERC20} from "./IERC20.sol";
import {IERC165} from "./IERC165.sol";
/**
* @title IERC1363
* @dev Interface of the ERC-1363 standard as defined in the https://eips.ethereum.org/EIPS/eip-1363[ERC-1363].
*
* Defines an extension interface for ERC-20 tokens that supports executing code on a recipient contract
* after `transfer` or `transferFrom`, or code on a spender contract after `approve`, in a single transaction.
*/
interface IERC1363 is IERC20, IERC165 {
/*
* Note: the ERC-165 identifier for this interface is 0xb0202a11.
* 0xb0202a11 ===
* bytes4(keccak256('transferAndCall(address,uint256)')) ^
* bytes4(keccak256('transferAndCall(address,uint256,bytes)')) ^
* bytes4(keccak256('transferFromAndCall(address,address,uint256)')) ^
* bytes4(keccak256('transferFromAndCall(address,address,uint256,bytes)')) ^
* bytes4(keccak256('approveAndCall(address,uint256)')) ^
* bytes4(keccak256('approveAndCall(address,uint256,bytes)'))
*/
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferAndCall(address to, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @param data Additional data with no specified format, sent in call to `to`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferAndCall(address to, uint256 value, bytes calldata data) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param from The address which you want to send tokens from.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferFromAndCall(address from, address to, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param from The address which you want to send tokens from.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @param data Additional data with no specified format, sent in call to `to`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferFromAndCall(address from, address to, uint256 value, bytes calldata data) external returns (bool);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function approveAndCall(address spender, uint256 value) external returns (bool);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
* @param data Additional data with no specified format, sent in call to `spender`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function approveAndCall(address spender, uint256 value, bytes calldata data) external returns (bool);
}
StorageSlot.sol 127 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/StorageSlot.sol)
// This file was procedurally generated from scripts/generate/templates/StorageSlot.js.
pragma solidity 0.8.30;
// solhint-disable no-inline-assembly
/**
* @dev Library for reading and writing primitive types to specific storage slots.
*
* Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.
* This library helps with reading and writing to such slots without the need for inline assembly.
*
* The functions in this library return Slot structs that contain a `value` member that can be used to read or write.
*
* TIP: Consider using this library along with {SlotDerivation}.
*/
library StorageSlot {
struct AddressSlot {
address value;
}
struct BooleanSlot {
bool value;
}
struct Bytes32Slot {
bytes32 value;
}
struct Uint256Slot {
uint256 value;
}
struct Int256Slot {
int256 value;
}
struct StringSlot {
string value;
}
struct BytesSlot {
bytes value;
}
/**
* @dev Returns an `AddressSlot` with member `value` located at `slot`.
*/
function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns a `BooleanSlot` with member `value` located at `slot`.
*/
function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns a `Bytes32Slot` with member `value` located at `slot`.
*/
function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns a `Uint256Slot` with member `value` located at `slot`.
*/
function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns a `Int256Slot` with member `value` located at `slot`.
*/
function getInt256Slot(bytes32 slot) internal pure returns (Int256Slot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns a `StringSlot` with member `value` located at `slot`.
*/
function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns an `StringSlot` representation of the string storage pointer `store`.
*/
function getStringSlot(string storage store) internal pure returns (StringSlot storage r) {
assembly ("memory-safe") {
r.slot := store.slot
}
}
/**
* @dev Returns a `BytesSlot` with member `value` located at `slot`.
*/
function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns an `BytesSlot` representation of the bytes storage pointer `store`.
*/
function getBytesSlot(bytes storage store) internal pure returns (BytesSlot storage r) {
assembly ("memory-safe") {
r.slot := store.slot
}
}
}
IERC20.sol 6 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC20.sol)
pragma solidity >=0.4.16;
import {IERC20} from "../token/ERC20/IERC20.sol";
IERC165.sol 6 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC165.sol)
pragma solidity >=0.4.16;
import {IERC165} from "../utils/introspection/IERC165.sol";
IERC165.sol 25 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (utils/introspection/IERC165.sol)
pragma solidity >=0.4.16;
/**
* @dev Interface of the ERC-165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[ERC].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[ERC section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
Read Contract
FXSAVE 0x56febbb5 → address
FXUSD 0x1308e8a5 → address
FXUSD_DIAMOND 0x30640812 → address
FXUSD_SWAP_ROUTER 0x720167c4 → address
MINTER 0xfe6d8124 → address
USDC 0x89a30271 → address
owner 0x8da5cb5b → address
Write Contract 7 functions
These functions modify contract state and require a wallet transaction to execute.
rescueEth 0xce31a06b
No parameters
rescueToken 0x4460d3cf
address token
transferOwnership 0xf2fde38b
address newOwner
zapFxUsdToLeveraged 0x1a6bcfbb
uint256 fxUsdAmount
address receiver
uint256 minLeveragedOut
returns: uint256
zapFxUsdToPegged 0x6fd29f4b
uint256 fxUsdAmount
address receiver
uint256 minPeggedOut
returns: uint256
zapUsdcToLeveraged 0xc290a925
uint256 usdcAmount
address receiver
uint256 minLeveragedOut
returns: uint256
zapUsdcToPegged 0x8234acf9
uint256 usdcAmount
address receiver
uint256 minPeggedOut
returns: uint256
Recent Transactions
This address has 1 on-chain transactions, but only 1.0% of the chain is indexed. Transactions will appear as indexing progresses. View on Etherscan →