Skip to content

Commit 482af04

Browse files
committed
chore: added limited calls enforcer utils
1 parent 1f88f2d commit 482af04

7 files changed

Lines changed: 707 additions & 2 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import * as read from './read';
2+
3+
export { read };
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { LimitedCallsEnforcer } from '@metamask/delegation-abis';
2+
import type { Client, Hex } from 'viem';
3+
import { readContract } from 'viem/actions';
4+
5+
export type ReadCallCountsParameters = {
6+
client: Client;
7+
contractAddress: `0x${string}`;
8+
delegationManager: `0x${string}`;
9+
delegationHash: Hex;
10+
};
11+
12+
export const read = async ({
13+
client,
14+
contractAddress,
15+
delegationManager,
16+
delegationHash,
17+
}: ReadCallCountsParameters) => {
18+
const count = await readContract(client, {
19+
address: contractAddress,
20+
abi: LimitedCallsEnforcer.abi,
21+
functionName: 'callCounts',
22+
args: [delegationManager, delegationHash],
23+
});
24+
25+
return count;
26+
};
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { LimitedCallsEnforcer } from '@metamask/delegation-abis';
2+
import type { Client, Hex } from 'viem';
3+
import { readContract } from 'viem/actions';
4+
5+
export type ReadGetTermsInfoParameters = {
6+
client: Client;
7+
contractAddress: `0x${string}`;
8+
terms: Hex;
9+
};
10+
11+
export const read = async ({
12+
client,
13+
contractAddress,
14+
terms,
15+
}: ReadGetTermsInfoParameters) => {
16+
const limit = await readContract(client, {
17+
address: contractAddress,
18+
abi: LimitedCallsEnforcer.abi,
19+
functionName: 'getTermsInfo',
20+
args: [terms],
21+
});
22+
23+
return limit;
24+
};
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { read as callCounts } from './methods/callCounts';
2+
import { read as getTermsInfo } from './methods/getTermsInfo';
3+
4+
export { callCounts, getTermsInfo };

packages/delegation-toolkit/src/contracts/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import * as ERC20StreamingEnforcer from '../DelegationFramework/ERC20StreamingEn
77
import * as ERC20TransferAmountEnforcer from '../DelegationFramework/ERC20TransferAmountEnforcer';
88
import * as HybridDeleGator from '../DelegationFramework/HybridDeleGator';
99
import * as IdEnforcer from '../DelegationFramework/IdEnforcer';
10+
import * as LimitedCallsEnforcer from '../DelegationFramework/LimitedCallsEnforcer';
1011
import * as MultiSigDeleGator from '../DelegationFramework/MultiSigDeleGator';
1112
import * as MultiTokenPeriodEnforcer from '../DelegationFramework/MultiTokenPeriodEnforcer';
1213
import * as NativeTokenPeriodTransferEnforcer from '../DelegationFramework/NativeTokenPeriodTransferEnforcer';
@@ -31,6 +32,7 @@ export {
3132
EntryPoint,
3233
HybridDeleGator,
3334
IdEnforcer,
35+
LimitedCallsEnforcer,
3436
MultiSigDeleGator,
3537
Ownable2Step,
3638
Pausable,

0 commit comments

Comments
 (0)