Skip to content

Commit

Permalink
fix: add wsteth to addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
DiRaiks committed Sep 2, 2023
1 parent 44d6ad8 commit 30a9b5e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/sdk/src/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export const ContractNames = {
withdrawalQueue: 'withdrawalQueue',
withdrawalVault: 'withdrawalVault',
oracleDaemonConfig: 'oracleDaemonConfig',
wsteth: 'wsteth',
};

export type ContractName = keyof typeof ContractNames;
9 changes: 9 additions & 0 deletions packages/sdk/src/core/abi/wq.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export const wqAbi = [
{
inputs: [],
name: 'WSTETH',
outputs: [{ internalType: 'contract IWstETH', name: '', type: 'address' }],
stateMutability: 'view',
type: 'function',
},
];
29 changes: 28 additions & 1 deletion packages/sdk/src/core/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
} from '../common/constants.js';

import { LidoLocatorAbi } from './abi/lidoLocator.js';
import { wqAbi } from './abi/wq.js';
import { LidoSDKCoreProps } from './types.js';

export default class LidoSDKCore {
Expand Down Expand Up @@ -156,6 +157,18 @@ export default class LidoSDKCore {
});
}

@Logger('Contracts:')
@Cache(30 * 60 * 1000, ['chain.id'])
private getContractWQ(
address: Address,
): GetContractReturnType<typeof wqAbi, PublicClient> {
return getContract({
address,
abi: wqAbi,
publicClient: this.rpcProvider,
});
}

// Utils

@Logger('Utils:')
Expand Down Expand Up @@ -218,6 +231,20 @@ export default class LidoSDKCore {
invariant(this.rpcProvider, 'RPC provider is not defined');
const lidoLocator = this.getContractLidoLocator();

return lidoLocator.read[contract]();
invariant(lidoLocator, 'Lido locator is not defined');

if (contract === 'wsteth') {
const withdrawalQueue = await lidoLocator.read.withdrawalQueue();
const contract = await this.getContractWQ(withdrawalQueue);
const wstethAddress = await contract.read.WSTETH?.();

invariant(wstethAddress, 'wstETH address is not defined');

return wstethAddress as Address;
} else {
invariant(lidoLocator.read[contract], 'Lido locator read is not defined');

return lidoLocator.read[contract]();
}
}
}

0 comments on commit 30a9b5e

Please sign in to comment.