Skip to content

Commit

Permalink
update:gateio chains&addresses (#12993)
Browse files Browse the repository at this point in the history
Co-authored-by: g1nt0ki <[email protected]>
Co-authored-by: Booyoun <[email protected]>
Co-authored-by: jaejeonglee <[email protected]>
Co-authored-by: stanli1231 <[email protected]>
  • Loading branch information
5 people authored Jan 7, 2025
1 parent e8819d2 commit f5d667b
Show file tree
Hide file tree
Showing 12 changed files with 1,805 additions and 73 deletions.
1,629 changes: 1,563 additions & 66 deletions projects/gate-io/index.js

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion projects/helper/bitcoin-book/gate-io.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ module.exports = [
'1G47mSr3oANXMafVrR8UC4pzV7FEAzo3r9',
'1HpED69tpKSaEaWpY3Udt1DtcVcuCUoh2Y',
'3HroDXv8hmzKRtaSfBffRgedKpru8fgy6M',
'1ECeVF6wfbiihCRrrpRnkbwrWsZfYmixMG'
'1ECeVF6wfbiihCRrrpRnkbwrWsZfYmixMG',
'1FhncfokiSDagazXbuVqKQ6ew4oyDmAzhG',
'1FLKsCiEsABS7LysfDA8R181TQ6eLjoxPv'
]
30 changes: 30 additions & 0 deletions projects/helper/chain/acala.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const sdk = require('@defillama/sdk')
const { post } = require('../http')
const { sleep } = require('../utils')

const endpoint = 'https://acala.api.subscan.io/api/v2/scan/search'

async function getBalance(key) {
const data = await post(endpoint, { key }, {
headers: {
'Content-Type': 'application/json',
'X-API-Key': 'f89d810db5ef4c4fbc83b987dc2ffcda'
}
})
return +(data?.data?.account?.balance ?? 0)
}

async function sumTokens({ balances = {}, owners = [] }) {
let total = 0
for (const owner of owners) {
const balance = await getBalance(owner)
total += balance
await sleep(3000)
}
sdk.util.sumSingleBalance(balances, 'acala', total)
return balances
}

module.exports = {
sumTokens
}
22 changes: 22 additions & 0 deletions projects/helper/chain/aelf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const sdk = require('@defillama/sdk')
const { get } = require('../http')


async function getBalance(key) {
const data = await get(`https://explorer.aelf.io/api/viewer/balances?address=${key}`)
return +(data?.data?.[0]?.balance ?? 0)
}

async function sumTokens({ balances = {}, owners = [] }) {
let total = 0
for (const owner of owners) {
const balance = await getBalance(owner)
total += balance
}
sdk.util.sumSingleBalance(balances, 'aelf', total)
return balances
}

module.exports = {
sumTokens
}
28 changes: 28 additions & 0 deletions projects/helper/chain/aeternity.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const axios = require('axios');

const endpoint = 'https://mainnet.aeternity.io/v2/accounts'; // Replace with the appropriate endpoint

async function getBalance(address) {
try {
const response = await axios.get(`${endpoint}/${address}`);
const balance = response.data.balance;
return balance;
} catch (error) {
console.error('Error fetching token balance:', error);
return 0;
}
}

async function sumTokens({ balances = {}, owners = [] }) {
let total = 0;
for (const owner of owners) {
const balance = await getBalance(owner);
total += balance;
}
sdk.util.sumSingleBalance(balances, 'aeternity', total);
return balances;
}

module.exports = {
sumTokens
};
12 changes: 12 additions & 0 deletions projects/helper/chain/alephium.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,19 @@ function addressFromContractId(contractId) {
return bs58.encode(bytes);
}

async function sumTokens({ owners = [], owner }) {
if (owner) owners = [owner];
let total = 0
for (const owner of owners)
total += (await getAlphBalance(owner)).balance / 1e18

return {
alephium: total
}
}

module.exports = {
sumTokens,
getAlphBalance,
getTokensBalance,
getTokenInfo,
Expand Down
30 changes: 30 additions & 0 deletions projects/helper/chain/astar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const sdk = require('@defillama/sdk')
const { post } = require('../http')
const { sleep } = require('../utils')

const endpoint = 'https://astar.api.subscan.io/api/v2/scan/search'

async function getBalance(key) {
const data = await post(endpoint, { key }, {
headers: {
'Content-Type': 'application/json',
'X-API-Key': 'f89d810db5ef4c4fbc83b987dc2ffcda'
}
})
return +(data?.data?.account?.balance ?? 0)
}

async function sumTokens({ balances = {}, owners = [] }) {
let total = 0
for (const owner of owners) {
const balance = await getBalance(owner)
total += balance
await sleep(3000)
}
sdk.util.sumSingleBalance(balances, 'astar', total)
return balances
}

module.exports = {
sumTokens
}
30 changes: 30 additions & 0 deletions projects/helper/chain/bifrost.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const sdk = require('@defillama/sdk')
const { post } = require('../http')
const { sleep } = require('../utils')

const endpoint = 'https://bifrost.api.subscan.io/api/v2/scan/search'

async function getBalance(key) {
const data = await post(endpoint, { key }, {
headers: {
'Content-Type': 'application/json',
'X-API-Key': 'f89d810db5ef4c4fbc83b987dc2ffcda'
}
})
return +(data?.data?.account?.balance ?? 0)
}

async function sumTokens({ balances = {}, owners = [] }) {
let total = 0
for (const owner of owners) {
const balance = await getBalance(owner)
total += balance
await sleep(3000)
}
sdk.util.sumSingleBalance(balances, 'bifrost', total)
return balances
}

module.exports = {
sumTokens
}
39 changes: 39 additions & 0 deletions projects/helper/chain/bittensor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const sdk = require('@defillama/sdk')
const { post } = require('../http')

const TAO_STATS_SUBQUERY = "https://api.subquery.network/sq/TaoStats/bittensor-indexer";

async function getBalance(key) {
const query = `{
query{
account(id: "${key}"){
id
nodeId
balanceTotal
balanceStaked
balanceFree
address
}
}
}`;


const { data: { query: { account: { balanceTotal } } } } = await post(TAO_STATS_SUBQUERY, { query, variables: {}, });
return balanceTotal/1e9
}


async function sumTokens({ balances = {}, owners = [] }) {
let total = 0
for (const owner of owners) {
const balance = await getBalance(owner)
console.log(owner, balance)
total += balance
}
sdk.util.sumSingleBalance(balances, 'bittensor', total)
return balances
}

module.exports = {
sumTokens
}
7 changes: 6 additions & 1 deletion projects/helper/chain/cosmos.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const ADDRESSES = require('../coreAssets.json')
// https://proxy.atomscan.com/chains.json
// https://cosmos-chain.directory/chains/cosmoshub
// https://cosmos-chain.directory/chains
// https://celestia.publicnode.com/
const endPoints = {
crescent: "https://mainnet.crescent.network:1317",
osmosis: "https://lcd.osmosis.zone",
Expand Down Expand Up @@ -47,7 +48,11 @@ const endPoints = {
noble: "https://noble-api.polkachu.com",
mantra: "https://api.mantrachain.io",
elys: "https://api.elys.network", // https://api.elys.network/#/Query/ElysAmmPoolAll
pryzm: "https://api.pryzm.zone"
pryzm: "https://api.pryzm.zone",
agoric: 'https://as-proxy.gateway.atomscan.com/agoric-lcd',
band: 'https://laozi1.bandchain.org/api',
celestia: 'https://celestia-rest.publicnode.com',
dydx: 'https://dydx-rest.publicnode.com',
};

const chainSubpaths = {
Expand Down
30 changes: 27 additions & 3 deletions projects/helper/sumTokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,25 @@ const helpers = {
"bitcoin": require("./chain/bitcoin"),
"litecoin": require("./chain/litecoin"),
"polkadot": require("./chain/polkadot"),
"acala": require("./chain/acala"),
"bifrost": require("./chain/bifrost"),
"aelf": require("./chain/aelf"),
"aeternity": require("./chain/aeternity"),
"alephium": require("./chain/alephium"),
"hedera": require("./chain/hbar"),
"stacks": require("./chain/stacks"),
"starknet": require("./chain/starknet"),
"brc20": require("./chain/brc20"),
"doge": require("./chain/doge"),
"bittensor": require("./chain/bittensor"),
"fuel": require("./chain/fuel"),
"radixdlt": require("./chain/radixdlt"),
}


// some chains support both evm & non-evm, this is to handle if address provided is not evm
const altEVMHelper = {
"astar": require("./chain/astar"),
}

const geckoMapping = {
Expand Down Expand Up @@ -60,11 +74,20 @@ async function sumTokens(options) {

if (token) tokens = [token]
if (owner) owners = [owner]
const nonEvmOwnerFound = chain !== 'tron' && owners.some(o => !o.startsWith('0x'))
const isAltEvm = altEVMHelper[chain] && nonEvmOwnerFound

if (!ibcChains.includes(chain) && !helpers[chain] && !specialChains.includes(chain))
if (!ibcChains.includes(chain) && !helpers[chain] && !specialChains.includes(chain) && !isAltEvm) {
if (nonEvmOwnerFound) throw new Error('chain handler missing: ' + chain)
return sumTokensEVM(options)
}


if (!isAltEvm)
owners = getUniqueAddresses(owners, chain)
else
owners = [...new Set(owners)] // retain case sensitivity

owners = getUniqueAddresses(owners, chain)
blacklistedTokens = getUniqueAddresses(blacklistedTokens, chain)
if (!['eos'].includes(chain))
tokens = getUniqueAddresses(tokens, chain).filter(t => !blacklistedTokens.includes(t))
Expand All @@ -80,7 +103,7 @@ async function sumTokens(options) {
options.owners = owners
options.tokens = tokens
options.blacklistedTokens = blacklistedTokens
let helper = helpers[chain]
let helper = helpers[chain] || altEVMHelper[chain]

if (ibcChains.includes(chain)) helper = helpers.cosmos

Expand Down Expand Up @@ -118,6 +141,7 @@ async function sumTokens(options) {
async function getRippleBalance(account) {
const body = { "method": "account_info", "params": [{ account }] }
const res = await post('https://s1.ripple.com:51234', body)
if (res.result.error === 'actNotFound') return 0
return res.result.account_data.Balance / 1e6
}

Expand Down
17 changes: 15 additions & 2 deletions projects/helper/tokenMapping.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ coreAssets = JSON.parse(JSON.stringify(coreAssets))


const ibcChains = ['ibc', 'terra', 'terra2', 'crescent', 'osmosis', 'kujira', 'stargaze', 'juno', 'injective', 'cosmos', 'comdex', 'umee', 'orai', 'persistence', 'fxcore', 'neutron', 'quasar', 'chihuahua', 'sei', 'archway', 'migaloo', 'secret', 'aura', 'xpla', 'bostrom', 'joltify', 'nibiru',
'kopi', 'elys', "pryzm", "mantra",
'kopi', 'elys', "pryzm", "mantra", 'agoric', 'band',
'celestia', 'dydx',

]
const caseSensitiveChains = [...ibcChains, 'solana', 'tezos', 'ton', 'algorand', 'aptos', 'near', 'bitcoin', 'waves', 'tron', 'litecoin', 'polkadot', 'ripple', 'elrond', 'cardano', 'stacks', 'sui', 'ergo', 'mvc', 'renec', 'doge', 'stellar', 'massa',
'eclipse',
'eclipse', 'acala', 'aelf', 'aeternity', 'alephium', 'bifrost', 'bittensor',
]

const transformTokens = {
Expand Down Expand Up @@ -53,6 +54,18 @@ const fixBalancesTokens = {
water: {
'0xC807C5FfFf748eF435Ddb99b181846Edd1e70041': { coingeckoId: "water-3", decimals: 18 },
},
bittorrent: {
[ADDRESSES.null]: { coingeckoId: "bittorrent", decimals: 18 },
},
dymension: {
[ADDRESSES.null]: { coingeckoId: "dymension", decimals: 18 },
},
energyweb: {
[ADDRESSES.null]: { coingeckoId: "energy-web-token", decimals: 18 },
},
etn: {
[ADDRESSES.null]: { coingeckoId: "electroneum", decimals: 18 },
},
kopi: {
'uasusdc': { coingeckoId: 'usd-coin', decimals: 6 },
'ucusdc': { coingeckoId: 'usd-coin', decimals: 6 },
Expand Down

0 comments on commit f5d667b

Please sign in to comment.