-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
45 changed files
with
7,361 additions
and
189 deletions.
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,37 @@ | ||
name: Deploy to hardhat Development Server | ||
|
||
on: | ||
push: | ||
branches: | ||
- 'develop' | ||
|
||
jobs: | ||
deploy-hardhat-network: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Copy files to server | ||
uses: easingthemes/ssh-deploy@main | ||
env: | ||
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} | ||
REMOTE_HOST: ${{ secrets.REMOTE_HOST }} | ||
ARGS: '-rlgoDzvc -i --delete' | ||
REMOTE_USER: ${{ secrets.REMOTE_USER }} | ||
TARGET: '/root/penx' | ||
SOURCE: './' | ||
|
||
- name: Run Node.js service | ||
uses: appleboy/[email protected] | ||
with: | ||
host: ${{ secrets.REMOTE_HOST }} | ||
username: ${{ secrets.REMOTE_USER }} | ||
key: ${{ secrets.SSH_PRIVATE_KEY }} | ||
script: | | ||
whoami | ||
ls -al | ||
cd /root/penx/apps/protocol | ||
npm i --no-package-lock | ||
npm run hardhat:development |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
{ | ||
"search.followSymlinks": false | ||
"search.followSymlinks": false, | ||
"cSpell.enableFiletypes": ["solidity"] | ||
} |
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,17 @@ | ||
node_modules | ||
.env | ||
.DS_Store | ||
.deps | ||
.VSCodeCounter | ||
coverage | ||
coverage.json | ||
typechain | ||
typechain-types | ||
|
||
# Hardhat files | ||
cache | ||
artifacts | ||
|
||
types | ||
test/generated.ts | ||
abi |
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,16 @@ | ||
'use strict' | ||
process.env.TS_NODE_FILES = true | ||
module.exports = { | ||
'allow-uncaught': true, | ||
diff: true, | ||
extension: ['ts'], | ||
recursive: true, | ||
reporter: 'spec', | ||
require: ['ts-node/register', 'hardhat/register'], // ['ts-node/register/transpile-only'], (for yarn link <plugin>) | ||
slow: 300, | ||
spec: 'test/**/*.test.ts', | ||
timeout: 20000, | ||
ui: 'bdd', | ||
watch: false, | ||
'watch-files': ['src/**/*.sol', 'test/**/*.ts'], | ||
} |
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 @@ | ||
bracketSpacing: true | ||
plugins: | ||
- "prettier-plugin-solidity" | ||
printWidth: 120 | ||
proseWrap: "always" | ||
singleQuote: true | ||
semi: false | ||
tabWidth: 2 | ||
trailingComma: "all" | ||
|
||
overrides: | ||
- files: "*.sol" | ||
options: | ||
semi: true | ||
compiler: "0.8.17" | ||
singleQuote: false | ||
parser: "solidity-parse" | ||
tabWidth: 4 | ||
- files: "*.ts" | ||
options: | ||
importOrder: ["<THIRD_PARTY_MODULES>", "^[./]"] | ||
importOrderParserPlugins: ["typescript"] | ||
importOrderSeparation: true | ||
importOrderSortSpecifiers: true | ||
parser: "typescript" |
Empty file.
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,30 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.18; | ||
|
||
/******************************************************************************\ | ||
* Author: Nick Mudge <[email protected]> (https://twitter.com/mudgen) | ||
* EIP-2535 Diamonds: https://eips.ethereum.org/EIPS/eip-2535 | ||
/******************************************************************************/ | ||
|
||
import { IDiamondCut } from "../interfaces/IDiamondCut.sol"; | ||
import { LibDiamond } from "../storage/LibDiamond.sol"; | ||
|
||
// Remember to add the loupe functions from DiamondLoupeFacet to the diamond. | ||
// The loupe functions are required by the EIP2535 Diamonds standard | ||
|
||
contract DiamondCutFacet is IDiamondCut { | ||
/// @notice Add/replace/remove any number of functions and optionally execute | ||
/// a function with delegatecall | ||
/// @param _diamondCut Contains the facet addresses and function selectors | ||
/// @param _init The address of the contract or facet to execute _calldata | ||
/// @param _calldata A function call, including function selector and arguments | ||
/// _calldata is executed with delegatecall on _init | ||
function diamondCut( | ||
FacetCut[] calldata _diamondCut, | ||
address _init, | ||
bytes calldata _calldata | ||
) external override { | ||
LibDiamond.enforceIsContractOwner(); | ||
LibDiamond.diamondCut(_diamondCut, _init, _calldata); | ||
} | ||
} |
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,147 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.18; | ||
/******************************************************************************\ | ||
* Author: Nick Mudge <[email protected]> (https://twitter.com/mudgen) | ||
* EIP-2535 Diamonds: https://eips.ethereum.org/EIPS/eip-2535 | ||
/******************************************************************************/ | ||
|
||
// The functions in DiamondLoupeFacet MUST be added to a diamond. | ||
// The EIP-2535 Diamond standard requires these functions. | ||
|
||
import "@openzeppelin/contracts/utils/introspection/IERC165.sol"; | ||
import { LibDiamond } from "../storage/LibDiamond.sol"; | ||
import { IDiamondLoupe } from "../interfaces/IDiamondLoupe.sol"; | ||
|
||
contract DiamondLoupeFacet is IDiamondLoupe, IERC165 { | ||
// Diamond Loupe Functions | ||
//////////////////////////////////////////////////////////////////// | ||
/// These functions are expected to be called frequently by tools. | ||
// | ||
// struct Facet { | ||
// address facetAddress; | ||
// bytes4[] functionSelectors; | ||
// } | ||
/// @notice Gets all facets and their selectors. | ||
/// @return facets_ Facet | ||
function facets() external override view returns (Facet[] memory facets_) { | ||
LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage(); | ||
uint256 selectorCount = ds.selectors.length; | ||
// create an array set to the maximum size possible | ||
facets_ = new Facet[](selectorCount); | ||
// create an array for counting the number of selectors for each facet | ||
uint16[] memory numFacetSelectors = new uint16[](selectorCount); | ||
// total number of facets | ||
uint256 numFacets; | ||
// loop through function selectors | ||
for (uint256 selectorIndex; selectorIndex < selectorCount; selectorIndex++) { | ||
bytes4 selector = ds.selectors[selectorIndex]; | ||
address facetAddress_ = ds.facetAddressAndSelectorPosition[selector].facetAddress; | ||
bool continueLoop = false; | ||
// find the functionSelectors array for selector and add selector to it | ||
for (uint256 facetIndex; facetIndex < numFacets; facetIndex++) { | ||
if (facets_[facetIndex].facetAddress == facetAddress_) { | ||
facets_[facetIndex].functionSelectors[numFacetSelectors[facetIndex]] = selector; | ||
numFacetSelectors[facetIndex]++; | ||
continueLoop = true; | ||
break; | ||
} | ||
} | ||
// if functionSelectors array exists for selector then continue loop | ||
if (continueLoop) { | ||
continueLoop = false; | ||
continue; | ||
} | ||
// create a new functionSelectors array for selector | ||
facets_[numFacets].facetAddress = facetAddress_; | ||
facets_[numFacets].functionSelectors = new bytes4[](selectorCount); | ||
facets_[numFacets].functionSelectors[0] = selector; | ||
numFacetSelectors[numFacets] = 1; | ||
numFacets++; | ||
} | ||
for (uint256 facetIndex; facetIndex < numFacets; facetIndex++) { | ||
uint256 numSelectors = numFacetSelectors[facetIndex]; | ||
bytes4[] memory selectors = facets_[facetIndex].functionSelectors; | ||
// setting the number of selectors | ||
assembly { | ||
mstore(selectors, numSelectors) | ||
} | ||
} | ||
// setting the number of facets | ||
assembly { | ||
mstore(facets_, numFacets) | ||
} | ||
} | ||
|
||
/// @notice Gets all the function selectors supported by a specific facet. | ||
/// @param _facet The facet address. | ||
/// @return _facetFunctionSelectors The selectors associated with a facet address. | ||
function facetFunctionSelectors(address _facet) external override view returns (bytes4[] memory _facetFunctionSelectors) { | ||
LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage(); | ||
uint256 selectorCount = ds.selectors.length; | ||
uint256 numSelectors; | ||
_facetFunctionSelectors = new bytes4[](selectorCount); | ||
// loop through function selectors | ||
for (uint256 selectorIndex; selectorIndex < selectorCount; selectorIndex++) { | ||
bytes4 selector = ds.selectors[selectorIndex]; | ||
address facetAddress_ = ds.facetAddressAndSelectorPosition[selector].facetAddress; | ||
if (_facet == facetAddress_) { | ||
_facetFunctionSelectors[numSelectors] = selector; | ||
numSelectors++; | ||
} | ||
} | ||
// Set the number of selectors in the array | ||
assembly { | ||
mstore(_facetFunctionSelectors, numSelectors) | ||
} | ||
} | ||
|
||
/// @notice Get all the facet addresses used by a diamond. | ||
/// @return facetAddresses_ | ||
function facetAddresses() external override view returns (address[] memory facetAddresses_) { | ||
LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage(); | ||
uint256 selectorCount = ds.selectors.length; | ||
// create an array set to the maximum size possible | ||
facetAddresses_ = new address[](selectorCount); | ||
uint256 numFacets; | ||
// loop through function selectors | ||
for (uint256 selectorIndex; selectorIndex < selectorCount; selectorIndex++) { | ||
bytes4 selector = ds.selectors[selectorIndex]; | ||
address facetAddress_ = ds.facetAddressAndSelectorPosition[selector].facetAddress; | ||
bool continueLoop = false; | ||
// see if we have collected the address already and break out of loop if we have | ||
for (uint256 facetIndex; facetIndex < numFacets; facetIndex++) { | ||
if (facetAddress_ == facetAddresses_[facetIndex]) { | ||
continueLoop = true; | ||
break; | ||
} | ||
} | ||
// continue loop if we already have the address | ||
if (continueLoop) { | ||
continueLoop = false; | ||
continue; | ||
} | ||
// include address | ||
facetAddresses_[numFacets] = facetAddress_; | ||
numFacets++; | ||
} | ||
// Set the number of facet addresses in the array | ||
assembly { | ||
mstore(facetAddresses_, numFacets) | ||
} | ||
} | ||
|
||
/// @notice Gets the facet address that supports the given selector. | ||
/// @dev If facet is not found return address(0). | ||
/// @param _functionSelector The function selector. | ||
/// @return facetAddress_ The facet address. | ||
function facetAddress(bytes4 _functionSelector) external override view returns (address facetAddress_) { | ||
LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage(); | ||
facetAddress_ = ds.facetAddressAndSelectorPosition[_functionSelector].facetAddress; | ||
} | ||
|
||
// This implements ERC-165. | ||
function supportsInterface(bytes4 _interfaceId) external override view returns (bool) { | ||
LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage(); | ||
return ds.supportedInterfaces[_interfaceId]; | ||
} | ||
} |
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,20 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
/******************************************************************************\ | ||
* Author: Nick Mudge <[email protected]> (https://twitter.com/mudgen) | ||
* EIP-2535 Diamonds: https://eips.ethereum.org/EIPS/eip-2535 | ||
/******************************************************************************/ | ||
|
||
interface IDiamond { | ||
enum FacetCutAction {Add, Replace, Remove} | ||
// Add=0, Replace=1, Remove=2 | ||
|
||
struct FacetCut { | ||
address facetAddress; | ||
FacetCutAction action; | ||
bytes4[] functionSelectors; | ||
} | ||
|
||
event DiamondCut(FacetCut[] _diamondCut, address _init, bytes _calldata); | ||
} |
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,24 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
/******************************************************************************\ | ||
* Author: Nick Mudge <[email protected]> (https://twitter.com/mudgen) | ||
* EIP-2535 Diamonds: https://eips.ethereum.org/EIPS/eip-2535 | ||
/******************************************************************************/ | ||
|
||
import { IDiamond } from "./IDiamond.sol"; | ||
|
||
interface IDiamondCut is IDiamond { | ||
|
||
/// @notice Add/replace/remove any number of functions and optionally execute | ||
/// a function with delegatecall | ||
/// @param _diamondCut Contains the facet addresses and function selectors | ||
/// @param _init The address of the contract or facet to execute _calldata | ||
/// @param _calldata A function call, including function selector and arguments | ||
/// _calldata is executed with delegatecall on _init | ||
function diamondCut( | ||
FacetCut[] calldata _diamondCut, | ||
address _init, | ||
bytes calldata _calldata | ||
) external; | ||
} |
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 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
/******************************************************************************\ | ||
* Author: Nick Mudge <[email protected]> (https://twitter.com/mudgen) | ||
* EIP-2535 Diamonds: https://eips.ethereum.org/EIPS/eip-2535 | ||
/******************************************************************************/ | ||
|
||
// A loupe is a small magnifying glass used to look at diamonds. | ||
// These functions look at diamonds | ||
interface IDiamondLoupe { | ||
/// These functions are expected to be called frequently | ||
/// by tools. | ||
|
||
struct Facet { | ||
address facetAddress; | ||
bytes4[] functionSelectors; | ||
} | ||
|
||
/// @notice Gets all facet addresses and their four byte function selectors. | ||
/// @return facets_ Facet | ||
function facets() external view returns (Facet[] memory facets_); | ||
|
||
/// @notice Gets all the function selectors supported by a specific facet. | ||
/// @param _facet The facet address. | ||
/// @return facetFunctionSelectors_ | ||
function facetFunctionSelectors(address _facet) external view returns (bytes4[] memory facetFunctionSelectors_); | ||
|
||
/// @notice Get all the facet addresses used by a diamond. | ||
/// @return facetAddresses_ | ||
function facetAddresses() external view returns (address[] memory facetAddresses_); | ||
|
||
/// @notice Gets the facet that supports the given selector. | ||
/// @dev If facet is not found return address(0). | ||
/// @param _functionSelector The function selector. | ||
/// @return facetAddress_ The facet address. | ||
function facetAddress(bytes4 _functionSelector) external view returns (address facetAddress_); | ||
} |
Oops, something went wrong.