Skip to content

Instantly share code, notes, and snippets.

@michaeljklein
Last active November 1, 2019 19:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaeljklein/a6490e412aba5058932446a5b31e51f6 to your computer and use it in GitHub Desktop.
Save michaeljklein/a6490e412aba5058932446a5b31e51f6 to your computer and use it in GitHub Desktop.

TinyURL for this file: https://tinyurl.com/tezos-sfbw19

Setup

brew tap tqtezos/homebrew-tq https://github.com/tqtezos/homebrew-tq.git
brew install tezos
brew install lorentz-contract-param
brew install lorentz-contracts-sale

Install Ruby

To ensure that Ruby is installed, run which ruby:

$ which ruby
/usr/bin/ruby

The Ruby tools used in this tutorial were tested on:

$ ruby -v                                                                                                                                      $ 
ruby 2.3.7p456 (2018-03-28 revision 63024) [universal.x86_64-darwin18]

Get the sale token files and lorentz-contract-originate

git clone https://github.com/tqtezos/lorentz-contracts-sale.git
cd originations/taco_sale
rm taco_sale_user.originations.yaml

Account setup

Send an account request to michael@tqgroup.io with subject SBFW_NEW_ACCOUNT.

You will receive a line that looks like:

bobs-key-100,edpkunrCtFEkdARBY6tDEAxvpNKGcw2FCgWTX6T5AQNoJaqX6JE9dh,tz1Suah9bipLFo3jNZWwhL7bR9J3DVmnMjvh,unencrypted:edsk3RFfvfE3qxLELeUxzTz1DHfb6NHTTscLs45HnvUcmuisLwTEE5

You will need to add your keys to three files in ~/tezos-client for the client to recognize your account:

  • ~/.tezos-client/public_key_hashes
[ { "name": "bob", "value": "tz1bDC.." } ]

~/.tezos-client/public_keys

[ { "name": "bob",
    "value":
      { "locator":
          "unencrypted:edpkuPT..",
        "key": "edpkuPT.." } } ]

~/.tezos-client/secret_keys

[ { "name": "bob",
    "value":
      "unencrypted:edsk4Bi.." } ]

Config

Edit taco_sale_user.yaml to use your username in the config > user-base-config > user_address field:

config:
  user-base-config: &user-base-config
    tezos_client_path:
      "tezos-client -A ec2-18-190-24-202.us-east-2.compute.amazonaws.com -P 20000"
    user_address:
      tz1[YOUR_ADDRESS_HERE]
    param_path: '.'
    stack_path: null

Optional:

  • Replace Bob with your name (without spaces)
  • Modify the minted amount:
  - run: &mint-token
      alias: MintTokenBob_Bob_100
      config: $user-base-config
      contract: $TokenBob
      command: lorentz-contract-param ManagedLedgerBabylon-mint
      parameters:
        to: $Bob
        value: [AMOUNT_TO_MINT]
      burn_cap: '0.074'

Origination

To originate, run:

../../lorentz-contract-originate.rb taco_sale_user.yaml

It should fail when it reaches SaleToken17_TokenTokenBob_1_1 (we'll get to that in a bit).

If it succeeds in originating your contract taco_sale_user.originated.yaml should contain the address of your new token!

# taco_sale_user.originated.yaml
originated:
  TokenBob:
    address: KT1DFXkKHnbDQwv4PXbk2VDygeBfop6QN55h
    config: "$user-base-config"

Registration

Send the whole taco_sale_user.originated.yaml file to michael@tqgroup.io with subject SBFW_NEW_TOKEN.

I'll then originate a randomly selected sale that will allow you to trade up to Token1, the taco stablecoin.

You'll be able to trade up to 100 of your tokens 1:1 for a randomly selected leaf token in the binary tree.

Completing registration

Once your entry sale-contract is originated, I'll send you a user entry for the do field in your taco_sale_user.yaml file.

It'll look something like this:

  - user:
      name: SaleToken17_TokenTokenBob_1_1
      address: KT1UvFrCuk8oJqbhJQVGPPfUqKo4FBH6okwr

Note: feel free to rename it, as long as you reference the new name when purchasing tokens

Replace the example SaleToken user in your taco_sale_user.yaml (your token won't be authorized to purchase from the one in the example):

# taco_sale_user.yaml
do:
  ..
  - user:
      name: SaleToken17_TokenBob_1_1
      address: KT1UvFrCuk8oJqbhJQVGPPfUqKo4FBH6okwr

Running the rest of taco_sale_user.yaml

If the rest of the taco_sale_user.yaml is unmodified,

It will allow the sale contract to spend all of its tokens:

  - run: &approve
      alias: SaleToken17_TokenBob_1_1_100
      config: $user-base-config
      contract: $TokenBob
      command: lorentz-contract-param ManagedLedgerBabylon-approve
      parameters:
        spender: $SaleToken17_TokenBob_1_1
        value: 100
      burn_cap: '0.031'

And then purchase a single token from the sale contract:

  - run: &purchase
      alias: PurchaseToken17
      config: $user-sale-config
      contract: $SaleToken17_TokenBob_1_1
      command: "lorentz-contracts-sale purchase"
      parameters:
        held-price: "1"
        wanted-price: "1"
      burn_cap:  "0.148"

Finally, it will originate two contracts to store how many tokens you have in your original contract as well as in the contract you just bought tokens from:

  - originate: &originate-nat-storage
      alias: BobPostSaleBalanceToken17
      config: $user-base-config
      command: "lorentz-contract print --name NatStorageContract"
      storage_command: "ruby -e 'puts ARGV[1]' -- "
      initial_storage:
        initial: "0"
      burn_cap:  "0.295"

  - originate:
      <<: *originate-nat-storage
      alias: BobPostSaleBalanceTokenBob
      config: $user-base-config
  - run: &get-balance
      alias: BobPostSaleGetBalanceToken17
      config: $user-base-config
      contract: $Token17
      command: "lorentz-contract-param ManagedLedgerBabylon-getBalance"
      parameters:
        account: $Bob
        callback-contract: $BobPostSaleBalanceToken17
      burn_cap:  "0.000001"

  - run:
      <<: *get-balance
      alias: BobPostSaleGetBalanceTokenBob
      contract: $TokenBob
      parameters:
        callback-contract: $BobPostSaleBalanceTokenBob

There's an example origination of a sale contract commented out at the end of taco_sale_user.yaml, which you can use to offer your own sales:

  - originate: &originate-sale
      alias: SaleTokenBob_Token16
      config: $user-sale-config
      command: lorentz-contracts-sale print
      storage_command: lorentz-contracts-sale init
      initial_storage:
        admin: $Bob
        held: $TokenBob
        wallet: $Bob
        wanted: $Token16
        held-price: '1'
        wanted-price: '2'
      burn_cap: '1.749'

Note: you'll need to approve the new sale contract to spend how ever many tokens you're willing to sell. See do > run: &approve in taco_sale_user.yaml. Until you approve any tokens, it will be able to spend zero of your tokens, and so it will be an offer for zero tokens at the price you set.

@michaeljklein
Copy link
Author

Command to get storage for a contract:

 tezos-client -A ec2-3-133-133-46.us-east-2.compute.amazonaws.com -P 20000 get contract storage for KT1PXscqmUte9vYzn8N1DAHGJwo8NkoMJenz

@michaeljklein
Copy link
Author

tezos-client -A ec2-3-133-133-46.us-east-2.compute.amazonaws.com -P 20000  import secret key bob_test 'unencrypted:edsk...'

@michaeljklein
Copy link
Author

Faucet for testnet account: https://faucet.tzalpha.net
Client setup help: https://assets.tqtezos.com/quickstart/1-index

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment