Skip to content

Commit

Permalink
refactor: ofac on sdk-ts
Browse files Browse the repository at this point in the history
  • Loading branch information
bangjelkoski committed Sep 6, 2024
1 parent 1fbd1e3 commit 0f4bdb1
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 9 deletions.
2 changes: 1 addition & 1 deletion etc/ofac.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const fetchOfac = async () => {
const wallets = await response.text()

try {
storeJsonFile(`src/json/ofac.json`, wallets)
storeJsonFile(`src/json/ofac.ts`, `export const ofacWallets = ${wallets}`)

console.log(`✅✅✅ OFAC list fetched`)
} catch (e) {
Expand Down
1 change: 1 addition & 0 deletions packages/sdk-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
},
"scripts": {
"postinstall": "link-module-alias",
"fetch:ofac": "node --experimental-fetch ./../../etc/ofac.js",
"build": "tsc --build --force tsconfig.build.json && tsc --build --force tsconfig.build.esm.json && yarn build:post && link-module-alias",
"build:watch": "tsc --build -w tsconfig.build.json && tsc -w --build tsconfig.build.esm.json && yarn build:post && link-module-alias",
"build:post": "shx cp ../../etc/stub/package.json.stub dist/cjs/package.json && shx cp ../../etc/stub/package.esm.json.stub dist/esm/package.json",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { CreateTransactionArgs } from '../types'
import { IndexerGrpcTransactionApi } from '../../../../client'
import { AccountDetails } from '../../../../types/auth'
import { CosmosTxV1Beta1Tx } from '@injectivelabs/core-proto-ts'
import { ofacWallets } from './../../../../json'

interface MsgBroadcasterTxOptions {
msgs: Msgs | Msgs[]
Expand Down Expand Up @@ -104,6 +105,14 @@ export class MsgBroadcasterWithPk {
* @returns {string} transaction hash
*/
async broadcast(transaction: MsgBroadcasterTxOptions) {
const { privateKey } = this

if (ofacWallets.includes(privateKey.toHex())) {
throw new GeneralException(
new Error('You cannot execute this transaction'),
)
}

const { txRaw } = await this.prepareTxForBroadcast(transaction)

return await this.broadcastTxRaw(txRaw)
Expand All @@ -117,6 +126,15 @@ export class MsgBroadcasterWithPk {
*/
async broadcastWithFeeDelegation(transaction: MsgBroadcasterTxOptions) {
const { simulateTx, privateKey, ethereumChainId, endpoints } = this

const ethereumWallet = this.privateKey.toHex()

if (ofacWallets.includes(ethereumWallet)) {
throw new GeneralException(
new Error('You cannot execute this transaction'),
)
}

const msgs = Array.isArray(transaction.msgs)
? transaction.msgs
: [transaction.msgs]
Expand Down Expand Up @@ -164,6 +182,15 @@ export class MsgBroadcasterWithPk {
*/
async simulate(transaction: MsgBroadcasterTxOptions) {
const { privateKey, endpoints, chainId } = this

const ethereumWallet = this.privateKey.toHex()

if (ofacWallets.includes(ethereumWallet)) {
throw new GeneralException(
new Error('You cannot execute this transaction'),
)
}

const tx = {
...transaction,
msgs: Array.isArray(transaction.msgs)
Expand Down
1 change: 1 addition & 0 deletions packages/sdk-ts/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export * from './client'
export * from './utils'
export * from './service'
export * from './types'
export * from './json'
1 change: 1 addition & 0 deletions packages/sdk-ts/src/json/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './ofac'
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[
export const ofacWallets = [
"0x179f48c78f57a3a78f0608cc9197b8972921d1d2",
"0x1967d8af5bd86a497fb3dd7899a020e47560daaf",
"0x19aa5fe80d33a56d56c78e82ea5e50e5d80b4dff",
Expand Down
3 changes: 1 addition & 2 deletions packages/wallet-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@
},
"scripts": {
"postinstall": "link-module-alias",
"fetch:ofac": "node --experimental-fetch ./../../etc/ofac.js",
"build:cjs": "BUILD_MODE=cjs node ./../../etc/replacements.js && tsc --build tsconfig.build.json",
"build:esm": "BUILD_MODE=esm node ./../../etc/replacements.js && tsc --build tsconfig.build.esm.json",
"build": "yarn fetch:ofac && yarn build:esm && yarn build:cjs && yarn build:post && link-module-alias",
"build": "yarn build:esm && yarn build:cjs && yarn build:post && link-module-alias",
"build:watch": "tsc --build -w tsconfig.build.json && tsc -w --build tsconfig.build.esm.json && yarn build:post && link-module-alias",
"build:post": "shx cp ../../etc/stub/package.json.stub dist/cjs/package.json && shx cp ../../etc/stub/package.esm.json.stub dist/esm/package.json",
"clean": "tsc --build tsconfig.build.json --clean && tsc --build tsconfig.build.esm.json --clean && shx rm -rf coverage *.log junit.xml dist && jest --clearCache && shx mkdir -p dist",
Expand Down
10 changes: 5 additions & 5 deletions packages/wallet-ts/src/broadcaster/MsgBroadcaster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
SIGN_DIRECT,
TxResponse,
hexToBase64,
ofacWallets,
SIGN_EIP712_V2,
SIGN_EIP712,
ChainGrpcAuthApi,
Expand Down Expand Up @@ -58,7 +59,6 @@ import { createEip712StdSignDoc, KeplrWallet } from '../utils/wallets/keplr'
import { isCosmosAminoOnlyWallet } from '../utils'
import { LeapWallet } from '../utils/wallets'
import { checkIfTxRunOutOfGas } from './helper'
import ofac from './../json/ofac.json'

const getEthereumWalletPubKey = <T>({
pubKey,
Expand Down Expand Up @@ -145,7 +145,7 @@ export class MsgBroadcaster {
),
} as MsgBroadcasterTxOptionsWithAddresses

if (ofac.includes(txWithAddresses.ethereumAddress)) {
if (ofacWallets.includes(txWithAddresses.ethereumAddress)) {
throw new GeneralException(
new Error('You cannot execute this transaction'),
)
Expand Down Expand Up @@ -179,7 +179,7 @@ export class MsgBroadcaster {
),
} as MsgBroadcasterTxOptionsWithAddresses

if (ofac.includes(txWithAddresses.ethereumAddress)) {
if (ofacWallets.includes(txWithAddresses.ethereumAddress)) {
throw new GeneralException(
new Error('You cannot execute this transaction'),
)
Expand Down Expand Up @@ -213,7 +213,7 @@ export class MsgBroadcaster {
),
} as MsgBroadcasterTxOptionsWithAddresses

if (ofac.includes(txWithAddresses.ethereumAddress)) {
if (ofacWallets.includes(txWithAddresses.ethereumAddress)) {
throw new GeneralException(
new Error('You cannot execute this transaction'),
)
Expand Down Expand Up @@ -244,7 +244,7 @@ export class MsgBroadcaster {
),
} as MsgBroadcasterTxOptionsWithAddresses

if (ofac.includes(txWithAddresses.ethereumAddress)) {
if (ofacWallets.includes(txWithAddresses.ethereumAddress)) {
throw new GeneralException(
new Error('You cannot execute this transaction'),
)
Expand Down

0 comments on commit 0f4bdb1

Please sign in to comment.