Skip to content

Commit

Permalink
Check deposit notary hash on Revolut deposits
Browse files Browse the repository at this point in the history
  • Loading branch information
asoong committed May 25, 2024
1 parent cbff779 commit 3bdf4e5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
27 changes: 20 additions & 7 deletions client/src/contexts/revolut/Liquidity/LiquidityProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import React, {
ReactNode,
} from 'react';
import { readContract } from '@wagmi/core';
import { ethers } from "ethers";

import {
Abi,
Expand All @@ -20,7 +21,7 @@ import {
createDepositsStore,
fetchBestDepositForAmount,
fetchDepositForMaxAvailableTransferSize
} from './helper';
} from './helper';
import { esl, CALLER_ACCOUNT, ZERO } from '@helpers/constants';
import useSmartContracts from '@hooks/useSmartContracts';
import useRampState from '@hooks/revolut/useRampState';
Expand All @@ -32,6 +33,11 @@ import LiquidityContext from './LiquidityContext';
const BATCH_SIZE = 30;
const PRUNED_DEPOSITS_PREFIX = 'prunedRevolutDepositIds_';

const NOTARY_PUBKEY_HASH = process.env.NOTARY_PUBKEY_HASH;
if (!NOTARY_PUBKEY_HASH) {
throw new Error("NOTARY_PUBKEY_HASH environment variable is not defined.");
};

interface ProvidersProps {
children: ReactNode;
}
Expand Down Expand Up @@ -78,14 +84,20 @@ const LiquidityProvider = ({ children }: ProvidersProps) => {
for (let j = 0; j < deposits.length; j++) {
const deposit = deposits[j];

const orderHasNoAvailableLiquidity = deposit.availableLiquidity < 1;
const orderHasNoOustandingIntent = deposit.deposit.outstandingIntentAmount === ZERO;
const orderIsFilled = orderHasNoAvailableLiquidity && orderHasNoOustandingIntent;

if (orderIsFilled) {
const pubkeyHashHex = ethers.utils.hexZeroPad(ethers.utils.hexlify(BigInt(NOTARY_PUBKEY_HASH)), 32);
const isInvalidNotaryKeyHash = deposit.deposit.notaryKeyHash !== pubkeyHashHex;
if (isInvalidNotaryKeyHash) {
depositIdsToPrune.push(deposit.depositId);
} else {
batchedDeposits.push(deposit);
const orderHasNoAvailableLiquidity = deposit.availableLiquidity < 1;
const orderHasNoOustandingIntent = deposit.deposit.outstandingIntentAmount === ZERO;
const isOrderFilled = orderHasNoAvailableLiquidity && orderHasNoOustandingIntent;

if (isOrderFilled) {
depositIdsToPrune.push(deposit.depositId);
} else {
batchedDeposits.push(deposit);
}
}
}
}
Expand Down Expand Up @@ -153,6 +165,7 @@ const LiquidityProvider = ({ children }: ProvidersProps) => {
outstandingIntentAmount: depositData.outstandingIntentAmount,
conversionRate: depositData.conversionRate,
intentHashes: depositData.intentHashes,
notaryKeyHash: depositData.notaryKeyHash,
};

const depositWithLiquidity: DepositWithAvailableLiquidity = {
Expand Down
1 change: 1 addition & 0 deletions client/src/helpers/types/deposit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface Deposit {
outstandingIntentAmount: bigint;
conversionRate: bigint;
intentHashes: string[];
notaryKeyHash?: string;
}

// struct DepositWithAvailableLiquidity {
Expand Down

0 comments on commit 3bdf4e5

Please sign in to comment.