Skip to content

Commit

Permalink
Merge pull request #60 from naviprotocol/feat-support-check-navi-inte…
Browse files Browse the repository at this point in the history
…gration

Feat-Add-support-for-NAVI-integration
  • Loading branch information
ComeOnOliver authored Dec 17, 2024
2 parents f16dffe + 1438536 commit 5aa3173
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "navi-sdk",
"version": "1.4.11",
"version": "1.4.12",
"description": "",
"main": "dist/index.js",
"scripts": {
Expand Down
7 changes: 6 additions & 1 deletion src/libs/Aggregator/swapPTB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,4 +253,9 @@ export async function swapPTB(
}

return finalCoinB;
}
}

export async function checkIfNAVIIntegrated(digest: string, client: SuiClient): Promise<boolean> {
const results = await client.getTransactionBlock({ digest, options: { showEvents: true } });
return results.events?.some(event => event.type.includes(`${AggregatorConfig.aggregatorContract}::slippage`)) ?? false;
}
14 changes: 12 additions & 2 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { describe, it, expect } from 'vitest';
import { NAVISDKClient } from '../src/index';
import { NAVX, nUSDC, Sui } from '../src/address';
import { Transaction } from "@mysten/sui/transactions";
import { borrowCoin, depositCoin, withdrawCoin, repayDebt, stakeTovSuiPTB, updateOraclePTB, swapPTB, SignAndSubmitTXB } from '../src/libs/PTB';
import { borrowCoin, depositCoin, withdrawCoin, repayDebt, stakeTovSuiPTB, updateOraclePTB, swapPTB, SignAndSubmitTXB, checkIfNAVIIntegrated } from '../src/libs/PTB';
import { Pool, PoolConfig, CoinInfo, OptionType } from "../src/types";
import { getConfig, pool, AddressMap, vSui } from "../src/address";
import { error } from 'console';
Expand All @@ -19,7 +19,7 @@ const privateKey = process.env.PRIVATE_KEY || '';
describe('NAVI SDK Client', async () => {

const client = new NAVISDKClient({ networkType: rpcUrl, mnemonic: mnemonic });

const account = client.accounts[0];
it('should generate correct account', async () => {
expect(client.accounts[0].getPublicKey()).toBe(client.getAllAccounts()[0].getPublicKey());
});
Expand Down Expand Up @@ -86,6 +86,16 @@ describe('NAVI SDK Client', async () => {
expect(reward.asset_id).toBe('5');

});
it('should check if NAVI is integrated', async () => {
const digest = "4JwmF4UFESM2b18wgNgGsfHA7MStTDAomLuQQnUaa6qr";
const res = await checkIfNAVIIntegrated(digest, account.client);
expect(res).toBe(true);
});
it('should check if NAVI is not integrated', async () => {
const digest = "F94zASa3cudFffhetkW898MDt3ZT1qEmxvAUULp6BSbP";
const res = await checkIfNAVIIntegrated(digest, account.client);
expect(res).toBe(false);
});

});

Expand Down

0 comments on commit 5aa3173

Please sign in to comment.