Skip to content

Commit

Permalink
feat: udc working example
Browse files Browse the repository at this point in the history
  • Loading branch information
tabaktoni committed Oct 28, 2022
1 parent 27b402b commit 5c4452a
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 19 deletions.
22 changes: 14 additions & 8 deletions __tests__/account.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 () => {
Expand Down
16 changes: 9 additions & 7 deletions src/account/default.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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';
Expand Down Expand Up @@ -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<any> {
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,
Expand Down
5 changes: 5 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 5 additions & 3 deletions src/types/api/index.ts
Original file line number Diff line number Diff line change
@@ -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[];

Expand Down
7 changes: 6 additions & 1 deletion src/types/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ export type KeyPair = EC.KeyPair;
export type Signature = string[];
export type RawCalldata = BigNumberish[];
export type AllowArray<T> = T | T[];
export type RawArgs =
| {
[inputName: string]: string | string[] | { type: 'struct'; [k: string]: BigNumberish };
}
| string[];

export interface ContractClass {
program: CompressedProgram;
Expand All @@ -18,7 +23,7 @@ export type UniversalDeployerContractPayload = {
classHash: BigNumberish;
salt: string;
unique: boolean;
constructorCalldata: RawCalldata;
callData: RawArgs;
};

export type DeployContractPayload = {
Expand Down
2 changes: 2 additions & 0 deletions src/utils/number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,5 @@ export function getHexString(value: string) {
export function getHexStringArray(value: Array<string>) {
return value.map((el) => getHexString(el));
}

export const toCairoBool = (value: boolean): string => (+value).toString();

0 comments on commit 5c4452a

Please sign in to comment.