@wikialisalabs/evm-interop 0.0.0-stage → 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.
- package/LICENSE +33 -0
- package/package.json +28 -3
- package/src/abis.ts +400 -0
- package/src/index.ts +447 -0
- package/README.md +0 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 wikialisalabs (https://github.com/wikialisalabs)
|
|
4
|
+
Author & Founder: Nguyen Thi Thu Huong (wikialisa)
|
|
5
|
+
Technical Contact: wiki@axvn.vn
|
|
6
|
+
Organization: wikialisalabs
|
|
7
|
+
|
|
8
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
10
|
+
in the Software without restriction, including without limitation the rights
|
|
11
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
13
|
+
furnished to do so, subject to the following conditions:
|
|
14
|
+
|
|
15
|
+
The above copyright notice and this permission notice shall be included in all
|
|
16
|
+
copies or substantial portions of the Software.
|
|
17
|
+
|
|
18
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
24
|
+
SOFTWARE.
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
### Tóm tắt ý nghĩa của giấy phép MIT đối với tổ chức wikialisalabs:
|
|
29
|
+
|
|
30
|
+
* **Chuyển giao toàn diện bản quyền:** Quyền sở hữu trí tuệ và thương hiệu mã nguồn thuộc về tổ chức **wikialisalabs** do tác giả Nguyễn Thị Thu Hương sáng lập.
|
|
31
|
+
* **Tự do thương mại hóa tối đa:** Bất kỳ cá nhân hoặc tổ chức nào cũng có thể sử dụng, tích hợp và thương mại hóa mã nguồn của hệ sinh thái mà không bị rào cản BSL hay bản quyền đóng.
|
|
32
|
+
* **Tự do tùy biến & Đóng góp:** Cộng đồng được quyền fork, phát triển module mở rộng, tối ưu hóa các thành phần kiến trúc và đóng góp lại cho `wikialisalabs`.
|
|
33
|
+
* **Miễn trừ trách nhiệm pháp lý:** Tổ chức `wikialisalabs` và tác giả được miễn trừ toàn bộ trách nhiệm pháp lý đối với bất kỳ rủi ro vận hành hoặc tổn thất tài chính nào phát sinh từ việc sử dụng phần mềm.
|
package/package.json
CHANGED
|
@@ -1,6 +1,31 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wikialisalabs/evm-interop",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "EVM interop layer — ABI codegen, typed contract wrappers, wagmi hook factories",
|
|
5
|
+
"main": "src/index.ts",
|
|
6
|
+
"types": "src/index.ts",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"dependencies": {
|
|
9
|
+
"viem": "^2.17.0",
|
|
10
|
+
"wagmi": "^2.12.7"
|
|
11
|
+
},
|
|
12
|
+
"devDependencies": {
|
|
13
|
+
"typescript": "^5.5.4"
|
|
14
|
+
},
|
|
15
|
+
"peerDependencies": {
|
|
16
|
+
"react": ">=18"
|
|
17
|
+
},
|
|
18
|
+
"author": "wikialisa (Nguyen Thi Thu Huong) <wiki@axvn.vn>",
|
|
19
|
+
"publishConfig": {
|
|
20
|
+
"access": "public",
|
|
21
|
+
"registry": "https://registry.npmjs.org/"
|
|
22
|
+
},
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "https://github.com/wikialisalabs/evm-interop.git"
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "echo \"Source-only package — consumed by Next.js apps directly\"",
|
|
29
|
+
"clean": "rm -rf dist"
|
|
30
|
+
}
|
|
6
31
|
}
|
package/src/abis.ts
ADDED
|
@@ -0,0 +1,400 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @axioledger/evm-interop — ABI catalogue
|
|
3
|
+
*
|
|
4
|
+
* One canonical place for every contract ABI used across the monorepo.
|
|
5
|
+
* Import what you need; tree-shaking removes the rest in bundled apps.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
// ── AXQToken ─────────────────────────────────────────────────────────────────
|
|
9
|
+
|
|
10
|
+
export const AXQ_TOKEN_ABI = [
|
|
11
|
+
// ERC-20 reads
|
|
12
|
+
{ name: 'name', type: 'function', stateMutability: 'view',
|
|
13
|
+
inputs: [], outputs: [{ type: 'string' }] },
|
|
14
|
+
{ name: 'symbol', type: 'function', stateMutability: 'view',
|
|
15
|
+
inputs: [], outputs: [{ type: 'string' }] },
|
|
16
|
+
{ name: 'decimals', type: 'function', stateMutability: 'view',
|
|
17
|
+
inputs: [], outputs: [{ type: 'uint8' }] },
|
|
18
|
+
{ name: 'totalSupply', type: 'function', stateMutability: 'view',
|
|
19
|
+
inputs: [], outputs: [{ type: 'uint256' }] },
|
|
20
|
+
{ name: 'balanceOf', type: 'function', stateMutability: 'view',
|
|
21
|
+
inputs: [{ name: 'account', type: 'address' }], outputs: [{ type: 'uint256' }] },
|
|
22
|
+
{ name: 'allowance', type: 'function', stateMutability: 'view',
|
|
23
|
+
inputs: [{ name: 'owner', type: 'address' }, { name: 'spender', type: 'address' }],
|
|
24
|
+
outputs: [{ type: 'uint256' }] },
|
|
25
|
+
// ERC-20 writes
|
|
26
|
+
{ name: 'transfer', type: 'function', stateMutability: 'nonpayable',
|
|
27
|
+
inputs: [{ name: 'to', type: 'address' }, { name: 'amount', type: 'uint256' }],
|
|
28
|
+
outputs: [{ type: 'bool' }] },
|
|
29
|
+
{ name: 'approve', type: 'function', stateMutability: 'nonpayable',
|
|
30
|
+
inputs: [{ name: 'spender', type: 'address' }, { name: 'amount', type: 'uint256' }],
|
|
31
|
+
outputs: [{ type: 'bool' }] },
|
|
32
|
+
{ name: 'transferFrom', type: 'function', stateMutability: 'nonpayable',
|
|
33
|
+
inputs: [{ name: 'from', type: 'address' }, { name: 'to', type: 'address' }, { name: 'amount', type: 'uint256' }],
|
|
34
|
+
outputs: [{ type: 'bool' }] },
|
|
35
|
+
// AXQToken-specific
|
|
36
|
+
{ name: 'genesisAllocate', type: 'function', stateMutability: 'nonpayable',
|
|
37
|
+
inputs: [], outputs: [] },
|
|
38
|
+
{ name: 'TOTAL_SUPPLY', type: 'function', stateMutability: 'view',
|
|
39
|
+
inputs: [], outputs: [{ type: 'uint256' }] },
|
|
40
|
+
// Events
|
|
41
|
+
{ name: 'Transfer', type: 'event',
|
|
42
|
+
inputs: [
|
|
43
|
+
{ name: 'from', type: 'address', indexed: true },
|
|
44
|
+
{ name: 'to', type: 'address', indexed: true },
|
|
45
|
+
{ name: 'value', type: 'uint256', indexed: false },
|
|
46
|
+
] },
|
|
47
|
+
{ name: 'Approval', type: 'event',
|
|
48
|
+
inputs: [
|
|
49
|
+
{ name: 'owner', type: 'address', indexed: true },
|
|
50
|
+
{ name: 'spender', type: 'address', indexed: true },
|
|
51
|
+
{ name: 'value', type: 'uint256', indexed: false },
|
|
52
|
+
] },
|
|
53
|
+
] as const;
|
|
54
|
+
|
|
55
|
+
// ── AXQGovernance ─────────────────────────────────────────────────────────────
|
|
56
|
+
|
|
57
|
+
export const AXQ_GOVERNANCE_ABI = [
|
|
58
|
+
// Constants / state reads
|
|
59
|
+
{ name: 'VOTING_PERIOD', type: 'function', stateMutability: 'view', inputs: [], outputs: [{ type: 'uint64' }] },
|
|
60
|
+
{ name: 'TIME_LOCK_PERIOD', type: 'function', stateMutability: 'view', inputs: [], outputs: [{ type: 'uint64' }] },
|
|
61
|
+
{ name: 'PROPOSAL_THRESHOLD', type: 'function', stateMutability: 'view', inputs: [], outputs: [{ type: 'uint256' }] },
|
|
62
|
+
{ name: 'QUORUM_VOTES', type: 'function', stateMutability: 'view', inputs: [], outputs: [{ type: 'uint256' }] },
|
|
63
|
+
{ name: 'proposalCount', type: 'function', stateMutability: 'view', inputs: [], outputs: [{ type: 'uint256' }] },
|
|
64
|
+
{ name: 'AXQ_TOKEN', type: 'function', stateMutability: 'view', inputs: [], outputs: [{ type: 'address' }] },
|
|
65
|
+
{ name: 'treasury', type: 'function', stateMutability: 'view', inputs: [], outputs: [{ type: 'address' }] },
|
|
66
|
+
{
|
|
67
|
+
name: 'proposals',
|
|
68
|
+
type: 'function', stateMutability: 'view',
|
|
69
|
+
inputs: [{ name: 'id', type: 'uint256' }],
|
|
70
|
+
outputs: [
|
|
71
|
+
{ name: 'id', type: 'uint256' },
|
|
72
|
+
{ name: 'proposer', type: 'address' },
|
|
73
|
+
{ name: 'description', type: 'string' },
|
|
74
|
+
{ name: 'callData', type: 'bytes' },
|
|
75
|
+
{ name: 'target', type: 'address' },
|
|
76
|
+
{ name: 'value', type: 'uint256' },
|
|
77
|
+
{ name: 'voteStart', type: 'uint64' },
|
|
78
|
+
{ name: 'voteEnd', type: 'uint64' },
|
|
79
|
+
{ name: 'executionTime', type: 'uint64' },
|
|
80
|
+
{ name: 'votesFor', type: 'uint256' },
|
|
81
|
+
{ name: 'votesAgainst', type: 'uint256' },
|
|
82
|
+
{ name: 'executed', type: 'bool' },
|
|
83
|
+
{ name: 'vetoed', type: 'bool' },
|
|
84
|
+
],
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
name: 'hasVoted',
|
|
88
|
+
type: 'function', stateMutability: 'view',
|
|
89
|
+
inputs: [{ name: 'id', type: 'uint256' }, { name: 'voter', type: 'address' }],
|
|
90
|
+
outputs: [{ type: 'bool' }],
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
name: 'vetoCount',
|
|
94
|
+
type: 'function', stateMutability: 'view',
|
|
95
|
+
inputs: [{ name: 'id', type: 'uint256' }],
|
|
96
|
+
outputs: [{ type: 'uint8' }],
|
|
97
|
+
},
|
|
98
|
+
// Writes
|
|
99
|
+
{
|
|
100
|
+
name: 'propose',
|
|
101
|
+
type: 'function', stateMutability: 'nonpayable',
|
|
102
|
+
inputs: [
|
|
103
|
+
{ name: 'target', type: 'address' },
|
|
104
|
+
{ name: 'value', type: 'uint256' },
|
|
105
|
+
{ name: 'callData', type: 'bytes' },
|
|
106
|
+
{ name: 'description', type: 'string' },
|
|
107
|
+
],
|
|
108
|
+
outputs: [{ type: 'uint256' }],
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
name: 'castVote',
|
|
112
|
+
type: 'function', stateMutability: 'nonpayable',
|
|
113
|
+
inputs: [{ name: 'id', type: 'uint256' }, { name: 'support', type: 'bool' }],
|
|
114
|
+
outputs: [],
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
name: 'queue',
|
|
118
|
+
type: 'function', stateMutability: 'nonpayable',
|
|
119
|
+
inputs: [{ name: 'id', type: 'uint256' }],
|
|
120
|
+
outputs: [],
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
name: 'execute',
|
|
124
|
+
type: 'function', stateMutability: 'payable',
|
|
125
|
+
inputs: [{ name: 'id', type: 'uint256' }],
|
|
126
|
+
outputs: [],
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
name: 'vetoVote',
|
|
130
|
+
type: 'function', stateMutability: 'nonpayable',
|
|
131
|
+
inputs: [{ name: 'id', type: 'uint256' }],
|
|
132
|
+
outputs: [],
|
|
133
|
+
},
|
|
134
|
+
// Events
|
|
135
|
+
{ name: 'ProposalCreated', type: 'event',
|
|
136
|
+
inputs: [
|
|
137
|
+
{ name: 'id', type: 'uint256', indexed: true },
|
|
138
|
+
{ name: 'proposer', type: 'address', indexed: false },
|
|
139
|
+
{ name: 'description', type: 'string', indexed: false },
|
|
140
|
+
] },
|
|
141
|
+
{ name: 'VoteCast', type: 'event',
|
|
142
|
+
inputs: [
|
|
143
|
+
{ name: 'id', type: 'uint256', indexed: true },
|
|
144
|
+
{ name: 'voter', type: 'address', indexed: false },
|
|
145
|
+
{ name: 'support', type: 'bool', indexed: false },
|
|
146
|
+
{ name: 'weight', type: 'uint256', indexed: false },
|
|
147
|
+
] },
|
|
148
|
+
{ name: 'ProposalQueued', type: 'event',
|
|
149
|
+
inputs: [
|
|
150
|
+
{ name: 'id', type: 'uint256', indexed: true },
|
|
151
|
+
{ name: 'executionTime', type: 'uint64', indexed: false },
|
|
152
|
+
] },
|
|
153
|
+
{ name: 'ProposalExecuted', type: 'event',
|
|
154
|
+
inputs: [{ name: 'id', type: 'uint256', indexed: true }] },
|
|
155
|
+
{ name: 'ProposalVetoed', type: 'event',
|
|
156
|
+
inputs: [
|
|
157
|
+
{ name: 'id', type: 'uint256', indexed: true },
|
|
158
|
+
{ name: 'guardian', type: 'address', indexed: false },
|
|
159
|
+
{ name: 'vetoCount', type: 'uint8', indexed: false },
|
|
160
|
+
] },
|
|
161
|
+
] as const;
|
|
162
|
+
|
|
163
|
+
// ── ANSRegistry ───────────────────────────────────────────────────────────────
|
|
164
|
+
|
|
165
|
+
export const ANS_REGISTRY_ABI = [
|
|
166
|
+
// reads
|
|
167
|
+
{ name: 'records', type: 'function', stateMutability: 'view',
|
|
168
|
+
inputs: [{ name: 'nameHash', type: 'bytes32' }],
|
|
169
|
+
outputs: [
|
|
170
|
+
{ name: 'owner', type: 'address' },
|
|
171
|
+
{ name: 'resolver', type: 'address' },
|
|
172
|
+
{ name: 'expiry', type: 'uint64' },
|
|
173
|
+
{ name: 'locked', type: 'bool' },
|
|
174
|
+
] },
|
|
175
|
+
{ name: 'resolve', type: 'function', stateMutability: 'view',
|
|
176
|
+
inputs: [{ name: 'label', type: 'string' }, { name: 'tld', type: 'string' }],
|
|
177
|
+
outputs: [{ type: 'address' }] },
|
|
178
|
+
{ name: 'getResolver', type: 'function', stateMutability: 'view',
|
|
179
|
+
inputs: [{ name: 'label', type: 'string' }, { name: 'tld', type: 'string' }],
|
|
180
|
+
outputs: [{ type: 'address' }] },
|
|
181
|
+
{ name: 'tldFees', type: 'function', stateMutability: 'view',
|
|
182
|
+
inputs: [{ name: 'tldHash', type: 'bytes32' }], outputs: [{ type: 'uint256' }] },
|
|
183
|
+
{ name: 'supportedTlds', type: 'function', stateMutability: 'view',
|
|
184
|
+
inputs: [{ name: 'tldHash', type: 'bytes32' }], outputs: [{ type: 'bool' }] },
|
|
185
|
+
// writes
|
|
186
|
+
{ name: 'register', type: 'function', stateMutability: 'payable',
|
|
187
|
+
inputs: [
|
|
188
|
+
{ name: 'label', type: 'string' },
|
|
189
|
+
{ name: 'tld', type: 'string' },
|
|
190
|
+
{ name: 'resolver', type: 'address' },
|
|
191
|
+
], outputs: [] },
|
|
192
|
+
{ name: 'renew', type: 'function', stateMutability: 'payable',
|
|
193
|
+
inputs: [{ name: 'label', type: 'string' }, { name: 'tld', type: 'string' }],
|
|
194
|
+
outputs: [] },
|
|
195
|
+
{ name: 'setResolver', type: 'function', stateMutability: 'nonpayable',
|
|
196
|
+
inputs: [
|
|
197
|
+
{ name: 'label', type: 'string' },
|
|
198
|
+
{ name: 'tld', type: 'string' },
|
|
199
|
+
{ name: 'resolver', type: 'address' },
|
|
200
|
+
], outputs: [] },
|
|
201
|
+
{ name: 'transfer', type: 'function', stateMutability: 'nonpayable',
|
|
202
|
+
inputs: [
|
|
203
|
+
{ name: 'label', type: 'string' },
|
|
204
|
+
{ name: 'tld', type: 'string' },
|
|
205
|
+
{ name: 'to', type: 'address' },
|
|
206
|
+
], outputs: [] },
|
|
207
|
+
// events
|
|
208
|
+
{ name: 'NameRegistered', type: 'event',
|
|
209
|
+
inputs: [
|
|
210
|
+
{ name: 'nameHash', type: 'bytes32', indexed: true },
|
|
211
|
+
{ name: 'label', type: 'string', indexed: false },
|
|
212
|
+
{ name: 'tld', type: 'string', indexed: false },
|
|
213
|
+
{ name: 'owner', type: 'address', indexed: false },
|
|
214
|
+
{ name: 'expiry', type: 'uint64', indexed: false },
|
|
215
|
+
] },
|
|
216
|
+
{ name: 'NameRenewed', type: 'event',
|
|
217
|
+
inputs: [
|
|
218
|
+
{ name: 'nameHash', type: 'bytes32', indexed: true },
|
|
219
|
+
{ name: 'newExpiry', type: 'uint64', indexed: false },
|
|
220
|
+
] },
|
|
221
|
+
] as const;
|
|
222
|
+
|
|
223
|
+
// ── KPXLiquidityPool ──────────────────────────────────────────────────────────
|
|
224
|
+
|
|
225
|
+
export const KPX_LIQUIDITY_POOL_ABI = [
|
|
226
|
+
// reads
|
|
227
|
+
{ name: 'TOKEN_A', type: 'function', stateMutability: 'view', inputs: [], outputs: [{ type: 'address' }] },
|
|
228
|
+
{ name: 'TOKEN_B', type: 'function', stateMutability: 'view', inputs: [], outputs: [{ type: 'address' }] },
|
|
229
|
+
{ name: 'reserveA', type: 'function', stateMutability: 'view', inputs: [], outputs: [{ type: 'uint256' }] },
|
|
230
|
+
{ name: 'reserveB', type: 'function', stateMutability: 'view', inputs: [], outputs: [{ type: 'uint256' }] },
|
|
231
|
+
{ name: 'totalSupply', type: 'function', stateMutability: 'view', inputs: [], outputs: [{ type: 'uint256' }] },
|
|
232
|
+
{ name: 'balanceOf', type: 'function', stateMutability: 'view',
|
|
233
|
+
inputs: [{ name: 'account', type: 'address' }], outputs: [{ type: 'uint256' }] },
|
|
234
|
+
{ name: 'priceAInB', type: 'function', stateMutability: 'view', inputs: [], outputs: [{ type: 'uint256' }] },
|
|
235
|
+
{ name: 'getAmountOut', type: 'function', stateMutability: 'view',
|
|
236
|
+
inputs: [{ name: 'amountIn', type: 'uint256' }, { name: 'tokenIn', type: 'address' }],
|
|
237
|
+
outputs: [{ type: 'uint256' }] },
|
|
238
|
+
// writes
|
|
239
|
+
{ name: 'addLiquidity', type: 'function', stateMutability: 'nonpayable',
|
|
240
|
+
inputs: [
|
|
241
|
+
{ name: 'amountADesired', type: 'uint256' },
|
|
242
|
+
{ name: 'amountBDesired', type: 'uint256' },
|
|
243
|
+
{ name: 'amountAMin', type: 'uint256' },
|
|
244
|
+
{ name: 'amountBMin', type: 'uint256' },
|
|
245
|
+
{ name: 'to', type: 'address' },
|
|
246
|
+
],
|
|
247
|
+
outputs: [
|
|
248
|
+
{ name: 'amountA', type: 'uint256' },
|
|
249
|
+
{ name: 'amountB', type: 'uint256' },
|
|
250
|
+
{ name: 'liquidity', type: 'uint256' },
|
|
251
|
+
] },
|
|
252
|
+
{ name: 'removeLiquidity', type: 'function', stateMutability: 'nonpayable',
|
|
253
|
+
inputs: [
|
|
254
|
+
{ name: 'lpAmount', type: 'uint256' },
|
|
255
|
+
{ name: 'amountAMin', type: 'uint256' },
|
|
256
|
+
{ name: 'amountBMin', type: 'uint256' },
|
|
257
|
+
{ name: 'to', type: 'address' },
|
|
258
|
+
],
|
|
259
|
+
outputs: [
|
|
260
|
+
{ name: 'amountA', type: 'uint256' },
|
|
261
|
+
{ name: 'amountB', type: 'uint256' },
|
|
262
|
+
] },
|
|
263
|
+
{ name: 'swapExactIn', type: 'function', stateMutability: 'nonpayable',
|
|
264
|
+
inputs: [
|
|
265
|
+
{ name: 'tokenIn', type: 'address' },
|
|
266
|
+
{ name: 'amountIn', type: 'uint256' },
|
|
267
|
+
{ name: 'amountOutMin', type: 'uint256' },
|
|
268
|
+
{ name: 'to', type: 'address' },
|
|
269
|
+
],
|
|
270
|
+
outputs: [{ name: 'amountOut', type: 'uint256' }] },
|
|
271
|
+
// events
|
|
272
|
+
{ name: 'Swap', type: 'event',
|
|
273
|
+
inputs: [
|
|
274
|
+
{ name: 'sender', type: 'address', indexed: true },
|
|
275
|
+
{ name: 'tokenIn', type: 'address', indexed: false },
|
|
276
|
+
{ name: 'amountIn', type: 'uint256', indexed: false },
|
|
277
|
+
{ name: 'amountOut', type: 'uint256', indexed: false },
|
|
278
|
+
{ name: 'to', type: 'address', indexed: true },
|
|
279
|
+
] },
|
|
280
|
+
{ name: 'LiquidityAdded', type: 'event',
|
|
281
|
+
inputs: [
|
|
282
|
+
{ name: 'provider', type: 'address', indexed: true },
|
|
283
|
+
{ name: 'amountA', type: 'uint256', indexed: false },
|
|
284
|
+
{ name: 'amountB', type: 'uint256', indexed: false },
|
|
285
|
+
{ name: 'lpMinted', type: 'uint256', indexed: false },
|
|
286
|
+
] },
|
|
287
|
+
{ name: 'LiquidityRemoved', type: 'event',
|
|
288
|
+
inputs: [
|
|
289
|
+
{ name: 'provider', type: 'address', indexed: true },
|
|
290
|
+
{ name: 'amountA', type: 'uint256', indexed: false },
|
|
291
|
+
{ name: 'amountB', type: 'uint256', indexed: false },
|
|
292
|
+
{ name: 'lpBurned', type: 'uint256', indexed: false },
|
|
293
|
+
] },
|
|
294
|
+
] as const;
|
|
295
|
+
|
|
296
|
+
// ── VRQPasskeyValidator ───────────────────────────────────────────────────────
|
|
297
|
+
|
|
298
|
+
export const VRQ_PASSKEY_VALIDATOR_ABI = [
|
|
299
|
+
// reads
|
|
300
|
+
{ name: 'isModuleType', type: 'function', stateMutability: 'pure',
|
|
301
|
+
inputs: [{ name: 'moduleTypeId', type: 'uint256' }], outputs: [{ type: 'bool' }] },
|
|
302
|
+
{ name: 'isInitialized', type: 'function', stateMutability: 'view',
|
|
303
|
+
inputs: [{ name: 'smartAccount', type: 'address' }], outputs: [{ type: 'bool' }] },
|
|
304
|
+
{ name: 'accountPubKeyX', type: 'function', stateMutability: 'view',
|
|
305
|
+
inputs: [{ name: 'account', type: 'address' }], outputs: [{ type: 'uint256' }] },
|
|
306
|
+
{ name: 'accountPubKeyY', type: 'function', stateMutability: 'view',
|
|
307
|
+
inputs: [{ name: 'account', type: 'address' }], outputs: [{ type: 'uint256' }] },
|
|
308
|
+
{ name: 'zkVerifier', type: 'function', stateMutability: 'view',
|
|
309
|
+
inputs: [], outputs: [{ type: 'address' }] },
|
|
310
|
+
// ERC-1271
|
|
311
|
+
{ name: 'isValidSignatureWithSender', type: 'function', stateMutability: 'view',
|
|
312
|
+
inputs: [
|
|
313
|
+
{ name: 'sender', type: 'address' },
|
|
314
|
+
{ name: 'hash', type: 'bytes32' },
|
|
315
|
+
{ name: 'data', type: 'bytes' },
|
|
316
|
+
], outputs: [{ name: '', type: 'bytes4' }] },
|
|
317
|
+
// ERC-7579 lifecycle
|
|
318
|
+
{ name: 'onInstall', type: 'function', stateMutability: 'payable',
|
|
319
|
+
inputs: [{ name: 'data', type: 'bytes' }], outputs: [] },
|
|
320
|
+
{ name: 'onUninstall', type: 'function', stateMutability: 'payable',
|
|
321
|
+
inputs: [{ name: 'data', type: 'bytes' }], outputs: [] },
|
|
322
|
+
// ERC-4337 validation
|
|
323
|
+
{ name: 'validateUserOp', type: 'function', stateMutability: 'payable',
|
|
324
|
+
inputs: [
|
|
325
|
+
{
|
|
326
|
+
name: 'userOp', type: 'tuple',
|
|
327
|
+
components: [
|
|
328
|
+
{ name: 'sender', type: 'address' },
|
|
329
|
+
{ name: 'nonce', type: 'uint256' },
|
|
330
|
+
{ name: 'initCode', type: 'bytes' },
|
|
331
|
+
{ name: 'callData', type: 'bytes' },
|
|
332
|
+
{ name: 'accountGasLimits', type: 'bytes32' },
|
|
333
|
+
{ name: 'preVerificationGas', type: 'uint256' },
|
|
334
|
+
{ name: 'gasFees', type: 'bytes32' },
|
|
335
|
+
{ name: 'paymasterAndData', type: 'bytes' },
|
|
336
|
+
{ name: 'signature', type: 'bytes' },
|
|
337
|
+
],
|
|
338
|
+
},
|
|
339
|
+
{ name: 'userOpHash', type: 'bytes32' },
|
|
340
|
+
],
|
|
341
|
+
outputs: [{ type: 'uint256' }] },
|
|
342
|
+
// events
|
|
343
|
+
{ name: 'ValidatorInstalled', type: 'event',
|
|
344
|
+
inputs: [
|
|
345
|
+
{ name: 'account', type: 'address', indexed: true },
|
|
346
|
+
{ name: 'pubKeyX', type: 'uint256', indexed: false },
|
|
347
|
+
{ name: 'pubKeyY', type: 'uint256', indexed: false },
|
|
348
|
+
] },
|
|
349
|
+
{ name: 'ValidatorUninstalled', type: 'event',
|
|
350
|
+
inputs: [{ name: 'account', type: 'address', indexed: true }] },
|
|
351
|
+
] as const;
|
|
352
|
+
|
|
353
|
+
// ── KPXRouterGateway ──────────────────────────────────────────────────────────
|
|
354
|
+
|
|
355
|
+
export const KPX_ROUTER_GATEWAY_ABI = [
|
|
356
|
+
// reads
|
|
357
|
+
{ name: 'feeRate', type: 'function', stateMutability: 'view',
|
|
358
|
+
inputs: [], outputs: [{ type: 'uint256' }] },
|
|
359
|
+
{ name: 'vrqVerifier', type: 'function', stateMutability: 'view',
|
|
360
|
+
inputs: [], outputs: [{ type: 'address' }] },
|
|
361
|
+
{ name: 'darkPool', type: 'function', stateMutability: 'view',
|
|
362
|
+
inputs: [], outputs: [{ type: 'address' }] },
|
|
363
|
+
{ name: 'getPool', type: 'function', stateMutability: 'view',
|
|
364
|
+
inputs: [{ name: 'tokenA', type: 'address' }, { name: 'tokenB', type: 'address' }],
|
|
365
|
+
outputs: [{ type: 'address' }] },
|
|
366
|
+
// swapExactIn via a known pool address
|
|
367
|
+
{ name: 'swapExactIn', type: 'function', stateMutability: 'nonpayable',
|
|
368
|
+
inputs: [
|
|
369
|
+
{ name: 'pool', type: 'address' },
|
|
370
|
+
{ name: 'tokenIn', type: 'address' },
|
|
371
|
+
{ name: 'amountIn', type: 'uint256' },
|
|
372
|
+
{ name: 'amountOutMin', type: 'uint256' },
|
|
373
|
+
{ name: 'to', type: 'address' },
|
|
374
|
+
],
|
|
375
|
+
outputs: [{ name: 'amountOut', type: 'uint256' }] },
|
|
376
|
+
// depositRWA — Banking bridge entry point
|
|
377
|
+
{ name: 'depositRWA', type: 'function', stateMutability: 'nonpayable',
|
|
378
|
+
inputs: [
|
|
379
|
+
{ name: 'assetId', type: 'bytes32' },
|
|
380
|
+
{ name: 'amount', type: 'uint256' },
|
|
381
|
+
{ name: 'collateral', type: 'uint256' },
|
|
382
|
+
{ name: 'zkProof', type: 'bytes' },
|
|
383
|
+
],
|
|
384
|
+
outputs: [] },
|
|
385
|
+
// events
|
|
386
|
+
{ name: 'SwapExecuted', type: 'event',
|
|
387
|
+
inputs: [
|
|
388
|
+
{ name: 'sender', type: 'address', indexed: true },
|
|
389
|
+
{ name: 'pool', type: 'address', indexed: false },
|
|
390
|
+
{ name: 'tokenIn', type: 'address', indexed: false },
|
|
391
|
+
{ name: 'amountIn', type: 'uint256', indexed: false },
|
|
392
|
+
{ name: 'amountOut', type: 'uint256', indexed: false },
|
|
393
|
+
] },
|
|
394
|
+
{ name: 'RWADeposited', type: 'event',
|
|
395
|
+
inputs: [
|
|
396
|
+
{ name: 'depositor', type: 'address', indexed: true },
|
|
397
|
+
{ name: 'assetId', type: 'bytes32', indexed: false },
|
|
398
|
+
{ name: 'amount', type: 'uint256', indexed: false },
|
|
399
|
+
] },
|
|
400
|
+
] as const;
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,447 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @axioledger/evm-interop — wagmi hook factories for KPX + AXQ contracts
|
|
3
|
+
*
|
|
4
|
+
* Re-export pattern: each hook calls the generated wagmi v2 hooks with the
|
|
5
|
+
* correct ABI and function name already bound. Callers only need to supply
|
|
6
|
+
* the contract address (or pull it from a config context).
|
|
7
|
+
*
|
|
8
|
+
* Usage in a Next.js 'use client' component:
|
|
9
|
+
*
|
|
10
|
+
* import { useAXQBalance, useProposals, useKPXAmountOut } from '@axioledger/evm-interop';
|
|
11
|
+
*
|
|
12
|
+
* const { data: balance } = useAXQBalance(AXQ_TOKEN_ADDR, userAddress);
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
'use client';
|
|
16
|
+
|
|
17
|
+
import { useReadContract, useWriteContract, useWatchContractEvent } from 'wagmi';
|
|
18
|
+
import type { Address, Abi } from 'viem';
|
|
19
|
+
|
|
20
|
+
import {
|
|
21
|
+
AXQ_TOKEN_ABI,
|
|
22
|
+
AXQ_GOVERNANCE_ABI,
|
|
23
|
+
ANS_REGISTRY_ABI,
|
|
24
|
+
KPX_LIQUIDITY_POOL_ABI,
|
|
25
|
+
VRQ_PASSKEY_VALIDATOR_ABI,
|
|
26
|
+
} from './abis';
|
|
27
|
+
|
|
28
|
+
// ── Helpers ──────────────────────────────────────────────────────────────────
|
|
29
|
+
|
|
30
|
+
/** Narrow type to satisfy wagmi's `abi` parameter. */
|
|
31
|
+
type AsAbi<T> = T extends Abi ? T : never;
|
|
32
|
+
|
|
33
|
+
// ── AXQToken hooks ────────────────────────────────────────────────────────────
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Read the $AXQ balance of `account`.
|
|
37
|
+
* @returns bigint | undefined
|
|
38
|
+
*/
|
|
39
|
+
export function useAXQBalance(contractAddress: Address, account: Address) {
|
|
40
|
+
return useReadContract({
|
|
41
|
+
address: contractAddress,
|
|
42
|
+
abi: AXQ_TOKEN_ABI as AsAbi<typeof AXQ_TOKEN_ABI>,
|
|
43
|
+
functionName: 'balanceOf',
|
|
44
|
+
args: [account],
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Read the total $AXQ supply.
|
|
50
|
+
*/
|
|
51
|
+
export function useAXQTotalSupply(contractAddress: Address) {
|
|
52
|
+
return useReadContract({
|
|
53
|
+
address: contractAddress,
|
|
54
|
+
abi: AXQ_TOKEN_ABI as AsAbi<typeof AXQ_TOKEN_ABI>,
|
|
55
|
+
functionName: 'totalSupply',
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Read the allowance granted by `owner` to `spender`.
|
|
61
|
+
*/
|
|
62
|
+
export function useAXQAllowance(contractAddress: Address, owner: Address, spender: Address) {
|
|
63
|
+
return useReadContract({
|
|
64
|
+
address: contractAddress,
|
|
65
|
+
abi: AXQ_TOKEN_ABI as AsAbi<typeof AXQ_TOKEN_ABI>,
|
|
66
|
+
functionName: 'allowance',
|
|
67
|
+
args: [owner, spender],
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Write: transfer $AXQ. Returns `{ writeContract, isPending, … }`.
|
|
73
|
+
*/
|
|
74
|
+
export function useAXQTransfer(contractAddress: Address) {
|
|
75
|
+
const { writeContract, ...rest } = useWriteContract();
|
|
76
|
+
const transfer = (to: Address, amount: bigint) =>
|
|
77
|
+
writeContract({
|
|
78
|
+
address: contractAddress,
|
|
79
|
+
abi: AXQ_TOKEN_ABI as AsAbi<typeof AXQ_TOKEN_ABI>,
|
|
80
|
+
functionName: 'transfer',
|
|
81
|
+
args: [to, amount],
|
|
82
|
+
});
|
|
83
|
+
return { transfer, ...rest };
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Write: approve a spender.
|
|
88
|
+
*/
|
|
89
|
+
export function useAXQApprove(contractAddress: Address) {
|
|
90
|
+
const { writeContract, ...rest } = useWriteContract();
|
|
91
|
+
const approve = (spender: Address, amount: bigint) =>
|
|
92
|
+
writeContract({
|
|
93
|
+
address: contractAddress,
|
|
94
|
+
abi: AXQ_TOKEN_ABI as AsAbi<typeof AXQ_TOKEN_ABI>,
|
|
95
|
+
functionName: 'approve',
|
|
96
|
+
args: [spender, amount],
|
|
97
|
+
});
|
|
98
|
+
return { approve, ...rest };
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// ── AXQGovernance hooks ───────────────────────────────────────────────────────
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Read a single proposal by ID.
|
|
105
|
+
*/
|
|
106
|
+
export function useProposal(contractAddress: Address, proposalId: bigint) {
|
|
107
|
+
return useReadContract({
|
|
108
|
+
address: contractAddress,
|
|
109
|
+
abi: AXQ_GOVERNANCE_ABI as AsAbi<typeof AXQ_GOVERNANCE_ABI>,
|
|
110
|
+
functionName: 'proposals',
|
|
111
|
+
args: [proposalId],
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Read the current proposal count (useful for paginating).
|
|
117
|
+
*/
|
|
118
|
+
export function useProposalCount(contractAddress: Address) {
|
|
119
|
+
return useReadContract({
|
|
120
|
+
address: contractAddress,
|
|
121
|
+
abi: AXQ_GOVERNANCE_ABI as AsAbi<typeof AXQ_GOVERNANCE_ABI>,
|
|
122
|
+
functionName: 'proposalCount',
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Read whether `voter` has already voted on `proposalId`.
|
|
128
|
+
*/
|
|
129
|
+
export function useHasVoted(contractAddress: Address, proposalId: bigint, voter: Address) {
|
|
130
|
+
return useReadContract({
|
|
131
|
+
address: contractAddress,
|
|
132
|
+
abi: AXQ_GOVERNANCE_ABI as AsAbi<typeof AXQ_GOVERNANCE_ABI>,
|
|
133
|
+
functionName: 'hasVoted',
|
|
134
|
+
args: [proposalId, voter],
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Write: cast a quadratic-weighted vote.
|
|
140
|
+
*/
|
|
141
|
+
export function useCastVote(contractAddress: Address) {
|
|
142
|
+
const { writeContract, ...rest } = useWriteContract();
|
|
143
|
+
const castVote = (proposalId: bigint, support: boolean) =>
|
|
144
|
+
writeContract({
|
|
145
|
+
address: contractAddress,
|
|
146
|
+
abi: AXQ_GOVERNANCE_ABI as AsAbi<typeof AXQ_GOVERNANCE_ABI>,
|
|
147
|
+
functionName: 'castVote',
|
|
148
|
+
args: [proposalId, support],
|
|
149
|
+
});
|
|
150
|
+
return { castVote, ...rest };
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Write: create a governance proposal.
|
|
155
|
+
*/
|
|
156
|
+
export function usePropose(contractAddress: Address) {
|
|
157
|
+
const { writeContract, ...rest } = useWriteContract();
|
|
158
|
+
const propose = (target: Address, value: bigint, callData: `0x${string}`, description: string) =>
|
|
159
|
+
writeContract({
|
|
160
|
+
address: contractAddress,
|
|
161
|
+
abi: AXQ_GOVERNANCE_ABI as AsAbi<typeof AXQ_GOVERNANCE_ABI>,
|
|
162
|
+
functionName: 'propose',
|
|
163
|
+
args: [target, value, callData, description],
|
|
164
|
+
});
|
|
165
|
+
return { propose, ...rest };
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Write: queue a passed proposal for execution.
|
|
170
|
+
*/
|
|
171
|
+
export function useQueueProposal(contractAddress: Address) {
|
|
172
|
+
const { writeContract, ...rest } = useWriteContract();
|
|
173
|
+
const queue = (proposalId: bigint) =>
|
|
174
|
+
writeContract({
|
|
175
|
+
address: contractAddress,
|
|
176
|
+
abi: AXQ_GOVERNANCE_ABI as AsAbi<typeof AXQ_GOVERNANCE_ABI>,
|
|
177
|
+
functionName: 'queue',
|
|
178
|
+
args: [proposalId],
|
|
179
|
+
});
|
|
180
|
+
return { queue, ...rest };
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Write: execute a time-lock-expired proposal.
|
|
185
|
+
*/
|
|
186
|
+
export function useExecuteProposal(contractAddress: Address) {
|
|
187
|
+
const { writeContract, ...rest } = useWriteContract();
|
|
188
|
+
const execute = (proposalId: bigint, value?: bigint) =>
|
|
189
|
+
writeContract({
|
|
190
|
+
address: contractAddress,
|
|
191
|
+
abi: AXQ_GOVERNANCE_ABI as AsAbi<typeof AXQ_GOVERNANCE_ABI>,
|
|
192
|
+
functionName: 'execute',
|
|
193
|
+
args: [proposalId],
|
|
194
|
+
value: value ?? 0n,
|
|
195
|
+
});
|
|
196
|
+
return { execute, ...rest };
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Watch for new ProposalCreated events.
|
|
201
|
+
*/
|
|
202
|
+
export function useWatchProposalCreated(
|
|
203
|
+
contractAddress: Address,
|
|
204
|
+
onProposal: (id: bigint, proposer: Address, description: string) => void,
|
|
205
|
+
) {
|
|
206
|
+
return useWatchContractEvent({
|
|
207
|
+
address: contractAddress,
|
|
208
|
+
abi: AXQ_GOVERNANCE_ABI as AsAbi<typeof AXQ_GOVERNANCE_ABI>,
|
|
209
|
+
eventName: 'ProposalCreated',
|
|
210
|
+
onLogs(logs) {
|
|
211
|
+
for (const log of logs) {
|
|
212
|
+
const { id, proposer, description } = (log as any).args;
|
|
213
|
+
onProposal(id, proposer, description);
|
|
214
|
+
}
|
|
215
|
+
},
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Watch for VoteCast events on a specific proposal.
|
|
221
|
+
*/
|
|
222
|
+
export function useWatchVoteCast(
|
|
223
|
+
contractAddress: Address,
|
|
224
|
+
proposalId: bigint,
|
|
225
|
+
onVote: (voter: Address, support: boolean, weight: bigint) => void,
|
|
226
|
+
) {
|
|
227
|
+
return useWatchContractEvent({
|
|
228
|
+
address: contractAddress,
|
|
229
|
+
abi: AXQ_GOVERNANCE_ABI as AsAbi<typeof AXQ_GOVERNANCE_ABI>,
|
|
230
|
+
eventName: 'VoteCast',
|
|
231
|
+
args: { id: proposalId } as any,
|
|
232
|
+
onLogs(logs) {
|
|
233
|
+
for (const log of logs) {
|
|
234
|
+
const { voter, support, weight } = (log as any).args;
|
|
235
|
+
onVote(voter, support, weight);
|
|
236
|
+
}
|
|
237
|
+
},
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// ── ANSRegistry hooks ─────────────────────────────────────────────────────────
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Resolve `label.tld` → owner address. Reverts on-chain if name is expired.
|
|
245
|
+
*/
|
|
246
|
+
export function useANSResolve(contractAddress: Address, label: string, tld: string) {
|
|
247
|
+
return useReadContract({
|
|
248
|
+
address: contractAddress,
|
|
249
|
+
abi: ANS_REGISTRY_ABI as AsAbi<typeof ANS_REGISTRY_ABI>,
|
|
250
|
+
functionName: 'resolve',
|
|
251
|
+
args: [label, tld],
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Write: register a new ANS name.
|
|
257
|
+
*/
|
|
258
|
+
export function useANSRegister(contractAddress: Address) {
|
|
259
|
+
const { writeContract, ...rest } = useWriteContract();
|
|
260
|
+
const register = (label: string, tld: string, resolver: Address, fee: bigint) =>
|
|
261
|
+
writeContract({
|
|
262
|
+
address: contractAddress,
|
|
263
|
+
abi: ANS_REGISTRY_ABI as AsAbi<typeof ANS_REGISTRY_ABI>,
|
|
264
|
+
functionName: 'register',
|
|
265
|
+
args: [label, tld, resolver],
|
|
266
|
+
value: fee,
|
|
267
|
+
});
|
|
268
|
+
return { register, ...rest };
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// ── KPXLiquidityPool hooks ────────────────────────────────────────────────────
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Read pool reserves.
|
|
275
|
+
*/
|
|
276
|
+
export function useKPXReserves(poolAddress: Address) {
|
|
277
|
+
const a = useReadContract({
|
|
278
|
+
address: poolAddress,
|
|
279
|
+
abi: KPX_LIQUIDITY_POOL_ABI as AsAbi<typeof KPX_LIQUIDITY_POOL_ABI>,
|
|
280
|
+
functionName: 'reserveA',
|
|
281
|
+
});
|
|
282
|
+
const b = useReadContract({
|
|
283
|
+
address: poolAddress,
|
|
284
|
+
abi: KPX_LIQUIDITY_POOL_ABI as AsAbi<typeof KPX_LIQUIDITY_POOL_ABI>,
|
|
285
|
+
functionName: 'reserveB',
|
|
286
|
+
});
|
|
287
|
+
return { reserveA: a, reserveB: b };
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Quote: calculate output amount for `amountIn` of `tokenIn`.
|
|
292
|
+
*/
|
|
293
|
+
export function useKPXAmountOut(poolAddress: Address, tokenIn: Address, amountIn: bigint) {
|
|
294
|
+
return useReadContract({
|
|
295
|
+
address: poolAddress,
|
|
296
|
+
abi: KPX_LIQUIDITY_POOL_ABI as AsAbi<typeof KPX_LIQUIDITY_POOL_ABI>,
|
|
297
|
+
functionName: 'getAmountOut',
|
|
298
|
+
args: [amountIn, tokenIn],
|
|
299
|
+
query: { enabled: amountIn > 0n },
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* Read the spot price of TOKEN_A expressed in TOKEN_B (18-decimal fixed-point).
|
|
305
|
+
*/
|
|
306
|
+
export function useKPXSpotPrice(poolAddress: Address) {
|
|
307
|
+
return useReadContract({
|
|
308
|
+
address: poolAddress,
|
|
309
|
+
abi: KPX_LIQUIDITY_POOL_ABI as AsAbi<typeof KPX_LIQUIDITY_POOL_ABI>,
|
|
310
|
+
functionName: 'priceAInB',
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* Write: swap exact tokenIn for at least amountOutMin of the other token.
|
|
316
|
+
*/
|
|
317
|
+
export function useKPXSwapExactIn(poolAddress: Address) {
|
|
318
|
+
const { writeContract, ...rest } = useWriteContract();
|
|
319
|
+
const swap = (tokenIn: Address, amountIn: bigint, amountOutMin: bigint, to: Address) =>
|
|
320
|
+
writeContract({
|
|
321
|
+
address: poolAddress,
|
|
322
|
+
abi: KPX_LIQUIDITY_POOL_ABI as AsAbi<typeof KPX_LIQUIDITY_POOL_ABI>,
|
|
323
|
+
functionName: 'swapExactIn',
|
|
324
|
+
args: [tokenIn, amountIn, amountOutMin, to],
|
|
325
|
+
});
|
|
326
|
+
return { swap, ...rest };
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* Write: add liquidity to a KPX pool.
|
|
331
|
+
*/
|
|
332
|
+
export function useKPXAddLiquidity(poolAddress: Address) {
|
|
333
|
+
const { writeContract, ...rest } = useWriteContract();
|
|
334
|
+
const addLiquidity = (
|
|
335
|
+
amountADesired: bigint,
|
|
336
|
+
amountBDesired: bigint,
|
|
337
|
+
amountAMin: bigint,
|
|
338
|
+
amountBMin: bigint,
|
|
339
|
+
to: Address,
|
|
340
|
+
) =>
|
|
341
|
+
writeContract({
|
|
342
|
+
address: poolAddress,
|
|
343
|
+
abi: KPX_LIQUIDITY_POOL_ABI as AsAbi<typeof KPX_LIQUIDITY_POOL_ABI>,
|
|
344
|
+
functionName: 'addLiquidity',
|
|
345
|
+
args: [amountADesired, amountBDesired, amountAMin, amountBMin, to],
|
|
346
|
+
});
|
|
347
|
+
return { addLiquidity, ...rest };
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* Watch Swap events on a KPX pool.
|
|
352
|
+
*/
|
|
353
|
+
export function useWatchKPXSwap(
|
|
354
|
+
poolAddress: Address,
|
|
355
|
+
onSwap: (sender: Address, tokenIn: Address, amountIn: bigint, amountOut: bigint, to: Address) => void,
|
|
356
|
+
) {
|
|
357
|
+
return useWatchContractEvent({
|
|
358
|
+
address: poolAddress,
|
|
359
|
+
abi: KPX_LIQUIDITY_POOL_ABI as AsAbi<typeof KPX_LIQUIDITY_POOL_ABI>,
|
|
360
|
+
eventName: 'Swap',
|
|
361
|
+
onLogs(logs) {
|
|
362
|
+
for (const log of logs) {
|
|
363
|
+
const { sender, tokenIn, amountIn, amountOut, to } = (log as any).args;
|
|
364
|
+
onSwap(sender, tokenIn, amountIn, amountOut, to);
|
|
365
|
+
}
|
|
366
|
+
},
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
// ── VRQPasskeyValidator hooks ─────────────────────────────────────────────────
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* Check whether a smart-account has the VRQ validator installed.
|
|
374
|
+
*/
|
|
375
|
+
export function useVRQIsInstalled(contractAddress: Address, smartAccount: Address) {
|
|
376
|
+
return useReadContract({
|
|
377
|
+
address: contractAddress,
|
|
378
|
+
abi: VRQ_PASSKEY_VALIDATOR_ABI as AsAbi<typeof VRQ_PASSKEY_VALIDATOR_ABI>,
|
|
379
|
+
functionName: 'isInitialized',
|
|
380
|
+
args: [smartAccount],
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* Read the stored P256 public key (X coordinate) for a smart-account.
|
|
386
|
+
*/
|
|
387
|
+
export function useVRQPubKeyX(contractAddress: Address, smartAccount: Address) {
|
|
388
|
+
return useReadContract({
|
|
389
|
+
address: contractAddress,
|
|
390
|
+
abi: VRQ_PASSKEY_VALIDATOR_ABI as AsAbi<typeof VRQ_PASSKEY_VALIDATOR_ABI>,
|
|
391
|
+
functionName: 'accountPubKeyX',
|
|
392
|
+
args: [smartAccount],
|
|
393
|
+
});
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
/**
|
|
397
|
+
* Read the stored P256 public key (Y coordinate) for a smart-account.
|
|
398
|
+
*/
|
|
399
|
+
export function useVRQPubKeyY(contractAddress: Address, smartAccount: Address) {
|
|
400
|
+
return useReadContract({
|
|
401
|
+
address: contractAddress,
|
|
402
|
+
abi: VRQ_PASSKEY_VALIDATOR_ABI as AsAbi<typeof VRQ_PASSKEY_VALIDATOR_ABI>,
|
|
403
|
+
functionName: 'accountPubKeyY',
|
|
404
|
+
args: [smartAccount],
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* Write: install the VRQ validator module on the calling smart-account.
|
|
410
|
+
* `installData` = abi.encode(pubKeyX, pubKeyY, kycCommitment, zkProof)
|
|
411
|
+
*/
|
|
412
|
+
export function useVRQInstall(contractAddress: Address) {
|
|
413
|
+
const { writeContract, ...rest } = useWriteContract();
|
|
414
|
+
const install = (installData: `0x${string}`) =>
|
|
415
|
+
writeContract({
|
|
416
|
+
address: contractAddress,
|
|
417
|
+
abi: VRQ_PASSKEY_VALIDATOR_ABI as AsAbi<typeof VRQ_PASSKEY_VALIDATOR_ABI>,
|
|
418
|
+
functionName: 'onInstall',
|
|
419
|
+
args: [installData],
|
|
420
|
+
});
|
|
421
|
+
return { install, ...rest };
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
/**
|
|
425
|
+
* Write: uninstall the VRQ validator from the calling smart-account.
|
|
426
|
+
*/
|
|
427
|
+
export function useVRQUninstall(contractAddress: Address) {
|
|
428
|
+
const { writeContract, ...rest } = useWriteContract();
|
|
429
|
+
const uninstall = () =>
|
|
430
|
+
writeContract({
|
|
431
|
+
address: contractAddress,
|
|
432
|
+
abi: VRQ_PASSKEY_VALIDATOR_ABI as AsAbi<typeof VRQ_PASSKEY_VALIDATOR_ABI>,
|
|
433
|
+
functionName: 'onUninstall',
|
|
434
|
+
args: ['0x'],
|
|
435
|
+
});
|
|
436
|
+
return { uninstall, ...rest };
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
// ── Re-exports ────────────────────────────────────────────────────────────────
|
|
440
|
+
|
|
441
|
+
export {
|
|
442
|
+
AXQ_TOKEN_ABI,
|
|
443
|
+
AXQ_GOVERNANCE_ABI,
|
|
444
|
+
ANS_REGISTRY_ABI,
|
|
445
|
+
KPX_LIQUIDITY_POOL_ABI,
|
|
446
|
+
VRQ_PASSKEY_VALIDATOR_ABI,
|
|
447
|
+
} from './abis';
|
package/README.md
DELETED