Skip to content

Commit

Permalink
Adds hardhat
Browse files Browse the repository at this point in the history
  • Loading branch information
peterpolman committed May 16, 2024
1 parent 3d28a25 commit 4e6f0a6
Show file tree
Hide file tree
Showing 33 changed files with 2,784 additions and 141 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [20.x] # Add other versions if needed
node-version: [18.x] # Add other versions if needed

steps:
- name: Checkout repository
Expand Down Expand Up @@ -48,8 +48,10 @@ jobs:
key: ${{ runner.os }}-node-${{ hashFiles('**/yarn.lock') }}

- name: Start Hardhat RPC
working-directory: ./libs/contracts
run: npx hardhat node --hostname 0.0.0.0 > /dev/null &
working-directory: ./apps/api/hardhat
run: |
npx hardhat node --hostname 0.0.0.0 > /dev/null &
npx hardhat run scripts/deploy.ts --network localhost
- name: Start Safe Transaction Service
run: |
Expand Down
42 changes: 21 additions & 21 deletions apps/api/src/app/contracts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,33 +21,33 @@ import THXPaymentSplitter from './abis/THXPaymentSplitter.json';
export const contractNetworks = {
'31337': {
// Safe
safeMasterCopyAddress: '0xC44951780f195Ed71145e3d0d2F25726A097C348',
safeProxyFactoryAddress: '0x1122fD9eBB2a8E7c181Cc77705d2B4cA5D72988A',
multiSendAddress: '0x7E4728eFfC9376CC7C0EfBCc779cC9833D83a984',
multiSendCallOnlyAddress: '0x75Cbb6C4Db4Bb4f6F8D5F56072A6cF4Bf4C5413C',
fallbackHandlerAddress: '0x5D3D550Da6678C0444F5D77Ca086678D9CdeEecA',
signMessageLibAddress: '0x658FAD2acB6d1E615f295E566ee9a6d32Cc97b10',
createCallAddress: '0x40Efd8a16485213445E6d8b9a4266Fd2dFf7C69a',
simulateTxAccessorAddress: '0xFF1eE64b8806C0891e8F73b37f8403F441b552E1',
simulateTxAccessorAddress: '0xB952d9b5de7804691e7936E88915A669B15822ef',
safeProxyFactoryAddress: '0x50aF0922d65D04D87d810048Dc640E2474eBfbd9',
fallbackHandlerAddress: '0x278Ff6d33826D906070eE938CDc9788003749e93',
createCallAddress: '0xEAB9a65eB0F098f822033192802B53EE159De5F0',
multiSendAddress: '0x15FC0878406CcF4d2963235A5B1EF68C67F17Ee5',
multiSendCallOnlyAddress: '0xa4E84979c95cD4f12C53E73d63E0A8634A1f44Ae',
signMessageLibAddress: '0xd916a690676e925Ac9Faf2d01869c13Fd9757ef2',
safeMasterCopyAddress: '0xb63564A81D5d4004F4f22E9aB074cE25540B0C26',

// Tokens
THX: '0xc368fA6A4057BcFD9E49221d8354d5fA6B88945a',
USDC: '0x439F0128d07f005e0703602f366599ACaaBfEA18',
BAL: '0x24E91C3a2822bDc4bc73512872ab07fD93c8101b',
BPT: '0x76aBe9ec9b15947ba1Ca910695B8b6CffeD8E6CA',
BPTGauge: '0x7Cb8d1EAd6303C079c501e93F3ba28C227cd7000',
BalancerVault: '0xb3B2b0fc5ce12aE58EEb13E19547Eb2Dd61A79D5',
THX: '0xf228ADAa4c3D07C8285C1025421afe2c4F320C59',
USDC: '0x8613B8E442219e4349fa5602C69431131a7ED114',
BAL: '0x7150A3CC09429583471020A6CE5228A57736180a',
BPT: '0xe1c01805a21ee0DC535afa93172a5F21CE160649',
BPTGauge: '0x8B219D3d1FC64e03F6cF3491E7C7A732bF253EC8',
BalancerVault: '0xeDdBA2bDeE7c9006944aCF9379Daa64478E02290',

// veTHX
VotingEscrow: '0xFB1aEd47351005cE1BF85a339C019bea96BC9a21',
RewardDistributor: '0x1BBfB8A870823D52Ed42F4Ad0706f37F32C229a7',
RewardFaucet: '0xF880B1920Eb6c1A45162900059150D22faFc2070',
SmartWalletWhitelist: '0x36260689483bc55753E3258725f31E8aee31A7B0',
LensReward: '0x8c4Ca9343734227366653495cC068aB03B4f5bee',
VotingEscrow: '0xdb8549fdb720C35b926fC3fFF2FfBec61383E994',
RewardDistributor: '0xD98E8ac8D53e3330b5DBc3425FB178810128A9e5',
RewardFaucet: '0x3e3B1997c3Bc3Cf512359EEa6d9cAd19394D51B4',
SmartWalletWhitelist: '0x774442713f32fa98bf27bEc78c96fb7186f7C223',
LensReward: '0xb2Bea6009625407C3c3cF7158185125Ed2C7f101',

// Company
THXRegistry: '0x726C9c8278eC209CfBE6BBb1d02e65dF6FcB7cdA',
THXPaymentSplitter: '0x50861908E2Bb609524D63F5b4E57d3CACaDf09C2',
THXRegistry: '0xa4cBDae70871E8664b8de077765DDA2f4cc90d02',
THXPaymentSplitter: '0xe42CA31C24ee6bA76DBd87D86ab66D45b65ee5A2',
CompanyMultiSig: '0xaf9d56684466fcFcEA0a2B7fC137AB864d642946',
},
'137': {
Expand Down
17 changes: 17 additions & 0 deletions apps/api/src/app/hardhat/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
node_modules
.env

# Hardhat files
/cache
/artifacts

# TypeChain files
/typechain
/typechain-types

# solidity-coverage files
/coverage
/coverage.json

# Hardhat Ignition default folder for deployments against a local node
ignition/deployments/chain-31337
27 changes: 27 additions & 0 deletions apps/api/src/app/hardhat/contracts/ImportSafe.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.7.4;

import '@gnosis.pm/safe-contracts/contracts/accessors/SimulateTxAccessor.sol';
import '@gnosis.pm/safe-contracts/contracts/proxies/GnosisSafeProxyFactory.sol';
import '@gnosis.pm/safe-contracts/contracts/handler/DefaultCallbackHandler.sol';
import '@gnosis.pm/safe-contracts/contracts/handler/CompatibilityFallbackHandler.sol';
import '@gnosis.pm/safe-contracts/contracts/libraries/CreateCall.sol';
import '@gnosis.pm/safe-contracts/contracts/libraries/MultiSend.sol';
import '@gnosis.pm/safe-contracts/contracts/libraries/MultiSendCallOnly.sol';
import '@gnosis.pm/safe-contracts/contracts/examples/libraries/SignMessage.sol';
import '@gnosis.pm/safe-contracts/contracts/GnosisSafeL2.sol';
import '@gnosis.pm/safe-contracts/contracts/GnosisSafe.sol';

// Get the compiler to pick up these facets
contract ImportSafe {
SimulateTxAccessor public simulateTxAccessor;
GnosisSafeProxyFactory public gnosisSafeProxyFactory;
DefaultCallbackHandler public defaultCallbackHandler;
CompatibilityFallbackHandler public compatibilityFallbackHandler;
CreateCall public createCall;
MultiSend public multiSend;
MultiSendCallOnly public multiSendCallOnly;
SignMessageLib public signMessageLib;
GnosisSafeL2 public gnosisSafeL2;
GnosisSafe public gnosisSafe;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.7.6;

interface IAccessControlEvents {
event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);
event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);
event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);
}
15 changes: 15 additions & 0 deletions apps/api/src/app/hardhat/contracts/mock/BAL.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// SPDX-License-Identifier: Apache-2.0

pragma solidity ^0.7.6;

import '@openzeppelin/contracts/token/ERC20/ERC20.sol';

contract BAL is ERC20 {
constructor(address to, uint256 amount) ERC20('Balancer', 'BAL') {
_mint(to, amount);
}

function mint(address to, uint256 amount) external {
_mint(to, amount);
}
}
31 changes: 31 additions & 0 deletions apps/api/src/app/hardhat/contracts/mock/BPT.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// SPDX-License-Identifier: Apache-2.0

pragma solidity ^0.7.6;

import '@openzeppelin/contracts/token/ERC20/ERC20.sol';

interface IWeightedPool is IERC20 {
function setVault(address _vault) external;
function getVault() external view returns (address);
function getPoolId() external view returns (bytes32);
}

contract BPT is ERC20, IWeightedPool {
address public vault;

constructor(address _to, uint256 _amount) ERC20('20USDC-80THX', '20USDC-80THX') {
_mint(_to, _amount);
}

function setVault(address _vault) external override {
vault = _vault;
}

function getVault() external override view returns (address) {
return vault;
}

function getPoolId() external override pure returns (bytes32) {
return 0xb204bf10bc3a5435017d3db247f56da601dfe08a0002000000000000000000fe;
}
}
60 changes: 60 additions & 0 deletions apps/api/src/app/hardhat/contracts/mock/BPTGauge.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// SPDX-License-Identifier: Apache-2.0
pragma abicoder v2;
pragma solidity ^0.7.6;

import '@openzeppelin/contracts/token/ERC20/ERC20.sol';

interface IGauge is IERC20 {
function deposit(uint256 _value) external;
function withdraw(uint256 _value) external;
function lp_token() external view returns (address);
function working_supply() external view returns (uint256);
}

contract BPTGauge is ERC20, IGauge {
IERC20 public bpt;

event Deposit(address indexed user, uint256 value);
event Withdraw(address indexed user, uint256 value);

constructor(address _bpt) ERC20('Balancer 20USDC-80THX Gauge Deposit', '20USDC-80THX-gauge') {
bpt = IERC20(_bpt);
}

/*
* @dev Deposit LP tokens in the gauge and mint BPTGauge for msg.sender
* @param _value Amount of LP tokens to deposit
*/
function deposit(uint256 _value) external override {
// Transfer BPT from the user to the gauge
bpt.transferFrom(msg.sender, address(this), _value);

// Mint BPTGauge tokens to the user
_mint(msg.sender, _value);

emit Deposit(msg.sender, _value);
}

/*
* @dev Withdraw LP tokens from the gauge
* @param _value Amount of LP tokens to withdraw
* @notice This mock function will not decrease the totalSupply
*/
function withdraw(uint256 _value) external override {
// Transfer staked BPT from the gauge to the user
bpt.transfer(msg.sender, _value);

// Burn BPTGauge for the user
transferFrom(msg.sender, address(0), _value);

emit Withdraw(msg.sender, _value);
}

function lp_token() external override view returns (address) {
return address(bpt);
}

function working_supply() external override pure returns (uint256) {
return 585909572986408132343905;
}
}
41 changes: 41 additions & 0 deletions apps/api/src/app/hardhat/contracts/mock/BalancerVault.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// SPDX-License-Identifier: Apache-2.0
pragma abicoder v2;
pragma solidity ^0.7.6;

import '@openzeppelin/contracts/token/ERC20/ERC20.sol';
import "@openzeppelin/contracts/math/SafeMath.sol";
import 'hardhat/console.sol';

contract BalancerVault {
using SafeMath for uint256;

ERC20 public bpt;
ERC20 public usdc;
ERC20 public thx;

struct JoinPoolRequest {
address[] assets;
uint256[] maxAmountsIn;
bytes userData;
bool fromInternalBalance;
}

constructor(address _bpt, address _usdc, address _thx) {
bpt = ERC20(_bpt);
usdc = ERC20(_usdc);
thx = ERC20(_thx);
}

function joinPool(bytes32 poolId, address sender, address recipient, JoinPoolRequest memory request) external {
usdc.transferFrom(sender, address(this), request.maxAmountsIn[0]);
thx.transferFrom(sender, address(this), request.maxAmountsIn[1]);

// Assumes BalancerVault has a BPT balance and transfers BPT to recipient
// Aligns decimals in order to get to a workable BPT amount
uint256 usdcAmount = request.maxAmountsIn[0].div(10**usdc.decimals());
uint256 thxAmount = request.maxAmountsIn[1].div(10**thx.decimals());
uint256 amount = usdcAmount.add(thxAmount).mul(10**bpt.decimals());

require(bpt.transfer(recipient, amount), 'BalancerVault: BPT transfer failed');
}
}
11 changes: 11 additions & 0 deletions apps/api/src/app/hardhat/contracts/mock/ExampleToken.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// SPDX-License-Identifier: Apache-2.0

pragma solidity ^0.7.6;

import '@openzeppelin/contracts/token/ERC20/ERC20.sol';

contract ExampleToken is ERC20 {
constructor(address to, uint256 amount) ERC20('Test Token', 'TEST') {
_mint(to, amount);
}
}
11 changes: 11 additions & 0 deletions apps/api/src/app/hardhat/contracts/mock/THX.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// SPDX-License-Identifier: Apache-2.0

pragma solidity ^0.7.6;

import '@openzeppelin/contracts/token/ERC20/ERC20.sol';

contract THX is ERC20 {
constructor(address to, uint256 amount) ERC20('THX Network (PoS)', 'THX') {
_mint(to, amount);
}
}
12 changes: 12 additions & 0 deletions apps/api/src/app/hardhat/contracts/mock/USDC.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// SPDX-License-Identifier: Apache-2.0

pragma solidity ^0.7.6;

import '@openzeppelin/contracts/token/ERC20/ERC20.sol';

contract USDC is ERC20 {
constructor(address to, uint256 amount) ERC20('USD Coin (PoS)', 'USDC.e') {
_setupDecimals(6);
_mint(to, amount);
}
}
38 changes: 38 additions & 0 deletions apps/api/src/app/hardhat/contracts/utils/BondPurchaseChecker.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// SPDX-License-Identifier: Apache-2.0
pragma abicoder v2;
pragma solidity ^0.7.6;

interface ICustomBill {
struct Bill {
uint256 payout;
uint256 payoutClaimed;
uint256 vesting;
uint256 vestingTerm;
uint256 vestingStartTimestamp;
uint256 lastClaimTimestamp;
uint256 truePricePaid;
}

function getBillIds(address user) external view returns (uint[] memory);
function getBillInfo(uint256 billId) external view returns (Bill memory);
}

contract BondPurchaseChecker {
ICustomBill bond;

constructor(address _bondContractAddress) {
bond = ICustomBill(_bondContractAddress);
}

function largestPayoutOf(address _user) public view returns (uint256) {
uint[] memory billIds = bond.getBillIds(_user);
uint256 largestPayout = 0;

for (uint i = 0; i < billIds.length; i++) {
uint256 payout = bond.getBillInfo(billIds[i]).payout;
largestPayout = payout > largestPayout ? payout : largestPayout;
}

return largestPayout;
}
}
14 changes: 14 additions & 0 deletions apps/api/src/app/hardhat/contracts/utils/ERC1155/ITHX_ERC1155.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.7.6;

import '@openzeppelin/contracts/token/ERC1155/IERC1155.sol';

interface ITHX_ERC1155 is IERC1155 {
function mint(address to, uint256 id, uint256 amount, bytes memory data) external;
function mintBatch(
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) external;
}
Loading

0 comments on commit 4e6f0a6

Please sign in to comment.