Skip to content

[BOOST-5224] feat(evm): add topup functionality to core#367

Merged
Quazia merged 25 commits intomainfrom
arthur/boost-5224-add-topup-functionality-to-core
Jan 24, 2025
Merged

[BOOST-5224] feat(evm): add topup functionality to core#367
Quazia merged 25 commits intomainfrom
arthur/boost-5224-add-topup-functionality-to-core

Conversation

@Quazia
Copy link
Contributor

@Quazia Quazia commented Jan 15, 2025

Description

This PR introduces a new top-up flow in BoostCore that routes additional tokens into existing incentives, adding topupIncentiveFromBudget (for budget-based tokens) and topupIncentiveFromSender (for user-supplied tokens). Both flows gather all tokens in BoostCore , compute and record protocol fees, and temporarily approve the incentive contract to pull the remainder via its topup function. We remove approval after the transfers. Two things to watch out for in review are that funds can't be pulled out of core if there was a malicious incentive and that all permissions on the budget are respected. Basically we want to avoid loss of funds.

Assumptions:

  • If sending directly the user has already approved BoostCore for ERC20 tokens or setApprovalForAll for ERC1155 tokens .
  • If sending from a budget the user must be permissioned on the budget. Approval isn't needed based on how we handle disbursals.
  • The bytes data_ argument decodes based on the incentives InitPayload struct an example of which is shown below.
  • Protocol fees are only reserved in BoostCore, and may be transferred or settled at a later time.

New Function Signatures

function topupIncentiveFromBudget(
    uint256 boostId,
    uint256 incentiveId,
    bytes calldata data_,
    address budget
) external nonReentrant;

function topupIncentiveFromSender(
    uint256 boostId,
    uint256 incentiveId,
    bytes calldata data_
) external nonReentrant;

Example of Relevant Struct for _data payload

struct InitPayload {
        address asset;
        Strategy strategy;
        uint256 reward;
        uint256 limit;
        address manager;
    }

This param (_data) should be the InitPayload for the incentive being topped up.

@changeset-bot
Copy link

changeset-bot bot commented Jan 15, 2025

⚠️ No Changeset found

Latest commit: fcd9d88

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@Quazia Quazia changed the base branch from main to kevin/boost-5204-add-topup-functionality-to-budgets January 15, 2025 04:08
@github-actions github-actions bot added the EVM label Jan 15, 2025
@sammccord
Copy link
Contributor

Warnings
⚠️

Are you sure you want to be submitting a change without including a changeset? If you're just changing docs or tests, you probably don't need to. See the publishing section of the README for more info.

Generated by 🚫 dangerJS against 73177a0

1 similar comment
@sammccord
Copy link
Contributor

Warnings
⚠️

Are you sure you want to be submitting a change without including a changeset? If you're just changing docs or tests, you probably don't need to. See the publishing section of the README for more info.

Generated by 🚫 dangerJS against 73177a0

Copy link
Contributor

@topocount topocount left a comment

Choose a reason for hiding this comment

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

@Quazia are there any tests for this one?

@sammccord
Copy link
Contributor

Warnings
⚠️

Are you sure you want to be submitting a change without including a changeset? If you're just changing docs or tests, you probably don't need to. See the publishing section of the README for more info.

Generated by 🚫 dangerJS against 93adba2

@topocount topocount force-pushed the arthur/boost-5224-add-topup-functionality-to-core branch from 93adba2 to 8d0633b Compare January 15, 2025 20:45
@sammccord
Copy link
Contributor

Warnings
⚠️

Are you sure you want to be submitting a change without including a changeset? If you're just changing docs or tests, you probably don't need to. See the publishing section of the README for more info.

Generated by 🚫 dangerJS against 8d0633b

@topocount topocount force-pushed the arthur/boost-5224-add-topup-functionality-to-core branch from 8d0633b to b5ee7b5 Compare January 15, 2025 20:47
@sammccord
Copy link
Contributor

Warnings
⚠️

Are you sure you want to be submitting a change without including a changeset? If you're just changing docs or tests, you probably don't need to. See the publishing section of the README for more info.

Generated by 🚫 dangerJS against b5ee7b5

@sammccord
Copy link
Contributor

Warnings
⚠️

Are you sure you want to be submitting a change without including a changeset? If you're just changing docs or tests, you probably don't need to. See the publishing section of the README for more info.

Generated by 🚫 dangerJS against 795b315

@topocount topocount changed the base branch from kevin/boost-5204-add-topup-functionality-to-budgets to main January 16, 2025 16:29
@sammccord
Copy link
Contributor

Warnings
⚠️

Are you sure you want to be submitting a change without including a changeset? If you're just changing docs or tests, you probably don't need to. See the publishing section of the README for more info.

Generated by 🚫 dangerJS against 795b315

@topocount
Copy link
Contributor

@Quazia just a heads-up I've closed #363 and redirected this pr to main. It still contains changes for BOOST-5200 but no PR is open for that feature branch

@sammccord
Copy link
Contributor

Warnings
⚠️

Are you sure you want to be submitting a change without including a changeset? If you're just changing docs or tests, you probably don't need to. See the publishing section of the README for more info.

Generated by 🚫 dangerJS against ad8d258

@Quazia Quazia force-pushed the arthur/boost-5224-add-topup-functionality-to-core branch from ad8d258 to 3e33311 Compare January 17, 2025 16:07
@sammccord
Copy link
Contributor

Warnings
⚠️

Are you sure you want to be submitting a change without including a changeset? If you're just changing docs or tests, you probably don't need to. See the publishing section of the README for more info.

Generated by 🚫 dangerJS against 3e33311

@sammccord
Copy link
Contributor

Warnings
⚠️

Are you sure you want to be submitting a change without including a changeset? If you're just changing docs or tests, you probably don't need to. See the publishing section of the README for more info.

Generated by 🚫 dangerJS against 59b095d

@topocount topocount force-pushed the arthur/boost-5224-add-topup-functionality-to-core branch from 59b095d to a6a1ee4 Compare January 23, 2025 15:56
@sammccord
Copy link
Contributor

Warnings
⚠️

Are you sure you want to be submitting a change without including a changeset? If you're just changing docs or tests, you probably don't need to. See the publishing section of the README for more info.

Generated by 🚫 dangerJS against a6a1ee4

@github-actions github-actions bot added the SDK label Jan 24, 2025
@Quazia Quazia force-pushed the arthur/boost-5224-add-topup-functionality-to-core branch from 1c9d8a2 to bf1a8da Compare January 24, 2025 15:42
@sammccord
Copy link
Contributor

Warnings
⚠️

Are you sure you want to be submitting a change without including a changeset? If you're just changing docs or tests, you probably don't need to. See the publishing section of the README for more info.

Generated by 🚫 dangerJS against bf1a8da

@sammccord
Copy link
Contributor

Warnings
⚠️

Are you sure you want to be submitting a change without including a changeset? If you're just changing docs or tests, you probably don't need to. See the publishing section of the README for more info.

Generated by 🚫 dangerJS against fcd9d88

@Quazia Quazia enabled auto-merge (rebase) January 24, 2025 16:12
Copy link
Contributor

@topocount topocount 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 to me, a few small questions

/// @dev Uses `msg.sender` as the token source, and uses `asset` to identify which token.
/// Caller must approve this contract to spend at least `amount` prior to calling.
/// @param amount The number of tokens to top up
function topup(uint256 amount) external virtual override onlyOwnerOrRoles(MANAGER_ROLE) {
Copy link
Contributor

Choose a reason for hiding this comment

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

bit of a bikeshedding question: should this interface be added to AIncentive?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I specifically avoided that cause it'd change all the component interfaces and we're not calling into it from the helpers but I could add it. Would just require more thought around the component interface change for existing incentive modules.

Comment on lines +135 to +137
if (amount == 0) {
revert BoostError.InvalidInitialization();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

why have this check? spam avoidance?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could probably remove it - the check exists in the SDK and I'm generally in favor of less in-contract checks for 'enough rope' type problems

) {
const feeBps = await this.protocolFee(params);
const topupAmount =
(totalAmount * FEE_DENOMINATOR) / (FEE_DENOMINATOR + feeBps);
Copy link
Contributor

Choose a reason for hiding this comment

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

nice!
it might be worth reconstituting this and validating the diff isn't greater than the available budget

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah we could add some sort of additional check here - we'd probably want it for all four though. WDYT is it worth it?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think its better than relying on a relatively terse revert

* @param {?WriteParams} [params] Additional transaction overrides
* @returns {Promise<{ hash: Hex; result: void }>}
*/
public async topupIncentiveFromBudgetPostFee(
Copy link
Contributor

Choose a reason for hiding this comment

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

soft nit:

Suggested change
public async topupIncentiveFromBudgetPostFee(
public async topupIncentiveFromBudgetIncludingFee(

* @param {?WriteParams} [params] Additional transaction overrides
* @returns {Promise<{ hash: Hex; result: void }>} The transaction hash and simulation result
*/
public async topupIncentiveFromBudgetPreFee(
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
public async topupIncentiveFromBudgetPreFee(
public async topupIncentiveFromBudgetWithoutFee(

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This sort of implies that there won't be a fee which there very much will be.

Copy link
Contributor

@topocount topocount Jan 24, 2025

Choose a reason for hiding this comment

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

Yeah pre-fee probably works fine

@Quazia Quazia merged commit 43c154c into main Jan 24, 2025
5 checks passed
@Quazia Quazia deleted the arthur/boost-5224-add-topup-functionality-to-core branch January 24, 2025 18:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants