Skip to content

Commit

Permalink
Store stakingAssetId as proto-compatible type (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
grod220 authored Jun 28, 2024
1 parent 25ae9b5 commit a3dedf8
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 11 deletions.
6 changes: 6 additions & 0 deletions npm/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @penumbra-labs/registry

## 9.2.0

### Minor Changes

- Save stakingAssetId as proto-compatible type

## 9.1.1

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion npm/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@penumbra-labs/registry",
"version": "9.1.1",
"version": "9.2.0",
"description": "Chain and asset registry for Penumbra",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
Expand Down
10 changes: 10 additions & 0 deletions npm/src/client.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { describe, it, expect } from 'vitest';
import { ChainRegistryClient } from './client';
import { Registry } from './registry';
import { AssetId } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/asset/v1/asset_pb';
import { base64ToUint8Array } from './utils/base64';

describe('ChainRegistryClient', () => {
const client = new ChainRegistryClient();
Expand All @@ -20,4 +22,12 @@ describe('ChainRegistryClient', () => {
expect(registry).toBeInstanceOf(Registry);
expect(registry.chainId).toEqual('penumbra-testnet-deimos-7');
});

it('returns staking asset global as expected', () => {
const registry = client.globals();
const umStakingAsset = new AssetId({
inner: base64ToUint8Array('KeqcLzNx9qSH5+lcJHBB9KNW+YPrBk5dKzvPMiypahA='),
});
expect(umStakingAsset.equals(registry.stakingAssetId)).toBeTruthy();
});
});
3 changes: 1 addition & 2 deletions npm/src/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import * as Deimos8 from '../../registry/chains/penumbra-testnet-deimos-8.json';
import * as GlobalsJson from '../../registry/globals.json';

import { Base64AssetId, Chain, Rpc } from './registry';
import { base64ToUint8Array } from './utils/base64';
import { AssetId } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/asset/v1/asset_pb';

export interface RegistryGlobals {
Expand Down Expand Up @@ -53,5 +52,5 @@ export const allJsonRegistries: Record<string, JsonRegistry> = {

export const registryGlobals: RegistryGlobals = {
...GlobalsJson,
stakingAssetId: new AssetId({ inner: base64ToUint8Array(GlobalsJson.stakingAssetId) }),
stakingAssetId: AssetId.fromJson(GlobalsJson.stakingAssetId),
};
4 changes: 3 additions & 1 deletion registry/globals.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@
"frontends": [
"https://app.testnet.penumbra.zone"
],
"stakingAssetId": "KeqcLzNx9qSH5+lcJHBB9KNW+YPrBk5dKzvPMiypahA="
"stakingAssetId": {
"inner": "KeqcLzNx9qSH5+lcJHBB9KNW+YPrBk5dKzvPMiypahA="
}
}
6 changes: 3 additions & 3 deletions tools/compiler/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ impl From<IbcInput> for Chain {
}
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Globals {
pub rpcs: Vec<Rpc>,
pub frontends: Vec<String>,
pub staking_asset_id: String,
pub staking_asset_id: Id,
}

impl TryFrom<GlobalsInput> for Globals {
Expand All @@ -56,7 +56,7 @@ impl TryFrom<GlobalsInput> for Globals {
Ok(Globals {
rpcs: g.rpcs,
frontends: g.frontends,
staking_asset_id: base64_id(&STAKING_TOKEN_ASSET_ID)?,
staking_asset_id: *STAKING_TOKEN_ASSET_ID,
})
}
}
Expand Down
6 changes: 2 additions & 4 deletions tools/compiler/tests/test_copy_globals.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use penumbra_asset::STAKING_TOKEN_ASSET_ID;
use penumbra_registry::parser::{copy_globals, GlobalsInput, Rpc};
use penumbra_registry::processor::Globals;
use std::fs::{self, File};
Expand Down Expand Up @@ -41,10 +42,7 @@ fn test_successful_copy() {

assert_eq!(output_globals.frontends, globals.frontends);
assert_eq!(output_globals.rpcs, globals.rpcs);
assert_eq!(
output_globals.staking_asset_id,
"KeqcLzNx9qSH5+lcJHBB9KNW+YPrBk5dKzvPMiypahA=".to_string()
);
assert_eq!(output_globals.staking_asset_id, *STAKING_TOKEN_ASSET_ID);
}

#[test]
Expand Down

0 comments on commit a3dedf8

Please sign in to comment.