-
Notifications
You must be signed in to change notification settings - Fork 302
Expand file tree
/
Copy pathtransaction.ts
More file actions
115 lines (97 loc) · 3.25 KB
/
transaction.ts
File metadata and controls
115 lines (97 loc) · 3.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/**
* TIP-20 Transaction
*
* Represents a Tempo Account Abstraction (AA) transaction (type 0x76)
* Supports single or batch TIP-20 token transfers with memos
*/
import { BaseTransaction, ParseTransactionError, TransactionType } from '@bitgo/sdk-core';
import { BaseCoin as CoinConfig } from '@bitgo/statics';
import { Address, Hex, Tip20Operation } from './types';
/**
* TIP-20 Transaction Request Structure
* Represents the raw transaction data for Tempo Account Abstraction (EIP-7702)
*/
export interface Tip20TransactionRequest {
/** Transaction type (0x76 for Tempo AA) */
type: number | string;
/** Chain ID for the Tempo network */
chainId: number;
/** Transaction nonce */
nonce: number;
/** Maximum fee per gas (EIP-1559) */
maxFeePerGas: bigint;
/** Maximum priority fee per gas (EIP-1559) */
maxPriorityFeePerGas: bigint;
/** Gas limit for the transaction */
gas: bigint;
/** Array of calls to execute in this transaction */
calls: { to: Address; data: Hex; value: bigint }[];
/** Access list (optional, typically empty for TIP-20) */
accessList?: unknown[];
/** Optional TIP-20 token to use for paying fees */
feeToken?: Address;
}
export class Tip20Transaction extends BaseTransaction {
private txRequest: Tip20TransactionRequest;
private _operations: Tip20Operation[];
private _signature?: { r: Hex; s: Hex; yParity: number };
constructor(_coinConfig: Readonly<CoinConfig>, request: Tip20TransactionRequest, operations: Tip20Operation[] = []) {
super(_coinConfig);
this.txRequest = request;
this._operations = operations;
}
get type(): TransactionType {
return TransactionType.Send;
}
canSign(): boolean {
return true;
}
async serialize(signature?: { r: Hex; s: Hex; yParity: number }): Promise<Hex> {
// TODO: Implement EIP-7702 transaction serialization with ethers.js
throw new ParseTransactionError('Transaction serialization not yet implemented');
}
getOperations(): Tip20Operation[] {
return [...this._operations];
}
getFeeToken(): Address | undefined {
return this.txRequest.feeToken;
}
getOperationCount(): number {
return this.txRequest.calls.length;
}
isBatch(): boolean {
return this.txRequest.calls.length > 1;
}
setSignature(signature: { r: Hex; s: Hex; yParity: number }): void {
this._signature = signature;
}
getSignature(): { r: Hex; s: Hex; yParity: number } | undefined {
return this._signature;
}
toJson(): Record<string, unknown> {
return {
type: this.txRequest.type,
chainId: this.txRequest.chainId,
nonce: this.txRequest.nonce,
maxFeePerGas: this.txRequest.maxFeePerGas.toString(),
maxPriorityFeePerGas: this.txRequest.maxPriorityFeePerGas.toString(),
gas: this.txRequest.gas.toString(),
callCount: this.txRequest.calls.length,
feeToken: this.txRequest.feeToken,
operations: this._operations,
signature: this._signature,
};
}
async toBroadcastFormat(): Promise<string> {
return await this.serialize(this._signature);
}
get id(): string {
return 'pending';
}
toString(): string {
return JSON.stringify(this.toJson(), null, 2);
}
canBroadcast(): boolean {
return this.txRequest.calls.length > 0 && this.txRequest.chainId > 0;
}
}