Skip to content

Commit

Permalink
test script
Browse files Browse the repository at this point in the history
  • Loading branch information
libevm committed Dec 11, 2021
1 parent af5b5f4 commit d2eba69
Show file tree
Hide file tree
Showing 5 changed files with 477 additions and 30 deletions.
27 changes: 0 additions & 27 deletions contracts/yulp/compile.js

This file was deleted.

4 changes: 3 additions & 1 deletion contracts/yulp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
"main": "index.js",
"license": "MIT",
"dependencies": {
"@ethersproject/address": "^5.5.0",
"ethers": "^5.5.2",
"solc": "0.8.10",
"yulp": "^0.2.3"
},
"scripts": {
"compile": "node compile.js"
"compile": "node scripts/compile.js"
}
}
36 changes: 36 additions & 0 deletions contracts/yulp/scripts/compile.js
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)
45 changes: 45 additions & 0 deletions contracts/yulp/scripts/test.js
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()
Loading

0 comments on commit d2eba69

Please sign in to comment.