Skip to content

Commit 0317036

Browse files
committed
fix: fixes after audit, hotfix updates to deployment script
1 parent 3dc3f1a commit 0317036

4 files changed

Lines changed: 99 additions & 27 deletions

File tree

script/PWN.s.sol

Lines changed: 76 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -101,56 +101,90 @@ forge script script/PWN.s.sol:Deploy --sig "deploy()" \
101101
_loadDeployedAddresses();
102102
vm.startBroadcast();
103103

104-
// __d.loan = PWNLoan(
105-
// _deploy(
106-
// PWNContractDeployerSalt.LOAN,
107-
// abi.encodePacked(
108-
// type(PWNLoan).creationCode,
109-
// abi.encode(address(__d.loanToken), address(__d.config), address(__d.categoryRegistry))
110-
// )
111-
// )
112-
// );
104+
// !!! TODO LOADING ADDRESSES FROM JSON DOES NOT WORK SOMEHOW, SO I AM JUST HARDCODING THE ADDRESSES HERE !!!
105+
106+
// __d.loan = PWNLoan(0x7f53449251EF28991C99EA25698B37BC13b173B8);
107+
__e.aave = IAaveLike(address(0x6Ae43d3271ff6888e7Fc43Fd7321a503ff738951));
108+
__d.hub = PWNHub(0x37807A2F031b3B44081F4b21500E5D70EbaDAdd5);
109+
__d.revokedNonce = PWNRevokedNonce(0x972204fF33348ee6889B2d0A3967dB67d7b08e4c);
110+
__d.utilizedCredit = PWNUtilizedCredit(0x8E6F44DEa3c11d69C63655BDEcbA25Fa986BCE9D);
111+
__d.chainlinkFeedRegistry = IChainlinkFeedRegistryLike(0x8D5e90706E52a52853dA9A14fA1c63889a412851);
112+
__e.chainlinkL2SequencerUptimeFeed = address(0x0000000000000000000000000000000000000000);
113+
__e.weth = address(0x7b79995e5f793A07Bc00c21412e50Ecae098E7f9);
114+
__d.products.installments = PWNInstallmentsProduct(0x68669e7ec29070e3dfa684cb4893282Cd4C9E608);
115+
116+
117+
__d.loanToken = PWNLOAN(0x4440C069272cC34b80C7B11bEE657D0349Ba9C23);
118+
__d.config = PWNConfig(0xd52a2898d61636bB3eEF0d145f05352FF543bdCC);
119+
__d.categoryRegistry = MultiTokenCategoryRegistry(0xbB2168d5546A94AE2DA9254e63D88F7f137B2534);
120+
121+
__d.loan = PWNLoan(
122+
_deploy(
123+
PWNContractDeployerSalt.LOAN,
124+
abi.encodePacked(
125+
type(PWNLoan).creationCode,
126+
abi.encode(
127+
address(__d.loanToken),
128+
address(__d.config),
129+
address(__d.categoryRegistry)
130+
)
131+
)
132+
)
133+
);
113134

114135
// __d.products.installments = PWNInstallmentsProduct(
115136
// _deploy(
116137
// PWNContractDeployerSalt.INSTALLMENTS_PRODUCT,
117138
// abi.encodePacked(
118139
// type(PWNInstallmentsProduct).creationCode,
119-
// abi.encode(address(__d.hub), address(__d.revokedNonce), address(__d.utilizedCredit), address(__d.chainlinkFeedRegistry), __e.chainlinkL2SequencerUptimeFeed, __e.weth)
140+
// abi.encode(
141+
// address(__d.hub),
142+
// address(__d.revokedNonce),
143+
// address(__d.utilizedCredit),
144+
// address(__d.chainlinkFeedRegistry),
145+
// __e.chainlinkL2SequencerUptimeFeed,
146+
// __e.weth
147+
// )
120148
// )
121149
// )
122150
// );
123151

124-
// !!! LOADING ADDRESSES FROM JSON DOES NOT WORK SOMEHOW, SO I AM JUST HARDCODING THE ADDRESSES HERE !!!
125-
126-
__d.loan = PWNLoan(0x7f53449251EF28991C99EA25698B37BC13b173B8);
127-
__d.products.installments = PWNInstallmentsProduct(address(0xEc22A11214567f580ef0f1eD8541c6Ff10d1880d));
128-
__e.aave = IAaveLike(address(0x6Ae43d3271ff6888e7Fc43Fd7321a503ff738951));
129-
130152
console2.log("PWNLoan:", address(__d.loan));
131-
console2.log("PWNInstallmentsProduct:", address(__d.products.installments));
153+
// console2.log("PWNInstallmentsProduct:", address(__d.products.installments));
154+
// console2.log("Aave:", address(__e.aave));
132155

133156
// address[] memory addrs = new address[](2);
134157
// addrs[0] = address(__d.loan);
135158
// addrs[1] = address(__d.products.installments);
136159

160+
address[] memory addrs = new address[](1);
161+
addrs[0] = address(__d.loan);
162+
137163
// bytes32[] memory tags = new bytes32[](2);
138164
// tags[0] = PWNHubTags.ACTIVE_LOAN;
139165
// tags[1] = PWNHubTags.LOAN_PROPOSAL;
140166

167+
bytes32[] memory tags = new bytes32[](1);
168+
tags[0] = PWNHubTags.ACTIVE_LOAN;
169+
141170
// // TODO on what contract this should be called?
142-
// console2.logBytes(abi.encodeWithSignature("setTags(address[],bytes32[],bool)", addrs, tags, true));
171+
console2.logBytes(abi.encodeWithSignature("setTags(address[],bytes32[],bool)", addrs, tags, true));
143172

144-
address[] memory feedIntermediaryDenominations = new address[](0);
173+
address[] memory feedIntermediaryDenominations = new address[](1);
174+
feedIntermediaryDenominations[0] = address(0x0000000000000000000000000000000000000348);
145175
// USDC / USD feed + ETH / USD feed
146176
// feedIntermediaryDenominations[0] = address(840); // USD representation in chainlink
147177
// LINK / ETH feed
148178
// feedIntermediaryDenominations[0] = address(0x42585eD362B3f1BCa95c640FdFf35Ef899212734);
149-
bool[] memory feedInvertFlags = new bool[](1);
179+
// EUR / ETH feed
180+
// feedIntermediaryDenominations[0] = address(0x1a81afB8146aeFfCFc5E50e8479e826E7D55b910);
181+
bool[] memory feedInvertFlags = new bool[](2);
150182
feedInvertFlags[0] = false;
183+
feedInvertFlags[1] = true;
151184
// feedInvertFlags[0] = false;
152185
// feedInvertFlags[1] = true;
153186

187+
154188
__d.crowdsourceLenderVault = PWNCrowdsourceLenderVault(
155189
_deploy(
156190
PWNContractDeployerSalt.CROWDSOURCE_LENDER_VAULT,
@@ -177,17 +211,34 @@ forge script script/PWN.s.sol:Deploy --sig "deploy()" \
177211
// expiration: block.timestamp + 10368000 // 120 days from now
178212
// })
179213
// LINK CREDIT on Sepolia
214+
// PWNCrowdsourceLenderVault.Terms({
215+
// collateralAddress: address(0x7b79995e5f793A07Bc00c21412e50Ecae098E7f9),
216+
// creditAddress: address(0xf8Fb3713D459D7C1018BD0A49D19b4C44290EBE5),
217+
// feedIntermediaryDenominations: feedIntermediaryDenominations,
218+
// feedInvertFlags: feedInvertFlags,
219+
// loanToValue: 7500, // 75%
220+
// interestAPR: 1000, // 10%
221+
// postponement: 2592000, // 30 days in seconds
222+
// duration: 63072000, // 730 days (2 years) in seconds
223+
// minCreditAmount: 500000000000000000000,
224+
// expiration: block.timestamp + 10368000 // 120 days from now
225+
// })
226+
// EURS CREDIT on Sepolia
180227
PWNCrowdsourceLenderVault.Terms({
181228
collateralAddress: address(0x7b79995e5f793A07Bc00c21412e50Ecae098E7f9),
182-
creditAddress: address(0xf8Fb3713D459D7C1018BD0A49D19b4C44290EBE5),
229+
creditAddress: address(0x6d906e526a4e2Ca02097BA9d0caA3c382F52278E),
183230
feedIntermediaryDenominations: feedIntermediaryDenominations,
184231
feedInvertFlags: feedInvertFlags,
185232
loanToValue: 7500, // 75%
186233
interestAPR: 1000, // 10%
187-
postponement: 2592000, // 30 days in seconds
188-
duration: 63072000, // 730 days (2 years) in seconds
189-
minCreditAmount: 500000000000000000000,
190-
expiration: block.timestamp + 10368000 // 120 days from now
234+
// postponement: 2592000, // 30 days in seconds
235+
postponement: 1200, // 20 minutes in seconds
236+
// duration: 63072000, // 730 days (2 years) in seconds
237+
duration: 7200, // 2 hours in seconds
238+
// minCreditAmount: 50000, // 500 EURS
239+
minCreditAmount: 10000, // 100 EURS
240+
// expiration: block.timestamp + 10368000 // 120 days from now
241+
expiration: block.timestamp + 36000 // 10 hours from now
191242
})
192243
)
193244
)

src/periphery/crowdsource/PWNCrowdsourceLenderVault.sol

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ contract PWNCrowdsourceLenderVault is ERC4626, IPWNLenderCreateHook, IPWNLenderR
9999
}
100100
collateralDecimals = decimals;
101101

102+
// TODO should we check the values here that they are correct?
103+
104+
// TODO should we check here that the getCollateralAmount on installments product contract returns
105+
// positive result (to ensure that the feeds are set up correctly)?
106+
102107
proposalHash = loanContract.makeProposalAcceptable(product, abi.encode(
103108
PWNInstallmentsProduct.Proposal({
104109
collateralAddress: _terms.collateralAddress,
@@ -194,7 +199,7 @@ contract PWNCrowdsourceLenderVault is ERC4626, IPWNLenderCreateHook, IPWNLenderR
194199
function maxRedeem(address owner) public view override returns (uint256 max) {
195200
max = balanceOf(owner);
196201
if (stage() == Stage.RUNNING) {
197-
max = Math.min(max, _convertToShares(_availableLiquidity(), Math.Rounding.Up));
202+
max = Math.min(max, _convertToShares(_availableLiquidity(), Math.Rounding.Down));
198203
}
199204
}
200205

@@ -314,6 +319,14 @@ contract PWNCrowdsourceLenderVault is ERC4626, IPWNLenderCreateHook, IPWNLenderR
314319
return IERC20(collateralAddr).balanceOf(address(this)) + additionalCollateralAssets;
315320
}
316321

322+
// TODO shall we keep this as `public`, or only as `external` since so far it's not used internally anywhere?
323+
// TODO same question for:
324+
// 1) totalAssets
325+
// 2) deposit
326+
// 3) mint
327+
// 4) withdraw
328+
// 5) redeem
329+
// 6) previewCollateralRedeem
317330
/**
318331
* @notice ERC4626-like function that allows an on-chain or off-chain user to simulate the effects
319332
* of their collateral redeemption at the current block, given current on-chain conditions.

src/periphery/lib/Chainlink.sol

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,9 @@ library Chainlink {
210210
// Note: registry reverts with "Feed not found" for no registered feed
211211

212212
(, int256 price,, uint256 updatedAt,) = feed.latestRoundData();
213-
if (price < 0) {
213+
// TODO should we adjust this to <= also in other Product contracts?
214+
// TODO should we revert on any other place if encountered price is 0 or negative, or is this okay to do just here?
215+
if (price <= 0) {
214216
revert ChainlinkFeedReturnedNegativePrice({ feed: address(feed), price: price, updatedAt: updatedAt });
215217
}
216218
if (block.timestamp - updatedAt > MAX_CHAINLINK_FEED_PRICE_AGE) {

src/periphery/product/PWNInstallmentsProduct.sol

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ contract PWNInstallmentsProduct is IPWNProduct {
219219
uint256 loanToValue
220220
) public view returns (uint256) {
221221
if (loanToValue == 0) revert LoanToValueZero();
222+
// throws if returned price from chainlink pracle is negative or zero
222223
return _chainlink.convertDenomination({
223224
amount: creditAmount,
224225
oldDenomination: creditAddress,
@@ -268,6 +269,11 @@ contract PWNInstallmentsProduct is IPWNProduct {
268269
revert DurationTooShort();
269270
}
270271

272+
// TODO should here be >= or just >
273+
if (proposal.postponement >= proposal.duration) {
274+
revert PostponementBiggerThanDuration();
275+
}
276+
271277
// Check min credit amount
272278
if (proposal.minCreditAmount == 0) {
273279
revert MinCreditAmountNotSet();

0 commit comments

Comments
 (0)