viem 2.57.5 → 2.57.6
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 +8 -0
- package/_cjs/errors/version.js +1 -1
- package/_cjs/tempo/Abis.js +297 -1
- package/_cjs/tempo/Abis.js.map +1 -1
- package/_cjs/tempo/Addresses.js +2 -1
- package/_cjs/tempo/Addresses.js.map +1 -1
- package/_cjs/tempo/Decorator.js.map +1 -1
- package/_cjs/tempo/ExecutionError.js +94 -3
- package/_cjs/tempo/ExecutionError.js.map +1 -1
- package/_cjs/tempo/actions/accessKey.js +382 -10
- package/_cjs/tempo/actions/accessKey.js.map +1 -1
- package/_cjs/tempo/actions/accounts.js +3 -2
- package/_cjs/tempo/actions/accounts.js.map +1 -1
- package/_cjs/tempo/actions/amm.js +90 -4
- package/_cjs/tempo/actions/amm.js.map +1 -1
- package/_cjs/tempo/actions/channel.js +183 -7
- package/_cjs/tempo/actions/channel.js.map +1 -1
- package/_cjs/tempo/actions/dex.js +507 -14
- package/_cjs/tempo/actions/dex.js.map +1 -1
- package/_cjs/tempo/actions/earn/deployment.js +4 -3
- package/_cjs/tempo/actions/earn/deployment.js.map +1 -1
- package/_cjs/tempo/actions/earn.js +22 -21
- package/_cjs/tempo/actions/earn.js.map +1 -1
- package/_cjs/tempo/actions/fee.js +85 -5
- package/_cjs/tempo/actions/fee.js.map +1 -1
- package/_cjs/tempo/actions/nonce.js +54 -1
- package/_cjs/tempo/actions/nonce.js.map +1 -1
- package/_cjs/tempo/actions/policy.js +35 -6
- package/_cjs/tempo/actions/policy.js.map +1 -1
- package/_cjs/tempo/actions/propAmm.js +18 -8
- package/_cjs/tempo/actions/propAmm.js.map +1 -1
- package/_cjs/tempo/actions/receivePolicy.js +7 -6
- package/_cjs/tempo/actions/receivePolicy.js.map +1 -1
- package/_cjs/tempo/actions/reward.js +7 -6
- package/_cjs/tempo/actions/reward.js.map +1 -1
- package/_cjs/tempo/actions/token.js +433 -22
- package/_cjs/tempo/actions/token.js.map +1 -1
- package/_cjs/tempo/actions/validator.js +12 -11
- package/_cjs/tempo/actions/validator.js.map +1 -1
- package/_cjs/tempo/actions/virtualAddress.js +3 -2
- package/_cjs/tempo/actions/virtualAddress.js.map +1 -1
- package/_cjs/tempo/actions/zone.js +12 -11
- package/_cjs/tempo/actions/zone.js.map +1 -1
- package/_cjs/tempo/errors.js +57 -1
- package/_cjs/tempo/errors.js.map +1 -1
- package/_cjs/tempo/internal/errors.js +46 -0
- package/_cjs/tempo/internal/errors.js.map +1 -0
- package/_cjs/tempo/internal/resolveError.js +128 -0
- package/_cjs/tempo/internal/resolveError.js.map +1 -0
- package/_cjs/tempo/internal/utils.js +1 -0
- package/_cjs/tempo/internal/utils.js.map +1 -1
- package/_esm/errors/version.js +1 -1
- package/_esm/tempo/Abis.js +297 -0
- package/_esm/tempo/Abis.js.map +1 -1
- package/_esm/tempo/Addresses.js +1 -0
- package/_esm/tempo/Addresses.js.map +1 -1
- package/_esm/tempo/Decorator.js.map +1 -1
- package/_esm/tempo/ExecutionError.js +95 -2
- package/_esm/tempo/ExecutionError.js.map +1 -1
- package/_esm/tempo/actions/accessKey.js +406 -10
- package/_esm/tempo/actions/accessKey.js.map +1 -1
- package/_esm/tempo/actions/accounts.js +3 -2
- package/_esm/tempo/actions/accounts.js.map +1 -1
- package/_esm/tempo/actions/amm.js +95 -4
- package/_esm/tempo/actions/amm.js.map +1 -1
- package/_esm/tempo/actions/channel.js +191 -7
- package/_esm/tempo/actions/channel.js.map +1 -1
- package/_esm/tempo/actions/dex.js +537 -14
- package/_esm/tempo/actions/dex.js.map +1 -1
- package/_esm/tempo/actions/earn/deployment.js +4 -3
- package/_esm/tempo/actions/earn/deployment.js.map +1 -1
- package/_esm/tempo/actions/earn.js +22 -21
- package/_esm/tempo/actions/earn.js.map +1 -1
- package/_esm/tempo/actions/fee.js +90 -6
- package/_esm/tempo/actions/fee.js.map +1 -1
- package/_esm/tempo/actions/nonce.js +57 -1
- package/_esm/tempo/actions/nonce.js.map +1 -1
- package/_esm/tempo/actions/policy.js +36 -6
- package/_esm/tempo/actions/policy.js.map +1 -1
- package/_esm/tempo/actions/propAmm.js +18 -8
- package/_esm/tempo/actions/propAmm.js.map +1 -1
- package/_esm/tempo/actions/receivePolicy.js +7 -6
- package/_esm/tempo/actions/receivePolicy.js.map +1 -1
- package/_esm/tempo/actions/reward.js +7 -6
- package/_esm/tempo/actions/reward.js.map +1 -1
- package/_esm/tempo/actions/token.js +461 -22
- package/_esm/tempo/actions/token.js.map +1 -1
- package/_esm/tempo/actions/validator.js +12 -11
- package/_esm/tempo/actions/validator.js.map +1 -1
- package/_esm/tempo/actions/virtualAddress.js +3 -2
- package/_esm/tempo/actions/virtualAddress.js.map +1 -1
- package/_esm/tempo/actions/zone.js +12 -11
- package/_esm/tempo/actions/zone.js.map +1 -1
- package/_esm/tempo/errors.js +63 -0
- package/_esm/tempo/errors.js.map +1 -1
- package/_esm/tempo/internal/errors.js +51 -0
- package/_esm/tempo/internal/errors.js.map +1 -0
- package/_esm/tempo/internal/resolveError.js +130 -0
- package/_esm/tempo/internal/resolveError.js.map +1 -0
- package/_esm/tempo/internal/utils.js +2 -0
- package/_esm/tempo/internal/utils.js.map +1 -1
- package/_types/errors/version.d.ts +1 -1
- package/_types/tempo/Abis.d.ts +807 -0
- package/_types/tempo/Abis.d.ts.map +1 -1
- package/_types/tempo/Addresses.d.ts +1 -0
- package/_types/tempo/Addresses.d.ts.map +1 -1
- package/_types/tempo/Decorator.d.ts +1 -1
- package/_types/tempo/Decorator.d.ts.map +1 -1
- package/_types/tempo/ExecutionError.d.ts +3 -1
- package/_types/tempo/ExecutionError.d.ts.map +1 -1
- package/_types/tempo/actions/accessKey.d.ts +155 -8
- package/_types/tempo/actions/accessKey.d.ts.map +1 -1
- package/_types/tempo/actions/accounts.d.ts +3 -1
- package/_types/tempo/actions/accounts.d.ts.map +1 -1
- package/_types/tempo/actions/amm.d.ts +39 -0
- package/_types/tempo/actions/amm.d.ts.map +1 -1
- package/_types/tempo/actions/channel.d.ts +77 -7
- package/_types/tempo/actions/channel.d.ts.map +1 -1
- package/_types/tempo/actions/dex.d.ts +222 -16
- package/_types/tempo/actions/dex.d.ts.map +1 -1
- package/_types/tempo/actions/earn/deployment.d.ts +7 -6
- package/_types/tempo/actions/earn/deployment.d.ts.map +1 -1
- package/_types/tempo/actions/earn.d.ts +15 -14
- package/_types/tempo/actions/earn.d.ts.map +1 -1
- package/_types/tempo/actions/fee.d.ts +32 -6
- package/_types/tempo/actions/fee.d.ts.map +1 -1
- package/_types/tempo/actions/nonce.d.ts +35 -0
- package/_types/tempo/actions/nonce.d.ts.map +1 -1
- package/_types/tempo/actions/policy.d.ts +29 -8
- package/_types/tempo/actions/policy.d.ts.map +1 -1
- package/_types/tempo/actions/propAmm.d.ts +9 -1
- package/_types/tempo/actions/propAmm.d.ts.map +1 -1
- package/_types/tempo/actions/receivePolicy.d.ts +10 -6
- package/_types/tempo/actions/receivePolicy.d.ts.map +1 -1
- package/_types/tempo/actions/reward.d.ts +7 -3
- package/_types/tempo/actions/reward.d.ts.map +1 -1
- package/_types/tempo/actions/token.d.ts +200 -32
- package/_types/tempo/actions/token.d.ts.map +1 -1
- package/_types/tempo/actions/validator.d.ts +17 -5
- package/_types/tempo/actions/validator.d.ts.map +1 -1
- package/_types/tempo/actions/virtualAddress.d.ts +4 -3
- package/_types/tempo/actions/virtualAddress.d.ts.map +1 -1
- package/_types/tempo/actions/zone.d.ts +10 -9
- package/_types/tempo/actions/zone.d.ts.map +1 -1
- package/_types/tempo/errors.d.ts +63 -1
- package/_types/tempo/errors.d.ts.map +1 -1
- package/_types/tempo/internal/errors.d.ts +59 -0
- package/_types/tempo/internal/errors.d.ts.map +1 -0
- package/_types/tempo/internal/resolveError.d.ts +8 -0
- package/_types/tempo/internal/resolveError.d.ts.map +1 -0
- package/_types/tempo/internal/utils.d.ts.map +1 -1
- package/errors/version.ts +1 -1
- package/package.json +1 -1
- package/tempo/Abis.ts +298 -0
- package/tempo/Addresses.ts +1 -0
- package/tempo/Decorator.ts +5 -3
- package/tempo/ExecutionError.ts +101 -3
- package/tempo/actions/accessKey.ts +496 -25
- package/tempo/actions/accounts.ts +7 -3
- package/tempo/actions/amm.ts +126 -4
- package/tempo/actions/channel.ts +248 -14
- package/tempo/actions/dex.ts +599 -33
- package/tempo/actions/earn/deployment.ts +11 -9
- package/tempo/actions/earn.ts +40 -35
- package/tempo/actions/fee.ts +111 -9
- package/tempo/actions/nonce.ts +86 -1
- package/tempo/actions/policy.ts +66 -14
- package/tempo/actions/propAmm.ts +36 -9
- package/tempo/actions/receivePolicy.ts +26 -15
- package/tempo/actions/reward.ts +17 -9
- package/tempo/actions/token.ts +519 -54
- package/tempo/actions/validator.ts +40 -16
- package/tempo/actions/virtualAddress.ts +7 -5
- package/tempo/actions/zone.ts +25 -20
- package/tempo/errors.ts +114 -1
- package/tempo/internal/errors.ts +110 -0
- package/tempo/internal/resolveError.ts +169 -0
- package/tempo/internal/utils.ts +2 -0
package/tempo/actions/dex.ts
CHANGED
|
@@ -24,8 +24,16 @@ import type { ExtractAbiItem, GetEventArgs } from '../../types/contract.js'
|
|
|
24
24
|
import type { Log as viem_Log } from '../../types/log.js'
|
|
25
25
|
import type { Compute, UnionOmit } from '../../types/utils.js'
|
|
26
26
|
import { parseEventLogs } from '../../utils/abi/parseEventLogs.js'
|
|
27
|
+
import { isAddressEqual } from '../../utils/address/isAddressEqual.js'
|
|
27
28
|
import * as Abis from '../Abis.js'
|
|
28
29
|
import * as Addresses from '../Addresses.js'
|
|
30
|
+
import type * as Errors from '../errors.js'
|
|
31
|
+
import { TempoExecutionError } from '../errors.js'
|
|
32
|
+
import {
|
|
33
|
+
type Context,
|
|
34
|
+
type Resolvers,
|
|
35
|
+
withExecutionError,
|
|
36
|
+
} from '../internal/errors.js'
|
|
29
37
|
import type {
|
|
30
38
|
GetAccountParameter,
|
|
31
39
|
ReadParameters,
|
|
@@ -97,7 +105,7 @@ export namespace buy {
|
|
|
97
105
|
export type ReturnValue = WriteContractReturnType
|
|
98
106
|
|
|
99
107
|
// TODO: exhaustive error type
|
|
100
|
-
export type ErrorType = BaseErrorType
|
|
108
|
+
export type ErrorType = Errors.ExecutionErrorType | BaseErrorType
|
|
101
109
|
|
|
102
110
|
/** @internal */
|
|
103
111
|
export async function inner<
|
|
@@ -111,7 +119,7 @@ export namespace buy {
|
|
|
111
119
|
): Promise<ReturnType<action>> {
|
|
112
120
|
const { tokenIn, tokenOut, amountOut, maxAmountIn, ...rest } = parameters
|
|
113
121
|
const call = buy.call({ tokenIn, tokenOut, amountOut, maxAmountIn })
|
|
114
|
-
return (await action(client, {
|
|
122
|
+
return (await withExecutionError(action)(client, {
|
|
115
123
|
...rest,
|
|
116
124
|
...call,
|
|
117
125
|
} as never)) as never
|
|
@@ -219,7 +227,7 @@ export namespace buySync {
|
|
|
219
227
|
}>
|
|
220
228
|
|
|
221
229
|
// TODO: exhaustive error type
|
|
222
|
-
export type ErrorType = BaseErrorType
|
|
230
|
+
export type ErrorType = Errors.ExecutionErrorType | BaseErrorType
|
|
223
231
|
}
|
|
224
232
|
|
|
225
233
|
/**
|
|
@@ -271,7 +279,7 @@ export namespace cancel {
|
|
|
271
279
|
export type ReturnValue = WriteContractReturnType
|
|
272
280
|
|
|
273
281
|
// TODO: exhaustive error type
|
|
274
|
-
export type ErrorType = BaseErrorType
|
|
282
|
+
export type ErrorType = Errors.ExecutionErrorType | BaseErrorType
|
|
275
283
|
|
|
276
284
|
/** @internal */
|
|
277
285
|
export async function inner<
|
|
@@ -285,7 +293,7 @@ export namespace cancel {
|
|
|
285
293
|
): Promise<ReturnType<action>> {
|
|
286
294
|
const { orderId, ...rest } = parameters
|
|
287
295
|
const call = cancel.call({ orderId })
|
|
288
|
-
return (await action(client, {
|
|
296
|
+
return (await withExecutionError(action)(client, {
|
|
289
297
|
...rest,
|
|
290
298
|
...call,
|
|
291
299
|
} as never)) as never
|
|
@@ -416,7 +424,7 @@ export namespace cancelSync {
|
|
|
416
424
|
>
|
|
417
425
|
|
|
418
426
|
// TODO: exhaustive error type
|
|
419
|
-
export type ErrorType = BaseErrorType
|
|
427
|
+
export type ErrorType = Errors.ExecutionErrorType | BaseErrorType
|
|
420
428
|
}
|
|
421
429
|
|
|
422
430
|
/**
|
|
@@ -471,7 +479,7 @@ export namespace cancelStale {
|
|
|
471
479
|
export type ReturnValue = WriteContractReturnType
|
|
472
480
|
|
|
473
481
|
// TODO: exhaustive error type
|
|
474
|
-
export type ErrorType = BaseErrorType
|
|
482
|
+
export type ErrorType = Errors.ExecutionErrorType | BaseErrorType
|
|
475
483
|
|
|
476
484
|
/** @internal */
|
|
477
485
|
export async function inner<
|
|
@@ -485,7 +493,7 @@ export namespace cancelStale {
|
|
|
485
493
|
): Promise<ReturnType<action>> {
|
|
486
494
|
const { orderId, ...rest } = parameters
|
|
487
495
|
const call = cancelStale.call({ orderId })
|
|
488
|
-
return (await action(client, {
|
|
496
|
+
return (await withExecutionError(action)(client, {
|
|
489
497
|
...rest,
|
|
490
498
|
...call,
|
|
491
499
|
} as never)) as never
|
|
@@ -619,7 +627,7 @@ export namespace cancelStaleSync {
|
|
|
619
627
|
>
|
|
620
628
|
|
|
621
629
|
// TODO: exhaustive error type
|
|
622
|
-
export type ErrorType = BaseErrorType
|
|
630
|
+
export type ErrorType = Errors.ExecutionErrorType | BaseErrorType
|
|
623
631
|
}
|
|
624
632
|
|
|
625
633
|
/**
|
|
@@ -671,7 +679,7 @@ export namespace createPair {
|
|
|
671
679
|
export type ReturnValue = WriteContractReturnType
|
|
672
680
|
|
|
673
681
|
// TODO: exhaustive error type
|
|
674
|
-
export type ErrorType = BaseErrorType
|
|
682
|
+
export type ErrorType = Errors.ExecutionErrorType | BaseErrorType
|
|
675
683
|
|
|
676
684
|
/** @internal */
|
|
677
685
|
export async function inner<
|
|
@@ -685,7 +693,7 @@ export namespace createPair {
|
|
|
685
693
|
): Promise<ReturnType<action>> {
|
|
686
694
|
const { base, ...rest } = parameters
|
|
687
695
|
const call = createPair.call({ base })
|
|
688
|
-
return (await action(client, {
|
|
696
|
+
return (await withExecutionError(action)(client, {
|
|
689
697
|
...rest,
|
|
690
698
|
...call,
|
|
691
699
|
} as never)) as never
|
|
@@ -816,7 +824,7 @@ export namespace createPairSync {
|
|
|
816
824
|
>
|
|
817
825
|
|
|
818
826
|
// TODO: exhaustive error type
|
|
819
|
-
export type ErrorType = BaseErrorType
|
|
827
|
+
export type ErrorType = Errors.ExecutionErrorType | BaseErrorType
|
|
820
828
|
}
|
|
821
829
|
|
|
822
830
|
/**
|
|
@@ -853,7 +861,7 @@ export async function getBalance<
|
|
|
853
861
|
const { account: acc = client.account, token, ...rest } = parameters
|
|
854
862
|
const address = acc ? parseAccount(acc).address : undefined
|
|
855
863
|
if (!address) throw new Error('account is required.')
|
|
856
|
-
return readContract(client, {
|
|
864
|
+
return withExecutionError(readContract)(client, {
|
|
857
865
|
...rest,
|
|
858
866
|
...getBalance.call({ account: address, token }),
|
|
859
867
|
})
|
|
@@ -892,6 +900,8 @@ export namespace getBalance {
|
|
|
892
900
|
functionName: 'balanceOf',
|
|
893
901
|
})
|
|
894
902
|
}
|
|
903
|
+
|
|
904
|
+
export type ErrorType = Errors.ExecutionErrorType | BaseErrorType
|
|
895
905
|
}
|
|
896
906
|
|
|
897
907
|
/**
|
|
@@ -924,7 +934,7 @@ export async function getBuyQuote<chain extends Chain | undefined>(
|
|
|
924
934
|
parameters: getBuyQuote.Parameters,
|
|
925
935
|
): Promise<getBuyQuote.ReturnValue> {
|
|
926
936
|
const { tokenIn, tokenOut, amountOut, ...rest } = parameters
|
|
927
|
-
return readContract(client, {
|
|
937
|
+
return withExecutionError(readContract)(client, {
|
|
928
938
|
...rest,
|
|
929
939
|
...getBuyQuote.call({ tokenIn, tokenOut, amountOut }),
|
|
930
940
|
})
|
|
@@ -963,6 +973,8 @@ export namespace getBuyQuote {
|
|
|
963
973
|
functionName: 'quoteSwapExactAmountOut',
|
|
964
974
|
})
|
|
965
975
|
}
|
|
976
|
+
|
|
977
|
+
export type ErrorType = Errors.ExecutionErrorType | BaseErrorType
|
|
966
978
|
}
|
|
967
979
|
|
|
968
980
|
/**
|
|
@@ -993,7 +1005,7 @@ export async function getOrder<chain extends Chain | undefined>(
|
|
|
993
1005
|
parameters: getOrder.Parameters,
|
|
994
1006
|
): Promise<getOrder.ReturnValue> {
|
|
995
1007
|
const { orderId, ...rest } = parameters
|
|
996
|
-
return readContract(client, {
|
|
1008
|
+
return withExecutionError(readContract)(client, {
|
|
997
1009
|
...rest,
|
|
998
1010
|
...getOrder.call({ orderId }),
|
|
999
1011
|
})
|
|
@@ -1028,6 +1040,8 @@ export namespace getOrder {
|
|
|
1028
1040
|
functionName: 'getOrder',
|
|
1029
1041
|
})
|
|
1030
1042
|
}
|
|
1043
|
+
|
|
1044
|
+
export type ErrorType = Errors.ExecutionErrorType | BaseErrorType
|
|
1031
1045
|
}
|
|
1032
1046
|
|
|
1033
1047
|
/**
|
|
@@ -1059,7 +1073,7 @@ export async function getOrderbook<chain extends Chain | undefined>(
|
|
|
1059
1073
|
parameters: getOrderbook.Parameters,
|
|
1060
1074
|
): Promise<getOrderbook.ReturnValue> {
|
|
1061
1075
|
const { base, quote, ...rest } = parameters
|
|
1062
|
-
return readContract(client, {
|
|
1076
|
+
return withExecutionError(readContract)(client, {
|
|
1063
1077
|
...rest,
|
|
1064
1078
|
...getOrderbook.call({ base, quote }),
|
|
1065
1079
|
})
|
|
@@ -1097,6 +1111,8 @@ export namespace getOrderbook {
|
|
|
1097
1111
|
functionName: 'books',
|
|
1098
1112
|
})
|
|
1099
1113
|
}
|
|
1114
|
+
|
|
1115
|
+
export type ErrorType = Errors.ExecutionErrorType | BaseErrorType
|
|
1100
1116
|
}
|
|
1101
1117
|
|
|
1102
1118
|
/**
|
|
@@ -1129,10 +1145,13 @@ export async function getTickLevel<chain extends Chain | undefined>(
|
|
|
1129
1145
|
parameters: getTickLevel.Parameters,
|
|
1130
1146
|
): Promise<getTickLevel.ReturnValue> {
|
|
1131
1147
|
const { base, tick, isBid, ...rest } = parameters
|
|
1132
|
-
const [head, tail, totalLiquidity] = await readContract(
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1148
|
+
const [head, tail, totalLiquidity] = await withExecutionError(readContract)(
|
|
1149
|
+
client,
|
|
1150
|
+
{
|
|
1151
|
+
...rest,
|
|
1152
|
+
...getTickLevel.call({ base, tick, isBid }),
|
|
1153
|
+
},
|
|
1154
|
+
)
|
|
1136
1155
|
return { head, tail, totalLiquidity }
|
|
1137
1156
|
}
|
|
1138
1157
|
|
|
@@ -1172,6 +1191,8 @@ export namespace getTickLevel {
|
|
|
1172
1191
|
functionName: 'getTickLevel',
|
|
1173
1192
|
})
|
|
1174
1193
|
}
|
|
1194
|
+
|
|
1195
|
+
export type ErrorType = Errors.ExecutionErrorType | BaseErrorType
|
|
1175
1196
|
}
|
|
1176
1197
|
|
|
1177
1198
|
/**
|
|
@@ -1204,7 +1225,7 @@ export async function getSellQuote<chain extends Chain | undefined>(
|
|
|
1204
1225
|
parameters: getSellQuote.Parameters,
|
|
1205
1226
|
): Promise<getSellQuote.ReturnValue> {
|
|
1206
1227
|
const { tokenIn, tokenOut, amountIn, ...rest } = parameters
|
|
1207
|
-
return readContract(client, {
|
|
1228
|
+
return withExecutionError(readContract)(client, {
|
|
1208
1229
|
...rest,
|
|
1209
1230
|
...getSellQuote.call({ tokenIn, tokenOut, amountIn }),
|
|
1210
1231
|
})
|
|
@@ -1243,6 +1264,8 @@ export namespace getSellQuote {
|
|
|
1243
1264
|
functionName: 'quoteSwapExactAmountIn',
|
|
1244
1265
|
})
|
|
1245
1266
|
}
|
|
1267
|
+
|
|
1268
|
+
export type ErrorType = Errors.ExecutionErrorType | BaseErrorType
|
|
1246
1269
|
}
|
|
1247
1270
|
|
|
1248
1271
|
/**
|
|
@@ -1303,7 +1326,7 @@ export namespace place {
|
|
|
1303
1326
|
export type ReturnValue = WriteContractReturnType
|
|
1304
1327
|
|
|
1305
1328
|
// TODO: exhaustive error type
|
|
1306
|
-
export type ErrorType = BaseErrorType
|
|
1329
|
+
export type ErrorType = Errors.ExecutionErrorType | BaseErrorType
|
|
1307
1330
|
|
|
1308
1331
|
/** @internal */
|
|
1309
1332
|
export async function inner<
|
|
@@ -1317,7 +1340,7 @@ export namespace place {
|
|
|
1317
1340
|
): Promise<ReturnType<action>> {
|
|
1318
1341
|
const { amount, token, type, tick, ...rest } = parameters
|
|
1319
1342
|
const call = place.call({ amount, token, type, tick })
|
|
1320
|
-
return (await action(client, {
|
|
1343
|
+
return (await withExecutionError(action)(client, {
|
|
1321
1344
|
...rest,
|
|
1322
1345
|
...call,
|
|
1323
1346
|
} as never)) as never
|
|
@@ -1447,7 +1470,7 @@ export namespace placeFlip {
|
|
|
1447
1470
|
export type ReturnValue = WriteContractReturnType
|
|
1448
1471
|
|
|
1449
1472
|
// TODO: exhaustive error type
|
|
1450
|
-
export type ErrorType = BaseErrorType
|
|
1473
|
+
export type ErrorType = Errors.ExecutionErrorType | BaseErrorType
|
|
1451
1474
|
|
|
1452
1475
|
/** @internal */
|
|
1453
1476
|
export async function inner<
|
|
@@ -1461,7 +1484,7 @@ export namespace placeFlip {
|
|
|
1461
1484
|
): Promise<ReturnType<action>> {
|
|
1462
1485
|
const { amount, flipTick, tick, token, type, ...rest } = parameters
|
|
1463
1486
|
const call = placeFlip.call({ amount, flipTick, tick, token, type })
|
|
1464
|
-
return (await action(client, {
|
|
1487
|
+
return (await withExecutionError(action)(client, {
|
|
1465
1488
|
...rest,
|
|
1466
1489
|
...call,
|
|
1467
1490
|
} as never)) as never
|
|
@@ -1602,7 +1625,7 @@ export namespace placeFlipSync {
|
|
|
1602
1625
|
>
|
|
1603
1626
|
|
|
1604
1627
|
// TODO: exhaustive error type
|
|
1605
|
-
export type ErrorType = BaseErrorType
|
|
1628
|
+
export type ErrorType = Errors.ExecutionErrorType | BaseErrorType
|
|
1606
1629
|
}
|
|
1607
1630
|
|
|
1608
1631
|
/**
|
|
@@ -1674,7 +1697,7 @@ export namespace placeSync {
|
|
|
1674
1697
|
>
|
|
1675
1698
|
|
|
1676
1699
|
// TODO: exhaustive error type
|
|
1677
|
-
export type ErrorType = BaseErrorType
|
|
1700
|
+
export type ErrorType = Errors.ExecutionErrorType | BaseErrorType
|
|
1678
1701
|
}
|
|
1679
1702
|
|
|
1680
1703
|
/**
|
|
@@ -1735,7 +1758,7 @@ export namespace sell {
|
|
|
1735
1758
|
export type ReturnValue = WriteContractReturnType
|
|
1736
1759
|
|
|
1737
1760
|
// TODO: exhaustive error type
|
|
1738
|
-
export type ErrorType = BaseErrorType
|
|
1761
|
+
export type ErrorType = Errors.ExecutionErrorType | BaseErrorType
|
|
1739
1762
|
|
|
1740
1763
|
/** @internal */
|
|
1741
1764
|
export async function inner<
|
|
@@ -1749,7 +1772,7 @@ export namespace sell {
|
|
|
1749
1772
|
): Promise<ReturnType<action>> {
|
|
1750
1773
|
const { tokenIn, tokenOut, amountIn, minAmountOut, ...rest } = parameters
|
|
1751
1774
|
const call = sell.call({ tokenIn, tokenOut, amountIn, minAmountOut })
|
|
1752
|
-
return (await action(client, {
|
|
1775
|
+
return (await withExecutionError(action)(client, {
|
|
1753
1776
|
...rest,
|
|
1754
1777
|
...call,
|
|
1755
1778
|
} as never)) as never
|
|
@@ -1857,7 +1880,7 @@ export namespace sellSync {
|
|
|
1857
1880
|
}>
|
|
1858
1881
|
|
|
1859
1882
|
// TODO: exhaustive error type
|
|
1860
|
-
export type ErrorType = BaseErrorType
|
|
1883
|
+
export type ErrorType = Errors.ExecutionErrorType | BaseErrorType
|
|
1861
1884
|
}
|
|
1862
1885
|
|
|
1863
1886
|
/**
|
|
@@ -2236,7 +2259,7 @@ export namespace withdraw {
|
|
|
2236
2259
|
export type ReturnValue = WriteContractReturnType
|
|
2237
2260
|
|
|
2238
2261
|
// TODO: exhaustive error type
|
|
2239
|
-
export type ErrorType = BaseErrorType
|
|
2262
|
+
export type ErrorType = Errors.ExecutionErrorType | BaseErrorType
|
|
2240
2263
|
|
|
2241
2264
|
/** @internal */
|
|
2242
2265
|
export async function inner<
|
|
@@ -2250,7 +2273,7 @@ export namespace withdraw {
|
|
|
2250
2273
|
): Promise<ReturnType<action>> {
|
|
2251
2274
|
const { token, amount, ...rest } = parameters
|
|
2252
2275
|
const call = withdraw.call({ token, amount })
|
|
2253
|
-
return (await action(client, {
|
|
2276
|
+
return (await withExecutionError(action)(client, {
|
|
2254
2277
|
...rest,
|
|
2255
2278
|
...call,
|
|
2256
2279
|
} as never)) as never
|
|
@@ -2354,9 +2377,552 @@ export namespace withdrawSync {
|
|
|
2354
2377
|
}>
|
|
2355
2378
|
|
|
2356
2379
|
// TODO: exhaustive error type
|
|
2357
|
-
export type ErrorType = BaseErrorType
|
|
2380
|
+
export type ErrorType = Errors.ExecutionErrorType | BaseErrorType
|
|
2358
2381
|
}
|
|
2359
2382
|
|
|
2360
2383
|
function getPairKey(base: Address, quote: Address) {
|
|
2361
2384
|
return Hash.keccak256(Hex.concat(base, quote))
|
|
2362
2385
|
}
|
|
2386
|
+
|
|
2387
|
+
// Errors
|
|
2388
|
+
|
|
2389
|
+
/** Errors this module throws for decoded Tempo errors. Narrow with `error.name`. */
|
|
2390
|
+
export type ExecutionErrorType =
|
|
2391
|
+
| DexBelowMinimumOrderSizeErrorType
|
|
2392
|
+
| DexInsufficientBalanceErrorType
|
|
2393
|
+
| DexInsufficientLiquidityErrorType
|
|
2394
|
+
| DexInsufficientOutputErrorType
|
|
2395
|
+
| DexInvalidFlipTickErrorType
|
|
2396
|
+
| DexMaxInputExceededErrorType
|
|
2397
|
+
| DexOrderNotFoundErrorType
|
|
2398
|
+
| DexOrderNotStaleErrorType
|
|
2399
|
+
| DexPairNotFoundErrorType
|
|
2400
|
+
| DexTickOutOfBoundsErrorType
|
|
2401
|
+
|
|
2402
|
+
/** `DexInsufficientOutputError` with a literal `name`, for narrowing. */
|
|
2403
|
+
export type DexInsufficientOutputErrorType = DexInsufficientOutputError & {
|
|
2404
|
+
name: 'DexInsufficientOutputError'
|
|
2405
|
+
}
|
|
2406
|
+
|
|
2407
|
+
/** Thrown when a sell would return less than `minAmountOut`. */
|
|
2408
|
+
export class DexInsufficientOutputError extends TempoExecutionError<
|
|
2409
|
+
Errors.TempoExecutionError.Decoded<'InsufficientOutput'>
|
|
2410
|
+
> {
|
|
2411
|
+
/** Amount of `tokenIn` to sell. */
|
|
2412
|
+
amountIn: bigint | undefined
|
|
2413
|
+
/** Minimum amount of `tokenOut` to receive. */
|
|
2414
|
+
minAmountOut: bigint | undefined
|
|
2415
|
+
/** Current quote for `amountIn`, when available. */
|
|
2416
|
+
quote: bigint | undefined
|
|
2417
|
+
/** Token to sell. */
|
|
2418
|
+
tokenIn: Address | undefined
|
|
2419
|
+
/** Token to buy. */
|
|
2420
|
+
tokenOut: Address | undefined
|
|
2421
|
+
|
|
2422
|
+
constructor(parameters: DexInsufficientOutputError.Parameters) {
|
|
2423
|
+
const { amountIn, minAmountOut, quote, tokenIn, tokenOut } = parameters
|
|
2424
|
+
super(parameters, {
|
|
2425
|
+
details: {
|
|
2426
|
+
'token in': tokenIn,
|
|
2427
|
+
'token out': tokenOut,
|
|
2428
|
+
'amount in': amountIn,
|
|
2429
|
+
'min amount out': minAmountOut,
|
|
2430
|
+
quote,
|
|
2431
|
+
},
|
|
2432
|
+
name: 'DexInsufficientOutputError',
|
|
2433
|
+
})
|
|
2434
|
+
this.amountIn = amountIn
|
|
2435
|
+
this.minAmountOut = minAmountOut
|
|
2436
|
+
this.quote = quote
|
|
2437
|
+
this.tokenIn = tokenIn
|
|
2438
|
+
this.tokenOut = tokenOut
|
|
2439
|
+
}
|
|
2440
|
+
}
|
|
2441
|
+
|
|
2442
|
+
export declare namespace DexInsufficientOutputError {
|
|
2443
|
+
/** Constructor parameters. */
|
|
2444
|
+
type Parameters = Errors.TempoExecutionError.Parameters & {
|
|
2445
|
+
/** Amount of `tokenIn` to sell. */
|
|
2446
|
+
amountIn?: bigint | undefined
|
|
2447
|
+
/** Minimum amount of `tokenOut` to receive. */
|
|
2448
|
+
minAmountOut?: bigint | undefined
|
|
2449
|
+
/** Current quote for `amountIn`, when available. */
|
|
2450
|
+
quote?: bigint | undefined
|
|
2451
|
+
/** Token to sell. */
|
|
2452
|
+
tokenIn?: Address | undefined
|
|
2453
|
+
/** Token to buy. */
|
|
2454
|
+
tokenOut?: Address | undefined
|
|
2455
|
+
}
|
|
2456
|
+
}
|
|
2457
|
+
|
|
2458
|
+
/** `DexMaxInputExceededError` with a literal `name`, for narrowing. */
|
|
2459
|
+
export type DexMaxInputExceededErrorType = DexMaxInputExceededError & {
|
|
2460
|
+
name: 'DexMaxInputExceededError'
|
|
2461
|
+
}
|
|
2462
|
+
|
|
2463
|
+
/** Thrown when a buy would cost more than `maxAmountIn`. */
|
|
2464
|
+
export class DexMaxInputExceededError extends TempoExecutionError<
|
|
2465
|
+
Errors.TempoExecutionError.Decoded<'MaxInputExceeded'>
|
|
2466
|
+
> {
|
|
2467
|
+
/** Amount of `tokenOut` to buy. */
|
|
2468
|
+
amountOut: bigint | undefined
|
|
2469
|
+
/** Maximum amount of `tokenIn` to spend. */
|
|
2470
|
+
maxAmountIn: bigint | undefined
|
|
2471
|
+
/** Current cost of `amountOut`, when available. */
|
|
2472
|
+
quote: bigint | undefined
|
|
2473
|
+
/** Token to spend. */
|
|
2474
|
+
tokenIn: Address | undefined
|
|
2475
|
+
/** Token to buy. */
|
|
2476
|
+
tokenOut: Address | undefined
|
|
2477
|
+
|
|
2478
|
+
constructor(parameters: DexMaxInputExceededError.Parameters) {
|
|
2479
|
+
const { amountOut, maxAmountIn, quote, tokenIn, tokenOut } = parameters
|
|
2480
|
+
super(parameters, {
|
|
2481
|
+
details: {
|
|
2482
|
+
'token in': tokenIn,
|
|
2483
|
+
'token out': tokenOut,
|
|
2484
|
+
'amount out': amountOut,
|
|
2485
|
+
'max amount in': maxAmountIn,
|
|
2486
|
+
quote,
|
|
2487
|
+
},
|
|
2488
|
+
name: 'DexMaxInputExceededError',
|
|
2489
|
+
})
|
|
2490
|
+
this.amountOut = amountOut
|
|
2491
|
+
this.maxAmountIn = maxAmountIn
|
|
2492
|
+
this.quote = quote
|
|
2493
|
+
this.tokenIn = tokenIn
|
|
2494
|
+
this.tokenOut = tokenOut
|
|
2495
|
+
}
|
|
2496
|
+
}
|
|
2497
|
+
|
|
2498
|
+
export declare namespace DexMaxInputExceededError {
|
|
2499
|
+
/** Constructor parameters. */
|
|
2500
|
+
type Parameters = Errors.TempoExecutionError.Parameters & {
|
|
2501
|
+
/** Amount of `tokenOut` to buy. */
|
|
2502
|
+
amountOut?: bigint | undefined
|
|
2503
|
+
/** Maximum amount of `tokenIn` to spend. */
|
|
2504
|
+
maxAmountIn?: bigint | undefined
|
|
2505
|
+
/** Current cost of `amountOut`, when available. */
|
|
2506
|
+
quote?: bigint | undefined
|
|
2507
|
+
/** Token to spend. */
|
|
2508
|
+
tokenIn?: Address | undefined
|
|
2509
|
+
/** Token to buy. */
|
|
2510
|
+
tokenOut?: Address | undefined
|
|
2511
|
+
}
|
|
2512
|
+
}
|
|
2513
|
+
|
|
2514
|
+
/** `DexInsufficientLiquidityError` with a literal `name`, for narrowing. */
|
|
2515
|
+
export type DexInsufficientLiquidityErrorType =
|
|
2516
|
+
DexInsufficientLiquidityError & { name: 'DexInsufficientLiquidityError' }
|
|
2517
|
+
|
|
2518
|
+
/** Thrown when the order book cannot fill a swap. */
|
|
2519
|
+
export class DexInsufficientLiquidityError extends TempoExecutionError<
|
|
2520
|
+
Errors.TempoExecutionError.Decoded<'InsufficientLiquidity'>
|
|
2521
|
+
> {
|
|
2522
|
+
/** Amount of `tokenIn` to sell, for sells. */
|
|
2523
|
+
amountIn: bigint | undefined
|
|
2524
|
+
/** Amount of `tokenOut` to buy, for buys. */
|
|
2525
|
+
amountOut: bigint | undefined
|
|
2526
|
+
/** Token to spend. */
|
|
2527
|
+
tokenIn: Address | undefined
|
|
2528
|
+
/** Token to buy. */
|
|
2529
|
+
tokenOut: Address | undefined
|
|
2530
|
+
|
|
2531
|
+
constructor(
|
|
2532
|
+
parameters: Errors.TempoExecutionError.Parameters & {
|
|
2533
|
+
amountIn?: bigint | undefined
|
|
2534
|
+
amountOut?: bigint | undefined
|
|
2535
|
+
tokenIn?: Address | undefined
|
|
2536
|
+
tokenOut?: Address | undefined
|
|
2537
|
+
},
|
|
2538
|
+
) {
|
|
2539
|
+
const { amountIn, amountOut, tokenIn, tokenOut } = parameters
|
|
2540
|
+
super(parameters, {
|
|
2541
|
+
details: {
|
|
2542
|
+
'token in': tokenIn,
|
|
2543
|
+
'token out': tokenOut,
|
|
2544
|
+
'amount in': amountIn,
|
|
2545
|
+
'amount out': amountOut,
|
|
2546
|
+
},
|
|
2547
|
+
name: 'DexInsufficientLiquidityError',
|
|
2548
|
+
})
|
|
2549
|
+
this.amountIn = amountIn
|
|
2550
|
+
this.amountOut = amountOut
|
|
2551
|
+
this.tokenIn = tokenIn
|
|
2552
|
+
this.tokenOut = tokenOut
|
|
2553
|
+
}
|
|
2554
|
+
}
|
|
2555
|
+
|
|
2556
|
+
/** `DexBelowMinimumOrderSizeError` with a literal `name`, for narrowing. */
|
|
2557
|
+
export type DexBelowMinimumOrderSizeErrorType =
|
|
2558
|
+
DexBelowMinimumOrderSizeError & { name: 'DexBelowMinimumOrderSizeError' }
|
|
2559
|
+
|
|
2560
|
+
/** Thrown when an order is smaller than the minimum order size. */
|
|
2561
|
+
export class DexBelowMinimumOrderSizeError extends TempoExecutionError<
|
|
2562
|
+
Errors.TempoExecutionError.Decoded<'BelowMinimumOrderSize'>
|
|
2563
|
+
> {
|
|
2564
|
+
/** Order amount. */
|
|
2565
|
+
amount: bigint
|
|
2566
|
+
/** Minimum order amount, when known. */
|
|
2567
|
+
minimum: bigint | undefined
|
|
2568
|
+
|
|
2569
|
+
constructor(
|
|
2570
|
+
parameters: Errors.TempoExecutionError.Parameters & {
|
|
2571
|
+
minimum?: bigint | undefined
|
|
2572
|
+
},
|
|
2573
|
+
) {
|
|
2574
|
+
const [amount] = parameters.error.args as readonly [bigint]
|
|
2575
|
+
const { minimum } = parameters
|
|
2576
|
+
super(parameters, {
|
|
2577
|
+
details: { amount, minimum },
|
|
2578
|
+
name: 'DexBelowMinimumOrderSizeError',
|
|
2579
|
+
shortMessage: `Order amount ${amount} is below the minimum${minimum === undefined ? '' : ` of ${minimum}`}.`,
|
|
2580
|
+
})
|
|
2581
|
+
this.amount = amount
|
|
2582
|
+
this.minimum = minimum
|
|
2583
|
+
}
|
|
2584
|
+
}
|
|
2585
|
+
|
|
2586
|
+
/** `DexTickOutOfBoundsError` with a literal `name`, for narrowing. */
|
|
2587
|
+
export type DexTickOutOfBoundsErrorType = DexTickOutOfBoundsError & {
|
|
2588
|
+
name: 'DexTickOutOfBoundsError'
|
|
2589
|
+
}
|
|
2590
|
+
|
|
2591
|
+
/** Thrown when an order's tick or flip tick is outside the allowed range. */
|
|
2592
|
+
export class DexTickOutOfBoundsError extends TempoExecutionError<
|
|
2593
|
+
Errors.TempoExecutionError.Decoded<'TickOutOfBounds'>
|
|
2594
|
+
> {
|
|
2595
|
+
/** Highest allowed tick, when known. */
|
|
2596
|
+
maxTick: number | undefined
|
|
2597
|
+
/** Lowest allowed tick, when known. */
|
|
2598
|
+
minTick: number | undefined
|
|
2599
|
+
/** Tick that is out of range. */
|
|
2600
|
+
tick: number
|
|
2601
|
+
|
|
2602
|
+
constructor(
|
|
2603
|
+
parameters: Errors.TempoExecutionError.Parameters & {
|
|
2604
|
+
maxTick?: number | undefined
|
|
2605
|
+
minTick?: number | undefined
|
|
2606
|
+
},
|
|
2607
|
+
) {
|
|
2608
|
+
const [tick] = parameters.error.args as readonly [number]
|
|
2609
|
+
const { maxTick, minTick } = parameters
|
|
2610
|
+
super(parameters, {
|
|
2611
|
+
details: {
|
|
2612
|
+
tick,
|
|
2613
|
+
range:
|
|
2614
|
+
minTick === undefined || maxTick === undefined
|
|
2615
|
+
? undefined
|
|
2616
|
+
: `${minTick} to ${maxTick}`,
|
|
2617
|
+
},
|
|
2618
|
+
name: 'DexTickOutOfBoundsError',
|
|
2619
|
+
})
|
|
2620
|
+
this.maxTick = maxTick
|
|
2621
|
+
this.minTick = minTick
|
|
2622
|
+
this.tick = tick
|
|
2623
|
+
}
|
|
2624
|
+
}
|
|
2625
|
+
|
|
2626
|
+
/** `DexInvalidFlipTickError` with a literal `name`, for narrowing. */
|
|
2627
|
+
export type DexInvalidFlipTickErrorType = DexInvalidFlipTickError & {
|
|
2628
|
+
name: 'DexInvalidFlipTickError'
|
|
2629
|
+
}
|
|
2630
|
+
|
|
2631
|
+
/** Thrown when a flip order's flip tick is on the wrong side of its tick or off the tick spacing. */
|
|
2632
|
+
export class DexInvalidFlipTickError extends TempoExecutionError<
|
|
2633
|
+
Errors.TempoExecutionError.Decoded<'InvalidFlipTick'>
|
|
2634
|
+
> {
|
|
2635
|
+
/** Flip tick. */
|
|
2636
|
+
flipTick: number | undefined
|
|
2637
|
+
/** Order side. */
|
|
2638
|
+
side: 'buy' | 'sell' | undefined
|
|
2639
|
+
/** Order tick. */
|
|
2640
|
+
tick: number | undefined
|
|
2641
|
+
/** Tick spacing, when known. */
|
|
2642
|
+
tickSpacing: number | undefined
|
|
2643
|
+
|
|
2644
|
+
constructor(
|
|
2645
|
+
parameters: Errors.TempoExecutionError.Parameters & {
|
|
2646
|
+
flipTick?: number | undefined
|
|
2647
|
+
side?: 'buy' | 'sell' | undefined
|
|
2648
|
+
tick?: number | undefined
|
|
2649
|
+
tickSpacing?: number | undefined
|
|
2650
|
+
},
|
|
2651
|
+
) {
|
|
2652
|
+
const { flipTick, side, tick, tickSpacing } = parameters
|
|
2653
|
+
super(parameters, {
|
|
2654
|
+
details: {
|
|
2655
|
+
side,
|
|
2656
|
+
tick,
|
|
2657
|
+
'flip tick': flipTick,
|
|
2658
|
+
'tick spacing': tickSpacing,
|
|
2659
|
+
},
|
|
2660
|
+
name: 'DexInvalidFlipTickError',
|
|
2661
|
+
shortMessage:
|
|
2662
|
+
side === 'buy'
|
|
2663
|
+
? 'The flip tick of a buy order must be at or above its tick, and a multiple of the tick spacing.'
|
|
2664
|
+
: side === 'sell'
|
|
2665
|
+
? 'The flip tick of a sell order must be at or below its tick, and a multiple of the tick spacing.'
|
|
2666
|
+
: undefined,
|
|
2667
|
+
})
|
|
2668
|
+
this.flipTick = flipTick
|
|
2669
|
+
this.side = side
|
|
2670
|
+
this.tick = tick
|
|
2671
|
+
this.tickSpacing = tickSpacing
|
|
2672
|
+
}
|
|
2673
|
+
}
|
|
2674
|
+
|
|
2675
|
+
/** `DexOrderNotFoundError` with a literal `name`, for narrowing. */
|
|
2676
|
+
export type DexOrderNotFoundErrorType = DexOrderNotFoundError & {
|
|
2677
|
+
name: 'DexOrderNotFoundError'
|
|
2678
|
+
}
|
|
2679
|
+
|
|
2680
|
+
/** Thrown when an order does not exist or is already filled. */
|
|
2681
|
+
export class DexOrderNotFoundError extends TempoExecutionError<
|
|
2682
|
+
Errors.TempoExecutionError.Decoded<'OrderDoesNotExist'>
|
|
2683
|
+
> {
|
|
2684
|
+
/** Order ID. */
|
|
2685
|
+
orderId: bigint
|
|
2686
|
+
|
|
2687
|
+
constructor(
|
|
2688
|
+
parameters: Errors.TempoExecutionError.Parameters & { orderId: bigint },
|
|
2689
|
+
) {
|
|
2690
|
+
super(parameters, {
|
|
2691
|
+
details: { order: parameters.orderId },
|
|
2692
|
+
name: 'DexOrderNotFoundError',
|
|
2693
|
+
shortMessage: `Order ${parameters.orderId} does not exist or is already filled.`,
|
|
2694
|
+
})
|
|
2695
|
+
this.orderId = parameters.orderId
|
|
2696
|
+
}
|
|
2697
|
+
}
|
|
2698
|
+
|
|
2699
|
+
/** `DexOrderNotStaleError` with a literal `name`, for narrowing. */
|
|
2700
|
+
export type DexOrderNotStaleErrorType = DexOrderNotStaleError & {
|
|
2701
|
+
name: 'DexOrderNotStaleError'
|
|
2702
|
+
}
|
|
2703
|
+
|
|
2704
|
+
/** Thrown when cancelling a stale order whose maker is still authorized by the token's policy. */
|
|
2705
|
+
export class DexOrderNotStaleError extends TempoExecutionError<
|
|
2706
|
+
Errors.TempoExecutionError.Decoded<'OrderNotStale'>
|
|
2707
|
+
> {
|
|
2708
|
+
/** Order ID. */
|
|
2709
|
+
orderId: bigint
|
|
2710
|
+
|
|
2711
|
+
constructor(
|
|
2712
|
+
parameters: Errors.TempoExecutionError.Parameters & { orderId: bigint },
|
|
2713
|
+
) {
|
|
2714
|
+
super(parameters, {
|
|
2715
|
+
details: { order: parameters.orderId },
|
|
2716
|
+
name: 'DexOrderNotStaleError',
|
|
2717
|
+
shortMessage: `Order ${parameters.orderId} is not stale: its maker is still authorized.`,
|
|
2718
|
+
})
|
|
2719
|
+
this.orderId = parameters.orderId
|
|
2720
|
+
}
|
|
2721
|
+
}
|
|
2722
|
+
|
|
2723
|
+
/** `DexPairNotFoundError` with a literal `name`, for narrowing. */
|
|
2724
|
+
export type DexPairNotFoundErrorType = DexPairNotFoundError & {
|
|
2725
|
+
name: 'DexPairNotFoundError'
|
|
2726
|
+
}
|
|
2727
|
+
|
|
2728
|
+
/** Thrown when no trading pair exists for a token. */
|
|
2729
|
+
export class DexPairNotFoundError extends TempoExecutionError<
|
|
2730
|
+
Errors.TempoExecutionError.Decoded<'PairDoesNotExist'>
|
|
2731
|
+
> {
|
|
2732
|
+
/** Tokens of the call. */
|
|
2733
|
+
tokens: readonly Address[]
|
|
2734
|
+
|
|
2735
|
+
constructor(
|
|
2736
|
+
parameters: Errors.TempoExecutionError.Parameters & {
|
|
2737
|
+
tokens: readonly Address[]
|
|
2738
|
+
},
|
|
2739
|
+
) {
|
|
2740
|
+
super(parameters, {
|
|
2741
|
+
details: { tokens: parameters.tokens.join(', ') || undefined },
|
|
2742
|
+
name: 'DexPairNotFoundError',
|
|
2743
|
+
})
|
|
2744
|
+
this.tokens = parameters.tokens
|
|
2745
|
+
}
|
|
2746
|
+
}
|
|
2747
|
+
|
|
2748
|
+
/** `DexInsufficientBalanceError` with a literal `name`, for narrowing. */
|
|
2749
|
+
export type DexInsufficientBalanceErrorType = DexInsufficientBalanceError & {
|
|
2750
|
+
name: 'DexInsufficientBalanceError'
|
|
2751
|
+
}
|
|
2752
|
+
|
|
2753
|
+
/** Thrown when withdrawing more than the account's exchange balance. */
|
|
2754
|
+
export class DexInsufficientBalanceError extends TempoExecutionError<
|
|
2755
|
+
Errors.TempoExecutionError.Decoded<'InsufficientBalance'>
|
|
2756
|
+
> {
|
|
2757
|
+
/** Amount to withdraw. */
|
|
2758
|
+
amount: bigint | undefined
|
|
2759
|
+
/** Exchange balance, when known. */
|
|
2760
|
+
balance: bigint | undefined
|
|
2761
|
+
/** Token address. */
|
|
2762
|
+
token: Address
|
|
2763
|
+
|
|
2764
|
+
constructor(
|
|
2765
|
+
parameters: Errors.TempoExecutionError.Parameters & {
|
|
2766
|
+
amount?: bigint | undefined
|
|
2767
|
+
balance?: bigint | undefined
|
|
2768
|
+
token: Address
|
|
2769
|
+
},
|
|
2770
|
+
) {
|
|
2771
|
+
const { amount, balance, token } = parameters
|
|
2772
|
+
super(parameters, {
|
|
2773
|
+
details: { token, amount, balance },
|
|
2774
|
+
name: 'DexInsufficientBalanceError',
|
|
2775
|
+
shortMessage: `Insufficient exchange balance of token "${token}".`,
|
|
2776
|
+
})
|
|
2777
|
+
this.amount = amount
|
|
2778
|
+
this.balance = balance
|
|
2779
|
+
this.token = token
|
|
2780
|
+
}
|
|
2781
|
+
}
|
|
2782
|
+
|
|
2783
|
+
const exchange = {
|
|
2784
|
+
address: Addresses.stablecoinDex,
|
|
2785
|
+
abi: Abis.stablecoinDex,
|
|
2786
|
+
} as const
|
|
2787
|
+
|
|
2788
|
+
/** The failed call, when it targets the exchange. */
|
|
2789
|
+
function getExchangeCall(context: Context) {
|
|
2790
|
+
const { call } = context
|
|
2791
|
+
return call && isAddressEqual(call.address, Addresses.stablecoinDex)
|
|
2792
|
+
? call
|
|
2793
|
+
: undefined
|
|
2794
|
+
}
|
|
2795
|
+
|
|
2796
|
+
/** @internal */
|
|
2797
|
+
export const errorResolvers: Resolvers = {
|
|
2798
|
+
'BelowMinimumOrderSize(uint128)': async (context) => {
|
|
2799
|
+
if (!getExchangeCall(context) || !context.base.error.args) return undefined
|
|
2800
|
+
const [minimum] = await context.read([
|
|
2801
|
+
{ ...exchange, functionName: 'MIN_ORDER_AMOUNT' },
|
|
2802
|
+
])
|
|
2803
|
+
return new DexBelowMinimumOrderSizeError({
|
|
2804
|
+
...context.base,
|
|
2805
|
+
minimum: minimum?.result,
|
|
2806
|
+
})
|
|
2807
|
+
},
|
|
2808
|
+
'InsufficientBalance()': async (context) => {
|
|
2809
|
+
const call = getExchangeCall(context)
|
|
2810
|
+
const token = call?.arg<Address>('token')
|
|
2811
|
+
if (call?.functionName !== 'withdraw' || !token || !context.signer)
|
|
2812
|
+
return undefined
|
|
2813
|
+
const [balance] = await context.read([
|
|
2814
|
+
{
|
|
2815
|
+
...exchange,
|
|
2816
|
+
functionName: 'balanceOf',
|
|
2817
|
+
args: [context.signer.address, token],
|
|
2818
|
+
},
|
|
2819
|
+
])
|
|
2820
|
+
return new DexInsufficientBalanceError({
|
|
2821
|
+
...context.base,
|
|
2822
|
+
amount: call.arg<bigint>('amount'),
|
|
2823
|
+
balance: balance?.result,
|
|
2824
|
+
token,
|
|
2825
|
+
})
|
|
2826
|
+
},
|
|
2827
|
+
'InsufficientLiquidity()': (context) => {
|
|
2828
|
+
const call = getExchangeCall(context)
|
|
2829
|
+
if (!call) return undefined
|
|
2830
|
+
return new DexInsufficientLiquidityError({
|
|
2831
|
+
...context.base,
|
|
2832
|
+
amountIn: call.arg<bigint>('amountIn'),
|
|
2833
|
+
amountOut: call.arg<bigint>('amountOut'),
|
|
2834
|
+
tokenIn: call.arg<Address>('tokenIn'),
|
|
2835
|
+
tokenOut: call.arg<Address>('tokenOut'),
|
|
2836
|
+
})
|
|
2837
|
+
},
|
|
2838
|
+
'InsufficientOutput()': async (context) => {
|
|
2839
|
+
const call = getExchangeCall(context)
|
|
2840
|
+
if (!call) return undefined
|
|
2841
|
+
const tokenIn = call.arg<Address>('tokenIn')!
|
|
2842
|
+
const tokenOut = call.arg<Address>('tokenOut')!
|
|
2843
|
+
const amountIn = call.arg<bigint>('amountIn')!
|
|
2844
|
+
const [quote] = await context.read([
|
|
2845
|
+
{
|
|
2846
|
+
...exchange,
|
|
2847
|
+
functionName: 'quoteSwapExactAmountIn',
|
|
2848
|
+
args: [tokenIn, tokenOut, amountIn],
|
|
2849
|
+
},
|
|
2850
|
+
])
|
|
2851
|
+
return new DexInsufficientOutputError({
|
|
2852
|
+
...context.base,
|
|
2853
|
+
amountIn,
|
|
2854
|
+
minAmountOut: call.arg<bigint>('minAmountOut'),
|
|
2855
|
+
quote: quote?.result,
|
|
2856
|
+
tokenIn,
|
|
2857
|
+
tokenOut,
|
|
2858
|
+
})
|
|
2859
|
+
},
|
|
2860
|
+
'InvalidFlipTick()': async (context) => {
|
|
2861
|
+
const call = getExchangeCall(context)
|
|
2862
|
+
if (!call) return undefined
|
|
2863
|
+
const [tickSpacing] = await context.read([
|
|
2864
|
+
{ ...exchange, functionName: 'TICK_SPACING' },
|
|
2865
|
+
])
|
|
2866
|
+
const isBid = call.arg<boolean>('isBid')
|
|
2867
|
+
return new DexInvalidFlipTickError({
|
|
2868
|
+
...context.base,
|
|
2869
|
+
flipTick: call.arg<number>('flipTick'),
|
|
2870
|
+
side: isBid === undefined ? undefined : isBid ? 'buy' : 'sell',
|
|
2871
|
+
tick: call.arg<number>('tick'),
|
|
2872
|
+
tickSpacing: tickSpacing?.result,
|
|
2873
|
+
})
|
|
2874
|
+
},
|
|
2875
|
+
'MaxInputExceeded()': async (context) => {
|
|
2876
|
+
const call = getExchangeCall(context)
|
|
2877
|
+
if (!call) return undefined
|
|
2878
|
+
const tokenIn = call.arg<Address>('tokenIn')!
|
|
2879
|
+
const tokenOut = call.arg<Address>('tokenOut')!
|
|
2880
|
+
const amountOut = call.arg<bigint>('amountOut')!
|
|
2881
|
+
const [quote] = await context.read([
|
|
2882
|
+
{
|
|
2883
|
+
...exchange,
|
|
2884
|
+
functionName: 'quoteSwapExactAmountOut',
|
|
2885
|
+
args: [tokenIn, tokenOut, amountOut],
|
|
2886
|
+
},
|
|
2887
|
+
])
|
|
2888
|
+
return new DexMaxInputExceededError({
|
|
2889
|
+
...context.base,
|
|
2890
|
+
amountOut,
|
|
2891
|
+
maxAmountIn: call.arg<bigint>('maxAmountIn'),
|
|
2892
|
+
quote: quote?.result,
|
|
2893
|
+
tokenIn,
|
|
2894
|
+
tokenOut,
|
|
2895
|
+
})
|
|
2896
|
+
},
|
|
2897
|
+
'OrderDoesNotExist()': (context) => {
|
|
2898
|
+
const orderId = getExchangeCall(context)?.arg<bigint>('orderId')
|
|
2899
|
+
if (orderId === undefined) return undefined
|
|
2900
|
+
return new DexOrderNotFoundError({ ...context.base, orderId })
|
|
2901
|
+
},
|
|
2902
|
+
'OrderNotStale()': (context) => {
|
|
2903
|
+
const orderId = getExchangeCall(context)?.arg<bigint>('orderId')
|
|
2904
|
+
if (orderId === undefined) return undefined
|
|
2905
|
+
return new DexOrderNotStaleError({ ...context.base, orderId })
|
|
2906
|
+
},
|
|
2907
|
+
'PairDoesNotExist()': (context) => {
|
|
2908
|
+
const call = getExchangeCall(context)
|
|
2909
|
+
if (!call) return undefined
|
|
2910
|
+
const tokens = ['token', 'tokenIn', 'tokenOut', 'base'].flatMap((name) => {
|
|
2911
|
+
const token = call.arg<Address>(name)
|
|
2912
|
+
return token ? [token] : []
|
|
2913
|
+
})
|
|
2914
|
+
return new DexPairNotFoundError({ ...context.base, tokens })
|
|
2915
|
+
},
|
|
2916
|
+
'TickOutOfBounds(int16)': async (context) => {
|
|
2917
|
+
if (!getExchangeCall(context) || !context.base.error.args) return undefined
|
|
2918
|
+
const [minTick, maxTick] = await context.read([
|
|
2919
|
+
{ ...exchange, functionName: 'MIN_TICK' },
|
|
2920
|
+
{ ...exchange, functionName: 'MAX_TICK' },
|
|
2921
|
+
])
|
|
2922
|
+
return new DexTickOutOfBoundsError({
|
|
2923
|
+
...context.base,
|
|
2924
|
+
maxTick: maxTick?.result,
|
|
2925
|
+
minTick: minTick?.result,
|
|
2926
|
+
})
|
|
2927
|
+
},
|
|
2928
|
+
}
|