Adjust linter errors.
This commit is contained in:
@@ -58,11 +58,10 @@ export const getProviderByNetwork = (network: NetworkEnum) => {
|
||||
const chain = network === NetworkEnum.sepolia ? sepolia : rootstock;
|
||||
return createPublicClient({
|
||||
chain,
|
||||
transport: http(getProviderUrl(network))
|
||||
transport: http(getProviderUrl(network)),
|
||||
});
|
||||
};
|
||||
|
||||
export const isPossibleNetwork = (networkChain: NetworkEnum): boolean => {
|
||||
return Number(networkChain) in NetworkEnum;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
import { useUser } from "@/composables/useUser";
|
||||
import { formatEther, decodeEventLog, parseAbi, toHex, type PublicClient, type Address } from "viem";
|
||||
import {
|
||||
formatEther,
|
||||
decodeEventLog,
|
||||
parseAbi,
|
||||
toHex,
|
||||
type PublicClient,
|
||||
} from "viem";
|
||||
|
||||
import p2pix from "@/utils/smart_contract_files/P2PIX.json";
|
||||
import { getContract } from "./provider";
|
||||
import type { ValidDeposit } from "@/model/ValidDeposit";
|
||||
import {
|
||||
getP2PixAddress,
|
||||
getProviderByNetwork,
|
||||
getTokenAddress,
|
||||
} from "./addresses";
|
||||
import { getTokenAddress } from "./addresses";
|
||||
import { NetworkEnum } from "@/model/NetworkEnum";
|
||||
import type { UnreleasedLock } from "@/model/UnreleasedLock";
|
||||
import type { Pix } from "@/model/Pix";
|
||||
@@ -37,16 +39,17 @@ const getNetworksLiquidity = async (): Promise<void> => {
|
||||
|
||||
const getPixKey = async (seller: string, token: string): Promise<string> => {
|
||||
const { address, abi, client } = await getContract();
|
||||
|
||||
|
||||
const pixKeyHex = await client.readContract({
|
||||
address,
|
||||
abi,
|
||||
functionName: 'getPixTarget',
|
||||
args: [seller, token]
|
||||
functionName: "getPixTarget",
|
||||
args: [seller, token],
|
||||
});
|
||||
|
||||
|
||||
// Remove '0x' prefix and convert hex to UTF-8 string
|
||||
const hexString = typeof pixKeyHex === 'string' ? pixKeyHex : toHex(pixKeyHex);
|
||||
const hexString =
|
||||
typeof pixKeyHex === "string" ? pixKeyHex : toHex(pixKeyHex);
|
||||
if (!hexString) throw new Error("PixKey not found");
|
||||
const bytes = new Uint8Array(
|
||||
// @ts-ignore
|
||||
@@ -62,10 +65,10 @@ const getPixKey = async (seller: string, token: string): Promise<string> => {
|
||||
const getValidDeposits = async (
|
||||
token: string,
|
||||
network: NetworkEnum,
|
||||
contractInfo?: { client: any, address: string }
|
||||
contractInfo?: { client: any; address: string }
|
||||
): Promise<ValidDeposit[]> => {
|
||||
let client:PublicClient, address, abi;
|
||||
|
||||
let client: PublicClient, address, abi;
|
||||
|
||||
if (contractInfo) {
|
||||
({ client, address } = contractInfo);
|
||||
abi = p2pix.abi;
|
||||
@@ -76,17 +79,17 @@ const getValidDeposits = async (
|
||||
const depositLogs = await client.getLogs({
|
||||
address,
|
||||
event: parseAbi([
|
||||
"event DepositAdded(address indexed seller, address token, uint256 amount)"
|
||||
"event DepositAdded(address indexed seller, address token, uint256 amount)",
|
||||
])[0],
|
||||
fromBlock: 0n,
|
||||
toBlock: 'latest'
|
||||
toBlock: "latest",
|
||||
});
|
||||
|
||||
if (!contractInfo) {
|
||||
// Get metamask provider contract
|
||||
({ address, abi, client } = await getContract());
|
||||
}
|
||||
|
||||
|
||||
const depositList: { [key: string]: ValidDeposit } = {};
|
||||
|
||||
for (const log of depositLogs) {
|
||||
@@ -94,19 +97,19 @@ const getValidDeposits = async (
|
||||
const decoded = decodeEventLog({
|
||||
abi,
|
||||
data: log.data,
|
||||
topics: log.topics
|
||||
topics: log.topics,
|
||||
});
|
||||
|
||||
|
||||
// Get liquidity only for the selected token
|
||||
if (decoded?.args.token.toLowerCase() !== token.toLowerCase()) continue;
|
||||
|
||||
|
||||
const mappedBalance = await client.readContract({
|
||||
address,
|
||||
abi,
|
||||
functionName: 'getBalance',
|
||||
args: [decoded.args.seller, token]
|
||||
functionName: "getBalance",
|
||||
args: [decoded.args.seller, token],
|
||||
});
|
||||
|
||||
|
||||
let validDeposit: ValidDeposit | null = null;
|
||||
|
||||
if (mappedBalance) {
|
||||
@@ -139,8 +142,8 @@ const getUnreleasedLockById = async (
|
||||
const lock = await client.readContract({
|
||||
address,
|
||||
abi,
|
||||
functionName: 'mapLocks',
|
||||
args: [BigInt(lockID)]
|
||||
functionName: "mapLocks",
|
||||
args: [BigInt(lockID)],
|
||||
});
|
||||
|
||||
const pixTarget = lock.pixTarget;
|
||||
|
||||
@@ -13,8 +13,9 @@ const getPublicClient = (onlyRpcProvider = false) => {
|
||||
const user = useUser();
|
||||
const rpcUrl = getProviderUrl();
|
||||
return createPublicClient({
|
||||
chain: Number(user.networkName.value) === sepolia.id ? sepolia : rootstock,
|
||||
transport: http(rpcUrl)
|
||||
chain:
|
||||
Number(user.networkName.value) === sepolia.id ? sepolia : rootstock,
|
||||
transport: http(rpcUrl),
|
||||
});
|
||||
}
|
||||
return publicClient;
|
||||
@@ -35,16 +36,17 @@ const getContract = async (onlyRpcProvider = false) => {
|
||||
const connectProvider = async (p: any): Promise<void> => {
|
||||
console.log("Connecting to provider...");
|
||||
const user = useUser();
|
||||
const chain = Number(user.networkName.value) === sepolia.id ? sepolia : rootstock;
|
||||
const chain =
|
||||
Number(user.networkName.value) === sepolia.id ? sepolia : rootstock;
|
||||
|
||||
publicClient = createPublicClient({
|
||||
chain,
|
||||
transport: custom(p)
|
||||
transport: custom(p),
|
||||
});
|
||||
|
||||
walletClient = createWalletClient({
|
||||
chain,
|
||||
transport: custom(p)
|
||||
transport: custom(p),
|
||||
});
|
||||
|
||||
await updateWalletStatus();
|
||||
|
||||
@@ -26,8 +26,8 @@ const approveTokens = async (participant: Participant): Promise<any> => {
|
||||
const allowance = await publicClient.readContract({
|
||||
address: tokenAddress,
|
||||
abi: mockToken.abi,
|
||||
functionName: 'allowance',
|
||||
args: [account, getP2PixAddress()]
|
||||
functionName: "allowance",
|
||||
args: [account, getP2PixAddress()],
|
||||
});
|
||||
|
||||
if (allowance < parseEther(participant.offer.toString())) {
|
||||
@@ -35,9 +35,9 @@ const approveTokens = async (participant: Participant): Promise<any> => {
|
||||
const hash = await walletClient.writeContract({
|
||||
address: tokenAddress,
|
||||
abi: mockToken.abi,
|
||||
functionName: 'approve',
|
||||
functionName: "approve",
|
||||
args: [getP2PixAddress(), parseEther(participant.offer.toString())],
|
||||
account
|
||||
account,
|
||||
});
|
||||
|
||||
await publicClient.waitForTransactionReceipt({ hash });
|
||||
@@ -63,15 +63,15 @@ const addDeposit = async (): Promise<any> => {
|
||||
const hash = await walletClient.writeContract({
|
||||
address,
|
||||
abi,
|
||||
functionName: 'deposit',
|
||||
functionName: "deposit",
|
||||
args: [
|
||||
sellerId.id,
|
||||
toHex("", { size: 32 }),
|
||||
getTokenAddress(user.selectedToken.value),
|
||||
parseEther(user.seller.value.offer),
|
||||
true
|
||||
true,
|
||||
],
|
||||
account
|
||||
account,
|
||||
});
|
||||
|
||||
const receipt = await client.waitForTransactionReceipt({ hash });
|
||||
|
||||
@@ -1,16 +1,9 @@
|
||||
import {
|
||||
decodeEventLog,
|
||||
formatEther,
|
||||
getAddress,
|
||||
type Log,
|
||||
parseAbi,
|
||||
} from "viem";
|
||||
import { decodeEventLog, formatEther, type Log, parseAbi } from "viem";
|
||||
import { useUser } from "@/composables/useUser";
|
||||
|
||||
import { getPublicClient, getWalletClient, getContract } from "./provider";
|
||||
import { getTokenAddress, isPossibleNetwork } from "./addresses";
|
||||
import { getTokenAddress } from "./addresses";
|
||||
|
||||
import mockToken from "@/utils/smart_contract_files/MockToken.json";
|
||||
import p2pix from "@/utils/smart_contract_files/P2PIX.json";
|
||||
|
||||
import { getValidDeposits } from "./events";
|
||||
@@ -63,8 +56,8 @@ const getLockStatus = async (id: bigint): Promise<number> => {
|
||||
const result = await client.readContract({
|
||||
address,
|
||||
abi,
|
||||
functionName: 'getLocksStatus',
|
||||
args: [[id]]
|
||||
functionName: "getLocksStatus",
|
||||
args: [[id]],
|
||||
});
|
||||
return result[1][0];
|
||||
};
|
||||
@@ -90,9 +83,7 @@ const filterLockStatus = async (
|
||||
const tx: WalletTransaction = {
|
||||
token: args.token ? String(args.token) : "",
|
||||
blockNumber: Number(transaction.blockNumber),
|
||||
amount: args.amount
|
||||
? Number(formatEther(args.amount))
|
||||
: -1,
|
||||
amount: args.amount ? Number(formatEther(args.amount)) : -1,
|
||||
seller: args.seller ? String(args.seller) : "",
|
||||
buyer: args.buyer ? String(args.buyer) : "",
|
||||
event: decoded.eventName || "",
|
||||
@@ -116,53 +107,61 @@ const filterLockStatus = async (
|
||||
export const listAllTransactionByWalletAddress = async (
|
||||
walletAddress: string
|
||||
): Promise<WalletTransaction[]> => {
|
||||
const { address, abi, client } = await getContract(true);
|
||||
const { address, client } = await getContract(true);
|
||||
|
||||
// Get deposits
|
||||
const depositLogs = await client.getLogs({
|
||||
address,
|
||||
event: parseAbi(['event DepositAdded(address indexed seller, address token, uint256 amount)'])[0],
|
||||
event: parseAbi([
|
||||
"event DepositAdded(address indexed seller, address token, uint256 amount)",
|
||||
])[0],
|
||||
args: {
|
||||
seller: walletAddress
|
||||
seller: walletAddress,
|
||||
},
|
||||
fromBlock: 0n,
|
||||
toBlock: 'latest'
|
||||
toBlock: "latest",
|
||||
});
|
||||
console.log("Fetched all wallet deposits");
|
||||
|
||||
// Get locks
|
||||
const lockLogs = await client.getLogs({
|
||||
address,
|
||||
event: parseAbi(['event LockAdded(address indexed buyer, uint256 indexed lockID, address seller, address token, uint256 amount)'])[0],
|
||||
event: parseAbi([
|
||||
"event LockAdded(address indexed buyer, uint256 indexed lockID, address seller, address token, uint256 amount)",
|
||||
])[0],
|
||||
args: {
|
||||
buyer: walletAddress
|
||||
buyer: walletAddress,
|
||||
},
|
||||
fromBlock: 0n,
|
||||
toBlock: 'latest'
|
||||
toBlock: "latest",
|
||||
});
|
||||
console.log("Fetched all wallet locks");
|
||||
|
||||
// Get released locks
|
||||
const releasedLogs = await client.getLogs({
|
||||
address,
|
||||
event: parseAbi(['event LockReleased(address indexed buyer, uint256 indexed lockID, string e2eId)'])[0],
|
||||
event: parseAbi([
|
||||
"event LockReleased(address indexed buyer, uint256 indexed lockID, string e2eId)",
|
||||
])[0],
|
||||
args: {
|
||||
buyer: walletAddress
|
||||
buyer: walletAddress,
|
||||
},
|
||||
fromBlock: 0n,
|
||||
toBlock: 'latest'
|
||||
toBlock: "latest",
|
||||
});
|
||||
console.log("Fetched all wallet released locks");
|
||||
|
||||
// Get withdrawn deposits
|
||||
const withdrawnLogs = await client.getLogs({
|
||||
address,
|
||||
event: parseAbi(['event DepositWithdrawn(address indexed seller, address token, uint256 amount)'])[0],
|
||||
event: parseAbi([
|
||||
"event DepositWithdrawn(address indexed seller, address token, uint256 amount)",
|
||||
])[0],
|
||||
args: {
|
||||
seller: walletAddress
|
||||
seller: walletAddress,
|
||||
},
|
||||
fromBlock: 0n,
|
||||
toBlock: 'latest'
|
||||
toBlock: "latest",
|
||||
});
|
||||
console.log("Fetched all wallet withdrawn deposits");
|
||||
|
||||
@@ -170,7 +169,7 @@ export const listAllTransactionByWalletAddress = async (
|
||||
...depositLogs,
|
||||
...lockLogs,
|
||||
...releasedLogs,
|
||||
...withdrawnLogs
|
||||
...withdrawnLogs,
|
||||
].sort((a: Log, b: Log) => {
|
||||
return Number(b.blockNumber) - Number(a.blockNumber);
|
||||
});
|
||||
@@ -182,16 +181,18 @@ export const listAllTransactionByWalletAddress = async (
|
||||
export const listReleaseTransactionByWalletAddress = async (
|
||||
walletAddress: string
|
||||
) => {
|
||||
const { address, abi, client } = await getContract(true);
|
||||
const { address, client } = await getContract(true);
|
||||
|
||||
const releasedLogs = await client.getLogs({
|
||||
address,
|
||||
event: parseAbi(['event LockReleased(address indexed buyer, uint256 indexed lockID, string e2eId)'])[0],
|
||||
event: parseAbi([
|
||||
"event LockReleased(address indexed buyer, uint256 indexed lockID, string e2eId)",
|
||||
])[0],
|
||||
args: {
|
||||
buyer: walletAddress
|
||||
buyer: walletAddress,
|
||||
},
|
||||
fromBlock: 0n,
|
||||
toBlock: 'latest'
|
||||
toBlock: "latest",
|
||||
});
|
||||
|
||||
return releasedLogs
|
||||
@@ -203,7 +204,7 @@ export const listReleaseTransactionByWalletAddress = async (
|
||||
return decodeEventLog({
|
||||
abi: p2pix.abi,
|
||||
data: log.data,
|
||||
topics: log.topics
|
||||
topics: log.topics,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Error decoding log", error);
|
||||
@@ -213,19 +214,19 @@ export const listReleaseTransactionByWalletAddress = async (
|
||||
.filter((decoded: any) => decoded !== null);
|
||||
};
|
||||
|
||||
const listLockTransactionByWalletAddress = async (
|
||||
walletAddress: string
|
||||
) => {
|
||||
const { address, abi, client } = await getContract(true);
|
||||
const listLockTransactionByWalletAddress = async (walletAddress: string) => {
|
||||
const { address, client } = await getContract(true);
|
||||
|
||||
const lockLogs = await client.getLogs({
|
||||
address,
|
||||
event: parseAbi(['event LockAdded(address indexed buyer, uint256 indexed lockID, address seller, address token, uint256 amount)'])[0],
|
||||
event: parseAbi([
|
||||
"event LockAdded(address indexed buyer, uint256 indexed lockID, address seller, address token, uint256 amount)",
|
||||
])[0],
|
||||
args: {
|
||||
buyer: walletAddress
|
||||
buyer: walletAddress,
|
||||
},
|
||||
fromBlock: 0n,
|
||||
toBlock: 'latest'
|
||||
toBlock: "latest",
|
||||
});
|
||||
|
||||
return lockLogs
|
||||
@@ -237,7 +238,7 @@ const listLockTransactionByWalletAddress = async (
|
||||
return decodeEventLog({
|
||||
abi: p2pix.abi,
|
||||
data: log.data,
|
||||
topics: log.topics
|
||||
topics: log.topics,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Error decoding log", error);
|
||||
@@ -247,17 +248,17 @@ const listLockTransactionByWalletAddress = async (
|
||||
.filter((decoded: any) => decoded !== null);
|
||||
};
|
||||
|
||||
const listLockTransactionBySellerAddress = async (
|
||||
sellerAddress: string
|
||||
) => {
|
||||
const { address, abi, client } = await getContract(true);
|
||||
const listLockTransactionBySellerAddress = async (sellerAddress: string) => {
|
||||
const { address, client } = await getContract(true);
|
||||
console.log("Will get locks as seller", sellerAddress);
|
||||
|
||||
const lockLogs = await client.getLogs({
|
||||
address,
|
||||
event: parseAbi(['event LockAdded(address indexed buyer, uint256 indexed lockID, address seller, address token, uint256 amount)'])[0],
|
||||
event: parseAbi([
|
||||
"event LockAdded(address indexed buyer, uint256 indexed lockID, address seller, address token, uint256 amount)",
|
||||
])[0],
|
||||
fromBlock: 0n,
|
||||
toBlock: 'latest'
|
||||
toBlock: "latest",
|
||||
});
|
||||
|
||||
return lockLogs
|
||||
@@ -266,7 +267,7 @@ const listLockTransactionBySellerAddress = async (
|
||||
return decodeEventLog({
|
||||
abi: p2pix.abi,
|
||||
data: log.data,
|
||||
topics: log.topics
|
||||
topics: log.topics,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Error decoding log", error);
|
||||
@@ -275,7 +276,9 @@ const listLockTransactionBySellerAddress = async (
|
||||
})
|
||||
.filter((decoded: any) => decoded !== null)
|
||||
.filter(
|
||||
(decoded: any) => decoded.args && decoded.args.seller &&
|
||||
(decoded: any) =>
|
||||
decoded.args &&
|
||||
decoded.args.seller &&
|
||||
decoded.args.seller.toLowerCase() === sellerAddress.toLowerCase()
|
||||
);
|
||||
};
|
||||
@@ -297,8 +300,8 @@ export const checkUnreleasedLock = async (
|
||||
const lockStatus = await client.readContract({
|
||||
address,
|
||||
abi,
|
||||
functionName: 'getLocksStatus',
|
||||
args: [lockIds]
|
||||
functionName: "getLocksStatus",
|
||||
args: [lockIds],
|
||||
});
|
||||
|
||||
const unreleasedLockId = lockStatus[1].findIndex(
|
||||
@@ -311,8 +314,8 @@ export const checkUnreleasedLock = async (
|
||||
const lock = await client.readContract({
|
||||
address,
|
||||
abi,
|
||||
functionName: 'mapLocks',
|
||||
args: [lockID]
|
||||
functionName: "mapLocks",
|
||||
args: [lockID],
|
||||
});
|
||||
|
||||
const pixTarget = lock.pixTarget;
|
||||
@@ -340,8 +343,8 @@ export const getActiveLockAmount = async (
|
||||
const lockStatus = await client.readContract({
|
||||
address,
|
||||
abi,
|
||||
functionName: 'getLocksStatus',
|
||||
args: [lockIds]
|
||||
functionName: "getLocksStatus",
|
||||
args: [lockIds],
|
||||
});
|
||||
|
||||
let activeLockAmount = 0;
|
||||
@@ -351,8 +354,8 @@ export const getActiveLockAmount = async (
|
||||
const lock = await client.readContract({
|
||||
address,
|
||||
abi,
|
||||
functionName: 'mapLocks',
|
||||
args: [lockId]
|
||||
functionName: "mapLocks",
|
||||
args: [lockId],
|
||||
});
|
||||
activeLockAmount += Number(formatEther(lock.amount));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user