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.
@@ -0,0 +1,79 @@
1
+ import { Contract } from "./Contract";
2
+ import { OperationJson } from "./interface";
3
+ import { ProviderInterface } from "./Provider";
4
+ import { Transaction } from "./Transaction";
5
+ export declare class Multicall {
6
+ /**
7
+ * Multicall contract address
8
+ */
9
+ id: string;
10
+ transaction: Transaction;
11
+ contracts: Contract[];
12
+ /**
13
+ * @example
14
+ * ```ts
15
+ * const tokens = [
16
+ * "19GYjDBVXU7keLbYvMLazsGQn3GTWHjHkK", // koin
17
+ * "12Y5vW6gk8GceH53YfRkRre2Rrcsgw7Naq", // vhp
18
+ * "12VoHz41a4HtfiyhTWbg9RXqGMRbYk6pXh", // vortex usdt
19
+ * "1Tf1QKv3gVYLjq34yURSHw5ErTYbFjqTG", // vortex eth
20
+ * ];
21
+ *
22
+ * const provider = new Provider("https://api.koinos.io");
23
+ *
24
+ * // create an array of the different contracts
25
+ * // used in the multicall
26
+ * const contracts = [];
27
+ * for (const token of tokens) {
28
+ * contracts.push(
29
+ * new Contract({
30
+ * id: token,
31
+ * provider,
32
+ * abi: utils.tokenAbi,
33
+ * })
34
+ * );
35
+ * }
36
+ *
37
+ * // create the multicall instance
38
+ * const multicall = new Multicall({
39
+ * provider,
40
+ * contracts
41
+ * });
42
+ *
43
+ * // add operations to the multicall
44
+ * for (const contract of contracts) {
45
+ * await multicall.add(contract.functions.balanceOf, {
46
+ * owner: "1MdqwaSBy6rbasPJ9vmg2pZFJSVZ29GFpZ",
47
+ * });
48
+ * }
49
+ *
50
+ * // call the multicall
51
+ * const results = await multicall.call();
52
+ * console.log(results);
53
+ * ```
54
+ *
55
+ * For testnet set the id to the multicall contract address for testnet
56
+ * ```ts
57
+ * const multicall = new Multicall({
58
+ * id: "1MM9ydA8SdgXvCTH3LdQ5FS8JvHijCmGSg",
59
+ * provider: new Provider("https://testnet-api.koinos.io"),
60
+ * contracts: [ koinContract, fogataPoolContract ],
61
+ * });
62
+ * ```
63
+ */
64
+ constructor(c: {
65
+ /**
66
+ * Multicall contract address. Leave it undefined
67
+ * to use the mainnet multicall contract address.
68
+ */
69
+ id?: string;
70
+ provider?: ProviderInterface;
71
+ contracts?: Contract[];
72
+ });
73
+ add(input: OperationJson | {
74
+ operation: OperationJson;
75
+ } | Promise<{
76
+ operation: OperationJson;
77
+ }> | Contract["functions"]["x"], args?: unknown): Promise<void>;
78
+ call<T = Record<string, unknown>>(): Promise<(T | Error)[]>;
79
+ }
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Multicall = void 0;
4
+ const Contract_1 = require("./Contract");
5
+ const Transaction_1 = require("./Transaction");
6
+ const multicallAbi_1 = require("./abis/multicallAbi");
7
+ class Multicall {
8
+ /**
9
+ * @example
10
+ * ```ts
11
+ * const tokens = [
12
+ * "19GYjDBVXU7keLbYvMLazsGQn3GTWHjHkK", // koin
13
+ * "12Y5vW6gk8GceH53YfRkRre2Rrcsgw7Naq", // vhp
14
+ * "12VoHz41a4HtfiyhTWbg9RXqGMRbYk6pXh", // vortex usdt
15
+ * "1Tf1QKv3gVYLjq34yURSHw5ErTYbFjqTG", // vortex eth
16
+ * ];
17
+ *
18
+ * const provider = new Provider("https://api.koinos.io");
19
+ *
20
+ * // create an array of the different contracts
21
+ * // used in the multicall
22
+ * const contracts = [];
23
+ * for (const token of tokens) {
24
+ * contracts.push(
25
+ * new Contract({
26
+ * id: token,
27
+ * provider,
28
+ * abi: utils.tokenAbi,
29
+ * })
30
+ * );
31
+ * }
32
+ *
33
+ * // create the multicall instance
34
+ * const multicall = new Multicall({
35
+ * provider,
36
+ * contracts
37
+ * });
38
+ *
39
+ * // add operations to the multicall
40
+ * for (const contract of contracts) {
41
+ * await multicall.add(contract.functions.balanceOf, {
42
+ * owner: "1MdqwaSBy6rbasPJ9vmg2pZFJSVZ29GFpZ",
43
+ * });
44
+ * }
45
+ *
46
+ * // call the multicall
47
+ * const results = await multicall.call();
48
+ * console.log(results);
49
+ * ```
50
+ *
51
+ * For testnet set the id to the multicall contract address for testnet
52
+ * ```ts
53
+ * const multicall = new Multicall({
54
+ * id: "1MM9ydA8SdgXvCTH3LdQ5FS8JvHijCmGSg",
55
+ * provider: new Provider("https://testnet-api.koinos.io"),
56
+ * contracts: [ koinContract, fogataPoolContract ],
57
+ * });
58
+ * ```
59
+ */
60
+ constructor(c) {
61
+ if (c.id)
62
+ this.id = c.id;
63
+ else
64
+ this.id = "18dVCqPG3gwgL7DWQAciKYNuXfzEg5LW7"; // multicontract address mainnet
65
+ this.transaction = new Transaction_1.Transaction({ provider: c.provider });
66
+ this.contracts = c.contracts || [];
67
+ }
68
+ async add(input, args) {
69
+ await this.transaction.pushOperation(input, args);
70
+ }
71
+ async call() {
72
+ const multicallContract = new Contract_1.Contract({
73
+ id: this.id,
74
+ provider: this.transaction.provider,
75
+ abi: multicallAbi_1.multicallAbi,
76
+ });
77
+ const calls = this.transaction.transaction.operations.map((op) => op.call_contract);
78
+ const { result: multicallResult } = await multicallContract.functions.get({
79
+ calls,
80
+ });
81
+ const results = [];
82
+ for (let i = 0; i < calls.length; i += 1) {
83
+ const contract = this.contracts.find((c) => c.getId() === calls[i].contract_id);
84
+ if (contract && contract.abi) {
85
+ const method = Object.values(contract.abi.methods).find((method) => {
86
+ return method.entry_point === calls[i].entry_point;
87
+ });
88
+ if (method) {
89
+ const decoded = (await contract.serializer.deserialize(multicallResult.results[i].res.object, method.return));
90
+ results.push(decoded);
91
+ }
92
+ else {
93
+ results.push(new Error(`Method ${calls[i].entry_point} not found in contract ${calls[i].contract_id}`));
94
+ }
95
+ }
96
+ else {
97
+ results.push(new Error(`Contract ${calls[i].contract_id} not found`));
98
+ }
99
+ }
100
+ return results;
101
+ }
102
+ }
103
+ exports.Multicall = Multicall;
104
+ //# sourceMappingURL=Multicall.js.map
@@ -0,0 +1 @@
1
+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Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.multicallAbi = void 0;
4
+ exports.multicallAbi = {
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: "CvEDCg9tdWx0aWNhbGwucHJvdG8SCW11bHRpY2FsbBoUa29pbm9zL29wdGlvbnMucHJvdG8ibAoOY2FsbF9hcmd1bWVudHMSJQoLY29udHJhY3RfaWQYASABKAxCBIC1GAVSCmNvbnRyYWN0SWQSHwoLZW50cnlfcG9pbnQYAiABKA1SCmVudHJ5UG9pbnQSEgoEYXJncxgDIAEoDFIEYXJncyJaCgZyZXN1bHQSGAoGb2JqZWN0GAEgASgMSABSBm9iamVjdBItCgVlcnJvchgCIAEoCzIVLm11bHRpY2FsbC5lcnJvcl9kYXRhSABSBWVycm9yQgcKBXZhbHVlIiYKCmVycm9yX2RhdGESGAoHbWVzc2FnZRgBIAEoCVIHbWVzc2FnZSI7CghnZXRfYXJncxIvCgVjYWxscxgBIAMoCzIZLm11bHRpY2FsbC5jYWxsX2FyZ3VtZW50c1IFY2FsbHMiRgoLY2FsbF9yZXR1cm4SEgoEY29kZRgBIAEoBVIEY29kZRIjCgNyZXMYAiABKAsyES5tdWx0aWNhbGwucmVzdWx0UgNyZXMiPgoKZ2V0X3JldHVybhIwCgdyZXN1bHRzGAEgAygLMhYubXVsdGljYWxsLmNhbGxfcmV0dXJuUgdyZXN1bHRzYgZwcm90bzM=",
15
+ koilib_types: {
16
+ nested: {
17
+ multicall: {
18
+ nested: {
19
+ call_arguments: {
20
+ fields: {
21
+ contract_id: {
22
+ type: "bytes",
23
+ id: 1,
24
+ options: {
25
+ "(koinos.btype)": "CONTRACT_ID",
26
+ },
27
+ },
28
+ entry_point: {
29
+ type: "uint32",
30
+ id: 2,
31
+ },
32
+ args: {
33
+ type: "bytes",
34
+ id: 3,
35
+ },
36
+ },
37
+ },
38
+ result: {
39
+ oneofs: {
40
+ value: {
41
+ oneof: ["object", "error"],
42
+ },
43
+ },
44
+ fields: {
45
+ object: {
46
+ type: "bytes",
47
+ id: 1,
48
+ },
49
+ error: {
50
+ type: "error_data",
51
+ id: 2,
52
+ },
53
+ },
54
+ },
55
+ error_data: {
56
+ fields: {
57
+ message: {
58
+ type: "string",
59
+ id: 1,
60
+ },
61
+ },
62
+ },
63
+ get_args: {
64
+ fields: {
65
+ calls: {
66
+ rule: "repeated",
67
+ type: "call_arguments",
68
+ id: 1,
69
+ },
70
+ },
71
+ },
72
+ call_return: {
73
+ fields: {
74
+ code: {
75
+ type: "int32",
76
+ id: 1,
77
+ },
78
+ res: {
79
+ type: "result",
80
+ id: 2,
81
+ },
82
+ },
83
+ },
84
+ get_return: {
85
+ fields: {
86
+ results: {
87
+ rule: "repeated",
88
+ type: "call_return",
89
+ id: 1,
90
+ },
91
+ },
92
+ },
93
+ },
94
+ },
95
+ koinos: {
96
+ options: {
97
+ go_package: "github.com/koinos/koinos-proto-golang/koinos",
98
+ },
99
+ nested: {
100
+ bytes_type: {
101
+ values: {
102
+ BASE64: 0,
103
+ BASE58: 1,
104
+ HEX: 2,
105
+ BLOCK_ID: 3,
106
+ TRANSACTION_ID: 4,
107
+ CONTRACT_ID: 5,
108
+ ADDRESS: 6,
109
+ },
110
+ },
111
+ _btype: {
112
+ oneof: ["btype"],
113
+ },
114
+ btype: {
115
+ type: "bytes_type",
116
+ id: 50000,
117
+ extend: "google.protobuf.FieldOptions",
118
+ options: {
119
+ proto3_optional: true,
120
+ },
121
+ },
122
+ },
123
+ },
124
+ },
125
+ },
126
+ };
127
+ //# sourceMappingURL=multicallAbi.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"multicallAbi.js","sourceRoot":"","sources":["../../src/abis/multicallAbi.ts"],"names":[],"mappings":";;;AAGa,QAAA,YAAY,GAAQ;IAC/B,OAAO,EAAE;QACP,GAAG,EAAE;YACH,QAAQ,EAAE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AE;gCACH,IAAI,EAAE,QAAQ;gCACd,EAAE,EAAE,CAAC;6BACN;yBACF;qBACF;oBACD,UAAU,EAAE;wBACV,MAAM,EAAE;4BACN,OAAO,EAAE;gCACP,IAAI,EAAE,UAAU;gCAChB,IAAI,EAAE,aAAa;gCACnB,EAAE,EAAE,CAAC;6BACN;yBACF;qBACF;iBACF;aACF;YACD,MAAM,EAAE;gBACN,OAAO,EAAE;oBACP,UAAU,EAAE,8CAA8C;iBAC3D;gBACD,MAAM,EAAE;oBACN,UAAU,EAAE;wBACV,MAAM,EAAE;4BACN,MAAM,EAAE,CAAC;4BACT,MAAM,EAAE,CAAC;4BACT,GAAG,EAAE,CAAC;4BACN,QAAQ,EAAE,CAAC;4BACX,cAAc,EAAE,CAAC;4BACjB,WAAW,EAAE,CAAC;4BACd,OAAO,EAAE,CAAC;yBACX;qBACF;oBACD,MAAM,EAAE;wBACN,KAAK,EAAE,CAAC,OAAO,CAAC;qBACE;oBACpB,KAAK,EAAE;wBACL,IAAI,EAAE,YAAY;wBAClB,EAAE,EAAE,KAAK;wBACT,MAAM,EAAE,8BAA8B;wBACtC,OAAO,EAAE;4BACP,eAAe,EAAE,IAAI;yBACtB;qBACF;iBACF;aACF;SACF;KACF;CACF,CAAC"}
@@ -0,0 +1,79 @@
1
+ import { Contract } from "./Contract";
2
+ import { OperationJson } from "./interface";
3
+ import { ProviderInterface } from "./Provider";
4
+ import { Transaction } from "./Transaction";
5
+ export declare class Multicall {
6
+ /**
7
+ * Multicall contract address
8
+ */
9
+ id: string;
10
+ transaction: Transaction;
11
+ contracts: Contract[];
12
+ /**
13
+ * @example
14
+ * ```ts
15
+ * const tokens = [
16
+ * "19GYjDBVXU7keLbYvMLazsGQn3GTWHjHkK", // koin
17
+ * "12Y5vW6gk8GceH53YfRkRre2Rrcsgw7Naq", // vhp
18
+ * "12VoHz41a4HtfiyhTWbg9RXqGMRbYk6pXh", // vortex usdt
19
+ * "1Tf1QKv3gVYLjq34yURSHw5ErTYbFjqTG", // vortex eth
20
+ * ];
21
+ *
22
+ * const provider = new Provider("https://api.koinos.io");
23
+ *
24
+ * // create an array of the different contracts
25
+ * // used in the multicall
26
+ * const contracts = [];
27
+ * for (const token of tokens) {
28
+ * contracts.push(
29
+ * new Contract({
30
+ * id: token,
31
+ * provider,
32
+ * abi: utils.tokenAbi,
33
+ * })
34
+ * );
35
+ * }
36
+ *
37
+ * // create the multicall instance
38
+ * const multicall = new Multicall({
39
+ * provider,
40
+ * contracts
41
+ * });
42
+ *
43
+ * // add operations to the multicall
44
+ * for (const contract of contracts) {
45
+ * await multicall.add(contract.functions.balanceOf, {
46
+ * owner: "1MdqwaSBy6rbasPJ9vmg2pZFJSVZ29GFpZ",
47
+ * });
48
+ * }
49
+ *
50
+ * // call the multicall
51
+ * const results = await multicall.call();
52
+ * console.log(results);
53
+ * ```
54
+ *
55
+ * For testnet set the id to the multicall contract address for testnet
56
+ * ```ts
57
+ * const multicall = new Multicall({
58
+ * id: "1MM9ydA8SdgXvCTH3LdQ5FS8JvHijCmGSg",
59
+ * provider: new Provider("https://testnet-api.koinos.io"),
60
+ * contracts: [ koinContract, fogataPoolContract ],
61
+ * });
62
+ * ```
63
+ */
64
+ constructor(c: {
65
+ /**
66
+ * Multicall contract address. Leave it undefined
67
+ * to use the mainnet multicall contract address.
68
+ */
69
+ id?: string;
70
+ provider?: ProviderInterface;
71
+ contracts?: Contract[];
72
+ });
73
+ add(input: OperationJson | {
74
+ operation: OperationJson;
75
+ } | Promise<{
76
+ operation: OperationJson;
77
+ }> | Contract["functions"]["x"], args?: unknown): Promise<void>;
78
+ call<T = Record<string, unknown>>(): Promise<(T | Error)[]>;
79
+ }
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Multicall = void 0;
4
+ const Contract_1 = require("./Contract");
5
+ const Transaction_1 = require("./Transaction");
6
+ const multicallAbi_1 = require("./abis/multicallAbi");
7
+ class Multicall {
8
+ /**
9
+ * @example
10
+ * ```ts
11
+ * const tokens = [
12
+ * "19GYjDBVXU7keLbYvMLazsGQn3GTWHjHkK", // koin
13
+ * "12Y5vW6gk8GceH53YfRkRre2Rrcsgw7Naq", // vhp
14
+ * "12VoHz41a4HtfiyhTWbg9RXqGMRbYk6pXh", // vortex usdt
15
+ * "1Tf1QKv3gVYLjq34yURSHw5ErTYbFjqTG", // vortex eth
16
+ * ];
17
+ *
18
+ * const provider = new Provider("https://api.koinos.io");
19
+ *
20
+ * // create an array of the different contracts
21
+ * // used in the multicall
22
+ * const contracts = [];
23
+ * for (const token of tokens) {
24
+ * contracts.push(
25
+ * new Contract({
26
+ * id: token,
27
+ * provider,
28
+ * abi: utils.tokenAbi,
29
+ * })
30
+ * );
31
+ * }
32
+ *
33
+ * // create the multicall instance
34
+ * const multicall = new Multicall({
35
+ * provider,
36
+ * contracts
37
+ * });
38
+ *
39
+ * // add operations to the multicall
40
+ * for (const contract of contracts) {
41
+ * await multicall.add(contract.functions.balanceOf, {
42
+ * owner: "1MdqwaSBy6rbasPJ9vmg2pZFJSVZ29GFpZ",
43
+ * });
44
+ * }
45
+ *
46
+ * // call the multicall
47
+ * const results = await multicall.call();
48
+ * console.log(results);
49
+ * ```
50
+ *
51
+ * For testnet set the id to the multicall contract address for testnet
52
+ * ```ts
53
+ * const multicall = new Multicall({
54
+ * id: "1MM9ydA8SdgXvCTH3LdQ5FS8JvHijCmGSg",
55
+ * provider: new Provider("https://testnet-api.koinos.io"),
56
+ * contracts: [ koinContract, fogataPoolContract ],
57
+ * });
58
+ * ```
59
+ */
60
+ constructor(c) {
61
+ if (c.id)
62
+ this.id = c.id;
63
+ else
64
+ this.id = "18dVCqPG3gwgL7DWQAciKYNuXfzEg5LW7"; // multicontract address mainnet
65
+ this.transaction = new Transaction_1.Transaction({ provider: c.provider });
66
+ this.contracts = c.contracts || [];
67
+ }
68
+ async add(input, args) {
69
+ await this.transaction.pushOperation(input, args);
70
+ }
71
+ async call() {
72
+ const multicallContract = new Contract_1.Contract({
73
+ id: this.id,
74
+ provider: this.transaction.provider,
75
+ abi: multicallAbi_1.multicallAbi,
76
+ });
77
+ const calls = this.transaction.transaction.operations.map((op) => op.call_contract);
78
+ const { result: multicallResult } = await multicallContract.functions.get({
79
+ calls,
80
+ });
81
+ const results = [];
82
+ for (let i = 0; i < calls.length; i += 1) {
83
+ const contract = this.contracts.find((c) => c.getId() === calls[i].contract_id);
84
+ if (contract && contract.abi) {
85
+ const method = Object.values(contract.abi.methods).find((method) => {
86
+ return method.entry_point === calls[i].entry_point;
87
+ });
88
+ if (method) {
89
+ const decoded = (await contract.serializer.deserialize(multicallResult.results[i].res.object, method.return));
90
+ results.push(decoded);
91
+ }
92
+ else {
93
+ results.push(new Error(`Method ${calls[i].entry_point} not found in contract ${calls[i].contract_id}`));
94
+ }
95
+ }
96
+ else {
97
+ results.push(new Error(`Contract ${calls[i].contract_id} not found`));
98
+ }
99
+ }
100
+ return results;
101
+ }
102
+ }
103
+ exports.Multicall = Multicall;
104
+ //# sourceMappingURL=Multicall.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Multicall.js","sourceRoot":"","sources":["../../src/Multicall.ts"],"names":[],"mappings":";;;AAAA,yCAAsC;AAGtC,+CAA4C;AAC5C,sDAAmD;AAEnD,MAAa,SAAS;IAUpB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAmDG;IACH,YAAY,CAQX;QACC,IAAI,CAAC,CAAC,EAAE;YAAE,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC;;YACpB,IAAI,CAAC,EAAE,GAAG,mCAAmC,CAAC,CAAC,gCAAgC;QACpF,IAAI,CAAC,WAAW,GAAG,IAAI,yBAAW,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC;QAC7D,IAAI,CAAC,SAAS,GAAG,CAAC,CAAC,SAAS,IAAI,EAAE,CAAC;IACrC,CAAC;IAED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O,GAAG,CAAC,MAAM,QAAS,CAAC,UAAW,CAAC,WAAW,CACtD,eAAgB,CAAC,OAAO,CAAC,CAAC,CAAE,CAAC,GAAG,CAAC,MAAM,EACvC,MAAM,CAAC,MAAM,CACd,CAAM,CAAC;oBACR,OAAO,CAAC,IAAI,CAAC,OAAY,CAAC,CAAC;iBAC5B;qBAAM;oBACL,OAAO,CAAC,IAAI,CACV,IAAI,KAAK,CACP,UAAU,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,0BAA0B,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAC/E,CACF,CAAC;iBACH;aACF;iBAAM;gBACL,OAAO,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,YAAY,CAAC,CAAC,CAAC;aACvE;SACF;QAED,OAAO,OAAO,CAAC;IACjB,CAAC;CACF;AApID,8BAoIC"}
@@ -0,0 +1,2 @@
1
+ import { Abi } from "../interface";
2
+ export declare const multicallAbi: Abi;
@@ -0,0 +1,127 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.multicallAbi = void 0;
4
+ exports.multicallAbi = {
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: "CvEDCg9tdWx0aWNhbGwucHJvdG8SCW11bHRpY2FsbBoUa29pbm9zL29wdGlvbnMucHJvdG8ibAoOY2FsbF9hcmd1bWVudHMSJQoLY29udHJhY3RfaWQYASABKAxCBIC1GAVSCmNvbnRyYWN0SWQSHwoLZW50cnlfcG9pbnQYAiABKA1SCmVudHJ5UG9pbnQSEgoEYXJncxgDIAEoDFIEYXJncyJaCgZyZXN1bHQSGAoGb2JqZWN0GAEgASgMSABSBm9iamVjdBItCgVlcnJvchgCIAEoCzIVLm11bHRpY2FsbC5lcnJvcl9kYXRhSABSBWVycm9yQgcKBXZhbHVlIiYKCmVycm9yX2RhdGESGAoHbWVzc2FnZRgBIAEoCVIHbWVzc2FnZSI7CghnZXRfYXJncxIvCgVjYWxscxgBIAMoCzIZLm11bHRpY2FsbC5jYWxsX2FyZ3VtZW50c1IFY2FsbHMiRgoLY2FsbF9yZXR1cm4SEgoEY29kZRgBIAEoBVIEY29kZRIjCgNyZXMYAiABKAsyES5tdWx0aWNhbGwucmVzdWx0UgNyZXMiPgoKZ2V0X3JldHVybhIwCgdyZXN1bHRzGAEgAygLMhYubXVsdGljYWxsLmNhbGxfcmV0dXJuUgdyZXN1bHRzYgZwcm90bzM=",
15
+ koilib_types: {
16
+ nested: {
17
+ multicall: {
18
+ nested: {
19
+ call_arguments: {
20
+ fields: {
21
+ contract_id: {
22
+ type: "bytes",
23
+ id: 1,
24
+ options: {
25
+ "(koinos.btype)": "CONTRACT_ID",
26
+ },
27
+ },
28
+ entry_point: {
29
+ type: "uint32",
30
+ id: 2,
31
+ },
32
+ args: {
33
+ type: "bytes",
34
+ id: 3,
35
+ },
36
+ },
37
+ },
38
+ result: {
39
+ oneofs: {
40
+ value: {
41
+ oneof: ["object", "error"],
42
+ },
43
+ },
44
+ fields: {
45
+ object: {
46
+ type: "bytes",
47
+ id: 1,
48
+ },
49
+ error: {
50
+ type: "error_data",
51
+ id: 2,
52
+ },
53
+ },
54
+ },
55
+ error_data: {
56
+ fields: {
57
+ message: {
58
+ type: "string",
59
+ id: 1,
60
+ },
61
+ },
62
+ },
63
+ get_args: {
64
+ fields: {
65
+ calls: {
66
+ rule: "repeated",
67
+ type: "call_arguments",
68
+ id: 1,
69
+ },
70
+ },
71
+ },
72
+ call_return: {
73
+ fields: {
74
+ code: {
75
+ type: "int32",
76
+ id: 1,
77
+ },
78
+ res: {
79
+ type: "result",
80
+ id: 2,
81
+ },
82
+ },
83
+ },
84
+ get_return: {
85
+ fields: {
86
+ results: {
87
+ rule: "repeated",
88
+ type: "call_return",
89
+ id: 1,
90
+ },
91
+ },
92
+ },
93
+ },
94
+ },
95
+ koinos: {
96
+ options: {
97
+ go_package: "github.com/koinos/koinos-proto-golang/koinos",
98
+ },
99
+ nested: {
100
+ bytes_type: {
101
+ values: {
102
+ BASE64: 0,
103
+ BASE58: 1,
104
+ HEX: 2,
105
+ BLOCK_ID: 3,
106
+ TRANSACTION_ID: 4,
107
+ CONTRACT_ID: 5,
108
+ ADDRESS: 6,
109
+ },
110
+ },
111
+ _btype: {
112
+ oneof: ["btype"],
113
+ },
114
+ btype: {
115
+ type: "bytes_type",
116
+ id: 50000,
117
+ extend: "google.protobuf.FieldOptions",
118
+ options: {
119
+ proto3_optional: true,
120
+ },
121
+ },
122
+ },
123
+ },
124
+ },
125
+ },
126
+ };
127
+ //# sourceMappingURL=multicallAbi.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"multicallAbi.js","sourceRoot":"","sources":["../../../src/abis/multicallAbi.ts"],"names":[],"mappings":";;;AAGa,QAAA,YAAY,GAAQ;IAC/B,OAAO,EAAE;QACP,GAAG,EAAE;YACH,QAAQ,EAAE,oBAAoB;YAC9B,MAAM,EAAE,sBAAsB;YAC9B,WAAW,EAAE,+BAA+B;YAC5C,WAAW,EAAE,SAAS;YACtB,SAAS,EAAE,IAAI;SAChB;KACF;IACD,KAAK,EACH,8pBAA8pB;IAChqB,YAAY,EAAE;QACZ,MAAM,EAAE;YACN,SAAS,EAAE;gBACT,MAAM,EAAE;oBACN,cAAc,EAAE;wBACd,MAAM,EAAE;4BACN,WAAW,EAAE;gCACX,IAAI,EAAE,OAAO;gCACb,EAAE,EAAE,CAAC;gCACL,OAAO,EAAE;oCACP,gBAAgB,EAAE,aAAa;iCAChC;6BACF;4BACD,WAAW,EAAE;gCACX,IAAI,EAAE,QAAQ;gCACd,EAAE,EAAE,CAAC;6BACN;4BACD,IAAI,EAAE;gCACJ,IAAI,EAAE,OAAO;gCACb,EAAE,EAAE,CAAC;6BACN;yBACF;qBACF;oBACD,MAAM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wBACN,KAAK,EAAE,CAAC,OAAO,CAAC;qBACE;oBACpB,KAAK,EAAE;wBACL,IAAI,EAAE,YAAY;wBAClB,EAAE,EAAE,KAAK;wBACT,MAAM,EAAE,8BAA8B;wBACtC,OAAO,EAAE;4BACP,eAAe,EAAE,IAAI;yBACtB;qBACF;iBACF;aACF;SACF;KACF;CACF,CAAC"}
@@ -6,3 +6,4 @@ export * from "./Signer";
6
6
  export * from "./Provider";
7
7
  export * from "./Transaction";
8
8
  export * from "./Serializer";
9
+ export * from "./Multicall";
@@ -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
@@ -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"}