forked from libevm/subway
-
Notifications
You must be signed in to change notification settings - Fork 0
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
libevm
committed
Dec 11, 2021
1 parent
af5b5f4
commit d2eba69
Showing
5 changed files
with
477 additions
and
30 deletions.
There are no files selected for viewing
This file was deleted.
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
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 @@ | ||
const yulp = require('yulp') | ||
const solc = require('solc') | ||
const fs = require('fs') | ||
const path = require('path') | ||
|
||
const CONTRACTS_DIR = path.join(__dirname, '..', 'src') | ||
const OUT_DIR = path.join(__dirname, '..', 'out') | ||
|
||
const sourceCode = fs.readFileSync(path.join(CONTRACTS_DIR, 'Sandwich.yulp'), { encoding: 'ascii' }) | ||
const source = yulp.compile(sourceCode) | ||
|
||
const output = JSON.parse(solc.compile(JSON.stringify({ | ||
"language": "Yul", | ||
"sources": { "Sandwich.yul": { "content": yulp.print(source.results) } }, | ||
"settings": { | ||
"outputSelection": { "*": { "*": ["*"], "": ["*"] } }, | ||
"optimizer": { | ||
"enabled": true, | ||
"runs": 0, | ||
"details": { | ||
"yul": true | ||
} | ||
} | ||
} | ||
}))) | ||
|
||
if (!fs.existsSync(OUT_DIR)) { | ||
fs.mkdirSync(OUT_DIR) | ||
} | ||
|
||
const abi = source.signatures.map(v => v.abi.slice(4, -1)).concat(source.topics.map(v => v.abi.slice(6, -1))) | ||
const bytecode = output.contracts["Sandwich.yul"]["Sandwich"]["evm"]["bytecode"]["object"] | ||
|
||
fs.writeFileSync(path.join(OUT_DIR, 'sandwich.out.json'), JSON.stringify(output)) | ||
fs.writeFileSync(path.join(OUT_DIR, 'sandwich.abi'), JSON.stringify(abi)) | ||
fs.writeFileSync(path.join(OUT_DIR, 'sandwich.bytecode'), bytecode) |
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,45 @@ | ||
const { parseUnits } = require('@ethersproject/units') | ||
const { getContractAddress } = require('@ethersproject/address') | ||
const { ethers } = require('ethers') | ||
const fs = require('fs') | ||
const path = require('path') | ||
|
||
const OUT_DIR = path.join(__dirname, '..', 'out') | ||
|
||
const abi = fs.readFileSync(path.join(OUT_DIR, 'sandwich.abi'), { encoding: 'ascii' }) | ||
const bytecode = fs.readFileSync(path.join(OUT_DIR, 'sandwich.bytecode'), { encoding: 'ascii' }) | ||
|
||
const provider = new ethers.providers.JsonRpcProvider() | ||
|
||
const main = async () => { | ||
const signer = await provider.getSigner(0) | ||
const signerAddress = await signer.getAddress() | ||
const nonce = await provider.getTransactionCount(signerAddress) | ||
|
||
const contractAddress = getContractAddress({ | ||
from: signerAddress, | ||
nonce | ||
}) | ||
|
||
const contractArgs = ethers.utils.defaultAbiCoder.encode(['address'], [signerAddress]) | ||
const tx = await signer.sendTransaction({ | ||
data: '0x' + bytecode + contractArgs.replace('0x', ''), | ||
type: 0, | ||
gasLimit: 5000000, | ||
gasPrice: parseUnits('100', 9), | ||
nonce | ||
}) | ||
await tx.wait() | ||
|
||
const data = await provider.call({ | ||
to: contractAddress, | ||
data: '0x' | ||
}) | ||
|
||
const code = await provider.getCode(contractAddress) | ||
|
||
console.log('data', data) | ||
console.log('code', code) | ||
} | ||
|
||
main() |
Oops, something went wrong.