This repository has been archived by the owner on Jan 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 382
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(lyra-avalon): Add unique keys on Lyra Avalon positions (#846)
- Loading branch information
1 parent
833c26c
commit 78ff09f
Showing
6 changed files
with
91 additions
and
4 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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import murmur from 'murmurhash-js'; | ||
|
||
import { Network } from '~types/network.interface'; | ||
|
||
import { ContractType } from './contract.interface'; | ||
import { AppTokenPosition, ContractPosition, MetaType, NonFungibleToken } from './position.interface'; | ||
import { BaseToken } from './token.interface'; | ||
|
||
export type AppGroupsDefinition = { | ||
appId: string; | ||
groupIds: string[]; | ||
network: Network; | ||
}; | ||
|
||
@Injectable() | ||
export class PositionKeyService { | ||
generateKey(input: string) { | ||
return murmur.murmur3(input).toString(); | ||
} | ||
|
||
getPositionKey( | ||
position: ContractPosition | AppTokenPosition | BaseToken | NonFungibleToken, | ||
pickFields: string[] = [], | ||
) { | ||
if ('key' in position) return position.key!; | ||
|
||
switch (position.type) { | ||
case ContractType.POSITION: | ||
return this.generateKey( | ||
[ | ||
position.address, | ||
position.network, | ||
position.appId, | ||
position.tokens.map(token => [token.address, token.network, token.metaType].join(':')), | ||
pickFields.map(v => position.dataProps[v]).join(':'), | ||
].join(':'), | ||
); | ||
case ContractType.APP_TOKEN: | ||
return this.generateKey( | ||
[ | ||
position.appId, | ||
position.address, | ||
position.network, | ||
MetaType.SUPPLIED, | ||
pickFields.map(v => position.dataProps[v]).join(':'), | ||
].join(':'), | ||
); | ||
default: | ||
return this.generateKey([position.address, position.network, MetaType.SUPPLIED].join(':')); | ||
} | ||
} | ||
} |
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