mppx 0.6.16 → 0.6.17
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 +6 -0
- package/dist/Challenge.d.ts +0 -10
- package/dist/Challenge.d.ts.map +1 -1
- package/dist/Receipt.d.ts +0 -5
- package/dist/Receipt.d.ts.map +1 -1
- package/dist/stripe/server/internal/html.gen.d.ts +1 -1
- package/dist/stripe/server/internal/html.gen.d.ts.map +1 -1
- package/dist/stripe/server/internal/html.gen.js +1 -1
- package/dist/stripe/server/internal/html.gen.js.map +1 -1
- package/dist/tempo/internal/fee-token.d.ts +7 -0
- package/dist/tempo/internal/fee-token.d.ts.map +1 -0
- package/dist/tempo/internal/fee-token.js +44 -0
- package/dist/tempo/internal/fee-token.js.map +1 -0
- package/dist/tempo/server/Session.d.ts.map +1 -1
- package/dist/tempo/server/Session.js +2 -0
- package/dist/tempo/server/Session.js.map +1 -1
- package/dist/tempo/server/internal/html.gen.d.ts +1 -1
- package/dist/tempo/server/internal/html.gen.d.ts.map +1 -1
- package/dist/tempo/server/internal/html.gen.js +1 -1
- package/dist/tempo/server/internal/html.gen.js.map +1 -1
- package/dist/tempo/session/Chain.d.ts +4 -0
- package/dist/tempo/session/Chain.d.ts.map +1 -1
- package/dist/tempo/session/Chain.js +19 -35
- package/dist/tempo/session/Chain.js.map +1 -1
- package/package.json +3 -3
- package/src/stripe/server/internal/html/node_modules/.bin/mppx +22 -0
- package/src/stripe/server/internal/html/node_modules/.bin/mppx.src +3 -2
- package/src/stripe/server/internal/html.gen.ts +1 -1
- package/src/tempo/internal/fee-token.test.ts +123 -0
- package/src/tempo/internal/fee-token.ts +51 -0
- package/src/tempo/server/Charge.test.ts +18 -2
- package/src/tempo/server/Session.ts +2 -0
- package/src/tempo/server/internal/html/node_modules/.bin/mppx +22 -0
- package/src/tempo/server/internal/html/node_modules/.bin/mppx.src +3 -2
- package/src/tempo/server/internal/html.gen.ts +1 -1
- package/src/tempo/session/Chain.ts +54 -42
|
@@ -17,7 +17,6 @@ import {
|
|
|
17
17
|
sendRawTransaction,
|
|
18
18
|
sendRawTransactionSync,
|
|
19
19
|
signTransaction,
|
|
20
|
-
writeContract,
|
|
21
20
|
} from 'viem/actions'
|
|
22
21
|
import { Transaction } from 'viem/tempo'
|
|
23
22
|
|
|
@@ -25,6 +24,7 @@ import { BadRequestError, ChannelClosedError, VerificationFailedError } from '..
|
|
|
25
24
|
import * as TempoAddress from '../internal/address.js'
|
|
26
25
|
import * as defaults from '../internal/defaults.js'
|
|
27
26
|
import * as FeePayer from '../internal/fee-payer.js'
|
|
27
|
+
import { resolveFeeToken } from '../internal/fee-token.js'
|
|
28
28
|
import * as Channel from './Channel.js'
|
|
29
29
|
import { escrowAbi } from './escrow.abi.js'
|
|
30
30
|
import type { SignedVoucher } from './Types.js'
|
|
@@ -94,16 +94,14 @@ function assertUint128(amount: bigint): void {
|
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
-
function isTempoAccessKeyAccount(
|
|
98
|
-
account: Account,
|
|
99
|
-
): account is Account & { accessKeyAddress: Address } {
|
|
100
|
-
return 'accessKeyAddress' in account && typeof account.accessKeyAddress === 'string'
|
|
101
|
-
}
|
|
102
|
-
|
|
103
97
|
/** Options for {@link settleOnChain}. */
|
|
104
98
|
export type SettleOptions =
|
|
105
|
-
| { feePayer: Account; account: Account }
|
|
106
|
-
| {
|
|
99
|
+
| { candidateFeeTokens?: readonly Address[] | undefined; feePayer: Account; account: Account }
|
|
100
|
+
| {
|
|
101
|
+
candidateFeeTokens?: readonly Address[] | undefined
|
|
102
|
+
feePayer?: undefined
|
|
103
|
+
account?: Account | undefined
|
|
104
|
+
}
|
|
107
105
|
|
|
108
106
|
/**
|
|
109
107
|
* Submit a settle transaction on-chain.
|
|
@@ -123,31 +121,38 @@ export async function settleOnChain(
|
|
|
123
121
|
const args = [voucher.channelId, voucher.cumulativeAmount, voucher.signature] as const
|
|
124
122
|
if (options?.feePayer) {
|
|
125
123
|
const data = encodeFunctionData({ abi: escrowAbi, functionName: 'settle', args })
|
|
126
|
-
return sendFeePayerTx(
|
|
127
|
-
}
|
|
128
|
-
if (isTempoAccessKeyAccount(resolved)) {
|
|
129
|
-
return sendAccountTx(
|
|
124
|
+
return sendFeePayerTx(
|
|
130
125
|
client,
|
|
131
126
|
resolved,
|
|
127
|
+
options.feePayer,
|
|
132
128
|
escrowContract,
|
|
133
|
-
|
|
129
|
+
data,
|
|
134
130
|
'settle',
|
|
131
|
+
options.candidateFeeTokens,
|
|
135
132
|
)
|
|
136
133
|
}
|
|
137
|
-
return
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
abi: escrowAbi,
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
134
|
+
return sendAccountTx(
|
|
135
|
+
client,
|
|
136
|
+
resolved,
|
|
137
|
+
escrowContract,
|
|
138
|
+
encodeFunctionData({ abi: escrowAbi, functionName: 'settle', args }),
|
|
139
|
+
'settle',
|
|
140
|
+
options?.candidateFeeTokens,
|
|
141
|
+
)
|
|
145
142
|
}
|
|
146
143
|
|
|
147
144
|
/** Options for {@link closeOnChain}. */
|
|
148
145
|
export type CloseOptions =
|
|
149
|
-
| {
|
|
150
|
-
|
|
146
|
+
| {
|
|
147
|
+
candidateFeeTokens?: readonly Address[] | undefined
|
|
148
|
+
feePayer: Account
|
|
149
|
+
account: Account
|
|
150
|
+
}
|
|
151
|
+
| {
|
|
152
|
+
candidateFeeTokens?: readonly Address[] | undefined
|
|
153
|
+
feePayer?: undefined
|
|
154
|
+
account?: Account | undefined
|
|
155
|
+
}
|
|
151
156
|
|
|
152
157
|
/**
|
|
153
158
|
* Submit a close transaction on-chain.
|
|
@@ -167,25 +172,24 @@ export async function closeOnChain(
|
|
|
167
172
|
const args = [voucher.channelId, voucher.cumulativeAmount, voucher.signature] as const
|
|
168
173
|
if (options?.feePayer) {
|
|
169
174
|
const data = encodeFunctionData({ abi: escrowAbi, functionName: 'close', args })
|
|
170
|
-
return sendFeePayerTx(
|
|
171
|
-
}
|
|
172
|
-
if (isTempoAccessKeyAccount(resolved)) {
|
|
173
|
-
return sendAccountTx(
|
|
175
|
+
return sendFeePayerTx(
|
|
174
176
|
client,
|
|
175
177
|
resolved,
|
|
178
|
+
options.feePayer,
|
|
176
179
|
escrowContract,
|
|
177
|
-
|
|
180
|
+
data,
|
|
178
181
|
'close',
|
|
182
|
+
options.candidateFeeTokens,
|
|
179
183
|
)
|
|
180
184
|
}
|
|
181
|
-
return
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
abi: escrowAbi,
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
185
|
+
return sendAccountTx(
|
|
186
|
+
client,
|
|
187
|
+
resolved,
|
|
188
|
+
escrowContract,
|
|
189
|
+
encodeFunctionData({ abi: escrowAbi, functionName: 'close', args }),
|
|
190
|
+
'close',
|
|
191
|
+
options?.candidateFeeTokens,
|
|
192
|
+
)
|
|
189
193
|
}
|
|
190
194
|
|
|
191
195
|
async function sendAccountTx(
|
|
@@ -194,10 +198,17 @@ async function sendAccountTx(
|
|
|
194
198
|
to: Address,
|
|
195
199
|
data: Hex,
|
|
196
200
|
label: string,
|
|
201
|
+
candidateFeeTokens?: readonly Address[] | undefined,
|
|
197
202
|
): Promise<Hex> {
|
|
203
|
+
const feeToken = await resolveFeeToken({
|
|
204
|
+
account: account.address,
|
|
205
|
+
candidateTokens: candidateFeeTokens,
|
|
206
|
+
client,
|
|
207
|
+
})
|
|
198
208
|
const prepared = await prepareTransactionRequest(client, {
|
|
199
209
|
account,
|
|
200
210
|
calls: [{ to, data }],
|
|
211
|
+
...(feeToken ? { feeToken } : {}),
|
|
201
212
|
} as never)
|
|
202
213
|
prepared.gas = prepared.gas! + 5_000n
|
|
203
214
|
|
|
@@ -236,12 +247,13 @@ async function sendFeePayerTx(
|
|
|
236
247
|
to: Address,
|
|
237
248
|
data: Hex,
|
|
238
249
|
label: string,
|
|
250
|
+
candidateFeeTokens?: readonly Address[] | undefined,
|
|
239
251
|
): Promise<Hex> {
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
252
|
+
const feeToken = await resolveFeeToken({
|
|
253
|
+
account: feePayer.address,
|
|
254
|
+
candidateTokens: candidateFeeTokens,
|
|
255
|
+
client,
|
|
256
|
+
})
|
|
245
257
|
|
|
246
258
|
const prepared = await prepareTransactionRequest(client, {
|
|
247
259
|
account,
|