1+ import { CompassApiSDK } from "@compass-labs/api-sdk" ;
2+ import dotenv from "dotenv" ;
3+ import { privateKeyToAccount } from 'viem/accounts'
4+ import { mainnet } from 'viem/chains' ;
5+ import { http , SendTransactionRequest } from 'viem' ;
6+
7+ import { createWalletClient } from 'viem' ;
8+
9+ dotenv . config ( ) ;
10+
11+ const PRIVATE_KEY = process . env . PRIVATE_KEY as `0x${string } `;
12+ const RPC_URL = process . env . RPC_URL as string ;
13+
14+ const main = async ( ) => {
15+ const compassApiSDK = new CompassApiSDK ( {
16+ apiKeyAuth : process . env . COMPASS_API_KEY ,
17+ } ) ;
18+
19+ const account = privateKeyToAccount ( PRIVATE_KEY ) ;
20+
21+ const walletClient = createWalletClient ( {
22+ account,
23+ chain : mainnet ,
24+ transport : http ( RPC_URL as string ) ,
25+ } ) ;
26+
27+ const auth = await compassApiSDK . transactionBatching . authorization ( {
28+ chain : "ethereum:mainnet" ,
29+ sender : account . address ,
30+ } ) ;
31+
32+ const signedAuth = await walletClient . signAuthorization ( {
33+ account,
34+ contractAddress : auth . address as `0x${string } `,
35+ } ) ;
36+
37+ const loopingTx = await compassApiSDK . transactionBatching . aaveLoop ( {
38+ chain : "ethereum:mainnet" ,
39+ sender : account . address ,
40+ signedAuthorization : {
41+ nonce : signedAuth . nonce ,
42+ address : signedAuth . address ,
43+ chainId : signedAuth . chainId ,
44+ r : signedAuth . r ,
45+ s : signedAuth . s ,
46+ yParity : signedAuth . yParity as number ,
47+ } ,
48+ collateralToken : "USDC" ,
49+ borrowToken : "WETH" ,
50+ initialCollateralAmount : 5 ,
51+ multiplier : 1.5 ,
52+ maxSlippagePercent : 2.5 ,
53+ loanToValue : 70 ,
54+ } ) ;
55+
56+ const tx = await walletClient . sendTransaction ( loopingTx as unknown as SendTransactionRequest ) ;
57+
58+ console . log ( tx ) ;
59+ }
60+
61+
62+ main ( ) ;
0 commit comments