-
Notifications
You must be signed in to change notification settings - Fork 3
/
osmo.js
170 lines (151 loc) · 4.44 KB
/
osmo.js
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
// API definition:
osmo = {
assetlist: async function() {},
wallet: {
balances: async function(wallet) {},
rewards: async function(wallet) {},
bondingDurations: async function(wallet) {},
pools: {
amounts: async function(wallet) {}
},
delegations: async function(wallet) {}
},
pool: {
amounts: async function(poolNumber) {},
gamm: async function(poolNumber) {}
},
helper: {
walletPoolAmounts: async function(wallet) {}
}
};
osmo.assetlist = async function() {
let ret = {};
await fetch('https://raw.githubusercontent.com/osmosis-labs/assetlists/main/osmosis-1/osmosis-1.assetlist.json')
.then(response => response.json())
.then((data) => {
ret = data;
});
return ret;
}
osmo.wallet.balances = async function(wallet) {
let ret = {};
await fetch('https://lcd-osmosis.keplr.app/bank/balances/' + wallet)
.then(response => response.json())
.then((data) => {
ret = data;
}).catch(error => {
ret = {
error: true
};
});
return ret;
};
osmo.wallet.delegations = async function(wallet) {
let ret = {};
await fetch('https://lcd-osmosis.keplr.app/staking/delegators/' + wallet + '/delegations')
.then(response => response.json())
.then((data) => {
ret = data;
}).catch(error => {
ret = {
error: true
};
});
return ret;
};
osmo.wallet.unbonding_delegations = async function(wallet) {
let ret = {};
await fetch('https://lcd-osmosis.keplr.app/staking/delegators/' + wallet + '/unbonding_delegations')
.then(response => response.json())
.then((data) => {
ret = data;
}).catch(error => {
ret = {
error: true
};
});
return ret;
};
osmo.wallet.locked = async function(wallet) {
let ret = {};
await fetch('https://lcd-osmosis.keplr.app/osmosis/lockup/v1beta1/account_locked_coins/' + wallet)
.then(response => response.json())
.then((data) => {
ret = data;
}).catch(error => {
ret = {
error: true
};
});
return ret;
};
osmo.wallet.rewards = async function(wallet) {
let ret = {};
await fetch('https://lcd-osmosis.keplr.app/osmosis/lockup/v1beta1/account_unlockable_coins/' + wallet)
.then(response => response.json())
.then((data) => {
ret = data;
});
return ret;
};
osmo.wallet.bondingDurations = async function(wallet) {
let ret = {};
await fetch('https://lcd-osmosis.keplr.app/osmosis/lockup/v1beta1/account_locked_longer_duration/' + wallet)
.then(response => response.json())
.then((data) => {
ret = data;
});
return ret;
};
osmo.wallet.pools.amounts = async function(wallet) {
let ret = {};
await fetch('https://lcd-osmosis.keplr.app/osmosis/lockup/v1beta1/account_locked_coins/' + wallet)
.then(response => response.json())
.then((data) => {
ret = data;
});
return ret;
};
osmo.wallet.delegations = async function(wallet) {
let ret = {};
await fetch('https://lcd-osmosis.keplr.app/staking/delegators/' + wallet + '/delegations')
.then(response => response.json())
.then((data) => {
ret = data;
});
return ret;
};
// TODO: do all requests asyncronously and wait for all responses before proceeding with calculation.
osmo.wallet.pools.balances = async function(wallet) {
let ret = {};
let walletPoolsAmounts = await osmo.wallet.pools.amounts(wallet);
// loop through wallet's pools, and then get those pool's token weightings
walletPoolsAmounts.coins.forEach(async (walletPoolShares, i) => {
let poolNumber = walletPoolShares.denom.substr(walletPoolShares.denom.lastIndexOf("/") + 1);
//let poolStats = await osmo.pool.stats(poolNumber);
let gamm = await osmo.pool.gamm(poolNumber);
// divide wallet shares by pool total shares to get share percentage.
let shareRatio = walletPoolShares.amount / gamm.pool.totalShares.amount;
//multiply share ratio by pool liquidity value to get wallet value
// let gamm.
});
return ret;
};
osmo.pool.stats = async function(poolNumber = "") {
let ret = {};
await fetch('https://api-osmosis.imperator.co/search/v1/pools/' + poolNumber)
.then(response => response.json())
.then((data) => {
ret = data;
});
return ret;
}
osmo.pool.gamm = async function(poolNumber = "") {
let ret = {};
await fetch('https://lcd-osmosis.keplr.app/osmosis/gamm/v1beta1/pools/' + poolNumber)
.then(response => response.json())
.then((data) => {
ret = data;
});
return ret;
}