Skip to content
This repository has been archived by the owner on Sep 27, 2022. It is now read-only.

Implement ERC721MarginLoan #218

Merged
merged 5 commits into from
Apr 21, 2018
Merged

Implement ERC721MarginLoan #218

merged 5 commits into from
Apr 21, 2018

Conversation

BrendanChou
Copy link
Contributor

No description provided.

@@ -54,7 +54,7 @@ contract ERC721MarginPosition is
address margin
)
public
ERC721Token("dYdX Margin Positions", "DYDX-M")
ERC721Token("dYdX Margin Positions", "DYDX-MarginPosition")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is too long for a symbol. I liked the old one better, if you want to know what it means, just look at the name

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

// Mapping from an address to other addresses that are approved to be margin-callers
mapping (address => mapping (address => bool)) public approvedCallers;

// Mapping from a positionId to the value of totalOwedTokensRepaidToLender for the position when
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you should use a variable name to describe part of what this is

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

especially if totalOwedTokensRepaidToLender is not another defined state variable


// Mapping from a positionId to the address of the owedToken of that position. Needed because
// margin erases this information when the position is closed.
mapping (bytes32 => address) public owedTokenForPosition;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm... I hadn't thought about this. This is a bit unfortunate we have to have this

address margin
)
public
ERC721Token("dYdX Margin Loans", "DYDX-Loan")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also feel DYDX-Loan is too long for a symbol

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

// ============ Token-Holder functions ============

/**
* Approves any address to margin-call any of the positions owned by the sender.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approves "an" address

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

)
external
onlyMargin
nonReentrant
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same thing for nonReentrant

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 leave in for this one

)
external
onlyMargin
nonReentrant
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not needed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

)
external
onlyMargin
nonReentrant
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


address owedToken = owedTokenForPosition[positionId];
address owner = ownerOf(uint256(positionId));
TokenInteract.transfer(owedToken, owner, tokensToSend);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should add an assert(TokenInteract.balanceOf(owedToken , address(this)) > tokensToSend

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

address owedToken = owedTokenForPosition[positionId];
address owner = ownerOf(uint256(positionId));
TokenInteract.transfer(owedToken, owner, tokensToSend);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if you want to do it in this function or another helper, but we should burn the token if the position is closed. Also delete owedTokensRepaidSinceLastWithdraw and owedTokenForPosition as commented above

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also don't do owedTokensRepaidSinceLastWithdraw[positionId] = totalRepaid; on line 303 if we're just about to delete it anyways

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@BrendanChou
Copy link
Contributor Author

I can't override non-view interface function with a view implementation function without the compiler complaining. As also complained about here: ethereum/solidity#3412

It's dumb because it should be able to do that as the visibility doesn't affect the ABI

@BrendanChou BrendanChou changed the title implement ERC721MarginLoan Implement ERC721MarginLoan Apr 21, 2018
@@ -27,7 +27,7 @@ contract ERC20Short is ERC20Position {
margin,
initialTokenHolder,
trustedRecipients,
"DYDX-S"
"D/SS"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just one "S" like the nouns are "leveraged long" and "short"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -62,6 +62,6 @@ contract ERC20Long is ERC20Position {
pure
returns (bytes)
{
return "dYdX Tokenized Long";
return "dYdX ERC20 Leveraged-Long";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"dYdX Leveraged-Long Token"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -62,6 +62,6 @@ contract ERC20Short is ERC20Position {
pure
returns (bytes)
{
return "dYdX Tokenized Short";
return "dYdX ERC20 Short-Sell";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"dYdX Short Token"

@@ -62,6 +62,6 @@ contract ERC20Short is ERC20Position {
pure
returns (bytes)
{
return "dYdX Tokenized Short";
return "dYdX Short-Sell";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"dYdX Short Token"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -62,6 +62,6 @@ contract ERC20Long is ERC20Position {
pure
returns (bytes)
{
return "dYdX Tokenized Long";
return "dYdX Leveraged-Long";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"dYdX Leveraged Long Token"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -27,7 +27,7 @@ contract ERC20Short is ERC20Position {
margin,
initialTokenHolder,
trustedRecipients,
"DYDX-S"
"d/SS"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just "d/S"

the nouns are "Short" and "Leveraged Long"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

)
external
onlyMargin
nonReentrant
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 leave in for this one

address owner = ownerOf(uint256(positionId));
require(owner != address(0));

address owedToken = owedTokenAddress[positionId];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe also assert(owedToken != address(0) I know it shouldn't be, but just to be sure

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's fine to not have that assert. It definitely shouldn't be, but if there were a problem that big, it should be asserted in the base protocol instead. Secondly it should revert on TokenInteract.transfer() anyway if the address is zero

@BrendanChou BrendanChou merged commit cd224a2 into master Apr 21, 2018
@BrendanChou BrendanChou deleted the bc_erc721loan branch April 21, 2018 01:29
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants