@@ -19,7 +19,15 @@ import (
19
19
solclient "github.com/portto/solana-go-sdk/client"
20
20
)
21
21
22
- type SolanaExtractionProvider struct {}
22
+ // type SolanaExtractionProvider struct{}
23
+ type SolanaExtractionProvider int
24
+
25
+ func (provider SolanaExtractionProvider ) Build (isDirect bool ) ChainExtractionBridge {
26
+ if isDirect {
27
+ return & EthereumToSolanaExtractionBridge {}
28
+ }
29
+ return & SolanaToEVMExtractionBridge {}
30
+ }
23
31
24
32
type EthereumToSolanaExtractionBridge struct {
25
33
config ConfigureCommand
@@ -32,7 +40,6 @@ type EthereumToSolanaExtractionBridge struct {
32
40
33
41
solanaClient * solclient.Client
34
42
solanaCtx context.Context
35
- // solanaExecutor *solexecutor.GenericExecutor
36
43
37
44
IBPortDataAccount string
38
45
}
@@ -60,10 +67,6 @@ func (provider *EthereumToSolanaExtractionBridge) Configure(config ConfigureComm
60
67
61
68
provider .IBPortDataAccount = config .IBPortAddress
62
69
63
- // provider.solanaExecutor, err = solcommand.InitGenericExecutor(
64
-
65
- // )
66
-
67
70
return nil
68
71
}
69
72
@@ -97,10 +100,6 @@ func (provider *EthereumToSolanaExtractionBridge) pickRequestFromQueue(luState *
97
100
* on smart contracts (ports) does not have additional
98
101
* confirmation tx, we should check just for the existence of the swap with that id
99
102
*/
100
- //if ibRequest := ibState.Request(wavesRequestId); ibRequest != nil && Status(ibRequest.Status) == CompletedStatus {
101
- // if ibRequest := ibState.Request(wavesRequestId); ibRequest != nil && Status(ibRequest.Status) != CompletedStatus {
102
- // continue
103
- // }
104
103
var requestIdFixed SwapID
105
104
106
105
// validate target address
@@ -115,29 +114,29 @@ func (provider *EthereumToSolanaExtractionBridge) pickRequestFromQueue(luState *
115
114
continue
116
115
}
117
116
118
- fmt .Printf ("lu: %+v \n " , luRequest )
117
+ // fmt.Printf("lu: %+v \n", luRequest)
119
118
copy (requestIdFixed [:], rqIdInt .Bytes ()[0 :16 ])
120
119
121
- fmt .Printf ("requestIdFixed: %v \n " , requestIdFixed )
120
+ // fmt.Printf("requestIdFixed: %v \n", requestIdFixed)
122
121
123
122
ibRequestStatus := ibState .SwapStatusDict [requestIdFixed ]
124
123
125
- fmt .Printf ("RQ: %v; IB status: %v \n " , requestIdFixed , ibRequestStatus )
124
+ // fmt.Printf("RQ: %v; IB status: %v \n", requestIdFixed, ibRequestStatus)
126
125
127
- if ibRequestStatus != nil {
128
- fmt .Printf ("IB status(unwrapped): %v \n " , * ibRequestStatus )
129
- } else {
130
- fmt .Printf ("LU request: %+v \n " , luRequest )
131
- fmt .Printf ("IB status == nil: %v \n " , requestIdFixed )
132
- }
126
+ // if ibRequestStatus != nil {
127
+ // fmt.Printf("IB status(unwrapped): %v \n", *ibRequestStatus)
128
+ // } else {
129
+ // fmt.Printf("LU request: %+v \n", luRequest)
130
+ // fmt.Printf("IB status == nil: %v \n", requestIdFixed)
131
+ // }
133
132
134
133
if ibRequestStatus != nil && * ibRequestStatus == EthereumRequestStatusSuccess {
135
134
continue
136
135
}
137
136
138
- fmt .Printf ("Solana Address: %v \n " , base58 .Encode (luRequest .ForeignAddress [0 :32 ]))
137
+ // fmt.Printf("Solana Address: %v \n", base58.Encode(luRequest.ForeignAddress[0:32]))
139
138
if ! ValidateSolanaAddress (base58 .Encode (luRequest .ForeignAddress [0 :32 ])) {
140
- fmt .Printf ("swap_id: %v; solana address is invalid \n " , requestIdFixed )
139
+ // fmt.Printf("swap_id: %v; solana address is invalid \n", requestIdFixed)
141
140
continue
142
141
}
143
142
@@ -147,12 +146,12 @@ func (provider *EthereumToSolanaExtractionBridge) pickRequestFromQueue(luState *
147
146
provider .config .Meta ,
148
147
)
149
148
if tokenDataErr != nil || ! isTokenDataAccountPassed {
150
- fmt .Printf ("swap_id: %v; tokenDataErr: %v \n " , requestIdFixed , tokenDataErr )
149
+ // fmt.Printf("swap_id: %v; tokenDataErr: %v \n", requestIdFixed, tokenDataErr)
151
150
continue
152
151
}
153
152
154
153
if luRequest .Amount .Uint64 () == 0 {
155
- fmt .Printf ("swap_id: %v; amount is zero \n " , requestIdFixed )
154
+ // fmt.Printf("swap_id: %v; amount is zero \n", requestIdFixed)
156
155
continue
157
156
}
158
157
@@ -172,22 +171,12 @@ func (provider *EthereumToSolanaExtractionBridge) pickRequestFromQueue(luState *
172
171
return swapID , resultRqIdInt , nil
173
172
}
174
173
175
- func (provider * EthereumToSolanaExtractionBridge ) IBPortState () (* IBPortContractState , error ) {
176
- ibportStateResult , err := provider .solanaClient .GetAccountInfo (provider .solanaCtx , provider .IBPortDataAccount , solclient.GetAccountInfoConfig {
177
- Encoding : "base64" ,
178
- })
179
- if err != nil {
180
- return nil , err
181
- }
182
-
183
- ibportState := ibportStateResult .Data .([]interface {})[0 ].(string )
184
-
185
- stateDecoded , err := base64 .StdEncoding .DecodeString (ibportState )
186
- if err != nil {
187
- return nil , err
188
- }
189
-
190
- return DecodeIBPortState (stateDecoded ), nil
174
+ func (provider * EthereumToSolanaExtractionBridge ) IBPortState () (* PortContractState , error ) {
175
+ return GetSolanaPortContractState (
176
+ provider .solanaClient ,
177
+ provider .solanaCtx ,
178
+ provider .IBPortDataAccount ,
179
+ )
191
180
}
192
181
193
182
func (provider * EthereumToSolanaExtractionBridge ) requestSerializer (array []byte ) string {
@@ -207,7 +196,6 @@ func (provider *EthereumToSolanaExtractionBridge) ExtractDirectTransferRequest(c
207
196
if bytes .Equal (luRequestIds .First [:], make ([]byte , 32 )) {
208
197
return nil , extractors .NotFoundErr
209
198
}
210
-
211
199
if err != nil {
212
200
return nil , err
213
201
}
@@ -233,20 +221,20 @@ func (provider *EthereumToSolanaExtractionBridge) ExtractDirectTransferRequest(c
233
221
234
222
targetAmountCasted := float64 (targetAmount ) / float64 (solanaDecimals .Uint64 ())
235
223
236
- fmt .Printf ("rqId[:]: %v \n " , rqId [:])
237
- fmt .Printf ("rqId(len): %v \n " , len (rqId ))
224
+ // fmt.Printf("rqId[:]: %v \n", rqId[:])
225
+ // fmt.Printf("rqId(len): %v \n", len(rqId))
238
226
239
- fmt .Printf ("luRequest.ForeignAddress: %v \n " , luRequest .ForeignAddress )
240
- fmt .Printf ("luRequest.ForeignAddress: %v \n " , base58 .Encode (luRequest .ForeignAddress [:]))
227
+ // fmt.Printf("luRequest.ForeignAddress: %v \n", luRequest.ForeignAddress)
228
+ // fmt.Printf("luRequest.ForeignAddress: %v \n", base58.Encode(luRequest.ForeignAddress[:]))
241
229
242
- fmt .Printf ("targetAmount: %v \n " , targetAmount )
243
- fmt .Printf ("targetAmountCasted: %v \n " , targetAmountCasted )
230
+ // fmt.Printf("targetAmount: %v \n", targetAmount)
231
+ // fmt.Printf("targetAmountCasted: %v \n", targetAmountCasted)
244
232
245
233
var resultByteVector [64 ]byte
246
234
copy (resultByteVector [:], solexecutor .BuildCrossChainMintByteVector (rqId [:], luRequest .ForeignAddress , targetAmountCasted ))
247
235
248
236
// fmt.Printf("result byte string: %v \n", provider.requestSerializer(resultByteVector[:]))
249
- fmt .Printf ("result byte string(len): %v \n " , len (resultByteVector ))
237
+ // fmt.Printf("result byte string(len): %v \n", len(resultByteVector))
250
238
251
239
return & extractors.Data {
252
240
Type : extractors .Base64 ,
@@ -261,7 +249,7 @@ func (provider *EthereumToSolanaExtractionBridge) ExtractReverseTransferRequest(
261
249
}
262
250
263
251
var rqSwapID SwapID
264
- var reverseRequest * IBPortContractUnwrapRequest
252
+ var reverseRequest * PortContractUnwrapRequest
265
253
266
254
for swapID , burnRequest := range ibState .RequestsDict {
267
255
status := ibState .SwapStatusDict [swapID ]
@@ -317,7 +305,7 @@ func (provider *EthereumToSolanaExtractionBridge) ExtractReverseTransferRequest(
317
305
318
306
amount := MapAmount (int64 (reverseRequest .Amount ), provider .config .DestinationDecimals , provider .config .SourceDecimals )
319
307
320
- fmt .Printf ("amount mapped: %v \n " , amount )
308
+ // fmt.Printf("amount mapped: %v \n", amount)
321
309
322
310
var rqIDBytes [32 ]byte
323
311
copy (rqIDBytes [:], rqSwapID [:])
@@ -330,8 +318,8 @@ func (provider *EthereumToSolanaExtractionBridge) ExtractReverseTransferRequest(
330
318
331
319
result := BuildForEVMByteArray ('u' , rqIDBytes , amountBytes , evmReceiver )
332
320
333
- fmt .Printf ("result byte string: %v \n " , provider .requestSerializer (result [:]))
334
- fmt .Printf ("result byte string(len): %v \n " , len (result ))
321
+ // fmt.Printf("result byte string: %v \n", provider.requestSerializer(result[:]))
322
+ // fmt.Printf("result byte string(len): %v \n", len(result))
335
323
336
324
return & extractors.Data {
337
325
Type : extractors .Base64 ,
0 commit comments