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

Feature/modius #574

Draft
wants to merge 34 commits into
base: fix/meme-staging
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
ca090f6
feat: add modius configs
Tanya-atatakai Dec 11, 2024
2acb3f2
feat: more constants and configs updates for modius
Tanya-atatakai Dec 11, 2024
4ff166a
fix: activity checker address
Tanya-atatakai Dec 11, 2024
0841c66
Update frontend/service/agents/Modius.ts
Tanya-atatakai Dec 11, 2024
d43f49e
feat: display modius on agent selection
Tanya-atatakai Dec 11, 2024
770ce64
chore: review fixes
Tanya-atatakai Dec 11, 2024
2acdb6c
feat: hide safe interaction for mode
Tanya-atatakai Dec 11, 2024
afdcf60
feat: add service template
Tanya-atatakai Dec 12, 2024
7021bd3
fix: env variables
Tanya-atatakai Dec 13, 2024
246e450
fix: provide operatingThresholds for modius
Tanya-atatakai Dec 18, 2024
64d249d
chore: update in envs and agent description
Tanya-atatakai Dec 18, 2024
ebd0d79
feat: add setup agent for Modius
Tanya-atatakai Dec 18, 2024
5f69d88
chore: review fixes
Tanya-atatakai Dec 18, 2024
15dee39
fix: import
Tanya-atatakai Dec 18, 2024
1fa178d
feat: support additional tokens required for initial funding
Tanya-atatakai Dec 19, 2024
ef0b3c9
Update frontend/components/MainPage/sections/AlertSections/LowFunds/F…
Tanya-atatakai Dec 19, 2024
05b0164
feat: extend manage wallet with erc20 tokens
Tanya-atatakai Dec 19, 2024
13b2fde
Merge pull request #626 from valory-xyz/tanya/modius-manage-wallet
Tanya-atatakai Dec 23, 2024
ffa5658
Feat: Support ERC20 in funding job
OjusWiZard Dec 24, 2024
54a1e73
style: fix CI lint checks
OjusWiZard Dec 24, 2024
65ceeb3
Merge pull request #630 from valory-xyz/feat/erc20-funding
OjusWiZard Dec 24, 2024
92bde1f
chore: resolve conflicts
Tanya-atatakai Dec 26, 2024
ccd8b9e
fix: modius service template environment variables
OjusWiZard Dec 26, 2024
afefe1d
feat: support computed env-vars for modius
OjusWiZard Dec 26, 2024
afb79a1
Merge pull request #632 from valory-xyz/fix/modius-middleware
OjusWiZard Dec 26, 2024
45e2b6d
fix: a small bug in agents other than modius
OjusWiZard Dec 26, 2024
ef38a1e
feat: support funds by chain
Tanya-atatakai Dec 27, 2024
911909f
Merge pull request #631 from valory-xyz/tanya/modius-transfer
Tanya-atatakai Dec 27, 2024
4b20895
fix: service is not deployed after creating
Tanya-atatakai Dec 27, 2024
14f8def
chore: change staking contract
Tanya-atatakai Dec 27, 2024
b5b4b97
Merge branch 'fix/meme-staging' of github.com:valory-xyz/olas-operate…
Tanya-atatakai Dec 27, 2024
176fd1d
release: 0.2.0-rc63
Tanya-atatakai Dec 27, 2024
6305d95
chore: update dev rpc for mode
Tanya-atatakai Dec 27, 2024
2ed70be
fix: modius env-var `SAFE_CONTRACT_ADDRESSES`
OjusWiZard Dec 27, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ DEV_RPC=
GNOSIS_RPC=
ETHEREUM_RPC=
OPTIMISM_RPC=
BASE_RPC=
BASE_RPC=
MODE_RPC=
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ jobs:
BASE_RPC: https://virtual.base.rpc.tenderly.co/2a91611a-3251-48a6-8095-b86815de84bf
GNOSIS_RPC: https://virtual.gnosis.rpc.tenderly.co/7de511da-9ad7-4e9f-98c1-e99052e92b15
ETHEREUM_RPC: https://rpc-gate.autonolas.tech/ethereum-rpc/
MODE_RPC: https://mainnet.mode.network
MODE_RPC: https://virtual.mode.rpc.tenderly.co/9f5ab06c-f005-4f8d-8bb2-786cb7b8f865

# Run the build and notarization process for production
- name: Build, notarize, and publish (Production)
Expand Down Expand Up @@ -282,11 +282,11 @@ jobs:
BASE_RPC: https://virtual.base.rpc.tenderly.co/2a91611a-3251-48a6-8095-b86815de84bf
GNOSIS_RPC: https://virtual.gnosis.rpc.tenderly.co/7de511da-9ad7-4e9f-98c1-e99052e92b15
ETHEREUM_RPC: https://rpc-gate.autonolas.tech/ethereum-rpc/
MODE_RPC: https://mainnet.mode.network
MODE_RPC: https://virtual.mode.rpc.tenderly.co/9f5ab06c-f005-4f8d-8bb2-786cb7b8f865
run: |
echo "OPTIMISM_RPC=https://rpc-gate.autonolas.tech/optimism-rpc/" >> .env
echo "BASE_RPC=https://virtual.base.rpc.tenderly.co/2a91611a-3251-48a6-8095-b86815de84bf" >> .env
echo "GNOSIS_RPC=https://virtual.gnosis.rpc.tenderly.co/7de511da-9ad7-4e9f-98c1-e99052e92b15" >> .env
echo "ETHEREUM_RPC=https://rpc-gate.autonolas.tech/ethereum-rpc/" >> .env
echo "MODE_RPC=https://mainnet.mode.network" >> .env
echo "MODE_RPC=https://virtual.mode.rpc.tenderly.co/9f5ab06c-f005-4f8d-8bb2-786cb7b8f865" >> .env
node build.js
2 changes: 1 addition & 1 deletion .github/workflows/release_win.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
BASE_RPC: "https://virtual.base.rpc.tenderly.co/2a91611a-3251-48a6-8095-b86815de84bf"
GNOSIS_RPC: "https://virtual.gnosis.rpc.tenderly.co/7de511da-9ad7-4e9f-98c1-e99052e92b15"
ETHEREUM_RPC: "https://rpc-gate.autonolas.tech/ethereum-rpc/"
MODE_RPC: "https://mainnet.mode.network"
MODE_RPC: "https://virtual.mode.rpc.tenderly.co/9f5ab06c-f005-4f8d-8bb2-786cb7b8f865"
arch: "x64"
defaults:
run:
Expand Down
1 change: 1 addition & 0 deletions electron/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const schema = {
// Each agent has its own settings
trader: { type: 'object', default: defaultInitialAgentSettings },
memeooorr: { type: 'object', default: defaultInitialAgentSettings },
modius: { type: 'object', default: defaultInitialAgentSettings },
};

/**
Expand Down
8 changes: 5 additions & 3 deletions frontend/client/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ export type ChainData = {
agent_id: number;
cost_of_bond: number;
fund_requirements: {
agent: number;
safe: number;
[tokenAddress: string]: {
agent: number;
safe: number;
};
};
nft: string;
staking_program_id: StakingProgramId;
Expand Down Expand Up @@ -95,7 +97,7 @@ export type ConfigurationTemplate = {
use_mech_marketplace?: boolean;
cost_of_bond: number;
monthly_gas_estimate: number;
fund_requirements: FundRequirementsTemplate;
fund_requirements: { [tokenAddress: string]: FundRequirementsTemplate };
};

export type FundRequirementsTemplate = {
Expand Down
5 changes: 3 additions & 2 deletions frontend/components/AgentSelection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,9 @@ const EachAgent = memo(
}

// Neither service nor safe is created
if (agentType === AgentType.Memeooorr) {
// if the selected type is Memeooorr - should set up the agent first
if (agentType === AgentType.Memeooorr || agentType === AgentType.Modius) {
// if the selected type requires setting up an agent - should redirect to SetupYourAgent first
// TODO: can have this as a boolean flag in agentConfig?
gotoPage(Pages.Setup);
gotoSetup(SetupScreen.SetupYourAgent);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
} from '@/hooks/useBalanceContext';
import { useElectronApi } from '@/hooks/useElectronApi';
import { MultisigOwners, useMultisigs } from '@/hooks/useMultisig';
import { useNeedsFunds } from '@/hooks/useNeedsFunds';
import { usePageState } from '@/hooks/usePageState';
import { useService } from '@/hooks/useService';
import { useServices } from '@/hooks/useServices';
Expand All @@ -31,15 +32,13 @@ import {
useStakingContractContext,
} from '@/hooks/useStakingContractDetails';
import { useStakingProgram } from '@/hooks/useStakingProgram';
import { useStore } from '@/hooks/useStore';
import { useMasterWalletContext } from '@/hooks/useWallet';
import { ServicesService } from '@/service/Services';
import { WalletService } from '@/service/Wallet';
import { AgentConfig } from '@/types/Agent';
import { delayInSeconds } from '@/utils/delay';

const useServiceDeployment = () => {
const { storeState } = useStore();
const { showNotification } = useElectronApi();

const { goto: gotoPage } = usePageState();
Expand Down Expand Up @@ -80,8 +79,7 @@ const useServiceDeployment = () => {
(balance) => balance.evmChainId === selectedAgentConfig.evmHomeChainId,
)?.balance;

const { masterSafeBalances, masterSafeNativeGasBalance } =
useMasterBalances();
const { masterSafeNativeGasBalance } = useMasterBalances();

const {
isAllStakingContractDetailsRecordLoaded,
Expand All @@ -98,6 +96,10 @@ const useServiceDeployment = () => {

const { masterSafesOwners } = useMultisigs(masterSafes);

const { isInitialFunded, needsInitialFunding } = useNeedsFunds(
selectedStakingProgramId,
);

const requiredStakedOlas =
selectedStakingProgramId &&
STAKING_PROGRAMS[selectedAgentConfig.evmHomeChainId][
Expand Down Expand Up @@ -128,13 +130,6 @@ const useServiceDeployment = () => {
return false;
}

const masterSafeOlasBalance = masterSafeBalances?.find(
(walletBalanceResult) =>
walletBalanceResult.symbol === TokenSymbol.OLAS &&
walletBalanceResult.evmChainId === selectedAgentConfig.evmHomeChainId,
)?.balance;

const isInitialFunded = storeState?.[selectedAgentType]?.isInitialFunded;
if (service && isInitialFunded && isServiceStaked) {
return (serviceTotalStakedOlas ?? 0) >= requiredStakedOlas;
}
Expand All @@ -160,36 +155,25 @@ const useServiceDeployment = () => {
}

// SERVICE IS NOT STAKED AND/OR IS STARTING FOR THE FIRST TIME
const totalOlasStakedAndInSafes = sum([
serviceOlasBalanceOnHomeChain,
serviceTotalStakedOlas,
masterSafeOlasBalance,
]);

const hasEnoughForInitialDeployment =
(totalOlasStakedAndInSafes ?? 0) >= requiredStakedOlas &&
(masterSafeNativeGasBalance ?? 0) >= safeThreshold;

return hasEnoughForInitialDeployment;
// Check if it has enough initial funding
return !needsInitialFunding;
}, [
isServicesLoading,
isServiceRunning,
isAllStakingContractDetailsRecordLoaded,
requiredStakedOlas,
hasEnoughServiceSlots,
isServiceStaked,
masterSafeBalances,
service,
storeState,
selectedAgentType,
isInitialFunded,
isAgentEvicted,
isEligibleForStaking,
selectedAgentConfig.operatingThresholds,
selectedAgentConfig.evmHomeChainId,
serviceOlasBalanceOnHomeChain,
needsInitialFunding,
serviceTotalStakedOlas,
masterSafeNativeGasBalance,
serviceSafeOlasWithStaked,
masterSafeNativeGasBalance,
]);

const pauseAllPolling = useCallback(() => {
Expand Down Expand Up @@ -362,7 +346,7 @@ const useServiceDeployment = () => {
selectedAgentType,
]);

const buttonText = `Start agent ${service ? '' : '& stake'}`;
const buttonText = `Start agent ${isServiceStaked ? '' : '& stake'}`;

return { isDeployable, handleStart, buttonText };
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const EmptyFunds = () => {
<InlineBanner text="Your safe address" address={masterEoaAddress} />
)}
<PurpleDivider />
<FundsToActivate stakingFundsRequired otherFundsRequired />
<FundsToActivate stakingFundsRequired nativeFundsRequired />
</Flex>
}
type="primary"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,20 @@ const { Text } = Typography;

type FundsToActivateProps = {
stakingFundsRequired: boolean;
otherFundsRequired: boolean;
nativeFundsRequired: boolean;
additionalFundsRequired?: boolean;
};

const FUNDS_REQUIRED_FOR_BY_AGENT_TYPE = {
[AgentType.PredictTrader]: 'for trading',
[AgentType.Memeooorr]: 'for agent operations',
[AgentType.Modius]: 'minimum for investment',
};

export const FundsToActivate = ({
stakingFundsRequired = true,
otherFundsRequired = true,
nativeFundsRequired = true,
additionalFundsRequired = true,
}: FundsToActivateProps) => {
const { selectedStakingProgramId } = useStakingProgram();

Expand All @@ -39,16 +42,38 @@ export const FundsToActivate = ({

// Calculate the required OLAS
const olasRequired = useMemo(() => {
if (!serviceFundRequirements[homeChainId]) return;

const olas = serviceFundRequirements[homeChainId][TokenSymbol.OLAS];
return `${UNICODE_SYMBOLS.OLAS}${olas} OLAS `;
}, [homeChainId, serviceFundRequirements]);

// Calculate the required native token (Eg. ETH)
const nativeTokenRequired = useMemo(() => {
if (!serviceFundRequirements[homeChainId]) return;

const native = serviceFundRequirements[homeChainId][nativeTokenSymbol];
return `${native} ${nativeTokenSymbol}`;
}, [homeChainId, serviceFundRequirements, nativeTokenSymbol]);

// Calculate additional tokens requirements (Eg. USDC)
const additionalTokensRequired = useMemo(() => {
if (!serviceFundRequirements[homeChainId]) return [];

const additionalTokens = Object.keys(
serviceFundRequirements[homeChainId],
).filter(
(token) => token !== TokenSymbol.OLAS && token !== nativeTokenSymbol,
);

if (additionalTokens.length === 0) return [];

return additionalTokens.map((tokenSymbol) => {
const token = serviceFundRequirements[homeChainId]?.[tokenSymbol];
return `${token} ${tokenSymbol}`;
});
}, [homeChainId, serviceFundRequirements, nativeTokenSymbol]);

return (
<>
<Text>
Expand All @@ -63,12 +88,20 @@ export const FundsToActivate = ({
staking.
</div>
)}
{otherFundsRequired && (
{nativeFundsRequired && (
<div>
{UNICODE_SYMBOLS.BULLET} <Text strong>{nativeTokenRequired}</Text> -
{` ${FUNDS_REQUIRED_FOR_BY_AGENT_TYPE[selectedAgentType]}.`}
</div>
)}

{additionalFundsRequired &&
additionalTokensRequired.map((additionalToken) => (
<div key={additionalToken}>
{UNICODE_SYMBOLS.BULLET} <Text strong>{additionalToken}</Text> -
{` ${FUNDS_REQUIRED_FOR_BY_AGENT_TYPE[selectedAgentType]}.`}
</div>
))}
</Flex>

{masterSafeAddress && (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { round } from 'lodash';
import { useMemo } from 'react';

import { getNativeTokenSymbol } from '@/config/tokens';
import { TokenSymbol } from '@/enums/Token';
import { WalletType } from '@/enums/Wallet';
import { useMasterBalances } from '@/hooks/useBalanceContext';
import { useNeedsFunds } from '@/hooks/useNeedsFunds';
Expand All @@ -22,8 +24,9 @@ export const LowFunds = () => {
masterSafeNativeGasBalance,
} = useMasterBalances();

const { nativeBalancesByChain, olasBalancesByChain, isInitialFunded } =
useNeedsFunds(selectedStakingProgramId);
const { balancesByChain, isInitialFunded } = useNeedsFunds(
selectedStakingProgramId,
);
const { tokenSymbol, masterThresholds } = useLowFundsDetails();

const chainId = selectedAgentConfig.evmHomeChainId;
Expand All @@ -50,15 +53,14 @@ export const LowFunds = () => {
// Show the empty funds alert if the agent is not funded
const isEmptyFundsVisible = useMemo(() => {
if (!isBalanceLoaded) return false;
if (!olasBalancesByChain) return false;
if (!nativeBalancesByChain) return false;
if (!balancesByChain) return false;

// If the agent is not funded, <MainNeedsFunds /> will be displayed
if (!isInitialFunded) return false;

if (
round(nativeBalancesByChain[chainId], 2) === 0 &&
round(olasBalancesByChain[chainId], 2) === 0 &&
round(balancesByChain[chainId][getNativeTokenSymbol(chainId)], 2) === 0 &&
round(balancesByChain[chainId][TokenSymbol.OLAS], 2) === 0 &&
isSafeSignerBalanceLow
) {
return true;
Expand All @@ -69,8 +71,7 @@ export const LowFunds = () => {
isBalanceLoaded,
isInitialFunded,
chainId,
nativeBalancesByChain,
olasBalancesByChain,
balancesByChain,
isSafeSignerBalanceLow,
]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const MainNeedsFunds = () => {
const {
hasEnoughEthForInitialFunding,
hasEnoughOlasForInitialFunding,
hasEnoughAdditionalTokensForInitialFunding,
isInitialFunded,
needsInitialFunding,
} = useNeedsFunds(selectedStakingProgramId);
Expand All @@ -28,6 +29,7 @@ export const MainNeedsFunds = () => {
if (
hasEnoughEthForInitialFunding &&
hasEnoughOlasForInitialFunding &&
hasEnoughAdditionalTokensForInitialFunding &&
!isInitialFunded
) {
electronApi.store?.set?.(`${selectedAgentType}.isInitialFunded`, true);
Expand All @@ -37,6 +39,7 @@ export const MainNeedsFunds = () => {
selectedAgentType,
hasEnoughEthForInitialFunding,
hasEnoughOlasForInitialFunding,
hasEnoughAdditionalTokensForInitialFunding,
isInitialFunded,
]);

Expand All @@ -54,7 +57,10 @@ export const MainNeedsFunds = () => {

<FundsToActivate
stakingFundsRequired={!hasEnoughOlasForInitialFunding}
otherFundsRequired={!hasEnoughEthForInitialFunding}
nativeFundsRequired={!hasEnoughEthForInitialFunding}
additionalFundsRequired={
!hasEnoughAdditionalTokensForInitialFunding
}
/>
</Flex>
}
Expand Down
Loading