Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(bid-script): keep leading zero & use the fractional pricing #212

Merged
merged 4 commits into from
Aug 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions charts/akash-provider/scripts/price_script_generic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# WARNING: the runtime of this script should NOT exceed 5 seconds! (Perhaps can be amended via AKASH_BID_PRICE_SCRIPT_PROCESS_TIMEOUT env variable)
# Requirements:
# curl jq bc mawk ca-certificates
# Version: Aug-08-2023
# Version: Aug-14-2023
set -o pipefail

# Example:
Expand Down Expand Up @@ -145,7 +145,7 @@ total_cost_akt_target=$(bc -l <<<"(${total_cost_usd_target}/$usd_per_akt)")
total_cost_uakt_target=$(bc -l <<<"(${total_cost_akt_target}*1000000)")
rate_per_block_uakt=$(bc -l <<<"(${total_cost_uakt_target}/${blocks_a_month})")
rate_per_block_usd=$(bc -l <<<"(${total_cost_usd_target}/${blocks_a_month})")
total_cost_uakt=$(echo "$rate_per_block_uakt" | jq 'def ceil: if . | floor == . then . else . + 1.0 | floor end; .|ceil')
total_cost_uakt="$(printf "%.18f" $rate_per_block_uakt)"

# NOTE: max_rate_usd, max_rate_uakt = are per block rates !

Expand All @@ -158,7 +158,7 @@ if [[ $isDenom = true ]]; then
max_rate_uakt=$(echo '{"price":"'$price'"}' | jq -r '.price | gsub("[^0-9.]"; "")')
# Hint: bc <<< "$a > $b" (if a is greater than b, it will return 1, otherwise 0)
if bc <<< "$rate_per_block_uakt > $max_rate_uakt" | grep -qw 1; then
printf "requested rate is too low. min expected %.8f%s" "$rate_per_block_uakt" "$denom" >&2
printf "requested rate is too low. min expected %.18f%s" "$rate_per_block_uakt" "$denom" >&2
exit 1
fi

Expand All @@ -169,9 +169,9 @@ if [[ $isDenom = true ]]; then
# sandbox: Axelar USDC
*"ibc/12C6A0C374171B595A0A9E18B83FA09D295FB1F2D8C6DAA3AC28683471752D84")
max_rate_usd=$(echo '{"price":"'$price'"}' | jq -r '.price | gsub("[^0-9.]"; "")')
rate_per_block_usd_normalized=$(bc -l <<<"scale=18; (${rate_per_block_usd}*1000000)/1")
rate_per_block_usd_normalized=$(bc -l <<<"scale=18; (${rate_per_block_usd}*1000000)/1" | awk '{printf "%.18f", $0}')
if bc <<< "$rate_per_block_usd_normalized > $max_rate_usd" | grep -qw 1; then
printf "requested rate is too low. min expected %.8f%s" "$rate_per_block_usd_normalized" "$denom" >&2
printf "requested rate is too low. min expected %.18f%s" "$rate_per_block_usd_normalized" "$denom" >&2
exit 1
fi

Expand Down
Loading