koilib 9.1.1 → 9.2.0
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/README.md +1 -0
- package/dist/koinos.js +1682 -393
- package/dist/koinos.min.js +1 -1
- package/lib/Multicall.d.ts +79 -0
- package/lib/Multicall.js +104 -0
- package/lib/Multicall.js.map +1 -0
- package/lib/abis/multicallAbi.d.ts +2 -0
- package/lib/abis/multicallAbi.js +127 -0
- package/lib/abis/multicallAbi.js.map +1 -0
- package/lib/browser/Multicall.d.ts +79 -0
- package/lib/browser/Multicall.js +104 -0
- package/lib/browser/Multicall.js.map +1 -0
- package/lib/browser/abis/multicallAbi.d.ts +2 -0
- package/lib/browser/abis/multicallAbi.js +127 -0
- package/lib/browser/abis/multicallAbi.js.map +1 -0
- package/lib/browser/index.d.ts +1 -0
- package/lib/browser/index.js +1 -0
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/index2.js +2 -0
- package/lib/browser/index2.js.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/index2.js +2 -0
- package/lib/index2.js.map +1 -1
- package/package.json +1 -1
- package/src/Multicall.ts +139 -0
- package/src/abis/multicallAbi.ts +127 -0
- package/src/index.ts +1 -0
- package/src/index2.ts +2 -0
package/lib/browser/index2.js
CHANGED
|
@@ -30,10 +30,12 @@ const Signer_1 = require("./Signer");
|
|
|
30
30
|
const Provider_1 = require("./Provider");
|
|
31
31
|
const Transaction_1 = require("./Transaction");
|
|
32
32
|
const Serializer_1 = require("./Serializer");
|
|
33
|
+
const Multicall_1 = require("./Multicall");
|
|
33
34
|
window.utils = utils;
|
|
34
35
|
window.Contract = Contract_1.Contract;
|
|
35
36
|
window.Signer = Signer_1.Signer;
|
|
36
37
|
window.Provider = Provider_1.Provider;
|
|
37
38
|
window.Transaction = Transaction_1.Transaction;
|
|
38
39
|
window.Serializer = Serializer_1.Serializer;
|
|
40
|
+
window.Multicall = Multicall_1.Multicall;
|
|
39
41
|
//# sourceMappingURL=index2.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index2.js","sourceRoot":"","sources":["../../src/index2.ts"],"names":[],"mappings":";AAAA,wEAAwE;;;;;;;;;;;;;;;;;;;;;;;;;AAExE,+CAAiC;AACjC,yCAAsC;AACtC,qCAAkC;AAClC,yCAAsC;AACtC,+CAA4C;AAC5C,6CAA0C;
|
|
1
|
+
{"version":3,"file":"index2.js","sourceRoot":"","sources":["../../src/index2.ts"],"names":[],"mappings":";AAAA,wEAAwE;;;;;;;;;;;;;;;;;;;;;;;;;AAExE,+CAAiC;AACjC,yCAAsC;AACtC,qCAAkC;AAClC,yCAAsC;AACtC,+CAA4C;AAC5C,6CAA0C;AAC1C,2CAAwC;AAIxC,MAAM,CAAC,KAAK,GAAG,KAAK,CAAC;AACrB,MAAM,CAAC,QAAQ,GAAG,mBAAQ,CAAC;AAC3B,MAAM,CAAC,MAAM,GAAG,eAAM,CAAC;AACvB,MAAM,CAAC,QAAQ,GAAG,mBAAQ,CAAC;AAC3B,MAAM,CAAC,WAAW,GAAG,yBAAW,CAAC;AACjC,MAAM,CAAC,UAAU,GAAG,uBAAU,CAAC;AAC/B,MAAM,CAAC,SAAS,GAAG,qBAAS,CAAC"}
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -36,4 +36,5 @@ __exportStar(require("./Signer"), exports);
|
|
|
36
36
|
__exportStar(require("./Provider"), exports);
|
|
37
37
|
__exportStar(require("./Transaction"), exports);
|
|
38
38
|
__exportStar(require("./Serializer"), exports);
|
|
39
|
+
__exportStar(require("./Multicall"), exports);
|
|
39
40
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,wEAAwE;AACxE,iCAAiC;AACjC,sDAAsC;AACtC,8CAA4B;AAC5B,6CAA2B;AAC3B,2CAAyB;AACzB,6CAA2B;AAC3B,gDAA8B;AAC9B,+CAA6B"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,wEAAwE;AACxE,iCAAiC;AACjC,sDAAsC;AACtC,8CAA4B;AAC5B,6CAA2B;AAC3B,2CAAyB;AACzB,6CAA2B;AAC3B,gDAA8B;AAC9B,+CAA6B;AAC7B,8CAA4B"}
|
package/lib/index2.js
CHANGED
|
@@ -30,10 +30,12 @@ const Signer_1 = require("./Signer");
|
|
|
30
30
|
const Provider_1 = require("./Provider");
|
|
31
31
|
const Transaction_1 = require("./Transaction");
|
|
32
32
|
const Serializer_1 = require("./Serializer");
|
|
33
|
+
const Multicall_1 = require("./Multicall");
|
|
33
34
|
window.utils = utils;
|
|
34
35
|
window.Contract = Contract_1.Contract;
|
|
35
36
|
window.Signer = Signer_1.Signer;
|
|
36
37
|
window.Provider = Provider_1.Provider;
|
|
37
38
|
window.Transaction = Transaction_1.Transaction;
|
|
38
39
|
window.Serializer = Serializer_1.Serializer;
|
|
40
|
+
window.Multicall = Multicall_1.Multicall;
|
|
39
41
|
//# sourceMappingURL=index2.js.map
|
package/lib/index2.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index2.js","sourceRoot":"","sources":["../src/index2.ts"],"names":[],"mappings":";AAAA,wEAAwE;;;;;;;;;;;;;;;;;;;;;;;;;AAExE,+CAAiC;AACjC,yCAAsC;AACtC,qCAAkC;AAClC,yCAAsC;AACtC,+CAA4C;AAC5C,6CAA0C;
|
|
1
|
+
{"version":3,"file":"index2.js","sourceRoot":"","sources":["../src/index2.ts"],"names":[],"mappings":";AAAA,wEAAwE;;;;;;;;;;;;;;;;;;;;;;;;;AAExE,+CAAiC;AACjC,yCAAsC;AACtC,qCAAkC;AAClC,yCAAsC;AACtC,+CAA4C;AAC5C,6CAA0C;AAC1C,2CAAwC;AAIxC,MAAM,CAAC,KAAK,GAAG,KAAK,CAAC;AACrB,MAAM,CAAC,QAAQ,GAAG,mBAAQ,CAAC;AAC3B,MAAM,CAAC,MAAM,GAAG,eAAM,CAAC;AACvB,MAAM,CAAC,QAAQ,GAAG,mBAAQ,CAAC;AAC3B,MAAM,CAAC,WAAW,GAAG,yBAAW,CAAC;AACjC,MAAM,CAAC,UAAU,GAAG,uBAAU,CAAC;AAC/B,MAAM,CAAC,SAAS,GAAG,qBAAS,CAAC"}
|
package/package.json
CHANGED
package/src/Multicall.ts
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { Contract } from "./Contract";
|
|
2
|
+
import { OperationJson } from "./interface";
|
|
3
|
+
import { ProviderInterface } from "./Provider";
|
|
4
|
+
import { Transaction } from "./Transaction";
|
|
5
|
+
import { multicallAbi } from "./abis/multicallAbi";
|
|
6
|
+
|
|
7
|
+
export class Multicall {
|
|
8
|
+
/**
|
|
9
|
+
* Multicall contract address
|
|
10
|
+
*/
|
|
11
|
+
id: string;
|
|
12
|
+
|
|
13
|
+
transaction: Transaction;
|
|
14
|
+
|
|
15
|
+
contracts: Contract[];
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* const tokens = [
|
|
21
|
+
* "19GYjDBVXU7keLbYvMLazsGQn3GTWHjHkK", // koin
|
|
22
|
+
* "12Y5vW6gk8GceH53YfRkRre2Rrcsgw7Naq", // vhp
|
|
23
|
+
* "12VoHz41a4HtfiyhTWbg9RXqGMRbYk6pXh", // vortex usdt
|
|
24
|
+
* "1Tf1QKv3gVYLjq34yURSHw5ErTYbFjqTG", // vortex eth
|
|
25
|
+
* ];
|
|
26
|
+
*
|
|
27
|
+
* const provider = new Provider("https://api.koinos.io");
|
|
28
|
+
*
|
|
29
|
+
* // create an array of the different contracts
|
|
30
|
+
* // used in the multicall
|
|
31
|
+
* const contracts = [];
|
|
32
|
+
* for (const token of tokens) {
|
|
33
|
+
* contracts.push(
|
|
34
|
+
* new Contract({
|
|
35
|
+
* id: token,
|
|
36
|
+
* provider,
|
|
37
|
+
* abi: utils.tokenAbi,
|
|
38
|
+
* })
|
|
39
|
+
* );
|
|
40
|
+
* }
|
|
41
|
+
*
|
|
42
|
+
* // create the multicall instance
|
|
43
|
+
* const multicall = new Multicall({
|
|
44
|
+
* provider,
|
|
45
|
+
* contracts
|
|
46
|
+
* });
|
|
47
|
+
*
|
|
48
|
+
* // add operations to the multicall
|
|
49
|
+
* for (const contract of contracts) {
|
|
50
|
+
* await multicall.add(contract.functions.balanceOf, {
|
|
51
|
+
* owner: "1MdqwaSBy6rbasPJ9vmg2pZFJSVZ29GFpZ",
|
|
52
|
+
* });
|
|
53
|
+
* }
|
|
54
|
+
*
|
|
55
|
+
* // call the multicall
|
|
56
|
+
* const results = await multicall.call();
|
|
57
|
+
* console.log(results);
|
|
58
|
+
* ```
|
|
59
|
+
*
|
|
60
|
+
* For testnet set the id to the multicall contract address for testnet
|
|
61
|
+
* ```ts
|
|
62
|
+
* const multicall = new Multicall({
|
|
63
|
+
* id: "1MM9ydA8SdgXvCTH3LdQ5FS8JvHijCmGSg",
|
|
64
|
+
* provider: new Provider("https://testnet-api.koinos.io"),
|
|
65
|
+
* contracts: [ koinContract, fogataPoolContract ],
|
|
66
|
+
* });
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
constructor(c: {
|
|
70
|
+
/**
|
|
71
|
+
* Multicall contract address. Leave it undefined
|
|
72
|
+
* to use the mainnet multicall contract address.
|
|
73
|
+
*/
|
|
74
|
+
id?: string;
|
|
75
|
+
provider?: ProviderInterface;
|
|
76
|
+
contracts?: Contract[];
|
|
77
|
+
}) {
|
|
78
|
+
if (c.id) this.id = c.id;
|
|
79
|
+
else this.id = "18dVCqPG3gwgL7DWQAciKYNuXfzEg5LW7"; // multicontract address mainnet
|
|
80
|
+
this.transaction = new Transaction({ provider: c.provider });
|
|
81
|
+
this.contracts = c.contracts || [];
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
async add(
|
|
85
|
+
input:
|
|
86
|
+
| OperationJson
|
|
87
|
+
| { operation: OperationJson }
|
|
88
|
+
| Promise<{ operation: OperationJson }>
|
|
89
|
+
| Contract["functions"]["x"],
|
|
90
|
+
args?: unknown
|
|
91
|
+
): Promise<void> {
|
|
92
|
+
await this.transaction.pushOperation(input, args);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
async call<T = Record<string, unknown>>(): Promise<(T | Error)[]> {
|
|
96
|
+
const multicallContract = new Contract({
|
|
97
|
+
id: this.id,
|
|
98
|
+
provider: this.transaction.provider,
|
|
99
|
+
abi: multicallAbi,
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
const calls = this.transaction.transaction.operations!.map(
|
|
103
|
+
(op) => op.call_contract!
|
|
104
|
+
);
|
|
105
|
+
const { result: multicallResult } = await multicallContract.functions.get({
|
|
106
|
+
calls,
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
const results: (T | Error)[] = [];
|
|
110
|
+
|
|
111
|
+
for (let i = 0; i < calls.length; i += 1) {
|
|
112
|
+
const contract = this.contracts.find(
|
|
113
|
+
(c) => c.getId() === calls[i].contract_id
|
|
114
|
+
);
|
|
115
|
+
if (contract && contract.abi) {
|
|
116
|
+
const method = Object.values(contract.abi.methods).find((method) => {
|
|
117
|
+
return method.entry_point === calls[i].entry_point;
|
|
118
|
+
});
|
|
119
|
+
if (method) {
|
|
120
|
+
const decoded = (await contract!.serializer!.deserialize(
|
|
121
|
+
multicallResult!.results[i]!.res.object,
|
|
122
|
+
method.return
|
|
123
|
+
)) as T;
|
|
124
|
+
results.push(decoded as T);
|
|
125
|
+
} else {
|
|
126
|
+
results.push(
|
|
127
|
+
new Error(
|
|
128
|
+
`Method ${calls[i].entry_point} not found in contract ${calls[i].contract_id}`
|
|
129
|
+
)
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
} else {
|
|
133
|
+
results.push(new Error(`Contract ${calls[i].contract_id} not found`));
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return results;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { AnyNestedObject } from "protobufjs";
|
|
2
|
+
import { Abi } from "../interface";
|
|
3
|
+
|
|
4
|
+
export const multicallAbi: Abi = {
|
|
5
|
+
methods: {
|
|
6
|
+
get: {
|
|
7
|
+
argument: "multicall.get_args",
|
|
8
|
+
return: "multicall.get_return",
|
|
9
|
+
description: "Get the result of a multicall",
|
|
10
|
+
entry_point: 697873187,
|
|
11
|
+
read_only: true,
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
types:
|
|
15
|
+
"CvEDCg9tdWx0aWNhbGwucHJvdG8SCW11bHRpY2FsbBoUa29pbm9zL29wdGlvbnMucHJvdG8ibAoOY2FsbF9hcmd1bWVudHMSJQoLY29udHJhY3RfaWQYASABKAxCBIC1GAVSCmNvbnRyYWN0SWQSHwoLZW50cnlfcG9pbnQYAiABKA1SCmVudHJ5UG9pbnQSEgoEYXJncxgDIAEoDFIEYXJncyJaCgZyZXN1bHQSGAoGb2JqZWN0GAEgASgMSABSBm9iamVjdBItCgVlcnJvchgCIAEoCzIVLm11bHRpY2FsbC5lcnJvcl9kYXRhSABSBWVycm9yQgcKBXZhbHVlIiYKCmVycm9yX2RhdGESGAoHbWVzc2FnZRgBIAEoCVIHbWVzc2FnZSI7CghnZXRfYXJncxIvCgVjYWxscxgBIAMoCzIZLm11bHRpY2FsbC5jYWxsX2FyZ3VtZW50c1IFY2FsbHMiRgoLY2FsbF9yZXR1cm4SEgoEY29kZRgBIAEoBVIEY29kZRIjCgNyZXMYAiABKAsyES5tdWx0aWNhbGwucmVzdWx0UgNyZXMiPgoKZ2V0X3JldHVybhIwCgdyZXN1bHRzGAEgAygLMhYubXVsdGljYWxsLmNhbGxfcmV0dXJuUgdyZXN1bHRzYgZwcm90bzM=",
|
|
16
|
+
koilib_types: {
|
|
17
|
+
nested: {
|
|
18
|
+
multicall: {
|
|
19
|
+
nested: {
|
|
20
|
+
call_arguments: {
|
|
21
|
+
fields: {
|
|
22
|
+
contract_id: {
|
|
23
|
+
type: "bytes",
|
|
24
|
+
id: 1,
|
|
25
|
+
options: {
|
|
26
|
+
"(koinos.btype)": "CONTRACT_ID",
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
entry_point: {
|
|
30
|
+
type: "uint32",
|
|
31
|
+
id: 2,
|
|
32
|
+
},
|
|
33
|
+
args: {
|
|
34
|
+
type: "bytes",
|
|
35
|
+
id: 3,
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
result: {
|
|
40
|
+
oneofs: {
|
|
41
|
+
value: {
|
|
42
|
+
oneof: ["object", "error"],
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
fields: {
|
|
46
|
+
object: {
|
|
47
|
+
type: "bytes",
|
|
48
|
+
id: 1,
|
|
49
|
+
},
|
|
50
|
+
error: {
|
|
51
|
+
type: "error_data",
|
|
52
|
+
id: 2,
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
error_data: {
|
|
57
|
+
fields: {
|
|
58
|
+
message: {
|
|
59
|
+
type: "string",
|
|
60
|
+
id: 1,
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
get_args: {
|
|
65
|
+
fields: {
|
|
66
|
+
calls: {
|
|
67
|
+
rule: "repeated",
|
|
68
|
+
type: "call_arguments",
|
|
69
|
+
id: 1,
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
call_return: {
|
|
74
|
+
fields: {
|
|
75
|
+
code: {
|
|
76
|
+
type: "int32",
|
|
77
|
+
id: 1,
|
|
78
|
+
},
|
|
79
|
+
res: {
|
|
80
|
+
type: "result",
|
|
81
|
+
id: 2,
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
get_return: {
|
|
86
|
+
fields: {
|
|
87
|
+
results: {
|
|
88
|
+
rule: "repeated",
|
|
89
|
+
type: "call_return",
|
|
90
|
+
id: 1,
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
koinos: {
|
|
97
|
+
options: {
|
|
98
|
+
go_package: "github.com/koinos/koinos-proto-golang/koinos",
|
|
99
|
+
},
|
|
100
|
+
nested: {
|
|
101
|
+
bytes_type: {
|
|
102
|
+
values: {
|
|
103
|
+
BASE64: 0,
|
|
104
|
+
BASE58: 1,
|
|
105
|
+
HEX: 2,
|
|
106
|
+
BLOCK_ID: 3,
|
|
107
|
+
TRANSACTION_ID: 4,
|
|
108
|
+
CONTRACT_ID: 5,
|
|
109
|
+
ADDRESS: 6,
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
_btype: {
|
|
113
|
+
oneof: ["btype"],
|
|
114
|
+
} as AnyNestedObject,
|
|
115
|
+
btype: {
|
|
116
|
+
type: "bytes_type",
|
|
117
|
+
id: 50000,
|
|
118
|
+
extend: "google.protobuf.FieldOptions",
|
|
119
|
+
options: {
|
|
120
|
+
proto3_optional: true,
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
};
|
package/src/index.ts
CHANGED
package/src/index2.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { Signer } from "./Signer";
|
|
|
6
6
|
import { Provider } from "./Provider";
|
|
7
7
|
import { Transaction } from "./Transaction";
|
|
8
8
|
import { Serializer } from "./Serializer";
|
|
9
|
+
import { Multicall } from "./Multicall";
|
|
9
10
|
|
|
10
11
|
declare const window: { [x: string]: unknown };
|
|
11
12
|
|
|
@@ -15,3 +16,4 @@ window.Signer = Signer;
|
|
|
15
16
|
window.Provider = Provider;
|
|
16
17
|
window.Transaction = Transaction;
|
|
17
18
|
window.Serializer = Serializer;
|
|
19
|
+
window.Multicall = Multicall;
|