@across-protocol/sdk 4.3.56 → 4.3.57
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/dist/cjs/pool/poolClient.d.ts +9 -13
- package/dist/cjs/pool/poolClient.js +1 -1
- package/dist/cjs/pool/poolClient.js.map +1 -1
- package/dist/cjs/pool/uma/across/constants.d.ts +2 -0
- package/dist/cjs/pool/uma/across/constants.js +6 -0
- package/dist/cjs/pool/uma/across/constants.js.map +1 -0
- package/dist/cjs/pool/uma/across/index.d.ts +2 -0
- package/dist/cjs/pool/uma/across/index.js +8 -0
- package/dist/cjs/pool/uma/across/index.js.map +1 -0
- package/dist/cjs/pool/uma/across/transactionManager.d.ts +12 -0
- package/dist/cjs/pool/uma/across/transactionManager.js +121 -0
- package/dist/cjs/pool/uma/across/transactionManager.js.map +1 -0
- package/dist/cjs/pool/uma/clients/erc20/client.d.ts +26 -0
- package/dist/cjs/pool/uma/clients/erc20/client.js +38 -0
- package/dist/cjs/pool/uma/clients/erc20/client.js.map +1 -0
- package/dist/cjs/pool/uma/clients/erc20/index.d.ts +1 -0
- package/dist/cjs/pool/uma/clients/erc20/index.js +5 -0
- package/dist/cjs/pool/uma/clients/erc20/index.js.map +1 -0
- package/dist/cjs/pool/uma/clients/index.d.ts +1 -0
- package/dist/cjs/pool/uma/clients/index.js +6 -0
- package/dist/cjs/pool/uma/clients/index.js.map +1 -0
- package/dist/cjs/pool/uma/index.d.ts +13 -0
- package/dist/cjs/pool/uma/index.js +9 -0
- package/dist/cjs/pool/uma/index.js.map +1 -0
- package/dist/cjs/pool/uma/oracle/index.d.ts +1 -0
- package/dist/cjs/pool/uma/oracle/index.js +6 -0
- package/dist/cjs/pool/uma/oracle/index.js.map +1 -0
- package/dist/cjs/pool/uma/oracle/utils.d.ts +7 -0
- package/dist/cjs/pool/uma/oracle/utils.js +20 -0
- package/dist/cjs/pool/uma/oracle/utils.js.map +1 -0
- package/dist/cjs/pool/uma/utils.d.ts +17 -0
- package/dist/cjs/pool/uma/utils.js +69 -0
- package/dist/cjs/pool/uma/utils.js.map +1 -0
- package/dist/esm/pool/poolClient.d.ts +9 -13
- package/dist/esm/pool/poolClient.js +1 -1
- package/dist/esm/pool/poolClient.js.map +1 -1
- package/dist/esm/pool/uma/across/constants.d.ts +2 -0
- package/dist/esm/pool/uma/across/constants.js +3 -0
- package/dist/esm/pool/uma/across/constants.js.map +1 -0
- package/dist/esm/pool/uma/across/index.d.ts +2 -0
- package/dist/esm/pool/uma/across/index.js +4 -0
- package/dist/esm/pool/uma/across/index.js.map +1 -0
- package/dist/esm/pool/uma/across/transactionManager.d.ts +12 -0
- package/dist/esm/pool/uma/across/transactionManager.js +122 -0
- package/dist/esm/pool/uma/across/transactionManager.js.map +1 -0
- package/dist/esm/pool/uma/clients/erc20/client.d.ts +26 -0
- package/dist/esm/pool/uma/clients/erc20/client.js +35 -0
- package/dist/esm/pool/uma/clients/erc20/client.js.map +1 -0
- package/dist/esm/pool/uma/clients/erc20/index.d.ts +1 -0
- package/dist/esm/pool/uma/clients/erc20/index.js +2 -0
- package/dist/esm/pool/uma/clients/erc20/index.js.map +1 -0
- package/dist/esm/pool/uma/clients/index.d.ts +1 -0
- package/dist/esm/pool/uma/clients/index.js +3 -0
- package/dist/esm/pool/uma/clients/index.js.map +1 -0
- package/dist/esm/pool/uma/index.d.ts +13 -0
- package/dist/esm/pool/uma/index.js +9 -0
- package/dist/esm/pool/uma/index.js.map +1 -0
- package/dist/esm/pool/uma/oracle/index.d.ts +1 -0
- package/dist/esm/pool/uma/oracle/index.js +3 -0
- package/dist/esm/pool/uma/oracle/index.js.map +1 -0
- package/dist/esm/pool/uma/oracle/utils.d.ts +23 -0
- package/dist/esm/pool/uma/oracle/utils.js +33 -0
- package/dist/esm/pool/uma/oracle/utils.js.map +1 -0
- package/dist/esm/pool/uma/utils.d.ts +17 -0
- package/dist/esm/pool/uma/utils.js +68 -0
- package/dist/esm/pool/uma/utils.js.map +1 -0
- package/dist/types/pool/poolClient.d.ts +9 -13
- package/dist/types/pool/poolClient.d.ts.map +1 -1
- package/dist/types/pool/uma/across/constants.d.ts +3 -0
- package/dist/types/pool/uma/across/constants.d.ts.map +1 -0
- package/dist/types/pool/uma/across/index.d.ts +3 -0
- package/dist/types/pool/uma/across/index.d.ts.map +1 -0
- package/dist/types/pool/uma/across/transactionManager.d.ts +13 -0
- package/dist/types/pool/uma/across/transactionManager.d.ts.map +1 -0
- package/dist/types/pool/uma/clients/erc20/client.d.ts +27 -0
- package/dist/types/pool/uma/clients/erc20/client.d.ts.map +1 -0
- package/dist/types/pool/uma/clients/erc20/index.d.ts +2 -0
- package/dist/types/pool/uma/clients/erc20/index.d.ts.map +1 -0
- package/dist/types/pool/uma/clients/index.d.ts +2 -0
- package/dist/types/pool/uma/clients/index.d.ts.map +1 -0
- package/dist/types/pool/uma/index.d.ts +14 -0
- package/dist/types/pool/uma/index.d.ts.map +1 -0
- package/dist/types/pool/uma/oracle/index.d.ts +2 -0
- package/dist/types/pool/uma/oracle/index.d.ts.map +1 -0
- package/dist/types/pool/uma/oracle/utils.d.ts +24 -0
- package/dist/types/pool/uma/oracle/utils.d.ts.map +1 -0
- package/dist/types/pool/uma/utils.d.ts +18 -0
- package/dist/types/pool/uma/utils.d.ts.map +1 -0
- package/package.json +2 -2
- package/src/pool/poolClient.ts +1 -1
- package/src/pool/uma/across/constants.ts +2 -0
- package/src/pool/uma/across/index.ts +2 -0
- package/src/pool/uma/across/transactionManager.ts +73 -0
- package/src/pool/uma/clients/erc20/README.md +29 -0
- package/src/pool/uma/clients/erc20/client.e2e.ts +26 -0
- package/src/pool/uma/clients/erc20/client.ts +67 -0
- package/src/pool/uma/clients/erc20/index.ts +1 -0
- package/src/pool/uma/clients/index.ts +1 -0
- package/src/pool/uma/index.ts +33 -0
- package/src/pool/uma/oracle/index.ts +2 -0
- package/src/pool/uma/oracle/utils.ts +38 -0
- package/src/pool/uma/utils.test.ts +24 -0
- package/src/pool/uma/utils.ts +53 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { BigNumberish } from "../../../utils";
|
|
2
|
+
import sortedLastIndexBy from "lodash/sortedLastIndexBy";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* eventKey. Make a unique and sortable identifier string for an event
|
|
6
|
+
* Used by poolClient.ts lines 166, 246
|
|
7
|
+
*
|
|
8
|
+
* @param {Event} event
|
|
9
|
+
* @returns {string} - the unique id
|
|
10
|
+
*/
|
|
11
|
+
export function eventKey(event: {
|
|
12
|
+
blockNumber: BigNumberish;
|
|
13
|
+
transactionIndex: BigNumberish;
|
|
14
|
+
logIndex: BigNumberish;
|
|
15
|
+
}): string {
|
|
16
|
+
return [
|
|
17
|
+
// we pad these because numbers of varying lengths will not sort correctly, ie "10" will incorrectly sort before "9", but "09" will be correct.
|
|
18
|
+
event.blockNumber.toString().padStart(16, "0"),
|
|
19
|
+
event.transactionIndex.toString().padStart(16, "0"),
|
|
20
|
+
event.logIndex?.toString().padStart(16, "0"),
|
|
21
|
+
// ~ is the last printable ascii char, so it does not interfere with sorting
|
|
22
|
+
].join("~");
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* insertOrdered. Inserts items in an array maintaining sorted order, in this case lowest to highest. Does not check duplicates.
|
|
27
|
+
* Mainly used for caching all known events, in order of oldest to newest.
|
|
28
|
+
* Used by poolClient.ts line 181
|
|
29
|
+
*
|
|
30
|
+
* @param {T[]} array
|
|
31
|
+
* @param {T} element
|
|
32
|
+
* @param {Function} orderBy
|
|
33
|
+
*/
|
|
34
|
+
export function insertOrderedAscending<T>(array: T[], element: T, orderBy: (element: T) => string | number): T[] {
|
|
35
|
+
const index = sortedLastIndexBy(array, element, orderBy);
|
|
36
|
+
array.splice(index, 0, element);
|
|
37
|
+
return array;
|
|
38
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import * as utils from "./utils";
|
|
2
|
+
import assert from "assert";
|
|
3
|
+
test("Balances", function () {
|
|
4
|
+
const balances = utils.Balances();
|
|
5
|
+
assert.ok(balances);
|
|
6
|
+
balances.create("a", "100");
|
|
7
|
+
balances.create("b", "99");
|
|
8
|
+
let result = balances.get("a");
|
|
9
|
+
assert.equal(result, "100");
|
|
10
|
+
result = balances.get("b");
|
|
11
|
+
assert.equal(result, "99");
|
|
12
|
+
|
|
13
|
+
result = balances.sub("a", 1);
|
|
14
|
+
assert.equal(result, "99");
|
|
15
|
+
|
|
16
|
+
result = balances.sub("b", 1);
|
|
17
|
+
assert.equal(result, "98");
|
|
18
|
+
|
|
19
|
+
result = balances.add("b", 2);
|
|
20
|
+
assert.equal(result, "100");
|
|
21
|
+
|
|
22
|
+
const bals = balances.balances;
|
|
23
|
+
assert.equal(Object.keys(bals).length, 2);
|
|
24
|
+
});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import assert from "assert";
|
|
2
|
+
import { BigNumber, BigNumberish, delay as sleep } from "../../utils";
|
|
3
|
+
|
|
4
|
+
export { delay as sleep } from "../../utils";
|
|
5
|
+
|
|
6
|
+
// check if a value is not null or undefined, useful for numbers which could be 0.
|
|
7
|
+
// "is" syntax: https://stackoverflow.com/questions/40081332/what-does-the-is-keyword-do-in-typescript
|
|
8
|
+
/* eslint-disable-next-line @typescript-eslint/ban-types */
|
|
9
|
+
export function exists<T>(value: T | null | undefined): value is NonNullable<T> {
|
|
10
|
+
return value !== null && value !== undefined;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// useful for maintaining balances from events
|
|
14
|
+
export type Balances = { [key: string]: string };
|
|
15
|
+
export function Balances(balances: Balances = {}) {
|
|
16
|
+
function create(id: string, amount = "0") {
|
|
17
|
+
assert(!has(id), "balance already exists");
|
|
18
|
+
return set(id, amount);
|
|
19
|
+
}
|
|
20
|
+
function has(id: string) {
|
|
21
|
+
return exists(balances[id]);
|
|
22
|
+
}
|
|
23
|
+
function set(id: string, amount: string) {
|
|
24
|
+
balances[id] = amount;
|
|
25
|
+
return amount;
|
|
26
|
+
}
|
|
27
|
+
function add(id: string, amount: BigNumberish) {
|
|
28
|
+
return set(id, BigNumber.from(amount).add(getOrCreate(id)).toString());
|
|
29
|
+
}
|
|
30
|
+
function sub(id: string, amount: BigNumberish) {
|
|
31
|
+
return set(id, BigNumber.from(getOrCreate(id)).sub(amount).toString());
|
|
32
|
+
}
|
|
33
|
+
function get(id: string) {
|
|
34
|
+
assert(has(id), "balance does not exist");
|
|
35
|
+
return balances[id];
|
|
36
|
+
}
|
|
37
|
+
function getOrCreate(id: string) {
|
|
38
|
+
if (has(id)) return get(id);
|
|
39
|
+
return create(id);
|
|
40
|
+
}
|
|
41
|
+
return { create, add, sub, get, balances, set, has, getOrCreate };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Loop forever but wait until execution is finished before starting next timer. Throw an error to break this
|
|
45
|
+
// or add another utlity function if you need it to end on condition.
|
|
46
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
47
|
+
export async function loop(fn: (...args: any[]) => any, delay: number, ...args: any[]) {
|
|
48
|
+
do {
|
|
49
|
+
await fn(...args);
|
|
50
|
+
await sleep(delay);
|
|
51
|
+
/* eslint-disable-next-line no-constant-condition */
|
|
52
|
+
} while (true);
|
|
53
|
+
}
|