-
Notifications
You must be signed in to change notification settings - Fork 212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
finance: Adapt to new Vault #135
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amazing work Bingen! 💰🏆
apps/finance/contracts/Finance.sol
Outdated
@@ -105,23 +102,20 @@ contract Finance is AragonApp, ERC677Receiver { | |||
* @notice Allows to send ETH from this contract to Vault, to avoid locking them in contract forever. | |||
*/ | |||
function escapeHatch() public payable { | |||
// convert ETH to EtherToken | |||
etherToken.wrapAndCall.value(this.balance)(address(this), "Adding Funds"); | |||
vault.deposit.value(msg.value)(address(0), msg.sender, 0, new bytes(0)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better to use an ETH
constant than passing around address(0)
everywhere
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure!
apps/finance/contracts/Finance.sol
Outdated
@@ -105,23 +102,20 @@ contract Finance is AragonApp, ERC677Receiver { | |||
* @notice Allows to send ETH from this contract to Vault, to avoid locking them in contract forever. | |||
*/ | |||
function escapeHatch() public payable { | |||
// convert ETH to EtherToken | |||
etherToken.wrapAndCall.value(this.balance)(address(this), "Adding Funds"); | |||
vault.deposit.value(msg.value)(address(0), msg.sender, 0, new bytes(0)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Value must be msg.value
, this code should only work when msg.value == 0
apps/finance/contracts/Finance.sol
Outdated
_recordIncomingTransaction( | ||
_token, | ||
msg.sender, | ||
_amount, | ||
_reference | ||
); | ||
require(_token.transferFrom(msg.sender, address(vault), _amount)); | ||
vault.deposit(_token, msg.sender, _amount, new bytes(0)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is not very user friendly, I'm changing it to get the tokens to finance app, allow to Vault and then deposit, in the way receiveApproval
was done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I think this was always the case, to be honest. We could get away with it in one call if the token had approveAndCall
/ ERC677, but I guess that's not in here anymore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but what was weird (from UX perspective) was to approve to Vault
but to send to Finance
. Have a look at how it is now, please, and let me know your thoughts.
apps/finance/contracts/Finance.sol
Outdated
@@ -166,32 +160,35 @@ contract Finance is AragonApp, ERC677Receiver { | |||
external |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would remove this function entirely now that we have the new vault
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
apps/finance/contracts/Finance.sol
Outdated
); | ||
require(token.transfer(address(vault), amount)); | ||
return true; | ||
vault.deposit(msg.sender, _from, _amount, _userData); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't finance need to create an allowance or setOperator here for this to work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, well, as ERC777 is not part of the release and Vault doesn't fully support it yet, there was no tests for it .. so even the name and the signature are wrong! :(
Wouldn't something like this work?
ERC777(msg.sender).send(adress(vault), _amount, _userData);
Anyway, maybe I could just comment it out until we have ERC777
on Vault.
@@ -325,12 +322,15 @@ contract Finance is AragonApp, ERC677Receiver { | |||
require(value > 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can remove ERC20 token = ERC20(_token);
above
apps/finance/test/finance.js
Outdated
@@ -55,13 +60,13 @@ contract('Finance App', accounts => { | |||
}) | |||
|
|||
it('records ERC20 deposits', async () => { | |||
await token1.approve(app.address, 5) | |||
await token1.approve(vault.address, 5) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
apps/finance/contracts/Finance.sol
Outdated
@@ -105,23 +102,20 @@ contract Finance is AragonApp, ERC677Receiver { | |||
* @notice Allows to send ETH from this contract to Vault, to avoid locking them in contract forever. | |||
*/ | |||
function escapeHatch() public payable { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should make this function function () payable { vault.deposit.value(this.balance)(ETH, msg.sender, this.balance, new bytes(0)) }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rather than escapeHatch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So true! 💯
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looking good, thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is awesome, love how we've been able to refine this with the Vault's new API :).
A few questions / small changes noted.
@@ -74,8 +73,7 @@ contract Finance is AragonApp, ERC677Receiver { | |||
mapping (address => bool) hasBudget; | |||
} | |||
|
|||
Vault public vault; | |||
EtherToken public etherToken; | |||
IVaultConnector public vault; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems a bit odd that vault
is an IVaultConnector
; I haven't looked yet, but I guess Vault
builds on that interface too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ya, it looks odd, but it's actually cool: Vault
doesn't implement it, but fallback is doing delegateFwd
to it. This way final functions can be called without the need of implementing them in Vault
. It was @izqui 's suggestion, so pinging him here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep, lets do this for now.
// convert ETH to EtherToken | ||
etherToken.wrapAndCall.value(this.balance)(address(this), "Adding Funds"); | ||
function () public payable { | ||
vault.deposit.value(this.balance)(ETH, msg.sender, this.balance, new bytes(0)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Somewhat confused about this—do we want this to be the fallback (rather than an explicit "escape hatch")?
Also, should it be this
and not msg.sender
, e.g.:
vault.deposit.value(this.balance)(ETH, this, this.balance, new bytes(0));
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, it should be this, as for the vault's context it is coming from finance, doesn't matter where it originated
apps/finance/contracts/Finance.sol
Outdated
ERC20(_token).approve(address(vault), _amount); | ||
// finally we can deposit them | ||
vault.deposit(_token, this, _amount, new bytes(0)); | ||
//vault.deposit(_token, msg.sender, _amount, new bytes(0)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this commented out line be removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure, thanks!
apps/finance/contracts/Finance.sol
Outdated
@@ -429,7 +409,7 @@ contract Finance is AragonApp, ERC677Receiver { | |||
return settings.periodDuration; | |||
} | |||
|
|||
function getBudget(address _token) transitionsPeriod public returns (uint256 budget, bool hasBudget, uint256 remainingBudget) { | |||
function getBudget(address _token) transitionsPeriod public view returns (uint256 budget, bool hasBudget, uint256 remainingBudget) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can't be view
; transitionsPeriod
potentially changes state.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, yes, thanks! I changed because I was having problems with some test, but reverting it now.
apps/finance/test/finance.js
Outdated
@@ -2,6 +2,9 @@ const { assertRevert, assertInvalidOpcode } = require('@aragon/test-helpers/asse | |||
const getBalance = require('@aragon/test-helpers/balance')(web3) | |||
|
|||
const Vault = artifacts.require('Vault') | |||
const ETHConnector = artifacts.require('ETHConnector') | |||
const ERC20Connector = artifacts.require('ERC20Connector') | |||
//const IVaultConnector = artifacts.require('IVaultConnector') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we remove this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
apps/finance/test/finance.js
Outdated
@@ -13,10 +16,13 @@ contract('Finance App', accounts => { | |||
const periodDuration = 100 | |||
const withdrawAddr = '0x0000000000000000000000000000000000001234' | |||
|
|||
const ETH='0x0' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we get this from Finance as Finance.ETH()
(if we made that public)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried, but it doesn't work for me from Truffle. I get:
TypeError: Finance.ETH is not a function
I consider Brett's comments addressed. Merging to my branch |
* finance: Adapt to new Vault * finance: Adapt to new Vault (address PR comments) * finance: Adapt to new Vault (address PR comments)
Besides, rename IConnector interface to IVaultConnector