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

test: add BancorExchangeProvider pricing tests #532

Merged
merged 8 commits into from
Oct 23, 2024

Conversation

philbow61
Copy link
Contributor

@philbow61 philbow61 commented Oct 18, 2024

Description

This Pr adds tests for the pricing logic of the bancor exchange provider.

During the testing, we realized that the BancorFormula.sol contract is missing one function we need.
This function is getAmountIn for the tokenIn being the BancorToken. The new function is called saleCost()

The math formula for this function is derived from the saleTargetAmount() function already implemented. It's important that the base of power operation is larger one otherwise the power function in that contract reverts.

These are the current formulas used for the different pricing functions:
image

This is how we derived the formula for saleCost()

image

Related issues

How to review

  • verify formula is derived correctly
  • exit contribution is applied correctly
  • tests cover everything

@philbow61 philbow61 marked this pull request as ready for review October 18, 2024 14:01
@philbow61 philbow61 changed the base branch from feat/GDollar-of-latest-develop to main October 18, 2024 14:38
@philbow61 philbow61 changed the base branch from main to feat/GDollar-of-latest-develop October 18, 2024 14:38
(result, precision) = power(_reserveBalance, baseD, _reserveWeight, MAX_WEIGHT);
uint256 temp1 = _supply * result;
uint256 temp2 = _supply << precision;
return (temp1 - temp2 - 1) / result + 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not entrenched in context enough to assess the potential implications for this implementation.

But at the minimum, the setting of baseD, temp1 & temp2 as variables in this function can be removed to improve gas efficiency.

    (result, precision) = power(_reserveBalance, (_reserveBalance - _amount), _reserveWeight, MAX_WEIGHT);
    return ((_supply * result) - (_supply << precision) - 1) / result + 1;
    ```

Copy link
Contributor

@baroooo baroooo left a comment

Choose a reason for hiding this comment

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

Great job ✅

test/unit/goodDollar/BancorExchangeProvider.t.sol Outdated Show resolved Hide resolved
test/unit/goodDollar/BancorExchangeProvider.t.sol Outdated Show resolved Hide resolved
test/unit/goodDollar/BancorExchangeProvider.t.sol Outdated Show resolved Hide resolved
test/unit/goodDollar/BancorExchangeProvider.t.sol Outdated Show resolved Hide resolved
test/unit/goodDollar/BancorExchangeProvider.t.sol Outdated Show resolved Hide resolved
Copy link
Contributor

@RyRy79261 RyRy79261 left a comment

Choose a reason for hiding this comment

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

Looks good! Only nitpik on the temp variables for gas but likely very low impact

@philbow61 philbow61 merged commit 578747c into feat/GDollar-of-latest-develop Oct 23, 2024
5 checks passed
@philbow61 philbow61 deleted the test/BancorExchangeProvider branch October 23, 2024 08:58
bowd pushed a commit that referenced this pull request Oct 24, 2024
7704a9b chore: reserve storage gap in new contracts
040b7fe GoodDollar Fork Tests (#530)
2ee14b4 Feat(454): Exchange provider tests  (#529)
578747c test: add BancorExchangeProvider pricing tests (#532)
fcd3d02 feat: improve tests around the expansion controller (#533)
d3a31fa Streamline comments and errors (#528)
ec64f0a fix: ☦ pray to the lords of echidna
13d3a98 fix: add back forge install to the CI step
c236009 fix: echidna tests
c50a198 feat: add Broker liquidity check (#523)
914ba7d Address Slither Issues in GoodDollar/Bancor Contracts (#526)
8bcf3fd Feat/change gdollar modifiers (#524)
379a511 feat: make validate() internal
bcbd9aa chore: added "yarn todo" task to log out open todos in the code
0631c60 refactor: renamed SafeERC20 to SafeERC20MintableBurnable
2800297 feat: simplified SafeERC20
e858391 feat: extend open zeppelin's IERC20 instead of duplicating it
196f6be chore: fixed linter and compiler warnings
096efe2 test: fix fork integration test
e5308d9 feat: add GoodDollar contracts + tests
3135626 feat: update Broker + TradingLimits to 0.8 and make G$ changes
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.

5 participants