ton-sdk-ruby-smc 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: bb2ae454e34d3c6222b872cb2c513be364d6222e94c1ad82603be1e867cf513d
4
+ data.tar.gz: 73b44d07251370ebb6bce667b6f6be1a5b12e3fdc7d66d28e4bf96e0eaccea9e
5
+ SHA512:
6
+ metadata.gz: 342353755d75c2dc567bf62d3b66607f93c6de90f8f473e02779564973af5a634e08755458f94e8729afedc161a3cf42c5714749958c654b1b6ef351cede4cfd
7
+ data.tar.gz: 97484b6b86681154a430798ba241bf73f697735d5d59760a4ccb414483c795405cab10da1e182e10712f1155994bfc82fac8b040b741a2813d314a7c989163e4
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ GEM_DIR = File.dirname(__FILE__) + '/..'
4
+
5
+ if ARGV[0] == 'start'
6
+ p 'start'
7
+ end
@@ -0,0 +1,11 @@
1
+ module TonSdkRubySmc
2
+ TOKEN_ATTRIBUTES_SHA256 = {
3
+ uri: "70e5d7b6a29b392f85076fe15ca2f2053c56c2338728c4e33c9e8ddb1ee827cc",
4
+ name: "82a3537ff0dbce7eec35d69edc3a189ee6f17d82f353a553f9aa96cb0be3ce89",
5
+ description: "c9046f7a37ad0ea7cee73355984fa5428982f8b37c8f7bcec91f7ac71a7cd104",
6
+ image: "6105d6cc76af400325e94d588ce511be5bfdbb73b437dc51eca43917d7a43e3d",
7
+ image_data: "d9a88ccec79eef59c84b671136a20ece4cd00caaad5bc47e2c208829154ee9e4",
8
+ symbol: "b76a7ca153c24671658335bbd08946350ffc621fa1c516e7123095d4ffd5c581",
9
+ decimals: "ee80fd2f1e03480e2282363596ee752d7bb27f50776b95086a0279189675923e"
10
+ }
11
+ end
@@ -0,0 +1,5 @@
1
+ module TonSdkRubySmc
2
+ def require_type(name, value, type)
3
+ raise "#{name} must be #{type}" unless value.is_a?(type)
4
+ end
5
+ end
@@ -0,0 +1,82 @@
1
+ =begin
2
+ ton-sdk-ruby-smc – commonly used tvm contracts ruby package
3
+
4
+ Copyright (C) 2023 Oleh Hudeichuk
5
+
6
+ This file is part of ton-sdk-ruby-smc.
7
+
8
+ ton-sdk-ruby-smc is free software: you can redistribute it and/or modify
9
+ it under the terms of the GNU Lesser General Public License as
10
+ published by the Free Software Foundation, either version 3 of
11
+ the License, or (at your option) any later version.
12
+
13
+ ton-sdk-ruby-smc is distributed in the hope that it will be useful,
14
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ GNU Lesser General Public License for more details.
17
+
18
+ You should have received a copy of the GNU Lesser General Public License
19
+ along with ton-sdk-ruby-smc. If not, see <https://www.gnu.org/licenses/>.
20
+
21
+
22
+ =end
23
+
24
+ module TonSdkRubySmc
25
+ include TonSdkRuby
26
+
27
+ class Jetton
28
+
29
+ =begin
30
+ transfer#0f8a7ea5 query_id:uint64 amount:(VarUInteger 16) destination:MsgAddress
31
+ response_destination:MsgAddress custom_payload:(Maybe ^Cell)
32
+ forward_ton_amount:(VarUInteger 16) forward_payload:(Either Cell ^Cell)
33
+ = InternalMsgBody;
34
+ =end
35
+ def self.build_transfer(query_id, amount, destination, response_destionation, forward_ton_amount, forward_payload, custom_payload = nil)
36
+ require_type('query_id', query_id, Integer)
37
+ require_type('amount', amount, Coins)
38
+ require_type('destination', destination, Address)
39
+ require_type('response_destionation', response_destionation, Address)
40
+ require_type('forward_ton_amount', forward_ton_amount, Coins)
41
+ require_type('forward_payload', forward_payload, Cell)
42
+ require_type('custom_payload', custom_payload, Cell) unless custom_payload.nil?
43
+
44
+ body = Builder.new
45
+ body.store_uint(0x0f8a7ea5, 32)
46
+ body.store_uint(query_id, 64)
47
+ body.store_coins(amount)
48
+ body.store_address(destination)
49
+ body.store_address(response_destionation)
50
+ body.store_maybe_ref(custom_payload)
51
+ body.store_coins(forward_ton_amount)
52
+ if (body.bits.size + forward_payload.bits.size > 1023) || body.refs.size + forward_payload.refs.size > 4
53
+ body.store_bit(1)
54
+ body.store_ref(forward_payload)
55
+ else
56
+ body.store_bit(0)
57
+ body.store_slice(forward_payload.parse)
58
+ end
59
+ body.cell
60
+ end
61
+
62
+ =begin
63
+ burn#595f07bc query_id:uint64 amount:(VarUInteger 16)
64
+ response_destination:MsgAddress custom_payload:(Maybe ^Cell)
65
+ = InternalMsgBody;
66
+ =end
67
+ def self.build_burn(query_id, amount, response_destination, custom_payload = nil)
68
+ require_type('query_id', query_id, Integer)
69
+ require_type('amount', amount, Coins)
70
+ require_type('response_destionation', response_destionation, Address)
71
+ require_type('custom_payload', custom_payload, Cell) unless custom_payload.nil?
72
+
73
+ body = Builder.new
74
+ body.store_uint(0x595f07bc, 32)
75
+ body.store_uint(query_id, 64)
76
+ body.store_coins(amount)
77
+ body.store_address(response_destionation)
78
+ body.store_maybe_ref(custom_payload)
79
+ body.cell
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,61 @@
1
+ module TonSdkRubySmc
2
+ include TonSdkRuby
3
+
4
+ class MetaData
5
+ def self.parse_token_metadata(da_slice)
6
+ require_type('da_slice', da_slice, Slice)
7
+ pum_purum_tag = da_slice.load_uint(8)
8
+ result = {}
9
+ if pum_purum_tag == 0x01
10
+ result[:tag] = 'offchain'
11
+ result[:data] = parse_off_chain_metadata(da_slice)
12
+ result
13
+ else
14
+ result[:tag] = 'onchain'
15
+ result[:data] = parse_on_chain_metadata(da_slice)
16
+ result
17
+ end
18
+ end
19
+
20
+ private
21
+
22
+ def self.parse_on_chain_metadata(slice)
23
+ deserializers = {
24
+ key: -> (k) do
25
+ slice = Slice.parse(Builder.new.store_bits(k).cell)
26
+ just_value = slice.load_bytes(32)
27
+ bytes_to_hex(just_value)
28
+ end,
29
+ value: -> (v) do
30
+ v.parse.load_ref
31
+ end
32
+ }
33
+
34
+ result_vot_da = {}
35
+ dick = slice.load_dict(256, {deserializers: deserializers})
36
+ dick.each do |key, value|
37
+ TOKEN_ATTRIBUTES_SHA256.each do |name, hash|
38
+ if hash == key
39
+ cs = value.parse
40
+ da_content_tag = cs.load_uint(8)
41
+ if da_content_tag == 0x00
42
+ result_vot_da[name] = parse_off_chain_metadata(cs)
43
+ else
44
+ raise 'Chuncked data unsupported'
45
+ end
46
+ end
47
+ end
48
+ end
49
+ result_vot_da
50
+ end
51
+
52
+ def self.parse_off_chain_metadata(slice)
53
+ string = slice.load_string(slice.bits.size / 8)
54
+ while slice.refs.size > 0
55
+ slice = slice.load_ref.parse
56
+ string += slice.load_string(slice.bits.size / 8)
57
+ end
58
+ string
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,60 @@
1
+ =begin
2
+ ton-sdk-ruby-smc – commonly used tvm contracts ruby package
3
+
4
+ Copyright (C) 2023 Oleh Hudeichuk
5
+
6
+ This file is part of ton-sdk-ruby-smc.
7
+
8
+ ton-sdk-ruby-smc is free software: you can redistribute it and/or modify
9
+ it under the terms of the GNU Lesser General Public License as
10
+ published by the Free Software Foundation, either version 3 of
11
+ the License, or (at your option) any later version.
12
+
13
+ ton-sdk-ruby-smc is distributed in the hope that it will be useful,
14
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ GNU Lesser General Public License for more details.
17
+
18
+ You should have received a copy of the GNU Lesser General Public License
19
+ along with ton-sdk-ruby-smc. If not, see <https://www.gnu.org/licenses/>.
20
+
21
+
22
+ =end
23
+
24
+ module TonSdkRubySmc
25
+ include TonSdkRuby
26
+
27
+ class NFT
28
+
29
+ =begin
30
+ transfer#5fcc3d14 query_id:uint64 new_owner:MsgAddress response_destination:MsgAddress
31
+ custom_payload:(Maybe ^Cell) forward_amount:(VarUInteger 16)
32
+ forward_payload:(Either Cell ^Cell) = InternalMsgBody;
33
+ =end
34
+ def self.build_transfer(query_id, new_owner, response_destination, forward_amount, forward_payload, custom_payload = nil)
35
+ require_type('query_id', query_id, Integer)
36
+ require_type('new_owner', new_owner, Address)
37
+ require_type('response_destionation', response_destionation, Address)
38
+ require_type('custom_payload', custom_payload, Cell) unless custom_payload.nil?
39
+ require_type('forward_amount', forward_amount, Coins)
40
+ require_type('forward_payload', forward_payload, Cell)
41
+
42
+ body = Builder.new
43
+ body.store_uint(0x5fcc3d14, 32)
44
+ body.store_uint(query_id, 64)
45
+ body.store_address(new_owner)
46
+ body.store_address(response_destionation)
47
+ body.store_maybe_ref(custom_payload)
48
+ body.store_coins(forward_amount)
49
+
50
+ if (body.bits.size + forward_payload.bits.size > 1023) || body.refs.size + forward_payload.refs.size > 4
51
+ body.store_bit(1)
52
+ body.store_ref(forward_payload)
53
+ else
54
+ body.store_bit(0)
55
+ body.store_slice(forward_payload.parse)
56
+ end
57
+ body.cell
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,27 @@
1
+ =begin
2
+ ton-sdk-ruby-smc – commonly used tvm contracts ruby package
3
+
4
+ Copyright (C) 2023 Oleh Hudeichuk
5
+
6
+ This file is part of ton-sdk-ruby-smc.
7
+
8
+ ton-sdk-ruby-smc is free software: you can redistribute it and/or modify
9
+ it under the terms of the GNU Lesser General Public License as
10
+ published by the Free Software Foundation, either version 3 of
11
+ the License, or (at your option) any later version.
12
+
13
+ ton-sdk-ruby-smc is distributed in the hope that it will be useful,
14
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ GNU Lesser General Public License for more details.
17
+
18
+ You should have received a copy of the GNU Lesser General Public License
19
+ along with ton-sdk-ruby-smc. If not, see <https://www.gnu.org/licenses/>.
20
+
21
+
22
+ =end
23
+
24
+ module TonSdkRubySmc
25
+ VERSION = "0.0.1"
26
+
27
+ end
@@ -0,0 +1,176 @@
1
+ =begin
2
+ ton-sdk-ruby-smc – commonly used tvm contracts ruby package
3
+
4
+ Copyright (C) 2023 Oleh Hudeichuk
5
+
6
+ This file is part of ton-sdk-ruby-smc.
7
+
8
+ ton-sdk-ruby-smc is free software: you can redistribute it and/or modify
9
+ it under the terms of the GNU Lesser General Public License as
10
+ published by the Free Software Foundation, either version 3 of
11
+ the License, or (at your option) any later version.
12
+
13
+ ton-sdk-ruby-smc is distributed in the hope that it will be useful,
14
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ GNU Lesser General Public License for more details.
17
+
18
+ You should have received a copy of the GNU Lesser General Public License
19
+ along with ton-sdk-ruby-smc. If not, see <https://www.gnu.org/licenses/>.
20
+
21
+
22
+ =end
23
+
24
+ =begin
25
+ The source code and LICENSE of the "ton-preprocessed-wallet-v2":
26
+ https://github.com/pyAndr3w/ton-preprocessed-wallet-v2
27
+
28
+ "PWV2_CODE = ..." is a compiled version (byte code) of
29
+ the "ton-preprocessed-wallet-v2" in the bag of cells
30
+ serialization in hexadecimal representation.
31
+
32
+ code cell hash(sha256): 45EBBCE9B5D235886CB6BFE1C3AD93B708DE058244892365C9EE0DFE439CB7B5
33
+
34
+ Respect the rights of open source software. Thanks!
35
+ If you notice copyright violation, please create an issue.
36
+ https://github.com/nerzh/ton-sdk-ruby-smc/issues
37
+ =end
38
+
39
+ module TonSdkRubySmc
40
+ include TonSdkRuby
41
+
42
+ PWV2_CODE = 'B5EE9C7241010101003D000076FF00DDD40120F90001D0D33FD30FD74CED44D0D3FFD70B0F20A4830FA90822C8CBFFCB0FC9ED5444301046BAF2A1F823BEF2A2F910F2A3F800ED552E766412'
43
+
44
+ class PWV2Transfer
45
+ attr_accessor :destination, :bounce, :value, :mode, :body, :init
46
+
47
+ def initialize(destination, bounce, value, mode, body = nil, init = nil)
48
+ @destination = destination # Address
49
+ @bounce = bounce # Boolean
50
+ @value = value # Coins
51
+ @mode = mode # Integer
52
+ @body = body # Cell
53
+ @init = init # StateInit
54
+ end
55
+ end
56
+
57
+ class PWV2
58
+ attr_accessor :code, :pubkey, :init, :address
59
+
60
+ def initialize(pubkey, wc = 0)
61
+ @pubkey = pubkey
62
+ @code = deserialize(hex_to_bytes(PWV2_CODE)).first
63
+ @init = build_state_init
64
+ @address = Address.new("#{wc}:#{init.cell.hash}")
65
+ end
66
+
67
+ def self.parse_storage(storage_slice)
68
+ {
69
+ pubkey: storage_slice.load_bytes(32),
70
+ seqno: storage_slice.load_uint(16)
71
+ }
72
+ end
73
+
74
+ def build_transfer(transfers, seqno, private_key, is_init = false, timeout = 60)
75
+ raise 'Transfers must be an [PWV2Transfer]' unless transfers.size > 0 && transfers.first.is_a?(PWV2Transfer)
76
+ raise "PWV2 can handle only 255 transfers at once" unless transfers.size <= 255
77
+ actions = []
78
+
79
+ transfers.each do |t|
80
+ info = CommonMsgInfo.new(
81
+ IntMsgInfo.new(
82
+ tag: 'int_msg_info',
83
+ dest: t.destination,
84
+ bounce: t.bounce,
85
+ value: t.value
86
+ )
87
+ )
88
+
89
+ action = OutAction.new(
90
+ ActionSendMsg.new(
91
+ tag: 'action_send_msg',
92
+ mode: t.mode,
93
+ out_msg: Message.new(
94
+ MessageOptions.new(
95
+ info: info,
96
+ body: t.body,
97
+ init: t.init
98
+ )
99
+ )
100
+ )
101
+ )
102
+
103
+ actions.push(action)
104
+ end
105
+
106
+ outlist = OutList.new(OutListOptions.new(actions: actions))
107
+
108
+ msg_inner = Builder.new
109
+ # .store_uint((Time.now.to_i + timeout).to_s, 64)
110
+ .store_uint((1000 + timeout).to_s, 64)
111
+ .store_uint(seqno.to_s, 16)
112
+ .store_ref(outlist.cell)
113
+ .cell
114
+
115
+ sign = sign_cell(msg_inner, private_key)
116
+
117
+ msg_body = Builder.new
118
+ .store_bytes(sign.unpack('C*'))
119
+ .store_ref(msg_inner)
120
+
121
+ info = CommonMsgInfo.new(
122
+ ExtInMsgInfo.new(
123
+ tag: 'ext_in_msg_info',
124
+ dest: @address
125
+ )
126
+ )
127
+
128
+ init_t = is_init ? init : nil
129
+
130
+ m_cell = msg_body.cell
131
+
132
+ Message.new(
133
+ MessageOptions.new(
134
+ info: info,
135
+ init: init_t,
136
+ body: m_cell
137
+ )
138
+ )
139
+ end
140
+
141
+ private
142
+
143
+ def build_state_init()
144
+ data = Builder.new()
145
+ data.store_bytes(hex_to_bytes(pubkey))
146
+ data.store_uint(0, 16)
147
+
148
+ options = StateInitOptions.new(code: code, data: data.cell)
149
+ TonSdkRuby::StateInit.new(options)
150
+ end
151
+ end
152
+ end
153
+
154
+
155
+
156
+
157
+
158
+
159
+
160
+
161
+
162
+
163
+
164
+
165
+
166
+
167
+
168
+
169
+
170
+
171
+
172
+
173
+
174
+
175
+
176
+
@@ -0,0 +1,145 @@
1
+ =begin
2
+ ton-sdk-ruby-smc – commonly used tvm contracts ruby package
3
+
4
+ Copyright (C) 2023 Oleh Hudeichuk
5
+
6
+ This file is part of ton-sdk-ruby-smc.
7
+
8
+ ton-sdk-ruby-smc is free software: you can redistribute it and/or modify
9
+ it under the terms of the GNU Lesser General Public License as
10
+ published by the Free Software Foundation, either version 3 of
11
+ the License, or (at your option) any later version.
12
+
13
+ ton-sdk-ruby-smc is distributed in the hope that it will be useful,
14
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ GNU Lesser General Public License for more details.
17
+
18
+ You should have received a copy of the GNU Lesser General Public License
19
+ along with ton-sdk-ruby-smc. If not, see <https://www.gnu.org/licenses/>.
20
+
21
+
22
+ =end
23
+
24
+ =begin
25
+ The source code and LICENSE of the "wallet v3 r2" smart contract:
26
+ https://github.com/toncenter/tonweb/blob/master/src/contract/wallet/WalletSources.md
27
+
28
+ "WALLET_V3_CODE = ..." is a compiled version (byte code) of
29
+ the smart contract "wallet-v3-r2-code.fif" in the bag of cells
30
+ serialization in hexadecimal representation.
31
+
32
+ code cell hash(sha256): 84DAFA449F98A6987789BA232358072BC0F76DC4524002A5D0918B9A75D2D599
33
+
34
+ Respect the rights of open source software. Thanks! :)
35
+ If you notice copyright violation, please create an issue:
36
+ https://github.com/nerzh/ton-sdk-ruby-smc/issues
37
+ =end
38
+
39
+ module TonSdkRubySmc
40
+ include TonSdkRuby
41
+
42
+ WALLET_V3_CODE = "B5EE9C724101010100710000DEFF0020DD2082014C97BA218201339CBAB19F71B0ED44D0D31FD31F31D70BFFE304E0A4F2608308D71820D31FD31FD31FF82313BBF263ED44D0D31FD31FD3FFD15132BAF2A15144BAF2A204F901541055F910F2A3F8009320D74A96D307D402FB00E8D101A4C8CB1FCB1FCBFFC9ED5410BD6DAD"
43
+ SUB_WALLET_ID = 698983191
44
+
45
+ class WalletV3Transfer
46
+ attr_accessor :destination, :bounce, :value, :mode, :body, :init
47
+
48
+ def initialize(destination, bounce, value, mode, body = nil, init = nil)
49
+ @destination = destination # Address
50
+ @bounce = bounce # Boolean
51
+ @value = value # Coins
52
+ @mode = mode # Integer
53
+ @body = body # Cell
54
+ @init = init # StateInit
55
+ end
56
+ end
57
+
58
+ class WalletV3
59
+ attr_accessor :code, :pubkey, :init, :address, :sub_wallet_id
60
+
61
+ def initialize(pubkey, wc = 0, sub_wallet_id = SUB_WALLET_ID)
62
+ @pubkey = pubkey
63
+ @sub_wallet_id = sub_wallet_id
64
+ @code = deserialize(hex_to_bytes(WALLET_V3_CODE)).first
65
+ @init = build_state_init
66
+ @address = Address.new("#{wc}:#{init.cell.hash}")
67
+ end
68
+
69
+ def self.parse_storage(storage_slice)
70
+ raise 'Must be a Slice' unless storage_slice.is_a?(Slice)
71
+ {
72
+ seqno: storage_slice.load_uint(32),
73
+ sub_wallet_id: storage_slice.load_uint(32),
74
+ pubkey: storage_slice.load_bytes(32)
75
+ }
76
+ end
77
+
78
+ def build_transfer(transfers, seqno, private_key, is_init = false, timeout = 60)
79
+ raise 'Transfers must be an [WalletV3Transfer]' unless transfers.size > 0 && transfers.first.is_a?(WalletV3Transfer)
80
+ raise "Wallet v3 can handle only 4 transfers at once" unless transfers.size <= 4
81
+ body = Builder.new()
82
+ body.store_uint(sub_wallet_id, 32)
83
+ body.store_uint((Time.now.to_i + timeout), 32)
84
+ body.store_uint(seqno, 32)
85
+ transfers.each do |t|
86
+ info = CommonMsgInfo.new(
87
+ IntMsgInfo.new(
88
+ tag: "int_msg_info",
89
+ dest: t.destination,
90
+ bounce: t.bounce,
91
+ value: t.value,
92
+ )
93
+ )
94
+
95
+ message = Message.new(
96
+ MessageOptions.new(
97
+ info: info,
98
+ body: t.body,
99
+ init: t.init,
100
+ )
101
+ )
102
+
103
+ body.store_uint(t.mode, 8)
104
+ body.store_ref(message.cell)
105
+ end
106
+
107
+ sign = sign_cell(body.cell, private_key)
108
+
109
+ message_body = Builder.new
110
+ message_body.store_bytes(sign.unpack('C*'))
111
+ message_body.store_slice(body.cell.parse)
112
+
113
+ info = CommonMsgInfo.new(
114
+ ExtInMsgInfo.new(
115
+ tag: 'ext_in_msg_info',
116
+ dest: address
117
+ )
118
+ )
119
+ init_t = is_init ? init : nil
120
+ m_cell = message_body.cell
121
+
122
+ message = Message.new(
123
+ MessageOptions.new(
124
+ info: info,
125
+ init: init_t,
126
+ body: m_cell
127
+ )
128
+ )
129
+
130
+ message
131
+ end
132
+
133
+ private
134
+
135
+ def build_state_init()
136
+ data = Builder.new()
137
+ data.store_uint(0, 32)
138
+ data.store_uint(sub_wallet_id, 32)
139
+ data.store_bytes(hex_to_bytes(pubkey))
140
+
141
+ options = StateInitOptions.new(code: code, data: data.cell)
142
+ TonSdkRuby::StateInit.new(options)
143
+ end
144
+ end
145
+ end
@@ -0,0 +1,155 @@
1
+ =begin
2
+ ton-sdk-ruby-smc – commonly used tvm contracts ruby package
3
+
4
+ Copyright (C) 2023 Oleh Hudeichuk
5
+
6
+ This file is part of ton-sdk-ruby-smc.
7
+
8
+ ton-sdk-ruby-smc is free software: you can redistribute it and/or modify
9
+ it under the terms of the GNU Lesser General Public License as
10
+ published by the Free Software Foundation, either version 3 of
11
+ the License, or (at your option) any later version.
12
+
13
+ ton-sdk-ruby-smc is distributed in the hope that it will be useful,
14
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ GNU Lesser General Public License for more details.
17
+
18
+ You should have received a copy of the GNU Lesser General Public License
19
+ along with ton-sdk-ruby-smc. If not, see <https://www.gnu.org/licenses/>.
20
+ =end
21
+
22
+ =begin
23
+ The source code and LICENSE of the "wallet v4 r2" smart contract:
24
+ https://github.com/toncenter/tonweb/blob/master/src/contract/wallet/WalletSources.md
25
+
26
+ "WALLET_V4_CODE = ..." is a compiled version (byte code) of
27
+ the smart contract "wallet-v4-r2-code.fif" in the bag of cells
28
+ serialization in hexadecimal representation.
29
+
30
+ code cell hash(sha256): FEB5FF6820E2FF0D9483E7E0D62C817D846789FB4AE580C878866D959DABD5C0
31
+
32
+ Respect the rights of open source software. Thanks! :)
33
+ If you notice copyright violation, please create an issue:
34
+ https://github.com/nerzh/ton-sdk-ruby-smc/issues
35
+ =end
36
+
37
+ module TonSdkRubySmc
38
+ include TonSdkRuby
39
+
40
+ WALLET_V4_CODE = "B5EE9C72410214010002D4000114FF00F4A413F4BCF2C80B010201200203020148040504F8F28308D71820D31FD31FD31F02F823BBF264ED44D0D31FD31FD3FFF404D15143BAF2A15151BAF2A205F901541064F910F2A3F80024A4C8CB1F5240CB1F5230CBFF5210F400C9ED54F80F01D30721C0009F6C519320D74A96D307D402FB00E830E021C001E30021C002E30001C0039130E30D03A4C8CB1F12CB1FCBFF1011121302E6D001D0D3032171B0925F04E022D749C120925F04E002D31F218210706C7567BD22821064737472BDB0925F05E003FA403020FA4401C8CA07CBFFC9D0ED44D0810140D721F404305C810108F40A6FA131B3925F07E005D33FC8258210706C7567BA923830E30D03821064737472BA925F06E30D06070201200809007801FA00F40430F8276F2230500AA121BEF2E0508210706C7567831EB17080185004CB0526CF1658FA0219F400CB6917CB1F5260CB3F20C98040FB0006008A5004810108F45930ED44D0810140D720C801CF16F400C9ED540172B08E23821064737472831EB17080185005CB055003CF1623FA0213CB6ACB1FCB3FC98040FB00925F03E20201200A0B0059BD242B6F6A2684080A06B90FA0218470D4080847A4937D29910CE6903E9FF9837812801B7810148987159F31840201580C0D0011B8C97ED44D0D70B1F8003DB29DFB513420405035C87D010C00B23281F2FFF274006040423D029BE84C600201200E0F0019ADCE76A26840206B90EB85FFC00019AF1DF6A26840106B90EB858FC0006ED207FA00D4D422F90005C8CA0715CBFFC9D077748018C8CB05CB0222CF165005FA0214CB6B12CCCCC973FB00C84014810108F451F2A7020070810108D718FA00D33FC8542047810108F451F2A782106E6F746570748018C8CB05CB025006CF165004FA0214CB6A12CB1FCB3FC973FB0002006C810108D718FA00D33F305224810108F459F2A782106473747270748018C8CB05CB025005CF165003FA0213CB6ACB1F12CB3FC973FB00000AF400C9ED54696225E5"
41
+ SUB_WALLET_ID = 698983191
42
+
43
+ class WalletV4Transfer
44
+ attr_accessor :destination, :bounce, :value, :mode, :body, :init
45
+
46
+ def initialize(destination, bounce, value, mode, body = nil, init = nil)
47
+ @destination = destination # Address
48
+ @bounce = bounce # Boolean
49
+ @value = value # Coins
50
+ @mode = mode # Integer
51
+ @body = body # Cell
52
+ @init = init # StateInit
53
+ end
54
+ end
55
+
56
+ class WalletV4
57
+ attr_accessor :code, :pubkey, :init, :address, :sub_wallet_id
58
+
59
+ def initialize(pubkey, wc = 0, sub_wallet_id = SUB_WALLET_ID)
60
+ @pubkey = pubkey
61
+ @sub_wallet_id = sub_wallet_id
62
+ @code = deserialize(hex_to_bytes(WALLET_V4_CODE)).first
63
+ @init = build_state_init
64
+ @address = Address.new("#{wc}:#{init.cell.hash}")
65
+ end
66
+
67
+ def self.parse_storage(storage_slice)
68
+ raise "Must be a Slice" unless storage_slice.is_a?(Slice)
69
+ deserializers = {
70
+ key: ->(k) do
71
+ slice = Slice.parse(Builder.new.store_bits(k).cell)
72
+ wc = slice.load_int(8)
73
+ addr = slice.load_bytes(32)
74
+ Address.new("#{wc}:#{bytes_to_hex(addr)}")
75
+ end,
76
+ value: ->(v) { nil },
77
+ }
78
+
79
+ {
80
+ seqno: storage_slice.load_uint(32),
81
+ sub_wallet_id: storage_slice.load_uint(32),
82
+ pubkey: storage_slice.load_bytes(32),
83
+ plugins_list: storage_slice
84
+ .load_dict(8 + 256, { deserializers: deserializers }).each { |key, value| { key: key, value: value } }
85
+ .map { |item| item[:key] },
86
+ }
87
+ end
88
+
89
+ def build_transfer(transfers, seqno, private_key, timeout = 60)
90
+ raise "Transfers must be an [WalletV3Transfer]" unless transfers.size > 0 && transfers.first.is_a?(WalletV3Transfer)
91
+ raise "Wallet v3 can handle only 4 transfers at once" unless transfers.size <= 4
92
+ body = Builder.new()
93
+ body.store_uint(sub_wallet_id, 32)
94
+ body.store_uint((Time.now.to_i + timeout).to_s, 32)
95
+ body.store_uint(seqno, 32)
96
+ transfers.each do |t|
97
+ info = CommonMsgInfo.new(
98
+ IntMsgInfo.new(
99
+ tag: "int_msg_info",
100
+ dest: t.destination,
101
+ bounce: t.bounce,
102
+ value: t.value,
103
+ )
104
+ )
105
+
106
+ message = Message.new(
107
+ MessageOptions.new(
108
+ info: info,
109
+ body: t.body,
110
+ init: t.init,
111
+ )
112
+ )
113
+
114
+ body.store_uint(t.mode, 8)
115
+ body.store_ref(message.cell)
116
+ end
117
+
118
+ sign = sign_cell(body.cell, private_key)
119
+
120
+ message_body = Builder.new
121
+ message_body.store_bytes(sign.unpack('C*'))
122
+ message_body.store_slice(body.cell.parse)
123
+
124
+ info = CommonMsgInfo.new(
125
+ ExtInMsgInfo.new(
126
+ tag: "ext_in_msg_info",
127
+ dest: @address,
128
+ )
129
+ )
130
+ init_t = seqno == 0 ? init : nil
131
+ m_cell = msg_body.cell
132
+
133
+ Message.new(
134
+ MessageOptions.new(
135
+ info: info,
136
+ init: init_t,
137
+ body: m_cell,
138
+ )
139
+ )
140
+ end
141
+
142
+ private
143
+
144
+ def build_state_init()
145
+ data = Builder.new()
146
+ data.store_uint(0, 32)
147
+ data.store_uint(sub_wallet_id, 32)
148
+ data.store_bytes(hex_to_bytes(pubkey))
149
+ data.store_bit(0)
150
+
151
+ options = StateInitOptions.new(code: code, data: data.cell)
152
+ TonSdkRuby::StateInit.new(options)
153
+ end
154
+ end
155
+ end
@@ -0,0 +1,37 @@
1
+ =begin
2
+ ton-sdk-ruby-smc – commonly used tvm contracts ruby package
3
+
4
+ Copyright (C) 2023 Oleh Hudeichuk
5
+
6
+ This file is part of ton-sdk-ruby-smc.
7
+
8
+ ton-sdk-ruby-smc is free software: you can redistribute it and/or modify
9
+ it under the terms of the GNU Lesser General Public License as
10
+ published by the Free Software Foundation, either version 3 of
11
+ the License, or (at your option) any later version.
12
+
13
+ ton-sdk-ruby-smc is distributed in the hope that it will be useful,
14
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ GNU Lesser General Public License for more details.
17
+
18
+ You should have received a copy of the GNU Lesser General Public License
19
+ along with ton-sdk-ruby-smc. If not, see <https://www.gnu.org/licenses/>.
20
+
21
+
22
+ =end
23
+
24
+ require 'ton-sdk-ruby'
25
+ require_relative './ton-sdk-ruby-smc/helpers/constants'
26
+ require_relative './ton-sdk-ruby-smc/version'
27
+ require_relative './ton-sdk-ruby-smc/wallets/pwv2'
28
+ require_relative './ton-sdk-ruby-smc/wallets/wallet_v3'
29
+ require_relative './ton-sdk-ruby-smc/wallets/wallet_v4'
30
+ require_relative './ton-sdk-ruby-smc/helpers/helpers'
31
+ require_relative './ton-sdk-ruby-smc/tokens/jetton'
32
+ require_relative './ton-sdk-ruby-smc/tokens/nft'
33
+ require_relative './ton-sdk-ruby-smc/tokens/metadata'
34
+
35
+
36
+ module TonSdkRubySmc
37
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ton-sdk-ruby-smc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - nerzh
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-08-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: byebug
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Gem Ton SDK Ruby for all TVM ruby projects
70
+ email:
71
+ - emptystamp@gmail.com
72
+ executables:
73
+ - ton-sdk-ruby-smc
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - bin/ton-sdk-ruby-smc
78
+ - lib/ton-sdk-ruby-smc.rb
79
+ - lib/ton-sdk-ruby-smc/helpers/constants.rb
80
+ - lib/ton-sdk-ruby-smc/helpers/helpers.rb
81
+ - lib/ton-sdk-ruby-smc/tokens/jetton.rb
82
+ - lib/ton-sdk-ruby-smc/tokens/metadata.rb
83
+ - lib/ton-sdk-ruby-smc/tokens/nft.rb
84
+ - lib/ton-sdk-ruby-smc/version.rb
85
+ - lib/ton-sdk-ruby-smc/wallets/pwv2.rb
86
+ - lib/ton-sdk-ruby-smc/wallets/wallet_v3.rb
87
+ - lib/ton-sdk-ruby-smc/wallets/wallet_v4.rb
88
+ homepage: https://github.com/nerzh/ton-sdk-ruby
89
+ licenses:
90
+ - LGPL-3.0-or-later
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubygems_version: 3.4.19
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: This is gem ton-sdk-ruby-smc
111
+ test_files: []