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

Colin/liquid exchange #5

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft

Colin/liquid exchange #5

wants to merge 3 commits into from

Conversation

Autoparallel
Copy link
Contributor

Linking to relevant arbiter PR

@@ -1,12 +1,25 @@
pragma solidity ^0.8.10;
import "../../openzeppelin-contracts/contracts/token/ERC20/ERC20.sol";

Choose a reason for hiding this comment

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

forge install transmissions11/solmate

Better module!

Comment on lines +5 to +6
import "../../portfolio/lib/solmate/src/utils/FixedPointMathLib.sol"; // This import goes directly to the contract
import "../../openzeppelin-contracts/contracts/token/ERC20/ERC20.sol";

Choose a reason for hiding this comment

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

In foundry.toml, you can make a 'remappings' entry that will make these imports easier:

remappings = [
 'solmate/=lib/portfolio/lib/solmate/src'
]

Then in contract:
import "solmate/utils/FixedPointMath.sol";

uint256 public constant WAD = 10**18;

// Each LiquidExchange contract will be deployed with a pair of token addresses and an initial price
constructor(address _arbiter_token_x, address _arbiter_token_y, uint256 _price) {

Choose a reason for hiding this comment

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

Styling nit:

Solidity is usually camel case, but I don't mind.
I DO mind leading underscores. Leading underscores are reserved for internal variables and functions. Trailing underscores are good for arguments.

Comment on lines +25 to +26
arbiter_token_x = ERC20(_arbiter_token_x);
arbiter_token_x_address = _arbiter_token_x;

Choose a reason for hiding this comment

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

Don't need two! Just need the address, and you can cast between the types like this:

address token = 0x01
ERC20 token0 = ERC20(token);
address token1 = address(token0);

Comment on lines +48 to +50
function getPrice() public view returns (uint256) {
return price;
}

Choose a reason for hiding this comment

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

While getPrice is fine, since price is a public variable, it creates a getter price() already

Comment on lines +59 to +61
// Set allowances
// arbiter_token_x.increaseAllowance(msg.sender, _amount_in);
// arbiter_token_y.increaseAllowance(admin, amount_out); //might not be necessary if we increase the allowance for the manager outside of this

Choose a reason for hiding this comment

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

So:
You call this contract, which means its asking for YOUR allowance for THIS contract to spend tokens. This means you have to send a transaction to the token to approve this contract as a spender.

// arbiter_token_y.increaseAllowance(admin, amount_out); //might not be necessary if we increase the allowance for the manager outside of this
// Transfer amount in and amount out
arbiter_token_x.transferFrom(msg.sender, admin, _amount_in);
arbiter_token_y.transferFrom(admin, msg.sender, amount_out);

Choose a reason for hiding this comment

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

The from argument in transferFrom should ALWAYS be msg.sender.

You should use transfer here, and have this contract hold the tokens.

Choose a reason for hiding this comment

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

I guess this does work for admin.

arbiter_token_y.transferFrom(msg.sender, admin, _amount_in);
arbiter_token_x.transferFrom(admin, msg.sender, amount_out);
} else {
revert("Invalid token");

Choose a reason for hiding this comment

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

Use a custom error:

error InvalidToken();

revert InvalidToken();

Copy link
Collaborator

Choose a reason for hiding this comment

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

Following up on this? @Autoparallel, I am at a spot where i want to decode the events on this market.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants