Skip to content

Commit

Permalink
feat: udc demo
Browse files Browse the repository at this point in the history
  • Loading branch information
tabaktoni committed Oct 27, 2022
1 parent e810c88 commit 27b402b
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 4 deletions.
16 changes: 14 additions & 2 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,7 +39,19 @@ describe('deploy and test Wallet', () => {
});
dapp = new Contract(compiledTestDapp.abi, dappResponse.contract_address!, provider);
await provider.waitForTransaction(dappResponse.transaction_hash);
await provider.waitForTransaction(dappResponse.transaction_hash); */
console.log('ok');
});

test('UDC Deploy', async () => {
const result = await account.deploy({
classHash: '0x04c2d9baf8dd7c2c57959b5c20ce35cb6b8e9a1f9089da5bf10c9a4986854869',
salt: '123',
unique: true,
constructorCalldata: [],
});

console.log('resut: ', result);
});

test('estimate fee', async () => {
Expand Down
27 changes: 26 additions & 1 deletion src/account/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ import {
Signature,
} from '../types';
import { EstimateFee, EstimateFeeDetails } from '../types/account';
import { AllowArray, DeclareContractPayload, DeployAccountContractPayload } from '../types/lib';
import {
AllowArray,
DeclareContractPayload,
DeployAccountContractPayload,
UniversalDeployerContractPayload,
} from '../types/lib';
import { calculateContractAddressFromHash, transactionVersion } from '../utils/hash';
import { BigNumberish, toBN } from '../utils/number';
import { parseContract } from '../utils/provider';
Expand Down Expand Up @@ -228,6 +233,26 @@ export class Account extends Provider implements AccountInterface {
);
}

public async deploy(
{ classHash, salt, unique, constructorCalldata = [] }: UniversalDeployerContractPayload,
transactionsDetail: InvocationsDetails = {}
): Promise<any> {
return this.execute(
{
contractAddress: '0x041a78e741e5af2fec34b695679bc6891742439f7afb8484ecd7766661ad02bf',
entrypoint: 'deployContract',
calldata: [
classHash,
salt,
unique === true ? '1' : '0',
// constructorCalldata.toString(),
],
},
undefined,
transactionsDetail
);
}

public async deployAccount(
{
classHash,
Expand Down
23 changes: 22 additions & 1 deletion src/account/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ import {
InvokeFunctionResponse,
Signature,
} from '../types';
import { AllowArray, DeclareContractPayload, DeployAccountContractPayload } from '../types/lib';
import {
AllowArray,
DeclareContractPayload,
DeployAccountContractPayload,
UniversalDeployerContractPayload,
} from '../types/lib';
import { BigNumberish } from '../utils/number';
import { TypedData } from '../utils/typedData/types';

Expand Down Expand Up @@ -117,6 +122,22 @@ export abstract class AccountInterface extends ProviderInterface {
transactionsDetail?: InvocationsDetails
): Promise<DeclareContractResponse>;

/**
* @param deployContractPayload containing
* - classHash: computed class hash of compiled contract
* - salt: address salt
* - unique: bool if true ensure unique salt
* - calldata: constructor calldata
* @param transactionsDetail Invocation Details containing:
* - optional nonce
* - optional version
* - optional maxFee
*/
public abstract deploy(
deployContractPayload: UniversalDeployerContractPayload,
transactionsDetail?: InvocationsDetails
): Promise<any>;

/**
* Deploy the account on Starknet
*
Expand Down
7 changes: 7 additions & 0 deletions src/types/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ export interface ContractClass {
abi?: Abi;
}

export type UniversalDeployerContractPayload = {
classHash: BigNumberish;
salt: string;
unique: boolean;
constructorCalldata: RawCalldata;
};

export type DeployContractPayload = {
contract: CompiledContract | string;
constructorCalldata?: RawCalldata;
Expand Down

0 comments on commit 27b402b

Please sign in to comment.