Skip to content
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

Default Token Address Linking #5

Merged
merged 2 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@ Some generic schemas for improving the usability of Frequency

## Schemas

### Default Token Address

- Goal: Allow MSAs to list their default token sending and receiving addresses, both from Frequency and other chains
- Payload Location Options
- Itemized: Each piece of data is atomic
- Signature Required: Creating or removing connecting addresses should require user sign-off

#### Data

- Address: String form of the token address for the specific chain
- Token: SLIP-0044 Chain Identifier

#### References

- [SLIP-0044](https://github.com/satoshilabs/slips/blob/master/slip-0044.md)

## Use to Deploy Schemas

Expand Down
22 changes: 22 additions & 0 deletions schemas/defaultTokenAddress.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Token Address is a way to record a token sending and receiving addresses for an MSA
* Should be stored using Itemized and Signature Required
* SLIP-0044 Standard: https://github.com/satoshilabs/slips/blob/master/slip-0044.md
*/
export default {
type: "record",
name: "DefaultTokenAddress",
namespace: "frequency",
fields: [
{
name: "token_slip_0044",
type: "int",
doc: "Network for this token address using SLIP-0044 registered coin type integers",
},
{
name: "address",
type: "string",
doc: "The address as a string encoded in standard way for the given coin type",
},
],
};
25 changes: 25 additions & 0 deletions schemas/defaultTokenAddress.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { expect, test, it } from "vitest";
import avro from "avsc";
import defaultTokenAddress from "./defaultTokenAddress.js";

test("Token Addresses Schema is Avro", () => {
const schema = avro.Type.forSchema(defaultTokenAddress);
expect(schema).toBeDefined();
});

test("Token Addresses Schema can take the correct data", () => {
const schema = avro.Type.forSchema(defaultTokenAddress);
const dot = schema.toBuffer({
token_slip_0044: 354,
address: "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY",
});
expect(dot).toBeDefined();
expect(schema.fromBuffer(dot).token_slip_0044).toBe(354);

const btc = schema.toBuffer({
token_slip_0044: 0,
address: "34xp4vRoCGJym3xR7yCVPFHoCNxv4Twseo",
});
expect(btc).toBeDefined();
expect(schema.fromBuffer(btc).token_slip_0044).toBe(0);
});
14 changes: 13 additions & 1 deletion schemas/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
export const schemas = new Map([]);
import * as defaultTokenAddress from "./defaultTokenAddress.js";

export const schemas = new Map([
[
"defaultTokenAddress",
wilwade marked this conversation as resolved.
Show resolved Hide resolved
{
model: defaultTokenAddress,
modelType: "AvroBinary",
payloadLocation: "Itemized",
settings: ["SignatureRequired"],
},
],
]);