-
Notifications
You must be signed in to change notification settings - Fork 71
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
Add /v1/chains/:chainId/safes/:safeAddress/portfolio
route
#2261
Draft
iamacook
wants to merge
15
commits into
portfolio-domain
Choose a base branch
from
portfolio-route
base: portfolio-domain
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,347
−53
Draft
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
fe6f824
Add `/v1/chains/:chainId/safes/:safeAddress/portfolio` route
iamacook 6f8542e
Merge branch 'portfolio-domain' into portfolio-route
iamacook 9fe3027
Merge branch 'portfolio-domain' into portfolio-route
iamacook f23a003
Map regular/complex positions
iamacook edcee99
Map complex positions correctly
iamacook f8b553e
Simplify complexity mapping
iamacook 83ff166
Remove debug code
iamacook e531726
Remove log
iamacook fe6d381
Add initial tests
iamacook f3f38a9
Add more tests
iamacook 9b190bd
Add happy path test for controller
iamacook a48e8b4
Adjust entities and add controller tests
iamacook 21b295d
Fix tests
iamacook 9f5ea69
Gracefully handle unknown position types
iamacook ee1158f
Remove comment
iamacook File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,51 @@ | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
import { TokenInfo } from '@/routes/transactions/entities/swaps/token-info.entity'; | ||
|
||
export enum PortfolioAssetType { | ||
General = 'GENERAL', | ||
Borrow = 'BORROW', | ||
Dex = 'DEX', | ||
Rewards = 'REWARDS', | ||
Supply = 'SUPPLY', | ||
} | ||
|
||
export class PortfolioAsset extends TokenInfo { | ||
@ApiProperty({ enum: PortfolioAssetType }) | ||
type: PortfolioAssetType; | ||
|
||
@ApiProperty() | ||
balance: string; | ||
|
||
@ApiProperty() | ||
price: string; | ||
|
||
@ApiProperty({ description: 'USD' }) | ||
fiatBalance: string; | ||
|
||
constructor(args: { | ||
type: PortfolioAssetType; | ||
address: `0x${string}`; | ||
decimals: number; | ||
logoUri: string; | ||
name: string; | ||
symbol: string; | ||
balance: string; | ||
price: string; | ||
fiatBalance: string; | ||
}) { | ||
super({ | ||
address: args.address, | ||
decimals: args.decimals, | ||
logoUri: args.logoUri, | ||
name: args.name, | ||
symbol: args.symbol, | ||
// Don't trust external API | ||
trusted: false, | ||
}); | ||
|
||
this.type = args.type; | ||
this.balance = args.balance; | ||
this.price = args.price; | ||
this.fiatBalance = args.fiatBalance; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/routes/portfolio/entities/portfolio-item-page.entity.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { ApiExtraModels, ApiProperty } from '@nestjs/swagger'; | ||
import { Page } from '@/routes/common/entities/page.entity'; | ||
import { PositionItem } from '@/routes/portfolio/entities/position-item.entity'; | ||
|
||
@ApiExtraModels(PositionItem) | ||
export class PortfolioItemPage extends Page<PositionItem> { | ||
@ApiProperty({ | ||
type: [PositionItem], | ||
isArray: true, | ||
}) | ||
results!: Array<PositionItem>; | ||
|
||
constructor(args: { | ||
results: Array<PositionItem>; | ||
count: number; | ||
next: string | null; | ||
previous: string | null; | ||
}) { | ||
super(); | ||
this.results = args.results; | ||
this.count = args.count; | ||
this.next = args.next; | ||
this.previous = args.previous; | ||
} | ||
} |
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,129 @@ | ||
import { | ||
ApiProperty, | ||
ApiPropertyOptional, | ||
getSchemaPath, | ||
} from '@nestjs/swagger'; | ||
import { PortfolioAsset } from '@/routes/portfolio/entities/portfolio-asset.entity'; | ||
|
||
type BasePosition = { | ||
name: string; | ||
fiatBalance: string; | ||
}; | ||
|
||
type Position = BasePosition & { | ||
assets: Array<PortfolioAsset>; | ||
}; | ||
|
||
enum PositionType { | ||
Regular = 'REGULAR', | ||
Complex = 'COMPLEX', | ||
} | ||
|
||
export class RegularProtocolPosition implements Position { | ||
@ApiProperty({ enum: [PositionType.Regular] }) | ||
type = PositionType.Regular; | ||
|
||
@ApiProperty() | ||
name: string; | ||
|
||
@ApiProperty({ type: PortfolioAsset, isArray: true }) | ||
assets: Array<PortfolioAsset>; | ||
|
||
@ApiProperty() | ||
fiatBalance: string; | ||
|
||
constructor(args: { | ||
name: string; | ||
assets: Array<PortfolioAsset>; | ||
fiatBalance: string; | ||
}) { | ||
this.name = args.name; | ||
this.assets = args.assets; | ||
this.fiatBalance = args.fiatBalance; | ||
} | ||
} | ||
|
||
export class NestedProtocolPosition implements Position { | ||
@ApiProperty() | ||
name: string; | ||
|
||
@ApiProperty({ type: PortfolioAsset, isArray: true }) | ||
assets: Array<PortfolioAsset>; | ||
|
||
@ApiProperty() | ||
fiatBalance: string; | ||
|
||
@ApiPropertyOptional({ | ||
type: String, | ||
nullable: true, | ||
}) | ||
healthRate?: string; | ||
|
||
constructor(args: { | ||
name: string; | ||
fiatBalance: string; | ||
healthRate?: string; | ||
assets: Array<PortfolioAsset>; | ||
}) { | ||
this.name = args.name; | ||
this.assets = args.assets; | ||
this.fiatBalance = args.fiatBalance; | ||
this.healthRate = args.healthRate; | ||
} | ||
} | ||
|
||
export class ComplexProtocolPosition implements BasePosition { | ||
@ApiProperty({ enum: [PositionType.Complex] }) | ||
type = PositionType.Complex; | ||
|
||
@ApiProperty() | ||
name: string; | ||
|
||
@ApiProperty({ type: NestedProtocolPosition, isArray: true }) | ||
positions: Array<NestedProtocolPosition>; | ||
|
||
@ApiProperty() | ||
fiatBalance: string; | ||
|
||
constructor(args: { | ||
name: string; | ||
positions: Array<NestedProtocolPosition>; | ||
fiatBalance: string; | ||
}) { | ||
this.name = args.name; | ||
this.positions = args.positions; | ||
this.fiatBalance = args.fiatBalance; | ||
} | ||
} | ||
|
||
export class PositionItem implements BasePosition { | ||
@ApiProperty() | ||
fiatBalance: string; | ||
|
||
@ApiProperty() | ||
name: string; | ||
|
||
@ApiProperty() | ||
logoUri: string; | ||
|
||
@ApiProperty({ | ||
oneOf: [ | ||
{ $ref: getSchemaPath(RegularProtocolPosition) }, | ||
{ $ref: getSchemaPath(ComplexProtocolPosition) }, | ||
], | ||
isArray: true, | ||
}) | ||
protocolPositions: Array<RegularProtocolPosition | ComplexProtocolPosition>; | ||
|
||
constructor(args: { | ||
fiatBalance: string; | ||
name: string; | ||
logoUri: string; | ||
protocolPositions: Array<RegularProtocolPosition | ComplexProtocolPosition>; | ||
}) { | ||
this.fiatBalance = args.fiatBalance; | ||
this.name = args.name; | ||
this.logoUri = args.logoUri; | ||
this.protocolPositions = args.protocolPositions; | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should add logging here but I'm not sure on the best approach as we'd need to inject the logging service into the entity. To keep the footprint focused, I will address this in a follow up PR.