Skip to content

Commit

Permalink
feat: generate contract types from packages (#1201)
Browse files Browse the repository at this point in the history
  • Loading branch information
therealemjy authored Jul 25, 2023
1 parent 478e063 commit ba6b8e9
Show file tree
Hide file tree
Showing 17 changed files with 766 additions and 13 deletions.
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ src/assets/font
src/types/contracts
src/clients/subgraph/gql/mainnet.ts
src/clients/subgraph/gql/testnet.ts
src/packages/contracts/types/contracts
src/storybook-static
11 changes: 8 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@
"generate-subgraph-types:testnet": "yarn graphql-codegen --config ./src/config/codegen.ts --project testnet",
"generate-subgraph-types": "npm-run-all --parallel generate-subgraph-types:mainnet generate-subgraph-types:testnet",
"generate-contract-types": "rimraf src/types/contracts && typechain --target=ethers-v5 --out-dir=src/types/contracts 'src/constants/contracts/abis/*.json'",
"generate-contract-types:contract-package": "rimraf ./src/types/contracts && typechain --target=ethers-v5 --out-dir=./src/packages/contracts/types/contracts/isolatedPools './node_modules/@venusprotocol/isolated-pools/artifacts/contracts/!(Factories)/**/*[!.dbg].json' && typechain --target=ethers-v5 --out-dir=./src/packages/contracts/types/contracts/oracle './node_modules/@venusprotocol/oracle/artifacts/contracts/!(Factories)/**/*[!.dbg].json' && typechain --target=ethers-v5 --out-dir=./src/packages/contracts/types/contracts/venusProtocol './node_modules/@venusprotocol/venus-protocol/artifacts/contracts/!(Factories)/**/*[!.dbg].json' && typechain --target=ethers-v5 --out-dir=./src/packages/contracts/types/contracts/xvsVesting './node_modules/@venusprotocol/venus-protocol/artifacts/contracts/Tokens/XVS/XVSVesting.sol/XVSVesting.json' && typechain --target=ethers-v5 --out-dir=./src/packages/contracts/types/contracts/others './src/packages/contracts/contractInfos/externalAbis/*.json'",
"generate-pancake-swap-tokens": "node ./scripts/generatePancakeSwapTokens.mjs && yarn prettier --write ./src/constants/tokens/swap/mainnetPancakeSwapTokens.ts",
"generate-version-file": "genversion --es6 --semi src/constants/version.ts",
"husky:install": "husky install",
"postinstall": "npm-run-all --parallel husky:install generate-contract-types generate-subgraph-types generate-pancake-swap-tokens generate-version-file",
"postinstall": "npm-run-all --parallel husky:install generate-contract-types generate-contract-types:contract-package generate-subgraph-types generate-version-file && yarn generate-pancake-swap-tokens",
"storybook": "storybook dev -p 6006",
"build-storybook": "storybook build",
"regression": "reg-suit run"
Expand All @@ -47,8 +48,10 @@
"@sentry/tracing": "^7.43.0",
"@uiw/react-markdown-preview": "^4.1.13",
"@uiw/react-md-editor": "^3.14.3",
"@venusprotocol/governance-contracts": "^1.0.0",
"@venusprotocol/isolated-pools": "^1.1.0",
"@venusprotocol/oracle": "^1.7.0",
"@venusprotocol/venus-protocol": "^3.0.0-dev.13",
"bignumber.js": "^9.0.0",
"copy-to-clipboard": "^3.3.1",
"date-fns": "^2.28.0",
Expand Down Expand Up @@ -80,6 +83,8 @@
},
"devDependencies": {
"@commitlint/config-conventional": "^17.6.6",
"@ethersproject/abi": "^5.7.0",
"@ethersproject/abstract-provider": "^5.7.0",
"@graphql-codegen/add": "^5.0.0",
"@graphql-codegen/cli": "^4.0.1",
"@graphql-codegen/client-preset": "^4.0.1",
Expand All @@ -103,7 +108,7 @@
"@testing-library/react": "^12.1.4",
"@testing-library/react-hooks": "^8.0.1",
"@trivago/prettier-plugin-sort-imports": "^3.2.0",
"@typechain/ethers-v5": "^10.2.0",
"@typechain/ethers-v5": "^11.1.0",
"@types/lodash": "^4.14.178",
"@types/react": "^17.0.01",
"@types/react-dom": "^17.0.11",
Expand Down Expand Up @@ -156,7 +161,7 @@
"stylelint-config-prettier": "^9.0.3",
"stylelint-config-standard": "^18.3.0",
"stylelint-scss": "^3.9.2",
"typechain": "^8.1.1",
"typechain": "^8.3.0",
"typescript": "^4.5.5",
"validate-branch-name": "^1.3.0",
"vite": "^4.3.9",
Expand Down
2 changes: 1 addition & 1 deletion src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const isLocalServer = import.meta.env.DEV && environment !== 'ci' && environment
const isOnTestnet =
environment === 'testnet' || environment === 'storybook' || environment === 'ci';

const chainId: BscChainId = isOnTestnet ? 97 : 56;
const chainId: BscChainId = isOnTestnet ? BscChainId.TESTNET : BscChainId.MAINNET;

const localRpcUrl =
environment === 'mainnet' || environment === 'preview'
Expand Down
2 changes: 2 additions & 0 deletions src/packages/contracts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Contract types, automatically generated by TypeChain (https://github.com/dethcrypto/TypeChain)
/types/contracts/
38 changes: 38 additions & 0 deletions src/packages/contracts/contractInfos/externalAbis/maximillion.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[
{
"inputs": [{ "internalType": "contract VBNB", "name": "vBnb_", "type": "address" }],
"payable": false,
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"constant": false,
"inputs": [{ "internalType": "address", "name": "borrower", "type": "address" }],
"name": "repayBehalf",
"outputs": [],
"payable": true,
"stateMutability": "payable",
"type": "function"
},
{
"constant": false,
"inputs": [
{ "internalType": "address", "name": "borrower", "type": "address" },
{ "internalType": "contract VBNB", "name": "vBnb_", "type": "address" }
],
"name": "repayBehalfExplicit",
"outputs": [],
"payable": true,
"stateMutability": "payable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "vBnb",
"outputs": [{ "internalType": "contract VBNB", "name": "", "type": "address" }],
"payable": false,
"stateMutability": "view",
"type": "function"
}
]
236 changes: 236 additions & 0 deletions src/packages/contracts/contractInfos/externalAbis/multicall.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,236 @@
[
{
"inputs": [
{
"components": [
{ "internalType": "address", "name": "target", "type": "address" },
{ "internalType": "bytes", "name": "callData", "type": "bytes" }
],
"internalType": "struct Multicall3.Call[]",
"name": "calls",
"type": "tuple[]"
}
],
"name": "aggregate",
"outputs": [
{ "internalType": "uint256", "name": "blockNumber", "type": "uint256" },
{ "internalType": "bytes[]", "name": "returnData", "type": "bytes[]" }
],
"stateMutability": "payable",
"type": "function"
},
{
"inputs": [
{
"components": [
{ "internalType": "address", "name": "target", "type": "address" },
{ "internalType": "bool", "name": "allowFailure", "type": "bool" },
{ "internalType": "bytes", "name": "callData", "type": "bytes" }
],
"internalType": "struct Multicall3.Call3[]",
"name": "calls",
"type": "tuple[]"
}
],
"name": "aggregate3",
"outputs": [
{
"components": [
{ "internalType": "bool", "name": "success", "type": "bool" },
{ "internalType": "bytes", "name": "returnData", "type": "bytes" }
],
"internalType": "struct Multicall3.Result[]",
"name": "returnData",
"type": "tuple[]"
}
],
"stateMutability": "payable",
"type": "function"
},
{
"inputs": [
{
"components": [
{ "internalType": "address", "name": "target", "type": "address" },
{ "internalType": "bool", "name": "allowFailure", "type": "bool" },
{ "internalType": "uint256", "name": "value", "type": "uint256" },
{ "internalType": "bytes", "name": "callData", "type": "bytes" }
],
"internalType": "struct Multicall3.Call3Value[]",
"name": "calls",
"type": "tuple[]"
}
],
"name": "aggregate3Value",
"outputs": [
{
"components": [
{ "internalType": "bool", "name": "success", "type": "bool" },
{ "internalType": "bytes", "name": "returnData", "type": "bytes" }
],
"internalType": "struct Multicall3.Result[]",
"name": "returnData",
"type": "tuple[]"
}
],
"stateMutability": "payable",
"type": "function"
},
{
"inputs": [
{
"components": [
{ "internalType": "address", "name": "target", "type": "address" },
{ "internalType": "bytes", "name": "callData", "type": "bytes" }
],
"internalType": "struct Multicall3.Call[]",
"name": "calls",
"type": "tuple[]"
}
],
"name": "blockAndAggregate",
"outputs": [
{ "internalType": "uint256", "name": "blockNumber", "type": "uint256" },
{ "internalType": "bytes32", "name": "blockHash", "type": "bytes32" },
{
"components": [
{ "internalType": "bool", "name": "success", "type": "bool" },
{ "internalType": "bytes", "name": "returnData", "type": "bytes" }
],
"internalType": "struct Multicall3.Result[]",
"name": "returnData",
"type": "tuple[]"
}
],
"stateMutability": "payable",
"type": "function"
},
{
"inputs": [],
"name": "getBasefee",
"outputs": [{ "internalType": "uint256", "name": "basefee", "type": "uint256" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [{ "internalType": "uint256", "name": "blockNumber", "type": "uint256" }],
"name": "getBlockHash",
"outputs": [{ "internalType": "bytes32", "name": "blockHash", "type": "bytes32" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "getBlockNumber",
"outputs": [{ "internalType": "uint256", "name": "blockNumber", "type": "uint256" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "getChainId",
"outputs": [{ "internalType": "uint256", "name": "chainid", "type": "uint256" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "getCurrentBlockCoinbase",
"outputs": [{ "internalType": "address", "name": "coinbase", "type": "address" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "getCurrentBlockDifficulty",
"outputs": [{ "internalType": "uint256", "name": "difficulty", "type": "uint256" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "getCurrentBlockGasLimit",
"outputs": [{ "internalType": "uint256", "name": "gaslimit", "type": "uint256" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "getCurrentBlockTimestamp",
"outputs": [{ "internalType": "uint256", "name": "timestamp", "type": "uint256" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [{ "internalType": "address", "name": "addr", "type": "address" }],
"name": "getEthBalance",
"outputs": [{ "internalType": "uint256", "name": "balance", "type": "uint256" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "getLastBlockHash",
"outputs": [{ "internalType": "bytes32", "name": "blockHash", "type": "bytes32" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{ "internalType": "bool", "name": "requireSuccess", "type": "bool" },
{
"components": [
{ "internalType": "address", "name": "target", "type": "address" },
{ "internalType": "bytes", "name": "callData", "type": "bytes" }
],
"internalType": "struct Multicall3.Call[]",
"name": "calls",
"type": "tuple[]"
}
],
"name": "tryAggregate",
"outputs": [
{
"components": [
{ "internalType": "bool", "name": "success", "type": "bool" },
{ "internalType": "bytes", "name": "returnData", "type": "bytes" }
],
"internalType": "struct Multicall3.Result[]",
"name": "returnData",
"type": "tuple[]"
}
],
"stateMutability": "payable",
"type": "function"
},
{
"inputs": [
{ "internalType": "bool", "name": "requireSuccess", "type": "bool" },
{
"components": [
{ "internalType": "address", "name": "target", "type": "address" },
{ "internalType": "bytes", "name": "callData", "type": "bytes" }
],
"internalType": "struct Multicall3.Call[]",
"name": "calls",
"type": "tuple[]"
}
],
"name": "tryBlockAndAggregate",
"outputs": [
{ "internalType": "uint256", "name": "blockNumber", "type": "uint256" },
{ "internalType": "bytes32", "name": "blockHash", "type": "bytes32" },
{
"components": [
{ "internalType": "bool", "name": "success", "type": "bool" },
{ "internalType": "bytes", "name": "returnData", "type": "bytes" }
],
"internalType": "struct Multicall3.Result[]",
"name": "returnData",
"type": "tuple[]"
}
],
"stateMutability": "payable",
"type": "function"
}
]
Loading

0 comments on commit ba6b8e9

Please sign in to comment.