@boostxyz/sdk 2.0.0-alpha.35 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (136) hide show
  1. package/dist/Actions/Action.cjs +1 -1
  2. package/dist/Actions/Action.js +4 -4
  3. package/dist/Actions/EventAction.cjs +1 -1
  4. package/dist/Actions/EventAction.js +17 -17
  5. package/dist/Actions/EventAction.js.map +1 -1
  6. package/dist/AllowLists/AllowList.cjs +1 -1
  7. package/dist/AllowLists/AllowList.js +5 -5
  8. package/dist/AllowLists/SimpleAllowList.cjs +1 -1
  9. package/dist/AllowLists/SimpleAllowList.js +19 -19
  10. package/dist/AllowLists/SimpleDenyList.cjs +1 -1
  11. package/dist/AllowLists/SimpleDenyList.js +3 -3
  12. package/dist/Auth/PassthroughAuth.cjs +1 -1
  13. package/dist/Auth/PassthroughAuth.js +1 -1
  14. package/dist/BoostCore.cjs +2 -2
  15. package/dist/BoostCore.cjs.map +1 -1
  16. package/dist/BoostCore.d.ts +14 -0
  17. package/dist/BoostCore.d.ts.map +1 -1
  18. package/dist/BoostCore.js +100 -81
  19. package/dist/BoostCore.js.map +1 -1
  20. package/dist/BoostRegistry.cjs +1 -1
  21. package/dist/BoostRegistry.js +31 -31
  22. package/dist/Budget-B0kJsZtZ.cjs +2 -0
  23. package/dist/Budget-B0kJsZtZ.cjs.map +1 -0
  24. package/dist/Budget-NtzY9H7G.js +462 -0
  25. package/dist/Budget-NtzY9H7G.js.map +1 -0
  26. package/dist/Budgets/Budget.cjs +1 -1
  27. package/dist/Budgets/Budget.cjs.map +1 -1
  28. package/dist/Budgets/Budget.d.ts +5 -4
  29. package/dist/Budgets/Budget.d.ts.map +1 -1
  30. package/dist/Budgets/Budget.js +9 -26
  31. package/dist/Budgets/Budget.js.map +1 -1
  32. package/dist/Budgets/ManagedBudget.cjs +1 -1
  33. package/dist/Budgets/ManagedBudget.js +34 -34
  34. package/dist/Budgets/ManagedBudgetWithFees.d.ts +1203 -0
  35. package/dist/Budgets/ManagedBudgetWithFees.d.ts.map +1 -0
  36. package/dist/Deployable/DeployableTarget.cjs +1 -1
  37. package/dist/Deployable/DeployableTarget.js +1 -1
  38. package/dist/Deployable/DeployableTargetWithRBAC.cjs +1 -1
  39. package/dist/Deployable/DeployableTargetWithRBAC.js +23 -23
  40. package/dist/Incentives/AllowListIncentive.cjs +1 -1
  41. package/dist/Incentives/AllowListIncentive.cjs.map +1 -1
  42. package/dist/Incentives/AllowListIncentive.d.ts +18 -0
  43. package/dist/Incentives/AllowListIncentive.d.ts.map +1 -1
  44. package/dist/Incentives/AllowListIncentive.js +48 -22
  45. package/dist/Incentives/AllowListIncentive.js.map +1 -1
  46. package/dist/Incentives/CGDAIncentive.cjs +1 -1
  47. package/dist/Incentives/CGDAIncentive.cjs.map +1 -1
  48. package/dist/Incentives/CGDAIncentive.d.ts +18 -0
  49. package/dist/Incentives/CGDAIncentive.d.ts.map +1 -1
  50. package/dist/Incentives/CGDAIncentive.js +47 -16
  51. package/dist/Incentives/CGDAIncentive.js.map +1 -1
  52. package/dist/Incentives/ERC20Incentive.cjs +1 -1
  53. package/dist/Incentives/ERC20Incentive.cjs.map +1 -1
  54. package/dist/Incentives/ERC20Incentive.d.ts +18 -0
  55. package/dist/Incentives/ERC20Incentive.d.ts.map +1 -1
  56. package/dist/Incentives/ERC20Incentive.js +58 -32
  57. package/dist/Incentives/ERC20Incentive.js.map +1 -1
  58. package/dist/Incentives/ERC20VariableCriteriaIncentive.cjs +1 -1
  59. package/dist/Incentives/ERC20VariableCriteriaIncentive.cjs.map +1 -1
  60. package/dist/Incentives/ERC20VariableCriteriaIncentive.js +29 -29
  61. package/dist/Incentives/ERC20VariableCriteriaIncentive.js.map +1 -1
  62. package/dist/Incentives/ERC20VariableIncentive.cjs +1 -1
  63. package/dist/Incentives/ERC20VariableIncentive.cjs.map +1 -1
  64. package/dist/Incentives/ERC20VariableIncentive.d.ts +18 -0
  65. package/dist/Incentives/ERC20VariableIncentive.d.ts.map +1 -1
  66. package/dist/Incentives/ERC20VariableIncentive.js +37 -11
  67. package/dist/Incentives/ERC20VariableIncentive.js.map +1 -1
  68. package/dist/Incentives/Incentive.cjs +1 -1
  69. package/dist/Incentives/Incentive.js +4 -4
  70. package/dist/Incentives/PointsIncentive.cjs +1 -1
  71. package/dist/Incentives/PointsIncentive.cjs.map +1 -1
  72. package/dist/Incentives/PointsIncentive.d.ts +18 -0
  73. package/dist/Incentives/PointsIncentive.d.ts.map +1 -1
  74. package/dist/Incentives/PointsIncentive.js +49 -23
  75. package/dist/Incentives/PointsIncentive.js.map +1 -1
  76. package/dist/{SimpleDenyList-wDvsNIuY.cjs → SimpleDenyList-B65fnca2.cjs} +2 -2
  77. package/dist/{SimpleDenyList-wDvsNIuY.cjs.map → SimpleDenyList-B65fnca2.cjs.map} +1 -1
  78. package/dist/{SimpleDenyList-D-rGBaay.js → SimpleDenyList-UvXQl2vm.js} +20 -20
  79. package/dist/{SimpleDenyList-D-rGBaay.js.map → SimpleDenyList-UvXQl2vm.js.map} +1 -1
  80. package/dist/Validators/LimitedSignerValidator.cjs +1 -1
  81. package/dist/Validators/LimitedSignerValidator.js +9 -9
  82. package/dist/Validators/SignerValidator.cjs +1 -1
  83. package/dist/Validators/SignerValidator.js +8 -8
  84. package/dist/Validators/Validator.cjs +1 -1
  85. package/dist/Validators/Validator.cjs.map +1 -1
  86. package/dist/Validators/Validator.js +20 -20
  87. package/dist/componentInterfaces-Bt-4sNB5.cjs +2 -0
  88. package/dist/componentInterfaces-Bt-4sNB5.cjs.map +1 -0
  89. package/dist/componentInterfaces-dakxtQHf.js +16 -0
  90. package/dist/componentInterfaces-dakxtQHf.js.map +1 -0
  91. package/dist/deployments-DxkwtCyu.cjs +2 -0
  92. package/dist/deployments-DxkwtCyu.cjs.map +1 -0
  93. package/dist/{deployments-BdPDIh-i.js → deployments-ZLVwJGZD.js} +33 -30
  94. package/dist/deployments-ZLVwJGZD.js.map +1 -0
  95. package/dist/deployments.json +17 -14
  96. package/dist/{generated-CDEDSOGZ.js → generated-B0XfMfoq.js} +1037 -470
  97. package/dist/generated-B0XfMfoq.js.map +1 -0
  98. package/dist/generated-pNKCp_Ez.cjs +3 -0
  99. package/dist/generated-pNKCp_Ez.cjs.map +1 -0
  100. package/dist/index.cjs +1 -1
  101. package/dist/index.d.ts +1 -0
  102. package/dist/index.d.ts.map +1 -1
  103. package/dist/index.js +148 -144
  104. package/dist/utils.cjs +1 -1
  105. package/dist/utils.cjs.map +1 -1
  106. package/dist/utils.d.ts +12 -0
  107. package/dist/utils.d.ts.map +1 -1
  108. package/dist/utils.js +64 -35
  109. package/dist/utils.js.map +1 -1
  110. package/package.json +1 -1
  111. package/src/BoostCore.ts +30 -0
  112. package/src/Budgets/Budget.ts +8 -3
  113. package/src/Budgets/ManagedBudgetWithFees.test.ts +286 -0
  114. package/src/Budgets/ManagedBudgetWithFees.ts +671 -0
  115. package/src/Incentives/AllowListIncentive.test.ts +52 -4
  116. package/src/Incentives/AllowListIncentive.ts +28 -0
  117. package/src/Incentives/CGDAIncentive.test.ts +48 -3
  118. package/src/Incentives/CGDAIncentive.ts +34 -0
  119. package/src/Incentives/ERC20Incentive.test.ts +42 -0
  120. package/src/Incentives/ERC20Incentive.ts +28 -0
  121. package/src/Incentives/ERC20VariableIncentive.test.ts +41 -1
  122. package/src/Incentives/ERC20VariableIncentive.ts +28 -0
  123. package/src/Incentives/PointsIncentive.test.ts +47 -3
  124. package/src/Incentives/PointsIncentive.ts +28 -0
  125. package/src/index.ts +1 -0
  126. package/src/utils.ts +46 -0
  127. package/dist/componentInterfaces-BQw7DH-m.cjs +0 -2
  128. package/dist/componentInterfaces-BQw7DH-m.cjs.map +0 -1
  129. package/dist/componentInterfaces-C0vuWQlh.js +0 -15
  130. package/dist/componentInterfaces-C0vuWQlh.js.map +0 -1
  131. package/dist/deployments--f75Pthq.cjs +0 -2
  132. package/dist/deployments--f75Pthq.cjs.map +0 -1
  133. package/dist/deployments-BdPDIh-i.js.map +0 -1
  134. package/dist/generated-CDEDSOGZ.js.map +0 -1
  135. package/dist/generated-D3DE5TfH.cjs +0 -3
  136. package/dist/generated-D3DE5TfH.cjs.map +0 -1
@@ -1,6 +1,3 @@
1
- import { loadFixture } from "@nomicfoundation/hardhat-network-helpers";
2
- import { isAddress, pad, parseEther, zeroAddress } from "viem";
3
- import { beforeAll, describe, expect, test } from "vitest";
4
1
  import { accounts } from "@boostxyz/test/accounts";
5
2
  import {
6
3
  type Fixtures,
@@ -8,8 +5,11 @@ import {
8
5
  deployFixtures,
9
6
  freshBoost,
10
7
  } from "@boostxyz/test/helpers";
11
- import { PointsIncentive } from "./PointsIncentive";
8
+ import { loadFixture } from "@nomicfoundation/hardhat-network-helpers";
9
+ import { isAddress, pad, parseEther, zeroAddress } from "viem";
10
+ import { beforeAll, describe, expect, test } from "vitest";
12
11
  import { Roles } from "../Deployable/DeployableTargetWithRBAC";
12
+ import { PointsIncentive } from "./PointsIncentive";
13
13
 
14
14
  let fixtures: Fixtures;
15
15
 
@@ -86,6 +86,54 @@ describe("AllowListIncentive", () => {
86
86
  expect(await allowList.isAllowed(trustedSigner.account)).toBe(true);
87
87
  });
88
88
 
89
+ test("can test claimability", async () => {
90
+ // biome-ignore lint/style/noNonNullAssertion: we know this is defined
91
+ const referrer = accounts.at(1)?.account!;
92
+ // biome-ignore lint/style/noNonNullAssertion: we know this is defined
93
+ const trustedSigner = accounts.at(0)!;
94
+ const allowList = await loadFixture(freshAllowList(fixtures));
95
+ const allowListIncentive = new fixtures.bases.AllowListIncentive(
96
+ defaultOptions,
97
+ {
98
+ allowList: allowList.assertValidAddress(),
99
+ limit: 1n,
100
+ },
101
+ );
102
+ const boost = await freshBoost(fixtures, {
103
+ incentives: [allowListIncentive],
104
+ });
105
+ await allowList.grantManyRoles(
106
+ [allowListIncentive.assertValidAddress()],
107
+ [Roles.MANAGER],
108
+ );
109
+
110
+ const claimant = trustedSigner.account;
111
+ const incentiveData = pad("0xdef456232173821931823712381232131391321934");
112
+
113
+ const claimDataPayload = await boost.validator.encodeClaimData({
114
+ signer: trustedSigner,
115
+ incentiveData,
116
+ chainId: defaultOptions.config.chains[0].id,
117
+ incentiveQuantity: boost.incentives.length,
118
+ claimant,
119
+ boostId: boost.id,
120
+ });
121
+
122
+ expect(await boost.incentives.at(0)!.getRemainingClaimPotential()).toBeGreaterThan(0n)
123
+ expect(await boost.incentives.at(0)!.canBeClaimed()).toBe(true)
124
+
125
+ //await boost.validator.setValidatorCaller(boost.assertValidAddress());
126
+ await fixtures.core.claimIncentive(
127
+ boost.id,
128
+ 0n,
129
+ referrer,
130
+ claimDataPayload,
131
+ { value: parseEther("0.000075"), account: trustedSigner.privateKey },
132
+ );
133
+ expect(await boost.incentives.at(0)!.getRemainingClaimPotential()).toBe(0n)
134
+ expect(await boost.incentives.at(0)!.canBeClaimed()).toBe(false)
135
+ });
136
+
89
137
  test("cannot claim twice", async () => {
90
138
  // biome-ignore lint/style/noNonNullAssertion: we know this is defined
91
139
  const referrer = accounts.at(1)?.account!;
@@ -278,6 +278,34 @@ export class AllowListIncentive extends DeployableTarget<
278
278
  });
279
279
  }
280
280
 
281
+ /**
282
+ * Check if an incentive can potentially be claimed by comparing limit and total claims. Does not take requesting user or underlying allowlist into account.
283
+ *
284
+ * @public
285
+ * @async
286
+ * @param {?ReadParams} [params]
287
+ * @returns {Promise<boolean>} - True if total claims is less than limit
288
+ */
289
+ public async canBeClaimed(params?: ReadParams) {
290
+ return (await this.getRemainingClaimPotential(params)) > 0n;
291
+ }
292
+
293
+ /**
294
+ * Check how many claims remain by comparing limit and total claims. Does not take requesting user or underlying allowlist into account.
295
+ *
296
+ * @public
297
+ * @async
298
+ * @param {?ReadParams} [params]
299
+ * @returns {Promise<bigint>} - True if total claims is less than limit
300
+ */
301
+ public async getRemainingClaimPotential(params?: ReadParams) {
302
+ const [claims, limit] = await Promise.all([
303
+ this.claims(params),
304
+ this.limit(params),
305
+ ]);
306
+ return limit - claims;
307
+ }
308
+
281
309
  /**
282
310
  * @inheritdoc
283
311
  *
@@ -1,7 +1,4 @@
1
1
  import { readMockErc20BalanceOf } from "@boostxyz/evm";
2
- import { loadFixture } from "@nomicfoundation/hardhat-network-helpers";
3
- import { isAddress, isAddressEqual, pad, parseEther, zeroAddress } from "viem";
4
- import { beforeAll, beforeEach, describe, expect, test } from "vitest";
5
2
  import { accounts } from "@boostxyz/test/accounts";
6
3
  import {
7
4
  type BudgetFixtures,
@@ -11,6 +8,9 @@ import {
11
8
  freshBoost,
12
9
  fundBudget,
13
10
  } from "@boostxyz/test/helpers";
11
+ import { loadFixture } from "@nomicfoundation/hardhat-network-helpers";
12
+ import { isAddress, isAddressEqual, pad, parseEther, zeroAddress } from "viem";
13
+ import { beforeAll, beforeEach, describe, expect, test } from "vitest";
14
14
  import { CGDAIncentive } from "./CGDAIncentive";
15
15
 
16
16
  let fixtures: Fixtures, budgets: BudgetFixtures;
@@ -82,6 +82,51 @@ describe("CGDAIncentive", () => {
82
82
  ).toBe(1n);
83
83
  });
84
84
 
85
+ test("can get claimability", async () => {
86
+ // biome-ignore lint/style/noNonNullAssertion: we know this is defined
87
+ const referrer = accounts.at(1)!.account!;
88
+ // biome-ignore lint/style/noNonNullAssertion: we know this is defined
89
+ const trustedSigner = accounts.at(0)!;
90
+ const erc20Incentive = fixtures.core.CGDAIncentive({
91
+ asset: budgets.erc20.assertValidAddress(),
92
+ initialReward: 1n,
93
+ totalBudget: 2n,
94
+ rewardBoost: 1n,
95
+ rewardDecay: 1n,
96
+ manager: budgets.budget.assertValidAddress(),
97
+ });
98
+ const boost = await freshBoost(fixtures, {
99
+ budget: budgets.budget,
100
+ incentives: [erc20Incentive],
101
+ });
102
+
103
+ const claimant = trustedSigner.account;
104
+ const incentiveData = pad("0xdef456232173821931823712381232131391321934");
105
+
106
+ const claimDataPayload = await boost.validator.encodeClaimData({
107
+ signer: trustedSigner,
108
+ incentiveData,
109
+ chainId: defaultOptions.config.chains[0].id,
110
+ incentiveQuantity: boost.incentives.length,
111
+ claimant,
112
+ boostId: boost.id,
113
+ });
114
+
115
+ expect(await boost.incentives.at(0)!.getRemainingClaimPotential()).toBeGreaterThan(0n)
116
+ expect(await boost.incentives.at(0)!.canBeClaimed()).toBe(true)
117
+
118
+ await fixtures.core.claimIncentive(
119
+ boost.id,
120
+ 0n,
121
+ referrer,
122
+ claimDataPayload
123
+ );
124
+
125
+ expect(await boost.incentives.at(0)!.getRemainingClaimPotential()).toBe(0n)
126
+ expect(await boost.incentives.at(0)!.canBeClaimed()).toBe(false)
127
+
128
+ });
129
+
85
130
  test("cannot claim twice", async () => {
86
131
  // biome-ignore lint/style/noNonNullAssertion: we know this is defined
87
132
  const referrer = accounts.at(1)!.account!;
@@ -34,6 +34,7 @@ import {
34
34
  type ReadParams,
35
35
  RegistryType,
36
36
  type WriteParams,
37
+ getErc20Balance,
37
38
  } from '../utils';
38
39
 
39
40
  export { cgdaIncentiveAbi };
@@ -380,6 +381,39 @@ export class CGDAIncentive extends DeployableTarget<
380
381
  });
381
382
  }
382
383
 
384
+ /**
385
+ * Check if any claims remain by comparing the incentive's balance against the current reward. Does not take requesting user's elligibility into account.
386
+ *
387
+ * @public
388
+ * @async
389
+ * @param {?ReadParams} [params]
390
+ * @returns {Promise<boolean>} - True if asset balance minus current reward is greater than 0
391
+ */
392
+ public async canBeClaimed(params?: ReadParams) {
393
+ return (await this.getRemainingClaimPotential(params)) > 0n;
394
+ }
395
+
396
+ /**
397
+ * Check how many claims remain by comparing the incentive's balance against the current reward. Does not take requesting user's elligibility into account.
398
+ *
399
+ * @public
400
+ * @async
401
+ * @param {?ReadParams} [params]
402
+ * @returns {Promise<bigint>} - Asset balance minus current reward
403
+ */
404
+ public async getRemainingClaimPotential(params?: ReadParams) {
405
+ const [currentReward, currentBalance] = await Promise.all([
406
+ this.currentReward(params),
407
+ getErc20Balance(
408
+ this._config,
409
+ await this.asset(),
410
+ this.assertValidAddress(),
411
+ params,
412
+ ),
413
+ ]);
414
+ return currentBalance - currentReward;
415
+ }
416
+
383
417
  /**
384
418
  * Calculates the current reward based on the time since the last claim.
385
419
  * The reward is calculated based on the time since the last claim, the available budget, and the reward parameters. It increases linearly over time in the absence of claims, with each hour adding `rewardBoost` to the current reward, up to the available budget.
@@ -85,6 +85,48 @@ describe("ERC20Incentive", () => {
85
85
  ).toBe(1n);
86
86
  });
87
87
 
88
+ test("can test claimability", async () => {
89
+ // biome-ignore lint/style/noNonNullAssertion: we know this is defined
90
+ const referrer = accounts.at(1)!.account!,
91
+ // biome-ignore lint/style/noNonNullAssertion: we know this is defined
92
+ trustedSigner = accounts.at(0)!;
93
+ const erc20Incentive = fixtures.core.ERC20Incentive({
94
+ asset: budgets.erc20.assertValidAddress(),
95
+ strategy: StrategyType.POOL,
96
+ reward: 1n,
97
+ limit: 1n,
98
+ manager: budgets.budget.assertValidAddress(),
99
+ });
100
+ const boost = await freshBoost(fixtures, {
101
+ budget: budgets.budget,
102
+ incentives: [erc20Incentive],
103
+ });
104
+
105
+ const claimant = trustedSigner.account;
106
+ const incentiveData = erc20Incentive.buildClaimData();
107
+ const claimDataPayload = await boost.validator.encodeClaimData({
108
+ signer: trustedSigner,
109
+ incentiveData,
110
+ chainId: defaultOptions.config.chains[0].id,
111
+ incentiveQuantity: boost.incentives.length,
112
+ claimant,
113
+ boostId: boost.id,
114
+ });
115
+
116
+ expect(await boost.incentives.at(0)!.getRemainingClaimPotential()).toBeGreaterThan(0n)
117
+ expect(await boost.incentives.at(0)!.canBeClaimed()).toBe(true)
118
+
119
+ await fixtures.core.claimIncentive(
120
+ boost.id,
121
+ 0n,
122
+ referrer,
123
+ claimDataPayload,
124
+ );
125
+
126
+ expect(await boost.incentives.at(0)!.getRemainingClaimPotential()).toBe(0n)
127
+ expect(await boost.incentives.at(0)!.canBeClaimed()).toBe(false)
128
+ });
129
+
88
130
  test("cannot claim twice", async () => {
89
131
  // biome-ignore lint/style/noNonNullAssertion: we know this is defined
90
132
  const referrer = accounts.at(1)!.account!;
@@ -439,6 +439,34 @@ export class ERC20Incentive extends DeployableTarget<
439
439
  return strategy === StrategyType.POOL ? limit * reward : reward;
440
440
  }
441
441
 
442
+ /**
443
+ * Check if any claims remain by comparing the incentive's total claims against its limit. Does not take requesting user's elligibility into account.
444
+ *
445
+ * @public
446
+ * @async
447
+ * @param {?ReadParams} [params]
448
+ * @returns {Promise<boolean>} - True if total claims is less than limit
449
+ */
450
+ public async canBeClaimed(params?: ReadParams) {
451
+ return (await this.getRemainingClaimPotential(params)) > 0n;
452
+ }
453
+
454
+ /**
455
+ * Check how many claims remain by comparing the incentive's total claims against its limit. Does not take requesting user's elligibility into account.
456
+ *
457
+ * @public
458
+ * @async
459
+ * @param {?ReadParams} [params]
460
+ * @returns {Promise<bigint>} - True if total claims is less than limit
461
+ */
462
+ public async getRemainingClaimPotential(params?: ReadParams) {
463
+ const [claims, limit] = await Promise.all([
464
+ this.claims(params),
465
+ this.limit(params),
466
+ ]);
467
+ return limit - claims;
468
+ }
469
+
442
470
  /**
443
471
  * @inheritdoc
444
472
  *
@@ -16,8 +16,8 @@ import {
16
16
  zeroAddress
17
17
  } from "viem";
18
18
  import { beforeAll, beforeEach, describe, expect, test } from "vitest";
19
- import { ERC20VariableIncentive } from "./ERC20VariableIncentive";
20
19
  import { decodeClaimData } from "../Validators/Validator";
20
+ import { ERC20VariableIncentive } from "./ERC20VariableIncentive";
21
21
 
22
22
 
23
23
  let fixtures: Fixtures, budgets: BudgetFixtures;
@@ -84,6 +84,46 @@ describe("ERC20VariableIncentive", () => {
84
84
  ).toBe(1n);
85
85
  });
86
86
 
87
+ test("can test claimability", async () => {
88
+ // biome-ignore lint/style/noNonNullAssertion: we know this is defined
89
+ const referrer = accounts.at(1)!.account!,
90
+ // biome-ignore lint/style/noNonNullAssertion: we know this is defined
91
+ trustedSigner = accounts.at(0)!;
92
+ const erc20VariableIncentive = new fixtures.bases.ERC20VariableIncentive(
93
+ defaultOptions,
94
+ {
95
+ asset: budgets.erc20.assertValidAddress(),
96
+ reward: 1n,
97
+ limit: 1n,
98
+ manager: zeroAddress,
99
+ },
100
+ );
101
+ const boost = await freshBoost(fixtures, {
102
+ budget: budgets.budget,
103
+ incentives: [erc20VariableIncentive],
104
+ });
105
+
106
+ const claimant = trustedSigner.account;
107
+ const claimDataPayload = await boost.validator.encodeClaimData({
108
+ signer: trustedSigner,
109
+ incentiveData: erc20VariableIncentive.buildClaimData(parseEther("1")),
110
+ chainId: defaultOptions.config.chains[0].id,
111
+ incentiveQuantity: boost.incentives.length,
112
+ claimant,
113
+ boostId: boost.id,
114
+ });
115
+ expect(await boost.incentives.at(0)!.getRemainingClaimPotential()).toBeGreaterThan(0n)
116
+ expect(await boost.incentives.at(0)!.canBeClaimed()).toBe(true)
117
+ await fixtures.core.claimIncentive(
118
+ boost.id,
119
+ 0n,
120
+ referrer,
121
+ claimDataPayload,
122
+ );
123
+ expect(await boost.incentives.at(0)!.getRemainingClaimPotential()).toBe(0n)
124
+ expect(await boost.incentives.at(0)!.canBeClaimed()).toBe(false)
125
+ });
126
+
87
127
  test("cannot claim twice", async () => {
88
128
  // biome-ignore lint/style/noNonNullAssertion: we know this is defined
89
129
  const referrer = accounts.at(1)!.account!;
@@ -367,6 +367,34 @@ export class ERC20VariableIncentive<
367
367
  return await this.limit(params);
368
368
  }
369
369
 
370
+ /**
371
+ * Check if any claims remain by comparing the incentive's total claimed amount against its limit. Does not take requesting user's elligibility into account.
372
+ *
373
+ * @public
374
+ * @async
375
+ * @param {?ReadParams} [params]
376
+ * @returns {Promise<boolean>} - True if limit minus total claimed is greater than 0
377
+ */
378
+ public async canBeClaimed(params?: ReadParams) {
379
+ return (await this.getRemainingClaimPotential(params)) > 0n;
380
+ }
381
+
382
+ /**
383
+ * Check how much of the underlying asset remains by comparing the the limit against the total amount claimed. Does not take requesting user's elligibility into account.
384
+ *
385
+ * @public
386
+ * @async
387
+ * @param {?ReadParams} [params]
388
+ * @returns {Promise<bigint>} - Limit minus total claimed
389
+ */
390
+ public async getRemainingClaimPotential(params?: ReadParams) {
391
+ const [totalClaimed, limit] = await Promise.all([
392
+ this.totalClaimed(params),
393
+ this.limit(params),
394
+ ]);
395
+ return limit - totalClaimed;
396
+ }
397
+
370
398
  /**
371
399
  * Builds the claim data for the ERC20VariableIncentive.
372
400
  *
@@ -1,7 +1,4 @@
1
1
  import { readPointsBalanceOf, writePointsGrantRoles } from "@boostxyz/evm";
2
- import { loadFixture } from "@nomicfoundation/hardhat-network-helpers";
3
- import { isAddress, pad, parseEther, zeroAddress } from "viem";
4
- import { beforeAll, beforeEach, describe, expect, test } from "vitest";
5
2
  import type { MockPoints } from "@boostxyz/test/MockPoints";
6
3
  import { accounts } from "@boostxyz/test/accounts";
7
4
  import {
@@ -11,6 +8,9 @@ import {
11
8
  freshBoost,
12
9
  freshPoints,
13
10
  } from "@boostxyz/test/helpers";
11
+ import { loadFixture } from "@nomicfoundation/hardhat-network-helpers";
12
+ import { isAddress, pad, parseEther, zeroAddress } from "viem";
13
+ import { beforeAll, beforeEach, describe, expect, test } from "vitest";
14
14
  import { bytes4 } from "../utils";
15
15
  import { PointsIncentive } from "./PointsIncentive";
16
16
 
@@ -81,6 +81,50 @@ describe("PointsIncentive", () => {
81
81
  ).toBe(1n);
82
82
  });
83
83
 
84
+ test("can test claimability", async () => {
85
+ // biome-ignore lint/style/noNonNullAssertion: we know this is defined
86
+ const referrer = accounts.at(1)!.account!;
87
+ // biome-ignore lint/style/noNonNullAssertion: we know this is defined
88
+ const trustedSigner = accounts.at(0)!;
89
+ const pointsIncentive = fixtures.core.PointsIncentive({
90
+ venue: points.assertValidAddress(),
91
+ selector: bytes4("issue(address,uint256)"),
92
+ reward: 1n,
93
+ limit: 1n,
94
+ });
95
+ const boost = await freshBoost(fixtures, {
96
+ incentives: [pointsIncentive],
97
+ });
98
+
99
+ const claimant = trustedSigner.account;
100
+ const incentiveData = pad("0xdef456232173821931823712381232131391321934");
101
+ const claimDataPayload = await boost.validator.encodeClaimData({
102
+ signer: trustedSigner,
103
+ incentiveData,
104
+ chainId: defaultOptions.config.chains[0].id,
105
+ incentiveQuantity: boost.incentives.length,
106
+ claimant,
107
+ boostId: boost.id,
108
+ });
109
+
110
+ expect(await boost.incentives.at(0)!.getRemainingClaimPotential()).toBeGreaterThan(0n)
111
+ expect(await boost.incentives.at(0)!.canBeClaimed()).toBe(true)
112
+
113
+ await writePointsGrantRoles(defaultOptions.config, {
114
+ address: points.assertValidAddress(),
115
+ args: [pointsIncentive.assertValidAddress(), 2n],
116
+ account: defaultOptions.account,
117
+ });
118
+ await fixtures.core.claimIncentive(
119
+ boost.id,
120
+ 0n,
121
+ referrer,
122
+ claimDataPayload,
123
+ );
124
+ expect(await boost.incentives.at(0)!.getRemainingClaimPotential()).toBe(0n)
125
+ expect(await boost.incentives.at(0)!.canBeClaimed()).toBe(false)
126
+ });
127
+
84
128
  test("cannot claim twice", async () => {
85
129
  const reward = 1n;
86
130
  // biome-ignore lint/style/noNonNullAssertion: we know this is defined
@@ -296,6 +296,34 @@ export class PointsIncentive extends DeployableTarget<
296
296
  });
297
297
  }
298
298
 
299
+ /**
300
+ * Check if any claims remain by comparing the incentive's total claims against its limit. Does not take requesting user's elligibility into account.
301
+ *
302
+ * @public
303
+ * @async
304
+ * @param {?ReadParams} [params]
305
+ * @returns {Promise<boolean>} - True if total claims is less than limit
306
+ */
307
+ public async canBeClaimed(params?: ReadParams) {
308
+ return (await this.getRemainingClaimPotential(params)) > 0n;
309
+ }
310
+
311
+ /**
312
+ * Check how many claims remain by comparing the incentive's total claims against its limit. Does not take requesting user's elligibility into account.
313
+ *
314
+ * @public
315
+ * @async
316
+ * @param {?ReadParams} [params]
317
+ * @returns {Promise<bigint>} - True if total claims is less than limit
318
+ */
319
+ public async getRemainingClaimPotential(params?: ReadParams) {
320
+ const [claims, limit] = await Promise.all([
321
+ this.claims(params),
322
+ this.limit(params),
323
+ ]);
324
+ return limit - claims;
325
+ }
326
+
299
327
  /**
300
328
  * @inheritdoc
301
329
  *
package/src/index.ts CHANGED
@@ -21,6 +21,7 @@ export * from './Budgets/Budget';
21
21
  // export * from './Budgets/SimpleBudget';
22
22
  // export * from './Budgets/VestingBudget';
23
23
  export * from './Budgets/ManagedBudget';
24
+ export * from './Budgets/ManagedBudgetWithFees';
24
25
 
25
26
  // Deployable
26
27
 
package/src/utils.ts CHANGED
@@ -5,6 +5,7 @@ import {
5
5
  type WatchContractEventParameters,
6
6
  getAccount,
7
7
  getChainId,
8
+ readContract,
8
9
  waitForTransactionReceipt,
9
10
  } from '@wagmi/core';
10
11
  import type { ExtractAbiEvent } from 'abitype';
@@ -255,3 +256,48 @@ export function assertValidAddressByChainId(
255
256
  // biome-ignore lint/style/noNonNullAssertion: this type should be narrowed by the above statement but isn't?
256
257
  return { chainId, address: addressByChainId[chainId]! };
257
258
  }
259
+
260
+ /**
261
+ * Check an ERC20's balance for a given asset and
262
+ *
263
+ * @public
264
+ * @async
265
+ * @param {Config} [config]
266
+ * @param {Address} [asset]
267
+ * @param {Address} [owner]
268
+ * @param {?ReadParams} [params]
269
+ * @returns {Promise<bigint>} - The erc20 balance
270
+ */
271
+ export async function getErc20Balance(
272
+ config: Config,
273
+ asset: Address,
274
+ owner: Address,
275
+ params?: ReadParams,
276
+ ) {
277
+ return await readContract(config, {
278
+ ...params,
279
+ functionName: 'balanceOf',
280
+ address: asset,
281
+ args: [owner],
282
+ abi: [
283
+ {
284
+ constant: true,
285
+ inputs: [
286
+ {
287
+ name: '_owner',
288
+ type: 'address',
289
+ },
290
+ ],
291
+ name: 'balanceOf',
292
+ outputs: [
293
+ {
294
+ name: 'balance',
295
+ type: 'uint256',
296
+ },
297
+ ],
298
+ stateMutability: 'view',
299
+ type: 'function',
300
+ },
301
+ ],
302
+ });
303
+ }
@@ -1,2 +0,0 @@
1
- "use strict";const e="0xc2c281ec",n="0x53cf8555",t="0x7cc1d5bb",i="0x52b8e45c",c="0x90318111",A="0x7687b0ed",a="0x5fbfaa4e",o="0x0d36a40d",s="0xb8ce7b22",l="0x1392d798",v="0x3d30a22c";exports.AAllowListIncentive=e;exports.ACGDAIncentive=n;exports.AERC20Incentive=t;exports.AERC20VariableCriteriaIncentive=i;exports.AERC20VariableIncentive=c;exports.AEventAction=A;exports.AManagedBudget=a;exports.APointsIncentive=o;exports.ASignerValidator=s;exports.ASimpleAllowList=l;exports.ASimpleDenyList=v;
2
- //# sourceMappingURL=componentInterfaces-BQw7DH-m.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"componentInterfaces-BQw7DH-m.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -1,15 +0,0 @@
1
- const e = "0xc2c281ec", n = "0x53cf8555", c = "0x7cc1d5bb", t = "0x52b8e45c", s = "0x90318111", a = "0x7687b0ed", i = "0x5fbfaa4e", o = "0x0d36a40d", A = "0xb8ce7b22", x = "0x1392d798", b = "0x3d30a22c";
2
- export {
3
- a as A,
4
- i as a,
5
- o as b,
6
- c,
7
- e as d,
8
- n as e,
9
- s as f,
10
- t as g,
11
- A as h,
12
- x as i,
13
- b as j
14
- };
15
- //# sourceMappingURL=componentInterfaces-C0vuWQlh.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"componentInterfaces-C0vuWQlh.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
@@ -1,2 +0,0 @@
1
- "use strict";const e={10:"0x5AA51DCC8F3bdeD3a270613d3C9682EA10062782",8453:"0x5AA51DCC8F3bdeD3a270613d3C9682EA10062782",42161:"0x5AA51DCC8F3bdeD3a270613d3C9682EA10062782",84532:"0x5AA51DCC8F3bdeD3a270613d3C9682EA10062782",11155111:"0x5AA51DCC8F3bdeD3a270613d3C9682EA10062782"},D={10:"0xE2D376c791cAA498b86ebfc3C87121112Fd8Cd5b",8453:"0xE2D376c791cAA498b86ebfc3C87121112Fd8Cd5b",42161:"0xE2D376c791cAA498b86ebfc3C87121112Fd8Cd5b",84532:"0xE2D376c791cAA498b86ebfc3C87121112Fd8Cd5b",11155111:"0xE2D376c791cAA498b86ebfc3C87121112Fd8Cd5b"},C={10:"0x694c04324C2F4D97eBF98FaC633DF54E7A95334f",8453:"0x694c04324C2F4D97eBF98FaC633DF54E7A95334f",42161:"0x694c04324C2F4D97eBF98FaC633DF54E7A95334f",84532:"0x694c04324C2F4D97eBF98FaC633DF54E7A95334f",11155111:"0x694c04324C2F4D97eBF98FaC633DF54E7A95334f"},b={10:"0x2B5E78665C7e79791078dfFE94f04c1d1C42558F",8453:"0x2B5E78665C7e79791078dfFE94f04c1d1C42558F",42161:"0x2B5E78665C7e79791078dfFE94f04c1d1C42558F",84532:"0x2B5E78665C7e79791078dfFE94f04c1d1C42558F",11155111:"0x2B5E78665C7e79791078dfFE94f04c1d1C42558F"},B={10:"0x449094B4fb2A9Bf25dd9876E90ab2310aa386697",8453:"0x449094B4fb2A9Bf25dd9876E90ab2310aa386697",42161:"0x449094B4fb2A9Bf25dd9876E90ab2310aa386697",84532:"0x449094B4fb2A9Bf25dd9876E90ab2310aa386697",11155111:"0x449094B4fb2A9Bf25dd9876E90ab2310aa386697"},A={10:"0x96b23C5B81FEA6Da7f12B70050D4C4f76d3a9D0D",8453:"0x96b23C5B81FEA6Da7f12B70050D4C4f76d3a9D0D",42161:"0x96b23C5B81FEA6Da7f12B70050D4C4f76d3a9D0D",84532:"0x96b23C5B81FEA6Da7f12B70050D4C4f76d3a9D0D",11155111:"0x96b23C5B81FEA6Da7f12B70050D4C4f76d3a9D0D"},F={10:"0x8Db3E5226FD46F14E666954F65557539e7025136",8453:"0x8Db3E5226FD46F14E666954F65557539e7025136",42161:"0x8Db3E5226FD46F14E666954F65557539e7025136",84532:"0x8Db3E5226FD46F14E666954F65557539e7025136",11155111:"0x8Db3E5226FD46F14E666954F65557539e7025136"},a={10:"0x674f6b02e0B1159D61DFFCEe096776fd3B2bb7C1",8453:"0x674f6b02e0B1159D61DFFCEe096776fd3B2bb7C1",42161:"0x674f6b02e0B1159D61DFFCEe096776fd3B2bb7C1",84532:"0x674f6b02e0B1159D61DFFCEe096776fd3B2bb7C1",11155111:"0x674f6b02e0B1159D61DFFCEe096776fd3B2bb7C1"},E={10:"0xC9fB769A6A1e71663E85AE30CCfE97bf67B6d42F",8453:"0xC9fB769A6A1e71663E85AE30CCfE97bf67B6d42F",42161:"0xC9fB769A6A1e71663E85AE30CCfE97bf67B6d42F",84532:"0xC9fB769A6A1e71663E85AE30CCfE97bf67B6d42F",11155111:"0xC9fB769A6A1e71663E85AE30CCfE97bf67B6d42F"},f={10:"0x817aD27DF5a20a995bCD87962A8B32eB60c6c2D9",8453:"0x817aD27DF5a20a995bCD87962A8B32eB60c6c2D9",42161:"0x817aD27DF5a20a995bCD87962A8B32eB60c6c2D9",84532:"0x817aD27DF5a20a995bCD87962A8B32eB60c6c2D9",11155111:"0x817aD27DF5a20a995bCD87962A8B32eB60c6c2D9"},c={10:"0x72D733558473Cb3e9A66B25B99cb9810111f5E11",8453:"0x72D733558473Cb3e9A66B25B99cb9810111f5E11",42161:"0x72D733558473Cb3e9A66B25B99cb9810111f5E11",84532:"0x72D733558473Cb3e9A66B25B99cb9810111f5E11",11155111:"0x72D733558473Cb3e9A66B25B99cb9810111f5E11"},x={10:"0x5aE607016b0a742D0eF3aDD7B3257881bA383CB3",8453:"0x5aE607016b0a742D0eF3aDD7B3257881bA383CB3",42161:"0x5aE607016b0a742D0eF3aDD7B3257881bA383CB3",84532:"0x5aE607016b0a742D0eF3aDD7B3257881bA383CB3",11155111:"0x5aE607016b0a742D0eF3aDD7B3257881bA383CB3"},d={10:"0x5b0eD712b54775584cbB28fe7954e854781AA805",8453:"0x5b0eD712b54775584cbB28fe7954e854781AA805",42161:"0x5b0eD712b54775584cbB28fe7954e854781AA805",84532:"0x5b0eD712b54775584cbB28fe7954e854781AA805",11155111:"0x5b0eD712b54775584cbB28fe7954e854781AA805"};exports.AllowListIncentive=e;exports.BoostCore=D;exports.BoostRegistry=C;exports.CGDAIncentive=b;exports.ERC20Incentive=B;exports.ERC20VariableCriteriaIncentive=A;exports.ERC20VariableIncentive=F;exports.EventAction=a;exports.ManagedBudget=E;exports.PointsIncentive=f;exports.SignerValidator=c;exports.SimpleAllowList=x;exports.SimpleDenyList=d;
2
- //# sourceMappingURL=deployments--f75Pthq.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"deployments--f75Pthq.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- {"version":3,"file":"deployments-BdPDIh-i.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}