-
Notifications
You must be signed in to change notification settings - Fork 35
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
pay contract: new daimo pay relayer #1372
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
e724886
to
23a31be
Compare
23a31be
to
66f938a
Compare
@@ -23,6 +23,10 @@ contract DeployDaimoPayRelayer is Script { | |||
|
|||
console.log("daimoPayRelayer deployed at address:", daimoPayRelayer); | |||
|
|||
address relayer = 0x723A63fb50dA50A26997Fb99A2Eb151E4F8c5227; |
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.
where does this address come from?
the line below (daimoPayRelayer...grantRelayerRole(relayer)
) is a bit confusing
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 just the other EOA i created for starts/claims
|
||
import "./DaimoPay.sol"; | ||
import "./TokenUtils.sol"; | ||
|
||
/* | ||
* Relayer contract that funds completes DaimoPay intents. | ||
*/ | ||
contract DaimoPayRelayer is Ownable2Step { | ||
contract DaimoPayRelayer is AccessControl { |
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.
👍
address indexed requiredTokenOut, | ||
uint256 swapAmountOut, | ||
uint256 maxPreTip, | ||
uint256 maxPostTip |
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.
might be worth calling this maxIntentTip
and maxStartTip
for clarity
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.
maxStartTip
would be the post-tip and maxIntentTip
would be the pre-tip?
personally, i prefer maxPreTip
and maxPostTip
. i think this naming makes more sense at the function-level context, whereas maxStartTip
and maxIntentTip
requires global-level context to make sense
|
||
// Withdraws the full balance of a token from the contract to the admin. | ||
function withdrawBalance(IERC20 token) public onlyRole(DEFAULT_ADMIN_ROLE) { | ||
TokenUtils.transferBalance(token, payable(msg.sender)); |
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 have this return uint256
, then return TokenUtils.transferBalance...
this way if admin needs to send the token balance on to anywhere else they know the amount cleanly
Call calldata innerSwap | ||
) external payable { | ||
require(tx.origin == owner(), "DPR: only usable by owner"); | ||
require(hasRole(RELAYER_ROLE, tx.origin), "DPR: only relayer"); |
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.
🚀
// suppliedTokenInAmount. The difference is tipped by the contract. We | ||
// already checked that the tip is within maxPreTip. | ||
if (innerSwap.to != address(0)) { | ||
requiredTokenIn.token.approve(innerSwap.to, requiredTokenIn.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.
forceapprove handles USDT inputs
////////////////////////////////////////////////////////////// | ||
|
||
// If we received less than required, check that the amount we need to | ||
// tip is within maxPostTip. | ||
if (swapAmountOut < requiredTokenOut.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.
so if i understand correctly:
-
during
start
, we have some amount of (random token) and need to produce an exact amount of the bridge token. maxPreTip is 0, maxPostTip is the max amount of the bridge token (eg USDC) we're willing to tip. -
during
fastfinish
/claim
(whichever is actually running the intent) we have some amount of bridge token and we need an exact amount of destination token. maxPostTip is now 0, and maxPreTip is whatever amount of the bridge token we're willing to tip.
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.
correct
} | ||
|
||
// Transfer the required output tokens to the caller, tipping the | ||
// shortfall if needed. If there are surplus tokens from the swap, keep | ||
// them. |
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.
one effect of this is that the relayer will accumulate change in whatever the destination tokens are.
for ethOS, for example, it'll accumulate ETH on Base.
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
@@ -124,7 +167,7 @@ contract DaimoPayRelayer is Ownable2Step { | |||
Call[] calldata startCalls, | |||
bytes calldata bridgeExtraData, | |||
Call[] calldata postCalls | |||
) public payable onlyOwner { | |||
) public payable onlyRole(RELAYER_ROLE) { |
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 might be worth renaming this from RELAYER_ROLE
/ relayer
etc to RELAY_EOA_ROLE
/ relayEOA
or similar, to distinguish it from the relayer contract
*/ | ||
export function isEvmChain(chainId: number) { | ||
return chainId !== solana.chainId; | ||
} |
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.
that's funny, I have this exact diff on another branch.
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.
LGreatTM after comments
maxPreTip
andmaxPostTip
separate parameters. This could be useful to avoid unintentionally tipping when we switch to having the relayer hold multiple tokensswapAndTip
now emits an event upon success. This will help us track how tipping affects our PnLTesting
Wrote test suite for new contract which tests:
swapAndTip
pre-tip and post-tip work correctlyswapAndTip
doesn't allow pre-tip or post-tip to exceed the max tip amount