From 597fc5c89a291c094c81d6525906db0daa8b43a1 Mon Sep 17 00:00:00 2001 From: ERoydev Date: Wed, 10 Sep 2025 15:15:05 +0300 Subject: [PATCH 01/33] refactor(typeManifest): Handle fixed-sized fields when extracting fields for template rendering --- src/TypeManifest.ts | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/src/TypeManifest.ts b/src/TypeManifest.ts index 259d95d..197eba7 100644 --- a/src/TypeManifest.ts +++ b/src/TypeManifest.ts @@ -20,24 +20,34 @@ export type TypeManifestOptions = { parentName?: string | null; }; +export interface TypeManifestField { + baseType: string; + field: string; + name: string; + nesting: number; + optional: boolean; + size?: number; + type: string; +} + // ' final Int64List i64_array;\n' + // ' final Int8List /* length: 2 */ fixed_i8;\n' + -export function extractFieldsFromTypeManifest(typeManifest: TypeManifest): { - baseType: string - field: string, - name: string, - nesting: number, - type: string, -}[] { +export function extractFieldsFromTypeManifest(typeManifest: TypeManifest): TypeManifestField[] { return typeManifest.type .split('\n') - .map((line) => { + .map((line): TypeManifestField | null => { // That handles lines like: final Uint8List fieldName; and extracts the type and name in order to be used from borsh readers/writers - const match = line.trim().match(/^final\s+([\w<>, ?]+)\s+(\w+);$/); + const match = line.trim().match(/^final\s+([\w<>, ?]+)(?:\s*\/\*\s*length:\s*\d+\s*\*\/)?\s+(\w+);$/); if (match && match[2] !== 'discriminator') { - const isOptional = /\?$/.test(match[1]); + let size: number | undefined; // Placeholder for size extraction logic if needed + const isOptional = /\?$/.test(match[1].trim()); // check if the string ends with a '?' const rawType = match[1].replace(/\?$/, '').trim(); + + const lengthMatch = line.match(/\/\*\s*length:\s*(\d+)\s*\*\//); // Extract length if present + if (lengthMatch) { + size = parseInt(lengthMatch[1]); + } // Count nesting depth of List<> let nesting = 0; @@ -50,22 +60,16 @@ export function extractFieldsFromTypeManifest(typeManifest: TypeManifest): { } return { - baseType: inner, + baseType: inner.trim(), field: line, name: match[2], nesting, optional: isOptional, - type: match[1].replace(/\?$/, ''), + size: size, + type: match[1].replace(/\?$/, '').trim(), }; } return null; }) - .filter((entry): entry is { - baseType: string; - field: string; - name: string; - nesting: number; - optional: boolean; - type: string; - } => entry !== null); + .filter((entry): entry is TypeManifestField => entry !== null); } \ No newline at end of file From 728c27c92865b9389b05017ce56f272e44abb79d Mon Sep 17 00:00:00 2001 From: ERoydev Date: Wed, 10 Sep 2025 15:15:29 +0300 Subject: [PATCH 02/33] fix(): Handle fixed-sized optional fields in optionTypeNode Visitor --- src/getTypeManifestVisitor.ts | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/getTypeManifestVisitor.ts b/src/getTypeManifestVisitor.ts index 64eef0d..713a4f5 100644 --- a/src/getTypeManifestVisitor.ts +++ b/src/getTypeManifestVisitor.ts @@ -82,7 +82,8 @@ export function getTypeManifestVisitor(options: TypeManifestOptions) { // Fixed-size typed array handler return { ...typedArrayManifest, - type: `${typedArrayManifest.type}`, + // If is a fixed-sized array, include the length in a comment so i can extract that using regex + type: `${typedArrayManifest.type} /* length: ${arrayType.count.value} */`, }; } return typedArrayManifest; @@ -266,14 +267,25 @@ export function getTypeManifestVisitor(options: TypeManifestOptions) { default: throw new Error(`Unknown number format: ${numberType.format}`); } - }, + }, visitOptionType(optionType: OptionTypeNode, { self }: { self: Visitor }): TypeManifest { const childManifest = visit(optionType.item, self); + // Regex to split type and comment (e.g., 'Uint32List /* length: 2 */') + const typeMatch = childManifest.type.match(/^([^\s]+)(.*)$/); + let typeWithOptional: string; + + if (typeMatch) { + typeWithOptional = `${typeMatch[1]}?${typeMatch[2]}`; + } else { + // Fallback if regex fails + typeWithOptional = `${childManifest.type}?`; + } + return { ...childManifest, - type: `${childManifest.type}?`, + type: typeWithOptional, }; }, @@ -318,7 +330,7 @@ export function getTypeManifestVisitor(options: TypeManifestOptions) { inlineStruct = false; const fieldManifest = visit(structFieldType.type, self); - + parentName = originalParentName; inlineStruct = originalInlineStruct; nestedStruct = originalNestedStruct; @@ -331,7 +343,7 @@ export function getTypeManifestVisitor(options: TypeManifestOptions) { field: `${docblock} final ${fieldManifest.type} ${fieldName};`, imports: fieldManifest.imports, nestedStructs: fieldManifest.nestedStructs, - type: fieldManifest.type, + type: fieldManifest.type, }; }, @@ -345,9 +357,10 @@ export function getTypeManifestVisitor(options: TypeManifestOptions) { const classConstrutor = ` ${pascalCase(structName)}({\n${structType.fields.map((field) => ` required this.${snakeCase(field.name)},`).join('\n')}\n });\n`; // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment - const fields = structType.fields.map((field) => + const fields = structType.fields.map((field: StructFieldTypeNode) => visit(field, self) ); + const fieldTypes = fields.map((field) => field.field).join('\n'); const mergedManifest = { imports: new ImportMap().mergeWith(...fields.map((f) => f.imports)), From ee076400e78412106e88b6bf7544461e07679139 Mon Sep 17 00:00:00 2001 From: ERoydev Date: Wed, 10 Sep 2025 15:39:43 +0300 Subject: [PATCH 03/33] ref(sharedTemplate): Added deserializing functions and one reusable to handle fixed arrays --- public/templates/pages/sharedPage.njk | 375 +++++++++++++++++++++----- 1 file changed, 304 insertions(+), 71 deletions(-) diff --git a/public/templates/pages/sharedPage.njk b/public/templates/pages/sharedPage.njk index 2e9a45e..0e2c941 100644 --- a/public/templates/pages/sharedPage.njk +++ b/public/templates/pages/sharedPage.njk @@ -1,7 +1,10 @@ -{% extends "layout.njk" %} -{% import "macros.njk" as macros %} +/// This code was AUTOGENERATED using the codama library. +/// Please DO NOT EDIT THIS FILE, instead use visitors +/// to add features, then rerun codama to update it. +/// +/// https://github.com/codama-idl/codama +/// -{% block main %} // Shared utilities and types for the SDK. import 'dart:convert'; @@ -23,12 +26,31 @@ class AccountNotFoundError extends Error { /// Binary reader for decoding Borsh-encoded data. class BinaryReader { - final ByteData _data; + final ByteData + _data; // holds the raw binary data buffer, that i read from. Represents entire sequence of bytes. + + // Offset tracks the current byte position in the buffer; advance it after each read to ensure correct sequential decoding. int _offset = 0; /// Creates a new BinaryReader. BinaryReader(this._data); + Uint8List readDiscriminator() { + final length = 8; // Discriminator is always the first 8 bytes + final bytes = + Uint8List.view(_data.buffer, _data.offsetInBytes + _offset, length); + _offset += length; + return bytes; + } + + /// Reads a single public key (32 raw bytes, no prefix). + Uint8List readPubkey() { + final length = 32; + final bytes = Uint8List.view(_data.buffer, _data.offsetInBytes + _offset, length); + _offset += length; + return bytes; + } + /// Reads a boolean value. bool readBool() { final value = _data.getUint8(_offset) != 0; @@ -116,73 +138,146 @@ class BinaryReader { /// Reads a string. String readString() { final length = readU32(); - final bytes = Uint8List.view(_data.buffer, _data.offsetInBytes + _offset, length); + final bytes = + Uint8List.view(_data.buffer, _data.offsetInBytes + _offset, length); _offset += length; return utf8.decode(bytes); } - /// Reads a fixed-size u8 array of bytes. - Uint8List readFixedU8Array(int length) { - final bytes = - Uint8List.view(_data.buffer, _data.offsetInBytes + _offset, length); - _offset += length; - return bytes; + /// Reads a u8 array from Borsh data. If `length` is null, reads the length from a 4-byte prefix. + Uint8List readU8Array([int? length]) { + if (length == null) { + // Read the 4-byte little-endian length prefix (Borsh Vec) + length = _data.getUint32(_offset, Endian.little); + _offset += 4; + } + + return readAlignedArray( + 1, + length, + Uint8List.view, + 1, + (offset) => _data.getUint8(offset), + ); } /// Reads a fixed-size i8 array of bytes. - Int8List readFixedI8Array(int length) { - final bytes = - Int8List.view(_data.buffer, _data.offsetInBytes + _offset, length); - _offset += length; - return bytes; + Int8List readI8Array([int? length]) { + if (length == null) { + // Read the 4-byte little-endian length prefix (Borsh Vec) + length = _data.getUint32(_offset, Endian.little); + _offset += 4; + } + + return readAlignedArray( + 1, + length, + Int8List.view, + 1, + (offset) => _data.getInt8(offset), + ); } /// Reads a fixed-size u16 array of bytes. - Uint16List readFixedU16Array(int length) { - final bytes = - Uint16List.view(_data.buffer, _data.offsetInBytes + _offset, length); - _offset += length * 4; - return bytes; + Uint16List readU16Array([int? length]) { + if (length == null) { + // Read the 4-byte little-endian length prefix (Borsh Vec) + length = _data.getUint32(_offset, Endian.little); + _offset += 4; + } + + return readAlignedArray( + 2, + length, + Uint16List.view, + 2, + (offset) => _data.getUint16(offset, Endian.little), + ); } /// Reads a fixed-size i16 array of bytes. - Int16List readFixedI16Array(int length) { - final bytes = - Int16List.view(_data.buffer, _data.offsetInBytes + _offset, length); - _offset += length * 4; - return bytes; + Int16List readI16Array([int? length]) { + if (length == null) { + // Read the 4-byte little-endian length prefix (Borsh Vec) + length = _data.getUint32(_offset, Endian.little); + _offset += 4; + } + + return readAlignedArray( + 2, + length, + Int16List.view, + 2, + (offset) => _data.getInt16(offset, Endian.little), + ); } /// Reads a fixed-size u32 array of bytes. - Uint32List readFixedU32Array(int length) { - final bytes = - Uint32List.view(_data.buffer, _data.offsetInBytes + _offset, length); - _offset += length * 4; - return bytes; + Uint32List readU32Array([int? length]) { + if (length == null) { + // Read the 4-byte little-endian length prefix (Borsh Vec) + length = _data.getUint32(_offset, Endian.little); + _offset += 4; + } + + return readAlignedArray( + 4, + length, + Uint32List.view, + 4, + (offset) => _data.getUint32(offset, Endian.little), + ); } /// Reads a fixed-size i32 array of bytes. - Int32List readFixedI32Array(int length) { - final bytes = - Int32List.view(_data.buffer, _data.offsetInBytes + _offset, length); - _offset += length * 4; - return bytes; + Int32List readI32Array([int? length]) { + if (length == null) { + // Read the 4-byte little-endian length prefix (Borsh Vec) + length = _data.getUint32(_offset, Endian.little); + _offset += 4; + } + + return readAlignedArray( + 4, + length, + Int32List.view, + 4, + (offset) => _data.getInt32(offset, Endian.little), + ); } /// Reads a fixed-size u64 array of bytes. - Uint64List readFixedU64Array(int length) { - final bytes = - Uint64List.view(_data.buffer, _data.offsetInBytes + _offset, length); - _offset += length * 4; - return bytes; + Uint64List readU64Array([int? length]) { + if (length == null) { + // Read the 4-byte little-endian length prefix (Borsh Vec) + length = _data.getUint32(_offset, Endian.little); + _offset += 4; + } + + return readAlignedArray( + 8, + length, + Uint64List.view, + 8, + (offset) => _data.getUint64(offset, Endian.little), + ); } /// Reads a fixed-size i64 array of bytes. - Int64List readFixedI64Array(int length) { - final bytes = - Int64List.view(_data.buffer, _data.offsetInBytes + _offset, length); - _offset += length * 4; - return bytes; + Int64List readI64Array([int? length]) { + if (length == null) { + // Read the 4-byte little-endian length prefix (Borsh Vec) + length = _data.getUint32(_offset, Endian.little); + _offset += 4; + } + + return readAlignedArray( + 8, + length, + Int64List.view, + 8, + (offset) => _data.getInt64(offset, Endian.little), + ); } /// Reads a variable-length array of generic items. @@ -198,7 +293,46 @@ class BinaryReader { /// Reads a variable-length array of bytes. Uint8List readBytes() { final length = readU32(); - return readFixedU8Array(length); + return readU8Array(length); + } + + // ========= Utils for alignment-safe array reading ======== + + // This function handles the problem of buffer's offset that is not properly aligned for typed array views. + // It happens because i have fixed-size and prefixed-size arrays. + T readAlignedArray( + int alignment, + int length, + T Function(ByteBuffer buffer, int offset, int length) viewConstructor, + int bytesPerElement, + int Function(int offset) manualGetter, + ) { + // Check the offset alignment for `Uint*List.view` it should be multiple of element size + if ((_data.offsetInBytes + _offset) % alignment == 0) { + final arr = + viewConstructor(_data.buffer, _data.offsetInBytes + _offset, length); + _offset += length * bytesPerElement; + return arr; + } else { + // Manual read if not aligned + // For example, for Uint16List: + final arr = List.generate(length, (i) { + final value = manualGetter(_offset); + _offset += bytesPerElement; + return value; + }); + // Convert to typed list + if (T == Uint8List) return Uint8List.fromList(arr) as T; + if (T == Uint16List) return Uint16List.fromList(arr) as T; + if (T == Uint32List) return Uint32List.fromList(arr) as T; + if (T == Uint64List) return Uint64List.fromList(arr) as T; + if (T == Int8List) return Int8List.fromList(arr) as T; + if (T == Int16List) return Int16List.fromList(arr) as T; + if (T == Int32List) return Int32List.fromList(arr) as T; + if (T == Int64List) return Int64List.fromList(arr) as T; + // ...add more types as needed + return arr as T; + } } } @@ -206,6 +340,13 @@ class BinaryReader { class BinaryWriter { final List _bytes = []; + void writeDiscriminator(Uint8List discriminator) { + if (discriminator.length != 8) { + throw ArgumentError('Discriminator must be exactly 8 bytes'); + } + _bytes.addAll(discriminator); + } + /// Writes a boolean value. void writeBool(bool value) { _bytes.add(value ? 1 : 0); @@ -253,7 +394,7 @@ class BinaryWriter { void writeU64(BigInt value) { final low = value & BigInt.from(0xFFFFFFFF); final high = (value >> 32) & BigInt.from(0xFFFFFFFF); - + _bytes.addAll([ low.toInt() & 0xFF, (low.toInt() >> 8) & 0xFF, @@ -293,44 +434,132 @@ class BinaryWriter { _bytes.addAll(bytes); } - /// Writes a fixed-size u8 array of bytes. - void writeFixedU8Array(Uint8List value) { - _bytes.addAll(value); + /// Writes a fixed-size and prefixed-size u8 array of bytes. + void writeU8Array(Uint8List value, int? length) { + if (length == null) { + // Variable-length: write length prefix + writeU32(value.length); + for (final v in value) { + writeU8(v); + } + } else { + // Fixed-size: write exactly [length] elements, no prefix + for (int i = 0; i < length; i++) { + writeU8(value[i]); + } + } } - /// Writes a fixed-size i8 array of bytes. - void writeFixedI8Array(Int8List value) { - _bytes.addAll(value); + /// Writes a fixed-size and prefixed-size u8 array of bytes. + void writeI8Array(Int8List value, int? length) { + if (length == null) { + // Variable-length: write length prefix + writeU32(value.length); + for (final v in value) { + writeI8(v); + } + } else { + // Fixed-size: write exactly [length] elements, no prefix + for (int i = 0; i < length; i++) { + writeI8(value[i]); + } + } } - /// Writes a fixed-size u16 array of bytes. - void writeFixedU16Array(Uint16List value) { - _bytes.addAll(value); + /// Writes a fixed-size and prefixed-size u16 array of bytes. + void writeU16Array(Uint16List value, int? length) { + if (length == null) { + // Variable-length: write length prefix + writeU32(value.length); + for (final v in value) { + writeU16(v); + } + } else { + // Fixed-size: write exactly [length] elements, no prefix + for (int i = 0; i < length; i++) { + writeU16(value[i]); + } + } } - /// Writes a fixed-size i16 array of bytes. - void writeFixedI16Array(Int16List value) { - _bytes.addAll(value); + /// Writes a fixed-size and prefixed-size i16 array of bytes. + void writeI16Array(Int16List value, int? length) { + if (length == null) { + // Variable-length: write length prefix + writeU32(value.length); + for (final v in value) { + writeI16(v); + } + } else { + // Fixed-size: write exactly [length] elements, no prefix + for (int i = 0; i < length; i++) { + writeI16(value[i]); + } + } } - - /// Writes a fixed-size u32 array of bytes. - void writeFixedU32Array(Uint32List value) { - _bytes.addAll(value); + + /// Writes a fixed-size and prefixed-size i16 array of bytes. + void writeU32Array(Uint32List value, int? length) { + if (length == null) { + // Variable-length: write length prefix + writeU32(value.length); + for (final v in value) { + writeU32(v); + } + } else { + // Fixed-size: write exactly [length] elements, no prefix + for (int i = 0; i < length; i++) { + writeU32(value[i]); + } + } } /// Writes a fixed-size i32 array of bytes. - void writeFixedI32Array(Int32List value) { - _bytes.addAll(value); + void writeI32Array(Int32List value, int? length) { + if (length == null) { + // Variable-length: write length prefix + writeU32(value.length); + for (final v in value) { + writeI32(v); + } + } else { + // Fixed-size: write exactly [length] elements, no prefix + for (int i = 0; i < length; i++) { + writeI32(value[i]); + } + } } /// Writes a fixed-size u64 array of bytes. - void writeFixedU64Array(Uint64List value) { - _bytes.addAll(value); + void writeU64Array(Uint64List value, int? length) { + if (length == null) { + // Variable-length: write length prefix + writeU32(value.length); + for (final v in value) { + writeU64(BigInt.from(v)); + } + } else { + // Fixed-size: write exactly [length] elements, no prefix + for (int i = 0; i < length; i++) { + writeU64(BigInt.from(value[i])); + } + } } /// Writes a fixed-size i64 array of bytes. - void writeFixedI64Array(Int64List value) { - _bytes.addAll(value); + void writeI64Array(Int64List value, int? length) { + if (length == null) { + // Variable-length: write length prefix + writeU32(value.length); + for (final v in value) { + writeI64(BigInt.from(v)); + } + } else { + // Fixed-size: write exactly [length] elements, no prefix + for (int i = 0; i < length; i++) { + writeI64(BigInt.from(value[i])); + } + } } /// Writes a variable-length array of bytes. @@ -347,7 +576,11 @@ class BinaryWriter { } } + /// Writes a single public key (32 raw bytes, no prefix). + void writePubkey(Uint8List pubkeyBytes) { + _bytes.addAll(pubkeyBytes); + } + /// Returns the byte array. Uint8List toBytes() => Uint8List.fromList(_bytes); } -{% endblock %} \ No newline at end of file From 37a25b555372a4bcd9441ac9e8aa04fae67c5017 Mon Sep 17 00:00:00 2001 From: ERoydev Date: Wed, 10 Sep 2025 15:40:23 +0300 Subject: [PATCH 04/33] add(): Applied discriminator functions instead of array used ones --- public/templates/pages/accountsPage.njk | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/public/templates/pages/accountsPage.njk b/public/templates/pages/accountsPage.njk index e3fa5ef..c71063a 100644 --- a/public/templates/pages/accountsPage.njk +++ b/public/templates/pages/accountsPage.njk @@ -67,7 +67,7 @@ void toBorsh(BinaryWriter writer) { {% if account.discriminator %} // Validate the discriminator - final discriminator = reader.readFixedU8Array(8); + final discriminator = reader.readDiscriminator(); if (!const ListEquality().equals(discriminator, {{ account.name | snakeCase | upper }}_DISCRIMINATOR)) { throw FormatException('Invalid account discriminator'); } @@ -82,7 +82,7 @@ void toBorsh(BinaryWriter writer) { {% if account.discriminator %} // Write discriminator - writer.writeFixedU8Array(Uint8List.fromList({{ account.name | snakeCase | upper }}_DISCRIMINATOR)); + writer.writeDiscriminator(Uint8List.fromList({{ account.name | snakeCase | upper }}_DISCRIMINATOR)); {% endif %} // Write account data @@ -129,7 +129,11 @@ void toBorsh(BinaryWriter writer) { RpcClient client, Ed25519HDPublicKey address, ) async { - final accountInfo = await client.getAccountInfo(address.toBase58()); + {# Always use encoding: Encoding.base64 when fetching account data. #} + {# Base58 is meant for public keys, not raw binary, and will produce the wrong bytes. #} + {# Base64 ensures we get the exact raw on-chain bytes (including the correct discriminator). #} + + final accountInfo = await client.getAccountInfo(address.toBase58(), encoding: Encoding.base64); final data = accountInfo.value?.data; if (data == null) { From 94d20abe3536fb48bb41eedd62eaf1cca1dad421 Mon Sep 17 00:00:00 2001 From: ERoydev Date: Wed, 10 Sep 2025 15:47:34 +0300 Subject: [PATCH 05/33] fix(macros): Nesting depth for recursive borsh and sizes passed to borsh methods --- public/templates/macros.njk | 67 ++++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 30 deletions(-) diff --git a/public/templates/macros.njk b/public/templates/macros.njk index d3acac8..a7126d5 100644 --- a/public/templates/macros.njk +++ b/public/templates/macros.njk @@ -38,15 +38,18 @@ {# Recursive Borsh Reader, responsible for handling collections and any nested levels #} {% macro borshReader(field) %} - {{ recursiveReader(field.nesting, field.baseType, field.isStruct) }} + {{ recursiveReader(field.nesting, field.baseType, field.isStruct, field.size) }} {% endmacro %} -{% macro recursiveReader(depth, baseType, isStruct) %} - {% if depth == 0 %} +{% macro recursiveReader(depth, baseType, isStruct, size) %} + {% if depth > 5 %} + // ERROR: Nesting depth exceeds supported limit (5) + throw Exception('Nesting depth exceeds supported limit(5)'); + {% elif depth == 0 %} {% if isStruct %} {{ baseType }}Borsh.fromBorsh(reader) {% else %} - {{ baseTypeReader(baseType) }} + {{ baseTypeReader(baseType, false, size) }} {% endif %} {% else %} reader.readArray(() { @@ -54,14 +57,14 @@ // item is a struct, call fromBorsh per item return {{ baseType }}Borsh.fromBorsh(reader); {% else %} - return {{ recursiveReader(depth - 1, baseType, false) }}; + return {{ recursiveReader(depth - 1, baseType, false, size) }}; {% endif %} }) {% endif %} {% endmacro %} {# Reader for the base types (no nesting) #} -{% macro baseTypeReader(baseType, isStruct) %} +{% macro baseTypeReader(baseType, isStruct, size) %} {% if baseType == 'int' %} reader.readInt() {% elif baseType == 'BigInt' %} @@ -69,26 +72,27 @@ {% elif baseType == 'String' %} reader.readString() {% elif baseType == 'Uint8List' %} - reader.readFixedU8Array({{ field.size or 8}}) + reader.readU8Array({{ size if size is defined else '' }}) {% elif baseType == 'Int8List' %} - reader.readFixedI8Array({{ field.size or 8}}) + reader.readI8Array({{ size if size is defined else '' }}) {% elif baseType == 'Uint16List' %} - reader.readFixedU16Array({{ field.size or 16 }}) + reader.readU16Array({{ size if size is defined else '' }}) {% elif baseType == 'Int16List' %} - reader.readFixedI16Array({{ field.size or 16}}) + reader.readI16Array({{ size if size is defined else '' }}) {% elif baseType == 'Uint32List' %} - reader.readFixedU32Array({{ field.size or 32}}) + reader.readU32Array({{ size if size is defined else '' }}) {% elif baseType == 'Int32List' %} - reader.readFixedI32Array({{ field.size or 32}}) + reader.readI32Array({{ size if size is defined else '' }}) {% elif baseType == 'Uint64List' %} - reader.readFixedU64Array({{ field.size or 64}}) + reader.readU64Array({{ size if size is defined else '' }}) {% elif baseType == 'Int64List' %} - reader.readFixedI64Array({{ field.size or 64 }}) + reader.readI64Array({{ size if size is defined else '' }}) {% elif baseType == 'bool' %} reader.readBool() {% elif baseType == 'Ed25519HDPublicKey' %} - Ed25519HDPublicKey(Uint8List.fromList(reader.readFixedU8Array(32))) + Ed25519HDPublicKey(reader.readPubkey()) {% else %} + /// TODO: I need to provide panic or error guard to indicate that user is doing something that is not supported reader.readUnknownType('{{ baseType }}') {% endif %} {% endmacro %} @@ -96,16 +100,19 @@ {# Recursive Borsh Writer, responsible to handle nested type of collections #} {% macro borshWriter(field, overrideFieldName="") %} {% set name = overrideFieldName if overrideFieldName else field.name %} - {{ recursiveWriter(name, field.nesting, field.baseType, field.isStruct) }} + {{ recursiveWriter(name, field.nesting, field.baseType, field.isStruct, field.size) }} {% endmacro %} -{% macro recursiveWriter(varName, depth, baseType, isStruct) %} - {% if depth == 0 %} +{% macro recursiveWriter(varName, depth, baseType, isStruct, size) %} + {% if depth > 5 %} + // ERROR: Nesting depth exceeds supported limit (5) + throw Exception('Nesting depth exceeds supported limit(5)'); + {% elif depth == 0 %} {% if isStruct %} {{ varName }}.toBorsh(writer); {% else %} {# TODO: I have problem here because of these recursions i put ';' twice because twice is iterated here first trough writeArray and on the recursion i go inside here and i put ';' again #} - {{ baseTypeWriter(baseType, varName) }}; + {{ baseTypeWriter(baseType, varName, size) }}; {% endif %} {% else %} writer.writeArray<{{ baseType }}>({{ varName }}, ({{ baseType }} item) { @@ -113,14 +120,14 @@ // Each item is a struct item.toBorsh(writer); {% else %} - {{ recursiveWriter("item", depth - 1, baseType, false) }}; + {{ recursiveWriter("item", depth - 1, baseType, false, size) }}; {% endif %} }); {% endif %} {% endmacro %} {# Base Writer, no nested types inside #} -{% macro baseTypeWriter(baseType, varName, isStruct) %} +{% macro baseTypeWriter(baseType, varName, size) %} {% if baseType == 'int' %} writer.writeInt({{ varName }}) {% elif baseType == 'BigInt' %} @@ -128,25 +135,25 @@ {% elif baseType == 'String' %} writer.writeString({{ varName }}) {% elif baseType == 'Uint8List' %} - writer.writeFixedU8Array({{ varName }}) + writer.writeU8Array({{ varName }}, {{ size if size is defined else 'null' }}) {% elif baseType == 'Int8List' %} - writer.writeFixedI8Array({{ varName }}) + writer.writeI8Array({{ varName }}, {{ size if size is defined else 'null' }}) {% elif baseType == 'Uint16List' %} - writer.writeFixedU16Array({{ varName }}) + writer.writeU16Array({{ varName }}, {{ size if size is defined else 'null' }}) {% elif baseType == 'Int16List' %} - writer.writeFixedI16Array({{ varName }}) + writer.writeI16Array({{ varName }}, {{ size if size is defined else 'null' }}) {% elif baseType == 'Uint32List' %} - writer.writeFixedU32Array({{ varName }}) + writer.writeU32Array({{ varName }}, {{ size if size is defined else 'null' }}) {% elif baseType == 'Int32List' %} - writer.writeFixedI32Array({{ varName }}) + writer.writeI32Array({{ varName }}, {{ size if size is defined else 'null' }}) {% elif baseType == 'Uint64List' %} - writer.writeFixedU64Array({{ varName }}) + writer.writeU64Array({{ varName }}, {{ size if size is defined else 'null' }}) {% elif baseType == 'Int64List' %} - writer.writeFixedI64Array({{ varName }}) + writer.writeI64Array({{ varName }}, {{ size if size is defined else 'null' }}) {% elif baseType == 'bool' %} writer.writeBool({{ varName }}) {% elif baseType == 'Ed25519HDPublicKey' %} - writer.writeFixedU8Array(Uint8List.fromList({{ varName }}.bytes)) + writer.writePubkey(Uint8List.fromList({{ varName }}.bytes)) {% else %} writer.writeUnknownType('{{ baseType }}') {% endif %} From 64bad8f8d970315ca3acba2ed9662673f9693c29 Mon Sep 17 00:00:00 2001 From: ERoydev Date: Wed, 10 Sep 2025 15:48:59 +0300 Subject: [PATCH 06/33] fix(templates): Use snakeCase and reuse broshMethods for serializing --- public/templates/pages/instructionsPage.njk | 184 ++++++++++---------- 1 file changed, 88 insertions(+), 96 deletions(-) diff --git a/public/templates/pages/instructionsPage.njk b/public/templates/pages/instructionsPage.njk index da2f6dd..8631854 100644 --- a/public/templates/pages/instructionsPage.njk +++ b/public/templates/pages/instructionsPage.njk @@ -5,120 +5,112 @@ {{ imports }} {% if instruction.discriminator and instruction.discriminator.length > 0 -%} -const List - {{ instruction.name | snakeCase | upper }}_DISCRIMINATOR = [{{ instruction.discriminator | join(', ') }}]; -{%- endif %} + const List {{ instruction.name | snakeCase | upper }}_DISCRIMINATOR = [{{ instruction.discriminator | join(', ') }}]; + {%- endif %} -/// Generated instruction class for {{ instruction.name | pascalCase }}. -/// -{% if instruction.docs.length > 0 -%} - {%- for doc in instruction.docs -%} -/// {{ doc }} - {%- endfor -%} - {%- endif %} -class {{ instruction.name | pascalCase }}Instruction { + /// Generated instruction class for {{ instruction.name | pascalCase }}. + /// + {% if instruction.docs.length > 0 -%} + {%- for doc in instruction.docs -%} + /// {{ doc }} + {%- endfor -%} + {%- endif %} - // Accounts - {% for account in instruction.accounts %} - // {{ account.docs[0] if account.docs and account.docs[0] else ('The ' ~ (account.name | camelCase) ~ ' account.') }} + class {{ instruction.name | pascalCase }}Instruction { + + // Accounts + {% for account in instruction.accounts %} + // {{ account.docs[0] if account.docs and account.docs[0] else ('The ' ~ (account.name | snakeCase ) ~ ' account.') }} {% if account.isOptional %} - final Ed25519HDPublicKey? {{ account.name | camelCase }}; - {% else %} - final Ed25519HDPublicKey {{ account.name | camelCase }}; - {% endif %} + final Ed25519HDPublicKey? {{ account.name | snakeCase }}; + {% else %} + final Ed25519HDPublicKey {{ account.name | snakeCase }}; + {% endif %} {% if account.isSigner === 'either' %} - /// Whether the {{ account.name | camelCase }} account is a signer. - final bool {{ account.name | camelCase }}IsSigner; - {% endif %} + /// Whether the {{ account.name | snakeCase }} account is a signer. + final bool {{ account.name | snakeCase }}IsSigner; + {% endif %} {% endfor %} - // Args - {% if args and args.length > 0 %} + // Args + {% if args and args.length > 0 %} {% for arg in args %} - final {{ arg.dartType }} - {{ arg.name }}; - {% endfor %} + final {{ arg.dartType }} {{ arg.name | snakeCase }}; + {% endfor %} {% endif %} {{ instruction.name | pascalCase }}Instruction({ - {% for account in instruction.accounts -%} - {%- if account.isOptional -%} - this.{{ account.name | camelCase }}, - {%- else -%} - required this.{{ account.name | camelCase }}, - {%- endif -%} - {%- if account.isSigner === 'either' -%} - this.{{ account.name | camelCase }}IsSigner = false, - {%- endif -%} - {%- endfor -%} - {%- if args and args.length > 0 -%} - {%- for arg in args -%} - required this.{{ arg.name }}, + {% for account in instruction.accounts -%} + {%- if account.isOptional -%} + this.{{ account.name | snakeCase }}, + {%- else -%} + required this.{{ account.name | snakeCase }}, + {%- endif -%} + {%- if account.isSigner === 'either' -%} + this.{{ account.name | snakeCase }}IsSigner = false, + {%- endif -%} {%- endfor -%} - {%- endif -%} - }); + {%- if args and args.length > 0 -%} + {%- for arg in args -%} + required this.{{ arg.name | snakeCase }}, + {%- endfor -%} + {%- endif -%} + }); - /// Builds the `Instruction` (data = discriminator + args). - Instruction toInstruction({ List remainingAccounts = const [] }) { - final keys = [ - {%- for account in instruction.accounts %} + /// Builds the `Instruction` (data = discriminator + args). + Instruction toInstruction({ List remainingAccounts = const [] }) { + final keys = [ + {%- for account in instruction.accounts %} {%- if account.isOptional %} - if ({{ account.name | camelCase }} != null) - AccountMeta( - pubKey: {{ account.name | camelCase }}!, - isSigner: {%- if account.isSigner === 'either' -%}{{ account.name | camelCase }}IsSigner{%- else -%}{{ 'true' if account.isSigner else 'false' }} - {%- endif -%}, - isWriteable: {{ 'true' if account.isWritable else 'false' }}, - ), - {%- else %} - AccountMeta( - pubKey: {{ account.name | camelCase }}, - isSigner: {%- if account.isSigner === 'either' -%}{{ account.name | camelCase }}IsSigner{%- else -%}{{ 'true' if account.isSigner else 'false' }} - {%- endif -%}, - isWriteable: {{ 'true' if account.isWritable else 'false' }}, - ), - {%- endif %} + if ({{ account.name | snakeCase }} != null) + AccountMeta( + pubKey: {{ account.name | snakeCase }}!, + isSigner: {%- if account.isSigner === 'either' -%}{{ account.name | snakeCase }}IsSigner{%- else -%}{{ 'true' if account.isSigner else 'false' }}{%- endif -%}, + isWriteable: {{ 'true' if account.isWritable else 'false' }}, + ), + {%- else %} + AccountMeta( + pubKey: {{ account.name | snakeCase }}, + isSigner: {%- if account.isSigner === 'either' -%}{{ account.name | snakeCase }}IsSigner{%- else -%}{{ 'true' if account.isSigner else 'false' }}{%- endif -%}, + isWriteable: {{ 'true' if account.isWritable else 'false' }}, + ), + {%- endif %} {%- endfor %} - ]; + ]; - if (remainingAccounts.isNotEmpty) { - keys.addAll(remainingAccounts); - } + if (remainingAccounts.isNotEmpty) { + keys.addAll(remainingAccounts); + } - // Serialize: discriminator (8 bytes) + args - final writer = BinaryWriter(); -{%- if instruction.discriminator and instruction.discriminator.length > 0 %} -writer.writeFixedU8Array(Uint8List.fromList({{ instruction.name | snakeCase | upper }}_DISCRIMINATOR)); -{%- endif %} - {%- if args and args.length > 0 %} - {%- for arg in args %} - {%- if arg.resolvedType.kind === 'numberTypeNode' %} - writer.writeU{{ arg.resolvedType.format | replace('u', '') }}({{ arg.name }}); - {%- elif arg.resolvedType.kind === 'stringTypeNode' %} - writer.writeString({{ arg.name }}); - {%- elif arg.resolvedType.kind === 'booleanTypeNode' %} - writer.writeBool({{ arg.name }}); - {%- elif arg.resolvedType.kind === 'publicKeyTypeNode' %} - writer.writeFixedU8Array(Uint8List.fromList({{ arg.name }}.bytes)); - {%- elif arg.resolvedType.kind === 'bytesTypeNode' %} - writer.writeBytes({{ arg.name }}); - {%- else %} - {{ arg.name }}.toBorsh(writer); + // Serialize: discriminator (8 bytes) + args + final writer = BinaryWriter(); + {%- if instruction.discriminator and instruction.discriminator.length > 0 %} + writer.writeDiscriminator(Uint8List.fromList({{ instruction.name | snakeCase | upper }}_DISCRIMINATOR)); + {%- endif %} + {%- if fields and fields.length > 0 %} + {% for field in fields %} + {% if field.optional %} + writer.writeU8({{ field.name }} != null ? 1 : 0); + if ({{ field.name }} != null) { + {{ macros.borshWriter(field) | replace(field.name, field.name ~ '!') }} + } + {% else %} + {{ macros.borshWriter(field) }} + {% endif %} + {% endfor %} {%- endif %} - {%- endfor %} - {%- endif %} - return Instruction( - programId: {{ program.name | pascalCase }}Program.programId, - accounts: keys, - data: ByteArray(writer.toBytes()), - ); + return Instruction( + programId: {{ program.name | pascalCase }}Program.programId, + accounts: keys, + data: ByteArray(writer.toBytes()), + ); + } } -} -{# Nested structs (if any) #} - {% for nestedStruct in typeManifest.nestedStructs %} - {{ nestedStruct }} - {% endfor %} - {% endblock %} \ No newline at end of file + {# Nested structs (if any) #} + {% for nestedStruct in typeManifest.nestedStructs %} + {{ nestedStruct }} + {% endfor %} +{% endblock %} \ No newline at end of file From 8ea4aebe43d5409ba1e6e070a3e6ef01da221e49 Mon Sep 17 00:00:00 2001 From: ERoydev Date: Wed, 10 Sep 2025 16:05:04 +0300 Subject: [PATCH 07/33] add(typeManifest): Regex handler added for number formats --- src/TypeManifest.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/TypeManifest.ts b/src/TypeManifest.ts index 197eba7..5854dfd 100644 --- a/src/TypeManifest.ts +++ b/src/TypeManifest.ts @@ -23,10 +23,11 @@ export type TypeManifestOptions = { export interface TypeManifestField { baseType: string; field: string; + format?: string; // Since dart have `int` or `BigInt` i need to know the original format to handle the borsh read/write name: string; nesting: number; optional: boolean; - size?: number; + size?: number; // In case of fixed-sized i need to know the size to handle the borsh read/write type: string; } @@ -38,9 +39,11 @@ export function extractFieldsFromTypeManifest(typeManifest: TypeManifest): TypeM .split('\n') .map((line): TypeManifestField | null => { // That handles lines like: final Uint8List fieldName; and extracts the type and name in order to be used from borsh readers/writers - const match = line.trim().match(/^final\s+([\w<>, ?]+)(?:\s*\/\*\s*length:\s*\d+\s*\*\/)?\s+(\w+);$/); + const match = line.trim().match(/^final\s+([\w<>, ?]+)(?:\s*\/\*.*?\*\/)*\s+(\w+);$/); if (match && match[2] !== 'discriminator') { let size: number | undefined; // Placeholder for size extraction logic if needed + let format: string | undefined; // Placeholder for format extraction logic if needed + const isOptional = /\?$/.test(match[1].trim()); // check if the string ends with a '?' const rawType = match[1].replace(/\?$/, '').trim(); @@ -49,6 +52,11 @@ export function extractFieldsFromTypeManifest(typeManifest: TypeManifest): TypeM size = parseInt(lengthMatch[1]); } + const typeMatch = line.match(/\/\*\s*type:\s*([\w<>, ?]+)\s*\*\//); // Extract type if present + if (typeMatch) { + format = typeMatch[1].trim(); + } + // Count nesting depth of List<> let nesting = 0; let inner = rawType; @@ -62,6 +70,7 @@ export function extractFieldsFromTypeManifest(typeManifest: TypeManifest): TypeM return { baseType: inner.trim(), field: line, + format: format, name: match[2], nesting, optional: isOptional, From 59fe25ea589831c21ed83a171b57e6ac8fd563e5 Mon Sep 17 00:00:00 2001 From: ERoydev Date: Wed, 10 Sep 2025 16:07:07 +0300 Subject: [PATCH 08/33] add(): NumberTypeNodes return int type with exact rust integer type as a comment --- src/getTypeManifestVisitor.ts | 50 +++++++++++++++++++++++++++++++---- 1 file changed, 45 insertions(+), 5 deletions(-) diff --git a/src/getTypeManifestVisitor.ts b/src/getTypeManifestVisitor.ts index 713a4f5..b32c740 100644 --- a/src/getTypeManifestVisitor.ts +++ b/src/getTypeManifestVisitor.ts @@ -239,30 +239,70 @@ export function getTypeManifestVisitor(options: TypeManifestOptions) { visitNumberType(numberType: NumberTypeNode): TypeManifest { switch (numberType.format) { case 'u8': - case 'u16': - case 'u32': + return { + imports: new ImportMap(), + nestedStructs: [], + type: 'int /* type: u8 */', + }; case 'i8': + return { + imports: new ImportMap(), + nestedStructs: [], + type: 'int /* type: i8 */', + }; + case 'u16': + return { + imports: new ImportMap(), + nestedStructs: [], + type: 'int /* type: u16 */', + }; case 'i16': + return { + imports: new ImportMap(), + nestedStructs: [], + type: 'int /* type: i16 */', + }; + case 'u32': + return { + imports: new ImportMap(), + nestedStructs: [], + type: 'int /* type: u32 */', + }; case 'i32': return { imports: new ImportMap(), nestedStructs: [], - type: 'int', + type: 'int /* type: i32 */', }; case 'u64': + return { + imports: new ImportMap(), + nestedStructs: [], + type: 'BigInt /* type: u64 */', + }; case 'i64': + return { + imports: new ImportMap(), + nestedStructs: [], + type: 'BigInt /* type: i64 */', + }; case 'u128': + return { + imports: new ImportMap(), + nestedStructs: [], + type: 'BigInt /* type: u128 */', + }; case 'i128': return { imports: new ImportMap(), nestedStructs: [], - type: 'BigInt', + type: 'BigInt /* type: i128 */', }; case 'shortU16': return { imports: new ImportMap(), nestedStructs: [], - type: 'int', + type: 'int /* type: shortU16 */', }; default: throw new Error(`Unknown number format: ${numberType.format}`); From e26c726ec0cb5a4b5e33025e6ef981151d88d05d Mon Sep 17 00:00:00 2001 From: ERoydev Date: Wed, 10 Sep 2025 16:07:39 +0300 Subject: [PATCH 09/33] add(macros): Added formats handling in macros --- public/templates/macros.njk | 92 +++++++++++++++++++++++++++++-------- 1 file changed, 74 insertions(+), 18 deletions(-) diff --git a/public/templates/macros.njk b/public/templates/macros.njk index a7126d5..a6cbe77 100644 --- a/public/templates/macros.njk +++ b/public/templates/macros.njk @@ -38,10 +38,10 @@ {# Recursive Borsh Reader, responsible for handling collections and any nested levels #} {% macro borshReader(field) %} - {{ recursiveReader(field.nesting, field.baseType, field.isStruct, field.size) }} + {{ recursiveReader(field.nesting, field.baseType, field.isStruct, field.size, field.format) }} {% endmacro %} -{% macro recursiveReader(depth, baseType, isStruct, size) %} +{% macro recursiveReader(depth, baseType, isStruct, size, format) %} {% if depth > 5 %} // ERROR: Nesting depth exceeds supported limit (5) throw Exception('Nesting depth exceeds supported limit(5)'); @@ -49,7 +49,7 @@ {% if isStruct %} {{ baseType }}Borsh.fromBorsh(reader) {% else %} - {{ baseTypeReader(baseType, false, size) }} + {{ baseTypeReader(baseType, false, size, format) }} {% endif %} {% else %} reader.readArray(() { @@ -57,18 +57,76 @@ // item is a struct, call fromBorsh per item return {{ baseType }}Borsh.fromBorsh(reader); {% else %} - return {{ recursiveReader(depth - 1, baseType, false, size) }}; + return {{ recursiveReader(depth - 1, baseType, false, size, format) }}; {% endif %} }) {% endif %} {% endmacro %} +{% macro intFormatUtil(format, isWrite, varName='value') %} + {% if format == 'u8' %} + {% if isWrite %} + writer.writeU8({{ varName }}) + {% else %} + reader.readU8() + {% endif %} + {% elif format == 'i8' %} + {% if isWrite %} + writer.writeI8({{ varName }}) + {% else %} + reader.readI8() + {% endif %} + {% elif format == 'u16' %} + {% if isWrite %} + writer.writeU16({{ varName }}) + {% else %} + reader.readU16() + {% endif %} + {% elif format == 'i16' %} + {% if isWrite %} + writer.writeI16({{ varName }}) + {% else %} + reader.readI16() + {% endif %} + {% elif format == 'u32' %} + {% if isWrite %} + writer.writeU32({{ varName }}) + {% else %} + reader.readU32() + {% endif %} + {% elif format == 'i32' %} + {% if isWrite %} + writer.writeI32({{ varName }}) + {% else %} + reader.readI32() + {% endif %} + {% elif format == 'u64' %} + {% if isWrite %} + writer.writeU64({{ varName }}) + {% else %} + reader.readU64() + {% endif %} + {% elif format == 'i64' %} + {% if isWrite %} + writer.writeI64({{ varName }}) + {% else %} + reader.readI64() + {% endif %} + {% elif format == 'u128' or format == 'i128' %} + {% if isWrite %} + writer.writeBigInt({{ varName }}) + {% else %} + reader.readBigInt() + {% endif %} + {% else %} + throw Exception('Unsupported number format: {{ format }}'); + {% endif %} +{% endmacro %} + {# Reader for the base types (no nesting) #} -{% macro baseTypeReader(baseType, isStruct, size) %} - {% if baseType == 'int' %} - reader.readInt() - {% elif baseType == 'BigInt' %} - reader.readBigInt() +{% macro baseTypeReader(baseType, isStruct, size, format) %} + {% if baseType == 'int' or baseType == 'BigInt' %} + {{ intFormatUtil(format, false) }} {% elif baseType == 'String' %} reader.readString() {% elif baseType == 'Uint8List' %} @@ -100,10 +158,10 @@ {# Recursive Borsh Writer, responsible to handle nested type of collections #} {% macro borshWriter(field, overrideFieldName="") %} {% set name = overrideFieldName if overrideFieldName else field.name %} - {{ recursiveWriter(name, field.nesting, field.baseType, field.isStruct, field.size) }} + {{ recursiveWriter(name, field.nesting, field.baseType, field.isStruct, field.size, field.format) }} {% endmacro %} -{% macro recursiveWriter(varName, depth, baseType, isStruct, size) %} +{% macro recursiveWriter(varName, depth, baseType, isStruct, size, format) %} {% if depth > 5 %} // ERROR: Nesting depth exceeds supported limit (5) throw Exception('Nesting depth exceeds supported limit(5)'); @@ -112,7 +170,7 @@ {{ varName }}.toBorsh(writer); {% else %} {# TODO: I have problem here because of these recursions i put ';' twice because twice is iterated here first trough writeArray and on the recursion i go inside here and i put ';' again #} - {{ baseTypeWriter(baseType, varName, size) }}; + {{ baseTypeWriter(baseType, varName, size, format) }}; {% endif %} {% else %} writer.writeArray<{{ baseType }}>({{ varName }}, ({{ baseType }} item) { @@ -120,18 +178,16 @@ // Each item is a struct item.toBorsh(writer); {% else %} - {{ recursiveWriter("item", depth - 1, baseType, false, size) }}; + {{ recursiveWriter("item", depth - 1, baseType, false, size, format) }}; {% endif %} }); {% endif %} {% endmacro %} {# Base Writer, no nested types inside #} -{% macro baseTypeWriter(baseType, varName, size) %} - {% if baseType == 'int' %} - writer.writeInt({{ varName }}) - {% elif baseType == 'BigInt' %} - writer.writeBigInt({{ varName }}) +{% macro baseTypeWriter(baseType, varName, size, format) %} + {% if baseType == 'int' or baseType == 'BigInt' %} + {{ intFormatUtil(format, true, varName) }} {% elif baseType == 'String' %} writer.writeString({{ varName }}) {% elif baseType == 'Uint8List' %} From b15781e7d183194c5b1a3b38f83adeaf35e0902e Mon Sep 17 00:00:00 2001 From: ERoydev Date: Wed, 10 Sep 2025 17:24:45 +0300 Subject: [PATCH 10/33] add(): Add import.meta check --- src/utils/render.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/utils/render.ts b/src/utils/render.ts index 96421b8..863e3a6 100644 --- a/src/utils/render.ts +++ b/src/utils/render.ts @@ -11,8 +11,13 @@ export function dartDocblock(docs: string[]): string { } export const render = (template: string, context?: object, options?: NunJucksOptions): string => { - // @ts-expect-error import.meta will be used in the right environment. - const dirname = __ESM__ ? pathDirname(fileURLToPath(import.meta.url)) : __dirname; + let dirname: string; + // Safely resolve dirname for both ESM and CommonJS environments + if (typeof import.meta !== 'undefined' && import.meta.url) { + dirname = pathDirname(fileURLToPath(import.meta.url)); + } else { + dirname = __dirname; + } const templates = __TEST__ ? join(dirname, '..', '..', 'public', 'templates') : join(dirname, 'templates'); const env = nunjucks.configure(templates, { autoescape: false, trimBlocks: true, ...options }); env.addFilter('pascalCase', pascalCase); @@ -22,4 +27,4 @@ export const render = (template: string, context?: object, options?: NunJucksOpt env.addFilter('titleCase', titleCase); env.addFilter('dartDocblock', dartDocblock); return env.render(template, context); -}; +}; \ No newline at end of file From b88ad59287b70299acb1357fde375aadaeb9cc10 Mon Sep 17 00:00:00 2001 From: ERoydev Date: Wed, 10 Sep 2025 17:26:11 +0300 Subject: [PATCH 11/33] fix:(): Inconsistent compilation issue fixed with ecmascript specification here --- tsconfig.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tsconfig.json b/tsconfig.json index 423cd40..612a7ea 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,6 +1,8 @@ { "$schema": "https://json.schemastore.org/tsconfig", - "compilerOptions": { "lib": [] }, + "compilerOptions": { + "module": "es2022", + }, "display": "@codama/renderers-dart", "extends": "./tsconfig.base.json", "include": ["src", "test"] From f27f8fe53fc3f4ab8ff1bc75366f26939778d0a1 Mon Sep 17 00:00:00 2001 From: ERoydev Date: Mon, 15 Sep 2025 16:47:23 +0300 Subject: [PATCH 12/33] add(): Added tests --- e2e/anchor/.dart_tool/package_config.json | 206 + e2e/anchor/.dart_tool/package_graph.json | 257 + e2e/anchor/idl.json | 640 +++ e2e/anchor/lib/generated/accounts.dart | 10 + .../lib/generated/accounts/guard_v1.dart | 137 + e2e/anchor/lib/generated/errors.dart | 8 + .../generated/errors/wen_transfer_guard.dart | 161 + e2e/anchor/lib/generated/instructions.dart | 13 + .../generated/instructions/create_guard.dart | 160 + .../lib/generated/instructions/execute.dart | 111 + .../generated/instructions/initialize.dart | 98 + .../generated/instructions/update_guard.dart | 130 + e2e/anchor/lib/generated/lib.dart | 19 + e2e/anchor/lib/generated/mod.dart | 19 + e2e/anchor/lib/generated/programs.dart | 20 + e2e/anchor/lib/generated/shared.dart | 587 ++ e2e/anchor/lib/generated/types.dart | 13 + e2e/anchor/lib/generated/types/cpi_rule.dart | 72 + ...metadata_additional_field_restriction.dart | 72 + .../types/metadata_additional_field_rule.dart | 49 + .../generated/types/transfer_amount_rule.dart | 88 + e2e/anchor/pubspec.lock | 261 + e2e/anchor/pubspec.yaml | 7 + e2e/anchor/src/generated/accounts.dart | 10 + .../src/generated/accounts/guard_v1.dart | 137 + e2e/anchor/src/generated/errors.dart | 8 + .../generated/errors/wen_transfer_guard.dart | 161 + e2e/anchor/src/generated/instructions.dart | 13 + .../generated/instructions/create_guard.dart | 160 + .../src/generated/instructions/execute.dart | 111 + .../generated/instructions/initialize.dart | 98 + .../generated/instructions/update_guard.dart | 130 + e2e/anchor/src/generated/lib.dart | 19 + e2e/anchor/src/generated/mod.dart | 19 + e2e/anchor/src/generated/programs.dart | 20 + e2e/anchor/src/generated/shared.dart | 587 ++ e2e/anchor/src/generated/types.dart | 13 + e2e/anchor/src/generated/types/cpi_rule.dart | 72 + ...metadata_additional_field_restriction.dart | 72 + .../types/metadata_additional_field_rule.dart | 49 + .../generated/types/transfer_amount_rule.dart | 88 + e2e/dummy/.dart_tool/package_config.json | 206 + e2e/dummy/.dart_tool/package_graph.json | 257 + e2e/dummy/idl.json | 149 + e2e/dummy/lib/generated/errors.dart | 8 + e2e/dummy/lib/generated/lib.dart | 11 + e2e/dummy/lib/generated/mod.dart | 11 + e2e/dummy/lib/generated/programs.dart | 19 + e2e/dummy/pubspec.lock | 261 + e2e/dummy/pubspec.yaml | 7 + e2e/generate-anchor.cjs | 32 + e2e/generate.cjs | 31 + e2e/memo/.dart_tool/package_config.json | 206 + e2e/memo/.dart_tool/package_graph.json | 257 + e2e/memo/idl.json | 44 + e2e/memo/lib/generated/errors.dart | 8 + e2e/memo/lib/generated/lib.dart | 11 + e2e/memo/lib/generated/mod.dart | 11 + e2e/memo/lib/generated/programs.dart | 19 + e2e/memo/pubspec.lock | 261 + e2e/memo/pubspec.yaml | 7 + e2e/meteora/.dart_tool/package_config.json | 206 + e2e/meteora/.dart_tool/package_graph.json | 257 + e2e/meteora/idl.json | 4868 +++++++++++++++++ e2e/meteora/pubspec.lock | 261 + e2e/meteora/pubspec.yaml | 7 + e2e/system/.dart_tool/package_config.json | 206 + e2e/system/.dart_tool/package_graph.json | 257 + e2e/system/idl.json | 1042 ++++ e2e/system/lib/generated/errors.dart | 8 + e2e/system/lib/generated/lib.dart | 11 + e2e/system/lib/generated/mod.dart | 11 + e2e/system/lib/generated/programs.dart | 19 + e2e/system/pubspec.lock | 261 + e2e/system/pubspec.yaml | 7 + e2e/test.sh | 43 + package.json | 23 +- pnpm-lock.yaml | 728 ++- public/templates/macros.njk | 84 +- public/templates/pages/accountsPage.njk | 10 +- public/templates/pages/instructionsPage.njk | 184 +- public/templates/pages/sharedPage.njk | 351 +- scripts/test-treeshakability.mjs | 14 + scripts/test-types.mjs | 6 + scripts/test-unit.mjs | 14 + test/_setup.ts | 23 + test/accountsPage.test.ts | 94 + test/definedTypesPage.test.ts | 39 + test/exports/commonjs.cjs | 7 + test/exports/module.mjs | 10 + test/types/array.test.ts | 518 ++ test/types/number.test.ts | 536 ++ vitest.config.base.mts | 22 + vitest.config.browser.mts | 3 + vitest.config.node.mts | 3 + vitest.config.react-native.mts | 3 + 96 files changed, 16438 insertions(+), 419 deletions(-) create mode 100644 e2e/anchor/.dart_tool/package_config.json create mode 100644 e2e/anchor/.dart_tool/package_graph.json create mode 100644 e2e/anchor/idl.json create mode 100644 e2e/anchor/lib/generated/accounts.dart create mode 100644 e2e/anchor/lib/generated/accounts/guard_v1.dart create mode 100644 e2e/anchor/lib/generated/errors.dart create mode 100644 e2e/anchor/lib/generated/errors/wen_transfer_guard.dart create mode 100644 e2e/anchor/lib/generated/instructions.dart create mode 100644 e2e/anchor/lib/generated/instructions/create_guard.dart create mode 100644 e2e/anchor/lib/generated/instructions/execute.dart create mode 100644 e2e/anchor/lib/generated/instructions/initialize.dart create mode 100644 e2e/anchor/lib/generated/instructions/update_guard.dart create mode 100644 e2e/anchor/lib/generated/lib.dart create mode 100644 e2e/anchor/lib/generated/mod.dart create mode 100644 e2e/anchor/lib/generated/programs.dart create mode 100644 e2e/anchor/lib/generated/shared.dart create mode 100644 e2e/anchor/lib/generated/types.dart create mode 100644 e2e/anchor/lib/generated/types/cpi_rule.dart create mode 100644 e2e/anchor/lib/generated/types/metadata_additional_field_restriction.dart create mode 100644 e2e/anchor/lib/generated/types/metadata_additional_field_rule.dart create mode 100644 e2e/anchor/lib/generated/types/transfer_amount_rule.dart create mode 100644 e2e/anchor/pubspec.lock create mode 100644 e2e/anchor/pubspec.yaml create mode 100644 e2e/anchor/src/generated/accounts.dart create mode 100644 e2e/anchor/src/generated/accounts/guard_v1.dart create mode 100644 e2e/anchor/src/generated/errors.dart create mode 100644 e2e/anchor/src/generated/errors/wen_transfer_guard.dart create mode 100644 e2e/anchor/src/generated/instructions.dart create mode 100644 e2e/anchor/src/generated/instructions/create_guard.dart create mode 100644 e2e/anchor/src/generated/instructions/execute.dart create mode 100644 e2e/anchor/src/generated/instructions/initialize.dart create mode 100644 e2e/anchor/src/generated/instructions/update_guard.dart create mode 100644 e2e/anchor/src/generated/lib.dart create mode 100644 e2e/anchor/src/generated/mod.dart create mode 100644 e2e/anchor/src/generated/programs.dart create mode 100644 e2e/anchor/src/generated/shared.dart create mode 100644 e2e/anchor/src/generated/types.dart create mode 100644 e2e/anchor/src/generated/types/cpi_rule.dart create mode 100644 e2e/anchor/src/generated/types/metadata_additional_field_restriction.dart create mode 100644 e2e/anchor/src/generated/types/metadata_additional_field_rule.dart create mode 100644 e2e/anchor/src/generated/types/transfer_amount_rule.dart create mode 100644 e2e/dummy/.dart_tool/package_config.json create mode 100644 e2e/dummy/.dart_tool/package_graph.json create mode 100644 e2e/dummy/idl.json create mode 100644 e2e/dummy/lib/generated/errors.dart create mode 100644 e2e/dummy/lib/generated/lib.dart create mode 100644 e2e/dummy/lib/generated/mod.dart create mode 100644 e2e/dummy/lib/generated/programs.dart create mode 100644 e2e/dummy/pubspec.lock create mode 100644 e2e/dummy/pubspec.yaml create mode 100755 e2e/generate-anchor.cjs create mode 100755 e2e/generate.cjs create mode 100644 e2e/memo/.dart_tool/package_config.json create mode 100644 e2e/memo/.dart_tool/package_graph.json create mode 100644 e2e/memo/idl.json create mode 100644 e2e/memo/lib/generated/errors.dart create mode 100644 e2e/memo/lib/generated/lib.dart create mode 100644 e2e/memo/lib/generated/mod.dart create mode 100644 e2e/memo/lib/generated/programs.dart create mode 100644 e2e/memo/pubspec.lock create mode 100644 e2e/memo/pubspec.yaml create mode 100644 e2e/meteora/.dart_tool/package_config.json create mode 100644 e2e/meteora/.dart_tool/package_graph.json create mode 100644 e2e/meteora/idl.json create mode 100644 e2e/meteora/pubspec.lock create mode 100644 e2e/meteora/pubspec.yaml create mode 100644 e2e/system/.dart_tool/package_config.json create mode 100644 e2e/system/.dart_tool/package_graph.json create mode 100644 e2e/system/idl.json create mode 100644 e2e/system/lib/generated/errors.dart create mode 100644 e2e/system/lib/generated/lib.dart create mode 100644 e2e/system/lib/generated/mod.dart create mode 100644 e2e/system/lib/generated/programs.dart create mode 100644 e2e/system/pubspec.lock create mode 100644 e2e/system/pubspec.yaml create mode 100755 e2e/test.sh create mode 100644 scripts/test-treeshakability.mjs create mode 100644 scripts/test-types.mjs create mode 100644 scripts/test-unit.mjs create mode 100644 test/_setup.ts create mode 100644 test/accountsPage.test.ts create mode 100644 test/definedTypesPage.test.ts create mode 100644 test/exports/commonjs.cjs create mode 100644 test/exports/module.mjs create mode 100644 test/types/array.test.ts create mode 100644 test/types/number.test.ts create mode 100644 vitest.config.base.mts create mode 100644 vitest.config.browser.mts create mode 100644 vitest.config.node.mts create mode 100644 vitest.config.react-native.mts diff --git a/e2e/anchor/.dart_tool/package_config.json b/e2e/anchor/.dart_tool/package_config.json new file mode 100644 index 0000000..b766e22 --- /dev/null +++ b/e2e/anchor/.dart_tool/package_config.json @@ -0,0 +1,206 @@ +{ + "configVersion": 2, + "packages": [ + { + "name": "async", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/async-2.13.0", + "packageUri": "lib/", + "languageVersion": "3.4" + }, + { + "name": "bip39", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/bip39-1.0.6", + "packageUri": "lib/", + "languageVersion": "2.12" + }, + { + "name": "borsh_annotation", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/borsh_annotation-0.3.2", + "packageUri": "lib/", + "languageVersion": "3.0" + }, + { + "name": "clock", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/clock-1.1.2", + "packageUri": "lib/", + "languageVersion": "3.4" + }, + { + "name": "collection", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/collection-1.19.1", + "packageUri": "lib/", + "languageVersion": "3.4" + }, + { + "name": "convert", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/convert-3.1.2", + "packageUri": "lib/", + "languageVersion": "3.4" + }, + { + "name": "crypto", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/crypto-3.0.6", + "packageUri": "lib/", + "languageVersion": "3.4" + }, + { + "name": "cryptography", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/cryptography-2.7.0", + "packageUri": "lib/", + "languageVersion": "3.1" + }, + { + "name": "decimal", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/decimal-3.2.4", + "packageUri": "lib/", + "languageVersion": "3.3" + }, + { + "name": "ed25519_hd_key", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/ed25519_hd_key-2.3.0", + "packageUri": "lib/", + "languageVersion": "3.4" + }, + { + "name": "ffi", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/ffi-2.1.4", + "packageUri": "lib/", + "languageVersion": "3.7" + }, + { + "name": "freezed_annotation", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/freezed_annotation-2.4.4", + "packageUri": "lib/", + "languageVersion": "3.0" + }, + { + "name": "hex", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/hex-0.2.0", + "packageUri": "lib/", + "languageVersion": "2.12" + }, + { + "name": "http", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/http-1.5.0", + "packageUri": "lib/", + "languageVersion": "3.4" + }, + { + "name": "http_parser", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/http_parser-4.1.2", + "packageUri": "lib/", + "languageVersion": "3.4" + }, + { + "name": "intl", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/intl-0.20.2", + "packageUri": "lib/", + "languageVersion": "3.3" + }, + { + "name": "js", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/js-0.6.7", + "packageUri": "lib/", + "languageVersion": "2.19" + }, + { + "name": "json_annotation", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/json_annotation-4.9.0", + "packageUri": "lib/", + "languageVersion": "3.0" + }, + { + "name": "meta", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/meta-1.17.0", + "packageUri": "lib/", + "languageVersion": "3.5" + }, + { + "name": "path", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/path-1.9.1", + "packageUri": "lib/", + "languageVersion": "3.4" + }, + { + "name": "pinenacl", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/pinenacl-0.6.0", + "packageUri": "lib/", + "languageVersion": "3.4" + }, + { + "name": "pointycastle", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/pointycastle-3.9.1", + "packageUri": "lib/", + "languageVersion": "3.2" + }, + { + "name": "rational", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/rational-2.2.3", + "packageUri": "lib/", + "languageVersion": "2.14" + }, + { + "name": "solana", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/solana-0.31.2+1", + "packageUri": "lib/", + "languageVersion": "3.2" + }, + { + "name": "source_span", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/source_span-1.10.1", + "packageUri": "lib/", + "languageVersion": "3.1" + }, + { + "name": "stream_channel", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/stream_channel-2.1.4", + "packageUri": "lib/", + "languageVersion": "3.3" + }, + { + "name": "string_scanner", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/string_scanner-1.4.1", + "packageUri": "lib/", + "languageVersion": "3.1" + }, + { + "name": "term_glyph", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/term_glyph-1.2.2", + "packageUri": "lib/", + "languageVersion": "3.1" + }, + { + "name": "typed_data", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/typed_data-1.4.0", + "packageUri": "lib/", + "languageVersion": "3.5" + }, + { + "name": "web", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/web-1.1.1", + "packageUri": "lib/", + "languageVersion": "3.4" + }, + { + "name": "web_socket", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/web_socket-1.0.1", + "packageUri": "lib/", + "languageVersion": "3.4" + }, + { + "name": "web_socket_channel", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/web_socket_channel-3.0.3", + "packageUri": "lib/", + "languageVersion": "3.3" + }, + { + "name": "anchor", + "rootUri": "../", + "packageUri": "lib/", + "languageVersion": "2.17" + } + ], + "generator": "pub", + "generatorVersion": "3.9.0", + "pubCache": "file:///Users/emilemilovroydev/.pub-cache" +} diff --git a/e2e/anchor/.dart_tool/package_graph.json b/e2e/anchor/.dart_tool/package_graph.json new file mode 100644 index 0000000..0f5245e --- /dev/null +++ b/e2e/anchor/.dart_tool/package_graph.json @@ -0,0 +1,257 @@ +{ + "roots": [ + "anchor" + ], + "packages": [ + { + "name": "anchor", + "version": "0.1.0", + "dependencies": [ + "solana" + ], + "devDependencies": [] + }, + { + "name": "solana", + "version": "0.31.2+1", + "dependencies": [ + "bip39", + "borsh_annotation", + "collection", + "convert", + "cryptography", + "decimal", + "ed25519_hd_key", + "freezed_annotation", + "http", + "json_annotation", + "typed_data", + "web_socket_channel" + ] + }, + { + "name": "web_socket_channel", + "version": "3.0.3", + "dependencies": [ + "async", + "crypto", + "stream_channel", + "web", + "web_socket" + ] + }, + { + "name": "typed_data", + "version": "1.4.0", + "dependencies": [ + "collection" + ] + }, + { + "name": "json_annotation", + "version": "4.9.0", + "dependencies": [ + "meta" + ] + }, + { + "name": "http", + "version": "1.5.0", + "dependencies": [ + "async", + "http_parser", + "meta", + "web" + ] + }, + { + "name": "freezed_annotation", + "version": "2.4.4", + "dependencies": [ + "collection", + "json_annotation", + "meta" + ] + }, + { + "name": "ed25519_hd_key", + "version": "2.3.0", + "dependencies": [ + "crypto", + "pinenacl" + ] + }, + { + "name": "decimal", + "version": "3.2.4", + "dependencies": [ + "intl", + "rational" + ] + }, + { + "name": "cryptography", + "version": "2.7.0", + "dependencies": [ + "collection", + "crypto", + "ffi", + "js", + "meta", + "typed_data" + ] + }, + { + "name": "convert", + "version": "3.1.2", + "dependencies": [ + "typed_data" + ] + }, + { + "name": "collection", + "version": "1.19.1", + "dependencies": [] + }, + { + "name": "borsh_annotation", + "version": "0.3.2", + "dependencies": [] + }, + { + "name": "bip39", + "version": "1.0.6", + "dependencies": [ + "crypto", + "hex", + "pointycastle" + ] + }, + { + "name": "web_socket", + "version": "1.0.1", + "dependencies": [ + "web" + ] + }, + { + "name": "web", + "version": "1.1.1", + "dependencies": [] + }, + { + "name": "stream_channel", + "version": "2.1.4", + "dependencies": [ + "async" + ] + }, + { + "name": "crypto", + "version": "3.0.6", + "dependencies": [ + "typed_data" + ] + }, + { + "name": "async", + "version": "2.13.0", + "dependencies": [ + "collection", + "meta" + ] + }, + { + "name": "meta", + "version": "1.17.0", + "dependencies": [] + }, + { + "name": "http_parser", + "version": "4.1.2", + "dependencies": [ + "collection", + "source_span", + "string_scanner", + "typed_data" + ] + }, + { + "name": "pinenacl", + "version": "0.6.0", + "dependencies": [] + }, + { + "name": "rational", + "version": "2.2.3", + "dependencies": [] + }, + { + "name": "intl", + "version": "0.20.2", + "dependencies": [ + "clock", + "meta", + "path" + ] + }, + { + "name": "js", + "version": "0.6.7", + "dependencies": [ + "meta" + ] + }, + { + "name": "ffi", + "version": "2.1.4", + "dependencies": [] + }, + { + "name": "hex", + "version": "0.2.0", + "dependencies": [] + }, + { + "name": "pointycastle", + "version": "3.9.1", + "dependencies": [ + "collection", + "convert", + "js" + ] + }, + { + "name": "string_scanner", + "version": "1.4.1", + "dependencies": [ + "source_span" + ] + }, + { + "name": "source_span", + "version": "1.10.1", + "dependencies": [ + "collection", + "path", + "term_glyph" + ] + }, + { + "name": "path", + "version": "1.9.1", + "dependencies": [] + }, + { + "name": "clock", + "version": "1.1.2", + "dependencies": [] + }, + { + "name": "term_glyph", + "version": "1.2.2", + "dependencies": [] + } + ], + "configVersion": 1 +} \ No newline at end of file diff --git a/e2e/anchor/idl.json b/e2e/anchor/idl.json new file mode 100644 index 0000000..d6a1d8b --- /dev/null +++ b/e2e/anchor/idl.json @@ -0,0 +1,640 @@ +{ + "address": "LockdqYQ9X2kwtWB99ioSbxubAmEi8o9jqYwbXgrrRw", + "metadata": { + "name": "wen_transfer_guard", + "version": "0.1.0", + "spec": "0.1.0", + "description": "A generic transfer hook implementation for Token Extensions" + }, + "instructions": [ + { + "name": "create_guard", + "discriminator": [251, 254, 17, 198, 219, 218, 154, 99], + "accounts": [ + { + "name": "guard", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 119, 101, 110, 95, 116, 111, 107, 101, 110, 95, 116, 114, 97, 110, 115, 102, 101, + 114, 95, 103, 117, 97, 114, 100 + ] + }, + { + "kind": "const", + "value": [103, 117, 97, 114, 100, 95, 118, 49] + }, + { + "kind": "account", + "path": "mint" + } + ] + } + }, + { + "name": "mint", + "writable": true, + "signer": true + }, + { + "name": "mint_token_account", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "account", + "path": "guard_authority" + }, + { + "kind": "account", + "path": "token_program" + }, + { + "kind": "account", + "path": "mint" + } + ], + "program": { + "kind": "const", + "value": [ + 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142, 13, 131, 11, 90, 19, 153, + 218, 255, 16, 132, 4, 142, 123, 216, 219, 233, 248, 89 + ] + } + } + }, + { + "name": "guard_authority", + "signer": true + }, + { + "name": "payer", + "writable": true, + "signer": true + }, + { + "name": "associated_token_program", + "address": "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL" + }, + { + "name": "token_program", + "address": "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb" + }, + { + "name": "system_program", + "address": "11111111111111111111111111111111" + } + ], + "args": [ + { + "name": "args", + "type": { + "defined": { + "name": "CreateGuardArgs" + } + } + } + ] + }, + { + "name": "execute", + "discriminator": [105, 37, 101, 197, 75, 251, 102, 26], + "accounts": [ + { + "name": "source_account" + }, + { + "name": "mint" + }, + { + "name": "destination_account" + }, + { + "name": "owner_delegate" + }, + { + "name": "extra_metas_account", + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 101, 120, 116, 114, 97, 45, 97, 99, 99, 111, 117, 110, 116, 45, 109, 101, 116, 97, + 115 + ] + }, + { + "kind": "account", + "path": "mint" + } + ] + } + }, + { + "name": "guard", + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 119, 101, 110, 95, 116, 111, 107, 101, 110, 95, 116, 114, 97, 110, 115, 102, 101, + 114, 95, 103, 117, 97, 114, 100 + ] + }, + { + "kind": "const", + "value": [103, 117, 97, 114, 100, 95, 118, 49] + }, + { + "kind": "account", + "path": "guard.mint", + "account": "GuardV1" + } + ] + } + }, + { + "name": "instruction_sysvar_account", + "address": "Sysvar1nstructions1111111111111111111111111" + } + ], + "args": [ + { + "name": "amount", + "type": "u64" + } + ] + }, + { + "name": "initialize", + "discriminator": [43, 34, 13, 49, 167, 88, 235, 235], + "accounts": [ + { + "name": "extra_metas_account", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 101, 120, 116, 114, 97, 45, 97, 99, 99, 111, 117, 110, 116, 45, 109, 101, 116, 97, + 115 + ] + }, + { + "kind": "account", + "path": "mint" + } + ] + } + }, + { + "name": "guard", + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 119, 101, 110, 95, 116, 111, 107, 101, 110, 95, 116, 114, 97, 110, 115, 102, 101, + 114, 95, 103, 117, 97, 114, 100 + ] + }, + { + "kind": "const", + "value": [103, 117, 97, 114, 100, 95, 118, 49] + }, + { + "kind": "account", + "path": "guard.mint", + "account": "GuardV1" + } + ] + } + }, + { + "name": "mint" + }, + { + "name": "transfer_hook_authority", + "writable": true, + "signer": true + }, + { + "name": "system_program", + "address": "11111111111111111111111111111111" + }, + { + "name": "payer", + "writable": true, + "signer": true + } + ], + "args": [] + }, + { + "name": "update_guard", + "discriminator": [51, 38, 175, 180, 25, 249, 39, 24], + "accounts": [ + { + "name": "guard", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 119, 101, 110, 95, 116, 111, 107, 101, 110, 95, 116, 114, 97, 110, 115, 102, 101, + 114, 95, 103, 117, 97, 114, 100 + ] + }, + { + "kind": "const", + "value": [103, 117, 97, 114, 100, 95, 118, 49] + }, + { + "kind": "account", + "path": "mint" + } + ] + } + }, + { + "name": "mint" + }, + { + "name": "token_account", + "pda": { + "seeds": [ + { + "kind": "account", + "path": "guard_authority" + }, + { + "kind": "account", + "path": "token_program" + }, + { + "kind": "account", + "path": "mint" + } + ], + "program": { + "kind": "const", + "value": [ + 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142, 13, 131, 11, 90, 19, 153, + 218, 255, 16, 132, 4, 142, 123, 216, 219, 233, 248, 89 + ] + } + } + }, + { + "name": "guard_authority", + "signer": true + }, + { + "name": "token_program", + "address": "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb" + }, + { + "name": "system_program", + "address": "11111111111111111111111111111111" + } + ], + "args": [ + { + "name": "args", + "type": { + "defined": { + "name": "UpdateGuardArgs" + } + } + } + ] + } + ], + "accounts": [ + { + "name": "GuardV1", + "discriminator": [185, 149, 156, 78, 245, 108, 172, 68] + } + ], + "errors": [ + { + "code": 6000, + "name": "CpiRuleEnforcementFailed", + "msg": "Cpi Rule Enforcement Failed" + }, + { + "code": 6001, + "name": "TransferAmountRuleEnforceFailed", + "msg": "Transfer Amount Rule Enforce Failed" + }, + { + "code": 6002, + "name": "MetadataFieldDoesNotExist", + "msg": "Metadata Field Does Not Exist" + }, + { + "code": 6003, + "name": "MetadataFieldDoesNotPass", + "msg": "Metadata Field Does Not Pass" + }, + { + "code": 6004, + "name": "GuardTokenAmountShouldBeAtLeastOne", + "msg": "Guard token amount should be at least 1" + }, + { + "code": 6005, + "name": "NotOwnedByToken2022Program", + "msg": "Not owned by token 2022 program" + }, + { + "code": 6006, + "name": "MustBeInitializedByTransferHookAuthority", + "msg": "Must be initialized by Transfer Hook Authority" + }, + { + "code": 6007, + "name": "MintAssignedTransferHookProgramIsNotThisOne", + "msg": "Mints assigned Transfer Hook Program is not this one" + } + ], + "types": [ + { + "name": "CpiRule", + "docs": ["Controls which protocols can interact with the token by", "enforcing Allow and Deny lists."], + "type": { + "kind": "enum", + "variants": [ + { + "name": "Allow", + "fields": [ + { + "vec": "pubkey" + } + ] + }, + { + "name": "Deny", + "fields": [ + { + "vec": "pubkey" + } + ] + } + ] + } + }, + { + "name": "CreateGuardArgs", + "type": { + "kind": "struct", + "fields": [ + { + "name": "name", + "type": "string" + }, + { + "name": "symbol", + "type": "string" + }, + { + "name": "uri", + "type": "string" + }, + { + "name": "cpi_rule", + "type": { + "option": { + "defined": { + "name": "CpiRule" + } + } + } + }, + { + "name": "transfer_amount_rule", + "type": { + "option": { + "defined": { + "name": "TransferAmountRule" + } + } + } + }, + { + "name": "additional_fields_rule", + "type": { + "vec": { + "defined": { + "name": "MetadataAdditionalFieldRule" + } + } + } + } + ] + } + }, + { + "name": "GuardV1", + "type": { + "kind": "struct", + "fields": [ + { + "name": "mint", + "docs": [ + "Mint token representing the guard, do not confuse with the mint of the token being transferred." + ], + "type": "pubkey" + }, + { + "name": "bump", + "docs": ["Bump seed for the guard account."], + "type": "u8" + }, + { + "name": "cpi_rule", + "docs": ["CPI ruleset for the guard."], + "type": { + "option": { + "defined": { + "name": "CpiRule" + } + } + } + }, + { + "name": "transfer_amount_rule", + "docs": ["Transfer amount ruleset for the guard."], + "type": { + "option": { + "defined": { + "name": "TransferAmountRule" + } + } + } + }, + { + "name": "additional_fields_rule", + "docs": ["Additional fields ruleset for the guard."], + "type": { + "vec": { + "defined": { + "name": "MetadataAdditionalFieldRule" + } + } + } + } + ] + } + }, + { + "name": "MetadataAdditionalFieldRestriction", + "docs": [ + "Inner enum for the MetadataAdditionalFieldRestriction enum.", + "* Includes - The field must include one of the values in the vector.", + "* Excludes - The field must not include any of the values in the vector." + ], + "type": { + "kind": "enum", + "variants": [ + { + "name": "Includes", + "fields": [ + { + "vec": "string" + } + ] + }, + { + "name": "Excludes", + "fields": [ + { + "vec": "string" + } + ] + } + ] + } + }, + { + "name": "MetadataAdditionalFieldRule", + "docs": [ + "Enforces rules on a single additional field in the mint metadata.", + "The field must exist and the value must pass the restriction." + ], + "type": { + "kind": "struct", + "fields": [ + { + "name": "field", + "type": "string" + }, + { + "name": "value_restrictions", + "type": { + "option": { + "defined": { + "name": "MetadataAdditionalFieldRestriction" + } + } + } + } + ] + } + }, + { + "name": "TransferAmountRule", + "docs": [ + "Enforces rules on the amount of tokens being transferred.", + "The rules can be above, below, equal to, or within a range." + ], + "type": { + "kind": "enum", + "variants": [ + { + "name": "Above", + "fields": ["u64"] + }, + { + "name": "Below", + "fields": ["u64"] + }, + { + "name": "Equal", + "fields": ["u64"] + }, + { + "name": "Rang", + "fields": ["u64", "u64"] + } + ] + } + }, + { + "name": "UpdateGuardArgs", + "type": { + "kind": "struct", + "fields": [ + { + "name": "cpi_rule", + "type": { + "option": { + "defined": { + "name": "CpiRule" + } + } + } + }, + { + "name": "transfer_amount_rule", + "type": { + "option": { + "defined": { + "name": "TransferAmountRule" + } + } + } + }, + { + "name": "additional_fields_rule", + "type": { + "vec": { + "defined": { + "name": "MetadataAdditionalFieldRule" + } + } + } + } + ] + } + } + ], + "constants": [ + { + "name": "EXTRA_ACCOUNT_METAS", + "type": { + "array": ["u8", 19] + }, + "value": "[101, 120, 116, 114, 97, 45, 97, 99, 99, 111, 117, 110, 116, 45, 109, 101, 116, 97, 115]" + }, + { + "name": "GUARD_V1", + "type": { + "array": ["u8", 8] + }, + "value": "[103, 117, 97, 114, 100, 95, 118, 49]" + }, + { + "name": "WEN_TOKEN_GUARD", + "type": { + "array": ["u8", 24] + }, + "value": "[119, 101, 110, 95, 116, 111, 107, 101, 110, 95, 116, 114, 97, 110, 115, 102, 101, 114, 95, 103, 117, 97, 114, 100]" + } + ] +} diff --git a/e2e/anchor/lib/generated/accounts.dart b/e2e/anchor/lib/generated/accounts.dart new file mode 100644 index 0000000..98c8416 --- /dev/null +++ b/e2e/anchor/lib/generated/accounts.dart @@ -0,0 +1,10 @@ +/// This code was AUTOGENERATED using the codama library. +/// Please DO NOT EDIT THIS FILE, instead use visitors +/// to add features, then rerun codama to update it. +/// +/// https://github.com/codama-idl/codama +/// + +// This file exports account classes for all accounts in the SDK. + +export 'accounts/guard_v1.dart'; diff --git a/e2e/anchor/lib/generated/accounts/guard_v1.dart b/e2e/anchor/lib/generated/accounts/guard_v1.dart new file mode 100644 index 0000000..722c577 --- /dev/null +++ b/e2e/anchor/lib/generated/accounts/guard_v1.dart @@ -0,0 +1,137 @@ +/// This code was AUTOGENERATED using the codama library. +/// Please DO NOT EDIT THIS FILE, instead use visitors +/// to add features, then rerun codama to update it. +/// +/// https://github.com/codama-idl/codama +/// + +import 'dart:typed_data'; +import 'package:collection/collection.dart'; +import 'package:solana/dto.dart'; +import 'package:solana/solana.dart'; +import '../shared.dart'; +import '../types/cpi_rule.dart'; +import '../types/metadata_additional_field_rule.dart'; +import '../types/transfer_amount_rule.dart'; + +const List GUARD_V1_DISCRIMINATOR = [185, 149, 156, 78, 245, 108, 172, 68]; + +/// Generated account class for GuardV1. +/// +class GuardV1 { + // Fields + final Ed25519HDPublicKey mint; + final int /* type: u8 */ bump; + final CpiRule? cpi_rule; + final TransferAmountRule? transfer_amount_rule; + final List additional_fields_rule; + + // Constructor + GuardV1({ + required this.mint, + required this.bump, + required this.cpi_rule, + required this.transfer_amount_rule, + required this.additional_fields_rule, + }); + + /// Deserializes this account from borsh. + static GuardV1 fromBorsh(BinaryReader reader) { + return GuardV1( + mint: Ed25519HDPublicKey(reader.readPubkey()), + bump: reader.readU8(), + cpi_rule: reader.readU8() == 1 ? CpiRuleBorsh.fromBorsh(reader) : null, + transfer_amount_rule: reader.readU8() == 1 + ? TransferAmountRuleBorsh.fromBorsh(reader) + : null, + additional_fields_rule: reader.readArray(() { + // item is a struct, call fromBorsh per item + return MetadataAdditionalFieldRuleBorsh.fromBorsh(reader); + }), + ); + } + + /// Serializes this account to borsh. + void toBorsh(BinaryWriter writer) { + writer.writePubkey(Uint8List.fromList(mint.bytes)); + + writer.writeU8(bump); + + writer.writeU8(cpi_rule != null ? 1 : 0); + if (cpi_rule != null) { + cpi_rule!.toBorsh(writer); + } + writer.writeU8(transfer_amount_rule != null ? 1 : 0); + if (transfer_amount_rule != null) { + transfer_amount_rule!.toBorsh(writer); + } + writer.writeArray(additional_fields_rule, + (MetadataAdditionalFieldRule item) { + // Each item is a struct + item.toBorsh(writer); + }); + } + + /// Creates a [GuardV1] from its bytes representation. + static GuardV1 fromBytes(Uint8List data) { + final buffer = ByteData.view(data.buffer); + final reader = BinaryReader(buffer); + + // Validate the discriminator + final discriminator = reader.readDiscriminator(); + if (!const ListEquality().equals(discriminator, GUARD_V1_DISCRIMINATOR)) { + throw FormatException('Invalid account discriminator'); + } + + return GuardV1.fromBorsh(reader); + } + + /// Serializes this account to its bytes representation. + Uint8List toBytes() { + final writer = BinaryWriter(); + + // Write discriminator + writer.writeDiscriminator(Uint8List.fromList(GUARD_V1_DISCRIMINATOR)); + + // Write account data + toBorsh(writer); + + return writer.toBytes(); + } + + /// Fetches a [GuardV1] from the blockchain. + static Future fetch( + RpcClient client, + Ed25519HDPublicKey address, + ) async { + final accountInfo = await client.getAccountInfo(address.toBase58(), + encoding: Encoding.base64); + final data = accountInfo.value?.data; + + if (data == null) { + throw AccountNotFoundError(address); + } + + if (data is! BinaryAccountData) { + throw FormatException( + 'Expected binary account data, got ${data.runtimeType}'); + } + + return fromBytes(Uint8List.fromList(data.data)); + } + + /// Fetches a [GuardV1] from the blockchain if it exists. + static Future fetchNullable( + RpcClient client, + Ed25519HDPublicKey address, + ) async { + try { + return await fetch(client, address); + } catch (e) { + if (e is AccountNotFoundError) { + return null; + } + rethrow; + } + } +} diff --git a/e2e/anchor/lib/generated/errors.dart b/e2e/anchor/lib/generated/errors.dart new file mode 100644 index 0000000..a105376 --- /dev/null +++ b/e2e/anchor/lib/generated/errors.dart @@ -0,0 +1,8 @@ +/// This code was AUTOGENERATED using the codama library. +/// Please DO NOT EDIT THIS FILE, instead use visitors +/// to add features, then rerun codama to update it. +/// +/// https://github.com/codama-idl/codama +/// + +// This file exports error classes for all programs in the SDK. diff --git a/e2e/anchor/lib/generated/errors/wen_transfer_guard.dart b/e2e/anchor/lib/generated/errors/wen_transfer_guard.dart new file mode 100644 index 0000000..1e633ed --- /dev/null +++ b/e2e/anchor/lib/generated/errors/wen_transfer_guard.dart @@ -0,0 +1,161 @@ +/// This code was AUTOGENERATED using the codama library. +/// Please DO NOT EDIT THIS FILE, instead use visitors +/// to add features, then rerun codama to update it. +/// +/// https://github.com/codama-idl/codama +/// + +/// Error codes for the WenTransferGuard program. +class WenTransferGuardErrorCode { + /// Cpi Rule Enforcement Failed + static const int CpiRuleEnforcementFailed = 0x1770; + + /// Transfer Amount Rule Enforce Failed + static const int TransferAmountRuleEnforceFailed = 0x1771; + + /// Metadata Field Does Not Exist + static const int MetadataFieldDoesNotExist = 0x1772; + + /// Metadata Field Does Not Pass + static const int MetadataFieldDoesNotPass = 0x1773; + + /// Guard token amount should be at least 1 + static const int GuardTokenAmountShouldBeAtLeastOne = 0x1774; + + /// Not owned by token 2022 program + static const int NotOwnedByToken2022Program = 0x1775; + + /// Must be initialized by Transfer Hook Authority + static const int MustBeInitializedByTransferHookAuthority = 0x1776; + + /// Mints assigned Transfer Hook Program is not this one + static const int MintAssignedTransferHookProgramIsNotThisOne = 0x1777; +} + +/// Base class for all WenTransferGuard program errors. +abstract class WenTransferGuardError extends Error { + /// The numerical error code. + final int code; + + /// Human-readable error message. + final String message; + + /// Creates a new WenTransferGuardError. + WenTransferGuardError(this.code, this.message); + + /// Creates a WenTransferGuardError from a raw error code. + static WenTransferGuardError fromCode(int code) { + switch (code) { + case WenTransferGuardErrorCode.CpiRuleEnforcementFailed: + return CpiRuleEnforcementFailedError(); + case WenTransferGuardErrorCode.TransferAmountRuleEnforceFailed: + return TransferAmountRuleEnforceFailedError(); + case WenTransferGuardErrorCode.MetadataFieldDoesNotExist: + return MetadataFieldDoesNotExistError(); + case WenTransferGuardErrorCode.MetadataFieldDoesNotPass: + return MetadataFieldDoesNotPassError(); + case WenTransferGuardErrorCode.GuardTokenAmountShouldBeAtLeastOne: + return GuardTokenAmountShouldBeAtLeastOneError(); + case WenTransferGuardErrorCode.NotOwnedByToken2022Program: + return NotOwnedByToken2022ProgramError(); + case WenTransferGuardErrorCode.MustBeInitializedByTransferHookAuthority: + return MustBeInitializedByTransferHookAuthorityError(); + case WenTransferGuardErrorCode + .MintAssignedTransferHookProgramIsNotThisOne: + return MintAssignedTransferHookProgramIsNotThisOneError(); + default: + return UnknownError(code); + } + } + + @override + String toString() => '$runtimeType: [$code] $message'; +} + +/// Represents an unknown error from the WenTransferGuard program. +class UnknownError extends WenTransferGuardError { + /// Creates a new UnknownError. + UnknownError(int code) : super(code, 'Unknown error'); +} + +/// Cpi Rule Enforcement Failed +class CpiRuleEnforcementFailedError extends WenTransferGuardError { + /// Creates a new CpiRuleEnforcementFailedError. + CpiRuleEnforcementFailedError() + : super( + WenTransferGuardErrorCode.CpiRuleEnforcementFailed, + 'Cpi Rule Enforcement Failed', + ); +} + +/// Transfer Amount Rule Enforce Failed +class TransferAmountRuleEnforceFailedError extends WenTransferGuardError { + /// Creates a new TransferAmountRuleEnforceFailedError. + TransferAmountRuleEnforceFailedError() + : super( + WenTransferGuardErrorCode.TransferAmountRuleEnforceFailed, + 'Transfer Amount Rule Enforce Failed', + ); +} + +/// Metadata Field Does Not Exist +class MetadataFieldDoesNotExistError extends WenTransferGuardError { + /// Creates a new MetadataFieldDoesNotExistError. + MetadataFieldDoesNotExistError() + : super( + WenTransferGuardErrorCode.MetadataFieldDoesNotExist, + 'Metadata Field Does Not Exist', + ); +} + +/// Metadata Field Does Not Pass +class MetadataFieldDoesNotPassError extends WenTransferGuardError { + /// Creates a new MetadataFieldDoesNotPassError. + MetadataFieldDoesNotPassError() + : super( + WenTransferGuardErrorCode.MetadataFieldDoesNotPass, + 'Metadata Field Does Not Pass', + ); +} + +/// Guard token amount should be at least 1 +class GuardTokenAmountShouldBeAtLeastOneError extends WenTransferGuardError { + /// Creates a new GuardTokenAmountShouldBeAtLeastOneError. + GuardTokenAmountShouldBeAtLeastOneError() + : super( + WenTransferGuardErrorCode.GuardTokenAmountShouldBeAtLeastOne, + 'Guard token amount should be at least 1', + ); +} + +/// Not owned by token 2022 program +class NotOwnedByToken2022ProgramError extends WenTransferGuardError { + /// Creates a new NotOwnedByToken2022ProgramError. + NotOwnedByToken2022ProgramError() + : super( + WenTransferGuardErrorCode.NotOwnedByToken2022Program, + 'Not owned by token 2022 program', + ); +} + +/// Must be initialized by Transfer Hook Authority +class MustBeInitializedByTransferHookAuthorityError + extends WenTransferGuardError { + /// Creates a new MustBeInitializedByTransferHookAuthorityError. + MustBeInitializedByTransferHookAuthorityError() + : super( + WenTransferGuardErrorCode.MustBeInitializedByTransferHookAuthority, + 'Must be initialized by Transfer Hook Authority', + ); +} + +/// Mints assigned Transfer Hook Program is not this one +class MintAssignedTransferHookProgramIsNotThisOneError + extends WenTransferGuardError { + /// Creates a new MintAssignedTransferHookProgramIsNotThisOneError. + MintAssignedTransferHookProgramIsNotThisOneError() + : super( + WenTransferGuardErrorCode.MintAssignedTransferHookProgramIsNotThisOne, + 'Mints assigned Transfer Hook Program is not this one', + ); +} diff --git a/e2e/anchor/lib/generated/instructions.dart b/e2e/anchor/lib/generated/instructions.dart new file mode 100644 index 0000000..f9d3900 --- /dev/null +++ b/e2e/anchor/lib/generated/instructions.dart @@ -0,0 +1,13 @@ +/// This code was AUTOGENERATED using the codama library. +/// Please DO NOT EDIT THIS FILE, instead use visitors +/// to add features, then rerun codama to update it. +/// +/// https://github.com/codama-idl/codama +/// + +// This file exports instruction classes for all instructions in the SDK. + +export 'instructions/create_guard.dart'; +export 'instructions/execute.dart'; +export 'instructions/initialize.dart'; +export 'instructions/update_guard.dart'; diff --git a/e2e/anchor/lib/generated/instructions/create_guard.dart b/e2e/anchor/lib/generated/instructions/create_guard.dart new file mode 100644 index 0000000..c8e7046 --- /dev/null +++ b/e2e/anchor/lib/generated/instructions/create_guard.dart @@ -0,0 +1,160 @@ +/// This code was AUTOGENERATED using the codama library. +/// Please DO NOT EDIT THIS FILE, instead use visitors +/// to add features, then rerun codama to update it. +/// +/// https://github.com/codama-idl/codama +/// + +import 'dart:typed_data'; +import 'package:solana/encoder.dart'; +import 'package:solana/solana.dart'; +import '../programs.dart'; +import '../shared.dart'; +import '../types/cpi_rule.dart'; +import '../types/metadata_additional_field_rule.dart'; +import '../types/transfer_amount_rule.dart'; + +const List CREATE_GUARD_DISCRIMINATOR = [ + 251, + 254, + 17, + 198, + 219, + 218, + 154, + 99 +]; + +/// Generated instruction class for CreateGuard. +/// + +class CreateGuardInstruction { + // Accounts + // The guard account. + final Ed25519HDPublicKey guard; + + // The mint account. + final Ed25519HDPublicKey mint; + + // The mint_token_account account. + final Ed25519HDPublicKey mint_token_account; + + // The guard_authority account. + final Ed25519HDPublicKey guard_authority; + + // The payer account. + final Ed25519HDPublicKey payer; + + // The associated_token_program account. + final Ed25519HDPublicKey associated_token_program; + + // The token_program account. + final Ed25519HDPublicKey token_program; + + // The system_program account. + final Ed25519HDPublicKey system_program; + + // Args + final String name; + final String symbol; + final String uri; + final CpiRule? cpi_rule; + final TransferAmountRule? transfer_amount_rule; + final List additional_fields_rule; + + CreateGuardInstruction({ + required this.guard, + required this.mint, + required this.mint_token_account, + required this.guard_authority, + required this.payer, + required this.associated_token_program, + required this.token_program, + required this.system_program, + required this.name, + required this.symbol, + required this.uri, + required this.cpi_rule, + required this.transfer_amount_rule, + required this.additional_fields_rule, + }); + + /// Builds the `Instruction` (data = discriminator + args). + Instruction toInstruction({List remainingAccounts = const []}) { + final keys = [ + AccountMeta( + pubKey: guard, + isSigner: false, + isWriteable: true, + ), + AccountMeta( + pubKey: mint, + isSigner: true, + isWriteable: true, + ), + AccountMeta( + pubKey: mint_token_account, + isSigner: false, + isWriteable: true, + ), + AccountMeta( + pubKey: guard_authority, + isSigner: true, + isWriteable: false, + ), + AccountMeta( + pubKey: payer, + isSigner: true, + isWriteable: true, + ), + AccountMeta( + pubKey: associated_token_program, + isSigner: false, + isWriteable: false, + ), + AccountMeta( + pubKey: token_program, + isSigner: false, + isWriteable: false, + ), + AccountMeta( + pubKey: system_program, + isSigner: false, + isWriteable: false, + ), + ]; + + if (remainingAccounts.isNotEmpty) { + keys.addAll(remainingAccounts); + } + + // Serialize: discriminator (8 bytes) + args + final writer = BinaryWriter(); + writer.writeDiscriminator(Uint8List.fromList(CREATE_GUARD_DISCRIMINATOR)); + writer.writeString(name); + + writer.writeString(symbol); + + writer.writeString(uri); + + writer.writeU8(cpi_rule != null ? 1 : 0); + if (cpi_rule != null) { + cpi_rule!.toBorsh(writer); + } + writer.writeU8(transfer_amount_rule != null ? 1 : 0); + if (transfer_amount_rule != null) { + transfer_amount_rule!.toBorsh(writer); + } + writer.writeArray(additional_fields_rule, + (MetadataAdditionalFieldRule item) { + // Each item is a struct + item.toBorsh(writer); + }); + + return Instruction( + programId: WenTransferGuardProgram.programId, + accounts: keys, + data: ByteArray(writer.toBytes()), + ); + } +} diff --git a/e2e/anchor/lib/generated/instructions/execute.dart b/e2e/anchor/lib/generated/instructions/execute.dart new file mode 100644 index 0000000..7f21543 --- /dev/null +++ b/e2e/anchor/lib/generated/instructions/execute.dart @@ -0,0 +1,111 @@ +/// This code was AUTOGENERATED using the codama library. +/// Please DO NOT EDIT THIS FILE, instead use visitors +/// to add features, then rerun codama to update it. +/// +/// https://github.com/codama-idl/codama +/// + +import 'dart:typed_data'; +import 'package:solana/encoder.dart'; +import 'package:solana/solana.dart'; +import '../programs.dart'; +import '../shared.dart'; + +const List EXECUTE_DISCRIMINATOR = [105, 37, 101, 197, 75, 251, 102, 26]; + +/// Generated instruction class for Execute. +/// + +class ExecuteInstruction { + // Accounts + // The source_account account. + final Ed25519HDPublicKey source_account; + + // The mint account. + final Ed25519HDPublicKey mint; + + // The destination_account account. + final Ed25519HDPublicKey destination_account; + + // The owner_delegate account. + final Ed25519HDPublicKey owner_delegate; + + // The extra_metas_account account. + final Ed25519HDPublicKey extra_metas_account; + + // The guard account. + final Ed25519HDPublicKey guard; + + // The instruction_sysvar_account account. + final Ed25519HDPublicKey instruction_sysvar_account; + + // Args + final BigInt /* type: u64 */ amount; + + ExecuteInstruction({ + required this.source_account, + required this.mint, + required this.destination_account, + required this.owner_delegate, + required this.extra_metas_account, + required this.guard, + required this.instruction_sysvar_account, + required this.amount, + }); + + /// Builds the `Instruction` (data = discriminator + args). + Instruction toInstruction({List remainingAccounts = const []}) { + final keys = [ + AccountMeta( + pubKey: source_account, + isSigner: false, + isWriteable: false, + ), + AccountMeta( + pubKey: mint, + isSigner: false, + isWriteable: false, + ), + AccountMeta( + pubKey: destination_account, + isSigner: false, + isWriteable: false, + ), + AccountMeta( + pubKey: owner_delegate, + isSigner: false, + isWriteable: false, + ), + AccountMeta( + pubKey: extra_metas_account, + isSigner: false, + isWriteable: false, + ), + AccountMeta( + pubKey: guard, + isSigner: false, + isWriteable: false, + ), + AccountMeta( + pubKey: instruction_sysvar_account, + isSigner: false, + isWriteable: false, + ), + ]; + + if (remainingAccounts.isNotEmpty) { + keys.addAll(remainingAccounts); + } + + // Serialize: discriminator (8 bytes) + args + final writer = BinaryWriter(); + writer.writeDiscriminator(Uint8List.fromList(EXECUTE_DISCRIMINATOR)); + writer.writeU64(amount); + + return Instruction( + programId: WenTransferGuardProgram.programId, + accounts: keys, + data: ByteArray(writer.toBytes()), + ); + } +} diff --git a/e2e/anchor/lib/generated/instructions/initialize.dart b/e2e/anchor/lib/generated/instructions/initialize.dart new file mode 100644 index 0000000..ffe3780 --- /dev/null +++ b/e2e/anchor/lib/generated/instructions/initialize.dart @@ -0,0 +1,98 @@ +/// This code was AUTOGENERATED using the codama library. +/// Please DO NOT EDIT THIS FILE, instead use visitors +/// to add features, then rerun codama to update it. +/// +/// https://github.com/codama-idl/codama +/// + +import 'dart:typed_data'; +import 'package:solana/encoder.dart'; +import 'package:solana/solana.dart'; +import '../programs.dart'; +import '../shared.dart'; + +const List INITIALIZE_DISCRIMINATOR = [43, 34, 13, 49, 167, 88, 235, 235]; + +/// Generated instruction class for Initialize. +/// + +class InitializeInstruction { + // Accounts + // The extra_metas_account account. + final Ed25519HDPublicKey extra_metas_account; + + // The guard account. + final Ed25519HDPublicKey guard; + + // The mint account. + final Ed25519HDPublicKey mint; + + // The transfer_hook_authority account. + final Ed25519HDPublicKey transfer_hook_authority; + + // The system_program account. + final Ed25519HDPublicKey system_program; + + // The payer account. + final Ed25519HDPublicKey payer; + + // Args + + InitializeInstruction({ + required this.extra_metas_account, + required this.guard, + required this.mint, + required this.transfer_hook_authority, + required this.system_program, + required this.payer, + }); + + /// Builds the `Instruction` (data = discriminator + args). + Instruction toInstruction({List remainingAccounts = const []}) { + final keys = [ + AccountMeta( + pubKey: extra_metas_account, + isSigner: false, + isWriteable: true, + ), + AccountMeta( + pubKey: guard, + isSigner: false, + isWriteable: false, + ), + AccountMeta( + pubKey: mint, + isSigner: false, + isWriteable: false, + ), + AccountMeta( + pubKey: transfer_hook_authority, + isSigner: true, + isWriteable: true, + ), + AccountMeta( + pubKey: system_program, + isSigner: false, + isWriteable: false, + ), + AccountMeta( + pubKey: payer, + isSigner: true, + isWriteable: true, + ), + ]; + + if (remainingAccounts.isNotEmpty) { + keys.addAll(remainingAccounts); + } + + // Serialize: discriminator (8 bytes) + args + final writer = BinaryWriter(); + writer.writeDiscriminator(Uint8List.fromList(INITIALIZE_DISCRIMINATOR)); + return Instruction( + programId: WenTransferGuardProgram.programId, + accounts: keys, + data: ByteArray(writer.toBytes()), + ); + } +} diff --git a/e2e/anchor/lib/generated/instructions/update_guard.dart b/e2e/anchor/lib/generated/instructions/update_guard.dart new file mode 100644 index 0000000..8ade019 --- /dev/null +++ b/e2e/anchor/lib/generated/instructions/update_guard.dart @@ -0,0 +1,130 @@ +/// This code was AUTOGENERATED using the codama library. +/// Please DO NOT EDIT THIS FILE, instead use visitors +/// to add features, then rerun codama to update it. +/// +/// https://github.com/codama-idl/codama +/// + +import 'dart:typed_data'; +import 'package:solana/encoder.dart'; +import 'package:solana/solana.dart'; +import '../programs.dart'; +import '../shared.dart'; +import '../types/cpi_rule.dart'; +import '../types/metadata_additional_field_rule.dart'; +import '../types/transfer_amount_rule.dart'; + +const List UPDATE_GUARD_DISCRIMINATOR = [ + 51, + 38, + 175, + 180, + 25, + 249, + 39, + 24 +]; + +/// Generated instruction class for UpdateGuard. +/// + +class UpdateGuardInstruction { + // Accounts + // The guard account. + final Ed25519HDPublicKey guard; + + // The mint account. + final Ed25519HDPublicKey mint; + + // The token_account account. + final Ed25519HDPublicKey token_account; + + // The guard_authority account. + final Ed25519HDPublicKey guard_authority; + + // The token_program account. + final Ed25519HDPublicKey token_program; + + // The system_program account. + final Ed25519HDPublicKey system_program; + + // Args + final CpiRule? cpi_rule; + final TransferAmountRule? transfer_amount_rule; + final List additional_fields_rule; + + UpdateGuardInstruction({ + required this.guard, + required this.mint, + required this.token_account, + required this.guard_authority, + required this.token_program, + required this.system_program, + required this.cpi_rule, + required this.transfer_amount_rule, + required this.additional_fields_rule, + }); + + /// Builds the `Instruction` (data = discriminator + args). + Instruction toInstruction({List remainingAccounts = const []}) { + final keys = [ + AccountMeta( + pubKey: guard, + isSigner: false, + isWriteable: true, + ), + AccountMeta( + pubKey: mint, + isSigner: false, + isWriteable: false, + ), + AccountMeta( + pubKey: token_account, + isSigner: false, + isWriteable: false, + ), + AccountMeta( + pubKey: guard_authority, + isSigner: true, + isWriteable: false, + ), + AccountMeta( + pubKey: token_program, + isSigner: false, + isWriteable: false, + ), + AccountMeta( + pubKey: system_program, + isSigner: false, + isWriteable: false, + ), + ]; + + if (remainingAccounts.isNotEmpty) { + keys.addAll(remainingAccounts); + } + + // Serialize: discriminator (8 bytes) + args + final writer = BinaryWriter(); + writer.writeDiscriminator(Uint8List.fromList(UPDATE_GUARD_DISCRIMINATOR)); + writer.writeU8(cpi_rule != null ? 1 : 0); + if (cpi_rule != null) { + cpi_rule!.toBorsh(writer); + } + writer.writeU8(transfer_amount_rule != null ? 1 : 0); + if (transfer_amount_rule != null) { + transfer_amount_rule!.toBorsh(writer); + } + writer.writeArray(additional_fields_rule, + (MetadataAdditionalFieldRule item) { + // Each item is a struct + item.toBorsh(writer); + }); + + return Instruction( + programId: WenTransferGuardProgram.programId, + accounts: keys, + data: ByteArray(writer.toBytes()), + ); + } +} diff --git a/e2e/anchor/lib/generated/lib.dart b/e2e/anchor/lib/generated/lib.dart new file mode 100644 index 0000000..1ea8243 --- /dev/null +++ b/e2e/anchor/lib/generated/lib.dart @@ -0,0 +1,19 @@ +/// This code was AUTOGENERATED using the codama library. +/// Please DO NOT EDIT THIS FILE, instead use visitors +/// to add features, then rerun codama to update it. +/// +/// https://github.com/codama-idl/codama +/// + +// Entry point for the SDK. +// This file exports all the modules in the SDK. + +export 'programs.dart'; + +export 'accounts.dart'; + +export 'instructions.dart'; + +export 'types.dart'; + +export 'shared.dart'; diff --git a/e2e/anchor/lib/generated/mod.dart b/e2e/anchor/lib/generated/mod.dart new file mode 100644 index 0000000..1ea8243 --- /dev/null +++ b/e2e/anchor/lib/generated/mod.dart @@ -0,0 +1,19 @@ +/// This code was AUTOGENERATED using the codama library. +/// Please DO NOT EDIT THIS FILE, instead use visitors +/// to add features, then rerun codama to update it. +/// +/// https://github.com/codama-idl/codama +/// + +// Entry point for the SDK. +// This file exports all the modules in the SDK. + +export 'programs.dart'; + +export 'accounts.dart'; + +export 'instructions.dart'; + +export 'types.dart'; + +export 'shared.dart'; diff --git a/e2e/anchor/lib/generated/programs.dart b/e2e/anchor/lib/generated/programs.dart new file mode 100644 index 0000000..a392088 --- /dev/null +++ b/e2e/anchor/lib/generated/programs.dart @@ -0,0 +1,20 @@ +/// This code was AUTOGENERATED using the codama library. +/// Please DO NOT EDIT THIS FILE, instead use visitors +/// to add features, then rerun codama to update it. +/// +/// https://github.com/codama-idl/codama +/// + +// This file exports program information for all programs in the SDK. + +import 'package:solana/solana.dart'; + +/// Program information for the WenTransferGuard program. +class WenTransferGuardProgram { + /// The program ID for the WenTransferGuard program. + static final Ed25519HDPublicKey programId = Ed25519HDPublicKey.fromBase58( + "LockdqYQ9X2kwtWB99ioSbxubAmEi8o9jqYwbXgrrRw"); + + /// The program name. + static const String name = "wenTransferGuard"; +} diff --git a/e2e/anchor/lib/generated/shared.dart b/e2e/anchor/lib/generated/shared.dart new file mode 100644 index 0000000..ef6c923 --- /dev/null +++ b/e2e/anchor/lib/generated/shared.dart @@ -0,0 +1,587 @@ +/// This code was AUTOGENERATED using the codama library. +/// Please DO NOT EDIT THIS FILE, instead use visitors +/// to add features, then rerun codama to update it. +/// +/// https://github.com/codama-idl/codama +/// + +// Shared utilities and types for the SDK. + +import 'dart:convert'; +import 'dart:typed_data'; + +import 'package:solana/solana.dart'; + +/// Account not found error. +class AccountNotFoundError extends Error { + /// The address of the account that was not found. + final Ed25519HDPublicKey address; + + /// Creates a new AccountNotFoundError. + AccountNotFoundError(this.address); + + @override + String toString() => 'Account not found: $address'; +} + +/// Binary reader for decoding Borsh-encoded data. +class BinaryReader { + final ByteData + _data; // holds the raw binary data buffer, that i read from. Represents entire sequence of bytes. + + // Offset tracks the current byte position in the buffer; advance it after each read to ensure correct sequential decoding. + int _offset = 0; + + /// Creates a new BinaryReader. + BinaryReader(this._data); + + Uint8List readDiscriminator() { + final length = 8; // Discriminator is always the first 8 bytes + final bytes = + Uint8List.view(_data.buffer, _data.offsetInBytes + _offset, length); + _offset += length; + return bytes; + } + + /// Reads a single public key (32 raw bytes, no prefix). + Uint8List readPubkey() { + final length = 32; + final bytes = + Uint8List.view(_data.buffer, _data.offsetInBytes + _offset, length); + _offset += length; + return bytes; + } + + /// Reads a boolean value. + bool readBool() { + final value = _data.getUint8(_offset) != 0; + _offset += 1; + return value; + } + + /// Reads a int data type. + int readInt() { + final b0 = _data.getUint8(_offset); + final b1 = _data.getUint8(_offset + 1); + final b2 = _data.getUint8(_offset + 2); + final b3 = _data.getUint8(_offset + 3); + _offset += 4; + return b0 | (b1 << 8) | (b2 << 16) | (b3 << 24); + } + + BigInt readBigInt() { + BigInt result = BigInt.zero; + for (int i = 0; i < 16; i++) { + result |= BigInt.from(_data.getUint8(_offset + i)) << (8 * i); + } + _offset += 16; + return result; + } + + /// Reads an unsigned 8-bit integer. + int readU8() { + final value = _data.getUint8(_offset); + _offset += 1; + return value; + } + + /// Reads an unsigned 16-bit integer. + int readU16() { + final value = _data.getUint16(_offset, Endian.little); + _offset += 2; + return value; + } + + /// Reads an unsigned 32-bit integer. + int readU32() { + final value = _data.getUint32(_offset, Endian.little); + _offset += 4; + return value; + } + + /// Reads an unsigned 64-bit integer. + BigInt readU64() { + final low = _data.getUint32(_offset, Endian.little); + final high = _data.getUint32(_offset + 4, Endian.little); + _offset += 8; + return (BigInt.from(high) << 32) | BigInt.from(low); + } + + /// Reads a signed 8-bit integer. + int readI8() { + final value = _data.getInt8(_offset); + _offset += 1; + return value; + } + + /// Reads a signed 16-bit integer. + int readI16() { + final value = _data.getInt16(_offset, Endian.little); + _offset += 2; + return value; + } + + /// Reads a signed 32-bit integer. + int readI32() { + final value = _data.getInt32(_offset, Endian.little); + _offset += 4; + return value; + } + + /// Reads a signed 64-bit integer. + BigInt readI64() { + final low = _data.getUint32(_offset, Endian.little); + final high = _data.getInt32(_offset + 4, Endian.little); + _offset += 8; + return (BigInt.from(high) << 32) | BigInt.from(low); + } + + /// Reads a string. + String readString() { + final length = readU32(); + final bytes = + Uint8List.view(_data.buffer, _data.offsetInBytes + _offset, length); + _offset += length; + return utf8.decode(bytes); + } + + /// Reads a u8 array from Borsh data. If `length` is null, reads the length from a 4-byte prefix. + Uint8List readU8Array([int? length]) { + if (length == null) { + // Read the 4-byte little-endian length prefix (Borsh Vec) + length = _data.getUint32(_offset, Endian.little); + _offset += 4; + } + + return readAlignedArray( + 1, + length, + Uint8List.view, + 1, + (offset) => _data.getUint8(offset), + ); + } + + /// Reads a fixed-size i8 array of bytes. + Int8List readI8Array([int? length]) { + if (length == null) { + // Read the 4-byte little-endian length prefix (Borsh Vec) + length = _data.getUint32(_offset, Endian.little); + _offset += 4; + } + + return readAlignedArray( + 1, + length, + Int8List.view, + 1, + (offset) => _data.getInt8(offset), + ); + } + + /// Reads a fixed-size u16 array of bytes. + Uint16List readU16Array([int? length]) { + if (length == null) { + // Read the 4-byte little-endian length prefix (Borsh Vec) + length = _data.getUint32(_offset, Endian.little); + _offset += 4; + } + + return readAlignedArray( + 2, + length, + Uint16List.view, + 2, + (offset) => _data.getUint16(offset, Endian.little), + ); + } + + /// Reads a fixed-size i16 array of bytes. + Int16List readI16Array([int? length]) { + if (length == null) { + // Read the 4-byte little-endian length prefix (Borsh Vec) + length = _data.getUint32(_offset, Endian.little); + _offset += 4; + } + + return readAlignedArray( + 2, + length, + Int16List.view, + 2, + (offset) => _data.getInt16(offset, Endian.little), + ); + } + + /// Reads a fixed-size u32 array of bytes. + Uint32List readU32Array([int? length]) { + if (length == null) { + // Read the 4-byte little-endian length prefix (Borsh Vec) + length = _data.getUint32(_offset, Endian.little); + _offset += 4; + } + + return readAlignedArray( + 4, + length, + Uint32List.view, + 4, + (offset) => _data.getUint32(offset, Endian.little), + ); + } + + /// Reads a fixed-size i32 array of bytes. + Int32List readI32Array([int? length]) { + if (length == null) { + // Read the 4-byte little-endian length prefix (Borsh Vec) + length = _data.getUint32(_offset, Endian.little); + _offset += 4; + } + + return readAlignedArray( + 4, + length, + Int32List.view, + 4, + (offset) => _data.getInt32(offset, Endian.little), + ); + } + + /// Reads a fixed-size u64 array of bytes. + Uint64List readU64Array([int? length]) { + if (length == null) { + // Read the 4-byte little-endian length prefix (Borsh Vec) + length = _data.getUint32(_offset, Endian.little); + _offset += 4; + } + + return readAlignedArray( + 8, + length, + Uint64List.view, + 8, + (offset) => _data.getUint64(offset, Endian.little), + ); + } + + /// Reads a fixed-size i64 array of bytes. + Int64List readI64Array([int? length]) { + if (length == null) { + // Read the 4-byte little-endian length prefix (Borsh Vec) + length = _data.getUint32(_offset, Endian.little); + _offset += 4; + } + + return readAlignedArray( + 8, + length, + Int64List.view, + 8, + (offset) => _data.getInt64(offset, Endian.little), + ); + } + + /// Reads a variable-length array of generic items. + List readArray(T Function() itemReader) { + final count = readU32(); + final result = []; + for (var i = 0; i < count; i++) { + result.add(itemReader()); + } + return result; + } + + /// Reads a variable-length array of bytes. + Uint8List readBytes() { + final length = readU32(); + return readU8Array(length); + } + + // ========= Utils for alignment-safe array reading ======== + + // This function handles the problem of buffer's offset that is not properly aligned for typed array views. + // It happens because i have fixed-size and prefixed-size arrays. + T readAlignedArray( + int alignment, + int length, + T Function(ByteBuffer buffer, int offset, int length) viewConstructor, + int bytesPerElement, + int Function(int offset) manualGetter, + ) { + // Check the offset alignment for `Uint*List.view` it should be multiple of element size + if ((_data.offsetInBytes + _offset) % alignment == 0) { + final arr = + viewConstructor(_data.buffer, _data.offsetInBytes + _offset, length); + _offset += length * bytesPerElement; + return arr; + } else { + // Manual read if not aligned + // For example, for Uint16List: + final arr = List.generate(length, (i) { + final value = manualGetter(_offset); + _offset += bytesPerElement; + return value; + }); + // Convert to typed list + if (T == Uint8List) return Uint8List.fromList(arr) as T; + if (T == Uint16List) return Uint16List.fromList(arr) as T; + if (T == Uint32List) return Uint32List.fromList(arr) as T; + if (T == Uint64List) return Uint64List.fromList(arr) as T; + if (T == Int8List) return Int8List.fromList(arr) as T; + if (T == Int16List) return Int16List.fromList(arr) as T; + if (T == Int32List) return Int32List.fromList(arr) as T; + if (T == Int64List) return Int64List.fromList(arr) as T; + // ...add more types as needed + return arr as T; + } + } +} + +/// Binary writer for encoding Borsh data. +class BinaryWriter { + final List _bytes = []; + + void writeDiscriminator(Uint8List discriminator) { + if (discriminator.length != 8) { + throw ArgumentError('Discriminator must be exactly 8 bytes'); + } + _bytes.addAll(discriminator); + } + + /// Writes a boolean value. + void writeBool(bool value) { + _bytes.add(value ? 1 : 0); + } + + void writeInt(int value) { + _bytes.addAll([ + value & 0xFF, + (value >> 8) & 0xFF, + (value >> 16) & 0xFF, + (value >> 24) & 0xFF, + ]); + } + + void writeBigInt(BigInt value) { + for (int i = 0; i < 16; i++) { + _bytes.add(((value >> (8 * i)) & BigInt.from(0xFF)).toInt()); + } + } + + /// Writes an unsigned 8-bit integer. + void writeU8(int value) { + _bytes.add(value & 0xFF); + } + + /// Writes an unsigned 16-bit integer. + void writeU16(int value) { + _bytes.addAll([ + value & 0xFF, + (value >> 8) & 0xFF, + ]); + } + + /// Writes an unsigned 32-bit integer. + void writeU32(int value) { + _bytes.addAll([ + value & 0xFF, + (value >> 8) & 0xFF, + (value >> 16) & 0xFF, + (value >> 24) & 0xFF, + ]); + } + + /// Writes an unsigned 64-bit integer. + void writeU64(BigInt value) { + final low = value & BigInt.from(0xFFFFFFFF); + final high = (value >> 32) & BigInt.from(0xFFFFFFFF); + + _bytes.addAll([ + low.toInt() & 0xFF, + (low.toInt() >> 8) & 0xFF, + (low.toInt() >> 16) & 0xFF, + (low.toInt() >> 24) & 0xFF, + high.toInt() & 0xFF, + (high.toInt() >> 8) & 0xFF, + (high.toInt() >> 16) & 0xFF, + (high.toInt() >> 24) & 0xFF, + ]); + } + + /// Writes a signed 8-bit integer. + void writeI8(int value) { + writeU8(value & 0xFF); + } + + /// Writes a signed 16-bit integer. + void writeI16(int value) { + writeU16(value & 0xFFFF); + } + + /// Writes a signed 32-bit integer. + void writeI32(int value) { + writeU32(value & 0xFFFFFFFF); + } + + /// Writes a signed 64-bit integer. + void writeI64(BigInt value) { + writeU64(value & (BigInt.one << 64) - BigInt.one); + } + + /// Writes a string. + void writeString(String value) { + final bytes = utf8.encode(value); + writeU32(bytes.length); + _bytes.addAll(bytes); + } + + /// Writes a fixed-size and prefixed-size u8 array of bytes. + void writeU8Array(Uint8List value, int? length) { + if (length == null) { + // Variable-length: write length prefix + writeU32(value.length); + for (final v in value) { + writeU8(v); + } + } else { + // Fixed-size: write exactly [length] elements, no prefix + for (int i = 0; i < length; i++) { + writeU8(value[i]); + } + } + } + + /// Writes a fixed-size and prefixed-size u8 array of bytes. + void writeI8Array(Int8List value, int? length) { + if (length == null) { + // Variable-length: write length prefix + writeU32(value.length); + for (final v in value) { + writeI8(v); + } + } else { + // Fixed-size: write exactly [length] elements, no prefix + for (int i = 0; i < length; i++) { + writeI8(value[i]); + } + } + } + + /// Writes a fixed-size and prefixed-size u16 array of bytes. + void writeU16Array(Uint16List value, int? length) { + if (length == null) { + // Variable-length: write length prefix + writeU32(value.length); + for (final v in value) { + writeU16(v); + } + } else { + // Fixed-size: write exactly [length] elements, no prefix + for (int i = 0; i < length; i++) { + writeU16(value[i]); + } + } + } + + /// Writes a fixed-size and prefixed-size i16 array of bytes. + void writeI16Array(Int16List value, int? length) { + if (length == null) { + // Variable-length: write length prefix + writeU32(value.length); + for (final v in value) { + writeI16(v); + } + } else { + // Fixed-size: write exactly [length] elements, no prefix + for (int i = 0; i < length; i++) { + writeI16(value[i]); + } + } + } + + /// Writes a fixed-size and prefixed-size i16 array of bytes. + void writeU32Array(Uint32List value, int? length) { + if (length == null) { + // Variable-length: write length prefix + writeU32(value.length); + for (final v in value) { + writeU32(v); + } + } else { + // Fixed-size: write exactly [length] elements, no prefix + for (int i = 0; i < length; i++) { + writeU32(value[i]); + } + } + } + + /// Writes a fixed-size i32 array of bytes. + void writeI32Array(Int32List value, int? length) { + if (length == null) { + // Variable-length: write length prefix + writeU32(value.length); + for (final v in value) { + writeI32(v); + } + } else { + // Fixed-size: write exactly [length] elements, no prefix + for (int i = 0; i < length; i++) { + writeI32(value[i]); + } + } + } + + /// Writes a fixed-size u64 array of bytes. + void writeU64Array(Uint64List value, int? length) { + if (length == null) { + // Variable-length: write length prefix + writeU32(value.length); + for (final v in value) { + writeU64(BigInt.from(v)); + } + } else { + // Fixed-size: write exactly [length] elements, no prefix + for (int i = 0; i < length; i++) { + writeU64(BigInt.from(value[i])); + } + } + } + + /// Writes a fixed-size i64 array of bytes. + void writeI64Array(Int64List value, int? length) { + if (length == null) { + // Variable-length: write length prefix + writeU32(value.length); + for (final v in value) { + writeI64(BigInt.from(v)); + } + } else { + // Fixed-size: write exactly [length] elements, no prefix + for (int i = 0; i < length; i++) { + writeI64(BigInt.from(value[i])); + } + } + } + + /// Writes a variable-length array of bytes. + void writeBytes(Uint8List value) { + writeU32(value.length); + _bytes.addAll(value); + } + + /// Writes a variable-length array of generic items. + void writeArray(List items, void Function(T) itemWriter) { + writeU32(items.length); + for (final item in items) { + itemWriter(item); + } + } + + /// Writes a single public key (32 raw bytes, no prefix). + void writePubkey(Uint8List pubkeyBytes) { + _bytes.addAll(pubkeyBytes); + } + + /// Returns the byte array. + Uint8List toBytes() => Uint8List.fromList(_bytes); +} diff --git a/e2e/anchor/lib/generated/types.dart b/e2e/anchor/lib/generated/types.dart new file mode 100644 index 0000000..1a323b5 --- /dev/null +++ b/e2e/anchor/lib/generated/types.dart @@ -0,0 +1,13 @@ +/// This code was AUTOGENERATED using the codama library. +/// Please DO NOT EDIT THIS FILE, instead use visitors +/// to add features, then rerun codama to update it. +/// +/// https://github.com/codama-idl/codama +/// + +// This file exports custom data types for the SDK. + +export 'types/cpi_rule.dart'; +export 'types/metadata_additional_field_restriction.dart'; +export 'types/metadata_additional_field_rule.dart'; +export 'types/transfer_amount_rule.dart'; diff --git a/e2e/anchor/lib/generated/types/cpi_rule.dart b/e2e/anchor/lib/generated/types/cpi_rule.dart new file mode 100644 index 0000000..4b978d4 --- /dev/null +++ b/e2e/anchor/lib/generated/types/cpi_rule.dart @@ -0,0 +1,72 @@ +/// This code was AUTOGENERATED using the codama library. +/// Please DO NOT EDIT THIS FILE, instead use visitors +/// to add features, then rerun codama to update it. +/// +/// https://github.com/codama-idl/codama +/// + +import 'dart:typed_data'; +import 'package:solana/solana.dart'; +import '../shared.dart'; + +/// Generated type definition for CpiRule. +/// +/// Controls which protocols can interact with the token by +/// enforcing Allow and Deny lists. + +abstract class CpiRule {} + +class Allow extends CpiRule { + final List value0; + + Allow(this.value0); +} + +class Deny extends CpiRule { + final List value0; + + Deny(this.value0); +} + +/// Extension providing serialization methods for CpiRule. +/// +extension CpiRuleBorsh on CpiRule { + /// Converts the enum to a byte representation. + void toBorsh(BinaryWriter writer) { + if (this is Allow) { + final v = this as Allow; + + writer.writeArray(v.value0, + (Ed25519HDPublicKey item) { + writer.writePubkey(Uint8List.fromList(item.bytes)); + ; + }); + } + if (this is Deny) { + final v = this as Deny; + + writer.writeArray(v.value0, + (Ed25519HDPublicKey item) { + writer.writePubkey(Uint8List.fromList(item.bytes)); + ; + }); + } + } + + /// Creates an enum from a byte representation. + static CpiRule fromBorsh(BinaryReader reader) { + final variant = reader.readU8(); + switch (variant) { + case 0: + return Allow(reader.readArray(() { + return Ed25519HDPublicKey(reader.readPubkey()); + })); + case 1: + return Deny(reader.readArray(() { + return Ed25519HDPublicKey(reader.readPubkey()); + })); + default: + throw Exception('Unknown cpiRule variant: $variant'); + } + } +} diff --git a/e2e/anchor/lib/generated/types/metadata_additional_field_restriction.dart b/e2e/anchor/lib/generated/types/metadata_additional_field_restriction.dart new file mode 100644 index 0000000..b2ed4fe --- /dev/null +++ b/e2e/anchor/lib/generated/types/metadata_additional_field_restriction.dart @@ -0,0 +1,72 @@ +/// This code was AUTOGENERATED using the codama library. +/// Please DO NOT EDIT THIS FILE, instead use visitors +/// to add features, then rerun codama to update it. +/// +/// https://github.com/codama-idl/codama +/// + +import 'dart:typed_data'; +import '../shared.dart'; + +/// Generated type definition for MetadataAdditionalFieldRestriction. +/// +/// Inner enum for the MetadataAdditionalFieldRestriction enum. +/// * Includes - The field must include one of the values in the vector. +/// * Excludes - The field must not include any of the values in the vector. + +abstract class MetadataAdditionalFieldRestriction {} + +class Includes extends MetadataAdditionalFieldRestriction { + final List value0; + + Includes(this.value0); +} + +class Excludes extends MetadataAdditionalFieldRestriction { + final List value0; + + Excludes(this.value0); +} + +/// Extension providing serialization methods for MetadataAdditionalFieldRestriction. +/// +extension MetadataAdditionalFieldRestrictionBorsh + on MetadataAdditionalFieldRestriction { + /// Converts the enum to a byte representation. + void toBorsh(BinaryWriter writer) { + if (this is Includes) { + final v = this as Includes; + + writer.writeArray(v.value0, (String item) { + writer.writeString(item); + ; + }); + } + if (this is Excludes) { + final v = this as Excludes; + + writer.writeArray(v.value0, (String item) { + writer.writeString(item); + ; + }); + } + } + + /// Creates an enum from a byte representation. + static MetadataAdditionalFieldRestriction fromBorsh(BinaryReader reader) { + final variant = reader.readU8(); + switch (variant) { + case 0: + return Includes(reader.readArray(() { + return reader.readString(); + })); + case 1: + return Excludes(reader.readArray(() { + return reader.readString(); + })); + default: + throw Exception( + 'Unknown metadataAdditionalFieldRestriction variant: $variant'); + } + } +} diff --git a/e2e/anchor/lib/generated/types/metadata_additional_field_rule.dart b/e2e/anchor/lib/generated/types/metadata_additional_field_rule.dart new file mode 100644 index 0000000..973246b --- /dev/null +++ b/e2e/anchor/lib/generated/types/metadata_additional_field_rule.dart @@ -0,0 +1,49 @@ +/// This code was AUTOGENERATED using the codama library. +/// Please DO NOT EDIT THIS FILE, instead use visitors +/// to add features, then rerun codama to update it. +/// +/// https://github.com/codama-idl/codama +/// + +import 'dart:typed_data'; +import '../shared.dart'; +import '../types/metadata_additional_field_restriction.dart'; + +/// Generated type definition for MetadataAdditionalFieldRule. +/// +/// Enforces rules on a single additional field in the mint metadata. +/// The field must exist and the value must pass the restriction. + +class MetadataAdditionalFieldRule { + final String field; + final MetadataAdditionalFieldRestriction? value_restrictions; + + MetadataAdditionalFieldRule({ + required this.field, + required this.value_restrictions, + }); +} + +/// Extension providing serialization methods for MetadataAdditionalFieldRule. +/// +extension MetadataAdditionalFieldRuleBorsh on MetadataAdditionalFieldRule { + /// Serializes the struct to its byte representation. + void toBorsh(BinaryWriter writer) { + writer.writeString(field); + + writer.writeU8(value_restrictions != null ? 1 : 0); + if (value_restrictions != null) { + value_restrictions!.toBorsh(writer); + } + } + + /// Creates a struct from its byte representation. + static MetadataAdditionalFieldRule fromBorsh(BinaryReader reader) { + return MetadataAdditionalFieldRule( + field: reader.readString(), + value_restrictions: reader.readU8() == 1 + ? MetadataAdditionalFieldRestrictionBorsh.fromBorsh(reader) + : null, + ); + } +} diff --git a/e2e/anchor/lib/generated/types/transfer_amount_rule.dart b/e2e/anchor/lib/generated/types/transfer_amount_rule.dart new file mode 100644 index 0000000..1a7c748 --- /dev/null +++ b/e2e/anchor/lib/generated/types/transfer_amount_rule.dart @@ -0,0 +1,88 @@ +/// This code was AUTOGENERATED using the codama library. +/// Please DO NOT EDIT THIS FILE, instead use visitors +/// to add features, then rerun codama to update it. +/// +/// https://github.com/codama-idl/codama +/// + +import 'dart:typed_data'; +import '../shared.dart'; + +/// Generated type definition for TransferAmountRule. +/// +/// Enforces rules on the amount of tokens being transferred. +/// The rules can be above, below, equal to, or within a range. + +abstract class TransferAmountRule {} + +class Above extends TransferAmountRule { + final BigInt /* type: u64 */ value0; + + Above(this.value0); +} + +class Below extends TransferAmountRule { + final BigInt /* type: u64 */ value0; + + Below(this.value0); +} + +class Equal extends TransferAmountRule { + final BigInt /* type: u64 */ value0; + + Equal(this.value0); +} + +class Rang extends TransferAmountRule { + final BigInt /* type: u64 */ value0; + final BigInt /* type: u64 */ value1; + + Rang(this.value0, this.value1); +} + +/// Extension providing serialization methods for TransferAmountRule. +/// +extension TransferAmountRuleBorsh on TransferAmountRule { + /// Converts the enum to a byte representation. + void toBorsh(BinaryWriter writer) { + if (this is Above) { + final v = this as Above; + + writer.writeU64(v.value0); + } + if (this is Below) { + final v = this as Below; + + writer.writeU64(v.value0); + } + if (this is Equal) { + final v = this as Equal; + + writer.writeU64(v.value0); + } + if (this is Rang) { + final v = this as Rang; + + writer.writeU64(v.value0); + + writer.writeU64(v.value1); + } + } + + /// Creates an enum from a byte representation. + static TransferAmountRule fromBorsh(BinaryReader reader) { + final variant = reader.readU8(); + switch (variant) { + case 0: + return Above(reader.readU64()); + case 1: + return Below(reader.readU64()); + case 2: + return Equal(reader.readU64()); + case 3: + return Rang(reader.readU64(), reader.readU64()); + default: + throw Exception('Unknown transferAmountRule variant: $variant'); + } + } +} diff --git a/e2e/anchor/pubspec.lock b/e2e/anchor/pubspec.lock new file mode 100644 index 0000000..86d9781 --- /dev/null +++ b/e2e/anchor/pubspec.lock @@ -0,0 +1,261 @@ +# Generated by pub +# See https://dart.dev/tools/pub/glossary#lockfile +packages: + async: + dependency: transitive + description: + name: async + sha256: "758e6d74e971c3e5aceb4110bfd6698efc7f501675bcfe0c775459a8140750eb" + url: "https://pub.dev" + source: hosted + version: "2.13.0" + bip39: + dependency: transitive + description: + name: bip39 + sha256: de1ee27ebe7d96b84bb3a04a4132a0a3007dcdd5ad27dd14aa87a29d97c45edc + url: "https://pub.dev" + source: hosted + version: "1.0.6" + borsh_annotation: + dependency: transitive + description: + name: borsh_annotation + sha256: dc73a7fdc6fe4505535657daf8ab3cebe382311fae63a0faaf9315ea1bc30bff + url: "https://pub.dev" + source: hosted + version: "0.3.2" + clock: + dependency: transitive + description: + name: clock + sha256: fddb70d9b5277016c77a80201021d40a2247104d9f4aa7bab7157b7e3f05b84b + url: "https://pub.dev" + source: hosted + version: "1.1.2" + collection: + dependency: transitive + description: + name: collection + sha256: "2f5709ae4d3d59dd8f7cd309b4e023046b57d8a6c82130785d2b0e5868084e76" + url: "https://pub.dev" + source: hosted + version: "1.19.1" + convert: + dependency: transitive + description: + name: convert + sha256: b30acd5944035672bc15c6b7a8b47d773e41e2f17de064350988c5d02adb1c68 + url: "https://pub.dev" + source: hosted + version: "3.1.2" + crypto: + dependency: transitive + description: + name: crypto + sha256: "1e445881f28f22d6140f181e07737b22f1e099a5e1ff94b0af2f9e4a463f4855" + url: "https://pub.dev" + source: hosted + version: "3.0.6" + cryptography: + dependency: transitive + description: + name: cryptography + sha256: d146b76d33d94548cf035233fbc2f4338c1242fa119013bead807d033fc4ae05 + url: "https://pub.dev" + source: hosted + version: "2.7.0" + decimal: + dependency: transitive + description: + name: decimal + sha256: fc706a5618b81e5b367b01dd62621def37abc096f2b46a9bd9068b64c1fa36d0 + url: "https://pub.dev" + source: hosted + version: "3.2.4" + ed25519_hd_key: + dependency: transitive + description: + name: ed25519_hd_key + sha256: "31e191ec97492873067e46dc9cc0c7d55170559c83a478400feffa0627acaccf" + url: "https://pub.dev" + source: hosted + version: "2.3.0" + ffi: + dependency: transitive + description: + name: ffi + sha256: "289279317b4b16eb2bb7e271abccd4bf84ec9bdcbe999e278a94b804f5630418" + url: "https://pub.dev" + source: hosted + version: "2.1.4" + freezed_annotation: + dependency: transitive + description: + name: freezed_annotation + sha256: c2e2d632dd9b8a2b7751117abcfc2b4888ecfe181bd9fca7170d9ef02e595fe2 + url: "https://pub.dev" + source: hosted + version: "2.4.4" + hex: + dependency: transitive + description: + name: hex + sha256: "4e7cd54e4b59ba026432a6be2dd9d96e4c5205725194997193bf871703b82c4a" + url: "https://pub.dev" + source: hosted + version: "0.2.0" + http: + dependency: transitive + description: + name: http + sha256: bb2ce4590bc2667c96f318d68cac1b5a7987ec819351d32b1c987239a815e007 + url: "https://pub.dev" + source: hosted + version: "1.5.0" + http_parser: + dependency: transitive + description: + name: http_parser + sha256: "178d74305e7866013777bab2c3d8726205dc5a4dd935297175b19a23a2e66571" + url: "https://pub.dev" + source: hosted + version: "4.1.2" + intl: + dependency: transitive + description: + name: intl + sha256: "3df61194eb431efc39c4ceba583b95633a403f46c9fd341e550ce0bfa50e9aa5" + url: "https://pub.dev" + source: hosted + version: "0.20.2" + js: + dependency: transitive + description: + name: js + sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3 + url: "https://pub.dev" + source: hosted + version: "0.6.7" + json_annotation: + dependency: transitive + description: + name: json_annotation + sha256: "1ce844379ca14835a50d2f019a3099f419082cfdd231cd86a142af94dd5c6bb1" + url: "https://pub.dev" + source: hosted + version: "4.9.0" + meta: + dependency: transitive + description: + name: meta + sha256: "23f08335362185a5ea2ad3a4e597f1375e78bce8a040df5c600c8d3552ef2394" + url: "https://pub.dev" + source: hosted + version: "1.17.0" + path: + dependency: transitive + description: + name: path + sha256: "75cca69d1490965be98c73ceaea117e8a04dd21217b37b292c9ddbec0d955bc5" + url: "https://pub.dev" + source: hosted + version: "1.9.1" + pinenacl: + dependency: transitive + description: + name: pinenacl + sha256: "57e907beaacbc3c024a098910b6240758e899674de07d6949a67b52fd984cbdf" + url: "https://pub.dev" + source: hosted + version: "0.6.0" + pointycastle: + dependency: transitive + description: + name: pointycastle + sha256: "4be0097fcf3fd3e8449e53730c631200ebc7b88016acecab2b0da2f0149222fe" + url: "https://pub.dev" + source: hosted + version: "3.9.1" + rational: + dependency: transitive + description: + name: rational + sha256: cb808fb6f1a839e6fc5f7d8cb3b0a10e1db48b3be102de73938c627f0b636336 + url: "https://pub.dev" + source: hosted + version: "2.2.3" + solana: + dependency: "direct main" + description: + name: solana + sha256: "98d8780dbd9af7e90ff14a6e762a45d77466450304773610317d1fffdea09701" + url: "https://pub.dev" + source: hosted + version: "0.31.2+1" + source_span: + dependency: transitive + description: + name: source_span + sha256: "254ee5351d6cb365c859e20ee823c3bb479bf4a293c22d17a9f1bf144ce86f7c" + url: "https://pub.dev" + source: hosted + version: "1.10.1" + stream_channel: + dependency: transitive + description: + name: stream_channel + sha256: "969e04c80b8bcdf826f8f16579c7b14d780458bd97f56d107d3950fdbeef059d" + url: "https://pub.dev" + source: hosted + version: "2.1.4" + string_scanner: + dependency: transitive + description: + name: string_scanner + sha256: "921cd31725b72fe181906c6a94d987c78e3b98c2e205b397ea399d4054872b43" + url: "https://pub.dev" + source: hosted + version: "1.4.1" + term_glyph: + dependency: transitive + description: + name: term_glyph + sha256: "7f554798625ea768a7518313e58f83891c7f5024f88e46e7182a4558850a4b8e" + url: "https://pub.dev" + source: hosted + version: "1.2.2" + typed_data: + dependency: transitive + description: + name: typed_data + sha256: f9049c039ebfeb4cf7a7104a675823cd72dba8297f264b6637062516699fa006 + url: "https://pub.dev" + source: hosted + version: "1.4.0" + web: + dependency: transitive + description: + name: web + sha256: "868d88a33d8a87b18ffc05f9f030ba328ffefba92d6c127917a2ba740f9cfe4a" + url: "https://pub.dev" + source: hosted + version: "1.1.1" + web_socket: + dependency: transitive + description: + name: web_socket + sha256: "34d64019aa8e36bf9842ac014bb5d2f5586ca73df5e4d9bf5c936975cae6982c" + url: "https://pub.dev" + source: hosted + version: "1.0.1" + web_socket_channel: + dependency: transitive + description: + name: web_socket_channel + sha256: d645757fb0f4773d602444000a8131ff5d48c9e47adfe9772652dd1a4f2d45c8 + url: "https://pub.dev" + source: hosted + version: "3.0.3" +sdks: + dart: ">=3.7.0 <4.0.0" diff --git a/e2e/anchor/pubspec.yaml b/e2e/anchor/pubspec.yaml new file mode 100644 index 0000000..570caaf --- /dev/null +++ b/e2e/anchor/pubspec.yaml @@ -0,0 +1,7 @@ +name: anchor +description: anchor project for e2e generated Dart code +version: 0.1.0 +environment: + sdk: '>=2.17.0 <4.0.0' +dependencies: + solana: ^0.31.2+1 \ No newline at end of file diff --git a/e2e/anchor/src/generated/accounts.dart b/e2e/anchor/src/generated/accounts.dart new file mode 100644 index 0000000..98c8416 --- /dev/null +++ b/e2e/anchor/src/generated/accounts.dart @@ -0,0 +1,10 @@ +/// This code was AUTOGENERATED using the codama library. +/// Please DO NOT EDIT THIS FILE, instead use visitors +/// to add features, then rerun codama to update it. +/// +/// https://github.com/codama-idl/codama +/// + +// This file exports account classes for all accounts in the SDK. + +export 'accounts/guard_v1.dart'; diff --git a/e2e/anchor/src/generated/accounts/guard_v1.dart b/e2e/anchor/src/generated/accounts/guard_v1.dart new file mode 100644 index 0000000..722c577 --- /dev/null +++ b/e2e/anchor/src/generated/accounts/guard_v1.dart @@ -0,0 +1,137 @@ +/// This code was AUTOGENERATED using the codama library. +/// Please DO NOT EDIT THIS FILE, instead use visitors +/// to add features, then rerun codama to update it. +/// +/// https://github.com/codama-idl/codama +/// + +import 'dart:typed_data'; +import 'package:collection/collection.dart'; +import 'package:solana/dto.dart'; +import 'package:solana/solana.dart'; +import '../shared.dart'; +import '../types/cpi_rule.dart'; +import '../types/metadata_additional_field_rule.dart'; +import '../types/transfer_amount_rule.dart'; + +const List GUARD_V1_DISCRIMINATOR = [185, 149, 156, 78, 245, 108, 172, 68]; + +/// Generated account class for GuardV1. +/// +class GuardV1 { + // Fields + final Ed25519HDPublicKey mint; + final int /* type: u8 */ bump; + final CpiRule? cpi_rule; + final TransferAmountRule? transfer_amount_rule; + final List additional_fields_rule; + + // Constructor + GuardV1({ + required this.mint, + required this.bump, + required this.cpi_rule, + required this.transfer_amount_rule, + required this.additional_fields_rule, + }); + + /// Deserializes this account from borsh. + static GuardV1 fromBorsh(BinaryReader reader) { + return GuardV1( + mint: Ed25519HDPublicKey(reader.readPubkey()), + bump: reader.readU8(), + cpi_rule: reader.readU8() == 1 ? CpiRuleBorsh.fromBorsh(reader) : null, + transfer_amount_rule: reader.readU8() == 1 + ? TransferAmountRuleBorsh.fromBorsh(reader) + : null, + additional_fields_rule: reader.readArray(() { + // item is a struct, call fromBorsh per item + return MetadataAdditionalFieldRuleBorsh.fromBorsh(reader); + }), + ); + } + + /// Serializes this account to borsh. + void toBorsh(BinaryWriter writer) { + writer.writePubkey(Uint8List.fromList(mint.bytes)); + + writer.writeU8(bump); + + writer.writeU8(cpi_rule != null ? 1 : 0); + if (cpi_rule != null) { + cpi_rule!.toBorsh(writer); + } + writer.writeU8(transfer_amount_rule != null ? 1 : 0); + if (transfer_amount_rule != null) { + transfer_amount_rule!.toBorsh(writer); + } + writer.writeArray(additional_fields_rule, + (MetadataAdditionalFieldRule item) { + // Each item is a struct + item.toBorsh(writer); + }); + } + + /// Creates a [GuardV1] from its bytes representation. + static GuardV1 fromBytes(Uint8List data) { + final buffer = ByteData.view(data.buffer); + final reader = BinaryReader(buffer); + + // Validate the discriminator + final discriminator = reader.readDiscriminator(); + if (!const ListEquality().equals(discriminator, GUARD_V1_DISCRIMINATOR)) { + throw FormatException('Invalid account discriminator'); + } + + return GuardV1.fromBorsh(reader); + } + + /// Serializes this account to its bytes representation. + Uint8List toBytes() { + final writer = BinaryWriter(); + + // Write discriminator + writer.writeDiscriminator(Uint8List.fromList(GUARD_V1_DISCRIMINATOR)); + + // Write account data + toBorsh(writer); + + return writer.toBytes(); + } + + /// Fetches a [GuardV1] from the blockchain. + static Future fetch( + RpcClient client, + Ed25519HDPublicKey address, + ) async { + final accountInfo = await client.getAccountInfo(address.toBase58(), + encoding: Encoding.base64); + final data = accountInfo.value?.data; + + if (data == null) { + throw AccountNotFoundError(address); + } + + if (data is! BinaryAccountData) { + throw FormatException( + 'Expected binary account data, got ${data.runtimeType}'); + } + + return fromBytes(Uint8List.fromList(data.data)); + } + + /// Fetches a [GuardV1] from the blockchain if it exists. + static Future fetchNullable( + RpcClient client, + Ed25519HDPublicKey address, + ) async { + try { + return await fetch(client, address); + } catch (e) { + if (e is AccountNotFoundError) { + return null; + } + rethrow; + } + } +} diff --git a/e2e/anchor/src/generated/errors.dart b/e2e/anchor/src/generated/errors.dart new file mode 100644 index 0000000..a105376 --- /dev/null +++ b/e2e/anchor/src/generated/errors.dart @@ -0,0 +1,8 @@ +/// This code was AUTOGENERATED using the codama library. +/// Please DO NOT EDIT THIS FILE, instead use visitors +/// to add features, then rerun codama to update it. +/// +/// https://github.com/codama-idl/codama +/// + +// This file exports error classes for all programs in the SDK. diff --git a/e2e/anchor/src/generated/errors/wen_transfer_guard.dart b/e2e/anchor/src/generated/errors/wen_transfer_guard.dart new file mode 100644 index 0000000..1e633ed --- /dev/null +++ b/e2e/anchor/src/generated/errors/wen_transfer_guard.dart @@ -0,0 +1,161 @@ +/// This code was AUTOGENERATED using the codama library. +/// Please DO NOT EDIT THIS FILE, instead use visitors +/// to add features, then rerun codama to update it. +/// +/// https://github.com/codama-idl/codama +/// + +/// Error codes for the WenTransferGuard program. +class WenTransferGuardErrorCode { + /// Cpi Rule Enforcement Failed + static const int CpiRuleEnforcementFailed = 0x1770; + + /// Transfer Amount Rule Enforce Failed + static const int TransferAmountRuleEnforceFailed = 0x1771; + + /// Metadata Field Does Not Exist + static const int MetadataFieldDoesNotExist = 0x1772; + + /// Metadata Field Does Not Pass + static const int MetadataFieldDoesNotPass = 0x1773; + + /// Guard token amount should be at least 1 + static const int GuardTokenAmountShouldBeAtLeastOne = 0x1774; + + /// Not owned by token 2022 program + static const int NotOwnedByToken2022Program = 0x1775; + + /// Must be initialized by Transfer Hook Authority + static const int MustBeInitializedByTransferHookAuthority = 0x1776; + + /// Mints assigned Transfer Hook Program is not this one + static const int MintAssignedTransferHookProgramIsNotThisOne = 0x1777; +} + +/// Base class for all WenTransferGuard program errors. +abstract class WenTransferGuardError extends Error { + /// The numerical error code. + final int code; + + /// Human-readable error message. + final String message; + + /// Creates a new WenTransferGuardError. + WenTransferGuardError(this.code, this.message); + + /// Creates a WenTransferGuardError from a raw error code. + static WenTransferGuardError fromCode(int code) { + switch (code) { + case WenTransferGuardErrorCode.CpiRuleEnforcementFailed: + return CpiRuleEnforcementFailedError(); + case WenTransferGuardErrorCode.TransferAmountRuleEnforceFailed: + return TransferAmountRuleEnforceFailedError(); + case WenTransferGuardErrorCode.MetadataFieldDoesNotExist: + return MetadataFieldDoesNotExistError(); + case WenTransferGuardErrorCode.MetadataFieldDoesNotPass: + return MetadataFieldDoesNotPassError(); + case WenTransferGuardErrorCode.GuardTokenAmountShouldBeAtLeastOne: + return GuardTokenAmountShouldBeAtLeastOneError(); + case WenTransferGuardErrorCode.NotOwnedByToken2022Program: + return NotOwnedByToken2022ProgramError(); + case WenTransferGuardErrorCode.MustBeInitializedByTransferHookAuthority: + return MustBeInitializedByTransferHookAuthorityError(); + case WenTransferGuardErrorCode + .MintAssignedTransferHookProgramIsNotThisOne: + return MintAssignedTransferHookProgramIsNotThisOneError(); + default: + return UnknownError(code); + } + } + + @override + String toString() => '$runtimeType: [$code] $message'; +} + +/// Represents an unknown error from the WenTransferGuard program. +class UnknownError extends WenTransferGuardError { + /// Creates a new UnknownError. + UnknownError(int code) : super(code, 'Unknown error'); +} + +/// Cpi Rule Enforcement Failed +class CpiRuleEnforcementFailedError extends WenTransferGuardError { + /// Creates a new CpiRuleEnforcementFailedError. + CpiRuleEnforcementFailedError() + : super( + WenTransferGuardErrorCode.CpiRuleEnforcementFailed, + 'Cpi Rule Enforcement Failed', + ); +} + +/// Transfer Amount Rule Enforce Failed +class TransferAmountRuleEnforceFailedError extends WenTransferGuardError { + /// Creates a new TransferAmountRuleEnforceFailedError. + TransferAmountRuleEnforceFailedError() + : super( + WenTransferGuardErrorCode.TransferAmountRuleEnforceFailed, + 'Transfer Amount Rule Enforce Failed', + ); +} + +/// Metadata Field Does Not Exist +class MetadataFieldDoesNotExistError extends WenTransferGuardError { + /// Creates a new MetadataFieldDoesNotExistError. + MetadataFieldDoesNotExistError() + : super( + WenTransferGuardErrorCode.MetadataFieldDoesNotExist, + 'Metadata Field Does Not Exist', + ); +} + +/// Metadata Field Does Not Pass +class MetadataFieldDoesNotPassError extends WenTransferGuardError { + /// Creates a new MetadataFieldDoesNotPassError. + MetadataFieldDoesNotPassError() + : super( + WenTransferGuardErrorCode.MetadataFieldDoesNotPass, + 'Metadata Field Does Not Pass', + ); +} + +/// Guard token amount should be at least 1 +class GuardTokenAmountShouldBeAtLeastOneError extends WenTransferGuardError { + /// Creates a new GuardTokenAmountShouldBeAtLeastOneError. + GuardTokenAmountShouldBeAtLeastOneError() + : super( + WenTransferGuardErrorCode.GuardTokenAmountShouldBeAtLeastOne, + 'Guard token amount should be at least 1', + ); +} + +/// Not owned by token 2022 program +class NotOwnedByToken2022ProgramError extends WenTransferGuardError { + /// Creates a new NotOwnedByToken2022ProgramError. + NotOwnedByToken2022ProgramError() + : super( + WenTransferGuardErrorCode.NotOwnedByToken2022Program, + 'Not owned by token 2022 program', + ); +} + +/// Must be initialized by Transfer Hook Authority +class MustBeInitializedByTransferHookAuthorityError + extends WenTransferGuardError { + /// Creates a new MustBeInitializedByTransferHookAuthorityError. + MustBeInitializedByTransferHookAuthorityError() + : super( + WenTransferGuardErrorCode.MustBeInitializedByTransferHookAuthority, + 'Must be initialized by Transfer Hook Authority', + ); +} + +/// Mints assigned Transfer Hook Program is not this one +class MintAssignedTransferHookProgramIsNotThisOneError + extends WenTransferGuardError { + /// Creates a new MintAssignedTransferHookProgramIsNotThisOneError. + MintAssignedTransferHookProgramIsNotThisOneError() + : super( + WenTransferGuardErrorCode.MintAssignedTransferHookProgramIsNotThisOne, + 'Mints assigned Transfer Hook Program is not this one', + ); +} diff --git a/e2e/anchor/src/generated/instructions.dart b/e2e/anchor/src/generated/instructions.dart new file mode 100644 index 0000000..f9d3900 --- /dev/null +++ b/e2e/anchor/src/generated/instructions.dart @@ -0,0 +1,13 @@ +/// This code was AUTOGENERATED using the codama library. +/// Please DO NOT EDIT THIS FILE, instead use visitors +/// to add features, then rerun codama to update it. +/// +/// https://github.com/codama-idl/codama +/// + +// This file exports instruction classes for all instructions in the SDK. + +export 'instructions/create_guard.dart'; +export 'instructions/execute.dart'; +export 'instructions/initialize.dart'; +export 'instructions/update_guard.dart'; diff --git a/e2e/anchor/src/generated/instructions/create_guard.dart b/e2e/anchor/src/generated/instructions/create_guard.dart new file mode 100644 index 0000000..c8e7046 --- /dev/null +++ b/e2e/anchor/src/generated/instructions/create_guard.dart @@ -0,0 +1,160 @@ +/// This code was AUTOGENERATED using the codama library. +/// Please DO NOT EDIT THIS FILE, instead use visitors +/// to add features, then rerun codama to update it. +/// +/// https://github.com/codama-idl/codama +/// + +import 'dart:typed_data'; +import 'package:solana/encoder.dart'; +import 'package:solana/solana.dart'; +import '../programs.dart'; +import '../shared.dart'; +import '../types/cpi_rule.dart'; +import '../types/metadata_additional_field_rule.dart'; +import '../types/transfer_amount_rule.dart'; + +const List CREATE_GUARD_DISCRIMINATOR = [ + 251, + 254, + 17, + 198, + 219, + 218, + 154, + 99 +]; + +/// Generated instruction class for CreateGuard. +/// + +class CreateGuardInstruction { + // Accounts + // The guard account. + final Ed25519HDPublicKey guard; + + // The mint account. + final Ed25519HDPublicKey mint; + + // The mint_token_account account. + final Ed25519HDPublicKey mint_token_account; + + // The guard_authority account. + final Ed25519HDPublicKey guard_authority; + + // The payer account. + final Ed25519HDPublicKey payer; + + // The associated_token_program account. + final Ed25519HDPublicKey associated_token_program; + + // The token_program account. + final Ed25519HDPublicKey token_program; + + // The system_program account. + final Ed25519HDPublicKey system_program; + + // Args + final String name; + final String symbol; + final String uri; + final CpiRule? cpi_rule; + final TransferAmountRule? transfer_amount_rule; + final List additional_fields_rule; + + CreateGuardInstruction({ + required this.guard, + required this.mint, + required this.mint_token_account, + required this.guard_authority, + required this.payer, + required this.associated_token_program, + required this.token_program, + required this.system_program, + required this.name, + required this.symbol, + required this.uri, + required this.cpi_rule, + required this.transfer_amount_rule, + required this.additional_fields_rule, + }); + + /// Builds the `Instruction` (data = discriminator + args). + Instruction toInstruction({List remainingAccounts = const []}) { + final keys = [ + AccountMeta( + pubKey: guard, + isSigner: false, + isWriteable: true, + ), + AccountMeta( + pubKey: mint, + isSigner: true, + isWriteable: true, + ), + AccountMeta( + pubKey: mint_token_account, + isSigner: false, + isWriteable: true, + ), + AccountMeta( + pubKey: guard_authority, + isSigner: true, + isWriteable: false, + ), + AccountMeta( + pubKey: payer, + isSigner: true, + isWriteable: true, + ), + AccountMeta( + pubKey: associated_token_program, + isSigner: false, + isWriteable: false, + ), + AccountMeta( + pubKey: token_program, + isSigner: false, + isWriteable: false, + ), + AccountMeta( + pubKey: system_program, + isSigner: false, + isWriteable: false, + ), + ]; + + if (remainingAccounts.isNotEmpty) { + keys.addAll(remainingAccounts); + } + + // Serialize: discriminator (8 bytes) + args + final writer = BinaryWriter(); + writer.writeDiscriminator(Uint8List.fromList(CREATE_GUARD_DISCRIMINATOR)); + writer.writeString(name); + + writer.writeString(symbol); + + writer.writeString(uri); + + writer.writeU8(cpi_rule != null ? 1 : 0); + if (cpi_rule != null) { + cpi_rule!.toBorsh(writer); + } + writer.writeU8(transfer_amount_rule != null ? 1 : 0); + if (transfer_amount_rule != null) { + transfer_amount_rule!.toBorsh(writer); + } + writer.writeArray(additional_fields_rule, + (MetadataAdditionalFieldRule item) { + // Each item is a struct + item.toBorsh(writer); + }); + + return Instruction( + programId: WenTransferGuardProgram.programId, + accounts: keys, + data: ByteArray(writer.toBytes()), + ); + } +} diff --git a/e2e/anchor/src/generated/instructions/execute.dart b/e2e/anchor/src/generated/instructions/execute.dart new file mode 100644 index 0000000..7f21543 --- /dev/null +++ b/e2e/anchor/src/generated/instructions/execute.dart @@ -0,0 +1,111 @@ +/// This code was AUTOGENERATED using the codama library. +/// Please DO NOT EDIT THIS FILE, instead use visitors +/// to add features, then rerun codama to update it. +/// +/// https://github.com/codama-idl/codama +/// + +import 'dart:typed_data'; +import 'package:solana/encoder.dart'; +import 'package:solana/solana.dart'; +import '../programs.dart'; +import '../shared.dart'; + +const List EXECUTE_DISCRIMINATOR = [105, 37, 101, 197, 75, 251, 102, 26]; + +/// Generated instruction class for Execute. +/// + +class ExecuteInstruction { + // Accounts + // The source_account account. + final Ed25519HDPublicKey source_account; + + // The mint account. + final Ed25519HDPublicKey mint; + + // The destination_account account. + final Ed25519HDPublicKey destination_account; + + // The owner_delegate account. + final Ed25519HDPublicKey owner_delegate; + + // The extra_metas_account account. + final Ed25519HDPublicKey extra_metas_account; + + // The guard account. + final Ed25519HDPublicKey guard; + + // The instruction_sysvar_account account. + final Ed25519HDPublicKey instruction_sysvar_account; + + // Args + final BigInt /* type: u64 */ amount; + + ExecuteInstruction({ + required this.source_account, + required this.mint, + required this.destination_account, + required this.owner_delegate, + required this.extra_metas_account, + required this.guard, + required this.instruction_sysvar_account, + required this.amount, + }); + + /// Builds the `Instruction` (data = discriminator + args). + Instruction toInstruction({List remainingAccounts = const []}) { + final keys = [ + AccountMeta( + pubKey: source_account, + isSigner: false, + isWriteable: false, + ), + AccountMeta( + pubKey: mint, + isSigner: false, + isWriteable: false, + ), + AccountMeta( + pubKey: destination_account, + isSigner: false, + isWriteable: false, + ), + AccountMeta( + pubKey: owner_delegate, + isSigner: false, + isWriteable: false, + ), + AccountMeta( + pubKey: extra_metas_account, + isSigner: false, + isWriteable: false, + ), + AccountMeta( + pubKey: guard, + isSigner: false, + isWriteable: false, + ), + AccountMeta( + pubKey: instruction_sysvar_account, + isSigner: false, + isWriteable: false, + ), + ]; + + if (remainingAccounts.isNotEmpty) { + keys.addAll(remainingAccounts); + } + + // Serialize: discriminator (8 bytes) + args + final writer = BinaryWriter(); + writer.writeDiscriminator(Uint8List.fromList(EXECUTE_DISCRIMINATOR)); + writer.writeU64(amount); + + return Instruction( + programId: WenTransferGuardProgram.programId, + accounts: keys, + data: ByteArray(writer.toBytes()), + ); + } +} diff --git a/e2e/anchor/src/generated/instructions/initialize.dart b/e2e/anchor/src/generated/instructions/initialize.dart new file mode 100644 index 0000000..ffe3780 --- /dev/null +++ b/e2e/anchor/src/generated/instructions/initialize.dart @@ -0,0 +1,98 @@ +/// This code was AUTOGENERATED using the codama library. +/// Please DO NOT EDIT THIS FILE, instead use visitors +/// to add features, then rerun codama to update it. +/// +/// https://github.com/codama-idl/codama +/// + +import 'dart:typed_data'; +import 'package:solana/encoder.dart'; +import 'package:solana/solana.dart'; +import '../programs.dart'; +import '../shared.dart'; + +const List INITIALIZE_DISCRIMINATOR = [43, 34, 13, 49, 167, 88, 235, 235]; + +/// Generated instruction class for Initialize. +/// + +class InitializeInstruction { + // Accounts + // The extra_metas_account account. + final Ed25519HDPublicKey extra_metas_account; + + // The guard account. + final Ed25519HDPublicKey guard; + + // The mint account. + final Ed25519HDPublicKey mint; + + // The transfer_hook_authority account. + final Ed25519HDPublicKey transfer_hook_authority; + + // The system_program account. + final Ed25519HDPublicKey system_program; + + // The payer account. + final Ed25519HDPublicKey payer; + + // Args + + InitializeInstruction({ + required this.extra_metas_account, + required this.guard, + required this.mint, + required this.transfer_hook_authority, + required this.system_program, + required this.payer, + }); + + /// Builds the `Instruction` (data = discriminator + args). + Instruction toInstruction({List remainingAccounts = const []}) { + final keys = [ + AccountMeta( + pubKey: extra_metas_account, + isSigner: false, + isWriteable: true, + ), + AccountMeta( + pubKey: guard, + isSigner: false, + isWriteable: false, + ), + AccountMeta( + pubKey: mint, + isSigner: false, + isWriteable: false, + ), + AccountMeta( + pubKey: transfer_hook_authority, + isSigner: true, + isWriteable: true, + ), + AccountMeta( + pubKey: system_program, + isSigner: false, + isWriteable: false, + ), + AccountMeta( + pubKey: payer, + isSigner: true, + isWriteable: true, + ), + ]; + + if (remainingAccounts.isNotEmpty) { + keys.addAll(remainingAccounts); + } + + // Serialize: discriminator (8 bytes) + args + final writer = BinaryWriter(); + writer.writeDiscriminator(Uint8List.fromList(INITIALIZE_DISCRIMINATOR)); + return Instruction( + programId: WenTransferGuardProgram.programId, + accounts: keys, + data: ByteArray(writer.toBytes()), + ); + } +} diff --git a/e2e/anchor/src/generated/instructions/update_guard.dart b/e2e/anchor/src/generated/instructions/update_guard.dart new file mode 100644 index 0000000..8ade019 --- /dev/null +++ b/e2e/anchor/src/generated/instructions/update_guard.dart @@ -0,0 +1,130 @@ +/// This code was AUTOGENERATED using the codama library. +/// Please DO NOT EDIT THIS FILE, instead use visitors +/// to add features, then rerun codama to update it. +/// +/// https://github.com/codama-idl/codama +/// + +import 'dart:typed_data'; +import 'package:solana/encoder.dart'; +import 'package:solana/solana.dart'; +import '../programs.dart'; +import '../shared.dart'; +import '../types/cpi_rule.dart'; +import '../types/metadata_additional_field_rule.dart'; +import '../types/transfer_amount_rule.dart'; + +const List UPDATE_GUARD_DISCRIMINATOR = [ + 51, + 38, + 175, + 180, + 25, + 249, + 39, + 24 +]; + +/// Generated instruction class for UpdateGuard. +/// + +class UpdateGuardInstruction { + // Accounts + // The guard account. + final Ed25519HDPublicKey guard; + + // The mint account. + final Ed25519HDPublicKey mint; + + // The token_account account. + final Ed25519HDPublicKey token_account; + + // The guard_authority account. + final Ed25519HDPublicKey guard_authority; + + // The token_program account. + final Ed25519HDPublicKey token_program; + + // The system_program account. + final Ed25519HDPublicKey system_program; + + // Args + final CpiRule? cpi_rule; + final TransferAmountRule? transfer_amount_rule; + final List additional_fields_rule; + + UpdateGuardInstruction({ + required this.guard, + required this.mint, + required this.token_account, + required this.guard_authority, + required this.token_program, + required this.system_program, + required this.cpi_rule, + required this.transfer_amount_rule, + required this.additional_fields_rule, + }); + + /// Builds the `Instruction` (data = discriminator + args). + Instruction toInstruction({List remainingAccounts = const []}) { + final keys = [ + AccountMeta( + pubKey: guard, + isSigner: false, + isWriteable: true, + ), + AccountMeta( + pubKey: mint, + isSigner: false, + isWriteable: false, + ), + AccountMeta( + pubKey: token_account, + isSigner: false, + isWriteable: false, + ), + AccountMeta( + pubKey: guard_authority, + isSigner: true, + isWriteable: false, + ), + AccountMeta( + pubKey: token_program, + isSigner: false, + isWriteable: false, + ), + AccountMeta( + pubKey: system_program, + isSigner: false, + isWriteable: false, + ), + ]; + + if (remainingAccounts.isNotEmpty) { + keys.addAll(remainingAccounts); + } + + // Serialize: discriminator (8 bytes) + args + final writer = BinaryWriter(); + writer.writeDiscriminator(Uint8List.fromList(UPDATE_GUARD_DISCRIMINATOR)); + writer.writeU8(cpi_rule != null ? 1 : 0); + if (cpi_rule != null) { + cpi_rule!.toBorsh(writer); + } + writer.writeU8(transfer_amount_rule != null ? 1 : 0); + if (transfer_amount_rule != null) { + transfer_amount_rule!.toBorsh(writer); + } + writer.writeArray(additional_fields_rule, + (MetadataAdditionalFieldRule item) { + // Each item is a struct + item.toBorsh(writer); + }); + + return Instruction( + programId: WenTransferGuardProgram.programId, + accounts: keys, + data: ByteArray(writer.toBytes()), + ); + } +} diff --git a/e2e/anchor/src/generated/lib.dart b/e2e/anchor/src/generated/lib.dart new file mode 100644 index 0000000..1ea8243 --- /dev/null +++ b/e2e/anchor/src/generated/lib.dart @@ -0,0 +1,19 @@ +/// This code was AUTOGENERATED using the codama library. +/// Please DO NOT EDIT THIS FILE, instead use visitors +/// to add features, then rerun codama to update it. +/// +/// https://github.com/codama-idl/codama +/// + +// Entry point for the SDK. +// This file exports all the modules in the SDK. + +export 'programs.dart'; + +export 'accounts.dart'; + +export 'instructions.dart'; + +export 'types.dart'; + +export 'shared.dart'; diff --git a/e2e/anchor/src/generated/mod.dart b/e2e/anchor/src/generated/mod.dart new file mode 100644 index 0000000..1ea8243 --- /dev/null +++ b/e2e/anchor/src/generated/mod.dart @@ -0,0 +1,19 @@ +/// This code was AUTOGENERATED using the codama library. +/// Please DO NOT EDIT THIS FILE, instead use visitors +/// to add features, then rerun codama to update it. +/// +/// https://github.com/codama-idl/codama +/// + +// Entry point for the SDK. +// This file exports all the modules in the SDK. + +export 'programs.dart'; + +export 'accounts.dart'; + +export 'instructions.dart'; + +export 'types.dart'; + +export 'shared.dart'; diff --git a/e2e/anchor/src/generated/programs.dart b/e2e/anchor/src/generated/programs.dart new file mode 100644 index 0000000..a392088 --- /dev/null +++ b/e2e/anchor/src/generated/programs.dart @@ -0,0 +1,20 @@ +/// This code was AUTOGENERATED using the codama library. +/// Please DO NOT EDIT THIS FILE, instead use visitors +/// to add features, then rerun codama to update it. +/// +/// https://github.com/codama-idl/codama +/// + +// This file exports program information for all programs in the SDK. + +import 'package:solana/solana.dart'; + +/// Program information for the WenTransferGuard program. +class WenTransferGuardProgram { + /// The program ID for the WenTransferGuard program. + static final Ed25519HDPublicKey programId = Ed25519HDPublicKey.fromBase58( + "LockdqYQ9X2kwtWB99ioSbxubAmEi8o9jqYwbXgrrRw"); + + /// The program name. + static const String name = "wenTransferGuard"; +} diff --git a/e2e/anchor/src/generated/shared.dart b/e2e/anchor/src/generated/shared.dart new file mode 100644 index 0000000..ef6c923 --- /dev/null +++ b/e2e/anchor/src/generated/shared.dart @@ -0,0 +1,587 @@ +/// This code was AUTOGENERATED using the codama library. +/// Please DO NOT EDIT THIS FILE, instead use visitors +/// to add features, then rerun codama to update it. +/// +/// https://github.com/codama-idl/codama +/// + +// Shared utilities and types for the SDK. + +import 'dart:convert'; +import 'dart:typed_data'; + +import 'package:solana/solana.dart'; + +/// Account not found error. +class AccountNotFoundError extends Error { + /// The address of the account that was not found. + final Ed25519HDPublicKey address; + + /// Creates a new AccountNotFoundError. + AccountNotFoundError(this.address); + + @override + String toString() => 'Account not found: $address'; +} + +/// Binary reader for decoding Borsh-encoded data. +class BinaryReader { + final ByteData + _data; // holds the raw binary data buffer, that i read from. Represents entire sequence of bytes. + + // Offset tracks the current byte position in the buffer; advance it after each read to ensure correct sequential decoding. + int _offset = 0; + + /// Creates a new BinaryReader. + BinaryReader(this._data); + + Uint8List readDiscriminator() { + final length = 8; // Discriminator is always the first 8 bytes + final bytes = + Uint8List.view(_data.buffer, _data.offsetInBytes + _offset, length); + _offset += length; + return bytes; + } + + /// Reads a single public key (32 raw bytes, no prefix). + Uint8List readPubkey() { + final length = 32; + final bytes = + Uint8List.view(_data.buffer, _data.offsetInBytes + _offset, length); + _offset += length; + return bytes; + } + + /// Reads a boolean value. + bool readBool() { + final value = _data.getUint8(_offset) != 0; + _offset += 1; + return value; + } + + /// Reads a int data type. + int readInt() { + final b0 = _data.getUint8(_offset); + final b1 = _data.getUint8(_offset + 1); + final b2 = _data.getUint8(_offset + 2); + final b3 = _data.getUint8(_offset + 3); + _offset += 4; + return b0 | (b1 << 8) | (b2 << 16) | (b3 << 24); + } + + BigInt readBigInt() { + BigInt result = BigInt.zero; + for (int i = 0; i < 16; i++) { + result |= BigInt.from(_data.getUint8(_offset + i)) << (8 * i); + } + _offset += 16; + return result; + } + + /// Reads an unsigned 8-bit integer. + int readU8() { + final value = _data.getUint8(_offset); + _offset += 1; + return value; + } + + /// Reads an unsigned 16-bit integer. + int readU16() { + final value = _data.getUint16(_offset, Endian.little); + _offset += 2; + return value; + } + + /// Reads an unsigned 32-bit integer. + int readU32() { + final value = _data.getUint32(_offset, Endian.little); + _offset += 4; + return value; + } + + /// Reads an unsigned 64-bit integer. + BigInt readU64() { + final low = _data.getUint32(_offset, Endian.little); + final high = _data.getUint32(_offset + 4, Endian.little); + _offset += 8; + return (BigInt.from(high) << 32) | BigInt.from(low); + } + + /// Reads a signed 8-bit integer. + int readI8() { + final value = _data.getInt8(_offset); + _offset += 1; + return value; + } + + /// Reads a signed 16-bit integer. + int readI16() { + final value = _data.getInt16(_offset, Endian.little); + _offset += 2; + return value; + } + + /// Reads a signed 32-bit integer. + int readI32() { + final value = _data.getInt32(_offset, Endian.little); + _offset += 4; + return value; + } + + /// Reads a signed 64-bit integer. + BigInt readI64() { + final low = _data.getUint32(_offset, Endian.little); + final high = _data.getInt32(_offset + 4, Endian.little); + _offset += 8; + return (BigInt.from(high) << 32) | BigInt.from(low); + } + + /// Reads a string. + String readString() { + final length = readU32(); + final bytes = + Uint8List.view(_data.buffer, _data.offsetInBytes + _offset, length); + _offset += length; + return utf8.decode(bytes); + } + + /// Reads a u8 array from Borsh data. If `length` is null, reads the length from a 4-byte prefix. + Uint8List readU8Array([int? length]) { + if (length == null) { + // Read the 4-byte little-endian length prefix (Borsh Vec) + length = _data.getUint32(_offset, Endian.little); + _offset += 4; + } + + return readAlignedArray( + 1, + length, + Uint8List.view, + 1, + (offset) => _data.getUint8(offset), + ); + } + + /// Reads a fixed-size i8 array of bytes. + Int8List readI8Array([int? length]) { + if (length == null) { + // Read the 4-byte little-endian length prefix (Borsh Vec) + length = _data.getUint32(_offset, Endian.little); + _offset += 4; + } + + return readAlignedArray( + 1, + length, + Int8List.view, + 1, + (offset) => _data.getInt8(offset), + ); + } + + /// Reads a fixed-size u16 array of bytes. + Uint16List readU16Array([int? length]) { + if (length == null) { + // Read the 4-byte little-endian length prefix (Borsh Vec) + length = _data.getUint32(_offset, Endian.little); + _offset += 4; + } + + return readAlignedArray( + 2, + length, + Uint16List.view, + 2, + (offset) => _data.getUint16(offset, Endian.little), + ); + } + + /// Reads a fixed-size i16 array of bytes. + Int16List readI16Array([int? length]) { + if (length == null) { + // Read the 4-byte little-endian length prefix (Borsh Vec) + length = _data.getUint32(_offset, Endian.little); + _offset += 4; + } + + return readAlignedArray( + 2, + length, + Int16List.view, + 2, + (offset) => _data.getInt16(offset, Endian.little), + ); + } + + /// Reads a fixed-size u32 array of bytes. + Uint32List readU32Array([int? length]) { + if (length == null) { + // Read the 4-byte little-endian length prefix (Borsh Vec) + length = _data.getUint32(_offset, Endian.little); + _offset += 4; + } + + return readAlignedArray( + 4, + length, + Uint32List.view, + 4, + (offset) => _data.getUint32(offset, Endian.little), + ); + } + + /// Reads a fixed-size i32 array of bytes. + Int32List readI32Array([int? length]) { + if (length == null) { + // Read the 4-byte little-endian length prefix (Borsh Vec) + length = _data.getUint32(_offset, Endian.little); + _offset += 4; + } + + return readAlignedArray( + 4, + length, + Int32List.view, + 4, + (offset) => _data.getInt32(offset, Endian.little), + ); + } + + /// Reads a fixed-size u64 array of bytes. + Uint64List readU64Array([int? length]) { + if (length == null) { + // Read the 4-byte little-endian length prefix (Borsh Vec) + length = _data.getUint32(_offset, Endian.little); + _offset += 4; + } + + return readAlignedArray( + 8, + length, + Uint64List.view, + 8, + (offset) => _data.getUint64(offset, Endian.little), + ); + } + + /// Reads a fixed-size i64 array of bytes. + Int64List readI64Array([int? length]) { + if (length == null) { + // Read the 4-byte little-endian length prefix (Borsh Vec) + length = _data.getUint32(_offset, Endian.little); + _offset += 4; + } + + return readAlignedArray( + 8, + length, + Int64List.view, + 8, + (offset) => _data.getInt64(offset, Endian.little), + ); + } + + /// Reads a variable-length array of generic items. + List readArray(T Function() itemReader) { + final count = readU32(); + final result = []; + for (var i = 0; i < count; i++) { + result.add(itemReader()); + } + return result; + } + + /// Reads a variable-length array of bytes. + Uint8List readBytes() { + final length = readU32(); + return readU8Array(length); + } + + // ========= Utils for alignment-safe array reading ======== + + // This function handles the problem of buffer's offset that is not properly aligned for typed array views. + // It happens because i have fixed-size and prefixed-size arrays. + T readAlignedArray( + int alignment, + int length, + T Function(ByteBuffer buffer, int offset, int length) viewConstructor, + int bytesPerElement, + int Function(int offset) manualGetter, + ) { + // Check the offset alignment for `Uint*List.view` it should be multiple of element size + if ((_data.offsetInBytes + _offset) % alignment == 0) { + final arr = + viewConstructor(_data.buffer, _data.offsetInBytes + _offset, length); + _offset += length * bytesPerElement; + return arr; + } else { + // Manual read if not aligned + // For example, for Uint16List: + final arr = List.generate(length, (i) { + final value = manualGetter(_offset); + _offset += bytesPerElement; + return value; + }); + // Convert to typed list + if (T == Uint8List) return Uint8List.fromList(arr) as T; + if (T == Uint16List) return Uint16List.fromList(arr) as T; + if (T == Uint32List) return Uint32List.fromList(arr) as T; + if (T == Uint64List) return Uint64List.fromList(arr) as T; + if (T == Int8List) return Int8List.fromList(arr) as T; + if (T == Int16List) return Int16List.fromList(arr) as T; + if (T == Int32List) return Int32List.fromList(arr) as T; + if (T == Int64List) return Int64List.fromList(arr) as T; + // ...add more types as needed + return arr as T; + } + } +} + +/// Binary writer for encoding Borsh data. +class BinaryWriter { + final List _bytes = []; + + void writeDiscriminator(Uint8List discriminator) { + if (discriminator.length != 8) { + throw ArgumentError('Discriminator must be exactly 8 bytes'); + } + _bytes.addAll(discriminator); + } + + /// Writes a boolean value. + void writeBool(bool value) { + _bytes.add(value ? 1 : 0); + } + + void writeInt(int value) { + _bytes.addAll([ + value & 0xFF, + (value >> 8) & 0xFF, + (value >> 16) & 0xFF, + (value >> 24) & 0xFF, + ]); + } + + void writeBigInt(BigInt value) { + for (int i = 0; i < 16; i++) { + _bytes.add(((value >> (8 * i)) & BigInt.from(0xFF)).toInt()); + } + } + + /// Writes an unsigned 8-bit integer. + void writeU8(int value) { + _bytes.add(value & 0xFF); + } + + /// Writes an unsigned 16-bit integer. + void writeU16(int value) { + _bytes.addAll([ + value & 0xFF, + (value >> 8) & 0xFF, + ]); + } + + /// Writes an unsigned 32-bit integer. + void writeU32(int value) { + _bytes.addAll([ + value & 0xFF, + (value >> 8) & 0xFF, + (value >> 16) & 0xFF, + (value >> 24) & 0xFF, + ]); + } + + /// Writes an unsigned 64-bit integer. + void writeU64(BigInt value) { + final low = value & BigInt.from(0xFFFFFFFF); + final high = (value >> 32) & BigInt.from(0xFFFFFFFF); + + _bytes.addAll([ + low.toInt() & 0xFF, + (low.toInt() >> 8) & 0xFF, + (low.toInt() >> 16) & 0xFF, + (low.toInt() >> 24) & 0xFF, + high.toInt() & 0xFF, + (high.toInt() >> 8) & 0xFF, + (high.toInt() >> 16) & 0xFF, + (high.toInt() >> 24) & 0xFF, + ]); + } + + /// Writes a signed 8-bit integer. + void writeI8(int value) { + writeU8(value & 0xFF); + } + + /// Writes a signed 16-bit integer. + void writeI16(int value) { + writeU16(value & 0xFFFF); + } + + /// Writes a signed 32-bit integer. + void writeI32(int value) { + writeU32(value & 0xFFFFFFFF); + } + + /// Writes a signed 64-bit integer. + void writeI64(BigInt value) { + writeU64(value & (BigInt.one << 64) - BigInt.one); + } + + /// Writes a string. + void writeString(String value) { + final bytes = utf8.encode(value); + writeU32(bytes.length); + _bytes.addAll(bytes); + } + + /// Writes a fixed-size and prefixed-size u8 array of bytes. + void writeU8Array(Uint8List value, int? length) { + if (length == null) { + // Variable-length: write length prefix + writeU32(value.length); + for (final v in value) { + writeU8(v); + } + } else { + // Fixed-size: write exactly [length] elements, no prefix + for (int i = 0; i < length; i++) { + writeU8(value[i]); + } + } + } + + /// Writes a fixed-size and prefixed-size u8 array of bytes. + void writeI8Array(Int8List value, int? length) { + if (length == null) { + // Variable-length: write length prefix + writeU32(value.length); + for (final v in value) { + writeI8(v); + } + } else { + // Fixed-size: write exactly [length] elements, no prefix + for (int i = 0; i < length; i++) { + writeI8(value[i]); + } + } + } + + /// Writes a fixed-size and prefixed-size u16 array of bytes. + void writeU16Array(Uint16List value, int? length) { + if (length == null) { + // Variable-length: write length prefix + writeU32(value.length); + for (final v in value) { + writeU16(v); + } + } else { + // Fixed-size: write exactly [length] elements, no prefix + for (int i = 0; i < length; i++) { + writeU16(value[i]); + } + } + } + + /// Writes a fixed-size and prefixed-size i16 array of bytes. + void writeI16Array(Int16List value, int? length) { + if (length == null) { + // Variable-length: write length prefix + writeU32(value.length); + for (final v in value) { + writeI16(v); + } + } else { + // Fixed-size: write exactly [length] elements, no prefix + for (int i = 0; i < length; i++) { + writeI16(value[i]); + } + } + } + + /// Writes a fixed-size and prefixed-size i16 array of bytes. + void writeU32Array(Uint32List value, int? length) { + if (length == null) { + // Variable-length: write length prefix + writeU32(value.length); + for (final v in value) { + writeU32(v); + } + } else { + // Fixed-size: write exactly [length] elements, no prefix + for (int i = 0; i < length; i++) { + writeU32(value[i]); + } + } + } + + /// Writes a fixed-size i32 array of bytes. + void writeI32Array(Int32List value, int? length) { + if (length == null) { + // Variable-length: write length prefix + writeU32(value.length); + for (final v in value) { + writeI32(v); + } + } else { + // Fixed-size: write exactly [length] elements, no prefix + for (int i = 0; i < length; i++) { + writeI32(value[i]); + } + } + } + + /// Writes a fixed-size u64 array of bytes. + void writeU64Array(Uint64List value, int? length) { + if (length == null) { + // Variable-length: write length prefix + writeU32(value.length); + for (final v in value) { + writeU64(BigInt.from(v)); + } + } else { + // Fixed-size: write exactly [length] elements, no prefix + for (int i = 0; i < length; i++) { + writeU64(BigInt.from(value[i])); + } + } + } + + /// Writes a fixed-size i64 array of bytes. + void writeI64Array(Int64List value, int? length) { + if (length == null) { + // Variable-length: write length prefix + writeU32(value.length); + for (final v in value) { + writeI64(BigInt.from(v)); + } + } else { + // Fixed-size: write exactly [length] elements, no prefix + for (int i = 0; i < length; i++) { + writeI64(BigInt.from(value[i])); + } + } + } + + /// Writes a variable-length array of bytes. + void writeBytes(Uint8List value) { + writeU32(value.length); + _bytes.addAll(value); + } + + /// Writes a variable-length array of generic items. + void writeArray(List items, void Function(T) itemWriter) { + writeU32(items.length); + for (final item in items) { + itemWriter(item); + } + } + + /// Writes a single public key (32 raw bytes, no prefix). + void writePubkey(Uint8List pubkeyBytes) { + _bytes.addAll(pubkeyBytes); + } + + /// Returns the byte array. + Uint8List toBytes() => Uint8List.fromList(_bytes); +} diff --git a/e2e/anchor/src/generated/types.dart b/e2e/anchor/src/generated/types.dart new file mode 100644 index 0000000..1a323b5 --- /dev/null +++ b/e2e/anchor/src/generated/types.dart @@ -0,0 +1,13 @@ +/// This code was AUTOGENERATED using the codama library. +/// Please DO NOT EDIT THIS FILE, instead use visitors +/// to add features, then rerun codama to update it. +/// +/// https://github.com/codama-idl/codama +/// + +// This file exports custom data types for the SDK. + +export 'types/cpi_rule.dart'; +export 'types/metadata_additional_field_restriction.dart'; +export 'types/metadata_additional_field_rule.dart'; +export 'types/transfer_amount_rule.dart'; diff --git a/e2e/anchor/src/generated/types/cpi_rule.dart b/e2e/anchor/src/generated/types/cpi_rule.dart new file mode 100644 index 0000000..4b978d4 --- /dev/null +++ b/e2e/anchor/src/generated/types/cpi_rule.dart @@ -0,0 +1,72 @@ +/// This code was AUTOGENERATED using the codama library. +/// Please DO NOT EDIT THIS FILE, instead use visitors +/// to add features, then rerun codama to update it. +/// +/// https://github.com/codama-idl/codama +/// + +import 'dart:typed_data'; +import 'package:solana/solana.dart'; +import '../shared.dart'; + +/// Generated type definition for CpiRule. +/// +/// Controls which protocols can interact with the token by +/// enforcing Allow and Deny lists. + +abstract class CpiRule {} + +class Allow extends CpiRule { + final List value0; + + Allow(this.value0); +} + +class Deny extends CpiRule { + final List value0; + + Deny(this.value0); +} + +/// Extension providing serialization methods for CpiRule. +/// +extension CpiRuleBorsh on CpiRule { + /// Converts the enum to a byte representation. + void toBorsh(BinaryWriter writer) { + if (this is Allow) { + final v = this as Allow; + + writer.writeArray(v.value0, + (Ed25519HDPublicKey item) { + writer.writePubkey(Uint8List.fromList(item.bytes)); + ; + }); + } + if (this is Deny) { + final v = this as Deny; + + writer.writeArray(v.value0, + (Ed25519HDPublicKey item) { + writer.writePubkey(Uint8List.fromList(item.bytes)); + ; + }); + } + } + + /// Creates an enum from a byte representation. + static CpiRule fromBorsh(BinaryReader reader) { + final variant = reader.readU8(); + switch (variant) { + case 0: + return Allow(reader.readArray(() { + return Ed25519HDPublicKey(reader.readPubkey()); + })); + case 1: + return Deny(reader.readArray(() { + return Ed25519HDPublicKey(reader.readPubkey()); + })); + default: + throw Exception('Unknown cpiRule variant: $variant'); + } + } +} diff --git a/e2e/anchor/src/generated/types/metadata_additional_field_restriction.dart b/e2e/anchor/src/generated/types/metadata_additional_field_restriction.dart new file mode 100644 index 0000000..b2ed4fe --- /dev/null +++ b/e2e/anchor/src/generated/types/metadata_additional_field_restriction.dart @@ -0,0 +1,72 @@ +/// This code was AUTOGENERATED using the codama library. +/// Please DO NOT EDIT THIS FILE, instead use visitors +/// to add features, then rerun codama to update it. +/// +/// https://github.com/codama-idl/codama +/// + +import 'dart:typed_data'; +import '../shared.dart'; + +/// Generated type definition for MetadataAdditionalFieldRestriction. +/// +/// Inner enum for the MetadataAdditionalFieldRestriction enum. +/// * Includes - The field must include one of the values in the vector. +/// * Excludes - The field must not include any of the values in the vector. + +abstract class MetadataAdditionalFieldRestriction {} + +class Includes extends MetadataAdditionalFieldRestriction { + final List value0; + + Includes(this.value0); +} + +class Excludes extends MetadataAdditionalFieldRestriction { + final List value0; + + Excludes(this.value0); +} + +/// Extension providing serialization methods for MetadataAdditionalFieldRestriction. +/// +extension MetadataAdditionalFieldRestrictionBorsh + on MetadataAdditionalFieldRestriction { + /// Converts the enum to a byte representation. + void toBorsh(BinaryWriter writer) { + if (this is Includes) { + final v = this as Includes; + + writer.writeArray(v.value0, (String item) { + writer.writeString(item); + ; + }); + } + if (this is Excludes) { + final v = this as Excludes; + + writer.writeArray(v.value0, (String item) { + writer.writeString(item); + ; + }); + } + } + + /// Creates an enum from a byte representation. + static MetadataAdditionalFieldRestriction fromBorsh(BinaryReader reader) { + final variant = reader.readU8(); + switch (variant) { + case 0: + return Includes(reader.readArray(() { + return reader.readString(); + })); + case 1: + return Excludes(reader.readArray(() { + return reader.readString(); + })); + default: + throw Exception( + 'Unknown metadataAdditionalFieldRestriction variant: $variant'); + } + } +} diff --git a/e2e/anchor/src/generated/types/metadata_additional_field_rule.dart b/e2e/anchor/src/generated/types/metadata_additional_field_rule.dart new file mode 100644 index 0000000..973246b --- /dev/null +++ b/e2e/anchor/src/generated/types/metadata_additional_field_rule.dart @@ -0,0 +1,49 @@ +/// This code was AUTOGENERATED using the codama library. +/// Please DO NOT EDIT THIS FILE, instead use visitors +/// to add features, then rerun codama to update it. +/// +/// https://github.com/codama-idl/codama +/// + +import 'dart:typed_data'; +import '../shared.dart'; +import '../types/metadata_additional_field_restriction.dart'; + +/// Generated type definition for MetadataAdditionalFieldRule. +/// +/// Enforces rules on a single additional field in the mint metadata. +/// The field must exist and the value must pass the restriction. + +class MetadataAdditionalFieldRule { + final String field; + final MetadataAdditionalFieldRestriction? value_restrictions; + + MetadataAdditionalFieldRule({ + required this.field, + required this.value_restrictions, + }); +} + +/// Extension providing serialization methods for MetadataAdditionalFieldRule. +/// +extension MetadataAdditionalFieldRuleBorsh on MetadataAdditionalFieldRule { + /// Serializes the struct to its byte representation. + void toBorsh(BinaryWriter writer) { + writer.writeString(field); + + writer.writeU8(value_restrictions != null ? 1 : 0); + if (value_restrictions != null) { + value_restrictions!.toBorsh(writer); + } + } + + /// Creates a struct from its byte representation. + static MetadataAdditionalFieldRule fromBorsh(BinaryReader reader) { + return MetadataAdditionalFieldRule( + field: reader.readString(), + value_restrictions: reader.readU8() == 1 + ? MetadataAdditionalFieldRestrictionBorsh.fromBorsh(reader) + : null, + ); + } +} diff --git a/e2e/anchor/src/generated/types/transfer_amount_rule.dart b/e2e/anchor/src/generated/types/transfer_amount_rule.dart new file mode 100644 index 0000000..1a7c748 --- /dev/null +++ b/e2e/anchor/src/generated/types/transfer_amount_rule.dart @@ -0,0 +1,88 @@ +/// This code was AUTOGENERATED using the codama library. +/// Please DO NOT EDIT THIS FILE, instead use visitors +/// to add features, then rerun codama to update it. +/// +/// https://github.com/codama-idl/codama +/// + +import 'dart:typed_data'; +import '../shared.dart'; + +/// Generated type definition for TransferAmountRule. +/// +/// Enforces rules on the amount of tokens being transferred. +/// The rules can be above, below, equal to, or within a range. + +abstract class TransferAmountRule {} + +class Above extends TransferAmountRule { + final BigInt /* type: u64 */ value0; + + Above(this.value0); +} + +class Below extends TransferAmountRule { + final BigInt /* type: u64 */ value0; + + Below(this.value0); +} + +class Equal extends TransferAmountRule { + final BigInt /* type: u64 */ value0; + + Equal(this.value0); +} + +class Rang extends TransferAmountRule { + final BigInt /* type: u64 */ value0; + final BigInt /* type: u64 */ value1; + + Rang(this.value0, this.value1); +} + +/// Extension providing serialization methods for TransferAmountRule. +/// +extension TransferAmountRuleBorsh on TransferAmountRule { + /// Converts the enum to a byte representation. + void toBorsh(BinaryWriter writer) { + if (this is Above) { + final v = this as Above; + + writer.writeU64(v.value0); + } + if (this is Below) { + final v = this as Below; + + writer.writeU64(v.value0); + } + if (this is Equal) { + final v = this as Equal; + + writer.writeU64(v.value0); + } + if (this is Rang) { + final v = this as Rang; + + writer.writeU64(v.value0); + + writer.writeU64(v.value1); + } + } + + /// Creates an enum from a byte representation. + static TransferAmountRule fromBorsh(BinaryReader reader) { + final variant = reader.readU8(); + switch (variant) { + case 0: + return Above(reader.readU64()); + case 1: + return Below(reader.readU64()); + case 2: + return Equal(reader.readU64()); + case 3: + return Rang(reader.readU64(), reader.readU64()); + default: + throw Exception('Unknown transferAmountRule variant: $variant'); + } + } +} diff --git a/e2e/dummy/.dart_tool/package_config.json b/e2e/dummy/.dart_tool/package_config.json new file mode 100644 index 0000000..cc60d19 --- /dev/null +++ b/e2e/dummy/.dart_tool/package_config.json @@ -0,0 +1,206 @@ +{ + "configVersion": 2, + "packages": [ + { + "name": "async", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/async-2.13.0", + "packageUri": "lib/", + "languageVersion": "3.4" + }, + { + "name": "bip39", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/bip39-1.0.6", + "packageUri": "lib/", + "languageVersion": "2.12" + }, + { + "name": "borsh_annotation", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/borsh_annotation-0.3.2", + "packageUri": "lib/", + "languageVersion": "3.0" + }, + { + "name": "clock", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/clock-1.1.2", + "packageUri": "lib/", + "languageVersion": "3.4" + }, + { + "name": "collection", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/collection-1.19.1", + "packageUri": "lib/", + "languageVersion": "3.4" + }, + { + "name": "convert", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/convert-3.1.2", + "packageUri": "lib/", + "languageVersion": "3.4" + }, + { + "name": "crypto", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/crypto-3.0.6", + "packageUri": "lib/", + "languageVersion": "3.4" + }, + { + "name": "cryptography", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/cryptography-2.7.0", + "packageUri": "lib/", + "languageVersion": "3.1" + }, + { + "name": "decimal", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/decimal-3.2.4", + "packageUri": "lib/", + "languageVersion": "3.3" + }, + { + "name": "ed25519_hd_key", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/ed25519_hd_key-2.3.0", + "packageUri": "lib/", + "languageVersion": "3.4" + }, + { + "name": "ffi", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/ffi-2.1.4", + "packageUri": "lib/", + "languageVersion": "3.7" + }, + { + "name": "freezed_annotation", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/freezed_annotation-2.4.4", + "packageUri": "lib/", + "languageVersion": "3.0" + }, + { + "name": "hex", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/hex-0.2.0", + "packageUri": "lib/", + "languageVersion": "2.12" + }, + { + "name": "http", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/http-1.5.0", + "packageUri": "lib/", + "languageVersion": "3.4" + }, + { + "name": "http_parser", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/http_parser-4.1.2", + "packageUri": "lib/", + "languageVersion": "3.4" + }, + { + "name": "intl", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/intl-0.20.2", + "packageUri": "lib/", + "languageVersion": "3.3" + }, + { + "name": "js", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/js-0.6.7", + "packageUri": "lib/", + "languageVersion": "2.19" + }, + { + "name": "json_annotation", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/json_annotation-4.9.0", + "packageUri": "lib/", + "languageVersion": "3.0" + }, + { + "name": "meta", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/meta-1.17.0", + "packageUri": "lib/", + "languageVersion": "3.5" + }, + { + "name": "path", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/path-1.9.1", + "packageUri": "lib/", + "languageVersion": "3.4" + }, + { + "name": "pinenacl", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/pinenacl-0.6.0", + "packageUri": "lib/", + "languageVersion": "3.4" + }, + { + "name": "pointycastle", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/pointycastle-3.9.1", + "packageUri": "lib/", + "languageVersion": "3.2" + }, + { + "name": "rational", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/rational-2.2.3", + "packageUri": "lib/", + "languageVersion": "2.14" + }, + { + "name": "solana", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/solana-0.31.2+1", + "packageUri": "lib/", + "languageVersion": "3.2" + }, + { + "name": "source_span", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/source_span-1.10.1", + "packageUri": "lib/", + "languageVersion": "3.1" + }, + { + "name": "stream_channel", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/stream_channel-2.1.4", + "packageUri": "lib/", + "languageVersion": "3.3" + }, + { + "name": "string_scanner", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/string_scanner-1.4.1", + "packageUri": "lib/", + "languageVersion": "3.1" + }, + { + "name": "term_glyph", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/term_glyph-1.2.2", + "packageUri": "lib/", + "languageVersion": "3.1" + }, + { + "name": "typed_data", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/typed_data-1.4.0", + "packageUri": "lib/", + "languageVersion": "3.5" + }, + { + "name": "web", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/web-1.1.1", + "packageUri": "lib/", + "languageVersion": "3.4" + }, + { + "name": "web_socket", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/web_socket-1.0.1", + "packageUri": "lib/", + "languageVersion": "3.4" + }, + { + "name": "web_socket_channel", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/web_socket_channel-3.0.3", + "packageUri": "lib/", + "languageVersion": "3.3" + }, + { + "name": "dummy", + "rootUri": "../", + "packageUri": "lib/", + "languageVersion": "2.17" + } + ], + "generator": "pub", + "generatorVersion": "3.9.0", + "pubCache": "file:///Users/emilemilovroydev/.pub-cache" +} diff --git a/e2e/dummy/.dart_tool/package_graph.json b/e2e/dummy/.dart_tool/package_graph.json new file mode 100644 index 0000000..8b4e474 --- /dev/null +++ b/e2e/dummy/.dart_tool/package_graph.json @@ -0,0 +1,257 @@ +{ + "roots": [ + "dummy" + ], + "packages": [ + { + "name": "dummy", + "version": "0.1.0", + "dependencies": [ + "solana" + ], + "devDependencies": [] + }, + { + "name": "solana", + "version": "0.31.2+1", + "dependencies": [ + "bip39", + "borsh_annotation", + "collection", + "convert", + "cryptography", + "decimal", + "ed25519_hd_key", + "freezed_annotation", + "http", + "json_annotation", + "typed_data", + "web_socket_channel" + ] + }, + { + "name": "web_socket_channel", + "version": "3.0.3", + "dependencies": [ + "async", + "crypto", + "stream_channel", + "web", + "web_socket" + ] + }, + { + "name": "typed_data", + "version": "1.4.0", + "dependencies": [ + "collection" + ] + }, + { + "name": "json_annotation", + "version": "4.9.0", + "dependencies": [ + "meta" + ] + }, + { + "name": "http", + "version": "1.5.0", + "dependencies": [ + "async", + "http_parser", + "meta", + "web" + ] + }, + { + "name": "freezed_annotation", + "version": "2.4.4", + "dependencies": [ + "collection", + "json_annotation", + "meta" + ] + }, + { + "name": "ed25519_hd_key", + "version": "2.3.0", + "dependencies": [ + "crypto", + "pinenacl" + ] + }, + { + "name": "decimal", + "version": "3.2.4", + "dependencies": [ + "intl", + "rational" + ] + }, + { + "name": "cryptography", + "version": "2.7.0", + "dependencies": [ + "collection", + "crypto", + "ffi", + "js", + "meta", + "typed_data" + ] + }, + { + "name": "convert", + "version": "3.1.2", + "dependencies": [ + "typed_data" + ] + }, + { + "name": "collection", + "version": "1.19.1", + "dependencies": [] + }, + { + "name": "borsh_annotation", + "version": "0.3.2", + "dependencies": [] + }, + { + "name": "bip39", + "version": "1.0.6", + "dependencies": [ + "crypto", + "hex", + "pointycastle" + ] + }, + { + "name": "web_socket", + "version": "1.0.1", + "dependencies": [ + "web" + ] + }, + { + "name": "web", + "version": "1.1.1", + "dependencies": [] + }, + { + "name": "stream_channel", + "version": "2.1.4", + "dependencies": [ + "async" + ] + }, + { + "name": "crypto", + "version": "3.0.6", + "dependencies": [ + "typed_data" + ] + }, + { + "name": "async", + "version": "2.13.0", + "dependencies": [ + "collection", + "meta" + ] + }, + { + "name": "meta", + "version": "1.17.0", + "dependencies": [] + }, + { + "name": "http_parser", + "version": "4.1.2", + "dependencies": [ + "collection", + "source_span", + "string_scanner", + "typed_data" + ] + }, + { + "name": "pinenacl", + "version": "0.6.0", + "dependencies": [] + }, + { + "name": "rational", + "version": "2.2.3", + "dependencies": [] + }, + { + "name": "intl", + "version": "0.20.2", + "dependencies": [ + "clock", + "meta", + "path" + ] + }, + { + "name": "js", + "version": "0.6.7", + "dependencies": [ + "meta" + ] + }, + { + "name": "ffi", + "version": "2.1.4", + "dependencies": [] + }, + { + "name": "hex", + "version": "0.2.0", + "dependencies": [] + }, + { + "name": "pointycastle", + "version": "3.9.1", + "dependencies": [ + "collection", + "convert", + "js" + ] + }, + { + "name": "string_scanner", + "version": "1.4.1", + "dependencies": [ + "source_span" + ] + }, + { + "name": "source_span", + "version": "1.10.1", + "dependencies": [ + "collection", + "path", + "term_glyph" + ] + }, + { + "name": "path", + "version": "1.9.1", + "dependencies": [] + }, + { + "name": "clock", + "version": "1.1.2", + "dependencies": [] + }, + { + "name": "term_glyph", + "version": "1.2.2", + "dependencies": [] + } + ], + "configVersion": 1 +} \ No newline at end of file diff --git a/e2e/dummy/idl.json b/e2e/dummy/idl.json new file mode 100644 index 0000000..b81b84d --- /dev/null +++ b/e2e/dummy/idl.json @@ -0,0 +1,149 @@ +{ + "kind": "rootNode", + "program": { + "kind": "programNode", + "pdas": [], + "accounts": [], + "instructions": [ + { + "kind": "instructionNode", + "name": "instruction1", + "optionalAccountStrategy": "programId", + "docs": ["Testing instructions with no accounts or arguments"], + "accounts": [], + "arguments": [], + "remainingAccounts": [] + }, + { + "kind": "instructionNode", + "name": "instruction2", + "optionalAccountStrategy": "programId", + "docs": ["Testing instructions with remaining accounts only"], + "accounts": [], + "arguments": [], + "remainingAccounts": [ + { + "kind": "instructionRemainingAccountsNode", + "value": { + "kind": "argumentValueNode", + "name": "remainingAccounts" + }, + "isOptional": true, + "isSigner": false + } + ] + }, + { + "kind": "instructionNode", + "name": "instruction3", + "optionalAccountStrategy": "programId", + "docs": ["Testing instructions with discriminator only"], + "accounts": [], + "arguments": [ + { + "kind": "instructionArgumentNode", + "name": "discriminator", + "type": { + "kind": "numberTypeNode", + "format": "u32", + "endian": "le" + }, + "docs": [], + "defaultValue": { "kind": "numberValueNode", "number": 42 }, + "defaultValueStrategy": "omitted" + } + ], + "discriminators": [ + { + "kind": "fieldDiscriminatorNode", + "name": "discriminator", + "offset": 0 + } + ] + }, + { + "kind": "instructionNode", + "name": "instruction4", + "optionalAccountStrategy": "programId", + "docs": ["Testing instructions with arguments only"], + "accounts": [], + "arguments": [ + { + "kind": "instructionArgumentNode", + "name": "myArgument", + "type": { + "kind": "numberTypeNode", + "format": "u64", + "endian": "le" + }, + "docs": [] + } + ] + }, + { + "kind": "instructionNode", + "name": "instruction5", + "optionalAccountStrategy": "programId", + "docs": ["Testing instructions with optional arguments only"], + "accounts": [], + "arguments": [ + { + "kind": "instructionArgumentNode", + "name": "myArgument", + "type": { + "kind": "numberTypeNode", + "format": "u64", + "endian": "le" + }, + "defaultValue": { "kind": "numberValueNode", "number": 42 }, + "docs": [] + } + ] + }, + { + "kind": "instructionNode", + "name": "instruction6", + "optionalAccountStrategy": "programId", + "docs": ["Testing instructions with accounts only"], + "accounts": [ + { + "kind": "instructionAccountNode", + "name": "myAccount", + "isWritable": true, + "isSigner": false, + "isOptional": false, + "docs": [] + } + ], + "arguments": [] + }, + { + "kind": "instructionNode", + "name": "instruction7", + "optionalAccountStrategy": "programId", + "docs": ["Testing instructions with optional accounts only"], + "accounts": [ + { + "kind": "instructionAccountNode", + "name": "myAccount", + "isWritable": true, + "isSigner": false, + "isOptional": true, + "docs": [] + } + ], + "arguments": [] + } + ], + "definedTypes": [], + "errors": [], + "name": "dummy", + "prefix": "", + "publicKey": "Dummy11111111111111111111111111111111111111", + "version": "3.0.1", + "origin": "shank" + }, + "additionalPrograms": [], + "standard": "codama", + "version": "1.0.0" + } \ No newline at end of file diff --git a/e2e/dummy/lib/generated/errors.dart b/e2e/dummy/lib/generated/errors.dart new file mode 100644 index 0000000..a105376 --- /dev/null +++ b/e2e/dummy/lib/generated/errors.dart @@ -0,0 +1,8 @@ +/// This code was AUTOGENERATED using the codama library. +/// Please DO NOT EDIT THIS FILE, instead use visitors +/// to add features, then rerun codama to update it. +/// +/// https://github.com/codama-idl/codama +/// + +// This file exports error classes for all programs in the SDK. diff --git a/e2e/dummy/lib/generated/lib.dart b/e2e/dummy/lib/generated/lib.dart new file mode 100644 index 0000000..3144eb0 --- /dev/null +++ b/e2e/dummy/lib/generated/lib.dart @@ -0,0 +1,11 @@ +/// This code was AUTOGENERATED using the codama library. +/// Please DO NOT EDIT THIS FILE, instead use visitors +/// to add features, then rerun codama to update it. +/// +/// https://github.com/codama-idl/codama +/// + +// Entry point for the SDK. +// This file exports all the modules in the SDK. + +export 'programs.dart'; diff --git a/e2e/dummy/lib/generated/mod.dart b/e2e/dummy/lib/generated/mod.dart new file mode 100644 index 0000000..3144eb0 --- /dev/null +++ b/e2e/dummy/lib/generated/mod.dart @@ -0,0 +1,11 @@ +/// This code was AUTOGENERATED using the codama library. +/// Please DO NOT EDIT THIS FILE, instead use visitors +/// to add features, then rerun codama to update it. +/// +/// https://github.com/codama-idl/codama +/// + +// Entry point for the SDK. +// This file exports all the modules in the SDK. + +export 'programs.dart'; diff --git a/e2e/dummy/lib/generated/programs.dart b/e2e/dummy/lib/generated/programs.dart new file mode 100644 index 0000000..2122c90 --- /dev/null +++ b/e2e/dummy/lib/generated/programs.dart @@ -0,0 +1,19 @@ +/// This code was AUTOGENERATED using the codama library. +/// Please DO NOT EDIT THIS FILE, instead use visitors +/// to add features, then rerun codama to update it. +/// +/// https://github.com/codama-idl/codama +/// + +// This file exports program information for all programs in the SDK. + +import 'package:solana/solana.dart'; + +/// Program information for the program. +class Program { + /// The program ID for the program. + static final Ed25519HDPublicKey programId = Ed25519HDPublicKey.fromBase58(""); + + /// The program name. + static const String name = ""; +} diff --git a/e2e/dummy/pubspec.lock b/e2e/dummy/pubspec.lock new file mode 100644 index 0000000..86d9781 --- /dev/null +++ b/e2e/dummy/pubspec.lock @@ -0,0 +1,261 @@ +# Generated by pub +# See https://dart.dev/tools/pub/glossary#lockfile +packages: + async: + dependency: transitive + description: + name: async + sha256: "758e6d74e971c3e5aceb4110bfd6698efc7f501675bcfe0c775459a8140750eb" + url: "https://pub.dev" + source: hosted + version: "2.13.0" + bip39: + dependency: transitive + description: + name: bip39 + sha256: de1ee27ebe7d96b84bb3a04a4132a0a3007dcdd5ad27dd14aa87a29d97c45edc + url: "https://pub.dev" + source: hosted + version: "1.0.6" + borsh_annotation: + dependency: transitive + description: + name: borsh_annotation + sha256: dc73a7fdc6fe4505535657daf8ab3cebe382311fae63a0faaf9315ea1bc30bff + url: "https://pub.dev" + source: hosted + version: "0.3.2" + clock: + dependency: transitive + description: + name: clock + sha256: fddb70d9b5277016c77a80201021d40a2247104d9f4aa7bab7157b7e3f05b84b + url: "https://pub.dev" + source: hosted + version: "1.1.2" + collection: + dependency: transitive + description: + name: collection + sha256: "2f5709ae4d3d59dd8f7cd309b4e023046b57d8a6c82130785d2b0e5868084e76" + url: "https://pub.dev" + source: hosted + version: "1.19.1" + convert: + dependency: transitive + description: + name: convert + sha256: b30acd5944035672bc15c6b7a8b47d773e41e2f17de064350988c5d02adb1c68 + url: "https://pub.dev" + source: hosted + version: "3.1.2" + crypto: + dependency: transitive + description: + name: crypto + sha256: "1e445881f28f22d6140f181e07737b22f1e099a5e1ff94b0af2f9e4a463f4855" + url: "https://pub.dev" + source: hosted + version: "3.0.6" + cryptography: + dependency: transitive + description: + name: cryptography + sha256: d146b76d33d94548cf035233fbc2f4338c1242fa119013bead807d033fc4ae05 + url: "https://pub.dev" + source: hosted + version: "2.7.0" + decimal: + dependency: transitive + description: + name: decimal + sha256: fc706a5618b81e5b367b01dd62621def37abc096f2b46a9bd9068b64c1fa36d0 + url: "https://pub.dev" + source: hosted + version: "3.2.4" + ed25519_hd_key: + dependency: transitive + description: + name: ed25519_hd_key + sha256: "31e191ec97492873067e46dc9cc0c7d55170559c83a478400feffa0627acaccf" + url: "https://pub.dev" + source: hosted + version: "2.3.0" + ffi: + dependency: transitive + description: + name: ffi + sha256: "289279317b4b16eb2bb7e271abccd4bf84ec9bdcbe999e278a94b804f5630418" + url: "https://pub.dev" + source: hosted + version: "2.1.4" + freezed_annotation: + dependency: transitive + description: + name: freezed_annotation + sha256: c2e2d632dd9b8a2b7751117abcfc2b4888ecfe181bd9fca7170d9ef02e595fe2 + url: "https://pub.dev" + source: hosted + version: "2.4.4" + hex: + dependency: transitive + description: + name: hex + sha256: "4e7cd54e4b59ba026432a6be2dd9d96e4c5205725194997193bf871703b82c4a" + url: "https://pub.dev" + source: hosted + version: "0.2.0" + http: + dependency: transitive + description: + name: http + sha256: bb2ce4590bc2667c96f318d68cac1b5a7987ec819351d32b1c987239a815e007 + url: "https://pub.dev" + source: hosted + version: "1.5.0" + http_parser: + dependency: transitive + description: + name: http_parser + sha256: "178d74305e7866013777bab2c3d8726205dc5a4dd935297175b19a23a2e66571" + url: "https://pub.dev" + source: hosted + version: "4.1.2" + intl: + dependency: transitive + description: + name: intl + sha256: "3df61194eb431efc39c4ceba583b95633a403f46c9fd341e550ce0bfa50e9aa5" + url: "https://pub.dev" + source: hosted + version: "0.20.2" + js: + dependency: transitive + description: + name: js + sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3 + url: "https://pub.dev" + source: hosted + version: "0.6.7" + json_annotation: + dependency: transitive + description: + name: json_annotation + sha256: "1ce844379ca14835a50d2f019a3099f419082cfdd231cd86a142af94dd5c6bb1" + url: "https://pub.dev" + source: hosted + version: "4.9.0" + meta: + dependency: transitive + description: + name: meta + sha256: "23f08335362185a5ea2ad3a4e597f1375e78bce8a040df5c600c8d3552ef2394" + url: "https://pub.dev" + source: hosted + version: "1.17.0" + path: + dependency: transitive + description: + name: path + sha256: "75cca69d1490965be98c73ceaea117e8a04dd21217b37b292c9ddbec0d955bc5" + url: "https://pub.dev" + source: hosted + version: "1.9.1" + pinenacl: + dependency: transitive + description: + name: pinenacl + sha256: "57e907beaacbc3c024a098910b6240758e899674de07d6949a67b52fd984cbdf" + url: "https://pub.dev" + source: hosted + version: "0.6.0" + pointycastle: + dependency: transitive + description: + name: pointycastle + sha256: "4be0097fcf3fd3e8449e53730c631200ebc7b88016acecab2b0da2f0149222fe" + url: "https://pub.dev" + source: hosted + version: "3.9.1" + rational: + dependency: transitive + description: + name: rational + sha256: cb808fb6f1a839e6fc5f7d8cb3b0a10e1db48b3be102de73938c627f0b636336 + url: "https://pub.dev" + source: hosted + version: "2.2.3" + solana: + dependency: "direct main" + description: + name: solana + sha256: "98d8780dbd9af7e90ff14a6e762a45d77466450304773610317d1fffdea09701" + url: "https://pub.dev" + source: hosted + version: "0.31.2+1" + source_span: + dependency: transitive + description: + name: source_span + sha256: "254ee5351d6cb365c859e20ee823c3bb479bf4a293c22d17a9f1bf144ce86f7c" + url: "https://pub.dev" + source: hosted + version: "1.10.1" + stream_channel: + dependency: transitive + description: + name: stream_channel + sha256: "969e04c80b8bcdf826f8f16579c7b14d780458bd97f56d107d3950fdbeef059d" + url: "https://pub.dev" + source: hosted + version: "2.1.4" + string_scanner: + dependency: transitive + description: + name: string_scanner + sha256: "921cd31725b72fe181906c6a94d987c78e3b98c2e205b397ea399d4054872b43" + url: "https://pub.dev" + source: hosted + version: "1.4.1" + term_glyph: + dependency: transitive + description: + name: term_glyph + sha256: "7f554798625ea768a7518313e58f83891c7f5024f88e46e7182a4558850a4b8e" + url: "https://pub.dev" + source: hosted + version: "1.2.2" + typed_data: + dependency: transitive + description: + name: typed_data + sha256: f9049c039ebfeb4cf7a7104a675823cd72dba8297f264b6637062516699fa006 + url: "https://pub.dev" + source: hosted + version: "1.4.0" + web: + dependency: transitive + description: + name: web + sha256: "868d88a33d8a87b18ffc05f9f030ba328ffefba92d6c127917a2ba740f9cfe4a" + url: "https://pub.dev" + source: hosted + version: "1.1.1" + web_socket: + dependency: transitive + description: + name: web_socket + sha256: "34d64019aa8e36bf9842ac014bb5d2f5586ca73df5e4d9bf5c936975cae6982c" + url: "https://pub.dev" + source: hosted + version: "1.0.1" + web_socket_channel: + dependency: transitive + description: + name: web_socket_channel + sha256: d645757fb0f4773d602444000a8131ff5d48c9e47adfe9772652dd1a4f2d45c8 + url: "https://pub.dev" + source: hosted + version: "3.0.3" +sdks: + dart: ">=3.7.0 <4.0.0" diff --git a/e2e/dummy/pubspec.yaml b/e2e/dummy/pubspec.yaml new file mode 100644 index 0000000..36e435e --- /dev/null +++ b/e2e/dummy/pubspec.yaml @@ -0,0 +1,7 @@ +name: dummy +description: Dummy project for e2e generated Dart code +version: 0.1.0 +environment: + sdk: '>=2.17.0 <4.0.0' +dependencies: + solana: ^0.31.2+1 \ No newline at end of file diff --git a/e2e/generate-anchor.cjs b/e2e/generate-anchor.cjs new file mode 100755 index 0000000..b2969b7 --- /dev/null +++ b/e2e/generate-anchor.cjs @@ -0,0 +1,32 @@ +#!/usr/bin/env -S node +const { createFromRoot } = require('codama'); +const { rootNodeFromAnchor } = require('@codama/nodes-from-anchor'); + +const path = require('node:path'); +const process = require('node:process'); + +const { readJson } = require('@codama/renderers-core'); + +const { renderVisitor } = require('../dist/index.node.cjs'); + +async function main() { + const project = process.argv.slice(2)[0] ?? undefined; + if (project === undefined) { + throw new Error('Project name is required.'); + } + + await generateProject(project); +} + +async function generateProject(project) { + console.log(`Generating code for project: ${project}`); + const idl = readJson(path.join(__dirname, project, 'idl.json')); + const codama = createFromRoot(rootNodeFromAnchor(idl)); + const outDir = path.join(__dirname, project, 'lib', 'generated'); + codama.accept(renderVisitor(outDir)); +} + +main().catch(err => { + console.error(err); + process.exit(1); +}); diff --git a/e2e/generate.cjs b/e2e/generate.cjs new file mode 100755 index 0000000..bca93ea --- /dev/null +++ b/e2e/generate.cjs @@ -0,0 +1,31 @@ +#!/usr/bin/env -S node +const { createFromRoot } = require('codama'); +const { rootNodeFromAnchor } = require('@codama/nodes-from-anchor'); + +const path = require('node:path'); +const process = require('node:process'); + +const { readJson } = require('@codama/renderers-core'); + +const { renderVisitor } = require('../dist/index.node.cjs'); + +async function main() { + const project = process.argv.slice(2)[0] ?? undefined; + if (project === undefined) { + throw new Error('Project name is required.'); + } + await generateProject(project); +} + +async function generateProject(project) { + console.log(`Generating code for project: ${project}`); + const idl = readJson(path.join(__dirname, project, 'idl.json')); + const codama = createFromRoot(rootNodeFromAnchor(idl)); + const outDir = path.join(__dirname, project, 'lib', 'generated'); + codama.accept(renderVisitor(outDir)); +} + +main().catch(err => { + console.error(err); + process.exit(1); +}); \ No newline at end of file diff --git a/e2e/memo/.dart_tool/package_config.json b/e2e/memo/.dart_tool/package_config.json new file mode 100644 index 0000000..b817373 --- /dev/null +++ b/e2e/memo/.dart_tool/package_config.json @@ -0,0 +1,206 @@ +{ + "configVersion": 2, + "packages": [ + { + "name": "async", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/async-2.13.0", + "packageUri": "lib/", + "languageVersion": "3.4" + }, + { + "name": "bip39", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/bip39-1.0.6", + "packageUri": "lib/", + "languageVersion": "2.12" + }, + { + "name": "borsh_annotation", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/borsh_annotation-0.3.2", + "packageUri": "lib/", + "languageVersion": "3.0" + }, + { + "name": "clock", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/clock-1.1.2", + "packageUri": "lib/", + "languageVersion": "3.4" + }, + { + "name": "collection", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/collection-1.19.1", + "packageUri": "lib/", + "languageVersion": "3.4" + }, + { + "name": "convert", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/convert-3.1.2", + "packageUri": "lib/", + "languageVersion": "3.4" + }, + { + "name": "crypto", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/crypto-3.0.6", + "packageUri": "lib/", + "languageVersion": "3.4" + }, + { + "name": "cryptography", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/cryptography-2.7.0", + "packageUri": "lib/", + "languageVersion": "3.1" + }, + { + "name": "decimal", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/decimal-3.2.4", + "packageUri": "lib/", + "languageVersion": "3.3" + }, + { + "name": "ed25519_hd_key", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/ed25519_hd_key-2.3.0", + "packageUri": "lib/", + "languageVersion": "3.4" + }, + { + "name": "ffi", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/ffi-2.1.4", + "packageUri": "lib/", + "languageVersion": "3.7" + }, + { + "name": "freezed_annotation", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/freezed_annotation-2.4.4", + "packageUri": "lib/", + "languageVersion": "3.0" + }, + { + "name": "hex", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/hex-0.2.0", + "packageUri": "lib/", + "languageVersion": "2.12" + }, + { + "name": "http", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/http-1.5.0", + "packageUri": "lib/", + "languageVersion": "3.4" + }, + { + "name": "http_parser", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/http_parser-4.1.2", + "packageUri": "lib/", + "languageVersion": "3.4" + }, + { + "name": "intl", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/intl-0.20.2", + "packageUri": "lib/", + "languageVersion": "3.3" + }, + { + "name": "js", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/js-0.6.7", + "packageUri": "lib/", + "languageVersion": "2.19" + }, + { + "name": "json_annotation", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/json_annotation-4.9.0", + "packageUri": "lib/", + "languageVersion": "3.0" + }, + { + "name": "meta", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/meta-1.17.0", + "packageUri": "lib/", + "languageVersion": "3.5" + }, + { + "name": "path", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/path-1.9.1", + "packageUri": "lib/", + "languageVersion": "3.4" + }, + { + "name": "pinenacl", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/pinenacl-0.6.0", + "packageUri": "lib/", + "languageVersion": "3.4" + }, + { + "name": "pointycastle", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/pointycastle-3.9.1", + "packageUri": "lib/", + "languageVersion": "3.2" + }, + { + "name": "rational", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/rational-2.2.3", + "packageUri": "lib/", + "languageVersion": "2.14" + }, + { + "name": "solana", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/solana-0.31.2+1", + "packageUri": "lib/", + "languageVersion": "3.2" + }, + { + "name": "source_span", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/source_span-1.10.1", + "packageUri": "lib/", + "languageVersion": "3.1" + }, + { + "name": "stream_channel", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/stream_channel-2.1.4", + "packageUri": "lib/", + "languageVersion": "3.3" + }, + { + "name": "string_scanner", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/string_scanner-1.4.1", + "packageUri": "lib/", + "languageVersion": "3.1" + }, + { + "name": "term_glyph", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/term_glyph-1.2.2", + "packageUri": "lib/", + "languageVersion": "3.1" + }, + { + "name": "typed_data", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/typed_data-1.4.0", + "packageUri": "lib/", + "languageVersion": "3.5" + }, + { + "name": "web", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/web-1.1.1", + "packageUri": "lib/", + "languageVersion": "3.4" + }, + { + "name": "web_socket", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/web_socket-1.0.1", + "packageUri": "lib/", + "languageVersion": "3.4" + }, + { + "name": "web_socket_channel", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/web_socket_channel-3.0.3", + "packageUri": "lib/", + "languageVersion": "3.3" + }, + { + "name": "memo", + "rootUri": "../", + "packageUri": "lib/", + "languageVersion": "2.17" + } + ], + "generator": "pub", + "generatorVersion": "3.9.0", + "pubCache": "file:///Users/emilemilovroydev/.pub-cache" +} diff --git a/e2e/memo/.dart_tool/package_graph.json b/e2e/memo/.dart_tool/package_graph.json new file mode 100644 index 0000000..21013f5 --- /dev/null +++ b/e2e/memo/.dart_tool/package_graph.json @@ -0,0 +1,257 @@ +{ + "roots": [ + "memo" + ], + "packages": [ + { + "name": "memo", + "version": "0.1.0", + "dependencies": [ + "solana" + ], + "devDependencies": [] + }, + { + "name": "solana", + "version": "0.31.2+1", + "dependencies": [ + "bip39", + "borsh_annotation", + "collection", + "convert", + "cryptography", + "decimal", + "ed25519_hd_key", + "freezed_annotation", + "http", + "json_annotation", + "typed_data", + "web_socket_channel" + ] + }, + { + "name": "web_socket_channel", + "version": "3.0.3", + "dependencies": [ + "async", + "crypto", + "stream_channel", + "web", + "web_socket" + ] + }, + { + "name": "typed_data", + "version": "1.4.0", + "dependencies": [ + "collection" + ] + }, + { + "name": "json_annotation", + "version": "4.9.0", + "dependencies": [ + "meta" + ] + }, + { + "name": "http", + "version": "1.5.0", + "dependencies": [ + "async", + "http_parser", + "meta", + "web" + ] + }, + { + "name": "freezed_annotation", + "version": "2.4.4", + "dependencies": [ + "collection", + "json_annotation", + "meta" + ] + }, + { + "name": "ed25519_hd_key", + "version": "2.3.0", + "dependencies": [ + "crypto", + "pinenacl" + ] + }, + { + "name": "decimal", + "version": "3.2.4", + "dependencies": [ + "intl", + "rational" + ] + }, + { + "name": "cryptography", + "version": "2.7.0", + "dependencies": [ + "collection", + "crypto", + "ffi", + "js", + "meta", + "typed_data" + ] + }, + { + "name": "convert", + "version": "3.1.2", + "dependencies": [ + "typed_data" + ] + }, + { + "name": "collection", + "version": "1.19.1", + "dependencies": [] + }, + { + "name": "borsh_annotation", + "version": "0.3.2", + "dependencies": [] + }, + { + "name": "bip39", + "version": "1.0.6", + "dependencies": [ + "crypto", + "hex", + "pointycastle" + ] + }, + { + "name": "web_socket", + "version": "1.0.1", + "dependencies": [ + "web" + ] + }, + { + "name": "web", + "version": "1.1.1", + "dependencies": [] + }, + { + "name": "stream_channel", + "version": "2.1.4", + "dependencies": [ + "async" + ] + }, + { + "name": "crypto", + "version": "3.0.6", + "dependencies": [ + "typed_data" + ] + }, + { + "name": "async", + "version": "2.13.0", + "dependencies": [ + "collection", + "meta" + ] + }, + { + "name": "meta", + "version": "1.17.0", + "dependencies": [] + }, + { + "name": "http_parser", + "version": "4.1.2", + "dependencies": [ + "collection", + "source_span", + "string_scanner", + "typed_data" + ] + }, + { + "name": "pinenacl", + "version": "0.6.0", + "dependencies": [] + }, + { + "name": "rational", + "version": "2.2.3", + "dependencies": [] + }, + { + "name": "intl", + "version": "0.20.2", + "dependencies": [ + "clock", + "meta", + "path" + ] + }, + { + "name": "js", + "version": "0.6.7", + "dependencies": [ + "meta" + ] + }, + { + "name": "ffi", + "version": "2.1.4", + "dependencies": [] + }, + { + "name": "hex", + "version": "0.2.0", + "dependencies": [] + }, + { + "name": "pointycastle", + "version": "3.9.1", + "dependencies": [ + "collection", + "convert", + "js" + ] + }, + { + "name": "string_scanner", + "version": "1.4.1", + "dependencies": [ + "source_span" + ] + }, + { + "name": "source_span", + "version": "1.10.1", + "dependencies": [ + "collection", + "path", + "term_glyph" + ] + }, + { + "name": "path", + "version": "1.9.1", + "dependencies": [] + }, + { + "name": "clock", + "version": "1.1.2", + "dependencies": [] + }, + { + "name": "term_glyph", + "version": "1.2.2", + "dependencies": [] + } + ], + "configVersion": 1 +} \ No newline at end of file diff --git a/e2e/memo/idl.json b/e2e/memo/idl.json new file mode 100644 index 0000000..f25afa6 --- /dev/null +++ b/e2e/memo/idl.json @@ -0,0 +1,44 @@ +{ + "kind": "rootNode", + "program": { + "kind": "programNode", + "pdas": [], + "accounts": [], + "instructions": [ + { + "kind": "instructionNode", + "accounts": [], + "arguments": [ + { + "kind": "instructionArgumentNode", + "name": "memo", + "type": { "kind": "stringTypeNode", "encoding": "utf8" }, + "docs": [] + } + ], + "remainingAccounts": [ + { + "kind": "instructionRemainingAccountsNode", + "value": { "kind": "argumentValueNode", "name": "signers" }, + "isOptional": true, + "isSigner": true + } + ], + "name": "addMemo", + "idlName": "addMemo", + "docs": [], + "optionalAccountStrategy": "programId" + } + ], + "definedTypes": [], + "errors": [], + "name": "memo", + "prefix": "", + "publicKey": "MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr", + "version": "3.0.1", + "origin": "shank" + }, + "additionalPrograms": [], + "standard": "codama", + "version": "1.0.0" +} diff --git a/e2e/memo/lib/generated/errors.dart b/e2e/memo/lib/generated/errors.dart new file mode 100644 index 0000000..a105376 --- /dev/null +++ b/e2e/memo/lib/generated/errors.dart @@ -0,0 +1,8 @@ +/// This code was AUTOGENERATED using the codama library. +/// Please DO NOT EDIT THIS FILE, instead use visitors +/// to add features, then rerun codama to update it. +/// +/// https://github.com/codama-idl/codama +/// + +// This file exports error classes for all programs in the SDK. diff --git a/e2e/memo/lib/generated/lib.dart b/e2e/memo/lib/generated/lib.dart new file mode 100644 index 0000000..3144eb0 --- /dev/null +++ b/e2e/memo/lib/generated/lib.dart @@ -0,0 +1,11 @@ +/// This code was AUTOGENERATED using the codama library. +/// Please DO NOT EDIT THIS FILE, instead use visitors +/// to add features, then rerun codama to update it. +/// +/// https://github.com/codama-idl/codama +/// + +// Entry point for the SDK. +// This file exports all the modules in the SDK. + +export 'programs.dart'; diff --git a/e2e/memo/lib/generated/mod.dart b/e2e/memo/lib/generated/mod.dart new file mode 100644 index 0000000..3144eb0 --- /dev/null +++ b/e2e/memo/lib/generated/mod.dart @@ -0,0 +1,11 @@ +/// This code was AUTOGENERATED using the codama library. +/// Please DO NOT EDIT THIS FILE, instead use visitors +/// to add features, then rerun codama to update it. +/// +/// https://github.com/codama-idl/codama +/// + +// Entry point for the SDK. +// This file exports all the modules in the SDK. + +export 'programs.dart'; diff --git a/e2e/memo/lib/generated/programs.dart b/e2e/memo/lib/generated/programs.dart new file mode 100644 index 0000000..2122c90 --- /dev/null +++ b/e2e/memo/lib/generated/programs.dart @@ -0,0 +1,19 @@ +/// This code was AUTOGENERATED using the codama library. +/// Please DO NOT EDIT THIS FILE, instead use visitors +/// to add features, then rerun codama to update it. +/// +/// https://github.com/codama-idl/codama +/// + +// This file exports program information for all programs in the SDK. + +import 'package:solana/solana.dart'; + +/// Program information for the program. +class Program { + /// The program ID for the program. + static final Ed25519HDPublicKey programId = Ed25519HDPublicKey.fromBase58(""); + + /// The program name. + static const String name = ""; +} diff --git a/e2e/memo/pubspec.lock b/e2e/memo/pubspec.lock new file mode 100644 index 0000000..86d9781 --- /dev/null +++ b/e2e/memo/pubspec.lock @@ -0,0 +1,261 @@ +# Generated by pub +# See https://dart.dev/tools/pub/glossary#lockfile +packages: + async: + dependency: transitive + description: + name: async + sha256: "758e6d74e971c3e5aceb4110bfd6698efc7f501675bcfe0c775459a8140750eb" + url: "https://pub.dev" + source: hosted + version: "2.13.0" + bip39: + dependency: transitive + description: + name: bip39 + sha256: de1ee27ebe7d96b84bb3a04a4132a0a3007dcdd5ad27dd14aa87a29d97c45edc + url: "https://pub.dev" + source: hosted + version: "1.0.6" + borsh_annotation: + dependency: transitive + description: + name: borsh_annotation + sha256: dc73a7fdc6fe4505535657daf8ab3cebe382311fae63a0faaf9315ea1bc30bff + url: "https://pub.dev" + source: hosted + version: "0.3.2" + clock: + dependency: transitive + description: + name: clock + sha256: fddb70d9b5277016c77a80201021d40a2247104d9f4aa7bab7157b7e3f05b84b + url: "https://pub.dev" + source: hosted + version: "1.1.2" + collection: + dependency: transitive + description: + name: collection + sha256: "2f5709ae4d3d59dd8f7cd309b4e023046b57d8a6c82130785d2b0e5868084e76" + url: "https://pub.dev" + source: hosted + version: "1.19.1" + convert: + dependency: transitive + description: + name: convert + sha256: b30acd5944035672bc15c6b7a8b47d773e41e2f17de064350988c5d02adb1c68 + url: "https://pub.dev" + source: hosted + version: "3.1.2" + crypto: + dependency: transitive + description: + name: crypto + sha256: "1e445881f28f22d6140f181e07737b22f1e099a5e1ff94b0af2f9e4a463f4855" + url: "https://pub.dev" + source: hosted + version: "3.0.6" + cryptography: + dependency: transitive + description: + name: cryptography + sha256: d146b76d33d94548cf035233fbc2f4338c1242fa119013bead807d033fc4ae05 + url: "https://pub.dev" + source: hosted + version: "2.7.0" + decimal: + dependency: transitive + description: + name: decimal + sha256: fc706a5618b81e5b367b01dd62621def37abc096f2b46a9bd9068b64c1fa36d0 + url: "https://pub.dev" + source: hosted + version: "3.2.4" + ed25519_hd_key: + dependency: transitive + description: + name: ed25519_hd_key + sha256: "31e191ec97492873067e46dc9cc0c7d55170559c83a478400feffa0627acaccf" + url: "https://pub.dev" + source: hosted + version: "2.3.0" + ffi: + dependency: transitive + description: + name: ffi + sha256: "289279317b4b16eb2bb7e271abccd4bf84ec9bdcbe999e278a94b804f5630418" + url: "https://pub.dev" + source: hosted + version: "2.1.4" + freezed_annotation: + dependency: transitive + description: + name: freezed_annotation + sha256: c2e2d632dd9b8a2b7751117abcfc2b4888ecfe181bd9fca7170d9ef02e595fe2 + url: "https://pub.dev" + source: hosted + version: "2.4.4" + hex: + dependency: transitive + description: + name: hex + sha256: "4e7cd54e4b59ba026432a6be2dd9d96e4c5205725194997193bf871703b82c4a" + url: "https://pub.dev" + source: hosted + version: "0.2.0" + http: + dependency: transitive + description: + name: http + sha256: bb2ce4590bc2667c96f318d68cac1b5a7987ec819351d32b1c987239a815e007 + url: "https://pub.dev" + source: hosted + version: "1.5.0" + http_parser: + dependency: transitive + description: + name: http_parser + sha256: "178d74305e7866013777bab2c3d8726205dc5a4dd935297175b19a23a2e66571" + url: "https://pub.dev" + source: hosted + version: "4.1.2" + intl: + dependency: transitive + description: + name: intl + sha256: "3df61194eb431efc39c4ceba583b95633a403f46c9fd341e550ce0bfa50e9aa5" + url: "https://pub.dev" + source: hosted + version: "0.20.2" + js: + dependency: transitive + description: + name: js + sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3 + url: "https://pub.dev" + source: hosted + version: "0.6.7" + json_annotation: + dependency: transitive + description: + name: json_annotation + sha256: "1ce844379ca14835a50d2f019a3099f419082cfdd231cd86a142af94dd5c6bb1" + url: "https://pub.dev" + source: hosted + version: "4.9.0" + meta: + dependency: transitive + description: + name: meta + sha256: "23f08335362185a5ea2ad3a4e597f1375e78bce8a040df5c600c8d3552ef2394" + url: "https://pub.dev" + source: hosted + version: "1.17.0" + path: + dependency: transitive + description: + name: path + sha256: "75cca69d1490965be98c73ceaea117e8a04dd21217b37b292c9ddbec0d955bc5" + url: "https://pub.dev" + source: hosted + version: "1.9.1" + pinenacl: + dependency: transitive + description: + name: pinenacl + sha256: "57e907beaacbc3c024a098910b6240758e899674de07d6949a67b52fd984cbdf" + url: "https://pub.dev" + source: hosted + version: "0.6.0" + pointycastle: + dependency: transitive + description: + name: pointycastle + sha256: "4be0097fcf3fd3e8449e53730c631200ebc7b88016acecab2b0da2f0149222fe" + url: "https://pub.dev" + source: hosted + version: "3.9.1" + rational: + dependency: transitive + description: + name: rational + sha256: cb808fb6f1a839e6fc5f7d8cb3b0a10e1db48b3be102de73938c627f0b636336 + url: "https://pub.dev" + source: hosted + version: "2.2.3" + solana: + dependency: "direct main" + description: + name: solana + sha256: "98d8780dbd9af7e90ff14a6e762a45d77466450304773610317d1fffdea09701" + url: "https://pub.dev" + source: hosted + version: "0.31.2+1" + source_span: + dependency: transitive + description: + name: source_span + sha256: "254ee5351d6cb365c859e20ee823c3bb479bf4a293c22d17a9f1bf144ce86f7c" + url: "https://pub.dev" + source: hosted + version: "1.10.1" + stream_channel: + dependency: transitive + description: + name: stream_channel + sha256: "969e04c80b8bcdf826f8f16579c7b14d780458bd97f56d107d3950fdbeef059d" + url: "https://pub.dev" + source: hosted + version: "2.1.4" + string_scanner: + dependency: transitive + description: + name: string_scanner + sha256: "921cd31725b72fe181906c6a94d987c78e3b98c2e205b397ea399d4054872b43" + url: "https://pub.dev" + source: hosted + version: "1.4.1" + term_glyph: + dependency: transitive + description: + name: term_glyph + sha256: "7f554798625ea768a7518313e58f83891c7f5024f88e46e7182a4558850a4b8e" + url: "https://pub.dev" + source: hosted + version: "1.2.2" + typed_data: + dependency: transitive + description: + name: typed_data + sha256: f9049c039ebfeb4cf7a7104a675823cd72dba8297f264b6637062516699fa006 + url: "https://pub.dev" + source: hosted + version: "1.4.0" + web: + dependency: transitive + description: + name: web + sha256: "868d88a33d8a87b18ffc05f9f030ba328ffefba92d6c127917a2ba740f9cfe4a" + url: "https://pub.dev" + source: hosted + version: "1.1.1" + web_socket: + dependency: transitive + description: + name: web_socket + sha256: "34d64019aa8e36bf9842ac014bb5d2f5586ca73df5e4d9bf5c936975cae6982c" + url: "https://pub.dev" + source: hosted + version: "1.0.1" + web_socket_channel: + dependency: transitive + description: + name: web_socket_channel + sha256: d645757fb0f4773d602444000a8131ff5d48c9e47adfe9772652dd1a4f2d45c8 + url: "https://pub.dev" + source: hosted + version: "3.0.3" +sdks: + dart: ">=3.7.0 <4.0.0" diff --git a/e2e/memo/pubspec.yaml b/e2e/memo/pubspec.yaml new file mode 100644 index 0000000..0d0817e --- /dev/null +++ b/e2e/memo/pubspec.yaml @@ -0,0 +1,7 @@ +name: memo +description: memo project for e2e generated Dart code +version: 0.1.0 +environment: + sdk: '>=2.17.0 <4.0.0' +dependencies: + solana: ^0.31.2+1 \ No newline at end of file diff --git a/e2e/meteora/.dart_tool/package_config.json b/e2e/meteora/.dart_tool/package_config.json new file mode 100644 index 0000000..572b34d --- /dev/null +++ b/e2e/meteora/.dart_tool/package_config.json @@ -0,0 +1,206 @@ +{ + "configVersion": 2, + "packages": [ + { + "name": "async", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/async-2.13.0", + "packageUri": "lib/", + "languageVersion": "3.4" + }, + { + "name": "bip39", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/bip39-1.0.6", + "packageUri": "lib/", + "languageVersion": "2.12" + }, + { + "name": "borsh_annotation", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/borsh_annotation-0.3.2", + "packageUri": "lib/", + "languageVersion": "3.0" + }, + { + "name": "clock", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/clock-1.1.2", + "packageUri": "lib/", + "languageVersion": "3.4" + }, + { + "name": "collection", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/collection-1.19.1", + "packageUri": "lib/", + "languageVersion": "3.4" + }, + { + "name": "convert", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/convert-3.1.2", + "packageUri": "lib/", + "languageVersion": "3.4" + }, + { + "name": "crypto", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/crypto-3.0.6", + "packageUri": "lib/", + "languageVersion": "3.4" + }, + { + "name": "cryptography", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/cryptography-2.7.0", + "packageUri": "lib/", + "languageVersion": "3.1" + }, + { + "name": "decimal", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/decimal-3.2.4", + "packageUri": "lib/", + "languageVersion": "3.3" + }, + { + "name": "ed25519_hd_key", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/ed25519_hd_key-2.3.0", + "packageUri": "lib/", + "languageVersion": "3.4" + }, + { + "name": "ffi", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/ffi-2.1.4", + "packageUri": "lib/", + "languageVersion": "3.7" + }, + { + "name": "freezed_annotation", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/freezed_annotation-2.4.4", + "packageUri": "lib/", + "languageVersion": "3.0" + }, + { + "name": "hex", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/hex-0.2.0", + "packageUri": "lib/", + "languageVersion": "2.12" + }, + { + "name": "http", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/http-1.5.0", + "packageUri": "lib/", + "languageVersion": "3.4" + }, + { + "name": "http_parser", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/http_parser-4.1.2", + "packageUri": "lib/", + "languageVersion": "3.4" + }, + { + "name": "intl", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/intl-0.20.2", + "packageUri": "lib/", + "languageVersion": "3.3" + }, + { + "name": "js", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/js-0.6.7", + "packageUri": "lib/", + "languageVersion": "2.19" + }, + { + "name": "json_annotation", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/json_annotation-4.9.0", + "packageUri": "lib/", + "languageVersion": "3.0" + }, + { + "name": "meta", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/meta-1.17.0", + "packageUri": "lib/", + "languageVersion": "3.5" + }, + { + "name": "path", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/path-1.9.1", + "packageUri": "lib/", + "languageVersion": "3.4" + }, + { + "name": "pinenacl", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/pinenacl-0.6.0", + "packageUri": "lib/", + "languageVersion": "3.4" + }, + { + "name": "pointycastle", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/pointycastle-3.9.1", + "packageUri": "lib/", + "languageVersion": "3.2" + }, + { + "name": "rational", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/rational-2.2.3", + "packageUri": "lib/", + "languageVersion": "2.14" + }, + { + "name": "solana", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/solana-0.31.2+1", + "packageUri": "lib/", + "languageVersion": "3.2" + }, + { + "name": "source_span", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/source_span-1.10.1", + "packageUri": "lib/", + "languageVersion": "3.1" + }, + { + "name": "stream_channel", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/stream_channel-2.1.4", + "packageUri": "lib/", + "languageVersion": "3.3" + }, + { + "name": "string_scanner", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/string_scanner-1.4.1", + "packageUri": "lib/", + "languageVersion": "3.1" + }, + { + "name": "term_glyph", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/term_glyph-1.2.2", + "packageUri": "lib/", + "languageVersion": "3.1" + }, + { + "name": "typed_data", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/typed_data-1.4.0", + "packageUri": "lib/", + "languageVersion": "3.5" + }, + { + "name": "web", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/web-1.1.1", + "packageUri": "lib/", + "languageVersion": "3.4" + }, + { + "name": "web_socket", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/web_socket-1.0.1", + "packageUri": "lib/", + "languageVersion": "3.4" + }, + { + "name": "web_socket_channel", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/web_socket_channel-3.0.3", + "packageUri": "lib/", + "languageVersion": "3.3" + }, + { + "name": "meteora", + "rootUri": "../", + "packageUri": "lib/", + "languageVersion": "2.17" + } + ], + "generator": "pub", + "generatorVersion": "3.9.0", + "pubCache": "file:///Users/emilemilovroydev/.pub-cache" +} diff --git a/e2e/meteora/.dart_tool/package_graph.json b/e2e/meteora/.dart_tool/package_graph.json new file mode 100644 index 0000000..4d411e3 --- /dev/null +++ b/e2e/meteora/.dart_tool/package_graph.json @@ -0,0 +1,257 @@ +{ + "roots": [ + "meteora" + ], + "packages": [ + { + "name": "meteora", + "version": "0.1.0", + "dependencies": [ + "solana" + ], + "devDependencies": [] + }, + { + "name": "solana", + "version": "0.31.2+1", + "dependencies": [ + "bip39", + "borsh_annotation", + "collection", + "convert", + "cryptography", + "decimal", + "ed25519_hd_key", + "freezed_annotation", + "http", + "json_annotation", + "typed_data", + "web_socket_channel" + ] + }, + { + "name": "web_socket_channel", + "version": "3.0.3", + "dependencies": [ + "async", + "crypto", + "stream_channel", + "web", + "web_socket" + ] + }, + { + "name": "typed_data", + "version": "1.4.0", + "dependencies": [ + "collection" + ] + }, + { + "name": "json_annotation", + "version": "4.9.0", + "dependencies": [ + "meta" + ] + }, + { + "name": "http", + "version": "1.5.0", + "dependencies": [ + "async", + "http_parser", + "meta", + "web" + ] + }, + { + "name": "freezed_annotation", + "version": "2.4.4", + "dependencies": [ + "collection", + "json_annotation", + "meta" + ] + }, + { + "name": "ed25519_hd_key", + "version": "2.3.0", + "dependencies": [ + "crypto", + "pinenacl" + ] + }, + { + "name": "decimal", + "version": "3.2.4", + "dependencies": [ + "intl", + "rational" + ] + }, + { + "name": "cryptography", + "version": "2.7.0", + "dependencies": [ + "collection", + "crypto", + "ffi", + "js", + "meta", + "typed_data" + ] + }, + { + "name": "convert", + "version": "3.1.2", + "dependencies": [ + "typed_data" + ] + }, + { + "name": "collection", + "version": "1.19.1", + "dependencies": [] + }, + { + "name": "borsh_annotation", + "version": "0.3.2", + "dependencies": [] + }, + { + "name": "bip39", + "version": "1.0.6", + "dependencies": [ + "crypto", + "hex", + "pointycastle" + ] + }, + { + "name": "web_socket", + "version": "1.0.1", + "dependencies": [ + "web" + ] + }, + { + "name": "web", + "version": "1.1.1", + "dependencies": [] + }, + { + "name": "stream_channel", + "version": "2.1.4", + "dependencies": [ + "async" + ] + }, + { + "name": "crypto", + "version": "3.0.6", + "dependencies": [ + "typed_data" + ] + }, + { + "name": "async", + "version": "2.13.0", + "dependencies": [ + "collection", + "meta" + ] + }, + { + "name": "meta", + "version": "1.17.0", + "dependencies": [] + }, + { + "name": "http_parser", + "version": "4.1.2", + "dependencies": [ + "collection", + "source_span", + "string_scanner", + "typed_data" + ] + }, + { + "name": "pinenacl", + "version": "0.6.0", + "dependencies": [] + }, + { + "name": "rational", + "version": "2.2.3", + "dependencies": [] + }, + { + "name": "intl", + "version": "0.20.2", + "dependencies": [ + "clock", + "meta", + "path" + ] + }, + { + "name": "js", + "version": "0.6.7", + "dependencies": [ + "meta" + ] + }, + { + "name": "ffi", + "version": "2.1.4", + "dependencies": [] + }, + { + "name": "hex", + "version": "0.2.0", + "dependencies": [] + }, + { + "name": "pointycastle", + "version": "3.9.1", + "dependencies": [ + "collection", + "convert", + "js" + ] + }, + { + "name": "string_scanner", + "version": "1.4.1", + "dependencies": [ + "source_span" + ] + }, + { + "name": "source_span", + "version": "1.10.1", + "dependencies": [ + "collection", + "path", + "term_glyph" + ] + }, + { + "name": "path", + "version": "1.9.1", + "dependencies": [] + }, + { + "name": "clock", + "version": "1.1.2", + "dependencies": [] + }, + { + "name": "term_glyph", + "version": "1.2.2", + "dependencies": [] + } + ], + "configVersion": 1 +} \ No newline at end of file diff --git a/e2e/meteora/idl.json b/e2e/meteora/idl.json new file mode 100644 index 0000000..27c85c5 --- /dev/null +++ b/e2e/meteora/idl.json @@ -0,0 +1,4868 @@ +{ + "version": "0.8.2", + "name": "lb_clmm", + "constants": [ + { + "name": "BASIS_POINT_MAX", + "type": "i32", + "value": "10000" + }, + { + "name": "MAX_BIN_PER_ARRAY", + "type": { + "defined": "usize" + }, + "value": "70" + }, + { + "name": "MAX_BIN_PER_POSITION", + "type": { + "defined": "usize" + }, + "value": "70" + }, + { + "name": "MIN_BIN_ID", + "type": "i32", + "value": "- 443636" + }, + { + "name": "MAX_BIN_ID", + "type": "i32", + "value": "443636" + }, + { + "name": "MAX_FEE_RATE", + "type": "u64", + "value": "100_000_000" + }, + { + "name": "FEE_PRECISION", + "type": "u64", + "value": "1_000_000_000" + }, + { + "name": "MAX_PROTOCOL_SHARE", + "type": "u16", + "value": "2_500" + }, + { + "name": "HOST_FEE_BPS", + "type": "u16", + "value": "2_000" + }, + { + "name": "NUM_REWARDS", + "type": { + "defined": "usize" + }, + "value": "2" + }, + { + "name": "MIN_REWARD_DURATION", + "type": "u64", + "value": "1" + }, + { + "name": "MAX_REWARD_DURATION", + "type": "u64", + "value": "31536000" + }, + { + "name": "EXTENSION_BINARRAY_BITMAP_SIZE", + "type": { + "defined": "usize" + }, + "value": "12" + }, + { + "name": "BIN_ARRAY_BITMAP_SIZE", + "type": "i32", + "value": "512" + }, + { + "name": "MAX_REWARD_BIN_SPLIT", + "type": { + "defined": "usize" + }, + "value": "15" + }, + { + "name": "MAX_BIN_STEP", + "type": "u16", + "value": "400" + }, + { + "name": "MAX_BASE_FEE", + "type": "u128", + "value": "100_000_000" + }, + { + "name": "MIN_BASE_FEE", + "type": "u128", + "value": "100_000" + }, + { + "name": "BIN_ARRAY", + "type": "bytes", + "value": "[98, 105, 110, 95, 97, 114, 114, 97, 121]" + }, + { + "name": "ORACLE", + "type": "bytes", + "value": "[111, 114, 97, 99, 108, 101]" + }, + { + "name": "BIN_ARRAY_BITMAP_SEED", + "type": "bytes", + "value": "[98, 105, 116, 109, 97, 112]" + }, + { + "name": "PRESET_PARAMETER", + "type": "bytes", + "value": "[112, 114, 101, 115, 101, 116, 95, 112, 97, 114, 97, 109, 101, 116, 101, 114]" + }, + { + "name": "POSITION", + "type": "bytes", + "value": "[112, 111, 115, 105, 116, 105, 111, 110]" + } + ], + "instructions": [ + { + "name": "initializeLbPair", + "accounts": [ + { + "name": "lbPair", + "isMut": true, + "isSigner": false + }, + { + "name": "binArrayBitmapExtension", + "isMut": true, + "isSigner": false, + "isOptional": true + }, + { + "name": "tokenMintX", + "isMut": false, + "isSigner": false + }, + { + "name": "tokenMintY", + "isMut": false, + "isSigner": false + }, + { + "name": "reserveX", + "isMut": true, + "isSigner": false + }, + { + "name": "reserveY", + "isMut": true, + "isSigner": false + }, + { + "name": "oracle", + "isMut": true, + "isSigner": false + }, + { + "name": "presetParameter", + "isMut": false, + "isSigner": false + }, + { + "name": "funder", + "isMut": true, + "isSigner": true + }, + { + "name": "tokenProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "systemProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "rent", + "isMut": false, + "isSigner": false + }, + { + "name": "eventAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "program", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "activeId", + "type": "i32" + }, + { + "name": "binStep", + "type": "u16" + } + ] + }, + { + "name": "initializePermissionLbPair", + "accounts": [ + { + "name": "base", + "isMut": false, + "isSigner": true + }, + { + "name": "lbPair", + "isMut": true, + "isSigner": false + }, + { + "name": "binArrayBitmapExtension", + "isMut": true, + "isSigner": false, + "isOptional": true + }, + { + "name": "tokenMintX", + "isMut": false, + "isSigner": false + }, + { + "name": "tokenMintY", + "isMut": false, + "isSigner": false + }, + { + "name": "reserveX", + "isMut": true, + "isSigner": false + }, + { + "name": "reserveY", + "isMut": true, + "isSigner": false + }, + { + "name": "oracle", + "isMut": true, + "isSigner": false + }, + { + "name": "admin", + "isMut": true, + "isSigner": true + }, + { + "name": "tokenProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "systemProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "rent", + "isMut": false, + "isSigner": false + }, + { + "name": "eventAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "program", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "ixData", + "type": { + "defined": "InitPermissionPairIx" + } + } + ] + }, + { + "name": "initializeCustomizablePermissionlessLbPair", + "accounts": [ + { + "name": "lbPair", + "isMut": true, + "isSigner": false + }, + { + "name": "binArrayBitmapExtension", + "isMut": true, + "isSigner": false, + "isOptional": true + }, + { + "name": "tokenMintX", + "isMut": false, + "isSigner": false + }, + { + "name": "tokenMintY", + "isMut": false, + "isSigner": false + }, + { + "name": "reserveX", + "isMut": true, + "isSigner": false + }, + { + "name": "reserveY", + "isMut": true, + "isSigner": false + }, + { + "name": "oracle", + "isMut": true, + "isSigner": false + }, + { + "name": "userTokenX", + "isMut": false, + "isSigner": false + }, + { + "name": "funder", + "isMut": true, + "isSigner": true + }, + { + "name": "tokenProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "systemProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "rent", + "isMut": false, + "isSigner": false + }, + { + "name": "eventAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "program", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "params", + "type": { + "defined": "CustomizableParams" + } + } + ] + }, + { + "name": "initializeBinArrayBitmapExtension", + "accounts": [ + { + "name": "lbPair", + "isMut": false, + "isSigner": false + }, + { + "name": "binArrayBitmapExtension", + "isMut": true, + "isSigner": false, + "docs": ["Initialize an account to store if a bin array is initialized."] + }, + { + "name": "funder", + "isMut": true, + "isSigner": true + }, + { + "name": "systemProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "rent", + "isMut": false, + "isSigner": false + } + ], + "args": [] + }, + { + "name": "initializeBinArray", + "accounts": [ + { + "name": "lbPair", + "isMut": false, + "isSigner": false + }, + { + "name": "binArray", + "isMut": true, + "isSigner": false + }, + { + "name": "funder", + "isMut": true, + "isSigner": true + }, + { + "name": "systemProgram", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "index", + "type": "i64" + } + ] + }, + { + "name": "addLiquidity", + "accounts": [ + { + "name": "position", + "isMut": true, + "isSigner": false + }, + { + "name": "lbPair", + "isMut": true, + "isSigner": false + }, + { + "name": "binArrayBitmapExtension", + "isMut": true, + "isSigner": false, + "isOptional": true + }, + { + "name": "userTokenX", + "isMut": true, + "isSigner": false + }, + { + "name": "userTokenY", + "isMut": true, + "isSigner": false + }, + { + "name": "reserveX", + "isMut": true, + "isSigner": false + }, + { + "name": "reserveY", + "isMut": true, + "isSigner": false + }, + { + "name": "tokenXMint", + "isMut": false, + "isSigner": false + }, + { + "name": "tokenYMint", + "isMut": false, + "isSigner": false + }, + { + "name": "binArrayLower", + "isMut": true, + "isSigner": false + }, + { + "name": "binArrayUpper", + "isMut": true, + "isSigner": false + }, + { + "name": "sender", + "isMut": false, + "isSigner": true + }, + { + "name": "tokenXProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "tokenYProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "eventAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "program", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "liquidityParameter", + "type": { + "defined": "LiquidityParameter" + } + } + ] + }, + { + "name": "addLiquidityByWeight", + "accounts": [ + { + "name": "position", + "isMut": true, + "isSigner": false + }, + { + "name": "lbPair", + "isMut": true, + "isSigner": false + }, + { + "name": "binArrayBitmapExtension", + "isMut": true, + "isSigner": false, + "isOptional": true + }, + { + "name": "userTokenX", + "isMut": true, + "isSigner": false + }, + { + "name": "userTokenY", + "isMut": true, + "isSigner": false + }, + { + "name": "reserveX", + "isMut": true, + "isSigner": false + }, + { + "name": "reserveY", + "isMut": true, + "isSigner": false + }, + { + "name": "tokenXMint", + "isMut": false, + "isSigner": false + }, + { + "name": "tokenYMint", + "isMut": false, + "isSigner": false + }, + { + "name": "binArrayLower", + "isMut": true, + "isSigner": false + }, + { + "name": "binArrayUpper", + "isMut": true, + "isSigner": false + }, + { + "name": "sender", + "isMut": false, + "isSigner": true + }, + { + "name": "tokenXProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "tokenYProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "eventAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "program", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "liquidityParameter", + "type": { + "defined": "LiquidityParameterByWeight" + } + } + ] + }, + { + "name": "addLiquidityByStrategy", + "accounts": [ + { + "name": "position", + "isMut": true, + "isSigner": false + }, + { + "name": "lbPair", + "isMut": true, + "isSigner": false + }, + { + "name": "binArrayBitmapExtension", + "isMut": true, + "isSigner": false, + "isOptional": true + }, + { + "name": "userTokenX", + "isMut": true, + "isSigner": false + }, + { + "name": "userTokenY", + "isMut": true, + "isSigner": false + }, + { + "name": "reserveX", + "isMut": true, + "isSigner": false + }, + { + "name": "reserveY", + "isMut": true, + "isSigner": false + }, + { + "name": "tokenXMint", + "isMut": false, + "isSigner": false + }, + { + "name": "tokenYMint", + "isMut": false, + "isSigner": false + }, + { + "name": "binArrayLower", + "isMut": true, + "isSigner": false + }, + { + "name": "binArrayUpper", + "isMut": true, + "isSigner": false + }, + { + "name": "sender", + "isMut": false, + "isSigner": true + }, + { + "name": "tokenXProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "tokenYProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "eventAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "program", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "liquidityParameter", + "type": { + "defined": "LiquidityParameterByStrategy" + } + } + ] + }, + { + "name": "addLiquidityByStrategyOneSide", + "accounts": [ + { + "name": "position", + "isMut": true, + "isSigner": false + }, + { + "name": "lbPair", + "isMut": true, + "isSigner": false + }, + { + "name": "binArrayBitmapExtension", + "isMut": true, + "isSigner": false, + "isOptional": true + }, + { + "name": "userToken", + "isMut": true, + "isSigner": false + }, + { + "name": "reserve", + "isMut": true, + "isSigner": false + }, + { + "name": "tokenMint", + "isMut": false, + "isSigner": false + }, + { + "name": "binArrayLower", + "isMut": true, + "isSigner": false + }, + { + "name": "binArrayUpper", + "isMut": true, + "isSigner": false + }, + { + "name": "sender", + "isMut": false, + "isSigner": true + }, + { + "name": "tokenProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "eventAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "program", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "liquidityParameter", + "type": { + "defined": "LiquidityParameterByStrategyOneSide" + } + } + ] + }, + { + "name": "addLiquidityOneSide", + "accounts": [ + { + "name": "position", + "isMut": true, + "isSigner": false + }, + { + "name": "lbPair", + "isMut": true, + "isSigner": false + }, + { + "name": "binArrayBitmapExtension", + "isMut": true, + "isSigner": false, + "isOptional": true + }, + { + "name": "userToken", + "isMut": true, + "isSigner": false + }, + { + "name": "reserve", + "isMut": true, + "isSigner": false + }, + { + "name": "tokenMint", + "isMut": false, + "isSigner": false + }, + { + "name": "binArrayLower", + "isMut": true, + "isSigner": false + }, + { + "name": "binArrayUpper", + "isMut": true, + "isSigner": false + }, + { + "name": "sender", + "isMut": false, + "isSigner": true + }, + { + "name": "tokenProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "eventAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "program", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "liquidityParameter", + "type": { + "defined": "LiquidityOneSideParameter" + } + } + ] + }, + { + "name": "removeLiquidity", + "accounts": [ + { + "name": "position", + "isMut": true, + "isSigner": false + }, + { + "name": "lbPair", + "isMut": true, + "isSigner": false + }, + { + "name": "binArrayBitmapExtension", + "isMut": true, + "isSigner": false, + "isOptional": true + }, + { + "name": "userTokenX", + "isMut": true, + "isSigner": false + }, + { + "name": "userTokenY", + "isMut": true, + "isSigner": false + }, + { + "name": "reserveX", + "isMut": true, + "isSigner": false + }, + { + "name": "reserveY", + "isMut": true, + "isSigner": false + }, + { + "name": "tokenXMint", + "isMut": false, + "isSigner": false + }, + { + "name": "tokenYMint", + "isMut": false, + "isSigner": false + }, + { + "name": "binArrayLower", + "isMut": true, + "isSigner": false + }, + { + "name": "binArrayUpper", + "isMut": true, + "isSigner": false + }, + { + "name": "sender", + "isMut": false, + "isSigner": true + }, + { + "name": "tokenXProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "tokenYProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "eventAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "program", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "binLiquidityRemoval", + "type": { + "vec": { + "defined": "BinLiquidityReduction" + } + } + } + ] + }, + { + "name": "initializePosition", + "accounts": [ + { + "name": "payer", + "isMut": true, + "isSigner": true + }, + { + "name": "position", + "isMut": true, + "isSigner": true + }, + { + "name": "lbPair", + "isMut": false, + "isSigner": false + }, + { + "name": "owner", + "isMut": false, + "isSigner": true + }, + { + "name": "systemProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "rent", + "isMut": false, + "isSigner": false + }, + { + "name": "eventAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "program", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "lowerBinId", + "type": "i32" + }, + { + "name": "width", + "type": "i32" + } + ] + }, + { + "name": "initializePositionPda", + "accounts": [ + { + "name": "payer", + "isMut": true, + "isSigner": true + }, + { + "name": "base", + "isMut": false, + "isSigner": true + }, + { + "name": "position", + "isMut": true, + "isSigner": false + }, + { + "name": "lbPair", + "isMut": false, + "isSigner": false + }, + { + "name": "owner", + "isMut": false, + "isSigner": true, + "docs": ["owner"] + }, + { + "name": "systemProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "rent", + "isMut": false, + "isSigner": false + }, + { + "name": "eventAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "program", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "lowerBinId", + "type": "i32" + }, + { + "name": "width", + "type": "i32" + } + ] + }, + { + "name": "initializePositionByOperator", + "accounts": [ + { + "name": "payer", + "isMut": true, + "isSigner": true + }, + { + "name": "base", + "isMut": false, + "isSigner": true + }, + { + "name": "position", + "isMut": true, + "isSigner": false + }, + { + "name": "lbPair", + "isMut": false, + "isSigner": false + }, + { + "name": "owner", + "isMut": false, + "isSigner": false + }, + { + "name": "operator", + "isMut": false, + "isSigner": true, + "docs": ["operator"] + }, + { + "name": "operatorTokenX", + "isMut": false, + "isSigner": false + }, + { + "name": "ownerTokenX", + "isMut": false, + "isSigner": false + }, + { + "name": "systemProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "eventAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "program", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "lowerBinId", + "type": "i32" + }, + { + "name": "width", + "type": "i32" + }, + { + "name": "feeOwner", + "type": "publicKey" + }, + { + "name": "lockReleasePoint", + "type": "u64" + } + ] + }, + { + "name": "updatePositionOperator", + "accounts": [ + { + "name": "position", + "isMut": true, + "isSigner": false + }, + { + "name": "owner", + "isMut": false, + "isSigner": true + }, + { + "name": "eventAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "program", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "operator", + "type": "publicKey" + } + ] + }, + { + "name": "swap", + "accounts": [ + { + "name": "lbPair", + "isMut": true, + "isSigner": false + }, + { + "name": "binArrayBitmapExtension", + "isMut": false, + "isSigner": false, + "isOptional": true + }, + { + "name": "reserveX", + "isMut": true, + "isSigner": false + }, + { + "name": "reserveY", + "isMut": true, + "isSigner": false + }, + { + "name": "userTokenIn", + "isMut": true, + "isSigner": false + }, + { + "name": "userTokenOut", + "isMut": true, + "isSigner": false + }, + { + "name": "tokenXMint", + "isMut": false, + "isSigner": false + }, + { + "name": "tokenYMint", + "isMut": false, + "isSigner": false + }, + { + "name": "oracle", + "isMut": true, + "isSigner": false + }, + { + "name": "hostFeeIn", + "isMut": true, + "isSigner": false, + "isOptional": true + }, + { + "name": "user", + "isMut": false, + "isSigner": true + }, + { + "name": "tokenXProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "tokenYProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "eventAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "program", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "amountIn", + "type": "u64" + }, + { + "name": "minAmountOut", + "type": "u64" + } + ] + }, + { + "name": "swapExactOut", + "accounts": [ + { + "name": "lbPair", + "isMut": true, + "isSigner": false + }, + { + "name": "binArrayBitmapExtension", + "isMut": false, + "isSigner": false, + "isOptional": true + }, + { + "name": "reserveX", + "isMut": true, + "isSigner": false + }, + { + "name": "reserveY", + "isMut": true, + "isSigner": false + }, + { + "name": "userTokenIn", + "isMut": true, + "isSigner": false + }, + { + "name": "userTokenOut", + "isMut": true, + "isSigner": false + }, + { + "name": "tokenXMint", + "isMut": false, + "isSigner": false + }, + { + "name": "tokenYMint", + "isMut": false, + "isSigner": false + }, + { + "name": "oracle", + "isMut": true, + "isSigner": false + }, + { + "name": "hostFeeIn", + "isMut": true, + "isSigner": false, + "isOptional": true + }, + { + "name": "user", + "isMut": false, + "isSigner": true + }, + { + "name": "tokenXProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "tokenYProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "eventAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "program", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "maxInAmount", + "type": "u64" + }, + { + "name": "outAmount", + "type": "u64" + } + ] + }, + { + "name": "swapWithPriceImpact", + "accounts": [ + { + "name": "lbPair", + "isMut": true, + "isSigner": false + }, + { + "name": "binArrayBitmapExtension", + "isMut": false, + "isSigner": false, + "isOptional": true + }, + { + "name": "reserveX", + "isMut": true, + "isSigner": false + }, + { + "name": "reserveY", + "isMut": true, + "isSigner": false + }, + { + "name": "userTokenIn", + "isMut": true, + "isSigner": false + }, + { + "name": "userTokenOut", + "isMut": true, + "isSigner": false + }, + { + "name": "tokenXMint", + "isMut": false, + "isSigner": false + }, + { + "name": "tokenYMint", + "isMut": false, + "isSigner": false + }, + { + "name": "oracle", + "isMut": true, + "isSigner": false + }, + { + "name": "hostFeeIn", + "isMut": true, + "isSigner": false, + "isOptional": true + }, + { + "name": "user", + "isMut": false, + "isSigner": true + }, + { + "name": "tokenXProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "tokenYProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "eventAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "program", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "amountIn", + "type": "u64" + }, + { + "name": "activeId", + "type": { + "option": "i32" + } + }, + { + "name": "maxPriceImpactBps", + "type": "u16" + } + ] + }, + { + "name": "withdrawProtocolFee", + "accounts": [ + { + "name": "lbPair", + "isMut": true, + "isSigner": false + }, + { + "name": "reserveX", + "isMut": true, + "isSigner": false + }, + { + "name": "reserveY", + "isMut": true, + "isSigner": false + }, + { + "name": "tokenXMint", + "isMut": false, + "isSigner": false + }, + { + "name": "tokenYMint", + "isMut": false, + "isSigner": false + }, + { + "name": "receiverTokenX", + "isMut": true, + "isSigner": false + }, + { + "name": "receiverTokenY", + "isMut": true, + "isSigner": false + }, + { + "name": "tokenXProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "tokenYProgram", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "amountX", + "type": "u64" + }, + { + "name": "amountY", + "type": "u64" + } + ] + }, + { + "name": "initializeReward", + "accounts": [ + { + "name": "lbPair", + "isMut": true, + "isSigner": false + }, + { + "name": "rewardVault", + "isMut": true, + "isSigner": false + }, + { + "name": "rewardMint", + "isMut": false, + "isSigner": false + }, + { + "name": "admin", + "isMut": true, + "isSigner": true + }, + { + "name": "tokenProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "systemProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "rent", + "isMut": false, + "isSigner": false + }, + { + "name": "eventAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "program", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "rewardIndex", + "type": "u64" + }, + { + "name": "rewardDuration", + "type": "u64" + }, + { + "name": "funder", + "type": "publicKey" + } + ] + }, + { + "name": "fundReward", + "accounts": [ + { + "name": "lbPair", + "isMut": true, + "isSigner": false + }, + { + "name": "rewardVault", + "isMut": true, + "isSigner": false + }, + { + "name": "rewardMint", + "isMut": false, + "isSigner": false + }, + { + "name": "funderTokenAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "funder", + "isMut": false, + "isSigner": true + }, + { + "name": "binArray", + "isMut": true, + "isSigner": false + }, + { + "name": "tokenProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "eventAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "program", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "rewardIndex", + "type": "u64" + }, + { + "name": "amount", + "type": "u64" + }, + { + "name": "carryForward", + "type": "bool" + } + ] + }, + { + "name": "updateRewardFunder", + "accounts": [ + { + "name": "lbPair", + "isMut": true, + "isSigner": false + }, + { + "name": "admin", + "isMut": false, + "isSigner": true + }, + { + "name": "eventAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "program", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "rewardIndex", + "type": "u64" + }, + { + "name": "newFunder", + "type": "publicKey" + } + ] + }, + { + "name": "updateRewardDuration", + "accounts": [ + { + "name": "lbPair", + "isMut": true, + "isSigner": false + }, + { + "name": "admin", + "isMut": false, + "isSigner": true + }, + { + "name": "binArray", + "isMut": true, + "isSigner": false + }, + { + "name": "eventAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "program", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "rewardIndex", + "type": "u64" + }, + { + "name": "newDuration", + "type": "u64" + } + ] + }, + { + "name": "claimReward", + "accounts": [ + { + "name": "lbPair", + "isMut": true, + "isSigner": false + }, + { + "name": "position", + "isMut": true, + "isSigner": false + }, + { + "name": "binArrayLower", + "isMut": true, + "isSigner": false + }, + { + "name": "binArrayUpper", + "isMut": true, + "isSigner": false + }, + { + "name": "sender", + "isMut": false, + "isSigner": true + }, + { + "name": "rewardVault", + "isMut": true, + "isSigner": false + }, + { + "name": "rewardMint", + "isMut": false, + "isSigner": false + }, + { + "name": "userTokenAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "tokenProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "eventAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "program", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "rewardIndex", + "type": "u64" + } + ] + }, + { + "name": "claimFee", + "accounts": [ + { + "name": "lbPair", + "isMut": true, + "isSigner": false + }, + { + "name": "position", + "isMut": true, + "isSigner": false + }, + { + "name": "binArrayLower", + "isMut": true, + "isSigner": false + }, + { + "name": "binArrayUpper", + "isMut": true, + "isSigner": false + }, + { + "name": "sender", + "isMut": false, + "isSigner": true + }, + { + "name": "reserveX", + "isMut": true, + "isSigner": false + }, + { + "name": "reserveY", + "isMut": true, + "isSigner": false + }, + { + "name": "userTokenX", + "isMut": true, + "isSigner": false + }, + { + "name": "userTokenY", + "isMut": true, + "isSigner": false + }, + { + "name": "tokenXMint", + "isMut": false, + "isSigner": false + }, + { + "name": "tokenYMint", + "isMut": false, + "isSigner": false + }, + { + "name": "tokenProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "eventAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "program", + "isMut": false, + "isSigner": false + } + ], + "args": [] + }, + { + "name": "closePosition", + "accounts": [ + { + "name": "position", + "isMut": true, + "isSigner": false + }, + { + "name": "lbPair", + "isMut": true, + "isSigner": false + }, + { + "name": "binArrayLower", + "isMut": true, + "isSigner": false + }, + { + "name": "binArrayUpper", + "isMut": true, + "isSigner": false + }, + { + "name": "sender", + "isMut": false, + "isSigner": true + }, + { + "name": "rentReceiver", + "isMut": true, + "isSigner": false + }, + { + "name": "eventAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "program", + "isMut": false, + "isSigner": false + } + ], + "args": [] + }, + { + "name": "updateFeeParameters", + "accounts": [ + { + "name": "lbPair", + "isMut": true, + "isSigner": false + }, + { + "name": "admin", + "isMut": false, + "isSigner": true + }, + { + "name": "eventAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "program", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "feeParameter", + "type": { + "defined": "FeeParameter" + } + } + ] + }, + { + "name": "increaseOracleLength", + "accounts": [ + { + "name": "oracle", + "isMut": true, + "isSigner": false + }, + { + "name": "funder", + "isMut": true, + "isSigner": true + }, + { + "name": "systemProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "eventAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "program", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "lengthToAdd", + "type": "u64" + } + ] + }, + { + "name": "initializePresetParameter", + "accounts": [ + { + "name": "presetParameter", + "isMut": true, + "isSigner": false + }, + { + "name": "admin", + "isMut": true, + "isSigner": true + }, + { + "name": "systemProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "rent", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "ix", + "type": { + "defined": "InitPresetParametersIx" + } + } + ] + }, + { + "name": "closePresetParameter", + "accounts": [ + { + "name": "presetParameter", + "isMut": true, + "isSigner": false + }, + { + "name": "admin", + "isMut": true, + "isSigner": true + }, + { + "name": "rentReceiver", + "isMut": true, + "isSigner": false + } + ], + "args": [] + }, + { + "name": "removeAllLiquidity", + "accounts": [ + { + "name": "position", + "isMut": true, + "isSigner": false + }, + { + "name": "lbPair", + "isMut": true, + "isSigner": false + }, + { + "name": "binArrayBitmapExtension", + "isMut": true, + "isSigner": false, + "isOptional": true + }, + { + "name": "userTokenX", + "isMut": true, + "isSigner": false + }, + { + "name": "userTokenY", + "isMut": true, + "isSigner": false + }, + { + "name": "reserveX", + "isMut": true, + "isSigner": false + }, + { + "name": "reserveY", + "isMut": true, + "isSigner": false + }, + { + "name": "tokenXMint", + "isMut": false, + "isSigner": false + }, + { + "name": "tokenYMint", + "isMut": false, + "isSigner": false + }, + { + "name": "binArrayLower", + "isMut": true, + "isSigner": false + }, + { + "name": "binArrayUpper", + "isMut": true, + "isSigner": false + }, + { + "name": "sender", + "isMut": false, + "isSigner": true + }, + { + "name": "tokenXProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "tokenYProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "eventAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "program", + "isMut": false, + "isSigner": false + } + ], + "args": [] + }, + { + "name": "togglePairStatus", + "accounts": [ + { + "name": "lbPair", + "isMut": true, + "isSigner": false + }, + { + "name": "admin", + "isMut": false, + "isSigner": true + } + ], + "args": [] + }, + { + "name": "migratePosition", + "accounts": [ + { + "name": "positionV2", + "isMut": true, + "isSigner": true + }, + { + "name": "positionV1", + "isMut": true, + "isSigner": false + }, + { + "name": "lbPair", + "isMut": false, + "isSigner": false + }, + { + "name": "binArrayLower", + "isMut": true, + "isSigner": false + }, + { + "name": "binArrayUpper", + "isMut": true, + "isSigner": false + }, + { + "name": "owner", + "isMut": true, + "isSigner": true + }, + { + "name": "systemProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "rentReceiver", + "isMut": true, + "isSigner": false + }, + { + "name": "eventAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "program", + "isMut": false, + "isSigner": false + } + ], + "args": [] + }, + { + "name": "migrateBinArray", + "accounts": [ + { + "name": "lbPair", + "isMut": false, + "isSigner": false + } + ], + "args": [] + }, + { + "name": "updateFeesAndRewards", + "accounts": [ + { + "name": "position", + "isMut": true, + "isSigner": false + }, + { + "name": "lbPair", + "isMut": true, + "isSigner": false + }, + { + "name": "binArrayLower", + "isMut": true, + "isSigner": false + }, + { + "name": "binArrayUpper", + "isMut": true, + "isSigner": false + }, + { + "name": "owner", + "isMut": false, + "isSigner": true + } + ], + "args": [] + }, + { + "name": "withdrawIneligibleReward", + "accounts": [ + { + "name": "lbPair", + "isMut": true, + "isSigner": false + }, + { + "name": "rewardVault", + "isMut": true, + "isSigner": false + }, + { + "name": "rewardMint", + "isMut": false, + "isSigner": false + }, + { + "name": "funderTokenAccount", + "isMut": true, + "isSigner": false + }, + { + "name": "funder", + "isMut": false, + "isSigner": true + }, + { + "name": "binArray", + "isMut": true, + "isSigner": false + }, + { + "name": "tokenProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "eventAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "program", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "rewardIndex", + "type": "u64" + } + ] + }, + { + "name": "setActivationPoint", + "accounts": [ + { + "name": "lbPair", + "isMut": true, + "isSigner": false + }, + { + "name": "admin", + "isMut": true, + "isSigner": true + } + ], + "args": [ + { + "name": "activationPoint", + "type": "u64" + } + ] + }, + { + "name": "removeLiquidityByRange", + "accounts": [ + { + "name": "position", + "isMut": true, + "isSigner": false + }, + { + "name": "lbPair", + "isMut": true, + "isSigner": false + }, + { + "name": "binArrayBitmapExtension", + "isMut": true, + "isSigner": false, + "isOptional": true + }, + { + "name": "userTokenX", + "isMut": true, + "isSigner": false + }, + { + "name": "userTokenY", + "isMut": true, + "isSigner": false + }, + { + "name": "reserveX", + "isMut": true, + "isSigner": false + }, + { + "name": "reserveY", + "isMut": true, + "isSigner": false + }, + { + "name": "tokenXMint", + "isMut": false, + "isSigner": false + }, + { + "name": "tokenYMint", + "isMut": false, + "isSigner": false + }, + { + "name": "binArrayLower", + "isMut": true, + "isSigner": false + }, + { + "name": "binArrayUpper", + "isMut": true, + "isSigner": false + }, + { + "name": "sender", + "isMut": false, + "isSigner": true + }, + { + "name": "tokenXProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "tokenYProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "eventAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "program", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "fromBinId", + "type": "i32" + }, + { + "name": "toBinId", + "type": "i32" + }, + { + "name": "bpsToRemove", + "type": "u16" + } + ] + }, + { + "name": "addLiquidityOneSidePrecise", + "accounts": [ + { + "name": "position", + "isMut": true, + "isSigner": false + }, + { + "name": "lbPair", + "isMut": true, + "isSigner": false + }, + { + "name": "binArrayBitmapExtension", + "isMut": true, + "isSigner": false, + "isOptional": true + }, + { + "name": "userToken", + "isMut": true, + "isSigner": false + }, + { + "name": "reserve", + "isMut": true, + "isSigner": false + }, + { + "name": "tokenMint", + "isMut": false, + "isSigner": false + }, + { + "name": "binArrayLower", + "isMut": true, + "isSigner": false + }, + { + "name": "binArrayUpper", + "isMut": true, + "isSigner": false + }, + { + "name": "sender", + "isMut": false, + "isSigner": true + }, + { + "name": "tokenProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "eventAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "program", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "parameter", + "type": { + "defined": "AddLiquiditySingleSidePreciseParameter" + } + } + ] + }, + { + "name": "goToABin", + "accounts": [ + { + "name": "lbPair", + "isMut": true, + "isSigner": false + }, + { + "name": "binArrayBitmapExtension", + "isMut": false, + "isSigner": false, + "isOptional": true + }, + { + "name": "fromBinArray", + "isMut": false, + "isSigner": false, + "isOptional": true + }, + { + "name": "toBinArray", + "isMut": false, + "isSigner": false, + "isOptional": true + }, + { + "name": "eventAuthority", + "isMut": false, + "isSigner": false + }, + { + "name": "program", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "binId", + "type": "i32" + } + ] + }, + { + "name": "setPreActivationDuration", + "accounts": [ + { + "name": "lbPair", + "isMut": true, + "isSigner": false + }, + { + "name": "creator", + "isMut": false, + "isSigner": true + } + ], + "args": [ + { + "name": "preActivationDuration", + "type": "u64" + } + ] + }, + { + "name": "setPreActivationSwapAddress", + "accounts": [ + { + "name": "lbPair", + "isMut": true, + "isSigner": false + }, + { + "name": "creator", + "isMut": false, + "isSigner": true + } + ], + "args": [ + { + "name": "preActivationSwapAddress", + "type": "publicKey" + } + ] + } + ], + "accounts": [ + { + "name": "BinArrayBitmapExtension", + "type": { + "kind": "struct", + "fields": [ + { + "name": "lbPair", + "type": "publicKey" + }, + { + "name": "positiveBinArrayBitmap", + "docs": ["Packed initialized bin array state for start_bin_index is positive"], + "type": { + "array": [ + { + "array": ["u64", 8] + }, + 12 + ] + } + }, + { + "name": "negativeBinArrayBitmap", + "docs": ["Packed initialized bin array state for start_bin_index is negative"], + "type": { + "array": [ + { + "array": ["u64", 8] + }, + 12 + ] + } + } + ] + } + }, + { + "name": "BinArray", + "docs": [ + "An account to contain a range of bin. For example: Bin 100 <-> 200.", + "For example:", + "BinArray index: 0 contains bin 0 <-> 599", + "index: 2 contains bin 600 <-> 1199, ..." + ], + "type": { + "kind": "struct", + "fields": [ + { + "name": "index", + "type": "i64" + }, + { + "name": "version", + "docs": ["Version of binArray"], + "type": "u8" + }, + { + "name": "padding", + "type": { + "array": ["u8", 7] + } + }, + { + "name": "lbPair", + "type": "publicKey" + }, + { + "name": "bins", + "type": { + "array": [ + { + "defined": "Bin" + }, + 70 + ] + } + } + ] + } + }, + { + "name": "LbPair", + "type": { + "kind": "struct", + "fields": [ + { + "name": "parameters", + "type": { + "defined": "StaticParameters" + } + }, + { + "name": "vParameters", + "type": { + "defined": "VariableParameters" + } + }, + { + "name": "bumpSeed", + "type": { + "array": ["u8", 1] + } + }, + { + "name": "binStepSeed", + "docs": ["Bin step signer seed"], + "type": { + "array": ["u8", 2] + } + }, + { + "name": "pairType", + "docs": ["Type of the pair"], + "type": "u8" + }, + { + "name": "activeId", + "docs": ["Active bin id"], + "type": "i32" + }, + { + "name": "binStep", + "docs": ["Bin step. Represent the price increment / decrement."], + "type": "u16" + }, + { + "name": "status", + "docs": ["Status of the pair. Check PairStatus enum."], + "type": "u8" + }, + { + "name": "requireBaseFactorSeed", + "docs": ["Require base factor seed"], + "type": "u8" + }, + { + "name": "baseFactorSeed", + "docs": ["Base factor seed"], + "type": { + "array": ["u8", 2] + } + }, + { + "name": "activationType", + "docs": ["Activation type"], + "type": "u8" + }, + { + "name": "padding0", + "docs": ["padding 0"], + "type": "u8" + }, + { + "name": "tokenXMint", + "docs": ["Token X mint"], + "type": "publicKey" + }, + { + "name": "tokenYMint", + "docs": ["Token Y mint"], + "type": "publicKey" + }, + { + "name": "reserveX", + "docs": ["LB token X vault"], + "type": "publicKey" + }, + { + "name": "reserveY", + "docs": ["LB token Y vault"], + "type": "publicKey" + }, + { + "name": "protocolFee", + "docs": ["Uncollected protocol fee"], + "type": { + "defined": "ProtocolFee" + } + }, + { + "name": "padding1", + "docs": ["_padding_1, previous Fee owner, BE CAREFUL FOR TOMBSTONE WHEN REUSE !!"], + "type": { + "array": ["u8", 32] + } + }, + { + "name": "rewardInfos", + "docs": ["Farming reward information"], + "type": { + "array": [ + { + "defined": "RewardInfo" + }, + 2 + ] + } + }, + { + "name": "oracle", + "docs": ["Oracle pubkey"], + "type": "publicKey" + }, + { + "name": "binArrayBitmap", + "docs": ["Packed initialized bin array state"], + "type": { + "array": ["u64", 16] + } + }, + { + "name": "lastUpdatedAt", + "docs": ["Last time the pool fee parameter was updated"], + "type": "i64" + }, + { + "name": "padding2", + "docs": ["_padding_2, previous whitelisted_wallet, BE CAREFUL FOR TOMBSTONE WHEN REUSE !!"], + "type": { + "array": ["u8", 32] + } + }, + { + "name": "preActivationSwapAddress", + "docs": [ + "Address allowed to swap when the current point is greater than or equal to the pre-activation point. The pre-activation point is calculated as `activation_point - pre_activation_duration`." + ], + "type": "publicKey" + }, + { + "name": "baseKey", + "docs": ["Base keypair. Only required for permission pair"], + "type": "publicKey" + }, + { + "name": "activationPoint", + "docs": ["Time point to enable the pair. Only applicable for permission pair."], + "type": "u64" + }, + { + "name": "preActivationDuration", + "docs": [ + "Duration before activation activation_point. Used to calculate pre-activation time point for pre_activation_swap_address" + ], + "type": "u64" + }, + { + "name": "padding3", + "docs": [ + "_padding 3 is reclaimed free space from swap_cap_deactivate_point and swap_cap_amount before, BE CAREFUL FOR TOMBSTONE WHEN REUSE !!" + ], + "type": { + "array": ["u8", 8] + } + }, + { + "name": "padding4", + "docs": ["_padding_4, previous lock_duration, BE CAREFUL FOR TOMBSTONE WHEN REUSE !!"], + "type": "u64" + }, + { + "name": "creator", + "docs": ["Pool creator"], + "type": "publicKey" + }, + { + "name": "reserved", + "docs": ["Reserved space for future use"], + "type": { + "array": ["u8", 24] + } + } + ] + } + }, + { + "name": "Oracle", + "type": { + "kind": "struct", + "fields": [ + { + "name": "idx", + "docs": ["Index of latest observation"], + "type": "u64" + }, + { + "name": "activeSize", + "docs": ["Size of active sample. Active sample is initialized observation."], + "type": "u64" + }, + { + "name": "length", + "docs": ["Number of observations"], + "type": "u64" + } + ] + } + }, + { + "name": "Position", + "type": { + "kind": "struct", + "fields": [ + { + "name": "lbPair", + "docs": ["The LB pair of this position"], + "type": "publicKey" + }, + { + "name": "owner", + "docs": ["Owner of the position. Client rely on this to to fetch their positions."], + "type": "publicKey" + }, + { + "name": "liquidityShares", + "docs": [ + "Liquidity shares of this position in bins (lower_bin_id <-> upper_bin_id). This is the same as LP concept." + ], + "type": { + "array": ["u64", 70] + } + }, + { + "name": "rewardInfos", + "docs": ["Farming reward information"], + "type": { + "array": [ + { + "defined": "UserRewardInfo" + }, + 70 + ] + } + }, + { + "name": "feeInfos", + "docs": ["Swap fee to claim information"], + "type": { + "array": [ + { + "defined": "FeeInfo" + }, + 70 + ] + } + }, + { + "name": "lowerBinId", + "docs": ["Lower bin ID"], + "type": "i32" + }, + { + "name": "upperBinId", + "docs": ["Upper bin ID"], + "type": "i32" + }, + { + "name": "lastUpdatedAt", + "docs": ["Last updated timestamp"], + "type": "i64" + }, + { + "name": "totalClaimedFeeXAmount", + "docs": ["Total claimed token fee X"], + "type": "u64" + }, + { + "name": "totalClaimedFeeYAmount", + "docs": ["Total claimed token fee Y"], + "type": "u64" + }, + { + "name": "totalClaimedRewards", + "docs": ["Total claimed rewards"], + "type": { + "array": ["u64", 2] + } + }, + { + "name": "reserved", + "docs": ["Reserved space for future use"], + "type": { + "array": ["u8", 160] + } + } + ] + } + }, + { + "name": "PositionV2", + "type": { + "kind": "struct", + "fields": [ + { + "name": "lbPair", + "docs": ["The LB pair of this position"], + "type": "publicKey" + }, + { + "name": "owner", + "docs": ["Owner of the position. Client rely on this to to fetch their positions."], + "type": "publicKey" + }, + { + "name": "liquidityShares", + "docs": [ + "Liquidity shares of this position in bins (lower_bin_id <-> upper_bin_id). This is the same as LP concept." + ], + "type": { + "array": ["u128", 70] + } + }, + { + "name": "rewardInfos", + "docs": ["Farming reward information"], + "type": { + "array": [ + { + "defined": "UserRewardInfo" + }, + 70 + ] + } + }, + { + "name": "feeInfos", + "docs": ["Swap fee to claim information"], + "type": { + "array": [ + { + "defined": "FeeInfo" + }, + 70 + ] + } + }, + { + "name": "lowerBinId", + "docs": ["Lower bin ID"], + "type": "i32" + }, + { + "name": "upperBinId", + "docs": ["Upper bin ID"], + "type": "i32" + }, + { + "name": "lastUpdatedAt", + "docs": ["Last updated timestamp"], + "type": "i64" + }, + { + "name": "totalClaimedFeeXAmount", + "docs": ["Total claimed token fee X"], + "type": "u64" + }, + { + "name": "totalClaimedFeeYAmount", + "docs": ["Total claimed token fee Y"], + "type": "u64" + }, + { + "name": "totalClaimedRewards", + "docs": ["Total claimed rewards"], + "type": { + "array": ["u64", 2] + } + }, + { + "name": "operator", + "docs": ["Operator of position"], + "type": "publicKey" + }, + { + "name": "lockReleasePoint", + "docs": ["Time point which the locked liquidity can be withdraw"], + "type": "u64" + }, + { + "name": "padding0", + "docs": [ + "_padding_0, previous subjected_to_bootstrap_liquidity_locking, BE CAREFUL FOR TOMBSTONE WHEN REUSE !!" + ], + "type": "u8" + }, + { + "name": "feeOwner", + "docs": [ + "Address is able to claim fee in this position, only valid for bootstrap_liquidity_position" + ], + "type": "publicKey" + }, + { + "name": "reserved", + "docs": ["Reserved space for future use"], + "type": { + "array": ["u8", 87] + } + } + ] + } + }, + { + "name": "PresetParameter", + "type": { + "kind": "struct", + "fields": [ + { + "name": "binStep", + "docs": ["Bin step. Represent the price increment / decrement."], + "type": "u16" + }, + { + "name": "baseFactor", + "docs": ["Used for base fee calculation. base_fee_rate = base_factor * bin_step"], + "type": "u16" + }, + { + "name": "filterPeriod", + "docs": ["Filter period determine high frequency trading time window."], + "type": "u16" + }, + { + "name": "decayPeriod", + "docs": ["Decay period determine when the volatile fee start decay / decrease."], + "type": "u16" + }, + { + "name": "reductionFactor", + "docs": ["Reduction factor controls the volatile fee rate decrement rate."], + "type": "u16" + }, + { + "name": "variableFeeControl", + "docs": ["Used to scale the variable fee component depending on the dynamic of the market"], + "type": "u32" + }, + { + "name": "maxVolatilityAccumulator", + "docs": ["Maximum number of bin crossed can be accumulated. Used to cap volatile fee rate."], + "type": "u32" + }, + { + "name": "minBinId", + "docs": ["Min bin id supported by the pool based on the configured bin step."], + "type": "i32" + }, + { + "name": "maxBinId", + "docs": ["Max bin id supported by the pool based on the configured bin step."], + "type": "i32" + }, + { + "name": "protocolShare", + "docs": [ + "Portion of swap fees retained by the protocol by controlling protocol_share parameter. protocol_swap_fee = protocol_share * total_swap_fee" + ], + "type": "u16" + } + ] + } + } + ], + "types": [ + { + "name": "InitPresetParametersIx", + "type": { + "kind": "struct", + "fields": [ + { + "name": "binStep", + "docs": ["Bin step. Represent the price increment / decrement."], + "type": "u16" + }, + { + "name": "baseFactor", + "docs": ["Used for base fee calculation. base_fee_rate = base_factor * bin_step"], + "type": "u16" + }, + { + "name": "filterPeriod", + "docs": ["Filter period determine high frequency trading time window."], + "type": "u16" + }, + { + "name": "decayPeriod", + "docs": ["Decay period determine when the volatile fee start decay / decrease."], + "type": "u16" + }, + { + "name": "reductionFactor", + "docs": ["Reduction factor controls the volatile fee rate decrement rate."], + "type": "u16" + }, + { + "name": "variableFeeControl", + "docs": ["Used to scale the variable fee component depending on the dynamic of the market"], + "type": "u32" + }, + { + "name": "maxVolatilityAccumulator", + "docs": ["Maximum number of bin crossed can be accumulated. Used to cap volatile fee rate."], + "type": "u32" + }, + { + "name": "minBinId", + "docs": ["Min bin id supported by the pool based on the configured bin step."], + "type": "i32" + }, + { + "name": "maxBinId", + "docs": ["Max bin id supported by the pool based on the configured bin step."], + "type": "i32" + }, + { + "name": "protocolShare", + "docs": [ + "Portion of swap fees retained by the protocol by controlling protocol_share parameter. protocol_swap_fee = protocol_share * total_swap_fee" + ], + "type": "u16" + } + ] + } + }, + { + "name": "FeeParameter", + "type": { + "kind": "struct", + "fields": [ + { + "name": "protocolShare", + "docs": [ + "Portion of swap fees retained by the protocol by controlling protocol_share parameter. protocol_swap_fee = protocol_share * total_swap_fee" + ], + "type": "u16" + }, + { + "name": "baseFactor", + "docs": ["Base factor for base fee rate"], + "type": "u16" + } + ] + } + }, + { + "name": "LiquidityParameterByStrategyOneSide", + "type": { + "kind": "struct", + "fields": [ + { + "name": "amount", + "docs": ["Amount of X token or Y token to deposit"], + "type": "u64" + }, + { + "name": "activeId", + "docs": ["Active bin that integrator observe off-chain"], + "type": "i32" + }, + { + "name": "maxActiveBinSlippage", + "docs": ["max active bin slippage allowed"], + "type": "i32" + }, + { + "name": "strategyParameters", + "docs": ["strategy parameters"], + "type": { + "defined": "StrategyParameters" + } + } + ] + } + }, + { + "name": "LiquidityParameterByStrategy", + "type": { + "kind": "struct", + "fields": [ + { + "name": "amountX", + "docs": ["Amount of X token to deposit"], + "type": "u64" + }, + { + "name": "amountY", + "docs": ["Amount of Y token to deposit"], + "type": "u64" + }, + { + "name": "activeId", + "docs": ["Active bin that integrator observe off-chain"], + "type": "i32" + }, + { + "name": "maxActiveBinSlippage", + "docs": ["max active bin slippage allowed"], + "type": "i32" + }, + { + "name": "strategyParameters", + "docs": ["strategy parameters"], + "type": { + "defined": "StrategyParameters" + } + } + ] + } + }, + { + "name": "StrategyParameters", + "type": { + "kind": "struct", + "fields": [ + { + "name": "minBinId", + "docs": ["min bin id"], + "type": "i32" + }, + { + "name": "maxBinId", + "docs": ["max bin id"], + "type": "i32" + }, + { + "name": "strategyType", + "docs": ["strategy type"], + "type": { + "defined": "StrategyType" + } + }, + { + "name": "parameteres", + "docs": ["parameters"], + "type": { + "array": ["u8", 64] + } + } + ] + } + }, + { + "name": "LiquidityOneSideParameter", + "type": { + "kind": "struct", + "fields": [ + { + "name": "amount", + "docs": ["Amount of X token or Y token to deposit"], + "type": "u64" + }, + { + "name": "activeId", + "docs": ["Active bin that integrator observe off-chain"], + "type": "i32" + }, + { + "name": "maxActiveBinSlippage", + "docs": ["max active bin slippage allowed"], + "type": "i32" + }, + { + "name": "binLiquidityDist", + "docs": ["Liquidity distribution to each bins"], + "type": { + "vec": { + "defined": "BinLiquidityDistributionByWeight" + } + } + } + ] + } + }, + { + "name": "BinLiquidityDistributionByWeight", + "type": { + "kind": "struct", + "fields": [ + { + "name": "binId", + "docs": ["Define the bin ID wish to deposit to."], + "type": "i32" + }, + { + "name": "weight", + "docs": ["weight of liquidity distributed for this bin id"], + "type": "u16" + } + ] + } + }, + { + "name": "LiquidityParameterByWeight", + "type": { + "kind": "struct", + "fields": [ + { + "name": "amountX", + "docs": ["Amount of X token to deposit"], + "type": "u64" + }, + { + "name": "amountY", + "docs": ["Amount of Y token to deposit"], + "type": "u64" + }, + { + "name": "activeId", + "docs": ["Active bin that integrator observe off-chain"], + "type": "i32" + }, + { + "name": "maxActiveBinSlippage", + "docs": ["max active bin slippage allowed"], + "type": "i32" + }, + { + "name": "binLiquidityDist", + "docs": ["Liquidity distribution to each bins"], + "type": { + "vec": { + "defined": "BinLiquidityDistributionByWeight" + } + } + } + ] + } + }, + { + "name": "AddLiquiditySingleSidePreciseParameter", + "type": { + "kind": "struct", + "fields": [ + { + "name": "bins", + "type": { + "vec": { + "defined": "CompressedBinDepositAmount" + } + } + }, + { + "name": "decompressMultiplier", + "type": "u64" + } + ] + } + }, + { + "name": "CompressedBinDepositAmount", + "type": { + "kind": "struct", + "fields": [ + { + "name": "binId", + "type": "i32" + }, + { + "name": "amount", + "type": "u32" + } + ] + } + }, + { + "name": "BinLiquidityDistribution", + "type": { + "kind": "struct", + "fields": [ + { + "name": "binId", + "docs": ["Define the bin ID wish to deposit to."], + "type": "i32" + }, + { + "name": "distributionX", + "docs": [ + "DistributionX (or distributionY) is the percentages of amountX (or amountY) you want to add to each bin." + ], + "type": "u16" + }, + { + "name": "distributionY", + "docs": [ + "DistributionX (or distributionY) is the percentages of amountX (or amountY) you want to add to each bin." + ], + "type": "u16" + } + ] + } + }, + { + "name": "LiquidityParameter", + "type": { + "kind": "struct", + "fields": [ + { + "name": "amountX", + "docs": ["Amount of X token to deposit"], + "type": "u64" + }, + { + "name": "amountY", + "docs": ["Amount of Y token to deposit"], + "type": "u64" + }, + { + "name": "binLiquidityDist", + "docs": ["Liquidity distribution to each bins"], + "type": { + "vec": { + "defined": "BinLiquidityDistribution" + } + } + } + ] + } + }, + { + "name": "CustomizableParams", + "type": { + "kind": "struct", + "fields": [ + { + "name": "activeId", + "docs": ["Pool price"], + "type": "i32" + }, + { + "name": "binStep", + "docs": ["Bin step"], + "type": "u16" + }, + { + "name": "baseFactor", + "docs": ["Base factor"], + "type": "u16" + }, + { + "name": "activationType", + "docs": ["Activation type. 0 = Slot, 1 = Time. Check ActivationType enum"], + "type": "u8" + }, + { + "name": "hasAlphaVault", + "docs": ["Whether the pool has an alpha vault"], + "type": "bool" + }, + { + "name": "activationPoint", + "docs": ["Decide when does the pool start trade. None = Now"], + "type": { + "option": "u64" + } + }, + { + "name": "padding", + "docs": ["Padding, for future use"], + "type": { + "array": ["u8", 64] + } + } + ] + } + }, + { + "name": "InitPermissionPairIx", + "type": { + "kind": "struct", + "fields": [ + { + "name": "activeId", + "type": "i32" + }, + { + "name": "binStep", + "type": "u16" + }, + { + "name": "baseFactor", + "type": "u16" + }, + { + "name": "minBinId", + "type": "i32" + }, + { + "name": "maxBinId", + "type": "i32" + }, + { + "name": "activationType", + "type": "u8" + } + ] + } + }, + { + "name": "BinLiquidityReduction", + "type": { + "kind": "struct", + "fields": [ + { + "name": "binId", + "type": "i32" + }, + { + "name": "bpsToRemove", + "type": "u16" + } + ] + } + }, + { + "name": "Bin", + "type": { + "kind": "struct", + "fields": [ + { + "name": "amountX", + "docs": ["Amount of token X in the bin. This already excluded protocol fees."], + "type": "u64" + }, + { + "name": "amountY", + "docs": ["Amount of token Y in the bin. This already excluded protocol fees."], + "type": "u64" + }, + { + "name": "price", + "docs": ["Bin price"], + "type": "u128" + }, + { + "name": "liquiditySupply", + "docs": ["Liquidities of the bin. This is the same as LP mint supply. q-number"], + "type": "u128" + }, + { + "name": "rewardPerTokenStored", + "docs": ["reward_a_per_token_stored"], + "type": { + "array": ["u128", 2] + } + }, + { + "name": "feeAmountXPerTokenStored", + "docs": ["Swap fee amount of token X per liquidity deposited."], + "type": "u128" + }, + { + "name": "feeAmountYPerTokenStored", + "docs": ["Swap fee amount of token Y per liquidity deposited."], + "type": "u128" + }, + { + "name": "amountXIn", + "docs": ["Total token X swap into the bin. Only used for tracking purpose."], + "type": "u128" + }, + { + "name": "amountYIn", + "docs": ["Total token Y swap into he bin. Only used for tracking purpose."], + "type": "u128" + } + ] + } + }, + { + "name": "ProtocolFee", + "type": { + "kind": "struct", + "fields": [ + { + "name": "amountX", + "type": "u64" + }, + { + "name": "amountY", + "type": "u64" + } + ] + } + }, + { + "name": "RewardInfo", + "docs": ["Stores the state relevant for tracking liquidity mining rewards"], + "type": { + "kind": "struct", + "fields": [ + { + "name": "mint", + "docs": ["Reward token mint."], + "type": "publicKey" + }, + { + "name": "vault", + "docs": ["Reward vault token account."], + "type": "publicKey" + }, + { + "name": "funder", + "docs": ["Authority account that allows to fund rewards"], + "type": "publicKey" + }, + { + "name": "rewardDuration", + "docs": ["TODO check whether we need to store it in pool"], + "type": "u64" + }, + { + "name": "rewardDurationEnd", + "docs": ["TODO check whether we need to store it in pool"], + "type": "u64" + }, + { + "name": "rewardRate", + "docs": ["TODO check whether we need to store it in pool"], + "type": "u128" + }, + { + "name": "lastUpdateTime", + "docs": ["The last time reward states were updated."], + "type": "u64" + }, + { + "name": "cumulativeSecondsWithEmptyLiquidityReward", + "docs": [ + "Accumulated seconds where when farm distribute rewards, but the bin is empty. The reward will be accumulated for next reward time window." + ], + "type": "u64" + } + ] + } + }, + { + "name": "Observation", + "type": { + "kind": "struct", + "fields": [ + { + "name": "cumulativeActiveBinId", + "docs": ["Cumulative active bin ID"], + "type": "i128" + }, + { + "name": "createdAt", + "docs": ["Observation sample created timestamp"], + "type": "i64" + }, + { + "name": "lastUpdatedAt", + "docs": ["Observation sample last updated timestamp"], + "type": "i64" + } + ] + } + }, + { + "name": "StaticParameters", + "docs": ["Parameter that set by the protocol"], + "type": { + "kind": "struct", + "fields": [ + { + "name": "baseFactor", + "docs": ["Used for base fee calculation. base_fee_rate = base_factor * bin_step"], + "type": "u16" + }, + { + "name": "filterPeriod", + "docs": ["Filter period determine high frequency trading time window."], + "type": "u16" + }, + { + "name": "decayPeriod", + "docs": ["Decay period determine when the volatile fee start decay / decrease."], + "type": "u16" + }, + { + "name": "reductionFactor", + "docs": ["Reduction factor controls the volatile fee rate decrement rate."], + "type": "u16" + }, + { + "name": "variableFeeControl", + "docs": ["Used to scale the variable fee component depending on the dynamic of the market"], + "type": "u32" + }, + { + "name": "maxVolatilityAccumulator", + "docs": ["Maximum number of bin crossed can be accumulated. Used to cap volatile fee rate."], + "type": "u32" + }, + { + "name": "minBinId", + "docs": ["Min bin id supported by the pool based on the configured bin step."], + "type": "i32" + }, + { + "name": "maxBinId", + "docs": ["Max bin id supported by the pool based on the configured bin step."], + "type": "i32" + }, + { + "name": "protocolShare", + "docs": [ + "Portion of swap fees retained by the protocol by controlling protocol_share parameter. protocol_swap_fee = protocol_share * total_swap_fee" + ], + "type": "u16" + }, + { + "name": "padding", + "docs": ["Padding for bytemuck safe alignment"], + "type": { + "array": ["u8", 6] + } + } + ] + } + }, + { + "name": "VariableParameters", + "docs": ["Parameters that changes based on dynamic of the market"], + "type": { + "kind": "struct", + "fields": [ + { + "name": "volatilityAccumulator", + "docs": [ + "Volatility accumulator measure the number of bin crossed since reference bin ID. Normally (without filter period taken into consideration), reference bin ID is the active bin of last swap.", + "It affects the variable fee rate" + ], + "type": "u32" + }, + { + "name": "volatilityReference", + "docs": [ + "Volatility reference is decayed volatility accumulator. It is always <= volatility_accumulator" + ], + "type": "u32" + }, + { + "name": "indexReference", + "docs": ["Active bin id of last swap."], + "type": "i32" + }, + { + "name": "padding", + "docs": ["Padding for bytemuck safe alignment"], + "type": { + "array": ["u8", 4] + } + }, + { + "name": "lastUpdateTimestamp", + "docs": ["Last timestamp the variable parameters was updated"], + "type": "i64" + }, + { + "name": "padding1", + "docs": ["Padding for bytemuck safe alignment"], + "type": { + "array": ["u8", 8] + } + } + ] + } + }, + { + "name": "FeeInfo", + "type": { + "kind": "struct", + "fields": [ + { + "name": "feeXPerTokenComplete", + "type": "u128" + }, + { + "name": "feeYPerTokenComplete", + "type": "u128" + }, + { + "name": "feeXPending", + "type": "u64" + }, + { + "name": "feeYPending", + "type": "u64" + } + ] + } + }, + { + "name": "UserRewardInfo", + "type": { + "kind": "struct", + "fields": [ + { + "name": "rewardPerTokenCompletes", + "type": { + "array": ["u128", 2] + } + }, + { + "name": "rewardPendings", + "type": { + "array": ["u64", 2] + } + } + ] + } + }, + { + "name": "StrategyType", + "type": { + "kind": "enum", + "variants": [ + { + "name": "SpotOneSide" + }, + { + "name": "CurveOneSide" + }, + { + "name": "BidAskOneSide" + }, + { + "name": "SpotBalanced" + }, + { + "name": "CurveBalanced" + }, + { + "name": "BidAskBalanced" + }, + { + "name": "SpotImBalanced" + }, + { + "name": "CurveImBalanced" + }, + { + "name": "BidAskImBalanced" + } + ] + } + }, + { + "name": "Rounding", + "type": { + "kind": "enum", + "variants": [ + { + "name": "Up" + }, + { + "name": "Down" + } + ] + } + }, + { + "name": "ActivationType", + "docs": ["Type of the activation"], + "type": { + "kind": "enum", + "variants": [ + { + "name": "Slot" + }, + { + "name": "Timestamp" + } + ] + } + }, + { + "name": "LayoutVersion", + "docs": ["Layout version"], + "type": { + "kind": "enum", + "variants": [ + { + "name": "V0" + }, + { + "name": "V1" + } + ] + } + }, + { + "name": "PairType", + "docs": [ + "Type of the Pair. 0 = Permissionless, 1 = Permission, 2 = CustomizablePermissionless. Putting 0 as permissionless for backward compatibility." + ], + "type": { + "kind": "enum", + "variants": [ + { + "name": "Permissionless" + }, + { + "name": "Permission" + }, + { + "name": "CustomizablePermissionless" + } + ] + } + }, + { + "name": "PairStatus", + "docs": ["Pair status. 0 = Enabled, 1 = Disabled. Putting 0 as enabled for backward compatibility."], + "type": { + "kind": "enum", + "variants": [ + { + "name": "Enabled" + }, + { + "name": "Disabled" + } + ] + } + } + ], + "events": [ + { + "name": "CompositionFee", + "fields": [ + { + "name": "from", + "type": "publicKey", + "index": false + }, + { + "name": "binId", + "type": "i16", + "index": false + }, + { + "name": "tokenXFeeAmount", + "type": "u64", + "index": false + }, + { + "name": "tokenYFeeAmount", + "type": "u64", + "index": false + }, + { + "name": "protocolTokenXFeeAmount", + "type": "u64", + "index": false + }, + { + "name": "protocolTokenYFeeAmount", + "type": "u64", + "index": false + } + ] + }, + { + "name": "AddLiquidity", + "fields": [ + { + "name": "lbPair", + "type": "publicKey", + "index": false + }, + { + "name": "from", + "type": "publicKey", + "index": false + }, + { + "name": "position", + "type": "publicKey", + "index": false + }, + { + "name": "amounts", + "type": { + "array": ["u64", 2] + }, + "index": false + }, + { + "name": "activeBinId", + "type": "i32", + "index": false + } + ] + }, + { + "name": "RemoveLiquidity", + "fields": [ + { + "name": "lbPair", + "type": "publicKey", + "index": false + }, + { + "name": "from", + "type": "publicKey", + "index": false + }, + { + "name": "position", + "type": "publicKey", + "index": false + }, + { + "name": "amounts", + "type": { + "array": ["u64", 2] + }, + "index": false + }, + { + "name": "activeBinId", + "type": "i32", + "index": false + } + ] + }, + { + "name": "Swap", + "fields": [ + { + "name": "lbPair", + "type": "publicKey", + "index": false + }, + { + "name": "from", + "type": "publicKey", + "index": false + }, + { + "name": "startBinId", + "type": "i32", + "index": false + }, + { + "name": "endBinId", + "type": "i32", + "index": false + }, + { + "name": "amountIn", + "type": "u64", + "index": false + }, + { + "name": "amountOut", + "type": "u64", + "index": false + }, + { + "name": "swapForY", + "type": "bool", + "index": false + }, + { + "name": "fee", + "type": "u64", + "index": false + }, + { + "name": "protocolFee", + "type": "u64", + "index": false + }, + { + "name": "feeBps", + "type": "u128", + "index": false + }, + { + "name": "hostFee", + "type": "u64", + "index": false + } + ] + }, + { + "name": "ClaimReward", + "fields": [ + { + "name": "lbPair", + "type": "publicKey", + "index": false + }, + { + "name": "position", + "type": "publicKey", + "index": false + }, + { + "name": "owner", + "type": "publicKey", + "index": false + }, + { + "name": "rewardIndex", + "type": "u64", + "index": false + }, + { + "name": "totalReward", + "type": "u64", + "index": false + } + ] + }, + { + "name": "FundReward", + "fields": [ + { + "name": "lbPair", + "type": "publicKey", + "index": false + }, + { + "name": "funder", + "type": "publicKey", + "index": false + }, + { + "name": "rewardIndex", + "type": "u64", + "index": false + }, + { + "name": "amount", + "type": "u64", + "index": false + } + ] + }, + { + "name": "InitializeReward", + "fields": [ + { + "name": "lbPair", + "type": "publicKey", + "index": false + }, + { + "name": "rewardMint", + "type": "publicKey", + "index": false + }, + { + "name": "funder", + "type": "publicKey", + "index": false + }, + { + "name": "rewardIndex", + "type": "u64", + "index": false + }, + { + "name": "rewardDuration", + "type": "u64", + "index": false + } + ] + }, + { + "name": "UpdateRewardDuration", + "fields": [ + { + "name": "lbPair", + "type": "publicKey", + "index": false + }, + { + "name": "rewardIndex", + "type": "u64", + "index": false + }, + { + "name": "oldRewardDuration", + "type": "u64", + "index": false + }, + { + "name": "newRewardDuration", + "type": "u64", + "index": false + } + ] + }, + { + "name": "UpdateRewardFunder", + "fields": [ + { + "name": "lbPair", + "type": "publicKey", + "index": false + }, + { + "name": "rewardIndex", + "type": "u64", + "index": false + }, + { + "name": "oldFunder", + "type": "publicKey", + "index": false + }, + { + "name": "newFunder", + "type": "publicKey", + "index": false + } + ] + }, + { + "name": "PositionClose", + "fields": [ + { + "name": "position", + "type": "publicKey", + "index": false + }, + { + "name": "owner", + "type": "publicKey", + "index": false + } + ] + }, + { + "name": "ClaimFee", + "fields": [ + { + "name": "lbPair", + "type": "publicKey", + "index": false + }, + { + "name": "position", + "type": "publicKey", + "index": false + }, + { + "name": "owner", + "type": "publicKey", + "index": false + }, + { + "name": "feeX", + "type": "u64", + "index": false + }, + { + "name": "feeY", + "type": "u64", + "index": false + } + ] + }, + { + "name": "LbPairCreate", + "fields": [ + { + "name": "lbPair", + "type": "publicKey", + "index": false + }, + { + "name": "binStep", + "type": "u16", + "index": false + }, + { + "name": "tokenX", + "type": "publicKey", + "index": false + }, + { + "name": "tokenY", + "type": "publicKey", + "index": false + } + ] + }, + { + "name": "PositionCreate", + "fields": [ + { + "name": "lbPair", + "type": "publicKey", + "index": false + }, + { + "name": "position", + "type": "publicKey", + "index": false + }, + { + "name": "owner", + "type": "publicKey", + "index": false + } + ] + }, + { + "name": "FeeParameterUpdate", + "fields": [ + { + "name": "lbPair", + "type": "publicKey", + "index": false + }, + { + "name": "protocolShare", + "type": "u16", + "index": false + }, + { + "name": "baseFactor", + "type": "u16", + "index": false + } + ] + }, + { + "name": "IncreaseObservation", + "fields": [ + { + "name": "oracle", + "type": "publicKey", + "index": false + }, + { + "name": "newObservationLength", + "type": "u64", + "index": false + } + ] + }, + { + "name": "WithdrawIneligibleReward", + "fields": [ + { + "name": "lbPair", + "type": "publicKey", + "index": false + }, + { + "name": "rewardMint", + "type": "publicKey", + "index": false + }, + { + "name": "amount", + "type": "u64", + "index": false + } + ] + }, + { + "name": "UpdatePositionOperator", + "fields": [ + { + "name": "position", + "type": "publicKey", + "index": false + }, + { + "name": "oldOperator", + "type": "publicKey", + "index": false + }, + { + "name": "newOperator", + "type": "publicKey", + "index": false + } + ] + }, + { + "name": "UpdatePositionLockReleasePoint", + "fields": [ + { + "name": "position", + "type": "publicKey", + "index": false + }, + { + "name": "currentPoint", + "type": "u64", + "index": false + }, + { + "name": "newLockReleasePoint", + "type": "u64", + "index": false + }, + { + "name": "oldLockReleasePoint", + "type": "u64", + "index": false + }, + { + "name": "sender", + "type": "publicKey", + "index": false + } + ] + }, + { + "name": "GoToABin", + "fields": [ + { + "name": "lbPair", + "type": "publicKey", + "index": false + }, + { + "name": "fromBinId", + "type": "i32", + "index": false + }, + { + "name": "toBinId", + "type": "i32", + "index": false + } + ] + } + ], + "errors": [ + { + "code": 6000, + "name": "InvalidStartBinIndex", + "msg": "Invalid start bin index" + }, + { + "code": 6001, + "name": "InvalidBinId", + "msg": "Invalid bin id" + }, + { + "code": 6002, + "name": "InvalidInput", + "msg": "Invalid input data" + }, + { + "code": 6003, + "name": "ExceededAmountSlippageTolerance", + "msg": "Exceeded amount slippage tolerance" + }, + { + "code": 6004, + "name": "ExceededBinSlippageTolerance", + "msg": "Exceeded bin slippage tolerance" + }, + { + "code": 6005, + "name": "CompositionFactorFlawed", + "msg": "Composition factor flawed" + }, + { + "code": 6006, + "name": "NonPresetBinStep", + "msg": "Non preset bin step" + }, + { + "code": 6007, + "name": "ZeroLiquidity", + "msg": "Zero liquidity" + }, + { + "code": 6008, + "name": "InvalidPosition", + "msg": "Invalid position" + }, + { + "code": 6009, + "name": "BinArrayNotFound", + "msg": "Bin array not found" + }, + { + "code": 6010, + "name": "InvalidTokenMint", + "msg": "Invalid token mint" + }, + { + "code": 6011, + "name": "InvalidAccountForSingleDeposit", + "msg": "Invalid account for single deposit" + }, + { + "code": 6012, + "name": "PairInsufficientLiquidity", + "msg": "Pair insufficient liquidity" + }, + { + "code": 6013, + "name": "InvalidFeeOwner", + "msg": "Invalid fee owner" + }, + { + "code": 6014, + "name": "InvalidFeeWithdrawAmount", + "msg": "Invalid fee withdraw amount" + }, + { + "code": 6015, + "name": "InvalidAdmin", + "msg": "Invalid admin" + }, + { + "code": 6016, + "name": "IdenticalFeeOwner", + "msg": "Identical fee owner" + }, + { + "code": 6017, + "name": "InvalidBps", + "msg": "Invalid basis point" + }, + { + "code": 6018, + "name": "MathOverflow", + "msg": "Math operation overflow" + }, + { + "code": 6019, + "name": "TypeCastFailed", + "msg": "Type cast error" + }, + { + "code": 6020, + "name": "InvalidRewardIndex", + "msg": "Invalid reward index" + }, + { + "code": 6021, + "name": "InvalidRewardDuration", + "msg": "Invalid reward duration" + }, + { + "code": 6022, + "name": "RewardInitialized", + "msg": "Reward already initialized" + }, + { + "code": 6023, + "name": "RewardUninitialized", + "msg": "Reward not initialized" + }, + { + "code": 6024, + "name": "IdenticalFunder", + "msg": "Identical funder" + }, + { + "code": 6025, + "name": "RewardCampaignInProgress", + "msg": "Reward campaign in progress" + }, + { + "code": 6026, + "name": "IdenticalRewardDuration", + "msg": "Reward duration is the same" + }, + { + "code": 6027, + "name": "InvalidBinArray", + "msg": "Invalid bin array" + }, + { + "code": 6028, + "name": "NonContinuousBinArrays", + "msg": "Bin arrays must be continuous" + }, + { + "code": 6029, + "name": "InvalidRewardVault", + "msg": "Invalid reward vault" + }, + { + "code": 6030, + "name": "NonEmptyPosition", + "msg": "Position is not empty" + }, + { + "code": 6031, + "name": "UnauthorizedAccess", + "msg": "Unauthorized access" + }, + { + "code": 6032, + "name": "InvalidFeeParameter", + "msg": "Invalid fee parameter" + }, + { + "code": 6033, + "name": "MissingOracle", + "msg": "Missing oracle account" + }, + { + "code": 6034, + "name": "InsufficientSample", + "msg": "Insufficient observation sample" + }, + { + "code": 6035, + "name": "InvalidLookupTimestamp", + "msg": "Invalid lookup timestamp" + }, + { + "code": 6036, + "name": "BitmapExtensionAccountIsNotProvided", + "msg": "Bitmap extension account is not provided" + }, + { + "code": 6037, + "name": "CannotFindNonZeroLiquidityBinArrayId", + "msg": "Cannot find non-zero liquidity binArrayId" + }, + { + "code": 6038, + "name": "BinIdOutOfBound", + "msg": "Bin id out of bound" + }, + { + "code": 6039, + "name": "InsufficientOutAmount", + "msg": "Insufficient amount in for minimum out" + }, + { + "code": 6040, + "name": "InvalidPositionWidth", + "msg": "Invalid position width" + }, + { + "code": 6041, + "name": "ExcessiveFeeUpdate", + "msg": "Excessive fee update" + }, + { + "code": 6042, + "name": "PoolDisabled", + "msg": "Pool disabled" + }, + { + "code": 6043, + "name": "InvalidPoolType", + "msg": "Invalid pool type" + }, + { + "code": 6044, + "name": "ExceedMaxWhitelist", + "msg": "Whitelist for wallet is full" + }, + { + "code": 6045, + "name": "InvalidIndex", + "msg": "Invalid index" + }, + { + "code": 6046, + "name": "RewardNotEnded", + "msg": "Reward not ended" + }, + { + "code": 6047, + "name": "MustWithdrawnIneligibleReward", + "msg": "Must withdraw ineligible reward" + }, + { + "code": 6048, + "name": "UnauthorizedAddress", + "msg": "Unauthorized address" + }, + { + "code": 6049, + "name": "OperatorsAreTheSame", + "msg": "Cannot update because operators are the same" + }, + { + "code": 6050, + "name": "WithdrawToWrongTokenAccount", + "msg": "Withdraw to wrong token account" + }, + { + "code": 6051, + "name": "WrongRentReceiver", + "msg": "Wrong rent receiver" + }, + { + "code": 6052, + "name": "AlreadyPassActivationPoint", + "msg": "Already activated" + }, + { + "code": 6053, + "name": "ExceedMaxSwappedAmount", + "msg": "Swapped amount is exceeded max swapped amount" + }, + { + "code": 6054, + "name": "InvalidStrategyParameters", + "msg": "Invalid strategy parameters" + }, + { + "code": 6055, + "name": "LiquidityLocked", + "msg": "Liquidity locked" + }, + { + "code": 6056, + "name": "BinRangeIsNotEmpty", + "msg": "Bin range is not empty" + }, + { + "code": 6057, + "name": "NotExactAmountOut", + "msg": "Amount out is not matched with exact amount out" + }, + { + "code": 6058, + "name": "InvalidActivationType", + "msg": "Invalid activation type" + }, + { + "code": 6059, + "name": "InvalidActivationDuration", + "msg": "Invalid activation duration" + }, + { + "code": 6060, + "name": "MissingTokenAmountAsTokenLaunchProof", + "msg": "Missing token amount as token launch owner proof" + }, + { + "code": 6061, + "name": "InvalidQuoteToken", + "msg": "Quote token must be SOL or USDC" + }, + { + "code": 6062, + "name": "InvalidBinStep", + "msg": "Invalid bin step" + }, + { + "code": 6063, + "name": "InvalidBaseFee", + "msg": "Invalid base fee" + }, + { + "code": 6064, + "name": "InvalidPreActivationDuration", + "msg": "Invalid pre-activation duration" + }, + { + "code": 6065, + "name": "AlreadyPassPreActivationSwapPoint", + "msg": "Already pass pre-activation swap point" + } + ] +} diff --git a/e2e/meteora/pubspec.lock b/e2e/meteora/pubspec.lock new file mode 100644 index 0000000..86d9781 --- /dev/null +++ b/e2e/meteora/pubspec.lock @@ -0,0 +1,261 @@ +# Generated by pub +# See https://dart.dev/tools/pub/glossary#lockfile +packages: + async: + dependency: transitive + description: + name: async + sha256: "758e6d74e971c3e5aceb4110bfd6698efc7f501675bcfe0c775459a8140750eb" + url: "https://pub.dev" + source: hosted + version: "2.13.0" + bip39: + dependency: transitive + description: + name: bip39 + sha256: de1ee27ebe7d96b84bb3a04a4132a0a3007dcdd5ad27dd14aa87a29d97c45edc + url: "https://pub.dev" + source: hosted + version: "1.0.6" + borsh_annotation: + dependency: transitive + description: + name: borsh_annotation + sha256: dc73a7fdc6fe4505535657daf8ab3cebe382311fae63a0faaf9315ea1bc30bff + url: "https://pub.dev" + source: hosted + version: "0.3.2" + clock: + dependency: transitive + description: + name: clock + sha256: fddb70d9b5277016c77a80201021d40a2247104d9f4aa7bab7157b7e3f05b84b + url: "https://pub.dev" + source: hosted + version: "1.1.2" + collection: + dependency: transitive + description: + name: collection + sha256: "2f5709ae4d3d59dd8f7cd309b4e023046b57d8a6c82130785d2b0e5868084e76" + url: "https://pub.dev" + source: hosted + version: "1.19.1" + convert: + dependency: transitive + description: + name: convert + sha256: b30acd5944035672bc15c6b7a8b47d773e41e2f17de064350988c5d02adb1c68 + url: "https://pub.dev" + source: hosted + version: "3.1.2" + crypto: + dependency: transitive + description: + name: crypto + sha256: "1e445881f28f22d6140f181e07737b22f1e099a5e1ff94b0af2f9e4a463f4855" + url: "https://pub.dev" + source: hosted + version: "3.0.6" + cryptography: + dependency: transitive + description: + name: cryptography + sha256: d146b76d33d94548cf035233fbc2f4338c1242fa119013bead807d033fc4ae05 + url: "https://pub.dev" + source: hosted + version: "2.7.0" + decimal: + dependency: transitive + description: + name: decimal + sha256: fc706a5618b81e5b367b01dd62621def37abc096f2b46a9bd9068b64c1fa36d0 + url: "https://pub.dev" + source: hosted + version: "3.2.4" + ed25519_hd_key: + dependency: transitive + description: + name: ed25519_hd_key + sha256: "31e191ec97492873067e46dc9cc0c7d55170559c83a478400feffa0627acaccf" + url: "https://pub.dev" + source: hosted + version: "2.3.0" + ffi: + dependency: transitive + description: + name: ffi + sha256: "289279317b4b16eb2bb7e271abccd4bf84ec9bdcbe999e278a94b804f5630418" + url: "https://pub.dev" + source: hosted + version: "2.1.4" + freezed_annotation: + dependency: transitive + description: + name: freezed_annotation + sha256: c2e2d632dd9b8a2b7751117abcfc2b4888ecfe181bd9fca7170d9ef02e595fe2 + url: "https://pub.dev" + source: hosted + version: "2.4.4" + hex: + dependency: transitive + description: + name: hex + sha256: "4e7cd54e4b59ba026432a6be2dd9d96e4c5205725194997193bf871703b82c4a" + url: "https://pub.dev" + source: hosted + version: "0.2.0" + http: + dependency: transitive + description: + name: http + sha256: bb2ce4590bc2667c96f318d68cac1b5a7987ec819351d32b1c987239a815e007 + url: "https://pub.dev" + source: hosted + version: "1.5.0" + http_parser: + dependency: transitive + description: + name: http_parser + sha256: "178d74305e7866013777bab2c3d8726205dc5a4dd935297175b19a23a2e66571" + url: "https://pub.dev" + source: hosted + version: "4.1.2" + intl: + dependency: transitive + description: + name: intl + sha256: "3df61194eb431efc39c4ceba583b95633a403f46c9fd341e550ce0bfa50e9aa5" + url: "https://pub.dev" + source: hosted + version: "0.20.2" + js: + dependency: transitive + description: + name: js + sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3 + url: "https://pub.dev" + source: hosted + version: "0.6.7" + json_annotation: + dependency: transitive + description: + name: json_annotation + sha256: "1ce844379ca14835a50d2f019a3099f419082cfdd231cd86a142af94dd5c6bb1" + url: "https://pub.dev" + source: hosted + version: "4.9.0" + meta: + dependency: transitive + description: + name: meta + sha256: "23f08335362185a5ea2ad3a4e597f1375e78bce8a040df5c600c8d3552ef2394" + url: "https://pub.dev" + source: hosted + version: "1.17.0" + path: + dependency: transitive + description: + name: path + sha256: "75cca69d1490965be98c73ceaea117e8a04dd21217b37b292c9ddbec0d955bc5" + url: "https://pub.dev" + source: hosted + version: "1.9.1" + pinenacl: + dependency: transitive + description: + name: pinenacl + sha256: "57e907beaacbc3c024a098910b6240758e899674de07d6949a67b52fd984cbdf" + url: "https://pub.dev" + source: hosted + version: "0.6.0" + pointycastle: + dependency: transitive + description: + name: pointycastle + sha256: "4be0097fcf3fd3e8449e53730c631200ebc7b88016acecab2b0da2f0149222fe" + url: "https://pub.dev" + source: hosted + version: "3.9.1" + rational: + dependency: transitive + description: + name: rational + sha256: cb808fb6f1a839e6fc5f7d8cb3b0a10e1db48b3be102de73938c627f0b636336 + url: "https://pub.dev" + source: hosted + version: "2.2.3" + solana: + dependency: "direct main" + description: + name: solana + sha256: "98d8780dbd9af7e90ff14a6e762a45d77466450304773610317d1fffdea09701" + url: "https://pub.dev" + source: hosted + version: "0.31.2+1" + source_span: + dependency: transitive + description: + name: source_span + sha256: "254ee5351d6cb365c859e20ee823c3bb479bf4a293c22d17a9f1bf144ce86f7c" + url: "https://pub.dev" + source: hosted + version: "1.10.1" + stream_channel: + dependency: transitive + description: + name: stream_channel + sha256: "969e04c80b8bcdf826f8f16579c7b14d780458bd97f56d107d3950fdbeef059d" + url: "https://pub.dev" + source: hosted + version: "2.1.4" + string_scanner: + dependency: transitive + description: + name: string_scanner + sha256: "921cd31725b72fe181906c6a94d987c78e3b98c2e205b397ea399d4054872b43" + url: "https://pub.dev" + source: hosted + version: "1.4.1" + term_glyph: + dependency: transitive + description: + name: term_glyph + sha256: "7f554798625ea768a7518313e58f83891c7f5024f88e46e7182a4558850a4b8e" + url: "https://pub.dev" + source: hosted + version: "1.2.2" + typed_data: + dependency: transitive + description: + name: typed_data + sha256: f9049c039ebfeb4cf7a7104a675823cd72dba8297f264b6637062516699fa006 + url: "https://pub.dev" + source: hosted + version: "1.4.0" + web: + dependency: transitive + description: + name: web + sha256: "868d88a33d8a87b18ffc05f9f030ba328ffefba92d6c127917a2ba740f9cfe4a" + url: "https://pub.dev" + source: hosted + version: "1.1.1" + web_socket: + dependency: transitive + description: + name: web_socket + sha256: "34d64019aa8e36bf9842ac014bb5d2f5586ca73df5e4d9bf5c936975cae6982c" + url: "https://pub.dev" + source: hosted + version: "1.0.1" + web_socket_channel: + dependency: transitive + description: + name: web_socket_channel + sha256: d645757fb0f4773d602444000a8131ff5d48c9e47adfe9772652dd1a4f2d45c8 + url: "https://pub.dev" + source: hosted + version: "3.0.3" +sdks: + dart: ">=3.7.0 <4.0.0" diff --git a/e2e/meteora/pubspec.yaml b/e2e/meteora/pubspec.yaml new file mode 100644 index 0000000..10da710 --- /dev/null +++ b/e2e/meteora/pubspec.yaml @@ -0,0 +1,7 @@ +name: meteora +description: meteora project for e2e generated Dart code +version: 0.1.0 +environment: + sdk: '>=2.17.0 <4.0.0' +dependencies: + solana: ^0.31.2+1 \ No newline at end of file diff --git a/e2e/system/.dart_tool/package_config.json b/e2e/system/.dart_tool/package_config.json new file mode 100644 index 0000000..53e8c5a --- /dev/null +++ b/e2e/system/.dart_tool/package_config.json @@ -0,0 +1,206 @@ +{ + "configVersion": 2, + "packages": [ + { + "name": "async", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/async-2.13.0", + "packageUri": "lib/", + "languageVersion": "3.4" + }, + { + "name": "bip39", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/bip39-1.0.6", + "packageUri": "lib/", + "languageVersion": "2.12" + }, + { + "name": "borsh_annotation", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/borsh_annotation-0.3.2", + "packageUri": "lib/", + "languageVersion": "3.0" + }, + { + "name": "clock", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/clock-1.1.2", + "packageUri": "lib/", + "languageVersion": "3.4" + }, + { + "name": "collection", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/collection-1.19.1", + "packageUri": "lib/", + "languageVersion": "3.4" + }, + { + "name": "convert", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/convert-3.1.2", + "packageUri": "lib/", + "languageVersion": "3.4" + }, + { + "name": "crypto", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/crypto-3.0.6", + "packageUri": "lib/", + "languageVersion": "3.4" + }, + { + "name": "cryptography", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/cryptography-2.7.0", + "packageUri": "lib/", + "languageVersion": "3.1" + }, + { + "name": "decimal", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/decimal-3.2.4", + "packageUri": "lib/", + "languageVersion": "3.3" + }, + { + "name": "ed25519_hd_key", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/ed25519_hd_key-2.3.0", + "packageUri": "lib/", + "languageVersion": "3.4" + }, + { + "name": "ffi", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/ffi-2.1.4", + "packageUri": "lib/", + "languageVersion": "3.7" + }, + { + "name": "freezed_annotation", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/freezed_annotation-2.4.4", + "packageUri": "lib/", + "languageVersion": "3.0" + }, + { + "name": "hex", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/hex-0.2.0", + "packageUri": "lib/", + "languageVersion": "2.12" + }, + { + "name": "http", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/http-1.5.0", + "packageUri": "lib/", + "languageVersion": "3.4" + }, + { + "name": "http_parser", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/http_parser-4.1.2", + "packageUri": "lib/", + "languageVersion": "3.4" + }, + { + "name": "intl", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/intl-0.20.2", + "packageUri": "lib/", + "languageVersion": "3.3" + }, + { + "name": "js", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/js-0.6.7", + "packageUri": "lib/", + "languageVersion": "2.19" + }, + { + "name": "json_annotation", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/json_annotation-4.9.0", + "packageUri": "lib/", + "languageVersion": "3.0" + }, + { + "name": "meta", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/meta-1.17.0", + "packageUri": "lib/", + "languageVersion": "3.5" + }, + { + "name": "path", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/path-1.9.1", + "packageUri": "lib/", + "languageVersion": "3.4" + }, + { + "name": "pinenacl", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/pinenacl-0.6.0", + "packageUri": "lib/", + "languageVersion": "3.4" + }, + { + "name": "pointycastle", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/pointycastle-3.9.1", + "packageUri": "lib/", + "languageVersion": "3.2" + }, + { + "name": "rational", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/rational-2.2.3", + "packageUri": "lib/", + "languageVersion": "2.14" + }, + { + "name": "solana", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/solana-0.31.2+1", + "packageUri": "lib/", + "languageVersion": "3.2" + }, + { + "name": "source_span", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/source_span-1.10.1", + "packageUri": "lib/", + "languageVersion": "3.1" + }, + { + "name": "stream_channel", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/stream_channel-2.1.4", + "packageUri": "lib/", + "languageVersion": "3.3" + }, + { + "name": "string_scanner", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/string_scanner-1.4.1", + "packageUri": "lib/", + "languageVersion": "3.1" + }, + { + "name": "term_glyph", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/term_glyph-1.2.2", + "packageUri": "lib/", + "languageVersion": "3.1" + }, + { + "name": "typed_data", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/typed_data-1.4.0", + "packageUri": "lib/", + "languageVersion": "3.5" + }, + { + "name": "web", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/web-1.1.1", + "packageUri": "lib/", + "languageVersion": "3.4" + }, + { + "name": "web_socket", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/web_socket-1.0.1", + "packageUri": "lib/", + "languageVersion": "3.4" + }, + { + "name": "web_socket_channel", + "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/web_socket_channel-3.0.3", + "packageUri": "lib/", + "languageVersion": "3.3" + }, + { + "name": "system", + "rootUri": "../", + "packageUri": "lib/", + "languageVersion": "2.17" + } + ], + "generator": "pub", + "generatorVersion": "3.9.0", + "pubCache": "file:///Users/emilemilovroydev/.pub-cache" +} diff --git a/e2e/system/.dart_tool/package_graph.json b/e2e/system/.dart_tool/package_graph.json new file mode 100644 index 0000000..54386fa --- /dev/null +++ b/e2e/system/.dart_tool/package_graph.json @@ -0,0 +1,257 @@ +{ + "roots": [ + "system" + ], + "packages": [ + { + "name": "system", + "version": "0.1.0", + "dependencies": [ + "solana" + ], + "devDependencies": [] + }, + { + "name": "solana", + "version": "0.31.2+1", + "dependencies": [ + "bip39", + "borsh_annotation", + "collection", + "convert", + "cryptography", + "decimal", + "ed25519_hd_key", + "freezed_annotation", + "http", + "json_annotation", + "typed_data", + "web_socket_channel" + ] + }, + { + "name": "web_socket_channel", + "version": "3.0.3", + "dependencies": [ + "async", + "crypto", + "stream_channel", + "web", + "web_socket" + ] + }, + { + "name": "typed_data", + "version": "1.4.0", + "dependencies": [ + "collection" + ] + }, + { + "name": "json_annotation", + "version": "4.9.0", + "dependencies": [ + "meta" + ] + }, + { + "name": "http", + "version": "1.5.0", + "dependencies": [ + "async", + "http_parser", + "meta", + "web" + ] + }, + { + "name": "freezed_annotation", + "version": "2.4.4", + "dependencies": [ + "collection", + "json_annotation", + "meta" + ] + }, + { + "name": "ed25519_hd_key", + "version": "2.3.0", + "dependencies": [ + "crypto", + "pinenacl" + ] + }, + { + "name": "decimal", + "version": "3.2.4", + "dependencies": [ + "intl", + "rational" + ] + }, + { + "name": "cryptography", + "version": "2.7.0", + "dependencies": [ + "collection", + "crypto", + "ffi", + "js", + "meta", + "typed_data" + ] + }, + { + "name": "convert", + "version": "3.1.2", + "dependencies": [ + "typed_data" + ] + }, + { + "name": "collection", + "version": "1.19.1", + "dependencies": [] + }, + { + "name": "borsh_annotation", + "version": "0.3.2", + "dependencies": [] + }, + { + "name": "bip39", + "version": "1.0.6", + "dependencies": [ + "crypto", + "hex", + "pointycastle" + ] + }, + { + "name": "web_socket", + "version": "1.0.1", + "dependencies": [ + "web" + ] + }, + { + "name": "web", + "version": "1.1.1", + "dependencies": [] + }, + { + "name": "stream_channel", + "version": "2.1.4", + "dependencies": [ + "async" + ] + }, + { + "name": "crypto", + "version": "3.0.6", + "dependencies": [ + "typed_data" + ] + }, + { + "name": "async", + "version": "2.13.0", + "dependencies": [ + "collection", + "meta" + ] + }, + { + "name": "meta", + "version": "1.17.0", + "dependencies": [] + }, + { + "name": "http_parser", + "version": "4.1.2", + "dependencies": [ + "collection", + "source_span", + "string_scanner", + "typed_data" + ] + }, + { + "name": "pinenacl", + "version": "0.6.0", + "dependencies": [] + }, + { + "name": "rational", + "version": "2.2.3", + "dependencies": [] + }, + { + "name": "intl", + "version": "0.20.2", + "dependencies": [ + "clock", + "meta", + "path" + ] + }, + { + "name": "js", + "version": "0.6.7", + "dependencies": [ + "meta" + ] + }, + { + "name": "ffi", + "version": "2.1.4", + "dependencies": [] + }, + { + "name": "hex", + "version": "0.2.0", + "dependencies": [] + }, + { + "name": "pointycastle", + "version": "3.9.1", + "dependencies": [ + "collection", + "convert", + "js" + ] + }, + { + "name": "string_scanner", + "version": "1.4.1", + "dependencies": [ + "source_span" + ] + }, + { + "name": "source_span", + "version": "1.10.1", + "dependencies": [ + "collection", + "path", + "term_glyph" + ] + }, + { + "name": "path", + "version": "1.9.1", + "dependencies": [] + }, + { + "name": "clock", + "version": "1.1.2", + "dependencies": [] + }, + { + "name": "term_glyph", + "version": "1.2.2", + "dependencies": [] + } + ], + "configVersion": 1 +} \ No newline at end of file diff --git a/e2e/system/idl.json b/e2e/system/idl.json new file mode 100644 index 0000000..9ce94eb --- /dev/null +++ b/e2e/system/idl.json @@ -0,0 +1,1042 @@ +{ + "kind": "rootNode", + "program": { + "kind": "programNode", + "pdas": [], + "accounts": [ + { + "kind": "accountNode", + "data": { + "kind": "structTypeNode", + "fields": [ + { + "kind": "structFieldTypeNode", + "name": "version", + "type": { "kind": "definedTypeLinkNode", "name": "nonceVersion" }, + "docs": [] + }, + { + "kind": "structFieldTypeNode", + "name": "state", + "type": { "kind": "definedTypeLinkNode", "name": "nonceState" }, + "docs": [] + }, + { + "kind": "structFieldTypeNode", + "name": "authority", + "type": { "kind": "publicKeyTypeNode" }, + "docs": [] + }, + { + "kind": "structFieldTypeNode", + "name": "blockhash", + "type": { "kind": "publicKeyTypeNode" }, + "docs": [] + }, + { + "kind": "structFieldTypeNode", + "name": "lamportsPerSignature", + "type": { + "kind": "numberTypeNode", + "format": "u64", + "endian": "le" + }, + "docs": [] + } + ] + }, + "name": "nonce", + "idlName": "Nonce", + "docs": [], + "size": 80 + } + ], + "instructions": [ + { + "kind": "instructionNode", + "accounts": [ + { + "kind": "instructionAccountNode", + "name": "payer", + "isWritable": true, + "isSigner": true, + "isOptional": false, + "docs": [], + "defaultValue": { "kind": "payerValueNode" } + }, + { + "kind": "instructionAccountNode", + "name": "newAccount", + "isWritable": true, + "isSigner": true, + "isOptional": false, + "docs": [] + } + ], + "arguments": [ + { + "kind": "instructionArgumentNode", + "name": "discriminator", + "type": { + "kind": "numberTypeNode", + "format": "u32", + "endian": "le" + }, + "docs": [], + "defaultValue": { "kind": "numberValueNode", "number": 0 }, + "defaultValueStrategy": "omitted" + }, + { + "kind": "instructionArgumentNode", + "name": "lamports", + "type": { + "kind": "numberTypeNode", + "format": "u64", + "endian": "le" + }, + "docs": [] + }, + { + "kind": "instructionArgumentNode", + "name": "space", + "type": { + "kind": "numberTypeNode", + "format": "u64", + "endian": "le" + }, + "docs": [] + }, + { + "kind": "instructionArgumentNode", + "name": "programAddress", + "type": { "kind": "publicKeyTypeNode" }, + "docs": [] + } + ], + "byteDeltas": [ + { + "kind": "instructionByteDeltaNode", + "value": { "kind": "argumentValueNode", "name": "space" }, + "withHeader": true + } + ], + "discriminators": [ + { + "kind": "fieldDiscriminatorNode", + "name": "discriminator", + "offset": 0 + } + ], + "name": "createAccount", + "idlName": "CreateAccount", + "docs": [], + "optionalAccountStrategy": "programId" + }, + { + "kind": "instructionNode", + "accounts": [ + { + "kind": "instructionAccountNode", + "name": "account", + "isWritable": true, + "isSigner": true, + "isOptional": false, + "docs": [] + } + ], + "arguments": [ + { + "kind": "instructionArgumentNode", + "name": "discriminator", + "type": { + "kind": "numberTypeNode", + "format": "u32", + "endian": "le" + }, + "docs": [], + "defaultValue": { "kind": "numberValueNode", "number": 1 }, + "defaultValueStrategy": "omitted" + }, + { + "kind": "instructionArgumentNode", + "name": "programAddress", + "type": { "kind": "publicKeyTypeNode" }, + "docs": [] + } + ], + "discriminators": [ + { + "kind": "fieldDiscriminatorNode", + "name": "discriminator", + "offset": 0 + } + ], + "name": "assign", + "idlName": "Assign", + "docs": [], + "optionalAccountStrategy": "programId" + }, + { + "kind": "instructionNode", + "accounts": [ + { + "kind": "instructionAccountNode", + "name": "source", + "isWritable": true, + "isSigner": true, + "isOptional": false, + "docs": [] + }, + { + "kind": "instructionAccountNode", + "name": "destination", + "isWritable": true, + "isSigner": false, + "isOptional": false, + "docs": [] + } + ], + "arguments": [ + { + "kind": "instructionArgumentNode", + "name": "discriminator", + "type": { + "kind": "numberTypeNode", + "format": "u32", + "endian": "le" + }, + "docs": [], + "defaultValue": { "kind": "numberValueNode", "number": 2 }, + "defaultValueStrategy": "omitted" + }, + { + "kind": "instructionArgumentNode", + "name": "amount", + "type": { + "kind": "numberTypeNode", + "format": "u64", + "endian": "le" + }, + "docs": [] + } + ], + "discriminators": [ + { + "kind": "fieldDiscriminatorNode", + "name": "discriminator", + "offset": 0 + } + ], + "name": "transferSol", + "idlName": "TransferSol", + "docs": [], + "optionalAccountStrategy": "programId" + }, + { + "kind": "instructionNode", + "accounts": [ + { + "kind": "instructionAccountNode", + "name": "payer", + "isWritable": true, + "isSigner": true, + "isOptional": false, + "docs": [], + "defaultValue": { "kind": "payerValueNode" } + }, + { + "kind": "instructionAccountNode", + "name": "newAccount", + "isWritable": true, + "isSigner": false, + "isOptional": false, + "docs": [] + }, + { + "kind": "instructionAccountNode", + "name": "baseAccount", + "isWritable": false, + "isSigner": true, + "isOptional": false, + "docs": [] + } + ], + "arguments": [ + { + "kind": "instructionArgumentNode", + "name": "discriminator", + "type": { + "kind": "numberTypeNode", + "format": "u32", + "endian": "le" + }, + "docs": [], + "defaultValue": { "kind": "numberValueNode", "number": 3 }, + "defaultValueStrategy": "omitted" + }, + { + "kind": "instructionArgumentNode", + "name": "base", + "type": { "kind": "publicKeyTypeNode" }, + "docs": [] + }, + { + "kind": "instructionArgumentNode", + "name": "seed", + "type": { + "kind": "sizePrefixTypeNode", + "type": { "kind": "stringTypeNode", "encoding": "utf8" }, + "prefix": { + "kind": "numberTypeNode", + "format": "u32", + "endian": "le" + } + }, + "docs": [] + }, + { + "kind": "instructionArgumentNode", + "name": "amount", + "type": { + "kind": "numberTypeNode", + "format": "u64", + "endian": "le" + }, + "docs": [] + }, + { + "kind": "instructionArgumentNode", + "name": "space", + "type": { + "kind": "numberTypeNode", + "format": "u64", + "endian": "le" + }, + "docs": [] + }, + { + "kind": "instructionArgumentNode", + "name": "programAddress", + "type": { "kind": "publicKeyTypeNode" }, + "docs": [] + } + ], + "discriminators": [ + { + "kind": "fieldDiscriminatorNode", + "name": "discriminator", + "offset": 0 + } + ], + "name": "createAccountWithSeed", + "idlName": "CreateAccountWithSeed", + "docs": [], + "optionalAccountStrategy": "programId" + }, + { + "kind": "instructionNode", + "accounts": [ + { + "kind": "instructionAccountNode", + "name": "nonceAccount", + "isWritable": true, + "isSigner": false, + "isOptional": false, + "docs": [] + }, + { + "kind": "instructionAccountNode", + "name": "recentBlockhashesSysvar", + "isWritable": false, + "isSigner": false, + "isOptional": false, + "docs": [], + "defaultValue": { + "kind": "publicKeyValueNode", + "publicKey": "SysvarRecentB1ockHashes11111111111111111111" + } + }, + { + "kind": "instructionAccountNode", + "name": "nonceAuthority", + "isWritable": false, + "isSigner": true, + "isOptional": false, + "docs": [] + } + ], + "arguments": [ + { + "kind": "instructionArgumentNode", + "name": "discriminator", + "type": { + "kind": "numberTypeNode", + "format": "u32", + "endian": "le" + }, + "docs": [], + "defaultValue": { "kind": "numberValueNode", "number": 4 }, + "defaultValueStrategy": "omitted" + } + ], + "discriminators": [ + { + "kind": "fieldDiscriminatorNode", + "name": "discriminator", + "offset": 0 + } + ], + "name": "advanceNonceAccount", + "idlName": "AdvanceNonceAccount", + "docs": [], + "optionalAccountStrategy": "programId" + }, + { + "kind": "instructionNode", + "accounts": [ + { + "kind": "instructionAccountNode", + "name": "nonceAccount", + "isWritable": true, + "isSigner": false, + "isOptional": false, + "docs": [] + }, + { + "kind": "instructionAccountNode", + "name": "recipientAccount", + "isWritable": true, + "isSigner": false, + "isOptional": false, + "docs": [] + }, + { + "kind": "instructionAccountNode", + "name": "recentBlockhashesSysvar", + "isWritable": false, + "isSigner": false, + "isOptional": false, + "docs": [], + "defaultValue": { + "kind": "publicKeyValueNode", + "publicKey": "SysvarRecentB1ockHashes11111111111111111111" + } + }, + { + "kind": "instructionAccountNode", + "name": "rentSysvar", + "isWritable": false, + "isSigner": false, + "isOptional": false, + "docs": [], + "defaultValue": { + "kind": "publicKeyValueNode", + "publicKey": "SysvarRent111111111111111111111111111111111" + } + }, + { + "kind": "instructionAccountNode", + "name": "nonceAuthority", + "isWritable": false, + "isSigner": true, + "isOptional": false, + "docs": [] + } + ], + "arguments": [ + { + "kind": "instructionArgumentNode", + "name": "discriminator", + "type": { + "kind": "numberTypeNode", + "format": "u32", + "endian": "le" + }, + "docs": [], + "defaultValue": { "kind": "numberValueNode", "number": 5 }, + "defaultValueStrategy": "omitted" + }, + { + "kind": "instructionArgumentNode", + "name": "withdrawAmount", + "type": { + "kind": "numberTypeNode", + "format": "u64", + "endian": "le" + }, + "docs": [] + } + ], + "discriminators": [ + { + "kind": "fieldDiscriminatorNode", + "name": "discriminator", + "offset": 0 + } + ], + "name": "withdrawNonceAccount", + "idlName": "WithdrawNonceAccount", + "docs": [], + "optionalAccountStrategy": "programId" + }, + { + "kind": "instructionNode", + "accounts": [ + { + "kind": "instructionAccountNode", + "name": "nonceAccount", + "isWritable": true, + "isSigner": false, + "isOptional": false, + "docs": [] + }, + { + "kind": "instructionAccountNode", + "name": "recentBlockhashesSysvar", + "isWritable": false, + "isSigner": false, + "isOptional": false, + "docs": [], + "defaultValue": { + "kind": "publicKeyValueNode", + "publicKey": "SysvarRecentB1ockHashes11111111111111111111" + } + }, + { + "kind": "instructionAccountNode", + "name": "rentSysvar", + "isWritable": false, + "isSigner": false, + "isOptional": false, + "docs": [], + "defaultValue": { + "kind": "publicKeyValueNode", + "publicKey": "SysvarRent111111111111111111111111111111111" + } + } + ], + "arguments": [ + { + "kind": "instructionArgumentNode", + "name": "discriminator", + "type": { + "kind": "numberTypeNode", + "format": "u32", + "endian": "le" + }, + "docs": [], + "defaultValue": { "kind": "numberValueNode", "number": 6 }, + "defaultValueStrategy": "omitted" + }, + { + "kind": "instructionArgumentNode", + "name": "nonceAuthority", + "type": { "kind": "publicKeyTypeNode" }, + "docs": [] + } + ], + "discriminators": [ + { + "kind": "fieldDiscriminatorNode", + "name": "discriminator", + "offset": 0 + } + ], + "name": "initializeNonceAccount", + "idlName": "InitializeNonceAccount", + "docs": [], + "optionalAccountStrategy": "programId" + }, + { + "kind": "instructionNode", + "accounts": [ + { + "kind": "instructionAccountNode", + "name": "nonceAccount", + "isWritable": true, + "isSigner": false, + "isOptional": false, + "docs": [] + }, + { + "kind": "instructionAccountNode", + "name": "nonceAuthority", + "isWritable": false, + "isSigner": true, + "isOptional": false, + "docs": [] + } + ], + "arguments": [ + { + "kind": "instructionArgumentNode", + "name": "discriminator", + "type": { + "kind": "numberTypeNode", + "format": "u32", + "endian": "le" + }, + "docs": [], + "defaultValue": { "kind": "numberValueNode", "number": 7 }, + "defaultValueStrategy": "omitted" + }, + { + "kind": "instructionArgumentNode", + "name": "newNonceAuthority", + "type": { "kind": "publicKeyTypeNode" }, + "docs": [] + } + ], + "discriminators": [ + { + "kind": "fieldDiscriminatorNode", + "name": "discriminator", + "offset": 0 + } + ], + "name": "authorizeNonceAccount", + "idlName": "AuthorizeNonceAccount", + "docs": [], + "optionalAccountStrategy": "programId" + }, + { + "kind": "instructionNode", + "accounts": [ + { + "kind": "instructionAccountNode", + "name": "newAccount", + "isWritable": true, + "isSigner": true, + "isOptional": false, + "docs": [] + } + ], + "arguments": [ + { + "kind": "instructionArgumentNode", + "name": "discriminator", + "type": { + "kind": "numberTypeNode", + "format": "u32", + "endian": "le" + }, + "docs": [], + "defaultValue": { "kind": "numberValueNode", "number": 8 }, + "defaultValueStrategy": "omitted" + }, + { + "kind": "instructionArgumentNode", + "name": "space", + "type": { + "kind": "numberTypeNode", + "format": "u64", + "endian": "le" + }, + "docs": [] + } + ], + "discriminators": [ + { + "kind": "fieldDiscriminatorNode", + "name": "discriminator", + "offset": 0 + } + ], + "name": "allocate", + "idlName": "Allocate", + "docs": [], + "optionalAccountStrategy": "programId" + }, + { + "kind": "instructionNode", + "accounts": [ + { + "kind": "instructionAccountNode", + "name": "newAccount", + "isWritable": true, + "isSigner": false, + "isOptional": false, + "docs": [] + }, + { + "kind": "instructionAccountNode", + "name": "baseAccount", + "isWritable": false, + "isSigner": true, + "isOptional": false, + "docs": [] + } + ], + "arguments": [ + { + "kind": "instructionArgumentNode", + "name": "discriminator", + "type": { + "kind": "numberTypeNode", + "format": "u32", + "endian": "le" + }, + "docs": [], + "defaultValue": { "kind": "numberValueNode", "number": 9 }, + "defaultValueStrategy": "omitted" + }, + { + "kind": "instructionArgumentNode", + "name": "base", + "type": { "kind": "publicKeyTypeNode" }, + "docs": [] + }, + { + "kind": "instructionArgumentNode", + "name": "seed", + "type": { + "kind": "sizePrefixTypeNode", + "type": { "kind": "stringTypeNode", "encoding": "utf8" }, + "prefix": { + "kind": "numberTypeNode", + "format": "u32", + "endian": "le" + } + }, + "docs": [] + }, + { + "kind": "instructionArgumentNode", + "name": "space", + "type": { + "kind": "numberTypeNode", + "format": "u64", + "endian": "le" + }, + "docs": [] + }, + { + "kind": "instructionArgumentNode", + "name": "programAddress", + "type": { "kind": "publicKeyTypeNode" }, + "docs": [] + } + ], + "discriminators": [ + { + "kind": "fieldDiscriminatorNode", + "name": "discriminator", + "offset": 0 + } + ], + "name": "allocateWithSeed", + "idlName": "AllocateWithSeed", + "docs": [], + "optionalAccountStrategy": "programId" + }, + { + "kind": "instructionNode", + "accounts": [ + { + "kind": "instructionAccountNode", + "name": "account", + "isWritable": true, + "isSigner": false, + "isOptional": false, + "docs": [] + }, + { + "kind": "instructionAccountNode", + "name": "baseAccount", + "isWritable": false, + "isSigner": true, + "isOptional": false, + "docs": [] + } + ], + "arguments": [ + { + "kind": "instructionArgumentNode", + "name": "discriminator", + "type": { + "kind": "numberTypeNode", + "format": "u32", + "endian": "le" + }, + "docs": [], + "defaultValue": { "kind": "numberValueNode", "number": 10 }, + "defaultValueStrategy": "omitted" + }, + { + "kind": "instructionArgumentNode", + "name": "base", + "type": { "kind": "publicKeyTypeNode" }, + "docs": [] + }, + { + "kind": "instructionArgumentNode", + "name": "seed", + "type": { + "kind": "sizePrefixTypeNode", + "type": { "kind": "stringTypeNode", "encoding": "utf8" }, + "prefix": { + "kind": "numberTypeNode", + "format": "u32", + "endian": "le" + } + }, + "docs": [] + }, + { + "kind": "instructionArgumentNode", + "name": "programAddress", + "type": { "kind": "publicKeyTypeNode" }, + "docs": [] + } + ], + "discriminators": [ + { + "kind": "fieldDiscriminatorNode", + "name": "discriminator", + "offset": 0 + } + ], + "name": "assignWithSeed", + "idlName": "AssignWithSeed", + "docs": [], + "optionalAccountStrategy": "programId" + }, + { + "kind": "instructionNode", + "accounts": [ + { + "kind": "instructionAccountNode", + "name": "source", + "isWritable": true, + "isSigner": false, + "isOptional": false, + "docs": [] + }, + { + "kind": "instructionAccountNode", + "name": "baseAccount", + "isWritable": false, + "isSigner": true, + "isOptional": false, + "docs": [] + }, + { + "kind": "instructionAccountNode", + "name": "destination", + "isWritable": true, + "isSigner": false, + "isOptional": false, + "docs": [] + } + ], + "arguments": [ + { + "kind": "instructionArgumentNode", + "name": "discriminator", + "type": { + "kind": "numberTypeNode", + "format": "u32", + "endian": "le" + }, + "docs": [], + "defaultValue": { "kind": "numberValueNode", "number": 11 }, + "defaultValueStrategy": "omitted" + }, + { + "kind": "instructionArgumentNode", + "name": "amount", + "type": { + "kind": "numberTypeNode", + "format": "u64", + "endian": "le" + }, + "docs": [] + }, + { + "kind": "instructionArgumentNode", + "name": "fromSeed", + "type": { + "kind": "sizePrefixTypeNode", + "type": { "kind": "stringTypeNode", "encoding": "utf8" }, + "prefix": { + "kind": "numberTypeNode", + "format": "u32", + "endian": "le" + } + }, + "docs": [] + }, + { + "kind": "instructionArgumentNode", + "name": "fromOwner", + "type": { "kind": "publicKeyTypeNode" }, + "docs": [] + } + ], + "discriminators": [ + { + "kind": "fieldDiscriminatorNode", + "name": "discriminator", + "offset": 0 + } + ], + "name": "transferSolWithSeed", + "idlName": "TransferSolWithSeed", + "docs": [], + "optionalAccountStrategy": "programId" + }, + { + "kind": "instructionNode", + "accounts": [ + { + "kind": "instructionAccountNode", + "name": "nonceAccount", + "isWritable": true, + "isSigner": false, + "isOptional": false, + "docs": [] + } + ], + "arguments": [ + { + "kind": "instructionArgumentNode", + "name": "discriminator", + "type": { + "kind": "numberTypeNode", + "format": "u32", + "endian": "le" + }, + "docs": [], + "defaultValue": { "kind": "numberValueNode", "number": 12 }, + "defaultValueStrategy": "omitted" + } + ], + "discriminators": [ + { + "kind": "fieldDiscriminatorNode", + "name": "discriminator", + "offset": 0 + } + ], + "name": "upgradeNonceAccount", + "idlName": "UpgradeNonceAccount", + "docs": [], + "optionalAccountStrategy": "programId" + } + ], + "definedTypes": [ + { + "kind": "definedTypeNode", + "name": "nonceVersion", + "type": { + "kind": "enumTypeNode", + "variants": [ + { "kind": "enumEmptyVariantTypeNode", "name": "legacy" }, + { "kind": "enumEmptyVariantTypeNode", "name": "current" } + ], + "size": { "kind": "numberTypeNode", "format": "u32", "endian": "le" } + }, + "idlName": "NonceVersion", + "docs": [] + }, + { + "kind": "definedTypeNode", + "name": "nonceState", + "type": { + "kind": "enumTypeNode", + "variants": [ + { "kind": "enumEmptyVariantTypeNode", "name": "uninitialized" }, + { "kind": "enumEmptyVariantTypeNode", "name": "initialized" } + ], + "size": { "kind": "numberTypeNode", "format": "u32", "endian": "le" } + }, + "idlName": "NonceState", + "docs": [] + } + ], + "errors": [ + { + "kind": "errorNode", + "name": "accountAlreadyInUse", + "idlName": "AccountAlreadyInUse", + "code": 0, + "message": "an account with the same address already exists", + "docs": ["AccountAlreadyInUse: an account with the same address already exists"] + }, + { + "kind": "errorNode", + "name": "resultWithNegativeLamports", + "idlName": "ResultWithNegativeLamports", + "code": 1, + "message": "account does not have enough SOL to perform the operation", + "docs": ["ResultWithNegativeLamports: account does not have enough SOL to perform the operation"] + }, + { + "kind": "errorNode", + "name": "invalidProgramId", + "idlName": "InvalidProgramId", + "code": 2, + "message": "cannot assign account to this program id", + "docs": ["InvalidProgramId: cannot assign account to this program id"] + }, + { + "kind": "errorNode", + "name": "invalidAccountDataLength", + "idlName": "InvalidAccountDataLength", + "code": 3, + "message": "cannot allocate account data of this length", + "docs": ["InvalidAccountDataLength: cannot allocate account data of this length"] + }, + { + "kind": "errorNode", + "name": "maxSeedLengthExceeded", + "idlName": "MaxSeedLengthExceeded", + "code": 4, + "message": "length of requested seed is too long", + "docs": ["MaxSeedLengthExceeded: length of requested seed is too long"] + }, + { + "kind": "errorNode", + "name": "addressWithSeedMismatch", + "idlName": "AddressWithSeedMismatch", + "code": 5, + "message": "provided address does not match addressed derived from seed", + "docs": ["AddressWithSeedMismatch: provided address does not match addressed derived from seed"] + }, + { + "kind": "errorNode", + "name": "nonceNoRecentBlockhashes", + "idlName": "NonceNoRecentBlockhashes", + "code": 6, + "message": "advancing stored nonce requires a populated RecentBlockhashes sysvar", + "docs": [ + "NonceNoRecentBlockhashes: advancing stored nonce requires a populated RecentBlockhashes sysvar" + ] + }, + { + "kind": "errorNode", + "name": "nonceBlockhashNotExpired", + "idlName": "NonceBlockhashNotExpired", + "code": 7, + "message": "stored nonce is still in recent_blockhashes", + "docs": ["NonceBlockhashNotExpired: stored nonce is still in recent_blockhashes"] + }, + { + "kind": "errorNode", + "name": "nonceUnexpectedBlockhashValue", + "idlName": "NonceUnexpectedBlockhashValue", + "code": 8, + "message": "specified nonce does not match stored nonce", + "docs": ["NonceUnexpectedBlockhashValue: specified nonce does not match stored nonce"] + } + ], + "name": "system", + "prefix": "", + "publicKey": "11111111111111111111111111111111", + "version": "0.0.1", + "origin": "shank" + }, + "additionalPrograms": [], + "standard": "codama", + "version": "1.0.0" +} diff --git a/e2e/system/lib/generated/errors.dart b/e2e/system/lib/generated/errors.dart new file mode 100644 index 0000000..a105376 --- /dev/null +++ b/e2e/system/lib/generated/errors.dart @@ -0,0 +1,8 @@ +/// This code was AUTOGENERATED using the codama library. +/// Please DO NOT EDIT THIS FILE, instead use visitors +/// to add features, then rerun codama to update it. +/// +/// https://github.com/codama-idl/codama +/// + +// This file exports error classes for all programs in the SDK. diff --git a/e2e/system/lib/generated/lib.dart b/e2e/system/lib/generated/lib.dart new file mode 100644 index 0000000..3144eb0 --- /dev/null +++ b/e2e/system/lib/generated/lib.dart @@ -0,0 +1,11 @@ +/// This code was AUTOGENERATED using the codama library. +/// Please DO NOT EDIT THIS FILE, instead use visitors +/// to add features, then rerun codama to update it. +/// +/// https://github.com/codama-idl/codama +/// + +// Entry point for the SDK. +// This file exports all the modules in the SDK. + +export 'programs.dart'; diff --git a/e2e/system/lib/generated/mod.dart b/e2e/system/lib/generated/mod.dart new file mode 100644 index 0000000..3144eb0 --- /dev/null +++ b/e2e/system/lib/generated/mod.dart @@ -0,0 +1,11 @@ +/// This code was AUTOGENERATED using the codama library. +/// Please DO NOT EDIT THIS FILE, instead use visitors +/// to add features, then rerun codama to update it. +/// +/// https://github.com/codama-idl/codama +/// + +// Entry point for the SDK. +// This file exports all the modules in the SDK. + +export 'programs.dart'; diff --git a/e2e/system/lib/generated/programs.dart b/e2e/system/lib/generated/programs.dart new file mode 100644 index 0000000..2122c90 --- /dev/null +++ b/e2e/system/lib/generated/programs.dart @@ -0,0 +1,19 @@ +/// This code was AUTOGENERATED using the codama library. +/// Please DO NOT EDIT THIS FILE, instead use visitors +/// to add features, then rerun codama to update it. +/// +/// https://github.com/codama-idl/codama +/// + +// This file exports program information for all programs in the SDK. + +import 'package:solana/solana.dart'; + +/// Program information for the program. +class Program { + /// The program ID for the program. + static final Ed25519HDPublicKey programId = Ed25519HDPublicKey.fromBase58(""); + + /// The program name. + static const String name = ""; +} diff --git a/e2e/system/pubspec.lock b/e2e/system/pubspec.lock new file mode 100644 index 0000000..86d9781 --- /dev/null +++ b/e2e/system/pubspec.lock @@ -0,0 +1,261 @@ +# Generated by pub +# See https://dart.dev/tools/pub/glossary#lockfile +packages: + async: + dependency: transitive + description: + name: async + sha256: "758e6d74e971c3e5aceb4110bfd6698efc7f501675bcfe0c775459a8140750eb" + url: "https://pub.dev" + source: hosted + version: "2.13.0" + bip39: + dependency: transitive + description: + name: bip39 + sha256: de1ee27ebe7d96b84bb3a04a4132a0a3007dcdd5ad27dd14aa87a29d97c45edc + url: "https://pub.dev" + source: hosted + version: "1.0.6" + borsh_annotation: + dependency: transitive + description: + name: borsh_annotation + sha256: dc73a7fdc6fe4505535657daf8ab3cebe382311fae63a0faaf9315ea1bc30bff + url: "https://pub.dev" + source: hosted + version: "0.3.2" + clock: + dependency: transitive + description: + name: clock + sha256: fddb70d9b5277016c77a80201021d40a2247104d9f4aa7bab7157b7e3f05b84b + url: "https://pub.dev" + source: hosted + version: "1.1.2" + collection: + dependency: transitive + description: + name: collection + sha256: "2f5709ae4d3d59dd8f7cd309b4e023046b57d8a6c82130785d2b0e5868084e76" + url: "https://pub.dev" + source: hosted + version: "1.19.1" + convert: + dependency: transitive + description: + name: convert + sha256: b30acd5944035672bc15c6b7a8b47d773e41e2f17de064350988c5d02adb1c68 + url: "https://pub.dev" + source: hosted + version: "3.1.2" + crypto: + dependency: transitive + description: + name: crypto + sha256: "1e445881f28f22d6140f181e07737b22f1e099a5e1ff94b0af2f9e4a463f4855" + url: "https://pub.dev" + source: hosted + version: "3.0.6" + cryptography: + dependency: transitive + description: + name: cryptography + sha256: d146b76d33d94548cf035233fbc2f4338c1242fa119013bead807d033fc4ae05 + url: "https://pub.dev" + source: hosted + version: "2.7.0" + decimal: + dependency: transitive + description: + name: decimal + sha256: fc706a5618b81e5b367b01dd62621def37abc096f2b46a9bd9068b64c1fa36d0 + url: "https://pub.dev" + source: hosted + version: "3.2.4" + ed25519_hd_key: + dependency: transitive + description: + name: ed25519_hd_key + sha256: "31e191ec97492873067e46dc9cc0c7d55170559c83a478400feffa0627acaccf" + url: "https://pub.dev" + source: hosted + version: "2.3.0" + ffi: + dependency: transitive + description: + name: ffi + sha256: "289279317b4b16eb2bb7e271abccd4bf84ec9bdcbe999e278a94b804f5630418" + url: "https://pub.dev" + source: hosted + version: "2.1.4" + freezed_annotation: + dependency: transitive + description: + name: freezed_annotation + sha256: c2e2d632dd9b8a2b7751117abcfc2b4888ecfe181bd9fca7170d9ef02e595fe2 + url: "https://pub.dev" + source: hosted + version: "2.4.4" + hex: + dependency: transitive + description: + name: hex + sha256: "4e7cd54e4b59ba026432a6be2dd9d96e4c5205725194997193bf871703b82c4a" + url: "https://pub.dev" + source: hosted + version: "0.2.0" + http: + dependency: transitive + description: + name: http + sha256: bb2ce4590bc2667c96f318d68cac1b5a7987ec819351d32b1c987239a815e007 + url: "https://pub.dev" + source: hosted + version: "1.5.0" + http_parser: + dependency: transitive + description: + name: http_parser + sha256: "178d74305e7866013777bab2c3d8726205dc5a4dd935297175b19a23a2e66571" + url: "https://pub.dev" + source: hosted + version: "4.1.2" + intl: + dependency: transitive + description: + name: intl + sha256: "3df61194eb431efc39c4ceba583b95633a403f46c9fd341e550ce0bfa50e9aa5" + url: "https://pub.dev" + source: hosted + version: "0.20.2" + js: + dependency: transitive + description: + name: js + sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3 + url: "https://pub.dev" + source: hosted + version: "0.6.7" + json_annotation: + dependency: transitive + description: + name: json_annotation + sha256: "1ce844379ca14835a50d2f019a3099f419082cfdd231cd86a142af94dd5c6bb1" + url: "https://pub.dev" + source: hosted + version: "4.9.0" + meta: + dependency: transitive + description: + name: meta + sha256: "23f08335362185a5ea2ad3a4e597f1375e78bce8a040df5c600c8d3552ef2394" + url: "https://pub.dev" + source: hosted + version: "1.17.0" + path: + dependency: transitive + description: + name: path + sha256: "75cca69d1490965be98c73ceaea117e8a04dd21217b37b292c9ddbec0d955bc5" + url: "https://pub.dev" + source: hosted + version: "1.9.1" + pinenacl: + dependency: transitive + description: + name: pinenacl + sha256: "57e907beaacbc3c024a098910b6240758e899674de07d6949a67b52fd984cbdf" + url: "https://pub.dev" + source: hosted + version: "0.6.0" + pointycastle: + dependency: transitive + description: + name: pointycastle + sha256: "4be0097fcf3fd3e8449e53730c631200ebc7b88016acecab2b0da2f0149222fe" + url: "https://pub.dev" + source: hosted + version: "3.9.1" + rational: + dependency: transitive + description: + name: rational + sha256: cb808fb6f1a839e6fc5f7d8cb3b0a10e1db48b3be102de73938c627f0b636336 + url: "https://pub.dev" + source: hosted + version: "2.2.3" + solana: + dependency: "direct main" + description: + name: solana + sha256: "98d8780dbd9af7e90ff14a6e762a45d77466450304773610317d1fffdea09701" + url: "https://pub.dev" + source: hosted + version: "0.31.2+1" + source_span: + dependency: transitive + description: + name: source_span + sha256: "254ee5351d6cb365c859e20ee823c3bb479bf4a293c22d17a9f1bf144ce86f7c" + url: "https://pub.dev" + source: hosted + version: "1.10.1" + stream_channel: + dependency: transitive + description: + name: stream_channel + sha256: "969e04c80b8bcdf826f8f16579c7b14d780458bd97f56d107d3950fdbeef059d" + url: "https://pub.dev" + source: hosted + version: "2.1.4" + string_scanner: + dependency: transitive + description: + name: string_scanner + sha256: "921cd31725b72fe181906c6a94d987c78e3b98c2e205b397ea399d4054872b43" + url: "https://pub.dev" + source: hosted + version: "1.4.1" + term_glyph: + dependency: transitive + description: + name: term_glyph + sha256: "7f554798625ea768a7518313e58f83891c7f5024f88e46e7182a4558850a4b8e" + url: "https://pub.dev" + source: hosted + version: "1.2.2" + typed_data: + dependency: transitive + description: + name: typed_data + sha256: f9049c039ebfeb4cf7a7104a675823cd72dba8297f264b6637062516699fa006 + url: "https://pub.dev" + source: hosted + version: "1.4.0" + web: + dependency: transitive + description: + name: web + sha256: "868d88a33d8a87b18ffc05f9f030ba328ffefba92d6c127917a2ba740f9cfe4a" + url: "https://pub.dev" + source: hosted + version: "1.1.1" + web_socket: + dependency: transitive + description: + name: web_socket + sha256: "34d64019aa8e36bf9842ac014bb5d2f5586ca73df5e4d9bf5c936975cae6982c" + url: "https://pub.dev" + source: hosted + version: "1.0.1" + web_socket_channel: + dependency: transitive + description: + name: web_socket_channel + sha256: d645757fb0f4773d602444000a8131ff5d48c9e47adfe9772652dd1a4f2d45c8 + url: "https://pub.dev" + source: hosted + version: "3.0.3" +sdks: + dart: ">=3.7.0 <4.0.0" diff --git a/e2e/system/pubspec.yaml b/e2e/system/pubspec.yaml new file mode 100644 index 0000000..d5439c1 --- /dev/null +++ b/e2e/system/pubspec.yaml @@ -0,0 +1,7 @@ +name: system +description: system project for e2e generated Dart code +version: 0.1.0 +environment: + sdk: '>=2.17.0 <4.0.0' +dependencies: + solana: ^0.31.2+1 \ No newline at end of file diff --git a/e2e/test.sh b/e2e/test.sh new file mode 100755 index 0000000..4135be7 --- /dev/null +++ b/e2e/test.sh @@ -0,0 +1,43 @@ +#!/usr/bin/env bash +set -eux + +function print_dart_errors() { + local project="$1" + local log_file="${2:-analyze.log}" + RED='\033[0;31m' + NC='\033[0m' + if grep -q 'error ' "$log_file"; then + echo "" + echo -e "${RED}==================== Dart Analysis Errors in $project ====================${NC}" + echo "" + grep 'error ' "$log_file" | sed 's/^/ /' + echo "" + echo -e "${RED}====================================================================${NC}" + echo "" + echo "Dart analysis found errors in $project" + exit 1 + fi +} + +function test_project() { + ./e2e/generate.cjs $1 + cd e2e/$1 + + # Run dart analyze and fail only if there are errors + dart analyze > analyze.log || true + print_dart_errors "$1" analyze.log + + cd ../.. +} + +function test_anchor_project() { + ./e2e/generate-anchor.cjs $1 + cd e2e/$1 + cd ../.. +} + +test_project dummy +test_project system +test_project memo +# test_project meteora # TODO: uncomment after some internal fixes +test_anchor_project anchor \ No newline at end of file diff --git a/package.json b/package.json index 469fe43..8e67533 100644 --- a/package.json +++ b/package.json @@ -7,9 +7,9 @@ "types": "./dist/index.d.ts", "type": "module", "files": [ - "./dist/templates", - "./dist/types", - "./dist/index.*" + "./dist/templates", + "./dist/types", + "./dist/index.*" ], "sideEffects": false, "keywords": [ @@ -26,8 +26,12 @@ "build:types": "tsc --build tsconfig.declarations.json", "lint": "eslint .", "lint:fix": "eslint . --fix", - "test": "echo \"Error: no test specified\" && exit 1", - "test:e2e": "sh ./e2e/test.sh" + "test": "pnpm test:types && pnpm test:treeshakability && pnpm test:node && pnpm test:e2e && pnpm test:exports", + "test:e2e": "sh ./e2e/test.sh", + "test:exports": "node ./test/exports/module.mjs && node ./test/exports/commonjs.cjs", + "test:node": "zx ./scripts/test-unit.mjs node", + "test:treeshakability": "zx ./scripts/test-treeshakability.mjs", + "test:types": "zx ./scripts/test-types.mjs" }, "repository": { "type": "git", @@ -40,12 +44,19 @@ }, "homepage": "https://github.com/LimeChain/codama-dart#readme", "devDependencies": { + "@codama/cli": "^1.3.4", + "@codama/nodes-from-anchor": "^1.2.8", "@types/node": "^24.3.1", "@types/nunjucks": "^3.2.6", + "agadoo": "^3.0.0", "browserslist-to-esbuild": "^2.1.1", + "codama": "^1.3.6", "rimraf": "^5.0.0", "tsup": "^8.5.0", - "typescript": "^5.9.2" + "turbo": "^2.5.6", + "typescript": "^5.9.2", + "vitest": "^3.2.4", + "zx": "^8.8.1" }, "dependencies": { "@codama/errors": "^1.3.4", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index acfb06d..01f0b37 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -24,43 +24,90 @@ importers: specifier: ^3.2.4 version: 3.2.4 devDependencies: + '@codama/cli': + specifier: ^1.3.4 + version: 1.3.4 + '@codama/nodes-from-anchor': + specifier: ^1.2.8 + version: 1.2.8(fastestsmallesttextencoderdecoder@1.0.22)(typescript@5.9.2) '@types/node': specifier: ^24.3.1 version: 24.3.1 '@types/nunjucks': specifier: ^3.2.6 version: 3.2.6 + agadoo: + specifier: ^3.0.0 + version: 3.0.0 browserslist-to-esbuild: specifier: ^2.1.1 version: 2.1.1(browserslist@4.25.4) + codama: + specifier: ^1.3.6 + version: 1.3.6 rimraf: specifier: ^5.0.0 version: 5.0.10 tsup: specifier: ^8.5.0 - version: 8.5.0(typescript@5.9.2) + version: 8.5.0(postcss@8.5.6)(typescript@5.9.2) + turbo: + specifier: ^2.5.6 + version: 2.5.6 typescript: specifier: ^5.9.2 version: 5.9.2 + vitest: + specifier: ^3.2.4 + version: 3.2.4(@types/node@24.3.1) + zx: + specifier: ^8.8.1 + version: 8.8.1 packages: + '@codama/cli@1.3.4': + resolution: {integrity: sha512-MfnB4M8XhywaeRolZ190MsGu2m9VPFy9ovffvj3ox7KQ9u12u9NwsDkrMmjpX3SmQXH2XTLGnLlxpWdMecZ0bA==} + hasBin: true + '@codama/errors@1.3.4': resolution: {integrity: sha512-gEbfWkf5J1klGlLbrg5zIMYTncYO6SCsLRxKbDRrE1TmxRqt3cUovQyPhccGcNh/e/GisauIGjbsZTJaFNgXuw==} hasBin: true + '@codama/errors@1.3.6': + resolution: {integrity: sha512-pWP42vregNgFGKY/hF4ifyfSL8FfYNnd0fKXjxP3IUX9HS7+T1CcfgfJ7St9YI6C77LpFPWmx+68Af4DGnAhKA==} + hasBin: true + '@codama/node-types@1.3.4': resolution: {integrity: sha512-WOKU9v019gfX58y+I+hadokckvYLEZKvcsXpf578S+B+sV9YBCOhIjlzDDONcfe9iGUw49M6VpyWkp+EenasLg==} + '@codama/node-types@1.3.6': + resolution: {integrity: sha512-n9BpPh/Kl6Z6Bbt1MtsKykAtdPKljoBm4T8ea1IL9ABdFs+wnvgZBxnIAhgM0hC82AtvQPNGezXzLTER1JZpyg==} + + '@codama/nodes-from-anchor@1.2.8': + resolution: {integrity: sha512-nW/amXV5OxOc+ZqOqt4ZZEJ2c2Fvp0MIGEMmeqKrSM/Yf2e0K9K4UP5btUXGpdAkNbLM/lWlEBBTkAcWONpttw==} + '@codama/nodes@1.3.4': resolution: {integrity: sha512-Q3eS/kMqiozZzlpY/otVfQQ9M3pRdCS0D1dlB3TyuHWBAJiAGPfjRT21KQ4M8xub6eTWJY7PwT7sykPqS/fQPg==} + '@codama/nodes@1.3.6': + resolution: {integrity: sha512-6fgnfmx0v5fR153Lkwe4Ghl2ei/7ZEqFfGZxRPzzzYwPAE/Q5Am+xZ0mULDyI1wW37HftCtAkTuXnIv2+6l+SQ==} + '@codama/renderers-core@1.1.0': resolution: {integrity: sha512-OscEiIv4nXiiqb2I9PWDI0Aw8bM6Qdtb9oqbuFb0XXt8hJTeLoNk+AN8ZZFtJMtiy+SizJjUsbX2KFE2HsVhdg==} + '@codama/validators@1.3.6': + resolution: {integrity: sha512-14VcLfo8bHERxKRsnKR8m3fVWSgoDM8v7M8wrgO0bEXElTOwMFGSyL5wbs4RqWQ/LFO7uB/IGSZo//jkOUvT9A==} + '@codama/visitors-core@1.3.4': resolution: {integrity: sha512-TCP1ncA0ErBvv5q8BKCRvv98qHh9on8MOiPhdToJ/w50aNm0y5Y2mHbUWqk5vle8k3V9fuo7uf1aAOaqA6G4Vg==} + '@codama/visitors-core@1.3.6': + resolution: {integrity: sha512-qdG27oyCYYG53vD9V/M60/TS6IxlMSf8b/5KLb/UgCykNRFLxXhDZXkwnMKKtF3LgHFxaayb0Zq+W1Z0lmjaig==} + + '@codama/visitors@1.3.6': + resolution: {integrity: sha512-9SIOd08QBXUgFWyscSjbzwT2ljZflh4+LS+HS42Vg9BPkJAqJHflya1jl2LVsTM+oBcROl1/5uFR0zuLU3wZtA==} + '@esbuild/aix-ppc64@0.25.9': resolution: {integrity: sha512-OaGtL73Jck6pBKjNIe24BnFE6agGl+6KxDtTfHhy1HmhthfKouEcOhqpSL64K4/0WCtbKFLOdzD/44cJ4k9opA==} engines: {node: '>=18'} @@ -234,10 +281,23 @@ packages: '@jridgewell/trace-mapping@0.3.30': resolution: {integrity: sha512-GQ7Nw5G2lTu/BtHTKfXhKHok2WGetd4XYcVKGx00SjAk8GMwgJM3zr6zORiPGuOE+/vkc90KtTosSSvaCjKb2Q==} + '@noble/hashes@1.8.0': + resolution: {integrity: sha512-jCs9ldd7NwzpgXDIf6P3+NrHh9/sD6CQdxHyjQI+h/6rDNo88ypBxxz45UDuZHz9r3tNz7N/VInSVoVdtXEI4A==} + engines: {node: ^14.21.3 || >=16} + '@pkgjs/parseargs@0.11.0': resolution: {integrity: sha512-+1VkjdD0QBLPodGrJUeqarH8VAIvQODIbwh9XpP5Syisf7YoQgsJKPNFoqqLQlu+VQ/tVSshMR6loPMn8U+dPg==} engines: {node: '>=14'} + '@rollup/plugin-virtual@3.0.2': + resolution: {integrity: sha512-10monEYsBp3scM4/ND4LNH5Rxvh3e/cVeL3jWTgZ2SrQ+BmUoQcopVQvnaMcOnykb1VkxUFuDAN+0FnpTFRy2A==} + engines: {node: '>=14.0.0'} + peerDependencies: + rollup: ^1.20.0||^2.0.0||^3.0.0||^4.0.0 + peerDependenciesMeta: + rollup: + optional: true + '@rollup/rollup-android-arm-eabi@4.50.1': resolution: {integrity: sha512-HJXwzoZN4eYTdD8bVV22DN8gsPCAj3V20NHKOs8ezfXanGpmVPR7kalUHd+Y31IJp9stdB87VKPFbsGY3H/2ag==} cpu: [arm] @@ -343,6 +403,56 @@ packages: cpu: [x64] os: [win32] + '@solana/codecs-core@3.0.3': + resolution: {integrity: sha512-emKykJ3h1DmnDOY29Uv9eJXP8E/FHzvlUBJ6te+5EbKdFjj7vdlKYPfDxOI6iGdXTY+YC/ELtbNBh6QwF2uEDQ==} + engines: {node: '>=20.18.0'} + peerDependencies: + typescript: '>=5.3.3' + + '@solana/codecs-data-structures@3.0.3': + resolution: {integrity: sha512-R15cLp8riJvToXziW8lP6AMSwsztGhEnwgyGmll32Mo0Yjq+hduW2/fJrA/TJs6tA/OgTzMQjlxgk009EqZHCw==} + engines: {node: '>=20.18.0'} + peerDependencies: + typescript: '>=5.3.3' + + '@solana/codecs-numbers@3.0.3': + resolution: {integrity: sha512-pfXkH9J0glrM8qj6389GAn30+cJOxzXLR2FsPOHCUMXrqLhGjMMZAWhsQkpOQ37SGc/7EiQsT/gmyGC7gxHqJQ==} + engines: {node: '>=20.18.0'} + peerDependencies: + typescript: '>=5.3.3' + + '@solana/codecs-strings@3.0.3': + resolution: {integrity: sha512-VHBXnnTVtcQ1j+7Vrz+qSYo38no+jiHRdGnhFspRXEHNJbllzwKqgBE7YN3qoIXH+MKxgJUcwO5KHmdzf8Wn2A==} + engines: {node: '>=20.18.0'} + peerDependencies: + fastestsmallesttextencoderdecoder: ^1.0.22 + typescript: '>=5.3.3' + + '@solana/codecs@3.0.3': + resolution: {integrity: sha512-GOHwTlIQsCoJx9Ryr6cEf0FHKAQ7pY4aO4xgncAftrv0lveTQ1rPP2inQ1QT0gJllsIa8nwbfXAADs9nNJxQDA==} + engines: {node: '>=20.18.0'} + peerDependencies: + typescript: '>=5.3.3' + + '@solana/errors@3.0.3': + resolution: {integrity: sha512-1l84xJlHNva6io62PcYfUamwWlc0eM95nHgCrKX0g0cLoC6D6QHYPCEbEVkR+C5UtP9JDgyQM8MFiv+Ei5tO9Q==} + engines: {node: '>=20.18.0'} + hasBin: true + peerDependencies: + typescript: '>=5.3.3' + + '@solana/options@3.0.3': + resolution: {integrity: sha512-jarsmnQ63RN0JPC5j9sgUat07NrL9PC71XU7pUItd6LOHtu4+wJMio3l5mT0DHVfkfbFLL6iI6+QmXSVhTNF3g==} + engines: {node: '>=20.18.0'} + peerDependencies: + typescript: '>=5.3.3' + + '@types/chai@5.2.2': + resolution: {integrity: sha512-8kB30R7Hwqf40JPiKhVzodJs2Qc1ZJ5zuT3uzw5Hq/dhNCl3G3l83jfpdI1e20BP348+fV7VIL/+FxaXkqBmWg==} + + '@types/deep-eql@4.0.2': + resolution: {integrity: sha512-c9h9dVVMigMPc4bwTvC5dxqtqJZwQPePsWjPlpSOnojbor6pGqdk541lfA7AqFQr5pB1BRdq0juY9db81BwyFw==} + '@types/estree@1.0.8': resolution: {integrity: sha512-dWHzHa2WqEXI/O1E9OjrocMTKJl2mSrEolh1Iomrv6U+JuNwaHXsXx9bLu5gG7BUWFIN0skIQJQ/L1rIex4X6w==} @@ -352,6 +462,35 @@ packages: '@types/nunjucks@3.2.6': resolution: {integrity: sha512-pHiGtf83na1nCzliuAdq8GowYiXvH5l931xZ0YEHaLMNFgynpEqx+IPStlu7UaDkehfvl01e4x/9Tpwhy7Ue3w==} + '@vitest/expect@3.2.4': + resolution: {integrity: sha512-Io0yyORnB6sikFlt8QW5K7slY4OjqNX9jmJQ02QDda8lyM6B5oNgVWoSoKPac8/kgnCUzuHQKrSLtu/uOqqrig==} + + '@vitest/mocker@3.2.4': + resolution: {integrity: sha512-46ryTE9RZO/rfDd7pEqFl7etuyzekzEhUbTW3BvmeO/BcCMEgq59BKhek3dXDWgAj4oMK6OZi+vRr1wPW6qjEQ==} + peerDependencies: + msw: ^2.4.9 + vite: ^5.0.0 || ^6.0.0 || ^7.0.0-0 + peerDependenciesMeta: + msw: + optional: true + vite: + optional: true + + '@vitest/pretty-format@3.2.4': + resolution: {integrity: sha512-IVNZik8IVRJRTr9fxlitMKeJeXFFFN0JaB9PHPGQ8NKQbGpfjlTx9zO4RefN8gp7eqjNy8nyK3NZmBzOPeIxtA==} + + '@vitest/runner@3.2.4': + resolution: {integrity: sha512-oukfKT9Mk41LreEW09vt45f8wx7DordoWUZMYdY/cyAk7w5TWkTRCNZYF7sX7n2wB7jyGAl74OxgwhPgKaqDMQ==} + + '@vitest/snapshot@3.2.4': + resolution: {integrity: sha512-dEYtS7qQP2CjU27QBC5oUOxLE/v5eLkGqPE0ZKEIDGMs4vKWe7IjgLOeauHsR0D5YuuycGRO5oSRXnwnmA78fQ==} + + '@vitest/spy@3.2.4': + resolution: {integrity: sha512-vAfasCOe6AIK70iP5UD11Ac4siNUNJ9i/9PZ3NKx07sG6sUxeag1LWdNrMWeKKYBLlzuK+Gn65Yd5nyL6ds+nw==} + + '@vitest/utils@3.2.4': + resolution: {integrity: sha512-fB2V0JFrQSMsCo9HiSq3Ezpdv4iYaXRG1Sx8edX3MwxfyNn83mKiGzOcH+Fkxt4MHxr3y42fQi1oeAInqgX2QA==} + a-sync-waterfall@1.0.1: resolution: {integrity: sha512-RYTOHHdWipFUliRFMCS4X2Yn2X8M87V/OpSqWzKKOGhzqyUxzyVmhHDH9sAvG+ZuQf/TAOFsLCpMw09I1ufUnA==} @@ -360,6 +499,10 @@ packages: engines: {node: '>=0.4.0'} hasBin: true + agadoo@3.0.0: + resolution: {integrity: sha512-gq+fjT3Ilrhb88Jf+vYMjdO/+3znYfa7vJ4IMLPFsBPUxglnr40Ed3yCLrW6IABdJAedB94b2BkqR6I04lh3dg==} + hasBin: true + ansi-regex@5.0.1: resolution: {integrity: sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==} engines: {node: '>=8'} @@ -382,6 +525,10 @@ packages: asap@2.0.6: resolution: {integrity: sha512-BSHWgDSAiKs50o2Re8ppvp3seVHXSRM44cdSsT9FfNEUUZLOGWVCsiWaRPWM1Znn+mqZ1OfVZ3z3DWEzSp7hRA==} + assertion-error@2.0.1: + resolution: {integrity: sha512-Izi8RQcffqCeNVgFigKli1ssklIbpHnCYc6AknXGYoB6grJqyeby7jv12JUQgmTAnIDnbck1uxksT4dzN3PWBA==} + engines: {node: '>=12'} + balanced-match@1.0.2: resolution: {integrity: sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==} @@ -425,14 +572,26 @@ packages: caniuse-lite@1.0.30001741: resolution: {integrity: sha512-QGUGitqsc8ARjLdgAfxETDhRbJ0REsP6O3I96TAth/mVjh2cYzN2u+3AzPP3aVSm2FehEItaJw1xd+IGBXWeSw==} + chai@5.3.3: + resolution: {integrity: sha512-4zNhdJD/iOjSH0A05ea+Ke6MU5mmpQcbQsSOkgdaUMJ9zTlDTD/GYlwohmIE2u0gaxHYiVHEn1Fw9mZ/ktJWgw==} + engines: {node: '>=18'} + chalk@5.6.2: resolution: {integrity: sha512-7NzBL0rN6fMUW+f7A6Io4h40qQlG+xGmtMxfbnH/K7TAtt8JQWVQK+6g0UXKMeVJoyV5EkkNsErQ8pVD3bLHbA==} engines: {node: ^12.17.0 || ^14.13 || >=16.0.0} + check-error@2.1.1: + resolution: {integrity: sha512-OAlb+T7V4Op9OwdkjmguYRqncdlx5JiofwOAUkmTF+jNdHwzTaTs4sRAGpzLF3oOz5xAyDGrPgeIDFQmDOTiJw==} + engines: {node: '>= 16'} + chokidar@4.0.3: resolution: {integrity: sha512-Qgzu8kfBvo+cA4962jnP1KkS6Dop5NS6g7R5LFYJr4b8Ub94PPQXUksCw9PvXoeXPRRddRNC5C1JQUR2SMGtnA==} engines: {node: '>= 14.16.0'} + codama@1.3.6: + resolution: {integrity: sha512-tbNizqhWMB42AHIq4sD5frMwEuF9/xJTa90D074q1Lhp/9eeoEk0feaRUlboQVyniq8A3EJm8Kj8oUA2daiB1w==} + hasBin: true + color-convert@2.0.1: resolution: {integrity: sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==} engines: {node: '>=7.0.0'} @@ -444,6 +603,10 @@ packages: resolution: {integrity: sha512-2uM9rYjPvyq39NwLRqaiLtWHyDC1FvryJDa2ATTVims5YAS4PupsEQsDvP14FqhFr0P49CYDugi59xaxJlTXRA==} engines: {node: '>=20'} + commander@14.0.1: + resolution: {integrity: sha512-2JkV3gUZUVrbNA+1sjBOYLsMZ5cEEl8GTFP2a4AVz5hvasAMCQ1D2l2le/cX+pV4N6ZU17zjUahLpIXRrnWL8A==} + engines: {node: '>=20'} + commander@4.1.1: resolution: {integrity: sha512-NOKm8xhkzAjzFx8B2v5OAHT+u5pRQc2UCa2Vq9jYL/31o2wi9mxBA7LIFs3sV5VSC49z6pEhfbMULvShKj26WA==} engines: {node: '>= 6'} @@ -472,6 +635,10 @@ packages: supports-color: optional: true + deep-eql@5.0.2: + resolution: {integrity: sha512-h5k/5U50IJJFpzfL6nO9jaaumfjO/f2NjK/oYB2Djzm4p9L+3T9qWpZqZ2hAbLPuuYq9wrU08WQyBTL5GbPk5Q==} + engines: {node: '>=6'} + define-data-property@1.1.4: resolution: {integrity: sha512-rBMvIzlpA8v6E+SJZoo++HAYqsLrkg7MSfIinMPFhmkorw7X+dOXVJQs+QT69zGkzMyfDnIMN2Wid1+NbL3T+A==} engines: {node: '>= 0.4'} @@ -500,6 +667,9 @@ packages: resolution: {integrity: sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==} engines: {node: '>= 0.4'} + es-module-lexer@1.7.0: + resolution: {integrity: sha512-jEQoCwk8hyb2AZziIOLhDqpm5+2ww5uIE6lkO/6jcOCusfk6LhMHpXXfBLXTZ7Ydyt0j4VoUQv6uGNYbdW+kBA==} + es-object-atoms@1.1.1: resolution: {integrity: sha512-FGgH2h8zKNim9ljj7dankFPcICIK9Cp5bm+c2gQSYePhpaG5+esrLODihIorn+Pe6FGJzWhXQotPv73jTaldXA==} engines: {node: '>= 0.4'} @@ -513,6 +683,16 @@ packages: resolution: {integrity: sha512-WUj2qlxaQtO4g6Pq5c29GTcWGDyd8itL8zTlipgECz3JesAiiOKotd8JU6otB3PACgG6xkJUyVhboMS+bje/jA==} engines: {node: '>=6'} + estree-walker@3.0.3: + resolution: {integrity: sha512-7RUKfXgSMMkzt6ZuXmqapOurLGPPfgj6l9uRZ7lRGolvk0y2yocc35LdcxKC5PQZdn2DMqioAQ2NoWcrTKmm6g==} + + expect-type@1.2.2: + resolution: {integrity: sha512-JhFGDVJ7tmDJItKhYgJCGLOWjuK9vPxiXoUFLwLDc99NlmklilbiQJwoctZtt13+xMw91MCk/REan6MWHqDjyA==} + engines: {node: '>=12.0.0'} + + fastestsmallesttextencoderdecoder@1.0.22: + resolution: {integrity: sha512-Pb8d48e+oIuY4MaM64Cd7OW1gt4nxCHs7/ddPPZ/Ic3sg8yVGM7O9wDvZ7us6ScaUupzM+pfBolwtYhN1IxBIw==} + fdir@6.5.0: resolution: {integrity: sha512-tIbYtZbucOs0BRGqPJkshJUYdL+SDH7dVM8gjy+ERp3WAUjLEFJE+02kanyHtwjWOnwrKYBiwAmM0p4kLJAnXg==} engines: {node: '>=12.0.0'} @@ -581,6 +761,9 @@ packages: resolution: {integrity: sha512-34wB/Y7MW7bzjKRjUKTa46I2Z7eV62Rkhva+KkopW7Qvv/OSWBqvkSY7vusOPrNuZcUG3tApvdVgNB8POj3SPw==} engines: {node: '>=10'} + js-tokens@9.0.1: + resolution: {integrity: sha512-mxa9E9ITFOt0ban3j6L5MpjwegGz6lBQmM1IJkWeBZGcMxto50+eWdjC/52xDbS2vy0k7vIMK0Fe2wfL9OQSpQ==} + json-stable-stringify@1.3.0: resolution: {integrity: sha512-qtYiSSFlwot9XHtF9bD9c7rwKjr+RecWT//ZnPvSmEjpV5mmPOCN4j8UjY5hbjNkOwZ/jQv3J6R1/pL7RwgMsg==} engines: {node: '>= 0.4'} @@ -588,6 +771,10 @@ packages: jsonify@0.0.1: resolution: {integrity: sha512-2/Ki0GcmuqSrgFyelQq9M05y7PS0mEwuIzrf3f1fPqkVDVRvZrPZtVSMHxdgo8Aq0sxAOb/cr2aqqA3LeWHVPg==} + kleur@3.0.3: + resolution: {integrity: sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==} + engines: {node: '>=6'} + lilconfig@3.1.3: resolution: {integrity: sha512-/vlFKAoH5Cgt3Ie+JLhRbwOsCQePABiU3tJ1egGvyQ+33R/vcwM2Zl2QR/LzjsBeItPt3oSVXapn+m4nQDvpzw==} engines: {node: '>=14'} @@ -602,6 +789,9 @@ packages: lodash.sortby@4.7.0: resolution: {integrity: sha512-HDWXG8isMntAyRF5vZ7xKuEvOhT4AhlRt/3czTSjvGUxjYCBVRQY48ViDHyfYz9VIoBkW4TMGQNapx+l3RUwdA==} + loupe@3.2.1: + resolution: {integrity: sha512-CdzqowRJCeLU72bHvWqwRBBlLcMEtIvGrlvef74kMnV2AolS9Y8xUv1I0U/MNAWMhBlKIoyuEgoJ0t/bbwHbLQ==} + lru-cache@10.4.3: resolution: {integrity: sha512-JNAzZcXrCt42VGLuYz0zfAzDfAvJWW6AfYlDBQyDV5DClI2m5sAmK+OIO7s59XfsRsWHp02jAJrRadPRGTt6SQ==} @@ -633,6 +823,11 @@ packages: mz@2.7.0: resolution: {integrity: sha512-z81GNO7nnYMEhrGh9LeymoE4+Yr0Wn5McHIZMK5cfQCl+NDX08sCZgUc9/6MHni9IWuFLm1Z3HTCXu2z9fN62Q==} + nanoid@3.3.11: + resolution: {integrity: sha512-N8SpfPUnUp1bK+PMYW8qSWdl9U+wwNWI4QKxOYDy9JAro3WMX7p2OeVRF9v+347pnakNevPmiHhNmZ2HbFA76w==} + engines: {node: ^10 || ^12 || ^13.7 || ^14 || >=15.0.1} + hasBin: true + node-releases@2.0.20: resolution: {integrity: sha512-7gK6zSXEH6neM212JgfYFXe+GmZQM+fia5SsusuBIUgnPheLFBmIPhtFoAQRj8/7wASYQnbDlHPVwY0BefoFgA==} @@ -668,6 +863,10 @@ packages: pathe@2.0.3: resolution: {integrity: sha512-WUjGcAqP1gQacoQe+OBJsFA7Ld4DyXuUIjZ5cc75cLHvJ7dtNsTugphxIADwspS+AraAUePCKrSVtPLFj/F88w==} + pathval@2.0.1: + resolution: {integrity: sha512-//nshmD55c46FuFw26xV/xFAaB5HF9Xdap7HJBBnrKdAd6/GxDBaNA1870O79+9ueg61cZLSVc+OaFlfmObYVQ==} + engines: {node: '>= 14.16'} + picocolors@1.1.1: resolution: {integrity: sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==} @@ -700,6 +899,14 @@ packages: yaml: optional: true + postcss@8.5.6: + resolution: {integrity: sha512-3Ybi1tAuwAP9s0r1UQ2J4n5Y0G05bJkpUIO0/bI9MhwmD70S5aTWbXGBwxHrelT+XM1k6dM0pk+SwNkpTRN7Pg==} + engines: {node: ^10 || ^12 || >=14} + + prompts@2.4.2: + resolution: {integrity: sha512-NxNv/kLguCA7p3jE8oL2aEBsrJWgAakBpgmgK6lpPWV+WuOmY6r2/zbAVnP+T8bQlA0nzHXSJSJW0Hq7ylaD2Q==} + engines: {node: '>= 6'} + punycode@2.3.1: resolution: {integrity: sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==} engines: {node: '>=6'} @@ -716,6 +923,11 @@ packages: resolution: {integrity: sha512-l0OE8wL34P4nJH/H2ffoaniAokM2qSmrtXHmlpvYr5AVVX8msAyW0l8NVJFDxlSK4u3Uh/f41cQheDVdnYijwQ==} hasBin: true + rollup@3.29.5: + resolution: {integrity: sha512-GVsDdsbJzzy4S/v3dqWPJ7EfvZJfCHiDqe80IyrF59LYuP+e6U1LJoUqeuqRbwAWoMNoXivMNeNAOf5E22VA1w==} + engines: {node: '>=14.18.0', npm: '>=8.0.0'} + hasBin: true + rollup@4.50.1: resolution: {integrity: sha512-78E9voJHwnXQMiQdiqswVLZwJIzdBKJ1GdI5Zx6XwoFKUIk09/sSrr+05QFzvYb8q6Y9pPV45zzDuYa3907TZA==} engines: {node: '>=18.0.0', npm: '>=8.0.0'} @@ -733,15 +945,31 @@ packages: resolution: {integrity: sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==} engines: {node: '>=8'} + siginfo@2.0.0: + resolution: {integrity: sha512-ybx0WO1/8bSBLEWXZvEd7gMW3Sn3JFlW3TvX1nREbDLRNQNaeNN8WK0meBwPdAaOI7TtRRRJn/Es1zhrrCHu7g==} + signal-exit@4.1.0: resolution: {integrity: sha512-bzyZ1e88w9O1iNJbKnOlvYTrWPDl46O1bG0D3XInv+9tkPrxrN8jUUTiFlDkkmKWgn1M6CfIA13SuGqOa9Korw==} engines: {node: '>=14'} + sisteransi@1.0.5: + resolution: {integrity: sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg==} + + source-map-js@1.2.1: + resolution: {integrity: sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA==} + engines: {node: '>=0.10.0'} + source-map@0.8.0-beta.0: resolution: {integrity: sha512-2ymg6oRBpebeZi9UUNsgQ89bhx01TcTkmNTGnNO88imTmbSgy4nfujrgVEFKWpMTEGA11EDkTt7mqObTPdigIA==} engines: {node: '>= 8'} deprecated: The work that was done in this beta branch won't be included in future versions + stackback@0.0.2: + resolution: {integrity: sha512-1XMJE5fQo1jGH6Y/7ebnwPOBEkIEnT4QF32d5R1+VXdXveM0IBMJt8zfaxX1P3QhVwrYe+576+jkANtSS2mBbw==} + + std-env@3.9.0: + resolution: {integrity: sha512-UGvjygr6F6tpH7o2qyqR6QYpwraIjKSdtzyBdyytFOHmPZY917kwdwLG0RbOjWOnKmnm3PeHjaoLLMie7kPLQw==} + string-width@4.2.3: resolution: {integrity: sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==} engines: {node: '>=8'} @@ -758,6 +986,9 @@ packages: resolution: {integrity: sha512-gmBGslpoQJtgnMAvOVqGZpEz9dyoKTCzy2nfz/n8aIFhN/jCE/rCmcxabB6jOOHV+0WNnylOxaxBQPSvcWklhA==} engines: {node: '>=12'} + strip-literal@3.0.0: + resolution: {integrity: sha512-TcccoMhJOM3OebGhSBEmp3UZ2SfDMZUEBdRA/9ynfLi8yYajyWX3JiXArcJt4Umh4vISpspkQIY8ZZoCqjbviA==} + sucrase@3.35.0: resolution: {integrity: sha512-8EbVDiu9iN/nESwxeSxDKe0dunta1GOlHufmSSXxMD2z2/tMZpDMpvXQGsc+ajGo8y2uYUmixaSRUc/QPoQ0GA==} engines: {node: '>=16 || 14 >=14.17'} @@ -770,6 +1001,9 @@ packages: thenify@3.3.1: resolution: {integrity: sha512-RVZSIV5IG10Hk3enotrhvz0T9em6cyHBLkH/YAZuKqd8hRkKhSfCGIcP2KUY0EPxndzANBmNllzWPwak+bheSw==} + tinybench@2.9.0: + resolution: {integrity: sha512-0+DUvqWMValLmha6lr4kD8iAMK1HzV0/aKnCtWb9v9641TnP/MFb7Pc2bxoxQjTXAErryXVgUOfv2YqNllqGeg==} + tinyexec@0.3.2: resolution: {integrity: sha512-KQQR9yN7R5+OSwaK0XQoj22pwHoTlgYqmUscPYoknOoWCWfj/5/ABTMRi69FrKU5ffPVh5QcFikpWJI/P1ocHA==} @@ -777,6 +1011,18 @@ packages: resolution: {integrity: sha512-j2Zq4NyQYG5XMST4cbs02Ak8iJUdxRM0XI5QyxXuZOzKOINmWurp3smXu3y5wDcJrptwpSjgXHzIQxR0omXljQ==} engines: {node: '>=12.0.0'} + tinypool@1.1.1: + resolution: {integrity: sha512-Zba82s87IFq9A9XmjiX5uZA/ARWDrB03OHlq+Vw1fSdt0I+4/Kutwy8BP4Y/y/aORMo61FQ0vIb5j44vSo5Pkg==} + engines: {node: ^18.0.0 || >=20.0.0} + + tinyrainbow@2.0.0: + resolution: {integrity: sha512-op4nsTR47R6p0vMUUoYl/a+ljLFVtlfaXkLQmqfLR1qHma1h/ysYk4hEXZ880bf2CYgTskvTa/e196Vd5dDQXw==} + engines: {node: '>=14.0.0'} + + tinyspy@4.0.3: + resolution: {integrity: sha512-t2T/WLB2WRgZ9EpE4jgPJ9w+i66UZfDc8wHh0xrwiRNN+UwH98GIJkTeZqX9rg0i0ptwzqW+uYeIF0T4F8LR7A==} + engines: {node: '>=14.0.0'} + tr46@1.0.1: resolution: {integrity: sha512-dTpowEjclQ7Kgx5SdBkqRzVhERQXov8/l9Ft9dVM9fmg0W0KQSVaXX9T4i6twCPNtYiZM53lpSSUAwJbFPOHxA==} @@ -806,6 +1052,40 @@ packages: typescript: optional: true + turbo-darwin-64@2.5.6: + resolution: {integrity: sha512-3C1xEdo4aFwMJAPvtlPqz1Sw/+cddWIOmsalHFMrsqqydcptwBfu26WW2cDm3u93bUzMbBJ8k3zNKFqxJ9ei2A==} + cpu: [x64] + os: [darwin] + + turbo-darwin-arm64@2.5.6: + resolution: {integrity: sha512-LyiG+rD7JhMfYwLqB6k3LZQtYn8CQQUePbpA8mF/hMLPAekXdJo1g0bUPw8RZLwQXUIU/3BU7tXENvhSGz5DPA==} + cpu: [arm64] + os: [darwin] + + turbo-linux-64@2.5.6: + resolution: {integrity: sha512-GOcUTT0xiT/pSnHL4YD6Yr3HreUhU8pUcGqcI2ksIF9b2/r/kRHwGFcsHgpG3+vtZF/kwsP0MV8FTlTObxsYIA==} + cpu: [x64] + os: [linux] + + turbo-linux-arm64@2.5.6: + resolution: {integrity: sha512-10Tm15bruJEA3m0V7iZcnQBpObGBcOgUcO+sY7/2vk1bweW34LMhkWi8svjV9iDF68+KJDThnYDlYE/bc7/zzQ==} + cpu: [arm64] + os: [linux] + + turbo-windows-64@2.5.6: + resolution: {integrity: sha512-FyRsVpgaj76It0ludwZsNN40ytHN+17E4PFJyeliBEbxrGTc5BexlXVpufB7XlAaoaZVxbS6KT8RofLfDRyEPg==} + cpu: [x64] + os: [win32] + + turbo-windows-arm64@2.5.6: + resolution: {integrity: sha512-j/tWu8cMeQ7HPpKri6jvKtyXg9K1gRyhdK4tKrrchH8GNHscPX/F71zax58yYtLRWTiK04zNzPcUJuoS0+v/+Q==} + cpu: [arm64] + os: [win32] + + turbo@2.5.6: + resolution: {integrity: sha512-gxToHmi9oTBNB05UjUsrWf0OyN5ZXtD0apOarC1KIx232Vp3WimRNy3810QzeNSgyD5rsaIDXlxlbnOzlouo+w==} + hasBin: true + typescript@5.9.2: resolution: {integrity: sha512-CWBzXQrc/qOkhidw1OzBTQuYRbfyxDXJMVJ1XNwUHGROVmuaeiEm3OslpZ1RV96d7SKKjZKrSJu3+t/xlw3R9A==} engines: {node: '>=14.17'} @@ -823,6 +1103,79 @@ packages: peerDependencies: browserslist: '>= 4.21.0' + vite-node@3.2.4: + resolution: {integrity: sha512-EbKSKh+bh1E1IFxeO0pg1n4dvoOTt0UDiXMd/qn++r98+jPO1xtJilvXldeuQ8giIB5IkpjCgMleHMNEsGH6pg==} + engines: {node: ^18.0.0 || ^20.0.0 || >=22.0.0} + hasBin: true + + vite@7.1.5: + resolution: {integrity: sha512-4cKBO9wR75r0BeIWWWId9XK9Lj6La5X846Zw9dFfzMRw38IlTk2iCcUt6hsyiDRcPidc55ZParFYDXi0nXOeLQ==} + engines: {node: ^20.19.0 || >=22.12.0} + hasBin: true + peerDependencies: + '@types/node': ^20.19.0 || >=22.12.0 + jiti: '>=1.21.0' + less: ^4.0.0 + lightningcss: ^1.21.0 + sass: ^1.70.0 + sass-embedded: ^1.70.0 + stylus: '>=0.54.8' + sugarss: ^5.0.0 + terser: ^5.16.0 + tsx: ^4.8.1 + yaml: ^2.4.2 + peerDependenciesMeta: + '@types/node': + optional: true + jiti: + optional: true + less: + optional: true + lightningcss: + optional: true + sass: + optional: true + sass-embedded: + optional: true + stylus: + optional: true + sugarss: + optional: true + terser: + optional: true + tsx: + optional: true + yaml: + optional: true + + vitest@3.2.4: + resolution: {integrity: sha512-LUCP5ev3GURDysTWiP47wRRUpLKMOfPh+yKTx3kVIEiu5KOMeqzpnYNsKyOoVrULivR8tLcks4+lga33Whn90A==} + engines: {node: ^18.0.0 || ^20.0.0 || >=22.0.0} + hasBin: true + peerDependencies: + '@edge-runtime/vm': '*' + '@types/debug': ^4.1.12 + '@types/node': ^18.0.0 || ^20.0.0 || >=22.0.0 + '@vitest/browser': 3.2.4 + '@vitest/ui': 3.2.4 + happy-dom: '*' + jsdom: '*' + peerDependenciesMeta: + '@edge-runtime/vm': + optional: true + '@types/debug': + optional: true + '@types/node': + optional: true + '@vitest/browser': + optional: true + '@vitest/ui': + optional: true + happy-dom: + optional: true + jsdom: + optional: true + webidl-conversions@4.0.2: resolution: {integrity: sha512-YQ+BmxuTgd6UXZW3+ICGfyqRyHXVlD5GtQr5+qjiNW7bF0cqrzX500HVXPBOvgXb5YnzDd+h0zqyv61KUD7+Sg==} @@ -834,6 +1187,11 @@ packages: engines: {node: '>= 8'} hasBin: true + why-is-node-running@2.3.0: + resolution: {integrity: sha512-hUrmaWBdVDcxvYqnyh09zunKzROWjbZTiNy8dBEjkS7ehEDQibXJ7XvlmtbwuTclUiIyN+CyXQD4Vmko8fNm8w==} + engines: {node: '>=8'} + hasBin: true + wrap-ansi@7.0.0: resolution: {integrity: sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==} engines: {node: '>=10'} @@ -842,33 +1200,89 @@ packages: resolution: {integrity: sha512-si7QWI6zUMq56bESFvagtmzMdGOtoxfR+Sez11Mobfc7tm+VkUckk9bW2UeffTGVUbOksxmSw0AA2gs8g71NCQ==} engines: {node: '>=12'} + zx@8.8.1: + resolution: {integrity: sha512-qvsKBnvWHstHKCluKPlEgI/D3+mdiQyMoSSeFR8IX/aXzWIas5A297KxKgPJhuPXdrR6ma0Jzx43+GQ/8sqbrw==} + engines: {node: '>= 12.17.0'} + hasBin: true + snapshots: + '@codama/cli@1.3.4': + dependencies: + '@codama/nodes': 1.3.6 + '@codama/visitors': 1.3.6 + '@codama/visitors-core': 1.3.6 + commander: 14.0.1 + picocolors: 1.1.1 + prompts: 2.4.2 + '@codama/errors@1.3.4': dependencies: '@codama/node-types': 1.3.4 chalk: 5.6.2 commander: 14.0.0 + '@codama/errors@1.3.6': + dependencies: + '@codama/node-types': 1.3.6 + commander: 14.0.1 + picocolors: 1.1.1 + '@codama/node-types@1.3.4': {} + '@codama/node-types@1.3.6': {} + + '@codama/nodes-from-anchor@1.2.8(fastestsmallesttextencoderdecoder@1.0.22)(typescript@5.9.2)': + dependencies: + '@codama/errors': 1.3.6 + '@codama/nodes': 1.3.6 + '@codama/visitors': 1.3.6 + '@noble/hashes': 1.8.0 + '@solana/codecs': 3.0.3(fastestsmallesttextencoderdecoder@1.0.22)(typescript@5.9.2) + transitivePeerDependencies: + - fastestsmallesttextencoderdecoder + - typescript + '@codama/nodes@1.3.4': dependencies: '@codama/errors': 1.3.4 '@codama/node-types': 1.3.4 + '@codama/nodes@1.3.6': + dependencies: + '@codama/errors': 1.3.6 + '@codama/node-types': 1.3.6 + '@codama/renderers-core@1.1.0': dependencies: '@codama/errors': 1.3.4 '@codama/nodes': 1.3.4 '@codama/visitors-core': 1.3.4 + '@codama/validators@1.3.6': + dependencies: + '@codama/errors': 1.3.6 + '@codama/nodes': 1.3.6 + '@codama/visitors-core': 1.3.6 + '@codama/visitors-core@1.3.4': dependencies: '@codama/errors': 1.3.4 '@codama/nodes': 1.3.4 json-stable-stringify: 1.3.0 + '@codama/visitors-core@1.3.6': + dependencies: + '@codama/errors': 1.3.6 + '@codama/nodes': 1.3.6 + json-stable-stringify: 1.3.0 + + '@codama/visitors@1.3.6': + dependencies: + '@codama/errors': 1.3.6 + '@codama/nodes': 1.3.6 + '@codama/visitors-core': 1.3.6 + '@esbuild/aix-ppc64@0.25.9': optional: true @@ -970,9 +1384,15 @@ snapshots: '@jridgewell/resolve-uri': 3.1.2 '@jridgewell/sourcemap-codec': 1.5.5 + '@noble/hashes@1.8.0': {} + '@pkgjs/parseargs@0.11.0': optional: true + '@rollup/plugin-virtual@3.0.2(rollup@3.29.5)': + optionalDependencies: + rollup: 3.29.5 + '@rollup/rollup-android-arm-eabi@4.50.1': optional: true @@ -1036,6 +1456,66 @@ snapshots: '@rollup/rollup-win32-x64-msvc@4.50.1': optional: true + '@solana/codecs-core@3.0.3(typescript@5.9.2)': + dependencies: + '@solana/errors': 3.0.3(typescript@5.9.2) + typescript: 5.9.2 + + '@solana/codecs-data-structures@3.0.3(typescript@5.9.2)': + dependencies: + '@solana/codecs-core': 3.0.3(typescript@5.9.2) + '@solana/codecs-numbers': 3.0.3(typescript@5.9.2) + '@solana/errors': 3.0.3(typescript@5.9.2) + typescript: 5.9.2 + + '@solana/codecs-numbers@3.0.3(typescript@5.9.2)': + dependencies: + '@solana/codecs-core': 3.0.3(typescript@5.9.2) + '@solana/errors': 3.0.3(typescript@5.9.2) + typescript: 5.9.2 + + '@solana/codecs-strings@3.0.3(fastestsmallesttextencoderdecoder@1.0.22)(typescript@5.9.2)': + dependencies: + '@solana/codecs-core': 3.0.3(typescript@5.9.2) + '@solana/codecs-numbers': 3.0.3(typescript@5.9.2) + '@solana/errors': 3.0.3(typescript@5.9.2) + fastestsmallesttextencoderdecoder: 1.0.22 + typescript: 5.9.2 + + '@solana/codecs@3.0.3(fastestsmallesttextencoderdecoder@1.0.22)(typescript@5.9.2)': + dependencies: + '@solana/codecs-core': 3.0.3(typescript@5.9.2) + '@solana/codecs-data-structures': 3.0.3(typescript@5.9.2) + '@solana/codecs-numbers': 3.0.3(typescript@5.9.2) + '@solana/codecs-strings': 3.0.3(fastestsmallesttextencoderdecoder@1.0.22)(typescript@5.9.2) + '@solana/options': 3.0.3(fastestsmallesttextencoderdecoder@1.0.22)(typescript@5.9.2) + typescript: 5.9.2 + transitivePeerDependencies: + - fastestsmallesttextencoderdecoder + + '@solana/errors@3.0.3(typescript@5.9.2)': + dependencies: + chalk: 5.6.2 + commander: 14.0.0 + typescript: 5.9.2 + + '@solana/options@3.0.3(fastestsmallesttextencoderdecoder@1.0.22)(typescript@5.9.2)': + dependencies: + '@solana/codecs-core': 3.0.3(typescript@5.9.2) + '@solana/codecs-data-structures': 3.0.3(typescript@5.9.2) + '@solana/codecs-numbers': 3.0.3(typescript@5.9.2) + '@solana/codecs-strings': 3.0.3(fastestsmallesttextencoderdecoder@1.0.22)(typescript@5.9.2) + '@solana/errors': 3.0.3(typescript@5.9.2) + typescript: 5.9.2 + transitivePeerDependencies: + - fastestsmallesttextencoderdecoder + + '@types/chai@5.2.2': + dependencies: + '@types/deep-eql': 4.0.2 + + '@types/deep-eql@4.0.2': {} + '@types/estree@1.0.8': {} '@types/node@24.3.1': @@ -1044,10 +1524,58 @@ snapshots: '@types/nunjucks@3.2.6': {} + '@vitest/expect@3.2.4': + dependencies: + '@types/chai': 5.2.2 + '@vitest/spy': 3.2.4 + '@vitest/utils': 3.2.4 + chai: 5.3.3 + tinyrainbow: 2.0.0 + + '@vitest/mocker@3.2.4(vite@7.1.5(@types/node@24.3.1))': + dependencies: + '@vitest/spy': 3.2.4 + estree-walker: 3.0.3 + magic-string: 0.30.19 + optionalDependencies: + vite: 7.1.5(@types/node@24.3.1) + + '@vitest/pretty-format@3.2.4': + dependencies: + tinyrainbow: 2.0.0 + + '@vitest/runner@3.2.4': + dependencies: + '@vitest/utils': 3.2.4 + pathe: 2.0.3 + strip-literal: 3.0.0 + + '@vitest/snapshot@3.2.4': + dependencies: + '@vitest/pretty-format': 3.2.4 + magic-string: 0.30.19 + pathe: 2.0.3 + + '@vitest/spy@3.2.4': + dependencies: + tinyspy: 4.0.3 + + '@vitest/utils@3.2.4': + dependencies: + '@vitest/pretty-format': 3.2.4 + loupe: 3.2.1 + tinyrainbow: 2.0.0 + a-sync-waterfall@1.0.1: {} acorn@8.15.0: {} + agadoo@3.0.0: + dependencies: + '@rollup/plugin-virtual': 3.0.2(rollup@3.29.5) + acorn: 8.15.0 + rollup: 3.29.5 + ansi-regex@5.0.1: {} ansi-regex@6.2.2: {} @@ -1062,6 +1590,8 @@ snapshots: asap@2.0.6: {} + assertion-error@2.0.1: {} + balanced-match@1.0.2: {} brace-expansion@2.0.2: @@ -1106,12 +1636,30 @@ snapshots: caniuse-lite@1.0.30001741: {} + chai@5.3.3: + dependencies: + assertion-error: 2.0.1 + check-error: 2.1.1 + deep-eql: 5.0.2 + loupe: 3.2.1 + pathval: 2.0.1 + chalk@5.6.2: {} + check-error@2.1.1: {} + chokidar@4.0.3: dependencies: readdirp: 4.1.2 + codama@1.3.6: + dependencies: + '@codama/cli': 1.3.4 + '@codama/errors': 1.3.6 + '@codama/nodes': 1.3.6 + '@codama/validators': 1.3.6 + '@codama/visitors': 1.3.6 + color-convert@2.0.1: dependencies: color-name: 1.1.4 @@ -1120,6 +1668,8 @@ snapshots: commander@14.0.0: {} + commander@14.0.1: {} + commander@4.1.1: {} commander@5.1.0: {} @@ -1138,6 +1688,8 @@ snapshots: dependencies: ms: 2.1.3 + deep-eql@5.0.2: {} + define-data-property@1.1.4: dependencies: es-define-property: 1.0.1 @@ -1162,6 +1714,8 @@ snapshots: es-errors@1.3.0: {} + es-module-lexer@1.7.0: {} + es-object-atoms@1.1.1: dependencies: es-errors: 1.3.0 @@ -1197,6 +1751,14 @@ snapshots: escalade@3.2.0: {} + estree-walker@3.0.3: + dependencies: + '@types/estree': 1.0.8 + + expect-type@1.2.2: {} + + fastestsmallesttextencoderdecoder@1.0.22: {} + fdir@6.5.0(picomatch@4.0.3): optionalDependencies: picomatch: 4.0.3 @@ -1270,6 +1832,8 @@ snapshots: joycon@3.1.1: {} + js-tokens@9.0.1: {} + json-stable-stringify@1.3.0: dependencies: call-bind: 1.0.8 @@ -1280,6 +1844,8 @@ snapshots: jsonify@0.0.1: {} + kleur@3.0.3: {} + lilconfig@3.1.3: {} lines-and-columns@1.2.4: {} @@ -1288,6 +1854,8 @@ snapshots: lodash.sortby@4.7.0: {} + loupe@3.2.1: {} + lru-cache@10.4.3: {} magic-string@0.30.19: @@ -1319,6 +1887,8 @@ snapshots: object-assign: 4.1.1 thenify-all: 1.6.0 + nanoid@3.3.11: {} + node-releases@2.0.20: {} nunjucks@3.2.4: @@ -1342,6 +1912,8 @@ snapshots: pathe@2.0.3: {} + pathval@2.0.1: {} + picocolors@1.1.1: {} picomatch@4.0.3: {} @@ -1354,9 +1926,22 @@ snapshots: mlly: 1.8.0 pathe: 2.0.3 - postcss-load-config@6.0.1: + postcss-load-config@6.0.1(postcss@8.5.6): dependencies: lilconfig: 3.1.3 + optionalDependencies: + postcss: 8.5.6 + + postcss@8.5.6: + dependencies: + nanoid: 3.3.11 + picocolors: 1.1.1 + source-map-js: 1.2.1 + + prompts@2.4.2: + dependencies: + kleur: 3.0.3 + sisteransi: 1.0.5 punycode@2.3.1: {} @@ -1368,6 +1953,10 @@ snapshots: dependencies: glob: 10.4.5 + rollup@3.29.5: + optionalDependencies: + fsevents: 2.3.3 + rollup@4.50.1: dependencies: '@types/estree': 1.0.8 @@ -1410,12 +1999,22 @@ snapshots: shebang-regex@3.0.0: {} + siginfo@2.0.0: {} + signal-exit@4.1.0: {} + sisteransi@1.0.5: {} + + source-map-js@1.2.1: {} + source-map@0.8.0-beta.0: dependencies: whatwg-url: 7.1.0 + stackback@0.0.2: {} + + std-env@3.9.0: {} + string-width@4.2.3: dependencies: emoji-regex: 8.0.0 @@ -1436,6 +2035,10 @@ snapshots: dependencies: ansi-regex: 6.2.2 + strip-literal@3.0.0: + dependencies: + js-tokens: 9.0.1 + sucrase@3.35.0: dependencies: '@jridgewell/gen-mapping': 0.3.13 @@ -1454,6 +2057,8 @@ snapshots: dependencies: any-promise: 1.3.0 + tinybench@2.9.0: {} + tinyexec@0.3.2: {} tinyglobby@0.2.15: @@ -1461,6 +2066,12 @@ snapshots: fdir: 6.5.0(picomatch@4.0.3) picomatch: 4.0.3 + tinypool@1.1.1: {} + + tinyrainbow@2.0.0: {} + + tinyspy@4.0.3: {} + tr46@1.0.1: dependencies: punycode: 2.3.1 @@ -1469,7 +2080,7 @@ snapshots: ts-interface-checker@0.1.13: {} - tsup@8.5.0(typescript@5.9.2): + tsup@8.5.0(postcss@8.5.6)(typescript@5.9.2): dependencies: bundle-require: 5.1.0(esbuild@0.25.9) cac: 6.7.14 @@ -1480,7 +2091,7 @@ snapshots: fix-dts-default-cjs-exports: 1.0.1 joycon: 3.1.1 picocolors: 1.1.1 - postcss-load-config: 6.0.1 + postcss-load-config: 6.0.1(postcss@8.5.6) resolve-from: 5.0.0 rollup: 4.50.1 source-map: 0.8.0-beta.0 @@ -1489,6 +2100,7 @@ snapshots: tinyglobby: 0.2.15 tree-kill: 1.2.2 optionalDependencies: + postcss: 8.5.6 typescript: 5.9.2 transitivePeerDependencies: - jiti @@ -1496,6 +2108,33 @@ snapshots: - tsx - yaml + turbo-darwin-64@2.5.6: + optional: true + + turbo-darwin-arm64@2.5.6: + optional: true + + turbo-linux-64@2.5.6: + optional: true + + turbo-linux-arm64@2.5.6: + optional: true + + turbo-windows-64@2.5.6: + optional: true + + turbo-windows-arm64@2.5.6: + optional: true + + turbo@2.5.6: + optionalDependencies: + turbo-darwin-64: 2.5.6 + turbo-darwin-arm64: 2.5.6 + turbo-linux-64: 2.5.6 + turbo-linux-arm64: 2.5.6 + turbo-windows-64: 2.5.6 + turbo-windows-arm64: 2.5.6 + typescript@5.9.2: {} ufo@1.6.1: {} @@ -1508,6 +2147,80 @@ snapshots: escalade: 3.2.0 picocolors: 1.1.1 + vite-node@3.2.4(@types/node@24.3.1): + dependencies: + cac: 6.7.14 + debug: 4.4.1 + es-module-lexer: 1.7.0 + pathe: 2.0.3 + vite: 7.1.5(@types/node@24.3.1) + transitivePeerDependencies: + - '@types/node' + - jiti + - less + - lightningcss + - sass + - sass-embedded + - stylus + - sugarss + - supports-color + - terser + - tsx + - yaml + + vite@7.1.5(@types/node@24.3.1): + dependencies: + esbuild: 0.25.9 + fdir: 6.5.0(picomatch@4.0.3) + picomatch: 4.0.3 + postcss: 8.5.6 + rollup: 4.50.1 + tinyglobby: 0.2.15 + optionalDependencies: + '@types/node': 24.3.1 + fsevents: 2.3.3 + + vitest@3.2.4(@types/node@24.3.1): + dependencies: + '@types/chai': 5.2.2 + '@vitest/expect': 3.2.4 + '@vitest/mocker': 3.2.4(vite@7.1.5(@types/node@24.3.1)) + '@vitest/pretty-format': 3.2.4 + '@vitest/runner': 3.2.4 + '@vitest/snapshot': 3.2.4 + '@vitest/spy': 3.2.4 + '@vitest/utils': 3.2.4 + chai: 5.3.3 + debug: 4.4.1 + expect-type: 1.2.2 + magic-string: 0.30.19 + pathe: 2.0.3 + picomatch: 4.0.3 + std-env: 3.9.0 + tinybench: 2.9.0 + tinyexec: 0.3.2 + tinyglobby: 0.2.15 + tinypool: 1.1.1 + tinyrainbow: 2.0.0 + vite: 7.1.5(@types/node@24.3.1) + vite-node: 3.2.4(@types/node@24.3.1) + why-is-node-running: 2.3.0 + optionalDependencies: + '@types/node': 24.3.1 + transitivePeerDependencies: + - jiti + - less + - lightningcss + - msw + - sass + - sass-embedded + - stylus + - sugarss + - supports-color + - terser + - tsx + - yaml + webidl-conversions@4.0.2: {} whatwg-url@7.1.0: @@ -1520,6 +2233,11 @@ snapshots: dependencies: isexe: 2.0.0 + why-is-node-running@2.3.0: + dependencies: + siginfo: 2.0.0 + stackback: 0.0.2 + wrap-ansi@7.0.0: dependencies: ansi-styles: 4.3.0 @@ -1531,3 +2249,5 @@ snapshots: ansi-styles: 6.2.3 string-width: 5.1.2 strip-ansi: 7.1.2 + + zx@8.8.1: {} diff --git a/public/templates/macros.njk b/public/templates/macros.njk index a6cbe77..1b3f2fc 100644 --- a/public/templates/macros.njk +++ b/public/templates/macros.njk @@ -38,18 +38,15 @@ {# Recursive Borsh Reader, responsible for handling collections and any nested levels #} {% macro borshReader(field) %} - {{ recursiveReader(field.nesting, field.baseType, field.isStruct, field.size, field.format) }} + {{ recursiveReader(field.nesting, field.baseType, field.isStruct) }} {% endmacro %} -{% macro recursiveReader(depth, baseType, isStruct, size, format) %} - {% if depth > 5 %} - // ERROR: Nesting depth exceeds supported limit (5) - throw Exception('Nesting depth exceeds supported limit(5)'); - {% elif depth == 0 %} +{% macro recursiveReader(depth, baseType, isStruct) %} + {% if depth == 0 %} {% if isStruct %} {{ baseType }}Borsh.fromBorsh(reader) {% else %} - {{ baseTypeReader(baseType, false, size, format) }} + {{ baseTypeReader(baseType) }} {% endif %} {% else %} reader.readArray(() { @@ -57,9 +54,10 @@ // item is a struct, call fromBorsh per item return {{ baseType }}Borsh.fromBorsh(reader); {% else %} - return {{ recursiveReader(depth - 1, baseType, false, size, format) }}; + return {{ recursiveReader(depth - 1, baseType, false) }}; {% endif %} }) +<<<<<<< Updated upstream {% endif %} {% endmacro %} @@ -120,37 +118,40 @@ {% endif %} {% else %} throw Exception('Unsupported number format: {{ format }}'); +======= +>>>>>>> Stashed changes {% endif %} {% endmacro %} {# Reader for the base types (no nesting) #} -{% macro baseTypeReader(baseType, isStruct, size, format) %} - {% if baseType == 'int' or baseType == 'BigInt' %} - {{ intFormatUtil(format, false) }} +{% macro baseTypeReader(baseType, isStruct) %} + {% if baseType == 'int' %} + reader.readInt() + {% elif baseType == 'BigInt' %} + reader.readBigInt() {% elif baseType == 'String' %} reader.readString() {% elif baseType == 'Uint8List' %} - reader.readU8Array({{ size if size is defined else '' }}) + reader.readFixedU8Array({{ field.size or 8}}) {% elif baseType == 'Int8List' %} - reader.readI8Array({{ size if size is defined else '' }}) + reader.readFixedI8Array({{ field.size or 8}}) {% elif baseType == 'Uint16List' %} - reader.readU16Array({{ size if size is defined else '' }}) + reader.readFixedU16Array({{ field.size or 16 }}) {% elif baseType == 'Int16List' %} - reader.readI16Array({{ size if size is defined else '' }}) + reader.readFixedI16Array({{ field.size or 16}}) {% elif baseType == 'Uint32List' %} - reader.readU32Array({{ size if size is defined else '' }}) + reader.readFixedU32Array({{ field.size or 32}}) {% elif baseType == 'Int32List' %} - reader.readI32Array({{ size if size is defined else '' }}) + reader.readFixedI32Array({{ field.size or 32}}) {% elif baseType == 'Uint64List' %} - reader.readU64Array({{ size if size is defined else '' }}) + reader.readFixedU64Array({{ field.size or 64}}) {% elif baseType == 'Int64List' %} - reader.readI64Array({{ size if size is defined else '' }}) + reader.readFixedI64Array({{ field.size or 64 }}) {% elif baseType == 'bool' %} reader.readBool() {% elif baseType == 'Ed25519HDPublicKey' %} - Ed25519HDPublicKey(reader.readPubkey()) + Ed25519HDPublicKey(Uint8List.fromList(reader.readFixedU8Array(32))) {% else %} - /// TODO: I need to provide panic or error guard to indicate that user is doing something that is not supported reader.readUnknownType('{{ baseType }}') {% endif %} {% endmacro %} @@ -158,19 +159,16 @@ {# Recursive Borsh Writer, responsible to handle nested type of collections #} {% macro borshWriter(field, overrideFieldName="") %} {% set name = overrideFieldName if overrideFieldName else field.name %} - {{ recursiveWriter(name, field.nesting, field.baseType, field.isStruct, field.size, field.format) }} + {{ recursiveWriter(name, field.nesting, field.baseType, field.isStruct) }} {% endmacro %} -{% macro recursiveWriter(varName, depth, baseType, isStruct, size, format) %} - {% if depth > 5 %} - // ERROR: Nesting depth exceeds supported limit (5) - throw Exception('Nesting depth exceeds supported limit(5)'); - {% elif depth == 0 %} +{% macro recursiveWriter(varName, depth, baseType, isStruct) %} + {% if depth == 0 %} {% if isStruct %} {{ varName }}.toBorsh(writer); {% else %} {# TODO: I have problem here because of these recursions i put ';' twice because twice is iterated here first trough writeArray and on the recursion i go inside here and i put ';' again #} - {{ baseTypeWriter(baseType, varName, size, format) }}; + {{ baseTypeWriter(baseType, varName) }}; {% endif %} {% else %} writer.writeArray<{{ baseType }}>({{ varName }}, ({{ baseType }} item) { @@ -178,38 +176,44 @@ // Each item is a struct item.toBorsh(writer); {% else %} +<<<<<<< Updated upstream {{ recursiveWriter("item", depth - 1, baseType, false, size, format) }}; +======= + {{ recursiveWriter("item", depth - 1, baseType, false) }}; +>>>>>>> Stashed changes {% endif %} }); {% endif %} {% endmacro %} {# Base Writer, no nested types inside #} -{% macro baseTypeWriter(baseType, varName, size, format) %} - {% if baseType == 'int' or baseType == 'BigInt' %} - {{ intFormatUtil(format, true, varName) }} +{% macro baseTypeWriter(baseType, varName, isStruct) %} + {% if baseType == 'int' %} + writer.writeInt({{ varName }}) + {% elif baseType == 'BigInt' %} + writer.writeBigInt({{ varName }}) {% elif baseType == 'String' %} writer.writeString({{ varName }}) {% elif baseType == 'Uint8List' %} - writer.writeU8Array({{ varName }}, {{ size if size is defined else 'null' }}) + writer.writeFixedU8Array({{ varName }}) {% elif baseType == 'Int8List' %} - writer.writeI8Array({{ varName }}, {{ size if size is defined else 'null' }}) + writer.writeFixedI8Array({{ varName }}) {% elif baseType == 'Uint16List' %} - writer.writeU16Array({{ varName }}, {{ size if size is defined else 'null' }}) + writer.writeFixedU16Array({{ varName }}) {% elif baseType == 'Int16List' %} - writer.writeI16Array({{ varName }}, {{ size if size is defined else 'null' }}) + writer.writeFixedI16Array({{ varName }}) {% elif baseType == 'Uint32List' %} - writer.writeU32Array({{ varName }}, {{ size if size is defined else 'null' }}) + writer.writeFixedU32Array({{ varName }}) {% elif baseType == 'Int32List' %} - writer.writeI32Array({{ varName }}, {{ size if size is defined else 'null' }}) + writer.writeFixedI32Array({{ varName }}) {% elif baseType == 'Uint64List' %} - writer.writeU64Array({{ varName }}, {{ size if size is defined else 'null' }}) + writer.writeFixedU64Array({{ varName }}) {% elif baseType == 'Int64List' %} - writer.writeI64Array({{ varName }}, {{ size if size is defined else 'null' }}) + writer.writeFixedI64Array({{ varName }}) {% elif baseType == 'bool' %} writer.writeBool({{ varName }}) {% elif baseType == 'Ed25519HDPublicKey' %} - writer.writePubkey(Uint8List.fromList({{ varName }}.bytes)) + writer.writeFixedU8Array(Uint8List.fromList({{ varName }}.bytes)) {% else %} writer.writeUnknownType('{{ baseType }}') {% endif %} diff --git a/public/templates/pages/accountsPage.njk b/public/templates/pages/accountsPage.njk index c71063a..e3fa5ef 100644 --- a/public/templates/pages/accountsPage.njk +++ b/public/templates/pages/accountsPage.njk @@ -67,7 +67,7 @@ void toBorsh(BinaryWriter writer) { {% if account.discriminator %} // Validate the discriminator - final discriminator = reader.readDiscriminator(); + final discriminator = reader.readFixedU8Array(8); if (!const ListEquality().equals(discriminator, {{ account.name | snakeCase | upper }}_DISCRIMINATOR)) { throw FormatException('Invalid account discriminator'); } @@ -82,7 +82,7 @@ void toBorsh(BinaryWriter writer) { {% if account.discriminator %} // Write discriminator - writer.writeDiscriminator(Uint8List.fromList({{ account.name | snakeCase | upper }}_DISCRIMINATOR)); + writer.writeFixedU8Array(Uint8List.fromList({{ account.name | snakeCase | upper }}_DISCRIMINATOR)); {% endif %} // Write account data @@ -129,11 +129,7 @@ void toBorsh(BinaryWriter writer) { RpcClient client, Ed25519HDPublicKey address, ) async { - {# Always use encoding: Encoding.base64 when fetching account data. #} - {# Base58 is meant for public keys, not raw binary, and will produce the wrong bytes. #} - {# Base64 ensures we get the exact raw on-chain bytes (including the correct discriminator). #} - - final accountInfo = await client.getAccountInfo(address.toBase58(), encoding: Encoding.base64); + final accountInfo = await client.getAccountInfo(address.toBase58()); final data = accountInfo.value?.data; if (data == null) { diff --git a/public/templates/pages/instructionsPage.njk b/public/templates/pages/instructionsPage.njk index 8631854..da2f6dd 100644 --- a/public/templates/pages/instructionsPage.njk +++ b/public/templates/pages/instructionsPage.njk @@ -5,112 +5,120 @@ {{ imports }} {% if instruction.discriminator and instruction.discriminator.length > 0 -%} - const List {{ instruction.name | snakeCase | upper }}_DISCRIMINATOR = [{{ instruction.discriminator | join(', ') }}]; - {%- endif %} +const List + {{ instruction.name | snakeCase | upper }}_DISCRIMINATOR = [{{ instruction.discriminator | join(', ') }}]; +{%- endif %} - /// Generated instruction class for {{ instruction.name | pascalCase }}. - /// - {% if instruction.docs.length > 0 -%} - {%- for doc in instruction.docs -%} - /// {{ doc }} - {%- endfor -%} - {%- endif %} - - class {{ instruction.name | pascalCase }}Instruction { +/// Generated instruction class for {{ instruction.name | pascalCase }}. +/// +{% if instruction.docs.length > 0 -%} + {%- for doc in instruction.docs -%} +/// {{ doc }} + {%- endfor -%} + {%- endif %} +class {{ instruction.name | pascalCase }}Instruction { - // Accounts - {% for account in instruction.accounts %} - // {{ account.docs[0] if account.docs and account.docs[0] else ('The ' ~ (account.name | snakeCase ) ~ ' account.') }} + // Accounts + {% for account in instruction.accounts %} + // {{ account.docs[0] if account.docs and account.docs[0] else ('The ' ~ (account.name | camelCase) ~ ' account.') }} {% if account.isOptional %} - final Ed25519HDPublicKey? {{ account.name | snakeCase }}; - {% else %} - final Ed25519HDPublicKey {{ account.name | snakeCase }}; - {% endif %} + final Ed25519HDPublicKey? {{ account.name | camelCase }}; + {% else %} + final Ed25519HDPublicKey {{ account.name | camelCase }}; + {% endif %} {% if account.isSigner === 'either' %} - /// Whether the {{ account.name | snakeCase }} account is a signer. - final bool {{ account.name | snakeCase }}IsSigner; - {% endif %} + /// Whether the {{ account.name | camelCase }} account is a signer. + final bool {{ account.name | camelCase }}IsSigner; + {% endif %} {% endfor %} - // Args - {% if args and args.length > 0 %} + // Args + {% if args and args.length > 0 %} {% for arg in args %} - final {{ arg.dartType }} {{ arg.name | snakeCase }}; - {% endfor %} + final {{ arg.dartType }} + {{ arg.name }}; + {% endfor %} {% endif %} {{ instruction.name | pascalCase }}Instruction({ - {% for account in instruction.accounts -%} - {%- if account.isOptional -%} - this.{{ account.name | snakeCase }}, - {%- else -%} - required this.{{ account.name | snakeCase }}, - {%- endif -%} - {%- if account.isSigner === 'either' -%} - this.{{ account.name | snakeCase }}IsSigner = false, - {%- endif -%} - {%- endfor -%} - {%- if args and args.length > 0 -%} - {%- for arg in args -%} - required this.{{ arg.name | snakeCase }}, - {%- endfor -%} + {% for account in instruction.accounts -%} + {%- if account.isOptional -%} + this.{{ account.name | camelCase }}, + {%- else -%} + required this.{{ account.name | camelCase }}, + {%- endif -%} + {%- if account.isSigner === 'either' -%} + this.{{ account.name | camelCase }}IsSigner = false, {%- endif -%} - }); + {%- endfor -%} + {%- if args and args.length > 0 -%} + {%- for arg in args -%} + required this.{{ arg.name }}, + {%- endfor -%} + {%- endif -%} + }); - /// Builds the `Instruction` (data = discriminator + args). - Instruction toInstruction({ List remainingAccounts = const [] }) { - final keys = [ - {%- for account in instruction.accounts %} + /// Builds the `Instruction` (data = discriminator + args). + Instruction toInstruction({ List remainingAccounts = const [] }) { + final keys = [ + {%- for account in instruction.accounts %} {%- if account.isOptional %} - if ({{ account.name | snakeCase }} != null) - AccountMeta( - pubKey: {{ account.name | snakeCase }}!, - isSigner: {%- if account.isSigner === 'either' -%}{{ account.name | snakeCase }}IsSigner{%- else -%}{{ 'true' if account.isSigner else 'false' }}{%- endif -%}, - isWriteable: {{ 'true' if account.isWritable else 'false' }}, - ), - {%- else %} - AccountMeta( - pubKey: {{ account.name | snakeCase }}, - isSigner: {%- if account.isSigner === 'either' -%}{{ account.name | snakeCase }}IsSigner{%- else -%}{{ 'true' if account.isSigner else 'false' }}{%- endif -%}, - isWriteable: {{ 'true' if account.isWritable else 'false' }}, - ), - {%- endif %} + if ({{ account.name | camelCase }} != null) + AccountMeta( + pubKey: {{ account.name | camelCase }}!, + isSigner: {%- if account.isSigner === 'either' -%}{{ account.name | camelCase }}IsSigner{%- else -%}{{ 'true' if account.isSigner else 'false' }} + {%- endif -%}, + isWriteable: {{ 'true' if account.isWritable else 'false' }}, + ), + {%- else %} + AccountMeta( + pubKey: {{ account.name | camelCase }}, + isSigner: {%- if account.isSigner === 'either' -%}{{ account.name | camelCase }}IsSigner{%- else -%}{{ 'true' if account.isSigner else 'false' }} + {%- endif -%}, + isWriteable: {{ 'true' if account.isWritable else 'false' }}, + ), + {%- endif %} {%- endfor %} - ]; + ]; - if (remainingAccounts.isNotEmpty) { - keys.addAll(remainingAccounts); - } + if (remainingAccounts.isNotEmpty) { + keys.addAll(remainingAccounts); + } - // Serialize: discriminator (8 bytes) + args - final writer = BinaryWriter(); - {%- if instruction.discriminator and instruction.discriminator.length > 0 %} - writer.writeDiscriminator(Uint8List.fromList({{ instruction.name | snakeCase | upper }}_DISCRIMINATOR)); - {%- endif %} - {%- if fields and fields.length > 0 %} - {% for field in fields %} - {% if field.optional %} - writer.writeU8({{ field.name }} != null ? 1 : 0); - if ({{ field.name }} != null) { - {{ macros.borshWriter(field) | replace(field.name, field.name ~ '!') }} - } - {% else %} - {{ macros.borshWriter(field) }} - {% endif %} - {% endfor %} + // Serialize: discriminator (8 bytes) + args + final writer = BinaryWriter(); +{%- if instruction.discriminator and instruction.discriminator.length > 0 %} +writer.writeFixedU8Array(Uint8List.fromList({{ instruction.name | snakeCase | upper }}_DISCRIMINATOR)); +{%- endif %} + {%- if args and args.length > 0 %} + {%- for arg in args %} + {%- if arg.resolvedType.kind === 'numberTypeNode' %} + writer.writeU{{ arg.resolvedType.format | replace('u', '') }}({{ arg.name }}); + {%- elif arg.resolvedType.kind === 'stringTypeNode' %} + writer.writeString({{ arg.name }}); + {%- elif arg.resolvedType.kind === 'booleanTypeNode' %} + writer.writeBool({{ arg.name }}); + {%- elif arg.resolvedType.kind === 'publicKeyTypeNode' %} + writer.writeFixedU8Array(Uint8List.fromList({{ arg.name }}.bytes)); + {%- elif arg.resolvedType.kind === 'bytesTypeNode' %} + writer.writeBytes({{ arg.name }}); + {%- else %} + {{ arg.name }}.toBorsh(writer); {%- endif %} + {%- endfor %} + {%- endif %} - return Instruction( - programId: {{ program.name | pascalCase }}Program.programId, - accounts: keys, - data: ByteArray(writer.toBytes()), - ); - } + return Instruction( + programId: {{ program.name | pascalCase }}Program.programId, + accounts: keys, + data: ByteArray(writer.toBytes()), + ); } +} - {# Nested structs (if any) #} - {% for nestedStruct in typeManifest.nestedStructs %} - {{ nestedStruct }} - {% endfor %} -{% endblock %} \ No newline at end of file +{# Nested structs (if any) #} + {% for nestedStruct in typeManifest.nestedStructs %} + {{ nestedStruct }} + {% endfor %} + {% endblock %} \ No newline at end of file diff --git a/public/templates/pages/sharedPage.njk b/public/templates/pages/sharedPage.njk index 0e2c941..cc75cfd 100644 --- a/public/templates/pages/sharedPage.njk +++ b/public/templates/pages/sharedPage.njk @@ -1,10 +1,7 @@ -/// This code was AUTOGENERATED using the codama library. -/// Please DO NOT EDIT THIS FILE, instead use visitors -/// to add features, then rerun codama to update it. -/// -/// https://github.com/codama-idl/codama -/// +{% extends "layout.njk" %} +{% import "macros.njk" as macros %} +{% block main %} // Shared utilities and types for the SDK. import 'dart:convert'; @@ -26,15 +23,13 @@ class AccountNotFoundError extends Error { /// Binary reader for decoding Borsh-encoded data. class BinaryReader { - final ByteData - _data; // holds the raw binary data buffer, that i read from. Represents entire sequence of bytes. - - // Offset tracks the current byte position in the buffer; advance it after each read to ensure correct sequential decoding. + final ByteData _data; int _offset = 0; /// Creates a new BinaryReader. BinaryReader(this._data); +<<<<<<< Updated upstream Uint8List readDiscriminator() { final length = 8; // Discriminator is always the first 8 bytes final bytes = @@ -51,6 +46,8 @@ class BinaryReader { return bytes; } +======= +>>>>>>> Stashed changes /// Reads a boolean value. bool readBool() { final value = _data.getUint8(_offset) != 0; @@ -138,132 +135,69 @@ class BinaryReader { /// Reads a string. String readString() { final length = readU32(); - final bytes = - Uint8List.view(_data.buffer, _data.offsetInBytes + _offset, length); + final bytes = Uint8List.view(_data.buffer, _data.offsetInBytes + _offset, length); _offset += length; return utf8.decode(bytes); } - /// Reads a u8 array from Borsh data. If `length` is null, reads the length from a 4-byte prefix. - Uint8List readU8Array([int? length]) { - if (length == null) { - // Read the 4-byte little-endian length prefix (Borsh Vec) - length = _data.getUint32(_offset, Endian.little); - _offset += 4; - } - - return readAlignedArray( - 1, - length, - Uint8List.view, - 1, - (offset) => _data.getUint8(offset), - ); + /// Reads a fixed-size u8 array of bytes. + Uint8List readFixedU8Array(int length) { + final bytes = + Uint8List.view(_data.buffer, _data.offsetInBytes + _offset, length); + _offset += length; + return bytes; } /// Reads a fixed-size i8 array of bytes. - Int8List readI8Array([int? length]) { - if (length == null) { - // Read the 4-byte little-endian length prefix (Borsh Vec) - length = _data.getUint32(_offset, Endian.little); - _offset += 4; - } - - return readAlignedArray( - 1, - length, - Int8List.view, - 1, - (offset) => _data.getInt8(offset), - ); + Int8List readFixedI8Array(int length) { + final bytes = + Int8List.view(_data.buffer, _data.offsetInBytes + _offset, length); + _offset += length; + return bytes; } /// Reads a fixed-size u16 array of bytes. - Uint16List readU16Array([int? length]) { - if (length == null) { - // Read the 4-byte little-endian length prefix (Borsh Vec) - length = _data.getUint32(_offset, Endian.little); - _offset += 4; - } - - return readAlignedArray( - 2, - length, - Uint16List.view, - 2, - (offset) => _data.getUint16(offset, Endian.little), - ); + Uint16List readFixedU16Array(int length) { + final bytes = + Uint16List.view(_data.buffer, _data.offsetInBytes + _offset, length); + _offset += length * 4; + return bytes; } /// Reads a fixed-size i16 array of bytes. - Int16List readI16Array([int? length]) { - if (length == null) { - // Read the 4-byte little-endian length prefix (Borsh Vec) - length = _data.getUint32(_offset, Endian.little); - _offset += 4; - } - - return readAlignedArray( - 2, - length, - Int16List.view, - 2, - (offset) => _data.getInt16(offset, Endian.little), - ); + Int16List readFixedI16Array(int length) { + final bytes = + Int16List.view(_data.buffer, _data.offsetInBytes + _offset, length); + _offset += length * 4; + return bytes; } /// Reads a fixed-size u32 array of bytes. - Uint32List readU32Array([int? length]) { - if (length == null) { - // Read the 4-byte little-endian length prefix (Borsh Vec) - length = _data.getUint32(_offset, Endian.little); - _offset += 4; - } - - return readAlignedArray( - 4, - length, - Uint32List.view, - 4, - (offset) => _data.getUint32(offset, Endian.little), - ); + Uint32List readFixedU32Array(int length) { + final bytes = + Uint32List.view(_data.buffer, _data.offsetInBytes + _offset, length); + _offset += length * 4; + return bytes; } /// Reads a fixed-size i32 array of bytes. - Int32List readI32Array([int? length]) { - if (length == null) { - // Read the 4-byte little-endian length prefix (Borsh Vec) - length = _data.getUint32(_offset, Endian.little); - _offset += 4; - } - - return readAlignedArray( - 4, - length, - Int32List.view, - 4, - (offset) => _data.getInt32(offset, Endian.little), - ); + Int32List readFixedI32Array(int length) { + final bytes = + Int32List.view(_data.buffer, _data.offsetInBytes + _offset, length); + _offset += length * 4; + return bytes; } /// Reads a fixed-size u64 array of bytes. - Uint64List readU64Array([int? length]) { - if (length == null) { - // Read the 4-byte little-endian length prefix (Borsh Vec) - length = _data.getUint32(_offset, Endian.little); - _offset += 4; - } - - return readAlignedArray( - 8, - length, - Uint64List.view, - 8, - (offset) => _data.getUint64(offset, Endian.little), - ); + Uint64List readFixedU64Array(int length) { + final bytes = + Uint64List.view(_data.buffer, _data.offsetInBytes + _offset, length); + _offset += length * 4; + return bytes; } /// Reads a fixed-size i64 array of bytes. +<<<<<<< Updated upstream Int64List readI64Array([int? length]) { if (length == null) { // Read the 4-byte little-endian length prefix (Borsh Vec) @@ -278,6 +212,13 @@ class BinaryReader { 8, (offset) => _data.getInt64(offset, Endian.little), ); +======= + Int64List readFixedI64Array(int length) { + final bytes = + Int64List.view(_data.buffer, _data.offsetInBytes + _offset, length); + _offset += length * 4; + return bytes; +>>>>>>> Stashed changes } /// Reads a variable-length array of generic items. @@ -293,46 +234,7 @@ class BinaryReader { /// Reads a variable-length array of bytes. Uint8List readBytes() { final length = readU32(); - return readU8Array(length); - } - - // ========= Utils for alignment-safe array reading ======== - - // This function handles the problem of buffer's offset that is not properly aligned for typed array views. - // It happens because i have fixed-size and prefixed-size arrays. - T readAlignedArray( - int alignment, - int length, - T Function(ByteBuffer buffer, int offset, int length) viewConstructor, - int bytesPerElement, - int Function(int offset) manualGetter, - ) { - // Check the offset alignment for `Uint*List.view` it should be multiple of element size - if ((_data.offsetInBytes + _offset) % alignment == 0) { - final arr = - viewConstructor(_data.buffer, _data.offsetInBytes + _offset, length); - _offset += length * bytesPerElement; - return arr; - } else { - // Manual read if not aligned - // For example, for Uint16List: - final arr = List.generate(length, (i) { - final value = manualGetter(_offset); - _offset += bytesPerElement; - return value; - }); - // Convert to typed list - if (T == Uint8List) return Uint8List.fromList(arr) as T; - if (T == Uint16List) return Uint16List.fromList(arr) as T; - if (T == Uint32List) return Uint32List.fromList(arr) as T; - if (T == Uint64List) return Uint64List.fromList(arr) as T; - if (T == Int8List) return Int8List.fromList(arr) as T; - if (T == Int16List) return Int16List.fromList(arr) as T; - if (T == Int32List) return Int32List.fromList(arr) as T; - if (T == Int64List) return Int64List.fromList(arr) as T; - // ...add more types as needed - return arr as T; - } + return readFixedU8Array(length); } } @@ -340,13 +242,6 @@ class BinaryReader { class BinaryWriter { final List _bytes = []; - void writeDiscriminator(Uint8List discriminator) { - if (discriminator.length != 8) { - throw ArgumentError('Discriminator must be exactly 8 bytes'); - } - _bytes.addAll(discriminator); - } - /// Writes a boolean value. void writeBool(bool value) { _bytes.add(value ? 1 : 0); @@ -394,7 +289,7 @@ class BinaryWriter { void writeU64(BigInt value) { final low = value & BigInt.from(0xFFFFFFFF); final high = (value >> 32) & BigInt.from(0xFFFFFFFF); - + _bytes.addAll([ low.toInt() & 0xFF, (low.toInt() >> 8) & 0xFF, @@ -434,132 +329,44 @@ class BinaryWriter { _bytes.addAll(bytes); } - /// Writes a fixed-size and prefixed-size u8 array of bytes. - void writeU8Array(Uint8List value, int? length) { - if (length == null) { - // Variable-length: write length prefix - writeU32(value.length); - for (final v in value) { - writeU8(v); - } - } else { - // Fixed-size: write exactly [length] elements, no prefix - for (int i = 0; i < length; i++) { - writeU8(value[i]); - } - } + /// Writes a fixed-size u8 array of bytes. + void writeFixedU8Array(Uint8List value) { + _bytes.addAll(value); } - /// Writes a fixed-size and prefixed-size u8 array of bytes. - void writeI8Array(Int8List value, int? length) { - if (length == null) { - // Variable-length: write length prefix - writeU32(value.length); - for (final v in value) { - writeI8(v); - } - } else { - // Fixed-size: write exactly [length] elements, no prefix - for (int i = 0; i < length; i++) { - writeI8(value[i]); - } - } + /// Writes a fixed-size i8 array of bytes. + void writeFixedI8Array(Int8List value) { + _bytes.addAll(value); } - /// Writes a fixed-size and prefixed-size u16 array of bytes. - void writeU16Array(Uint16List value, int? length) { - if (length == null) { - // Variable-length: write length prefix - writeU32(value.length); - for (final v in value) { - writeU16(v); - } - } else { - // Fixed-size: write exactly [length] elements, no prefix - for (int i = 0; i < length; i++) { - writeU16(value[i]); - } - } + /// Writes a fixed-size u16 array of bytes. + void writeFixedU16Array(Uint16List value) { + _bytes.addAll(value); } - /// Writes a fixed-size and prefixed-size i16 array of bytes. - void writeI16Array(Int16List value, int? length) { - if (length == null) { - // Variable-length: write length prefix - writeU32(value.length); - for (final v in value) { - writeI16(v); - } - } else { - // Fixed-size: write exactly [length] elements, no prefix - for (int i = 0; i < length; i++) { - writeI16(value[i]); - } - } + /// Writes a fixed-size i16 array of bytes. + void writeFixedI16Array(Int16List value) { + _bytes.addAll(value); } - - /// Writes a fixed-size and prefixed-size i16 array of bytes. - void writeU32Array(Uint32List value, int? length) { - if (length == null) { - // Variable-length: write length prefix - writeU32(value.length); - for (final v in value) { - writeU32(v); - } - } else { - // Fixed-size: write exactly [length] elements, no prefix - for (int i = 0; i < length; i++) { - writeU32(value[i]); - } - } + + /// Writes a fixed-size u32 array of bytes. + void writeFixedU32Array(Uint32List value) { + _bytes.addAll(value); } /// Writes a fixed-size i32 array of bytes. - void writeI32Array(Int32List value, int? length) { - if (length == null) { - // Variable-length: write length prefix - writeU32(value.length); - for (final v in value) { - writeI32(v); - } - } else { - // Fixed-size: write exactly [length] elements, no prefix - for (int i = 0; i < length; i++) { - writeI32(value[i]); - } - } + void writeFixedI32Array(Int32List value) { + _bytes.addAll(value); } /// Writes a fixed-size u64 array of bytes. - void writeU64Array(Uint64List value, int? length) { - if (length == null) { - // Variable-length: write length prefix - writeU32(value.length); - for (final v in value) { - writeU64(BigInt.from(v)); - } - } else { - // Fixed-size: write exactly [length] elements, no prefix - for (int i = 0; i < length; i++) { - writeU64(BigInt.from(value[i])); - } - } + void writeFixedU64Array(Uint64List value) { + _bytes.addAll(value); } /// Writes a fixed-size i64 array of bytes. - void writeI64Array(Int64List value, int? length) { - if (length == null) { - // Variable-length: write length prefix - writeU32(value.length); - for (final v in value) { - writeI64(BigInt.from(v)); - } - } else { - // Fixed-size: write exactly [length] elements, no prefix - for (int i = 0; i < length; i++) { - writeI64(BigInt.from(value[i])); - } - } + void writeFixedI64Array(Int64List value) { + _bytes.addAll(value); } /// Writes a variable-length array of bytes. @@ -576,11 +383,7 @@ class BinaryWriter { } } - /// Writes a single public key (32 raw bytes, no prefix). - void writePubkey(Uint8List pubkeyBytes) { - _bytes.addAll(pubkeyBytes); - } - /// Returns the byte array. Uint8List toBytes() => Uint8List.fromList(_bytes); } +{% endblock %} \ No newline at end of file diff --git a/scripts/test-treeshakability.mjs b/scripts/test-treeshakability.mjs new file mode 100644 index 0000000..b086d68 --- /dev/null +++ b/scripts/test-treeshakability.mjs @@ -0,0 +1,14 @@ +#!/usr/bin/env zx +import { $ } from 'zx'; + +// Ensure the code is tree-shakable. +$.stdio = 'inherit'; +if ((await $`[[ -f dist/index.browser.mjs ]]`.exitCode) == 0) { + await $`agadoo dist/index.browser.mjs`; +} +if ((await $`[[ -f dist/index.node.mjs ]]`.exitCode) == 0) { + await $`agadoo dist/index.node.mjs`; +} +if ((await $`[[ -f dist/index.react-native.mjs ]]`.exitCode) == 0) { + await $`agadoo dist/index.react-native.mjs`; +} diff --git a/scripts/test-types.mjs b/scripts/test-types.mjs new file mode 100644 index 0000000..4509543 --- /dev/null +++ b/scripts/test-types.mjs @@ -0,0 +1,6 @@ +#!/usr/bin/env zx +import { $ } from 'zx'; + +// Ensure the code type checks. +$.stdio = 'inherit'; +await $`tsc --noEmit`; diff --git a/scripts/test-unit.mjs b/scripts/test-unit.mjs new file mode 100644 index 0000000..d539273 --- /dev/null +++ b/scripts/test-unit.mjs @@ -0,0 +1,14 @@ +#!/usr/bin/env zx +import { $, argv } from 'zx'; + +$.stdio = 'inherit'; +const platform = argv._[0]; +const watch = argv.watch; + +const testArgs = ['--config', `./vitest.config.${platform}.mts`]; + +if (watch) { + await $`vitest ${testArgs}`; +} else { + await $`vitest run ${testArgs}`; +} diff --git a/test/_setup.ts b/test/_setup.ts new file mode 100644 index 0000000..beb4f1d --- /dev/null +++ b/test/_setup.ts @@ -0,0 +1,23 @@ +import { expect } from 'vitest'; + +export function codeContains(actual: string, expected: (RegExp | string)[] | RegExp | string) { + const expectedArray = Array.isArray(expected) ? expected : [expected]; + expectedArray.forEach(e => { + if (typeof e === 'string') { + expect(actual).toContain(e); + } else { + expect(actual).toMatch(e); + } + }); +} + +export function codeDoesNotContains(actual: string, expected: (RegExp | string)[] | RegExp | string) { + const expectedArray = Array.isArray(expected) ? expected : [expected]; + expectedArray.forEach(e => { + if (typeof e === 'string') { + expect(actual).not.toContain(e); + } else { + expect(actual).not.toMatch(e); + } + }); +} diff --git a/test/accountsPage.test.ts b/test/accountsPage.test.ts new file mode 100644 index 0000000..b4f37ee --- /dev/null +++ b/test/accountsPage.test.ts @@ -0,0 +1,94 @@ +// import { +// accountNode, +// camelCase, +// pdaLinkNode, +// programNode, +// } from '@codama/nodes'; +// import { getFromRenderMap } from '@codama/renderers-core'; +// import { visit } from '@codama/visitors-core'; +// import { test } from 'vitest'; + +// import { getRenderMapVisitor } from '../src'; +// import { codeContains } from './_setup'; + +// test('it renders Dart account serialization and ownership', () => { +// // Given the following account. +// const node = programNode({ +// accounts: [ +// accountNode({ +// discriminators: [ +// { +// kind: 'fieldDiscriminatorNode', +// name: camelCase('discriminator'), +// offset: 0, +// }, +// ], +// name: 'testAccount', +// pda: pdaLinkNode('testPda'), +// }), +// ], +// name: 'myProgram', +// publicKey: '1111', +// }); + +// // When we render it. +// const renderMap = visit(node, getRenderMapVisitor()); + +// // Then we expect Dart serialization and ownership helpers. +// codeContains(getFromRenderMap(renderMap, 'accounts/test_account.dart'), [ +// /class TestAccount\s*{/, +// /static TestAccount fromBorsh\(BinaryReader reader\)/, +// /void toBorsh\(BinaryWriter writer\)/, +// /static TestAccount fromBytes\(Uint8List data\)/, +// /Uint8List toBytes\(\)/, +// /static Future fetch\(/, +// /static Future fetchNullable\(/, +// /throw AccountNotFoundError\(address\);/, +// ]); +// }); + +// test('it renders fetch functions', () => { +// // Given the following account. +// const node = programNode({ +// accounts: [ +// accountNode({ +// discriminators: [ +// { +// kind: 'fieldDiscriminatorNode', +// // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call +// name: camelCase('discriminator'), +// offset: 0, +// }, +// ], +// name: 'testAccount', +// pda: pdaLinkNode('testPda'), +// }), +// ], +// name: 'myProgram', +// publicKey: '1111', +// }); + +// // When we render it. +// const renderMap = visit(node, getRenderMapVisitor()); + +// // Then we expect the following fetch functions to be rendered. +// codeContains(getFromRenderMap(renderMap, 'accounts/test_account.dart'), [ +// /class TestAccount\s*{/, // class declaration +// /const List\s+TEST_ACCOUNT_DISCRIMINATOR\s*=\s*\[.*\];/, // discriminator +// /static TestAccount fromBorsh\(BinaryReader reader\)/, // deserialization +// /void toBorsh\(BinaryWriter writer\)/, // serialization +// /static TestAccount fromBytes\(Uint8List data\)/, // fromBytes method +// /Uint8List toBytes\(\)/, // toBytes method +// /static Future fetch\(/, // fetch method +// /static Future fetchNullable\(/, // fetchNullable method +// /final discriminator = reader\.readDiscriminator\(\);/, // discriminator validation +// /if \(!const ListEquality\(\)\.equals\(discriminator, TEST_ACCOUNT_DISCRIMINATOR\)\)/, // discriminator check +// /throw AccountNotFoundError\(address\);/, // error handling +// /import 'dart:typed_data';/, +// /import 'package:collection\/collection\.dart';/, +// /import 'package:solana\/dto\.dart';/, +// /import 'package:solana\/solana\.dart';/, +// /import '\.\.\/shared\.dart';/, +// ]); +// }); + diff --git a/test/definedTypesPage.test.ts b/test/definedTypesPage.test.ts new file mode 100644 index 0000000..cf07a13 --- /dev/null +++ b/test/definedTypesPage.test.ts @@ -0,0 +1,39 @@ +// import { definedTypeNode, numberTypeNode, programNode, sizePrefixTypeNode, stringTypeNode, structFieldTypeNode, structTypeNode } from "@codama/nodes"; +// import { getFromRenderMap } from "@codama/renderers-core"; +// import { visit } from "@codama/visitors-core"; +// import { test } from 'vitest'; + +// import { getRenderMapVisitor } from "../src"; +// import { codeContains } from "./_setup"; + + +// test('it renders a prefix string on a defined type', () => { +// const node = programNode({ +// definedTypes: [ +// definedTypeNode({ +// name: 'blob', +// type: structTypeNode([ +// structFieldTypeNode({ +// name: 'contentType', +// type: sizePrefixTypeNode(stringTypeNode('utf8'), numberTypeNode('u8')), +// }), +// ]), +// }), +// ], +// name: 'splToken', +// publicKey: 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', +// }); + +// const renderMap = visit(node, getRenderMapVisitor()); + +// codeContains(getFromRenderMap(renderMap, 'types/blob.dart'), [ +// /class Blob\s*{/, // class declaration +// /final String content_type;/, // field declaration (matches your output) +// /import '\.\.\/shared\.dart';/, // shared import +// /Generated type definition for Blob/, // doc comment +// /void toBorsh\(BinaryWriter writer\)/, // serialization method +// /writer\.writeString\(content_type\)/, // serialization line +// /static Blob fromBorsh\(BinaryReader reader\)/, // deserialization method +// /content_type:\s*reader\.readString\(\)/, // deserialization line +// ]); +// }); \ No newline at end of file diff --git a/test/exports/commonjs.cjs b/test/exports/commonjs.cjs new file mode 100644 index 0000000..a091a74 --- /dev/null +++ b/test/exports/commonjs.cjs @@ -0,0 +1,7 @@ +const { definedTypeNode, numberTypeNode } = require('@codama/nodes'); +const { visit } = require('@codama/visitors-core'); + +const { getRenderMapVisitor } = require('../../dist/index.node.cjs'); + +const node = definedTypeNode({ name: 'answerToLife', type: numberTypeNode('u8') }); +visit(node, getRenderMapVisitor()); diff --git a/test/exports/module.mjs b/test/exports/module.mjs new file mode 100644 index 0000000..87c6ff6 --- /dev/null +++ b/test/exports/module.mjs @@ -0,0 +1,10 @@ +// This ensures that we do not rely on `__dirname` in ES modules even when it is polyfilled. +globalThis.__dirname = 'DO_NOT_USE'; + +import { definedTypeNode, numberTypeNode } from '@codama/nodes'; +import { visit } from '@codama/visitors-core'; + +import { getRenderMapVisitor } from '../../dist/index.node.mjs'; + +const node = definedTypeNode({ name: 'answerToLife', type: numberTypeNode('u8') }); +visit(node, getRenderMapVisitor()); diff --git a/test/types/array.test.ts b/test/types/array.test.ts new file mode 100644 index 0000000..1899f75 --- /dev/null +++ b/test/types/array.test.ts @@ -0,0 +1,518 @@ +// import { +// arrayTypeNode, +// definedTypeNode, +// numberTypeNode, +// prefixedCountNode, +// publicKeyTypeNode, +// structFieldTypeNode, +// structTypeNode, +// } from '@codama/nodes'; +// import { getFromRenderMap } from '@codama/renderers-core'; +// import { visit } from '@codama/visitors-core'; +// import { test } from 'vitest'; + +// import { getRenderMapVisitor } from '../../src'; +// import { codeContains, codeDoesNotContains } from '../_setup'; + +// test('it exports short vecs', () => { +// // Given an array using a shortU16 prefix. +// const node = definedTypeNode({ +// name: 'myShortVec', +// type: arrayTypeNode(publicKeyTypeNode(), prefixedCountNode(numberTypeNode('shortU16'))), +// }); + +// // When we render the array. +// const renderMap = visit(node, getRenderMapVisitor()); +// // Then we expect a Dart class or type for the short vec. +// codeContains(getFromRenderMap(renderMap, 'types/my_short_vec.dart'), [ +// /typedef MyShortVec/, // Dart typedef for the array +// /List;/, // correct Dart type for the array +// /import 'package:solana\/solana.dart';/, // Dart import for public key +// /import 'dart:typed_data';/, +// /import '\.\.\/shared\.dart';/, +// ]); +// codeDoesNotContains(getFromRenderMap(renderMap, 'types/my_short_vec.dart'), [ +// /BorshSerialize/, // Rust-specific, should not appear +// /BorshDeserialize/, // Rust-specific, should not appear +// /^use /m, // Rust import, should not appear +// ]); +// }); + +// test('it exports short vecs as struct fields', () => { +// // Given an array using a shortU16 prefix. +// const node = definedTypeNode({ +// name: 'myShortVec', +// type: structTypeNode([ +// structFieldTypeNode({ +// name: 'value', +// type: arrayTypeNode(publicKeyTypeNode(), prefixedCountNode(numberTypeNode('shortU16'))), +// }), +// ]), +// }); + +// // When we render the array. +// const renderMap = visit(node, getRenderMapVisitor()); + +// // Then we expect a short vec to be exported as a struct field. +// codeContains(getFromRenderMap(renderMap, 'types/my_short_vec.dart'), [ +// /class MyShortVec /, // class declaration +// /final List value;/, // field declaration +// /MyShortVec\(\s*{\s*required this\.value,\s*}\s*\);/, // constructor +// /extension MyShortVecBorsh on MyShortVec/, // extension for serialization +// /void toBorsh\(BinaryWriter writer\)/, // serialization method +// /static MyShortVec fromBorsh\(BinaryReader reader\)/, // deserialization method +// /import 'package:solana\/solana.dart';/, // solana import +// /import 'dart:typed_data';/, // typed_data import +// /import '\.\.\/shared\.dart';/, // shared import +// ]); +// }); + +// test('it exports u8 numbers', () => { +// const node = definedTypeNode({ +// name: 'myU8', +// type: numberTypeNode('u8'), +// }); +// const renderMap = visit(node, getRenderMapVisitor()); +// codeContains(getFromRenderMap(renderMap, 'types/my_u8.dart'), [ +// /typedef MyU8 = int.*u8/, +// /import 'dart:typed_data';/, +// /import '\.\.\/shared\.dart';/, +// /Generated type definition for MyU8/, +// ]); +// codeDoesNotContains(getFromRenderMap(renderMap, 'types/my_u8.dart'), [ +// /BorshSerialize/, +// /BorshDeserialize/, +// /^use /m, +// ]); +// }); + +// test('it exports u8 numbers as struct fields', () => { +// const node = definedTypeNode({ +// name: 'myU8', +// type: structTypeNode([ +// structFieldTypeNode({ +// name: 'value', +// type: numberTypeNode('u8'), +// }), +// ]), +// }); +// const renderMap = visit(node, getRenderMapVisitor()); +// codeContains(getFromRenderMap(renderMap, 'types/my_u8.dart'), [ +// /class MyU8 /, +// /final int.*u8.*value;/, +// /required this\.value,/, +// /extension MyU8Borsh on MyU8/, +// /void toBorsh\(BinaryWriter writer\)/, +// /writer\.writeU8\(value\)/, // serialization line +// /static MyU8 fromBorsh\(BinaryReader reader\)/, +// /reader\.readU8\(\)/, // deserialization line +// /import 'dart:typed_data';/, +// /import '\.\.\/shared\.dart';/, +// /Generated type definition for MyU8/, // doc comment +// ]); +// }); + +// test('it exports i8 numbers', () => { +// const node = definedTypeNode({ +// name: 'myI8', +// type: numberTypeNode('i8'), +// }); +// const renderMap = visit(node, getRenderMapVisitor()); +// codeContains(getFromRenderMap(renderMap, 'types/my_i8.dart'), [ +// /typedef MyI8 = int.*i8/, +// /import 'dart:typed_data';/, +// /import '\.\.\/shared\.dart';/, +// /Generated type definition for MyI8/, +// ]); +// codeDoesNotContains(getFromRenderMap(renderMap, 'types/my_i8.dart'), [ +// /BorshSerialize/, +// /BorshDeserialize/, +// /^use /m, +// ]); +// }); + +// test('it exports i8 numbers as struct fields', () => { +// const node = definedTypeNode({ +// name: 'myI8', +// type: structTypeNode([ +// structFieldTypeNode({ +// name: 'value', +// type: numberTypeNode('i8'), +// }), +// ]), +// }); +// const renderMap = visit(node, getRenderMapVisitor()); +// codeContains(getFromRenderMap(renderMap, 'types/my_i8.dart'), [ +// /class MyI8 /, +// /final int.*i8.*value;/, +// /required this\.value,/, +// /extension MyI8Borsh on MyI8/, +// /void toBorsh\(BinaryWriter writer\)/, +// /writer\.writeI8\(value\)/, +// /static MyI8 fromBorsh\(BinaryReader reader\)/, +// /reader\.readI8\(\)/, +// /import 'dart:typed_data';/, +// /import '\.\.\/shared\.dart';/, +// /Generated type definition for MyI8/, +// ]); +// }); + +// test('it exports u16 numbers', () => { +// const node = definedTypeNode({ +// name: 'myU16', +// type: numberTypeNode('u16'), +// }); +// const renderMap = visit(node, getRenderMapVisitor()); +// codeContains(getFromRenderMap(renderMap, 'types/my_u16.dart'), [ +// /typedef MyU16 = int.*u16/, +// /import 'dart:typed_data';/, +// /import '\.\.\/shared\.dart';/, +// /Generated type definition for MyU16/, +// ]); +// codeDoesNotContains(getFromRenderMap(renderMap, 'types/my_u16.dart'), [ +// /BorshSerialize/, +// /BorshDeserialize/, +// /^use /m, +// ]); +// }); + +// test('it exports u16 numbers as struct fields', () => { +// const node = definedTypeNode({ +// name: 'myU16', +// type: structTypeNode([ +// structFieldTypeNode({ +// name: 'value', +// type: numberTypeNode('u16'), +// }), +// ]), +// }); +// const renderMap = visit(node, getRenderMapVisitor()); +// codeContains(getFromRenderMap(renderMap, 'types/my_u16.dart'), [ +// /class MyU16 /, +// /final int.*u16.*value;/, +// /required this\.value,/, +// /extension MyU16Borsh on MyU16/, +// /void toBorsh\(BinaryWriter writer\)/, +// /writer\.writeU16\(value\)/, +// /static MyU16 fromBorsh\(BinaryReader reader\)/, +// /reader\.readU16\(\)/, +// /import 'dart:typed_data';/, +// /import '\.\.\/shared\.dart';/, +// /Generated type definition for MyU16/, +// ]); +// }); + +// test('it exports i16 numbers', () => { +// const node = definedTypeNode({ +// name: 'myI16', +// type: numberTypeNode('i16'), +// }); +// const renderMap = visit(node, getRenderMapVisitor()); +// codeContains(getFromRenderMap(renderMap, 'types/my_i16.dart'), [ +// /typedef MyI16 = int.*i16/, +// /import 'dart:typed_data';/, +// /import '\.\.\/shared\.dart';/, +// /Generated type definition for MyI16/, +// ]); +// codeDoesNotContains(getFromRenderMap(renderMap, 'types/my_i16.dart'), [ +// /BorshSerialize/, +// /BorshDeserialize/, +// /^use /m, +// ]); +// }); + +// test('it exports i16 numbers as struct fields', () => { +// const node = definedTypeNode({ +// name: 'myI16', +// type: structTypeNode([ +// structFieldTypeNode({ +// name: 'value', +// type: numberTypeNode('i16'), +// }), +// ]), +// }); +// const renderMap = visit(node, getRenderMapVisitor()); +// codeContains(getFromRenderMap(renderMap, 'types/my_i16.dart'), [ +// /class MyI16 /, +// /final int.*i16.*value;/, +// /required this\.value,/, +// /extension MyI16Borsh on MyI16/, +// /void toBorsh\(BinaryWriter writer\)/, +// /writer\.writeI16\(value\)/, +// /static MyI16 fromBorsh\(BinaryReader reader\)/, +// /reader\.readI16\(\)/, +// /import 'dart:typed_data';/, +// /import '\.\.\/shared\.dart';/, +// /Generated type definition for MyI16/, +// ]); +// }); + +// test('it exports u32 numbers', () => { +// const node = definedTypeNode({ +// name: 'myU32', +// type: numberTypeNode('u32'), +// }); +// const renderMap = visit(node, getRenderMapVisitor()); +// codeContains(getFromRenderMap(renderMap, 'types/my_u32.dart'), [ +// /typedef MyU32 = int.*u32/, +// /import 'dart:typed_data';/, +// /import '\.\.\/shared\.dart';/, +// /Generated type definition for MyU32/, +// ]); +// codeDoesNotContains(getFromRenderMap(renderMap, 'types/my_u32.dart'), [ +// /BorshSerialize/, +// /BorshDeserialize/, +// /^use /m, +// ]); +// }); + +// test('it exports u32 numbers as struct fields', () => { +// const node = definedTypeNode({ +// name: 'myU32', +// type: structTypeNode([ +// structFieldTypeNode({ +// name: 'value', +// type: numberTypeNode('u32'), +// }), +// ]), +// }); +// const renderMap = visit(node, getRenderMapVisitor()); +// codeContains(getFromRenderMap(renderMap, 'types/my_u32.dart'), [ +// /class MyU32 /, +// /final int.*u32.*value;/, +// /required this\.value,/, +// /extension MyU32Borsh on MyU32/, +// /void toBorsh\(BinaryWriter writer\)/, +// /writer\.writeU32\(value\)/, +// /static MyU32 fromBorsh\(BinaryReader reader\)/, +// /reader\.readU32\(\)/, +// /import 'dart:typed_data';/, +// /import '\.\.\/shared\.dart';/, +// /Generated type definition for MyU32/, +// ]); +// }); + +// test('it exports i32 numbers', () => { +// const node = definedTypeNode({ +// name: 'myI32', +// type: numberTypeNode('i32'), +// }); +// const renderMap = visit(node, getRenderMapVisitor()); +// codeContains(getFromRenderMap(renderMap, 'types/my_i32.dart'), [ +// /typedef MyI32 = int.*i32/, +// /import 'dart:typed_data';/, +// /import '\.\.\/shared\.dart';/, +// /Generated type definition for MyI32/, +// ]); +// codeDoesNotContains(getFromRenderMap(renderMap, 'types/my_i32.dart'), [ +// /BorshSerialize/, +// /BorshDeserialize/, +// /^use /m, +// ]); +// }); + +// test('it exports i32 numbers as struct fields', () => { +// const node = definedTypeNode({ +// name: 'myI32', +// type: structTypeNode([ +// structFieldTypeNode({ +// name: 'value', +// type: numberTypeNode('i32'), +// }), +// ]), +// }); +// const renderMap = visit(node, getRenderMapVisitor()); +// codeContains(getFromRenderMap(renderMap, 'types/my_i32.dart'), [ +// /class MyI32 /, +// /final int.*i32.*value;/, +// /required this\.value,/, +// /extension MyI32Borsh on MyI32/, +// /void toBorsh\(BinaryWriter writer\)/, +// /writer\.writeI32\(value\)/, +// /static MyI32 fromBorsh\(BinaryReader reader\)/, +// /reader\.readI32\(\)/, +// /import 'dart:typed_data';/, +// /import '\.\.\/shared\.dart';/, +// /Generated type definition for MyI32/, +// ]); +// }); + +// test('it exports u64 numbers', () => { +// const node = definedTypeNode({ +// name: 'myU64', +// type: numberTypeNode('u64'), +// }); +// const renderMap = visit(node, getRenderMapVisitor()); +// codeContains(getFromRenderMap(renderMap, 'types/my_u64.dart'), [ +// /typedef MyU64 = BigInt.*u64/, +// /import 'dart:typed_data';/, +// /import '\.\.\/shared\.dart';/, +// /Generated type definition for MyU64/, +// ]); +// codeDoesNotContains(getFromRenderMap(renderMap, 'types/my_u64.dart'), [ +// /BorshSerialize/, +// /BorshDeserialize/, +// /^use /m, +// ]); +// }); + +// test('it exports u64 numbers as struct fields', () => { +// const node = definedTypeNode({ +// name: 'myU64', +// type: structTypeNode([ +// structFieldTypeNode({ +// name: 'value', +// type: numberTypeNode('u64'), +// }), +// ]), +// }); +// const renderMap = visit(node, getRenderMapVisitor()); +// codeContains(getFromRenderMap(renderMap, 'types/my_u64.dart'), [ +// /class MyU64 /, +// /final BigInt.*u64.*value;/, +// /required this\.value,/, +// /extension MyU64Borsh on MyU64/, +// /void toBorsh\(BinaryWriter writer\)/, +// /writer\.writeU64\(value\)/, +// /static MyU64 fromBorsh\(BinaryReader reader\)/, +// /reader\.readU64\(\)/, +// /import 'dart:typed_data';/, +// /import '\.\.\/shared\.dart';/, +// /Generated type definition for MyU64/, +// ]); +// }); + +// test('it exports i64 numbers', () => { +// const node = definedTypeNode({ +// name: 'myI64', +// type: numberTypeNode('i64'), +// }); +// const renderMap = visit(node, getRenderMapVisitor()); +// codeContains(getFromRenderMap(renderMap, 'types/my_i64.dart'), [ +// /typedef MyI64 = BigInt.*i64/, +// /import 'dart:typed_data';/, +// /import '\.\.\/shared\.dart';/, +// /Generated type definition for MyI64/, +// ]); +// codeDoesNotContains(getFromRenderMap(renderMap, 'types/my_i64.dart'), [ +// /BorshSerialize/, +// /BorshDeserialize/, +// /^use /m, +// ]); +// }); + +// test('it exports i64 numbers as struct fields', () => { +// const node = definedTypeNode({ +// name: 'myI64', +// type: structTypeNode([ +// structFieldTypeNode({ +// name: 'value', +// type: numberTypeNode('i64'), +// }), +// ]), +// }); +// const renderMap = visit(node, getRenderMapVisitor()); +// codeContains(getFromRenderMap(renderMap, 'types/my_i64.dart'), [ +// /class MyI64 /, +// /final BigInt.*i64.*value;/, +// /required this\.value,/, +// /extension MyI64Borsh on MyI64/, +// /void toBorsh\(BinaryWriter writer\)/, +// /writer\.writeI64\(value\)/, +// /static MyI64 fromBorsh\(BinaryReader reader\)/, +// /reader\.readI64\(\)/, +// /import 'dart:typed_data';/, +// /import '\.\.\/shared\.dart';/, +// /Generated type definition for MyI64/, +// ]); +// }); + +// test('it exports u128 numbers', () => { +// const node = definedTypeNode({ +// name: 'myU128', +// type: numberTypeNode('u128'), +// }); +// const renderMap = visit(node, getRenderMapVisitor()); +// codeContains(getFromRenderMap(renderMap, 'types/my_u128.dart'), [ +// /typedef MyU128 = BigInt.*u128/, +// /import 'dart:typed_data';/, +// /import '\.\.\/shared\.dart';/, +// /Generated type definition for MyU128/, +// ]); +// codeDoesNotContains(getFromRenderMap(renderMap, 'types/my_u128.dart'), [ +// /BorshSerialize/, +// /BorshDeserialize/, +// /^use /m, +// ]); +// }); + +// test('it exports u128 numbers as struct fields', () => { +// const node = definedTypeNode({ +// name: 'myU128', +// type: structTypeNode([ +// structFieldTypeNode({ +// name: 'value', +// type: numberTypeNode('u128'), +// }), +// ]), +// }); +// const renderMap = visit(node, getRenderMapVisitor()); +// codeContains(getFromRenderMap(renderMap, 'types/my_u128.dart'), [ +// /class MyU128 /, +// /final BigInt.*u128.*value;/, +// /required this\.value,/, +// /extension MyU128Borsh on MyU128/, +// /void toBorsh\(BinaryWriter writer\)/, +// /writer\.writeBigInt\(value\)/, +// /static MyU128 fromBorsh\(BinaryReader reader\)/, +// /reader\.readBigInt\(\)/, +// /import 'dart:typed_data';/, +// /import '\.\.\/shared\.dart';/, +// /Generated type definition for MyU128/, +// ]); +// }); + +// test('it exports u128 numbers', () => { +// const node = definedTypeNode({ +// name: 'myU128', +// type: numberTypeNode('u128'), +// }); +// const renderMap = visit(node, getRenderMapVisitor()); +// codeContains(getFromRenderMap(renderMap, 'types/my_u128.dart'), [ +// /typedef MyU128 = BigInt.*u128/, +// /import 'dart:typed_data';/, +// /import '\.\.\/shared\.dart';/, +// /Generated type definition for MyU128/, +// ]); +// codeDoesNotContains(getFromRenderMap(renderMap, 'types/my_u128.dart'), [ +// /BorshSerialize/, +// /BorshDeserialize/, +// /^use /m, +// ]); +// }); + +// test('it exports u128 numbers as struct fields', () => { +// const node = definedTypeNode({ +// name: 'myU128', +// type: structTypeNode([ +// structFieldTypeNode({ +// name: 'value', +// type: numberTypeNode('u128'), +// }), +// ]), +// }); +// const renderMap = visit(node, getRenderMapVisitor()); +// codeContains(getFromRenderMap(renderMap, 'types/my_u128.dart'), [ +// /class MyU128 /, +// /final BigInt.*u128.*value;/, +// /required this\.value,/, +// /extension MyU128Borsh on MyU128/, +// /void toBorsh\(BinaryWriter writer\)/, +// /writer\.writeBigInt\(value\)/, +// /static MyU128 fromBorsh\(BinaryReader reader\)/, +// /reader\.readBigInt\(\)/, +// /import 'dart:typed_data';/, +// /import '\.\.\/shared\.dart';/, +// /Generated type definition for MyU128/, +// ]); +// }); \ No newline at end of file diff --git a/test/types/number.test.ts b/test/types/number.test.ts new file mode 100644 index 0000000..02cfc17 --- /dev/null +++ b/test/types/number.test.ts @@ -0,0 +1,536 @@ +// import { definedTypeNode, numberTypeNode, structFieldTypeNode, structTypeNode } from '@codama/nodes'; +// import { getFromRenderMap } from '@codama/renderers-core'; +// import { visit } from '@codama/visitors-core'; +// import { test } from 'vitest'; + +// import { getRenderMapVisitor } from '../../src'; +// import { codeContains, codeDoesNotContains } from '../_setup'; + +// test('it exports short u16 numbers', () => { +// // Given a shortU16 number. +// const node = definedTypeNode({ +// name: 'myShortU16', +// type: numberTypeNode('shortU16'), +// }); + +// // When we render the number. +// const renderMap = visit(node, getRenderMapVisitor()); + +// // Then we expect a short u16 to be exported. +// codeContains(getFromRenderMap(renderMap, 'types/my_short_u16.dart'), [ +// /typedef MyShortU16 = int.*shortU16/, // Dart typedef with comment +// /import 'dart:typed_data';/, // Dart import +// /import '\.\.\/shared\.dart';/, // Dart import +// /Generated type definition for MyShortU16/, // doc comment +// ]); + +// codeDoesNotContains(getFromRenderMap(renderMap, 'types/my_short_u16.dart'), [ +// /BorshSerialize/, // Rust-specific, should not appear +// /BorshDeserialize/, // Rust-specific, should not appear +// /^use /m, // Rust import, should not appear +// ]); +// }); + +// test('it exports short u16 numbers as struct fields', () => { +// // Given a shortU16 number. +// const node = definedTypeNode({ +// name: 'myShortU16', +// type: structTypeNode([structFieldTypeNode({ name: 'value', type: numberTypeNode('shortU16') })]), +// }); + +// // When we render the number. +// const renderMap = visit(node, getRenderMapVisitor()); + +// // Then we expect a short u16 to be exported as a struct field. +// codeContains(getFromRenderMap(renderMap, 'types/my_short_u16.dart'), [ +// /class MyShortU16 /, // class declaration +// /final int.*shortU16.*value;/, // field declaration with type comment +// /MyShortU16\(\s*{\s*required this\.value,\s*}\s*\);/, // constructor +// /extension MyShortU16Borsh on MyShortU16/, // extension for serialization +// /void toBorsh\(BinaryWriter writer\)/, // serialization method +// /static MyShortU16 fromBorsh\(BinaryReader reader\)/, // deserialization method +// /throw Exception\('Unsupported number format: shortU16'\);/, // error for unsupported format +// /import 'dart:typed_data';/, // Dart import +// /import '\.\.\/shared\.dart';/, // shared import +// /Generated type definition for MyShortU16/, // doc comment +// ]); +// }); + +// test('it exports u8 numbers', () => { +// // Given a u8 number. +// const node = definedTypeNode({ +// name: 'myU8', +// type: numberTypeNode('u8'), +// }); + +// // When we render the number. +// const renderMap = visit(node, getRenderMapVisitor()); + +// // Then we expect a u8 to be exported. +// codeContains(getFromRenderMap(renderMap, 'types/my_u8.dart'), [ +// /typedef MyU8 = int.*u8/, // Dart typedef with comment +// /import 'dart:typed_data';/, // Dart import +// /import '\.\.\/shared\.dart';/, // Dart import +// /Generated type definition for MyU8/, // doc comment +// ]); + +// codeDoesNotContains(getFromRenderMap(renderMap, 'types/my_u8.dart'), [ +// /BorshSerialize/, // Rust-specific, should not appear +// /BorshDeserialize/, // Rust-specific, should not appear +// /^use /m, // Rust import, should not appear +// ]); +// }); + +// test('it exports u8 numbers as struct fields', () => { +// // Given a u8 number. +// const node = definedTypeNode({ +// name: 'myU8', +// type: structTypeNode([structFieldTypeNode({ name: 'value', type: numberTypeNode('u8') })]), +// }); + +// // When we render the number. +// const renderMap = visit(node, getRenderMapVisitor()); + +// // Then we expect a u8 to be exported as a struct field. +// codeContains(getFromRenderMap(renderMap, 'types/my_u8.dart'), [ +// /class MyU8 /, // class declaration +// /final int.*u8.*value;/, // field declaration with type comment +// /MyU8\(\s*{\s*required this\.value,\s*}\s*\);/, // constructor +// /extension MyU8Borsh on MyU8/, // extension for serialization +// /void toBorsh\(BinaryWriter writer\)/, // serialization method +// /static MyU8 fromBorsh\(BinaryReader reader\)/, // deserialization method +// /writer\.writeInt\(value\)/, // serialization line +// /reader\.readU8\(\)/, // deserialization line +// /import 'dart:typed_data';/, // Dart import +// /import '\.\.\/shared\.dart';/, // shared import +// /Generated type definition for MyU8/, // doc comment +// ]); +// }); + +// test('it exports u8 numbers', () => { +// // Given a u8 number. +// const node = definedTypeNode({ +// name: 'myU8', +// type: numberTypeNode('u8'), +// }); + +// // When we render the number. +// const renderMap = visit(node, getRenderMapVisitor()); + +// // Then we expect a u8 to be exported. +// codeContains(getFromRenderMap(renderMap, 'types/my_u8.dart'), [ +// /typedef MyU8 = int.*u8/, // Dart typedef with comment +// /import 'dart:typed_data';/, // Dart import +// /import '\.\.\/shared\.dart';/, // Dart import +// /Generated type definition for MyU8/, // doc comment +// ]); + +// codeDoesNotContains(getFromRenderMap(renderMap, 'types/my_u8.dart'), [ +// /BorshSerialize/, // Rust-specific, should not appear +// /BorshDeserialize/, // Rust-specific, should not appear +// /^use /m, // Rust import, should not appear +// ]); +// }); + +// test('it exports u8 numbers as struct fields', () => { +// // Given a u8 number. +// const node = definedTypeNode({ +// name: 'myU8', +// type: structTypeNode([structFieldTypeNode({ name: 'value', type: numberTypeNode('u8') })]), +// }); + +// // When we render the number. +// const renderMap = visit(node, getRenderMapVisitor()); + +// // Then we expect a u8 to be exported as a struct field. +// codeContains(getFromRenderMap(renderMap, 'types/my_u8.dart'), [ +// /class MyU8 /, // class declaration +// /final int.*u8.*value;/, // field declaration with type comment +// /MyU8\(\s*{\s*required this\.value,\s*}\s*\);/, // constructor +// /extension MyU8Borsh on MyU8/, // extension for serialization +// /void toBorsh\(BinaryWriter writer\)/, // serialization method +// /static MyU8 fromBorsh\(BinaryReader reader\)/, // deserialization method +// /writer\.writeInt\(value\)/, // serialization line +// /reader\.readU8\(\)/, // deserialization line +// /import 'dart:typed_data';/, // Dart import +// /import '\.\.\/shared\.dart';/, // shared import +// /Generated type definition for MyU8/, // doc comment +// ]); +// }); + +// test('it exports u16 numbers', () => { +// // Given a u16 number. +// const node = definedTypeNode({ +// name: 'myU16', +// type: numberTypeNode('u16'), +// }); + +// const renderMap = visit(node, getRenderMapVisitor()); + +// codeContains(getFromRenderMap(renderMap, 'types/my_u16.dart'), [ +// /typedef MyU16 = int.*u16/, +// /import 'dart:typed_data';/, +// /import '\.\.\/shared\.dart';/, +// /Generated type definition for MyU16/, +// ]); + +// codeDoesNotContains(getFromRenderMap(renderMap, 'types/my_u16.dart'), [ +// /BorshSerialize/, +// /BorshDeserialize/, +// /^use /m, +// ]); +// }); + +// test('it exports u16 numbers as struct fields', () => { +// // Given a u16 number. +// const node = definedTypeNode({ +// name: 'myU16', +// type: structTypeNode([structFieldTypeNode({ name: 'value', type: numberTypeNode('u16') })]), +// }); + +// const renderMap = visit(node, getRenderMapVisitor()); + +// codeContains(getFromRenderMap(renderMap, 'types/my_u16.dart'), [ +// /class MyU16 /, +// /final int.*u16.*value;/, +// /MyU16\(\s*{\s*required this\.value,\s*}\s*\);/, +// /extension MyU16Borsh on MyU16/, +// /void toBorsh\(BinaryWriter writer\)/, +// /static MyU16 fromBorsh\(BinaryReader reader\)/, +// /writer\.writeU16\(value\)/, +// /reader\.readU16\(\)/, +// /import 'dart:typed_data';/, +// /import '\.\.\/shared\.dart';/, +// /Generated type definition for MyU16/, +// ]); +// }); + +// test('it exports u16 numbers', () => { +// // Given a u16 number. +// const node = definedTypeNode({ +// name: 'myU16', +// type: numberTypeNode('u16'), +// }); + +// const renderMap = visit(node, getRenderMapVisitor()); + +// codeContains(getFromRenderMap(renderMap, 'types/my_u16.dart'), [ +// /typedef MyU16 = int.*u16/, +// /import 'dart:typed_data';/, +// /import '\.\.\/shared\.dart';/, +// /Generated type definition for MyU16/, +// ]); + +// codeDoesNotContains(getFromRenderMap(renderMap, 'types/my_u16.dart'), [ +// /BorshSerialize/, +// /BorshDeserialize/, +// /^use /m, +// ]); +// }); + +// test('it exports u16 numbers as struct fields', () => { +// // Given a u16 number. +// const node = definedTypeNode({ +// name: 'myU16', +// type: structTypeNode([structFieldTypeNode({ name: 'value', type: numberTypeNode('u16') })]), +// }); + +// const renderMap = visit(node, getRenderMapVisitor()); + +// codeContains(getFromRenderMap(renderMap, 'types/my_u16.dart'), [ +// /class MyU16 /, +// /final int.*u16.*value;/, +// /MyU16\(\s*{\s*required this\.value,\s*}\s*\);/, +// /extension MyU16Borsh on MyU16/, +// /void toBorsh\(BinaryWriter writer\)/, +// /static MyU16 fromBorsh\(BinaryReader reader\)/, +// /writer\.writeInt\(value\)/, +// /reader\.readInt\(\)/, +// /import 'dart:typed_data';/, +// /import '\.\.\/shared\.dart';/, +// /Generated type definition for MyU16/, +// ]); +// }); + +// test('it exports u32 numbers', () => { +// // Given a u32 number. +// const node = definedTypeNode({ +// name: 'myU32', +// type: numberTypeNode('u32'), +// }); + +// const renderMap = visit(node, getRenderMapVisitor()); + +// codeContains(getFromRenderMap(renderMap, 'types/my_u32.dart'), [ +// /typedef MyU32 = int.*u32/, +// /import 'dart:typed_data';/, +// /import '\.\.\/shared\.dart';/, +// /Generated type definition for MyU32/, +// ]); + +// codeDoesNotContains(getFromRenderMap(renderMap, 'types/my_u32.dart'), [ +// /BorshSerialize/, +// /BorshDeserialize/, +// /^use /m, +// ]); +// }); + +// test('it exports u32 numbers as struct fields', () => { +// // Given a u32 number. +// const node = definedTypeNode({ +// name: 'myU32', +// type: structTypeNode([structFieldTypeNode({ name: 'value', type: numberTypeNode('u32') })]), +// }); + +// const renderMap = visit(node, getRenderMapVisitor()); + +// codeContains(getFromRenderMap(renderMap, 'types/my_u32.dart'), [ +// /class MyU32 /, +// /final int.*u32.*value;/, +// /MyU32\(\s*{\s*required this\.value,\s*}\s*\);/, +// /extension MyU32Borsh on MyU32/, +// /void toBorsh\(BinaryWriter writer\)/, +// /static MyU32 fromBorsh\(BinaryReader reader\)/, +// /writer\.writeBigInt\(value\)/, +// /reader\.readU32\(\)/, +// /import 'dart:typed_data';/, +// /import '\.\.\/shared\.dart';/, +// /Generated type definition for MyU32/, +// ]); +// }); + +// test('it exports i32 numbers', () => { +// // Given an i32 number. +// const node = definedTypeNode({ +// name: 'myI32', +// type: numberTypeNode('i32'), +// }); + +// const renderMap = visit(node, getRenderMapVisitor()); + +// codeContains(getFromRenderMap(renderMap, 'types/my_i32.dart'), [ +// /typedef MyI32 = int.*i32/, +// /import 'dart:typed_data';/, +// /import '\.\.\/shared\.dart';/, +// /Generated type definition for MyI32/, +// ]); + +// codeDoesNotContains(getFromRenderMap(renderMap, 'types/my_i32.dart'), [ +// /BorshSerialize/, +// /BorshDeserialize/, +// /^use /m, +// ]); +// }); + +// test('it exports i32 numbers as struct fields', () => { +// // Given an i32 number. +// const node = definedTypeNode({ +// name: 'myI32', +// type: structTypeNode([structFieldTypeNode({ name: 'value', type: numberTypeNode('i32') })]), +// }); + +// const renderMap = visit(node, getRenderMapVisitor()); + +// codeContains(getFromRenderMap(renderMap, 'types/my_i32.dart'), [ +// /class MyI32 /, +// /final int.*i32.*value;/, +// /MyI32\(\s*{\s*required this\.value,\s*}\s*\);/, +// /extension MyI32Borsh on MyI32/, +// /void toBorsh\(BinaryWriter writer\)/, +// /static MyI32 fromBorsh\(BinaryReader reader\)/, +// /writer\.writeI32\(value\)/, +// /reader\.readI32\(\)/, +// /import 'dart:typed_data';/, +// /import '\.\.\/shared\.dart';/, +// /Generated type definition for MyI32/, +// ]); +// }); + +// test('it exports u64 numbers', () => { +// // Given a u64 number. +// const node = definedTypeNode({ +// name: 'myU64', +// type: numberTypeNode('u64'), +// }); + +// const renderMap = visit(node, getRenderMapVisitor()); + +// codeContains(getFromRenderMap(renderMap, 'types/my_u64.dart'), [ +// /typedef MyU64 = BigInt.*u64/, +// /import 'dart:typed_data';/, +// /import '\.\.\/shared\.dart';/, +// /Generated type definition for MyU64/, +// ]); + +// codeDoesNotContains(getFromRenderMap(renderMap, 'types/my_u64.dart'), [ +// /BorshSerialize/, +// /BorshDeserialize/, +// /^use /m, +// ]); +// }); + +// test('it exports u64 numbers as struct fields', () => { +// // Given a u64 number. +// const node = definedTypeNode({ +// name: 'myU64', +// type: structTypeNode([structFieldTypeNode({ name: 'value', type: numberTypeNode('u64') })]), +// }); + +// const renderMap = visit(node, getRenderMapVisitor()); + +// codeContains(getFromRenderMap(renderMap, 'types/my_u64.dart'), [ +// /class MyU64 /, +// /final BigInt.*u64.*value;/, +// /MyU64\(\s*{\s*required this\.value,\s*}\s*\);/, +// /extension MyU64Borsh on MyU64/, +// /void toBorsh\(BinaryWriter writer\)/, +// /static MyU64 fromBorsh\(BinaryReader reader\)/, +// /writer\.writeBigInt\(value\)/, +// /reader\.readU64\(\)/, +// /import 'dart:typed_data';/, +// /import '\.\.\/shared\.dart';/, +// /Generated type definition for MyU64/, +// ]); +// }); + +// test('it exports i64 numbers', () => { +// // Given an i64 number. +// const node = definedTypeNode({ +// name: 'myI64', +// type: numberTypeNode('i64'), +// }); + +// const renderMap = visit(node, getRenderMapVisitor()); + +// codeContains(getFromRenderMap(renderMap, 'types/my_i64.dart'), [ +// /typedef MyI64 = BigInt.*i64/, +// /import 'dart:typed_data';/, +// /import '\.\.\/shared\.dart';/, +// /Generated type definition for MyI64/, +// ]); + +// codeDoesNotContains(getFromRenderMap(renderMap, 'types/my_i64.dart'), [ +// /BorshSerialize/, +// /BorshDeserialize/, +// /^use /m, +// ]); +// }); + +// test('it exports i64 numbers as struct fields', () => { +// // Given an i64 number. +// const node = definedTypeNode({ +// name: 'myI64', +// type: structTypeNode([structFieldTypeNode({ name: 'value', type: numberTypeNode('i64') })]), +// }); + +// const renderMap = visit(node, getRenderMapVisitor()); + +// codeContains(getFromRenderMap(renderMap, 'types/my_i64.dart'), [ +// /class MyI64 /, +// /final BigInt.*i64.*value;/, +// /MyI64\(\s*{\s*required this\.value,\s*}\s*\);/, +// /extension MyI64Borsh on MyI64/, +// /void toBorsh\(BinaryWriter writer\)/, +// /static MyI64 fromBorsh\(BinaryReader reader\)/, +// /writer\.writeI64\(value\)/, +// /reader\.readI64\(\)/, +// /import 'dart:typed_data';/, +// /import '\.\.\/shared\.dart';/, +// /Generated type definition for MyI64/, +// ]); +// }); + + +// test('it exports u128 numbers', () => { +// // Given a u128 number. +// const node = definedTypeNode({ +// name: 'myU128', +// type: numberTypeNode('u128'), +// }); + +// const renderMap = visit(node, getRenderMapVisitor()); + +// codeContains(getFromRenderMap(renderMap, 'types/my_u128.dart'), [ +// /typedef MyU128 = BigInt.*u128/, +// /import 'dart:typed_data';/, +// /import '\.\.\/shared\.dart';/, +// /Generated type definition for MyU128/, +// ]); + +// codeDoesNotContains(getFromRenderMap(renderMap, 'types/my_u128.dart'), [ +// /BorshSerialize/, +// /BorshDeserialize/, +// /^use /m, +// ]); +// }); + +// test('it exports u128 numbers as struct fields', () => { +// // Given a u128 number. +// const node = definedTypeNode({ +// name: 'myU128', +// type: structTypeNode([structFieldTypeNode({ name: 'value', type: numberTypeNode('u128') })]), +// }); + +// const renderMap = visit(node, getRenderMapVisitor()); + +// codeContains(getFromRenderMap(renderMap, 'types/my_u128.dart'), [ +// /class MyU128 /, +// /final BigInt.*u128.*value;/, +// /MyU128\(\s*{\s*required this\.value,\s*}\s*\);/, +// /extension MyU128Borsh on MyU128/, +// /void toBorsh\(BinaryWriter writer\)/, +// /static MyU128 fromBorsh\(BinaryReader reader\)/, +// /writer\.writeBigInt\(value\)/, +// /reader\.readBigInt\(\)/, +// /import 'dart:typed_data';/, +// /import '\.\.\/shared\.dart';/, +// /Generated type definition for MyU128/, +// ]); +// }); + +// test('it exports i128 numbers', () => { +// // Given an i128 number. +// const node = definedTypeNode({ +// name: 'myI128', +// type: numberTypeNode('i128'), +// }); + +// const renderMap = visit(node, getRenderMapVisitor()); + +// codeContains(getFromRenderMap(renderMap, 'types/my_i128.dart'), [ +// /typedef MyI128 = BigInt.*i128/, +// /import 'dart:typed_data';/, +// /import '\.\.\/shared\.dart';/, +// /Generated type definition for MyI128/, +// ]); + +// codeDoesNotContains(getFromRenderMap(renderMap, 'types/my_i128.dart'), [ +// /BorshSerialize/, +// /BorshDeserialize/, +// /^use /m, +// ]); +// }); + +// test('it exports i128 numbers as struct fields', () => { +// // Given an i128 number. +// const node = definedTypeNode({ +// name: 'myI128', +// type: structTypeNode([structFieldTypeNode({ name: 'value', type: numberTypeNode('i128') })]), +// }); + +// const renderMap = visit(node, getRenderMapVisitor()); + +// codeContains(getFromRenderMap(renderMap, 'types/my_i128.dart'), [ +// /class MyI128 /, +// /final BigInt.*i128.*value;/, +// /MyI128\(\s*{\s*required this\.value,\s*}\s*\);/, +// /extension MyI128Borsh on MyI128/, +// /void toBorsh\(BinaryWriter writer\)/, +// /static MyI128 fromBorsh\(BinaryReader reader\)/, +// /writer\.writeBigInt\(value\)/, +// /reader\.readBigInt\(\)/, +// /import 'dart:typed_data';/, +// /import '\.\.\/shared\.dart';/, +// /Generated type definition for MyI128/, +// ]); +// }); \ No newline at end of file diff --git a/vitest.config.base.mts b/vitest.config.base.mts new file mode 100644 index 0000000..f09635e --- /dev/null +++ b/vitest.config.base.mts @@ -0,0 +1,22 @@ +import { env } from 'node:process'; + +import { configDefaults, defineConfig } from 'vitest/config'; + +export type Platform = 'browser' | 'node' | 'react-native'; + +export function getVitestConfig(platform: Platform) { + return defineConfig({ + define: { + __BROWSER__: `${platform === 'browser'}`, + __ESM__: 'true', + __NODEJS__: `${platform === 'node'}`, + __REACTNATIVE__: `${platform === 'react-native'}`, + __TEST__: 'true', + __VERSION__: `"${env.npm_package_version}"`, + }, + test: { + environment: platform === 'browser' ? 'happy-dom' : 'node', + exclude: [...configDefaults.exclude, '**/e2e/**'], + }, + }); +} diff --git a/vitest.config.browser.mts b/vitest.config.browser.mts new file mode 100644 index 0000000..9ed0818 --- /dev/null +++ b/vitest.config.browser.mts @@ -0,0 +1,3 @@ +import { getVitestConfig } from './vitest.config.base.mjs'; + +export default getVitestConfig('browser'); diff --git a/vitest.config.node.mts b/vitest.config.node.mts new file mode 100644 index 0000000..b12f920 --- /dev/null +++ b/vitest.config.node.mts @@ -0,0 +1,3 @@ +import { getVitestConfig } from './vitest.config.base.mjs'; + +export default getVitestConfig('node'); diff --git a/vitest.config.react-native.mts b/vitest.config.react-native.mts new file mode 100644 index 0000000..8922da5 --- /dev/null +++ b/vitest.config.react-native.mts @@ -0,0 +1,3 @@ +import { getVitestConfig } from './vitest.config.base.mjs'; + +export default getVitestConfig('react-native'); From bfa56ee53bcc3f8de9bfe75950e42acd2a0ff563 Mon Sep 17 00:00:00 2001 From: ERoydev Date: Mon, 15 Sep 2025 17:07:19 +0300 Subject: [PATCH 13/33] Fix: Arrays were incorrectly always treated as prefixed (with a prefix value). Now there are separate functions for fixed and prefixed arrays. --- e2e/anchor/lib/generated/shared.dart | 27 +- public/templates/macros.njk | 112 ++++---- public/templates/pages/sharedPage.njk | 380 ++++++++++++++++++++------ 3 files changed, 385 insertions(+), 134 deletions(-) diff --git a/e2e/anchor/lib/generated/shared.dart b/e2e/anchor/lib/generated/shared.dart index ef6c923..6941969 100644 --- a/e2e/anchor/lib/generated/shared.dart +++ b/e2e/anchor/lib/generated/shared.dart @@ -281,6 +281,11 @@ class BinaryReader { ); } + // Reads a fixed-length array of generic items. + List readFixedArray(int length, T Function() itemReader) { + return List.generate(length, (_) => itemReader()); + } + /// Reads a variable-length array of generic items. List readArray(T Function() itemReader) { final count = readU32(); @@ -425,7 +430,10 @@ class BinaryWriter { /// Writes a signed 64-bit integer. void writeI64(BigInt value) { - writeU64(value & (BigInt.one << 64) - BigInt.one); + var v = value.toSigned(64); + for (int i = 0; i < 8; i++) { + _bytes.add(((v >> (8 * i)) & BigInt.from(0xFF)).toInt()); + } } /// Writes a string. @@ -569,6 +577,23 @@ class BinaryWriter { _bytes.addAll(value); } + // Reads a fixed-length array of generic items. + // List readFixedArray(int length, T Function() itemReader) { + // return List.generate(length, (_) => itemReader()); + // } + + void writeFixedArray( + int length, List items, void Function(T) itemWriter) { + final count = length ?? items.length; + if (items.length < count) { + throw ArgumentError( + 'items length (${items.length}) is less than fixed array length ($count)'); + } + for (int i = 0; i < count; i++) { + itemWriter(items[i]); + } + } + /// Writes a variable-length array of generic items. void writeArray(List items, void Function(T) itemWriter) { writeU32(items.length); diff --git a/public/templates/macros.njk b/public/templates/macros.njk index 1b3f2fc..0d20a93 100644 --- a/public/templates/macros.njk +++ b/public/templates/macros.njk @@ -38,26 +38,32 @@ {# Recursive Borsh Reader, responsible for handling collections and any nested levels #} {% macro borshReader(field) %} - {{ recursiveReader(field.nesting, field.baseType, field.isStruct) }} + {{ recursiveReader(field.nesting, field.baseType, field.isStruct, field.size, field.format) }} {% endmacro %} -{% macro recursiveReader(depth, baseType, isStruct) %} - {% if depth == 0 %} +{% macro recursiveReader(depth, baseType, isStruct, size, format) %} + {% if depth > 5 %} + // ERROR: Nesting depth exceeds supported limit (5) + throw Exception('Nesting depth exceeds supported limit(5)'); + {% elif depth == 0 %} {% if isStruct %} {{ baseType }}Borsh.fromBorsh(reader) {% else %} - {{ baseTypeReader(baseType) }} + {{ baseTypeReader(baseType, false, size, format) }} {% endif %} {% else %} - reader.readArray(() { + {% if size is defined %} + reader.readFixedArray({{size}}, () { + {% else %} + reader.readArray(() { + {% endif %} {% if isStruct %} // item is a struct, call fromBorsh per item return {{ baseType }}Borsh.fromBorsh(reader); {% else %} - return {{ recursiveReader(depth - 1, baseType, false) }}; + return {{ recursiveReader(depth - 1, baseType, false, size, format) }}; {% endif %} - }) -<<<<<<< Updated upstream + }) {% endif %} {% endmacro %} @@ -118,40 +124,37 @@ {% endif %} {% else %} throw Exception('Unsupported number format: {{ format }}'); -======= ->>>>>>> Stashed changes {% endif %} {% endmacro %} {# Reader for the base types (no nesting) #} -{% macro baseTypeReader(baseType, isStruct) %} - {% if baseType == 'int' %} - reader.readInt() - {% elif baseType == 'BigInt' %} - reader.readBigInt() +{% macro baseTypeReader(baseType, isStruct, size, format) %} + {% if baseType == 'int' or baseType == 'BigInt' %} + {{ intFormatUtil(format, false) }} {% elif baseType == 'String' %} reader.readString() {% elif baseType == 'Uint8List' %} - reader.readFixedU8Array({{ field.size or 8}}) + reader.readU8Array({{ size if size is defined else '' }}) {% elif baseType == 'Int8List' %} - reader.readFixedI8Array({{ field.size or 8}}) + reader.readI8Array({{ size if size is defined else '' }}) {% elif baseType == 'Uint16List' %} - reader.readFixedU16Array({{ field.size or 16 }}) + reader.readU16Array({{ size if size is defined else '' }}) {% elif baseType == 'Int16List' %} - reader.readFixedI16Array({{ field.size or 16}}) + reader.readI16Array({{ size if size is defined else '' }}) {% elif baseType == 'Uint32List' %} - reader.readFixedU32Array({{ field.size or 32}}) + reader.readU32Array({{ size if size is defined else '' }}) {% elif baseType == 'Int32List' %} - reader.readFixedI32Array({{ field.size or 32}}) + reader.readI32Array({{ size if size is defined else '' }}) {% elif baseType == 'Uint64List' %} - reader.readFixedU64Array({{ field.size or 64}}) + reader.readU64Array({{ size if size is defined else '' }}) {% elif baseType == 'Int64List' %} - reader.readFixedI64Array({{ field.size or 64 }}) + reader.readI64Array({{ size if size is defined else '' }}) {% elif baseType == 'bool' %} reader.readBool() {% elif baseType == 'Ed25519HDPublicKey' %} - Ed25519HDPublicKey(Uint8List.fromList(reader.readFixedU8Array(32))) + Ed25519HDPublicKey(reader.readPubkey()) {% else %} + /// TODO: I need to provide panic or error guard to indicate that user is doing something that is not supported reader.readUnknownType('{{ baseType }}') {% endif %} {% endmacro %} @@ -159,61 +162,62 @@ {# Recursive Borsh Writer, responsible to handle nested type of collections #} {% macro borshWriter(field, overrideFieldName="") %} {% set name = overrideFieldName if overrideFieldName else field.name %} - {{ recursiveWriter(name, field.nesting, field.baseType, field.isStruct) }} + {{ recursiveWriter(name, field.nesting, field.baseType, field.isStruct, field.size, field.format) }} {% endmacro %} -{% macro recursiveWriter(varName, depth, baseType, isStruct) %} - {% if depth == 0 %} +{% macro recursiveWriter(varName, depth, baseType, isStruct, size, format) %} + {% if depth > 5 %} + // ERROR: Nesting depth exceeds supported limit (5) + throw Exception('Nesting depth exceeds supported limit(5)'); + {% elif depth == 0 %} {% if isStruct %} {{ varName }}.toBorsh(writer); {% else %} {# TODO: I have problem here because of these recursions i put ';' twice because twice is iterated here first trough writeArray and on the recursion i go inside here and i put ';' again #} - {{ baseTypeWriter(baseType, varName) }}; + {{ baseTypeWriter(baseType, varName, size, format) }}; {% endif %} {% else %} - writer.writeArray<{{ baseType }}>({{ varName }}, ({{ baseType }} item) { - {% if isStruct %} - // Each item is a struct - item.toBorsh(writer); - {% else %} -<<<<<<< Updated upstream - {{ recursiveWriter("item", depth - 1, baseType, false, size, format) }}; -======= - {{ recursiveWriter("item", depth - 1, baseType, false) }}; ->>>>>>> Stashed changes - {% endif %} - }); + {% if size is defined %} + writer.writeFixedArray<{{ baseType }}>({{size}}, {{ varName }}, ({{ baseType }} item) { + {% else %} + writer.writeArray<{{ baseType }}>({{ varName }}, ({{ baseType }} item) { + {% endif %} + {% if isStruct %} + // Each item is a struct + item.toBorsh(writer); + {% else %} + {{ recursiveWriter("item", depth - 1, baseType, false, size, format) }}; + {% endif %} + }); {% endif %} {% endmacro %} {# Base Writer, no nested types inside #} -{% macro baseTypeWriter(baseType, varName, isStruct) %} - {% if baseType == 'int' %} - writer.writeInt({{ varName }}) - {% elif baseType == 'BigInt' %} - writer.writeBigInt({{ varName }}) +{% macro baseTypeWriter(baseType, varName, size, format) %} + {% if baseType == 'int' or baseType == 'BigInt' %} + {{ intFormatUtil(format, true, varName) }} {% elif baseType == 'String' %} writer.writeString({{ varName }}) {% elif baseType == 'Uint8List' %} - writer.writeFixedU8Array({{ varName }}) + writer.writeU8Array({{ varName }}, {{ size if size is defined else 'null' }}) {% elif baseType == 'Int8List' %} - writer.writeFixedI8Array({{ varName }}) + writer.writeI8Array({{ varName }}, {{ size if size is defined else 'null' }}) {% elif baseType == 'Uint16List' %} - writer.writeFixedU16Array({{ varName }}) + writer.writeU16Array({{ varName }}, {{ size if size is defined else 'null' }}) {% elif baseType == 'Int16List' %} - writer.writeFixedI16Array({{ varName }}) + writer.writeI16Array({{ varName }}, {{ size if size is defined else 'null' }}) {% elif baseType == 'Uint32List' %} - writer.writeFixedU32Array({{ varName }}) + writer.writeU32Array({{ varName }}, {{ size if size is defined else 'null' }}) {% elif baseType == 'Int32List' %} - writer.writeFixedI32Array({{ varName }}) + writer.writeI32Array({{ varName }}, {{ size if size is defined else 'null' }}) {% elif baseType == 'Uint64List' %} - writer.writeFixedU64Array({{ varName }}) + writer.writeU64Array({{ varName }}, {{ size if size is defined else 'null' }}) {% elif baseType == 'Int64List' %} - writer.writeFixedI64Array({{ varName }}) + writer.writeI64Array({{ varName }}, {{ size if size is defined else 'null' }}) {% elif baseType == 'bool' %} writer.writeBool({{ varName }}) {% elif baseType == 'Ed25519HDPublicKey' %} - writer.writeFixedU8Array(Uint8List.fromList({{ varName }}.bytes)) + writer.writePubkey(Uint8List.fromList({{ varName }}.bytes)) {% else %} writer.writeUnknownType('{{ baseType }}') {% endif %} diff --git a/public/templates/pages/sharedPage.njk b/public/templates/pages/sharedPage.njk index cc75cfd..5c36a60 100644 --- a/public/templates/pages/sharedPage.njk +++ b/public/templates/pages/sharedPage.njk @@ -1,7 +1,10 @@ -{% extends "layout.njk" %} -{% import "macros.njk" as macros %} +/// This code was AUTOGENERATED using the codama library. +/// Please DO NOT EDIT THIS FILE, instead use visitors +/// to add features, then rerun codama to update it. +/// +/// https://github.com/codama-idl/codama +/// -{% block main %} // Shared utilities and types for the SDK. import 'dart:convert'; @@ -23,13 +26,15 @@ class AccountNotFoundError extends Error { /// Binary reader for decoding Borsh-encoded data. class BinaryReader { - final ByteData _data; + final ByteData + _data; // holds the raw binary data buffer, that i read from. Represents entire sequence of bytes. + + // Offset tracks the current byte position in the buffer; advance it after each read to ensure correct sequential decoding. int _offset = 0; /// Creates a new BinaryReader. BinaryReader(this._data); -<<<<<<< Updated upstream Uint8List readDiscriminator() { final length = 8; // Discriminator is always the first 8 bytes final bytes = @@ -41,13 +46,12 @@ class BinaryReader { /// Reads a single public key (32 raw bytes, no prefix). Uint8List readPubkey() { final length = 32; - final bytes = Uint8List.view(_data.buffer, _data.offsetInBytes + _offset, length); + final bytes = + Uint8List.view(_data.buffer, _data.offsetInBytes + _offset, length); _offset += length; return bytes; } -======= ->>>>>>> Stashed changes /// Reads a boolean value. bool readBool() { final value = _data.getUint8(_offset) != 0; @@ -135,69 +139,132 @@ class BinaryReader { /// Reads a string. String readString() { final length = readU32(); - final bytes = Uint8List.view(_data.buffer, _data.offsetInBytes + _offset, length); + final bytes = + Uint8List.view(_data.buffer, _data.offsetInBytes + _offset, length); _offset += length; return utf8.decode(bytes); } - /// Reads a fixed-size u8 array of bytes. - Uint8List readFixedU8Array(int length) { - final bytes = - Uint8List.view(_data.buffer, _data.offsetInBytes + _offset, length); - _offset += length; - return bytes; + /// Reads a u8 array from Borsh data. If `length` is null, reads the length from a 4-byte prefix. + Uint8List readU8Array([int? length]) { + if (length == null) { + // Read the 4-byte little-endian length prefix (Borsh Vec) + length = _data.getUint32(_offset, Endian.little); + _offset += 4; + } + + return readAlignedArray( + 1, + length, + Uint8List.view, + 1, + (offset) => _data.getUint8(offset), + ); } /// Reads a fixed-size i8 array of bytes. - Int8List readFixedI8Array(int length) { - final bytes = - Int8List.view(_data.buffer, _data.offsetInBytes + _offset, length); - _offset += length; - return bytes; + Int8List readI8Array([int? length]) { + if (length == null) { + // Read the 4-byte little-endian length prefix (Borsh Vec) + length = _data.getUint32(_offset, Endian.little); + _offset += 4; + } + + return readAlignedArray( + 1, + length, + Int8List.view, + 1, + (offset) => _data.getInt8(offset), + ); } /// Reads a fixed-size u16 array of bytes. - Uint16List readFixedU16Array(int length) { - final bytes = - Uint16List.view(_data.buffer, _data.offsetInBytes + _offset, length); - _offset += length * 4; - return bytes; + Uint16List readU16Array([int? length]) { + if (length == null) { + // Read the 4-byte little-endian length prefix (Borsh Vec) + length = _data.getUint32(_offset, Endian.little); + _offset += 4; + } + + return readAlignedArray( + 2, + length, + Uint16List.view, + 2, + (offset) => _data.getUint16(offset, Endian.little), + ); } /// Reads a fixed-size i16 array of bytes. - Int16List readFixedI16Array(int length) { - final bytes = - Int16List.view(_data.buffer, _data.offsetInBytes + _offset, length); - _offset += length * 4; - return bytes; + Int16List readI16Array([int? length]) { + if (length == null) { + // Read the 4-byte little-endian length prefix (Borsh Vec) + length = _data.getUint32(_offset, Endian.little); + _offset += 4; + } + + return readAlignedArray( + 2, + length, + Int16List.view, + 2, + (offset) => _data.getInt16(offset, Endian.little), + ); } /// Reads a fixed-size u32 array of bytes. - Uint32List readFixedU32Array(int length) { - final bytes = - Uint32List.view(_data.buffer, _data.offsetInBytes + _offset, length); - _offset += length * 4; - return bytes; + Uint32List readU32Array([int? length]) { + if (length == null) { + // Read the 4-byte little-endian length prefix (Borsh Vec) + length = _data.getUint32(_offset, Endian.little); + _offset += 4; + } + + return readAlignedArray( + 4, + length, + Uint32List.view, + 4, + (offset) => _data.getUint32(offset, Endian.little), + ); } /// Reads a fixed-size i32 array of bytes. - Int32List readFixedI32Array(int length) { - final bytes = - Int32List.view(_data.buffer, _data.offsetInBytes + _offset, length); - _offset += length * 4; - return bytes; + Int32List readI32Array([int? length]) { + if (length == null) { + // Read the 4-byte little-endian length prefix (Borsh Vec) + length = _data.getUint32(_offset, Endian.little); + _offset += 4; + } + + return readAlignedArray( + 4, + length, + Int32List.view, + 4, + (offset) => _data.getInt32(offset, Endian.little), + ); } /// Reads a fixed-size u64 array of bytes. - Uint64List readFixedU64Array(int length) { - final bytes = - Uint64List.view(_data.buffer, _data.offsetInBytes + _offset, length); - _offset += length * 4; - return bytes; + Uint64List readU64Array([int? length]) { + if (length == null) { + // Read the 4-byte little-endian length prefix (Borsh Vec) + length = _data.getUint32(_offset, Endian.little); + _offset += 4; + } + + return readAlignedArray( + 8, + length, + Uint64List.view, + 8, + (offset) => _data.getUint64(offset, Endian.little), + ); } /// Reads a fixed-size i64 array of bytes. -<<<<<<< Updated upstream Int64List readI64Array([int? length]) { if (length == null) { // Read the 4-byte little-endian length prefix (Borsh Vec) @@ -212,13 +279,11 @@ class BinaryReader { 8, (offset) => _data.getInt64(offset, Endian.little), ); -======= - Int64List readFixedI64Array(int length) { - final bytes = - Int64List.view(_data.buffer, _data.offsetInBytes + _offset, length); - _offset += length * 4; - return bytes; ->>>>>>> Stashed changes + } + + // Reads a fixed-length array of generic items. + List readFixedArray(int length, T Function() itemReader) { + return List.generate(length, (_) => itemReader()); } /// Reads a variable-length array of generic items. @@ -234,7 +299,46 @@ class BinaryReader { /// Reads a variable-length array of bytes. Uint8List readBytes() { final length = readU32(); - return readFixedU8Array(length); + return readU8Array(length); + } + + // ========= Utils for alignment-safe array reading ======== + + // This function handles the problem of buffer's offset that is not properly aligned for typed array views. + // It happens because i have fixed-size and prefixed-size arrays. + T readAlignedArray( + int alignment, + int length, + T Function(ByteBuffer buffer, int offset, int length) viewConstructor, + int bytesPerElement, + int Function(int offset) manualGetter, + ) { + // Check the offset alignment for `Uint*List.view` it should be multiple of element size + if ((_data.offsetInBytes + _offset) % alignment == 0) { + final arr = + viewConstructor(_data.buffer, _data.offsetInBytes + _offset, length); + _offset += length * bytesPerElement; + return arr; + } else { + // Manual read if not aligned + // For example, for Uint16List: + final arr = List.generate(length, (i) { + final value = manualGetter(_offset); + _offset += bytesPerElement; + return value; + }); + // Convert to typed list + if (T == Uint8List) return Uint8List.fromList(arr) as T; + if (T == Uint16List) return Uint16List.fromList(arr) as T; + if (T == Uint32List) return Uint32List.fromList(arr) as T; + if (T == Uint64List) return Uint64List.fromList(arr) as T; + if (T == Int8List) return Int8List.fromList(arr) as T; + if (T == Int16List) return Int16List.fromList(arr) as T; + if (T == Int32List) return Int32List.fromList(arr) as T; + if (T == Int64List) return Int64List.fromList(arr) as T; + // ...add more types as needed + return arr as T; + } } } @@ -242,6 +346,13 @@ class BinaryReader { class BinaryWriter { final List _bytes = []; + void writeDiscriminator(Uint8List discriminator) { + if (discriminator.length != 8) { + throw ArgumentError('Discriminator must be exactly 8 bytes'); + } + _bytes.addAll(discriminator); + } + /// Writes a boolean value. void writeBool(bool value) { _bytes.add(value ? 1 : 0); @@ -289,7 +400,7 @@ class BinaryWriter { void writeU64(BigInt value) { final low = value & BigInt.from(0xFFFFFFFF); final high = (value >> 32) & BigInt.from(0xFFFFFFFF); - + _bytes.addAll([ low.toInt() & 0xFF, (low.toInt() >> 8) & 0xFF, @@ -319,7 +430,10 @@ class BinaryWriter { /// Writes a signed 64-bit integer. void writeI64(BigInt value) { - writeU64(value & (BigInt.one << 64) - BigInt.one); + var v = value.toSigned(64); + for (int i = 0; i < 8; i++) { + _bytes.add(((v >> (8 * i)) & BigInt.from(0xFF)).toInt()); + } } /// Writes a string. @@ -329,44 +443,132 @@ class BinaryWriter { _bytes.addAll(bytes); } - /// Writes a fixed-size u8 array of bytes. - void writeFixedU8Array(Uint8List value) { - _bytes.addAll(value); + /// Writes a fixed-size and prefixed-size u8 array of bytes. + void writeU8Array(Uint8List value, int? length) { + if (length == null) { + // Variable-length: write length prefix + writeU32(value.length); + for (final v in value) { + writeU8(v); + } + } else { + // Fixed-size: write exactly [length] elements, no prefix + for (int i = 0; i < length; i++) { + writeU8(value[i]); + } + } } - /// Writes a fixed-size i8 array of bytes. - void writeFixedI8Array(Int8List value) { - _bytes.addAll(value); + /// Writes a fixed-size and prefixed-size u8 array of bytes. + void writeI8Array(Int8List value, int? length) { + if (length == null) { + // Variable-length: write length prefix + writeU32(value.length); + for (final v in value) { + writeI8(v); + } + } else { + // Fixed-size: write exactly [length] elements, no prefix + for (int i = 0; i < length; i++) { + writeI8(value[i]); + } + } } - /// Writes a fixed-size u16 array of bytes. - void writeFixedU16Array(Uint16List value) { - _bytes.addAll(value); + /// Writes a fixed-size and prefixed-size u16 array of bytes. + void writeU16Array(Uint16List value, int? length) { + if (length == null) { + // Variable-length: write length prefix + writeU32(value.length); + for (final v in value) { + writeU16(v); + } + } else { + // Fixed-size: write exactly [length] elements, no prefix + for (int i = 0; i < length; i++) { + writeU16(value[i]); + } + } } - /// Writes a fixed-size i16 array of bytes. - void writeFixedI16Array(Int16List value) { - _bytes.addAll(value); + /// Writes a fixed-size and prefixed-size i16 array of bytes. + void writeI16Array(Int16List value, int? length) { + if (length == null) { + // Variable-length: write length prefix + writeU32(value.length); + for (final v in value) { + writeI16(v); + } + } else { + // Fixed-size: write exactly [length] elements, no prefix + for (int i = 0; i < length; i++) { + writeI16(value[i]); + } + } } - - /// Writes a fixed-size u32 array of bytes. - void writeFixedU32Array(Uint32List value) { - _bytes.addAll(value); + + /// Writes a fixed-size and prefixed-size i16 array of bytes. + void writeU32Array(Uint32List value, int? length) { + if (length == null) { + // Variable-length: write length prefix + writeU32(value.length); + for (final v in value) { + writeU32(v); + } + } else { + // Fixed-size: write exactly [length] elements, no prefix + for (int i = 0; i < length; i++) { + writeU32(value[i]); + } + } } /// Writes a fixed-size i32 array of bytes. - void writeFixedI32Array(Int32List value) { - _bytes.addAll(value); + void writeI32Array(Int32List value, int? length) { + if (length == null) { + // Variable-length: write length prefix + writeU32(value.length); + for (final v in value) { + writeI32(v); + } + } else { + // Fixed-size: write exactly [length] elements, no prefix + for (int i = 0; i < length; i++) { + writeI32(value[i]); + } + } } /// Writes a fixed-size u64 array of bytes. - void writeFixedU64Array(Uint64List value) { - _bytes.addAll(value); + void writeU64Array(Uint64List value, int? length) { + if (length == null) { + // Variable-length: write length prefix + writeU32(value.length); + for (final v in value) { + writeU64(BigInt.from(v)); + } + } else { + // Fixed-size: write exactly [length] elements, no prefix + for (int i = 0; i < length; i++) { + writeU64(BigInt.from(value[i])); + } + } } /// Writes a fixed-size i64 array of bytes. - void writeFixedI64Array(Int64List value) { - _bytes.addAll(value); + void writeI64Array(Int64List value, int? length) { + if (length == null) { + // Variable-length: write length prefix + writeU32(value.length); + for (final v in value) { + writeI64(BigInt.from(v)); + } + } else { + // Fixed-size: write exactly [length] elements, no prefix + for (int i = 0; i < length; i++) { + writeI64(BigInt.from(value[i])); + } + } } /// Writes a variable-length array of bytes. @@ -375,6 +577,22 @@ class BinaryWriter { _bytes.addAll(value); } + // Reads a fixed-length array of generic items. + // List readFixedArray(int length, T Function() itemReader) { + // return List.generate(length, (_) => itemReader()); + // } + + + void writeFixedArray(int length, List items, void Function(T) itemWriter) { + final count = length ?? items.length; + if (items.length < count) { + throw ArgumentError('items length (${items.length}) is less than fixed array length ($count)'); + } + for (int i = 0; i < count; i++) { + itemWriter(items[i]); + } + } + /// Writes a variable-length array of generic items. void writeArray(List items, void Function(T) itemWriter) { writeU32(items.length); @@ -383,7 +601,11 @@ class BinaryWriter { } } + /// Writes a single public key (32 raw bytes, no prefix). + void writePubkey(Uint8List pubkeyBytes) { + _bytes.addAll(pubkeyBytes); + } + /// Returns the byte array. Uint8List toBytes() => Uint8List.fromList(_bytes); } -{% endblock %} \ No newline at end of file From 185e6ca18be9c2999abe596986281792f7d7f37a Mon Sep 17 00:00:00 2001 From: ERoydev Date: Mon, 15 Sep 2025 17:07:45 +0300 Subject: [PATCH 14/33] fix: Discriminator borsh implementation --- public/templates/pages/accountsPage.njk | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/public/templates/pages/accountsPage.njk b/public/templates/pages/accountsPage.njk index e3fa5ef..c71063a 100644 --- a/public/templates/pages/accountsPage.njk +++ b/public/templates/pages/accountsPage.njk @@ -67,7 +67,7 @@ void toBorsh(BinaryWriter writer) { {% if account.discriminator %} // Validate the discriminator - final discriminator = reader.readFixedU8Array(8); + final discriminator = reader.readDiscriminator(); if (!const ListEquality().equals(discriminator, {{ account.name | snakeCase | upper }}_DISCRIMINATOR)) { throw FormatException('Invalid account discriminator'); } @@ -82,7 +82,7 @@ void toBorsh(BinaryWriter writer) { {% if account.discriminator %} // Write discriminator - writer.writeFixedU8Array(Uint8List.fromList({{ account.name | snakeCase | upper }}_DISCRIMINATOR)); + writer.writeDiscriminator(Uint8List.fromList({{ account.name | snakeCase | upper }}_DISCRIMINATOR)); {% endif %} // Write account data @@ -129,7 +129,11 @@ void toBorsh(BinaryWriter writer) { RpcClient client, Ed25519HDPublicKey address, ) async { - final accountInfo = await client.getAccountInfo(address.toBase58()); + {# Always use encoding: Encoding.base64 when fetching account data. #} + {# Base58 is meant for public keys, not raw binary, and will produce the wrong bytes. #} + {# Base64 ensures we get the exact raw on-chain bytes (including the correct discriminator). #} + + final accountInfo = await client.getAccountInfo(address.toBase58(), encoding: Encoding.base64); final data = accountInfo.value?.data; if (data == null) { From 6893303a1ca31d487f8d0a6d4e568d73aa88c0a6 Mon Sep 17 00:00:00 2001 From: ERoydev Date: Mon, 15 Sep 2025 17:08:17 +0300 Subject: [PATCH 15/33] add(): Utility regex for errors --- public/templates/pages/errorsPage.njk | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/public/templates/pages/errorsPage.njk b/public/templates/pages/errorsPage.njk index 4f6ffdd..e38b6dd 100644 --- a/public/templates/pages/errorsPage.njk +++ b/public/templates/pages/errorsPage.njk @@ -14,6 +14,19 @@ class {{ program.name | pascalCase }}ErrorCode { /// Base class for all {{ program.name | pascalCase }} program errors. abstract class {{ program.name | pascalCase }}Error extends Error { + + /// Utility: Extracts and maps a Solana error string to an {{program.name | pascalCase }}Error, or null if not found. + static {{program.name | pascalCase}}Error? fromSolanaErrorString(Object error) { + final errorString = error.toString(); + final match = RegExp(r'custom program error: 0x([0-9a-fA-F]+)').firstMatch(errorString); + if (match != null) { + final codeHex = match.group(1); + final code = int.parse(codeHex!, radix: 16); + return {{ program.name | pascalCase }}Error.fromCode(code); + } + return null; + } + /// The numerical error code. final int code; From cda5120f369555bd269eb2a07e1ec53e4ee08657 Mon Sep 17 00:00:00 2001 From: ERoydev Date: Mon, 15 Sep 2025 17:08:52 +0300 Subject: [PATCH 16/33] fix: Enum still need to specify the Variant index when serialized to match the buffer --- public/templates/pages/definedTypesPage.njk | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/public/templates/pages/definedTypesPage.njk b/public/templates/pages/definedTypesPage.njk index 285a9ae..7feb4fb 100644 --- a/public/templates/pages/definedTypesPage.njk +++ b/public/templates/pages/definedTypesPage.njk @@ -23,6 +23,13 @@ extension {{ definedType.name | pascalCase }}Borsh on {{ definedType.name | pasc {# Initial idx value used to track which field from fields collection is reached #} {% set startIdx = 0 %} {% for variant in definedType.type.variants %} + {% if variant.kind == 'enumEmptyVariantTypeNode' %} + {# The enum is empty but i still need to specify the Variant Index in Borsh Serialization #} + if (this is {{ variant.name | pascalCase }}) { + writer.writeU8({{ loop.index0 }}); // Variant index expected by Borsh + } + {% endif %} + {% if variant.kind != 'enumEmptyVariantTypeNode' %} if (this is {{ variant.name | pascalCase }}) { {# Count of fields that this Variant has #} @@ -33,6 +40,7 @@ extension {{ definedType.name | pascalCase }}Borsh on {{ definedType.name | pasc %} {% set indices = range(startIdx, startIdx + count) %} {# Index range for this enum Variant's fields #} + writer.writeU8({{ loop.index0 }}); // Variant index expected by Bors final v = this as {{ variant.name | pascalCase }}; {% for i in indices %} From 4049fd90b85e81560e7054e8ae6a41c88c8ffaa9 Mon Sep 17 00:00:00 2001 From: ERoydev Date: Mon, 15 Sep 2025 17:09:38 +0300 Subject: [PATCH 17/33] fix: Instruction page borsh for arguments reused --- public/templates/pages/instructionsPage.njk | 184 ++++++++++---------- 1 file changed, 88 insertions(+), 96 deletions(-) diff --git a/public/templates/pages/instructionsPage.njk b/public/templates/pages/instructionsPage.njk index da2f6dd..8631854 100644 --- a/public/templates/pages/instructionsPage.njk +++ b/public/templates/pages/instructionsPage.njk @@ -5,120 +5,112 @@ {{ imports }} {% if instruction.discriminator and instruction.discriminator.length > 0 -%} -const List - {{ instruction.name | snakeCase | upper }}_DISCRIMINATOR = [{{ instruction.discriminator | join(', ') }}]; -{%- endif %} + const List {{ instruction.name | snakeCase | upper }}_DISCRIMINATOR = [{{ instruction.discriminator | join(', ') }}]; + {%- endif %} -/// Generated instruction class for {{ instruction.name | pascalCase }}. -/// -{% if instruction.docs.length > 0 -%} - {%- for doc in instruction.docs -%} -/// {{ doc }} - {%- endfor -%} - {%- endif %} -class {{ instruction.name | pascalCase }}Instruction { + /// Generated instruction class for {{ instruction.name | pascalCase }}. + /// + {% if instruction.docs.length > 0 -%} + {%- for doc in instruction.docs -%} + /// {{ doc }} + {%- endfor -%} + {%- endif %} - // Accounts - {% for account in instruction.accounts %} - // {{ account.docs[0] if account.docs and account.docs[0] else ('The ' ~ (account.name | camelCase) ~ ' account.') }} + class {{ instruction.name | pascalCase }}Instruction { + + // Accounts + {% for account in instruction.accounts %} + // {{ account.docs[0] if account.docs and account.docs[0] else ('The ' ~ (account.name | snakeCase ) ~ ' account.') }} {% if account.isOptional %} - final Ed25519HDPublicKey? {{ account.name | camelCase }}; - {% else %} - final Ed25519HDPublicKey {{ account.name | camelCase }}; - {% endif %} + final Ed25519HDPublicKey? {{ account.name | snakeCase }}; + {% else %} + final Ed25519HDPublicKey {{ account.name | snakeCase }}; + {% endif %} {% if account.isSigner === 'either' %} - /// Whether the {{ account.name | camelCase }} account is a signer. - final bool {{ account.name | camelCase }}IsSigner; - {% endif %} + /// Whether the {{ account.name | snakeCase }} account is a signer. + final bool {{ account.name | snakeCase }}IsSigner; + {% endif %} {% endfor %} - // Args - {% if args and args.length > 0 %} + // Args + {% if args and args.length > 0 %} {% for arg in args %} - final {{ arg.dartType }} - {{ arg.name }}; - {% endfor %} + final {{ arg.dartType }} {{ arg.name | snakeCase }}; + {% endfor %} {% endif %} {{ instruction.name | pascalCase }}Instruction({ - {% for account in instruction.accounts -%} - {%- if account.isOptional -%} - this.{{ account.name | camelCase }}, - {%- else -%} - required this.{{ account.name | camelCase }}, - {%- endif -%} - {%- if account.isSigner === 'either' -%} - this.{{ account.name | camelCase }}IsSigner = false, - {%- endif -%} - {%- endfor -%} - {%- if args and args.length > 0 -%} - {%- for arg in args -%} - required this.{{ arg.name }}, + {% for account in instruction.accounts -%} + {%- if account.isOptional -%} + this.{{ account.name | snakeCase }}, + {%- else -%} + required this.{{ account.name | snakeCase }}, + {%- endif -%} + {%- if account.isSigner === 'either' -%} + this.{{ account.name | snakeCase }}IsSigner = false, + {%- endif -%} {%- endfor -%} - {%- endif -%} - }); + {%- if args and args.length > 0 -%} + {%- for arg in args -%} + required this.{{ arg.name | snakeCase }}, + {%- endfor -%} + {%- endif -%} + }); - /// Builds the `Instruction` (data = discriminator + args). - Instruction toInstruction({ List remainingAccounts = const [] }) { - final keys = [ - {%- for account in instruction.accounts %} + /// Builds the `Instruction` (data = discriminator + args). + Instruction toInstruction({ List remainingAccounts = const [] }) { + final keys = [ + {%- for account in instruction.accounts %} {%- if account.isOptional %} - if ({{ account.name | camelCase }} != null) - AccountMeta( - pubKey: {{ account.name | camelCase }}!, - isSigner: {%- if account.isSigner === 'either' -%}{{ account.name | camelCase }}IsSigner{%- else -%}{{ 'true' if account.isSigner else 'false' }} - {%- endif -%}, - isWriteable: {{ 'true' if account.isWritable else 'false' }}, - ), - {%- else %} - AccountMeta( - pubKey: {{ account.name | camelCase }}, - isSigner: {%- if account.isSigner === 'either' -%}{{ account.name | camelCase }}IsSigner{%- else -%}{{ 'true' if account.isSigner else 'false' }} - {%- endif -%}, - isWriteable: {{ 'true' if account.isWritable else 'false' }}, - ), - {%- endif %} + if ({{ account.name | snakeCase }} != null) + AccountMeta( + pubKey: {{ account.name | snakeCase }}!, + isSigner: {%- if account.isSigner === 'either' -%}{{ account.name | snakeCase }}IsSigner{%- else -%}{{ 'true' if account.isSigner else 'false' }}{%- endif -%}, + isWriteable: {{ 'true' if account.isWritable else 'false' }}, + ), + {%- else %} + AccountMeta( + pubKey: {{ account.name | snakeCase }}, + isSigner: {%- if account.isSigner === 'either' -%}{{ account.name | snakeCase }}IsSigner{%- else -%}{{ 'true' if account.isSigner else 'false' }}{%- endif -%}, + isWriteable: {{ 'true' if account.isWritable else 'false' }}, + ), + {%- endif %} {%- endfor %} - ]; + ]; - if (remainingAccounts.isNotEmpty) { - keys.addAll(remainingAccounts); - } + if (remainingAccounts.isNotEmpty) { + keys.addAll(remainingAccounts); + } - // Serialize: discriminator (8 bytes) + args - final writer = BinaryWriter(); -{%- if instruction.discriminator and instruction.discriminator.length > 0 %} -writer.writeFixedU8Array(Uint8List.fromList({{ instruction.name | snakeCase | upper }}_DISCRIMINATOR)); -{%- endif %} - {%- if args and args.length > 0 %} - {%- for arg in args %} - {%- if arg.resolvedType.kind === 'numberTypeNode' %} - writer.writeU{{ arg.resolvedType.format | replace('u', '') }}({{ arg.name }}); - {%- elif arg.resolvedType.kind === 'stringTypeNode' %} - writer.writeString({{ arg.name }}); - {%- elif arg.resolvedType.kind === 'booleanTypeNode' %} - writer.writeBool({{ arg.name }}); - {%- elif arg.resolvedType.kind === 'publicKeyTypeNode' %} - writer.writeFixedU8Array(Uint8List.fromList({{ arg.name }}.bytes)); - {%- elif arg.resolvedType.kind === 'bytesTypeNode' %} - writer.writeBytes({{ arg.name }}); - {%- else %} - {{ arg.name }}.toBorsh(writer); + // Serialize: discriminator (8 bytes) + args + final writer = BinaryWriter(); + {%- if instruction.discriminator and instruction.discriminator.length > 0 %} + writer.writeDiscriminator(Uint8List.fromList({{ instruction.name | snakeCase | upper }}_DISCRIMINATOR)); + {%- endif %} + {%- if fields and fields.length > 0 %} + {% for field in fields %} + {% if field.optional %} + writer.writeU8({{ field.name }} != null ? 1 : 0); + if ({{ field.name }} != null) { + {{ macros.borshWriter(field) | replace(field.name, field.name ~ '!') }} + } + {% else %} + {{ macros.borshWriter(field) }} + {% endif %} + {% endfor %} {%- endif %} - {%- endfor %} - {%- endif %} - return Instruction( - programId: {{ program.name | pascalCase }}Program.programId, - accounts: keys, - data: ByteArray(writer.toBytes()), - ); + return Instruction( + programId: {{ program.name | pascalCase }}Program.programId, + accounts: keys, + data: ByteArray(writer.toBytes()), + ); + } } -} -{# Nested structs (if any) #} - {% for nestedStruct in typeManifest.nestedStructs %} - {{ nestedStruct }} - {% endfor %} - {% endblock %} \ No newline at end of file + {# Nested structs (if any) #} + {% for nestedStruct in typeManifest.nestedStructs %} + {{ nestedStruct }} + {% endfor %} +{% endblock %} \ No newline at end of file From 4d86fca7ea78162b785bd4f67b7bc9c69c481ebc Mon Sep 17 00:00:00 2001 From: ERoydev Date: Mon, 15 Sep 2025 17:09:51 +0300 Subject: [PATCH 18/33] fix: Uncomment test cases --- test/accountsPage.test.ts | 172 +++--- test/definedTypesPage.test.ts | 68 +-- test/types/array.test.ts | 984 +++++++++++++++--------------- test/types/number.test.ts | 1072 ++++++++++++++++----------------- 4 files changed, 1148 insertions(+), 1148 deletions(-) diff --git a/test/accountsPage.test.ts b/test/accountsPage.test.ts index b4f37ee..d6ed984 100644 --- a/test/accountsPage.test.ts +++ b/test/accountsPage.test.ts @@ -1,94 +1,94 @@ -// import { -// accountNode, -// camelCase, -// pdaLinkNode, -// programNode, -// } from '@codama/nodes'; -// import { getFromRenderMap } from '@codama/renderers-core'; -// import { visit } from '@codama/visitors-core'; -// import { test } from 'vitest'; +import { + accountNode, + camelCase, + pdaLinkNode, + programNode, +} from '@codama/nodes'; +import { getFromRenderMap } from '@codama/renderers-core'; +import { visit } from '@codama/visitors-core'; +import { test } from 'vitest'; -// import { getRenderMapVisitor } from '../src'; -// import { codeContains } from './_setup'; +import { getRenderMapVisitor } from '../src'; +import { codeContains } from './_setup'; -// test('it renders Dart account serialization and ownership', () => { -// // Given the following account. -// const node = programNode({ -// accounts: [ -// accountNode({ -// discriminators: [ -// { -// kind: 'fieldDiscriminatorNode', -// name: camelCase('discriminator'), -// offset: 0, -// }, -// ], -// name: 'testAccount', -// pda: pdaLinkNode('testPda'), -// }), -// ], -// name: 'myProgram', -// publicKey: '1111', -// }); +test('it renders Dart account serialization and ownership', () => { + // Given the following account. + const node = programNode({ + accounts: [ + accountNode({ + discriminators: [ + { + kind: 'fieldDiscriminatorNode', + name: camelCase('discriminator'), + offset: 0, + }, + ], + name: 'testAccount', + pda: pdaLinkNode('testPda'), + }), + ], + name: 'myProgram', + publicKey: '1111', + }); -// // When we render it. -// const renderMap = visit(node, getRenderMapVisitor()); + // When we render it. + const renderMap = visit(node, getRenderMapVisitor()); -// // Then we expect Dart serialization and ownership helpers. -// codeContains(getFromRenderMap(renderMap, 'accounts/test_account.dart'), [ -// /class TestAccount\s*{/, -// /static TestAccount fromBorsh\(BinaryReader reader\)/, -// /void toBorsh\(BinaryWriter writer\)/, -// /static TestAccount fromBytes\(Uint8List data\)/, -// /Uint8List toBytes\(\)/, -// /static Future fetch\(/, -// /static Future fetchNullable\(/, -// /throw AccountNotFoundError\(address\);/, -// ]); -// }); + // Then we expect Dart serialization and ownership helpers. + codeContains(getFromRenderMap(renderMap, 'accounts/test_account.dart'), [ + /class TestAccount\s*{/, + /static TestAccount fromBorsh\(BinaryReader reader\)/, + /void toBorsh\(BinaryWriter writer\)/, + /static TestAccount fromBytes\(Uint8List data\)/, + /Uint8List toBytes\(\)/, + /static Future fetch\(/, + /static Future fetchNullable\(/, + /throw AccountNotFoundError\(address\);/, + ]); +}); -// test('it renders fetch functions', () => { -// // Given the following account. -// const node = programNode({ -// accounts: [ -// accountNode({ -// discriminators: [ -// { -// kind: 'fieldDiscriminatorNode', -// // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call -// name: camelCase('discriminator'), -// offset: 0, -// }, -// ], -// name: 'testAccount', -// pda: pdaLinkNode('testPda'), -// }), -// ], -// name: 'myProgram', -// publicKey: '1111', -// }); +test('it renders fetch functions', () => { + // Given the following account. + const node = programNode({ + accounts: [ + accountNode({ + discriminators: [ + { + kind: 'fieldDiscriminatorNode', + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call + name: camelCase('discriminator'), + offset: 0, + }, + ], + name: 'testAccount', + pda: pdaLinkNode('testPda'), + }), + ], + name: 'myProgram', + publicKey: '1111', + }); -// // When we render it. -// const renderMap = visit(node, getRenderMapVisitor()); + // When we render it. + const renderMap = visit(node, getRenderMapVisitor()); -// // Then we expect the following fetch functions to be rendered. -// codeContains(getFromRenderMap(renderMap, 'accounts/test_account.dart'), [ -// /class TestAccount\s*{/, // class declaration -// /const List\s+TEST_ACCOUNT_DISCRIMINATOR\s*=\s*\[.*\];/, // discriminator -// /static TestAccount fromBorsh\(BinaryReader reader\)/, // deserialization -// /void toBorsh\(BinaryWriter writer\)/, // serialization -// /static TestAccount fromBytes\(Uint8List data\)/, // fromBytes method -// /Uint8List toBytes\(\)/, // toBytes method -// /static Future fetch\(/, // fetch method -// /static Future fetchNullable\(/, // fetchNullable method -// /final discriminator = reader\.readDiscriminator\(\);/, // discriminator validation -// /if \(!const ListEquality\(\)\.equals\(discriminator, TEST_ACCOUNT_DISCRIMINATOR\)\)/, // discriminator check -// /throw AccountNotFoundError\(address\);/, // error handling -// /import 'dart:typed_data';/, -// /import 'package:collection\/collection\.dart';/, -// /import 'package:solana\/dto\.dart';/, -// /import 'package:solana\/solana\.dart';/, -// /import '\.\.\/shared\.dart';/, -// ]); -// }); + // Then we expect the following fetch functions to be rendered. + codeContains(getFromRenderMap(renderMap, 'accounts/test_account.dart'), [ + /class TestAccount\s*{/, // class declaration + /const List\s+TEST_ACCOUNT_DISCRIMINATOR\s*=\s*\[.*\];/, // discriminator + /static TestAccount fromBorsh\(BinaryReader reader\)/, // deserialization + /void toBorsh\(BinaryWriter writer\)/, // serialization + /static TestAccount fromBytes\(Uint8List data\)/, // fromBytes method + /Uint8List toBytes\(\)/, // toBytes method + /static Future fetch\(/, // fetch method + /static Future fetchNullable\(/, // fetchNullable method + /final discriminator = reader\.readDiscriminator\(\);/, // discriminator validation + /if \(!const ListEquality\(\)\.equals\(discriminator, TEST_ACCOUNT_DISCRIMINATOR\)\)/, // discriminator check + /throw AccountNotFoundError\(address\);/, // error handling + /import 'dart:typed_data';/, + /import 'package:collection\/collection\.dart';/, + /import 'package:solana\/dto\.dart';/, + /import 'package:solana\/solana\.dart';/, + /import '\.\.\/shared\.dart';/, + ]); +}); diff --git a/test/definedTypesPage.test.ts b/test/definedTypesPage.test.ts index cf07a13..c77185a 100644 --- a/test/definedTypesPage.test.ts +++ b/test/definedTypesPage.test.ts @@ -1,39 +1,39 @@ -// import { definedTypeNode, numberTypeNode, programNode, sizePrefixTypeNode, stringTypeNode, structFieldTypeNode, structTypeNode } from "@codama/nodes"; -// import { getFromRenderMap } from "@codama/renderers-core"; -// import { visit } from "@codama/visitors-core"; -// import { test } from 'vitest'; +import { definedTypeNode, numberTypeNode, programNode, sizePrefixTypeNode, stringTypeNode, structFieldTypeNode, structTypeNode } from "@codama/nodes"; +import { getFromRenderMap } from "@codama/renderers-core"; +import { visit } from "@codama/visitors-core"; +import { test } from 'vitest'; -// import { getRenderMapVisitor } from "../src"; -// import { codeContains } from "./_setup"; +import { getRenderMapVisitor } from "../src"; +import { codeContains } from "./_setup"; -// test('it renders a prefix string on a defined type', () => { -// const node = programNode({ -// definedTypes: [ -// definedTypeNode({ -// name: 'blob', -// type: structTypeNode([ -// structFieldTypeNode({ -// name: 'contentType', -// type: sizePrefixTypeNode(stringTypeNode('utf8'), numberTypeNode('u8')), -// }), -// ]), -// }), -// ], -// name: 'splToken', -// publicKey: 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', -// }); +test('it renders a prefix string on a defined type', () => { + const node = programNode({ + definedTypes: [ + definedTypeNode({ + name: 'blob', + type: structTypeNode([ + structFieldTypeNode({ + name: 'contentType', + type: sizePrefixTypeNode(stringTypeNode('utf8'), numberTypeNode('u8')), + }), + ]), + }), + ], + name: 'splToken', + publicKey: 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA', + }); -// const renderMap = visit(node, getRenderMapVisitor()); + const renderMap = visit(node, getRenderMapVisitor()); -// codeContains(getFromRenderMap(renderMap, 'types/blob.dart'), [ -// /class Blob\s*{/, // class declaration -// /final String content_type;/, // field declaration (matches your output) -// /import '\.\.\/shared\.dart';/, // shared import -// /Generated type definition for Blob/, // doc comment -// /void toBorsh\(BinaryWriter writer\)/, // serialization method -// /writer\.writeString\(content_type\)/, // serialization line -// /static Blob fromBorsh\(BinaryReader reader\)/, // deserialization method -// /content_type:\s*reader\.readString\(\)/, // deserialization line -// ]); -// }); \ No newline at end of file + codeContains(getFromRenderMap(renderMap, 'types/blob.dart'), [ + /class Blob\s*{/, // class declaration + /final String content_type;/, // field declaration (matches your output) + /import '\.\.\/shared\.dart';/, // shared import + /Generated type definition for Blob/, // doc comment + /void toBorsh\(BinaryWriter writer\)/, // serialization method + /writer\.writeString\(content_type\)/, // serialization line + /static Blob fromBorsh\(BinaryReader reader\)/, // deserialization method + /content_type:\s*reader\.readString\(\)/, // deserialization line + ]); +}); \ No newline at end of file diff --git a/test/types/array.test.ts b/test/types/array.test.ts index 1899f75..653ee80 100644 --- a/test/types/array.test.ts +++ b/test/types/array.test.ts @@ -1,518 +1,518 @@ -// import { -// arrayTypeNode, -// definedTypeNode, -// numberTypeNode, -// prefixedCountNode, -// publicKeyTypeNode, -// structFieldTypeNode, -// structTypeNode, -// } from '@codama/nodes'; -// import { getFromRenderMap } from '@codama/renderers-core'; -// import { visit } from '@codama/visitors-core'; -// import { test } from 'vitest'; +import { + arrayTypeNode, + definedTypeNode, + numberTypeNode, + prefixedCountNode, + publicKeyTypeNode, + structFieldTypeNode, + structTypeNode, +} from '@codama/nodes'; +import { getFromRenderMap } from '@codama/renderers-core'; +import { visit } from '@codama/visitors-core'; +import { test } from 'vitest'; -// import { getRenderMapVisitor } from '../../src'; -// import { codeContains, codeDoesNotContains } from '../_setup'; +import { getRenderMapVisitor } from '../../src'; +import { codeContains, codeDoesNotContains } from '../_setup'; -// test('it exports short vecs', () => { -// // Given an array using a shortU16 prefix. -// const node = definedTypeNode({ -// name: 'myShortVec', -// type: arrayTypeNode(publicKeyTypeNode(), prefixedCountNode(numberTypeNode('shortU16'))), -// }); +test('it exports short vecs', () => { + // Given an array using a shortU16 prefix. + const node = definedTypeNode({ + name: 'myShortVec', + type: arrayTypeNode(publicKeyTypeNode(), prefixedCountNode(numberTypeNode('shortU16'))), + }); -// // When we render the array. -// const renderMap = visit(node, getRenderMapVisitor()); -// // Then we expect a Dart class or type for the short vec. -// codeContains(getFromRenderMap(renderMap, 'types/my_short_vec.dart'), [ -// /typedef MyShortVec/, // Dart typedef for the array -// /List;/, // correct Dart type for the array -// /import 'package:solana\/solana.dart';/, // Dart import for public key -// /import 'dart:typed_data';/, -// /import '\.\.\/shared\.dart';/, -// ]); -// codeDoesNotContains(getFromRenderMap(renderMap, 'types/my_short_vec.dart'), [ -// /BorshSerialize/, // Rust-specific, should not appear -// /BorshDeserialize/, // Rust-specific, should not appear -// /^use /m, // Rust import, should not appear -// ]); -// }); + // When we render the array. + const renderMap = visit(node, getRenderMapVisitor()); + // Then we expect a Dart class or type for the short vec. + codeContains(getFromRenderMap(renderMap, 'types/my_short_vec.dart'), [ + /typedef MyShortVec/, // Dart typedef for the array + /List;/, // correct Dart type for the array + /import 'package:solana\/solana.dart';/, // Dart import for public key + /import 'dart:typed_data';/, + /import '\.\.\/shared\.dart';/, + ]); + codeDoesNotContains(getFromRenderMap(renderMap, 'types/my_short_vec.dart'), [ + /BorshSerialize/, // Rust-specific, should not appear + /BorshDeserialize/, // Rust-specific, should not appear + /^use /m, // Rust import, should not appear + ]); +}); -// test('it exports short vecs as struct fields', () => { -// // Given an array using a shortU16 prefix. -// const node = definedTypeNode({ -// name: 'myShortVec', -// type: structTypeNode([ -// structFieldTypeNode({ -// name: 'value', -// type: arrayTypeNode(publicKeyTypeNode(), prefixedCountNode(numberTypeNode('shortU16'))), -// }), -// ]), -// }); +test('it exports short vecs as struct fields', () => { + // Given an array using a shortU16 prefix. + const node = definedTypeNode({ + name: 'myShortVec', + type: structTypeNode([ + structFieldTypeNode({ + name: 'value', + type: arrayTypeNode(publicKeyTypeNode(), prefixedCountNode(numberTypeNode('shortU16'))), + }), + ]), + }); -// // When we render the array. -// const renderMap = visit(node, getRenderMapVisitor()); + // When we render the array. + const renderMap = visit(node, getRenderMapVisitor()); -// // Then we expect a short vec to be exported as a struct field. -// codeContains(getFromRenderMap(renderMap, 'types/my_short_vec.dart'), [ -// /class MyShortVec /, // class declaration -// /final List value;/, // field declaration -// /MyShortVec\(\s*{\s*required this\.value,\s*}\s*\);/, // constructor -// /extension MyShortVecBorsh on MyShortVec/, // extension for serialization -// /void toBorsh\(BinaryWriter writer\)/, // serialization method -// /static MyShortVec fromBorsh\(BinaryReader reader\)/, // deserialization method -// /import 'package:solana\/solana.dart';/, // solana import -// /import 'dart:typed_data';/, // typed_data import -// /import '\.\.\/shared\.dart';/, // shared import -// ]); -// }); + // Then we expect a short vec to be exported as a struct field. + codeContains(getFromRenderMap(renderMap, 'types/my_short_vec.dart'), [ + /class MyShortVec /, // class declaration + /final List value;/, // field declaration + /MyShortVec\(\s*{\s*required this\.value,\s*}\s*\);/, // constructor + /extension MyShortVecBorsh on MyShortVec/, // extension for serialization + /void toBorsh\(BinaryWriter writer\)/, // serialization method + /static MyShortVec fromBorsh\(BinaryReader reader\)/, // deserialization method + /import 'package:solana\/solana.dart';/, // solana import + /import 'dart:typed_data';/, // typed_data import + /import '\.\.\/shared\.dart';/, // shared import + ]); +}); -// test('it exports u8 numbers', () => { -// const node = definedTypeNode({ -// name: 'myU8', -// type: numberTypeNode('u8'), -// }); -// const renderMap = visit(node, getRenderMapVisitor()); -// codeContains(getFromRenderMap(renderMap, 'types/my_u8.dart'), [ -// /typedef MyU8 = int.*u8/, -// /import 'dart:typed_data';/, -// /import '\.\.\/shared\.dart';/, -// /Generated type definition for MyU8/, -// ]); -// codeDoesNotContains(getFromRenderMap(renderMap, 'types/my_u8.dart'), [ -// /BorshSerialize/, -// /BorshDeserialize/, -// /^use /m, -// ]); -// }); +test('it exports u8 numbers', () => { + const node = definedTypeNode({ + name: 'myU8', + type: numberTypeNode('u8'), + }); + const renderMap = visit(node, getRenderMapVisitor()); + codeContains(getFromRenderMap(renderMap, 'types/my_u8.dart'), [ + /typedef MyU8 = int.*u8/, + /import 'dart:typed_data';/, + /import '\.\.\/shared\.dart';/, + /Generated type definition for MyU8/, + ]); + codeDoesNotContains(getFromRenderMap(renderMap, 'types/my_u8.dart'), [ + /BorshSerialize/, + /BorshDeserialize/, + /^use /m, + ]); +}); -// test('it exports u8 numbers as struct fields', () => { -// const node = definedTypeNode({ -// name: 'myU8', -// type: structTypeNode([ -// structFieldTypeNode({ -// name: 'value', -// type: numberTypeNode('u8'), -// }), -// ]), -// }); -// const renderMap = visit(node, getRenderMapVisitor()); -// codeContains(getFromRenderMap(renderMap, 'types/my_u8.dart'), [ -// /class MyU8 /, -// /final int.*u8.*value;/, -// /required this\.value,/, -// /extension MyU8Borsh on MyU8/, -// /void toBorsh\(BinaryWriter writer\)/, -// /writer\.writeU8\(value\)/, // serialization line -// /static MyU8 fromBorsh\(BinaryReader reader\)/, -// /reader\.readU8\(\)/, // deserialization line -// /import 'dart:typed_data';/, -// /import '\.\.\/shared\.dart';/, -// /Generated type definition for MyU8/, // doc comment -// ]); -// }); +test('it exports u8 numbers as struct fields', () => { + const node = definedTypeNode({ + name: 'myU8', + type: structTypeNode([ + structFieldTypeNode({ + name: 'value', + type: numberTypeNode('u8'), + }), + ]), + }); + const renderMap = visit(node, getRenderMapVisitor()); + codeContains(getFromRenderMap(renderMap, 'types/my_u8.dart'), [ + /class MyU8 /, + /final int.*u8.*value;/, + /required this\.value,/, + /extension MyU8Borsh on MyU8/, + /void toBorsh\(BinaryWriter writer\)/, + /writer\.writeU8\(value\)/, // serialization line + /static MyU8 fromBorsh\(BinaryReader reader\)/, + /reader\.readU8\(\)/, // deserialization line + /import 'dart:typed_data';/, + /import '\.\.\/shared\.dart';/, + /Generated type definition for MyU8/, // doc comment + ]); +}); -// test('it exports i8 numbers', () => { -// const node = definedTypeNode({ -// name: 'myI8', -// type: numberTypeNode('i8'), -// }); -// const renderMap = visit(node, getRenderMapVisitor()); -// codeContains(getFromRenderMap(renderMap, 'types/my_i8.dart'), [ -// /typedef MyI8 = int.*i8/, -// /import 'dart:typed_data';/, -// /import '\.\.\/shared\.dart';/, -// /Generated type definition for MyI8/, -// ]); -// codeDoesNotContains(getFromRenderMap(renderMap, 'types/my_i8.dart'), [ -// /BorshSerialize/, -// /BorshDeserialize/, -// /^use /m, -// ]); -// }); +test('it exports i8 numbers', () => { + const node = definedTypeNode({ + name: 'myI8', + type: numberTypeNode('i8'), + }); + const renderMap = visit(node, getRenderMapVisitor()); + codeContains(getFromRenderMap(renderMap, 'types/my_i8.dart'), [ + /typedef MyI8 = int.*i8/, + /import 'dart:typed_data';/, + /import '\.\.\/shared\.dart';/, + /Generated type definition for MyI8/, + ]); + codeDoesNotContains(getFromRenderMap(renderMap, 'types/my_i8.dart'), [ + /BorshSerialize/, + /BorshDeserialize/, + /^use /m, + ]); +}); -// test('it exports i8 numbers as struct fields', () => { -// const node = definedTypeNode({ -// name: 'myI8', -// type: structTypeNode([ -// structFieldTypeNode({ -// name: 'value', -// type: numberTypeNode('i8'), -// }), -// ]), -// }); -// const renderMap = visit(node, getRenderMapVisitor()); -// codeContains(getFromRenderMap(renderMap, 'types/my_i8.dart'), [ -// /class MyI8 /, -// /final int.*i8.*value;/, -// /required this\.value,/, -// /extension MyI8Borsh on MyI8/, -// /void toBorsh\(BinaryWriter writer\)/, -// /writer\.writeI8\(value\)/, -// /static MyI8 fromBorsh\(BinaryReader reader\)/, -// /reader\.readI8\(\)/, -// /import 'dart:typed_data';/, -// /import '\.\.\/shared\.dart';/, -// /Generated type definition for MyI8/, -// ]); -// }); +test('it exports i8 numbers as struct fields', () => { + const node = definedTypeNode({ + name: 'myI8', + type: structTypeNode([ + structFieldTypeNode({ + name: 'value', + type: numberTypeNode('i8'), + }), + ]), + }); + const renderMap = visit(node, getRenderMapVisitor()); + codeContains(getFromRenderMap(renderMap, 'types/my_i8.dart'), [ + /class MyI8 /, + /final int.*i8.*value;/, + /required this\.value,/, + /extension MyI8Borsh on MyI8/, + /void toBorsh\(BinaryWriter writer\)/, + /writer\.writeI8\(value\)/, + /static MyI8 fromBorsh\(BinaryReader reader\)/, + /reader\.readI8\(\)/, + /import 'dart:typed_data';/, + /import '\.\.\/shared\.dart';/, + /Generated type definition for MyI8/, + ]); +}); -// test('it exports u16 numbers', () => { -// const node = definedTypeNode({ -// name: 'myU16', -// type: numberTypeNode('u16'), -// }); -// const renderMap = visit(node, getRenderMapVisitor()); -// codeContains(getFromRenderMap(renderMap, 'types/my_u16.dart'), [ -// /typedef MyU16 = int.*u16/, -// /import 'dart:typed_data';/, -// /import '\.\.\/shared\.dart';/, -// /Generated type definition for MyU16/, -// ]); -// codeDoesNotContains(getFromRenderMap(renderMap, 'types/my_u16.dart'), [ -// /BorshSerialize/, -// /BorshDeserialize/, -// /^use /m, -// ]); -// }); +test('it exports u16 numbers', () => { + const node = definedTypeNode({ + name: 'myU16', + type: numberTypeNode('u16'), + }); + const renderMap = visit(node, getRenderMapVisitor()); + codeContains(getFromRenderMap(renderMap, 'types/my_u16.dart'), [ + /typedef MyU16 = int.*u16/, + /import 'dart:typed_data';/, + /import '\.\.\/shared\.dart';/, + /Generated type definition for MyU16/, + ]); + codeDoesNotContains(getFromRenderMap(renderMap, 'types/my_u16.dart'), [ + /BorshSerialize/, + /BorshDeserialize/, + /^use /m, + ]); +}); -// test('it exports u16 numbers as struct fields', () => { -// const node = definedTypeNode({ -// name: 'myU16', -// type: structTypeNode([ -// structFieldTypeNode({ -// name: 'value', -// type: numberTypeNode('u16'), -// }), -// ]), -// }); -// const renderMap = visit(node, getRenderMapVisitor()); -// codeContains(getFromRenderMap(renderMap, 'types/my_u16.dart'), [ -// /class MyU16 /, -// /final int.*u16.*value;/, -// /required this\.value,/, -// /extension MyU16Borsh on MyU16/, -// /void toBorsh\(BinaryWriter writer\)/, -// /writer\.writeU16\(value\)/, -// /static MyU16 fromBorsh\(BinaryReader reader\)/, -// /reader\.readU16\(\)/, -// /import 'dart:typed_data';/, -// /import '\.\.\/shared\.dart';/, -// /Generated type definition for MyU16/, -// ]); -// }); +test('it exports u16 numbers as struct fields', () => { + const node = definedTypeNode({ + name: 'myU16', + type: structTypeNode([ + structFieldTypeNode({ + name: 'value', + type: numberTypeNode('u16'), + }), + ]), + }); + const renderMap = visit(node, getRenderMapVisitor()); + codeContains(getFromRenderMap(renderMap, 'types/my_u16.dart'), [ + /class MyU16 /, + /final int.*u16.*value;/, + /required this\.value,/, + /extension MyU16Borsh on MyU16/, + /void toBorsh\(BinaryWriter writer\)/, + /writer\.writeU16\(value\)/, + /static MyU16 fromBorsh\(BinaryReader reader\)/, + /reader\.readU16\(\)/, + /import 'dart:typed_data';/, + /import '\.\.\/shared\.dart';/, + /Generated type definition for MyU16/, + ]); +}); -// test('it exports i16 numbers', () => { -// const node = definedTypeNode({ -// name: 'myI16', -// type: numberTypeNode('i16'), -// }); -// const renderMap = visit(node, getRenderMapVisitor()); -// codeContains(getFromRenderMap(renderMap, 'types/my_i16.dart'), [ -// /typedef MyI16 = int.*i16/, -// /import 'dart:typed_data';/, -// /import '\.\.\/shared\.dart';/, -// /Generated type definition for MyI16/, -// ]); -// codeDoesNotContains(getFromRenderMap(renderMap, 'types/my_i16.dart'), [ -// /BorshSerialize/, -// /BorshDeserialize/, -// /^use /m, -// ]); -// }); +test('it exports i16 numbers', () => { + const node = definedTypeNode({ + name: 'myI16', + type: numberTypeNode('i16'), + }); + const renderMap = visit(node, getRenderMapVisitor()); + codeContains(getFromRenderMap(renderMap, 'types/my_i16.dart'), [ + /typedef MyI16 = int.*i16/, + /import 'dart:typed_data';/, + /import '\.\.\/shared\.dart';/, + /Generated type definition for MyI16/, + ]); + codeDoesNotContains(getFromRenderMap(renderMap, 'types/my_i16.dart'), [ + /BorshSerialize/, + /BorshDeserialize/, + /^use /m, + ]); +}); -// test('it exports i16 numbers as struct fields', () => { -// const node = definedTypeNode({ -// name: 'myI16', -// type: structTypeNode([ -// structFieldTypeNode({ -// name: 'value', -// type: numberTypeNode('i16'), -// }), -// ]), -// }); -// const renderMap = visit(node, getRenderMapVisitor()); -// codeContains(getFromRenderMap(renderMap, 'types/my_i16.dart'), [ -// /class MyI16 /, -// /final int.*i16.*value;/, -// /required this\.value,/, -// /extension MyI16Borsh on MyI16/, -// /void toBorsh\(BinaryWriter writer\)/, -// /writer\.writeI16\(value\)/, -// /static MyI16 fromBorsh\(BinaryReader reader\)/, -// /reader\.readI16\(\)/, -// /import 'dart:typed_data';/, -// /import '\.\.\/shared\.dart';/, -// /Generated type definition for MyI16/, -// ]); -// }); +test('it exports i16 numbers as struct fields', () => { + const node = definedTypeNode({ + name: 'myI16', + type: structTypeNode([ + structFieldTypeNode({ + name: 'value', + type: numberTypeNode('i16'), + }), + ]), + }); + const renderMap = visit(node, getRenderMapVisitor()); + codeContains(getFromRenderMap(renderMap, 'types/my_i16.dart'), [ + /class MyI16 /, + /final int.*i16.*value;/, + /required this\.value,/, + /extension MyI16Borsh on MyI16/, + /void toBorsh\(BinaryWriter writer\)/, + /writer\.writeI16\(value\)/, + /static MyI16 fromBorsh\(BinaryReader reader\)/, + /reader\.readI16\(\)/, + /import 'dart:typed_data';/, + /import '\.\.\/shared\.dart';/, + /Generated type definition for MyI16/, + ]); +}); -// test('it exports u32 numbers', () => { -// const node = definedTypeNode({ -// name: 'myU32', -// type: numberTypeNode('u32'), -// }); -// const renderMap = visit(node, getRenderMapVisitor()); -// codeContains(getFromRenderMap(renderMap, 'types/my_u32.dart'), [ -// /typedef MyU32 = int.*u32/, -// /import 'dart:typed_data';/, -// /import '\.\.\/shared\.dart';/, -// /Generated type definition for MyU32/, -// ]); -// codeDoesNotContains(getFromRenderMap(renderMap, 'types/my_u32.dart'), [ -// /BorshSerialize/, -// /BorshDeserialize/, -// /^use /m, -// ]); -// }); +test('it exports u32 numbers', () => { + const node = definedTypeNode({ + name: 'myU32', + type: numberTypeNode('u32'), + }); + const renderMap = visit(node, getRenderMapVisitor()); + codeContains(getFromRenderMap(renderMap, 'types/my_u32.dart'), [ + /typedef MyU32 = int.*u32/, + /import 'dart:typed_data';/, + /import '\.\.\/shared\.dart';/, + /Generated type definition for MyU32/, + ]); + codeDoesNotContains(getFromRenderMap(renderMap, 'types/my_u32.dart'), [ + /BorshSerialize/, + /BorshDeserialize/, + /^use /m, + ]); +}); -// test('it exports u32 numbers as struct fields', () => { -// const node = definedTypeNode({ -// name: 'myU32', -// type: structTypeNode([ -// structFieldTypeNode({ -// name: 'value', -// type: numberTypeNode('u32'), -// }), -// ]), -// }); -// const renderMap = visit(node, getRenderMapVisitor()); -// codeContains(getFromRenderMap(renderMap, 'types/my_u32.dart'), [ -// /class MyU32 /, -// /final int.*u32.*value;/, -// /required this\.value,/, -// /extension MyU32Borsh on MyU32/, -// /void toBorsh\(BinaryWriter writer\)/, -// /writer\.writeU32\(value\)/, -// /static MyU32 fromBorsh\(BinaryReader reader\)/, -// /reader\.readU32\(\)/, -// /import 'dart:typed_data';/, -// /import '\.\.\/shared\.dart';/, -// /Generated type definition for MyU32/, -// ]); -// }); +test('it exports u32 numbers as struct fields', () => { + const node = definedTypeNode({ + name: 'myU32', + type: structTypeNode([ + structFieldTypeNode({ + name: 'value', + type: numberTypeNode('u32'), + }), + ]), + }); + const renderMap = visit(node, getRenderMapVisitor()); + codeContains(getFromRenderMap(renderMap, 'types/my_u32.dart'), [ + /class MyU32 /, + /final int.*u32.*value;/, + /required this\.value,/, + /extension MyU32Borsh on MyU32/, + /void toBorsh\(BinaryWriter writer\)/, + /writer\.writeU32\(value\)/, + /static MyU32 fromBorsh\(BinaryReader reader\)/, + /reader\.readU32\(\)/, + /import 'dart:typed_data';/, + /import '\.\.\/shared\.dart';/, + /Generated type definition for MyU32/, + ]); +}); -// test('it exports i32 numbers', () => { -// const node = definedTypeNode({ -// name: 'myI32', -// type: numberTypeNode('i32'), -// }); -// const renderMap = visit(node, getRenderMapVisitor()); -// codeContains(getFromRenderMap(renderMap, 'types/my_i32.dart'), [ -// /typedef MyI32 = int.*i32/, -// /import 'dart:typed_data';/, -// /import '\.\.\/shared\.dart';/, -// /Generated type definition for MyI32/, -// ]); -// codeDoesNotContains(getFromRenderMap(renderMap, 'types/my_i32.dart'), [ -// /BorshSerialize/, -// /BorshDeserialize/, -// /^use /m, -// ]); -// }); +test('it exports i32 numbers', () => { + const node = definedTypeNode({ + name: 'myI32', + type: numberTypeNode('i32'), + }); + const renderMap = visit(node, getRenderMapVisitor()); + codeContains(getFromRenderMap(renderMap, 'types/my_i32.dart'), [ + /typedef MyI32 = int.*i32/, + /import 'dart:typed_data';/, + /import '\.\.\/shared\.dart';/, + /Generated type definition for MyI32/, + ]); + codeDoesNotContains(getFromRenderMap(renderMap, 'types/my_i32.dart'), [ + /BorshSerialize/, + /BorshDeserialize/, + /^use /m, + ]); +}); -// test('it exports i32 numbers as struct fields', () => { -// const node = definedTypeNode({ -// name: 'myI32', -// type: structTypeNode([ -// structFieldTypeNode({ -// name: 'value', -// type: numberTypeNode('i32'), -// }), -// ]), -// }); -// const renderMap = visit(node, getRenderMapVisitor()); -// codeContains(getFromRenderMap(renderMap, 'types/my_i32.dart'), [ -// /class MyI32 /, -// /final int.*i32.*value;/, -// /required this\.value,/, -// /extension MyI32Borsh on MyI32/, -// /void toBorsh\(BinaryWriter writer\)/, -// /writer\.writeI32\(value\)/, -// /static MyI32 fromBorsh\(BinaryReader reader\)/, -// /reader\.readI32\(\)/, -// /import 'dart:typed_data';/, -// /import '\.\.\/shared\.dart';/, -// /Generated type definition for MyI32/, -// ]); -// }); +test('it exports i32 numbers as struct fields', () => { + const node = definedTypeNode({ + name: 'myI32', + type: structTypeNode([ + structFieldTypeNode({ + name: 'value', + type: numberTypeNode('i32'), + }), + ]), + }); + const renderMap = visit(node, getRenderMapVisitor()); + codeContains(getFromRenderMap(renderMap, 'types/my_i32.dart'), [ + /class MyI32 /, + /final int.*i32.*value;/, + /required this\.value,/, + /extension MyI32Borsh on MyI32/, + /void toBorsh\(BinaryWriter writer\)/, + /writer\.writeI32\(value\)/, + /static MyI32 fromBorsh\(BinaryReader reader\)/, + /reader\.readI32\(\)/, + /import 'dart:typed_data';/, + /import '\.\.\/shared\.dart';/, + /Generated type definition for MyI32/, + ]); +}); -// test('it exports u64 numbers', () => { -// const node = definedTypeNode({ -// name: 'myU64', -// type: numberTypeNode('u64'), -// }); -// const renderMap = visit(node, getRenderMapVisitor()); -// codeContains(getFromRenderMap(renderMap, 'types/my_u64.dart'), [ -// /typedef MyU64 = BigInt.*u64/, -// /import 'dart:typed_data';/, -// /import '\.\.\/shared\.dart';/, -// /Generated type definition for MyU64/, -// ]); -// codeDoesNotContains(getFromRenderMap(renderMap, 'types/my_u64.dart'), [ -// /BorshSerialize/, -// /BorshDeserialize/, -// /^use /m, -// ]); -// }); +test('it exports u64 numbers', () => { + const node = definedTypeNode({ + name: 'myU64', + type: numberTypeNode('u64'), + }); + const renderMap = visit(node, getRenderMapVisitor()); + codeContains(getFromRenderMap(renderMap, 'types/my_u64.dart'), [ + /typedef MyU64 = BigInt.*u64/, + /import 'dart:typed_data';/, + /import '\.\.\/shared\.dart';/, + /Generated type definition for MyU64/, + ]); + codeDoesNotContains(getFromRenderMap(renderMap, 'types/my_u64.dart'), [ + /BorshSerialize/, + /BorshDeserialize/, + /^use /m, + ]); +}); -// test('it exports u64 numbers as struct fields', () => { -// const node = definedTypeNode({ -// name: 'myU64', -// type: structTypeNode([ -// structFieldTypeNode({ -// name: 'value', -// type: numberTypeNode('u64'), -// }), -// ]), -// }); -// const renderMap = visit(node, getRenderMapVisitor()); -// codeContains(getFromRenderMap(renderMap, 'types/my_u64.dart'), [ -// /class MyU64 /, -// /final BigInt.*u64.*value;/, -// /required this\.value,/, -// /extension MyU64Borsh on MyU64/, -// /void toBorsh\(BinaryWriter writer\)/, -// /writer\.writeU64\(value\)/, -// /static MyU64 fromBorsh\(BinaryReader reader\)/, -// /reader\.readU64\(\)/, -// /import 'dart:typed_data';/, -// /import '\.\.\/shared\.dart';/, -// /Generated type definition for MyU64/, -// ]); -// }); +test('it exports u64 numbers as struct fields', () => { + const node = definedTypeNode({ + name: 'myU64', + type: structTypeNode([ + structFieldTypeNode({ + name: 'value', + type: numberTypeNode('u64'), + }), + ]), + }); + const renderMap = visit(node, getRenderMapVisitor()); + codeContains(getFromRenderMap(renderMap, 'types/my_u64.dart'), [ + /class MyU64 /, + /final BigInt.*u64.*value;/, + /required this\.value,/, + /extension MyU64Borsh on MyU64/, + /void toBorsh\(BinaryWriter writer\)/, + /writer\.writeU64\(value\)/, + /static MyU64 fromBorsh\(BinaryReader reader\)/, + /reader\.readU64\(\)/, + /import 'dart:typed_data';/, + /import '\.\.\/shared\.dart';/, + /Generated type definition for MyU64/, + ]); +}); -// test('it exports i64 numbers', () => { -// const node = definedTypeNode({ -// name: 'myI64', -// type: numberTypeNode('i64'), -// }); -// const renderMap = visit(node, getRenderMapVisitor()); -// codeContains(getFromRenderMap(renderMap, 'types/my_i64.dart'), [ -// /typedef MyI64 = BigInt.*i64/, -// /import 'dart:typed_data';/, -// /import '\.\.\/shared\.dart';/, -// /Generated type definition for MyI64/, -// ]); -// codeDoesNotContains(getFromRenderMap(renderMap, 'types/my_i64.dart'), [ -// /BorshSerialize/, -// /BorshDeserialize/, -// /^use /m, -// ]); -// }); +test('it exports i64 numbers', () => { + const node = definedTypeNode({ + name: 'myI64', + type: numberTypeNode('i64'), + }); + const renderMap = visit(node, getRenderMapVisitor()); + codeContains(getFromRenderMap(renderMap, 'types/my_i64.dart'), [ + /typedef MyI64 = BigInt.*i64/, + /import 'dart:typed_data';/, + /import '\.\.\/shared\.dart';/, + /Generated type definition for MyI64/, + ]); + codeDoesNotContains(getFromRenderMap(renderMap, 'types/my_i64.dart'), [ + /BorshSerialize/, + /BorshDeserialize/, + /^use /m, + ]); +}); -// test('it exports i64 numbers as struct fields', () => { -// const node = definedTypeNode({ -// name: 'myI64', -// type: structTypeNode([ -// structFieldTypeNode({ -// name: 'value', -// type: numberTypeNode('i64'), -// }), -// ]), -// }); -// const renderMap = visit(node, getRenderMapVisitor()); -// codeContains(getFromRenderMap(renderMap, 'types/my_i64.dart'), [ -// /class MyI64 /, -// /final BigInt.*i64.*value;/, -// /required this\.value,/, -// /extension MyI64Borsh on MyI64/, -// /void toBorsh\(BinaryWriter writer\)/, -// /writer\.writeI64\(value\)/, -// /static MyI64 fromBorsh\(BinaryReader reader\)/, -// /reader\.readI64\(\)/, -// /import 'dart:typed_data';/, -// /import '\.\.\/shared\.dart';/, -// /Generated type definition for MyI64/, -// ]); -// }); +test('it exports i64 numbers as struct fields', () => { + const node = definedTypeNode({ + name: 'myI64', + type: structTypeNode([ + structFieldTypeNode({ + name: 'value', + type: numberTypeNode('i64'), + }), + ]), + }); + const renderMap = visit(node, getRenderMapVisitor()); + codeContains(getFromRenderMap(renderMap, 'types/my_i64.dart'), [ + /class MyI64 /, + /final BigInt.*i64.*value;/, + /required this\.value,/, + /extension MyI64Borsh on MyI64/, + /void toBorsh\(BinaryWriter writer\)/, + /writer\.writeI64\(value\)/, + /static MyI64 fromBorsh\(BinaryReader reader\)/, + /reader\.readI64\(\)/, + /import 'dart:typed_data';/, + /import '\.\.\/shared\.dart';/, + /Generated type definition for MyI64/, + ]); +}); -// test('it exports u128 numbers', () => { -// const node = definedTypeNode({ -// name: 'myU128', -// type: numberTypeNode('u128'), -// }); -// const renderMap = visit(node, getRenderMapVisitor()); -// codeContains(getFromRenderMap(renderMap, 'types/my_u128.dart'), [ -// /typedef MyU128 = BigInt.*u128/, -// /import 'dart:typed_data';/, -// /import '\.\.\/shared\.dart';/, -// /Generated type definition for MyU128/, -// ]); -// codeDoesNotContains(getFromRenderMap(renderMap, 'types/my_u128.dart'), [ -// /BorshSerialize/, -// /BorshDeserialize/, -// /^use /m, -// ]); -// }); +test('it exports u128 numbers', () => { + const node = definedTypeNode({ + name: 'myU128', + type: numberTypeNode('u128'), + }); + const renderMap = visit(node, getRenderMapVisitor()); + codeContains(getFromRenderMap(renderMap, 'types/my_u128.dart'), [ + /typedef MyU128 = BigInt.*u128/, + /import 'dart:typed_data';/, + /import '\.\.\/shared\.dart';/, + /Generated type definition for MyU128/, + ]); + codeDoesNotContains(getFromRenderMap(renderMap, 'types/my_u128.dart'), [ + /BorshSerialize/, + /BorshDeserialize/, + /^use /m, + ]); +}); -// test('it exports u128 numbers as struct fields', () => { -// const node = definedTypeNode({ -// name: 'myU128', -// type: structTypeNode([ -// structFieldTypeNode({ -// name: 'value', -// type: numberTypeNode('u128'), -// }), -// ]), -// }); -// const renderMap = visit(node, getRenderMapVisitor()); -// codeContains(getFromRenderMap(renderMap, 'types/my_u128.dart'), [ -// /class MyU128 /, -// /final BigInt.*u128.*value;/, -// /required this\.value,/, -// /extension MyU128Borsh on MyU128/, -// /void toBorsh\(BinaryWriter writer\)/, -// /writer\.writeBigInt\(value\)/, -// /static MyU128 fromBorsh\(BinaryReader reader\)/, -// /reader\.readBigInt\(\)/, -// /import 'dart:typed_data';/, -// /import '\.\.\/shared\.dart';/, -// /Generated type definition for MyU128/, -// ]); -// }); +test('it exports u128 numbers as struct fields', () => { + const node = definedTypeNode({ + name: 'myU128', + type: structTypeNode([ + structFieldTypeNode({ + name: 'value', + type: numberTypeNode('u128'), + }), + ]), + }); + const renderMap = visit(node, getRenderMapVisitor()); + codeContains(getFromRenderMap(renderMap, 'types/my_u128.dart'), [ + /class MyU128 /, + /final BigInt.*u128.*value;/, + /required this\.value,/, + /extension MyU128Borsh on MyU128/, + /void toBorsh\(BinaryWriter writer\)/, + /writer\.writeBigInt\(value\)/, + /static MyU128 fromBorsh\(BinaryReader reader\)/, + /reader\.readBigInt\(\)/, + /import 'dart:typed_data';/, + /import '\.\.\/shared\.dart';/, + /Generated type definition for MyU128/, + ]); +}); -// test('it exports u128 numbers', () => { -// const node = definedTypeNode({ -// name: 'myU128', -// type: numberTypeNode('u128'), -// }); -// const renderMap = visit(node, getRenderMapVisitor()); -// codeContains(getFromRenderMap(renderMap, 'types/my_u128.dart'), [ -// /typedef MyU128 = BigInt.*u128/, -// /import 'dart:typed_data';/, -// /import '\.\.\/shared\.dart';/, -// /Generated type definition for MyU128/, -// ]); -// codeDoesNotContains(getFromRenderMap(renderMap, 'types/my_u128.dart'), [ -// /BorshSerialize/, -// /BorshDeserialize/, -// /^use /m, -// ]); -// }); +test('it exports u128 numbers', () => { + const node = definedTypeNode({ + name: 'myU128', + type: numberTypeNode('u128'), + }); + const renderMap = visit(node, getRenderMapVisitor()); + codeContains(getFromRenderMap(renderMap, 'types/my_u128.dart'), [ + /typedef MyU128 = BigInt.*u128/, + /import 'dart:typed_data';/, + /import '\.\.\/shared\.dart';/, + /Generated type definition for MyU128/, + ]); + codeDoesNotContains(getFromRenderMap(renderMap, 'types/my_u128.dart'), [ + /BorshSerialize/, + /BorshDeserialize/, + /^use /m, + ]); +}); -// test('it exports u128 numbers as struct fields', () => { -// const node = definedTypeNode({ -// name: 'myU128', -// type: structTypeNode([ -// structFieldTypeNode({ -// name: 'value', -// type: numberTypeNode('u128'), -// }), -// ]), -// }); -// const renderMap = visit(node, getRenderMapVisitor()); -// codeContains(getFromRenderMap(renderMap, 'types/my_u128.dart'), [ -// /class MyU128 /, -// /final BigInt.*u128.*value;/, -// /required this\.value,/, -// /extension MyU128Borsh on MyU128/, -// /void toBorsh\(BinaryWriter writer\)/, -// /writer\.writeBigInt\(value\)/, -// /static MyU128 fromBorsh\(BinaryReader reader\)/, -// /reader\.readBigInt\(\)/, -// /import 'dart:typed_data';/, -// /import '\.\.\/shared\.dart';/, -// /Generated type definition for MyU128/, -// ]); -// }); \ No newline at end of file +test('it exports u128 numbers as struct fields', () => { + const node = definedTypeNode({ + name: 'myU128', + type: structTypeNode([ + structFieldTypeNode({ + name: 'value', + type: numberTypeNode('u128'), + }), + ]), + }); + const renderMap = visit(node, getRenderMapVisitor()); + codeContains(getFromRenderMap(renderMap, 'types/my_u128.dart'), [ + /class MyU128 /, + /final BigInt.*u128.*value;/, + /required this\.value,/, + /extension MyU128Borsh on MyU128/, + /void toBorsh\(BinaryWriter writer\)/, + /writer\.writeBigInt\(value\)/, + /static MyU128 fromBorsh\(BinaryReader reader\)/, + /reader\.readBigInt\(\)/, + /import 'dart:typed_data';/, + /import '\.\.\/shared\.dart';/, + /Generated type definition for MyU128/, + ]); +}); \ No newline at end of file diff --git a/test/types/number.test.ts b/test/types/number.test.ts index 02cfc17..08e0943 100644 --- a/test/types/number.test.ts +++ b/test/types/number.test.ts @@ -1,536 +1,536 @@ -// import { definedTypeNode, numberTypeNode, structFieldTypeNode, structTypeNode } from '@codama/nodes'; -// import { getFromRenderMap } from '@codama/renderers-core'; -// import { visit } from '@codama/visitors-core'; -// import { test } from 'vitest'; - -// import { getRenderMapVisitor } from '../../src'; -// import { codeContains, codeDoesNotContains } from '../_setup'; - -// test('it exports short u16 numbers', () => { -// // Given a shortU16 number. -// const node = definedTypeNode({ -// name: 'myShortU16', -// type: numberTypeNode('shortU16'), -// }); - -// // When we render the number. -// const renderMap = visit(node, getRenderMapVisitor()); - -// // Then we expect a short u16 to be exported. -// codeContains(getFromRenderMap(renderMap, 'types/my_short_u16.dart'), [ -// /typedef MyShortU16 = int.*shortU16/, // Dart typedef with comment -// /import 'dart:typed_data';/, // Dart import -// /import '\.\.\/shared\.dart';/, // Dart import -// /Generated type definition for MyShortU16/, // doc comment -// ]); - -// codeDoesNotContains(getFromRenderMap(renderMap, 'types/my_short_u16.dart'), [ -// /BorshSerialize/, // Rust-specific, should not appear -// /BorshDeserialize/, // Rust-specific, should not appear -// /^use /m, // Rust import, should not appear -// ]); -// }); - -// test('it exports short u16 numbers as struct fields', () => { -// // Given a shortU16 number. -// const node = definedTypeNode({ -// name: 'myShortU16', -// type: structTypeNode([structFieldTypeNode({ name: 'value', type: numberTypeNode('shortU16') })]), -// }); - -// // When we render the number. -// const renderMap = visit(node, getRenderMapVisitor()); - -// // Then we expect a short u16 to be exported as a struct field. -// codeContains(getFromRenderMap(renderMap, 'types/my_short_u16.dart'), [ -// /class MyShortU16 /, // class declaration -// /final int.*shortU16.*value;/, // field declaration with type comment -// /MyShortU16\(\s*{\s*required this\.value,\s*}\s*\);/, // constructor -// /extension MyShortU16Borsh on MyShortU16/, // extension for serialization -// /void toBorsh\(BinaryWriter writer\)/, // serialization method -// /static MyShortU16 fromBorsh\(BinaryReader reader\)/, // deserialization method -// /throw Exception\('Unsupported number format: shortU16'\);/, // error for unsupported format -// /import 'dart:typed_data';/, // Dart import -// /import '\.\.\/shared\.dart';/, // shared import -// /Generated type definition for MyShortU16/, // doc comment -// ]); -// }); - -// test('it exports u8 numbers', () => { -// // Given a u8 number. -// const node = definedTypeNode({ -// name: 'myU8', -// type: numberTypeNode('u8'), -// }); - -// // When we render the number. -// const renderMap = visit(node, getRenderMapVisitor()); - -// // Then we expect a u8 to be exported. -// codeContains(getFromRenderMap(renderMap, 'types/my_u8.dart'), [ -// /typedef MyU8 = int.*u8/, // Dart typedef with comment -// /import 'dart:typed_data';/, // Dart import -// /import '\.\.\/shared\.dart';/, // Dart import -// /Generated type definition for MyU8/, // doc comment -// ]); - -// codeDoesNotContains(getFromRenderMap(renderMap, 'types/my_u8.dart'), [ -// /BorshSerialize/, // Rust-specific, should not appear -// /BorshDeserialize/, // Rust-specific, should not appear -// /^use /m, // Rust import, should not appear -// ]); -// }); - -// test('it exports u8 numbers as struct fields', () => { -// // Given a u8 number. -// const node = definedTypeNode({ -// name: 'myU8', -// type: structTypeNode([structFieldTypeNode({ name: 'value', type: numberTypeNode('u8') })]), -// }); - -// // When we render the number. -// const renderMap = visit(node, getRenderMapVisitor()); - -// // Then we expect a u8 to be exported as a struct field. -// codeContains(getFromRenderMap(renderMap, 'types/my_u8.dart'), [ -// /class MyU8 /, // class declaration -// /final int.*u8.*value;/, // field declaration with type comment -// /MyU8\(\s*{\s*required this\.value,\s*}\s*\);/, // constructor -// /extension MyU8Borsh on MyU8/, // extension for serialization -// /void toBorsh\(BinaryWriter writer\)/, // serialization method -// /static MyU8 fromBorsh\(BinaryReader reader\)/, // deserialization method -// /writer\.writeInt\(value\)/, // serialization line -// /reader\.readU8\(\)/, // deserialization line -// /import 'dart:typed_data';/, // Dart import -// /import '\.\.\/shared\.dart';/, // shared import -// /Generated type definition for MyU8/, // doc comment -// ]); -// }); - -// test('it exports u8 numbers', () => { -// // Given a u8 number. -// const node = definedTypeNode({ -// name: 'myU8', -// type: numberTypeNode('u8'), -// }); - -// // When we render the number. -// const renderMap = visit(node, getRenderMapVisitor()); - -// // Then we expect a u8 to be exported. -// codeContains(getFromRenderMap(renderMap, 'types/my_u8.dart'), [ -// /typedef MyU8 = int.*u8/, // Dart typedef with comment -// /import 'dart:typed_data';/, // Dart import -// /import '\.\.\/shared\.dart';/, // Dart import -// /Generated type definition for MyU8/, // doc comment -// ]); - -// codeDoesNotContains(getFromRenderMap(renderMap, 'types/my_u8.dart'), [ -// /BorshSerialize/, // Rust-specific, should not appear -// /BorshDeserialize/, // Rust-specific, should not appear -// /^use /m, // Rust import, should not appear -// ]); -// }); - -// test('it exports u8 numbers as struct fields', () => { -// // Given a u8 number. -// const node = definedTypeNode({ -// name: 'myU8', -// type: structTypeNode([structFieldTypeNode({ name: 'value', type: numberTypeNode('u8') })]), -// }); - -// // When we render the number. -// const renderMap = visit(node, getRenderMapVisitor()); - -// // Then we expect a u8 to be exported as a struct field. -// codeContains(getFromRenderMap(renderMap, 'types/my_u8.dart'), [ -// /class MyU8 /, // class declaration -// /final int.*u8.*value;/, // field declaration with type comment -// /MyU8\(\s*{\s*required this\.value,\s*}\s*\);/, // constructor -// /extension MyU8Borsh on MyU8/, // extension for serialization -// /void toBorsh\(BinaryWriter writer\)/, // serialization method -// /static MyU8 fromBorsh\(BinaryReader reader\)/, // deserialization method -// /writer\.writeInt\(value\)/, // serialization line -// /reader\.readU8\(\)/, // deserialization line -// /import 'dart:typed_data';/, // Dart import -// /import '\.\.\/shared\.dart';/, // shared import -// /Generated type definition for MyU8/, // doc comment -// ]); -// }); - -// test('it exports u16 numbers', () => { -// // Given a u16 number. -// const node = definedTypeNode({ -// name: 'myU16', -// type: numberTypeNode('u16'), -// }); - -// const renderMap = visit(node, getRenderMapVisitor()); - -// codeContains(getFromRenderMap(renderMap, 'types/my_u16.dart'), [ -// /typedef MyU16 = int.*u16/, -// /import 'dart:typed_data';/, -// /import '\.\.\/shared\.dart';/, -// /Generated type definition for MyU16/, -// ]); - -// codeDoesNotContains(getFromRenderMap(renderMap, 'types/my_u16.dart'), [ -// /BorshSerialize/, -// /BorshDeserialize/, -// /^use /m, -// ]); -// }); - -// test('it exports u16 numbers as struct fields', () => { -// // Given a u16 number. -// const node = definedTypeNode({ -// name: 'myU16', -// type: structTypeNode([structFieldTypeNode({ name: 'value', type: numberTypeNode('u16') })]), -// }); - -// const renderMap = visit(node, getRenderMapVisitor()); - -// codeContains(getFromRenderMap(renderMap, 'types/my_u16.dart'), [ -// /class MyU16 /, -// /final int.*u16.*value;/, -// /MyU16\(\s*{\s*required this\.value,\s*}\s*\);/, -// /extension MyU16Borsh on MyU16/, -// /void toBorsh\(BinaryWriter writer\)/, -// /static MyU16 fromBorsh\(BinaryReader reader\)/, -// /writer\.writeU16\(value\)/, -// /reader\.readU16\(\)/, -// /import 'dart:typed_data';/, -// /import '\.\.\/shared\.dart';/, -// /Generated type definition for MyU16/, -// ]); -// }); - -// test('it exports u16 numbers', () => { -// // Given a u16 number. -// const node = definedTypeNode({ -// name: 'myU16', -// type: numberTypeNode('u16'), -// }); - -// const renderMap = visit(node, getRenderMapVisitor()); - -// codeContains(getFromRenderMap(renderMap, 'types/my_u16.dart'), [ -// /typedef MyU16 = int.*u16/, -// /import 'dart:typed_data';/, -// /import '\.\.\/shared\.dart';/, -// /Generated type definition for MyU16/, -// ]); - -// codeDoesNotContains(getFromRenderMap(renderMap, 'types/my_u16.dart'), [ -// /BorshSerialize/, -// /BorshDeserialize/, -// /^use /m, -// ]); -// }); - -// test('it exports u16 numbers as struct fields', () => { -// // Given a u16 number. -// const node = definedTypeNode({ -// name: 'myU16', -// type: structTypeNode([structFieldTypeNode({ name: 'value', type: numberTypeNode('u16') })]), -// }); - -// const renderMap = visit(node, getRenderMapVisitor()); - -// codeContains(getFromRenderMap(renderMap, 'types/my_u16.dart'), [ -// /class MyU16 /, -// /final int.*u16.*value;/, -// /MyU16\(\s*{\s*required this\.value,\s*}\s*\);/, -// /extension MyU16Borsh on MyU16/, -// /void toBorsh\(BinaryWriter writer\)/, -// /static MyU16 fromBorsh\(BinaryReader reader\)/, -// /writer\.writeInt\(value\)/, -// /reader\.readInt\(\)/, -// /import 'dart:typed_data';/, -// /import '\.\.\/shared\.dart';/, -// /Generated type definition for MyU16/, -// ]); -// }); - -// test('it exports u32 numbers', () => { -// // Given a u32 number. -// const node = definedTypeNode({ -// name: 'myU32', -// type: numberTypeNode('u32'), -// }); - -// const renderMap = visit(node, getRenderMapVisitor()); - -// codeContains(getFromRenderMap(renderMap, 'types/my_u32.dart'), [ -// /typedef MyU32 = int.*u32/, -// /import 'dart:typed_data';/, -// /import '\.\.\/shared\.dart';/, -// /Generated type definition for MyU32/, -// ]); - -// codeDoesNotContains(getFromRenderMap(renderMap, 'types/my_u32.dart'), [ -// /BorshSerialize/, -// /BorshDeserialize/, -// /^use /m, -// ]); -// }); - -// test('it exports u32 numbers as struct fields', () => { -// // Given a u32 number. -// const node = definedTypeNode({ -// name: 'myU32', -// type: structTypeNode([structFieldTypeNode({ name: 'value', type: numberTypeNode('u32') })]), -// }); - -// const renderMap = visit(node, getRenderMapVisitor()); - -// codeContains(getFromRenderMap(renderMap, 'types/my_u32.dart'), [ -// /class MyU32 /, -// /final int.*u32.*value;/, -// /MyU32\(\s*{\s*required this\.value,\s*}\s*\);/, -// /extension MyU32Borsh on MyU32/, -// /void toBorsh\(BinaryWriter writer\)/, -// /static MyU32 fromBorsh\(BinaryReader reader\)/, -// /writer\.writeBigInt\(value\)/, -// /reader\.readU32\(\)/, -// /import 'dart:typed_data';/, -// /import '\.\.\/shared\.dart';/, -// /Generated type definition for MyU32/, -// ]); -// }); - -// test('it exports i32 numbers', () => { -// // Given an i32 number. -// const node = definedTypeNode({ -// name: 'myI32', -// type: numberTypeNode('i32'), -// }); - -// const renderMap = visit(node, getRenderMapVisitor()); - -// codeContains(getFromRenderMap(renderMap, 'types/my_i32.dart'), [ -// /typedef MyI32 = int.*i32/, -// /import 'dart:typed_data';/, -// /import '\.\.\/shared\.dart';/, -// /Generated type definition for MyI32/, -// ]); - -// codeDoesNotContains(getFromRenderMap(renderMap, 'types/my_i32.dart'), [ -// /BorshSerialize/, -// /BorshDeserialize/, -// /^use /m, -// ]); -// }); - -// test('it exports i32 numbers as struct fields', () => { -// // Given an i32 number. -// const node = definedTypeNode({ -// name: 'myI32', -// type: structTypeNode([structFieldTypeNode({ name: 'value', type: numberTypeNode('i32') })]), -// }); - -// const renderMap = visit(node, getRenderMapVisitor()); - -// codeContains(getFromRenderMap(renderMap, 'types/my_i32.dart'), [ -// /class MyI32 /, -// /final int.*i32.*value;/, -// /MyI32\(\s*{\s*required this\.value,\s*}\s*\);/, -// /extension MyI32Borsh on MyI32/, -// /void toBorsh\(BinaryWriter writer\)/, -// /static MyI32 fromBorsh\(BinaryReader reader\)/, -// /writer\.writeI32\(value\)/, -// /reader\.readI32\(\)/, -// /import 'dart:typed_data';/, -// /import '\.\.\/shared\.dart';/, -// /Generated type definition for MyI32/, -// ]); -// }); - -// test('it exports u64 numbers', () => { -// // Given a u64 number. -// const node = definedTypeNode({ -// name: 'myU64', -// type: numberTypeNode('u64'), -// }); - -// const renderMap = visit(node, getRenderMapVisitor()); - -// codeContains(getFromRenderMap(renderMap, 'types/my_u64.dart'), [ -// /typedef MyU64 = BigInt.*u64/, -// /import 'dart:typed_data';/, -// /import '\.\.\/shared\.dart';/, -// /Generated type definition for MyU64/, -// ]); - -// codeDoesNotContains(getFromRenderMap(renderMap, 'types/my_u64.dart'), [ -// /BorshSerialize/, -// /BorshDeserialize/, -// /^use /m, -// ]); -// }); - -// test('it exports u64 numbers as struct fields', () => { -// // Given a u64 number. -// const node = definedTypeNode({ -// name: 'myU64', -// type: structTypeNode([structFieldTypeNode({ name: 'value', type: numberTypeNode('u64') })]), -// }); - -// const renderMap = visit(node, getRenderMapVisitor()); - -// codeContains(getFromRenderMap(renderMap, 'types/my_u64.dart'), [ -// /class MyU64 /, -// /final BigInt.*u64.*value;/, -// /MyU64\(\s*{\s*required this\.value,\s*}\s*\);/, -// /extension MyU64Borsh on MyU64/, -// /void toBorsh\(BinaryWriter writer\)/, -// /static MyU64 fromBorsh\(BinaryReader reader\)/, -// /writer\.writeBigInt\(value\)/, -// /reader\.readU64\(\)/, -// /import 'dart:typed_data';/, -// /import '\.\.\/shared\.dart';/, -// /Generated type definition for MyU64/, -// ]); -// }); - -// test('it exports i64 numbers', () => { -// // Given an i64 number. -// const node = definedTypeNode({ -// name: 'myI64', -// type: numberTypeNode('i64'), -// }); - -// const renderMap = visit(node, getRenderMapVisitor()); - -// codeContains(getFromRenderMap(renderMap, 'types/my_i64.dart'), [ -// /typedef MyI64 = BigInt.*i64/, -// /import 'dart:typed_data';/, -// /import '\.\.\/shared\.dart';/, -// /Generated type definition for MyI64/, -// ]); - -// codeDoesNotContains(getFromRenderMap(renderMap, 'types/my_i64.dart'), [ -// /BorshSerialize/, -// /BorshDeserialize/, -// /^use /m, -// ]); -// }); - -// test('it exports i64 numbers as struct fields', () => { -// // Given an i64 number. -// const node = definedTypeNode({ -// name: 'myI64', -// type: structTypeNode([structFieldTypeNode({ name: 'value', type: numberTypeNode('i64') })]), -// }); - -// const renderMap = visit(node, getRenderMapVisitor()); - -// codeContains(getFromRenderMap(renderMap, 'types/my_i64.dart'), [ -// /class MyI64 /, -// /final BigInt.*i64.*value;/, -// /MyI64\(\s*{\s*required this\.value,\s*}\s*\);/, -// /extension MyI64Borsh on MyI64/, -// /void toBorsh\(BinaryWriter writer\)/, -// /static MyI64 fromBorsh\(BinaryReader reader\)/, -// /writer\.writeI64\(value\)/, -// /reader\.readI64\(\)/, -// /import 'dart:typed_data';/, -// /import '\.\.\/shared\.dart';/, -// /Generated type definition for MyI64/, -// ]); -// }); - - -// test('it exports u128 numbers', () => { -// // Given a u128 number. -// const node = definedTypeNode({ -// name: 'myU128', -// type: numberTypeNode('u128'), -// }); - -// const renderMap = visit(node, getRenderMapVisitor()); - -// codeContains(getFromRenderMap(renderMap, 'types/my_u128.dart'), [ -// /typedef MyU128 = BigInt.*u128/, -// /import 'dart:typed_data';/, -// /import '\.\.\/shared\.dart';/, -// /Generated type definition for MyU128/, -// ]); - -// codeDoesNotContains(getFromRenderMap(renderMap, 'types/my_u128.dart'), [ -// /BorshSerialize/, -// /BorshDeserialize/, -// /^use /m, -// ]); -// }); - -// test('it exports u128 numbers as struct fields', () => { -// // Given a u128 number. -// const node = definedTypeNode({ -// name: 'myU128', -// type: structTypeNode([structFieldTypeNode({ name: 'value', type: numberTypeNode('u128') })]), -// }); - -// const renderMap = visit(node, getRenderMapVisitor()); - -// codeContains(getFromRenderMap(renderMap, 'types/my_u128.dart'), [ -// /class MyU128 /, -// /final BigInt.*u128.*value;/, -// /MyU128\(\s*{\s*required this\.value,\s*}\s*\);/, -// /extension MyU128Borsh on MyU128/, -// /void toBorsh\(BinaryWriter writer\)/, -// /static MyU128 fromBorsh\(BinaryReader reader\)/, -// /writer\.writeBigInt\(value\)/, -// /reader\.readBigInt\(\)/, -// /import 'dart:typed_data';/, -// /import '\.\.\/shared\.dart';/, -// /Generated type definition for MyU128/, -// ]); -// }); - -// test('it exports i128 numbers', () => { -// // Given an i128 number. -// const node = definedTypeNode({ -// name: 'myI128', -// type: numberTypeNode('i128'), -// }); - -// const renderMap = visit(node, getRenderMapVisitor()); - -// codeContains(getFromRenderMap(renderMap, 'types/my_i128.dart'), [ -// /typedef MyI128 = BigInt.*i128/, -// /import 'dart:typed_data';/, -// /import '\.\.\/shared\.dart';/, -// /Generated type definition for MyI128/, -// ]); - -// codeDoesNotContains(getFromRenderMap(renderMap, 'types/my_i128.dart'), [ -// /BorshSerialize/, -// /BorshDeserialize/, -// /^use /m, -// ]); -// }); - -// test('it exports i128 numbers as struct fields', () => { -// // Given an i128 number. -// const node = definedTypeNode({ -// name: 'myI128', -// type: structTypeNode([structFieldTypeNode({ name: 'value', type: numberTypeNode('i128') })]), -// }); - -// const renderMap = visit(node, getRenderMapVisitor()); - -// codeContains(getFromRenderMap(renderMap, 'types/my_i128.dart'), [ -// /class MyI128 /, -// /final BigInt.*i128.*value;/, -// /MyI128\(\s*{\s*required this\.value,\s*}\s*\);/, -// /extension MyI128Borsh on MyI128/, -// /void toBorsh\(BinaryWriter writer\)/, -// /static MyI128 fromBorsh\(BinaryReader reader\)/, -// /writer\.writeBigInt\(value\)/, -// /reader\.readBigInt\(\)/, -// /import 'dart:typed_data';/, -// /import '\.\.\/shared\.dart';/, -// /Generated type definition for MyI128/, -// ]); -// }); \ No newline at end of file +import { definedTypeNode, numberTypeNode, structFieldTypeNode, structTypeNode } from '@codama/nodes'; +import { getFromRenderMap } from '@codama/renderers-core'; +import { visit } from '@codama/visitors-core'; +import { test } from 'vitest'; + +import { getRenderMapVisitor } from '../../src'; +import { codeContains, codeDoesNotContains } from '../_setup'; + +test('it exports short u16 numbers', () => { + // Given a shortU16 number. + const node = definedTypeNode({ + name: 'myShortU16', + type: numberTypeNode('shortU16'), + }); + + // When we render the number. + const renderMap = visit(node, getRenderMapVisitor()); + + // Then we expect a short u16 to be exported. + codeContains(getFromRenderMap(renderMap, 'types/my_short_u16.dart'), [ + /typedef MyShortU16 = int.*shortU16/, // Dart typedef with comment + /import 'dart:typed_data';/, // Dart import + /import '\.\.\/shared\.dart';/, // Dart import + /Generated type definition for MyShortU16/, // doc comment + ]); + + codeDoesNotContains(getFromRenderMap(renderMap, 'types/my_short_u16.dart'), [ + /BorshSerialize/, // Rust-specific, should not appear + /BorshDeserialize/, // Rust-specific, should not appear + /^use /m, // Rust import, should not appear + ]); +}); + +test('it exports short u16 numbers as struct fields', () => { + // Given a shortU16 number. + const node = definedTypeNode({ + name: 'myShortU16', + type: structTypeNode([structFieldTypeNode({ name: 'value', type: numberTypeNode('shortU16') })]), + }); + + // When we render the number. + const renderMap = visit(node, getRenderMapVisitor()); + + // Then we expect a short u16 to be exported as a struct field. + codeContains(getFromRenderMap(renderMap, 'types/my_short_u16.dart'), [ + /class MyShortU16 /, // class declaration + /final int.*shortU16.*value;/, // field declaration with type comment + /MyShortU16\(\s*{\s*required this\.value,\s*}\s*\);/, // constructor + /extension MyShortU16Borsh on MyShortU16/, // extension for serialization + /void toBorsh\(BinaryWriter writer\)/, // serialization method + /static MyShortU16 fromBorsh\(BinaryReader reader\)/, // deserialization method + /throw Exception\('Unsupported number format: shortU16'\);/, // error for unsupported format + /import 'dart:typed_data';/, // Dart import + /import '\.\.\/shared\.dart';/, // shared import + /Generated type definition for MyShortU16/, // doc comment + ]); +}); + +test('it exports u8 numbers', () => { + // Given a u8 number. + const node = definedTypeNode({ + name: 'myU8', + type: numberTypeNode('u8'), + }); + + // When we render the number. + const renderMap = visit(node, getRenderMapVisitor()); + + // Then we expect a u8 to be exported. + codeContains(getFromRenderMap(renderMap, 'types/my_u8.dart'), [ + /typedef MyU8 = int.*u8/, // Dart typedef with comment + /import 'dart:typed_data';/, // Dart import + /import '\.\.\/shared\.dart';/, // Dart import + /Generated type definition for MyU8/, // doc comment + ]); + + codeDoesNotContains(getFromRenderMap(renderMap, 'types/my_u8.dart'), [ + /BorshSerialize/, // Rust-specific, should not appear + /BorshDeserialize/, // Rust-specific, should not appear + /^use /m, // Rust import, should not appear + ]); +}); + +test('it exports u8 numbers as struct fields', () => { + // Given a u8 number. + const node = definedTypeNode({ + name: 'myU8', + type: structTypeNode([structFieldTypeNode({ name: 'value', type: numberTypeNode('u8') })]), + }); + + // When we render the number. + const renderMap = visit(node, getRenderMapVisitor()); + + // Then we expect a u8 to be exported as a struct field. + codeContains(getFromRenderMap(renderMap, 'types/my_u8.dart'), [ + /class MyU8 /, // class declaration + /final int.*u8.*value;/, // field declaration with type comment + /MyU8\(\s*{\s*required this\.value,\s*}\s*\);/, // constructor + /extension MyU8Borsh on MyU8/, // extension for serialization + /void toBorsh\(BinaryWriter writer\)/, // serialization method + /static MyU8 fromBorsh\(BinaryReader reader\)/, // deserialization method + /writer\.writeU8\(value\)/, // serialization line + /reader\.readU8\(\)/, // deserialization line + /import 'dart:typed_data';/, // Dart import + /import '\.\.\/shared\.dart';/, // shared import + /Generated type definition for MyU8/, // doc comment + ]); +}); + +test('it exports u8 numbers', () => { + // Given a u8 number. + const node = definedTypeNode({ + name: 'myU8', + type: numberTypeNode('u8'), + }); + + // When we render the number. + const renderMap = visit(node, getRenderMapVisitor()); + + // Then we expect a u8 to be exported. + codeContains(getFromRenderMap(renderMap, 'types/my_u8.dart'), [ + /typedef MyU8 = int.*u8/, // Dart typedef with comment + /import 'dart:typed_data';/, // Dart import + /import '\.\.\/shared\.dart';/, // Dart import + /Generated type definition for MyU8/, // doc comment + ]); + + codeDoesNotContains(getFromRenderMap(renderMap, 'types/my_u8.dart'), [ + /BorshSerialize/, // Rust-specific, should not appear + /BorshDeserialize/, // Rust-specific, should not appear + /^use /m, // Rust import, should not appear + ]); +}); + +test('it exports u8 numbers as struct fields', () => { + // Given a u8 number. + const node = definedTypeNode({ + name: 'myU8', + type: structTypeNode([structFieldTypeNode({ name: 'value', type: numberTypeNode('u8') })]), + }); + + // When we render the number. + const renderMap = visit(node, getRenderMapVisitor()); + + // Then we expect a u8 to be exported as a struct field. + codeContains(getFromRenderMap(renderMap, 'types/my_u8.dart'), [ + /class MyU8 /, // class declaration + /final int.*u8.*value;/, // field declaration with type comment + /MyU8\(\s*{\s*required this\.value,\s*}\s*\);/, // constructor + /extension MyU8Borsh on MyU8/, // extension for serialization + /void toBorsh\(BinaryWriter writer\)/, // serialization method + /static MyU8 fromBorsh\(BinaryReader reader\)/, // deserialization method + /writer\.writeU8\(value\)/, // serialization line + /reader\.readU8\(\)/, // deserialization line + /import 'dart:typed_data';/, // Dart import + /import '\.\.\/shared\.dart';/, // shared import + /Generated type definition for MyU8/, // doc comment + ]); +}); + +test('it exports u16 numbers', () => { + // Given a u16 number. + const node = definedTypeNode({ + name: 'myU16', + type: numberTypeNode('u16'), + }); + + const renderMap = visit(node, getRenderMapVisitor()); + + codeContains(getFromRenderMap(renderMap, 'types/my_u16.dart'), [ + /typedef MyU16 = int.*u16/, + /import 'dart:typed_data';/, + /import '\.\.\/shared\.dart';/, + /Generated type definition for MyU16/, + ]); + + codeDoesNotContains(getFromRenderMap(renderMap, 'types/my_u16.dart'), [ + /BorshSerialize/, + /BorshDeserialize/, + /^use /m, + ]); +}); + +test('it exports u16 numbers as struct fields', () => { + // Given a u16 number. + const node = definedTypeNode({ + name: 'myU16', + type: structTypeNode([structFieldTypeNode({ name: 'value', type: numberTypeNode('u16') })]), + }); + + const renderMap = visit(node, getRenderMapVisitor()); + + codeContains(getFromRenderMap(renderMap, 'types/my_u16.dart'), [ + /class MyU16 /, + /final int.*u16.*value;/, + /MyU16\(\s*{\s*required this\.value,\s*}\s*\);/, + /extension MyU16Borsh on MyU16/, + /void toBorsh\(BinaryWriter writer\)/, + /static MyU16 fromBorsh\(BinaryReader reader\)/, + /writer\.writeU16\(value\)/, + /reader\.readU16\(\)/, + /import 'dart:typed_data';/, + /import '\.\.\/shared\.dart';/, + /Generated type definition for MyU16/, + ]); +}); + +test('it exports u16 numbers', () => { + // Given a u16 number. + const node = definedTypeNode({ + name: 'myU16', + type: numberTypeNode('u16'), + }); + + const renderMap = visit(node, getRenderMapVisitor()); + + codeContains(getFromRenderMap(renderMap, 'types/my_u16.dart'), [ + /typedef MyU16 = int.*u16/, + /import 'dart:typed_data';/, + /import '\.\.\/shared\.dart';/, + /Generated type definition for MyU16/, + ]); + + codeDoesNotContains(getFromRenderMap(renderMap, 'types/my_u16.dart'), [ + /BorshSerialize/, + /BorshDeserialize/, + /^use /m, + ]); +}); + +test('it exports u16 numbers as struct fields', () => { + // Given a u16 number. + const node = definedTypeNode({ + name: 'myU16', + type: structTypeNode([structFieldTypeNode({ name: 'value', type: numberTypeNode('u16') })]), + }); + + const renderMap = visit(node, getRenderMapVisitor()); + + codeContains(getFromRenderMap(renderMap, 'types/my_u16.dart'), [ + /class MyU16 /, + /final int.*u16.*value;/, + /MyU16\(\s*{\s*required this\.value,\s*}\s*\);/, + /extension MyU16Borsh on MyU16/, + /void toBorsh\(BinaryWriter writer\)/, + /static MyU16 fromBorsh\(BinaryReader reader\)/, + /writer\.writeU16\(value\)/, + /reader\.readU16\(\)/, + /import 'dart:typed_data';/, + /import '\.\.\/shared\.dart';/, + /Generated type definition for MyU16/, + ]); +}); + +test('it exports u32 numbers', () => { + // Given a u32 number. + const node = definedTypeNode({ + name: 'myU32', + type: numberTypeNode('u32'), + }); + + const renderMap = visit(node, getRenderMapVisitor()); + + codeContains(getFromRenderMap(renderMap, 'types/my_u32.dart'), [ + /typedef MyU32 = int.*u32/, + /import 'dart:typed_data';/, + /import '\.\.\/shared\.dart';/, + /Generated type definition for MyU32/, + ]); + + codeDoesNotContains(getFromRenderMap(renderMap, 'types/my_u32.dart'), [ + /BorshSerialize/, + /BorshDeserialize/, + /^use /m, + ]); +}); + +test('it exports u32 numbers as struct fields', () => { + // Given a u32 number. + const node = definedTypeNode({ + name: 'myU32', + type: structTypeNode([structFieldTypeNode({ name: 'value', type: numberTypeNode('u32') })]), + }); + + const renderMap = visit(node, getRenderMapVisitor()); + + codeContains(getFromRenderMap(renderMap, 'types/my_u32.dart'), [ + /class MyU32 /, + /final int.*u32.*value;/, + /MyU32\(\s*{\s*required this\.value,\s*}\s*\);/, + /extension MyU32Borsh on MyU32/, + /void toBorsh\(BinaryWriter writer\)/, + /static MyU32 fromBorsh\(BinaryReader reader\)/, + /writer\.writeU32\(value\)/, + /reader\.readU32\(\)/, + /import 'dart:typed_data';/, + /import '\.\.\/shared\.dart';/, + /Generated type definition for MyU32/, + ]); +}); + +test('it exports i32 numbers', () => { + // Given an i32 number. + const node = definedTypeNode({ + name: 'myI32', + type: numberTypeNode('i32'), + }); + + const renderMap = visit(node, getRenderMapVisitor()); + + codeContains(getFromRenderMap(renderMap, 'types/my_i32.dart'), [ + /typedef MyI32 = int.*i32/, + /import 'dart:typed_data';/, + /import '\.\.\/shared\.dart';/, + /Generated type definition for MyI32/, + ]); + + codeDoesNotContains(getFromRenderMap(renderMap, 'types/my_i32.dart'), [ + /BorshSerialize/, + /BorshDeserialize/, + /^use /m, + ]); +}); + +test('it exports i32 numbers as struct fields', () => { + // Given an i32 number. + const node = definedTypeNode({ + name: 'myI32', + type: structTypeNode([structFieldTypeNode({ name: 'value', type: numberTypeNode('i32') })]), + }); + + const renderMap = visit(node, getRenderMapVisitor()); + + codeContains(getFromRenderMap(renderMap, 'types/my_i32.dart'), [ + /class MyI32 /, + /final int.*i32.*value;/, + /MyI32\(\s*{\s*required this\.value,\s*}\s*\);/, + /extension MyI32Borsh on MyI32/, + /void toBorsh\(BinaryWriter writer\)/, + /static MyI32 fromBorsh\(BinaryReader reader\)/, + /writer\.writeI32\(value\)/, + /reader\.readI32\(\)/, + /import 'dart:typed_data';/, + /import '\.\.\/shared\.dart';/, + /Generated type definition for MyI32/, + ]); +}); + +test('it exports u64 numbers', () => { + // Given a u64 number. + const node = definedTypeNode({ + name: 'myU64', + type: numberTypeNode('u64'), + }); + + const renderMap = visit(node, getRenderMapVisitor()); + + codeContains(getFromRenderMap(renderMap, 'types/my_u64.dart'), [ + /typedef MyU64 = BigInt.*u64/, + /import 'dart:typed_data';/, + /import '\.\.\/shared\.dart';/, + /Generated type definition for MyU64/, + ]); + + codeDoesNotContains(getFromRenderMap(renderMap, 'types/my_u64.dart'), [ + /BorshSerialize/, + /BorshDeserialize/, + /^use /m, + ]); +}); + +test('it exports u64 numbers as struct fields', () => { + // Given a u64 number. + const node = definedTypeNode({ + name: 'myU64', + type: structTypeNode([structFieldTypeNode({ name: 'value', type: numberTypeNode('u64') })]), + }); + + const renderMap = visit(node, getRenderMapVisitor()); + + codeContains(getFromRenderMap(renderMap, 'types/my_u64.dart'), [ + /class MyU64 /, + /final BigInt.*u64.*value;/, + /MyU64\(\s*{\s*required this\.value,\s*}\s*\);/, + /extension MyU64Borsh on MyU64/, + /void toBorsh\(BinaryWriter writer\)/, + /static MyU64 fromBorsh\(BinaryReader reader\)/, + /writer\.writeU64\(value\)/, + /reader\.readU64\(\)/, + /import 'dart:typed_data';/, + /import '\.\.\/shared\.dart';/, + /Generated type definition for MyU64/, + ]); +}); + +test('it exports i64 numbers', () => { + // Given an i64 number. + const node = definedTypeNode({ + name: 'myI64', + type: numberTypeNode('i64'), + }); + + const renderMap = visit(node, getRenderMapVisitor()); + + codeContains(getFromRenderMap(renderMap, 'types/my_i64.dart'), [ + /typedef MyI64 = BigInt.*i64/, + /import 'dart:typed_data';/, + /import '\.\.\/shared\.dart';/, + /Generated type definition for MyI64/, + ]); + + codeDoesNotContains(getFromRenderMap(renderMap, 'types/my_i64.dart'), [ + /BorshSerialize/, + /BorshDeserialize/, + /^use /m, + ]); +}); + +test('it exports i64 numbers as struct fields', () => { + // Given an i64 number. + const node = definedTypeNode({ + name: 'myI64', + type: structTypeNode([structFieldTypeNode({ name: 'value', type: numberTypeNode('i64') })]), + }); + + const renderMap = visit(node, getRenderMapVisitor()); + + codeContains(getFromRenderMap(renderMap, 'types/my_i64.dart'), [ + /class MyI64 /, + /final BigInt.*i64.*value;/, + /MyI64\(\s*{\s*required this\.value,\s*}\s*\);/, + /extension MyI64Borsh on MyI64/, + /void toBorsh\(BinaryWriter writer\)/, + /static MyI64 fromBorsh\(BinaryReader reader\)/, + /writer\.writeI64\(value\)/, + /reader\.readI64\(\)/, + /import 'dart:typed_data';/, + /import '\.\.\/shared\.dart';/, + /Generated type definition for MyI64/, + ]); +}); + + +test('it exports u128 numbers', () => { + // Given a u128 number. + const node = definedTypeNode({ + name: 'myU128', + type: numberTypeNode('u128'), + }); + + const renderMap = visit(node, getRenderMapVisitor()); + + codeContains(getFromRenderMap(renderMap, 'types/my_u128.dart'), [ + /typedef MyU128 = BigInt.*u128/, + /import 'dart:typed_data';/, + /import '\.\.\/shared\.dart';/, + /Generated type definition for MyU128/, + ]); + + codeDoesNotContains(getFromRenderMap(renderMap, 'types/my_u128.dart'), [ + /BorshSerialize/, + /BorshDeserialize/, + /^use /m, + ]); +}); + +test('it exports u128 numbers as struct fields', () => { + // Given a u128 number. + const node = definedTypeNode({ + name: 'myU128', + type: structTypeNode([structFieldTypeNode({ name: 'value', type: numberTypeNode('u128') })]), + }); + + const renderMap = visit(node, getRenderMapVisitor()); + + codeContains(getFromRenderMap(renderMap, 'types/my_u128.dart'), [ + /class MyU128 /, + /final BigInt.*u128.*value;/, + /MyU128\(\s*{\s*required this\.value,\s*}\s*\);/, + /extension MyU128Borsh on MyU128/, + /void toBorsh\(BinaryWriter writer\)/, + /static MyU128 fromBorsh\(BinaryReader reader\)/, + /writer\.writeBigInt\(value\)/, + /reader\.readBigInt\(\)/, + /import 'dart:typed_data';/, + /import '\.\.\/shared\.dart';/, + /Generated type definition for MyU128/, + ]); +}); + +test('it exports i128 numbers', () => { + // Given an i128 number. + const node = definedTypeNode({ + name: 'myI128', + type: numberTypeNode('i128'), + }); + + const renderMap = visit(node, getRenderMapVisitor()); + + codeContains(getFromRenderMap(renderMap, 'types/my_i128.dart'), [ + /typedef MyI128 = BigInt.*i128/, + /import 'dart:typed_data';/, + /import '\.\.\/shared\.dart';/, + /Generated type definition for MyI128/, + ]); + + codeDoesNotContains(getFromRenderMap(renderMap, 'types/my_i128.dart'), [ + /BorshSerialize/, + /BorshDeserialize/, + /^use /m, + ]); +}); + +test('it exports i128 numbers as struct fields', () => { + // Given an i128 number. + const node = definedTypeNode({ + name: 'myI128', + type: structTypeNode([structFieldTypeNode({ name: 'value', type: numberTypeNode('i128') })]), + }); + + const renderMap = visit(node, getRenderMapVisitor()); + + codeContains(getFromRenderMap(renderMap, 'types/my_i128.dart'), [ + /class MyI128 /, + /final BigInt.*i128.*value;/, + /MyI128\(\s*{\s*required this\.value,\s*}\s*\);/, + /extension MyI128Borsh on MyI128/, + /void toBorsh\(BinaryWriter writer\)/, + /static MyI128 fromBorsh\(BinaryReader reader\)/, + /writer\.writeBigInt\(value\)/, + /reader\.readBigInt\(\)/, + /import 'dart:typed_data';/, + /import '\.\.\/shared\.dart';/, + /Generated type definition for MyI128/, + ]); +}); \ No newline at end of file From 3af7b5afe05286e4bcab206af481c6a248e5feb0 Mon Sep 17 00:00:00 2001 From: ERoydev Date: Mon, 15 Sep 2025 17:15:03 +0300 Subject: [PATCH 19/33] fix: Handle errors and baseType for optional fields --- src/getRenderMapVisitor.ts | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/getRenderMapVisitor.ts b/src/getRenderMapVisitor.ts index 99b201e..9b980a9 100644 --- a/src/getRenderMapVisitor.ts +++ b/src/getRenderMapVisitor.ts @@ -4,6 +4,7 @@ import { DefinedTypeNode, getAllAccounts, getAllDefinedTypes, + getAllErrors, getAllInstructionsWithSubs, getAllPdas, getAllPrograms, @@ -134,7 +135,8 @@ export function getRenderMapVisitor(options: GetRenderMapOptions = {}) { const baseType = getBaseType(field.type).replace(/\?$/, ''); // Remove optional marker `?` for the check return { ...field, - isStruct: structTypeNames.has(baseType) + baseType: baseType, + isStruct: structTypeNames.has(baseType), } }); @@ -269,6 +271,8 @@ export function getRenderMapVisitor(options: GetRenderMapOptions = {}) { const instructionsToExport = getAllInstructionsWithSubs(node, { leavesOnly: !renderParentInstructions, }); + + const errorsToExport = getAllErrors(node); const definedTypesToExport = getAllDefinedTypes(node); const hasAnythingToExport = programsToExport.length > 0 || @@ -280,6 +284,7 @@ export function getRenderMapVisitor(options: GetRenderMapOptions = {}) { const ctx = { accountsToExport, definedTypesToExport, + errorsToExport, hasAnythingToExport, instructionsToExport, pdasToExport, @@ -289,7 +294,7 @@ export function getRenderMapVisitor(options: GetRenderMapOptions = {}) { let renders: RenderMap = renderMap(); if (accountsToExport.length > 0) { - renders = addToRenderMap(renders, 'shared.dart', renderTemplate('sharedPage.njk', ctx)); + renders = addToRenderMap(renders, 'shared.dart', renderTemplate('sharedPage.njk', { ...ctx})); } if (programsToExport.length > 0) { const programsImports = new ImportMap().add('package:solana/solana.dart', new Set(['Ed25519HDPublicKey'])); @@ -306,28 +311,29 @@ export function getRenderMapVisitor(options: GetRenderMapOptions = {}) { r => addToRenderMap( r, 'errors.dart', - renderTemplate('errorsMod.njk', { ctx }) + renderTemplate('errorsMod.njk', { ...ctx }) ) ); } if (pdasToExport.length > 0) { - renders = addToRenderMap(renders, 'pdas.dart', renderTemplate('pdasMod.njk', ctx)); + renders = addToRenderMap(renders, 'pdas.dart', renderTemplate('pdasMod.njk', { ...ctx })); } if (accountsToExport.length > 0) { - renders = addToRenderMap(renders, 'accounts.dart', renderTemplate('accountsMod.njk', ctx)); + renders = addToRenderMap(renders, 'accounts.dart', renderTemplate('accountsMod.njk', { ...ctx })); } if (instructionsToExport.length > 0) { - renders = addToRenderMap(renders, 'instructions.dart', renderTemplate('instructionsMod.njk', ctx)); + renders = addToRenderMap(renders, 'instructions.dart', renderTemplate('instructionsMod.njk', { ...ctx})); } if (definedTypesToExport.length > 0) { - renders = addToRenderMap(renders, 'types.dart', renderTemplate('definedTypesMod.njk', ctx)); + renders = addToRenderMap(renders, 'types.dart', renderTemplate('definedTypesMod.njk', { ...ctx})); } + return pipe( renders, - (r: RenderMap): RenderMap => addToRenderMap(r, 'mod.dart', renderTemplate('rootMod.njk', ctx)), - (r: RenderMap): RenderMap => addToRenderMap(r, 'lib.dart', renderTemplate('rootMod.njk', ctx)), + (r: RenderMap): RenderMap => addToRenderMap(r, 'mod.dart', renderTemplate('rootMod.njk', { ...ctx })), + (r: RenderMap): RenderMap => addToRenderMap(r, 'lib.dart', renderTemplate('rootMod.njk', { ...ctx })), (r: RenderMap): RenderMap => mergeRenderMaps( [r, ...getAllPrograms(node).map((p) => visit(p, self) as RenderMap)] ), From abfaa02c39f336ab3c2b838081611197f7b1f2a7 Mon Sep 17 00:00:00 2001 From: ERoydev Date: Mon, 15 Sep 2025 17:16:24 +0300 Subject: [PATCH 20/33] update: Clean e2e examples --- e2e/anchor/lib/generated/accounts.dart | 10 - .../lib/generated/accounts/guard_v1.dart | 137 ---- e2e/anchor/lib/generated/errors.dart | 8 - .../generated/errors/wen_transfer_guard.dart | 161 ----- e2e/anchor/lib/generated/instructions.dart | 13 - .../generated/instructions/create_guard.dart | 160 ----- .../lib/generated/instructions/execute.dart | 111 ---- .../generated/instructions/initialize.dart | 98 --- .../generated/instructions/update_guard.dart | 130 ---- e2e/anchor/lib/generated/lib.dart | 19 - e2e/anchor/lib/generated/mod.dart | 19 - e2e/anchor/lib/generated/programs.dart | 20 - e2e/anchor/lib/generated/shared.dart | 612 ------------------ e2e/anchor/lib/generated/types.dart | 13 - e2e/anchor/lib/generated/types/cpi_rule.dart | 72 --- ...metadata_additional_field_restriction.dart | 72 --- .../types/metadata_additional_field_rule.dart | 49 -- .../generated/types/transfer_amount_rule.dart | 88 --- e2e/anchor/src/generated/accounts.dart | 10 - .../src/generated/accounts/guard_v1.dart | 137 ---- e2e/anchor/src/generated/errors.dart | 8 - .../generated/errors/wen_transfer_guard.dart | 161 ----- e2e/anchor/src/generated/instructions.dart | 13 - .../generated/instructions/create_guard.dart | 160 ----- .../src/generated/instructions/execute.dart | 111 ---- .../generated/instructions/initialize.dart | 98 --- .../generated/instructions/update_guard.dart | 130 ---- e2e/anchor/src/generated/lib.dart | 19 - e2e/anchor/src/generated/mod.dart | 19 - e2e/anchor/src/generated/programs.dart | 20 - e2e/anchor/src/generated/shared.dart | 587 ----------------- e2e/anchor/src/generated/types.dart | 13 - e2e/anchor/src/generated/types/cpi_rule.dart | 72 --- ...metadata_additional_field_restriction.dart | 72 --- .../types/metadata_additional_field_rule.dart | 49 -- .../generated/types/transfer_amount_rule.dart | 88 --- e2e/dummy/lib/generated/errors.dart | 8 - e2e/dummy/lib/generated/lib.dart | 11 - e2e/dummy/lib/generated/mod.dart | 11 - e2e/dummy/lib/generated/programs.dart | 19 - e2e/memo/lib/generated/errors.dart | 8 - e2e/memo/lib/generated/lib.dart | 11 - e2e/memo/lib/generated/mod.dart | 11 - e2e/memo/lib/generated/programs.dart | 19 - e2e/system/lib/generated/errors.dart | 8 - e2e/system/lib/generated/lib.dart | 11 - e2e/system/lib/generated/mod.dart | 11 - e2e/system/lib/generated/programs.dart | 19 - 48 files changed, 3706 deletions(-) delete mode 100644 e2e/anchor/lib/generated/accounts.dart delete mode 100644 e2e/anchor/lib/generated/accounts/guard_v1.dart delete mode 100644 e2e/anchor/lib/generated/errors.dart delete mode 100644 e2e/anchor/lib/generated/errors/wen_transfer_guard.dart delete mode 100644 e2e/anchor/lib/generated/instructions.dart delete mode 100644 e2e/anchor/lib/generated/instructions/create_guard.dart delete mode 100644 e2e/anchor/lib/generated/instructions/execute.dart delete mode 100644 e2e/anchor/lib/generated/instructions/initialize.dart delete mode 100644 e2e/anchor/lib/generated/instructions/update_guard.dart delete mode 100644 e2e/anchor/lib/generated/lib.dart delete mode 100644 e2e/anchor/lib/generated/mod.dart delete mode 100644 e2e/anchor/lib/generated/programs.dart delete mode 100644 e2e/anchor/lib/generated/shared.dart delete mode 100644 e2e/anchor/lib/generated/types.dart delete mode 100644 e2e/anchor/lib/generated/types/cpi_rule.dart delete mode 100644 e2e/anchor/lib/generated/types/metadata_additional_field_restriction.dart delete mode 100644 e2e/anchor/lib/generated/types/metadata_additional_field_rule.dart delete mode 100644 e2e/anchor/lib/generated/types/transfer_amount_rule.dart delete mode 100644 e2e/anchor/src/generated/accounts.dart delete mode 100644 e2e/anchor/src/generated/accounts/guard_v1.dart delete mode 100644 e2e/anchor/src/generated/errors.dart delete mode 100644 e2e/anchor/src/generated/errors/wen_transfer_guard.dart delete mode 100644 e2e/anchor/src/generated/instructions.dart delete mode 100644 e2e/anchor/src/generated/instructions/create_guard.dart delete mode 100644 e2e/anchor/src/generated/instructions/execute.dart delete mode 100644 e2e/anchor/src/generated/instructions/initialize.dart delete mode 100644 e2e/anchor/src/generated/instructions/update_guard.dart delete mode 100644 e2e/anchor/src/generated/lib.dart delete mode 100644 e2e/anchor/src/generated/mod.dart delete mode 100644 e2e/anchor/src/generated/programs.dart delete mode 100644 e2e/anchor/src/generated/shared.dart delete mode 100644 e2e/anchor/src/generated/types.dart delete mode 100644 e2e/anchor/src/generated/types/cpi_rule.dart delete mode 100644 e2e/anchor/src/generated/types/metadata_additional_field_restriction.dart delete mode 100644 e2e/anchor/src/generated/types/metadata_additional_field_rule.dart delete mode 100644 e2e/anchor/src/generated/types/transfer_amount_rule.dart delete mode 100644 e2e/dummy/lib/generated/errors.dart delete mode 100644 e2e/dummy/lib/generated/lib.dart delete mode 100644 e2e/dummy/lib/generated/mod.dart delete mode 100644 e2e/dummy/lib/generated/programs.dart delete mode 100644 e2e/memo/lib/generated/errors.dart delete mode 100644 e2e/memo/lib/generated/lib.dart delete mode 100644 e2e/memo/lib/generated/mod.dart delete mode 100644 e2e/memo/lib/generated/programs.dart delete mode 100644 e2e/system/lib/generated/errors.dart delete mode 100644 e2e/system/lib/generated/lib.dart delete mode 100644 e2e/system/lib/generated/mod.dart delete mode 100644 e2e/system/lib/generated/programs.dart diff --git a/e2e/anchor/lib/generated/accounts.dart b/e2e/anchor/lib/generated/accounts.dart deleted file mode 100644 index 98c8416..0000000 --- a/e2e/anchor/lib/generated/accounts.dart +++ /dev/null @@ -1,10 +0,0 @@ -/// This code was AUTOGENERATED using the codama library. -/// Please DO NOT EDIT THIS FILE, instead use visitors -/// to add features, then rerun codama to update it. -/// -/// https://github.com/codama-idl/codama -/// - -// This file exports account classes for all accounts in the SDK. - -export 'accounts/guard_v1.dart'; diff --git a/e2e/anchor/lib/generated/accounts/guard_v1.dart b/e2e/anchor/lib/generated/accounts/guard_v1.dart deleted file mode 100644 index 722c577..0000000 --- a/e2e/anchor/lib/generated/accounts/guard_v1.dart +++ /dev/null @@ -1,137 +0,0 @@ -/// This code was AUTOGENERATED using the codama library. -/// Please DO NOT EDIT THIS FILE, instead use visitors -/// to add features, then rerun codama to update it. -/// -/// https://github.com/codama-idl/codama -/// - -import 'dart:typed_data'; -import 'package:collection/collection.dart'; -import 'package:solana/dto.dart'; -import 'package:solana/solana.dart'; -import '../shared.dart'; -import '../types/cpi_rule.dart'; -import '../types/metadata_additional_field_rule.dart'; -import '../types/transfer_amount_rule.dart'; - -const List GUARD_V1_DISCRIMINATOR = [185, 149, 156, 78, 245, 108, 172, 68]; - -/// Generated account class for GuardV1. -/// -class GuardV1 { - // Fields - final Ed25519HDPublicKey mint; - final int /* type: u8 */ bump; - final CpiRule? cpi_rule; - final TransferAmountRule? transfer_amount_rule; - final List additional_fields_rule; - - // Constructor - GuardV1({ - required this.mint, - required this.bump, - required this.cpi_rule, - required this.transfer_amount_rule, - required this.additional_fields_rule, - }); - - /// Deserializes this account from borsh. - static GuardV1 fromBorsh(BinaryReader reader) { - return GuardV1( - mint: Ed25519HDPublicKey(reader.readPubkey()), - bump: reader.readU8(), - cpi_rule: reader.readU8() == 1 ? CpiRuleBorsh.fromBorsh(reader) : null, - transfer_amount_rule: reader.readU8() == 1 - ? TransferAmountRuleBorsh.fromBorsh(reader) - : null, - additional_fields_rule: reader.readArray(() { - // item is a struct, call fromBorsh per item - return MetadataAdditionalFieldRuleBorsh.fromBorsh(reader); - }), - ); - } - - /// Serializes this account to borsh. - void toBorsh(BinaryWriter writer) { - writer.writePubkey(Uint8List.fromList(mint.bytes)); - - writer.writeU8(bump); - - writer.writeU8(cpi_rule != null ? 1 : 0); - if (cpi_rule != null) { - cpi_rule!.toBorsh(writer); - } - writer.writeU8(transfer_amount_rule != null ? 1 : 0); - if (transfer_amount_rule != null) { - transfer_amount_rule!.toBorsh(writer); - } - writer.writeArray(additional_fields_rule, - (MetadataAdditionalFieldRule item) { - // Each item is a struct - item.toBorsh(writer); - }); - } - - /// Creates a [GuardV1] from its bytes representation. - static GuardV1 fromBytes(Uint8List data) { - final buffer = ByteData.view(data.buffer); - final reader = BinaryReader(buffer); - - // Validate the discriminator - final discriminator = reader.readDiscriminator(); - if (!const ListEquality().equals(discriminator, GUARD_V1_DISCRIMINATOR)) { - throw FormatException('Invalid account discriminator'); - } - - return GuardV1.fromBorsh(reader); - } - - /// Serializes this account to its bytes representation. - Uint8List toBytes() { - final writer = BinaryWriter(); - - // Write discriminator - writer.writeDiscriminator(Uint8List.fromList(GUARD_V1_DISCRIMINATOR)); - - // Write account data - toBorsh(writer); - - return writer.toBytes(); - } - - /// Fetches a [GuardV1] from the blockchain. - static Future fetch( - RpcClient client, - Ed25519HDPublicKey address, - ) async { - final accountInfo = await client.getAccountInfo(address.toBase58(), - encoding: Encoding.base64); - final data = accountInfo.value?.data; - - if (data == null) { - throw AccountNotFoundError(address); - } - - if (data is! BinaryAccountData) { - throw FormatException( - 'Expected binary account data, got ${data.runtimeType}'); - } - - return fromBytes(Uint8List.fromList(data.data)); - } - - /// Fetches a [GuardV1] from the blockchain if it exists. - static Future fetchNullable( - RpcClient client, - Ed25519HDPublicKey address, - ) async { - try { - return await fetch(client, address); - } catch (e) { - if (e is AccountNotFoundError) { - return null; - } - rethrow; - } - } -} diff --git a/e2e/anchor/lib/generated/errors.dart b/e2e/anchor/lib/generated/errors.dart deleted file mode 100644 index a105376..0000000 --- a/e2e/anchor/lib/generated/errors.dart +++ /dev/null @@ -1,8 +0,0 @@ -/// This code was AUTOGENERATED using the codama library. -/// Please DO NOT EDIT THIS FILE, instead use visitors -/// to add features, then rerun codama to update it. -/// -/// https://github.com/codama-idl/codama -/// - -// This file exports error classes for all programs in the SDK. diff --git a/e2e/anchor/lib/generated/errors/wen_transfer_guard.dart b/e2e/anchor/lib/generated/errors/wen_transfer_guard.dart deleted file mode 100644 index 1e633ed..0000000 --- a/e2e/anchor/lib/generated/errors/wen_transfer_guard.dart +++ /dev/null @@ -1,161 +0,0 @@ -/// This code was AUTOGENERATED using the codama library. -/// Please DO NOT EDIT THIS FILE, instead use visitors -/// to add features, then rerun codama to update it. -/// -/// https://github.com/codama-idl/codama -/// - -/// Error codes for the WenTransferGuard program. -class WenTransferGuardErrorCode { - /// Cpi Rule Enforcement Failed - static const int CpiRuleEnforcementFailed = 0x1770; - - /// Transfer Amount Rule Enforce Failed - static const int TransferAmountRuleEnforceFailed = 0x1771; - - /// Metadata Field Does Not Exist - static const int MetadataFieldDoesNotExist = 0x1772; - - /// Metadata Field Does Not Pass - static const int MetadataFieldDoesNotPass = 0x1773; - - /// Guard token amount should be at least 1 - static const int GuardTokenAmountShouldBeAtLeastOne = 0x1774; - - /// Not owned by token 2022 program - static const int NotOwnedByToken2022Program = 0x1775; - - /// Must be initialized by Transfer Hook Authority - static const int MustBeInitializedByTransferHookAuthority = 0x1776; - - /// Mints assigned Transfer Hook Program is not this one - static const int MintAssignedTransferHookProgramIsNotThisOne = 0x1777; -} - -/// Base class for all WenTransferGuard program errors. -abstract class WenTransferGuardError extends Error { - /// The numerical error code. - final int code; - - /// Human-readable error message. - final String message; - - /// Creates a new WenTransferGuardError. - WenTransferGuardError(this.code, this.message); - - /// Creates a WenTransferGuardError from a raw error code. - static WenTransferGuardError fromCode(int code) { - switch (code) { - case WenTransferGuardErrorCode.CpiRuleEnforcementFailed: - return CpiRuleEnforcementFailedError(); - case WenTransferGuardErrorCode.TransferAmountRuleEnforceFailed: - return TransferAmountRuleEnforceFailedError(); - case WenTransferGuardErrorCode.MetadataFieldDoesNotExist: - return MetadataFieldDoesNotExistError(); - case WenTransferGuardErrorCode.MetadataFieldDoesNotPass: - return MetadataFieldDoesNotPassError(); - case WenTransferGuardErrorCode.GuardTokenAmountShouldBeAtLeastOne: - return GuardTokenAmountShouldBeAtLeastOneError(); - case WenTransferGuardErrorCode.NotOwnedByToken2022Program: - return NotOwnedByToken2022ProgramError(); - case WenTransferGuardErrorCode.MustBeInitializedByTransferHookAuthority: - return MustBeInitializedByTransferHookAuthorityError(); - case WenTransferGuardErrorCode - .MintAssignedTransferHookProgramIsNotThisOne: - return MintAssignedTransferHookProgramIsNotThisOneError(); - default: - return UnknownError(code); - } - } - - @override - String toString() => '$runtimeType: [$code] $message'; -} - -/// Represents an unknown error from the WenTransferGuard program. -class UnknownError extends WenTransferGuardError { - /// Creates a new UnknownError. - UnknownError(int code) : super(code, 'Unknown error'); -} - -/// Cpi Rule Enforcement Failed -class CpiRuleEnforcementFailedError extends WenTransferGuardError { - /// Creates a new CpiRuleEnforcementFailedError. - CpiRuleEnforcementFailedError() - : super( - WenTransferGuardErrorCode.CpiRuleEnforcementFailed, - 'Cpi Rule Enforcement Failed', - ); -} - -/// Transfer Amount Rule Enforce Failed -class TransferAmountRuleEnforceFailedError extends WenTransferGuardError { - /// Creates a new TransferAmountRuleEnforceFailedError. - TransferAmountRuleEnforceFailedError() - : super( - WenTransferGuardErrorCode.TransferAmountRuleEnforceFailed, - 'Transfer Amount Rule Enforce Failed', - ); -} - -/// Metadata Field Does Not Exist -class MetadataFieldDoesNotExistError extends WenTransferGuardError { - /// Creates a new MetadataFieldDoesNotExistError. - MetadataFieldDoesNotExistError() - : super( - WenTransferGuardErrorCode.MetadataFieldDoesNotExist, - 'Metadata Field Does Not Exist', - ); -} - -/// Metadata Field Does Not Pass -class MetadataFieldDoesNotPassError extends WenTransferGuardError { - /// Creates a new MetadataFieldDoesNotPassError. - MetadataFieldDoesNotPassError() - : super( - WenTransferGuardErrorCode.MetadataFieldDoesNotPass, - 'Metadata Field Does Not Pass', - ); -} - -/// Guard token amount should be at least 1 -class GuardTokenAmountShouldBeAtLeastOneError extends WenTransferGuardError { - /// Creates a new GuardTokenAmountShouldBeAtLeastOneError. - GuardTokenAmountShouldBeAtLeastOneError() - : super( - WenTransferGuardErrorCode.GuardTokenAmountShouldBeAtLeastOne, - 'Guard token amount should be at least 1', - ); -} - -/// Not owned by token 2022 program -class NotOwnedByToken2022ProgramError extends WenTransferGuardError { - /// Creates a new NotOwnedByToken2022ProgramError. - NotOwnedByToken2022ProgramError() - : super( - WenTransferGuardErrorCode.NotOwnedByToken2022Program, - 'Not owned by token 2022 program', - ); -} - -/// Must be initialized by Transfer Hook Authority -class MustBeInitializedByTransferHookAuthorityError - extends WenTransferGuardError { - /// Creates a new MustBeInitializedByTransferHookAuthorityError. - MustBeInitializedByTransferHookAuthorityError() - : super( - WenTransferGuardErrorCode.MustBeInitializedByTransferHookAuthority, - 'Must be initialized by Transfer Hook Authority', - ); -} - -/// Mints assigned Transfer Hook Program is not this one -class MintAssignedTransferHookProgramIsNotThisOneError - extends WenTransferGuardError { - /// Creates a new MintAssignedTransferHookProgramIsNotThisOneError. - MintAssignedTransferHookProgramIsNotThisOneError() - : super( - WenTransferGuardErrorCode.MintAssignedTransferHookProgramIsNotThisOne, - 'Mints assigned Transfer Hook Program is not this one', - ); -} diff --git a/e2e/anchor/lib/generated/instructions.dart b/e2e/anchor/lib/generated/instructions.dart deleted file mode 100644 index f9d3900..0000000 --- a/e2e/anchor/lib/generated/instructions.dart +++ /dev/null @@ -1,13 +0,0 @@ -/// This code was AUTOGENERATED using the codama library. -/// Please DO NOT EDIT THIS FILE, instead use visitors -/// to add features, then rerun codama to update it. -/// -/// https://github.com/codama-idl/codama -/// - -// This file exports instruction classes for all instructions in the SDK. - -export 'instructions/create_guard.dart'; -export 'instructions/execute.dart'; -export 'instructions/initialize.dart'; -export 'instructions/update_guard.dart'; diff --git a/e2e/anchor/lib/generated/instructions/create_guard.dart b/e2e/anchor/lib/generated/instructions/create_guard.dart deleted file mode 100644 index c8e7046..0000000 --- a/e2e/anchor/lib/generated/instructions/create_guard.dart +++ /dev/null @@ -1,160 +0,0 @@ -/// This code was AUTOGENERATED using the codama library. -/// Please DO NOT EDIT THIS FILE, instead use visitors -/// to add features, then rerun codama to update it. -/// -/// https://github.com/codama-idl/codama -/// - -import 'dart:typed_data'; -import 'package:solana/encoder.dart'; -import 'package:solana/solana.dart'; -import '../programs.dart'; -import '../shared.dart'; -import '../types/cpi_rule.dart'; -import '../types/metadata_additional_field_rule.dart'; -import '../types/transfer_amount_rule.dart'; - -const List CREATE_GUARD_DISCRIMINATOR = [ - 251, - 254, - 17, - 198, - 219, - 218, - 154, - 99 -]; - -/// Generated instruction class for CreateGuard. -/// - -class CreateGuardInstruction { - // Accounts - // The guard account. - final Ed25519HDPublicKey guard; - - // The mint account. - final Ed25519HDPublicKey mint; - - // The mint_token_account account. - final Ed25519HDPublicKey mint_token_account; - - // The guard_authority account. - final Ed25519HDPublicKey guard_authority; - - // The payer account. - final Ed25519HDPublicKey payer; - - // The associated_token_program account. - final Ed25519HDPublicKey associated_token_program; - - // The token_program account. - final Ed25519HDPublicKey token_program; - - // The system_program account. - final Ed25519HDPublicKey system_program; - - // Args - final String name; - final String symbol; - final String uri; - final CpiRule? cpi_rule; - final TransferAmountRule? transfer_amount_rule; - final List additional_fields_rule; - - CreateGuardInstruction({ - required this.guard, - required this.mint, - required this.mint_token_account, - required this.guard_authority, - required this.payer, - required this.associated_token_program, - required this.token_program, - required this.system_program, - required this.name, - required this.symbol, - required this.uri, - required this.cpi_rule, - required this.transfer_amount_rule, - required this.additional_fields_rule, - }); - - /// Builds the `Instruction` (data = discriminator + args). - Instruction toInstruction({List remainingAccounts = const []}) { - final keys = [ - AccountMeta( - pubKey: guard, - isSigner: false, - isWriteable: true, - ), - AccountMeta( - pubKey: mint, - isSigner: true, - isWriteable: true, - ), - AccountMeta( - pubKey: mint_token_account, - isSigner: false, - isWriteable: true, - ), - AccountMeta( - pubKey: guard_authority, - isSigner: true, - isWriteable: false, - ), - AccountMeta( - pubKey: payer, - isSigner: true, - isWriteable: true, - ), - AccountMeta( - pubKey: associated_token_program, - isSigner: false, - isWriteable: false, - ), - AccountMeta( - pubKey: token_program, - isSigner: false, - isWriteable: false, - ), - AccountMeta( - pubKey: system_program, - isSigner: false, - isWriteable: false, - ), - ]; - - if (remainingAccounts.isNotEmpty) { - keys.addAll(remainingAccounts); - } - - // Serialize: discriminator (8 bytes) + args - final writer = BinaryWriter(); - writer.writeDiscriminator(Uint8List.fromList(CREATE_GUARD_DISCRIMINATOR)); - writer.writeString(name); - - writer.writeString(symbol); - - writer.writeString(uri); - - writer.writeU8(cpi_rule != null ? 1 : 0); - if (cpi_rule != null) { - cpi_rule!.toBorsh(writer); - } - writer.writeU8(transfer_amount_rule != null ? 1 : 0); - if (transfer_amount_rule != null) { - transfer_amount_rule!.toBorsh(writer); - } - writer.writeArray(additional_fields_rule, - (MetadataAdditionalFieldRule item) { - // Each item is a struct - item.toBorsh(writer); - }); - - return Instruction( - programId: WenTransferGuardProgram.programId, - accounts: keys, - data: ByteArray(writer.toBytes()), - ); - } -} diff --git a/e2e/anchor/lib/generated/instructions/execute.dart b/e2e/anchor/lib/generated/instructions/execute.dart deleted file mode 100644 index 7f21543..0000000 --- a/e2e/anchor/lib/generated/instructions/execute.dart +++ /dev/null @@ -1,111 +0,0 @@ -/// This code was AUTOGENERATED using the codama library. -/// Please DO NOT EDIT THIS FILE, instead use visitors -/// to add features, then rerun codama to update it. -/// -/// https://github.com/codama-idl/codama -/// - -import 'dart:typed_data'; -import 'package:solana/encoder.dart'; -import 'package:solana/solana.dart'; -import '../programs.dart'; -import '../shared.dart'; - -const List EXECUTE_DISCRIMINATOR = [105, 37, 101, 197, 75, 251, 102, 26]; - -/// Generated instruction class for Execute. -/// - -class ExecuteInstruction { - // Accounts - // The source_account account. - final Ed25519HDPublicKey source_account; - - // The mint account. - final Ed25519HDPublicKey mint; - - // The destination_account account. - final Ed25519HDPublicKey destination_account; - - // The owner_delegate account. - final Ed25519HDPublicKey owner_delegate; - - // The extra_metas_account account. - final Ed25519HDPublicKey extra_metas_account; - - // The guard account. - final Ed25519HDPublicKey guard; - - // The instruction_sysvar_account account. - final Ed25519HDPublicKey instruction_sysvar_account; - - // Args - final BigInt /* type: u64 */ amount; - - ExecuteInstruction({ - required this.source_account, - required this.mint, - required this.destination_account, - required this.owner_delegate, - required this.extra_metas_account, - required this.guard, - required this.instruction_sysvar_account, - required this.amount, - }); - - /// Builds the `Instruction` (data = discriminator + args). - Instruction toInstruction({List remainingAccounts = const []}) { - final keys = [ - AccountMeta( - pubKey: source_account, - isSigner: false, - isWriteable: false, - ), - AccountMeta( - pubKey: mint, - isSigner: false, - isWriteable: false, - ), - AccountMeta( - pubKey: destination_account, - isSigner: false, - isWriteable: false, - ), - AccountMeta( - pubKey: owner_delegate, - isSigner: false, - isWriteable: false, - ), - AccountMeta( - pubKey: extra_metas_account, - isSigner: false, - isWriteable: false, - ), - AccountMeta( - pubKey: guard, - isSigner: false, - isWriteable: false, - ), - AccountMeta( - pubKey: instruction_sysvar_account, - isSigner: false, - isWriteable: false, - ), - ]; - - if (remainingAccounts.isNotEmpty) { - keys.addAll(remainingAccounts); - } - - // Serialize: discriminator (8 bytes) + args - final writer = BinaryWriter(); - writer.writeDiscriminator(Uint8List.fromList(EXECUTE_DISCRIMINATOR)); - writer.writeU64(amount); - - return Instruction( - programId: WenTransferGuardProgram.programId, - accounts: keys, - data: ByteArray(writer.toBytes()), - ); - } -} diff --git a/e2e/anchor/lib/generated/instructions/initialize.dart b/e2e/anchor/lib/generated/instructions/initialize.dart deleted file mode 100644 index ffe3780..0000000 --- a/e2e/anchor/lib/generated/instructions/initialize.dart +++ /dev/null @@ -1,98 +0,0 @@ -/// This code was AUTOGENERATED using the codama library. -/// Please DO NOT EDIT THIS FILE, instead use visitors -/// to add features, then rerun codama to update it. -/// -/// https://github.com/codama-idl/codama -/// - -import 'dart:typed_data'; -import 'package:solana/encoder.dart'; -import 'package:solana/solana.dart'; -import '../programs.dart'; -import '../shared.dart'; - -const List INITIALIZE_DISCRIMINATOR = [43, 34, 13, 49, 167, 88, 235, 235]; - -/// Generated instruction class for Initialize. -/// - -class InitializeInstruction { - // Accounts - // The extra_metas_account account. - final Ed25519HDPublicKey extra_metas_account; - - // The guard account. - final Ed25519HDPublicKey guard; - - // The mint account. - final Ed25519HDPublicKey mint; - - // The transfer_hook_authority account. - final Ed25519HDPublicKey transfer_hook_authority; - - // The system_program account. - final Ed25519HDPublicKey system_program; - - // The payer account. - final Ed25519HDPublicKey payer; - - // Args - - InitializeInstruction({ - required this.extra_metas_account, - required this.guard, - required this.mint, - required this.transfer_hook_authority, - required this.system_program, - required this.payer, - }); - - /// Builds the `Instruction` (data = discriminator + args). - Instruction toInstruction({List remainingAccounts = const []}) { - final keys = [ - AccountMeta( - pubKey: extra_metas_account, - isSigner: false, - isWriteable: true, - ), - AccountMeta( - pubKey: guard, - isSigner: false, - isWriteable: false, - ), - AccountMeta( - pubKey: mint, - isSigner: false, - isWriteable: false, - ), - AccountMeta( - pubKey: transfer_hook_authority, - isSigner: true, - isWriteable: true, - ), - AccountMeta( - pubKey: system_program, - isSigner: false, - isWriteable: false, - ), - AccountMeta( - pubKey: payer, - isSigner: true, - isWriteable: true, - ), - ]; - - if (remainingAccounts.isNotEmpty) { - keys.addAll(remainingAccounts); - } - - // Serialize: discriminator (8 bytes) + args - final writer = BinaryWriter(); - writer.writeDiscriminator(Uint8List.fromList(INITIALIZE_DISCRIMINATOR)); - return Instruction( - programId: WenTransferGuardProgram.programId, - accounts: keys, - data: ByteArray(writer.toBytes()), - ); - } -} diff --git a/e2e/anchor/lib/generated/instructions/update_guard.dart b/e2e/anchor/lib/generated/instructions/update_guard.dart deleted file mode 100644 index 8ade019..0000000 --- a/e2e/anchor/lib/generated/instructions/update_guard.dart +++ /dev/null @@ -1,130 +0,0 @@ -/// This code was AUTOGENERATED using the codama library. -/// Please DO NOT EDIT THIS FILE, instead use visitors -/// to add features, then rerun codama to update it. -/// -/// https://github.com/codama-idl/codama -/// - -import 'dart:typed_data'; -import 'package:solana/encoder.dart'; -import 'package:solana/solana.dart'; -import '../programs.dart'; -import '../shared.dart'; -import '../types/cpi_rule.dart'; -import '../types/metadata_additional_field_rule.dart'; -import '../types/transfer_amount_rule.dart'; - -const List UPDATE_GUARD_DISCRIMINATOR = [ - 51, - 38, - 175, - 180, - 25, - 249, - 39, - 24 -]; - -/// Generated instruction class for UpdateGuard. -/// - -class UpdateGuardInstruction { - // Accounts - // The guard account. - final Ed25519HDPublicKey guard; - - // The mint account. - final Ed25519HDPublicKey mint; - - // The token_account account. - final Ed25519HDPublicKey token_account; - - // The guard_authority account. - final Ed25519HDPublicKey guard_authority; - - // The token_program account. - final Ed25519HDPublicKey token_program; - - // The system_program account. - final Ed25519HDPublicKey system_program; - - // Args - final CpiRule? cpi_rule; - final TransferAmountRule? transfer_amount_rule; - final List additional_fields_rule; - - UpdateGuardInstruction({ - required this.guard, - required this.mint, - required this.token_account, - required this.guard_authority, - required this.token_program, - required this.system_program, - required this.cpi_rule, - required this.transfer_amount_rule, - required this.additional_fields_rule, - }); - - /// Builds the `Instruction` (data = discriminator + args). - Instruction toInstruction({List remainingAccounts = const []}) { - final keys = [ - AccountMeta( - pubKey: guard, - isSigner: false, - isWriteable: true, - ), - AccountMeta( - pubKey: mint, - isSigner: false, - isWriteable: false, - ), - AccountMeta( - pubKey: token_account, - isSigner: false, - isWriteable: false, - ), - AccountMeta( - pubKey: guard_authority, - isSigner: true, - isWriteable: false, - ), - AccountMeta( - pubKey: token_program, - isSigner: false, - isWriteable: false, - ), - AccountMeta( - pubKey: system_program, - isSigner: false, - isWriteable: false, - ), - ]; - - if (remainingAccounts.isNotEmpty) { - keys.addAll(remainingAccounts); - } - - // Serialize: discriminator (8 bytes) + args - final writer = BinaryWriter(); - writer.writeDiscriminator(Uint8List.fromList(UPDATE_GUARD_DISCRIMINATOR)); - writer.writeU8(cpi_rule != null ? 1 : 0); - if (cpi_rule != null) { - cpi_rule!.toBorsh(writer); - } - writer.writeU8(transfer_amount_rule != null ? 1 : 0); - if (transfer_amount_rule != null) { - transfer_amount_rule!.toBorsh(writer); - } - writer.writeArray(additional_fields_rule, - (MetadataAdditionalFieldRule item) { - // Each item is a struct - item.toBorsh(writer); - }); - - return Instruction( - programId: WenTransferGuardProgram.programId, - accounts: keys, - data: ByteArray(writer.toBytes()), - ); - } -} diff --git a/e2e/anchor/lib/generated/lib.dart b/e2e/anchor/lib/generated/lib.dart deleted file mode 100644 index 1ea8243..0000000 --- a/e2e/anchor/lib/generated/lib.dart +++ /dev/null @@ -1,19 +0,0 @@ -/// This code was AUTOGENERATED using the codama library. -/// Please DO NOT EDIT THIS FILE, instead use visitors -/// to add features, then rerun codama to update it. -/// -/// https://github.com/codama-idl/codama -/// - -// Entry point for the SDK. -// This file exports all the modules in the SDK. - -export 'programs.dart'; - -export 'accounts.dart'; - -export 'instructions.dart'; - -export 'types.dart'; - -export 'shared.dart'; diff --git a/e2e/anchor/lib/generated/mod.dart b/e2e/anchor/lib/generated/mod.dart deleted file mode 100644 index 1ea8243..0000000 --- a/e2e/anchor/lib/generated/mod.dart +++ /dev/null @@ -1,19 +0,0 @@ -/// This code was AUTOGENERATED using the codama library. -/// Please DO NOT EDIT THIS FILE, instead use visitors -/// to add features, then rerun codama to update it. -/// -/// https://github.com/codama-idl/codama -/// - -// Entry point for the SDK. -// This file exports all the modules in the SDK. - -export 'programs.dart'; - -export 'accounts.dart'; - -export 'instructions.dart'; - -export 'types.dart'; - -export 'shared.dart'; diff --git a/e2e/anchor/lib/generated/programs.dart b/e2e/anchor/lib/generated/programs.dart deleted file mode 100644 index a392088..0000000 --- a/e2e/anchor/lib/generated/programs.dart +++ /dev/null @@ -1,20 +0,0 @@ -/// This code was AUTOGENERATED using the codama library. -/// Please DO NOT EDIT THIS FILE, instead use visitors -/// to add features, then rerun codama to update it. -/// -/// https://github.com/codama-idl/codama -/// - -// This file exports program information for all programs in the SDK. - -import 'package:solana/solana.dart'; - -/// Program information for the WenTransferGuard program. -class WenTransferGuardProgram { - /// The program ID for the WenTransferGuard program. - static final Ed25519HDPublicKey programId = Ed25519HDPublicKey.fromBase58( - "LockdqYQ9X2kwtWB99ioSbxubAmEi8o9jqYwbXgrrRw"); - - /// The program name. - static const String name = "wenTransferGuard"; -} diff --git a/e2e/anchor/lib/generated/shared.dart b/e2e/anchor/lib/generated/shared.dart deleted file mode 100644 index 6941969..0000000 --- a/e2e/anchor/lib/generated/shared.dart +++ /dev/null @@ -1,612 +0,0 @@ -/// This code was AUTOGENERATED using the codama library. -/// Please DO NOT EDIT THIS FILE, instead use visitors -/// to add features, then rerun codama to update it. -/// -/// https://github.com/codama-idl/codama -/// - -// Shared utilities and types for the SDK. - -import 'dart:convert'; -import 'dart:typed_data'; - -import 'package:solana/solana.dart'; - -/// Account not found error. -class AccountNotFoundError extends Error { - /// The address of the account that was not found. - final Ed25519HDPublicKey address; - - /// Creates a new AccountNotFoundError. - AccountNotFoundError(this.address); - - @override - String toString() => 'Account not found: $address'; -} - -/// Binary reader for decoding Borsh-encoded data. -class BinaryReader { - final ByteData - _data; // holds the raw binary data buffer, that i read from. Represents entire sequence of bytes. - - // Offset tracks the current byte position in the buffer; advance it after each read to ensure correct sequential decoding. - int _offset = 0; - - /// Creates a new BinaryReader. - BinaryReader(this._data); - - Uint8List readDiscriminator() { - final length = 8; // Discriminator is always the first 8 bytes - final bytes = - Uint8List.view(_data.buffer, _data.offsetInBytes + _offset, length); - _offset += length; - return bytes; - } - - /// Reads a single public key (32 raw bytes, no prefix). - Uint8List readPubkey() { - final length = 32; - final bytes = - Uint8List.view(_data.buffer, _data.offsetInBytes + _offset, length); - _offset += length; - return bytes; - } - - /// Reads a boolean value. - bool readBool() { - final value = _data.getUint8(_offset) != 0; - _offset += 1; - return value; - } - - /// Reads a int data type. - int readInt() { - final b0 = _data.getUint8(_offset); - final b1 = _data.getUint8(_offset + 1); - final b2 = _data.getUint8(_offset + 2); - final b3 = _data.getUint8(_offset + 3); - _offset += 4; - return b0 | (b1 << 8) | (b2 << 16) | (b3 << 24); - } - - BigInt readBigInt() { - BigInt result = BigInt.zero; - for (int i = 0; i < 16; i++) { - result |= BigInt.from(_data.getUint8(_offset + i)) << (8 * i); - } - _offset += 16; - return result; - } - - /// Reads an unsigned 8-bit integer. - int readU8() { - final value = _data.getUint8(_offset); - _offset += 1; - return value; - } - - /// Reads an unsigned 16-bit integer. - int readU16() { - final value = _data.getUint16(_offset, Endian.little); - _offset += 2; - return value; - } - - /// Reads an unsigned 32-bit integer. - int readU32() { - final value = _data.getUint32(_offset, Endian.little); - _offset += 4; - return value; - } - - /// Reads an unsigned 64-bit integer. - BigInt readU64() { - final low = _data.getUint32(_offset, Endian.little); - final high = _data.getUint32(_offset + 4, Endian.little); - _offset += 8; - return (BigInt.from(high) << 32) | BigInt.from(low); - } - - /// Reads a signed 8-bit integer. - int readI8() { - final value = _data.getInt8(_offset); - _offset += 1; - return value; - } - - /// Reads a signed 16-bit integer. - int readI16() { - final value = _data.getInt16(_offset, Endian.little); - _offset += 2; - return value; - } - - /// Reads a signed 32-bit integer. - int readI32() { - final value = _data.getInt32(_offset, Endian.little); - _offset += 4; - return value; - } - - /// Reads a signed 64-bit integer. - BigInt readI64() { - final low = _data.getUint32(_offset, Endian.little); - final high = _data.getInt32(_offset + 4, Endian.little); - _offset += 8; - return (BigInt.from(high) << 32) | BigInt.from(low); - } - - /// Reads a string. - String readString() { - final length = readU32(); - final bytes = - Uint8List.view(_data.buffer, _data.offsetInBytes + _offset, length); - _offset += length; - return utf8.decode(bytes); - } - - /// Reads a u8 array from Borsh data. If `length` is null, reads the length from a 4-byte prefix. - Uint8List readU8Array([int? length]) { - if (length == null) { - // Read the 4-byte little-endian length prefix (Borsh Vec) - length = _data.getUint32(_offset, Endian.little); - _offset += 4; - } - - return readAlignedArray( - 1, - length, - Uint8List.view, - 1, - (offset) => _data.getUint8(offset), - ); - } - - /// Reads a fixed-size i8 array of bytes. - Int8List readI8Array([int? length]) { - if (length == null) { - // Read the 4-byte little-endian length prefix (Borsh Vec) - length = _data.getUint32(_offset, Endian.little); - _offset += 4; - } - - return readAlignedArray( - 1, - length, - Int8List.view, - 1, - (offset) => _data.getInt8(offset), - ); - } - - /// Reads a fixed-size u16 array of bytes. - Uint16List readU16Array([int? length]) { - if (length == null) { - // Read the 4-byte little-endian length prefix (Borsh Vec) - length = _data.getUint32(_offset, Endian.little); - _offset += 4; - } - - return readAlignedArray( - 2, - length, - Uint16List.view, - 2, - (offset) => _data.getUint16(offset, Endian.little), - ); - } - - /// Reads a fixed-size i16 array of bytes. - Int16List readI16Array([int? length]) { - if (length == null) { - // Read the 4-byte little-endian length prefix (Borsh Vec) - length = _data.getUint32(_offset, Endian.little); - _offset += 4; - } - - return readAlignedArray( - 2, - length, - Int16List.view, - 2, - (offset) => _data.getInt16(offset, Endian.little), - ); - } - - /// Reads a fixed-size u32 array of bytes. - Uint32List readU32Array([int? length]) { - if (length == null) { - // Read the 4-byte little-endian length prefix (Borsh Vec) - length = _data.getUint32(_offset, Endian.little); - _offset += 4; - } - - return readAlignedArray( - 4, - length, - Uint32List.view, - 4, - (offset) => _data.getUint32(offset, Endian.little), - ); - } - - /// Reads a fixed-size i32 array of bytes. - Int32List readI32Array([int? length]) { - if (length == null) { - // Read the 4-byte little-endian length prefix (Borsh Vec) - length = _data.getUint32(_offset, Endian.little); - _offset += 4; - } - - return readAlignedArray( - 4, - length, - Int32List.view, - 4, - (offset) => _data.getInt32(offset, Endian.little), - ); - } - - /// Reads a fixed-size u64 array of bytes. - Uint64List readU64Array([int? length]) { - if (length == null) { - // Read the 4-byte little-endian length prefix (Borsh Vec) - length = _data.getUint32(_offset, Endian.little); - _offset += 4; - } - - return readAlignedArray( - 8, - length, - Uint64List.view, - 8, - (offset) => _data.getUint64(offset, Endian.little), - ); - } - - /// Reads a fixed-size i64 array of bytes. - Int64List readI64Array([int? length]) { - if (length == null) { - // Read the 4-byte little-endian length prefix (Borsh Vec) - length = _data.getUint32(_offset, Endian.little); - _offset += 4; - } - - return readAlignedArray( - 8, - length, - Int64List.view, - 8, - (offset) => _data.getInt64(offset, Endian.little), - ); - } - - // Reads a fixed-length array of generic items. - List readFixedArray(int length, T Function() itemReader) { - return List.generate(length, (_) => itemReader()); - } - - /// Reads a variable-length array of generic items. - List readArray(T Function() itemReader) { - final count = readU32(); - final result = []; - for (var i = 0; i < count; i++) { - result.add(itemReader()); - } - return result; - } - - /// Reads a variable-length array of bytes. - Uint8List readBytes() { - final length = readU32(); - return readU8Array(length); - } - - // ========= Utils for alignment-safe array reading ======== - - // This function handles the problem of buffer's offset that is not properly aligned for typed array views. - // It happens because i have fixed-size and prefixed-size arrays. - T readAlignedArray( - int alignment, - int length, - T Function(ByteBuffer buffer, int offset, int length) viewConstructor, - int bytesPerElement, - int Function(int offset) manualGetter, - ) { - // Check the offset alignment for `Uint*List.view` it should be multiple of element size - if ((_data.offsetInBytes + _offset) % alignment == 0) { - final arr = - viewConstructor(_data.buffer, _data.offsetInBytes + _offset, length); - _offset += length * bytesPerElement; - return arr; - } else { - // Manual read if not aligned - // For example, for Uint16List: - final arr = List.generate(length, (i) { - final value = manualGetter(_offset); - _offset += bytesPerElement; - return value; - }); - // Convert to typed list - if (T == Uint8List) return Uint8List.fromList(arr) as T; - if (T == Uint16List) return Uint16List.fromList(arr) as T; - if (T == Uint32List) return Uint32List.fromList(arr) as T; - if (T == Uint64List) return Uint64List.fromList(arr) as T; - if (T == Int8List) return Int8List.fromList(arr) as T; - if (T == Int16List) return Int16List.fromList(arr) as T; - if (T == Int32List) return Int32List.fromList(arr) as T; - if (T == Int64List) return Int64List.fromList(arr) as T; - // ...add more types as needed - return arr as T; - } - } -} - -/// Binary writer for encoding Borsh data. -class BinaryWriter { - final List _bytes = []; - - void writeDiscriminator(Uint8List discriminator) { - if (discriminator.length != 8) { - throw ArgumentError('Discriminator must be exactly 8 bytes'); - } - _bytes.addAll(discriminator); - } - - /// Writes a boolean value. - void writeBool(bool value) { - _bytes.add(value ? 1 : 0); - } - - void writeInt(int value) { - _bytes.addAll([ - value & 0xFF, - (value >> 8) & 0xFF, - (value >> 16) & 0xFF, - (value >> 24) & 0xFF, - ]); - } - - void writeBigInt(BigInt value) { - for (int i = 0; i < 16; i++) { - _bytes.add(((value >> (8 * i)) & BigInt.from(0xFF)).toInt()); - } - } - - /// Writes an unsigned 8-bit integer. - void writeU8(int value) { - _bytes.add(value & 0xFF); - } - - /// Writes an unsigned 16-bit integer. - void writeU16(int value) { - _bytes.addAll([ - value & 0xFF, - (value >> 8) & 0xFF, - ]); - } - - /// Writes an unsigned 32-bit integer. - void writeU32(int value) { - _bytes.addAll([ - value & 0xFF, - (value >> 8) & 0xFF, - (value >> 16) & 0xFF, - (value >> 24) & 0xFF, - ]); - } - - /// Writes an unsigned 64-bit integer. - void writeU64(BigInt value) { - final low = value & BigInt.from(0xFFFFFFFF); - final high = (value >> 32) & BigInt.from(0xFFFFFFFF); - - _bytes.addAll([ - low.toInt() & 0xFF, - (low.toInt() >> 8) & 0xFF, - (low.toInt() >> 16) & 0xFF, - (low.toInt() >> 24) & 0xFF, - high.toInt() & 0xFF, - (high.toInt() >> 8) & 0xFF, - (high.toInt() >> 16) & 0xFF, - (high.toInt() >> 24) & 0xFF, - ]); - } - - /// Writes a signed 8-bit integer. - void writeI8(int value) { - writeU8(value & 0xFF); - } - - /// Writes a signed 16-bit integer. - void writeI16(int value) { - writeU16(value & 0xFFFF); - } - - /// Writes a signed 32-bit integer. - void writeI32(int value) { - writeU32(value & 0xFFFFFFFF); - } - - /// Writes a signed 64-bit integer. - void writeI64(BigInt value) { - var v = value.toSigned(64); - for (int i = 0; i < 8; i++) { - _bytes.add(((v >> (8 * i)) & BigInt.from(0xFF)).toInt()); - } - } - - /// Writes a string. - void writeString(String value) { - final bytes = utf8.encode(value); - writeU32(bytes.length); - _bytes.addAll(bytes); - } - - /// Writes a fixed-size and prefixed-size u8 array of bytes. - void writeU8Array(Uint8List value, int? length) { - if (length == null) { - // Variable-length: write length prefix - writeU32(value.length); - for (final v in value) { - writeU8(v); - } - } else { - // Fixed-size: write exactly [length] elements, no prefix - for (int i = 0; i < length; i++) { - writeU8(value[i]); - } - } - } - - /// Writes a fixed-size and prefixed-size u8 array of bytes. - void writeI8Array(Int8List value, int? length) { - if (length == null) { - // Variable-length: write length prefix - writeU32(value.length); - for (final v in value) { - writeI8(v); - } - } else { - // Fixed-size: write exactly [length] elements, no prefix - for (int i = 0; i < length; i++) { - writeI8(value[i]); - } - } - } - - /// Writes a fixed-size and prefixed-size u16 array of bytes. - void writeU16Array(Uint16List value, int? length) { - if (length == null) { - // Variable-length: write length prefix - writeU32(value.length); - for (final v in value) { - writeU16(v); - } - } else { - // Fixed-size: write exactly [length] elements, no prefix - for (int i = 0; i < length; i++) { - writeU16(value[i]); - } - } - } - - /// Writes a fixed-size and prefixed-size i16 array of bytes. - void writeI16Array(Int16List value, int? length) { - if (length == null) { - // Variable-length: write length prefix - writeU32(value.length); - for (final v in value) { - writeI16(v); - } - } else { - // Fixed-size: write exactly [length] elements, no prefix - for (int i = 0; i < length; i++) { - writeI16(value[i]); - } - } - } - - /// Writes a fixed-size and prefixed-size i16 array of bytes. - void writeU32Array(Uint32List value, int? length) { - if (length == null) { - // Variable-length: write length prefix - writeU32(value.length); - for (final v in value) { - writeU32(v); - } - } else { - // Fixed-size: write exactly [length] elements, no prefix - for (int i = 0; i < length; i++) { - writeU32(value[i]); - } - } - } - - /// Writes a fixed-size i32 array of bytes. - void writeI32Array(Int32List value, int? length) { - if (length == null) { - // Variable-length: write length prefix - writeU32(value.length); - for (final v in value) { - writeI32(v); - } - } else { - // Fixed-size: write exactly [length] elements, no prefix - for (int i = 0; i < length; i++) { - writeI32(value[i]); - } - } - } - - /// Writes a fixed-size u64 array of bytes. - void writeU64Array(Uint64List value, int? length) { - if (length == null) { - // Variable-length: write length prefix - writeU32(value.length); - for (final v in value) { - writeU64(BigInt.from(v)); - } - } else { - // Fixed-size: write exactly [length] elements, no prefix - for (int i = 0; i < length; i++) { - writeU64(BigInt.from(value[i])); - } - } - } - - /// Writes a fixed-size i64 array of bytes. - void writeI64Array(Int64List value, int? length) { - if (length == null) { - // Variable-length: write length prefix - writeU32(value.length); - for (final v in value) { - writeI64(BigInt.from(v)); - } - } else { - // Fixed-size: write exactly [length] elements, no prefix - for (int i = 0; i < length; i++) { - writeI64(BigInt.from(value[i])); - } - } - } - - /// Writes a variable-length array of bytes. - void writeBytes(Uint8List value) { - writeU32(value.length); - _bytes.addAll(value); - } - - // Reads a fixed-length array of generic items. - // List readFixedArray(int length, T Function() itemReader) { - // return List.generate(length, (_) => itemReader()); - // } - - void writeFixedArray( - int length, List items, void Function(T) itemWriter) { - final count = length ?? items.length; - if (items.length < count) { - throw ArgumentError( - 'items length (${items.length}) is less than fixed array length ($count)'); - } - for (int i = 0; i < count; i++) { - itemWriter(items[i]); - } - } - - /// Writes a variable-length array of generic items. - void writeArray(List items, void Function(T) itemWriter) { - writeU32(items.length); - for (final item in items) { - itemWriter(item); - } - } - - /// Writes a single public key (32 raw bytes, no prefix). - void writePubkey(Uint8List pubkeyBytes) { - _bytes.addAll(pubkeyBytes); - } - - /// Returns the byte array. - Uint8List toBytes() => Uint8List.fromList(_bytes); -} diff --git a/e2e/anchor/lib/generated/types.dart b/e2e/anchor/lib/generated/types.dart deleted file mode 100644 index 1a323b5..0000000 --- a/e2e/anchor/lib/generated/types.dart +++ /dev/null @@ -1,13 +0,0 @@ -/// This code was AUTOGENERATED using the codama library. -/// Please DO NOT EDIT THIS FILE, instead use visitors -/// to add features, then rerun codama to update it. -/// -/// https://github.com/codama-idl/codama -/// - -// This file exports custom data types for the SDK. - -export 'types/cpi_rule.dart'; -export 'types/metadata_additional_field_restriction.dart'; -export 'types/metadata_additional_field_rule.dart'; -export 'types/transfer_amount_rule.dart'; diff --git a/e2e/anchor/lib/generated/types/cpi_rule.dart b/e2e/anchor/lib/generated/types/cpi_rule.dart deleted file mode 100644 index 4b978d4..0000000 --- a/e2e/anchor/lib/generated/types/cpi_rule.dart +++ /dev/null @@ -1,72 +0,0 @@ -/// This code was AUTOGENERATED using the codama library. -/// Please DO NOT EDIT THIS FILE, instead use visitors -/// to add features, then rerun codama to update it. -/// -/// https://github.com/codama-idl/codama -/// - -import 'dart:typed_data'; -import 'package:solana/solana.dart'; -import '../shared.dart'; - -/// Generated type definition for CpiRule. -/// -/// Controls which protocols can interact with the token by -/// enforcing Allow and Deny lists. - -abstract class CpiRule {} - -class Allow extends CpiRule { - final List value0; - - Allow(this.value0); -} - -class Deny extends CpiRule { - final List value0; - - Deny(this.value0); -} - -/// Extension providing serialization methods for CpiRule. -/// -extension CpiRuleBorsh on CpiRule { - /// Converts the enum to a byte representation. - void toBorsh(BinaryWriter writer) { - if (this is Allow) { - final v = this as Allow; - - writer.writeArray(v.value0, - (Ed25519HDPublicKey item) { - writer.writePubkey(Uint8List.fromList(item.bytes)); - ; - }); - } - if (this is Deny) { - final v = this as Deny; - - writer.writeArray(v.value0, - (Ed25519HDPublicKey item) { - writer.writePubkey(Uint8List.fromList(item.bytes)); - ; - }); - } - } - - /// Creates an enum from a byte representation. - static CpiRule fromBorsh(BinaryReader reader) { - final variant = reader.readU8(); - switch (variant) { - case 0: - return Allow(reader.readArray(() { - return Ed25519HDPublicKey(reader.readPubkey()); - })); - case 1: - return Deny(reader.readArray(() { - return Ed25519HDPublicKey(reader.readPubkey()); - })); - default: - throw Exception('Unknown cpiRule variant: $variant'); - } - } -} diff --git a/e2e/anchor/lib/generated/types/metadata_additional_field_restriction.dart b/e2e/anchor/lib/generated/types/metadata_additional_field_restriction.dart deleted file mode 100644 index b2ed4fe..0000000 --- a/e2e/anchor/lib/generated/types/metadata_additional_field_restriction.dart +++ /dev/null @@ -1,72 +0,0 @@ -/// This code was AUTOGENERATED using the codama library. -/// Please DO NOT EDIT THIS FILE, instead use visitors -/// to add features, then rerun codama to update it. -/// -/// https://github.com/codama-idl/codama -/// - -import 'dart:typed_data'; -import '../shared.dart'; - -/// Generated type definition for MetadataAdditionalFieldRestriction. -/// -/// Inner enum for the MetadataAdditionalFieldRestriction enum. -/// * Includes - The field must include one of the values in the vector. -/// * Excludes - The field must not include any of the values in the vector. - -abstract class MetadataAdditionalFieldRestriction {} - -class Includes extends MetadataAdditionalFieldRestriction { - final List value0; - - Includes(this.value0); -} - -class Excludes extends MetadataAdditionalFieldRestriction { - final List value0; - - Excludes(this.value0); -} - -/// Extension providing serialization methods for MetadataAdditionalFieldRestriction. -/// -extension MetadataAdditionalFieldRestrictionBorsh - on MetadataAdditionalFieldRestriction { - /// Converts the enum to a byte representation. - void toBorsh(BinaryWriter writer) { - if (this is Includes) { - final v = this as Includes; - - writer.writeArray(v.value0, (String item) { - writer.writeString(item); - ; - }); - } - if (this is Excludes) { - final v = this as Excludes; - - writer.writeArray(v.value0, (String item) { - writer.writeString(item); - ; - }); - } - } - - /// Creates an enum from a byte representation. - static MetadataAdditionalFieldRestriction fromBorsh(BinaryReader reader) { - final variant = reader.readU8(); - switch (variant) { - case 0: - return Includes(reader.readArray(() { - return reader.readString(); - })); - case 1: - return Excludes(reader.readArray(() { - return reader.readString(); - })); - default: - throw Exception( - 'Unknown metadataAdditionalFieldRestriction variant: $variant'); - } - } -} diff --git a/e2e/anchor/lib/generated/types/metadata_additional_field_rule.dart b/e2e/anchor/lib/generated/types/metadata_additional_field_rule.dart deleted file mode 100644 index 973246b..0000000 --- a/e2e/anchor/lib/generated/types/metadata_additional_field_rule.dart +++ /dev/null @@ -1,49 +0,0 @@ -/// This code was AUTOGENERATED using the codama library. -/// Please DO NOT EDIT THIS FILE, instead use visitors -/// to add features, then rerun codama to update it. -/// -/// https://github.com/codama-idl/codama -/// - -import 'dart:typed_data'; -import '../shared.dart'; -import '../types/metadata_additional_field_restriction.dart'; - -/// Generated type definition for MetadataAdditionalFieldRule. -/// -/// Enforces rules on a single additional field in the mint metadata. -/// The field must exist and the value must pass the restriction. - -class MetadataAdditionalFieldRule { - final String field; - final MetadataAdditionalFieldRestriction? value_restrictions; - - MetadataAdditionalFieldRule({ - required this.field, - required this.value_restrictions, - }); -} - -/// Extension providing serialization methods for MetadataAdditionalFieldRule. -/// -extension MetadataAdditionalFieldRuleBorsh on MetadataAdditionalFieldRule { - /// Serializes the struct to its byte representation. - void toBorsh(BinaryWriter writer) { - writer.writeString(field); - - writer.writeU8(value_restrictions != null ? 1 : 0); - if (value_restrictions != null) { - value_restrictions!.toBorsh(writer); - } - } - - /// Creates a struct from its byte representation. - static MetadataAdditionalFieldRule fromBorsh(BinaryReader reader) { - return MetadataAdditionalFieldRule( - field: reader.readString(), - value_restrictions: reader.readU8() == 1 - ? MetadataAdditionalFieldRestrictionBorsh.fromBorsh(reader) - : null, - ); - } -} diff --git a/e2e/anchor/lib/generated/types/transfer_amount_rule.dart b/e2e/anchor/lib/generated/types/transfer_amount_rule.dart deleted file mode 100644 index 1a7c748..0000000 --- a/e2e/anchor/lib/generated/types/transfer_amount_rule.dart +++ /dev/null @@ -1,88 +0,0 @@ -/// This code was AUTOGENERATED using the codama library. -/// Please DO NOT EDIT THIS FILE, instead use visitors -/// to add features, then rerun codama to update it. -/// -/// https://github.com/codama-idl/codama -/// - -import 'dart:typed_data'; -import '../shared.dart'; - -/// Generated type definition for TransferAmountRule. -/// -/// Enforces rules on the amount of tokens being transferred. -/// The rules can be above, below, equal to, or within a range. - -abstract class TransferAmountRule {} - -class Above extends TransferAmountRule { - final BigInt /* type: u64 */ value0; - - Above(this.value0); -} - -class Below extends TransferAmountRule { - final BigInt /* type: u64 */ value0; - - Below(this.value0); -} - -class Equal extends TransferAmountRule { - final BigInt /* type: u64 */ value0; - - Equal(this.value0); -} - -class Rang extends TransferAmountRule { - final BigInt /* type: u64 */ value0; - final BigInt /* type: u64 */ value1; - - Rang(this.value0, this.value1); -} - -/// Extension providing serialization methods for TransferAmountRule. -/// -extension TransferAmountRuleBorsh on TransferAmountRule { - /// Converts the enum to a byte representation. - void toBorsh(BinaryWriter writer) { - if (this is Above) { - final v = this as Above; - - writer.writeU64(v.value0); - } - if (this is Below) { - final v = this as Below; - - writer.writeU64(v.value0); - } - if (this is Equal) { - final v = this as Equal; - - writer.writeU64(v.value0); - } - if (this is Rang) { - final v = this as Rang; - - writer.writeU64(v.value0); - - writer.writeU64(v.value1); - } - } - - /// Creates an enum from a byte representation. - static TransferAmountRule fromBorsh(BinaryReader reader) { - final variant = reader.readU8(); - switch (variant) { - case 0: - return Above(reader.readU64()); - case 1: - return Below(reader.readU64()); - case 2: - return Equal(reader.readU64()); - case 3: - return Rang(reader.readU64(), reader.readU64()); - default: - throw Exception('Unknown transferAmountRule variant: $variant'); - } - } -} diff --git a/e2e/anchor/src/generated/accounts.dart b/e2e/anchor/src/generated/accounts.dart deleted file mode 100644 index 98c8416..0000000 --- a/e2e/anchor/src/generated/accounts.dart +++ /dev/null @@ -1,10 +0,0 @@ -/// This code was AUTOGENERATED using the codama library. -/// Please DO NOT EDIT THIS FILE, instead use visitors -/// to add features, then rerun codama to update it. -/// -/// https://github.com/codama-idl/codama -/// - -// This file exports account classes for all accounts in the SDK. - -export 'accounts/guard_v1.dart'; diff --git a/e2e/anchor/src/generated/accounts/guard_v1.dart b/e2e/anchor/src/generated/accounts/guard_v1.dart deleted file mode 100644 index 722c577..0000000 --- a/e2e/anchor/src/generated/accounts/guard_v1.dart +++ /dev/null @@ -1,137 +0,0 @@ -/// This code was AUTOGENERATED using the codama library. -/// Please DO NOT EDIT THIS FILE, instead use visitors -/// to add features, then rerun codama to update it. -/// -/// https://github.com/codama-idl/codama -/// - -import 'dart:typed_data'; -import 'package:collection/collection.dart'; -import 'package:solana/dto.dart'; -import 'package:solana/solana.dart'; -import '../shared.dart'; -import '../types/cpi_rule.dart'; -import '../types/metadata_additional_field_rule.dart'; -import '../types/transfer_amount_rule.dart'; - -const List GUARD_V1_DISCRIMINATOR = [185, 149, 156, 78, 245, 108, 172, 68]; - -/// Generated account class for GuardV1. -/// -class GuardV1 { - // Fields - final Ed25519HDPublicKey mint; - final int /* type: u8 */ bump; - final CpiRule? cpi_rule; - final TransferAmountRule? transfer_amount_rule; - final List additional_fields_rule; - - // Constructor - GuardV1({ - required this.mint, - required this.bump, - required this.cpi_rule, - required this.transfer_amount_rule, - required this.additional_fields_rule, - }); - - /// Deserializes this account from borsh. - static GuardV1 fromBorsh(BinaryReader reader) { - return GuardV1( - mint: Ed25519HDPublicKey(reader.readPubkey()), - bump: reader.readU8(), - cpi_rule: reader.readU8() == 1 ? CpiRuleBorsh.fromBorsh(reader) : null, - transfer_amount_rule: reader.readU8() == 1 - ? TransferAmountRuleBorsh.fromBorsh(reader) - : null, - additional_fields_rule: reader.readArray(() { - // item is a struct, call fromBorsh per item - return MetadataAdditionalFieldRuleBorsh.fromBorsh(reader); - }), - ); - } - - /// Serializes this account to borsh. - void toBorsh(BinaryWriter writer) { - writer.writePubkey(Uint8List.fromList(mint.bytes)); - - writer.writeU8(bump); - - writer.writeU8(cpi_rule != null ? 1 : 0); - if (cpi_rule != null) { - cpi_rule!.toBorsh(writer); - } - writer.writeU8(transfer_amount_rule != null ? 1 : 0); - if (transfer_amount_rule != null) { - transfer_amount_rule!.toBorsh(writer); - } - writer.writeArray(additional_fields_rule, - (MetadataAdditionalFieldRule item) { - // Each item is a struct - item.toBorsh(writer); - }); - } - - /// Creates a [GuardV1] from its bytes representation. - static GuardV1 fromBytes(Uint8List data) { - final buffer = ByteData.view(data.buffer); - final reader = BinaryReader(buffer); - - // Validate the discriminator - final discriminator = reader.readDiscriminator(); - if (!const ListEquality().equals(discriminator, GUARD_V1_DISCRIMINATOR)) { - throw FormatException('Invalid account discriminator'); - } - - return GuardV1.fromBorsh(reader); - } - - /// Serializes this account to its bytes representation. - Uint8List toBytes() { - final writer = BinaryWriter(); - - // Write discriminator - writer.writeDiscriminator(Uint8List.fromList(GUARD_V1_DISCRIMINATOR)); - - // Write account data - toBorsh(writer); - - return writer.toBytes(); - } - - /// Fetches a [GuardV1] from the blockchain. - static Future fetch( - RpcClient client, - Ed25519HDPublicKey address, - ) async { - final accountInfo = await client.getAccountInfo(address.toBase58(), - encoding: Encoding.base64); - final data = accountInfo.value?.data; - - if (data == null) { - throw AccountNotFoundError(address); - } - - if (data is! BinaryAccountData) { - throw FormatException( - 'Expected binary account data, got ${data.runtimeType}'); - } - - return fromBytes(Uint8List.fromList(data.data)); - } - - /// Fetches a [GuardV1] from the blockchain if it exists. - static Future fetchNullable( - RpcClient client, - Ed25519HDPublicKey address, - ) async { - try { - return await fetch(client, address); - } catch (e) { - if (e is AccountNotFoundError) { - return null; - } - rethrow; - } - } -} diff --git a/e2e/anchor/src/generated/errors.dart b/e2e/anchor/src/generated/errors.dart deleted file mode 100644 index a105376..0000000 --- a/e2e/anchor/src/generated/errors.dart +++ /dev/null @@ -1,8 +0,0 @@ -/// This code was AUTOGENERATED using the codama library. -/// Please DO NOT EDIT THIS FILE, instead use visitors -/// to add features, then rerun codama to update it. -/// -/// https://github.com/codama-idl/codama -/// - -// This file exports error classes for all programs in the SDK. diff --git a/e2e/anchor/src/generated/errors/wen_transfer_guard.dart b/e2e/anchor/src/generated/errors/wen_transfer_guard.dart deleted file mode 100644 index 1e633ed..0000000 --- a/e2e/anchor/src/generated/errors/wen_transfer_guard.dart +++ /dev/null @@ -1,161 +0,0 @@ -/// This code was AUTOGENERATED using the codama library. -/// Please DO NOT EDIT THIS FILE, instead use visitors -/// to add features, then rerun codama to update it. -/// -/// https://github.com/codama-idl/codama -/// - -/// Error codes for the WenTransferGuard program. -class WenTransferGuardErrorCode { - /// Cpi Rule Enforcement Failed - static const int CpiRuleEnforcementFailed = 0x1770; - - /// Transfer Amount Rule Enforce Failed - static const int TransferAmountRuleEnforceFailed = 0x1771; - - /// Metadata Field Does Not Exist - static const int MetadataFieldDoesNotExist = 0x1772; - - /// Metadata Field Does Not Pass - static const int MetadataFieldDoesNotPass = 0x1773; - - /// Guard token amount should be at least 1 - static const int GuardTokenAmountShouldBeAtLeastOne = 0x1774; - - /// Not owned by token 2022 program - static const int NotOwnedByToken2022Program = 0x1775; - - /// Must be initialized by Transfer Hook Authority - static const int MustBeInitializedByTransferHookAuthority = 0x1776; - - /// Mints assigned Transfer Hook Program is not this one - static const int MintAssignedTransferHookProgramIsNotThisOne = 0x1777; -} - -/// Base class for all WenTransferGuard program errors. -abstract class WenTransferGuardError extends Error { - /// The numerical error code. - final int code; - - /// Human-readable error message. - final String message; - - /// Creates a new WenTransferGuardError. - WenTransferGuardError(this.code, this.message); - - /// Creates a WenTransferGuardError from a raw error code. - static WenTransferGuardError fromCode(int code) { - switch (code) { - case WenTransferGuardErrorCode.CpiRuleEnforcementFailed: - return CpiRuleEnforcementFailedError(); - case WenTransferGuardErrorCode.TransferAmountRuleEnforceFailed: - return TransferAmountRuleEnforceFailedError(); - case WenTransferGuardErrorCode.MetadataFieldDoesNotExist: - return MetadataFieldDoesNotExistError(); - case WenTransferGuardErrorCode.MetadataFieldDoesNotPass: - return MetadataFieldDoesNotPassError(); - case WenTransferGuardErrorCode.GuardTokenAmountShouldBeAtLeastOne: - return GuardTokenAmountShouldBeAtLeastOneError(); - case WenTransferGuardErrorCode.NotOwnedByToken2022Program: - return NotOwnedByToken2022ProgramError(); - case WenTransferGuardErrorCode.MustBeInitializedByTransferHookAuthority: - return MustBeInitializedByTransferHookAuthorityError(); - case WenTransferGuardErrorCode - .MintAssignedTransferHookProgramIsNotThisOne: - return MintAssignedTransferHookProgramIsNotThisOneError(); - default: - return UnknownError(code); - } - } - - @override - String toString() => '$runtimeType: [$code] $message'; -} - -/// Represents an unknown error from the WenTransferGuard program. -class UnknownError extends WenTransferGuardError { - /// Creates a new UnknownError. - UnknownError(int code) : super(code, 'Unknown error'); -} - -/// Cpi Rule Enforcement Failed -class CpiRuleEnforcementFailedError extends WenTransferGuardError { - /// Creates a new CpiRuleEnforcementFailedError. - CpiRuleEnforcementFailedError() - : super( - WenTransferGuardErrorCode.CpiRuleEnforcementFailed, - 'Cpi Rule Enforcement Failed', - ); -} - -/// Transfer Amount Rule Enforce Failed -class TransferAmountRuleEnforceFailedError extends WenTransferGuardError { - /// Creates a new TransferAmountRuleEnforceFailedError. - TransferAmountRuleEnforceFailedError() - : super( - WenTransferGuardErrorCode.TransferAmountRuleEnforceFailed, - 'Transfer Amount Rule Enforce Failed', - ); -} - -/// Metadata Field Does Not Exist -class MetadataFieldDoesNotExistError extends WenTransferGuardError { - /// Creates a new MetadataFieldDoesNotExistError. - MetadataFieldDoesNotExistError() - : super( - WenTransferGuardErrorCode.MetadataFieldDoesNotExist, - 'Metadata Field Does Not Exist', - ); -} - -/// Metadata Field Does Not Pass -class MetadataFieldDoesNotPassError extends WenTransferGuardError { - /// Creates a new MetadataFieldDoesNotPassError. - MetadataFieldDoesNotPassError() - : super( - WenTransferGuardErrorCode.MetadataFieldDoesNotPass, - 'Metadata Field Does Not Pass', - ); -} - -/// Guard token amount should be at least 1 -class GuardTokenAmountShouldBeAtLeastOneError extends WenTransferGuardError { - /// Creates a new GuardTokenAmountShouldBeAtLeastOneError. - GuardTokenAmountShouldBeAtLeastOneError() - : super( - WenTransferGuardErrorCode.GuardTokenAmountShouldBeAtLeastOne, - 'Guard token amount should be at least 1', - ); -} - -/// Not owned by token 2022 program -class NotOwnedByToken2022ProgramError extends WenTransferGuardError { - /// Creates a new NotOwnedByToken2022ProgramError. - NotOwnedByToken2022ProgramError() - : super( - WenTransferGuardErrorCode.NotOwnedByToken2022Program, - 'Not owned by token 2022 program', - ); -} - -/// Must be initialized by Transfer Hook Authority -class MustBeInitializedByTransferHookAuthorityError - extends WenTransferGuardError { - /// Creates a new MustBeInitializedByTransferHookAuthorityError. - MustBeInitializedByTransferHookAuthorityError() - : super( - WenTransferGuardErrorCode.MustBeInitializedByTransferHookAuthority, - 'Must be initialized by Transfer Hook Authority', - ); -} - -/// Mints assigned Transfer Hook Program is not this one -class MintAssignedTransferHookProgramIsNotThisOneError - extends WenTransferGuardError { - /// Creates a new MintAssignedTransferHookProgramIsNotThisOneError. - MintAssignedTransferHookProgramIsNotThisOneError() - : super( - WenTransferGuardErrorCode.MintAssignedTransferHookProgramIsNotThisOne, - 'Mints assigned Transfer Hook Program is not this one', - ); -} diff --git a/e2e/anchor/src/generated/instructions.dart b/e2e/anchor/src/generated/instructions.dart deleted file mode 100644 index f9d3900..0000000 --- a/e2e/anchor/src/generated/instructions.dart +++ /dev/null @@ -1,13 +0,0 @@ -/// This code was AUTOGENERATED using the codama library. -/// Please DO NOT EDIT THIS FILE, instead use visitors -/// to add features, then rerun codama to update it. -/// -/// https://github.com/codama-idl/codama -/// - -// This file exports instruction classes for all instructions in the SDK. - -export 'instructions/create_guard.dart'; -export 'instructions/execute.dart'; -export 'instructions/initialize.dart'; -export 'instructions/update_guard.dart'; diff --git a/e2e/anchor/src/generated/instructions/create_guard.dart b/e2e/anchor/src/generated/instructions/create_guard.dart deleted file mode 100644 index c8e7046..0000000 --- a/e2e/anchor/src/generated/instructions/create_guard.dart +++ /dev/null @@ -1,160 +0,0 @@ -/// This code was AUTOGENERATED using the codama library. -/// Please DO NOT EDIT THIS FILE, instead use visitors -/// to add features, then rerun codama to update it. -/// -/// https://github.com/codama-idl/codama -/// - -import 'dart:typed_data'; -import 'package:solana/encoder.dart'; -import 'package:solana/solana.dart'; -import '../programs.dart'; -import '../shared.dart'; -import '../types/cpi_rule.dart'; -import '../types/metadata_additional_field_rule.dart'; -import '../types/transfer_amount_rule.dart'; - -const List CREATE_GUARD_DISCRIMINATOR = [ - 251, - 254, - 17, - 198, - 219, - 218, - 154, - 99 -]; - -/// Generated instruction class for CreateGuard. -/// - -class CreateGuardInstruction { - // Accounts - // The guard account. - final Ed25519HDPublicKey guard; - - // The mint account. - final Ed25519HDPublicKey mint; - - // The mint_token_account account. - final Ed25519HDPublicKey mint_token_account; - - // The guard_authority account. - final Ed25519HDPublicKey guard_authority; - - // The payer account. - final Ed25519HDPublicKey payer; - - // The associated_token_program account. - final Ed25519HDPublicKey associated_token_program; - - // The token_program account. - final Ed25519HDPublicKey token_program; - - // The system_program account. - final Ed25519HDPublicKey system_program; - - // Args - final String name; - final String symbol; - final String uri; - final CpiRule? cpi_rule; - final TransferAmountRule? transfer_amount_rule; - final List additional_fields_rule; - - CreateGuardInstruction({ - required this.guard, - required this.mint, - required this.mint_token_account, - required this.guard_authority, - required this.payer, - required this.associated_token_program, - required this.token_program, - required this.system_program, - required this.name, - required this.symbol, - required this.uri, - required this.cpi_rule, - required this.transfer_amount_rule, - required this.additional_fields_rule, - }); - - /// Builds the `Instruction` (data = discriminator + args). - Instruction toInstruction({List remainingAccounts = const []}) { - final keys = [ - AccountMeta( - pubKey: guard, - isSigner: false, - isWriteable: true, - ), - AccountMeta( - pubKey: mint, - isSigner: true, - isWriteable: true, - ), - AccountMeta( - pubKey: mint_token_account, - isSigner: false, - isWriteable: true, - ), - AccountMeta( - pubKey: guard_authority, - isSigner: true, - isWriteable: false, - ), - AccountMeta( - pubKey: payer, - isSigner: true, - isWriteable: true, - ), - AccountMeta( - pubKey: associated_token_program, - isSigner: false, - isWriteable: false, - ), - AccountMeta( - pubKey: token_program, - isSigner: false, - isWriteable: false, - ), - AccountMeta( - pubKey: system_program, - isSigner: false, - isWriteable: false, - ), - ]; - - if (remainingAccounts.isNotEmpty) { - keys.addAll(remainingAccounts); - } - - // Serialize: discriminator (8 bytes) + args - final writer = BinaryWriter(); - writer.writeDiscriminator(Uint8List.fromList(CREATE_GUARD_DISCRIMINATOR)); - writer.writeString(name); - - writer.writeString(symbol); - - writer.writeString(uri); - - writer.writeU8(cpi_rule != null ? 1 : 0); - if (cpi_rule != null) { - cpi_rule!.toBorsh(writer); - } - writer.writeU8(transfer_amount_rule != null ? 1 : 0); - if (transfer_amount_rule != null) { - transfer_amount_rule!.toBorsh(writer); - } - writer.writeArray(additional_fields_rule, - (MetadataAdditionalFieldRule item) { - // Each item is a struct - item.toBorsh(writer); - }); - - return Instruction( - programId: WenTransferGuardProgram.programId, - accounts: keys, - data: ByteArray(writer.toBytes()), - ); - } -} diff --git a/e2e/anchor/src/generated/instructions/execute.dart b/e2e/anchor/src/generated/instructions/execute.dart deleted file mode 100644 index 7f21543..0000000 --- a/e2e/anchor/src/generated/instructions/execute.dart +++ /dev/null @@ -1,111 +0,0 @@ -/// This code was AUTOGENERATED using the codama library. -/// Please DO NOT EDIT THIS FILE, instead use visitors -/// to add features, then rerun codama to update it. -/// -/// https://github.com/codama-idl/codama -/// - -import 'dart:typed_data'; -import 'package:solana/encoder.dart'; -import 'package:solana/solana.dart'; -import '../programs.dart'; -import '../shared.dart'; - -const List EXECUTE_DISCRIMINATOR = [105, 37, 101, 197, 75, 251, 102, 26]; - -/// Generated instruction class for Execute. -/// - -class ExecuteInstruction { - // Accounts - // The source_account account. - final Ed25519HDPublicKey source_account; - - // The mint account. - final Ed25519HDPublicKey mint; - - // The destination_account account. - final Ed25519HDPublicKey destination_account; - - // The owner_delegate account. - final Ed25519HDPublicKey owner_delegate; - - // The extra_metas_account account. - final Ed25519HDPublicKey extra_metas_account; - - // The guard account. - final Ed25519HDPublicKey guard; - - // The instruction_sysvar_account account. - final Ed25519HDPublicKey instruction_sysvar_account; - - // Args - final BigInt /* type: u64 */ amount; - - ExecuteInstruction({ - required this.source_account, - required this.mint, - required this.destination_account, - required this.owner_delegate, - required this.extra_metas_account, - required this.guard, - required this.instruction_sysvar_account, - required this.amount, - }); - - /// Builds the `Instruction` (data = discriminator + args). - Instruction toInstruction({List remainingAccounts = const []}) { - final keys = [ - AccountMeta( - pubKey: source_account, - isSigner: false, - isWriteable: false, - ), - AccountMeta( - pubKey: mint, - isSigner: false, - isWriteable: false, - ), - AccountMeta( - pubKey: destination_account, - isSigner: false, - isWriteable: false, - ), - AccountMeta( - pubKey: owner_delegate, - isSigner: false, - isWriteable: false, - ), - AccountMeta( - pubKey: extra_metas_account, - isSigner: false, - isWriteable: false, - ), - AccountMeta( - pubKey: guard, - isSigner: false, - isWriteable: false, - ), - AccountMeta( - pubKey: instruction_sysvar_account, - isSigner: false, - isWriteable: false, - ), - ]; - - if (remainingAccounts.isNotEmpty) { - keys.addAll(remainingAccounts); - } - - // Serialize: discriminator (8 bytes) + args - final writer = BinaryWriter(); - writer.writeDiscriminator(Uint8List.fromList(EXECUTE_DISCRIMINATOR)); - writer.writeU64(amount); - - return Instruction( - programId: WenTransferGuardProgram.programId, - accounts: keys, - data: ByteArray(writer.toBytes()), - ); - } -} diff --git a/e2e/anchor/src/generated/instructions/initialize.dart b/e2e/anchor/src/generated/instructions/initialize.dart deleted file mode 100644 index ffe3780..0000000 --- a/e2e/anchor/src/generated/instructions/initialize.dart +++ /dev/null @@ -1,98 +0,0 @@ -/// This code was AUTOGENERATED using the codama library. -/// Please DO NOT EDIT THIS FILE, instead use visitors -/// to add features, then rerun codama to update it. -/// -/// https://github.com/codama-idl/codama -/// - -import 'dart:typed_data'; -import 'package:solana/encoder.dart'; -import 'package:solana/solana.dart'; -import '../programs.dart'; -import '../shared.dart'; - -const List INITIALIZE_DISCRIMINATOR = [43, 34, 13, 49, 167, 88, 235, 235]; - -/// Generated instruction class for Initialize. -/// - -class InitializeInstruction { - // Accounts - // The extra_metas_account account. - final Ed25519HDPublicKey extra_metas_account; - - // The guard account. - final Ed25519HDPublicKey guard; - - // The mint account. - final Ed25519HDPublicKey mint; - - // The transfer_hook_authority account. - final Ed25519HDPublicKey transfer_hook_authority; - - // The system_program account. - final Ed25519HDPublicKey system_program; - - // The payer account. - final Ed25519HDPublicKey payer; - - // Args - - InitializeInstruction({ - required this.extra_metas_account, - required this.guard, - required this.mint, - required this.transfer_hook_authority, - required this.system_program, - required this.payer, - }); - - /// Builds the `Instruction` (data = discriminator + args). - Instruction toInstruction({List remainingAccounts = const []}) { - final keys = [ - AccountMeta( - pubKey: extra_metas_account, - isSigner: false, - isWriteable: true, - ), - AccountMeta( - pubKey: guard, - isSigner: false, - isWriteable: false, - ), - AccountMeta( - pubKey: mint, - isSigner: false, - isWriteable: false, - ), - AccountMeta( - pubKey: transfer_hook_authority, - isSigner: true, - isWriteable: true, - ), - AccountMeta( - pubKey: system_program, - isSigner: false, - isWriteable: false, - ), - AccountMeta( - pubKey: payer, - isSigner: true, - isWriteable: true, - ), - ]; - - if (remainingAccounts.isNotEmpty) { - keys.addAll(remainingAccounts); - } - - // Serialize: discriminator (8 bytes) + args - final writer = BinaryWriter(); - writer.writeDiscriminator(Uint8List.fromList(INITIALIZE_DISCRIMINATOR)); - return Instruction( - programId: WenTransferGuardProgram.programId, - accounts: keys, - data: ByteArray(writer.toBytes()), - ); - } -} diff --git a/e2e/anchor/src/generated/instructions/update_guard.dart b/e2e/anchor/src/generated/instructions/update_guard.dart deleted file mode 100644 index 8ade019..0000000 --- a/e2e/anchor/src/generated/instructions/update_guard.dart +++ /dev/null @@ -1,130 +0,0 @@ -/// This code was AUTOGENERATED using the codama library. -/// Please DO NOT EDIT THIS FILE, instead use visitors -/// to add features, then rerun codama to update it. -/// -/// https://github.com/codama-idl/codama -/// - -import 'dart:typed_data'; -import 'package:solana/encoder.dart'; -import 'package:solana/solana.dart'; -import '../programs.dart'; -import '../shared.dart'; -import '../types/cpi_rule.dart'; -import '../types/metadata_additional_field_rule.dart'; -import '../types/transfer_amount_rule.dart'; - -const List UPDATE_GUARD_DISCRIMINATOR = [ - 51, - 38, - 175, - 180, - 25, - 249, - 39, - 24 -]; - -/// Generated instruction class for UpdateGuard. -/// - -class UpdateGuardInstruction { - // Accounts - // The guard account. - final Ed25519HDPublicKey guard; - - // The mint account. - final Ed25519HDPublicKey mint; - - // The token_account account. - final Ed25519HDPublicKey token_account; - - // The guard_authority account. - final Ed25519HDPublicKey guard_authority; - - // The token_program account. - final Ed25519HDPublicKey token_program; - - // The system_program account. - final Ed25519HDPublicKey system_program; - - // Args - final CpiRule? cpi_rule; - final TransferAmountRule? transfer_amount_rule; - final List additional_fields_rule; - - UpdateGuardInstruction({ - required this.guard, - required this.mint, - required this.token_account, - required this.guard_authority, - required this.token_program, - required this.system_program, - required this.cpi_rule, - required this.transfer_amount_rule, - required this.additional_fields_rule, - }); - - /// Builds the `Instruction` (data = discriminator + args). - Instruction toInstruction({List remainingAccounts = const []}) { - final keys = [ - AccountMeta( - pubKey: guard, - isSigner: false, - isWriteable: true, - ), - AccountMeta( - pubKey: mint, - isSigner: false, - isWriteable: false, - ), - AccountMeta( - pubKey: token_account, - isSigner: false, - isWriteable: false, - ), - AccountMeta( - pubKey: guard_authority, - isSigner: true, - isWriteable: false, - ), - AccountMeta( - pubKey: token_program, - isSigner: false, - isWriteable: false, - ), - AccountMeta( - pubKey: system_program, - isSigner: false, - isWriteable: false, - ), - ]; - - if (remainingAccounts.isNotEmpty) { - keys.addAll(remainingAccounts); - } - - // Serialize: discriminator (8 bytes) + args - final writer = BinaryWriter(); - writer.writeDiscriminator(Uint8List.fromList(UPDATE_GUARD_DISCRIMINATOR)); - writer.writeU8(cpi_rule != null ? 1 : 0); - if (cpi_rule != null) { - cpi_rule!.toBorsh(writer); - } - writer.writeU8(transfer_amount_rule != null ? 1 : 0); - if (transfer_amount_rule != null) { - transfer_amount_rule!.toBorsh(writer); - } - writer.writeArray(additional_fields_rule, - (MetadataAdditionalFieldRule item) { - // Each item is a struct - item.toBorsh(writer); - }); - - return Instruction( - programId: WenTransferGuardProgram.programId, - accounts: keys, - data: ByteArray(writer.toBytes()), - ); - } -} diff --git a/e2e/anchor/src/generated/lib.dart b/e2e/anchor/src/generated/lib.dart deleted file mode 100644 index 1ea8243..0000000 --- a/e2e/anchor/src/generated/lib.dart +++ /dev/null @@ -1,19 +0,0 @@ -/// This code was AUTOGENERATED using the codama library. -/// Please DO NOT EDIT THIS FILE, instead use visitors -/// to add features, then rerun codama to update it. -/// -/// https://github.com/codama-idl/codama -/// - -// Entry point for the SDK. -// This file exports all the modules in the SDK. - -export 'programs.dart'; - -export 'accounts.dart'; - -export 'instructions.dart'; - -export 'types.dart'; - -export 'shared.dart'; diff --git a/e2e/anchor/src/generated/mod.dart b/e2e/anchor/src/generated/mod.dart deleted file mode 100644 index 1ea8243..0000000 --- a/e2e/anchor/src/generated/mod.dart +++ /dev/null @@ -1,19 +0,0 @@ -/// This code was AUTOGENERATED using the codama library. -/// Please DO NOT EDIT THIS FILE, instead use visitors -/// to add features, then rerun codama to update it. -/// -/// https://github.com/codama-idl/codama -/// - -// Entry point for the SDK. -// This file exports all the modules in the SDK. - -export 'programs.dart'; - -export 'accounts.dart'; - -export 'instructions.dart'; - -export 'types.dart'; - -export 'shared.dart'; diff --git a/e2e/anchor/src/generated/programs.dart b/e2e/anchor/src/generated/programs.dart deleted file mode 100644 index a392088..0000000 --- a/e2e/anchor/src/generated/programs.dart +++ /dev/null @@ -1,20 +0,0 @@ -/// This code was AUTOGENERATED using the codama library. -/// Please DO NOT EDIT THIS FILE, instead use visitors -/// to add features, then rerun codama to update it. -/// -/// https://github.com/codama-idl/codama -/// - -// This file exports program information for all programs in the SDK. - -import 'package:solana/solana.dart'; - -/// Program information for the WenTransferGuard program. -class WenTransferGuardProgram { - /// The program ID for the WenTransferGuard program. - static final Ed25519HDPublicKey programId = Ed25519HDPublicKey.fromBase58( - "LockdqYQ9X2kwtWB99ioSbxubAmEi8o9jqYwbXgrrRw"); - - /// The program name. - static const String name = "wenTransferGuard"; -} diff --git a/e2e/anchor/src/generated/shared.dart b/e2e/anchor/src/generated/shared.dart deleted file mode 100644 index ef6c923..0000000 --- a/e2e/anchor/src/generated/shared.dart +++ /dev/null @@ -1,587 +0,0 @@ -/// This code was AUTOGENERATED using the codama library. -/// Please DO NOT EDIT THIS FILE, instead use visitors -/// to add features, then rerun codama to update it. -/// -/// https://github.com/codama-idl/codama -/// - -// Shared utilities and types for the SDK. - -import 'dart:convert'; -import 'dart:typed_data'; - -import 'package:solana/solana.dart'; - -/// Account not found error. -class AccountNotFoundError extends Error { - /// The address of the account that was not found. - final Ed25519HDPublicKey address; - - /// Creates a new AccountNotFoundError. - AccountNotFoundError(this.address); - - @override - String toString() => 'Account not found: $address'; -} - -/// Binary reader for decoding Borsh-encoded data. -class BinaryReader { - final ByteData - _data; // holds the raw binary data buffer, that i read from. Represents entire sequence of bytes. - - // Offset tracks the current byte position in the buffer; advance it after each read to ensure correct sequential decoding. - int _offset = 0; - - /// Creates a new BinaryReader. - BinaryReader(this._data); - - Uint8List readDiscriminator() { - final length = 8; // Discriminator is always the first 8 bytes - final bytes = - Uint8List.view(_data.buffer, _data.offsetInBytes + _offset, length); - _offset += length; - return bytes; - } - - /// Reads a single public key (32 raw bytes, no prefix). - Uint8List readPubkey() { - final length = 32; - final bytes = - Uint8List.view(_data.buffer, _data.offsetInBytes + _offset, length); - _offset += length; - return bytes; - } - - /// Reads a boolean value. - bool readBool() { - final value = _data.getUint8(_offset) != 0; - _offset += 1; - return value; - } - - /// Reads a int data type. - int readInt() { - final b0 = _data.getUint8(_offset); - final b1 = _data.getUint8(_offset + 1); - final b2 = _data.getUint8(_offset + 2); - final b3 = _data.getUint8(_offset + 3); - _offset += 4; - return b0 | (b1 << 8) | (b2 << 16) | (b3 << 24); - } - - BigInt readBigInt() { - BigInt result = BigInt.zero; - for (int i = 0; i < 16; i++) { - result |= BigInt.from(_data.getUint8(_offset + i)) << (8 * i); - } - _offset += 16; - return result; - } - - /// Reads an unsigned 8-bit integer. - int readU8() { - final value = _data.getUint8(_offset); - _offset += 1; - return value; - } - - /// Reads an unsigned 16-bit integer. - int readU16() { - final value = _data.getUint16(_offset, Endian.little); - _offset += 2; - return value; - } - - /// Reads an unsigned 32-bit integer. - int readU32() { - final value = _data.getUint32(_offset, Endian.little); - _offset += 4; - return value; - } - - /// Reads an unsigned 64-bit integer. - BigInt readU64() { - final low = _data.getUint32(_offset, Endian.little); - final high = _data.getUint32(_offset + 4, Endian.little); - _offset += 8; - return (BigInt.from(high) << 32) | BigInt.from(low); - } - - /// Reads a signed 8-bit integer. - int readI8() { - final value = _data.getInt8(_offset); - _offset += 1; - return value; - } - - /// Reads a signed 16-bit integer. - int readI16() { - final value = _data.getInt16(_offset, Endian.little); - _offset += 2; - return value; - } - - /// Reads a signed 32-bit integer. - int readI32() { - final value = _data.getInt32(_offset, Endian.little); - _offset += 4; - return value; - } - - /// Reads a signed 64-bit integer. - BigInt readI64() { - final low = _data.getUint32(_offset, Endian.little); - final high = _data.getInt32(_offset + 4, Endian.little); - _offset += 8; - return (BigInt.from(high) << 32) | BigInt.from(low); - } - - /// Reads a string. - String readString() { - final length = readU32(); - final bytes = - Uint8List.view(_data.buffer, _data.offsetInBytes + _offset, length); - _offset += length; - return utf8.decode(bytes); - } - - /// Reads a u8 array from Borsh data. If `length` is null, reads the length from a 4-byte prefix. - Uint8List readU8Array([int? length]) { - if (length == null) { - // Read the 4-byte little-endian length prefix (Borsh Vec) - length = _data.getUint32(_offset, Endian.little); - _offset += 4; - } - - return readAlignedArray( - 1, - length, - Uint8List.view, - 1, - (offset) => _data.getUint8(offset), - ); - } - - /// Reads a fixed-size i8 array of bytes. - Int8List readI8Array([int? length]) { - if (length == null) { - // Read the 4-byte little-endian length prefix (Borsh Vec) - length = _data.getUint32(_offset, Endian.little); - _offset += 4; - } - - return readAlignedArray( - 1, - length, - Int8List.view, - 1, - (offset) => _data.getInt8(offset), - ); - } - - /// Reads a fixed-size u16 array of bytes. - Uint16List readU16Array([int? length]) { - if (length == null) { - // Read the 4-byte little-endian length prefix (Borsh Vec) - length = _data.getUint32(_offset, Endian.little); - _offset += 4; - } - - return readAlignedArray( - 2, - length, - Uint16List.view, - 2, - (offset) => _data.getUint16(offset, Endian.little), - ); - } - - /// Reads a fixed-size i16 array of bytes. - Int16List readI16Array([int? length]) { - if (length == null) { - // Read the 4-byte little-endian length prefix (Borsh Vec) - length = _data.getUint32(_offset, Endian.little); - _offset += 4; - } - - return readAlignedArray( - 2, - length, - Int16List.view, - 2, - (offset) => _data.getInt16(offset, Endian.little), - ); - } - - /// Reads a fixed-size u32 array of bytes. - Uint32List readU32Array([int? length]) { - if (length == null) { - // Read the 4-byte little-endian length prefix (Borsh Vec) - length = _data.getUint32(_offset, Endian.little); - _offset += 4; - } - - return readAlignedArray( - 4, - length, - Uint32List.view, - 4, - (offset) => _data.getUint32(offset, Endian.little), - ); - } - - /// Reads a fixed-size i32 array of bytes. - Int32List readI32Array([int? length]) { - if (length == null) { - // Read the 4-byte little-endian length prefix (Borsh Vec) - length = _data.getUint32(_offset, Endian.little); - _offset += 4; - } - - return readAlignedArray( - 4, - length, - Int32List.view, - 4, - (offset) => _data.getInt32(offset, Endian.little), - ); - } - - /// Reads a fixed-size u64 array of bytes. - Uint64List readU64Array([int? length]) { - if (length == null) { - // Read the 4-byte little-endian length prefix (Borsh Vec) - length = _data.getUint32(_offset, Endian.little); - _offset += 4; - } - - return readAlignedArray( - 8, - length, - Uint64List.view, - 8, - (offset) => _data.getUint64(offset, Endian.little), - ); - } - - /// Reads a fixed-size i64 array of bytes. - Int64List readI64Array([int? length]) { - if (length == null) { - // Read the 4-byte little-endian length prefix (Borsh Vec) - length = _data.getUint32(_offset, Endian.little); - _offset += 4; - } - - return readAlignedArray( - 8, - length, - Int64List.view, - 8, - (offset) => _data.getInt64(offset, Endian.little), - ); - } - - /// Reads a variable-length array of generic items. - List readArray(T Function() itemReader) { - final count = readU32(); - final result = []; - for (var i = 0; i < count; i++) { - result.add(itemReader()); - } - return result; - } - - /// Reads a variable-length array of bytes. - Uint8List readBytes() { - final length = readU32(); - return readU8Array(length); - } - - // ========= Utils for alignment-safe array reading ======== - - // This function handles the problem of buffer's offset that is not properly aligned for typed array views. - // It happens because i have fixed-size and prefixed-size arrays. - T readAlignedArray( - int alignment, - int length, - T Function(ByteBuffer buffer, int offset, int length) viewConstructor, - int bytesPerElement, - int Function(int offset) manualGetter, - ) { - // Check the offset alignment for `Uint*List.view` it should be multiple of element size - if ((_data.offsetInBytes + _offset) % alignment == 0) { - final arr = - viewConstructor(_data.buffer, _data.offsetInBytes + _offset, length); - _offset += length * bytesPerElement; - return arr; - } else { - // Manual read if not aligned - // For example, for Uint16List: - final arr = List.generate(length, (i) { - final value = manualGetter(_offset); - _offset += bytesPerElement; - return value; - }); - // Convert to typed list - if (T == Uint8List) return Uint8List.fromList(arr) as T; - if (T == Uint16List) return Uint16List.fromList(arr) as T; - if (T == Uint32List) return Uint32List.fromList(arr) as T; - if (T == Uint64List) return Uint64List.fromList(arr) as T; - if (T == Int8List) return Int8List.fromList(arr) as T; - if (T == Int16List) return Int16List.fromList(arr) as T; - if (T == Int32List) return Int32List.fromList(arr) as T; - if (T == Int64List) return Int64List.fromList(arr) as T; - // ...add more types as needed - return arr as T; - } - } -} - -/// Binary writer for encoding Borsh data. -class BinaryWriter { - final List _bytes = []; - - void writeDiscriminator(Uint8List discriminator) { - if (discriminator.length != 8) { - throw ArgumentError('Discriminator must be exactly 8 bytes'); - } - _bytes.addAll(discriminator); - } - - /// Writes a boolean value. - void writeBool(bool value) { - _bytes.add(value ? 1 : 0); - } - - void writeInt(int value) { - _bytes.addAll([ - value & 0xFF, - (value >> 8) & 0xFF, - (value >> 16) & 0xFF, - (value >> 24) & 0xFF, - ]); - } - - void writeBigInt(BigInt value) { - for (int i = 0; i < 16; i++) { - _bytes.add(((value >> (8 * i)) & BigInt.from(0xFF)).toInt()); - } - } - - /// Writes an unsigned 8-bit integer. - void writeU8(int value) { - _bytes.add(value & 0xFF); - } - - /// Writes an unsigned 16-bit integer. - void writeU16(int value) { - _bytes.addAll([ - value & 0xFF, - (value >> 8) & 0xFF, - ]); - } - - /// Writes an unsigned 32-bit integer. - void writeU32(int value) { - _bytes.addAll([ - value & 0xFF, - (value >> 8) & 0xFF, - (value >> 16) & 0xFF, - (value >> 24) & 0xFF, - ]); - } - - /// Writes an unsigned 64-bit integer. - void writeU64(BigInt value) { - final low = value & BigInt.from(0xFFFFFFFF); - final high = (value >> 32) & BigInt.from(0xFFFFFFFF); - - _bytes.addAll([ - low.toInt() & 0xFF, - (low.toInt() >> 8) & 0xFF, - (low.toInt() >> 16) & 0xFF, - (low.toInt() >> 24) & 0xFF, - high.toInt() & 0xFF, - (high.toInt() >> 8) & 0xFF, - (high.toInt() >> 16) & 0xFF, - (high.toInt() >> 24) & 0xFF, - ]); - } - - /// Writes a signed 8-bit integer. - void writeI8(int value) { - writeU8(value & 0xFF); - } - - /// Writes a signed 16-bit integer. - void writeI16(int value) { - writeU16(value & 0xFFFF); - } - - /// Writes a signed 32-bit integer. - void writeI32(int value) { - writeU32(value & 0xFFFFFFFF); - } - - /// Writes a signed 64-bit integer. - void writeI64(BigInt value) { - writeU64(value & (BigInt.one << 64) - BigInt.one); - } - - /// Writes a string. - void writeString(String value) { - final bytes = utf8.encode(value); - writeU32(bytes.length); - _bytes.addAll(bytes); - } - - /// Writes a fixed-size and prefixed-size u8 array of bytes. - void writeU8Array(Uint8List value, int? length) { - if (length == null) { - // Variable-length: write length prefix - writeU32(value.length); - for (final v in value) { - writeU8(v); - } - } else { - // Fixed-size: write exactly [length] elements, no prefix - for (int i = 0; i < length; i++) { - writeU8(value[i]); - } - } - } - - /// Writes a fixed-size and prefixed-size u8 array of bytes. - void writeI8Array(Int8List value, int? length) { - if (length == null) { - // Variable-length: write length prefix - writeU32(value.length); - for (final v in value) { - writeI8(v); - } - } else { - // Fixed-size: write exactly [length] elements, no prefix - for (int i = 0; i < length; i++) { - writeI8(value[i]); - } - } - } - - /// Writes a fixed-size and prefixed-size u16 array of bytes. - void writeU16Array(Uint16List value, int? length) { - if (length == null) { - // Variable-length: write length prefix - writeU32(value.length); - for (final v in value) { - writeU16(v); - } - } else { - // Fixed-size: write exactly [length] elements, no prefix - for (int i = 0; i < length; i++) { - writeU16(value[i]); - } - } - } - - /// Writes a fixed-size and prefixed-size i16 array of bytes. - void writeI16Array(Int16List value, int? length) { - if (length == null) { - // Variable-length: write length prefix - writeU32(value.length); - for (final v in value) { - writeI16(v); - } - } else { - // Fixed-size: write exactly [length] elements, no prefix - for (int i = 0; i < length; i++) { - writeI16(value[i]); - } - } - } - - /// Writes a fixed-size and prefixed-size i16 array of bytes. - void writeU32Array(Uint32List value, int? length) { - if (length == null) { - // Variable-length: write length prefix - writeU32(value.length); - for (final v in value) { - writeU32(v); - } - } else { - // Fixed-size: write exactly [length] elements, no prefix - for (int i = 0; i < length; i++) { - writeU32(value[i]); - } - } - } - - /// Writes a fixed-size i32 array of bytes. - void writeI32Array(Int32List value, int? length) { - if (length == null) { - // Variable-length: write length prefix - writeU32(value.length); - for (final v in value) { - writeI32(v); - } - } else { - // Fixed-size: write exactly [length] elements, no prefix - for (int i = 0; i < length; i++) { - writeI32(value[i]); - } - } - } - - /// Writes a fixed-size u64 array of bytes. - void writeU64Array(Uint64List value, int? length) { - if (length == null) { - // Variable-length: write length prefix - writeU32(value.length); - for (final v in value) { - writeU64(BigInt.from(v)); - } - } else { - // Fixed-size: write exactly [length] elements, no prefix - for (int i = 0; i < length; i++) { - writeU64(BigInt.from(value[i])); - } - } - } - - /// Writes a fixed-size i64 array of bytes. - void writeI64Array(Int64List value, int? length) { - if (length == null) { - // Variable-length: write length prefix - writeU32(value.length); - for (final v in value) { - writeI64(BigInt.from(v)); - } - } else { - // Fixed-size: write exactly [length] elements, no prefix - for (int i = 0; i < length; i++) { - writeI64(BigInt.from(value[i])); - } - } - } - - /// Writes a variable-length array of bytes. - void writeBytes(Uint8List value) { - writeU32(value.length); - _bytes.addAll(value); - } - - /// Writes a variable-length array of generic items. - void writeArray(List items, void Function(T) itemWriter) { - writeU32(items.length); - for (final item in items) { - itemWriter(item); - } - } - - /// Writes a single public key (32 raw bytes, no prefix). - void writePubkey(Uint8List pubkeyBytes) { - _bytes.addAll(pubkeyBytes); - } - - /// Returns the byte array. - Uint8List toBytes() => Uint8List.fromList(_bytes); -} diff --git a/e2e/anchor/src/generated/types.dart b/e2e/anchor/src/generated/types.dart deleted file mode 100644 index 1a323b5..0000000 --- a/e2e/anchor/src/generated/types.dart +++ /dev/null @@ -1,13 +0,0 @@ -/// This code was AUTOGENERATED using the codama library. -/// Please DO NOT EDIT THIS FILE, instead use visitors -/// to add features, then rerun codama to update it. -/// -/// https://github.com/codama-idl/codama -/// - -// This file exports custom data types for the SDK. - -export 'types/cpi_rule.dart'; -export 'types/metadata_additional_field_restriction.dart'; -export 'types/metadata_additional_field_rule.dart'; -export 'types/transfer_amount_rule.dart'; diff --git a/e2e/anchor/src/generated/types/cpi_rule.dart b/e2e/anchor/src/generated/types/cpi_rule.dart deleted file mode 100644 index 4b978d4..0000000 --- a/e2e/anchor/src/generated/types/cpi_rule.dart +++ /dev/null @@ -1,72 +0,0 @@ -/// This code was AUTOGENERATED using the codama library. -/// Please DO NOT EDIT THIS FILE, instead use visitors -/// to add features, then rerun codama to update it. -/// -/// https://github.com/codama-idl/codama -/// - -import 'dart:typed_data'; -import 'package:solana/solana.dart'; -import '../shared.dart'; - -/// Generated type definition for CpiRule. -/// -/// Controls which protocols can interact with the token by -/// enforcing Allow and Deny lists. - -abstract class CpiRule {} - -class Allow extends CpiRule { - final List value0; - - Allow(this.value0); -} - -class Deny extends CpiRule { - final List value0; - - Deny(this.value0); -} - -/// Extension providing serialization methods for CpiRule. -/// -extension CpiRuleBorsh on CpiRule { - /// Converts the enum to a byte representation. - void toBorsh(BinaryWriter writer) { - if (this is Allow) { - final v = this as Allow; - - writer.writeArray(v.value0, - (Ed25519HDPublicKey item) { - writer.writePubkey(Uint8List.fromList(item.bytes)); - ; - }); - } - if (this is Deny) { - final v = this as Deny; - - writer.writeArray(v.value0, - (Ed25519HDPublicKey item) { - writer.writePubkey(Uint8List.fromList(item.bytes)); - ; - }); - } - } - - /// Creates an enum from a byte representation. - static CpiRule fromBorsh(BinaryReader reader) { - final variant = reader.readU8(); - switch (variant) { - case 0: - return Allow(reader.readArray(() { - return Ed25519HDPublicKey(reader.readPubkey()); - })); - case 1: - return Deny(reader.readArray(() { - return Ed25519HDPublicKey(reader.readPubkey()); - })); - default: - throw Exception('Unknown cpiRule variant: $variant'); - } - } -} diff --git a/e2e/anchor/src/generated/types/metadata_additional_field_restriction.dart b/e2e/anchor/src/generated/types/metadata_additional_field_restriction.dart deleted file mode 100644 index b2ed4fe..0000000 --- a/e2e/anchor/src/generated/types/metadata_additional_field_restriction.dart +++ /dev/null @@ -1,72 +0,0 @@ -/// This code was AUTOGENERATED using the codama library. -/// Please DO NOT EDIT THIS FILE, instead use visitors -/// to add features, then rerun codama to update it. -/// -/// https://github.com/codama-idl/codama -/// - -import 'dart:typed_data'; -import '../shared.dart'; - -/// Generated type definition for MetadataAdditionalFieldRestriction. -/// -/// Inner enum for the MetadataAdditionalFieldRestriction enum. -/// * Includes - The field must include one of the values in the vector. -/// * Excludes - The field must not include any of the values in the vector. - -abstract class MetadataAdditionalFieldRestriction {} - -class Includes extends MetadataAdditionalFieldRestriction { - final List value0; - - Includes(this.value0); -} - -class Excludes extends MetadataAdditionalFieldRestriction { - final List value0; - - Excludes(this.value0); -} - -/// Extension providing serialization methods for MetadataAdditionalFieldRestriction. -/// -extension MetadataAdditionalFieldRestrictionBorsh - on MetadataAdditionalFieldRestriction { - /// Converts the enum to a byte representation. - void toBorsh(BinaryWriter writer) { - if (this is Includes) { - final v = this as Includes; - - writer.writeArray(v.value0, (String item) { - writer.writeString(item); - ; - }); - } - if (this is Excludes) { - final v = this as Excludes; - - writer.writeArray(v.value0, (String item) { - writer.writeString(item); - ; - }); - } - } - - /// Creates an enum from a byte representation. - static MetadataAdditionalFieldRestriction fromBorsh(BinaryReader reader) { - final variant = reader.readU8(); - switch (variant) { - case 0: - return Includes(reader.readArray(() { - return reader.readString(); - })); - case 1: - return Excludes(reader.readArray(() { - return reader.readString(); - })); - default: - throw Exception( - 'Unknown metadataAdditionalFieldRestriction variant: $variant'); - } - } -} diff --git a/e2e/anchor/src/generated/types/metadata_additional_field_rule.dart b/e2e/anchor/src/generated/types/metadata_additional_field_rule.dart deleted file mode 100644 index 973246b..0000000 --- a/e2e/anchor/src/generated/types/metadata_additional_field_rule.dart +++ /dev/null @@ -1,49 +0,0 @@ -/// This code was AUTOGENERATED using the codama library. -/// Please DO NOT EDIT THIS FILE, instead use visitors -/// to add features, then rerun codama to update it. -/// -/// https://github.com/codama-idl/codama -/// - -import 'dart:typed_data'; -import '../shared.dart'; -import '../types/metadata_additional_field_restriction.dart'; - -/// Generated type definition for MetadataAdditionalFieldRule. -/// -/// Enforces rules on a single additional field in the mint metadata. -/// The field must exist and the value must pass the restriction. - -class MetadataAdditionalFieldRule { - final String field; - final MetadataAdditionalFieldRestriction? value_restrictions; - - MetadataAdditionalFieldRule({ - required this.field, - required this.value_restrictions, - }); -} - -/// Extension providing serialization methods for MetadataAdditionalFieldRule. -/// -extension MetadataAdditionalFieldRuleBorsh on MetadataAdditionalFieldRule { - /// Serializes the struct to its byte representation. - void toBorsh(BinaryWriter writer) { - writer.writeString(field); - - writer.writeU8(value_restrictions != null ? 1 : 0); - if (value_restrictions != null) { - value_restrictions!.toBorsh(writer); - } - } - - /// Creates a struct from its byte representation. - static MetadataAdditionalFieldRule fromBorsh(BinaryReader reader) { - return MetadataAdditionalFieldRule( - field: reader.readString(), - value_restrictions: reader.readU8() == 1 - ? MetadataAdditionalFieldRestrictionBorsh.fromBorsh(reader) - : null, - ); - } -} diff --git a/e2e/anchor/src/generated/types/transfer_amount_rule.dart b/e2e/anchor/src/generated/types/transfer_amount_rule.dart deleted file mode 100644 index 1a7c748..0000000 --- a/e2e/anchor/src/generated/types/transfer_amount_rule.dart +++ /dev/null @@ -1,88 +0,0 @@ -/// This code was AUTOGENERATED using the codama library. -/// Please DO NOT EDIT THIS FILE, instead use visitors -/// to add features, then rerun codama to update it. -/// -/// https://github.com/codama-idl/codama -/// - -import 'dart:typed_data'; -import '../shared.dart'; - -/// Generated type definition for TransferAmountRule. -/// -/// Enforces rules on the amount of tokens being transferred. -/// The rules can be above, below, equal to, or within a range. - -abstract class TransferAmountRule {} - -class Above extends TransferAmountRule { - final BigInt /* type: u64 */ value0; - - Above(this.value0); -} - -class Below extends TransferAmountRule { - final BigInt /* type: u64 */ value0; - - Below(this.value0); -} - -class Equal extends TransferAmountRule { - final BigInt /* type: u64 */ value0; - - Equal(this.value0); -} - -class Rang extends TransferAmountRule { - final BigInt /* type: u64 */ value0; - final BigInt /* type: u64 */ value1; - - Rang(this.value0, this.value1); -} - -/// Extension providing serialization methods for TransferAmountRule. -/// -extension TransferAmountRuleBorsh on TransferAmountRule { - /// Converts the enum to a byte representation. - void toBorsh(BinaryWriter writer) { - if (this is Above) { - final v = this as Above; - - writer.writeU64(v.value0); - } - if (this is Below) { - final v = this as Below; - - writer.writeU64(v.value0); - } - if (this is Equal) { - final v = this as Equal; - - writer.writeU64(v.value0); - } - if (this is Rang) { - final v = this as Rang; - - writer.writeU64(v.value0); - - writer.writeU64(v.value1); - } - } - - /// Creates an enum from a byte representation. - static TransferAmountRule fromBorsh(BinaryReader reader) { - final variant = reader.readU8(); - switch (variant) { - case 0: - return Above(reader.readU64()); - case 1: - return Below(reader.readU64()); - case 2: - return Equal(reader.readU64()); - case 3: - return Rang(reader.readU64(), reader.readU64()); - default: - throw Exception('Unknown transferAmountRule variant: $variant'); - } - } -} diff --git a/e2e/dummy/lib/generated/errors.dart b/e2e/dummy/lib/generated/errors.dart deleted file mode 100644 index a105376..0000000 --- a/e2e/dummy/lib/generated/errors.dart +++ /dev/null @@ -1,8 +0,0 @@ -/// This code was AUTOGENERATED using the codama library. -/// Please DO NOT EDIT THIS FILE, instead use visitors -/// to add features, then rerun codama to update it. -/// -/// https://github.com/codama-idl/codama -/// - -// This file exports error classes for all programs in the SDK. diff --git a/e2e/dummy/lib/generated/lib.dart b/e2e/dummy/lib/generated/lib.dart deleted file mode 100644 index 3144eb0..0000000 --- a/e2e/dummy/lib/generated/lib.dart +++ /dev/null @@ -1,11 +0,0 @@ -/// This code was AUTOGENERATED using the codama library. -/// Please DO NOT EDIT THIS FILE, instead use visitors -/// to add features, then rerun codama to update it. -/// -/// https://github.com/codama-idl/codama -/// - -// Entry point for the SDK. -// This file exports all the modules in the SDK. - -export 'programs.dart'; diff --git a/e2e/dummy/lib/generated/mod.dart b/e2e/dummy/lib/generated/mod.dart deleted file mode 100644 index 3144eb0..0000000 --- a/e2e/dummy/lib/generated/mod.dart +++ /dev/null @@ -1,11 +0,0 @@ -/// This code was AUTOGENERATED using the codama library. -/// Please DO NOT EDIT THIS FILE, instead use visitors -/// to add features, then rerun codama to update it. -/// -/// https://github.com/codama-idl/codama -/// - -// Entry point for the SDK. -// This file exports all the modules in the SDK. - -export 'programs.dart'; diff --git a/e2e/dummy/lib/generated/programs.dart b/e2e/dummy/lib/generated/programs.dart deleted file mode 100644 index 2122c90..0000000 --- a/e2e/dummy/lib/generated/programs.dart +++ /dev/null @@ -1,19 +0,0 @@ -/// This code was AUTOGENERATED using the codama library. -/// Please DO NOT EDIT THIS FILE, instead use visitors -/// to add features, then rerun codama to update it. -/// -/// https://github.com/codama-idl/codama -/// - -// This file exports program information for all programs in the SDK. - -import 'package:solana/solana.dart'; - -/// Program information for the program. -class Program { - /// The program ID for the program. - static final Ed25519HDPublicKey programId = Ed25519HDPublicKey.fromBase58(""); - - /// The program name. - static const String name = ""; -} diff --git a/e2e/memo/lib/generated/errors.dart b/e2e/memo/lib/generated/errors.dart deleted file mode 100644 index a105376..0000000 --- a/e2e/memo/lib/generated/errors.dart +++ /dev/null @@ -1,8 +0,0 @@ -/// This code was AUTOGENERATED using the codama library. -/// Please DO NOT EDIT THIS FILE, instead use visitors -/// to add features, then rerun codama to update it. -/// -/// https://github.com/codama-idl/codama -/// - -// This file exports error classes for all programs in the SDK. diff --git a/e2e/memo/lib/generated/lib.dart b/e2e/memo/lib/generated/lib.dart deleted file mode 100644 index 3144eb0..0000000 --- a/e2e/memo/lib/generated/lib.dart +++ /dev/null @@ -1,11 +0,0 @@ -/// This code was AUTOGENERATED using the codama library. -/// Please DO NOT EDIT THIS FILE, instead use visitors -/// to add features, then rerun codama to update it. -/// -/// https://github.com/codama-idl/codama -/// - -// Entry point for the SDK. -// This file exports all the modules in the SDK. - -export 'programs.dart'; diff --git a/e2e/memo/lib/generated/mod.dart b/e2e/memo/lib/generated/mod.dart deleted file mode 100644 index 3144eb0..0000000 --- a/e2e/memo/lib/generated/mod.dart +++ /dev/null @@ -1,11 +0,0 @@ -/// This code was AUTOGENERATED using the codama library. -/// Please DO NOT EDIT THIS FILE, instead use visitors -/// to add features, then rerun codama to update it. -/// -/// https://github.com/codama-idl/codama -/// - -// Entry point for the SDK. -// This file exports all the modules in the SDK. - -export 'programs.dart'; diff --git a/e2e/memo/lib/generated/programs.dart b/e2e/memo/lib/generated/programs.dart deleted file mode 100644 index 2122c90..0000000 --- a/e2e/memo/lib/generated/programs.dart +++ /dev/null @@ -1,19 +0,0 @@ -/// This code was AUTOGENERATED using the codama library. -/// Please DO NOT EDIT THIS FILE, instead use visitors -/// to add features, then rerun codama to update it. -/// -/// https://github.com/codama-idl/codama -/// - -// This file exports program information for all programs in the SDK. - -import 'package:solana/solana.dart'; - -/// Program information for the program. -class Program { - /// The program ID for the program. - static final Ed25519HDPublicKey programId = Ed25519HDPublicKey.fromBase58(""); - - /// The program name. - static const String name = ""; -} diff --git a/e2e/system/lib/generated/errors.dart b/e2e/system/lib/generated/errors.dart deleted file mode 100644 index a105376..0000000 --- a/e2e/system/lib/generated/errors.dart +++ /dev/null @@ -1,8 +0,0 @@ -/// This code was AUTOGENERATED using the codama library. -/// Please DO NOT EDIT THIS FILE, instead use visitors -/// to add features, then rerun codama to update it. -/// -/// https://github.com/codama-idl/codama -/// - -// This file exports error classes for all programs in the SDK. diff --git a/e2e/system/lib/generated/lib.dart b/e2e/system/lib/generated/lib.dart deleted file mode 100644 index 3144eb0..0000000 --- a/e2e/system/lib/generated/lib.dart +++ /dev/null @@ -1,11 +0,0 @@ -/// This code was AUTOGENERATED using the codama library. -/// Please DO NOT EDIT THIS FILE, instead use visitors -/// to add features, then rerun codama to update it. -/// -/// https://github.com/codama-idl/codama -/// - -// Entry point for the SDK. -// This file exports all the modules in the SDK. - -export 'programs.dart'; diff --git a/e2e/system/lib/generated/mod.dart b/e2e/system/lib/generated/mod.dart deleted file mode 100644 index 3144eb0..0000000 --- a/e2e/system/lib/generated/mod.dart +++ /dev/null @@ -1,11 +0,0 @@ -/// This code was AUTOGENERATED using the codama library. -/// Please DO NOT EDIT THIS FILE, instead use visitors -/// to add features, then rerun codama to update it. -/// -/// https://github.com/codama-idl/codama -/// - -// Entry point for the SDK. -// This file exports all the modules in the SDK. - -export 'programs.dart'; diff --git a/e2e/system/lib/generated/programs.dart b/e2e/system/lib/generated/programs.dart deleted file mode 100644 index 2122c90..0000000 --- a/e2e/system/lib/generated/programs.dart +++ /dev/null @@ -1,19 +0,0 @@ -/// This code was AUTOGENERATED using the codama library. -/// Please DO NOT EDIT THIS FILE, instead use visitors -/// to add features, then rerun codama to update it. -/// -/// https://github.com/codama-idl/codama -/// - -// This file exports program information for all programs in the SDK. - -import 'package:solana/solana.dart'; - -/// Program information for the program. -class Program { - /// The program ID for the program. - static final Ed25519HDPublicKey programId = Ed25519HDPublicKey.fromBase58(""); - - /// The program name. - static const String name = ""; -} From 9e4acd7db078462e1e161d444854b721237ea4a4 Mon Sep 17 00:00:00 2001 From: ERoydev Date: Mon, 15 Sep 2025 17:18:27 +0300 Subject: [PATCH 21/33] ref: Move util file in utils instead of fragments --- src/getTypeManifestVisitor.ts | 2 +- src/{fragments => utils}/dartTypedArray.ts | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename src/{fragments => utils}/dartTypedArray.ts (100%) diff --git a/src/getTypeManifestVisitor.ts b/src/getTypeManifestVisitor.ts index b32c740..58024f8 100644 --- a/src/getTypeManifestVisitor.ts +++ b/src/getTypeManifestVisitor.ts @@ -28,7 +28,7 @@ import { } from '@codama/nodes'; import { extendVisitor, mergeVisitor, pipe, visit, Visitor } from '@codama/visitors-core'; -import { getDartTypedArrayType } from './fragments/dartTypedArray'; +import { getDartTypedArrayType } from './utils/dartTypedArray'; import { ImportMap } from './ImportMap'; import TypeManifest, { TypeManifestOptions } from './TypeManifest'; import { dartDocblock } from './utils'; diff --git a/src/fragments/dartTypedArray.ts b/src/utils/dartTypedArray.ts similarity index 100% rename from src/fragments/dartTypedArray.ts rename to src/utils/dartTypedArray.ts From 62100a8d2ed6bd9ff30605c4aa18b7063b0d780d Mon Sep 17 00:00:00 2001 From: ERoydev Date: Mon, 15 Sep 2025 18:02:04 +0300 Subject: [PATCH 22/33] comment one test case --- e2e/test.sh | 2 +- src/getTypeManifestVisitor.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/e2e/test.sh b/e2e/test.sh index 4135be7..77926a8 100755 --- a/e2e/test.sh +++ b/e2e/test.sh @@ -39,5 +39,5 @@ function test_anchor_project() { test_project dummy test_project system test_project memo -# test_project meteora # TODO: uncomment after some internal fixes +# test_project meteora # TODO: Uncomment after fixing [[u32; 3]; 2] -> type of nested fixed arrays and it will not break test_anchor_project anchor \ No newline at end of file diff --git a/src/getTypeManifestVisitor.ts b/src/getTypeManifestVisitor.ts index 58024f8..9839ce4 100644 --- a/src/getTypeManifestVisitor.ts +++ b/src/getTypeManifestVisitor.ts @@ -88,7 +88,7 @@ export function getTypeManifestVisitor(options: TypeManifestOptions) { } return typedArrayManifest; } - + return { ...childManifest, type: `List<${childManifest.type}>`, From c118785c9280c5553322b994d79f676f836f7b9d Mon Sep 17 00:00:00 2001 From: ERoydev Date: Tue, 16 Sep 2025 12:01:31 +0300 Subject: [PATCH 23/33] update --- e2e/anchor/.dart_tool/package_config.json | 206 ----------------- e2e/anchor/.dart_tool/package_graph.json | 257 --------------------- e2e/dummy/.dart_tool/package_config.json | 206 ----------------- e2e/dummy/.dart_tool/package_graph.json | 257 --------------------- e2e/memo/.dart_tool/package_config.json | 206 ----------------- e2e/memo/.dart_tool/package_graph.json | 257 --------------------- e2e/meteora/.dart_tool/package_config.json | 206 ----------------- e2e/meteora/.dart_tool/package_graph.json | 257 --------------------- e2e/system/.dart_tool/package_config.json | 206 ----------------- e2e/system/.dart_tool/package_graph.json | 257 --------------------- e2e/test.sh | 1 + vitest.config.react-native.mts | 3 - 12 files changed, 1 insertion(+), 2318 deletions(-) delete mode 100644 e2e/anchor/.dart_tool/package_config.json delete mode 100644 e2e/anchor/.dart_tool/package_graph.json delete mode 100644 e2e/dummy/.dart_tool/package_config.json delete mode 100644 e2e/dummy/.dart_tool/package_graph.json delete mode 100644 e2e/memo/.dart_tool/package_config.json delete mode 100644 e2e/memo/.dart_tool/package_graph.json delete mode 100644 e2e/meteora/.dart_tool/package_config.json delete mode 100644 e2e/meteora/.dart_tool/package_graph.json delete mode 100644 e2e/system/.dart_tool/package_config.json delete mode 100644 e2e/system/.dart_tool/package_graph.json delete mode 100644 vitest.config.react-native.mts diff --git a/e2e/anchor/.dart_tool/package_config.json b/e2e/anchor/.dart_tool/package_config.json deleted file mode 100644 index b766e22..0000000 --- a/e2e/anchor/.dart_tool/package_config.json +++ /dev/null @@ -1,206 +0,0 @@ -{ - "configVersion": 2, - "packages": [ - { - "name": "async", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/async-2.13.0", - "packageUri": "lib/", - "languageVersion": "3.4" - }, - { - "name": "bip39", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/bip39-1.0.6", - "packageUri": "lib/", - "languageVersion": "2.12" - }, - { - "name": "borsh_annotation", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/borsh_annotation-0.3.2", - "packageUri": "lib/", - "languageVersion": "3.0" - }, - { - "name": "clock", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/clock-1.1.2", - "packageUri": "lib/", - "languageVersion": "3.4" - }, - { - "name": "collection", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/collection-1.19.1", - "packageUri": "lib/", - "languageVersion": "3.4" - }, - { - "name": "convert", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/convert-3.1.2", - "packageUri": "lib/", - "languageVersion": "3.4" - }, - { - "name": "crypto", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/crypto-3.0.6", - "packageUri": "lib/", - "languageVersion": "3.4" - }, - { - "name": "cryptography", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/cryptography-2.7.0", - "packageUri": "lib/", - "languageVersion": "3.1" - }, - { - "name": "decimal", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/decimal-3.2.4", - "packageUri": "lib/", - "languageVersion": "3.3" - }, - { - "name": "ed25519_hd_key", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/ed25519_hd_key-2.3.0", - "packageUri": "lib/", - "languageVersion": "3.4" - }, - { - "name": "ffi", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/ffi-2.1.4", - "packageUri": "lib/", - "languageVersion": "3.7" - }, - { - "name": "freezed_annotation", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/freezed_annotation-2.4.4", - "packageUri": "lib/", - "languageVersion": "3.0" - }, - { - "name": "hex", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/hex-0.2.0", - "packageUri": "lib/", - "languageVersion": "2.12" - }, - { - "name": "http", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/http-1.5.0", - "packageUri": "lib/", - "languageVersion": "3.4" - }, - { - "name": "http_parser", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/http_parser-4.1.2", - "packageUri": "lib/", - "languageVersion": "3.4" - }, - { - "name": "intl", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/intl-0.20.2", - "packageUri": "lib/", - "languageVersion": "3.3" - }, - { - "name": "js", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/js-0.6.7", - "packageUri": "lib/", - "languageVersion": "2.19" - }, - { - "name": "json_annotation", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/json_annotation-4.9.0", - "packageUri": "lib/", - "languageVersion": "3.0" - }, - { - "name": "meta", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/meta-1.17.0", - "packageUri": "lib/", - "languageVersion": "3.5" - }, - { - "name": "path", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/path-1.9.1", - "packageUri": "lib/", - "languageVersion": "3.4" - }, - { - "name": "pinenacl", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/pinenacl-0.6.0", - "packageUri": "lib/", - "languageVersion": "3.4" - }, - { - "name": "pointycastle", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/pointycastle-3.9.1", - "packageUri": "lib/", - "languageVersion": "3.2" - }, - { - "name": "rational", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/rational-2.2.3", - "packageUri": "lib/", - "languageVersion": "2.14" - }, - { - "name": "solana", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/solana-0.31.2+1", - "packageUri": "lib/", - "languageVersion": "3.2" - }, - { - "name": "source_span", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/source_span-1.10.1", - "packageUri": "lib/", - "languageVersion": "3.1" - }, - { - "name": "stream_channel", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/stream_channel-2.1.4", - "packageUri": "lib/", - "languageVersion": "3.3" - }, - { - "name": "string_scanner", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/string_scanner-1.4.1", - "packageUri": "lib/", - "languageVersion": "3.1" - }, - { - "name": "term_glyph", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/term_glyph-1.2.2", - "packageUri": "lib/", - "languageVersion": "3.1" - }, - { - "name": "typed_data", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/typed_data-1.4.0", - "packageUri": "lib/", - "languageVersion": "3.5" - }, - { - "name": "web", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/web-1.1.1", - "packageUri": "lib/", - "languageVersion": "3.4" - }, - { - "name": "web_socket", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/web_socket-1.0.1", - "packageUri": "lib/", - "languageVersion": "3.4" - }, - { - "name": "web_socket_channel", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/web_socket_channel-3.0.3", - "packageUri": "lib/", - "languageVersion": "3.3" - }, - { - "name": "anchor", - "rootUri": "../", - "packageUri": "lib/", - "languageVersion": "2.17" - } - ], - "generator": "pub", - "generatorVersion": "3.9.0", - "pubCache": "file:///Users/emilemilovroydev/.pub-cache" -} diff --git a/e2e/anchor/.dart_tool/package_graph.json b/e2e/anchor/.dart_tool/package_graph.json deleted file mode 100644 index 0f5245e..0000000 --- a/e2e/anchor/.dart_tool/package_graph.json +++ /dev/null @@ -1,257 +0,0 @@ -{ - "roots": [ - "anchor" - ], - "packages": [ - { - "name": "anchor", - "version": "0.1.0", - "dependencies": [ - "solana" - ], - "devDependencies": [] - }, - { - "name": "solana", - "version": "0.31.2+1", - "dependencies": [ - "bip39", - "borsh_annotation", - "collection", - "convert", - "cryptography", - "decimal", - "ed25519_hd_key", - "freezed_annotation", - "http", - "json_annotation", - "typed_data", - "web_socket_channel" - ] - }, - { - "name": "web_socket_channel", - "version": "3.0.3", - "dependencies": [ - "async", - "crypto", - "stream_channel", - "web", - "web_socket" - ] - }, - { - "name": "typed_data", - "version": "1.4.0", - "dependencies": [ - "collection" - ] - }, - { - "name": "json_annotation", - "version": "4.9.0", - "dependencies": [ - "meta" - ] - }, - { - "name": "http", - "version": "1.5.0", - "dependencies": [ - "async", - "http_parser", - "meta", - "web" - ] - }, - { - "name": "freezed_annotation", - "version": "2.4.4", - "dependencies": [ - "collection", - "json_annotation", - "meta" - ] - }, - { - "name": "ed25519_hd_key", - "version": "2.3.0", - "dependencies": [ - "crypto", - "pinenacl" - ] - }, - { - "name": "decimal", - "version": "3.2.4", - "dependencies": [ - "intl", - "rational" - ] - }, - { - "name": "cryptography", - "version": "2.7.0", - "dependencies": [ - "collection", - "crypto", - "ffi", - "js", - "meta", - "typed_data" - ] - }, - { - "name": "convert", - "version": "3.1.2", - "dependencies": [ - "typed_data" - ] - }, - { - "name": "collection", - "version": "1.19.1", - "dependencies": [] - }, - { - "name": "borsh_annotation", - "version": "0.3.2", - "dependencies": [] - }, - { - "name": "bip39", - "version": "1.0.6", - "dependencies": [ - "crypto", - "hex", - "pointycastle" - ] - }, - { - "name": "web_socket", - "version": "1.0.1", - "dependencies": [ - "web" - ] - }, - { - "name": "web", - "version": "1.1.1", - "dependencies": [] - }, - { - "name": "stream_channel", - "version": "2.1.4", - "dependencies": [ - "async" - ] - }, - { - "name": "crypto", - "version": "3.0.6", - "dependencies": [ - "typed_data" - ] - }, - { - "name": "async", - "version": "2.13.0", - "dependencies": [ - "collection", - "meta" - ] - }, - { - "name": "meta", - "version": "1.17.0", - "dependencies": [] - }, - { - "name": "http_parser", - "version": "4.1.2", - "dependencies": [ - "collection", - "source_span", - "string_scanner", - "typed_data" - ] - }, - { - "name": "pinenacl", - "version": "0.6.0", - "dependencies": [] - }, - { - "name": "rational", - "version": "2.2.3", - "dependencies": [] - }, - { - "name": "intl", - "version": "0.20.2", - "dependencies": [ - "clock", - "meta", - "path" - ] - }, - { - "name": "js", - "version": "0.6.7", - "dependencies": [ - "meta" - ] - }, - { - "name": "ffi", - "version": "2.1.4", - "dependencies": [] - }, - { - "name": "hex", - "version": "0.2.0", - "dependencies": [] - }, - { - "name": "pointycastle", - "version": "3.9.1", - "dependencies": [ - "collection", - "convert", - "js" - ] - }, - { - "name": "string_scanner", - "version": "1.4.1", - "dependencies": [ - "source_span" - ] - }, - { - "name": "source_span", - "version": "1.10.1", - "dependencies": [ - "collection", - "path", - "term_glyph" - ] - }, - { - "name": "path", - "version": "1.9.1", - "dependencies": [] - }, - { - "name": "clock", - "version": "1.1.2", - "dependencies": [] - }, - { - "name": "term_glyph", - "version": "1.2.2", - "dependencies": [] - } - ], - "configVersion": 1 -} \ No newline at end of file diff --git a/e2e/dummy/.dart_tool/package_config.json b/e2e/dummy/.dart_tool/package_config.json deleted file mode 100644 index cc60d19..0000000 --- a/e2e/dummy/.dart_tool/package_config.json +++ /dev/null @@ -1,206 +0,0 @@ -{ - "configVersion": 2, - "packages": [ - { - "name": "async", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/async-2.13.0", - "packageUri": "lib/", - "languageVersion": "3.4" - }, - { - "name": "bip39", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/bip39-1.0.6", - "packageUri": "lib/", - "languageVersion": "2.12" - }, - { - "name": "borsh_annotation", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/borsh_annotation-0.3.2", - "packageUri": "lib/", - "languageVersion": "3.0" - }, - { - "name": "clock", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/clock-1.1.2", - "packageUri": "lib/", - "languageVersion": "3.4" - }, - { - "name": "collection", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/collection-1.19.1", - "packageUri": "lib/", - "languageVersion": "3.4" - }, - { - "name": "convert", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/convert-3.1.2", - "packageUri": "lib/", - "languageVersion": "3.4" - }, - { - "name": "crypto", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/crypto-3.0.6", - "packageUri": "lib/", - "languageVersion": "3.4" - }, - { - "name": "cryptography", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/cryptography-2.7.0", - "packageUri": "lib/", - "languageVersion": "3.1" - }, - { - "name": "decimal", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/decimal-3.2.4", - "packageUri": "lib/", - "languageVersion": "3.3" - }, - { - "name": "ed25519_hd_key", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/ed25519_hd_key-2.3.0", - "packageUri": "lib/", - "languageVersion": "3.4" - }, - { - "name": "ffi", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/ffi-2.1.4", - "packageUri": "lib/", - "languageVersion": "3.7" - }, - { - "name": "freezed_annotation", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/freezed_annotation-2.4.4", - "packageUri": "lib/", - "languageVersion": "3.0" - }, - { - "name": "hex", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/hex-0.2.0", - "packageUri": "lib/", - "languageVersion": "2.12" - }, - { - "name": "http", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/http-1.5.0", - "packageUri": "lib/", - "languageVersion": "3.4" - }, - { - "name": "http_parser", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/http_parser-4.1.2", - "packageUri": "lib/", - "languageVersion": "3.4" - }, - { - "name": "intl", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/intl-0.20.2", - "packageUri": "lib/", - "languageVersion": "3.3" - }, - { - "name": "js", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/js-0.6.7", - "packageUri": "lib/", - "languageVersion": "2.19" - }, - { - "name": "json_annotation", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/json_annotation-4.9.0", - "packageUri": "lib/", - "languageVersion": "3.0" - }, - { - "name": "meta", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/meta-1.17.0", - "packageUri": "lib/", - "languageVersion": "3.5" - }, - { - "name": "path", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/path-1.9.1", - "packageUri": "lib/", - "languageVersion": "3.4" - }, - { - "name": "pinenacl", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/pinenacl-0.6.0", - "packageUri": "lib/", - "languageVersion": "3.4" - }, - { - "name": "pointycastle", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/pointycastle-3.9.1", - "packageUri": "lib/", - "languageVersion": "3.2" - }, - { - "name": "rational", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/rational-2.2.3", - "packageUri": "lib/", - "languageVersion": "2.14" - }, - { - "name": "solana", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/solana-0.31.2+1", - "packageUri": "lib/", - "languageVersion": "3.2" - }, - { - "name": "source_span", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/source_span-1.10.1", - "packageUri": "lib/", - "languageVersion": "3.1" - }, - { - "name": "stream_channel", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/stream_channel-2.1.4", - "packageUri": "lib/", - "languageVersion": "3.3" - }, - { - "name": "string_scanner", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/string_scanner-1.4.1", - "packageUri": "lib/", - "languageVersion": "3.1" - }, - { - "name": "term_glyph", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/term_glyph-1.2.2", - "packageUri": "lib/", - "languageVersion": "3.1" - }, - { - "name": "typed_data", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/typed_data-1.4.0", - "packageUri": "lib/", - "languageVersion": "3.5" - }, - { - "name": "web", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/web-1.1.1", - "packageUri": "lib/", - "languageVersion": "3.4" - }, - { - "name": "web_socket", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/web_socket-1.0.1", - "packageUri": "lib/", - "languageVersion": "3.4" - }, - { - "name": "web_socket_channel", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/web_socket_channel-3.0.3", - "packageUri": "lib/", - "languageVersion": "3.3" - }, - { - "name": "dummy", - "rootUri": "../", - "packageUri": "lib/", - "languageVersion": "2.17" - } - ], - "generator": "pub", - "generatorVersion": "3.9.0", - "pubCache": "file:///Users/emilemilovroydev/.pub-cache" -} diff --git a/e2e/dummy/.dart_tool/package_graph.json b/e2e/dummy/.dart_tool/package_graph.json deleted file mode 100644 index 8b4e474..0000000 --- a/e2e/dummy/.dart_tool/package_graph.json +++ /dev/null @@ -1,257 +0,0 @@ -{ - "roots": [ - "dummy" - ], - "packages": [ - { - "name": "dummy", - "version": "0.1.0", - "dependencies": [ - "solana" - ], - "devDependencies": [] - }, - { - "name": "solana", - "version": "0.31.2+1", - "dependencies": [ - "bip39", - "borsh_annotation", - "collection", - "convert", - "cryptography", - "decimal", - "ed25519_hd_key", - "freezed_annotation", - "http", - "json_annotation", - "typed_data", - "web_socket_channel" - ] - }, - { - "name": "web_socket_channel", - "version": "3.0.3", - "dependencies": [ - "async", - "crypto", - "stream_channel", - "web", - "web_socket" - ] - }, - { - "name": "typed_data", - "version": "1.4.0", - "dependencies": [ - "collection" - ] - }, - { - "name": "json_annotation", - "version": "4.9.0", - "dependencies": [ - "meta" - ] - }, - { - "name": "http", - "version": "1.5.0", - "dependencies": [ - "async", - "http_parser", - "meta", - "web" - ] - }, - { - "name": "freezed_annotation", - "version": "2.4.4", - "dependencies": [ - "collection", - "json_annotation", - "meta" - ] - }, - { - "name": "ed25519_hd_key", - "version": "2.3.0", - "dependencies": [ - "crypto", - "pinenacl" - ] - }, - { - "name": "decimal", - "version": "3.2.4", - "dependencies": [ - "intl", - "rational" - ] - }, - { - "name": "cryptography", - "version": "2.7.0", - "dependencies": [ - "collection", - "crypto", - "ffi", - "js", - "meta", - "typed_data" - ] - }, - { - "name": "convert", - "version": "3.1.2", - "dependencies": [ - "typed_data" - ] - }, - { - "name": "collection", - "version": "1.19.1", - "dependencies": [] - }, - { - "name": "borsh_annotation", - "version": "0.3.2", - "dependencies": [] - }, - { - "name": "bip39", - "version": "1.0.6", - "dependencies": [ - "crypto", - "hex", - "pointycastle" - ] - }, - { - "name": "web_socket", - "version": "1.0.1", - "dependencies": [ - "web" - ] - }, - { - "name": "web", - "version": "1.1.1", - "dependencies": [] - }, - { - "name": "stream_channel", - "version": "2.1.4", - "dependencies": [ - "async" - ] - }, - { - "name": "crypto", - "version": "3.0.6", - "dependencies": [ - "typed_data" - ] - }, - { - "name": "async", - "version": "2.13.0", - "dependencies": [ - "collection", - "meta" - ] - }, - { - "name": "meta", - "version": "1.17.0", - "dependencies": [] - }, - { - "name": "http_parser", - "version": "4.1.2", - "dependencies": [ - "collection", - "source_span", - "string_scanner", - "typed_data" - ] - }, - { - "name": "pinenacl", - "version": "0.6.0", - "dependencies": [] - }, - { - "name": "rational", - "version": "2.2.3", - "dependencies": [] - }, - { - "name": "intl", - "version": "0.20.2", - "dependencies": [ - "clock", - "meta", - "path" - ] - }, - { - "name": "js", - "version": "0.6.7", - "dependencies": [ - "meta" - ] - }, - { - "name": "ffi", - "version": "2.1.4", - "dependencies": [] - }, - { - "name": "hex", - "version": "0.2.0", - "dependencies": [] - }, - { - "name": "pointycastle", - "version": "3.9.1", - "dependencies": [ - "collection", - "convert", - "js" - ] - }, - { - "name": "string_scanner", - "version": "1.4.1", - "dependencies": [ - "source_span" - ] - }, - { - "name": "source_span", - "version": "1.10.1", - "dependencies": [ - "collection", - "path", - "term_glyph" - ] - }, - { - "name": "path", - "version": "1.9.1", - "dependencies": [] - }, - { - "name": "clock", - "version": "1.1.2", - "dependencies": [] - }, - { - "name": "term_glyph", - "version": "1.2.2", - "dependencies": [] - } - ], - "configVersion": 1 -} \ No newline at end of file diff --git a/e2e/memo/.dart_tool/package_config.json b/e2e/memo/.dart_tool/package_config.json deleted file mode 100644 index b817373..0000000 --- a/e2e/memo/.dart_tool/package_config.json +++ /dev/null @@ -1,206 +0,0 @@ -{ - "configVersion": 2, - "packages": [ - { - "name": "async", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/async-2.13.0", - "packageUri": "lib/", - "languageVersion": "3.4" - }, - { - "name": "bip39", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/bip39-1.0.6", - "packageUri": "lib/", - "languageVersion": "2.12" - }, - { - "name": "borsh_annotation", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/borsh_annotation-0.3.2", - "packageUri": "lib/", - "languageVersion": "3.0" - }, - { - "name": "clock", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/clock-1.1.2", - "packageUri": "lib/", - "languageVersion": "3.4" - }, - { - "name": "collection", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/collection-1.19.1", - "packageUri": "lib/", - "languageVersion": "3.4" - }, - { - "name": "convert", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/convert-3.1.2", - "packageUri": "lib/", - "languageVersion": "3.4" - }, - { - "name": "crypto", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/crypto-3.0.6", - "packageUri": "lib/", - "languageVersion": "3.4" - }, - { - "name": "cryptography", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/cryptography-2.7.0", - "packageUri": "lib/", - "languageVersion": "3.1" - }, - { - "name": "decimal", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/decimal-3.2.4", - "packageUri": "lib/", - "languageVersion": "3.3" - }, - { - "name": "ed25519_hd_key", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/ed25519_hd_key-2.3.0", - "packageUri": "lib/", - "languageVersion": "3.4" - }, - { - "name": "ffi", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/ffi-2.1.4", - "packageUri": "lib/", - "languageVersion": "3.7" - }, - { - "name": "freezed_annotation", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/freezed_annotation-2.4.4", - "packageUri": "lib/", - "languageVersion": "3.0" - }, - { - "name": "hex", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/hex-0.2.0", - "packageUri": "lib/", - "languageVersion": "2.12" - }, - { - "name": "http", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/http-1.5.0", - "packageUri": "lib/", - "languageVersion": "3.4" - }, - { - "name": "http_parser", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/http_parser-4.1.2", - "packageUri": "lib/", - "languageVersion": "3.4" - }, - { - "name": "intl", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/intl-0.20.2", - "packageUri": "lib/", - "languageVersion": "3.3" - }, - { - "name": "js", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/js-0.6.7", - "packageUri": "lib/", - "languageVersion": "2.19" - }, - { - "name": "json_annotation", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/json_annotation-4.9.0", - "packageUri": "lib/", - "languageVersion": "3.0" - }, - { - "name": "meta", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/meta-1.17.0", - "packageUri": "lib/", - "languageVersion": "3.5" - }, - { - "name": "path", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/path-1.9.1", - "packageUri": "lib/", - "languageVersion": "3.4" - }, - { - "name": "pinenacl", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/pinenacl-0.6.0", - "packageUri": "lib/", - "languageVersion": "3.4" - }, - { - "name": "pointycastle", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/pointycastle-3.9.1", - "packageUri": "lib/", - "languageVersion": "3.2" - }, - { - "name": "rational", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/rational-2.2.3", - "packageUri": "lib/", - "languageVersion": "2.14" - }, - { - "name": "solana", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/solana-0.31.2+1", - "packageUri": "lib/", - "languageVersion": "3.2" - }, - { - "name": "source_span", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/source_span-1.10.1", - "packageUri": "lib/", - "languageVersion": "3.1" - }, - { - "name": "stream_channel", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/stream_channel-2.1.4", - "packageUri": "lib/", - "languageVersion": "3.3" - }, - { - "name": "string_scanner", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/string_scanner-1.4.1", - "packageUri": "lib/", - "languageVersion": "3.1" - }, - { - "name": "term_glyph", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/term_glyph-1.2.2", - "packageUri": "lib/", - "languageVersion": "3.1" - }, - { - "name": "typed_data", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/typed_data-1.4.0", - "packageUri": "lib/", - "languageVersion": "3.5" - }, - { - "name": "web", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/web-1.1.1", - "packageUri": "lib/", - "languageVersion": "3.4" - }, - { - "name": "web_socket", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/web_socket-1.0.1", - "packageUri": "lib/", - "languageVersion": "3.4" - }, - { - "name": "web_socket_channel", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/web_socket_channel-3.0.3", - "packageUri": "lib/", - "languageVersion": "3.3" - }, - { - "name": "memo", - "rootUri": "../", - "packageUri": "lib/", - "languageVersion": "2.17" - } - ], - "generator": "pub", - "generatorVersion": "3.9.0", - "pubCache": "file:///Users/emilemilovroydev/.pub-cache" -} diff --git a/e2e/memo/.dart_tool/package_graph.json b/e2e/memo/.dart_tool/package_graph.json deleted file mode 100644 index 21013f5..0000000 --- a/e2e/memo/.dart_tool/package_graph.json +++ /dev/null @@ -1,257 +0,0 @@ -{ - "roots": [ - "memo" - ], - "packages": [ - { - "name": "memo", - "version": "0.1.0", - "dependencies": [ - "solana" - ], - "devDependencies": [] - }, - { - "name": "solana", - "version": "0.31.2+1", - "dependencies": [ - "bip39", - "borsh_annotation", - "collection", - "convert", - "cryptography", - "decimal", - "ed25519_hd_key", - "freezed_annotation", - "http", - "json_annotation", - "typed_data", - "web_socket_channel" - ] - }, - { - "name": "web_socket_channel", - "version": "3.0.3", - "dependencies": [ - "async", - "crypto", - "stream_channel", - "web", - "web_socket" - ] - }, - { - "name": "typed_data", - "version": "1.4.0", - "dependencies": [ - "collection" - ] - }, - { - "name": "json_annotation", - "version": "4.9.0", - "dependencies": [ - "meta" - ] - }, - { - "name": "http", - "version": "1.5.0", - "dependencies": [ - "async", - "http_parser", - "meta", - "web" - ] - }, - { - "name": "freezed_annotation", - "version": "2.4.4", - "dependencies": [ - "collection", - "json_annotation", - "meta" - ] - }, - { - "name": "ed25519_hd_key", - "version": "2.3.0", - "dependencies": [ - "crypto", - "pinenacl" - ] - }, - { - "name": "decimal", - "version": "3.2.4", - "dependencies": [ - "intl", - "rational" - ] - }, - { - "name": "cryptography", - "version": "2.7.0", - "dependencies": [ - "collection", - "crypto", - "ffi", - "js", - "meta", - "typed_data" - ] - }, - { - "name": "convert", - "version": "3.1.2", - "dependencies": [ - "typed_data" - ] - }, - { - "name": "collection", - "version": "1.19.1", - "dependencies": [] - }, - { - "name": "borsh_annotation", - "version": "0.3.2", - "dependencies": [] - }, - { - "name": "bip39", - "version": "1.0.6", - "dependencies": [ - "crypto", - "hex", - "pointycastle" - ] - }, - { - "name": "web_socket", - "version": "1.0.1", - "dependencies": [ - "web" - ] - }, - { - "name": "web", - "version": "1.1.1", - "dependencies": [] - }, - { - "name": "stream_channel", - "version": "2.1.4", - "dependencies": [ - "async" - ] - }, - { - "name": "crypto", - "version": "3.0.6", - "dependencies": [ - "typed_data" - ] - }, - { - "name": "async", - "version": "2.13.0", - "dependencies": [ - "collection", - "meta" - ] - }, - { - "name": "meta", - "version": "1.17.0", - "dependencies": [] - }, - { - "name": "http_parser", - "version": "4.1.2", - "dependencies": [ - "collection", - "source_span", - "string_scanner", - "typed_data" - ] - }, - { - "name": "pinenacl", - "version": "0.6.0", - "dependencies": [] - }, - { - "name": "rational", - "version": "2.2.3", - "dependencies": [] - }, - { - "name": "intl", - "version": "0.20.2", - "dependencies": [ - "clock", - "meta", - "path" - ] - }, - { - "name": "js", - "version": "0.6.7", - "dependencies": [ - "meta" - ] - }, - { - "name": "ffi", - "version": "2.1.4", - "dependencies": [] - }, - { - "name": "hex", - "version": "0.2.0", - "dependencies": [] - }, - { - "name": "pointycastle", - "version": "3.9.1", - "dependencies": [ - "collection", - "convert", - "js" - ] - }, - { - "name": "string_scanner", - "version": "1.4.1", - "dependencies": [ - "source_span" - ] - }, - { - "name": "source_span", - "version": "1.10.1", - "dependencies": [ - "collection", - "path", - "term_glyph" - ] - }, - { - "name": "path", - "version": "1.9.1", - "dependencies": [] - }, - { - "name": "clock", - "version": "1.1.2", - "dependencies": [] - }, - { - "name": "term_glyph", - "version": "1.2.2", - "dependencies": [] - } - ], - "configVersion": 1 -} \ No newline at end of file diff --git a/e2e/meteora/.dart_tool/package_config.json b/e2e/meteora/.dart_tool/package_config.json deleted file mode 100644 index 572b34d..0000000 --- a/e2e/meteora/.dart_tool/package_config.json +++ /dev/null @@ -1,206 +0,0 @@ -{ - "configVersion": 2, - "packages": [ - { - "name": "async", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/async-2.13.0", - "packageUri": "lib/", - "languageVersion": "3.4" - }, - { - "name": "bip39", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/bip39-1.0.6", - "packageUri": "lib/", - "languageVersion": "2.12" - }, - { - "name": "borsh_annotation", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/borsh_annotation-0.3.2", - "packageUri": "lib/", - "languageVersion": "3.0" - }, - { - "name": "clock", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/clock-1.1.2", - "packageUri": "lib/", - "languageVersion": "3.4" - }, - { - "name": "collection", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/collection-1.19.1", - "packageUri": "lib/", - "languageVersion": "3.4" - }, - { - "name": "convert", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/convert-3.1.2", - "packageUri": "lib/", - "languageVersion": "3.4" - }, - { - "name": "crypto", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/crypto-3.0.6", - "packageUri": "lib/", - "languageVersion": "3.4" - }, - { - "name": "cryptography", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/cryptography-2.7.0", - "packageUri": "lib/", - "languageVersion": "3.1" - }, - { - "name": "decimal", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/decimal-3.2.4", - "packageUri": "lib/", - "languageVersion": "3.3" - }, - { - "name": "ed25519_hd_key", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/ed25519_hd_key-2.3.0", - "packageUri": "lib/", - "languageVersion": "3.4" - }, - { - "name": "ffi", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/ffi-2.1.4", - "packageUri": "lib/", - "languageVersion": "3.7" - }, - { - "name": "freezed_annotation", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/freezed_annotation-2.4.4", - "packageUri": "lib/", - "languageVersion": "3.0" - }, - { - "name": "hex", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/hex-0.2.0", - "packageUri": "lib/", - "languageVersion": "2.12" - }, - { - "name": "http", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/http-1.5.0", - "packageUri": "lib/", - "languageVersion": "3.4" - }, - { - "name": "http_parser", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/http_parser-4.1.2", - "packageUri": "lib/", - "languageVersion": "3.4" - }, - { - "name": "intl", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/intl-0.20.2", - "packageUri": "lib/", - "languageVersion": "3.3" - }, - { - "name": "js", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/js-0.6.7", - "packageUri": "lib/", - "languageVersion": "2.19" - }, - { - "name": "json_annotation", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/json_annotation-4.9.0", - "packageUri": "lib/", - "languageVersion": "3.0" - }, - { - "name": "meta", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/meta-1.17.0", - "packageUri": "lib/", - "languageVersion": "3.5" - }, - { - "name": "path", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/path-1.9.1", - "packageUri": "lib/", - "languageVersion": "3.4" - }, - { - "name": "pinenacl", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/pinenacl-0.6.0", - "packageUri": "lib/", - "languageVersion": "3.4" - }, - { - "name": "pointycastle", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/pointycastle-3.9.1", - "packageUri": "lib/", - "languageVersion": "3.2" - }, - { - "name": "rational", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/rational-2.2.3", - "packageUri": "lib/", - "languageVersion": "2.14" - }, - { - "name": "solana", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/solana-0.31.2+1", - "packageUri": "lib/", - "languageVersion": "3.2" - }, - { - "name": "source_span", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/source_span-1.10.1", - "packageUri": "lib/", - "languageVersion": "3.1" - }, - { - "name": "stream_channel", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/stream_channel-2.1.4", - "packageUri": "lib/", - "languageVersion": "3.3" - }, - { - "name": "string_scanner", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/string_scanner-1.4.1", - "packageUri": "lib/", - "languageVersion": "3.1" - }, - { - "name": "term_glyph", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/term_glyph-1.2.2", - "packageUri": "lib/", - "languageVersion": "3.1" - }, - { - "name": "typed_data", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/typed_data-1.4.0", - "packageUri": "lib/", - "languageVersion": "3.5" - }, - { - "name": "web", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/web-1.1.1", - "packageUri": "lib/", - "languageVersion": "3.4" - }, - { - "name": "web_socket", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/web_socket-1.0.1", - "packageUri": "lib/", - "languageVersion": "3.4" - }, - { - "name": "web_socket_channel", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/web_socket_channel-3.0.3", - "packageUri": "lib/", - "languageVersion": "3.3" - }, - { - "name": "meteora", - "rootUri": "../", - "packageUri": "lib/", - "languageVersion": "2.17" - } - ], - "generator": "pub", - "generatorVersion": "3.9.0", - "pubCache": "file:///Users/emilemilovroydev/.pub-cache" -} diff --git a/e2e/meteora/.dart_tool/package_graph.json b/e2e/meteora/.dart_tool/package_graph.json deleted file mode 100644 index 4d411e3..0000000 --- a/e2e/meteora/.dart_tool/package_graph.json +++ /dev/null @@ -1,257 +0,0 @@ -{ - "roots": [ - "meteora" - ], - "packages": [ - { - "name": "meteora", - "version": "0.1.0", - "dependencies": [ - "solana" - ], - "devDependencies": [] - }, - { - "name": "solana", - "version": "0.31.2+1", - "dependencies": [ - "bip39", - "borsh_annotation", - "collection", - "convert", - "cryptography", - "decimal", - "ed25519_hd_key", - "freezed_annotation", - "http", - "json_annotation", - "typed_data", - "web_socket_channel" - ] - }, - { - "name": "web_socket_channel", - "version": "3.0.3", - "dependencies": [ - "async", - "crypto", - "stream_channel", - "web", - "web_socket" - ] - }, - { - "name": "typed_data", - "version": "1.4.0", - "dependencies": [ - "collection" - ] - }, - { - "name": "json_annotation", - "version": "4.9.0", - "dependencies": [ - "meta" - ] - }, - { - "name": "http", - "version": "1.5.0", - "dependencies": [ - "async", - "http_parser", - "meta", - "web" - ] - }, - { - "name": "freezed_annotation", - "version": "2.4.4", - "dependencies": [ - "collection", - "json_annotation", - "meta" - ] - }, - { - "name": "ed25519_hd_key", - "version": "2.3.0", - "dependencies": [ - "crypto", - "pinenacl" - ] - }, - { - "name": "decimal", - "version": "3.2.4", - "dependencies": [ - "intl", - "rational" - ] - }, - { - "name": "cryptography", - "version": "2.7.0", - "dependencies": [ - "collection", - "crypto", - "ffi", - "js", - "meta", - "typed_data" - ] - }, - { - "name": "convert", - "version": "3.1.2", - "dependencies": [ - "typed_data" - ] - }, - { - "name": "collection", - "version": "1.19.1", - "dependencies": [] - }, - { - "name": "borsh_annotation", - "version": "0.3.2", - "dependencies": [] - }, - { - "name": "bip39", - "version": "1.0.6", - "dependencies": [ - "crypto", - "hex", - "pointycastle" - ] - }, - { - "name": "web_socket", - "version": "1.0.1", - "dependencies": [ - "web" - ] - }, - { - "name": "web", - "version": "1.1.1", - "dependencies": [] - }, - { - "name": "stream_channel", - "version": "2.1.4", - "dependencies": [ - "async" - ] - }, - { - "name": "crypto", - "version": "3.0.6", - "dependencies": [ - "typed_data" - ] - }, - { - "name": "async", - "version": "2.13.0", - "dependencies": [ - "collection", - "meta" - ] - }, - { - "name": "meta", - "version": "1.17.0", - "dependencies": [] - }, - { - "name": "http_parser", - "version": "4.1.2", - "dependencies": [ - "collection", - "source_span", - "string_scanner", - "typed_data" - ] - }, - { - "name": "pinenacl", - "version": "0.6.0", - "dependencies": [] - }, - { - "name": "rational", - "version": "2.2.3", - "dependencies": [] - }, - { - "name": "intl", - "version": "0.20.2", - "dependencies": [ - "clock", - "meta", - "path" - ] - }, - { - "name": "js", - "version": "0.6.7", - "dependencies": [ - "meta" - ] - }, - { - "name": "ffi", - "version": "2.1.4", - "dependencies": [] - }, - { - "name": "hex", - "version": "0.2.0", - "dependencies": [] - }, - { - "name": "pointycastle", - "version": "3.9.1", - "dependencies": [ - "collection", - "convert", - "js" - ] - }, - { - "name": "string_scanner", - "version": "1.4.1", - "dependencies": [ - "source_span" - ] - }, - { - "name": "source_span", - "version": "1.10.1", - "dependencies": [ - "collection", - "path", - "term_glyph" - ] - }, - { - "name": "path", - "version": "1.9.1", - "dependencies": [] - }, - { - "name": "clock", - "version": "1.1.2", - "dependencies": [] - }, - { - "name": "term_glyph", - "version": "1.2.2", - "dependencies": [] - } - ], - "configVersion": 1 -} \ No newline at end of file diff --git a/e2e/system/.dart_tool/package_config.json b/e2e/system/.dart_tool/package_config.json deleted file mode 100644 index 53e8c5a..0000000 --- a/e2e/system/.dart_tool/package_config.json +++ /dev/null @@ -1,206 +0,0 @@ -{ - "configVersion": 2, - "packages": [ - { - "name": "async", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/async-2.13.0", - "packageUri": "lib/", - "languageVersion": "3.4" - }, - { - "name": "bip39", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/bip39-1.0.6", - "packageUri": "lib/", - "languageVersion": "2.12" - }, - { - "name": "borsh_annotation", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/borsh_annotation-0.3.2", - "packageUri": "lib/", - "languageVersion": "3.0" - }, - { - "name": "clock", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/clock-1.1.2", - "packageUri": "lib/", - "languageVersion": "3.4" - }, - { - "name": "collection", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/collection-1.19.1", - "packageUri": "lib/", - "languageVersion": "3.4" - }, - { - "name": "convert", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/convert-3.1.2", - "packageUri": "lib/", - "languageVersion": "3.4" - }, - { - "name": "crypto", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/crypto-3.0.6", - "packageUri": "lib/", - "languageVersion": "3.4" - }, - { - "name": "cryptography", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/cryptography-2.7.0", - "packageUri": "lib/", - "languageVersion": "3.1" - }, - { - "name": "decimal", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/decimal-3.2.4", - "packageUri": "lib/", - "languageVersion": "3.3" - }, - { - "name": "ed25519_hd_key", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/ed25519_hd_key-2.3.0", - "packageUri": "lib/", - "languageVersion": "3.4" - }, - { - "name": "ffi", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/ffi-2.1.4", - "packageUri": "lib/", - "languageVersion": "3.7" - }, - { - "name": "freezed_annotation", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/freezed_annotation-2.4.4", - "packageUri": "lib/", - "languageVersion": "3.0" - }, - { - "name": "hex", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/hex-0.2.0", - "packageUri": "lib/", - "languageVersion": "2.12" - }, - { - "name": "http", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/http-1.5.0", - "packageUri": "lib/", - "languageVersion": "3.4" - }, - { - "name": "http_parser", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/http_parser-4.1.2", - "packageUri": "lib/", - "languageVersion": "3.4" - }, - { - "name": "intl", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/intl-0.20.2", - "packageUri": "lib/", - "languageVersion": "3.3" - }, - { - "name": "js", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/js-0.6.7", - "packageUri": "lib/", - "languageVersion": "2.19" - }, - { - "name": "json_annotation", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/json_annotation-4.9.0", - "packageUri": "lib/", - "languageVersion": "3.0" - }, - { - "name": "meta", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/meta-1.17.0", - "packageUri": "lib/", - "languageVersion": "3.5" - }, - { - "name": "path", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/path-1.9.1", - "packageUri": "lib/", - "languageVersion": "3.4" - }, - { - "name": "pinenacl", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/pinenacl-0.6.0", - "packageUri": "lib/", - "languageVersion": "3.4" - }, - { - "name": "pointycastle", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/pointycastle-3.9.1", - "packageUri": "lib/", - "languageVersion": "3.2" - }, - { - "name": "rational", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/rational-2.2.3", - "packageUri": "lib/", - "languageVersion": "2.14" - }, - { - "name": "solana", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/solana-0.31.2+1", - "packageUri": "lib/", - "languageVersion": "3.2" - }, - { - "name": "source_span", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/source_span-1.10.1", - "packageUri": "lib/", - "languageVersion": "3.1" - }, - { - "name": "stream_channel", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/stream_channel-2.1.4", - "packageUri": "lib/", - "languageVersion": "3.3" - }, - { - "name": "string_scanner", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/string_scanner-1.4.1", - "packageUri": "lib/", - "languageVersion": "3.1" - }, - { - "name": "term_glyph", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/term_glyph-1.2.2", - "packageUri": "lib/", - "languageVersion": "3.1" - }, - { - "name": "typed_data", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/typed_data-1.4.0", - "packageUri": "lib/", - "languageVersion": "3.5" - }, - { - "name": "web", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/web-1.1.1", - "packageUri": "lib/", - "languageVersion": "3.4" - }, - { - "name": "web_socket", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/web_socket-1.0.1", - "packageUri": "lib/", - "languageVersion": "3.4" - }, - { - "name": "web_socket_channel", - "rootUri": "file:///Users/emilemilovroydev/.pub-cache/hosted/pub.dev/web_socket_channel-3.0.3", - "packageUri": "lib/", - "languageVersion": "3.3" - }, - { - "name": "system", - "rootUri": "../", - "packageUri": "lib/", - "languageVersion": "2.17" - } - ], - "generator": "pub", - "generatorVersion": "3.9.0", - "pubCache": "file:///Users/emilemilovroydev/.pub-cache" -} diff --git a/e2e/system/.dart_tool/package_graph.json b/e2e/system/.dart_tool/package_graph.json deleted file mode 100644 index 54386fa..0000000 --- a/e2e/system/.dart_tool/package_graph.json +++ /dev/null @@ -1,257 +0,0 @@ -{ - "roots": [ - "system" - ], - "packages": [ - { - "name": "system", - "version": "0.1.0", - "dependencies": [ - "solana" - ], - "devDependencies": [] - }, - { - "name": "solana", - "version": "0.31.2+1", - "dependencies": [ - "bip39", - "borsh_annotation", - "collection", - "convert", - "cryptography", - "decimal", - "ed25519_hd_key", - "freezed_annotation", - "http", - "json_annotation", - "typed_data", - "web_socket_channel" - ] - }, - { - "name": "web_socket_channel", - "version": "3.0.3", - "dependencies": [ - "async", - "crypto", - "stream_channel", - "web", - "web_socket" - ] - }, - { - "name": "typed_data", - "version": "1.4.0", - "dependencies": [ - "collection" - ] - }, - { - "name": "json_annotation", - "version": "4.9.0", - "dependencies": [ - "meta" - ] - }, - { - "name": "http", - "version": "1.5.0", - "dependencies": [ - "async", - "http_parser", - "meta", - "web" - ] - }, - { - "name": "freezed_annotation", - "version": "2.4.4", - "dependencies": [ - "collection", - "json_annotation", - "meta" - ] - }, - { - "name": "ed25519_hd_key", - "version": "2.3.0", - "dependencies": [ - "crypto", - "pinenacl" - ] - }, - { - "name": "decimal", - "version": "3.2.4", - "dependencies": [ - "intl", - "rational" - ] - }, - { - "name": "cryptography", - "version": "2.7.0", - "dependencies": [ - "collection", - "crypto", - "ffi", - "js", - "meta", - "typed_data" - ] - }, - { - "name": "convert", - "version": "3.1.2", - "dependencies": [ - "typed_data" - ] - }, - { - "name": "collection", - "version": "1.19.1", - "dependencies": [] - }, - { - "name": "borsh_annotation", - "version": "0.3.2", - "dependencies": [] - }, - { - "name": "bip39", - "version": "1.0.6", - "dependencies": [ - "crypto", - "hex", - "pointycastle" - ] - }, - { - "name": "web_socket", - "version": "1.0.1", - "dependencies": [ - "web" - ] - }, - { - "name": "web", - "version": "1.1.1", - "dependencies": [] - }, - { - "name": "stream_channel", - "version": "2.1.4", - "dependencies": [ - "async" - ] - }, - { - "name": "crypto", - "version": "3.0.6", - "dependencies": [ - "typed_data" - ] - }, - { - "name": "async", - "version": "2.13.0", - "dependencies": [ - "collection", - "meta" - ] - }, - { - "name": "meta", - "version": "1.17.0", - "dependencies": [] - }, - { - "name": "http_parser", - "version": "4.1.2", - "dependencies": [ - "collection", - "source_span", - "string_scanner", - "typed_data" - ] - }, - { - "name": "pinenacl", - "version": "0.6.0", - "dependencies": [] - }, - { - "name": "rational", - "version": "2.2.3", - "dependencies": [] - }, - { - "name": "intl", - "version": "0.20.2", - "dependencies": [ - "clock", - "meta", - "path" - ] - }, - { - "name": "js", - "version": "0.6.7", - "dependencies": [ - "meta" - ] - }, - { - "name": "ffi", - "version": "2.1.4", - "dependencies": [] - }, - { - "name": "hex", - "version": "0.2.0", - "dependencies": [] - }, - { - "name": "pointycastle", - "version": "3.9.1", - "dependencies": [ - "collection", - "convert", - "js" - ] - }, - { - "name": "string_scanner", - "version": "1.4.1", - "dependencies": [ - "source_span" - ] - }, - { - "name": "source_span", - "version": "1.10.1", - "dependencies": [ - "collection", - "path", - "term_glyph" - ] - }, - { - "name": "path", - "version": "1.9.1", - "dependencies": [] - }, - { - "name": "clock", - "version": "1.1.2", - "dependencies": [] - }, - { - "name": "term_glyph", - "version": "1.2.2", - "dependencies": [] - } - ], - "configVersion": 1 -} \ No newline at end of file diff --git a/e2e/test.sh b/e2e/test.sh index 77926a8..7759496 100755 --- a/e2e/test.sh +++ b/e2e/test.sh @@ -36,6 +36,7 @@ function test_anchor_project() { cd ../.. } + test_project dummy test_project system test_project memo diff --git a/vitest.config.react-native.mts b/vitest.config.react-native.mts deleted file mode 100644 index 8922da5..0000000 --- a/vitest.config.react-native.mts +++ /dev/null @@ -1,3 +0,0 @@ -import { getVitestConfig } from './vitest.config.base.mjs'; - -export default getVitestConfig('react-native'); From 061374d6f240c449721cbed7e1a2b6a2afe0eee6 Mon Sep 17 00:00:00 2001 From: ERoydev Date: Tue, 16 Sep 2025 12:01:44 +0300 Subject: [PATCH 24/33] add: Readme documentation --- README.md | 243 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 242 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4efca17..d67a3b1 100644 --- a/README.md +++ b/README.md @@ -1 +1,242 @@ -# codama-dart \ No newline at end of file +# Codama ➤ Renderers ➤ Dart + +This package provides a Solana Dart client renderer for [Codama](https://github.com/codama-idl/codama) that generates Dart client code from Solana program IDL files. + +This tool is in beta, so please report any issues or feedback. + +## Installation + +```sh +pnpm install codama-dart +``` + +## Standalone Usage +To use Codama-dart independently (not as a library), you can clone the repository and use the built-in CLI tool: + +```sh +git clone https://github.com/LimeChain/codama-dart +cd codama-dart + +pnpm install + +pnpm build +``` + +## Usage +Once you have Codama IDL, you can use the `renderVisitor` of this package to generate Dart clients. Provide the base directory where the generated files will be saved and an optional set of options to customize the output. + +```ts +// create-codama-client.js +import { createFromRoot } from 'codama'; +import { rootNodeFromAnchor } from '@codama/nodes-from-anchor'; +import renderVisitor from 'codama-dart'; + +import path from 'path'; +import fs from 'fs'; + +// Load one Anchor IDL +const idl = JSON.parse( + fs.readFileSync('target/idl/anchor_gamble.json', 'utf8') +); + +// Define program name and output directory +const programName = 'anchor_gamble'; +const outDir = path.join('clients', 'dart', 'generated', programName); + +// Generate the Dart client +const codama = createFromRoot(rootNodeFromAnchor(idl as any)); +codama.accept(renderVisitor(outDir, options)); +``` + +## Generate file directory structure + +``` +. +├── accounts +│ └── array_account.dart +├── instructions +│ └── array_initialize.dart +├── types +│ ├── fixed_array_account.dart +│ ├── nested_vec_account.dart +│ └── string_account.dart +├── errors +│ └── array_errors.dart +│ +├── accounts.dart +├── errors.dart +├── instructions.dart +├── programs.dart +├── shared.dart +├── types.dart +├── lib.dart +└── mod.dart +``` + +## Dependencies + +```yaml +dependencies: + solana: ^0.31.2+1 +``` + +## Examples + +### Create client variable + +```dart +RpcClient createSolanaClient() { + return RpcClient('http://localhost:8899'); +} +``` + +### Instructions + +```dart +import 'package:solana/solana.dart'; +import 'dart:convert'; +// Import the generated client `lib.dart` which exports all of the generated properties +import '../../../generated/anchor_gamble/lib.rs'; + +void initialize() async { + // Signer mnemonic file + final String mnemonic = File('wallet.mnemonic').readAsStringSync(); + + // Signer keypair + final Ed25519HDKeyPair payer = await Ed25519HDKeyPair.fromMnemonic(mnemonic); + + // Create client + final RpcClient client = createSolanaClient(); + + // Get programId from the generated client + final gambleProgramId = gamble.AnchorGambleProgram.programId; + + final systemProgram = Ed25519HDPublicKey.fromBase58(SystemProgram.programId); + final gambleCost = 1000000; // Example cost, adjust as needed + + try { + final configSeeds = [utf8.encode('config')]; + + final config = await Ed25519HDPublicKey.findProgramAddress( + seeds: configSeeds, + programId: gambleProgramId, + ); + + final rewardPoolSeeds = [utf8.encode('reward_pool')]; + + final rewardPool = await Ed25519HDPublicKey.findProgramAddress( + seeds: rewardPoolSeeds, + programId: gambleProgramId, + ); + + // Use the Instruction Class method from client that is generated for you + final initializeIx = InitializeInstruction( + config: config, + reward_pool: rewardPool, + admin: payer.publicKey, + system_program: systemProgram, + gamble_cost: BigInt.from(gambleCost), + ).toInstruction(); + + final message = Message(instructions: [initializeIx]); + final signature = await client.signAndSendTransaction(message, [payer]); + + print("Transaction signature to initialize a gamble instruction: $signature"); + } catch (e) { + print('Error signing and sending transaction: $e'); + } +} +``` + +### Accounts + +```dart +import 'package:solana/solana.dart'; +import 'dart:convert'; +// Import the generated client `lib.dart` which exports all of the generated properties +import '../../../generated/anchor_gamble/lib.dart'; + +void getGambleState(RpcClient client, Ed25519HDPublicKey programId) async { + try { + final configSeeds = [utf8.encode('config')]; + + final configAcc = await Ed25519HDPublicKey.findProgramAddress( + seeds: configSeeds, + programId: programId, + ); + + // Use the generated Account Class in the client `Config` and use its method to fetch from blockchain and access the deserialized property + final gamleAccount = await Config.fetch(client, configAcc); + + // Access the properties from this Class + print('Admin: ${gamleAccount.admin}'); + print('Gamble Cost: ${gamleAccount.gamble_cost}'); + print('Config Bump: ${gamleAccount.config_bump}'); + print('Reward Pool Bump: ${gamleAccount.reward_pool_bump}'); + + } catch (e) { + print('Error fetching Gamble State: $e'); + } +} +``` + +### Types + +```dart +// Structs + +final Ed25519HDKeyPair arrayAcc = await Ed25519HDKeyPair.fromMnemonic(arrayMnemonic); +// Get the data for that account +final arrayAccount = await ArrayAccount.fetch(client, arrayAcc.publicKey); +``` + +```dart +// Enum (Structs following the sealed class pattern) + +final Ed25519HDKeyPair enumAcc = await Ed25519HDKeyPair.fromMnemonic(enumMnemonic); + +final enumAccount = await EnumAccount.fetch(client, enumAcc.publicKey); +if (enumValue is VariantA) { + print('VariantA(value0: ${enumValue.value0}, value1: ${enumValue.value1})'); + } else if (enumValue is VariantB) { + print('VariantB(x: ${enumValue.x}, y: ${enumValue.y})'); + } else if (enumValue is VariantC) { + print('VariantC'); + .... +``` + +### Errors + +```dart +try { + ...some instruction call here +} catch (e) { + // You take that from the generated `errors` folder and you find your corresponding Error Class + final dsError = DataStructuresError.fromSolanaErrorString(e); + if (dsError != null) { + print('Custom program error: $dsError'); + // You can also check the type: + if (dsError is StringTooLongError) { + print('String was too long!'); + } + } else { + print('Other error: $e'); + } +} +``` + +## Program ID + +The Program ID is generated based on the Program address provided in the IDL. If it is not present in the IDL, it needs to be manually filled in. + +## Description + +The generated code uses the Solana Dart SDK along with Borsh serialization methods. + +## Not Supported Data Types + +- FixedArray with u8 are not supported -> `[u8; 2]`, arrays with u8 acts as an `BytesTypeNode`, which means it is automatically set to size 8 instead of 2. + +- `Vec>` -> Not supported + +- Fixed Nested Arrays -> `[[u32; 3]; 2]` use `Vec>` instead and apply constraints using InitSpace macros -> `#[max_len(3, 2)]` \ No newline at end of file From 51dbc7a0a35f82130b438fb049a8f44f9feac935 Mon Sep 17 00:00:00 2001 From: Emil Roydev <125214785+ERoydev@users.noreply.github.com> Date: Tue, 16 Sep 2025 12:25:59 +0300 Subject: [PATCH 25/33] Delete src/.DS_Store --- src/.DS_Store | Bin 6148 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 src/.DS_Store diff --git a/src/.DS_Store b/src/.DS_Store deleted file mode 100644 index f3f4aa872ab9435a63a62001216d8115adcb8004..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHKF;2rk5ZntvGNMTd-PLsY!6h;;$Olje3P`qW2~yDAGw65#4Zq+4^!$K7FuQv) zK0AmGA=s7n=DfG-vB#FzM?`M9+suh(L{z{TCr23e7_YOBY?30p=;R!?)powRZ0dHD zYk}XX06)7!x}$q)>57KW?=@eoo3dP2%^J~S@%Hq*J$qRUGdAC3wAcMNgx@>x?{Eb- zR1Nu0AM({c|Kod)zpJmCPyYQGIe%b&GgH76Fa`db0_fRn#j&D|rhqA63Umta_rb#% zL&B&ipAHPN1prPF7Q42UCz>qL1A_8+-3e-}Uwir&!5%(!CB#eq$PEMF{p2Y0Z z4#f#O;$G6p1w|W80aGAX;6M*&-2czN-v8%Cc4P{e0)I*YH!WA?61S9k>*(gV*LwH` ooQ?CMVpoERv|{9PD?WjXA?|qs3<;wmA~5?A5E*PR1%6b44{WMSBme*a From a72209ecb3e5d0663f59b132ee148c823ff31960 Mon Sep 17 00:00:00 2001 From: ERoydev Date: Tue, 16 Sep 2025 13:23:21 +0300 Subject: [PATCH 26/33] fix: add example repo link --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index d67a3b1..716df94 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,8 @@ This package provides a Solana Dart client renderer for [Codama](https://github. This tool is in beta, so please report any issues or feedback. +> For a full example project using this renderer, see [codama-dart-example](https://github.com/LimeChain/codama-dart-examples). + ## Installation ```sh From 2b25d2efd3c1bd19c457f87044920b82d7b26298 Mon Sep 17 00:00:00 2001 From: ERoydev Date: Wed, 17 Sep 2025 16:27:26 +0300 Subject: [PATCH 27/33] fix: Removed the unused dependencies --- .gitignore | 4 ++++ e2e/test.sh | 8 ++++++-- package.json | 6 ------ 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 9a5aced..accc4a8 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,9 @@ lerna-debug.log* # Diagnostic reports (https://nodejs.org/api/report.html) report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json +# e2e test generated clients +e2e/**/lib/generated + # Runtime data pids *.pid @@ -40,6 +43,7 @@ build/Release # Dependency directories node_modules/ jspm_packages/ +.dart_tool # Snowpack dependency directory (https://snowpack.dev/) web_modules/ diff --git a/e2e/test.sh b/e2e/test.sh index 7759496..042dc17 100755 --- a/e2e/test.sh +++ b/e2e/test.sh @@ -8,7 +8,7 @@ function print_dart_errors() { NC='\033[0m' if grep -q 'error ' "$log_file"; then echo "" - echo -e "${RED}==================== Dart Analysis Errors in $project ====================${NC}" + echo -e "${RED}==================== E2E TESTS FAILED IN PROJECT: $project ====================${NC}" echo "" grep 'error ' "$log_file" | sed 's/^/ /' echo "" @@ -31,8 +31,12 @@ function test_project() { } function test_anchor_project() { - ./e2e/generate-anchor.cjs $1 + ./e2e/generate-anchor.cjs $1 cd e2e/$1 + + dart analyze > analyze.log || true + print_dart_errors "$1" analyze.log + cd ../.. } diff --git a/package.json b/package.json index 8e67533..2d1c37f 100644 --- a/package.json +++ b/package.json @@ -44,16 +44,10 @@ }, "homepage": "https://github.com/LimeChain/codama-dart#readme", "devDependencies": { - "@codama/cli": "^1.3.4", "@codama/nodes-from-anchor": "^1.2.8", - "@types/node": "^24.3.1", - "@types/nunjucks": "^3.2.6", "agadoo": "^3.0.0", "browserslist-to-esbuild": "^2.1.1", - "codama": "^1.3.6", - "rimraf": "^5.0.0", "tsup": "^8.5.0", - "turbo": "^2.5.6", "typescript": "^5.9.2", "vitest": "^3.2.4", "zx": "^8.8.1" From 29e4fd6a1e2057360a46e5b72b90e3f7c4d9a474 Mon Sep 17 00:00:00 2001 From: ERoydev Date: Wed, 17 Sep 2025 16:46:22 +0300 Subject: [PATCH 28/33] update: The lock file --- pnpm-lock.yaml | 150 +------------------------------------------------ 1 file changed, 3 insertions(+), 147 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 01f0b37..a4121f8 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -24,36 +24,18 @@ importers: specifier: ^3.2.4 version: 3.2.4 devDependencies: - '@codama/cli': - specifier: ^1.3.4 - version: 1.3.4 '@codama/nodes-from-anchor': specifier: ^1.2.8 version: 1.2.8(fastestsmallesttextencoderdecoder@1.0.22)(typescript@5.9.2) - '@types/node': - specifier: ^24.3.1 - version: 24.3.1 - '@types/nunjucks': - specifier: ^3.2.6 - version: 3.2.6 agadoo: specifier: ^3.0.0 version: 3.0.0 browserslist-to-esbuild: specifier: ^2.1.1 version: 2.1.1(browserslist@4.25.4) - codama: - specifier: ^1.3.6 - version: 1.3.6 - rimraf: - specifier: ^5.0.0 - version: 5.0.10 tsup: specifier: ^8.5.0 version: 8.5.0(postcss@8.5.6)(typescript@5.9.2) - turbo: - specifier: ^2.5.6 - version: 2.5.6 typescript: specifier: ^5.9.2 version: 5.9.2 @@ -66,10 +48,6 @@ importers: packages: - '@codama/cli@1.3.4': - resolution: {integrity: sha512-MfnB4M8XhywaeRolZ190MsGu2m9VPFy9ovffvj3ox7KQ9u12u9NwsDkrMmjpX3SmQXH2XTLGnLlxpWdMecZ0bA==} - hasBin: true - '@codama/errors@1.3.4': resolution: {integrity: sha512-gEbfWkf5J1klGlLbrg5zIMYTncYO6SCsLRxKbDRrE1TmxRqt3cUovQyPhccGcNh/e/GisauIGjbsZTJaFNgXuw==} hasBin: true @@ -96,9 +74,6 @@ packages: '@codama/renderers-core@1.1.0': resolution: {integrity: sha512-OscEiIv4nXiiqb2I9PWDI0Aw8bM6Qdtb9oqbuFb0XXt8hJTeLoNk+AN8ZZFtJMtiy+SizJjUsbX2KFE2HsVhdg==} - '@codama/validators@1.3.6': - resolution: {integrity: sha512-14VcLfo8bHERxKRsnKR8m3fVWSgoDM8v7M8wrgO0bEXElTOwMFGSyL5wbs4RqWQ/LFO7uB/IGSZo//jkOUvT9A==} - '@codama/visitors-core@1.3.4': resolution: {integrity: sha512-TCP1ncA0ErBvv5q8BKCRvv98qHh9on8MOiPhdToJ/w50aNm0y5Y2mHbUWqk5vle8k3V9fuo7uf1aAOaqA6G4Vg==} @@ -459,9 +434,6 @@ packages: '@types/node@24.3.1': resolution: {integrity: sha512-3vXmQDXy+woz+gnrTvuvNrPzekOi+Ds0ReMxw0LzBiK3a+1k0kQn9f2NWk+lgD4rJehFUmYy2gMhJ2ZI+7YP9g==} - '@types/nunjucks@3.2.6': - resolution: {integrity: sha512-pHiGtf83na1nCzliuAdq8GowYiXvH5l931xZ0YEHaLMNFgynpEqx+IPStlu7UaDkehfvl01e4x/9Tpwhy7Ue3w==} - '@vitest/expect@3.2.4': resolution: {integrity: sha512-Io0yyORnB6sikFlt8QW5K7slY4OjqNX9jmJQ02QDda8lyM6B5oNgVWoSoKPac8/kgnCUzuHQKrSLtu/uOqqrig==} @@ -588,10 +560,6 @@ packages: resolution: {integrity: sha512-Qgzu8kfBvo+cA4962jnP1KkS6Dop5NS6g7R5LFYJr4b8Ub94PPQXUksCw9PvXoeXPRRddRNC5C1JQUR2SMGtnA==} engines: {node: '>= 14.16.0'} - codama@1.3.6: - resolution: {integrity: sha512-tbNizqhWMB42AHIq4sD5frMwEuF9/xJTa90D074q1Lhp/9eeoEk0feaRUlboQVyniq8A3EJm8Kj8oUA2daiB1w==} - hasBin: true - color-convert@2.0.1: resolution: {integrity: sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==} engines: {node: '>=7.0.0'} @@ -771,10 +739,6 @@ packages: jsonify@0.0.1: resolution: {integrity: sha512-2/Ki0GcmuqSrgFyelQq9M05y7PS0mEwuIzrf3f1fPqkVDVRvZrPZtVSMHxdgo8Aq0sxAOb/cr2aqqA3LeWHVPg==} - kleur@3.0.3: - resolution: {integrity: sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==} - engines: {node: '>=6'} - lilconfig@3.1.3: resolution: {integrity: sha512-/vlFKAoH5Cgt3Ie+JLhRbwOsCQePABiU3tJ1egGvyQ+33R/vcwM2Zl2QR/LzjsBeItPt3oSVXapn+m4nQDvpzw==} engines: {node: '>=14'} @@ -903,10 +867,6 @@ packages: resolution: {integrity: sha512-3Ybi1tAuwAP9s0r1UQ2J4n5Y0G05bJkpUIO0/bI9MhwmD70S5aTWbXGBwxHrelT+XM1k6dM0pk+SwNkpTRN7Pg==} engines: {node: ^10 || ^12 || >=14} - prompts@2.4.2: - resolution: {integrity: sha512-NxNv/kLguCA7p3jE8oL2aEBsrJWgAakBpgmgK6lpPWV+WuOmY6r2/zbAVnP+T8bQlA0nzHXSJSJW0Hq7ylaD2Q==} - engines: {node: '>= 6'} - punycode@2.3.1: resolution: {integrity: sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==} engines: {node: '>=6'} @@ -919,10 +879,6 @@ packages: resolution: {integrity: sha512-qYg9KP24dD5qka9J47d0aVky0N+b4fTU89LN9iDnjB5waksiC49rvMB0PrUJQGoTmH50XPiqOvAjDfaijGxYZw==} engines: {node: '>=8'} - rimraf@5.0.10: - resolution: {integrity: sha512-l0OE8wL34P4nJH/H2ffoaniAokM2qSmrtXHmlpvYr5AVVX8msAyW0l8NVJFDxlSK4u3Uh/f41cQheDVdnYijwQ==} - hasBin: true - rollup@3.29.5: resolution: {integrity: sha512-GVsDdsbJzzy4S/v3dqWPJ7EfvZJfCHiDqe80IyrF59LYuP+e6U1LJoUqeuqRbwAWoMNoXivMNeNAOf5E22VA1w==} engines: {node: '>=14.18.0', npm: '>=8.0.0'} @@ -952,9 +908,6 @@ packages: resolution: {integrity: sha512-bzyZ1e88w9O1iNJbKnOlvYTrWPDl46O1bG0D3XInv+9tkPrxrN8jUUTiFlDkkmKWgn1M6CfIA13SuGqOa9Korw==} engines: {node: '>=14'} - sisteransi@1.0.5: - resolution: {integrity: sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg==} - source-map-js@1.2.1: resolution: {integrity: sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA==} engines: {node: '>=0.10.0'} @@ -1052,40 +1005,6 @@ packages: typescript: optional: true - turbo-darwin-64@2.5.6: - resolution: {integrity: sha512-3C1xEdo4aFwMJAPvtlPqz1Sw/+cddWIOmsalHFMrsqqydcptwBfu26WW2cDm3u93bUzMbBJ8k3zNKFqxJ9ei2A==} - cpu: [x64] - os: [darwin] - - turbo-darwin-arm64@2.5.6: - resolution: {integrity: sha512-LyiG+rD7JhMfYwLqB6k3LZQtYn8CQQUePbpA8mF/hMLPAekXdJo1g0bUPw8RZLwQXUIU/3BU7tXENvhSGz5DPA==} - cpu: [arm64] - os: [darwin] - - turbo-linux-64@2.5.6: - resolution: {integrity: sha512-GOcUTT0xiT/pSnHL4YD6Yr3HreUhU8pUcGqcI2ksIF9b2/r/kRHwGFcsHgpG3+vtZF/kwsP0MV8FTlTObxsYIA==} - cpu: [x64] - os: [linux] - - turbo-linux-arm64@2.5.6: - resolution: {integrity: sha512-10Tm15bruJEA3m0V7iZcnQBpObGBcOgUcO+sY7/2vk1bweW34LMhkWi8svjV9iDF68+KJDThnYDlYE/bc7/zzQ==} - cpu: [arm64] - os: [linux] - - turbo-windows-64@2.5.6: - resolution: {integrity: sha512-FyRsVpgaj76It0ludwZsNN40ytHN+17E4PFJyeliBEbxrGTc5BexlXVpufB7XlAaoaZVxbS6KT8RofLfDRyEPg==} - cpu: [x64] - os: [win32] - - turbo-windows-arm64@2.5.6: - resolution: {integrity: sha512-j/tWu8cMeQ7HPpKri6jvKtyXg9K1gRyhdK4tKrrchH8GNHscPX/F71zax58yYtLRWTiK04zNzPcUJuoS0+v/+Q==} - cpu: [arm64] - os: [win32] - - turbo@2.5.6: - resolution: {integrity: sha512-gxToHmi9oTBNB05UjUsrWf0OyN5ZXtD0apOarC1KIx232Vp3WimRNy3810QzeNSgyD5rsaIDXlxlbnOzlouo+w==} - hasBin: true - typescript@5.9.2: resolution: {integrity: sha512-CWBzXQrc/qOkhidw1OzBTQuYRbfyxDXJMVJ1XNwUHGROVmuaeiEm3OslpZ1RV96d7SKKjZKrSJu3+t/xlw3R9A==} engines: {node: '>=14.17'} @@ -1207,15 +1126,6 @@ packages: snapshots: - '@codama/cli@1.3.4': - dependencies: - '@codama/nodes': 1.3.6 - '@codama/visitors': 1.3.6 - '@codama/visitors-core': 1.3.6 - commander: 14.0.1 - picocolors: 1.1.1 - prompts: 2.4.2 - '@codama/errors@1.3.4': dependencies: '@codama/node-types': 1.3.4 @@ -1259,12 +1169,6 @@ snapshots: '@codama/nodes': 1.3.4 '@codama/visitors-core': 1.3.4 - '@codama/validators@1.3.6': - dependencies: - '@codama/errors': 1.3.6 - '@codama/nodes': 1.3.6 - '@codama/visitors-core': 1.3.6 - '@codama/visitors-core@1.3.4': dependencies: '@codama/errors': 1.3.4 @@ -1521,8 +1425,7 @@ snapshots: '@types/node@24.3.1': dependencies: undici-types: 7.10.0 - - '@types/nunjucks@3.2.6': {} + optional: true '@vitest/expect@3.2.4': dependencies: @@ -1652,14 +1555,6 @@ snapshots: dependencies: readdirp: 4.1.2 - codama@1.3.6: - dependencies: - '@codama/cli': 1.3.4 - '@codama/errors': 1.3.6 - '@codama/nodes': 1.3.6 - '@codama/validators': 1.3.6 - '@codama/visitors': 1.3.6 - color-convert@2.0.1: dependencies: color-name: 1.1.4 @@ -1844,8 +1739,6 @@ snapshots: jsonify@0.0.1: {} - kleur@3.0.3: {} - lilconfig@3.1.3: {} lines-and-columns@1.2.4: {} @@ -1938,21 +1831,12 @@ snapshots: picocolors: 1.1.1 source-map-js: 1.2.1 - prompts@2.4.2: - dependencies: - kleur: 3.0.3 - sisteransi: 1.0.5 - punycode@2.3.1: {} readdirp@4.1.2: {} resolve-from@5.0.0: {} - rimraf@5.0.10: - dependencies: - glob: 10.4.5 - rollup@3.29.5: optionalDependencies: fsevents: 2.3.3 @@ -2003,8 +1887,6 @@ snapshots: signal-exit@4.1.0: {} - sisteransi@1.0.5: {} - source-map-js@1.2.1: {} source-map@0.8.0-beta.0: @@ -2108,38 +1990,12 @@ snapshots: - tsx - yaml - turbo-darwin-64@2.5.6: - optional: true - - turbo-darwin-arm64@2.5.6: - optional: true - - turbo-linux-64@2.5.6: - optional: true - - turbo-linux-arm64@2.5.6: - optional: true - - turbo-windows-64@2.5.6: - optional: true - - turbo-windows-arm64@2.5.6: - optional: true - - turbo@2.5.6: - optionalDependencies: - turbo-darwin-64: 2.5.6 - turbo-darwin-arm64: 2.5.6 - turbo-linux-64: 2.5.6 - turbo-linux-arm64: 2.5.6 - turbo-windows-64: 2.5.6 - turbo-windows-arm64: 2.5.6 - typescript@5.9.2: {} ufo@1.6.1: {} - undici-types@7.10.0: {} + undici-types@7.10.0: + optional: true update-browserslist-db@1.1.3(browserslist@4.25.4): dependencies: From 91b42e3bde3d80b5df960ee9eff19129ddaf0fe4 Mon Sep 17 00:00:00 2001 From: ERoydev Date: Wed, 17 Sep 2025 16:58:33 +0300 Subject: [PATCH 29/33] fix: Dependecy issues --- package.json | 4 + pnpm-lock.yaml | 221 ++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 204 insertions(+), 21 deletions(-) diff --git a/package.json b/package.json index 2d1c37f..6e0ac4a 100644 --- a/package.json +++ b/package.json @@ -45,8 +45,12 @@ "homepage": "https://github.com/LimeChain/codama-dart#readme", "devDependencies": { "@codama/nodes-from-anchor": "^1.2.8", + "@types/node": "^24.5.1", + "@types/nunjucks": "^3.2.6", "agadoo": "^3.0.0", "browserslist-to-esbuild": "^2.1.1", + "codama": "^1.3.7", + "rimraf": "^6.0.1", "tsup": "^8.5.0", "typescript": "^5.9.2", "vitest": "^3.2.4", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a4121f8..bff8bb8 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -27,12 +27,24 @@ importers: '@codama/nodes-from-anchor': specifier: ^1.2.8 version: 1.2.8(fastestsmallesttextencoderdecoder@1.0.22)(typescript@5.9.2) + '@types/node': + specifier: ^24.5.1 + version: 24.5.1 + '@types/nunjucks': + specifier: ^3.2.6 + version: 3.2.6 agadoo: specifier: ^3.0.0 version: 3.0.0 browserslist-to-esbuild: specifier: ^2.1.1 version: 2.1.1(browserslist@4.25.4) + codama: + specifier: ^1.3.7 + version: 1.3.7 + rimraf: + specifier: ^6.0.1 + version: 6.0.1 tsup: specifier: ^8.5.0 version: 8.5.0(postcss@8.5.6)(typescript@5.9.2) @@ -41,13 +53,17 @@ importers: version: 5.9.2 vitest: specifier: ^3.2.4 - version: 3.2.4(@types/node@24.3.1) + version: 3.2.4(@types/node@24.5.1) zx: specifier: ^8.8.1 version: 8.8.1 packages: + '@codama/cli@1.3.5': + resolution: {integrity: sha512-UgJGaTK2TXnbRcnCgReKqcDFjU941XZTvA0qbSiFH0Njrwb0kcLkKirMKwdyDaCHry7QcybzIKbp4ErrwqExMA==} + hasBin: true + '@codama/errors@1.3.4': resolution: {integrity: sha512-gEbfWkf5J1klGlLbrg5zIMYTncYO6SCsLRxKbDRrE1TmxRqt3cUovQyPhccGcNh/e/GisauIGjbsZTJaFNgXuw==} hasBin: true @@ -56,12 +72,19 @@ packages: resolution: {integrity: sha512-pWP42vregNgFGKY/hF4ifyfSL8FfYNnd0fKXjxP3IUX9HS7+T1CcfgfJ7St9YI6C77LpFPWmx+68Af4DGnAhKA==} hasBin: true + '@codama/errors@1.3.7': + resolution: {integrity: sha512-96BF8agDVc2vAgL4qw1lZZfuJ7XBefdzTBk2VOUnOhdMQiLb0QhJCC4BH88OcL+rZXQdet4pk7Qwarj1I1GFKg==} + hasBin: true + '@codama/node-types@1.3.4': resolution: {integrity: sha512-WOKU9v019gfX58y+I+hadokckvYLEZKvcsXpf578S+B+sV9YBCOhIjlzDDONcfe9iGUw49M6VpyWkp+EenasLg==} '@codama/node-types@1.3.6': resolution: {integrity: sha512-n9BpPh/Kl6Z6Bbt1MtsKykAtdPKljoBm4T8ea1IL9ABdFs+wnvgZBxnIAhgM0hC82AtvQPNGezXzLTER1JZpyg==} + '@codama/node-types@1.3.7': + resolution: {integrity: sha512-L9UTFfoeki5t+BYJAa4OMsqBPpbMbx8YJQar+55mYcjwGlJsKJW7mRfLYvwEFkCUYyLdNva40OVmTf88jccZCA==} + '@codama/nodes-from-anchor@1.2.8': resolution: {integrity: sha512-nW/amXV5OxOc+ZqOqt4ZZEJ2c2Fvp0MIGEMmeqKrSM/Yf2e0K9K4UP5btUXGpdAkNbLM/lWlEBBTkAcWONpttw==} @@ -71,18 +94,30 @@ packages: '@codama/nodes@1.3.6': resolution: {integrity: sha512-6fgnfmx0v5fR153Lkwe4Ghl2ei/7ZEqFfGZxRPzzzYwPAE/Q5Am+xZ0mULDyI1wW37HftCtAkTuXnIv2+6l+SQ==} + '@codama/nodes@1.3.7': + resolution: {integrity: sha512-3OV6SIBcqsIDARyzZVGdfnffNlnKSYcb0aGp/9Liz5/EID0oBTIyuh/Cmj5Ww6RX4WPb+GNAxABAGW94zbcfQg==} + '@codama/renderers-core@1.1.0': resolution: {integrity: sha512-OscEiIv4nXiiqb2I9PWDI0Aw8bM6Qdtb9oqbuFb0XXt8hJTeLoNk+AN8ZZFtJMtiy+SizJjUsbX2KFE2HsVhdg==} + '@codama/validators@1.3.7': + resolution: {integrity: sha512-OxuPhIPcuqSLmwDTcl9+VyEq6mwsLLqVXtQjgQgjEpr0IO/KAV9RG98Ye2yoK21jEVGDnzN9jsSQVHysRfpMMA==} + '@codama/visitors-core@1.3.4': resolution: {integrity: sha512-TCP1ncA0ErBvv5q8BKCRvv98qHh9on8MOiPhdToJ/w50aNm0y5Y2mHbUWqk5vle8k3V9fuo7uf1aAOaqA6G4Vg==} '@codama/visitors-core@1.3.6': resolution: {integrity: sha512-qdG27oyCYYG53vD9V/M60/TS6IxlMSf8b/5KLb/UgCykNRFLxXhDZXkwnMKKtF3LgHFxaayb0Zq+W1Z0lmjaig==} + '@codama/visitors-core@1.3.7': + resolution: {integrity: sha512-B1JnzhRDJiLxewha/F3YzeEp8Zrtd7eKiGNJFJHSPufAnIVm2lQUDaKS+OrAOHnSRmRKIAVdzfpFpdz6EM0N6Q==} + '@codama/visitors@1.3.6': resolution: {integrity: sha512-9SIOd08QBXUgFWyscSjbzwT2ljZflh4+LS+HS42Vg9BPkJAqJHflya1jl2LVsTM+oBcROl1/5uFR0zuLU3wZtA==} + '@codama/visitors@1.3.7': + resolution: {integrity: sha512-pIVK84G4dquvDXmr0q9GACcwDROw7DOBz0Kk/qt837FsKYr37xc6nU2LIguXu8QVIFOHBZk1HVAb7/S0eo/dqg==} + '@esbuild/aix-ppc64@0.25.9': resolution: {integrity: sha512-OaGtL73Jck6pBKjNIe24BnFE6agGl+6KxDtTfHhy1HmhthfKouEcOhqpSL64K4/0WCtbKFLOdzD/44cJ4k9opA==} engines: {node: '>=18'} @@ -239,6 +274,14 @@ packages: cpu: [x64] os: [win32] + '@isaacs/balanced-match@4.0.1': + resolution: {integrity: sha512-yzMTt9lEb8Gv7zRioUilSglI0c0smZ9k5D65677DLWLtWJaXIS3CqcGyUFByYKlnUj6TkjLVs54fBl6+TiGQDQ==} + engines: {node: 20 || >=22} + + '@isaacs/brace-expansion@5.0.0': + resolution: {integrity: sha512-ZT55BDLV0yv0RBm2czMiZ+SqCGO7AvmOM3G/w2xhVPH+te0aKgFjmBvGlL1dH+ql2tgGO3MVrbb3jCKyvpgnxA==} + engines: {node: 20 || >=22} + '@isaacs/cliui@8.0.2': resolution: {integrity: sha512-O8jcjabXaleOG9DQ0+ARXWZBTfnP4WNAqzuiJK7ll44AmxGKv/J2M4TPjxjY3znBCfvBXFzucm1twdyFybFqEA==} engines: {node: '>=12'} @@ -431,8 +474,11 @@ packages: '@types/estree@1.0.8': resolution: {integrity: sha512-dWHzHa2WqEXI/O1E9OjrocMTKJl2mSrEolh1Iomrv6U+JuNwaHXsXx9bLu5gG7BUWFIN0skIQJQ/L1rIex4X6w==} - '@types/node@24.3.1': - resolution: {integrity: sha512-3vXmQDXy+woz+gnrTvuvNrPzekOi+Ds0ReMxw0LzBiK3a+1k0kQn9f2NWk+lgD4rJehFUmYy2gMhJ2ZI+7YP9g==} + '@types/node@24.5.1': + resolution: {integrity: sha512-/SQdmUP2xa+1rdx7VwB9yPq8PaKej8TD5cQ+XfKDPWWC+VDJU4rvVVagXqKUzhKjtFoNA8rXDJAkCxQPAe00+Q==} + + '@types/nunjucks@3.2.6': + resolution: {integrity: sha512-pHiGtf83na1nCzliuAdq8GowYiXvH5l931xZ0YEHaLMNFgynpEqx+IPStlu7UaDkehfvl01e4x/9Tpwhy7Ue3w==} '@vitest/expect@3.2.4': resolution: {integrity: sha512-Io0yyORnB6sikFlt8QW5K7slY4OjqNX9jmJQ02QDda8lyM6B5oNgVWoSoKPac8/kgnCUzuHQKrSLtu/uOqqrig==} @@ -560,6 +606,10 @@ packages: resolution: {integrity: sha512-Qgzu8kfBvo+cA4962jnP1KkS6Dop5NS6g7R5LFYJr4b8Ub94PPQXUksCw9PvXoeXPRRddRNC5C1JQUR2SMGtnA==} engines: {node: '>= 14.16.0'} + codama@1.3.7: + resolution: {integrity: sha512-+pUJrvSG3bO4QvfcWfc14p3sklzHRB/lV4gjnXPhyb7T6nCFwYpNWv6/bFuqQyUSgSNI1n3tst/I9EhoPXOjbw==} + hasBin: true + color-convert@2.0.1: resolution: {integrity: sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==} engines: {node: '>=7.0.0'} @@ -697,6 +747,11 @@ packages: resolution: {integrity: sha512-7Bv8RF0k6xjo7d4A/PxYLbUCfb6c+Vpd2/mB2yRDlew7Jb5hEXiCD9ibfO7wpk8i4sevK6DFny9h7EYbM3/sHg==} hasBin: true + glob@11.0.3: + resolution: {integrity: sha512-2Nim7dha1KVkaiF4q6Dj+ngPPMdfvLJEOpZk/jKiUAkqKebpGAWQXAq9z1xu9HKu5lWfqw/FASuccEjyznjPaA==} + engines: {node: 20 || >=22} + hasBin: true + gopd@1.2.0: resolution: {integrity: sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==} engines: {node: '>= 0.4'} @@ -725,6 +780,10 @@ packages: jackspeak@3.4.3: resolution: {integrity: sha512-OGlZQpz2yfahA/Rd1Y8Cd9SIEsqvXkLVoSw/cgwhnhFMDbsQFeZYoJJ7bIZBS9BcamUW96asq/npPWugM+RQBw==} + jackspeak@4.1.1: + resolution: {integrity: sha512-zptv57P3GpL+O0I7VdMJNBZCu+BPHVQUk55Ft8/QCJjTVxrnJHuVuX/0Bl2A6/+2oyR/ZMEuFKwmzqqZ/U5nPQ==} + engines: {node: 20 || >=22} + joycon@3.1.1: resolution: {integrity: sha512-34wB/Y7MW7bzjKRjUKTa46I2Z7eV62Rkhva+KkopW7Qvv/OSWBqvkSY7vusOPrNuZcUG3tApvdVgNB8POj3SPw==} engines: {node: '>=10'} @@ -739,6 +798,10 @@ packages: jsonify@0.0.1: resolution: {integrity: sha512-2/Ki0GcmuqSrgFyelQq9M05y7PS0mEwuIzrf3f1fPqkVDVRvZrPZtVSMHxdgo8Aq0sxAOb/cr2aqqA3LeWHVPg==} + kleur@3.0.3: + resolution: {integrity: sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==} + engines: {node: '>=6'} + lilconfig@3.1.3: resolution: {integrity: sha512-/vlFKAoH5Cgt3Ie+JLhRbwOsCQePABiU3tJ1egGvyQ+33R/vcwM2Zl2QR/LzjsBeItPt3oSVXapn+m4nQDvpzw==} engines: {node: '>=14'} @@ -759,6 +822,10 @@ packages: lru-cache@10.4.3: resolution: {integrity: sha512-JNAzZcXrCt42VGLuYz0zfAzDfAvJWW6AfYlDBQyDV5DClI2m5sAmK+OIO7s59XfsRsWHp02jAJrRadPRGTt6SQ==} + lru-cache@11.2.1: + resolution: {integrity: sha512-r8LA6i4LP4EeWOhqBaZZjDWwehd1xUJPCJd9Sv300H0ZmcUER4+JPh7bqqZeqs1o5pgtgvXm+d9UGrB5zZGDiQ==} + engines: {node: 20 || >=22} + magic-string@0.30.19: resolution: {integrity: sha512-2N21sPY9Ws53PZvsEpVtNuSW+ScYbQdp4b9qUaL+9QkHUrGFKo56Lg9Emg5s9V/qrtNBmiR01sYhUOwu3H+VOw==} @@ -770,6 +837,10 @@ packages: resolution: {integrity: sha512-pxQJQzB6djGPXh08dacEloMFopsOqGVRKFPYvPOt9XDZ1HasbgDZA74CJGreSU4G3Ak7EFJGoiH2auq+yXISgA==} engines: {node: '>=18'} + minimatch@10.0.3: + resolution: {integrity: sha512-IPZ167aShDZZUMdRk66cyQAW3qr0WzbHkPdMYa8bzZhlHhO3jALbKdxcaak7W9FfT2rZNpQuUu4Od7ILEpXSaw==} + engines: {node: 20 || >=22} + minimatch@9.0.5: resolution: {integrity: sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow==} engines: {node: '>=16 || 14 >=14.17'} @@ -824,6 +895,10 @@ packages: resolution: {integrity: sha512-Xa4Nw17FS9ApQFJ9umLiJS4orGjm7ZzwUrwamcGQuHSzDyth9boKDaycYdDcZDuqYATXw4HFXgaqWTctW/v1HA==} engines: {node: '>=16 || 14 >=14.18'} + path-scurry@2.0.0: + resolution: {integrity: sha512-ypGJsmGtdXUOeM5u93TyeIEfEhM6s+ljAhrk5vAvSx8uyY/02OvrZnA0YNGUrPXfpJMgI1ODd3nwz8Npx4O4cg==} + engines: {node: 20 || >=22} + pathe@2.0.3: resolution: {integrity: sha512-WUjGcAqP1gQacoQe+OBJsFA7Ld4DyXuUIjZ5cc75cLHvJ7dtNsTugphxIADwspS+AraAUePCKrSVtPLFj/F88w==} @@ -867,6 +942,10 @@ packages: resolution: {integrity: sha512-3Ybi1tAuwAP9s0r1UQ2J4n5Y0G05bJkpUIO0/bI9MhwmD70S5aTWbXGBwxHrelT+XM1k6dM0pk+SwNkpTRN7Pg==} engines: {node: ^10 || ^12 || >=14} + prompts@2.4.2: + resolution: {integrity: sha512-NxNv/kLguCA7p3jE8oL2aEBsrJWgAakBpgmgK6lpPWV+WuOmY6r2/zbAVnP+T8bQlA0nzHXSJSJW0Hq7ylaD2Q==} + engines: {node: '>= 6'} + punycode@2.3.1: resolution: {integrity: sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==} engines: {node: '>=6'} @@ -879,6 +958,11 @@ packages: resolution: {integrity: sha512-qYg9KP24dD5qka9J47d0aVky0N+b4fTU89LN9iDnjB5waksiC49rvMB0PrUJQGoTmH50XPiqOvAjDfaijGxYZw==} engines: {node: '>=8'} + rimraf@6.0.1: + resolution: {integrity: sha512-9dkvaxAsk/xNXSJzMgFqqMCuFgt2+KsOFek3TMLfo8NCPfWpBmqwyNn5Y+NX56QUYfCtsyhF3ayiboEoUmJk/A==} + engines: {node: 20 || >=22} + hasBin: true + rollup@3.29.5: resolution: {integrity: sha512-GVsDdsbJzzy4S/v3dqWPJ7EfvZJfCHiDqe80IyrF59LYuP+e6U1LJoUqeuqRbwAWoMNoXivMNeNAOf5E22VA1w==} engines: {node: '>=14.18.0', npm: '>=8.0.0'} @@ -908,6 +992,9 @@ packages: resolution: {integrity: sha512-bzyZ1e88w9O1iNJbKnOlvYTrWPDl46O1bG0D3XInv+9tkPrxrN8jUUTiFlDkkmKWgn1M6CfIA13SuGqOa9Korw==} engines: {node: '>=14'} + sisteransi@1.0.5: + resolution: {integrity: sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg==} + source-map-js@1.2.1: resolution: {integrity: sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA==} engines: {node: '>=0.10.0'} @@ -1013,8 +1100,8 @@ packages: ufo@1.6.1: resolution: {integrity: sha512-9a4/uxlTWJ4+a5i0ooc1rU7C7YOw3wT+UGqdeNNHWnOF9qcMBgLRS+4IYUqbczewFx4mLEig6gawh7X6mFlEkA==} - undici-types@7.10.0: - resolution: {integrity: sha512-t5Fy/nfn+14LuOc2KNYg75vZqClpAiqscVvMygNnlsHBFpSXdJaYtXMcdNLpl/Qvc3P2cB3s6lOV51nqsFq4ag==} + undici-types@7.12.0: + resolution: {integrity: sha512-goOacqME2GYyOZZfb5Lgtu+1IDmAlAEu5xnD3+xTzS10hT0vzpf0SPjkXwAw9Jm+4n/mQGDP3LO8CPbYROeBfQ==} update-browserslist-db@1.1.3: resolution: {integrity: sha512-UxhIZQ+QInVdunkDAaiazvvT/+fXL5Osr0JZlJulepYu6Jd7qJtDZjlur0emRlT71EN3ScPoE7gvsuIKKNavKw==} @@ -1126,6 +1213,15 @@ packages: snapshots: + '@codama/cli@1.3.5': + dependencies: + '@codama/nodes': 1.3.7 + '@codama/visitors': 1.3.7 + '@codama/visitors-core': 1.3.7 + commander: 14.0.1 + picocolors: 1.1.1 + prompts: 2.4.2 + '@codama/errors@1.3.4': dependencies: '@codama/node-types': 1.3.4 @@ -1138,10 +1234,18 @@ snapshots: commander: 14.0.1 picocolors: 1.1.1 + '@codama/errors@1.3.7': + dependencies: + '@codama/node-types': 1.3.7 + commander: 14.0.1 + picocolors: 1.1.1 + '@codama/node-types@1.3.4': {} '@codama/node-types@1.3.6': {} + '@codama/node-types@1.3.7': {} + '@codama/nodes-from-anchor@1.2.8(fastestsmallesttextencoderdecoder@1.0.22)(typescript@5.9.2)': dependencies: '@codama/errors': 1.3.6 @@ -1163,12 +1267,23 @@ snapshots: '@codama/errors': 1.3.6 '@codama/node-types': 1.3.6 + '@codama/nodes@1.3.7': + dependencies: + '@codama/errors': 1.3.7 + '@codama/node-types': 1.3.7 + '@codama/renderers-core@1.1.0': dependencies: '@codama/errors': 1.3.4 '@codama/nodes': 1.3.4 '@codama/visitors-core': 1.3.4 + '@codama/validators@1.3.7': + dependencies: + '@codama/errors': 1.3.7 + '@codama/nodes': 1.3.7 + '@codama/visitors-core': 1.3.7 + '@codama/visitors-core@1.3.4': dependencies: '@codama/errors': 1.3.4 @@ -1181,12 +1296,24 @@ snapshots: '@codama/nodes': 1.3.6 json-stable-stringify: 1.3.0 + '@codama/visitors-core@1.3.7': + dependencies: + '@codama/errors': 1.3.7 + '@codama/nodes': 1.3.7 + json-stable-stringify: 1.3.0 + '@codama/visitors@1.3.6': dependencies: '@codama/errors': 1.3.6 '@codama/nodes': 1.3.6 '@codama/visitors-core': 1.3.6 + '@codama/visitors@1.3.7': + dependencies: + '@codama/errors': 1.3.7 + '@codama/nodes': 1.3.7 + '@codama/visitors-core': 1.3.7 + '@esbuild/aix-ppc64@0.25.9': optional: true @@ -1265,6 +1392,12 @@ snapshots: '@esbuild/win32-x64@0.25.9': optional: true + '@isaacs/balanced-match@4.0.1': {} + + '@isaacs/brace-expansion@5.0.0': + dependencies: + '@isaacs/balanced-match': 4.0.1 + '@isaacs/cliui@8.0.2': dependencies: string-width: 5.1.2 @@ -1422,10 +1555,11 @@ snapshots: '@types/estree@1.0.8': {} - '@types/node@24.3.1': + '@types/node@24.5.1': dependencies: - undici-types: 7.10.0 - optional: true + undici-types: 7.12.0 + + '@types/nunjucks@3.2.6': {} '@vitest/expect@3.2.4': dependencies: @@ -1435,13 +1569,13 @@ snapshots: chai: 5.3.3 tinyrainbow: 2.0.0 - '@vitest/mocker@3.2.4(vite@7.1.5(@types/node@24.3.1))': + '@vitest/mocker@3.2.4(vite@7.1.5(@types/node@24.5.1))': dependencies: '@vitest/spy': 3.2.4 estree-walker: 3.0.3 magic-string: 0.30.19 optionalDependencies: - vite: 7.1.5(@types/node@24.3.1) + vite: 7.1.5(@types/node@24.5.1) '@vitest/pretty-format@3.2.4': dependencies: @@ -1555,6 +1689,14 @@ snapshots: dependencies: readdirp: 4.1.2 + codama@1.3.7: + dependencies: + '@codama/cli': 1.3.5 + '@codama/errors': 1.3.7 + '@codama/nodes': 1.3.7 + '@codama/validators': 1.3.7 + '@codama/visitors': 1.3.7 + color-convert@2.0.1: dependencies: color-name: 1.1.4 @@ -1701,6 +1843,15 @@ snapshots: package-json-from-dist: 1.0.1 path-scurry: 1.11.1 + glob@11.0.3: + dependencies: + foreground-child: 3.3.1 + jackspeak: 4.1.1 + minimatch: 10.0.3 + minipass: 7.1.2 + package-json-from-dist: 1.0.1 + path-scurry: 2.0.0 + gopd@1.2.0: {} has-property-descriptors@1.0.2: @@ -1725,6 +1876,10 @@ snapshots: optionalDependencies: '@pkgjs/parseargs': 0.11.0 + jackspeak@4.1.1: + dependencies: + '@isaacs/cliui': 8.0.2 + joycon@3.1.1: {} js-tokens@9.0.1: {} @@ -1739,6 +1894,8 @@ snapshots: jsonify@0.0.1: {} + kleur@3.0.3: {} + lilconfig@3.1.3: {} lines-and-columns@1.2.4: {} @@ -1751,6 +1908,8 @@ snapshots: lru-cache@10.4.3: {} + lru-cache@11.2.1: {} + magic-string@0.30.19: dependencies: '@jridgewell/sourcemap-codec': 1.5.5 @@ -1759,6 +1918,10 @@ snapshots: meow@13.2.0: {} + minimatch@10.0.3: + dependencies: + '@isaacs/brace-expansion': 5.0.0 + minimatch@9.0.5: dependencies: brace-expansion: 2.0.2 @@ -1803,6 +1966,11 @@ snapshots: lru-cache: 10.4.3 minipass: 7.1.2 + path-scurry@2.0.0: + dependencies: + lru-cache: 11.2.1 + minipass: 7.1.2 + pathe@2.0.3: {} pathval@2.0.1: {} @@ -1831,12 +1999,22 @@ snapshots: picocolors: 1.1.1 source-map-js: 1.2.1 + prompts@2.4.2: + dependencies: + kleur: 3.0.3 + sisteransi: 1.0.5 + punycode@2.3.1: {} readdirp@4.1.2: {} resolve-from@5.0.0: {} + rimraf@6.0.1: + dependencies: + glob: 11.0.3 + package-json-from-dist: 1.0.1 + rollup@3.29.5: optionalDependencies: fsevents: 2.3.3 @@ -1887,6 +2065,8 @@ snapshots: signal-exit@4.1.0: {} + sisteransi@1.0.5: {} + source-map-js@1.2.1: {} source-map@0.8.0-beta.0: @@ -1994,8 +2174,7 @@ snapshots: ufo@1.6.1: {} - undici-types@7.10.0: - optional: true + undici-types@7.12.0: {} update-browserslist-db@1.1.3(browserslist@4.25.4): dependencies: @@ -2003,13 +2182,13 @@ snapshots: escalade: 3.2.0 picocolors: 1.1.1 - vite-node@3.2.4(@types/node@24.3.1): + vite-node@3.2.4(@types/node@24.5.1): dependencies: cac: 6.7.14 debug: 4.4.1 es-module-lexer: 1.7.0 pathe: 2.0.3 - vite: 7.1.5(@types/node@24.3.1) + vite: 7.1.5(@types/node@24.5.1) transitivePeerDependencies: - '@types/node' - jiti @@ -2024,7 +2203,7 @@ snapshots: - tsx - yaml - vite@7.1.5(@types/node@24.3.1): + vite@7.1.5(@types/node@24.5.1): dependencies: esbuild: 0.25.9 fdir: 6.5.0(picomatch@4.0.3) @@ -2033,14 +2212,14 @@ snapshots: rollup: 4.50.1 tinyglobby: 0.2.15 optionalDependencies: - '@types/node': 24.3.1 + '@types/node': 24.5.1 fsevents: 2.3.3 - vitest@3.2.4(@types/node@24.3.1): + vitest@3.2.4(@types/node@24.5.1): dependencies: '@types/chai': 5.2.2 '@vitest/expect': 3.2.4 - '@vitest/mocker': 3.2.4(vite@7.1.5(@types/node@24.3.1)) + '@vitest/mocker': 3.2.4(vite@7.1.5(@types/node@24.5.1)) '@vitest/pretty-format': 3.2.4 '@vitest/runner': 3.2.4 '@vitest/snapshot': 3.2.4 @@ -2058,11 +2237,11 @@ snapshots: tinyglobby: 0.2.15 tinypool: 1.1.1 tinyrainbow: 2.0.0 - vite: 7.1.5(@types/node@24.3.1) - vite-node: 3.2.4(@types/node@24.3.1) + vite: 7.1.5(@types/node@24.5.1) + vite-node: 3.2.4(@types/node@24.5.1) why-is-node-running: 2.3.0 optionalDependencies: - '@types/node': 24.3.1 + '@types/node': 24.5.1 transitivePeerDependencies: - jiti - less From 2908a8161bfcfc89922dcba69db178b31aec5ce8 Mon Sep 17 00:00:00 2001 From: ERoydev Date: Thu, 18 Sep 2025 09:44:35 +0300 Subject: [PATCH 30/33] update: Readme usage update --- README.md | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 716df94..2130821 100644 --- a/README.md +++ b/README.md @@ -12,20 +12,30 @@ This tool is in beta, so please report any issues or feedback. pnpm install codama-dart ``` -## Standalone Usage -To use Codama-dart independently (not as a library), you can clone the repository and use the built-in CLI tool: - -```sh -git clone https://github.com/LimeChain/codama-dart -cd codama-dart - -pnpm install - -pnpm build +## Using with Codama configuration +When you have installed Codama IDL, you can use as a renderer plugin via Codama's configuration system. +Just add the following script to your Codama configuration file. + + +```json +{ + "scripts": { + "dart": { + "from": "@codama/renderers-dart", + "args": [ + "clients/dart/src/generated", + { + "crateFolder": "clients/dart", + "formatCode": true + } + ] + } + } +} ``` -## Usage -Once you have Codama IDL, you can use the `renderVisitor` of this package to generate Dart clients. Provide the base directory where the generated files will be saved and an optional set of options to customize the output. +## Using programmatically in Node.js +You can also use this package directly in your own Node.js scripts. This approach is ideal if you want to generate Dart clients programmatically, giving you full control over the generation process and output options. Simply import the `renderVisitor` function and use it as shown below: ```ts // create-codama-client.js From 6a55a7edbd520b8fcc479cf94cf5269f052fcbf6 Mon Sep 17 00:00:00 2001 From: ERoydev Date: Thu, 18 Sep 2025 09:56:50 +0300 Subject: [PATCH 31/33] update: Add reference to Codama CLI docs in readme --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 2130821..516ee27 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,8 @@ Just add the following script to your Codama configuration file. } } ``` +For more details on configuring Codama using a config file, see the official [Codama CLI documentation](https://github.com/codama-idl/codama/blob/main/packages/cli/README.md) + ## Using programmatically in Node.js You can also use this package directly in your own Node.js scripts. This approach is ideal if you want to generate Dart clients programmatically, giving you full control over the generation process and output options. Simply import the `renderVisitor` function and use it as shown below: From 57170e571b4ccb23b9b15e9a64a7ffaaa5b3f2e2 Mon Sep 17 00:00:00 2001 From: ERoydev Date: Mon, 22 Sep 2025 20:02:19 +0300 Subject: [PATCH 32/33] add: Support for defaultValues for fields that have them from the idl --- public/templates/pages/instructionsPage.njk | 18 +------- src/fragments/InstructionConstructor.ts | 50 +++++++++++++++++++++ src/getRenderMapVisitor.ts | 6 ++- 3 files changed, 56 insertions(+), 18 deletions(-) create mode 100644 src/fragments/InstructionConstructor.ts diff --git a/public/templates/pages/instructionsPage.njk b/public/templates/pages/instructionsPage.njk index 8631854..8e803df 100644 --- a/public/templates/pages/instructionsPage.njk +++ b/public/templates/pages/instructionsPage.njk @@ -40,23 +40,7 @@ {% endfor %} {% endif %} - {{ instruction.name | pascalCase }}Instruction({ - {% for account in instruction.accounts -%} - {%- if account.isOptional -%} - this.{{ account.name | snakeCase }}, - {%- else -%} - required this.{{ account.name | snakeCase }}, - {%- endif -%} - {%- if account.isSigner === 'either' -%} - this.{{ account.name | snakeCase }}IsSigner = false, - {%- endif -%} - {%- endfor -%} - {%- if args and args.length > 0 -%} - {%- for arg in args -%} - required this.{{ arg.name | snakeCase }}, - {%- endfor -%} - {%- endif -%} - }); + {{ instructionConstructorFragmentResult }} /// Builds the `Instruction` (data = discriminator + args). Instruction toInstruction({ List remainingAccounts = const [] }) { diff --git a/src/fragments/InstructionConstructor.ts b/src/fragments/InstructionConstructor.ts new file mode 100644 index 0000000..2c04015 --- /dev/null +++ b/src/fragments/InstructionConstructor.ts @@ -0,0 +1,50 @@ +import { pascalCase, snakeCase } from "@codama/nodes"; + +type Arg = { + name: string; +}; + +export default function instructionConstructorFragment( + instructionName: string, + accounts: any[], + args: Arg[] +) { + let fragment = `${pascalCase(instructionName)}Instruction({\n`; + let defaultAccounts: Record = {}; + + for (const account of accounts) { + if (account.defaultValue && account.defaultValue.kind === "publicKeyValueNode") { + let accountName = snakeCase(account.name); + fragment += `Ed25519HDPublicKey? ${accountName},\n`; + defaultAccounts[accountName] = (account.defaultValue).publicKey; + + } else if (account.isOptional) { + fragment += ` this.${snakeCase(account.name)},\n`; + } else { + fragment += ` required this.${snakeCase(account.name)},\n`; + } + if (account.isSigner === "either") { + fragment += ` this.${snakeCase(account.name)}IsSigner = false,\n`; + } + } + + if (args && args.length > 0) { + for (const arg of args) { + fragment += ` required this.${snakeCase(arg.name)},\n`; + } + } + + fragment += `})`; + + if (Object.keys(defaultAccounts).length > 0) { + fragment += ` : \n`; + const defaults = Object.entries(defaultAccounts).map( + ([key, value]) => `${key} = ${key} ?? Ed25519HDPublicKey.fromBase58('${value}')` + ).join(',\n '); + fragment += ` ${defaults};\n`; + } else { + fragment += `;\n`; + } + + return fragment; +} \ No newline at end of file diff --git a/src/getRenderMapVisitor.ts b/src/getRenderMapVisitor.ts index 9b980a9..467dd01 100644 --- a/src/getRenderMapVisitor.ts +++ b/src/getRenderMapVisitor.ts @@ -33,6 +33,7 @@ import { ImportMap } from './ImportMap'; import TypeManifest, { extractFieldsFromTypeManifest } from './TypeManifest'; import { extractDiscriminatorBytes, getImportFromFactory, LinkOverrides, render } from './utils'; import getAllDefinedTypesInNode from './utils/getAllDefinedTypesInNode'; +import instructionConstructorFragment from './fragments/InstructionConstructor'; export type GetRenderMapOptions = { @@ -153,6 +154,7 @@ export function getRenderMapVisitor(options: GetRenderMapOptions = {}) { }, visitInstruction(node) { + // Collect all accounts with a defaultValue of kind 'publicKeyValueNode', map to snake_case name and publicKey const instructionPath = stack.getPath('instructionNode'); const programNode = findProgramNodeFromPath(instructionPath); if (!programNode) { @@ -204,7 +206,8 @@ export function getRenderMapVisitor(options: GetRenderMapOptions = {}) { isStruct: structTypeNames.has(baseType) } }); - + + const instructionConstructorFragmentResult = instructionConstructorFragment(node.name, node.accounts, args); const context = { args, fields: fields, @@ -215,6 +218,7 @@ export function getRenderMapVisitor(options: GetRenderMapOptions = {}) { }, program: { name: pascalCase(programNode.name || '') }, typeManifest: typeManifest || { nestedStructs: [] }, + instructionConstructorFragmentResult, }; return addToRenderMap( From dbd3be868770522c7a373ddaae579b8614f8740e Mon Sep 17 00:00:00 2001 From: ERoydev Date: Tue, 23 Sep 2025 09:56:52 +0300 Subject: [PATCH 33/33] add: Add comments --- src/fragments/InstructionConstructor.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/fragments/InstructionConstructor.ts b/src/fragments/InstructionConstructor.ts index 2c04015..23cf206 100644 --- a/src/fragments/InstructionConstructor.ts +++ b/src/fragments/InstructionConstructor.ts @@ -4,6 +4,7 @@ type Arg = { name: string; }; +// Generates the Dart constructor argument and initializer fragment for the Dart representation of Solana instruction. export default function instructionConstructorFragment( instructionName: string, accounts: any[], @@ -13,6 +14,7 @@ export default function instructionConstructorFragment( let defaultAccounts: Record = {}; for (const account of accounts) { + // Handle Default Value for nodes that have them and they are public keys if (account.defaultValue && account.defaultValue.kind === "publicKeyValueNode") { let accountName = snakeCase(account.name); fragment += `Ed25519HDPublicKey? ${accountName},\n`; @@ -36,6 +38,7 @@ export default function instructionConstructorFragment( fragment += `})`; + // If there are default accounts, set each default account to its default value if not provided if (Object.keys(defaultAccounts).length > 0) { fragment += ` : \n`; const defaults = Object.entries(defaultAccounts).map(