Skip to content

Commit 0f733a8

Browse files
nooxxgithub-actions[bot]LeTamanoir
authored
SDK V3 (#121)
* Update generated OpenAPI schema.d.ts * wip * Update generated OpenAPI schema.d.ts * wip * nit * sign ada tx * sign atom tx * sign dydx tx * sign fet tx * sign inj tx * sign kava tx * sign osmo tx * sign tia tx * sign zeta tx * sign dot & ksm tx * sign eth tx * sign pol tx * sign ton tx * sign xtz tx * nit * remove unused libs + setup biome * format * fix lint * fix lint * bump version * add utils * fix lint * Update src/utils.ts Co-authored-by: Martin Saldinger <[email protected]> * Update src/utils.ts Co-authored-by: Martin Saldinger <[email protected]> --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Martin Saldinger <[email protected]> Co-authored-by: Martin Saldinger <[email protected]>
1 parent 11ddfa0 commit 0f733a8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+44270
-4908
lines changed

.eslintrc.json

Lines changed: 0 additions & 8 deletions
This file was deleted.

.github/workflows/sdk.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,12 @@ on:
66
- main
77
paths:
88
- "src/**"
9-
- "index.ts"
109
- ".github/workflows/sdk.yml"
1110
pull_request:
1211
branches:
1312
- main
1413
paths:
1514
- "src/**"
16-
- "index.ts"
1715
- ".github/workflows/sdk.yml"
1816

1917
jobs:

.prettierrc

Lines changed: 0 additions & 3 deletions
This file was deleted.

biome.json

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"$schema": "https://biomejs.dev/schemas/1.6.2/schema.json",
3+
"organizeImports": {
4+
"enabled": true
5+
},
6+
"formatter": {
7+
"indentStyle": "space",
8+
"lineWidth": 120
9+
},
10+
"javascript": {
11+
"formatter": {
12+
"quoteStyle": "single"
13+
}
14+
},
15+
"files": {
16+
"maxSize": 4000000,
17+
"ignore": ["openapi"]
18+
},
19+
"linter": {
20+
"enabled": true,
21+
"rules": {
22+
"nursery": {
23+
"useSortedClasses": "off"
24+
},
25+
"recommended": true,
26+
"a11y": {
27+
"noSvgWithoutTitle": "off"
28+
},
29+
"correctness": {
30+
"noUnusedImports": "error",
31+
"noUnusedVariables": "error"
32+
},
33+
"suspicious": {
34+
"noArrayIndexKey": "off"
35+
}
36+
}
37+
}
38+
}

bun.lockb

-191 KB
Binary file not shown.

index.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

package.json

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@kilnfi/sdk",
3-
"version": "2.23.0",
3+
"version": "3.0.0",
44
"autor": "Kiln <[email protected]> (https://kiln.fi)",
55
"license": "BUSL-1.1",
66
"description": "JavaScript sdk for Kiln API",
@@ -13,8 +13,8 @@
1313
}
1414
},
1515
"scripts": {
16-
"lint": "eslint index.ts src/**/*.ts",
17-
"lint:fix": "eslint index.ts src/**/*.ts --fix",
16+
"lint": "biome check ./src",
17+
"format": "biome check ./src --write --unsafe",
1818
"build": "tsc"
1919
},
2020
"keywords": [
@@ -32,34 +32,21 @@
3232
},
3333
"homepage": "https://github.com/kilnfi/sdk-js#readme",
3434
"dependencies": {
35-
"@blockfrost/blockfrost-js": "^5.5.0",
3635
"@cosmjs/proto-signing": "^0.30.1",
3736
"@cosmjs/stargate": "^0.30.1",
38-
"@emurgo/cardano-serialization-lib-nodejs": "^11.5.0",
39-
"@solana/web3.js": "^1.93.0",
40-
"@substrate/txwrapper-polkadot": "^7.5.1",
41-
"@taquito/local-forging": "^17.5.2",
42-
"@taquito/rpc": "^16.2.0",
4337
"@types/bn.js": "^5.1.5",
4438
"axios": "^1.7.2",
4539
"bn.js": "^5.2.1",
46-
"ethers": "^5.7.2",
4740
"fireblocks-sdk": "^4.2.0",
4841
"js-sha256": "^0.9.0",
4942
"near-api-js": "^2.1.4",
50-
"protobufjs": "^7.3.2",
43+
"openapi-fetch": "^0.12.0",
5144
"viem": "^1.21.4"
5245
},
5346
"devDependencies": {
47+
"@biomejs/biome": "^1.9.1",
5448
"@types/axios": "^0.14.0",
5549
"@types/node-fetch": "^2.6.11",
56-
"@typescript-eslint/eslint-plugin": "^5.62.0",
57-
"@typescript-eslint/parser": "^5.62.0",
58-
"eslint": "^7.32.0",
59-
"eslint-config-airbnb-base": "^14.2.1",
60-
"eslint-config-next": "^12.3.4",
61-
"eslint-plugin-import": "^2.29.1",
62-
"prettier": "^3.3.2",
63-
"typescript": "^5.5.2"
50+
"typescript": "^5.6.2"
6451
}
6552
}

src/api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import axios from "axios";
1+
import axios from 'axios';
22

33
const api = axios.create();
44
api.interceptors.response.use(
Lines changed: 57 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,41 @@
11
import {
2-
CreateTransactionResponse,
3-
FireblocksSDK,
2+
type CreateTransactionResponse,
3+
type FireblocksSDK,
44
PeerType,
5-
TransactionArguments,
5+
type TransactionArguments,
66
TransactionOperation,
7-
TransactionResponse,
7+
type TransactionResponse,
88
TransactionStatus,
9-
} from "fireblocks-sdk";
9+
} from 'fireblocks-sdk';
1010

11-
import { utils } from "ethers";
12-
import { EthTx } from "../types/eth";
13-
import { MaticTx } from "../types/matic";
11+
import { formatEther, formatUnits } from 'viem';
12+
import type { components } from './openapi/schema';
1413

1514
export type AssetId =
16-
| "SOL_TEST"
17-
| "SOL"
18-
| "ETH_TEST5"
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-
| "DOT"
32-
| "KSM"
33-
| "DV4TNT_TEST"
34-
| "DYDX_DYDX"
35-
| "CELESTIA"
36-
| "INJ_INJ"
37-
| "TON_TEST"
38-
| "TON"
39-
| "KAVA_KAVA";
15+
| 'SOL_TEST'
16+
| 'SOL'
17+
| 'ETH_TEST5'
18+
| 'ETH_TEST6'
19+
| 'ETH'
20+
| 'ATOM_COS_TEST'
21+
| 'ATOM_COS'
22+
| 'OSMO_TEST'
23+
| 'OSMO'
24+
| 'ADA_TEST'
25+
| 'ADA'
26+
| 'NEAR_TEST'
27+
| 'NEAR'
28+
| 'XTZ_TEST'
29+
| 'XTZ'
30+
| 'DOT'
31+
| 'KSM'
32+
| 'DV4TNT_TEST'
33+
| 'DYDX_DYDX'
34+
| 'CELESTIA'
35+
| 'INJ_INJ'
36+
| 'TON_TEST'
37+
| 'TON'
38+
| 'KAVA_KAVA';
4039

4140
export class FbSigner {
4241
protected fireblocks: FireblocksSDK;
@@ -55,24 +54,25 @@ export class FbSigner {
5554
protected async waitForTxCompletion(fbTx: CreateTransactionResponse): Promise<TransactionResponse> {
5655
try {
5756
let tx = fbTx;
58-
while (tx.status != TransactionStatus.COMPLETED) {
57+
while (tx.status !== TransactionStatus.COMPLETED) {
5958
if (
60-
tx.status == TransactionStatus.BLOCKED ||
61-
tx.status == TransactionStatus.FAILED ||
62-
tx.status == TransactionStatus.CANCELLED
59+
tx.status === TransactionStatus.BLOCKED ||
60+
tx.status === TransactionStatus.FAILED ||
61+
tx.status === TransactionStatus.CANCELLED
6362
) {
6463
throw Error(`Fireblocks signer: the transaction has been ${tx.status}`);
65-
} else if (tx.status == TransactionStatus.REJECTED) {
64+
}
65+
if (tx.status === TransactionStatus.REJECTED) {
6666
throw Error(
67-
`Fireblocks signer: the transaction has been rejected, make sure that the TAP security policy is not blocking the transaction`,
67+
'Fireblocks signer: the transaction has been rejected, make sure that the TAP security policy is not blocking the transaction',
6868
);
6969
}
7070
tx = await this.fireblocks.getTransactionById(fbTx.id);
7171
}
7272

7373
return await this.fireblocks.getTransactionById(fbTx.id);
74-
} catch (err: any) {
75-
throw new Error("Fireblocks signer (waitForTxCompletion): " + err);
74+
} catch (err) {
75+
throw new Error(`Fireblocks signer (waitForTxCompletion): ${err}`);
7676
}
7777
}
7878

@@ -82,7 +82,7 @@ export class FbSigner {
8282
* @param assetId fireblocks asset id
8383
* @param note optional fireblocks custom note
8484
*/
85-
public async sign(payloadToSign: any, assetId?: AssetId, note?: string): Promise<TransactionResponse> {
85+
public async sign(payloadToSign: object, assetId?: AssetId, note?: string): Promise<TransactionResponse> {
8686
try {
8787
const assetArgs = assetId
8888
? {
@@ -102,9 +102,8 @@ export class FbSigner {
102102
};
103103
const fbTx = await this.fireblocks.createTransaction(tx);
104104
return await this.waitForTxCompletion(fbTx);
105-
} catch (err: any) {
106-
console.log(err);
107-
throw new Error("Fireblocks signer (signWithFB): " + err);
105+
} catch (err) {
106+
throw new Error(`Fireblocks signer (signWithFB): ${err}`);
108107
}
109108
}
110109

@@ -115,8 +114,8 @@ export class FbSigner {
115114
* @param note optional fireblocks custom note
116115
*/
117116
public async signTypedMessage(
118-
eip712message: any,
119-
assetId: "ETH" | "ETH_TEST5" | "ETH_TEST6",
117+
eip712message: object,
118+
assetId: 'ETH' | 'ETH_TEST5' | 'ETH_TEST6',
120119
note?: string,
121120
): Promise<TransactionResponse> {
122121
try {
@@ -133,17 +132,16 @@ export class FbSigner {
133132
messages: [
134133
{
135134
content: eip712message,
136-
type: "EIP712",
135+
type: 'EIP712',
137136
},
138137
],
139138
},
140139
},
141140
};
142141
const fbTx = await this.fireblocks.createTransaction(tx);
143142
return await this.waitForTxCompletion(fbTx);
144-
} catch (err: any) {
145-
console.log(err);
146-
throw new Error("Fireblocks signer (signWithFB): " + err);
143+
} catch (err) {
144+
throw new Error(`Fireblocks signer (signWithFB): ${err}`);
147145
}
148146
}
149147

@@ -157,11 +155,11 @@ export class FbSigner {
157155
* @param sendAmount send the amount in tx to smart contract
158156
*/
159157
public async signAndBroadcastWith(
160-
payloadToSign: any,
158+
payloadToSign: object,
161159
assetId: AssetId,
162-
tx: EthTx | MaticTx,
160+
tx: components['schemas']['ETHUnsignedTx'] | components['schemas']['POLUnsignedTx'],
163161
destinationId: string,
164-
sendAmount: boolean = true,
162+
sendAmount = true,
165163
note?: string,
166164
): Promise<TransactionResponse> {
167165
try {
@@ -176,17 +174,17 @@ export class FbSigner {
176174
type: PeerType.EXTERNAL_WALLET,
177175
id: destinationId,
178176
},
179-
amount: tx.data.amount_wei && sendAmount ? utils.formatEther(tx.data.amount_wei) : "0",
177+
amount: tx.amount_wei && sendAmount ? formatEther(BigInt(tx.amount_wei), 'wei') : '0',
180178
note,
181179
extraParameters: payloadToSign,
182-
gasLimit: tx.data.gas_limit,
183-
priorityFee: utils.formatUnits(tx.data.max_priority_fee_per_gas_wei, "gwei"),
184-
maxFee: utils.formatUnits(tx.data.max_fee_per_gas_wei, "gwei"),
180+
gasLimit: tx.gas_limit,
181+
priorityFee: formatUnits(BigInt(tx.max_priority_fee_per_gas_wei), 9),
182+
maxFee: formatUnits(BigInt(tx.max_fee_per_gas_wei), 9),
185183
};
186184
const fbTx = await this.fireblocks.createTransaction(txArgs);
187185
return await this.waitForTxCompletion(fbTx);
188-
} catch (err: any) {
189-
throw new Error("Fireblocks signer (signAndBroadcastWithFB): " + err);
186+
} catch (err) {
187+
throw new Error(`Fireblocks signer (signAndBroadcastWithFB): ${err}`);
190188
}
191189
}
192190
}

0 commit comments

Comments
 (0)