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

sync code #15

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion projects/navi/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "navi",
"private": true,
"version": "1.0.0",
"version": "2.26.0",
"type": "module",
"scripts": {
"test": "sentio test",
Expand Down
24 changes: 5 additions & 19 deletions projects/navi/sentio.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
project: navi/navi
project: navi/naviproduction
contracts:
- chain: sui_mainnet
address: "0xe17e8d461129585fdd83dd891b1b5858f51984acbb308daa7ad8627c13f31c9d"
- chain: sui_testnet
address: "0x8ba6cdd02f5d1b9ff9970690681c21957d9a6a6fbb74546b2f0cfb16dbff4c25"
- chain: sui_testnet
address: "0x6850914af4d097f53be63182675334fb41a6782e4e702a5d605a61969750e777"
- chain: sui_mainnet
address: "0xccdf4385016f20c784e68376359ddc2f6a9e050ec431ca5c85f1bc81024d4427"
- chain: sui_mainnet
Expand All @@ -11,22 +15,4 @@ contracts:
- chain: sui_mainnet
address: "0xd899cf7d2b5db716bd2cf55599fb0d5ee38a3061e7b6bb6eebf73fa5bc4c81ca"
- chain: sui_mainnet
address: "0xe17e8d461129585fdd83dd891b1b5858f51984acbb308daa7ad8627c13f31c9d"
- chain: sui_mainnet
address: "0xccdf4385016f20c784e68376359ddc2f6a9e050ec431ca5c85f1bc81024d4427"
- chain: sui_mainnet
address: "0xda691d321641786d758d7435d0e230a7125777566c75b34c5742591163a252c3"
- chain: sui_mainnet
address: "0xca441b44943c16be0e6e23c5a955bb971537ea3289ae8016fbf33fffe1fd210f"
- chain: sui_mainnet

address: "0xd899cf7d2b5db716bd2cf55599fb0d5ee38a3061e7b6bb6eebf73fa5bc4c81ca"
- chain: sui_mainnet

address: "0xe66f07e2a8d9cf793da1e0bca98ff312b3ffba57228d97cf23a0613fddf31b65"
- chain: sui_mainnet

address: "0x81be491340a6964eb9903141c3068db55704b5892072eb9e372cc98f4b04639c"
- chain: sui_mainnet

address: "0xd92bc457b42d48924087ea3f22d35fd2fe9afdf5bdfe38cc51c0f14f3282f6d5"
3 changes: 3 additions & 0 deletions projects/navi/src/mainnet/interfaces.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface CoinMap {
[key: string]: string;
}
63 changes: 41 additions & 22 deletions projects/navi/src/mainnet/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
SuiContext,
SuiObjectContext,
} from "@sentio/sdk/sui"
import { lending } from "../types/sui/0xd899cf7d2b5db716bd2cf55599fb0d5ee38a3061e7b6bb6eebf73fa5bc4c81ca.js";
import { incentive_v2, lending } from "../types/sui/0xe66f07e2a8d9cf793da1e0bca98ff312b3ffba57228d97cf23a0613fddf31b65.js";
import { token } from "@sentio/sdk/utils"
import { ProtocolProcessor } from "./storage.js";
import { PoolProcessor } from "./pool.js";
Expand All @@ -24,11 +24,8 @@ export const getOrCreateCoin = async function (ctx: SuiContext | SuiObjectContex

export async function buildCoinInfo(ctx: SuiContext | SuiObjectContext, coinAddress: string): Promise<token.TokenInfo> {
const metadata = await ctx.client.getCoinMetadata({ coinType: coinAddress })
//@ts-ignore
const symbol = metadata.symbol
//@ts-ignore
const decimal = metadata.decimals
//@ts-ignore
const name = metadata.name
console.log(`build coin metadata ${symbol} ${decimal} ${name}`)
return {
Expand All @@ -53,7 +50,10 @@ async function onEvent(event: LendingEvent, ctx: SuiContext) {
0: "0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI",
1: "0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf::coin::COIN",
2: "0xc060006111016b8a020ad5b33834984a437aaa7d3c74c18e09a95d48aceab08c::coin::COIN",
3: "0xaf8cd5edc19c4512f4259f0bee101a40d41ebed738ade5874359610ef8eeced5::coin::COIN"
3: "0xaf8cd5edc19c4512f4259f0bee101a40d41ebed738ade5874359610ef8eeced5::coin::COIN",
4: "0x06864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b::cetus::CETUS",
5: "0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT",
6: "0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d::hasui::HASUI"
}
const coinAddress = Coins[reserve]
// const coinAddress = event.data_decoded.pool;
Expand All @@ -78,7 +78,6 @@ async function onLiquidationEvent(event: lending.LiquidationCallEventInstance, c
const liquidation_amount = event.data_decoded.liquidate_amount
const liquidate_user = event.data_decoded.liquidate_user
const reserve = event.data_decoded.reserve

const typeArray = event.type.split("::")
const type = typeArray[typeArray.length - 1]

Expand All @@ -94,20 +93,40 @@ async function onLiquidationEvent(event: lending.LiquidationCallEventInstance, c
}


import { lending as lending2 } from "../types/sui/0xe17e8d461129585fdd83dd891b1b5858f51984acbb308daa7ad8627c13f31c9d.js"
// import { lending as lending } from "../types/sui/0xccdf4385016f20c784e68376359ddc2f6a9e050ec431ca5c85f1bc81024d4427.js"
// import { lending as lending2 } from "../types/sui/0xda691d321641786d758d7435d0e230a7125777566c75b34c5742591163a252c3.js"
// import { lending as lending2 } from "../types/sui/0xca441b44943c16be0e6e23c5a955bb971537ea3289ae8016fbf33fffe1fd210f.js"
import { lending as lending3 } from "../types/sui/0xd899cf7d2b5db716bd2cf55599fb0d5ee38a3061e7b6bb6eebf73fa5bc4c81ca.js"
import { lending as lending4 } from "../types/sui/0xe66f07e2a8d9cf793da1e0bca98ff312b3ffba57228d97cf23a0613fddf31b65.js"
import { lending as lending5 } from "../types/sui/0x81be491340a6964eb9903141c3068db55704b5892072eb9e372cc98f4b04639c.js"
import { lending as lending6 } from "../types/sui/0xd92bc457b42d48924087ea3f22d35fd2fe9afdf5bdfe38cc51c0f14f3282f6d5.js"

for (const l of [lending, lending2, lending3, lending4, lending5, lending6]) {
l.bind()
.onEventBorrowEvent(onEvent)
.onEventDepositEvent(onEvent)
.onEventRepayEvent(onEvent)
.onEventWithdrawEvent(onEvent)
.onEventLiquidationCallEvent(onLiquidationEvent)
async function onRewardsClaimedEvent(event: incentive_v2.RewardsClaimedInstance, ctx: SuiContext) {

//TODO 需要改为动态
const Coins: any = {
0: "0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI",
1: "0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf::coin::COIN",
2: "0xc060006111016b8a020ad5b33834984a437aaa7d3c74c18e09a95d48aceab08c::coin::COIN",
3: "0xaf8cd5edc19c4512f4259f0bee101a40d41ebed738ade5874359610ef8eeced5::coin::COIN"
}
const coinAddress = Coins[0]
const coinDecimal = getOrCreateCoin(ctx, coinAddress)
const amount = scaleDown(event.data_decoded.amount, (await coinDecimal).decimal)
const pool = event.data_decoded.pool
const sender = event.data_decoded.sender

const typeArray = event.type.split("::")
const type = typeArray[typeArray.length - 1]

ctx.eventLogger.emit("UserInteraction", {
distinctId: sender,
sender,
amount,
pool,
type,
env: "mainnet"
})
}


lending.bind()
.onEventBorrowEvent(onEvent)
.onEventDepositEvent(onEvent)
.onEventRepayEvent(onEvent)
.onEventWithdrawEvent(onEvent)
.onEventLiquidationCallEvent(onLiquidationEvent)
incentive_v2.bind()
.onEventRewardsClaimed(onRewardsClaimedEvent)
10 changes: 6 additions & 4 deletions projects/navi/src/mainnet/pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ const pools = [
"0xa02a98f9c88db51c6f5efaaf2261c81f34dd56d86073387e0ef1805ca22e39c8", // Treasury Pool For USDC
"0x0e060c3b5b8de00fb50511b7a45188c8e34b6995c01f69d98ea5a466fe10d103", // Treasury Pool For USDT
"0x71b9f6e822c48ce827bceadce82201d6a7559f7b0350ed1daa1dc2ba3ac41b56", // Treasury Pool For WETH
"0x3c376f857ec4247b8ee456c1db19e9c74e0154d4876915e54221b5052d5b1e2e", //Treasury Pool For CETUS
"0x9790c2c272e15b6bf9b341eb531ef16bcc8ed2b20dfda25d060bf47f5dd88d01", // Treasury Pool For VoloSui
"0x6fd9cb6ebd76bc80340a9443d72ea0ae282ee20e2fd7544f6ffcd2c070d9557a", //Treasury Pool For haSui

]

export function PoolProcessor() {
Expand All @@ -20,11 +24,9 @@ export function PoolProcessor() {
const type = String(self.type);
const coin_type = SymbolMatcher(type);
const coin_symbol = COIN_MAP[coin_type];
//@ts-ignore
const decimal = self.fields.decimal
//@ts-ignore

const decimal = self.fields.decimal;
const balance = BigDecimal(self.fields.balance).div(Math.pow(10, decimal));
//@ts-ignore
const treasuryBalance = BigDecimal(self.fields.treasury_balance).div(Math.pow(10, decimal));

//TODO
Expand Down
40 changes: 40 additions & 0 deletions projects/navi/src/mainnet/reward.pool.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { SuiObjectProcessor } from "@sentio/sdk/sui"
import { ChainId } from "@sentio/chain"
import { BigDecimal } from "@sentio/sdk"
import { COIN_MAP, SymbolMatcher } from "./utils.js";

const rewardPools = [
"0x9180e0b8758f4b03f74fa3fa1350ae023af88bc2b5b347352a298b8ad547b7f5", // Reward Pool For SUI
"0x6c5d1f05ca6794ff24ea6bd5e1ee93ecae82b65e7f4361aa0a2d5f8b985b6639", // Reward Pool For USDC
"0x8d146663da3afc111f8e7dd197591c01a950049ed552f940bc20927411072ca2", // Reward Pool For SUI
"0x595c64e52d44ddac6e84fa55ddec7b993526ca73ea8df1f0887a05307ce09435", // Reward Pool For USDC
]

export function PoolProcessor() {
for (let pool of rewardPools) {
SuiObjectProcessor.bind({
objectId: pool,
network: ChainId.SUI_MAINNET,
startCheckpoint: 7800000n
}).onTimeInterval(async (self, data, ctx) => {
//TODO: find out the token type
const type = String(self.type);
const coin_type = SymbolMatcher(type);
const coin_symbol = COIN_MAP[coin_type];

const decimal = self.fields.decimal;
const distributedAmountForRewardPool = BigDecimal(self.fields.distributed_amount).div(Math.pow(10, decimal));
const balanceForRewardPool = BigDecimal(self.fields.balance).div(Math.pow(10, decimal));
const assetForRewardPool = self.fields.asset;
const currentIdxForRewardPool = self.fields.current_idx;


//TODO:
ctx.meter.Gauge("distributedAmountForRewardPool").record(distributedAmountForRewardPool, { env: "mainnet", type, coin_type, coin_symbol });
ctx.meter.Gauge("balanceForRewardPool").record(balanceForRewardPool, { env: "mainnet", type, coin_type, coin_symbol });
ctx.meter.Gauge("assetForRewardPool").record(assetForRewardPool, { env: "mainnet", type, coin_type, coin_symbol });
ctx.meter.Gauge("currentIdxForRewardPool").record(currentIdxForRewardPool, { env: "mainnet", type, coin_type, coin_symbol });

})
}
}
19 changes: 7 additions & 12 deletions projects/navi/src/mainnet/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ const reserves = [
"0xeb3903f7748ace73429bd52a70fff278aac1725d3b58afa781f25ce3450ac203", // Reserve For USDC
"0xb8c5eab02a0202f638958cc79a69a2d30055565caad1684b3c8bbca3bddcb322", // Reserve For USDT
"0xafecf4b57899d377cc8c9de75854c68925d9f512d0c47150ca52a0d3a442b735", // Reserve For WETH
"0x66a807c06212537fe46aa6719a00e4fa1e85a932d0b53ce7c4b1041983645133", // Reserve For CETUS
"0xd4fd7e094af9819b06ea3136c13a6ae8da184016b78cf19773ac26d2095793e2", // Reserve For VoloSui
"0x0c9f7a6ca561dc566bd75744bcc71a6af1dc3caf7bd32c099cd640bb5f3bb0e3", // Reserve For haSUI
]

export function ProtocolProcessor() {
Expand All @@ -19,31 +22,23 @@ export function ProtocolProcessor() {
startCheckpoint: 7800000n
}).onTimeInterval(async (self, _, ctx) => {
try {
//@ts-ignore
const type = String(self.fields.value.fields.coin_type)
//@ts-ignore
const id = String(self.fields.value.fields.id)
//@ts-ignore
const ltv = BigDecimal(self.fields.value.fields.ltv).div(Math.pow(10, DECIMAL_RAY))
const coin_symbol = COIN[i]
//@ts-ignore

const totalSupply = BigDecimal(self.fields.value.fields.supply_balance.fields.total_supply).div(Math.pow(10, DEFAULT_COIN_DECIMAL))
//@ts-ignore
const totalBorrow = BigDecimal(self.fields.value.fields.borrow_balance.fields.total_supply).div(Math.pow(10, DEFAULT_COIN_DECIMAL))
//@ts-ignore

const currentSupplyIndex = BigDecimal(self.fields.value.fields.current_supply_index).div(Math.pow(10, DECIMAL_RAY))
//@ts-ignore
const currentBorrowIndex = BigDecimal(self.fields.value.fields.current_borrow_index).div(Math.pow(10, DECIMAL_RAY))
//add
//@ts-ignore
const supplyCapCelling = BigDecimal(self.fields.value.fields.supply_cap_ceiling).div(Math.pow(10, DECIMAL_RAY))
//@ts-ignore
const borrowCapCeiling = BigDecimal(self.fields.value.fields.borrow_cap_ceiling).div(Math.pow(10, DECIMAL_RAY))
//@ts-ignore

const treasuryBalance = BigDecimal(self.fields.value.fields.treasury_balance).div(Math.pow(10, DEFAULT_COIN_DECIMAL))
//@ts-ignore

const currentBorrowRate = BigDecimal(self.fields.value.fields.current_borrow_rate).div(Math.pow(10, DECIMAL_RAY))
//@ts-ignore
const currentSupplyRate = BigDecimal(self.fields.value.fields.current_supply_rate).div(Math.pow(10, DECIMAL_RAY))

// const supply rate
Expand Down
8 changes: 7 additions & 1 deletion projects/navi/src/mainnet/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CoinMap } from "./interfaces.js";

export const COIN = ["SUI", "USDC", "USDT", "WETH"];
export const COIN = ["SUI", "USDC", "USDT", "WETH", "CETUS","VoloSui","HASUI"];

export const DECIMAL_RAY = 27;
export const DEFAULT_COIN_DECIMAL = 9;
Expand All @@ -14,6 +14,12 @@ export const COIN_MAP: CoinMap = {
"USDT",
"0xaf8cd5edc19c4512f4259f0bee101a40d41ebed738ade5874359610ef8eeced5::coin::COIN":
"WETH",
"0x06864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b::cetus::CETUS":
"CETUS",
"0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT":
"VoloSui",
"0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d::hasui::HASUI":
"HASUI"
};

export function SymbolMatcher(objectType: string) {
Expand Down
28 changes: 28 additions & 0 deletions projects/navi/src/processor.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { TestProcessorServer, firstCounterValue } from '@sentio/sdk/testing'
import { mockTransferLog } from '@sentio/sdk/eth/builtin/erc20'

describe('Test Processor', () => {
const service = new TestProcessorServer(() => import('./processor.js'))

beforeAll(async () => {
await service.start()
})

test('has valid config', async () => {
const config = await service.getConfig({})
expect(config.contractConfigs.length > 0).toBeTruthy()
})

test('check transfer event handling', async () => {
const resp = await service.eth.testLog(
mockTransferLog('0x1e4ede388cbc9f4b5c79681b7f94d36a11abebc9', {
from: '0x0000000000000000000000000000000000000000',
to: '0xb329e39ebefd16f40d38f07643652ce17ca5bac1',
value: 10n ** 18n * 10n,
})
)

const tokenCounter = firstCounterValue(resp.result, 'token')
expect(tokenCounter).toEqual(10n)
})
})
3 changes: 2 additions & 1 deletion projects/navi/src/processor.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
import "./mainnet/main"
import "./mainnet/main.js"
import "./testnet.js"
61 changes: 61 additions & 0 deletions projects/navi/src/testnet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// // import { pool, pool_factory } from "./types/sui/turbos.js";
// import { SuiObjectProcessor, SuiContext, SuiObjectContext, SuiObjectProcessorTemplate } from "@sentio/sdk/sui"
// // import * as constant from './constant-turbos.js'
// import { ChainId } from "@sentio/chain"
// import { BUILTIN_TYPES } from "@sentio/sdk/move"
// import { Gauge, scaleDown } from "@sentio/sdk";
// import { pool } from "./types/sui/testnet/0x8ba6cdd02f5d1b9ff9970690681c21957d9a6a6fbb74546b2f0cfb16dbff4c25.js"
// import { lending as lendingTestnet } from "./types/sui/testnet/0x8ba6cdd02f5d1b9ff9970690681c21957d9a6a6fbb74546b2f0cfb16dbff4c25.js";
// import { lending } from "./types/sui/0xe17e8d461129585fdd83dd891b1b5858f51984acbb308daa7ad8627c13f31c9d.js";

// import { storage } from "./types/sui/testnet/0x6850914af4d097f53be63182675334fb41a6782e4e702a5d605a61969750e777.js";

// import { dynamic_field } from "@sentio/sdk/sui/builtin/0x2";
// import { getOrCreateCoin } from "./mainnet/main.js";

// export type LendingEvent = lending.BorrowEventInstance | lending.DepositEventInstance | lending.WithdrawEventInstance | lending.RepayEventInstance

// // SuiObjectProcessor.bind({
// // objectId: "0x5d137ca143af1366db782327d957d8e2afbf10c17b9d45e0f46111e6bcc4e805",
// // network: ChainId.SUI_TESTNET,
// // startCheckpoint: 3150000n
// // }).onTimeInterval(async (self, _, ctx) => {

// // // const typeDescriptor = dynamic_field.Field.type(BUILTIN_TYPES.U8_TYPE, storage.ReserveData.type())

// // // const v = await ctx.coder.decodedType(self, typeDescriptor)
// // // if (v) {
// // try {
// // const totalSupply = Number(self.fields.value.fields.supply_balance.fields.total_supply)
// // ctx.meter.Gauge("total_supply").record(totalSupply)
// // } catch(e) {
// // console.log(e)
// // console.log(JSON.stringify(self))
// // }
// // })

// async function onEvent(event: LendingEvent, ctx: SuiContext) {
// const sender = event.data_decoded.sender
// const reserve = event.data_decoded.reserve

// const typeArray = event.type.split("::")
// const type = typeArray[typeArray.length - 1]

// const coinDecimal = getOrCreateCoin(ctx,type)
// const amount = scaleDown(event.data_decoded.amount, (await coinDecimal).decimal)

// ctx.eventLogger.emit("UserInteraction", {
// distinctId: sender,
// sender,
// amount,
// reserve,
// type,
// env: "testnet"
// })
// }

// lendingTestnet.bind()
// .onEventBorrowEvent(onEvent)
// .onEventDepositEvent(onEvent)
// .onEventRepayEvent(onEvent)
// .onEventWithdrawEvent(onEvent)
2 changes: 1 addition & 1 deletion projects/navi/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"esModuleInterop": true,
"noImplicitReturns": true,
"noImplicitAny": true,
"module": "esnext",
"module": "nodenext",
"moduleResolution": "nodenext",
"strictNullChecks": true,
"stripInternal": true,
Expand Down