Skip to content

Commit

Permalink
Create BorrowerNFT (#193)
Browse files Browse the repository at this point in the history
  • Loading branch information
haydenshively authored Oct 22, 2023
1 parent c71e7b0 commit ed7ab69
Show file tree
Hide file tree
Showing 14 changed files with 1,758 additions and 159 deletions.
9 changes: 9 additions & 0 deletions periphery/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ override_spacing = true
[doc]
title = 'Aloe II'

[invariant]
runs = 128 # The number of runs for each invariant test.
depth = 64 # The number of calls executed to attempt to break invariants in one run.
fail_on_revert = true # Fails the invariant test if a revert occurs.
call_override = false # Allows overriding an unsafe external call when running invariant tests, e.g. reentrancy checks (this feature is still a WIP).
dictionary_weight = 75 # Use values collected from your contracts 75% of the time, random 25% of the time.
include_storage = true # Collect values from contract storage and add them to the dictionary.
include_push_bytes = true # Collect PUSH bytes from the contract code and add them to the dictionary.

[rpc_endpoints]
mainnet = "${RPC_URL_MAINNET}"
goerli = "${RPC_URL_GOERLI}"
Expand Down
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
Loading

0 comments on commit ed7ab69

Please sign in to comment.