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 permit deadline criteria #74

Merged
merged 2 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ test_contractDeploy {
"intent": {
"from": "eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e",
"type": "deployContract",
"bytecode": "",
"chainId": 137,
},
}

Expand All @@ -15,4 +15,6 @@ test_contractDeploy {

checkSourceAddress({"eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e"}) with input as contractDeployRequest
with data.entities as entities

checkIntentChainId({1, 137}) with input as contractDeployRequest with data.entities as entities
}
48 changes: 48 additions & 0 deletions apps/authz/src/opa/rego/__test__/criteria/intent/permit_test.rego
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package main

test_permit {
permitRequest = {
"action": "signTransaction",
"intent": {
"type": "permit",
"from": "eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e",
"spender": "eip155:137:0xa45e21e9370ba031c5e1f47dedca74a7ce2ed7a3",
"token": "eip155:137/erc20:0x2791bca1f2de4661ed88a30c99a7a9449aa84174",
"amount": "1000000000000000000",
"deadline": "1634025600", # in ms
},
}

checkIntentType({"permit", "permit2"}) with input as permitRequest
with data.entities as entities

checkSourceAddress({"eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e"}) with input as permitRequest
with data.entities as entities

checkIntentSpenderAddress({"eip155:137:0xa45e21e9370ba031c5e1f47dedca74a7ce2ed7a3"}) with input as permitRequest
with data.entities as entities

checkIntentTokenAddress({"eip155:137/erc20:0x2791bca1f2de4661ed88a30c99a7a9449aa84174"}) with input as permitRequest
with data.entities as entities

checkIntentAmount({"currency": wildcard, "operator": "lte", "value": "1000000000000000000"}) with input as permitRequest
with data.entities as entities

checkPermitDeadline({"operator": "eq", "value": "1634025600"}) with input as permitRequest
with data.entities as entities

checkPermitDeadline({"operator": "neq", "value": "111111111"}) with input as permitRequest
with data.entities as entities

checkPermitDeadline({"operator": "lte", "value": "1634025600"}) with input as permitRequest
with data.entities as entities

checkPermitDeadline({"operator": "gte", "value": "1634025600"}) with input as permitRequest
with data.entities as entities

checkPermitDeadline({"operator": "lt", "value": "16340256000"}) with input as permitRequest
with data.entities as entities

checkPermitDeadline({"operator": "gt", "value": "163402560"}) with input as permitRequest
with data.entities as entities
}
12 changes: 6 additions & 6 deletions apps/authz/src/opa/rego/lib/criteria/intent/amount.rego
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,30 @@ intentAmount(currency) = result {

checkIntentAmount(condition) {
condition.operator == "eq"
to_number(condition.value) == intentAmount(condition.currency)
intentAmount(condition.currency) == to_number(condition.value)
}

checkIntentAmount(condition) {
condition.operator == "neq"
to_number(condition.value) != intentAmount(condition.currency)
intentAmount(condition.currency) != to_number(condition.value)
}

checkIntentAmount(condition) {
condition.operator == "gt"
to_number(condition.value) < intentAmount(condition.currency)
intentAmount(condition.currency) > to_number(condition.value)
}

checkIntentAmount(condition) {
condition.operator == "lt"
to_number(condition.value) > intentAmount(condition.currency)
intentAmount(condition.currency) < to_number(condition.value)
}

checkIntentAmount(condition) {
condition.operator == "gte"
to_number(condition.value) <= intentAmount(condition.currency)
intentAmount(condition.currency) >= to_number(condition.value)
}

checkIntentAmount(condition) {
condition.operator == "lte"
to_number(condition.value) >= intentAmount(condition.currency)
intentAmount(condition.currency) <= to_number(condition.value)
}
36 changes: 36 additions & 0 deletions apps/authz/src/opa/rego/lib/criteria/intent/permit.rego
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package main

import future.keywords.in

# convert ms to ns
permitDeadlineMs = to_number(input.intent.deadline)

checkPermitDeadline(condition) {
condition.operator == "eq"
permitDeadlineMs == to_number(condition.value)
}

checkPermitDeadline(condition) {
condition.operator == "neq"
permitDeadlineMs != to_number(condition.value)
}

checkPermitDeadline(condition) {
condition.operator == "lte"
permitDeadlineMs <= to_number(condition.value)
}

checkPermitDeadline(condition) {
condition.operator == "gte"
permitDeadlineMs >= to_number(condition.value)
}

checkPermitDeadline(condition) {
condition.operator == "lt"
permitDeadlineMs < to_number(condition.value)
}

checkPermitDeadline(condition) {
condition.operator == "gt"
permitDeadlineMs > to_number(condition.value)
}
Loading