Skip to content

Commit

Permalink
define chain constants
Browse files Browse the repository at this point in the history
  • Loading branch information
HananINouman committed Aug 25, 2024
1 parent a5509ef commit 8aa0568
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 26 deletions.
22 changes: 22 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { type TypedMessage } from '@metamask/eth-sig-util';
import { type TypedDataDomain } from 'ethers';
import * as pjson from '../package.json';
import { FORK_MAPPING } from './types';

export const CONFLICT_ERROR_MSG = 'Conflict';

Expand Down Expand Up @@ -136,3 +137,24 @@ export const TERMS_AND_CONDITIONS_URL =
: `https://obol.org/${TERMS_AND_CONDITIONS_VERSION as number}/terms.pdf`;
export const TERMS_AND_CONDITIONS_HASH =
'0xd33721644e8f3afab1495a74abe3523cec12d48b8da6cb760972492ca3f1a273';

export const AVAILABLE_SPLITTER_CHAINS = [FORK_MAPPING["0x00000000"], FORK_MAPPING["0x01017000"]];

export const CHAIN_CONFIGURATION = {
[AVAILABLE_SPLITTER_CHAINS[0]]: {

SPLITMAIN_ADDRESS: "0xfC8a305728051367797DADE6Aa0344E0987f5286",
MULTICALL_ADDRESS: "0xcA11bde05977b3631167028862bE2a173976CA11",
OWR_FACTORY_ADDRESS: "0xc0961353fcc43a99e3041db07ac646720e116256",
RETROACTIVE_FUNDING_ADDRESS: "0x43F641fA70e09f0326ac66b4Ef0C416EaEcBC6f5"

},
[AVAILABLE_SPLITTER_CHAINS[1]]: {
SPLITMAIN_ADDRESS: "0xfC8a305728051367797DADE6Aa0344E0987f5286",
MULTICALL_ADDRESS: "0xcA11bde05977b3631167028862bE2a173976CA11",
OWR_FACTORY_ADDRESS: "0xc0961353fcc43a99e3041db07ac646720e116256",
RETROACTIVE_FUNDING_ADDRESS: "0x43F641fA70e09f0326ac66b4Ef0C416EaEcBC6f5"

},
}

19 changes: 12 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {
TermsAndConditionsSigningTypes,
DEFAULT_BASE_VERSION,
TERMS_AND_CONDITIONS_HASH,
AVAILABLE_SPLITTER_CHAINS,
CHAIN_CONFIGURATION,
} from './constants.js';
import { ConflictError } from './errors.js';
import {
Expand All @@ -26,7 +28,7 @@ import {
import { clusterConfigOrDefinitionHash } from './verification/common.js';
import { validatePayload } from './ajv.js';
import { definitionSchema, operatorPayloadSchema } from './schema.js';
import { formatSplitRecipients, handleDeployRewardsSplitter, MULTICALL_ADDRESS, OWR_FACTORY_ADDRESS, predictSplitterAddress, RETROACTIVE_FUNDING_ADDRESS, RETROACTIVE_FUNDING_SPLIT, SPLITMAIN_ADDRESS } from './splitHelpers.js';
import { formatSplitRecipients, handleDeployRewardsSplitter, predictSplitterAddress, RETROACTIVE_FUNDING_SPLIT } from './splitHelpers.js';
import { isContractAvailable } from './utils.js';
export * from './types.js';
export * from './services.js';
Expand Down Expand Up @@ -114,20 +116,23 @@ export class Client extends Base {
}

//Check if we allow splitters on this chainId
if (!AVAILABLE_SPLITTER_CHAINS.includes(this.chainId)) {
throw new Error(`Splitter configuration is not supported on ${this.chainId} chain`);
}

//Double check the deployed addresses (not sure if needed)
const checkSplitMainAddress = await isContractAvailable(
SPLITMAIN_ADDRESS,
CHAIN_CONFIGURATION[this.chainId].SPLITMAIN_ADDRESS,
this.signer.provider as Provider,
);

const checkMulticallAddress = await isContractAvailable(
MULTICALL_ADDRESS,
CHAIN_CONFIGURATION[this.chainId].MULTICALL_ADDRESS,
this.signer.provider as Provider,
);

const checkOWRFactoryAddress = await isContractAvailable(
OWR_FACTORY_ADDRESS,
CHAIN_CONFIGURATION[this.chainId].OWR_FACTORY_ADDRESS,
this.signer.provider as Provider,
);

Expand All @@ -140,17 +145,17 @@ export class Client extends Base {
throw new Error('Something isn not working as expected, check this issue with obol-sdk team');
}

const retroActiveFundingRecipient = { account: RETROACTIVE_FUNDING_ADDRESS, percentAllocation: RETROACTIVE_FUNDING_SPLIT }
const retroActiveFundingRecipient = { account: CHAIN_CONFIGURATION[this.chainId].RETROACTIVE_FUNDING_ADDRESS, percentAllocation: RETROACTIVE_FUNDING_SPLIT }

splitRecipients.push(retroActiveFundingRecipient)

const { accounts, percentAllocations } = formatSplitRecipients(splitRecipients)
const predictedSplitterAddress = await predictSplitterAddress({ signer: this.signer, accounts, percentAllocations });
const predictedSplitterAddress = await predictSplitterAddress({ signer: this.signer, accounts, percentAllocations, chainId:this.chainId });
const isSplitterDeployed = await isContractAvailable(
predictedSplitterAddress,
this.signer.provider as Provider,
);
const { withdrawal_address, fee_recipient_address } = await handleDeployRewardsSplitter({ signer: this.signer, isSplitterDeployed: !!isSplitterDeployed, predictedSplitterAddress, accounts, percentAllocations, principalRecipient, validatorsSize })
const { withdrawal_address, fee_recipient_address } = await handleDeployRewardsSplitter({ signer: this.signer, isSplitterDeployed: !!isSplitterDeployed, predictedSplitterAddress, accounts, percentAllocations, principalRecipient, validatorsSize, chainId:this.chainId })

return { withdrawal_address, fee_recipient_address }

Expand Down
35 changes: 19 additions & 16 deletions src/splitHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,12 @@ import { Contract, Interface, parseEther, Signer } from "ethers";
import { OWRFactoryContract } from "./abi/OWR";
import { splitMainEthereumAbi } from "./abi/SplitMain";
import { MultiCallContract } from "./abi/Multicall"
import { CHAIN_CONFIGURATION } from "./constants";

const splitMainContractInterface = new Interface(splitMainEthereumAbi);
const owrFactoryContractInterface = new Interface(OWRFactoryContract.abi);



//Define them in constants and map them to each chainId
export const SPLITMAIN_ADDRESS = "0xfC8a305728051367797DADE6Aa0344E0987f5286";
export const MULTICALL_ADDRESS = "0xcA11bde05977b3631167028862bE2a173976CA11";
export const OWR_FACTORY_ADDRESS = "0xc0961353fcc43a99e3041db07ac646720e116256"
export const RETROACTIVE_FUNDING_ADDRESS = "0x43F641fA70e09f0326ac66b4Ef0C416EaEcBC6f5"

export const RETROACTIVE_FUNDING_SPLIT = 1

Expand Down Expand Up @@ -59,10 +54,10 @@ export const formatSplitRecipients = (recipients: SplitRecipient[]): { accounts:
}


export const predictSplitterAddress = async ({ signer, accounts, percentAllocations }: { signer: Signer, accounts: ETH_ADDRESS[], percentAllocations: number[] }): Promise<ETH_ADDRESS> => {
export const predictSplitterAddress = async ({ signer, accounts, percentAllocations, chainId }: { signer: Signer, accounts: ETH_ADDRESS[], percentAllocations: number[], chainId: number }): Promise<ETH_ADDRESS> => {

const splitMainContractInstance = new Contract(
SPLITMAIN_ADDRESS,
CHAIN_CONFIGURATION[chainId].SPLITMAIN_ADDRESS,
splitMainEthereumAbi,
signer,
);
Expand All @@ -78,15 +73,16 @@ export const predictSplitterAddress = async ({ signer, accounts, percentAllocati
}


export const handleDeployRewardsSplitter = async ({ signer, isSplitterDeployed, predictedSplitterAddress, accounts, percentAllocations, validatorsSize, principalRecipient }: { signer: Signer, isSplitterDeployed: boolean, predictedSplitterAddress: ETH_ADDRESS, accounts: ETH_ADDRESS[], percentAllocations: number[], validatorsSize: number, principalRecipient: ETH_ADDRESS }): Promise<ClusterValidator> => {
export const handleDeployRewardsSplitter = async ({ signer, isSplitterDeployed, predictedSplitterAddress, accounts, percentAllocations, validatorsSize, principalRecipient, chainId }: { signer: Signer, isSplitterDeployed: boolean, predictedSplitterAddress: ETH_ADDRESS, accounts: ETH_ADDRESS[], percentAllocations: number[], validatorsSize: number, principalRecipient: ETH_ADDRESS, chainId: number }): Promise<ClusterValidator> => {

try {
if (isSplitterDeployed) {
const owrAddress = await createOWRContract({
principalRecipient,
splitterAddress: predictedSplitterAddress,
amountOfPrincipalStake: validatorsSize * 32,
signer
signer,
chainId
});
return { withdrawal_address: owrAddress, fee_recipient_address: predictedSplitterAddress }

Expand All @@ -102,7 +98,8 @@ export const handleDeployRewardsSplitter = async ({ signer, isSplitterDeployed,
accounts: accounts,
percentAllocations: percentAllocations,
},
signer
signer,
chainId
}
);

Expand All @@ -125,15 +122,17 @@ const createOWRContract = async ({
splitterAddress,
amountOfPrincipalStake,
signer,
chainId
}: {
principalRecipient: ETH_ADDRESS,
splitterAddress: ETH_ADDRESS,
amountOfPrincipalStake: number,
signer: Signer,
chainId: number
}): Promise<ETH_ADDRESS> => {
try {
const OWRFactoryInstance = new Contract(
OWR_FACTORY_ADDRESS,
CHAIN_CONFIGURATION[chainId].OWR_FACTORY_ADDRESS,
OWRFactoryContract.abi,
signer,
);
Expand Down Expand Up @@ -165,10 +164,12 @@ export const deployImmutableSplitterAndOWRContracts = async ({
owrArgs,
splitterArgs,
signer,
chainId
}: {
owrArgs: OWRArgs,
splitterArgs: SplitArgs,
signer: Signer,
chainId: number
}): Promise<{ owrAddress: ETH_ADDRESS; splitterAddress: ETH_ADDRESS }> => {
const executeCalls: Call[] = [];
splitterArgs.distributorFee = DISTRIBUTOR_FEE;
Expand All @@ -192,16 +193,17 @@ export const deployImmutableSplitterAndOWRContracts = async ({

executeCalls.push(
{
target: SPLITMAIN_ADDRESS,
target: CHAIN_CONFIGURATION[chainId].SPLITMAIN_ADDRESS,
callData: splitTxData,
},
{
target: OWR_FACTORY_ADDRESS,
target: CHAIN_CONFIGURATION[chainId].OWR_FACTORY_ADDRESS,
callData: owrTxData,
},
);
const multicallAddess = CHAIN_CONFIGURATION[chainId].MULTICALL_ADDRESS

const executeMultiCalls = await multicall(executeCalls, signer);
const executeMultiCalls = await multicall(executeCalls, signer, multicallAddess);

const splitAddressData = executeMultiCalls?.logs[0]?.topics[1];

Expand All @@ -223,9 +225,10 @@ export const deployImmutableSplitterAndOWRContracts = async ({
export const multicall = async (
calls: Call[],
signer: Signer,
multicallAddress: string
): Promise<any> => {
const multiCallContractInstance = new Contract(
MULTICALL_ADDRESS,
multicallAddress,
MultiCallContract.abi,
signer,
);
Expand Down
3 changes: 0 additions & 3 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ export enum FORK_MAPPING {
/** Mainnet. */
'0x00000000' = 1,

/** Goerli/Prater. */
'0x00001020' = 5,

/** Gnosis Chain. */
'0x00000064' = 100,

Expand Down

0 comments on commit 8aa0568

Please sign in to comment.