mixin_bot 0.9.0 → 0.11.0

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.
@@ -0,0 +1,163 @@
1
+ [
2
+ {
3
+ "type": "constructor",
4
+ "stateMutability": "nonpayable",
5
+ "inputs": [
6
+ { "type": "address", "name": "factory", "internalType": "address" }
7
+ ]
8
+ },
9
+ {
10
+ "type": "event",
11
+ "name": "Bound",
12
+ "inputs": [
13
+ {
14
+ "type": "address",
15
+ "name": "from",
16
+ "internalType": "address",
17
+ "indexed": true
18
+ },
19
+ {
20
+ "type": "address",
21
+ "name": "to",
22
+ "internalType": "address",
23
+ "indexed": true
24
+ }
25
+ ],
26
+ "anonymous": false
27
+ },
28
+ {
29
+ "type": "event",
30
+ "name": "CollectionCreated",
31
+ "inputs": [
32
+ {
33
+ "type": "address",
34
+ "name": "at",
35
+ "internalType": "address",
36
+ "indexed": true
37
+ },
38
+ {
39
+ "type": "uint256",
40
+ "name": "id",
41
+ "internalType": "uint256",
42
+ "indexed": false
43
+ }
44
+ ],
45
+ "anonymous": false
46
+ },
47
+ {
48
+ "type": "event",
49
+ "name": "Through",
50
+ "inputs": [
51
+ {
52
+ "type": "address",
53
+ "name": "collection",
54
+ "internalType": "address",
55
+ "indexed": true
56
+ },
57
+ {
58
+ "type": "address",
59
+ "name": "from",
60
+ "internalType": "address",
61
+ "indexed": true
62
+ },
63
+ {
64
+ "type": "address",
65
+ "name": "to",
66
+ "internalType": "address",
67
+ "indexed": true
68
+ },
69
+ {
70
+ "type": "uint256",
71
+ "name": "id",
72
+ "internalType": "uint256",
73
+ "indexed": false
74
+ }
75
+ ],
76
+ "anonymous": false
77
+ },
78
+ {
79
+ "type": "function",
80
+ "stateMutability": "view",
81
+ "outputs": [{ "type": "address", "name": "", "internalType": "address" }],
82
+ "name": "FACTORY",
83
+ "inputs": []
84
+ },
85
+ {
86
+ "type": "function",
87
+ "stateMutability": "view",
88
+ "outputs": [{ "type": "uint256", "name": "", "internalType": "uint256" }],
89
+ "name": "VERSION",
90
+ "inputs": []
91
+ },
92
+ {
93
+ "type": "function",
94
+ "stateMutability": "nonpayable",
95
+ "outputs": [],
96
+ "name": "bind",
97
+ "inputs": [
98
+ { "type": "address", "name": "receiver", "internalType": "address" }
99
+ ]
100
+ },
101
+ {
102
+ "type": "function",
103
+ "stateMutability": "view",
104
+ "outputs": [{ "type": "address", "name": "", "internalType": "address" }],
105
+ "name": "bridges",
106
+ "inputs": [{ "type": "address", "name": "", "internalType": "address" }]
107
+ },
108
+ {
109
+ "type": "function",
110
+ "stateMutability": "view",
111
+ "outputs": [{ "type": "uint256", "name": "", "internalType": "uint256" }],
112
+ "name": "collections",
113
+ "inputs": [{ "type": "address", "name": "", "internalType": "address" }]
114
+ },
115
+ {
116
+ "type": "function",
117
+ "stateMutability": "view",
118
+ "outputs": [{ "type": "address", "name": "", "internalType": "address" }],
119
+ "name": "contracts",
120
+ "inputs": [{ "type": "uint256", "name": "", "internalType": "uint256" }]
121
+ },
122
+ {
123
+ "type": "function",
124
+ "stateMutability": "view",
125
+ "outputs": [
126
+ { "type": "address", "name": "collection", "internalType": "address" },
127
+ { "type": "uint256", "name": "id", "internalType": "uint256" }
128
+ ],
129
+ "name": "mints",
130
+ "inputs": [{ "type": "address", "name": "", "internalType": "address" }]
131
+ },
132
+ {
133
+ "type": "function",
134
+ "stateMutability": "nonpayable",
135
+ "outputs": [{ "type": "bytes4", "name": "", "internalType": "bytes4" }],
136
+ "name": "onERC721Received",
137
+ "inputs": [
138
+ { "type": "address", "name": "", "internalType": "address" },
139
+ { "type": "address", "name": "_from", "internalType": "address" },
140
+ { "type": "uint256", "name": "_tokenId", "internalType": "uint256" },
141
+ { "type": "bytes", "name": "_data", "internalType": "bytes" }
142
+ ]
143
+ },
144
+ {
145
+ "type": "function",
146
+ "stateMutability": "nonpayable",
147
+ "outputs": [],
148
+ "name": "pass",
149
+ "inputs": [
150
+ { "type": "address", "name": "asset", "internalType": "address" }
151
+ ]
152
+ },
153
+ {
154
+ "type": "function",
155
+ "stateMutability": "view",
156
+ "outputs": [{ "type": "address", "name": "", "internalType": "address" }],
157
+ "name": "tokens",
158
+ "inputs": [
159
+ { "type": "address", "name": "", "internalType": "address" },
160
+ { "type": "uint256", "name": "", "internalType": "uint256" }
161
+ ]
162
+ }
163
+ ]
@@ -0,0 +1,248 @@
1
+ [
2
+ {
3
+ "type": "constructor",
4
+ "stateMutability": "nonpayable",
5
+ "inputs": [
6
+ { "type": "bytes", "name": "raw", "internalType": "bytes" },
7
+ { "type": "uint128", "name": "pid", "internalType": "uint128" }
8
+ ]
9
+ },
10
+ {
11
+ "type": "event",
12
+ "name": "AssetCreated",
13
+ "inputs": [
14
+ {
15
+ "type": "address",
16
+ "name": "at",
17
+ "internalType": "address",
18
+ "indexed": true
19
+ },
20
+ {
21
+ "type": "uint256",
22
+ "name": "id",
23
+ "internalType": "uint256",
24
+ "indexed": false
25
+ }
26
+ ],
27
+ "anonymous": false
28
+ },
29
+ {
30
+ "type": "event",
31
+ "name": "Halted",
32
+ "inputs": [
33
+ {
34
+ "type": "bool",
35
+ "name": "state",
36
+ "internalType": "bool",
37
+ "indexed": false
38
+ }
39
+ ],
40
+ "anonymous": false
41
+ },
42
+ {
43
+ "type": "event",
44
+ "name": "Iterated",
45
+ "inputs": [
46
+ {
47
+ "type": "uint256[4]",
48
+ "name": "from",
49
+ "internalType": "uint256[4]",
50
+ "indexed": false
51
+ },
52
+ {
53
+ "type": "uint256[4]",
54
+ "name": "to",
55
+ "internalType": "uint256[4]",
56
+ "indexed": false
57
+ }
58
+ ],
59
+ "anonymous": false
60
+ },
61
+ {
62
+ "type": "event",
63
+ "name": "MixinEvent",
64
+ "inputs": [
65
+ {
66
+ "type": "uint64",
67
+ "name": "nonce",
68
+ "internalType": "uint64",
69
+ "indexed": true
70
+ },
71
+ {
72
+ "type": "address",
73
+ "name": "user",
74
+ "internalType": "address",
75
+ "indexed": true
76
+ },
77
+ {
78
+ "type": "address",
79
+ "name": "asset",
80
+ "internalType": "address",
81
+ "indexed": true
82
+ },
83
+ {
84
+ "type": "uint256",
85
+ "name": "amount",
86
+ "internalType": "uint256",
87
+ "indexed": false
88
+ },
89
+ {
90
+ "type": "bytes",
91
+ "name": "extra",
92
+ "internalType": "bytes",
93
+ "indexed": false
94
+ },
95
+ {
96
+ "type": "uint64",
97
+ "name": "timestamp",
98
+ "internalType": "uint64",
99
+ "indexed": false
100
+ }
101
+ ],
102
+ "anonymous": false
103
+ },
104
+ {
105
+ "type": "event",
106
+ "name": "MixinTransaction",
107
+ "inputs": [
108
+ {
109
+ "type": "bytes",
110
+ "name": "raw",
111
+ "internalType": "bytes",
112
+ "indexed": false
113
+ }
114
+ ],
115
+ "anonymous": false
116
+ },
117
+ {
118
+ "type": "event",
119
+ "name": "UserCreated",
120
+ "inputs": [
121
+ {
122
+ "type": "address",
123
+ "name": "at",
124
+ "internalType": "address",
125
+ "indexed": true
126
+ },
127
+ {
128
+ "type": "bytes",
129
+ "name": "members",
130
+ "internalType": "bytes",
131
+ "indexed": false
132
+ }
133
+ ],
134
+ "anonymous": false
135
+ },
136
+ {
137
+ "type": "function",
138
+ "stateMutability": "view",
139
+ "outputs": [{ "type": "uint256", "name": "", "internalType": "uint256" }],
140
+ "name": "GROUP",
141
+ "inputs": [{ "type": "uint256", "name": "", "internalType": "uint256" }]
142
+ },
143
+ {
144
+ "type": "function",
145
+ "stateMutability": "view",
146
+ "outputs": [{ "type": "bool", "name": "", "internalType": "bool" }],
147
+ "name": "HALTED",
148
+ "inputs": []
149
+ },
150
+ {
151
+ "type": "function",
152
+ "stateMutability": "view",
153
+ "outputs": [{ "type": "uint64", "name": "", "internalType": "uint64" }],
154
+ "name": "INBOUND",
155
+ "inputs": []
156
+ },
157
+ {
158
+ "type": "function",
159
+ "stateMutability": "view",
160
+ "outputs": [{ "type": "uint64", "name": "", "internalType": "uint64" }],
161
+ "name": "OUTBOUND",
162
+ "inputs": []
163
+ },
164
+ {
165
+ "type": "function",
166
+ "stateMutability": "view",
167
+ "outputs": [{ "type": "uint128", "name": "", "internalType": "uint128" }],
168
+ "name": "PID",
169
+ "inputs": []
170
+ },
171
+ {
172
+ "type": "function",
173
+ "stateMutability": "view",
174
+ "outputs": [{ "type": "uint256", "name": "", "internalType": "uint256" }],
175
+ "name": "VERSION",
176
+ "inputs": []
177
+ },
178
+ {
179
+ "type": "function",
180
+ "stateMutability": "view",
181
+ "outputs": [{ "type": "uint128", "name": "", "internalType": "uint128" }],
182
+ "name": "assets",
183
+ "inputs": [{ "type": "address", "name": "", "internalType": "address" }]
184
+ },
185
+ {
186
+ "type": "function",
187
+ "stateMutability": "view",
188
+ "outputs": [{ "type": "uint256", "name": "", "internalType": "uint256" }],
189
+ "name": "balances",
190
+ "inputs": [{ "type": "uint128", "name": "", "internalType": "uint128" }]
191
+ },
192
+ {
193
+ "type": "function",
194
+ "stateMutability": "nonpayable",
195
+ "outputs": [{ "type": "bool", "name": "", "internalType": "bool" }],
196
+ "name": "burn",
197
+ "inputs": [
198
+ { "type": "address", "name": "user", "internalType": "address" },
199
+ { "type": "uint256", "name": "amount", "internalType": "uint256" },
200
+ { "type": "bytes", "name": "extra", "internalType": "bytes" }
201
+ ]
202
+ },
203
+ {
204
+ "type": "function",
205
+ "stateMutability": "nonpayable",
206
+ "outputs": [{ "type": "bool", "name": "", "internalType": "bool" }],
207
+ "name": "claim",
208
+ "inputs": [
209
+ { "type": "address", "name": "asset", "internalType": "address" },
210
+ { "type": "uint256", "name": "amount", "internalType": "uint256" }
211
+ ]
212
+ },
213
+ {
214
+ "type": "function",
215
+ "stateMutability": "view",
216
+ "outputs": [{ "type": "address", "name": "", "internalType": "address" }],
217
+ "name": "contracts",
218
+ "inputs": [{ "type": "uint256", "name": "", "internalType": "uint256" }]
219
+ },
220
+ {
221
+ "type": "function",
222
+ "stateMutability": "nonpayable",
223
+ "outputs": [],
224
+ "name": "halt",
225
+ "inputs": [{ "type": "bytes", "name": "raw", "internalType": "bytes" }]
226
+ },
227
+ {
228
+ "type": "function",
229
+ "stateMutability": "nonpayable",
230
+ "outputs": [],
231
+ "name": "iterate",
232
+ "inputs": [{ "type": "bytes", "name": "raw", "internalType": "bytes" }]
233
+ },
234
+ {
235
+ "type": "function",
236
+ "stateMutability": "nonpayable",
237
+ "outputs": [{ "type": "bool", "name": "", "internalType": "bool" }],
238
+ "name": "mixin",
239
+ "inputs": [{ "type": "bytes", "name": "raw", "internalType": "bytes" }]
240
+ },
241
+ {
242
+ "type": "function",
243
+ "stateMutability": "view",
244
+ "outputs": [{ "type": "bytes", "name": "", "internalType": "bytes" }],
245
+ "name": "users",
246
+ "inputs": [{ "type": "address", "name": "", "internalType": "address" }]
247
+ }
248
+ ]
data/lib/mvm/bridge.rb ADDED
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MVM
4
+ class Bridge
5
+ attr_reader :client
6
+
7
+ def initialize
8
+ @client = MVM::Client.new 'bridge.mvm.dev'
9
+ end
10
+
11
+ def user(public_key)
12
+ path = '/users'
13
+
14
+ payload = {
15
+ public_key: public_key
16
+ }
17
+
18
+ client.post path, json: payload
19
+ end
20
+
21
+ def extra(receivers: [], threshold: 1, extra: '')
22
+ return if receivers.blank?
23
+
24
+ path = '/extra'
25
+
26
+ payload = {
27
+ receivers: receivers,
28
+ threshold: threshold,
29
+ extra: extra
30
+ }
31
+
32
+ client.post path, json: payload
33
+ end
34
+
35
+ def mirror
36
+ end
37
+ end
38
+ end
data/lib/mvm/client.rb ADDED
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MVM
4
+ class Client
5
+ SERVER_SCHEME = 'https'
6
+
7
+ attr_reader :host
8
+
9
+ def initialize(host)
10
+ @host = host
11
+ end
12
+
13
+ def get(path, options = {})
14
+ request(:get, path, options)
15
+ end
16
+
17
+ def post(path, options = {})
18
+ request(:post, path, options)
19
+ end
20
+
21
+ private
22
+
23
+ def request(verb, path, options = {})
24
+ uri = uri_for path
25
+
26
+ options[:headers] ||= {}
27
+ options[:headers]['Content-Type'] ||= 'application/json'
28
+
29
+ begin
30
+ response = HTTP.timeout(connect: 5, write: 5, read: 5).request(verb, uri, options)
31
+ rescue HTTP::Error => e
32
+ raise HttpError, e.message
33
+ end
34
+
35
+ raise ResponseError, response.to_s if response.status.server_error?
36
+ return response.status.to_s unless response.status.success?
37
+
38
+ JSON.parse(response.body.to_s)
39
+ end
40
+
41
+ def uri_for(path)
42
+ uri_options = {
43
+ scheme: SERVER_SCHEME,
44
+ host: host,
45
+ path: path
46
+ }
47
+ Addressable::URI.new(uri_options)
48
+ end
49
+ end
50
+ end
data/lib/mvm/nft.rb ADDED
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MVM
4
+ class Nft
5
+ RPC_URL = 'https://geth.mvm.dev'
6
+ MIRROR_ADDRESS = '0xC193486e6Bf3E8461cb8fcdF178676a5D75c066A'
7
+
8
+ attr_reader :client, :mirror
9
+
10
+ def initialize
11
+ @client = Eth::Client.create RPC_URL
12
+ @mirror = Eth::Contract.from_abi name: 'Mirror', address: MIRROR_ADDRESS, abi: File.open(File.expand_path('./abis/mirror.json', __dir__)).read
13
+ end
14
+
15
+ def collection_from_contract(address)
16
+ collection = @client.call @mirror, 'collections', address
17
+ return if collection.zero?
18
+
19
+ MixinBot::Utils::UUID.new(hex: collection.to_fs(16)).unpacked
20
+ end
21
+
22
+ def contract_from_collection(uuid)
23
+ collection = uuid.to_s.gsub('-', '').to_i(16)
24
+ contract = @client.call @mirror, 'contracts', collection
25
+ address = Eth::Address.new contract
26
+ return unless address.valid?
27
+
28
+ address.checksummed
29
+ end
30
+
31
+ def owner_of(collection_id, token_id)
32
+ address = contract_from_collection collection_id
33
+ return if address.blank? || address.to_i(16).zero?
34
+
35
+ contract = Eth::Contract.from_abi name: 'Collectible', address: address, abi: File.open(File.expand_path('./abis/erc721.json', __dir__)).read
36
+ owner = @client.call contract, 'ownerOf', token_id.to_i
37
+ address = Eth::Address.new owner
38
+ return unless address.valid?
39
+
40
+ address.checksummed
41
+ rescue IOError
42
+ nil
43
+ end
44
+
45
+ def token_of_owner_by_index(contract, owner, index)
46
+ contract = Eth::Contract.from_abi name: 'Collectible', address: contract, abi: File.open(File.expand_path('./abis/erc721.json', __dir__)).read
47
+
48
+ @client.call contract, 'tokenOfOwnerByIndex', owner, index
49
+ rescue IOError
50
+ nil
51
+ end
52
+ end
53
+ end
data/lib/mvm/scan.rb ADDED
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MVM
4
+ class Scan
5
+ attr_reader :client
6
+
7
+ def initialize
8
+ @client = Client.new 'scan.mvm.dev'
9
+ end
10
+
11
+ def tokens(address, type: nil)
12
+ path = '/api'
13
+ r = client.get(
14
+ path,
15
+ params: {
16
+ address: address,
17
+ action: 'tokenlist',
18
+ module: 'account'
19
+ }
20
+ )['result']
21
+
22
+ r = r.filter(&->(token) { token['type'] == type }) if type.present?
23
+
24
+ r
25
+ end
26
+ end
27
+ end
data/lib/mvm.rb ADDED
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/all'
4
+ require 'http'
5
+ require 'eth'
6
+
7
+ require_relative './mvm/bridge'
8
+ require_relative './mvm/client'
9
+ require_relative './mvm/nft'
10
+ require_relative './mvm/scan'
11
+
12
+ module MVM
13
+ class Error < StandardError; end
14
+ class HttpError < Error; end
15
+ class ResponseError < Error; end
16
+
17
+ def self.bridge
18
+ @bridge ||= MVM::Bridge.new
19
+ end
20
+
21
+ def self.nft
22
+ @nft ||= MVM::Nft.new
23
+ end
24
+
25
+ def self.scan
26
+ @scan ||= MVM::Scan.new
27
+ end
28
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mixin_bot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - an-lee
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-07-08 00:00:00.000000000 Z
11
+ date: 2022-10-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '1.3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: eth
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.5'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.5'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: faye-websocket
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -281,6 +295,7 @@ files:
281
295
  - lib/mixin_bot/api/blaze.rb
282
296
  - lib/mixin_bot/api/collectible.rb
283
297
  - lib/mixin_bot/api/conversation.rb
298
+ - lib/mixin_bot/api/encrypted_message.rb
284
299
  - lib/mixin_bot/api/me.rb
285
300
  - lib/mixin_bot/api/message.rb
286
301
  - lib/mixin_bot/api/multisig.rb
@@ -302,6 +317,16 @@ files:
302
317
  - lib/mixin_bot/utils/transaction.rb
303
318
  - lib/mixin_bot/utils/uuid.rb
304
319
  - lib/mixin_bot/version.rb
320
+ - lib/mvm.rb
321
+ - lib/mvm/abis/bridge.json
322
+ - lib/mvm/abis/erc20.json
323
+ - lib/mvm/abis/erc721.json
324
+ - lib/mvm/abis/mirror.json
325
+ - lib/mvm/abis/registry.json
326
+ - lib/mvm/bridge.rb
327
+ - lib/mvm/client.rb
328
+ - lib/mvm/nft.rb
329
+ - lib/mvm/scan.rb
305
330
  homepage: https://github.com/an-lee/mixin_bot
306
331
  licenses:
307
332
  - MIT