FROM scratch AS base
COPY --from=stagex/core-bash . /
COPY --from=stagex/user-jq . /
COPY --from=stagex/core-busybox . /
COPY --from=stagex/core-ca-certificates . /
COPY --from=stagex/core-curl . /
COPY --from=stagex/core-gcc . /
COPY --from=stagex/core-git . /
COPY --from=stagex/core-musl . /
COPY --from=stagex/core-openssl . /
COPY --from=stagex/core-zlib . /
COPY --from=stagex/core-solidity:0.8.30 . /


#RUN git clone https://github.com/mitche50/keeta-locker.git 
#WORKDIR ./keeta-locker
#RUN git checkout 8fb2b54b167dc7d8a91151eae06ec265afa48b06

COPY keeta-locker ./

RUN /usr/bin/solc --via-ir --optimize --combined-json abi,bin ./blockchain/src/LPLocker.sol > storage.js

RUN curl -L https://github.com/foundry-rs/foundry/releases/download/v1.2.2/foundry_v1.2.2_alpine_amd64.tar.gz > foundry_v1.2.2_linux_amd64.tar.gz

RUN tar -xvf foundry_v1.2.2_linux_amd64.tar.gz
RUN chmod +x forge
RUN ./forge build --contracts blockchain/src/LPLocker.sol --force --use /usr/bin/solc

RUN jq '.contracts["blockchain/src/LPLocker.sol:LPLocker"].abi' storage.js > abi_from_solc.json
RUN jq -r '.contracts["blockchain/src/LPLocker.sol:LPLocker"].bin' storage.js > init_from_solc.hex
RUN jq '.abi' ./out/LPLocker.sol/LPLocker.json > abi_from_forge.json
RUN jq -r '.bytecode.object' out/LPLocker.sol/LPLocker.json > init_from_forge.hex
#RUN diff abi_from_solc.json abi_from_forge.json
#RUN diff init_from_solc.hex init_from_forge.hex
#RUN diff ./out/LPLocker.sol/LPLocker.json storage.js
RUN cat init_from_solc.hex

RUN cat init_from_forge.hex

RUN /usr/bin/solc \
         --bin \
         --abi \
				 --asm \
         --allow-paths . \
				 --optimize --optimize-runs=200 \
         -o build \
         ./blockchain/src/LPLocker.sol \
         ./blockchain/src/openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol \
         ./blockchain/src/openzeppelin-contracts/contracts/access/Ownable2Step.sol \
         ./blockchain/src/openzeppelin-contracts/contracts/access/Ownable2Step.sol \
         ./blockchain/src/interfaces/IAerodromePool.sol \
         ./blockchain/src/interfaces/ILPLocker.sol

#RUN /usr/bin/solc --asm --bin-runtime ./blockchain/src/LPLocker.sol -o build/
#RUN /usr/bin/solc --asm --bin-runtime --opcodes ./blockchain/src/LPLocker.sol -o build/

#RUN diff ./pre-built.abi build/LPLocker.abi
#RUN diff ./pre-built.bin build/LPLocker.bin
#RUN diff ./pre-built.bin-runtime build/LPLocker.bin-runtime

#RUN tr -s '[:space:]' '\n' < build/LPLocker.opcode 
#RUN diff -wb ./pre-built.opcode build/LPLocker.opcode
