-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(bundler) check for transfers to sanctioned addresses (#576)
* add erc20 parsing logic + scaffold sanction check * add sanctions list contract, wire up rest of checks * remove todo * changeset * fix typo * fix action parsing * switch rpc urls * rename --------- Co-authored-by: Luke Tchang <[email protected]>
- Loading branch information
1 parent
e69bcb2
commit 57023ec
Showing
12 changed files
with
575 additions
and
1 deletion.
There are no files selected for viewing
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,5 @@ | ||
--- | ||
"@nocturne-xyz/bundler": patch | ||
--- | ||
|
||
check outgoing transfers against sanctions list |
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,188 @@ | ||
[ | ||
{ | ||
"inputs": [], | ||
"stateMutability": "nonpayable", | ||
"type": "constructor" | ||
}, | ||
{ | ||
"anonymous": false, | ||
"inputs": [ | ||
{ | ||
"indexed": true, | ||
"internalType": "address", | ||
"name": "addr", | ||
"type": "address" | ||
} | ||
], | ||
"name": "NonSanctionedAddress", | ||
"type": "event" | ||
}, | ||
{ | ||
"anonymous": false, | ||
"inputs": [ | ||
{ | ||
"indexed": true, | ||
"internalType": "address", | ||
"name": "previousOwner", | ||
"type": "address" | ||
}, | ||
{ | ||
"indexed": true, | ||
"internalType": "address", | ||
"name": "newOwner", | ||
"type": "address" | ||
} | ||
], | ||
"name": "OwnershipTransferred", | ||
"type": "event" | ||
}, | ||
{ | ||
"anonymous": false, | ||
"inputs": [ | ||
{ | ||
"indexed": true, | ||
"internalType": "address", | ||
"name": "addr", | ||
"type": "address" | ||
} | ||
], | ||
"name": "SanctionedAddress", | ||
"type": "event" | ||
}, | ||
{ | ||
"anonymous": false, | ||
"inputs": [ | ||
{ | ||
"indexed": false, | ||
"internalType": "address[]", | ||
"name": "addrs", | ||
"type": "address[]" | ||
} | ||
], | ||
"name": "SanctionedAddressesAdded", | ||
"type": "event" | ||
}, | ||
{ | ||
"anonymous": false, | ||
"inputs": [ | ||
{ | ||
"indexed": false, | ||
"internalType": "address[]", | ||
"name": "addrs", | ||
"type": "address[]" | ||
} | ||
], | ||
"name": "SanctionedAddressesRemoved", | ||
"type": "event" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "address[]", | ||
"name": "newSanctions", | ||
"type": "address[]" | ||
} | ||
], | ||
"name": "addToSanctionsList", | ||
"outputs": [], | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "address", | ||
"name": "addr", | ||
"type": "address" | ||
} | ||
], | ||
"name": "isSanctioned", | ||
"outputs": [ | ||
{ | ||
"internalType": "bool", | ||
"name": "", | ||
"type": "bool" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "address", | ||
"name": "addr", | ||
"type": "address" | ||
} | ||
], | ||
"name": "isSanctionedVerbose", | ||
"outputs": [ | ||
{ | ||
"internalType": "bool", | ||
"name": "", | ||
"type": "bool" | ||
} | ||
], | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "name", | ||
"outputs": [ | ||
{ | ||
"internalType": "string", | ||
"name": "", | ||
"type": "string" | ||
} | ||
], | ||
"stateMutability": "pure", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "owner", | ||
"outputs": [ | ||
{ | ||
"internalType": "address", | ||
"name": "", | ||
"type": "address" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "address[]", | ||
"name": "removeSanctions", | ||
"type": "address[]" | ||
} | ||
], | ||
"name": "removeFromSanctionsList", | ||
"outputs": [], | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "renounceOwnership", | ||
"outputs": [], | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "address", | ||
"name": "newOwner", | ||
"type": "address" | ||
} | ||
], | ||
"name": "transferOwnership", | ||
"outputs": [], | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
} | ||
] |
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,38 @@ | ||
import { Action } from "@nocturne-xyz/core"; | ||
import * as ethers from "ethers"; | ||
|
||
export function getSelector(signature: string): string { | ||
const sigBytes = ethers.utils.toUtf8Bytes(signature); | ||
const hash = ethers.utils.keccak256(sigBytes); | ||
return ethers.utils.hexDataSlice(hash, 0, 4); | ||
} | ||
|
||
// same for both ETHTransferAdapter and ERC20 Transfer | ||
const TRANSFER_SELECTOR = getSelector("transfer(address,uint256)"); | ||
|
||
export type TransferActionCalldata = { | ||
to: string; | ||
amount: string; | ||
}; | ||
|
||
export function isTransferAction(action: Action): boolean { | ||
const selector = ethers.utils.hexDataSlice(action.encodedFunction, 0, 4); | ||
return selector === TRANSFER_SELECTOR; | ||
} | ||
|
||
export function parseTransferAction(action: Action): TransferActionCalldata { | ||
if (!isTransferAction(action)) { | ||
throw new Error("Not an ERC20 transfer action"); | ||
} | ||
|
||
const calldata = ethers.utils.hexDataSlice(action.encodedFunction, 4); | ||
const [to, amount] = ethers.utils.defaultAbiCoder.decode( | ||
["address", "uint256"], | ||
calldata | ||
) as [string, ethers.BigNumber]; | ||
|
||
return { | ||
to, | ||
amount: amount.toString(), | ||
}; | ||
} |
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
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
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
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,25 @@ | ||
import { Address } from "@nocturne-xyz/core"; | ||
import * as ethers from "ethers"; | ||
import SanctionsListAbi from "./abis/SanctionsList.json"; | ||
|
||
const CHAIN_ID_TO_SANCTIONS_LIST_CONTRACT: Record<number, Address> = { | ||
1: "0x40c57923924b5c5c5455c48d93317139addac8fb", | ||
}; | ||
|
||
export async function isSanctionedAddress( | ||
provider: ethers.providers.Provider, | ||
address: Address | ||
): Promise<boolean> { | ||
const chainId = (await provider.getNetwork()).chainId; | ||
// skip check if there's no sanctions contract on this chain | ||
if (!CHAIN_ID_TO_SANCTIONS_LIST_CONTRACT[chainId]) { | ||
return false; | ||
} | ||
|
||
const contract = new ethers.Contract( | ||
CHAIN_ID_TO_SANCTIONS_LIST_CONTRACT[chainId], | ||
SanctionsListAbi, | ||
provider | ||
); | ||
return (await contract.isSanctioned(address)) as unknown as boolean; | ||
} |
Oops, something went wrong.