Skip to content

Commit b7e1dcd

Browse files
committed
todo: need to run test
1 parent 7fe571c commit b7e1dcd

File tree

2 files changed

+27
-20
lines changed

2 files changed

+27
-20
lines changed

packages/test/v0.7/permissionValidator.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ import {
3333
ECDSA_SIGNER_CONTRACT,
3434
GAS_POLICY_CONTRACT,
3535
type Policy,
36+
RATE_LIMIT_POLICY_WITH_RESET_CONTRACT,
3637
SUDO_POLICY_CONTRACT,
3738
deserializePermissionAccount,
38-
serializePermissionAccount,
39-
RATE_LIMIT_POLICY_WITH_RESET_CONTRACT
39+
serializePermissionAccount
4040
} from "../../../plugins/permission"
4141
import {
4242
CallPolicyVersion,

plugins/permission/policies/toRateLimitPolicy.ts

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { concatHex } from "viem"
22
import { PolicyFlags } from "../constants.js"
3-
import { RATE_LIMIT_POLICY_CONTRACT, RATE_LIMIT_POLICY_WITH_RESET_CONTRACT } from "../constants.js"
3+
import {
4+
RATE_LIMIT_POLICY_CONTRACT,
5+
RATE_LIMIT_POLICY_WITH_RESET_CONTRACT
6+
} from "../constants.js"
47
import type { Policy, PolicyParams } from "../types.js"
58

69
export type RateLimitPolicyParams = PolicyParams & {
@@ -18,27 +21,31 @@ export function toRateLimitPolicy({
1821
}: RateLimitPolicyParams): Policy {
1922
return {
2023
getPolicyData: () => {
21-
if(policyAddress === RATE_LIMIT_POLICY_CONTRACT) {
22-
const intervalHex = interval.toString(16).padStart(12, "0")
23-
const countHex = count.toString(16).padStart(12, "0")
24-
const startAtHex = startAt.toString(16).padStart(12, "0")
24+
if (policyAddress === RATE_LIMIT_POLICY_CONTRACT) {
25+
const intervalHex = interval.toString(16).padStart(12, "0")
26+
const countHex = count.toString(16).padStart(12, "0")
27+
const startAtHex = startAt.toString(16).padStart(12, "0")
2528

26-
const data = intervalHex + countHex + startAtHex
29+
const data = intervalHex + countHex + startAtHex
2730

28-
return `0x${data}`
29-
} else if(policyAddress === RATE_LIMIT_POLICY_WITH_RESET_CONTRACT) {
30-
if(startAt !== 0 && startAt !== undefined) {
31-
throw new Error("RATE_LIMIT_POLICY_WITH_RESET_CONTRACT does not support startAt")
32-
}
33-
const intervalHex = interval.toString(16).padStart(12, "0")
34-
const countHex = count.toString(16).padStart(12, "0")
31+
return `0x${data}`
32+
} else if (
33+
policyAddress === RATE_LIMIT_POLICY_WITH_RESET_CONTRACT
34+
) {
35+
if (startAt !== 0 && startAt !== undefined) {
36+
throw new Error(
37+
"RATE_LIMIT_POLICY_WITH_RESET_CONTRACT does not support startAt"
38+
)
39+
}
40+
const intervalHex = interval.toString(16).padStart(12, "0")
41+
const countHex = count.toString(16).padStart(12, "0")
3542

36-
const data = intervalHex + countHex
43+
const data = intervalHex + countHex
3744

38-
return `0x${data}`
39-
} else {
40-
throw new Error("Invalid policy address")
41-
}
45+
return `0x${data}`
46+
} else {
47+
throw new Error("Invalid policy address")
48+
}
4249
},
4350
getPolicyInfoInBytes: () => {
4451
return concatHex([policyFlag, policyAddress])

0 commit comments

Comments
 (0)