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

Add owr tranch function #61

Merged
merged 8 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
172 changes: 172 additions & 0 deletions src/abi/OWR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,175 @@ export const OWRFactoryContract = {
},
],
};

export const OWRContract = {
abi: [
{ inputs: [], stateMutability: 'nonpayable', type: 'constructor' },
{ inputs: [], name: 'InvalidDistribution_TooLarge', type: 'error' },
{
inputs: [],
name: 'InvalidTokenRecovery_InvalidRecipient',
type: 'error',
},
{
anonymous: false,
inputs: [
{
indexed: false,
internalType: 'uint256',
name: 'principalPayout',
type: 'uint256',
},
{
indexed: false,
internalType: 'uint256',
name: 'rewardPayout',
type: 'uint256',
},
{
indexed: false,
internalType: 'uint256',
name: 'pullFlowFlag',
type: 'uint256',
},
],
name: 'DistributeFunds',
type: 'event',
},
{
anonymous: false,
inputs: [
{
indexed: false,
internalType: 'uint256',
name: 'amount',
type: 'uint256',
},
],
name: 'ReceiveETH',
type: 'event',
},
{
anonymous: false,
inputs: [
{
indexed: false,
internalType: 'address',
name: 'recoveryAddressToken',
type: 'address',
},
{
indexed: false,
internalType: 'address',
name: 'recipient',
type: 'address',
},
{
indexed: false,
internalType: 'uint256',
name: 'amount',
type: 'uint256',
},
],
name: 'RecoverNonOWRecipientFunds',
type: 'event',
},
{
anonymous: false,
inputs: [
{
indexed: false,
internalType: 'address',
name: 'account',
type: 'address',
},
{
indexed: false,
internalType: 'uint256',
name: 'amount',
type: 'uint256',
},
],
name: 'Withdrawal',
type: 'event',
},
{
inputs: [],
name: 'claimedPrincipalFunds',
outputs: [{ internalType: 'uint128', name: '', type: 'uint128' }],
stateMutability: 'view',
type: 'function',
},
{
inputs: [],
name: 'distributeFunds',
outputs: [],
stateMutability: 'payable',
type: 'function',
},
{
inputs: [],
name: 'distributeFundsPull',
outputs: [],
stateMutability: 'payable',
type: 'function',
},
{
inputs: [],
name: 'fundsPendingWithdrawal',
outputs: [{ internalType: 'uint128', name: '', type: 'uint128' }],
stateMutability: 'view',
type: 'function',
},
{
inputs: [{ internalType: 'address', name: 'account', type: 'address' }],
name: 'getPullBalance',
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
stateMutability: 'view',
type: 'function',
},
{
inputs: [],
name: 'getTranches',
outputs: [
{
internalType: 'address',
name: 'principalRecipient',
type: 'address',
},
{ internalType: 'address', name: 'rewardRecipient', type: 'address' },
{
internalType: 'uint256',
name: 'amountOfPrincipalStake',
type: 'uint256',
},
],
stateMutability: 'pure',
type: 'function',
},
{
inputs: [
{ internalType: 'address', name: 'nonOWRToken', type: 'address' },
{ internalType: 'address', name: 'recipient', type: 'address' },
],
name: 'recoverFunds',
outputs: [],
stateMutability: 'payable',
type: 'function',
},
{
inputs: [],
name: 'recoveryAddress',
outputs: [{ internalType: 'address', name: '', type: 'address' }],
stateMutability: 'pure',
type: 'function',
},
{
inputs: [{ internalType: 'address', name: 'account', type: 'address' }],
name: 'withdraw',
outputs: [],
stateMutability: 'nonpayable',
type: 'function',
},
],
};
23 changes: 23 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import {
type OperatorPayload,
type TotalSplitPayload,
type ClusterValidator,
type ETH_ADDRESS,
type OWRTranches,
} from './types.js';
import { clusterConfigOrDefinitionHash } from './verification/common.js';
import { validatePayload } from './ajv.js';
Expand All @@ -42,6 +44,7 @@ import {
formatSplitRecipients,
handleDeployOWRAndSplitter,
predictSplitterAddress,
getOWRTranches,
} from './splitHelpers.js';
import { isContractAvailable } from './utils.js';
export * from './types.js';
Expand Down Expand Up @@ -338,6 +341,26 @@ export class Client extends Base {
};
}

/**
* Read OWR Tranches.
*
* @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 {ETH_ADDRESS} owrAddress - Address of the Deployed OWR Contract
* @returns {Promise<OWRTranches>} owr tranch information about principal and reward reciepient, as well as the principal amount
*
*/
async getOWRTranches(owrAddress: ETH_ADDRESS): Promise<OWRTranches> {
if (!this.signer) {
throw new Error('Signer is required in getOWRTranches');
}

const signer = this.signer;
return await getOWRTranches({ owrAddress, signer });
}

/**
* Creates a cluster definition which contains cluster configuration.
* @param {ClusterPayload} newCluster - The new unique cluster.
Expand Down
21 changes: 20 additions & 1 deletion src/splitHelpers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
type OWRTranches,
type ClusterValidator,
type ETH_ADDRESS,
type SplitRecipient,
Expand All @@ -10,7 +11,7 @@ import {
ZeroAddress,
type Signer,
} from 'ethers';
import { OWRFactoryContract } from './abi/OWR';
import { OWRContract, OWRFactoryContract } from './abi/OWR';
import { splitMainEthereumAbi } from './abi/SplitMain';
import { MultiCallContract } from './abi/Multicall';
import { CHAIN_CONFIGURATION } from './constants';
Expand Down Expand Up @@ -237,6 +238,7 @@ export const deploySplitterContract = async ({
throw e;
}
};

export const deploySplitterAndOWRContracts = async ({
owrArgs,
splitterArgs,
Expand Down Expand Up @@ -297,6 +299,23 @@ export const deploySplitterAndOWRContracts = async ({
}
};

export const getOWRTranches = async ({
owrAddress,
signer,
}: {
owrAddress: ETH_ADDRESS;
signer: Signer;
}): Promise<OWRTranches> => {
const owrContract = new Contract(owrAddress, OWRContract.abi, signer);
const res = await owrContract.getTranches();

return {
principalRecipient: res.principalRecipient,
rewardRecipient: res.rewardRecipient,
amountOfPrincipalStake: res.amountOfPrincipalStake,
};
};

export const multicall = async (
calls: Call[],
signer: Signer,
Expand Down
14 changes: 14 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,20 @@ export interface RewardsSplitPayload extends TotalSplitPayload {
recoveryAddress?: string;
}

/**
* OWR Tranches
*/
export type OWRTranches = {
/** Address that will reclaim validator principal after exit. */
principalRecipient: ETH_ADDRESS;

/** Address that will reclaim validator rewards during operation. */
rewardRecipient: ETH_ADDRESS;

/** Amount of principal staked. */
amountOfPrincipalStake: number;
};

/**
* Unsigned DV Builder Registration Message
*/
Expand Down
45 changes: 9 additions & 36 deletions test/sdk-package-test/cluster.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,44 +133,17 @@ describe('Cluster Definition', () => {
});

it('should deploy OWR and Splitter', async () => {
const signerAddress = await randomSigner.getAddress();
// new splitter
const { withdrawal_address, fee_recipient_address } =
await client.createObolRewardsSplit({
splitRecipients: [
{ account: signerAddress, percentAllocation: 39 },
{
account: '0xf6fF1a7A14D01e86a175bA958d3B6C75f2213966',
percentAllocation: 60,
},
],
principalRecipient: '0xf6fF1a7A14D01e86a175bA958d3B6C75f2213966',
etherAmount: 2,
recoveryAddress: '0xf6fF1a7A14D01e86a175bA958d3B6C75f2213966',
});

// same splitter
const contractsWithSameFeeRecipientAddress =
await client.createObolRewardsSplit({
splitRecipients: [
{ account: signerAddress, percentAllocation: 39 },
{
account: '0xf6fF1a7A14D01e86a175bA958d3B6C75f2213966',
percentAllocation: 60,
},
],
principalRecipient: '0xf6fF1a7A14D01e86a175bA958d3B6C75f2213966',
etherAmount: 2,
});
const res = await client.getOWRTranches(
LukeHackett12 marked this conversation as resolved.
Show resolved Hide resolved
'0x9D4c1790972eFBd5c5D892209116667ECA299cF4',
);

expect(withdrawal_address.length).toEqual(42);
expect(fee_recipient_address.length).toEqual(42);
expect(
contractsWithSameFeeRecipientAddress.withdrawal_address.length,
).toEqual(42);
expect(fee_recipient_address.toLowerCase()).toEqual(
contractsWithSameFeeRecipientAddress.fee_recipient_address.toLowerCase(),
expect(res.principalRecipient).toEqual(
'0xc6AE567Aba2314bA3C5bE11F2C3BC7Fc614011f3',
);
expect(res.rewardRecipient).toEqual(
'0x5B3c8F77305008A8B15C5dAB9E66CDFC10Db4bB5',
);
expect(res.amountOfPrincipalStake).toEqual(BigInt(32000000000000000000));
});

it('should deploy OWR and Splitter with a controller address and a distributorFee', async () => {
Expand Down
24 changes: 12 additions & 12 deletions test/sdk-package-test/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1683,9 +1683,9 @@ camelcase@^6.2.0:
integrity sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA==

caniuse-lite@^1.0.30001663:
version "1.0.30001667"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001667.tgz#99fc5ea0d9c6e96897a104a8352604378377f949"
integrity sha512-7LTwJjcRkzKFmtqGsibMeuXmvFDfZq/nzIjnmgCGzKKRVzjD72selLDK1oPF/Oxzmt4fNcPvTDvGqSDG4tCALw==
version "1.0.30001669"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001669.tgz#fda8f1d29a8bfdc42de0c170d7f34a9cf19ed7a3"
integrity sha512-DlWzFDJqstqtIVx1zeSpIMLjunf5SmwOw0N2Ck/QSQdS8PLS4+9HrLaYei4w8BIAL7IB/UEDu889d8vhCTPA0w==

chalk@^2.4.2:
version "2.4.2"
Expand Down Expand Up @@ -1986,9 +1986,9 @@ dotenv@*, dotenv@^16.3.1:
integrity sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==

electron-to-chromium@^1.5.28:
version "1.5.35"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.5.35.tgz#1d38d386186c72b1fa6e74c3a7de5f888b503100"
integrity sha512-hOSRInrIDm0Brzp4IHW2F/VM+638qOL2CzE0DgpnGzKW27C95IqqeqgKz/hxHGnvPxvQGpHUGD5qRVC9EZY2+A==
version "1.5.39"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.5.39.tgz#5cbe5200b43dff7b7c2bcb6bdacf65d514c76bb2"
integrity sha512-4xkpSR6CjuiaNyvwiWDI85N9AxsvbPawB8xc7yzLPonYTuP19BVgYweKyUMFtHEZgIcHWMt1ks5Cqx2m+6/Grg==

elliptic@^6.5.4:
version "6.5.7"
Expand Down Expand Up @@ -2356,9 +2356,9 @@ fast-safe-stringify@^2.1.1:
integrity sha512-W+KJc2dmILlPplD/H4K9l9LcAHAfPtP6BY84uVLXQ6Evcz9Lcg33Y2z1IVblT6xdY54PXYVHEv+0Wpq8Io6zkA==

fast-uri@^3.0.1:
version "3.0.2"
resolved "https://registry.yarnpkg.com/fast-uri/-/fast-uri-3.0.2.tgz#d78b298cf70fd3b752fd951175a3da6a7b48f024"
integrity sha512-GR6f0hD7XXyNJa25Tb9BuIdN0tdr+0BMi6/CJPH3wJO1JjNG3n/VsSw38AwRdKZABm8lGbPfakLRkYzx2V9row==
version "3.0.3"
resolved "https://registry.yarnpkg.com/fast-uri/-/fast-uri-3.0.3.tgz#892a1c91802d5d7860de728f18608a0573142241"
integrity sha512-aLrHthzCjH5He4Z2H9YZ+v6Ujb9ocRuW6ZzkJQOrTxleEijANq4v1TsaPaVG1PZcuurEzrLcWRyYBYXD5cEiaw==

fastq@^1.6.0:
version "1.17.1"
Expand Down Expand Up @@ -3835,9 +3835,9 @@ murmurhash3js-revisited@^3.0.0:
integrity sha512-/sF3ee6zvScXMb1XFJ8gDsSnY+X8PbOyjIuBhtgis10W2Jx4ZjIhikUCIF9c4gpJxVnQIsPAFrSwTCuAjicP6g==

nan@^2.14.2:
version "2.21.0"
resolved "https://registry.yarnpkg.com/nan/-/nan-2.21.0.tgz#203ab765a02e6676c8cb92e1cad9503e7976d55b"
integrity sha512-MCpOGmdWvAOMi4RWnpxS5G24l7dVMtdSHtV87I3ltjaLdFOTO74HVJ+DfYiAXjxGKsYR/UCmm1rBwhMN7KqS1A==
version "2.22.0"
resolved "https://registry.yarnpkg.com/nan/-/nan-2.22.0.tgz#31bc433fc33213c97bad36404bb68063de604de3"
integrity sha512-nbajikzWTMwsW+eSsNm3QwlOs7het9gGJU5dDZzRTQGk03vyBOauxgI4VakDzE0PtsGTmXPsXTbbjVhRwR5mpw==

native-fetch@^3.0.0:
version "3.0.0"
Expand Down
Loading