Skip to content

Commit

Permalink
more pendle (#37)
Browse files Browse the repository at this point in the history
* Point Algebra stuff to Camelot

* Add UniswapV3PendleWrapper
  • Loading branch information
ultrasecreth authored Apr 10, 2024
1 parent eb01f4b commit ec746d4
Show file tree
Hide file tree
Showing 9 changed files with 551 additions and 75 deletions.
37 changes: 19 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,25 @@ repayment approval.

Contracts are deployed at the same address for all supported networks.

| Contract | Lender | Address | Networks |
| ------------------------------------------------------------- | ------------------- | ------------------------------------------ | ------------------------------------------------- |
| [AaveWrapper](src/aave/AaveWrapper.sol) | Aave v3 | 0x9D4D2C08b29A2Db1c614483cd8971734BFDCC9F2 | Arbitrum One, Optimism, Polygon |
| [AaveWrapper](src/aave/AaveWrapper.sol) | Aave v3 | 0x0c86c636ed5593705b5675d370c831972C787841 | Ethereum, Gnosis |
| [AaveWrapper](src/aave/AaveWrapper.sol) | Spark | 0x8cB701df93f2Dae295aE8D7beE5Aa7e4D40CB397 | Ethereum, Gnosis |
| [BalancerWrapper](src/balancer/BalancerWrapper.sol) | Balancer v2 | 0x9E092cb431e5F1aa70e47e052773711d2Ba4917E | Ethereum, Arbitrum One, Optimism, Polygon, Gnosis |
| [BalancerWrapper](src/balancer/BalancerWrapper.sol) | Balancer v2 | 0xD534400B0555F8441c5a3e0E9e585615B54fB2F4 | Base |
| [UniswapV3Wrapper](src/uniswapV3/UniswapV3Wrapper.sol) | Uniswap v3 | 0x319300462C37AD2D4f26B584C2b67De51F51f289 | Arbitrum One, Optimism, Polygon |
| [CompoundWrapper](src/compound/CompoundWrapper.sol) | Balancer + Moonwell | 0x6207ec38da68902CC60D3760c9fe3EB64B426207 | Base |
| [CompoundWrapper](src/compound/CompoundWrapper.sol) | Balancer + Sonne | 0x6412183C579a276f467ad38468D19CC8f1F2b5cb | Optimism |
| [SiloWrapper](src/silo/SiloWrapper.sol) | Balancer + Silo | 0x0F9104Fec1a5C91e63632E215e8F5c57C8f32c77 | Arbitrum One |
| [DolomiteWrapper](src/dolomite/DolomiteWrapper.sol) | Dolomite | 0x54F1ce5E6bdf027C9a6016C9F52fC5A445b77ed6 | Arbitrum One |
| [MorphoBlueWrapper](src/morpho/MorphoBlueWrapper.sol) | MorphoBlue | 0xa0Cb4e1222d813D6e4dE79f2A7A0B7759209588F | Ethereum |
| [AlgebraWrapper](src/algebra/DolomiteWrapper.sol) | Camelot | 0x5E8820B2832aD8451f65Fa2CCe2F3Cef29016D0d | Arbitrum One |
| [AlgebraPendleWrapper](src/pendle/AlgebraPendleWrapper.sol) | Algebra + Pendle | 0xC9d66F655b7B35A2B4958bE2FB58E472736Bbc47 | Arbitrum One |
| [BalancerPendleWrapper](src/pendle/BalancerPendleWrapper.sol) | Balancer + Pendle | 0xC1Ea6a6df39D991006b39706db7C51f5A1819da7 | Arbitrum One |
| [SolidlyWrapper](src/solidly/SolidlyWrapper.sol) | Aerodrome | 0x69b6E55f00d908018E2D745c524995bc231D762b | Base |
| [SolidlyWrapper](src/solidly/SolidlyWrapper.sol) | Velodrome | 0xcF13CDdbA3aEf757c52466deC310F221e06238d6 | Optimism |
| Contract | Lender | Address | Networks |
| --------------------------------------------------------------- | ------------------- | ------------------------------------------ | ------------------------------------------------- |
| [AaveWrapper](src/aave/AaveWrapper.sol) | Aave v3 | 0x9D4D2C08b29A2Db1c614483cd8971734BFDCC9F2 | Arbitrum One, Optimism, Polygon |
| [AaveWrapper](src/aave/AaveWrapper.sol) | Aave v3 | 0x0c86c636ed5593705b5675d370c831972C787841 | Ethereum, Gnosis |
| [AaveWrapper](src/aave/AaveWrapper.sol) | Spark | 0x8cB701df93f2Dae295aE8D7beE5Aa7e4D40CB397 | Ethereum, Gnosis |
| [BalancerWrapper](src/balancer/BalancerWrapper.sol) | Balancer v2 | 0x9E092cb431e5F1aa70e47e052773711d2Ba4917E | Ethereum, Arbitrum One, Optimism, Polygon, Gnosis |
| [BalancerWrapper](src/balancer/BalancerWrapper.sol) | Balancer v2 | 0xD534400B0555F8441c5a3e0E9e585615B54fB2F4 | Base |
| [UniswapV3Wrapper](src/uniswapV3/UniswapV3Wrapper.sol) | Uniswap v3 | 0x319300462C37AD2D4f26B584C2b67De51F51f289 | Arbitrum One, Optimism, Polygon |
| [CompoundWrapper](src/compound/CompoundWrapper.sol) | Balancer + Moonwell | 0x6207ec38da68902CC60D3760c9fe3EB64B426207 | Base |
| [CompoundWrapper](src/compound/CompoundWrapper.sol) | Balancer + Sonne | 0x6412183C579a276f467ad38468D19CC8f1F2b5cb | Optimism |
| [SiloWrapper](src/silo/SiloWrapper.sol) | Balancer + Silo | 0x0F9104Fec1a5C91e63632E215e8F5c57C8f32c77 | Arbitrum One |
| [DolomiteWrapper](src/dolomite/DolomiteWrapper.sol) | Dolomite | 0x54F1ce5E6bdf027C9a6016C9F52fC5A445b77ed6 | Arbitrum One |
| [MorphoBlueWrapper](src/morpho/MorphoBlueWrapper.sol) | MorphoBlue | 0xa0Cb4e1222d813D6e4dE79f2A7A0B7759209588F | Ethereum |
| [AlgebraWrapper](src/algebra/DolomiteWrapper.sol) | Camelot | 0x5E8820B2832aD8451f65Fa2CCe2F3Cef29016D0d | Arbitrum One |
| [AlgebraPendleWrapper](src/pendle/AlgebraPendleWrapper.sol) | Camelot + Pendle | 0xC9d66F655b7B35A2B4958bE2FB58E472736Bbc47 | Arbitrum One |
| [BalancerPendleWrapper](src/pendle/BalancerPendleWrapper.sol) | Balancer + Pendle | 0xC1Ea6a6df39D991006b39706db7C51f5A1819da7 | Arbitrum One |
| [UniswapV3PendleWrapper](src/pendle/UniswapV3PendleWrapper.sol) | Uniswap v3 + Pendle | 0xa353Fd50210786F0E038ddD574A21d0CCefb3163 | Arbitrum One |
| [SolidlyWrapper](src/solidly/SolidlyWrapper.sol) | Aerodrome | 0x69b6E55f00d908018E2D745c524995bc231D762b | Base |
| [SolidlyWrapper](src/solidly/SolidlyWrapper.sol) | Velodrome | 0xcF13CDdbA3aEf757c52466deC310F221e06238d6 | Optimism |

When a contract requires constructor parameters which vary per network, these are supplied by the
[Registry](https://github.com/alcueca/registry) deployed at 0x1BFf8Eee6ECF1c8155E81dba8894CE9cF49a220c in each supported
Expand Down
63 changes: 38 additions & 25 deletions script/AlgebraDeploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,44 +22,57 @@ contract AlgebraDeploy is Script {
address usdc;
}

mapping(Network network => Fork fork) public forks;
mapping(Network network => Fork[] forks) public forks;

Registry internal registry = Registry(0xa348320114210b8F4eaF1b0795aa8F70803a93EA);

constructor() {
forks[ARBITRUM] = Fork({
name: "CamelotWrapper",
factory: IAlgebraFactory(0x1a3c9B1d2F0529D97f2afC5136Cc23e58f1FD35B),
weth: 0x82aF49447D8a07e3bd95BD0d56f35241523fBab1,
usdc: 0xaf88d065e77c8cC2239327C5EDb3A432268e5831
});
forks[ARBITRUM].push(
Fork({
name: "CamelotWrapper",
factory: IAlgebraFactory(0x1a3c9B1d2F0529D97f2afC5136Cc23e58f1FD35B),
weth: 0x82aF49447D8a07e3bd95BD0d56f35241523fBab1,
usdc: 0xaf88d065e77c8cC2239327C5EDb3A432268e5831
})
);
}

function run() public {
console2.log("Deploying as %s", msg.sender);
console2.log("Deploying as %s on %s", msg.sender, currentNetwork().toString());

Network network = currentNetwork();
Fork[] memory _forks = forks[currentNetwork()];

Fork memory fork = forks[network];
require(fork.weth != address(0), "Fork not supported");
for (uint256 i = 0; i < _forks.length; i++) {
Fork memory fork = _forks[i];

bytes memory paramsBytes = abi.encode(fork.factory, fork.weth, fork.usdc);
bytes memory paramsBytes = abi.encode(fork.factory, fork.weth, fork.usdc);

string memory key = fork.name;
string memory key = fork.name;

if (keccak256(registry.get(key)) != keccak256(paramsBytes)) {
console2.log("Updating registry");
vm.broadcast();
registry.set(key, paramsBytes);
}
if (keccak256(registry.get(key)) != keccak256(paramsBytes)) {
console2.log("Updating registry");
vm.broadcast();
registry.set(key, paramsBytes);
}

(address _factory, address _weth, address _usdc) =
abi.decode(registry.get(key), (address, address, address));
console2.log("Factory: %s", _factory);
console2.log("WETH: %s", _weth);
console2.log("USDC: %s", _usdc);

(address _factory, address _weth, address _usdc) = abi.decode(registry.get(key), (address, address, address));
console2.log("Factory: %s", _factory);
console2.log("WETH: %s", _weth);
console2.log("USDC: %s", _usdc);
if (
computeCreate2Address(SALT, hashInitCode(type(AlgebraWrapper).creationCode, abi.encode(key, registry)))
.code
.length > 0
) {
console2.log("%s: already deployed", key);
continue;
}

vm.broadcast();
AlgebraWrapper wrapper = new AlgebraWrapper{ salt: SALT }(key, registry);
console2.log("AlgebraWrapper: %s", address(wrapper));
vm.broadcast();
AlgebraWrapper wrapper = new AlgebraWrapper{ salt: SALT }(key, registry);
console2.log("%s: %s", key, address(wrapper));
}
}
}
72 changes: 55 additions & 17 deletions script/AlgebraPendleDeploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,67 @@ import { Script } from "forge-std/Script.sol";

import { console2 } from "forge-std/console2.sol";

import "./Network.sol";

import { AlgebraPendleWrapper, IAlgebraFactory, IPendleRouterV3 } from "../src/pendle/AlgebraPendleWrapper.sol";

/// @dev See the Solidity Scripting tutorial: https://book.getfoundry.sh/tutorials/solidity-scripting
contract AlgebraPendleDeploy is Script {
bytes32 public constant SALT = keccak256("ultrasecr.eth");

struct Fork {
string name;
IAlgebraFactory factory;
address weth;
address usdc;
IPendleRouterV3 pendleRouter;
}

mapping(Network network => Fork[] forks) public forks;

constructor() {
forks[ARBITRUM].push(
Fork({
name: "CamelotPendleWrapper",
factory: IAlgebraFactory(0x1a3c9B1d2F0529D97f2afC5136Cc23e58f1FD35B),
weth: 0x82aF49447D8a07e3bd95BD0d56f35241523fBab1,
usdc: 0xaf88d065e77c8cC2239327C5EDb3A432268e5831,
pendleRouter: IPendleRouterV3(0x00000000005BBB0EF59571E58418F9a4357b68A0)
})
);
}

function run() public {
console2.log("Deploying as %s", msg.sender);

IPendleRouterV3 pendleRouter = IPendleRouterV3(0x00000000005BBB0EF59571E58418F9a4357b68A0);
IAlgebraFactory factory = IAlgebraFactory(0x1a3c9B1d2F0529D97f2afC5136Cc23e58f1FD35B);
pendleRouter = IPendleRouterV3(0x00000000005BBB0EF59571E58418F9a4357b68A0);
address usdc = 0xaf88d065e77c8cC2239327C5EDb3A432268e5831;
address weth = 0x82aF49447D8a07e3bd95BD0d56f35241523fBab1;

console2.log("pendleRouter: %s", address(pendleRouter));
console2.log("factory: %s", address(factory));
console2.log("usdc: %s", usdc);
console2.log("weth: %s", weth);

vm.broadcast();
AlgebraPendleWrapper wrapper =
new AlgebraPendleWrapper{ salt: SALT }(msg.sender, factory, weth, usdc, pendleRouter);
console2.log("AlgebraPendleWrapper: %s", address(wrapper));
console2.log("Deploying as %s on %s", msg.sender, currentNetwork().toString());

Fork[] memory _forks = forks[currentNetwork()];

for (uint256 i = 0; i < _forks.length; i++) {
Fork memory fork = _forks[i];

console2.log("pendleRouter: %s", address(fork.pendleRouter));
console2.log("factory: %s", address(fork.factory));
console2.log("usdc: %s", fork.usdc);
console2.log("weth: %s", fork.weth);

if (
computeCreate2Address(
SALT,
hashInitCode(
type(AlgebraPendleWrapper).creationCode,
abi.encode(msg.sender, fork.factory, fork.weth, fork.usdc, fork.pendleRouter)
)
).code.length > 0
) {
console2.log("%s: already deployed", fork.name);
continue;
}

vm.broadcast();
AlgebraPendleWrapper wrapper = new AlgebraPendleWrapper{ salt: SALT }(
msg.sender, fork.factory, fork.weth, fork.usdc, fork.pendleRouter
);
console2.log("%s: %s", fork.name, address(wrapper));
}
}
}
15 changes: 15 additions & 0 deletions script/Network.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,18 @@ Network constant SCROLL = Network.wrap(534_352);
function currentNetwork() view returns (Network) {
return Network.wrap(block.chainid);
}

function toString(Network n) pure returns (string memory) {
if (Network.unwrap(n) == Network.unwrap(MAINNET)) return "Ethereum";
if (Network.unwrap(n) == Network.unwrap(OPTIMISM)) return "Optimism";
if (Network.unwrap(n) == Network.unwrap(GNOSIS)) return "Gnosis";
if (Network.unwrap(n) == Network.unwrap(POLYGON)) return "Polygon";
if (Network.unwrap(n) == Network.unwrap(BASE)) return "Base";
if (Network.unwrap(n) == Network.unwrap(ARBITRUM)) return "Arbitrum-One";
if (Network.unwrap(n) == Network.unwrap(BSC)) return "Binance Smart Chain";
if (Network.unwrap(n) == Network.unwrap(AVALANCHE)) return "Avalanche C-Chain";
if (Network.unwrap(n) == Network.unwrap(SCROLL)) return "Scroll";
revert("Unknown network");
}

using { toString } for Network global;
30 changes: 30 additions & 0 deletions script/UniswapV3PendleDeploy.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.19 <=0.9.0;

import { Script } from "forge-std/Script.sol";

import { console2 } from "forge-std/console2.sol";

import "./Network.sol";

import { UniswapV3PendleWrapper, IPendleRouterV3 } from "../src/pendle/UniswapV3PendleWrapper.sol";

/// @dev See the Solidity Scripting tutorial: https://book.getfoundry.sh/tutorials/solidity-scripting
contract UniswapV3PendleDeploy is Script {
bytes32 public constant SALT = keccak256("ultrasecr.eth");

mapping(Network network => mapping(bytes32 token => address)) public tokens;

address internal factory = 0x1F98431c8aD98523631AE4a59f267346ea31F984;
address internal weth = 0x82aF49447D8a07e3bd95BD0d56f35241523fBab1;
IPendleRouterV3 internal pendleRouter = IPendleRouterV3(0x00000000005BBB0EF59571E58418F9a4357b68A0);

function run() public {
console2.log("Deploying as %s on %s", msg.sender, currentNetwork().toString());

vm.broadcast();
UniswapV3PendleWrapper uniswapV3Wrapper =
new UniswapV3PendleWrapper{ salt: SALT }(msg.sender, factory, weth, pendleRouter);
console2.log("UniswapV3PendleWrapper deployed at: %s", address(uniswapV3Wrapper));
}
}
Loading

0 comments on commit ec746d4

Please sign in to comment.