-
Notifications
You must be signed in to change notification settings - Fork 282
[eth] Add token swap example application #518
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
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Ignored Deployment
|
|
||
``` | ||
forge install foundry-rs/forge-std@2c7cbfc6fbede6d7c9e6b17afe997e3fdfe22fef --no-git --no-commit | ||
forge install pyth-network/pyth-sdk-solidity@v1.0.1 --no-git --no-commit |
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.
for future: we can update this sdk to the new version. the only change will be the getUpdateFee
method.
@@ -0,0 +1,272 @@ | |||
[ |
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.
For future: maybe move abis to an abi
directory?
} | ||
} | ||
|
||
// TODO: we should probably move something like this into the solidity sdk |
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.
Yeah i had the same impression for this too. But If it is an example we want to share with people, can we add this as an issue and remove it from here?
|
||
if (isBuy) { | ||
// (Round up) | ||
quoteSize += 1; |
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 only true if the remainder of size * basePrice % quotePrice
is positive, right? I guess its fine.
// (Round up) | ||
quoteSize += 1; | ||
|
||
quoteToken.transferFrom(msg.sender, address(this), quoteSize); |
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.
Let's add that the transaction reverts if there is not enough fund in the users wallet or the contract.
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.
It is awesome! I left some minor comments.
In general before merging it let's have a disclaimer in the readme that this is not intended for any production use. Also, the way this DEX works is not very practical.
} | ||
|
||
function testSwap() public { | ||
setupTokens(10e18, 10e18, 10e18, 10e18); |
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.
maybe move this to setUp too?
This is an example oracle AMM application using Pyth prices. I'll give you the context for why we need this on slack.
(I based this on @ali-bahjati 's ETH transfer example)
The frontend associated with this app is very janky at the moment. It works, but it needs some love. I'll come back to that in the next PR.
