@boostxyz/sdk 0.0.0-alpha.10
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/LICENSE +674 -0
- package/README.md +7 -0
- package/dist/Actions/Action.cjs +2 -0
- package/dist/Actions/Action.cjs.map +1 -0
- package/dist/Actions/Action.d.ts +31 -0
- package/dist/Actions/Action.d.ts.map +1 -0
- package/dist/Actions/Action.js +29 -0
- package/dist/Actions/Action.js.map +1 -0
- package/dist/Actions/ContractAction.d.ts +370 -0
- package/dist/Actions/ContractAction.d.ts.map +1 -0
- package/dist/Actions/ERC721MintAction.d.ts +513 -0
- package/dist/Actions/ERC721MintAction.d.ts.map +1 -0
- package/dist/Actions/EventAction.cjs +2 -0
- package/dist/Actions/EventAction.cjs.map +1 -0
- package/dist/Actions/EventAction.d.ts +694 -0
- package/dist/Actions/EventAction.d.ts.map +1 -0
- package/dist/Actions/EventAction.js +491 -0
- package/dist/Actions/EventAction.js.map +1 -0
- package/dist/AllowLists/AllowList.cjs +2 -0
- package/dist/AllowLists/AllowList.cjs.map +1 -0
- package/dist/AllowLists/AllowList.d.ts +32 -0
- package/dist/AllowLists/AllowList.d.ts.map +1 -0
- package/dist/AllowLists/AllowList.js +30 -0
- package/dist/AllowLists/AllowList.js.map +1 -0
- package/dist/AllowLists/SimpleAllowList.cjs +2 -0
- package/dist/AllowLists/SimpleAllowList.cjs.map +1 -0
- package/dist/AllowLists/SimpleAllowList.d.ts +481 -0
- package/dist/AllowLists/SimpleAllowList.d.ts.map +1 -0
- package/dist/AllowLists/SimpleAllowList.js +154 -0
- package/dist/AllowLists/SimpleAllowList.js.map +1 -0
- package/dist/AllowLists/SimpleDenyList.cjs +2 -0
- package/dist/AllowLists/SimpleDenyList.cjs.map +1 -0
- package/dist/AllowLists/SimpleDenyList.d.ts +335 -0
- package/dist/AllowLists/SimpleDenyList.d.ts.map +1 -0
- package/dist/AllowLists/SimpleDenyList.js +115 -0
- package/dist/AllowLists/SimpleDenyList.js.map +1 -0
- package/dist/Auth/Auth.cjs +2 -0
- package/dist/Auth/Auth.cjs.map +1 -0
- package/dist/Auth/Auth.d.ts +10 -0
- package/dist/Auth/Auth.d.ts.map +1 -0
- package/dist/Auth/Auth.js +5 -0
- package/dist/Auth/Auth.js.map +1 -0
- package/dist/Auth/PassthroughAuth.cjs +2 -0
- package/dist/Auth/PassthroughAuth.cjs.map +1 -0
- package/dist/Auth/PassthroughAuth.d.ts +51 -0
- package/dist/Auth/PassthroughAuth.d.ts.map +1 -0
- package/dist/Auth/PassthroughAuth.js +39 -0
- package/dist/Auth/PassthroughAuth.js.map +1 -0
- package/dist/Boost.cjs +2 -0
- package/dist/Boost.cjs.map +1 -0
- package/dist/Boost.d.ts +234 -0
- package/dist/Boost.d.ts.map +1 -0
- package/dist/Boost.js +162 -0
- package/dist/Boost.js.map +1 -0
- package/dist/BoostCore.cjs +3 -0
- package/dist/BoostCore.cjs.map +1 -0
- package/dist/BoostCore.d.ts +498 -0
- package/dist/BoostCore.d.ts.map +1 -0
- package/dist/BoostCore.js +1153 -0
- package/dist/BoostCore.js.map +1 -0
- package/dist/BoostRegistry.cjs +2 -0
- package/dist/BoostRegistry.cjs.map +1 -0
- package/dist/BoostRegistry.d.ts +243 -0
- package/dist/BoostRegistry.d.ts.map +1 -0
- package/dist/BoostRegistry.js +262 -0
- package/dist/BoostRegistry.js.map +1 -0
- package/dist/Budgets/Budget.cjs +2 -0
- package/dist/Budgets/Budget.cjs.map +1 -0
- package/dist/Budgets/Budget.d.ts +31 -0
- package/dist/Budgets/Budget.d.ts.map +1 -0
- package/dist/Budgets/Budget.js +29 -0
- package/dist/Budgets/Budget.js.map +1 -0
- package/dist/Budgets/ManagedBudget.cjs +2 -0
- package/dist/Budgets/ManagedBudget.cjs.map +1 -0
- package/dist/Budgets/ManagedBudget.d.ts +1103 -0
- package/dist/Budgets/ManagedBudget.d.ts.map +1 -0
- package/dist/Budgets/ManagedBudget.js +516 -0
- package/dist/Budgets/ManagedBudget.js.map +1 -0
- package/dist/Budgets/SimpleBudget.d.ts +824 -0
- package/dist/Budgets/SimpleBudget.d.ts.map +1 -0
- package/dist/Budgets/VestingBudget.d.ts +778 -0
- package/dist/Budgets/VestingBudget.d.ts.map +1 -0
- package/dist/Deployable/Contract.cjs +2 -0
- package/dist/Deployable/Contract.cjs.map +1 -0
- package/dist/Deployable/Contract.d.ts +125 -0
- package/dist/Deployable/Contract.d.ts.map +1 -0
- package/dist/Deployable/Contract.js +150 -0
- package/dist/Deployable/Contract.js.map +1 -0
- package/dist/Deployable/Deployable.cjs +2 -0
- package/dist/Deployable/Deployable.cjs.map +1 -0
- package/dist/Deployable/Deployable.d.ts +161 -0
- package/dist/Deployable/Deployable.d.ts.map +1 -0
- package/dist/Deployable/Deployable.js +131 -0
- package/dist/Deployable/Deployable.js.map +1 -0
- package/dist/Deployable/DeployableTarget.cjs +2 -0
- package/dist/Deployable/DeployableTarget.cjs.map +1 -0
- package/dist/Deployable/DeployableTarget.d.ts +116 -0
- package/dist/Deployable/DeployableTarget.d.ts.map +1 -0
- package/dist/Deployable/DeployableTarget.js +132 -0
- package/dist/Deployable/DeployableTarget.js.map +1 -0
- package/dist/Incentives/AllowListIncentive.cjs +2 -0
- package/dist/Incentives/AllowListIncentive.cjs.map +1 -0
- package/dist/Incentives/AllowListIncentive.d.ts +513 -0
- package/dist/Incentives/AllowListIncentive.d.ts.map +1 -0
- package/dist/Incentives/AllowListIncentive.js +201 -0
- package/dist/Incentives/AllowListIncentive.js.map +1 -0
- package/dist/Incentives/CGDAIncentive.cjs +2 -0
- package/dist/Incentives/CGDAIncentive.cjs.map +1 -0
- package/dist/Incentives/CGDAIncentive.d.ts +644 -0
- package/dist/Incentives/CGDAIncentive.d.ts.map +1 -0
- package/dist/Incentives/CGDAIncentive.js +271 -0
- package/dist/Incentives/CGDAIncentive.js.map +1 -0
- package/dist/Incentives/ERC1155Incentive.d.ts +713 -0
- package/dist/Incentives/ERC1155Incentive.d.ts.map +1 -0
- package/dist/Incentives/ERC20Incentive.cjs +2 -0
- package/dist/Incentives/ERC20Incentive.cjs.map +1 -0
- package/dist/Incentives/ERC20Incentive.d.ts +666 -0
- package/dist/Incentives/ERC20Incentive.d.ts.map +1 -0
- package/dist/Incentives/ERC20Incentive.js +312 -0
- package/dist/Incentives/ERC20Incentive.js.map +1 -0
- package/dist/Incentives/ERC20VariableIncentive.d.ts +582 -0
- package/dist/Incentives/ERC20VariableIncentive.d.ts.map +1 -0
- package/dist/Incentives/Incentive.cjs +2 -0
- package/dist/Incentives/Incentive.cjs.map +1 -0
- package/dist/Incentives/Incentive.d.ts +36 -0
- package/dist/Incentives/Incentive.d.ts.map +1 -0
- package/dist/Incentives/Incentive.js +299 -0
- package/dist/Incentives/Incentive.js.map +1 -0
- package/dist/Incentives/PointsIncentive.cjs +2 -0
- package/dist/Incentives/PointsIncentive.cjs.map +1 -0
- package/dist/Incentives/PointsIncentive.d.ts +659 -0
- package/dist/Incentives/PointsIncentive.d.ts.map +1 -0
- package/dist/Incentives/PointsIncentive.js +215 -0
- package/dist/Incentives/PointsIncentive.js.map +1 -0
- package/dist/Validators/SignerValidator.cjs +2 -0
- package/dist/Validators/SignerValidator.cjs.map +1 -0
- package/dist/Validators/SignerValidator.d.ts +745 -0
- package/dist/Validators/SignerValidator.d.ts.map +1 -0
- package/dist/Validators/SignerValidator.js +293 -0
- package/dist/Validators/SignerValidator.js.map +1 -0
- package/dist/Validators/Validator.cjs +2 -0
- package/dist/Validators/Validator.cjs.map +1 -0
- package/dist/Validators/Validator.d.ts +31 -0
- package/dist/Validators/Validator.d.ts.map +1 -0
- package/dist/Validators/Validator.js +27 -0
- 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-CKCBwG16.cjs +2 -0
- package/dist/componentInterfaces-CKCBwG16.cjs.map +1 -0
- package/dist/componentInterfaces-DYkaxBda.js +13 -0
- package/dist/componentInterfaces-DYkaxBda.js.map +1 -0
- package/dist/errors.cjs +2 -0
- package/dist/errors.cjs.map +1 -0
- package/dist/errors.d.ts +441 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +262 -0
- package/dist/errors.js.map +1 -0
- package/dist/generated-BDeDiaCK.js +4625 -0
- package/dist/generated-BDeDiaCK.js.map +1 -0
- package/dist/generated-wKBNvm48.cjs +3 -0
- package/dist/generated-wKBNvm48.cjs.map +1 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +113 -0
- 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 -0
- package/dist/utils.cjs.map +1 -0
- package/dist/utils.d.ts +116 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +30 -0
- package/dist/utils.js.map +1 -0
- package/package.json +211 -0
- package/src/Actions/Action.test.ts +75 -0
- package/src/Actions/Action.ts +61 -0
- package/src/Actions/ContractAction.test.ts +197 -0
- package/src/Actions/ContractAction.ts +301 -0
- package/src/Actions/ERC721MintAction.test.ts +112 -0
- package/src/Actions/ERC721MintAction.ts +292 -0
- package/src/Actions/EventAction.test.ts +205 -0
- package/src/Actions/EventAction.ts +811 -0
- package/src/AllowLists/AllowList.test.ts +64 -0
- package/src/AllowLists/AllowList.ts +60 -0
- package/src/AllowLists/SimpleAllowList.test.ts +52 -0
- package/src/AllowLists/SimpleAllowList.ts +284 -0
- package/src/AllowLists/SimpleDenyList.test.ts +52 -0
- package/src/AllowLists/SimpleDenyList.ts +227 -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 +290 -0
- package/src/BoostCore.test.ts +773 -0
- package/src/BoostCore.ts +1261 -0
- package/src/BoostRegistry.ts +467 -0
- package/src/Budgets/Budget.test.ts +27 -0
- package/src/Budgets/Budget.ts +61 -0
- package/src/Budgets/ManagedBudget.test.ts +154 -0
- package/src/Budgets/ManagedBudget.ts +796 -0
- package/src/Budgets/SimpleBudget.test.ts +152 -0
- package/src/Budgets/SimpleBudget.ts +564 -0
- package/src/Budgets/VestingBudget.test.ts +123 -0
- package/src/Budgets/VestingBudget.ts +602 -0
- package/src/Deployable/Contract.ts +229 -0
- package/src/Deployable/Deployable.ts +250 -0
- package/src/Deployable/DeployableTarget.ts +223 -0
- package/src/Incentives/AllowListIncentive.test.ts +143 -0
- package/src/Incentives/AllowListIncentive.ts +334 -0
- package/src/Incentives/CGDAIncentive.test.ts +132 -0
- package/src/Incentives/CGDAIncentive.ts +468 -0
- package/src/Incentives/ERC1155Incentive.test.ts +87 -0
- package/src/Incentives/ERC1155Incentive.ts +466 -0
- package/src/Incentives/ERC20Incentive.test.ts +130 -0
- package/src/Incentives/ERC20Incentive.ts +482 -0
- package/src/Incentives/ERC20VariableIncentive.test.ts +136 -0
- package/src/Incentives/ERC20VariableIncentive.ts +420 -0
- package/src/Incentives/Incentive.test.ts +92 -0
- package/src/Incentives/Incentive.ts +85 -0
- package/src/Incentives/PointsIncentive.test.ts +139 -0
- package/src/Incentives/PointsIncentive.ts +365 -0
- package/src/Validators/SignerValidator.test.ts +159 -0
- package/src/Validators/SignerValidator.ts +681 -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 +542 -0
- package/src/index.test.ts +40 -0
- package/src/index.ts +53 -0
- package/src/transfers.ts +284 -0
- package/src/utils.test.ts +44 -0
- package/src/utils.ts +198 -0
|
@@ -0,0 +1,420 @@
|
|
|
1
|
+
import {
|
|
2
|
+
erc20VariableIncentiveAbi,
|
|
3
|
+
readErc20VariableIncentiveAsset,
|
|
4
|
+
readErc20VariableIncentiveClaimed,
|
|
5
|
+
readErc20VariableIncentiveClaims,
|
|
6
|
+
readErc20VariableIncentiveCurrentReward,
|
|
7
|
+
readErc20VariableIncentiveIsClaimable,
|
|
8
|
+
readErc20VariableIncentiveLimit,
|
|
9
|
+
readErc20VariableIncentiveOwner,
|
|
10
|
+
readErc20VariableIncentiveReward,
|
|
11
|
+
readErc20VariableIncentiveTotalClaimed,
|
|
12
|
+
simulateErc20VariableIncentiveClaim,
|
|
13
|
+
simulateErc20VariableIncentiveClawback,
|
|
14
|
+
writeErc20VariableIncentiveClaim,
|
|
15
|
+
writeErc20VariableIncentiveClawback,
|
|
16
|
+
} from '@boostxyz/evm';
|
|
17
|
+
import { bytecode } from '@boostxyz/evm/artifacts/contracts/incentives/ERC20VariableIncentive.sol/ERC20VariableIncentive.json';
|
|
18
|
+
import {
|
|
19
|
+
type Address,
|
|
20
|
+
type ContractEventName,
|
|
21
|
+
type Hex,
|
|
22
|
+
encodeAbiParameters,
|
|
23
|
+
} from 'viem';
|
|
24
|
+
import type {
|
|
25
|
+
DeployableOptions,
|
|
26
|
+
GenericDeployableParams,
|
|
27
|
+
} from '../Deployable/Deployable';
|
|
28
|
+
import { DeployableTarget } from '../Deployable/DeployableTarget';
|
|
29
|
+
import { type ClaimPayload, prepareClaimPayload } from '../claiming';
|
|
30
|
+
import {
|
|
31
|
+
type GenericLog,
|
|
32
|
+
type ReadParams,
|
|
33
|
+
RegistryType,
|
|
34
|
+
type WriteParams,
|
|
35
|
+
} from '../utils';
|
|
36
|
+
|
|
37
|
+
export { erc20VariableIncentiveAbi };
|
|
38
|
+
/**
|
|
39
|
+
* The object representation of a `ERC20VariableIncentivePayload.InitPayload`
|
|
40
|
+
*
|
|
41
|
+
* @export
|
|
42
|
+
* @interface ERC20VariableIncentivePayload
|
|
43
|
+
* @typedef {ERC20VariableIncentivePayload}
|
|
44
|
+
*/
|
|
45
|
+
export interface ERC20VariableIncentivePayload {
|
|
46
|
+
/**
|
|
47
|
+
* The address of the incentivized asset.
|
|
48
|
+
*
|
|
49
|
+
* @type {Address}
|
|
50
|
+
*/
|
|
51
|
+
asset: Address;
|
|
52
|
+
/**
|
|
53
|
+
* The amount of the asset to distribute.
|
|
54
|
+
*
|
|
55
|
+
* @type {bigint}
|
|
56
|
+
*/
|
|
57
|
+
reward: bigint;
|
|
58
|
+
/**
|
|
59
|
+
* How many times can this incentive be claimed.
|
|
60
|
+
*
|
|
61
|
+
* @type {bigint}
|
|
62
|
+
*/
|
|
63
|
+
limit: bigint;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* A generic `viem.Log` event with support for `ERC20VariableIncentive` event types.
|
|
68
|
+
*
|
|
69
|
+
* @export
|
|
70
|
+
* @typedef {ERC20VariableIncentiveLog}
|
|
71
|
+
* @template {ContractEventName<typeof erc20VariableIncentiveAbi>} [event=ContractEventName<
|
|
72
|
+
* typeof erc20VariableIncentiveAbi
|
|
73
|
+
* >]
|
|
74
|
+
*/
|
|
75
|
+
export type ERC20VariableIncentiveLog<
|
|
76
|
+
event extends ContractEventName<
|
|
77
|
+
typeof erc20VariableIncentiveAbi
|
|
78
|
+
> = ContractEventName<typeof erc20VariableIncentiveAbi>,
|
|
79
|
+
> = GenericLog<typeof erc20VariableIncentiveAbi, event>;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* A simple ERC20 incentive implementation that allows claiming of tokens
|
|
83
|
+
*
|
|
84
|
+
* @export
|
|
85
|
+
* @class ERC20VariableIncentive
|
|
86
|
+
* @typedef {ERC20VariableIncentive}
|
|
87
|
+
* @extends {DeployableTarget<ERC20VariableIncentivePayload>}
|
|
88
|
+
*/
|
|
89
|
+
export class ERC20VariableIncentive extends DeployableTarget<
|
|
90
|
+
ERC20VariableIncentivePayload,
|
|
91
|
+
typeof erc20VariableIncentiveAbi
|
|
92
|
+
> {
|
|
93
|
+
public override readonly abi = erc20VariableIncentiveAbi;
|
|
94
|
+
/**
|
|
95
|
+
* @inheritdoc
|
|
96
|
+
*
|
|
97
|
+
* @public
|
|
98
|
+
* @static
|
|
99
|
+
* @type {Address}
|
|
100
|
+
*/
|
|
101
|
+
public static override base: Address = import.meta.env
|
|
102
|
+
.VITE_ERC20_VARIABLE_INCENTIVE_BASE;
|
|
103
|
+
/**
|
|
104
|
+
* @inheritdoc
|
|
105
|
+
*
|
|
106
|
+
* @public
|
|
107
|
+
* @static
|
|
108
|
+
* @type {RegistryType}
|
|
109
|
+
*/
|
|
110
|
+
public static override registryType: RegistryType = RegistryType.INCENTIVE;
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* The owner of the incentive
|
|
114
|
+
*
|
|
115
|
+
* @public
|
|
116
|
+
* @async
|
|
117
|
+
* @param {?ReadParams<typeof erc20VariableIncentiveAbi, 'owner'>} [params]
|
|
118
|
+
* @returns {unknown}
|
|
119
|
+
*/
|
|
120
|
+
public async owner(
|
|
121
|
+
params?: ReadParams<typeof erc20VariableIncentiveAbi, 'owner'>,
|
|
122
|
+
) {
|
|
123
|
+
return await readErc20VariableIncentiveOwner(this._config, {
|
|
124
|
+
address: this.assertValidAddress(),
|
|
125
|
+
args: [],
|
|
126
|
+
// biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
|
|
127
|
+
...(params as any),
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* The current reward
|
|
133
|
+
*
|
|
134
|
+
* @public
|
|
135
|
+
* @async
|
|
136
|
+
* @param {?ReadParams<typeof erc20VariableIncentiveAbi, 'currentReward'>} [params]
|
|
137
|
+
* @returns {Promise<bigint>} - The current reward
|
|
138
|
+
*/
|
|
139
|
+
public async totalClaimed(
|
|
140
|
+
params?: ReadParams<typeof erc20VariableIncentiveAbi, 'totalClaimed'>,
|
|
141
|
+
) {
|
|
142
|
+
return await readErc20VariableIncentiveTotalClaimed(this._config, {
|
|
143
|
+
address: this.assertValidAddress(),
|
|
144
|
+
args: [],
|
|
145
|
+
// biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
|
|
146
|
+
...(params as any),
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* The current reward
|
|
152
|
+
*
|
|
153
|
+
* @public
|
|
154
|
+
* @async
|
|
155
|
+
* @param {?ReadParams<typeof erc20VariableIncentiveAbi, 'currentReward'>} [params]
|
|
156
|
+
* @returns {Promise<bigint>} - The current reward
|
|
157
|
+
*/
|
|
158
|
+
public async currentReward(
|
|
159
|
+
params?: ReadParams<typeof erc20VariableIncentiveAbi, 'currentReward'>,
|
|
160
|
+
) {
|
|
161
|
+
return await readErc20VariableIncentiveCurrentReward(this._config, {
|
|
162
|
+
address: this.assertValidAddress(),
|
|
163
|
+
args: [],
|
|
164
|
+
// biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
|
|
165
|
+
...(params as any),
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* The number of claims that have been made
|
|
171
|
+
*
|
|
172
|
+
* @public
|
|
173
|
+
* @async
|
|
174
|
+
* @param {?ReadParams<typeof erc20VariableIncentiveAbi, 'claims'>} [params]
|
|
175
|
+
* @returns {Promise<bigint>}
|
|
176
|
+
*/
|
|
177
|
+
public async claims(
|
|
178
|
+
params?: ReadParams<typeof erc20VariableIncentiveAbi, 'claims'>,
|
|
179
|
+
) {
|
|
180
|
+
return await readErc20VariableIncentiveClaims(this._config, {
|
|
181
|
+
address: this.assertValidAddress(),
|
|
182
|
+
args: [],
|
|
183
|
+
// biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
|
|
184
|
+
...(params as any),
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* A mapping of address to claim status
|
|
190
|
+
*
|
|
191
|
+
* @public
|
|
192
|
+
* @async
|
|
193
|
+
* @param {Address} address
|
|
194
|
+
* @param {?ReadParams<typeof erc20VariableIncentiveAbi, 'claimed'>} [params]
|
|
195
|
+
* @returns {Promise<boolean>}
|
|
196
|
+
*/
|
|
197
|
+
public async claimed(
|
|
198
|
+
address: Address,
|
|
199
|
+
params?: ReadParams<typeof erc20VariableIncentiveAbi, 'claimed'>,
|
|
200
|
+
) {
|
|
201
|
+
return await readErc20VariableIncentiveClaimed(this._config, {
|
|
202
|
+
address: this.assertValidAddress(),
|
|
203
|
+
args: [address],
|
|
204
|
+
// biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
|
|
205
|
+
...(params as any),
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* The address of the ERC20-like token
|
|
211
|
+
*
|
|
212
|
+
* @public
|
|
213
|
+
* @async
|
|
214
|
+
* @param {?ReadParams<typeof erc20VariableIncentiveAbi, 'asset'>} [params]
|
|
215
|
+
* @returns {Promise<Address>}
|
|
216
|
+
*/
|
|
217
|
+
public async asset(
|
|
218
|
+
params?: ReadParams<typeof erc20VariableIncentiveAbi, 'asset'>,
|
|
219
|
+
) {
|
|
220
|
+
return await readErc20VariableIncentiveAsset(this._config, {
|
|
221
|
+
address: this.assertValidAddress(),
|
|
222
|
+
// biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
|
|
223
|
+
...(params as any),
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* The reward amount issued for each claim
|
|
229
|
+
*
|
|
230
|
+
* @public
|
|
231
|
+
* @async
|
|
232
|
+
* @param {?ReadParams<typeof erc20VariableIncentiveAbi, 'reward'>} [params]
|
|
233
|
+
* @returns {Promise<bigint>}
|
|
234
|
+
*/
|
|
235
|
+
public async reward(
|
|
236
|
+
params?: ReadParams<typeof erc20VariableIncentiveAbi, 'reward'>,
|
|
237
|
+
) {
|
|
238
|
+
return await readErc20VariableIncentiveReward(this._config, {
|
|
239
|
+
address: this.assertValidAddress(),
|
|
240
|
+
// biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
|
|
241
|
+
...(params as any),
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* The limit (max claims, or max entries for raffles)
|
|
247
|
+
*
|
|
248
|
+
* @public
|
|
249
|
+
* @async
|
|
250
|
+
* @param {?ReadParams<typeof erc20VariableIncentiveAbi, 'limit'>} [params]
|
|
251
|
+
* @returns {unknown}
|
|
252
|
+
*/
|
|
253
|
+
public async limit(
|
|
254
|
+
params?: ReadParams<typeof erc20VariableIncentiveAbi, 'limit'>,
|
|
255
|
+
) {
|
|
256
|
+
return await readErc20VariableIncentiveLimit(this._config, {
|
|
257
|
+
address: this.assertValidAddress(),
|
|
258
|
+
// biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
|
|
259
|
+
...(params as any),
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Claim the incentive
|
|
265
|
+
*
|
|
266
|
+
* @public
|
|
267
|
+
* @async
|
|
268
|
+
* @param {ClaimPayload} payload
|
|
269
|
+
* @param {?WriteParams<typeof erc20VariableIncentiveAbi, 'claim'>} [params]
|
|
270
|
+
* @returns {Promise<boolean>} - Returns true if successfully claimed
|
|
271
|
+
*/
|
|
272
|
+
protected async claim(
|
|
273
|
+
payload: ClaimPayload,
|
|
274
|
+
params?: WriteParams<typeof erc20VariableIncentiveAbi, 'claim'>,
|
|
275
|
+
) {
|
|
276
|
+
return await this.awaitResult(this.claimRaw(payload, params));
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* Claim the incentive
|
|
281
|
+
*
|
|
282
|
+
* @public
|
|
283
|
+
* @async
|
|
284
|
+
* @param {ClaimPayload} payload
|
|
285
|
+
* @param {?WriteParams<typeof erc20VariableIncentiveAbi, 'claim'>} [params]
|
|
286
|
+
* @returns {Promise<boolean>} - Returns true if successfully claimed
|
|
287
|
+
*/
|
|
288
|
+
protected async claimRaw(
|
|
289
|
+
payload: ClaimPayload,
|
|
290
|
+
params?: WriteParams<typeof erc20VariableIncentiveAbi, 'claim'>,
|
|
291
|
+
) {
|
|
292
|
+
const { request, result } = await simulateErc20VariableIncentiveClaim(
|
|
293
|
+
this._config,
|
|
294
|
+
{
|
|
295
|
+
address: this.assertValidAddress(),
|
|
296
|
+
args: [prepareClaimPayload(payload)],
|
|
297
|
+
...this.optionallyAttachAccount(),
|
|
298
|
+
// biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
|
|
299
|
+
...(params as any),
|
|
300
|
+
},
|
|
301
|
+
);
|
|
302
|
+
const hash = await writeErc20VariableIncentiveClaim(this._config, request);
|
|
303
|
+
return { hash, result };
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* Clawback assets from the incentive
|
|
308
|
+
*
|
|
309
|
+
* @public
|
|
310
|
+
* @async
|
|
311
|
+
* @param {ClaimPayload} payload
|
|
312
|
+
* @param {?WriteParams<typeof erc20VariableIncentiveAbi, 'clawback'>} [params]
|
|
313
|
+
* @returns {Promise<boolean>} - True if the assets were successfully clawbacked
|
|
314
|
+
*/
|
|
315
|
+
public async clawback(
|
|
316
|
+
payload: ClaimPayload,
|
|
317
|
+
params?: WriteParams<typeof erc20VariableIncentiveAbi, 'clawback'>,
|
|
318
|
+
) {
|
|
319
|
+
return await this.awaitResult(this.clawbackRaw(payload, params));
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* Clawback assets from the incentive
|
|
324
|
+
*
|
|
325
|
+
* @public
|
|
326
|
+
* @async
|
|
327
|
+
* @param {ClaimPayload} payload
|
|
328
|
+
* @param {?WriteParams<typeof erc20VariableIncentiveAbi, 'clawback'>} [params]
|
|
329
|
+
* @returns {Promise<boolean>} - True if the assets were successfully clawbacked
|
|
330
|
+
*/
|
|
331
|
+
public async clawbackRaw(
|
|
332
|
+
payload: ClaimPayload,
|
|
333
|
+
params?: WriteParams<typeof erc20VariableIncentiveAbi, 'clawback'>,
|
|
334
|
+
) {
|
|
335
|
+
const { request, result } = await simulateErc20VariableIncentiveClawback(
|
|
336
|
+
this._config,
|
|
337
|
+
{
|
|
338
|
+
address: this.assertValidAddress(),
|
|
339
|
+
args: [prepareClaimPayload(payload)],
|
|
340
|
+
...this.optionallyAttachAccount(),
|
|
341
|
+
// biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
|
|
342
|
+
...(params as any),
|
|
343
|
+
},
|
|
344
|
+
);
|
|
345
|
+
const hash = await writeErc20VariableIncentiveClawback(
|
|
346
|
+
this._config,
|
|
347
|
+
request,
|
|
348
|
+
);
|
|
349
|
+
return { hash, result };
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* Check if an incentive is claimable. For the POOL strategy, the `bytes data` portion of the payload ignored. The recipient must not have already claimed the incentive.
|
|
354
|
+
*
|
|
355
|
+
* @public
|
|
356
|
+
* @async
|
|
357
|
+
* @param {ClaimPayload} payload
|
|
358
|
+
* @param {?ReadParams<typeof erc20VariableIncentiveAbi, 'isClaimable'>} [params]
|
|
359
|
+
* @returns {unknown} = True if the incentive is claimable based on the data payload
|
|
360
|
+
*/
|
|
361
|
+
public async isClaimable(
|
|
362
|
+
payload: ClaimPayload,
|
|
363
|
+
params?: ReadParams<typeof erc20VariableIncentiveAbi, 'isClaimable'>,
|
|
364
|
+
) {
|
|
365
|
+
return await readErc20VariableIncentiveIsClaimable(this._config, {
|
|
366
|
+
address: this.assertValidAddress(),
|
|
367
|
+
args: [prepareClaimPayload(payload)],
|
|
368
|
+
// biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
|
|
369
|
+
...(params as any),
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
/**
|
|
374
|
+
* @inheritdoc
|
|
375
|
+
*
|
|
376
|
+
* @public
|
|
377
|
+
* @param {?ERC20VariableIncentivePayload} [_payload]
|
|
378
|
+
* @param {?DeployableOptions} [_options]
|
|
379
|
+
* @returns {GenericDeployableParams}
|
|
380
|
+
*/
|
|
381
|
+
public override buildParameters(
|
|
382
|
+
_payload?: ERC20VariableIncentivePayload,
|
|
383
|
+
_options?: DeployableOptions,
|
|
384
|
+
): GenericDeployableParams {
|
|
385
|
+
const [payload, options] = this.validateDeploymentConfig(
|
|
386
|
+
_payload,
|
|
387
|
+
_options,
|
|
388
|
+
);
|
|
389
|
+
return {
|
|
390
|
+
abi: erc20VariableIncentiveAbi,
|
|
391
|
+
bytecode: bytecode as Hex,
|
|
392
|
+
args: [prepareERC20VariableIncentivePayload(payload)],
|
|
393
|
+
...this.optionallyAttachAccount(options.account),
|
|
394
|
+
};
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* Given a {@link ERC20VariableIncentivePayload}, properly encode a ` ERC20VariableIncentive.InitPayload` for use with {@link ERC20VariableIncentive} initialization.
|
|
400
|
+
*
|
|
401
|
+
* @param {ERC20VariableIncentivePayload} param0
|
|
402
|
+
* @param {Address} param0.asset - The address of the incentivized asset.
|
|
403
|
+
* @param {bigint} param0.reward - The amount of the asset to distribute.
|
|
404
|
+
* @param {bigint} param0.limit - How many times can this incentive be claimed.
|
|
405
|
+
* @returns {*}
|
|
406
|
+
*/
|
|
407
|
+
export function prepareERC20VariableIncentivePayload({
|
|
408
|
+
asset,
|
|
409
|
+
reward,
|
|
410
|
+
limit,
|
|
411
|
+
}: ERC20VariableIncentivePayload) {
|
|
412
|
+
return encodeAbiParameters(
|
|
413
|
+
[
|
|
414
|
+
{ type: 'address', name: 'asset' },
|
|
415
|
+
{ type: 'uint256', name: 'reward' },
|
|
416
|
+
{ type: 'uint256', name: 'limit' },
|
|
417
|
+
],
|
|
418
|
+
[asset, reward, limit],
|
|
419
|
+
);
|
|
420
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { zeroAddress } from 'viem';
|
|
2
|
+
import { describe, expect, test } from 'vitest';
|
|
3
|
+
import { defaultOptions } from '../../test/helpers';
|
|
4
|
+
import { StrategyType } from '../claiming';
|
|
5
|
+
import {
|
|
6
|
+
AllowListIncentive,
|
|
7
|
+
CGDAIncentive,
|
|
8
|
+
ERC20Incentive,
|
|
9
|
+
ERC20VariableIncentive,
|
|
10
|
+
incentiveFromAddress,
|
|
11
|
+
} from './Incentive';
|
|
12
|
+
import { PointsIncentive } from './PointsIncentive';
|
|
13
|
+
|
|
14
|
+
describe('Incentive', () => {
|
|
15
|
+
test('can automatically instantiate PointsIncentive given an address', async () => {
|
|
16
|
+
const incentive = new PointsIncentive(defaultOptions, {
|
|
17
|
+
venue: zeroAddress,
|
|
18
|
+
selector: '0xdeadb33f',
|
|
19
|
+
reward: 1n,
|
|
20
|
+
limit: 1n,
|
|
21
|
+
});
|
|
22
|
+
await incentive.deploy();
|
|
23
|
+
expect(
|
|
24
|
+
await incentiveFromAddress(
|
|
25
|
+
defaultOptions,
|
|
26
|
+
incentive.assertValidAddress(),
|
|
27
|
+
),
|
|
28
|
+
).toBeInstanceOf(PointsIncentive);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test('can automatically instantiate AllowListIncentive given an address', async () => {
|
|
32
|
+
const incentive = new AllowListIncentive(defaultOptions, {
|
|
33
|
+
allowList: zeroAddress,
|
|
34
|
+
limit: 3n,
|
|
35
|
+
});
|
|
36
|
+
await incentive.deploy();
|
|
37
|
+
expect(
|
|
38
|
+
await incentiveFromAddress(
|
|
39
|
+
defaultOptions,
|
|
40
|
+
incentive.assertValidAddress(),
|
|
41
|
+
),
|
|
42
|
+
).toBeInstanceOf(AllowListIncentive);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
test('can automatically instantiate CGDAIncentive given an address', async () => {
|
|
46
|
+
const incentive = new CGDAIncentive(defaultOptions, {
|
|
47
|
+
asset: zeroAddress,
|
|
48
|
+
initialReward: 1n,
|
|
49
|
+
totalBudget: 10n,
|
|
50
|
+
rewardBoost: 1n,
|
|
51
|
+
rewardDecay: 1n,
|
|
52
|
+
});
|
|
53
|
+
await incentive.deploy();
|
|
54
|
+
expect(
|
|
55
|
+
await incentiveFromAddress(
|
|
56
|
+
defaultOptions,
|
|
57
|
+
incentive.assertValidAddress(),
|
|
58
|
+
),
|
|
59
|
+
).toBeInstanceOf(CGDAIncentive);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test('can automatically instantiate ERC20Incentive given an address', async () => {
|
|
63
|
+
const incentive = new ERC20Incentive(defaultOptions, {
|
|
64
|
+
asset: zeroAddress,
|
|
65
|
+
strategy: StrategyType.POOL,
|
|
66
|
+
reward: 1n,
|
|
67
|
+
limit: 10n,
|
|
68
|
+
});
|
|
69
|
+
await incentive.deploy();
|
|
70
|
+
expect(
|
|
71
|
+
await incentiveFromAddress(
|
|
72
|
+
defaultOptions,
|
|
73
|
+
incentive.assertValidAddress(),
|
|
74
|
+
),
|
|
75
|
+
).toBeInstanceOf(ERC20Incentive);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test('can automatically instantiate ERC20VariableIncentive given an address', async () => {
|
|
79
|
+
const incentive = new ERC20VariableIncentive(defaultOptions, {
|
|
80
|
+
asset: zeroAddress,
|
|
81
|
+
reward: 1n,
|
|
82
|
+
limit: 10n,
|
|
83
|
+
});
|
|
84
|
+
await incentive.deploy();
|
|
85
|
+
expect(
|
|
86
|
+
await incentiveFromAddress(
|
|
87
|
+
defaultOptions,
|
|
88
|
+
incentive.assertValidAddress(),
|
|
89
|
+
),
|
|
90
|
+
).toBeInstanceOf(ERC20VariableIncentive);
|
|
91
|
+
});
|
|
92
|
+
});
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { aIncentiveAbi } from '@boostxyz/evm';
|
|
2
|
+
import {
|
|
3
|
+
AAllowListIncentive,
|
|
4
|
+
ACGDAIncentive,
|
|
5
|
+
AERC20Incentive,
|
|
6
|
+
AERC20VariableIncentive,
|
|
7
|
+
APointsIncentive,
|
|
8
|
+
} from '@boostxyz/evm/deploys/componentInterfaces.json';
|
|
9
|
+
import { readContract } from '@wagmi/core';
|
|
10
|
+
import type { Address, Hex } from 'viem';
|
|
11
|
+
import type { DeployableOptions } from '../Deployable/Deployable';
|
|
12
|
+
import { InvalidComponentInterfaceError } from '../errors';
|
|
13
|
+
import { AllowListIncentive } from './AllowListIncentive';
|
|
14
|
+
import { CGDAIncentive } from './CGDAIncentive';
|
|
15
|
+
import { ERC20Incentive } from './ERC20Incentive';
|
|
16
|
+
import { ERC20VariableIncentive } from './ERC20VariableIncentive';
|
|
17
|
+
// import { ERC1155Incentive } from './ERC1155Incentive';
|
|
18
|
+
import { PointsIncentive } from './PointsIncentive';
|
|
19
|
+
|
|
20
|
+
export {
|
|
21
|
+
AllowListIncentive,
|
|
22
|
+
CGDAIncentive,
|
|
23
|
+
// ERC1155Incentive,
|
|
24
|
+
ERC20Incentive,
|
|
25
|
+
PointsIncentive,
|
|
26
|
+
ERC20VariableIncentive,
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* A union type representing all valid protocol Incentive implementations
|
|
31
|
+
*
|
|
32
|
+
* @export
|
|
33
|
+
* @typedef {Incentive}
|
|
34
|
+
*/
|
|
35
|
+
export type Incentive =
|
|
36
|
+
| AllowListIncentive
|
|
37
|
+
| CGDAIncentive
|
|
38
|
+
| ERC20Incentive
|
|
39
|
+
// | ERC1155Incentive
|
|
40
|
+
| PointsIncentive
|
|
41
|
+
| ERC20VariableIncentive;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* A map of Incentive component interfaces to their constructors.
|
|
45
|
+
*
|
|
46
|
+
* @type {{ "0xc5b24b8e": typeof PointsIncentive; "0x8c901437": typeof ERC20Incentive; "0x0a466e6f": typeof AllowListIncentive; "0xa39e44d9": typeof CGDAIncentive; "0x6060409d": typeof ERC20VariableIncentive }}
|
|
47
|
+
*/
|
|
48
|
+
export const IncentiveByComponentInterface = {
|
|
49
|
+
[APointsIncentive as Hex]: PointsIncentive,
|
|
50
|
+
[AERC20Incentive as Hex]: ERC20Incentive,
|
|
51
|
+
// TODO: figure out why evm generates bad bytes4 here
|
|
52
|
+
['0x0a466e6f']: AllowListIncentive,
|
|
53
|
+
// [APointsIncentive as Hex]: ERC1155Incentive,
|
|
54
|
+
[ACGDAIncentive as Hex]: CGDAIncentive,
|
|
55
|
+
[AERC20VariableIncentive as Hex]: ERC20VariableIncentive,
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* A function that will read a contract's component interface using `getComponentInterface` and return the correct instantiated instance.
|
|
60
|
+
*
|
|
61
|
+
* @export
|
|
62
|
+
* @async
|
|
63
|
+
* @param {DeployableOptions} options
|
|
64
|
+
* @param {Address} address
|
|
65
|
+
* @returns {unknown}
|
|
66
|
+
* @throws {@link InvalidComponentInterfaceError}
|
|
67
|
+
*/
|
|
68
|
+
export async function incentiveFromAddress(
|
|
69
|
+
options: DeployableOptions,
|
|
70
|
+
address: Address,
|
|
71
|
+
) {
|
|
72
|
+
const interfaceId = (await readContract(options.config, {
|
|
73
|
+
abi: aIncentiveAbi,
|
|
74
|
+
functionName: 'getComponentInterface',
|
|
75
|
+
address,
|
|
76
|
+
})) as keyof typeof IncentiveByComponentInterface;
|
|
77
|
+
const Ctor = IncentiveByComponentInterface[interfaceId];
|
|
78
|
+
if (!Ctor) {
|
|
79
|
+
throw new InvalidComponentInterfaceError(
|
|
80
|
+
Object.keys(IncentiveByComponentInterface) as Hex[],
|
|
81
|
+
interfaceId as Hex,
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
return new Ctor(options, address);
|
|
85
|
+
}
|