Skip to content

Commit

Permalink
Merge pull request #1260 from airswap/develop
Browse files Browse the repository at this point in the history
Publish betas to NPM
  • Loading branch information
dmosites authored Jan 15, 2024
2 parents f0eef52 + 55b00d1 commit 6c1cc86
Show file tree
Hide file tree
Showing 42 changed files with 338 additions and 275 deletions.
25 changes: 19 additions & 6 deletions hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ const {
*/
module.exports = {
networks: {
goerli: {
url: apiUrls[ChainIds.GOERLI] + '/' + process.env.INFURA_API_KEY,
mainnet: {
url: apiUrls[ChainIds.MAINNET],
accounts: process.env.PRIVATE_KEY ? [process.env.PRIVATE_KEY] : undefined,
},
mainnet: {
url: apiUrls[ChainIds.MAINNET] + '/' + process.env.INFURA_API_KEY,
goerli: {
url: apiUrls[ChainIds.GOERLI],
accounts: process.env.PRIVATE_KEY ? [process.env.PRIVATE_KEY] : undefined,
},
bsctestnet: {
Expand Down Expand Up @@ -71,7 +71,7 @@ module.exports = {
accounts: process.env.PRIVATE_KEY ? [process.env.PRIVATE_KEY] : undefined,
},
linea: {
url: apiUrls[ChainIds.LINEA] + '/' + process.env.INFURA_API_KEY,
url: apiUrls[ChainIds.LINEA],
accounts: process.env.PRIVATE_KEY ? [process.env.PRIVATE_KEY] : undefined,
},
basegoerli: {
Expand All @@ -91,7 +91,11 @@ module.exports = {
accounts: process.env.PRIVATE_KEY ? [process.env.PRIVATE_KEY] : undefined,
},
sepolia: {
url: apiUrls[ChainIds.SEPOLIA] + '/' + process.env.INFURA_API_KEY,
url: apiUrls[ChainIds.SEPOLIA],
accounts: process.env.PRIVATE_KEY ? [process.env.PRIVATE_KEY] : undefined,
},
holesky: {
url: apiUrls[ChainIds.HOLESKY],
accounts: process.env.PRIVATE_KEY ? [process.env.PRIVATE_KEY] : undefined,
},
},
Expand Down Expand Up @@ -137,6 +141,7 @@ module.exports = {
arbitrumGoerli: 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,
Expand All @@ -163,6 +168,14 @@ module.exports = {
browserURL: explorerUrls[ChainIds.RSKTESTNET],
},
},
{
network: 'holesky',
chainId: 17000,
urls: {
apiURL: explorerApiUrls[ChainIds.HOLESKY],
browserURL: explorerUrls[ChainIds.HOLESKY],
},
},
{
network: 'linea',
chainId: 59144,
Expand Down
31 changes: 29 additions & 2 deletions source/batch-call/contracts/BatchCall.sol
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ contract BatchCall {
* @return bool[] order validity
*/

function checkOrders(
function getOrdersValid(
address senderWallet,
ISwap.Order[] calldata orders,
ISwap swapContract
Expand All @@ -207,7 +207,7 @@ contract BatchCall {
return orderValidity;
}

function checkOrdersERC20(
function getOrdersValidERC20(
address senderWallet,
ISwapERC20.OrderERC20[] calldata ordersERC20,
ISwapERC20 swapERC20Contract
Expand All @@ -234,4 +234,31 @@ contract BatchCall {
}
return orderValidity;
}

/**
* @notice Check if the nonce for an array of order has been already used or not
* @dev Swap and SwapERC20 nonceUsed function have a similar signature
* @dev The same function can be used for both contract calls
* @dev Returns an array of bool
* @dev return array and will fail if large nonce arrays are inputted
* @param signerWallets[] list of wallets associated with the nonces to be checked
* @param nonces[] list of nonces to be checked
* @param swapContract[] swap or swapERC contract to check nonces from
* @return bool[] nonce validity
*/

function getNoncesUsed(
address[] calldata signerWallets,
uint256[] calldata nonces,
ISwap swapContract
) external view returns (bool[] memory) {
require(signerWallets.length > 0);
require(signerWallets.length == nonces.length);
bool[] memory nonceUsed = new bool[](signerWallets.length);

for (uint256 i = 0; i < signerWallets.length; i++) {
nonceUsed[i] = swapContract.nonceUsed(signerWallets[i], nonces[i]);
}
return nonceUsed;
}
}
5 changes: 3 additions & 2 deletions source/batch-call/deploys-blocks.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module.exports = {
5: 10351183,
11155111: 5059276,
5: 10369619,
17000: 731238,
11155111: 5080685,
}
5 changes: 3 additions & 2 deletions source/batch-call/deploys.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module.exports = {
5: '0x1104d8e1f4499acbabbcd55c9a6c957e1f881318',
11155111: '0x1104D8E1F4499ACbaBBcD55c9A6C957E1F881318',
5: '0x08717c193f63E456971a4098f8e0A3eA8c9CA1A5',
17000: '0x1104D8E1F4499ACbaBBcD55c9A6C957E1F881318',
11155111: '0xCF8EbAd621778b3Ea973Dd12a15b6c90bC14bD3C',
}
8 changes: 4 additions & 4 deletions source/batch-call/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@airswap/batch-call",
"version": "4.1.0-beta.0",
"version": "4.1.0-beta.1",
"description": "Batch balance, allowance, order validity checks",
"license": "MIT",
"repository": {
Expand All @@ -27,11 +27,11 @@
},
"dependencies": {
"@openzeppelin/contracts": "^4.8.3",
"@airswap/swap": "4.1.3-beta.0",
"@airswap/swap-erc20": "4.1.7-beta.0"
"@airswap/swap": "4.1.3-beta.1",
"@airswap/swap-erc20": "4.1.7-beta.1"
},
"devDependencies": {
"@airswap/constants": "4.1.9-beta.0",
"@airswap/constants": "4.1.9-beta.2",
"@airswap/utils": "4.1.12",
"prompt-confirm": "^2.0.4"
},
Expand Down
108 changes: 104 additions & 4 deletions source/batch-call/test/BatchCall.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ describe('BatchCall Integration', () => {
]
const orderValidities = await batchCall
.connect(sender)
.checkOrders(sender.address, orders, swap.address)
.getOrdersValid(sender.address, orders, swap.address)
expect(orderValidities.toString()).to.equal([true, true, true].toString())
})

Expand All @@ -193,7 +193,7 @@ describe('BatchCall Integration', () => {
]
const orderValidities = await batchCall
.connect(sender)
.checkOrdersERC20(sender.address, ERC20orders, swapERC20.address)
.getOrdersValidERC20(sender.address, ERC20orders, swapERC20.address)
expect(orderValidities.toString()).to.equal([true, true, true].toString())
})

Expand All @@ -207,7 +207,7 @@ describe('BatchCall Integration', () => {
]
const orderValidities = await batchCall
.connect(sender)
.checkOrders(sender.address, orders, swap.address)
.getOrdersValid(sender.address, orders, swap.address)
expect(orderValidities.toString()).to.equal(
[false, false, false].toString()
)
Expand All @@ -223,10 +223,110 @@ describe('BatchCall Integration', () => {
]
const orderValidities = await batchCall
.connect(sender)
.checkOrdersERC20(sender.address, ERC20orders, swapERC20.address)
.getOrdersValidERC20(sender.address, ERC20orders, swapERC20.address)
expect(orderValidities.toString()).to.equal(
[false, false, false].toString()
)
})
})

describe('checks nonce validity', () => {
it('unused nonce are marked unused', async () => {
await setUpAllowances(DEFAULT_BALANCE, DEFAULT_BALANCE)
await setUpBalances(DEFAULT_BALANCE, DEFAULT_BALANCE)
const orders = [
await createSignedOrder({}, signer),
await createSignedOrder({}, signer),
await createSignedOrder({}, signer),
]
const orderValidities = await batchCall
.connect(sender)
.getNoncesUsed(
[signer.address, signer.address, signer.address],
[orders[0].nonce, orders[1].nonce, orders[2].nonce],
swap.address
)
expect(orderValidities.toString()).to.equal(
[false, false, false].toString()
)
})

it('unused nonce ERC20 are marked unused', async () => {
await setUpAllowances(DEFAULT_BALANCE, DEFAULT_BALANCE)
await setUpBalances(DEFAULT_BALANCE, DEFAULT_BALANCE)
const ERC20orders = [
await createSignedOrderERC20({}, signer),
await createSignedOrderERC20({}, signer),
await createSignedOrderERC20({}, signer),
]
const orderValidities = await batchCall
.connect(sender)
.getNoncesUsed(
[signer.address, signer.address, signer.address],
[ERC20orders[0].nonce, ERC20orders[1].nonce, ERC20orders[2].nonce],
swapERC20.address
)
expect(orderValidities.toString()).to.equal(
[false, false, false].toString()
)
})

it('used nonces are marked as used', async () => {
const usedNonce = 0
const unusedNonce = 1
const order = await createSignedOrder(
{
nonce: usedNonce,
},
signer
)
await swap.connect(sender).swap(sender.address, 0, order)
const orderValidities = await batchCall
.connect(sender)
.getNoncesUsed(
[signer.address, signer.address, signer.address],
[usedNonce, usedNonce, unusedNonce],
swap.address
)
expect(orderValidities.toString()).to.equal(
[true, true, false].toString()
)
})

it('used nonces ERC20 are marked used', async () => {
const usedNonce = 0
const unusedNonce = 1
const ERC20order = await createSignedOrderERC20(
{
nonce: usedNonce,
},
signer
)
await swapERC20
.connect(sender)
.swap(
sender.address,
ERC20order.nonce,
ERC20order.expiry,
ERC20order.signerWallet,
ERC20order.signerToken,
ERC20order.signerAmount,
ERC20order.senderToken,
ERC20order.senderAmount,
ERC20order.v,
ERC20order.r,
ERC20order.s
)
const orderValidities = await batchCall
.connect(sender)
.getNoncesUsed(
[signer.address, signer.address, signer.address],
[usedNonce, usedNonce, unusedNonce],
swapERC20.address
)
expect(orderValidities.toString()).to.equal(
[true, true, false].toString()
)
})
})
})
1 change: 1 addition & 0 deletions source/pool/deploys-blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module.exports = {
97: 34150670,
137: 48645401,
8453: 5180096,
17000: 731316,
42161: 140046382,
43113: 26720218,
43114: 36367783,
Expand Down
1 change: 1 addition & 0 deletions source/pool/deploys.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module.exports = {
97: '0xbbcec987E4C189FCbAB0a2534c77b3ba89229F11',
137: '0xbbcec987E4C189FCbAB0a2534c77b3ba89229F11',
8453: '0xbbcec987E4C189FCbAB0a2534c77b3ba89229F11',
17000: '0xc0799BA9b7bdBA773F77943a9FD448d188345081',
42161: '0xbbcec987E4C189FCbAB0a2534c77b3ba89229F11',
43113: '0xbbcec987E4C189FCbAB0a2534c77b3ba89229F11',
43114: '0xbbcec987E4C189FCbAB0a2534c77b3ba89229F11',
Expand Down
6 changes: 3 additions & 3 deletions source/pool/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@airswap/pool",
"version": "4.1.4",
"version": "4.1.5-beta.0",
"description": "AirSwap: Withdrawable Token Pool",
"license": "MIT",
"repository": {
Expand Down Expand Up @@ -31,9 +31,9 @@
"@openzeppelin/contracts": "^4.8.3"
},
"devDependencies": {
"@airswap/constants": "4.1.9-beta.0",
"@airswap/constants": "4.1.9-beta.2",
"@airswap/metadata": "4.1.15",
"@airswap/types": "4.1.3",
"@airswap/types": "4.1.4",
"@airswap/utils": "4.1.12",
"prompt-confirm": "^2.0.4"
},
Expand Down
13 changes: 7 additions & 6 deletions source/registry/contracts/Registry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ contract Registry {
msg.sender
];
uint256 _protocolListLength = supportedProtocolList.length();

bytes4[] memory _protocolList = new bytes4[](_protocolListLength);

for (uint256 i = _protocolListLength; i > 0; ) {
Expand All @@ -98,6 +99,7 @@ contract Registry {
msg.sender
];
uint256 _tokenListLength = supportedTokenList.length();

address[] memory _tokenList = new address[](_tokenListLength);

for (uint256 i = _tokenListLength; i > 0; ) {
Expand All @@ -108,19 +110,18 @@ contract Registry {
stakersByToken[_token].remove(msg.sender);
}

string memory _url = stakerServerURLs[msg.sender];

delete stakerServerURLs[msg.sender];

uint256 _transferAmount = stakingCost +
(supportCost * _protocolListLength) +
(supportCost * _tokenListLength);
if (_transferAmount > 0) {
stakingToken.safeTransfer(msg.sender, _transferAmount);
}

emit UnsetServer(
msg.sender,
stakerServerURLs[msg.sender],
_protocolList,
_tokenList
);
emit UnsetServer(msg.sender, _url, _protocolList, _tokenList);
}

/**
Expand Down
5 changes: 3 additions & 2 deletions source/registry/deploys-blocks.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
1: 18262901,
5: 9838505,
5: 10373345,
30: 5709710,
31: 4368351,
40: 305721452,
Expand All @@ -9,6 +9,7 @@ module.exports = {
97: 34026519,
137: 48480674,
8453: 4993843,
17000: 735685,
42161: 138763545,
43113: 26588430,
43114: 36195417,
Expand All @@ -17,5 +18,5 @@ module.exports = {
80001: 40977305,
84531: 10791692,
421613: 46289808,
11155111: 4506628,
11155111: 5084838,
}
Loading

0 comments on commit 6c1cc86

Please sign in to comment.