-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #286 from dappradar/ton-integration
Ton chain and 3 dapps integration
- Loading branch information
Showing
11 changed files
with
133 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { ITvlParams, ITvlReturn } from '../../../../interfaces/ITvl'; | ||
import axios from 'axios'; | ||
import formatter from '../../../../util/formatter'; | ||
import BigNumber from 'bignumber.js'; | ||
|
||
const POOLS_URI = 'https://api.dedust.io/v1/pools'; | ||
|
||
async function tvl(params: ITvlParams): Promise<Partial<ITvlReturn>> { | ||
const { block, chain, provider, web3 } = params; | ||
|
||
const balances = {}; | ||
const pools = (await axios.get(POOLS_URI)).data; | ||
|
||
pools.forEach((pool) => { | ||
balances[pool.left_token_root] = BigNumber( | ||
balances[pool.left_token_root] || 0, | ||
).plus(pool.left_token_reserve); | ||
balances[pool.right_token_root] = BigNumber( | ||
balances[pool.right_token_root] || 0, | ||
).plus(pool.right_token_reserve); | ||
}); | ||
|
||
formatter.convertBalancesToFixed(balances); | ||
return { balances }; | ||
} | ||
|
||
export { tvl }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { ITvlParams, ITvlReturn } from '../../../../interfaces/ITvl'; | ||
import axios from 'axios'; | ||
import formatter from '../../../../util/formatter'; | ||
import BigNumber from 'bignumber.js'; | ||
|
||
const POOLS_URI = 'https://app.ston.fi/rpc'; | ||
|
||
async function tvl(params: ITvlParams): Promise<Partial<ITvlReturn>> { | ||
const { block, chain, provider, web3 } = params; | ||
|
||
const balances = {}; | ||
const pools = ( | ||
await axios.post(POOLS_URI, { | ||
jsonrpc: '2.0', | ||
id: 2, | ||
method: 'pool.list', | ||
params: {}, | ||
}) | ||
).data.result.pools; | ||
|
||
pools.forEach((pool) => { | ||
balances[pool.token0_address] = BigNumber( | ||
balances[pool.token0_address] || 0, | ||
).plus(pool.reserve0); | ||
balances[pool.token1_address] = BigNumber( | ||
balances[pool.token1_address] || 0, | ||
).plus(pool.reserve1); | ||
}); | ||
|
||
formatter.convertBalancesToFixed(balances); | ||
return { balances }; | ||
} | ||
|
||
export { tvl }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { ITvlParams, ITvlReturn } from '../../../../interfaces/ITvl'; | ||
import formatter from '../../../../util/formatter'; | ||
|
||
const CONTRACT_ADDRESS = 'EQCkWxfyhAkim3g2DjKQQg8T5P4g-Q1-K_jErGcDJZ4i-vqR'; | ||
const METHOD = 'get_pool_full_data'; | ||
const TON_ADDRESS = 'EQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAM9c'; | ||
|
||
async function tvl(params: ITvlParams): Promise<Partial<ITvlReturn>> { | ||
const { block, chain, provider, web3 } = params; | ||
|
||
const balances = {}; | ||
const response = await web3.eth.call(CONTRACT_ADDRESS, METHOD); | ||
|
||
balances[TON_ADDRESS] = response[2]; | ||
|
||
formatter.convertBalancesToFixed(balances); | ||
return { balances }; | ||
} | ||
|
||
export { tvl }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import axios from 'axios'; | ||
|
||
@Injectable() | ||
export class Ton { | ||
async call(address, method, params = []) { | ||
const requestBody = { | ||
address, | ||
method, | ||
stack: params, | ||
}; | ||
|
||
const response = await axios | ||
.post('https://toncenter.com/api/v2/runGetMethod', requestBody, { | ||
headers: { | ||
'X-API-Key': process.env.TONCENTER_API_KEY, | ||
}, | ||
}) | ||
.then((response) => response.data.result); | ||
|
||
const { exit_code, stack } = response; | ||
if (exit_code !== 0) { | ||
throw new Error('Expected a zero exit code, but got ' + exit_code); | ||
} | ||
stack.forEach((i, idx) => { | ||
if (i[0] === 'num') { | ||
stack[idx] = parseInt(i[1], 16); | ||
} | ||
}); | ||
|
||
return stack; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters