0xtrails 0.1.13 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (216) hide show
  1. package/dist/aave.d.ts.map +1 -1
  2. package/dist/analytics.d.ts +11 -2
  3. package/dist/analytics.d.ts.map +1 -1
  4. package/dist/apiClient.d.ts +1 -1
  5. package/dist/apiClient.d.ts.map +1 -1
  6. package/dist/{proxyCaller.d.ts → balanceInjector.d.ts} +5 -4
  7. package/dist/balanceInjector.d.ts.map +1 -0
  8. package/dist/{ccip-D3gTQONK.js → ccip-D6ToCrWc.js} +12 -12
  9. package/dist/cctp.d.ts.map +1 -1
  10. package/dist/cctpqueue.d.ts +3 -3
  11. package/dist/cctpqueue.d.ts.map +1 -1
  12. package/dist/chains.d.ts.map +1 -1
  13. package/dist/config.d.ts +17 -3
  14. package/dist/config.d.ts.map +1 -1
  15. package/dist/constants.d.ts +5 -4
  16. package/dist/constants.d.ts.map +1 -1
  17. package/dist/contractUtils.d.ts +2 -0
  18. package/dist/contractUtils.d.ts.map +1 -1
  19. package/dist/customChains.d.ts +24 -0
  20. package/dist/customChains.d.ts.map +1 -0
  21. package/dist/{index-CnUM7lKf.js → index-BqgeTLL8.js} +34072 -30146
  22. package/dist/index.d.ts +5 -3
  23. package/dist/index.d.ts.map +1 -1
  24. package/dist/index.js +411 -400
  25. package/dist/intentEntrypoint.d.ts +96 -0
  26. package/dist/intentEntrypoint.d.ts.map +1 -0
  27. package/dist/intents.d.ts +5 -3
  28. package/dist/intents.d.ts.map +1 -1
  29. package/dist/metaTxnMonitor.d.ts.map +1 -1
  30. package/dist/morpho.d.ts.map +1 -1
  31. package/dist/pools.d.ts +3 -1
  32. package/dist/pools.d.ts.map +1 -1
  33. package/dist/prepareSend.d.ts +8 -2
  34. package/dist/prepareSend.d.ts.map +1 -1
  35. package/dist/prices.d.ts +1 -1
  36. package/dist/prices.d.ts.map +1 -1
  37. package/dist/relaySdk.d.ts.map +1 -1
  38. package/dist/relayer.d.ts.map +1 -1
  39. package/dist/toast.d.ts +9 -0
  40. package/dist/toast.d.ts.map +1 -0
  41. package/dist/tokenBalances.d.ts +6 -2
  42. package/dist/tokenBalances.d.ts.map +1 -1
  43. package/dist/tokens.d.ts.map +1 -1
  44. package/dist/trails.d.ts +6 -5
  45. package/dist/trails.d.ts.map +1 -1
  46. package/dist/trailsClient.d.ts +12 -0
  47. package/dist/trailsClient.d.ts.map +1 -0
  48. package/dist/transactions.d.ts +8 -0
  49. package/dist/transactions.d.ts.map +1 -1
  50. package/dist/wallets.d.ts.map +1 -1
  51. package/dist/widget/components/AccountActionsDropdown.d.ts.map +1 -1
  52. package/dist/widget/components/AccountIntentTransactionHistory.d.ts.map +1 -1
  53. package/dist/widget/components/AccountSettings.d.ts +7 -0
  54. package/dist/widget/components/AccountSettings.d.ts.map +1 -0
  55. package/dist/widget/components/ChainList.d.ts +0 -1
  56. package/dist/widget/components/ChainList.d.ts.map +1 -1
  57. package/dist/widget/components/ClassicSwap.d.ts +46 -0
  58. package/dist/widget/components/ClassicSwap.d.ts.map +1 -0
  59. package/dist/widget/components/ConfigDisplay.d.ts.map +1 -1
  60. package/dist/widget/components/ConnectedWallets.d.ts +9 -0
  61. package/dist/widget/components/ConnectedWallets.d.ts.map +1 -0
  62. package/dist/widget/components/DebugMenu.d.ts.map +1 -1
  63. package/dist/widget/components/DebugScreensList.d.ts.map +1 -1
  64. package/dist/widget/components/DebugToast.d.ts +3 -0
  65. package/dist/widget/components/DebugToast.d.ts.map +1 -0
  66. package/dist/widget/components/Earn.d.ts.map +1 -1
  67. package/dist/widget/components/EarnPools.d.ts.map +1 -1
  68. package/dist/widget/components/Fund.d.ts +44 -0
  69. package/dist/widget/components/Fund.d.ts.map +1 -0
  70. package/dist/widget/components/Identicon.d.ts +9 -0
  71. package/dist/widget/components/Identicon.d.ts.map +1 -0
  72. package/dist/widget/components/Pay.d.ts +46 -0
  73. package/dist/widget/components/Pay.d.ts.map +1 -0
  74. package/dist/widget/components/Receive.d.ts.map +1 -1
  75. package/dist/widget/components/RecentTokens.d.ts.map +1 -1
  76. package/dist/widget/components/Recipients.d.ts +9 -0
  77. package/dist/widget/components/Recipients.d.ts.map +1 -0
  78. package/dist/widget/components/RefundWarning.d.ts +9 -0
  79. package/dist/widget/components/RefundWarning.d.ts.map +1 -0
  80. package/dist/widget/components/SimpleSwap.d.ts.map +1 -1
  81. package/dist/widget/components/Swap.d.ts.map +1 -1
  82. package/dist/widget/components/SwapSettings.d.ts +1 -5
  83. package/dist/widget/components/SwapSettings.d.ts.map +1 -1
  84. package/dist/widget/components/ThemeProvider.d.ts.map +1 -1
  85. package/dist/widget/components/ThemeSyncer.d.ts +6 -0
  86. package/dist/widget/components/ThemeSyncer.d.ts.map +1 -0
  87. package/dist/widget/components/Toast.d.ts +24 -0
  88. package/dist/widget/components/Toast.d.ts.map +1 -0
  89. package/dist/widget/components/TokenList.d.ts.map +1 -1
  90. package/dist/widget/components/TransactionDetails.d.ts.map +1 -1
  91. package/dist/widget/components/TruncatedAddress.d.ts +2 -0
  92. package/dist/widget/components/TruncatedAddress.d.ts.map +1 -1
  93. package/dist/widget/components/UserPreferences.d.ts +7 -0
  94. package/dist/widget/components/UserPreferences.d.ts.map +1 -0
  95. package/dist/widget/hooks/useBalanceVisible.d.ts +1 -0
  96. package/dist/widget/hooks/useBalanceVisible.d.ts.map +1 -1
  97. package/dist/widget/hooks/useCheckout.d.ts.map +1 -1
  98. package/dist/widget/hooks/useCurrentScreen.d.ts +1 -1
  99. package/dist/widget/hooks/useCurrentScreen.d.ts.map +1 -1
  100. package/dist/widget/hooks/useDebugScreens.d.ts +1 -1
  101. package/dist/widget/hooks/useDebugScreens.d.ts.map +1 -1
  102. package/dist/widget/hooks/useDefaultTokenSelection.d.ts +54 -0
  103. package/dist/widget/hooks/useDefaultTokenSelection.d.ts.map +1 -0
  104. package/dist/widget/hooks/useIntentTransactionHistory.d.ts.map +1 -1
  105. package/dist/widget/hooks/usePayMessage.d.ts +34 -0
  106. package/dist/widget/hooks/usePayMessage.d.ts.map +1 -0
  107. package/dist/widget/hooks/useRecipients.d.ts +17 -0
  108. package/dist/widget/hooks/useRecipients.d.ts.map +1 -0
  109. package/dist/widget/hooks/useSelectedRecipient.d.ts +12 -0
  110. package/dist/widget/hooks/useSelectedRecipient.d.ts.map +1 -0
  111. package/dist/widget/hooks/useSendForm.d.ts +2 -0
  112. package/dist/widget/hooks/useSendForm.d.ts.map +1 -1
  113. package/dist/widget/hooks/useSwapAmount.d.ts +13 -0
  114. package/dist/widget/hooks/useSwapAmount.d.ts.map +1 -0
  115. package/dist/widget/hooks/useSwapSettings.d.ts +16 -0
  116. package/dist/widget/hooks/useSwapSettings.d.ts.map +1 -0
  117. package/dist/widget/hooks/useTargetAmount.d.ts +5 -0
  118. package/dist/widget/hooks/useTargetAmount.d.ts.map +1 -0
  119. package/dist/widget/hooks/useTheme.d.ts +14 -0
  120. package/dist/widget/hooks/useTheme.d.ts.map +1 -0
  121. package/dist/widget/hooks/useTokenList.d.ts.map +1 -1
  122. package/dist/widget/index.js +2 -2
  123. package/dist/widget/widget.d.ts +9 -0
  124. package/dist/widget/widget.d.ts.map +1 -1
  125. package/package.json +29 -28
  126. package/src/aave.ts +6 -1
  127. package/src/analytics.ts +103 -53
  128. package/src/apiClient.ts +1 -1
  129. package/src/{proxyCaller.ts → balanceInjector.ts} +22 -17
  130. package/src/cctp.ts +6 -2
  131. package/src/cctpqueue.ts +7 -7
  132. package/src/chains.ts +8 -0
  133. package/src/config.ts +40 -9
  134. package/src/constants.ts +11 -8
  135. package/src/contractUtils.ts +33 -2
  136. package/src/customChains.ts +24 -0
  137. package/src/index.ts +11 -1
  138. package/src/intentEntrypoint.ts +253 -0
  139. package/src/intents.ts +87 -54
  140. package/src/metaTxnMonitor.ts +1 -0
  141. package/src/morpho.ts +13 -2
  142. package/src/pools.ts +68 -86
  143. package/src/prepareSend.ts +437 -207
  144. package/src/prices.ts +51 -7
  145. package/src/relaySdk.ts +6 -4
  146. package/src/relayer.ts +2 -0
  147. package/src/toast.ts +110 -0
  148. package/src/tokenBalances.ts +112 -20
  149. package/src/tokens.ts +70 -7
  150. package/src/trails.ts +80 -77
  151. package/src/trailsClient.ts +45 -0
  152. package/src/transactions.ts +27 -35
  153. package/src/umd.tsx +1 -1
  154. package/src/wallets.ts +2 -1
  155. package/src/widget/assets/sequence-logo.svg +15 -0
  156. package/src/widget/compiled.css +2 -2
  157. package/src/widget/components/AccountActionsDropdown.tsx +18 -159
  158. package/src/widget/components/AccountIntentTransactionHistory.tsx +346 -63
  159. package/src/widget/components/AccountSettings.tsx +96 -0
  160. package/src/widget/components/ChainFilterDropdown.tsx +1 -1
  161. package/src/widget/components/ChainList.tsx +10 -20
  162. package/src/widget/components/ClassicSwap.tsx +923 -0
  163. package/src/widget/components/ConfigDisplay.tsx +8 -5
  164. package/src/widget/components/ConnectedWallets.tsx +260 -0
  165. package/src/widget/components/DebugMenu.tsx +2 -0
  166. package/src/widget/components/DebugScreensList.tsx +3 -0
  167. package/src/widget/components/DebugToast.tsx +63 -0
  168. package/src/widget/components/Earn.tsx +108 -116
  169. package/src/widget/components/EarnPools.tsx +2 -4
  170. package/src/widget/components/EarnPoolsFilters.tsx +6 -6
  171. package/src/widget/components/Fund.tsx +1245 -0
  172. package/src/widget/components/FundMethods.tsx +1 -1
  173. package/src/widget/components/FundSendForm.tsx +1 -1
  174. package/src/widget/components/Identicon.tsx +158 -0
  175. package/src/widget/components/Pay.tsx +1088 -0
  176. package/src/widget/components/PaySendForm.tsx +1 -1
  177. package/src/widget/components/QuoteDetails.tsx +1 -1
  178. package/src/widget/components/Receipt.tsx +1 -1
  179. package/src/widget/components/Receive.tsx +4 -2
  180. package/src/widget/components/RecentTokens.tsx +2 -1
  181. package/src/widget/components/Recipients.tsx +448 -0
  182. package/src/widget/components/RefundWarning.tsx +61 -0
  183. package/src/widget/components/ScreenHeader.tsx +1 -1
  184. package/src/widget/components/SimpleSwap.tsx +74 -58
  185. package/src/widget/components/Swap.tsx +35 -853
  186. package/src/widget/components/SwapSettings.tsx +5 -11
  187. package/src/widget/components/ThemeProvider.tsx +32 -0
  188. package/src/widget/components/ThemeSyncer.tsx +47 -0
  189. package/src/widget/components/Toast.tsx +315 -0
  190. package/src/widget/components/TokenList.tsx +2 -34
  191. package/src/widget/components/TokenSelector.tsx +3 -3
  192. package/src/widget/components/TransactionDetails.tsx +153 -13
  193. package/src/widget/components/TruncatedAddress.tsx +5 -1
  194. package/src/widget/components/UserPreferences.tsx +156 -0
  195. package/src/widget/components/WalletList.tsx +1 -1
  196. package/src/widget/hooks/useBalanceVisible.tsx +40 -2
  197. package/src/widget/hooks/useCheckout.ts +13 -0
  198. package/src/widget/hooks/useCurrentScreen.tsx +3 -0
  199. package/src/widget/hooks/useDebugScreens.ts +12 -2
  200. package/src/widget/hooks/useDefaultTokenSelection.tsx +475 -0
  201. package/src/widget/hooks/useIntentTransactionHistory.ts +212 -0
  202. package/src/widget/hooks/usePayMessage.tsx +370 -0
  203. package/src/widget/hooks/useRecipients.ts +168 -0
  204. package/src/widget/hooks/useSelectedRecipient.tsx +48 -0
  205. package/src/widget/hooks/useSendForm.ts +179 -26
  206. package/src/widget/hooks/useSwapAmount.tsx +50 -0
  207. package/src/widget/hooks/useSwapSettings.tsx +100 -0
  208. package/src/widget/hooks/useTargetAmount.ts +23 -0
  209. package/src/widget/hooks/useTheme.tsx +80 -0
  210. package/src/widget/hooks/useTokenList.ts +20 -11
  211. package/src/widget/index.css +45 -21
  212. package/src/widget/widget.tsx +164 -68
  213. package/dist/address.d.ts +0 -2
  214. package/dist/address.d.ts.map +0 -1
  215. package/dist/proxyCaller.d.ts.map +0 -1
  216. package/src/address.ts +0 -6
package/src/config.ts CHANGED
@@ -6,10 +6,12 @@ import {
6
6
  PROD_SEQUENCE_PROJECT_ACCESS_KEY,
7
7
  DEV_SEQUENCE_INDEXER_URL,
8
8
  DEV_SEQUENCE_API_URL,
9
+ DEV_TRAILS_API_URL,
9
10
  DEV_SEQUENCE_PROJECT_ACCESS_KEY,
10
11
  DEFAULT_SEQUENCE_ENV,
11
12
  PROD_SEQUENCE_NODE_GATEWAY_URL,
12
13
  DEV_SEQUENCE_NODE_GATEWAY_URL,
14
+ PROD_TRAILS_API_URL,
13
15
  } from "./constants.js"
14
16
  import { getQueryParam } from "./queryParams.js"
15
17
 
@@ -20,6 +22,7 @@ export const globalConfig: {
20
22
  sequenceIndexerUrl: string
21
23
  sequenceNodeGatewayUrl: string
22
24
  sequenceApiUrl: string
25
+ trailsApiUrl: string
23
26
  sequenceEnv: SequenceEnv
24
27
  walletConnectProjectId: string
25
28
  slippageTolerance: string
@@ -27,11 +30,12 @@ export const globalConfig: {
27
30
  commitHash: string | undefined
28
31
  } = {
29
32
  commitHash: declareCommitHash(),
33
+ sequenceEnv: declareSequenceEnv(),
30
34
  sequenceProjectAccessKey: declareSequenceProjectAccessKey(),
31
35
  sequenceIndexerUrl: declareSequenceIndexerUrl(),
32
36
  sequenceNodeGatewayUrl: declareSequenceNodeGatewayUrl(),
33
37
  sequenceApiUrl: declareSequenceApiUrl(),
34
- sequenceEnv: declareSequenceEnv(),
38
+ trailsApiUrl: declareTrailsApiUrl(),
35
39
  walletConnectProjectId: DEFAULT_WALLETCONNECT_PROJECT_ID,
36
40
  slippageTolerance: DEFAULT_SLIPPAGE_TOLERANCE,
37
41
  debug: false,
@@ -74,11 +78,21 @@ export function declareSequenceApiUrl() {
74
78
  return PROD_SEQUENCE_API_URL
75
79
  }
76
80
  if (declareSequenceEnv() === "local") {
77
- return getEnvVar("TEST_API_URL") || DEV_SEQUENCE_API_URL
81
+ return getEnvVar("SEQUENCE_API_URL") || DEV_SEQUENCE_API_URL
78
82
  }
79
83
  return DEV_SEQUENCE_API_URL
80
84
  }
81
85
 
86
+ export function declareTrailsApiUrl() {
87
+ if (declareSequenceEnv() === "prod") {
88
+ return PROD_TRAILS_API_URL
89
+ }
90
+ if (declareSequenceEnv() === "local") {
91
+ return getEnvVar("TRAILS_API_URL") || DEV_TRAILS_API_URL
92
+ }
93
+ return DEV_TRAILS_API_URL
94
+ }
95
+
82
96
  export function declareSequenceNodeGatewayUrl() {
83
97
  if (declareSequenceEnv() === "prod") {
84
98
  return PROD_SEQUENCE_NODE_GATEWAY_URL
@@ -87,6 +101,11 @@ export function declareSequenceNodeGatewayUrl() {
87
101
  }
88
102
 
89
103
  export function declareSequenceProjectAccessKey() {
104
+ if (typeof process !== "undefined") {
105
+ if (getEnvVar("SEQUENCE_PROJECT_ACCESS_KEY")) {
106
+ return getEnvVar("SEQUENCE_PROJECT_ACCESS_KEY")
107
+ }
108
+ }
90
109
  if (declareSequenceEnv() === "prod") {
91
110
  return PROD_SEQUENCE_PROJECT_ACCESS_KEY
92
111
  }
@@ -105,6 +124,10 @@ export function declareCommitHash() {
105
124
  return cfPagesCommitHash || viteCommitHash
106
125
  }
107
126
 
127
+ export function getSequenceConfig() {
128
+ return globalConfig
129
+ }
130
+
108
131
  export function getSequenceProjectAccessKey() {
109
132
  return globalConfig.sequenceProjectAccessKey
110
133
  }
@@ -137,24 +160,37 @@ export function getSequenceApiUrl() {
137
160
  return globalConfig.sequenceApiUrl
138
161
  }
139
162
 
163
+ export function setTrailsApiUrl(trailsApiUrl: string) {
164
+ globalConfig.trailsApiUrl = trailsApiUrl
165
+ }
166
+
167
+ export function getTrailsApiUrl() {
168
+ return globalConfig.trailsApiUrl
169
+ }
170
+
140
171
  export function setSequenceEnv(sequenceEnv: SequenceEnv) {
141
172
  globalConfig.sequenceEnv = sequenceEnv
142
173
 
143
174
  if (sequenceEnv === "prod") {
144
175
  setSequenceIndexerUrl(PROD_SEQUENCE_INDEXER_URL)
145
176
  setSequenceApiUrl(PROD_SEQUENCE_API_URL)
177
+ setTrailsApiUrl(PROD_TRAILS_API_URL)
146
178
  setSequenceNodeGatewayUrl(PROD_SEQUENCE_NODE_GATEWAY_URL)
147
179
  }
148
180
 
149
181
  if (sequenceEnv === "local") {
150
- if (getEnvVar("API_URL")) {
151
- setSequenceApiUrl(getEnvVar("API_URL"))
182
+ if (getEnvVar("SEQUENCE_API_URL")) {
183
+ setSequenceApiUrl(getEnvVar("SEQUENCE_API_URL"))
184
+ }
185
+ if (getEnvVar("TRAILS_API_URL")) {
186
+ setTrailsApiUrl(getEnvVar("TRAILS_API_URL"))
152
187
  }
153
188
  }
154
189
 
155
190
  if (sequenceEnv === "dev") {
156
191
  setSequenceIndexerUrl(DEV_SEQUENCE_INDEXER_URL)
157
192
  setSequenceApiUrl(DEV_SEQUENCE_API_URL)
193
+ setTrailsApiUrl(DEV_TRAILS_API_URL)
158
194
  setSequenceNodeGatewayUrl(DEV_SEQUENCE_NODE_GATEWAY_URL)
159
195
  }
160
196
  }
@@ -208,13 +244,8 @@ export function getAccountIntentTransactionHistory() {
208
244
  return FeatureFlags.accountIntentTransactionHistory
209
245
  }
210
246
 
211
- export function getSameChainSwapDifferentIntentAddresses() {
212
- return FeatureFlags.sameChainSwapDifferentIntentAddresses
213
- }
214
-
215
247
  export const FeatureFlags = {
216
248
  accountIntentTransactionHistory: false,
217
- sameChainSwapDifferentIntentAddresses: false,
218
249
  }
219
250
 
220
251
  export function getEnvVar(name: string) {
package/src/constants.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type { AddressOverrides } from "@0xsequence/trails-api"
1
2
  import type { Context as ContextLike } from "@0xsequence/wallet-primitives"
2
3
 
3
4
  export const SEQUENCE_V3_CONTRACT_ADDRESSES: ContextLike.Context = {
@@ -8,27 +9,29 @@ export const SEQUENCE_V3_CONTRACT_ADDRESSES: ContextLike.Context = {
8
9
  "0x6041600e3d396021805130553df33d3d36153402601f57363d3d373d363d30545af43d82803e903d91601f57fd5bf3" as `0x${string}`,
9
10
  }
10
11
 
12
+ export const SEQUENCE_V3_CONTRACT_ADDRESSES_OVERRIDES: AddressOverrides = {
13
+ sequenceWalletFactoryAddress: SEQUENCE_V3_CONTRACT_ADDRESSES.factory,
14
+ sequenceWalletMainModuleAddress: SEQUENCE_V3_CONTRACT_ADDRESSES.stage1,
15
+ sequenceWalletMainModuleUpgradableAddress:
16
+ SEQUENCE_V3_CONTRACT_ADDRESSES.stage2,
17
+ }
18
+
11
19
  export const TRAILS_BALANCE_INJECTOR_ADDRESS =
12
- "0x9eCA6CEf73799402a1afe4779f588f03034c5D0f"
20
+ "0xAca1813C717954c6Dc4Cbf69192b3Ef5781149C0"
13
21
 
14
22
  export const ATTESATION_SIGNER_ADDRESS =
15
23
  "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"
16
24
 
17
- export const TRAILS_LIFI_SAPIENT_SIGNER_ADDRESS =
18
- "0xd7571bd1e3af468c3a49966c9a92a2e907cdfa52"
19
- export const TRAILS_RELAY_SAPIENT_SIGNER_ADDRESS =
20
- "0x9a013e7d186611af36a918ef23d81886e8c256f8"
21
- export const TRAILS_CCTP_SAPIENT_SIGNER_ADDRESS =
22
- "0xc1A9B197eBb31Fc2B613C59dAC3f3E5698A429D0"
23
-
24
25
  export const DEFAULT_SEQUENCE_ENV = "prod"
25
26
 
26
27
  export const PROD_SEQUENCE_NODE_GATEWAY_URL = "https://nodes.sequence.app"
27
28
  export const PROD_SEQUENCE_INDEXER_URL = "https://indexer.sequence.app"
28
29
  export const PROD_SEQUENCE_API_URL = "https://api.sequence.app"
30
+ export const PROD_TRAILS_API_URL = "https://trails-api.sequence.app"
29
31
  export const DEV_SEQUENCE_NODE_GATEWAY_URL = "https://dev-nodes.sequence.app"
30
32
  export const DEV_SEQUENCE_INDEXER_URL = "https://dev-indexer.sequence.app"
31
33
  export const DEV_SEQUENCE_API_URL = "https://dev-api.sequence.app"
34
+ export const DEV_TRAILS_API_URL = "https://dev-trails-api.sequence-dev.app"
32
35
 
33
36
  export const intentEntrypoints: Record<number, `0x${string}`> = {
34
37
  8453: "0x2bf4c63199eD7D8A737E8DB2cC19E0C0103F6bE3",
@@ -1,5 +1,6 @@
1
1
  import { createPublicClient, http } from "viem"
2
2
  import { getChainInfo } from "./chains.js"
3
+ import { logger } from "./logger.js"
3
4
 
4
5
  export async function getIsContract(address: `0x${string}`, chainId: number) {
5
6
  const client = createPublicClient({
@@ -8,9 +9,39 @@ export async function getIsContract(address: `0x${string}`, chainId: number) {
8
9
  })
9
10
 
10
11
  const code = await client.getCode({ address })
11
- return code !== "0x"
12
+ const isNonZero = isNonZeroHexString(code)
13
+ const is7702 = is7702ContractCode(code)
14
+ const isContract = isNonZero && !is7702
15
+
16
+ logger.console.log(
17
+ "[trails-sdk] code:",
18
+ code?.slice(0, 10),
19
+ "address:",
20
+ address,
21
+ "chainId:",
22
+ chainId,
23
+ "isContract:",
24
+ isContract,
25
+ )
26
+
27
+ return isContract
28
+ }
29
+
30
+ export function is7702ContractCode(hex: string | undefined): boolean {
31
+ return hex?.startsWith("0xef0100") || false
32
+ }
33
+
34
+ export function isNonZeroHexString(hex: string | undefined): boolean {
35
+ return (
36
+ hex !== undefined &&
37
+ hex !== "" &&
38
+ hex !== "0" &&
39
+ hex !== "0x" &&
40
+ hex !== "0x0" &&
41
+ hex !== "0x00"
42
+ )
12
43
  }
13
44
 
14
45
  export function getIsCustomCalldata(calldata: string | undefined): boolean {
15
- return calldata !== undefined && calldata !== "" && calldata !== "0x"
46
+ return isNonZeroHexString(calldata)
16
47
  }
@@ -0,0 +1,24 @@
1
+ // Custom chain definition for Somnia
2
+ export const somnia = {
3
+ id: 5031,
4
+ name: "Somnia",
5
+ nativeCurrency: {
6
+ decimals: 18,
7
+ name: "SOMI",
8
+ symbol: "SOMI",
9
+ },
10
+ rpcUrls: {
11
+ default: {
12
+ http: ["https://api.infra.mainnet.somnia.network"],
13
+ },
14
+ public: {
15
+ http: ["https://api.infra.mainnet.somnia.network"],
16
+ },
17
+ },
18
+ blockExplorers: {
19
+ default: {
20
+ name: "Somnia Explorer",
21
+ url: "https://explorer.somnia.network/",
22
+ },
23
+ },
24
+ } as const
package/src/index.ts CHANGED
@@ -4,6 +4,8 @@ export { getAPIClient, useAPIClient } from "./apiClient.js"
4
4
  export {
5
5
  getSupportedChains,
6
6
  useSupportedChains,
7
+ getChainInfo,
8
+ getAllChains,
7
9
  } from "./chains.js"
8
10
  export {
9
11
  getIndexerGatewayClient,
@@ -71,11 +73,12 @@ export {
71
73
  useSupportedTokens,
72
74
  useTokenList,
73
75
  } from "./tokens.js"
76
+ export type { SupportedToken } from "./tokens.js"
74
77
  export { getTxTimeDiff } from "./transactions.js"
75
78
  export { useTrails } from "./trails.js"
76
79
  export type { WagmiAccount } from "./trails.js"
77
80
  export type { Mode } from "./mode.js"
78
- export { TRAILS_CONTRACT_PLACEHOLDER_AMOUNT } from "./proxyCaller.js"
81
+ export { TRAILS_CONTRACT_PLACEHOLDER_AMOUNT } from "./balanceInjector.js"
79
82
  export { getERC20TransferData } from "./encoders.js"
80
83
  export { getRelayer, useRelayers } from "./relayer.js"
81
84
  export { relayerSendMetaTx, getMetaTxnReceipt } from "./metaTxns.js"
@@ -83,10 +86,12 @@ export {
83
86
  declareSequenceEnv,
84
87
  getSequenceProjectAccessKey,
85
88
  getSequenceApiUrl,
89
+ getTrailsApiUrl,
86
90
  getSequenceIndexerUrl,
87
91
  getSequenceEnv,
88
92
  setSequenceProjectAccessKey,
89
93
  setSequenceApiUrl,
94
+ setTrailsApiUrl,
90
95
  setSequenceIndexerUrl,
91
96
  setSequenceNodeGatewayUrl,
92
97
  getSequenceNodeGatewayUrl,
@@ -100,3 +105,8 @@ export {
100
105
  } from "./config.js"
101
106
  export * from "./widget/index.js"
102
107
  export { logger, getMinLogLevel } from "./logger.js"
108
+ export {
109
+ getTrailsClient,
110
+ useTrailsClient,
111
+ TrailsClient,
112
+ } from "./trailsClient.js"
@@ -0,0 +1,253 @@
1
+ import type { Account, WalletClient, Hex, Address } from "viem"
2
+ import { intentEntrypoints } from "./constants.js"
3
+ import type { TrailsAPIClient } from "@0xsequence/trails-api"
4
+ import { signIntent } from "./gasless.js"
5
+
6
+ // Intent Entrypoint ABI (partial - only the functions we need)
7
+ // TODO: Uncomment and use when implementing calldata injection
8
+ /* const INTENT_ENTRYPOINT_ABI = [
9
+ {
10
+ name: "depositToIntent",
11
+ type: "function",
12
+ stateMutability: "nonpayable",
13
+ inputs: [
14
+ { name: "user", type: "address" },
15
+ { name: "token", type: "address" },
16
+ { name: "amount", type: "uint256" },
17
+ { name: "intentAddress", type: "address" },
18
+ { name: "deadline", type: "uint256" },
19
+ { name: "sigV", type: "uint8" },
20
+ { name: "sigR", type: "bytes32" },
21
+ { name: "sigS", type: "bytes32" },
22
+ ],
23
+ outputs: [],
24
+ },
25
+ {
26
+ name: "depositToIntentWithPermit",
27
+ type: "function",
28
+ stateMutability: "nonpayable",
29
+ inputs: [
30
+ { name: "user", type: "address" },
31
+ { name: "token", type: "address" },
32
+ { name: "amount", type: "uint256" },
33
+ { name: "permitAmount", type: "uint256" },
34
+ { name: "intentAddress", type: "address" },
35
+ { name: "deadline", type: "uint256" },
36
+ { name: "permitV", type: "uint8" },
37
+ { name: "permitR", type: "bytes32" },
38
+ { name: "permitS", type: "bytes32" },
39
+ { name: "sigV", type: "uint8" },
40
+ { name: "sigR", type: "bytes32" },
41
+ { name: "sigS", type: "bytes32" },
42
+ ],
43
+ outputs: [],
44
+ },
45
+ ] as const */
46
+
47
+ // Note: EIP-712 typed data signing has been replaced with raw message signing
48
+ // The backend generates the EIP-712 hash and the client signs it as a raw message
49
+ // This simplifies the flow and avoids wallet compatibility issues
50
+
51
+ export type IntentEntrypointDepositParams = {
52
+ userAddress: Address
53
+ tokenAddress: Address
54
+ amount: bigint | string
55
+ intentAddress: Address
56
+ chainId: number
57
+ deadline?: number // Unix timestamp, defaults to 1 hour from now
58
+ usePermit?: boolean
59
+ permitDeadline?: number
60
+ }
61
+
62
+ export type IntentEntrypointDepositResult = {
63
+ depositWalletAddress: Address
64
+ metaTxn: {
65
+ id: string
66
+ chainId: string
67
+ contract: string
68
+ input: string
69
+ walletAddress: string
70
+ }
71
+ feeQuote: string
72
+ entrypointAddress: Address
73
+ }
74
+
75
+ export type GaslessDepositOptions = {
76
+ trailsClient: TrailsAPIClient
77
+ walletClient: WalletClient
78
+ account: Account
79
+ tokenAddress: Address
80
+ amount: bigint | string
81
+ intentAddress: Address
82
+ chainId: number
83
+ deadline?: number
84
+ usePermit?: boolean
85
+ onStatusUpdate?: (status: DepositStatus) => void
86
+ }
87
+
88
+ export enum DepositStatus {
89
+ PREPARING = "preparing",
90
+ SIGNING = "signing",
91
+ SUBMITTING = "submitting",
92
+ PENDING = "pending",
93
+ CONFIRMED = "confirmed",
94
+ FAILED = "failed",
95
+ }
96
+
97
+ /**
98
+ * Execute a gasless deposit to an Intent Entrypoint
99
+ * This function handles the entire flow using the sign-first approach:
100
+ * 1. Gets message hash from API
101
+ * 2. User signs the message hash
102
+ * 3. Calls API with signature to get meta transaction
103
+ * 4. Submits meta transaction via relayer
104
+ */
105
+ export async function executeGaslessDeposit({
106
+ trailsClient,
107
+ walletClient,
108
+ account,
109
+ tokenAddress,
110
+ amount,
111
+ intentAddress,
112
+ chainId,
113
+ deadline,
114
+ usePermit = false,
115
+ onStatusUpdate,
116
+ }: GaslessDepositOptions): Promise<{
117
+ txHash: string | null
118
+ receipt: unknown
119
+ depositWalletAddress: Address
120
+ }> {
121
+ try {
122
+ // Update status
123
+ onStatusUpdate?.(DepositStatus.PREPARING)
124
+
125
+ // Default deadline to 1 hour from now
126
+ const effectiveDeadline = deadline || Math.floor(Date.now() / 1000) + 3600
127
+
128
+ // Convert amount to string if it's bigint
129
+ const amountStr = typeof amount === "bigint" ? amount.toString() : amount
130
+
131
+ // 1. Get the entrypoint address for this chain
132
+ const entrypointAddress = getIntentEntrypointAddress(chainId)
133
+ if (!entrypointAddress) {
134
+ throw new Error(`Intent Entrypoint not deployed on chain ${chainId}`)
135
+ }
136
+
137
+ // 2. User signs using EIP-712 typed data
138
+ onStatusUpdate?.(DepositStatus.SIGNING)
139
+ const { signature: intentSignature } = await signIntent({
140
+ client: walletClient,
141
+ intentParams: {
142
+ user: account.address,
143
+ token: tokenAddress,
144
+ amount: BigInt(amountStr),
145
+ intentAddress,
146
+ deadline: BigInt(effectiveDeadline),
147
+ chainId,
148
+ contractAddress: entrypointAddress,
149
+ },
150
+ })
151
+
152
+ // 3. Call the deposit endpoint with the signature
153
+ onStatusUpdate?.(DepositStatus.SUBMITTING)
154
+ const depositDataResponse = await trailsClient.getIntentEntrypointDeposit({
155
+ params: {
156
+ userAddress: account.address,
157
+ tokenAddress,
158
+ amount: amountStr,
159
+ intentAddress,
160
+ chainID: chainId,
161
+ deadline: effectiveDeadline,
162
+ intentSignature,
163
+ usePermit,
164
+ // TODO: Support permit signature
165
+ // permitSignature: permitSig,
166
+ // permitDeadline: usePermit ? effectiveDeadline : undefined,
167
+ },
168
+ })
169
+
170
+ const depositData = depositDataResponse.result
171
+
172
+ // 4. Submit meta transaction via relayer
173
+ // TODO: Implement relayer submission
174
+ // This would typically be done through the Sequence relayer
175
+ // const receipt = await relayer.sendMetaTxn({
176
+ // ...depositData.metaTxn,
177
+ // feeQuote: depositData.feeQuote,
178
+ // })
179
+
180
+ // For now, just return the deposit data
181
+ console.log("Deposit data ready:", depositData)
182
+
183
+ onStatusUpdate?.(DepositStatus.CONFIRMED)
184
+
185
+ return {
186
+ txHash: null, // Would come from relayer response
187
+ receipt: null, // Would come from relayer response
188
+ depositWalletAddress: depositData.depositWalletAddress as Address,
189
+ }
190
+ } catch (error) {
191
+ onStatusUpdate?.(DepositStatus.FAILED)
192
+ throw error
193
+ }
194
+ }
195
+
196
+ /**
197
+ * Inject signatures into the meta transaction calldata
198
+ * This updates the placeholder signature values in the Intent Entrypoint call
199
+ *
200
+ * TODO: Implement this function to properly update nested calldata
201
+ * This would require:
202
+ * 1. Decode the guest module execdata
203
+ * 2. Find the Intent Entrypoint call
204
+ * 3. Replace its calldata with properly signed version
205
+ * 4. Re-encode the guest module execdata
206
+ *
207
+ * For reference, the signed calldata can be generated using:
208
+ * ```typescript
209
+ * const { v, r, s } = splitSignature(signatures.intent)
210
+ * const depositCalldata = encodeFunctionData({
211
+ * abi: INTENT_ENTRYPOINT_ABI,
212
+ * functionName: "depositToIntent",
213
+ * args: [userAddress, tokenAddress, amount, intentAddress, deadline, v, r, s],
214
+ * })
215
+ * ```
216
+ */
217
+
218
+ /**
219
+ * Split a signature into v, r, s components
220
+ * TODO: Use this when implementing calldata injection
221
+ */
222
+ export function splitSignature(signature: Hex): {
223
+ v: number
224
+ r: Hex
225
+ s: Hex
226
+ } {
227
+ // Remove 0x prefix if present
228
+ const sig = signature.startsWith("0x") ? signature.slice(2) : signature
229
+
230
+ if (sig.length !== 130) {
231
+ throw new Error(`Invalid signature length: ${sig.length}`)
232
+ }
233
+
234
+ const r = `0x${sig.slice(0, 64)}` as Hex
235
+ const s = `0x${sig.slice(64, 128)}` as Hex
236
+ const v = parseInt(sig.slice(128, 130), 16)
237
+
238
+ return { v, r, s }
239
+ }
240
+
241
+ /**
242
+ * Get the Intent Entrypoint address for a given chain
243
+ */
244
+ export function getIntentEntrypointAddress(chainId: number): Address | null {
245
+ return (intentEntrypoints[chainId] as Address) || null
246
+ }
247
+
248
+ /**
249
+ * Check if Intent Entrypoint is deployed on a chain
250
+ */
251
+ export function isIntentEntrypointSupported(chainId: number): boolean {
252
+ return chainId in intentEntrypoints
253
+ }