forked from wormhole-foundation/wormhole
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtvl.ts
139 lines (122 loc) · 3.54 KB
/
tvl.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
const algosdk = require("@certusone/wormhole-sdk/node_modules/algosdk");
import { calcLogicSigAccount } from "@certusone/wormhole-sdk/lib/cjs/algorand";
import {
coalesceChainName,
ChainId,
coalesceChainId,
uint8ArrayToHex,
toChainName,
getOriginalAssetAlgorand,
CONTRACTS
} from "@certusone/wormhole-sdk";
export async function getNativeAlgoAddress(
algoClient: any,
token_bridge: any,
assetId: any
) {
const { doesExist, lsa } = await calcLogicSigAccount(
algoClient,
BigInt(token_bridge),
BigInt(assetId),
Buffer.from("native", "binary").toString("hex")
);
return lsa.address();
}
async function firstTransaction() {
let algodToken;
let algodServer;
let algodPort;
let server;
let port;
let token;
let appid;
const mainnet = true;
if (mainnet) {
appid = 842126029;
algodToken = "";
algodServer = "https://mainnet-api.algonode.cloud";
algodPort = 443;
server = "https://mainnet-idx.algonode.cloud";
port = 443;
token = "";
} else {
appid = CONTRACTS["DEVNET"].algorand.token_bridge;
algodToken =
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
algodServer = "http://localhost";
algodPort = 4001;
server = "http://localhost";
port = 8980;
token = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
}
let algodClient = new algosdk.Algodv2(algodToken, algodServer, algodPort);
let indexerClient = new algosdk.Indexer(token, server, port);
let addr = algosdk.getApplicationAddress(appid); // mainnet token bridge account
console.log(await algodClient.status().do());
//Check your balance
let accountInfo = await algodClient.accountInformation(addr).do();
console.log(accountInfo);
let ret = await indexerClient
.searchAccounts()
.authAddr(addr)
.applicationID(appid)
.do();
let wormholeAssets: any = [];
let nativeAssets: any = [];
while (true) {
ret["accounts"].forEach((x: any) => {
let amt = x["amount"];
if (x["assets"] != undefined) {
x["assets"].forEach((a: any) => {
if (x["created-assets"] != undefined) {
wormholeAssets.push(a);
} else {
nativeAssets.push(a);
}
});
}
});
if (ret["next-token"] == undefined) {
break;
}
ret = await indexerClient
.searchAccounts()
.authAddr(addr)
.applicationID(appid)
.nextToken(ret["next-token"])
.do();
}
let nativeAlgoAddr = await getNativeAlgoAddress(algodClient, appid, 0);
let algoInfo = await algodClient.accountInformation(nativeAlgoAddr).do();
console.log("ALGO locked: " + (algoInfo["amount"] - 1002001));
console.log("wormhole assets (bridged in)");
for (let i = 0; i < wormholeAssets.length; i++) {
let orig = await getOriginalAssetAlgorand(
algodClient,
BigInt(appid),
wormholeAssets[i]["asset-id"]
);
let v = [
coalesceChainName(orig["chainId"]),
uint8ArrayToHex(orig["assetAddress"]),
wormholeAssets[i],
await algodClient.getAssetByID(wormholeAssets[i]["asset-id"]).do(),
];
console.log(v);
}
console.log("native assets");
for (let i = 0; i < nativeAssets.length; i++) {
console.log(nativeAssets[i]);
console.log(
await algodClient.getAssetByID(nativeAssets[i]["asset-id"]).do()
);
let addr = await getNativeAlgoAddress(
algodClient,
appid,
nativeAssets[i]["asset-id"]
);
algoInfo = await algodClient.accountInformation(addr).do();
console.log(algoInfo);
}
}
firstTransaction();