diff --git a/src/services/ada.ts b/src/services/ada.ts index e3393e1..055a666 100644 --- a/src/services/ada.ts +++ b/src/services/ada.ts @@ -30,18 +30,14 @@ export class AdaService extends Service { walletAddress: string, poolId: string, ): Promise { - try { - const { data } = await api.post( - `/v1/ada/transaction/stake`, - { - account_id: accountId, - wallet: walletAddress, - pool_id: poolId, - }); - return data; - } catch (err: any) { - throw new Error(err); - } + const { data } = await api.post( + `/v1/ada/transaction/stake`, + { + account_id: accountId, + wallet: walletAddress, + pool_id: poolId, + }); + return data; } /** @@ -53,17 +49,13 @@ export class AdaService extends Service { walletAddress: string, amountAda?: number, ): Promise { - try { - const { data } = await api.post( - `/v1/ada/transaction/withdraw-rewards`, - { - wallet: walletAddress, - amount_lovelace: amountAda ? this.adaToLovelace(amountAda.toString()) : undefined, - }); - return data; - } catch (err: any) { - throw new Error(err); - } + const { data } = await api.post( + `/v1/ada/transaction/withdraw-rewards`, + { + wallet: walletAddress, + amount_lovelace: amountAda ? this.adaToLovelace(amountAda.toString()) : undefined, + }); + return data; } /** @@ -73,16 +65,12 @@ export class AdaService extends Service { async craftUnstakeTx( walletAddress: string, ): Promise { - try { - const { data } = await api.post( - `/v1/ada/transaction/unstake`, - { - wallet: walletAddress, - }); - return data; - } catch (err: any) { - throw new Error(err); - } + const { data } = await api.post( + `/v1/ada/transaction/unstake`, + { + wallet: walletAddress, + }); + return data; } /** @@ -100,51 +88,47 @@ export class AdaService extends Service { * @param note note to identify the transaction in your custody solution */ async sign(integration: Integration, tx: AdaTx, note?: string): Promise { - try { - const fbSigner = this.getFbSigner(integration); - const payload = { - rawMessageData: { - messages: [ - { - 'content': tx.data.unsigned_tx_hash, - }, - { - 'content': tx.data.unsigned_tx_hash, - 'bip44change': 2, - }, - ], - }, - inputsSelection: { - inputsToSpend: tx.data.inputs, - }, - }; + const fbSigner = this.getFbSigner(integration); + const payload = { + rawMessageData: { + messages: [ + { + 'content': tx.data.unsigned_tx_hash, + }, + { + 'content': tx.data.unsigned_tx_hash, + 'bip44change': 2, + }, + ], + }, + inputsSelection: { + inputsToSpend: tx.data.inputs, + }, + }; - const fbNote = note ? note : 'ADA tx from @kilnfi/sdk'; - const fbTx = await fbSigner.signWithFB(payload, this.testnet ? 'ADA_TEST' : 'ADA', fbNote); + const fbNote = note ? note : 'ADA tx from @kilnfi/sdk'; + const fbTx = await fbSigner.signWithFB(payload, this.testnet ? 'ADA_TEST' : 'ADA', fbNote); - if (!fbTx.signedMessages) { - throw new Error(`Could not sign the transaction.`); - } + if (!fbTx.signedMessages) { + throw new Error(`Could not sign the transaction.`); + } - const signedMessages: AdaSignedMessage[] = fbTx.signedMessages.map((message) => { - return { - pubkey: message.publicKey, - signature: message.signature.fullSig, - }; - }); + const signedMessages: AdaSignedMessage[] = fbTx.signedMessages.map((message) => { + return { + pubkey: message.publicKey, + signature: message.signature.fullSig, + }; + }); - const { data } = await api.post( - `/v1/ada/transaction/prepare`, - { - unsigned_tx_serialized: tx.data.unsigned_tx_serialized, - signed_messages: signedMessages, - }); + const { data } = await api.post( + `/v1/ada/transaction/prepare`, + { + unsigned_tx_serialized: tx.data.unsigned_tx_serialized, + signed_messages: signedMessages, + }); - data.data.fireblocks_tx = fbTx; - return data; - } catch (err: any) { - throw new Error(err); - } + data.data.fireblocks_tx = fbTx; + return data; } /** @@ -152,16 +136,12 @@ export class AdaService extends Service { * @param signedTx */ async broadcast(signedTx: AdaSignedTx): Promise { - try { - const { data } = await api.post( - `/v1/ada/transaction/broadcast`, - { - tx_serialized: signedTx.data.signed_tx_serialized, - }); - return data; - } catch (error: any) { - throw new Error(error); - } + const { data } = await api.post( + `/v1/ada/transaction/broadcast`, + { + tx_serialized: signedTx.data.signed_tx_serialized, + }); + return data; } /** @@ -169,13 +149,9 @@ export class AdaService extends Service { * @param txHash transaction hash */ async getTxStatus(txHash: string): Promise { - try { - const { data } = await api.get( - `/v1/ada/transaction/status?tx_hash=${txHash}`); - return data; - } catch (error: any) { - throw new Error(error); - } + const { data } = await api.get( + `/v1/ada/transaction/status?tx_hash=${txHash}`); + return data; } /** @@ -183,13 +159,9 @@ export class AdaService extends Service { * @param txSerialized transaction serialized */ async decodeTx(txSerialized: string): Promise { - try { - const { data } = await api.get( - `/v1/ada/transaction/decode?tx_serialized=${txSerialized}`); - return data; - } catch (error: any) { - throw new Error(error); - } + const { data } = await api.get( + `/v1/ada/transaction/decode?tx_serialized=${txSerialized}`); + return data; } /** @@ -200,13 +172,9 @@ export class AdaService extends Service { async getStakesByAccounts( accountIds: string[], ): Promise { - try { - const { data } = await api.get( - `/v1/ada/stakes?accounts=${accountIds.join(',')}`); - return data; - } catch (err: any) { - throw new Error(err); - } + const { data } = await api.get( + `/v1/ada/stakes?accounts=${accountIds.join(',')}`); + return data; } /** @@ -217,13 +185,9 @@ export class AdaService extends Service { async getStakesByStakeAddresses( stakeAddresses: string[], ): Promise { - try { - const { data } = await api.get( - `/v1/ada/stakes?stake_addresses=${stakeAddresses.join(',')}`); - return data; - } catch (err: any) { - throw new Error(err); - } + const { data } = await api.get( + `/v1/ada/stakes?stake_addresses=${stakeAddresses.join(',')}`); + return data; } /** @@ -234,13 +198,9 @@ export class AdaService extends Service { async getStakesByWallets( wallets: string[], ): Promise { - try { - const { data } = await api.get( - `/v1/ada/stakes?wallets=${wallets.join(',')}`); - return data; - } catch (err: any) { - throw new Error(err); - } + const { data } = await api.get( + `/v1/ada/stakes?wallets=${wallets.join(',')}`); + return data; } /** @@ -255,15 +215,13 @@ export class AdaService extends Service { startDate?: string, endDate?: string, ): Promise { - try { - const query = `/v1/ada/rewards?accounts=${accountIds.join(',')}${ - startDate ? `&start_date=${startDate}` : '' - }${endDate ? `&end_date=${endDate}` : ''}`; - const { data } = await api.get(query); - return data; - } catch (err: any) { - throw new Error(err); - } + + const query = `/v1/ada/rewards?accounts=${accountIds.join(',')}${ + startDate ? `&start_date=${startDate}` : '' + }${endDate ? `&end_date=${endDate}` : ''}`; + const { data } = await api.get(query); + return data; + } /** @@ -278,15 +236,13 @@ export class AdaService extends Service { startDate?: string, endDate?: string, ): Promise { - try { - const query = `/v1/ada/rewards?stake_addresses=${stakeAddresses.join(',')}${ - startDate ? `&start_date=${startDate}` : '' - }${endDate ? `&end_date=${endDate}` : ''}`; - const { data } = await api.get(query); - return data; - } catch (err: any) { - throw new Error(err); - } + + const query = `/v1/ada/rewards?stake_addresses=${stakeAddresses.join(',')}${ + startDate ? `&start_date=${startDate}` : '' + }${endDate ? `&end_date=${endDate}` : ''}`; + const { data } = await api.get(query); + return data; + } /** @@ -301,28 +257,24 @@ export class AdaService extends Service { startDate?: string, endDate?: string, ): Promise { - try { - const query = `/v1/ada/rewards?wallets=${wallets.join(',')}${ - startDate ? `&start_date=${startDate}` : '' - }${endDate ? `&end_date=${endDate}` : ''}`; - const { data } = await api.get(query); - return data; - } catch (err: any) { - throw new Error(err); - } + + const query = `/v1/ada/rewards?wallets=${wallets.join(',')}${ + startDate ? `&start_date=${startDate}` : '' + }${endDate ? `&end_date=${endDate}` : ''}`; + const { data } = await api.get(query); + return data; + } /** * Retrieve ADA network stats */ async getNetworkStats(): Promise { - try { - const { data } = await api.get( - `/v1/ada/network-stats`, - ); - return data; - } catch (err: any) { - throw new Error(err); - } + + const { data } = await api.get( + `/v1/ada/network-stats`, + ); + return data; + } } diff --git a/src/services/atom.ts b/src/services/atom.ts index ce3a0da..a9ddd54 100644 --- a/src/services/atom.ts +++ b/src/services/atom.ts @@ -34,19 +34,17 @@ export class AtomService extends Service { validatorAddress: string, amountAtom: number, ): Promise { - try { - const { data } = await api.post( - `/v1/atom/transaction/stake`, - { - account_id: accountId, - pubkey: pubkey, - validator: validatorAddress, - amount_uatom: this.atomToUatom(amountAtom.toString()), - }); - return data; - } catch (err: any) { - throw new Error(err); - } + + const { data } = await api.post( + `/v1/atom/transaction/stake`, + { + account_id: accountId, + pubkey: pubkey, + validator: validatorAddress, + amount_uatom: this.atomToUatom(amountAtom.toString()), + }); + return data; + } /** @@ -58,17 +56,15 @@ export class AtomService extends Service { pubkey: string, validatorAddress: string, ): Promise { - try { - const { data } = await api.post( - `/v1/atom/transaction/withdraw-rewards`, - { - pubkey: pubkey, - validator: validatorAddress, - }); - return data; - } catch (err: any) { - throw new Error(err); - } + + const { data } = await api.post( + `/v1/atom/transaction/withdraw-rewards`, + { + pubkey: pubkey, + validator: validatorAddress, + }); + return data; + } /** @@ -82,18 +78,16 @@ export class AtomService extends Service { validatorAddress: string, amountAtom?: number, ): Promise { - try { - const { data } = await api.post( - `/v1/atom/transaction/unstake`, - { - pubkey: pubkey, - validator: validatorAddress, - amount_uatom: amountAtom ? this.atomToUatom(amountAtom.toString()) : undefined, - }); - return data; - } catch (err: any) { - throw new Error(err); - } + + const { data } = await api.post( + `/v1/atom/transaction/unstake`, + { + pubkey: pubkey, + validator: validatorAddress, + amount_uatom: amountAtom ? this.atomToUatom(amountAtom.toString()) : undefined, + }); + return data; + } /** @@ -111,20 +105,18 @@ export class AtomService extends Service { validatorDestinationAddress: string, amountAtom?: number, ): Promise { - try { - const { data } = await api.post( - `/v1/atom/transaction/redelegate`, - { - account_id: accountId, - pubkey: pubkey, - validator_source: validatorSourceAddress, - validator_destination: validatorDestinationAddress, - amount_uatom: amountAtom ? this.atomToUatom(amountAtom.toString()) : undefined, - }); - return data; - } catch (err: any) { - throw new Error(err); - } + + const { data } = await api.post( + `/v1/atom/transaction/redelegate`, + { + account_id: accountId, + pubkey: pubkey, + validator_source: validatorSourceAddress, + validator_destination: validatorDestinationAddress, + amount_uatom: amountAtom ? this.atomToUatom(amountAtom.toString()) : undefined, + }); + return data; + } /** @@ -165,16 +157,14 @@ export class AtomService extends Service { * @param signedTx */ async broadcast(signedTx: CosmosSignedTx): Promise { - try { - const { data } = await api.post( - `/v1/atom/transaction/broadcast`, - { - tx_serialized: signedTx.data.signed_tx_serialized, - }); - return data; - } catch (e: any) { - throw new Error(e); - } + + const { data } = await api.post( + `/v1/atom/transaction/broadcast`, + { + tx_serialized: signedTx.data.signed_tx_serialized, + }); + return data; + } /** @@ -182,13 +172,11 @@ export class AtomService extends Service { * @param txHash */ async getTxStatus(txHash: string): Promise { - try { - const { data } = await api.get( - `/v1/atom/transaction/status?tx_hash=${txHash}`); - return data; - } catch (e: any) { - throw new Error(e); - } + + const { data } = await api.get( + `/v1/atom/transaction/status?tx_hash=${txHash}`); + return data; + } /** @@ -196,13 +184,11 @@ export class AtomService extends Service { * @param txSerialized transaction serialized */ async decodeTx(txSerialized: string): Promise { - try { - const { data } = await api.get( - `/v1/atom/transaction/decode?tx_serialized=${txSerialized}`); - return data; - } catch (error: any) { - throw new Error(error); - } + + const { data } = await api.get( + `/v1/atom/transaction/decode?tx_serialized=${txSerialized}`); + return data; + } /** @@ -213,13 +199,11 @@ export class AtomService extends Service { async getStakesByAccounts( accountIds: string[], ): Promise { - try { - const { data } = await api.get( - `/v1/atom/stakes?accounts=${accountIds.join(',')}`); - return data; - } catch (err: any) { - throw new Error(err); - } + + const { data } = await api.get( + `/v1/atom/stakes?accounts=${accountIds.join(',')}`); + return data; + } /** @@ -232,13 +216,11 @@ export class AtomService extends Service { delegators: string[], validators: string[], ): Promise { - try { - const { data } = await api.get( - `/v1/atom/stakes?delegators=${delegators.join(',')}&validators=${validators.join(',')}`); - return data; - } catch (err: any) { - throw new Error(err); - } + + const { data } = await api.get( + `/v1/atom/stakes?delegators=${delegators.join(',')}&validators=${validators.join(',')}`); + return data; + } /** @@ -253,15 +235,13 @@ export class AtomService extends Service { startDate?: string, endDate?: string, ): Promise { - try { - const query = `/v1/atom/rewards?accounts=${accountIds.join(',')}${ - startDate ? `&start_date=${startDate}` : '' - }${endDate ? `&end_date=${endDate}` : ''}`; - const { data } = await api.get(query); - return data; - } catch (err: any) { - throw new Error(err); - } + + const query = `/v1/atom/rewards?accounts=${accountIds.join(',')}${ + startDate ? `&start_date=${startDate}` : '' + }${endDate ? `&end_date=${endDate}` : ''}`; + const { data } = await api.get(query); + return data; + } /** @@ -278,14 +258,12 @@ export class AtomService extends Service { startDate?: string, endDate?: string, ): Promise { - try { - const query = `/v1/atom/rewards?delegators=${delegators.join(',')}&validators=${validators.join(',')}${ - startDate ? `&start_date=${startDate}` : '' - }${endDate ? `&end_date=${endDate}` : ''}`; - const { data } = await api.get(query); - return data; - } catch (err: any) { - throw new Error(err); - } + + const query = `/v1/atom/rewards?delegators=${delegators.join(',')}&validators=${validators.join(',')}${ + startDate ? `&start_date=${startDate}` : '' + }${endDate ? `&end_date=${endDate}` : ''}`; + const { data } = await api.get(query); + return data; + } } diff --git a/src/services/dot.ts b/src/services/dot.ts index 316e8e9..59d5a82 100644 --- a/src/services/dot.ts +++ b/src/services/dot.ts @@ -46,19 +46,17 @@ export class DotService extends Service { rewardDestination: DotRewardDestination, ): Promise { const amountPlanck = this.testnet ? this.wndToPlanck(amountDot.toString()) : this.dotToPlanck(amountDot.toString()); - try { - const { data } = await api.post( - `/v1/dot/transaction/bond`, - { - account_id: accountId, - stash_account: stashAccount, - amount_planck: amountPlanck, - reward_destination: rewardDestination, - }); - return data; - } catch (err: any) { - throw new Error(err); - } + + const { data } = await api.post( + `/v1/dot/transaction/bond`, + { + account_id: accountId, + stash_account: stashAccount, + amount_planck: amountPlanck, + reward_destination: rewardDestination, + }); + return data; + } /** @@ -71,17 +69,15 @@ export class DotService extends Service { amountDot: number, ): Promise { const amountPlanck = this.testnet ? this.wndToPlanck(amountDot.toString()) : this.dotToPlanck(amountDot.toString()); - try { - const { data } = await api.post( - `/v1/dot/transaction/bond-extra`, - { - stash_account: stashAccount, - amount_planck: amountPlanck, - }); - return data; - } catch (err: any) { - throw new Error(err); - } + + const { data } = await api.post( + `/v1/dot/transaction/bond-extra`, + { + stash_account: stashAccount, + amount_planck: amountPlanck, + }); + return data; + } /** @@ -94,17 +90,15 @@ export class DotService extends Service { amountDot: number, ): Promise { const amountPlanck = this.testnet ? this.wndToPlanck(amountDot.toString()) : this.dotToPlanck(amountDot.toString()); - try { - const { data } = await api.post( - `/v1/dot/transaction/rebond`, - { - stash_account: stashAccount, - amount_planck: amountPlanck, - }); - return data; - } catch (err: any) { - throw new Error(err); - } + + const { data } = await api.post( + `/v1/dot/transaction/rebond`, + { + stash_account: stashAccount, + amount_planck: amountPlanck, + }); + return data; + } /** @@ -116,17 +110,15 @@ export class DotService extends Service { stashAccount: string, validatorAddresses: string[], ): Promise { - try { - const { data } = await api.post( - `/v1/dot/transaction/nominate`, - { - stash_account: stashAccount, - validator_addresses: validatorAddresses, - }); - return data; - } catch (err: any) { - throw new Error(err); - } + + const { data } = await api.post( + `/v1/dot/transaction/nominate`, + { + stash_account: stashAccount, + validator_addresses: validatorAddresses, + }); + return data; + } /** @@ -139,17 +131,15 @@ export class DotService extends Service { amountDot: number, ): Promise { const amountPlanck = this.testnet ? this.wndToPlanck(amountDot.toString()) : this.dotToPlanck(amountDot.toString()); - try { - const { data } = await api.post( - `/v1/dot/transaction/unbond`, - { - stash_account: stashAccount, - amount_planck: amountPlanck, - }); - return data; - } catch (err: any) { - throw new Error(err); - } + + const { data } = await api.post( + `/v1/dot/transaction/unbond`, + { + stash_account: stashAccount, + amount_planck: amountPlanck, + }); + return data; + } /** @@ -159,16 +149,14 @@ export class DotService extends Service { async craftWithdrawUnbondedTx( stashAccount: string, ): Promise { - try { - const { data } = await api.post( - `/v1/dot/transaction/withdraw-unbonded`, - { - stash_account: stashAccount, - }); - return data; - } catch (err: any) { - throw new Error(err); - } + + const { data } = await api.post( + `/v1/dot/transaction/withdraw-unbonded`, + { + stash_account: stashAccount, + }); + return data; + } /** @@ -181,16 +169,14 @@ export class DotService extends Service { async craftChillTx( stashAccount: string, ): Promise { - try { - const { data } = await api.post( - `/v1/dot/transaction/chill`, - { - stash_account: stashAccount, - }); - return data; - } catch (err: any) { - throw new Error(err); - } + + const { data } = await api.post( + `/v1/dot/transaction/chill`, + { + stash_account: stashAccount, + }); + return data; + } /** @@ -206,17 +192,15 @@ export class DotService extends Service { stashAccount: string, rewardsDestination: DotRewardDestination, ): Promise { - try { - const { data } = await api.post( - `/v1/dot/transaction/set-payee`, - { - stash_account: stashAccount, - reward_destination: rewardsDestination, - }); - return data; - } catch (err: any) { - throw new Error(err); - } + + const { data } = await api.post( + `/v1/dot/transaction/set-payee`, + { + stash_account: stashAccount, + reward_destination: rewardsDestination, + }); + return data; + } /** @@ -233,20 +217,18 @@ export class DotService extends Service { amountDot: number, poolId: string, ): Promise { - try { - const amountPlanck = this.testnet ? this.wndToPlanck(amountDot.toString()) : this.dotToPlanck(amountDot.toString()); - const { data } = await api.post( - `/v1/dot/transaction/join-pool`, - { - account_id: accountId, - member_account: memberAccount, - amount_planck: amountPlanck, - pool_id: poolId, - }); - return data; - } catch (err: any) { - throw new Error(err); - } + + const amountPlanck = this.testnet ? this.wndToPlanck(amountDot.toString()) : this.dotToPlanck(amountDot.toString()); + const { data } = await api.post( + `/v1/dot/transaction/join-pool`, + { + account_id: accountId, + member_account: memberAccount, + amount_planck: amountPlanck, + pool_id: poolId, + }); + return data; + } /** @@ -260,18 +242,16 @@ export class DotService extends Service { memberAccount: string, amountDot: number, ): Promise { - try { - const amountPlanck = this.testnet ? this.wndToPlanck(amountDot.toString()) : this.dotToPlanck(amountDot.toString()); - const { data } = await api.post( - `/v1/dot/transaction/bond-extra-pool`, - { - member_account: memberAccount, - amount_planck: amountPlanck, - }); - return data; - } catch (err: any) { - throw new Error(err); - } + + const amountPlanck = this.testnet ? this.wndToPlanck(amountDot.toString()) : this.dotToPlanck(amountDot.toString()); + const { data } = await api.post( + `/v1/dot/transaction/bond-extra-pool`, + { + member_account: memberAccount, + amount_planck: amountPlanck, + }); + return data; + } /** @@ -281,16 +261,14 @@ export class DotService extends Service { async craftBondRewardsToPoolTx( memberAccount: string, ): Promise { - try { - const { data } = await api.post( - `/v1/dot/transaction/bond-rewards-pool`, - { - member_account: memberAccount, - }); - return data; - } catch (err: any) { - throw new Error(err); - } + + const { data } = await api.post( + `/v1/dot/transaction/bond-rewards-pool`, + { + member_account: memberAccount, + }); + return data; + } /** @@ -305,16 +283,14 @@ export class DotService extends Service { async craftClaimPayoutFromPoolTx( memberAccount: string, ): Promise { - try { - const { data } = await api.post( - `/v1/dot/transaction/claim-payout-pool`, - { - member_account: memberAccount, - }); - return data; - } catch (err: any) { - throw new Error(err); - } + + const { data } = await api.post( + `/v1/dot/transaction/claim-payout-pool`, + { + member_account: memberAccount, + }); + return data; + } /** @@ -329,18 +305,16 @@ export class DotService extends Service { memberAccount: string, amountDot: number, ): Promise { - try { - const amountPlanck = this.testnet ? this.wndToPlanck(amountDot.toString()) : this.dotToPlanck(amountDot.toString()); - const { data } = await api.post( - `/v1/dot/transaction/unbond-pool`, - { - member_account: memberAccount, - amount_planck: amountPlanck, - }); - return data; - } catch (err: any) { - throw new Error(err); - } + + const amountPlanck = this.testnet ? this.wndToPlanck(amountDot.toString()) : this.dotToPlanck(amountDot.toString()); + const { data } = await api.post( + `/v1/dot/transaction/unbond-pool`, + { + member_account: memberAccount, + amount_planck: amountPlanck, + }); + return data; + } /** @@ -351,16 +325,14 @@ export class DotService extends Service { async craftWithdrawUnbondedFromPoolTx( memberAccount: string, ): Promise { - try { - const { data } = await api.post( - `/v1/dot/transaction/withdraw-unbonded-pool`, - { - member_account: memberAccount, - }); - return data; - } catch (err: any) { - throw new Error(err); - } + + const { data } = await api.post( + `/v1/dot/transaction/withdraw-unbonded-pool`, + { + member_account: memberAccount, + }); + return data; + } /** @@ -370,33 +342,31 @@ export class DotService extends Service { * @param note note to identify the transaction in your custody solution */ async sign(integration: Integration, tx: DotTx, note?: string): Promise { - try { - const payload = { - rawMessageData: { - messages: [ - { - content: tx.data.unsigned_tx_payload.substring(2), - }, - ], - }, - }; - - const fbSigner = this.getFbSigner(integration); - const fbNote = note ? note : 'DOT tx from @kilnfi/sdk'; - const fbTx = await fbSigner.signWithFB(payload, this.testnet ? 'WND' : 'DOT', fbNote); - const signature = `0x00${fbTx.signedMessages![0].signature.fullSig}`; - - const { data } = await api.post( - `/v1/dot/transaction/prepare`, - { - unsigned_tx_serialized: tx.data.unsigned_tx_serialized, - signature: signature, - }); - data.data.fireblocks_tx = fbTx; - return data; - } catch (err: any) { - throw new Error(err); - } + + const payload = { + rawMessageData: { + messages: [ + { + content: tx.data.unsigned_tx_payload.substring(2), + }, + ], + }, + }; + + const fbSigner = this.getFbSigner(integration); + const fbNote = note ? note : 'DOT tx from @kilnfi/sdk'; + const fbTx = await fbSigner.signWithFB(payload, this.testnet ? 'WND' : 'DOT', fbNote); + const signature = `0x00${fbTx.signedMessages![0].signature.fullSig}`; + + const { data } = await api.post( + `/v1/dot/transaction/prepare`, + { + unsigned_tx_serialized: tx.data.unsigned_tx_serialized, + signature: signature, + }); + data.data.fireblocks_tx = fbTx; + return data; + } /** @@ -404,16 +374,14 @@ export class DotService extends Service { * @param signedTx */ async broadcast(signedTx: DotSignedTx): Promise { - try { - const { data } = await api.post( - `/v1/dot/transaction/broadcast`, - { - tx_serialized: signedTx.data.signed_tx_serialized, - }); - return data; - } catch (err: any) { - throw new Error(err); - } + + const { data } = await api.post( + `/v1/dot/transaction/broadcast`, + { + tx_serialized: signedTx.data.signed_tx_serialized, + }); + return data; + } /** @@ -423,12 +391,10 @@ export class DotService extends Service { async getTxStatus( txHash: string, ): Promise { - try { - const { data } = await api.get(`/v1/dot/transaction/status?tx_hash=${txHash}`); - return data; - } catch (err: any) { - throw new Error(err); - } + + const { data } = await api.get(`/v1/dot/transaction/status?tx_hash=${txHash}`); + return data; + } /** @@ -436,12 +402,10 @@ export class DotService extends Service { * @param txSerialized transaction serialized */ async decodeTx(txSerialized: string): Promise { - try { - const { data } = await api.get( - `/v1/dot/transaction/decode?tx_serialized=${txSerialized}`); - return data; - } catch (error: any) { - throw new Error(error); - } + + const { data } = await api.get( + `/v1/dot/transaction/decode?tx_serialized=${txSerialized}`); + return data; + } } diff --git a/src/services/dydx.ts b/src/services/dydx.ts index ca2ba8d..560ca91 100644 --- a/src/services/dydx.ts +++ b/src/services/dydx.ts @@ -33,19 +33,17 @@ export class DydxService extends Service { validatorAddress: string, amountDydx: number, ): Promise { - try { - const { data } = await api.post( - `/v1/dydx/transaction/stake`, - { - account_id: accountId, - pubkey: pubkey, - validator: validatorAddress, - amount_adydx: this.dydxToAdydx(amountDydx.toString()), - }); - return data; - } catch (err: any) { - throw new Error(err); - } + + const { data } = await api.post( + `/v1/dydx/transaction/stake`, + { + account_id: accountId, + pubkey: pubkey, + validator: validatorAddress, + amount_adydx: this.dydxToAdydx(amountDydx.toString()), + }); + return data; + } /** @@ -57,17 +55,15 @@ export class DydxService extends Service { pubkey: string, validatorAddress: string, ): Promise { - try { - const { data } = await api.post( - `/v1/dydx/transaction/withdraw-rewards`, - { - pubkey: pubkey, - validator: validatorAddress, - }); - return data; - } catch (err: any) { - throw new Error(err); - } + + const { data } = await api.post( + `/v1/dydx/transaction/withdraw-rewards`, + { + pubkey: pubkey, + validator: validatorAddress, + }); + return data; + } /** @@ -81,18 +77,16 @@ export class DydxService extends Service { validatorAddress: string, amountDydx?: number, ): Promise { - try { - const { data } = await api.post( - `/v1/dydx/transaction/unstake`, - { - pubkey: pubkey, - validator: validatorAddress, - amount_adydx: amountDydx ? this.dydxToAdydx(amountDydx.toString()) : undefined, - }); - return data; - } catch (err: any) { - throw new Error(err); - } + + const { data } = await api.post( + `/v1/dydx/transaction/unstake`, + { + pubkey: pubkey, + validator: validatorAddress, + amount_adydx: amountDydx ? this.dydxToAdydx(amountDydx.toString()) : undefined, + }); + return data; + } /** @@ -110,20 +104,18 @@ export class DydxService extends Service { validatorDestinationAddress: string, amountDydx?: number, ): Promise { - try { - const { data } = await api.post( - `/v1/dydx/transaction/redelegate`, - { - account_id: accountId, - pubkey: pubkey, - validator_source: validatorSourceAddress, - validator_destination: validatorDestinationAddress, - amount_adydx: amountDydx ? this.dydxToAdydx(amountDydx.toString()) : undefined, - }); - return data; - } catch (err: any) { - throw new Error(err); - } + + const { data } = await api.post( + `/v1/dydx/transaction/redelegate`, + { + account_id: accountId, + pubkey: pubkey, + validator_source: validatorSourceAddress, + validator_destination: validatorDestinationAddress, + amount_adydx: amountDydx ? this.dydxToAdydx(amountDydx.toString()) : undefined, + }); + return data; + } /** @@ -164,16 +156,14 @@ export class DydxService extends Service { * @param signedTx */ async broadcast(signedTx: CosmosSignedTx): Promise { - try { - const { data } = await api.post( - `/v1/dydx/transaction/broadcast`, - { - tx_serialized: signedTx.data.signed_tx_serialized, - }); - return data; - } catch (e: any) { - throw new Error(e); - } + + const { data } = await api.post( + `/v1/dydx/transaction/broadcast`, + { + tx_serialized: signedTx.data.signed_tx_serialized, + }); + return data; + } /** @@ -181,13 +171,11 @@ export class DydxService extends Service { * @param txHash */ async getTxStatus(txHash: string): Promise { - try { - const { data } = await api.get( - `/v1/dydx/transaction/status?tx_hash=${txHash}`); - return data; - } catch (e: any) { - throw new Error(e); - } + + const { data } = await api.get( + `/v1/dydx/transaction/status?tx_hash=${txHash}`); + return data; + } /** @@ -195,12 +183,10 @@ export class DydxService extends Service { * @param txSerialized transaction serialized */ async decodeTx(txSerialized: string): Promise { - try { - const { data } = await api.get( - `/v1/dydx/transaction/decode?tx_serialized=${txSerialized}`); - return data; - } catch (error: any) { - throw new Error(error); - } + + const { data } = await api.get( + `/v1/dydx/transaction/decode?tx_serialized=${txSerialized}`); + return data; + } } diff --git a/src/services/eth.ts b/src/services/eth.ts index 66fffe3..ee3fc67 100644 --- a/src/services/eth.ts +++ b/src/services/eth.ts @@ -32,18 +32,16 @@ export class EthService extends Service { walletAddress: string, amountEth: number, ): Promise { - try { - const { data } = await api.post( - `/v1/eth/transaction/stake`, - { - account_id: accountId, - wallet: walletAddress, - amount_wei: this.ethToWei(amountEth.toString()), - }); - return data; - } catch (err: any) { - throw new Error(err); - } + + const { data } = await api.post( + `/v1/eth/transaction/stake`, + { + account_id: accountId, + wallet: walletAddress, + amount_wei: this.ethToWei(amountEth.toString()), + }); + return data; + } /** @@ -55,17 +53,15 @@ export class EthService extends Service { walletAddress: string, validatorAddresses: string[], ): Promise { - try { - const { data } = await api.post( - `/v1/eth/transaction/exit-request`, - { - wallet: walletAddress, - validators: validatorAddresses, - }); - return data; - } catch (err: any) { - throw new Error(err); - } + + const { data } = await api.post( + `/v1/eth/transaction/exit-request`, + { + wallet: walletAddress, + validators: validatorAddresses, + }); + return data; + } /** @@ -75,38 +71,36 @@ export class EthService extends Service { * @param note note to identify the transaction in your custody solution */ async sign(integration: Integration, tx: EthTx, note?: string): Promise { - try { - const payload = { - rawMessageData: { - messages: [ - { - 'content': tx.data.unsigned_tx_hash, - }, - ], - }, - }; - - const fbSigner = this.getFbSigner(integration); - const assetId = this.testnet ? 'ETH_TEST6' : 'ETH'; - const fbNote = note ? note : 'ETH tx from @kilnfi/sdk'; - const fbTx = await fbSigner.signWithFB( - payload, - assetId, - fbNote, - ); - const { data } = await api.post( - `/v1/eth/transaction/prepare`, - { - unsigned_tx_serialized: tx.data.unsigned_tx_serialized, - r: `0x${fbTx?.signedMessages?.[0].signature.r}`, - s: `0x${fbTx?.signedMessages?.[0].signature.s}`, - v: fbTx?.signedMessages?.[0].signature.v ?? 0, - }); - data.data.fireblocks_tx = fbTx; - return data; - } catch (err: any) { - throw new Error(err); - } + + const payload = { + rawMessageData: { + messages: [ + { + 'content': tx.data.unsigned_tx_hash, + }, + ], + }, + }; + + const fbSigner = this.getFbSigner(integration); + const assetId = this.testnet ? 'ETH_TEST6' : 'ETH'; + const fbNote = note ? note : 'ETH tx from @kilnfi/sdk'; + const fbTx = await fbSigner.signWithFB( + payload, + assetId, + fbNote, + ); + const { data } = await api.post( + `/v1/eth/transaction/prepare`, + { + unsigned_tx_serialized: tx.data.unsigned_tx_serialized, + r: `0x${fbTx?.signedMessages?.[0].signature.r}`, + s: `0x${fbTx?.signedMessages?.[0].signature.s}`, + v: fbTx?.signedMessages?.[0].signature.v ?? 0, + }); + data.data.fireblocks_tx = fbTx; + return data; + } /** @@ -119,25 +113,23 @@ export class EthService extends Service { if(!integration.fireblocksDestinationId) { throw new Error('Fireblocks destination id is missing in integration'); } - try { - const payload = { - contractCallData: tx.data.contract_call_data, - }; - - const fbSigner = this.getFbSigner(integration); - const assetId = this.testnet ? 'ETH_TEST6' : 'ETH'; - const fbNote = note ? note : 'ETH tx from @kilnfi/sdk'; - return await fbSigner.signAndBroadcastWithFB( - payload, - assetId, - tx, - integration.fireblocksDestinationId, - true, - fbNote, - ); - } catch (err: any) { - throw new Error(err); - } + + const payload = { + contractCallData: tx.data.contract_call_data, + }; + + const fbSigner = this.getFbSigner(integration); + const assetId = this.testnet ? 'ETH_TEST6' : 'ETH'; + const fbNote = note ? note : 'ETH tx from @kilnfi/sdk'; + return await fbSigner.signAndBroadcastWithFB( + payload, + assetId, + tx, + integration.fireblocksDestinationId, + true, + fbNote, + ); + } /** @@ -145,16 +137,14 @@ export class EthService extends Service { * @param signedTx */ async broadcast(signedTx: EthSignedTx): Promise { - try { - const { data } = await api.post( - `/v1/eth/transaction/broadcast`, - { - tx_serialized: signedTx.data.signed_tx_serialized, - }); - return data; - } catch (err: any) { - throw new Error(err); - } + + const { data } = await api.post( + `/v1/eth/transaction/broadcast`, + { + tx_serialized: signedTx.data.signed_tx_serialized, + }); + return data; + } /** @@ -162,13 +152,11 @@ export class EthService extends Service { * @param txHash transaction hash */ async getTxStatus(txHash: string): Promise { - try { - const { data } = await api.get( - `/v1/eth/transaction/status?tx_hash=${txHash}`); - return data; - } catch (err: any) { - throw new Error(err); - } + + const { data } = await api.get( + `/v1/eth/transaction/status?tx_hash=${txHash}`); + return data; + } /** @@ -176,13 +164,11 @@ export class EthService extends Service { * @param txSerialized transaction serialized */ async decodeTx(txSerialized: string): Promise { - try { - const { data } = await api.get( - `/v1/eth/transaction/decode?tx_serialized=${txSerialized}`); - return data; - } catch (error: any) { - throw new Error(error); - } + + const { data } = await api.get( + `/v1/eth/transaction/decode?tx_serialized=${txSerialized}`); + return data; + } /** @@ -193,13 +179,11 @@ export class EthService extends Service { async getStakesByAccounts( accountIds: string[], ): Promise { - try { - const { data } = await api.get( - `/v1/eth/stakes?accounts=${accountIds.join(',')}`); - return data; - } catch (err: any) { - throw new Error(err); - } + + const { data } = await api.get( + `/v1/eth/stakes?accounts=${accountIds.join(',')}`); + return data; + } /** @@ -210,14 +194,12 @@ export class EthService extends Service { async getStakesByWallets( walletAddresses: string[], ): Promise { - try { - const { data } = await api.get( - `/v1/eth/stakes?wallets=${walletAddresses.join(',')}`, - ); - return data; - } catch (err: any) { - throw new Error(err); - } + + const { data } = await api.get( + `/v1/eth/stakes?wallets=${walletAddresses.join(',')}`, + ); + return data; + } /** @@ -226,14 +208,12 @@ export class EthService extends Service { * @returns {EthStakes} Ethereum Stakes */ async getStakesByValidators(validatorAddresses: string[]): Promise { - try { - const { data } = await api.get( - `/v1/eth/stakes?validators=${validatorAddresses.join(',')}`, - ); - return data; - } catch (err: any) { - throw new Error(err); - } + + const { data } = await api.get( + `/v1/eth/stakes?validators=${validatorAddresses.join(',')}`, + ); + return data; + } /** @@ -248,15 +228,13 @@ export class EthService extends Service { startDate?: string, endDate?: string, ): Promise { - try { - const query = `/v1/eth/rewards?accounts=${accountIds.join(',')}${ - startDate ? `&start_date=${startDate}` : '' - }${endDate ? `&end_date=${endDate}` : ''}`; - const { data } = await api.get(query); - return data; - } catch (err: any) { - throw new Error(err); - } + + const query = `/v1/eth/rewards?accounts=${accountIds.join(',')}${ + startDate ? `&start_date=${startDate}` : '' + }${endDate ? `&end_date=${endDate}` : ''}`; + const { data } = await api.get(query); + return data; + } /** @@ -271,15 +249,13 @@ export class EthService extends Service { startDate?: string, endDate?: string, ): Promise { - try { - const query = `/v1/eth/rewards?wallets=${walletAddresses.join(',')}${ - startDate ? `&start_date=${startDate}` : '' - }${endDate ? `&end_date=${endDate}` : ''}`; - const { data } = await api.get(query); - return data; - } catch (err: any) { - throw new Error(err); - } + + const query = `/v1/eth/rewards?wallets=${walletAddresses.join(',')}${ + startDate ? `&start_date=${startDate}` : '' + }${endDate ? `&end_date=${endDate}` : ''}`; + const { data } = await api.get(query); + return data; + } /** @@ -294,43 +270,37 @@ export class EthService extends Service { startDate?: string, endDate?: string, ): Promise { - try { - const query = `/v1/eth/rewards?validators=${validatorAddresses.join(',')}${ - startDate ? `&start_date=${startDate}` : '' - }${endDate ? `&end_date=${endDate}` : ''}`; - const { data } = await api.get(query); - return data; - } catch (err: any) { - throw new Error(err); - } + + const query = `/v1/eth/rewards?validators=${validatorAddresses.join(',')}${ + startDate ? `&start_date=${startDate}` : '' + }${endDate ? `&end_date=${endDate}` : ''}`; + const { data } = await api.get(query); + return data; + } /** * Retrieve ETH network stats */ async getNetworkStats(): Promise { - try { - const { data } = await api.get( - `/v1/eth/network-stats`, - ); - return data; - } catch (err: any) { - throw new Error(err); - } + + const { data } = await api.get( + `/v1/eth/network-stats`, + ); + return data; + } /** * Retrieve ETH kiln stats */ async getKilnStats(): Promise { - try { - const { data } = await api.get( - `/v1/eth/kiln-stats`, - ); - return data; - } catch (err: any) { - throw new Error(err); - } + + const { data } = await api.get( + `/v1/eth/kiln-stats`, + ); + return data; + } /** diff --git a/src/services/matic.ts b/src/services/matic.ts index eacdddc..8be6c9d 100644 --- a/src/services/matic.ts +++ b/src/services/matic.ts @@ -29,18 +29,16 @@ export class MaticService extends Service { contractAddressToApprove: string, amountMatic?: number, ): Promise { - try { - const { data } = await api.post( - `/v1/matic/transaction/approve`, - { - wallet: walletAddress, - contract: contractAddressToApprove, - amount_wei: amountMatic ? this.maticToWei(amountMatic?.toString()) : undefined, - }); - return data; - } catch (err: any) { - throw new Error(err); - } + + const { data } = await api.post( + `/v1/matic/transaction/approve`, + { + wallet: walletAddress, + contract: contractAddressToApprove, + amount_wei: amountMatic ? this.maticToWei(amountMatic?.toString()) : undefined, + }); + return data; + } /** @@ -57,19 +55,17 @@ export class MaticService extends Service { validatorShareProxyAddress: string, amountMatic: number, ): Promise { - try { - const { data } = await api.post( - `/v1/matic/transaction/buy-voucher`, - { - account_id: accountId, - wallet: walletAddress, - amount_wei: this.maticToWei(amountMatic.toString()), - validator_share_proxy_address: validatorShareProxyAddress, - }); - return data; - } catch (err: any) { - throw new Error(err); - } + + const { data } = await api.post( + `/v1/matic/transaction/buy-voucher`, + { + account_id: accountId, + wallet: walletAddress, + amount_wei: this.maticToWei(amountMatic.toString()), + validator_share_proxy_address: validatorShareProxyAddress, + }); + return data; + } /** @@ -84,18 +80,16 @@ export class MaticService extends Service { validatorShareProxyAddress: string, amountMatic: number, ): Promise { - try { - const { data } = await api.post( - `/v1/matic/transaction/sell-voucher`, - { - wallet: walletAddress, - amount_wei: this.maticToWei(amountMatic.toString()), - validator_share_proxy_address: validatorShareProxyAddress, - }); - return data; - } catch (err: any) { - throw new Error(err); - } + + const { data } = await api.post( + `/v1/matic/transaction/sell-voucher`, + { + wallet: walletAddress, + amount_wei: this.maticToWei(amountMatic.toString()), + validator_share_proxy_address: validatorShareProxyAddress, + }); + return data; + } /** @@ -108,17 +102,15 @@ export class MaticService extends Service { walletAddress: string, validatorShareProxyAddress: string, ): Promise { - try { - const { data } = await api.post( - `/v1/matic/transaction/unstake-claim-tokens`, - { - wallet: walletAddress, - validator_share_proxy_address: validatorShareProxyAddress, - }); - return data; - } catch (err: any) { - throw new Error(err); - } + + const { data } = await api.post( + `/v1/matic/transaction/unstake-claim-tokens`, + { + wallet: walletAddress, + validator_share_proxy_address: validatorShareProxyAddress, + }); + return data; + } /** @@ -131,17 +123,15 @@ export class MaticService extends Service { walletAddress: string, validatorShareProxyAddress: string, ): Promise { - try { - const { data } = await api.post( - `/v1/matic/transaction/withdraw-rewards`, - { - wallet: walletAddress, - validator_share_proxy_address: validatorShareProxyAddress, - }); - return data; - } catch (err: any) { - throw new Error(err); - } + + const { data } = await api.post( + `/v1/matic/transaction/withdraw-rewards`, + { + wallet: walletAddress, + validator_share_proxy_address: validatorShareProxyAddress, + }); + return data; + } /** @@ -154,17 +144,15 @@ export class MaticService extends Service { walletAddress: string, validatorShareProxyAddress: string, ): Promise { - try { - const { data } = await api.post( - `/v1/matic/transaction/restake-rewards`, - { - wallet: walletAddress, - validator_share_proxy_address: validatorShareProxyAddress, - }); - return data; - } catch (err: any) { - throw new Error(err); - } + + const { data } = await api.post( + `/v1/matic/transaction/restake-rewards`, + { + wallet: walletAddress, + validator_share_proxy_address: validatorShareProxyAddress, + }); + return data; + } /** @@ -174,33 +162,31 @@ export class MaticService extends Service { * @param note note to identify the transaction in your custody solution */ async sign(integration: Integration, tx: MaticTx, note?: string): Promise { - try { - const payload = { - rawMessageData: { - messages: [ - { - 'content': tx.data.unsigned_tx_hash, - }, - ], - }, - }; - const fbSigner = this.getFbSigner(integration); - const fbNote = note ? note : 'MATIC tx from @kilnfi/sdk'; - const fbTx = await fbSigner.signWithFB(payload, this.testnet ? 'ETH_TEST3' : 'ETH', fbNote); - const { data } = await api.post( - `/v1/matic/transaction/prepare`, - { - unsigned_tx_serialized: tx.data.unsigned_tx_serialized, - r: `0x${fbTx?.signedMessages?.[0].signature.r}`, - s: `0x${fbTx?.signedMessages?.[0].signature.s}`, - v: fbTx?.signedMessages?.[0].signature.v ?? 0, - }); - data.data.fireblocks_tx = fbTx; - return data; - } catch (err: any) { - throw new Error(err); - } + const payload = { + rawMessageData: { + messages: [ + { + 'content': tx.data.unsigned_tx_hash, + }, + ], + }, + }; + + const fbSigner = this.getFbSigner(integration); + const fbNote = note ? note : 'MATIC tx from @kilnfi/sdk'; + const fbTx = await fbSigner.signWithFB(payload, this.testnet ? 'ETH_TEST3' : 'ETH', fbNote); + const { data } = await api.post( + `/v1/matic/transaction/prepare`, + { + unsigned_tx_serialized: tx.data.unsigned_tx_serialized, + r: `0x${fbTx?.signedMessages?.[0].signature.r}`, + s: `0x${fbTx?.signedMessages?.[0].signature.s}`, + v: fbTx?.signedMessages?.[0].signature.v ?? 0, + }); + data.data.fireblocks_tx = fbTx; + return data; + } /** @@ -213,25 +199,23 @@ export class MaticService extends Service { if(!integration.fireblocksDestinationId) { throw new Error('Fireblocks destination id is missing in integration'); } - try { - const payload = { - contractCallData: tx.data.contract_call_data, - }; - const fbSigner = this.getFbSigner(integration); - const fbNote = note ? note : 'MATIC tx from @kilnfi/sdk'; - const assetId = this.testnet ? 'ETH_TEST3' : 'ETH'; - return await fbSigner.signAndBroadcastWithFB( - payload, - assetId, - tx, - integration.fireblocksDestinationId, - false, - fbNote, - ); - } catch (err: any) { - throw new Error(err); - } + const payload = { + contractCallData: tx.data.contract_call_data, + }; + + const fbSigner = this.getFbSigner(integration); + const fbNote = note ? note : 'MATIC tx from @kilnfi/sdk'; + const assetId = this.testnet ? 'ETH_TEST3' : 'ETH'; + return await fbSigner.signAndBroadcastWithFB( + payload, + assetId, + tx, + integration.fireblocksDestinationId, + false, + fbNote, + ); + } @@ -240,16 +224,14 @@ export class MaticService extends Service { * @param signedTx */ async broadcast(signedTx: MaticSignedTx): Promise { - try { - const { data } = await api.post( - `/v1/matic/transaction/broadcast`, - { - tx_serialized: signedTx.data.signed_tx_serialized, - }); - return data; - } catch (err: any) { - throw new Error(err); - } + + const { data } = await api.post( + `/v1/matic/transaction/broadcast`, + { + tx_serialized: signedTx.data.signed_tx_serialized, + }); + return data; + } /** @@ -257,13 +239,11 @@ export class MaticService extends Service { * @param txHash transaction hash */ async getTxStatus(txHash: string): Promise { - try { - const { data } = await api.get( - `/v1/matic/transaction/status?tx_hash=${txHash}`); - return data; - } catch (err: any) { - throw new Error(err); - } + + const { data } = await api.get( + `/v1/matic/transaction/status?tx_hash=${txHash}`); + return data; + } /** @@ -271,13 +251,11 @@ export class MaticService extends Service { * @param txSerialized transaction serialized */ async decodeTx(txSerialized: string): Promise { - try { - const { data } = await api.get( - `/v1/matic/transaction/decode?tx_serialized=${txSerialized}`); - return data; - } catch (error: any) { - throw new Error(error); - } + + const { data } = await api.get( + `/v1/matic/transaction/decode?tx_serialized=${txSerialized}`); + return data; + } /** diff --git a/src/services/near.ts b/src/services/near.ts index 8cc4b29..ca772c2 100644 --- a/src/services/near.ts +++ b/src/services/near.ts @@ -264,17 +264,15 @@ export class NearService extends Service { * @param signedTx */ async broadcast(signedTx: NearSignedTx): Promise { - try { - const connection = await this.getConnection(); - const res = await connection.connection.provider.sendTransaction(signedTx.data.tx); - return { - data: { - tx_hash: res.transaction.hash, - }, - }; - } catch (e: any) { - throw new Error(e); - } + + const connection = await this.getConnection(); + const res = await connection.connection.provider.sendTransaction(signedTx.data.tx); + return { + data: { + tx_hash: res.transaction.hash, + }, + }; + } /** @@ -283,19 +281,17 @@ export class NearService extends Service { * @param poolId pool id */ async getTxStatus(transactionHash: string, poolId: string): Promise { - try { - const connection = await this.getConnection(); - const receipt = await connection.connection.provider.txStatusReceipts(transactionHash, poolId); - const status = Object.keys(receipt.status).includes('SuccessValue') ? 'success' : 'error'; - return { - data: { - status: status, - receipt: receipt, - }, - }; - } catch (e: any) { - throw new Error(e); - } + + const connection = await this.getConnection(); + const receipt = await connection.connection.provider.txStatusReceipts(transactionHash, poolId); + const status = Object.keys(receipt.status).includes('SuccessValue') ? 'success' : 'error'; + return { + data: { + status: status, + receipt: receipt, + }, + }; + } /** @@ -303,13 +299,11 @@ export class NearService extends Service { * @param txSerialized transaction serialized */ async decodeTx(txSerialized: string): Promise { - try { - const { data } = await api.get( - `/v1/near/transaction/decode?tx_serialized=${txSerialized}`); - return data; - } catch (error: any) { - throw new Error(error); - } + + const { data } = await api.get( + `/v1/near/transaction/decode?tx_serialized=${txSerialized}`); + return data; + } /** @@ -320,13 +314,11 @@ export class NearService extends Service { async getStakesByAccounts( accountIds: string[], ): Promise { - try { - const { data } = await api.get( - `/v1/near/stakes?accounts=${accountIds.join(',')}`); - return data; - } catch (err: any) { - throw new Error(err); - } + + const { data } = await api.get( + `/v1/near/stakes?accounts=${accountIds.join(',')}`); + return data; + } /** @@ -337,13 +329,11 @@ export class NearService extends Service { async getStakesByStakeAccounts( stakeAccounts: string[], ): Promise { - try { - const { data } = await api.get( - `/v1/near/stakes?stake_accounts=${stakeAccounts.join(',')}`); - return data; - } catch (err: any) { - throw new Error(err); - } + + const { data } = await api.get( + `/v1/near/stakes?stake_accounts=${stakeAccounts.join(',')}`); + return data; + } /** @@ -354,13 +344,11 @@ export class NearService extends Service { async getStakesByWallets( wallets: string[], ): Promise { - try { - const { data } = await api.get( - `/v1/near/stakes?wallets=${wallets.join(',')}`); - return data; - } catch (err: any) { - throw new Error(err); - } + + const { data } = await api.get( + `/v1/near/stakes?wallets=${wallets.join(',')}`); + return data; + } /** @@ -375,15 +363,13 @@ export class NearService extends Service { startDate?: string, endDate?: string, ): Promise { - try { - const { data } = await api.get( - `/v1/near/rewards?accounts=${accountIds.join(',')}${ - startDate ? `&start_date=${startDate}` : '' - }${endDate ? `&end_date=${endDate}` : ''}`); - return data; - } catch (err: any) { - throw new Error(err); - } + + const { data } = await api.get( + `/v1/near/rewards?accounts=${accountIds.join(',')}${ + startDate ? `&start_date=${startDate}` : '' + }${endDate ? `&end_date=${endDate}` : ''}`); + return data; + } /** @@ -398,15 +384,13 @@ export class NearService extends Service { startDate?: string, endDate?: string, ): Promise { - try { - const { data } = await api.get( - `/v1/near/rewards?stake_accounts=${stakeAccounts.join(',')}${ - startDate ? `&start_date=${startDate}` : '' - }${endDate ? `&end_date=${endDate}` : ''}`); - return data; - } catch (err: any) { - throw new Error(err); - } + + const { data } = await api.get( + `/v1/near/rewards?stake_accounts=${stakeAccounts.join(',')}${ + startDate ? `&start_date=${startDate}` : '' + }${endDate ? `&end_date=${endDate}` : ''}`); + return data; + } /** @@ -421,28 +405,24 @@ export class NearService extends Service { startDate?: string, endDate?: string, ): Promise { - try { - const { data } = await api.get( - `/v1/near/rewards?wallets=${wallets.join(',')}${ - startDate ? `&start_date=${startDate}` : '' - }${endDate ? `&end_date=${endDate}` : ''}`); - return data; - } catch (err: any) { - throw new Error(err); - } + + const { data } = await api.get( + `/v1/near/rewards?wallets=${wallets.join(',')}${ + startDate ? `&start_date=${startDate}` : '' + }${endDate ? `&end_date=${endDate}` : ''}`); + return data; + } /** * Retrieve NEAR network stats */ async getNetworkStats(): Promise { - try { - const { data } = await api.get( - `/v1/near/network-stats`, - ); - return data; - } catch (err: any) { - throw new Error(err); - } + + const { data } = await api.get( + `/v1/near/network-stats`, + ); + return data; + } } diff --git a/src/services/osmo.ts b/src/services/osmo.ts index 0a6bd96..00ae1ba 100644 --- a/src/services/osmo.ts +++ b/src/services/osmo.ts @@ -37,19 +37,17 @@ export class OsmoService extends Service { validatorAddress: string, amountOsmo: number, ): Promise { - try { - const { data } = await api.post( - `/v1/osmo/transaction/stake`, - { - account_id: accountId, - pubkey: pubkey, - validator: validatorAddress, - amount_uosmo: this.osmoToUosmo(amountOsmo.toString()), - }); - return data; - } catch (err: any) { - throw new Error(err); - } + + const { data } = await api.post( + `/v1/osmo/transaction/stake`, + { + account_id: accountId, + pubkey: pubkey, + validator: validatorAddress, + amount_uosmo: this.osmoToUosmo(amountOsmo.toString()), + }); + return data; + } /** @@ -61,17 +59,15 @@ export class OsmoService extends Service { pubkey: string, validatorAddress: string, ): Promise { - try { - const { data } = await api.post( - `/v1/osmo/transaction/withdraw-rewards`, - { - pubkey: pubkey, - validator: validatorAddress, - }); - return data; - } catch (err: any) { - throw new Error(err); - } + + const { data } = await api.post( + `/v1/osmo/transaction/withdraw-rewards`, + { + pubkey: pubkey, + validator: validatorAddress, + }); + return data; + } /** @@ -85,18 +81,16 @@ export class OsmoService extends Service { validatorAddress: string, amountOsmo?: number, ): Promise { - try { - const { data } = await api.post( - `/v1/osmo/transaction/unstake`, - { - pubkey: pubkey, - validator: validatorAddress, - amount_uosmo: amountOsmo ? this.osmoToUosmo(amountOsmo.toString()) : undefined, - }); - return data; - } catch (err: any) { - throw new Error(err); - } + + const { data } = await api.post( + `/v1/osmo/transaction/unstake`, + { + pubkey: pubkey, + validator: validatorAddress, + amount_uosmo: amountOsmo ? this.osmoToUosmo(amountOsmo.toString()) : undefined, + }); + return data; + } /** @@ -114,20 +108,18 @@ export class OsmoService extends Service { validatorDestinationAddress: string, amountOsmo?: number, ): Promise { - try { - const { data } = await api.post( - `/v1/osmo/transaction/redelegate`, - { - account_id: accountId, - pubkey: pubkey, - validator_source: validatorSourceAddress, - validator_destination: validatorDestinationAddress, - amount_uosmo: amountOsmo ? this.osmoToUosmo(amountOsmo.toString()) : undefined, - }); - return data; - } catch (err: any) { - throw new Error(err); - } + + const { data } = await api.post( + `/v1/osmo/transaction/redelegate`, + { + account_id: accountId, + pubkey: pubkey, + validator_source: validatorSourceAddress, + validator_destination: validatorDestinationAddress, + amount_uosmo: amountOsmo ? this.osmoToUosmo(amountOsmo.toString()) : undefined, + }); + return data; + } /** @@ -168,16 +160,14 @@ export class OsmoService extends Service { * @param signedTx */ async broadcast(signedTx: CosmosSignedTx): Promise { - try { - const { data } = await api.post( - `/v1/osmo/transaction/broadcast`, - { - tx_serialized: signedTx.data.signed_tx_serialized, - }); - return data; - } catch (e: any) { - throw new Error(e); - } + + const { data } = await api.post( + `/v1/osmo/transaction/broadcast`, + { + tx_serialized: signedTx.data.signed_tx_serialized, + }); + return data; + } /** @@ -185,13 +175,11 @@ export class OsmoService extends Service { * @param txHash */ async getTxStatus(txHash: string): Promise { - try { - const { data } = await api.get( - `/v1/osmo/transaction/status?tx_hash=${txHash}`); - return data; - } catch (e: any) { - throw new Error(e); - } + + const { data } = await api.get( + `/v1/osmo/transaction/status?tx_hash=${txHash}`); + return data; + } /** @@ -199,13 +187,11 @@ export class OsmoService extends Service { * @param txSerialized transaction serialized */ async decodeTx(txSerialized: string): Promise { - try { - const { data } = await api.get( - `/v1/osmo/transaction/decode?tx_serialized=${txSerialized}`); - return data; - } catch (error: any) { - throw new Error(error); - } + + const { data } = await api.get( + `/v1/osmo/transaction/decode?tx_serialized=${txSerialized}`); + return data; + } /** @@ -216,13 +202,11 @@ export class OsmoService extends Service { async getStakesByAccounts( accountIds: string[], ): Promise { - try { - const { data } = await api.get( - `/v1/osmo/stakes?accounts=${accountIds.join(',')}`); - return data; - } catch (err: any) { - throw new Error(err); - } + + const { data } = await api.get( + `/v1/osmo/stakes?accounts=${accountIds.join(',')}`); + return data; + } /** @@ -235,13 +219,11 @@ export class OsmoService extends Service { delegators: string[], validators: string[], ): Promise { - try { - const { data } = await api.get( - `/v1/osmo/stakes?delegators=${delegators.join(',')}&validators=${validators.join(',')}`); - return data; - } catch (err: any) { - throw new Error(err); - } + + const { data } = await api.get( + `/v1/osmo/stakes?delegators=${delegators.join(',')}&validators=${validators.join(',')}`); + return data; + } /** @@ -256,15 +238,13 @@ export class OsmoService extends Service { startDate?: string, endDate?: string, ): Promise { - try { - const query = `/v1/osmo/rewards?accounts=${accountIds.join(',')}${ - startDate ? `&start_date=${startDate}` : '' - }${endDate ? `&end_date=${endDate}` : ''}`; - const { data } = await api.get(query); - return data; - } catch (err: any) { - throw new Error(err); - } + + const query = `/v1/osmo/rewards?accounts=${accountIds.join(',')}${ + startDate ? `&start_date=${startDate}` : '' + }${endDate ? `&end_date=${endDate}` : ''}`; + const { data } = await api.get(query); + return data; + } /** @@ -281,14 +261,12 @@ export class OsmoService extends Service { startDate?: string, endDate?: string, ): Promise { - try { - const query = `/v1/osmo/rewards?delegators=${delegators.join(',')}&validators=${validators.join(',')}${ - startDate ? `&start_date=${startDate}` : '' - }${endDate ? `&end_date=${endDate}` : ''}`; - const { data } = await api.get(query); - return data; - } catch (err: any) { - throw new Error(err); - } + + const query = `/v1/osmo/rewards?delegators=${delegators.join(',')}&validators=${validators.join(',')}${ + startDate ? `&start_date=${startDate}` : '' + }${endDate ? `&end_date=${endDate}` : ''}`; + const { data } = await api.get(query); + return data; + } } diff --git a/src/services/sol.ts b/src/services/sol.ts index 640e1ec..7920048 100644 --- a/src/services/sol.ts +++ b/src/services/sol.ts @@ -34,20 +34,18 @@ export class SolService extends Service { amountSol: number, memo?: string, ): Promise { - try { - const { data } = await api.post( - `/v1/sol/transaction/stake`, - { - account_id: accountId, - wallet: walletAddress, - amount_lamports: this.solToLamports(amountSol.toString()), - vote_account_address: voteAccountAddress, - memo, - }); - return data; - } catch (err: any) { - throw new Error(err); - } + + const { data } = await api.post( + `/v1/sol/transaction/stake`, + { + account_id: accountId, + wallet: walletAddress, + amount_lamports: this.solToLamports(amountSol.toString()), + vote_account_address: voteAccountAddress, + memo, + }); + return data; + } /** @@ -59,17 +57,15 @@ export class SolService extends Service { stakeAccountAddress: string, walletAddress: string, ): Promise { - try { - const { data } = await api.post( - `/v1/sol/transaction/deactivate-stake`, - { - stake_account: stakeAccountAddress, - wallet: walletAddress, - }); - return data; - } catch (err: any) { - throw new Error(err); - } + + const { data } = await api.post( + `/v1/sol/transaction/deactivate-stake`, + { + stake_account: stakeAccountAddress, + wallet: walletAddress, + }); + return data; + } /** @@ -83,18 +79,16 @@ export class SolService extends Service { walletAddress: string, amountSol?: number, ): Promise { - try { - const { data } = await api.post( - `/v1/sol/transaction/withdraw-stake`, - { - stake_account: stakeAccountAddress, - wallet: walletAddress, - amount_lamports: amountSol ? this.solToLamports(amountSol.toString()) : undefined, - }); - return data; - } catch (err: any) { - throw new Error(err); - } + + const { data } = await api.post( + `/v1/sol/transaction/withdraw-stake`, + { + stake_account: stakeAccountAddress, + wallet: walletAddress, + amount_lamports: amountSol ? this.solToLamports(amountSol.toString()) : undefined, + }); + return data; + } /** @@ -109,18 +103,16 @@ export class SolService extends Service { stakeAccountDestinationAddress: string, walletAddress: string, ): Promise { - try { - const { data } = await api.post( - `/v1/sol/transaction/merge-stakes`, - { - stake_account_source: stakeAccountSourceAddress, - stake_account_destination: stakeAccountDestinationAddress, - wallet: walletAddress, - }); - return data; - } catch (err: any) { - throw new Error(err); - } + + const { data } = await api.post( + `/v1/sol/transaction/merge-stakes`, + { + stake_account_source: stakeAccountSourceAddress, + stake_account_destination: stakeAccountDestinationAddress, + wallet: walletAddress, + }); + return data; + } /** @@ -136,19 +128,17 @@ export class SolService extends Service { walletAddress: string, amountSol: number, ): Promise { - try { - const { data } = await api.post( - `/v1/sol/transaction/split-stake`, - { - account_id: accountId, - stake_account: stakeAccountAddress, - wallet: walletAddress, - amount_lamports: this.solToLamports(amountSol.toString()), - }); - return data; - } catch (err: any) { - throw new Error(err); - } + + const { data } = await api.post( + `/v1/sol/transaction/split-stake`, + { + account_id: accountId, + stake_account: stakeAccountAddress, + wallet: walletAddress, + amount_lamports: this.solToLamports(amountSol.toString()), + }); + return data; + } /** @@ -158,38 +148,36 @@ export class SolService extends Service { * @param note note to identify the transaction in your custody solution */ async sign(integration: Integration, tx: SolTx, note?: string): Promise { - try { - const payload = { - rawMessageData: { - messages: [ - { - 'content': tx.data.unsigned_tx_hash, - }, - ], - }, - }; - - const fbSigner = this.getFbSigner(integration); - const fbNote = note ? note : 'SOL tx from @kilnfi/sdk'; - const fbTx = await fbSigner.signWithFB(payload, this.testnet ? 'SOL_TEST' : 'SOL', fbNote); - const signatures: string[] = []; - fbTx.signedMessages?.forEach((signedMessage: any) => { - if (signedMessage.derivationPath[3] == 0) { - signatures.push(signedMessage.signature.fullSig); - } - }); - const { data } = await api.post( - `/v1/sol/transaction/prepare`, - { - unsigned_tx_serialized: tx.data.unsigned_tx_serialized, - signatures: signatures, - }); - data.data.fireblocks_tx = fbTx; - return data; - } catch (err: any) { - throw new Error(err); - } + const payload = { + rawMessageData: { + messages: [ + { + 'content': tx.data.unsigned_tx_hash, + }, + ], + }, + }; + + const fbSigner = this.getFbSigner(integration); + const fbNote = note ? note : 'SOL tx from @kilnfi/sdk'; + const fbTx = await fbSigner.signWithFB(payload, this.testnet ? 'SOL_TEST' : 'SOL', fbNote); + const signatures: string[] = []; + fbTx.signedMessages?.forEach((signedMessage: any) => { + if (signedMessage.derivationPath[3] == 0) { + signatures.push(signedMessage.signature.fullSig); + } + }); + + const { data } = await api.post( + `/v1/sol/transaction/prepare`, + { + unsigned_tx_serialized: tx.data.unsigned_tx_serialized, + signatures: signatures, + }); + data.data.fireblocks_tx = fbTx; + return data; + } @@ -198,16 +186,14 @@ export class SolService extends Service { * @param signedTx serialized signed tx */ async broadcast(signedTx: SolSignedTx): Promise { - try { - const { data } = await api.post( - `/v1/sol/transaction/broadcast`, - { - tx_serialized: signedTx.data.signed_tx_serialized, - }); - return data; - } catch (err: any) { - throw new Error(err); - } + + const { data } = await api.post( + `/v1/sol/transaction/broadcast`, + { + tx_serialized: signedTx.data.signed_tx_serialized, + }); + return data; + } /** @@ -215,13 +201,11 @@ export class SolService extends Service { * @param txHash transaction hash */ async getTxStatus(txHash: string): Promise { - try { - const { data } = await api.get( - `/v1/sol/transaction/status?tx_hash=${txHash}`); - return data; - } catch (e: any) { - throw new Error(e); - } + + const { data } = await api.get( + `/v1/sol/transaction/status?tx_hash=${txHash}`); + return data; + } /** @@ -229,13 +213,11 @@ export class SolService extends Service { * @param txSerialized transaction serialized */ async decodeTx(txSerialized: string): Promise { - try { - const { data } = await api.get( - `/v1/sol/transaction/decode?tx_serialized=${txSerialized}`); - return data; - } catch (error: any) { - throw new Error(error); - } + + const { data } = await api.get( + `/v1/sol/transaction/decode?tx_serialized=${txSerialized}`); + return data; + } /** @@ -246,13 +228,11 @@ export class SolService extends Service { async getStakesByAccounts( accountIds: string[], ): Promise { - try { - const { data } = await api.get( - `/v1/sol/stakes?accounts=${accountIds.join(',')}`); - return data; - } catch (err: any) { - throw new Error(err); - } + + const { data } = await api.get( + `/v1/sol/stakes?accounts=${accountIds.join(',')}`); + return data; + } /** @@ -263,13 +243,11 @@ export class SolService extends Service { async getStakesByStakeAccounts( stakeAccounts: string[], ): Promise { - try { - const { data } = await api.get( - `/v1/sol/stakes?stake_accounts=${stakeAccounts.join(',')}`); - return data; - } catch (err: any) { - throw new Error(err); - } + + const { data } = await api.get( + `/v1/sol/stakes?stake_accounts=${stakeAccounts.join(',')}`); + return data; + } /** @@ -280,13 +258,11 @@ export class SolService extends Service { async getStakesByWallets( wallets: string[], ): Promise { - try { - const { data } = await api.get( - `/v1/sol/stakes?wallets=${wallets.join(',')}`); - return data; - } catch (err: any) { - throw new Error(err); - } + + const { data } = await api.get( + `/v1/sol/stakes?wallets=${wallets.join(',')}`); + return data; + } /** @@ -301,15 +277,13 @@ export class SolService extends Service { startDate?: string, endDate?: string, ): Promise { - try { - const query = `/v1/sol/rewards?accounts=${accountIds.join(',')}${ - startDate ? `&start_date=${startDate}` : '' - }${endDate ? `&end_date=${endDate}` : ''}`; - const { data } = await api.get(query); - return data; - } catch (err: any) { - throw new Error(err); - } + + const query = `/v1/sol/rewards?accounts=${accountIds.join(',')}${ + startDate ? `&start_date=${startDate}` : '' + }${endDate ? `&end_date=${endDate}` : ''}`; + const { data } = await api.get(query); + return data; + } /** @@ -324,15 +298,13 @@ export class SolService extends Service { startDate?: string, endDate?: string, ): Promise { - try { - const query = `/v1/sol/rewards?stake_accounts=${stakeAccounts.join(',')}${ - startDate ? `&start_date=${startDate}` : '' - }${endDate ? `&end_date=${endDate}` : ''}`; - const { data } = await api.get(query); - return data; - } catch (err: any) { - throw new Error(err); - } + + const query = `/v1/sol/rewards?stake_accounts=${stakeAccounts.join(',')}${ + startDate ? `&start_date=${startDate}` : '' + }${endDate ? `&end_date=${endDate}` : ''}`; + const { data } = await api.get(query); + return data; + } /** @@ -347,29 +319,25 @@ export class SolService extends Service { startDate?: string, endDate?: string, ): Promise { - try { - const query = `/v1/sol/rewards?wallets=${wallets.join(',')}${ - startDate ? `&start_date=${startDate}` : '' - }${endDate ? `&end_date=${endDate}` : ''}`; - const { data } = await api.get(query); - return data; - } catch (err: any) { - throw new Error(err); - } + + const query = `/v1/sol/rewards?wallets=${wallets.join(',')}${ + startDate ? `&start_date=${startDate}` : '' + }${endDate ? `&end_date=${endDate}` : ''}`; + const { data } = await api.get(query); + return data; + } /** * Retrieve SOL network stats */ async getNetworkStats(): Promise { - try { - const { data } = await api.get( - `/v1/sol/network-stats`, - ); - return data; - } catch (err: any) { - throw new Error(err); - } + + const { data } = await api.get( + `/v1/sol/network-stats`, + ); + return data; + } /** diff --git a/src/services/tia.ts b/src/services/tia.ts index 4a4c0d5..ad826e7 100644 --- a/src/services/tia.ts +++ b/src/services/tia.ts @@ -33,19 +33,17 @@ export class TiaService extends Service { validatorAddress: string, amountTia: number, ): Promise { - try { - const { data } = await api.post( - `/v1/tia/transaction/stake`, - { - account_id: accountId, - pubkey: pubkey, - validator: validatorAddress, - amount_utia: this.tiaToUtia(amountTia.toString()), - }); - return data; - } catch (err: any) { - throw new Error(err); - } + + const { data } = await api.post( + `/v1/tia/transaction/stake`, + { + account_id: accountId, + pubkey: pubkey, + validator: validatorAddress, + amount_utia: this.tiaToUtia(amountTia.toString()), + }); + return data; + } /** @@ -57,17 +55,15 @@ export class TiaService extends Service { pubkey: string, validatorAddress: string, ): Promise { - try { - const { data } = await api.post( - `/v1/tia/transaction/withdraw-rewards`, - { - pubkey: pubkey, - validator: validatorAddress, - }); - return data; - } catch (err: any) { - throw new Error(err); - } + + const { data } = await api.post( + `/v1/tia/transaction/withdraw-rewards`, + { + pubkey: pubkey, + validator: validatorAddress, + }); + return data; + } /** @@ -81,18 +77,16 @@ export class TiaService extends Service { validatorAddress: string, amountTia?: number, ): Promise { - try { - const { data } = await api.post( - `/v1/tia/transaction/unstake`, - { - pubkey: pubkey, - validator: validatorAddress, - amount_utia: amountTia ? this.tiaToUtia(amountTia.toString()) : undefined, - }); - return data; - } catch (err: any) { - throw new Error(err); - } + + const { data } = await api.post( + `/v1/tia/transaction/unstake`, + { + pubkey: pubkey, + validator: validatorAddress, + amount_utia: amountTia ? this.tiaToUtia(amountTia.toString()) : undefined, + }); + return data; + } /** @@ -110,20 +104,18 @@ export class TiaService extends Service { validatorDestinationAddress: string, amountTia?: number, ): Promise { - try { - const { data } = await api.post( - `/v1/tia/transaction/redelegate`, - { - account_id: accountId, - pubkey: pubkey, - validator_source: validatorSourceAddress, - validator_destination: validatorDestinationAddress, - amount_utia: amountTia ? this.tiaToUtia(amountTia.toString()) : undefined, - }); - return data; - } catch (err: any) { - throw new Error(err); - } + + const { data } = await api.post( + `/v1/tia/transaction/redelegate`, + { + account_id: accountId, + pubkey: pubkey, + validator_source: validatorSourceAddress, + validator_destination: validatorDestinationAddress, + amount_utia: amountTia ? this.tiaToUtia(amountTia.toString()) : undefined, + }); + return data; + } /** @@ -164,16 +156,14 @@ export class TiaService extends Service { * @param signedTx */ async broadcast(signedTx: CosmosSignedTx): Promise { - try { - const { data } = await api.post( - `/v1/tia/transaction/broadcast`, - { - tx_serialized: signedTx.data.signed_tx_serialized, - }); - return data; - } catch (e: any) { - throw new Error(e); - } + + const { data } = await api.post( + `/v1/tia/transaction/broadcast`, + { + tx_serialized: signedTx.data.signed_tx_serialized, + }); + return data; + } /** @@ -181,13 +171,11 @@ export class TiaService extends Service { * @param txHash */ async getTxStatus(txHash: string): Promise { - try { - const { data } = await api.get( - `/v1/tia/transaction/status?tx_hash=${txHash}`); - return data; - } catch (e: any) { - throw new Error(e); - } + + const { data } = await api.get( + `/v1/tia/transaction/status?tx_hash=${txHash}`); + return data; + } /** @@ -195,12 +183,10 @@ export class TiaService extends Service { * @param txSerialized transaction serialized */ async decodeTx(txSerialized: string): Promise { - try { - const { data } = await api.get( - `/v1/tia/transaction/decode?tx_serialized=${txSerialized}`); - return data; - } catch (error: any) { - throw new Error(error); - } + + const { data } = await api.get( + `/v1/tia/transaction/decode?tx_serialized=${txSerialized}`); + return data; + } } diff --git a/src/services/xtz.ts b/src/services/xtz.ts index 0d37022..5d3393c 100644 --- a/src/services/xtz.ts +++ b/src/services/xtz.ts @@ -29,18 +29,16 @@ export class XtzService extends Service { walletAddress: string, bakerAddress: string, ): Promise { - try { - const { data } = await api.post( - `/v1/xtz/transaction/stake`, - { - account_id: accountId, - wallet: walletAddress, - baker_address: bakerAddress, - }); - return data; - } catch (err: any) { - throw new Error(err); - } + + const { data } = await api.post( + `/v1/xtz/transaction/stake`, + { + account_id: accountId, + wallet: walletAddress, + baker_address: bakerAddress, + }); + return data; + } /** @@ -50,16 +48,14 @@ export class XtzService extends Service { async craftUnStakeTx( walletAddress: string, ): Promise { - try { - const { data } = await api.post( - `/v1/xtz/transaction/unstake`, - { - wallet: walletAddress, - }); - return data; - } catch (err: any) { - throw new Error(err); - } + + const { data } = await api.post( + `/v1/xtz/transaction/unstake`, + { + wallet: walletAddress, + }); + return data; + } /** @@ -99,16 +95,14 @@ export class XtzService extends Service { * @param signedTx serialized signed tx */ async broadcast(signedTx: XtzSignedTx): Promise { - try { - const { data } = await api.post( - `/v1/xtz/transaction/broadcast`, - { - tx_serialized: signedTx.data.signed_tx_serialized, - }); - return data; - } catch (e: any) { - throw new Error(e); - } + + const { data } = await api.post( + `/v1/xtz/transaction/broadcast`, + { + tx_serialized: signedTx.data.signed_tx_serialized, + }); + return data; + } /** @@ -117,13 +111,11 @@ export class XtzService extends Service { * @param txHash transaction hash */ async getTxStatus(blockNumber: number, txHash: string): Promise { - try { - const { data } = await api.get( - `/v1/xtz/transaction/status?block_number=${blockNumber}&tx_hash=${txHash}`); - return data; - } catch (e: any) { - throw new Error(e); - } + + const { data } = await api.get( + `/v1/xtz/transaction/status?block_number=${blockNumber}&tx_hash=${txHash}`); + return data; + } /** @@ -131,13 +123,11 @@ export class XtzService extends Service { * @param txSerialized transaction serialized */ async decodeTx(txSerialized: string): Promise { - try { - const { data } = await api.get( - `/v1/xtz/transaction/decode?tx_serialized=${txSerialized}`); - return data; - } catch (error: any) { - throw new Error(error); - } + + const { data } = await api.get( + `/v1/xtz/transaction/decode?tx_serialized=${txSerialized}`); + return data; + } /** @@ -148,13 +138,11 @@ export class XtzService extends Service { async getStakesByAccounts( accountIds: string[], ): Promise { - try { - const { data } = await api.get( - `/v1/xtz/stakes?accounts=${accountIds.join(',')}`); - return data; - } catch (err: any) { - throw new Error(err); - } + + const { data } = await api.get( + `/v1/xtz/stakes?accounts=${accountIds.join(',')}`); + return data; + } /** @@ -165,14 +153,12 @@ export class XtzService extends Service { async getStakesByWallets( walletAddresses: string[], ): Promise { - try { - const { data } = await api.get( - `/v1/xtz/stakes?wallets=${walletAddresses.join(',')}`, - ); - return data; - } catch (err: any) { - throw new Error(err); - } + + const { data } = await api.get( + `/v1/xtz/stakes?wallets=${walletAddresses.join(',')}`, + ); + return data; + } /** @@ -187,15 +173,13 @@ export class XtzService extends Service { startDate?: string, endDate?: string, ): Promise { - try { - const query = `/v1/xtz/rewards?accounts=${accountIds.join(',')}${ - startDate ? `&start_date=${startDate}` : '' - }${endDate ? `&end_date=${endDate}` : ''}`; - const { data } = await api.get(query); - return data; - } catch (err: any) { - throw new Error(err); - } + + const query = `/v1/xtz/rewards?accounts=${accountIds.join(',')}${ + startDate ? `&start_date=${startDate}` : '' + }${endDate ? `&end_date=${endDate}` : ''}`; + const { data } = await api.get(query); + return data; + } /** @@ -210,29 +194,25 @@ export class XtzService extends Service { startDate?: string, endDate?: string, ): Promise { - try { - const query = `/v1/xtz/rewards?wallets=${walletAddresses.join(',')}${ - startDate ? `&start_date=${startDate}` : '' - }${endDate ? `&end_date=${endDate}` : ''}`; - const { data } = await api.get(query); - return data; - } catch (err: any) { - throw new Error(err); - } + + const query = `/v1/xtz/rewards?wallets=${walletAddresses.join(',')}${ + startDate ? `&start_date=${startDate}` : '' + }${endDate ? `&end_date=${endDate}` : ''}`; + const { data } = await api.get(query); + return data; + } /** * Retrieve XTZ network stats */ async getNetworkStats(): Promise { - try { - const { data } = await api.get( - `/v1/xtz/network-stats`, - ); - return data; - } catch (err: any) { - throw new Error(err); - } + + const { data } = await api.get( + `/v1/xtz/network-stats`, + ); + return data; + } /**