diff --git a/__tests__/account.test.ts b/__tests__/account.test.ts index cbede2398..4b2fd8d30 100644 --- a/__tests__/account.test.ts +++ b/__tests__/account.test.ts @@ -23,7 +23,7 @@ describe('deploy and test Wallet', () => { const erc20DeployPayload = getERC20DeployPayload(account.address); - /* const erc20Response = await provider.deployContract(erc20DeployPayload); + const erc20Response = await provider.deployContract(erc20DeployPayload); erc20Address = erc20Response.contract_address; erc20 = new Contract(compiledErc20.abi, erc20Address, provider); @@ -39,19 +39,25 @@ describe('deploy and test Wallet', () => { }); dapp = new Contract(compiledTestDapp.abi, dappResponse.contract_address!, provider); - await provider.waitForTransaction(dappResponse.transaction_hash); */ - console.log('ok'); + await provider.waitForTransaction(dappResponse.transaction_hash); }); test('UDC Deploy', async () => { - const result = await account.deploy({ - classHash: '0x04c2d9baf8dd7c2c57959b5c20ce35cb6b8e9a1f9089da5bf10c9a4986854869', + // only work on testnet + const deployment = await account.deploy({ + classHash: '0x6ad13d6c3f382bdc7d337a3928528e974b76c21153ff25a946d2c4f26ef1c6b', + callData: [ + '0xb3e8b4bd1906e46f4b9ce2d0cbdcf747409ab506469287587b23130a600535', + '0x2dd76e7ad84dbed81c314ffe5e7a7cacfb8f4836f01af4e913f275f89a3de1a', + '0x2', + '0x46a1aa85bb0e68cd29fadbc81791208ddebee17886f075935e5b72f4aa898aa', + '0x46a1aa85bb0e68cd29fadbc81791208ddebee17886f075935e5b72f4aa898aa', + ], salt: '123', - unique: true, - constructorCalldata: [], + unique: false, }); - console.log('resut: ', result); + expect(deployment).toHaveProperty('transaction_hash'); }); test('estimate fee', async () => { diff --git a/src/account/default.ts b/src/account/default.ts index 2dfe8e2a5..a5ea18257 100644 --- a/src/account/default.ts +++ b/src/account/default.ts @@ -1,4 +1,4 @@ -import { ZERO } from '../constants'; +import { UDC, ZERO } from '../constants'; import { ProviderInterface, ProviderOptions } from '../provider'; import { Provider } from '../provider/default'; import { BlockIdentifier } from '../provider/utils'; @@ -23,7 +23,7 @@ import { UniversalDeployerContractPayload, } from '../types/lib'; import { calculateContractAddressFromHash, transactionVersion } from '../utils/hash'; -import { BigNumberish, toBN } from '../utils/number'; +import { BigNumberish, toBN, toCairoBool } from '../utils/number'; import { parseContract } from '../utils/provider'; import { compileCalldata, estimatedFeeToMaxFee } from '../utils/stark'; import { fromCallsToExecuteCalldata } from '../utils/transaction'; @@ -234,18 +234,20 @@ export class Account extends Provider implements AccountInterface { } public async deploy( - { classHash, salt, unique, constructorCalldata = [] }: UniversalDeployerContractPayload, + { classHash, salt, unique = true, callData = [] }: UniversalDeployerContractPayload, transactionsDetail: InvocationsDetails = {} ): Promise { + const compiledCallData = compileCalldata(callData); return this.execute( { - contractAddress: '0x041a78e741e5af2fec34b695679bc6891742439f7afb8484ecd7766661ad02bf', - entrypoint: 'deployContract', + contractAddress: UDC.ADDRESS, + entrypoint: UDC.ENTRYPOINT, calldata: [ classHash, salt, - unique === true ? '1' : '0', - // constructorCalldata.toString(), + toCairoBool(unique), + compiledCallData.length, + ...compiledCallData, ], }, undefined, diff --git a/src/constants.ts b/src/constants.ts index 763fd34f2..b0015018c 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -20,6 +20,11 @@ export enum TransactionHashPrefix { L1_HANDLER = '0x6c315f68616e646c6572', // encodeShortString('l1_handler'), } +export const UDC = { + ADDRESS: '0x041a78e741e5af2fec34b695679bc6891742439f7afb8484ecd7766661ad02bf', + ENTRYPOINT: 'deployContract', +}; + /** * The following is taken from https://github.com/starkware-libs/starkex-resources/blob/master/crypto/starkware/crypto/signature/pedersen_params.json but converted to hex, because JS is very bad handling big integers by default * Please do not edit until the JSON changes. diff --git a/src/types/api/index.ts b/src/types/api/index.ts index 17c034e1e..7f828965e 100644 --- a/src/types/api/index.ts +++ b/src/types/api/index.ts @@ -1,9 +1,11 @@ import { BigNumberish } from '../../utils/number'; import { Signature } from '../lib'; -export type RawArgs = { - [inputName: string]: string | string[] | { type: 'struct'; [k: string]: BigNumberish }; -}; +export type RawArgs = + | { + [inputName: string]: string | string[] | { type: 'struct'; [k: string]: BigNumberish }; + } + | string[]; export type Calldata = string[]; diff --git a/src/types/lib.ts b/src/types/lib.ts index bcb982678..8842d8636 100644 --- a/src/types/lib.ts +++ b/src/types/lib.ts @@ -7,6 +7,11 @@ export type KeyPair = EC.KeyPair; export type Signature = string[]; export type RawCalldata = BigNumberish[]; export type AllowArray = T | T[]; +export type RawArgs = + | { + [inputName: string]: string | string[] | { type: 'struct'; [k: string]: BigNumberish }; + } + | string[]; export interface ContractClass { program: CompressedProgram; @@ -18,7 +23,7 @@ export type UniversalDeployerContractPayload = { classHash: BigNumberish; salt: string; unique: boolean; - constructorCalldata: RawCalldata; + callData: RawArgs; }; export type DeployContractPayload = { diff --git a/src/utils/number.ts b/src/utils/number.ts index 125bc555a..703baf7be 100644 --- a/src/utils/number.ts +++ b/src/utils/number.ts @@ -88,3 +88,5 @@ export function getHexString(value: string) { export function getHexStringArray(value: Array) { return value.map((el) => getHexString(el)); } + +export const toCairoBool = (value: boolean): string => (+value).toString();