From c3688e372e256dfc9eed0d54d08180aef001ccf0 Mon Sep 17 00:00:00 2001 From: Ekrem BAL Date: Wed, 13 Mar 2024 19:40:55 +0300 Subject: [PATCH] Migrate to Sepolia --- .env.example | 6 ++-- package.json | 4 +-- src/constants/contracts.ts | 2 ++ src/constants/variables.ts | 6 ++++ src/modules/queue/transaction.processor.ts | 8 ++++- src/services/gas-price.service.ts | 4 +-- src/types/index.ts | 2 ++ yarn.lock | 38 +++++++++++----------- 8 files changed, 43 insertions(+), 27 deletions(-) diff --git a/.env.example b/.env.example index 380c53c..e3d3e49 100644 --- a/.env.example +++ b/.env.example @@ -10,9 +10,9 @@ REDIS_URL=redis://redis/0 # for development # REDIS_URL=redis://127.0.0.1:6379 -CHAIN_ID=100 +CHAIN_ID=11155111 -RPC_URL=https://rpc.gnosischain.com +RPC_URL=https://ethereum-sepolia-rpc.publicnode.com REWARD_ADDRESS= PRIVATE_KEY= @@ -22,7 +22,7 @@ MAX_GAS_PRICE=100 # commission for service # transfer fee is a fixed value in ether, 0.01 means 0.01 ether TRANSFER_SERVICE_FEE=0.00000001 -WITHDRAWAL_SERVICE_FEE=0.05 +WITHDRAWAL_SERVICE_FEE=0.005 # Pinata api key for uploading files to IPFS https://app.pinata.cloud/developers/api-keys diff --git a/package.json b/package.json index 42b330e..36d51ed 100644 --- a/package.json +++ b/package.json @@ -31,8 +31,8 @@ "@nestjs/microservices": "^9.0.0", "@nestjs/platform-express": "^9.0.0", "@pinata/sdk": "^2.1.0", - "@tornado/gas-price-oracle": "^0.5.3", - "@tornado/tx-manager": "^0.4.9", + "gas-price-oracle": "^0.5.2", + "tx-manager": "^0.4.9", "ajv": "^8.6.1", "bull": "^3.22.11", "class-validator": "^0.13.1", diff --git a/src/constants/contracts.ts b/src/constants/contracts.ts index bb278b6..4e7a1df 100644 --- a/src/constants/contracts.ts +++ b/src/constants/contracts.ts @@ -4,10 +4,12 @@ export const CONTRACT_NETWORKS: { [chainId in ChainId]: string } = { // [ChainId.MAINNET]: '', [ChainId.GOERLI]: '0x30221943644ffaa55f20e915a83352d0548585ca', [ChainId.LOCALHOST]: '0xdc64a140aa3e981100a9beca4e685f962f0cf6c9', + [ChainId.SEPOLIA]: '0x8e3E4702B4ec7400ef15fba30B3e4bfdc72aBC3B', }; export const RPC_LIST: { [chainId in ChainId]: string } = { // [ChainId.MAINNET]: 'https://api.mycryptoapi.com/eth', [ChainId.GOERLI]: 'https://ethereum-goerli.publicnode.com', [ChainId.LOCALHOST]: 'http://127.0.0.1:8545/', + [ChainId.SEPOLIA]: 'https://ethereum-sepolia-rpc.publicnode.com', }; diff --git a/src/constants/variables.ts b/src/constants/variables.ts index 9b5e6b8..082ecbf 100644 --- a/src/constants/variables.ts +++ b/src/constants/variables.ts @@ -7,6 +7,11 @@ const NETWORKS_INFO: { [chainId in ChainId] } = { gasLimit: BigNumber.from(2000000), minimumBalance: '0.1', }, + [ChainId.SEPOLIA]: { + symbol: 'sepolia', + gasLimit: BigNumber.from(2000000), + minimumBalance: '0.1', + }, [ChainId.LOCALHOST]: { symbol: 'localhost', gasLimit: BigNumber.from(2000000), @@ -58,4 +63,5 @@ export const SERVICE_ERRORS = { TOKEN_RATES: 'Could not get token rates', GAS_SPIKE: 'Provided fee is not enough. Probably it is a Gas Price spike, try to resubmit.', IPFS_CID_FAIL: 'CIDs do not match', + INVALID_RELAYER_ADDRESS: 'Invalid relayer address', }; diff --git a/src/modules/queue/transaction.processor.ts b/src/modules/queue/transaction.processor.ts index ba3d60f..1995d1a 100644 --- a/src/modules/queue/transaction.processor.ts +++ b/src/modules/queue/transaction.processor.ts @@ -1,5 +1,5 @@ import { BigNumber } from 'ethers'; -import { TxManager } from '@tornado/tx-manager'; +import { TxManager } from 'tx-manager'; import { Job, Queue, DoneCallback } from 'bull'; import { Injectable } from '@nestjs/common'; @@ -37,6 +37,12 @@ export class TransactionProcessor extends BaseProcessor { async processTransactions(job: Job, cb: DoneCallback) { try { const { extData, membershipProof } = job.data; + console.log('extData relayer:', extData.relayer); + const {rewardAddress} = this.configService.get('base'); + + if(extData.relayer != rewardAddress) { + throw new Error(SERVICE_ERRORS.INVALID_RELAYER_ADDRESS); + } console.log('extData:', extData); console.log('membershipProof:', membershipProof); await this.checkFee({ fee: extData.fee, externalAmount: extData.extAmount }); diff --git a/src/services/gas-price.service.ts b/src/services/gas-price.service.ts index 2ef3b96..e6b561e 100644 --- a/src/services/gas-price.service.ts +++ b/src/services/gas-price.service.ts @@ -2,8 +2,8 @@ import { Injectable } from '@nestjs/common'; import { ConfigService } from '@nestjs/config'; import { BigNumber } from 'ethers'; -import { GasPriceOracle } from '@tornado/gas-price-oracle'; -import type { GasPrice } from '@tornado/gas-price-oracle/lib/services'; +import { GasPriceOracle } from 'gas-price-oracle'; +import type { GasPrice } from 'gas-price-oracle/lib/services'; import { toWei } from '@/utilities'; import { SERVICE_ERRORS } from '@/constants'; diff --git a/src/types/index.ts b/src/types/index.ts index 8ac15bb..49e5095 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -4,11 +4,13 @@ import { BytesLike } from '@ethersproject/bytes'; // const MAINNET_CHAIN_ID = 1; const GOERLI_CHAIN_ID = 5; const LOCALHOST_CHAIN_ID = 31337; +const SEPOLIA_CHAIN_ID = 11155111; export enum ChainId { // MAINNET = MAINNET_CHAIN_ID, GOERLI = GOERLI_CHAIN_ID, LOCALHOST = LOCALHOST_CHAIN_ID, + SEPOLIA = SEPOLIA_CHAIN_ID, } export type ExtData = { diff --git a/yarn.lock b/yarn.lock index 116bfdc..f004a9a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1223,25 +1223,6 @@ resolved "https://registry.npmjs.org/@tootallnate/once/-/once-1.1.2.tgz#ccb91445360179a04e7fe6aff78c00ffc1eeaf82" integrity sha512-RbzJvlNzmRq5c3O09UipeuXno4tA1FE6ikOjxZK0tuxVv3412l64l5t1W5pj4+rJq9vpkm/kwiR07aZXnsKPxw== -"@tornado/gas-price-oracle@^0.5.3": - version "0.5.3" - resolved "https://git.tornado.ws/api/packages/tornado-packages/npm/%40tornado%2Fgas-price-oracle/-/0.5.3/gas-price-oracle-0.5.3.tgz#fb5423dddee2f52edbc16174c5ddce90bea5413d" - integrity sha512-LpVfPiPIz3FOmJdiqJf/yoeO5n9/Pd5jgtdY+6hB9lNW0AiWhylhpScojICViS+3OL9QC8CoTlgr+kbfGeO9pQ== - dependencies: - axios "^0.21.2" - bignumber.js "^9.0.0" - node-cache "^5.1.2" - -"@tornado/tx-manager@^0.4.9": - version "0.4.9" - resolved "https://git.tornado.ws/api/packages/tornado-packages/npm/%40tornado%2Ftx-manager/-/0.4.9/tx-manager-0.4.9.tgz#075add158e3c01da1b34bbcd68ba764491746ceb" - integrity sha512-0j6bquM/gB6JZvm2nv2y1Xo35IvsZcjQ0BMlvoH8OZYa1dzXQCiNBKSlNOIBOFMsOklUXHNE1JmQpko+rTgXOA== - dependencies: - "@tornado/gas-price-oracle" "^0.5.3" - async-mutex "^0.2.4" - ethers "^5.4.6" - web3-core-promievent "^1.3.0" - "@tsconfig/node10@^1.0.7": version "1.0.8" resolved "https://registry.npmjs.org/@tsconfig/node10/-/node10-1.0.8.tgz#c1e4e80d6f964fbecb3359c43bd48b40f7cadad9" @@ -3330,6 +3311,15 @@ functional-red-black-tree@^1.0.1: resolved "https://registry.npmjs.org/functional-red-black-tree/-/functional-red-black-tree-1.0.1.tgz#1b0ab3bd553b2a0d6399d29c0e3ea0b252078327" integrity sha1-GwqzvVU7Kg1jmdKcDj6gslIHgyc= +gas-price-oracle@^0.5.0, gas-price-oracle@^0.5.2: + version "0.5.2" + resolved "https://registry.yarnpkg.com/gas-price-oracle/-/gas-price-oracle-0.5.2.tgz#f0ecadd49f4f20cd0038ea8ce396c5ab39aa3480" + integrity sha512-sV9CgnUNA/upJM2p4ksFWOXxxceV+1UXgdSi3e2AWUBBjJ+jviKKxyyGlF+zNFaXa6Ux6RcIDR6Abt2HL+CPkQ== + dependencies: + axios "^0.21.2" + bignumber.js "^9.0.0" + node-cache "^5.1.2" + gensync@^1.0.0-beta.2: version "1.0.0-beta.2" resolved "https://registry.npmjs.org/gensync/-/gensync-1.0.0-beta.2.tgz#32a6ee76c3d7f52d46b2b1ae5d93fea8580a25e0" @@ -6050,6 +6040,16 @@ tsutils@^3.21.0: dependencies: tslib "^1.8.1" +tx-manager@^0.4.9: + version "0.4.9" + resolved "https://registry.yarnpkg.com/tx-manager/-/tx-manager-0.4.9.tgz#234a672ae0c5efb00697444896fc5ada3c464462" + integrity sha512-sSnLHXD6M8pBi1wqaGRdyAd2ZRMAoB/L5kDXUghJb3WkWx+/T0mM5N4CJ0Uy3FxPG88A8CWnOoaEt0lr/WXkcg== + dependencies: + async-mutex "^0.2.4" + ethers "^5.4.6" + gas-price-oracle "^0.5.0" + web3-core-promievent "^1.3.0" + type-check@^0.4.0, type-check@~0.4.0: version "0.4.0" resolved "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz#07b8203bfa7056c0657050e3ccd2c37730bab8f1"