-
Notifications
You must be signed in to change notification settings - Fork 0
/
investor.rb
101 lines (90 loc) · 2.27 KB
/
investor.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
require 'rubygems'
require 'bundler/setup'
require "stellar-sdk"
require "stellar-base"
include Stellar::DSL
### Network
horizon_client = Stellar::Client.default_testnet
### Accounts
issuer = Stellar::KeyPair.random
horizon_client.friendbot(issuer)
distributor = KeyPair()
investor = KeyPair()
### Config ICO
ico_name = "BOX"
asset = Asset("#{ico_name}-#{issuer.address}")
lumens = Asset("XLM-native")
max_supply = 1000000
initial_price = 1
#Build TXS
seq_num = horizon_client.account_info(issuer.address).sequence.to_i
tb = Stellar::TransactionBuilder.new(
source_account: issuer,
sequence_number: seq_num + 1
).add_operation(
Stellar::Operation.create_account(
destination: distributor,
starting_balance: 100
)
).add_operation(
Stellar::Operation.create_account(
destination: investor,
starting_balance: 1000
)
).add_operation(
Stellar::Operation.change_trust(
source_account: distributor,
line: asset,
limit: max_supply
)
).add_operation(
Stellar::Operation.payment(
source_account: issuer,
destination: distributor,
amount: [asset, max_supply]
)
).add_operation(
Stellar::Operation.set_options({
source_account: issuer,
master_weight: 0,
low_threshold: 1,
med_threshold: 1,
high_threshold: 1
})).add_operation(
Stellar::Operation.manage_sell_offer(
source_account: distributor,
selling: asset,
buying: lumens,
amount: max_supply,
price: initial_price
)
).add_operation(
Stellar::Operation.change_trust(
source_account: investor,
line: asset,
limit: 20
)
).add_operation(
Stellar::Operation.manage_buy_offer(
source_account: investor,
selling: lumens,
buying: asset,
amount: 10,
price: initial_price
)
)
#Send TXS
tx = tb.build
envelope = tx.to_envelope(issuer, distributor, investor)
response = horizon_client.submit_transaction(tx_envelope: envelope)
p "Transaction was submitted successfully. It's hash is #{response.id}\n\n"
# OutTheBox
p "=== Issuer Account"
p "Address: #{issuer.address}"
p "Seed: #{issuer.seed}"
p "=== Distributor Account"
p "Address: #{distributor.address}"
p "Seed: #{distributor.seed}"
p "=== Investor Account"
p "Address: #{investor.address}"
p "Seed: #{investor.seed}"