Skip to content

Commit

Permalink
Merge pull request #1350 from airswap/develop
Browse files Browse the repository at this point in the history
Merge latest for publishing
  • Loading branch information
dmosites authored Dec 3, 2024
2 parents 30d18bc + da3ae91 commit 302d89f
Show file tree
Hide file tree
Showing 68 changed files with 14,416 additions and 10,529 deletions.
14 changes: 9 additions & 5 deletions .github/workflows/beta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@ jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/checkout@v4
- name: Enable Corepack
run: corepack enable
- name: Use Node.js 18.x
uses: actions/setup-node@v4
with:
node-version: '18.x'
registry-url: 'https://registry.npmjs.org'
- run: yarn install
node-version: "18.x"
cache: 'yarn'
- name: Install dependencies
run: yarn install --immutable
- run: lerna run compile --concurrency=1
- run: lerna publish from-package --yes --dist-tag beta
env:
Expand Down
14 changes: 9 additions & 5 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@ jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/checkout@v4
- name: Enable Corepack
run: corepack enable
- name: Use Node.js 18.x
uses: actions/setup-node@v4
with:
node-version: '18.x'
registry-url: 'https://registry.npmjs.org'
- run: yarn install
node-version: "18.x"
cache: 'yarn'
- name: Install dependencies
run: yarn install --immutable
- run: lerna run compile --concurrency=1
- run: lerna publish from-package --yes
env:
Expand Down
14 changes: 9 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Test using Node.js
uses: actions/setup-node@v1
- uses: actions/checkout@v4
- name: Enable Corepack
run: corepack enable
- name: Use Node.js 18.x
uses: actions/setup-node@v4
with:
node-version: '18.x'
- run: yarn install
node-version: "18.x"
cache: 'yarn'
- name: Install dependencies
run: yarn install --immutable
- run: lerna run compile --concurrency=1
- run: lerna run test:ci --concurrency=1
env:
Expand Down
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
node_modules
.yarn/*
!.yarn/cache
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions
yarn-error.log
lerna-debug.log
.DS_Store
Expand Down
1 change: 1 addition & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodeLinker: node-modules
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@

## 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/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 |
| 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/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/utils`](/tools/utils) | [![npm](https://img.shields.io/npm/v/@airswap/utils)](https://www.npmjs.com/package/@airswap/utils) | Utils for Developers |
| 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/utils`](/tools/utils) | [![npm](https://img.shields.io/npm/v/@airswap/utils)](https://www.npmjs.com/package/@airswap/utils) | Utils for Developers |

## Commands

Expand Down
2 changes: 1 addition & 1 deletion hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ module.exports = {
],
},
gasReporter: {
enabled: process.env.REPORT_GAS === 'true' ? true : false,
enabled: process.env.REPORT_GAS === 'true',
},
paths: {
artifacts: './build',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"prepare": "husky install",
"prettier": "prettier --write \"./**/*.sol\" \"./**/*.ts\" \"./**/*.js\" \"./**/*.json\""
},
"packageManager": "[email protected]",
"devDependencies": {
"@ensdomains/ens": "^0.4.4",
"@ensdomains/resolver": "^0.2.4",
Expand All @@ -50,7 +51,6 @@
"hardhat-gas-reporter": "^1.0.9",
"husky": "^8.0.1",
"lerna": "^7.3.0",
"mocha": "^10.2.0",
"nx": "^16.5.5",
"prettier": "^2.8.4",
"prettier-plugin-solidity": "^1.1.2",
Expand Down
2 changes: 1 addition & 1 deletion scripts/deployer-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const {
} = require('@airswap/utils')

module.exports = {
confirmDeployment: async function (deployer, targetAddress) {
confirmDeployment: async (deployer, targetAddress) => {
const gasPrice = await deployer.getGasPrice()
const chainId = await deployer.getChainId()
const balance = ethers.utils.formatUnits(
Expand Down
6 changes: 3 additions & 3 deletions scripts/drain-deployer.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ async function main() {
}

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

Expand Down Expand Up @@ -72,7 +72,7 @@ async function main() {
)

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

Expand All @@ -85,7 +85,7 @@ async function main() {
})
console.log('Transferring...', getReceiptUrl(chainId, tx.hash), '\n')
await tx.wait(CONFIRMATIONS)
console.log(`✔ Balance transfer complete.\n`)
console.log('✔ Balance transfer complete.\n')
}
}

Expand Down
2 changes: 1 addition & 1 deletion scripts/migrate-pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ async function main() {
const gasPrice = await account.getGasPrice()
console.log(`\nGas price: ${gasPrice / 10 ** 9} gwei\n`)

const prompt = new Confirm(`Enable and set above as claimed on to-pool?`)
const prompt = new Confirm('Enable and set above as claimed on to-pool?')
if (await prompt.run()) {
const tx = await newPool.enableAndSetClaimed(tree, root, trees[tree])
console.log('Updating...', getReceiptUrl(chainId, tx.hash), '\n')
Expand Down
2 changes: 1 addition & 1 deletion scripts/owners-report.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async function main() {
const chainId = mainnets[m]
let apiUrl = apiUrls[chainId]
if (apiUrl.indexOf('infura.io') !== -1)
apiUrl += '/' + process.env.INFURA_API_KEY
apiUrl += `/${process.env.INFURA_API_KEY}`
const provider = new ethers.providers.JsonRpcProvider(apiUrl)
const deployer = new ethers.Wallet(process.env.PRIVATE_KEY, provider)

Expand Down
20 changes: 10 additions & 10 deletions scripts/owners-update.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const TRANSFER_STARTED =
'0x38d16b8cac22d99fc7c124b9cd0de2d3fa1faef420bfe791d8c362d765e22700'

module.exports = {
check: async function (name, factory, deploys) {
check: async (name, factory, deploys) => {
const [account] = await ethers.getSigners()
const gasPrice = await account.getGasPrice()
const chainId = await account.getChainId()
Expand All @@ -24,7 +24,7 @@ module.exports = {
console.log(`Network: ${chainNames[chainId].toUpperCase()}\n`)

if (!deploys[chainId]) {
console.log(`✘ No deploy found for selected network.\n`)
console.log('✘ No deploy found for selected network.\n')
process.exit(0)
}

Expand All @@ -36,28 +36,28 @@ module.exports = {
console.log(`Intended owner: ${ownerAddresses[chainId] || 'Not set'}`)

if (currentOwner === ownerAddresses[chainId]) {
console.log(`\n✔ Owner matches intended owner.\n`)
console.log('\n✔ Owner matches intended owner.\n')
} else if (!ownerAddresses[chainId]) {
console.log(`\n✘ Intended owner must be set.\n`)
console.log('\n✘ Intended owner must be set.\n')
} else if (account.address !== currentOwner) {
console.log(`\n✘ Current owner does not match intended owner.`)
console.log('\n✘ Current owner does not match intended owner.')
console.log(
`✘ Cannot update because current account does not match current owner.\n`
'✘ Cannot update because current account does not match current owner.\n'
)
} else {
console.log(`\n✘ Current owner does not match intended owner.\n`)
console.log('\n✘ Current owner does not match intended owner.\n')
console.log(`Gas price: ${gasPrice / 10 ** 9} gwei\n`)
const prompt = new Confirm(`Transfer ownership to intended owner?`)
const prompt = new Confirm('Transfer ownership to intended owner?')
if (await prompt.run()) {
const tx = await contract.transferOwnership(ownerAddresses[chainId])
console.log('Updating...', getReceiptUrl(chainId, tx.hash), '\n')
const receipt = await tx.wait(CONFIRMATIONS)
if (receipt.logs[0].topics[0] === TRANSFER_STARTED) {
console.log(
`✔ Ownership transfer started but must be accepted by new owner.\n`
'✔ Ownership transfer started but must be accepted by new owner.\n'
)
} else {
console.log(`✔ Ownership transfer complete.\n`)
console.log('✔ Ownership transfer complete.\n')
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/receivers-report.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ async function main() {
const chainId = mainnets[m]
let apiUrl = apiUrls[chainId]
if (apiUrl.indexOf('infura.io') !== -1)
apiUrl += '/' + process.env.INFURA_API_KEY
apiUrl += `/${process.env.INFURA_API_KEY}`
const provider = new ethers.providers.JsonRpcProvider(apiUrl)
const deployer = new ethers.Wallet(process.env.PRIVATE_KEY, provider)

Expand Down
6 changes: 4 additions & 2 deletions source/batch-call/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@
"ethers": "^5.7.2"
},
"devDependencies": {
"@airswap/utils": "5.0.2",
"@airswap/swap": "5.0.1",
"@airswap/swap-erc20": "5.0.1",
"@openzeppelin/contracts": "^4.8.3"
"@airswap/utils": "5.0.2",
"@openzeppelin/contracts": "^4.8.3",
"hardhat": "^2.12.7",
"typescript": "^5.0.4"
},
"publishConfig": {
"access": "public"
Expand Down
6 changes: 3 additions & 3 deletions source/batch-call/scripts/deploy.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable no-console */
const fs = require('fs')
const fs = require('node:fs')
const prettier = require('prettier')
const { ethers, run } = require('hardhat')
const { ChainIds, chainLabels, getReceiptUrl } = require('@airswap/utils')
Expand All @@ -17,7 +17,7 @@ async function main() {
console.log('Value for --network flag is required')
return
}
console.log(`\nDeploy BATCHCALL\n`)
console.log('\nDeploy BATCHCALL\n')

if (await confirmDeployment(deployer, batchCallDeploys)) {
const batchFactory = await ethers.getContractFactory('BatchCall')
Expand Down Expand Up @@ -58,7 +58,7 @@ async function main() {
)
)

batchCallCommits[chainId] = require('child_process')
batchCallCommits[chainId] = require('node:child_process')
.execSync('git rev-parse HEAD')
.toString()
.trim()
Expand Down
2 changes: 1 addition & 1 deletion source/batch-call/scripts/owner.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
console.log(`\n✘ BatchCall is not ownable.\n`)
console.log('\n✘ BatchCall is not ownable.\n')
27 changes: 13 additions & 14 deletions source/delegate/contracts/Delegate.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ contract Delegate is IDelegate, Ownable {

/**
* @notice Set a Rule
* @param _senderWallet address Address of the sender wallet
* @param _senderWallet address Address of the delegating sender 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
Expand Down Expand Up @@ -80,7 +80,7 @@ contract Delegate is IDelegate, Ownable {

/**
* @notice Unset a Rule
* @param _senderWallet The address of the sender's wallet
* @param _senderWallet address Address of the delegating sender wallet
* @param _senderToken address ERC-20 token the sender would transfer
* @param _signerToken address ERC-20 token the signer would transfer
*/
Expand Down Expand Up @@ -133,22 +133,21 @@ contract Delegate is IDelegate, Ownable {
bytes32 _s
) external {
Rule storage rule = rules[_senderWallet][_senderToken][_signerToken];
// Ensure the signer amount is valid
if (
_signerAmount <
(rule.signerAmount * (rule.senderAmount - rule.senderFilledAmount)) /
rule.senderAmount
) {
revert SignerAmountInvalid();
}
// Ensure the rule has not expired
if (rule.expiry < block.timestamp) revert RuleExpired();
// Ensure the expiry is not passed
if (rule.expiry <= block.timestamp) revert RuleExpiredOrDoesNotExist();

// Ensure the sender amount is valid
if (_senderAmount > (rule.senderAmount - rule.senderFilledAmount)) {
revert SenderAmountInvalid();
}

// Ensure the signer amount is valid
if (
rule.signerAmount * _senderAmount != rule.senderAmount * _signerAmount
) {
revert SignerAmountInvalid();
}

// Transfer the sender token to this contract
SafeTransferLib.safeTransferFrom(
_senderToken,
Expand Down Expand Up @@ -185,8 +184,8 @@ contract Delegate is IDelegate, Ownable {
rules[_senderWallet][_senderToken][_signerToken]
.senderFilledAmount += _senderAmount;

// Emit a DelegateSwap event
emit DelegateSwap(_nonce, _signerWallet);
// Emit a DelegatedSwapFor event
emit DelegatedSwapFor(_senderWallet, _signerWallet, _nonce);
}

/**
Expand Down
8 changes: 6 additions & 2 deletions source/delegate/contracts/interfaces/IDelegate.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ interface IDelegate {
}

event Authorize(address signatory, address signer);
event DelegateSwap(uint256 nonce, address signerWallet);
event DelegatedSwapFor(
address indexed senderWallet,
address indexed signerWallet,
uint256 indexed nonce
);
event Revoke(address tmp, address signer);

event SetRule(
Expand All @@ -33,7 +37,7 @@ interface IDelegate {
);

error AddressInvalid();
error RuleExpired();
error RuleExpiredOrDoesNotExist();
error SenderAmountInvalid();
error SignerAmountInvalid();
error SenderInvalid();
Expand Down
2 changes: 1 addition & 1 deletion source/delegate/deploys-blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ module.exports = {
42161: 258599054,
43114: 51146988,
59144: 10096855,
11155111: 6781500,
11155111: 7203627,
}
2 changes: 1 addition & 1 deletion source/delegate/deploys-commits.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ module.exports = {
42161: '57b971f929f783db5ee9d9121fcf76be394485a5',
43114: '57b971f929f783db5ee9d9121fcf76be394485a5',
59144: '57b971f929f783db5ee9d9121fcf76be394485a5',
11155111: '57b971f929f783db5ee9d9121fcf76be394485a5',
11155111: 'a6f5e5d8f8fcd5a7dc13ad5e9d0b6a903ba90f16',
}
Loading

0 comments on commit 302d89f

Please sign in to comment.