Skip to content

Commit 235821e

Browse files
committed
fix: encoding params
1 parent ae9705b commit 235821e

1 file changed

Lines changed: 59 additions & 28 deletions

File tree

packages/contracts/tasks/vaults/vault.ts

Lines changed: 59 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { constants } from "ethers";
22
import { task, types } from "hardhat/config";
3-
import { Address, parseEther, encodeAbiParameters } from "viem";
3+
import { Address, parseEther, encodeAbiParameters, isAddress } from "viem";
44

55
export default task("optimized-vault:add")
66
.addParam("vaultAddress", "Address of the vault to add", undefined, types.string)
@@ -92,7 +92,7 @@ task("optimized-vault:deploy")
9292
adapters[adapters.length - 1].allocation = adapters[adapters.length - 1].allocation + remainder;
9393
}
9494
type Adapter = {
95-
adapter: Address;
95+
adapter: `0x${string}`;
9696
allocation: bigint
9797
};
9898
const tenAdapters: Adapter[] = adapters.concat(
@@ -127,44 +127,75 @@ task("optimized-vault:deploy")
127127
});
128128

129129
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
147150
];
151+
148152
console.log('values generated', values);
149153

150154
const initData = encodeAbiParameters(
151155
[
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' }
160180
],
161181
values
162182
);
163183

164184
console.log(`initializing with values ${JSON.stringify(values)}`);
165185

186+
if (!isAddress(vaultFirstExtDep.address) || !isAddress(vaultSecondExtDep.address)) {
187+
throw new Error("Invalid Ethereum address for extensions");
188+
}
166189
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);
168199
console.log(`initialized the vault at ${optimizedVault.address}`);
169200

170201
await run("optimized-vault:add", {

0 commit comments

Comments
 (0)