1- import type { Contract } from './contract' ;
1+ import type { BaseImplementedTrait , Contract } from './contract' ;
22import { ContractBuilder } from './contract' ;
33import type { Access } from './set-access-control' ;
44import { requireAccessControl , setAccessControl } from './set-access-control' ;
@@ -19,6 +19,7 @@ import { addVotesComponent } from './common-components';
1919export const defaults : Required < ERC20Options > = {
2020 name : 'MyToken' ,
2121 symbol : 'MTK' ,
22+ decimals : '18' ,
2223 burnable : false ,
2324 pausable : false ,
2425 premint : '0' ,
@@ -38,6 +39,7 @@ export function printERC20(opts: ERC20Options = defaults): string {
3839export interface ERC20Options extends CommonContractOptions {
3940 name : string ;
4041 symbol : string ;
42+ decimals : string ;
4143 burnable ?: boolean ;
4244 pausable ?: boolean ;
4345 premint ?: string ;
@@ -70,7 +72,9 @@ export function buildERC20(opts: ERC20Options): Contract {
7072
7173 const allOpts = withDefaults ( opts ) ;
7274
73- addBase ( c , toByteArray ( allOpts . name ) , toByteArray ( allOpts . symbol ) ) ;
75+ const decimals = toUint ( opts . decimals , 'decimals' , 'u8' ) ;
76+ addBase ( c , toByteArray ( allOpts . name ) , toByteArray ( allOpts . symbol ) , decimals ) ;
77+
7478 addERC20Mixin ( c ) ;
7579
7680 if ( allOpts . premint ) {
@@ -183,9 +187,22 @@ function addERC20Mixin(c: ContractBuilder) {
183187 } ) ;
184188}
185189
186- function addBase ( c : ContractBuilder , name : string , symbol : string ) {
187- c . addUseClause ( 'openzeppelin::token::erc20' , 'DefaultConfig' ) ;
190+ function addBase ( c : ContractBuilder , name : string , symbol : string , decimals : bigint ) {
191+ // Add ERC20 component
188192 c . addComponent ( components . ERC20Component , [ name , symbol ] , true ) ;
193+
194+ // Add immutable config with decimals
195+ const trait : BaseImplementedTrait = {
196+ name : 'ERC20ImmutableConfig' ,
197+ of : 'ERC20Component::ImmutableConfig' ,
198+ tags : [ ] ,
199+ } ;
200+ c . addImplementedTrait ( trait ) ;
201+ c . addSuperVariableToTrait ( trait , {
202+ name : 'DECIMALS' ,
203+ type : 'u8' ,
204+ value : decimals . toString ( ) ,
205+ } ) ;
189206}
190207
191208function addBurnable ( c : ContractBuilder ) {
0 commit comments