Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: ChainType and LedgerType #452

Merged
merged 12 commits into from
Nov 15, 2024
24 changes: 12 additions & 12 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,9 @@ Creates a master wallet for given chain type. If a wallet already exists for a g
<details>
<summary>Request</summary>

```js
```json
{
"chain_type": ChainType,
"chain": Chain,
}
```

Expand Down Expand Up @@ -240,7 +240,7 @@ Creates a Gnosis safe for given chain type.

```js
{
"chain_type": ChainType,
"chain": Chain,
}
```

Expand Down Expand Up @@ -295,7 +295,7 @@ Returns the list of existing service configurations.
"env_variables": {...},
"hash": "bafybeidicxsruh3r4a2xarawzan6ocwyvpn3ofv42po5kxf7x6ck7kn22u",
"hash_history": {"1731487112": "bafybeidicxsruh3r4a2xarawzan6ocwyvpn3ofv42po5kxf7x6ck7kn22u"},
"home_chain_id": "100",
"home_chain": "gnosis",
"keys": [...],
"name": "valory/trader_omen_gnosis",
"service_config_id": "sc-85a7a12a-8c6b-46b8-919a-b8a3b8e3ad39",
Expand Down Expand Up @@ -324,7 +324,7 @@ Create a service configuration using a template.
"env_variables": {...},
"hash": "bafybeidicxsruh3r4a2xarawzan6ocwyvpn3ofv42po5kxf7x6ck7kn22u",
"image": "https://operate.olas.network/_next/image?url=%2Fimages%2Fprediction-agent.png&w=3840&q=75",
"home_chain_id": "100",
"home_chain": "gnosis",
"name": "valory/trader_omen_gnosis",
"service_version": "v0.18.4"
}
Expand All @@ -342,7 +342,7 @@ Create a service configuration using a template.
"env_variables": {...},
"hash": "bafybeidicxsruh3r4a2xarawzan6ocwyvpn3ofv42po5kxf7x6ck7kn22u",
"hash_history": {"1731487112": "bafybeidicxsruh3r4a2xarawzan6ocwyvpn3ofv42po5kxf7x6ck7kn22u"},
"home_chain_id": "100",
"home_chain": "gnosis",
"keys": [...],
"name": "valory/trader_omen_gnosis",
"service_config_id": "sc-85a7a12a-8c6b-46b8-919a-b8a3b8e3ad39",
Expand All @@ -369,7 +369,7 @@ Update all the service configurations whose Service Public ID match the Service
"env_variables": {...},
"hash": "bafybeibpseosblmaw6sk6zsnic2kfxfsijrnfluuhkwboyqhx7ma7zw2me",
"image": "https://operate.olas.network/_next/image?url=%2Fimages%2Fprediction-agent.png&w=3840&q=75",
"home_chain_id": "100",
"home_chain": "gnosis",
"name": "valory/trader_omen_gnosis",
"service_version": "v0.19.0"
}
Expand All @@ -390,7 +390,7 @@ The response contains an array of the services which have been updated (an empty
"env_variables": {...},
"hash": "bafybeidicxsruh3r4a2xarawzan6ocwyvpn3ofv42po5kxf7x6ck7kn22u",
"hash_history": {"1731487112": "bafybeidicxsruh3r4a2xarawzan6ocwyvpn3ofv42po5kxf7x6ck7kn22u", "1731490000": "bafybeibpseosblmaw6sk6zsnic2kfxfsijrnfluuhkwboyqhx7ma7zw2me"},
"home_chain_id": "100",
"home_chain": "gnosis",
"keys": [...],
"name": "valory/trader_omen_gnosis",
"service_config_id": "sc-85a7a12a-8c6b-46b8-919a-b8a3b8e3ad39",
Expand Down Expand Up @@ -451,7 +451,7 @@ Returns the service configuration `service_config_id`.
"env_variables": {...},
"hash": "bafybeidicxsruh3r4a2xarawzan6ocwyvpn3ofv42po5kxf7x6ck7kn22u",
"hash_history": {"1731487112": "bafybeidicxsruh3r4a2xarawzan6ocwyvpn3ofv42po5kxf7x6ck7kn22u"},
"home_chain_id": "100",
"home_chain": "gnosis",
"keys": [...],
"name": "valory/trader_omen_gnosis",
"service_config_id": "sc-85a7a12a-8c6b-46b8-919a-b8a3b8e3ad39",
Expand Down Expand Up @@ -498,7 +498,7 @@ The response contains the updated service configuration following the on-chain o
"env_variables": {...},
"hash": "bafybeidicxsruh3r4a2xarawzan6ocwyvpn3ofv42po5kxf7x6ck7kn22u",
"hash_history": {"1731487112": "bafybeidicxsruh3r4a2xarawzan6ocwyvpn3ofv42po5kxf7x6ck7kn22u"},
"home_chain_id": "100",
"home_chain": "gnosis",
"keys": [...],
"name": "valory/trader_omen_gnosis",
"service_config_id": "sc-85a7a12a-8c6b-46b8-919a-b8a3b8e3ad39",
Expand All @@ -525,7 +525,7 @@ Update service configuration `service_config_id` with the provided template.
"env_variables": {...},
"hash": "bafybeibpseosblmaw6sk6zsnic2kfxfsijrnfluuhkwboyqhx7ma7zw2me",
"image": "https://operate.olas.network/_next/image?url=%2Fimages%2Fprediction-agent.png&w=3840&q=75",
"home_chain_id": "100",
"home_chain": "gnosis",
"name": "valory/trader_omen_gnosis",
"service_version": "v0.19.0"
}
Expand All @@ -545,7 +545,7 @@ Update service configuration `service_config_id` with the provided template.
"env_variables": {...},
"hash": "bafybeidicxsruh3r4a2xarawzan6ocwyvpn3ofv42po5kxf7x6ck7kn22u",
"hash_history": {"1731487112": "bafybeidicxsruh3r4a2xarawzan6ocwyvpn3ofv42po5kxf7x6ck7kn22u", "1731490000": "bafybeibpseosblmaw6sk6zsnic2kfxfsijrnfluuhkwboyqhx7ma7zw2me"},
"home_chain_id": "100",
"home_chain": "gnosis",
"keys": [...],
"name": "valory/trader_omen_gnosis",
"service_config_id": "sc-85a7a12a-8c6b-46b8-919a-b8a3b8e3ad39",
Expand Down
14 changes: 7 additions & 7 deletions frontend/client/enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ export enum MiddlewareAction {
}

export enum MiddlewareChain {
ETHEREUM = 0,
GOERLI = 1,
GNOSIS = 2,
SOLANA = 3,
OPTIMISM = 4,
BASE = 5,
MODE = 6,
ETHEREUM = "ethereum",
GOERLI = "goerli",
GNOSIS = "gnosis",
SOLANA = "solana",
OPTIMISM = "optimism",
BASE = "base",
MODE = "mode",
}

export enum MiddlewareLedger {
Expand Down
7 changes: 3 additions & 4 deletions frontend/client/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export type ServiceKeys = {

export type LedgerConfig = {
rpc: string;
type: MiddlewareLedger;
chain: MiddlewareChain;
};

Expand Down Expand Up @@ -50,12 +49,12 @@ export type MiddlewareServiceResponse = {
hash_history: {
[block: string]: string;
};
home_chain_id: number;
home_chain: MiddlewareChain;
keys: ServiceKeys[];
service_path?: string;
version: string;
chain_configs: {
[chainId: number]: {
[chain in MiddlewareChain]: {
ledger_config: LedgerConfig;
chain_data: ChainData;
};
Expand All @@ -75,7 +74,7 @@ export type ServiceTemplate = {
description: string;
image: string;
service_version: string;
home_chain_id: string;
home_chain: string;
configurations: { [key: string]: ConfigurationTemplate };
env_variables: { [key: string]: EnvVariableAttributes };
deploy?: boolean;
Expand Down
14 changes: 9 additions & 5 deletions frontend/components/SetupPage/Create/SetupCreateSafe.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@ import { delayInSeconds } from '@/utils/delay';

const { Text } = Typography;

const capitalizedMiddlewareChainNames = {
[+MiddlewareChain.ETHEREUM]: 'Ethereum',
[+MiddlewareChain.BASE]: 'Base',
[+MiddlewareChain.OPTIMISM]: 'Optimism',
const capitalizedMiddlewareChainNames: { [key in MiddlewareChain]: string } = {
[MiddlewareChain.ETHEREUM]: 'Ethereum',
[MiddlewareChain.BASE]: 'Base',
[MiddlewareChain.OPTIMISM]: 'Optimism',
[MiddlewareChain.GOERLI]: 'Goerli',
[MiddlewareChain.GNOSIS]: 'Gnosis',
[MiddlewareChain.SOLANA]: 'Solana',
[MiddlewareChain.MODE]: 'Mode',
};

export const SetupCreateSafe = () => {
Expand Down Expand Up @@ -129,7 +133,7 @@ export const SetupCreateSafe = () => {

const safeCreationsRequired = Object.entries(chainsToCreateSafesFor).reduce(
(acc, [chain, safeAddressAlreadyExists]) => {
const middlewareChain = +chain as MiddlewareChain;
const middlewareChain = chain as MiddlewareChain;
if (safeAddressAlreadyExists) {
switch (middlewareChain) {
case MiddlewareChain.OPTIMISM:
Expand Down
6 changes: 3 additions & 3 deletions frontend/components/SetupPage/Create/SetupEoaFunding.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,11 @@ export const SetupEoaFunding = () => {
const { goto } = useSetup();
const { masterEoaAddress } = useWallet();
const [currentChain, setCurrentChain] = useState<MiddlewareChain>(
+Object.keys(eoaFundingMap)[0] as MiddlewareChain,
Object.keys(eoaFundingMap)[0] as MiddlewareChain,
);

const currentFundingMapObject =
eoaFundingMap[+currentChain as keyof typeof eoaFundingMap];
eoaFundingMap[currentChain as keyof typeof eoaFundingMap];

const getIsCurrentChainFunded = useCallback(
async (
Expand Down Expand Up @@ -218,7 +218,7 @@ export const SetupEoaFunding = () => {
if (nextChainExists) {
// goto next chain
setCurrentChain(
+Object.keys(eoaFundingMap)[indexOfCurrentChain + 1] as MiddlewareChain,
Object.keys(eoaFundingMap)[indexOfCurrentChain + 1] as MiddlewareChain,
);
return;
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/components/YourWalletPage/YourAgent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ const AgentTitle = () => {
const ServiceAndNftDetails = () => {
const { serviceId } = useServices();
const serviceAddress =
SERVICE_REGISTRY_L2_CONTRACT_ADDRESS[`${MiddlewareChain.OPTIMISM}`];
SERVICE_REGISTRY_L2_CONTRACT_ADDRESS[MiddlewareChain.OPTIMISM];

return (
<NftCard>
Expand Down
2 changes: 1 addition & 1 deletion frontend/config/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type ChainConfig = {
name: string;
currency: string;
chainId: number;
middlewareChain: number;
middlewareChain: MiddlewareChainId;
rpc: HttpUrl;
};

Expand Down
13 changes: 7 additions & 6 deletions frontend/constants/serviceTemplates.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ServiceTemplate, EnvProvisionType } from '@/client';
import { CHAIN_CONFIG } from '@/config/chains';
import { ChainId } from '@/enums/Chain';
import { StakingProgramId } from '@/enums/StakingProgram';

Expand All @@ -10,9 +11,9 @@ export const SERVICE_TEMPLATES: ServiceTemplate[] = [
image:
'https://operate.olas.network/_next/image?url=%2Fimages%2Fprediction-agent.png&w=3840&q=75',
service_version: 'v0.18.4',
home_chain_id: ChainId.Gnosis.toString(),
home_chain: CHAIN_CONFIG[ChainId.Gnosis].middlewareChain,
configurations: {
[ChainId.Optimism]: {
[CHAIN_CONFIG[ChainId.Optimism].middlewareChain]: {
staking_program_id: StakingProgramId.OptimusAlpha, // default, may be overwritten
nft: 'bafybeig64atqaladigoc3ds4arltdu63wkdrk3gesjfvnfdmz35amv7faq',
rpc: 'http://localhost:8545',
Expand Down Expand Up @@ -105,9 +106,9 @@ export const SERVICE_TEMPLATES: ServiceTemplate[] = [
// image:
// 'https://operate.olas.network/_next/image?url=%2Fimages%2Fprediction-agent.png&w=3840&q=75',
// service_version: 'v0.2.9',
// home_chain_id: `${CHAINS.OPTIMISM.chainId}`,
// home_chain: `${CHAINS.OPTIMISM}`,
// configurations: {
// [CHAINS.OPTIMISM.chainId]: {
// [CHAINS.OPTIMISM.middlewareChain]: {
// staking_program_id: StakingProgramId.OptimusAlpha, // default, may be overwritten
// nft: 'bafybeig64atqaladigoc3ds4arltdu63wkdrk3gesjfvnfdmz35amv7faq',
// // rpc: 'http://localhost:8545',
Expand All @@ -122,7 +123,7 @@ export const SERVICE_TEMPLATES: ServiceTemplate[] = [
// safe: 1000,
// },
// },
// [CHAINS.ETHEREUM.chainId]: {
// [CHAINS.ETHEREUM.middlewareChain]: {
// staking_program_id: StakingProgramId.OptimusAlpha, // default, may be overwritten
// nft: 'bafybeig64atqaladigoc3ds4arltdu63wkdrk3gesjfvnfdmz35amv7faq',
// // rpc: 'http://localhost:8545',
Expand All @@ -137,7 +138,7 @@ export const SERVICE_TEMPLATES: ServiceTemplate[] = [
// safe: 1000,
// },
// },
// [CHAINS.BASE.chainId]: {
// [CHAINS.BASE.middlewareChain]: {
// staking_program_id: StakingProgramId.OptimusAlpha, // default, may be overwritten
// nft: 'bafybeig64atqaladigoc3ds4arltdu63wkdrk3gesjfvnfdmz35amv7faq',
// // rpc: 'http://localhost:8545',
Expand Down
16 changes: 8 additions & 8 deletions frontend/context/BalanceProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export const BalanceContext = createContext<{
optimismBalance?: number;
}>({
isLoaded: false,
setIsLoaded: () => {},
setIsLoaded: () => { },
isBalanceLoaded: false,
olasBondBalance: undefined,
olasDepositBalance: undefined,
Expand All @@ -76,8 +76,8 @@ export const BalanceContext = createContext<{
walletBalances: {},
agentSafeBalance: undefined,
agentEoaBalance: undefined,
updateBalances: async () => {},
setIsPaused: () => {},
updateBalances: async () => { },
setIsPaused: () => { },
totalOlasStakedBalance: undefined,
baseBalance: undefined,
ethereumBalance: undefined,
Expand Down Expand Up @@ -171,7 +171,7 @@ export const BalanceProvider = ({ children }: PropsWithChildren) => {

// TODO: refactor to use ChainId enum, service from useService(),
const serviceId =
services?.[0]?.chain_configs[CHAIN_CONFIG.OPTIMISM.chainId].chain_data
services?.[0]?.chain_configs[CHAIN_CONFIG[ChainId.Optimism].middlewareChain].chain_data
.token;

if (!isNumber(serviceId)) {
Expand Down Expand Up @@ -232,7 +232,7 @@ export const BalanceProvider = ({ children }: PropsWithChildren) => {

const agentEoaAddress = useMemo(
() =>
services?.[0]?.chain_configs?.[CHAIN_CONFIG.OPTIMISM.chainId]?.chain_data
services?.[0]?.chain_configs?.[CHAIN_CONFIG[ChainId.Optimism].middlewareChain]?.chain_data
?.instances?.[0],
[services],
);
Expand All @@ -249,11 +249,11 @@ export const BalanceProvider = ({ children }: PropsWithChildren) => {

const agentSafeBalance = useMemo(
() =>
services?.[0]?.chain_configs[CHAIN_CONFIG.OPTIMISM.chainId].chain_data
services?.[0]?.chain_configs[CHAIN_CONFIG[ChainId.Optimism].middlewareChain].chain_data
?.multisig &&
walletBalances[
services[0].chain_configs[CHAIN_CONFIG.OPTIMISM.chainId].chain_data
.multisig!
services[0].chain_configs[CHAIN_CONFIG[ChainId.Optimism].middlewareChain].chain_data
.multisig!
],
[services, walletBalances],
);
Expand Down
7 changes: 4 additions & 3 deletions frontend/context/StakingContractInfoProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
DEFAULT_STAKING_PROGRAM_ID,
StakingProgramContext,
} from './StakingProgramProvider';
import { ChainId } from '@/enums/Chain';

type StakingContractInfoContextProps = {
activeStakingContractInfo?: Partial<StakingContractInfo>;
Expand All @@ -43,8 +44,8 @@ export const StakingContractInfoContext =
isStakingContractInfoRecordLoaded: false,
isActiveStakingContractInfoLoaded: false,
stakingContractInfoRecord: undefined,
updateActiveStakingContractInfo: async () => {},
setIsPaused: () => {},
updateActiveStakingContractInfo: async () => { },
setIsPaused: () => { },
});

export const StakingContractInfoProvider = ({
Expand All @@ -71,7 +72,7 @@ export const StakingContractInfoProvider = ({

const serviceId = useMemo(
() =>
services?.[0]?.chain_configs[CHAIN_CONFIG.OPTIMISM.chainId].chain_data?.token,
services?.[0]?.chain_configs[CHAIN_CONFIG[ChainId.Optimism].middlewareChain].chain_data?.token,
[services],
);

Expand Down
9 changes: 5 additions & 4 deletions frontend/context/StakingProgramProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { CHAIN_CONFIG } from '@/config/chains';
import { StakingProgramId } from '@/enums/StakingProgram';
import { useServices } from '@/hooks/useServices';
import { AutonolasService } from '@/service/Autonolas';
import { ChainId } from '@/enums/Chain';

export const INITIAL_DEFAULT_STAKING_PROGRAM_ID = StakingProgramId.Beta;

Expand All @@ -22,8 +23,8 @@ export const StakingProgramContext = createContext<{
}>({
activeStakingProgramId: undefined,
defaultStakingProgramId: INITIAL_DEFAULT_STAKING_PROGRAM_ID,
updateActiveStakingProgramId: async () => {},
setDefaultStakingProgramId: () => {},
updateActiveStakingProgramId: async () => { },
setDefaultStakingProgramId: () => { },
});

/** Determines the current active staking program, if any */
Expand All @@ -40,10 +41,10 @@ export const StakingProgramProvider = ({ children }: PropsWithChildren) => {
const updateActiveStakingProgramId = useCallback(async () => {
// if no service nft, not staked
const serviceId =
service?.chain_configs[CHAIN_CONFIG.OPTIMISM.chainId].chain_data?.token;
service?.chain_configs[CHAIN_CONFIG[ChainId.Optimism].middlewareChain].chain_data?.token;

if (
!service?.chain_configs[CHAIN_CONFIG.OPTIMISM.chainId].chain_data?.token
!service?.chain_configs[CHAIN_CONFIG[ChainId.Optimism].middlewareChain].chain_data?.token
) {
setActiveStakingProgramId(null);
return;
Expand Down
Loading
Loading