Created
July 26, 2025 05:28
-
-
Save nicolasochem/eed99ce4ca5f940a3ac3dacd37e9fb3b to your computer and use it in GitHub Desktop.
Sui Gas Price Updater K8s Cronjob
This file contains hidden or 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
apiVersion: batch/v1 | |
kind: CronJob | |
metadata: | |
name: sui-gas-price-updater | |
spec: | |
schedule: "{{ .Values.cronjob.schedule }}" | |
jobTemplate: | |
spec: | |
template: | |
spec: | |
containers: | |
- name: sui-gas-price-updater | |
image: "{{ .Values.cronjob.image }}" | |
command: ["/bin/sh", "-c"] | |
volumeMounts: | |
- name: keystore-volume | |
mountPath: "/root/.sui_keystore" | |
args: | |
- | | |
#!/bin/bash | |
# Generate client config | |
mkdir -p /root/.sui/sui_config | |
cat << 'EOT' > /root/.sui/sui_config/client.yaml | |
--- | |
keystore: | |
File: /root/.sui/sui_config/sui.keystore | |
envs: | |
- alias: "suinetwork" | |
rpc: "{{ .Values.cronjob.env.RPC }}" | |
active_address: "{{ .Values.cronjob.env.ACTIVE_ADDRESS }}" | |
active_env: "suinetwork" | |
EOT | |
cp /root/.sui_keystore/sui.keystore /root/.sui/sui_config | |
apt-get update && apt-get install -y ca-certificates bc curl jq && update-ca-certificates | |
# Calculate the daily incrementing number | |
start_date="2023-12-13" # Start date in YYYY-MM-DD format | |
initial_value=1741 | |
genesis_price=1.40 # SUI price at genesis in USD | |
today=$(date +%F) | |
days_passed=$(( ( $(date -d $today +%s) - $(date -d $start_date +%s) ) / 86400 )) | |
base_incremented_value=$(( initial_value + days_passed )) | |
# Get current SUI price from Binance API | |
echo "Fetching current SUI price..." | |
current_price=$(curl -s https://api.binance.com/api/v3/avgPrice?symbol=SUIUSDT | jq -r '.price') | |
if [ -z "$current_price" ]; then | |
echo "ERROR Failed to fetch SUI price" | |
exit 1 | |
else | |
# Calculate price ratio and adjust the gas price | |
price_ratio=$(echo "$genesis_price / $current_price" | bc -l) | |
final_value=$(echo "$base_incremented_value * $price_ratio" | bc -l | awk '{printf "%.0f", $0}') | |
echo "Current SUI price: $current_price USD (Genesis: $genesis_price USD)" | |
echo "Price ratio: $price_ratio" | |
echo "Base incremented value: $base_incremented_value" | |
fi | |
echo "*** NEW GAS PRICE VALUE FOR ${today}: ${final_value} ***" | |
# Main command with adjusted value | |
sui client call --package 0x3 --module sui_system --function request_set_gas_price --args 0x5 {{ .Values.cronjob.env.VALIDATOR_CAP_OBJECT_ID}} $final_value --gas-budget 10000000 | |
restartPolicy: OnFailure | |
volumes: | |
- name: keystore-volume | |
secret: | |
secretName: sui-keystore |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment