From cf58acea33d4596167c5aa6ca4b12ab588099df0 Mon Sep 17 00:00:00 2001 From: don mosites Date: Wed, 28 Aug 2024 18:00:17 +0200 Subject: [PATCH 1/2] Delegate and SwapERC20 Finalizations (#1322) * Use of hashTypeData for code clarity and check chain ID (#1318) * publish libraries 4.2.1-beta.0 * Removed redundant chain ID checks * Removed unused error and reduced max_error count by one * Removed unused error from swap and reduced MAX_ERROR by 1 --------- Co-authored-by: don mosites * naming, comments, adjustments * Updated NatSpec --------- Co-authored-by: Smartcontrart <100962328+smartcontrart@users.noreply.github.com> Co-authored-by: Smart Contrart --- source/delegate/contracts/Delegate.sol | 93 ++++++++++++------- .../contracts/interfaces/IDelegate.sol | 31 +++---- source/delegate/deploys-blocks.js.d.ts | 1 + source/delegate/deploys.js.d.ts | 1 - source/delegate/package.json | 6 +- source/delegate/test/Delegate.js | 10 +- source/swap-erc20/contracts/SwapERC20.sol | 14 +-- .../contracts/interfaces/ISwapERC20.sol | 10 +- source/swap-erc20/test/SwapERC20.js | 16 ++-- 9 files changed, 102 insertions(+), 80 deletions(-) create mode 100644 source/delegate/deploys-blocks.js.d.ts 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 7da818c58..a201838f6 100644 --- a/source/swap-erc20/contracts/SwapERC20.sol +++ b/source/swap-erc20/contracts/SwapERC20.sol @@ -62,9 +62,9 @@ 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(); @@ -324,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); } @@ -335,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); } @@ -346,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); } @@ -379,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); } diff --git a/source/swap-erc20/contracts/interfaces/ISwapERC20.sol b/source/swap-erc20/contracts/interfaces/ISwapERC20.sol index 7ce4cbbff..bc8722b50 100644 --- a/source/swap-erc20/contracts/interfaces/ISwapERC20.sol +++ b/source/swap-erc20/contracts/interfaces/ISwapERC20.sol @@ -28,16 +28,16 @@ interface ISwapERC20 { event SetBonusMax(uint256 bonusMax); event SetStaking(address indexed staking); - 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 () => { From b8243ac48f43593772c385a39aeccbb33721fba9 Mon Sep 17 00:00:00 2001 From: Smartcontrart <100962328+smartcontrart@users.noreply.github.com> Date: Wed, 4 Sep 2024 11:06:16 -0400 Subject: [PATCH 2/2] Delegate tests coverage (#1326) * Scripts enhancements (#1321) * Added checks to validate target deployment address matches mainnet * Added storing of commit hashes upon deployment to track deployed code * Created script to populate the latest deploy commits * Renamed deploy commits script for clarity * Updated module declarations * Removed script to populate hashes * prompt language update --------- Co-authored-by: Don Mosites * Bump micromatch from 4.0.5 to 4.0.8 (#1323) Bumps [micromatch](https://github.com/micromatch/micromatch) from 4.0.5 to 4.0.8. - [Release notes](https://github.com/micromatch/micromatch/releases) - [Changelog](https://github.com/micromatch/micromatch/blob/master/CHANGELOG.md) - [Commits](https://github.com/micromatch/micromatch/compare/4.0.5...4.0.8) --- updated-dependencies: - dependency-name: micromatch dependency-type: indirect ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump axios from 1.6.7 to 1.7.7 (#1324) Bumps [axios](https://github.com/axios/axios) from 1.6.7 to 1.7.7. - [Release notes](https://github.com/axios/axios/releases) - [Changelog](https://github.com/axios/axios/blob/v1.x/CHANGELOG.md) - [Commits](https://github.com/axios/axios/compare/v1.6.7...v1.7.7) --- updated-dependencies: - dependency-name: axios dependency-type: indirect ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Increased Delegate test coverage to 100% --------- Signed-off-by: dependabot[bot] Co-authored-by: Don Mosites Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- source/batch-call/deploys-commits.js | 19 +++++ source/batch-call/deploys-commits.js.d.ts | 1 + source/batch-call/scripts/deploy.js | 35 ++++++++- source/delegate/deploys-commits.js | 3 + source/delegate/deploys-commits.js.d.ts | 1 + source/delegate/scripts/deploy.js | 20 ++++- source/delegate/test/Delegate.js | 79 ++++++++++++++++++++ source/pool/deploys-commits.js | 22 ++++++ source/pool/deploys-commits.js.d.ts | 1 + source/pool/scripts/deploy.js | 20 ++++- source/registry/deploys-commits.js | 19 +++++ source/registry/deploys-commits.js.d.ts | 1 + source/registry/scripts/deploy.js | 20 ++++- source/staking/deploys-commits.js | 5 ++ source/staking/deploys-commits.js.d.ts | 1 + source/staking/scripts/deploy.js | 20 ++++- source/swap-erc20/deploys-commits.js | 17 +++++ source/swap-erc20/deploys-commits.js.d.ts | 1 + source/swap-erc20/scripts/deploy.js | 20 ++++- source/swap/deploys-adapters-commits.js | 1 + source/swap/deploys-adapters-commits.js.d.ts | 1 + source/swap/deploys-commits.js | 19 +++++ source/swap/deploys-commits.js.d.ts | 1 + source/swap/scripts/deploy-adapters.js | 21 +++++- source/swap/scripts/deploy.js | 20 ++++- source/wrapper/deploys-commits.js | 21 ++++++ source/wrapper/deploys-commits.js.d.ts | 1 + source/wrapper/scripts/deploy.js | 21 +++++- yarn.lock | 20 ++--- 29 files changed, 409 insertions(+), 22 deletions(-) create mode 100644 source/batch-call/deploys-commits.js create mode 100644 source/batch-call/deploys-commits.js.d.ts create mode 100644 source/delegate/deploys-commits.js create mode 100644 source/delegate/deploys-commits.js.d.ts create mode 100644 source/pool/deploys-commits.js create mode 100644 source/pool/deploys-commits.js.d.ts create mode 100644 source/registry/deploys-commits.js create mode 100644 source/registry/deploys-commits.js.d.ts create mode 100644 source/staking/deploys-commits.js create mode 100644 source/staking/deploys-commits.js.d.ts create mode 100644 source/swap-erc20/deploys-commits.js create mode 100644 source/swap-erc20/deploys-commits.js.d.ts create mode 100644 source/swap/deploys-adapters-commits.js create mode 100644 source/swap/deploys-adapters-commits.js.d.ts create mode 100644 source/swap/deploys-commits.js create mode 100644 source/swap/deploys-commits.js.d.ts create mode 100644 source/wrapper/deploys-commits.js create mode 100644 source/wrapper/deploys-commits.js.d.ts diff --git a/source/batch-call/deploys-commits.js b/source/batch-call/deploys-commits.js new file mode 100644 index 000000000..039485113 --- /dev/null +++ b/source/batch-call/deploys-commits.js @@ -0,0 +1,19 @@ +module.exports = { + 1: '863586ae7594b5088619f243dbee83c8d8e0075f', + 31: '863586ae7594b5088619f243dbee83c8d8e0075f', + 41: '863586ae7594b5088619f243dbee83c8d8e0075f', + 56: '863586ae7594b5088619f243dbee83c8d8e0075f', + 97: '863586ae7594b5088619f243dbee83c8d8e0075f', + 137: '863586ae7594b5088619f243dbee83c8d8e0075f', + 8453: '863586ae7594b5088619f243dbee83c8d8e0075f', + 17000: '863586ae7594b5088619f243dbee83c8d8e0075f', + 42161: '863586ae7594b5088619f243dbee83c8d8e0075f', + 43113: '863586ae7594b5088619f243dbee83c8d8e0075f', + 43114: '863586ae7594b5088619f243dbee83c8d8e0075f', + 59140: '863586ae7594b5088619f243dbee83c8d8e0075f', + 59144: '863586ae7594b5088619f243dbee83c8d8e0075f', + 80001: '863586ae7594b5088619f243dbee83c8d8e0075f', + 84532: '863586ae7594b5088619f243dbee83c8d8e0075f', + 421614: '863586ae7594b5088619f243dbee83c8d8e0075f', + 11155111: '863586ae7594b5088619f243dbee83c8d8e0075f', +} diff --git a/source/batch-call/deploys-commits.js.d.ts b/source/batch-call/deploys-commits.js.d.ts new file mode 100644 index 000000000..cc21f2ea2 --- /dev/null +++ b/source/batch-call/deploys-commits.js.d.ts @@ -0,0 +1 @@ +declare module '@airswap/batch-call/deploys-commits.js' diff --git a/source/batch-call/scripts/deploy.js b/source/batch-call/scripts/deploy.js index e53a39435..50479604d 100644 --- a/source/batch-call/scripts/deploy.js +++ b/source/batch-call/scripts/deploy.js @@ -7,6 +7,7 @@ const { ChainIds, chainLabels } = require('@airswap/utils') const { getReceiptUrl } = require('@airswap/utils') const batchCallDeploys = require('../deploys.js') const batchCallBlocks = require('../deploys-blocks.js') +const batchCallCommits = require('../deploys-commits.js') const { displayDeployerInfo } = require('../../../scripts/deployer-info') async function main() { @@ -18,9 +19,13 @@ async function main() { console.log('Value for --network flag is required') return } - await displayDeployerInfo(deployer) - - const prompt = new Confirm('Proceed to deploy?') + const targetAddress = await displayDeployerInfo(deployer) + const mainnetAddress = batchCallDeploys['1'] + const prompt = new Confirm( + targetAddress === mainnetAddress + ? 'Proceed to deploy?' + : 'Contract address would not match current mainnet address. Proceed anyway?' + ) if (await prompt.run()) { const batchFactory = await ethers.getContractFactory('BatchCall') const batchCallContract = await batchFactory.deploy() @@ -48,6 +53,30 @@ async function main() { { ...prettierConfig, parser: 'babel' } ) ) + + batchCallBlocks[chainId] = ( + await batchCallContract.deployTransaction.wait() + ).blockNumber + fs.writeFileSync( + './deploys-blocks.js', + prettier.format( + `module.exports = ${JSON.stringify(batchCallBlocks, null, '\t')}`, + { ...prettierConfig, parser: 'babel' } + ) + ) + + batchCallCommits[chainId] = require('child_process') + .execSync('git rev-parse HEAD') + .toString() + .trim() + fs.writeFileSync( + './deploys-commits.js', + prettier.format( + `module.exports = ${JSON.stringify(batchCallCommits, null, '\t')}`, + { ...prettierConfig, parser: 'babel' } + ) + ) + console.log( `Deployed: ${batchCallDeploys[chainId]} @ ${batchCallBlocks[chainId]}` ) diff --git a/source/delegate/deploys-commits.js b/source/delegate/deploys-commits.js new file mode 100644 index 000000000..c66486716 --- /dev/null +++ b/source/delegate/deploys-commits.js @@ -0,0 +1,3 @@ +module.exports = { + 11155111: 'da05cb9528630f4f2e15ce3f9093b0f944bec1b7', +} diff --git a/source/delegate/deploys-commits.js.d.ts b/source/delegate/deploys-commits.js.d.ts new file mode 100644 index 000000000..c530602c2 --- /dev/null +++ b/source/delegate/deploys-commits.js.d.ts @@ -0,0 +1 @@ +declare module '@airswap/delegate/deploys-commits.js' diff --git a/source/delegate/scripts/deploy.js b/source/delegate/scripts/deploy.js index a9464f620..0b7b10097 100644 --- a/source/delegate/scripts/deploy.js +++ b/source/delegate/scripts/deploy.js @@ -8,6 +8,7 @@ const { ChainIds, chainLabels } = require('@airswap/utils') const { getReceiptUrl } = require('@airswap/utils') const delegateDeploys = require('../deploys.js') const delegateBlocks = require('../deploys-blocks.js') +const delegateCommits = require('../deploys-commits.js') const { displayDeployerInfo } = require('../../../scripts/deployer-info') async function main() { @@ -23,7 +24,13 @@ async function main() { console.log(`swapERC20Contract: ${swapERC20Deploys[chainId]}\n`) - const prompt = new Confirm('Proceed to deploy?') + const targetAddress = await displayDeployerInfo(deployer) + const mainnetAddress = delegateDeploys['1'] + const prompt = new Confirm( + targetAddress === mainnetAddress + ? 'Proceed to deploy?' + : 'Contract address would not match current mainnet address. Proceed anyway?' + ) if (await prompt.run()) { const delegateFactory = await ethers.getContractFactory('Delegate') const delegateContract = await delegateFactory.deploy( @@ -53,6 +60,17 @@ async function main() { { ...prettierConfig, parser: 'babel' } ) ) + delegateCommits[chainId] = require('child_process') + .execSync('git rev-parse HEAD') + .toString() + .trim() + fs.writeFileSync( + './deploys-commits.js', + prettier.format( + `module.exports = ${JSON.stringify(delegateCommits, null, '\t')}`, + { ...prettierConfig, parser: 'babel' } + ) + ) console.log( `Deployed: ${delegateDeploys[chainId]} @ ${delegateBlocks[chainId]}` ) diff --git a/source/delegate/test/Delegate.js b/source/delegate/test/Delegate.js index cc0109d50..91c2f7d04 100644 --- a/source/delegate/test/Delegate.js +++ b/source/delegate/test/Delegate.js @@ -143,6 +143,12 @@ describe('Delegate Unit', () => { expect(await delegate.swapERC20()).to.equal(UPDATE_SWAP_ERC20_ADDRESS) }) + it('the swapERC20Contract address cannot be address(0)', async () => { + await expect( + delegate.setSwapERC20Contract(ADDRESS_ZERO) + ).to.be.revertedWith('InvalidAddress') + }) + it('only the owner can set the swapERC20Contract address', async () => { await expect( delegate.connect(anyone).setSwapERC20Contract(UPDATE_SWAP_ERC20_ADDRESS) @@ -210,6 +216,37 @@ describe('Delegate Unit', () => { ) }) + it('an unauthorized manager cannot set a rule', async () => { + await delegate.connect(sender).authorize(manager.address) + await expect( + delegate + .connect(signer) + .setRule( + sender.address, + senderToken.address, + DEFAULT_SENDER_AMOUNT, + signerToken.address, + DEFAULT_SIGNER_AMOUNT, + RULE_EXPIRY + ) + ).to.be.revertedWith('SenderInvalid') + }) + + it('a manager cannot set a rule without prior authorization', async () => { + await expect( + delegate + .connect(manager) + .setRule( + sender.address, + senderToken.address, + DEFAULT_SENDER_AMOUNT, + signerToken.address, + DEFAULT_SIGNER_AMOUNT, + RULE_EXPIRY + ) + ).to.be.revertedWith('SenderInvalid') + }) + it('a manager can unset a Rule', async () => { await delegate.connect(sender).authorize(manager.address) await delegate @@ -232,6 +269,48 @@ describe('Delegate Unit', () => { .withArgs(sender.address, senderToken.address, signerToken.address) }) + it('an unauthorized manager cannot unset a rule', async () => { + await delegate.connect(sender).authorize(manager.address) + await delegate + .connect(manager) + .setRule( + sender.address, + senderToken.address, + DEFAULT_SENDER_AMOUNT, + signerToken.address, + DEFAULT_SIGNER_AMOUNT, + RULE_EXPIRY + ) + + await expect( + delegate + .connect(signer) + .unsetRule(sender.address, senderToken.address, signerToken.address) + ).to.be.revertedWith('SenderInvalid') + }) + + it('a revoked manager cannot unset a rule', async () => { + await delegate.connect(sender).authorize(manager.address) + await delegate + .connect(manager) + .setRule( + sender.address, + senderToken.address, + DEFAULT_SENDER_AMOUNT, + signerToken.address, + DEFAULT_SIGNER_AMOUNT, + RULE_EXPIRY + ) + + await delegate.connect(sender).revoke() + + await expect( + delegate + .connect(manager) + .unsetRule(sender.address, senderToken.address, signerToken.address) + ).to.be.revertedWith('SenderInvalid') + }) + it('setting a Rule updates the rule balance', async () => { await delegate .connect(sender) diff --git a/source/pool/deploys-commits.js b/source/pool/deploys-commits.js new file mode 100644 index 000000000..5cd4eeb77 --- /dev/null +++ b/source/pool/deploys-commits.js @@ -0,0 +1,22 @@ +module.exports = { + 1: 'a535d0bb280fdb603a903dd2ae94e6b27d66b3d4', + 5: 'a535d0bb280fdb603a903dd2ae94e6b27d66b3d4', + 30: 'a535d0bb280fdb603a903dd2ae94e6b27d66b3d4', + 31: 'a535d0bb280fdb603a903dd2ae94e6b27d66b3d4', + 40: 'a535d0bb280fdb603a903dd2ae94e6b27d66b3d4', + 41: 'a535d0bb280fdb603a903dd2ae94e6b27d66b3d4', + 56: 'a535d0bb280fdb603a903dd2ae94e6b27d66b3d4', + 97: 'a535d0bb280fdb603a903dd2ae94e6b27d66b3d4', + 137: 'a535d0bb280fdb603a903dd2ae94e6b27d66b3d4', + 8453: 'a535d0bb280fdb603a903dd2ae94e6b27d66b3d4', + 17000: 'a535d0bb280fdb603a903dd2ae94e6b27d66b3d4', + 42161: 'a535d0bb280fdb603a903dd2ae94e6b27d66b3d4', + 43113: 'a535d0bb280fdb603a903dd2ae94e6b27d66b3d4', + 43114: 'a535d0bb280fdb603a903dd2ae94e6b27d66b3d4', + 59140: 'a535d0bb280fdb603a903dd2ae94e6b27d66b3d4', + 59144: 'a535d0bb280fdb603a903dd2ae94e6b27d66b3d4', + 80001: 'a535d0bb280fdb603a903dd2ae94e6b27d66b3d4', + 84531: 'a535d0bb280fdb603a903dd2ae94e6b27d66b3d4', + 421613: 'a535d0bb280fdb603a903dd2ae94e6b27d66b3d4', + 11155111: 'a535d0bb280fdb603a903dd2ae94e6b27d66b3d4', +} diff --git a/source/pool/deploys-commits.js.d.ts b/source/pool/deploys-commits.js.d.ts new file mode 100644 index 000000000..6ecf5882d --- /dev/null +++ b/source/pool/deploys-commits.js.d.ts @@ -0,0 +1 @@ +declare module '@airswap/pool/deploys-commits.js' diff --git a/source/pool/scripts/deploy.js b/source/pool/scripts/deploy.js index 520e7e6d6..7d9897ba8 100644 --- a/source/pool/scripts/deploy.js +++ b/source/pool/scripts/deploy.js @@ -7,6 +7,7 @@ const { chainLabels, ChainIds } = require('@airswap/utils') const { getReceiptUrl } = require('@airswap/utils') const poolDeploys = require('../deploys.js') const poolBlocks = require('../deploys-blocks.js') +const poolCommits = require('../deploys-commits.js') const { displayDeployerInfo } = require('../../../scripts/deployer-info') async function main() { @@ -26,7 +27,13 @@ async function main() { console.log(`scale: ${scale}`) console.log(`max: ${max}`) - const prompt = new Confirm('Proceed to deploy?') + const targetAddress = await displayDeployerInfo(deployer) + const mainnetAddress = poolDeploys['1'] + const prompt = new Confirm( + targetAddress === mainnetAddress + ? 'Proceed to deploy?' + : 'Contract address would not match current mainnet address. Proceed anyway?' + ) if (await prompt.run()) { const poolFactory = await ethers.getContractFactory('Pool') const poolContract = await poolFactory.deploy(scale, max) @@ -54,6 +61,17 @@ async function main() { { ...prettierConfig, parser: 'babel' } ) ) + poolCommits[chainId] = require('child_process') + .execSync('git rev-parse HEAD') + .toString() + .trim() + fs.writeFileSync( + './deploys-commits.js', + prettier.format( + `module.exports = ${JSON.stringify(poolCommits, null, '\t')}`, + { ...prettierConfig, parser: 'babel' } + ) + ) console.log(`Deployed: ${poolDeploys[chainId]} @ ${poolBlocks[chainId]}`) console.log( diff --git a/source/registry/deploys-commits.js b/source/registry/deploys-commits.js new file mode 100644 index 000000000..039485113 --- /dev/null +++ b/source/registry/deploys-commits.js @@ -0,0 +1,19 @@ +module.exports = { + 1: '863586ae7594b5088619f243dbee83c8d8e0075f', + 31: '863586ae7594b5088619f243dbee83c8d8e0075f', + 41: '863586ae7594b5088619f243dbee83c8d8e0075f', + 56: '863586ae7594b5088619f243dbee83c8d8e0075f', + 97: '863586ae7594b5088619f243dbee83c8d8e0075f', + 137: '863586ae7594b5088619f243dbee83c8d8e0075f', + 8453: '863586ae7594b5088619f243dbee83c8d8e0075f', + 17000: '863586ae7594b5088619f243dbee83c8d8e0075f', + 42161: '863586ae7594b5088619f243dbee83c8d8e0075f', + 43113: '863586ae7594b5088619f243dbee83c8d8e0075f', + 43114: '863586ae7594b5088619f243dbee83c8d8e0075f', + 59140: '863586ae7594b5088619f243dbee83c8d8e0075f', + 59144: '863586ae7594b5088619f243dbee83c8d8e0075f', + 80001: '863586ae7594b5088619f243dbee83c8d8e0075f', + 84532: '863586ae7594b5088619f243dbee83c8d8e0075f', + 421614: '863586ae7594b5088619f243dbee83c8d8e0075f', + 11155111: '863586ae7594b5088619f243dbee83c8d8e0075f', +} diff --git a/source/registry/deploys-commits.js.d.ts b/source/registry/deploys-commits.js.d.ts new file mode 100644 index 000000000..a7ccb3ee2 --- /dev/null +++ b/source/registry/deploys-commits.js.d.ts @@ -0,0 +1 @@ +declare module '@airswap/registry/deploys-commits.js' diff --git a/source/registry/scripts/deploy.js b/source/registry/scripts/deploy.js index 7ef092c20..f4fd9ec20 100644 --- a/source/registry/scripts/deploy.js +++ b/source/registry/scripts/deploy.js @@ -7,6 +7,7 @@ const { ChainIds, chainLabels } = require('@airswap/utils') const { getReceiptUrl } = require('@airswap/utils') const registryDeploys = require('../deploys.js') const registryBlocks = require('../deploys-blocks.js') +const registryCommits = require('../deploys-commits.js') const config = require('./config.js') const { displayDeployerInfo } = require('../../../scripts/deployer-info') @@ -35,7 +36,13 @@ async function main() { console.log(`stakingCost: ${stakingCost}`) console.log(`supportCost: ${supportCost}\n`) - const prompt = new Confirm('Proceed to deploy?') + const targetAddress = await displayDeployerInfo(deployer) + const mainnetAddress = registryDeploys['1'] + const prompt = new Confirm( + targetAddress === mainnetAddress + ? 'Proceed to deploy?' + : 'Contract address would not match current mainnet address. Proceed anyway?' + ) if (await prompt.run()) { const registryFactory = await ethers.getContractFactory('Registry') const registryContract = await registryFactory.deploy( @@ -67,6 +74,17 @@ async function main() { { ...prettierConfig, parser: 'babel' } ) ) + registryCommits[chainId] = require('child_process') + .execSync('git rev-parse HEAD') + .toString() + .trim() + fs.writeFileSync( + './deploys-commits.js', + prettier.format( + `module.exports = ${JSON.stringify(registryCommits, null, '\t')}`, + { ...prettierConfig, parser: 'babel' } + ) + ) console.log( `Deployed: ${registryDeploys[chainId]} @ ${registryBlocks[chainId]}` ) diff --git a/source/staking/deploys-commits.js b/source/staking/deploys-commits.js new file mode 100644 index 000000000..065e5af3d --- /dev/null +++ b/source/staking/deploys-commits.js @@ -0,0 +1,5 @@ +module.exports = { + 1: '6ede424741588b8e3fbb8060cc9ee8d343eac4ab', + 17000: '6ede424741588b8e3fbb8060cc9ee8d343eac4ab', + 11155111: '6ede424741588b8e3fbb8060cc9ee8d343eac4ab', +} diff --git a/source/staking/deploys-commits.js.d.ts b/source/staking/deploys-commits.js.d.ts new file mode 100644 index 000000000..9b529be60 --- /dev/null +++ b/source/staking/deploys-commits.js.d.ts @@ -0,0 +1 @@ +declare module '@airswap/staking/deploys-commits.js' diff --git a/source/staking/scripts/deploy.js b/source/staking/scripts/deploy.js index 60dd798d7..6bac5b329 100644 --- a/source/staking/scripts/deploy.js +++ b/source/staking/scripts/deploy.js @@ -7,6 +7,7 @@ const { chainLabels, ChainIds } = require('@airswap/utils') const { getReceiptUrl } = require('@airswap/utils') const stakingDeploys = require('../deploys.js') const stakingBlocks = require('../deploys-blocks.js') +const stakingCommits = require('../deploys-commits.js') const config = require('./config.js') const { displayDeployerInfo } = require('../../../scripts/deployer-info') @@ -35,7 +36,13 @@ async function main() { console.log(`stakingDuration: ${stakingDuration}`) console.log(`minDurationChangeDelay: ${minDurationChangeDelay}\n`) - const prompt = new Confirm('Proceed to deploy?') + const targetAddress = await displayDeployerInfo(deployer) + const mainnetAddress = stakingDeploys['1'] + const prompt = new Confirm( + targetAddress === mainnetAddress + ? 'Proceed to deploy?' + : 'Contract address would not match current mainnet address. Proceed anyway?' + ) if (await prompt.run()) { const stakingFactory = await ethers.getContractFactory('Staking') const stakingContract = await stakingFactory.deploy( @@ -69,6 +76,17 @@ async function main() { { ...prettierConfig, parser: 'babel' } ) ) + stakingCommits[chainId] = require('child_process') + .execSync('git rev-parse HEAD') + .toString() + .trim() + fs.writeFileSync( + './deploys-commits.js', + prettier.format( + `module.exports = ${JSON.stringify(stakingCommits, null, '\t')}`, + { ...prettierConfig, parser: 'babel' } + ) + ) console.log( `Deployed: ${stakingDeploys[chainId]} @ ${stakingBlocks[chainId]}` ) diff --git a/source/swap-erc20/deploys-commits.js b/source/swap-erc20/deploys-commits.js new file mode 100644 index 000000000..6958ffd06 --- /dev/null +++ b/source/swap-erc20/deploys-commits.js @@ -0,0 +1,17 @@ +module.exports = { + 1: '8870acc9b7241bc6d5bb7a1e094ddb37d2d2a927', + 56: '8870acc9b7241bc6d5bb7a1e094ddb37d2d2a927', + 97: '8870acc9b7241bc6d5bb7a1e094ddb37d2d2a927', + 137: '8870acc9b7241bc6d5bb7a1e094ddb37d2d2a927', + 8453: '8870acc9b7241bc6d5bb7a1e094ddb37d2d2a927', + 17000: '8870acc9b7241bc6d5bb7a1e094ddb37d2d2a927', + 42161: '8870acc9b7241bc6d5bb7a1e094ddb37d2d2a927', + 43113: '8870acc9b7241bc6d5bb7a1e094ddb37d2d2a927', + 43114: '8870acc9b7241bc6d5bb7a1e094ddb37d2d2a927', + 59140: '8870acc9b7241bc6d5bb7a1e094ddb37d2d2a927', + 59144: '8870acc9b7241bc6d5bb7a1e094ddb37d2d2a927', + 80001: '8870acc9b7241bc6d5bb7a1e094ddb37d2d2a927', + 84532: '8870acc9b7241bc6d5bb7a1e094ddb37d2d2a927', + 421614: '8870acc9b7241bc6d5bb7a1e094ddb37d2d2a927', + 11155111: '8870acc9b7241bc6d5bb7a1e094ddb37d2d2a927', +} diff --git a/source/swap-erc20/deploys-commits.js.d.ts b/source/swap-erc20/deploys-commits.js.d.ts new file mode 100644 index 000000000..17f79173d --- /dev/null +++ b/source/swap-erc20/deploys-commits.js.d.ts @@ -0,0 +1 @@ +declare module '@airswap/swap-erc20/deploys-commits.js' diff --git a/source/swap-erc20/scripts/deploy.js b/source/swap-erc20/scripts/deploy.js index 424febabc..e73c1a291 100644 --- a/source/swap-erc20/scripts/deploy.js +++ b/source/swap-erc20/scripts/deploy.js @@ -12,6 +12,7 @@ const { const { getReceiptUrl } = require('@airswap/utils') const swapERC20Deploys = require('../deploys.js') const swapERC20Blocks = require('../deploys-blocks.js') +const swapERC20Commits = require('../deploys-commits.js') const config = require('./config.js') const { displayDeployerInfo } = require('../../../scripts/deployer-info') @@ -47,7 +48,13 @@ async function main() { console.log(`protocolFeeLight: ${protocolFeeLight}`) console.log(`protocolFeeReceiver: ${protocolFeeReceiver}\n`) - const prompt = new Confirm('Proceed to deploy?') + const targetAddress = await displayDeployerInfo(deployer) + const mainnetAddress = swapERC20Deploys['1'] + const prompt = new Confirm( + targetAddress === mainnetAddress + ? 'Proceed to deploy?' + : 'Contract address would not match current mainnet address. Proceed anyway?' + ) if (await prompt.run()) { const swapFactory = await ethers.getContractFactory('SwapERC20') const swapContract = await swapFactory.deploy( @@ -81,6 +88,17 @@ async function main() { { ...prettierConfig, parser: 'babel' } ) ) + swapERC20Commits[chainId] = require('child_process') + .execSync('git rev-parse HEAD') + .toString() + .trim() + fs.writeFileSync( + './deploys-commits.js', + prettier.format( + `module.exports = ${JSON.stringify(swapERC20Commits, null, '\t')}`, + { ...prettierConfig, parser: 'babel' } + ) + ) console.log( `Deployed: ${swapERC20Deploys[chainId]} @ ${swapERC20Blocks[chainId]}` ) diff --git a/source/swap/deploys-adapters-commits.js b/source/swap/deploys-adapters-commits.js new file mode 100644 index 000000000..4ba52ba2c --- /dev/null +++ b/source/swap/deploys-adapters-commits.js @@ -0,0 +1 @@ +module.exports = {} diff --git a/source/swap/deploys-adapters-commits.js.d.ts b/source/swap/deploys-adapters-commits.js.d.ts new file mode 100644 index 000000000..44145ddfd --- /dev/null +++ b/source/swap/deploys-adapters-commits.js.d.ts @@ -0,0 +1 @@ +declare module '@airswap/swap/deploys-commits.js' diff --git a/source/swap/deploys-commits.js b/source/swap/deploys-commits.js new file mode 100644 index 000000000..a419bbde0 --- /dev/null +++ b/source/swap/deploys-commits.js @@ -0,0 +1,19 @@ +module.exports = { + 1: '15fc7c8ac53cf44f1e2d450edabb456d2f2d1ff0', + 31: '15fc7c8ac53cf44f1e2d450edabb456d2f2d1ff0', + 41: '15fc7c8ac53cf44f1e2d450edabb456d2f2d1ff0', + 56: '15fc7c8ac53cf44f1e2d450edabb456d2f2d1ff0', + 97: '15fc7c8ac53cf44f1e2d450edabb456d2f2d1ff0', + 137: '15fc7c8ac53cf44f1e2d450edabb456d2f2d1ff0', + 8453: '15fc7c8ac53cf44f1e2d450edabb456d2f2d1ff0', + 17000: '15fc7c8ac53cf44f1e2d450edabb456d2f2d1ff0', + 42161: '15fc7c8ac53cf44f1e2d450edabb456d2f2d1ff0', + 43113: '15fc7c8ac53cf44f1e2d450edabb456d2f2d1ff0', + 43114: '15fc7c8ac53cf44f1e2d450edabb456d2f2d1ff0', + 59140: '15fc7c8ac53cf44f1e2d450edabb456d2f2d1ff0', + 59144: '15fc7c8ac53cf44f1e2d450edabb456d2f2d1ff0', + 80001: '15fc7c8ac53cf44f1e2d450edabb456d2f2d1ff0', + 84532: '15fc7c8ac53cf44f1e2d450edabb456d2f2d1ff0', + 421614: '15fc7c8ac53cf44f1e2d450edabb456d2f2d1ff0', + 11155111: '15fc7c8ac53cf44f1e2d450edabb456d2f2d1ff0', +} diff --git a/source/swap/deploys-commits.js.d.ts b/source/swap/deploys-commits.js.d.ts new file mode 100644 index 000000000..44145ddfd --- /dev/null +++ b/source/swap/deploys-commits.js.d.ts @@ -0,0 +1 @@ +declare module '@airswap/swap/deploys-commits.js' diff --git a/source/swap/scripts/deploy-adapters.js b/source/swap/scripts/deploy-adapters.js index 832f8446b..cc5289a4f 100644 --- a/source/swap/scripts/deploy-adapters.js +++ b/source/swap/scripts/deploy-adapters.js @@ -7,6 +7,7 @@ const { chainLabels, ChainIds } = require('@airswap/utils') const { getReceiptUrl } = require('@airswap/utils') const adapterDeploys = require('../deploys-adapters.js') const adapterBlocks = require('../deploys-adapters-blocks.js') +const adapterCommits = require('../deploys-adapters-commits.js') const { displayDeployerInfo } = require('../../../scripts/deployer-info') async function main() { @@ -23,7 +24,13 @@ async function main() { const adapters = ['ERC20Adapter', 'ERC721Adapter', 'ERC1155Adapter'] console.log(`adapters: ${JSON.stringify(adapters)}`) - const prompt = new Confirm('Proceed to deploy?') + const targetAddress = await displayDeployerInfo(deployer) + const mainnetAddress = adapterDeploys['1'][0] + const prompt = new Confirm( + targetAddress === mainnetAddress + ? 'Proceed to deploy?' + : 'Contract address would not match current mainnet address. Proceed anyway?' + ) if (await prompt.run()) { const blocks = [] for (let i = 0; i < adapters.length; i++) { @@ -55,7 +62,17 @@ async function main() { { ...prettierConfig, parser: 'babel' } ) ) - + adapterCommits[chainId] = require('child_process') + .execSync('git rev-parse HEAD') + .toString() + .trim() + fs.writeFileSync( + './deploys-adapters-commits.js', + prettier.format( + `module.exports = ${JSON.stringify(adapterCommits, null, '\t')}`, + { ...prettierConfig, parser: 'babel' } + ) + ) console.log( `\nVerify with "yarn verify-adapters --network ${chainLabels[ chainId diff --git a/source/swap/scripts/deploy.js b/source/swap/scripts/deploy.js index b081f69ec..539b2d2ff 100644 --- a/source/swap/scripts/deploy.js +++ b/source/swap/scripts/deploy.js @@ -13,6 +13,7 @@ const { getReceiptUrl } = require('@airswap/utils') const poolDeploys = require('@airswap/pool/deploys.js') const swapDeploys = require('../deploys.js') const swapBlocks = require('../deploys-blocks.js') +const swapCommits = require('../deploys-commits.js') const adapterDeploys = require('../deploys-adapters.js') const config = require('./config.js') const { displayDeployerInfo } = require('../../../scripts/deployer-info') @@ -46,7 +47,13 @@ async function main() { console.log(`protocolFee: ${protocolFee}`) console.log(`protocolFeeReceiver: ${protocolFeeReceiver}`) - const prompt = new Confirm('Proceed to deploy?') + const targetAddress = await displayDeployerInfo(deployer) + const mainnetAddress = swapDeploys['1'] + const prompt = new Confirm( + targetAddress === mainnetAddress + ? 'Proceed to deploy?' + : 'Contract address would not match current mainnet address. Proceed anyway?' + ) if (await prompt.run()) { const swapFactory = await ethers.getContractFactory('Swap') const swapContract = await swapFactory.deploy( @@ -79,6 +86,17 @@ async function main() { { ...prettierConfig, parser: 'babel' } ) ) + swapCommits[chainId] = require('child_process') + .execSync('git rev-parse HEAD') + .toString() + .trim() + fs.writeFileSync( + './deploys-commits.js', + prettier.format( + `module.exports = ${JSON.stringify(swapCommits, null, '\t')}`, + { ...prettierConfig, parser: 'babel' } + ) + ) console.log(`Deployed: ${swapDeploys[chainId]} @ ${swapBlocks[chainId]}`) console.log( diff --git a/source/wrapper/deploys-commits.js b/source/wrapper/deploys-commits.js new file mode 100644 index 000000000..47f637366 --- /dev/null +++ b/source/wrapper/deploys-commits.js @@ -0,0 +1,21 @@ +module.exports = { + 1: 'e2dd551b1684cf2f9e4494386c9e3f6ff614fe4f', + 5: 'e2dd551b1684cf2f9e4494386c9e3f6ff614fe4f', + 30: 'e2dd551b1684cf2f9e4494386c9e3f6ff614fe4f', + 31: 'e2dd551b1684cf2f9e4494386c9e3f6ff614fe4f', + 40: 'e2dd551b1684cf2f9e4494386c9e3f6ff614fe4f', + 41: 'e2dd551b1684cf2f9e4494386c9e3f6ff614fe4f', + 56: 'e2dd551b1684cf2f9e4494386c9e3f6ff614fe4f', + 97: 'e2dd551b1684cf2f9e4494386c9e3f6ff614fe4f', + 137: 'e2dd551b1684cf2f9e4494386c9e3f6ff614fe4f', + 8453: 'e2dd551b1684cf2f9e4494386c9e3f6ff614fe4f', + 17000: 'e2dd551b1684cf2f9e4494386c9e3f6ff614fe4f', + 42161: 'e2dd551b1684cf2f9e4494386c9e3f6ff614fe4f', + 43113: 'e2dd551b1684cf2f9e4494386c9e3f6ff614fe4f', + 43114: 'e2dd551b1684cf2f9e4494386c9e3f6ff614fe4f', + 59140: 'e2dd551b1684cf2f9e4494386c9e3f6ff614fe4f', + 59144: 'e2dd551b1684cf2f9e4494386c9e3f6ff614fe4f', + 80001: 'e2dd551b1684cf2f9e4494386c9e3f6ff614fe4f', + 421613: 'e2dd551b1684cf2f9e4494386c9e3f6ff614fe4f', + 11155111: 'e2dd551b1684cf2f9e4494386c9e3f6ff614fe4f', +} diff --git a/source/wrapper/deploys-commits.js.d.ts b/source/wrapper/deploys-commits.js.d.ts new file mode 100644 index 000000000..54a10ee54 --- /dev/null +++ b/source/wrapper/deploys-commits.js.d.ts @@ -0,0 +1 @@ +declare module '@airswap/wrapper/deploys-commits.js' diff --git a/source/wrapper/scripts/deploy.js b/source/wrapper/scripts/deploy.js index 220eecb38..aa26558fb 100644 --- a/source/wrapper/scripts/deploy.js +++ b/source/wrapper/scripts/deploy.js @@ -6,9 +6,11 @@ const { ethers, run } = require('hardhat') const swapDeploys = require('@airswap/swap-erc20/deploys.js') const wrapperDeploys = require('../deploys.js') const wrapperBlocks = require('../deploys-blocks.js') +const wrapperCommits = require('../deploys-commits.js') const wethDeploys = require('../deploys-weth.js') const { ChainIds, chainNames, chainLabels } = require('@airswap/utils') const { getReceiptUrl } = require('@airswap/utils') +const { displayDeployerInfo } = require('../../../scripts/deployer-info') async function main() { await run('compile') @@ -36,7 +38,13 @@ async function main() { console.log(`SwapERC20: ${swapERC20Address}`) console.log(`Wrapped: ${wrappedTokenAddress}`) - const prompt = new Confirm('Proceed to deploy?') + const targetAddress = await displayDeployerInfo(deployer) + const mainnetAddress = wrapperDeploys['1'] + const prompt = new Confirm( + targetAddress === mainnetAddress + ? 'Proceed to deploy?' + : 'Contract address would not match current mainnet address. Proceed anyway?' + ) if (await prompt.run()) { const wrapperFactory = await ethers.getContractFactory('Wrapper') const wrapperContract = await wrapperFactory.deploy( @@ -70,6 +78,17 @@ async function main() { { ...prettierConfig, parser: 'babel' } ) ) + wrapperCommits[chainId] = require('child_process') + .execSync('git rev-parse HEAD') + .toString() + .trim() + fs.writeFileSync( + './deploys-commits.js', + prettier.format( + `module.exports = ${JSON.stringify(wrapperCommits, null, '\t')}`, + { ...prettierConfig, parser: 'babel' } + ) + ) console.log( `Deployed: ${wrapperDeploys[chainId]} @ ${wrapperBlocks[chainId]}` ) diff --git a/yarn.lock b/yarn.lock index d0a1a8d08..ee35ceac1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2719,11 +2719,11 @@ aws4@^1.8.0: integrity sha512-NmWvPnx0F1SfrQbYwOi7OeaNGokp9XhzNioJ/CSBs8Qa4vxug81mhJEAVZwxXuBmYB5KDRfMq/F3RR0BIU7sWg== axios@^1.0.0, axios@^1.5.1: - version "1.6.7" - resolved "https://registry.yarnpkg.com/axios/-/axios-1.6.7.tgz#7b48c2e27c96f9c68a2f8f31e2ab19f59b06b0a7" - integrity sha512-/hDJGff6/c7u0hDkvkGxR/oy6CbCs8ziCsC7SqmhjfozqiJGc8Z11wrv9z9lYfY4K8l+H9TpjcMDX0xOZmx+RA== + version "1.7.7" + resolved "https://registry.yarnpkg.com/axios/-/axios-1.7.7.tgz#2f554296f9892a72ac8d8e4c5b79c14a91d0a47f" + integrity sha512-S4kL7XrjgBmvdGut0sN3yJxqYzrDOnivkBiN0OFs6hLiUam3UPvswUo0kqGyhqUZGEOytHyumEdXsAkgCOUf3Q== dependencies: - follow-redirects "^1.15.4" + follow-redirects "^1.15.6" form-data "^4.0.0" proxy-from-env "^1.1.0" @@ -2867,7 +2867,7 @@ brace-expansion@^2.0.1: dependencies: balanced-match "^1.0.0" -braces@^3.0.2, braces@~3.0.2: +braces@^3.0.3, braces@~3.0.2: version "3.0.3" resolved "https://registry.yarnpkg.com/braces/-/braces-3.0.3.tgz#490332f40919452272d55a8480adc0c441358789" integrity sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA== @@ -4691,7 +4691,7 @@ flatted@^3.2.9: resolved "https://registry.yarnpkg.com/flatted/-/flatted-3.3.1.tgz#21db470729a6734d4997002f439cb308987f567a" integrity sha512-X8cqMLLie7KsNUDSdzeN8FYK9rEt4Dt67OsG/DNGnYTSDBG4uFAJFBnUeiV+zCVAvwFy56IjM9sH51jVaEhNxw== -follow-redirects@^1.12.1, follow-redirects@^1.15.4: +follow-redirects@^1.12.1, follow-redirects@^1.15.6: version "1.15.6" resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.6.tgz#7f815c0cda4249c74ff09e95ef97c23b5fd0399b" integrity sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA== @@ -6748,11 +6748,11 @@ micro-ftch@^0.3.1: integrity sha512-/0LLxhzP0tfiR5hcQebtudP56gUurs2CLkGarnCiB/OqEyUFQ6U3paQi/tgLv0hBJYt2rnr9MNpxz4fiiugstg== micromatch@^4.0.4: - version "4.0.5" - resolved "https://registry.yarnpkg.com/micromatch/-/micromatch-4.0.5.tgz#bc8999a7cbbf77cdc89f132f6e467051b49090c6" - integrity sha512-DMy+ERcEW2q8Z2Po+WNXuw3c5YaUSFjAO5GsJqfEl7UjvtIuFKO6ZrKvcItdy98dwFI2N1tg3zNIdKaQT+aNdA== + version "4.0.8" + resolved "https://registry.yarnpkg.com/micromatch/-/micromatch-4.0.8.tgz#d66fa18f3a47076789320b9b1af32bd86d9fa202" + integrity sha512-PXwfBhYu0hBCPw8Dn0E+WDYb7af3dSLVWKi3HGv84IdF4TyFoC0ysxFd0Goxw7nSv4T/PzEJQxsYsEiFCKo2BA== dependencies: - braces "^3.0.2" + braces "^3.0.3" picomatch "^2.3.1" miller-rabin@^4.0.0: