-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: implement basic sanctions * chore: useOfacSanctioned * chore: eqAddress * chore: comments * chore: named fns
- Loading branch information
1 parent
c04400d
commit a6d6ed6
Showing
4 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
src/features/sanctions/hooks/useIsAccountChainalysisSanctioned.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
24
src/features/sanctions/hooks/useIsAccountOfacSanctioned.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters