sushi 6.4.5 → 6.4.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.
Files changed (275) hide show
  1. package/_cjs/evm/config/simple-constants.js +2 -2
  2. package/_cjs/evm/config/simple-constants.js.map +1 -1
  3. package/_cjs/evm/currency/currency.js +1 -1
  4. package/_cjs/evm/currency/currency.js.map +1 -1
  5. package/_cjs/evm/currency/token.js +2 -1
  6. package/_cjs/evm/currency/token.js.map +1 -1
  7. package/_cjs/evm/utils/index.js +1 -0
  8. package/_cjs/evm/utils/index.js.map +1 -1
  9. package/_cjs/evm/utils/normalize-address.js +7 -0
  10. package/_cjs/evm/utils/normalize-address.js.map +1 -0
  11. package/_cjs/generic/utils/assert-never.js +8 -0
  12. package/_cjs/generic/utils/assert-never.js.map +1 -0
  13. package/_cjs/generic/utils/id.js +9 -10
  14. package/_cjs/generic/utils/id.js.map +1 -1
  15. package/_cjs/generic/utils/index.js +3 -0
  16. package/_cjs/generic/utils/index.js.map +1 -1
  17. package/_cjs/generic/utils/native-address.js +38 -0
  18. package/_cjs/generic/utils/native-address.js.map +1 -0
  19. package/_cjs/generic/utils/normalize-address.js +38 -0
  20. package/_cjs/generic/utils/normalize-address.js.map +1 -0
  21. package/_cjs/kvm/config/index.js +18 -0
  22. package/_cjs/kvm/config/index.js.map +1 -0
  23. package/_cjs/kvm/config/simple-constants.js +5 -0
  24. package/_cjs/kvm/config/simple-constants.js.map +1 -0
  25. package/_cjs/kvm/index.js +2 -0
  26. package/_cjs/kvm/index.js.map +1 -1
  27. package/_cjs/kvm/utils/index.js +18 -0
  28. package/_cjs/kvm/utils/index.js.map +1 -0
  29. package/_cjs/kvm/utils/normalize-address.js +7 -0
  30. package/_cjs/kvm/utils/normalize-address.js.map +1 -0
  31. package/_cjs/mvm/config/index.js +18 -0
  32. package/_cjs/mvm/config/index.js.map +1 -0
  33. package/_cjs/mvm/config/simple-constants.js +5 -0
  34. package/_cjs/mvm/config/simple-constants.js.map +1 -0
  35. package/_cjs/mvm/currency/token.js +2 -1
  36. package/_cjs/mvm/currency/token.js.map +1 -1
  37. package/_cjs/mvm/index.js +2 -0
  38. package/_cjs/mvm/index.js.map +1 -1
  39. package/_cjs/mvm/utils/index.js +18 -0
  40. package/_cjs/mvm/utils/index.js.map +1 -0
  41. package/_cjs/mvm/utils/normalize-address.js +7 -0
  42. package/_cjs/mvm/utils/normalize-address.js.map +1 -0
  43. package/_cjs/stellar/address.js +8 -0
  44. package/_cjs/stellar/address.js.map +1 -0
  45. package/_cjs/stellar/config/index.js +18 -0
  46. package/_cjs/stellar/config/index.js.map +1 -0
  47. package/_cjs/stellar/config/simple-constants.js +5 -0
  48. package/_cjs/stellar/config/simple-constants.js.map +1 -0
  49. package/_cjs/stellar/index.js +3 -0
  50. package/_cjs/stellar/index.js.map +1 -1
  51. package/_cjs/stellar/utils/index.js +18 -0
  52. package/_cjs/stellar/utils/index.js.map +1 -0
  53. package/_cjs/stellar/utils/normalize-address.js +7 -0
  54. package/_cjs/stellar/utils/normalize-address.js.map +1 -0
  55. package/_cjs/svm/currency/token.js +3 -2
  56. package/_cjs/svm/currency/token.js.map +1 -1
  57. package/_cjs/svm/index.js +1 -0
  58. package/_cjs/svm/index.js.map +1 -1
  59. package/_cjs/svm/types/id.js +3 -0
  60. package/_cjs/svm/types/id.js.map +1 -0
  61. package/_cjs/svm/utils/index.js +18 -0
  62. package/_cjs/svm/utils/index.js.map +1 -0
  63. package/_cjs/svm/utils/normalize-address.js +7 -0
  64. package/_cjs/svm/utils/normalize-address.js.map +1 -0
  65. package/_cjs/tvm/config/index.js +1 -0
  66. package/_cjs/tvm/config/index.js.map +1 -1
  67. package/_cjs/tvm/config/simple-constants.js +5 -0
  68. package/_cjs/tvm/config/simple-constants.js.map +1 -0
  69. package/_cjs/tvm/currency/token.js +2 -1
  70. package/_cjs/tvm/currency/token.js.map +1 -1
  71. package/_cjs/tvm/index.js +1 -0
  72. package/_cjs/tvm/index.js.map +1 -1
  73. package/_cjs/tvm/utils/index.js +18 -0
  74. package/_cjs/tvm/utils/index.js.map +1 -0
  75. package/_cjs/tvm/utils/normalize-address.js +7 -0
  76. package/_cjs/tvm/utils/normalize-address.js.map +1 -0
  77. package/_esm/evm/config/simple-constants.js +1 -1
  78. package/_esm/evm/config/simple-constants.js.map +1 -1
  79. package/_esm/evm/currency/currency.js +2 -2
  80. package/_esm/evm/currency/currency.js.map +1 -1
  81. package/_esm/evm/currency/token.js +2 -1
  82. package/_esm/evm/currency/token.js.map +1 -1
  83. package/_esm/evm/utils/index.js +1 -0
  84. package/_esm/evm/utils/index.js.map +1 -1
  85. package/_esm/evm/utils/normalize-address.js +4 -0
  86. package/_esm/evm/utils/normalize-address.js.map +1 -0
  87. package/_esm/generic/utils/assert-never.js +5 -0
  88. package/_esm/generic/utils/assert-never.js.map +1 -0
  89. package/_esm/generic/utils/id.js +9 -11
  90. package/_esm/generic/utils/id.js.map +1 -1
  91. package/_esm/generic/utils/index.js +3 -0
  92. package/_esm/generic/utils/index.js.map +1 -1
  93. package/_esm/generic/utils/native-address.js +35 -0
  94. package/_esm/generic/utils/native-address.js.map +1 -0
  95. package/_esm/generic/utils/normalize-address.js +35 -0
  96. package/_esm/generic/utils/normalize-address.js.map +1 -0
  97. package/_esm/kvm/config/index.js +2 -0
  98. package/_esm/kvm/config/index.js.map +1 -0
  99. package/_esm/kvm/config/simple-constants.js +2 -0
  100. package/_esm/kvm/config/simple-constants.js.map +1 -0
  101. package/_esm/kvm/index.js +2 -0
  102. package/_esm/kvm/index.js.map +1 -1
  103. package/_esm/kvm/utils/index.js +2 -0
  104. package/_esm/kvm/utils/index.js.map +1 -0
  105. package/_esm/kvm/utils/normalize-address.js +4 -0
  106. package/_esm/kvm/utils/normalize-address.js.map +1 -0
  107. package/_esm/mvm/config/index.js +2 -0
  108. package/_esm/mvm/config/index.js.map +1 -0
  109. package/_esm/mvm/config/simple-constants.js +2 -0
  110. package/_esm/mvm/config/simple-constants.js.map +1 -0
  111. package/_esm/mvm/currency/token.js +2 -1
  112. package/_esm/mvm/currency/token.js.map +1 -1
  113. package/_esm/mvm/index.js +2 -0
  114. package/_esm/mvm/index.js.map +1 -1
  115. package/_esm/mvm/utils/index.js +2 -0
  116. package/_esm/mvm/utils/index.js.map +1 -0
  117. package/_esm/mvm/utils/normalize-address.js +4 -0
  118. package/_esm/mvm/utils/normalize-address.js.map +1 -0
  119. package/_esm/stellar/address.js +5 -0
  120. package/_esm/stellar/address.js.map +1 -0
  121. package/_esm/stellar/config/index.js +2 -0
  122. package/_esm/stellar/config/index.js.map +1 -0
  123. package/_esm/stellar/config/simple-constants.js +2 -0
  124. package/_esm/stellar/config/simple-constants.js.map +1 -0
  125. package/_esm/stellar/index.js +3 -0
  126. package/_esm/stellar/index.js.map +1 -1
  127. package/_esm/stellar/utils/index.js +2 -0
  128. package/_esm/stellar/utils/index.js.map +1 -0
  129. package/_esm/stellar/utils/normalize-address.js +4 -0
  130. package/_esm/stellar/utils/normalize-address.js.map +1 -0
  131. package/_esm/svm/currency/token.js +3 -2
  132. package/_esm/svm/currency/token.js.map +1 -1
  133. package/_esm/svm/index.js +1 -0
  134. package/_esm/svm/index.js.map +1 -1
  135. package/_esm/svm/types/id.js +2 -0
  136. package/_esm/svm/types/id.js.map +1 -0
  137. package/_esm/svm/utils/index.js +2 -0
  138. package/_esm/svm/utils/index.js.map +1 -0
  139. package/_esm/svm/utils/normalize-address.js +4 -0
  140. package/_esm/svm/utils/normalize-address.js.map +1 -0
  141. package/_esm/tvm/config/index.js +1 -0
  142. package/_esm/tvm/config/index.js.map +1 -1
  143. package/_esm/tvm/config/simple-constants.js +2 -0
  144. package/_esm/tvm/config/simple-constants.js.map +1 -0
  145. package/_esm/tvm/currency/token.js +2 -1
  146. package/_esm/tvm/currency/token.js.map +1 -1
  147. package/_esm/tvm/index.js +1 -0
  148. package/_esm/tvm/index.js.map +1 -1
  149. package/_esm/tvm/utils/index.js +2 -0
  150. package/_esm/tvm/utils/index.js.map +1 -0
  151. package/_esm/tvm/utils/normalize-address.js +4 -0
  152. package/_esm/tvm/utils/normalize-address.js.map +1 -0
  153. package/_types/evm/config/simple-constants.d.ts +1 -1
  154. package/_types/evm/config/simple-constants.d.ts.map +1 -1
  155. package/_types/evm/currency/native.d.ts +1 -1
  156. package/_types/evm/currency/native.d.ts.map +1 -1
  157. package/_types/evm/currency/token.d.ts.map +1 -1
  158. package/_types/evm/utils/index.d.ts +1 -0
  159. package/_types/evm/utils/index.d.ts.map +1 -1
  160. package/_types/evm/utils/normalize-address.d.ts +3 -0
  161. package/_types/evm/utils/normalize-address.d.ts.map +1 -0
  162. package/_types/generic/types/for-chain.d.ts +17 -5
  163. package/_types/generic/types/for-chain.d.ts.map +1 -1
  164. package/_types/generic/utils/assert-never.d.ts +2 -0
  165. package/_types/generic/utils/assert-never.d.ts.map +1 -0
  166. package/_types/generic/utils/id.d.ts +3 -2
  167. package/_types/generic/utils/id.d.ts.map +1 -1
  168. package/_types/generic/utils/index.d.ts +3 -0
  169. package/_types/generic/utils/index.d.ts.map +1 -1
  170. package/_types/generic/utils/native-address.d.ts +4 -0
  171. package/_types/generic/utils/native-address.d.ts.map +1 -0
  172. package/_types/generic/utils/normalize-address.d.ts +4 -0
  173. package/_types/generic/utils/normalize-address.d.ts.map +1 -0
  174. package/_types/kvm/config/index.d.ts +2 -0
  175. package/_types/kvm/config/index.d.ts.map +1 -0
  176. package/_types/kvm/config/simple-constants.d.ts +3 -0
  177. package/_types/kvm/config/simple-constants.d.ts.map +1 -0
  178. package/_types/kvm/index.d.ts +2 -0
  179. package/_types/kvm/index.d.ts.map +1 -1
  180. package/_types/kvm/utils/index.d.ts +2 -0
  181. package/_types/kvm/utils/index.d.ts.map +1 -0
  182. package/_types/kvm/utils/normalize-address.d.ts +3 -0
  183. package/_types/kvm/utils/normalize-address.d.ts.map +1 -0
  184. package/_types/mvm/config/index.d.ts +2 -0
  185. package/_types/mvm/config/index.d.ts.map +1 -0
  186. package/_types/mvm/config/simple-constants.d.ts +3 -0
  187. package/_types/mvm/config/simple-constants.d.ts.map +1 -0
  188. package/_types/mvm/currency/token.d.ts.map +1 -1
  189. package/_types/mvm/index.d.ts +2 -0
  190. package/_types/mvm/index.d.ts.map +1 -1
  191. package/_types/mvm/utils/index.d.ts +2 -0
  192. package/_types/mvm/utils/index.d.ts.map +1 -0
  193. package/_types/mvm/utils/normalize-address.d.ts +3 -0
  194. package/_types/mvm/utils/normalize-address.d.ts.map +1 -0
  195. package/_types/stellar/address.d.ts +3 -0
  196. package/_types/stellar/address.d.ts.map +1 -0
  197. package/_types/stellar/config/index.d.ts +2 -0
  198. package/_types/stellar/config/index.d.ts.map +1 -0
  199. package/_types/stellar/config/simple-constants.d.ts +2 -0
  200. package/_types/stellar/config/simple-constants.d.ts.map +1 -0
  201. package/_types/stellar/index.d.ts +3 -0
  202. package/_types/stellar/index.d.ts.map +1 -1
  203. package/_types/stellar/utils/index.d.ts +2 -0
  204. package/_types/stellar/utils/index.d.ts.map +1 -0
  205. package/_types/stellar/utils/normalize-address.d.ts +3 -0
  206. package/_types/stellar/utils/normalize-address.d.ts.map +1 -0
  207. package/_types/svm/currency/native.d.ts +1 -1
  208. package/_types/svm/currency/native.d.ts.map +1 -1
  209. package/_types/svm/currency/token.d.ts +1 -1
  210. package/_types/svm/currency/token.d.ts.map +1 -1
  211. package/_types/svm/index.d.ts +1 -0
  212. package/_types/svm/index.d.ts.map +1 -1
  213. package/_types/svm/types/id.d.ts +5 -0
  214. package/_types/svm/types/id.d.ts.map +1 -0
  215. package/_types/svm/utils/index.d.ts +2 -0
  216. package/_types/svm/utils/index.d.ts.map +1 -0
  217. package/_types/svm/utils/normalize-address.d.ts +3 -0
  218. package/_types/svm/utils/normalize-address.d.ts.map +1 -0
  219. package/_types/tvm/config/index.d.ts +1 -0
  220. package/_types/tvm/config/index.d.ts.map +1 -1
  221. package/_types/tvm/config/simple-constants.d.ts +3 -0
  222. package/_types/tvm/config/simple-constants.d.ts.map +1 -0
  223. package/_types/tvm/currency/native.d.ts +1 -1
  224. package/_types/tvm/currency/native.d.ts.map +1 -1
  225. package/_types/tvm/currency/token.d.ts.map +1 -1
  226. package/_types/tvm/index.d.ts +1 -0
  227. package/_types/tvm/index.d.ts.map +1 -1
  228. package/_types/tvm/utils/index.d.ts +2 -0
  229. package/_types/tvm/utils/index.d.ts.map +1 -0
  230. package/_types/tvm/utils/normalize-address.d.ts +3 -0
  231. package/_types/tvm/utils/normalize-address.d.ts.map +1 -0
  232. package/evm/config/simple-constants.ts +1 -1
  233. package/evm/currency/currency.ts +2 -2
  234. package/evm/currency/native.ts +1 -1
  235. package/evm/currency/token.ts +2 -1
  236. package/evm/utils/index.ts +1 -0
  237. package/evm/utils/normalize-address.ts +5 -0
  238. package/generic/types/for-chain.ts +51 -11
  239. package/generic/utils/assert-never.ts +4 -0
  240. package/generic/utils/id.test.ts +13 -0
  241. package/generic/utils/id.ts +15 -16
  242. package/generic/utils/index.ts +3 -0
  243. package/generic/utils/native-address.ts +45 -0
  244. package/generic/utils/normalize-address.ts +64 -0
  245. package/kvm/config/index.ts +1 -0
  246. package/kvm/config/simple-constants.ts +3 -0
  247. package/kvm/index.ts +2 -0
  248. package/kvm/utils/index.ts +1 -0
  249. package/kvm/utils/normalize-address.ts +5 -0
  250. package/mvm/config/index.ts +1 -0
  251. package/mvm/config/simple-constants.ts +3 -0
  252. package/mvm/currency/token.ts +2 -1
  253. package/mvm/index.ts +2 -0
  254. package/mvm/utils/index.ts +1 -0
  255. package/mvm/utils/normalize-address.ts +5 -0
  256. package/package.json +1 -1
  257. package/stellar/address.ts +7 -0
  258. package/stellar/config/index.ts +1 -0
  259. package/stellar/config/simple-constants.ts +2 -0
  260. package/stellar/index.ts +3 -0
  261. package/stellar/utils/index.ts +1 -0
  262. package/stellar/utils/normalize-address.ts +7 -0
  263. package/svm/currency/native.ts +1 -1
  264. package/svm/currency/token.ts +3 -1
  265. package/svm/index.ts +1 -0
  266. package/svm/types/id.ts +9 -0
  267. package/svm/utils/index.ts +1 -0
  268. package/svm/utils/normalize-address.ts +5 -0
  269. package/tvm/config/index.ts +1 -0
  270. package/tvm/config/simple-constants.ts +3 -0
  271. package/tvm/currency/native.ts +1 -1
  272. package/tvm/currency/token.ts +2 -1
  273. package/tvm/index.ts +1 -0
  274. package/tvm/utils/index.ts +1 -0
  275. package/tvm/utils/normalize-address.ts +5 -0
@@ -0,0 +1,2 @@
1
+ export * from './normalize-address.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../tvm/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAA"}
@@ -0,0 +1,3 @@
1
+ import type { TvmAddress } from '../currency/token.js';
2
+ export declare function normalizeTvmAddress(address: TvmAddress): TvmAddress;
3
+ //# sourceMappingURL=normalize-address.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"normalize-address.d.ts","sourceRoot":"","sources":["../../../tvm/utils/normalize-address.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAEtD,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,UAAU,GAAG,UAAU,CAEnE"}
@@ -1,4 +1,4 @@
1
- export const nativeAddress = '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee'
1
+ export const evmNativeAddress = '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee'
2
2
 
3
3
  export const API_BASE_URL = 'https://api.sushi.com'
4
4
 
@@ -1,6 +1,6 @@
1
1
  import * as z from 'zod'
2
2
  import type { CurrencyMetadata } from '../../generic/currency/currency.js'
3
- import { nativeAddress } from '../config/simple-constants.js'
3
+ import { evmNativeAddress } from '../config/simple-constants.js'
4
4
  import { type EvmNative, serializedEvmNativeSchema } from './native.js'
5
5
  import { type EvmToken, serializedEvmTokenSchema } from './token.js'
6
6
 
@@ -23,7 +23,7 @@ export const serializedEvmCurrencySchema = <
23
23
  * @returns The address of the currency. If the currency is native, returns the native address constant.
24
24
  */
25
25
  export function getEvmCurrencyAddress(currency: EvmCurrency) {
26
- return currency.type === 'native' ? nativeAddress : currency.address
26
+ return currency.type === 'native' ? evmNativeAddress : currency.address
27
27
  }
28
28
 
29
29
  export type SerializedEvmCurrency<
@@ -1,5 +1,5 @@
1
1
  import * as z from 'zod'
2
- import type { CurrencyMetadata } from '~/generic/currency/currency.js'
2
+ import type { CurrencyMetadata } from '../../generic/currency/currency.js'
3
3
  import { Native } from '../../generic/currency/native.js'
4
4
  import {
5
5
  type EvmChainId,
@@ -4,6 +4,7 @@ import * as z from 'zod'
4
4
  import type { CurrencyMetadata } from '../../generic/currency/currency.js'
5
5
  import { Token } from '../../generic/currency/token.js'
6
6
  import { type EvmChainId, isEvmChainId } from '../chain/chains.js'
7
+ import { normalizeEvmAddress } from '../utils/normalize-address.js'
7
8
 
8
9
  export type EvmAddress = Address
9
10
 
@@ -32,7 +33,7 @@ export class EvmToken<
32
33
  } & ConstructorParameters<
33
34
  typeof Token<EvmChainId, EvmAddress, TMetadata>
34
35
  >[0]) {
35
- super({ address: address.toLowerCase() as EvmAddress, ...rest })
36
+ super({ address: normalizeEvmAddress(address), ...rest })
36
37
  this.origin = origin
37
38
  }
38
39
 
@@ -1,2 +1,3 @@
1
1
  export * from './add-gas-margin.js'
2
2
  export * from './get-create-2-address.js'
3
+ export * from './normalize-address.js'
@@ -0,0 +1,5 @@
1
+ import type { EvmAddress } from '../currency/token.js'
2
+
3
+ export function normalizeEvmAddress(address: EvmAddress): EvmAddress {
4
+ return address.toLowerCase() as EvmAddress
5
+ }
@@ -1,32 +1,72 @@
1
- import type { EvmCurrency } from '~/evm/currency/currency.js'
2
- import type { SvmCurrency } from '~/svm/currency/currency.js'
3
1
  import type { EvmChainId } from '../../evm/chain/chains.js'
2
+ import type { EvmCurrency } from '../../evm/currency/currency.js'
4
3
  import type { EvmAddress, EvmToken } from '../../evm/currency/token.js'
4
+ import type { EvmID } from '../../evm/types/id.js'
5
+ import type { KvmChainId } from '../../kvm/chain/chains.js'
6
+ import type { KvmToken, KvmTokenAddress } from '../../kvm/currency/token.js'
7
+ import type { MvmChainId } from '../../mvm/chain/chains.js'
8
+ import type { MvmAddress, MvmToken } from '../../mvm/currency/token.js'
9
+ import type { StellarAddress } from '../../stellar/address.js'
10
+ import type { StellarChainId } from '../../stellar/chain/chains.js'
5
11
  import type { SvmChainId } from '../../svm/chain/chains.js'
12
+ import type { SvmCurrency } from '../../svm/currency/currency.js'
6
13
  import type { SvmAddress, SvmToken } from '../../svm/currency/token.js'
14
+ import type { SvmID } from '../../svm/types/id.js'
15
+ import type { TvmChainId } from '../../tvm/chain/chains.js'
16
+ import type { TvmCurrency } from '../../tvm/currency/currency.js'
17
+ import type { TvmAddress, TvmToken } from '../../tvm/currency/token.js'
7
18
  import type { ChainId } from '../chain/chains.js'
8
19
  import type { CurrencyMetadata } from '../currency/currency.js'
9
20
 
10
21
  export type TokenFor<
11
- TChainId extends EvmChainId | SvmChainId,
22
+ TChainId extends Exclude<ChainId, StellarChainId>,
12
23
  Metadata extends CurrencyMetadata = CurrencyMetadata,
13
24
  > = TChainId extends EvmChainId
14
25
  ? EvmToken<Metadata>
15
- : TChainId extends SvmChainId
16
- ? SvmToken<Metadata>
17
- : never
26
+ : TChainId extends MvmChainId
27
+ ? MvmToken<Metadata>
28
+ : TChainId extends TvmChainId
29
+ ? TvmToken<Metadata>
30
+ : TChainId extends KvmChainId
31
+ ? KvmToken<Metadata>
32
+ : TChainId extends SvmChainId
33
+ ? SvmToken<Metadata>
34
+ : never
18
35
 
19
36
  export type CurrencyFor<
20
- TChainId extends EvmChainId | SvmChainId,
37
+ TChainId extends Exclude<ChainId, StellarChainId>,
21
38
  Metadata extends CurrencyMetadata = CurrencyMetadata,
22
39
  > = TChainId extends EvmChainId
23
40
  ? EvmCurrency<Metadata>
24
- : TChainId extends SvmChainId
25
- ? SvmCurrency<Metadata>
26
- : never
41
+ : TChainId extends MvmChainId
42
+ ? MvmToken<Metadata>
43
+ : TChainId extends KvmChainId
44
+ ? KvmToken<Metadata>
45
+ : TChainId extends TvmChainId
46
+ ? TvmCurrency<Metadata>
47
+ : TChainId extends SvmChainId
48
+ ? SvmCurrency<Metadata>
49
+ : never
27
50
 
28
51
  export type AddressFor<TChainId extends ChainId> = TChainId extends EvmChainId
29
52
  ? EvmAddress
53
+ : TChainId extends MvmChainId
54
+ ? MvmAddress
55
+ : TChainId extends TvmChainId
56
+ ? TvmAddress
57
+ : TChainId extends KvmChainId
58
+ ? KvmTokenAddress
59
+ : TChainId extends SvmChainId
60
+ ? SvmAddress
61
+ : TChainId extends StellarChainId
62
+ ? StellarAddress
63
+ : never
64
+
65
+ export type IDFor<
66
+ TChainId extends EvmChainId | SvmChainId,
67
+ TIncludeNative extends boolean = false,
68
+ > = TChainId extends EvmChainId
69
+ ? EvmID<TIncludeNative>
30
70
  : TChainId extends SvmChainId
31
- ? SvmAddress
71
+ ? SvmID<TIncludeNative>
32
72
  : never
@@ -0,0 +1,4 @@
1
+ export function assertNever(value: never, message = 'Unexpected value'): never {
2
+ void value
3
+ throw new Error(message)
4
+ }
@@ -0,0 +1,13 @@
1
+ import { describe, expect, it } from 'vitest'
2
+ import { getChainIdAddressFromId } from './id.js'
3
+
4
+ describe('getChainIdAddressFromId', () => {
5
+ it('parses MVM addresses containing colons', () => {
6
+ const id = '-1:0x1::module::token'
7
+
8
+ expect(getChainIdAddressFromId(id)).toEqual({
9
+ chainId: -1,
10
+ address: '0x1::module::token',
11
+ })
12
+ })
13
+ })
@@ -1,8 +1,8 @@
1
- import { nativeAddress } from '../../evm/config/simple-constants.js'
2
- import { isKvmTokenAddress } from '../../kvm/currency/token.js'
3
- import { isSvmAddress } from '../../svm/currency/token.js'
4
1
  import type { ChainId } from '../chain/chains.js'
2
+ import type { AddressFor } from '../types/for-chain.js'
5
3
  import type { ID } from '../types/id.js'
4
+ import { getNativeAddress } from './native-address.js'
5
+ import { normalizeAddress } from './normalize-address.js'
6
6
 
7
7
  export function getChainIdAddressFromId<
8
8
  TChainId extends ChainId,
@@ -13,30 +13,32 @@ export function getChainIdAddressFromId<
13
13
  chainId: TChainId
14
14
  address: TAddress
15
15
  } {
16
- const [chainId, address, ...rest] = id.split(':') as [TChainId, TAddress]
16
+ const separatorIndex = id.indexOf(':')
17
17
 
18
- if (rest.length > 0) {
18
+ if (separatorIndex === -1) {
19
19
  throw new Error(
20
20
  `Invalid ID format: ${id}. Expected format is "chainId:address".`,
21
21
  )
22
22
  }
23
23
 
24
+ const chainId = +id.slice(0, separatorIndex) as TChainId
25
+ const address = id.slice(separatorIndex + 1) as TAddress
26
+
24
27
  if (!chainId || !address) {
25
28
  throw new Error(
26
29
  `Invalid ID format: ${id}. Expected format is "chainId:address".`,
27
30
  )
28
31
  }
29
32
 
30
- return { chainId: +chainId as TChainId, address }
33
+ return { chainId, address }
31
34
  }
32
35
 
33
36
  export function getIdFromChainIdAddress<
34
37
  TChainId extends ChainId,
35
- TAddress extends string,
36
38
  TTranslateNative extends boolean = false,
37
39
  >(
38
40
  chainId: TChainId,
39
- address: TAddress,
41
+ address: AddressFor<TChainId>,
40
42
  options: { translateNative?: TTranslateNative } = {},
41
43
  ) {
42
44
  if (!chainId || !address) {
@@ -45,16 +47,13 @@ export function getIdFromChainIdAddress<
45
47
  )
46
48
  }
47
49
 
48
- // Kvm and Solana addresses are case-sensitive
49
- if (!isKvmTokenAddress(address) && !isSvmAddress(address)) {
50
- address = address.toLowerCase() as TAddress
51
- }
50
+ address = normalizeAddress(chainId, address)
52
51
 
53
- if (address === nativeAddress && options.translateNative) {
54
- address = 'NATIVE' as TAddress
52
+ if (address === getNativeAddress(chainId) && options.translateNative) {
53
+ address = 'NATIVE' as AddressFor<TChainId>
55
54
  }
56
55
 
57
56
  return `${chainId}:${address}` as TTranslateNative extends true
58
- ? ID<TChainId, TAddress | 'NATIVE'>
59
- : ID<TChainId, TAddress>
57
+ ? ID<TChainId, AddressFor<TChainId> | 'NATIVE'>
58
+ : ID<TChainId, AddressFor<TChainId>>
60
59
  }
@@ -1,3 +1,6 @@
1
+ export * from './assert-never.js'
1
2
  export * from './id.js'
2
3
  export * from './lowercase-map.js'
4
+ export * from './native-address.js'
5
+ export * from './normalize-address.js'
3
6
  export * from './subtract-slippage.js'
@@ -0,0 +1,45 @@
1
+ import { isEvmChainId } from '../../evm/chain/chains.js'
2
+ import { evmNativeAddress } from '../../evm/config/simple-constants.js'
3
+ import { isKvmChainId } from '../../kvm/chain/chains.js'
4
+ import { kvmNativeAddress } from '../../kvm/config/simple-constants.js'
5
+ import { isMvmChainId } from '../../mvm/chain/chains.js'
6
+ import { mvmNativeAddress } from '../../mvm/config/simple-constants.js'
7
+ import { isStellarChainId } from '../../stellar/chain/chains.js'
8
+ import { stellarNativeAddress } from '../../stellar/config/simple-constants.js'
9
+ import { isSvmChainId } from '../../svm/chain/chains.js'
10
+ import { svmNativeAddress } from '../../svm/config/simple-constants.js'
11
+ import { isTvmChainId } from '../../tvm/chain/chains.js'
12
+ import { tvmNativeAddress } from '../../tvm/config/simple-constants.js'
13
+ import type { ChainId } from '../chain/chains.js'
14
+ import type { AddressFor } from '../types/for-chain.js'
15
+ import { assertNever } from './assert-never.js'
16
+
17
+ export function getNativeAddress<TChainId extends ChainId>(
18
+ chainId: TChainId,
19
+ ): AddressFor<TChainId> {
20
+ if (isEvmChainId(chainId)) {
21
+ return evmNativeAddress as AddressFor<TChainId>
22
+ }
23
+
24
+ if (isMvmChainId(chainId)) {
25
+ return mvmNativeAddress as AddressFor<TChainId>
26
+ }
27
+
28
+ if (isTvmChainId(chainId)) {
29
+ return tvmNativeAddress as AddressFor<TChainId>
30
+ }
31
+
32
+ if (isKvmChainId(chainId)) {
33
+ return kvmNativeAddress as AddressFor<TChainId>
34
+ }
35
+
36
+ if (isSvmChainId(chainId)) {
37
+ return svmNativeAddress as AddressFor<TChainId>
38
+ }
39
+
40
+ if (isStellarChainId(chainId)) {
41
+ return stellarNativeAddress as AddressFor<TChainId>
42
+ }
43
+
44
+ assertNever(chainId, `getNativeAddress, unsupported chainId: ${chainId}`)
45
+ }
@@ -0,0 +1,64 @@
1
+ import type { EvmChainId } from '../../evm/chain/chains.js'
2
+ import { isEvmChainId } from '../../evm/chain/chains.js'
3
+ import { normalizeEvmAddress } from '../../evm/utils/normalize-address.js'
4
+ import type { KvmChainId } from '../../kvm/chain/chains.js'
5
+ import { isKvmChainId } from '../../kvm/chain/chains.js'
6
+ import { normalizeKvmAddress } from '../../kvm/utils/normalize-address.js'
7
+ import type { MvmChainId } from '../../mvm/chain/chains.js'
8
+ import { isMvmChainId } from '../../mvm/chain/chains.js'
9
+ import { normalizeMvmAddress } from '../../mvm/utils/normalize-address.js'
10
+ import type { StellarChainId } from '../../stellar/chain/chains.js'
11
+ import { isStellarChainId } from '../../stellar/chain/chains.js'
12
+ import { normalizeStellarAddress } from '../../stellar/utils/normalize-address.js'
13
+ import type { SvmChainId } from '../../svm/chain/chains.js'
14
+ import { isSvmChainId } from '../../svm/chain/chains.js'
15
+ import { normalizeSvmAddress } from '../../svm/utils/normalize-address.js'
16
+ import type { TvmChainId } from '../../tvm/chain/chains.js'
17
+ import { isTvmChainId } from '../../tvm/chain/chains.js'
18
+ import { normalizeTvmAddress } from '../../tvm/utils/normalize-address.js'
19
+ import type { ChainId } from '../chain/chains.js'
20
+ import type { AddressFor } from '../types/for-chain.js'
21
+ import { assertNever } from './assert-never.js'
22
+
23
+ export function normalizeAddress<TChainId extends ChainId>(
24
+ chainId: TChainId,
25
+ address: AddressFor<TChainId>,
26
+ ): AddressFor<TChainId> {
27
+ if (isEvmChainId(chainId)) {
28
+ return normalizeEvmAddress(
29
+ address as AddressFor<EvmChainId>,
30
+ ) as AddressFor<TChainId>
31
+ }
32
+
33
+ if (isMvmChainId(chainId)) {
34
+ return normalizeMvmAddress(
35
+ address as AddressFor<MvmChainId>,
36
+ ) as AddressFor<TChainId>
37
+ }
38
+
39
+ if (isTvmChainId(chainId)) {
40
+ return normalizeTvmAddress(
41
+ address as AddressFor<TvmChainId>,
42
+ ) as AddressFor<TChainId>
43
+ }
44
+
45
+ if (isKvmChainId(chainId)) {
46
+ return normalizeKvmAddress(
47
+ address as AddressFor<KvmChainId>,
48
+ ) as AddressFor<TChainId>
49
+ }
50
+
51
+ if (isSvmChainId(chainId)) {
52
+ return normalizeSvmAddress(
53
+ address as AddressFor<SvmChainId>,
54
+ ) as AddressFor<TChainId>
55
+ }
56
+
57
+ if (isStellarChainId(chainId)) {
58
+ return normalizeStellarAddress(
59
+ address as AddressFor<StellarChainId>,
60
+ ) as AddressFor<TChainId>
61
+ }
62
+
63
+ assertNever(chainId, `normalizeAddress, unsupported chainId: ${chainId}`)
64
+ }
@@ -0,0 +1 @@
1
+ export * from './simple-constants.js'
@@ -0,0 +1,3 @@
1
+ import type { KvmTokenAddress } from '../currency/token.js'
2
+
3
+ export const kvmNativeAddress: KvmTokenAddress = 'coin'
package/kvm/index.ts CHANGED
@@ -1,2 +1,4 @@
1
1
  export * from './chain/index.js'
2
+ export * from './config/index.js'
2
3
  export * from './currency/index.js'
4
+ export * from './utils/index.js'
@@ -0,0 +1 @@
1
+ export * from './normalize-address.js'
@@ -0,0 +1,5 @@
1
+ import type { KvmTokenAddress } from '../currency/token.js'
2
+
3
+ export function normalizeKvmAddress(address: KvmTokenAddress): KvmTokenAddress {
4
+ return address
5
+ }
@@ -0,0 +1 @@
1
+ export * from './simple-constants.js'
@@ -0,0 +1,3 @@
1
+ import type { MvmAddress } from '../currency/token.js'
2
+
3
+ export const mvmNativeAddress: MvmAddress = '0x1::aptos_coin::AptosCoin'
@@ -2,6 +2,7 @@ import * as z from 'zod'
2
2
  import type { CurrencyMetadata } from '../../generic/currency/currency.js'
3
3
  import { Token } from '../../generic/currency/token.js'
4
4
  import { isMvmChainId, type MvmChainId } from '../chain/chains.js'
5
+ import { normalizeMvmAddress } from '../utils/normalize-address.js'
5
6
 
6
7
  export type MvmAddress = `0x${string}::${string}::${string}`
7
8
 
@@ -19,7 +20,7 @@ export class MvmToken<
19
20
  }: ConstructorParameters<
20
21
  typeof Token<MvmChainId, MvmAddress, TMetadata>
21
22
  >[0]) {
22
- super({ address: address.toLowerCase() as MvmAddress, ...rest })
23
+ super({ address: normalizeMvmAddress(address), ...rest })
23
24
  }
24
25
 
25
26
  public override wrap(): MvmToken<TMetadata> {
package/mvm/index.ts CHANGED
@@ -1,2 +1,4 @@
1
1
  export * from './chain/index.js'
2
+ export * from './config/index.js'
2
3
  export * from './currency/index.js'
4
+ export * from './utils/index.js'
@@ -0,0 +1 @@
1
+ export * from './normalize-address.js'
@@ -0,0 +1,5 @@
1
+ import type { MvmAddress } from '../currency/token.js'
2
+
3
+ export function normalizeMvmAddress(address: MvmAddress): MvmAddress {
4
+ return address
5
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "sushi",
3
3
  "description": "Sushi",
4
- "version": "6.4.5",
4
+ "version": "6.4.6",
5
5
  "type": "module",
6
6
  "main": "./_cjs/generic/index.js",
7
7
  "module": "./_esm/generic/index.js",
@@ -0,0 +1,7 @@
1
+ export type StellarAddress = `G${string}`
2
+
3
+ const stellarAddressRegex = /^G[A-Z2-7]{55}$/
4
+
5
+ export function isStellarAddress(address: string): address is StellarAddress {
6
+ return stellarAddressRegex.test(address)
7
+ }
@@ -0,0 +1 @@
1
+ export * from './simple-constants.js'
@@ -0,0 +1,2 @@
1
+ export const stellarNativeAddress =
2
+ 'GAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' as const
package/stellar/index.ts CHANGED
@@ -1 +1,4 @@
1
+ export * from './address.js'
1
2
  export * from './chain/index.js'
3
+ export * from './config/index.js'
4
+ export * from './utils/index.js'
@@ -0,0 +1 @@
1
+ export * from './normalize-address.js'
@@ -0,0 +1,7 @@
1
+ import type { StellarAddress } from '../address.js'
2
+
3
+ export function normalizeStellarAddress(
4
+ address: StellarAddress,
5
+ ): StellarAddress {
6
+ return address.toUpperCase() as StellarAddress
7
+ }
@@ -1,5 +1,5 @@
1
1
  import * as z from 'zod'
2
- import type { CurrencyMetadata } from '~/generic/currency/currency.js'
2
+ import type { CurrencyMetadata } from '../../generic/currency/currency.js'
3
3
  import { Native } from '../../generic/currency/native.js'
4
4
  import {
5
5
  getSvmChainById,
@@ -7,6 +7,7 @@ import * as z from 'zod'
7
7
  import type { CurrencyMetadata } from '../../generic/currency/currency.js'
8
8
  import { Token } from '../../generic/currency/token.js'
9
9
  import { isSvmChainId, type SvmChainId } from '../chain/chains.js'
10
+ import { normalizeSvmAddress } from '../utils/normalize-address.js'
10
11
 
11
12
  export { type SvmAddress, svmAddress, isSvmAddress }
12
13
 
@@ -19,13 +20,14 @@ export class SvmToken<
19
20
 
20
21
  constructor({
21
22
  origin,
23
+ address,
22
24
  ...rest
23
25
  }: {
24
26
  origin?: SvmTokenOrigin | undefined
25
27
  } & ConstructorParameters<
26
28
  typeof Token<SvmChainId, SvmAddress, TMetadata>
27
29
  >[0]) {
28
- super({ ...rest })
30
+ super({ address: normalizeSvmAddress(address), ...rest })
29
31
  this.origin = origin
30
32
  }
31
33
 
package/svm/index.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './chain/index.js'
2
2
  export * from './config/index.js'
3
3
  export * from './currency/index.js'
4
+ export * from './utils/index.js'
@@ -0,0 +1,9 @@
1
+ import type { ID } from '../../generic/types/id.js'
2
+ import type { SvmChainId } from '../chain/chains.js'
3
+ import type { SvmAddress } from '../currency/token.js'
4
+
5
+ export type SvmID<TIncludeNative extends boolean = false> = ID<
6
+ SvmChainId,
7
+ SvmAddress,
8
+ TIncludeNative
9
+ >
@@ -0,0 +1 @@
1
+ export * from './normalize-address.js'
@@ -0,0 +1,5 @@
1
+ import type { SvmAddress } from '../currency/token.js'
2
+
3
+ export function normalizeSvmAddress(address: SvmAddress): SvmAddress {
4
+ return address
5
+ }
@@ -1,2 +1,3 @@
1
1
  export * from './features/index.js'
2
+ export * from './simple-constants.js'
2
3
  export * from './tokens/index.js'
@@ -0,0 +1,3 @@
1
+ import type { TvmAddress } from '../currency/token.js'
2
+
3
+ export const tvmNativeAddress: TvmAddress = 'T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb'
@@ -1,5 +1,5 @@
1
1
  import * as z from 'zod'
2
- import type { CurrencyMetadata } from '~/generic/currency/currency.js'
2
+ import type { CurrencyMetadata } from '../../generic/currency/currency.js'
3
3
  import { Native } from '../../generic/currency/native.js'
4
4
  import { isTvmChainId, type TvmChainId } from '../chain/chains.js'
5
5
  import { NATIVE } from '../config/index.js'
@@ -2,6 +2,7 @@ import * as z from 'zod'
2
2
  import type { CurrencyMetadata } from '../../generic/currency/currency.js'
3
3
  import { Token } from '../../generic/currency/token.js'
4
4
  import { isTvmChainId, type TvmChainId } from '../chain/chains.js'
5
+ import { normalizeTvmAddress } from '../utils/normalize-address.js'
5
6
 
6
7
  export type TvmAddress = `T${string}`
7
8
 
@@ -25,7 +26,7 @@ export class TvmToken<
25
26
  } & ConstructorParameters<
26
27
  typeof Token<TvmChainId, TvmAddress, TMetadata>
27
28
  >[0]) {
28
- super({ address: address.toLowerCase() as TvmAddress, ...rest })
29
+ super({ address: normalizeTvmAddress(address), ...rest })
29
30
  this.origin = origin
30
31
  }
31
32
 
package/tvm/index.ts CHANGED
@@ -2,3 +2,4 @@ export * from './abi/index.js'
2
2
  export * from './chain/index.js'
3
3
  export * from './config/index.js'
4
4
  export * from './currency/index.js'
5
+ export * from './utils/index.js'
@@ -0,0 +1 @@
1
+ export * from './normalize-address.js'
@@ -0,0 +1,5 @@
1
+ import type { TvmAddress } from '../currency/token.js'
2
+
3
+ export function normalizeTvmAddress(address: TvmAddress): TvmAddress {
4
+ return address
5
+ }