-
Notifications
You must be signed in to change notification settings - Fork 58
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
1 parent
ee22d72
commit 5612a90
Showing
32 changed files
with
8,539 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# OS cache files | ||
.DS_Store | ||
|
||
# Dependencies | ||
node_modules/ | ||
|
||
# Build directories | ||
dist/ | ||
tmp/ | ||
.next/ | ||
.nuxt/ | ||
|
||
# To maintain directory structure | ||
!.keep | ||
|
||
packages/document-parser/credentials/access_token.json | ||
|
||
# Error files | ||
yarn-error.log | ||
|
||
/artifacts/ | ||
/src/abi/ | ||
/src/bytecode/ | ||
/src/contract/ | ||
.npmrc |
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,2 @@ | ||
node_modules | ||
.npmrc |
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 @@ | ||
node_modules |
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,11 @@ | ||
{ | ||
"extends": "solium:all", | ||
"plugins": ["security"], | ||
"rules": { | ||
"arg-overflow": ["error", 4], | ||
"error-reason": ["off"], | ||
"indentation": ["error", 2], | ||
"no-experimental": ["off"], | ||
"quotes": ["error", "double"] | ||
} | ||
} |
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,43 @@ | ||
#!/usr/bin/env node | ||
|
||
const fs = require('fs'); | ||
const mkdirp = require('mkdirp'); | ||
const path = require('path'); | ||
|
||
const JSON_EXT_REGEX = /\.json$/; | ||
|
||
const artifactsDir = path.join(__dirname, '../artifacts'); | ||
const abisDir = path.join(__dirname, '../src/abi'); | ||
|
||
mkdirp.sync(abisDir); | ||
|
||
fs | ||
.readdirSync(artifactsDir) | ||
.forEach(filename => { | ||
if (!filename.match(JSON_EXT_REGEX)) { | ||
return; | ||
} | ||
|
||
const contractName = filename.replace(JSON_EXT_REGEX, ''); | ||
|
||
const artifactPath = path.join(artifactsDir, filename); | ||
const abiPath = path.join(abisDir, `${contractName}.abi.ts`); | ||
|
||
const artifactModifiedTime = fs.statSync(artifactPath).mtimeMs; | ||
const abiModifiedTime = fs.existsSync(abiPath) ? fs.statSync(abiPath).mtimeMs : 0; | ||
|
||
if (artifactModifiedTime <= abiModifiedTime) { | ||
return; | ||
} | ||
|
||
const artifact = require(artifactPath); | ||
const { abi } = artifact.compilerOutput; | ||
|
||
fs.writeFileSync( | ||
abiPath, | ||
`import { AbiItem } from 'web3-utils';\n\nexport default ${JSON.stringify(abi, null, 2)} as unknown as AbiItem[];\n`, | ||
'utf8', | ||
); | ||
|
||
console.log(`Extracted ABIs: ${contractName}.`) | ||
}); |
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,72 @@ | ||
#!/usr/bin/env node | ||
|
||
const fs = require('fs'); | ||
const mkdirp = require('mkdirp'); | ||
const path = require('path'); | ||
|
||
const JSON_EXT_REGEX = /\.json$/; | ||
|
||
const artifactsDir = path.join(__dirname, '../artifacts'); | ||
const bytecodesDir = path.join(__dirname, '../src/bytecode'); | ||
|
||
mkdirp.sync(bytecodesDir); | ||
|
||
fs | ||
.readdirSync(artifactsDir) | ||
.forEach(filename => { | ||
if (!filename.match(JSON_EXT_REGEX)) { | ||
return; | ||
} | ||
|
||
const contractName = filename.replace(JSON_EXT_REGEX, ''); | ||
|
||
const artifactPath = path.join(artifactsDir, filename); | ||
const bytecodePath = path.join(bytecodesDir, `${contractName}.bytecode.ts`); | ||
|
||
const artifactModifiedTime = fs.statSync(artifactPath).mtimeMs; | ||
const bytecodeModifiedTime = fs.existsSync(bytecodePath) ? fs.statSync(bytecodePath).mtimeMs : 0; | ||
|
||
if (artifactModifiedTime <= bytecodeModifiedTime) { | ||
return; | ||
} | ||
|
||
const artifact = require(artifactPath); | ||
const data = artifact.compilerOutput.evm.bytecode; | ||
let bytecode = data.object; | ||
|
||
if (bytecode === '0x') { | ||
return; | ||
} | ||
|
||
const replaceLibraryReference = (bytecode, reference, libraryName) => { | ||
if (libraryName.length > 36) { | ||
// Just an unreasonable reason to reduce engineering cost. | ||
throw new Error(`Library name "${libraryName}" too long.`); | ||
} | ||
|
||
const { start } = reference; | ||
let linkId = `__${libraryName}`; | ||
|
||
while (linkId.length < 40) { | ||
linkId += '_'; | ||
} | ||
|
||
return `${bytecode.slice(0, start * 2 + 2)}${linkId}${bytecode.slice(start * 2 + 42)}`; | ||
}; | ||
|
||
Object.keys(data.linkReferences).forEach(fileName => { | ||
Object.keys(data.linkReferences[fileName]).forEach(libraryName => { | ||
data.linkReferences[fileName][libraryName].forEach(reference => { | ||
bytecode = replaceLibraryReference(bytecode, reference, libraryName); | ||
}); | ||
}); | ||
}); | ||
|
||
fs.writeFileSync( | ||
bytecodePath, | ||
`export default '${bytecode}';\n`, | ||
'utf8', | ||
); | ||
|
||
console.log(`Extracted bytecode: ${contractName}.`) | ||
}); |
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,22 @@ | ||
{ | ||
"artifactsDir": "./artifacts", | ||
"compilerSettings": { | ||
"optimizer": { | ||
"enabled": true, | ||
"runs": 200 | ||
}, | ||
"outputSelection": { | ||
"*": { | ||
"*": [ | ||
"abi", | ||
"evm.bytecode.object", | ||
"evm.bytecode.sourceMap", | ||
"evm.deployedBytecode.object", | ||
"evm.deployedBytecode.sourceMap" | ||
] | ||
} | ||
} | ||
}, | ||
"contracts": "*", | ||
"contractsDir": "./contracts" | ||
} |
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,49 @@ | ||
import { | ||
BaseContract, | ||
ContractCall, | ||
ContractDeployment, | ||
ContractTransaction, | ||
} from '@axie/base-contract'; | ||
import { Web3Pool } from '@axie/web3-pool'; | ||
import BigNumber = require('bn.js'); | ||
import { TransactionConfig } from 'web3-core'; | ||
|
||
import abis from '../abi/{{contractName}}.abi'; | ||
|
||
export class {{contractName}}Contract extends BaseContract { | ||
static deploy( | ||
{{> typed_params inputs=ctor.inputs}} | ||
): ContractDeployment<{{contractName}}Contract> { | ||
const { default: bytecode } = eval('require')('../bytecode/{{contractName}}.bytecode'); | ||
|
||
return {{contractName}}Contract.deployFromBytecode( | ||
bytecode, | ||
{{> params inputs=ctor.inputs}} | ||
); | ||
} | ||
|
||
static deployFromBytecode( | ||
bytecode: string, | ||
{{> typed_params inputs=ctor.inputs}} | ||
): ContractDeployment<{{contractName}}Contract> { | ||
return BaseContract.constructDeployment( | ||
bytecode, | ||
[{{> params inputs=ctor.inputs}}], | ||
abis, | ||
(address, web3Pool) => new {{contractName}}Contract(address, web3Pool), | ||
); | ||
} | ||
|
||
constructor(address: string, web3Pool: Web3Pool, txDefaults?: TransactionConfig) { | ||
super('{{contractName}}', abis as any, address, web3Pool, txDefaults); | ||
} | ||
|
||
{{#each methods}} | ||
{{#this.constant}} | ||
{{> call contractName=../contractName}} | ||
{{/this.constant}} | ||
{{^this.constant}} | ||
{{> tx contractName=../contractName}} | ||
{{/this.constant}} | ||
{{/each}} | ||
} |
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,11 @@ | ||
{{this.tsName}}( | ||
this: {{contractName}}Contract, | ||
{{> typed_params inputs=inputs}} | ||
): ContractCall<{{> return_type outputs=outputs}}> { | ||
return BaseContract.constructCall( | ||
'{{this.functionSignature}}', | ||
[{{> params inputs=inputs}}], | ||
{{singleReturnValue}}, | ||
this, | ||
); | ||
} |
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,3 @@ | ||
{{#each inputs}} | ||
{{name}}{{#if @last}}{{else}},{{/if}} | ||
{{/each}} |
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,10 @@ | ||
{{#if outputs.length}} | ||
{{#singleReturnValue}} | ||
{{#returnType outputs.0.type outputs.0.components}}{{/returnType}} | ||
{{/singleReturnValue}} | ||
{{^singleReturnValue}} | ||
[{{#each outputs}}{{#returnType type components}}{{/returnType}}{{#unless @last}}, {{/unless}}{{/each}}] | ||
{{/singleReturnValue}} | ||
{{else}} | ||
void | ||
{{/if}} |
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,10 @@ | ||
{{this.tsName}}( | ||
this: {{contractName}}Contract, | ||
{{> typed_params inputs=inputs}} | ||
): ContractTransaction { | ||
return BaseContract.constructTransaction( | ||
'{{this.functionSignature}}', | ||
[{{> params inputs=inputs}}], | ||
this, | ||
); | ||
} |
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,3 @@ | ||
{{#each inputs}} | ||
{{name}}: {{#parameterType type components}}{{/parameterType}}, | ||
{{/each}} |
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,9 @@ | ||
pragma solidity ^0.5.2; | ||
|
||
contract IValidator { | ||
event ValidatorAdded(address indexed validator); | ||
event ValidatorRemoved(address indexed validator); | ||
|
||
function isValidator(address _addr) public view returns (bool _result); | ||
function getValidators() public view returns (address[] memory _validators); | ||
} |
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,11 @@ | ||
pragma solidity ^0.5.2; | ||
|
||
import "@axie/contract-library/contracts/token/erc20/IERC20.sol"; | ||
|
||
contract IWETH is IERC20 { | ||
event Deposit(address indexed dst, uint256 wad); | ||
event Withdrawal(address indexed src, uint256 wad); | ||
|
||
function deposit() external payable; | ||
function withdraw(uint256 wad) external; | ||
} |
Oops, something went wrong.