Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@
"typecheck": "tsc --noEmit",
"fetch:openapi": "tsx scripts/fetch-openapi.ts",
"fetch:arc56": "tsx scripts/fetch-arc56.ts",
"postfetch:arc56": "tsx scripts/clean-arc56.ts",
"fetch:specs": "pnpm fetch:openapi && pnpm fetch:arc56",
"generate:clients": "algokit generate client src/contracts/ --language typescript --output src/contracts/{contract_name}Client.ts",
"generate:clients": "algokit generate client src/contracts/minimal/ --language typescript --output src/contracts/{contract_name}Client.ts",
"generate:openapi": "openapi-ts",
"generate": "pnpm fetch:specs && pnpm generate:clients && pnpm generate:openapi"
},
Expand All @@ -75,13 +76,15 @@
"@hey-api/openapi-ts": "^0.64.5",
"@tanstack/config": "^0.16.2",
"@types/crypto-js": "^4.2.2",
"@types/node": "^22.13.9",
"@types/node-fetch": "^2.6.12",
"@vitest/coverage-v8": "^3.0.7",
"@vitest/ui": "^3.0.7",
"dotenv": "^16.4.7",
"node-fetch": "^3.3.2",
"publint": "^0.3.6",
"tsx": "^4.19.3",
"type-fest": "^4.37.0",
"vite": "^6.2.0",
"vite-plugin-dts": "^4.5.0",
"vite-tsconfig-paths": "^5.1.4",
Expand Down
98 changes: 98 additions & 0 deletions packages/sdk/scripts/clean-arc56.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import { readFileSync, writeFileSync, mkdirSync, existsSync } from 'node:fs'
import { join } from 'node:path'

import type { JsonValue } from 'type-fest'

const contractsDir = join(process.cwd(), 'src', 'contracts')
const minimalDir = join(contractsDir, 'minimal')

// Create the minimal directory if it doesn't exist
if (!existsSync(minimalDir)) {
mkdirSync(minimalDir, { recursive: true })
}

const files = [
{
source: 'NFDInstance.arc56.json',
target: 'NFDInstance.arc56.json',
},
{
source: 'NFDRegistry.arc56.json',
target: 'NFDRegistry.arc56.json',
},
]

interface SourceInfoItem {
errorMessage?: string
teal?: number
source?: string
pc?: number[]
[key: string]: JsonValue | undefined
}

interface ApprovalSourceInfo {
sourceInfo: SourceInfoItem[]
[key: string]: JsonValue | SourceInfoItem[] | undefined
}

interface Arc56Json {
source?: {
approval?: { bytecode: string }
clear?: { bytecode: string }
}
sourceInfo?: {
approval?: ApprovalSourceInfo
clear?: ApprovalSourceInfo
[key: string]: ApprovalSourceInfo | undefined
}
[key: string]:
| JsonValue
| { [key: string]: ApprovalSourceInfo | undefined }
| { approval?: { bytecode: string }; clear?: { bytecode: string } }
| undefined
}

files.forEach(({ source, target }) => {
const sourceFilePath = join(contractsDir, source)
const targetFilePath = join(minimalDir, target)

// Read and parse the JSON file
const content = JSON.parse(readFileSync(sourceFilePath, 'utf-8')) as Arc56Json

// Remove the top-level source property
delete content.source

// If sourceInfo exists, filter it
if (content.sourceInfo) {
// Handle approval sourceInfo
if (content.sourceInfo.approval?.sourceInfo) {
content.sourceInfo.approval.sourceInfo =
content.sourceInfo.approval.sourceInfo.filter(
(info): info is SourceInfoItem =>
info && typeof info === 'object' && 'errorMessage' in info,
)
}

// Handle clear sourceInfo if it exists
if (content.sourceInfo.clear?.sourceInfo) {
content.sourceInfo.clear.sourceInfo =
content.sourceInfo.clear.sourceInfo.filter(
(info): info is SourceInfoItem =>
info && typeof info === 'object' && 'errorMessage' in info,
)
}
}

// Write the modified content to the target file
writeFileSync(targetFilePath, JSON.stringify(content, null, 2))

const originalSize = readFileSync(sourceFilePath).length
const newSize = readFileSync(targetFilePath).length
const reduction = (((originalSize - newSize) / originalSize) * 100).toFixed(1)

console.log(
`Created ${join('minimal', target)}: Size reduced by ${reduction}% from original`,
)
})

console.log('Finished creating minimal ARC56 files')
2 changes: 1 addition & 1 deletion packages/sdk/src/contracts/NFDInstanceClient.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/sdk/src/contracts/NFDRegistryClient.ts

Large diffs are not rendered by default.

Loading