@swapkit/helpers 1.0.0-rc.74 → 1.0.0-rc.75

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -18,7 +18,7 @@ describe("getMemoFor", () => {
18
18
  }
19
19
  });
20
20
 
21
- describe("for Unbond and Thorname Register", () => {
21
+ describe("for Unbond and Thorname/Mayaname Register", () => {
22
22
  test("returns correct memo for Unbond", () => {
23
23
  const result = getMemoFor(MemoType.UNBOND, { address: "ABC123", unbondAmount: 1000000000 });
24
24
  expect(result).toBe("UNBOND:ABC123:1000000000");
@@ -33,6 +33,16 @@ describe("getMemoFor", () => {
33
33
  });
34
34
  expect(result).toBe("~:thorname:BNB:0xABC123:0xDEF456");
35
35
  });
36
+
37
+ test("returns correct memo for Mayaname Register", () => {
38
+ const result = getMemoFor(MemoType.THORNAME_REGISTER, {
39
+ name: "mayaname",
40
+ chain: "BNB",
41
+ address: "0xABC123",
42
+ owner: "0xDEF456",
43
+ });
44
+ expect(result).toBe("~:mayaname:BNB:0xABC123:0xDEF456");
45
+ });
36
46
  });
37
47
 
38
48
  describe("for Deposit", () => {
@@ -5,6 +5,14 @@ export function getTHORNameCost(year: number) {
5
5
  return 10 + year;
6
6
  }
7
7
 
8
+ // 10 CACAO for register
9
+ // 1.0512 CACAO per year
10
+ export function getMAYANameCost(year: number) {
11
+ if (year < 0) throw new Error("Invalid number of year");
12
+ // round to max 10 decimals
13
+ return Math.round((10 + year * 1.0512) * 1e10) / 1e10;
14
+ }
15
+
8
16
  export function validateTHORName(name: string) {
9
17
  if (name.length > 30) return false;
10
18
 
@@ -13,6 +21,14 @@ export function validateTHORName(name: string) {
13
21
  return !!name.match(regex);
14
22
  }
15
23
 
24
+ export function validateMAYAName(name: string) {
25
+ if (name.length > 30) return false;
26
+
27
+ const regex = /^[a-zA-Z0-9+_-]+$/g;
28
+
29
+ return !!name.match(regex);
30
+ }
31
+
16
32
  export function derivationPathToString([network, chainId, account, change, index]: number[]) {
17
33
  const shortPath = typeof index !== "number";
18
34