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

Marketplace contract - trustlines creation #103

Open
2 tasks
eloylp opened this issue Nov 9, 2023 · 3 comments
Open
2 tasks

Marketplace contract - trustlines creation #103

eloylp opened this issue Nov 9, 2023 · 3 comments
Labels
bug Something isn't working research

Comments

@eloylp
Copy link
Member

eloylp commented Nov 9, 2023

Summary

During the development of #90 we realised that we might have to properly declare the trustline relation between the NFTs that are being sold, to the respective buyers or new owners.

As far as we know, trustlines are needed in order to one account to receive balance of an specific stellar asset contract address. This was reflected on this comment links documentation, so we proceeded to create a little script (See #101) that follows those steps and creates the NFT with the indicated trustlines.

  • However, what happens if such trustlines are not pre-defined among buyers and the NFTs ?
  • Do we need some kind of external tool or contract, that would help to stablish such trustlines just before the moment of buying ? (Thus able to receive such balances)

In order to reply to this questions, some checks can be done:

  • From the script we are developing at replace golang with js #101 , check that if we remove one of the buyers trustlines the transfer process fails. Which may indicate the need of another component for stablishing trustlines.
  • If the above point results in transfer failure, investigate how to stablish the trustlines before buying. Check if this can be done from the contract itself or if we need a separate process for that, like the script we did in replace golang with js #101 . Or how to re-use it.

Motivations

We want to provide an end to end solution for an NFT marketplace, thus this research issue will help to stablish what are the new horizons after our initial fix, that may provide more components for building a final Dapp marketplace application.

Final conclusion

Waiting for research.

@geofmureithi
Copy link
Contributor

I did give it a try to see how to approach the specific problem. Here is some code:

const possibleReceiver = "" // ...keypair..
async function addNewTrustLine() {
  let receiver = await server.loadAccount(
    possibleReceiver.publicKey()
  );
  let transaction = new StellarSdk.TransactionBuilder(receiver, {
    networkPassphrase: StellarSdk.Networks.TESTNET,
    fee,
  }).addOperation(
    StellarSdk.Operation.changeTrust({
      asset: eigerNft,
      limit: "0.0000001",
      source: distributorKeyPair.publicKey(),
    })
  );
  transaction.sign(possibleReceiver);
  transaction.sign(distributorKeyPair);
}

This code should work but it still has the same flaws, you need both keypairs of the recipient and the distributor.
Failing to sign with either gives the following error:

data: {
      type: 'https://stellar.org/horizon-errors/transaction_failed',
      title: 'Transaction Failed',
      status: 400,
      detail: 'The transaction failed when submitted to the stellar network. The `extras.result_codes` field on this response contains further details.  Descriptions of each code can be found at: https://developers.stellar.org/api/errors/http-status-codes/horizon-specific/transaction-failed/',
      extras: {
        envelope_xdr: 'AAAAAgAAAAAgIrRAsWtmz2GYHN/hk7YAMah9UShMcCQKJZP4lLVYvAAAAGQAJpjDAAAAAQAAAAEAAAAAAAAAAAAAAABlVGiqAAAAAAAAAAEAAAABAAAAAATzbT6Ypxhjvruur/FETdob/rynR2T3+eul+gfD7lbzAAAABgAAAAJFaWdlck5GVAAAAAAAAAAAhqIkQdi3QuryT3+4Zt6KJCyItppRcFF/gZWmLceGvEcAAAAAAAAAAQAAAAAAAAABlLVYvAAAAEC64KeLNX9ySrQEI3Ko2UjCV3jSoMt8J+92EBgmQKflUaBefhMC0Wym7pRdGCHhhwGA5Lyw2GC3uHxj/H6/OekM',
        result_codes: { transaction: 'tx_failed', operations: [ 'op_bad_auth' ] },
        result_xdr: 'AAAAAAAAAGT/////AAAAAf////8AAAAA'
      }
    }

Considering that this requires the recipient key pair, this is not ideal.
Let me know your thoughts.

@geofmureithi geofmureithi self-assigned this Nov 15, 2023
@eloylp
Copy link
Member Author

eloylp commented Nov 16, 2023

Thanks for the test @geofmureithi . What about signing a transaction in one side (i.e the distributor) and then send it (maybe serialized) to the next party who needs to sign it and in the last step, actually submitting it to the network ?

This would be a multiparty signing process. The transaction just needs to be signed by multiple accounts, but the private keys of such accounts always remains on different machines. Its just the transaction what is needed and passed everywhere, not the private keys.

If the above works, on my mind a solution for this passes with a wallet integration. The marketplace should present the buyers a template transaction already signed by the issuer. Maybe this would be responsibility of each NFT. I dont know, this is a black box for me right now.

@geofmureithi
Copy link
Contributor

What about signing a transaction in one side (i.e the distributor) and then send it (maybe serialized) to the next party who needs to sign it and in the last step, actually submitting it to the network ?

There is no such functionality in stellar as far as I know. The code shown only has a single operation. I don't think your approach is practical right now.

@geofmureithi geofmureithi added the bug Something isn't working label Nov 27, 2023
@geofmureithi geofmureithi removed their assignment Oct 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working research
Projects
None yet
Development

No branches or pull requests

2 participants