Skip to content

Commit

Permalink
merge from main
Browse files Browse the repository at this point in the history
  • Loading branch information
dmosites committed Jun 4, 2024
2 parents d9d08fb + 6ad0137 commit ad2ea31
Show file tree
Hide file tree
Showing 137 changed files with 4,570 additions and 3,578 deletions.
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

yarn lint:check && yarn pretty:check
yarn linter && yarn prettier
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright 2023 AirSwap
Copyright 2024 AirSwap

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
Expand Down
22 changes: 7 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,28 @@
## Resources

- Discord → https://chat.airswap.io/
- Twitterhttps://twitter.com/airswap
- Xhttps://x.com/airswap
- Website → https://www.airswap.io/
- About → https://about.airswap.io/

## Contracts

| Package | Version | Description |
| :------------------------------------------------------ | :------------------------------------------------------------------------------------------------------------------------ | :---------------------------- |
| [`@airswap/registry`](/source/registry) | [![npm](https://img.shields.io/npm/v/@airswap/registry)](https://www.npmjs.com/package/@airswap/registry) | Server Registry |
| [`@airswap/swap`](/source/swap) | [![npm](https://img.shields.io/npm/v/@airswap/swap)](https://www.npmjs.com/package/@airswap/swap) | Atomic Token Swap |
| [`@airswap/swap-erc20`](/source/swap-erc20) | [![npm](https://img.shields.io/npm/v/@airswap/swap-erc20)](https://www.npmjs.com/package/@airswap/swap-erc20) | Atomic Token Swap (ERC20) |
| [`@airswap/registry`](/source/registry) | [![npm](https://img.shields.io/npm/v/@airswap/registry)](https://www.npmjs.com/package/@airswap/registry) | Server Discovery |
| [`@airswap/indexer-registry`](/source/indexer-registry) | [![npm](https://img.shields.io/npm/v/@airswap/indexer-registry)](https://www.npmjs.com/package/@airswap/indexer-registry) | Indexer Discovery |
| [`@airswap/staking`](/source/staking) | [![npm](https://img.shields.io/npm/v/@airswap/staking)](https://www.npmjs.com/package/@airswap/staking) | Staking for Participants |
| [`@airswap/pool`](/source/pool) | [![npm](https://img.shields.io/npm/v/@airswap/pool)](https://www.npmjs.com/package/@airswap/pool) | Rewards Pool for Participants |
| [`@airswap/wrapper`](/source/wrapper) | [![npm](https://img.shields.io/npm/v/@airswap/wrapper)](https://www.npmjs.com/package/@airswap/wrapper) | Wrapper for Native Tokens |
| [`@airswap/staking`](/source/staking) | [![npm](https://img.shields.io/npm/v/@airswap/staking)](https://www.npmjs.com/package/@airswap/staking) | Staking for Members |
| [`@airswap/pool`](/source/pool) | [![npm](https://img.shields.io/npm/v/@airswap/pool)](https://www.npmjs.com/package/@airswap/pool) | Rewards Pool for Members |
| [`@airswap/batch-call`](/source/batch-call) | [![npm](https://img.shields.io/npm/v/@airswap/batch-call)](https://www.npmjs.com/package/@airswap/batch-call) | Batch Token and Order Calls |

## Tools

| Package | Version | Description |
| :-------------------------------------- | :---------------------------------------------------------------------------------------------------------- | :---------------------------- |
| [`@airswap/libraries`](tools/libraries) | [![npm](https://img.shields.io/npm/v/@airswap/libraries)](https://www.npmjs.com/package/@airswap/libraries) | Libraries for Developers |
| [`@airswap/metadata`](tools/metadata) | [![npm](https://img.shields.io/npm/v/@airswap/metadata)](https://www.npmjs.com/package/@airswap/metadata) | Token Metadata for Developers |
| [`@airswap/utils`](/tools/utils) | [![npm](https://img.shields.io/npm/v/@airswap/utils)](https://www.npmjs.com/package/@airswap/utils) | Utilities for Developers |
| [`@airswap/types`](/tools/types) | [![npm](https://img.shields.io/npm/v/@airswap/types)](https://www.npmjs.com/package/@airswap/types) | Types for Developers |
| [`@airswap/constants`](tools/constants) | [![npm](https://img.shields.io/npm/v/@airswap/constants)](https://www.npmjs.com/package/@airswap/constants) | Constants for Developers |
| [`@airswap/utils`](/tools/utils) | [![npm](https://img.shields.io/npm/v/@airswap/utils)](https://www.npmjs.com/package/@airswap/utils) | Utils for Developers |

## Commands

Expand All @@ -53,12 +51,6 @@ Branch from Develop; Merge Feature → Develop → Beta → Main
Flow for tool updates (not contracts):
Branch from Main; Merge Feature → Main → Develop

## Versioning

- Major versions include breaking changes.
- Minor versions do not include breaking changes and may include additional functionality.
- Dependencies on fellow @airswap packages should use caret semver.

## Process

**Regular development process for a complete release**
Expand Down
52 changes: 26 additions & 26 deletions hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ require('dotenv').config({ path: '../../.env' })
require('@typechain/hardhat')
require('@nomiclabs/hardhat-ethers')
require('@nomiclabs/hardhat-waffle')
require('@nomiclabs/hardhat-etherscan')
require('@nomicfoundation/hardhat-verify')
require('hardhat-gas-reporter')
require('solidity-coverage')

Expand All @@ -11,7 +11,7 @@ const {
apiUrls,
explorerUrls,
explorerApiUrls,
} = require('@airswap/constants')
} = require('@airswap/utils')

/**
* @type import('hardhat/config').HardhatUserConfig
Expand Down Expand Up @@ -50,8 +50,8 @@ module.exports = {
url: apiUrls[ChainIds.ARBITRUM],
accounts: process.env.PRIVATE_KEY ? [process.env.PRIVATE_KEY] : undefined,
},
arbitrumgoerli: {
url: apiUrls[ChainIds.ARBITRUMGOERLI],
arbitrumsepolia: {
url: apiUrls[ChainIds.ARBITRUMSEPOLIA],
accounts: process.env.PRIVATE_KEY ? [process.env.PRIVATE_KEY] : undefined,
},
rsk: {
Expand All @@ -70,8 +70,8 @@ module.exports = {
url: apiUrls[ChainIds.LINEA],
accounts: process.env.PRIVATE_KEY ? [process.env.PRIVATE_KEY] : undefined,
},
basegoerli: {
url: apiUrls[ChainIds.BASEGOERLI],
basesepolia: {
url: apiUrls[ChainIds.BASESEPOLIA],
accounts: process.env.PRIVATE_KEY ? [process.env.PRIVATE_KEY] : undefined,
},
base: {
Expand Down Expand Up @@ -133,82 +133,82 @@ module.exports = {
bscTestnet: process.env.BSCSCAN_API_KEY,
polygon: process.env.POLYGONSCAN_API_KEY,
arbitrumOne: process.env.ARBISCAN_API_KEY,
arbitrumGoerli: process.env.ARBISCAN_API_KEY,
arbitrumSepolia: process.env.ARBISCAN_API_KEY,
avalanche: process.env.SNOWTRACE_API_KEY,
avalancheFujiTestnet: process.env.SNOWTRACE_API_KEY,
holesky: process.env.ETHERSCAN_API_KEY,
polygonMumbai: process.env.POLYGONSCAN_API_KEY,
linea: process.env.LINEASCAN_API_KEY,
lineagoerli: process.env.LINEASCAN_API_KEY,
lineaGoerli: process.env.LINEASCAN_API_KEY,
base: process.env.BASESCAN_API_KEY,
basegoerli: process.env.BASESCAN_API_KEY,
baseSepolia: process.env.BASESCAN_API_KEY,
rsk: process.env.BLOCKSCOUT_API_KEY,
rsktestnet: process.env.BLOCKSCOUT_API_KEY,
rskTestnet: process.env.BLOCKSCOUT_API_KEY,
sepolia: process.env.ETHERSCAN_API_KEY,
},
customChains: [
{
network: 'rsk',
chainId: 30,
chainId: ChainIds.RSK,
urls: {
apiURL: explorerApiUrls[ChainIds.RSK],
browserURL: explorerUrls[ChainIds.RSK],
},
},
{
network: 'rsktestnet',
chainId: 31,
network: 'rskTestnet',
chainId: ChainIds.RSKTESTNET,
urls: {
apiURL: explorerApiUrls[ChainIds.RSKTESTNET],
browserURL: explorerUrls[ChainIds.RSKTESTNET],
},
},
{
network: 'holesky',
chainId: 17000,
chainId: ChainIds.HOLESKY,
urls: {
apiURL: explorerApiUrls[ChainIds.HOLESKY],
browserURL: explorerUrls[ChainIds.HOLESKY],
},
},
{
network: 'linea',
chainId: 59144,
chainId: ChainIds.LINEA,
urls: {
apiURL: explorerApiUrls[ChainIds.LINEA],
browserURL: explorerUrls[ChainIds.LINEA],
},
},
{
network: 'lineagoerli',
chainId: 59140,
network: 'lineaGoerli',
chainId: ChainIds.LINEAGOERLI,
urls: {
apiURL: explorerApiUrls[ChainIds.LINEAGOERLI],
browserURL: explorerUrls[ChainIds.LINEAGOERLI],
},
},
{
network: 'base',
chainId: 8453,
chainId: ChainIds.BASE,
urls: {
apiURL: explorerApiUrls[ChainIds.BASE],
browserURL: explorerUrls[ChainIds.BASE],
},
},
{
network: 'basegoerli',
chainId: 84531,
network: 'baseSepolia',
chainId: ChainIds.BASESEPOLIA,
urls: {
apiURL: explorerApiUrls[ChainIds.BASEGOERLI],
browserURL: explorerUrls[ChainIds.BASEGOERLI],
apiURL: explorerApiUrls[ChainIds.BASESEPOLIA],
browserURL: explorerUrls[ChainIds.BASESEPOLIA],
},
},
{
network: 'arbitrumGoerli',
chainId: 421613,
network: 'arbitrumSepolia',
chainId: ChainIds.ARBITRUMSEPOLIA,
urls: {
apiURL: explorerApiUrls[ChainIds.ARBITRUMGOERLI],
browserURL: explorerUrls[ChainIds.ARBITRUMGOERLI],
apiURL: explorerApiUrls[ChainIds.ARBITRUMSEPOLIA],
browserURL: explorerUrls[ChainIds.ARBITRUMSEPOLIA],
},
},
],
Expand Down
32 changes: 17 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,40 @@
]
},
"scripts": {
"check:owners": "node ./scripts/owners-report.js",
"check:receivers": "node ./scripts/receivers-report.js",
"check:wrappers": "node ./scripts/wrappers-report.js",
"clean": "lerna run clean",
"compile": "lerna run compile",
"lint:check": "yarn eslint . --ext .js,.ts",
"lint:fix": "yarn eslint . --ext .js,.ts --fix",
"linter": "yarn eslint . --ext .js,.ts --fix",
"test": "lerna run test",
"test:ci": "lerna run test:ci",
"owners": "node ./scripts/owners-report.js",
"receivers": "node ./scripts/receivers-report.js",
"drain": "node ./scripts/drain-deployer.js",
"prepare": "husky install",
"pretty:check": "prettier --check \"./**/*.sol\" \"./**/*.ts\" \"./**/*.js\" \"./**/*.json\"",
"pretty:fix": "prettier --write \"./**/*.sol\" \"./**/*.ts\" \"./**/*.js\" \"./**/*.json\""
"prettier": "prettier --write \"./**/*.sol\" \"./**/*.ts\" \"./**/*.js\" \"./**/*.json\""
},
"devDependencies": {
"@ensdomains/ens": "^0.4.4",
"@ensdomains/resolver": "^0.2.4",
"@ethersproject/abi": "^5.7.0",
"@ethersproject/bytes": "^5.7.0",
"@ethersproject/providers": "^5.7.2",
"@nomiclabs/hardhat-ethers": "^2.1.0",
"@nomiclabs/hardhat-etherscan": "^3.1.0",
"@nomiclabs/hardhat-waffle": "^2.0.3",
"@typechain/ethers-v5": "^10.2.0",
"@typechain/hardhat": "^6.1.5",
"@nomicfoundation/hardhat-verify": "^2.0.4",
"@nomiclabs/hardhat-ethers": "^2.2.3",
"@nomiclabs/hardhat-waffle": "^2.0.6",
"@typechain/ethers-v5": "^11.1.2",
"@typechain/hardhat": "^7.0.0",
"@types/mocha": "^10.0.1",
"@types/node": "^18.15.11",
"@typescript-eslint/eslint-plugin": "^5.58.0",
"@typescript-eslint/parser": "^5.58.0",
"@types/sinon-chai": "^3.2.12",
"@typescript-eslint/eslint-plugin": "^7.1.0",
"@typescript-eslint/parser": "^7.1.0",
"chai": "^4.3.6",
"dotenv": "^16.0.1",
"eslint": "^8.20.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.2.1",
"ethereum-waffle": "^4.0.10",
"ethers": "^5.6.9",
"ethers": "^5.7.2",
"hardhat": "^2.12.7",
"hardhat-gas-reporter": "^1.0.9",
"husky": "^8.0.1",
Expand Down
27 changes: 27 additions & 0 deletions scripts/deployer-info.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const {
chainNames,
chainCurrencies,
EVM_NATIVE_TOKEN_DECIMALS,
} = require('@airswap/utils')

module.exports = {
displayDeployerInfo: async function (deployer) {
const gasPrice = await deployer.getGasPrice()
const chainId = await deployer.getChainId()
const balance = ethers.utils.formatUnits(
(await deployer.getBalance()).toString(),
EVM_NATIVE_TOKEN_DECIMALS
)
console.log(`\nNetwork: ${chainNames[chainId].toUpperCase()}`)
console.log(`Gas price: ${gasPrice / 10 ** 9} gwei`)
console.log(`\nDeployer: ${deployer.address}`)
console.log(`Balance: ${balance} ${chainCurrencies[chainId]}`)

console.log(
`\nNext contract address will be:\n${ethers.utils.getContractAddress({
from: deployer.address,
nonce: await deployer.provider.getTransactionCount(deployer.address),
})}\n`
)
},
}
97 changes: 97 additions & 0 deletions scripts/drain-deployer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
require('dotenv').config({ path: './.env' })
const Confirm = require('prompt-confirm')
const { ethers } = require('ethers')
const {
ChainIds,
chainNames,
chainCurrencies,
apiUrls,
getReceiptUrl,
ADDRESS_ZERO,
EVM_NATIVE_TOKEN_DECIMALS,
} = require('@airswap/utils')

const CONFIRMATIONS = 2
const RECIPIENT = '0x0000000000000000000000000000000000000000'

async function main() {
let chainId
if (process.argv[2] === '--network') {
chainId = ChainIds[process.argv[3].toUpperCase()]
}

if (!chainId) {
console.log('Value for --network flag is required')
return
}

const provider = new ethers.providers.JsonRpcProvider(apiUrls[chainId])
const deployer = new ethers.Wallet(process.env.PRIVATE_KEY, provider)
const gasPrice = await deployer.getGasPrice()

const balance = await deployer.getBalance()
const balanceFormatted = ethers.utils.formatUnits(
balance.toString(),
EVM_NATIVE_TOKEN_DECIMALS
)

if (balance.isZero()) {
console.log(
`\n✘ Balance is already 0 on ${process.argv[3].toUpperCase()}.\n`
)
process.exit(0)
}

if (RECIPIENT === ADDRESS_ZERO) {
console.log(`\n✘ RECIPIENT must be set.\n`)
process.exit(0)
}

const estimation = await provider.estimateGas({
to: RECIPIENT,
value: 1,
})

const cost = estimation.mul(gasPrice)
const costFormatted = ethers.utils.formatUnits(
cost,
EVM_NATIVE_TOKEN_DECIMALS
)
const value = balance.sub(cost)

console.log(`\nNetwork: ${chainNames[chainId].toUpperCase()}`)
console.log(`Gas price: ${gasPrice / 10 ** 9} gwei`)
console.log(`\nDeployer: ${deployer.address}`)
console.log(`Balance: ${balanceFormatted} ${chainCurrencies[chainId]}`)
console.log(`Transfer cost: ${costFormatted} ${chainCurrencies[chainId]}`)
console.log(
`Net amount: ${ethers.utils.formatUnits(
value,
EVM_NATIVE_TOKEN_DECIMALS
)} ${chainCurrencies[chainId]}\n`
)

if (value.isNegative()) {
console.log(`✘ Not enough balance to perform transfer.\n`)
process.exit(0)
}

const prompt = new Confirm(`Transfer ${balanceFormatted} to ${RECIPIENT}?`)
if (await prompt.run()) {
const tx = await deployer.sendTransaction({
to: RECIPIENT,
value,
gasPrice,
})
console.log('Transferring...', getReceiptUrl(chainId, tx.hash), '\n')
await tx.wait(CONFIRMATIONS)
console.log(`✔ Balance transfer complete.\n`)
}
}

main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error)
process.exit(1)
})
Loading

0 comments on commit ad2ea31

Please sign in to comment.