forked from Aperture-Finance/uniswap-v3-automation-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinterfaces.ts
836 lines (774 loc) · 29.5 KB
/
interfaces.ts
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
import { FeeAmount } from '@uniswap/v3-sdk';
import { z } from 'zod';
export enum ApertureSupportedChainId {
// Mainnets that use ETH native currency.
ETHEREUM_MAINNET_CHAIN_ID = 1,
ARBITRUM_MAINNET_CHAIN_ID = 42161,
OPTIMISM_MAINNET_CHAIN_ID = 10,
BASE_MAINNET_CHAIN_ID = 8453,
MANTA_PACIFIC_MAINNET_CHAIN_ID = 169,
SCROLL_MAINNET_CHAIN_ID = 534352,
// Mainnets that use non-ETH native currency.
POLYGON_MAINNET_CHAIN_ID = 137,
AVALANCHE_MAINNET_CHAIN_ID = 43114,
BNB_MAINNET_CHAIN_ID = 56,
CELO_MAINNET_CHAIN_ID = 42220,
// Testnets.
GOERLI_TESTNET_CHAIN_ID = 5,
ARBITRUM_GOERLI_TESTNET_CHAIN_ID = 421613,
MANTA_PACIFIC_TESTNET_CHAIN_ID = 3441005,
}
export const ClientTypeEnum = z.enum(['FRONTEND', 'API']);
export type ClientTypeEnum = z.infer<typeof ClientTypeEnum>;
const ClientTypeSchema = z.object({
clientType: ClientTypeEnum.optional().describe('The type of the client.'),
});
const ApertureSupportedChainIdEnum = z
.nativeEnum(ApertureSupportedChainId)
.describe(
'The chain id of the network; must be one of the chains supported by Aperture.',
);
export const ConditionTypeEnum = z.enum([
'Time',
'TokenAmount',
'Price',
'AccruedFees',
'RecurringPercentage',
'RecurringPrice',
'RecurringRatio',
]);
export type ConditionTypeEnum = z.infer<typeof ConditionTypeEnum>;
export const ActionTypeEnum = z
.enum([
'Close',
'LimitOrderClose',
'Reinvest',
'Rebalance',
'RecurringPercentage',
'RecurringPrice',
'RecurringRatio',
])
.describe('The type of action to take.');
export type ActionTypeEnum = z.infer<typeof ActionTypeEnum>;
// TODO: Create a constant for the maximum allowed `maxGasProportion` that matches Automan setting and use it here.
const MaxGasProportionSchema = z
.number()
.positive()
.lte(0.5)
.describe(
'Aperture deducts tokens from the position to cover the cost of performing this action (gas). ' +
'The `maxGasProportion` value represents the largest allowed proportion of the position value to be deducted. ' +
'For example, a `maxGasProportion` of 0.10 represents 10% of the position, i.e. no more than 10% of the ' +
"position's tokens (principal and accrued fees) may be deducted. If network gas price is high and the deduction " +
'would exceed the specified ceiling, then the action will not be triggered.',
);
const SlippageSchema = z
.number()
.nonnegative()
.lte(1)
.describe(
'A number between 0 and 1, inclusive, which Aperture will use as the slippage setting when triggering ' +
'the action after condition is met. Digits after the sixth decimal point are ignored, i.e. the precision is 0.000001.',
);
export const TriggerStatusEnum = z
.enum(['CREATED', 'STARTED', 'COMPLETED', 'INVALID', 'DELETED'])
.describe('The status of the trigger.');
export type TriggerStatusEnum = z.infer<typeof TriggerStatusEnum>;
export const HexSchema = z
.string()
.startsWith('0x')
.describe('A hexadecimal string.');
export const AddressSchema = HexSchema.length(42).describe(
'A hexadecimal address.',
);
export const SignatureSchema = HexSchema.min(132).describe(
'A raw signature of the ERC-712 typed message described in ERC-4494; the signature can be generated,' +
' for example, by https://docs.ethers.org/v5/api/signer/#Signer-signTypedData.',
);
export const TokenAmountSchema = z.object({
address: AddressSchema.describe('The ERC-20 token contract address.'),
rawAmount: z
.string()
.min(1)
.describe(
'The raw amount, which is the human-readable format multiplied by the token decimal.',
),
});
export type TokenAmount = z.infer<typeof TokenAmountSchema>;
export const TimeConditionSchema = z
.object({
type: z.literal(ConditionTypeEnum.enum.Time),
timeAfterEpochSec: z
.number()
.int()
.positive()
.describe(
'This timestamp threshold is specified as the number of seconds since UNIX epoch.',
),
})
.describe(
'The "Time" condition is considered met if the current time meets or exceeds the threshold specified by `timeAfterEpochSec`.',
);
export type TimeCondition = z.infer<typeof TimeConditionSchema>;
export const TokenAmountConditionSchema = z
.object({
type: z.literal(ConditionTypeEnum.enum.TokenAmount),
zeroAmountToken: z
.union([z.literal(0), z.literal(1)])
.describe('Either 0 or 1, representing token0 or token1, respectively.'),
})
.describe(
'The "TokenAmount" condition is considered met if the specified token has a zero (principal) amount in ' +
'the position. `zeroAmountToken` can only be either 0 or 1, representing token0 or token1 in the position, ' +
'respectively. For example, if `zeroAmountToken` is 1, then the condition is considered met if token1 in the ' +
'position is exactly zero. Note that only the principal amount is considered; accrued fees are not.',
);
export type TokenAmountCondition = z.infer<typeof TokenAmountConditionSchema>;
const DurationSecSchema = z
.number()
.int()
.positive()
.optional()
.describe(
'If set, the condition is only considered met if the price remains satisfaction the threshold requirement' +
' for at least the past `durationSec` seconds. For example, if `gte` is 10 and `durationSec` is set to 3600, ' +
'then the condition is only considered met if the price remains >= 10 for the entire past hour. The historical ' +
'price feed used is Coingecko.',
);
export const PriceConditionSchema = z
.object({
type: z.literal(ConditionTypeEnum.enum.Price),
frontendType: z
.enum(['POSITION_VALUE_RATIO', 'RELATIVE_PRICE'])
.optional()
.describe(
'The type of the price condition to display on the frontend. This allows the frontend to ' +
'distinguish between ratio-based and relative-price-based contidions.',
),
gte: z
.string()
.optional()
.describe(
'If `gte` is set, the condition is considered met if the current price >= `gte`.',
),
lte: z
.string()
.optional()
.describe(
'If `lte` is set, the condition is considered met if the current price <= `lte`.',
),
durationSec: DurationSecSchema,
// Deprecated. New triggers with `singleToken` set will be rejected after backend is updated. Existing triggers will continue to work.
singleToken: z
.union([z.literal(0), z.literal(1)])
.optional()
.describe(
'Deprecated. If `singleToken` is set, the condition is considered met if the current USD price of the specified' +
" token (either token0 or token1) meets the specified threshold; otherwise, token0's price denominated in " +
'token1 is compared against the specified threshold,',
),
})
.describe(
"The 'Price' condition checks either one token's price or the two tokens' relative price. If `singleToken`" +
" is set, the price condition compares the specified token's USD price against the specified threshold." +
"Otherwise, token0's price denominated in token1 is compared against the specified threshold, " +
'and we follow how a Uniswap V3 liquidity pool defines price, i.e. how much raw token1 equals 1 raw token0 in value. ' +
'"Raw" means the raw uint256 integer amount used in the token contract. For example, if token A uses 8 decimals, ' +
'then 1 raw token A represents 10^(-8) tokens in human-readable form.',
);
export type PriceCondition = z.infer<typeof PriceConditionSchema>;
export const AccruedFeesConditionSchema = z
.object({
type: z.literal(ConditionTypeEnum.enum.AccruedFees),
feeToPrincipalRatioThreshold: z
.number()
.positive()
.describe(
'The threshold ratio between the accrued fee value and the principal value in the position.',
),
})
.describe(
'The accrued-fees condition specifies a threshold in the form of the ratio between the value of accrued ' +
'fees and that of principal tokens in a specific liquidity position. This condition serves "auto-compound" which ' +
'triggers a "reinvest" action whenever the accrued fees meet the threshold specified in this condition.',
);
export type AccruedFeesCondition = z.infer<typeof AccruedFeesConditionSchema>;
export const RecurringConditionTypeEnum = z.enum([
'RecurringPercentage',
'RecurringPrice',
'RecurringRatio',
]);
export type RecurringConditionTypeEnum = z.infer<
typeof RecurringConditionTypeEnum
>;
export const BaseRecurringConditionSchema = z.object({
sqrtPriceX96: z
.string()
.min(1)
.describe(
'Square root price of `token0` multiplied by 2^96 at trigger creation',
),
durationSec: DurationSecSchema,
});
export const RecurringPercentageConditionSchema =
BaseRecurringConditionSchema.extend({
type: z.literal(RecurringConditionTypeEnum.enum.RecurringPercentage),
gteTickOffset: z
.number()
.optional()
.describe(
'Next trigger price that gets triggered when the pool price is greater than or equal to it, ' +
'as a tick offset from the current tick.',
),
lteTickOffset: z
.number()
.optional()
.describe(
'Next trigger price that gets triggered when the pool price is less than or equal to it, ' +
'as a tick offset from the current tick.',
),
}).describe(
'The "RecurringPercentage" condition defines the target prices in terms of a percentage offset from the ' +
'current price for the next trigger condition.',
);
export type RecurringPercentageCondition = z.infer<
typeof RecurringPercentageConditionSchema
>;
export const RecurringPriceConditionSchema =
BaseRecurringConditionSchema.extend({
type: z.literal(RecurringConditionTypeEnum.enum.RecurringPrice),
baseToken: z
.union([z.literal(0), z.literal(1)])
.describe('Either 0 or 1, representing token0 or token1, respectively.'),
gtePriceOffset: z
.string()
.min(1)
.optional()
.describe(
'The next trigger price that gets triggered when the pool price is greater than or equal to it, ' +
'as a price offset from the current price in human-readable format.',
),
ltePriceOffset: z
.string()
.min(1)
.optional()
.describe(
'The next trigger price that gets triggered when the pool price is less than or equal to it, ' +
'as a price offset from the current price in human-readable format.',
),
}).describe(
'The "RecurringPrice" condition defines the target prices in terms of a price offset from the current ' +
'price for the next trigger condition.',
);
export type RecurringPriceCondition = z.infer<
typeof RecurringPriceConditionSchema
>;
export const RecurringRatioConditionSchema =
BaseRecurringConditionSchema.extend({
type: z.literal(RecurringConditionTypeEnum.enum.RecurringRatio),
gteToken0ValueProportion: z
.string()
.min(1)
.optional()
.describe(
'The proportion of the position value in token0 that defines the target price which gets ' +
'triggered when the pool price is greater than or equal to it.',
),
lteToken0ValueProportion: z
.string()
.min(1)
.optional()
.describe(
'The proportion of the position value in token0 that defines the target price which gets ' +
'triggered when the pool price is less than or equal to it.',
),
}).describe(
'The "RecurringRatio" condition defines the target ratio in terms of the proportion of the position ' +
'value in token0 for the next trigger condition.',
);
export type RecurringRatioCondition = z.infer<
typeof RecurringRatioConditionSchema
>;
export const RecurringConditionSchema = z
.discriminatedUnion('type', [
RecurringPercentageConditionSchema,
RecurringPriceConditionSchema,
RecurringRatioConditionSchema,
])
.describe('The definition of the next trigger condition.');
export type RecurringCondition = z.infer<typeof RecurringConditionSchema>;
export const ConditionSchema = z
.discriminatedUnion('type', [
TimeConditionSchema,
TokenAmountConditionSchema,
PriceConditionSchema,
AccruedFeesConditionSchema,
RecurringPercentageConditionSchema,
RecurringPriceConditionSchema,
RecurringRatioConditionSchema,
])
.describe(
'The condition which triggers the action. If a trigger is successfully created with a condition that is' +
' already met at the time of trigger creation, then the action is immediately eligible to be triggered.',
);
export type Condition = z.infer<typeof ConditionSchema>;
const BaseActionSchema = z.object({
slippage: SlippageSchema,
maxGasProportion: MaxGasProportionSchema,
});
export const CloseActionSchema = BaseActionSchema.extend({
type: z.literal(ActionTypeEnum.enum.Close),
}).describe(
'The "Close" action close the position, and send both tokens (principal and collected fees) to the position owner.',
);
export type CloseAction = z.infer<typeof CloseActionSchema>;
export const LimitOrderCloseActionSchema = z
.object({
type: z.literal(ActionTypeEnum.enum.LimitOrderClose),
inputTokenAddr: AddressSchema.describe(
'The address of the input token for the limit order, i.e. the token which the user provided and ' +
'wants to sell. Must be one of the two tokens in the position.',
),
maxGasProportion: MaxGasProportionSchema,
})
.describe(
"The 'LimitOrderClose' action behaves the same as 'Close' but the position serves a limit order placed through Aperture. " +
'No slippage needs to be specified as limit order positions are always closed with a zero slippage setting.',
);
export type LimitOrderCloseAction = z.infer<typeof LimitOrderCloseActionSchema>;
export const ReinvestActionSchema = BaseActionSchema.extend({
type: z.literal(ActionTypeEnum.enum.Reinvest),
}).describe(
'The "Reinvest" action claims accrued fees, swap them to the same ratio as the principal amounts, and add liquidity.',
);
export type ReinvestAction = z.infer<typeof ReinvestActionSchema>;
export const RebalanceActionSchema = BaseActionSchema.extend({
type: z.literal(ActionTypeEnum.enum.Rebalance),
tickLower: z
.number()
.int()
.describe('The lower tick of the new price range.'),
tickUpper: z
.number()
.int()
.describe('The upper tick of the new price range.'),
isCurrentTickOffset: z
.boolean()
.optional()
.describe(
'When true, `tickLower` and `tickUpper` are offsets from the current tick.',
),
}).describe(
'The "Rebalance" action closes the position, and swap tokens (principal and collected fees) to the ' +
'ratio required by the specified new price range, and open a position with that price range.',
);
export type RebalanceAction = z.infer<typeof RebalanceActionSchema>;
const BaseRecurringActionSchema = BaseActionSchema.extend({
strategyId: z
.string()
.optional()
.describe(
'The id of the recurring rebalance strategy to identify the series of positions.',
),
});
export const RecurringPercentageActionSchema = BaseRecurringActionSchema.extend(
{
type: z.literal(ActionTypeEnum.enum.RecurringPercentage),
tickLowerOffset: z
.number()
.int()
.describe('The lower tick offset of the new price range.'),
tickUpperOffset: z
.number()
.int()
.describe('The upper tick offset of the new price range.'),
},
).describe(
'Rebalance to a new price range specified by the future pool tick and the tick offsets.',
);
export type RecurringPercentageAction = z.infer<
typeof RecurringPercentageActionSchema
>;
export const RecurringPriceActionSchema = BaseRecurringActionSchema.extend({
type: z.literal(ActionTypeEnum.enum.RecurringPrice),
baseToken: z
.union([z.literal(0), z.literal(1)])
.describe('Either 0 or 1, representing token0 or token1, respectively.'),
priceLowerOffset: z
.string()
.min(1)
.describe('The lower price offset in human-readable format.'),
priceUpperOffset: z
.string()
.min(1)
.describe('The upper price offset in human-readable format.'),
}).describe(
'Rebalance to a new price range specified by the future pool price of the base token and the price offsets.',
);
export type RecurringPriceAction = z.infer<typeof RecurringPriceActionSchema>;
export const RecurringRatioActionSchema = BaseRecurringActionSchema.extend({
type: z.literal(ActionTypeEnum.enum.RecurringRatio),
tickRangeWidth: z.number().int().describe('The width of the tick range.'),
token0ValueProportion: z
.string()
.min(1)
.describe('The proportion of the position value in token0.'),
}).describe(
'Rebalance to a new price range specified by the tick range width and the proportion of the position value in token0.',
);
export type RecurringRatioAction = z.infer<typeof RecurringRatioActionSchema>;
export const RecurringActionSchema = z.discriminatedUnion('type', [
RecurringPercentageActionSchema,
RecurringPriceActionSchema,
RecurringRatioActionSchema,
]);
export type RecurringAction = z.infer<typeof RecurringActionSchema>;
export const ActionSchema = z.discriminatedUnion('type', [
CloseActionSchema,
LimitOrderCloseActionSchema,
ReinvestActionSchema,
RebalanceActionSchema,
RecurringPercentageActionSchema,
RecurringPriceActionSchema,
RecurringRatioActionSchema,
]);
export type Action = z.infer<typeof ActionSchema>;
const BaseTriggerPayloadSchema = ClientTypeSchema.extend({
ownerAddr: AddressSchema.describe(
'The owner address of the position; must be a checksum address.',
),
chainId: ApertureSupportedChainIdEnum,
});
export const CreateTriggerPayloadSchema = BaseTriggerPayloadSchema.extend({
nftId: z
.string()
.min(1)
.describe('The nonfungible token id of the position.'),
action: ActionSchema,
condition: ConditionSchema,
expiration: z
.number()
.int()
.positive()
.describe('Unix timestamp in seconds when this trigger expires.'),
autoCompound: z
.object({
action: ReinvestActionSchema,
condition: AccruedFeesConditionSchema,
})
.optional()
.describe('If populated, a reinvest trigger will be created as well.'),
});
export type CreateTriggerPayload = z.infer<typeof CreateTriggerPayloadSchema>;
export const DeleteTriggerPayloadSchema = BaseTriggerPayloadSchema.extend({
taskId: z
.number()
.nonnegative()
.describe("The task id of the trigger in Aperture's automation service."),
});
export type DeleteTriggerPayload = z.infer<typeof DeleteTriggerPayloadSchema>;
export const UpdateTriggerPayloadSchema = BaseTriggerPayloadSchema.extend({
taskId: z
.number()
.nonnegative()
.describe("The task id of the trigger in Aperture's automation service."),
action: ActionSchema.optional().describe(
'If populated, update the action to details specified here; otherwise, action details remain unchanged.',
),
condition: ConditionSchema.optional().describe(
'If populated, update the condition to details specified here; otherwise, condition details remain unchanged.',
),
expiration: z
.number()
.int()
.positive()
.describe('Unix timestamp in seconds when this trigger expires.'),
});
export type UpdateTriggerPayload = z.infer<typeof UpdateTriggerPayloadSchema>;
export const PermitInfoSchema = z
.object({
signature: SignatureSchema,
deadline: z
.string()
.min(1)
.describe(
'Unix timestamp in seconds indicating deadline for the signed "permit".',
),
})
.describe(
'Information about a "permit" message signed by the position owner authorizing Aperture UniV3 Automan ' +
'contract to trigger actions on the position. See https://eips.ethereum.org/EIPS/eip-4494 for information on ' +
'the "permit" approval flow.',
);
export type PermitInfo = z.infer<typeof PermitInfoSchema>;
export const CheckPositionPermitRequestSchema = ClientTypeSchema.extend({
chainId: ApertureSupportedChainIdEnum,
tokenId: z
.string()
.min(1)
.describe('The nonfungible token id of the position.'),
});
export type CheckPositionPermitRequest = z.infer<
typeof CheckPositionPermitRequestSchema
>;
export const UpdatePositionPermitRequestSchema =
CheckPositionPermitRequestSchema.extend({
permitInfo: PermitInfoSchema,
});
export type UpdatePositionPermitRequest = z.infer<
typeof UpdatePositionPermitRequestSchema
>;
const PayloadSignatureSchema = z.object({
payloadSignature: SignatureSchema.describe('Signature of the payload.'),
});
export const CreateTriggerRequestSchema = PayloadSignatureSchema.extend({
payload: CreateTriggerPayloadSchema,
permitInfo: PermitInfoSchema.optional().describe(
"If Aperture doesn't already have authority over the position, " +
'then `permitInfo` should be obtained from the user and populated here.',
),
});
export type CreateTriggerRequest = z.infer<typeof CreateTriggerRequestSchema>;
export const DeleteTriggerRequestSchema = PayloadSignatureSchema.extend({
payload: DeleteTriggerPayloadSchema,
});
export type DeleteTriggerRequest = z.infer<typeof DeleteTriggerRequestSchema>;
export const UpdateTriggerRequestSchema = PayloadSignatureSchema.extend({
payload: UpdateTriggerPayloadSchema,
});
export type UpdateTriggerRequest = z.infer<typeof UpdateTriggerRequestSchema>;
export const ListTriggerRequestSchema = BaseTriggerPayloadSchema.extend({
isLimitOrder: z
.boolean()
.describe(
'If true, only list triggers for limit order fulfillment; otherwise, list all triggers except for limit order fulfillment.',
),
});
export type ListTriggerRequest = z.infer<typeof ListTriggerRequestSchema>;
export const LimitOrderInfoSchema = z.object({
inputTokenAmountAtCreation: TokenAmountSchema.describe(
'The amount of input token at limit order creation.',
),
outputTokenAmountAtClosure: TokenAmountSchema.describe(
'The calculated amount of output token at limit order closure. Note that the limit order may still be pending fulfillment.',
),
earnedFeeInputToken: z
.string()
.optional()
.describe(
'The amount of fees earned in input token. Only populated after the limit order is fulfilled.',
),
earnedFeeOutputToken: z
.string()
.optional()
.describe(
'The amount of fees earned in output token. Only populated after the limit order is fulfilled.',
),
feeTier: z
.nativeEnum(FeeAmount)
.describe('The fee tier of the pool used by the limit order.'),
tickLower: z
.number()
.int()
.describe('The lower tick of the position serving the limit order.'),
tickUpper: z
.number()
.int()
.describe('The upper tick of the position serving the limit order.'),
});
export type LimitOrderInfo = z.infer<typeof LimitOrderInfoSchema>;
export const TriggerItemSchema = z.object({
taskId: z
.number()
.nonnegative()
.describe("The task id of the trigger in Aperture's automation service."),
nftId: z
.string()
.min(1)
.describe('The nonfungible token id of the position.'),
status: TriggerStatusEnum,
lastFailedMessage: z
.string()
.optional()
.describe('If populated, the failure message of the last failed trigger.'),
limitOrderInfo: LimitOrderInfoSchema.optional(),
condition: ConditionSchema,
action: ActionSchema,
expiration: z
.number()
.int()
.positive()
.describe('Unix timestamp in seconds when this trigger expires.'),
creation: z
.number()
.int()
.positive()
.optional()
.describe('Unix timestamp in seconds when this trigger is created.'),
completion: z
.number()
.int()
.positive()
.optional()
.describe('Unix timestamp in seconds when this trigger is completed.'),
transactionHash: HexSchema.optional().describe(
'The transaction hash of the transaction that triggered this action.',
),
});
export type TriggerItem = z.infer<typeof TriggerItemSchema>;
export const ListTriggerResponseSchema = z.object({
triggers: z.array(TriggerItemSchema).describe('The list of triggers.'),
});
export type ListTriggerResponse = z.infer<typeof ListTriggerResponseSchema>;
export const CheckUserLimitRequestSchema = ClientTypeSchema.extend({
ownerAddr: AddressSchema.describe(
'The owner address of position `tokenId`; must be a checksum address.',
),
chainId: ApertureSupportedChainIdEnum,
tokenId: z
.string()
.min(1)
.describe('The nonfungible token id of the position to check limit for.'),
actionType: ActionTypeEnum,
});
export type CheckUserLimitRequest = z.infer<typeof CheckUserLimitRequestSchema>;
export const SignPrivateBetaAgreementRequestSchema = ClientTypeSchema.extend({
ownerAddr: AddressSchema.describe(
'The user wallet address; must be a checksum address.',
),
signature: SignatureSchema.describe('User signature.'),
});
export type SignPrivateBetaAgreementRequest = z.infer<
typeof SignPrivateBetaAgreementRequestSchema
>;
export const HasSignedPrivateBetaAgreementRequestSchema =
ClientTypeSchema.extend({
ownerAddr: AddressSchema.describe(
'The user wallet address; must be a checksum address.',
),
});
export type HasSignedPrivateBetaAgreementRequest = z.infer<
typeof HasSignedPrivateBetaAgreementRequestSchema
>;
export const HasSignedPrivateBetaAgreementResponseSchema = z.object({
hasSigned: z
.boolean()
.describe(
'True if the user has signed the private beta agreement; false otherwise.',
),
});
export type HasSignedPrivateBetaAgreementResponse = z.infer<
typeof HasSignedPrivateBetaAgreementResponseSchema
>;
export const GetStrategiesDetailRequestSchema = ClientTypeSchema.extend({
ownerAddr: AddressSchema.describe(
'The owner address of position `tokenId`; must be a checksum address.',
),
chainId: ApertureSupportedChainIdEnum,
});
export type GetStrategiesDetailRequest = z.infer<
typeof GetStrategiesDetailRequestSchema
>;
export const GetStrategyDetailRequestSchema =
GetStrategiesDetailRequestSchema.extend({
strategyId: z.string().min(1).describe('The id of the strategy.'),
});
export type GetStrategyDetailRequest = z.infer<
typeof GetStrategyDetailRequestSchema
>;
export const StrategyDetailItemSechema = TriggerItemSchema.omit({
limitOrderInfo: true,
}).extend({
gas_fee: z.number().nonnegative().optional(),
gas_fee_value: z.number().nonnegative().optional(),
token0Address: z.string().length(42).optional(),
token1Address: z.string().length(42).optional(),
feeTier: z.number().nonnegative().optional(),
tickLower: z.number().int().optional(),
tickUpper: z.number().int().optional(),
positionEtherValue: z
.number()
.optional()
.describe(
"The value of the position's prinpical tokens in the chain's native currency, e.g. a value of 2.3 means " +
"that the position's prinpical tokens are worth 2.3 ETH if the chain's native currency is ETH. Only populated " +
'when the action is triggered and the task switches to STARTED status.',
),
positionEtherValueWhenCompleted: z
.number()
.optional()
.describe(
"The value of the position's prinpical tokens in the chain's native currency, e.g. a value of 2.3 means " +
"that the position's prinpical tokens are worth 2.3 ETH if the chain's native currency is ETH. Only populated " +
'when the action is completed and the task switches to COMPLETED status.',
),
positionUsdValueWhenCompleted: z
.number()
.optional()
.describe(
"The value of the position's prinpical tokens in USD. Only populated when the action is completed and the task switches to COMPLETED status.",
),
accruedFeeFraction: z
.number()
.optional()
.describe(
'A number representing the ratio between accrued fees in the position and principal value. Only populated ' +
'when the action is triggered and the task switches to STARTED status, and the condition is of type AccruedFees.',
),
feeCollectedToken0: z
.number()
.optional()
.describe(
'A number representing the fee collected on token0. Only populated when the action is triggered and the ' +
'task switches to COMPLETED status, and the type is of Reinvest or Rebalance.',
),
feeCollectedToken1: z
.number()
.optional()
.describe(
'A number representing the fee collected on token0. Only populated when the action is triggered and the ' +
'task switches to COMPLETED status, and the type is of Reinvest or Rebalance.',
),
feeCollectedToken0UsdValue: z
.number()
.optional()
.describe(
'A number representing the fee collected on token0. Only populated when the action is triggered and the ' +
'task switches to COMPLETED status, and the type is of Reinvest or Rebalance.',
),
feeCollectedToken1UsdValue: z
.number()
.optional()
.describe(
'A number representing the fee collected on token0. Only populated when the action is triggered and the ' +
'task switches to COMPLETED status, and the type is of Reinvest or Rebalance.',
),
});
export type StrategyDetailItem = z.infer<typeof StrategyDetailItemSechema>;
export const GetStrategyDetailResponseSchema = z.object({
executed: z
.number()
.int()
.describe('Number of times the strategy is executed.'),
feeCollected: z.object({
feeCollectedToken0: z.number(),
feeCollectedToken1: z.number(),
feeCollectedToken0UsdValue: z.number(),
feeCollectedToken1UsdValue: z.number(),
}),
current: z
.array(StrategyDetailItemSechema)
.describe('Current strategy trigger.'),
history: z
.array(StrategyDetailItemSechema)
.describe('History of strategy triggers.'),
});
export type GetStrategyDetailResponse = z.infer<
typeof GetStrategyDetailResponseSchema
>;
export const GetStrategiesDetailResponseSchema = z.array(
GetStrategyDetailResponseSchema,
);
export type GetStrategiesDetailResponse = z.infer<
typeof GetStrategiesDetailResponseSchema
>;