codama-renderers-dart 0.4.0 → 0.4.2

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.
@@ -1 +1 @@
1
- {"version":3,"file":"accountPage.d.ts","sourceRoot":"","sources":["../../../src/fragments/accountPage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAuB,MAAM,eAAe,CAAC;AAItE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAQrD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAIvD;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,WAAW,EACjB,KAAK,EAAE,WAAW,GACjB,QAAQ,CAkLV"}
1
+ {"version":3,"file":"accountPage.d.ts","sourceRoot":"","sources":["../../../src/fragments/accountPage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAuB,MAAM,eAAe,CAAC;AAItE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAQrD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAIvD;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,WAAW,EACjB,KAAK,EAAE,WAAW,GACjB,QAAQ,CA0LV"}
@@ -1,4 +1,4 @@
1
- import type { InstructionNode } from "@codama/nodes";
1
+ import { InstructionNode } from "@codama/nodes";
2
2
  import type { Fragment } from "../utils/fragment.js";
3
3
  import type { RenderScope } from "../utils/options.js";
4
4
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"instructionPage.d.ts","sourceRoot":"","sources":["../../../src/fragments/instructionPage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,eAAe,EAChB,MAAM,eAAe,CAAC;AAGvB,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAQrD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAIvD;;GAEG;AACH,wBAAgB,0BAA0B,CACxC,IAAI,EAAE,eAAe,EACrB,KAAK,EAAE,WAAW,GACjB,QAAQ,CAoOV"}
1
+ {"version":3,"file":"instructionPage.d.ts","sourceRoot":"","sources":["../../../src/fragments/instructionPage.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,eAAe,EAChB,MAAM,eAAe,CAAC;AAGvB,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAQrD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAKvD;;GAEG;AACH,wBAAgB,0BAA0B,CACxC,IAAI,EAAE,eAAe,EACrB,KAAK,EAAE,WAAW,GACjB,QAAQ,CA4PV"}
@@ -1 +1 @@
1
- {"version":3,"file":"pdaPage.d.ts","sourceRoot":"","sources":["../../../src/fragments/pdaPage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAG7C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAOrD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAGvD;;GAEG;AACH,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,OAAO,EACb,KAAK,EAAE,WAAW,GACjB,QAAQ,CAmGV"}
1
+ {"version":3,"file":"pdaPage.d.ts","sourceRoot":"","sources":["../../../src/fragments/pdaPage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAG7C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAOrD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAKvD;;GAEG;AACH,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,OAAO,EACb,KAAK,EAAE,WAAW,GACjB,QAAQ,CAmJV"}
@@ -1 +1 @@
1
- {"version":3,"file":"programPage.d.ts","sourceRoot":"","sources":["../../../src/fragments/programPage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAEjD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAQrD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAGvD;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,WAAW,EACjB,KAAK,EAAE,WAAW,GACjB,QAAQ,CA2CV"}
1
+ {"version":3,"file":"programPage.d.ts","sourceRoot":"","sources":["../../../src/fragments/programPage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAEjD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAQrD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAIvD;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,WAAW,EACjB,KAAK,EAAE,WAAW,GACjB,QAAQ,CAgEV"}
@@ -5,4 +5,5 @@ export * from "./importMap.js";
5
5
  export * from "./nameTransformers.js";
6
6
  export * from "./options.js";
7
7
  export * from "./typeManifest.js";
8
+ export * from "./wellKnownAddresses.js";
8
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,yBAAyB,CAAC"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Maps well-known Solana public keys to their canonical Dart constant names
3
+ * in `package:solana_kit_addresses`. When the renderer encounters a known
4
+ * address, it emits a re-export from that package instead of hardcoding the
5
+ * address string.
6
+ *
7
+ * The keys are the base-58 public key strings as they appear in IDL/Codama nodes.
8
+ * The values are the Dart constant names exported by `solana_kit_addresses`.
9
+ */
10
+ export declare const WELL_KNOWN_ADDRESSES: ReadonlyMap<string, string>;
11
+ //# sourceMappingURL=wellKnownAddresses.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wellKnownAddresses.d.ts","sourceRoot":"","sources":["../../../src/utils/wellKnownAddresses.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,eAAO,MAAM,oBAAoB,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAsD3D,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"getRenderMapVisitor.d.ts","sourceRoot":"","sources":["../../../src/visitors/getRenderMapVisitor.ts"],"names":[],"mappings":"AAQA,OAAO,EACL,KAAK,SAAS,EAIf,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,KAAK,OAAO,EASb,MAAM,uBAAuB,CAAC;AAE/B,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,KAAK,EAAE,mBAAmB,EAAe,MAAM,qBAAqB,CAAC;AAa5E;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,GAAE,mBAAwB,GAChC,OAAO,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,UAAU,GAAG,aAAa,GAAG,aAAa,GAAG,iBAAiB,GAAG,iBAAiB,GAAG,SAAS,CAAC,CAkO9H"}
1
+ {"version":3,"file":"getRenderMapVisitor.d.ts","sourceRoot":"","sources":["../../../src/visitors/getRenderMapVisitor.ts"],"names":[],"mappings":"AAQA,OAAO,EACL,KAAK,SAAS,EAIf,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,KAAK,OAAO,EASb,MAAM,uBAAuB,CAAC;AAE/B,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,KAAK,EAAE,mBAAmB,EAAe,MAAM,qBAAqB,CAAC;AAa5E;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,GAAE,mBAAwB,GAChC,OAAO,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,UAAU,GAAG,aAAa,GAAG,aAAa,GAAG,iBAAiB,GAAG,iBAAiB,GAAG,SAAS,CAAC,CAwK9H"}
@@ -15,5 +15,5 @@ export declare function getTypeManifestVisitor(input: {
15
15
  linkables: LinkableDictionary;
16
16
  stack: NodeStack;
17
17
  nonScalarEnums?: CamelCaseString[];
18
- }): Visitor<TypeManifest, "accountNode" | "definedTypeNode" | "errorNode" | "instructionAccountNode" | "instructionArgumentNode" | "instructionByteDeltaNode" | "instructionNode" | "instructionRemainingAccountsNode" | "instructionStatusNode" | "pdaNode" | "programNode" | "pdaSeedValueNode" | "accountBumpValueNode" | "accountValueNode" | "argumentValueNode" | "conditionalValueNode" | "identityValueNode" | "payerValueNode" | "pdaValueNode" | "programIdValueNode" | "resolverValueNode" | "fixedCountNode" | "prefixedCountNode" | "remainderCountNode" | "constantDiscriminatorNode" | "fieldDiscriminatorNode" | "sizeDiscriminatorNode" | "accountLinkNode" | "definedTypeLinkNode" | "instructionAccountLinkNode" | "instructionArgumentLinkNode" | "instructionLinkNode" | "pdaLinkNode" | "programLinkNode" | "constantPdaSeedNode" | "variablePdaSeedNode" | "enumEmptyVariantTypeNode" | "enumStructVariantTypeNode" | "enumTupleVariantTypeNode" | "amountTypeNode" | "arrayTypeNode" | "booleanTypeNode" | "bytesTypeNode" | "dateTimeTypeNode" | "enumTypeNode" | "fixedSizeTypeNode" | "hiddenPrefixTypeNode" | "hiddenSuffixTypeNode" | "mapTypeNode" | "numberTypeNode" | "optionTypeNode" | "postOffsetTypeNode" | "preOffsetTypeNode" | "publicKeyTypeNode" | "remainderOptionTypeNode" | "sentinelTypeNode" | "setTypeNode" | "sizePrefixTypeNode" | "solAmountTypeNode" | "stringTypeNode" | "structTypeNode" | "tupleTypeNode" | "zeroableOptionTypeNode" | "structFieldTypeNode" | "mapEntryValueNode" | "arrayValueNode" | "booleanValueNode" | "bytesValueNode" | "constantValueNode" | "enumValueNode" | "mapValueNode" | "noneValueNode" | "numberValueNode" | "publicKeyValueNode" | "setValueNode" | "someValueNode" | "stringValueNode" | "structValueNode" | "tupleValueNode" | "structFieldValueNode" | "rootNode">;
18
+ }): Visitor<TypeManifest, "accountNode" | "constantNode" | "definedTypeNode" | "errorNode" | "eventNode" | "instructionAccountNode" | "instructionArgumentNode" | "instructionByteDeltaNode" | "instructionNode" | "instructionRemainingAccountsNode" | "instructionStatusNode" | "pdaNode" | "programNode" | "pdaSeedValueNode" | "accountBumpValueNode" | "accountValueNode" | "argumentValueNode" | "conditionalValueNode" | "identityValueNode" | "payerValueNode" | "pdaValueNode" | "programIdValueNode" | "resolverValueNode" | "fixedCountNode" | "prefixedCountNode" | "remainderCountNode" | "constantDiscriminatorNode" | "fieldDiscriminatorNode" | "sizeDiscriminatorNode" | "accountLinkNode" | "definedTypeLinkNode" | "instructionAccountLinkNode" | "instructionArgumentLinkNode" | "instructionLinkNode" | "pdaLinkNode" | "programLinkNode" | "constantPdaSeedNode" | "variablePdaSeedNode" | "enumEmptyVariantTypeNode" | "enumStructVariantTypeNode" | "enumTupleVariantTypeNode" | "amountTypeNode" | "arrayTypeNode" | "booleanTypeNode" | "bytesTypeNode" | "dateTimeTypeNode" | "enumTypeNode" | "fixedSizeTypeNode" | "hiddenPrefixTypeNode" | "hiddenSuffixTypeNode" | "mapTypeNode" | "numberTypeNode" | "optionTypeNode" | "postOffsetTypeNode" | "preOffsetTypeNode" | "publicKeyTypeNode" | "remainderOptionTypeNode" | "sentinelTypeNode" | "setTypeNode" | "sizePrefixTypeNode" | "solAmountTypeNode" | "stringTypeNode" | "structTypeNode" | "tupleTypeNode" | "zeroableOptionTypeNode" | "structFieldTypeNode" | "mapEntryValueNode" | "arrayValueNode" | "booleanValueNode" | "bytesValueNode" | "constantValueNode" | "enumValueNode" | "mapValueNode" | "noneValueNode" | "numberValueNode" | "publicKeyValueNode" | "setValueNode" | "someValueNode" | "stringValueNode" | "structValueNode" | "tupleValueNode" | "structFieldValueNode" | "rootNode">;
19
19
  //# sourceMappingURL=getTypeManifestVisitor.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"getTypeManifestVisitor.d.ts","sourceRoot":"","sources":["../../../src/visitors/getTypeManifestVisitor.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,KAAK,eAAe,EA8BrB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,SAAS,EACd,KAAK,OAAO,EAIb,MAAM,uBAAuB,CAAC;AAI/B,OAAO,EAEL,KAAK,YAAY,EAKlB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,KAAK,WAAW,EAAa,MAAM,8BAA8B,CAAC;AAE3E;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG,UAAU,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAE5E;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE;IAC5C,OAAO,EAAE,WAAW,CAAC;IACrB,SAAS,EAAE,kBAAkB,CAAC;IAC9B,KAAK,EAAE,SAAS,CAAC;IACjB,cAAc,CAAC,EAAE,eAAe,EAAE,CAAC;CACpC,8vDAilBA"}
1
+ {"version":3,"file":"getTypeManifestVisitor.d.ts","sourceRoot":"","sources":["../../../src/visitors/getTypeManifestVisitor.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,KAAK,eAAe,EA8BrB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,SAAS,EACd,KAAK,OAAO,EAIb,MAAM,uBAAuB,CAAC;AAI/B,OAAO,EAEL,KAAK,YAAY,EAKlB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,KAAK,WAAW,EAAa,MAAM,8BAA8B,CAAC;AAE3E;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG,UAAU,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAE5E;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE;IAC5C,OAAO,EAAE,WAAW,CAAC;IACrB,SAAS,EAAE,kBAAkB,CAAC;IAC9B,KAAK,EAAE,SAAS,CAAC;IACjB,cAAc,CAAC,EAAE,eAAe,EAAE,CAAC;CACpC,6xDAymBA"}
package/package.json CHANGED
@@ -1,23 +1,31 @@
1
1
  {
2
- "name": "codama-renderers-dart",
3
- "version": "0.4.0",
2
+ "dependencies": {
3
+ "@codama/errors": "^1.4.4",
4
+ "@codama/nodes": "^1.4.4",
5
+ "@codama/renderers-core": "^1.3.3",
6
+ "@codama/visitors-core": "^1.4.4"
7
+ },
4
8
  "description": "Codama renderer for generating Dart code targeting the solana_kit SDK",
9
+ "devDependencies": {
10
+ "@codama/nodes-from-anchor": "^1.3.9",
11
+ "@codama/renderers-js": "^2.0.2",
12
+ "@vitest/coverage-v8": "4.1.0"
13
+ },
14
+ "engines": {
15
+ "node": ">=18"
16
+ },
5
17
  "exports": {
6
- "node": {
7
- "import": "./dist/index.node.mjs",
8
- "require": "./dist/index.node.cjs"
9
- },
10
18
  "browser": {
11
19
  "import": "./dist/index.browser.mjs",
12
20
  "require": "./dist/index.browser.cjs"
13
21
  },
22
+ "node": {
23
+ "import": "./dist/index.node.mjs",
24
+ "require": "./dist/index.node.cjs"
25
+ },
14
26
  "react-native": "./dist/index.react-native.mjs",
15
27
  "types": "./dist/types/index.d.ts"
16
28
  },
17
- "main": "./dist/index.node.cjs",
18
- "module": "./dist/index.node.mjs",
19
- "types": "./dist/types/index.d.ts",
20
- "type": "module",
21
29
  "files": [
22
30
  "dist",
23
31
  "src"
@@ -30,28 +38,13 @@
30
38
  "code-generator"
31
39
  ],
32
40
  "license": "MIT",
33
- "repository": {
34
- "type": "git",
35
- "url": "https://github.com/openbudgetfun/solana_kit.git",
36
- "directory": "packages/codama-renderers-dart"
37
- },
38
- "dependencies": {
39
- "@codama/errors": "^1.4.4",
40
- "@codama/nodes": "^1.4.4",
41
- "@codama/renderers-core": "^1.3.3",
42
- "@codama/visitors-core": "^1.4.4"
43
- },
44
- "devDependencies": {
45
- "@codama/nodes-from-anchor": "^1.3.9",
46
- "@codama/renderers-js": "^2.0.2",
47
- "@vitest/coverage-v8": "3.2.4"
48
- },
49
- "engines": {
50
- "node": ">=18"
51
- },
41
+ "main": "./dist/index.node.cjs",
42
+ "module": "./dist/index.node.mjs",
43
+ "name": "codama-renderers-dart",
52
44
  "publishConfig": {
53
45
  "access": "public"
54
46
  },
47
+ "repository": "https://github.com/openbudgetfun/solana_kit/tree/main/packages/codama-renderers-dart",
55
48
  "scripts": {
56
49
  "build": "pnpm exec rimraf dist && pnpm exec tsup && pnpm exec tsc -p tsconfig.declarations.json",
57
50
  "lint": "eslint --ext .ts src",
@@ -59,5 +52,8 @@
59
52
  "test:coverage": "pnpm exec vitest run --coverage.enabled --coverage.reporter=lcov",
60
53
  "test:watch": "pnpm exec vitest",
61
54
  "typecheck": "pnpm exec tsc --noEmit"
62
- }
63
- }
55
+ },
56
+ "type": "module",
57
+ "types": "./dist/types/index.d.ts",
58
+ "version": "0.4.2"
59
+ }
@@ -44,6 +44,11 @@ export function getAccountPageFragment(
44
44
  .map((f: StructFieldTypeNode) => ` required this.${camelCase(f.name as string)},`)
45
45
  .join("\n");
46
46
 
47
+ // Empty structs use a no-arg constructor; `const Foo({})` is invalid Dart.
48
+ const ctorSignature = fields.length === 0
49
+ ? `const ${typeName}();`
50
+ : `const ${typeName}({\n${ctorParams}\n });`;
51
+
47
52
  const eqChecks =
48
53
  fields.length === 0
49
54
  ? "true"
@@ -54,9 +59,14 @@ export function getAccountPageFragment(
54
59
  )
55
60
  .join(" &&\n ");
56
61
 
57
- const hashFields = fields
58
- .map((f: StructFieldTypeNode) => camelCase(f.name as string))
59
- .join(", ");
62
+ const hashFieldNames = fields.map((f: StructFieldTypeNode) => camelCase(f.name as string));
63
+ // `Object.hash()` requires at least two arguments, so handle 0/1 fields specially.
64
+ const hashCodeExpr =
65
+ hashFieldNames.length === 0
66
+ ? "0"
67
+ : hashFieldNames.length === 1
68
+ ? `${hashFieldNames[0]}.hashCode`
69
+ : `Object.hash(${hashFieldNames.join(", ")})`;
60
70
 
61
71
  const toStringFields = fields
62
72
  .map(
@@ -129,9 +139,7 @@ ${use("decodeAccount", "solanaAccounts")}
129
139
 
130
140
  @immutable
131
141
  class ${fragmentFromString(typeName)} {
132
- const ${fragmentFromString(typeName)}({
133
- ${fragmentFromString(ctorParams)}
134
- });
142
+ ${fragmentFromString(ctorSignature)}
135
143
 
136
144
  ${fragmentFromString(fieldDecls)}
137
145
 
@@ -143,7 +151,7 @@ ${fragmentFromString(fieldDecls)}
143
151
  ${fragmentFromString(eqChecks)};
144
152
 
145
153
  @override
146
- int get hashCode => Object.hash(${fragmentFromString(hashFields)});
154
+ int get hashCode => ${fragmentFromString(hashCodeExpr)};
147
155
 
148
156
  @override
149
157
  String toString() => '${fragmentFromString(typeName)}(${fragmentFromString(toStringFields)})';
@@ -1,4 +1,4 @@
1
- import type {
1
+ import {
2
2
  InstructionAccountNode,
3
3
  InstructionArgumentNode,
4
4
  InstructionNode,
@@ -16,6 +16,7 @@ import {
16
16
  import type { RenderScope } from "../utils/options.js";
17
17
  import { camelCase, pascalCase } from "../utils/nameTransformers.js";
18
18
  import { getDiscriminatorConstantsFragment } from "./discriminatorConstants.js";
19
+ import { WELL_KNOWN_ADDRESSES } from "../utils/wellKnownAddresses.js";
19
20
 
20
21
  /**
21
22
  * Generate a full Dart file for an instruction.
@@ -338,8 +339,14 @@ function getDefaultValue(arg: InstructionArgumentNode): string {
338
339
  return String(dv.boolean);
339
340
  case "stringValueNode":
340
341
  return `'${dv.string}'`;
341
- case "publicKeyValueNode":
342
+ case "publicKeyValueNode": {
343
+ const wellKnownName = WELL_KNOWN_ADDRESSES.get(dv.publicKey);
344
+ if (wellKnownName) {
345
+ use(wellKnownName, "solanaAddresses");
346
+ return wellKnownName;
347
+ }
342
348
  return `Address('${dv.publicKey}')`;
349
+ }
343
350
  case "noneValueNode":
344
351
  return "null";
345
352
  case "bytesValueNode": {
@@ -10,6 +10,8 @@ import {
10
10
  } from "../utils/fragment.js";
11
11
  import type { RenderScope } from "../utils/options.js";
12
12
  import { camelCase, pascalCase } from "../utils/nameTransformers.js";
13
+ import type { TypeManifest } from "../utils/typeManifest.js";
14
+ import { WELL_KNOWN_ADDRESSES } from "../utils/wellKnownAddresses.js";
13
15
 
14
16
  /**
15
17
  * Generate a full Dart file for a PDA.
@@ -40,10 +42,14 @@ export function getPdaPageFragment(
40
42
  // Build seeds class if there are variable seeds
41
43
  const hasSeedsClass = variableSeeds.length > 0;
42
44
 
45
+ // Collect type manifests so their imports can be merged into the result.
46
+ const seedManifests: TypeManifest[] = [];
47
+
43
48
  const seedFieldDecls = variableSeeds
44
49
  .map((s) => {
45
50
  if (s.kind !== "variablePdaSeedNode") return "";
46
51
  const manifest = visit(s.type, scope.typeManifestVisitor);
52
+ seedManifests.push(manifest);
47
53
  return ` final ${manifest.type.content} ${camelCase(s.name as string)};`;
48
54
  })
49
55
  .join("\n");
@@ -64,15 +70,25 @@ export function getPdaPageFragment(
64
70
  } else if (seed.value.kind === "stringValueNode") {
65
71
  seedValues.push(` '${seed.value.string}',`);
66
72
  } else if (seed.value.kind === "publicKeyValueNode") {
67
- seedValues.push(
68
- ` getAddressEncoder().encode(Address('${seed.value.publicKey}')),`,
69
- );
73
+ const wellKnownSeedName = WELL_KNOWN_ADDRESSES.get(seed.value.publicKey);
74
+ if (wellKnownSeedName) {
75
+ use(wellKnownSeedName, "solanaAddresses");
76
+ seedValues.push(
77
+ ` getAddressEncoder().encode(${wellKnownSeedName}),`,
78
+ );
79
+ } else {
80
+ seedValues.push(
81
+ ` getAddressEncoder().encode(Address('${seed.value.publicKey}')),`,
82
+ );
83
+ }
70
84
  } else if (seed.value.kind === "numberValueNode") {
71
85
  const manifest = visit(seed.type, scope.typeManifestVisitor);
86
+ seedManifests.push(manifest);
72
87
  seedValues.push(` ${manifest.encoder.content}.encode(${seed.value.number}),`);
73
88
  }
74
89
  } else if (seed.kind === "variablePdaSeedNode") {
75
90
  const manifest = visit(seed.type, scope.typeManifestVisitor);
91
+ seedManifests.push(manifest);
76
92
  seedValues.push(
77
93
  ` ${manifest.encoder.content}.encode(seeds.${camelCase(seed.name as string)}),`,
78
94
  );
@@ -80,20 +96,31 @@ export function getPdaPageFragment(
80
96
  }
81
97
 
82
98
  // Program address parameter
99
+ const wellKnownProgramName = node.programId
100
+ ? WELL_KNOWN_ADDRESSES.get(node.programId)
101
+ : undefined;
102
+ if (wellKnownProgramName) {
103
+ use(wellKnownProgramName, "solanaAddresses");
104
+ }
83
105
  const programIdParam = node.programId
84
- ? `Address programAddress = const Address('${node.programId}')`
106
+ ? wellKnownProgramName
107
+ ? `Address programAddress = ${wellKnownProgramName}`
108
+ : `Address programAddress = const Address('${node.programId}')`
85
109
  : "required Address programAddress";
86
110
 
87
111
  const typedDataImport = hasByteSeeds
88
112
  ? use("Uint8List", "dartTypedData")
89
113
  : fragmentFromString("");
90
114
 
115
+ // `@immutable` is only needed when a seeds class is emitted.
116
+ const metaImport = hasSeedsClass ? use("immutable", "meta") : fragmentFromString("");
117
+
91
118
  const parts: Fragment[] = [
92
119
  fragment`// Auto-generated. Do not edit.
93
120
  // ignore_for_file: type=lint
94
121
 
95
122
  ${typedDataImport}
96
- ${use("immutable", "meta")}
123
+ ${metaImport}
97
124
  ${use("Address", "solanaAddresses")}
98
125
  ${use("getAddressEncoder", "solanaAddresses")}
99
126
  ${use("getProgramDerivedAddress", "solanaAddresses")}`,
@@ -129,7 +156,16 @@ ${fragmentFromString(seedValues.join("\n"))}
129
156
  );
130
157
  }`);
131
158
 
132
- return mergeFragments(parts, (cs) => cs.join("\n"));
159
+ const result = mergeFragments(parts, (cs) => cs.join("\n"));
160
+
161
+ // Merge seed type manifest imports (encoders/types) into the result so that
162
+ // helpers like `getU64Encoder` are imported.
163
+ for (const manifest of seedManifests) {
164
+ result.imports.mergeWith(manifest.encoder.imports);
165
+ result.imports.mergeWith(manifest.type.imports);
166
+ }
167
+
168
+ return result;
133
169
  }
134
170
 
135
171
  function bytesValueToDart(hex: string): string {
@@ -10,6 +10,7 @@ import {
10
10
  } from "../utils/fragment.js";
11
11
  import type { RenderScope } from "../utils/options.js";
12
12
  import { camelCase, pascalCase } from "../utils/nameTransformers.js";
13
+ import { WELL_KNOWN_ADDRESSES } from "../utils/wellKnownAddresses.js";
13
14
 
14
15
  /**
15
16
  * Generate a full Dart file for a program.
@@ -21,15 +22,36 @@ export function getProgramPageFragment(
21
22
  const name = node.name as string;
22
23
  const addressConstName = scope.nameApi.programAddressConstant(name);
23
24
 
24
- const parts: Fragment[] = [
25
- fragment`// Auto-generated. Do not edit.
25
+ const wellKnownName = WELL_KNOWN_ADDRESSES.get(node.publicKey);
26
+
27
+ // For well-known addresses, export and alias the canonical constant from
28
+ // solana_kit_addresses instead of hardcoding the address string.
29
+ // When the generated name matches the canonical name, a simple export suffices.
30
+ // When they differ, we also need a local const alias.
31
+ // For unknown addresses, fall back to the original Address('...') pattern.
32
+ const addressDeclaration: Fragment = wellKnownName
33
+ ? addressConstName === wellKnownName
34
+ ? fragment`// Auto-generated. Do not edit.
35
+ // ignore_for_file: type=lint
36
+
37
+ /// The address of the ${fragmentFromString(pascalCase(name))} program.
38
+ export 'package:solana_kit_addresses/solana_kit_addresses.dart' show ${fragmentFromString(wellKnownName)};`
39
+ : fragment`${use(wellKnownName, "solanaAddresses")}
40
+
41
+ // Auto-generated. Do not edit.
42
+ // ignore_for_file: type=lint
43
+
44
+ /// The address of the ${fragmentFromString(pascalCase(name))} program.
45
+ const ${fragmentFromString(addressConstName)} = ${fragmentFromString(wellKnownName)};`
46
+ : fragment`// Auto-generated. Do not edit.
26
47
  // ignore_for_file: type=lint
27
48
 
28
49
  ${use("Address", "solanaAddresses")}
29
50
 
30
51
  /// The address of the ${fragmentFromString(pascalCase(name))} program.
31
- const ${fragmentFromString(addressConstName)} = Address('${fragmentFromString(node.publicKey)}');`,
32
- ];
52
+ const ${fragmentFromString(addressConstName)} = Address('${fragmentFromString(node.publicKey)}');`;
53
+
54
+ const parts: Fragment[] = [addressDeclaration];
33
55
 
34
56
  // Account identifier enum
35
57
  const accounts = node.accounts ?? [];
@@ -60,4 +82,4 @@ ${fragmentFromString(instrVariants)}
60
82
  }
61
83
 
62
84
  return mergeFragments(parts, (cs) => cs.join("\n"));
63
- }
85
+ }
@@ -5,3 +5,4 @@ export * from "./importMap.js";
5
5
  export * from "./nameTransformers.js";
6
6
  export * from "./options.js";
7
7
  export * from "./typeManifest.js";
8
+ export * from "./wellKnownAddresses.js";
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Maps well-known Solana public keys to their canonical Dart constant names
3
+ * in `package:solana_kit_addresses`. When the renderer encounters a known
4
+ * address, it emits a re-export from that package instead of hardcoding the
5
+ * address string.
6
+ *
7
+ * The keys are the base-58 public key strings as they appear in IDL/Codama nodes.
8
+ * The values are the Dart constant names exported by `solana_kit_addresses`.
9
+ */
10
+ export const WELL_KNOWN_ADDRESSES: ReadonlyMap<string, string> = new Map([
11
+ // Agave / Solana native programs
12
+ ['11111111111111111111111111111111', 'systemProgramAddress'],
13
+ ['AddressLookupTab1e1111111111111111111111111', 'addressLookupTableProgramAddress'],
14
+ ['BPFLoader2111111111111111111111111111111111', 'bpfLoaderProgramAddress'],
15
+ ['BPFLoader1111111111111111111111111111111111', 'bpfLoaderDeprecatedProgramAddress'],
16
+ ['BPFLoaderUpgradeab1e11111111111111111111111', 'bpfLoaderUpgradeableProgramAddress'],
17
+ ['ComputeBudget111111111111111111111111111111', 'computeBudgetProgramAddress'],
18
+ ['Config1111111111111111111111111111111111111', 'configProgramAddress'],
19
+ ['Ed25519SigVerify111111111111111111111111111', 'ed25519ProgramAddress'],
20
+ ['Feature111111111111111111111111111111111111', 'featureProgramAddress'],
21
+ ['1nc1nerator11111111111111111111111111111111', 'incineratorAddress'],
22
+ ['LoaderV411111111111111111111111111111111111', 'loaderV4ProgramAddress'],
23
+ ['NativeLoader1111111111111111111111111111', 'nativeLoaderProgramAddress'],
24
+ ['KeccakSecp256k11111111111111111111111111111', 'secp256k1ProgramAddress'],
25
+ ['Secp256r1SigVerify1111111111111111111111111', 'secp256r1ProgramAddress'],
26
+ ['Stake11111111111111111111111111111111111111', 'stakeProgramAddress'],
27
+ ['StakeConfig1111111111111111111111111111', 'stakeConfigAddress'],
28
+ ['Vote111111111111111111111111111111111111111', 'voteProgramAddress'],
29
+ ['ZkTokenProof1111111111111111111111111111111', 'zkTokenProofProgramAddress'],
30
+ ['ZkE1Gama1Proof11111111111111111111111111111', 'zkElgamalProofProgramAddress'],
31
+
32
+ // Sysvars
33
+ ['SysvarC1ock11111111111111111111111111111111', 'sysvarClockAddress'],
34
+ ['Rent11111111111111111111111111111111111111', 'sysvarRentAddress'],
35
+ ['11111111111111111111111111111111111111111111', 'sysvarRecentBlockhashesAddress'], // note: 44 chars
36
+ ['SysvarFees1111111111111111111111111111111111', 'sysvarFeesAddress'],
37
+ ['Sysvar1nstruct1ons11111111111111111111111111', 'sysvarInstructionsAddress'],
38
+ ['SysvarEpochSchedu1e111111111111111111111111', 'sysvarEpochScheduleAddress'],
39
+ ['SysvarRewards111111111111111111111111111111', 'sysvarRewardsAddress'],
40
+ ['SysvarStakeHistory1111111111111111111111111', 'sysvarStakeHistoryAddress'],
41
+ ['SysvarS1otHashes111111111111111111111111111', 'sysvarSlotHashesAddress'],
42
+ ['SysvarS1otHistory11111111111111111111111111', 'sysvarSlotHistoryAddress'],
43
+ ['Sysvar1111111111111111111111111111111111111', 'sysvarOwnerAddress'],
44
+
45
+ // SPL programs
46
+ ['TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', 'tokenProgramAddress'],
47
+ ['TokenzQdBNb4qyze1S1U9AHB8MGXmNK1REkTPT5Z3Y', 'token2022ProgramAddress'],
48
+ ['ATokenGPvbdGVxr1b2hvZbsiqW5xWH25ef7s3c8BnQKu', 'associatedTokenProgramAddress'],
49
+ ['Memo1UhkJRfRhVq1sR7Y7Nto1s3J2mXTT3L6Wk4K2m6', 'memoProgramAddress'],
50
+ ['MemoSq4gqABXKKYWVqKkV3m3kb1cTR7F2UMy9r6kFNK', 'memoLegacyProgramAddress'],
51
+
52
+ // Metaplex programs
53
+ ['metaqbxxU9qX8rZXkmUJ7haCrXXz2W1PSUq1Rn3E1od', 'tokenMetadataProgramAddress'],
54
+ ['BGUMAp9V1mQ2KV8t34L5u3gZsXYZaYDBdKkc1xYk1qA1', 'mplBubblegumProgramAddress'],
55
+ ['auth9SigNpDKz4s8cHr3MFBPS1phbRKLSCN3aBe9sS', 'authRulesProgramAddress'],
56
+ ['CoREENxT6tW1Ho6BW6W5Z4N41ci5Xz2mmrR2kErmM5TR', 'metaplexCoreProgramAddress'],
57
+ ['cmtMqR4bPM9sEV3bPnJQq5s2EnYw4N5vQ8hWhEd1xzS', 'splAccountCompressionProgramAddress'],
58
+ ['noopb9skMVngR5Qi4sczwFr1jU4V4F7nm8xzFQK9C', 'noopProgramAddress'],
59
+
60
+ // Well-known mints
61
+ ['So11111111111111111111111111111111111111112', 'wrappedSolAddress'],
62
+ ['EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v', 'usdcAddress'],
63
+ ['Es9vMFrzaCERm6YKXx6bqKr1Rmd9b5v3J8rM5e4rfF4', 'usdtAddress'],
64
+ ]);
@@ -137,9 +137,8 @@ export function getTypeManifestVisitor(input: {
137
137
  const codecName = getNumberCodecName(format);
138
138
 
139
139
  return {
140
- type: dartType === "BigInt"
141
- ? use("BigInt", "dartTypedData")
142
- : fragmentFromString(dartType),
140
+ // `BigInt` and other number types live in `dart:core` and need no import.
141
+ type: fragmentFromString(dartType),
143
142
  encoder: fragment`${use(
144
143
  `get${codecName}Encoder`,
145
144
  "solanaCodecsNumbers",
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 Ifiok Jr.
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.