Skip to content

Commit

Permalink
Fix build, update BoostManager, disable BoostNFT
Browse files Browse the repository at this point in the history
  • Loading branch information
haydenshively committed Oct 22, 2023
1 parent 969ef1a commit dcac2a9
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 159 deletions.
7 changes: 7 additions & 0 deletions periphery/script/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import {Factory} from "aloe-ii-core/Factory.sol";
import {BorrowerLens} from "src/BorrowerLens.sol";
import {LenderLens} from "src/LenderLens.sol";
import {Router, IPermit2} from "src/Router.sol";

import {BorrowerNFT} from "src/borrower-nft/BorrowerNFT.sol";

import {BoostManager} from "src/managers/BoostManager.sol";
import {FrontendManager} from "src/managers/FrontendManager.sol";
import {SimpleManager} from "src/managers/SimpleManager.sol";
import {UniswapNFTManager, INFTManager} from "src/managers/UniswapNFTManager.sol";
Expand Down Expand Up @@ -48,6 +52,9 @@ contract DeployScript is Script {
new LenderLens{salt: TAG}();
new Router{salt: TAG}(permit2);

BorrowerNFT borrowerNft = new BorrowerNFT{salt: TAG}(factory);

new BoostManager{salt: TAG}(factory, address(borrowerNft), uniswapNft);
new FrontendManager{salt: TAG}(factory);
new SimpleManager{salt: TAG}();
new UniswapNFTManager{salt: TAG}(factory, uniswapNft);
Expand Down
91 changes: 0 additions & 91 deletions periphery/script/DeployBoost.s.sol

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ contract BoostNFT is ERC721 {
}

function createBorrower(IUniswapV3Pool pool) external {
_freeBorrowers.push(Borrower(FACTORY.createBorrower(pool, address(this))));
_freeBorrowers.push(Borrower(FACTORY.createBorrower(pool, address(this), 0)));
}

/*//////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -144,7 +144,7 @@ contract BoostNFT is ERC721 {
borrower = _freeBorrowers[count - 1];
_freeBorrowers.pop();
} else {
borrower = Borrower(FACTORY.createBorrower(pool, address(this)));
borrower = Borrower(FACTORY.createBorrower(pool, address(this), 0));
}
}
}
Expand Down
81 changes: 38 additions & 43 deletions periphery/src/boost/NFTDescriptor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,43 +11,42 @@ library NFTDescriptor {
using LibString for uint256;

struct ConstructTokenURIParams {
uint256 tokenId;
address poolAddress;
uint24 fee;
address token0;
address token1;
string symbol0;
string symbol1;
int24 tickLower;
int24 tickUpper;
int24 tickCurrent;
uint24 fee;
address poolAddress;
address borrowerAddress;
bool isGeneralized;
uint256 counter;
uint24 health;
bool hasAnte;
}

function constructTokenURI(ConstructTokenURIParams memory params) internal pure returns (string memory) {
params.symbol0 = params.symbol0.escapeJSON();
params.symbol1 = params.symbol1.escapeJSON();

string memory tokenId = params.tokenId.toString();
// Pool-specific parameters
string memory poolString = _addressToString(params.poolAddress);
string memory feeString = _feeToString(params.fee);
string memory token0 = _addressToString(params.token0);
string memory token1 = _addressToString(params.token1);
string memory feeString = _feeToString(params.fee);
string memory poolString = _addressToString(params.poolAddress);
params.symbol0 = params.symbol0.escapeJSON();
params.symbol1 = params.symbol1.escapeJSON();
// Borrower-specific parameters
string memory borrowerString = _addressToString(params.borrowerAddress);
string memory counter = params.counter.toString();

string memory name = _generateName(params, feeString);
string memory name = _generateName(params);
string memory description = _generateDescription(
tokenId,
params.symbol0,
params.symbol1,
poolString,
feeString,
token0,
token1,
feeString,
poolString,
borrowerString
params.symbol0,
params.symbol1,
borrowerString,
counter
);
string memory image = Base64.encode(bytes(_generateSVGImage(params, tokenId, token0, token1, feeString)));
string memory image = Base64.encode(bytes(_generateSVGImage(params, counter, token0, token1, feeString)));

return
string.concat(
Expand All @@ -69,33 +68,28 @@ library NFTDescriptor {
);
}

function _generateName(
ConstructTokenURIParams memory params,
string memory feeString
) private pure returns (string memory) {
return string.concat("Uniswap V3 (Aloe) - ", feeString, " - ", params.symbol0, "/", params.symbol1);
function _generateName(ConstructTokenURIParams memory params) private pure returns (string memory) {
return string.concat(params.symbol0, "/", params.symbol1, " Borrower");
}

function _generateDescription(
string memory tokenId,
string memory symbol0,
string memory symbol1,
string memory poolString,
string memory feeString,
string memory token0,
string memory token1,
string memory feeString,
string memory poolString,
string memory borrowerString
string memory symbol0,
string memory symbol1,
string memory borrowerString,
string memory counter
) private pure returns (string memory) {
return
string.concat(
"This NFT grants the owner control of an Aloe II Boosted Position in the ",
"This NFT grants its owner control of an Aloe II Borrower in the ",
symbol0,
"-",
symbol1,
" Uniswap V3 pool.\\n",
"\\nPool: ",
poolString,
"\\n\\nBorrower: ",
" market.\\n",
"\\nBorrower: ",
borrowerString,
"\\n\\n",
symbol0,
Expand All @@ -105,10 +99,13 @@ library NFTDescriptor {
symbol1,
": ",
token1,
"\\n\\nFee Tier: ",
"\\n\\nUniswap Pool: ",
poolString,
" (",
feeString,
" Fee Tier)",
"\\n\\nToken ID: ",
tokenId,
counter,
"\\n\\n",
unicode"⚠️ DISCLAIMER: Due diligence is imperative when assessing this NFT. Make sure token addresses match the expected tokens, as token symbols may be imitated."
);
Expand All @@ -128,10 +125,8 @@ library NFTDescriptor {
params.symbol0,
params.symbol1,
feeString,
params.tickLower,
params.tickUpper,
params.tickLower <= params.tickCurrent && params.tickCurrent < params.tickUpper,
params.isGeneralized,
params.health,
params.hasAnte,
_tokenToColor(params.token0, 60),
_tokenToColor(params.token1, 32),
_tokenToColor(params.token0, 80),
Expand Down
24 changes: 10 additions & 14 deletions periphery/src/boost/NFTSVG.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@ library NFTSVG {
string symbol0;
string symbol1;
string feeTier;
int24 lower;
int24 upper;
bool inRange;
bool isGeneralized;
uint24 health;
bool hasAnte;
string color0;
string color1;
string color2;
Expand All @@ -36,11 +34,11 @@ library NFTSVG {
'<rect width="350" height="475" x="30" y="30" fill="white" />',
_generateSVGHeaderText(params.symbol0, params.symbol1, params.feeTier),
'<g clip-path="url(#square330)" style="transform:translate(40px,165px)"',
params.inRange ? ">" : ' filter="url(#grayscale)">',
params.hasAnte ? ">" : ' filter="url(#grayscale)">',
_generate3X3Quilt(params.color0, "rgb(242,245,238)", params.color1, params.color2, params.color3),
_generateAnimatedText(params.token0, params.token1, params.symbol0, params.symbol1),
"</g>",
_generatePositionDataText(params.tokenId, params.lower, params.upper, params.isGeneralized),
_generatePositionDataText(params.tokenId, params.health, true),
"</g></g></svg>"
);
}
Expand Down Expand Up @@ -225,8 +223,7 @@ library NFTSVG {

function _generatePositionDataText(
string memory tokenId,
int24 tickLower,
int24 tickUpper,
uint24 health,
bool isGeneralized
) private pure returns (string memory) {
if (isGeneralized) {
Expand All @@ -242,8 +239,7 @@ library NFTSVG {
);
}

string memory tickLowerStr = int256(tickLower).toString();
string memory tickUpperStr = int256(tickUpper).toString();
string memory healthStr = uint256(health).toString();

return
string.concat(
Expand All @@ -256,17 +252,17 @@ library NFTSVG {
"</text></g>",
' <g style="transform:translate(50px, 428px)">',
'<rect width="',
uint256(7 * (bytes(tickLowerStr).length + 14)).toString(),
uint256(7 * (bytes(healthStr).length + 14)).toString(),
'px" height="26px" rx="8px" ry="8px" fill="white" />',
'<text x="12px" y="17px" font-family="\'Courier New\', monospace" font-size="12px" fill="black"><tspan fill="rgba(0,0,0,0.6)">Min Tick: </tspan>',
tickLowerStr,
healthStr,
"</text></g>",
'<g style="transform:translate(50px, 458px)">',
'<rect width="',
uint256(7 * (bytes(tickUpperStr).length + 14)).toString(),
uint256(7 * (bytes(healthStr).length + 14)).toString(),
'px" height="26px" rx="8px" ry="8px" fill="white" />',
'<text x="12px" y="17px" font-family="\'Courier New\', monospace" font-size="12px" fill="black"><tspan fill="rgba(0,0,0,0.6)">Max Tick: </tspan>',
tickUpperStr,
healthStr,
"</text></g>"
);
}
Expand Down
18 changes: 9 additions & 9 deletions periphery/src/managers/BoostManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ contract BoostManager is IManager, IUniswapV3SwapCallback {

Factory public immutable FACTORY;

address public immutable BOOST_NFT;
address public immutable BORROWER_NFT;

IUniswapNFT public immutable UNISWAP_NFT;

constructor(Factory factory, address boostNft, IUniswapNFT uniswapNft) {
constructor(Factory factory, address borrowerNft, IUniswapNFT uniswapNft) {
FACTORY = factory;
BOOST_NFT = boostNft;
BORROWER_NFT = borrowerNft;
UNISWAP_NFT = uniswapNft;
}

Expand All @@ -37,16 +37,16 @@ contract BoostManager is IManager, IUniswapV3SwapCallback {
// We cast `msg.sender` as a `Borrower`, but it could really be anything. DO NOT TRUST!
Borrower borrower = Borrower(payable(msg.sender));

// Need to check that `msg.sender` is really a borrower and that its owner is `BOOST_NFT`
// Need to check that `msg.sender` is really a borrower and that its owner is `BORROWER_NFT`
// in order to be sure that incoming `data` is in the expected format
require(FACTORY.isBorrower(msg.sender) && owner == BOOST_NFT, "Aloe: bad caller");
require(FACTORY.isBorrower(msg.sender) && owner == BORROWER_NFT, "Aloe: bad caller");

// Now `owner` is the true owner of the borrower
uint8 action;
bytes memory args;
(owner, action, args) = abi.decode(data, (address, uint8, bytes));
owner = address(bytes20(data[:20]));
// Decode remaining data
(uint8 action, bytes memory args) = abi.decode(data[20:], (uint8, bytes));

// Mint Boost NFT (import funds from Uniswap NFT)
// Add liquidity (import funds from Uniswap NFT and borrow enough for specified boost factor)
if (action == 0) {
// The ID of the Uniswap NFT to import
uint256 tokenId;
Expand Down
File renamed without changes.

0 comments on commit dcac2a9

Please sign in to comment.