Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat-Add-support-for-NAVI-integration #60

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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