|
1 | 1 | import { constants } from "ethers"; |
2 | 2 | import { task, types } from "hardhat/config"; |
3 | | -import { Address, parseEther, encodeAbiParameters } from "viem"; |
| 3 | +import { Address, parseEther, encodeAbiParameters, isAddress } from "viem"; |
4 | 4 |
|
5 | 5 | export default task("optimized-vault:add") |
6 | 6 | .addParam("vaultAddress", "Address of the vault to add", undefined, types.string) |
@@ -92,7 +92,7 @@ task("optimized-vault:deploy") |
92 | 92 | adapters[adapters.length - 1].allocation = adapters[adapters.length - 1].allocation + remainder; |
93 | 93 | } |
94 | 94 | type Adapter = { |
95 | | - adapter: Address; |
| 95 | + adapter: `0x${string}`; |
96 | 96 | allocation: bigint |
97 | 97 | }; |
98 | 98 | const tenAdapters: Adapter[] = adapters.concat( |
@@ -127,44 +127,75 @@ task("optimized-vault:deploy") |
127 | 127 | }); |
128 | 128 |
|
129 | 129 | const values: [ |
130 | | - string, |
131 | | - Adapter[], // Matches "tuple(address adapter, uint64 allocation)[10]" |
132 | | - number, // Matches "uint8" |
133 | | - Fee, // Matches "tuple(uint64, ...)" |
134 | | - string, // Matches "address" |
135 | | - bigint, // Matches "uint256" |
136 | | - string, // Matches "address" |
137 | | - string // Matches "address" |
138 | | - ] = [ |
139 | | - assetAddress as Address, |
140 | | - tenAdapters, // initial adapters |
141 | | - tenAdapters.length, // adapters count |
142 | | - fees, |
143 | | - deployer as Address, // fee recipient |
144 | | - 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffn, // deposit limit |
145 | | - registry.address as Address, |
146 | | - flywheelLogic.address as Address |
| 130 | + `0x${string}`, // Matches "address" |
| 131 | + { adapter: `0x${string}`, allocation: bigint }[], // Matches "tuple(address, uint256)[]" |
| 132 | + number, // Matches "uint8" |
| 133 | + Fee, // Matches "tuple(uint64, uint64, uint64, uint64)" |
| 134 | + `0x${string}`, // Matches "address" |
| 135 | + bigint, // Matches "uint256" |
| 136 | + `0x${string}`, // Matches "address" |
| 137 | + `0x${string}` // Matches "address" |
| 138 | + ] = [ |
| 139 | + assetAddress as `0x${string}`, // Asset address |
| 140 | + tenAdapters.map(adapter => ({ |
| 141 | + adapter: adapter.adapter, |
| 142 | + allocation: adapter.allocation |
| 143 | + })), // Adapters array |
| 144 | + tenAdapters.length, // Count of adapters |
| 145 | + fees, // Fees |
| 146 | + deployer as `0x${string}`, // Fee recipient |
| 147 | + 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffn, // Deposit limit |
| 148 | + registry.address as `0x${string}`, // Registry address |
| 149 | + flywheelLogic.address as `0x${string}` // Flywheel logic address |
147 | 150 | ]; |
| 151 | + |
148 | 152 | console.log('values generated', values); |
149 | 153 |
|
150 | 154 | const initData = encodeAbiParameters( |
151 | 155 | [ |
152 | | - "address", |
153 | | - "tuple(address adapter, uint64 allocation)[10]", |
154 | | - "uint8", |
155 | | - "tuple(uint64 deposit, uint64 withdrawal, uint64 management, uint64 performance)", |
156 | | - "address", |
157 | | - "uint256", |
158 | | - "address", |
159 | | - "address" |
| 156 | + { name: 'asset_', type: 'address' }, |
| 157 | + { |
| 158 | + name: 'adapters_', |
| 159 | + type: 'tuple[]', // Array of tuples |
| 160 | + components: [ |
| 161 | + { name: 'adapter', type: 'address' }, // Address field |
| 162 | + { name: 'allocation', type: 'uint256' } // Uint256 field |
| 163 | + ] |
| 164 | + }, |
| 165 | + { name: 'adaptersCount_', type: 'uint8' }, |
| 166 | + { |
| 167 | + name: 'fees_', |
| 168 | + type: 'tuple', |
| 169 | + components: [ |
| 170 | + { name: 'deposit', type: 'uint64' }, |
| 171 | + { name: 'withdrawal', type: 'uint64' }, |
| 172 | + { name: 'management', type: 'uint64' }, |
| 173 | + { name: 'performance', type: 'uint64' } |
| 174 | + ] |
| 175 | + }, |
| 176 | + { name: 'feeRecipient_', type: 'address' }, |
| 177 | + { name: 'depositLimit_', type: 'uint256' }, |
| 178 | + { name: 'registry_', type: 'address' }, |
| 179 | + { name: 'flywheelLogic_', type: 'address' } |
160 | 180 | ], |
161 | 181 | values |
162 | 182 | ); |
163 | 183 |
|
164 | 184 | console.log(`initializing with values ${JSON.stringify(values)}`); |
165 | 185 |
|
| 186 | + if (!isAddress(vaultFirstExtDep.address) || !isAddress(vaultSecondExtDep.address)) { |
| 187 | + throw new Error("Invalid Ethereum address for extensions"); |
| 188 | + } |
166 | 189 | const optimizedVault = await viem.getContractAt("OptimizedAPRVaultBase", optimizedVaultDep.address as Address); |
167 | | - await optimizedVault.write.initialize([vaultFirstExtDep.address, vaultSecondExtDep.address], initData); |
| 190 | + const a = vaultFirstExtDep.address as `0x${string}`; |
| 191 | + const b = vaultSecondExtDep.address as `0x${string}`; |
| 192 | + |
| 193 | + await optimizedVault.write.initialize( |
| 194 | + [ |
| 195 | + vaultFirstExtDep.address as `0x${string}`, |
| 196 | + vaultSecondExtDep.address as `0x${string}` |
| 197 | + ], |
| 198 | + , initData); |
168 | 199 | console.log(`initialized the vault at ${optimizedVault.address}`); |
169 | 200 |
|
170 | 201 | await run("optimized-vault:add", { |
|
0 commit comments