Skip to content

Commit

Permalink
refactor: migrate to starknet@6 (#313)
Browse files Browse the repository at this point in the history
* refactor: migrate to starknet@6

* feat: migrate to starknet-devnet-rs

* chore: fix lint
  • Loading branch information
Sekhmet authored Aug 12, 2024
1 parent f7e9771 commit 58fc38b
Show file tree
Hide file tree
Showing 14 changed files with 111 additions and 49 deletions.
2 changes: 1 addition & 1 deletion apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"@types/node": "^18.11.6",
"cross-fetch": "^4.0.0",
"dotenv": "^16.0.1",
"starknet": "^5.19.3"
"starknet": "6.11.0"
},
"devDependencies": {
"@snapshot-labs/eslint-config": "0.1.0-beta.18",
Expand Down
8 changes: 3 additions & 5 deletions apps/api/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
CallData,
Contract,
hash,
Provider,
RpcProvider,
shortString,
validateAndParseAddress
} from 'starknet';
Expand All @@ -34,10 +34,8 @@ export const ethProvider = new JsonRpcProvider(
process.env.L1_NETWORK_NODE_URL ??
`https://rpc.brovider.xyz/${networkProperties.baseChainId}`
);
const starkProvider = new Provider({
rpc: {
nodeUrl: networkNodeUrl
}
const starkProvider = new RpcProvider({
nodeUrl: networkNodeUrl
});

const encodersAbi = new CallData(EncodersAbi);
Expand Down
2 changes: 1 addition & 1 deletion apps/mana/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"express": "^4.17.1",
"knex": "^2.5.1",
"pg": "^8.11.3",
"starknet": "5.25.0",
"starknet": "6.11.0",
"zod": "^3.22.4"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion apps/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
"pinia": "^2.1.6",
"remarkable": "^2.0.1",
"scrollmonitor": "^1.2.11",
"starknet": "5.25.0",
"starknet": "6.11.0",
"starknetkit": "^1.1.9",
"stream-browserify": "^3.0.0",
"tippy.js": "^6.3.7",
Expand Down
7 changes: 4 additions & 3 deletions apps/ui/src/networks/starknet/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
LibraryError,
constants as starknetConstants,
TransactionExecutionStatus
ReceiptTx,
constants as starknetConstants
} from 'starknet';
import { pinPineapple } from '@/helpers/pin';
import { Network } from '@/networks/types';
Expand Down Expand Up @@ -106,7 +106,8 @@ export function createStarknetNetwork(networkId: NetworkID): Network {
return;
}

if (tx.execution_status === TransactionExecutionStatus.SUCCEEDED) {
const receiptTx = new ReceiptTx(tx);
if (receiptTx.isSuccess()) {
resolve(tx);
} else {
reject(tx);
Expand Down
4 changes: 2 additions & 2 deletions packages/sx.js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"prepare": "yarn build",
"prepublishOnly": "yarn run lint",
"node:evm": "anvil",
"node:starknet": "OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES starknet-devnet --seed 1",
"node:starknet": "starknet-devnet --seed 1",
"test": "SEPOLIA_NODE_URL=https://rpc.snapshotx.xyz/11155111 vitest run test/unit",
"test:integration:starknet": "vitest run test/integration/starknet",
"test:integration:evm": "vitest run test/integration/evm",
Expand Down Expand Up @@ -54,7 +54,7 @@
"micro-starknet": "^0.2.3",
"randombytes": "^2.1.0",
"snake-case": "^3.0.4",
"starknet": "5.25.0"
"starknet": "6.11.0"
},
"devDependencies": {
"@ethersproject/units": "^5.7.0",
Expand Down
1 change: 1 addition & 0 deletions packages/sx.js/src/clients/starknet/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const ESTIMATE_FEE_OVERHEAD_PERCENT = 50;
14 changes: 4 additions & 10 deletions packages/sx.js/src/clients/starknet/ethereum-tx/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Signer } from '@ethersproject/abstract-signer';
import { Contract } from '@ethersproject/contracts';
import { poseidonHashMany } from 'micro-starknet';
import { CallData, constants, SequencerProvider, shortString } from 'starknet';
import { CallData, shortString } from 'starknet';
import StarknetCommitAbi from './abis/StarknetCommit.json';
import {
ClientConfig,
Expand Down Expand Up @@ -199,12 +199,10 @@ const UPDATE_PROPOSAL_SELECTOR =
'0x1f93122f646d968b0ce8c1a4986533f8b4ed3f099122381a4f77478a480c2c3';

export class EthereumTx {
// TODO: handle sequencerUrl in network config
config: ClientConfig & { sequencerUrl: string };
config: ClientConfig;

constructor(opts: ClientOpts & { sequencerUrl?: string }) {
constructor(opts: ClientOpts) {
this.config = {
sequencerUrl: opts.sequencerUrl || constants.BaseUrl.SN_SEPOLIA,
...opts
};
}
Expand All @@ -213,11 +211,7 @@ export class EthereumTx {
l2Address: string,
payload: string[]
): Promise<{ overall_fee: number }> {
const sequencerProvider = new SequencerProvider({
baseUrl: this.config.sequencerUrl
});

const fees = await sequencerProvider.estimateMessageFee({
const fees = await this.config.starkProvider.estimateMessageFee({
from_address: this.config.networkConfig.starknetCommit,
to_address: l2Address,
entry_point_selector: 'commit',
Expand Down
2 changes: 1 addition & 1 deletion packages/sx.js/src/clients/starknet/starknet-sig/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export class StarknetSig {
verifyingContract
};

const data: typedData.TypedData = {
const data: typeof typedData.TypedData = {
types,
primaryType,
domain,
Expand Down
4 changes: 2 additions & 2 deletions packages/sx.js/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
TypedDataDomain,
TypedDataField
} from '@ethersproject/abstract-signer';
import { BigNumberish, Call, RpcProvider, StarkNetType } from 'starknet';
import { BigNumberish, Call, RpcProvider, StarknetType } from 'starknet';
import { NetworkConfig } from './networkConfig';
import { MetaTransaction } from '../utils/encoding';

Expand Down Expand Up @@ -151,7 +151,7 @@ export type SignatureData = {
signature?: string | string[] | null;
message?: Record<string, any>;
domain?: TypedDataDomain;
types?: Record<string, TypedDataField[] | StarkNetType[]>;
types?: Record<string, TypedDataField[] | StarknetType[]>;
primaryType?: any;
};

Expand Down
2 changes: 1 addition & 1 deletion packages/sx.js/src/utils/fees.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Account, Call, stark } from 'starknet';
import { NetworkConfig } from '../types';

const FEE_OVERHEAD = 0.5;
const FEE_OVERHEAD = 50;

export async function estimateStarknetFee(
account: Account,
Expand Down
21 changes: 8 additions & 13 deletions packages/sx.js/test/integration/starknet/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { JsonRpcProvider } from '@ethersproject/providers';
import { Wallet } from '@ethersproject/wallet';
import { Account, Provider, uint256 } from 'starknet';
import { Account, RpcProvider, uint256 } from 'starknet';
import { beforeAll, describe, expect, it } from 'vitest';
import ozAccountCasm from './fixtures/openzeppelin_Account.casm.json';
import ozAccountSierra from './fixtures/openzeppelin_Account.sierra.json';
Expand All @@ -25,8 +25,8 @@ import { Choice } from '../../../src/types';
describe('sx-starknet', () => {
const ethUrl = 'http://127.0.0.1:8545';
const entryAddress =
'0x7d2f37b75a5e779f7da01c22acee1b66c39e8ba470ee5448f05e1462afcedb4';
const entryPrivateKey = '0xcd613e30d8f16adf91b7584a2265b1f5';
'0x260a8311b4f1092db620b923e8d7d20e76dedcc615fb4b6fdf28315b81de201';
const entryPrivateKey = '0xc10662b7b247c7cecf7e8a30726cff12';
const ethPrivateKey =
'0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80';

Expand All @@ -35,11 +35,8 @@ describe('sx-starknet', () => {
'0x138b5dd1ca094fcaebd669a5d2aa7bb7d13db32d5939939ee66b938ded2f361';
const privateKey = '0x9c7d498a8f76dc87564274036988f668';

// RpcProvider doesn't work with starknet-devnet
const starkProvider = new Provider({
sequencer: {
baseUrl: 'http://127.0.0.1:5050'
}
const starkProvider = new RpcProvider({
nodeUrl: 'http://127.0.0.1:5050/rpc'
});

const provider = new JsonRpcProvider(ethUrl);
Expand Down Expand Up @@ -92,16 +89,15 @@ describe('sx-starknet', () => {
ethTxClient = new EthereumTx({
starkProvider: starkProvider as any,
ethUrl,
networkConfig: testConfig.networkConfig,
sequencerUrl: 'http://127.0.0.1:5050'
networkConfig: testConfig.networkConfig
});
starkSigClient = new StarknetSig({
starkProvider: starkProvider as any,
ethUrl,
networkConfig: testConfig.networkConfig,
manaUrl: 'http://localhost:3000'
});
}, 300_000);
}, 500_000);

describe('vanilla authenticator', () => {
it('StarknetTx.propose()', async () => {
Expand Down Expand Up @@ -601,8 +597,7 @@ describe('sx-starknet', () => {

it('should execute on l1', async () => {
const flushL2Response = await flush();
const message_payload =
flushL2Response.consumed_messages.from_l2[0].payload;
const message_payload = flushL2Response.messages_to_l1[0].payload;

const { executionParams } = getExecutionData(
'EthRelayer',
Expand Down
6 changes: 3 additions & 3 deletions packages/sx.js/test/integration/starknet/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export async function setup({
ethereumWallet: Wallet;
ethUrl: string;
}): Promise<TestConfig> {
await mint(starknetAccount.address, 1000000000000000000000);
await mint(starknetAccount.address, 100000000000000000);

const masterSpaceResult = await starknetAccount.declareIfNot({
contract: sxSpaceSierra as any,
Expand Down Expand Up @@ -287,7 +287,7 @@ export async function setup({
const merkleTreeRoot = generateMerkleRoot(hashes);

const networkConfig: NetworkConfig = {
eip712ChainId: '0x534e5f474f45524c49',
eip712ChainId: '0x534e5f5345504f4c4941',
spaceFactory: factoryAddress,
l1AvatarExecutionStrategyImplementation: masterl1AvatarExecutionStrategy,
l1AvatarExecutionStrategyFactory,
Expand Down Expand Up @@ -531,7 +531,7 @@ export function increaseTime(timeIncrease: number) {

export function loadL1MessagingContract(networkUrl: string, address: string) {
return postDevnet('postman/load_l1_messaging_contract', {
networkUrl,
network_url: networkUrl,
address
});
}
Expand Down
Loading

0 comments on commit 58fc38b

Please sign in to comment.