Skip to content

Commit 6518436

Browse files
authored
Merge pull request #540 from algorandfoundation/feat/updated_arc56
feat: updated arc56
2 parents c9b2f65 + 13ed4f6 commit 6518436

File tree

195 files changed

+204110
-203085
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

195 files changed

+204110
-203085
lines changed

examples/amm/tealscript_artifacts/ConstantProductAMM.arc56_draft.json

Lines changed: 4780 additions & 4777 deletions
Large diffs are not rendered by default.

examples/arc58/artifacts/AbstractedAccount.arc56_draft.json

Lines changed: 4795 additions & 4774 deletions
Large diffs are not rendered by default.

examples/arc72/artifacts/ARC72.arc56_draft.json

Lines changed: 2597 additions & 2579 deletions
Large diffs are not rendered by default.

examples/arc75/artifacts/ARC75.arc56_draft.json

Lines changed: 3243 additions & 3231 deletions
Large diffs are not rendered by default.

examples/auction/tealscript_artifacts/Auction.arc56_draft.json

Lines changed: 2129 additions & 2126 deletions
Large diffs are not rendered by default.

examples/big_box/artifacts/BigBox.arc56_draft.json

Lines changed: 1817 additions & 1802 deletions
Large diffs are not rendered by default.

examples/calculator/artifacts/Calculator.arc56_draft.json

Lines changed: 649 additions & 646 deletions
Large diffs are not rendered by default.

examples/itxns/artifacts/FactoryCaller.arc56_draft.json

Lines changed: 1072 additions & 1069 deletions
Large diffs are not rendered by default.

examples/itxns/artifacts/NFTFactory.arc56_draft.json

Lines changed: 608 additions & 605 deletions
Large diffs are not rendered by default.

examples/lsig_with_app/artifacts/CreatorVerifier.arc56_draft.json

Lines changed: 715 additions & 712 deletions
Large diffs are not rendered by default.

examples/merkle/artifacts/MerkleTree.arc56_draft.json

Lines changed: 2066 additions & 2063 deletions
Large diffs are not rendered by default.

examples/non_abi/artifacts/NonABIExample.arc56_draft.json

Lines changed: 555 additions & 552 deletions
Large diffs are not rendered by default.

examples/reti/artifacts/StakingPool.arc56_draft.json

Lines changed: 18971 additions & 18938 deletions
Large diffs are not rendered by default.

examples/reti/artifacts/ValidatorRegistry.arc56_draft.json

Lines changed: 27894 additions & 27663 deletions
Large diffs are not rendered by default.

examples/simple/artifacts/Simple.arc56_draft.json

Lines changed: 1058 additions & 1055 deletions
Large diffs are not rendered by default.

examples/tuple_in_box/tealscript_artifacts/ContactsApp.arc56_draft.json

Lines changed: 2700 additions & 2691 deletions
Large diffs are not rendered by default.

src/lib/compiler.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import path from 'path';
1313
import langspec from '../static/langspec.json';
1414
import { VERSION } from '../version';
1515
import { optimizeTeal } from './optimize';
16-
import { type ARC56Contract, type StructFields } from '../types/arc56.d';
16+
import { type ARC56Contract, type StructField } from '../types/arc56.d';
1717

1818
const MULTI_OUTPUT_TYPES = ['split uint128', 'divmodw output', 'vrf return values', 'ecdsa pubkey'];
1919

@@ -7663,14 +7663,14 @@ declare type AssetFreezeTxn = Required<AssetFreezeParams>;
76637663

76647664
arc56Description(): ARC56Contract {
76657665
const objectToStructFields = (typeInfo: TypeInfo & { kind: 'object' }) => {
7666-
const fields: StructFields = {};
7666+
const fields: StructField[] = [];
76677667

76687668
// eslint-disable-next-line no-restricted-syntax
76697669
for (const [field, type] of Object.entries(typeInfo.properties)) {
76707670
if (type.kind === 'object') {
7671-
fields[field] = objectToStructFields(type);
7671+
fields.push({ name: field, type: objectToStructFields(type) });
76727672
} else {
7673-
fields[field] = typeInfoToABIString(type);
7673+
fields.push({ name: field, type: typeInfoToABIString(type) });
76747674
}
76757675
}
76767676

@@ -7706,7 +7706,8 @@ declare type AssetFreezeTxn = Required<AssetFreezeParams>;
77067706
structs: {},
77077707
state,
77087708
bareActions: { create: [], call: [] },
7709-
sourceInfo: this.sourceInfo,
7709+
// TODO: clear source mapping
7710+
sourceInfo: { approval: this.sourceInfo, clear: [] },
77107711
source: {
77117712
approval: Buffer.from(this.teal.approval.map((t) => t.teal).join('\n')).toString('base64'),
77127713
clear: Buffer.from(this.teal.clear.map((t) => t.teal).join('\n')).toString('base64'),

src/types/arc56.d.ts

Lines changed: 166 additions & 141 deletions
Original file line numberDiff line numberDiff line change
@@ -1,130 +1,4 @@
1-
/** An ABI-encoded type */
2-
type ABIType = string;
3-
4-
/** The name of a defined struct */
5-
type StructName = string;
6-
7-
/** Raw byteslice without the length prefixed that is specified in ARC-4 */
8-
type AVMBytes = 'bytes';
9-
10-
/** Mapping of named structs to the ABI type of their fields */
11-
interface StructFields {
12-
[fieldName: string]: ABIType | StructFields;
13-
}
14-
15-
/** Describes a single key in app storage */
16-
interface StorageKey {
17-
/** Description of what this storage key holds */
18-
desc?: string;
19-
/** The type of the key */
20-
keyType: ABIType | AVMBytes | StructName;
21-
/** The type of the value */
22-
valueType: ABIType | AVMBytes | StructName;
23-
/** The bytes of the key encoded as base64 */
24-
key: string;
25-
}
26-
27-
interface StorageMap {
28-
/** Description of what the key-value pairs in this mapping hold */
29-
desc?: string;
30-
/** The type of the keys in the map */
31-
keyType: ABIType | AVMBytes | StructName;
32-
/** The type of the values in the map */
33-
valueType: ABIType | AVMBytes | StructName;
34-
/** The prefix of the map, encoded as a utf-8 string */
35-
prefix?: string;
36-
}
37-
38-
interface SourceInfo {
39-
/** The line of pre-compiled TEAL */
40-
teal?: number;
41-
/** The program counter offset(s) that correspond to this line of TEAL */
42-
pc?: Array<number>;
43-
/** A human-readable string that describes the error when the program fails at this given line of TEAL */
44-
errorMessage?: string;
45-
}
46-
47-
interface Event {
48-
/** The name of the event */
49-
name: string;
50-
/** Optional, user-friendly description for the event */
51-
desc?: string;
52-
/** The arguments of the event, in order */
53-
args: Array<{
54-
/** The type of the argument */
55-
type: ABIType;
56-
/** Optional, user-friendly name for the argument */
57-
name?: string;
58-
/** Optional, user-friendly description for the argument */
59-
desc?: string;
60-
/** If the type is a struct, the name of the struct */
61-
struct?: StructName;
62-
}>;
63-
}
64-
65-
/** Describes a method in the contract. This interface is an extension of the interface described in ARC-4 */
66-
interface Method {
67-
/** The name of the method */
68-
name: string;
69-
/** Optional, user-friendly description for the method */
70-
desc?: string;
71-
/** The arguments of the method, in order */
72-
args: Array<{
73-
/** The type of the argument */
74-
type: ABIType;
75-
/** If the type is a struct, the name of the struct */
76-
struct?: StructName;
77-
/** Optional, user-friendly name for the argument */
78-
name?: string;
79-
/** Optional, user-friendly description for the argument */
80-
desc?: string;
81-
/** The default value that clients should use. MUST be base64 encoded bytes */
82-
defaultValue?: string;
83-
}>;
84-
/** Information about the method's return value */
85-
returns: {
86-
/** The type of the return value, or "void" to indicate no return value. */
87-
type: ABIType;
88-
/** If the type is a struct, the name of the struct */
89-
struct?: StructName;
90-
/** Optional, user-friendly description for the return value */
91-
desc?: string;
92-
};
93-
/** an action is a combination of call/create and an OnComplete */
94-
actions: {
95-
/** OnCompletes this method allows when appID === 0 */
96-
create: ('NoOp' | 'OptIn' | 'DeleteApplication')[];
97-
/** OnCompletes this method allows when appID !== 0 */
98-
call: ('NoOp' | 'OptIn' | 'CloseOut' | 'ClearState' | 'UpdateApplication' | 'DeleteApplication')[];
99-
};
100-
/** If this method does not write anything to the ledger (ARC-22) */
101-
readonly: boolean;
102-
/** ARC-28 events that MAY be emitted by this method */
103-
events?: Array<Event>;
104-
/** Information that clients can use when calling the method */
105-
recommendations?: {
106-
/** The number of inner transactions the caller should cover the fees for */
107-
innerTransactionCount?: number;
108-
/** Recommended box references to include */
109-
boxes?: {
110-
/** The app ID for the box */
111-
app?: number;
112-
/** The base64 encoded box key */
113-
key: string;
114-
/** The number of bytes being read from the box */
115-
readBytes: number;
116-
/** The number of bytes being written to the box */
117-
writeBytes: number;
118-
};
119-
/** Recommended foreign accounts */
120-
accounts?: string[];
121-
/** Recommended foreign apps */
122-
apps?: number[];
123-
/** Recommended foreign assets */
124-
assets?: number[];
125-
};
126-
}
127-
1+
/* eslint-disable no-use-before-define */
1282
/** Describes the entire contract. This interface is an extension of the interface described in ARC-4 */
1293
export interface ARC56Contract {
1304
/** The ARCs used and/or supported by this contract. All contracts implicity support ARC4 and ARC56 */
@@ -134,22 +8,20 @@ export interface ARC56Contract {
1348
/** Optional, user-friendly description for the interface */
1359
desc?: string;
13610
/**
137-
* Optional object listing the contract instances across different networks
11+
* Optional object listing the contract instances across different networks.
12+
* The key is the base64 genesis hash of the network, and the value contains
13+
* information about the deployed contract in the network indicated by the
14+
* key. A key containing the human-readable name of the network MAY be
15+
* included, but the corresponding genesis hash key MUST also be define
13816
*/
13917
networks?: {
140-
/**
141-
* The key is the base64 genesis hash of the network, and the value contains
142-
* information about the deployed contract in the network indicated by the
143-
* key. A key containing the human-readable name of the network MAY be
144-
* included, but the corresponding genesis hash key MUST also be defined
145-
*/
14618
[network: string]: {
14719
/** The app ID of the deployed contract in this network */
14820
appID: number;
14921
};
15022
};
151-
/** Named structs use by the application */
152-
structs: { [structName: StructName]: StructFields };
23+
/** Named structs use by the application. Each struct field appears in the same order as ABI encoding. */
24+
structs: { [structName: StructName]: StructField[] };
15325
/** All of the methods that the contract implements */
15426
methods: Method[];
15527
state: {
@@ -184,8 +56,13 @@ export interface ARC56Contract {
18456
/** OnCompletes this method allows when appID !== 0 */
18557
call: ('NoOp' | 'OptIn' | 'CloseOut' | 'ClearState' | 'UpdateApplication' | 'DeleteApplication')[];
18658
};
187-
/** Information about the TEAL */
188-
sourceInfo?: SourceInfo[];
59+
/** Information about the TEAL programs */
60+
sourceInfo?: {
61+
/** Approval program information */
62+
approval: SourceInfo[];
63+
/** Clear program information */
64+
clear: SourceInfo[];
65+
};
18966
/** The pre-compiled TEAL that may contain template variables. MUST be omitted if included as part of ARC23 */
19067
source?: {
19168
/** The approval program */
@@ -209,7 +86,7 @@ export interface ARC56Contract {
20986
major: number;
21087
minor: number;
21188
patch: number;
212-
commit?: string;
89+
commitHash?: string;
21390
};
21491
};
21592
/** ARC-28 events that MAY be emitted by this contract */
@@ -218,7 +95,7 @@ export interface ARC56Contract {
21895
templateVariables?: {
21996
[name: string]: {
22097
/** The type of the template variable */
221-
type: ABIType | AVMBytes | StructName;
98+
type: ABIType | AVMString | AVMBytes | StructName;
22299
/** If given, the the base64 encoded value used for the given app/program */
223100
value?: string;
224101
};
@@ -227,7 +104,155 @@ export interface ARC56Contract {
227104
scratchVariables?: {
228105
[name: string]: {
229106
slot: number;
230-
type: ABIType | AVMBytes | StructName;
107+
type: ABIType | AVMString | AVMBytes | StructName;
108+
};
109+
};
110+
}
111+
112+
/** Describes a method in the contract. This interface is an extension of the interface described in ARC-4 */
113+
export interface Method {
114+
/** The name of the method */
115+
name: string;
116+
/** Optional, user-friendly description for the method */
117+
desc?: string;
118+
/** The arguments of the method, in order */
119+
args: Array<{
120+
/** The type of the argument. The `struct` field should also be checked to determine if this arg is a struct. */
121+
type: ABIType;
122+
/** If the type is a struct, the name of the struct */
123+
struct?: StructName;
124+
/** Optional, user-friendly name for the argument */
125+
name?: string;
126+
/** Optional, user-friendly description for the argument */
127+
desc?: string;
128+
/** The default value that clients should use. */
129+
defaultValue?: {
130+
/** Base64 encoded bytes or uint64 */
131+
data: string | bigint;
132+
/** How the data is encoded. This is the encoding for the data provided here, not the arg type */
133+
type: ABIType | AVMBytes | AVMString;
134+
/** Where the default value is coming from
135+
* - box: The data key signifies the box key to read the value from
136+
* - global: The data key signifies the global state key to read the value from
137+
* - local: The data key signifies the local state key to read the value from (for the sender)
138+
* - literal: the value is a literal and should be passed directly as the argument
139+
*/
140+
source: 'box' | 'global' | 'local' | 'literal';
231141
};
142+
}>;
143+
/** Information about the method's return value */
144+
returns: {
145+
/** The type of the return value, or "void" to indicate no return value. The `struct` field should also be checked to determine if this return value is a struct. */
146+
type: ABIType;
147+
/** If the type is a struct, the name of the struct */
148+
struct?: StructName;
149+
/** Optional, user-friendly description for the return value */
150+
desc?: string;
232151
};
152+
/** an action is a combination of call/create and an OnComplete */
153+
actions: {
154+
/** OnCompletes this method allows when appID === 0 */
155+
create: ('NoOp' | 'OptIn' | 'DeleteApplication')[];
156+
/** OnCompletes this method allows when appID !== 0 */
157+
call: ('NoOp' | 'OptIn' | 'CloseOut' | 'ClearState' | 'UpdateApplication' | 'DeleteApplication')[];
158+
};
159+
/** If this method does not write anything to the ledger (ARC-22) */
160+
readonly?: boolean;
161+
/** ARC-28 events that MAY be emitted by this method */
162+
events?: Array<Event>;
163+
/** Information that clients can use when calling the method */
164+
recommendations?: {
165+
/** The number of inner transactions the caller should cover the fees for */
166+
innerTransactionCount?: number;
167+
/** Recommended box references to include */
168+
boxes?: {
169+
/** The app ID for the box */
170+
app?: number;
171+
/** The base64 encoded box key */
172+
key: string;
173+
/** The number of bytes being read from the box */
174+
readBytes: number;
175+
/** The number of bytes being written to the box */
176+
writeBytes: number;
177+
};
178+
/** Recommended foreign accounts */
179+
accounts?: string[];
180+
/** Recommended foreign apps */
181+
apps?: number[];
182+
/** Recommended foreign assets */
183+
assets?: number[];
184+
};
185+
}
186+
187+
export interface Event {
188+
/** The name of the event */
189+
name: string;
190+
/** Optional, user-friendly description for the event */
191+
desc?: string;
192+
/** The arguments of the event, in order */
193+
args: Array<{
194+
/** The type of the argument. The `struct` field should also be checked to determine if this arg is a struct. */
195+
type: ABIType;
196+
/** Optional, user-friendly name for the argument */
197+
name?: string;
198+
/** Optional, user-friendly description for the argument */
199+
desc?: string;
200+
/** If the type is a struct, the name of the struct */
201+
struct?: StructName;
202+
}>;
203+
}
204+
205+
/** An ABI-encoded type */
206+
type ABIType = string;
207+
208+
/** The name of a defined struct */
209+
type StructName = string;
210+
211+
/** Raw byteslice without the length prefixed that is specified in ARC-4 */
212+
type AVMBytes = 'AVMBytes';
213+
214+
/** A string without the length prefix that is specified in ARC-4 */
215+
type AVMString = 'AVMString';
216+
217+
/** Information about a single field in a struct */
218+
export interface StructField {
219+
/** The name of the struct field */
220+
name: string;
221+
/** The type of the struct field's value */
222+
type: ABIType | StructName | StructField[];
223+
}
224+
225+
/** Describes a single key in app storage */
226+
export interface StorageKey {
227+
/** Description of what this storage key holds */
228+
desc?: string;
229+
/** The type of the key */
230+
keyType: ABIType | AVMString | AVMBytes | StructName;
231+
/** The type of the value */
232+
valueType: ABIType | AVMString | AVMBytes | StructName;
233+
/** The bytes of the key encoded as base64 */
234+
key: string;
235+
}
236+
237+
/** Describes a mapping of key-value pairs in storage */
238+
export interface StorageMap {
239+
/** Description of what the key-value pairs in this mapping hold */
240+
desc?: string;
241+
/** The type of the keys in the map */
242+
keyType: ABIType | AVMString | AVMBytes | StructName;
243+
/** The type of the values in the map */
244+
valueType: ABIType | AVMString | AVMBytes | StructName;
245+
/** The base64-encoded prefix of the map keys */
246+
prefix?: string;
247+
}
248+
249+
export interface SourceInfo {
250+
/** The line of pre-compiled TEAL */
251+
teal?: number;
252+
/** The program counter offset(s) that correspond to this line of TEAL */
253+
pc?: Array<number>;
254+
/** A human-readable string that describes the error when the program fails at this given line of TEAL */
255+
errorMessage?: string;
256+
/** The line of the dissasembled TEAL this line of pre-compiled TEAL corresponds to */
257+
disassembledTeal?: number;
233258
}

0 commit comments

Comments
 (0)