Skip to content

Commit

Permalink
Merge pull request #10 from Hephaestus-V/main
Browse files Browse the repository at this point in the history
Updated the Lit action Execution Server
  • Loading branch information
Hephaestus-V authored Sep 3, 2024
2 parents 2e1adde + a319eb0 commit adced87
Showing 1 changed file with 64 additions and 16 deletions.
80 changes: 64 additions & 16 deletions packages/nextjs/scripts/strategyExecutor.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ import { encryptString } from "@lit-protocol/encryption";

async function main() {
const strategy = {
threshold: 0.5,
threshold: 0.005,
};

const strategyString=JSON.stringify(strategy);
Expand Down Expand Up @@ -274,31 +274,79 @@ async function main() {
});
console.log("✅ Got Session Sigs via an Auth Sig");

const code = `(async () => {
const resp = await Lit.Actions.decryptAndCombine({
accessControlConditions,
ciphertext,
dataToEncryptHash,
authSig: null,
chain: 'ethereum',
});
// Example values for yields and current chain
const arbitrumYield = 0.05; // 5% yield on Arbitrum
const optimismYield = 0.06; // 6% yield on Optimism
const currentChain = "ethereum"; // Current chain where funds are


const a=JSON.parse(resp);
console.log(a);
console.log(meriYield);
const code = `
(async () => {
const resp = await Lit.Actions.decryptAndCombine({
accessControlConditions,
ciphertext,
dataToEncryptHash,
authSig: null,
chain: 'ethereum',
});
const strategy = JSON.parse(resp);
console.log("Decrypted strategy:", strategy);
const { threshold } = strategy;
let shouldMove = false;
let targetChain = currentChain;
if (currentChain === "ethereum") {
if (arbitrumYield > optimismYield && arbitrumYield > threshold) {
shouldMove = true;
targetChain = "arbitrum";
} else if (optimismYield > arbitrumYield && optimismYield > threshold) {
shouldMove = true;
targetChain = "optimism";
}
} else if (currentChain === "arbitrum") {
if (optimismYield > arbitrumYield && optimismYield > threshold) {
shouldMove = true;
targetChain = "optimism";
} else if (arbitrumYield < threshold) {
shouldMove = true;
targetChain = "ethereum";
}
} else if (currentChain === "optimism") {
if (arbitrumYield > optimismYield && arbitrumYield > threshold) {
shouldMove = true;
targetChain = "arbitrum";
} else if (optimismYield < threshold) {
shouldMove = true;
targetChain = "ethereum";
}
}
const result = {
shouldMove,
targetChain,
currentChain,
arbitrumYield,
optimismYield
};
Lit.Actions.setResponse({ response: JSON.stringify(result) });
})();
`;

Lit.Actions.setResponse({ response: resp });
})();`;

const meriYield=0.5 ;
const res = await client.executeJs({
sessionSigs,
code,
jsParams: {
accessControlConditions,
ciphertext,
dataToEncryptHash,
meriYield,
arbitrumYield,
optimismYield,
currentChain
},
});

Expand Down

0 comments on commit adced87

Please sign in to comment.