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

@ -1,3 +0,0 @@
VITE_API_URL=http://localhost:8000/
VITE_GOERLI_API_URL={GOERLI_API_URL_ALCHEMY}
VITE_MUMBAI_API_URL={MUMBAI_API_URL_ALCHEMY}

View File

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

View File

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

View File

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

View File

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

View File

@ -1,10 +1,7 @@
import type { BigNumber } from "ethers";
export type ValidDeposit = { export type ValidDeposit = {
depositID: BigNumber; token: string;
blockNumber: number; blockNumber: number;
remaining: number; remaining: number;
seller: string; seller: string;
pixKey: string; pixKey: number;
pixTarget?: string;
}; };

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,8 +0,0 @@
{
"signers": [
"0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
"0x70997970C51812dc3A010C7d01b50e0d17dc79C8"
],
"p2pix": "0x5f3EFA9A90532914545CEf527C530658af87e196",
"token": "0x294003F602c321627152c6b7DED3EAb5bEa853Ee"
}

View File

@ -1,8 +0,0 @@
{
"signers": [
"0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
"0x70997970C51812dc3A010C7d01b50e0d17dc79C8"
],
"p2pix": "0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0",
"token": "0x5FbDB2315678afecb367f032d93F642f64180aa3"
}

View File

@ -1,8 +0,0 @@
{
"signers": [
"0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
"0x70997970C51812dc3A010C7d01b50e0d17dc79C8"
],
"p2pix": "0x5f3EFA9A90532914545CEf527C530658af87e196",
"token": "0x294003F602c321627152c6b7DED3EAb5bEa853Ee"
}

View File

@ -1,6 +0,0 @@
{
"wallets":[
"0x70997970C51812dc3A010C7d01b50e0d17dc79C8",
"0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC"
]
}

View File

@ -27,7 +27,7 @@ etherStore.setSellerView(false);
// States // States
const { loadingLock, walletAddress } = storeToRefs(etherStore); const { loadingLock, walletAddress } = storeToRefs(etherStore);
const flowStep = ref<Step>(Step.Search); const flowStep = ref<Step>(Step.Search);
const pixTarget = ref<string>(""); const pixTarget = ref<number>();
const tokenAmount = ref<number>(); const tokenAmount = ref<number>();
const _lockID = ref<string>(""); const _lockID = ref<string>("");
const loadingRelease = ref<boolean>(false); const loadingRelease = ref<boolean>(false);
@ -46,7 +46,7 @@ const confirmBuyClick = async (
flowStep.value = Step.Buy; flowStep.value = Step.Buy;
etherStore.setLoadingLock(true); etherStore.setLoadingLock(true);
await addLock(selectedDeposit.depositID, tokenValue) await addLock(selectedDeposit.seller, selectedDeposit.token, tokenValue)
.then((lockID) => { .then((lockID) => {
_lockID.value = lockID; _lockID.value = lockID;
}) })
@ -63,7 +63,7 @@ const releaseTransaction = async (e2eId: string) => {
flowStep.value = Step.List; flowStep.value = Step.List;
loadingRelease.value = true; loadingRelease.value = true;
if (_lockID.value && tokenAmount.value) { if (_lockID.value && tokenAmount.value && pixTarget.value) {
const release = await releaseLock( const release = await releaseLock(
pixTarget.value, pixTarget.value,
tokenAmount.value, tokenAmount.value,
@ -96,7 +96,7 @@ onMounted(async () => {
/> />
<div v-if="flowStep == Step.Buy"> <div v-if="flowStep == Step.Buy">
<QrCodeComponent <QrCodeComponent
:pixTarget="pixTarget" :pixTarget="String(pixTarget)"
:tokenValue="tokenAmount" :tokenValue="tokenAmount"
@pix-validated="releaseTransaction" @pix-validated="releaseTransaction"
v-if="!loadingLock" v-if="!loadingLock"