@metamask/smart-accounts-kit 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -1
- package/README.md +34 -2
- package/dist/actions/index.cjs +5 -5
- package/dist/actions/index.mjs +4 -4
- package/dist/{smartAccountsEnvironment-BIcho7e0.d.cts → caveats-CQbtzOKm.d.ts} +9 -2
- package/dist/{smartAccountsEnvironment-Bso0CIWt.d.ts → caveats-Cey0wm33.d.cts} +9 -2
- package/dist/{chunk-UUOH2WAW.cjs → chunk-3SHZ7PV2.cjs} +12 -12
- package/dist/{chunk-UUOH2WAW.cjs.map → chunk-3SHZ7PV2.cjs.map} +1 -1
- package/dist/{chunk-TPBFVDVM.mjs → chunk-4QXIOE7F.mjs} +8 -6
- package/dist/chunk-4QXIOE7F.mjs.map +1 -0
- package/dist/{chunk-NOCLGZGB.mjs → chunk-734MOPHR.mjs} +63 -5
- package/dist/chunk-734MOPHR.mjs.map +1 -0
- package/dist/{chunk-YDLLC6PP.cjs → chunk-7BEEGBA2.cjs} +519 -16
- package/dist/chunk-7BEEGBA2.cjs.map +1 -0
- package/dist/{chunk-45GHWVQA.mjs → chunk-G7VZ7E6W.mjs} +4 -4
- package/dist/{chunk-F2RG26RH.cjs → chunk-HFRQNSZE.cjs} +105 -105
- package/dist/{chunk-F2RG26RH.cjs.map → chunk-HFRQNSZE.cjs.map} +1 -1
- package/dist/{chunk-YSBBRLMT.mjs → chunk-L5DLMBDC.mjs} +5 -5
- package/dist/{chunk-VLKX4BR6.cjs → chunk-MOHCTPYQ.cjs} +8 -6
- package/dist/chunk-MOHCTPYQ.cjs.map +1 -0
- package/dist/{chunk-QMRKCB7T.cjs → chunk-T4IAMAB2.cjs} +102 -44
- package/dist/chunk-T4IAMAB2.cjs.map +1 -0
- package/dist/{chunk-BYWRJGSK.cjs → chunk-UB2FLPP3.cjs} +16 -16
- package/dist/{chunk-BYWRJGSK.cjs.map → chunk-UB2FLPP3.cjs.map} +1 -1
- package/dist/{chunk-23YXLKTX.cjs → chunk-UZO5OYCD.cjs} +14 -14
- package/dist/{chunk-23YXLKTX.cjs.map → chunk-UZO5OYCD.cjs.map} +1 -1
- package/dist/{chunk-YTELOQ4I.mjs → chunk-VJXM3LWA.mjs} +2 -2
- package/dist/{chunk-WV2R7BXP.mjs → chunk-YTNCEXUX.mjs} +3 -3
- package/dist/{chunk-C5ZEEH2Z.mjs → chunk-ZA2XYCVX.mjs} +517 -14
- package/dist/chunk-ZA2XYCVX.mjs.map +1 -0
- package/dist/contracts/index.cjs +6 -6
- package/dist/contracts/index.d.cts +2 -2
- package/dist/contracts/index.d.ts +2 -2
- package/dist/contracts/index.mjs +5 -5
- package/dist/{delegation-DgmIOh21.d.ts → delegation-Bx4FEAIU.d.ts} +1 -1
- package/dist/{delegation-Ci3me5Rg.d.cts → delegation-KbWHzRxV.d.cts} +1 -1
- package/dist/experimental/index.cjs +36 -4
- package/dist/experimental/index.cjs.map +1 -1
- package/dist/experimental/index.d.cts +4 -1
- package/dist/experimental/index.d.ts +4 -1
- package/dist/experimental/index.mjs +35 -3
- package/dist/experimental/index.mjs.map +1 -1
- package/dist/{index-UF6eCzBC.d.ts → index-D2THBlfm.d.ts} +1 -1
- package/dist/{index-CSjEW7MJ.d.cts → index-DE87r5KY.d.cts} +1 -1
- package/dist/index.cjs +33 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -9
- package/dist/index.d.ts +7 -9
- package/dist/index.mjs +24 -8
- package/dist/index.mjs.map +1 -1
- package/dist/utils/index.cjs +7 -5
- package/dist/utils/index.cjs.map +1 -1
- package/dist/utils/index.d.cts +2 -2
- package/dist/utils/index.d.ts +2 -2
- package/dist/utils/index.mjs +6 -4
- package/package.json +5 -4
- package/dist/chunk-C5ZEEH2Z.mjs.map +0 -1
- package/dist/chunk-NOCLGZGB.mjs.map +0 -1
- package/dist/chunk-QMRKCB7T.cjs.map +0 -1
- package/dist/chunk-TPBFVDVM.mjs.map +0 -1
- package/dist/chunk-VLKX4BR6.cjs.map +0 -1
- package/dist/chunk-YDLLC6PP.cjs.map +0 -1
- /package/dist/{chunk-45GHWVQA.mjs.map → chunk-G7VZ7E6W.mjs.map} +0 -0
- /package/dist/{chunk-YSBBRLMT.mjs.map → chunk-L5DLMBDC.mjs.map} +0 -0
- /package/dist/{chunk-YTELOQ4I.mjs.map → chunk-VJXM3LWA.mjs.map} +0 -0
- /package/dist/{chunk-WV2R7BXP.mjs.map → chunk-YTNCEXUX.mjs.map} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [1.2.0]
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- `decodeCaveat` util function ([#191](https://github.com/metamask/smart-accounts-kit/pull/191))
|
|
15
|
+
- Chain deployment for Katana mainnet and Katana Bokuto ([#203](https://github.com/MetaMask/smart-accounts-kit/pull/203))
|
|
16
|
+
- Anonymous usage statistics to help improve the SDK ([#185](https://github.com/metamask/smart-accounts-kit/pull/185))
|
|
17
|
+
- Opt out by setting environment variables `CI` or `DO_NOT_TRACK`, or `navigator.doNotTrack` or `window.doNotTrack` to either '1', 'true', or 'yes'
|
|
18
|
+
|
|
10
19
|
## [1.1.0]
|
|
11
20
|
|
|
12
21
|
### Added
|
|
@@ -105,7 +114,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
105
114
|
|
|
106
115
|
- Promote readable permissions actions (`requestExecutionPermissions`, `sendTransactionWithDelegation`, and `sendUserOperationWithDelegation`) from experimental ([#91](https://github.com/MetaMask/smart-accounts-kit/pull/91))
|
|
107
116
|
|
|
108
|
-
[Unreleased]: https://github.com/metamask/smart-accounts-kit/compare/@metamask/smart-accounts-kit@1.
|
|
117
|
+
[Unreleased]: https://github.com/metamask/smart-accounts-kit/compare/@metamask/smart-accounts-kit@1.2.0...HEAD
|
|
118
|
+
[1.2.0]: https://github.com/metamask/smart-accounts-kit/compare/@metamask/smart-accounts-kit@1.1.0...@metamask/smart-accounts-kit@1.2.0
|
|
109
119
|
[1.1.0]: https://github.com/metamask/smart-accounts-kit/compare/@metamask/smart-accounts-kit@1.0.0...@metamask/smart-accounts-kit@1.1.0
|
|
110
120
|
[1.0.0]: https://github.com/metamask/smart-accounts-kit/compare/@metamask/smart-accounts-kit@0.4.0-beta.2...@metamask/smart-accounts-kit@1.0.0
|
|
111
121
|
[0.4.0-beta.2]: https://github.com/metamask/smart-accounts-kit/compare/@metamask/smart-accounts-kit@0.4.0-beta.1...@metamask/smart-accounts-kit@0.4.0-beta.2
|
package/README.md
CHANGED
|
@@ -19,15 +19,17 @@ The MetaMask Smart Accounts Kit is a [Viem](https://viem.sh)-based collection of
|
|
|
19
19
|
Yarn:
|
|
20
20
|
|
|
21
21
|
```sh
|
|
22
|
-
yarn add @metamask/smart-accounts-kit
|
|
22
|
+
yarn add @metamask/smart-accounts-kit viem
|
|
23
23
|
```
|
|
24
24
|
|
|
25
25
|
Npm:
|
|
26
26
|
|
|
27
27
|
```sh
|
|
28
|
-
npm install @metamask/smart-accounts-kit
|
|
28
|
+
npm install @metamask/smart-accounts-kit viem
|
|
29
29
|
```
|
|
30
30
|
|
|
31
|
+
`viem` is a peer dependency; install a compatible version alongside the kit.
|
|
32
|
+
|
|
31
33
|
## Overview
|
|
32
34
|
|
|
33
35
|
---
|
|
@@ -63,6 +65,36 @@ const smartAccount = await toMetaMaskSmartAccount({
|
|
|
63
65
|
|
|
64
66
|
[Head to our documentation](https://docs.gator.metamask.io) to learn more about the MetaMask Smart Accounts Kit.
|
|
65
67
|
|
|
68
|
+
## Analytics
|
|
69
|
+
|
|
70
|
+
This package collects anonymous usage analytics to help us understand how it's being used and prioritize improvements. No personal information is collected. **[Analytics can be disabled](#disabling-analytics)**.
|
|
71
|
+
|
|
72
|
+
### What's collected
|
|
73
|
+
|
|
74
|
+
Two event types are sent (namespace `metamask/smart-accounts-kit`): a one-time **initialized** event when the first instrumented API runs (just before the first **function called** event), and **function called** events when those APIs run afterward. Both include a small **session base**; function events add which API was used and optional **parameters**.
|
|
75
|
+
|
|
76
|
+
- **`sdk_version`** — Kit version.
|
|
77
|
+
- **`anon_id`** — Random id regenerated on each SDK initialization for correlating events within that session. It is not derived from wallet or personal data, is not written to local storage or cookies for tracking purposes, and is not used to identify or track a user across sites or apps.
|
|
78
|
+
- **`platform`** — Coarse runtime (`web-desktop`, `web-mobile`, or `nodejs`).
|
|
79
|
+
- **`domain`** *(web only, when available)* — Current page hostname.
|
|
80
|
+
|
|
81
|
+
- **`function_name`** — Stable internal name of the API that was called.
|
|
82
|
+
- **`parameters`** *(optional)* — Only coarse, non-identifying data: things like numeric **chain id**, **counts** (e.g. calls, caveats, signatures), **booleans** (whether optional inputs were present), **implementation or scope _type_** from fixed enums, and **high-level labels** (e.g. which known delegation-storage tier or filter mode). No raw addresses, hashes, calldata, keys, or permission payloads.
|
|
83
|
+
|
|
84
|
+
### What's NOT collected
|
|
85
|
+
|
|
86
|
+
- **Secrets and credentials** — Private keys, API keys, bearer tokens, RPC or bundler URLs, and similar.
|
|
87
|
+
- **On-chain identifiers and payloads** — Account or contract addresses, transaction `to` / `data` / `value`, user operation calldata, delegation bodies, delegation hashes, permission request or response payloads, and signature bytes.
|
|
88
|
+
- **Personal information** — No names, emails, or other PII is sent as part of this analytics design.
|
|
89
|
+
|
|
90
|
+
### Disabling analytics
|
|
91
|
+
|
|
92
|
+
Analytics is not initialized when any of the following is set to: `1`, or `yes` / `true` (case-insensitive):
|
|
93
|
+
|
|
94
|
+
- **`CI`** environment variable (Node.js)
|
|
95
|
+
- **`DO_NOT_TRACK`** environment variable (Node.js)
|
|
96
|
+
- **`navigator.doNotTrack`** or **`window.doNotTrack`** (in browsers).
|
|
97
|
+
|
|
66
98
|
## Contributing
|
|
67
99
|
|
|
68
100
|
---
|
package/dist/actions/index.cjs
CHANGED
|
@@ -16,11 +16,11 @@
|
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
|
|
19
|
-
var
|
|
20
|
-
require('../chunk-
|
|
19
|
+
var _chunkT4IAMAB2cjs = require('../chunk-T4IAMAB2.cjs');
|
|
20
|
+
require('../chunk-3SHZ7PV2.cjs');
|
|
21
21
|
require('../chunk-SOFB2MXG.cjs');
|
|
22
|
-
require('../chunk-
|
|
23
|
-
require('../chunk-
|
|
22
|
+
require('../chunk-MOHCTPYQ.cjs');
|
|
23
|
+
require('../chunk-7BEEGBA2.cjs');
|
|
24
24
|
|
|
25
25
|
|
|
26
26
|
|
|
@@ -39,5 +39,5 @@ require('../chunk-YDLLC6PP.cjs');
|
|
|
39
39
|
|
|
40
40
|
|
|
41
41
|
|
|
42
|
-
exports.caveatEnforcerActions =
|
|
42
|
+
exports.caveatEnforcerActions = _chunkT4IAMAB2cjs.caveatEnforcerActions; exports.erc7710BundlerActions = _chunkT4IAMAB2cjs.erc7710BundlerActions; exports.erc7710WalletActions = _chunkT4IAMAB2cjs.erc7710WalletActions; exports.erc7715ProviderActions = _chunkT4IAMAB2cjs.erc7715ProviderActions; exports.getErc20PeriodTransferEnforcerAvailableAmount = _chunkT4IAMAB2cjs.getErc20PeriodTransferEnforcerAvailableAmount; exports.getErc20StreamingEnforcerAvailableAmount = _chunkT4IAMAB2cjs.getErc20StreamingEnforcerAvailableAmount; exports.getGrantedExecutionPermissions = _chunkT4IAMAB2cjs.erc7715GetGrantedExecutionPermissionsAction; exports.getMultiTokenPeriodEnforcerAvailableAmount = _chunkT4IAMAB2cjs.getMultiTokenPeriodEnforcerAvailableAmount; exports.getNativeTokenPeriodTransferEnforcerAvailableAmount = _chunkT4IAMAB2cjs.getNativeTokenPeriodTransferEnforcerAvailableAmount; exports.getNativeTokenStreamingEnforcerAvailableAmount = _chunkT4IAMAB2cjs.getNativeTokenStreamingEnforcerAvailableAmount; exports.getSupportedExecutionPermissions = _chunkT4IAMAB2cjs.erc7715GetSupportedExecutionPermissionsAction; exports.isValid7702Implementation = _chunkT4IAMAB2cjs.isValid7702Implementation; exports.requestExecutionPermissions = _chunkT4IAMAB2cjs.erc7715RequestExecutionPermissionsAction; exports.signDelegation = _chunkT4IAMAB2cjs.signDelegation; exports.signDelegationActions = _chunkT4IAMAB2cjs.signDelegationActions; exports.signUserOperation = _chunkT4IAMAB2cjs.signUserOperation; exports.signUserOperationActions = _chunkT4IAMAB2cjs.signUserOperationActions;
|
|
43
43
|
//# sourceMappingURL=index.cjs.map
|
package/dist/actions/index.mjs
CHANGED
|
@@ -16,11 +16,11 @@ import {
|
|
|
16
16
|
signDelegationActions,
|
|
17
17
|
signUserOperation,
|
|
18
18
|
signUserOperationActions
|
|
19
|
-
} from "../chunk-
|
|
20
|
-
import "../chunk-
|
|
19
|
+
} from "../chunk-734MOPHR.mjs";
|
|
20
|
+
import "../chunk-VJXM3LWA.mjs";
|
|
21
21
|
import "../chunk-QCULIK3O.mjs";
|
|
22
|
-
import "../chunk-
|
|
23
|
-
import "../chunk-
|
|
22
|
+
import "../chunk-4QXIOE7F.mjs";
|
|
23
|
+
import "../chunk-ZA2XYCVX.mjs";
|
|
24
24
|
export {
|
|
25
25
|
caveatEnforcerActions,
|
|
26
26
|
erc7710BundlerActions,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { WalletClient, PublicClient, Chain, Hex } from 'viem';
|
|
2
|
-
import { S as SmartAccountsEnvironment } from './types-BWaH4KH1.
|
|
2
|
+
import { S as SmartAccountsEnvironment, C as Caveat } from './types-BWaH4KH1.js';
|
|
3
|
+
import { A as CoreCaveatConfiguration } from './delegation-Bx4FEAIU.js';
|
|
3
4
|
|
|
4
5
|
type SupportedVersion = '1.0.0' | '1.1.0' | '1.2.0' | '1.3.0';
|
|
5
6
|
declare const PREFERRED_VERSION: SupportedVersion;
|
|
@@ -9,4 +10,10 @@ declare function deploySmartAccountsEnvironment(walletClient: WalletClient, publ
|
|
|
9
10
|
[contract: string]: Hex;
|
|
10
11
|
}): Promise<SmartAccountsEnvironment>;
|
|
11
12
|
|
|
12
|
-
|
|
13
|
+
declare const createCaveat: (enforcer: Hex, terms: Hex, args?: Hex) => Caveat;
|
|
14
|
+
declare const decodeCaveat: ({ caveat: { enforcer, terms }, environment: { caveatEnforcers }, }: {
|
|
15
|
+
caveat: Caveat;
|
|
16
|
+
environment: SmartAccountsEnvironment;
|
|
17
|
+
}) => CoreCaveatConfiguration;
|
|
18
|
+
|
|
19
|
+
export { PREFERRED_VERSION as P, deploySmartAccountsEnvironment as a, createCaveat as c, decodeCaveat as d, getSmartAccountsEnvironment as g, overrideDeployedEnvironment as o };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { WalletClient, PublicClient, Chain, Hex } from 'viem';
|
|
2
|
-
import { S as SmartAccountsEnvironment } from './types-BWaH4KH1.
|
|
2
|
+
import { S as SmartAccountsEnvironment, C as Caveat } from './types-BWaH4KH1.cjs';
|
|
3
|
+
import { A as CoreCaveatConfiguration } from './delegation-KbWHzRxV.cjs';
|
|
3
4
|
|
|
4
5
|
type SupportedVersion = '1.0.0' | '1.1.0' | '1.2.0' | '1.3.0';
|
|
5
6
|
declare const PREFERRED_VERSION: SupportedVersion;
|
|
@@ -9,4 +10,10 @@ declare function deploySmartAccountsEnvironment(walletClient: WalletClient, publ
|
|
|
9
10
|
[contract: string]: Hex;
|
|
10
11
|
}): Promise<SmartAccountsEnvironment>;
|
|
11
12
|
|
|
12
|
-
|
|
13
|
+
declare const createCaveat: (enforcer: Hex, terms: Hex, args?: Hex) => Caveat;
|
|
14
|
+
declare const decodeCaveat: ({ caveat: { enforcer, terms }, environment: { caveatEnforcers }, }: {
|
|
15
|
+
caveat: Caveat;
|
|
16
|
+
environment: SmartAccountsEnvironment;
|
|
17
|
+
}) => CoreCaveatConfiguration;
|
|
18
|
+
|
|
19
|
+
export { PREFERRED_VERSION as P, deploySmartAccountsEnvironment as a, createCaveat as c, decodeCaveat as d, getSmartAccountsEnvironment as g, overrideDeployedEnvironment as o };
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunk7BEEGBA2cjs = require('./chunk-7BEEGBA2.cjs');
|
|
4
4
|
|
|
5
5
|
// src/DelegationFramework/ERC20PeriodTransferEnforcer/index.ts
|
|
6
6
|
var ERC20PeriodTransferEnforcer_exports = {};
|
|
7
|
-
|
|
7
|
+
_chunk7BEEGBA2cjs.__export.call(void 0, ERC20PeriodTransferEnforcer_exports, {
|
|
8
8
|
read: () => read_exports
|
|
9
9
|
});
|
|
10
10
|
|
|
11
11
|
// src/DelegationFramework/ERC20PeriodTransferEnforcer/read.ts
|
|
12
12
|
var read_exports = {};
|
|
13
|
-
|
|
13
|
+
_chunk7BEEGBA2cjs.__export.call(void 0, read_exports, {
|
|
14
14
|
getAvailableAmount: () => read
|
|
15
15
|
});
|
|
16
16
|
|
|
@@ -42,13 +42,13 @@ var read = async ({
|
|
|
42
42
|
|
|
43
43
|
// src/DelegationFramework/ERC20StreamingEnforcer/index.ts
|
|
44
44
|
var ERC20StreamingEnforcer_exports = {};
|
|
45
|
-
|
|
45
|
+
_chunk7BEEGBA2cjs.__export.call(void 0, ERC20StreamingEnforcer_exports, {
|
|
46
46
|
read: () => read_exports2
|
|
47
47
|
});
|
|
48
48
|
|
|
49
49
|
// src/DelegationFramework/ERC20StreamingEnforcer/read.ts
|
|
50
50
|
var read_exports2 = {};
|
|
51
|
-
|
|
51
|
+
_chunk7BEEGBA2cjs.__export.call(void 0, read_exports2, {
|
|
52
52
|
getAvailableAmount: () => read2
|
|
53
53
|
});
|
|
54
54
|
|
|
@@ -126,13 +126,13 @@ function getAvailableAmount(allowance) {
|
|
|
126
126
|
|
|
127
127
|
// src/DelegationFramework/MultiTokenPeriodEnforcer/index.ts
|
|
128
128
|
var MultiTokenPeriodEnforcer_exports = {};
|
|
129
|
-
|
|
129
|
+
_chunk7BEEGBA2cjs.__export.call(void 0, MultiTokenPeriodEnforcer_exports, {
|
|
130
130
|
read: () => read_exports3
|
|
131
131
|
});
|
|
132
132
|
|
|
133
133
|
// src/DelegationFramework/MultiTokenPeriodEnforcer/read.ts
|
|
134
134
|
var read_exports3 = {};
|
|
135
|
-
|
|
135
|
+
_chunk7BEEGBA2cjs.__export.call(void 0, read_exports3, {
|
|
136
136
|
getAvailableAmount: () => read3
|
|
137
137
|
});
|
|
138
138
|
|
|
@@ -165,13 +165,13 @@ var read3 = async ({
|
|
|
165
165
|
|
|
166
166
|
// src/DelegationFramework/NativeTokenPeriodTransferEnforcer/index.ts
|
|
167
167
|
var NativeTokenPeriodTransferEnforcer_exports = {};
|
|
168
|
-
|
|
168
|
+
_chunk7BEEGBA2cjs.__export.call(void 0, NativeTokenPeriodTransferEnforcer_exports, {
|
|
169
169
|
read: () => read_exports4
|
|
170
170
|
});
|
|
171
171
|
|
|
172
172
|
// src/DelegationFramework/NativeTokenPeriodTransferEnforcer/read.ts
|
|
173
173
|
var read_exports4 = {};
|
|
174
|
-
|
|
174
|
+
_chunk7BEEGBA2cjs.__export.call(void 0, read_exports4, {
|
|
175
175
|
getAvailableAmount: () => read4
|
|
176
176
|
});
|
|
177
177
|
|
|
@@ -203,13 +203,13 @@ var read4 = async ({
|
|
|
203
203
|
|
|
204
204
|
// src/DelegationFramework/NativeTokenStreamingEnforcer/index.ts
|
|
205
205
|
var NativeTokenStreamingEnforcer_exports = {};
|
|
206
|
-
|
|
206
|
+
_chunk7BEEGBA2cjs.__export.call(void 0, NativeTokenStreamingEnforcer_exports, {
|
|
207
207
|
read: () => read_exports5
|
|
208
208
|
});
|
|
209
209
|
|
|
210
210
|
// src/DelegationFramework/NativeTokenStreamingEnforcer/read.ts
|
|
211
211
|
var read_exports5 = {};
|
|
212
|
-
|
|
212
|
+
_chunk7BEEGBA2cjs.__export.call(void 0, read_exports5, {
|
|
213
213
|
getAvailableAmount: () => read5
|
|
214
214
|
});
|
|
215
215
|
|
|
@@ -296,4 +296,4 @@ function getAvailableAmount2(allowance) {
|
|
|
296
296
|
|
|
297
297
|
|
|
298
298
|
exports.read_exports = read_exports; exports.ERC20PeriodTransferEnforcer_exports = ERC20PeriodTransferEnforcer_exports; exports.read_exports2 = read_exports2; exports.ERC20StreamingEnforcer_exports = ERC20StreamingEnforcer_exports; exports.read_exports3 = read_exports3; exports.MultiTokenPeriodEnforcer_exports = MultiTokenPeriodEnforcer_exports; exports.read_exports4 = read_exports4; exports.NativeTokenPeriodTransferEnforcer_exports = NativeTokenPeriodTransferEnforcer_exports; exports.read_exports5 = read_exports5; exports.NativeTokenStreamingEnforcer_exports = NativeTokenStreamingEnforcer_exports;
|
|
299
|
-
//# sourceMappingURL=chunk-
|
|
299
|
+
//# sourceMappingURL=chunk-3SHZ7PV2.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/smart-accounts-kit/smart-accounts-kit/packages/smart-accounts-kit/dist/chunk-UUOH2WAW.cjs","../src/DelegationFramework/ERC20PeriodTransferEnforcer/index.ts","../src/DelegationFramework/ERC20PeriodTransferEnforcer/read.ts","../src/DelegationFramework/ERC20PeriodTransferEnforcer/methods/getAvailableAmount.ts","../src/DelegationFramework/ERC20StreamingEnforcer/index.ts","../src/DelegationFramework/ERC20StreamingEnforcer/read.ts","../src/DelegationFramework/ERC20StreamingEnforcer/methods/getAvailableAmount.ts","../src/DelegationFramework/MultiTokenPeriodEnforcer/index.ts","../src/DelegationFramework/MultiTokenPeriodEnforcer/read.ts","../src/DelegationFramework/MultiTokenPeriodEnforcer/methods/getAvailableAmount.ts","../src/DelegationFramework/NativeTokenPeriodTransferEnforcer/index.ts","../src/DelegationFramework/NativeTokenPeriodTransferEnforcer/read.ts","../src/DelegationFramework/NativeTokenPeriodTransferEnforcer/methods/getAvailableAmount.ts","../src/DelegationFramework/NativeTokenStreamingEnforcer/index.ts","../src/DelegationFramework/NativeTokenStreamingEnforcer/read.ts","../src/DelegationFramework/NativeTokenStreamingEnforcer/methods/getAvailableAmount.ts"],"names":["read_exports","read","readContract","availableAmount","getBlock","getAvailableAmount"],"mappings":"AAAA;AACE;AACF,wDAA6B;AAC7B;AACA;ACJA,IAAA,oCAAA,EAAA,CAAA,CAAA;AAAA,wCAAA,mCAAA,EAAA;AAAA,EAAA,IAAA,EAAA,CAAA,EAAA,GAAA;AAAA,CAAA,CAAA;ADSA;AACA;AEVA,IAAA,aAAA,EAAA,CAAA,CAAA;AAAA,wCAAA,YAAA,EAAA;AAAA,EAAA,kBAAA,EAAA,CAAA,EAAA,GAAA;AAAA,CAAA,CAAA;AFeA;AACA;AGhBA,2DAA4C;AAE5C,uCAA6B;AAUtB,IAAM,KAAA,EAAO,MAAA,CAAO;AAAA,EACzB,MAAA;AAAA,EACA,eAAA;AAAA,EACA,cAAA;AAAA,EACA,iBAAA;AAAA,EACA;AACF,CAAA,EAAA,GAAwC;AACtC,EAAA,MAAM,CAAC,eAAA,EAAiB,WAAA,EAAa,aAAa,EAAA,EAAI,MAAM,mCAAA;AAAA,IAC1D,MAAA;AAAA,IACA;AAAA,MACE,OAAA,EAAS,eAAA;AAAA,MACT,GAAA,EAAK,2CAAA;AAAA,MACL,YAAA,EAAc,oBAAA;AAAA,MACd,IAAA,EAAM,CAAC,cAAA,EAAgB,iBAAA,EAAmB,KAAK;AAAA,IACjD;AAAA,EACF,CAAA;AAEA,EAAA,OAAO;AAAA,IACL,eAAA;AAAA,IACA,WAAA;AAAA,IACA;AAAA,EACF,CAAA;AACF,CAAA;AHOA;AACA;AI1CA,IAAA,+BAAA,EAAA,CAAA,CAAA;AAAA,wCAAA,8BAAA,EAAA;AAAA,EAAA,IAAA,EAAA,CAAA,EAAA,GAAAA;AAAA,CAAA,CAAA;AJ+CA;AACA;AKhDA,IAAAA,cAAAA,EAAA,CAAA,CAAA;AAAA,wCAAA,aAAAA,EAAA;AAAA,EAAA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SAAA,CAAU,KAAA;AAC9B;AfiKA;AACA;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,6lBAAC","file":"/home/runner/work/smart-accounts-kit/smart-accounts-kit/packages/smart-accounts-kit/dist/chunk-UUOH2WAW.cjs","sourcesContent":[null,"import * as read from './read';\n\nexport { read };\n","import { read as getAvailableAmount } from './methods/getAvailableAmount';\n\nexport { getAvailableAmount };\n","import { ERC20PeriodTransferEnforcer } from '@metamask/delegation-abis';\nimport type { Address, Client, Hex } from 'viem';\nimport { readContract } from 'viem/actions';\n\nexport type ReadGetAvailableAmountParameters = {\n client: Client;\n contractAddress: Address;\n delegationHash: Hex;\n delegationManager: Address;\n terms: Hex;\n};\n\nexport const read = async ({\n client,\n contractAddress,\n delegationHash,\n delegationManager,\n terms,\n}: ReadGetAvailableAmountParameters) => {\n const [availableAmount, isNewPeriod, currentPeriod] = await readContract(\n client,\n {\n address: contractAddress,\n abi: ERC20PeriodTransferEnforcer,\n functionName: 'getAvailableAmount',\n args: [delegationHash, delegationManager, terms],\n },\n );\n\n return {\n availableAmount,\n isNewPeriod,\n currentPeriod,\n };\n};\n","import * as read from './read';\n\nexport { read };\n","import { read as getAvailableAmount } from './methods/getAvailableAmount';\n\nexport { getAvailableAmount };\n","import { ERC20StreamingEnforcer } from '@metamask/delegation-abis';\nimport type { Address, Client, Hex } from 'viem';\nimport { readContract, getBlock } from 'viem/actions';\n\nexport type ReadGetAvailableAmountParameters = {\n client: Client;\n contractAddress: Address;\n delegationManager: Address;\n delegationHash: Hex;\n terms: Hex;\n};\n\nexport const read = async ({\n client,\n contractAddress,\n delegationManager,\n delegationHash,\n terms,\n}: ReadGetAvailableAmountParameters) => {\n // Get current block timestamp from blockchain\n const currentBlock = await getBlock(client);\n const currentTimestamp = currentBlock.timestamp;\n\n // First, get the current state from the contract\n const allowanceState = await readContract(client, {\n address: contractAddress,\n abi: ERC20StreamingEnforcer,\n functionName: 'streamingAllowances',\n args: [delegationManager, delegationHash],\n });\n\n const [initialAmount, maxAmount, amountPerSecond, startTime, spent] =\n allowanceState;\n\n // Check if state exists (startTime != 0)\n if (startTime !== 0n) {\n // State exists, calculate available amount using the stored state\n const availableAmount = getAvailableAmount({\n initialAmount,\n maxAmount,\n amountPerSecond,\n startTime,\n spent,\n currentTimestamp,\n });\n\n return {\n availableAmount,\n };\n }\n\n // State doesn't exist, decode terms and simulate with spent = 0\n const decodedTerms = await readContract(client, {\n address: contractAddress,\n abi: ERC20StreamingEnforcer,\n functionName: 'getTermsInfo',\n args: [terms],\n });\n\n const [\n ,\n decodedInitialAmount,\n decodedMaxAmount,\n decodedAmountPerSecond,\n decodedStartTime,\n ] = decodedTerms;\n\n // Simulate using decoded terms with spent = 0\n const availableAmount = getAvailableAmount({\n initialAmount: decodedInitialAmount,\n maxAmount: decodedMaxAmount,\n amountPerSecond: decodedAmountPerSecond,\n startTime: decodedStartTime,\n spent: 0n,\n currentTimestamp,\n });\n\n return {\n availableAmount,\n };\n};\n\n/**\n * Replicates the internal _getAvailableAmount logic from the smart contract.\n *\n * @param allowance - The allowance object containing all parameters.\n * @param allowance.initialAmount - The initial amount available.\n * @param allowance.maxAmount - The maximum amount allowed.\n * @param allowance.amountPerSecond - The amount streamed per second.\n * @param allowance.startTime - The start time of the streaming.\n * @param allowance.spent - The amount already spent.\n * @param allowance.currentTimestamp - The current timestamp.\n * @returns The available amount that can be spent.\n */\nfunction getAvailableAmount(allowance: {\n initialAmount: bigint;\n maxAmount: bigint;\n amountPerSecond: bigint;\n startTime: bigint;\n spent: bigint;\n currentTimestamp: bigint;\n}): bigint {\n // If current time is before start time, nothing is available\n if (allowance.currentTimestamp < allowance.startTime) {\n return 0n;\n }\n\n // Calculate elapsed time since start\n const elapsed = allowance.currentTimestamp - allowance.startTime;\n\n // Calculate total unlocked amount\n let unlocked = allowance.initialAmount + allowance.amountPerSecond * elapsed;\n\n // Cap by max amount\n if (unlocked > allowance.maxAmount) {\n unlocked = allowance.maxAmount;\n }\n\n // If spent >= unlocked, nothing available\n if (allowance.spent >= unlocked) {\n return 0n;\n }\n\n // Return available amount\n return unlocked - allowance.spent;\n}\n","import * as read from './read';\n\nexport { read };\n","import { read as getAvailableAmount } from './methods/getAvailableAmount';\n\nexport { getAvailableAmount };\n","import { MultiTokenPeriodEnforcer } from '@metamask/delegation-abis';\nimport type { Address, Client, Hex } from 'viem';\nimport { readContract } from 'viem/actions';\n\nexport type ReadGetAvailableAmountParameters = {\n client: Client;\n contractAddress: Address;\n delegationHash: Hex;\n delegationManager: Address;\n terms: Hex;\n args: Hex;\n};\n\nexport const read = async ({\n client,\n contractAddress,\n delegationHash,\n delegationManager,\n terms,\n args,\n}: ReadGetAvailableAmountParameters) => {\n const [availableAmount, isNewPeriod, currentPeriod] = await readContract(\n client,\n {\n address: contractAddress,\n abi: MultiTokenPeriodEnforcer,\n functionName: 'getAvailableAmount',\n args: [delegationHash, delegationManager, terms, args],\n },\n );\n\n return {\n availableAmount,\n isNewPeriod,\n currentPeriod,\n };\n};\n","import * as read from './read';\n\nexport { read };\n","import { read as getAvailableAmount } from './methods/getAvailableAmount';\n\nexport { getAvailableAmount };\n","import { NativeTokenPeriodTransferEnforcer } from '@metamask/delegation-abis';\nimport type { Address, Client, Hex } from 'viem';\nimport { readContract } from 'viem/actions';\n\nexport type ReadGetAvailableAmountParameters = {\n client: Client;\n contractAddress: Address;\n delegationHash: Hex;\n delegationManager: Address;\n terms: Hex;\n};\n\nexport const read = async ({\n client,\n contractAddress,\n delegationHash,\n delegationManager,\n terms,\n}: ReadGetAvailableAmountParameters) => {\n const [availableAmount, isNewPeriod, currentPeriod] = await readContract(\n client,\n {\n address: contractAddress,\n abi: NativeTokenPeriodTransferEnforcer,\n functionName: 'getAvailableAmount',\n args: [delegationHash, delegationManager, terms],\n },\n );\n\n return {\n availableAmount,\n isNewPeriod,\n currentPeriod,\n };\n};\n","import * as read from './read';\n\nexport { read };\n","import { read as getAvailableAmount } from './methods/getAvailableAmount';\n\nexport { getAvailableAmount };\n","import { NativeTokenStreamingEnforcer } from '@metamask/delegation-abis';\nimport type { Address, Client, Hex } from 'viem';\nimport { readContract, getBlock } from 'viem/actions';\n\nexport type ReadGetAvailableAmountParameters = {\n client: Client;\n contractAddress: Address;\n delegationManager: Address;\n delegationHash: Hex;\n terms: Hex;\n};\n\nexport const read = async ({\n client,\n contractAddress,\n delegationManager,\n delegationHash,\n terms,\n}: ReadGetAvailableAmountParameters) => {\n // Get current block timestamp from blockchain\n const currentBlock = await getBlock(client);\n const currentTimestamp = currentBlock.timestamp;\n\n // First, get the current state from the contract\n const allowanceState = await readContract(client, {\n address: contractAddress,\n abi: NativeTokenStreamingEnforcer,\n functionName: 'streamingAllowances',\n args: [delegationManager, delegationHash],\n });\n\n const [initialAmount, maxAmount, amountPerSecond, startTime, spent] =\n allowanceState;\n\n // Check if state exists (startTime != 0)\n if (startTime !== 0n) {\n // State exists, calculate available amount using the stored state\n const availableAmount = getAvailableAmount({\n initialAmount,\n maxAmount,\n amountPerSecond,\n startTime,\n spent,\n currentTimestamp,\n });\n\n return {\n availableAmount,\n };\n }\n\n // State doesn't exist, decode terms and simulate with spent = 0\n const decodedTerms = await readContract(client, {\n address: contractAddress,\n abi: NativeTokenStreamingEnforcer,\n functionName: 'getTermsInfo',\n args: [terms],\n });\n\n const [\n decodedInitialAmount,\n decodedMaxAmount,\n decodedAmountPerSecond,\n decodedStartTime,\n ] = decodedTerms;\n\n // Simulate using decoded terms with spent = 0\n const availableAmount = getAvailableAmount({\n initialAmount: decodedInitialAmount,\n maxAmount: decodedMaxAmount,\n amountPerSecond: decodedAmountPerSecond,\n startTime: decodedStartTime,\n spent: 0n,\n currentTimestamp,\n });\n\n return {\n availableAmount,\n };\n};\n\n/**\n * Replicates the internal _getAvailableAmount logic from the smart contract.\n *\n * @param allowance - The allowance object containing all parameters.\n * @param allowance.initialAmount - The initial amount available.\n * @param allowance.maxAmount - The maximum amount allowed.\n * @param allowance.amountPerSecond - The amount streamed per second.\n * @param allowance.startTime - The start time of the streaming.\n * @param allowance.spent - The amount already spent.\n * @param allowance.currentTimestamp - The current timestamp.\n * @returns The available amount that can be spent.\n */\nfunction getAvailableAmount(allowance: {\n initialAmount: bigint;\n maxAmount: bigint;\n amountPerSecond: bigint;\n startTime: bigint;\n spent: bigint;\n currentTimestamp: bigint;\n}): bigint {\n // If current time is before start time, nothing is available\n if (allowance.currentTimestamp < allowance.startTime) {\n return 0n;\n }\n\n // Calculate elapsed time since start\n const elapsed = allowance.currentTimestamp - allowance.startTime;\n\n // Calculate total unlocked amount\n let unlocked = allowance.initialAmount + allowance.amountPerSecond * elapsed;\n\n // Cap by max amount\n if (unlocked > allowance.maxAmount) {\n unlocked = allowance.maxAmount;\n }\n\n // If spent >= unlocked, nothing available\n if (allowance.spent >= unlocked) {\n return 0n;\n }\n\n // Return available amount\n return unlocked - allowance.spent;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/smart-accounts-kit/smart-accounts-kit/packages/smart-accounts-kit/dist/chunk-3SHZ7PV2.cjs","../src/DelegationFramework/ERC20PeriodTransferEnforcer/index.ts","../src/DelegationFramework/ERC20PeriodTransferEnforcer/read.ts","../src/DelegationFramework/ERC20PeriodTransferEnforcer/methods/getAvailableAmount.ts","../src/DelegationFramework/ERC20StreamingEnforcer/index.ts","../src/DelegationFramework/ERC20StreamingEnforcer/read.ts","../src/DelegationFramework/ERC20StreamingEnforcer/methods/getAvailableAmount.ts","../src/DelegationFramework/MultiTokenPeriodEnforcer/index.ts","../src/DelegationFramework/MultiTokenPeriodEnforcer/read.ts","../src/DelegationFramework/MultiTokenPeriodEnforcer/methods/getAvailableAmount.ts","../src/DelegationFramework/NativeTokenPeriodTransferEnforcer/index.ts","../src/DelegationFramework/NativeTokenPeriodTransferEnforcer/read.ts","../src/DelegationFramework/NativeTokenPeriodTransferEnforcer/methods/getAvailableAmount.ts","../src/DelegationFramework/NativeTokenStreamingEnforcer/index.ts","../src/DelegationFramework/NativeTokenStreamingEnforcer/read.ts","../src/DelegationFramework/NativeTokenStreamingEnforcer/methods/getAvailableAmount.ts"],"names":["read_exports","read","readContract","availableAmount","getBlock","getAvailableAmount"],"mappings":"AAAA;AACE;AACF,wDAA6B;AAC7B;AACA;ACJA,IAAA,oCAAA,EAAA,CAAA,CAAA;AAAA,wCAAA,mCAAA,EAAA;AAAA,EAAA,IAAA,EAAA,CAAA,EAAA,GAAA;AAAA,CAAA,CAAA;ADSA;AACA;AEVA,IAAA,aAAA,EAAA,CAAA,CAAA;AAAA,wCAAA,YAAA,EAAA;AAAA,EAAA,kBAAA,EAAA,CAAA,EAAA,GAAA;AAAA,CAAA,CAAA;AFeA;AACA;AGhBA,2DAA4C;AAE5C,uCAA6B;AAUtB,IAAM,KAAA,EAAO,MAAA,CAAO;AAAA,EACzB,MAAA;AAAA,EACA,eAAA;AAAA,EACA,cAAA;AAAA,EACA,iBAAA;AAAA,EACA;AACF,CAAA,EAAA,GAAwC;AACtC,EAAA,MAAM,CAAC,eAAA,EAAiB,WAAA,EAAa,aAAa,EAAA,EAAI,MAAM,mCAAA;AAAA,IAC1D,MAAA;AAAA,IACA;AAAA,MACE,OAAA,EAAS,eAAA;AAAA,MACT,GAAA,EAAK,2CAAA;AAAA,MACL,YAAA,EAAc,oBAAA;AAAA,MACd,IAAA,EAAM,CAAC,cAAA,EAAgB,iBAAA,EAAmB,KAAK;AAAA,IACjD;AAAA,EACF,CAAA;AAEA,EAAA,OAAO;AAAA,IACL,eAAA;AAAA,IACA,WAAA;AAAA,IACA;AAAA,EACF,CAAA;AACF,CAAA;AHOA;AACA;AI1CA,IAAA,+BAAA,EAAA,CAAA,CAAA;AAAA,wCAAA,8BAAA,EAAA;AAAA,EAAA,IAAA,EAAA,CAAA,EAAA,GAAAA;AAAA,CAAA,CAAA;AJ+CA;AACA;AKhDA,IAAAA,cAAAA,EAAA,CAAA,CAAA;AAAA,wCAAA,aAAAA,EAAA;AAAA,EAAA,kBAAA,EAAA,CAAA,EAAA,GAA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A;AACA;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,6lBAAC","file":"/home/runner/work/smart-accounts-kit/smart-accounts-kit/packages/smart-accounts-kit/dist/chunk-3SHZ7PV2.cjs","sourcesContent":[null,"import * as read from './read';\n\nexport { read };\n","import { read as getAvailableAmount } from './methods/getAvailableAmount';\n\nexport { getAvailableAmount };\n","import { ERC20PeriodTransferEnforcer } from '@metamask/delegation-abis';\nimport type { Address, Client, Hex } from 'viem';\nimport { readContract } from 'viem/actions';\n\nexport type ReadGetAvailableAmountParameters = {\n client: Client;\n contractAddress: Address;\n delegationHash: Hex;\n delegationManager: Address;\n terms: Hex;\n};\n\nexport const read = async ({\n client,\n contractAddress,\n delegationHash,\n delegationManager,\n terms,\n}: ReadGetAvailableAmountParameters) => {\n const [availableAmount, isNewPeriod, currentPeriod] = await readContract(\n client,\n {\n address: contractAddress,\n abi: ERC20PeriodTransferEnforcer,\n functionName: 'getAvailableAmount',\n args: [delegationHash, delegationManager, terms],\n },\n );\n\n return {\n availableAmount,\n isNewPeriod,\n currentPeriod,\n };\n};\n","import * as read from './read';\n\nexport { read };\n","import { read as getAvailableAmount } from './methods/getAvailableAmount';\n\nexport { getAvailableAmount };\n","import { ERC20StreamingEnforcer } from '@metamask/delegation-abis';\nimport type { Address, Client, Hex } from 'viem';\nimport { readContract, getBlock } from 'viem/actions';\n\nexport type ReadGetAvailableAmountParameters = {\n client: Client;\n contractAddress: Address;\n delegationManager: Address;\n delegationHash: Hex;\n terms: Hex;\n};\n\nexport const read = async ({\n client,\n contractAddress,\n delegationManager,\n delegationHash,\n terms,\n}: ReadGetAvailableAmountParameters) => {\n // Get current block timestamp from blockchain\n const currentBlock = await getBlock(client);\n const currentTimestamp = currentBlock.timestamp;\n\n // First, get the current state from the contract\n const allowanceState = await readContract(client, {\n address: contractAddress,\n abi: ERC20StreamingEnforcer,\n functionName: 'streamingAllowances',\n args: [delegationManager, delegationHash],\n });\n\n const [initialAmount, maxAmount, amountPerSecond, startTime, spent] =\n allowanceState;\n\n // Check if state exists (startTime != 0)\n if (startTime !== 0n) {\n // State exists, calculate available amount using the stored state\n const availableAmount = getAvailableAmount({\n initialAmount,\n maxAmount,\n amountPerSecond,\n startTime,\n spent,\n currentTimestamp,\n });\n\n return {\n availableAmount,\n };\n }\n\n // State doesn't exist, decode terms and simulate with spent = 0\n const decodedTerms = await readContract(client, {\n address: contractAddress,\n abi: ERC20StreamingEnforcer,\n functionName: 'getTermsInfo',\n args: [terms],\n });\n\n const [\n ,\n decodedInitialAmount,\n decodedMaxAmount,\n decodedAmountPerSecond,\n decodedStartTime,\n ] = decodedTerms;\n\n // Simulate using decoded terms with spent = 0\n const availableAmount = getAvailableAmount({\n initialAmount: decodedInitialAmount,\n maxAmount: decodedMaxAmount,\n amountPerSecond: decodedAmountPerSecond,\n startTime: decodedStartTime,\n spent: 0n,\n currentTimestamp,\n });\n\n return {\n availableAmount,\n };\n};\n\n/**\n * Replicates the internal _getAvailableAmount logic from the smart contract.\n *\n * @param allowance - The allowance object containing all parameters.\n * @param allowance.initialAmount - The initial amount available.\n * @param allowance.maxAmount - The maximum amount allowed.\n * @param allowance.amountPerSecond - The amount streamed per second.\n * @param allowance.startTime - The start time of the streaming.\n * @param allowance.spent - The amount already spent.\n * @param allowance.currentTimestamp - The current timestamp.\n * @returns The available amount that can be spent.\n */\nfunction getAvailableAmount(allowance: {\n initialAmount: bigint;\n maxAmount: bigint;\n amountPerSecond: bigint;\n startTime: bigint;\n spent: bigint;\n currentTimestamp: bigint;\n}): bigint {\n // If current time is before start time, nothing is available\n if (allowance.currentTimestamp < allowance.startTime) {\n return 0n;\n }\n\n // Calculate elapsed time since start\n const elapsed = allowance.currentTimestamp - allowance.startTime;\n\n // Calculate total unlocked amount\n let unlocked = allowance.initialAmount + allowance.amountPerSecond * elapsed;\n\n // Cap by max amount\n if (unlocked > allowance.maxAmount) {\n unlocked = allowance.maxAmount;\n }\n\n // If spent >= unlocked, nothing available\n if (allowance.spent >= unlocked) {\n return 0n;\n }\n\n // Return available amount\n return unlocked - allowance.spent;\n}\n","import * as read from './read';\n\nexport { read };\n","import { read as getAvailableAmount } from './methods/getAvailableAmount';\n\nexport { getAvailableAmount };\n","import { MultiTokenPeriodEnforcer } from '@metamask/delegation-abis';\nimport type { Address, Client, Hex } from 'viem';\nimport { readContract } from 'viem/actions';\n\nexport type ReadGetAvailableAmountParameters = {\n client: Client;\n contractAddress: Address;\n delegationHash: Hex;\n delegationManager: Address;\n terms: Hex;\n args: Hex;\n};\n\nexport const read = async ({\n client,\n contractAddress,\n delegationHash,\n delegationManager,\n terms,\n args,\n}: ReadGetAvailableAmountParameters) => {\n const [availableAmount, isNewPeriod, currentPeriod] = await readContract(\n client,\n {\n address: contractAddress,\n abi: MultiTokenPeriodEnforcer,\n functionName: 'getAvailableAmount',\n args: [delegationHash, delegationManager, terms, args],\n },\n );\n\n return {\n availableAmount,\n isNewPeriod,\n currentPeriod,\n };\n};\n","import * as read from './read';\n\nexport { read };\n","import { read as getAvailableAmount } from './methods/getAvailableAmount';\n\nexport { getAvailableAmount };\n","import { NativeTokenPeriodTransferEnforcer } from '@metamask/delegation-abis';\nimport type { Address, Client, Hex } from 'viem';\nimport { readContract } from 'viem/actions';\n\nexport type ReadGetAvailableAmountParameters = {\n client: Client;\n contractAddress: Address;\n delegationHash: Hex;\n delegationManager: Address;\n terms: Hex;\n};\n\nexport const read = async ({\n client,\n contractAddress,\n delegationHash,\n delegationManager,\n terms,\n}: ReadGetAvailableAmountParameters) => {\n const [availableAmount, isNewPeriod, currentPeriod] = await readContract(\n client,\n {\n address: contractAddress,\n abi: NativeTokenPeriodTransferEnforcer,\n functionName: 'getAvailableAmount',\n args: [delegationHash, delegationManager, terms],\n },\n );\n\n return {\n availableAmount,\n isNewPeriod,\n currentPeriod,\n };\n};\n","import * as read from './read';\n\nexport { read };\n","import { read as getAvailableAmount } from './methods/getAvailableAmount';\n\nexport { getAvailableAmount };\n","import { NativeTokenStreamingEnforcer } from '@metamask/delegation-abis';\nimport type { Address, Client, Hex } from 'viem';\nimport { readContract, getBlock } from 'viem/actions';\n\nexport type ReadGetAvailableAmountParameters = {\n client: Client;\n contractAddress: Address;\n delegationManager: Address;\n delegationHash: Hex;\n terms: Hex;\n};\n\nexport const read = async ({\n client,\n contractAddress,\n delegationManager,\n delegationHash,\n terms,\n}: ReadGetAvailableAmountParameters) => {\n // Get current block timestamp from blockchain\n const currentBlock = await getBlock(client);\n const currentTimestamp = currentBlock.timestamp;\n\n // First, get the current state from the contract\n const allowanceState = await readContract(client, {\n address: contractAddress,\n abi: NativeTokenStreamingEnforcer,\n functionName: 'streamingAllowances',\n args: [delegationManager, delegationHash],\n });\n\n const [initialAmount, maxAmount, amountPerSecond, startTime, spent] =\n allowanceState;\n\n // Check if state exists (startTime != 0)\n if (startTime !== 0n) {\n // State exists, calculate available amount using the stored state\n const availableAmount = getAvailableAmount({\n initialAmount,\n maxAmount,\n amountPerSecond,\n startTime,\n spent,\n currentTimestamp,\n });\n\n return {\n availableAmount,\n };\n }\n\n // State doesn't exist, decode terms and simulate with spent = 0\n const decodedTerms = await readContract(client, {\n address: contractAddress,\n abi: NativeTokenStreamingEnforcer,\n functionName: 'getTermsInfo',\n args: [terms],\n });\n\n const [\n decodedInitialAmount,\n decodedMaxAmount,\n decodedAmountPerSecond,\n decodedStartTime,\n ] = decodedTerms;\n\n // Simulate using decoded terms with spent = 0\n const availableAmount = getAvailableAmount({\n initialAmount: decodedInitialAmount,\n maxAmount: decodedMaxAmount,\n amountPerSecond: decodedAmountPerSecond,\n startTime: decodedStartTime,\n spent: 0n,\n currentTimestamp,\n });\n\n return {\n availableAmount,\n };\n};\n\n/**\n * Replicates the internal _getAvailableAmount logic from the smart contract.\n *\n * @param allowance - The allowance object containing all parameters.\n * @param allowance.initialAmount - The initial amount available.\n * @param allowance.maxAmount - The maximum amount allowed.\n * @param allowance.amountPerSecond - The amount streamed per second.\n * @param allowance.startTime - The start time of the streaming.\n * @param allowance.spent - The amount already spent.\n * @param allowance.currentTimestamp - The current timestamp.\n * @returns The available amount that can be spent.\n */\nfunction getAvailableAmount(allowance: {\n initialAmount: bigint;\n maxAmount: bigint;\n amountPerSecond: bigint;\n startTime: bigint;\n spent: bigint;\n currentTimestamp: bigint;\n}): bigint {\n // If current time is before start time, nothing is available\n if (allowance.currentTimestamp < allowance.startTime) {\n return 0n;\n }\n\n // Calculate elapsed time since start\n const elapsed = allowance.currentTimestamp - allowance.startTime;\n\n // Calculate total unlocked amount\n let unlocked = allowance.initialAmount + allowance.amountPerSecond * elapsed;\n\n // Cap by max amount\n if (unlocked > allowance.maxAmount) {\n unlocked = allowance.maxAmount;\n }\n\n // If spent >= unlocked, nothing available\n if (allowance.spent >= unlocked) {\n return 0n;\n }\n\n // Return available amount\n return unlocked - allowance.spent;\n}\n"]}
|
|
@@ -7,11 +7,13 @@ var createExecution = ({
|
|
|
7
7
|
target,
|
|
8
8
|
value = 0n,
|
|
9
9
|
callData = "0x"
|
|
10
|
-
}) =>
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
}) => {
|
|
11
|
+
return {
|
|
12
|
+
target,
|
|
13
|
+
value,
|
|
14
|
+
callData
|
|
15
|
+
};
|
|
16
|
+
};
|
|
15
17
|
var ExecutionMode = /* @__PURE__ */ ((ExecutionMode2) => {
|
|
16
18
|
ExecutionMode2["SingleDefault"] = "0x0000000000000000000000000000000000000000000000000000000000000000";
|
|
17
19
|
ExecutionMode2["SingleTry"] = "0x0001000000000000000000000000000000000000000000000000000000000000";
|
|
@@ -74,4 +76,4 @@ export {
|
|
|
74
76
|
encodeExecutionCalldata,
|
|
75
77
|
encodeExecutionCalldatas
|
|
76
78
|
};
|
|
77
|
-
//# sourceMappingURL=chunk-
|
|
79
|
+
//# sourceMappingURL=chunk-4QXIOE7F.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/executions.ts"],"sourcesContent":["import {\n type Address,\n type Hex,\n encodeAbiParameters,\n encodePacked,\n} from 'viem';\n\nexport type ExecutionStruct = {\n target: Address;\n value: bigint;\n callData: Hex;\n};\n\nexport type CreateExecutionArgs = {\n target: Address;\n value?: bigint;\n callData?: Hex;\n};\n\n/**\n * Creates an execution data structure.\n *\n * @param args - The arguments for creating an execution.\n * @param args.target - The address to invoke some calldata on.\n * @param args.value - ETH to send to the address.\n * @param args.callData - The calldata to invoke on the address.\n * @returns The created execution data structure.\n */\nexport const createExecution = ({\n target,\n value = 0n,\n callData = '0x',\n}: CreateExecutionArgs): ExecutionStruct => {\n return {\n target,\n value,\n callData,\n };\n};\n\n// Encoded modes\n// https://github.com/erc7579/erc7579-implementation/blob/main/src/lib/ModeLib.sol\nexport enum ExecutionMode {\n SingleDefault = '0x0000000000000000000000000000000000000000000000000000000000000000',\n SingleTry = '0x0001000000000000000000000000000000000000000000000000000000000000',\n BatchDefault = '0x0100000000000000000000000000000000000000000000000000000000000000',\n BatchTry = '0x0101000000000000000000000000000000000000000000000000000000000000',\n}\n\n/**\n * The ABI type components of an Execution.\n */\nexport const EXECUTION_ABI_TYPE_COMPONENTS = [\n { type: 'address', name: 'target' },\n { type: 'uint256', name: 'value' },\n { type: 'bytes', name: 'callData' },\n];\n\n/**\n * Encodes a single Execution. Used for executing a single Execution in a DeleGator SCA.\n *\n * @param execution - The execution to encode.\n * @returns The encoded execution.\n */\nexport const encodeSingleExecution = (execution: ExecutionStruct): Hex => {\n return encodePacked(\n ['address', 'uint256', 'bytes'],\n [execution.target, execution.value, execution.callData],\n );\n};\n\n/**\n * Encodes a batch of Executions. Used for executing a batch of Executions in a DeleGator SCA.\n *\n * @param executions - The executions to encode.\n * @returns The encoded executions.\n */\nexport const encodeBatchExecution = (executions: ExecutionStruct[]): Hex => {\n return encodeAbiParameters(\n [\n {\n components: EXECUTION_ABI_TYPE_COMPONENTS,\n name: 'executions',\n type: 'tuple[]',\n },\n ],\n [executions],\n );\n};\n\n/**\n * Encodes the calldata for interacting with the advanced `execute` DeleGator method.\n *\n * @param executions - The execution(s) to encode.\n * @returns The encoded execution(s).\n */\nexport const encodeExecutionCalldata = (executions: ExecutionStruct[]): Hex => {\n if (executions.length === 0) {\n throw new Error(\n 'Error while getting the execution calldatas, executions is empty',\n );\n }\n if (executions.length === 1) {\n const execution = executions[0];\n if (!execution) {\n throw new Error('Execution not found');\n }\n return encodeSingleExecution(execution);\n }\n\n return encodeBatchExecution(executions);\n};\n\n/**\n * Encodes the calldata for interacting with `redeemDelegations`.\n *\n * @param executionsBatch - The executions to encode.\n * @returns The encoded executions.\n */\nexport const encodeExecutionCalldatas = (\n executionsBatch: ExecutionStruct[][],\n): Hex[] => {\n if (executionsBatch.length === 0) {\n throw new Error(\n 'Error while getting the execution calldatas, executionsBatch is empty',\n );\n }\n return executionsBatch.map(encodeExecutionCalldata);\n};\n"],"mappings":";AAAA;AAAA,EAGE;AAAA,EACA;AAAA,OACK;AAuBA,IAAM,kBAAkB,CAAC;AAAA,EAC9B;AAAA,EACA,QAAQ;AAAA,EACR,WAAW;AACb,MAA4C;AAC1C,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAIO,IAAK,gBAAL,kBAAKA,mBAAL;AACL,EAAAA,eAAA,mBAAgB;AAChB,EAAAA,eAAA,eAAY;AACZ,EAAAA,eAAA,kBAAe;AACf,EAAAA,eAAA,cAAW;AAJD,SAAAA;AAAA,GAAA;AAUL,IAAM,gCAAgC;AAAA,EAC3C,EAAE,MAAM,WAAW,MAAM,SAAS;AAAA,EAClC,EAAE,MAAM,WAAW,MAAM,QAAQ;AAAA,EACjC,EAAE,MAAM,SAAS,MAAM,WAAW;AACpC;AAQO,IAAM,wBAAwB,CAAC,cAAoC;AACxE,SAAO;AAAA,IACL,CAAC,WAAW,WAAW,OAAO;AAAA,IAC9B,CAAC,UAAU,QAAQ,UAAU,OAAO,UAAU,QAAQ;AAAA,EACxD;AACF;AAQO,IAAM,uBAAuB,CAAC,eAAuC;AAC1E,SAAO;AAAA,IACL;AAAA,MACE;AAAA,QACE,YAAY;AAAA,QACZ,MAAM;AAAA,QACN,MAAM;AAAA,MACR;AAAA,IACF;AAAA,IACA,CAAC,UAAU;AAAA,EACb;AACF;AAQO,IAAM,0BAA0B,CAAC,eAAuC;AAC7E,MAAI,WAAW,WAAW,GAAG;AAC3B,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACA,MAAI,WAAW,WAAW,GAAG;AAC3B,UAAM,YAAY,WAAW,CAAC;AAC9B,QAAI,CAAC,WAAW;AACd,YAAM,IAAI,MAAM,qBAAqB;AAAA,IACvC;AACA,WAAO,sBAAsB,SAAS;AAAA,EACxC;AAEA,SAAO,qBAAqB,UAAU;AACxC;AAQO,IAAM,2BAA2B,CACtC,oBACU;AACV,MAAI,gBAAgB,WAAW,GAAG;AAChC,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AACA,SAAO,gBAAgB,IAAI,uBAAuB;AACpD;","names":["ExecutionMode"]}
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
read_exports3,
|
|
5
5
|
read_exports4,
|
|
6
6
|
read_exports5
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-VJXM3LWA.mjs";
|
|
8
8
|
import {
|
|
9
9
|
getSmartAccountsEnvironment,
|
|
10
10
|
prepareSignUserOperationTypedData
|
|
@@ -12,15 +12,16 @@ import {
|
|
|
12
12
|
import {
|
|
13
13
|
createExecution,
|
|
14
14
|
encodeExecutionCalldatas
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-4QXIOE7F.mjs";
|
|
16
16
|
import {
|
|
17
17
|
__export,
|
|
18
18
|
encodeDelegations,
|
|
19
19
|
hashDelegation,
|
|
20
20
|
isDefined,
|
|
21
21
|
prepareSignDelegationTypedData,
|
|
22
|
-
toHexOrThrow
|
|
23
|
-
|
|
22
|
+
toHexOrThrow,
|
|
23
|
+
trackSmartAccountsKitFunctionCall
|
|
24
|
+
} from "./chunk-ZA2XYCVX.mjs";
|
|
24
25
|
|
|
25
26
|
// src/actions/index.ts
|
|
26
27
|
var actions_exports = {};
|
|
@@ -48,6 +49,9 @@ __export(actions_exports, {
|
|
|
48
49
|
import { DelegationManager } from "@metamask/delegation-abis";
|
|
49
50
|
import { concat, encodeFunctionData, isAddressEqual } from "viem";
|
|
50
51
|
async function sendTransactionWithDelegationAction(client, args) {
|
|
52
|
+
trackSmartAccountsKitFunctionCall("sendTransactionWithDelegationAction", {
|
|
53
|
+
chainId: client.chain?.id ?? null
|
|
54
|
+
});
|
|
51
55
|
if (!args.to) {
|
|
52
56
|
throw new Error(
|
|
53
57
|
"`to` is required. `sendTransactionWithDelegation` cannot be used to deploy contracts."
|
|
@@ -93,6 +97,11 @@ async function sendTransactionWithDelegationAction(client, args) {
|
|
|
93
97
|
return hash;
|
|
94
98
|
}
|
|
95
99
|
async function sendUserOperationWithDelegationAction(client, parameters) {
|
|
100
|
+
trackSmartAccountsKitFunctionCall("sendUserOperationWithDelegationAction", {
|
|
101
|
+
chainId: client.chain?.id ?? null,
|
|
102
|
+
callCount: parameters.calls.length,
|
|
103
|
+
hasDependencies: parameters.dependencies !== void 0
|
|
104
|
+
});
|
|
96
105
|
if (parameters.dependencies) {
|
|
97
106
|
const { publicClient } = parameters;
|
|
98
107
|
const includedAccountKeys = {};
|
|
@@ -377,6 +386,12 @@ function rpcSupportedPermissionsToDeveloper(result) {
|
|
|
377
386
|
|
|
378
387
|
// src/actions/erc7715GetGrantedExecutionPermissionsAction.ts
|
|
379
388
|
async function erc7715GetGrantedExecutionPermissionsAction(client) {
|
|
389
|
+
trackSmartAccountsKitFunctionCall(
|
|
390
|
+
"erc7715GetGrantedExecutionPermissionsAction",
|
|
391
|
+
{
|
|
392
|
+
chainId: client.chain?.id ?? null
|
|
393
|
+
}
|
|
394
|
+
);
|
|
380
395
|
const result = await client.request(
|
|
381
396
|
{
|
|
382
397
|
method: "wallet_getGrantedExecutionPermissions",
|
|
@@ -392,6 +407,12 @@ async function erc7715GetGrantedExecutionPermissionsAction(client) {
|
|
|
392
407
|
|
|
393
408
|
// src/actions/erc7715GetSupportedExecutionPermissionsAction.ts
|
|
394
409
|
async function erc7715GetSupportedExecutionPermissionsAction(client) {
|
|
410
|
+
trackSmartAccountsKitFunctionCall(
|
|
411
|
+
"erc7715GetSupportedExecutionPermissionsAction",
|
|
412
|
+
{
|
|
413
|
+
chainId: client.chain?.id ?? null
|
|
414
|
+
}
|
|
415
|
+
);
|
|
395
416
|
const result = await client.request(
|
|
396
417
|
{
|
|
397
418
|
method: "wallet_getSupportedExecutionPermissions",
|
|
@@ -407,6 +428,13 @@ async function erc7715GetSupportedExecutionPermissionsAction(client) {
|
|
|
407
428
|
|
|
408
429
|
// src/actions/erc7715RequestExecutionPermissionsAction.ts
|
|
409
430
|
async function erc7715RequestExecutionPermissionsAction(client, parameters) {
|
|
431
|
+
trackSmartAccountsKitFunctionCall(
|
|
432
|
+
"erc7715RequestExecutionPermissionsAction",
|
|
433
|
+
{
|
|
434
|
+
chainId: client.chain?.id ?? null,
|
|
435
|
+
requestCount: parameters.length
|
|
436
|
+
}
|
|
437
|
+
);
|
|
410
438
|
const formattedPermissionRequest = parameters.map(permissionRequestToRpc);
|
|
411
439
|
const result = await client.request(
|
|
412
440
|
{
|
|
@@ -461,6 +489,12 @@ function getEnforcerAddress({
|
|
|
461
489
|
return enforcerAddress;
|
|
462
490
|
}
|
|
463
491
|
async function getErc20PeriodTransferEnforcerAvailableAmount(client, environment, params) {
|
|
492
|
+
trackSmartAccountsKitFunctionCall(
|
|
493
|
+
"getErc20PeriodTransferEnforcerAvailableAmount",
|
|
494
|
+
{
|
|
495
|
+
chainId: client.chain?.id ?? null
|
|
496
|
+
}
|
|
497
|
+
);
|
|
464
498
|
const enforcerName = "ERC20PeriodTransferEnforcer";
|
|
465
499
|
const delegationManager = getDelegationManager(environment);
|
|
466
500
|
const enforcerAddress = getEnforcerAddress({
|
|
@@ -482,6 +516,12 @@ async function getErc20PeriodTransferEnforcerAvailableAmount(client, environment
|
|
|
482
516
|
});
|
|
483
517
|
}
|
|
484
518
|
async function getErc20StreamingEnforcerAvailableAmount(client, environment, params) {
|
|
519
|
+
trackSmartAccountsKitFunctionCall(
|
|
520
|
+
"getErc20StreamingEnforcerAvailableAmount",
|
|
521
|
+
{
|
|
522
|
+
chainId: client.chain?.id ?? null
|
|
523
|
+
}
|
|
524
|
+
);
|
|
485
525
|
const enforcerName = "ERC20StreamingEnforcer";
|
|
486
526
|
const delegationManager = getDelegationManager(environment);
|
|
487
527
|
const enforcerAddress = getEnforcerAddress({
|
|
@@ -503,6 +543,12 @@ async function getErc20StreamingEnforcerAvailableAmount(client, environment, par
|
|
|
503
543
|
});
|
|
504
544
|
}
|
|
505
545
|
async function getMultiTokenPeriodEnforcerAvailableAmount(client, environment, params) {
|
|
546
|
+
trackSmartAccountsKitFunctionCall(
|
|
547
|
+
"getMultiTokenPeriodEnforcerAvailableAmount",
|
|
548
|
+
{
|
|
549
|
+
chainId: client.chain?.id ?? null
|
|
550
|
+
}
|
|
551
|
+
);
|
|
506
552
|
const enforcerName = "MultiTokenPeriodEnforcer";
|
|
507
553
|
const delegationManager = getDelegationManager(environment);
|
|
508
554
|
const enforcerAddress = getEnforcerAddress({
|
|
@@ -525,6 +571,12 @@ async function getMultiTokenPeriodEnforcerAvailableAmount(client, environment, p
|
|
|
525
571
|
});
|
|
526
572
|
}
|
|
527
573
|
async function getNativeTokenPeriodTransferEnforcerAvailableAmount(client, environment, params) {
|
|
574
|
+
trackSmartAccountsKitFunctionCall(
|
|
575
|
+
"getNativeTokenPeriodTransferEnforcerAvailableAmount",
|
|
576
|
+
{
|
|
577
|
+
chainId: client.chain?.id ?? null
|
|
578
|
+
}
|
|
579
|
+
);
|
|
528
580
|
const enforcerName = "NativeTokenPeriodTransferEnforcer";
|
|
529
581
|
const delegationManager = getDelegationManager(environment);
|
|
530
582
|
const enforcerAddress = getEnforcerAddress({
|
|
@@ -546,6 +598,12 @@ async function getNativeTokenPeriodTransferEnforcerAvailableAmount(client, envir
|
|
|
546
598
|
});
|
|
547
599
|
}
|
|
548
600
|
async function getNativeTokenStreamingEnforcerAvailableAmount(client, environment, params) {
|
|
601
|
+
trackSmartAccountsKitFunctionCall(
|
|
602
|
+
"getNativeTokenStreamingEnforcerAvailableAmount",
|
|
603
|
+
{
|
|
604
|
+
chainId: client.chain?.id ?? null
|
|
605
|
+
}
|
|
606
|
+
);
|
|
549
607
|
const enforcerName = "NativeTokenStreamingEnforcer";
|
|
550
608
|
const delegationManager = getDelegationManager(environment);
|
|
551
609
|
const enforcerAddress = getEnforcerAddress({
|
|
@@ -809,4 +867,4 @@ export {
|
|
|
809
867
|
erc7710BundlerActions,
|
|
810
868
|
actions_exports
|
|
811
869
|
};
|
|
812
|
-
//# sourceMappingURL=chunk-
|
|
870
|
+
//# sourceMappingURL=chunk-734MOPHR.mjs.map
|