Skip to content

Commit 0de4dd7

Browse files
committed
add FET support
1 parent 491227d commit 0de4dd7

File tree

5 files changed

+373
-88
lines changed

5 files changed

+373
-88
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@kilnfi/sdk",
3-
"version": "2.11.2",
3+
"version": "2.11.3",
44
"autor": "Kiln <[email protected]> (https://kiln.fi)",
55
"license": "BUSL-1.1",
66
"description": "JavaScript sdk for Kiln API",
@@ -57,4 +57,4 @@
5757
"eslint-plugin-import": "^2.25.2",
5858
"typescript": "^5.3.2"
5959
}
60-
}
60+
}

src/integrations/fb_signer.ts

Lines changed: 105 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,38 @@ import {
22
CreateTransactionResponse,
33
FireblocksSDK,
44
PeerType,
5+
SigningAlgorithm,
56
TransactionArguments,
67
TransactionOperation,
78
TransactionResponse,
89
TransactionStatus,
9-
} from 'fireblocks-sdk';
10+
} from "fireblocks-sdk";
1011

11-
import { utils } from 'ethers';
12-
import { EthTx } from '../types/eth';
12+
import { utils } from "ethers";
13+
import { EthTx } from "../types/eth";
1314
import { MaticTx } from "../types/matic";
1415

1516
type AssetId =
16-
'SOL_TEST'
17-
| 'SOL'
18-
| 'ETH_TEST3'
19-
| 'ETH_TEST6'
20-
| 'ETH'
21-
| 'ATOM_COS_TEST'
22-
| 'ATOM_COS'
23-
| 'OSMO_TEST'
24-
| 'OSMO'
25-
| 'ADA_TEST'
26-
| 'ADA'
27-
| 'NEAR_TEST'
28-
| 'NEAR'
29-
| 'XTZ_TEST'
30-
| 'XTZ'
31-
| 'WND'
32-
| 'DOT'
33-
| 'DV4TNT_TEST'
34-
| 'DYDX_DYDX'
35-
| 'CELESTIA'
36-
;
17+
| "SOL_TEST"
18+
| "SOL"
19+
| "ETH_TEST3"
20+
| "ETH_TEST6"
21+
| "ETH"
22+
| "ATOM_COS_TEST"
23+
| "ATOM_COS"
24+
| "OSMO_TEST"
25+
| "OSMO"
26+
| "ADA_TEST"
27+
| "ADA"
28+
| "NEAR_TEST"
29+
| "NEAR"
30+
| "XTZ_TEST"
31+
| "XTZ"
32+
| "WND"
33+
| "DOT"
34+
| "DV4TNT_TEST"
35+
| "DYDX_DYDX"
36+
| "CELESTIA";
3737

3838
export class FbSigner {
3939
protected fireblocks: FireblocksSDK;
@@ -42,38 +42,52 @@ export class FbSigner {
4242
constructor(fireblocks: FireblocksSDK, vaultId: number) {
4343
this.fireblocks = fireblocks;
4444
this.vaultId = vaultId;
45-
};
46-
45+
}
4746

4847
/**
4948
* Wait for given transaction to be completed
5049
* @param fbTx: fireblocks transaction
5150
* @private
5251
*/
53-
protected async waitForTxCompletion(fbTx: CreateTransactionResponse): Promise<TransactionResponse> {
52+
protected async waitForTxCompletion(
53+
fbTx: CreateTransactionResponse
54+
): Promise<TransactionResponse> {
5455
try {
5556
let tx = fbTx;
5657
while (tx.status != TransactionStatus.COMPLETED) {
57-
if (tx.status == TransactionStatus.BLOCKED || tx.status == TransactionStatus.FAILED || tx.status == TransactionStatus.REJECTED || tx.status == TransactionStatus.CANCELLED) {
58-
throw Error(`Fireblocks signer: the transaction has been ${tx.status}`);
58+
if (
59+
tx.status == TransactionStatus.BLOCKED ||
60+
tx.status == TransactionStatus.FAILED ||
61+
tx.status == TransactionStatus.CANCELLED
62+
) {
63+
throw Error(
64+
`Fireblocks signer: the transaction has been ${tx.status}`
65+
);
66+
} else if (tx.status == TransactionStatus.REJECTED) {
67+
throw Error(
68+
`Fireblocks signer: the transaction has been rejected, make sure that the TAP security policy is not blocking the transaction`
69+
);
5970
}
6071
tx = await this.fireblocks.getTransactionById(fbTx.id);
6172
}
6273

63-
return (await this.fireblocks.getTransactionById(fbTx.id));
74+
return await this.fireblocks.getTransactionById(fbTx.id);
6475
} catch (err: any) {
65-
throw new Error('Fireblocks signer (waitForTxCompletion): ' + err);
76+
throw new Error("Fireblocks signer (waitForTxCompletion): " + err);
6677
}
6778
}
6879

69-
7080
/**
7181
* Sign a transaction with fireblocks using Fireblocks raw message signing feature
7282
* @param payloadToSign: transaction data in hexadecimal
7383
* @param assetId: fireblocks asset id
7484
* @param note: optional fireblocks custom note
7585
*/
76-
public async signWithFB(payloadToSign: any, assetId: AssetId, note?: string): Promise<TransactionResponse> {
86+
public async signWithFB(
87+
payloadToSign: any,
88+
assetId: AssetId,
89+
note?: string
90+
): Promise<TransactionResponse> {
7791
try {
7892
const tx: TransactionArguments = {
7993
assetId: assetId,
@@ -86,10 +100,47 @@ export class FbSigner {
86100
extraParameters: payloadToSign,
87101
};
88102
const fbTx = await this.fireblocks.createTransaction(tx);
89-
return (await this.waitForTxCompletion(fbTx));
103+
return await this.waitForTxCompletion(fbTx);
104+
} catch (err: any) {
105+
console.log(err);
106+
throw new Error("Fireblocks signer (signWithFB): " + err);
107+
}
108+
}
109+
110+
/**
111+
* Sign a generic transaction with fireblocks using Fireblocks raw message signing feature.
112+
* @param payloadToSign: transaction data in hexadecimal
113+
* @param derivationPath: derivation path of the token to sign
114+
* @param algorithm: algorithm of the token to sign
115+
* @param note: optional fireblocks custom note
116+
*/
117+
public async signGenericWithFB(
118+
payloadContent: string,
119+
derivationPath: number[],
120+
algorithm: SigningAlgorithm,
121+
note?: string
122+
): Promise<TransactionResponse> {
123+
try {
124+
const payloadToSign = {
125+
operation: TransactionOperation.RAW,
126+
note,
127+
extraParameters: {
128+
rawMessageData: {
129+
messages: [
130+
{
131+
content: payloadContent,
132+
derivationPath,
133+
},
134+
],
135+
algorithm,
136+
},
137+
},
138+
};
139+
const fbTx = await this.fireblocks.createTransaction(payloadToSign);
140+
return await this.waitForTxCompletion(fbTx);
90141
} catch (err: any) {
91142
console.log(err);
92-
throw new Error('Fireblocks signer (signWithFB): ' + err);
143+
throw new Error("Fireblocks signer (signGenericWithFB): " + err);
93144
}
94145
}
95146

@@ -102,7 +153,14 @@ export class FbSigner {
102153
* @param destinationId Fireblocks destination id, this corresponds to the Fireblocks whitelisted contract address id
103154
* @param sendAmount send the amount in tx to smart contract
104155
*/
105-
public async signAndBroadcastWithFB(payloadToSign: any, assetId: AssetId, tx: EthTx | MaticTx, destinationId: string, sendAmount: boolean = true, note?: string): Promise<TransactionResponse> {
156+
public async signAndBroadcastWithFB(
157+
payloadToSign: any,
158+
assetId: AssetId,
159+
tx: EthTx | MaticTx,
160+
destinationId: string,
161+
sendAmount: boolean = true,
162+
note?: string
163+
): Promise<TransactionResponse> {
106164
try {
107165
const txArgs: TransactionArguments = {
108166
assetId: assetId,
@@ -115,18 +173,23 @@ export class FbSigner {
115173
type: PeerType.EXTERNAL_WALLET,
116174
id: destinationId,
117175
},
118-
amount: tx.data.amount_wei && sendAmount ? utils.formatEther(tx.data.amount_wei) : "0",
176+
amount:
177+
tx.data.amount_wei && sendAmount
178+
? utils.formatEther(tx.data.amount_wei)
179+
: "0",
119180
note,
120181
extraParameters: payloadToSign,
121182
gasLimit: tx.data.gas_limit,
122-
priorityFee: utils.formatUnits(tx.data.max_priority_fee_per_gas_wei, 'gwei'),
123-
maxFee: utils.formatUnits(tx.data.max_fee_per_gas_wei, 'gwei'),
183+
priorityFee: utils.formatUnits(
184+
tx.data.max_priority_fee_per_gas_wei,
185+
"gwei"
186+
),
187+
maxFee: utils.formatUnits(tx.data.max_fee_per_gas_wei, "gwei"),
124188
};
125189
const fbTx = await this.fireblocks.createTransaction(txArgs);
126-
return (await this.waitForTxCompletion(fbTx));
190+
return await this.waitForTxCompletion(fbTx);
127191
} catch (err: any) {
128-
throw new Error('Fireblocks signer (signAndBroadcastWithFB): ' + err);
192+
throw new Error("Fireblocks signer (signAndBroadcastWithFB): " + err);
129193
}
130194
}
131195
}
132-

src/kiln.ts

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1-
import api from './api';
1+
import api from "./api";
22
import { KILN_VALIDATORS as v } from "./validators";
3-
import { EthService } from './services/eth';
4-
import { SolService } from './services/sol';
5-
import { AtomService } from './services/atom';
6-
import { AccountService } from './services/accounts';
7-
import { AdaService } from './services/ada';
8-
import { NearService } from './services/near';
9-
import { DotService } from './services/dot';
10-
import { XtzService } from './services/xtz';
11-
import { MaticService } from './services/matic';
12-
import { OsmoService } from './services/osmo';
3+
import { EthService } from "./services/eth";
4+
import { SolService } from "./services/sol";
5+
import { AtomService } from "./services/atom";
6+
import { AccountService } from "./services/accounts";
7+
import { AdaService } from "./services/ada";
8+
import { NearService } from "./services/near";
9+
import { DotService } from "./services/dot";
10+
import { XtzService } from "./services/xtz";
11+
import { MaticService } from "./services/matic";
12+
import { OsmoService } from "./services/osmo";
1313
import { FireblocksService } from "./services/fireblocks";
1414
import { DydxService } from "./services/dydx";
1515
import { TiaService } from "./services/tia";
16+
import { FetService } from "./services/fet";
1617

1718
type Config = {
1819
apiToken: string;
@@ -36,14 +37,16 @@ export class Kiln {
3637
osmo: OsmoService;
3738
dydx: DydxService;
3839
tia: TiaService;
40+
fet: FetService;
3941

4042
constructor({ testnet, apiToken, baseUrl }: Config) {
4143
api.defaults.headers.common.Authorization = `Bearer ${apiToken}`;
42-
api.defaults.headers.common['Content-Type'] = 'application/json';
43-
api.defaults.baseURL = baseUrl ? baseUrl :
44-
testnet === true
45-
? 'https://api.testnet.kiln.fi'
46-
: 'https://api.kiln.fi';
44+
api.defaults.headers.common["Content-Type"] = "application/json";
45+
api.defaults.baseURL = baseUrl
46+
? baseUrl
47+
: testnet === true
48+
? "https://api.testnet.kiln.fi"
49+
: "https://api.kiln.fi";
4750

4851
this.fireblocks = new FireblocksService({ testnet });
4952
this.accounts = new AccountService({ testnet });
@@ -58,5 +61,6 @@ export class Kiln {
5861
this.osmo = new OsmoService({ testnet });
5962
this.dydx = new DydxService({ testnet });
6063
this.tia = new TiaService({ testnet });
64+
this.fet = new FetService({ testnet });
6165
}
62-
}
66+
}

0 commit comments

Comments
 (0)