Skip to content

Commit

Permalink
Merge branch 'master' into feature/drel-378-tg-osmosis-team-facing-is…
Browse files Browse the repository at this point in the history
…sues-with-sdk-utility-method
  • Loading branch information
Ansonhkg authored Dec 23, 2024
2 parents 10cf10b + 5fd2674 commit 5116b9d
Show file tree
Hide file tree
Showing 61 changed files with 3,712 additions and 43 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"@cosmjs/proto-signing": "0.30.1",
"@cosmjs/stargate": "0.30.1",
"@dotenvx/dotenvx": "^1.6.4",
"@lit-protocol/accs-schemas": "^0.0.20",
"@lit-protocol/accs-schemas": "^0.0.22",
"@lit-protocol/contracts": "^0.0.74",
"@metamask/eth-sig-util": "5.0.2",
"@mysten/sui.js": "^0.37.1",
Expand Down Expand Up @@ -85,6 +85,7 @@
"@nx/web": "17.3.0",
"@solana/web3.js": "1.95.3",
"@types/depd": "^1.1.36",
"@types/events": "^3.0.3",
"@types/jest": "27.4.1",
"@types/node": "18.19.18",
"@types/secp256k1": "^4.0.6",
Expand Down
46 changes: 45 additions & 1 deletion packages/constants/src/lib/constants/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export const LIT_CHAINS: LITChain<LITEVMChain> = {
name: 'Arbitrum Sepolia',
symbol: 'ETH',
decimals: 18,
rpcUrls: ['https://arbitrum-sepolia.blockpi.network/v1/rpc/public'],
rpcUrls: ['https://sepolia-rollup.arbitrum.io/rpc'],
blockExplorerUrls: ['https://sepolia.arbiscan.io/'],
type: null,
vmType: 'EVM',
Expand Down Expand Up @@ -358,6 +358,17 @@ export const LIT_CHAINS: LITChain<LITEVMChain> = {
type: null,
vmType: 'EVM',
},
filecoinCalibrationTestnet: {
contractAddress: null,
chainId: 314159,
name: 'Filecoin Calibration Testnet',
symbol: 'tFIL',
decimals: 18,
rpcUrls: ['https://api.calibration.node.glif.io/rpc/v1'],
blockExplorerUrls: ['https://calibration.filscan.io/'],
type: null,
vmType: 'EVM',
},
hyperspace: {
contractAddress: null,
chainId: 3141,
Expand Down Expand Up @@ -879,6 +890,39 @@ export const LIT_CHAINS: LITChain<LITEVMChain> = {
type: null,
vmType: 'EVM',
},
coreDao: {
contractAddress: null,
chainId: 1116,
name: 'Core DAO',
symbol: 'CORE',
decimals: 18,
rpcUrls: ['https://rpc.coredao.org'],
blockExplorerUrls: ['https://scan.coredao.org/'],
type: null,
vmType: 'EVM',
},
zkCandySepoliaTestnet: {
contractAddress: null,
chainId: 302,
name: 'ZKcandy Sepolia Testnet',
symbol: 'ETH',
decimals: 18,
rpcUrls: ['https://sepolia.rpc.zkcandy.io'],
blockExplorerUrls: ['https://sepolia.explorer.zkcandy.io'],
type: null,
vmType: 'EVM',
},
vana: {
contractAddress: null,
chainId: 1480,
name: 'Vana',
symbol: 'VANA',
decimals: 18,
rpcUrls: ['https://rpc.vana.org'],
blockExplorerUrls: ['https://vanascan.io'],
type: null,
vmType: 'EVM',
},
};

/**
Expand Down
6 changes: 6 additions & 0 deletions packages/constants/src/lib/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,11 @@ export const LIT_ERROR: Record<string, ErrorConfig> = {
code: 'transaction_error',
kind: LitErrorKind.Unexpected,
},
AUTOMATION_ERROR: {
name: 'AutomationError',
code: 'automation_error',
kind: LitErrorKind.Unexpected,
},
};

export const LIT_ERROR_CODE = {
Expand Down Expand Up @@ -292,6 +297,7 @@ const MultiError = VError.MultiError;
export { MultiError };

export const {
AutomationError,
InitError,
InvalidAccessControlConditions,
InvalidArgumentException,
Expand Down
22 changes: 17 additions & 5 deletions packages/core/src/lib/lit-core.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,21 @@ describe('LitCore', () => {
timestamp: currentTime,
}),
};
// eslint-disable-next-line @typescript-eslint/no-explicit-any
jest.spyOn(core as any, '_getProviderWithFallback').mockResolvedValue({
...mockProvider,
provider: mockProvider,
testResult: {
hash: mockBlockhash,
number: 12345,
timestamp: currentTime,
},
});

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

// Assert
expect(fetch).toHaveBeenCalledWith(mockBlockhashUrl);
expect(mockProvider.getBlock).toHaveBeenCalledWith(-1); // safety margin
expect(result).toBe(mockBlockhash);
});

Expand All @@ -132,16 +137,21 @@ describe('LitCore', () => {
timestamp: currentTime,
}),
};
// eslint-disable-next-line @typescript-eslint/no-explicit-any
jest.spyOn(core as any, '_getProviderWithFallback').mockResolvedValue({
...mockProvider,
provider: mockProvider,
testResult: {
hash: mockBlockhash,
number: 12345,
timestamp: currentTime,
},
});

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

// Assert
expect(fetch).toHaveBeenCalledWith(mockBlockhashUrl);
expect(mockProvider.getBlock).toHaveBeenCalledWith(-1); // safety margin
expect(result).toBe(mockBlockhash);
});

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

// eslint-disable-next-line @typescript-eslint/no-explicit-any
jest.spyOn(core as any, '_getProviderWithFallback').mockResolvedValue({
...mockProvider,
provider: mockProvider,
testResult: null,
});

// Execute & Assert
Expand Down
65 changes: 37 additions & 28 deletions packages/core/src/lib/lit-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {
LIT_CURVE,
LIT_CURVE_VALUES,
LIT_ENDPOINT,
LIT_ERROR,
LIT_ERROR_CODE,
LIT_NETWORK,
LIT_NETWORKS,
Expand Down Expand Up @@ -69,7 +68,6 @@ import {
NodeClientErrorV0,
NodeClientErrorV1,
NodeCommandServerKeysResponse,
NodeErrorV3,
RejectedNodePromises,
SendNodeCommand,
SessionSigsMap,
Expand All @@ -82,6 +80,10 @@ import { composeLitUrl } from './endpoint-version';
// eslint-disable-next-line @typescript-eslint/no-explicit-any
type Listener = (...args: any[]) => void;

type providerTest<T> = (
provider: ethers.providers.JsonRpcProvider
) => Promise<T>;

interface CoreNodeConfig {
subnetPubKey: string;
networkPubKey: string;
Expand Down Expand Up @@ -119,8 +121,8 @@ export type LitNodeClientConfigWithDefaults = Required<
const EPOCH_PROPAGATION_DELAY = 45_000;
// This interval is responsible for keeping latest block hash up to date
const BLOCKHASH_SYNC_INTERVAL = 30_000;
// 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
const BLOCKHASH_COUNT_PROVIDER_DELAY = -1;
// When fetching the blockhash from a provider (not lit), we use a 5 minutes old block to ensure the nodes centralized indexer has it
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

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

private _getProviderWithFallback =
async (): Promise<ethers.providers.JsonRpcProvider | null> => {
for (const url of FALLBACK_RPC_URLS) {
try {
const provider = new ethers.providers.JsonRpcProvider({
url: url,
private _getProviderWithFallback = async <T>(
providerTest: providerTest<T>
): Promise<{
provider: ethers.providers.JsonRpcProvider;
testResult: T;
} | null> => {
for (const url of FALLBACK_RPC_URLS) {
try {
const provider = new ethers.providers.JsonRpcProvider({
url: url,

// https://docs.ethers.org/v5/api/utils/web/#ConnectionInfo
timeout: 60000,
});
await provider.getBlockNumber(); // Simple check to see if the provider is working
return provider;
} catch (error) {
logError(`RPC URL failed: ${url}`);
}
// https://docs.ethers.org/v5/api/utils/web/#ConnectionInfo
timeout: 60000,
});
const testResult = await providerTest(provider); // Check to see if the provider is working
return {
provider,
testResult,
};
} catch (error) {
logError(`RPC URL failed: ${url}`);
}
return null;
};
}
return null;
};

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

if (!provider) {
if (!testResult || !testResult.hash) {
logError('All fallback RPC URLs failed. Unable to retrieve blockhash.');
return;
}

try {
// We use a previous block to avoid nodes not having received the latest block yet
const priorBlock = await provider.getBlock(
BLOCKHASH_COUNT_PROVIDER_DELAY
);
this.latestBlockhash = priorBlock.hash;
this.lastBlockHashRetrieved = priorBlock.timestamp;
this.latestBlockhash = testResult.hash;
this.lastBlockHashRetrieved = testResult.timestamp;
log(
'Successfully retrieved blockhash manually: ',
this.latestBlockhash
Expand Down
10 changes: 10 additions & 0 deletions packages/event-listener/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"presets": [
[
"@nx/web/babel",
{
"useBuiltIns": "usage"
}
]
]
}
18 changes: 18 additions & 0 deletions packages/event-listener/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
Loading

0 comments on commit 5116b9d

Please sign in to comment.