-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Experiment with symbols for delegation tokens (#558)
* Experiment with symbols for delegation tokens This PR experiments with symbols for delegation tokens. Two possible approaches are illustrated: 1. The extension's asset registry can be augmented with the validator-specific token info, as I did for the two main testnet validators. 2. The extension could auto-create a symbol for the delegation token, but we must be very very careful about this, because the `symbol` field is shown to users and it is potentially attacker-controlled. For instance, if we just read the label off the chain, someone could spoof another validator's identity without consequence. However, this seems like a good place to start. * change from "Delegated UM" to "Delegation" This is better because it doesn't mislead the user into thinking that the number of tokens for the asset is the value of UM they represent. * Update regex parsing + unbonding case --------- Co-authored-by: Gabe Rodriguez <[email protected]>
- Loading branch information
1 parent
8c2150b
commit 209f264
Showing
9 changed files
with
160 additions
and
40 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,32 @@ | ||
import { describe, expect, test } from 'vitest'; | ||
import { Metadata } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/asset/v1/asset_pb'; | ||
import { customizeSymbol } from './customize-symbol'; | ||
|
||
describe('Customizing metadata', () => { | ||
test('should work for delegation token', () => { | ||
const metadata = new Metadata({ | ||
display: | ||
'delegation_penumbravalid1fjuj67ayaqueqxg03d65ps5aah6m39u39qeacu3zv2cw3dzxssyq3yrcez', | ||
}); | ||
customizeSymbol(metadata); | ||
expect(metadata.symbol).toBe('Delegated UM (fjuj67ayaqueqxg03d65ps5aa...)'); | ||
}); | ||
|
||
test('should work for unbonding token', () => { | ||
const metadata = new Metadata({ | ||
display: | ||
'uunbonding_epoch_29_penumbravalid1fjuj67ayaqueqxg03d65ps5aah6m39u39qeacu3zv2cw3dzxssyq3yrcez', | ||
}); | ||
customizeSymbol(metadata); | ||
expect(metadata.symbol).toBe('Unbonding UM, epoch 29 (fjuj67ayaqueqxg03d65ps5aa...)'); | ||
}); | ||
|
||
test('should do nothing if no matches', () => { | ||
const metadata = new Metadata({ | ||
display: 'test_usd', | ||
symbol: 'usdc', | ||
}); | ||
customizeSymbol(metadata); | ||
expect(metadata.symbol).toBe('usdc'); | ||
}); | ||
}); |
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,27 @@ | ||
import { Metadata } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/asset/v1/asset_pb'; | ||
import { | ||
assetPatterns, | ||
DelegationCaptureGroups, | ||
UnbondingCaptureGroups, | ||
} from '@penumbra-zone/constants'; | ||
|
||
const DELEGATION_SYMBOL_LENGTH = 50 - 'delegation_penumbravalid1'.length; | ||
const UNBONDING_SYMBOL_LENGTH = 41 - 'unbonding_epoch_'.length; | ||
|
||
// If the metadata is for a delegation or unbonding tokens, customize its symbol. | ||
// We can't trust the validator's self-described name, so use their validator ID (in metadata.display). | ||
export const customizeSymbol = (metadata: Metadata) => { | ||
const delegationMatch = assetPatterns.delegationToken.exec(metadata.display); | ||
if (delegationMatch) { | ||
const { id } = delegationMatch.groups as unknown as DelegationCaptureGroups; | ||
const shortenedId = id.slice(0, DELEGATION_SYMBOL_LENGTH); | ||
metadata.symbol = `Delegated UM (${shortenedId}...)`; | ||
} | ||
|
||
const unbondingMatch = assetPatterns.unbondingToken.exec(metadata.display); | ||
if (unbondingMatch) { | ||
const { id, epoch } = unbondingMatch.groups as unknown as UnbondingCaptureGroups; | ||
const shortenedId = id.slice(0, UNBONDING_SYMBOL_LENGTH); | ||
metadata.symbol = `Unbonding UM, epoch ${epoch} (${shortenedId}...)`; | ||
} | ||
}; |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.