@codama/renderers-js 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +23 -0
- package/README.md +54 -0
- package/dist/index.node.cjs +2733 -0
- package/dist/index.node.cjs.map +1 -0
- package/dist/index.node.mjs +2700 -0
- package/dist/index.node.mjs.map +1 -0
- package/dist/templates/fragments/accountFetchHelpers.njk +43 -0
- package/dist/templates/fragments/accountPdaHelpers.njk +25 -0
- package/dist/templates/fragments/accountSizeHelpers.njk +3 -0
- package/dist/templates/fragments/instructionExtraArgs.njk +4 -0
- package/dist/templates/fragments/instructionFunction.njk +62 -0
- package/dist/templates/fragments/instructionInputType.njk +16 -0
- package/dist/templates/fragments/instructionParseFunction.njk +81 -0
- package/dist/templates/fragments/instructionType.njk +18 -0
- package/dist/templates/fragments/pdaFunction.njk +32 -0
- package/dist/templates/fragments/program.njk +3 -0
- package/dist/templates/fragments/programErrors.njk +36 -0
- package/dist/templates/fragments/type.njk +12 -0
- package/dist/templates/fragments/typeCodec.njk +6 -0
- package/dist/templates/fragments/typeDecoder.njk +6 -0
- package/dist/templates/fragments/typeDiscriminatedUnionHelpers.njk +23 -0
- package/dist/templates/fragments/typeEncoder.njk +6 -0
- package/dist/templates/layout.njk +9 -0
- package/dist/templates/macros.njk +12 -0
- package/dist/templates/pages/accountsIndex.njk +9 -0
- package/dist/templates/pages/accountsPage.njk +12 -0
- package/dist/templates/pages/definedTypesIndex.njk +9 -0
- package/dist/templates/pages/definedTypesPage.njk +9 -0
- package/dist/templates/pages/errorsIndex.njk +9 -0
- package/dist/templates/pages/errorsPage.njk +8 -0
- package/dist/templates/pages/instructionsIndex.njk +9 -0
- package/dist/templates/pages/instructionsPage.njk +14 -0
- package/dist/templates/pages/pdasIndex.njk +9 -0
- package/dist/templates/pages/pdasPage.njk +8 -0
- package/dist/templates/pages/programsIndex.njk +9 -0
- package/dist/templates/pages/programsPage.njk +10 -0
- package/dist/templates/pages/rootIndex.njk +26 -0
- package/dist/templates/pages/sharedPage.njk +106 -0
- package/dist/types/ImportMap.d.ts +15 -0
- package/dist/types/ImportMap.d.ts.map +1 -0
- package/dist/types/TypeManifest.d.ts +16 -0
- package/dist/types/TypeManifest.d.ts.map +1 -0
- package/dist/types/fragments/accountFetchHelpers.d.ts +9 -0
- package/dist/types/fragments/accountFetchHelpers.d.ts.map +1 -0
- package/dist/types/fragments/accountPdaHelpers.d.ts +10 -0
- package/dist/types/fragments/accountPdaHelpers.d.ts.map +1 -0
- package/dist/types/fragments/accountSizeHelpers.d.ts +7 -0
- package/dist/types/fragments/accountSizeHelpers.d.ts.map +1 -0
- package/dist/types/fragments/accountType.d.ts +9 -0
- package/dist/types/fragments/accountType.d.ts.map +1 -0
- package/dist/types/fragments/common.d.ts +25 -0
- package/dist/types/fragments/common.d.ts.map +1 -0
- package/dist/types/fragments/discriminatorCondition.d.ts +26 -0
- package/dist/types/fragments/discriminatorCondition.d.ts.map +1 -0
- package/dist/types/fragments/discriminatorConstants.d.ts +22 -0
- package/dist/types/fragments/discriminatorConstants.d.ts.map +1 -0
- package/dist/types/fragments/index.d.ts +31 -0
- package/dist/types/fragments/index.d.ts.map +1 -0
- package/dist/types/fragments/instructionAccountMeta.d.ts +4 -0
- package/dist/types/fragments/instructionAccountMeta.d.ts.map +1 -0
- package/dist/types/fragments/instructionAccountTypeParam.d.ts +10 -0
- package/dist/types/fragments/instructionAccountTypeParam.d.ts.map +1 -0
- package/dist/types/fragments/instructionByteDelta.d.ts +8 -0
- package/dist/types/fragments/instructionByteDelta.d.ts.map +1 -0
- package/dist/types/fragments/instructionData.d.ts +9 -0
- package/dist/types/fragments/instructionData.d.ts.map +1 -0
- package/dist/types/fragments/instructionExtraArgs.d.ts +9 -0
- package/dist/types/fragments/instructionExtraArgs.d.ts.map +1 -0
- package/dist/types/fragments/instructionFunction.d.ts +15 -0
- package/dist/types/fragments/instructionFunction.d.ts.map +1 -0
- package/dist/types/fragments/instructionInputDefault.d.ts +9 -0
- package/dist/types/fragments/instructionInputDefault.d.ts.map +1 -0
- package/dist/types/fragments/instructionInputResolved.d.ts +10 -0
- package/dist/types/fragments/instructionInputResolved.d.ts.map +1 -0
- package/dist/types/fragments/instructionInputType.d.ts +13 -0
- package/dist/types/fragments/instructionInputType.d.ts.map +1 -0
- package/dist/types/fragments/instructionParseFunction.d.ts +10 -0
- package/dist/types/fragments/instructionParseFunction.d.ts.map +1 -0
- package/dist/types/fragments/instructionRemainingAccounts.d.ts +8 -0
- package/dist/types/fragments/instructionRemainingAccounts.d.ts.map +1 -0
- package/dist/types/fragments/instructionType.d.ts +8 -0
- package/dist/types/fragments/instructionType.d.ts.map +1 -0
- package/dist/types/fragments/pdaFunction.d.ts +8 -0
- package/dist/types/fragments/pdaFunction.d.ts.map +1 -0
- package/dist/types/fragments/program.d.ts +7 -0
- package/dist/types/fragments/program.d.ts.map +1 -0
- package/dist/types/fragments/programAccounts.d.ts +7 -0
- package/dist/types/fragments/programAccounts.d.ts.map +1 -0
- package/dist/types/fragments/programErrors.d.ts +7 -0
- package/dist/types/fragments/programErrors.d.ts.map +1 -0
- package/dist/types/fragments/programInstructions.d.ts +7 -0
- package/dist/types/fragments/programInstructions.d.ts.map +1 -0
- package/dist/types/fragments/type.d.ts +9 -0
- package/dist/types/fragments/type.d.ts.map +1 -0
- package/dist/types/fragments/typeCodec.d.ts +11 -0
- package/dist/types/fragments/typeCodec.d.ts.map +1 -0
- package/dist/types/fragments/typeDecoder.d.ts +9 -0
- package/dist/types/fragments/typeDecoder.d.ts.map +1 -0
- package/dist/types/fragments/typeDiscriminatedUnionHelpers.d.ts +8 -0
- package/dist/types/fragments/typeDiscriminatedUnionHelpers.d.ts.map +1 -0
- package/dist/types/fragments/typeEncoder.d.ts +9 -0
- package/dist/types/fragments/typeEncoder.d.ts.map +1 -0
- package/dist/types/fragments/typeWithCodec.d.ts +12 -0
- package/dist/types/fragments/typeWithCodec.d.ts.map +1 -0
- package/dist/types/getRenderMapVisitor.d.ts +31 -0
- package/dist/types/getRenderMapVisitor.d.ts.map +1 -0
- package/dist/types/getTypeManifestVisitor.d.ts +19 -0
- package/dist/types/getTypeManifestVisitor.d.ts.map +1 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/nameTransformers.d.ts +15 -0
- package/dist/types/nameTransformers.d.ts.map +1 -0
- package/dist/types/renderVisitor.d.ts +11 -0
- package/dist/types/renderVisitor.d.ts.map +1 -0
- package/dist/types/utils/async.d.ts +7 -0
- package/dist/types/utils/async.d.ts.map +1 -0
- package/dist/types/utils/codecs.d.ts +3 -0
- package/dist/types/utils/codecs.d.ts.map +1 -0
- package/dist/types/utils/customData.d.ts +18 -0
- package/dist/types/utils/customData.d.ts.map +1 -0
- package/dist/types/utils/index.d.ts +6 -0
- package/dist/types/utils/index.d.ts.map +1 -0
- package/dist/types/utils/linkOverrides.d.ts +15 -0
- package/dist/types/utils/linkOverrides.d.ts.map +1 -0
- package/dist/types/utils/render.d.ts +4 -0
- package/dist/types/utils/render.d.ts.map +1 -0
- package/package.json +70 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export function {{ decodeFunction }}<TAddress extends string = string>(encodedAccount: EncodedAccount<TAddress>): Account<{{ accountType }}, TAddress>;
|
|
2
|
+
export function {{ decodeFunction }}<TAddress extends string = string>(encodedAccount: MaybeEncodedAccount<TAddress>): MaybeAccount<{{ accountType }}, TAddress>;
|
|
3
|
+
export function {{ decodeFunction }}<TAddress extends string = string>(encodedAccount: EncodedAccount<TAddress> | MaybeEncodedAccount<TAddress>): Account<{{ accountType }}, TAddress> | MaybeAccount<{{ accountType }}, TAddress> {
|
|
4
|
+
return decodeAccount(encodedAccount as MaybeEncodedAccount<TAddress>, {{ decoderFunction }});
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export async function {{ fetchFunction }}<TAddress extends string = string>(
|
|
8
|
+
rpc: Parameters<typeof fetchEncodedAccount>[0],
|
|
9
|
+
address: Address<TAddress>,
|
|
10
|
+
config?: FetchAccountConfig,
|
|
11
|
+
): Promise<Account<{{ accountType }}, TAddress>> {
|
|
12
|
+
const maybeAccount = await {{ fetchMaybeFunction }}(rpc, address, config);
|
|
13
|
+
assertAccountExists(maybeAccount);
|
|
14
|
+
return maybeAccount;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export async function {{ fetchMaybeFunction }}<TAddress extends string = string>(
|
|
18
|
+
rpc: Parameters<typeof fetchEncodedAccount>[0],
|
|
19
|
+
address: Address<TAddress>,
|
|
20
|
+
config?: FetchAccountConfig,
|
|
21
|
+
): Promise<MaybeAccount<{{ accountType }}, TAddress>> {
|
|
22
|
+
const maybeAccount = await fetchEncodedAccount(rpc, address, config);
|
|
23
|
+
return {{ decodeFunction }}(maybeAccount);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export async function {{ fetchAllFunction }}(
|
|
27
|
+
rpc: Parameters<typeof fetchEncodedAccounts>[0],
|
|
28
|
+
addresses: Array<Address>,
|
|
29
|
+
config?: FetchAccountsConfig,
|
|
30
|
+
): Promise<Account<{{ accountType }}>[]> {
|
|
31
|
+
const maybeAccounts = await {{ fetchAllMaybeFunction }}(rpc, addresses, config);
|
|
32
|
+
assertAccountsExist(maybeAccounts);
|
|
33
|
+
return maybeAccounts;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export async function {{ fetchAllMaybeFunction }}(
|
|
37
|
+
rpc: Parameters<typeof fetchEncodedAccounts>[0],
|
|
38
|
+
addresses: Array<Address>,
|
|
39
|
+
config?: FetchAccountsConfig,
|
|
40
|
+
): Promise<MaybeAccount<{{ accountType }}>[]> {
|
|
41
|
+
const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
|
|
42
|
+
return maybeAccounts.map((maybeAccount) => {{ decodeFunction }}(maybeAccount));
|
|
43
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{% import "macros.njk" as macros %}
|
|
2
|
+
|
|
3
|
+
export async function {{ fetchFromSeedsFunction }}(
|
|
4
|
+
rpc: Parameters<typeof fetchEncodedAccount>[0],
|
|
5
|
+
{% if hasVariableSeeds %}
|
|
6
|
+
seeds: {{ pdaSeedsType }},
|
|
7
|
+
{% endif %}
|
|
8
|
+
config: FetchAccountConfig & { programAddress?: Address } = {},
|
|
9
|
+
): Promise<Account<{{ accountType }}>> {
|
|
10
|
+
const maybeAccount = await {{ fetchMaybeFromSeedsFunction }}(rpc, {% if hasVariableSeeds %}seeds, {% endif %}config);
|
|
11
|
+
assertAccountExists(maybeAccount);
|
|
12
|
+
return maybeAccount;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export async function {{ fetchMaybeFromSeedsFunction }}(
|
|
16
|
+
rpc: Parameters<typeof fetchEncodedAccount>[0],
|
|
17
|
+
{% if hasVariableSeeds %}
|
|
18
|
+
seeds: {{ pdaSeedsType }},
|
|
19
|
+
{% endif %}
|
|
20
|
+
config: FetchAccountConfig & { programAddress?: Address } = {},
|
|
21
|
+
): Promise<MaybeAccount<{{ accountType }}>> {
|
|
22
|
+
const { programAddress, ...fetchConfig } = config;
|
|
23
|
+
const [address] = await {{ findPdaFunction }}({% if hasVariableSeeds %}seeds, {% endif %}{ programAddress });
|
|
24
|
+
return await {{ fetchMaybeFunction }}(rpc, address, fetchConfig);
|
|
25
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
{{ inputTypeFragment }}
|
|
2
|
+
|
|
3
|
+
export {{ 'async' if useAsync }} function {{ functionName }}{{ typeParamsFragment }}(input: {{ inputTypeCallFragment }}, config?: { programAddress?: TProgramAddress } ): {{ getReturnType(instructionTypeFragment) }} {
|
|
4
|
+
// Program address.
|
|
5
|
+
const programAddress = config?.programAddress ?? {{ programAddressConstant }};
|
|
6
|
+
|
|
7
|
+
{% if hasAccounts %}
|
|
8
|
+
// Original accounts.
|
|
9
|
+
const originalAccounts = {
|
|
10
|
+
{% for account in instruction.accounts %}
|
|
11
|
+
{{ account.name | camelCase }}: { value: input.{{ account.name | camelCase }} ?? null, isWritable: {{ "true" if account.isWritable else "false" }} },
|
|
12
|
+
{% endfor %}
|
|
13
|
+
};
|
|
14
|
+
const accounts = originalAccounts as Record<keyof typeof originalAccounts, ResolvedAccount>;
|
|
15
|
+
{% endif %}
|
|
16
|
+
|
|
17
|
+
{% if hasAnyArgs %}
|
|
18
|
+
// Original args.
|
|
19
|
+
const args = { ...input, {{ renamedArgs }} };
|
|
20
|
+
{% endif %}
|
|
21
|
+
|
|
22
|
+
{% if hasResolver %}
|
|
23
|
+
// Resolver scope.
|
|
24
|
+
const resolverScope = { programAddress{{ ', accounts' if hasAccounts }}{{ ', args' if hasAnyArgs }} };
|
|
25
|
+
{% endif %}
|
|
26
|
+
|
|
27
|
+
{{ resolvedFragment }}
|
|
28
|
+
|
|
29
|
+
{% if hasAccounts %}
|
|
30
|
+
const getAccountMeta = getAccountMetaFactory(programAddress, '{{ 'omitted' if instruction.optionalAccountStrategy === 'omitted' else 'programId' }}');
|
|
31
|
+
{% endif %}
|
|
32
|
+
const instruction = {
|
|
33
|
+
{%- if hasAccounts -%}
|
|
34
|
+
accounts: [
|
|
35
|
+
{% for account in instruction.accounts %}
|
|
36
|
+
getAccountMeta(accounts.{{ account.name | camelCase }}),
|
|
37
|
+
{% endfor %}
|
|
38
|
+
{% if hasRemainingAccounts %}
|
|
39
|
+
...remainingAccounts,
|
|
40
|
+
{% endif %}
|
|
41
|
+
]
|
|
42
|
+
{%- if hasLegacyOptionalAccounts -%}
|
|
43
|
+
.filter(<T>(x: T | undefined): x is T => x !== undefined)
|
|
44
|
+
{% endif %}
|
|
45
|
+
,
|
|
46
|
+
{%- elif hasRemainingAccounts -%}
|
|
47
|
+
accounts: remainingAccounts,
|
|
48
|
+
{% endif %}
|
|
49
|
+
programAddress,
|
|
50
|
+
{% if hasDataArgs %}
|
|
51
|
+
data: {{ encoderFunction }}.encode(args as {{ argsTypeFragment }}),
|
|
52
|
+
{% elif hasData %}
|
|
53
|
+
data: {{ encoderFunction }}.encode({}),
|
|
54
|
+
{% endif %}
|
|
55
|
+
} as {{ instructionTypeFragment }};
|
|
56
|
+
|
|
57
|
+
{% if hasByteDeltas %}
|
|
58
|
+
return Object.freeze({ ...instruction, byteDelta });
|
|
59
|
+
{% else %}
|
|
60
|
+
return instruction;
|
|
61
|
+
{% endif %}
|
|
62
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{% import "macros.njk" as macros %}
|
|
2
|
+
|
|
3
|
+
export type {{ instructionInputType }}
|
|
4
|
+
{%- if instruction.accounts.length > 0 -%}
|
|
5
|
+
<
|
|
6
|
+
{%- for account in instruction.accounts -%}
|
|
7
|
+
TAccount{{ account.name | pascalCase }} extends string = string,
|
|
8
|
+
{% endfor %}
|
|
9
|
+
>
|
|
10
|
+
{% endif %}
|
|
11
|
+
= {{ customDataArgumentsFragment }} {
|
|
12
|
+
{{ accountsFragment -}}
|
|
13
|
+
{{ dataArgumentsFragment -}}
|
|
14
|
+
{{ extraArgumentsFragment -}}
|
|
15
|
+
{{ remainingAccountsFragment }}
|
|
16
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
{% import "macros.njk" as macros %}
|
|
2
|
+
|
|
3
|
+
export type {{ instructionParsedType }}<
|
|
4
|
+
TProgram extends string = typeof {{ programAddressConstant }},
|
|
5
|
+
{% if hasAccounts %}
|
|
6
|
+
TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[],
|
|
7
|
+
{% endif %}
|
|
8
|
+
> = {
|
|
9
|
+
programAddress: Address<TProgram>;
|
|
10
|
+
{% if hasAccounts %}
|
|
11
|
+
accounts: {
|
|
12
|
+
{% for account in instruction.accounts %}
|
|
13
|
+
{% if account.docs.length > 0 %}
|
|
14
|
+
{{ macros.docblock(account.docs) }}
|
|
15
|
+
{% endif %}
|
|
16
|
+
{{ account.name | camelCase }}{{ '?' if account.isOptional }}: TAccountMetas[{{ loop.index0 }}]{{ ' | undefined' if account.isOptional }},
|
|
17
|
+
{% endfor %}
|
|
18
|
+
};
|
|
19
|
+
{% endif %}
|
|
20
|
+
{% if hasData %}
|
|
21
|
+
data: {{ dataTypeFragment }};
|
|
22
|
+
{% endif %}
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export function {{ instructionParseFunction }}<
|
|
26
|
+
TProgram extends string,
|
|
27
|
+
{% if hasAccounts %}
|
|
28
|
+
TAccountMetas extends readonly IAccountMeta[],
|
|
29
|
+
{% endif %}
|
|
30
|
+
>(
|
|
31
|
+
instruction: IInstruction<TProgram>
|
|
32
|
+
{% if hasAccounts %}
|
|
33
|
+
& IInstructionWithAccounts<TAccountMetas>
|
|
34
|
+
{% endif %}
|
|
35
|
+
{% if hasData %}
|
|
36
|
+
& IInstructionWithData<Uint8Array>
|
|
37
|
+
{% endif %}
|
|
38
|
+
): {{ instructionParsedType }}<TProgram {{ ', TAccountMetas' if hasAccounts }}> {
|
|
39
|
+
{% if hasAccounts %}
|
|
40
|
+
if (instruction.accounts.length < {{ minimumNumberOfAccounts }}) {
|
|
41
|
+
// TODO: Coded error.
|
|
42
|
+
throw new Error('Not enough accounts');
|
|
43
|
+
}
|
|
44
|
+
let accountIndex = 0;
|
|
45
|
+
const getNextAccount = () => {
|
|
46
|
+
const accountMeta = instruction.accounts![accountIndex]!;
|
|
47
|
+
accountIndex += 1;
|
|
48
|
+
return accountMeta;
|
|
49
|
+
}
|
|
50
|
+
{% if hasOptionalAccounts and instruction.optionalAccountStrategy === 'programId' %}
|
|
51
|
+
const getNextOptionalAccount = () => {
|
|
52
|
+
const accountMeta = getNextAccount();
|
|
53
|
+
return accountMeta.address === {{ programAddressConstant }} ? undefined : accountMeta;
|
|
54
|
+
};
|
|
55
|
+
{% elif hasOptionalAccounts and instruction.optionalAccountStrategy === 'omitted' %}
|
|
56
|
+
let optionalAccountsRemaining = instruction.accounts.length - {{ minimumNumberOfAccounts }};
|
|
57
|
+
const getNextOptionalAccount = () => {
|
|
58
|
+
if (optionalAccountsRemaining === 0) return undefined;
|
|
59
|
+
optionalAccountsRemaining -= 1;
|
|
60
|
+
return getNextAccount();
|
|
61
|
+
};
|
|
62
|
+
{% endif %}
|
|
63
|
+
{% endif %}
|
|
64
|
+
return {
|
|
65
|
+
programAddress: instruction.programAddress,
|
|
66
|
+
{% if hasAccounts %}
|
|
67
|
+
accounts: {
|
|
68
|
+
{% for account in instruction.accounts %}
|
|
69
|
+
{% if account.isOptional %}
|
|
70
|
+
{{ account.name | camelCase }}: getNextOptionalAccount(),
|
|
71
|
+
{% else %}
|
|
72
|
+
{{ account.name | camelCase }}: getNextAccount(),
|
|
73
|
+
{% endif %}
|
|
74
|
+
{% endfor %}
|
|
75
|
+
},
|
|
76
|
+
{% endif %}
|
|
77
|
+
{% if hasData %}
|
|
78
|
+
data: {{ decoderFunction }}.decode(instruction.data),
|
|
79
|
+
{% endif %}
|
|
80
|
+
};
|
|
81
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{% import "macros.njk" as macros %}
|
|
2
|
+
|
|
3
|
+
export type {{ instructionType }}<
|
|
4
|
+
TProgram extends string = typeof {{ programAddressConstant }},
|
|
5
|
+
{% if hasAccounts %}
|
|
6
|
+
{{ accountTypeParams }},
|
|
7
|
+
{% endif %}
|
|
8
|
+
TRemainingAccounts extends readonly IAccountMeta<string>[] = [],
|
|
9
|
+
> = IInstruction<TProgram>
|
|
10
|
+
{% if hasData %}
|
|
11
|
+
& IInstructionWithData<Uint8Array>
|
|
12
|
+
{% endif %}
|
|
13
|
+
{% if hasAccounts %}
|
|
14
|
+
& IInstructionWithAccounts<[{{ accountMetas }}, ...TRemainingAccounts]>
|
|
15
|
+
{% else %}
|
|
16
|
+
& IInstructionWithAccounts<TRemainingAccounts>
|
|
17
|
+
{% endif %}
|
|
18
|
+
;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{% import "macros.njk" as macros %}
|
|
2
|
+
|
|
3
|
+
{% if hasVariableSeeds %}
|
|
4
|
+
export type {{ pdaSeedsType }} = {
|
|
5
|
+
{% for seed in seeds %}
|
|
6
|
+
{% if seed.kind === 'variablePdaSeedNode' %}
|
|
7
|
+
{{ macros.docblock(seed.docs) }}
|
|
8
|
+
{{ seed.name | camelCase }}: {{ seed.typeManifest.looseType.render }};
|
|
9
|
+
{% endif %}
|
|
10
|
+
{% endfor %}
|
|
11
|
+
}
|
|
12
|
+
{% endif %}
|
|
13
|
+
|
|
14
|
+
export async function {{ findPdaFunction }}(
|
|
15
|
+
{% if hasVariableSeeds %}
|
|
16
|
+
seeds: {{ pdaSeedsType }},
|
|
17
|
+
{% endif %}
|
|
18
|
+
config: { programAddress?: Address | undefined } = {},
|
|
19
|
+
): Promise<ProgramDerivedAddress> {
|
|
20
|
+
const { programAddress = '{{ programAddress }}' as Address<'{{ programAddress }}'> } = config;
|
|
21
|
+
return await getProgramDerivedAddress({ programAddress, seeds: [
|
|
22
|
+
{% for seed in seeds %}
|
|
23
|
+
{% if seed.kind === 'constantPdaSeedNode' and seed.value.kind === 'programIdValueNode' %}
|
|
24
|
+
getAddressEncoder().encode(programAddress),
|
|
25
|
+
{% elif seed.kind === 'constantPdaSeedNode' %}
|
|
26
|
+
{{ seed.typeManifest.encoder.render }}.encode({{ seed.valueManifest.render }}),
|
|
27
|
+
{% else %}
|
|
28
|
+
{{ seed.typeManifest.encoder.render }}.encode(seeds.{{ seed.name | camelCase }}),
|
|
29
|
+
{% endif %}
|
|
30
|
+
{% endfor %}
|
|
31
|
+
]});
|
|
32
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{% import "macros.njk" as macros %}
|
|
2
|
+
|
|
3
|
+
{% for error in errors | sort(false, false, 'code') %}
|
|
4
|
+
{{ macros.docblock(error.docs) }}
|
|
5
|
+
export const {{ getProgramErrorConstant(error.name) }} = 0x{{ error.code.toString(16) }}, // {{ error.code }}
|
|
6
|
+
{% endfor %}
|
|
7
|
+
|
|
8
|
+
export type {{ programErrorUnion }} =
|
|
9
|
+
{% for error in errors | sort(false, false, 'name') %}
|
|
10
|
+
| typeof {{ getProgramErrorConstant(error.name) }}
|
|
11
|
+
{% endfor %};
|
|
12
|
+
|
|
13
|
+
let {{ programErrorMessagesMap }}: Record<{{ programErrorUnion }}, string> | undefined;
|
|
14
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
15
|
+
{{ programErrorMessagesMap }} = {
|
|
16
|
+
{% for error in errors | sort(false, false, 'name') %}
|
|
17
|
+
[{{ getProgramErrorConstant(error.name) }}]: `{{ error.message }}`,
|
|
18
|
+
{% endfor %}
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function {{ programGetErrorMessageFunction }}(code: {{ programErrorUnion }}): string {
|
|
23
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
24
|
+
return ({{ programErrorMessagesMap }} as Record<{{ programErrorUnion }}, string>)[code];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return 'Error message not available in production bundles.';
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function {{ programIsErrorFunction }}<TProgramErrorCode extends {{ programErrorUnion }}>(
|
|
31
|
+
error: unknown,
|
|
32
|
+
transactionMessage: { instructions: Record<number, { programAddress: Address }> },
|
|
33
|
+
code?: TProgramErrorCode,
|
|
34
|
+
): error is SolanaError<typeof SOLANA_ERROR__INSTRUCTION_ERROR__CUSTOM> & Readonly<{ context: Readonly<{ code: TProgramErrorCode }> }> {
|
|
35
|
+
return isProgramError<TProgramErrorCode>(error, transactionMessage, {{ programAddressConstant }}, code);
|
|
36
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{% import "macros.njk" as macros %}
|
|
2
|
+
|
|
3
|
+
{{ macros.docblock(docs) }}
|
|
4
|
+
{% if manifest.isEnum %}
|
|
5
|
+
export enum {{ strictName }} {{ manifest.strictType.render }};
|
|
6
|
+
|
|
7
|
+
export type {{ looseName }} = {{ strictName }};
|
|
8
|
+
{% else %}
|
|
9
|
+
export type {{ strictName }} = {{ manifest.strictType.render }};
|
|
10
|
+
|
|
11
|
+
export type {{ looseName }} = {{ manifest.looseType.render if manifest.strictType.render != manifest.looseType.render else strictName }};
|
|
12
|
+
{% endif %}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// Data Enum Helpers.
|
|
2
|
+
{% for variant in typeNode.variants %}
|
|
3
|
+
{% if variant.kind === 'enumStructVariantTypeNode' %}
|
|
4
|
+
export function {{ discriminatedUnionFunction }}(kind: '{{ getVariant(variant.name) }}', data: GetDiscriminatedUnionVariantContent<{{ looseName }}, '{{ discriminatedUnionDiscriminator }}', '{{ getVariant(variant.name) }}'>): GetDiscriminatedUnionVariant<{{ looseName }}, '{{ discriminatedUnionDiscriminator }}', '{{ getVariant(variant.name) }}'>;
|
|
5
|
+
{% elif variant.kind === 'enumTupleVariantTypeNode' %}
|
|
6
|
+
export function {{ discriminatedUnionFunction }}(kind: '{{ getVariant(variant.name) }}', data: GetDiscriminatedUnionVariantContent<{{ looseName }}, '{{ discriminatedUnionDiscriminator }}', '{{ getVariant(variant.name) }}'>['fields']): GetDiscriminatedUnionVariant<{{ looseName }}, '{{ discriminatedUnionDiscriminator }}', '{{ getVariant(variant.name) }}'>;
|
|
7
|
+
{% else %}
|
|
8
|
+
export function {{ discriminatedUnionFunction }}(kind: '{{ getVariant(variant.name) }}'): GetDiscriminatedUnionVariant<{{ looseName }}, '{{ discriminatedUnionDiscriminator }}', '{{ getVariant(variant.name) }}'>;
|
|
9
|
+
{% endif %}
|
|
10
|
+
{% endfor %}
|
|
11
|
+
export function {{ discriminatedUnionFunction }}<K extends {{ looseName }}['{{ discriminatedUnionDiscriminator }}'], Data>(
|
|
12
|
+
kind: K,
|
|
13
|
+
data?: Data,
|
|
14
|
+
) {
|
|
15
|
+
return Array.isArray(data) ? { {{ discriminatedUnionDiscriminator }}: kind, fields: data } : { {{ discriminatedUnionDiscriminator }}: kind, ...(data ?? {}) };
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function {{ isDiscriminatedUnionFunction }}<K extends {{ strictName }}['{{ discriminatedUnionDiscriminator }}']>(
|
|
19
|
+
kind: K,
|
|
20
|
+
value: {{ strictName }},
|
|
21
|
+
): value is {{ strictName }} & { {{ discriminatedUnionDiscriminator }}: K } {
|
|
22
|
+
return value.{{ discriminatedUnionDiscriminator }} === kind;
|
|
23
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{# Write a docblock from an array of strings. #}
|
|
2
|
+
{% macro docblock(docs) %}
|
|
3
|
+
{%- if docs.length === 1 -%}
|
|
4
|
+
/** {{ docs[0] }} */
|
|
5
|
+
{%- elif docs.length > 1 -%}
|
|
6
|
+
/**
|
|
7
|
+
{% for doc in docs %}
|
|
8
|
+
* {{ doc }}
|
|
9
|
+
{% endfor %}
|
|
10
|
+
*/
|
|
11
|
+
{% endif %}
|
|
12
|
+
{% endmacro %}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{% extends "layout.njk" %}
|
|
2
|
+
{% import "macros.njk" as macros %}
|
|
3
|
+
|
|
4
|
+
{% block main %}
|
|
5
|
+
{{ imports }}
|
|
6
|
+
|
|
7
|
+
{{ accountDiscriminatorConstantsFragment }}
|
|
8
|
+
{{ accountTypeFragment }}
|
|
9
|
+
{{ accountFetchHelpersFragment }}
|
|
10
|
+
{{ accountSizeHelpersFragment }}
|
|
11
|
+
{{ accountPdaHelpersFragment }}
|
|
12
|
+
{% endblock %}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{% extends "layout.njk" %}
|
|
2
|
+
{% import "macros.njk" as macros %}
|
|
3
|
+
|
|
4
|
+
{% block main %}
|
|
5
|
+
{{ imports }}
|
|
6
|
+
|
|
7
|
+
{{ instructionDiscriminatorConstantsFragment }}
|
|
8
|
+
{{ instructionTypeFragment }}
|
|
9
|
+
{{ instructionDataFragment }}
|
|
10
|
+
{{ instructionExtraArgsFragment }}
|
|
11
|
+
{{ instructionFunctionAsyncFragment }}
|
|
12
|
+
{{ instructionFunctionSyncFragment }}
|
|
13
|
+
{{ instructionParseFunctionFragment }}
|
|
14
|
+
{% endblock %}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{% extends "layout.njk" %}
|
|
2
|
+
|
|
3
|
+
{% block main %}
|
|
4
|
+
{% if hasAnythingToExport %}
|
|
5
|
+
{% if accountsToExport.length > 0 %}
|
|
6
|
+
export * from './accounts';
|
|
7
|
+
{% endif %}
|
|
8
|
+
{% if programsWithErrorsToExport.length > 0 %}
|
|
9
|
+
export * from './errors';
|
|
10
|
+
{% endif %}
|
|
11
|
+
{% if instructionsToExport.length > 0 %}
|
|
12
|
+
export * from './instructions';
|
|
13
|
+
{% endif %}
|
|
14
|
+
{% if pdasToExport.length > 0 %}
|
|
15
|
+
export * from './pdas';
|
|
16
|
+
{% endif %}
|
|
17
|
+
{% if programsToExport.length > 0 %}
|
|
18
|
+
export * from './programs';
|
|
19
|
+
{% endif %}
|
|
20
|
+
{% if definedTypesToExport.length > 0 %}
|
|
21
|
+
export * from './types';
|
|
22
|
+
{% endif %}
|
|
23
|
+
{% else %}
|
|
24
|
+
export default {};
|
|
25
|
+
{% endif %}
|
|
26
|
+
{% endblock %}
|