Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle withdrawal with eth address #430

Merged
merged 1 commit into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion packages/backend/src/api/controllers/UserController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export class UserController {
forcedTradeOffers,
forcedTradeOffersCount,
finalizableOffers,
withdrawableAssets,
starkKeyWithdrawableAssets,
userStatistics,
] = await Promise.all([
this.userRegistrationEventRepository.findByStarkKey(starkKey),
Expand Down Expand Up @@ -178,6 +178,16 @@ export class UserController {
message: `User with starkKey ${starkKey.toString()} not found`,
}
}
const ethAddressWithdrawableAssets = givenUser.address
? await this.withdrawableAssetRepository.getAssetBalancesByStarkKey(
StarkKey.fromEthereumAddress(givenUser.address)
)
: []

const withdrawableAssets = [
...starkKeyWithdrawableAssets,
...ethAddressWithdrawableAssets,
]

const assetDetailsMap = await this.assetDetailsService.getAssetDetailsMap({
userAssets: userAssets,
Expand Down
7 changes: 7 additions & 0 deletions packages/types/src/StarkKey.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { type BigNumber } from '@ethersproject/bignumber'

import { EthereumAddress } from './EthereumAddress'
import { fakeHexString } from './fake'

export interface StarkKey extends String {
Expand All @@ -25,6 +26,12 @@ StarkKey.from = function from(value: BigNumber | bigint) {
return StarkKey('0x' + value.toString(16).padStart(64, '0'))
}

StarkKey.fromEthereumAddress = function fromEthereumAddress(
address: EthereumAddress
) {
return StarkKey('0' + address.toString().slice(2).padStart(63, '0'))
}

StarkKey.fake = function fake(start?: string) {
if (!start) {
return StarkKey('0' + fakeHexString(63))
Expand Down