From f0260fe3926db57e3bfdaf79c6b2b5edc6c5b0f8 Mon Sep 17 00:00:00 2001 From: jar-o Date: Fri, 28 Oct 2022 12:33:27 -0600 Subject: [PATCH] Mosm hack per sc-989, staging on Goerli --- lib/ethereum.sh | 80 +++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 65 insertions(+), 15 deletions(-) diff --git a/lib/ethereum.sh b/lib/ethereum.sh index 291a89d..f8b7b09 100644 --- a/lib/ethereum.sh +++ b/lib/ethereum.sh @@ -39,10 +39,63 @@ pullOraclePrice () { ethereum --from-wei "$(ethereum --to-dec "${_rawStorage:34:32}")" } +jameshackMosmHash () { # NOTE this one creates uint32 for zzz + local wat wad zzz + + wat=$(seth --to-bytes32 "$(seth --from-ascii "$1")") + wad=$2 # already in bytes32 format + zzz=$(echo "$3" | sed 's/0\{56\}//g') # truncate to uint32 + hexcat=$(echo "$wad$zzz$wat" | sed 's/0x//g') + log "jameshack wat $wat" + log "jameshack wad $wad" + log "jameshack zzz $zzz" + seth keccak 0x"$hexcat" +} + +jameshackMosm () { + log "jameshackMosm($1 $2 $3)" + log "jameshack price ${allPrices[0]}" + log "jameshack time ${allTimes[0]}" + log "jameshack v ${allV[0]}" + log "jameshack r ${allR[0]}" + log "jameshack s ${allS[0]}" + hash=$(jameshackMosmHash ETHUSD "${allPrices[0]}" "${allTimes[0]}") + log "jameshackMosmHash: $hash" + + sig=$(ethsign msg --from "$ETH_FROM" --data "$hash" --passphrase-file "$ETH_PASSWORD") + res=$(sed 's/^0x//' <<< "$sig") + r=${res:0:64} + s=${res:64:64} + v=${res:128:2} + v=$(seth --to-word "0x$v") + + log "jameshack ETH_FROM=$ETH_FROM (make sure to lift())" + log "jameshack new v $v" + log "jameshack new r $r" + log "jameshack new s $s" + + + zzz=$(echo "${allTimes[0]}" | sed 's/0\{56\}//g') # truncate to uint32 + log "jameshack zzz $zzz" + + tx=$(ethereum --rpc-url "$ETH_RPC_URL" --gas-price "$2" --prio-fee "$3" send --async "$1" 'poke(uint256[] memory,uint32[] memory,uint8[] memory,bytes32[] memory,bytes32[] memory)' \ + "[${allPrices[0]}]" \ + "[$zzz]" \ + "[$v]" \ + "[0x$r]" \ + "[0x$s]") + + _status="$(timeout -s9 60 ethereum --rpc-url "$ETH_RPC_URL" receipt "$tx" status)" + _gasUsed="$(timeout -s9 60 ethereum --rpc-url "$ETH_RPC_URL" receipt "$tx" gasUsed)" + + # Monitoring node helper JSON + verbose "Transaction receipt" "tx=$tx" "maxGasPrice=${_fees[0]}" "prioFee=${_fees[1]}" "gasUsed=$_gasUsed" "status=$_status" +} + pushOraclePrice () { local _assetPair="$1" local _oracleContract - + # Using custom gas pricing strategy local _fees _fees=($(getGasPrice)) @@ -52,24 +105,21 @@ pushOraclePrice () { error "Error - Invalid Oracle contract" return 1 fi - - local _gasParams - _gasParams=(--rpc-url "$ETH_RPC_URL" --gas-price "${_fees[0]}") - [[ $ETH_TX_TYPE -eq 2 ]] && _gasParams+=(--prio-fee "${_fees[1]}") - _gasParams+=(--gas "$ETH_GAS") - log "Sending tx..." - tx=$(ethereum "${_gasParams[@]}" \ - send --async "$_oracleContract" 'poke(uint256[] memory,uint256[] memory,uint8[] memory,bytes32[] memory,bytes32[] memory)' \ + if [ "$_oracleContract" = "0x50B19f34595bfF59977e3058AC0ff7f729Fdc67a" ]; then + jameshackMosm "$_oracleContract" "${_fees[0]}" "${_fees[1]}" + else + tx=$(ethereum --rpc-url "$ETH_RPC_URL" --gas-price "${_fees[0]}" --prio-fee "${_fees[1]}" send --async "$_oracleContract" 'poke(uint256[] memory,uint256[] memory,uint8[] memory,bytes32[] memory,bytes32[] memory)' \ "[$(join "${allPrices[@]}")]" \ "[$(join "${allTimes[@]}")]" \ "[$(join "${allV[@]}")]" \ "[$(join "${allR[@]}")]" \ "[$(join "${allS[@]}")]") - - _status="$(timeout -s9 60 ethereum --rpc-url "$ETH_RPC_URL" receipt "$tx" status)" - _gasUsed="$(timeout -s9 60 ethereum --rpc-url "$ETH_RPC_URL" receipt "$tx" gasUsed)" - - # Monitoring node helper JSON - verbose "Transaction receipt" "tx=$tx" "type=$ETH_TX_TYPE" "maxGasPrice=${_fees[0]}" "prioFee=${_fees[1]}" "gasUsed=$_gasUsed" "status=$_status" + + _status="$(timeout -s9 60 ethereum --rpc-url "$ETH_RPC_URL" receipt "$tx" status)" + _gasUsed="$(timeout -s9 60 ethereum --rpc-url "$ETH_RPC_URL" receipt "$tx" gasUsed)" + + # Monitoring node helper JSON + verbose "Transaction receipt" "tx=$tx" "maxGasPrice=${_fees[0]}" "prioFee=${_fees[1]}" "gasUsed=$_gasUsed" "status=$_status" + fi }