Skip to content

Commit 2944829

Browse files
CoveMBericglauCopilot
authored
Plat 6357 add cairo ai assistant (#514)
Co-authored-by: Eric Lau <[email protected]> Co-authored-by: Copilot <[email protected]>
1 parent 7ef1cc4 commit 2944829

23 files changed

+816
-23
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import type { AiFunctionPropertyDefinition } from '../types/function-definition.ts';
2+
import type { CairoAlphaCommonContractOptions, CairoAlphaRoyaltyInfoOptions } from '../types/languages.ts';
3+
4+
const commonContractFunctionDescription = {
5+
upgradeable: {
6+
type: 'boolean',
7+
description: 'Whether the smart contract is upgradeable.',
8+
},
9+
10+
info: {
11+
type: 'object',
12+
description: 'Metadata about the contract and author',
13+
properties: {
14+
license: {
15+
type: 'string',
16+
description: 'The license used by the contract, default is "MIT"',
17+
},
18+
},
19+
},
20+
21+
access: {
22+
anyOf: [
23+
{ type: 'boolean', enum: [false] },
24+
{ type: 'string', enum: ['ownable', 'roles'] },
25+
],
26+
description:
27+
'The type of access control to provision. Ownable is a simple mechanism with a single account authorized for all privileged actions. Roles is a flexible mechanism with a separate role for each privileged action. A role can have many authorized accounts.',
28+
},
29+
} as const satisfies AiFunctionPropertyDefinition<CairoAlphaCommonContractOptions>['properties'];
30+
31+
export const cairoAlphaSharedFunctionDefinition = {
32+
...commonContractFunctionDescription,
33+
34+
appName: {
35+
type: 'string',
36+
description:
37+
'Required when votes is enabled, for hashing and signing typed structured data. Name for domain separator implementing SNIP12Metadata trait. Prevents two applications from producing the same hash.',
38+
},
39+
40+
appVersion: {
41+
type: 'string',
42+
description:
43+
'Required when votes is enabled, for hashing and signing typed structured data. Version for domain separator implementing SNIP12Metadata trait. Prevents two versions of the same application from producing the same hash.',
44+
},
45+
46+
royaltyInfo: {
47+
type: 'object',
48+
description:
49+
'Provides information for how much royalty is owed and to whom, based on a sale price. Follows ERC-2981 standard.',
50+
properties: {
51+
enabled: {
52+
type: 'boolean',
53+
description: 'Whether to enable royalty feature for the contract',
54+
},
55+
defaultRoyaltyFraction: {
56+
type: 'string',
57+
description:
58+
"The royalty fraction that will be default for all tokens. It will be used for a token if there's no custom royalty fraction set for it.",
59+
},
60+
feeDenominator: {
61+
type: 'string',
62+
description: "The denominator used to interpret a token's fee and to calculate the result fee fraction.",
63+
},
64+
},
65+
},
66+
} as const satisfies AiFunctionPropertyDefinition<
67+
{ royaltyInfo: CairoAlphaRoyaltyInfoOptions } & { appName: string; appVersion: string }
68+
>['properties'];
Lines changed: 279 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,279 @@
1+
import type { AiFunctionDefinition } from '../types/function-definition.ts';
2+
import { cairoAlphaSharedFunctionDefinition } from './cairo-alpha-shared.ts';
3+
import { addFunctionPropertiesFrom } from './shared.ts';
4+
5+
export const cairoAlphaERC20AIFunctionDefinition = {
6+
name: 'ERC20',
7+
description: 'Make a fungible token per the ERC-20 standard.',
8+
parameters: {
9+
type: 'object',
10+
properties: {
11+
...addFunctionPropertiesFrom(cairoAlphaSharedFunctionDefinition, [
12+
'name',
13+
'symbol',
14+
'burnable',
15+
'pausable',
16+
'mintable',
17+
'access',
18+
'upgradeable',
19+
'info',
20+
'appName',
21+
'appVersion',
22+
]),
23+
premint: {
24+
type: 'string',
25+
description: 'The number of tokens to premint for the deployer.',
26+
},
27+
votes: {
28+
type: 'boolean',
29+
description:
30+
"Whether to keep track of historical balances for voting in on-chain governance, with a way to delegate one's voting power to a trusted account.",
31+
},
32+
},
33+
required: ['name', 'symbol'],
34+
additionalProperties: false,
35+
},
36+
} as const satisfies AiFunctionDefinition<'cairoAlpha', 'ERC20'>;
37+
38+
export const cairoAlphaERC721AIFunctionDefinition = {
39+
name: 'ERC721',
40+
description: 'Make a non-fungible token per the ERC-721 standard.',
41+
parameters: {
42+
type: 'object',
43+
properties: {
44+
...addFunctionPropertiesFrom(cairoAlphaSharedFunctionDefinition, [
45+
'name',
46+
'symbol',
47+
'access',
48+
'burnable',
49+
'pausable',
50+
'mintable',
51+
'upgradeable',
52+
'info',
53+
'royaltyInfo',
54+
'appName',
55+
'appVersion',
56+
]),
57+
baseUri: { type: 'string', description: 'A base uri for the non-fungible token.' },
58+
enumerable: {
59+
type: 'boolean',
60+
description:
61+
'Whether to allow on-chain enumeration of all tokens or those owned by an account. Increases gas cost of transfers.',
62+
},
63+
votes: {
64+
type: 'boolean',
65+
description:
66+
'Whether to keep track of individual units for voting in on-chain governance. Voting durations can be expressed as block numbers or timestamps.',
67+
},
68+
},
69+
required: ['name', 'symbol'],
70+
additionalProperties: false,
71+
},
72+
} as const satisfies AiFunctionDefinition<'cairoAlpha', 'ERC721'>;
73+
74+
export const cairoAlphaERC1155AIFunctionDefinition = {
75+
name: 'ERC1155',
76+
description: 'Make a non-fungible token per the ERC-1155 standard.',
77+
parameters: {
78+
type: 'object',
79+
properties: {
80+
...addFunctionPropertiesFrom(cairoAlphaSharedFunctionDefinition, [
81+
'name',
82+
'burnable',
83+
'pausable',
84+
'mintable',
85+
'access',
86+
'upgradeable',
87+
'info',
88+
'royaltyInfo',
89+
]),
90+
baseUri: {
91+
type: 'string',
92+
description:
93+
'The Location of the metadata for the token. Clients will replace any instance of {id} in this string with the tokenId.',
94+
},
95+
updatableUri: {
96+
type: 'boolean',
97+
description: 'Whether privileged accounts will be able to set a new URI for all token types.',
98+
},
99+
},
100+
required: ['name', 'baseUri'],
101+
additionalProperties: false,
102+
},
103+
} as const satisfies AiFunctionDefinition<'cairoAlpha', 'ERC1155'>;
104+
105+
export const cairoAlphaGovernorAIFunctionDefinition = {
106+
name: 'Governor',
107+
description: 'Make a contract to implement governance, such as for a DAO.',
108+
parameters: {
109+
type: 'object',
110+
properties: {
111+
...addFunctionPropertiesFrom(cairoAlphaSharedFunctionDefinition, [
112+
'name',
113+
'upgradeable',
114+
'info',
115+
'appName',
116+
'appVersion',
117+
]),
118+
delay: {
119+
type: 'string',
120+
description:
121+
'The delay since proposal is created until voting starts, in readable date time format matching /^(\\d+(?:\\.\\d+)?) +(second|minute|hour|day|week|month|year)s?$/, default is "1 day".',
122+
},
123+
period: {
124+
type: 'string',
125+
description:
126+
'The length of period during which people can cast their vote, in readable date time format matching /^(\\d+(?:\\.\\d+)?) +(second|minute|hour|day|week|month|year)s?$/, default is "1 week".',
127+
},
128+
proposalThreshold: {
129+
type: 'string',
130+
description: 'Minimum number of votes an account must have to create a proposal, default is 0.',
131+
},
132+
decimals: {
133+
type: 'number',
134+
description:
135+
'The number of decimals to use for the contract, unless otherwise specified default is 18 for ERC20Votes and 0 for ERC721Votes (because it does not apply to ERC721Votes).',
136+
},
137+
quorumMode: {
138+
type: 'string',
139+
enum: ['percent', 'absolute'],
140+
description: 'The type of quorum mode to use, either by percentage or absolute value.',
141+
},
142+
quorumPercent: {
143+
type: 'number',
144+
description: 'The percent required, in cases of quorumMode equals percent.',
145+
},
146+
quorumAbsolute: {
147+
type: 'string',
148+
description: 'The absolute quorum required, in cases of quorumMode equals absolute.',
149+
},
150+
votes: {
151+
type: 'string',
152+
enum: ['erc20votes', 'erc721votes'],
153+
description:
154+
'The type of voting to use. Either erc20votes, meaning voting power with a votes-enabled ERC20 token. Either erc721votes, meaning voting power with a votes-enabled ERC721 token. Voters can entrust their voting power to a delegate.',
155+
},
156+
clockMode: {
157+
type: 'string',
158+
enum: ['timestamp'],
159+
description:
160+
'The clock mode used by the voting token. For now, only timestamp mode where the token uses voting durations expressed as timestamps is supported. For Governor, this must be chosen to match what the ERC20 or ERC721 voting token uses.',
161+
},
162+
timelock: {
163+
anyOf: [
164+
{ type: 'boolean', enum: [false] },
165+
{ type: 'string', enum: ['openzeppelin'] },
166+
],
167+
description:
168+
'Whether to add a delay to actions taken by the Governor. Gives users time to exit the system if they disagree with governance decisions. If "openzeppelin", Module compatible with OpenZeppelin\'s TimelockController.',
169+
},
170+
settings: {
171+
type: 'boolean',
172+
description: 'Whether to allow governance to update voting settings (delay, period, proposal threshold).',
173+
},
174+
},
175+
required: ['name', 'delay', 'period'],
176+
additionalProperties: false,
177+
},
178+
} as const satisfies AiFunctionDefinition<'cairoAlpha', 'Governor'>;
179+
180+
export const cairoAlphaVestingAIFunctionDefinition = {
181+
name: 'Vesting',
182+
description:
183+
'Make a vesting smart contract that manages the gradual release of ERC-20 tokens to a designated beneficiary based on a predefined vesting schedule',
184+
parameters: {
185+
type: 'object',
186+
properties: {
187+
...addFunctionPropertiesFrom(cairoAlphaSharedFunctionDefinition, ['name', 'info']),
188+
startDate: {
189+
type: 'string',
190+
description: 'The timestamp marking the beginning of the vesting period. In HTML input datetime-local format',
191+
},
192+
duration: {
193+
type: 'string',
194+
description:
195+
'The total duration of the vesting period. In readable date time format matching /^(\\d+(?:\\.\\d+)?) +(second|minute|hour|day|week|month|year)s?$/',
196+
},
197+
cliffDuration: {
198+
type: 'string',
199+
description:
200+
'The duration of the cliff period. Must be less than or equal to the total duration. In readable date time format matching /^(\\d+(?:\\.\\d+)?) +(second|minute|hour|day|week|month|year)s?$/',
201+
},
202+
schedule: {
203+
type: 'string',
204+
enum: ['linear', 'custom'],
205+
description:
206+
'A vesting schedule implementation, tokens can either be vested gradually following a linear curve or with custom vesting schedule that requires the implementation of the VestingSchedule trait.',
207+
},
208+
},
209+
required: ['name', 'schedule', 'cliffDuration', 'duration', 'startDate'],
210+
additionalProperties: false,
211+
},
212+
} as const satisfies AiFunctionDefinition<'cairoAlpha', 'Vesting'>;
213+
214+
export const cairoAlphaAccountAIFunctionDefinition = {
215+
name: 'Account',
216+
description:
217+
'Make a custom smart contract that represents an account that can be deployed and interacted with other contracts, and can be extended to implement custom logic. An account is a special type of contract that is used to validate and execute transactions',
218+
parameters: {
219+
type: 'object',
220+
properties: {
221+
...addFunctionPropertiesFrom(cairoAlphaSharedFunctionDefinition, ['name', 'upgradeable', 'info']),
222+
type: {
223+
type: 'string',
224+
enum: ['stark', 'eth'],
225+
description:
226+
'Type of signature used for signature checking by the Account contract, Starknet account uses the STARK curve, Ethereum-flavored account uses the Secp256k1 curve.',
227+
},
228+
declare: {
229+
type: 'boolean',
230+
description: 'Whether to enable the account to declare other contract classes.',
231+
},
232+
deploy: { type: 'boolean', description: 'Whether to enables the account to be counterfactually deployed.' },
233+
pubkey: { type: 'boolean', description: 'Whether to enables the account to change its own public key.' },
234+
outsideExecution: {
235+
type: 'boolean',
236+
description:
237+
'Whether to allow a protocol to submit transactions on behalf of the account, as long as it has the relevant signatures.',
238+
},
239+
},
240+
required: ['name', 'type'],
241+
additionalProperties: false,
242+
},
243+
} as const satisfies AiFunctionDefinition<'cairoAlpha', 'Account'>;
244+
245+
export const cairoAlphaMultisigAIFunctionDefinition = {
246+
name: 'Multisig',
247+
description: 'Make a custom smart contract',
248+
parameters: {
249+
type: 'object',
250+
properties: {
251+
...addFunctionPropertiesFrom(cairoAlphaSharedFunctionDefinition, ['name', 'upgradeable', 'info']),
252+
quorum: {
253+
type: 'string',
254+
description: 'The minimal number of confirmations required by the Multisig to approve a transaction.',
255+
},
256+
},
257+
required: ['name', 'quorum'],
258+
additionalProperties: false,
259+
},
260+
} as const satisfies AiFunctionDefinition<'cairoAlpha', 'Multisig'>;
261+
262+
export const cairoAlphaCustomAIFunctionDefinition = {
263+
name: 'Custom',
264+
description: 'Make a custom smart contract',
265+
parameters: {
266+
type: 'object',
267+
properties: {
268+
...addFunctionPropertiesFrom(cairoAlphaSharedFunctionDefinition, [
269+
'name',
270+
'pausable',
271+
'access',
272+
'upgradeable',
273+
'info',
274+
]),
275+
},
276+
required: ['name'],
277+
additionalProperties: false,
278+
},
279+
} as const satisfies AiFunctionDefinition<'cairoAlpha', 'Custom'>;

0 commit comments

Comments
 (0)