1
1
const sdk = require ( "@defillama/sdk" ) ;
2
- import { Balances , ChainBlocks , PeggedIssuanceAdapter } from "../peggedAsset.type" ;
3
- import { chainContracts } from "./config" ;
4
- import { sumSingleBalance } from "../helper/generalUtil" ;
5
- import { solanaMintedOrBridged } from "../helper/getSupply" ;
6
- import { getTokenBalance } from "../helper/solana" ;
7
-
8
- const getChainBalance =
9
- ( chain : string , decimals : number , type : "minted" | "unreleased" , owner ?: string ) =>
10
- async ( _ts : number , _ethBlock : number , chainBlocks : ChainBlocks ) => {
11
- const balances : Balances = { } ;
12
- for ( const token of chainContracts [ chain ] . issued ) {
13
- const value =
14
- type === "minted"
15
- ? (
16
- await sdk . api . abi . call ( {
17
- abi : "erc20:totalSupply" ,
18
- target : token ,
19
- block : chainBlocks [ chain ] ,
20
- chain,
21
- } )
22
- ) . output
23
- : (
24
- await sdk . api . erc20 . balanceOf ( {
25
- target : token ,
26
- owner : owner ! ,
27
- block : chainBlocks [ chain ] ,
28
- chain,
29
- } )
2
+ import { Balances , ChainBlocks , PeggedAssetType , PeggedIssuanceAdapter } from "../peggedAsset.type" ;
3
+ import { chainContracts } from "../societe-generale-forge-eurcv/config" ;
4
+ import { getTokenBalance as solanaGetTokenBalance , getTokenSupply as solanaGetTokenSupply } from "../helper/solana" ;
5
+ import { sumSingleBalance } from "../helper/generalUtil" ;
6
+
7
+
8
+
9
+ async function chainMinted ( chain : string , decimals : number ) {
10
+ return async function (
11
+ _timestamp : number ,
12
+ _ethBlock : number ,
13
+ _chainBlocks : ChainBlocks
14
+ ) {
15
+ let balances = { } as Balances ;
16
+ for ( let issued of chainContracts [ chain ] . issued ) {
17
+ const totalSupply = (
18
+ await sdk . api . abi . call ( {
19
+ abi : "erc20:totalSupply" ,
20
+ target : issued ,
21
+ block : _chainBlocks ?. [ chain ] ,
22
+ chain : chain ,
23
+ } )
24
+ ) . output ;
25
+ sumSingleBalance (
26
+ balances ,
27
+ "peggedEUR" ,
28
+ totalSupply / 10 ** decimals ,
29
+ "issued" ,
30
+ false
31
+ ) ;
32
+ }
33
+ return balances ;
34
+ } ;
35
+ }
36
+
37
+ async function chainUnreleased ( chain : string , decimals : number , owner : string ) {
38
+ return async function (
39
+ _timestamp : number ,
40
+ _ethBlock : number ,
41
+ _chainBlocks : ChainBlocks
42
+ ) {
43
+ let balances = { } as Balances ;
44
+ for ( let issued of chainContracts [ chain ] . issued ) {
45
+ const reserve = (
46
+ await sdk . api . erc20 . balanceOf ( {
47
+ target : issued ,
48
+ owner : owner ,
49
+ block : _chainBlocks ?. [ chain ] ,
50
+ chain : chain ,
51
+ } )
30
52
) . output ;
31
- sumSingleBalance ( balances , "peggedEUR" , + value / 10 ** decimals , "issued" , false ) ;
32
- }
33
- return balances ;
34
- } ;
53
+ sumSingleBalance ( balances , "peggedEUR" , reserve / 10 ** decimals , "issued" , false ) ;
54
+ }
55
+ return balances ;
56
+ } ;
57
+ }
35
58
59
+ export function solanaMintedOrBridged (
60
+ targets : string [ ]
61
+ ) {
62
+ return async function (
63
+ _timestamp : number ,
64
+ _ethBlock : number ,
65
+ _chainBlocks : ChainBlocks
66
+ ) {
67
+ let balances = { } as Balances ;
68
+ for ( let target of targets ) {
69
+ const totalSupply = await solanaGetTokenSupply ( target ) ;
70
+ sumSingleBalance ( balances , "peggedEUR" , totalSupply , target , false ) ;
71
+ }
72
+ return balances ;
73
+ } ;
74
+ }
36
75
37
- const solanaUnreleased = async ( ) => {
38
- const balances : Balances = { } ;
39
- for ( const addr of chainContracts . solana . unreleased ) {
40
- const amount = await getTokenBalance ( chainContracts . solana . issued [ 0 ] , addr ) ;
41
- sumSingleBalance ( balances , "peggedEUR" , amount , addr , false ) ;
42
- }
43
- return balances ;
44
- } ;
76
+ async function solanaUnreleased ( ) {
77
+ return async function (
78
+ _timestamp : number ,
79
+ _ethBlock : number ,
80
+ _chainBlocks : ChainBlocks
81
+ ) {
82
+ let balances = { } as Balances ;
83
+ for ( let unreleasedAddress of chainContracts [ "solana" ] . unreleased ) {
84
+ sumSingleBalance ( balances , "peggedEUR" , await solanaGetTokenBalance (
85
+ chainContracts [ "solana" ] . issued [ 0 ] ,
86
+ unreleasedAddress
87
+ ) , unreleasedAddress , false ) ;
88
+ }
89
+ return balances ;
90
+ } ;
91
+ }
45
92
46
93
const adapter : PeggedIssuanceAdapter = {
47
- ethereum : {
48
- minted : getChainBalance ( "ethereum" , 18 , "minted" ) ,
49
- unreleased : getChainBalance ( "ethereum" , 18 , "unreleased" , chainContracts . ethereum . unreleased [ 0 ] ) ,
50
- } ,
51
- solana : {
52
- minted : solanaMintedOrBridged ( chainContracts . solana . issued , "peggedEUR" ) ,
53
- unreleased : ( ) => solanaUnreleased ( ) ,
54
- } ,
55
- } ;
94
+ ethereum : {
95
+ minted : chainMinted ( "ethereum" , 18 ) ,
96
+ unreleased : chainUnreleased (
97
+ "ethereum" ,
98
+ 18 ,
99
+ chainContracts . ethereum . unreleased [ 0 ]
100
+ ) ,
101
+ } ,
102
+ solana : {
103
+ minted : solanaMintedOrBridged ( chainContracts . solana . issued ) ,
104
+ unreleased : solanaUnreleased ( )
105
+ } ,
106
+ }
56
107
57
108
export default adapter ;
0 commit comments