Skip to content

Commit

Permalink
reflect feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
HananINouman committed Sep 10, 2024
1 parent 6810ad1 commit 29528aa
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 92 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ module.exports = {
'@typescript-eslint/member-delimiter-style': 'off',
'no-useless-catch': 0,
'new-cap': 0,
"@typescript-eslint/naming-convention": 'off'
},
};
2 changes: 2 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,5 @@ export const CHAIN_CONFIGURATION = {
export const DEFAULT_RETROACTIVE_FUNDING_REWARDS_ONLY_SPLIT = 1;

export const DEFAULT_RETROACTIVE_FUNDING_TOTAL_SPLIT = 0.1;

export const OBOL_SDK_EMAIL="[email protected]"
33 changes: 17 additions & 16 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
CHAIN_CONFIGURATION,
DEFAULT_RETROACTIVE_FUNDING_REWARDS_ONLY_SPLIT,
DEFAULT_RETROACTIVE_FUNDING_TOTAL_SPLIT,
OBOL_SDK_EMAIL,
} from './constants.js';
import { ConflictError } from './errors.js';
import {
Expand All @@ -25,8 +26,8 @@ import {
type ClusterLock,
type ClusterPayload,
type OperatorPayload,
type SplitterReturnedType,
type TotalSplitPayload,
type ClusterValidator,
} from './types.js';
import { clusterConfigOrDefinitionHash } from './verification/common.js';
import { validatePayload } from './ajv.js';
Expand Down Expand Up @@ -118,17 +119,17 @@ export class Client extends Base {
/**
* Deploys OWR and Splitter Proxy.
* @param {RewardsSplitPayload} rewardsSplitPayload - Data needed to deploy owr and splitter.
* @returns {Promise<SplitterReturnedType>} owr address as withdrawal address and splitter as fee recipient
* @returns {Promise<ClusterValidator>} owr address as withdrawal address and splitter as fee recipient
*/
// add the example reference
async createObolRewardSplit({
splitRecipients,
principalRecipient,
validatorsSize,
etherAmount,
ObolRAFSplit = DEFAULT_RETROACTIVE_FUNDING_REWARDS_ONLY_SPLIT,
distributorFee = 0,
controllerAddress = ZeroAddress,
}: RewardsSplitPayload): Promise<SplitterReturnedType> {
}: RewardsSplitPayload): Promise<ClusterValidator> {
// This method doesnt require T&C signature
if (!this.signer) {
throw new Error('Signer is required in createObolRewardSplit');
Expand All @@ -138,7 +139,7 @@ export class Client extends Base {
{
splitRecipients,
principalRecipient,
validatorsSize,
etherAmount,
ObolRAFSplit,
distributorFee,
controllerAddress,
Expand Down Expand Up @@ -174,7 +175,7 @@ export class Client extends Base {
!checkOWRFactoryAddress
) {
throw new Error(
'Something isn not working as expected, check this issue with obol-sdk team',
`Something isn not working as expected, check this issue with obol-sdk team on ${OBOL_SDK_EMAIL}`,
);
}

Expand Down Expand Up @@ -204,35 +205,35 @@ export class Client extends Base {
this.signer.provider as Provider,
);

const { withdrawalAddress, feeRecipientAddress } =
const { withdrawal_address, fee_recipient_address } =
await handleDeployOWRAndSplitter({
signer: this.signer,
isSplitterDeployed: !!isSplitterDeployed,
predictedSplitterAddress,
accounts,
percentAllocations,
principalRecipient,
validatorsSize,
etherAmount,
chainId: this.chainId,
distributorFee,
controllerAddress,
});

return { withdrawalAddress, feeRecipientAddress };
return { withdrawal_address, fee_recipient_address };
}

/**
* Deploys Splitter Proxy.
* @param {TotalSplitPayload} totalSplitPayload - Data needed to deploy splitter if it doesnt exist.
* @returns {Promise<SplitterReturnedType>} splitter address as withdrawal address and splitter as fee recipient too
* @returns {Promise<ClusterValidator>} splitter address as withdrawal address and splitter as fee recipient too
*/
// add the example reference
async createObolTotalSplit({
splitRecipients,
ObolRAFSplit = DEFAULT_RETROACTIVE_FUNDING_TOTAL_SPLIT,
distributorFee = 0,
controllerAddress = ZeroAddress,
}: TotalSplitPayload): Promise<SplitterReturnedType> {
}: TotalSplitPayload): Promise<ClusterValidator> {
// This method doesnt require T&C signature
if (!this.signer) {
throw new Error('Signer is required in createObolTotalSplit');
Expand Down Expand Up @@ -262,7 +263,7 @@ export class Client extends Base {

if (!checkSplitMainAddress) {
throw new Error(
'Something isn not working as expected, check this issue with obol-sdk team',
`Something isn not working as expected, check this issue with obol-sdk team on ${OBOL_SDK_EMAIL}`,
);
}

Expand Down Expand Up @@ -301,14 +302,14 @@ export class Client extends Base {
controllerAddress,
});
return {
withdrawalAddress: splitterAddress,
feeRecipientAddress: splitterAddress,
withdrawal_address: splitterAddress,
fee_recipient_address: splitterAddress,
};
}

return {
withdrawalAddress: predictedSplitterAddress,
feeRecipientAddress: predictedSplitterAddress,
withdrawal_address: predictedSplitterAddress,
fee_recipient_address: predictedSplitterAddress,
};
}

Expand Down
4 changes: 2 additions & 2 deletions src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,13 @@ export const rewardsSplitterPayloadSchema = {
type: 'number',
minimum: DEFAULT_RETROACTIVE_FUNDING_REWARDS_ONLY_SPLIT,
},
validatorsSize: {
etherAmount: {
type: 'number',
},
principalRecipient: {
type: 'string',
pattern: '^0x[a-fA-F0-9]{40}$',
},
},
required: ['splitRecipients', 'principalRecipient', 'validatorsSize'],
required: ['splitRecipients', 'principalRecipient', 'etherAmount'],
};
20 changes: 10 additions & 10 deletions src/splitHelpers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
type SplitterReturnedType,
type ClusterValidator,
type ETH_ADDRESS,
type SplitRecipient,
} from './types';
Expand Down Expand Up @@ -106,7 +106,7 @@ export const handleDeployOWRAndSplitter = async ({
predictedSplitterAddress,
accounts,
percentAllocations,
validatorsSize,
etherAmount,
principalRecipient,
chainId,
distributorFee,
Expand All @@ -117,31 +117,31 @@ export const handleDeployOWRAndSplitter = async ({
predictedSplitterAddress: ETH_ADDRESS;
accounts: ETH_ADDRESS[];
percentAllocations: number[];
validatorsSize: number;
etherAmount: number;
principalRecipient: ETH_ADDRESS;
chainId: number;
distributorFee: number;
controllerAddress: ETH_ADDRESS;
}): Promise<SplitterReturnedType> => {
}): Promise<ClusterValidator> => {
try {
if (isSplitterDeployed) {
const owrAddress = await createOWRContract({
principalRecipient,
splitterAddress: predictedSplitterAddress,
amountOfPrincipalStake: validatorsSize * 32,
amountOfPrincipalStake: etherAmount,
signer,
chainId,
});
return {
withdrawalAddress: owrAddress,
feeRecipientAddress: predictedSplitterAddress,
withdrawal_address: owrAddress,
fee_recipient_address: predictedSplitterAddress,
};
} else {
const { owrAddress, splitterAddress } =
await deploySplitterAndOWRContracts({
owrArgs: {
principalRecipient,
amountOfPrincipalStake: validatorsSize * 32,
amountOfPrincipalStake: etherAmount,
predictedSplitterAddress,
},
splitterArgs: {
Expand All @@ -155,8 +155,8 @@ export const handleDeployOWRAndSplitter = async ({
});

return {
withdrawalAddress: owrAddress,
feeRecipientAddress: splitterAddress,
withdrawal_address: owrAddress,
fee_recipient_address: splitterAddress,
};
}
} catch (e) {
Expand Down
19 changes: 4 additions & 15 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,6 @@ export type ClusterValidator = {
withdrawal_address: string;
};

/**
* Splitter withdrawal returned type
*/
export type SplitterReturnedType = {
/** The validator fee recipient address. */
feeRecipientAddress: string;

/** The validator reward address. */
withdrawalAddress: string;
};

/**
* Cluster configuration
*/
Expand Down Expand Up @@ -146,10 +135,10 @@ export type TotalSplitPayload = {
/** The split recipients addresses and splits. */
splitRecipients: SplitRecipient[];

/** Maximum number of validators with this configuration. */
/** Split percentageNumber allocated for obol retroactive funding, minimum is 1%. */
ObolRAFSplit?: number;

/** Fees paid to the distributor. */
/** The percentageNumber of accrued rewards that is paid to the caller of the distribution function to compensate them for the gas costs of doing so. Cannot be greater than 10%. For example, 5 represents 5%. */
distributorFee?: number;

/** Address that can mutate the split, should be ZeroAddress for immutable split. */
Expand All @@ -163,8 +152,8 @@ export interface RewardsSplitPayload extends TotalSplitPayload {
/** Address that will reclaim validator principal after exit. */
principalRecipient: string;

/** Maximum number of validators needed for the OWR configuration. */
validatorsSize: number;
/** Amount needed to deploy all validators expected for the OWR/Splitter configuration. */
etherAmount: number;
}

/**
Expand Down
28 changes: 14 additions & 14 deletions test/methods.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,8 @@ describe('createObolRewardSplit', () => {
jest.spyOn(splitsHelpers, 'handleDeployOWRAndSplitter').mockImplementation(
async () =>
await Promise.resolve({
withdrawalAddress: '0xWithdrawalAddress',
feeRecipientAddress: '0xFeeRecipientAddress',
withdrawal_address: '0xWithdrawalAddress',
fee_recipient_address: '0xFeeRecipientAddress',
}),
);

Expand Down Expand Up @@ -320,14 +320,14 @@ describe('createObolRewardSplit', () => {
},
];
const mockPrincipalRecipient = '0x86B8145c98e5BD25BA722645b15eD65f024a87EC';
const mockValidatorsSize = 2;
const mockEtherAmount = 64;

it('should throw an error if signer is not defined', async () => {
await expect(
clientInstanceWithourSigner.createObolRewardSplit({
splitRecipients: mockSplitRecipients,
principalRecipient: mockPrincipalRecipient,
validatorsSize: mockValidatorsSize,
etherAmount: mockEtherAmount,
}),
).rejects.toThrow('Signer is required in createObolRewardSplit');
});
Expand All @@ -342,7 +342,7 @@ describe('createObolRewardSplit', () => {
await unsupportedSplitterChainClient.createObolRewardSplit({
splitRecipients: mockSplitRecipients,
principalRecipient: mockPrincipalRecipient,
validatorsSize: mockValidatorsSize,
etherAmount: mockEtherAmount,
});
} catch (error: any) {
expect(error.message).toEqual(
Expand All @@ -361,7 +361,7 @@ describe('createObolRewardSplit', () => {
},
],
principalRecipient: mockPrincipalRecipient,
validatorsSize: mockValidatorsSize,
etherAmount: mockEtherAmount,
});
} catch (error: any) {
expect(error.message).toEqual(
Expand All @@ -375,7 +375,7 @@ describe('createObolRewardSplit', () => {
await clientInstance.createObolRewardSplit({
splitRecipients: mockSplitRecipients,
principalRecipient: mockPrincipalRecipient,
validatorsSize: mockValidatorsSize,
etherAmount: mockEtherAmount,
ObolRAFSplit: 0.5,
});
} catch (error: any) {
Expand All @@ -387,12 +387,12 @@ describe('createObolRewardSplit', () => {
const result = await clientInstance.createObolRewardSplit({
splitRecipients: mockSplitRecipients,
principalRecipient: mockPrincipalRecipient,
validatorsSize: mockValidatorsSize,
etherAmount: mockEtherAmount,
});

expect(result).toEqual({
withdrawalAddress: '0xWithdrawalAddress',
feeRecipientAddress: '0xFeeRecipientAddress',
withdrawal_address: '0xWithdrawalAddress',
fee_recipient_address: '0xFeeRecipientAddress',
});
});
});
Expand Down Expand Up @@ -497,8 +497,8 @@ describe('createObolTotalSplit', () => {

// 0xPredictedAddress and not 0xSplitterAddress since were mocking isContractAvailable response to be true
expect(result).toEqual({
withdrawalAddress: '0xPredictedAddress',
feeRecipientAddress: '0xPredictedAddress',
withdrawal_address: '0xPredictedAddress',
fee_recipient_address: '0xPredictedAddress',
});
});

Expand All @@ -509,8 +509,8 @@ describe('createObolTotalSplit', () => {

// 0xPredictedAddress and not 0xSplitterAddress since were mocking isContractAvailable response to be true
expect(result).toEqual({
withdrawalAddress: '0xPredictedAddress',
feeRecipientAddress: '0xPredictedAddress',
withdrawal_address: '0xPredictedAddress',
fee_recipient_address: '0xPredictedAddress',
});
});
});
Loading

0 comments on commit 29528aa

Please sign in to comment.