@xyo-network/uniswap-v3-crypto-market-plugin 3.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +165 -0
- package/README.md +13 -0
- package/dist/neutral/index.mjs +270 -0
- package/dist/neutral/index.mjs.map +1 -0
- package/dist/types/Config.d.ts +7 -0
- package/dist/types/Config.d.ts.map +1 -0
- package/dist/types/Plugin.d.ts +15 -0
- package/dist/types/Plugin.d.ts.map +1 -0
- package/dist/types/Witness.d.ts +19 -0
- package/dist/types/Witness.d.ts.map +1 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/lib/UniSwap3Pair.d.ts +39 -0
- package/dist/types/lib/UniSwap3Pair.d.ts.map +1 -0
- package/dist/types/lib/Uniswap3PoolSlot0Wrapper.d.ts +13 -0
- package/dist/types/lib/Uniswap3PoolSlot0Wrapper.d.ts.map +1 -0
- package/dist/types/lib/UniswapPoolContracts.d.ts +2 -0
- package/dist/types/lib/UniswapPoolContracts.d.ts.map +1 -0
- package/dist/types/lib/UniswapV3Slot0Fields.d.ts +3 -0
- package/dist/types/lib/UniswapV3Slot0Fields.d.ts.map +1 -0
- package/dist/types/lib/createUniswapPoolContracts.d.ts +4 -0
- package/dist/types/lib/createUniswapPoolContracts.d.ts.map +1 -0
- package/dist/types/lib/index.d.ts +7 -0
- package/dist/types/lib/index.d.ts.map +1 -0
- package/dist/types/lib/logErrors.d.ts +3 -0
- package/dist/types/lib/logErrors.d.ts.map +1 -0
- package/dist/types/lib/pricesFromUniswap3.d.ts +4 -0
- package/dist/types/lib/pricesFromUniswap3.d.ts.map +1 -0
- package/package.json +60 -0
- package/src/Config.ts +7 -0
- package/src/Plugin.ts +16 -0
- package/src/Witness.ts +56 -0
- package/src/index.ts +4 -0
- package/src/lib/UniSwap3Pair.ts +135 -0
- package/src/lib/Uniswap3PoolSlot0Wrapper.ts +36 -0
- package/src/lib/UniswapPoolContracts.ts +15 -0
- package/src/lib/UniswapV3Slot0Fields.ts +2 -0
- package/src/lib/createUniswapPoolContracts.ts +10 -0
- package/src/lib/index.ts +6 -0
- package/src/lib/logErrors.ts +17 -0
- package/src/lib/pricesFromUniswap3.ts +17 -0
- package/typedoc.json +5 -0
- package/xy.config.ts +10 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
GNU LESSER GENERAL PUBLIC LICENSE
|
|
2
|
+
Version 3, 29 June 2007
|
|
3
|
+
|
|
4
|
+
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
|
5
|
+
Everyone is permitted to copy and distribute verbatim copies
|
|
6
|
+
of this license document, but changing it is not allowed.
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
This version of the GNU Lesser General Public License incorporates
|
|
10
|
+
the terms and conditions of version 3 of the GNU General Public
|
|
11
|
+
License, supplemented by the additional permissions listed below.
|
|
12
|
+
|
|
13
|
+
0. Additional Definitions.
|
|
14
|
+
|
|
15
|
+
As used herein, "this License" refers to version 3 of the GNU Lesser
|
|
16
|
+
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
|
17
|
+
General Public License.
|
|
18
|
+
|
|
19
|
+
"The Library" refers to a covered work governed by this License,
|
|
20
|
+
other than an Application or a Combined Work as defined below.
|
|
21
|
+
|
|
22
|
+
An "Application" is any work that makes use of an interface provided
|
|
23
|
+
by the Library, but which is not otherwise based on the Library.
|
|
24
|
+
Defining a subclass of a class defined by the Library is deemed a mode
|
|
25
|
+
of using an interface provided by the Library.
|
|
26
|
+
|
|
27
|
+
A "Combined Work" is a work produced by combining or linking an
|
|
28
|
+
Application with the Library. The particular version of the Library
|
|
29
|
+
with which the Combined Work was made is also called the "Linked
|
|
30
|
+
Version".
|
|
31
|
+
|
|
32
|
+
The "Minimal Corresponding Source" for a Combined Work means the
|
|
33
|
+
Corresponding Source for the Combined Work, excluding any source code
|
|
34
|
+
for portions of the Combined Work that, considered in isolation, are
|
|
35
|
+
based on the Application, and not on the Linked Version.
|
|
36
|
+
|
|
37
|
+
The "Corresponding Application Code" for a Combined Work means the
|
|
38
|
+
object code and/or source code for the Application, including any data
|
|
39
|
+
and utility programs needed for reproducing the Combined Work from the
|
|
40
|
+
Application, but excluding the System Libraries of the Combined Work.
|
|
41
|
+
|
|
42
|
+
1. Exception to Section 3 of the GNU GPL.
|
|
43
|
+
|
|
44
|
+
You may convey a covered work under sections 3 and 4 of this License
|
|
45
|
+
without being bound by section 3 of the GNU GPL.
|
|
46
|
+
|
|
47
|
+
2. Conveying Modified Versions.
|
|
48
|
+
|
|
49
|
+
If you modify a copy of the Library, and, in your modifications, a
|
|
50
|
+
facility refers to a function or data to be supplied by an Application
|
|
51
|
+
that uses the facility (other than as an argument passed when the
|
|
52
|
+
facility is invoked), then you may convey a copy of the modified
|
|
53
|
+
version:
|
|
54
|
+
|
|
55
|
+
a) under this License, provided that you make a good faith effort to
|
|
56
|
+
ensure that, in the event an Application does not supply the
|
|
57
|
+
function or data, the facility still operates, and performs
|
|
58
|
+
whatever part of its purpose remains meaningful, or
|
|
59
|
+
|
|
60
|
+
b) under the GNU GPL, with none of the additional permissions of
|
|
61
|
+
this License applicable to that copy.
|
|
62
|
+
|
|
63
|
+
3. Object Code Incorporating Material from Library Header Files.
|
|
64
|
+
|
|
65
|
+
The object code form of an Application may incorporate material from
|
|
66
|
+
a header file that is part of the Library. You may convey such object
|
|
67
|
+
code under terms of your choice, provided that, if the incorporated
|
|
68
|
+
material is not limited to numerical parameters, data structure
|
|
69
|
+
layouts and accessors, or small macros, inline functions and templates
|
|
70
|
+
(ten or fewer lines in length), you do both of the following:
|
|
71
|
+
|
|
72
|
+
a) Give prominent notice with each copy of the object code that the
|
|
73
|
+
Library is used in it and that the Library and its use are
|
|
74
|
+
covered by this License.
|
|
75
|
+
|
|
76
|
+
b) Accompany the object code with a copy of the GNU GPL and this license
|
|
77
|
+
document.
|
|
78
|
+
|
|
79
|
+
4. Combined Works.
|
|
80
|
+
|
|
81
|
+
You may convey a Combined Work under terms of your choice that,
|
|
82
|
+
taken together, effectively do not restrict modification of the
|
|
83
|
+
portions of the Library contained in the Combined Work and reverse
|
|
84
|
+
engineering for debugging such modifications, if you also do each of
|
|
85
|
+
the following:
|
|
86
|
+
|
|
87
|
+
a) Give prominent notice with each copy of the Combined Work that
|
|
88
|
+
the Library is used in it and that the Library and its use are
|
|
89
|
+
covered by this License.
|
|
90
|
+
|
|
91
|
+
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
|
92
|
+
document.
|
|
93
|
+
|
|
94
|
+
c) For a Combined Work that displays copyright notices during
|
|
95
|
+
execution, include the copyright notice for the Library among
|
|
96
|
+
these notices, as well as a reference directing the user to the
|
|
97
|
+
copies of the GNU GPL and this license document.
|
|
98
|
+
|
|
99
|
+
d) Do one of the following:
|
|
100
|
+
|
|
101
|
+
0) Convey the Minimal Corresponding Source under the terms of this
|
|
102
|
+
License, and the Corresponding Application Code in a form
|
|
103
|
+
suitable for, and under terms that permit, the user to
|
|
104
|
+
recombine or relink the Application with a modified version of
|
|
105
|
+
the Linked Version to produce a modified Combined Work, in the
|
|
106
|
+
manner specified by section 6 of the GNU GPL for conveying
|
|
107
|
+
Corresponding Source.
|
|
108
|
+
|
|
109
|
+
1) Use a suitable shared library mechanism for linking with the
|
|
110
|
+
Library. A suitable mechanism is one that (a) uses at run time
|
|
111
|
+
a copy of the Library already present on the user's computer
|
|
112
|
+
system, and (b) will operate properly with a modified version
|
|
113
|
+
of the Library that is interface-compatible with the Linked
|
|
114
|
+
Version.
|
|
115
|
+
|
|
116
|
+
e) Provide Installation Information, but only if you would otherwise
|
|
117
|
+
be required to provide such information under section 6 of the
|
|
118
|
+
GNU GPL, and only to the extent that such information is
|
|
119
|
+
necessary to install and execute a modified version of the
|
|
120
|
+
Combined Work produced by recombining or relinking the
|
|
121
|
+
Application with a modified version of the Linked Version. (If
|
|
122
|
+
you use option 4d0, the Installation Information must accompany
|
|
123
|
+
the Minimal Corresponding Source and Corresponding Application
|
|
124
|
+
Code. If you use option 4d1, you must provide the Installation
|
|
125
|
+
Information in the manner specified by section 6 of the GNU GPL
|
|
126
|
+
for conveying Corresponding Source.)
|
|
127
|
+
|
|
128
|
+
5. Combined Libraries.
|
|
129
|
+
|
|
130
|
+
You may place library facilities that are a work based on the
|
|
131
|
+
Library side by side in a single library together with other library
|
|
132
|
+
facilities that are not Applications and are not covered by this
|
|
133
|
+
License, and convey such a combined library under terms of your
|
|
134
|
+
choice, if you do both of the following:
|
|
135
|
+
|
|
136
|
+
a) Accompany the combined library with a copy of the same work based
|
|
137
|
+
on the Library, uncombined with any other library facilities,
|
|
138
|
+
conveyed under the terms of this License.
|
|
139
|
+
|
|
140
|
+
b) Give prominent notice with the combined library that part of it
|
|
141
|
+
is a work based on the Library, and explaining where to find the
|
|
142
|
+
accompanying uncombined form of the same work.
|
|
143
|
+
|
|
144
|
+
6. Revised Versions of the GNU Lesser General Public License.
|
|
145
|
+
|
|
146
|
+
The Free Software Foundation may publish revised and/or new versions
|
|
147
|
+
of the GNU Lesser General Public License from time to time. Such new
|
|
148
|
+
versions will be similar in spirit to the present version, but may
|
|
149
|
+
differ in detail to address new problems or concerns.
|
|
150
|
+
|
|
151
|
+
Each version is given a distinguishing version number. If the
|
|
152
|
+
Library as you received it specifies that a certain numbered version
|
|
153
|
+
of the GNU Lesser General Public License "or any later version"
|
|
154
|
+
applies to it, you have the option of following the terms and
|
|
155
|
+
conditions either of that published version or of any later version
|
|
156
|
+
published by the Free Software Foundation. If the Library as you
|
|
157
|
+
received it does not specify a version number of the GNU Lesser
|
|
158
|
+
General Public License, you may choose any version of the GNU Lesser
|
|
159
|
+
General Public License ever published by the Free Software Foundation.
|
|
160
|
+
|
|
161
|
+
If the Library as you received it specifies that a proxy can decide
|
|
162
|
+
whether future versions of the GNU Lesser General Public License shall
|
|
163
|
+
apply, that proxy's public statement of acceptance of any version is
|
|
164
|
+
permanent authorization for you to choose that version for the
|
|
165
|
+
Library.
|
package/README.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
[![logo][]](https://xyo.network)
|
|
2
|
+
|
|
3
|
+
Part of [sdk-xyo-client-js](https://www.npmjs.com/package/@xyo-network/sdk-xyo-client-js)
|
|
4
|
+
|
|
5
|
+
## License
|
|
6
|
+
|
|
7
|
+
> See the [LICENSE](LICENSE) file for license details
|
|
8
|
+
|
|
9
|
+
## Credits
|
|
10
|
+
|
|
11
|
+
[Made with 🔥 and ❄️ by XYO](https://xyo.network)
|
|
12
|
+
|
|
13
|
+
[logo]: https://cdn.xy.company/img/brand/XYO_full_colored.png
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
// src/lib/logErrors.ts
|
|
2
|
+
var logErrors = (func) => {
|
|
3
|
+
try {
|
|
4
|
+
return func();
|
|
5
|
+
} catch (ex) {
|
|
6
|
+
console.error(ex);
|
|
7
|
+
throw ex;
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
var logErrorsAsync = async (func) => {
|
|
11
|
+
try {
|
|
12
|
+
return await func();
|
|
13
|
+
} catch (ex) {
|
|
14
|
+
console.error(ex);
|
|
15
|
+
throw ex;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
// src/lib/UniSwap3Pair.ts
|
|
20
|
+
import { Token } from "@uniswap/sdk-core";
|
|
21
|
+
import { Pool } from "@uniswap/v3-sdk";
|
|
22
|
+
import { assertEx } from "@xylabs/assert";
|
|
23
|
+
import { delay } from "@xylabs/delay";
|
|
24
|
+
import { Enum } from "@xylabs/enum";
|
|
25
|
+
import { IERC20Metadata__factory } from "@xyo-network/open-zeppelin-typechain";
|
|
26
|
+
import { IUniswapV3Pool__factory } from "@xyo-network/uniswap-typechain";
|
|
27
|
+
|
|
28
|
+
// src/lib/Uniswap3PoolSlot0Wrapper.ts
|
|
29
|
+
var EthersUniswap3PoolSlot0Wrapper = class {
|
|
30
|
+
values;
|
|
31
|
+
constructor(values) {
|
|
32
|
+
this.values = values;
|
|
33
|
+
}
|
|
34
|
+
get feeProtocol() {
|
|
35
|
+
return this.values[5];
|
|
36
|
+
}
|
|
37
|
+
get observationCardinality() {
|
|
38
|
+
return this.values[3];
|
|
39
|
+
}
|
|
40
|
+
get observationCardinalityNext() {
|
|
41
|
+
return this.values[4];
|
|
42
|
+
}
|
|
43
|
+
get observationIndex() {
|
|
44
|
+
return this.values[2];
|
|
45
|
+
}
|
|
46
|
+
get sqrtPriceX96() {
|
|
47
|
+
return this.values[0];
|
|
48
|
+
}
|
|
49
|
+
get tick() {
|
|
50
|
+
return this.values[1];
|
|
51
|
+
}
|
|
52
|
+
get unlocked() {
|
|
53
|
+
return this.values[6];
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
// src/lib/UniSwap3Pair.ts
|
|
58
|
+
var ChainId = Enum({
|
|
59
|
+
MAINNET: 1,
|
|
60
|
+
ROPSTEN: 3,
|
|
61
|
+
RINKEBY: 4,
|
|
62
|
+
G\u00D6RLI: 5,
|
|
63
|
+
KOVAN: 42
|
|
64
|
+
});
|
|
65
|
+
var waitNotNull = async (closure) => {
|
|
66
|
+
while (closure() === null) await delay(10);
|
|
67
|
+
};
|
|
68
|
+
var EthersUniSwap3Pair = class {
|
|
69
|
+
address;
|
|
70
|
+
provider;
|
|
71
|
+
_pool;
|
|
72
|
+
_poolContract;
|
|
73
|
+
_slot0;
|
|
74
|
+
_tokenContracts = [void 0, void 0];
|
|
75
|
+
_tokens = [void 0, void 0];
|
|
76
|
+
constructor(address, provider) {
|
|
77
|
+
this.address = address;
|
|
78
|
+
this.provider = provider;
|
|
79
|
+
}
|
|
80
|
+
async pool() {
|
|
81
|
+
return await logErrorsAsync(async () => {
|
|
82
|
+
await waitNotNull(() => this._pool);
|
|
83
|
+
this._pool = this._pool || null;
|
|
84
|
+
const slot0 = await this.slot0();
|
|
85
|
+
this._pool = this._pool === null ? new Pool(
|
|
86
|
+
await this.token(0),
|
|
87
|
+
await this.token(1),
|
|
88
|
+
Number(slot0.feeProtocol),
|
|
89
|
+
`0x${slot0.sqrtPriceX96.toString(16)}`,
|
|
90
|
+
`0x${(await this.poolContract().liquidity()).toString(16)}`,
|
|
91
|
+
Number(slot0.tick)
|
|
92
|
+
) : this._pool;
|
|
93
|
+
return assertEx(this._pool);
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
poolContract() {
|
|
97
|
+
return logErrors(() => {
|
|
98
|
+
this._poolContract = this._poolContract ?? IUniswapV3Pool__factory.connect(this.address, this.provider);
|
|
99
|
+
return assertEx(this._poolContract);
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
async price() {
|
|
103
|
+
return await logErrorsAsync(async () => {
|
|
104
|
+
const tokenIndexes = [0, 1];
|
|
105
|
+
const pool = await this.pool();
|
|
106
|
+
const tokens = await Promise.all(tokenIndexes.map((value) => this.token(value)));
|
|
107
|
+
const tokenContracts = await Promise.all(tokenIndexes.map((value) => this.tokenContract(value)));
|
|
108
|
+
const tokenPrices = tokens.map((token) => Number.parseFloat(pool.priceOf(token).toSignificant()));
|
|
109
|
+
const tokenSymbols = tokens.map((token, index) => assertEx(token.symbol, () => `Token[${index}] Missing Symbols`).toLowerCase());
|
|
110
|
+
const result = {
|
|
111
|
+
tokens: await Promise.all(
|
|
112
|
+
tokenIndexes.map(async (value) => {
|
|
113
|
+
return {
|
|
114
|
+
address: await tokenContracts[value].getAddress(),
|
|
115
|
+
symbol: tokenSymbols[value],
|
|
116
|
+
value: tokenPrices[value]
|
|
117
|
+
};
|
|
118
|
+
})
|
|
119
|
+
)
|
|
120
|
+
};
|
|
121
|
+
return result;
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
async slot0() {
|
|
125
|
+
return await logErrorsAsync(async () => {
|
|
126
|
+
await waitNotNull(() => this._slot0);
|
|
127
|
+
this._slot0 = this._slot0 || null;
|
|
128
|
+
if (this._slot0 === null) {
|
|
129
|
+
const poolContract = this.poolContract();
|
|
130
|
+
const slot = await poolContract.slot0();
|
|
131
|
+
this._slot0 = this._slot0 ?? new EthersUniswap3PoolSlot0Wrapper(slot);
|
|
132
|
+
}
|
|
133
|
+
return assertEx(this._slot0);
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
async token(index) {
|
|
137
|
+
return await logErrorsAsync(async () => {
|
|
138
|
+
await waitNotNull(() => this._tokens[index]);
|
|
139
|
+
this._tokens[index] = this._tokens[index] || null;
|
|
140
|
+
const tokenContract = await this.tokenContract(index);
|
|
141
|
+
this._tokens[index] = this._tokens[index] ?? new Token(
|
|
142
|
+
ChainId.MAINNET,
|
|
143
|
+
await tokenContract.getAddress(),
|
|
144
|
+
Number(await tokenContract.decimals()),
|
|
145
|
+
await tokenContract.symbol(),
|
|
146
|
+
await tokenContract.name()
|
|
147
|
+
);
|
|
148
|
+
return assertEx(this._tokens[index]);
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
async tokenContract(index) {
|
|
152
|
+
return await logErrorsAsync(async () => {
|
|
153
|
+
await waitNotNull(() => this._tokenContracts[index]);
|
|
154
|
+
this._tokenContracts[index] = this._tokenContracts[index] || null;
|
|
155
|
+
this._tokenContracts[index] = this._tokenContracts[index] ?? IERC20Metadata__factory.connect(await (index === 0 ? this.poolContract().token0() : this.poolContract().token1()), this.provider);
|
|
156
|
+
return assertEx(this._tokenContracts[index]);
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
// src/lib/createUniswapPoolContracts.ts
|
|
162
|
+
var createUniswapPoolContracts = (provider, contracts) => {
|
|
163
|
+
return logErrors(() => {
|
|
164
|
+
return contracts.map((contract) => new EthersUniSwap3Pair(contract, provider));
|
|
165
|
+
});
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
// src/lib/pricesFromUniswap3.ts
|
|
169
|
+
import { fulfilled } from "@xylabs/promise";
|
|
170
|
+
var pricesFromUniswap3 = async (pools) => {
|
|
171
|
+
return await logErrorsAsync(async () => {
|
|
172
|
+
const promiseResults = await Promise.allSettled(
|
|
173
|
+
pools.map(async (pool) => {
|
|
174
|
+
const result = await pool.price();
|
|
175
|
+
return result;
|
|
176
|
+
})
|
|
177
|
+
);
|
|
178
|
+
return promiseResults.filter(fulfilled).map((result) => result.value);
|
|
179
|
+
});
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
// src/lib/UniswapPoolContracts.ts
|
|
183
|
+
var UniswapPoolContracts = [
|
|
184
|
+
/* xyo/weth */
|
|
185
|
+
"0xE331DE28cd81B768C19A366b0e4e4675c45eC2dA",
|
|
186
|
+
/* xyo/usdt */
|
|
187
|
+
"0xd0AF1981f52146a6939385451dAeA0726e13a484",
|
|
188
|
+
/* xyo/dai */
|
|
189
|
+
"0x9D7e5647CE3c7C2d835F2F5e82C8fDb36B0BB0fe",
|
|
190
|
+
/* wbtc/xyo */
|
|
191
|
+
"0x0cF7494c9dE661467403aBeE8454b3BBf0179a84",
|
|
192
|
+
/* link/xyo */
|
|
193
|
+
"0x4693456599a8a4975862A0E720C5de7E1D09A1e4",
|
|
194
|
+
/* wbtc/weth */
|
|
195
|
+
"0xCBCdF9626bC03E24f779434178A73a0B4bad62eD",
|
|
196
|
+
/* dai/usdc */
|
|
197
|
+
"0x5777d92f208679DB4b9778590Fa3CAB3aC9e2168",
|
|
198
|
+
/* usdc/weth */
|
|
199
|
+
"0x8ad599c3A0ff1De082011EFDDc58f1908eb6e6D8",
|
|
200
|
+
/* usdc/weth */
|
|
201
|
+
"0x88e6A0c2dDD26FEEb64F039a2c41296FcB3f5640",
|
|
202
|
+
/* dai/usdc */
|
|
203
|
+
"0x6c6Bc977E13Df9b0de53b251522280BB72383700",
|
|
204
|
+
/* frax/usdc */
|
|
205
|
+
"0xc63B0708E2F7e69CB8A1df0e1389A98C35A76D52",
|
|
206
|
+
/* wbtc/usdc */
|
|
207
|
+
"0x99ac8cA7087fA4A2A1FB6357269965A2014ABc35",
|
|
208
|
+
/* usdc/usdt */
|
|
209
|
+
"0x3416cF6C708Da44DB2624D63ea0AAef7113527C6"
|
|
210
|
+
];
|
|
211
|
+
|
|
212
|
+
// src/Plugin.ts
|
|
213
|
+
import { PayloadSetSchema } from "@xyo-network/payload-model";
|
|
214
|
+
import { createPayloadSetWitnessPlugin } from "@xyo-network/payloadset-plugin";
|
|
215
|
+
import { UniswapCryptoMarketSchema as UniswapCryptoMarketSchema2 } from "@xyo-network/uniswap-crypto-market-payload-plugin";
|
|
216
|
+
|
|
217
|
+
// src/Witness.ts
|
|
218
|
+
import { assertEx as assertEx2 } from "@xylabs/assert";
|
|
219
|
+
import { AbstractWitness } from "@xyo-network/abstract-witness";
|
|
220
|
+
import { UniswapCryptoMarketSchema, UniswapCryptoMarketWitnessConfigSchema } from "@xyo-network/uniswap-crypto-market-payload-plugin";
|
|
221
|
+
var UniswapCryptoMarketWitness = class extends AbstractWitness {
|
|
222
|
+
static configSchemas = [...super.configSchemas, UniswapCryptoMarketWitnessConfigSchema];
|
|
223
|
+
static defaultConfigSchema = UniswapCryptoMarketWitnessConfigSchema;
|
|
224
|
+
pairs;
|
|
225
|
+
get provider() {
|
|
226
|
+
return this.params.provider;
|
|
227
|
+
}
|
|
228
|
+
async observeHandler() {
|
|
229
|
+
await this.started("throw");
|
|
230
|
+
const pairs = await pricesFromUniswap3(assertEx2(this.pairs));
|
|
231
|
+
const timestamp = Date.now();
|
|
232
|
+
const payload = {
|
|
233
|
+
pairs,
|
|
234
|
+
schema: UniswapCryptoMarketSchema,
|
|
235
|
+
timestamp
|
|
236
|
+
};
|
|
237
|
+
return [payload];
|
|
238
|
+
}
|
|
239
|
+
async startHandler() {
|
|
240
|
+
await super.startHandler();
|
|
241
|
+
this.pairs = createUniswapPoolContracts(
|
|
242
|
+
assertEx2(this.provider, () => "Provider Required"),
|
|
243
|
+
this.config?.pools ?? UniswapPoolContracts
|
|
244
|
+
);
|
|
245
|
+
return true;
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
// src/Plugin.ts
|
|
250
|
+
var UniswapCryptoMarketPlugin = () => createPayloadSetWitnessPlugin(
|
|
251
|
+
{ required: { [UniswapCryptoMarketSchema2]: 1 }, schema: PayloadSetSchema },
|
|
252
|
+
{
|
|
253
|
+
witness: async (params) => {
|
|
254
|
+
const result = await UniswapCryptoMarketWitness.create(params);
|
|
255
|
+
return result;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
);
|
|
259
|
+
export {
|
|
260
|
+
ChainId,
|
|
261
|
+
EthersUniSwap3Pair,
|
|
262
|
+
EthersUniswap3PoolSlot0Wrapper,
|
|
263
|
+
UniswapCryptoMarketPlugin,
|
|
264
|
+
UniswapCryptoMarketWitness,
|
|
265
|
+
UniswapPoolContracts,
|
|
266
|
+
createUniswapPoolContracts,
|
|
267
|
+
UniswapCryptoMarketPlugin as default,
|
|
268
|
+
pricesFromUniswap3
|
|
269
|
+
};
|
|
270
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/lib/logErrors.ts","../../src/lib/UniSwap3Pair.ts","../../src/lib/Uniswap3PoolSlot0Wrapper.ts","../../src/lib/createUniswapPoolContracts.ts","../../src/lib/pricesFromUniswap3.ts","../../src/lib/UniswapPoolContracts.ts","../../src/Plugin.ts","../../src/Witness.ts"],"sourcesContent":["export const logErrors = <T>(func: () => T) => {\n try {\n return func()\n } catch (ex) {\n console.error(ex)\n throw ex\n }\n}\n\nexport const logErrorsAsync = async <T>(func: () => Promise<T>) => {\n try {\n return await func()\n } catch (ex) {\n console.error(ex)\n throw ex\n }\n}\n","import { Token } from '@uniswap/sdk-core'\nimport { Pool } from '@uniswap/v3-sdk'\nimport { assertEx } from '@xylabs/assert'\nimport { delay } from '@xylabs/delay'\nimport type { EnumValue } from '@xylabs/enum'\nimport { Enum } from '@xylabs/enum'\nimport type { IERC20Metadata } from '@xyo-network/open-zeppelin-typechain'\nimport { IERC20Metadata__factory } from '@xyo-network/open-zeppelin-typechain'\nimport type { IUniswapV3Pool } from '@xyo-network/uniswap-typechain'\nimport { IUniswapV3Pool__factory } from '@xyo-network/uniswap-typechain'\nimport type { Provider } from 'ethers'\n\nimport { logErrors, logErrorsAsync } from './logErrors.ts'\nimport { EthersUniswap3PoolSlot0Wrapper } from './Uniswap3PoolSlot0Wrapper.ts'\n\nexport const ChainId = Enum({\n MAINNET: 1,\n ROPSTEN: 3,\n RINKEBY: 4,\n GÖRLI: 5,\n KOVAN: 42,\n})\n\nexport type ChainId = EnumValue<typeof ChainId>\n\n// null is used as 'in-progress'\nconst waitNotNull = async (closure: () => unknown) => {\n while (closure() === null) await delay(10)\n}\n\nexport class EthersUniSwap3Pair {\n protected address: string\n protected provider: Provider\n\n private _pool?: Pool | null\n private _poolContract?: IUniswapV3Pool\n private _slot0?: EthersUniswap3PoolSlot0Wrapper | null\n private _tokenContracts: (IERC20Metadata | null | undefined)[] = [undefined, undefined]\n private _tokens: (Token | null | undefined)[] = [undefined, undefined]\n\n constructor(address: string, provider: Provider) {\n this.address = address\n this.provider = provider\n }\n\n async pool(): Promise<Pool> {\n return await logErrorsAsync(async () => {\n await waitNotNull(() => this._pool)\n this._pool = this._pool || null\n const slot0 = await this.slot0()\n this._pool\n = this._pool === null\n ? new Pool(\n await this.token(0),\n await this.token(1),\n Number(slot0.feeProtocol),\n `0x${slot0.sqrtPriceX96.toString(16)}`,\n `0x${(await this.poolContract().liquidity()).toString(16)}`,\n Number(slot0.tick),\n )\n : this._pool\n return assertEx(this._pool)\n })\n }\n\n poolContract() {\n return logErrors(() => {\n this._poolContract = this._poolContract ?? IUniswapV3Pool__factory.connect(this.address, this.provider)\n return assertEx(this._poolContract)\n })\n }\n\n async price() {\n return await logErrorsAsync(async () => {\n const tokenIndexes: (0 | 1)[] = [0, 1]\n const pool = await this.pool()\n const tokens = await Promise.all(tokenIndexes.map(value => this.token(value)))\n const tokenContracts = await Promise.all(tokenIndexes.map(value => this.tokenContract(value)))\n const tokenPrices = tokens.map(token => Number.parseFloat(pool.priceOf(token).toSignificant()))\n const tokenSymbols = tokens.map((token, index) => assertEx(token.symbol, () => `Token[${index}] Missing Symbols`).toLowerCase())\n const result = {\n tokens: await Promise.all(\n tokenIndexes.map(async (value) => {\n return {\n address: await tokenContracts[value].getAddress(), symbol: tokenSymbols[value], value: tokenPrices[value],\n }\n }),\n ),\n }\n return result\n })\n }\n\n async slot0(): Promise<EthersUniswap3PoolSlot0Wrapper> {\n return await logErrorsAsync(async () => {\n await waitNotNull(() => this._slot0)\n this._slot0 = this._slot0 || null\n if (this._slot0 === null) {\n const poolContract = this.poolContract()\n const slot = await poolContract.slot0()\n this._slot0 = this._slot0 ?? new EthersUniswap3PoolSlot0Wrapper(slot)\n }\n return assertEx(this._slot0)\n })\n }\n\n async token(index: 0 | 1): Promise<Token> {\n return await logErrorsAsync(async () => {\n await waitNotNull(() => this._tokens[index])\n this._tokens[index] = this._tokens[index] || null\n const tokenContract = await this.tokenContract(index)\n this._tokens[index]\n = this._tokens[index]\n ?? new Token(\n ChainId.MAINNET,\n await tokenContract.getAddress(),\n Number(await tokenContract.decimals()),\n await tokenContract.symbol(),\n await tokenContract.name(),\n )\n return assertEx(this._tokens[index])\n })\n }\n\n async tokenContract(index: 0 | 1): Promise<IERC20Metadata> {\n return await logErrorsAsync(async () => {\n await waitNotNull(() => this._tokenContracts[index])\n this._tokenContracts[index] = this._tokenContracts[index] || null\n this._tokenContracts[index]\n = this._tokenContracts[index]\n ?? IERC20Metadata__factory.connect(await (index === 0 ? this.poolContract().token0() : this.poolContract().token1()), this.provider)\n return assertEx(this._tokenContracts[index])\n })\n }\n}\n","import type { EthersUniswapV3Slot0Fields } from './UniswapV3Slot0Fields.ts'\n\nexport class EthersUniswap3PoolSlot0Wrapper {\n protected values: EthersUniswapV3Slot0Fields\n constructor(values: EthersUniswapV3Slot0Fields) {\n this.values = values\n }\n\n get feeProtocol() {\n return this.values[5]\n }\n\n get observationCardinality() {\n return this.values[3]\n }\n\n get observationCardinalityNext() {\n return this.values[4]\n }\n\n get observationIndex() {\n return this.values[2]\n }\n\n get sqrtPriceX96() {\n return this.values[0]\n }\n\n get tick() {\n return this.values[1]\n }\n\n get unlocked() {\n return this.values[6]\n }\n}\n","import type { Provider } from 'ethers'\n\nimport { logErrors } from './logErrors.ts'\nimport { EthersUniSwap3Pair } from './UniSwap3Pair.ts'\n\nexport const createUniswapPoolContracts = (provider: Provider, contracts: string[]) => {\n return logErrors(() => {\n return contracts.map(contract => new EthersUniSwap3Pair(contract, provider))\n })\n}\n","import { fulfilled } from '@xylabs/promise'\nimport type { UniswapCryptoPair } from '@xyo-network/uniswap-crypto-market-payload-plugin'\n\nimport type { EthersUniSwap3Pair } from './index.ts'\nimport { logErrorsAsync } from './logErrors.ts'\n\nexport const pricesFromUniswap3 = async (pools: EthersUniSwap3Pair[]): Promise<UniswapCryptoPair[]> => {\n return await logErrorsAsync(async () => {\n const promiseResults = await Promise.allSettled(\n pools.map(async (pool): Promise<UniswapCryptoPair> => {\n const result = await pool.price()\n return result\n }),\n )\n return promiseResults.filter(fulfilled).map(result => result.value)\n })\n}\n","export const UniswapPoolContracts = [\n /* xyo/weth */ '0xE331DE28cd81B768C19A366b0e4e4675c45eC2dA',\n /* xyo/usdt */ '0xd0AF1981f52146a6939385451dAeA0726e13a484',\n /* xyo/dai */ '0x9D7e5647CE3c7C2d835F2F5e82C8fDb36B0BB0fe',\n /* wbtc/xyo */ '0x0cF7494c9dE661467403aBeE8454b3BBf0179a84',\n /* link/xyo */ '0x4693456599a8a4975862A0E720C5de7E1D09A1e4',\n /* wbtc/weth */ '0xCBCdF9626bC03E24f779434178A73a0B4bad62eD',\n /* dai/usdc */ '0x5777d92f208679DB4b9778590Fa3CAB3aC9e2168',\n /* usdc/weth */ '0x8ad599c3A0ff1De082011EFDDc58f1908eb6e6D8',\n /* usdc/weth */ '0x88e6A0c2dDD26FEEb64F039a2c41296FcB3f5640',\n /* dai/usdc */ '0x6c6Bc977E13Df9b0de53b251522280BB72383700',\n /* frax/usdc */ '0xc63B0708E2F7e69CB8A1df0e1389A98C35A76D52',\n /* wbtc/usdc */ '0x99ac8cA7087fA4A2A1FB6357269965A2014ABc35',\n /* usdc/usdt */ '0x3416cF6C708Da44DB2624D63ea0AAef7113527C6',\n]\n","import { PayloadSetSchema } from '@xyo-network/payload-model'\nimport { createPayloadSetWitnessPlugin } from '@xyo-network/payloadset-plugin'\nimport { UniswapCryptoMarketSchema } from '@xyo-network/uniswap-crypto-market-payload-plugin'\n\nimport { UniswapCryptoMarketWitness } from './Witness.ts'\n\nexport const UniswapCryptoMarketPlugin = () =>\n createPayloadSetWitnessPlugin<UniswapCryptoMarketWitness>(\n { required: { [UniswapCryptoMarketSchema]: 1 }, schema: PayloadSetSchema },\n {\n witness: async (params) => {\n const result = await UniswapCryptoMarketWitness.create(params)\n return result\n },\n },\n )\n","import { assertEx } from '@xylabs/assert'\nimport { AbstractWitness } from '@xyo-network/abstract-witness'\nimport type { AnyConfigSchema } from '@xyo-network/module-model'\nimport type { Payload, Schema } from '@xyo-network/payload-model'\nimport type { UniswapCryptoMarketPayload } from '@xyo-network/uniswap-crypto-market-payload-plugin'\nimport { UniswapCryptoMarketSchema, UniswapCryptoMarketWitnessConfigSchema } from '@xyo-network/uniswap-crypto-market-payload-plugin'\nimport type { WitnessParams } from '@xyo-network/witness-model'\nimport type { Provider } from 'ethers'\n\nimport type { UniswapCryptoMarketWitnessConfig } from './Config.ts'\nimport type { EthersUniSwap3Pair } from './lib/index.ts'\nimport {\n createUniswapPoolContracts, pricesFromUniswap3, UniswapPoolContracts,\n} from './lib/index.ts'\n\nexport type UniswapCryptoMarketWitnessParams = WitnessParams<\n AnyConfigSchema<UniswapCryptoMarketWitnessConfig>,\n {\n provider?: Provider\n }\n>\n\nexport class UniswapCryptoMarketWitness<\n TParams extends UniswapCryptoMarketWitnessParams = UniswapCryptoMarketWitnessParams,\n> extends AbstractWitness<TParams> {\n static override readonly configSchemas: Schema[] = [...super.configSchemas, UniswapCryptoMarketWitnessConfigSchema]\n static override readonly defaultConfigSchema: Schema = UniswapCryptoMarketWitnessConfigSchema\n\n protected pairs?: EthersUniSwap3Pair[]\n protected get provider() {\n return this.params.provider\n }\n\n protected override async observeHandler(): Promise<Payload[]> {\n await this.started('throw')\n const pairs = await pricesFromUniswap3(assertEx(this.pairs))\n const timestamp = Date.now()\n\n const payload: UniswapCryptoMarketPayload = {\n pairs,\n schema: UniswapCryptoMarketSchema,\n timestamp,\n }\n\n return [payload]\n }\n\n protected override async startHandler() {\n await super.startHandler()\n this.pairs = createUniswapPoolContracts(\n assertEx(this.provider, () => 'Provider Required'),\n this.config?.pools ?? UniswapPoolContracts,\n )\n return true\n }\n}\n"],"mappings":";AAAO,IAAM,YAAY,CAAI,SAAkB;AAC7C,MAAI;AACF,WAAO,KAAK;AAAA,EACd,SAAS,IAAI;AACX,YAAQ,MAAM,EAAE;AAChB,UAAM;AAAA,EACR;AACF;AAEO,IAAM,iBAAiB,OAAU,SAA2B;AACjE,MAAI;AACF,WAAO,MAAM,KAAK;AAAA,EACpB,SAAS,IAAI;AACX,YAAQ,MAAM,EAAE;AAChB,UAAM;AAAA,EACR;AACF;;;AChBA,SAAS,aAAa;AACtB,SAAS,YAAY;AACrB,SAAS,gBAAgB;AACzB,SAAS,aAAa;AAEtB,SAAS,YAAY;AAErB,SAAS,+BAA+B;AAExC,SAAS,+BAA+B;;;ACPjC,IAAM,iCAAN,MAAqC;AAAA,EAChC;AAAA,EACV,YAAY,QAAoC;AAC9C,SAAK,SAAS;AAAA,EAChB;AAAA,EAEA,IAAI,cAAc;AAChB,WAAO,KAAK,OAAO,CAAC;AAAA,EACtB;AAAA,EAEA,IAAI,yBAAyB;AAC3B,WAAO,KAAK,OAAO,CAAC;AAAA,EACtB;AAAA,EAEA,IAAI,6BAA6B;AAC/B,WAAO,KAAK,OAAO,CAAC;AAAA,EACtB;AAAA,EAEA,IAAI,mBAAmB;AACrB,WAAO,KAAK,OAAO,CAAC;AA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AAS;AAAA,IACxB;AACA,WAAO;AAAA,EACT;AACF;;;ADjDO,IAAM,4BAA4B,MACvC;AAAA,EACE,EAAE,UAAU,EAAE,CAACC,0BAAyB,GAAG,EAAE,GAAG,QAAQ,iBAAiB;AAAA,EACzE;AAAA,IACE,SAAS,OAAO,WAAW;AACzB,YAAM,SAAS,MAAM,2BAA2B,OAAO,MAAM;AAC7D,aAAO;AAAA,IACT;AAAA,EACF;AACF;","names":["UniswapCryptoMarketSchema","assertEx","assertEx","UniswapCryptoMarketSchema"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { UniswapCryptoMarketWitnessConfigSchema } from '@xyo-network/uniswap-crypto-market-payload-plugin';
|
|
2
|
+
import type { WitnessConfig } from '@xyo-network/witness-model';
|
|
3
|
+
export type UniswapCryptoMarketWitnessConfig = WitnessConfig<{
|
|
4
|
+
pools?: string[];
|
|
5
|
+
schema: UniswapCryptoMarketWitnessConfigSchema;
|
|
6
|
+
}>;
|
|
7
|
+
//# sourceMappingURL=Config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Config.d.ts","sourceRoot":"","sources":["../../src/Config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sCAAsC,EAAE,MAAM,mDAAmD,CAAA;AAC/G,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAE/D,MAAM,MAAM,gCAAgC,GAAG,aAAa,CAAC;IAC3D,KAAK,CAAC,EAAE,MAAM,EAAE,CAAA;IAChB,MAAM,EAAE,sCAAsC,CAAA;CAC/C,CAAC,CAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { UniswapCryptoMarketWitness } from './Witness.ts';
|
|
2
|
+
export declare const UniswapCryptoMarketPlugin: () => import("@xyo-network/payloadset-plugin").PayloadSetWitnessPlugin<UniswapCryptoMarketWitness<import(".store/@xylabs-base-npm-4.8.7-ae479fd9f4/package").BaseParamsFields & {
|
|
3
|
+
account?: import(".store/@xyo-network-account-model-npm-3.13.0-942698b671/package").AccountInstance | "random";
|
|
4
|
+
addToResolvers?: boolean;
|
|
5
|
+
additionalSigners?: import(".store/@xyo-network-account-model-npm-3.13.0-942698b671/package").AccountInstance[];
|
|
6
|
+
allowNameResolution?: boolean;
|
|
7
|
+
config: import("@xyo-network/module-model").AnyConfigSchema<import("./Config.ts").UniswapCryptoMarketWitnessConfig>;
|
|
8
|
+
ephemeralQueryAccountEnabled?: boolean;
|
|
9
|
+
moduleIdentifierTransformers?: import("@xyo-network/module-model").ModuleIdentifierTransformer[];
|
|
10
|
+
privateChildren?: import("@xyo-network/module-model").ModuleInstance[];
|
|
11
|
+
publicChildren?: import("@xyo-network/module-model").ModuleInstance[];
|
|
12
|
+
} & {
|
|
13
|
+
provider?: import("ethers").Provider;
|
|
14
|
+
}>>;
|
|
15
|
+
//# sourceMappingURL=Plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Plugin.d.ts","sourceRoot":"","sources":["../../src/Plugin.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAA;AAEzD,eAAO,MAAM,yBAAyB;;;;;;;;;;;;GASnC,CAAA"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { AbstractWitness } from '@xyo-network/abstract-witness';
|
|
2
|
+
import type { AnyConfigSchema } from '@xyo-network/module-model';
|
|
3
|
+
import type { Payload, Schema } from '@xyo-network/payload-model';
|
|
4
|
+
import type { WitnessParams } from '@xyo-network/witness-model';
|
|
5
|
+
import type { Provider } from 'ethers';
|
|
6
|
+
import type { UniswapCryptoMarketWitnessConfig } from './Config.ts';
|
|
7
|
+
import type { EthersUniSwap3Pair } from './lib/index.ts';
|
|
8
|
+
export type UniswapCryptoMarketWitnessParams = WitnessParams<AnyConfigSchema<UniswapCryptoMarketWitnessConfig>, {
|
|
9
|
+
provider?: Provider;
|
|
10
|
+
}>;
|
|
11
|
+
export declare class UniswapCryptoMarketWitness<TParams extends UniswapCryptoMarketWitnessParams = UniswapCryptoMarketWitnessParams> extends AbstractWitness<TParams> {
|
|
12
|
+
static readonly configSchemas: Schema[];
|
|
13
|
+
static readonly defaultConfigSchema: Schema;
|
|
14
|
+
protected pairs?: EthersUniSwap3Pair[];
|
|
15
|
+
protected get provider(): Provider | undefined;
|
|
16
|
+
protected observeHandler(): Promise<Payload[]>;
|
|
17
|
+
protected startHandler(): Promise<boolean>;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=Witness.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Witness.d.ts","sourceRoot":"","sources":["../../src/Witness.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;AAC/D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAA;AAChE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAA;AAGjE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAC/D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAA;AAEtC,OAAO,KAAK,EAAE,gCAAgC,EAAE,MAAM,aAAa,CAAA;AACnE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AAKxD,MAAM,MAAM,gCAAgC,GAAG,aAAa,CAC1D,eAAe,CAAC,gCAAgC,CAAC,EACjD;IACE,QAAQ,CAAC,EAAE,QAAQ,CAAA;CACpB,CACF,CAAA;AAED,qBAAa,0BAA0B,CACrC,OAAO,SAAS,gCAAgC,GAAG,gCAAgC,CACnF,SAAQ,eAAe,CAAC,OAAO,CAAC;IAChC,gBAAyB,aAAa,EAAE,MAAM,EAAE,CAAmE;IACnH,gBAAyB,mBAAmB,EAAE,MAAM,CAAyC;IAE7F,SAAS,CAAC,KAAK,CAAC,EAAE,kBAAkB,EAAE,CAAA;IACtC,SAAS,KAAK,QAAQ,yBAErB;cAEwB,cAAc,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;cAcpC,YAAY;CAQtC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,gBAAgB,CAAA;AAC9B,OAAO,EAAE,yBAAyB,IAAI,OAAO,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAA;AAC7F,cAAc,cAAc,CAAA"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Token } from '@uniswap/sdk-core';
|
|
2
|
+
import { Pool } from '@uniswap/v3-sdk';
|
|
3
|
+
import type { EnumValue } from '@xylabs/enum';
|
|
4
|
+
import { Enum } from '@xylabs/enum';
|
|
5
|
+
import type { IERC20Metadata } from '@xyo-network/open-zeppelin-typechain';
|
|
6
|
+
import type { IUniswapV3Pool } from '@xyo-network/uniswap-typechain';
|
|
7
|
+
import type { Provider } from 'ethers';
|
|
8
|
+
import { EthersUniswap3PoolSlot0Wrapper } from './Uniswap3PoolSlot0Wrapper.ts';
|
|
9
|
+
export declare const ChainId: Enum<{
|
|
10
|
+
MAINNET: 1;
|
|
11
|
+
ROPSTEN: 3;
|
|
12
|
+
RINKEBY: 4;
|
|
13
|
+
GÖRLI: 5;
|
|
14
|
+
KOVAN: 42;
|
|
15
|
+
}>;
|
|
16
|
+
export type ChainId = EnumValue<typeof ChainId>;
|
|
17
|
+
export declare class EthersUniSwap3Pair {
|
|
18
|
+
protected address: string;
|
|
19
|
+
protected provider: Provider;
|
|
20
|
+
private _pool?;
|
|
21
|
+
private _poolContract?;
|
|
22
|
+
private _slot0?;
|
|
23
|
+
private _tokenContracts;
|
|
24
|
+
private _tokens;
|
|
25
|
+
constructor(address: string, provider: Provider);
|
|
26
|
+
pool(): Promise<Pool>;
|
|
27
|
+
poolContract(): IUniswapV3Pool;
|
|
28
|
+
price(): Promise<{
|
|
29
|
+
tokens: {
|
|
30
|
+
address: string;
|
|
31
|
+
symbol: string;
|
|
32
|
+
value: number;
|
|
33
|
+
}[];
|
|
34
|
+
}>;
|
|
35
|
+
slot0(): Promise<EthersUniswap3PoolSlot0Wrapper>;
|
|
36
|
+
token(index: 0 | 1): Promise<Token>;
|
|
37
|
+
tokenContract(index: 0 | 1): Promise<IERC20Metadata>;
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=UniSwap3Pair.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UniSwap3Pair.d.ts","sourceRoot":"","sources":["../../../src/lib/UniSwap3Pair.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AACzC,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AAGtC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAC7C,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AACnC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sCAAsC,CAAA;AAE1E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAA;AAEpE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAA;AAGtC,OAAO,EAAE,8BAA8B,EAAE,MAAM,+BAA+B,CAAA;AAE9E,eAAO,MAAM,OAAO;;;;;;EAMlB,CAAA;AAEF,MAAM,MAAM,OAAO,GAAG,SAAS,CAAC,OAAO,OAAO,CAAC,CAAA;AAO/C,qBAAa,kBAAkB;IAC7B,SAAS,CAAC,OAAO,EAAE,MAAM,CAAA;IACzB,SAAS,CAAC,QAAQ,EAAE,QAAQ,CAAA;IAE5B,OAAO,CAAC,KAAK,CAAC,CAAa;IAC3B,OAAO,CAAC,aAAa,CAAC,CAAgB;IACtC,OAAO,CAAC,MAAM,CAAC,CAAuC;IACtD,OAAO,CAAC,eAAe,CAAgE;IACvF,OAAO,CAAC,OAAO,CAAuD;gBAE1D,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ;IAKzC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAoB3B,YAAY;IAON,KAAK;;;;;;;IAqBL,KAAK,IAAI,OAAO,CAAC,8BAA8B,CAAC;IAahD,KAAK,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC;IAkBnC,aAAa,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,cAAc,CAAC;CAU3D"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { EthersUniswapV3Slot0Fields } from './UniswapV3Slot0Fields.ts';
|
|
2
|
+
export declare class EthersUniswap3PoolSlot0Wrapper {
|
|
3
|
+
protected values: EthersUniswapV3Slot0Fields;
|
|
4
|
+
constructor(values: EthersUniswapV3Slot0Fields);
|
|
5
|
+
get feeProtocol(): bigint;
|
|
6
|
+
get observationCardinality(): bigint;
|
|
7
|
+
get observationCardinalityNext(): bigint;
|
|
8
|
+
get observationIndex(): bigint;
|
|
9
|
+
get sqrtPriceX96(): bigint;
|
|
10
|
+
get tick(): bigint;
|
|
11
|
+
get unlocked(): boolean;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=Uniswap3PoolSlot0Wrapper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Uniswap3PoolSlot0Wrapper.d.ts","sourceRoot":"","sources":["../../../src/lib/Uniswap3PoolSlot0Wrapper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,2BAA2B,CAAA;AAE3E,qBAAa,8BAA8B;IACzC,SAAS,CAAC,MAAM,EAAE,0BAA0B,CAAA;gBAChC,MAAM,EAAE,0BAA0B;IAI9C,IAAI,WAAW,WAEd;IAED,IAAI,sBAAsB,WAEzB;IAED,IAAI,0BAA0B,WAE7B;IAED,IAAI,gBAAgB,WAEnB;IAED,IAAI,YAAY,WAEf;IAED,IAAI,IAAI,WAEP;IAED,IAAI,QAAQ,YAEX;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UniswapPoolContracts.d.ts","sourceRoot":"","sources":["../../../src/lib/UniswapPoolContracts.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,oBAAoB,UAchC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UniswapV3Slot0Fields.d.ts","sourceRoot":"","sources":["../../../src/lib/UniswapV3Slot0Fields.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,0BAA0B,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,CAAA;AAClG,MAAM,MAAM,oBAAoB,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,CAAA"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Provider } from 'ethers';
|
|
2
|
+
import { EthersUniSwap3Pair } from './UniSwap3Pair.ts';
|
|
3
|
+
export declare const createUniswapPoolContracts: (provider: Provider, contracts: string[]) => EthersUniSwap3Pair[];
|
|
4
|
+
//# sourceMappingURL=createUniswapPoolContracts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createUniswapPoolContracts.d.ts","sourceRoot":"","sources":["../../../src/lib/createUniswapPoolContracts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAA;AAGtC,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAEtD,eAAO,MAAM,0BAA0B,GAAI,UAAU,QAAQ,EAAE,WAAW,MAAM,EAAE,yBAIjF,CAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from './createUniswapPoolContracts.ts';
|
|
2
|
+
export * from './pricesFromUniswap3.ts';
|
|
3
|
+
export * from './UniSwap3Pair.ts';
|
|
4
|
+
export * from './Uniswap3PoolSlot0Wrapper.ts';
|
|
5
|
+
export * from './UniswapPoolContracts.ts';
|
|
6
|
+
export * from './UniswapV3Slot0Fields.ts';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,iCAAiC,CAAA;AAC/C,cAAc,yBAAyB,CAAA;AACvC,cAAc,mBAAmB,CAAA;AACjC,cAAc,+BAA+B,CAAA;AAC7C,cAAc,2BAA2B,CAAA;AACzC,cAAc,2BAA2B,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logErrors.d.ts","sourceRoot":"","sources":["../../../src/lib/logErrors.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,SAAS,GAAI,CAAC,EAAE,MAAM,MAAM,CAAC,MAOzC,CAAA;AAED,eAAO,MAAM,cAAc,GAAU,CAAC,EAAE,MAAM,MAAM,OAAO,CAAC,CAAC,CAAC,eAO7D,CAAA"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { UniswapCryptoPair } from '@xyo-network/uniswap-crypto-market-payload-plugin';
|
|
2
|
+
import type { EthersUniSwap3Pair } from './index.ts';
|
|
3
|
+
export declare const pricesFromUniswap3: (pools: EthersUniSwap3Pair[]) => Promise<UniswapCryptoPair[]>;
|
|
4
|
+
//# sourceMappingURL=pricesFromUniswap3.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pricesFromUniswap3.d.ts","sourceRoot":"","sources":["../../../src/lib/pricesFromUniswap3.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mDAAmD,CAAA;AAE1F,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAGpD,eAAO,MAAM,kBAAkB,GAAU,OAAO,kBAAkB,EAAE,KAAG,OAAO,CAAC,iBAAiB,EAAE,CAUjG,CAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@xyo-network/uniswap-v3-crypto-market-plugin",
|
|
3
|
+
"version": "3.5.2",
|
|
4
|
+
"description": "Typescript/Javascript Plugins for XYO Platform",
|
|
5
|
+
"homepage": "https://xyo.network",
|
|
6
|
+
"bugs": {
|
|
7
|
+
"url": "git+https://github.com/XYOracleNetwork/plugins/issues",
|
|
8
|
+
"email": "support@xyo.network"
|
|
9
|
+
},
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/XYOracleNetwork/plugins.git"
|
|
13
|
+
},
|
|
14
|
+
"license": "LGPL-3.0-only",
|
|
15
|
+
"author": {
|
|
16
|
+
"name": "XYO Development Team",
|
|
17
|
+
"email": "support@xyo.network",
|
|
18
|
+
"url": "https://xyo.network"
|
|
19
|
+
},
|
|
20
|
+
"sideEffects": false,
|
|
21
|
+
"type": "module",
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"types": "./dist/types/index.d.ts",
|
|
25
|
+
"default": "./dist/neutral/index.mjs"
|
|
26
|
+
},
|
|
27
|
+
"./package.json": "./package.json"
|
|
28
|
+
},
|
|
29
|
+
"module": "dist/neutral/index.mjs",
|
|
30
|
+
"types": "dist/types/index.d.ts",
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@uniswap/sdk-core": "^7.7.2",
|
|
33
|
+
"@uniswap/v3-sdk": "^3.25.2",
|
|
34
|
+
"@xylabs/assert": "^4.8.7",
|
|
35
|
+
"@xylabs/delay": "^4.8.7",
|
|
36
|
+
"@xylabs/enum": "^4.8.7",
|
|
37
|
+
"@xylabs/promise": "^4.8.7",
|
|
38
|
+
"@xyo-network/abstract-witness": "^3.13.0",
|
|
39
|
+
"@xyo-network/module-model": "^3.13.0",
|
|
40
|
+
"@xyo-network/open-zeppelin-typechain": "^3.5.2",
|
|
41
|
+
"@xyo-network/payload-model": "^3.13.0",
|
|
42
|
+
"@xyo-network/payloadset-plugin": "^3.13.0",
|
|
43
|
+
"@xyo-network/uniswap-crypto-market-payload-plugin": "^3.5.2",
|
|
44
|
+
"@xyo-network/uniswap-typechain": "^3.5.2",
|
|
45
|
+
"@xyo-network/witness-model": "^3.13.0",
|
|
46
|
+
"ethers": "^6.13.6"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@xylabs/ts-scripts-yarn3": "^6.3.1",
|
|
50
|
+
"@xylabs/tsconfig": "^6.3.1",
|
|
51
|
+
"@xylabs/vitest-extended": "^4.8.7",
|
|
52
|
+
"@xyo-network/payload-wrapper": "^3.13.0",
|
|
53
|
+
"@xyo-network/witness-blockchain-abstract": "^3.13.0",
|
|
54
|
+
"typescript": "^5.8.3",
|
|
55
|
+
"vitest": "^3.1.1"
|
|
56
|
+
},
|
|
57
|
+
"publishConfig": {
|
|
58
|
+
"access": "public"
|
|
59
|
+
}
|
|
60
|
+
}
|
package/src/Config.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { UniswapCryptoMarketWitnessConfigSchema } from '@xyo-network/uniswap-crypto-market-payload-plugin'
|
|
2
|
+
import type { WitnessConfig } from '@xyo-network/witness-model'
|
|
3
|
+
|
|
4
|
+
export type UniswapCryptoMarketWitnessConfig = WitnessConfig<{
|
|
5
|
+
pools?: string[]
|
|
6
|
+
schema: UniswapCryptoMarketWitnessConfigSchema
|
|
7
|
+
}>
|
package/src/Plugin.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { PayloadSetSchema } from '@xyo-network/payload-model'
|
|
2
|
+
import { createPayloadSetWitnessPlugin } from '@xyo-network/payloadset-plugin'
|
|
3
|
+
import { UniswapCryptoMarketSchema } from '@xyo-network/uniswap-crypto-market-payload-plugin'
|
|
4
|
+
|
|
5
|
+
import { UniswapCryptoMarketWitness } from './Witness.ts'
|
|
6
|
+
|
|
7
|
+
export const UniswapCryptoMarketPlugin = () =>
|
|
8
|
+
createPayloadSetWitnessPlugin<UniswapCryptoMarketWitness>(
|
|
9
|
+
{ required: { [UniswapCryptoMarketSchema]: 1 }, schema: PayloadSetSchema },
|
|
10
|
+
{
|
|
11
|
+
witness: async (params) => {
|
|
12
|
+
const result = await UniswapCryptoMarketWitness.create(params)
|
|
13
|
+
return result
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
)
|
package/src/Witness.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { assertEx } from '@xylabs/assert'
|
|
2
|
+
import { AbstractWitness } from '@xyo-network/abstract-witness'
|
|
3
|
+
import type { AnyConfigSchema } from '@xyo-network/module-model'
|
|
4
|
+
import type { Payload, Schema } from '@xyo-network/payload-model'
|
|
5
|
+
import type { UniswapCryptoMarketPayload } from '@xyo-network/uniswap-crypto-market-payload-plugin'
|
|
6
|
+
import { UniswapCryptoMarketSchema, UniswapCryptoMarketWitnessConfigSchema } from '@xyo-network/uniswap-crypto-market-payload-plugin'
|
|
7
|
+
import type { WitnessParams } from '@xyo-network/witness-model'
|
|
8
|
+
import type { Provider } from 'ethers'
|
|
9
|
+
|
|
10
|
+
import type { UniswapCryptoMarketWitnessConfig } from './Config.ts'
|
|
11
|
+
import type { EthersUniSwap3Pair } from './lib/index.ts'
|
|
12
|
+
import {
|
|
13
|
+
createUniswapPoolContracts, pricesFromUniswap3, UniswapPoolContracts,
|
|
14
|
+
} from './lib/index.ts'
|
|
15
|
+
|
|
16
|
+
export type UniswapCryptoMarketWitnessParams = WitnessParams<
|
|
17
|
+
AnyConfigSchema<UniswapCryptoMarketWitnessConfig>,
|
|
18
|
+
{
|
|
19
|
+
provider?: Provider
|
|
20
|
+
}
|
|
21
|
+
>
|
|
22
|
+
|
|
23
|
+
export class UniswapCryptoMarketWitness<
|
|
24
|
+
TParams extends UniswapCryptoMarketWitnessParams = UniswapCryptoMarketWitnessParams,
|
|
25
|
+
> extends AbstractWitness<TParams> {
|
|
26
|
+
static override readonly configSchemas: Schema[] = [...super.configSchemas, UniswapCryptoMarketWitnessConfigSchema]
|
|
27
|
+
static override readonly defaultConfigSchema: Schema = UniswapCryptoMarketWitnessConfigSchema
|
|
28
|
+
|
|
29
|
+
protected pairs?: EthersUniSwap3Pair[]
|
|
30
|
+
protected get provider() {
|
|
31
|
+
return this.params.provider
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
protected override async observeHandler(): Promise<Payload[]> {
|
|
35
|
+
await this.started('throw')
|
|
36
|
+
const pairs = await pricesFromUniswap3(assertEx(this.pairs))
|
|
37
|
+
const timestamp = Date.now()
|
|
38
|
+
|
|
39
|
+
const payload: UniswapCryptoMarketPayload = {
|
|
40
|
+
pairs,
|
|
41
|
+
schema: UniswapCryptoMarketSchema,
|
|
42
|
+
timestamp,
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return [payload]
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
protected override async startHandler() {
|
|
49
|
+
await super.startHandler()
|
|
50
|
+
this.pairs = createUniswapPoolContracts(
|
|
51
|
+
assertEx(this.provider, () => 'Provider Required'),
|
|
52
|
+
this.config?.pools ?? UniswapPoolContracts,
|
|
53
|
+
)
|
|
54
|
+
return true
|
|
55
|
+
}
|
|
56
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { Token } from '@uniswap/sdk-core'
|
|
2
|
+
import { Pool } from '@uniswap/v3-sdk'
|
|
3
|
+
import { assertEx } from '@xylabs/assert'
|
|
4
|
+
import { delay } from '@xylabs/delay'
|
|
5
|
+
import type { EnumValue } from '@xylabs/enum'
|
|
6
|
+
import { Enum } from '@xylabs/enum'
|
|
7
|
+
import type { IERC20Metadata } from '@xyo-network/open-zeppelin-typechain'
|
|
8
|
+
import { IERC20Metadata__factory } from '@xyo-network/open-zeppelin-typechain'
|
|
9
|
+
import type { IUniswapV3Pool } from '@xyo-network/uniswap-typechain'
|
|
10
|
+
import { IUniswapV3Pool__factory } from '@xyo-network/uniswap-typechain'
|
|
11
|
+
import type { Provider } from 'ethers'
|
|
12
|
+
|
|
13
|
+
import { logErrors, logErrorsAsync } from './logErrors.ts'
|
|
14
|
+
import { EthersUniswap3PoolSlot0Wrapper } from './Uniswap3PoolSlot0Wrapper.ts'
|
|
15
|
+
|
|
16
|
+
export const ChainId = Enum({
|
|
17
|
+
MAINNET: 1,
|
|
18
|
+
ROPSTEN: 3,
|
|
19
|
+
RINKEBY: 4,
|
|
20
|
+
GÖRLI: 5,
|
|
21
|
+
KOVAN: 42,
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
export type ChainId = EnumValue<typeof ChainId>
|
|
25
|
+
|
|
26
|
+
// null is used as 'in-progress'
|
|
27
|
+
const waitNotNull = async (closure: () => unknown) => {
|
|
28
|
+
while (closure() === null) await delay(10)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export class EthersUniSwap3Pair {
|
|
32
|
+
protected address: string
|
|
33
|
+
protected provider: Provider
|
|
34
|
+
|
|
35
|
+
private _pool?: Pool | null
|
|
36
|
+
private _poolContract?: IUniswapV3Pool
|
|
37
|
+
private _slot0?: EthersUniswap3PoolSlot0Wrapper | null
|
|
38
|
+
private _tokenContracts: (IERC20Metadata | null | undefined)[] = [undefined, undefined]
|
|
39
|
+
private _tokens: (Token | null | undefined)[] = [undefined, undefined]
|
|
40
|
+
|
|
41
|
+
constructor(address: string, provider: Provider) {
|
|
42
|
+
this.address = address
|
|
43
|
+
this.provider = provider
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async pool(): Promise<Pool> {
|
|
47
|
+
return await logErrorsAsync(async () => {
|
|
48
|
+
await waitNotNull(() => this._pool)
|
|
49
|
+
this._pool = this._pool || null
|
|
50
|
+
const slot0 = await this.slot0()
|
|
51
|
+
this._pool
|
|
52
|
+
= this._pool === null
|
|
53
|
+
? new Pool(
|
|
54
|
+
await this.token(0),
|
|
55
|
+
await this.token(1),
|
|
56
|
+
Number(slot0.feeProtocol),
|
|
57
|
+
`0x${slot0.sqrtPriceX96.toString(16)}`,
|
|
58
|
+
`0x${(await this.poolContract().liquidity()).toString(16)}`,
|
|
59
|
+
Number(slot0.tick),
|
|
60
|
+
)
|
|
61
|
+
: this._pool
|
|
62
|
+
return assertEx(this._pool)
|
|
63
|
+
})
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
poolContract() {
|
|
67
|
+
return logErrors(() => {
|
|
68
|
+
this._poolContract = this._poolContract ?? IUniswapV3Pool__factory.connect(this.address, this.provider)
|
|
69
|
+
return assertEx(this._poolContract)
|
|
70
|
+
})
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
async price() {
|
|
74
|
+
return await logErrorsAsync(async () => {
|
|
75
|
+
const tokenIndexes: (0 | 1)[] = [0, 1]
|
|
76
|
+
const pool = await this.pool()
|
|
77
|
+
const tokens = await Promise.all(tokenIndexes.map(value => this.token(value)))
|
|
78
|
+
const tokenContracts = await Promise.all(tokenIndexes.map(value => this.tokenContract(value)))
|
|
79
|
+
const tokenPrices = tokens.map(token => Number.parseFloat(pool.priceOf(token).toSignificant()))
|
|
80
|
+
const tokenSymbols = tokens.map((token, index) => assertEx(token.symbol, () => `Token[${index}] Missing Symbols`).toLowerCase())
|
|
81
|
+
const result = {
|
|
82
|
+
tokens: await Promise.all(
|
|
83
|
+
tokenIndexes.map(async (value) => {
|
|
84
|
+
return {
|
|
85
|
+
address: await tokenContracts[value].getAddress(), symbol: tokenSymbols[value], value: tokenPrices[value],
|
|
86
|
+
}
|
|
87
|
+
}),
|
|
88
|
+
),
|
|
89
|
+
}
|
|
90
|
+
return result
|
|
91
|
+
})
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
async slot0(): Promise<EthersUniswap3PoolSlot0Wrapper> {
|
|
95
|
+
return await logErrorsAsync(async () => {
|
|
96
|
+
await waitNotNull(() => this._slot0)
|
|
97
|
+
this._slot0 = this._slot0 || null
|
|
98
|
+
if (this._slot0 === null) {
|
|
99
|
+
const poolContract = this.poolContract()
|
|
100
|
+
const slot = await poolContract.slot0()
|
|
101
|
+
this._slot0 = this._slot0 ?? new EthersUniswap3PoolSlot0Wrapper(slot)
|
|
102
|
+
}
|
|
103
|
+
return assertEx(this._slot0)
|
|
104
|
+
})
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
async token(index: 0 | 1): Promise<Token> {
|
|
108
|
+
return await logErrorsAsync(async () => {
|
|
109
|
+
await waitNotNull(() => this._tokens[index])
|
|
110
|
+
this._tokens[index] = this._tokens[index] || null
|
|
111
|
+
const tokenContract = await this.tokenContract(index)
|
|
112
|
+
this._tokens[index]
|
|
113
|
+
= this._tokens[index]
|
|
114
|
+
?? new Token(
|
|
115
|
+
ChainId.MAINNET,
|
|
116
|
+
await tokenContract.getAddress(),
|
|
117
|
+
Number(await tokenContract.decimals()),
|
|
118
|
+
await tokenContract.symbol(),
|
|
119
|
+
await tokenContract.name(),
|
|
120
|
+
)
|
|
121
|
+
return assertEx(this._tokens[index])
|
|
122
|
+
})
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
async tokenContract(index: 0 | 1): Promise<IERC20Metadata> {
|
|
126
|
+
return await logErrorsAsync(async () => {
|
|
127
|
+
await waitNotNull(() => this._tokenContracts[index])
|
|
128
|
+
this._tokenContracts[index] = this._tokenContracts[index] || null
|
|
129
|
+
this._tokenContracts[index]
|
|
130
|
+
= this._tokenContracts[index]
|
|
131
|
+
?? IERC20Metadata__factory.connect(await (index === 0 ? this.poolContract().token0() : this.poolContract().token1()), this.provider)
|
|
132
|
+
return assertEx(this._tokenContracts[index])
|
|
133
|
+
})
|
|
134
|
+
}
|
|
135
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { EthersUniswapV3Slot0Fields } from './UniswapV3Slot0Fields.ts'
|
|
2
|
+
|
|
3
|
+
export class EthersUniswap3PoolSlot0Wrapper {
|
|
4
|
+
protected values: EthersUniswapV3Slot0Fields
|
|
5
|
+
constructor(values: EthersUniswapV3Slot0Fields) {
|
|
6
|
+
this.values = values
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
get feeProtocol() {
|
|
10
|
+
return this.values[5]
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
get observationCardinality() {
|
|
14
|
+
return this.values[3]
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
get observationCardinalityNext() {
|
|
18
|
+
return this.values[4]
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
get observationIndex() {
|
|
22
|
+
return this.values[2]
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
get sqrtPriceX96() {
|
|
26
|
+
return this.values[0]
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
get tick() {
|
|
30
|
+
return this.values[1]
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
get unlocked() {
|
|
34
|
+
return this.values[6]
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export const UniswapPoolContracts = [
|
|
2
|
+
/* xyo/weth */ '0xE331DE28cd81B768C19A366b0e4e4675c45eC2dA',
|
|
3
|
+
/* xyo/usdt */ '0xd0AF1981f52146a6939385451dAeA0726e13a484',
|
|
4
|
+
/* xyo/dai */ '0x9D7e5647CE3c7C2d835F2F5e82C8fDb36B0BB0fe',
|
|
5
|
+
/* wbtc/xyo */ '0x0cF7494c9dE661467403aBeE8454b3BBf0179a84',
|
|
6
|
+
/* link/xyo */ '0x4693456599a8a4975862A0E720C5de7E1D09A1e4',
|
|
7
|
+
/* wbtc/weth */ '0xCBCdF9626bC03E24f779434178A73a0B4bad62eD',
|
|
8
|
+
/* dai/usdc */ '0x5777d92f208679DB4b9778590Fa3CAB3aC9e2168',
|
|
9
|
+
/* usdc/weth */ '0x8ad599c3A0ff1De082011EFDDc58f1908eb6e6D8',
|
|
10
|
+
/* usdc/weth */ '0x88e6A0c2dDD26FEEb64F039a2c41296FcB3f5640',
|
|
11
|
+
/* dai/usdc */ '0x6c6Bc977E13Df9b0de53b251522280BB72383700',
|
|
12
|
+
/* frax/usdc */ '0xc63B0708E2F7e69CB8A1df0e1389A98C35A76D52',
|
|
13
|
+
/* wbtc/usdc */ '0x99ac8cA7087fA4A2A1FB6357269965A2014ABc35',
|
|
14
|
+
/* usdc/usdt */ '0x3416cF6C708Da44DB2624D63ea0AAef7113527C6',
|
|
15
|
+
]
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Provider } from 'ethers'
|
|
2
|
+
|
|
3
|
+
import { logErrors } from './logErrors.ts'
|
|
4
|
+
import { EthersUniSwap3Pair } from './UniSwap3Pair.ts'
|
|
5
|
+
|
|
6
|
+
export const createUniswapPoolContracts = (provider: Provider, contracts: string[]) => {
|
|
7
|
+
return logErrors(() => {
|
|
8
|
+
return contracts.map(contract => new EthersUniSwap3Pair(contract, provider))
|
|
9
|
+
})
|
|
10
|
+
}
|
package/src/lib/index.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export const logErrors = <T>(func: () => T) => {
|
|
2
|
+
try {
|
|
3
|
+
return func()
|
|
4
|
+
} catch (ex) {
|
|
5
|
+
console.error(ex)
|
|
6
|
+
throw ex
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const logErrorsAsync = async <T>(func: () => Promise<T>) => {
|
|
11
|
+
try {
|
|
12
|
+
return await func()
|
|
13
|
+
} catch (ex) {
|
|
14
|
+
console.error(ex)
|
|
15
|
+
throw ex
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { fulfilled } from '@xylabs/promise'
|
|
2
|
+
import type { UniswapCryptoPair } from '@xyo-network/uniswap-crypto-market-payload-plugin'
|
|
3
|
+
|
|
4
|
+
import type { EthersUniSwap3Pair } from './index.ts'
|
|
5
|
+
import { logErrorsAsync } from './logErrors.ts'
|
|
6
|
+
|
|
7
|
+
export const pricesFromUniswap3 = async (pools: EthersUniSwap3Pair[]): Promise<UniswapCryptoPair[]> => {
|
|
8
|
+
return await logErrorsAsync(async () => {
|
|
9
|
+
const promiseResults = await Promise.allSettled(
|
|
10
|
+
pools.map(async (pool): Promise<UniswapCryptoPair> => {
|
|
11
|
+
const result = await pool.price()
|
|
12
|
+
return result
|
|
13
|
+
}),
|
|
14
|
+
)
|
|
15
|
+
return promiseResults.filter(fulfilled).map(result => result.value)
|
|
16
|
+
})
|
|
17
|
+
}
|
package/typedoc.json
ADDED