From e776ea065edf6008a0f4e1f1ae5a2ebe12bb004c Mon Sep 17 00:00:00 2001 From: KafkaUnderCurrent Date: Thu, 12 Dec 2024 16:46:37 +0700 Subject: [PATCH 1/2] Tvl --- projects/wansui/index.js | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 projects/wansui/index.js diff --git a/projects/wansui/index.js b/projects/wansui/index.js new file mode 100644 index 000000000000..b74f8be6656a --- /dev/null +++ b/projects/wansui/index.js @@ -0,0 +1,37 @@ +const sui = require("../helper/chain/sui"); + +const CREATED_EVENT = "0xc4bb66da17fec7444b7b3e2ac750e35ea6225f5cca936c423fad2c78245d987c::suipump::Created"; + +async function tvl(api) { + const createdTokens = await sui.queryEvents({ + eventType: CREATED_EVENT, + transform: e => { + let tokenAddr = e.token_address + if (!tokenAddr.startsWith("0x")) { + tokenAddr = "0x" + tokenAddr + } + + return { + token: tokenAddr, + owner: e.created_by + } + } + }) + + const tokens = createdTokens.map(e => e.token) + const owners = createdTokens.map(e => e.owner) + + return await sui.sumTokens( + { + owners, + tokens, + api + } + ) +} + +module.exports = { + sui: { + tvl, + }, +} \ No newline at end of file From b02dfe0f426199ad4d37b6c0232958a4156b5269 Mon Sep 17 00:00:00 2001 From: KafkaUnderCurrent Date: Thu, 12 Dec 2024 21:51:49 +0700 Subject: [PATCH 2/2] Fix calculate token amount --- projects/wansui/index.js | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/projects/wansui/index.js b/projects/wansui/index.js index b74f8be6656a..6450ee744f74 100644 --- a/projects/wansui/index.js +++ b/projects/wansui/index.js @@ -1,7 +1,12 @@ const sui = require("../helper/chain/sui"); +const BigNumber = require('bignumber.js'); const CREATED_EVENT = "0xc4bb66da17fec7444b7b3e2ac750e35ea6225f5cca936c423fad2c78245d987c::suipump::Created"; +/** @typedef {import("@defillama/sdk").ChainApi} ChainApi */ +/** + * @param {ChainApi} api + */ async function tvl(api) { const createdTokens = await sui.queryEvents({ eventType: CREATED_EVENT, @@ -13,24 +18,29 @@ async function tvl(api) { return { token: tokenAddr, - owner: e.created_by + bondingCurve: e.bonding_curve } } }) - const tokens = createdTokens.map(e => e.token) - const owners = createdTokens.map(e => e.owner) + const bondingCurveData = await sui.getObjects(createdTokens.map(t => t.bondingCurve)) - return await sui.sumTokens( - { - owners, - tokens, - api - } - ) + const suiDecimal = 6 + const balances = bondingCurveData.map(item => { + // When created, bonding curve has 800M tokens to sell + const initialAmount = new BigNumber(800_000_000).multipliedBy(10 ** suiDecimal) + const tokenReserve = new BigNumber(item.fields.real_token_reserves) + + return initialAmount.minus(tokenReserve) + }) + + const tokens = createdTokens.map(t => t.token) + + api.addTokens(tokens, balances) } module.exports = { + methodology: "We count the tokens that have been created by the bonding curve and subtract the amount of tokens that are still in the bonding curve.", sui: { tvl, },