7

Hi fellow Stellar developers,

My question is, how would I be able to restrict the transfer of let's say 20% of my asset from a persons wallet until 1 year from today.

So lets say I send someone 1,000 exampleAsset. Is there a way I could ensure that they are only able to trade/use/send 800 exampleAsset and must retain 200 exampleAsset until a 2/5/2019, at which time they will be able to then spend the remaining 200 exampleAsset.

My first thoughts on this was that we would be able to add ourselves as a co-signer to the account and have it setup so each transaction has to go through us for signing (our weight would be higher than the persons), but I feel like this is a bit invasive.

Is there an easier, less invasive way to handle this?

2 Answers 2

8

You can do this, but you'll have to create one additional account that supports the process (you can merge it with your account later so it shouldn't be a big problem). Let's say the accounts are as follows:

  • D - your account (Derek)
  • U - user's account
  • S - support account

Then the process looks like this:

  1. You send 800 exampleAsset to U. They can spend it right away.
  2. You generate a new key pair (you control the keys) and create account S.
  3. From account S, you have to create a trust line to your exampleAsset.
  4. You send 200 exampleAsset to S (again, you control the keys so user can't spend the funds).
  5. Now, things start getting interesting:
    1. You create a transaction with the following parameters:
      • Sequence number = Current sequence + 2
      • minTime equal to the time when you want the funds to be released to U
      • Operations:
        • Payment: 200 exampleAsset to U
        • Change Trust: remove exampleAsset trust line
        • Account Merge: merge with D
    2. Then you calculate the hash of the transaction from the previous point and add it as a signer (Pre-authorized Transaction) of account S with weight equal 1 and change master weight to 0. This means that no other transaction will be allowed on this account ever - the network will only accept the transaction from the previous point.

After configuring the account S you can pubish the transaction from 5.1. When the time comes to release the funds anyone (you/your users/bot/other people) can submit this transaction to the network and release the funds.

There are two possible ways for the owner of account U to make this transaction fail - he/she can remove the trust line or their account. You may want to create another transaction: recovery transaction, that will set master weight back to 1 so you can move the funds back to yourself (D).

0
5

You can't freeze a specific amount of an asset on the account.

However there is an approach that might help you with your case. I haven't it tried myself, but in theory it should work.

  1. Send 80% of total amount to user's account.
  2. Create one more account (let's name it "temporary"), establish trustline to your asset and then transfer the remaining 20% to this account.
  3. Prepare a transaction that transfers 20% of your asset from the temporary account to the user account and then merges the temporary account to your account (for example, asset issuing account). Set the desired time bounds for the transaction. You can prepare such transaction with Stellar Laboratory or using the Stellar SDK for a language of your choice. JS code looks like this: new Sdk.TransactionBuilder(account, {minTime: '1527811200', maxTime: '0'}) (transaction will be valid only after June 1, 2018).
  4. Add the hash of the constructed transaction as a signer to the temporary account with weight 2. All thresholds should be also set to 2.

As a result, we have a temporary account with funds locked on it. Nobody can transfer funds or merge account, even if he knows the private key (thresholds value prevents all operations). The only way to unlock it is to submit a special pre-authorized transaction which releases all funds to the user account and returns base reserve to the asset issuer.

Caveats:

  1. This special transaction have to be prepared beforehand with proper sequence number.
  2. You need to pre-authorize the transaction (add the required signature to the envelope). I'm not sure how this can be done with such setup.
  3. The transaction should be stored somewhere (publicly and immutably). Database isn't the best place because your user need to be 100% sure that their fund will be released even if you loose your db as result of a hack or hardware failure.
  4. A temporary account need to be funded with at least 1.5001 XLM (1 XLM to cover minimum balance and 0.5 XLM for additional signer).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.