Skip to content

Commit

Permalink
rename nst -> usds
Browse files Browse the repository at this point in the history
  • Loading branch information
hexonaut committed Aug 27, 2024
1 parent 2897ef2 commit 1e9a37e
Show file tree
Hide file tree
Showing 9 changed files with 170 additions and 170 deletions.
2 changes: 1 addition & 1 deletion lib/nst
Submodule nst updated from 56e2dd to eb1994
6 changes: 3 additions & 3 deletions script/D3MDeploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,13 @@ contract D3MDeployScript is Script {
address(dss.dai),
config.readAddress(".lendingPool")
);
} else if (poolType.eq("aave-v3-nst-no-supply-cap")) {
d3m.pool = D3MDeploy.deployAaveV3NSTNoSupplyCapTypePool(
} else if (poolType.eq("aave-v3-usds-no-supply-cap")) {
d3m.pool = D3MDeploy.deployAaveV3USDSNoSupplyCapTypePool(
msg.sender,
admin,
ilk,
hub,
config.readAddress(".nstJoin"),
config.readAddress(".usdsJoin"),
address(dss.daiJoin),
config.readAddress(".lendingPool")
);
Expand Down
20 changes: 10 additions & 10 deletions script/D3MInit.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ import {
D3MInstance,
D3MCommonConfig,
D3MAavePoolConfig,
D3MAaveNSTPoolConfig,
D3MAaveUSDSPoolConfig,
D3MCompoundPoolConfig,
D3MAaveRateTargetPlanConfig,
D3MCompoundRateTargetPlanConfig,
D3MAavePoolLike,
D3MAaveNSTPoolLike,
D3MAaveUSDSPoolLike,
D3MAaveRateTargetPlanLike,
D3MAaveBufferPlanLike,
D3MAaveBufferPlanConfig,
Expand Down Expand Up @@ -112,16 +112,16 @@ contract D3MInitScript is Script {
cfg,
aaveCfg
);
} else if (poolType.eq("aave-v3-nst-no-supply-cap")) {
D3MAaveNSTPoolConfig memory aaveCfg = D3MAaveNSTPoolConfig({
} else if (poolType.eq("aave-v3-usds-no-supply-cap")) {
D3MAaveUSDSPoolConfig memory aaveCfg = D3MAaveUSDSPoolConfig({
king: config.readAddress(".king"),
anst: D3MAaveNSTPoolLike(d3m.pool).anst(),
nstJoin: D3MAaveNSTPoolLike(d3m.pool).nstJoin(),
nst: D3MAaveNSTPoolLike(d3m.pool).nst(),
stableDebt: D3MAaveNSTPoolLike(d3m.pool).stableDebt(),
variableDebt: D3MAaveNSTPoolLike(d3m.pool).variableDebt()
ausds: D3MAaveUSDSPoolLike(d3m.pool).ausds(),
usdsJoin: D3MAaveUSDSPoolLike(d3m.pool).usdsJoin(),
usds: D3MAaveUSDSPoolLike(d3m.pool).usds(),
stableDebt: D3MAaveUSDSPoolLike(d3m.pool).stableDebt(),
variableDebt: D3MAaveUSDSPoolLike(d3m.pool).variableDebt()
});
D3MInit.initAaveNSTPool(
D3MInit.initAaveUSDSPool(
dss,
d3m,
cfg,
Expand Down
4 changes: 2 additions & 2 deletions script/input/1/template-aave-v3-lido.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"chainlog": "0xdA0Ab1e0017DEbCd72Be8599041a2aa3bA7e740F",
"admin": "0xBE8E3e3618f7474F8cB1d074A26afFef007E98FB",
"poolType": "aave-v3-nst-no-supply-cap",
"poolType": "aave-v3-usds-no-supply-cap",
"planType": "operator",
"ilk": "DIRECT-SPARK-AAVE-NST",
"ilk": "DIRECT-SPARK-AAVE-USDS",
"existingIlk": false,
"maxLine": 100000000,
"gap": 100000000,
Expand Down
8 changes: 4 additions & 4 deletions src/deploy/D3MDeploy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { D3MAaveV2TypeRateTargetPlan } from "../plans/D3MAaveV2TypeRateTargetPla
import { D3MAaveTypeBufferPlan } from "../plans/D3MAaveTypeBufferPlan.sol";
import { D3MAaveV2TypePool } from "../pools/D3MAaveV2TypePool.sol";
import { D3MAaveV3NoSupplyCapTypePool } from "../pools/D3MAaveV3NoSupplyCapTypePool.sol";
import { D3MAaveV3NSTNoSupplyCapTypePool } from "../pools/D3MAaveV3NSTNoSupplyCapTypePool.sol";
import { D3MAaveV3USDSNoSupplyCapTypePool } from "../pools/D3MAaveV3USDSNoSupplyCapTypePool.sol";
import { D3MCompoundV2TypeRateTargetPlan } from "../plans/D3MCompoundV2TypeRateTargetPlan.sol";
import { D3MCompoundV2TypePool } from "../pools/D3MCompoundV2TypePool.sol";
import { D3M4626TypePool } from "../pools/D3M4626TypePool.sol";
Expand Down Expand Up @@ -87,16 +87,16 @@ library D3MDeploy {
ScriptTools.switchOwner(pool, deployer, owner);
}

function deployAaveV3NSTNoSupplyCapTypePool(
function deployAaveV3USDSNoSupplyCapTypePool(
address deployer,
address owner,
bytes32 ilk,
address hub,
address nstJoin,
address usdsJoin,
address daiJoin,
address lendingPool
) internal returns (address pool) {
pool = address(new D3MAaveV3NSTNoSupplyCapTypePool(ilk, hub, nstJoin, daiJoin, lendingPool));
pool = address(new D3MAaveV3USDSNoSupplyCapTypePool(ilk, hub, usdsJoin, daiJoin, lendingPool));

ScriptTools.switchOwner(pool, deployer, owner);
}
Expand Down
28 changes: 14 additions & 14 deletions src/deploy/D3MInit.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ interface D3MAavePoolLike {
function variableDebt() external view returns (address);
}

interface D3MAaveNSTPoolLike {
interface D3MAaveUSDSPoolLike {
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 file(bytes32, address) external;
function anst() external view returns (address);
function nstJoin() external view returns (address);
function nst() external view returns (address);
function ausds() external view returns (address);
function usdsJoin() external view returns (address);
function usds() external view returns (address);
function daiJoin() external view returns (address);
function stableDebt() external view returns (address);
function variableDebt() external view returns (address);
Expand Down Expand Up @@ -146,11 +146,11 @@ struct D3MAavePoolConfig {
address variableDebt;
}

struct D3MAaveNSTPoolConfig {
struct D3MAaveUSDSPoolConfig {
address king;
address anst;
address nstJoin;
address nst;
address ausds;
address usdsJoin;
address usds;
address stableDebt;
address variableDebt;
}
Expand Down Expand Up @@ -298,23 +298,23 @@ library D3MInit {
pool.file("king", aaveCfg.king);
}

function initAaveNSTPool(
function initAaveUSDSPool(
DssInstance memory dss,
D3MInstance memory d3m,
D3MCommonConfig memory cfg,
D3MAaveNSTPoolConfig memory aaveCfg
D3MAaveUSDSPoolConfig memory aaveCfg
) internal {
D3MAaveNSTPoolLike pool = D3MAaveNSTPoolLike(d3m.pool);
D3MAaveUSDSPoolLike pool = D3MAaveUSDSPoolLike(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.nstJoin() == aaveCfg.nstJoin, "Pool nstJoin mismatch");
require(pool.nst() == aaveCfg.nst, "Pool nst mismatch");
require(pool.usdsJoin() == aaveCfg.usdsJoin, "Pool usdsJoin mismatch");
require(pool.usds() == aaveCfg.usds, "Pool usds mismatch");
require(pool.daiJoin() == address(dss.daiJoin), "Pool daiJoin mismatch");
require(pool.dai() == address(dss.dai), "Pool dai mismatch");
require(pool.anst() == aaveCfg.anst, "Pool anst mismatch");
require(pool.ausds() == aaveCfg.ausds, "Pool ausds mismatch");
require(pool.stableDebt() == aaveCfg.stableDebt, "Pool stableDebt mismatch");
require(pool.variableDebt() == aaveCfg.variableDebt, "Pool variableDebt mismatch");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,12 @@ interface RewardsClaimerLike {

interface JoinLike {
function dai() external view returns (address);
function nst() external view returns (address);
function usds() external view returns (address);
function join(address, uint256) external;
function exit(address, uint256) external;
}

contract D3MAaveV3NSTNoSupplyCapTypePool is ID3MPool {
contract D3MAaveV3USDSNoSupplyCapTypePool is ID3MPool {

mapping (address => uint256) public wards;
address public hub;
Expand All @@ -112,9 +112,9 @@ contract D3MAaveV3NSTNoSupplyCapTypePool is ID3MPool {
PoolLike public immutable pool;
ATokenLike public immutable stableDebt;
ATokenLike public immutable variableDebt;
ATokenLike public immutable anst;
JoinLike public immutable nstJoin;
TokenLike public immutable nst; // Asset
ATokenLike public immutable ausds;
JoinLike public immutable usdsJoin;
TokenLike public immutable usds; // Asset
JoinLike public immutable daiJoin;
TokenLike public immutable dai;

Expand All @@ -124,33 +124,33 @@ contract D3MAaveV3NSTNoSupplyCapTypePool is ID3MPool {
event File(bytes32 indexed what, address data);
event Collect(address indexed king, address indexed gift, uint256 amt);

constructor(bytes32 ilk_, address hub_, address nstJoin_, address daiJoin_, address pool_) {
constructor(bytes32 ilk_, address hub_, address usdsJoin_, address daiJoin_, address pool_) {
ilk = ilk_;
nstJoin = JoinLike(nstJoin_);
nst = TokenLike(nstJoin.nst());
usdsJoin = JoinLike(usdsJoin_);
usds = TokenLike(usdsJoin.usds());
daiJoin = JoinLike(daiJoin_);
dai = TokenLike(daiJoin.dai());
pool = PoolLike(pool_);

// Fetch the reserve data from Aave
PoolLike.ReserveData memory data = pool.getReserveData(address(nst));
require(data.aTokenAddress != address(0), "D3MAaveV3NoSupplyCapTypePool/invalid-anst");
PoolLike.ReserveData memory data = pool.getReserveData(address(usds));
require(data.aTokenAddress != address(0), "D3MAaveV3NoSupplyCapTypePool/invalid-ausds");
require(data.stableDebtTokenAddress != address(0), "D3MAaveV3NoSupplyCapTypePool/invalid-stableDebt");
require(data.variableDebtTokenAddress != address(0), "D3MAaveV3NoSupplyCapTypePool/invalid-variableDebt");

anst = ATokenLike(data.aTokenAddress);
ausds = ATokenLike(data.aTokenAddress);
stableDebt = ATokenLike(data.stableDebtTokenAddress);
variableDebt = ATokenLike(data.variableDebtTokenAddress);

hub = hub_;
vat = VatLike(D3mHubLike(hub_).vat());
vat.hope(hub_);

nst.approve(pool_, type(uint256).max);
usds.approve(pool_, type(uint256).max);
dai.approve(daiJoin_, type(uint256).max);
vat.hope(daiJoin_);
nst.approve(nstJoin_, type(uint256).max);
vat.hope(nstJoin_);
usds.approve(usdsJoin_, type(uint256).max);
vat.hope(usdsJoin_);

wards[msg.sender] = 1;
emit Rely(msg.sender);
Expand Down Expand Up @@ -196,76 +196,76 @@ contract D3MAaveV3NSTNoSupplyCapTypePool is ID3MPool {
emit File(what, data);
}

// Deposits NST to Aave in exchange for anst which is received by this contract
// Deposits USDS to Aave in exchange for ausds which is received by this contract
// Aave: https://docs.aave.com/developers/core-contracts/pool#supply
function deposit(uint256 wad) external override onlyHub {
daiJoin.join(address(this), wad);
nstJoin.exit(address(this), wad);
usdsJoin.exit(address(this), wad);

uint256 scaledPrev = anst.scaledBalanceOf(address(this));
uint256 scaledPrev = ausds.scaledBalanceOf(address(this));

pool.supply(address(nst), wad, address(this), 0);
pool.supply(address(usds), wad, address(this), 0);

// Verify the correct amount of anst shows up
uint256 interestIndex = pool.getReserveNormalizedIncome(address(nst));
// Verify the correct amount of ausds shows up
uint256 interestIndex = pool.getReserveNormalizedIncome(address(usds));
uint256 scaledAmount = _rdiv(wad, interestIndex);
require(anst.scaledBalanceOf(address(this)) >= (scaledPrev + scaledAmount), "D3MAaveV3NoSupplyCapTypePool/incorrect-anst-balance-received");
require(ausds.scaledBalanceOf(address(this)) >= (scaledPrev + scaledAmount), "D3MAaveV3NoSupplyCapTypePool/incorrect-ausds-balance-received");
}

// Withdraws NST from Aave in exchange for anst
// Withdraws USDS from Aave in exchange for ausds
// Aave: https://docs.aave.com/developers/core-contracts/pool#withdraw
function withdraw(uint256 wad) external override onlyHub {
uint256 prevNst = nst.balanceOf(address(this));
uint256 prevNst = usds.balanceOf(address(this));

pool.withdraw(address(nst), wad, address(this));
pool.withdraw(address(usds), wad, address(this));

require(nst.balanceOf(address(this)) == prevNst + wad, "D3MAaveV3NoSupplyCapTypePool/incorrect-nst-balance-received");
require(usds.balanceOf(address(this)) == prevNst + wad, "D3MAaveV3NoSupplyCapTypePool/incorrect-usds-balance-received");

nstJoin.join(address(this), wad);
usdsJoin.join(address(this), wad);
daiJoin.exit(msg.sender, wad);
}

function exit(address dst, uint256 wad) external override onlyHub {
uint256 exited_ = exited;
exited = exited_ + wad;
uint256 amt = wad * assetBalance() / (D3mHubLike(hub).end().Art(ilk) - exited_);
require(anst.transfer(dst, amt), "D3MAaveV3NoSupplyCapTypePool/transfer-failed");
require(ausds.transfer(dst, amt), "D3MAaveV3NoSupplyCapTypePool/transfer-failed");
}

function quit(address dst) external override auth {
require(vat.live() == 1, "D3MAaveV3NoSupplyCapTypePool/no-quit-during-shutdown");
require(anst.transfer(dst, anst.balanceOf(address(this))), "D3MAaveV3NoSupplyCapTypePool/transfer-failed");
require(ausds.transfer(dst, ausds.balanceOf(address(this))), "D3MAaveV3NoSupplyCapTypePool/transfer-failed");
}

function preDebtChange() external override {}

function postDebtChange() external override {}

// --- Balance of the underlying asset (NST)
// --- Balance of the underlying asset (USDS)
function assetBalance() public view override returns (uint256) {
return anst.balanceOf(address(this));
return ausds.balanceOf(address(this));
}

function maxDeposit() external pure override returns (uint256) {
return type(uint256).max;
}

function maxWithdraw() external view override returns (uint256) {
return _min(nst.balanceOf(address(anst)), assetBalance());
return _min(usds.balanceOf(address(ausds)), assetBalance());
}

function redeemable() external view override returns (address) {
return address(anst);
return address(ausds);
}

// --- Collect any rewards ---
function collect(address gift) external returns (uint256 amt) {
require(king != address(0), "D3MAaveV3NoSupplyCapTypePool/king-not-set");

address[] memory assets = new address[](1);
assets[0] = address(anst);
assets[0] = address(ausds);

RewardsClaimerLike rewardsClaimer = RewardsClaimerLike(anst.getIncentivesController());
RewardsClaimerLike rewardsClaimer = RewardsClaimerLike(ausds.getIncentivesController());

amt = rewardsClaimer.claimRewards(assets, type(uint256).max, king, gift);
emit Collect(king, gift, amt);
Expand Down
Loading

0 comments on commit 1e9a37e

Please sign in to comment.