Skip to content

Commit

Permalink
Merge pull request #1251 from airswap/develop
Browse files Browse the repository at this point in the history
Merge to Beta for NPM Publishing
  • Loading branch information
dmosites authored Jan 11, 2024
2 parents cdd8948 + e2dd551 commit f0eef52
Show file tree
Hide file tree
Showing 89 changed files with 1,187 additions and 697 deletions.
9 changes: 9 additions & 0 deletions hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,15 @@ module.exports = {
},
},
},
{
version: '0.8.23',
settings: {
optimizer: {
enabled: true,
runs: 999999,
},
},
},
],
},
etherscan: {
Expand Down
18 changes: 0 additions & 18 deletions source/balances/deploys.js

This file was deleted.

1 change: 0 additions & 1 deletion source/balances/deploys.js.d.ts

This file was deleted.

4 changes: 2 additions & 2 deletions source/balances/README.md → source/batch-call/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# BalanceChecker
# BatchCall

[AirSwap](https://www.airswap.io/) is a peer-to-peer trading network for Ethereum tokens. This package contains source code and tests for a basic ERC20 balance and allowance aggregator.

Expand All @@ -15,7 +15,7 @@

## Usage

:warning: This package is under active development. The [BalanceChecker](./contracts/BalanceChecker.sol) contract is deployed; see [deploys.js](./deploys.js) for latest. For all AirSwap contract deployments see [Deployed Contracts](https://docs.airswap.io/system/contract-deployments).
:warning: This package is under active development. The [BatchCall](./contracts/BatchCall.sol) contract is deployed; see [deploys.js](./deploys.js) for latest. For all AirSwap contract deployments see [Deployed Contracts](https://docs.airswap.io/system/contract-deployments).

## Commands

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;
pragma solidity 0.8.23;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/utils/Address.sol";
import "@airswap/swap/contracts/interfaces/ISwap.sol";
import "@airswap/swap-erc20/contracts/interfaces/ISwapERC20.sol";

/**
* @title BalanceChecker: Batch ERC-20 allowance and balance calls
* @title BatchCalling: Batch balance, allowance, order validity checks
*/
contract BalanceChecker is Ownable {
contract BatchCall {
using SafeERC20 for IERC20;
using Address for address;

Expand Down Expand Up @@ -127,36 +128,6 @@ contract BalanceChecker is Ownable {
return balances;
}

/**
* @notice Self-destruct contract for clean-up
*/
function destruct(address payable recipientAddress) public onlyOwner {
selfdestruct(recipientAddress);
}

/**
* @notice Allow owner to withdraw ether from contract
*/
function withdraw() public onlyOwner {
(bool success, ) = address(owner()).call{ value: address(this).balance }(
""
);
require(success, "ETH_WITHDRAW_FAILED");
}

/**
* @notice Allow owner to withdraw stuck tokens from contract
* @param tokenAddress address
* @param amount uint256
*/
function withdrawToken(
address tokenAddress,
uint256 amount
) public onlyOwner {
require(tokenAddress != address(0x0)); //use withdraw for ETH
IERC20(tokenAddress).safeTransfer(msg.sender, amount);
}

/**
* @notice Check the token allowance of a wallet in a token contract
* @dev return 0 on returns 0 on invalid spender contract or non-contract address
Expand Down Expand Up @@ -212,4 +183,55 @@ contract BalanceChecker is Ownable {
}
return 0;
}

/**
* @notice Check if the validity of an array of Orders
* @dev return array and will fail if large token arrays are inputted
* @dev Returns an array of bool
* @param orders[] list of orders to be checked
* @return bool[] order validity
*/

function checkOrders(
address senderWallet,
ISwap.Order[] calldata orders,
ISwap swapContract
) external view returns (bool[] memory) {
require(orders.length > 0);
bool[] memory orderValidity = new bool[](orders.length);

for (uint256 i = 0; i < orders.length; i++) {
(, uint256 errorCount) = swapContract.check(senderWallet, orders[i]);
orderValidity[i] = errorCount == 0 ? true : false;
}
return orderValidity;
}

function checkOrdersERC20(
address senderWallet,
ISwapERC20.OrderERC20[] calldata ordersERC20,
ISwapERC20 swapERC20Contract
) external view returns (bool[] memory) {
require(ordersERC20.length > 0);
bool[] memory orderValidity = new bool[](ordersERC20.length);

for (uint256 i = 0; i < ordersERC20.length; i++) {
ISwapERC20.OrderERC20 memory order = ordersERC20[i];
(uint256 errorCount, ) = swapERC20Contract.check(
senderWallet,
order.nonce,
order.expiry,
order.signerWallet,
order.signerToken,
order.signerAmount,
order.senderToken,
order.senderAmount,
order.v,
order.r,
order.s
);
orderValidity[i] = errorCount == 0 ? true : false;
}
return orderValidity;
}
}
4 changes: 4 additions & 0 deletions source/batch-call/deploys-blocks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
5: 10351183,
11155111: 5059276,
}
1 change: 1 addition & 0 deletions source/batch-call/deploys-blocks.js.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module '@airswap/batch-call/deploys-blocks.js'
4 changes: 4 additions & 0 deletions source/batch-call/deploys.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
5: '0x1104d8e1f4499acbabbcd55c9a6c957e1f881318',
11155111: '0x1104D8E1F4499ACbaBBcD55c9A6C957E1F881318',
}
1 change: 1 addition & 0 deletions source/batch-call/deploys.js.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module '@airswap/batch-call/deploys.js'
File renamed without changes.
12 changes: 7 additions & 5 deletions source/balances/package.json → source/batch-call/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@airswap/balances",
"version": "4.0.4",
"description": "Batch balance and allowance calls",
"name": "@airswap/batch-call",
"version": "4.1.0-beta.0",
"description": "Batch balance, allowance, order validity checks",
"license": "MIT",
"repository": {
"type": "git",
Expand All @@ -26,10 +26,12 @@
"owners": "hardhat run ./scripts/owner.js"
},
"dependencies": {
"@openzeppelin/contracts": "^4.8.3"
"@openzeppelin/contracts": "^4.8.3",
"@airswap/swap": "4.1.3-beta.0",
"@airswap/swap-erc20": "4.1.7-beta.0"
},
"devDependencies": {
"@airswap/constants": "4.1.8",
"@airswap/constants": "4.1.9-beta.0",
"@airswap/utils": "4.1.12",
"prompt-confirm": "^2.0.4"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
/* eslint-disable no-console */
const fs = require('fs')
const prettier = require('prettier')
const Confirm = require('prompt-confirm')
const { ethers, run } = require('hardhat')
const { ChainIds, chainNames, chainLabels } = require('@airswap/constants')
const { getReceiptUrl } = require('@airswap/utils')
const balancesDeploys = require('../deploys.js')
const batchCallDeploys = require('../deploys.js')
const batchCallBlocks = require('../deploys-blocks.js')

async function main() {
await run('compile')
Expand All @@ -21,23 +23,36 @@ async function main() {

const prompt = new Confirm('Proceed to deploy?')
if (await prompt.run()) {
const balanceCheckerFactory = await ethers.getContractFactory(
'BalanceChecker'
)
const balanceCheckerContract = await balanceCheckerFactory.deploy()
const prettierConfig = await prettier.resolveConfig('../deploys.js')
const batchFactory = await ethers.getContractFactory('BatchCall')
const batchCallContract = await batchFactory.deploy()
console.log(
'Deploying...',
getReceiptUrl(chainId, balanceCheckerContract.deployTransaction.hash)
getReceiptUrl(chainId, batchCallContract.deployTransaction.hash)
)
await balanceCheckerContract.deployed()
console.log(`Deployed: ${balanceCheckerContract.address}`)
await batchCallContract.deployed()

balancesDeploys[chainId] = balanceCheckerContract.address
batchCallDeploys[chainId] = batchCallContract.address
fs.writeFileSync(
'./deploys.js',
`module.exports = ${JSON.stringify(balancesDeploys, null, '\t')}`
prettier.format(
`module.exports = ${JSON.stringify(batchCallDeploys, null, '\t')}`,
{ ...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' }
)
)
console.log(
`Deployed: ${batchCallDeploys[chainId]} @ ${batchCallBlocks[chainId]}`
)
console.log('Updated deploys.js')

console.log(
`\nVerify with "yarn verify --network ${chainLabels[
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-console */
const { ethers, run } = require('hardhat')
const { chainNames } = require('@airswap/constants')
const balancesDeploys = require('../deploys.js')
const batchCallDeploys = require('../deploys.js')

async function main() {
await run('compile')
Expand All @@ -12,7 +12,7 @@ async function main() {

console.log(`Verifying on ${chainNames[chainId].toUpperCase()}`)
await run('verify:verify', {
address: balancesDeploys[chainId],
address: batchCallDeploys[chainId],
constructorArguments: [],
})
}
Expand Down
Loading

0 comments on commit f0eef52

Please sign in to comment.