@tokenops/sdk 1.5.1 → 2.0.0-alpha.1
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/CHANGELOG.md +198 -2
- package/CONTRIBUTING.md +4 -2
- package/README.md +146 -90
- package/SECURITY.md +7 -1
- package/SUPPORT.md +47 -0
- package/dist/{chunk-YQIBBEFJ.js → chunk-335Z2W67.js} +1 -1
- package/dist/{chunk-2NCLOQ56.cjs → chunk-3QHNYEQD.cjs} +77 -0
- package/dist/chunk-456VDDA3.js +370 -0
- package/dist/{chunk-SG65XWH7.js → chunk-4RAAATVY.js} +1 -3
- package/dist/{chunk-6BMP4ICG.js → chunk-4TSDNZQ3.js} +60 -2
- package/dist/{chunk-PUPKNW3R.cjs → chunk-5576FRT3.cjs} +30 -6
- package/dist/{chunk-AOP6HMPW.js → chunk-6GNR22OV.js} +75 -1
- package/dist/{chunk-NTZY6IB7.js → chunk-6NAVMWZQ.js} +4 -3
- package/dist/{chunk-C7BRZXJA.cjs → chunk-6PXXGACR.cjs} +8 -7
- package/dist/{chunk-IJFQ5L4I.js → chunk-74QFZ5MK.js} +4 -3
- package/dist/chunk-7AFPOE7N.cjs +59 -0
- package/dist/chunk-AXIPOR3C.js +56 -0
- package/dist/chunk-CTED3MTR.cjs +380 -0
- package/dist/{chunk-XGGTQQFH.js → chunk-DZHYSUGY.js} +28 -7
- package/dist/{chunk-OXTLPTO3.js → chunk-EAJ7SYHE.js} +4 -3
- package/dist/{chunk-V2PXZVBF.cjs → chunk-FGEB7RMY.cjs} +4 -4
- package/dist/chunk-GKKDAW44.js +8823 -0
- package/dist/{chunk-2PWNH3UE.js → chunk-H5POPGOZ.js} +63 -5
- package/dist/{chunk-W7IGCOVL.cjs → chunk-JQYC66TO.cjs} +9 -8
- package/dist/{chunk-PFXURMBZ.cjs → chunk-JZLGCTGK.cjs} +68 -8
- package/dist/{chunk-JYOTGRSO.cjs → chunk-KFRDLKMA.cjs} +61 -1
- package/dist/chunk-M4IT6DNJ.cjs +608 -0
- package/dist/{chunk-KLKI352M.cjs → chunk-MVDQMV25.cjs} +0 -3
- package/dist/chunk-NCVX3K2N.cjs +161 -0
- package/dist/chunk-NWFMBLSQ.js +4 -0
- package/dist/chunk-O5676ZWY.js +585 -0
- package/dist/chunk-PUX5VXDB.cjs +8845 -0
- package/dist/{chunk-IXLO7GO5.js → chunk-TWT3STIX.js} +46 -80
- package/dist/chunk-UG5RKLU2.cjs +6 -0
- package/dist/chunk-VP2B4WM2.js +154 -0
- package/dist/{chunk-5X5WL5CU.cjs → chunk-WJLECC22.cjs} +51 -88
- package/dist/{chunk-WENHUPZC.cjs → chunk-XAYGD4E4.cjs} +9 -8
- package/dist/core/addresses.d.ts +15 -3
- package/dist/core/brands.d.ts +8 -2
- package/dist/core/errors.d.ts +71 -10
- package/dist/core/preflight.d.ts +1 -0
- package/dist/fhe/erc7984-abi.d.ts +1 -0
- package/dist/fhe/index.cjs +34 -13
- package/dist/fhe/index.d.cts +1 -0
- package/dist/fhe/index.d.ts +1 -0
- package/dist/fhe/index.js +19 -6
- package/dist/fhe/mock-erc7984.d.ts +4 -4
- package/dist/fhe/operators.d.ts +160 -3
- package/dist/fhe/react/index.cjs +14 -0
- package/dist/fhe/react/index.d.cts +2 -0
- package/dist/fhe/react/index.d.ts +2 -0
- package/dist/fhe/react/index.js +6 -0
- package/dist/fhe/react/useEnsureOperator.d.ts +56 -0
- package/dist/fhe/react/useIsOperator.d.ts +54 -0
- package/dist/fhe/sepolia-encryptor-web.d.ts +18 -3
- package/dist/fhe/types.d.ts +6 -0
- package/dist/fhe-airdrop/abis/{cloneable.d.ts → airdrop-base.d.ts} +254 -396
- package/dist/fhe-airdrop/abis/compliance.d.ts +422 -0
- package/dist/fhe-airdrop/abis/ecdsa.d.ts +1316 -0
- package/dist/fhe-airdrop/abis/factory.d.ts +1319 -190
- package/dist/fhe-airdrop/abis/index.d.ts +5 -2
- package/dist/fhe-airdrop/abis/merkle.d.ts +1238 -0
- package/dist/fhe-airdrop/advanced/index.cjs +10 -12
- package/dist/fhe-airdrop/advanced/index.d.cts +34 -11
- package/dist/fhe-airdrop/advanced/index.d.ts +34 -11
- package/dist/fhe-airdrop/advanced/index.js +2 -8
- package/dist/fhe-airdrop/advanced/react/index.cjs +34 -48
- package/dist/fhe-airdrop/advanced/react/index.d.cts +9 -3
- package/dist/fhe-airdrop/advanced/react/index.d.ts +9 -3
- package/dist/fhe-airdrop/advanced/react/index.js +33 -48
- package/dist/fhe-airdrop/advanced/react/usePredictEcdsaAirdropAddress.d.ts +33 -0
- package/dist/fhe-airdrop/advanced/react/usePredictMerkleAirdropAddress.d.ts +27 -0
- package/dist/fhe-airdrop/airdrop-base.d.ts +600 -0
- package/dist/fhe-airdrop/campaign.d.ts +297 -0
- package/dist/fhe-airdrop/compliance.d.ts +302 -0
- package/dist/fhe-airdrop/constants.d.ts +33 -0
- package/dist/fhe-airdrop/ecdsa.d.ts +263 -0
- package/dist/fhe-airdrop/encryption.d.ts +92 -14
- package/dist/fhe-airdrop/errors.d.ts +245 -15
- package/dist/fhe-airdrop/factory.d.ts +533 -274
- package/dist/fhe-airdrop/guards.d.ts +273 -0
- package/dist/fhe-airdrop/index.cjs +1089 -33
- package/dist/fhe-airdrop/index.d.cts +46 -8
- package/dist/fhe-airdrop/index.d.ts +46 -8
- package/dist/fhe-airdrop/index.js +929 -7
- package/dist/fhe-airdrop/merkle-tree.d.ts +103 -0
- package/dist/fhe-airdrop/merkle.d.ts +180 -0
- package/dist/fhe-airdrop/react/_shared.d.ts +144 -71
- package/dist/fhe-airdrop/react/index.cjs +364 -413
- package/dist/fhe-airdrop/react/index.d.cts +53 -72
- package/dist/fhe-airdrop/react/index.d.ts +53 -72
- package/dist/fhe-airdrop/react/index.js +258 -369
- package/dist/fhe-airdrop/react/useAirdropGasFee.d.ts +10 -5
- package/dist/fhe-airdrop/react/useAirdropHasRole.d.ts +15 -6
- package/dist/fhe-airdrop/react/useAirdropPause.d.ts +30 -0
- package/dist/fhe-airdrop/react/useAirdropPaused.d.ts +17 -0
- package/dist/fhe-airdrop/react/useAirdropToken.d.ts +11 -4
- package/dist/fhe-airdrop/react/useAirdropWindow.d.ts +37 -0
- package/dist/fhe-airdrop/react/useClaimedAmount.d.ts +29 -0
- package/dist/fhe-airdrop/react/useComplianceManager.d.ts +16 -0
- package/dist/fhe-airdrop/react/useCreateEcdsaAirdrop.d.ts +28 -0
- package/dist/fhe-airdrop/react/useCreateMerkleAirdrop.d.ts +25 -0
- package/dist/fhe-airdrop/react/useEcdsaClaim.d.ts +23 -0
- package/dist/fhe-airdrop/react/useEffectiveUpgradeable.d.ts +20 -0
- package/dist/fhe-airdrop/react/useExtendClaimWindow.d.ts +17 -12
- package/dist/fhe-airdrop/react/useFactoryFees.d.ts +28 -0
- package/dist/fhe-airdrop/react/useFactoryRegistry.d.ts +35 -0
- package/dist/fhe-airdrop/react/useFundAirdrop.d.ts +35 -0
- package/dist/fhe-airdrop/react/useGrantInstanceRoles.d.ts +35 -0
- package/dist/fhe-airdrop/react/useMerkleClaim.d.ts +34 -0
- package/dist/fhe-airdrop/react/useMerkleRoot.d.ts +15 -0
- package/dist/fhe-airdrop/react/useSetMerkleRoot.d.ts +22 -0
- package/dist/fhe-airdrop/react/useWithdrawConfidential.d.ts +23 -0
- package/dist/fhe-airdrop/roles.d.ts +147 -0
- package/dist/fhe-airdrop/types.d.ts +68 -55
- package/dist/fhe-disperse/errors.d.ts +55 -0
- package/dist/fhe-disperse/index.cjs +34 -25
- package/dist/fhe-disperse/index.d.cts +1 -1
- package/dist/fhe-disperse/index.d.ts +1 -1
- package/dist/fhe-disperse/index.js +6 -5
- package/dist/fhe-disperse/react/index.cjs +42 -23
- package/dist/fhe-disperse/react/index.d.cts +3 -1
- package/dist/fhe-disperse/react/index.d.ts +3 -1
- package/dist/fhe-disperse/react/index.js +9 -6
- package/dist/fhe-vesting/advanced/index.cjs +8 -7
- package/dist/fhe-vesting/advanced/index.js +6 -5
- package/dist/fhe-vesting/advanced/react/index.cjs +12 -11
- package/dist/fhe-vesting/advanced/react/index.js +9 -8
- package/dist/fhe-vesting/index.cjs +35 -34
- package/dist/fhe-vesting/index.js +7 -6
- package/dist/fhe-vesting/manager.d.ts +19 -0
- package/dist/fhe-vesting/react/index.cjs +160 -140
- package/dist/fhe-vesting/react/index.d.cts +6 -4
- package/dist/fhe-vesting/react/index.d.ts +6 -4
- package/dist/fhe-vesting/react/index.js +24 -16
- package/dist/fhe-vesting/react/useAccessClaimableAmount.d.ts +11 -3
- package/dist/fhe-vesting/react/useAccessSettledAmount.d.ts +11 -3
- package/dist/fhe-vesting/react/useAccessTotalAllocation.d.ts +11 -3
- package/dist/fhe-vesting/react/useAccessVestedAmount.d.ts +11 -3
- package/dist/fhe-vesting/react/useAdminGetClaimableAmount.d.ts +1 -1
- package/dist/fhe-vesting/react/useAdminGetSettledAmount.d.ts +1 -1
- package/dist/fhe-vesting/react/useAdminGetTotalAllocation.d.ts +1 -1
- package/dist/fhe-vesting/react/useAdminGetVestedAmount.d.ts +1 -1
- package/dist/fhe-vesting/react/useAdminPartialClaim.d.ts +8 -0
- package/dist/fhe-vesting/react/useClaim.d.ts +1 -1
- package/dist/fhe-vesting/react/useDiscloseHandleToParty.d.ts +1 -1
- package/dist/fhe-vesting/react/useManagerDiscloseHandleToParty.d.ts +1 -1
- package/dist/fhe-vesting/react/usePartialClaim.d.ts +1 -1
- package/dist/fhe-vesting/react/useVestingInfo.d.ts +1 -1
- package/dist/fhe-vesting/types.d.ts +12 -1
- package/dist/index.cjs +27 -15
- package/dist/index.js +1 -1
- package/dist/testnet-faucet/index.cjs +17 -16
- package/dist/testnet-faucet/index.js +5 -4
- package/dist/testnet-faucet/react/index.cjs +11 -10
- package/dist/testnet-faucet/react/index.js +6 -5
- package/package.json +18 -9
- package/dist/chunk-4WPGQSNT.cjs +0 -44
- package/dist/chunk-6R4KNAPK.js +0 -1630
- package/dist/chunk-DUZIIRPF.js +0 -1655
- package/dist/chunk-MCRBVJGZ.cjs +0 -1637
- package/dist/chunk-ODLTEGHB.js +0 -41
- package/dist/chunk-ORFTDNFZ.js +0 -105
- package/dist/chunk-T46YXSBP.cjs +0 -109
- package/dist/chunk-TIUKIY5V.cjs +0 -1663
- package/dist/fhe-airdrop/advanced/factory-advanced.d.ts +0 -53
- package/dist/fhe-airdrop/advanced/react/usePredictAirdropAddress.d.ts +0 -49
- package/dist/fhe-airdrop/airdrop.d.ts +0 -310
- package/dist/fhe-airdrop/react/useAccessClaimAmount.d.ts +0 -31
- package/dist/fhe-airdrop/react/useAirdropCanExtendClaimWindow.d.ts +0 -7
- package/dist/fhe-airdrop/react/useAirdropClaim.d.ts +0 -27
- package/dist/fhe-airdrop/react/useAirdropClaimTypehash.d.ts +0 -10
- package/dist/fhe-airdrop/react/useAirdropClaimedSignatures.d.ts +0 -16
- package/dist/fhe-airdrop/react/useAirdropDeploymentBlockNumber.d.ts +0 -6
- package/dist/fhe-airdrop/react/useAirdropDomainSeparator.d.ts +0 -8
- package/dist/fhe-airdrop/react/useAirdropEndTime.d.ts +0 -10
- package/dist/fhe-airdrop/react/useAirdropFactoryCustomFee.d.ts +0 -17
- package/dist/fhe-airdrop/react/useAirdropFactoryDefaultGasFee.d.ts +0 -10
- package/dist/fhe-airdrop/react/useAirdropFactoryDisableCustomFee.d.ts +0 -15
- package/dist/fhe-airdrop/react/useAirdropFactoryFeeCollector.d.ts +0 -11
- package/dist/fhe-airdrop/react/useAirdropFactoryInitCodeHash.d.ts +0 -17
- package/dist/fhe-airdrop/react/useAirdropFactorySetCustomFee.d.ts +0 -17
- package/dist/fhe-airdrop/react/useAirdropFactorySetDefaultGasFee.d.ts +0 -16
- package/dist/fhe-airdrop/react/useAirdropFactorySetFeeCollector.d.ts +0 -15
- package/dist/fhe-airdrop/react/useAirdropGrantRole.d.ts +0 -16
- package/dist/fhe-airdrop/react/useAirdropHasClaimEnded.d.ts +0 -7
- package/dist/fhe-airdrop/react/useAirdropHasClaimStarted.d.ts +0 -7
- package/dist/fhe-airdrop/react/useAirdropIsClaimWindowActive.d.ts +0 -9
- package/dist/fhe-airdrop/react/useAirdropIsPaused.d.ts +0 -8
- package/dist/fhe-airdrop/react/useAirdropIsSignatureClaimed.d.ts +0 -22
- package/dist/fhe-airdrop/react/useAirdropIsSignatureValid.d.ts +0 -51
- package/dist/fhe-airdrop/react/useAirdropRevokeRole.d.ts +0 -15
- package/dist/fhe-airdrop/react/useAirdropStartTime.d.ts +0 -10
- package/dist/fhe-airdrop/react/useAirdropWithdrawGasFee.d.ts +0 -15
- package/dist/fhe-airdrop/react/useAirdropWithdrawOtherConfidentialToken.d.ts +0 -14
- package/dist/fhe-airdrop/react/useAirdropWithdrawOtherToken.d.ts +0 -14
- package/dist/fhe-airdrop/react/useClaim.d.ts +0 -31
- package/dist/fhe-airdrop/react/useConfidentialAirdropFactoryImplementation.d.ts +0 -11
- package/dist/fhe-airdrop/react/useCreateAndFundConfidentialAirdrop.d.ts +0 -41
- package/dist/fhe-airdrop/react/useCreateAndFundConfidentialAirdropAndGetAddress.d.ts +0 -48
- package/dist/fhe-airdrop/react/useCreateConfidentialAirdrop.d.ts +0 -29
- package/dist/fhe-airdrop/react/useCreateConfidentialAirdropAndGetAddress.d.ts +0 -31
- package/dist/fhe-airdrop/react/useDisableCustomFee.d.ts +0 -14
- package/dist/fhe-airdrop/react/useFactoryCustomFee.d.ts +0 -17
- package/dist/fhe-airdrop/react/useFactoryDefaultGasFee.d.ts +0 -10
- package/dist/fhe-airdrop/react/useFactoryFeeCollector.d.ts +0 -11
- package/dist/fhe-airdrop/react/useFactoryInitCodeHash.d.ts +0 -17
- package/dist/fhe-airdrop/react/useFundConfidentialAirdrop.d.ts +0 -33
- package/dist/fhe-airdrop/react/useGetClaimAmount.d.ts +0 -30
- package/dist/fhe-airdrop/react/usePreflightCreateAirdrop.d.ts +0 -51
- package/dist/fhe-airdrop/react/useSetCustomFee.d.ts +0 -16
- package/dist/fhe-airdrop/react/useSetDefaultGasFee.d.ts +0 -15
- package/dist/fhe-airdrop/react/useSetFeeCollector.d.ts +0 -14
- package/dist/fhe-airdrop/react/useSetPaused.d.ts +0 -14
- package/dist/fhe-airdrop/react/useSignClaimAuthorization.d.ts +0 -31
- package/dist/fhe-airdrop/react/useWithdraw.d.ts +0 -12
- package/dist/fhe-airdrop/react/useWithdrawOtherConfidentialToken.d.ts +0 -13
- package/dist/fhe-airdrop/react/useWithdrawOtherToken.d.ts +0 -13
- package/dist/fhe-vesting/react/useGetClaimableAmount.d.ts +0 -13
- package/dist/fhe-vesting/react/useGetSettledAmount.d.ts +0 -14
- package/dist/fhe-vesting/react/useGetTotalAllocation.d.ts +0 -13
- package/dist/fhe-vesting/react/useGetVestedAmount.d.ts +0 -25
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
import { resolveEncryptor, encryptUint64 } from './chunk-GKKDAW44.js';
|
|
2
|
+
import { assertPredictionFresh, FeeCollectorSelfAdministeredError } from './chunk-O5676ZWY.js';
|
|
3
|
+
import { normaliseAddress } from './chunk-ZA673I3O.js';
|
|
4
|
+
import { InvalidArgumentError, MissingWalletClientError, MissingAccountError, ContractRevertError, MissingEncryptorError, isTokenOpsSdkError, UnknownWriteFailureError } from './chunk-QBJ7O2B4.js';
|
|
5
|
+
import { StandardMerkleTree } from '@openzeppelin/merkle-tree';
|
|
6
|
+
import { keccak256, encodeAbiParameters, isAddress, isAddressEqual, zeroAddress } from 'viem';
|
|
7
|
+
|
|
8
|
+
function leafOf(args) {
|
|
9
|
+
const inner = keccak256(
|
|
10
|
+
encodeAbiParameters(
|
|
11
|
+
[{ type: "address" }, { type: "address" }, { type: "bytes32" }],
|
|
12
|
+
[args.instance, args.recipient, args.handle]
|
|
13
|
+
)
|
|
14
|
+
);
|
|
15
|
+
return keccak256(inner);
|
|
16
|
+
}
|
|
17
|
+
var HANDLE_PATTERN = /^0x[0-9a-fA-F]{64}$/;
|
|
18
|
+
function assertLeaves(instance, leaves, method) {
|
|
19
|
+
if (!isAddress(instance, { strict: false })) {
|
|
20
|
+
throw new InvalidArgumentError({
|
|
21
|
+
method,
|
|
22
|
+
argument: "instance",
|
|
23
|
+
reason: "is not a 20-byte hex address",
|
|
24
|
+
value: instance
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
if (isAddressEqual(instance, zeroAddress)) {
|
|
28
|
+
throw new InvalidArgumentError({
|
|
29
|
+
method,
|
|
30
|
+
argument: "instance",
|
|
31
|
+
reason: "is the zero address; leaves must be scoped to the airdrop instance"
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
if (leaves.length === 0) {
|
|
35
|
+
throw new InvalidArgumentError({
|
|
36
|
+
method,
|
|
37
|
+
argument: "leaves",
|
|
38
|
+
reason: "a tree needs at least one leaf"
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
const seen = /* @__PURE__ */ new Map();
|
|
42
|
+
leaves.forEach((leaf, index) => {
|
|
43
|
+
if (!isAddress(leaf.recipient, { strict: false })) {
|
|
44
|
+
throw new InvalidArgumentError({
|
|
45
|
+
method,
|
|
46
|
+
argument: `leaves[${index}].recipient`,
|
|
47
|
+
reason: "is not a 20-byte hex address",
|
|
48
|
+
value: leaf.recipient
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
if (isAddressEqual(leaf.recipient, zeroAddress)) {
|
|
52
|
+
throw new InvalidArgumentError({
|
|
53
|
+
method,
|
|
54
|
+
argument: `leaves[${index}].recipient`,
|
|
55
|
+
reason: "is the zero address, whose leaf can never be claimed"
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
if (!HANDLE_PATTERN.test(leaf.handle)) {
|
|
59
|
+
throw new InvalidArgumentError({
|
|
60
|
+
method,
|
|
61
|
+
argument: `leaves[${index}].handle`,
|
|
62
|
+
reason: "is not a 32-byte hex handle; the tree would commit to a value no claim can reproduce",
|
|
63
|
+
value: leaf.handle
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
const key = leaf.recipient.toLowerCase();
|
|
67
|
+
const first = seen.get(key);
|
|
68
|
+
if (first !== void 0) {
|
|
69
|
+
throw new InvalidArgumentError({
|
|
70
|
+
method,
|
|
71
|
+
argument: `leaves[${index}].recipient`,
|
|
72
|
+
reason: `appears twice (also at index ${first}); one root pays max, not sum, of a recipient's leaves \u2014 merge them into a single cumulative total`
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
seen.set(key, index);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
function buildMerkleTree(args) {
|
|
79
|
+
return buildMerkleTreeInternal(args, "buildMerkleTree");
|
|
80
|
+
}
|
|
81
|
+
function buildMerkleTreeInternal({ instance, leaves }, method) {
|
|
82
|
+
assertLeaves(instance, leaves, method);
|
|
83
|
+
const airdrop = normaliseAddress(instance);
|
|
84
|
+
const accounts = leaves.map((leaf) => normaliseAddress(leaf.recipient));
|
|
85
|
+
const rows = accounts.map((account, i) => [airdrop, account, leaves[i].handle]);
|
|
86
|
+
const tree = StandardMerkleTree.of(rows, ["address", "address", "bytes32"]);
|
|
87
|
+
return {
|
|
88
|
+
root: tree.root,
|
|
89
|
+
// `getProof(i)` indexes the INPUT array, not the tree: `StandardMerkleTree`
|
|
90
|
+
// sorts leaves internally but keeps `values` in insertion order, so entry
|
|
91
|
+
// `i` always belongs to `leaves[i]`.
|
|
92
|
+
entries: leaves.map((leaf, i) => ({
|
|
93
|
+
...leaf,
|
|
94
|
+
recipient: accounts[i],
|
|
95
|
+
merkleProof: tree.getProof(i)
|
|
96
|
+
}))
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
var MAX_UINT64 = (1n << 64n) - 1n;
|
|
100
|
+
function validateCampaignRecipients(recipients) {
|
|
101
|
+
validateCampaignRecipientsInternal(recipients, "validateCampaignRecipients");
|
|
102
|
+
}
|
|
103
|
+
function validateCampaignRecipientsInternal(recipients, method) {
|
|
104
|
+
if (recipients.length === 0) {
|
|
105
|
+
throw new InvalidArgumentError({
|
|
106
|
+
method,
|
|
107
|
+
argument: "recipients",
|
|
108
|
+
reason: "a campaign needs at least one recipient"
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
const seen = /* @__PURE__ */ new Map();
|
|
112
|
+
recipients.forEach((entry, index) => {
|
|
113
|
+
if (!isAddress(entry.recipient, { strict: false })) {
|
|
114
|
+
throw new InvalidArgumentError({
|
|
115
|
+
method,
|
|
116
|
+
argument: `recipients[${index}].recipient`,
|
|
117
|
+
reason: "is not a 20-byte hex address",
|
|
118
|
+
value: entry.recipient
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
if (isAddressEqual(entry.recipient, zeroAddress)) {
|
|
122
|
+
throw new InvalidArgumentError({
|
|
123
|
+
method,
|
|
124
|
+
argument: `recipients[${index}].recipient`,
|
|
125
|
+
reason: "is the zero address, whose leaf can never be claimed"
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
if (entry.cumulativeTotal < 0n || entry.cumulativeTotal > MAX_UINT64) {
|
|
129
|
+
throw new InvalidArgumentError({
|
|
130
|
+
method,
|
|
131
|
+
argument: `recipients[${index}].cumulativeTotal`,
|
|
132
|
+
// Deliberately no `value`: the total is confidential.
|
|
133
|
+
reason: "is outside uint64 range (0..2^64-1)"
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
const key = entry.recipient.toLowerCase();
|
|
137
|
+
const first = seen.get(key);
|
|
138
|
+
if (first !== void 0) {
|
|
139
|
+
throw new InvalidArgumentError({
|
|
140
|
+
method,
|
|
141
|
+
argument: `recipients[${index}].recipient`,
|
|
142
|
+
reason: `appears twice (also at index ${first}); one root pays max, not sum, of a recipient's leaves \u2014 merge them into a single cumulative total`
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
seen.set(key, index);
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
async function encryptRoster({ instance, recipients, encryptor }, method) {
|
|
149
|
+
validateCampaignRecipientsInternal(recipients, method);
|
|
150
|
+
if (!isAddress(instance, { strict: false })) {
|
|
151
|
+
throw new InvalidArgumentError({
|
|
152
|
+
method,
|
|
153
|
+
argument: "instance",
|
|
154
|
+
reason: "is not a 20-byte hex address",
|
|
155
|
+
value: instance
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
if (isAddressEqual(instance, zeroAddress)) {
|
|
159
|
+
throw new InvalidArgumentError({
|
|
160
|
+
method,
|
|
161
|
+
argument: "instance",
|
|
162
|
+
reason: "is the zero address; inputs must be bound to the airdrop instance"
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
const enc = resolveEncryptor(encryptor);
|
|
166
|
+
if (!enc) {
|
|
167
|
+
throw new MissingEncryptorError(method, {
|
|
168
|
+
hint: "Pass an encryptor instance, or a lazy factory that returns one."
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
const airdrop = normaliseAddress(instance);
|
|
172
|
+
const accounts = recipients.map((r) => normaliseAddress(r.recipient));
|
|
173
|
+
const encrypted = await Promise.all(
|
|
174
|
+
recipients.map(
|
|
175
|
+
(r, i) => encryptUint64({
|
|
176
|
+
encryptor: enc,
|
|
177
|
+
contractAddress: airdrop,
|
|
178
|
+
userAddress: accounts[i],
|
|
179
|
+
value: r.cumulativeTotal
|
|
180
|
+
})
|
|
181
|
+
)
|
|
182
|
+
);
|
|
183
|
+
return accounts.map((recipient, i) => ({
|
|
184
|
+
recipient,
|
|
185
|
+
handle: encrypted[i].handle,
|
|
186
|
+
inputProof: encrypted[i].inputProof
|
|
187
|
+
}));
|
|
188
|
+
}
|
|
189
|
+
async function encryptCampaignAmounts(args) {
|
|
190
|
+
return encryptRoster(args, "encryptCampaignAmounts");
|
|
191
|
+
}
|
|
192
|
+
async function buildMerkleCampaign({
|
|
193
|
+
instance,
|
|
194
|
+
recipients,
|
|
195
|
+
encryptor
|
|
196
|
+
}) {
|
|
197
|
+
const leaves = await encryptRoster({ instance, recipients, encryptor }, "buildMerkleCampaign");
|
|
198
|
+
return buildMerkleTreeInternal({ instance, leaves }, "buildMerkleCampaign");
|
|
199
|
+
}
|
|
200
|
+
async function planMerkleCampaign({
|
|
201
|
+
factory,
|
|
202
|
+
params,
|
|
203
|
+
mode,
|
|
204
|
+
creator,
|
|
205
|
+
userSalt,
|
|
206
|
+
recipients,
|
|
207
|
+
encryptor
|
|
208
|
+
}) {
|
|
209
|
+
validateCampaignRecipientsInternal(recipients, "planMerkleCampaign");
|
|
210
|
+
const initCodeHashBefore = await factory.getMerkleInitCodeHash({ params, mode });
|
|
211
|
+
const predictedAddress = await factory.predictMerkleAirdropAddress({
|
|
212
|
+
params,
|
|
213
|
+
mode,
|
|
214
|
+
deployer: creator,
|
|
215
|
+
userSalt
|
|
216
|
+
});
|
|
217
|
+
const campaign = await buildMerkleCampaign({
|
|
218
|
+
instance: predictedAddress,
|
|
219
|
+
recipients,
|
|
220
|
+
encryptor
|
|
221
|
+
});
|
|
222
|
+
const initCodeHashAfter = await factory.getMerkleInitCodeHash({ params, mode });
|
|
223
|
+
assertPredictionFresh({
|
|
224
|
+
variant: "merkle",
|
|
225
|
+
initCodeHashBefore,
|
|
226
|
+
initCodeHashAfter,
|
|
227
|
+
predictedAddress,
|
|
228
|
+
method: "planMerkleCampaign"
|
|
229
|
+
});
|
|
230
|
+
return { ...campaign, predictedAddress, initCodeHashBefore, initCodeHashAfter };
|
|
231
|
+
}
|
|
232
|
+
async function rotateMerkleRoot({
|
|
233
|
+
airdrop,
|
|
234
|
+
recipients,
|
|
235
|
+
encryptor,
|
|
236
|
+
account
|
|
237
|
+
}) {
|
|
238
|
+
const campaign = await buildMerkleCampaign({
|
|
239
|
+
instance: airdrop.address,
|
|
240
|
+
recipients,
|
|
241
|
+
encryptor
|
|
242
|
+
});
|
|
243
|
+
const hash = await airdrop.setMerkleRoot({ newRoot: campaign.root, account });
|
|
244
|
+
return { ...campaign, hash };
|
|
245
|
+
}
|
|
246
|
+
var ASSIGNABLE_ROLES = [
|
|
247
|
+
{ key: "pauser", role: "PAUSER_ROLE" },
|
|
248
|
+
{ key: "windowAdmin", role: "WINDOW_ADMIN_ROLE" },
|
|
249
|
+
{ key: "treasury", role: "TREASURY_ROLE" },
|
|
250
|
+
{ key: "rescuer", role: "RESCUER_ROLE" },
|
|
251
|
+
{ key: "disclosureAdmin", role: "DISCLOSURE_ADMIN_ROLE" },
|
|
252
|
+
{ key: "upgrader", role: "UPGRADER_ROLE" },
|
|
253
|
+
{ key: "merkleAdmin", role: "MERKLE_ADMIN_ROLE", variant: "merkle" },
|
|
254
|
+
{ key: "signer", role: "SIGNER_ROLE", variant: "ecdsa" }
|
|
255
|
+
];
|
|
256
|
+
function planInstanceRoleSplit(args) {
|
|
257
|
+
const { assignment, caller, airdropType } = args;
|
|
258
|
+
if (assignment.feeCollector !== void 0) {
|
|
259
|
+
throw new FeeCollectorSelfAdministeredError({ requestedGrantee: assignment.feeCollector });
|
|
260
|
+
}
|
|
261
|
+
const steps = [];
|
|
262
|
+
for (const { key, role, variant } of ASSIGNABLE_ROLES) {
|
|
263
|
+
const account = assignment[key];
|
|
264
|
+
if (account === void 0) continue;
|
|
265
|
+
if (variant !== void 0 && variant !== airdropType) {
|
|
266
|
+
throw new InvalidArgumentError({
|
|
267
|
+
method: "planInstanceRoleSplit",
|
|
268
|
+
argument: `assignment.${key}`,
|
|
269
|
+
reason: `${role} only exists on ${variant} campaigns; this is a(n) ${airdropType} campaign`
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
steps.push({ kind: "grant", role, account });
|
|
273
|
+
}
|
|
274
|
+
if (assignment.admin !== void 0) {
|
|
275
|
+
if (isAddressEqual(assignment.admin, zeroAddress)) {
|
|
276
|
+
throw new InvalidArgumentError({
|
|
277
|
+
method: "planInstanceRoleSplit",
|
|
278
|
+
argument: "assignment.admin",
|
|
279
|
+
reason: "granting DEFAULT_ADMIN_ROLE to the zero address is never valid"
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
steps.push({ kind: "grant", role: "DEFAULT_ADMIN_ROLE", account: assignment.admin });
|
|
283
|
+
steps.push({ kind: "revoke", role: "DEFAULT_ADMIN_ROLE", account: caller });
|
|
284
|
+
}
|
|
285
|
+
return steps;
|
|
286
|
+
}
|
|
287
|
+
function roleGetterAbiEntry(name) {
|
|
288
|
+
return {
|
|
289
|
+
inputs: [],
|
|
290
|
+
name,
|
|
291
|
+
outputs: [{ internalType: "bytes32", name: "", type: "bytes32" }],
|
|
292
|
+
stateMutability: "view",
|
|
293
|
+
type: "function"
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
var ROLE_GETTER_ABI = [
|
|
297
|
+
roleGetterAbiEntry("PAUSER_ROLE"),
|
|
298
|
+
roleGetterAbiEntry("WINDOW_ADMIN_ROLE"),
|
|
299
|
+
roleGetterAbiEntry("TREASURY_ROLE"),
|
|
300
|
+
roleGetterAbiEntry("RESCUER_ROLE"),
|
|
301
|
+
roleGetterAbiEntry("DISCLOSURE_ADMIN_ROLE"),
|
|
302
|
+
roleGetterAbiEntry("UPGRADER_ROLE"),
|
|
303
|
+
roleGetterAbiEntry("MERKLE_ADMIN_ROLE"),
|
|
304
|
+
roleGetterAbiEntry("SIGNER_ROLE")
|
|
305
|
+
];
|
|
306
|
+
var DEFAULT_ADMIN_ROLE_CONSTANT = `0x${"0".repeat(64)}`;
|
|
307
|
+
async function resolveRoleConstant(airdrop, role) {
|
|
308
|
+
if (role === "DEFAULT_ADMIN_ROLE") return DEFAULT_ADMIN_ROLE_CONSTANT;
|
|
309
|
+
const result = await airdrop.publicClient.readContract({
|
|
310
|
+
address: airdrop.address,
|
|
311
|
+
abi: ROLE_GETTER_ABI,
|
|
312
|
+
functionName: role
|
|
313
|
+
});
|
|
314
|
+
return result;
|
|
315
|
+
}
|
|
316
|
+
function toOutcomeError(step, airdrop, error) {
|
|
317
|
+
if (isTokenOpsSdkError(error)) return error;
|
|
318
|
+
return new UnknownWriteFailureError({
|
|
319
|
+
method: `grantInstanceRoles.${step.kind}.${step.role}`,
|
|
320
|
+
contractAddress: airdrop.address,
|
|
321
|
+
cause: error
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
async function grantInstanceRoles(args) {
|
|
325
|
+
const { airdrop, assignment, revokeFromCreator = true } = args;
|
|
326
|
+
const wallet = airdrop.walletClient;
|
|
327
|
+
if (!wallet) {
|
|
328
|
+
throw new MissingWalletClientError("grantInstanceRoles");
|
|
329
|
+
}
|
|
330
|
+
const callerAccount = wallet.account;
|
|
331
|
+
if (!callerAccount) {
|
|
332
|
+
throw new MissingAccountError("grantInstanceRoles");
|
|
333
|
+
}
|
|
334
|
+
const caller = typeof callerAccount === "string" ? callerAccount : callerAccount.address;
|
|
335
|
+
const airdropType = await airdrop.airdropType() === 1 ? "merkle" : "ecdsa";
|
|
336
|
+
let steps = planInstanceRoleSplit({ assignment, caller, airdropType });
|
|
337
|
+
if (!revokeFromCreator) {
|
|
338
|
+
steps = steps.filter((step) => !(step.kind === "revoke" && step.role === "DEFAULT_ADMIN_ROLE"));
|
|
339
|
+
}
|
|
340
|
+
const outcomes = [];
|
|
341
|
+
for (const step of steps) {
|
|
342
|
+
try {
|
|
343
|
+
const role = await resolveRoleConstant(airdrop, step.role);
|
|
344
|
+
const hash = step.kind === "grant" ? await airdrop.grantRole({ role, holder: step.account, account: caller }) : await airdrop.revokeRole({ role, holder: step.account, account: caller });
|
|
345
|
+
const receipt = await airdrop.publicClient.waitForTransactionReceipt({ hash });
|
|
346
|
+
if (receipt.status !== "success") {
|
|
347
|
+
outcomes.push({
|
|
348
|
+
role: step.role,
|
|
349
|
+
account: step.account,
|
|
350
|
+
error: new ContractRevertError({
|
|
351
|
+
method: `grantInstanceRoles.${step.kind}.${step.role}`,
|
|
352
|
+
contractAddress: airdrop.address,
|
|
353
|
+
message: `grantInstanceRoles.${step.kind}.${step.role}: transaction ${hash} was mined with a reverted status; the role change did not apply.`
|
|
354
|
+
})
|
|
355
|
+
});
|
|
356
|
+
continue;
|
|
357
|
+
}
|
|
358
|
+
outcomes.push({ role: step.role, account: step.account, hash });
|
|
359
|
+
} catch (error) {
|
|
360
|
+
outcomes.push({
|
|
361
|
+
role: step.role,
|
|
362
|
+
account: step.account,
|
|
363
|
+
error: toOutcomeError(step, airdrop, error)
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
return outcomes;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
export { buildMerkleCampaign, buildMerkleTree, encryptCampaignAmounts, grantInstanceRoles, leafOf, planInstanceRoleSplit, planMerkleCampaign, rotateMerkleRoot, validateCampaignRecipients };
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { TokenOpsSdkError, ContractRevertError, InvalidArgumentError, OperatorNotApprovedError, InvalidSignatureError, FheHandleNotAllowedError, TransferFailedError, FeatureDisabledError, BatchTooLargeError, InsufficientBalanceError, InsufficientFeeError, ReentrancyError, AlreadyInitializedError, AccessDeniedError, PausedError, UnknownWriteFailureError, WalletRejectedError, WalletChainMismatchError, InsufficientGasFundsError, NetworkError } from './chunk-QBJ7O2B4.js';
|
|
2
2
|
import { decodeErrorResult, BaseError, ContractFunctionRevertedError, UserRejectedRequestError, TransactionRejectedRpcError, ChainMismatchError, InsufficientFundsError, HttpRequestError, TimeoutError } from 'viem';
|
|
3
3
|
|
|
4
|
-
// src/core/version.ts
|
|
5
|
-
var SDK_VERSION = "1.0.0";
|
|
6
4
|
var ERC7984_ERRORS_ABI = [
|
|
7
5
|
{
|
|
8
6
|
type: "error",
|
|
@@ -378,4 +376,4 @@ function coerceRevertHex(value) {
|
|
|
378
376
|
return void 0;
|
|
379
377
|
}
|
|
380
378
|
|
|
381
|
-
export {
|
|
379
|
+
export { isContractRevert, mapContractRevert };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { erc7984OperatorAbi } from './chunk-7VELUOMI.js';
|
|
1
2
|
import { normaliseAddress } from './chunk-ZA673I3O.js';
|
|
2
|
-
import { withTelemetry } from './chunk-Q2GP5UDC.js';
|
|
3
3
|
import { TokenOpsContractError } from './chunk-QBJ7O2B4.js';
|
|
4
|
+
import { withTelemetry } from './chunk-Q2GP5UDC.js';
|
|
4
5
|
|
|
5
6
|
// src/fhe/operators.ts
|
|
6
7
|
var ERC7984_SET_OPERATOR_ABI = [
|
|
@@ -92,5 +93,62 @@ async function revokeOperator(args) {
|
|
|
92
93
|
});
|
|
93
94
|
});
|
|
94
95
|
}
|
|
96
|
+
async function isOperator(args) {
|
|
97
|
+
const token = normaliseAddress(args.token);
|
|
98
|
+
const holder = normaliseAddress(args.holder);
|
|
99
|
+
const spender = normaliseAddress(args.spender);
|
|
100
|
+
return withTelemetry(args.telemetry, "fhe.isOperator", async () => {
|
|
101
|
+
try {
|
|
102
|
+
return await args.publicClient.readContract({
|
|
103
|
+
address: token,
|
|
104
|
+
abi: erc7984OperatorAbi,
|
|
105
|
+
functionName: "isOperator",
|
|
106
|
+
args: [holder, spender]
|
|
107
|
+
});
|
|
108
|
+
} catch (err) {
|
|
109
|
+
throw new TokenOpsContractError(
|
|
110
|
+
`isOperator: readContract failed (token=${token}, holder=${holder}, spender=${spender})`,
|
|
111
|
+
{ contract: "ERC7984", call: "isOperator", token, holder, spender, cause: err }
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
async function ensureOperator(args) {
|
|
117
|
+
return withTelemetry(args.telemetry, "fhe.ensureOperator", async () => {
|
|
118
|
+
if (args.deadline <= 0n || args.deadline > ERC7984_OPERATOR_MAX_DEADLINE) {
|
|
119
|
+
throw new TokenOpsContractError(
|
|
120
|
+
`ensureOperator: deadline ${args.deadline} out of range (0, ${ERC7984_OPERATOR_MAX_DEADLINE}]`,
|
|
121
|
+
{ contract: "ERC7984", call: "ensureOperator", deadline: args.deadline.toString() }
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
const fromAccount = args.account ?? args.walletClient.account;
|
|
125
|
+
if (!fromAccount) {
|
|
126
|
+
throw new TokenOpsContractError(
|
|
127
|
+
"ensureOperator: no account available \u2014 pass `account` explicitly or attach an account to the walletClient",
|
|
128
|
+
{ contract: "ERC7984", call: "ensureOperator" }
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
const holder = typeof fromAccount === "string" ? fromAccount : fromAccount.address;
|
|
132
|
+
const authorized = await isOperator({
|
|
133
|
+
publicClient: args.publicClient,
|
|
134
|
+
token: args.token,
|
|
135
|
+
holder,
|
|
136
|
+
spender: args.spender
|
|
137
|
+
});
|
|
138
|
+
if (authorized) {
|
|
139
|
+
return { alreadyOperator: true, hash: null };
|
|
140
|
+
}
|
|
141
|
+
const hash = await setOperator({
|
|
142
|
+
publicClient: args.publicClient,
|
|
143
|
+
walletClient: args.walletClient,
|
|
144
|
+
...args.account !== void 0 ? { account: args.account } : {},
|
|
145
|
+
token: args.token,
|
|
146
|
+
spender: args.spender,
|
|
147
|
+
deadline: args.deadline,
|
|
148
|
+
...args.waitForReceipt !== void 0 ? { waitForReceipt: args.waitForReceipt } : {}
|
|
149
|
+
});
|
|
150
|
+
return { alreadyOperator: false, hash };
|
|
151
|
+
});
|
|
152
|
+
}
|
|
95
153
|
|
|
96
|
-
export { ERC7984_OPERATOR_MAX_DEADLINE, ERC7984_SET_OPERATOR_ABI, revokeOperator, setOperator };
|
|
154
|
+
export { ERC7984_OPERATOR_MAX_DEADLINE, ERC7984_SET_OPERATOR_ABI, ensureOperator, isOperator, revokeOperator, setOperator };
|
|
@@ -6,14 +6,26 @@ var chains = require('viem/chains');
|
|
|
6
6
|
var DEPLOYED_ADDRESSES = {
|
|
7
7
|
fheVesting: {
|
|
8
8
|
confidentialVestingFactory: {
|
|
9
|
-
[chains.sepolia.id]: "
|
|
9
|
+
[chains.sepolia.id]: "0x059d6Bb8ff9a13E794fe416d4757d7310CdC69ab"
|
|
10
10
|
// mainnet omitted — not deployed.
|
|
11
11
|
}
|
|
12
12
|
},
|
|
13
|
+
// Airdrop v2 (tokenops-fhe-airdrop-v2 @ 8e5b144). The four contracts deploy
|
|
14
|
+
// together in one scripted run, so a chain either has all of them or none —
|
|
15
|
+
// which is what `chainsWithDeployment` assumes.
|
|
13
16
|
fheAirdrop: {
|
|
14
|
-
|
|
15
|
-
[chains.sepolia.id]: "
|
|
16
|
-
// mainnet omitted — not deployed.
|
|
17
|
+
airdropFactory: {
|
|
18
|
+
[chains.sepolia.id]: "0x383083B6f13a0ee513596A6750B511c5E482d2d1"
|
|
19
|
+
// mainnet omitted — ZamaConfig-gated, not deployed.
|
|
20
|
+
},
|
|
21
|
+
ecdsaImplementation: {
|
|
22
|
+
[chains.sepolia.id]: "0xefE40570C1837210f8E4Ae938635e11bd1ae788E"
|
|
23
|
+
},
|
|
24
|
+
merkleImplementation: {
|
|
25
|
+
[chains.sepolia.id]: "0x9f3156546744F3ceE98Dc44bed817d98A8b8ae74"
|
|
26
|
+
},
|
|
27
|
+
complianceManagerImplementation: {
|
|
28
|
+
[chains.sepolia.id]: "0x6adA841250C048364d1d3027958C662Dd4E62136"
|
|
17
29
|
}
|
|
18
30
|
},
|
|
19
31
|
fheDisperse: {
|
|
@@ -64,10 +76,19 @@ function requireFheVestingFactoryAddress(chainId) {
|
|
|
64
76
|
return requireDeployedAddress("fheVesting", "confidentialVestingFactory", chainId);
|
|
65
77
|
}
|
|
66
78
|
function getFheAirdropFactoryAddress(chainId) {
|
|
67
|
-
return getDeployedAddress("fheAirdrop", "
|
|
79
|
+
return getDeployedAddress("fheAirdrop", "airdropFactory", chainId);
|
|
68
80
|
}
|
|
69
81
|
function requireFheAirdropFactoryAddress(chainId) {
|
|
70
|
-
return requireDeployedAddress("fheAirdrop", "
|
|
82
|
+
return requireDeployedAddress("fheAirdrop", "airdropFactory", chainId);
|
|
83
|
+
}
|
|
84
|
+
function getFheAirdropEcdsaImplementationAddress(chainId) {
|
|
85
|
+
return getDeployedAddress("fheAirdrop", "ecdsaImplementation", chainId);
|
|
86
|
+
}
|
|
87
|
+
function getFheAirdropMerkleImplementationAddress(chainId) {
|
|
88
|
+
return getDeployedAddress("fheAirdrop", "merkleImplementation", chainId);
|
|
89
|
+
}
|
|
90
|
+
function getFheAirdropComplianceImplementationAddress(chainId) {
|
|
91
|
+
return getDeployedAddress("fheAirdrop", "complianceManagerImplementation", chainId);
|
|
71
92
|
}
|
|
72
93
|
function getFheDisperseSingletonAddress(chainId) {
|
|
73
94
|
return getDeployedAddress("fheDisperse", "disperseConfidentialSingleton", chainId);
|
|
@@ -115,7 +136,10 @@ exports.chainsWithDeployment = chainsWithDeployment;
|
|
|
115
136
|
exports.chainsWithKnownRegistryEntry = chainsWithKnownRegistryEntry;
|
|
116
137
|
exports.getConfidentialTestTokenAddress = getConfidentialTestTokenAddress;
|
|
117
138
|
exports.getDeployedAddress = getDeployedAddress;
|
|
139
|
+
exports.getFheAirdropComplianceImplementationAddress = getFheAirdropComplianceImplementationAddress;
|
|
140
|
+
exports.getFheAirdropEcdsaImplementationAddress = getFheAirdropEcdsaImplementationAddress;
|
|
118
141
|
exports.getFheAirdropFactoryAddress = getFheAirdropFactoryAddress;
|
|
142
|
+
exports.getFheAirdropMerkleImplementationAddress = getFheAirdropMerkleImplementationAddress;
|
|
119
143
|
exports.getFheDisperseSingletonAddress = getFheDisperseSingletonAddress;
|
|
120
144
|
exports.getFheVestingFactoryAddress = getFheVestingFactoryAddress;
|
|
121
145
|
exports.getTestTokenAddress = getTestTokenAddress;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { asExternalInputProof, asEncryptedHandle } from './chunk-KWFFIJYX.js';
|
|
1
2
|
import { InvalidArgumentError } from './chunk-QBJ7O2B4.js';
|
|
3
|
+
import { bytesToHex } from 'viem';
|
|
2
4
|
|
|
3
5
|
// src/fhe/scale-ratio.ts
|
|
4
6
|
var FHE_SPLIT_DENOMINATOR = 90090000n;
|
|
@@ -131,5 +133,77 @@ function toIntegerBigInt(value, method, argument) {
|
|
|
131
133
|
}
|
|
132
134
|
return BigInt(value);
|
|
133
135
|
}
|
|
136
|
+
function resolveEncryptor(source) {
|
|
137
|
+
if (source === void 0) return void 0;
|
|
138
|
+
return typeof source === "function" ? source() : source;
|
|
139
|
+
}
|
|
140
|
+
var MAX_UINT642 = (1n << 64n) - 1n;
|
|
141
|
+
function assertUint64(value, label) {
|
|
142
|
+
if (value < 0n || value > MAX_UINT642) {
|
|
143
|
+
throw new InvalidArgumentError({
|
|
144
|
+
method: "encryptUint64",
|
|
145
|
+
argument: label,
|
|
146
|
+
reason: `does not fit in uint64 (0..2^64-1)`,
|
|
147
|
+
value
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
async function encryptUint64({
|
|
152
|
+
encryptor,
|
|
153
|
+
contractAddress,
|
|
154
|
+
userAddress,
|
|
155
|
+
value
|
|
156
|
+
}) {
|
|
157
|
+
assertUint64(value, "value");
|
|
158
|
+
const { handles, inputProof } = await encryptor.encrypt({
|
|
159
|
+
values: [{ value, type: "euint64" }],
|
|
160
|
+
contractAddress,
|
|
161
|
+
userAddress
|
|
162
|
+
});
|
|
163
|
+
if (handles.length !== 1) {
|
|
164
|
+
throw new InvalidArgumentError({
|
|
165
|
+
method: "encryptUint64",
|
|
166
|
+
argument: "handles",
|
|
167
|
+
reason: `expected 1 handle, got ${handles.length}`,
|
|
168
|
+
value: handles.length
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
return {
|
|
172
|
+
handle: asEncryptedHandle(bytesToHex(handles[0])),
|
|
173
|
+
inputProof: asExternalInputProof(bytesToHex(inputProof))
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
async function encryptUint64Batch({
|
|
177
|
+
encryptor,
|
|
178
|
+
contractAddress,
|
|
179
|
+
userAddress,
|
|
180
|
+
values
|
|
181
|
+
}) {
|
|
182
|
+
if (values.length === 0) {
|
|
183
|
+
throw new InvalidArgumentError({
|
|
184
|
+
method: "encryptUint64Batch",
|
|
185
|
+
argument: "values",
|
|
186
|
+
reason: "must be non-empty"
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
values.forEach((v, i) => assertUint64(v, `values[${i}]`));
|
|
190
|
+
const { handles, inputProof } = await encryptor.encrypt({
|
|
191
|
+
values: values.map((value) => ({ value, type: "euint64" })),
|
|
192
|
+
contractAddress,
|
|
193
|
+
userAddress
|
|
194
|
+
});
|
|
195
|
+
if (handles.length !== values.length) {
|
|
196
|
+
throw new InvalidArgumentError({
|
|
197
|
+
method: "encryptUint64Batch",
|
|
198
|
+
argument: "handles",
|
|
199
|
+
reason: `expected ${values.length} handles, got ${handles.length}`,
|
|
200
|
+
value: handles.length
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
return {
|
|
204
|
+
handles: handles.map((h) => asEncryptedHandle(bytesToHex(h))),
|
|
205
|
+
inputProof: asExternalInputProof(bytesToHex(inputProof))
|
|
206
|
+
};
|
|
207
|
+
}
|
|
134
208
|
|
|
135
|
-
export { FHE_SPLIT_DENOMINATOR, scaleRatio, share };
|
|
209
|
+
export { FHE_SPLIT_DENOMINATOR, encryptUint64, encryptUint64Batch, resolveEncryptor, scaleRatio, share };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { createConfidentialVestingManagerClient
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { createConfidentialVestingManagerClient } from './chunk-TWT3STIX.js';
|
|
2
|
+
import { resolveEncryptor } from './chunk-6GNR22OV.js';
|
|
3
|
+
import { createConfidentialVestingFactoryClient } from './chunk-EAJ7SYHE.js';
|
|
4
|
+
import { getFheVestingFactoryAddress } from './chunk-DZHYSUGY.js';
|
|
4
5
|
import { DeploymentAddressUnavailableError } from './chunk-QBJ7O2B4.js';
|
|
5
6
|
import { useMemo, useRef, useEffect } from 'react';
|
|
6
7
|
import { usePublicClient, useWalletClient } from 'wagmi';
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
3
|
+
var chunkUG5RKLU2_cjs = require('./chunk-UG5RKLU2.cjs');
|
|
4
|
+
var chunkMVDQMV25_cjs = require('./chunk-MVDQMV25.cjs');
|
|
5
|
+
var chunk5576FRT3_cjs = require('./chunk-5576FRT3.cjs');
|
|
5
6
|
var chunkJK4XMMKM_cjs = require('./chunk-JK4XMMKM.cjs');
|
|
6
|
-
var chunkVJKZWYYJ_cjs = require('./chunk-VJKZWYYJ.cjs');
|
|
7
7
|
var chunk66IHPTOK_cjs = require('./chunk-66IHPTOK.cjs');
|
|
8
8
|
var chunk67OV5CX2_cjs = require('./chunk-67OV5CX2.cjs');
|
|
9
|
+
var chunkVJKZWYYJ_cjs = require('./chunk-VJKZWYYJ.cjs');
|
|
9
10
|
var viem = require('viem');
|
|
10
11
|
|
|
11
12
|
// src/fhe-vesting/abis/factory.ts
|
|
@@ -445,7 +446,7 @@ var ConfidentialVestingFactoryClient = class {
|
|
|
445
446
|
this.walletClient = config.walletClient;
|
|
446
447
|
const chainId = config.chainId ?? config.publicClient.chain?.id;
|
|
447
448
|
const addressOverride = config.address ? chunkJK4XMMKM_cjs.normaliseAddress(config.address) : void 0;
|
|
448
|
-
const resolved = addressOverride ?? (chainId === void 0 ? void 0 :
|
|
449
|
+
const resolved = addressOverride ?? (chainId === void 0 ? void 0 : chunk5576FRT3_cjs.getFheVestingFactoryAddress(chainId));
|
|
449
450
|
if (!resolved) {
|
|
450
451
|
throw new chunk67OV5CX2_cjs.DeploymentAddressUnavailableError({
|
|
451
452
|
reason: chainId === void 0 ? "chain-id-missing" : "registry-not-deployed",
|
|
@@ -463,7 +464,7 @@ var ConfidentialVestingFactoryClient = class {
|
|
|
463
464
|
hasWallet: !!this.walletClient,
|
|
464
465
|
aclResolved: true,
|
|
465
466
|
// factory has no ACL dependency; constant for funnel-shape parity with manager.
|
|
466
|
-
sdkVersion:
|
|
467
|
+
sdkVersion: chunkUG5RKLU2_cjs.SDK_VERSION
|
|
467
468
|
});
|
|
468
469
|
}
|
|
469
470
|
// ----------------------- writes -----------------------
|
|
@@ -691,7 +692,7 @@ var ConfidentialVestingFactoryClient = class {
|
|
|
691
692
|
}
|
|
692
693
|
}
|
|
693
694
|
#mapRevert(method, err, account) {
|
|
694
|
-
return
|
|
695
|
+
return chunkMVDQMV25_cjs.mapContractRevert(err, {
|
|
695
696
|
method,
|
|
696
697
|
contractAddress: this.address,
|
|
697
698
|
abi: confidentialVestingFactoryAbi,
|
|
@@ -716,7 +717,7 @@ var ConfidentialVestingFactoryClient = class {
|
|
|
716
717
|
...value !== void 0 ? { value } : {}
|
|
717
718
|
});
|
|
718
719
|
} catch (err) {
|
|
719
|
-
if (
|
|
720
|
+
if (chunkMVDQMV25_cjs.isContractRevert(err)) {
|
|
720
721
|
throw this.#mapRevert(method, err, accountAddress(account));
|
|
721
722
|
}
|
|
722
723
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { SDK_VERSION
|
|
2
|
-
import {
|
|
1
|
+
import { SDK_VERSION } from './chunk-NWFMBLSQ.js';
|
|
2
|
+
import { isContractRevert, mapContractRevert } from './chunk-4RAAATVY.js';
|
|
3
|
+
import { getConfidentialTestTokenAddress, getTestTokenAddress } from './chunk-DZHYSUGY.js';
|
|
3
4
|
import { normaliseAddress } from './chunk-ZA673I3O.js';
|
|
4
|
-
import { withTelemetry } from './chunk-Q2GP5UDC.js';
|
|
5
5
|
import { asEncryptedHandle, asTxHash } from './chunk-KWFFIJYX.js';
|
|
6
6
|
import { TokenOpsSdkError, UnsupportedChainError, DeploymentAddressUnavailableError, TokenOpsContractError, ReceiptEventNotFoundError, ReceiptEventAmbiguousError, MissingWalletClientError, MissingAccountError, InvalidArgumentError } from './chunk-QBJ7O2B4.js';
|
|
7
|
+
import { withTelemetry } from './chunk-Q2GP5UDC.js';
|
|
7
8
|
import { sepolia } from 'viem/chains';
|
|
8
9
|
import { parseEventLogs } from 'viem';
|
|
9
10
|
|