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

allow withdraw for non-created sales in auction contracts #204

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
15 changes: 12 additions & 3 deletions pact/sale-contracts/conventional-auction/conventional-auction.pact
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,19 @@
)

(defun enforce-withdrawal:bool (sale-id:string)
(with-read auctions sale-id
(with-default-read auctions sale-id
{ 'end-date: -1,
'highest-bid: 0.0 }
{ 'end-date:= end-date,
'highest-bid:= highest-bid
}
(enforce (> (curr-time) end-date) "Auction is still ongoing or hasn't started yet")
(enforce (= highest-bid 0.0) "Bid has been placed, can't withdraw")
(if (= end-date -1)
true
(let ((_ ""))
(enforce (> (curr-time) end-date) "Auction is still ongoing or hasn't started yet")
(enforce (= highest-bid 0.0) "Bid has been placed, can't withdraw")
)
)
)
true
)
Expand Down Expand Up @@ -244,6 +251,7 @@
(install-capability (fungible::TRANSFER (escrow-account sale-id) previous-bidder (fungible::get-balance (escrow-account sale-id))))
(fungible::transfer (escrow-account sale-id) previous-bidder (fungible::get-balance (escrow-account sale-id)))
)
true
)
true
)
Expand All @@ -265,6 +273,7 @@
(mk-account:string (at 'account (fungible::details (at 'mk-account mk-fee-spec)))))
(enforce (!= "" mk-account) "Marketplace fee account does not exist")
(write mk-fees bid-id mk-fee-spec)
true
)
)
(update auctions sale-id { 'highest-bid: bid, 'highest-bid-id: bid-id })
Expand Down
66 changes: 66 additions & 0 deletions pact/sale-contracts/conventional-auction/conventional-auction.repl
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,72 @@
(mint (read-string "token1-id" ) (read-string 'creator) (read-keyset 'creator-guard ) 1.0))
(commit-tx)

(begin-tx "Offer token for sale with wrong sale-price and withdraw")
(env-hash (hash "offer-token-1"))
(use marmalade-v2.ledger)
(use marmalade-v2.policy-manager)
(use marmalade-v2.util-v1)
(use mini-guard-utils)
(use marmalade-sale.conventional-auction)

(env-data {
"token1-id": (create-token-id { 'uri: "conventional-auction-uri-1", 'precision: 0, 'policies: (create-policies DEFAULT_ROYALTY)} ALWAYS-TRUE)
,"creator": "k:e4c6807d79d8bf4695e10e5678ebf72862f59b71f971d39dd3349f4beeacd6e3"
,"quote":{
"fungible": coin
,"sale-price": 2.0
,"seller-fungible-account": {
"account": "k:e4c6807d79d8bf4695e10e5678ebf72862f59b71f971d39dd3349f4beeacd6e3"
,"guard": {"keys": ["e4c6807d79d8bf4695e10e5678ebf72862f59b71f971d39dd3349f4beeacd6e3"], "pred": "keys-all"}
}
,"sale-type": "marmalade-sale.conventional-auction"
}
})

(env-sigs [
{ 'key: 'e4c6807d79d8bf4695e10e5678ebf72862f59b71f971d39dd3349f4beeacd6e3
,'caps: [
(marmalade-v2.ledger.OFFER (read-msg 'token1-id) (read-string 'creator) 1.0 0)]
}])

(expect "Offer token up for sale"
"_vS1Y4nXQavtHxQAUCNDeRzG5Jc8Se22Ocg4RNP5B2Y"
(sale (read-msg 'token1-id) (read-string 'creator) 1.0 0))

(env-data {
"sale-id": "_vS1Y4nXQavtHxQAUCNDeRzG5Jc8Se22Ocg4RNP5B2Y",
"token1-id": (create-token-id { 'uri: "conventional-auction-uri-1", 'precision: 0, 'policies: (create-policies DEFAULT_ROYALTY)} ALWAYS-TRUE)
})

(env-sigs [
{ 'key: 'e4c6807d79d8bf4695e10e5678ebf72862f59b71f971d39dd3349f4beeacd6e3
,'caps: [(MANAGE_AUCTION (read-msg 'sale-id) (read-msg 'token1-id))]
}])

(env-data {
"sale-id": "_vS1Y4nXQavtHxQAUCNDeRzG5Jc8Se22Ocg4RNP5B2Y",
"token1-id": (create-token-id { 'uri: "conventional-auction-uri-1", 'precision: 0, 'policies: (create-policies DEFAULT_ROYALTY)} ALWAYS-TRUE),
"seller": "k:e4c6807d79d8bf4695e10e5678ebf72862f59b71f971d39dd3349f4beeacd6e3"
})

(expect-failure "Create a conventional auction fails because sale-price was not 0.0"
"Quote price must be 0"
(create-auction (read-string "sale-id") (read-string "token1-id") 1696204800 1696723200 50.0)
)

(env-sigs [
{ 'key: 'e4c6807d79d8bf4695e10e5678ebf72862f59b71f971d39dd3349f4beeacd6e3
,'caps: [(marmalade-v2.ledger.WITHDRAW (read-msg 'token1-id) (read-string 'seller) 1.0 0 (read-msg 'sale-id))]
}
])

(expect "withdrawing after the auction has ended withoud bids succeed"
"_vS1Y4nXQavtHxQAUCNDeRzG5Jc8Se22Ocg4RNP5B2Y"
(continue-pact 0 true (read-msg 'sale-id))
)

(rollback-tx)

(begin-tx "Offer token for sale with the conventional auction sale type and a non-finalized price")
(env-hash (hash "offer-token-1"))
(use marmalade-v2.ledger)
Expand Down
15 changes: 11 additions & 4 deletions pact/sale-contracts/dutch-auction/dutch-auction.pact
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
@event
true
)

(defcap PRICE_ACCEPTED:bool
( sale-id:string
token-id:string
Expand Down Expand Up @@ -95,12 +95,19 @@
)

(defun enforce-withdrawal:bool (sale-id:string)
(with-read auctions sale-id
(with-default-read auctions sale-id
{ 'end-date: -1,
'sell-price: 0.0 }
{ 'end-date:= end-date,
'sell-price:= sell-price
}
(enforce (> (curr-time) end-date) "Auction is still ongoing or hasn't started yet")
(enforce (= sell-price 0.0) "Price has been accepted, can't withdraw")
(if (= end-date -1)
true
(let ((_ ""))
(enforce (> (curr-time) end-date) "Auction is still ongoing or hasn't started yet")
(enforce (= sell-price 0.0) "Price has been accepted, can't withdraw")
)
)
)
true
)
Expand Down
65 changes: 65 additions & 0 deletions pact/sale-contracts/dutch-auction/dutch-auction.repl
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,71 @@
(mint (read-string "token1-id" ) "k:05df86b4fda15ac84cdd2ab4facb433db6098d10b6b09803eedbaea78d10723e" (read-keyset 'creator-guard ) 1.0))
(commit-tx)

(begin-tx "Offer token for sale with wrong sale-price and withdraw")
(env-hash (hash "offer-token-1"))
(use marmalade-v2.ledger)
(use marmalade-v2.policy-manager)
(use marmalade-v2.util-v1)
(use mini-guard-utils)
(use marmalade-sale.dutch-auction)

(env-data {
"token1-id": (create-token-id { 'uri: "dutch-auction-uri-1", 'precision: 0, 'policies: (create-policies DEFAULT_ROYALTY)} ALWAYS-TRUE)
,"quote":{
"fungible": coin
,"sale-price": 10.0
,"seller-fungible-account": {
"account": "k:05df86b4fda15ac84cdd2ab4facb433db6098d10b6b09803eedbaea78d10723e"
,"guard": {"keys": ["05df86b4fda15ac84cdd2ab4facb433db6098d10b6b09803eedbaea78d10723e"], "pred": "keys-all"}
}
,"sale-type": "marmalade-sale.dutch-auction"
}
})

(env-sigs [
{ 'key: "05df86b4fda15ac84cdd2ab4facb433db6098d10b6b09803eedbaea78d10723e"
,'caps: [
(marmalade-v2.ledger.OFFER (read-msg 'token1-id) "k:05df86b4fda15ac84cdd2ab4facb433db6098d10b6b09803eedbaea78d10723e" 1.0 0)]
}])

(expect "Offer token up for sale"
"_vS1Y4nXQavtHxQAUCNDeRzG5Jc8Se22Ocg4RNP5B2Y"
(sale (read-msg 'token1-id) "k:05df86b4fda15ac84cdd2ab4facb433db6098d10b6b09803eedbaea78d10723e" 1.0 0))

(env-data {
"sale-id": "_vS1Y4nXQavtHxQAUCNDeRzG5Jc8Se22Ocg4RNP5B2Y",
"token1-id": (create-token-id { 'uri: "dutch-auction-uri-1", 'precision: 0, 'policies: (create-policies DEFAULT_ROYALTY)} ALWAYS-TRUE)
})

(env-sigs [
{ 'key: "05df86b4fda15ac84cdd2ab4facb433db6098d10b6b09803eedbaea78d10723e"
,'caps: [(MANAGE_AUCTION (read-msg 'sale-id) (read-msg 'token1-id))]
}])

(env-data {
"sale-id": "_vS1Y4nXQavtHxQAUCNDeRzG5Jc8Se22Ocg4RNP5B2Y",
"token1-id": (create-token-id { 'uri: "dutch-auction-uri-1", 'precision: 0, 'policies: (create-policies DEFAULT_ROYALTY)} ALWAYS-TRUE),
"seller": "k:05df86b4fda15ac84cdd2ab4facb433db6098d10b6b09803eedbaea78d10723e"
})

(expect-failure "Create a dutch auction fails because sale-price was not 0.0"
"Quote price must be 0"
(create-auction (read-string "sale-id") (read-string "token1-id") 1696204800 1696723200 50.0 100.0 3600)
)

(env-sigs [
{ 'key: "05df86b4fda15ac84cdd2ab4facb433db6098d10b6b09803eedbaea78d10723e"
,'caps: [(marmalade-v2.ledger.WITHDRAW (read-msg 'token1-id) (read-string 'seller) 1.0 0 (read-msg 'sale-id))]
}
])

(expect "withdrawing after the auction has ended withoud bids succeed"
"_vS1Y4nXQavtHxQAUCNDeRzG5Jc8Se22Ocg4RNP5B2Y"
(continue-pact 0 true (read-msg 'sale-id))
)

(rollback-tx)

(begin-tx "Offer token for sale with the dutch auction sale type and a non-finalized price")
(env-hash (hash "offer-token-1"))
(use marmalade-v2.ledger)
Expand Down
Loading