Skip to content

Commit

Permalink
Fix deps
Browse files Browse the repository at this point in the history
  • Loading branch information
peterpolman committed May 18, 2024
1 parent 5b46f9d commit 1713828
Show file tree
Hide file tree
Showing 100 changed files with 4,987 additions and 2,123 deletions.
9 changes: 4 additions & 5 deletions apps/api/scripts/src/veLiquidity.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { ethers } from 'ethers';
import { parseUnits } from 'ethers/lib/utils';
import { PRIVATE_KEY } from '@thxnetwork/api/config/secrets';
import { contractArtifacts, contractNetworks } from '@thxnetwork/api/contracts';
import { getArtifact, contractNetworks } from '@thxnetwork/api/hardhat';
import { ChainId } from '@thxnetwork/common/enums';
import { parseUnits } from 'ethers/lib/utils';
import TransactionService from '@thxnetwork/api/services/TransactionService';

async function increaseBlockTime(provider, seconds) {
await provider.send('evm_increaseTime', [seconds]);
Expand All @@ -21,10 +20,10 @@ export default async function main() {
const chainId = ChainId.Hardhat;
const signer = new ethers.Wallet(PRIVATE_KEY, hardhatProvider) as unknown as ethers.Signer;

const usdc = new ethers.Contract(contractNetworks[chainId].USDC, contractArtifacts['USDC'].abi, signer);
const usdc = new ethers.Contract(contractNetworks[chainId].USDC, getArtifact('USDC').abi, signer);
await usdc.transfer(TO, AMOUNT_USDC);

const thx = new ethers.Contract(contractNetworks[chainId].THX, contractArtifacts['THX'].abi, signer);
const thx = new ethers.Contract(contractNetworks[chainId].THX, getArtifact('THX').abi, signer);
await thx.transfer(TO, AMOUNT_THX);

// Increase time till past veTHX reward distribution start time
Expand Down
10 changes: 5 additions & 5 deletions apps/api/scripts/src/veRewards.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ethers } from 'ethers';
import { PRIVATE_KEY } from '@thxnetwork/api/config/secrets';
import { contractArtifacts, contractNetworks } from '@thxnetwork/api/contracts';
import { contractNetworks, getArtifact } from '@thxnetwork/api/hardhat';
import { ChainId } from '@thxnetwork/common/enums';
import { ethers } from 'ethers';
import { parseUnits } from 'ethers/lib/utils';
import { increaseBlockTime } from './time';

Expand All @@ -10,11 +10,11 @@ export default async function main() {
const hardhatProvider = new ethers.providers.JsonRpcProvider(HARDHAT_RPC);
const chainId = ChainId.Hardhat;
const signer = new ethers.Wallet(PRIVATE_KEY, hardhatProvider) as unknown as ethers.Signer;
const bpt = new ethers.Contract(contractNetworks[chainId].BPT, contractArtifacts['BPT'].abi, signer);
const bal = new ethers.Contract(contractNetworks[chainId].BAL, contractArtifacts['BAL'].abi, signer);
const bpt = new ethers.Contract(contractNetworks[chainId].BPT, getArtifact('BPT').abi, signer);
const bal = new ethers.Contract(contractNetworks[chainId].BAL, getArtifact('BAL').abi, signer);
const rewardFaucet = new ethers.Contract(
contractNetworks[chainId].RewardFaucet,
contractArtifacts['RewardFaucet'].abi,
getArtifact('RewardFaucet').abi,
signer,
);
const AMOUNTBAL = parseUnits('100').toString();
Expand Down
4 changes: 2 additions & 2 deletions apps/api/scripts/src/veTransfer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ethers } from 'ethers';
import { PRIVATE_KEY } from '@thxnetwork/api/config/secrets';
import { contractArtifacts, contractNetworks } from '@thxnetwork/api/contracts';
import { getArtifact, contractNetworks } from '@thxnetwork/api/hardhat';
import { ChainId } from '@thxnetwork/common/enums';
import { parseUnits } from 'ethers/lib/utils';

Expand All @@ -13,7 +13,7 @@ export default async function main() {
const AMOUNT = parseUnits('10000').toString();
const chainId = ChainId.Hardhat;
const signer = new ethers.Wallet(PRIVATE_KEY, hardhatProvider) as unknown as ethers.Signer;
const bpt = new ethers.Contract(contractNetworks[chainId].BPT, contractArtifacts['BPT'].abi, signer);
const bpt = new ethers.Contract(contractNetworks[chainId].BPT, getArtifact('BPT').abi, signer);

await bpt.transfer(TO, AMOUNT);
}
4 changes: 2 additions & 2 deletions apps/api/src/app/controllers/account/get.controller.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Request, Response } from 'express';
import { WalletVariant, AccountVariant } from '@thxnetwork/common/enums';
import { getChainId } from '@thxnetwork/api/services/ContractService';
import AccountProxy from '@thxnetwork/api/proxies/AccountProxy';
import WalletService from '@thxnetwork/api/services/WalletService';
import THXService from '@thxnetwork/api/services/THXService';
import ContractService from '@thxnetwork/api/services/ContractService';

const validation = [];

Expand All @@ -28,7 +28,7 @@ const controller = async (req: Request, res: Response) => {
await WalletService.createWalletConnect({
sub: req.auth.sub,
address: account.address,
chainId: getChainId(),
chainId: ContractService.getChainId(),
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import { deployERC1155, mockGetNftsForOwner } from '@thxnetwork/api/util/jest/er
import { PoolDocument } from '@thxnetwork/api/models';
import { Contract } from 'web3-eth-contract';
import { getProvider } from '@thxnetwork/api/util/network';
import TransactionService from '@thxnetwork/api/services/TransactionService';
import { ethers } from 'ethers';
import TransactionService from '@thxnetwork/api/services/TransactionService';

const user = request.agent(app);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ const controller = async (req: Request, res: Response) => {
const wallet = await WalletService.findById(walletId);
if (!wallet) throw new NotFoundError('Could not find wallet for account');

const contract = ContractService.getContractFromName(
const contract = ContractService.getContract(
'THXERC20_LimitedSupply',
wallet.chainId,
'LimitedSupplyToken',
req.query.tokenAddress as string,
);
const allowanceInWei = await contract.methods.allowance(wallet.address, req.query.spender).call();
const allowance = await contract.allowance(wallet.address, req.query.spender);

res.json({ allowanceInWei: String(allowanceInWei) });
res.json({ allowanceInWei: allowance.toString() });
};
export { controller, validation };
10 changes: 5 additions & 5 deletions apps/api/src/app/controllers/erc20/allowance/post.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { Request, Response } from 'express';
import { body, query } from 'express-validator';
import { ForbiddenError, NotFoundError } from '@thxnetwork/api/util/errors';
import { getProvider } from '@thxnetwork/api/util/network';
import { BigNumber } from 'ethers';
import { getAbiForContractName } from '@thxnetwork/api/services/ContractService';
import { BigNumber } from 'alchemy-sdk';
import { getArtifact } from '@thxnetwork/api/hardhat';
import TransactionService from '@thxnetwork/api/services/TransactionService';
import WalletService from '@thxnetwork/api/services/WalletService';

Expand All @@ -21,14 +21,14 @@ const controller = async (req: Request, res: Response) => {
if (wallet.sub !== req.auth.sub) throw new ForbiddenError('Wallet not owned by sub.');

const { web3 } = getProvider(wallet.chainId);

const abi = getAbiForContractName('LimitedSupplyToken');
const { abi } = getArtifact('THXERC20_LimitedSupply');
const contract = new web3.eth.Contract(abi, req.body.tokenAddress);
const amount = await contract.methods.balanceOf(wallet.address).call();

// Check sufficient BPT Balance
if (BigNumber.from(amount).lt(BigNumber.from(req.body.amountInWei)))
if (BigNumber.from(amount).lt(BigNumber.from(req.body.amountInWei))) {
throw new ForbiddenError('Insufficient balance');
}

const fn = contract.methods.approve(req.body.spender, req.body.amountInWei);

Expand Down
8 changes: 4 additions & 4 deletions apps/api/src/app/controllers/erc20/balance/get.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ const controller = async (req: Request, res: Response) => {
const wallet = await WalletService.findById(walletId);
if (!wallet) throw new NotFoundError('Wallet not found');

const contract = ContractService.getContractFromAbi(
const contract = ContractService.getContract(
'THXERC20_LimitedSupply',
wallet.chainId,
ContractService.getAbiForContractName('LimitedSupplyToken'),
req.query.tokenAddress as string,
);
const balanceInWei = await contract.methods.balanceOf(wallet.address).call();
const balance = await contract.balanceOf(wallet.address);

res.json({ balanceInWei });
res.json({ balanceInWei: balance.toString() });
};
export { controller, validation };
2 changes: 1 addition & 1 deletion apps/api/src/app/controllers/erc20/erc20.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import request from 'supertest';
import app from '@thxnetwork/api/';
import { ChainId, ERC20Type } from '@thxnetwork/common/enums';
import { afterAllCallback, beforeAllCallback } from '@thxnetwork/api/util/jest/config';
import { isAddress } from 'ethers/lib/utils';
import { isAddress } from 'ethers';
import { dashboardAccessToken } from '@thxnetwork/api/util/jest/constants';
import { createImage } from '@thxnetwork/api/util/jest/images';
import { toWei } from 'web3-utils';
Expand Down
10 changes: 5 additions & 5 deletions apps/api/src/app/controllers/erc20/preview/get.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ const validation = [query('chainId').isInt(), query('address').isEthereumAddress
const controller = async (req: Request, res: Response) => {
const chainId = req.query.chainId as unknown as ChainId;
const contractAddress = req.query.address as string;
const contract = ContractService.getContractFromName(chainId, 'LimitedSupplyToken', contractAddress);
const contract = ContractService.getContract('THXERC20_LimitedSupply', chainId, contractAddress);
const [name, symbol, totalSupplyInWei] = await Promise.all([
contract.methods.name().call(),
contract.methods.symbol().call(),
contract.methods.totalSupply().call(),
contract.name(),
contract.symbol(),
contract.totalSupply(),
]);

res.json({ name, symbol, totalSupplyInWei });
res.json({ name, symbol, totalSupplyInWei: totalSupplyInWei.toString() });
};
export { controller, validation };
23 changes: 9 additions & 14 deletions apps/api/src/app/controllers/health/list.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import { ChainId } from '@thxnetwork/common/enums';
import { logger } from '@thxnetwork/api/util/logger';
import { getProvider } from '@thxnetwork/api/util/network';
import { ethers } from 'ethers';
import { contractArtifacts } from '@thxnetwork/api/services/ContractService';
import { contractNetworks } from '@thxnetwork/api/hardhat';
import { getArtifact, contractNetworks } from '@thxnetwork/api/hardhat';
import { BigNumber } from 'alchemy-sdk';

function handleError(error: Error) {
Expand All @@ -21,31 +20,27 @@ async function getNetworkDetails(chainId: ChainId) {
const { defaultAccount, web3, signer } = getProvider(chainId);
const rfthx = new ethers.Contract(
contractNetworks[chainId].RewardFaucet,
contractArtifacts['RewardFaucet'].abi,
getArtifact('RewardFaucet').abi,
signer,
);
const registry = new ethers.Contract(
contractNetworks[chainId].THXRegistry,
contractArtifacts['THXRegistry'].abi,
getArtifact('THXRegistry').abi,
signer,
);
const rdthx = new ethers.Contract(
contractNetworks[chainId].RewardDistributor,
contractArtifacts['RewardDistributor'].abi,
signer,
);
const bpt = new ethers.Contract(contractNetworks[chainId].BPT, contractArtifacts['BPT'].abi, signer);
const bptGauge = new ethers.Contract(
contractNetworks[chainId].BPTGauge,
contractArtifacts['BPTGauge'].abi,
getArtifact('RewardDistributor').abi,
signer,
);
const bpt = new ethers.Contract(contractNetworks[chainId].BPT, getArtifact('BPT').abi, signer);
const bptGauge = new ethers.Contract(contractNetworks[chainId].BPTGauge, getArtifact('BPTGauge').abi, signer);
const veTHX = new ethers.Contract(
contractNetworks[chainId].VotingEscrow,
contractArtifacts['VotingEscrow'].abi,
getArtifact('VotingEscrow').abi,
signer,
);
const bal = new ethers.Contract(contractNetworks[chainId].BAL, contractArtifacts['BAL'].abi, signer);
const bal = new ethers.Contract(contractNetworks[chainId].BAL, getArtifact('BAL').abi, signer);
// const thx = new ethers.Contract(contractNetworks[chainId].THX, contractArtifacts['THX'].abi, signer);
// const usdc = new ethers.Contract(contractNetworks[chainId].USDC, contractArtifacts['USDC'].abi, signer);

Expand Down Expand Up @@ -104,7 +99,7 @@ async function getNetworkDetails(chainId: ChainId) {
};
const splitter = new ethers.Contract(
contractNetworks[chainId].THXPaymentSplitter,
contractArtifacts['THXPaymentSplitter'].abi,
getArtifact('THXPaymentSplitter').abi,
signer,
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { contractArtifacts } from '@thxnetwork/api/services/ContractService';
import { getArtifact } from '@thxnetwork/api/hardhat';
import { BadRequestError } from '@thxnetwork/api/util/errors';
import { getProvider } from '@thxnetwork/api/util/network';
import { contractNetworks } from '@thxnetwork/api/contracts';
import { BigNumber } from 'ethers';
import { contractNetworks } from '@thxnetwork/api/hardhat';
import { Request, Response } from 'express';
import { body, query } from 'express-validator';
import { BigNumber } from 'alchemy-sdk';
import LiquidityService from '@thxnetwork/api/services/LiquidityService';

const validation = [body('amountInWei').isString(), query('walletId').isMongoId()];

const controller = async ({ wallet, body }: Request, res: Response) => {
const { web3 } = getProvider(wallet.chainId);
const bpt = new web3.eth.Contract(contractArtifacts['BPT'].abi, contractNetworks[wallet.chainId].BPT);
const bpt = new web3.eth.Contract(getArtifact('BPT').abi, contractNetworks[wallet.chainId].BPT);

// Check if sender has sufficient BPT
const balanceInWei = await bpt.methods.balanceOf(wallet.address).call();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Request, Response } from 'express';
import { query } from 'express-validator';
import { NotFoundError } from '@thxnetwork/api/util/errors';
import { Pool } from '@thxnetwork/api/models';
import ContractService from '@thxnetwork/api/services/ContractService';
import SafeService from '@thxnetwork/api/services/SafeService';
import { Pool } from '@thxnetwork/api/models';

const validation = [query('contractAddress').isEthereumAddress(), query('tokenId').isInt()];

Expand All @@ -14,9 +14,8 @@ const controller = async (req: Request, res: Response) => {
const safe = await SafeService.findOneByPool(pool, pool.chainId);
if (!safe) throw new NotFoundError('Safe not found');

const abi = ContractService.getAbiForContractName('THX_ERC1155');
const contract = ContractService.getContractFromAbi(pool.chainId, abi, req.query.contractAddress as string);
const balance = await contract.methods.balanceOf(safe.address, req.query.tokenId).call();
const contract = ContractService.getContract('THXERC1155', pool.chainId, req.query.contractAddress as string);
const balance = await contract.balanceOf(safe.address, req.query.tokenId);

res.json({ balance });
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ const controller = async (req: Request, res: Response) => {
const safe = await SafeService.findOneByPool(pool);
if (!safe) throw new NotFoundError('Wallet not found');

const contract = ContractService.getContractFromName(
const contract = ContractService.getContract(
'THXERC20_LimitedSupply',
safe.chainId,
'LimitedSupplyToken',
req.query.tokenAddress as string,
);
const allowanceInWei = await contract.methods.allowance(safe.address, req.query.spender).call();
const allowance = await contract.allowance(safe.address, req.query.spender);

res.json({ allowanceInWei: String(allowanceInWei) });
res.json({ allowanceInWei: allowance.toString() });
};
export { controller, validation };
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Request, Response } from 'express';
import { body, param } from 'express-validator';
import { NotFoundError } from '@thxnetwork/api/util/errors';
import { getProvider } from '@thxnetwork/api/util/network';
import { getAbiForContractName } from '@thxnetwork/api/services/ContractService';
import { getArtifact } from '@thxnetwork/api/hardhat';
import TransactionService from '@thxnetwork/api/services/TransactionService';
import PoolService from '@thxnetwork/api/services/PoolService';
import SafeService from '@thxnetwork/api/services/SafeService';
Expand All @@ -23,8 +23,7 @@ const controller = async (req: Request, res: Response) => {
if (!safe) throw new NotFoundError('Wallet not found');

const { web3 } = getProvider(safe.chainId);

const abi = getAbiForContractName('LimitedSupplyToken');
const { abi } = getArtifact('THXERC20_LimitedSupply');
const contract = new web3.eth.Contract(abi, req.body.tokenAddress);
const fn = contract.methods.approve(req.body.spender, req.body.amountInWei);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ const controller = async (req: Request, res: Response) => {
const safe = await SafeService.findOneByPool(pool, pool.chainId);
if (!safe) throw new NotFoundError('Campaign Safe not found.');

const contract = ContractService.getContractFromAbi(
const contract = ContractService.getContract(
'THXERC20_LimitedSupply',
safe.chainId,
ContractService.getAbiForContractName('LimitedSupplyToken'),
req.query.tokenAddress as string,
);
const balanceInWei = await contract.methods.balanceOf(safe.address).call();
const balance = await contract.balanceOf(safe.address);

res.json({ balanceInWei: String(balanceInWei) });
res.json({ balanceInWei: balance.toString() });
};

export { controller, validation };
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Request, Response } from 'express';
import { InsufficientAllowanceError, InsufficientBalanceError, NotFoundError } from '@thxnetwork/api/util/errors';
import { body, param } from 'express-validator';
import { BigNumber } from 'ethers';
import { contractArtifacts, contractNetworks } from '@thxnetwork/api/contracts';
import { BigNumber } from 'alchemy-sdk';
import { contractArtifacts, contractNetworks } from '@thxnetwork/api/hardhat';
import { getProvider } from '@thxnetwork/api/util/network';
import PoolService from '@thxnetwork/api/services/PoolService';
import SafeService from '@thxnetwork/api/services/SafeService';
Expand Down
4 changes: 2 additions & 2 deletions apps/api/src/app/controllers/pools/post.controller.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Request, Response } from 'express';
import { body } from 'express-validator';
import { getChainId, safeVersion } from '@thxnetwork/api/services/ContractService';
import ContractService, { safeVersion } from '@thxnetwork/api/services/ContractService';
import PoolService from '@thxnetwork/api/services/PoolService';
import SafeService from '@thxnetwork/api/services/SafeService';

Expand All @@ -12,7 +12,7 @@ const controller = async (req: Request, res: Response) => {

// Deploy a Safe for the campaign
const poolId = String(pool._id);
const chainId = getChainId();
const chainId = ContractService.getChainId();
const safe = await SafeService.create({ chainId, sub: req.auth.sub, safeVersion, poolId });

// Update predicted safe address for pool
Expand Down
4 changes: 2 additions & 2 deletions apps/api/src/app/controllers/ve/deposit/post.controller.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Request, Response } from 'express';
import { body, query } from 'express-validator';
import { ForbiddenError } from '@thxnetwork/api/util/errors';
import { BigNumber } from 'ethers';
import { BigNumber } from 'alchemy-sdk';
import { getProvider } from '@thxnetwork/api/util/network';
import { contractNetworks } from '@thxnetwork/api/contracts';
import { contractNetworks } from '@thxnetwork/api/hardhat';
import VoteEscrowService from '@thxnetwork/api/services/VoteEscrowService';

const validation = [body('amountInWei').isString(), body('lockEndTimestamp').isInt(), query('walletId').isMongoId()];
Expand Down
Loading

0 comments on commit 1713828

Please sign in to comment.