-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from lidofinance/feature/si-771-withdrawals-claim
Withdrawals claim
- Loading branch information
Showing
23 changed files
with
718 additions
and
526 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,17 @@ | ||
export { LidoSDK } from './sdk.js'; | ||
export { type SDKError } from './common/utils/SDKError.js'; | ||
export * from './common/decorators/index.js'; | ||
export { StakeProps } from './staking/index.js'; | ||
export { | ||
RequestCallbackStages, | ||
RequestStageCallback, | ||
RequestProps, | ||
RequestWithPermitProps, | ||
TransactionCallbackStage, | ||
type TransactionCallback, | ||
} from './core/index.js'; | ||
export { type StakeProps } from './staking/index.js'; | ||
export { | ||
type ClaimRequestsProps, | ||
type RequestProps, | ||
type RequestWithPermitProps, | ||
ApproveCallbackStages, | ||
ApproveStageCallback, | ||
type ApproveStageCallback, | ||
} from './withdrawals/index.js'; | ||
export { LIDO_CONTRACT_NAMES } from './common/constants.js'; | ||
export { type WrapProps } from './wrap/index.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
import invariant from 'tiny-invariant'; | ||
|
||
import { type LidoSDKCoreProps } from '../../core/index.js'; | ||
import { Logger, Cache, ErrorHandler } from '../../common/decorators/index.js'; | ||
import { TransactionCallbackStage } from '../../core/types.js'; | ||
import { version } from '../../version.js'; | ||
|
||
import { Bus } from '../bus.js'; | ||
|
||
import { ClaimRequestsProps } from './types.js'; | ||
|
||
export class LidoSDKWithdrawalsClaim { | ||
private readonly bus: Bus; | ||
|
||
constructor(props: LidoSDKCoreProps & { bus?: Bus }) { | ||
if (props.bus) this.bus = props.bus; | ||
else this.bus = new Bus(props, version); | ||
} | ||
|
||
// Calls | ||
|
||
@Logger('Call:') | ||
@ErrorHandler('Error:') | ||
public async claimRequests(props: ClaimRequestsProps) { | ||
const { account } = props; | ||
invariant(this.bus.core.web3Provider, 'Web3 provider is not defined'); | ||
invariant(this.bus.core.rpcProvider, 'RPC provider is not defined'); | ||
|
||
const isContract = await this.bus.core.isContract(account); | ||
|
||
if (isContract) return this.claimRequestsMultisig(props); | ||
else return this.claimRequestsEOA(props); | ||
} | ||
|
||
@Logger('Call:') | ||
@ErrorHandler('Error:') | ||
public async claimRequestsEOA(props: ClaimRequestsProps) { | ||
const { account, requestsIds, hints, callback } = props; | ||
|
||
const contract = await this.bus.contract.getContractWithdrawalsQueue(); | ||
|
||
callback?.({ stage: TransactionCallbackStage.GAS_LIMIT }); | ||
|
||
const feeData = await this.bus.core.getFeeData(); | ||
const gasLimit = await this.claimGasLimit(props); | ||
const overrides = { | ||
account, | ||
maxPriorityFeePerGas: feeData.maxPriorityFeePerGas ?? undefined, | ||
maxFeePerGas: feeData.maxFeePerGas ?? undefined, | ||
}; | ||
|
||
callback?.({ stage: TransactionCallbackStage.SIGN, payload: gasLimit }); | ||
|
||
const params = [requestsIds, hints] as const; | ||
const transaction = await contract.write.claimWithdrawals(params, { | ||
...overrides, | ||
gas: gasLimit, | ||
chain: this.bus.core.chain, | ||
}); | ||
|
||
callback?.({ | ||
stage: TransactionCallbackStage.RECEIPT, | ||
payload: transaction, | ||
}); | ||
|
||
const transactionReceipt = | ||
await this.bus.core.rpcProvider.waitForTransactionReceipt({ | ||
hash: transaction, | ||
}); | ||
|
||
callback?.({ | ||
stage: TransactionCallbackStage.CONFIRMATION, | ||
payload: transactionReceipt, | ||
}); | ||
|
||
const confirmations = | ||
await this.bus.core.rpcProvider.getTransactionConfirmations({ | ||
hash: transactionReceipt.transactionHash, | ||
}); | ||
|
||
callback?.({ | ||
stage: TransactionCallbackStage.DONE, | ||
payload: confirmations, | ||
}); | ||
|
||
return { hash: transaction, receipt: transactionReceipt, confirmations }; | ||
} | ||
|
||
@Logger('Call:') | ||
@ErrorHandler('Error:') | ||
public async claimRequestsMultisig(props: ClaimRequestsProps) { | ||
const { account, requestsIds, hints, callback } = props; | ||
|
||
const contract = await this.bus.contract.getContractWithdrawalsQueue(); | ||
|
||
callback?.({ stage: TransactionCallbackStage.SIGN }); | ||
|
||
const params = [requestsIds, hints] as const; | ||
const transaction = await contract.write.claimWithdrawals(params, { | ||
account, | ||
chain: this.bus.core.chain, | ||
}); | ||
|
||
callback?.({ stage: TransactionCallbackStage.MULTISIG_DONE }); | ||
|
||
return { hash: transaction }; | ||
} | ||
|
||
@Logger('Utils:') | ||
@Cache(30 * 1000, ['core.chain.id']) | ||
private async claimGasLimit(props: ClaimRequestsProps): Promise<bigint> { | ||
const { account, requestsIds, hints } = props; | ||
invariant(this.bus.core.rpcProvider, 'RPC provider is not defined'); | ||
|
||
const contract = await this.bus.contract.getContractWithdrawalsQueue(); | ||
|
||
const params = [requestsIds, hints] as const; | ||
const gasLimit = await contract.estimateGas.claimWithdrawals(params, { | ||
account, | ||
}); | ||
|
||
return gasLimit; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { LidoSDKWithdrawalsClaim } from './claim.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { type Address } from 'viem'; | ||
|
||
import { TransactionCallback } from '../../core/index.js'; | ||
|
||
export type ClaimRequestsProps = { | ||
account: Address; | ||
requestsIds: bigint[]; | ||
hints: bigint[]; | ||
callback?: TransactionCallback; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,8 @@ | ||
export { LidoSDKWithdrawals } from './withdrawals.js'; | ||
export { ClaimRequestsProps } from './claim/types.js'; | ||
export { | ||
type RequestCallbackStages, | ||
type RequestStageCallback, | ||
type RequestProps, | ||
type RequestWithPermitProps, | ||
type ApproveCallbackStages, | ||
type ApproveStageCallback, | ||
} from './types.js'; | ||
} from './request/types.js'; |
8 changes: 4 additions & 4 deletions
8
...sdk/src/withdrawals/withdrawalsApprove.ts → ...es/sdk/src/withdrawals/request/approve.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { LidoSDKWithdrawalsRequest } from './request.js'; |
Oops, something went wrong.