Skip to content

Commit

Permalink
Merge pull request #30 from Bananapus/verbiage/percent
Browse files Browse the repository at this point in the history
Verbiage/percent
  • Loading branch information
xBA5ED authored Jul 21, 2024
2 parents 8edadb2 + 7aad155 commit 9caaedd
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 27 deletions.
2 changes: 1 addition & 1 deletion lib/sphinx
Submodule sphinx updated 107 files
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bananapus/buyback-hook",
"version": "0.0.16",
"version": "0.0.17",
"license": "MIT",
"repository": {
"type": "git",
Expand All @@ -18,7 +18,7 @@
"artifacts": "source ./.env && npx sphinx artifacts --org-id 'my-org-id' --project-name 'nana-buyback-hook-testnet'"
},
"dependencies": {
"@bananapus/core": "^0.0.23",
"@bananapus/core": "^0.0.24",
"@bananapus/permission-ids": "^0.0.11",
"@exhausted-pigeon/uniswap-v3-forge-quoter": "^1.0.1",
"@openzeppelin/contracts": "^5.0.2",
Expand All @@ -28,4 +28,4 @@
"devDependencies": {
"@sphinx-labs/plugins": "^0.33.0"
}
}
}
2 changes: 1 addition & 1 deletion src/JBBuybackHook.sol
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ contract JBBuybackHook is JBPermissioned, IJBBuybackHook {
tokenCount: exactSwapAmountOut + partialMintTokenCount,
beneficiary: address(context.beneficiary),
memo: "",
useReservedRate: true
useReservedPercent: true
});
}

Expand Down
29 changes: 15 additions & 14 deletions test/Fork.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -265,17 +265,17 @@ contract TestJBBuybackHook_Fork is Test, UniswapV3ForgeQuoter {
// // *
// // * @dev Should swap for both beneficiary and reserve (by burning/minting)
// // */
// // function test_swapIfQuoteBetter(uint256 _weight, uint256 _amountIn, uint256 _reservedRate) public {
// // function test_swapIfQuoteBetter(uint256 _weight, uint256 _amountIn, uint256 _reservedPercent) public {
// // _amountIn = bound(_amountIn, 100, 100 ether);

// // uint256 _amountOutQuoted = getAmountOut(pool, _amountIn, address(weth));

// // // Reconfigure with a weight smaller than the price implied by the quote
// // _weight = bound(_weight, 1, (_amountOutQuoted * 10 ** 18 / _amountIn) - 1);

// // _reservedRate = bound(_reservedRate, 0, 10_000);
// // _reservedPercent = bound(_reservedPercent, 0, 10_000);

// // _reconfigure(1, address(delegate), _weight, _reservedRate);
// // _reconfigure(1, address(delegate), _weight, _reservedPercent);

// // uint256 _reservedBalanceBefore = jbController.reservedTokenBalanceOf(1);

Expand Down Expand Up @@ -314,15 +314,15 @@ contract TestJBBuybackHook_Fork is Test, UniswapV3ForgeQuoter {
// // // Check: token received by the beneficiary
// // assertApproxEqAbs(
// // jbx.balanceOf(beneficiary) - _balBeforePayment,
// // _amountOutQuoted - (_amountOutQuoted * _reservedRate / 10_000),
// // _amountOutQuoted - (_amountOutQuoted * _reservedPercent / 10_000),
// // 1,
// // "wrong balance"
// // );

// // // Check: token added to the reserve - 1 wei sensitivity for rounding errors
// // assertApproxEqAbs(
// // jbController.reservedTokenBalanceOf(1),
// // _reservedBalanceBefore + _amountOutQuoted * _reservedRate / 10_000,
// // _reservedBalanceBefore + _amountOutQuoted * _reservedPercent / 10_000,
// // 1,
// // "wrong reserve"
// // );
Expand Down Expand Up @@ -468,13 +468,13 @@ contract TestJBBuybackHook_Fork is Test, UniswapV3ForgeQuoter {
// // *
// // * @dev Should swap for both beneficiary and reserve (by burning/minting)
// // */
// // function test_swapWhenQuoteNotProvidedInMetadata(uint256 _amountIn, uint256 _reservedRate) public {
// // function test_swapWhenQuoteNotProvidedInMetadata(uint256 _amountIn, uint256 _reservedPercent) public {
// // _amountIn = bound(_amountIn, 10, 10 ether);
// // _reservedRate = bound(_reservedRate, 0, 10_000);
// // _reservedPercent = bound(_reservedPercent, 0, 10_000);

// // uint256 _weight = 10 ether;

// // _reconfigure(1, address(delegate), _weight, _reservedRate);
// // _reconfigure(1, address(delegate), _weight, _reservedPercent);

// // uint256 _reservedBalanceBefore = jbController.reservedTokenBalanceOf(1);

Expand Down Expand Up @@ -511,18 +511,19 @@ contract TestJBBuybackHook_Fork is Test, UniswapV3ForgeQuoter {
// // // 1 wei sensitivity for rounding errors
// // if (_twap > _tokenCount) {
// // // Path is picked based on twap, but the token received are the one quoted
// // assertApproxEqAbs(_tokenReceived, _quote - (_quote * _reservedRate) / 10_000, 1, "wrong swap");
// // assertApproxEqAbs(_tokenReceived, _quote - (_quote * _reservedPercent) / 10_000, 1, "wrong swap");
// // assertApproxEqAbs(
// // jbController.reservedTokenBalanceOf(1),
// // _reservedBalanceBefore + (_quote * _reservedRate) / 10_000,
// // _reservedBalanceBefore + (_quote * _reservedPercent) / 10_000,
// // 1,
// // "Reserve"
// // );
// // } else {
// // assertApproxEqAbs(_tokenReceived, _tokenCount - (_tokenCount * _reservedRate) / 10_000, 1, "Wrong mint");
// // assertApproxEqAbs(_tokenReceived, _tokenCount - (_tokenCount * _reservedPercent) / 10_000, 1, "Wrong
// mint");
// // assertApproxEqAbs(
// // jbController.reservedTokenBalanceOf(1),
// // _reservedBalanceBefore + (_tokenCount * _reservedRate) / 10_000,
// // _reservedBalanceBefore + (_tokenCount * _reservedPercent) / 10_000,
// // 1,
// // "Reserve"
// // );
Expand Down Expand Up @@ -676,7 +677,7 @@ contract TestJBBuybackHook_Fork is Test, UniswapV3ForgeQuoter {
// // );
// // }

// function _reconfigure(uint256 _projectId, address _delegate, uint256 _weight, uint256 _reservedRate) internal {
// function _reconfigure(uint256 _projectId, address _delegate, uint256 _weight, uint256 _reservedPercent) internal {
// address _projectOwner = jbProjects.ownerOf(_projectId);

// JBRuleset memory _fundingCycle = jbRulesets.currentOf(_projectId);
Expand All @@ -696,7 +697,7 @@ contract TestJBBuybackHook_Fork is Test, UniswapV3ForgeQuoter {
// metadata.useDataHookForPay = true;
// metadata.dataHook = _delegate;

// metadata.reservedRate = _reservedRate;
// metadata.reservedPercent = _reservedPercent;

// data.weight = _weight;
// data.duration = 14 days;
Expand Down
2 changes: 1 addition & 1 deletion test/Unit.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ contract Test_BuybackHook_Unit is Test {
rulesetId: 0,
beneficiary: dude,
weight: 69,
reservedRate: 0,
reservedPercent: 0,
metadata: ""
});

Expand Down
6 changes: 3 additions & 3 deletions test/helpers/TestBaseWorkflowV3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ contract TestBaseWorkflowV3 is Test {
JBBuybackHook hook;

uint256 projectId;
uint16 reservedRate = 4500;
uint16 reservedPercent = 4500;
uint112 weight = 10 ether; // Minting 10 token per eth
uint32 cardinality = 1000;
uint256 twapDelta = 500;
Expand Down Expand Up @@ -170,7 +170,7 @@ contract TestBaseWorkflowV3 is Test {

// Ruleset metadata: use the hook for payments.
metadata = JBRulesetMetadata({
reservedRate: reservedRate,
reservedPercent: reservedPercent,
redemptionRate: 5000,
baseCurrency: uint32(uint160(JBConstants.NATIVE_TOKEN)),
pausePay: false,
Expand Down Expand Up @@ -210,7 +210,7 @@ contract TestBaseWorkflowV3 is Test {
rulesetConfigurations[0].mustStartAtOrAfter = 0;
rulesetConfigurations[0].duration = 6 days;
rulesetConfigurations[0].weight = weight;
rulesetConfigurations[0].decayRate = 0;
rulesetConfigurations[0].decayPercent = 0;
rulesetConfigurations[0].approvalHook = IJBRulesetApprovalHook(address(0));

rulesetConfigurations[0].metadata = metadata;
Expand Down

0 comments on commit 9caaedd

Please sign in to comment.