-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add test support for smart sessions
- Loading branch information
Showing
14 changed files
with
519 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
export const UniActionPolicyAbi = [ | ||
{ | ||
components: [ | ||
{ | ||
name: "valueLimitPerUse", | ||
type: "uint256" | ||
}, | ||
{ | ||
components: [ | ||
{ | ||
name: "length", | ||
type: "uint256" | ||
}, | ||
{ | ||
components: [ | ||
{ | ||
name: "condition", | ||
type: "uint8" | ||
}, | ||
{ | ||
name: "offset", | ||
type: "uint64" | ||
}, | ||
{ | ||
name: "isLimited", | ||
type: "bool" | ||
}, | ||
{ | ||
name: "ref", | ||
type: "bytes32" | ||
}, | ||
{ | ||
components: [ | ||
{ | ||
name: "limit", | ||
type: "uint256" | ||
}, | ||
{ | ||
name: "used", | ||
type: "uint256" | ||
} | ||
], | ||
name: "usage", | ||
type: "tuple" | ||
} | ||
], | ||
name: "rules", | ||
type: "tuple[]" | ||
} | ||
], | ||
name: "paramRules", | ||
type: "tuple" | ||
} | ||
], | ||
name: "ActionConfig", | ||
type: "tuple" | ||
} | ||
] as const |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
// The contents of this folder is auto-generated. Please do not edit as your changes are likely to be overwritten | ||
|
||
import type { Hex } from "viem" | ||
import { TEST_CONTRACTS } from "../../tests/src/callDatas" | ||
Check failure on line 4 in src/__contracts/addresses.ts GitHub Actions / size report
|
||
export const addresses: Record<string, Hex> = { | ||
Nexus: "0x776d63154D2aa9256D72C420416c930F3B735464", | ||
K1Validator: "0xd98238BBAeA4f91683d250003799EAd31d7F5c55", | ||
K1ValidatorFactory: "0x8025afaD10209b8bEF3A3C94684AaE4D309c9996" | ||
K1ValidatorFactory: "0x8025afaD10209b8bEF3A3C94684AaE4D309c9996", | ||
UniActionPolicy: TEST_CONTRACTS.UniActionPolicy.address | ||
} as const | ||
export default addresses |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
import { type Address, type Hex, encodeAbiParameters, isHex } from "viem" | ||
import { TEST_CONTRACTS } from "../../tests/src/callDatas" | ||
import contracts from "../__contracts" | ||
import { ERROR_MESSAGES } from "../account" | ||
|
||
export type ActionConfig = { | ||
valueLimitPerUse: bigint | ||
paramRules: { | ||
length: number | ||
rules: { | ||
condition: ParamCondition | ||
offsetIndex: number | ||
isLimited: boolean | ||
ref: Hex | ||
usage: LimitUsage | ||
}[] | ||
} | ||
} | ||
|
||
export const toActionConfig = (config: ActionConfig): RawActionConfig => ({ | ||
valueLimitPerUse: BigInt(config.valueLimitPerUse), | ||
paramRules: { | ||
length: BigInt(config.paramRules.length), | ||
rules: config.paramRules.rules.map((rule) => { | ||
if (isHex(rule.ref) && rule.ref.length !== 66) { | ||
throw new Error(ERROR_MESSAGES.INVALID_HEX) | ||
} | ||
return { | ||
condition: rule.condition, | ||
offset: BigInt(rule.offsetIndex) * BigInt(32), | ||
isLimited: rule.isLimited, | ||
ref: rule.ref, | ||
usage: rule.usage | ||
} | ||
}) | ||
} | ||
}) | ||
|
||
export type RawActionConfig = { | ||
valueLimitPerUse: bigint | ||
paramRules: RawParamRules | ||
} | ||
|
||
export type RawParamRules = { | ||
length: bigint | ||
rules: RawParamRule[] | ||
} | ||
|
||
export type RawParamRule = { | ||
condition: ParamCondition | ||
offset: bigint | ||
isLimited: boolean | ||
ref: Hex | ||
usage: LimitUsage | ||
} | ||
|
||
export type LimitUsage = { | ||
limit: bigint | ||
used: bigint | ||
} | ||
|
||
export enum ParamCondition { | ||
EQUAL = 0, | ||
GREATER_THAN = 1, | ||
LESS_THAN = 2, | ||
GREATER_THAN_OR_EQUAL = 3, | ||
LESS_THAN_OR_EQUAL = 4, | ||
NOT_EQUAL = 5 | ||
} | ||
|
||
export type Policy = { | ||
address: Hex | ||
initData: Hex | ||
deInitData: Hex | ||
} | ||
|
||
export type Params = { | ||
token: Address | ||
limit: bigint | ||
}[] | ||
|
||
export const MAX_RULES = 16 | ||
|
||
export const toUniversalActionPolicy = ( | ||
actionConfig: ActionConfig | ||
): Policy => ({ | ||
address: contracts.uniActionPolicy.address, | ||
initData: encodeAbiParameters(contracts.uniActionPolicy.abi, [ | ||
toActionConfig(actionConfig) | ||
]), | ||
deInitData: "0x" | ||
}) | ||
|
||
export const sudoPolicy: Policy = { | ||
address: "0x", | ||
initData: "0x", | ||
deInitData: "0x" | ||
} | ||
|
||
export const toSpendingLimitsPolicy = (params: Params): Policy => { | ||
return { | ||
address: TEST_CONTRACTS.ValueLimitPolicy.address, | ||
initData: encodeAbiParameters( | ||
[{ type: "address[]" }, { type: "uint256[]" }], | ||
[params.map(({ token }) => token), params.map(({ limit }) => limit)] | ||
), | ||
deInitData: "0x" | ||
} | ||
} | ||
|
||
export const policies = { | ||
to: { | ||
universalAction: toUniversalActionPolicy, | ||
spendingLimits: toSpendingLimitsPolicy | ||
}, | ||
sudo: sudoPolicy | ||
} as const | ||
|
||
export default policies |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.