diff --git a/source/delegate/contracts/Delegate.sol b/source/delegate/contracts/Delegate.sol index 779ca746b..15e9366ad 100644 --- a/source/delegate/contracts/Delegate.sol +++ b/source/delegate/contracts/Delegate.sol @@ -9,18 +9,18 @@ import { Ownable } from "solady/src/auth/Ownable.sol"; import { SafeTransferLib } from "solady/src/utils/SafeTransferLib.sol"; /** - * @title Delegate: Deployable Trading Rules for the AirSwap Network - * @notice Supports fungible tokens (ERC-20) + * @title AirSwap: Delegated On-chain Trading Rules + * @notice Supports ERC-20 tokens * @dev inherits IDelegate, Ownable and uses SafeTransferLib */ contract Delegate is IDelegate, Ownable { - // The Swap contract to be used to settle trades + // The SwapERC20 contract to be used to execute orders ISwapERC20 public swapERC20; // Mapping of sender to senderToken to to signerToken to Rule mapping(address => mapping(address => mapping(address => Rule))) public rules; - // Mapping of signer to authorized signatory + // Mapping of sender to authorized manager mapping(address => address) public authorized; /** @@ -32,52 +32,56 @@ contract Delegate is IDelegate, Ownable { } /** - * @notice Set a Trading Rule - * @param _senderToken address Address of an ERC-20 token the consumer would send - * @param _senderRuleAmount uint256 Maximum amount of ERC-20 token the sender wants to swap - * @param _signerToken address Address of an ERC-20 token the delegate would recieve - * @param _signerAmount uint256 Minimum amount of ERC-20 token the delegate would recieve + * @notice Set a Rule + * @param _senderWallet The address of the sender's wallet + * @param _senderToken address ERC-20 token the sender would transfer + * @param _senderAmount uint256 Maximum sender amount for the rule + * @param _signerToken address ERC-20 token the signer would transfer + * @param _signerAmount uint256 Maximum signer amount for the rule + * @param _expiry uint256 Expiry in seconds since 1 January 1970 */ function setRule( address _senderWallet, address _senderToken, - uint256 _senderRuleAmount, + uint256 _senderAmount, address _signerToken, uint256 _signerAmount, - uint256 _ruleExpiry + uint256 _expiry ) external { if (authorized[_senderWallet] != address(0)) { - if (authorized[_senderWallet] != msg.sender) revert SenderInvalid(); + // If an authorized manager is set, message sender must be the manager + if (msg.sender != authorized[_senderWallet]) revert SenderInvalid(); } else { - if (_senderWallet != msg.sender) revert SenderInvalid(); + // Otherwise message sender must be the sender wallet + if (msg.sender != _senderWallet) revert SenderInvalid(); } + // Set the rule. Overwrites an existing rule. rules[_senderWallet][_senderToken][_signerToken] = Rule( _senderWallet, _senderToken, - _senderRuleAmount, + _senderAmount, 0, _signerToken, _signerAmount, - _ruleExpiry + _expiry ); emit SetRule( _senderWallet, _senderToken, - _senderRuleAmount, - 0, + _senderAmount, _signerToken, _signerAmount, - _ruleExpiry + _expiry ); } /** - * @notice Unset a Trading Rule - * @dev only callable by the owner of the contract, removes from a mapping - * @param _senderToken address Address of an ERC-20 token the sender would send - * @param _signerToken address Address of an ERC-20 token the delegate would receive + * @notice Unset rule + * @param _senderWallet The address of the sender's wallet + * @param _senderToken address sender token of the rule + * @param _signerToken address signer token of the rule */ function unsetRule( address _senderWallet, @@ -85,15 +89,34 @@ contract Delegate is IDelegate, Ownable { address _signerToken ) external { if (authorized[_senderWallet] != address(0)) { - if (authorized[_senderWallet] != msg.sender) revert SenderInvalid(); + // If an authorized manager is set, the message sender must be the manager + if (msg.sender != authorized[_senderWallet]) revert SenderInvalid(); } else { - if (_senderWallet != msg.sender) revert SenderInvalid(); + // Otherwise the message sender must be the sender wallet + if (msg.sender != _senderWallet) revert SenderInvalid(); } + + // Delete the rule delete rules[_senderWallet][_senderToken][_signerToken]; emit UnsetRule(_senderWallet, _senderToken, _signerToken); } + /** + * @notice Atomic ERC20 Swap + * @notice forwards to the underlying SwapERC20 contract + * @param _senderWallet address Wallet to receive sender proceeds + * @param _nonce uint256 Unique and should be sequential + * @param _expiry uint256 Expiry in seconds since 1 January 1970 + * @param _signerWallet address Wallet of the signer + * @param _signerToken address ERC20 token transferred from the signer + * @param _signerAmount uint256 Amount transferred from the signer + * @param _senderToken address ERC20 token transferred from the sender + * @param _senderAmount uint256 Amount transferred from the sender + * @param _v uint8 "v" value of the ECDSA signature + * @param _r bytes32 "r" value of the ECDSA signature + * @param _s bytes32 "s" value of the ECDSA signature + */ function swap( address _senderWallet, uint256 _nonce, @@ -108,20 +131,20 @@ contract Delegate is IDelegate, Ownable { bytes32 _s ) external { Rule storage rule = rules[_senderWallet][_senderToken][_signerToken]; - if ( _signerAmount < - (rule.signerAmount * (rule.senderRuleAmount - rule.senderFilledAmount)) / - rule.senderRuleAmount + (rule.signerAmount * (rule.senderAmount - rule.senderFilledAmount)) / + rule.senderAmount ) { - revert InvalidSignerAmount(); + revert SignerAmountInvalid(); } - if (rule.ruleExpiry < block.timestamp) revert RuleExpired(); + if (rule.expiry < block.timestamp) revert RuleExpired(); - if (_senderAmount > (rule.senderRuleAmount - rule.senderFilledAmount)) { - revert InvalidSenderAmount(); + if (_senderAmount > (rule.senderAmount - rule.senderFilledAmount)) { + revert SenderAmountInvalid(); } + // Transfer the sender token to this contract SafeTransferLib.safeTransferFrom( _senderToken, _senderWallet, @@ -129,8 +152,10 @@ contract Delegate is IDelegate, Ownable { _senderAmount ); + // Approve the SwapERC20 contract to transfer the sender token ERC20(_senderToken).approve(address(swapERC20), _senderAmount); + // Execute the swap swapERC20.swapLight( _nonce, _expiry, @@ -144,8 +169,10 @@ contract Delegate is IDelegate, Ownable { _s ); + // Transfer the signer token to the sender wallet SafeTransferLib.safeTransfer(_signerToken, _senderWallet, _signerAmount); + // Update the filled amount rules[_senderWallet][_senderToken][_signerToken] .senderFilledAmount += _senderAmount; emit DelegateSwap(_nonce, _signerWallet); @@ -153,7 +180,7 @@ contract Delegate is IDelegate, Ownable { /** * @notice Authorize a wallet to manage rules - * @param _manager address Wallet of the signatory to authorize + * @param _manager address Wallet of the manager to authorize * @dev Emits an Authorize event */ function authorize(address _manager) external { @@ -177,7 +204,7 @@ contract Delegate is IDelegate, Ownable { * @param _swapERC20 ISwapERC20 The SwapERC20 contract */ function setSwapERC20Contract(ISwapERC20 _swapERC20) external onlyOwner { - if (address(_swapERC20) == address(0)) revert InvalidAddress(); + if (address(_swapERC20) == address(0)) revert AddressInvalid(); swapERC20 = _swapERC20; } } diff --git a/source/delegate/contracts/interfaces/IDelegate.sol b/source/delegate/contracts/interfaces/IDelegate.sol index 49d7327a1..2a2da99d2 100644 --- a/source/delegate/contracts/interfaces/IDelegate.sol +++ b/source/delegate/contracts/interfaces/IDelegate.sol @@ -6,23 +6,15 @@ pragma solidity 0.8.23; interface IDelegate { struct Rule { - address sender; + address senderWallet; address senderToken; - uint256 senderRuleAmount; + uint256 senderAmount; uint256 senderFilledAmount; address signerToken; uint256 signerAmount; - uint256 ruleExpiry; + uint256 expiry; } - error RuleExpired(); - error InvalidAddress(); - error InvalidSenderAmount(); - error InvalidSignerAmount(); - error ManagerInvalid(); - error SenderInvalid(); - error TransferFromFailed(); - event Authorize(address signatory, address signer); event DelegateSwap(uint256 nonce, address signerWallet); event Revoke(address tmp, address signer); @@ -30,22 +22,29 @@ interface IDelegate { event SetRule( address senderWallet, address senderToken, - uint256 senderRuleAmount, - uint256 senderFilledAmount, + uint256 senderAmount, address signerToken, uint256 signerAmount, - uint256 ruleExpiry + uint256 expiry ); event UnsetRule(address signer, address signerToken, address senderToken); + error AddressInvalid(); + error RuleExpired(); + error SenderAmountInvalid(); + error SignerAmountInvalid(); + error SenderInvalid(); + error ManagerInvalid(); + error TransferFromFailed(); + function setRule( address sender, address senderToken, - uint256 senderRuleAmount, + uint256 senderAmount, address signerToken, uint256 signerAmount, - uint256 ruleExpiry + uint256 expiry ) external; function swap( diff --git a/source/delegate/deploys-blocks.js.d.ts b/source/delegate/deploys-blocks.js.d.ts new file mode 100644 index 000000000..71bf3bd4b --- /dev/null +++ b/source/delegate/deploys-blocks.js.d.ts @@ -0,0 +1 @@ +declare module '@airswap/delegate/deploys-blocks.js' diff --git a/source/delegate/deploys.js.d.ts b/source/delegate/deploys.js.d.ts index dff926ba4..d73edcc6e 100644 --- a/source/delegate/deploys.js.d.ts +++ b/source/delegate/deploys.js.d.ts @@ -1,2 +1 @@ declare module '@airswap/delegate/deploys.js' -declare module '@airswap/delegate/deploys-blocks.js' diff --git a/source/delegate/package.json b/source/delegate/package.json index 384b42a0e..84549d31b 100644 --- a/source/delegate/package.json +++ b/source/delegate/package.json @@ -1,7 +1,7 @@ { "name": "@airswap/delegate", "version": "4.3.0-beta.0", - "description": "AirSwap: Delegate On-chain Trading Rules", + "description": "AirSwap: Delegated On-chain Trading Rules", "license": "MIT", "repository": { "type": "git", @@ -22,10 +22,8 @@ "test": "hardhat test", "test:ci": "hardhat test", "deploy": "hardhat run ./scripts/deploy.js", - "verify": "hardhat run ./scripts/verify.js", "owners": "hardhat run ./scripts/owner.js", - "migrate": "hardhat run ./scripts/migrate.js", - "balances": "hardhat run ./scripts/balances.js" + "verify": "hardhat run ./scripts/verify.js" }, "devDependencies": { "@airswap/utils": "4.3.3", diff --git a/source/delegate/test/Delegate.js b/source/delegate/test/Delegate.js index a00dddeeb..cc0109d50 100644 --- a/source/delegate/test/Delegate.js +++ b/source/delegate/test/Delegate.js @@ -169,7 +169,6 @@ describe('Delegate Unit', () => { sender.address, senderToken.address, DEFAULT_SENDER_AMOUNT, - 0, signerToken.address, DEFAULT_SIGNER_AMOUNT, RULE_EXPIRY @@ -205,7 +204,6 @@ describe('Delegate Unit', () => { sender.address, senderToken.address, DEFAULT_SENDER_AMOUNT, - 0, signerToken.address, DEFAULT_SIGNER_AMOUNT, RULE_EXPIRY @@ -252,7 +250,7 @@ describe('Delegate Unit', () => { signerToken.address ) - expect(rule.senderRuleAmount.toString()).to.equal(DEFAULT_SENDER_AMOUNT) + expect(rule.senderAmount.toString()).to.equal(DEFAULT_SENDER_AMOUNT) }) it('unsetting a Rule updates the rule balance', async () => { @@ -283,7 +281,7 @@ describe('Delegate Unit', () => { signerToken.address ) - expect(rule.senderRuleAmount.toString()).to.equal('0') + expect(rule.senderAmount.toString()).to.equal('0') }) }) @@ -413,7 +411,7 @@ describe('Delegate Unit', () => { await expect( delegate.connect(signer).swap(sender.address, ...order) - ).to.be.revertedWith('InvalidSenderAmount') + ).to.be.revertedWith('SenderAmountInvalid') }) it('fails to swap with insufficient signer amount on Rule', async () => { @@ -453,7 +451,7 @@ describe('Delegate Unit', () => { await expect( delegate.connect(signer).swap(sender.address, ...order) - ).to.be.revertedWith('InvalidSignerAmount') + ).to.be.revertedWith('SignerAmountInvalid') }) it('fails to swap with a rule expired', async () => { diff --git a/source/swap-erc20/contracts/SwapERC20.sol b/source/swap-erc20/contracts/SwapERC20.sol index 4b8720297..a201838f6 100644 --- a/source/swap-erc20/contracts/SwapERC20.sol +++ b/source/swap-erc20/contracts/SwapERC20.sol @@ -15,7 +15,6 @@ import "./interfaces/ISwapERC20.sol"; * @notice https://www.airswap.io/ */ contract SwapERC20 is ISwapERC20, Ownable, EIP712 { - uint256 public immutable DOMAIN_CHAIN_ID; bytes32 public immutable DOMAIN_SEPARATOR; bytes32 public constant ORDER_TYPEHASH = @@ -27,7 +26,7 @@ contract SwapERC20 is ISwapERC20, Ownable, EIP712 { ); uint256 public constant FEE_DIVISOR = 10000; - uint256 private constant MAX_ERROR_COUNT = 8; + uint256 private constant MAX_ERROR_COUNT = 7; uint256 private constant MAX_MAX = 100; uint256 private constant MAX_SCALE = 77; @@ -63,15 +62,14 @@ contract SwapERC20 is ISwapERC20, Ownable, EIP712 { uint256 _bonusScale, uint256 _bonusMax ) { - if (_protocolFee >= FEE_DIVISOR) revert InvalidFee(); - if (_protocolFeeLight >= FEE_DIVISOR) revert InvalidFeeLight(); - if (_protocolFeeWallet == address(0)) revert InvalidFeeWallet(); + if (_protocolFee >= FEE_DIVISOR) revert ProtocolFeeInvalid(); + if (_protocolFeeLight >= FEE_DIVISOR) revert ProtocolFeeLightInvalid(); + if (_protocolFeeWallet == address(0)) revert ProtocolFeeWalletInvalid(); if (_bonusMax > MAX_MAX) revert MaxTooHigh(); if (_bonusScale > MAX_SCALE) revert ScaleTooHigh(); _initializeOwner(msg.sender); - DOMAIN_CHAIN_ID = block.chainid; DOMAIN_SEPARATOR = _domainSeparator(); protocolFee = _protocolFee; @@ -257,23 +255,19 @@ contract SwapERC20 is ISwapERC20, Ownable, EIP712 { // Recover the signatory from the hash and signature address signatory = ECDSA.tryRecover( - keccak256( - abi.encodePacked( - "\x19\x01", // EIP191: Indicates EIP712 - DOMAIN_SEPARATOR, - keccak256( - abi.encode( - ORDER_TYPEHASH, - nonce, - expiry, - signerWallet, - signerToken, - signerAmount, - protocolFeeLight, - msg.sender, - senderToken, - senderAmount - ) + _hashTypedData( + keccak256( + abi.encode( + ORDER_TYPEHASH, + nonce, + expiry, + signerWallet, + signerToken, + signerAmount, + protocolFeeLight, + msg.sender, + senderToken, + senderAmount ) ) ), @@ -330,7 +324,7 @@ contract SwapERC20 is ISwapERC20, Ownable, EIP712 { */ function setProtocolFee(uint256 _protocolFee) external onlyOwner { // Ensure the fee is less than divisor - if (_protocolFee >= FEE_DIVISOR) revert InvalidFee(); + if (_protocolFee >= FEE_DIVISOR) revert ProtocolFeeInvalid(); protocolFee = _protocolFee; emit SetProtocolFee(_protocolFee); } @@ -341,7 +335,7 @@ contract SwapERC20 is ISwapERC20, Ownable, EIP712 { */ function setProtocolFeeLight(uint256 _protocolFeeLight) external onlyOwner { // Ensure the fee is less than divisor - if (_protocolFeeLight >= FEE_DIVISOR) revert InvalidFeeLight(); + if (_protocolFeeLight >= FEE_DIVISOR) revert ProtocolFeeLightInvalid(); protocolFeeLight = _protocolFeeLight; emit SetProtocolFeeLight(_protocolFeeLight); } @@ -352,7 +346,7 @@ contract SwapERC20 is ISwapERC20, Ownable, EIP712 { */ function setProtocolFeeWallet(address _protocolFeeWallet) external onlyOwner { // Ensure the new fee wallet is not null - if (_protocolFeeWallet == address(0)) revert InvalidFeeWallet(); + if (_protocolFeeWallet == address(0)) revert ProtocolFeeWalletInvalid(); protocolFeeWallet = _protocolFeeWallet; emit SetProtocolFeeWallet(_protocolFeeWallet); } @@ -385,7 +379,7 @@ contract SwapERC20 is ISwapERC20, Ownable, EIP712 { */ function setStaking(address _stakingToken) external onlyOwner { // Ensure the new staking token is not null - if (_stakingToken == address(0)) revert InvalidStaking(); + if (_stakingToken == address(0)) revert StakingInvalid(); stakingToken = _stakingToken; emit SetStaking(_stakingToken); } @@ -474,10 +468,6 @@ contract SwapERC20 is ISwapERC20, Ownable, EIP712 { order.s = s; order.senderWallet = senderWallet; - if (DOMAIN_CHAIN_ID != block.chainid) { - errors[count++] = "ChainIdChanged"; - } - // Validate as the authorized signatory if set address signatory = order.signerWallet; if (authorized[signatory] != address(0)) { @@ -655,9 +645,6 @@ contract SwapERC20 is ISwapERC20, Ownable, EIP712 { bytes32 r, bytes32 s ) private { - // Ensure execution on the intended chain - if (DOMAIN_CHAIN_ID != block.chainid) revert ChainIdChanged(); - // Ensure the expiry is not passed if (expiry <= block.timestamp) revert OrderExpired(); @@ -711,23 +698,19 @@ contract SwapERC20 is ISwapERC20, Ownable, EIP712 { uint256 senderAmount ) private view returns (bytes32) { return - keccak256( - abi.encodePacked( - "\x19\x01", // EIP191: Indicates EIP712 - DOMAIN_SEPARATOR, - keccak256( - abi.encode( - ORDER_TYPEHASH, - nonce, - expiry, - signerWallet, - signerToken, - signerAmount, - protocolFee, - senderWallet, - senderToken, - senderAmount - ) + _hashTypedData( + keccak256( + abi.encode( + ORDER_TYPEHASH, + nonce, + expiry, + signerWallet, + signerToken, + signerAmount, + protocolFee, + senderWallet, + senderToken, + senderAmount ) ) ); diff --git a/source/swap-erc20/contracts/interfaces/ISwapERC20.sol b/source/swap-erc20/contracts/interfaces/ISwapERC20.sol index 70a62308f..bc8722b50 100644 --- a/source/swap-erc20/contracts/interfaces/ISwapERC20.sol +++ b/source/swap-erc20/contracts/interfaces/ISwapERC20.sol @@ -28,17 +28,16 @@ interface ISwapERC20 { event SetBonusMax(uint256 bonusMax); event SetStaking(address indexed staking); - error ChainIdChanged(); - error InvalidFee(); - error InvalidFeeLight(); - error InvalidFeeWallet(); - error InvalidStaking(); - error OrderExpired(); error MaxTooHigh(); error NonceAlreadyUsed(uint256); + error OrderExpired(); + error ProtocolFeeInvalid(); + error ProtocolFeeLightInvalid(); + error ProtocolFeeWalletInvalid(); error ScaleTooHigh(); error SignatoryInvalid(); error SignatureInvalid(); + error StakingInvalid(); error TransferFromFailed(); function swap( diff --git a/source/swap-erc20/test/SwapERC20.js b/source/swap-erc20/test/SwapERC20.js index e0084068b..d92f60e70 100644 --- a/source/swap-erc20/test/SwapERC20.js +++ b/source/swap-erc20/test/SwapERC20.js @@ -180,7 +180,7 @@ describe('SwapERC20 Unit', () => { BONUS_SCALE, BONUS_MAX ) - ).to.be.revertedWith('InvalidFeeWallet') + ).to.be.revertedWith('ProtocolFeeWalletInvalid') }) it('test invalid fee', async () => { @@ -194,7 +194,7 @@ describe('SwapERC20 Unit', () => { BONUS_SCALE, BONUS_MAX ) - ).to.be.revertedWith('InvalidFee') + ).to.be.revertedWith('ProtocolFeeInvalid') }) it('test invalid fee light', async () => { @@ -208,7 +208,7 @@ describe('SwapERC20 Unit', () => { BONUS_SCALE, BONUS_MAX ) - ).to.be.revertedWith('InvalidFeeLight') + ).to.be.revertedWith('ProtocolFeeLightInvalid') }) it('test invalid bonus scale', async () => { @@ -250,7 +250,7 @@ describe('SwapERC20 Unit', () => { it('test setProtocolFee with invalid input', async () => { await expect( swap.connect(deployer).setProtocolFee(FEE_DIVISOR) - ).to.be.revertedWith('InvalidFee') + ).to.be.revertedWith('ProtocolFeeInvalid') }) it('test setProtocolFee as non-owner', async () => { await expect( @@ -265,7 +265,7 @@ describe('SwapERC20 Unit', () => { it('test setProtocolFeeLight with invalid input', async () => { await expect( swap.connect(deployer).setProtocolFeeLight(FEE_DIVISOR) - ).to.be.revertedWith('InvalidFeeLight') + ).to.be.revertedWith('ProtocolFeeLightInvalid') }) it('test setProtocolFeeLight as non-owner', async () => { await expect( @@ -318,7 +318,7 @@ describe('SwapERC20 Unit', () => { it('test setStaking with zero address', async () => { await expect( swap.connect(deployer).setStaking(ADDRESS_ZERO) - ).to.be.revertedWith('InvalidStaking') + ).to.be.revertedWith('StakingInvalid') }) }) @@ -688,7 +688,7 @@ describe('SwapERC20 Unit', () => { it('test invalid fee wallet', async () => { await expect( swap.connect(deployer).setProtocolFeeWallet(ADDRESS_ZERO) - ).to.be.revertedWith('InvalidFeeWallet') + ).to.be.revertedWith('ProtocolFeeWalletInvalid') }) it('test changing fee', async () => { @@ -721,7 +721,7 @@ describe('SwapERC20 Unit', () => { it('test invalid fee', async () => { await expect( swap.connect(deployer).setProtocolFee(FEE_DIVISOR + 1) - ).to.be.revertedWith('InvalidFee') + ).to.be.revertedWith('ProtocolFeeInvalid') }) it('test when signed with incorrect fee', async () => { diff --git a/source/swap/contracts/Swap.sol b/source/swap/contracts/Swap.sol index b2b136d1b..86f432981 100644 --- a/source/swap/contracts/Swap.sol +++ b/source/swap/contracts/Swap.sol @@ -28,11 +28,10 @@ contract Swap is ISwap, Ownable2Step, EIP712 { // Domain name and version for use in EIP712 signatures string public constant DOMAIN_NAME = "SWAP"; string public constant DOMAIN_VERSION = "4.2"; - uint256 public immutable DOMAIN_CHAIN_ID; bytes32 public immutable DOMAIN_SEPARATOR; uint256 public constant FEE_DIVISOR = 10000; - uint256 private constant MAX_ERROR_COUNT = 16; + uint256 private constant MAX_ERROR_COUNT = 15; /** * @notice Double mapping of signers to nonce groups to nonce states @@ -71,7 +70,6 @@ contract Swap is ISwap, Ownable2Step, EIP712 { if (_protocolFeeWallet == address(0)) revert FeeWalletInvalid(); if (_adapters.length == 0) revert AdaptersInvalid(); - DOMAIN_CHAIN_ID = block.chainid; DOMAIN_SEPARATOR = _domainSeparatorV4(); uint256 adaptersLength = _adapters.length; @@ -268,10 +266,6 @@ contract Swap is ISwap, Ownable2Step, EIP712 { bytes32[] memory errors = new bytes32[](MAX_ERROR_COUNT); uint256 count; - if (DOMAIN_CHAIN_ID != block.chainid) { - errors[count++] = "ChainIdChanged"; - } - // Validate as the authorized signatory if set address signatory = order.signer.wallet; if (authorized[signatory] != address(0)) { @@ -423,9 +417,6 @@ contract Swap is ISwap, Ownable2Step, EIP712 { * @param order Order to validate */ function _check(Order calldata order) private { - // Ensure execution on the intended chain - if (DOMAIN_CHAIN_ID != block.chainid) revert ChainIdChanged(); - // Ensure the sender token is the required kind if (order.sender.kind != requiredSenderKind) revert SenderTokenInvalid(); @@ -466,21 +457,17 @@ contract Swap is ISwap, Ownable2Step, EIP712 { */ function _getOrderHash(Order calldata order) private view returns (bytes32) { return - keccak256( - abi.encodePacked( - "\x19\x01", // EIP191: Indicates EIP712 - DOMAIN_SEPARATOR, - keccak256( - abi.encode( - ORDER_TYPEHASH, - order.nonce, - order.expiry, - protocolFee, - keccak256(abi.encode(PARTY_TYPEHASH, order.signer)), - keccak256(abi.encode(PARTY_TYPEHASH, order.sender)), - order.affiliateWallet, - order.affiliateAmount - ) + _hashTypedDataV4( + keccak256( + abi.encode( + ORDER_TYPEHASH, + order.nonce, + order.expiry, + protocolFee, + keccak256(abi.encode(PARTY_TYPEHASH, order.signer)), + keccak256(abi.encode(PARTY_TYPEHASH, order.sender)), + order.affiliateWallet, + order.affiliateAmount ) ) ); diff --git a/source/swap/contracts/interfaces/ISwap.sol b/source/swap/contracts/interfaces/ISwap.sol index 27a7888bd..c123d1de6 100644 --- a/source/swap/contracts/interfaces/ISwap.sol +++ b/source/swap/contracts/interfaces/ISwap.sol @@ -36,7 +36,6 @@ interface ISwap { event Authorize(address indexed signer, address indexed signerWallet); event Revoke(address indexed signer, address indexed signerWallet); - error ChainIdChanged(); error AdaptersInvalid(); error FeeInvalid(); error FeeWalletInvalid();