1
1
/* eslint-disable @typescript-eslint/no-floating-promises */
2
2
/* eslint-disable @typescript-eslint/no-explicit-any */
3
-
4
3
import { GearApi , decodeAddress } from '@gear-js/api' ;
5
4
import { TypeRegistry } from '@polkadot/types' ;
6
- import {
7
- ActorId ,
8
- H160 ,
9
- TransactionBuilder ,
10
- MessageId ,
11
- getServiceNamePrefix ,
12
- getFnNamePrefix ,
13
- ZERO_ADDRESS ,
14
- } from 'sails-js' ;
5
+ import { TransactionBuilder , H160 , ActorId , getServiceNamePrefix , getFnNamePrefix , ZERO_ADDRESS } from 'sails-js' ;
15
6
16
7
export interface InitConfig {
17
8
admin_address : ActorId ;
18
- vft_gateway_address : ActorId ;
9
+ vft_manager_address : ActorId ;
19
10
config : Config ;
20
11
}
21
12
22
13
export interface Config {
23
14
fee : number | string | bigint ;
24
15
gas_for_reply_deposit : number | string | bigint ;
25
- gas_to_send_request_to_gateway : number | string | bigint ;
26
- gas_to_transfer_tokens : number | string | bigint ;
16
+ gas_to_send_request_to_vft_manager : number | string | bigint ;
27
17
reply_timeout : number ;
28
- gas_for_request_to_gateway_msg : number | string | bigint ;
29
- }
30
-
31
- export interface MessageInfo {
32
- status : MessageStatus ;
33
- details : TransactionDetails ;
18
+ gas_for_request_to_vft_manager_msg : number | string | bigint ;
34
19
}
35
20
36
- export type MessageStatus =
37
- | { sendingMessageToTransferTokens : null }
38
- | { tokenTransferCompleted : boolean }
39
- | { waitingReplyFromTokenTransfer : null }
40
- | { sendingMessageToGateway : null }
41
- | { gatewayMessageProcessingCompleted : [ number | string | bigint , H160 ] }
42
- | { waitingReplyFromGateway : null }
43
- | { messageToGatewayStep : null }
44
- | { returnTokensBackStep : null }
45
- | { sendingMessageToTransferTokensBack : null }
46
- | { waitingReplyFromTokenTransferBack : null }
47
- | { tokenTransferBackCompleted : null }
48
- | { messageProcessedWithSuccess : [ number | string | bigint , H160 ] } ;
49
-
50
- export type TransactionDetails =
51
- | { transfer : { sender : ActorId ; receiver : ActorId ; amount : number | string | bigint ; token_id : ActorId } }
52
- | {
53
- sendMessageToGateway : {
54
- sender : ActorId ;
55
- vara_token_id : ActorId ;
56
- amount : number | string | bigint ;
57
- receiver : H160 ;
58
- attached_value : number | string | bigint ;
59
- } ;
60
- } ;
61
-
62
21
export class Program {
63
22
public readonly registry : TypeRegistry ;
64
23
public readonly bridgingPayment : BridgingPayment ;
65
24
66
25
constructor ( public api : GearApi , public programId ?: `0x${string } `) {
67
26
const types : Record < string , any > = {
68
- InitConfig : { admin_address : '[u8;32]' , vft_gateway_address : '[u8;32]' , config : 'Config' } ,
27
+ InitConfig : { admin_address : '[u8;32]' , vft_manager_address : '[u8;32]' , config : 'Config' } ,
69
28
Config : {
70
29
fee : 'u128' ,
71
30
gas_for_reply_deposit : 'u64' ,
72
- gas_to_send_request_to_gateway : 'u64' ,
73
- gas_to_transfer_tokens : 'u64' ,
31
+ gas_to_send_request_to_vft_manager : 'u64' ,
74
32
reply_timeout : 'u32' ,
75
- gas_for_request_to_gateway_msg : 'u64' ,
76
- } ,
77
- MessageInfo : { status : 'MessageStatus' , details : 'TransactionDetails' } ,
78
- MessageStatus : {
79
- _enum : {
80
- SendingMessageToTransferTokens : 'Null' ,
81
- TokenTransferCompleted : 'bool' ,
82
- WaitingReplyFromTokenTransfer : 'Null' ,
83
- SendingMessageToGateway : 'Null' ,
84
- GatewayMessageProcessingCompleted : '(U256, H160)' ,
85
- WaitingReplyFromGateway : 'Null' ,
86
- MessageToGatewayStep : 'Null' ,
87
- ReturnTokensBackStep : 'Null' ,
88
- SendingMessageToTransferTokensBack : 'Null' ,
89
- WaitingReplyFromTokenTransferBack : 'Null' ,
90
- TokenTransferBackCompleted : 'Null' ,
91
- MessageProcessedWithSuccess : '(U256, H160)' ,
92
- } ,
93
- } ,
94
- TransactionDetails : {
95
- _enum : {
96
- Transfer : { sender : '[u8;32]' , receiver : '[u8;32]' , amount : 'U256' , token_id : '[u8;32]' } ,
97
- SendMessageToGateway : {
98
- sender : '[u8;32]' ,
99
- vara_token_id : '[u8;32]' ,
100
- amount : 'U256' ,
101
- receiver : 'H160' ,
102
- attached_value : 'u128' ,
103
- } ,
104
- } ,
33
+ gas_for_request_to_vft_manager_msg : 'u64' ,
105
34
} ,
106
35
} ;
107
36
@@ -146,14 +75,18 @@ export class Program {
146
75
export class BridgingPayment {
147
76
constructor ( private _program : Program ) { }
148
77
149
- public continueTransaction ( msg_id : MessageId ) : TransactionBuilder < null > {
78
+ public makeRequest (
79
+ amount : number | string | bigint ,
80
+ receiver : H160 ,
81
+ vara_token_id : ActorId ,
82
+ ) : TransactionBuilder < null > {
150
83
if ( ! this . _program . programId ) throw new Error ( 'Program ID is not set' ) ;
151
84
return new TransactionBuilder < null > (
152
85
this . _program . api ,
153
86
this . _program . registry ,
154
87
'send_message' ,
155
- [ 'BridgingPayment' , 'ContinueTransaction ' , msg_id ] ,
156
- '(String, String, [u8;32])' ,
88
+ [ 'BridgingPayment' , 'MakeRequest ' , amount , receiver , vara_token_id ] ,
89
+ '(String, String, U256, H160, [u8;32])' ,
157
90
'Null' ,
158
91
this . _program . programId ,
159
92
) ;
@@ -172,31 +105,14 @@ export class BridgingPayment {
172
105
) ;
173
106
}
174
107
175
- public requestToGateway (
176
- amount : number | string | bigint ,
177
- receiver : H160 ,
178
- vara_token_id : ActorId ,
179
- ) : TransactionBuilder < null > {
180
- if ( ! this . _program . programId ) throw new Error ( 'Program ID is not set' ) ;
181
- return new TransactionBuilder < null > (
182
- this . _program . api ,
183
- this . _program . registry ,
184
- 'send_message' ,
185
- [ 'BridgingPayment' , 'RequestToGateway' , amount , receiver , vara_token_id ] ,
186
- '(String, String, U256, H160, [u8;32])' ,
187
- 'Null' ,
188
- this . _program . programId ,
189
- ) ;
190
- }
191
-
192
- public returnTokens ( msg_id : MessageId ) : TransactionBuilder < null > {
108
+ public setConfig ( config : Config ) : TransactionBuilder < null > {
193
109
if ( ! this . _program . programId ) throw new Error ( 'Program ID is not set' ) ;
194
110
return new TransactionBuilder < null > (
195
111
this . _program . api ,
196
112
this . _program . registry ,
197
113
'send_message' ,
198
- [ 'BridgingPayment' , 'ReturnTokens ' , msg_id ] ,
199
- '(String, String, [u8;32] )' ,
114
+ [ 'BridgingPayment' , 'SetConfig ' , config ] ,
115
+ '(String, String, Config )' ,
200
116
'Null' ,
201
117
this . _program . programId ,
202
118
) ;
@@ -215,42 +131,13 @@ export class BridgingPayment {
215
131
) ;
216
132
}
217
133
218
- public updateConfig (
219
- fee : number | string | bigint | null ,
220
- gas_for_reply_deposit : number | string | bigint | null ,
221
- gas_to_send_request_to_gateway : number | string | bigint | null ,
222
- gas_to_transfer_tokens : number | string | bigint | null ,
223
- reply_timeout : number | null ,
224
- gas_for_request_to_gateway_msg : number | string | bigint | null ,
225
- ) : TransactionBuilder < null > {
134
+ public updateVftManagerAddress ( new_vft_manager_address : ActorId ) : TransactionBuilder < null > {
226
135
if ( ! this . _program . programId ) throw new Error ( 'Program ID is not set' ) ;
227
136
return new TransactionBuilder < null > (
228
137
this . _program . api ,
229
138
this . _program . registry ,
230
139
'send_message' ,
231
- [
232
- 'BridgingPayment' ,
233
- 'UpdateConfig' ,
234
- fee ,
235
- gas_for_reply_deposit ,
236
- gas_to_send_request_to_gateway ,
237
- gas_to_transfer_tokens ,
238
- reply_timeout ,
239
- gas_for_request_to_gateway_msg ,
240
- ] ,
241
- '(String, String, Option<u128>, Option<u64>, Option<u64>, Option<u64>, Option<u32>, Option<u64>)' ,
242
- 'Null' ,
243
- this . _program . programId ,
244
- ) ;
245
- }
246
-
247
- public updateVftGatewayAddress ( new_vft_gateway_address : ActorId ) : TransactionBuilder < null > {
248
- if ( ! this . _program . programId ) throw new Error ( 'Program ID is not set' ) ;
249
- return new TransactionBuilder < null > (
250
- this . _program . api ,
251
- this . _program . registry ,
252
- 'send_message' ,
253
- [ 'BridgingPayment' , 'UpdateVftGatewayAddress' , new_vft_gateway_address ] ,
140
+ [ 'BridgingPayment' , 'UpdateVftManagerAddress' , new_vft_manager_address ] ,
254
141
'(String, String, [u8;32])' ,
255
142
'Null' ,
256
143
this . _program . programId ,
@@ -295,34 +182,13 @@ export class BridgingPayment {
295
182
return result [ 2 ] . toJSON ( ) as unknown as Config ;
296
183
}
297
184
298
- public async msgTrackerState (
299
- originAddress ?: string ,
300
- value ?: number | string | bigint ,
301
- atBlock ?: `0x${string } `,
302
- ) : Promise < Array < [ MessageId , MessageInfo ] > > {
303
- const payload = this . _program . registry
304
- . createType ( '(String, String)' , [ 'BridgingPayment' , 'MsgTrackerState' ] )
305
- . toHex ( ) ;
306
- const reply = await this . _program . api . message . calculateReply ( {
307
- destination : this . _program . programId ! ,
308
- origin : originAddress ? decodeAddress ( originAddress ) : ZERO_ADDRESS ,
309
- payload,
310
- value : value || 0 ,
311
- gasLimit : this . _program . api . blockGasLimit . toBigInt ( ) ,
312
- at : atBlock ,
313
- } ) ;
314
- if ( ! reply . code . isSuccess ) throw new Error ( this . _program . registry . createType ( 'String' , reply . payload ) . toString ( ) ) ;
315
- const result = this . _program . registry . createType ( '(String, String, Vec<([u8;32], MessageInfo)>)' , reply . payload ) ;
316
- return result [ 2 ] . toJSON ( ) as unknown as Array < [ MessageId , MessageInfo ] > ;
317
- }
318
-
319
- public async vftGatewayAddress (
185
+ public async vftManagerAddress (
320
186
originAddress ?: string ,
321
187
value ?: number | string | bigint ,
322
188
atBlock ?: `0x${string } `,
323
189
) : Promise < ActorId > {
324
190
const payload = this . _program . registry
325
- . createType ( '(String, String)' , [ 'BridgingPayment' , 'VftGatewayAddress ' ] )
191
+ . createType ( '(String, String)' , [ 'BridgingPayment' , 'VftManagerAddress ' ] )
326
192
. toHex ( ) ;
327
193
const reply = await this . _program . api . message . calculateReply ( {
328
194
destination : this . _program . programId ! ,
0 commit comments