@@ -4,12 +4,7 @@ import { ServiceProps } from "../types/service";
44import { Integration } from "../types/integrations" ;
55import api from "../api" ;
66import { DecodedTxRaw } from "@cosmjs/proto-signing" ;
7- import {
8- CosmosSignedTx ,
9- CosmosTx ,
10- CosmosTxHash ,
11- CosmosTxStatus ,
12- } from "../types/cosmos" ;
7+ import { CosmosSignedTx , CosmosTx , CosmosTxHash , CosmosTxStatus } from "../types/cosmos" ;
138import { SigningAlgorithm } from "fireblocks-sdk" ;
149
1510export class FetService extends Service {
@@ -22,7 +17,7 @@ export class FetService extends Service {
2217 * @param amountFet
2318 */
2419 fetToAfet ( amountFet : string ) : string {
25- return ( parseFloat ( amountFet ) * 10 ** 18 ) . toFixed ( ) ;
20+ return ( BigInt ( amountFet ) * BigInt ( 10 ** 18 ) ) . toString ( ) ;
2621 }
2722
2823 /**
@@ -38,7 +33,7 @@ export class FetService extends Service {
3833 pubkey : string ,
3934 validatorAddress : string ,
4035 amountFet : number ,
41- restakeRewards : boolean = false
36+ restakeRewards : boolean = false ,
4237 ) : Promise < CosmosTx > {
4338 const { data } = await api . post < CosmosTx > ( `/v1/fet/transaction/stake` , {
4439 account_id : accountId ,
@@ -55,17 +50,11 @@ export class FetService extends Service {
5550 * @param pubkey wallet pubkey, this is different from the wallet address
5651 * @param validatorAddress validator address to which the delegation has been made
5752 */
58- async craftWithdrawRewardsTx (
59- pubkey : string ,
60- validatorAddress : string
61- ) : Promise < CosmosTx > {
62- const { data } = await api . post < CosmosTx > (
63- `/v1/fet/transaction/withdraw-rewards` ,
64- {
65- pubkey : pubkey ,
66- validator : validatorAddress ,
67- }
68- ) ;
53+ async craftWithdrawRewardsTx ( pubkey : string , validatorAddress : string ) : Promise < CosmosTx > {
54+ const { data } = await api . post < CosmosTx > ( `/v1/fet/transaction/withdraw-rewards` , {
55+ pubkey : pubkey ,
56+ validator : validatorAddress ,
57+ } ) ;
6958 return data ;
7059 }
7160
@@ -75,17 +64,11 @@ export class FetService extends Service {
7564 * @param validatorAccount validator account address (wallet controlling the validator)
7665 * @param validatorAddress validator address to which the delegation has been made
7766 */
78- async craftRestakeRewardsTx (
79- pubkey : string ,
80- validatorAddress : string
81- ) : Promise < CosmosTx > {
82- const { data } = await api . post < CosmosTx > (
83- `/v1/fet/transaction/restake-rewards` ,
84- {
85- pubkey : pubkey ,
86- validator_address : validatorAddress ,
87- }
88- ) ;
67+ async craftRestakeRewardsTx ( pubkey : string , validatorAddress : string ) : Promise < CosmosTx > {
68+ const { data } = await api . post < CosmosTx > ( `/v1/fet/transaction/restake-rewards` , {
69+ pubkey : pubkey ,
70+ validator_address : validatorAddress ,
71+ } ) ;
8972 return data ;
9073 }
9174
@@ -95,11 +78,7 @@ export class FetService extends Service {
9578 * @param validatorAddress validator address to which the delegation has been made
9679 * @param amountFet how many tokens to undelegate in FET
9780 */
98- async craftUnstakeTx (
99- pubkey : string ,
100- validatorAddress : string ,
101- amountFet ?: number
102- ) : Promise < CosmosTx > {
81+ async craftUnstakeTx ( pubkey : string , validatorAddress : string , amountFet ?: number ) : Promise < CosmosTx > {
10382 const { data } = await api . post < CosmosTx > ( `/v1/fet/transaction/unstake` , {
10483 pubkey : pubkey ,
10584 validator : validatorAddress ,
@@ -121,20 +100,15 @@ export class FetService extends Service {
121100 pubkey : string ,
122101 validatorSourceAddress : string ,
123102 validatorDestinationAddress : string ,
124- amountFet ?: number
103+ amountFet ?: number ,
125104 ) : Promise < CosmosTx > {
126- const { data } = await api . post < CosmosTx > (
127- `/v1/fet/transaction/redelegate` ,
128- {
129- account_id : accountId ,
130- pubkey : pubkey ,
131- validator_source : validatorSourceAddress ,
132- validator_destination : validatorDestinationAddress ,
133- amount_afet : amountFet
134- ? this . fetToAfet ( amountFet . toString ( ) )
135- : undefined ,
136- }
137- ) ;
105+ const { data } = await api . post < CosmosTx > ( `/v1/fet/transaction/redelegate` , {
106+ account_id : accountId ,
107+ pubkey : pubkey ,
108+ validator_source : validatorSourceAddress ,
109+ validator_destination : validatorDestinationAddress ,
110+ amount_afet : amountFet ? this . fetToAfet ( amountFet . toString ( ) ) : undefined ,
111+ } ) ;
138112 return data ;
139113 }
140114
@@ -144,33 +118,21 @@ export class FetService extends Service {
144118 * @param tx raw transaction
145119 * @param note note to identify the transaction in your custody solution
146120 */
147- async sign (
148- integration : Integration ,
149- tx : CosmosTx ,
150- note ?: string
151- ) : Promise < CosmosSignedTx > {
121+ async sign ( integration : Integration , tx : CosmosTx , note ?: string ) : Promise < CosmosSignedTx > {
152122 const payloadContent = tx . data . unsigned_tx_hash ;
153123 const derivationPath = [ 44 , 118 , integration . vaultId , 0 , 0 ] ;
154124 const signingAlgorithm = SigningAlgorithm . MPC_ECDSA_SECP256K1 ;
155125 const fbNote = note ? note : "FET tx from @kilnfi/sdk" ;
156126
157127 const signer = this . getFbSigner ( integration ) ;
158- const fbTx = await signer . signGenericWithFB (
159- payloadContent ,
160- derivationPath ,
161- signingAlgorithm ,
162- fbNote
163- ) ;
128+ const fbTx = await signer . signGenericWithFB ( payloadContent , derivationPath , signingAlgorithm , fbNote ) ;
164129 const signature : string = fbTx . signedMessages ! [ 0 ] . signature . fullSig ;
165- const { data } = await api . post < CosmosSignedTx > (
166- `/v1/fet/transaction/prepare` ,
167- {
168- pubkey : tx . data . pubkey ,
169- tx_body : tx . data . tx_body ,
170- tx_auth_info : tx . data . tx_auth_info ,
171- signature : signature ,
172- }
173- ) ;
130+ const { data } = await api . post < CosmosSignedTx > ( `/v1/fet/transaction/prepare` , {
131+ pubkey : tx . data . pubkey ,
132+ tx_body : tx . data . tx_body ,
133+ tx_auth_info : tx . data . tx_auth_info ,
134+ signature : signature ,
135+ } ) ;
174136 data . data . fireblocks_tx = fbTx ;
175137 return data ;
176138 }
@@ -180,12 +142,9 @@ export class FetService extends Service {
180142 * @param signedTx
181143 */
182144 async broadcast ( signedTx : CosmosSignedTx ) : Promise < CosmosTxHash > {
183- const { data } = await api . post < CosmosTxHash > (
184- `/v1/fet/transaction/broadcast` ,
185- {
186- tx_serialized : signedTx . data . signed_tx_serialized ,
187- }
188- ) ;
145+ const { data } = await api . post < CosmosTxHash > ( `/v1/fet/transaction/broadcast` , {
146+ tx_serialized : signedTx . data . signed_tx_serialized ,
147+ } ) ;
189148 return data ;
190149 }
191150
@@ -194,9 +153,7 @@ export class FetService extends Service {
194153 * @param txHash
195154 */
196155 async getTxStatus ( txHash : string ) : Promise < CosmosTxStatus > {
197- const { data } = await api . get < CosmosTxStatus > (
198- `/v1/fet/transaction/status?tx_hash=${ txHash } `
199- ) ;
156+ const { data } = await api . get < CosmosTxStatus > ( `/v1/fet/transaction/status?tx_hash=${ txHash } ` ) ;
200157 return data ;
201158 }
202159
@@ -205,9 +162,7 @@ export class FetService extends Service {
205162 * @param txSerialized transaction serialized
206163 */
207164 async decodeTx ( txSerialized : string ) : Promise < DecodedTxRaw > {
208- const { data } = await api . get < DecodedTxRaw > (
209- `/v1/fet/transaction/decode?tx_serialized=${ txSerialized } `
210- ) ;
165+ const { data } = await api . get < DecodedTxRaw > ( `/v1/fet/transaction/decode?tx_serialized=${ txSerialized } ` ) ;
211166 return data ;
212167 }
213168}
0 commit comments