diff --git a/packages/core-cairo/src/api.ts b/packages/core-cairo/src/api.ts index 42b5982be..af48ca78e 100644 --- a/packages/core-cairo/src/api.ts +++ b/packages/core-cairo/src/api.ts @@ -3,7 +3,6 @@ import { printERC20, defaults as erc20defaults, isAccessControlRequired as erc20 // import { printERC721, defaults as erc721defaults, isAccessControlRequired as erc721IsAccessControlRequired, ERC721Options } from './erc721'; // import { printERC1155, defaults as erc1155defaults, isAccessControlRequired as erc1155IsAccessControlRequired, ERC1155Options } from './erc1155'; // import { printCustom, defaults as customDefaults, isAccessControlRequired as customIsAccessControlRequired, CustomOptions } from './custom'; -import { toUint256 } from './utils/uint256'; export interface WizardContractAPI { /** @@ -54,6 +53,3 @@ export const erc20: ERC20 = { // defaults: customDefaults, // isAccessControlRequired: customIsAccessControlRequired // } -export const utils = { - toUint256 -} \ No newline at end of file diff --git a/packages/core-cairo/src/build-generic.ts b/packages/core-cairo/src/build-generic.ts index 5703eb048..a3a800fb4 100644 --- a/packages/core-cairo/src/build-generic.ts +++ b/packages/core-cairo/src/build-generic.ts @@ -26,8 +26,8 @@ export function buildGeneric(opts: GenericOptions) { // case 'Custom': // return buildCustom(opts); - default: - const _: never = opts; - throw new Error('Unknown ERC'); + // default: + // const _: never = opts; + // throw new Error('Unknown ERC'); } } diff --git a/packages/core-cairo/src/contract.test.ts b/packages/core-cairo/src/contract.test.ts index 2633bcf8a..06ba26887 100644 --- a/packages/core-cairo/src/contract.test.ts +++ b/packages/core-cairo/src/contract.test.ts @@ -1,75 +1,75 @@ import test from 'ava'; -import { BaseFunction, ContractBuilder } from './contract'; +import { ContractFunction, ContractBuilder } from './contract'; import { printContract } from './print'; test('contract basics', t => { - const Foo = new ContractBuilder(); + const Foo = new ContractBuilder("foo"); t.snapshot(printContract(Foo)); }); test('contract with constructor code', t => { - const Foo = new ContractBuilder(); + const Foo = new ContractBuilder("foo"); Foo.addConstructorCode('someFunction()'); t.snapshot(printContract(Foo)); }); test('contract with constructor code with semicolon', t => { - const Foo = new ContractBuilder(); + const Foo = new ContractBuilder("foo"); Foo.addConstructorCode('someFunction();'); t.snapshot(printContract(Foo)); }); -test('contract with function code', t => { - const Foo = new ContractBuilder(); - Foo.addFunctionCode('someFunction()', _otherFunction); - t.snapshot(printContract(Foo)); -}); +// test('contract with function code', t => { +// const Foo = new ContractBuilder("foo"); +// Foo.addFunctionCode('someFunction()', _otherFunction); +// t.snapshot(printContract(Foo)); +// }); -test('contract with function code with semicolon', t => { - const Foo = new ContractBuilder(); - Foo.addFunctionCode('someFunction();', _otherFunction); - t.snapshot(printContract(Foo)); -}); +// test('contract with function code with semicolon', t => { +// const Foo = new ContractBuilder(); +// Foo.addFunctionCode('someFunction();', _otherFunction); +// t.snapshot(printContract(Foo)); +// }); -test('contract with initializer params', t => { - const Foo = new ContractBuilder(); - Foo.addComponent( - someModule, - ['param1'], - [], - true - ); - t.snapshot(printContract(Foo)); -}); +// test('contract with initializer params', t => { +// const Foo = new ContractBuilder(); +// Foo.addComponent( +// someModule, +// ['param1'], +// [], +// true +// ); +// t.snapshot(printContract(Foo)); +// }); -test('contract with library call', t => { - const Foo = new ContractBuilder(); - Foo.addComponent( - someModule, - [], - [], - false - ); - Foo.addFunction(_libraryFunction); - t.snapshot(printContract(Foo)); -}); +// test('contract with library call', t => { +// const Foo = new ContractBuilder(); +// Foo.addComponent( +// someModule, +// [], +// [], +// false +// ); +// Foo.addFunction(_libraryFunction); +// t.snapshot(printContract(Foo)); +// }); -const someModule = { - name: 'SomeLibrary', - path: 'contracts/some/library', - useNamespace: true -}; +// const someModule = { +// name: 'SomeLibrary', +// path: 'contracts/some/library', +// useNamespace: true +// }; -const _otherFunction: BaseFunction = { - name: 'otherFunction', - kind: 'external', - args: [], -}; +// const _otherFunction: BaseFunction = { +// name: 'otherFunction', +// kind: 'external', +// args: [], +// }; -const _libraryFunction: BaseFunction = { - module: someModule, - name: 'libraryFunction', - kind: 'external', - args: [], -}; \ No newline at end of file +// const _libraryFunction: BaseFunction = { +// module: someModule, +// name: 'libraryFunction', +// kind: 'external', +// args: [], +// }; \ No newline at end of file diff --git a/packages/core-cairo/src/erc20.ts b/packages/core-cairo/src/erc20.ts index f8c9da489..859b653c6 100644 --- a/packages/core-cairo/src/erc20.ts +++ b/packages/core-cairo/src/erc20.ts @@ -9,7 +9,6 @@ import { OptionsError } from './error'; import { defineComponents } from './utils/define-components'; import { defaults as commonDefaults } from './common-options'; import { printContract } from './print'; -import { importUint256, NumberTooLarge, toUint256 } from './utils/uint256'; // import { importGetCallerAddress } from './common-functions'; export const defaults: Required = { diff --git a/packages/core-cairo/src/generate/custom.ts b/packages/core-cairo/src/generate/custom.ts.txt similarity index 100% rename from packages/core-cairo/src/generate/custom.ts rename to packages/core-cairo/src/generate/custom.ts.txt diff --git a/packages/core-cairo/src/generate/erc20.ts b/packages/core-cairo/src/generate/erc20.ts index 50a803058..5621199e7 100644 --- a/packages/core-cairo/src/generate/erc20.ts +++ b/packages/core-cairo/src/generate/erc20.ts @@ -10,17 +10,13 @@ const blueprint = { name: ['MyToken'], symbol: ['MTK'], burnable: booleans, - snapshots: booleans, pausable: booleans, mintable: booleans, - permit: booleans, - votes: booleans, - flashmint: booleans, + safeAllowance: booleans, premint: ['1'], access: accessOptions, upgradeable: upgradeableOptions, - info: infoOptions, - decimals: ['18'] + info: infoOptions }; export function* generateERC20Options(): Generator> { diff --git a/packages/core-cairo/src/generate/erc721.ts b/packages/core-cairo/src/generate/erc721.ts.txt similarity index 100% rename from packages/core-cairo/src/generate/erc721.ts rename to packages/core-cairo/src/generate/erc721.ts.txt diff --git a/packages/core-cairo/src/generate/sources.ts b/packages/core-cairo/src/generate/sources.ts index 7fe89e5f8..b9295e463 100644 --- a/packages/core-cairo/src/generate/sources.ts +++ b/packages/core-cairo/src/generate/sources.ts @@ -3,8 +3,8 @@ import path from 'path'; import crypto from 'crypto'; import { generateERC20Options } from './erc20'; -import { generateERC721Options } from './erc721'; -import { generateCustomOptions } from './custom'; +// import { generateERC721Options } from './erc721'; +// import { generateCustomOptions } from './custom'; import { buildGeneric, GenericOptions } from '../build-generic'; import { printContract } from '../print'; import { OptionsError } from '../error'; @@ -18,13 +18,13 @@ export function* generateOptions(): Generator { yield { kind: 'ERC20', ...kindOpts }; } - for (const kindOpts of generateERC721Options()) { - yield { kind: 'ERC721', ...kindOpts }; - } + // for (const kindOpts of generateERC721Options()) { + // yield { kind: 'ERC721', ...kindOpts }; + // } - for (const kindOpts of generateCustomOptions()) { - yield { kind: 'Custom', ...kindOpts }; - } + // for (const kindOpts of generateCustomOptions()) { + // yield { kind: 'Custom', ...kindOpts }; + // } } interface GeneratedContract { @@ -62,7 +62,7 @@ function generateContractSubset(subset: Subset): GeneratedContract[] { if (subset === 'all') { return contracts; } else { - const getParents = (c: GeneratedContract) => c.contract.components.map(p => p.module.path); + const getParents = (c: GeneratedContract) => c.contract.components.map(p => p.path); return [ ...findCover(contracts.filter(c => c.options.upgradeable), getParents), ...findCover(contracts.filter(c => !c.options.upgradeable), getParents), diff --git a/packages/core-cairo/src/index.ts b/packages/core-cairo/src/index.ts index 89433e666..eff505e0a 100644 --- a/packages/core-cairo/src/index.ts +++ b/packages/core-cairo/src/index.ts @@ -22,4 +22,4 @@ export { sanitizeKind } from './kind'; export { contractsVersion, contractsVersionTag } from './utils/version'; -export { erc20, utils } from './api'; +export { erc20 } from './api'; diff --git a/packages/core-cairo/src/print.ts b/packages/core-cairo/src/print.ts index b75e31b17..6df64a29e 100644 --- a/packages/core-cairo/src/print.ts +++ b/packages/core-cairo/src/print.ts @@ -10,8 +10,6 @@ import { getSelfArg } from './common-options'; export function printContract(contract: Contract): string { - console.log('printing contract', contract); - const fns = contract.functions.map(fn => printFunction(fn)); // const hasViews = fns.views.some(l => l.length > 0); diff --git a/packages/core-cairo/src/test.ts b/packages/core-cairo/src/test.ts index 0fef5a08d..bbe1a06d2 100644 --- a/packages/core-cairo/src/test.ts +++ b/packages/core-cairo/src/test.ts @@ -2,16 +2,16 @@ import test from 'ava'; import { generateSources } from './generate/sources'; import type { GenericOptions } from './build-generic'; -import { custom, erc20, erc721 } from './api'; +import { /*custom,*/ erc20, /*erc721*/ } from './api'; function isAccessControlRequired(opts: GenericOptions) { switch(opts.kind) { case 'ERC20': return erc20.isAccessControlRequired(opts); - case 'ERC721': - return erc721.isAccessControlRequired(opts); - case 'Custom': - return custom.isAccessControlRequired(opts); + // case 'ERC721': + // return erc721.isAccessControlRequired(opts); + // case 'Custom': + // return custom.isAccessControlRequired(opts); default: throw new Error("No such kind"); } diff --git a/packages/core-cairo/src/utils/uint256.test.ts b/packages/core-cairo/src/utils/uint256.test.ts deleted file mode 100644 index 6bfcf6501..000000000 --- a/packages/core-cairo/src/utils/uint256.test.ts +++ /dev/null @@ -1,32 +0,0 @@ -import test from 'ava'; -import BN from 'bn.js'; - -import { NumberTooLarge, toUint256 } from './uint256'; - -test('basic', t => { - t.deepEqual(toUint256('1000'), { lowBits: new BN(1000), highBits: new BN(0) }); - t.deepEqual(toUint256('0'), { lowBits: new BN(0), highBits: new BN(0) }); - t.deepEqual(toUint256(''), { lowBits: new BN(0), highBits: new BN(0) }); -}); - -test('max values', t => { - const twoE128minus1 = toUint256('340282366920938463463374607431768211455'); // 2^128-1 - t.is(twoE128minus1.highBits.toString(), '0'); - t.is(twoE128minus1.lowBits.toString(), '340282366920938463463374607431768211455'); - - const twoE128 = toUint256('340282366920938463463374607431768211456'); // 2^128 - t.is(twoE128.highBits.toString(), '1'); - t.is(twoE128.lowBits.toString(), '0'); - - const twoE128plus1 = toUint256('340282366920938463463374607431768211457'); // 2^128+1 - t.is(twoE128plus1.highBits.toString(), '1'); - t.is(twoE128plus1.lowBits.toString(), '1'); - - const maxValue = toUint256('115792089237316195423570985008687907853269984665640564039457584007913129639935'); // 2^256-1 - t.is(maxValue.highBits.toString(), '340282366920938463463374607431768211455'); // 2^128-1 - t.is(maxValue.lowBits.toString(), '340282366920938463463374607431768211455'); // 2^128-1 - - const error = t.throws(() => toUint256('115792089237316195423570985008687907853269984665640564039457584007913129639936')); // 2^256 - t.assert(error instanceof NumberTooLarge); -}); - diff --git a/packages/core-cairo/src/utils/uint256.ts b/packages/core-cairo/src/utils/uint256.ts deleted file mode 100644 index 701cfe6e9..000000000 --- a/packages/core-cairo/src/utils/uint256.ts +++ /dev/null @@ -1,36 +0,0 @@ -import BN from "bn.js"; -import type { ContractBuilder } from "../contract"; -import { defineComponents } from "./define-components"; - -/** - * Returns Uint256 components for low and high bits based on a given number in string format. - * @param num Number in string format - * @returns Object with lowBits and highBits - * @throws {NumberTooLarge} if the provided number is larger than 256 bits - */ -export function toUint256(num: string) { - const bignum = new BN(num, 10); - if (bignum.bitLength() > 256) { // 256 bits - throw new NumberTooLarge(); - } else { - const highBits = bignum.shrn(128); - const lowBits = bignum.maskn(128); - return { - lowBits, highBits - } - } -} - -export class NumberTooLarge extends Error {} - -const modules = defineComponents( { - uint256: { - path: 'starkware.cairo.common.uint256', - // useNamespace: false - }, -}) - -export function importUint256(c: ContractBuilder) { - // c.addComponent(modules.uint256, [], [], false); - // c.addModuleFunction(modules.uint256, 'Uint256'); -} \ No newline at end of file