Skip to content
Open
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/chilly-buses-itch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@boostxyz/sdk": patch
---

allow 4-byte function selectors in incentive criteria
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
decodeAbiParameters,
decodeFunctionData,
encodeAbiParameters,
pad,
parseEther,
parseEventLogs,
zeroAddress,
Expand Down Expand Up @@ -844,7 +845,7 @@ export function prepareERC20PeggedVariableCriteriaIncentivePayload({
maxReward,
criteria: {
criteriaType: criteria.criteriaType,
signature: criteria.signature,
signature: pad(criteria.signature),
fieldIndex: criteria.fieldIndex,
targetContract: criteria.targetContract,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,4 +358,34 @@ describe("ERC20PeggedVariableCriteriaIncentive", () => {

expect(balanceAfterClaim - balanceBeforeClaim).toBe(signedAmount);
})

test("should deploy with a 4-byte function selector", async () => {
const fourByteSignature = "0xa9059cbb" as Hex; // transfer(address,uint256)

const incentiveWithFourByteSelector = fixtures.core.ERC20PeggedVariableCriteriaIncentiveV2({
asset: budgets.erc20.assertValidAddress(),
peg: zeroAddress,
limit: 1000000n,
reward: 1000000n,
maxReward: 1000000n,
criteria: {
criteriaType: SignatureType.FUNC,
signature: fourByteSignature,
fieldIndex: 1,
targetContract: budgets.erc20.assertValidAddress(),
valueType: ValueType.WAD,
},
});

const newBoost = await freshBoost(fixtures, {
budget: budgets.budget,
incentives: [incentiveWithFourByteSelector],
});
const incentive = newBoost.incentives[0] as ERC20PeggedVariableCriteriaIncentiveV2;
const deployedCriteria = await incentive.getIncentiveCriteria();

expect(isAddress(newBoost.incentives[0]!.assertValidAddress())).toBe(true);
expect(deployedCriteria.signature.length).toBe(66);
expect(deployedCriteria.signature.endsWith(fourByteSignature.slice(2))).toBe(true);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
decodeAbiParameters,
decodeFunctionData,
encodeAbiParameters,
pad,
parseEther,
parseEventLogs,
zeroAddress,
Expand Down Expand Up @@ -923,7 +924,7 @@ export function prepareERC20PeggedVariableCriteriaIncentiveV2Payload({
maxReward,
criteria: {
criteriaType: criteria.criteriaType,
signature: criteria.signature,
signature: pad(criteria.signature),
fieldIndex: criteria.fieldIndex,
targetContract: criteria.targetContract,
valueType: criteria.valueType,
Comment on lines 924 to 930
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Guard EVENT topics; pad only FUNC selectors.

Same rationale as the V2 variable file: keep EVENT topics strict 32B; pad 4B only for FUNC. Make pad explicit.

-          signature: pad(criteria.signature),
+          signature:
+            criteria.criteriaType === SignatureType.FUNC
+              ? pad(criteria.signature, { size: 32, dir: 'left' })
+              : criteria.signature,
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
maxReward,
criteria: {
criteriaType: criteria.criteriaType,
signature: criteria.signature,
signature: pad(criteria.signature),
fieldIndex: criteria.fieldIndex,
targetContract: criteria.targetContract,
valueType: criteria.valueType,
maxReward,
criteria: {
criteriaType: criteria.criteriaType,
signature:
criteria.criteriaType === SignatureType.FUNC
? pad(criteria.signature, { size: 32, dir: 'left' })
: criteria.signature,
fieldIndex: criteria.fieldIndex,
targetContract: criteria.targetContract,
valueType: criteria.valueType,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
decodeAbiParameters,
decodeFunctionData,
encodeAbiParameters,
pad,
parseEther,
parseEventLogs,
zeroAddress,
Expand Down Expand Up @@ -429,7 +430,7 @@ export function prepareERC20VariableCriteriaIncentivePayload({
maxReward: maxReward,
criteria: {
criteriaType: criteria.criteriaType,
signature: criteria.signature,
signature: pad(criteria.signature),
fieldIndex: criteria.fieldIndex,
targetContract: criteria.targetContract,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,4 +272,32 @@ describe("ERC20VariableCriteriaIncentiveV2", () => {
true,
);
});

test("should deploy with a 4-byte function selector", async () => {
const fourByteSignature = "0xa9059cbb" as Hex; // transfer(address,uint256)

const incentiveWithFourByteSelector = fixtures.core.ERC20VariableCriteriaIncentiveV2({
asset: budgets.erc20.assertValidAddress(),
limit: 1000000n,
reward: 1000000n,
criteria: {
criteriaType: SignatureType.FUNC,
signature: fourByteSignature,
fieldIndex: 1,
targetContract: budgets.erc20.assertValidAddress(),
valueType: ValueType.WAD,
},
});

const newBoost = await freshBoost(fixtures, {
budget: budgets.budget,
incentives: [incentiveWithFourByteSelector],
});
const incentive = newBoost.incentives[0] as ERC20VariableCriteriaIncentiveV2;
const deployedCriteria = await incentive.getIncentiveCriteria();

expect(isAddress(newBoost.incentives[0]!.assertValidAddress())).toBe(true);
expect(deployedCriteria.signature.length).toBe(66);
expect(deployedCriteria.signature.endsWith(fourByteSignature.slice(2))).toBe(true);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
decodeAbiParameters,
decodeFunctionData,
encodeAbiParameters,
pad,
parseEther,
parseEventLogs,
zeroAddress,
Expand Down Expand Up @@ -501,7 +502,7 @@ export function prepareERC20VariableCriteriaIncentiveV2Payload({
maxReward: maxReward,
criteria: {
criteriaType: criteria.criteriaType,
signature: criteria.signature,
signature: pad(criteria.signature),
fieldIndex: criteria.fieldIndex,
targetContract: criteria.targetContract,
valueType: criteria.valueType,
Expand Down
Loading