Skip to content

Commit

Permalink
Merge pull request #147 from bancorprotocol/carbon-vortex-2.0
Browse files Browse the repository at this point in the history
vortex 2.0 - expose target and final target tokens
  • Loading branch information
ivanzhelyazkov authored Jun 5, 2024
2 parents e323291 + b6379ef commit a5f4bbe
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 5 deletions.
24 changes: 19 additions & 5 deletions contracts/vortex/CarbonVortex.sol
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,17 @@ contract CarbonVortex is ICarbonVortex, Upgradeable, ReentrancyGuardUpgradeable,
IVault vault,
IVault oldVortex,
address payable transferAddress,
Token targetToken,
Token finalTargetToken
) validAddress(transferAddress) validAddress(Token.unwrap(targetToken)) {
Token targetTokenInit,
Token finalTargetTokenInit
) validAddress(transferAddress) validAddress(Token.unwrap(targetTokenInit)) {
_carbonController = carbonController;
_vault = vault;
_oldVortex = oldVortex;

_transferAddress = transferAddress;

_targetToken = targetToken;
_finalTargetToken = finalTargetToken;
_targetToken = targetTokenInit;
_finalTargetToken = finalTargetTokenInit;
initialize();
}

Expand Down Expand Up @@ -322,6 +322,20 @@ contract CarbonVortex is ICarbonVortex, Upgradeable, ReentrancyGuardUpgradeable,
return _totalCollected;
}

/**
* @inheritdoc ICarbonVortex
*/
function targetToken() external view returns (Token) {
return _targetToken;
}

/**
* @inheritdoc ICarbonVortex
*/
function finalTargetToken() external view returns (Token) {
return _finalTargetToken;
}

/**
* @inheritdoc ICarbonVortex
*/
Expand Down
10 changes: 10 additions & 0 deletions contracts/vortex/interfaces/ICarbonVortex.sol
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,16 @@ interface ICarbonVortex is IUpgradeable {
*/
function availableTokens(Token token) external view returns (uint256);

/**
* @notice returns the target token
*/
function targetToken() external view returns (Token);

/**
* @notice returns the final target token
*/
function finalTargetToken() external view returns (Token);

/**
* @notice trades *targetToken* for *targetAmount* of *token* based on the current token price (trade by target amount)
* @notice if token == *targetToken*, trades *finalTargetToken* for amount of *targetToken* and also
Expand Down
10 changes: 10 additions & 0 deletions test/forge/CarbonVortex.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2244,6 +2244,16 @@ contract CarbonVortexTest is TestFixture {
assertEq(targetAmount, 1 ether);
}

/// @dev test should return the target token
function testShouldReturnTheTargetToken() public {
assertEq(Token.unwrap(carbonVortex.targetToken()), Token.unwrap(targetToken));
}

/// @dev test should return the final target token
function testShouldReturnTheFinalTargetToken() public {
assertEq(Token.unwrap(carbonVortex.finalTargetToken()), Token.unwrap(finalTargetToken));
}

/// @dev test should revert on expected trade input if the target amount is larger than the available balance
function testShouldRevertOnExpectedTradeInputIfTheTargetAmountIsLargerThanTheAvailableBalance() public {
vm.prank(admin);
Expand Down

0 comments on commit a5f4bbe

Please sign in to comment.