Skip to content

Conversation

@IaroslavMazur
Copy link
Member

@IaroslavMazur IaroslavMazur commented Apr 30, 2025

Closes #47. Depends on #174.

  • feat(lk+mi): Oracle-based fee charging
  • test(lk+mi): Oracle-based fee charging
  • test: Added Bankrun Programs & Accounts
  • test: Fetch account data from Devnet
  • refactor(lk+mi): constants
  • chore: remove the unused dependencies

Base automatically changed from iaro/dependencies to main May 2, 2025 11:54
@IaroslavMazur IaroslavMazur force-pushed the iaro/oraclized-fees-chainlink branch from 279e738 to b48b4bb Compare July 17, 2025 16:44
@IaroslavMazur IaroslavMazur marked this pull request as draft July 17, 2025 16:44
@IaroslavMazur IaroslavMazur force-pushed the iaro/oraclized-fees-chainlink branch from 9257e3f to 99a523a Compare July 21, 2025 11:08
@IaroslavMazur IaroslavMazur marked this pull request as ready for review July 21, 2025 11:08
@IaroslavMazur IaroslavMazur changed the title feat: calculate withdrawal fee using ChainLink Oracle-based fee charging Jul 21, 2025
@IaroslavMazur IaroslavMazur force-pushed the iaro/oraclized-fees-chainlink branch from 99a523a to 6b444fe Compare July 22, 2025 20:52
@IaroslavMazur IaroslavMazur changed the base branch from main to iaro/fix-build-gh-workflow July 22, 2025 20:54
Base automatically changed from iaro/fix-build-gh-workflow to main July 24, 2025 15:11
@andreivladbrg
Copy link
Member

@IaroslavMazur before I proceed with a full review, I have a quick question

why is the WITHDRAWAL_FEE_USD defined as a constant and not configurable?

@IaroslavMazur
Copy link
Member Author

why is the WITHDRAWAL_FEE_USD defined as a constant and not configurable?

Because at this point, we don't have a way of modifying it (by an admin) after the program deployment.

This will be implemented in #171.

@andreivladbrg
Copy link
Member

hmm, why not implement it from the beginning and do it as a 2-step process? 😆

@IaroslavMazur
Copy link
Member Author

hmm, why not implement it from the beginning and do it as a 2-step process? 😆

Fee changing wasn't a part of our product offering for v1, as far as I remember.

@andreivladbrg
Copy link
Member

Fee changing wasn't a part of our product offering for v1, as far as I remember.

what's v1?

we initially used a constant (for the lamports amount) due to not having chainlink available - but now, we should have the USD fee editable

now nvm, we'll implement it later then

@IaroslavMazur
Copy link
Member Author

what's v1?

The first official release of SolSab.

we should have the USD fee editable

This subject was raised during the EthCC All-Hands - and, as far as I remember, the consensus was that it's not a must for V1.

I have no issue with implementing it now. In fact, that's what I envisioned for us in the nearest future, as well. I just explained why it was not a part of this PR.

@andreivladbrg
Copy link
Member

andreivladbrg commented Jul 26, 2025

This subject was raised during the EthCC All-Hands - and, as far as I remember, the consensus was that it's not a must for V1.

is it? then, i may have been remembered incorrectly - mb

Copy link
Member

@andreivladbrg andreivladbrg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left some comments on the lockup implementation — the same feedback can be applied to merkle_instant

i haven't reviewed the tests yet, as we'll first need to rebase from PRB's PR, which will of course cause conflicts
but there's one thing that caught my attention:

you're using the actual devnet address for the chainlink oracle
these are fork tests, not unit ones - we should declare some mocks that return various values, see this

or maybe chainlink already provides some test utils

@IaroslavMazur
Copy link
Member Author

we should declare some mocks that return various values

For this,

  • either Anchor would have to provide us with the ability to create mocks (which they don't currently offer, as far as I can tell)
  • or we'd need to manually re-implement the Chainlink programs - and deploy them to Testnet/Devnet, where we want to test SolSab.

Are you suggesting we do the latter? And do it before the audit?

@andreivladbrg
Copy link
Member

For this,

  • either Anchor would have to provide us with the ability to create mocks (which they don't currently offer, as far as I can tell)
  • or we'd need to manually re-implement the Chainlink programs - and deploy them to Testnet/Devnet, where we want to test SolSab.

asked Claude and it should be doable without having a very complex system
could you rebase first please? i can give it a try later today
if it turns out to be too complicated, let's stick with the devnet approach

@IaroslavMazur IaroslavMazur force-pushed the iaro/oraclized-fees-chainlink branch from cc079a1 to 6d9fa01 Compare July 30, 2025 22:59
@IaroslavMazur
Copy link
Member Author

IaroslavMazur commented Jul 30, 2025

@andreivladbrg, rebased the PR.

Note that we still need to double-check the generic branch of the following match:

let fee_in_lamports: u64 = match oracle_decimals {
        8 => {
            // If the oracle decimals are 8, calculate the fee.
            CLAIM_FEE_USD * LAMPORTS_PER_SOL / price
        }
        decimals => {
            // Otherwise, adjust the calculation to account for the oracle decimals.
            CLAIM_FEE_USD * 10_u64.pow(10 + decimals as u32) / price
        }
    };

Also, I'm not sure why CI is failing. Will check it tomorrow.

Copy link
Member

@andreivladbrg andreivladbrg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will leave comments sequentially

@andreivladbrg
Copy link
Member

andreivladbrg commented Jul 31, 2025

Note that we still need to double-check the generic branch of the following match:

fixed in ed22eb1

@andreivladbrg
Copy link
Member

@IaroslavMazur does the Treasury naming make sense anymore?

i believe we can rename it to comptroller (like in EVM)

wdyt?

@IaroslavMazur
Copy link
Member Author

IaroslavMazur commented Jul 31, 2025

i believe we can rename it to comptroller (like in EVM)

Now that we have both the fee_collector and the Chainlink program addresses in there, Treasury does seem off-point.

"Comptroller" sounds good!

Copy link
Member

@andreivladbrg andreivladbrg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@IaroslavMazur left few more comments, i'll address them (already made changes locally)

@andreivladbrg
Copy link
Member

Now that we have both the fee_collector and the Chainlink program addresses in there, Treasury does seem off-point.

"Comptroller" sounds good!

thanks

@IaroslavMazur
Copy link
Member Author

@IaroslavMazur left few more comments, i'll address them (already made changes locally)

Awesome, thank you!

@andreivladbrg
Copy link
Member

@IaroslavMazur pushed 2 more commits: 68e12c7 3b2504d

if they look good, could you please mark the above comments as resolved?

Copy link
Member Author

@IaroslavMazur IaroslavMazur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes to the program code look good, in general.

Left some feedback.

Copy link
Member

@andreivladbrg andreivladbrg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left few comments more

@andreivladbrg
Copy link
Member

andreivladbrg commented Aug 2, 2025

@IaroslavMazur I did it 🎉 I finally managed to mock Chainlink!

I'd recommend revisiting coverage later with different mock scenarios.

Please review: cc02f36

Copy link
Member Author

@IaroslavMazur IaroslavMazur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very well done! Without the requests to the Solana Devnet & the Chainlink/Hermes oracles, the tests are truly flying now! 👏

Leaving some feedback below, along with a little cleaning in bc64a55.

@IaroslavMazur IaroslavMazur force-pushed the iaro/oraclized-fees-chainlink branch from 8e14cbf to 4b5e9e6 Compare August 3, 2025 14:52
@IaroslavMazur
Copy link
Member Author

@andreivladbrg, squashed the commits from this branch - and rebased them onto main

@IaroslavMazur IaroslavMazur force-pushed the iaro/oraclized-fees-chainlink branch from 4b5e9e6 to 3d4b800 Compare August 3, 2025 14:56
Copy link
Member

@andreivladbrg andreivladbrg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's merge this

@andreivladbrg andreivladbrg mentioned this pull request Aug 3, 2025
IaroslavMazur and others added 3 commits August 4, 2025 14:26
test: Oracle-based fee charging

docs: mention the amount in USD charged
docs: explanatory comment for the constants
docs: polish

refactor: polish

feat: add view function to calculate the withdraw/claim lamports fee
refactor: move fee calculation into a separate file

test: mock chainlink

Co-authored-by: Andrei Vlad <[email protected]>
@IaroslavMazur IaroslavMazur force-pushed the iaro/oraclized-fees-chainlink branch from 5daee84 to 38fca92 Compare August 4, 2025 11:27
@IaroslavMazur
Copy link
Member Author

Rebased the branch again.

@andreivladbrg, feel free to merge if it lgty.

@andreivladbrg andreivladbrg merged commit 0ceed58 into main Aug 4, 2025
1 check failed
@andreivladbrg andreivladbrg deleted the iaro/oraclized-fees-chainlink branch August 4, 2025 11:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Oracle-based withdrawal fee charging

3 participants