-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Create hook to determine guild implementation * Create hook to determine guild implementation * refactor * Create script to copy bytecodes from artifacts, update hook to use those * format * refator & fix jsdoc * fix typo
- Loading branch information
1 parent
42c48c4
commit 17433ef
Showing
5 changed files
with
97 additions
and
0 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
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,39 @@ | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
|
||
function main() { | ||
const paths = { | ||
ERC20Guild: | ||
'../artifacts/dxdao-contracts/contracts/erc20guild/ERC20Guild.sol/ERC20Guild.json', | ||
SnapshotRepERC20Guild: | ||
'../artifacts/dxdao-contracts/contracts/erc20guild/implementations/SnapshotRepERC20Guild.sol/SnapshotRepERC20Guild.json', | ||
DXDGuild: | ||
'../artifacts/dxdao-contracts/contracts/erc20guild/implementations/DXDGuild.sol/DXDGuild.json', | ||
//TODO: add other contracts here (IERC20Guild) | ||
}; | ||
|
||
const data = Object.entries(paths).reduce((acc, [type, path]) => { | ||
try { | ||
const json = require(path); | ||
return [ | ||
...acc, | ||
{ | ||
type, | ||
bytecode: json.deployedBytecode, | ||
}, | ||
]; | ||
} catch (e) { | ||
console.error( | ||
`[updateDeployedBytecodes.js] File was not found: ${path}. Skipping ${type}` | ||
); | ||
return acc; | ||
} | ||
}, []); | ||
|
||
fs.writeFileSync( | ||
path.resolve(__dirname, '../src/bytecodes/config.json'), | ||
JSON.stringify(data, null, 2) | ||
); | ||
} | ||
|
||
main(); |
Large diffs are not rendered by default.
Oops, something went wrong.
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,36 @@ | ||
import { useMemo, useEffect, useState } from 'react'; | ||
import useJsonRpcProvider from '../web3/useJsonRpcProvider'; | ||
import { GuildImplementationType } from '../../../types/types.guilds.d'; | ||
import deployedBytecodes from '../../../bytecodes/config.json'; | ||
|
||
/** | ||
* @function useGuildImplementationType | ||
* @param {string} guildAddress | ||
* @returns {string} GuildImplementationType. 'SnapshotRepERC20Guild' | 'DXDGuild' | 'ERC20Guild' | 'IERC20Guild' | ||
*/ | ||
export default function useGuildImplementationType( | ||
guildAddress: string | ||
): GuildImplementationType { | ||
const [guildBytecode, setGuildBytecode] = useState<string>(''); | ||
const provider = useJsonRpcProvider(); | ||
|
||
useEffect(() => { | ||
const getBytecode = async () => { | ||
const bytecode = await provider.getCode(guildAddress); | ||
setGuildBytecode(bytecode); | ||
}; | ||
getBytecode(); | ||
}, [guildAddress, provider]); | ||
|
||
const implementationType: GuildImplementationType = useMemo(() => { | ||
if (!guildBytecode) return GuildImplementationType.IERC20Guild; | ||
|
||
const match = deployedBytecodes.find( | ||
({ bytecode }) => guildBytecode === bytecode | ||
); | ||
|
||
return match ? match.type : GuildImplementationType.IERC20Guild; // default to IERC20Guild | ||
}, [guildBytecode]) as GuildImplementationType; | ||
|
||
return implementationType; | ||
} |
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