Skip to content
574 changes: 574 additions & 0 deletions packages/router/contracts/adapters/SpectraAdapter.sol

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions packages/router/contracts/adapters/interfaces/ICurvePool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,21 @@ interface ICurvePool {
function price_oracle() external view returns (uint256);

function last_price() external view returns (uint256);

/*
@dev some pools have last_prices method, example https://etherscan.io/address/0xb09fc8bbdcc8dc9d8b3775132c52fcebf1c7dbb3#readContract
*/
function last_prices() external view returns (uint256);

/*
@dev Spectra version of curve pool
*/
function exchange(
uint256 i,
uint256 j,
uint256 dx,
uint256 min_dy,
bool use_eth,
address receiver
) external returns (uint256);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity 0.8.19;

interface ISpectraErc4626Wrapper {
/// @dev Returns the address of the wrapped vault share.
function vaultShare() external view returns (address);

/// @dev Allows the owner to deposit vault shares into the wrapper.
/// @param vaultShares The amount of vault shares to deposit.
/// @param receiver The address to receive the wrapper shares.
/// @return The amount of minted wrapper shares.
function wrap(uint256 vaultShares, address receiver) external returns (uint256);

/// @dev Allows the owner to deposit vault shares into the wrapper, with support for slippage protection.
/// @param vaultShares The amount of vault shares to deposit.
/// @param receiver The address to receive the wrapper shares.
/// @param minShares The minimum allowed wrapper shares from this deposit.
/// @return The amount of minted wrapper shares.
function wrap(uint256 vaultShares, address receiver, uint256 minShares) external returns (uint256);

/// @dev Allows the owner to withdraw vault shares from the wrapper.
/// @param shares The amount of wrapper shares to redeem.
/// @param receiver The address to receive the vault shares.
/// @param owner The address of the owner of the wrapper shares.
/// @return The amount of withdrawn vault shares.
function unwrap(uint256 shares, address receiver, address owner) external returns (uint256);

/// @dev Allows the owner to withdraw vault shares from the wrapper, with support for slippage protection.
/// @param shares The amount of wrapper shares to redeem.
/// @param receiver The address to receive the vault shares.
/// @param owner The address of the owner of the wrapper shares.
/// @param minVaultShares The minimum vault shares that should be returned.
/// @return The amount of withdrawn vault shares.
function unwrap(uint256 shares, address receiver, address owner, uint256 minVaultShares) external returns (uint256);

/// @dev Allows to preview the amount of minted wrapper shares for a given amount of deposited vault shares.
/// @param vaultShares The amount of vault shares to deposit.
/// @return The amount of minted vault shares.
function previewWrap(uint256 vaultShares) external view returns (uint256);

/// @dev Allows to preview the amount of withdrawn vault shares for a given amount of redeemed wrapper shares.
/// @param shares The amount of wrapper shares to redeem.
/// @return The amount of withdrawn vault shares.
function previewUnwrap(uint256 shares) external view returns (uint256);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity 0.8.19;

interface ISpectraPrincipalToken {
/**
* @notice Returns the unix timestamp (uint256) at which the PT contract expires
* @return The unix timestamp (uint256) when PTs become redeemable
*/
function maturity() external view returns (uint256);

/**
* @notice Burns owner's shares (PTs and YTs before expiry, PTs after expiry)
* and sends IBTs to receiver
* @param shares The amount of shares to burn
* @param receiver The address that will receive the IBTs
* @param owner The owner of the shares
* @return ibts The actual amount of IBT received for burning the shares
*/
function redeemForIBT(uint256 shares, address receiver, address owner) external returns (uint256 ibts);

/**
* @notice Burns owner's shares (PTs and YTs before expiry, PTs after expiry)
* and sends IBTs to receiver
* @param shares The amount of shares to burn
* @param receiver The address that will receive the IBTs
* @param owner The owner of the shares
* @param minIbts The minimum IBTs that should be returned to user
* @return ibts The actual amount of IBT received for burning the shares
*/
function redeemForIBT(
uint256 shares,
address receiver,
address owner,
uint256 minIbts
) external returns (uint256 ibts);

/**
* @notice Burns owner's shares (before expiry : PTs and YTs) and sends IBTs to receiver
* @param ibts The amount of IBT to be received
* @param receiver The address that will receive the IBTs
* @param owner The owner of the shares (PTs and YTs)
* @return shares The actual amount of shares burnt for receiving the IBTs
*/
function withdrawIBT(uint256 ibts, address receiver, address owner) external returns (uint256 shares);

/**
* @notice Burns owner's shares (before expiry : PTs and YTs) and sends IBTs to receiver
* @param ibts The amount of IBT to be received
* @param receiver The address that will receive the IBTs
* @param owner The owner of the shares (PTs and YTs)
* @param maxShares The maximum shares allowed to be burnt
* @return shares The actual amount of shares burnt for receiving the IBTs
*/
function withdrawIBT(
uint256 ibts,
address receiver,
address owner,
uint256 maxShares
) external returns (uint256 shares);

/**
* @notice Burns owner's shares (PTs and YTs before expiry, PTs after expiry)
* and sends assets to receiver
* @param shares The amount of shares to burn
* @param receiver The address that will receive the assets
* @param owner The owner of the shares
* @return assets The actual amount of assets received for burning the shares
*/
function redeem(uint256 shares, address receiver, address owner) external returns (uint256 assets);

/**
* @notice Burns owner's shares (before expiry : PTs and YTs) and sends assets to receiver
* @param assets The amount of assets to be received
* @param receiver The address that will receive the assets
* @param owner The owner of the shares (PTs and YTs)
* @return shares The actual amount of shares burnt for receiving the assets
*/
function withdraw(uint256 assets, address receiver, address owner) external returns (uint256 shares);
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,22 @@ contract TestStableSwap2EMAOraclePool is ICurvePool {
TransferHelper.safeTransfer(j == 0 ? token0 : token1, _receiver, dy);
}

function exchange(
uint256 i,
uint256 j,
uint256 _dx,
uint256 _min_dy,
bool,
address _receiver
) external returns (uint256 dy) {
dy = get_dy(int128(uint128(i)), int128(uint128(j)), _dx);

if (dy < _min_dy) revert('dy < _min_dy');

TransferHelper.safeTransferFrom(i == 0 ? token0 : token1, msg.sender, address(this), _dx);
TransferHelper.safeTransfer(j == 0 ? token0 : token1, _receiver, dy);
}

function coins(uint256 i) external view returns (address) {
if (i == 0) {
return token0;
Expand Down Expand Up @@ -64,4 +80,8 @@ contract TestStableSwap2EMAOraclePool is ICurvePool {
function last_price() external view returns (uint256) {
return price;
}

function last_prices() external view returns (uint256) {
return price;
}
}
Loading