Skip to content

Commit

Permalink
handle withdrawal with eth address
Browse files Browse the repository at this point in the history
  • Loading branch information
torztomasz committed Jul 21, 2023
1 parent 9ac3ff8 commit 4991527
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
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

0 comments on commit 4991527

Please sign in to comment.