-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
490 additions
and
247 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
# @penumbra-labs/registry | ||
|
||
## 5.0.0 | ||
|
||
### Major Changes | ||
|
||
- New registry class | ||
|
||
## 4.1.0 | ||
|
||
### Minor Changes | ||
|
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
Large diffs are not rendered by default.
Oops, something went wrong.
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 +1,2 @@ | ||
export * from './client'; | ||
export * from './registry'; |
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,101 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { base64ToUint8Array, isTestnetPreviewChainId } from './utils'; | ||
import { Registry } from './registry'; | ||
import { GithubRegistryResponse } from './github'; | ||
import { AssetId } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/asset/v1/asset_pb'; | ||
|
||
const testRegistry: GithubRegistryResponse = { | ||
chainId: 'penumbra-testnet-deimos-6', | ||
ibcConnections: [ | ||
{ | ||
addressPrefix: 'osmo', | ||
chainId: 'osmo-test-5', | ||
ibcChannel: 'channel-3', | ||
displayName: 'Osmosis', | ||
images: [ | ||
{ | ||
svg: 'https://raw.githubusercontent.com/cosmos/chain-registry/f1348793beb994c6cc0256ed7ebdb48c7aa70003/osmosis/images/osmo.svg', | ||
}, | ||
], | ||
}, | ||
], | ||
rpcs: [ | ||
{ | ||
name: 'Penumbra Labs Testnet RPC', | ||
url: 'https://grpc.testnet.penumbra.zone', | ||
images: [ | ||
{ | ||
png: 'https://raw.githubusercontent.com/prax-wallet/registry/main/images/penumbra-favicon.png', | ||
}, | ||
], | ||
}, | ||
], | ||
assetById: { | ||
'KeqcLzNx9qSH5+lcJHBB9KNW+YPrBk5dKzvPMiypahA=': { | ||
denomUnits: [ | ||
{ | ||
denom: 'penumbra', | ||
exponent: 6, | ||
}, | ||
{ | ||
denom: 'mpenumbra', | ||
exponent: 3, | ||
}, | ||
{ | ||
denom: 'upenumbra', | ||
}, | ||
], | ||
base: 'upenumbra', | ||
display: 'penumbra', | ||
symbol: 'UM', | ||
penumbraAssetId: { | ||
inner: 'KeqcLzNx9qSH5+lcJHBB9KNW+YPrBk5dKzvPMiypahA=', | ||
}, | ||
images: [ | ||
{ | ||
svg: 'https://raw.githubusercontent.com/prax-wallet/registry/main/images/um.svg', | ||
}, | ||
], | ||
}, | ||
'reum7wQmk/owgvGMWMZn/6RFPV24zIKq3W6In/WwZgg=': { | ||
denomUnits: [ | ||
{ | ||
denom: 'test_usd', | ||
exponent: 18, | ||
}, | ||
{ | ||
denom: 'wtest_usd', | ||
}, | ||
], | ||
base: 'wtest_usd', | ||
display: 'test_usd', | ||
symbol: 'TestUSD', | ||
penumbraAssetId: { | ||
inner: 'reum7wQmk/owgvGMWMZn/6RFPV24zIKq3W6In/WwZgg=', | ||
}, | ||
images: [ | ||
{ | ||
svg: 'https://raw.githubusercontent.com/prax-wallet/registry/main/images/test-usd.svg', | ||
}, | ||
], | ||
}, | ||
}, | ||
stakingAssetId: 'KeqcLzNx9qSH5+lcJHBB9KNW+YPrBk5dKzvPMiypahA=', | ||
numeraires: ['reum7wQmk/owgvGMWMZn/6RFPV24zIKq3W6In/WwZgg='], | ||
}; | ||
|
||
describe('Registry', () => { | ||
it('get metadata successfully', () => { | ||
const registry = new Registry(testRegistry); | ||
const usdcId = base64ToUint8Array('reum7wQmk/owgvGMWMZn/6RFPV24zIKq3W6In/WwZgg='); | ||
const res = registry.getMetadata(new AssetId({ inner: usdcId })); | ||
expect(res.base).toEqual('wtest_usd'); | ||
}); | ||
|
||
it('throw when searching for metadata that does not exist', () => { | ||
const registry = new Registry(testRegistry); | ||
const cubeId = base64ToUint8Array('6KBVsPINa8gWSHhfH+kAFJC4afEJA3EtuB2HyCqJUws='); | ||
const getCubeMetadata = () => registry.getMetadata(new AssetId({ inner: cubeId })); | ||
expect(getCubeMetadata).toThrow(); | ||
}); | ||
}); |
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,55 @@ | ||
import { | ||
AssetId, | ||
Metadata, | ||
} from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/asset/v1/asset_pb'; | ||
import { base64ToUint8Array, mapObjectValues, Stringified, uint8ArrayToBase64 } from './utils'; | ||
import { GithubRegistryResponse } from './github'; | ||
|
||
export type Base64AssetId = Stringified<AssetId['inner']>; | ||
|
||
export interface Chain { | ||
addressPrefix: string; | ||
chainId: string; | ||
ibcChannel: string; | ||
images: Image[]; | ||
displayName: string; | ||
} | ||
|
||
export interface Rpc { | ||
name: string; | ||
url: string; | ||
images: Image[]; | ||
} | ||
|
||
export interface Image { | ||
png?: string; | ||
svg?: string; | ||
} | ||
|
||
export class Registry { | ||
public readonly chainId: string; | ||
public readonly ibcConnections: Chain[]; | ||
public readonly rpcs: Rpc[]; | ||
public readonly stakingAssetId: AssetId; | ||
public readonly numeraires: AssetId[]; | ||
|
||
private readonly assetById: Record<Base64AssetId, Metadata>; | ||
|
||
constructor(response: GithubRegistryResponse) { | ||
this.chainId = response.chainId; | ||
this.ibcConnections = response.ibcConnections; | ||
this.rpcs = response.rpcs; | ||
this.assetById = mapObjectValues(response.assetById, Metadata.fromJson); | ||
this.stakingAssetId = new AssetId({ inner: base64ToUint8Array(response.stakingAssetId) }); | ||
this.numeraires = response.numeraires.map(a => new AssetId({ inner: base64ToUint8Array(a) })); | ||
} | ||
|
||
getMetadata(id: AssetId): Metadata { | ||
const key = uint8ArrayToBase64(id.inner); | ||
const metadata = this.assetById[key]; | ||
if (!metadata) { | ||
throw new Error(`No metadata in registry for asset id: ${key}`); | ||
} | ||
return metadata; | ||
} | ||
} |
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
Oops, something went wrong.