-
Notifications
You must be signed in to change notification settings - Fork 390
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
feat: update contract HypERC20CollateralSaving #2499
base: main
Are you sure you want to change the base?
feat: update contract HypERC20CollateralSaving #2499
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.
I believe you need a bit more specific accounting/tracking around the shares in the vault
bytes calldata // no metadata | ||
) internal override { | ||
// redeem token from vault | ||
uint256 amount = savingToken.redeem(_amount, address(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.
redeem takes the shares
quantity which might be different from the token amount
quantity, so I believe you need to track that separately.
* @title Hyperlane ERC20 Token Collateral that wraps an existing ERC20 with remote transfer functionality. | ||
* @author Abacus Works | ||
*/ | ||
contract HypERC20CollateralSaving is TokenRouter { |
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.
You should probably just extend from HypErc20Collateral
5c42e4c
to
1f85381
Compare
@nambrot |
I have deployed it successfully but still need to test it a bit |
) internal override { | ||
uint256 redeemAmount = _convertToRedeemToken(_amount); | ||
// redeem token from vault | ||
uint256 amount = erc4626Token.redeem( |
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 believe you are assuming that amount == shares which i don't think has to be 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.
@nambrot
it is quite difficult to implement in reverse
for example i send 10Dai from ethereum to polygon.
in polygon I �transfer 3Dai to someone else and he transfer back from polygon to ethereum so who will get the interrest.
if I use withdraw instead of redeem, the profit will be hard to calculate
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'm not sure what you mean by do it in reverse? Can you not just track the amount per user and the total number of shares, which then gives you the profit at any given time for the owner?
|
||
// approve to erc4626 | ||
uint256 amount = type(uint256).max; // Maximum value of uint256 | ||
wrappedToken.approve(erc4626, amount); |
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.
Is this a good idea?
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.
because we move the token to erc4626 so we should approve it instead of approving it every time
7a5582f
to
d1808dc
Compare
@nambrot |
Description
I try to implement HypERC20CollateralSaving that can send token to saving vault (erc ERC4626)
Drive-by changes
i create wrap_route from goerli to fuji
ERC20
Code
Address
0xf4089c897f93060F3004B7160f798E9Fd0eE916b
ERC4626
Code
Address
0xE32343749686f759AB771A8098672327c2837902
Wrap-route
Artifacts
Test
Step 1
i sent 10DAI from goerli to fuji
https://explorer.hyperlane.xyz/message/0x81da02aaea4942a7cd492e77d9e858cf96e2f68ec911203468f79fd95d59ce88
before i add 10 DAI to vault contract it already have 10DAI and 5 shareToken
So after i add more 10DAI hypCollateralSaving contract will have 5 (eth) shareToken = 10 (eth) DAI
Step 2
Add more 4 (ẹth) DAI direct to vault contract as reward
https://goerli.etherscan.io/tx/0x5b520acf7f41fde32dd369441dc806f092c05d7c1fb0abfc1b2dee10551392d5
i expect that 5 shareToken = 12 (eth)DAI
Step 3
i withdraw 10DAI by send from Fuji -> Goerli
expect that hypCollateralSaving contract have 0.83(eth) shareToken and use still get 2DAI at Goerli
https://explorer.hyperlane.xyz/message/0x1563809b6a42086310099e60cf98000894a0d6d78f54b66412f0fd00edfff0bb
Step 4
i will withdraw the rest of token by call function
takeProfit
i expect that i can get 2 more DAI
https://goerli.etherscan.io/tx/0x6b4f47c15d59b27e7b99f5b6567c83d3746dab794d96140fb89f2a93621e2cd5
Check balance of my account
now i have 101.9999 DAI
Related issues
Backward compatibility
Yes
Testing
not yet