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

pay contract: fix leftover recipient, redeploy #1371

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions packages/contract/broadcast/DeployDaimoPay.s.sol/1/run-latest.json

Large diffs are not rendered by default.

44 changes: 22 additions & 22 deletions packages/contract/broadcast/DeployDaimoPay.s.sol/10/run-latest.json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

34 changes: 17 additions & 17 deletions packages/contract/broadcast/DeployDaimoPay.s.sol/56/run-latest.json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions packages/contract/script/deployV2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ SCRIPTS=(
# "script/pay/DeployDaimoPayBridger.s.sol"
# "script/pay/DeployPayIntentFactory.s.sol"
# "script/pay/DeployDaimoPay.s.sol"
# "script/pay/DeployDaimoPayRelayer.s.sol" # The deployer must be the LP that calls this contract.
"script/pay/DeployDaimoPayRelayer.s.sol" # The deployer must be the LP that calls this contract.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

comment this back out


# DAv2
# "script/DeployFlexSwapperUniOnly.s.sol"
Expand Down Expand Up @@ -50,7 +50,7 @@ CHAINS=(

# TESTNETS
# "$ETHERSCAN_API_KEY_L1,https://eth-sepolia.g.alchemy.com/v2/$ALCHEMY_API_KEY"
# "$ETHERSCAN_API_KEY_BASE,https://sepolia.base.org"
"$ETHERSCAN_API_KEY_BASE,https://sepolia.base.org"

)

Expand Down
4 changes: 2 additions & 2 deletions packages/contract/script/pay/DeployDaimoPay.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ contract DeployDaimoPay is Script {

address intentFactory = CREATE3.getDeployed(
msg.sender,
keccak256("PayIntentFactory-options4")
keccak256("PayIntentFactory-5")
);
address bridger = CREATE3.getDeployed(
msg.sender,
Expand All @@ -22,7 +22,7 @@ contract DeployDaimoPay is Script {
console.log("using bridger at", bridger);

address daimoPay = CREATE3.deploy(
keccak256("DaimoPay-options4"),
keccak256("DaimoPay-5"),
abi.encodePacked(
type(DaimoPay).creationCode,
abi.encode(intentFactory, bridger)
Expand Down
2 changes: 1 addition & 1 deletion packages/contract/script/pay/DeployDaimoPayRelayer.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ contract DeployDaimoPayRelayer is Script {
vm.startBroadcast();

address daimoPayRelayer = CREATE3.deploy(
keccak256("DaimoPayRelayer-options5"),
keccak256("DaimoPayRelayer-5"),
abi.encodePacked(
type(DaimoPayRelayer).creationCode,
abi.encode(owner)
Expand Down
2 changes: 1 addition & 1 deletion packages/contract/script/pay/DeployPayIntentFactory.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ contract DeployPayIntentFactory is Script {
vm.startBroadcast();

address intentFactory = CREATE3.deploy(
keccak256("PayIntentFactory-options4"),
keccak256("PayIntentFactory-5"),
abi.encodePacked(type(PayIntentFactory).creationCode, abi.encode())
);

Expand Down
16 changes: 7 additions & 9 deletions packages/contract/src/pay/DaimoPay.sol
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,6 @@ contract DaimoPay {

// Finish the intent and return any leftover tokens to the caller
_finishIntent({intentAddr: intentAddr, intent: intent, calls: calls});
TransferTokenBalance.refundLeftoverTokens({
token: intent.finalCallToken.token,
recipient: payable(msg.sender)
});

emit FastFinish({intentAddr: intentAddr, newRecipient: msg.sender});
}
Expand Down Expand Up @@ -175,10 +171,6 @@ contract DaimoPay {
intent: intent,
calls: calls
});
TransferTokenBalance.refundLeftoverTokens({
token: intent.finalCallToken.token,
recipient: payable(recipient)
});
} else {
// Otherwise, the relayer fastFinished the intent, give them the recieved
// amount.
Expand All @@ -187,7 +179,7 @@ contract DaimoPay {
uint256 n = intent.bridgeTokenOutOptions.length;
for (uint256 i = 0; i < n; ++i) {
TokenAmount calldata tokenOut = intent.bridgeTokenOutOptions[i];
TransferTokenBalance.transferBalance({
TokenUtils.transferBalance({
token: tokenOut.token,
recipient: payable(recipient)
});
Expand All @@ -203,6 +195,7 @@ contract DaimoPay {
// Swap the token the relayer transferred to finalCallToken
// Then, if the intent has a finalCall, make the intent call.
// Otherwise, transfer the token to the final address.
// Finally, send any leftover final token to the caller.
function _finishIntent(
address intentAddr,
PayIntent calldata intent,
Expand Down Expand Up @@ -268,6 +261,11 @@ contract DaimoPay {
intent: intent
});
}

TokenUtils.transferBalance({
token: intent.finalCallToken.token,
recipient: payable(msg.sender)
});
}

receive() external payable {}
Expand Down
2 changes: 1 addition & 1 deletion packages/contract/src/pay/DaimoPayRelayer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ contract DaimoPayRelayer is Ownable2Step {
// Transfer any bridgeTokenOut balance back to the owner
uint256 n = intent.bridgeTokenOutOptions.length;
for (uint256 i = 0; i < n; i++) {
TransferTokenBalance.transferBalance(
TokenUtils.transferBalance(
intent.bridgeTokenOutOptions[i].token,
payable(msg.sender)
);
Expand Down
6 changes: 3 additions & 3 deletions packages/contract/src/pay/PayIntent.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity ^0.8.12;
import "openzeppelin-contracts/contracts/proxy/utils/Initializable.sol";
import "openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol";

import "./TransferTokenBalance.sol";
import "./TokenUtils.sol";
import "../interfaces/IDaimoPayBridger.sol";

/// @dev Represents an intended call: "make X of token Y show up on chain Z, then
Expand Down Expand Up @@ -123,7 +123,7 @@ contract PayIntentContract is Initializable {
});

// Refund any leftover tokens in the contract to caller
TransferTokenBalance.refundLeftoverTokens({
TokenUtils.transferBalance({
token: IERC20(bridgeTokenIn),
recipient: caller
});
Expand All @@ -150,7 +150,7 @@ contract PayIntentContract is Initializable {
// Send to escrow contract, which will forward to current recipient
uint256 n = intent.bridgeTokenOutOptions.length;
for (uint256 i = 0; i < n; ++i) {
TransferTokenBalance.transferBalance({
TokenUtils.transferBalance({
token: intent.bridgeTokenOutOptions[i].token,
recipient: intent.escrow
});
Expand Down
9 changes: 9 additions & 0 deletions packages/contract/src/pay/TokenUtils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,13 @@ library TokenUtils {
);
token.safeTransferFrom({from: from, to: to, value: amount});
}

/// Sends any token balance in the contract to the recipient.
function transferBalance(IERC20 token, address payable recipient) internal {
uint256 balance = getBalanceOf({token: token, addr: address(this)});

if (balance > 0) {
transfer({token: token, recipient: recipient, amount: balance});
}
}
}
45 changes: 0 additions & 45 deletions packages/contract/src/pay/TransferTokenBalance.sol

This file was deleted.

22 changes: 9 additions & 13 deletions packages/contract/test/pay/DaimoPay.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import "forge-std/Test.sol";
import {GasInfo} from "@axelar-network/contracts/interfaces/IAxelarGasService.sol";
import "account-abstraction/interfaces/IEntryPoint.sol";
import "account-abstraction/core/EntryPoint.sol";
import {IERC20} from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol";

import "../../src/pay/DaimoPay.sol";
import "../../src/pay/DaimoPayBridger.sol";
Expand Down Expand Up @@ -181,7 +182,10 @@ contract DaimoPayTest is Test {
console.log("DaimoPay address:", address(dp));
console.log("TestUSDC (fromToken) address:", address(_fromToken));
console.log("TestUSDC (toToken) address:", address(_toToken));
console.log("TestUSDC (bridgeTokenOption) address:", address(_bridgeTokenOption));
console.log(
"TestUSDC (bridgeTokenOption) address:",
address(_bridgeTokenOption)
);
}

function getBridgeTokenOutOptions()
Expand Down Expand Up @@ -420,12 +424,8 @@ contract DaimoPayTest is Test {
});

// Extra tokens should be refunded to the caller
vm.expectEmit(LINEA_INTENT_ADDR);
emit TransferTokenBalance.RefundedTokens({
recipient: _alice,
token: address(_fromToken),
amount: 10
});
vm.expectEmit(address(_fromToken));
emit IERC20.Transfer(LINEA_INTENT_ADDR, _alice, 10);

vm.expectEmit(address(dp));
emit DaimoPay.Start(LINEA_INTENT_ADDR, intent);
Expand Down Expand Up @@ -619,12 +619,8 @@ contract DaimoPayTest is Test {
_toToken.transfer({to: address(dp), value: 10});

// An extra 9 of finalCallToken should be sent back to the LP
vm.expectEmit(address(dp));
emit TransferTokenBalance.RefundedTokens({
recipient: _lp,
token: address(_toToken),
amount: 9
});
vm.expectEmit(address(_toToken));
emit IERC20.Transfer(address(dp), _lp, 9);

dp.fastFinishIntent({intent: intent, calls: new Call[](0)});

Expand Down
50 changes: 0 additions & 50 deletions packages/daimo-contract/src/codegen/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2887,31 +2887,6 @@ export const daimoPayAbi = [
],
name: 'IntentFinished',
},
{
type: 'event',
anonymous: false,
inputs: [
{
name: 'recipient',
internalType: 'address',
type: 'address',
indexed: true,
},
{
name: 'token',
internalType: 'address',
type: 'address',
indexed: true,
},
{
name: 'amount',
internalType: 'uint256',
type: 'uint256',
indexed: true,
},
],
name: 'RefundedTokens',
},
{
type: 'event',
anonymous: false,
Expand Down Expand Up @@ -6840,31 +6815,6 @@ export const payIntentContractAbi = [
],
name: 'Initialized',
},
{
type: 'event',
anonymous: false,
inputs: [
{
name: 'recipient',
internalType: 'address',
type: 'address',
indexed: true,
},
{
name: 'token',
internalType: 'address',
type: 'address',
indexed: true,
},
{
name: 'amount',
internalType: 'uint256',
type: 'uint256',
indexed: true,
},
],
name: 'RefundedTokens',
},
{
type: 'error',
inputs: [{ name: 'target', internalType: 'address', type: 'address' }],
Expand Down
6 changes: 3 additions & 3 deletions packages/daimo-contract/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ export const daimoFastCctpAddrs: Address[] = [
];

// Daimo Pay
export const daimoPayAddress = "0xf603cE83e28c9E9E699c4df2B11E31B63b1890C0";
export const daimoPayAddress = "0x9BD9caF29B76E98d57Fc3a228A39C7efe8ca0eAf";
export const daimoPayBridgerAddress =
"0xB4418A1EcE96CF1F797fef3Ab2c0Afdf59701C38";
export const daimoPayAxelarBridgerAddress =
"0x91052AEc686070bc8787fde3d530f21976302867";
export const payIntentFactoryAddress =
"0x78dC70cC8C3b3a79BF161941934ed4829C9E7DDf";
"0x90498530e2FddcD937faB0Ab56cF6a7c1FB08b62";
export const daimoPayRelayerAddress =
"0xD9c53251d364F4E467412EDbD0ecCe6aAEB97cAA";
"0xc46614d2E324Bfe5c0707D0b61d61d280FDcf65B";

// Utils
export const daimoPayBatchReadUtilsAddress =
Expand Down
1 change: 1 addition & 0 deletions packages/daimo-contract/wagmi.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export default defineConfig({
forge: { build: false },
include: [
"Daimo*.sol/*",
"Dummy*.sol/*",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

why add Dummy?

"Pay*.sol/*",
"ERC*.sol/*",
"EntryPoint.sol/*",
Expand Down
Loading