tempo.ts 0.0.0 → 0.0.1

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.
Files changed (153) hide show
  1. package/README.md +92 -0
  2. package/dist/chains.d.ts +1477 -0
  3. package/dist/chains.d.ts.map +1 -0
  4. package/dist/chains.js +43 -0
  5. package/dist/chains.js.map +1 -0
  6. package/dist/index.d.ts +2 -0
  7. package/dist/index.d.ts.map +1 -0
  8. package/dist/index.js +2 -0
  9. package/dist/index.js.map +1 -0
  10. package/dist/internal/types.d.ts +284 -0
  11. package/dist/internal/types.d.ts.map +1 -0
  12. package/dist/internal/types.js +2 -0
  13. package/dist/internal/types.js.map +1 -0
  14. package/dist/ox/TokenId.d.ts +18 -0
  15. package/dist/ox/TokenId.d.ts.map +1 -0
  16. package/dist/ox/TokenId.js +29 -0
  17. package/dist/ox/TokenId.js.map +1 -0
  18. package/dist/ox/TokenRole.d.ts +11 -0
  19. package/dist/ox/TokenRole.d.ts.map +1 -0
  20. package/dist/ox/TokenRole.js +22 -0
  21. package/dist/ox/TokenRole.js.map +1 -0
  22. package/dist/ox/Transaction.d.ts +161 -0
  23. package/dist/ox/Transaction.d.ts.map +1 -0
  24. package/dist/ox/Transaction.js +117 -0
  25. package/dist/ox/Transaction.js.map +1 -0
  26. package/dist/ox/TransactionEnvelopeFeeToken.d.ts +393 -0
  27. package/dist/ox/TransactionEnvelopeFeeToken.d.ts.map +1 -0
  28. package/dist/ox/TransactionEnvelopeFeeToken.js +452 -0
  29. package/dist/ox/TransactionEnvelopeFeeToken.js.map +1 -0
  30. package/dist/ox/TransactionRequest.d.ts +62 -0
  31. package/dist/ox/TransactionRequest.d.ts.map +1 -0
  32. package/dist/ox/TransactionRequest.js +66 -0
  33. package/dist/ox/TransactionRequest.js.map +1 -0
  34. package/dist/ox/index.d.ts +5 -0
  35. package/dist/ox/index.d.ts.map +1 -0
  36. package/dist/ox/index.js +5 -0
  37. package/dist/ox/index.js.map +1 -0
  38. package/dist/prool/Instance.d.ts +92 -0
  39. package/dist/prool/Instance.d.ts.map +1 -0
  40. package/dist/prool/Instance.js +96 -0
  41. package/dist/prool/Instance.js.map +1 -0
  42. package/dist/prool/index.d.ts +2 -0
  43. package/dist/prool/index.d.ts.map +1 -0
  44. package/dist/prool/index.js +2 -0
  45. package/dist/prool/index.js.map +1 -0
  46. package/dist/viem/abis.d.ts +2058 -0
  47. package/dist/viem/abis.d.ts.map +1 -0
  48. package/dist/viem/abis.js +1599 -0
  49. package/dist/viem/abis.js.map +1 -0
  50. package/dist/viem/actions/amm.d.ts +2091 -0
  51. package/dist/viem/actions/amm.d.ts.map +1 -0
  52. package/dist/viem/actions/amm.js +876 -0
  53. package/dist/viem/actions/amm.js.map +1 -0
  54. package/dist/viem/actions/fee.d.ts +727 -0
  55. package/dist/viem/actions/fee.d.ts.map +1 -0
  56. package/dist/viem/actions/fee.js +230 -0
  57. package/dist/viem/actions/fee.js.map +1 -0
  58. package/dist/viem/actions/index.d.ts +5 -0
  59. package/dist/viem/actions/index.d.ts.map +1 -0
  60. package/dist/viem/actions/index.js +5 -0
  61. package/dist/viem/actions/index.js.map +1 -0
  62. package/dist/viem/actions/policy.d.ts +1900 -0
  63. package/dist/viem/actions/policy.d.ts.map +1 -0
  64. package/dist/viem/actions/policy.js +841 -0
  65. package/dist/viem/actions/policy.js.map +1 -0
  66. package/dist/viem/actions/token.d.ts +13759 -0
  67. package/dist/viem/actions/token.d.ts.map +1 -0
  68. package/dist/viem/actions/token.js +2579 -0
  69. package/dist/viem/actions/token.js.map +1 -0
  70. package/dist/viem/addresses.d.ts +8 -0
  71. package/dist/viem/addresses.d.ts.map +1 -0
  72. package/dist/viem/addresses.js +8 -0
  73. package/dist/viem/addresses.js.map +1 -0
  74. package/dist/viem/chain.d.ts +341 -0
  75. package/dist/viem/chain.d.ts.map +1 -0
  76. package/dist/viem/chain.js +22 -0
  77. package/dist/viem/chain.js.map +1 -0
  78. package/dist/viem/client.d.ts +27 -0
  79. package/dist/viem/client.d.ts.map +1 -0
  80. package/dist/viem/client.js +28 -0
  81. package/dist/viem/client.js.map +1 -0
  82. package/dist/viem/decorator.d.ts +1636 -0
  83. package/dist/viem/decorator.d.ts.map +1 -0
  84. package/dist/viem/decorator.js +95 -0
  85. package/dist/viem/decorator.js.map +1 -0
  86. package/dist/viem/formatters.d.ts +4 -0
  87. package/dist/viem/formatters.d.ts.map +1 -0
  88. package/dist/viem/formatters.js +69 -0
  89. package/dist/viem/formatters.js.map +1 -0
  90. package/dist/viem/index.d.ts +9 -0
  91. package/dist/viem/index.d.ts.map +1 -0
  92. package/dist/viem/index.js +9 -0
  93. package/dist/viem/index.js.map +1 -0
  94. package/dist/viem/transaction.d.ts +54 -0
  95. package/dist/viem/transaction.d.ts.map +1 -0
  96. package/dist/viem/transaction.js +108 -0
  97. package/dist/viem/transaction.js.map +1 -0
  98. package/dist/viem/transport.d.ts +16 -0
  99. package/dist/viem/transport.d.ts.map +1 -0
  100. package/dist/viem/transport.js +33 -0
  101. package/dist/viem/transport.js.map +1 -0
  102. package/dist/viem/types.d.ts +10 -0
  103. package/dist/viem/types.d.ts.map +1 -0
  104. package/dist/viem/types.js +2 -0
  105. package/dist/viem/types.js.map +1 -0
  106. package/dist/viem/utils.d.ts +8 -0
  107. package/dist/viem/utils.d.ts.map +1 -0
  108. package/dist/viem/utils.js +9 -0
  109. package/dist/viem/utils.js.map +1 -0
  110. package/package.json +100 -2
  111. package/src/chains.ts +46 -0
  112. package/src/index.ts +1 -0
  113. package/src/internal/types.ts +414 -0
  114. package/src/ox/TokenId.test.ts +29 -0
  115. package/src/ox/TokenId.ts +35 -0
  116. package/src/ox/TokenRole.test.ts +20 -0
  117. package/src/ox/TokenRole.ts +27 -0
  118. package/src/ox/Transaction.test.ts +257 -0
  119. package/src/ox/Transaction.ts +247 -0
  120. package/src/ox/TransactionEnvelopeFeeToken.test.ts +1215 -0
  121. package/src/ox/TransactionEnvelopeFeeToken.ts +717 -0
  122. package/src/ox/TransactionRequest.ts +100 -0
  123. package/src/ox/index.ts +4 -0
  124. package/src/prool/Instance.test.ts +43 -0
  125. package/src/prool/Instance.ts +190 -0
  126. package/src/prool/index.ts +1 -0
  127. package/src/prool/internal/chain.json +106 -0
  128. package/src/prool/internal/consensus.toml +32 -0
  129. package/src/viem/abis.ts +1606 -0
  130. package/src/viem/actions/amm.test.ts +425 -0
  131. package/src/viem/actions/amm.ts +1308 -0
  132. package/src/viem/actions/fee.test.ts +281 -0
  133. package/src/viem/actions/fee.ts +362 -0
  134. package/src/viem/actions/index.ts +4 -0
  135. package/src/viem/actions/policy.test.ts +514 -0
  136. package/src/viem/actions/policy.ts +1284 -0
  137. package/src/viem/actions/token.test.ts +2172 -0
  138. package/src/viem/actions/token.ts +3830 -0
  139. package/src/viem/addresses.ts +10 -0
  140. package/src/viem/chain.ts +27 -0
  141. package/src/viem/client.bench-d.ts +8 -0
  142. package/src/viem/client.test.ts +152 -0
  143. package/src/viem/client.ts +91 -0
  144. package/src/viem/decorator.bench-d.ts +11 -0
  145. package/src/viem/decorator.test.ts +35 -0
  146. package/src/viem/decorator.ts +1914 -0
  147. package/src/viem/e2e.test.ts +410 -0
  148. package/src/viem/formatters.ts +100 -0
  149. package/src/viem/index.ts +8 -0
  150. package/src/viem/transaction.ts +253 -0
  151. package/src/viem/transport.ts +47 -0
  152. package/src/viem/types.ts +55 -0
  153. package/src/viem/utils.ts +37 -0
package/package.json CHANGED
@@ -1,4 +1,102 @@
1
1
  {
2
- "name": "tempo.ts",
3
- "version": "0.0.0"
2
+ "name": "tempo.ts",
3
+ "type": "module",
4
+ "version": "0.0.1",
5
+ "scripts": {
6
+ "build": "zshy --project ./tsconfig.build.json",
7
+ "changeset:publish": "bun run build && changeset publish",
8
+ "changeset:version": "changeset version && bun run check",
9
+ "check": "biome check . --write --unsafe",
10
+ "check:types": "tsc -b",
11
+ "gen:abis": "forge build --config-path ./contracts/specs/foundry.toml && bun scripts/gen:abis.ts && bun run check",
12
+ "test": "vitest",
13
+ "test:install": "cd test/tempo && cargo install --path bin/tempo"
14
+ },
15
+ "zshy": {
16
+ "exports": {
17
+ ".": "./src/index.ts",
18
+ "./chains": "./src/chains.ts",
19
+ "./ox": "./src/ox/index.ts",
20
+ "./prool": "./src/prool/index.ts",
21
+ "./viem": "./src/viem/index.ts",
22
+ "./viem/actions": "./src/viem/actions/index.ts"
23
+ },
24
+ "cjs": false,
25
+ "conditions": {
26
+ "src": "src"
27
+ }
28
+ },
29
+ "dependencies": {
30
+ "ox": "~0.9.9"
31
+ },
32
+ "peerDependencies": {
33
+ "prool": "^0",
34
+ "viem": ">=2.38"
35
+ },
36
+ "peerDependenciesMeta": {
37
+ "prool": {
38
+ "optional": true
39
+ },
40
+ "viem": {
41
+ "optional": true
42
+ }
43
+ },
44
+ "author": "jxom <j@wevm.dev>",
45
+ "license": "MIT",
46
+ "devDependencies": {
47
+ "@ark/attest": "^0.49.0",
48
+ "@biomejs/biome": "^2.2.4",
49
+ "@changesets/changelog-github": "^0.5.0",
50
+ "@changesets/cli": "^2.27.7",
51
+ "@elysiajs/node": "^1.4.1",
52
+ "@types/bun": "latest",
53
+ "elysia": "latest",
54
+ "prool": "latest",
55
+ "simple-git-hooks": "^2.13.1",
56
+ "typescript": "^5.9.2",
57
+ "viem": "^2.38.0",
58
+ "vitest": "^3.2.4",
59
+ "zshy": "^0.4.2"
60
+ },
61
+ "files": [
62
+ "dist",
63
+ "src"
64
+ ],
65
+ "module": "./dist/index.js",
66
+ "types": "./dist/index.d.ts",
67
+ "exports": {
68
+ ".": {
69
+ "src": "./src/index.ts",
70
+ "types": "./dist/index.d.ts",
71
+ "import": "./dist/index.js"
72
+ },
73
+ "./chains": {
74
+ "src": "./src/chains.ts",
75
+ "types": "./dist/chains.d.ts",
76
+ "import": "./dist/chains.js"
77
+ },
78
+ "./ox": {
79
+ "src": "./src/ox/index.ts",
80
+ "types": "./dist/ox/index.d.ts",
81
+ "import": "./dist/ox/index.js"
82
+ },
83
+ "./prool": {
84
+ "src": "./src/prool/index.ts",
85
+ "types": "./dist/prool/index.d.ts",
86
+ "import": "./dist/prool/index.js"
87
+ },
88
+ "./viem": {
89
+ "src": "./src/viem/index.ts",
90
+ "types": "./dist/viem/index.d.ts",
91
+ "import": "./dist/viem/index.js"
92
+ },
93
+ "./viem/actions": {
94
+ "src": "./src/viem/actions/index.ts",
95
+ "types": "./dist/viem/actions/index.d.ts",
96
+ "import": "./dist/viem/actions/index.js"
97
+ }
98
+ },
99
+ "simple-git-hooks": {
100
+ "pre-commit": "bun run check"
101
+ }
4
102
  }
package/src/chains.ts ADDED
@@ -0,0 +1,46 @@
1
+ import { defineChain } from 'viem'
2
+ import { chainConfig } from './viem/chain.js'
3
+
4
+ export const tempoAdagietto = /*#__PURE__*/ defineChain({
5
+ ...chainConfig,
6
+ id: 1337,
7
+ name: 'Tempo',
8
+ nativeCurrency: {
9
+ name: 'USD',
10
+ symbol: 'USD',
11
+ decimals: 18,
12
+ },
13
+ rpcUrls: {
14
+ default: { http: ['https://rpc-adagietto.tempoxyz.dev'] },
15
+ },
16
+ })
17
+
18
+ export const tempoLento = /*#__PURE__*/ defineChain({
19
+ ...chainConfig,
20
+ id: 4246,
21
+ name: 'Tempo',
22
+ nativeCurrency: {
23
+ name: 'USD',
24
+ symbol: 'USD',
25
+ decimals: 18,
26
+ },
27
+ rpcUrls: {
28
+ default: { http: ['https://rpc-lento.tempoxyz.dev'] },
29
+ },
30
+ })
31
+
32
+ export const tempoLocal = /*#__PURE__*/ defineChain({
33
+ ...chainConfig,
34
+ id: 1337,
35
+ name: 'Tempo',
36
+ nativeCurrency: {
37
+ name: 'USD',
38
+ symbol: 'USD',
39
+ decimals: 18,
40
+ },
41
+ rpcUrls: {
42
+ default: { http: ['http://localhost:8545'] },
43
+ },
44
+ })
45
+
46
+ export const tempo = /*#__PURE__*/ defineChain(tempoLento)
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export {}
@@ -0,0 +1,414 @@
1
+ /** Combines members of an intersection into a readable type. */
2
+ // https://twitter.com/mattpocockuk/status/1622730173446557697?s=20&t=NdpAcmEFXY01xkqU3KO0Mg
3
+ export type Compute<type> = { [key in keyof type]: type[key] } & unknown
4
+
5
+ declare const symbol: unique symbol
6
+
7
+ /**
8
+ * Creates a branded type of `T` with the brand `U`.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * type Result = Branded<string, 'foo'>
13
+ * // ^? type Result = string & { [symbol]: 'foo' }
14
+ * ```
15
+ */
16
+ export type Branded<T, U> = T & { [symbol]: U }
17
+
18
+ /**
19
+ * Filters out all members of `T` that are not `P`
20
+ *
21
+ * @example
22
+ * ```ts
23
+ * type Result = Filter<['a', 'b', 'c'], 'b'>
24
+ * // ^? type Result = ['a', 'c']
25
+ * ```
26
+ *
27
+ * @internal
28
+ */
29
+ export type Filter<
30
+ T extends readonly unknown[],
31
+ P,
32
+ Acc extends readonly unknown[] = [],
33
+ > = T extends readonly [infer F, ...infer Rest extends readonly unknown[]]
34
+ ? [F] extends [P]
35
+ ? Filter<Rest, P, [...Acc, F]>
36
+ : Filter<Rest, P, Acc>
37
+ : readonly [...Acc]
38
+
39
+ /**
40
+ * Checks if `T` can be narrowed further than `U`
41
+ *
42
+ * @example
43
+ * ```ts
44
+ * type Result = IsNarrowable<'foo', string>
45
+ * // ^? true
46
+ * ```
47
+ */
48
+ export type IsNarrowable<T, U> = IsNever<
49
+ (T extends U ? true : false) & (U extends T ? false : true)
50
+ > extends true
51
+ ? false
52
+ : true
53
+
54
+ /**
55
+ * Checks if `T` is `never`
56
+ *
57
+ * @example
58
+ * ```ts
59
+ * type Result = IsNever<never>
60
+ * // ^? type Result = true
61
+ * ```
62
+ */
63
+ export type IsNever<T> = [T] extends [never] ? true : false
64
+
65
+ /**
66
+ * Removes `readonly` from all properties of an object.
67
+ *
68
+ * @internal
69
+ */
70
+ export type Mutable<type extends object> = {
71
+ -readonly [key in keyof type]: type[key]
72
+ }
73
+
74
+ /**
75
+ * Evaluates boolean "or" condition for `T` properties.
76
+ *
77
+ * * @example
78
+ * ```ts
79
+ * type Result = Or<[false, true, false]>
80
+ * // ^? type Result = true
81
+ * ```
82
+ *
83
+ * @example
84
+ * ```ts
85
+ * type Result = Or<[false, false, false]>
86
+ * // ^? type Result = false
87
+ * ```
88
+ *
89
+ * @internal
90
+ */
91
+ export type Or<T extends readonly unknown[]> = T extends readonly [
92
+ infer Head,
93
+ ...infer Tail,
94
+ ]
95
+ ? Head extends true
96
+ ? true
97
+ : Or<Tail>
98
+ : false
99
+
100
+ /**
101
+ * Checks if `T` is `undefined`
102
+ *
103
+ * @example
104
+ * ```ts
105
+ * type Result = IsUndefined<undefined>
106
+ * // ^? type Result = true
107
+ * ```
108
+ *
109
+ * @internal
110
+ */
111
+ export type IsUndefined<T> = [undefined] extends [T] ? true : false
112
+
113
+ /**
114
+ * Checks if type `T` is the `unknown` type.
115
+ *
116
+ * @internal
117
+ */
118
+ export type IsUnknown<T> = unknown extends T
119
+ ? [T] extends [null]
120
+ ? false
121
+ : true
122
+ : false
123
+
124
+ /** @internal */
125
+ export type MaybePromise<T> = T | Promise<T>
126
+
127
+ /**
128
+ * Makes attributes on the type T required if required is true.
129
+ *
130
+ * @example
131
+ * ```ts
132
+ * MaybeRequired<{ a: string, b?: number }, true>
133
+ * // { a: string, b: number }
134
+ *
135
+ * MaybeRequired<{ a: string, b?: number }, false>
136
+ * // { a: string, b?: number }
137
+ * ```
138
+ *
139
+ * @internal
140
+ */
141
+ export type MaybeRequired<T, required extends boolean> = required extends true
142
+ ? ExactRequired<T>
143
+ : T
144
+
145
+ /**
146
+ * Assigns the properties of U onto T.
147
+ *
148
+ * @example
149
+ * ```ts
150
+ * Assign<{ a: string, b: number }, { a: undefined, c: boolean }>
151
+ * // { a: undefined, b: number, c: boolean }
152
+ * ```
153
+ *
154
+ * @internal
155
+ */
156
+ export type Assign<T, U> = Assign_inner<T, U> & U
157
+
158
+ /** @internal */
159
+ export type Assign_inner<T, U> = {
160
+ [K in keyof T as K extends keyof U
161
+ ? U[K] extends void
162
+ ? never
163
+ : K
164
+ : K]: K extends keyof U ? U[K] : T[K]
165
+ }
166
+
167
+ /**
168
+ * Constructs a type by excluding `undefined` from `T`.
169
+ *
170
+ * @example
171
+ * ```ts
172
+ * NoUndefined<string | undefined>
173
+ * // string
174
+ * ```
175
+ *
176
+ * @internal
177
+ */
178
+ export type NoUndefined<T> = T extends undefined ? never : T
179
+
180
+ /**
181
+ * Strict version of built-in Omit type
182
+ *
183
+ * @internal
184
+ */
185
+ export type Omit<type, keys extends keyof type> = Pick<
186
+ type,
187
+ Exclude<keyof type, keys>
188
+ >
189
+
190
+ /**
191
+ * Creates a type that is a partial of T, but with the required keys K.
192
+ *
193
+ * @example
194
+ * ```ts
195
+ * PartialBy<{ a: string, b: number }, 'a'>
196
+ * // { a?: string, b: number }
197
+ * ```
198
+ *
199
+ * @internal
200
+ */
201
+ export type PartialBy<T, K extends keyof T> = Omit<T, K> &
202
+ ExactPartial<Pick<T, K>>
203
+
204
+ export type RecursiveArray<T> = T | readonly RecursiveArray<T>[]
205
+
206
+ /**
207
+ * Creates a type that is T with the required keys K.
208
+ *
209
+ * @example
210
+ * ```ts
211
+ * RequiredBy<{ a?: string, b: number }, 'a'>
212
+ * // { a: string, b: number }
213
+ * ```
214
+ *
215
+ * @internal
216
+ */
217
+ export type RequiredBy<T, K extends keyof T> = Omit<T, K> &
218
+ ExactRequired<Pick<T, K>>
219
+
220
+ /**
221
+ * Returns truthy if `array` contains `value`.
222
+ *
223
+ * @example
224
+ * ```ts
225
+ * Some<[1, 2, 3], 2>
226
+ * // true
227
+ * ```
228
+ *
229
+ * @internal
230
+ */
231
+ export type Some<
232
+ array extends readonly unknown[],
233
+ value,
234
+ > = array extends readonly [value, ...unknown[]]
235
+ ? true
236
+ : array extends readonly [unknown, ...infer rest]
237
+ ? Some<rest, value>
238
+ : false
239
+
240
+ /**
241
+ * Prints custom error message
242
+ *
243
+ * @param messages - Error message
244
+ * @returns Custom error message
245
+ *
246
+ * @example
247
+ * ```ts
248
+ * type Result = TypeErrorMessage<'Custom error message'>
249
+ * // ^? type Result = ['Error: Custom error message']
250
+ * ```
251
+ */
252
+ export type TypeErrorMessage<messages extends string | string[]> =
253
+ messages extends string
254
+ ? [
255
+ // Surrounding with array to prevent `messages` from being widened to `string`
256
+ `Error: ${messages}`,
257
+ ]
258
+ : {
259
+ [key in keyof messages]: messages[key] extends infer message extends
260
+ string
261
+ ? `Error: ${message}`
262
+ : never
263
+ }
264
+
265
+ /** @internal */
266
+ export type UnionToTuple<
267
+ union,
268
+ ///
269
+ last = LastInUnion<union>,
270
+ > = [union] extends [never] ? [] : [...UnionToTuple<Exclude<union, last>>, last]
271
+
272
+ /** @internal */
273
+ export type LastInUnion<U> = UnionToIntersection<
274
+ U extends unknown ? (x: U) => 0 : never
275
+ > extends (x: infer l) => 0
276
+ ? l
277
+ : never
278
+
279
+ /** @internal */
280
+ export type UnionToIntersection<union> = (
281
+ union extends unknown
282
+ ? (arg: union) => 0
283
+ : never
284
+ ) extends (arg: infer i) => 0
285
+ ? i
286
+ : never
287
+
288
+ /** @internal */
289
+ export type IsUnion<
290
+ union,
291
+ ///
292
+ union2 = union,
293
+ > = union extends union2 ? ([union2] extends [union] ? false : true) : never
294
+
295
+ /** @internal */
296
+ export type MaybePartial<
297
+ type,
298
+ enabled extends boolean | undefined,
299
+ > = enabled extends true ? Compute<ExactPartial<type>> : type
300
+
301
+ export type ExactPartial<type> = {
302
+ [key in keyof type]?: type[key] | undefined
303
+ }
304
+
305
+ /** @internal */
306
+ export type ExactRequired<type> = {
307
+ [key in keyof type]-?: Exclude<type[key], undefined>
308
+ }
309
+
310
+ export type OneOf<
311
+ union extends object,
312
+ fallback extends object | undefined = undefined,
313
+ ///
314
+ keys extends KeyofUnion<union> = KeyofUnion<union>,
315
+ > = union extends infer item
316
+ ? Compute<
317
+ item & {
318
+ [key in Exclude<keys, keyof item>]?: fallback extends object
319
+ ? key extends keyof fallback
320
+ ? fallback[key]
321
+ : undefined
322
+ : undefined
323
+ }
324
+ >
325
+ : never
326
+
327
+ /** @internal */
328
+ export type KeyofUnion<type> = type extends type ? keyof type : never
329
+
330
+ /** @internal */
331
+ export type Undefined<type> = {
332
+ [key in keyof type]?: undefined
333
+ }
334
+
335
+ ///////////////////////////////////////////////////////////////////////////
336
+ // Loose types
337
+
338
+ /**
339
+ * Loose version of {@link Omit}
340
+ * @internal
341
+ */
342
+ export type LooseOmit<type, keys extends string> = Pick<
343
+ type,
344
+ Exclude<keyof type, keys>
345
+ >
346
+
347
+ ///////////////////////////////////////////////////////////////////////////
348
+ // Union types
349
+
350
+ /** @internal */
351
+ export type UnionCompute<type> = type extends object ? Compute<type> : type
352
+
353
+ /** @internal */
354
+ export type UnionLooseOmit<type, keys extends string> = type extends any
355
+ ? LooseOmit<type, keys>
356
+ : never
357
+
358
+ /**
359
+ * Construct a type with the properties of union type T except for those in type K.
360
+ * @example
361
+ * ```ts
362
+ * type Result = UnionOmit<{ a: string, b: number } | { a: string, b: undefined, c: number }, 'a'>
363
+ * // { b: number } | { b: undefined, c: number }
364
+ * ```
365
+ *
366
+ * @internal
367
+ */
368
+ export type UnionOmit<type, keys extends keyof type> = type extends any
369
+ ? Omit<type, keys>
370
+ : never
371
+
372
+ /**
373
+ * Construct a type with the properties of union type T except for those in type K.
374
+ * @example
375
+ * ```ts
376
+ * type Result = UnionOmit<{ a: string, b: number } | { a: string, b: undefined, c: number }, 'a'>
377
+ * // { b: number } | { b: undefined, c: number }
378
+ * ```
379
+ *
380
+ * @internal
381
+ */
382
+ export type UnionPick<type, keys extends keyof type> = type extends any
383
+ ? Pick<type, keys>
384
+ : never
385
+
386
+ /**
387
+ * Creates a type that is a partial of T, but with the required keys K.
388
+ *
389
+ * @example
390
+ * ```ts
391
+ * PartialBy<{ a: string, b: number } | { a: string, b: undefined, c: number }, 'a'>
392
+ * // { a?: string, b: number } | { a?: string, b: undefined, c: number }
393
+ * ```
394
+ *
395
+ * @internal
396
+ */
397
+ export type UnionPartialBy<T, K extends keyof T> = T extends any
398
+ ? PartialBy<T, K>
399
+ : never
400
+
401
+ /**
402
+ * Creates a type that is T with the required keys K.
403
+ *
404
+ * @example
405
+ * ```ts
406
+ * RequiredBy<{ a?: string, b: number } | { a?: string, c?: number }, 'a'>
407
+ * // { a: string, b: number } | { a: string, c?: number }
408
+ * ```
409
+ *
410
+ * @internal
411
+ */
412
+ export type UnionRequiredBy<T, K extends keyof T> = T extends any
413
+ ? RequiredBy<T, K>
414
+ : never
@@ -0,0 +1,29 @@
1
+ import { TokenId } from 'tempo.ts/ox'
2
+ import { expect, test } from 'vitest'
3
+
4
+ test('fromAddress', () => {
5
+ expect(
6
+ TokenId.fromAddress('0x20c0000000000000000000000000000000000000'),
7
+ ).toBe(0n)
8
+ expect(
9
+ TokenId.fromAddress('0x20c0000000000000000000000000000000000001'),
10
+ ).toBe(1n)
11
+ expect(
12
+ TokenId.fromAddress('0x20c0000000000000000000000000000000000def'),
13
+ ).toBe(0xdefn)
14
+ })
15
+
16
+ test('toAddress', () => {
17
+ expect(TokenId.toAddress(0n)).toBe(
18
+ '0x20c0000000000000000000000000000000000000',
19
+ )
20
+ expect(TokenId.toAddress('0x20c0000000000000000000000000000000000000')).toBe(
21
+ '0x20c0000000000000000000000000000000000000',
22
+ )
23
+ expect(TokenId.toAddress(1n)).toBe(
24
+ '0x20c0000000000000000000000000000000000001',
25
+ )
26
+ expect(TokenId.toAddress(0xdefn)).toBe(
27
+ '0x20c0000000000000000000000000000000000def',
28
+ )
29
+ })
@@ -0,0 +1,35 @@
1
+ import * as Address from 'ox/Address'
2
+ import * as Hex from 'ox/Hex'
3
+
4
+ const tip20Prefix = '0x20c0'
5
+
6
+ export type TokenId = bigint
7
+ export type TokenIdOrAddress = TokenId | Address.Address
8
+
9
+ /**
10
+ * Converts a TIP20 token address to a token ID.
11
+ *
12
+ * @param address - The token address.
13
+ * @returns The token ID.
14
+ */
15
+ export function fromAddress(address: Address.Address): TokenId {
16
+ if (!address.toLowerCase().startsWith(tip20Prefix))
17
+ throw new Error('invalid tip20 address.')
18
+ return Hex.toBigInt(Hex.slice(address, tip20Prefix.length))
19
+ }
20
+
21
+ /**
22
+ * Converts a TIP20 token ID to an address.
23
+ *
24
+ * @param tokenId - The token ID.
25
+ * @returns The address.
26
+ */
27
+ export function toAddress(tokenId: TokenIdOrAddress): Address.Address {
28
+ if (typeof tokenId === 'string') {
29
+ Address.assert(tokenId)
30
+ return tokenId
31
+ }
32
+
33
+ const tokenIdHex = Hex.fromNumber(tokenId, { size: 18 })
34
+ return Hex.concat(tip20Prefix, tokenIdHex)
35
+ }
@@ -0,0 +1,20 @@
1
+ import { Hash, Hex } from 'ox'
2
+ import { TokenRole } from 'tempo.ts/ox'
3
+ import { expect, test } from 'vitest'
4
+
5
+ test('serialize', () => {
6
+ TokenRole.roles.forEach((role) => {
7
+ if (role === 'defaultAdmin')
8
+ expect(TokenRole.serialize(role)).toBe(
9
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
10
+ )
11
+ else
12
+ expect(TokenRole.serialize(role)).toBe(
13
+ Hash.keccak256(Hex.fromString(TokenRole.toPreHashed[role])),
14
+ )
15
+ })
16
+
17
+ expect(TokenRole.serialize('ARBITRARY_ROLE')).toBe(
18
+ '0x1288a906030fe58348e9da8c4847d9d03a41eabb4999a3d64d7c0a7fb8b15c5c',
19
+ )
20
+ })
@@ -0,0 +1,27 @@
1
+ import * as Hash from 'ox/Hash'
2
+ import * as Hex from 'ox/Hex'
3
+
4
+ export const roles = [
5
+ 'defaultAdmin',
6
+ 'pause',
7
+ 'unpause',
8
+ 'issuer',
9
+ 'burnBlocked',
10
+ ] as const
11
+ export type TokenRole = (typeof roles)[number] | (string & {})
12
+
13
+ export const toPreHashed = {
14
+ defaultAdmin: 'DEFAULT_ADMIN_ROLE',
15
+ pause: 'PAUSE_ROLE',
16
+ unpause: 'UNPAUSE_ROLE',
17
+ issuer: 'ISSUER_ROLE',
18
+ burnBlocked: 'BURN_BLOCKED_ROLE',
19
+ } as const satisfies Record<TokenRole, string>
20
+
21
+ export function serialize(role: TokenRole) {
22
+ if (role === 'defaultAdmin')
23
+ return '0x0000000000000000000000000000000000000000000000000000000000000000'
24
+ return Hash.keccak256(
25
+ Hex.fromString(toPreHashed[role as keyof typeof toPreHashed] ?? role),
26
+ )
27
+ }