@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.
- package/CHANGELOG.md +10 -0
- package/constants.js +1 -1
- package/package.json +1 -1
- package/src/environment.ts +7 -40
- package/src/intents/Call/EvmCall.ts +41 -125
- package/src/intents/Call/EvmDynamicCall.ts +272 -0
- package/src/intents/Call/SvmCall.ts +25 -99
- package/src/intents/Call/index.ts +1 -0
- package/src/intents/Intent.ts +238 -99
- package/src/intents/Operation.ts +114 -0
- package/src/intents/Swap.ts +26 -105
- package/src/intents/Transfer.ts +24 -120
- package/src/intents/index.ts +1 -0
- package/src/storage/storage.ts +1 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @mimicprotocol/lib-ts
|
|
2
2
|
|
|
3
|
+
## 0.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 45a5f9f: Add operations and dynamic call operation
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- 45a5f9f: Refactor intents to have operations and bump to runner version v0.1.0
|
|
12
|
+
|
|
3
13
|
## 0.0.1
|
|
4
14
|
|
|
5
15
|
### Patch Changes
|
package/constants.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const RUNNER_TARGET_VERSION = '0.0
|
|
1
|
+
export const RUNNER_TARGET_VERSION = '0.1.0'
|
package/package.json
CHANGED
package/src/environment.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { JSON } from 'json-as/assembly'
|
|
|
3
3
|
import { Context, SerializableContext } from './context'
|
|
4
4
|
import { evm } from './evm'
|
|
5
5
|
import { Consensus, ListType, MIMIC_HELPER_ADDRESS } from './helpers'
|
|
6
|
-
import {
|
|
6
|
+
import { Intent } from './intents'
|
|
7
7
|
import {
|
|
8
8
|
EvmCallQuery,
|
|
9
9
|
EvmCallQueryResponse,
|
|
@@ -23,17 +23,8 @@ import { BlockchainToken, Token, TokenAmount, USD } from './tokens'
|
|
|
23
23
|
import { Address, BigInt, Bytes, ChainId, EvmDecodeParam, EvmEncodeParam, Result } from './types'
|
|
24
24
|
|
|
25
25
|
export namespace environment {
|
|
26
|
-
@external('environment', '
|
|
27
|
-
declare function
|
|
28
|
-
|
|
29
|
-
@external('environment', '_svmCall')
|
|
30
|
-
declare function _svmCall(params: string): void
|
|
31
|
-
|
|
32
|
-
@external('environment', '_swap')
|
|
33
|
-
declare function _swap(params: string): void
|
|
34
|
-
|
|
35
|
-
@external('environment', '_transfer')
|
|
36
|
-
declare function _transfer(params: string): void
|
|
26
|
+
@external('environment', '_sendIntent')
|
|
27
|
+
declare function _sendIntent(params: string): void
|
|
37
28
|
|
|
38
29
|
@external('environment', '_tokenPriceQuery')
|
|
39
30
|
declare function _tokenPriceQuery(params: string): string
|
|
@@ -54,35 +45,11 @@ export namespace environment {
|
|
|
54
45
|
declare function _getContext(): string
|
|
55
46
|
|
|
56
47
|
/**
|
|
57
|
-
*
|
|
58
|
-
* @param
|
|
59
|
-
*/
|
|
60
|
-
export function evmCall(call: EvmCall): void {
|
|
61
|
-
_evmCall(JSON.stringify(call))
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Generates a SVM Call intent containing contract calls on the blockchain.
|
|
66
|
-
* @param call - The SvmCall intent to generate
|
|
67
|
-
*/
|
|
68
|
-
export function svmCall(call: SvmCall): void {
|
|
69
|
-
_svmCall(JSON.stringify(call))
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Generates a Swap intent for token exchange operations.
|
|
74
|
-
* @param swap - The Swap intent to generate
|
|
75
|
-
*/
|
|
76
|
-
export function swap(swap: Swap): void {
|
|
77
|
-
_swap(JSON.stringify(swap))
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Generates a Transfer intent for sending tokens to recipients.
|
|
82
|
-
* @param transfer - The Transfer intent to generate
|
|
48
|
+
* Sends an intent containing one or more operations to the execution environment.
|
|
49
|
+
* @param intent - The intent to send
|
|
83
50
|
*/
|
|
84
|
-
export function
|
|
85
|
-
|
|
51
|
+
export function sendIntent(intent: Intent): void {
|
|
52
|
+
_sendIntent(JSON.stringify(intent))
|
|
86
53
|
}
|
|
87
54
|
|
|
88
55
|
/**
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { environment } from '../../environment'
|
|
2
2
|
import { TokenAmount } from '../../tokens'
|
|
3
3
|
import { Address, BigInt, Bytes, ChainId } from '../../types'
|
|
4
|
-
import {
|
|
4
|
+
import { IntentBuilder } from '../Intent'
|
|
5
|
+
import { Operation, OperationBuilder, OperationEvent, OperationType } from '../Operation'
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
|
-
* Builder for creating EVM
|
|
8
|
-
* Allows chaining multiple contract calls and configuring fees and settlement parameters.
|
|
8
|
+
* Builder for creating EVM call operations.
|
|
9
9
|
*/
|
|
10
|
-
export class EvmCallBuilder extends
|
|
10
|
+
export class EvmCallBuilder extends OperationBuilder {
|
|
11
11
|
protected chainId: ChainId
|
|
12
12
|
protected calls: EvmCallData[] = []
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
|
-
* Creates
|
|
15
|
+
* Creates an EvmCallBuilder for the specified EVM blockchain network.
|
|
16
16
|
* @param chainId - The blockchain network identifier
|
|
17
17
|
* @returns A new EvmCallBuilder instance
|
|
18
18
|
*/
|
|
@@ -30,10 +30,10 @@ export class EvmCallBuilder extends IntentBuilder {
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
|
-
* Adds a contract call to the
|
|
33
|
+
* Adds a contract call to the operation.
|
|
34
34
|
* @param target - The contract address to call
|
|
35
|
-
* @param data - The call data
|
|
36
|
-
* @param value - The native token value to send
|
|
35
|
+
* @param data - The call data
|
|
36
|
+
* @param value - The native token value to send
|
|
37
37
|
* @returns This EvmCallBuilder instance for method chaining
|
|
38
38
|
*/
|
|
39
39
|
addCall(target: Address, data: Bytes = Bytes.empty(), value: BigInt = BigInt.zero()): EvmCallBuilder {
|
|
@@ -42,7 +42,7 @@ export class EvmCallBuilder extends IntentBuilder {
|
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
/**
|
|
45
|
-
* Adds multiple contract calls to the
|
|
45
|
+
* Adds multiple contract calls to the operation.
|
|
46
46
|
* @param calls - The contract calls to add
|
|
47
47
|
* @returns This EvmCallBuilder instance for method chaining
|
|
48
48
|
*/
|
|
@@ -84,34 +84,7 @@ export class EvmCallBuilder extends IntentBuilder {
|
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
/**
|
|
87
|
-
* Sets the
|
|
88
|
-
* @param settler - The settler address as an Address instance
|
|
89
|
-
* @returns This EvmCallBuilder instance for method chaining
|
|
90
|
-
*/
|
|
91
|
-
addSettler(settler: Address): EvmCallBuilder {
|
|
92
|
-
return changetype<EvmCallBuilder>(super.addSettler(settler))
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Sets the settler address from a string.
|
|
97
|
-
* @param settler - The settler address as a hex string
|
|
98
|
-
* @returns This EvmCallBuilder instance for method chaining
|
|
99
|
-
*/
|
|
100
|
-
addSettlerAsString(settler: string): EvmCallBuilder {
|
|
101
|
-
return changetype<EvmCallBuilder>(super.addSettlerAsString(settler))
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Sets the deadline for this intent.
|
|
106
|
-
* @param deadline - The deadline as a timestamp
|
|
107
|
-
* @returns This EvmCallBuilder instance for method chaining
|
|
108
|
-
*/
|
|
109
|
-
addDeadline(deadline: BigInt): EvmCallBuilder {
|
|
110
|
-
return changetype<EvmCallBuilder>(super.addDeadline(deadline))
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Sets the user address for this intent.
|
|
87
|
+
* Sets the user address for this operation.
|
|
115
88
|
* @param user - The user address
|
|
116
89
|
* @returns This EvmCallBuilder instance for method chaining
|
|
117
90
|
*/
|
|
@@ -129,27 +102,7 @@ export class EvmCallBuilder extends IntentBuilder {
|
|
|
129
102
|
}
|
|
130
103
|
|
|
131
104
|
/**
|
|
132
|
-
* Sets
|
|
133
|
-
* @param nonce - A unique identifier to prevent replay attacks
|
|
134
|
-
* @returns This EvmCallBuilder instance for method chaining
|
|
135
|
-
*/
|
|
136
|
-
addNonce(nonce: string): EvmCallBuilder {
|
|
137
|
-
return changetype<EvmCallBuilder>(super.addNonce(nonce))
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* Adds a max fee for this intent.
|
|
142
|
-
* @param fee - The max fee token amount (must be on same chain)
|
|
143
|
-
* @returns This EvmCallBuilder instance for method chaining
|
|
144
|
-
*/
|
|
145
|
-
addMaxFee(fee: TokenAmount): EvmCallBuilder {
|
|
146
|
-
if (!fee.token.hasChain(this.chainId)) throw new Error('Fee token must be on the same chain')
|
|
147
|
-
this.maxFees.push(fee)
|
|
148
|
-
return this
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* Sets an event for the intent.
|
|
105
|
+
* Sets an event for the operation.
|
|
153
106
|
* @param topic - The topic to be indexed in the event
|
|
154
107
|
* @param data - The event data
|
|
155
108
|
* @returns This EvmCallBuilder instance for method chaining
|
|
@@ -159,34 +112,34 @@ export class EvmCallBuilder extends IntentBuilder {
|
|
|
159
112
|
}
|
|
160
113
|
|
|
161
114
|
/**
|
|
162
|
-
* Sets multiple events for the
|
|
115
|
+
* Sets multiple events for the operation.
|
|
163
116
|
* @param events - The list of events to be added
|
|
164
117
|
* @returns This EvmCallBuilder instance for method chaining
|
|
165
118
|
*/
|
|
166
|
-
addEvents(events:
|
|
119
|
+
addEvents(events: OperationEvent[]): EvmCallBuilder {
|
|
167
120
|
return changetype<EvmCallBuilder>(super.addEvents(events))
|
|
168
121
|
}
|
|
169
122
|
|
|
170
123
|
/**
|
|
171
|
-
* Builds and returns the final EvmCall
|
|
124
|
+
* Builds and returns the final EvmCall operation.
|
|
172
125
|
* @returns A new EvmCall instance with all configured parameters
|
|
173
126
|
*/
|
|
174
127
|
build(): EvmCall {
|
|
175
|
-
return new EvmCall(
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
)
|
|
128
|
+
return new EvmCall(this.chainId, this.calls, this.user, this.events)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Builds this operation and sends it inside an intent with the provided fee data.
|
|
133
|
+
* @param maxFee - The max fee to pay for the intent
|
|
134
|
+
* @param feePayer - The fee payer for the intent (optional)
|
|
135
|
+
*/
|
|
136
|
+
send(maxFee: TokenAmount, feePayer: Address | null = null): void {
|
|
137
|
+
this.build().send(maxFee, feePayer)
|
|
185
138
|
}
|
|
186
139
|
}
|
|
187
140
|
|
|
188
141
|
/**
|
|
189
|
-
* Represents data for a single contract call within
|
|
142
|
+
* Represents data for a single contract call within an EVM call operation.
|
|
190
143
|
* Contains the target address, call data, and value to send.
|
|
191
144
|
*/
|
|
192
145
|
@json
|
|
@@ -198,8 +151,8 @@ export class EvmCallData {
|
|
|
198
151
|
/**
|
|
199
152
|
* Creates a new EvmCallData instance.
|
|
200
153
|
* @param target - The contract address to call
|
|
201
|
-
* @param data - The call data
|
|
202
|
-
* @param value - The native token value to send
|
|
154
|
+
* @param data - The call data
|
|
155
|
+
* @param value - The native token value to send
|
|
203
156
|
*/
|
|
204
157
|
constructor(target: Address, data: Bytes = Bytes.empty(), value: BigInt = BigInt.zero()) {
|
|
205
158
|
this.target = target.toString()
|
|
@@ -209,75 +162,38 @@ export class EvmCallData {
|
|
|
209
162
|
}
|
|
210
163
|
|
|
211
164
|
/**
|
|
212
|
-
* Represents
|
|
165
|
+
* Represents an EVM call operation containing one or more contract calls to be executed.
|
|
213
166
|
*/
|
|
214
167
|
@json
|
|
215
|
-
export class EvmCall extends
|
|
216
|
-
public chainId: ChainId
|
|
168
|
+
export class EvmCall extends Operation {
|
|
217
169
|
public calls: EvmCallData[]
|
|
218
170
|
|
|
219
171
|
/**
|
|
220
|
-
* Creates a EvmCall
|
|
221
|
-
* @param chainId - The blockchain network identifier
|
|
222
|
-
* @param target - The contract address to call
|
|
223
|
-
* @param data - The call data
|
|
224
|
-
* @param maxFee - The max fee to pay for the call intent
|
|
225
|
-
* @param value - The native token value to send (optional, defaults to zero)
|
|
226
|
-
* @param settler - The settler address (optional)
|
|
227
|
-
* @param user - The user address (optional)
|
|
228
|
-
* @param deadline - The deadline timestamp (optional)
|
|
229
|
-
* @param nonce - The nonce for replay protection (optional)
|
|
230
|
-
* @returns A new Call instance
|
|
231
|
-
*/
|
|
232
|
-
static create(
|
|
233
|
-
chainId: ChainId,
|
|
234
|
-
target: Address,
|
|
235
|
-
data: Bytes,
|
|
236
|
-
maxFee: TokenAmount,
|
|
237
|
-
value: BigInt = BigInt.zero(),
|
|
238
|
-
settler: Address | null = null,
|
|
239
|
-
user: Address | null = null,
|
|
240
|
-
deadline: BigInt | null = null,
|
|
241
|
-
nonce: string | null = null,
|
|
242
|
-
events: IntentEvent[] | null = null
|
|
243
|
-
): EvmCall {
|
|
244
|
-
const callData = new EvmCallData(target, data, value)
|
|
245
|
-
return new EvmCall(chainId, [callData], [maxFee], settler, user, deadline, nonce, events)
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
/**
|
|
249
|
-
* Creates a new EvmCall intent.
|
|
172
|
+
* Creates a new EvmCall operation.
|
|
250
173
|
* @param chainId - The blockchain network identifier
|
|
251
174
|
* @param calls - Array of contract calls to execute
|
|
252
|
-
* @param
|
|
253
|
-
* @param
|
|
254
|
-
* @param user - The user address (optional)
|
|
255
|
-
* @param deadline - The deadline timestamp (optional)
|
|
256
|
-
* @param nonce - The nonce for replay protection (optional)
|
|
175
|
+
* @param user - The user address
|
|
176
|
+
* @param events - The operation events to emit
|
|
257
177
|
*/
|
|
258
178
|
constructor(
|
|
259
179
|
chainId: ChainId,
|
|
260
180
|
calls: EvmCallData[],
|
|
261
|
-
maxFees: TokenAmount[],
|
|
262
|
-
settler: Address | null = null,
|
|
263
181
|
user: Address | null = null,
|
|
264
|
-
|
|
265
|
-
nonce: string | null = null,
|
|
266
|
-
events: IntentEvent[] | null = null
|
|
182
|
+
events: OperationEvent[] | null = null
|
|
267
183
|
) {
|
|
268
|
-
|
|
269
|
-
super(OperationType.EvmCall, chainId, fees, settler, user, deadline, nonce, events)
|
|
184
|
+
super(OperationType.EvmCall, chainId, user, events)
|
|
270
185
|
if (calls.length === 0) throw new Error('Call list cannot be empty')
|
|
271
|
-
if (maxFees.length == 0) throw new Error('At least a max fee must be specified')
|
|
272
|
-
|
|
273
186
|
this.calls = calls
|
|
274
|
-
this.chainId = chainId
|
|
275
187
|
}
|
|
276
188
|
|
|
277
189
|
/**
|
|
278
|
-
* Sends this EvmCall
|
|
190
|
+
* Sends this EvmCall operation wrapped in an intent.
|
|
191
|
+
* @param maxFee - The max fee to pay for the intent
|
|
192
|
+
* @param feePayer - The fee payer for the intent (optional)
|
|
279
193
|
*/
|
|
280
|
-
public send(): void {
|
|
281
|
-
|
|
194
|
+
public send(maxFee: TokenAmount, feePayer: Address | null = null): void {
|
|
195
|
+
const intentBuilder = new IntentBuilder().addMaxFee(maxFee).addOperation(this)
|
|
196
|
+
if (feePayer) intentBuilder.addFeePayer(feePayer)
|
|
197
|
+
environment.sendIntent(intentBuilder.build())
|
|
282
198
|
}
|
|
283
199
|
}
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
import { environment } from '../../environment'
|
|
2
|
+
import { evm } from '../../evm'
|
|
3
|
+
import { TokenAmount } from '../../tokens'
|
|
4
|
+
import { Address, BigInt, Bytes, ChainId, EvmEncodeParam } from '../../types'
|
|
5
|
+
import { IntentBuilder } from '../Intent'
|
|
6
|
+
import { Operation, OperationBuilder, OperationEvent, OperationType } from '../Operation'
|
|
7
|
+
|
|
8
|
+
export enum EvmDynamicArgKind {
|
|
9
|
+
Literal = 0,
|
|
10
|
+
Variable = 1,
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Builder for creating EVM dynamic call operations.
|
|
15
|
+
*/
|
|
16
|
+
export class EvmDynamicCallBuilder extends OperationBuilder {
|
|
17
|
+
protected chainId: ChainId
|
|
18
|
+
protected calls: EvmDynamicCallData[] = []
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Creates an EvmDynamicCallBuilder for the specified EVM blockchain network.
|
|
22
|
+
* @param chainId - The blockchain network identifier
|
|
23
|
+
* @returns A new EvmDynamicCallBuilder instance
|
|
24
|
+
*/
|
|
25
|
+
static forChain(chainId: ChainId): EvmDynamicCallBuilder {
|
|
26
|
+
return new EvmDynamicCallBuilder(chainId)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Creates a new EvmDynamicCallBuilder instance.
|
|
31
|
+
* @param chainId - The EVM blockchain network identifier
|
|
32
|
+
*/
|
|
33
|
+
private constructor(chainId: ChainId) {
|
|
34
|
+
super()
|
|
35
|
+
this.chainId = chainId
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Adds a dynamic contract call to the operation.
|
|
40
|
+
* @param target - The contract address to call
|
|
41
|
+
* @param selector - The function selector to call
|
|
42
|
+
* @param args - The dynamic call arguments
|
|
43
|
+
* @param value - The native token value to send
|
|
44
|
+
* @returns This EvmDynamicCallBuilder instance for method chaining
|
|
45
|
+
*/
|
|
46
|
+
addCall(
|
|
47
|
+
target: Address,
|
|
48
|
+
selector: Bytes,
|
|
49
|
+
args: EvmDynamicArg[] = [],
|
|
50
|
+
value: BigInt = BigInt.zero()
|
|
51
|
+
): EvmDynamicCallBuilder {
|
|
52
|
+
this.calls.push(new EvmDynamicCallData(target, selector, args, value))
|
|
53
|
+
return this
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Adds multiple dynamic contract calls to the operation.
|
|
58
|
+
* @param calls - The contract calls to add
|
|
59
|
+
* @returns This EvmDynamicCallBuilder instance for method chaining
|
|
60
|
+
*/
|
|
61
|
+
addCalls(calls: EvmDynamicCallData[]): EvmDynamicCallBuilder {
|
|
62
|
+
for (let i = 0; i < calls.length; i++) {
|
|
63
|
+
this.addCall(
|
|
64
|
+
Address.fromString(calls[i].target),
|
|
65
|
+
Bytes.fromHexString(calls[i].selector),
|
|
66
|
+
calls[i].arguments,
|
|
67
|
+
BigInt.fromString(calls[i].value)
|
|
68
|
+
)
|
|
69
|
+
}
|
|
70
|
+
return this
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Adds the calls from another EvmDynamicCallBuilder to this EvmDynamicCallBuilder.
|
|
75
|
+
* @param builder - The EvmDynamicCallBuilder to add the calls from
|
|
76
|
+
* @returns This EvmDynamicCallBuilder instance for method chaining
|
|
77
|
+
*/
|
|
78
|
+
addCallsFromBuilder(builder: EvmDynamicCallBuilder): EvmDynamicCallBuilder {
|
|
79
|
+
return this.addCalls(builder.getCalls())
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Adds the calls from multiple EvmDynamicCallBuilders to this EvmDynamicCallBuilder.
|
|
84
|
+
* @param builders - The EvmDynamicCallBuilders to add the calls from
|
|
85
|
+
* @returns This EvmDynamicCallBuilder instance for method chaining
|
|
86
|
+
*/
|
|
87
|
+
addCallsFromBuilders(builders: EvmDynamicCallBuilder[]): EvmDynamicCallBuilder {
|
|
88
|
+
for (let i = 0; i < builders.length; i++) this.addCallsFromBuilder(builders[i])
|
|
89
|
+
return this
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Returns a copy of the calls array.
|
|
94
|
+
* @returns A copy of the calls array
|
|
95
|
+
*/
|
|
96
|
+
getCalls(): EvmDynamicCallData[] {
|
|
97
|
+
return this.calls.slice(0)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Sets the user address for this operation.
|
|
102
|
+
* @param user - The user address
|
|
103
|
+
* @returns This EvmDynamicCallBuilder instance for method chaining
|
|
104
|
+
*/
|
|
105
|
+
addUser(user: Address): EvmDynamicCallBuilder {
|
|
106
|
+
return changetype<EvmDynamicCallBuilder>(super.addUser(user))
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Sets the user address from a string.
|
|
111
|
+
* @param user - The user address as a hex string
|
|
112
|
+
* @returns This EvmDynamicCallBuilder instance for method chaining
|
|
113
|
+
*/
|
|
114
|
+
addUserAsString(user: string): EvmDynamicCallBuilder {
|
|
115
|
+
return changetype<EvmDynamicCallBuilder>(super.addUserAsString(user))
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Sets an event for the operation.
|
|
120
|
+
* @param topic - The topic to be indexed in the event
|
|
121
|
+
* @param data - The event data
|
|
122
|
+
* @returns This EvmDynamicCallBuilder instance for method chaining
|
|
123
|
+
*/
|
|
124
|
+
addEvent(topic: Bytes, data: Bytes): EvmDynamicCallBuilder {
|
|
125
|
+
return changetype<EvmDynamicCallBuilder>(super.addEvent(topic, data))
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Sets multiple events for the operation.
|
|
130
|
+
* @param events - The list of events to be added
|
|
131
|
+
* @returns This EvmDynamicCallBuilder instance for method chaining
|
|
132
|
+
*/
|
|
133
|
+
addEvents(events: OperationEvent[]): EvmDynamicCallBuilder {
|
|
134
|
+
return changetype<EvmDynamicCallBuilder>(super.addEvents(events))
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Builds and returns the final EvmDynamicCall operation.
|
|
139
|
+
* @returns A new EvmDynamicCall instance with all configured parameters
|
|
140
|
+
*/
|
|
141
|
+
build(): EvmDynamicCall {
|
|
142
|
+
return new EvmDynamicCall(this.chainId, this.calls, this.user, this.events)
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Builds this operation and sends it inside an intent with the provided fee data.
|
|
147
|
+
* @param maxFee - The max fee to pay for the intent
|
|
148
|
+
* @param feePayer - The fee payer for the intent (optional)
|
|
149
|
+
*/
|
|
150
|
+
send(maxFee: TokenAmount, feePayer: Address | null = null): void {
|
|
151
|
+
this.build().send(maxFee, feePayer)
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Represents a single dynamic argument in a dynamic call.
|
|
157
|
+
*/
|
|
158
|
+
@json
|
|
159
|
+
export class EvmDynamicArg {
|
|
160
|
+
public kind: EvmDynamicArgKind
|
|
161
|
+
public data: string
|
|
162
|
+
public isDynamic: bool
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Creates a literal dynamic argument from ABI-encoded parameters.
|
|
166
|
+
* @param parameters - The ABI parameters to encode as a literal argument
|
|
167
|
+
* @param isDynamic - Whether the resolved argument is ABI-dynamic
|
|
168
|
+
* @returns A new literal dynamic argument
|
|
169
|
+
*/
|
|
170
|
+
static literal(parameters: EvmEncodeParam[], isDynamic: bool): EvmDynamicArg {
|
|
171
|
+
return new EvmDynamicArg(EvmDynamicArgKind.Literal, Bytes.fromHexString(evm.encode(parameters)), isDynamic)
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Creates a variable reference dynamic argument.
|
|
176
|
+
* @param opIndex - The referenced operation index
|
|
177
|
+
* @param subIndex - The referenced output index within the operation
|
|
178
|
+
* @param isDynamic - Whether the resolved argument is ABI-dynamic
|
|
179
|
+
* @returns A new variable dynamic argument
|
|
180
|
+
*/
|
|
181
|
+
static variable(opIndex: u32, subIndex: u32, isDynamic: bool): EvmDynamicArg {
|
|
182
|
+
return new EvmDynamicArg(
|
|
183
|
+
EvmDynamicArgKind.Variable,
|
|
184
|
+
Bytes.fromHexString(
|
|
185
|
+
evm.encode([
|
|
186
|
+
EvmEncodeParam.fromValue('uint256', BigInt.fromU32(opIndex)),
|
|
187
|
+
EvmEncodeParam.fromValue('uint256', BigInt.fromU32(subIndex)),
|
|
188
|
+
])
|
|
189
|
+
),
|
|
190
|
+
isDynamic
|
|
191
|
+
)
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Creates a new EvmDynamicArg instance.
|
|
196
|
+
* @param kind - The argument resolution strategy
|
|
197
|
+
* @param data - The ABI-encoded argument data
|
|
198
|
+
* @param isDynamic - Whether the resolved argument is ABI-dynamic
|
|
199
|
+
*/
|
|
200
|
+
constructor(kind: EvmDynamicArgKind, data: Bytes, isDynamic: bool) {
|
|
201
|
+
this.kind = kind
|
|
202
|
+
this.data = data.toHexString()
|
|
203
|
+
this.isDynamic = isDynamic
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Represents data for a single dynamic contract call within an EVM dynamic call operation.
|
|
209
|
+
*/
|
|
210
|
+
@json
|
|
211
|
+
export class EvmDynamicCallData {
|
|
212
|
+
public target: string
|
|
213
|
+
public value: string
|
|
214
|
+
public selector: string
|
|
215
|
+
public arguments: EvmDynamicArg[]
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Creates a new EvmDynamicCallData instance.
|
|
219
|
+
* @param target - The contract address to call
|
|
220
|
+
* @param selector - The function selector to call
|
|
221
|
+
* @param args - The dynamic arguments for the call
|
|
222
|
+
* @param value - The native token value to send
|
|
223
|
+
*/
|
|
224
|
+
constructor(target: Address, selector: Bytes, args: EvmDynamicArg[] = [], value: BigInt = BigInt.zero()) {
|
|
225
|
+
if (selector.length !== 4) throw new Error('Selector must be 4 bytes')
|
|
226
|
+
this.target = target.toString()
|
|
227
|
+
this.value = value.toString()
|
|
228
|
+
this.selector = selector.toHexString()
|
|
229
|
+
this.arguments = new Array<EvmDynamicArg>(args.length)
|
|
230
|
+
for (let i = 0; i < args.length; i++) {
|
|
231
|
+
const argument = args[i]
|
|
232
|
+
this.arguments[i] = new EvmDynamicArg(argument.kind, Bytes.fromHexString(argument.data), argument.isDynamic)
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Represents an EVM dynamic call operation containing one or more dynamic contract calls.
|
|
239
|
+
*/
|
|
240
|
+
@json
|
|
241
|
+
export class EvmDynamicCall extends Operation {
|
|
242
|
+
public calls: EvmDynamicCallData[]
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Creates a new EvmDynamicCall operation.
|
|
246
|
+
* @param chainId - The blockchain network identifier
|
|
247
|
+
* @param calls - Array of dynamic contract calls to execute
|
|
248
|
+
* @param user - The user address
|
|
249
|
+
* @param events - The operation events to emit
|
|
250
|
+
*/
|
|
251
|
+
constructor(
|
|
252
|
+
chainId: ChainId,
|
|
253
|
+
calls: EvmDynamicCallData[],
|
|
254
|
+
user: Address | null = null,
|
|
255
|
+
events: OperationEvent[] | null = null
|
|
256
|
+
) {
|
|
257
|
+
super(OperationType.EvmDynamicCall, chainId, user, events)
|
|
258
|
+
if (calls.length === 0) throw new Error('Call list cannot be empty')
|
|
259
|
+
this.calls = calls
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Sends this EvmDynamicCall operation wrapped in an intent.
|
|
264
|
+
* @param maxFee - The max fee to pay for the intent
|
|
265
|
+
* @param feePayer - The fee payer for the intent (optional)
|
|
266
|
+
*/
|
|
267
|
+
public send(maxFee: TokenAmount, feePayer: Address | null = null): void {
|
|
268
|
+
const intentBuilder = new IntentBuilder().addMaxFee(maxFee).addOperation(this)
|
|
269
|
+
if (feePayer) intentBuilder.addFeePayer(feePayer)
|
|
270
|
+
environment.sendIntent(intentBuilder.build())
|
|
271
|
+
}
|
|
272
|
+
}
|