Skip to content

Commit

Permalink
Sanctions (#177)
Browse files Browse the repository at this point in the history
* feat: implement basic sanctions

* chore: useOfacSanctioned

* chore: eqAddress

* chore: comments

* chore: named fns
  • Loading branch information
AlexBHarley authored Jun 19, 2024
1 parent c04400d commit a6d6ed6
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/features/sanctions/hooks/useIsAccountChainalysisSanctioned.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { isAddress } from 'viem';
import { useContractRead } from 'wagmi';

import { useEvmAccount } from '../../wallet/hooks/evm';

// https://go.chainalysis.com/chainalysis-oracle-docs.html
const ORACLE_ABI = [
{
inputs: [
{
internalType: 'address',
name: 'addr',
type: 'address',
},
],
name: 'isSanctioned',
outputs: [
{
internalType: 'bool',
name: '',
type: 'bool',
},
],
stateMutability: 'view',
type: 'function',
},
] as const;
const ORACLE_ADDRESS = '0x40C57923924B5c5c5455c48D93317139ADDaC8fb';

export function useIsAccountChainalysisSanctioned() {
const evmAddress = useEvmAccount().addresses[0]?.address;

const sanctioned = useContractRead({
abi: ORACLE_ABI,
functionName: 'isSanctioned',
args: [isAddress(evmAddress) ? evmAddress : '0x'],
chainId: 1,
address: ORACLE_ADDRESS,
enabled: !!evmAddress,
});

return !!sanctioned.data;
}
24 changes: 24 additions & 0 deletions src/features/sanctions/hooks/useIsAccountOfacSanctioned.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { useQuery } from '@tanstack/react-query';

import { eqAddress } from '@hyperlane-xyz/utils';

import { useEvmAccount } from '../../wallet/hooks/evm';

const OFAC_SANCTIONED_ADDRESSES_ENDPOINT =
'https://raw.githubusercontent.com/0xB10C/ofac-sanctioned-digital-currency-addresses/lists/sanctioned_addresses_ETH.json';

export function useIsAccountOfacSanctioned() {
const evmAddress = useEvmAccount().addresses[0]?.address;

const sanctionedAddresses = useQuery<string[]>({
queryKey: ['useIsAccountOfacSanctioned', evmAddress],
queryFn: () => fetch(OFAC_SANCTIONED_ADDRESSES_ENDPOINT).then((x) => x.json()),
enabled: !!evmAddress,
});

return (
!!sanctionedAddresses.data &&
!!evmAddress &&
!!sanctionedAddresses.data.find((x) => eqAddress(x, evmAddress))
);
}
9 changes: 9 additions & 0 deletions src/features/sanctions/hooks/useIsAccountSanctioned.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { useIsAccountChainalysisSanctioned } from './useIsAccountChainalysisSanctioned';
import { useIsAccountOfacSanctioned } from './useIsAccountOfacSanctioned';

export function useIsAccountSanctioned() {
const isAccountOfacSanctioned = useIsAccountOfacSanctioned();
const isAccountChainalysisSanctioned = useIsAccountChainalysisSanctioned();

return isAccountOfacSanctioned || isAccountChainalysisSanctioned;
}
5 changes: 5 additions & 0 deletions src/features/transfer/TransferTokenForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { Color } from '../../styles/Color';
import { logger } from '../../utils/logger';
import { ChainSelectField } from '../chains/ChainSelectField';
import { getChainDisplayName } from '../chains/utils';
import { useIsAccountSanctioned } from '../sanctions/hooks/useIsAccountSanctioned';
import { useStore } from '../store';
import { SelectOrInputTokenIds } from '../tokens/SelectOrInputTokenIds';
import { TokenSelectField } from '../tokens/TokenSelectField';
Expand Down Expand Up @@ -215,6 +216,7 @@ function ButtonSection({
setIsReview: (b: boolean) => void;
}) {
const { values } = useFormikContext<TransferFormValues>();
const isSanctioned = useIsAccountSanctioned();

const onDoneTransactions = () => {
setIsReview(false);
Expand All @@ -228,6 +230,9 @@ function ButtonSection({
}));

const triggerTransactionsHandler = async () => {
if (isSanctioned) {
return;
}
setTransferLoading(true);
await triggerTransactions(values);
};
Expand Down

0 comments on commit a6d6ed6

Please sign in to comment.