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

[ADHOC] Add decodeClaimData to ERC20PeggedIncentive #359

Merged
merged 2 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/silly-carpets-jog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@boostxyz/sdk": patch
---

add decodeClaimData to ERC20PeggedIncentive
31 changes: 30 additions & 1 deletion packages/sdk/src/Incentives/ERC20PeggedIncentive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import {
type Address,
type ContractEventName,
type Hex,
decodeAbiParameters,
encodeAbiParameters,
zeroAddress,
zeroHash,
} from 'viem';
import { ERC20PeggedIncentive as ERC20PeggedIncentiveBases } from '../../dist/deployments.json';
import type {
Expand Down Expand Up @@ -478,6 +478,35 @@ export class ERC20PeggedIncentive extends DeployableTarget<
[rewardAmount],
);
}

/**
* Decodes claim data for the ERC20PeggedIncentive, returning the claim amount.
* Useful when deriving amount claimed from logs.
*
* @public
* @param {Hex} claimData
* @returns {BigInt} Returns the reward amount from a claim data payload
*/
public decodeClaimData(claimData: Hex) {
const boostClaimData = decodeAbiParameters(
[
{
type: 'tuple',
name: 'BoostClaimData',
components: [
{ type: 'bytes', name: 'validatorData' },
{ type: 'bytes', name: 'incentiveData' },
],
},
],
claimData,
);
const signedAmount = decodeAbiParameters(
[{ type: 'uint256' }],
boostClaimData[0].incentiveData,
)[0];
return signedAmount;
}
}

/**
Expand Down
Loading