Skip to content

Commit

Permalink
Add check to prevent depositor from creating orders on his own liquidity
Browse files Browse the repository at this point in the history
  • Loading branch information
asoong committed Oct 18, 2023
1 parent 1f3ac13 commit e803c54
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion client/src/components/Swap/OnRamperIntentRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const IntentRow: React.FC<IntentRowProps> = ({
const minutes = (timeLeft / 60n).toString();
const seconds = (timeLeft % 60n).toString();

setTimeRemainingLabel(`${minutes.padStart(2, '0')} minutes ${seconds.padStart(2, '0')} seconds`);
setTimeRemainingLabel(`${minutes.padStart(2, '0')} m ${seconds.padStart(2, '0')} s`);
} else {
setTimeRemainingLabel('Open');

Expand Down
2 changes: 1 addition & 1 deletion client/src/components/Swap/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ const SwapModal: React.FC<SwapModalProps> = ({
const getButtonText = () => {
switch (quoteStatus) {
case 'exceeds-order-count':
return 'One open order allowed';
return 'Max one open order';

case 'exceeds-max-size':
return 'Exceeded USD transfer limit of 2,000';
Expand Down
12 changes: 9 additions & 3 deletions client/src/contexts/Liquidity/LiquidityProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ import {
calculateUsdFromRequestedUSDC,
createDepositsStore,
fetchBestDepositForAmount,
pruneDeposits,
} from './helper'
import { esl, CALLER_ACCOUNT } from '@helpers/constants'
import { unpackPackedVenmoId } from '@helpers/poseidonHash'
import useSmartContracts from '@hooks/useSmartContracts';
import useRampState from '@hooks/useRampState';
import useAccount from '@hooks/useAccount'

import LiquidityContext from './LiquidityContext'

Expand All @@ -37,6 +39,7 @@ const LiquidityProvider = ({ children }: ProvidersProps) => {

const { rampAddress, rampAbi } = useSmartContracts()
const { depositCounter } = useRampState();
const { loggedInEthereumAddress } = useAccount();

/*
* State
Expand Down Expand Up @@ -156,19 +159,22 @@ const LiquidityProvider = ({ children }: ProvidersProps) => {
esl && console.log('depositStore_1');
esl && console.log('checking deposits: ', deposits);
esl && console.log('checking depositIdsToFetch: ', depositIdsToFetch);
esl && console.log('loggedInEthereumAddress: ', loggedInEthereumAddress);

if (deposits && deposits.length > 0 && depositIdsToFetch.length > 0) {
if (loggedInEthereumAddress && deposits && deposits.length > 0 && depositIdsToFetch.length > 0) {
esl && console.log('depositStore_2');

const newStore = createDepositsStore(depositIdsToFetch, deposits);
const prunedDeposits = pruneDeposits(deposits, loggedInEthereumAddress);

const newStore = createDepositsStore(prunedDeposits);

setDepositStore(newStore);
} else {
esl && console.log('depositStore_3');

setDepositStore(null);
}
}, [deposits, depositIdsToFetch]);
}, [deposits, depositIdsToFetch, loggedInEthereumAddress]);

const getBestDepositForAmount = useCallback((requestedOnRampInputAmount: string): IndicativeQuote => {
if (depositStore) {
Expand Down
12 changes: 5 additions & 7 deletions client/src/contexts/Liquidity/helper.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Address } from 'wagmi';

import {
DepositWithAvailableLiquidity,
IndicativeQuote,
Expand All @@ -7,7 +9,7 @@ import { PRECISION } from "@helpers/constants";
import { toBigInt, toUsdString } from "@helpers/units";


export const createDepositsStore = (depositIds: bigint[], deposits: DepositWithAvailableLiquidity[]): StoredDeposit[] => {
export const createDepositsStore = (deposits: DepositWithAvailableLiquidity[]): StoredDeposit[] => {
const sortedDeposits = deposits.sort((a, b) => {
// Sort by ascending order of conversion rate
if (a.deposit.conversionRate > b.deposit.conversionRate) {
Expand Down Expand Up @@ -65,10 +67,6 @@ export const fetchBestDepositForAmount = (requestedOnRampInputAmount: string, de
} as IndicativeQuote;
};

export const pruneDeposits = (depositIds: number[], deposits: DepositWithAvailableLiquidity[]): number[] => {
/*
TODO: Fill me out, currently returning no deposit ids to prune. This means that all deposits are being re-fetched continuously
*/

return [];
export const pruneDeposits = (deposits: DepositWithAvailableLiquidity[], userAddress: Address): DepositWithAvailableLiquidity[] => {
return deposits.filter(deposit => deposit.deposit.depositor !== userAddress);
};

0 comments on commit e803c54

Please sign in to comment.