In general this may not be done, see siman יו׳׳ד קסב סע׳׳א that it is assur rabbinically since it might result in ribbis. You can however obligate yourself to return the lower amount in the future (if it goes down) see Taz, or the value as it is now see brit Yehudah perek 17.
אָסוּר לִלְוֹת סְאָה בִּסְאָה, אֲפִלּוּ לֹא קָצַב לוֹ זְמַן
לְפֵרָעוֹן. וְכֵן כָּל דָּבָר, חוּץ מִמַּטְבֵּעַ כֶּסֶף הַיּוֹצֵא
{אָז} בְּהוֹצָאָה, דְּשֶׁמָּא יִתְיַקְּרוּ, וְנִמְצָא שֶׁנּוֹתֵן לוֹ
יוֹתֵר מִמַּה שֶּׁהִלְוָהוּ, אִם לֹא שֶׁיַּעֲשֶׂנּוּ דָּמִים, שֶׁאִם
יִתְיַקְּרוּ יִתֵּן לוֹ אוֹתָם הַדָּמִים. וְאִם לֹא עֲשָׂהוּ דָּמִים,
וְנִתְיַקְּרוּ, נוֹתֵן לוֹ הַדָּמִים שֶׁהָיוּ שָׁוִים בִּשְׁעַת
הַלְוָאָה, וְאִם הוּזְלוּ נוֹתֵן לוֹ הַסְאָה שֶׁהִלְוָהוּ.
It is prohibited to lean a seah for a seah even if there is no set
time... maybe it will increase in price and you are paying back more
then what was lent to you...
There are technical exceptions, like if the object is readily available at time of loan and the borrower may return/pay the load immediately at any time. This is called heter yatza hashaar. See קסב סע׳׳ג
הָיָה לְאוֹתוֹ מִין שַׁעַר בַּשּׁוּק, קָבוּעַ וְיָדוּעַ לִשְׁנֵיהֶם,
מֻתָּר לִלְוֹת סְאָה בִּסְאָה. {הַגָּה: וְעַיֵּן לְקַמָּן סִימָן קע״ה
אֵיזֶה מִקְרֵי שַׁעַר קָבוּעַ. וְהָא דְּיָכוֹל לִלְוֹת עַל שַׁעַר
שֶׁבַּשּׁוּק, הַיְנוּ דְּהַלֹּוֶה יָכוֹל לִפְרֹעַ לוֹ אֵימַת
שֶׁיִּרְצֶה, אֲבָל אִם הִתְנָה שֶׁלֹּא יְקַבֵּל פֵּרָעוֹן עַד שְׁעַת
הַיֹּקֶר, אָסוּר (הָרא״ש בִּתְשׁוּבָתוֹ וּסְמַ״ק וְכָל בּוֹ).}
If it exists in the market place, and this is known to both you can
lend a seah for a seah. Rema: ... you must be able to pay at any time
you want but if you set a date for repayment when it is more valuable
it is prohibited
The logic is that (according to Rashi cited by BY) since he can buy it at any time, it is like he has it and so the value goes up in the possession of the lender instead. The Rema qualifies it there that the loan must be able to be repaid at any time; otherwise, it is not like it was in the possession of the lender when it went up in value.
There are other scenarios and technicalities though.