imm-cli 0.1.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 (227) hide show
  1. package/README.md +315 -0
  2. package/dist/cli.d.ts +7 -0
  3. package/dist/cli.d.ts.map +1 -0
  4. package/dist/cli.js +112 -0
  5. package/dist/cli.js.map +1 -0
  6. package/dist/commands/config.d.ts +3 -0
  7. package/dist/commands/config.d.ts.map +1 -0
  8. package/dist/commands/config.js +251 -0
  9. package/dist/commands/config.js.map +1 -0
  10. package/dist/commands/immbook.d.ts +16 -0
  11. package/dist/commands/immbook.d.ts.map +1 -0
  12. package/dist/commands/immbook.js +795 -0
  13. package/dist/commands/immbook.js.map +1 -0
  14. package/dist/commands/jaine.d.ts +3 -0
  15. package/dist/commands/jaine.d.ts.map +1 -0
  16. package/dist/commands/jaine.js +1397 -0
  17. package/dist/commands/jaine.js.map +1 -0
  18. package/dist/commands/send.d.ts +3 -0
  19. package/dist/commands/send.d.ts.map +1 -0
  20. package/dist/commands/send.js +229 -0
  21. package/dist/commands/send.js.map +1 -0
  22. package/dist/commands/setup.d.ts +3 -0
  23. package/dist/commands/setup.d.ts.map +1 -0
  24. package/dist/commands/setup.js +83 -0
  25. package/dist/commands/setup.js.map +1 -0
  26. package/dist/commands/slop-app.d.ts +9 -0
  27. package/dist/commands/slop-app.d.ts.map +1 -0
  28. package/dist/commands/slop-app.js +793 -0
  29. package/dist/commands/slop-app.js.map +1 -0
  30. package/dist/commands/slop.d.ts +3 -0
  31. package/dist/commands/slop.d.ts.map +1 -0
  32. package/dist/commands/slop.js +1053 -0
  33. package/dist/commands/slop.js.map +1 -0
  34. package/dist/commands/wallet.d.ts +3 -0
  35. package/dist/commands/wallet.d.ts.map +1 -0
  36. package/dist/commands/wallet.js +298 -0
  37. package/dist/commands/wallet.js.map +1 -0
  38. package/dist/config/paths.d.ts +6 -0
  39. package/dist/config/paths.d.ts.map +1 -0
  40. package/dist/config/paths.js +24 -0
  41. package/dist/config/paths.js.map +1 -0
  42. package/dist/config/store.d.ts +44 -0
  43. package/dist/config/store.d.ts.map +1 -0
  44. package/dist/config/store.js +109 -0
  45. package/dist/config/store.js.map +1 -0
  46. package/dist/constants/chain.d.ts +56 -0
  47. package/dist/constants/chain.d.ts.map +1 -0
  48. package/dist/constants/chain.js +50 -0
  49. package/dist/constants/chain.js.map +1 -0
  50. package/dist/errors.d.ts +86 -0
  51. package/dist/errors.d.ts.map +1 -0
  52. package/dist/errors.js +100 -0
  53. package/dist/errors.js.map +1 -0
  54. package/dist/immbook/api.d.ts +38 -0
  55. package/dist/immbook/api.d.ts.map +1 -0
  56. package/dist/immbook/api.js +86 -0
  57. package/dist/immbook/api.js.map +1 -0
  58. package/dist/immbook/auth.d.ts +31 -0
  59. package/dist/immbook/auth.d.ts.map +1 -0
  60. package/dist/immbook/auth.js +93 -0
  61. package/dist/immbook/auth.js.map +1 -0
  62. package/dist/immbook/comments.d.ts +26 -0
  63. package/dist/immbook/comments.d.ts.map +1 -0
  64. package/dist/immbook/comments.js +20 -0
  65. package/dist/immbook/comments.js.map +1 -0
  66. package/dist/immbook/follows.d.ts +19 -0
  67. package/dist/immbook/follows.d.ts.map +1 -0
  68. package/dist/immbook/follows.js +21 -0
  69. package/dist/immbook/follows.js.map +1 -0
  70. package/dist/immbook/jwtCache.d.ts +15 -0
  71. package/dist/immbook/jwtCache.d.ts.map +1 -0
  72. package/dist/immbook/jwtCache.js +63 -0
  73. package/dist/immbook/jwtCache.js.map +1 -0
  74. package/dist/immbook/points.d.ts +35 -0
  75. package/dist/immbook/points.d.ts.map +1 -0
  76. package/dist/immbook/points.js +20 -0
  77. package/dist/immbook/points.js.map +1 -0
  78. package/dist/immbook/posts.d.ts +46 -0
  79. package/dist/immbook/posts.d.ts.map +1 -0
  80. package/dist/immbook/posts.js +43 -0
  81. package/dist/immbook/posts.js.map +1 -0
  82. package/dist/immbook/profile.d.ts +29 -0
  83. package/dist/immbook/profile.d.ts.map +1 -0
  84. package/dist/immbook/profile.js +14 -0
  85. package/dist/immbook/profile.js.map +1 -0
  86. package/dist/immbook/submolts.d.ts +22 -0
  87. package/dist/immbook/submolts.d.ts.map +1 -0
  88. package/dist/immbook/submolts.js +24 -0
  89. package/dist/immbook/submolts.js.map +1 -0
  90. package/dist/immbook/tradeProof.d.ts +21 -0
  91. package/dist/immbook/tradeProof.d.ts.map +1 -0
  92. package/dist/immbook/tradeProof.js +14 -0
  93. package/dist/immbook/tradeProof.js.map +1 -0
  94. package/dist/immbook/votes.d.ts +17 -0
  95. package/dist/immbook/votes.d.ts.map +1 -0
  96. package/dist/immbook/votes.js +20 -0
  97. package/dist/immbook/votes.js.map +1 -0
  98. package/dist/intents/store.d.ts +22 -0
  99. package/dist/intents/store.d.ts.map +1 -0
  100. package/dist/intents/store.js +76 -0
  101. package/dist/intents/store.js.map +1 -0
  102. package/dist/intents/types.d.ts +21 -0
  103. package/dist/intents/types.d.ts.map +1 -0
  104. package/dist/intents/types.js +2 -0
  105. package/dist/intents/types.js.map +1 -0
  106. package/dist/jaine/abi/erc20.d.ts +90 -0
  107. package/dist/jaine/abi/erc20.d.ts.map +1 -0
  108. package/dist/jaine/abi/erc20.js +65 -0
  109. package/dist/jaine/abi/erc20.js.map +1 -0
  110. package/dist/jaine/abi/factory.d.ts +38 -0
  111. package/dist/jaine/abi/factory.d.ts.map +1 -0
  112. package/dist/jaine/abi/factory.js +26 -0
  113. package/dist/jaine/abi/factory.js.map +1 -0
  114. package/dist/jaine/abi/index.d.ts +11 -0
  115. package/dist/jaine/abi/index.d.ts.map +1 -0
  116. package/dist/jaine/abi/index.js +11 -0
  117. package/dist/jaine/abi/index.js.map +1 -0
  118. package/dist/jaine/abi/nftManager.d.ts +282 -0
  119. package/dist/jaine/abi/nftManager.d.ts.map +1 -0
  120. package/dist/jaine/abi/nftManager.js +182 -0
  121. package/dist/jaine/abi/nftManager.js.map +1 -0
  122. package/dist/jaine/abi/pool.d.ts +77 -0
  123. package/dist/jaine/abi/pool.d.ts.map +1 -0
  124. package/dist/jaine/abi/pool.js +56 -0
  125. package/dist/jaine/abi/pool.js.map +1 -0
  126. package/dist/jaine/abi/quoter.d.ts +84 -0
  127. package/dist/jaine/abi/quoter.d.ts.map +1 -0
  128. package/dist/jaine/abi/quoter.js +53 -0
  129. package/dist/jaine/abi/quoter.js.map +1 -0
  130. package/dist/jaine/abi/router.d.ts +135 -0
  131. package/dist/jaine/abi/router.d.ts.map +1 -0
  132. package/dist/jaine/abi/router.js +88 -0
  133. package/dist/jaine/abi/router.js.map +1 -0
  134. package/dist/jaine/abi/w0g.d.ts +41 -0
  135. package/dist/jaine/abi/w0g.d.ts.map +1 -0
  136. package/dist/jaine/abi/w0g.js +34 -0
  137. package/dist/jaine/abi/w0g.js.map +1 -0
  138. package/dist/jaine/allowance.d.ts +48 -0
  139. package/dist/jaine/allowance.d.ts.map +1 -0
  140. package/dist/jaine/allowance.js +192 -0
  141. package/dist/jaine/allowance.js.map +1 -0
  142. package/dist/jaine/coreTokens.d.ts +32 -0
  143. package/dist/jaine/coreTokens.d.ts.map +1 -0
  144. package/dist/jaine/coreTokens.js +91 -0
  145. package/dist/jaine/coreTokens.js.map +1 -0
  146. package/dist/jaine/pathEncoding.d.ts +39 -0
  147. package/dist/jaine/pathEncoding.d.ts.map +1 -0
  148. package/dist/jaine/pathEncoding.js +98 -0
  149. package/dist/jaine/pathEncoding.js.map +1 -0
  150. package/dist/jaine/paths.d.ts +11 -0
  151. package/dist/jaine/paths.d.ts.map +1 -0
  152. package/dist/jaine/paths.js +20 -0
  153. package/dist/jaine/paths.js.map +1 -0
  154. package/dist/jaine/poolCache.d.ts +42 -0
  155. package/dist/jaine/poolCache.d.ts.map +1 -0
  156. package/dist/jaine/poolCache.js +164 -0
  157. package/dist/jaine/poolCache.js.map +1 -0
  158. package/dist/jaine/routing.d.ts +41 -0
  159. package/dist/jaine/routing.d.ts.map +1 -0
  160. package/dist/jaine/routing.js +247 -0
  161. package/dist/jaine/routing.js.map +1 -0
  162. package/dist/jaine/userTokens.d.ts +27 -0
  163. package/dist/jaine/userTokens.d.ts.map +1 -0
  164. package/dist/jaine/userTokens.js +89 -0
  165. package/dist/jaine/userTokens.js.map +1 -0
  166. package/dist/slop/abi/factory.d.ts +128 -0
  167. package/dist/slop/abi/factory.d.ts.map +1 -0
  168. package/dist/slop/abi/factory.js +70 -0
  169. package/dist/slop/abi/factory.js.map +1 -0
  170. package/dist/slop/abi/feeCollector.d.ts +95 -0
  171. package/dist/slop/abi/feeCollector.d.ts.map +1 -0
  172. package/dist/slop/abi/feeCollector.js +71 -0
  173. package/dist/slop/abi/feeCollector.js.map +1 -0
  174. package/dist/slop/abi/index.d.ts +5 -0
  175. package/dist/slop/abi/index.d.ts.map +1 -0
  176. package/dist/slop/abi/index.js +5 -0
  177. package/dist/slop/abi/index.js.map +1 -0
  178. package/dist/slop/abi/registry.d.ts +135 -0
  179. package/dist/slop/abi/registry.d.ts.map +1 -0
  180. package/dist/slop/abi/registry.js +90 -0
  181. package/dist/slop/abi/registry.js.map +1 -0
  182. package/dist/slop/abi/token.d.ts +320 -0
  183. package/dist/slop/abi/token.d.ts.map +1 -0
  184. package/dist/slop/abi/token.js +251 -0
  185. package/dist/slop/abi/token.js.map +1 -0
  186. package/dist/slop/quote.d.ts +80 -0
  187. package/dist/slop/quote.d.ts.map +1 -0
  188. package/dist/slop/quote.js +174 -0
  189. package/dist/slop/quote.js.map +1 -0
  190. package/dist/utils/canonicalJson.d.ts +8 -0
  191. package/dist/utils/canonicalJson.d.ts.map +1 -0
  192. package/dist/utils/canonicalJson.js +20 -0
  193. package/dist/utils/canonicalJson.js.map +1 -0
  194. package/dist/utils/env.d.ts +11 -0
  195. package/dist/utils/env.d.ts.map +1 -0
  196. package/dist/utils/env.js +20 -0
  197. package/dist/utils/env.js.map +1 -0
  198. package/dist/utils/http.d.ts +19 -0
  199. package/dist/utils/http.d.ts.map +1 -0
  200. package/dist/utils/http.js +61 -0
  201. package/dist/utils/http.js.map +1 -0
  202. package/dist/utils/logger.d.ts +4 -0
  203. package/dist/utils/logger.d.ts.map +1 -0
  204. package/dist/utils/logger.js +21 -0
  205. package/dist/utils/logger.js.map +1 -0
  206. package/dist/utils/output.d.ts +19 -0
  207. package/dist/utils/output.d.ts.map +1 -0
  208. package/dist/utils/output.js +37 -0
  209. package/dist/utils/output.js.map +1 -0
  210. package/dist/utils/respond.d.ts +19 -0
  211. package/dist/utils/respond.d.ts.map +1 -0
  212. package/dist/utils/respond.js +25 -0
  213. package/dist/utils/respond.js.map +1 -0
  214. package/dist/utils/ui.d.ts +38 -0
  215. package/dist/utils/ui.d.ts.map +1 -0
  216. package/dist/utils/ui.js +126 -0
  217. package/dist/utils/ui.js.map +1 -0
  218. package/dist/wallet/client.d.ts +4 -0
  219. package/dist/wallet/client.d.ts.map +1 -0
  220. package/dist/wallet/client.js +53 -0
  221. package/dist/wallet/client.js.map +1 -0
  222. package/dist/wallet/keystore.d.ts +21 -0
  223. package/dist/wallet/keystore.d.ts.map +1 -0
  224. package/dist/wallet/keystore.js +111 -0
  225. package/dist/wallet/keystore.js.map +1 -0
  226. package/package.json +56 -0
  227. package/skills/imm/SKILL.md +617 -0
@@ -0,0 +1,88 @@
1
+ /**
2
+ * Jaine (Uniswap V3) SwapRouter ABI - for executing swaps
3
+ */
4
+ export const ROUTER_ABI = [
5
+ {
6
+ type: "function",
7
+ name: "exactInput",
8
+ stateMutability: "payable",
9
+ inputs: [
10
+ {
11
+ name: "params",
12
+ type: "tuple",
13
+ components: [
14
+ { name: "path", type: "bytes" },
15
+ { name: "recipient", type: "address" },
16
+ { name: "deadline", type: "uint256" },
17
+ { name: "amountIn", type: "uint256" },
18
+ { name: "amountOutMinimum", type: "uint256" },
19
+ ],
20
+ },
21
+ ],
22
+ outputs: [{ name: "amountOut", type: "uint256" }],
23
+ },
24
+ {
25
+ type: "function",
26
+ name: "exactInputSingle",
27
+ stateMutability: "payable",
28
+ inputs: [
29
+ {
30
+ name: "params",
31
+ type: "tuple",
32
+ components: [
33
+ { name: "tokenIn", type: "address" },
34
+ { name: "tokenOut", type: "address" },
35
+ { name: "fee", type: "uint24" },
36
+ { name: "recipient", type: "address" },
37
+ { name: "deadline", type: "uint256" },
38
+ { name: "amountIn", type: "uint256" },
39
+ { name: "amountOutMinimum", type: "uint256" },
40
+ { name: "sqrtPriceLimitX96", type: "uint160" },
41
+ ],
42
+ },
43
+ ],
44
+ outputs: [{ name: "amountOut", type: "uint256" }],
45
+ },
46
+ {
47
+ type: "function",
48
+ name: "exactOutput",
49
+ stateMutability: "payable",
50
+ inputs: [
51
+ {
52
+ name: "params",
53
+ type: "tuple",
54
+ components: [
55
+ { name: "path", type: "bytes" },
56
+ { name: "recipient", type: "address" },
57
+ { name: "deadline", type: "uint256" },
58
+ { name: "amountOut", type: "uint256" },
59
+ { name: "amountInMaximum", type: "uint256" },
60
+ ],
61
+ },
62
+ ],
63
+ outputs: [{ name: "amountIn", type: "uint256" }],
64
+ },
65
+ {
66
+ type: "function",
67
+ name: "exactOutputSingle",
68
+ stateMutability: "payable",
69
+ inputs: [
70
+ {
71
+ name: "params",
72
+ type: "tuple",
73
+ components: [
74
+ { name: "tokenIn", type: "address" },
75
+ { name: "tokenOut", type: "address" },
76
+ { name: "fee", type: "uint24" },
77
+ { name: "recipient", type: "address" },
78
+ { name: "deadline", type: "uint256" },
79
+ { name: "amountOut", type: "uint256" },
80
+ { name: "amountInMaximum", type: "uint256" },
81
+ { name: "sqrtPriceLimitX96", type: "uint160" },
82
+ ],
83
+ },
84
+ ],
85
+ outputs: [{ name: "amountIn", type: "uint256" }],
86
+ },
87
+ ];
88
+ //# sourceMappingURL=router.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"router.js","sourceRoot":"","sources":["../../../src/jaine/abi/router.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB;QACE,IAAI,EAAE,UAAU;QAChB,IAAI,EAAE,YAAY;QAClB,eA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I,EAAE,SAAS,EAAE;oBAC5C,EAAE,IAAI,EAAE,mBAAmB,EAAE,IAAI,EAAE,SAAS,EAAE;iBAC/C;aACF;SACF;QACD,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;KACjD;CACO,CAAC"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Wrapped 0G (W0G) ABI - WETH9-style wrapper for native 0G token
3
+ */
4
+ export declare const W0G_ABI: readonly [{
5
+ readonly type: "function";
6
+ readonly name: "deposit";
7
+ readonly stateMutability: "payable";
8
+ readonly inputs: readonly [];
9
+ readonly outputs: readonly [];
10
+ }, {
11
+ readonly type: "function";
12
+ readonly name: "withdraw";
13
+ readonly stateMutability: "nonpayable";
14
+ readonly inputs: readonly [{
15
+ readonly name: "wad";
16
+ readonly type: "uint256";
17
+ }];
18
+ readonly outputs: readonly [];
19
+ }, {
20
+ readonly type: "function";
21
+ readonly name: "balanceOf";
22
+ readonly stateMutability: "view";
23
+ readonly inputs: readonly [{
24
+ readonly name: "account";
25
+ readonly type: "address";
26
+ }];
27
+ readonly outputs: readonly [{
28
+ readonly name: "";
29
+ readonly type: "uint256";
30
+ }];
31
+ }, {
32
+ readonly type: "function";
33
+ readonly name: "totalSupply";
34
+ readonly stateMutability: "view";
35
+ readonly inputs: readonly [];
36
+ readonly outputs: readonly [{
37
+ readonly name: "";
38
+ readonly type: "uint256";
39
+ }];
40
+ }];
41
+ //# sourceMappingURL=w0g.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"w0g.d.ts","sourceRoot":"","sources":["../../../src/jaine/abi/w0g.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA6BV,CAAC"}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Wrapped 0G (W0G) ABI - WETH9-style wrapper for native 0G token
3
+ */
4
+ export const W0G_ABI = [
5
+ {
6
+ type: "function",
7
+ name: "deposit",
8
+ stateMutability: "payable",
9
+ inputs: [],
10
+ outputs: [],
11
+ },
12
+ {
13
+ type: "function",
14
+ name: "withdraw",
15
+ stateMutability: "nonpayable",
16
+ inputs: [{ name: "wad", type: "uint256" }],
17
+ outputs: [],
18
+ },
19
+ {
20
+ type: "function",
21
+ name: "balanceOf",
22
+ stateMutability: "view",
23
+ inputs: [{ name: "account", type: "address" }],
24
+ outputs: [{ name: "", type: "uint256" }],
25
+ },
26
+ {
27
+ type: "function",
28
+ name: "totalSupply",
29
+ stateMutability: "view",
30
+ inputs: [],
31
+ outputs: [{ name: "", type: "uint256" }],
32
+ },
33
+ ];
34
+ //# sourceMappingURL=w0g.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"w0g.js","sourceRoot":"","sources":["../../../src/jaine/abi/w0g.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG;IACrB;QACE,IAAI,EAAE,UAAU;QAChB,IAAI,EAAE,SAAS;QACf,eAAe,EAAE,SAAS;QAC1B,MAAM,EAAE,EAAE;QACV,OAAO,EAAE,EAAE;KACZ;IACD;QACE,IAAI,EAAE,UAAU;QAChB,IAAI,EAAE,UAAU;QAChB,eAAe,EAAE,YAAY;QAC7B,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;QAC1C,OAAO,EAAE,EAAE;KACZ;IACD;QACE,IAAI,EAAE,UAAU;QAChB,IAAI,EAAE,WAAW;QACjB,eAAe,EAAE,MAAM;QACvB,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;QAC9C,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;KACzC;IACD;QACE,IAAI,EAAE,UAAU;QAChB,IAAI,EAAE,aAAa;QACnB,eAAe,EAAE,MAAM;QACvB,MAAM,EAAE,EAAE;QACV,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;KACzC;CACO,CAAC"}
@@ -0,0 +1,48 @@
1
+ import type { Address, Hex } from "viem";
2
+ /**
3
+ * Allowed spenders - only these addresses can be approved
4
+ */
5
+ export declare function getAllowedSpenders(): Record<string, Address>;
6
+ export type SpenderType = "router" | "nft";
7
+ /**
8
+ * Validate that spender is in the allowlist
9
+ */
10
+ export declare function validateSpender(spender: Address): void;
11
+ /**
12
+ * Get spender address by type
13
+ */
14
+ export declare function getSpenderAddress(spenderType: SpenderType): Address;
15
+ /**
16
+ * Get current allowance for a token
17
+ */
18
+ export declare function getAllowance(token: Address, owner: Address, spender: Address): Promise<bigint>;
19
+ /**
20
+ * Get allowances for both spenders
21
+ */
22
+ export declare function getAllAllowances(token: Address, owner: Address): Promise<Record<SpenderType, bigint>>;
23
+ export interface ApproveResult {
24
+ txHash: Hex;
25
+ resetTxHash?: Hex;
26
+ }
27
+ /**
28
+ * Safe approve with USDT-style reset handling
29
+ *
30
+ * Some tokens (like USDT) require setting allowance to 0 before
31
+ * setting a new non-zero allowance if current allowance is non-zero.
32
+ *
33
+ * @param token - Token address
34
+ * @param spender - Spender address (must be in allowlist)
35
+ * @param amount - Amount to approve (use maxUint256 for unlimited)
36
+ * @param privateKey - Private key for signing
37
+ * @returns Transaction hash(es)
38
+ */
39
+ export declare function safeApprove(token: Address, spender: Address, amount: bigint, privateKey: Hex): Promise<ApproveResult>;
40
+ /**
41
+ * Revoke approval (set to 0)
42
+ */
43
+ export declare function revokeApproval(token: Address, spender: Address, privateKey: Hex): Promise<Hex>;
44
+ /**
45
+ * Ensure allowance is sufficient, approve if needed
46
+ */
47
+ export declare function ensureAllowance(token: Address, spender: Address, requiredAmount: bigint, privateKey: Hex, approveExact?: boolean): Promise<ApproveResult | null>;
48
+ //# sourceMappingURL=allowance.d.ts.map
@@ -0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AE,MAAM,EACtB,UAAU,EAAE,GAAG,EACf,YAAY,GAAE,OAAe,GAC5B,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC,CAU/B"}
@@ -0,0 +1,192 @@
1
+ import { maxUint256, getAddress } from "viem";
2
+ import { createWalletClient, http } from "viem";
3
+ import { privateKeyToAccount } from "viem/accounts";
4
+ import { ERC20_EXTENDED_ABI } from "./abi/erc20.js";
5
+ import { getPublicClient } from "../wallet/client.js";
6
+ import { loadConfig } from "../config/store.js";
7
+ import { ImmError, ErrorCodes } from "../errors.js";
8
+ import logger from "../utils/logger.js";
9
+ /**
10
+ * Allowed spenders - only these addresses can be approved
11
+ */
12
+ export function getAllowedSpenders() {
13
+ const cfg = loadConfig();
14
+ return {
15
+ router: cfg.protocol.jaineRouter,
16
+ nft: cfg.protocol.nftPositionManager,
17
+ };
18
+ }
19
+ /**
20
+ * Validate that spender is in the allowlist
21
+ */
22
+ export function validateSpender(spender) {
23
+ const allowed = getAllowedSpenders();
24
+ const isAllowed = Object.values(allowed).some((addr) => getAddress(addr) === getAddress(spender));
25
+ if (!isAllowed) {
26
+ throw new ImmError(ErrorCodes.INVALID_SPENDER, `Spender ${spender} is not in allowlist`, `Allowed spenders: router (${allowed.router}), nft (${allowed.nft})`);
27
+ }
28
+ }
29
+ /**
30
+ * Get spender address by type
31
+ */
32
+ export function getSpenderAddress(spenderType) {
33
+ const allowed = getAllowedSpenders();
34
+ return allowed[spenderType];
35
+ }
36
+ /**
37
+ * Get current allowance for a token
38
+ */
39
+ export async function getAllowance(token, owner, spender) {
40
+ const client = getPublicClient();
41
+ const allowance = await client.readContract({
42
+ address: token,
43
+ abi: ERC20_EXTENDED_ABI,
44
+ functionName: "allowance",
45
+ args: [owner, spender],
46
+ });
47
+ return allowance;
48
+ }
49
+ /**
50
+ * Get allowances for both spenders
51
+ */
52
+ export async function getAllAllowances(token, owner) {
53
+ const allowed = getAllowedSpenders();
54
+ const client = getPublicClient();
55
+ const [routerAllowance, nftAllowance] = await Promise.all([
56
+ client.readContract({
57
+ address: token,
58
+ abi: ERC20_EXTENDED_ABI,
59
+ functionName: "allowance",
60
+ args: [owner, allowed.router],
61
+ }),
62
+ client.readContract({
63
+ address: token,
64
+ abi: ERC20_EXTENDED_ABI,
65
+ functionName: "allowance",
66
+ args: [owner, allowed.nft],
67
+ }),
68
+ ]);
69
+ return {
70
+ router: routerAllowance,
71
+ nft: nftAllowance,
72
+ };
73
+ }
74
+ /**
75
+ * Safe approve with USDT-style reset handling
76
+ *
77
+ * Some tokens (like USDT) require setting allowance to 0 before
78
+ * setting a new non-zero allowance if current allowance is non-zero.
79
+ *
80
+ * @param token - Token address
81
+ * @param spender - Spender address (must be in allowlist)
82
+ * @param amount - Amount to approve (use maxUint256 for unlimited)
83
+ * @param privateKey - Private key for signing
84
+ * @returns Transaction hash(es)
85
+ */
86
+ export async function safeApprove(token, spender, amount, privateKey) {
87
+ // Validate spender is in allowlist
88
+ validateSpender(spender);
89
+ const cfg = loadConfig();
90
+ const client = getPublicClient();
91
+ const account = privateKeyToAccount(privateKey);
92
+ const walletClient = createWalletClient({
93
+ account,
94
+ chain: {
95
+ id: cfg.chain.chainId,
96
+ name: "0G",
97
+ nativeCurrency: { name: "0G", symbol: "0G", decimals: 18 },
98
+ rpcUrls: { default: { http: [cfg.chain.rpcUrl] } },
99
+ },
100
+ transport: http(cfg.chain.rpcUrl, {
101
+ timeout: 30_000,
102
+ retryCount: 2,
103
+ }),
104
+ });
105
+ // Check current allowance
106
+ const currentAllowance = await getAllowance(token, account.address, spender);
107
+ // If current allowance is sufficient, no action needed
108
+ if (currentAllowance >= amount) {
109
+ logger.debug(`Allowance already sufficient: ${currentAllowance} >= ${amount}`);
110
+ return { txHash: "0x0" }; // No-op
111
+ }
112
+ let resetTxHash;
113
+ // If current allowance > 0 and < amount, reset to 0 first (USDT-style)
114
+ if (currentAllowance > 0n && currentAllowance < amount) {
115
+ logger.debug("Resetting allowance to 0 (USDT-style)");
116
+ try {
117
+ resetTxHash = await walletClient.writeContract({
118
+ address: token,
119
+ abi: ERC20_EXTENDED_ABI,
120
+ functionName: "approve",
121
+ args: [spender, 0n],
122
+ });
123
+ // Wait for reset tx to confirm
124
+ await client.waitForTransactionReceipt({ hash: resetTxHash });
125
+ }
126
+ catch (err) {
127
+ throw new ImmError(ErrorCodes.APPROVAL_FAILED, `Failed to reset allowance: ${err instanceof Error ? err.message : err}`);
128
+ }
129
+ }
130
+ // Approve the target amount
131
+ try {
132
+ const txHash = await walletClient.writeContract({
133
+ address: token,
134
+ abi: ERC20_EXTENDED_ABI,
135
+ functionName: "approve",
136
+ args: [spender, amount],
137
+ });
138
+ // Wait for approve tx to confirm before returning
139
+ await client.waitForTransactionReceipt({ hash: txHash });
140
+ return { txHash, resetTxHash };
141
+ }
142
+ catch (err) {
143
+ throw new ImmError(ErrorCodes.APPROVAL_FAILED, `Failed to approve: ${err instanceof Error ? err.message : err}`);
144
+ }
145
+ }
146
+ /**
147
+ * Revoke approval (set to 0)
148
+ */
149
+ export async function revokeApproval(token, spender, privateKey) {
150
+ // Validate spender is in allowlist
151
+ validateSpender(spender);
152
+ const cfg = loadConfig();
153
+ const account = privateKeyToAccount(privateKey);
154
+ const walletClient = createWalletClient({
155
+ account,
156
+ chain: {
157
+ id: cfg.chain.chainId,
158
+ name: "0G",
159
+ nativeCurrency: { name: "0G", symbol: "0G", decimals: 18 },
160
+ rpcUrls: { default: { http: [cfg.chain.rpcUrl] } },
161
+ },
162
+ transport: http(cfg.chain.rpcUrl, {
163
+ timeout: 30_000,
164
+ retryCount: 2,
165
+ }),
166
+ });
167
+ try {
168
+ const txHash = await walletClient.writeContract({
169
+ address: token,
170
+ abi: ERC20_EXTENDED_ABI,
171
+ functionName: "approve",
172
+ args: [spender, 0n],
173
+ });
174
+ return txHash;
175
+ }
176
+ catch (err) {
177
+ throw new ImmError(ErrorCodes.APPROVAL_FAILED, `Failed to revoke approval: ${err instanceof Error ? err.message : err}`);
178
+ }
179
+ }
180
+ /**
181
+ * Ensure allowance is sufficient, approve if needed
182
+ */
183
+ export async function ensureAllowance(token, spender, requiredAmount, privateKey, approveExact = false) {
184
+ const account = privateKeyToAccount(privateKey);
185
+ const currentAllowance = await getAllowance(token, account.address, spender);
186
+ if (currentAllowance >= requiredAmount) {
187
+ return null; // No approval needed
188
+ }
189
+ const approveAmount = approveExact ? requiredAmount : maxUint256;
190
+ return safeApprove(token, spender, approveAmount, privateKey);
191
+ }
192
+ //# sourceMappingURL=allowance.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"allowance.js","sourceRoot":"","sources":["../../src/jaine/allowance.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAC9C,OAAO,EAAE,kBAAkB,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAChD,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,MAAM,MAAM,oBAAoB,CAAC;AAExC;;GAEG;AACH,MAAM,UAAU,kBAAkB;IAChC,MAAM,GAAG,GAAG,UAAU,EAAE,CAAC;IACzB,OAAO;QACL,MAAM,EAAE,GAAG,CAAC,QAAQ,CAAC,WAAW;QAChC,GAAG,EAAE,GAAG,CAAC,QAAQ,CAAC,kBAAkB;KACrC,CAAC;AACJ,CAAC;AAID;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,OAAgB;IAC9C,MAAM,OAAO,GAAG,kBAAkB,EAAE,CAAC;IACrC,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAC3C,CAAC,IAAI,EAAE,EAA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,CAAC,eAAe,EAC1B,8BAA8B,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,CACzE,CAAC;IACJ,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,KAAc,EACd,OAAgB,EAChB,cAAsB,EACtB,UAAe,EACf,eAAwB,KAAK;IAE7B,MAAM,OAAO,GAAG,mBAAmB,CAAC,UAAU,CAAC,CAAC;IAChD,MAAM,gBAAgB,GAAG,MAAM,YAAY,CAAC,KAAK,EAAE,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAE7E,IAAI,gBAAgB,IAAI,cAAc,EAAE,CAAC;QACvC,OAAO,IAAI,CAAC,CAAC,qBAAqB;IACpC,CAAC;IAED,MAAM,aAAa,GAAG,YAAY,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,UAAU,CAAC;IACjE,OAAO,WAAW,CAAC,KAAK,EAAE,OAAO,EAAE,aAAa,EAAE,UAAU,CAAC,CAAC;AAChE,CAAC"}
@@ -0,0 +1,32 @@
1
+ import type { Address } from "viem";
2
+ /**
3
+ * Core tokens on 0G mainnet supported by Jaine DEX
4
+ * Addresses from MOLTBOT/jaine.md
5
+ */
6
+ export declare const CORE_TOKENS: Record<string, Address>;
7
+ /** List of core token symbols */
8
+ export declare const CORE_TOKEN_SYMBOLS: (keyof typeof CORE_TOKENS)[];
9
+ /**
10
+ * Resolve token symbol or address to checksummed address
11
+ * @param tokenOrSymbol - Token symbol (e.g., "USDC") or address (0x...)
12
+ * @param userAliases - Optional user-defined token aliases
13
+ * @returns Checksummed address
14
+ * @throws ImmError if token not found
15
+ */
16
+ export declare function resolveToken(tokenOrSymbol: string, userAliases?: Record<string, Address>): Address;
17
+ /**
18
+ * Get symbol for a token address (reverse lookup)
19
+ * @param address - Token address
20
+ * @param userAliases - Optional user-defined token aliases
21
+ * @returns Symbol if found, shortened address otherwise
22
+ */
23
+ export declare function getTokenSymbol(address: Address, userAliases?: Record<string, Address>): string;
24
+ /**
25
+ * Check if a token is a core token
26
+ */
27
+ export declare function isCoreToken(address: Address): boolean;
28
+ /**
29
+ * Get all core token addresses
30
+ */
31
+ export declare function getCoreTokenAddresses(): Address[];
32
+ //# sourceMappingURL=coreTokens.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"coreTokens.d.ts","sourceRoot":"","sources":["../../src/jaine/coreTokens.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAIpC;;;GAGG;AACH,eAAO,MAAM,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAatC,CAAC;AAEX,iCAAiC;AACjC,eAAO,MAAM,kBAAkB,EAA+B,CAAC,MAAM,OAAO,WAAW,CAAC,EAAE,CAAC;AAE3F;;;;;;GAMG;AACH,wBAAgB,YAAY,CAC1B,aAAa,EAAE,MAAM,EACrB,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACpC,OAAO,CA8BT;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAC5B,OAAO,EAAE,OAAO,EAChB,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACpC,MAAM,CAqBR;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAGrD;AAED;;GAEG;AACH,wBAAgB,qBAAqB,IAAI,OAAO,EAAE,CAEjD"}
@@ -0,0 +1,91 @@
1
+ import { isAddress, getAddress } from "viem";
2
+ import { ImmError, ErrorCodes } from "../errors.js";
3
+ /**
4
+ * Core tokens on 0G mainnet supported by Jaine DEX
5
+ * Addresses from MOLTBOT/jaine.md
6
+ */
7
+ export const CORE_TOKENS = {
8
+ USDC: "0x1f3aa82227281ca364bfb3d253b0f1af1da6473e",
9
+ WETH: "0x564770837ef8bbf077cfe54e5f6106538c815b22",
10
+ stgUSDT: "0x9FBBAFC2Ad79af2b57eD23C60DfF79eF5c2b0FB5",
11
+ stgUSDC: "0x8a2B28364102Bea189D99A475C494330Ef2bDD0B",
12
+ w0G: "0x1Cd0690fF9a693f5EF2dD976660a8dAFc81A109c",
13
+ st0G: "0x7bBC63D01CA42491c3E084C941c3E86e55951404",
14
+ wstETH: "0x161a128567BF0C005b58211757F7e46eed983F02",
15
+ PAI: "0x59ef6F3943bBdFE2fB19565037Ac85071223E94C",
16
+ oUSDT: "0x1217BfE6c773EEC6cc4A38b5Dc45B92292B6E189",
17
+ LINK: "0x76159c2b43ff6F630193e37EC68452169914C1Bb",
18
+ coinbaseBTC: "0xa5613ac7f1E83a68719b1398c8F6aAA25581db82",
19
+ HAIO: "0xbCB868d3d0A823ced82B77DD72E4f7A3C720A40E",
20
+ };
21
+ /** List of core token symbols */
22
+ export const CORE_TOKEN_SYMBOLS = Object.keys(CORE_TOKENS);
23
+ /**
24
+ * Resolve token symbol or address to checksummed address
25
+ * @param tokenOrSymbol - Token symbol (e.g., "USDC") or address (0x...)
26
+ * @param userAliases - Optional user-defined token aliases
27
+ * @returns Checksummed address
28
+ * @throws ImmError if token not found
29
+ */
30
+ export function resolveToken(tokenOrSymbol, userAliases) {
31
+ // If it's already a valid address, return checksummed
32
+ if (isAddress(tokenOrSymbol)) {
33
+ return getAddress(tokenOrSymbol);
34
+ }
35
+ // Normalize symbol to match case-insensitive
36
+ const upperSymbol = tokenOrSymbol.toUpperCase();
37
+ // Check user aliases first (they have priority)
38
+ if (userAliases) {
39
+ for (const [symbol, addr] of Object.entries(userAliases)) {
40
+ if (symbol.toUpperCase() === upperSymbol) {
41
+ return getAddress(addr);
42
+ }
43
+ }
44
+ }
45
+ // Check core tokens (case-insensitive)
46
+ for (const [symbol, addr] of Object.entries(CORE_TOKENS)) {
47
+ if (symbol.toUpperCase() === upperSymbol) {
48
+ return getAddress(addr);
49
+ }
50
+ }
51
+ throw new ImmError(ErrorCodes.TOKEN_NOT_FOUND, `Token not found: ${tokenOrSymbol}`, `Use a valid address or one of: ${CORE_TOKEN_SYMBOLS.join(", ")}`);
52
+ }
53
+ /**
54
+ * Get symbol for a token address (reverse lookup)
55
+ * @param address - Token address
56
+ * @param userAliases - Optional user-defined token aliases
57
+ * @returns Symbol if found, shortened address otherwise
58
+ */
59
+ export function getTokenSymbol(address, userAliases) {
60
+ const checksummed = getAddress(address);
61
+ // Check user aliases first
62
+ if (userAliases) {
63
+ for (const [symbol, addr] of Object.entries(userAliases)) {
64
+ if (getAddress(addr) === checksummed) {
65
+ return symbol;
66
+ }
67
+ }
68
+ }
69
+ // Check core tokens
70
+ for (const [symbol, addr] of Object.entries(CORE_TOKENS)) {
71
+ if (getAddress(addr) === checksummed) {
72
+ return symbol;
73
+ }
74
+ }
75
+ // Return shortened address if not found
76
+ return `${checksummed.slice(0, 6)}...${checksummed.slice(-4)}`;
77
+ }
78
+ /**
79
+ * Check if a token is a core token
80
+ */
81
+ export function isCoreToken(address) {
82
+ const checksummed = getAddress(address);
83
+ return Object.values(CORE_TOKENS).some((addr) => getAddress(addr) === checksummed);
84
+ }
85
+ /**
86
+ * Get all core token addresses
87
+ */
88
+ export function getCoreTokenAddresses() {
89
+ return Object.values(CORE_TOKENS).map((addr) => getAddress(addr));
90
+ }
91
+ //# sourceMappingURL=coreTokens.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"coreTokens.js","sourceRoot":"","sources":["../../src/jaine/coreTokens.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAEpD;;;GAGG;AACH,MAAM,CAAC,MAAM,WAAW,GAA4B;IAClD,IAAI,EAAE,4CAA4C;IAClD,IAAI,EAAE,4CAA4C;IAClD,OAAO,EAAE,4CAA4C;IACrD,OAAO,EAAE,4CAA4C;IACrD,GAAG,EAAE,4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39 @@
1
+ import type { Address, Hex } from "viem";
2
+ /**
3
+ * Encode path for Uniswap V3 exactInput
4
+ * Format: token0 + fee0 + token1 + fee1 + token2 + ...
5
+ *
6
+ * @param tokens - Array of token addresses in swap order
7
+ * @param fees - Array of fee tiers (length = tokens.length - 1)
8
+ * @returns Encoded path bytes
9
+ */
10
+ export declare function encodePath(tokens: Address[], fees: number[]): Hex;
11
+ /**
12
+ * Encode path for Uniswap V3 exactOutput
13
+ * Note: exactOutput requires REVERSED path (tokenOut first)
14
+ *
15
+ * @param tokens - Array of token addresses in swap order (tokenIn → tokenOut)
16
+ * @param fees - Array of fee tiers
17
+ * @returns Encoded path bytes (reversed for exactOutput)
18
+ */
19
+ export declare function encodePathForExactOutput(tokens: Address[], fees: number[]): Hex;
20
+ /**
21
+ * Decode path bytes into tokens and fees
22
+ *
23
+ * @param path - Encoded path bytes
24
+ * @returns Object with tokens array and fees array
25
+ */
26
+ export declare function decodePath(path: Hex): {
27
+ tokens: Address[];
28
+ fees: number[];
29
+ };
30
+ /**
31
+ * Calculate the number of hops in a path
32
+ */
33
+ export declare function getPathHops(tokens: Address[]): number;
34
+ /**
35
+ * Format path as human-readable string
36
+ * e.g., "USDC → [0.3%] → w0G → [0.05%] → WETH"
37
+ */
38
+ export declare function formatPath(tokens: Address[], fees: number[], getSymbol: (addr: Address) => string): string;
39
+ //# sourceMappingURL=pathEncoding.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pathEncoding.d.ts","sourceRoot":"","sources":["../../src/jaine/pathEncoding.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AAGzC;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,GAAG,CAwBjE;AAED;;;;;;;GAOG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,GAAG,CAK/E;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,GAAG,GAAG;IAAE,MAAM,EAAE,OAAO,EAAE,CAAC;IAAC,IAAI,EAAE,MAAM,EAAE,CAAA;CAAE,CA4B3E;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,CAErD;AAED;;;GAGG;AACH,wBAAgB,UAAU,CACxB,MAAM,EAAE,OAAO,EAAE,EACjB,IAAI,EAAE,MAAM,EAAE,EACd,SAAS,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,MAAM,GACnC,MAAM,CAaR"}