Skip to content
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

Merged
merged 3 commits into from
Mar 16, 2018
Merged

finance: Adapt to new Vault #135

merged 3 commits into from
Mar 16, 2018

Conversation

bingen
Copy link
Contributor

@bingen bingen commented Mar 15, 2018

Besides, rename IConnector interface to IVaultConnector

@bingen bingen requested a review from izqui March 15, 2018 22:32
Copy link
Contributor

@izqui izqui left a comment

Choose a reason for hiding this comment

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

Amazing work Bingen! 💰🏆

@@ -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));
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure!

@@ -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));
Copy link
Contributor

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

https://github.com/aragon/aragon-apps/pull/129/files#diff-9ebb8e9a2c4b877825d0aeece0fb63feR14

_recordIncomingTransaction(
_token,
msg.sender,
_amount,
_reference
);
require(_token.transferFrom(msg.sender, address(vault), _amount));
vault.deposit(_token, msg.sender, _amount, new bytes(0));
Copy link
Contributor

Choose a reason for hiding this comment

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

So now before depositing tokens using Finance you need to create an allowance to the Vault? (otherwise there is no way this works haha). This should be made very clear in the documentation. Also pinging @onbjerg and @sohkai who are working in the frontend and this could be a blocker

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

@@ -166,32 +160,35 @@ contract Finance is AragonApp, ERC677Receiver {
external
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

);
require(token.transfer(address(vault), amount));
return true;
vault.deposit(msg.sender, _from, _amount, _userData);
Copy link
Contributor

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?

Copy link
Contributor Author

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);
Copy link
Contributor

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

@@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@@ -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 {
Copy link
Contributor

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)) }

Copy link
Contributor

Choose a reason for hiding this comment

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

rather than escapeHatch

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So true! 💯

Copy link
Contributor

@izqui izqui left a comment

Choose a reason for hiding this comment

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

looking good, thanks

Copy link
Contributor

@sohkai sohkai left a 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;
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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));
Copy link
Contributor

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));

Copy link
Contributor

Choose a reason for hiding this comment

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

Pinging @izqui, who came up with this change earlier.

Copy link
Contributor

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

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));
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure, thanks!

@@ -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) {
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@@ -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')
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we remove this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

@@ -13,10 +16,13 @@ contract('Finance App', accounts => {
const periodDuration = 100
const withdrawAddr = '0x0000000000000000000000000000000000001234'

const ETH='0x0'
Copy link
Contributor

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)?

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 tried, but it doesn't work for me from Truffle. I get:

TypeError: Finance.ETH is not a function

@izqui
Copy link
Contributor

izqui commented Mar 16, 2018

I consider Brett's comments addressed. Merging to my branch

@izqui izqui merged commit 191d312 into good-vault Mar 16, 2018
@izqui izqui deleted the good-vault-finance-2 branch March 16, 2018 19:42
ramilexe pushed a commit to ConsiderItDone/aragon-apps that referenced this pull request Dec 9, 2021
* finance: Adapt to new Vault

* finance: Adapt to new Vault (address PR comments)

* finance: Adapt to new Vault (address PR comments)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants