mppx 0.4.10 → 0.4.12
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 +23 -1
- package/dist/internal/env.d.ts +1 -1
- package/dist/internal/env.d.ts.map +1 -1
- package/dist/internal/env.js +2 -6
- package/dist/internal/env.js.map +1 -1
- package/dist/internal/types.d.ts +23 -0
- package/dist/internal/types.d.ts.map +1 -1
- package/dist/server/Mppx.d.ts +1 -1
- package/dist/server/Mppx.d.ts.map +1 -1
- package/dist/server/Mppx.js +49 -2
- package/dist/server/Mppx.js.map +1 -1
- package/dist/stripe/internal/types.d.ts +3 -0
- package/dist/stripe/internal/types.d.ts.map +1 -1
- package/dist/stripe/server/Charge.d.ts.map +1 -1
- package/dist/stripe/server/Charge.js +9 -2
- package/dist/stripe/server/Charge.js.map +1 -1
- package/dist/tempo/Methods.d.ts +15 -0
- package/dist/tempo/Methods.d.ts.map +1 -1
- package/dist/tempo/Methods.js +27 -3
- package/dist/tempo/Methods.js.map +1 -1
- package/dist/tempo/client/Charge.d.ts +21 -0
- package/dist/tempo/client/Charge.d.ts.map +1 -1
- package/dist/tempo/client/Charge.js +33 -7
- package/dist/tempo/client/Charge.js.map +1 -1
- package/dist/tempo/client/Methods.d.ts +15 -0
- package/dist/tempo/client/Methods.d.ts.map +1 -1
- package/dist/tempo/internal/account.d.ts +5 -11
- package/dist/tempo/internal/account.d.ts.map +1 -1
- package/dist/tempo/internal/charge.d.ts +20 -0
- package/dist/tempo/internal/charge.d.ts.map +1 -0
- package/dist/tempo/internal/charge.js +23 -0
- package/dist/tempo/internal/charge.js.map +1 -0
- package/dist/tempo/internal/fee-payer.d.ts.map +1 -1
- package/dist/tempo/internal/fee-payer.js +15 -3
- package/dist/tempo/internal/fee-payer.js.map +1 -1
- package/dist/tempo/server/Charge.d.ts +17 -2
- package/dist/tempo/server/Charge.d.ts.map +1 -1
- package/dist/tempo/server/Charge.js +148 -99
- package/dist/tempo/server/Charge.js.map +1 -1
- package/dist/tempo/server/Methods.d.ts +17 -2
- package/dist/tempo/server/Methods.d.ts.map +1 -1
- package/dist/tempo/server/Methods.js +4 -1
- package/dist/tempo/server/Methods.js.map +1 -1
- package/dist/tempo/server/Session.d.ts +9 -4
- package/dist/tempo/server/Session.d.ts.map +1 -1
- package/dist/tempo/server/Session.js +25 -6
- package/dist/tempo/server/Session.js.map +1 -1
- package/dist/tempo/session/Chain.d.ts +18 -2
- package/dist/tempo/session/Chain.d.ts.map +1 -1
- package/dist/tempo/session/Chain.js +18 -14
- package/dist/tempo/session/Chain.js.map +1 -1
- package/package.json +1 -1
- package/src/internal/env.test.ts +12 -12
- package/src/internal/env.ts +2 -6
- package/src/internal/types.ts +25 -0
- package/src/server/Mppx.test.ts +287 -0
- package/src/server/Mppx.ts +59 -5
- package/src/stripe/internal/types.ts +5 -1
- package/src/stripe/server/Charge.test.ts +52 -1
- package/src/stripe/server/Charge.ts +12 -4
- package/src/tempo/Methods.test.ts +79 -0
- package/src/tempo/Methods.ts +53 -17
- package/src/tempo/client/Charge.ts +41 -8
- package/src/tempo/internal/account.ts +7 -14
- package/src/tempo/internal/charge.ts +43 -0
- package/src/tempo/internal/fee-payer.test.ts +33 -14
- package/src/tempo/internal/fee-payer.ts +21 -6
- package/src/tempo/server/Charge.test.ts +231 -0
- package/src/tempo/server/Charge.ts +193 -124
- package/src/tempo/server/Methods.ts +4 -1
- package/src/tempo/server/Session.test.ts +57 -0
- package/src/tempo/server/Session.ts +33 -20
- package/src/tempo/session/Chain.test.ts +25 -5
- package/src/tempo/session/Chain.ts +30 -14
|
@@ -93,6 +93,11 @@ function assertUint128(amount: bigint): void {
|
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
+
/** Options for {@link settleOnChain}. */
|
|
97
|
+
export type SettleOptions =
|
|
98
|
+
| { feePayer: Account; account: Account }
|
|
99
|
+
| { feePayer?: undefined; account?: Account | undefined }
|
|
100
|
+
|
|
96
101
|
/**
|
|
97
102
|
* Submit a settle transaction on-chain.
|
|
98
103
|
*/
|
|
@@ -100,16 +105,21 @@ export async function settleOnChain(
|
|
|
100
105
|
client: Client,
|
|
101
106
|
escrowContract: Address,
|
|
102
107
|
voucher: SignedVoucher,
|
|
103
|
-
|
|
108
|
+
options?: SettleOptions,
|
|
104
109
|
): Promise<Hex> {
|
|
105
110
|
assertUint128(voucher.cumulativeAmount)
|
|
111
|
+
const resolved = options?.account ?? client.account
|
|
112
|
+
if (!resolved)
|
|
113
|
+
throw new Error(
|
|
114
|
+
'Cannot settle channel: no account available. Pass an `account` to tempo.settle(), or provide a `getClient` that returns an account-bearing client.',
|
|
115
|
+
)
|
|
106
116
|
const args = [voucher.channelId, voucher.cumulativeAmount, voucher.signature] as const
|
|
107
|
-
if (feePayer) {
|
|
117
|
+
if (options?.feePayer) {
|
|
108
118
|
const data = encodeFunctionData({ abi: escrowAbi, functionName: 'settle', args })
|
|
109
|
-
return sendFeePayerTx(client, feePayer, escrowContract, data, 'settle')
|
|
119
|
+
return sendFeePayerTx(client, resolved, options.feePayer, escrowContract, data, 'settle')
|
|
110
120
|
}
|
|
111
121
|
return writeContract(client, {
|
|
112
|
-
account:
|
|
122
|
+
account: resolved,
|
|
113
123
|
chain: client.chain,
|
|
114
124
|
address: escrowContract,
|
|
115
125
|
abi: escrowAbi,
|
|
@@ -118,6 +128,11 @@ export async function settleOnChain(
|
|
|
118
128
|
})
|
|
119
129
|
}
|
|
120
130
|
|
|
131
|
+
/** Options for {@link closeOnChain}. */
|
|
132
|
+
export type CloseOptions =
|
|
133
|
+
| { feePayer: Account; account: Account }
|
|
134
|
+
| { feePayer?: undefined; account?: Account | undefined }
|
|
135
|
+
|
|
121
136
|
/**
|
|
122
137
|
* Submit a close transaction on-chain.
|
|
123
138
|
*/
|
|
@@ -125,19 +140,18 @@ export async function closeOnChain(
|
|
|
125
140
|
client: Client,
|
|
126
141
|
escrowContract: Address,
|
|
127
142
|
voucher: SignedVoucher,
|
|
128
|
-
|
|
129
|
-
feePayer?: Account | undefined,
|
|
143
|
+
options?: CloseOptions,
|
|
130
144
|
): Promise<Hex> {
|
|
131
145
|
assertUint128(voucher.cumulativeAmount)
|
|
132
|
-
const resolved = account ?? client.account
|
|
146
|
+
const resolved = options?.account ?? client.account
|
|
133
147
|
if (!resolved)
|
|
134
148
|
throw new Error(
|
|
135
149
|
'Cannot close channel: no account available. Pass an `account` (viem Account, e.g. privateKeyToAccount("0x...")) to tempo.session(), or provide a `getClient` that returns an account-bearing client.',
|
|
136
150
|
)
|
|
137
151
|
const args = [voucher.channelId, voucher.cumulativeAmount, voucher.signature] as const
|
|
138
|
-
if (feePayer) {
|
|
152
|
+
if (options?.feePayer) {
|
|
139
153
|
const data = encodeFunctionData({ abi: escrowAbi, functionName: 'close', args })
|
|
140
|
-
return sendFeePayerTx(client, feePayer, escrowContract, data, 'close')
|
|
154
|
+
return sendFeePayerTx(client, resolved, options.feePayer, escrowContract, data, 'close')
|
|
141
155
|
}
|
|
142
156
|
return writeContract(client, {
|
|
143
157
|
account: resolved,
|
|
@@ -155,9 +169,13 @@ export async function closeOnChain(
|
|
|
155
169
|
* Follows the same signTransaction + sendRawTransactionSync pattern used
|
|
156
170
|
* by broadcastOpenTransaction / broadcastTopUpTransaction, but originates
|
|
157
171
|
* the transaction server-side (estimating gas and fees first).
|
|
172
|
+
*
|
|
173
|
+
* @param account - The logical sender / msg.sender (e.g. the payee).
|
|
174
|
+
* @param feePayer - The gas sponsor — only co-signs to cover fees.
|
|
158
175
|
*/
|
|
159
176
|
async function sendFeePayerTx(
|
|
160
177
|
client: Client,
|
|
178
|
+
account: Account,
|
|
161
179
|
feePayer: Account,
|
|
162
180
|
to: Address,
|
|
163
181
|
data: Hex,
|
|
@@ -167,12 +185,10 @@ async function sendFeePayerTx(
|
|
|
167
185
|
// token. `feePayer: true` tells the prepare hook to use expiring nonces but
|
|
168
186
|
// does NOT set feeToken automatically, so we must provide it explicitly.
|
|
169
187
|
const chainId = client.chain?.id
|
|
170
|
-
const feeToken = chainId
|
|
171
|
-
? defaults.currency[chainId as keyof typeof defaults.currency]
|
|
172
|
-
: undefined
|
|
188
|
+
const feeToken = chainId ? defaults.resolveCurrency({ chainId }) : undefined
|
|
173
189
|
|
|
174
190
|
const prepared = await prepareTransactionRequest(client, {
|
|
175
|
-
account
|
|
191
|
+
account,
|
|
176
192
|
calls: [{ to, data }],
|
|
177
193
|
feePayer: true,
|
|
178
194
|
...(feeToken ? { feeToken } : {}),
|
|
@@ -180,7 +196,7 @@ async function sendFeePayerTx(
|
|
|
180
196
|
|
|
181
197
|
const serialized = (await signTransaction(client, {
|
|
182
198
|
...prepared,
|
|
183
|
-
account
|
|
199
|
+
account,
|
|
184
200
|
feePayer,
|
|
185
201
|
} as never)) as Hex
|
|
186
202
|
|