Skip to content

Commit 5116b9d

Browse files
authored
Merge branch 'master' into feature/drel-378-tg-osmosis-team-facing-issues-with-sdk-utility-method
2 parents 10cf10b + 5fd2674 commit 5116b9d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+3712
-43
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"@cosmjs/proto-signing": "0.30.1",
4141
"@cosmjs/stargate": "0.30.1",
4242
"@dotenvx/dotenvx": "^1.6.4",
43-
"@lit-protocol/accs-schemas": "^0.0.20",
43+
"@lit-protocol/accs-schemas": "^0.0.22",
4444
"@lit-protocol/contracts": "^0.0.74",
4545
"@metamask/eth-sig-util": "5.0.2",
4646
"@mysten/sui.js": "^0.37.1",
@@ -85,6 +85,7 @@
8585
"@nx/web": "17.3.0",
8686
"@solana/web3.js": "1.95.3",
8787
"@types/depd": "^1.1.36",
88+
"@types/events": "^3.0.3",
8889
"@types/jest": "27.4.1",
8990
"@types/node": "18.19.18",
9091
"@types/secp256k1": "^4.0.6",

packages/constants/src/lib/constants/constants.ts

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ export const LIT_CHAINS: LITChain<LITEVMChain> = {
120120
name: 'Arbitrum Sepolia',
121121
symbol: 'ETH',
122122
decimals: 18,
123-
rpcUrls: ['https://arbitrum-sepolia.blockpi.network/v1/rpc/public'],
123+
rpcUrls: ['https://sepolia-rollup.arbitrum.io/rpc'],
124124
blockExplorerUrls: ['https://sepolia.arbiscan.io/'],
125125
type: null,
126126
vmType: 'EVM',
@@ -358,6 +358,17 @@ export const LIT_CHAINS: LITChain<LITEVMChain> = {
358358
type: null,
359359
vmType: 'EVM',
360360
},
361+
filecoinCalibrationTestnet: {
362+
contractAddress: null,
363+
chainId: 314159,
364+
name: 'Filecoin Calibration Testnet',
365+
symbol: 'tFIL',
366+
decimals: 18,
367+
rpcUrls: ['https://api.calibration.node.glif.io/rpc/v1'],
368+
blockExplorerUrls: ['https://calibration.filscan.io/'],
369+
type: null,
370+
vmType: 'EVM',
371+
},
361372
hyperspace: {
362373
contractAddress: null,
363374
chainId: 3141,
@@ -879,6 +890,39 @@ export const LIT_CHAINS: LITChain<LITEVMChain> = {
879890
type: null,
880891
vmType: 'EVM',
881892
},
893+
coreDao: {
894+
contractAddress: null,
895+
chainId: 1116,
896+
name: 'Core DAO',
897+
symbol: 'CORE',
898+
decimals: 18,
899+
rpcUrls: ['https://rpc.coredao.org'],
900+
blockExplorerUrls: ['https://scan.coredao.org/'],
901+
type: null,
902+
vmType: 'EVM',
903+
},
904+
zkCandySepoliaTestnet: {
905+
contractAddress: null,
906+
chainId: 302,
907+
name: 'ZKcandy Sepolia Testnet',
908+
symbol: 'ETH',
909+
decimals: 18,
910+
rpcUrls: ['https://sepolia.rpc.zkcandy.io'],
911+
blockExplorerUrls: ['https://sepolia.explorer.zkcandy.io'],
912+
type: null,
913+
vmType: 'EVM',
914+
},
915+
vana: {
916+
contractAddress: null,
917+
chainId: 1480,
918+
name: 'Vana',
919+
symbol: 'VANA',
920+
decimals: 18,
921+
rpcUrls: ['https://rpc.vana.org'],
922+
blockExplorerUrls: ['https://vanascan.io'],
923+
type: null,
924+
vmType: 'EVM',
925+
},
882926
};
883927

884928
/**

packages/constants/src/lib/errors.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,11 @@ export const LIT_ERROR: Record<string, ErrorConfig> = {
217217
code: 'transaction_error',
218218
kind: LitErrorKind.Unexpected,
219219
},
220+
AUTOMATION_ERROR: {
221+
name: 'AutomationError',
222+
code: 'automation_error',
223+
kind: LitErrorKind.Unexpected,
224+
},
220225
};
221226

222227
export const LIT_ERROR_CODE = {
@@ -292,6 +297,7 @@ const MultiError = VError.MultiError;
292297
export { MultiError };
293298

294299
export const {
300+
AutomationError,
295301
InitError,
296302
InvalidAccessControlConditions,
297303
InvalidArgumentException,

packages/core/src/lib/lit-core.spec.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,16 +98,21 @@ describe('LitCore', () => {
9898
timestamp: currentTime,
9999
}),
100100
};
101+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
101102
jest.spyOn(core as any, '_getProviderWithFallback').mockResolvedValue({
102-
...mockProvider,
103+
provider: mockProvider,
104+
testResult: {
105+
hash: mockBlockhash,
106+
number: 12345,
107+
timestamp: currentTime,
108+
},
103109
});
104110

105111
// Execute
106112
const result = await core.getLatestBlockhash();
107113

108114
// Assert
109115
expect(fetch).toHaveBeenCalledWith(mockBlockhashUrl);
110-
expect(mockProvider.getBlock).toHaveBeenCalledWith(-1); // safety margin
111116
expect(result).toBe(mockBlockhash);
112117
});
113118

@@ -132,16 +137,21 @@ describe('LitCore', () => {
132137
timestamp: currentTime,
133138
}),
134139
};
140+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
135141
jest.spyOn(core as any, '_getProviderWithFallback').mockResolvedValue({
136-
...mockProvider,
142+
provider: mockProvider,
143+
testResult: {
144+
hash: mockBlockhash,
145+
number: 12345,
146+
timestamp: currentTime,
147+
},
137148
});
138149

139150
// Execute
140151
const result = await core.getLatestBlockhash();
141152

142153
// Assert
143154
expect(fetch).toHaveBeenCalledWith(mockBlockhashUrl);
144-
expect(mockProvider.getBlock).toHaveBeenCalledWith(-1); // safety margin
145155
expect(result).toBe(mockBlockhash);
146156
});
147157

@@ -164,8 +174,10 @@ describe('LitCore', () => {
164174
getBlock: jest.fn().mockResolvedValue(null), // Provider also fails
165175
};
166176

177+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
167178
jest.spyOn(core as any, '_getProviderWithFallback').mockResolvedValue({
168-
...mockProvider,
179+
provider: mockProvider,
180+
testResult: null,
169181
});
170182

171183
// Execute & Assert

packages/core/src/lib/lit-core.ts

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import {
2121
LIT_CURVE,
2222
LIT_CURVE_VALUES,
2323
LIT_ENDPOINT,
24-
LIT_ERROR,
2524
LIT_ERROR_CODE,
2625
LIT_NETWORK,
2726
LIT_NETWORKS,
@@ -69,7 +68,6 @@ import {
6968
NodeClientErrorV0,
7069
NodeClientErrorV1,
7170
NodeCommandServerKeysResponse,
72-
NodeErrorV3,
7371
RejectedNodePromises,
7472
SendNodeCommand,
7573
SessionSigsMap,
@@ -82,6 +80,10 @@ import { composeLitUrl } from './endpoint-version';
8280
// eslint-disable-next-line @typescript-eslint/no-explicit-any
8381
type Listener = (...args: any[]) => void;
8482

83+
type providerTest<T> = (
84+
provider: ethers.providers.JsonRpcProvider
85+
) => Promise<T>;
86+
8587
interface CoreNodeConfig {
8688
subnetPubKey: string;
8789
networkPubKey: string;
@@ -119,8 +121,8 @@ export type LitNodeClientConfigWithDefaults = Required<
119121
const EPOCH_PROPAGATION_DELAY = 45_000;
120122
// This interval is responsible for keeping latest block hash up to date
121123
const BLOCKHASH_SYNC_INTERVAL = 30_000;
122-
// When fetching the blockhash from a provider (not lit), we use a previous block to avoid a nodes not knowing about the new block yet
123-
const BLOCKHASH_COUNT_PROVIDER_DELAY = -1;
124+
// When fetching the blockhash from a provider (not lit), we use a 5 minutes old block to ensure the nodes centralized indexer has it
125+
const BLOCKHASH_COUNT_PROVIDER_DELAY = -30; // 30 blocks ago. Eth block are mined every 12s. 30 blocks is 6 minutes, indexer/nodes must have it by now
124126

125127
// Intentionally not including datil-dev here per discussion with Howard
126128
const NETWORKS_REQUIRING_SEV: string[] = [
@@ -766,24 +768,31 @@ export class LitCore {
766768
};
767769
}
768770

769-
private _getProviderWithFallback =
770-
async (): Promise<ethers.providers.JsonRpcProvider | null> => {
771-
for (const url of FALLBACK_RPC_URLS) {
772-
try {
773-
const provider = new ethers.providers.JsonRpcProvider({
774-
url: url,
771+
private _getProviderWithFallback = async <T>(
772+
providerTest: providerTest<T>
773+
): Promise<{
774+
provider: ethers.providers.JsonRpcProvider;
775+
testResult: T;
776+
} | null> => {
777+
for (const url of FALLBACK_RPC_URLS) {
778+
try {
779+
const provider = new ethers.providers.JsonRpcProvider({
780+
url: url,
775781

776-
// https://docs.ethers.org/v5/api/utils/web/#ConnectionInfo
777-
timeout: 60000,
778-
});
779-
await provider.getBlockNumber(); // Simple check to see if the provider is working
780-
return provider;
781-
} catch (error) {
782-
logError(`RPC URL failed: ${url}`);
783-
}
782+
// https://docs.ethers.org/v5/api/utils/web/#ConnectionInfo
783+
timeout: 60000,
784+
});
785+
const testResult = await providerTest(provider); // Check to see if the provider is working
786+
return {
787+
provider,
788+
testResult,
789+
};
790+
} catch (error) {
791+
logError(`RPC URL failed: ${url}`);
784792
}
785-
return null;
786-
};
793+
}
794+
return null;
795+
};
787796

788797
/**
789798
* Fetches the latest block hash and log any errors that are returned
@@ -854,20 +863,20 @@ export class LitCore {
854863
log(
855864
'Attempting to fetch blockhash manually using ethers with fallback RPC URLs...'
856865
);
857-
const provider = await this._getProviderWithFallback();
866+
const { testResult } =
867+
(await this._getProviderWithFallback<ethers.providers.Block>(
868+
// We use a previous block to avoid nodes not having received the latest block yet
869+
(provider) => provider.getBlock(BLOCKHASH_COUNT_PROVIDER_DELAY)
870+
)) || {};
858871

859-
if (!provider) {
872+
if (!testResult || !testResult.hash) {
860873
logError('All fallback RPC URLs failed. Unable to retrieve blockhash.');
861874
return;
862875
}
863876

864877
try {
865-
// We use a previous block to avoid nodes not having received the latest block yet
866-
const priorBlock = await provider.getBlock(
867-
BLOCKHASH_COUNT_PROVIDER_DELAY
868-
);
869-
this.latestBlockhash = priorBlock.hash;
870-
this.lastBlockHashRetrieved = priorBlock.timestamp;
878+
this.latestBlockhash = testResult.hash;
879+
this.lastBlockHashRetrieved = testResult.timestamp;
871880
log(
872881
'Successfully retrieved blockhash manually: ',
873882
this.latestBlockhash

packages/event-listener/.babelrc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"presets": [
3+
[
4+
"@nx/web/babel",
5+
{
6+
"useBuiltIns": "usage"
7+
}
8+
]
9+
]
10+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"extends": ["../../.eslintrc.json"],
3+
"ignorePatterns": ["!**/*"],
4+
"overrides": [
5+
{
6+
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
7+
"rules": {}
8+
},
9+
{
10+
"files": ["*.ts", "*.tsx"],
11+
"rules": {}
12+
},
13+
{
14+
"files": ["*.js", "*.jsx"],
15+
"rules": {}
16+
}
17+
]
18+
}

0 commit comments

Comments
 (0)