Skip to content

Commit

Permalink
feat: Deferred and Marketplace methods to always guarantee to buy the…
Browse files Browse the repository at this point in the history
… next token
  • Loading branch information
veeso committed Dec 5, 2024
1 parent 807ebff commit 8ee16f2
Show file tree
Hide file tree
Showing 10 changed files with 976 additions and 184 deletions.
7 changes: 7 additions & 0 deletions docs/contracts/Deferred.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,11 @@ The tokens are eventually phyisically minted when they are first bought. So when

It's important to know that **Deferred ERC721 can't be transferred by the token owner**, but only by the [Marketplace](./Marketplace.md). The marketplace is always allowed to transfer tokens, while the user is never allowed to. It's neither allowed to call `approve` on the contract.

The Marketplace calls the `transferToken` which will transfer the next `token` for the provided contract id for the buyer to get. This means that:

1. If the buyer is the contract buyer, this will get the next token id owned by the first third-party investor, or if none the contract seller.
2. If the buyer is a third-party investor, this will get the next token id owned by the contract seller.

Others methods like `transferFrom` or `safeTransferFrom` are disabled

This is of course done to prevent users from selling the tokens breaking their intrisic price, defined at the contract creation. The **token price will never change**.
8 changes: 5 additions & 3 deletions docs/contracts/Marketplace.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,18 @@ If the Buyer of the contract buys the token, he will pay the token price plus th

## Buy process

The Marketplace contract provides two functions useful to buy a process, the `buyToken` method and the `tokenPriceForCaller` view method.
The Marketplace contract provides two functions useful to buy a process, the `buyNextToken` method and the `tokenPriceForCaller` view method.

`buyNextToken` will always buy the next token available to be bought for the contract.

```solidity
function tokenPriceForCaller(
uint256 _tokenId
uint256 _contractId
) external view returns (uint256) {}
```

```solidity
function buyToken(uint256 _tokenId) external {}
function buyNextToken(uint256 _contractId) external {}
```

So the buy process is divided in two parts.
Expand Down
211 changes: 202 additions & 9 deletions ethereum/app/src/js/web3/contracts/Deferred.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,44 @@ export const ABI = [
stateMutability: 'nonpayable',
type: 'function',
},
{
inputs: [
{
internalType: 'uint256',
name: '_contractId',
type: 'uint256',
},
],
name: 'contractCompleted',
outputs: [
{
internalType: 'bool',
name: 'completed',
type: 'bool',
},
],
stateMutability: 'view',
type: 'function',
},
{
inputs: [
{
internalType: 'uint256',
name: '_contractId',
type: 'uint256',
},
],
name: 'contractProgress',
outputs: [
{
internalType: 'uint256',
name: '_progress',
type: 'uint256',
},
],
stateMutability: 'view',
type: 'function',
},
{
inputs: [
{
Expand Down Expand Up @@ -459,6 +497,89 @@ export const ABI = [
stateMutability: 'view',
type: 'function',
},
{
inputs: [
{
internalType: 'uint256',
name: '_contractId',
type: 'uint256',
},
],
name: 'getContract',
outputs: [
{
components: [
{
internalType: 'string',
name: 'metadataUri',
type: 'string',
},
{
components: [
{
internalType: 'address',
name: 'seller',
type: 'address',
},
{
internalType: 'uint256',
name: 'tokenFromId',
type: 'uint256',
},
{
internalType: 'uint256',
name: 'tokenToId',
type: 'uint256',
},
],
internalType: 'struct Deferred.Seller[]',
name: 'sellers',
type: 'tuple[]',
},
{
internalType: 'address[]',
name: 'buyers',
type: 'address[]',
},
{
internalType: 'uint256',
name: 'ekokeReward',
type: 'uint256',
},
{
internalType: 'uint256',
name: 'tokenPriceUsd',
type: 'uint256',
},
{
internalType: 'uint256',
name: 'tokenFromId',
type: 'uint256',
},
{
internalType: 'uint256',
name: 'tokenToId',
type: 'uint256',
},
{
internalType: 'bool',
name: 'closed',
type: 'bool',
},
{
internalType: 'bool',
name: 'created',
type: 'bool',
},
],
internalType: 'struct Deferred.SellContract',
name: '_sellContract',
type: 'tuple',
},
],
stateMutability: 'view',
type: 'function',
},
{
inputs: [
{
Expand Down Expand Up @@ -509,6 +630,49 @@ export const ABI = [
stateMutability: 'view',
type: 'function',
},
{
inputs: [
{
internalType: 'uint256',
name: '_contractId',
type: 'uint256',
},
],
name: 'nextTokenIdToBuy',
outputs: [
{
internalType: 'uint256',
name: '_nextTokenId',
type: 'uint256',
},
],
stateMutability: 'view',
type: 'function',
},
{
inputs: [
{
internalType: 'uint256',
name: '_contractId',
type: 'uint256',
},
{
internalType: 'address',
name: '_caller',
type: 'address',
},
],
name: 'nextTokenIdToBuyFor',
outputs: [
{
internalType: 'uint256',
name: '',
type: 'uint256',
},
],
stateMutability: 'view',
type: 'function',
},
{
inputs: [],
name: 'owner',
Expand Down Expand Up @@ -588,28 +752,28 @@ export const ABI = [
inputs: [
{
internalType: 'address',
name: 'from',
name: '',
type: 'address',
},
{
internalType: 'address',
name: 'to',
name: '',
type: 'address',
},
{
internalType: 'uint256',
name: 'tokenId',
name: '',
type: 'uint256',
},
{
internalType: 'bytes',
name: 'data',
name: '',
type: 'bytes',
},
],
name: 'safeTransferFrom',
outputs: [],
stateMutability: 'nonpayable',
stateMutability: 'pure',
type: 'function',
},
{
Expand Down Expand Up @@ -787,23 +951,23 @@ export const ABI = [
inputs: [
{
internalType: 'address',
name: 'from',
name: '',
type: 'address',
},
{
internalType: 'address',
name: 'to',
name: '',
type: 'address',
},
{
internalType: 'uint256',
name: 'tokenId',
name: '',
type: 'uint256',
},
],
name: 'transferFrom',
outputs: [],
stateMutability: 'nonpayable',
stateMutability: 'pure',
type: 'function',
},
{
Expand All @@ -819,6 +983,35 @@ export const ABI = [
stateMutability: 'nonpayable',
type: 'function',
},
{
inputs: [
{
internalType: 'uint256',
name: '_contractId',
type: 'uint256',
},
{
internalType: 'address',
name: 'from',
type: 'address',
},
{
internalType: 'address',
name: 'to',
type: 'address',
},
],
name: 'transferToken',
outputs: [
{
internalType: 'uint256',
name: '_tokenId',
type: 'uint256',
},
],
stateMutability: 'nonpayable',
type: 'function',
},
];

interface ContractAddress {
Expand Down
37 changes: 34 additions & 3 deletions ethereum/app/src/js/web3/contracts/Marketplace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ export const ABI = [
name: 'seller',
type: 'address',
},
{
indexed: false,
internalType: 'uint256',
name: 'contractId',
type: 'uint256',
},
{
indexed: false,
internalType: 'uint256',
Expand Down Expand Up @@ -135,12 +141,18 @@ export const ABI = [
inputs: [
{
internalType: 'uint256',
name: '_tokenId',
name: '_contractId',
type: 'uint256',
},
],
name: 'buyNextToken',
outputs: [
{
internalType: 'uint256',
name: 'tokenId',
type: 'uint256',
},
],
name: 'buyToken',
outputs: [],
stateMutability: 'nonpayable',
type: 'function',
},
Expand Down Expand Up @@ -177,6 +189,25 @@ export const ABI = [
stateMutability: 'nonpayable',
type: 'function',
},
{
inputs: [
{
internalType: 'uint256',
name: '_contractId',
type: 'uint256',
},
],
name: 'tokenPriceForCaller',
outputs: [
{
internalType: 'uint256',
name: '',
type: 'uint256',
},
],
stateMutability: 'view',
type: 'function',
},
{
inputs: [
{
Expand Down
Loading

0 comments on commit 8ee16f2

Please sign in to comment.