Skip to content
This repository has been archived by the owner on Feb 22, 2024. It is now read-only.

Commit

Permalink
chore(starknet): add sepolia network (#253)
Browse files Browse the repository at this point in the history
* chore(starknet): add sepolia network

* chore: do not estimate separately if not using explicit nonce
  • Loading branch information
Sekhmet authored Jan 10, 2024
1 parent 1bf39c8 commit 31b4df5
Show file tree
Hide file tree
Showing 11 changed files with 220 additions and 143 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"micro-starknet": "^0.2.3",
"randombytes": "^2.1.0",
"snake-case": "^3.0.4",
"starknet": "5.24.3"
"starknet": "5.25.0"
},
"devDependencies": {
"@ethersproject/units": "^5.7.0",
Expand Down
14 changes: 6 additions & 8 deletions src/clients/starknet/starknet-tx/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ export class StarknetTx {

const calls = [call];

const fee = await account.estimateFee(calls);
return account.execute(calls, undefined, { ...opts, maxFee: fee.suggestedMaxFee });
const fee = opts?.nonce ? await account.estimateFee(calls) : null;
return account.execute(calls, undefined, fee ? { maxFee: fee.suggestedMaxFee } : undefined);
}

async updateProposal(account: Account, envelope: Envelope<UpdateProposal>, opts?: Opts) {
Expand All @@ -189,10 +189,8 @@ export class StarknetTx {
metadataUri: envelope.data.metadataUri
});

const calls = [call];

const fee = await account.estimateFee(calls);
return account.execute(calls, undefined, { ...opts, maxFee: fee.suggestedMaxFee });
const fee = opts?.nonce ? await account.estimateFee(call) : null;
return account.execute(call, undefined, fee ? { maxFee: fee.suggestedMaxFee } : undefined);
}

async vote(account: Account, envelope: Envelope<Vote>, opts?: Opts) {
Expand All @@ -219,8 +217,8 @@ export class StarknetTx {
metadataUri: ''
});

const fee = await account.estimateFee(call);
return account.execute(call, undefined, { ...opts, maxFee: fee.suggestedMaxFee });
const fee = opts?.nonce ? await account.estimateFee(call) : null;
return account.execute(call, undefined, fee ? { maxFee: fee.suggestedMaxFee } : undefined);
}

execute({
Expand Down
187 changes: 129 additions & 58 deletions src/networks.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { NetworkConfig, EvmNetworkConfig } from './types';
import { validateAndParseAddress } from 'starknet';
import { NetworkConfig, EvmNetworkConfig } from './types';

export const evmMainnet: EvmNetworkConfig = {
eip712ChainId: 1,
Expand Down Expand Up @@ -89,76 +90,146 @@ export const evmLineaGoerli: EvmNetworkConfig = {
}
};

export const starknetMainnet: NetworkConfig = {
eip712ChainId: '0x534e5f4d41494e',
herodotusAccumulatesChainId: 1,
spaceFactory: '0x0250e28c97e729842190c3672f9fcf8db0fc78b8080e87a894831dc69e4f4439',
masterSpace: '0x00f20287bef9f46c6051e425a84094d2436bcc1fef804db353e60f93661961ac',
starknetCommit: '0xf1ec7b0276aa5af11ecefe56efb0f198a77016e9',
authenticators: {
'0x00c4b0a7d8626638e7dd410b16ccbc48fe36e68f864dec75b23ef41e3732d5d2': {
type: 'vanilla'
},
'0x0687b57bc5459d05d9575483be8ed8e623c379484fdb1aad18b073ffd4602099': {
type: 'starkTx'
},
'0x06e9de29d8c3551e7f845888f323e864ff214359b56a137633bf7e191035b442': {
type: 'starkSig'
},
'0x063c89d1c6b938b68e88db2719cf2546a121c23642974c268515238b442b0ea0': {
type: 'ethTx'
},
'0x00b610082a0f39458e03a96663767ec25d6fb259f32c1e0dd19bf2be7a52532c': {
type: 'ethSig'
export const starknetNetworks = {
sn: {
Meta: {
eip712ChainId: '0x534e5f4d41494e',
herodotusAccumulatesChainId: 1,
herodotusDeployedOnChain: 'SN',
spaceFactory: '0x0250e28c97e729842190c3672f9fcf8db0fc78b8080e87a894831dc69e4f4439',
masterSpace: '0x00f20287bef9f46c6051e425a84094d2436bcc1fef804db353e60f93661961ac',
starknetCommit: '0xf1ec7b0276aa5af11ecefe56efb0f198a77016e9'
},
Authenticators: {
Vanilla: '0xc4b0a7d8626638e7dd410b16ccbc48fe36e68f864dec75b23ef41e3732d5d2',
EthSig: '0xb610082a0f39458e03a96663767ec25d6fb259f32c1e0dd19bf2be7a52532c',
EthTx: '0x63c89d1c6b938b68e88db2719cf2546a121c23642974c268515238b442b0ea0',
StarkSig: '0x6e9de29d8c3551e7f845888f323e864ff214359b56a137633bf7e191035b442',
StarkTx: '0x687b57bc5459d05d9575483be8ed8e623c379484fdb1aad18b073ffd4602099'
},
Strategies: {
MerkleWhitelist: '0x528b83a6af52c56cb2134fd9190a441e930831af437c1cb0fa6e459ad1435ba',
ERC20Votes: '0x2429becc80a90bbeb38c6566617c584f79c60f684e8e73313af58b109b7d637',
EVMSlotValue: null
},
ProposalValidations: {
VotingPower: '0x1b28f95cbc5bcbe52014ef974d609f14497517f31d3c9e079a2464edf988751'
},
ExecutionStrategies: {
NoExecutionSimpleMajority: '0x180e1f4fcd875b35690b6771b30197867d39c893d5ba6e32c36616733ee37c4'
}
},
strategies: {
'0x0528b83a6af52c56cb2134fd9190a441e930831af437c1cb0fa6e459ad1435ba': {
type: 'whitelist'
},
'0x02429becc80a90bbeb38c6566617c584f79c60f684e8e73313af58b109b7d637': {
type: 'erc20Votes'
'sn-tn': {
Meta: {
eip712ChainId: '0x534e5f474f45524c49',
herodotusAccumulatesChainId: 5,
herodotusDeployedOnChain: 'SN_GOERLI',
spaceFactory: '0x063c62258e1ba4d9ad72eab809ea5c3d1a4545b721bc444d6068ced6246c2f3c',
masterSpace: '0x00f20287bef9f46c6051e425a84094d2436bcc1fef804db353e60f93661961ac',
starknetCommit: '0x8bf85537c80becba711447f66a9a4452e3575e29'
},
Authenticators: {
Vanilla: '0x46ad946f22ac4e14e271f24309f14ac36f0fde92c6831a605813fefa46e0893',
EthSig: '0x48b33fe56e9b9354d4278ffdd5f6d546b13aa3d8c33149db2e2e2fdb48a369e',
EthTx: '0xd6f14d3df9ea2db12ed9572ab41d527f18dd24192e1744d3c100b2cd470812',
StarkSig: '0x5280813396bf63dd47531ccdbfa5887099d44421d3f62db3de8f7bed68794f5',
StarkTx: '0x573a7fc4d8dd3a860b376741c251772cd4d15508dd94564ff23a645d28042d'
},
Strategies: {
MerkleWhitelist: '0xe3ca14dcb7862116bbbe4331a9927c6693b141aa8936bb76e2bdfa4b551a52',
ERC20Votes: '0x30258c0b5832763b16f4e5d2ddbf97b3d61b8ff3368a3e3f112533b8549dd29',
EVMSlotValue: '0x35dbd4e4f46a059557e1b299d17f4568b49488bad5da9a003b171d90052139e'
},
ProposalValidations: {
VotingPower: '0x3ff398ab4e0aa9109c0cc889ff968c6215053a5e2176519b59f8ba87927c631'
},
ExecutionStrategies: {
NoExecutionSimpleMajority: '0x4a5658d6b9fe62283147719a8b13d72f96e8959afacc716569b936c91089147'
}
},
'sn-sep': {
Meta: {
eip712ChainId: '0x534e5f5345504f4c4941',
herodotusAccumulatesChainId: 11155111,
herodotusDeployedOnChain: 'SN_SEPOLIA',
spaceFactory: '0x302d332e9aceb184e5f301cb62c85181e7fc3b30559935c5736e987de579f6e',
masterSpace: '0x04b61126a7def0956cb4ff342ba72d850ea6b78b0ddb3e0b45f3a99bc9eb5995',
starknetCommit: '0xf1ec7b0276aa5af11ecefe56efb0f198a77016e9'
},
Authenticators: {
Vanilla: '0x51a4a1eb5ce28fc95edf408a847efccfb030d27314d9fbe82d82cb998ec1a0b',
EthSig: '0x53d98050a9738da0eac7498d909ea03f6eb03d07fb95877b54ff8acf7712276',
EthTx: '0x47ee3743ce7ad0ffcdb1ba51c9730a77cafd0ca51539714e711258f86c9f8af',
StarkSig: '0x213bb25044b189ccfda9882999dba32e011781dc11b2a6efa2b3d232824378e',
StarkTx: '0x2b63a8a92b7c67484ab99c4307c7db41b15b9a3c33359cd2b2459fd7f543a9c'
},
Strategies: {
MerkleWhitelist: '0x13bcbe7318fb8aa219d264dcf5916feb873e596389ba93d923f9a23378cb743',
ERC20Votes: '0x72067addfebbaf2d20ed07303a2c9b8e19154e8797e6e9d6819b37fea2a2963',
EVMSlotValue: '0x1f8544918b5d9b4833fb2ba2d0c7ceb0d699ae7f2b8b23ea129c9a10fe8046c'
},
ProposalValidations: {
VotingPower: '0x296e1a5ad28c9bf32b9570d6e1bedae77917866cd5d92aea4ef9271905ef549'
},
ExecutionStrategies: {
NoExecutionSimpleMajority: '0x5327bdc6522d531b7770cd51aa641fb91c280a30cdece29edbf9edd970167f6'
}
}
};
} as const;

export const starknetGoerli1: NetworkConfig = {
eip712ChainId: '0x534e5f474f45524c49',
herodotusAccumulatesChainId: 5,
spaceFactory: '0x063c62258e1ba4d9ad72eab809ea5c3d1a4545b721bc444d6068ced6246c2f3c',
masterSpace: '0x00f20287bef9f46c6051e425a84094d2436bcc1fef804db353e60f93661961ac',
starknetCommit: '0x8bf85537c80becba711447f66a9a4452e3575e29',
authenticators: {
'0x046ad946f22ac4e14e271f24309f14ac36f0fde92c6831a605813fefa46e0893': {
function createStarknetConfig(networkId: keyof typeof starknetNetworks): NetworkConfig {
const network = starknetNetworks[networkId];

const authenticators = {
[validateAndParseAddress(network.Authenticators.Vanilla)]: {
type: 'vanilla'
},
'0x00573a7fc4d8dd3a860b376741c251772cd4d15508dd94564ff23a645d28042d': {
type: 'starkTx'
},
'0x05280813396bf63dd47531ccdbfa5887099d44421d3f62db3de8f7bed68794f5': {
type: 'starkSig'
[validateAndParseAddress(network.Authenticators.EthSig)]: {
type: 'ethSig'
},
'0x00d6f14d3df9ea2db12ed9572ab41d527f18dd24192e1744d3c100b2cd470812': {
[validateAndParseAddress(network.Authenticators.EthTx)]: {
type: 'ethTx'
},
'0x048b33fe56e9b9354d4278ffdd5f6d546b13aa3d8c33149db2e2e2fdb48a369e': {
type: 'ethSig'
[validateAndParseAddress(network.Authenticators.StarkSig)]: {
type: 'starkSig'
},
[validateAndParseAddress(network.Authenticators.StarkTx)]: {
type: 'starkTx'
}
},
strategies: {
'0x00e3ca14dcb7862116bbbe4331a9927c6693b141aa8936bb76e2bdfa4b551a52': {
} as const;

const strategies = {
[validateAndParseAddress(network.Strategies.MerkleWhitelist)]: {
type: 'whitelist'
},
'0x030258c0b5832763b16f4e5d2ddbf97b3d61b8ff3368a3e3f112533b8549dd29': {
[validateAndParseAddress(network.Strategies.ERC20Votes)]: {
type: 'erc20Votes'
},
'0x035dbd4e4f46a059557e1b299d17f4568b49488bad5da9a003b171d90052139e': {
type: 'evmSlotValue',
params: {
deployedOnChain: 'SN_GOERLI'
}
}
}
};
...(network.Strategies.EVMSlotValue
? ({
[validateAndParseAddress(network.Strategies.EVMSlotValue)]: {
type: 'evmSlotValue',
params: {
deployedOnChain: network.Meta.herodotusDeployedOnChain
}
}
} as const)
: {})
} as const;

return {
eip712ChainId: network.Meta.eip712ChainId,
herodotusAccumulatesChainId: network.Meta.herodotusAccumulatesChainId,
spaceFactory: network.Meta.spaceFactory,
masterSpace: network.Meta.masterSpace,
starknetCommit: network.Meta.starknetCommit,
authenticators,
strategies
};
}

export const starknetMainnet: NetworkConfig = createStarknetConfig('sn');
export const starknetGoerli: NetworkConfig = createStarknetConfig('sn-tn');
export const starknetSepolia: NetworkConfig = createStarknetConfig('sn-sep');

export const defaultNetwork = starknetGoerli1;
export const defaultNetwork = starknetGoerli;
19 changes: 5 additions & 14 deletions test/unit/authenticators/starknet/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
import { getAuthenticator } from '../../../../src/authenticators/starknet';
import { defaultNetwork } from '../../../../src/networks';
import { starknetNetworks, starknetGoerli } from '../../../../src/networks';

describe('authenticators', () => {
describe('getAuthenticator', () => {
it('should return correct authenticator from predefined default addresses', () => {
expect(
getAuthenticator(
'0x046ad946f22ac4e14e271f24309f14ac36f0fde92c6831a605813fefa46e0893',
defaultNetwork
)?.type
).toBe('vanilla');
const { Vanilla, EthTx } = starknetNetworks['sn-tn'].Authenticators;

expect(
getAuthenticator(
'0x00d6f14d3df9ea2db12ed9572ab41d527f18dd24192e1744d3c100b2cd470812',
defaultNetwork
)?.type
).toBe('ethTx');
it('should return correct authenticator from predefined default addresses', () => {
expect(getAuthenticator(Vanilla, starknetGoerli)?.type).toBe('vanilla');
expect(getAuthenticator(EthTx, starknetGoerli)?.type).toBe('ethTx');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exports[`EthereumSig should create propose envelope 1`] = `
{
"data": {
"authenticator": "0x048b33fe56e9b9354d4278ffdd5f6d546b13aa3d8c33149db2e2e2fdb48a369e",
"authenticator": "0x48b33fe56e9b9354d4278ffdd5f6d546b13aa3d8c33149db2e2e2fdb48a369e",
"executionStrategy": {
"addr": "0x040de235a2b53e921d37c2ea2b160750ca2e94f01d709f78f870963559de8fbe",
"params": [
Expand All @@ -14,15 +14,15 @@ exports[`EthereumSig should create propose envelope 1`] = `
"space": "0x06330d3e48f59f5411c201ee2e9e9ccdc738fb3bb192b0e77e4eda26fa1a22f8",
"strategies": [
{
"address": "0x00e3ca14dcb7862116bbbe4331a9927c6693b141aa8936bb76e2bdfa4b551a52",
"address": "0xe3ca14dcb7862116bbbe4331a9927c6693b141aa8936bb76e2bdfa4b551a52",
"index": 0,
},
],
},
"signatureData": {
"address": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
"message": {
"authenticator": "0x048b33fe56e9b9354d4278ffdd5f6d546b13aa3d8c33149db2e2e2fdb48a369e",
"authenticator": "0x48b33fe56e9b9354d4278ffdd5f6d546b13aa3d8c33149db2e2e2fdb48a369e",
"author": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
"chainId": "0x534e5f474f45524c49",
"executionStrategy": {
Expand Down Expand Up @@ -54,7 +54,7 @@ exports[`EthereumSig should create propose envelope 1`] = `
exports[`EthereumSig should create update proposal envelope 1`] = `
{
"data": {
"authenticator": "0x048b33fe56e9b9354d4278ffdd5f6d546b13aa3d8c33149db2e2e2fdb48a369e",
"authenticator": "0x48b33fe56e9b9354d4278ffdd5f6d546b13aa3d8c33149db2e2e2fdb48a369e",
"executionStrategy": {
"addr": "0x040de235a2b53e921d37c2ea2b160750ca2e94f01d709f78f870963559de8fbe",
"params": [
Expand All @@ -68,7 +68,7 @@ exports[`EthereumSig should create update proposal envelope 1`] = `
"signatureData": {
"address": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
"message": {
"authenticator": "0x048b33fe56e9b9354d4278ffdd5f6d546b13aa3d8c33149db2e2e2fdb48a369e",
"authenticator": "0x48b33fe56e9b9354d4278ffdd5f6d546b13aa3d8c33149db2e2e2fdb48a369e",
"author": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
"chainId": "0x534e5f474f45524c49",
"executionStrategy": {
Expand Down Expand Up @@ -98,21 +98,21 @@ exports[`EthereumSig should create update proposal envelope 1`] = `
exports[`EthereumSig should create vote envelope 1`] = `
{
"data": {
"authenticator": "0x048b33fe56e9b9354d4278ffdd5f6d546b13aa3d8c33149db2e2e2fdb48a369e",
"authenticator": "0x48b33fe56e9b9354d4278ffdd5f6d546b13aa3d8c33149db2e2e2fdb48a369e",
"choice": 1,
"proposal": 1,
"space": "0x06330d3e48f59f5411c201ee2e9e9ccdc738fb3bb192b0e77e4eda26fa1a22f8",
"strategies": [
{
"address": "0x00e3ca14dcb7862116bbbe4331a9927c6693b141aa8936bb76e2bdfa4b551a52",
"address": "0xe3ca14dcb7862116bbbe4331a9927c6693b141aa8936bb76e2bdfa4b551a52",
"index": 0,
},
],
},
"signatureData": {
"address": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
"message": {
"authenticator": "0x048b33fe56e9b9354d4278ffdd5f6d546b13aa3d8c33149db2e2e2fdb48a369e",
"authenticator": "0x48b33fe56e9b9354d4278ffdd5f6d546b13aa3d8c33149db2e2e2fdb48a369e",
"chainId": "0x534e5f474f45524c49",
"choice": "0x1",
"metadataUri": [],
Expand Down
Loading

0 comments on commit 31b4df5

Please sign in to comment.