diff --git a/source/batch-call/package.json b/source/batch-call/package.json index fab0337e8..fa3e481c7 100644 --- a/source/batch-call/package.json +++ b/source/batch-call/package.json @@ -24,7 +24,7 @@ "owners": "hardhat run ./scripts/owner.js" }, "devDependencies": { - "@airswap/utils": "5.0.0", + "@airswap/utils": "5.0.1", "@airswap/swap": "5.0.0", "@airswap/swap-erc20": "5.0.0", "@openzeppelin/contracts": "^4.8.3" diff --git a/source/delegate/package.json b/source/delegate/package.json index 58591e0e1..56be71843 100644 --- a/source/delegate/package.json +++ b/source/delegate/package.json @@ -24,7 +24,7 @@ "owners": "hardhat run ./scripts/owner.js" }, "devDependencies": { - "@airswap/utils": "5.0.0", + "@airswap/utils": "5.0.1", "@airswap/swap-erc20": "5.0.0" }, "publishConfig": { diff --git a/source/pool/package.json b/source/pool/package.json index 7917886b6..e4e1ff60a 100644 --- a/source/pool/package.json +++ b/source/pool/package.json @@ -25,7 +25,7 @@ "balances": "hardhat run ./scripts/balances.js" }, "devDependencies": { - "@airswap/utils": "5.0.0", + "@airswap/utils": "5.0.1", "@airswap/merkle": "0.0.2", "@openzeppelin/contracts": "^4.8.3" }, diff --git a/source/registry/package.json b/source/registry/package.json index fa86a7429..15ca93fa8 100644 --- a/source/registry/package.json +++ b/source/registry/package.json @@ -24,7 +24,7 @@ "owners": "hardhat run ./scripts/owner.js" }, "devDependencies": { - "@airswap/utils": "5.0.0", + "@airswap/utils": "5.0.1", "@openzeppelin/contracts": "^4.8.3" }, "publishConfig": { diff --git a/source/staking/package.json b/source/staking/package.json index 04564049f..c313805dc 100644 --- a/source/staking/package.json +++ b/source/staking/package.json @@ -24,7 +24,7 @@ "owners": "hardhat run ./scripts/owner.js" }, "devDependencies": { - "@airswap/utils": "5.0.0", + "@airswap/utils": "5.0.1", "@openzeppelin/contracts": "^4.8.3" }, "publishConfig": { diff --git a/source/swap-erc20/package.json b/source/swap-erc20/package.json index 5b1375967..f08e71c3b 100644 --- a/source/swap-erc20/package.json +++ b/source/swap-erc20/package.json @@ -25,7 +25,7 @@ }, "devDependencies": { "@airswap/staking": "5.0.0", - "@airswap/utils": "5.0.0", + "@airswap/utils": "5.0.1", "solady": "0.0.173" }, "publishConfig": { diff --git a/source/swap/package.json b/source/swap/package.json index c328403a1..0cf02aaa4 100644 --- a/source/swap/package.json +++ b/source/swap/package.json @@ -26,7 +26,7 @@ "owners": "hardhat run ./scripts/owner.js" }, "devDependencies": { - "@airswap/utils": "5.0.0", + "@airswap/utils": "5.0.1", "@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..7c91b70c9 100644 --- a/source/wrapper/package.json +++ b/source/wrapper/package.json @@ -24,7 +24,7 @@ "owners": "hardhat run ./scripts/owner.js" }, "devDependencies": { - "@airswap/utils": "5.0.0", + "@airswap/utils": "5.0.1", "@airswap/swap-erc20": "5.0.0", "@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 b050a65c9..e8be538f5 100644 --- a/tools/libraries/package.json +++ b/tools/libraries/package.json @@ -30,7 +30,7 @@ "@airswap/staking": "5.0.0", "@airswap/swap": "5.0.0", "@airswap/swap-erc20": "5.0.0", - "@airswap/utils": "5.0.0", + "@airswap/utils": "5.0.1", "@airswap/wrapper": "5.0.0", "browser-or-node": "^2.1.1", "ethers": "^5.7.2", diff --git a/tools/stores/package.json b/tools/stores/package.json index 8fa6dbc16..57b3d82cd 100644 --- a/tools/stores/package.json +++ b/tools/stores/package.json @@ -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.1", "redis": "^4.6.13" }, "devDependencies": { diff --git a/tools/utils/package.json b/tools/utils/package.json index 6bf6bd8df..95658e987 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.1", "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 98568fece..9fc30291d 100644 --- a/tools/utils/src/swap-erc20.ts +++ b/tools/utils/src/swap-erc20.ts @@ -18,7 +18,7 @@ import { DOMAIN_NAME_SWAP_ERC20, } from './constants' -import { Signature, Settlement } from './types' +import { 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) => { +const parseTransfer = (log: any): Transfer | null => { let parsed let transfer try { @@ -351,33 +351,20 @@ const parseTransfer = (log: 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 - - feeReceiver = feeReceiver.toLowerCase() - signerWallet = signerWallet.toLowerCase() - - while (length--) { - if ((transfer = parseTransfer(logs[length]))) { - 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) { - fee = transfers[i] + feeTransfer = transfers[i] } else { let j = transfers.length while (j--) { @@ -386,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: Either signer or sender 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.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 {