Skip to content

Commit

Permalink
a warning and some improvements (#59)
Browse files Browse the repository at this point in the history
* a warning and someimporvements

* fix lint
  • Loading branch information
HananINouman authored Oct 10, 2024
1 parent e5935d9 commit cf67958
Show file tree
Hide file tree
Showing 6 changed files with 235 additions and 212 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ Checkout our [docs](https://docs.obol.org/docs/advanced/quickstart-sdk), [exampl
## Terms and Conditions
To use obol-sdk and in order to be able to create a cluster definition or accept an invite to join a cluster, you must accept the [latest Obol terms and conditions](https://obol.org/terms.pdf) by calling acceptObolLatestTermsAndConditions.

## ⚠️ Important Security Notice:
If you're integrating this SDK with a **backend** (e.g., in Node.js), and you store a private key for executing splitter transactions, handle it with extreme caution. Ensure that:

- The private key is securely stored (e.g., in an `.env` file).
- Never commit or push your `.env` file containing the private key to version control.

## Contributing

Please review the following guidelines:
Expand Down
20 changes: 18 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,19 @@ export class Client extends Base {

/**
* Deploys OWR and Splitter Proxy.
*
* @remarks
* **⚠️ Important:** If you're storing the private key in an `.env` file, ensure it is securely managed
* and not pushed to version control.
*
* @param {RewardsSplitPayload} rewardsSplitPayload - Data needed to deploy owr and splitter.
* @returns {Promise<ClusterValidator>} owr address as withdrawal address and splitter as fee recipient
*
* An example of how to use createObolRewardsSplit:
* [createObolRewardsSplit](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts#L141)
*/
// add the example reference
async createObolRewardSplit({
async createObolRewardsSplit({
splitRecipients,
principalRecipient,
etherAmount,
Expand All @@ -133,7 +141,7 @@ export class Client extends Base {
}: RewardsSplitPayload): Promise<ClusterValidator> {
// This method doesnt require T&C signature
if (!this.signer) {
throw new Error('Signer is required in createObolRewardSplit');
throw new Error('Signer is required in createObolRewardsSplit');
}

validatePayload(
Expand Down Expand Up @@ -231,8 +239,16 @@ export class Client extends Base {

/**
* Deploys Splitter Proxy.
*
* @remarks
* **⚠️ Important:** If you're storing the private key in an `.env` file, ensure it is securely managed
* and not pushed to version control.
*
* @param {TotalSplitPayload} totalSplitPayload - Data needed to deploy splitter if it doesnt exist.
* @returns {Promise<ClusterValidator>} splitter address as withdrawal address and splitter as fee recipient too
*
* An example of how to use createObolTotalSplit:
* [createObolTotalSplit](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts#L168)
*/
// add the example reference
async createObolTotalSplit({
Expand Down
4 changes: 2 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ export type ClusterCreator = {
* Validator withdrawal configuration
*/
export type ClusterValidator = {
/** The validator fee recipient address. */
/** Address to receive MEV rewards (if enabled), block proposal and priority fees. */
fee_recipient_address: string;

/** The validator reward address. */
/** Address to receive skimming rewards and validator principal at exit. */
withdrawal_address: string;
};

Expand Down
14 changes: 7 additions & 7 deletions test/methods.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ describe('Cluster Client without a signer', () => {
});
});

describe('createObolRewardSplit', () => {
describe('createObolRewardsSplit', () => {
jest
.spyOn(utils, 'isContractAvailable')
.mockImplementation(async () => await Promise.resolve(true));
Expand Down Expand Up @@ -324,12 +324,12 @@ describe('createObolRewardSplit', () => {

it('should throw an error if signer is not defined', async () => {
await expect(
clientInstanceWithourSigner.createObolRewardSplit({
clientInstanceWithourSigner.createObolRewardsSplit({
splitRecipients: mockSplitRecipients,
principalRecipient: mockPrincipalRecipient,
etherAmount: mockEtherAmount,
}),
).rejects.toThrow('Signer is required in createObolRewardSplit');
).rejects.toThrow('Signer is required in createObolRewardsSplit');
});

it('should throw an error if chainId is not supported', async () => {
Expand All @@ -339,7 +339,7 @@ describe('createObolRewardSplit', () => {
);

try {
await unsupportedSplitterChainClient.createObolRewardSplit({
await unsupportedSplitterChainClient.createObolRewardsSplit({
splitRecipients: mockSplitRecipients,
principalRecipient: mockPrincipalRecipient,
etherAmount: mockEtherAmount,
Expand All @@ -353,7 +353,7 @@ describe('createObolRewardSplit', () => {

test('should throw an error on invalid recipients', async () => {
try {
await clientInstance.createObolRewardSplit({
await clientInstance.createObolRewardsSplit({
splitRecipients: [
{
account: '0x86B8145c98e5BD25BA722645b15eD65f024a87EC',
Expand All @@ -372,7 +372,7 @@ describe('createObolRewardSplit', () => {

test('should throw an error if ObolRAFSplit is less than 1', async () => {
try {
await clientInstance.createObolRewardSplit({
await clientInstance.createObolRewardsSplit({
splitRecipients: mockSplitRecipients,
principalRecipient: mockPrincipalRecipient,
etherAmount: mockEtherAmount,
Expand All @@ -384,7 +384,7 @@ describe('createObolRewardSplit', () => {
});

it('should return the correct withdrawal and fee recipient addresses', async () => {
const result = await clientInstance.createObolRewardSplit({
const result = await clientInstance.createObolRewardsSplit({
splitRecipients: mockSplitRecipients,
principalRecipient: mockPrincipalRecipient,
etherAmount: mockEtherAmount,
Expand Down
8 changes: 4 additions & 4 deletions test/sdk-package-test/cluster.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ describe('Cluster Definition', () => {
const signerAddress = await randomSigner.getAddress();
// new splitter
const { withdrawal_address, fee_recipient_address } =
await client.createObolRewardSplit({
await client.createObolRewardsSplit({
splitRecipients: [
{ account: signerAddress, percentAllocation: 39 },
{
Expand All @@ -151,7 +151,7 @@ describe('Cluster Definition', () => {

// same splitter
const contractsWithSameFeeRecipientAddress =
await client.createObolRewardSplit({
await client.createObolRewardsSplit({
splitRecipients: [
{ account: signerAddress, percentAllocation: 39 },
{
Expand All @@ -177,7 +177,7 @@ describe('Cluster Definition', () => {
const signerAddress = await randomSigner.getAddress();
// new splitter
const { withdrawal_address, fee_recipient_address } =
await client.createObolRewardSplit({
await client.createObolRewardsSplit({
splitRecipients: [
{ account: signerAddress, percentAllocation: 39 },
{
Expand All @@ -193,7 +193,7 @@ describe('Cluster Definition', () => {

// same splitter
const contractsWithDifferentFeeRecipient =
await client.createObolRewardSplit({
await client.createObolRewardsSplit({
splitRecipients: [
{ account: signerAddress, percentAllocation: 39 },
{
Expand Down
Loading

0 comments on commit cf67958

Please sign in to comment.