Skip to content
This repository has been archived by the owner on Jan 26, 2024. It is now read-only.

Commit

Permalink
Golfed ceilDiv and LienToken (#117)
Browse files Browse the repository at this point in the history
* Fix install instructions and add markdown filetree (#116)

* Fix install instructions and add markdown filetree

* Cleaned up filetree

* implement testNewLienExceeds2XEpoch() (#105)

* implement testNewLienExceeds2XEpoch()

* lien duration check

* commitToLien now caps duration at 2 weeks

* privatevault commitolienfix

* add length cap on refinance

* moved timeToSecondEpochEnd into method

* minor changes

* implement _timeToSecondEndIfPublic

* remove isValidVault check in onlyVaults function

Co-authored-by: = <santiagogregoryl@gmail.com>

* replaced transferfrom with safertransferfrom (#111)

* replaced transferfrom with safertransferfrom

* update ierc721

Co-authored-by: Joseph Delong <joseph@delong.me>

* implement testFinalAuctionEnd() (#115)

* Refinance update (#110)

* lien duration check

* updates requested

Co-authored-by: Joseph Delong <joseph@delong.me>

* Golfed CeilDiv🏌

* Hole 9 on LienToken

* Finished up LienToken

* Fixed syntax

Co-authored-by: Joseph Delong <joseph@delong.me>
Co-authored-by: = <santiagogregoryl@gmail.com>
Co-authored-by: Andrew Redden <=>
  • Loading branch information
3 people authored Nov 21, 2022
1 parent b3d1953 commit d9351af
Show file tree
Hide file tree
Showing 13 changed files with 262 additions and 104 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ out

lcov.info


.idea

scripts/loanProofGenerator.js
36 changes: 33 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,37 @@ test
```

# Astaria Docs
```ml
src
├─ AstariaRouter.sol
├─ AstariaVaultBase.sol
├─ BeaconProxy.sol
├─ CollateralToken.sol
├─ LienToken.sol
├─ PublicVault.sol
├─ TransferProxy.sol
├─ Vault.sol
├─ VaultImplementation.sol
├─ WithdrawProxy.sol
├─ WithdrawVaultBase.sol
└─ actions
└─ UNIV3
└─ClaimFees.sol
└─ libraries
└─ Base64.sol
└─ CollateralLookup.sol
└─ security
└─ V3SecurityHook.sol
└─ strategies
└─ CollectionValidator.sol
├─ UNI_V3Validator.sol
└─ UniqueValidator.sol
└─ utils
├─ Math.sol
├─ MerkleProofLib.sol
└─ Pausable.sol
```
For more details on the Astaria protocol and its contracts, see the [docs](https://docs.astaria.xyz/docs/intro)

# Astaria Contracts Setup
Expand All @@ -42,9 +73,8 @@ So make sure you get setup with Foundry first
To install contract dependencies, run:

```sh
yarn
forge install
git submodule install
yarn
```


Expand Down Expand Up @@ -73,4 +103,4 @@ To target tests following disallowed behavior, run:

```sh
forge test --ffi --match-contract RevertTesting
```
```
63 changes: 42 additions & 21 deletions src/AstariaRouter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ contract AstariaRouter is Auth, ERC4626Router, Pausable, IAstariaRouter {
s.minInterestBPS = uint32((uint256(1e15) * 5) / (365 days));
s.minEpochLength = uint32(7 days);
s.maxEpochLength = uint32(45 days);
s.maxInterestRate = ((uint256(1e16) * 200) / (365 days)).safeCastTo88(); //63419583966; // 200% apy / second
s.maxInterestRate = ((uint256(1e16) * 200) / (365 days)).safeCastTo88();
//63419583966; // 200% apy / second
s.strategistFeeNumerator = uint32(200);
s.strategistFeeDenominator = uint32(1000);
s.buyoutFeeNumerator = uint32(100);
Expand Down Expand Up @@ -266,7 +267,8 @@ contract AstariaRouter is Auth, ERC4626Router, Pausable, IAstariaRouter {

function fileGuardian(File[] calldata file) external {
RouterStorage storage s = _loadRouterSlot();
require(address(msg.sender) == address(s.guardian)); //only the guardian can call this
require(address(msg.sender) == address(s.guardian));
//only the guardian can call this
for (uint256 i = 0; i < file.length; i++) {
FileType what = file[i].what;
bytes memory data = file[i].data;
Expand Down Expand Up @@ -323,17 +325,18 @@ contract AstariaRouter is Auth, ERC4626Router, Pausable, IAstariaRouter {
return x;
}

function validateCommitment(IAstariaRouter.Commitment calldata commitment)
external
view
returns (ILienToken.Lien memory lien)
{
return _validateCommitment(_loadRouterSlot(), commitment);
function validateCommitment(
IAstariaRouter.Commitment calldata commitment,
uint256 timeToSecondEpochEnd
) public view returns (ILienToken.Lien memory lien) {
return
_validateCommitment(_loadRouterSlot(), commitment, timeToSecondEpochEnd);
}

function _validateCommitment(
RouterStorage storage s,
IAstariaRouter.Commitment calldata commitment
IAstariaRouter.Commitment calldata commitment,
uint256 timeToSecondEpochEnd
) internal view returns (ILienToken.Lien memory lien) {
if (block.timestamp > commitment.lienRequest.strategy.deadline) {
revert InvalidCommitmentState(CommitmentState.EXPIRED);
Expand Down Expand Up @@ -371,6 +374,10 @@ contract AstariaRouter is Auth, ERC4626Router, Pausable, IAstariaRouter {
revert InvalidCommitmentState(CommitmentState.INVALID);
}

if (timeToSecondEpochEnd > 0 && details.duration > timeToSecondEpochEnd) {
details.duration = timeToSecondEpochEnd;
}

lien = ILienToken.Lien({
details: details,
strategyRoot: commitment.lienRequest.merkle.root,
Expand All @@ -382,7 +389,7 @@ contract AstariaRouter is Auth, ERC4626Router, Pausable, IAstariaRouter {

//todo fix this //return from _executeCommitment is a stack array, this needs to be a multi dimension stack to support updates to many tokens at once
function commitToLiens(IAstariaRouter.Commitment[] memory commitments)
external
public
whenNotPaused
returns (uint256[] memory lienIds, ILienToken.Stack[] memory stack)
{
Expand Down Expand Up @@ -431,7 +438,7 @@ contract AstariaRouter is Auth, ERC4626Router, Pausable, IAstariaRouter {
bool allowListEnabled,
address[] calldata allowList,
uint256 depositCap
) external whenNotPaused returns (address) {
) public whenNotPaused returns (address) {
return
_newVault(
epochLength,
Expand Down Expand Up @@ -462,7 +469,15 @@ contract AstariaRouter is Auth, ERC4626Router, Pausable, IAstariaRouter {
s.LIEN_TOKEN.createLien(
ILienToken.LienActionEncumber({
collateralId: params.tokenContract.computeId(params.tokenId),
lien: _validateCommitment(s, params),
lien: _validateCommitment({
s: s,
commitment: params,
timeToSecondEpochEnd: IPublicVault(msg.sender).supportsInterface(
type(IPublicVault).interfaceId
)
? IPublicVault(msg.sender).timeToSecondEpochEnd()
: 0
}),
amount: params.lienRequest.amount,
stack: params.lienRequest.stack,
receiver: receiver
Expand All @@ -481,7 +496,7 @@ contract AstariaRouter is Auth, ERC4626Router, Pausable, IAstariaRouter {
}

function liquidate(ILienToken.Stack[] memory stack, uint8 position)
external
public
returns (uint256 reserve, OrderParameters memory listedOrder)
{
if (!canLiquidate(stack[position])) {
Expand Down Expand Up @@ -556,25 +571,31 @@ contract AstariaRouter is Auth, ERC4626Router, Pausable, IAstariaRouter {
);
}

function isValidVault(address vault) external view returns (bool) {
/**
* @notice Returns whether a given address is that of a Vault.
* @param vault The Vault address.
* @return A boolean representing whether the address exists as a Vault.
*/
function isValidVault(address vault) public view returns (bool) {
return _loadRouterSlot().vaults[vault] != address(0);
}

function isValidRefinance(
ILienToken.Lien calldata newLien,
uint8 position,
ILienToken.Stack[] calldata stack
) external view returns (bool) {
) public view returns (bool) {
RouterStorage storage s = _loadRouterSlot();
uint256 minNewRate = uint256(stack[position].lien.details.rate) -
uint256 maxNewRate = uint256(stack[position].lien.details.rate) -
s.minInterestBPS;

return
!((newLien.details.rate < minNewRate) ||
(block.timestamp +
newLien.details.duration -
stack[position].point.end <
s.minDurationIncrease));
(newLien.details.rate < maxNewRate &&
newLien.details.duration + block.timestamp >=
stack[position].point.end) ||
(block.timestamp + newLien.details.duration - stack[position].point.end >=
s.minDurationIncrease &&
newLien.details.rate <= stack[position].lien.details.rate);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/CollateralToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ contract CollateralToken is
}
// transfer the NFT to the destination optimistically

nft.transferFrom(address(this), address(receiver), tokenId);
nft.safeTransferFrom(address(this), address(receiver), tokenId);
// invoke the call passed by the msg.sender

if (
Expand Down
Loading

0 comments on commit d9351af

Please sign in to comment.