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: 5 additions & 0 deletions .changeset/hungry-laws-jam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-solana-program": patch
---

Use Codama v1.0.0 (See https://github.com/codama-idl/codama/pull/234)
4 changes: 2 additions & 2 deletions template/clients/base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"validator:stop": "zx ./scripts/stop-validator.mjs"
},
"devDependencies": {
"kinobi": "^0.21.5",
"@kinobi-so/nodes-from-anchor": "^0.21.3"
"codama": "^1.0.0",
"@codama/nodes-from-anchor": "^1.0.0"
}
}
50 changes: 25 additions & 25 deletions template/clients/base/scripts/generate-clients.mjs.njk
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
#!/usr/bin/env zx
import 'zx/globals';
import * as k from 'kinobi';
import { rootNodeFromAnchor } from '@kinobi-so/nodes-from-anchor';
import * as c from 'codama';
import { rootNodeFromAnchor } from '@codama/nodes-from-anchor';
{% if jsClient %}
import { renderVisitor as renderJavaScriptVisitor } from '@kinobi-so/renderers-js';
import { renderVisitor as renderJavaScriptVisitor } from '@codama/renderers-js';
{% endif %}
{% if rustClient %}
import { renderVisitor as renderRustVisitor } from '@kinobi-so/renderers-rust';
import { renderVisitor as renderRustVisitor } from '@codama/renderers-rust';
{% endif %}
import { getAllProgramIdls } from './utils.mjs';

// Instanciate Kinobi.
// Instanciate Codama.
const [idl, ...additionalIdls] = getAllProgramIdls().map((idl) =>
rootNodeFromAnchor(require(idl))
);
const kinobi = k.createFromRoot(idl, additionalIdls);
const codama = c.createFromRoot(idl, additionalIdls);

// Update programs.
kinobi.update(
k.updateProgramsVisitor({
codama.update(
c.updateProgramsVisitor({
{{ programCrateName | camelCase }}: { name: '{{ programName | camelCase }}' },
})
);

{% if programFramework === 'shank' %}
// Update accounts.
kinobi.update(
k.updateAccountsVisitor({
codama.update(
c.updateAccountsVisitor({
counter: {
seeds: [
k.constantPdaSeedNodeFromString('utf8', 'counter'),
k.variablePdaSeedNode(
c.constantPdaSeedNodeFromString('utf8', 'counter'),
c.variablePdaSeedNode(
'authority',
k.publicKeyTypeNode(),
c.publicKeyTypeNode(),
'The authority of the counter account'
),
],
Expand All @@ -41,30 +41,30 @@ kinobi.update(
);

// Update instructions.
kinobi.update(
k.updateInstructionsVisitor({
codama.update(
c.updateInstructionsVisitor({
create: {
byteDeltas: [k.instructionByteDeltaNode(k.accountLinkNode('counter'))],
byteDeltas: [c.instructionByteDeltaNode(c.accountLinkNode('counter'))],
accounts: {
counter: { defaultValue: k.pdaValueNode('counter') },
payer: { defaultValue: k.accountValueNode('authority') },
counter: { defaultValue: c.pdaValueNode('counter') },
payer: { defaultValue: c.accountValueNode('authority') },
},
},
increment: {
accounts: {
counter: { defaultValue: k.pdaValueNode('counter') },
counter: { defaultValue: c.pdaValueNode('counter') },
},
arguments: {
amount: { defaultValue: k.noneValueNode() },
amount: { defaultValue: c.noneValueNode() },
},
},
})
);

// Set account discriminators.
const key = (name) => ({ field: 'key', value: k.enumValueNode('Key', name) });
kinobi.update(
k.setAccountDiscriminatorFromFieldVisitor({
const key = (name) => ({ field: 'key', value: c.enumValueNode('Key', name) });
codama.update(
c.setAccountDiscriminatorFromFieldVisitor({
counter: key('counter'),
})
);
Expand All @@ -73,7 +73,7 @@ kinobi.update(
{% if jsClient %}
// Render JavaScript.
const jsClient = path.join(__dirname, '..', 'clients', 'js');
kinobi.accept(
codama.accept(
renderJavaScriptVisitor(path.join(jsClient, 'src', 'generated'), {
prettierOptions: require(path.join(jsClient, '.prettierrc.json')),
})
Expand All @@ -83,7 +83,7 @@ kinobi.accept(
{% if rustClient %}
// Render Rust.
const rustClient = path.join(__dirname, '..', 'clients', 'rust');
kinobi.accept(
codama.accept(
renderRustVisitor(path.join(rustClient, 'src', 'generated'), {
formatCode: true,
crateFolder: rustClient,
Expand Down
2 changes: 1 addition & 1 deletion template/clients/js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
"clients:js:test": "zx ./scripts/client/test-js.mjs"
},
"devDependencies": {
"@kinobi-so/renderers-js": "^0.21.9"
"@codama/renderers-js": "^1.0.0"
}
}
2 changes: 1 addition & 1 deletion template/clients/rust/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
"clients:rust:test": "zx ./scripts/client/test-rust.mjs"
},
"devDependencies": {
"@kinobi-so/renderers-rust": "^0.21.7"
"@codama/renderers-rust": "^1.0.0"
}
}