@obolnetwork/obol-sdk 2.3.0 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/package.json +2 -2
- package/dist/cjs/src/abi/MerkleDistributorWithDeadline.js +73 -0
- package/dist/cjs/src/incentives.js +92 -0
- package/dist/cjs/src/incentivesHalpers.js +41 -0
- package/dist/cjs/src/index.js +2 -13
- package/dist/cjs/test/incentives.test.js +174 -0
- package/dist/cjs/test/methods.test.js +0 -44
- package/dist/esm/package.json +2 -2
- package/dist/esm/src/abi/MerkleDistributorWithDeadline.js +70 -0
- package/dist/esm/src/incentives.js +88 -0
- package/dist/esm/src/incentivesHalpers.js +36 -0
- package/dist/esm/src/index.js +2 -13
- package/dist/esm/test/incentives.test.js +149 -0
- package/dist/esm/test/methods.test.js +0 -44
- package/dist/types/src/abi/MerkleDistributorWithDeadline.d.ts +91 -0
- package/dist/types/src/incentives.d.ts +49 -0
- package/dist/types/src/incentivesHalpers.d.ts +13 -0
- package/dist/types/src/index.d.ts +3 -7
- package/dist/types/test/incentives.test.d.ts +1 -0
- package/package.json +2 -2
- package/src/abi/MerkleDistributorWithDeadline.ts +70 -0
- package/src/incentives.ts +116 -0
- package/src/incentivesHalpers.ts +58 -0
- package/src/index.ts +7 -16
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { type ETH_ADDRESS } from './types';
|
|
2
|
+
import { Contract, type Signer } from 'ethers';
|
|
3
|
+
import { MerkleDistributorABI } from './abi/MerkleDistributorWithDeadline';
|
|
4
|
+
import { getProvider } from './utils';
|
|
5
|
+
|
|
6
|
+
export const claimIncentivesFromMerkleDistributor = async (incentivesData: {
|
|
7
|
+
signer: Signer;
|
|
8
|
+
contractAddress: ETH_ADDRESS;
|
|
9
|
+
index: number;
|
|
10
|
+
operatorAddress: ETH_ADDRESS;
|
|
11
|
+
amount: number;
|
|
12
|
+
merkleProof: string[];
|
|
13
|
+
}): Promise<{ txHash: string }> => {
|
|
14
|
+
try {
|
|
15
|
+
const contract = new Contract(
|
|
16
|
+
incentivesData.contractAddress,
|
|
17
|
+
MerkleDistributorABI.abi,
|
|
18
|
+
incentivesData.signer,
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
const tx = await contract.claim(
|
|
22
|
+
BigInt(incentivesData.index),
|
|
23
|
+
incentivesData.operatorAddress,
|
|
24
|
+
BigInt(incentivesData.amount),
|
|
25
|
+
incentivesData.merkleProof,
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
const receipt = await tx.wait();
|
|
29
|
+
|
|
30
|
+
return { txHash: receipt.hash };
|
|
31
|
+
} catch (error: any) {
|
|
32
|
+
console.log('Error claiming incentives:', error);
|
|
33
|
+
throw new Error(`Failed to claim incentives: ${error.message}`);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export const isClaimedFromMerkleDistributor = async (
|
|
38
|
+
chainId: number,
|
|
39
|
+
contractAddress: ETH_ADDRESS,
|
|
40
|
+
index: number,
|
|
41
|
+
): Promise<boolean> => {
|
|
42
|
+
try {
|
|
43
|
+
const provider = getProvider(chainId);
|
|
44
|
+
|
|
45
|
+
const contract = new Contract(
|
|
46
|
+
contractAddress,
|
|
47
|
+
MerkleDistributorABI.abi,
|
|
48
|
+
provider,
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
const claimed = await contract.isClaimed(BigInt(index));
|
|
52
|
+
|
|
53
|
+
return claimed;
|
|
54
|
+
} catch (error: any) {
|
|
55
|
+
console.log('Error checking claim status:', error);
|
|
56
|
+
throw new Error(`Failed to check claim status: ${error.message}`);
|
|
57
|
+
}
|
|
58
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -30,7 +30,6 @@ import {
|
|
|
30
30
|
type ClusterValidator,
|
|
31
31
|
type ETH_ADDRESS,
|
|
32
32
|
type OWRTranches,
|
|
33
|
-
type Incentives,
|
|
34
33
|
} from './types.js';
|
|
35
34
|
import { clusterConfigOrDefinitionHash } from './verification/common.js';
|
|
36
35
|
import { validatePayload } from './ajv.js';
|
|
@@ -48,6 +47,7 @@ import {
|
|
|
48
47
|
getOWRTranches,
|
|
49
48
|
} from './splitHelpers.js';
|
|
50
49
|
import { isContractAvailable } from './utils.js';
|
|
50
|
+
import { Incentives } from './incentives.js';
|
|
51
51
|
export * from './types.js';
|
|
52
52
|
export * from './services.js';
|
|
53
53
|
export * from './verification/signature-validator.js';
|
|
@@ -58,6 +58,7 @@ export * from './verification/common.js';
|
|
|
58
58
|
*/
|
|
59
59
|
export class Client extends Base {
|
|
60
60
|
private readonly signer: Signer | undefined;
|
|
61
|
+
public incentives: Incentives;
|
|
61
62
|
|
|
62
63
|
/**
|
|
63
64
|
* @param config - Client configurations
|
|
@@ -72,6 +73,11 @@ export class Client extends Base {
|
|
|
72
73
|
constructor(config: { baseUrl?: string; chainId?: number }, signer?: Signer) {
|
|
73
74
|
super(config);
|
|
74
75
|
this.signer = signer;
|
|
76
|
+
this.incentives = new Incentives(
|
|
77
|
+
this.signer,
|
|
78
|
+
this.chainId,
|
|
79
|
+
this.request.bind(this),
|
|
80
|
+
);
|
|
75
81
|
}
|
|
76
82
|
|
|
77
83
|
/**
|
|
@@ -521,19 +527,4 @@ export class Client extends Base {
|
|
|
521
527
|
);
|
|
522
528
|
return lock;
|
|
523
529
|
}
|
|
524
|
-
|
|
525
|
-
/**
|
|
526
|
-
* @param address - Operator address
|
|
527
|
-
* @returns {Promise<Incentives>} The matched incentives from DB
|
|
528
|
-
* @throws On not found if address not found.
|
|
529
|
-
*/
|
|
530
|
-
async getIncentivesByAddress(address: string): Promise<Incentives> {
|
|
531
|
-
const incentives: Incentives = await this.request(
|
|
532
|
-
`/${DEFAULT_BASE_VERSION}/address/incentives/${address}`,
|
|
533
|
-
{
|
|
534
|
-
method: 'GET',
|
|
535
|
-
},
|
|
536
|
-
);
|
|
537
|
-
return incentives;
|
|
538
|
-
}
|
|
539
530
|
}
|