Contracts addresses, getLiquidity function and blockchain (deposit, lock, release) methods corrected

This commit is contained in:
brunoedcf
2023-01-31 14:38:34 -03:00
parent d665376eb4
commit d569294648
13 changed files with 305 additions and 172 deletions

View File

@@ -5,8 +5,8 @@ const getTokenAddress = (): string => {
const etherStore = useEtherStore();
const possibleTokenAddresses: { [key: string]: string } = {
Ethereum: "0x294003F602c321627152c6b7DED3EAb5bEa853Ee",
Polygon: "0x294003F602c321627152c6b7DED3EAb5bEa853Ee",
Ethereum: "0x4A2886EAEc931e04297ed336Cc55c4eb7C75BA00",
Polygon: "0xC86042E9F2977C62Da8c9dDF7F9c40fde4796A29",
};
return possibleTokenAddresses[etherStore.networkName];
@@ -16,8 +16,8 @@ const getP2PixAddress = (): string => {
const etherStore = useEtherStore();
const possibleP2PixAddresses: { [key: string]: string } = {
Ethereum: "0x5f3EFA9A90532914545CEf527C530658af87e196",
Polygon: "0x5f3EFA9A90532914545CEf527C530658af87e196",
Ethereum: "0xefa5cE4351cda51192509cf8De7d8881ADAE95DD",
Polygon: "0xA9258eBb157E4cf5e756b77FDD0DF09C2F73240b",
};
return possibleP2PixAddresses[etherStore.networkName];

View File

@@ -9,7 +9,8 @@ import { BigNumber, ethers } from "ethers";
import { parseEther } from "ethers/lib/utils";
const addLock = async (
depositId: BigNumber,
seller: string,
token: string,
amount: number
): Promise<string> => {
const etherStore = useEtherStore();
@@ -17,7 +18,8 @@ const addLock = async (
const p2pContract = getContract();
const lock = await p2pContract.lock(
depositId, // BigNumber
seller,
token,
etherStore.walletAddress, // String "0x70997970C51812dc3A010C7d01b50e0d17dc79C8" (Example)
ethers.constants.AddressZero, // String "0x0000000000000000000000000000000000000000"
0,
@@ -33,7 +35,7 @@ const addLock = async (
};
const releaseLock = async (
pixKey: string,
pixKey: number,
amount: number,
e2eId: string,
lockId: string

View File

@@ -20,19 +20,25 @@ const getNetworksLiquidity = async (): Promise<void> => {
); // mumbai provider
const p2pContractGoerli = new ethers.Contract(
"0x5f3EFA9A90532914545CEf527C530658af87e196",
"0xefa5cE4351cda51192509cf8De7d8881ADAE95DD",
p2pix.abi,
goerliProvider
);
const p2pContractMumbai = new ethers.Contract(
"0x5f3EFA9A90532914545CEf527C530658af87e196",
"0xA9258eBb157E4cf5e756b77FDD0DF09C2F73240b",
p2pix.abi,
mumbaiProvider
);
const depositListGoerli = await getValidDeposits(p2pContractGoerli);
const depositListGoerli = await getValidDeposits(
"0x4A2886EAEc931e04297ed336Cc55c4eb7C75BA00",
p2pContractGoerli
);
const depositListMumbai = await getValidDeposits(p2pContractMumbai);
const depositListMumbai = await getValidDeposits(
"0xC86042E9F2977C62Da8c9dDF7F9c40fde4796A29",
p2pContractMumbai
);
etherStore.setDepositsValidListGoerli(depositListGoerli);
console.log(depositListGoerli);
@@ -42,6 +48,7 @@ const getNetworksLiquidity = async (): Promise<void> => {
};
const getValidDeposits = async (
token: string,
contract?: Contract
): Promise<ValidDeposit[]> => {
let p2pContract: Contract;
@@ -59,18 +66,28 @@ const getValidDeposits = async (
const depositList = await Promise.all(
eventsDeposits.map(async (deposit) => {
const mappedDeposit = await p2pContract.mapDeposits(
deposit.args?.depositID
// Get liquidity only for the selected token
if (deposit.args?.token != token) return null;
const mappedBalance = await p2pContract.getBalance(
deposit.args?.seller,
token
);
const mappedPixTarget = await p2pContract.getPixTarget(
deposit.args?.seller,
token
);
let validDeposit: ValidDeposit | null = null;
if (mappedDeposit.valid) {
if (mappedBalance._hex) {
validDeposit = {
token: token,
blockNumber: deposit.blockNumber,
depositID: deposit.args?.depositID,
remaining: Number(formatEther(mappedDeposit.remaining)),
seller: mappedDeposit.seller,
pixKey: mappedDeposit.pixTarget,
remaining: Number(formatEther(mappedBalance._hex)),
seller: deposit.args?.seller,
pixKey: Number(mappedPixTarget._hex),
};
}

View File

@@ -33,6 +33,7 @@ const addDeposit = async (tokenQty: string, pixKey: string): Promise<any> => {
getTokenAddress(),
parseEther(tokenQty),
pixKey,
true,
ethers.utils.formatBytes32String("")
);