Skip to content

Commit 5c00e9e

Browse files
committed
feat: deploying multiple messengers
1 parent 51e7cf1 commit 5c00e9e

File tree

9 files changed

+234
-252
lines changed

9 files changed

+234
-252
lines changed

chainlinkUtils.ts

Lines changed: 49 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
import axios from 'axios';
22
import { ChainlinkNodeConfiguration } from './types';
33

4-
const fs = require('fs');
5-
6-
const appRoot = require('app-root-path');
7-
const dslaProtocolJsonPath = `${appRoot.path}/services/dsla-protocol.json`;
8-
94
let cookies = {};
105

116
const getChainlinkSessionCookie = async (node: ChainlinkNodeConfiguration) => {
@@ -45,9 +40,11 @@ const getChainlinkAccounts = async (node: ChainlinkNodeConfiguration) => {
4540
return data;
4641
};
4742

48-
const getChainlinkBridge = async (node: ChainlinkNodeConfiguration) => {
43+
const getChainlinkBridges = async (node: ChainlinkNodeConfiguration) => {
4944
const sessionCookie = await getChainlinkSessionCookie(node);
50-
const { data } = await axios({
45+
const {
46+
data: { data },
47+
} = await axios({
5148
method: 'get',
5249
url: `${node.restApiUrl}${
5350
node.restApiPort ? ':' + node.restApiPort : undefined
@@ -58,15 +55,14 @@ const getChainlinkBridge = async (node: ChainlinkNodeConfiguration) => {
5855
},
5956
withCredentials: true,
6057
});
61-
const jobJson = JSON.parse(fs.readFileSync(dslaProtocolJsonPath));
62-
return data.data.find(
63-
(bridge) => bridge.attributes.name === jobJson.tasks[0].type
64-
);
58+
return data;
6559
};
6660

67-
const getChainlinkJob = async (node: ChainlinkNodeConfiguration) => {
61+
const getChainlinkJobs = async (node: ChainlinkNodeConfiguration) => {
6862
const sessionCookie = await getChainlinkSessionCookie(node);
69-
const { data } = await axios({
63+
const {
64+
data: { data },
65+
} = await axios({
7066
method: 'get',
7167
url: `${node.restApiUrl}${
7268
node.restApiPort ? ':' + node.restApiPort : undefined
@@ -77,10 +73,7 @@ const getChainlinkJob = async (node: ChainlinkNodeConfiguration) => {
7773
},
7874
withCredentials: true,
7975
});
80-
const jobJson = JSON.parse(fs.readFileSync(dslaProtocolJsonPath));
81-
return data.data.find((job) =>
82-
job.attributes.tasks.some((task) => task.type === jobJson.tasks[0].type)
83-
);
76+
return data;
8477
};
8578

8679
const getChainlinkJobId = async (node: ChainlinkNodeConfiguration) => {
@@ -99,7 +92,11 @@ const getChainlinkJobId = async (node: ChainlinkNodeConfiguration) => {
9992
return `0x${data.data[0].id}`;
10093
};
10194

102-
const postChainlinkJob = async (node: ChainlinkNodeConfiguration) => {
95+
const postChainlinkJob = async (
96+
node: ChainlinkNodeConfiguration,
97+
jobName,
98+
oracleContractAddress
99+
) => {
103100
const sessionCookie = await getChainlinkSessionCookie(node);
104101
const { data } = await axios({
105102
method: 'post',
@@ -111,15 +108,41 @@ const postChainlinkJob = async (node: ChainlinkNodeConfiguration) => {
111108
'Content-Type': 'application/json',
112109
},
113110
// eslint-disable-next-line global-require,import/no-dynamic-require
114-
data: require(dslaProtocolJsonPath),
111+
data: {
112+
initiators: [
113+
{
114+
type: 'RunLog',
115+
params: {
116+
address: oracleContractAddress,
117+
},
118+
},
119+
],
120+
tasks: [
121+
{
122+
type: jobName,
123+
},
124+
{
125+
type: 'copy',
126+
params: {
127+
copyPath: ['result'],
128+
},
129+
},
130+
{
131+
type: 'ethtx',
132+
},
133+
],
134+
minPayment: '10000000000',
135+
},
115136
withCredentials: true,
116137
});
117138
return data;
118139
};
119140

120-
const postChainlinkBridge = async (node: ChainlinkNodeConfiguration) => {
121-
const jobJson = JSON.parse(fs.readFileSync(dslaProtocolJsonPath));
122-
141+
const postChainlinkBridge = async (
142+
node: ChainlinkNodeConfiguration,
143+
useCaseName,
144+
externalAdapterUrl
145+
) => {
123146
const sessionCookie = await getChainlinkSessionCookie(node);
124147
const { data } = await axios({
125148
method: 'post',
@@ -131,8 +154,8 @@ const postChainlinkBridge = async (node: ChainlinkNodeConfiguration) => {
131154
'Content-Type': 'application/json',
132155
},
133156
data: {
134-
name: jobJson.tasks[0].type,
135-
url: node.externalAdapterUrl,
157+
name: useCaseName,
158+
url: externalAdapterUrl,
136159
},
137160
withCredentials: true,
138161
});
@@ -159,9 +182,9 @@ export {
159182
deleteJob,
160183
postChainlinkJob,
161184
postChainlinkBridge,
162-
getChainlinkJob,
185+
getChainlinkJobs,
163186
getChainlinkJobId,
164-
getChainlinkBridge,
187+
getChainlinkBridges,
165188
getChainlinkAccounts,
166189
getChainlinkSessionCookie,
167190
};

constants.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ export enum DEPLOYMENT_TAGS {
5151
Chainlink = 'chainlink',
5252
Services = 'services',
5353
Details = 'details',
54+
Messengers = 'messengers',
55+
}
56+
57+
export enum USE_CASES {
58+
STAKING_EFFICIENCY = 'staking-efficiency',
5459
}
5560

5661
export enum NETWORKS {

deploy/3_deploy_messengers.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { StackticalConfiguration } from '../types';
2+
import { CONTRACT_NAMES, DEPLOYMENT_TAGS } from '../constants';
3+
import { SUB_TASK_NAMES } from '../subtasks';
4+
5+
module.exports = async ({ getNamedAccounts, deployments, network, run }) => {
6+
const { stacktical }: { stacktical: StackticalConfiguration } =
7+
network.config;
8+
const { deployer } = await getNamedAccounts();
9+
const { deploy, get } = deployments;
10+
const stringUtils = await get(CONTRACT_NAMES.StringUtils);
11+
const periodRegistry = await get(CONTRACT_NAMES.PeriodRegistry);
12+
const linkToken = await get(CONTRACT_NAMES.LinkToken);
13+
14+
for (let messenger of stacktical.bootstrap.registry.messengers) {
15+
const saId = await run(SUB_TASK_NAMES.SET_PRECOORDINATOR, {
16+
useCaseName: messenger.useCaseName,
17+
});
18+
const preCoordinator = await get(CONTRACT_NAMES.PreCoordinator);
19+
const feeMultiplier = stacktical.chainlink.nodesConfiguration.length;
20+
await deploy(messenger.contract, {
21+
from: deployer,
22+
log: true,
23+
args: [
24+
preCoordinator.address,
25+
linkToken.address,
26+
saId,
27+
feeMultiplier,
28+
periodRegistry.address,
29+
],
30+
libraries: {
31+
StringUtils: stringUtils.address,
32+
},
33+
});
34+
}
35+
};
36+
37+
module.exports.tags = [DEPLOYMENT_TAGS.Messengers];

deploy/3_deploy_staking_efficiency.ts

Lines changed: 0 additions & 61 deletions
This file was deleted.

services/dsla-protocol.json

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)