forked from fireblocks/fireblocks-defi-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ethers-bridge.ts
36 lines (34 loc) · 1.57 KB
/
ethers-bridge.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { Deferrable } from "@ethersproject/properties";
import { PeerType, TransactionOperation, CreateTransactionResponse, TransactionArguments } from "fireblocks-sdk";
import { PopulatedTransaction } from "ethers";
import { BaseBridge } from "./base-bridge";
import { formatEther, formatUnits } from "ethers/lib/utils";
export class EthersBridge extends BaseBridge {
async sendTransaction(transaction: Deferrable<PopulatedTransaction>, txNote?: string): Promise<CreateTransactionResponse> {
const txArguments: TransactionArguments = {
operation: TransactionOperation.CONTRACT_CALL,
assetId: this.assetId,
source: {
type: PeerType.VAULT_ACCOUNT,
id: this.params.vaultAccountId
},
gasPrice: transaction.gasPrice != undefined ? formatUnits(transaction.gasPrice.toString(), "gwei") : undefined,
gasLimit: transaction.gasLimit?.toString(),
destination: {
type: this.params.externalWalletId ? PeerType.EXTERNAL_WALLET : PeerType.ONE_TIME_ADDRESS,
id: this.params.externalWalletId,
},
note: txNote || '',
amount: formatEther(transaction.value?.toString() || "0"),
extraParameters: {
contractCallData: transaction.data
}
};
if (transaction.to) {
txArguments.destination.oneTimeAddress = {
address: <string>transaction.to
}
}
return this.params.fireblocksApiClient.createTransaction(txArguments);
}
}