@strkfarm/sdk 1.0.55 → 1.0.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/cli.js +0 -0
- package/dist/cli.mjs +0 -0
- package/dist/index.browser.global.js +65617 -46434
- package/dist/index.browser.mjs +16547 -8981
- package/dist/index.d.ts +355 -15
- package/dist/index.js +19314 -11582
- package/dist/index.mjs +17620 -9895
- package/package.json +4 -3
- package/src/data/universal-vault.abi.json +1565 -0
- package/src/data/vault-manager.abi.json +634 -0
- package/src/data/vesu-singleton.abi.json +2247 -0
- package/src/dataTypes/address.ts +4 -0
- package/src/global.ts +30 -0
- package/src/interfaces/common.tsx +18 -1
- package/src/modules/pricer.ts +1 -1
- package/src/node/deployer.ts +219 -0
- package/src/node/index.ts +2 -1
- package/src/notifs/telegram.ts +0 -2
- package/src/strategies/base-strategy.ts +3 -23
- package/src/strategies/index.ts +3 -1
- package/src/strategies/sensei.ts +13 -6
- package/src/strategies/universal-adapters/adapter-utils.ts +13 -0
- package/src/strategies/universal-adapters/baseAdapter.ts +41 -0
- package/src/strategies/universal-adapters/common-adapter.ts +96 -0
- package/src/strategies/universal-adapters/index.ts +3 -0
- package/src/strategies/universal-adapters/vesu-adapter.ts +344 -0
- package/src/strategies/universal-strategy.ts +695 -0
- package/src/utils/cacheClass.ts +29 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/oz-merkle.ts +91 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
interface CacheData {
|
|
2
|
+
timestamp: number;
|
|
3
|
+
ttl: number;
|
|
4
|
+
data: any;
|
|
5
|
+
}
|
|
6
|
+
export class CacheClass {
|
|
7
|
+
readonly cache: Map<string, CacheData> = new Map();
|
|
8
|
+
|
|
9
|
+
setCache(key: string, data: any, ttl: number = 60000): void {
|
|
10
|
+
const timestamp = Date.now();
|
|
11
|
+
this.cache.set(key, { timestamp, ttl, data });
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
getCache<T>(key: string): T | null {
|
|
15
|
+
const cachedData = this.cache.get(key);
|
|
16
|
+
if (!cachedData || !this.isCacheValid(key)) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
return cachedData.data;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
isCacheValid(key: string): boolean {
|
|
23
|
+
const cachedData = this.cache.get(key);
|
|
24
|
+
if (!cachedData) return false;
|
|
25
|
+
|
|
26
|
+
const { timestamp, ttl } = cachedData;
|
|
27
|
+
return Date.now() - timestamp <= ttl;
|
|
28
|
+
}
|
|
29
|
+
}
|
package/src/utils/index.ts
CHANGED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { BytesLike, HexString, toHex } from "@ericnordelo/strk-merkle-tree/dist/bytes";
|
|
2
|
+
import { MultiProof, processMultiProof, processProof } from "@ericnordelo/strk-merkle-tree/dist/core";
|
|
3
|
+
import { standardLeafHash } from "@ericnordelo/strk-merkle-tree/dist/hashes";
|
|
4
|
+
import { MerkleTreeData, MerkleTreeImpl } from "@ericnordelo/strk-merkle-tree/dist/merkletree";
|
|
5
|
+
import { MerkleTreeOptions } from "@ericnordelo/strk-merkle-tree/dist/options";
|
|
6
|
+
import { ValueType } from "@ericnordelo/strk-merkle-tree/dist/serde";
|
|
7
|
+
import { validateArgument } from "@ericnordelo/strk-merkle-tree/src/utils/errors";
|
|
8
|
+
import { num } from "starknet";
|
|
9
|
+
import * as starknet from "@scure/starknet";
|
|
10
|
+
|
|
11
|
+
export interface LeafData {
|
|
12
|
+
id: bigint,
|
|
13
|
+
readableId: string,
|
|
14
|
+
data: bigint[]
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function hash_leaf(leaf: LeafData) {
|
|
18
|
+
if (leaf.data.length < 1) {
|
|
19
|
+
throw new Error("Invalid leaf data");
|
|
20
|
+
}
|
|
21
|
+
let firstElement = leaf.data[0];
|
|
22
|
+
let value = firstElement;
|
|
23
|
+
for (let i=1; i < leaf.data.length; i++) {
|
|
24
|
+
value = pedersen_hash(value, leaf.data[i]);
|
|
25
|
+
}
|
|
26
|
+
return `0x${num.toHexString(value).replace(/^0x/, '').padStart(64, '0')}`;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function pedersen_hash(a: bigint, b: bigint): bigint {
|
|
30
|
+
return BigInt(starknet.pedersen(a, b).toString());
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
export interface StandardMerkleTreeData<T extends any> extends MerkleTreeData<T> {
|
|
35
|
+
format: 'standard-v1';
|
|
36
|
+
leafEncoding: ValueType[];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export class StandardMerkleTree extends MerkleTreeImpl<LeafData> {
|
|
40
|
+
protected constructor(
|
|
41
|
+
protected readonly tree: HexString[],
|
|
42
|
+
protected readonly values: StandardMerkleTreeData<LeafData>['values'],
|
|
43
|
+
protected readonly leafEncoding: ValueType[],
|
|
44
|
+
) {
|
|
45
|
+
super(tree, values, leaf => {
|
|
46
|
+
return hash_leaf(leaf)
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
static of(
|
|
51
|
+
values: LeafData[],
|
|
52
|
+
leafEncoding: ValueType[] = [],
|
|
53
|
+
options: MerkleTreeOptions = {},
|
|
54
|
+
): StandardMerkleTree {
|
|
55
|
+
// use default nodeHash (standardNodeHash)
|
|
56
|
+
const [tree, indexedValues] = MerkleTreeImpl.prepare(values, options, leaf => {
|
|
57
|
+
return hash_leaf(leaf)
|
|
58
|
+
});
|
|
59
|
+
return new StandardMerkleTree(tree, indexedValues, leafEncoding);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
static verify<T extends any[]>(root: BytesLike, leafEncoding: ValueType[], leaf: T, proof: BytesLike[]): boolean {
|
|
63
|
+
// use default nodeHash (standardNodeHash) for processProof
|
|
64
|
+
return toHex(root) === processProof(standardLeafHash(leafEncoding, leaf), proof);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
static verifyMultiProof<T extends any[]>(
|
|
68
|
+
root: BytesLike,
|
|
69
|
+
leafEncoding: ValueType[],
|
|
70
|
+
multiproof: MultiProof<BytesLike, T>,
|
|
71
|
+
): boolean {
|
|
72
|
+
// use default nodeHash (standardNodeHash) for processMultiProof
|
|
73
|
+
return (
|
|
74
|
+
toHex(root) ===
|
|
75
|
+
processMultiProof({
|
|
76
|
+
leaves: multiproof.leaves.map(leaf => standardLeafHash(leafEncoding, leaf)),
|
|
77
|
+
proof: multiproof.proof,
|
|
78
|
+
proofFlags: multiproof.proofFlags,
|
|
79
|
+
})
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
dump(): StandardMerkleTreeData<LeafData> {
|
|
84
|
+
return {
|
|
85
|
+
format: 'standard-v1',
|
|
86
|
+
leafEncoding: this.leafEncoding,
|
|
87
|
+
tree: this.tree,
|
|
88
|
+
values: this.values,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
}
|