Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/tempo/server/Session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ export async function settle(
options?: {
escrowContract?: Address | undefined
feePayer?: viem_Account | undefined
account?: viem_Account | undefined
},
): Promise<Hex> {
const channel = await store.getChannel(channelId)
Expand All @@ -359,6 +360,7 @@ export async function settle(
resolvedEscrow,
channel.highestVoucher,
options?.feePayer,
options?.account,
)

await store.updateChannel(channelId, (current) => {
Expand Down
33 changes: 31 additions & 2 deletions src/tempo/session/Chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,44 @@ export async function settleOnChain(
escrowContract: Address,
voucher: SignedVoucher,
feePayer?: Account | undefined,
account?: Account | undefined,
): Promise<Hex> {
assertUint128(voucher.cumulativeAmount)
const args = [voucher.channelId, voucher.cumulativeAmount, voucher.signature] as const
const resolved = account ?? client.account
if (!resolved)
throw new Error(
'Cannot settle channel: no account available. Pass an `account` to tempo.settle(), or provide a `getClient` that returns an account-bearing client.',
)
if (feePayer) {
const data = encodeFunctionData({ abi: escrowAbi, functionName: 'settle', args })
return sendFeePayerTx(client, feePayer, escrowContract, data, 'settle')
const chainId = client.chain?.id
const feeToken = chainId
? defaults.currency[chainId as keyof typeof defaults.currency]
: undefined
const prepared = await prepareTransactionRequest(client, {
account: resolved,
calls: [{ to: escrowContract, data }],
feePayer: true,
...(feeToken ? { feeToken } : {}),
} as never)
const serialized = (await signTransaction(client, {
...prepared,
account: resolved,
feePayer,
} as never)) as Hex
const receipt = await sendRawTransactionSync(client, {
serializedTransaction: serialized as Transaction.TransactionSerializedTempo,
})
if (receipt.status !== 'success') {
throw new VerificationFailedError({
reason: `settle transaction reverted: ${receipt.transactionHash}`,
})
}
return receipt.transactionHash
}
return writeContract(client, {
account: client.account!,
account: resolved,
chain: client.chain,
address: escrowContract,
abi: escrowAbi,
Expand Down