Skip to content

Commit

Permalink
Neon deployment preparation (#1313)
Browse files Browse the repository at this point in the history
* publish libraries 4.2.1-beta.0

* Bump follow-redirects from 1.15.5 to 1.15.6 (#1302)

Bumps [follow-redirects](https://github.com/follow-redirects/follow-redirects) from 1.15.5 to 1.15.6.
- [Release notes](https://github.com/follow-redirects/follow-redirects/releases)
- [Commits](follow-redirects/follow-redirects@v1.15.5...v1.15.6)

---
updated-dependencies:
- dependency-name: follow-redirects
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Batch registry call (#1295)

* Created Registry interface and imported in BatchCall

* Created getTokensForStakers

* Ran Prettier

* Switched to solady lib for ERC20 calls

---------

Co-authored-by: Don Mosites <[email protected]>

* Bump express from 4.18.3 to 4.19.2 (#1303)

Bumps [express](https://github.com/expressjs/express) from 4.18.3 to 4.19.2.
- [Release notes](https://github.com/expressjs/express/releases)
- [Changelog](https://github.com/expressjs/express/blob/master/History.md)
- [Commits](expressjs/express@4.18.3...4.19.2)

---
updated-dependencies:
- dependency-name: express
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump undici from 5.28.3 to 5.28.4 (#1304)

Bumps [undici](https://github.com/nodejs/undici) from 5.28.3 to 5.28.4.
- [Release notes](https://github.com/nodejs/undici/releases)
- [Commits](nodejs/undici@v5.28.3...v5.28.4)

---
updated-dependencies:
- dependency-name: undici
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump ejs from 3.1.9 to 3.1.10 (#1308)

Bumps [ejs](https://github.com/mde/ejs) from 3.1.9 to 3.1.10.
- [Release notes](https://github.com/mde/ejs/releases)
- [Commits](mde/ejs@v3.1.9...v3.1.10)

---
updated-dependencies:
- dependency-name: ejs
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Delegates (#1309)

* Imported Delegate and Indexer contracts and Fixed Delegate code to allow compilation

* Updated Indexer code to compile with Solidity 0.8.17

* Updated licenses for Delegates and Indexer contracts

* Removed constructor visibility and updated Delegate/Indexer interactions to ensure both contracts compile simultaneously

* Removed the indexer boilerplate and adjusted the delegate placeholder contract accordingly. Removed the delegateFactory contract

* Removed the indexer boilerplate and adjusted the delegate placeholder contract accordingly. Removed the delegateFactory contract

* Removed IDelegateFactoryContract

* Created basics of the swap function for the delegate contract

* Fixed token transfers

* Removed unecessary variable

* Removed unused imports in Delegate tests

* Removed unused imports in Delegate tests

* Fixed transfer amounts

* Updated recipient to delegator in swapERC20

* Renamed signer to delegator and sender to taker

* Renamed signer and sender to delegator and taker for clarity and added tracking of remaining rule allowance

* Created delegate integration test

* Removed unused variables

* updated delegates contract to solady library

* delegates: cleanup deps; remove redundants

* name updates; test quickfix

* prettier

* Renamed _maxDelegatorAmount to _maxSenderAmount for consistency

* Added test to check delegate allowance

* Added internal rule tests

* Implemented Delegate price check

* Separated setting and unsetting rules tests

* Specified DEFAULT_SIGNER_AMOUNT and DEFAULT_SENDER_AMOUNT in tests. Added a test case when SENDER_AMOUNT is above requirements

* Removed test to check if sender can send more token that defined in the rule

* Implemented signatory logic allowing sender to delegate rule setting on their behalf

* Wrote delegate deploy script

* Removed unecessary scripts

* updated deploy.js.d.ts

* Fixed chain name import

* Deployed to Sepolia

* Renamed Signatory to Manager, adjusted tests accordingly

* Deployed to Sepolia

* prettier

* restore abis

* Updated copyright date

* PR comments, added swapERC20 setter and fixed ownership initialization

* zeroed out all fields in the rule when unsetting

* Refactored rule reset on unset

---------

Co-authored-by: Don Mosites <[email protected]>

* @airswap/delegate: update utils version; update yarn.lock

* Prepared neon and neondevnet deployment

* Deployment to Neon Devnet

* Deployed wrapper

* update utils deps to latest

* update neonscan vars

* update env.example

* restore yarn.lock

* Removed Delegates

* Deployed on Neon mainnet

* Verified contracts and transfered ownership on Neon

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: don mosites <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Jul 18, 2024
1 parent fe6ba6f commit 8b67963
Show file tree
Hide file tree
Showing 34 changed files with 297 additions and 42 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ SNOWTRACE_API_KEY=00000000000000000000000000000000
ARBISCAN_API_KEY=00000000000000000000000000000000
LINEASCAN_API_KEY=00000000000000000000000000000000
BASESCAN_API_KEY=00000000000000000000000000000000
NEONSCAN_API_KEY=test
BLOCKSCOUT_API_KEY=abc
REPORT_GAS=true
26 changes: 26 additions & 0 deletions hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ module.exports = {
url: apiUrls[ChainIds.HOLESKY],
accounts: process.env.PRIVATE_KEY ? [process.env.PRIVATE_KEY] : undefined,
},
neon: {
url: apiUrls[ChainIds.NEON],
accounts: process.env.PRIVATE_KEY ? [process.env.PRIVATE_KEY] : undefined,
},
neondevnet: {
url: apiUrls[ChainIds.NEONDEVNET],
accounts: process.env.PRIVATE_KEY ? [process.env.PRIVATE_KEY] : undefined,
},
},
solidity: {
compilers: [
Expand Down Expand Up @@ -145,6 +153,8 @@ module.exports = {
rsk: process.env.BLOCKSCOUT_API_KEY,
rskTestnet: process.env.BLOCKSCOUT_API_KEY,
sepolia: process.env.ETHERSCAN_API_KEY,
neon: process.env.NEONSCAN_API_KEY,
neondevnet: process.env.NEONSCAN_API_KEY,
},
customChains: [
{
Expand Down Expand Up @@ -211,6 +221,22 @@ module.exports = {
browserURL: explorerUrls[ChainIds.ARBITRUMSEPOLIA],
},
},
{
network: 'neon',
chainId: ChainIds.NEON,
urls: {
apiURL: explorerApiUrls[ChainIds.NEON],
browserURL: explorerUrls[ChainIds.NEON],
},
},
{
network: 'neondevnet',
chainId: ChainIds.NEONDEVNET,
urls: {
apiURL: explorerApiUrls[ChainIds.NEONDEVNET],
browserURL: explorerUrls[ChainIds.NEONDEVNET],
},
},
],
},
gasReporter: {
Expand Down
31 changes: 26 additions & 5 deletions source/batch-call/contracts/BatchCall.sol
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.23;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { ERC20 } from "solady/src/tokens/ERC20.sol";
import "@openzeppelin/contracts/utils/Address.sol";
import "@airswap/swap/contracts/interfaces/ISwap.sol";
import "@airswap/swap-erc20/contracts/interfaces/ISwapERC20.sol";
import "@airswap/registry/contracts/interfaces/IRegistry.sol";

/**
* @title BatchCall: Batch balance, allowance, order validity checks, nonce usage check
*/
contract BatchCall {
using SafeERC20 for IERC20;
using Address for address;

error ArgumentInvalid();
Expand All @@ -28,7 +27,7 @@ contract BatchCall {
address tokenAddress
) public view returns (uint256) {
if (tokenAddress.isContract()) {
IERC20 token = IERC20(tokenAddress);
ERC20 token = ERC20(tokenAddress);
// Check if balanceOf succeeds.
(bool success, ) = address(token).staticcall(
abi.encodeWithSelector(token.balanceOf.selector, userAddress)
Expand Down Expand Up @@ -119,7 +118,7 @@ contract BatchCall {
address tokenAddress
) public view returns (uint256) {
if (tokenAddress.isContract()) {
IERC20 token = IERC20(tokenAddress);
ERC20 token = ERC20(tokenAddress);
// Check if allowance succeeds as a call else returns 0.
(bool success, ) = address(token).staticcall(
abi.encodeWithSelector(
Expand Down Expand Up @@ -290,4 +289,26 @@ contract BatchCall {
}
return nonceUsed;
}

/**
* @notice provides the tokens supported by multiple Stakers
* @param stakers address[] list of stakers to be checked
* @param registryContract IRegistry Registry contract to call
* @return bool[] true indicates the nonce is used
*/
function getTokensForStakers(
address[] calldata stakers,
IRegistry registryContract
) external view returns (address[][] memory) {
if (stakers.length == 0) revert ArgumentInvalid();
address[][] memory tokensSupported = new address[][](stakers.length);

for (uint256 i; i < stakers.length; ) {
tokensSupported[i] = registryContract.getTokensForStaker(stakers[i]);
unchecked {
++i;
}
}
return tokensSupported;
}
}
2 changes: 2 additions & 0 deletions source/batch-call/deploys-blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ module.exports = {
84532: 5688630,
421614: 11923855,
11155111: 5225773,
245022926: 308301583,
245022934: 277791498,
}
2 changes: 2 additions & 0 deletions source/batch-call/deploys.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ module.exports = {
84532: '0xd88cf00477B0Edd2C514e6474Ecfc44222830F58',
421614: '0xd88cf00477B0Edd2C514e6474Ecfc44222830F58',
11155111: '0xd88cf00477B0Edd2C514e6474Ecfc44222830F58',
245022926: '0x37e65CCF8a60E2420dEe21D9B0D98960Ea4d307D',
245022934: '0xD82E10B9A4107939e55fCCa9B53A9ede6CF2fC46',
}
2 changes: 1 addition & 1 deletion source/batch-call/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"owners": "hardhat run ./scripts/owner.js"
},
"devDependencies": {
"@airswap/utils": "4.3.3",
"@airswap/utils": "4.3.4",
"@airswap/swap": "4.2.2",
"@airswap/swap-erc20": "4.3.1",
"@openzeppelin/contracts": "^4.8.3",
Expand Down
95 changes: 93 additions & 2 deletions source/batch-call/test/BatchCall.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const { ethers, waffle } = require('hardhat')
const { deployMockContract } = waffle
const IERC20 = require('@openzeppelin/contracts/build/contracts/IERC20.json')
const IERC721 = require('@openzeppelin/contracts/build/contracts/ERC721Royalty.json')
const REGISTRY = require('@airswap/registry/build/contracts/Registry.sol/Registry.json')
const SWAP = require('@airswap/swap/build/contracts/Swap.sol/Swap.json')
const SWAP_ERC20 = require('@airswap/swap-erc20/build/contracts/SwapERC20.sol/SwapERC20.json')
const ERC20_ADAPTER = require('@airswap/swap/build/contracts/adapters/ERC20Adapter.sol/ERC20Adapter.json')
Expand All @@ -22,6 +23,8 @@ const DEFAULT_AMOUNT = '1000'
const DEFAULT_BALANCE = '100000'
const BONUS_SCALE = '10'
const BONUS_MAX = '100'
const STAKING_COST = '1000000000'
const SUPPORT_COST = '1000000'

let snapshotId
let deployer
Expand All @@ -31,6 +34,7 @@ let erc20token
let erc20adapter
let erc721token
let erc721adapter
let registry
let swap
let swapERC20
let batchCall
Expand Down Expand Up @@ -107,6 +111,15 @@ async function setUpAllowances(senderAmount, signerAmount) {
async function setUpBalances(senderAmount, signerAmount) {
await erc20token.mock.balanceOf.withArgs(sender.address).returns(senderAmount)
await erc20token.mock.balanceOf.withArgs(signer.address).returns(signerAmount)
await erc20token.mock.balanceOf
.withArgs(staker1.address)
.returns(STAKING_COST)
await erc20token.mock.balanceOf
.withArgs(staker2.address)
.returns(STAKING_COST)
await erc20token.mock.balanceOf
.withArgs(staker3.address)
.returns(STAKING_COST)
}

describe('BatchCall Integration', () => {
Expand All @@ -119,8 +132,17 @@ describe('BatchCall Integration', () => {
})

before('deploy adapter and swap', async () => {
;[deployer, sender, signer, affiliate, protocolFeeWallet, anyone] =
await ethers.getSigners()
;[
deployer,
sender,
signer,
affiliate,
protocolFeeWallet,
anyone,
staker1,
staker2,
staker3,
] = await ethers.getSigners()
erc20token = await deployMockContract(deployer, IERC20.abi)
await erc20token.mock.allowance.returns(DEFAULT_AMOUNT)
await erc20token.mock.balanceOf.returns(DEFAULT_AMOUNT)
Expand All @@ -143,6 +165,12 @@ describe('BatchCall Integration', () => {
)
).deploy()
await erc721adapter.deployed()

registry = await (
await ethers.getContractFactory(REGISTRY.abi, REGISTRY.bytecode)
).deploy(erc20token.address, STAKING_COST, SUPPORT_COST)
await registry.deployed()

swap = await (
await ethers.getContractFactory(SWAP.abi, SWAP.bytecode)
).deploy(
Expand Down Expand Up @@ -329,4 +357,67 @@ describe('BatchCall Integration', () => {
)
})
})

describe('returns tokensSupported for mutiple stakers', () => {
it('returns all tokens supported by multiple stakers', async () => {
const tokensSupported = []
for (let i = 0; i < 10; i++) {
tokensSupported[i] = await deployMockContract(deployer, IERC20.abi)
}
registry
.connect(staker1)
.addTokens([
tokensSupported[0].address,
tokensSupported[1].address,
tokensSupported[2].address,
])
registry
.connect(staker2)
.addTokens([
tokensSupported[3].address,
tokensSupported[4].address,
tokensSupported[5].address,
])
registry
.connect(staker3)
.addTokens([
tokensSupported[6].address,
tokensSupported[7].address,
tokensSupported[8].address,
tokensSupported[9].address,
])
const expectedTokensSupported = await batchCall
.connect(deployer)
.getTokensForStakers(
[staker1.address, staker2.address, staker3.address],
registry.address
)
expect(expectedTokensSupported.toString()).to.equal(
[
[
tokensSupported[0].address,
tokensSupported[1].address,
tokensSupported[2].address,
],
[
tokensSupported[3].address,
tokensSupported[4].address,
tokensSupported[5].address,
],
[
tokensSupported[6].address,
tokensSupported[7].address,
tokensSupported[8].address,
tokensSupported[9].address,
],
].toString()
)
})

it('reverts if a wrong argument is passed', async () => {
await expect(
batchCall.getTokensForStakers([], registry.address)
).to.be.revertedWith('ArgumentInvalid')
})
})
})
2 changes: 2 additions & 0 deletions source/pool/deploys-blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ module.exports = {
84531: 10978032,
421613: 47402006,
11155111: 4509265,
245022926: 308305928,
245022934: 277791732,
}
2 changes: 2 additions & 0 deletions source/pool/deploys.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ module.exports = {
84531: '0xbbcec987E4C189FCbAB0a2534c77b3ba89229F11',
421613: '0xbbcec987E4C189FCbAB0a2534c77b3ba89229F11',
11155111: '0xbbcec987E4C189FCbAB0a2534c77b3ba89229F11',
245022926: '0x6d982E13e39991c7492b85bC052bfBFcFca9C376',
245022934: '0x6D61CDE28EF2Df6AB4d728A6f283Ad09B8E5d7b0',
}
2 changes: 1 addition & 1 deletion source/pool/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"balances": "hardhat run ./scripts/balances.js"
},
"devDependencies": {
"@airswap/utils": "4.3.3",
"@airswap/utils": "4.3.4",
"@airswap/merkle": "0.0.2",
"@openzeppelin/contracts": "^4.8.3",
"prompt-confirm": "^2.0.4"
Expand Down
23 changes: 2 additions & 21 deletions source/registry/contracts/Registry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ pragma solidity 0.8.23;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import "./interfaces/IRegistry.sol";

/**
* @title AirSwap: Server Registry
* @notice https://www.airswap.io/
*/
contract Registry {
contract Registry is IRegistry {
using SafeERC20 for IERC20;
using EnumerableSet for EnumerableSet.AddressSet;
using EnumerableSet for EnumerableSet.Bytes32Set;
Expand All @@ -25,26 +26,6 @@ contract Registry {
mapping(address => EnumerableSet.AddressSet) internal tokensByStaker;
mapping(address => EnumerableSet.AddressSet) internal stakersByToken;

event SetServerURL(address indexed staker, string url);
event AddProtocols(address indexed staker, bytes4[] protocols);
event AddTokens(address indexed staker, address[] tokens);
event RemoveProtocols(address indexed staker, bytes4[] protocols);
event RemoveTokens(address indexed staker, address[] tokens);
event UnsetServer(
address indexed staker,
string url,
bytes4[] protocols,
address[] tokens
);

error ArgumentInvalid();
error NoServerURLSet();
error ProtocolDoesNotExist(bytes4);
error ProtocolExists(bytes4);
error TokenDoesNotExist(address);
error TokenExists(address);
error ServerURLInvalid();

/**
* @notice Registry constructor
* @param _stakingToken IERC20 address of token used for staking
Expand Down
Loading

0 comments on commit 8b67963

Please sign in to comment.