Skip to content

Commit

Permalink
Merge pull request #210 from kadena-io/bugfix/deployment
Browse files Browse the repository at this point in the history
Bugfix/deployment
  • Loading branch information
EnoF authored Dec 17, 2024
2 parents 0c61b61 + a3b15e0 commit 5bf80d2
Show file tree
Hide file tree
Showing 4 changed files with 454 additions and 8 deletions.
59 changes: 52 additions & 7 deletions deploy.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,55 @@
},
"sender": "sender00"
},
{
"profile": "default",
"codeFile": "./pact/spirekey-gas-station.pact",
"data": {
"upgrade": false
},
"sender": "sender00"
},
{
"profile": "default",
"code": "(coin.transfer-create \"sender00\" \"senderx\" (read-keyset 'ks) 1000000.0)",
"data": {
"ks": {
"keys": [
"368820f80c324bbc7c2b0610688a7da43e39f91d118732671cd9c7500ff43cca"
],
"pred": "keys-all"
}
},
"sender": "sender00",
"caps": [
[
"coin.TRANSFER",
"sender00",
"senderx",
"1000000.0"
],
[
"coin.GAS"
]
]
},
{
"profile": "default",
"code": "(coin.transfer \"sender00\" \"c:kZqdOJ6B_584lKXJgB8srIVivESgjqLneAA6JYJwrf8\" 100.0)",
"data": {},
"sender": "sender00",
"caps": [
[
"coin.TRANSFER",
"sender00",
"c:kZqdOJ6B_584lKXJgB8srIVivESgjqLneAA6JYJwrf8",
"100.0"
],
[
"coin.GAS"
]
]
},
{
"profile": "default",
"code": "(ns.write-registry \"kip\" (read-keyset 'ks) true)(define-namespace \"kip\" (read-keyset 'ks) (read-keyset 'ks))",
Expand Down Expand Up @@ -172,8 +221,6 @@
},
"sender": "sender00"
},


{
"profile": "default",
"codeFile": "./pact/concrete-policies/collection-policy/collection-policy-v1.pact",
Expand Down Expand Up @@ -224,7 +271,6 @@
},
"sender": "sender00"
},

{
"profile": "default",
"codeFile": "./pact/policy-manager/manager-init.pact",
Expand All @@ -242,14 +288,12 @@
},
"sender": "sender00"
},

{
"profile": "default",
"codeFile": "./pact/util/guards1.pact",
"data": {},
"sender": "sender00"
},

{
"profile": "default",
"codeFile": "./pact/sale-contracts/conventional-auction/conventional-auction.pact",
Expand Down Expand Up @@ -283,10 +327,11 @@
"marmalade-v2.policy-manager.SALE-WHITELIST",
"marmalade-sale.dutch-auction"
],
["coin.GAS"]
[
"coin.GAS"
]
],
"sender": "sender00"
}
]
}

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"author": "",
"license": "ISC",
"devDependencies": {
"@types/node": "^22.7.5"
"@types/node": "^22.7.5",
"tsx": "^4.19.2"
},
"dependencies": {
"@kadena/client": "^1.15.0",
Expand Down
125 changes: 125 additions & 0 deletions pact/spirekey-gas-station.pact
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
(namespace 'kadena)

(module gas-station GOVERNANCE
(implements gas-payer-v1)
(use coin)

(defconst NS_HASH 'kadena)
(defconst NS_KEYSET (keyset-ref-guard "ns-operate-keyset"))
(defconst GAS_STATION_GUARD:guard
(guard-any
[
(create-gas-payer-guard)
NS_KEYSET
]
)
)
(defconst GAS_STATION:string (create-principal GAS_STATION_GUARD))

(defcap GOVERNANCE () (enforce-guard NS_KEYSET))

(defcap GAS_PAYER : bool
( user : string
limit : integer
price : decimal
)
(enforce-one
(format "only {} namespace is paid for" [(read-msg)])
[
(enforce
(try
false
(= (format "({}." [NS_HASH])
(take 44 (at 0 (read-msg 'exec-code))))
)
(format "only {} namespace is paid for" [NS_HASH])
)
(enforce
(try
false
(let ((code (at 0 (read-msg 'exec-code))))
(or
(and
(contains "define-keyset" code)
(contains (format "{}.spirekey.add-device-pair" [NS_HASH]) code)
)
(contains (format "{}.spirekey.remove-device-pair" [NS_HASH]) code)
)
)
)
"Only creation and removal of keypairs allowed"
)
(enforce
(try
false
(= (read-msg 'tx-type) 'cont)
)
"only continuation transactions are paid for"
)
]
)
(enforce-below-or-at-gas-price 0.0000001)
(compose-capability (ALLOW_GAS))
)

; UTIL FUNCTIONS extracted so no additional deploy is necessary
(defun enforce-below-or-at-gas-price:bool (gasPrice:decimal)
(enforce
(<= (chain-gas-price) gasPrice)
(format "Gas Price must be smaller than or equal to {}" [gasPrice])))

(defun guard-any:guard (guards:[guard])
"Create a guard that succeeds if at least one guard in GUARDS is successfully enforced."
(enforce (< 0 (length guards)) "Guard list cannot be empty")
(create-user-guard (enforce-guard-any guards)))

(defun enforce-guard-any:bool (guards:[guard])
"Will succeed if at least one guard in GUARDS is successfully enforced."
(enforce (< 0
(length
(filter
(= true)
(map (try-enforce-guard) guards))))
"None of the guards passed")
)

(defun try-enforce-guard (g:guard)
(try false (enforce-guard g))
)

(defun chain-gas-price ()
"Return gas price from chain-data"
(at 'gas-price (chain-data)))
; END OF UTIL COPY

(defcap ALLOW_GAS () true)

(defun init ()
(coin.create-account GAS_STATION
(guard-any
[
(create-gas-payer-guard)
NS_KEYSET
]
)
)
)

(defun create-gas-payer-guard:guard ()
(create-user-guard (gas-payer-guard))
)

(defun gas-payer-guard ()
(require-capability (GAS))
(require-capability (ALLOW_GAS))
)
)

(if (read-msg 'upgrade)
["upgrade"]
[
(init)
]
)
(enforce-guard NS_KEYSET)
(coin.details GAS_STATION)
Loading

0 comments on commit 5bf80d2

Please sign in to comment.