@mimicprotocol/lib-ts 0.0.1 → 0.1.0

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.
@@ -1,14 +1,15 @@
1
1
  import { environment } from '../../environment'
2
2
  import { TokenAmount } from '../../tokens'
3
- import { Address, BigInt, Bytes, ChainId } from '../../types'
3
+ import { Address, Bytes, ChainId } from '../../types'
4
4
  import { SvmAccountMeta } from '../../types/svm/SvmAccountMeta'
5
- import { Intent, IntentBuilder, IntentEvent, MaxFee, OperationType } from '../Intent'
5
+ import { IntentBuilder } from '../Intent'
6
+ import { Operation, OperationBuilder, OperationEvent, OperationType } from '../Operation'
6
7
 
7
8
  /**
8
9
  * Builder for creating SVM Call intents with program call operations.
9
10
  * Allows chaining multiple calls and configuring fees and settlement parameters.
10
11
  */
11
- export class SvmCallBuilder extends IntentBuilder {
12
+ export class SvmCallBuilder extends OperationBuilder {
12
13
  protected chainId: ChainId
13
14
  protected instructions: SvmInstruction[] = []
14
15
 
@@ -75,33 +76,6 @@ export class SvmCallBuilder extends IntentBuilder {
75
76
  return this.instructions.slice(0)
76
77
  }
77
78
 
78
- /**
79
- * Sets the settler address for this intent.
80
- * @param settler - The settler address as an Address instance
81
- * @returns This SvmCallBuilder instance for method chaining
82
- */
83
- addSettler(settler: Address): SvmCallBuilder {
84
- return changetype<SvmCallBuilder>(super.addSettler(settler))
85
- }
86
-
87
- /**
88
- * Sets the settler address from a string.
89
- * @param settler - The settler address as a hex string
90
- * @returns This SvmCallBuilder instance for method chaining
91
- */
92
- addSettlerAsString(settler: string): SvmCallBuilder {
93
- return changetype<SvmCallBuilder>(super.addSettlerAsString(settler))
94
- }
95
-
96
- /**
97
- * Sets the deadline for this intent.
98
- * @param deadline - The deadline as a timestamp
99
- * @returns This SvmCallBuilder instance for method chaining
100
- */
101
- addDeadline(deadline: BigInt): SvmCallBuilder {
102
- return changetype<SvmCallBuilder>(super.addDeadline(deadline))
103
- }
104
-
105
79
  /**
106
80
  * Sets the user address for this intent.
107
81
  * @param user - The user address
@@ -120,26 +94,6 @@ export class SvmCallBuilder extends IntentBuilder {
120
94
  return changetype<SvmCallBuilder>(super.addUserAsString(user))
121
95
  }
122
96
 
123
- /**
124
- * Sets the nonce for this intent.
125
- * @param nonce - A unique identifier to prevent replay attacks
126
- * @returns This SvmCallBuilder instance for method chaining
127
- */
128
- addNonce(nonce: string): SvmCallBuilder {
129
- return changetype<SvmCallBuilder>(super.addNonce(nonce))
130
- }
131
-
132
- /**
133
- * Adds a max fee for this intent.
134
- * @param fee - The max fee token amount (must be on same chain)
135
- * @returns This SvmCallBuilder instance for method chaining
136
- */
137
- addMaxFee(fee: TokenAmount): SvmCallBuilder {
138
- if (!fee.token.hasChain(this.chainId)) throw new Error('Fee token must be on the same chain')
139
- this.maxFees.push(fee)
140
- return this
141
- }
142
-
143
97
  /**
144
98
  * Sets an event for the intent.
145
99
  * @param topic - The topic to be indexed in the event
@@ -155,7 +109,7 @@ export class SvmCallBuilder extends IntentBuilder {
155
109
  * @param events - The list of events to be added
156
110
  * @returns This SvmCallBuilder instance for method chaining
157
111
  */
158
- addEvents(events: IntentEvent[]): SvmCallBuilder {
112
+ addEvents(events: OperationEvent[]): SvmCallBuilder {
159
113
  return changetype<SvmCallBuilder>(super.addEvents(events))
160
114
  }
161
115
 
@@ -164,7 +118,16 @@ export class SvmCallBuilder extends IntentBuilder {
164
118
  * @returns A new SvmCall instance with all configured parameters
165
119
  */
166
120
  build(): SvmCall {
167
- return new SvmCall(this.instructions, this.maxFees, this.settler, this.user, this.deadline, this.nonce, this.events)
121
+ return new SvmCall(this.instructions, this.user, this.events)
122
+ }
123
+
124
+ /**
125
+ * Builds this operation and sends it inside an intent with the provided fee data.
126
+ * @param maxFee - The max fee to pay for the intent
127
+ * @param feePayer - The fee payer for the intent (optional)
128
+ */
129
+ send(maxFee: TokenAmount, feePayer: Address | null = null): void {
130
+ this.build().send(maxFee, feePayer)
168
131
  }
169
132
  }
170
133
 
@@ -193,7 +156,7 @@ export class SvmInstructionBuilder {
193
156
  }
194
157
 
195
158
  instruction(): SvmInstruction {
196
- return SvmInstruction.create(this.programId, this.accountsMeta, this.data)
159
+ return new SvmInstruction(this.programId.toBase58String(), this.accountsMeta, this.data.toHexString())
197
160
  }
198
161
  }
199
162
 
@@ -204,44 +167,15 @@ export class SvmInstruction {
204
167
  public accountsMeta: SvmAccountMeta[],
205
168
  public data: string
206
169
  ) {}
207
-
208
- static create(programId: Address, accountsMeta: SvmAccountMeta[], data: Bytes): SvmInstruction {
209
- return new SvmInstruction(programId.toBase58String(), accountsMeta, data.toHexString())
210
- }
211
170
  }
212
171
 
213
172
  /**
214
173
  * Represents a SVM Call intent containing one or more program calls to be executed.
215
174
  */
216
175
  @json
217
- export class SvmCall extends Intent {
218
- public chainId: ChainId
176
+ export class SvmCall extends Operation {
219
177
  public instructions: SvmInstruction[]
220
178
 
221
- /**
222
- * Creates a SvmCall intent with a single program call.
223
- * @param maxFee - The max fee to pay for the call intent
224
- * @param settler - The settler address (optional)
225
- * @param user - The user address (optional)
226
- * @param deadline - The deadline timestamp (optional)
227
- * @param nonce - The nonce for replay protection (optional)
228
- * @returns A new Call instance
229
- */
230
- static create(
231
- programId: Address,
232
- accountsMeta: SvmAccountMeta[],
233
- data: Bytes,
234
- maxFee: TokenAmount,
235
- settler: Address | null = null,
236
- user: Address | null = null,
237
- deadline: BigInt | null = null,
238
- nonce: string | null = null,
239
- events: IntentEvent[] | null = null
240
- ): SvmCall {
241
- const instruction = SvmInstruction.create(programId, accountsMeta, data)
242
- return new SvmCall([instruction], [maxFee], settler, user, deadline, nonce, events)
243
- }
244
-
245
179
  /**
246
180
  * Creates a new SvmCall intent.
247
181
  * @param instructions - Array of instructions to execute
@@ -251,28 +185,20 @@ export class SvmCall extends Intent {
251
185
  * @param deadline - The deadline timestamp (optional)
252
186
  * @param nonce - The nonce for replay protection (optional)
253
187
  */
254
- constructor(
255
- instructions: SvmInstruction[],
256
- maxFees: TokenAmount[],
257
- settler: Address | null = null,
258
- user: Address | null = null,
259
- deadline: BigInt | null = null,
260
- nonce: string | null = null,
261
- events: IntentEvent[] | null = null
262
- ) {
263
- const fees: MaxFee[] = maxFees.map((fee: TokenAmount) => MaxFee.fromTokenAmount(fee))
264
- super(OperationType.SvmCall, ChainId.SOLANA_MAINNET, fees, settler, user, deadline, nonce, events)
188
+ constructor(instructions: SvmInstruction[], user: Address | null = null, events: OperationEvent[] | null = null) {
189
+ super(OperationType.SvmCall, ChainId.SOLANA_MAINNET, user, events)
265
190
  if (instructions.length === 0) throw new Error('Call list cannot be empty')
266
- if (maxFees.length == 0) throw new Error('At least a max fee must be specified')
267
-
268
191
  this.instructions = instructions
269
- this.chainId = ChainId.SOLANA_MAINNET
270
192
  }
271
193
 
272
194
  /**
273
195
  * Sends this SvmCall intent to the execution environment.
196
+ * @param maxFee - The max fee to pay for the intent
197
+ * @param feePayer - The fee payer for the intent (optional)
274
198
  */
275
- public send(): void {
276
- environment.svmCall(this)
199
+ public send(maxFee: TokenAmount, feePayer: Address | null = null): void {
200
+ const intentBuilder = new IntentBuilder().addMaxFee(maxFee).addOperation(this)
201
+ if (feePayer) intentBuilder.addFeePayer(feePayer)
202
+ environment.sendIntent(intentBuilder.build())
277
203
  }
278
204
  }
@@ -1,2 +1,3 @@
1
1
  export * from './EvmCall'
2
+ export * from './EvmDynamicCall'
2
3
  export * from './SvmCall'
@@ -1,28 +1,185 @@
1
1
  import { environment } from '../environment'
2
2
  import { evm } from '../evm'
3
3
  import { NULL_ADDRESS } from '../helpers'
4
- import { Token, TokenAmount } from '../tokens'
4
+ import { BlockchainToken, Token, TokenAmount } from '../tokens'
5
5
  import { Address, BigInt, Bytes, ChainId } from '../types'
6
+ import { SvmAccountMeta } from '../types/svm/SvmAccountMeta'
6
7
 
7
- export enum OperationType {
8
- Swap,
9
- Transfer,
10
- EvmCall,
11
- SvmCall,
12
- }
8
+ import { EvmCall, EvmCallData } from './Call/EvmCall'
9
+ import { EvmDynamicArg, EvmDynamicCall, EvmDynamicCallData } from './Call/EvmDynamicCall'
10
+ import { SvmCall, SvmInstruction } from './Call/SvmCall'
11
+ import { Operation, OperationBuilder, OperationEvent, OperationType } from './Operation'
12
+ import { Swap, SwapTokenIn, SwapTokenOut } from './Swap'
13
+ import { Transfer, TransferData } from './Transfer'
13
14
 
14
15
  const DEFAULT_DEADLINE = 5 * 60 // 5 minutes in seconds
15
16
 
16
17
  /**
17
- * Base builder for creating intents.
18
+ * Builder for creating intents with one or more operations.
18
19
  */
19
- export abstract class IntentBuilder {
20
- protected user: Address | null = null
20
+ export class IntentBuilder {
21
21
  protected settler: Address | null = null
22
+ protected feePayer: Address | null = null
22
23
  protected deadline: BigInt | null = null
23
24
  protected nonce: string | null = null
24
25
  protected maxFees: TokenAmount[] = []
25
- protected events: IntentEvent[] = []
26
+ protected operations: Operation[] = []
27
+
28
+ /**
29
+ * Adds an operation to this intent.
30
+ * @param operation - The operation to add
31
+ * @returns This IntentBuilder instance for method chaining
32
+ */
33
+ addOperation(operation: Operation): IntentBuilder {
34
+ this.operations.push(operation)
35
+ return this
36
+ }
37
+
38
+ /**
39
+ * Adds multiple operations to this intent.
40
+ * @param operations - The operations to add
41
+ * @returns This IntentBuilder instance for method chaining
42
+ */
43
+ addOperations(operations: Operation[]): IntentBuilder {
44
+ for (let i = 0; i < operations.length; i++) this.addOperation(operations[i])
45
+ return this
46
+ }
47
+
48
+ /**
49
+ * Adds a built operation builder to this intent.
50
+ * @param operationBuilder - The operation builder to build and add
51
+ * @returns This IntentBuilder instance for method chaining
52
+ */
53
+ addOperationBuilder(operationBuilder: OperationBuilder): IntentBuilder {
54
+ return this.addOperation(operationBuilder.build())
55
+ }
56
+
57
+ /**
58
+ * Adds multiple built operation builders to this intent.
59
+ * @param operationBuilders - The operation builders to build and add
60
+ * @returns This IntentBuilder instance for method chaining
61
+ */
62
+ addOperationsBuilders(operationBuilders: OperationBuilder[]): IntentBuilder {
63
+ for (let i = 0; i < operationBuilders.length; i++) this.addOperationBuilder(operationBuilders[i])
64
+ return this
65
+ }
66
+
67
+ /**
68
+ * Adds a single EVM call operation to this intent from raw parameters.
69
+ * @param chainId - The blockchain network identifier
70
+ * @param target - The contract address to call
71
+ * @param data - The encoded call data
72
+ * @param value - The native token value to send
73
+ * @param user - The user that should execute the operation
74
+ * @param events - The operation events to emit
75
+ * @returns This IntentBuilder instance for method chaining
76
+ */
77
+ addEvmCallOperation(
78
+ chainId: ChainId,
79
+ target: Address,
80
+ data: Bytes = Bytes.empty(),
81
+ value: BigInt = BigInt.zero(),
82
+ user: Address | null = null,
83
+ events: OperationEvent[] | null = null
84
+ ): IntentBuilder {
85
+ return this.addOperation(new EvmCall(chainId, [new EvmCallData(target, data, value)], user, events))
86
+ }
87
+
88
+ /**
89
+ * Adds a single EVM dynamic call operation to this intent from raw parameters.
90
+ * @param chainId - The blockchain network identifier
91
+ * @param target - The contract address to call
92
+ * @param selector - The function selector to call
93
+ * @param args - The dynamic arguments to resolve at execution time
94
+ * @param value - The native token value to send
95
+ * @param user - The user that should execute the operation
96
+ * @param events - The operation events to emit
97
+ * @returns This IntentBuilder instance for method chaining
98
+ */
99
+ addEvmDynamicCallOperation(
100
+ chainId: ChainId,
101
+ target: Address,
102
+ selector: Bytes,
103
+ args: EvmDynamicArg[] = [],
104
+ value: BigInt = BigInt.zero(),
105
+ user: Address | null = null,
106
+ events: OperationEvent[] | null = null
107
+ ): IntentBuilder {
108
+ return this.addOperation(
109
+ new EvmDynamicCall(chainId, [new EvmDynamicCallData(target, selector, args, value)], user, events)
110
+ )
111
+ }
112
+
113
+ /**
114
+ * Adds a single swap operation to this intent from raw parameters.
115
+ * @param sourceChain - The source blockchain network identifier
116
+ * @param tokenIn - The token to swap from
117
+ * @param amountIn - The amount to swap from
118
+ * @param tokenOut - The token to receive
119
+ * @param minAmountOut - The minimum amount to receive
120
+ * @param recipient - The recipient of the output token
121
+ * @param destinationChain - The destination blockchain network identifier
122
+ * @param user - The user that should execute the operation
123
+ * @param events - The operation events to emit
124
+ * @returns This IntentBuilder instance for method chaining
125
+ */
126
+ addSwapOperation(
127
+ sourceChain: ChainId,
128
+ tokenIn: Token,
129
+ amountIn: BigInt,
130
+ tokenOut: Token,
131
+ minAmountOut: BigInt,
132
+ recipient: Address,
133
+ destinationChain: ChainId = sourceChain,
134
+ user: Address | null = null,
135
+ events: OperationEvent[] | null = null
136
+ ): IntentBuilder {
137
+ const swapIn = SwapTokenIn.fromBigInt(tokenIn, amountIn)
138
+ const swapOut = SwapTokenOut.fromBigInt(tokenOut, minAmountOut, recipient)
139
+ return this.addOperation(new Swap(sourceChain, [swapIn], [swapOut], destinationChain, user, events))
140
+ }
141
+
142
+ /**
143
+ * Adds a single transfer operation to this intent from raw parameters.
144
+ * @param token - The token to transfer
145
+ * @param amount - The amount to transfer
146
+ * @param recipient - The recipient of the transfer
147
+ * @param user - The user that should execute the operation
148
+ * @param events - The operation events to emit
149
+ * @returns This IntentBuilder instance for method chaining
150
+ */
151
+ addTransferOperation(
152
+ token: Token,
153
+ amount: BigInt,
154
+ recipient: Address,
155
+ user: Address | null = null,
156
+ events: OperationEvent[] | null = null
157
+ ): IntentBuilder {
158
+ if (!(token instanceof BlockchainToken)) throw new Error('Transfer token must be a blockchain token')
159
+ const transferAmount = TokenAmount.fromBigInt(token, amount)
160
+ const transferData = TransferData.fromTokenAmount(transferAmount, recipient)
161
+ const chainId = changetype<BlockchainToken>(token).chainId
162
+ return this.addOperation(new Transfer(chainId, [transferData], user, events))
163
+ }
164
+
165
+ /**
166
+ * Adds a single SVM call operation to this intent from raw parameters.
167
+ * @param programId - The program address to call
168
+ * @param accountsMeta - The accounts metadata for the instruction
169
+ * @param data - The encoded instruction data
170
+ * @param user - The user that should execute the operation
171
+ * @param events - The operation events to emit
172
+ * @returns This IntentBuilder instance for method chaining
173
+ */
174
+ addSvmCallOperation(
175
+ programId: Address,
176
+ accountsMeta: SvmAccountMeta[],
177
+ data: Bytes,
178
+ user: Address | null = null,
179
+ events: OperationEvent[] | null = null
180
+ ): IntentBuilder {
181
+ return this.addOperation(new SvmCall([SvmInstruction.create(programId, accountsMeta, data)], user, events))
182
+ }
26
183
 
27
184
  /**
28
185
  * Sets the settler address for this intent.
@@ -44,32 +201,32 @@ export abstract class IntentBuilder {
44
201
  }
45
202
 
46
203
  /**
47
- * Sets the deadline for this intent.
48
- * @param deadline - The deadline as a timestamp
204
+ * Sets the fee payer address for this intent.
205
+ * @param feePayer - The fee payer address as an Address instance
49
206
  * @returns This IntentBuilder instance for method chaining
50
207
  */
51
- addDeadline(deadline: BigInt): IntentBuilder {
52
- this.deadline = deadline
208
+ addFeePayer(feePayer: Address): IntentBuilder {
209
+ this.feePayer = feePayer
53
210
  return this
54
211
  }
55
212
 
56
213
  /**
57
- * Sets the user address for this intent.
58
- * @param user - The user address
214
+ * Sets the fee payer address from a string.
215
+ * @param feePayer - The fee payer address as a hex string
59
216
  * @returns This IntentBuilder instance for method chaining
60
217
  */
61
- addUser(user: Address): IntentBuilder {
62
- this.user = user
63
- return this
218
+ addFeePayerAsString(feePayer: string): IntentBuilder {
219
+ return this.addFeePayer(Address.fromString(feePayer))
64
220
  }
65
221
 
66
222
  /**
67
- * Sets the user address from a string.
68
- * @param user - The user address as a hex string
223
+ * Sets the deadline for this intent.
224
+ * @param deadline - The deadline as a timestamp
69
225
  * @returns This IntentBuilder instance for method chaining
70
226
  */
71
- addUserAsString(user: string): IntentBuilder {
72
- return this.addUser(Address.fromString(user))
227
+ addDeadline(deadline: BigInt): IntentBuilder {
228
+ this.deadline = deadline
229
+ return this
73
230
  }
74
231
 
75
232
  /**
@@ -83,41 +240,29 @@ export abstract class IntentBuilder {
83
240
  }
84
241
 
85
242
  /**
86
- * Sets an event for the intent.
87
- * @param topic - The topic to be indexed in the event
88
- * @param data - The event data
243
+ * Adds a max fee for this intent.
244
+ * @param fee - The max fee token amount
89
245
  * @returns This IntentBuilder instance for method chaining
90
246
  */
91
- addEvent(topic: Bytes, data: Bytes): IntentBuilder {
92
- const event = new IntentEvent(topic, data)
93
- this.events.push(event)
247
+ addMaxFee(fee: TokenAmount): IntentBuilder {
248
+ this.maxFees.push(fee)
94
249
  return this
95
250
  }
96
251
 
97
252
  /**
98
- * Sets multiple events for the intent.
99
- * @param events - The list of events to be added
100
- * @returns This IntentBuilder instance for method chaining
253
+ * Builds and returns the final intent.
254
+ * @returns A new intent
101
255
  */
102
- addEvents(events: IntentEvent[]): IntentBuilder {
103
- for (let i = 0; i < events.length; i++) {
104
- this.events.push(events[i])
105
- }
106
- return this
256
+ build(): Intent {
257
+ return new Intent(this.maxFees, this.settler, this.feePayer, this.deadline, this.nonce, this.operations)
107
258
  }
108
259
 
109
260
  /**
110
- * Adds a max fee for this intent.
111
- * @param fee - The max fee token amount (must be on same chain)
112
- * @returns This IntentBuilder instance for method chaining
113
- */
114
- abstract addMaxFee(fee: TokenAmount): IntentBuilder
115
-
116
- /**
117
- * Builds and returns the final intent.
118
- * @returns A new intent
261
+ * Builds and sends the final intent.
119
262
  */
120
- abstract build(): Intent
263
+ send(): void {
264
+ this.build().send()
265
+ }
121
266
  }
122
267
 
123
268
  /**
@@ -179,74 +324,68 @@ export class MaxFee {
179
324
  }
180
325
  }
181
326
 
327
+ let INTENT_INDEX: u32 = 0
328
+
182
329
  /**
183
- * Represents an intent event.
184
- * Specifies the topic and data for the event. The topic is an indexed parameter for the EVM events.
330
+ * Represents a sendable intent containing one or more operations plus intent-level metadata.
185
331
  */
186
332
  @json
187
- export class IntentEvent {
188
- topic: string
189
- data: string
190
-
191
- /**
192
- * Creates a new Intent Event instance.
193
- * @param topic - the topic that is going to be index in the event
194
- * @param data - The event data
195
- */
196
- constructor(topic: Bytes, data: Bytes) {
197
- this.topic = topic.toHexString()
198
- this.data = data.toHexString()
199
- }
200
- }
201
-
202
- let INTENT_INDEX: u32 = 0
203
- @json
204
- export abstract class Intent {
205
- public op: OperationType
206
- public settler: string
207
- public user: string
208
- public deadline: string
209
- public nonce: string
210
- public maxFees: MaxFee[]
211
- public events: IntentEvent[]
333
+ export class Intent {
334
+ public settler: string = ''
335
+ public feePayer: string = ''
336
+ public deadline: string = ''
337
+ public nonce: string = ''
338
+ public maxFees: MaxFee[] = []
339
+ public operations: Operation[]
212
340
 
213
341
  /**
214
342
  * Creates a new intent.
215
- * @param op - The type of intent to be created
216
- * @param chainId - The chain ID for fetch the settler
217
- * @param maxFees - The list of max fees to pay for the intent (optional)
218
- * @param settler - The settler address (optional)
219
- * @param user - The user address (optional)
220
- * @param deadline - The deadline timestamp (optional)
221
- * @param nonce - The nonce for replay protection (optional)
222
- */
223
- protected constructor(
224
- op: OperationType,
225
- chainId: ChainId,
226
- maxFees: MaxFee[] | null,
227
- settler: Address | null,
228
- user: Address | null,
229
- deadline: BigInt | null,
230
- nonce: string | null,
231
- events: IntentEvent[] | null
343
+ * @param maxFees - The list of max fees to pay for the intent
344
+ * @param settler - The settler address
345
+ * @param feePayer - The fee payer address
346
+ * @param deadline - The deadline timestamp
347
+ * @param nonce - The nonce for replay protection
348
+ * @param operations - The operations to execute
349
+ */
350
+ constructor(
351
+ maxFees: TokenAmount[] | null = null,
352
+ settler: Address | null = null,
353
+ feePayer: Address | null = null,
354
+ deadline: BigInt | null = null,
355
+ nonce: string | null = null,
356
+ operations: Operation[] | null = null
232
357
  ) {
233
358
  const context = environment.getContext()
234
- this.op = op
235
- this.maxFees = maxFees || []
236
- this.settler = settler ? settler.toString() : context.findSettler(chainId).toString()
359
+ this.operations = operations || []
360
+ if (this.operations.length === 0) throw new Error('Operation list cannot be empty')
361
+
362
+ const defaultChainId = this.operations[0].chainId
363
+ for (let i = 0; i < this.operations.length; i++) {
364
+ const operation = this.operations[i]
365
+
366
+ if (operation.chainId !== defaultChainId) throw new Error('All operations must have the same chainId')
367
+
368
+ if (operation.opType === OperationType.CrossChainSwap) {
369
+ if (this.operations.length > 1) throw new Error('Cross-chain swap must be the only operation in an intent')
370
+ }
371
+ }
372
+
373
+ this.maxFees = maxFees ? maxFees.map((fee: TokenAmount) => MaxFee.fromTokenAmount(fee)) : []
374
+ this.settler = settler ? settler.toString() : context.findSettler(defaultChainId).toString()
375
+ this.feePayer = feePayer ? feePayer.toString() : context.user.toString()
237
376
  this.deadline = deadline ? deadline.toString() : (context.timestamp / 1000 + DEFAULT_DEADLINE).toString()
238
- this.user = user ? user.toString() : context.user.toString()
239
- this.events = events || []
240
377
  this.nonce = nonce
241
378
  ? nonce
242
379
  : evm.keccak(`${context.triggerSig}${context.timestamp}${context.triggerPayload.data}${++INTENT_INDEX}`)
243
380
 
244
- if (!this.user || this.user == NULL_ADDRESS) throw new Error('A user must be specified')
245
381
  if (!this.settler || this.settler == NULL_ADDRESS) throw new Error('A settler contract must be specified')
382
+ if (!this.feePayer || this.feePayer == NULL_ADDRESS) throw new Error('A fee payer must be specified')
246
383
  }
247
384
 
248
385
  /**
249
386
  * Sends this intent to the execution environment.
250
387
  */
251
- abstract send(): void
388
+ send(): void {
389
+ environment.sendIntent(this)
390
+ }
252
391
  }