Skip to content

Commit

Permalink
Add SRC5 to 721
Browse files Browse the repository at this point in the history
  • Loading branch information
ericglau committed Nov 29, 2023
1 parent 432a7fc commit 095ef34
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 27 deletions.
26 changes: 26 additions & 0 deletions packages/core-cairo/src/common-components.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import type { ContractBuilder } from "./contract";
import { defineComponents } from "./utils/define-components";

const components = defineComponents( {
SRC5Component: {
path: 'openzeppelin::introspection::src5',
substorage: {
name: 'src5',
type: 'SRC5Component::Storage',
},
event: {
name: 'SRC5Event',
type: 'SRC5Component::Event',
},
impls: [
{
name: 'SRC5Impl',
value: 'SRC5Component::SRC5Impl<ContractState>',
},
],
},
})

export function addSRC5Component(c: ContractBuilder) {
c.addComponent(components.SRC5Component, [], false);
}
2 changes: 2 additions & 0 deletions packages/core-cairo/src/erc721.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { setInfo } from './set-info';
import { defineComponents } from './utils/define-components';
import { defaults as commonDefaults } from './common-options';
import { printContract } from './print';
import { addSRC5Component } from './common-components';

export const defaults: Required<ERC721Options> = {
name: 'MyToken',
Expand Down Expand Up @@ -83,6 +84,7 @@ function addBase(c: ContractBuilder, name: string, symbol: string) {
],
true,
);
addSRC5Component(c);
}

function addBurnable(c: ContractBuilder) {
Expand Down
30 changes: 3 additions & 27 deletions packages/core-cairo/src/set-access-control.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { defineFunctions } from './utils/define-functions';
import { defineComponents } from './utils/define-components';
import { keccak256 } from 'ethereum-cryptography/keccak';
import { utf8ToBytes, bytesToHex } from 'ethereum-cryptography/utils';
import { addSRC5Component } from './common-components';

export const accessOptions = [false, 'ownable', 'roles'] as const;

Expand All @@ -29,7 +30,7 @@ export type Access = typeof accessOptions[number];
if (c.addComponent(components.AccessControlComponent, [], true)) {
// importDefaultAdminRole(c);

c.addComponent(components.SRC5Component, [], false);
addSRC5Component(c);

c.addStandaloneImport('starknet::ContractAddress');
c.addConstructorArgument({ name: 'admin', type: 'ContractAddress'});
Expand Down Expand Up @@ -139,32 +140,7 @@ const components = defineComponents( {
value: 'AccessControlComponent::InternalImpl<ContractState>',
},
},
SRC5Component: {
path: 'openzeppelin::introspection::src5',
substorage: {
name: 'src5',
type: 'SRC5Component::Storage',
},
event: {
name: 'SRC5Event',
type: 'SRC5Component::Event',
},
impls: [
{
name: 'SRC5Impl',
value: 'SRC5Component::SRC5Impl<ContractState>',
},
],
// internalImpl: {
// name: 'SRC5InternalImpl',
// value: 'SRC5Component::InternalImpl<ContractState>',
// },
},
// AccessControl: {
// path: 'openzeppelin.access.accesscontrol.library',
// useNamespace: true
// },
})
});

// const functions = defineFunctions({
// // --- library-only calls ---
Expand Down

0 comments on commit 095ef34

Please sign in to comment.