Skip to content

Commit

Permalink
add deploy/init libraries and scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
hexonaut committed Mar 15, 2024
1 parent b1cb6a2 commit de4730a
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 0 deletions.
13 changes: 13 additions & 0 deletions script/D3MDeploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,14 @@ contract D3MDeployScript is Script {
hub,
config.readAddress(".cdai")
);
} else if (poolType.eq("erc4626")) {
d3m.pool = D3MDeploy.deploy4626TypePool(
msg.sender,
admin,
ilk,
hub,
config.readAddress(".vault")
);
} else {
revert("Unknown pool type");
}
Expand Down Expand Up @@ -135,6 +143,11 @@ contract D3MDeployScript is Script {
} else {
revert("Invalid pool type for liquidity buffer plan type");
}
} else if (planType.eq("operator")) {
d3m.plan = D3MDeploy.deployOperatorPlan(
msg.sender,
admin
);
} else {
revert("Unknown plan type");
}
Expand Down
20 changes: 20 additions & 0 deletions script/D3MInit.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ import {
D3MAaveBufferPlanConfig,
D3MCompoundPoolLike,
D3MCompoundRateTargetPlanLike,
D3M4626PoolLike,
D3MOperatorPlanLike,
CDaiLike
} from "../src/deploy/D3MInit.sol";

Expand Down Expand Up @@ -119,6 +121,16 @@ contract D3MInitScript is Script {
cfg,
compoundCfg
);
} else if (poolType.eq("erc4626")) {
D3M4626PoolConfig memory erc4626Cfg = D3M4626PoolConfig({
vault: D3M4626PoolLike(d3m.pool).vault()
});
D3MInit.init4626Pool(
dss,
d3m,
cfg,
erc4626Cfg
);
} else {
revert("Unknown pool type");
}
Expand Down Expand Up @@ -165,6 +177,14 @@ contract D3MInitScript is Script {
} else {
revert("Invalid pool type for liquidity buffer plan type");
}
} else if (planType.eq("operator")) {
D3MOperatorPlanConfig memory operatorCfg = D3MOperatorPlanConfig({
operator: config.readAddress(".operator")
});
D3MInit.initOperatorPlan(
d3m,
operatorCfg
);
} else {
revert("Unknown plan type");
}
Expand Down
14 changes: 14 additions & 0 deletions script/input/1/template-morpho.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"chainlog": "0xdA0Ab1e0017DEbCd72Be8599041a2aa3bA7e740F",
"admin": "0x3300f198988e4C9C63F75dF86De36421f06af8c4",
"poolType": "erc4626",
"planType": "operator",
"ilk": "DIRECT-SPARK-MORPHO-DAI",
"existingIlk": false,
"maxLine": 500000000,
"gap": 10000000,
"ttl": 21600,
"tau": 604800,
"vault": "0xB8C7F2a4B3bF76CC04bd55Ebc259b33a67b3b36d",
"operator": "0x3300f198988e4C9C63F75dF86De36421f06af8c4"
}
24 changes: 24 additions & 0 deletions src/deploy/D3MDeploy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import { D3MAaveV2TypePool } from "../pools/D3MAaveV2TypePool.sol";
import { D3MAaveV3NoSupplyCapTypePool } from "../pools/D3MAaveV3NoSupplyCapTypePool.sol";
import { D3MCompoundV2TypeRateTargetPlan } from "../plans/D3MCompoundV2TypeRateTargetPlan.sol";
import { D3MCompoundV2TypePool } from "../pools/D3MCompoundV2TypePool.sol";
import { D3M4626TypePool } from "../pools/D3M4626TypePool.sol";
import { D3MOperatorPlan } from "../plans/D3MOperatorPlan.sol";
import { D3MOracle } from "../D3MOracle.sol";

// Deploy a D3M instance
Expand Down Expand Up @@ -96,6 +98,19 @@ library D3MDeploy {
ScriptTools.switchOwner(pool, deployer, owner);
}

function deploy4626TypePool(
address deployer,
address owner,
address ilk,
address hub,
address dai,
address vault
) internal returns (address pool) {
pool = address(new D3M4626TypePool(ilk, hub, dai, vault));

ScriptTools.switchOwner(pool, deployer, owner);
}

function deployAaveV2TypeRateTargetPlan(
address deployer,
address owner,
Expand Down Expand Up @@ -127,4 +142,13 @@ library D3MDeploy {
ScriptTools.switchOwner(plan, deployer, owner);
}

function deployOperatorPlan(
address deployer,
address owner
) internal returns (address plan) {
plan = address(new D3MOperatorPlan());

ScriptTools.switchOwner(plan, deployer, owner);
}

}
48 changes: 48 additions & 0 deletions src/deploy/D3MInit.sol
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,18 @@ interface CDaiLike {
function implementation() external view returns (address);
}

interface D3M4626PoolLike {
function hub() external view returns (address);
function dai() external view returns (address);
function ilk() external view returns (bytes32);
function vat() external view returns (address);
function vault() external view returns (address);
}

interface D3MOperatorPlanLike {
function file(bytes32, address) external;
}

interface D3MOracleLike {
function vat() external view returns (address);
function ilk() external view returns (bytes32);
Expand Down Expand Up @@ -148,6 +160,14 @@ struct D3MCompoundRateTargetPlanConfig {
address delegate;
}

struct D3M4626PoolConfig {
address vault;
}

struct D3MOperatorPlanConfig {
address operator;
}

// Init a D3M instance
library D3MInit {

Expand Down Expand Up @@ -275,6 +295,25 @@ library D3MInit {
pool.file("king", compoundCfg.king);
}

/**
* @dev Initialize a 4626 pool.
*/
function init4626Pool(
DssInstance memory dss,
D3MInstance memory d3m,
D3MCommonConfig memory cfg,
D3M4626PoolConfig memory erc4626Cfg
) internal {
D3M4626PoolLike pool = D3M4626PoolLike(d3m.pool);

// Sanity checks
require(pool.hub() == cfg.hub, "Pool hub mismatch");
require(pool.ilk() == cfg.ilk, "Pool ilk mismatch");
require(pool.vat() == address(dss.vat), "Pool vat mismatch");
require(pool.dai() == address(dss.dai), "Pool dai mismatch");
require(pool.vault() == erc4626Cfg.vault, "Pool vault mismatch");
}

function initAaveRateTargetPlan(
D3MInstance memory d3m,
D3MAaveRateTargetPlanConfig memory aaveCfg
Expand Down Expand Up @@ -323,4 +362,13 @@ library D3MInit {
plan.file("barb", compoundCfg.barb);
}

function initOperatorPlan(
D3MInstance memory d3m,
D3MOperatorPlanConfig memory operatorCfg
) internal {
D3MOperatorPlanLike plan = D3MOperatorPlanLike(d3m.plan);

plan.file("operator", operatorCfg.operator);
}

}

0 comments on commit de4730a

Please sign in to comment.