diff --git a/source/balances/package.json b/source/balances/package.json index dcecf9f6b..9b6bbaf78 100644 --- a/source/balances/package.json +++ b/source/balances/package.json @@ -29,7 +29,7 @@ }, "devDependencies": { "@airswap/constants": "^4.1.0", - "@airswap/utils": "^4.1.0", + "@airswap/utils": "^4.1.1", "prompt-confirm": "^2.0.4" }, "publishConfig": { diff --git a/source/pool/package.json b/source/pool/package.json index 71952c346..60843a536 100644 --- a/source/pool/package.json +++ b/source/pool/package.json @@ -29,8 +29,8 @@ }, "devDependencies": { "@airswap/constants": "^4.1.0", - "@airswap/types": "^4.1.0", - "@airswap/utils": "^4.1.0", + "@airswap/types": "^4.1.1", + "@airswap/utils": "^4.1.1", "prompt-confirm": "^2.0.4" }, "publishConfig": { diff --git a/source/registry/package.json b/source/registry/package.json index f940e91fc..8050c8ec5 100644 --- a/source/registry/package.json +++ b/source/registry/package.json @@ -32,7 +32,7 @@ }, "devDependencies": { "@airswap/constants": "^4.1.0", - "@airswap/utils": "^4.1.0", + "@airswap/utils": "^4.1.1", "prompt-confirm": "^2.0.4" } } diff --git a/source/staking/package.json b/source/staking/package.json index 672e211d4..f535732dc 100644 --- a/source/staking/package.json +++ b/source/staking/package.json @@ -31,7 +31,7 @@ "access": "public" }, "devDependencies": { - "@airswap/utils": "^4.1.0", + "@airswap/utils": "^4.1.1", "prompt-confirm": "^2.0.4" } } diff --git a/source/swap-erc20/package.json b/source/swap-erc20/package.json index c745dca1c..a0eaa608b 100644 --- a/source/swap-erc20/package.json +++ b/source/swap-erc20/package.json @@ -30,8 +30,8 @@ "devDependencies": { "@airswap/constants": "^4.1.0", "@airswap/staking": "4.0.3", - "@airswap/types": "^4.1.0", - "@airswap/utils": "^4.1.0", + "@airswap/types": "^4.1.1", + "@airswap/utils": "^4.1.1", "prompt-confirm": "^2.0.4" }, "publishConfig": { diff --git a/source/swap/package.json b/source/swap/package.json index be7f1634e..e7f1463b4 100644 --- a/source/swap/package.json +++ b/source/swap/package.json @@ -33,8 +33,8 @@ }, "devDependencies": { "@airswap/constants": "^4.1.0", - "@airswap/types": "^4.1.0", - "@airswap/utils": "^4.1.0", + "@airswap/types": "^4.1.1", + "@airswap/utils": "^4.1.1", "@nomicfoundation/hardhat-network-helpers": "^1.0.7" }, "publishConfig": { diff --git a/source/wrapper/package.json b/source/wrapper/package.json index b1ee56519..453e25862 100644 --- a/source/wrapper/package.json +++ b/source/wrapper/package.json @@ -32,8 +32,8 @@ }, "devDependencies": { "@airswap/constants": "^4.1.0", - "@airswap/utils": "^4.1.0", - "@airswap/types": "^4.1.0", + "@airswap/utils": "^4.1.1", + "@airswap/types": "^4.1.1", "@uniswap/v2-periphery": "^1.1.0-beta.0", "prompt-confirm": "^2.0.4" }, diff --git a/tools/libraries/package.json b/tools/libraries/package.json index dd2961855..3fe870796 100644 --- a/tools/libraries/package.json +++ b/tools/libraries/package.json @@ -1,6 +1,6 @@ { "name": "@airswap/libraries", - "version": "4.1.2", + "version": "4.1.3", "description": "AirSwap: Libraries for Developers", "repository": { "type": "git", @@ -27,7 +27,7 @@ }, "dependencies": { "@airswap/balances": "4.0.2", - "@airswap/constants": "4.1.0", + "@airswap/constants": "^4.1.0", "@airswap/jsonrpc-client-websocket": "0.0.1", "@airswap/registry": "4.1.0", "@airswap/maker-registry": "4.0.4", @@ -35,8 +35,8 @@ "@airswap/staking": "4.0.3", "@airswap/swap": "4.0.4", "@airswap/swap-erc20": "4.1.0", - "@airswap/types": "4.1.0", - "@airswap/utils": "4.1.0", + "@airswap/types": "^4.1.1", + "@airswap/utils": "^4.1.1", "@airswap/wrapper": "4.1.0", "browser-or-node": "^2.1.1", "ethers": "^5.6.9", diff --git a/tools/metadata/package.json b/tools/metadata/package.json index fc2f24cf7..875ad8962 100644 --- a/tools/metadata/package.json +++ b/tools/metadata/package.json @@ -1,6 +1,6 @@ { "name": "@airswap/metadata", - "version": "4.1.0", + "version": "4.1.1", "description": "AirSwap: Token Metadata for Developers", "repository": { "type": "git", @@ -21,7 +21,7 @@ }, "dependencies": { "@airswap/constants": "^4.1.0", - "@airswap/types": "^4.1.0", + "@airswap/types": "^4.1.1", "@airswap/wrapper": "4.1.0", "@openzeppelin/contracts": "^4.8.3", "@uniswap/token-lists": "^1.0.0-beta.24", diff --git a/tools/types/package.json b/tools/types/package.json index a71edd3d2..75871cad7 100644 --- a/tools/types/package.json +++ b/tools/types/package.json @@ -1,6 +1,6 @@ { "name": "@airswap/types", - "version": "4.1.0", + "version": "4.1.1", "description": "AirSwap: Types for Developers", "repository": { "type": "git", diff --git a/tools/types/src/typescript.ts b/tools/types/src/typescript.ts index 0d51180be..95d3bd69e 100644 --- a/tools/types/src/typescript.ts +++ b/tools/types/src/typescript.ts @@ -55,6 +55,20 @@ export type OrderERC20 = { export type FullOrderERC20 = UnsignedOrderERC20 & Signature & Settlement +export type SwapERC20 = { + nonce: string + signerWallet: string +} + +export type FullSwapERC20 = { + signerToken: string + signerAmount: string + senderWallet: string + senderToken: string + senderAmount: string + feeAmount: string +} & SwapERC20 + export type Levels = [string, string][] export type Formula = string diff --git a/tools/utils/index.ts b/tools/utils/index.ts index 90e272840..6a2b8dcaa 100644 --- a/tools/utils/index.ts +++ b/tools/utils/index.ts @@ -1,6 +1,13 @@ import { ethers, BigNumber as BigNumberEthers } from 'ethers' import * as url from 'url' import { explorerUrls } from '@airswap/constants' +import { SwapERC20, FullSwapERC20 } from '@airswap/types' + +import { SwapERC20__factory } from '@airswap/swap-erc20/typechain/factories/contracts' +import { abi as ERC20_ABI } from '@openzeppelin/contracts/build/contracts/ERC20.json' + +const swapInterface = new ethers.utils.Interface(SwapERC20__factory.abi) +const erc20Interface = new ethers.utils.Interface(ERC20_ABI) export * from './src/pricing' export * from './src/swap' @@ -14,6 +21,77 @@ export function getAccountUrl(chainId: number, address: string): string { return `${explorerUrls[chainId]}/address/${address}` } +const parseTransfer = (log: any) => { + let parsed + let transfer + try { + parsed = erc20Interface.parseLog(log) + if (parsed.name === 'Transfer') + transfer = { + token: log.address, + from: parsed.args[0], + to: parsed.args[1], + amount: ethers.BigNumber.from(parsed.args[2]), + } + } catch (e) { + return null + } + return transfer +} + +export const getFullSwapERC20 = async ( + event: SwapERC20, + tx: ethers.providers.TransactionResponse +): Promise => { + const receipt = await tx.wait() + const transfers = [] + for (let i = 0; i < receipt.logs.length; i++) { + let parsed: ethers.utils.LogDescription + try { + parsed = swapInterface.parseLog(receipt.logs[i]) + } catch (e) { + continue + } + if (parsed && parsed.name === 'SwapERC20') { + let transfer: any + while (i--) { + if ((transfer = parseTransfer(receipt.logs[i]))) { + transfers.push(transfer) + } + } + break + } + } + + const [fee, signer, sender] = transfers + if (fee.from !== event.signerWallet) + throw new Error( + 'unable to get SwapERC20 params: found incorrect fee transfer (wrong signerWallet)' + ) + if (signer.from !== event.signerWallet) + throw new Error( + 'unable to get SwapERC20 params: found incorrect signer transfer (wrong signerWallet)' + ) + if (signer.from !== sender.to) + throw new Error( + 'unable to get SwapERC20 params: signer transfer mismatched sender transfer' + ) + if (sender.from !== signer.to) + throw new Error( + 'unable to get SwapERC20 params: sender transfer mismatched signer transfer' + ) + + return { + ...event, + signerToken: signer.token, + signerAmount: signer.amount.toString(), + senderWallet: sender.from, + senderToken: sender.token, + senderAmount: sender.amount.toString(), + feeAmount: fee.amount.toString(), + } +} + export function checkResultToErrors( count: BigNumberEthers, errors: Array diff --git a/tools/utils/package.json b/tools/utils/package.json index 9c909d5d4..28a3a19f6 100644 --- a/tools/utils/package.json +++ b/tools/utils/package.json @@ -1,6 +1,6 @@ { "name": "@airswap/utils", - "version": "4.1.0", + "version": "4.1.1", "description": "AirSwap: Utilities for Developers", "repository": { "type": "git", @@ -22,7 +22,8 @@ }, "dependencies": { "@airswap/constants": "^4.1.0", - "@airswap/types": "^4.0.4", + "@airswap/swap-erc20": "4.1.0", + "@airswap/types": "^4.1.1", "@metamask/eth-sig-util": "^5.0.2", "bignumber.js": "^9.0.1", "ethereumjs-util": "^7.1.5",