@boostxyz/sdk 0.0.0-alpha.2 → 0.0.0-alpha.20
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.
- package/dist/Actions/Action.cjs +2 -1
- package/dist/Actions/Action.cjs.map +1 -0
- package/dist/Actions/Action.d.ts +1 -1
- package/dist/Actions/Action.d.ts.map +1 -1
- package/dist/Actions/Action.js +14 -12
- package/dist/Actions/Action.js.map +1 -0
- package/dist/Actions/ContractAction.d.ts +57 -14
- package/dist/Actions/ContractAction.d.ts.map +1 -1
- package/dist/Actions/ERC721MintAction.d.ts +50 -23
- package/dist/Actions/ERC721MintAction.d.ts.map +1 -1
- package/dist/Actions/EventAction.cjs +2 -1
- package/dist/Actions/EventAction.cjs.map +1 -0
- package/dist/Actions/EventAction.d.ts +405 -36
- package/dist/Actions/EventAction.d.ts.map +1 -1
- package/dist/Actions/EventAction.js +15 -209
- package/dist/Actions/EventAction.js.map +1 -0
- package/dist/AllowLists/AllowList.cjs +2 -1
- package/dist/AllowLists/AllowList.cjs.map +1 -0
- package/dist/AllowLists/AllowList.d.ts +6 -5
- package/dist/AllowLists/AllowList.d.ts.map +1 -1
- package/dist/AllowLists/AllowList.js +46 -22
- package/dist/AllowLists/AllowList.js.map +1 -0
- package/dist/AllowLists/OpenAllowList.d.ts +423 -0
- package/dist/AllowLists/OpenAllowList.d.ts.map +1 -0
- package/dist/AllowLists/SimpleAllowList.cjs +2 -1
- package/dist/AllowLists/SimpleAllowList.cjs.map +1 -0
- package/dist/AllowLists/SimpleAllowList.d.ts +124 -40
- package/dist/AllowLists/SimpleAllowList.d.ts.map +1 -1
- package/dist/AllowLists/SimpleAllowList.js +77 -77
- package/dist/AllowLists/SimpleAllowList.js.map +1 -0
- package/dist/AllowLists/SimpleDenyList.cjs +2 -1
- package/dist/AllowLists/SimpleDenyList.cjs.map +1 -0
- package/dist/AllowLists/SimpleDenyList.d.ts +234 -13
- package/dist/AllowLists/SimpleDenyList.d.ts.map +1 -1
- package/dist/AllowLists/SimpleDenyList.js +12 -200
- package/dist/AllowLists/SimpleDenyList.js.map +1 -0
- package/dist/Auth/Auth.cjs +1 -0
- package/dist/Auth/Auth.cjs.map +1 -0
- package/dist/Auth/Auth.js +1 -0
- package/dist/Auth/Auth.js.map +1 -0
- package/dist/Auth/PassthroughAuth.cjs +2 -1
- package/dist/Auth/PassthroughAuth.cjs.map +1 -0
- package/dist/Auth/PassthroughAuth.js +5 -4
- package/dist/Auth/PassthroughAuth.js.map +1 -0
- package/dist/Boost.cjs +2 -1
- package/dist/Boost.cjs.map +1 -0
- package/dist/Boost.d.ts +111 -1
- package/dist/Boost.d.ts.map +1 -1
- package/dist/Boost.js +140 -5
- package/dist/Boost.js.map +1 -0
- package/dist/BoostCore-3-U1xTQN.cjs +3 -0
- package/dist/BoostCore-3-U1xTQN.cjs.map +1 -0
- package/dist/BoostCore-DVGBUr2y.js +1477 -0
- package/dist/BoostCore-DVGBUr2y.js.map +1 -0
- package/dist/BoostCore.cjs +2 -2
- package/dist/BoostCore.cjs.map +1 -0
- package/dist/BoostCore.d.ts +166 -43
- package/dist/BoostCore.d.ts.map +1 -1
- package/dist/BoostCore.js +30 -1103
- package/dist/BoostCore.js.map +1 -0
- package/dist/BoostRegistry.cjs +2 -1
- package/dist/BoostRegistry.cjs.map +1 -0
- package/dist/BoostRegistry.d.ts +64 -23
- package/dist/BoostRegistry.d.ts.map +1 -1
- package/dist/BoostRegistry.js +162 -88
- package/dist/BoostRegistry.js.map +1 -0
- package/dist/Budgets/Budget.cjs +2 -1
- package/dist/Budgets/Budget.cjs.map +1 -0
- package/dist/Budgets/Budget.d.ts +1 -1
- package/dist/Budgets/Budget.d.ts.map +1 -1
- package/dist/Budgets/Budget.js +15 -13
- package/dist/Budgets/Budget.js.map +1 -0
- package/dist/Budgets/ManagedBudget.cjs +2 -1
- package/dist/Budgets/ManagedBudget.cjs.map +1 -0
- package/dist/Budgets/ManagedBudget.d.ts +78 -188
- package/dist/Budgets/ManagedBudget.d.ts.map +1 -1
- package/dist/Budgets/ManagedBudget.js +86 -286
- package/dist/Budgets/ManagedBudget.js.map +1 -0
- package/dist/Budgets/VestingBudget.d.ts +243 -87
- package/dist/Budgets/VestingBudget.d.ts.map +1 -1
- package/dist/Deployable/Contract.cjs +2 -1
- package/dist/Deployable/Contract.cjs.map +1 -0
- package/dist/Deployable/Contract.d.ts +4 -5
- package/dist/Deployable/Contract.d.ts.map +1 -1
- package/dist/Deployable/Contract.js +7 -8
- package/dist/Deployable/Contract.js.map +1 -0
- package/dist/Deployable/Deployable.cjs +1 -0
- package/dist/Deployable/Deployable.cjs.map +1 -0
- package/dist/Deployable/Deployable.d.ts +9 -3
- package/dist/Deployable/Deployable.d.ts.map +1 -1
- package/dist/Deployable/Deployable.js +10 -5
- package/dist/Deployable/Deployable.js.map +1 -0
- package/dist/Deployable/DeployableTarget.cjs +2 -1
- package/dist/Deployable/DeployableTarget.cjs.map +1 -0
- package/dist/Deployable/DeployableTarget.d.ts +16 -15
- package/dist/Deployable/DeployableTarget.d.ts.map +1 -1
- package/dist/Deployable/DeployableTarget.js +49 -42
- package/dist/Deployable/DeployableTarget.js.map +1 -0
- package/dist/Deployable/DeployableTargetWithRBAC.cjs +2 -0
- package/dist/Deployable/DeployableTargetWithRBAC.cjs.map +1 -0
- package/dist/Deployable/DeployableTargetWithRBAC.d.ts +179 -0
- package/dist/Deployable/DeployableTargetWithRBAC.d.ts.map +1 -0
- package/dist/Deployable/DeployableTargetWithRBAC.js +222 -0
- package/dist/Deployable/DeployableTargetWithRBAC.js.map +1 -0
- package/dist/EventAction-CIPqmAoP.js +1450 -0
- package/dist/EventAction-CIPqmAoP.js.map +1 -0
- package/dist/EventAction-d-oeqZQs.cjs +2 -0
- package/dist/EventAction-d-oeqZQs.cjs.map +1 -0
- package/dist/Incentive-Bp8Sez7M.js +298 -0
- package/dist/Incentive-Bp8Sez7M.js.map +1 -0
- package/dist/Incentive-Djnzseoj.cjs +2 -0
- package/dist/Incentive-Djnzseoj.cjs.map +1 -0
- package/dist/Incentives/AllowListIncentive.cjs +2 -1
- package/dist/Incentives/AllowListIncentive.cjs.map +1 -0
- package/dist/Incentives/AllowListIncentive.d.ts +49 -19
- package/dist/Incentives/AllowListIncentive.d.ts.map +1 -1
- package/dist/Incentives/AllowListIncentive.js +50 -34
- package/dist/Incentives/AllowListIncentive.js.map +1 -0
- package/dist/Incentives/CGDAIncentive.cjs +2 -1
- package/dist/Incentives/CGDAIncentive.cjs.map +1 -0
- package/dist/Incentives/CGDAIncentive.d.ts +118 -22
- package/dist/Incentives/CGDAIncentive.d.ts.map +1 -1
- package/dist/Incentives/CGDAIncentive.js +67 -42
- package/dist/Incentives/CGDAIncentive.js.map +1 -0
- package/dist/Incentives/ERC1155Incentive.d.ts +99 -38
- package/dist/Incentives/ERC1155Incentive.d.ts.map +1 -1
- package/dist/Incentives/ERC20Incentive.cjs +2 -1
- package/dist/Incentives/ERC20Incentive.cjs.map +1 -0
- package/dist/Incentives/ERC20Incentive.d.ts +73 -29
- package/dist/Incentives/ERC20Incentive.d.ts.map +1 -1
- package/dist/Incentives/ERC20Incentive.js +71 -48
- package/dist/Incentives/ERC20Incentive.js.map +1 -0
- package/dist/Incentives/ERC20VariableCriteriaIncentive.d.ts +523 -0
- package/dist/Incentives/ERC20VariableCriteriaIncentive.d.ts.map +1 -0
- package/dist/Incentives/ERC20VariableIncentive.d.ts +65 -28
- package/dist/Incentives/ERC20VariableIncentive.d.ts.map +1 -1
- package/dist/Incentives/Incentive.cjs +2 -1
- package/dist/Incentives/Incentive.cjs.map +1 -0
- package/dist/Incentives/Incentive.d.ts +4 -7
- package/dist/Incentives/Incentive.d.ts.map +1 -1
- package/dist/Incentives/Incentive.js +17 -278
- package/dist/Incentives/Incentive.js.map +1 -0
- package/dist/Incentives/PointsIncentive.cjs +2 -1
- package/dist/Incentives/PointsIncentive.cjs.map +1 -0
- package/dist/Incentives/PointsIncentive.d.ts +65 -21
- package/dist/Incentives/PointsIncentive.d.ts.map +1 -1
- package/dist/Incentives/PointsIncentive.js +57 -36
- package/dist/Incentives/PointsIncentive.js.map +1 -0
- package/dist/SimpleDenyList-BwfNjRsg.cjs +2 -0
- package/dist/SimpleDenyList-BwfNjRsg.cjs.map +1 -0
- package/dist/SimpleDenyList-Cn5WpNn0.js +132 -0
- package/dist/SimpleDenyList-Cn5WpNn0.js.map +1 -0
- package/dist/Validators/SignerValidator.cjs +2 -1
- package/dist/Validators/SignerValidator.cjs.map +1 -0
- package/dist/Validators/SignerValidator.d.ts +310 -17
- package/dist/Validators/SignerValidator.d.ts.map +1 -1
- package/dist/Validators/SignerValidator.js +165 -36
- package/dist/Validators/SignerValidator.js.map +1 -0
- package/dist/Validators/Validator.cjs +2 -1
- package/dist/Validators/Validator.cjs.map +1 -0
- package/dist/Validators/Validator.d.ts +2 -2
- package/dist/Validators/Validator.d.ts.map +1 -1
- package/dist/Validators/Validator.js +12 -10
- package/dist/Validators/Validator.js.map +1 -0
- package/dist/claiming.cjs +2 -0
- package/dist/claiming.cjs.map +1 -0
- package/dist/claiming.d.ts +43 -0
- package/dist/claiming.d.ts.map +1 -0
- package/dist/claiming.js +17 -0
- package/dist/claiming.js.map +1 -0
- package/dist/componentInterfaces-D09mhzxO.cjs +2 -0
- package/dist/componentInterfaces-D09mhzxO.cjs.map +1 -0
- package/dist/componentInterfaces-RXBMI5yH.js +14 -0
- package/dist/componentInterfaces-RXBMI5yH.js.map +1 -0
- package/dist/deployments-BM42vImE.js +43 -0
- package/dist/deployments-BM42vImE.js.map +1 -0
- package/dist/deployments-CMdF5uEC.cjs +2 -0
- package/dist/deployments-CMdF5uEC.cjs.map +1 -0
- package/dist/deployments.json +41 -0
- package/dist/errors.cjs +2 -1
- package/dist/errors.cjs.map +1 -0
- package/dist/errors.d.ts +403 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +285 -39
- package/dist/errors.js.map +1 -0
- package/dist/generated-B0tk-c9b.cjs +3 -0
- package/dist/generated-B0tk-c9b.cjs.map +1 -0
- package/dist/{generated-x_abr3Yv.js → generated-B7VaSah4.js} +2058 -2541
- package/dist/generated-B7VaSah4.js.map +1 -0
- package/dist/index.cjs +2 -1
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +10 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +143 -1353
- package/dist/index.js.map +1 -0
- package/dist/transfers.cjs +2 -0
- package/dist/transfers.cjs.map +1 -0
- package/dist/transfers.d.ts +198 -0
- package/dist/transfers.d.ts.map +1 -0
- package/dist/transfers.js +84 -0
- package/dist/transfers.js.map +1 -0
- package/dist/utils.cjs +2 -1
- package/dist/utils.cjs.map +1 -0
- package/dist/utils.d.ts +26 -1350
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +38 -636
- package/dist/utils.js.map +1 -0
- package/package.json +37 -11
- package/src/Actions/Action.test.ts +79 -0
- package/src/Actions/Action.ts +61 -0
- package/src/Actions/ContractAction.test.ts +197 -0
- package/src/Actions/ContractAction.ts +300 -0
- package/src/Actions/ERC721MintAction.test.ts +112 -0
- package/src/Actions/ERC721MintAction.ts +291 -0
- package/src/Actions/EventAction.test.ts +787 -0
- package/src/Actions/EventAction.ts +1214 -0
- package/src/AllowLists/AllowList.test.ts +64 -0
- package/src/AllowLists/AllowList.ts +62 -0
- package/src/AllowLists/OpenAllowList.test.ts +40 -0
- package/src/AllowLists/OpenAllowList.ts +45 -0
- package/src/AllowLists/SimpleAllowList.test.ts +52 -0
- package/src/AllowLists/SimpleAllowList.ts +262 -0
- package/src/AllowLists/SimpleDenyList.test.ts +52 -0
- package/src/AllowLists/SimpleDenyList.ts +250 -0
- package/src/Auth/Auth.ts +11 -0
- package/src/Auth/PassthroughAuth.test.ts +12 -0
- package/src/Auth/PassthroughAuth.ts +80 -0
- package/src/Boost.ts +309 -0
- package/src/BoostCore.test.ts +827 -0
- package/src/BoostCore.ts +1447 -0
- package/src/BoostRegistry.ts +543 -0
- package/src/Budgets/Budget.test.ts +27 -0
- package/src/Budgets/Budget.ts +60 -0
- package/src/Budgets/ManagedBudget.test.ts +217 -0
- package/src/Budgets/ManagedBudget.ts +534 -0
- package/src/Budgets/VestingBudget.test.ts +123 -0
- package/src/Budgets/VestingBudget.ts +530 -0
- package/src/Deployable/Contract.ts +228 -0
- package/src/Deployable/Deployable.ts +250 -0
- package/src/Deployable/DeployableTarget.ts +234 -0
- package/src/Deployable/DeployableTargetWithRBAC.ts +323 -0
- package/src/Incentives/AllowListIncentive.test.ts +143 -0
- package/src/Incentives/AllowListIncentive.ts +336 -0
- package/src/Incentives/CGDAIncentive.test.ts +132 -0
- package/src/Incentives/CGDAIncentive.ts +470 -0
- package/src/Incentives/ERC1155Incentive.test.ts +87 -0
- package/src/Incentives/ERC1155Incentive.ts +465 -0
- package/src/Incentives/ERC20Incentive.test.ts +130 -0
- package/src/Incentives/ERC20Incentive.ts +484 -0
- package/src/Incentives/ERC20VariableCriteriaIncentive.test.ts +184 -0
- package/src/Incentives/ERC20VariableCriteriaIncentive.ts +309 -0
- package/src/Incentives/ERC20VariableIncentive.test.ts +136 -0
- package/src/Incentives/ERC20VariableIncentive.ts +422 -0
- package/src/Incentives/Incentive.test.ts +92 -0
- package/src/Incentives/Incentive.ts +86 -0
- package/src/Incentives/PointsIncentive.test.ts +139 -0
- package/src/Incentives/PointsIncentive.ts +367 -0
- package/src/Validators/SignerValidator.test.ts +159 -0
- package/src/Validators/SignerValidator.ts +683 -0
- package/src/Validators/Validator.test.ts +21 -0
- package/src/Validators/Validator.ts +55 -0
- package/src/claiming.ts +56 -0
- package/src/errors.ts +844 -0
- package/src/index.test.ts +122 -0
- package/src/index.ts +58 -0
- package/src/transfers.ts +284 -0
- package/src/utils.test.ts +44 -0
- package/src/utils.ts +247 -0
- package/dist/Budgets/SimpleBudget.d.ts +0 -793
- package/dist/Budgets/SimpleBudget.d.ts.map +0 -1
- package/dist/generated-BaaleHW-.cjs +0 -2
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
import {
|
|
2
|
+
erc20VariableCriteriaIncentiveAbi,
|
|
3
|
+
readErc20VariableCriteriaIncentiveGetIncentiveCriteria,
|
|
4
|
+
} from '@boostxyz/evm';
|
|
5
|
+
import { bytecode } from '@boostxyz/evm/artifacts/contracts/incentives/ERC20VariableCriteriaIncentive.sol/ERC20VariableCriteriaIncentive.json';
|
|
6
|
+
import events from '@boostxyz/signatures/events';
|
|
7
|
+
import functions from '@boostxyz/signatures/functions';
|
|
8
|
+
import { getTransaction, getTransactionReceipt } from '@wagmi/core';
|
|
9
|
+
import {
|
|
10
|
+
type AbiEvent,
|
|
11
|
+
type AbiFunction,
|
|
12
|
+
type Address,
|
|
13
|
+
type Hex,
|
|
14
|
+
type Log,
|
|
15
|
+
decodeFunctionData,
|
|
16
|
+
encodeAbiParameters,
|
|
17
|
+
parseEventLogs,
|
|
18
|
+
} from 'viem';
|
|
19
|
+
import { ERC20VariableCriteriaIncentive as ERC20VariableCriteriaIncentiveBases } from '../../dist/deployments.json';
|
|
20
|
+
import { SignatureType } from '../Actions/EventAction';
|
|
21
|
+
import type {
|
|
22
|
+
DeployableOptions,
|
|
23
|
+
GenericDeployableParams,
|
|
24
|
+
} from '../Deployable/Deployable';
|
|
25
|
+
import { DeployableTarget } from '../Deployable/DeployableTarget';
|
|
26
|
+
import {
|
|
27
|
+
DecodedArgsError,
|
|
28
|
+
FieldActionValidationError,
|
|
29
|
+
IncentiveCriteriaNotFoundError,
|
|
30
|
+
InvalidCriteriaTypeError,
|
|
31
|
+
NoMatchingLogsError,
|
|
32
|
+
} from '../errors';
|
|
33
|
+
import type { ReadParams } from '../utils';
|
|
34
|
+
import { ERC20VariableIncentive } from './ERC20VariableIncentive';
|
|
35
|
+
|
|
36
|
+
export interface ERC20VariableCriteriaIncentivePayload {
|
|
37
|
+
/**
|
|
38
|
+
* The address of the incentivized asset.
|
|
39
|
+
*
|
|
40
|
+
* @type {Address}
|
|
41
|
+
*/
|
|
42
|
+
asset: Address;
|
|
43
|
+
/**
|
|
44
|
+
* The amount of the asset to distribute as reward.
|
|
45
|
+
*
|
|
46
|
+
* @type {bigint}
|
|
47
|
+
*/
|
|
48
|
+
reward: bigint;
|
|
49
|
+
/**
|
|
50
|
+
* The total spending limit of the asset that will be distributed.
|
|
51
|
+
*
|
|
52
|
+
* @type {bigint}
|
|
53
|
+
*/
|
|
54
|
+
limit: bigint;
|
|
55
|
+
/**
|
|
56
|
+
* The criteria for the incentive that determines how the reward is distributed.
|
|
57
|
+
*
|
|
58
|
+
* @type {IncentiveCriteria}
|
|
59
|
+
*/
|
|
60
|
+
criteria: IncentiveCriteria;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export interface IncentiveCriteria {
|
|
64
|
+
/**
|
|
65
|
+
* The type of criteria used, either function signature or event signature.
|
|
66
|
+
*
|
|
67
|
+
* @type {SignatureType}
|
|
68
|
+
*/
|
|
69
|
+
criteriaType: SignatureType;
|
|
70
|
+
/**
|
|
71
|
+
* The function or event signature used for criteria matching.
|
|
72
|
+
*
|
|
73
|
+
* @type {Hex}
|
|
74
|
+
*/
|
|
75
|
+
signature: Hex;
|
|
76
|
+
/**
|
|
77
|
+
* The index of the field from where the scalar value is extracted.
|
|
78
|
+
*
|
|
79
|
+
* @type {number}
|
|
80
|
+
*/
|
|
81
|
+
fieldIndex: number;
|
|
82
|
+
/**
|
|
83
|
+
* The address of the contract where the event/function is called/emitted.
|
|
84
|
+
*
|
|
85
|
+
* @type {Address}
|
|
86
|
+
*/
|
|
87
|
+
targetContract: Address;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export interface ReadIncentiveCriteriaParams
|
|
91
|
+
extends ReadParams<
|
|
92
|
+
typeof erc20VariableCriteriaIncentiveAbi,
|
|
93
|
+
'getIncentiveCriteria'
|
|
94
|
+
> {}
|
|
95
|
+
|
|
96
|
+
export interface GetIncentiveScalarParams {
|
|
97
|
+
hash: Hex;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Extended ERC20 Variable Criteria Incentive class that fetches incentive criteria and scalar
|
|
102
|
+
*/
|
|
103
|
+
export class ERC20VariableCriteriaIncentive extends DeployableTarget<
|
|
104
|
+
ERC20VariableCriteriaIncentivePayload,
|
|
105
|
+
typeof erc20VariableCriteriaIncentiveAbi
|
|
106
|
+
> {
|
|
107
|
+
public override readonly abi = erc20VariableCriteriaIncentiveAbi;
|
|
108
|
+
/**
|
|
109
|
+
* @inheritdoc
|
|
110
|
+
*
|
|
111
|
+
* @public
|
|
112
|
+
* @static
|
|
113
|
+
* @type {Record<number, Address>}
|
|
114
|
+
*/
|
|
115
|
+
public static override bases: Record<number, Address> = {
|
|
116
|
+
...(ERC20VariableCriteriaIncentiveBases as Record<number, Address>),
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
*Functions from the ERC20VariableIncentive contract
|
|
121
|
+
*/
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Fetches the IncentiveCriteria struct from the contract
|
|
125
|
+
*
|
|
126
|
+
* @returns {Promise<IncentiveCriteria>} Incentive criteria structure
|
|
127
|
+
* @throws {IncentiveCriteriaNotFoundError}
|
|
128
|
+
*/
|
|
129
|
+
public async getIncentiveCriteria(): Promise<IncentiveCriteria> {
|
|
130
|
+
try {
|
|
131
|
+
const criteria =
|
|
132
|
+
await readErc20VariableCriteriaIncentiveGetIncentiveCriteria(
|
|
133
|
+
this._config,
|
|
134
|
+
{
|
|
135
|
+
address: this.assertValidAddress(),
|
|
136
|
+
},
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
return criteria;
|
|
140
|
+
} catch (e) {
|
|
141
|
+
throw new IncentiveCriteriaNotFoundError(e as Error);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Fetches the incentive scalar from a transaction hash
|
|
147
|
+
*
|
|
148
|
+
* @param {GetIncentiveScalarParams} params
|
|
149
|
+
* @returns {Promise<bigint>}
|
|
150
|
+
* @throws {InvalidCriteriaTypeError | NoMatchingLogsError | DecodedArgsError}
|
|
151
|
+
*/
|
|
152
|
+
public async getIncentiveScalar({
|
|
153
|
+
hash,
|
|
154
|
+
}: GetIncentiveScalarParams): Promise<bigint> {
|
|
155
|
+
const criteria = await this.getIncentiveCriteria();
|
|
156
|
+
const transaction = await getTransaction(this._config, {
|
|
157
|
+
hash,
|
|
158
|
+
});
|
|
159
|
+
if (criteria.criteriaType === SignatureType.EVENT) {
|
|
160
|
+
const transactionReceipt = await getTransactionReceipt(this._config, {
|
|
161
|
+
hash,
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
const logs = transactionReceipt.logs;
|
|
165
|
+
|
|
166
|
+
if (logs.length === 0) {
|
|
167
|
+
throw new NoMatchingLogsError(
|
|
168
|
+
`No logs found for event signature ${criteria.signature}`,
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// Decode the event log
|
|
173
|
+
try {
|
|
174
|
+
// Decode function data
|
|
175
|
+
const eventAbi = (events.abi as Record<Hex, AbiEvent>)[
|
|
176
|
+
criteria.signature
|
|
177
|
+
] as AbiEvent;
|
|
178
|
+
const decodedEvents = parseEventLogs({
|
|
179
|
+
abi: [eventAbi],
|
|
180
|
+
logs,
|
|
181
|
+
});
|
|
182
|
+
if (decodedEvents == undefined || decodedEvents.length === 0) {
|
|
183
|
+
throw new NoMatchingLogsError(
|
|
184
|
+
`No logs found for event signature ${criteria.signature}`,
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
const scalarValue = (decodedEvents[0]?.args as string[])[
|
|
188
|
+
criteria.fieldIndex
|
|
189
|
+
];
|
|
190
|
+
|
|
191
|
+
if (scalarValue === undefined) {
|
|
192
|
+
throw new DecodedArgsError(
|
|
193
|
+
`Decoded argument at index ${criteria.fieldIndex} is undefined`,
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
return BigInt(scalarValue);
|
|
197
|
+
} catch (e) {
|
|
198
|
+
throw new DecodedArgsError(
|
|
199
|
+
`Failed to decode event log for signature ${criteria.signature}: ${(e as Error).message}`,
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
} else if (criteria.criteriaType === SignatureType.FUNC) {
|
|
203
|
+
// Fetch the transaction data
|
|
204
|
+
try {
|
|
205
|
+
// Decode function data
|
|
206
|
+
const func = (functions.abi as Record<Hex, AbiFunction>)[
|
|
207
|
+
criteria.signature
|
|
208
|
+
] as AbiFunction;
|
|
209
|
+
|
|
210
|
+
const decodedFunction = decodeFunctionData({
|
|
211
|
+
abi: [func],
|
|
212
|
+
data: transaction.input,
|
|
213
|
+
});
|
|
214
|
+
const scalarValue = decodedFunction.args[criteria.fieldIndex] as string;
|
|
215
|
+
if (scalarValue === undefined || scalarValue === null) {
|
|
216
|
+
throw new DecodedArgsError(
|
|
217
|
+
`Decoded argument at index ${criteria.fieldIndex} is undefined`,
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
return BigInt(scalarValue);
|
|
221
|
+
} catch (e) {
|
|
222
|
+
throw new DecodedArgsError(
|
|
223
|
+
`Failed to decode function data for signature ${criteria.signature}: ${(e as Error).message}`,
|
|
224
|
+
);
|
|
225
|
+
}
|
|
226
|
+
} else {
|
|
227
|
+
throw new InvalidCriteriaTypeError(
|
|
228
|
+
`Invalid criteria type ${criteria.criteriaType}`,
|
|
229
|
+
);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* @inheritdoc
|
|
234
|
+
*
|
|
235
|
+
* @public
|
|
236
|
+
* @param {?ERC20VariableCriteriaIncentivePayload} [_payload]
|
|
237
|
+
* @param {?DeployableOptions} [_options]
|
|
238
|
+
* @returns {GenericDeployableParams}
|
|
239
|
+
*/
|
|
240
|
+
public override buildParameters(
|
|
241
|
+
_payload?: ERC20VariableCriteriaIncentivePayload,
|
|
242
|
+
_options?: DeployableOptions,
|
|
243
|
+
): GenericDeployableParams {
|
|
244
|
+
const [payload, options] = this.validateDeploymentConfig(
|
|
245
|
+
_payload,
|
|
246
|
+
_options,
|
|
247
|
+
);
|
|
248
|
+
return {
|
|
249
|
+
abi: erc20VariableCriteriaIncentiveAbi,
|
|
250
|
+
bytecode: bytecode as Hex,
|
|
251
|
+
args: [prepareERC20VariableCriteriaIncentivePayload(payload)],
|
|
252
|
+
...this.optionallyAttachAccount(options.account),
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
*
|
|
259
|
+
*
|
|
260
|
+
* @param {InitPayloadExtended} param0
|
|
261
|
+
* @param {Address} param0.asset - The address of the ERC20 asset to incentivize.
|
|
262
|
+
* @param {bigint} param0.reward - The reward amount to distribute per action.
|
|
263
|
+
* @param {bigint} param0.limit - The total limit of the asset distribution.
|
|
264
|
+
* @param {IncentiveCriteria} param0.criteria - The incentive criteria for reward distribution.
|
|
265
|
+
* @returns {Hex}
|
|
266
|
+
*/
|
|
267
|
+
export function prepareERC20VariableCriteriaIncentivePayload({
|
|
268
|
+
asset,
|
|
269
|
+
reward,
|
|
270
|
+
limit,
|
|
271
|
+
criteria,
|
|
272
|
+
}: ERC20VariableCriteriaIncentivePayload) {
|
|
273
|
+
return encodeAbiParameters(
|
|
274
|
+
[
|
|
275
|
+
{
|
|
276
|
+
type: 'tuple',
|
|
277
|
+
name: 'initPayloadExtended',
|
|
278
|
+
components: [
|
|
279
|
+
{ type: 'address', name: 'asset' },
|
|
280
|
+
{ type: 'uint256', name: 'reward' },
|
|
281
|
+
{ type: 'uint256', name: 'limit' },
|
|
282
|
+
{
|
|
283
|
+
type: 'tuple',
|
|
284
|
+
name: 'criteria',
|
|
285
|
+
components: [
|
|
286
|
+
{ type: 'uint8', name: 'criteriaType' },
|
|
287
|
+
{ type: 'bytes32', name: 'signature' },
|
|
288
|
+
{ type: 'uint8', name: 'fieldIndex' },
|
|
289
|
+
{ type: 'address', name: 'targetContract' },
|
|
290
|
+
],
|
|
291
|
+
},
|
|
292
|
+
],
|
|
293
|
+
},
|
|
294
|
+
],
|
|
295
|
+
[
|
|
296
|
+
{
|
|
297
|
+
asset: asset,
|
|
298
|
+
reward: reward,
|
|
299
|
+
limit: limit,
|
|
300
|
+
criteria: {
|
|
301
|
+
criteriaType: criteria.criteriaType,
|
|
302
|
+
signature: criteria.signature,
|
|
303
|
+
fieldIndex: criteria.fieldIndex,
|
|
304
|
+
targetContract: criteria.targetContract,
|
|
305
|
+
},
|
|
306
|
+
},
|
|
307
|
+
],
|
|
308
|
+
);
|
|
309
|
+
}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { readMockErc20BalanceOf } from '@boostxyz/evm';
|
|
2
|
+
import { loadFixture } from '@nomicfoundation/hardhat-network-helpers';
|
|
3
|
+
import { encodeAbiParameters, isAddress, parseEther, zeroAddress } from 'viem';
|
|
4
|
+
import { beforeAll, beforeEach, describe, expect, test } from 'vitest';
|
|
5
|
+
import { accounts } from '@boostxyz/test/accounts';
|
|
6
|
+
import {
|
|
7
|
+
type BudgetFixtures,
|
|
8
|
+
type Fixtures,
|
|
9
|
+
defaultOptions,
|
|
10
|
+
deployFixtures,
|
|
11
|
+
freshBoost,
|
|
12
|
+
fundBudget,
|
|
13
|
+
} from '@boostxyz/test/helpers';
|
|
14
|
+
import { ERC20VariableIncentive } from './ERC20VariableIncentive';
|
|
15
|
+
|
|
16
|
+
const BOOST_CORE_CLAIM_FEE = parseEther('0.000075');
|
|
17
|
+
|
|
18
|
+
let fixtures: Fixtures, budgets: BudgetFixtures;
|
|
19
|
+
|
|
20
|
+
describe('ERC20VariableIncentive', () => {
|
|
21
|
+
beforeAll(async () => {
|
|
22
|
+
fixtures = await loadFixture(deployFixtures(defaultOptions));
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
beforeEach(async () => {
|
|
26
|
+
budgets = await loadFixture(fundBudget(defaultOptions, fixtures));
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test('can successfully be deployed', async () => {
|
|
30
|
+
const action = new ERC20VariableIncentive(defaultOptions, {
|
|
31
|
+
asset: zeroAddress,
|
|
32
|
+
reward: 1n,
|
|
33
|
+
limit: 1n,
|
|
34
|
+
});
|
|
35
|
+
await action.deploy();
|
|
36
|
+
expect(isAddress(action.assertValidAddress())).toBe(true);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test('can claim', async () => {
|
|
40
|
+
// biome-ignore lint/style/noNonNullAssertion: we know this is defined
|
|
41
|
+
const referrer = accounts.at(1)!.account!,
|
|
42
|
+
// biome-ignore lint/style/noNonNullAssertion: we know this is defined
|
|
43
|
+
trustedSigner = accounts.at(0)!;
|
|
44
|
+
const erc20VariableIncentive = new fixtures.bases.ERC20VariableIncentive(
|
|
45
|
+
defaultOptions,
|
|
46
|
+
{
|
|
47
|
+
asset: budgets.erc20.assertValidAddress(),
|
|
48
|
+
reward: 1n,
|
|
49
|
+
limit: 1n,
|
|
50
|
+
},
|
|
51
|
+
);
|
|
52
|
+
const boost = await freshBoost(fixtures, {
|
|
53
|
+
budget: budgets.budget,
|
|
54
|
+
incentives: [erc20VariableIncentive],
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
const claimant = trustedSigner.account;
|
|
58
|
+
const incentiveQuantity = 1;
|
|
59
|
+
const claimDataPayload = await boost.validator.encodeClaimData({
|
|
60
|
+
signer: trustedSigner,
|
|
61
|
+
incentiveData: encodeAbiParameters(
|
|
62
|
+
[{ name: '', type: 'uint256' }],
|
|
63
|
+
[parseEther('1')],
|
|
64
|
+
),
|
|
65
|
+
chainId: defaultOptions.config.chains[0].id,
|
|
66
|
+
incentiveQuantity,
|
|
67
|
+
claimant,
|
|
68
|
+
boostId: boost.id,
|
|
69
|
+
});
|
|
70
|
+
await fixtures.core.claimIncentive(
|
|
71
|
+
boost.id,
|
|
72
|
+
0n,
|
|
73
|
+
referrer,
|
|
74
|
+
claimDataPayload,
|
|
75
|
+
{ value: BOOST_CORE_CLAIM_FEE },
|
|
76
|
+
);
|
|
77
|
+
expect(
|
|
78
|
+
await readMockErc20BalanceOf(defaultOptions.config, {
|
|
79
|
+
address: budgets.erc20.assertValidAddress(),
|
|
80
|
+
args: [claimant],
|
|
81
|
+
}),
|
|
82
|
+
).toBe(1n);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
test('cannot claim twice', 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 erc20VariableIncentive = new fixtures.bases.ERC20VariableIncentive(
|
|
91
|
+
defaultOptions,
|
|
92
|
+
{
|
|
93
|
+
asset: budgets.erc20.assertValidAddress(),
|
|
94
|
+
reward: 1n,
|
|
95
|
+
limit: 1n,
|
|
96
|
+
},
|
|
97
|
+
);
|
|
98
|
+
const boost = await freshBoost(fixtures, {
|
|
99
|
+
budget: budgets.budget,
|
|
100
|
+
incentives: [erc20VariableIncentive],
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
const claimant = trustedSigner.account;
|
|
104
|
+
const incentiveQuantity = 1;
|
|
105
|
+
const claimDataPayload = await boost.validator.encodeClaimData({
|
|
106
|
+
signer: trustedSigner,
|
|
107
|
+
incentiveData: encodeAbiParameters(
|
|
108
|
+
[{ name: '', type: 'uint256' }],
|
|
109
|
+
[parseEther('1')],
|
|
110
|
+
),
|
|
111
|
+
chainId: defaultOptions.config.chains[0].id,
|
|
112
|
+
incentiveQuantity,
|
|
113
|
+
claimant,
|
|
114
|
+
boostId: boost.id,
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
await fixtures.core.claimIncentive(
|
|
118
|
+
boost.id,
|
|
119
|
+
0n,
|
|
120
|
+
referrer,
|
|
121
|
+
claimDataPayload,
|
|
122
|
+
{ value: BOOST_CORE_CLAIM_FEE },
|
|
123
|
+
);
|
|
124
|
+
try {
|
|
125
|
+
await fixtures.core.claimIncentive(
|
|
126
|
+
boost.id,
|
|
127
|
+
0n,
|
|
128
|
+
referrer,
|
|
129
|
+
claimDataPayload,
|
|
130
|
+
{ value: BOOST_CORE_CLAIM_FEE },
|
|
131
|
+
);
|
|
132
|
+
} catch (e) {
|
|
133
|
+
expect(e).toBeInstanceOf(Error);
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
});
|