Skip to content

Commit

Permalink
add TIA support
Browse files Browse the repository at this point in the history
  • Loading branch information
nooxx committed Jan 19, 2024
1 parent f5dac4a commit 405ef67
Show file tree
Hide file tree
Showing 12 changed files with 270 additions and 128 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ Check out the [full documentation](https://docs.kiln.fi/v1/connect/overview).
- ADA
- ATOM
- DOT
- DYDX
- ETH
- MATIC
- NEAR
- OSMO
- SOL
- TIA
- XTZ
- OSMO
- DYDX
- More protocol to come, don't hesitate to contact us ([email protected])

## Installation
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kilnfi/sdk",
"version": "2.9.0",
"version": "2.10.0",
"autor": "Kiln <[email protected]> (https://kiln.fi)",
"license": "BUSL-1.1",
"description": "JavaScript sdk for Kiln API",
Expand Down
1 change: 1 addition & 0 deletions src/integrations/fb_signer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type AssetId =
| 'DOT'
| 'DV4TNT_TEST'
| 'DYDX_DYDX'
| 'CELESTIA'
;

export class FbSigner {
Expand Down
3 changes: 3 additions & 0 deletions src/kiln.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { MaticService } from './services/matic';
import { OsmoService } from './services/osmo';
import { FireblocksService } from "./services/fireblocks";
import { DydxService } from "./services/dydx";
import { TiaService } from "./services/tia";

type Config = {
apiToken: string;
Expand All @@ -34,6 +35,7 @@ export class Kiln {
matic: MaticService;
osmo: OsmoService;
dydx: DydxService;
tia: TiaService;

constructor({ testnet, apiToken, baseUrl }: Config) {
api.defaults.headers.common.Authorization = `Bearer ${apiToken}`;
Expand All @@ -55,5 +57,6 @@ export class Kiln {
this.matic = new MaticService({ testnet });
this.osmo = new OsmoService({ testnet });
this.dydx = new DydxService({ testnet });
this.tia = new TiaService({ testnet });
}
}
31 changes: 16 additions & 15 deletions src/services/atom.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Service } from "./service";

import { AtomRewards, AtomSignedTx, AtomStakes, AtomTx, AtomTxHash, AtomTxStatus } from "../types/atom";
import { AtomRewards, AtomStakes } from "../types/atom";
import { ServiceProps } from "../types/service";
import { Integration } from "../types/integrations";
import api from "../api";
import { DecodedTxRaw } from "@cosmjs/proto-signing";
import { CosmosSignedTx, CosmosTx, CosmosTxHash, CosmosTxStatus } from "../types/cosmos";

export class AtomService extends Service {

Expand Down Expand Up @@ -32,9 +33,9 @@ export class AtomService extends Service {
pubkey: string,
validatorAddress: string,
amountAtom: number,
): Promise<AtomTx> {
): Promise<CosmosTx> {
try {
const { data } = await api.post<AtomTx>(
const { data } = await api.post<CosmosTx>(
`/v1/atom/transaction/stake`,
{
account_id: accountId,
Expand All @@ -56,9 +57,9 @@ export class AtomService extends Service {
async craftWithdrawRewardsTx(
pubkey: string,
validatorAddress: string,
): Promise<AtomTx> {
): Promise<CosmosTx> {
try {
const { data } = await api.post<AtomTx>(
const { data } = await api.post<CosmosTx>(
`/v1/atom/transaction/withdraw-rewards`,
{
pubkey: pubkey,
Expand All @@ -80,9 +81,9 @@ export class AtomService extends Service {
pubkey: string,
validatorAddress: string,
amountAtom?: number,
): Promise<AtomTx> {
): Promise<CosmosTx> {
try {
const { data } = await api.post<AtomTx>(
const { data } = await api.post<CosmosTx>(
`/v1/atom/transaction/unstake`,
{
pubkey: pubkey,
Expand All @@ -109,9 +110,9 @@ export class AtomService extends Service {
validatorSourceAddress: string,
validatorDestinationAddress: string,
amountAtom?: number,
): Promise<AtomTx> {
): Promise<CosmosTx> {
try {
const { data } = await api.post<AtomTx>(
const { data } = await api.post<CosmosTx>(
`/v1/atom/transaction/redelegate`,
{
account_id: accountId,
Expand All @@ -132,7 +133,7 @@ export class AtomService extends Service {
* @param tx raw transaction
* @param note note to identify the transaction in your custody solution
*/
async sign(integration: Integration, tx: AtomTx, note?: string): Promise<AtomSignedTx> {
async sign(integration: Integration, tx: CosmosTx, note?: string): Promise<CosmosSignedTx> {
const payload = {
rawMessageData: {
messages: [
Expand All @@ -146,7 +147,7 @@ export class AtomService extends Service {
const signer = this.getFbSigner(integration);
const fbTx = await signer.signWithFB(payload, this.testnet ? 'ATOM_COS_TEST' : 'ATOM_COS', fbNote);
const signature: string = fbTx.signedMessages![0].signature.fullSig;
const { data } = await api.post<AtomSignedTx>(
const { data } = await api.post<CosmosSignedTx>(
`/v1/atom/transaction/prepare`,
{
pubkey: tx.data.pubkey,
Expand All @@ -163,9 +164,9 @@ export class AtomService extends Service {
* Broadcast transaction to the network
* @param signedTx
*/
async broadcast(signedTx: AtomSignedTx): Promise<AtomTxHash> {
async broadcast(signedTx: CosmosSignedTx): Promise<CosmosTxHash> {
try {
const { data } = await api.post<AtomTxHash>(
const { data } = await api.post<CosmosTxHash>(
`/v1/atom/transaction/broadcast`,
{
tx_serialized: signedTx.data.signed_tx_serialized,
Expand All @@ -180,9 +181,9 @@ export class AtomService extends Service {
* Get transaction status
* @param txHash
*/
async getTxStatus(txHash: string): Promise<AtomTxStatus> {
async getTxStatus(txHash: string): Promise<CosmosTxStatus> {
try {
const { data } = await api.get<AtomTxStatus>(
const { data } = await api.get<CosmosTxStatus>(
`/v1/atom/transaction/status?tx_hash=${txHash}`);
return data;
} catch (e: any) {
Expand Down
30 changes: 15 additions & 15 deletions src/services/dydx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ServiceProps } from '../types/service';
import { Integration } from '../types/integrations';
import api from '../api';
import { DecodedTxRaw } from "@cosmjs/proto-signing";
import { DydxSignedTx, DydxTxHash, DydxTxStatus, DydxTx } from "../types/dydx";
import { CosmosSignedTx, CosmosTx, CosmosTxHash, CosmosTxStatus } from "../types/cosmos";

export class DydxService extends Service {

Expand Down Expand Up @@ -32,9 +32,9 @@ export class DydxService extends Service {
pubkey: string,
validatorAddress: string,
amountDydx: number,
): Promise<DydxTx> {
): Promise<CosmosTx> {
try {
const { data } = await api.post<DydxTx>(
const { data } = await api.post<CosmosTx>(
`/v1/dydx/transaction/stake`,
{
account_id: accountId,
Expand All @@ -56,9 +56,9 @@ export class DydxService extends Service {
async craftWithdrawRewardsTx(
pubkey: string,
validatorAddress: string,
): Promise<DydxTx> {
): Promise<CosmosTx> {
try {
const { data } = await api.post<DydxTx>(
const { data } = await api.post<CosmosTx>(
`/v1/dydx/transaction/withdraw-rewards`,
{
pubkey: pubkey,
Expand All @@ -80,9 +80,9 @@ export class DydxService extends Service {
pubkey: string,
validatorAddress: string,
amountDydx?: number,
): Promise<DydxTx> {
): Promise<CosmosTx> {
try {
const { data } = await api.post<DydxTx>(
const { data } = await api.post<CosmosTx>(
`/v1/dydx/transaction/unstake`,
{
pubkey: pubkey,
Expand All @@ -109,9 +109,9 @@ export class DydxService extends Service {
validatorSourceAddress: string,
validatorDestinationAddress: string,
amountDydx?: number,
): Promise<DydxTx> {
): Promise<CosmosTx> {
try {
const { data } = await api.post<DydxTx>(
const { data } = await api.post<CosmosTx>(
`/v1/dydx/transaction/redelegate`,
{
account_id: accountId,
Expand All @@ -132,7 +132,7 @@ export class DydxService extends Service {
* @param tx raw transaction
* @param note note to identify the transaction in your custody solution
*/
async sign(integration: Integration, tx: DydxTx, note?: string): Promise<DydxSignedTx> {
async sign(integration: Integration, tx: CosmosTx, note?: string): Promise<CosmosSignedTx> {
const payload = {
rawMessageData: {
messages: [
Expand All @@ -146,7 +146,7 @@ export class DydxService extends Service {
const signer = this.getFbSigner(integration);
const fbTx = await signer.signWithFB(payload, this.testnet ? 'DV4TNT_TEST' : 'DYDX_DYDX', fbNote);
const signature: string = fbTx.signedMessages![0].signature.fullSig;
const { data } = await api.post<DydxSignedTx>(
const { data } = await api.post<CosmosSignedTx>(
`/v1/dydx/transaction/prepare`,
{
pubkey: tx.data.pubkey,
Expand All @@ -163,9 +163,9 @@ export class DydxService extends Service {
* Broadcast transaction to the network
* @param signedTx
*/
async broadcast(signedTx: DydxSignedTx): Promise<DydxTxHash> {
async broadcast(signedTx: CosmosSignedTx): Promise<CosmosTxHash> {
try {
const { data } = await api.post<DydxTxHash>(
const { data } = await api.post<CosmosTxHash>(
`/v1/dydx/transaction/broadcast`,
{
tx_serialized: signedTx.data.signed_tx_serialized,
Expand All @@ -180,9 +180,9 @@ export class DydxService extends Service {
* Get transaction status
* @param txHash
*/
async getTxStatus(txHash: string): Promise<DydxTxStatus> {
async getTxStatus(txHash: string): Promise<CosmosTxStatus> {
try {
const { data } = await api.get<DydxTxStatus>(
const { data } = await api.get<CosmosTxStatus>(
`/v1/dydx/transaction/status?tx_hash=${txHash}`);
return data;
} catch (e: any) {
Expand Down
7 changes: 6 additions & 1 deletion src/services/fireblocks.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Integration } from "../types/integrations";
import { Service } from "./service";
import { PublicKeyResponse } from "fireblocks-sdk";
import { AssetTypeResponse, PublicKeyResponse } from "fireblocks-sdk";

export class FireblocksService extends Service {

Expand All @@ -20,4 +20,9 @@ export class FireblocksService extends Service {
});
return data;
}

async getAssets(integration: Integration): Promise<AssetTypeResponse[]> {
const fbSdk = this.getFbSdk(integration);
return await fbSdk.getSupportedAssets();
}
}
33 changes: 15 additions & 18 deletions src/services/osmo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@ import { Service } from './service';

import {
OsmoRewards,
OsmoSignedTx,
OsmoStakes,
OsmoTx,
OsmoTxHash,
OsmoTxStatus,
} from '../types/osmo';
import { ServiceProps } from '../types/service';
import { Integration } from '../types/integrations';
import api from '../api';
import { DecodedTxRaw } from "@cosmjs/proto-signing";
import { CosmosSignedTx, CosmosTx, CosmosTxHash, CosmosTxStatus } from "../types/cosmos";

export class OsmoService extends Service {

Expand Down Expand Up @@ -39,9 +36,9 @@ export class OsmoService extends Service {
pubkey: string,
validatorAddress: string,
amountOsmo: number,
): Promise<OsmoTx> {
): Promise<CosmosTx> {
try {
const { data } = await api.post<OsmoTx>(
const { data } = await api.post<CosmosTx>(
`/v1/osmo/transaction/stake`,
{
account_id: accountId,
Expand All @@ -63,9 +60,9 @@ export class OsmoService extends Service {
async craftWithdrawRewardsTx(
pubkey: string,
validatorAddress: string,
): Promise<OsmoTx> {
): Promise<CosmosTx> {
try {
const { data } = await api.post<OsmoTx>(
const { data } = await api.post<CosmosTx>(
`/v1/osmo/transaction/withdraw-rewards`,
{
pubkey: pubkey,
Expand All @@ -87,9 +84,9 @@ export class OsmoService extends Service {
pubkey: string,
validatorAddress: string,
amountOsmo?: number,
): Promise<OsmoTx> {
): Promise<CosmosTx> {
try {
const { data } = await api.post<OsmoTx>(
const { data } = await api.post<CosmosTx>(
`/v1/osmo/transaction/unstake`,
{
pubkey: pubkey,
Expand All @@ -116,9 +113,9 @@ export class OsmoService extends Service {
validatorSourceAddress: string,
validatorDestinationAddress: string,
amountOsmo?: number,
): Promise<OsmoTx> {
): Promise<CosmosTx> {
try {
const { data } = await api.post<OsmoTx>(
const { data } = await api.post<CosmosTx>(
`/v1/osmo/transaction/redelegate`,
{
account_id: accountId,
Expand All @@ -139,7 +136,7 @@ export class OsmoService extends Service {
* @param tx raw transaction
* @param note note to identify the transaction in your custody solution
*/
async sign(integration: Integration, tx: OsmoTx, note?: string): Promise<OsmoSignedTx> {
async sign(integration: Integration, tx: CosmosTx, note?: string): Promise<CosmosSignedTx> {
const payload = {
rawMessageData: {
messages: [
Expand All @@ -153,7 +150,7 @@ export class OsmoService extends Service {
const signer = this.getFbSigner(integration);
const fbTx = await signer.signWithFB(payload, this.testnet ? 'OSMO_TEST' : 'OSMO', fbNote);
const signature: string = fbTx.signedMessages![0].signature.fullSig;
const { data } = await api.post<OsmoSignedTx>(
const { data } = await api.post<CosmosSignedTx>(
`/v1/osmo/transaction/prepare`,
{
pubkey: tx.data.pubkey,
Expand All @@ -170,9 +167,9 @@ export class OsmoService extends Service {
* Broadcast transaction to the network
* @param signedTx
*/
async broadcast(signedTx: OsmoSignedTx): Promise<OsmoTxHash> {
async broadcast(signedTx: CosmosSignedTx): Promise<CosmosTxHash> {
try {
const { data } = await api.post<OsmoTxHash>(
const { data } = await api.post<CosmosTxHash>(
`/v1/osmo/transaction/broadcast`,
{
tx_serialized: signedTx.data.signed_tx_serialized,
Expand All @@ -187,9 +184,9 @@ export class OsmoService extends Service {
* Get transaction status
* @param txHash
*/
async getTxStatus(txHash: string): Promise<OsmoTxStatus> {
async getTxStatus(txHash: string): Promise<CosmosTxStatus> {
try {
const { data } = await api.get<OsmoTxStatus>(
const { data } = await api.get<CosmosTxStatus>(
`/v1/osmo/transaction/status?tx_hash=${txHash}`);
return data;
} catch (e: any) {
Expand Down
Loading

0 comments on commit 405ef67

Please sign in to comment.