Skip to content

Commit

Permalink
remove more lib functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Leonard-Pat committed Jun 6, 2024
1 parent f1bb825 commit 28ed163
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 343 deletions.
68 changes: 4 additions & 64 deletions lib/accounts.ts
Original file line number Diff line number Diff line change
@@ -1,67 +1,7 @@
import {
Abi,
Account,
AllowArray,
Call,
CallData,
Contract,
DeployAccountContractPayload,
DeployContractResponse,
InvokeFunctionResponse,
RPC,
UniversalDetails,
num,
uint256,
} from "starknet";
import { Account, Call, CallData, RPC, uint256 } from "starknet";
import { manager } from "./manager";
import { KeyPair } from "./signers/signers";
import { ethAddress, strkAddress } from "./tokens";

export class ArgentAccount extends Account {
// Increase the gas limit by 30% to avoid failures due to gas estimation being too low with tx v3 and transactions the use escaping
override async deployAccount(
payload: DeployAccountContractPayload,
details?: UniversalDetails,
): Promise<DeployContractResponse> {
details ||= {};
if (!details.skipValidate) {
details.skipValidate = false;
}
return super.deployAccount(payload, details);
}

override async execute(
calls: AllowArray<Call>,
abis?: Abi[],
details: UniversalDetails = {},
): Promise<InvokeFunctionResponse> {
details ||= {};
if (!details.skipValidate) {
details.skipValidate = false;
}
if (details.resourceBounds) {
return super.execute(calls, abis, details);
}
const estimate = await this.estimateFee(calls, details);
return super.execute(calls, abis, {
...details,
resourceBounds: {
...estimate.resourceBounds,
l1_gas: {
...estimate.resourceBounds.l1_gas,
max_amount: num.toHexString(num.addPercent(estimate.resourceBounds.l1_gas.max_amount, 30)),
},
},
});
}
}

export interface ArgentWallet {
account: ArgentAccount;
accountContract: Contract;
owner: KeyPair;
}

export const deployer = (() => {
if (manager.isDevnet) {
const devnetAddress = "0x64b48806902a367c8598f4f95c305e8c1a1acba5f082d294a43793113115691";
Expand All @@ -87,15 +27,15 @@ export const genericAccount = (() => {

export const deployerV3 = setDefaultTransactionVersionV3(deployer);

export function setDefaultTransactionVersion(account: ArgentAccount, newVersion: boolean): Account {
export function setDefaultTransactionVersion(account: Account, newVersion: boolean): Account {
const newDefaultVersion = newVersion ? RPC.ETransactionVersion.V3 : RPC.ETransactionVersion.V2;
if (account.transactionVersion === newDefaultVersion) {
return account;
}
return new ArgentAccount(account, account.address, account.signer, account.cairoVersion, newDefaultVersion);
return new Account(account, account.address, account.signer, account.cairoVersion, newDefaultVersion);
}

export function setDefaultTransactionVersionV3(account: ArgentAccount): ArgentAccount {
export function setDefaultTransactionVersionV3(account: Account): Account {
return setDefaultTransactionVersion(account, true);
}

Expand Down
1 change: 0 additions & 1 deletion lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export * from "./contracts";
export * from "./devnet";
export * from "./expectations";
export * from "./manager";
export * from "./openZeppelinAccount";
export * from "./receipts";
export * from "./signers/legacy";
export * from "./signers/signers";
Expand Down
60 changes: 0 additions & 60 deletions lib/openZeppelinAccount.ts

This file was deleted.

39 changes: 0 additions & 39 deletions lib/signers/legacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,6 @@ export class LegacyArgentSigner extends RawSigner {
}
}

export class LegacyMultisigSigner extends RawSigner {
constructor(public keys: RawSigner[]) {
super();
}

async signRaw(messageHash: string): Promise<string[]> {
const keys = [];
for (const key of this.keys) {
keys.push(await key.signRaw(messageHash));
}
return keys.flat();
}
}

export abstract class LegacyKeyPair extends RawSigner {
abstract get privateKey(): string;
abstract get publicKey(): bigint;
Expand All @@ -60,28 +46,3 @@ export class LegacyStarknetKeyPair extends LegacyKeyPair {
return [r.toString(), s.toString()];
}
}

export class LegacyMultisigKeyPair extends LegacyKeyPair {
pk: string;

constructor(pk?: string | bigint) {
super();
this.pk = pk ? `${pk}` : `0x${encode.buf2hex(ec.starkCurve.utils.randomPrivateKey())}`;
}

public get publicKey() {
return BigInt(ec.starkCurve.getStarkKey(this.pk));
}

public get privateKey(): string {
return this.pk;
}

public async signRaw(messageHash: string): Promise<string[]> {
const { r, s } = ec.starkCurve.sign(messageHash, this.pk);
return [this.publicKey.toString(), r.toString(), s.toString()];
}
}

export const randomLegacyMultisigKeyPairs = (length: number) =>
Array.from({ length }, () => new LegacyMultisigKeyPair()).sort((n1, n2) => (n1.publicKey < n2.publicKey ? -1 : 1));
Loading

0 comments on commit 28ed163

Please sign in to comment.