@insumermodel/mppx-condition-gate 2.0.0 → 2.0.2
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/README.md +39 -6
- package/dist/index.d.ts +30 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +27 -2
- package/dist/index.js.map +1 -1
- package/package.json +2 -3
- package/src/index.ts +54 -3
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @insumermodel/mppx-condition-gate
|
|
2
2
|
|
|
3
|
-
Condition-based access for [mppx](https://github.com/wevm/mppx) routes. One signed call between request and charge gives free access to wallets that meet your conditions; everyone else falls through to the normal paid path.
|
|
3
|
+
Condition-based access for [mppx](https://github.com/wevm/mppx) routes. One signed call between request and charge gives free access to wallets that meet your conditions; everyone else falls through to the normal paid path. Six condition types: token balance, NFT ownership, EAS attestation, Farcaster ID, plus ratio_to_amount (hold >= N x a spend amount) and ratio_to_supply (hold >= a fraction of token supply). No RPC management.
|
|
4
4
|
|
|
5
5
|
> **Migrating from `@insumermodel/mppx-token-gate`?** This is the v2 successor. See [Migration](#migrating-from-mppx-token-gate) below.
|
|
6
6
|
|
|
@@ -49,7 +49,7 @@ Works with any framework (Hono, Express, Elysia, Next.js) and any payment method
|
|
|
49
49
|
|
|
50
50
|
## Condition types
|
|
51
51
|
|
|
52
|
-
Mix any of the
|
|
52
|
+
Mix any of the six in a single call. `matchMode: 'any'` (default) passes when any one is met; `matchMode: 'all'` requires all of them.
|
|
53
53
|
|
|
54
54
|
### Token balance
|
|
55
55
|
|
|
@@ -112,11 +112,42 @@ Available templates: `coinbase_verified_account`, `coinbase_verified_country`, `
|
|
|
112
112
|
|
|
113
113
|
Always evaluated on Optimism (chain 10). Passes if the wallet has any FID registered.
|
|
114
114
|
|
|
115
|
+
### Ratio to amount
|
|
116
|
+
|
|
117
|
+
Self-scaling spend rule: passes when the wallet holds at least `multiple` times a per-request `amount`. RPC EVM chains only.
|
|
118
|
+
|
|
119
|
+
```ts
|
|
120
|
+
{
|
|
121
|
+
type: 'ratio_to_amount',
|
|
122
|
+
contractAddress: 'native', // or an ERC-20 address
|
|
123
|
+
chainId: 8453,
|
|
124
|
+
multiple: 10,
|
|
125
|
+
amount: 250,
|
|
126
|
+
label: 'Holds >= 10x the 250-unit spend',
|
|
127
|
+
}
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### Ratio to supply
|
|
131
|
+
|
|
132
|
+
Share-of-supply rule: passes when the wallet holds at least `minFraction` of the token's on-chain total supply. For project/governance tokens, not stablecoins. RPC EVM chains, ERC-20 contracts only.
|
|
133
|
+
|
|
134
|
+
```ts
|
|
135
|
+
{
|
|
136
|
+
type: 'ratio_to_supply',
|
|
137
|
+
contractAddress: '0x1f9840a85d5aF5bf1D1762F925BdADdC4201F984', // UNI
|
|
138
|
+
chainId: 1,
|
|
139
|
+
minFraction: 0.005, // 0.5% of supply
|
|
140
|
+
label: 'Holds >= 0.5% of UNI supply',
|
|
141
|
+
}
|
|
142
|
+
```
|
|
143
|
+
|
|
115
144
|
## API key and credits
|
|
116
145
|
|
|
117
|
-
|
|
146
|
+
Each call to `/v1/attest` consumes one or more attestation credits. New keys ship with **10 free credits**, enough to wire up the integration end-to-end before paying anything.
|
|
118
147
|
|
|
119
|
-
|
|
148
|
+
Two ways to provision a key.
|
|
149
|
+
|
|
150
|
+
**Email signup** (human-managed):
|
|
120
151
|
|
|
121
152
|
```bash
|
|
122
153
|
curl -X POST https://api.insumermodel.com/v1/keys/create \
|
|
@@ -124,9 +155,11 @@ curl -X POST https://api.insumermodel.com/v1/keys/create \
|
|
|
124
155
|
-d '{"email":"you@example.com","appName":"my-app","tier":"free"}'
|
|
125
156
|
```
|
|
126
157
|
|
|
127
|
-
|
|
158
|
+
**On-chain** (autonomous agent bootstrap): send USDC, USDT, or BTC to the platform wallet, then call `POST /v1/keys/buy` with the transaction hash. The transaction sender wallet is the identity, the payment is the auth — no email, no human in the loop.
|
|
159
|
+
|
|
160
|
+
Either way, set `INSUMER_API_KEY` as an environment variable in your runtime.
|
|
128
161
|
|
|
129
|
-
Top up
|
|
162
|
+
**Top up** an existing key on-chain via `POST /v1/credits/buy`. Accepted: USDC or USDT on any major EVM chain, USDC on Solana, or BTC on Bitcoin. See the [credits endpoint](https://insumermodel.com/developers/api-reference/) for transaction format.
|
|
130
163
|
|
|
131
164
|
**Pricing model**: the wallet holder pays nothing at the gated route. The operator running the gate pays per attestation call out of the key's credit balance. Cost per attestation depends on tier and condition mix.
|
|
132
165
|
|
package/dist/index.d.ts
CHANGED
|
@@ -51,12 +51,36 @@ export type FarcasterIdCondition = {
|
|
|
51
51
|
type: 'farcaster_id';
|
|
52
52
|
label?: string;
|
|
53
53
|
};
|
|
54
|
+
/** Self-scaling agent-spend check: met iff balance >= multiple * amount. RPC EVM chains only. */
|
|
55
|
+
export type RatioToAmountCondition = {
|
|
56
|
+
type: 'ratio_to_amount';
|
|
57
|
+
/** Token contract address, or "native" for the chain's native asset. */
|
|
58
|
+
contractAddress: string;
|
|
59
|
+
/** EVM chain ID (ratio conditions are RPC EVM only). */
|
|
60
|
+
chainId: number;
|
|
61
|
+
/** Collateralization multiple. Met iff balance >= multiple * amount. */
|
|
62
|
+
multiple: number;
|
|
63
|
+
/** Per-request reference amount in token/display units (e.g. 100 for 100 USDC, not base units). */
|
|
64
|
+
amount: number;
|
|
65
|
+
label?: string;
|
|
66
|
+
};
|
|
67
|
+
/** Share-of-supply check: met iff balance / totalSupply() >= minFraction. RPC EVM + ERC-20 only. */
|
|
68
|
+
export type RatioToSupplyCondition = {
|
|
69
|
+
type: 'ratio_to_supply';
|
|
70
|
+
/** ERC-20 token contract address (does not accept "native"). */
|
|
71
|
+
contractAddress: string;
|
|
72
|
+
/** EVM chain ID (ratio conditions are RPC EVM only). */
|
|
73
|
+
chainId: number;
|
|
74
|
+
/** Required share of total supply, a fraction in (0, 1] (e.g. 0.005 for 0.5%). */
|
|
75
|
+
minFraction: number;
|
|
76
|
+
label?: string;
|
|
77
|
+
};
|
|
54
78
|
/** Any condition accepted by /v1/attest */
|
|
55
|
-
export type Condition = TokenBalanceCondition | NftOwnershipCondition | EasAttestationCondition | FarcasterIdCondition;
|
|
79
|
+
export type Condition = TokenBalanceCondition | NftOwnershipCondition | EasAttestationCondition | FarcasterIdCondition | RatioToAmountCondition | RatioToSupplyCondition;
|
|
56
80
|
export type ConditionGateOptions = {
|
|
57
81
|
/** InsumerAPI key. Falls back to INSUMER_API_KEY env var. */
|
|
58
82
|
apiKey?: string;
|
|
59
|
-
/** One or more conditions to evaluate. Mix any of the
|
|
83
|
+
/** One or more conditions to evaluate. Mix any of the six types. */
|
|
60
84
|
conditions: Condition[];
|
|
61
85
|
/** Whether the wallet must satisfy "any" (default) or "all" conditions. */
|
|
62
86
|
matchMode?: 'any' | 'all';
|
|
@@ -126,8 +150,10 @@ export declare function parseBitcoinDid(source: string): string | null;
|
|
|
126
150
|
* wallets that meet the conditions. Wallets that do not meet them fall through
|
|
127
151
|
* to the original payment method.
|
|
128
152
|
*
|
|
129
|
-
* Supports
|
|
130
|
-
*
|
|
153
|
+
* Supports six condition types: token_balance, nft_ownership, eas_attestation,
|
|
154
|
+
* farcaster_id, ratio_to_amount (balance >= multiple * amount), and ratio_to_supply
|
|
155
|
+
* (balance / totalSupply >= minFraction; EVM + ERC-20 only). Conditions can be mixed
|
|
156
|
+
* in a single call.
|
|
131
157
|
*
|
|
132
158
|
* The attestation is ECDSA P-256 signed and verifiable offline via the public
|
|
133
159
|
* JWKS at https://insumermodel.com/.well-known/jwks.json.
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAW,MAAM,MAAM,CAAA;AAM3C,MAAM,MAAM,OAAO,GAAG,MAAM,GAAG,QAAQ,GAAG,MAAM,GAAG,SAAS,CAAA;AAE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AM,GAAG,IAAI,CAK5D;AAED,iFAAiF;AACjF,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAO1D;AAED,qFAAqF;AACrF,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAK7D;AAiHD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,MAAM,CAAC,SAAS,EACxB,OAAO,EAAE,oBAAoB,GAC5B,MAAM,CAAC,SAAS,CAyFlB"}
|
package/dist/index.js
CHANGED
|
@@ -95,6 +95,29 @@ function buildBodyConditions(conditions) {
|
|
|
95
95
|
cond.label = c.label;
|
|
96
96
|
return cond;
|
|
97
97
|
}
|
|
98
|
+
if (c.type === 'ratio_to_amount') {
|
|
99
|
+
const cond = {
|
|
100
|
+
type: c.type,
|
|
101
|
+
contractAddress: c.contractAddress,
|
|
102
|
+
chainId: c.chainId,
|
|
103
|
+
multiple: c.multiple,
|
|
104
|
+
amount: c.amount,
|
|
105
|
+
};
|
|
106
|
+
if (c.label)
|
|
107
|
+
cond.label = c.label;
|
|
108
|
+
return cond;
|
|
109
|
+
}
|
|
110
|
+
if (c.type === 'ratio_to_supply') {
|
|
111
|
+
const cond = {
|
|
112
|
+
type: c.type,
|
|
113
|
+
contractAddress: c.contractAddress,
|
|
114
|
+
chainId: c.chainId,
|
|
115
|
+
minFraction: c.minFraction,
|
|
116
|
+
};
|
|
117
|
+
if (c.label)
|
|
118
|
+
cond.label = c.label;
|
|
119
|
+
return cond;
|
|
120
|
+
}
|
|
98
121
|
// token_balance or nft_ownership
|
|
99
122
|
const cond = {
|
|
100
123
|
type: c.type,
|
|
@@ -162,8 +185,10 @@ async function callAttest(wallet, walletType, conditions, options) {
|
|
|
162
185
|
* wallets that meet the conditions. Wallets that do not meet them fall through
|
|
163
186
|
* to the original payment method.
|
|
164
187
|
*
|
|
165
|
-
* Supports
|
|
166
|
-
*
|
|
188
|
+
* Supports six condition types: token_balance, nft_ownership, eas_attestation,
|
|
189
|
+
* farcaster_id, ratio_to_amount (balance >= multiple * amount), and ratio_to_supply
|
|
190
|
+
* (balance / totalSupply >= minFraction; EVM + ERC-20 only). Conditions can be mixed
|
|
191
|
+
* in a single call.
|
|
167
192
|
*
|
|
168
193
|
* The attestation is ECDSA P-256 signed and verifiable offline via the public
|
|
169
194
|
* JWKS at https://insumermodel.com/.well-known/jwks.json.
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAuKA,MAAM,KAAK,GAAG,IAAI,GAAG,EAAsB,CAAA;AAE3C,SAAS,gBAAgB,CAAC,CAAY;IACpC,IAAI,CAAC,CAAC,IAAI,KAAK,cAAc;QAAE,OAAO,cAAc,CAAA;IACpD,IAAI,CAAC,CAAC,IAAI,KAAK,iBAAiB,EAAE,CAAC;QACjC,OAAO,OAAO,CAAC,CAAC,OAAO,IAAI,CAAC,CAAC,CAAC,QAAQ,IAAI,CAAC,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC,WAAW,EAAE,EAAE,CAAA;IAC7E,CAAC;IACD,OAAO,GAAG,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,OAAO,IAAI,CAAC,CAAC,eAAe,CAAC,WAAW,EAAE,EAAE,CAAA;AACpE,CAAC;AAED,SAAS,QAAQ,CAAC,OAAe,EAAE,UAAuB;IACxD,MAAM,MAAM,GAAG,CAAC,GAAG,UAAU,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;QAC3C,MAAM,EAAE,GAAG,gBAAgB,CAAC,CAAC,CAAC,CAAA;QAC9B,MAAM,EAAE,GAAG,gBAAgB,CAAC,CAAC,CAAC,CAAA;QAC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AI,IAAI,EAAE,CAAC;gBACT,OAAO;oBACL,MAAM,EAAE,MAAM,CAAC,IAAI;oBACnB,SAAS,EAAE,uBAAuB,WAAW,CAAC,EAAE,EAAE;oBAClD,MAAM,EAAE,SAAkB;oBAC1B,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;iBACpC,CAAA;YACH,CAAC;QACH,CAAC;QAAC,MAAM,CAAC;YACP,8DAA8D;QAChE,CAAC;QAED,OAAO,cAAc,CAAC,MAAM,CAAC,CAAA;IAC/B,CAAC,CAAA;IAED,OAAO;QACL,GAAG,MAAM;QACT,MAAM,EAAE,WAAW;KACpB,CAAA;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@insumermodel/mppx-condition-gate",
|
|
3
|
-
"version": "2.0.
|
|
4
|
-
"description": "Condition-based access for mppx routes. Wallet auth via signed attestations
|
|
3
|
+
"version": "2.0.2",
|
|
4
|
+
"description": "Condition-based access for mppx routes. Wallet auth via signed attestations. Six condition types: token balance, NFT ownership, EAS attestation, Farcaster ID, ratio_to_amount, ratio_to_supply.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -29,7 +29,6 @@
|
|
|
29
29
|
"attestation",
|
|
30
30
|
"eas",
|
|
31
31
|
"farcaster",
|
|
32
|
-
"token-gate",
|
|
33
32
|
"nft",
|
|
34
33
|
"erc20",
|
|
35
34
|
"erc721",
|
package/src/index.ts
CHANGED
|
@@ -66,17 +66,45 @@ export type FarcasterIdCondition = {
|
|
|
66
66
|
label?: string
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
+
/** Self-scaling agent-spend check: met iff balance >= multiple * amount. RPC EVM chains only. */
|
|
70
|
+
export type RatioToAmountCondition = {
|
|
71
|
+
type: 'ratio_to_amount'
|
|
72
|
+
/** Token contract address, or "native" for the chain's native asset. */
|
|
73
|
+
contractAddress: string
|
|
74
|
+
/** EVM chain ID (ratio conditions are RPC EVM only). */
|
|
75
|
+
chainId: number
|
|
76
|
+
/** Collateralization multiple. Met iff balance >= multiple * amount. */
|
|
77
|
+
multiple: number
|
|
78
|
+
/** Per-request reference amount in token/display units (e.g. 100 for 100 USDC, not base units). */
|
|
79
|
+
amount: number
|
|
80
|
+
label?: string
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Share-of-supply check: met iff balance / totalSupply() >= minFraction. RPC EVM + ERC-20 only. */
|
|
84
|
+
export type RatioToSupplyCondition = {
|
|
85
|
+
type: 'ratio_to_supply'
|
|
86
|
+
/** ERC-20 token contract address (does not accept "native"). */
|
|
87
|
+
contractAddress: string
|
|
88
|
+
/** EVM chain ID (ratio conditions are RPC EVM only). */
|
|
89
|
+
chainId: number
|
|
90
|
+
/** Required share of total supply, a fraction in (0, 1] (e.g. 0.005 for 0.5%). */
|
|
91
|
+
minFraction: number
|
|
92
|
+
label?: string
|
|
93
|
+
}
|
|
94
|
+
|
|
69
95
|
/** Any condition accepted by /v1/attest */
|
|
70
96
|
export type Condition =
|
|
71
97
|
| TokenBalanceCondition
|
|
72
98
|
| NftOwnershipCondition
|
|
73
99
|
| EasAttestationCondition
|
|
74
100
|
| FarcasterIdCondition
|
|
101
|
+
| RatioToAmountCondition
|
|
102
|
+
| RatioToSupplyCondition
|
|
75
103
|
|
|
76
104
|
export type ConditionGateOptions = {
|
|
77
105
|
/** InsumerAPI key. Falls back to INSUMER_API_KEY env var. */
|
|
78
106
|
apiKey?: string
|
|
79
|
-
/** One or more conditions to evaluate. Mix any of the
|
|
107
|
+
/** One or more conditions to evaluate. Mix any of the six types. */
|
|
80
108
|
conditions: Condition[]
|
|
81
109
|
/** Whether the wallet must satisfy "any" (default) or "all" conditions. */
|
|
82
110
|
matchMode?: 'any' | 'all'
|
|
@@ -227,6 +255,27 @@ function buildBodyConditions(conditions: Condition[]): Array<Record<string, unkn
|
|
|
227
255
|
if (c.label) cond.label = c.label
|
|
228
256
|
return cond
|
|
229
257
|
}
|
|
258
|
+
if (c.type === 'ratio_to_amount') {
|
|
259
|
+
const cond: Record<string, unknown> = {
|
|
260
|
+
type: c.type,
|
|
261
|
+
contractAddress: c.contractAddress,
|
|
262
|
+
chainId: c.chainId,
|
|
263
|
+
multiple: c.multiple,
|
|
264
|
+
amount: c.amount,
|
|
265
|
+
}
|
|
266
|
+
if (c.label) cond.label = c.label
|
|
267
|
+
return cond
|
|
268
|
+
}
|
|
269
|
+
if (c.type === 'ratio_to_supply') {
|
|
270
|
+
const cond: Record<string, unknown> = {
|
|
271
|
+
type: c.type,
|
|
272
|
+
contractAddress: c.contractAddress,
|
|
273
|
+
chainId: c.chainId,
|
|
274
|
+
minFraction: c.minFraction,
|
|
275
|
+
}
|
|
276
|
+
if (c.label) cond.label = c.label
|
|
277
|
+
return cond
|
|
278
|
+
}
|
|
230
279
|
// token_balance or nft_ownership
|
|
231
280
|
const cond: Record<string, unknown> = {
|
|
232
281
|
type: c.type,
|
|
@@ -302,8 +351,10 @@ async function callAttest(
|
|
|
302
351
|
* wallets that meet the conditions. Wallets that do not meet them fall through
|
|
303
352
|
* to the original payment method.
|
|
304
353
|
*
|
|
305
|
-
* Supports
|
|
306
|
-
*
|
|
354
|
+
* Supports six condition types: token_balance, nft_ownership, eas_attestation,
|
|
355
|
+
* farcaster_id, ratio_to_amount (balance >= multiple * amount), and ratio_to_supply
|
|
356
|
+
* (balance / totalSupply >= minFraction; EVM + ERC-20 only). Conditions can be mixed
|
|
357
|
+
* in a single call.
|
|
307
358
|
*
|
|
308
359
|
* The attestation is ECDSA P-256 signed and verifiable offline via the public
|
|
309
360
|
* JWKS at https://insumermodel.com/.well-known/jwks.json.
|