Skip to content

Commit

Permalink
fix(contracts): allow fulfiller to be the offerer in case of the auct…
Browse files Browse the repository at this point in the history
…ion (#391)

## Description

<!--
Please do not leave this blank.
Describe the changes in this PR. What does it [add/remove/fix/replace]?

For crafting a good description, consider using ChatGPT to help
articulate your changes.
-->

- For auction order, fulfiller and offerer could be the same.
- Renamed some tests
- For auction order, fulfill allowance is check for related order
offerer.

## What type of PR is this? (check all applicable)

- [ ] 🍕 Feature (`feat:`)
- [x] 🐛 Bug Fix (`fix:`)
- [ ] 📝 Documentation Update (`docs:`)
- [ ] 🎨 Style (`style:`)
- [ ] 🧑‍💻 Code Refactor (`refactor:`)
- [ ] 🔥 Performance Improvements (`perf:`)
- [ ] ✅ Test (`test:`)
- [ ] 🤖 Build (`build:`)
- [ ] 🔁 CI (`ci:`)
- [ ] 📦 Chore (`chore:`)
- [ ] ⏩ Revert (`revert:`)
- [ ] 🚀 Breaking Changes (`BREAKING CHANGE:`)

## Related Tickets & Documents

<!--
Please use this format to link related issues: Fixes #<issue_number>
More info:
https://docs.github.com/en/free-pro-team@latest/github/managing-your-work-on-github/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword
-->

## Added tests?

- [x] 👍 yes
- [ ] 🙅 no, because they aren't needed
- [ ] 🙋 no, because I need help

## Added to documentation?

- [ ] 📜 README.md
- [ ] 📓 Documentation
- [x] 🙅 no documentation needed

## [optional] Are there any post-deployment tasks we need to perform?

<!-- Describe any additional tasks, if any, and provide steps. -->

## [optional] What gif best describes this PR or how it makes you feel?

<!-- Share a fun gif related to your PR! -->

### PR Title and Description Guidelines:

- Ensure your PR title follows semantic versioning standards. This helps
automate releases and changelogs.
- Use types like `feat:`, `fix:`, `chore:`, `BREAKING CHANGE:` etc. in
your PR title.
- Your PR title will be used as a commit message when merging. Make sure
it adheres to [Conventional Commits
standards](https://www.conventionalcommits.org/).

## Closing Issues

<!--
Use keywords to close related issues. This ensures that the associated
issues will automatically close when the PR is merged.

- `Fixes #123` will close issue 123 when the PR is merged.
- `Closes #123` will also close issue 123 when the PR is merged.
- `Resolves #123` will also close issue 123 when the PR is merged.

You can also use multiple keywords in one comment:
- `Fixes #123, Resolves #456`

More info:
https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue
-->
  • Loading branch information
ptisserand authored Jun 13, 2024
1 parent c605e22 commit 94fbe7e
Show file tree
Hide file tree
Showing 2 changed files with 194 additions and 40 deletions.
59 changes: 43 additions & 16 deletions contracts/ark_starknet/src/executor.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -410,27 +410,35 @@ mod executor {
if order_info.currency_address.is_zero() {
panic!("Order not found");
}
assert!(order_info.offerer != fulfiller, "Orderer and fulfiller must be different");

if order_info.order_type != OrderType::Auction {
assert!(order_info.offerer != fulfiller, "Offerer and fulfiller must be different");
}

let contract_address = get_contract_address();
match order_info.order_type {
OrderType::Listing => {
_verify_fulfill_listing_order(order_info, fulfill_info, contract_address);
_verify_fulfill_listing_order(self, order_info, fulfill_info, contract_address);
},
OrderType::Offer => {
_verify_fulfill_offer_order(order_info, fulfill_info, contract_address);
_verify_fulfill_offer_order(self, order_info, fulfill_info, contract_address);
},
OrderType::Auction => {
_verify_fulfill_auction_order(order_info, fulfill_info, contract_address);
_verify_fulfill_auction_order(self, order_info, fulfill_info, contract_address);
},
OrderType::CollectionOffer => {
_verify_fulfill_collection_offer_order(order_info, fulfill_info, contract_address);
_verify_fulfill_collection_offer_order(
self, order_info, fulfill_info, contract_address
);
}
}
}

fn _verify_fulfill_listing_order(
order_info: OrderInfo, fulfill_info: @FulfillInfo, contract_address: ContractAddress
self: @ContractState,
order_info: OrderInfo,
fulfill_info: @FulfillInfo,
contract_address: ContractAddress
) {
let fulfiller = *(fulfill_info.fulfiller);
assert!(
Expand Down Expand Up @@ -464,7 +472,10 @@ mod executor {
}

fn _verify_fulfill_offer_order(
order_info: OrderInfo, fulfill_info: @FulfillInfo, contract_address: ContractAddress
self: @ContractState,
order_info: OrderInfo,
fulfill_info: @FulfillInfo,
contract_address: ContractAddress
) {
let fulfiller = *(fulfill_info.fulfiller);
let token_id = match *(fulfill_info.token_id) {
Expand Down Expand Up @@ -501,22 +512,35 @@ mod executor {
}

fn _verify_fulfill_auction_order(
order_info: OrderInfo, fulfill_info: @FulfillInfo, contract_address: ContractAddress
self: @ContractState,
order_info: OrderInfo,
fulfill_info: @FulfillInfo,
contract_address: ContractAddress
) {
let fulfiller = *(fulfill_info.fulfiller);
let related_order_info = match *(fulfill_info.related_order_hash) {
Option::None => panic!("Fulfill auction order require a related order"),
Option::Some(related_order_hash) => self.orders.read(related_order_hash),
};
assert!(
@order_info.currency_address == @related_order_info.currency_address,
"Order and related order use different currency"
);
let buyer = related_order_info.offerer;

assert!(
_check_erc20_amount(@order_info.currency_address, order_info.start_amount, @fulfiller),
"Fulfiller does not own enough ERC20 tokens"
_check_erc20_amount(
@related_order_info.currency_address, related_order_info.start_amount, @buyer
),
"Buyer does not own enough ERC20 tokens"
);
assert!(
_check_erc20_allowance(
@order_info.currency_address,
order_info.start_amount,
@fulfiller,
@related_order_info.currency_address,
related_order_info.start_amount,
@buyer,
@get_contract_address()
),
"Fulfiller's allowance of executor is not enough"
"Buyer's allowance of executor is not enough"
);
assert!(
_check_erc721_owner(
Expand All @@ -536,7 +560,10 @@ mod executor {
}

fn _verify_fulfill_collection_offer_order(
order_info: OrderInfo, fulfill_info: @FulfillInfo, contract_address: ContractAddress
self: @ContractState,
order_info: OrderInfo,
fulfill_info: @FulfillInfo,
contract_address: ContractAddress
) {
let fulfiller = *(fulfill_info.fulfiller);
let token_id = match *(fulfill_info.token_id) {
Expand Down
Loading

0 comments on commit 94fbe7e

Please sign in to comment.