diff --git a/source/batch-call/package.json b/source/batch-call/package.json index fab0337e8..818206a75 100644 --- a/source/batch-call/package.json +++ b/source/batch-call/package.json @@ -1,6 +1,6 @@ { "name": "@airswap/batch-call", - "version": "5.0.0", + "version": "5.0.1", "description": "AirSwap: Balance, Allowance, Validity Checks", "license": "MIT", "repository": { @@ -12,6 +12,8 @@ "./typechain", "./deploys*" ], + "main": "typechain/index.js", + "types": "typechain/index.ts", "scripts": { "clean": "rm -rf ./cache && rm -rf ./build && rm -rf ./typechain", "compile": "hardhat compile; yarn typechain", @@ -23,10 +25,13 @@ "verify": "hardhat run ./scripts/verify.js", "owners": "hardhat run ./scripts/owner.js" }, + "dependencies": { + "ethers": "^5.7.2" + }, "devDependencies": { - "@airswap/utils": "5.0.0", - "@airswap/swap": "5.0.0", - "@airswap/swap-erc20": "5.0.0", + "@airswap/utils": "5.0.2", + "@airswap/swap": "5.0.1", + "@airswap/swap-erc20": "5.0.1", "@openzeppelin/contracts": "^4.8.3" }, "publishConfig": { diff --git a/source/delegate/package.json b/source/delegate/package.json index 58591e0e1..2238faf94 100644 --- a/source/delegate/package.json +++ b/source/delegate/package.json @@ -1,6 +1,6 @@ { "name": "@airswap/delegate", - "version": "5.0.0", + "version": "5.0.1", "description": "AirSwap: Delegated On-chain Trading Rules", "license": "MIT", "repository": { @@ -12,6 +12,8 @@ "./typechain", "./deploys*" ], + "main": "typechain/index.js", + "types": "typechain/index.ts", "scripts": { "clean": "rm -rf ./cache && rm -rf ./build && rm -rf ./typechain", "compile": "hardhat compile; yarn typechain", @@ -23,9 +25,12 @@ "verify": "hardhat run ./scripts/verify.js", "owners": "hardhat run ./scripts/owner.js" }, + "dependencies": { + "ethers": "^5.7.2" + }, "devDependencies": { - "@airswap/utils": "5.0.0", - "@airswap/swap-erc20": "5.0.0" + "@airswap/utils": "5.0.2", + "@airswap/swap-erc20": "5.0.1" }, "publishConfig": { "access": "public" diff --git a/source/pool/package.json b/source/pool/package.json index 7917886b6..6a02741ac 100644 --- a/source/pool/package.json +++ b/source/pool/package.json @@ -1,6 +1,6 @@ { "name": "@airswap/pool", - "version": "5.0.0", + "version": "5.0.1", "description": "AirSwap: Withdrawable Token Pool", "license": "MIT", "repository": { @@ -12,6 +12,8 @@ "./typechain", "./deploys*" ], + "main": "typechain/index.js", + "types": "typechain/index.ts", "scripts": { "clean": "rm -rf ./cache && rm -rf ./build && rm -rf ./typechain", "compile": "hardhat compile; yarn typechain", @@ -24,8 +26,11 @@ "owners": "hardhat run ./scripts/owner.js", "balances": "hardhat run ./scripts/balances.js" }, + "dependencies": { + "ethers": "^5.7.2" + }, "devDependencies": { - "@airswap/utils": "5.0.0", + "@airswap/utils": "5.0.2", "@airswap/merkle": "0.0.2", "@openzeppelin/contracts": "^4.8.3" }, diff --git a/source/registry/package.json b/source/registry/package.json index fa86a7429..d3121fa4c 100644 --- a/source/registry/package.json +++ b/source/registry/package.json @@ -1,6 +1,6 @@ { "name": "@airswap/registry", - "version": "5.0.0", + "version": "5.0.1", "description": "AirSwap: Server Registry", "license": "MIT", "repository": { @@ -12,6 +12,8 @@ "./typechain", "./deploys*" ], + "main": "typechain/index.js", + "types": "typechain/index.ts", "scripts": { "clean": "rm -rf ./cache && rm -rf ./build && rm -rf ./typechain", "compile": "hardhat compile; yarn typechain", @@ -23,8 +25,11 @@ "verify": "hardhat run ./scripts/verify.js", "owners": "hardhat run ./scripts/owner.js" }, + "dependencies": { + "ethers": "^5.7.2" + }, "devDependencies": { - "@airswap/utils": "5.0.0", + "@airswap/utils": "5.0.2", "@openzeppelin/contracts": "^4.8.3" }, "publishConfig": { diff --git a/source/staking/package.json b/source/staking/package.json index 04564049f..dbee452c7 100644 --- a/source/staking/package.json +++ b/source/staking/package.json @@ -1,6 +1,6 @@ { "name": "@airswap/staking", - "version": "5.0.0", + "version": "5.0.1", "description": "AirSwap: Stake Tokens", "license": "MIT", "repository": { @@ -12,6 +12,8 @@ "./typechain", "./deploys*" ], + "main": "typechain/index.js", + "types": "typechain/index.ts", "scripts": { "clean": "rm -rf ./cache && rm -rf ./build && rm -rf ./typechain", "compile": "hardhat compile; yarn typechain", @@ -23,8 +25,11 @@ "verify": "hardhat run ./scripts/verify.js", "owners": "hardhat run ./scripts/owner.js" }, + "dependencies": { + "ethers": "^5.7.2" + }, "devDependencies": { - "@airswap/utils": "5.0.0", + "@airswap/utils": "5.0.2", "@openzeppelin/contracts": "^4.8.3" }, "publishConfig": { diff --git a/source/swap-erc20/package.json b/source/swap-erc20/package.json index 5b1375967..f791939b8 100644 --- a/source/swap-erc20/package.json +++ b/source/swap-erc20/package.json @@ -1,6 +1,6 @@ { "name": "@airswap/swap-erc20", - "version": "5.0.0", + "version": "5.0.1", "description": "AirSwap: Atomic ERC20 Token Swap", "license": "MIT", "repository": { @@ -12,6 +12,8 @@ "./typechain", "./deploys*" ], + "main": "typechain/index.js", + "types": "typechain/index.ts", "scripts": { "clean": "rm -rf ./cache && rm -rf ./build && rm -rf ./typechain", "compile": "hardhat compile; yarn typechain", @@ -23,9 +25,12 @@ "verify": "hardhat run ./scripts/verify.js", "owners": "hardhat run ./scripts/owner.js" }, + "dependencies": { + "ethers": "^5.7.2" + }, "devDependencies": { - "@airswap/staking": "5.0.0", - "@airswap/utils": "5.0.0", + "@airswap/staking": "5.0.1", + "@airswap/utils": "5.0.2", "solady": "0.0.173" }, "publishConfig": { diff --git a/source/swap/package.json b/source/swap/package.json index c328403a1..3f48e1463 100644 --- a/source/swap/package.json +++ b/source/swap/package.json @@ -1,6 +1,6 @@ { "name": "@airswap/swap", - "version": "5.0.0", + "version": "5.0.1", "description": "AirSwap: Atomic Token Swap", "license": "MIT", "repository": { @@ -12,6 +12,8 @@ "./typechain", "./deploys*" ], + "main": "typechain/index.js", + "types": "typechain/index.ts", "scripts": { "clean": "rm -rf ./cache && rm -rf ./build && rm -rf ./typechain", "compile": "hardhat compile; yarn typechain", @@ -25,8 +27,11 @@ "verify-adapters": "hardhat run ./scripts/verify-adapters.js", "owners": "hardhat run ./scripts/owner.js" }, + "dependencies": { + "ethers": "^5.7.2" + }, "devDependencies": { - "@airswap/utils": "5.0.0", + "@airswap/utils": "5.0.2", "@nomicfoundation/hardhat-network-helpers": "^1.0.7", "@openzeppelin/contracts": "^4.8.3" }, diff --git a/source/wrapper/package.json b/source/wrapper/package.json index 6a38cf7b3..3237c7bcc 100644 --- a/source/wrapper/package.json +++ b/source/wrapper/package.json @@ -1,6 +1,6 @@ { "name": "@airswap/wrapper", - "version": "5.0.0", + "version": "5.0.1", "description": "AirSwap: Wrap and Unwrap Native Tokens", "license": "MIT", "repository": { @@ -12,6 +12,8 @@ "./typechain", "./deploys*" ], + "main": "typechain/index.js", + "types": "typechain/index.ts", "scripts": { "clean": "rm -rf ./cache && rm -rf ./build && rm -rf ./typechain", "compile": "hardhat compile; yarn typechain", @@ -24,8 +26,8 @@ "owners": "hardhat run ./scripts/owner.js" }, "devDependencies": { - "@airswap/utils": "5.0.0", - "@airswap/swap-erc20": "5.0.0", + "@airswap/utils": "5.0.2", + "@airswap/swap-erc20": "5.0.1", "@openzeppelin/contracts": "^4.8.3", "@uniswap/v2-periphery": "^1.1.0-beta.0" }, diff --git a/tools/libraries/package.json b/tools/libraries/package.json index 7afffdee6..5b4ee5787 100644 --- a/tools/libraries/package.json +++ b/tools/libraries/package.json @@ -1,6 +1,6 @@ { "name": "@airswap/libraries", - "version": "5.0.0", + "version": "5.0.3", "description": "AirSwap: Libraries for Developers", "repository": { "type": "git", @@ -22,15 +22,16 @@ "test:ci": "yarn test" }, "dependencies": { - "@airswap/batch-call": "5.0.0", + "@airswap/batch-call": "5.0.1", "@airswap/jsonrpc-client-websocket": "0.0.1", - "@airswap/pool": "5.0.0", - "@airswap/registry": "5.0.0", - "@airswap/staking": "5.0.0", - "@airswap/swap": "5.0.0", - "@airswap/swap-erc20": "5.0.0", - "@airswap/utils": "5.0.0", - "@airswap/wrapper": "5.0.0", + "@airswap/delegate": "5.0.1", + "@airswap/pool": "5.0.1", + "@airswap/registry": "5.0.1", + "@airswap/staking": "5.0.1", + "@airswap/swap": "5.0.1", + "@airswap/swap-erc20": "5.0.1", + "@airswap/utils": "5.0.2", + "@airswap/wrapper": "5.0.1", "browser-or-node": "^2.1.1", "ethers": "^5.7.2", "jayson": "^4.0.0", diff --git a/tools/stores/package.json b/tools/stores/package.json index 8fa6dbc16..b9571e6f7 100644 --- a/tools/stores/package.json +++ b/tools/stores/package.json @@ -1,6 +1,6 @@ { "name": "@airswap/stores", - "version": "5.0.0", + "version": "5.0.1", "description": "AirSwap: Storage for Indexing", "repository": { "type": "git", @@ -22,7 +22,7 @@ "test": "REDISCLOUD_URL=redis://localhost:6379 TS_NODE_COMPILER_OPTIONS='{\"strict\":false}' yarn mocha -r ts-node/esm test/*.ts" }, "dependencies": { - "@airswap/utils": "5.0.0", + "@airswap/utils": "5.0.2", "redis": "^4.6.13" }, "devDependencies": { diff --git a/tools/utils/package.json b/tools/utils/package.json index 6bf6bd8df..e3ca6479f 100644 --- a/tools/utils/package.json +++ b/tools/utils/package.json @@ -1,6 +1,6 @@ { "name": "@airswap/utils", - "version": "5.0.0", + "version": "5.0.2", "description": "AirSwap: Utilities for Developers", "repository": { "type": "git", diff --git a/tools/utils/src/swap-erc20.ts b/tools/utils/src/swap-erc20.ts index d6f392827..8532cc9cd 100644 --- a/tools/utils/src/swap-erc20.ts +++ b/tools/utils/src/swap-erc20.ts @@ -18,7 +18,7 @@ import { SECONDS_IN_DAY, } from './constants' -import type { Settlement, Signature } from './types' +import type { Signature, Settlement, Transfer } from './types' export const EIP712SwapERC20 = { EIP712Domain: [ @@ -332,7 +332,7 @@ export function decompressFullOrderERC20(str: string): FullOrderERC20 { return paramsToFullOrderERC20(lzString.decompressFromEncodedURIComponent(str)) } -const parseTransfer = (log: any): any => { +const parseTransfer = (log: any): Transfer | null => { let parsed: any let transfer: any try { @@ -351,31 +351,20 @@ const parseTransfer = (log: any): any => { return transfer } -export const getFullSwapERC20 = async ( +export const getFullSwapERC20FromTransfers = ( nonce: string, signerWallet: string, feeReceiver: string, - logs: ethers.providers.Log[] -): Promise => { - const transfers = [] - let transfer: any - let length = logs.length - - while (length--) { - transfer = parseTransfer(logs[length]) - if (transfer) { - transfers.push(transfer) - } - } - - let fee: any - let signer: any - let sender: any + transfers: Transfer[] +): FullSwapERC20 => { + let feeTransfer: Transfer | null + let signerTransfer: Transfer | null + let senderTransfer: Transfer | null let i = transfers.length while (i--) { - if (transfers[i].to === feeReceiver.toLowerCase()) { - fee = transfers[i] + if (transfers[i].to === feeReceiver) { + feeTransfer = transfers[i] } else { let j = transfers.length while (j--) { @@ -384,26 +373,53 @@ export const getFullSwapERC20 = async ( transfers[i].from === transfers[j].to && transfers[i].to === transfers[j].from ) { - signer = transfers[i] - sender = transfers[j] + signerTransfer = transfers[i] + senderTransfer = transfers[j] break } } } } - if (!signer || !sender) { - throw new Error('getFullSwapERC20: Swap not found') + if (!signerTransfer || !senderTransfer) { + throw new Error('getFullSwapERC20: mutual transfers not found') } return { nonce: nonce.toString(), - signerWallet: signer.from, - signerToken: signer.token, - signerAmount: signer.amount.toString(), - senderWallet: sender.from, - senderToken: sender.token, - senderAmount: sender.amount.toString(), - feeAmount: fee.amount.toString(), + signerWallet: signerTransfer.from, + signerToken: signerTransfer.token, + signerAmount: signerTransfer.amount.toString(), + senderWallet: senderTransfer.from, + senderToken: senderTransfer.token, + senderAmount: senderTransfer.amount.toString(), + feeAmount: (feeTransfer?.amount || 0).toString(), } } + +export const getFullSwapERC20 = ( + nonce: string, + signerWallet: string, + feeReceiver: string, + logs: ethers.providers.Log[] +): FullSwapERC20 => { + const allTransfers: Transfer[] = [] + let transfer: Transfer | null + let length = logs.length + + feeReceiver = feeReceiver.toLowerCase() + signerWallet = signerWallet.toLowerCase() + + while (length--) { + if ((transfer = parseTransfer(logs[length]))) { + allTransfers.push(transfer) + } + } + + return getFullSwapERC20FromTransfers( + nonce, + signerWallet, + feeReceiver, + allTransfers + ) +} diff --git a/tools/utils/src/types.ts b/tools/utils/src/types.ts index 79cac8b43..f27c1a11f 100644 --- a/tools/utils/src/types.ts +++ b/tools/utils/src/types.ts @@ -15,6 +15,13 @@ export type Token = { decimals: number } +export type Transfer = { + from: string + to: string + token: string + amount: string +} + export type { TokenInfo } from '@uniswap/token-lists' export interface CollectionTokenAttribute {